Appearance
ExtensionBuilder
Builder class for creating extensions using a fluent API pattern.
typescript
class ExtensionBuilder
Description
ExtensionBuilder
provides a convenient fluent interface for constructing Extension instances. It allows you to progressively configure all aspects of your extension - from blocks and controls to external integrations and styling - using method chaining. This approach makes extension configuration more readable and maintainable compared to direct constructor calls.
The builder pattern ensures that all components are properly collected and configured before creating the final Extension instance.
Import
typescript
import { ExtensionBuilder } from '@stripoinc/ui-editor-extensions';
Methods
withLocalization()
Sets the internationalization configuration for the extension.
typescript
public withLocalization(i18n: Record<string, Record<string, string>>): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
i18n | Record<string, Record<string, string>> | Localization strings organized by language code |
Returns
ExtensionBuilder
- The builder instance for method chaining
Example
typescript
builder.withLocalization({
'en': {
'button.label': 'Click Me',
'block.title': 'Custom Block'
},
'es': {
'button.label': 'Haz Clic',
'block.title': 'Bloque Personalizado'
}
})
addStyles()
Adds CSS styles for editor UI to the extension. Can be called multiple times to add styles incrementally.
typescript
public addStyles(styles: string): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
styles | string | CSS styles to inject into the editor |
Returns
ExtensionBuilder
- The builder instance for method chaining
Usage Notes
- Can be called multiple times to add styles incrementally
- All styles are concatenated when the extension is built
Example
typescript
builder
.addStyles('.my-block { padding: 20px; }')
.addStyles('.my-control { border: 1px solid #ccc; }')
withPreviewStyles()
Sets CSS styles specific to the email template preview.
typescript
public withPreviewStyles(styles: string): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
styles | string | CSS styles for preview mode only |
Returns
ExtensionBuilder
- The builder instance for method chaining
Usage Notes
- These styles are only applied in preview template frame
- Useful for setting styles of selected block (borders, context actions, etc.)
- Does not affect the editor interface
addBlock()
Registers a custom block with the extension.
typescript
public addBlock(block: ConstructorOfType<Block>): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
block | ConstructorOfType<Block> | Block class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
Example
typescript
import { MyHeroBlock } from './blocks/MyHeroBlock';
import { MyTestimonialBlock } from './blocks/MyTestimonialBlock';
builder
.addBlock(MyHeroBlock)
.addBlock(MyTestimonialBlock)
addControl()
Registers a custom control or built-in control extension.
typescript
public addControl(control: ConstructorOfType<Control | BuiltInControl>): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
control | ConstructorOfType<Control | BuiltInControl> | Control class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
addContextAction()
Registers a custom context action for blocks.
typescript
public addContextAction(contextAction: ConstructorOfType<ContextAction>): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
contextAction | ConstructorOfType<ContextAction> | Context action class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
addUiElement()
Registers a custom UI element.
typescript
public addUiElement(uiElement: ConstructorOfType<UIElement>): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
uiElement | ConstructorOfType<UIElement> | UI element class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withUiElementTagRegistry()
Sets the UI element tag registry for custom element tags.
typescript
public withUiElementTagRegistry(
uiElementTagRegistry: ConstructorOfType<UIElementTagRegistry>
): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
uiElementTagRegistry | ConstructorOfType<UIElementTagRegistry> | Tag registry class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withSettingsPanelRegistry()
Sets the settings panel registry for custom settings panels.
typescript
public withSettingsPanelRegistry(
settingsPanelRegistry: ConstructorOfType<SettingsPanelRegistry>
): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
settingsPanelRegistry | ConstructorOfType<SettingsPanelRegistry> | Registry class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withBlocksPanel()
Sets a custom blocks panel configuration.
typescript
public withBlocksPanel(blocksPanel: ConstructorOfType<BlocksPanel>): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
blocksPanel | ConstructorOfType<BlocksPanel> | Blocks panel class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withExternalImageLibrary()
Integrates an external image library.
typescript
public withExternalImageLibrary(
externalImageLibrary: ConstructorOfType<ExternalImageLibrary>
): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
externalImageLibrary | ConstructorOfType<ExternalImageLibrary> | Image library class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withExternalVideosLibrary()
Integrates an external video library.
typescript
public withExternalVideosLibrary(
externalVideoLibrary: ConstructorOfType<ExternalVideosLibrary>
): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
externalVideoLibrary | ConstructorOfType<ExternalVideosLibrary> | Video library class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withExternalSmartElementsLibrary()
Integrates an external smart elements library.
typescript
public withExternalSmartElementsLibrary(
externalSmartElementsLibrary: ConstructorOfType<ExternalSmartElementsLibrary>
): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
externalSmartElementsLibrary | ConstructorOfType<ExternalSmartElementsLibrary> | Smart elements library constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withExternalAiAssistant()
Integrates an external AI assistant.
typescript
public withExternalAiAssistant(
externalAiAssistant: ConstructorOfType<ExternalAiAssistant>
): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
externalAiAssistant | ConstructorOfType<ExternalAiAssistant> | AI assistant class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withExternalDisplayCondition()
Integrates an external display conditions library.
typescript
public withExternalDisplayCondition(
externalDisplayCondition: ConstructorOfType<ExternalDisplayConditionsLibrary>
): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
externalDisplayCondition | ConstructorOfType<ExternalDisplayConditionsLibrary> | Display conditions library constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
withIconsRegistry()
Sets a custom icons registry for registering SVG icons.
typescript
public withIconsRegistry(iconsRegistry: ConstructorOfType<IconsRegistry>): ExtensionBuilder
Parameters
Name | Type | Description |
---|---|---|
iconsRegistry | ConstructorOfType<IconsRegistry> | Icons registry class constructor |
Returns
ExtensionBuilder
- The builder instance for method chaining
Usage Notes
- Allows registration of custom SVG icons for use in controls and UI elements
- Icons can be referenced by key throughout the extension
- Useful for maintaining consistent iconography across custom components
Example
typescript
import { MyIconsRegistry } from './icons/MyIconsRegistry';
builder.withIconsRegistry(MyIconsRegistry)
build()
Creates the final Extension instance with all configured components.
typescript
public build(): Extension
Returns
Extension
- The configured extension instance ready for registration