@lexical/html 0.44.1-nightly.20260518.0 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/{DOMRenderExtension.d.ts → dist/DOMRenderExtension.d.ts} +12 -1
  2. package/dist/DOMRenderRuntime.d.ts +51 -0
  3. package/dist/LexicalHtml.dev.js +3192 -0
  4. package/dist/LexicalHtml.dev.mjs +3146 -0
  5. package/{LexicalHtml.js.flow → dist/LexicalHtml.js.flow} +16 -16
  6. package/dist/LexicalHtml.mjs +56 -0
  7. package/dist/LexicalHtml.node.mjs +54 -0
  8. package/dist/LexicalHtml.prod.js +9 -0
  9. package/dist/LexicalHtml.prod.mjs +9 -0
  10. package/dist/RenderContext.d.ts +68 -0
  11. package/{compileDOMRenderConfigOverrides.d.ts → dist/compileDOMRenderConfigOverrides.d.ts} +1 -1
  12. package/{constants.d.ts → dist/constants.d.ts} +2 -0
  13. package/dist/domOverride.d.ts +23 -0
  14. package/dist/import/CoreImportExtension.d.ts +11 -0
  15. package/dist/import/DOMImportExtension.d.ts +82 -0
  16. package/dist/import/HorizontalRuleImportExtension.d.ts +27 -0
  17. package/dist/import/ImportContext.d.ts +208 -0
  18. package/dist/import/compileImportRules.d.ts +50 -0
  19. package/dist/import/coreImportRules.d.ts +25 -0
  20. package/dist/import/defineImportRule.d.ts +32 -0
  21. package/dist/import/defineOverlayRules.d.ts +66 -0
  22. package/dist/import/index.d.ts +38 -0
  23. package/dist/import/inlineStylesFromStyleSheets.d.ts +28 -0
  24. package/dist/import/parseCss.d.ts +18 -0
  25. package/dist/import/runImport.d.ts +19 -0
  26. package/dist/import/schemas.d.ts +91 -0
  27. package/dist/import/sel.d.ts +74 -0
  28. package/dist/import/types.d.ts +394 -0
  29. package/dist/index.d.ts +44 -0
  30. package/{types.d.ts → dist/types.d.ts} +96 -8
  31. package/package.json +33 -18
  32. package/src/ContextRecord.ts +243 -0
  33. package/src/DOMRenderExtension.ts +96 -0
  34. package/src/DOMRenderRuntime.ts +265 -0
  35. package/src/RenderContext.ts +168 -0
  36. package/src/compileDOMRenderConfigOverrides.ts +416 -0
  37. package/src/constants.ts +18 -0
  38. package/src/domOverride.ts +46 -0
  39. package/src/import/CoreImportExtension.ts +26 -0
  40. package/src/import/DOMImportExtension.ts +221 -0
  41. package/src/import/HorizontalRuleImportExtension.ts +53 -0
  42. package/src/import/ImportContext.ts +339 -0
  43. package/src/import/compileImportRules.ts +178 -0
  44. package/src/import/coreImportRules.ts +485 -0
  45. package/src/import/defineImportRule.ts +40 -0
  46. package/src/import/defineOverlayRules.ts +105 -0
  47. package/src/import/index.ts +96 -0
  48. package/src/import/inlineStylesFromStyleSheets.ts +104 -0
  49. package/src/import/parseCss.ts +219 -0
  50. package/src/import/runImport.ts +245 -0
  51. package/src/import/schemas.ts +236 -0
  52. package/src/import/sel.ts +314 -0
  53. package/src/import/types.ts +471 -0
  54. package/src/index.ts +555 -0
  55. package/src/types.ts +470 -0
  56. package/LexicalHtml.dev.js +0 -914
  57. package/LexicalHtml.dev.mjs +0 -900
  58. package/LexicalHtml.mjs +0 -24
  59. package/LexicalHtml.node.mjs +0 -22
  60. package/LexicalHtml.prod.js +0 -9
  61. package/LexicalHtml.prod.mjs +0 -9
  62. package/RenderContext.d.ts +0 -32
  63. package/domOverride.d.ts +0 -18
  64. package/index.d.ts +0 -32
  65. /package/{ContextRecord.d.ts → dist/ContextRecord.d.ts} +0 -0
  66. /package/{LexicalHtml.js → dist/LexicalHtml.js} +0 -0
