The Macro
Javascript module is designed to manage multi-bodied macros (macros that have a multi-body-rich-text
bodyType). This module enables you to manipulate the macro bodies and allows for the storage and retrieval of macro parameters. The module is available in both the editor and renderer, however, modifications to the macro are not possible in the renderer (further details are provided below).
For a more comprehensive understanding of multi-bodied macros and a guide on how to utilize some of these methods, please refer to the tutorial.
Add a new body to the multi-bodied macro. At the moment, the total number of bodies cannot exceed 5. When a new macro is added to the page, it comes with a single body by default. This body becomes active and visible to users.
This method can't be used in the renderer.
Promise<Boolean>
1 2await AP.macro.addBody();
Remove a specified body from the multi-bodied macro. All bodies located to the right shift to the left after the body is removed. If the body being removed is the last, the multi-bodied macro is removed from the page.
This method can't be used in the renderer.
Name | Type | Description |
---|---|---|
index | Number | The index of the body to remove. |
Promise<Boolean>
1 2await AP.macro.removeBody(1);
By default, the first body of the multi-bodied macro is active (visible to users). This function brings a specified body to the front. Use this function while a user interacts with a macro or to show a specific body by default.
Name | Type | Description |
---|---|---|
body | Number | The index of the body to show (make active). |
frame | Number | The index of the frame in which the body should be shown. (The current value of this parameter is disregarded. However, it is intended to be utilized in future releases.) |
Promise<Boolean>
1 2await AP.macro.showBody({ body: 4, frame: 0, });
Returns the number of bodies created in the macro.
Promise<Number>
1 2const numberOfBodies = await AP.macro.getBodyCount();
Returns the macro parameters in the form of a collection of key/value pairs.
Promise<Record<string, string>>
1 2const macroParams = await AP.macro.getParameters();
Update macro parameters. Use this function to include metadata associated with bodies into macro parameters.
To ensure that parameters are used and stored correctly, they should
be defined in the module's parameters section. For those parameters not intended to be altered via the configuration panel, they should be marked as hidden.
include all parameters previously saved or updated through the configuration panel.
See an example below.
This method can't be used in the renderer.
Name | Type | Description |
---|---|---|
macroParams | Record<string, string> | The collection of key/value pairs |
Promise<Boolean>
1 2const currentParameters = await AP.macro.getParameters(); await AP.macro.updateParameters({ ...currentParameters, tabs: JSON.stringify([ { title: "Tab 1", isActive: true, bodyIndex: 0, }, { title: "Tab 2", isActive: false, bodyIndex: 1, }, ]), });
Rate this page: