@dotcms/uve
Version:
Official JavaScript library for interacting with Universal Visual Editor (UVE)
89 lines (88 loc) • 3.4 kB
TypeScript
import type { StyleEditorFormSchema } from '@dotcms/types/internal';
import { StyleEditorForm } from './types';
/**
* Normalizes a complete form definition into the schema format expected by UVE.
*
* This is the main entry point for converting a developer-friendly form definition
* into the normalized schema structure that UVE (Universal Visual Editor) can consume.
* The normalization process transforms the entire form hierarchy:
*
* **Normalization Process:**
* 1. Preserves the `contentType` identifier
* 2. Processes each section using `normalizeSection`, which:
* - Normalizes all fields in the section using `normalizeField`
* - Organizes fields into the required multi-dimensional array structure
* 3. Returns a fully normalized schema with consistent structure across all sections
*
* The resulting schema has all field-specific properties moved into `config` objects
* and all sections using the consistent single-column array structure, regardless
* of the input format.
*
* @experimental This method is experimental and may be subject to change.
*
* @param form - The complete form definition to normalize
* @param form.contentType - The content type identifier this form is associated with
* @param form.sections - Array of section definitions, each containing a title and fields
* @returns The normalized form schema ready to be sent to UVE, with all fields and sections normalized
*
* @example
* ```typescript
* const schema = normalizeForm({
* contentType: 'my-content-type',
* sections: [
* {
* title: 'Typography',
* fields: [
* { type: 'input', id: 'font-size', label: 'Font Size', inputType: 'number' },
* { type: 'dropdown', id: 'font-family', label: 'Font Family', options: ['Arial', 'Helvetica'] }
* ]
* },
* {
* title: 'Colors',
* fields: [
* { type: 'input', id: 'primary-color', label: 'Primary Color', inputType: 'text' }
* ]
* }
* ]
* });
* // Returns: {
* // contentType: 'my-content-type',
* // sections: [
* // {
* // title: 'Typography',
* // fields: [
* // [
* // { type: 'input', id: 'font-size', label: 'Font Size', config: { inputType: 'number' } },
* // { type: 'dropdown', id: 'font-family', label: 'Font Family', config: { options: [...] } }
* // ]
* // ]
* // },
* // {
* // title: 'Colors',
* // fields: [
* // [
* // { type: 'input', id: 'primary-color', label: 'Primary Color', config: { inputType: 'text' } }
* // ]
* // ]
* // }
* // ]
* // }
* ```
*/
export declare function normalizeForm(form: StyleEditorForm): StyleEditorFormSchema;
/**
* Normalizes and validates a style editor form definition into the schema format
* expected by UVE. Used internally by the schema builder.
*
* @internal
*/
export declare function defineStyleEditorSchema(form: StyleEditorForm): StyleEditorFormSchema;
/**
* Registers style editor form schemas with the UVE editor.
*
* Sends normalized style editor schemas to UVE for registration.
* Only registers schemas when UVE is in EDIT mode.
*
* @internal — called automatically by useEditableDotCMSPage and DotCMSEditablePageService
*/
export declare function registerStyleEditorSchemas(schemas: StyleEditorFormSchema[]): void;