I’ve got a macro with a body that should be able to hold other macros with no body. When rendering the macro I am receiving its content in storage format from rest/api/content/{pageId}/history/{pageVersion}/macro/id/{macroId}
and then converting it to HTML using rest/api/contentbody/convert/view
.
With normal elements this works fine, but when there are other macros inside, they all get an iframe of 300x150px and it does not resize afterwards. It does not work with other third party macros either.
How can I get the macro iframes inside to resize properly?
Hi @PhilipFeldmann,
I think the key thing to note here is probably that no matter the HTML you’re rendering in your DOM, you are responsible for sizing it correctly. An iframe
is no different from a div
or really anything else in this case.
You will need to add some JavaScript or CSS yourself to your wrapper macro that resizes the nested macro how you want it. Does that make sense?
Cheers,
Sven
Thanks @sven.schatter .
How is this supposed to work? Confluence has more information about how to size frames correctly, than a plugin has, as it depends on the (inner) macro itself. Some macros will have a fixed amount of px as width, others will just want to get 100% of the container. That works when macros are not wrapped inside each other, but confluence does the work here, as every macro talks to confluence over the iframe bridge and can therefore be sized according to the content.
For my plugin that macro iframe is just a black box, I can’t look what’s inside it due to the shadow dom. And just measuring the dimensions of the frame does not work, because it’ll always be sized to 300x150px.
For the initial size you’ll of course have to trust on what Atlassian’s REST API gives you and that might or might not be what the given macro has specified in it’s descriptor.
For resizing the nested macro dynamically whenever it’s calling AP.resize
you’ll likely need to implement this in your wrapper macro via Atlassian’s simple-xdm bridge. (See my other response here and especially the part about auto resizing iframes in the readme of the linked simple-xdm repo)
Note that I’m saying likely, because I haven’t actually tried this myself - but if you approach it from a technical side: how else is AP.resize()
going to have any effect? It definitely needs to trigger something in the context of your wrapper macro that then adjusts the size of the iframe, and simple-xdm seems to be the way to do that.
Cheers,
Sven
Thanks a lot Sven, I’ll have a look into it and see what can be done.
1 Like