@@ -0,0 +1,208 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { ContextRecord } from '../types';
9
+ import type { CompiledOverlayRules } from './defineOverlayRules';
10
+ import type { ImportContextPairOrUpdater, ImportSession, ImportStateConfig } from './types';
11
+ import { type LexicalEditor } from 'lexical';
12
+ import { DOMImportContextSymbol } from '../constants';
13
+ type ImportContextRecord = ContextRecord<typeof DOMImportContextSymbol>;
14
+ /**
15
+ * Create an import context state. The phantom symbol prevents accidental
16
+ * use of a render-context state in an import context (and vice versa).
17
+ *
18
+ * Note: to support the value-or-updater pattern, `V` cannot be a function
19
+ * type; wrap it in an array or object if needed.
20
+ *
21
+ * `getDefaultValue` is called **once at state creation** and the result is
22
+ * shared between every session that reads the state without first writing
23
+ * a value. Defaults must therefore be immutable (primitives, frozen
24
+ * objects, or read-only arrays / records). If your state needs mutable
25
+ * per-session storage, lazily initialize it inside your rule (e.g.
26
+ * `if (!ctx.session.has(cfg)) ctx.session.set(cfg, new …())`).
27
+ *
28
+ * @experimental
29
+ * @__NO_SIDE_EFFECTS__
30
+ */
31
+ export declare function createImportState<V>(name: string, getDefaultValue: () => V, isEqual?: (a: V, b: V) => boolean): ImportStateConfig<V>;
32
+ /**
33
+ * The kind of operation that produced this import. Lets rules adapt
34
+ * their behavior (e.g. preserve more whitespace on `'paste'`).
35
+ * Defaults to `'unknown'`. Apps that need a different vocabulary can
36
+ * define their own {@link ImportStateConfig} with whatever value type
37
+ * they want.
38
+ *
39
+ * @experimental
40
+ */
41
+ export type ImportSourceKind = 'paste' | 'unknown';
42
+ /**
43
+ * Built-in import-context state identifying how this import was initiated.
44
+ * Callers of `$generateNodesFromDOM` should set it via the `context` option.
45
+ *
46
+ * @experimental
47
+ */
48
+ export declare const ImportSource: ImportStateConfig<ImportSourceKind>;
49
+ /**
50
+ * Built-in import-context state holding the {@link DataTransfer} the
51
+ * import was sourced from, if any. `null` outside paste/drop flows.
52
+ *
53
+ * The clipboard import pipeline passes the original `DataTransfer`
54
+ * through to its per-MIME-type handler stack (see
55
+ * {@link ImportMimeTypeFunction}); handlers that route HTML through
56
+ * the {@link DOMImportExtension} pipeline should forward it into the
57
+ * walk via `context: [contextValue(ImportSourceDataTransfer,
58
+ * dataTransfer)]` so rules and preprocessors can call
59
+ * `ctx.get(ImportSourceDataTransfer)` to inspect companion MIME types
60
+ * (e.g. an `'application/rtf'` alternative or an attached
61
+ * `'application/x-officedrawing'` payload), the file list, or any
62
+ * custom drag-and-drop slot.
63
+ *
64
+ * Use sparingly: the safer pattern is to decide *which* MIME-type
65
+ * payload to walk in the clipboard handler stack and hand a finalized
66
+ * DOM to the rules; only fall back to peeking at `ImportSourceDataTransfer`
67
+ * when the source-detection signal genuinely lives in a companion
68
+ * slot.
69
+ *
70
+ * @experimental
71
+ */
72
+ export declare const ImportSourceDataTransfer: ImportStateConfig<DataTransfer | null>;
73
+ /**
74
+ * Built-in import-context state holding the bit-packed
75
+ * {@link TextFormatType} formats that should apply to {@link TextNode}s
76
+ * produced during the current subtree. Used by inline-format wrappers
77
+ * (`<b>`, `<i>`, `<u>`, …) to propagate formatting through the context
78
+ * record instead of via the legacy `forChild` chain.
79
+ *
80
+ * @experimental
81
+ */
82
+ export declare const ImportTextFormat: ImportStateConfig<number>;
83
+ /**
84
+ * Built-in import-context state holding a parsed CSS-style record
85
+ * (the {@link getStyleObjectFromCSS} shape) that should apply to
86
+ * {@link TextNode}s produced during the current subtree. Mirrors the
87
+ * format-bit propagation in {@link ImportTextFormat} for properties
88
+ * that don't fit into the format bit mask — `color`, `font-family`,
89
+ * `font-size`, etc.
90
+ *
91
+ * Ancestor rules that contribute a style branch the context with a
92
+ * merged record; the core `#text` rule materializes the non-empty
93
+ * record to a CSS string and calls `setStyle` on the new TextNode.
94
+ * Once TextNode adopts a parsed style record, the materialization
95
+ * step will go away.
96
+ *
97
+ * @experimental
98
+ */
99
+ export declare const ImportTextStyle: ImportStateConfig<Readonly<Record<string, string>>>;
100
+ /**
101
+ * Determines whether a given DOM element should be treated as preserving
102
+ * whitespace (i.e. text content under it is not collapsed and is split on
103
+ * `\n` / `\t` into `LineBreakNode` / `TabNode`). The default matches the
104
+ * legacy behavior: the element itself is `<pre>` or its inline
105
+ * `white-space` style begins with `'pre'`.
106
+ *
107
+ * @experimental
108
+ */
109
+ export type IsPreserveWhitespaceDom = (node: Node) => boolean;
110
+ /**
111
+ * Determines whether a given DOM node sits on the same visual line as its
112
+ * adjacent text siblings, governing whether leading/trailing whitespace in
113
+ * a `#text` is collapsed against neighbors. The default consults
114
+ * {@link isInlineDomNode} from `lexical` (style.display or a fixed inline
115
+ * tag-name set) and additionally treats elements with an explicit
116
+ * non-inline `display` style as block.
117
+ *
118
+ * @experimental
119
+ */
120
+ export type IsInlineForWhitespace = (node: Node) => boolean;
121
+ /**
122
+ * Configuration for the core text whitespace-collapse logic. Override via
123
+ * {@link ImportWhitespaceConfig} either as a `contextDefaults` entry on
124
+ * the {@link DOMImportExtension} or per-call on `$generateNodesFromDOM`'s
125
+ * `context` option.
126
+ *
127
+ * @experimental
128
+ */
129
+ export interface WhitespaceImportConfig {
130
+ /** See {@link IsPreserveWhitespaceDom}. */
131
+ readonly preservesWhitespace: IsPreserveWhitespaceDom;
132
+ /** See {@link IsInlineForWhitespace}. */
133
+ readonly isInline: IsInlineForWhitespace;
134
+ }
135
+ /**
136
+ * Default {@link WhitespaceImportConfig.preservesWhitespace}: matches
137
+ * `<pre>` and any element with `white-space: pre*`.
138
+ *
139
+ * @experimental
140
+ */
141
+ export declare function defaultPreservesWhitespace(node: Node): boolean;
142
+ /**
143
+ * Default {@link WhitespaceImportConfig.isInline}: treats an element as
144
+ * inline iff its inline `display` style is `inline*` OR (no explicit
145
+ * non-inline display) its nodeName is a known inline tag (`isInlineDomNode`).
146
+ * Text nodes are always inline; comments and other non-elements are not.
147
+ *
148
+ * @experimental
149
+ */
150
+ export declare function defaultIsInline(node: Node): boolean;
151
+ /**
152
+ * Built-in import-context state controlling text-node whitespace handling
153
+ * (collapse vs. preserve, what counts as an inline sibling). Override per
154
+ * editor via {@link DOMImportConfig.contextDefaults} or per call via
155
+ * {@link GenerateNodesFromDOMOptions.context}.
156
+ *
157
+ * @experimental
158
+ */
159
+ export declare const ImportWhitespaceConfig: ImportStateConfig<WhitespaceImportConfig>;
160
+ /**
161
+ * Built-in session slot for runtime overlay rules that should be in
162
+ * effect for the entire walk. A preprocessor writes here when it wants
163
+ * to conditionally install handling for a particular paste source
164
+ * (e.g. "if the Microsoft Word generator meta tag is present, push the
165
+ * Word-paste overlay"). Each entry contributes an overlay dispatcher
166
+ * to the runtime's overlay stack; later array entries are higher
167
+ * priority. Use `ctx.session.update(ImportOverlays, prev => […])` to
168
+ * append.
169
+ *
170
+ * This is the walk-wide counterpart to
171
+ * `$importChildren({rules: …})` (which scopes an overlay to one
172
+ * subtree): write to {@link ImportOverlays} when the overlay should
173
+ * apply for the whole document; use `$importChildren`'s `rules` when
174
+ * the overlay should only apply for a deeper region.
175
+ *
176
+ * @experimental
177
+ */
178
+ export declare const ImportOverlays: ImportStateConfig<readonly CompiledOverlayRules[]>;
179
+ /**
180
+ * The session IS the root-layer {@link ContextRecord} of the walk. Reads
181
+ * fall through the prototype chain to the editor's `contextDefaults`,
182
+ * writes mutate the record's own properties, and any branch pushed by
183
+ * `$importChildren({context})` sits above this layer and can shadow
184
+ * (but does not overwrite) slots.
185
+ *
186
+ * @internal
187
+ */
188
+ export declare class ImportSessionImpl implements ImportSession {
189
+ readonly record: ImportContextRecord;
190
+ constructor(record: ImportContextRecord);
191
+ get<V>(cfg: ImportStateConfig<V>): V;
192
+ set<V>(cfg: ImportStateConfig<V>, value: V): void;
193
+ update<V>(cfg: ImportStateConfig<V>, updater: (prev: V) => V): void;
194
+ has<V>(cfg: ImportStateConfig<V>): boolean;
195
+ }
196
+ /**
197
+ * Read an import context value during an import operation.
198
+ * @experimental
199
+ */
200
+ export declare function $getImportContextValue<V>(cfg: ImportStateConfig<V>, editor?: LexicalEditor): V;
201
+ /**
202
+ * Run `f` with the given context pairs applied on top of the editor's
203
+ * current import context.
204
+ *
205
+ * @experimental
206
+ */
207
+ export declare const $withImportContext: (cfg: readonly ImportContextPairOrUpdater[], editor?: LexicalEditor) => <T>(f: () => T) => T;
208
+ export {};
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { AnyDOMImportRule, DOMImportFn } from './types';
9
+ import { type Predicate } from './sel';
10
+ /** @internal */
11
+ export interface CompiledRule {
12
+ readonly name: string;
13
+ readonly predicate: Predicate;
14
+ readonly $import: DOMImportFn<Node, Record<string, RegExpMatchArray>>;
15
+ }
16
+ /** @internal */
17
+ export interface CompiledDispatch {
18
+ /** All rules in registration order. Index = registration order. */
19
+ readonly rules: readonly CompiledRule[];
20
+ /**
21
+ * For each (uppercased) HTML tag name, the ordered list of rule indices
22
+ * considered when dispatching that tag. Includes interleaved wildcard
23
+ * element rules so a single iteration handles both.
24
+ */
25
+ readonly byTag: ReadonlyMap<string, readonly number[]>;
26
+ /** Indices of rules whose match has no tag restriction. */
27
+ readonly wildcardIndices: readonly number[];
28
+ /** Indices of rules whose match is `sel.text()`. */
29
+ readonly textIndices: readonly number[];
30
+ /** Indices of rules whose match is `sel.comment()`. */
31
+ readonly commentIndices: readonly number[];
32
+ }
33
+ /**
34
+ * Compile an ordered list of {@link DOMImportRule}s into the dispatch tables
35
+ * used by the import runtime. The rule at index 0 is the highest-priority
36
+ * (`mergeConfig` prepends partial.rules so later-merged extensions land
37
+ * first).
38
+ *
39
+ * @internal
40
+ */
41
+ export declare function compileImportRules(rules: readonly AnyDOMImportRule[]): CompiledDispatch;
42
+ /**
43
+ * Look up the (already interleaved) rule indices relevant to `node`. Element
44
+ * nodes hit `byTag` (with wildcards merged in) or fall back to the wildcard
45
+ * bucket if no tag-specific rules exist; text and comment nodes use their
46
+ * own buckets.
47
+ *
48
+ * @internal
49
+ */
50
+ export declare function getDispatchIndices(dispatch: CompiledDispatch, node: Node): readonly number[];
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { type ElementFormatType } from 'lexical';
9
+ /**
10
+ * True if `value` is a non-empty {@link ElementFormatType} (matches one of
11
+ * the supported `text-align` / legacy `align`-attribute values).
12
+ *
13
+ * @internal
14
+ */
15
+ export declare function isAlignmentValue(value: string): value is ElementFormatType;
16
+ /**
17
+ * Rules covering the {@link ParagraphNode}, {@link TextNode},
18
+ * {@link LineBreakNode}, and {@link TabNode} cases that the legacy
19
+ * `importDOM` machinery in `@lexical/lexical` handled. Intended to be
20
+ * registered as a dependency of every editor that uses
21
+ * {@link DOMImportExtension}.
22
+ *
23
+ * @experimental
24
+ */
25
+ export declare const CoreImportRules: (import("./types").DOMImportRule<import("./types").ElementSelectorBuilder<HTMLElement | HTMLSpanElement, Record<string, never>>> | import("./types").DOMImportRule<import("./types").CompiledSelector<Text, Record<string, RegExpMatchArray>>>)[];
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { CompiledSelector, DOMImportFn, DOMImportRule } from './types';
9
+ /**
10
+ * Identity helper that infers a rule's matched node type and capture map
11
+ * from its `match` selector and threads them into the `$import` signature.
12
+ * Usage:
13
+ *
14
+ * ```ts
15
+ * defineImportRule({
16
+ * name: '@lexical/list/li',
17
+ * match: sel.tag('li'),
18
+ * $import: (ctx, el, $next) => {
19
+ * // el: HTMLLIElement
20
+ * return [$createListItemNode()];
21
+ * },
22
+ * });
23
+ * ```
24
+ *
25
+ * @experimental
26
+ * @__NO_SIDE_EFFECTS__
27
+ */
28
+ export declare function defineImportRule<const S extends CompiledSelector>(rule: {
29
+ readonly name?: string;
30
+ readonly match: S;
31
+ readonly $import: DOMImportFn<S extends CompiledSelector<infer N, Record<string, RegExpMatchArray>> ? N : Node, S extends CompiledSelector<Node, infer C> ? C : Record<string, never>>;
32
+ }): DOMImportRule<S>;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { AnyDOMImportRule } from './types';
9
+ import { type CompiledDispatch } from './compileImportRules';
10
+ /**
11
+ * Opaque handle for a pre-compiled set of overlay rules. Produce one with
12
+ * {@link defineOverlayRules} and pass it to
13
+ * {@link DOMImportContext.$importChildren} via
14
+ * {@link ImportChildrenOpts.rules}.
15
+ *
16
+ * To merge two or more overlays into a single one, pass them (alongside
17
+ * raw {@link DOMImportRule}s if desired) to a fresh
18
+ * {@link defineOverlayRules} — earlier arguments are higher priority.
19
+ *
20
+ * The internal shape is intentionally not part of the public API: it's a
21
+ * compiled dispatch table tagged with `__type` so callers cannot pass a
22
+ * raw rule array where a compiled overlay is expected.
23
+ *
24
+ * @experimental
25
+ */
26
+ export interface CompiledOverlayRules {
27
+ readonly __type: 'CompiledOverlayRules';
28
+ /** @internal */
29
+ readonly dispatch: CompiledDispatch;
30
+ /**
31
+ * @internal — flattened source rules retained so an overlay can be
32
+ * recompiled when it is passed to another {@link defineOverlayRules}
33
+ * call or as part of {@link DOMImportConfig.rules}.
34
+ */
35
+ readonly rules: readonly AnyDOMImportRule[];
36
+ }
37
+ /**
38
+ * An entry accepted everywhere rules are configured (overlay
39
+ * definitions, {@link DOMImportConfig.rules}). Either a single
40
+ * {@link DOMImportRule} or a {@link CompiledOverlayRules} produced by
41
+ * a previous {@link defineOverlayRules} call — passing the latter
42
+ * inlines the overlay's rules at this position in priority order.
43
+ *
44
+ * @experimental
45
+ */
46
+ export type DOMImportRuleEntry = AnyDOMImportRule | CompiledOverlayRules;
47
+ /** @internal */
48
+ export declare function flattenRuleEntries(entries: readonly DOMImportRuleEntry[]): AnyDOMImportRule[];
49
+ /**
50
+ * Pre-compile a set of {@link DOMImportRuleEntry}s into a
51
+ * {@link CompiledOverlayRules} handle that can be installed via
52
+ * `ctx.$importChildren(el, {rules: …})`.
53
+ *
54
+ * Entries can be raw {@link DOMImportRule}s or other
55
+ * {@link CompiledOverlayRules} (the latter are inlined at their
56
+ * position in priority order, so the same call composes any number of
57
+ * overlays). Earlier entries are higher priority.
58
+ *
59
+ * Overlay rules installed as a raw array would be re-compiled on every
60
+ * `$importChildren` call. For overlays that are reused (e.g. a GitHub
61
+ * code-table rule that wraps every matching table), call this once at
62
+ * module scope so the dispatch table is built up front.
63
+ *
64
+ * @experimental
65
+ */
66
+ export declare function defineOverlayRules(entries: readonly DOMImportRuleEntry[]): CompiledOverlayRules;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { parseSelector } from './parseCss';
9
+ /**
10
+ * Combinator-and-parser-based builder for {@link CompiledSelector}s. The
11
+ * runtime shape returned by these factory methods is opaque; consumers
12
+ * should never inspect or construct selector objects directly.
13
+ *
14
+ * @experimental
15
+ */
16
+ export declare const sel: {
17
+ readonly any: () => import("./types").ElementSelectorBuilder<HTMLElement>;
18
+ readonly comment: () => import("./types").CompiledSelector<Comment>;
19
+ /**
20
+ * Parse a reduced CSS-selector subset and return a builder you can chain
21
+ * combinator methods off of.
22
+ */
23
+ readonly css: typeof parseSelector;
24
+ readonly tag: <const Tags extends readonly string[]>(...tags: Tags) => import("./types").ElementSelectorBuilder<Tags[number] extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[Tags[number]] : HTMLElement>;
25
+ readonly text: () => import("./types").CompiledSelector<Text>;
26
+ };
27
+ export { CoreImportExtension } from './CoreImportExtension';
28
+ export { CoreImportRules } from './coreImportRules';
29
+ export { defineImportRule } from './defineImportRule';
30
+ export { type CompiledOverlayRules, defineOverlayRules, type DOMImportRuleEntry, } from './defineOverlayRules';
31
+ export { $generateNodesFromDOMViaExtension, type DOMImportConfig, DOMImportExtension, } from './DOMImportExtension';
32
+ export { HorizontalRuleImportExtension, HorizontalRuleImportRules, } from './HorizontalRuleImportExtension';
33
+ export { $getImportContextValue, $withImportContext, createImportState, defaultIsInline, defaultPreservesWhitespace, ImportOverlays, ImportSource, ImportSourceDataTransfer, type ImportSourceKind, ImportTextFormat, ImportTextStyle, ImportWhitespaceConfig, type IsInlineForWhitespace, type IsPreserveWhitespaceDom, type WhitespaceImportConfig, } from './ImportContext';
34
+ export { $inlineStylesFromStyleSheets } from './inlineStylesFromStyleSheets';
35
+ export { parseSelector } from './parseCss';
36
+ export { $distributeInlineWrapper, $isBlockLevel, BlockSchema, InlineSchema, NestedBlockSchema, RootSchema, } from './schemas';
37
+ export { isElementOfTag } from './sel';
38
+ export type { AnyDOMImportRule, AttrMatchOptions, CapturesOfSelector, ChildSchema, CompiledSelector, DOMImportContext, DOMImportExtensionOutput, DOMImportFn, DOMImportRule, DOMPreprocessContext, DOMPreprocessFn, ElementSelectorBuilder, GenerateNodesFromDOMOptions, ImportChildrenOpts, ImportContextPairOrUpdater, ImportNodeOpts, ImportSession, ImportStateConfig, NodeOfSelector, StyleMatchOptions, } from './types';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { DOMPreprocessFn } from './types';
9
+ /**
10
+ * Inlines CSS rules from `<style>` tags onto matching elements as inline
11
+ * styles.
12
+ *
13
+ * Used by apps like Excel that generate HTML where styles live in
14
+ * class-based `<style>` rules (e.g. `.xl65 { background: #FFFF00; color:
15
+ * blue; }`) rather than inline styles. Since Lexical's import converters
16
+ * read inline styles, we resolve stylesheet rules into inline styles
17
+ * before conversion.
18
+ *
19
+ * Mutates the DOM in-place. Original inline styles always take
20
+ * precedence over stylesheet rules (matching CSS specificity behavior).
21
+ *
22
+ * No-op for {@link ParentNode}s that are not {@link Document}s — only a
23
+ * full document carries `styleSheets` we can iterate.
24
+ *
25
+ * @experimental
26
+ */
27
+ export declare const $inlineStylesFromStyleSheets: DOMPreprocessFn;
28
+ export declare function $inlineStylesFromStyleSheetsDOM(dom: Document | ParentNode): void;
@@ -0,0 +1,18 @@
1
+ import type { ElementSelectorBuilder } from './types';
2
+ /**
3
+ * Parse a reduced CSS-selector subset and return a {@link CompiledSelector}.
4
+ * Supported:
5
+ * - Tag (`p`), wildcard (`*`).
6
+ * - Tag list (`h1, h2, h3`).
7
+ * - Class (`.foo`, `.foo.bar`).
8
+ * - ID (`#foo`).
9
+ * - Attribute presence (`[name]`).
10
+ * - Attribute equality (`[name="value"]`, `[name=value]`).
11
+ *
12
+ * Anything outside the subset (regex attribute, inline-style match,
13
+ * combinators, pseudo-classes) is intentionally rejected — chain combinator
14
+ * methods off the returned builder instead.
15
+ *
16
+ * @experimental
17
+ */
18
+ export declare function parseSelector(source: string): ElementSelectorBuilder<HTMLElement>;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { ImportSession } from './types';
9
+ import { type LexicalEditor, type LexicalNode } from 'lexical';
10
+ import { type CompiledDispatch } from './compileImportRules';
11
+ /**
12
+ * Top-level walker for a compiled dispatcher. Iterates the DOM children of
13
+ * `dom` (using the document body if a {@link Document} is passed) and
14
+ * applies `RootSchema` to the produced lexical nodes so runs of inlines are
15
+ * wrapped in paragraphs — same shape as the legacy `$generateNodesFromDOM`.
16
+ *
17
+ * @internal
18
+ */
19
+ export declare function $runImport(dispatch: CompiledDispatch, editor: LexicalEditor, dom: Document | ParentNode, session: ImportSession): LexicalNode[];
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { ChildSchema } from './types';
9
+ import { type ElementNode, type LexicalNode } from 'lexical';
10
+ /**
11
+ * True if the node fills a block slot at the root or inside another
12
+ * block — covers both ElementNode-style blocks (paragraph, heading,
13
+ * quote) and block-level DecoratorNodes (HorizontalRuleNode,
14
+ * ImageNode-as-block, etc.). Used by {@link BlockSchema},
15
+ * {@link RootSchema}, and {@link NestedBlockSchema}.
16
+ *
17
+ * @experimental
18
+ */
19
+ export declare function $isBlockLevel(node: LexicalNode): boolean;
20
+ /**
21
+ * Distribute an inline wrapper (`LinkNode`, `MarkNode`, …) across a
22
+ * heterogeneous run of children produced by `$importChildren`, lifting
23
+ * any block children to the top level while keeping the wrapper around
24
+ * the leaf inline content.
25
+ *
26
+ * Use from a rule whose DOM source is an inline element that the
27
+ * browser permitted to enclose block elements — the canonical case is
28
+ * `<a href="…"><h1>title</h1><div>body</div></a>`, which a link rule
29
+ * wants to surface as two block siblings (heading + paragraph), each
30
+ * with its own link wrapping the original inline content. Schemas
31
+ * can't express this because they reason about a parent's children
32
+ * only — they cannot lift the parent out of itself.
33
+ *
34
+ * For each top-level child:
35
+ * - **Inline children** are collected into runs; each run is wrapped
36
+ * in a single fresh wrapper (from `$makeWrapper()`).
37
+ * - **Block children** are descended into: their own children are
38
+ * recursively distributed with `$makeWrapper`, then re-attached so
39
+ * the block keeps its position at the top level.
40
+ *
41
+ * The returned list will contain a mix of blocks and wrapped inline
42
+ * runs. The enclosing schema (typically {@link BlockSchema}) will
43
+ * then package those inline wrappers into paragraphs as usual.
44
+ *
45
+ * @experimental
46
+ */
47
+ export declare function $distributeInlineWrapper(children: readonly LexicalNode[], $makeWrapper: () => ElementNode): LexicalNode[];
48
+ /**
49
+ * Apply a {@link ChildSchema} to a flat list of children produced by
50
+ * `$importChildren`. Walks the list once, partitions into accepted vs.
51
+ * rejected runs, packages or drops rejected runs, then runs `$finalize`.
52
+ *
53
+ * @internal
54
+ */
55
+ export declare function $applySchema(schema: ChildSchema, children: LexicalNode[], parent: LexicalNode | null, domParent: Node | null): LexicalNode[];
56
+ /**
57
+ * Default schema for block-level positions (root of the document, the body
58
+ * of a block element node). Accepts block lexical nodes; packages runs of
59
+ * inline children into fresh paragraph nodes.
60
+ *
61
+ * @experimental
62
+ */
63
+ export declare const BlockSchema: ChildSchema;
64
+ /**
65
+ * Schema for inline-only positions (the body of an inline lexical node such
66
+ * as a link). Accepts non-block lexical nodes; runs of block children are
67
+ * dropped (`onReject: 'drop'` is the default).
68
+ *
69
+ * @experimental
70
+ */
71
+ export declare const InlineSchema: ChildSchema;
72
+ /**
73
+ * Schema for nested block positions — the equivalent of the legacy
74
+ * `ArtificialNode__DO_NOT_USE` flow used when a block DOM element appears
75
+ * inside another block lexical ancestor. Accepts block nodes; runs of inline
76
+ * children are emitted with a line break between consecutive runs (instead
77
+ * of being wrapped in a paragraph, which would introduce an extra level of
78
+ * nesting).
79
+ *
80
+ * @experimental
81
+ */
82
+ export declare const NestedBlockSchema: ChildSchema;
83
+ /**
84
+ * Schema for the topmost level of `$generateNodesFromDOM`. Identical to
85
+ * {@link BlockSchema}; aliased for clarity at the entry point and so it can
86
+ * be overridden separately in the future (e.g. to synthesize a `ListNode`
87
+ * around runs of orphan `ListItemNode`s).
88
+ *
89
+ * @experimental
90
+ */
91
+ export declare const RootSchema: ChildSchema;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { AttrMatchOptions, CompiledSelector, ElementSelectorBuilder } from './types';
9
+ /**
10
+ * @internal
11
+ *
12
+ * A predicate that may write into the per-invocation `captures` map. Returns
13
+ * `true` if the rule matches; `false` otherwise.
14
+ */
15
+ export type Predicate = (node: Node, captures: Record<string, RegExpMatchArray>) => boolean;
16
+ /** @internal */
17
+ export type SelectorKind = 'element' | 'text' | 'comment';
18
+ /** @internal The runtime shape of a {@link CompiledSelector}. */
19
+ export interface SelectorImpl {
20
+ readonly kind: SelectorKind;
21
+ /**
22
+ * Uppercased tag names this selector is restricted to. Empty for wildcard
23
+ * element selectors and for text / comment selectors (dispatched by
24
+ * `kind`).
25
+ */
26
+ readonly tags: ReadonlySet<string>;
27
+ /** Composed predicate run against a candidate node. */
28
+ readonly predicate: Predicate;
29
+ }
30
+ /** @internal */
31
+ export declare function getSelectorImpl(sel: CompiledSelector): SelectorImpl;
32
+ /**
33
+ * @internal
34
+ *
35
+ * Build a selector value from a tag set and a predicate list. Used by the
36
+ * combinator API and the CSS parser.
37
+ */
38
+ export declare function buildSelector(tags: ReadonlySet<string>, predicates: readonly Predicate[]): ElementSelectorBuilder<HTMLElement>;
39
+ /** @internal */
40
+ export declare function buildClassAllPredicate(classes: readonly string[]): Predicate;
41
+ /** @internal */
42
+ export declare function buildClassAnyPredicate(classes: readonly string[]): Predicate;
43
+ /** @internal */
44
+ export declare function buildAttrPredicate(name: string, value: unknown, options?: AttrMatchOptions): Predicate;
45
+ /**
46
+ * Combinator API for building {@link CompiledSelector}s. The public
47
+ * `sel` is augmented from this in `./index.ts` (where the CSS parser is
48
+ * available without a circular import); consumers outside `@lexical/html`
49
+ * should always import the public `sel` from the package root.
50
+ *
51
+ * @internal
52
+ */
53
+ export declare const selBase: {
54
+ /** Match any {@link HTMLElement}. */
55
+ readonly any: () => ElementSelectorBuilder<HTMLElement>;
56
+ /** Match DOM {@link Comment} nodes. */
57
+ readonly comment: () => CompiledSelector<Comment>;
58
+ /**
59
+ * Match by tag name(s). With one literal tag the element type is narrowed
60
+ * (e.g. `'a' → HTMLAnchorElement`); with multiple, it is the union of
61
+ * their `HTMLElementTagNameMap` entries.
62
+ */
63
+ readonly tag: <const Tags extends readonly string[]>(...tags: Tags) => ElementSelectorBuilder<Tags[number] extends keyof HTMLElementTagNameMap ? HTMLElementTagNameMap[Tags[number]] : HTMLElement>;
64
+ /** Match DOM {@link Text} nodes. */
65
+ readonly text: () => CompiledSelector<Text>;
66
+ };
67
+ /**
68
+ * Cross-frame-safe replacement for `node instanceof HTMLXxxElement`. Returns
69
+ * true when `node` is an HTMLElement whose `nodeName` equals `tag` (compared
70
+ * case-insensitively).
71
+ *
72
+ * @experimental
73
+ */
74
+ export declare function isElementOfTag<T extends keyof HTMLElementTagNameMap>(node: Node, tag: T): node is HTMLElementTagNameMap[T];