import { MaybeGetter } from './utilities/callOrGet.js'; import { NodeType, ParseRule, Node as PmNode } from 'prosemirror-model'; import { Plugin } from 'prosemirror-state'; import { NodeView, EditorView, Decoration, DecorationSource } from 'prosemirror-view'; import { InputRule } from './InputRule.js'; import { Editor } from './Editor.js'; import { Command } from './types/ChainedCommands.js'; import { AttributeSpec, AttributeValue } from './Attribute.js'; /** * Attribute object accepted inside a `SuperDocDOMOutputSpec` tuple. * Runtime `setAttribute` coerces non-string values, so number / * boolean / null / undefined are accepted alongside string. */ export type RenderDOMAttrs = Record; /** * Tuple branch of `SuperDocDOMOutputSpec`, declared as an interface * to break TypeScript's direct-recursion check (PM's upstream * `readonly [string, ...any[]]` avoids this because `any` swallows * the recursion; we cannot replicate that with `unknown`). The * interface form defers the self-reference through a named type, * which TS accepts. * * The shape mirrors PM's tuple convention: index 0 is the tagName, * subsequent items are an optional attrs object, the literal `0` * (content hole), or nested specs. Both readonly and mutable * arrays satisfy this interface because `ReadonlyArray` is the * supertype of `Array`. */ export interface SuperDocDOMOutputSpecTuple extends ReadonlyArray { readonly 0: string; } /** * Public DOM rendering output spec for `NodeConfig.renderDOM`. * Mirrors ProseMirror's `DOMOutputSpec` shape but replaces the * upstream `readonly [string, ...any[]]` tuple branch with the * `SuperDocDOMOutputSpecTuple` interface above, so the public type * surface does not leak `any` through the SD-3213 supported-root * audit. * * `globalThis.Node` is used to disambiguate from the editor `Node` * class exported from this same file. */ export type SuperDocDOMOutputSpec = string | globalThis.Node | { dom: globalThis.Node; contentDOM?: HTMLElement; } | SuperDocDOMOutputSpecTuple; /** * Public function signature for `NodeConfig.renderDOM`. Function-only * (not `MaybeGetter`) because the runtime in * `packages/super-editor/src/editors/v1/core/Schema.js:99` invokes * `renderDOM({ node, htmlAttributes })` directly with no * `callOrGet()` wrapper. Typing it as `MaybeGetter` would * advertise a direct-value form that throws `TypeError` at runtime. * * `htmlAttributes` is the `Record` that * `Attribute.getAttributesToRender()` returns at runtime. */ export type RenderDOMFn = (props: { node: PmNode; htmlAttributes: Record; }) => SuperDocDOMOutputSpec; /** * Configuration for Node extensions. * * @typeParam Options - Type for node options. * @typeParam Storage - Type for node storage. * @typeParam Attrs - Type for node attributes (optional, enables typed addAttributes). */ export interface NodeConfig = Record, Storage extends Record = Record, Attrs extends Record = Record> { /** The node name */ name: string; /** The node group */ group?: string; /** The node options */ options?: Options; /** Whether the node is an atom node */ atom?: boolean; /** Whether the node is draggable */ draggable?: boolean; /** Whether the node is isolating */ isolating?: boolean; /** Whether the node is defining */ defining?: boolean; /** Whether the node is a top-level node */ topNode?: boolean; /** The role of the node in a table */ tableRole?: string; /** ProseMirror string for what content this node accepts */ content?: MaybeGetter; /** The marks applied to this node */ marks?: string; /** Whether the node is an inline node */ inline?: boolean; /** Whether the node is selectable */ selectable?: boolean; /** The ProseMirror node type (set at runtime) */ type?: NodeType; /** The editor instance (set at runtime) */ editor?: Editor; /** The DOM parsing rules */ parseDOM?: MaybeGetter; /** * The DOM rendering function for the node. Receives * `{ node, htmlAttributes }` at runtime (see `Schema.js:99`) and * returns a `SuperDocDOMOutputSpec`: a public local alias * mirroring ProseMirror's `DOMOutputSpec` shape but with an * unknown-free tuple branch. * * Typed as a plain function (`RenderDOMFn`) rather than * `MaybeGetter` because the runtime only * invokes the function form. A direct-value `renderDOM: ['br']` * type-checks under `MaybeGetter` but throws `TypeError` at * runtime. Narrowing the type aligns the public contract with * what the runtime actually supports. */ renderDOM?: RenderDOMFn; /** Function or object to add options to the node */ addOptions?: MaybeGetter; /** Function or object to add storage to the node */ addStorage?: MaybeGetter; /** * Function or object to add attributes to the node. * When Attrs generic is provided, attribute keys are validated against it. */ addAttributes?: MaybeGetter<{ [K in keyof Attrs]?: Partial; }>; /** Function or object to add commands to the node */ addCommands?: MaybeGetter>; /** Function or object to add helpers to the node */ addHelpers?: MaybeGetter unknown>>; /** Function or object to add shortcuts to the node */ addShortcuts?: MaybeGetter>; /** Function or object to add input rules to the node */ addInputRules?: MaybeGetter; /** Function to add a custom node view to the node */ addNodeView?: MaybeGetter<(props: { node: PmNode; view: EditorView; getPos: () => number | undefined; decorations: readonly Decoration[]; innerDecorations: DecorationSource; }) => NodeView | null>; /** Function to add ProseMirror plugins to the node */ addPmPlugins?: MaybeGetter[]>; /** Function to extend the ProseMirror node schema */ extendNodeSchema?: MaybeGetter>; /** Additional config fields - use with caution */ [key: string]: unknown; } /** * Node class is used to create Node extensions. * * @typeParam Options - Type for node options. * @typeParam Storage - Type for node storage. * @typeParam Attrs - Type for node attributes (enables typed attribute access). */ export declare class Node = Record, Storage extends Record = Record, Attrs extends Record = Record> { type: NodeType | string; name: string; options: Options; group: string | undefined; atom: boolean | undefined; editor: Editor | undefined; storage: Storage; config: NodeConfig; /** * Type hint for the attributes this node uses. * Not used at runtime, but enables type inference. */ readonly __attrsType: Attrs; constructor(config: NodeConfig); /** * Factory method to construct a new Node extension. * @param config - The node configuration. * @returns A new Node instance. */ static create = Record, S extends Record = Record, A extends Record = Record>(config: NodeConfig): Node; } //# sourceMappingURL=Node.d.ts.map