import type { DOMImportExtensionOutput, DOMPreprocessFn, GenerateNodesFromDOMOptions, ImportContextPairOrUpdater } from './types.js'; import { type LexicalNode } from 'lexical'; import { type DOMImportRuleEntry } from './defineOverlayRules.js'; /** * Configuration for {@link DOMImportExtension}. * * @experimental */ export interface DOMImportConfig { /** * The ordered list of rules compiled into the import dispatcher. * Entries can be raw {@link DOMImportRule}s or a * {@link CompiledOverlayRules} produced by {@link defineOverlayRules} * (the latter is inlined at its position in the list — useful for * libraries that already publish a compiled overlay). * * **Rules are evaluated in list order.** For a given DOM node the * dispatcher visits every rule whose `match` accepts that node, front * to back, and the first one that returns without calling `$next()` * decides the outcome. "Higher priority" and "earlier in this list" * mean the same thing. * * **Composition prepends.** `mergeConfig` puts `partial.rules` in * FRONT of the rules accumulated so far, and configs are merged in * dependency order — a dependency's contribution is merged before the * contribution of the extension that depends on it. So: * * - Each contributor's array is inlined as one contiguous chunk that * keeps its own internal order: within a single * `configExtension(DOMImportExtension, {rules})` call the first * entry has the highest priority. * - The chunks are ordered from the most dependent contributor to the * least. An extension's rules therefore outrank the rules * contributed by its dependencies, and rules passed directly to * `buildEditorFromExtensions` (merged last of all) outrank every * extension's. This extension's own default entry * ({@link DefaultHoistRule}) is the base of the list and so is * always tried last. * * The relative order of two extensions where neither transitively * depends on the other falls out of the topological sort and is not * part of the API. Make the intended precedence explicit by having the * overriding extension depend on the one whose rules it overrides. */ readonly rules: readonly DOMImportRuleEntry[]; /** * Default context pairs applied to every `$generateNodesFromDOM` call. * Per-call overrides can be supplied via * {@link GenerateNodesFromDOMOptions.context}. */ readonly contextDefaults: readonly ImportContextPairOrUpdater[]; /** * Middleware run on the DOM before walking begins, mutating it in * place. Each function receives `$next` and may wrap or short-circuit * the rest of the chain (see {@link DOMPreprocessFn}). The default * config registers {@link $inlineStylesFromStyleSheets} (resolves * `