import type { Component, ComponentDataCollection, ComponentDataCondition, ComponentDataVariable, DataConditionProps, Editor, ExpressionProps, LogicGroupProps, ObjectAny, Property, Sector, Trait } from 'grapesjs'; import { DataCollectionResolverProps } from '../components/public/types/StudioDataCollectionPickerSchema'; import { DataVariableResolverProps } from '../components/public/types/StudioDataVariablePickerSchema'; export type { DataCollectionResolverProps } from '../components/public/types/StudioDataCollectionPickerSchema'; export type { DataVariableResolverProps } from '../components/public/types/StudioDataVariablePickerSchema'; export type GetCustomPath = (opts: { component: Component; path: string; paths: string[]; }) => string; export interface ExportConfig { getCustomPath?: GetCustomPath; /** * If true, removes the component tags (e.g., ``) from the output, * leaving only the raw template engine syntax (e.g., `{{#if ...}}`). */ skipTags?: boolean; /** * A function that wraps the generated template syntax (e.g., `{{#if}}`, `{{/each}}`) * in custom markup. This is important for frameworks like MJML where template * logic must be enclosed in `` tags to prevent the MJML parser from * misinterpreting it. * * @param {object} opts The options object for wrapping. * @param {string} opts.content The raw template syntax string (e.g., `{{#if user.isLoggedIn}}`). * @param {Component} opts.component The GrapesJS component instance associated with the syntax. * @returns {string} The wrapped template syntax. * @example * // Basic MJML compatibility * wrapTemplateContent: ({ content }) => `${content}` */ wrapTemplateContent?: (opts: { content: string; component: Component; }) => string; } export interface DataSourcesConfig { /** * Configuration for global datasets that can be used as data sources. */ globalData?: GlobalDataset; /** * Add data source components to blocks. * @default false */ blocks?: boolean; /** * Configuration options for exporting data resolvers. */ exportConfig?: ExportConfig; /** * Enable or configure data binding for the Style Manager. * Can be a boolean to toggle the feature on/off, or an object for detailed configuration. * @default false */ styleManager?: StyleManagerDataConfig; /** * Enable or configure data binding for the Trait Manager. * Can be a boolean to toggle the feature on/off, or an object for detailed configuration. * @default false */ traitManager?: TraitManagerDataConfig; } /** * Represents the global datasets available as data sources. * For example: * ``` * { * user: { firstname: 'John', lastname: 'Doe', age: 30 }, * products: [{ name: 'Laptop', price: 1200 }, { name: 'Mouse', price: 25 }] * } * ``` * Each key in this record represents the name of a global dataset (e.g., 'user', 'products'). * The value associated with each key can be either a single object or an array of objects, representing the data for that dataset. */ export type GlobalDataset = Record; export type ConditionType = ExpressionProps | LogicGroupProps; export interface IDataSourceExporter { getHelperId?(operator: string, typeHint?: 'string' | 'number' | 'any'): string | undefined; getVariableSyntax(options: { component: ComponentDataVariable; dataResolver: DataVariableResolverProps; }): string; getCollectionStartSyntax(options: { component: ComponentDataCollection; dataResolver: DataCollectionResolverProps; }): string; getCollectionEndSyntax(options: { component: ComponentDataCollection; }): string; getConditionalStartSyntax(options: { component: ComponentDataCondition; dataResolver: DataConditionProps; }): string; getConditionElseSyntax(options: { component: ComponentDataCondition; }): string; getConditionalEndSyntax(options: { component: ComponentDataCondition; }): string; } export interface IDataSourceImporter { import(template: string): string; } export type ExpressionSideType = string | number | DataVariableResolverProps; export declare enum DataComponentTypes { variable = "data-variable", condition = "data-condition", conditionTrue = "data-condition-true-content", conditionFalse = "data-condition-false-content", collection = "data-collection", collectionItem = "data-collection-item" } /** * Properties passed to the StyleManager's enable function. */ export interface StyleManagerEnableProps { /** * The style property being considered. */ property: Property; /** * The sector containing the property. */ sector: Sector; /** * The component for which the style is being applied. */ component: Component; /** * The editor object. */ editor: Editor; } /** * A function that determines if data binding should be enabled for a specific style property. * @returns `true` to enable, `false` to disable. */ export type StyleManagerEnableDataValueFn = (props: StyleManagerEnableProps) => boolean; /** * Configuration for the Style Manager data binding. */ export type StyleManagerDataConfig = boolean | { /** * A function to dynamically enable or disable data binding for specific style properties. * This allows for granular control over which styles can be connected to a data source. * @example * // Disable data binding for the 'color' property in the 'typography' sector. * enable: ({ property, sector }) => { * if (sector.getId() === 'typography' && property.getName() === 'color') { * return false; * } * return true; * } */ enable: StyleManagerEnableDataValueFn; }; /** * Properties passed to the TraitManager's enable function. */ export interface TraitManagerEnableProps { /** * The trait being considered. */ trait: Trait; /** * The component to which the trait belongs. */ component: Component; /** * The editor object. */ editor: Editor; } /** * A function that determines if data binding should be enabled for a specific trait. * @returns `true` to enable, `false` to disable. */ export type TraitManagerEnableDataValueFn = (props: TraitManagerEnableProps) => boolean; /** * Configuration for the Trait Manager data binding. */ export type TraitManagerDataConfig = boolean | { /** * A function to dynamically enable or disable data binding for specific traits. * This is useful for preventing certain component attributes from being data-bound. * @example * // Disable data binding for any trait named 'id'. * enable: ({ trait }) => { * return trait.getName() !== 'id'; * } */ enable: TraitManagerEnableDataValueFn; };