Skip to content

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>>): this

Parameters ​

NameTypeDescription
i18nRecord<string, Record<string, string>>Localization strings organized by language code

Returns ​

this - 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): this

Parameters ​

NameTypeDescription
stylesstringCSS styles to inject into the editor

Returns ​

this - 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): this

Parameters ​

NameTypeDescription
stylesstringCSS styles for preview mode only

Returns ​

this - 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>): this

Parameters ​

NameTypeDescription
blockConstructorOfType<Block>Block class constructor

Returns ​

this - 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>): this

Parameters ​

NameTypeDescription
controlConstructorOfType<Control | BuiltInControl>Control class constructor

Returns ​

this - The builder instance for method chaining


addContextAction() ​

Registers a custom context action for blocks.

typescript
public addContextAction(contextAction: ConstructorOfType<ContextAction>): this

Parameters ​

NameTypeDescription
contextActionConstructorOfType<ContextAction>Context action class constructor

Returns ​

this - The builder instance for method chaining


addUiElement() ​

Registers a custom UI element.

typescript
public addUiElement(uiElement: ConstructorOfType<UIElement>): this

Parameters ​

NameTypeDescription
uiElementConstructorOfType<UIElement>UI element class constructor

Returns ​

this - The builder instance for method chaining


withUiElementTagRegistry() ​

Sets the UI element tag registry for custom element tags.

typescript
public withUiElementTagRegistry(
  uiElementTagRegistry: ConstructorOfType<UIElementTagRegistry>
): this

Parameters ​

NameTypeDescription
uiElementTagRegistryConstructorOfType<UIElementTagRegistry>Tag registry class constructor

Returns ​

this - The builder instance for method chaining


withSettingsPanelRegistry() ​

Sets the settings panel registry for custom settings panels.

typescript
public withSettingsPanelRegistry(
  settingsPanelRegistry: ConstructorOfType<SettingsPanelRegistry>
): this

Parameters ​

NameTypeDescription
settingsPanelRegistryConstructorOfType<SettingsPanelRegistry>Registry class constructor

Returns ​

this - The builder instance for method chaining


withBlocksPanel() ​

Sets a custom blocks panel configuration.

typescript
public withBlocksPanel(blocksPanel: ConstructorOfType<BlocksPanel>): this

Parameters ​

NameTypeDescription
blocksPanelConstructorOfType<BlocksPanel>Blocks panel class constructor

Returns ​

this - The builder instance for method chaining


withExternalImageLibrary() ​

Integrates an external image library.

typescript
public withExternalImageLibrary(
  externalImageLibrary: ConstructorOfType<ExternalImageLibrary>
): this

Parameters ​

NameTypeDescription
externalImageLibraryConstructorOfType<ExternalImageLibrary>Image library class constructor

Returns ​

this - The builder instance for method chaining


withExternalImageLibraryTab() ​

Version Availability

This method is available starting from v3.2.0

Registers a custom tab within the external image library interface.

typescript
public withExternalImageLibraryTab(
  externalImageLibraryTab: ConstructorOfType<ExternalImageLibraryTab>
): this

Parameters ​

NameTypeDescription
externalImageLibraryTabConstructorOfType<ExternalImageLibraryTab>Image library tab class constructor

Returns ​

this - The builder instance for method chaining


withExternalMergeTagsLibrary() ​

Version Availability

This method is available starting from v3.11.0

Integrates an external merge tags library.

typescript
public withExternalMergeTagsLibrary(
  externalMergeTagsLibrary: ConstructorOfType<ExternalMergeTagsLibrary>
): this

Parameters ​

NameTypeDescription
externalMergeTagsLibraryConstructorOfType<ExternalMergeTagsLibrary>Merge tags library class constructor

Returns ​

this - The builder instance for method chaining

Example ​

typescript
import { MyMergeTagsLibrary } from './integrations/MyMergeTagsLibrary';

builder.withExternalMergeTagsLibrary(MyMergeTagsLibrary)

withExternalVideosLibrary() ​

Integrates an external video library.

typescript
public withExternalVideosLibrary(
  externalVideoLibrary: ConstructorOfType<ExternalVideosLibrary>
): this

Parameters ​

NameTypeDescription
externalVideoLibraryConstructorOfType<ExternalVideosLibrary>Video library class constructor

Returns ​

this - The builder instance for method chaining


withExternalSmartElementsLibrary() ​

Integrates an external smart elements library.

typescript
public withExternalSmartElementsLibrary(
  externalSmartElementsLibrary: ConstructorOfType<ExternalSmartElementsLibrary>
): this

Parameters ​

NameTypeDescription
externalSmartElementsLibraryConstructorOfType<ExternalSmartElementsLibrary>Smart elements library constructor

Returns ​

this - The builder instance for method chaining


withExternalAiAssistant() ​

Integrates an external AI assistant.

typescript
public withExternalAiAssistant(
  externalAiAssistant: ConstructorOfType<ExternalAiAssistant>
): this

Parameters ​

NameTypeDescription
externalAiAssistantConstructorOfType<ExternalAiAssistant>AI assistant class constructor

Returns ​

this - The builder instance for method chaining


withExternalDisplayCondition() ​

Integrates an external display conditions library.

typescript
public withExternalDisplayCondition(
  externalDisplayCondition: ConstructorOfType<ExternalDisplayConditionsLibrary>
): this

Parameters ​

NameTypeDescription
externalDisplayConditionConstructorOfType<ExternalDisplayConditionsLibrary>Display conditions library constructor

Returns ​

this - The builder instance for method chaining


withIconsRegistry() ​

Sets a custom icons registry for registering SVG icons.

typescript
public withIconsRegistry(iconsRegistry: ConstructorOfType<IconsRegistry>): this

Parameters ​

NameTypeDescription
iconsRegistryConstructorOfType<IconsRegistry>Icons registry class constructor

Returns ​

this - 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)

addGeneralPanelTab() ​

Version Availability

This method is available starting from v3.5.0

Registers a custom tab within the "General" panel of the editor.

typescript
public addGeneralPanelTab(tab: ConstructorOfType<GeneralPanelTab>): this

Parameters ​

NameTypeDescription
tabConstructorOfType<GeneralPanelTab>General panel tab class constructor

Returns ​

this - The builder instance for method chaining

Example ​

typescript
import { MyGlobalSettingsTab } from './tabs/MyGlobalSettingsTab';

builder.addGeneralPanelTab(MyGlobalSettingsTab)

addModulesPanelTab() ​

Version Availability

This method is available starting from v3.7.0

Registers a custom tab within the "Modules" panel of the editor.

typescript
public addModulesPanelTab(tab: ConstructorOfType<ModulesPanelTab>): this

Parameters ​

NameTypeDescription
tabConstructorOfType<ModulesPanelTab>Modules panel tab class constructor

Returns ​

this - The builder instance for method chaining

Example ​

typescript
import { MyModulesTab } from './tabs/MyModulesTab';

builder.addModulesPanelTab(MyModulesTab)

build() ​

Creates the final Extension instance with all configured components.

typescript
public build(): Extension

Returns ​

Extension - The configured extension instance ready for registration