Add a New Block via Composition API
Step 1: Import Necessary Components
Import the necessary components
Step 2: Create a New Component Instance
Instantiate the ComponentComposer and initialize your component by defining its namespace and operationId using the .create(displayNamespace, displayOperationId) method.
Set the namespace to const NS_OMNI
Step 3: Define Component Characteristics
Further define the characteristics of your component using provided methods. You can set the title, description, method, and category.
Instead of using the fromScratch()
method, you can also utilize the fromJSON()
method with a valid Partial<OmniComponentFormat>
JSON. This must include both the displayNamespace/operationID
and apiNamespace/operationId
.
Step 4: Create and Add Inputs and Outputs
For inputs and outputs, you'll first create an IOComposer
using the .createInput(name, type, customSocket)
or .createOutput(name, type, customSocket)
methods. You can further define their properties, including setting up controls which can be automatically selected or overridden.
Inputs always have controls associated with them, and they can be defined directly within the input creation process. Here's an example of defining an input with a control:
Note:
When using .allowMultiple()
in conjunction with { array: true }
, the input array is flattened into a single array:
You can define which characters are used for joining (or separating on input) an array (default is \n) via a custom setting (specific to the Text Socket):
Alternatively, you can also define inputs and outputs in an array:
You also have the option to directly write the JSON if that's your preference.
Step 5: Create and Add Controls (Optional)
Controls are created using the ControlComposer
and are added similarly to inputs/outputs.
Or
Step 6: Define Execution Macro
You can define the behavior of your component using a macro. In this case, the OmniComponentMacroTypes.EXEC
macro type is used.
Step 8: Export the Component
Finally, convert the component to JSON and export it.
Step 9: Add the Component to App Blocks
Note: extensions don’t need to call addBlock
. they just need to export the createComponent
function.
Optional Settings:
Composing Patches
To compose a patch with a valid OmniComponentPatch
, the same format applies:
Dependencies
Use .dependsOn(string[])
to specify dependencies, indicating if a block relies on other blocks (for instance, when using runblock
internally). For example:
Last updated