Sign up (with export icon)

core/editor/utils/normalizerootsconfig

Api-module iconmodule

Functions

  • Chevron-right icon

    normalizeMultiRootEditorConstructorParams( sourceElementOrDataOrConfig, editorConfig ) → object
    internal

    Normalizes the parameters passed to the editor constructor when a multi root is used. It supports both of the following signatures:

    new Editor( editorConfig: EditorConfig );
    new Editor( sourceElementsOrData: Record<string, string> | Record<string, HTMLElement>, editorConfig: EditorConfig );
    
    Copy code

    Parameters

    sourceElementOrDataOrConfig : Record<string, string> | Record<string, HTMLElement>
    editorConfig : EditorConfig

    Returns

    object
  • Chevron-right icon

    normalizeRootsConfig( sourceElementsOrData, config, defaultRootName, separateAttachTo ) → void
    internal

    Normalizes the editor roots configuration. It ensures that all root configurations are defined in config.roots and that they have initialData defined.

    It normalizes a single-root configuration (where config.root is used) to a multi-root configuration (where all roots are defined in config.roots). This is considered a standard configuration format, so the editor features can always expect roots to be defined in config.roots.

    It also handles legacy configuration options, such as config.initialData, config.placeholder, and config.label.

    Parameters

    sourceElementsOrData : string | HTMLElement | Record<string, string> | Record<string, HTMLElement>
    config : Config<EditorConfig>
    defaultRootName : string | false

    Defaults to 'main'

    separateAttachTo : boolean

    Defaults to false

    Returns

    void
  • Chevron-right icon

    normalizeSingleRootEditorConstructorParams( sourceElementOrDataOrConfig, editorConfig ) → object
    internal

    Normalizes the parameters passed to the editor constructor when a single root is used. It supports both of the following signatures:

    new Editor( editorConfig: EditorConfig );
    new Editor( sourceElementOrData: HTMLElement | string, editorConfig: EditorConfig );
    
    Copy code

    Parameters

    sourceElementOrDataOrConfig : string | HTMLElement | EditorConfig
    editorConfig : EditorConfig

    Returns

    object
  • Chevron-right icon

    normalizeViewRootElementDefinition( spec ) → HTMLElement | ViewRootElementDefinition | undefined
    internal

    Normalizes the value passed in config.root.element into a canonical form (HTMLElement or ViewRootElementDefinition) that the UI layer can consume directly.

    Accepts:

    • an existing HTMLElement - returned as is, so the editor wraps it in place,
    • a tag name string (e.g. 'h1') - turned into { name: 'h1' },
    • a ViewRootElementDefinition object - reshaped so classes becomes an array and attributes.class is lifted into it.

    The class attribute may be passed either as the dedicated classes field (string or array of strings) or as a class key inside attributes. They are concatenated. The style attribute may be passed either as the styles object or as a style string inside attributes. When both are provided, the object form takes precedence and a warning is logged.

    The <textarea> tag name is rejected as it cannot host a rich-text editable.

    Already used internally by normalizeRootsConfig() for config.root.element / config.roots.*.element. Exported for callers that bypass the regular config-normalization pass, e.g. MultiRootEditor.addRoot() and MultiRootEditor.createEditable().

    Parameters

    spec : string | HTMLElement | ViewRootElementDefinition | undefined

    Returns

    HTMLElement | ViewRootElementDefinition | undefined