import { WithEditorProps } from '@studio/editor/src/typeConfigs/common'; import { StudioLayoutComponentsConfigProps } from '@studio/editor/src/typeConfigs/layoutComponents'; import { RteCustomToolbarProps, RteCustomToolbarResult } from '@studio/editor/src/typeConfigs/rte'; import { ComponentView } from 'grapesjs'; import { MarkSpec, Node, Schema } from 'prosemirror-model'; import { Plugin, Transaction } from 'prosemirror-state'; import { EditorView } from 'prosemirror-view'; import { BuiltInCommands } from './commands'; import { CreateCustomMarkOptions, DefaultSchema } from './schema'; import { RteProseMirrorOptionsSchema } from './typesSchema'; export { StudioCommands } from '@studio/editor/src/plugins/global/types'; export type { LayoutCommandProps, RteCustomToolbar } from '@studio/editor/src/types'; export type { CreateCustomMarkOptions, DefaultSchema } from './schema'; export interface CustomRteOptions extends RteCustomToolbarProps { event?: PointerEvent; view: ComponentView; } export interface CustomOnEnterProps extends CustomRteOptions { /** * ProseMirror node. */ node: Node; /** * Built-in commands. */ commands: BuiltInCommands; /** * ProseMirror instance. */ proseMirror: { view: EditorView; dispatch?: (tr: Transaction) => void; }; } export interface RteProseMirrorToolbarProps extends RteCustomToolbarProps { /** * Default toolbar items. */ items: StudioLayoutComponentsConfigProps[]; /** * Built-in commands. */ commands: BuiltInCommands; /** * Built-in toolbar layout components. */ layouts: Record; /** * ProseMirror instance. */ proseMirror: { view: EditorView; }; } export interface RteProseMirrorOptions extends Omit { /** * Enable RTE on click of the text component, instead of the default double-click. * @default false */ enableOnClick?: boolean; /** * Extend the default ProseMirror schema. * @example * ({ schema, createCustomMark }) => { * // add additional nodes and return a new schema * return new Schema({ * nodes: schema.spec.nodes.append({...}), * marks: schema.spec.marks.append({ * myColor: createCustomMark({ key: 'data-my-color', cssProperty: 'color' }) * }) * }); * } */ schema?: (props: WithEditorProps & { schema: DefaultSchema; /** * Utility function to create custom marks with CSS property support. * @example * createCustomMark({ key: 'data-gs-mrk-color', cssProperty: 'color' }) */ createCustomMark: (options: CreateCustomMarkOptions) => MarkSpec; }) => Schema; /** * Pass additional ProseMirror plugins. * @example * ({ plugins }) => [ * // use the default plugins * ...plugins, * // pass your plugins * ] */ plugins?: (props: WithEditorProps & { plugins: Plugin[]; Plugin: typeof Plugin; }) => Plugin[]; /** * Customize the toolbar items. * @example * toolbar({ items, component, proseMirror }) { * const { view } = proseMirror; * return [ * // use the default toolbar items * ...items, * { * id: 'customButton', * type: 'button', * icon: 'flare', * onClick: () => {...} * } * ]; * } */ toolbar?: (props: RteProseMirrorToolbarProps) => RteCustomToolbarResult; /** * Custom function to handle the Enter key press. * @example * onEnter({ commands, component }) { * if (component.is('link')) { * // Create always a break for links * commands.text.createBreak(); * return true; * } * } */ onEnter?: (props: CustomOnEnterProps) => boolean | undefined | void; commandAttrs?: { link?: (htmlAttrs: Record) => Record | undefined | void; }; }