@lexical/code-core 0.48.0 → 0.48.1-nightly.20260720.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.
- package/dist/CodeHighlightNode.d.ts +60 -3
- package/dist/CodeNode.d.ts +65 -5
- package/dist/FlatStructureUtils.d.ts +3 -3
- package/dist/LexicalCodeCore.dev.js +74 -76
- package/dist/LexicalCodeCore.dev.mjs +74 -76
- package/dist/LexicalCodeCore.js.flow +2 -6
- package/dist/LexicalCodeCore.prod.js +1 -1
- package/dist/LexicalCodeCore.prod.mjs +2 -2
- package/package.json +6 -6
- package/src/CodeHighlightNode.ts +2 -16
- package/src/CodeNode.ts +71 -78
- package/src/FlatStructureUtils.ts +16 -11
|
@@ -14,15 +14,72 @@ export declare class CodeHighlightNode extends TextNode {
|
|
|
14
14
|
/** @internal */
|
|
15
15
|
__highlightType: string | null | undefined;
|
|
16
16
|
constructor(text?: string, highlightType?: string | null | undefined, key?: NodeKey);
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
$config(): import("lexical").BaseStaticNodeConfig & {
|
|
18
|
+
readonly text?: {
|
|
19
|
+
readonly importDOM: {
|
|
20
|
+
readonly '#text': () => {
|
|
21
|
+
conversion: (domNode: Node) => import("lexical").DOMConversionOutput;
|
|
22
|
+
priority: 0;
|
|
23
|
+
};
|
|
24
|
+
readonly b: () => {
|
|
25
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
26
|
+
priority: 0;
|
|
27
|
+
};
|
|
28
|
+
readonly code: () => {
|
|
29
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
30
|
+
priority: 0;
|
|
31
|
+
};
|
|
32
|
+
readonly em: () => {
|
|
33
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
34
|
+
priority: 0;
|
|
35
|
+
};
|
|
36
|
+
readonly i: () => {
|
|
37
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
38
|
+
priority: 0;
|
|
39
|
+
};
|
|
40
|
+
readonly mark: () => {
|
|
41
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
42
|
+
priority: 0;
|
|
43
|
+
};
|
|
44
|
+
readonly s: () => {
|
|
45
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
46
|
+
priority: 0;
|
|
47
|
+
};
|
|
48
|
+
readonly span: () => {
|
|
49
|
+
conversion: (domNode: HTMLSpanElement) => import("lexical").DOMConversionOutput;
|
|
50
|
+
priority: 0;
|
|
51
|
+
};
|
|
52
|
+
readonly strong: () => {
|
|
53
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
54
|
+
priority: 0;
|
|
55
|
+
};
|
|
56
|
+
readonly sub: () => {
|
|
57
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
58
|
+
priority: 0;
|
|
59
|
+
};
|
|
60
|
+
readonly sup: () => {
|
|
61
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
62
|
+
priority: 0;
|
|
63
|
+
};
|
|
64
|
+
readonly u: () => {
|
|
65
|
+
conversion: (domNode: HTMLElement) => import("lexical").DOMConversionOutput;
|
|
66
|
+
priority: 0;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
} | undefined;
|
|
70
|
+
} & {
|
|
71
|
+
readonly "code-highlight"?: {
|
|
72
|
+
readonly extends: typeof TextNode;
|
|
73
|
+
} | undefined;
|
|
74
|
+
} & import("lexical").StaticNodeTypeAccessor<"code-highlight"> & import("lexical").StaticNodeConfigAccessor<{
|
|
75
|
+
readonly extends: typeof TextNode;
|
|
76
|
+
}>;
|
|
19
77
|
afterCloneFrom(prevNode: this): void;
|
|
20
78
|
getHighlightType(): string | null | undefined;
|
|
21
79
|
setHighlightType(highlightType?: string | null | undefined): this;
|
|
22
80
|
canHaveFormat(): boolean;
|
|
23
81
|
createDOM(config: EditorConfig): HTMLElement;
|
|
24
82
|
updateDOM(prevNode: this, dom: HTMLElement, config: EditorConfig): boolean;
|
|
25
|
-
static importJSON(serializedNode: SerializedCodeHighlightNode): CodeHighlightNode;
|
|
26
83
|
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedCodeHighlightNode>): this;
|
|
27
84
|
exportJSON(): SerializedCodeHighlightNode;
|
|
28
85
|
setFormat(format: number): this;
|
package/dist/CodeNode.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { type
|
|
8
|
+
import { type DOMConversionOutput, type DOMExportOutput, type EditorConfig, ElementNode, type LexicalEditor, type LexicalNode, type LexicalUpdateJSON, type NodeKey, type ParagraphNode, type RangeSelection, type SerializedElementNode, type Spread, type TabNode } from 'lexical';
|
|
9
9
|
import { type CodeHighlightNode } from './CodeHighlightNode';
|
|
10
10
|
export type SerializedCodeNode = Spread<{
|
|
11
11
|
language: string | null | undefined;
|
|
@@ -22,15 +22,70 @@ export declare class CodeNode extends ElementNode {
|
|
|
22
22
|
__theme: string | undefined;
|
|
23
23
|
/** @internal */
|
|
24
24
|
__isSyntaxHighlightSupported: boolean;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
$config(): import("lexical").BaseStaticNodeConfig & {
|
|
26
|
+
readonly code?: {
|
|
27
|
+
readonly extends: typeof ElementNode;
|
|
28
|
+
readonly importDOM: {
|
|
29
|
+
readonly code: (node: Node) => {
|
|
30
|
+
conversion: typeof $convertPreElement;
|
|
31
|
+
priority: 1;
|
|
32
|
+
} | null;
|
|
33
|
+
readonly div: () => {
|
|
34
|
+
conversion: typeof $convertDivElement;
|
|
35
|
+
priority: 1;
|
|
36
|
+
};
|
|
37
|
+
readonly pre: () => {
|
|
38
|
+
conversion: typeof $convertPreElement;
|
|
39
|
+
priority: 0;
|
|
40
|
+
};
|
|
41
|
+
readonly table: (node: Node) => {
|
|
42
|
+
conversion: typeof $convertTableElement;
|
|
43
|
+
priority: 3;
|
|
44
|
+
} | null;
|
|
45
|
+
readonly td: (node: Node) => {
|
|
46
|
+
conversion: typeof convertCodeNoop;
|
|
47
|
+
priority: 3;
|
|
48
|
+
} | null;
|
|
49
|
+
readonly tr: (node: Node) => {
|
|
50
|
+
conversion: typeof convertCodeNoop;
|
|
51
|
+
priority: 3;
|
|
52
|
+
} | null;
|
|
53
|
+
};
|
|
54
|
+
} | undefined;
|
|
55
|
+
} & import("lexical").StaticNodeTypeAccessor<"code"> & import("lexical").StaticNodeConfigAccessor<{
|
|
56
|
+
readonly extends: typeof ElementNode;
|
|
57
|
+
readonly importDOM: {
|
|
58
|
+
readonly code: (node: Node) => {
|
|
59
|
+
conversion: typeof $convertPreElement;
|
|
60
|
+
priority: 1;
|
|
61
|
+
} | null;
|
|
62
|
+
readonly div: () => {
|
|
63
|
+
conversion: typeof $convertDivElement;
|
|
64
|
+
priority: 1;
|
|
65
|
+
};
|
|
66
|
+
readonly pre: () => {
|
|
67
|
+
conversion: typeof $convertPreElement;
|
|
68
|
+
priority: 0;
|
|
69
|
+
};
|
|
70
|
+
readonly table: (node: Node) => {
|
|
71
|
+
conversion: typeof $convertTableElement;
|
|
72
|
+
priority: 3;
|
|
73
|
+
} | null;
|
|
74
|
+
readonly td: (node: Node) => {
|
|
75
|
+
conversion: typeof convertCodeNoop;
|
|
76
|
+
priority: 3;
|
|
77
|
+
} | null;
|
|
78
|
+
readonly tr: (node: Node) => {
|
|
79
|
+
conversion: typeof convertCodeNoop;
|
|
80
|
+
priority: 3;
|
|
81
|
+
} | null;
|
|
82
|
+
};
|
|
83
|
+
}>;
|
|
27
84
|
constructor(language?: string | null | undefined, key?: NodeKey);
|
|
28
85
|
afterCloneFrom(prevNode: this): void;
|
|
29
86
|
createDOM(config: EditorConfig): HTMLElement;
|
|
30
87
|
updateDOM(prevNode: this, dom: HTMLElement, config: EditorConfig): boolean;
|
|
31
88
|
exportDOM(editor: LexicalEditor): DOMExportOutput;
|
|
32
|
-
static importDOM(): DOMConversionMap | null;
|
|
33
|
-
static importJSON(serializedNode: SerializedCodeNode): CodeNode;
|
|
34
89
|
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedCodeNode>): this;
|
|
35
90
|
exportJSON(): SerializedCodeNode;
|
|
36
91
|
insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): null | ParagraphNode | CodeHighlightNode | TabNode;
|
|
@@ -45,4 +100,9 @@ export declare class CodeNode extends ElementNode {
|
|
|
45
100
|
}
|
|
46
101
|
export declare function $createCodeNode(language?: string | null | undefined, theme?: string | null | undefined): CodeNode;
|
|
47
102
|
export declare function $isCodeNode(node: LexicalNode | null | undefined): node is CodeNode;
|
|
103
|
+
declare function $convertPreElement(domNode: HTMLElement): DOMConversionOutput;
|
|
104
|
+
declare function $convertDivElement(domNode: Node): DOMConversionOutput;
|
|
105
|
+
declare function $convertTableElement(): DOMConversionOutput;
|
|
106
|
+
declare function convertCodeNoop(): DOMConversionOutput;
|
|
48
107
|
export declare function $exitCodeNodeOnEnter(selection: RangeSelection): null | ParagraphNode;
|
|
108
|
+
export {};
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { type LexicalNode, type LineBreakNode, type RangeSelection, type TabNode } from 'lexical';
|
|
8
|
+
import { type LexicalNode, type LineBreakNode, type RangeSelection, type TabNode, type TextNode } from 'lexical';
|
|
9
9
|
import { type CodeHighlightNode } from './CodeHighlightNode';
|
|
10
|
-
export declare function $getFirstCodeNodeOfLine
|
|
11
|
-
export declare function $getLastCodeNodeOfLine
|
|
10
|
+
export declare function $getFirstCodeNodeOfLine<T extends TextNode | LineBreakNode>(anchor: T): T | CodeHighlightNode | TabNode;
|
|
11
|
+
export declare function $getLastCodeNodeOfLine<T extends TextNode | LineBreakNode>(anchor: T): T | CodeHighlightNode | TabNode;
|
|
12
12
|
/**
|
|
13
13
|
* Determines the visual writing direction of a code line.
|
|
14
14
|
*
|
|
@@ -49,6 +49,10 @@ function formatDevErrorMessage(message) {
|
|
|
49
49
|
throw new Error(message);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
// The anchor is generic (rather than the narrower
|
|
53
|
+
// `CodeHighlightNode | TabNode | LineBreakNode`) because callers may have only
|
|
54
|
+
// narrowed as far as TextNode; the matched siblings are always
|
|
55
|
+
// CodeHighlightNode/TabNode, and an unmatched anchor is returned unchanged.
|
|
52
56
|
function $getLastMatchingCodeNode(anchor, direction) {
|
|
53
57
|
let matchingNode = anchor;
|
|
54
58
|
for (let caret = lexical.$getSiblingCaret(anchor, direction); caret && ($isCodeHighlightNode(caret.origin) || lexical.$isTabNode(caret.origin)); caret = caret.getAdjacentCaret()) {
|
|
@@ -289,13 +293,73 @@ class CodeNode extends lexical.ElementNode {
|
|
|
289
293
|
__theme;
|
|
290
294
|
/** @internal */
|
|
291
295
|
__isSyntaxHighlightSupported;
|
|
292
|
-
|
|
293
|
-
return 'code'
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
296
|
+
$config() {
|
|
297
|
+
return this.config('code', {
|
|
298
|
+
extends: lexical.ElementNode,
|
|
299
|
+
importDOM: {
|
|
300
|
+
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
301
|
+
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
302
|
+
// inline format handled by TextNode otherwise.
|
|
303
|
+
code: node => {
|
|
304
|
+
const isMultiLine = node.textContent != null && (/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
|
|
305
|
+
return isMultiLine ? {
|
|
306
|
+
conversion: $convertPreElement,
|
|
307
|
+
priority: 1
|
|
308
|
+
} : null;
|
|
309
|
+
},
|
|
310
|
+
div: () => ({
|
|
311
|
+
conversion: $convertDivElement,
|
|
312
|
+
priority: 1
|
|
313
|
+
}),
|
|
314
|
+
pre: () => ({
|
|
315
|
+
conversion: $convertPreElement,
|
|
316
|
+
priority: 0
|
|
317
|
+
}),
|
|
318
|
+
table: node => {
|
|
319
|
+
const table = node;
|
|
320
|
+
// domNode is a <table> since we matched it by nodeName
|
|
321
|
+
if (isGitHubCodeTable(table)) {
|
|
322
|
+
return {
|
|
323
|
+
conversion: $convertTableElement,
|
|
324
|
+
priority: 3
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
return null;
|
|
328
|
+
},
|
|
329
|
+
td: node => {
|
|
330
|
+
// element is a <td> since we matched it by nodeName
|
|
331
|
+
const td = node;
|
|
332
|
+
const table = td.closest('table');
|
|
333
|
+
if (isGitHubCodeCell(td) || table && isGitHubCodeTable(table)) {
|
|
334
|
+
// Return a no-op if it's a table cell in a code table, but not a code line.
|
|
335
|
+
// Otherwise it'll fall back to the T
|
|
336
|
+
return {
|
|
337
|
+
conversion: convertCodeNoop,
|
|
338
|
+
priority: 3
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
return null;
|
|
342
|
+
},
|
|
343
|
+
tr: node => {
|
|
344
|
+
// element is a <tr> since we matched it by nodeName
|
|
345
|
+
const tr = node;
|
|
346
|
+
const table = tr.closest('table');
|
|
347
|
+
if (table && isGitHubCodeTable(table)) {
|
|
348
|
+
return {
|
|
349
|
+
conversion: convertCodeNoop,
|
|
350
|
+
priority: 3
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
});
|
|
297
357
|
}
|
|
298
|
-
|
|
358
|
+
|
|
359
|
+
// `language` carries an explicit `undefined` default so the constructor
|
|
360
|
+
// reports zero required arguments and `$config` can synthesize the static
|
|
361
|
+
// `clone` from the no-argument constructor.
|
|
362
|
+
constructor(language = undefined, key) {
|
|
299
363
|
super(key);
|
|
300
364
|
this.__language = language || undefined;
|
|
301
365
|
this.__isSyntaxHighlightSupported = false;
|
|
@@ -392,68 +456,6 @@ class CodeNode extends lexical.ElementNode {
|
|
|
392
456
|
element
|
|
393
457
|
};
|
|
394
458
|
}
|
|
395
|
-
static importDOM() {
|
|
396
|
-
return {
|
|
397
|
-
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
398
|
-
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
399
|
-
// inline format handled by TextNode otherwise.
|
|
400
|
-
code: node => {
|
|
401
|
-
const isMultiLine = node.textContent != null && (/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
|
|
402
|
-
return isMultiLine ? {
|
|
403
|
-
conversion: $convertPreElement,
|
|
404
|
-
priority: 1
|
|
405
|
-
} : null;
|
|
406
|
-
},
|
|
407
|
-
div: () => ({
|
|
408
|
-
conversion: $convertDivElement,
|
|
409
|
-
priority: 1
|
|
410
|
-
}),
|
|
411
|
-
pre: () => ({
|
|
412
|
-
conversion: $convertPreElement,
|
|
413
|
-
priority: 0
|
|
414
|
-
}),
|
|
415
|
-
table: node => {
|
|
416
|
-
const table = node;
|
|
417
|
-
// domNode is a <table> since we matched it by nodeName
|
|
418
|
-
if (isGitHubCodeTable(table)) {
|
|
419
|
-
return {
|
|
420
|
-
conversion: $convertTableElement,
|
|
421
|
-
priority: 3
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
return null;
|
|
425
|
-
},
|
|
426
|
-
td: node => {
|
|
427
|
-
// element is a <td> since we matched it by nodeName
|
|
428
|
-
const td = node;
|
|
429
|
-
const table = td.closest('table');
|
|
430
|
-
if (isGitHubCodeCell(td) || table && isGitHubCodeTable(table)) {
|
|
431
|
-
// Return a no-op if it's a table cell in a code table, but not a code line.
|
|
432
|
-
// Otherwise it'll fall back to the T
|
|
433
|
-
return {
|
|
434
|
-
conversion: convertCodeNoop,
|
|
435
|
-
priority: 3
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
return null;
|
|
439
|
-
},
|
|
440
|
-
tr: node => {
|
|
441
|
-
// element is a <tr> since we matched it by nodeName
|
|
442
|
-
const tr = node;
|
|
443
|
-
const table = tr.closest('table');
|
|
444
|
-
if (table && isGitHubCodeTable(table)) {
|
|
445
|
-
return {
|
|
446
|
-
conversion: convertCodeNoop,
|
|
447
|
-
priority: 3
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
return null;
|
|
451
|
-
}
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
static importJSON(serializedNode) {
|
|
455
|
-
return $createCodeNode().updateFromJSON(serializedNode);
|
|
456
|
-
}
|
|
457
459
|
updateFromJSON(serializedNode) {
|
|
458
460
|
return super.updateFromJSON(serializedNode).setLanguage(serializedNode.language).setTheme(serializedNode.theme);
|
|
459
461
|
}
|
|
@@ -659,11 +661,10 @@ class CodeHighlightNode extends lexical.TextNode {
|
|
|
659
661
|
super(text, key);
|
|
660
662
|
this.__highlightType = highlightType;
|
|
661
663
|
}
|
|
662
|
-
|
|
663
|
-
return 'code-highlight'
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
return new CodeHighlightNode(node.__text, node.__highlightType || undefined, node.__key);
|
|
664
|
+
$config() {
|
|
665
|
+
return this.config('code-highlight', {
|
|
666
|
+
extends: lexical.TextNode
|
|
667
|
+
});
|
|
667
668
|
}
|
|
668
669
|
afterCloneFrom(prevNode) {
|
|
669
670
|
super.afterCloneFrom(prevNode);
|
|
@@ -701,9 +702,6 @@ class CodeHighlightNode extends lexical.TextNode {
|
|
|
701
702
|
}
|
|
702
703
|
return update;
|
|
703
704
|
}
|
|
704
|
-
static importJSON(serializedNode) {
|
|
705
|
-
return $createCodeHighlightNode().updateFromJSON(serializedNode);
|
|
706
|
-
}
|
|
707
705
|
updateFromJSON(serializedNode) {
|
|
708
706
|
return super.updateFromJSON(serializedNode).setHighlightType(serializedNode.highlightType);
|
|
709
707
|
}
|
|
@@ -47,6 +47,10 @@ function formatDevErrorMessage(message) {
|
|
|
47
47
|
throw new Error(message);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// The anchor is generic (rather than the narrower
|
|
51
|
+
// `CodeHighlightNode | TabNode | LineBreakNode`) because callers may have only
|
|
52
|
+
// narrowed as far as TextNode; the matched siblings are always
|
|
53
|
+
// CodeHighlightNode/TabNode, and an unmatched anchor is returned unchanged.
|
|
50
54
|
function $getLastMatchingCodeNode(anchor, direction) {
|
|
51
55
|
let matchingNode = anchor;
|
|
52
56
|
for (let caret = $getSiblingCaret(anchor, direction); caret && ($isCodeHighlightNode(caret.origin) || $isTabNode(caret.origin)); caret = caret.getAdjacentCaret()) {
|
|
@@ -287,13 +291,73 @@ class CodeNode extends ElementNode {
|
|
|
287
291
|
__theme;
|
|
288
292
|
/** @internal */
|
|
289
293
|
__isSyntaxHighlightSupported;
|
|
290
|
-
|
|
291
|
-
return 'code'
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
294
|
+
$config() {
|
|
295
|
+
return this.config('code', {
|
|
296
|
+
extends: ElementNode,
|
|
297
|
+
importDOM: {
|
|
298
|
+
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
299
|
+
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
300
|
+
// inline format handled by TextNode otherwise.
|
|
301
|
+
code: node => {
|
|
302
|
+
const isMultiLine = node.textContent != null && (/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
|
|
303
|
+
return isMultiLine ? {
|
|
304
|
+
conversion: $convertPreElement,
|
|
305
|
+
priority: 1
|
|
306
|
+
} : null;
|
|
307
|
+
},
|
|
308
|
+
div: () => ({
|
|
309
|
+
conversion: $convertDivElement,
|
|
310
|
+
priority: 1
|
|
311
|
+
}),
|
|
312
|
+
pre: () => ({
|
|
313
|
+
conversion: $convertPreElement,
|
|
314
|
+
priority: 0
|
|
315
|
+
}),
|
|
316
|
+
table: node => {
|
|
317
|
+
const table = node;
|
|
318
|
+
// domNode is a <table> since we matched it by nodeName
|
|
319
|
+
if (isGitHubCodeTable(table)) {
|
|
320
|
+
return {
|
|
321
|
+
conversion: $convertTableElement,
|
|
322
|
+
priority: 3
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return null;
|
|
326
|
+
},
|
|
327
|
+
td: node => {
|
|
328
|
+
// element is a <td> since we matched it by nodeName
|
|
329
|
+
const td = node;
|
|
330
|
+
const table = td.closest('table');
|
|
331
|
+
if (isGitHubCodeCell(td) || table && isGitHubCodeTable(table)) {
|
|
332
|
+
// Return a no-op if it's a table cell in a code table, but not a code line.
|
|
333
|
+
// Otherwise it'll fall back to the T
|
|
334
|
+
return {
|
|
335
|
+
conversion: convertCodeNoop,
|
|
336
|
+
priority: 3
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
return null;
|
|
340
|
+
},
|
|
341
|
+
tr: node => {
|
|
342
|
+
// element is a <tr> since we matched it by nodeName
|
|
343
|
+
const tr = node;
|
|
344
|
+
const table = tr.closest('table');
|
|
345
|
+
if (table && isGitHubCodeTable(table)) {
|
|
346
|
+
return {
|
|
347
|
+
conversion: convertCodeNoop,
|
|
348
|
+
priority: 3
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
});
|
|
295
355
|
}
|
|
296
|
-
|
|
356
|
+
|
|
357
|
+
// `language` carries an explicit `undefined` default so the constructor
|
|
358
|
+
// reports zero required arguments and `$config` can synthesize the static
|
|
359
|
+
// `clone` from the no-argument constructor.
|
|
360
|
+
constructor(language = undefined, key) {
|
|
297
361
|
super(key);
|
|
298
362
|
this.__language = language || undefined;
|
|
299
363
|
this.__isSyntaxHighlightSupported = false;
|
|
@@ -390,68 +454,6 @@ class CodeNode extends ElementNode {
|
|
|
390
454
|
element
|
|
391
455
|
};
|
|
392
456
|
}
|
|
393
|
-
static importDOM() {
|
|
394
|
-
return {
|
|
395
|
-
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
396
|
-
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
397
|
-
// inline format handled by TextNode otherwise.
|
|
398
|
-
code: node => {
|
|
399
|
-
const isMultiLine = node.textContent != null && (/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
|
|
400
|
-
return isMultiLine ? {
|
|
401
|
-
conversion: $convertPreElement,
|
|
402
|
-
priority: 1
|
|
403
|
-
} : null;
|
|
404
|
-
},
|
|
405
|
-
div: () => ({
|
|
406
|
-
conversion: $convertDivElement,
|
|
407
|
-
priority: 1
|
|
408
|
-
}),
|
|
409
|
-
pre: () => ({
|
|
410
|
-
conversion: $convertPreElement,
|
|
411
|
-
priority: 0
|
|
412
|
-
}),
|
|
413
|
-
table: node => {
|
|
414
|
-
const table = node;
|
|
415
|
-
// domNode is a <table> since we matched it by nodeName
|
|
416
|
-
if (isGitHubCodeTable(table)) {
|
|
417
|
-
return {
|
|
418
|
-
conversion: $convertTableElement,
|
|
419
|
-
priority: 3
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
return null;
|
|
423
|
-
},
|
|
424
|
-
td: node => {
|
|
425
|
-
// element is a <td> since we matched it by nodeName
|
|
426
|
-
const td = node;
|
|
427
|
-
const table = td.closest('table');
|
|
428
|
-
if (isGitHubCodeCell(td) || table && isGitHubCodeTable(table)) {
|
|
429
|
-
// Return a no-op if it's a table cell in a code table, but not a code line.
|
|
430
|
-
// Otherwise it'll fall back to the T
|
|
431
|
-
return {
|
|
432
|
-
conversion: convertCodeNoop,
|
|
433
|
-
priority: 3
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
return null;
|
|
437
|
-
},
|
|
438
|
-
tr: node => {
|
|
439
|
-
// element is a <tr> since we matched it by nodeName
|
|
440
|
-
const tr = node;
|
|
441
|
-
const table = tr.closest('table');
|
|
442
|
-
if (table && isGitHubCodeTable(table)) {
|
|
443
|
-
return {
|
|
444
|
-
conversion: convertCodeNoop,
|
|
445
|
-
priority: 3
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
return null;
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
static importJSON(serializedNode) {
|
|
453
|
-
return $createCodeNode().updateFromJSON(serializedNode);
|
|
454
|
-
}
|
|
455
457
|
updateFromJSON(serializedNode) {
|
|
456
458
|
return super.updateFromJSON(serializedNode).setLanguage(serializedNode.language).setTheme(serializedNode.theme);
|
|
457
459
|
}
|
|
@@ -657,11 +659,10 @@ class CodeHighlightNode extends TextNode {
|
|
|
657
659
|
super(text, key);
|
|
658
660
|
this.__highlightType = highlightType;
|
|
659
661
|
}
|
|
660
|
-
|
|
661
|
-
return 'code-highlight'
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
return new CodeHighlightNode(node.__text, node.__highlightType || undefined, node.__key);
|
|
662
|
+
$config() {
|
|
663
|
+
return this.config('code-highlight', {
|
|
664
|
+
extends: TextNode
|
|
665
|
+
});
|
|
665
666
|
}
|
|
666
667
|
afterCloneFrom(prevNode) {
|
|
667
668
|
super.afterCloneFrom(prevNode);
|
|
@@ -699,9 +700,6 @@ class CodeHighlightNode extends TextNode {
|
|
|
699
700
|
}
|
|
700
701
|
return update;
|
|
701
702
|
}
|
|
702
|
-
static importJSON(serializedNode) {
|
|
703
|
-
return $createCodeHighlightNode().updateFromJSON(serializedNode);
|
|
704
|
-
}
|
|
705
703
|
updateFromJSON(serializedNode) {
|
|
706
704
|
return super.updateFromJSON(serializedNode).setHighlightType(serializedNode.highlightType);
|
|
707
705
|
}
|
|
@@ -54,9 +54,7 @@ declare export function $isCodeHighlightNode(
|
|
|
54
54
|
|
|
55
55
|
declare export class CodeHighlightNode extends TextNode {
|
|
56
56
|
__highlightType: ?string;
|
|
57
|
-
constructor(text
|
|
58
|
-
static getType(): string;
|
|
59
|
-
static clone(node: CodeHighlightNode): CodeHighlightNode;
|
|
57
|
+
constructor(text?: string, highlightType?: string, key?: NodeKey): void;
|
|
60
58
|
createDOM(config: EditorConfig): HTMLElement;
|
|
61
59
|
setFormat(format: number): this;
|
|
62
60
|
}
|
|
@@ -99,9 +97,7 @@ declare export function $isCodeNode(
|
|
|
99
97
|
|
|
100
98
|
declare export class CodeNode extends ElementNode {
|
|
101
99
|
__language: string | null | void;
|
|
102
|
-
|
|
103
|
-
static clone(node: CodeNode): CodeNode;
|
|
104
|
-
constructor(language: ?string, key?: NodeKey): void;
|
|
100
|
+
constructor(language?: ?string, key?: NodeKey): void;
|
|
105
101
|
createDOM(config: EditorConfig): HTMLElement;
|
|
106
102
|
insertNewAfter(
|
|
107
103
|
selection: RangeSelection,
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/html"),t=require("lexical"),n=require("@lexical/extension"),r=require("@lexical/utils");function i(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function o(e,n){let r=e;for(let i=t.$getSiblingCaret(e,n);i&&(A(i.origin)||t.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function s(e){return o(e,"previous")}function l(e){return o(e,"next")}function a(e){const n=s(e),r=l(e);let i=n;for(;null!==i;){if(A(i)){const e=t.getTextDirection(i.getTextContent());if(null!==e)return e}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(t.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function c(e,n){let r=null,o=null,s=e,l=n,a=e.getTextContent();for(;;){if(0===l){const e=s.getPreviousSibling();if(null===e){s=null;break}if(A(e)||t.$isTabNode(e)||t.$isLineBreakNode(e)||i(167),s=e,t.$isLineBreakNode(s)){r={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const e=a[l];A(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<e.getTextContentSize())A(e)&&(c=e.getTextContent()[n]);else{const t=e.getNextSibling();A(t)&&(c=t.getTextContent()[0])}if(null!==c&&" "!==c)return r;{const i=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!A(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;A(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(A(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,n);return null!==i?i:r}}function u(e){const n=l(e);return t.$isLineBreakNode(n)&&i(168),n}function g(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,a=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==a&&n.focus.set(s,Math.max(0,a-o),"text"),!0}const d="javascript";function f(e,n){for(const r of e.childNodes){if(t.isHTMLElement(r)&&r.tagName===n)return!0;if(f(r,n))return!0}return!1}const h="data-language",p="data-highlight-language",N="data-theme",m=()=>{};class _ extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new _(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const n=t.$getDocument().createElement("code");t.addClassNamesToElement(n,e.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),n}updateDOM(e,n,r){const i=this.__language,o=e.__language;i?i!==o&&n.setAttribute(h,i):o&&n.removeAttribute(h);const s=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(p,i):n.removeAttribute(p):s&&i&&n.setAttribute(p,i);const l=this.__theme,a=e.__theme;l?l!==a&&n.setAttribute(N,l):a&&n.removeAttribute(N);const c=this.__style,u=e.__style;return c!==u&&t.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(e){const n=t.$getDocument().createElement("pre");t.addClassNamesToElement(n,e._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||f(e,"BR"))?{conversion:x,priority:1}:null,div:()=>({conversion:O,priority:1}),pre:()=>({conversion:x,priority:0}),table:e=>b(e)?{conversion:S,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:$,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:$,priority:3}:null}}}static importJSON(e){return T().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,r=!0){if(!n.getPeerDependencyFromEditor(t.$getEditor(),"@lexical/code")){m();const t=E(e);if(t)return t}const{anchor:i,focus:o}=e,l=(i.isBefore(o)?i:o).getNode();if(t.$isTextNode(l)){let e=s(l);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!A(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(y(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=l.splitText(i.offset)[0],o=0===i.offset?0:1,a=r.getIndexWithinParent()+o,c=l.getParentOrThrow(),u=[t.$createLineBreakNode(),...n];c.splice(a,0,u);const g=n[n.length-1];g?g.select():0===i.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(C(l)){const{offset:n}=e.anchor;l.splice(n,0,[t.$createLineBreakNode()]),l.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function T(e,n){return t.$create(_).setLanguage(e).setTheme(n)}function C(e){return e instanceof _}function x(e){return{node:T(e.getAttribute(h))}}function O(e){const t=e,n=M(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(M(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function $(){return{node:null}}function M(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function E(e){const{anchor:n}=e;if(e.isCollapsed()&&"element"===n.type){const e=n.getNode();if(C(e)){const r=e.getChildrenSize();if(r>=2&&n.offset===r){const n=e.getLastChild();if(t.$isLineBreakNode(n)&&t.$isLineBreakNode(n.getPreviousSibling())){const n=t.$createParagraphNode();return e.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class R extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new R(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const n=super.createDOM(e),r=D(e.theme,this.__highlightType);return t.addClassNamesToElement(n,r),n}updateDOM(e,n,r){const i=super.updateDOM(e,n,r),o=D(r.theme,e.__highlightType),s=D(r.theme,this.__highlightType);return o!==s&&(o&&t.removeClassNamesFromElement(n,o),s&&t.addClassNamesToElement(n,s)),i}static importJSON(e){return y().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return T()}}function D(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function y(e="",n){return t.$applyNodeReplacement(new R(e,n))}function A(e){return e instanceof R}const v="data-language";function I(e){return null!==e.style.fontFamily.match("monospace")}function L(e){let t=e.parentElement;for(;null!==t;){if(I(t))return!0;t=t.parentElement}return!1}const P=/* @__PURE__ */e.defineOverlayRules([/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),B=/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))],match:e.sel.tag("pre"),name:"@lexical/code/pre"}),k=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))]:n()},match:e.sel.tag("code"),name:"@lexical/code/code-multiline"});function W(e){if(!t.isHTMLElement(e))return!1;const n=e.style.fontFamily,r=e.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function w(e){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(e.childNodes))if(t.isHTMLElement(l))"DIV"===l.tagName?(s(),r.push(l.textContent||""),n=!0):"BR"===l.tagName?(s(),r.push(""),n=!0):(i+=l.textContent||"",o=!0);else if(t.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function F(e){for(const n of Array.from(e.children)){if(t.isHTMLElement(n)&&W(n)){if(null!==w(n))return!0;const e=n.nextElementSibling;if(e&&W(e))return!0;continue}if(F(n))return!0}return!1}const H=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!W(n)||L(n))return r();const i=w(n);return null===i||0===i.length?r():[T().splice(0,0,t.$generateNodesFromRawText(i.join("\n")))]},match:e.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),Y=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!W(n)||L(n))return r();const i=n.previousElementSibling;if(i&&W(i))return[];const o=[];let s=n;for(;s&&W(s);)o.push("BR"===s.tagName?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?r():[T().splice(0,0,t.$generateNodesFromRawText(o.join("\n")))]},match:e.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),K=/* @__PURE__ */e.defineOverlayRules([H,Y]),U=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>I(t)?[T().splice(0,0,e.$importChildren(t))]:L(t)?e.$importChildren(t):n(),match:e.sel.tag("div"),name:"@lexical/code/div"}),z=[/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T().splice(0,0,e.$importChildren(t,{rules:P}))],match:e.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),k,B,U],J=/* @__PURE__ */t.defineExtension({dependencies:[e.CoreImportExtension,/* @__PURE__ */t.configExtension(e.DOMImportExtension,{preprocess:[(n,r,i)=>{F(t.isDOMDocumentNode(n)?n.body:n)&&r.session.update(e.ImportOverlays,e=>[...e,K]),i()}],rules:z})],name:"@lexical/code",nodes:()=>[_,R],register:e=>t.mergeRegister(e.registerCommand(t.KEY_ENTER_COMMAND,e=>{const n=t.$getSelection();return!(!t.$isRangeSelection(n)||!E(n))&&(e.preventDefault(),!0)},t.COMMAND_PRIORITY_LOW),e.registerNodeTransform(t.TabNode,e=>{0!==e.getFormat()&&C(e.getParent())&&e.setFormat(0)}))}),j=/* @__PURE__ */t.defineExtension({dependencies:[J],name:"@lexical/code/Import"});function q(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=C(n)?n:n.getParent(),i=e.focus.getNode(),o=C(i)?i:i.getParent();return C(r)&&r.is(o)}function V(e){const n=e.getNodes(),r=[];if(1===n.length&&C(n[0]))return r;let o=[];for(let e=0;e<n.length;e++){const s=n[e];A(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||i(169),t.$isLineBreakNode(s)?o.length>0&&(r.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,i=t.$createPoint(o[0].getKey(),0,"text");n.is(i)||r.push(o)}return r}function G(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!q(r))return!1;const i=V(r),o=i.length;if(0===o&&r.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&r.insertNodes([t.$createTabNode()]),!0;if(0===o&&e===t.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const e=t.$createTabNode(),n=t.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([e,n]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(n,"next"))),i)),!0}for(let l=0;l<o;l++){const o=i[l];if(o.length>0){let i=o[0];if(0===l&&(i=s(i)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(i.insertBefore(e),0===l){const n=r.isBackward()?"focus":"anchor",o=t.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(e.getKey(),0,"text")}}else t.$isTabNode(i)?i.remove():void 0!==n&&A(i)&&g(i,n,r)}}return!0}function Q(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,a=i.offset,c=o.offset,u=i.getNode(),g=o.getNode(),d=e===t.KEY_ARROW_UP_COMMAND;if(!q(r)||!A(u)&&!t.$isTabNode(u)||!A(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=u.getParentOrThrow();if(d&&0===a&&null===u.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!1}else if(!d&&a===u.getTextContentSize()&&null===u.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!1}}return!1}let f,h;if(u.isBefore(g)?(f=s(u),h=l(g)):(f=s(g),h=l(u)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const n=p[e];if(!A(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!t.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=A(m)||t.$isTabNode(m)||t.$isLineBreakNode(m)?d?s(m):l(m):null;let T=null!=_?_:m;return N.remove(),p.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>T.insertBefore(e)),T.insertBefore(N)):(T.insertAfter(N),T=N,p.forEach(e=>{T.insertAfter(e),T=e})),r.setTextNodeRange(u,a,g,c),!0}function X(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),l=o.getNode(),g=e===t.MOVE_TO_START;if(!q(r)||!A(s)&&!t.$isTabNode(s)||!A(l)&&!t.$isTabNode(l))return!1;const d=l,f="rtl"===a(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const e=c(d,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else d.getParentOrThrow().selectStart()}else{u(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function Z(e,n,o){return t.mergeRegister(...o?[e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_RIGHT_COMMAND,e=>r.$onEscapeDown(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(C,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_LEFT_COMMAND,e=>r.$onEscapeUp(C,e),t.COMMAND_PRIORITY_LOW)]:[],e.registerCommand(t.KEY_TAB_COMMAND,n=>{const r=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!q(n))return null;const r=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return o;const u=V(n);if(1!==u.length)return r;const g=u[0];let d,f;0===g.length&&i(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=s(g[0]),p=l(g[0]),N=t.$createPoint(h.getKey(),0,"text"),m=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?r:N.isBefore(d)||f.isBefore(m)?o:r}(n.shiftKey);return null!==r&&(n.preventDefault(),e.dispatchCommand(r,void 0),!0)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INSERT_TAB_COMMAND,()=>!!q(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INDENT_CONTENT_COMMAND,()=>G(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.OUTDENT_CONTENT_COMMAND,()=>G(t.OUTDENT_CONTENT_COMMAND,n),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();if(!q(n))return!1;const o=i.getParent();return n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&C(o)&&null===o.getPreviousSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_UP_COMMAND,e)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!q(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&C(i.getParentOrThrow())&&null===i.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_START,e=>X(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_END,e=>X(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW))}const ee=/* @__PURE__ */t.defineExtension({build:(e,t)=>n.namedSignals(t),config:/* @__PURE__ */t.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[J],name:"@lexical/code-indent",register:(e,t,r)=>{const i=r.getOutput();return n.effect(()=>{if(!i.disabled.value)return Z(e,i.tabSize.value,i.escapeWithArrows.value)})}});exports.$createCodeHighlightNode=y,exports.$createCodeNode=T,exports.$getCodeLineDirection=a,exports.$getEndOfCodeInLine=u,exports.$getFirstCodeNodeOfLine=s,exports.$getLastCodeNodeOfLine=l,exports.$getStartOfCodeInLine=c,exports.$isCodeHighlightNode=A,exports.$isCodeNode=C,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(e){const n=[];return t.tokenizeRawText(e,{linebreak:()=>n.push(t.$createLineBreakNode()),tab:()=>n.push(t.$createTabNode()),text:e=>n.push(y(e))}),n},exports.CodeExtension=J,exports.CodeHighlightNode=R,exports.CodeImportExtension=j,exports.CodeImportRules=z,exports.CodeIndentExtension=ee,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=Z;
|
|
9
|
+
"use strict";var e=require("@lexical/html"),t=require("lexical"),n=require("@lexical/extension"),r=require("@lexical/utils");function i(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function o(e,n){let r=e;for(let i=t.$getSiblingCaret(e,n);i&&(y(i.origin)||t.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function s(e){return o(e,"previous")}function l(e){return o(e,"next")}function a(e){const n=s(e),r=l(e);let i=n;for(;null!==i;){if(y(i)){const e=t.getTextDirection(i.getTextContent());if(null!==e)return e}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(t.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function c(e,n){let r=null,o=null,s=e,l=n,a=e.getTextContent();for(;;){if(0===l){const e=s.getPreviousSibling();if(null===e){s=null;break}if(y(e)||t.$isTabNode(e)||t.$isLineBreakNode(e)||i(167),s=e,t.$isLineBreakNode(s)){r={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const e=a[l];y(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<e.getTextContentSize())y(e)&&(c=e.getTextContent()[n]);else{const t=e.getNextSibling();y(t)&&(c=t.getTextContent()[0])}if(null!==c&&" "!==c)return r;{const i=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!y(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;y(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(y(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,n);return null!==i?i:r}}function u(e){const n=l(e);return t.$isLineBreakNode(n)&&i(168),n}function g(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,a=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==a&&n.focus.set(s,Math.max(0,a-o),"text"),!0}const d="javascript";function f(e,n){for(const r of e.childNodes){if(t.isHTMLElement(r)&&r.tagName===n)return!0;if(f(r,n))return!0}return!1}const h="data-language",p="data-highlight-language",N="data-theme",m=()=>{};class _ extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:t.ElementNode,importDOM:{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||f(e,"BR"))?{conversion:C,priority:1}:null,div:()=>({conversion:O,priority:1}),pre:()=>({conversion:C,priority:0}),table:e=>b(e)?{conversion:S,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:$,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:$,priority:3}:null}}})}constructor(e=void 0,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const n=t.$getDocument().createElement("code");t.addClassNamesToElement(n,e.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),n}updateDOM(e,n,r){const i=this.__language,o=e.__language;i?i!==o&&n.setAttribute(h,i):o&&n.removeAttribute(h);const s=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(p,i):n.removeAttribute(p):s&&i&&n.setAttribute(p,i);const l=this.__theme,a=e.__theme;l?l!==a&&n.setAttribute(N,l):a&&n.removeAttribute(N);const c=this.__style,u=e.__style;return c!==u&&t.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(e){const n=t.$getDocument().createElement("pre");t.addClassNamesToElement(n,e._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),{element:n}}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,r=!0){if(!n.getPeerDependencyFromEditor(t.$getEditor(),"@lexical/code")){m();const t=E(e);if(t)return t}const{anchor:i,focus:o}=e,l=(i.isBefore(o)?i:o).getNode();if(t.$isTextNode(l)){let e=s(l);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!y(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(A(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=l.splitText(i.offset)[0],o=0===i.offset?0:1,a=r.getIndexWithinParent()+o,c=l.getParentOrThrow(),u=[t.$createLineBreakNode(),...n];c.splice(a,0,u);const g=n[n.length-1];g?g.select():0===i.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(x(l)){const{offset:n}=e.anchor;l.splice(n,0,[t.$createLineBreakNode()]),l.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function T(e,n){return t.$create(_).setLanguage(e).setTheme(n)}function x(e){return e instanceof _}function C(e){return{node:T(e.getAttribute(h))}}function O(e){const t=e,n=M(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(M(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function $(){return{node:null}}function M(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function E(e){const{anchor:n}=e;if(e.isCollapsed()&&"element"===n.type){const e=n.getNode();if(x(e)){const r=e.getChildrenSize();if(r>=2&&n.offset===r){const n=e.getLastChild();if(t.$isLineBreakNode(n)&&t.$isLineBreakNode(n.getPreviousSibling())){const n=t.$createParagraphNode();return e.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class R extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}$config(){return this.config("code-highlight",{extends:t.TextNode})}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const n=super.createDOM(e),r=D(e.theme,this.__highlightType);return t.addClassNamesToElement(n,r),n}updateDOM(e,n,r){const i=super.updateDOM(e,n,r),o=D(r.theme,e.__highlightType),s=D(r.theme,this.__highlightType);return o!==s&&(o&&t.removeClassNamesFromElement(n,o),s&&t.addClassNamesToElement(n,s)),i}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return T()}}function D(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function A(e="",n){return t.$applyNodeReplacement(new R(e,n))}function y(e){return e instanceof R}const v="data-language";function I(e){return null!==e.style.fontFamily.match("monospace")}function L(e){let t=e.parentElement;for(;null!==t;){if(I(t))return!0;t=t.parentElement}return!1}const P=/* @__PURE__ */e.defineOverlayRules([/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),B=/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))],match:e.sel.tag("pre"),name:"@lexical/code/pre"}),W=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))]:n()},match:e.sel.tag("code"),name:"@lexical/code/code-multiline"});function k(e){if(!t.isHTMLElement(e))return!1;const n=e.style.fontFamily,r=e.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function H(e){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(e.childNodes))if(t.isHTMLElement(l))"DIV"===l.tagName?(s(),r.push(l.textContent||""),n=!0):"BR"===l.tagName?(s(),r.push(""),n=!0):(i+=l.textContent||"",o=!0);else if(t.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function w(e){for(const n of Array.from(e.children)){if(t.isHTMLElement(n)&&k(n)){if(null!==H(n))return!0;const e=n.nextElementSibling;if(e&&k(e))return!0;continue}if(w(n))return!0}return!1}const F=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!k(n)||L(n))return r();const i=H(n);return null===i||0===i.length?r():[T().splice(0,0,t.$generateNodesFromRawText(i.join("\n")))]},match:e.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),Y=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!k(n)||L(n))return r();const i=n.previousElementSibling;if(i&&k(i))return[];const o=[];let s=n;for(;s&&k(s);)o.push("BR"===s.tagName?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?r():[T().splice(0,0,t.$generateNodesFromRawText(o.join("\n")))]},match:e.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),K=/* @__PURE__ */e.defineOverlayRules([F,Y]),U=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>I(t)?[T().splice(0,0,e.$importChildren(t))]:L(t)?e.$importChildren(t):n(),match:e.sel.tag("div"),name:"@lexical/code/div"}),z=[/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T().splice(0,0,e.$importChildren(t,{rules:P}))],match:e.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),W,B,U],j=/* @__PURE__ */t.defineExtension({dependencies:[e.CoreImportExtension,/* @__PURE__ */t.configExtension(e.DOMImportExtension,{preprocess:[(n,r,i)=>{w(t.isDOMDocumentNode(n)?n.body:n)&&r.session.update(e.ImportOverlays,e=>[...e,K]),i()}],rules:z})],name:"@lexical/code",nodes:()=>[_,R],register:e=>t.mergeRegister(e.registerCommand(t.KEY_ENTER_COMMAND,e=>{const n=t.$getSelection();return!(!t.$isRangeSelection(n)||!E(n))&&(e.preventDefault(),!0)},t.COMMAND_PRIORITY_LOW),e.registerNodeTransform(t.TabNode,e=>{0!==e.getFormat()&&x(e.getParent())&&e.setFormat(0)}))}),J=/* @__PURE__ */t.defineExtension({dependencies:[j],name:"@lexical/code/Import"});function q(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=x(n)?n:n.getParent(),i=e.focus.getNode(),o=x(i)?i:i.getParent();return x(r)&&r.is(o)}function V(e){const n=e.getNodes(),r=[];if(1===n.length&&x(n[0]))return r;let o=[];for(let e=0;e<n.length;e++){const s=n[e];y(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||i(169),t.$isLineBreakNode(s)?o.length>0&&(r.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,i=t.$createPoint(o[0].getKey(),0,"text");n.is(i)||r.push(o)}return r}function G(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!q(r))return!1;const i=V(r),o=i.length;if(0===o&&r.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&r.insertNodes([t.$createTabNode()]),!0;if(0===o&&e===t.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const e=t.$createTabNode(),n=t.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([e,n]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(n,"next"))),i)),!0}for(let l=0;l<o;l++){const o=i[l];if(o.length>0){let i=o[0];if(0===l&&(i=s(i)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(i.insertBefore(e),0===l){const n=r.isBackward()?"focus":"anchor",o=t.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(e.getKey(),0,"text")}}else t.$isTabNode(i)?i.remove():void 0!==n&&y(i)&&g(i,n,r)}}return!0}function Q(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,a=i.offset,c=o.offset,u=i.getNode(),g=o.getNode(),d=e===t.KEY_ARROW_UP_COMMAND;if(!q(r)||!y(u)&&!t.$isTabNode(u)||!y(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=u.getParentOrThrow();if(d&&0===a&&null===u.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!1}else if(!d&&a===u.getTextContentSize()&&null===u.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!1}}return!1}let f,h;if(u.isBefore(g)?(f=s(u),h=l(g)):(f=s(g),h=l(u)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const n=p[e];if(!y(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!t.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=y(m)||t.$isTabNode(m)||t.$isLineBreakNode(m)?d?s(m):l(m):null;let T=null!=_?_:m;return N.remove(),p.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>T.insertBefore(e)),T.insertBefore(N)):(T.insertAfter(N),T=N,p.forEach(e=>{T.insertAfter(e),T=e})),r.setTextNodeRange(u,a,g,c),!0}function X(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),l=o.getNode(),g=e===t.MOVE_TO_START;if(!q(r)||!y(s)&&!t.$isTabNode(s)||!y(l)&&!t.$isTabNode(l))return!1;const d=l,f="rtl"===a(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const e=c(d,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else d.getParentOrThrow().selectStart()}else{u(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function Z(e,n,o){return t.mergeRegister(...o?[e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_RIGHT_COMMAND,e=>r.$onEscapeDown(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_LEFT_COMMAND,e=>r.$onEscapeUp(x,e),t.COMMAND_PRIORITY_LOW)]:[],e.registerCommand(t.KEY_TAB_COMMAND,n=>{const r=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!q(n))return null;const r=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return o;const u=V(n);if(1!==u.length)return r;const g=u[0];let d,f;0===g.length&&i(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=s(g[0]),p=l(g[0]),N=t.$createPoint(h.getKey(),0,"text"),m=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?r:N.isBefore(d)||f.isBefore(m)?o:r}(n.shiftKey);return null!==r&&(n.preventDefault(),e.dispatchCommand(r,void 0),!0)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INSERT_TAB_COMMAND,()=>!!q(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INDENT_CONTENT_COMMAND,()=>G(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.OUTDENT_CONTENT_COMMAND,()=>G(t.OUTDENT_CONTENT_COMMAND,n),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();if(!q(n))return!1;const o=i.getParent();return n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&x(o)&&null===o.getPreviousSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_UP_COMMAND,e)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!q(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&x(i.getParentOrThrow())&&null===i.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_START,e=>X(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_END,e=>X(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW))}const ee=/* @__PURE__ */t.defineExtension({build:(e,t)=>n.namedSignals(t),config:/* @__PURE__ */t.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[j],name:"@lexical/code-indent",register:(e,t,r)=>{const i=r.getOutput();return n.effect(()=>{if(!i.disabled.value)return Z(e,i.tabSize.value,i.escapeWithArrows.value)})}});exports.$createCodeHighlightNode=A,exports.$createCodeNode=T,exports.$getCodeLineDirection=a,exports.$getEndOfCodeInLine=u,exports.$getFirstCodeNodeOfLine=s,exports.$getLastCodeNodeOfLine=l,exports.$getStartOfCodeInLine=c,exports.$isCodeHighlightNode=y,exports.$isCodeNode=x,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(e){const n=[];return t.tokenizeRawText(e,{linebreak:()=>n.push(t.$createLineBreakNode()),tab:()=>n.push(t.$createTabNode()),text:e=>n.push(A(e))}),n},exports.CodeExtension=j,exports.CodeHighlightNode=R,exports.CodeImportExtension=J,exports.CodeImportRules=z,exports.CodeIndentExtension=ee,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=Z;
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{defineImportRule as e,sel as t,ImportOverlays as n,defineOverlayRules as r,CoreImportExtension as i,DOMImportExtension as o}from"@lexical/html";import{getTextDirection as s,$isElementNode as l,$isTabNode as u,$isLineBreakNode as c,tokenizeRawText as a,$createTabNode as g,$createLineBreakNode as
|
|
10
|
-
/*@__INLINE__*/function se(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function le(e,t){let n=e;for(let r=f(e,t);r&&(Le(r.origin)||u(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function ue(e){return le(e,"previous")}function ce(e){return le(e,"next")}function ae(e){const t=ue(e),n=ce(e);let r=t;for(;null!==r;){if(Le(r)){const e=s(r.getTextContent());if(null!==e)return e}if(r===n)break;r=r.getNextSibling()}const i=t.getParent();if(l(i)){const e=i.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function ge(e,t){let n=null,r=null,i=e,o=t,s=e.getTextContent();for(;;){if(0===o){const e=i.getPreviousSibling();if(null===e){i=null;break}if(Le(e)||u(e)||c(e)||se(167),i=e,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const e=s[o];Le(i)&&" "!==e&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(t<e.getTextContentSize())Le(e)&&(l=e.getTextContent()[t]);else{const t=e.getNextSibling();Le(t)&&(l=t.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(e,t){let n=e,r=t,i=e.getTextContent(),o=e.getTextContentSize();for(;;){if(!Le(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Le(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Le(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(e,t);return null!==r?r:n}}function he(e){const t=ce(e);return c(t)&&se(168),t}function fe(e){const t=[];return a(e,{linebreak:()=>t.push(h()),tab:()=>t.push(g()),text:e=>t.push(Fe(e))}),t}function pe(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,u=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==u&&n.focus.set(s,Math.max(0,u-o),"text"),!0}const de="javascript",me=()=>de;function xe(e,t){for(const n of e.childNodes){if(v(n)&&n.tagName===t)return!0;if(xe(n,t))return!0}return!1}const _e="data-language",Se="data-highlight-language",ye="data-theme",be=()=>{};class ve extends d{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new ve(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const t=m().createElement("code");x(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(_e,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(Se,n));const r=this.getTheme();r&&t.setAttribute(ye,r);const i=this.getStyle();return i&&_(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(_e,r):i&&t.removeAttribute(_e);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(Se,r):t.removeAttribute(Se):o&&r&&t.setAttribute(Se,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(ye,s):l&&t.removeAttribute(ye);const u=this.__style,c=e.__style;return u!==c&&_(t.style,u,c),!1}exportDOM(e){const t=m().createElement("pre");x(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(_e,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(Se,n));const r=this.getTheme();r&&t.setAttribute(ye,r);const i=this.getStyle();return i&&_(t.style,i),{element:t}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||xe(e,"BR"))?{conversion:Te,priority:1}:null,div:()=>({conversion:Ae,priority:1}),pre:()=>({conversion:Te,priority:0}),table:e=>He(e)?{conversion:Oe,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&He(n)?{conversion:Pe,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&He(t)?{conversion:Pe,priority:3}:null}}}static importJSON(e){return Ce().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,t=!0){if(!te(S(),"@lexical/code")){be();const t=De(e);if(t)return t}const{anchor:n,focus:r}=e,i=(n.isBefore(r)?n:r).getNode();if(y(i)){let e=ue(i);const t=[];for(;;)if(u(e))t.push(g()),e=e.getNextSibling();else{if(!Le(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(Fe(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,l=i.getParentOrThrow(),c=[h(),...t];l.splice(s,0,c);const a=t[t.length-1];a?a.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(Ne(i)){const{offset:t}=e.anchor;i.splice(t,0,[h()]),i.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=b();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function Ce(e,t){return p(ve).setLanguage(e).setTheme(t)}function Ne(e){return e instanceof ve}function Te(e){return{node:Ce(e.getAttribute(_e))}}function Ae(e){const t=e,n=we(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(we(t))return!0;t=t.parentElement}return!1}(t)?{node:n?Ce():null}:{node:null}}function Oe(){return{node:Ce()}}function Pe(){return{node:null}}function we(e){return null!==e.style.fontFamily.match("monospace")}function He(e){return e.classList.contains("js-file-line-container")}function De(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(Ne(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(c(t)&&c(t.getPreviousSibling())){const t=b();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class ke extends N{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new ke(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),n=Be(e.theme,this.__highlightType);return x(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=Be(n.theme,e.__highlightType),o=Be(n.theme,this.__highlightType);return i!==o&&(i&&T(t,i),o&&x(t,o)),r}static importJSON(e){return Fe().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return Ce()}}function Be(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function Fe(e="",t){return C(new ke(e,t))}function Le(e){return e instanceof ke}const $e="data-language";function Ee(e){return null!==e.style.fontFamily.match("monospace")}function Me(e){let t=e.parentElement;for(;null!==t;){if(Ee(t))return!0;t=t.parentElement}return!1}const Je=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),ze=/* @__PURE__ */e({$import:(e,t)=>[Ce(t.getAttribute($e)).splice(0,0,e.$importChildren(t))],match:t.tag("pre"),name:"@lexical/code/pre"}),Ke=/* @__PURE__ */e({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[Ce(t.getAttribute($e)).splice(0,0,e.$importChildren(t))]:n()},match:t.tag("code"),name:"@lexical/code/code-multiline"});function Ie(e){if(!v(e))return!1;const t=e.style.fontFamily,n=e.style.whiteSpace;return"string"==typeof t&&/monospace/i.test(t)&&"string"==typeof n&&n.startsWith("pre")}function je(e){let t=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(e.childNodes))if(v(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),t=!0):"BR"===s.tagName?(o(),n.push(""),t=!0):(r+=s.textContent||"",i=!0);else if(O(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function Re(e){for(const t of Array.from(e.children)){if(v(t)&&Ie(t)){if(null!==je(t))return!0;const e=t.nextElementSibling;if(e&&Ie(e))return!0;continue}if(Re(t))return!0}return!1}const We=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t,n)=>{if(!Ie(t)||Me(t))return n();const r=je(t);return null===r||0===r.length?n():[Ce().splice(0,0,P(r.join("\n")))]},match:t.tag("div"),name:"@lexical/code/vscode-wrapper"}),/* @__PURE__ */e({$import:(e,t,n)=>{if(!Ie(t)||Me(t))return n();const r=t.previousElementSibling;if(r&&Ie(r))return[];const i=[];let o=t;for(;o&&Ie(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[Ce().splice(0,0,P(i.join("\n")))]},match:t.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),qe=/* @__PURE__ */e({$import:(e,t,n)=>Ee(t)?[Ce().splice(0,0,e.$importChildren(t))]:Me(t)?e.$importChildren(t):n(),match:t.tag("div"),name:"@lexical/code/div"}),Ue=[/* @__PURE__ */e({$import:(e,t)=>[Ce().splice(0,0,e.$importChildren(t,{rules:Je}))],match:t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),Ke,ze,qe],Ve=/* @__PURE__ */w({dependencies:[i,/* @__PURE__ */$(o,{preprocess:[(e,t,r)=>{Re(A(e)?e.body:e)&&t.session.update(n,e=>[...e,We]),r()}],rules:Ue})],name:"@lexical/code",nodes:()=>[ve,ke],register:e=>H(e.registerCommand(D,e=>{const t=k();return!(!B(t)||!De(t))&&(e.preventDefault(),!0)},F),e.registerNodeTransform(L,e=>{0!==e.getFormat()&&Ne(e.getParent())&&e.setFormat(0)}))}),Ge=/* @__PURE__ */w({dependencies:[Ve],name:"@lexical/code/Import"});function Qe(e){if(!B(e))return!1;const t=e.anchor.getNode(),n=Ne(t)?t:t.getParent(),r=e.focus.getNode(),i=Ne(r)?r:r.getParent();return Ne(n)&&n.is(i)}function Xe(e){const t=e.getNodes(),n=[];if(1===t.length&&Ne(t[0]))return n;let r=[];for(let e=0;e<t.length;e++){const i=t[e];Le(i)||u(i)||c(i)||se(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const t=e.isBackward()?e.anchor:e.focus,i=G(r[0].getKey(),0,"text");t.is(i)||n.push(r)}return n}function Ye(e,t){const n=k();if(!B(n)||!Qe(n))return!1;const r=Xe(n),i=r.length;if(0===i&&n.isCollapsed())return e===W&&n.insertNodes([g()]),!0;if(0===i&&e===W&&"\n"===n.getTextContent()){const e=g(),t=h(),r=n.isBackward()?"previous":"next";return n.insertNodes([e,t]),Q(X(Y(Z(e,"next",0),ee(f(t,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=ue(r)),e===W){const e=g();if(r.insertBefore(e),0===o){const t=n.isBackward()?"focus":"anchor",i=G(r.getKey(),0,"text");n[t].is(i)&&n[t].set(e.getKey(),0,"text")}}else u(r)?r.remove():void 0!==t&&Le(r)&&pe(r,t,n)}}return!0}function Ze(e,t){const n=k();if(!B(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),a=i.getNode(),g=e===z;if(!Qe(n)||!Le(l)&&!u(l)||!Le(a)&&!u(a))return!1;if(!t.altKey){if(n.isCollapsed()){const e=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let h,f;if(l.isBefore(a)?(h=ue(l),f=ce(a)):(h=ue(a),f=ce(l)),null==h||null==f)return!1;const p=h.getNodesBetween(f);for(let e=0;e<p.length;e++){const t=p[e];if(!Le(t)&&!u(t)&&!c(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?h.getPreviousSibling():f.getNextSibling();if(!c(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=Le(m)||u(m)||c(m)?g?ue(m):ce(m):null;let _=null!=x?x:m;return d.remove(),p.forEach(e=>e.remove()),e===z?(p.forEach(e=>_.insertBefore(e)),_.insertBefore(d)):(_.insertAfter(d),_=d,p.forEach(e=>{_.insertAfter(e),_=e})),n.setTextNodeRange(l,o,a,s),!0}function et(e,t){const n=k();if(!B(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=e===U;if(!Qe(n)||!Le(o)&&!u(o)||!Le(s)&&!u(s))return!1;const a=s,g="rtl"===ae(a)?!l:l,h=r.key,f=r.offset,p=r.type;if(g){const e=ge(a,i.offset);if(null!==e){const{node:t,offset:r}=e;c(t)?t.selectNext(0,0):n.setTextNodeRange(t,r,t,r)}else a.getParentOrThrow().selectStart()}else{he(a).select()}return t.shiftKey&&n.anchor.set(h,f,p),t.preventDefault(),t.stopPropagation(),!0}function tt(e,t,n){return H(...n?[e.registerCommand(M,e=>!e.altKey&&ie(Ne,e),F),e.registerCommand(J,e=>ie(Ne,e),F),e.registerCommand(z,e=>!e.altKey&&oe(Ne,e),F),e.registerCommand(K,e=>oe(Ne,e),F)]:[],e.registerCommand(I,t=>{const n=function(e){const t=k();if(!B(t)||!Qe(t))return null;const n=e?q:W,r=e?q:j,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Xe(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&se(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=ue(l[0]),g=ce(l[0]),h=G(a.getKey(),0,"text"),f=G(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(h)||f.isBefore(c)?n:h.isBefore(u)||c.isBefore(f)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n,void 0),!0)},F),e.registerCommand(j,()=>!!Qe(k())&&(R([g()]),!0),F),e.registerCommand(W,()=>Ye(W),F),e.registerCommand(q,()=>Ye(q,t),F),e.registerCommand(z,e=>{const t=k();if(!B(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Qe(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&Ne(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):Ze(z,e)},F),e.registerCommand(M,e=>{const t=k();if(!B(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Qe(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&Ne(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Ze(M,e))},F),e.registerCommand(U,e=>et(U,e),F),e.registerCommand(V,e=>et(V,e),F))}const nt=/* @__PURE__ */w({build:(e,t)=>re(t),config:/* @__PURE__ */E({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[Ve],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return ne(()=>{if(!r.disabled.value)return tt(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{Fe as $createCodeHighlightNode,Ce as $createCodeNode,ae as $getCodeLineDirection,he as $getEndOfCodeInLine,ue as $getFirstCodeNodeOfLine,ce as $getLastCodeNodeOfLine,ge as $getStartOfCodeInLine,Le as $isCodeHighlightNode,Ne as $isCodeNode,pe as $outdentLeadingSpaces,fe as $plainifyCodeContent,Ve as CodeExtension,ke as CodeHighlightNode,Ge as CodeImportExtension,Ue as CodeImportRules,nt as CodeIndentExtension,ve as CodeNode,de as DEFAULT_CODE_LANGUAGE,me as getDefaultCodeLanguage,tt as registerCodeIndentation};
|
|
9
|
+
import{defineImportRule as e,sel as t,ImportOverlays as n,defineOverlayRules as r,CoreImportExtension as i,DOMImportExtension as o}from"@lexical/html";import{getTextDirection as s,$isElementNode as l,$isTabNode as u,$isLineBreakNode as c,tokenizeRawText as a,$createTabNode as g,$createLineBreakNode as f,$getSiblingCaret as h,$create as p,ElementNode as d,$getDocument as m,addClassNamesToElement as x,setDOMStyleFromCSS as S,$getEditor as y,$isTextNode as b,$createParagraphNode as _,isHTMLElement as v,$applyNodeReplacement as C,TextNode as T,removeClassNamesFromElement as N,isDOMDocumentNode as A,isDOMTextNode as P,$generateNodesFromRawText as O,defineExtension as w,mergeRegister as H,KEY_ENTER_COMMAND as $,$getSelection as D,$isRangeSelection as B,COMMAND_PRIORITY_LOW as L,TabNode as k,configExtension as E,safeCast as F,KEY_ARROW_DOWN_COMMAND as M,KEY_ARROW_RIGHT_COMMAND as z,KEY_ARROW_UP_COMMAND as K,KEY_ARROW_LEFT_COMMAND as I,KEY_TAB_COMMAND as j,INSERT_TAB_COMMAND as J,$insertNodes as R,INDENT_CONTENT_COMMAND as W,OUTDENT_CONTENT_COMMAND as q,MOVE_TO_START as U,MOVE_TO_END as V,$createPoint as G,$setSelectionFromCaretRange as Q,$getCaretRangeInDirection as X,$getCaretRange as Y,$getTextPointCaret as Z,$normalizeCaret as ee}from"lexical";import{getPeerDependencyFromEditor as te,effect as ne,namedSignals as re}from"@lexical/extension";import{$onEscapeDown as ie,$onEscapeUp as oe}from"@lexical/utils";
|
|
10
|
+
/*@__INLINE__*/function se(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function le(e,t){let n=e;for(let r=h(e,t);r&&(ke(r.origin)||u(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function ue(e){return le(e,"previous")}function ce(e){return le(e,"next")}function ae(e){const t=ue(e),n=ce(e);let r=t;for(;null!==r;){if(ke(r)){const e=s(r.getTextContent());if(null!==e)return e}if(r===n)break;r=r.getNextSibling()}const i=t.getParent();if(l(i)){const e=i.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function ge(e,t){let n=null,r=null,i=e,o=t,s=e.getTextContent();for(;;){if(0===o){const e=i.getPreviousSibling();if(null===e){i=null;break}if(ke(e)||u(e)||c(e)||se(167),i=e,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const e=s[o];ke(i)&&" "!==e&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(t<e.getTextContentSize())ke(e)&&(l=e.getTextContent()[t]);else{const t=e.getNextSibling();ke(t)&&(l=t.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(e,t){let n=e,r=t,i=e.getTextContent(),o=e.getTextContentSize();for(;;){if(!ke(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;ke(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(ke(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(e,t);return null!==r?r:n}}function fe(e){const t=ce(e);return c(t)&&se(168),t}function he(e){const t=[];return a(e,{linebreak:()=>t.push(f()),tab:()=>t.push(g()),text:e=>t.push(Le(e))}),t}function pe(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,u=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==u&&n.focus.set(s,Math.max(0,u-o),"text"),!0}const de="javascript",me=()=>de;function xe(e,t){for(const n of e.childNodes){if(v(n)&&n.tagName===t)return!0;if(xe(n,t))return!0}return!1}const Se="data-language",ye="data-highlight-language",be="data-theme",_e=()=>{};class ve extends d{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:d,importDOM:{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||xe(e,"BR"))?{conversion:Ne,priority:1}:null,div:()=>({conversion:Ae,priority:1}),pre:()=>({conversion:Ne,priority:0}),table:e=>He(e)?{conversion:Pe,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&He(n)?{conversion:Oe,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&He(t)?{conversion:Oe,priority:3}:null}}})}constructor(e=void 0,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const t=m().createElement("code");x(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(Se,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(ye,n));const r=this.getTheme();r&&t.setAttribute(be,r);const i=this.getStyle();return i&&S(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(Se,r):i&&t.removeAttribute(Se);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(ye,r):t.removeAttribute(ye):o&&r&&t.setAttribute(ye,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(be,s):l&&t.removeAttribute(be);const u=this.__style,c=e.__style;return u!==c&&S(t.style,u,c),!1}exportDOM(e){const t=m().createElement("pre");x(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(Se,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(ye,n));const r=this.getTheme();r&&t.setAttribute(be,r);const i=this.getStyle();return i&&S(t.style,i),{element:t}}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,t=!0){if(!te(y(),"@lexical/code")){_e();const t=$e(e);if(t)return t}const{anchor:n,focus:r}=e,i=(n.isBefore(r)?n:r).getNode();if(b(i)){let e=ue(i);const t=[];for(;;)if(u(e))t.push(g()),e=e.getNextSibling();else{if(!ke(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(Le(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,l=i.getParentOrThrow(),c=[f(),...t];l.splice(s,0,c);const a=t[t.length-1];a?a.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(Te(i)){const{offset:t}=e.anchor;i.splice(t,0,[f()]),i.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=_();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function Ce(e,t){return p(ve).setLanguage(e).setTheme(t)}function Te(e){return e instanceof ve}function Ne(e){return{node:Ce(e.getAttribute(Se))}}function Ae(e){const t=e,n=we(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(we(t))return!0;t=t.parentElement}return!1}(t)?{node:n?Ce():null}:{node:null}}function Pe(){return{node:Ce()}}function Oe(){return{node:null}}function we(e){return null!==e.style.fontFamily.match("monospace")}function He(e){return e.classList.contains("js-file-line-container")}function $e(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(Te(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(c(t)&&c(t.getPreviousSibling())){const t=_();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class De extends T{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}$config(){return this.config("code-highlight",{extends:T})}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),n=Be(e.theme,this.__highlightType);return x(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=Be(n.theme,e.__highlightType),o=Be(n.theme,this.__highlightType);return i!==o&&(i&&N(t,i),o&&x(t,o)),r}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return Ce()}}function Be(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function Le(e="",t){return C(new De(e,t))}function ke(e){return e instanceof De}const Ee="data-language";function Fe(e){return null!==e.style.fontFamily.match("monospace")}function Me(e){let t=e.parentElement;for(;null!==t;){if(Fe(t))return!0;t=t.parentElement}return!1}const ze=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),Ke=/* @__PURE__ */e({$import:(e,t)=>[Ce(t.getAttribute(Ee)).splice(0,0,e.$importChildren(t))],match:t.tag("pre"),name:"@lexical/code/pre"}),Ie=/* @__PURE__ */e({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[Ce(t.getAttribute(Ee)).splice(0,0,e.$importChildren(t))]:n()},match:t.tag("code"),name:"@lexical/code/code-multiline"});function je(e){if(!v(e))return!1;const t=e.style.fontFamily,n=e.style.whiteSpace;return"string"==typeof t&&/monospace/i.test(t)&&"string"==typeof n&&n.startsWith("pre")}function Je(e){let t=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(e.childNodes))if(v(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),t=!0):"BR"===s.tagName?(o(),n.push(""),t=!0):(r+=s.textContent||"",i=!0);else if(P(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function Re(e){for(const t of Array.from(e.children)){if(v(t)&&je(t)){if(null!==Je(t))return!0;const e=t.nextElementSibling;if(e&&je(e))return!0;continue}if(Re(t))return!0}return!1}const We=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t,n)=>{if(!je(t)||Me(t))return n();const r=Je(t);return null===r||0===r.length?n():[Ce().splice(0,0,O(r.join("\n")))]},match:t.tag("div"),name:"@lexical/code/vscode-wrapper"}),/* @__PURE__ */e({$import:(e,t,n)=>{if(!je(t)||Me(t))return n();const r=t.previousElementSibling;if(r&&je(r))return[];const i=[];let o=t;for(;o&&je(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[Ce().splice(0,0,O(i.join("\n")))]},match:t.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),qe=/* @__PURE__ */e({$import:(e,t,n)=>Fe(t)?[Ce().splice(0,0,e.$importChildren(t))]:Me(t)?e.$importChildren(t):n(),match:t.tag("div"),name:"@lexical/code/div"}),Ue=[/* @__PURE__ */e({$import:(e,t)=>[Ce().splice(0,0,e.$importChildren(t,{rules:ze}))],match:t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),Ie,Ke,qe],Ve=/* @__PURE__ */w({dependencies:[i,/* @__PURE__ */E(o,{preprocess:[(e,t,r)=>{Re(A(e)?e.body:e)&&t.session.update(n,e=>[...e,We]),r()}],rules:Ue})],name:"@lexical/code",nodes:()=>[ve,De],register:e=>H(e.registerCommand($,e=>{const t=D();return!(!B(t)||!$e(t))&&(e.preventDefault(),!0)},L),e.registerNodeTransform(k,e=>{0!==e.getFormat()&&Te(e.getParent())&&e.setFormat(0)}))}),Ge=/* @__PURE__ */w({dependencies:[Ve],name:"@lexical/code/Import"});function Qe(e){if(!B(e))return!1;const t=e.anchor.getNode(),n=Te(t)?t:t.getParent(),r=e.focus.getNode(),i=Te(r)?r:r.getParent();return Te(n)&&n.is(i)}function Xe(e){const t=e.getNodes(),n=[];if(1===t.length&&Te(t[0]))return n;let r=[];for(let e=0;e<t.length;e++){const i=t[e];ke(i)||u(i)||c(i)||se(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const t=e.isBackward()?e.anchor:e.focus,i=G(r[0].getKey(),0,"text");t.is(i)||n.push(r)}return n}function Ye(e,t){const n=D();if(!B(n)||!Qe(n))return!1;const r=Xe(n),i=r.length;if(0===i&&n.isCollapsed())return e===W&&n.insertNodes([g()]),!0;if(0===i&&e===W&&"\n"===n.getTextContent()){const e=g(),t=f(),r=n.isBackward()?"previous":"next";return n.insertNodes([e,t]),Q(X(Y(Z(e,"next",0),ee(h(t,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=ue(r)),e===W){const e=g();if(r.insertBefore(e),0===o){const t=n.isBackward()?"focus":"anchor",i=G(r.getKey(),0,"text");n[t].is(i)&&n[t].set(e.getKey(),0,"text")}}else u(r)?r.remove():void 0!==t&&ke(r)&&pe(r,t,n)}}return!0}function Ze(e,t){const n=D();if(!B(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),a=i.getNode(),g=e===K;if(!Qe(n)||!ke(l)&&!u(l)||!ke(a)&&!u(a))return!1;if(!t.altKey){if(n.isCollapsed()){const e=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let f,h;if(l.isBefore(a)?(f=ue(l),h=ce(a)):(f=ue(a),h=ce(l)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const t=p[e];if(!ke(t)&&!u(t)&&!c(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?f.getPreviousSibling():h.getNextSibling();if(!c(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=ke(m)||u(m)||c(m)?g?ue(m):ce(m):null;let S=null!=x?x:m;return d.remove(),p.forEach(e=>e.remove()),e===K?(p.forEach(e=>S.insertBefore(e)),S.insertBefore(d)):(S.insertAfter(d),S=d,p.forEach(e=>{S.insertAfter(e),S=e})),n.setTextNodeRange(l,o,a,s),!0}function et(e,t){const n=D();if(!B(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=e===U;if(!Qe(n)||!ke(o)&&!u(o)||!ke(s)&&!u(s))return!1;const a=s,g="rtl"===ae(a)?!l:l,f=r.key,h=r.offset,p=r.type;if(g){const e=ge(a,i.offset);if(null!==e){const{node:t,offset:r}=e;c(t)?t.selectNext(0,0):n.setTextNodeRange(t,r,t,r)}else a.getParentOrThrow().selectStart()}else{fe(a).select()}return t.shiftKey&&n.anchor.set(f,h,p),t.preventDefault(),t.stopPropagation(),!0}function tt(e,t,n){return H(...n?[e.registerCommand(M,e=>!e.altKey&&ie(Te,e),L),e.registerCommand(z,e=>ie(Te,e),L),e.registerCommand(K,e=>!e.altKey&&oe(Te,e),L),e.registerCommand(I,e=>oe(Te,e),L)]:[],e.registerCommand(j,t=>{const n=function(e){const t=D();if(!B(t)||!Qe(t))return null;const n=e?q:W,r=e?q:J,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Xe(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&se(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=ue(l[0]),g=ce(l[0]),f=G(a.getKey(),0,"text"),h=G(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(f)||h.isBefore(c)?n:f.isBefore(u)||c.isBefore(h)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n,void 0),!0)},L),e.registerCommand(J,()=>!!Qe(D())&&(R([g()]),!0),L),e.registerCommand(W,()=>Ye(W),L),e.registerCommand(q,()=>Ye(q,t),L),e.registerCommand(K,e=>{const t=D();if(!B(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Qe(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&Te(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):Ze(K,e)},L),e.registerCommand(M,e=>{const t=D();if(!B(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Qe(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&Te(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Ze(M,e))},L),e.registerCommand(U,e=>et(U,e),L),e.registerCommand(V,e=>et(V,e),L))}const nt=/* @__PURE__ */w({build:(e,t)=>re(t),config:/* @__PURE__ */F({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[Ve],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return ne(()=>{if(!r.disabled.value)return tt(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{Le as $createCodeHighlightNode,Ce as $createCodeNode,ae as $getCodeLineDirection,fe as $getEndOfCodeInLine,ue as $getFirstCodeNodeOfLine,ce as $getLastCodeNodeOfLine,ge as $getStartOfCodeInLine,ke as $isCodeHighlightNode,Te as $isCodeNode,pe as $outdentLeadingSpaces,he as $plainifyCodeContent,Ve as CodeExtension,De as CodeHighlightNode,Ge as CodeImportExtension,Ue as CodeImportRules,nt as CodeIndentExtension,ve as CodeNode,de as DEFAULT_CODE_LANGUAGE,me as getDefaultCodeLanguage,tt as registerCodeIndentation};
|
package/package.json
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.48.0",
|
|
11
|
+
"version": "0.48.1-nightly.20260720.0",
|
|
12
12
|
"main": "./dist/LexicalCodeCore.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/extension": "0.48.0",
|
|
16
|
-
"@lexical/
|
|
17
|
-
"@lexical/
|
|
18
|
-
"@lexical/
|
|
19
|
-
"lexical": "0.48.0"
|
|
15
|
+
"@lexical/extension": "0.48.1-nightly.20260720.0",
|
|
16
|
+
"@lexical/html": "0.48.1-nightly.20260720.0",
|
|
17
|
+
"@lexical/utils": "0.48.1-nightly.20260720.0",
|
|
18
|
+
"@lexical/internal": "0.48.1-nightly.20260720.0",
|
|
19
|
+
"lexical": "0.48.1-nightly.20260720.0"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
package/src/CodeHighlightNode.ts
CHANGED
|
@@ -44,16 +44,8 @@ export class CodeHighlightNode extends TextNode {
|
|
|
44
44
|
this.__highlightType = highlightType;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
return 'code-highlight';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
static clone(node: CodeHighlightNode): CodeHighlightNode {
|
|
52
|
-
return new CodeHighlightNode(
|
|
53
|
-
node.__text,
|
|
54
|
-
node.__highlightType || undefined,
|
|
55
|
-
node.__key,
|
|
56
|
-
);
|
|
47
|
+
$config() {
|
|
48
|
+
return this.config('code-highlight', {extends: TextNode});
|
|
57
49
|
}
|
|
58
50
|
|
|
59
51
|
afterCloneFrom(prevNode: this): void {
|
|
@@ -107,12 +99,6 @@ export class CodeHighlightNode extends TextNode {
|
|
|
107
99
|
return update;
|
|
108
100
|
}
|
|
109
101
|
|
|
110
|
-
static importJSON(
|
|
111
|
-
serializedNode: SerializedCodeHighlightNode,
|
|
112
|
-
): CodeHighlightNode {
|
|
113
|
-
return $createCodeHighlightNode().updateFromJSON(serializedNode);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
102
|
updateFromJSON(
|
|
117
103
|
serializedNode: LexicalUpdateJSON<SerializedCodeHighlightNode>,
|
|
118
104
|
): this {
|
package/src/CodeNode.ts
CHANGED
|
@@ -21,7 +21,6 @@ import {
|
|
|
21
21
|
$isTabNode,
|
|
22
22
|
$isTextNode,
|
|
23
23
|
addClassNamesToElement,
|
|
24
|
-
type DOMConversionMap,
|
|
25
24
|
type DOMConversionOutput,
|
|
26
25
|
type DOMExportOutput,
|
|
27
26
|
type EditorConfig,
|
|
@@ -87,15 +86,80 @@ export class CodeNode extends ElementNode {
|
|
|
87
86
|
/** @internal */
|
|
88
87
|
__isSyntaxHighlightSupported: boolean;
|
|
89
88
|
|
|
90
|
-
|
|
91
|
-
return 'code'
|
|
92
|
-
|
|
89
|
+
$config() {
|
|
90
|
+
return this.config('code', {
|
|
91
|
+
extends: ElementNode,
|
|
92
|
+
importDOM: {
|
|
93
|
+
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
94
|
+
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
95
|
+
// inline format handled by TextNode otherwise.
|
|
96
|
+
code: (node: Node) => {
|
|
97
|
+
const isMultiLine =
|
|
98
|
+
node.textContent != null &&
|
|
99
|
+
(/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
|
|
100
|
+
|
|
101
|
+
return isMultiLine
|
|
102
|
+
? {
|
|
103
|
+
conversion: $convertPreElement,
|
|
104
|
+
priority: 1,
|
|
105
|
+
}
|
|
106
|
+
: null;
|
|
107
|
+
},
|
|
108
|
+
div: () => ({
|
|
109
|
+
conversion: $convertDivElement,
|
|
110
|
+
priority: 1,
|
|
111
|
+
}),
|
|
112
|
+
pre: () => ({
|
|
113
|
+
conversion: $convertPreElement,
|
|
114
|
+
priority: 0,
|
|
115
|
+
}),
|
|
116
|
+
table: (node: Node) => {
|
|
117
|
+
const table = node;
|
|
118
|
+
// domNode is a <table> since we matched it by nodeName
|
|
119
|
+
if (isGitHubCodeTable(table as HTMLTableElement)) {
|
|
120
|
+
return {
|
|
121
|
+
conversion: $convertTableElement,
|
|
122
|
+
priority: 3,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return null;
|
|
126
|
+
},
|
|
127
|
+
td: (node: Node) => {
|
|
128
|
+
// element is a <td> since we matched it by nodeName
|
|
129
|
+
const td = node as HTMLTableCellElement;
|
|
130
|
+
const table: HTMLTableElement | null = td.closest('table');
|
|
131
|
+
|
|
132
|
+
if (isGitHubCodeCell(td) || (table && isGitHubCodeTable(table))) {
|
|
133
|
+
// Return a no-op if it's a table cell in a code table, but not a code line.
|
|
134
|
+
// Otherwise it'll fall back to the T
|
|
135
|
+
return {
|
|
136
|
+
conversion: convertCodeNoop,
|
|
137
|
+
priority: 3,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
93
140
|
|
|
94
|
-
|
|
95
|
-
|
|
141
|
+
return null;
|
|
142
|
+
},
|
|
143
|
+
tr: (node: Node) => {
|
|
144
|
+
// element is a <tr> since we matched it by nodeName
|
|
145
|
+
const tr = node as HTMLTableCellElement;
|
|
146
|
+
const table: HTMLTableElement | null = tr.closest('table');
|
|
147
|
+
if (table && isGitHubCodeTable(table)) {
|
|
148
|
+
return {
|
|
149
|
+
conversion: convertCodeNoop,
|
|
150
|
+
priority: 3,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
});
|
|
96
157
|
}
|
|
97
158
|
|
|
98
|
-
|
|
159
|
+
// `language` carries an explicit `undefined` default so the constructor
|
|
160
|
+
// reports zero required arguments and `$config` can synthesize the static
|
|
161
|
+
// `clone` from the no-argument constructor.
|
|
162
|
+
constructor(language: string | null | undefined = undefined, key?: NodeKey) {
|
|
99
163
|
super(key);
|
|
100
164
|
this.__language = language || undefined;
|
|
101
165
|
this.__isSyntaxHighlightSupported = false;
|
|
@@ -206,77 +270,6 @@ export class CodeNode extends ElementNode {
|
|
|
206
270
|
return {element};
|
|
207
271
|
}
|
|
208
272
|
|
|
209
|
-
static importDOM(): DOMConversionMap | null {
|
|
210
|
-
return {
|
|
211
|
-
// Typically <pre> is used for code blocks, and <code> for inline code styles
|
|
212
|
-
// but if it's a multi line <code> we'll create a block. Pass through to
|
|
213
|
-
// inline format handled by TextNode otherwise.
|
|
214
|
-
code: (node: Node) => {
|
|
215
|
-
const isMultiLine =
|
|
216
|
-
node.textContent != null &&
|
|
217
|
-
(/\r?\n/.test(node.textContent) || hasChildDOMNodeTag(node, 'BR'));
|
|
218
|
-
|
|
219
|
-
return isMultiLine
|
|
220
|
-
? {
|
|
221
|
-
conversion: $convertPreElement,
|
|
222
|
-
priority: 1,
|
|
223
|
-
}
|
|
224
|
-
: null;
|
|
225
|
-
},
|
|
226
|
-
div: () => ({
|
|
227
|
-
conversion: $convertDivElement,
|
|
228
|
-
priority: 1,
|
|
229
|
-
}),
|
|
230
|
-
pre: () => ({
|
|
231
|
-
conversion: $convertPreElement,
|
|
232
|
-
priority: 0,
|
|
233
|
-
}),
|
|
234
|
-
table: (node: Node) => {
|
|
235
|
-
const table = node;
|
|
236
|
-
// domNode is a <table> since we matched it by nodeName
|
|
237
|
-
if (isGitHubCodeTable(table as HTMLTableElement)) {
|
|
238
|
-
return {
|
|
239
|
-
conversion: $convertTableElement,
|
|
240
|
-
priority: 3,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
return null;
|
|
244
|
-
},
|
|
245
|
-
td: (node: Node) => {
|
|
246
|
-
// element is a <td> since we matched it by nodeName
|
|
247
|
-
const td = node as HTMLTableCellElement;
|
|
248
|
-
const table: HTMLTableElement | null = td.closest('table');
|
|
249
|
-
|
|
250
|
-
if (isGitHubCodeCell(td) || (table && isGitHubCodeTable(table))) {
|
|
251
|
-
// Return a no-op if it's a table cell in a code table, but not a code line.
|
|
252
|
-
// Otherwise it'll fall back to the T
|
|
253
|
-
return {
|
|
254
|
-
conversion: convertCodeNoop,
|
|
255
|
-
priority: 3,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
return null;
|
|
260
|
-
},
|
|
261
|
-
tr: (node: Node) => {
|
|
262
|
-
// element is a <tr> since we matched it by nodeName
|
|
263
|
-
const tr = node as HTMLTableCellElement;
|
|
264
|
-
const table: HTMLTableElement | null = tr.closest('table');
|
|
265
|
-
if (table && isGitHubCodeTable(table)) {
|
|
266
|
-
return {
|
|
267
|
-
conversion: convertCodeNoop,
|
|
268
|
-
priority: 3,
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
return null;
|
|
272
|
-
},
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
static importJSON(serializedNode: SerializedCodeNode): CodeNode {
|
|
277
|
-
return $createCodeNode().updateFromJSON(serializedNode);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
273
|
updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedCodeNode>): this {
|
|
281
274
|
return super
|
|
282
275
|
.updateFromJSON(serializedNode)
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
type RangeSelection,
|
|
22
22
|
type SiblingCaret,
|
|
23
23
|
type TabNode,
|
|
24
|
+
type TextNode,
|
|
24
25
|
tokenizeRawText,
|
|
25
26
|
} from 'lexical';
|
|
26
27
|
|
|
@@ -30,11 +31,15 @@ import {
|
|
|
30
31
|
type CodeHighlightNode,
|
|
31
32
|
} from './CodeHighlightNode';
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// The anchor is generic (rather than the narrower
|
|
35
|
+
// `CodeHighlightNode | TabNode | LineBreakNode`) because callers may have only
|
|
36
|
+
// narrowed as far as TextNode; the matched siblings are always
|
|
37
|
+
// CodeHighlightNode/TabNode, and an unmatched anchor is returned unchanged.
|
|
38
|
+
function $getLastMatchingCodeNode<
|
|
39
|
+
T extends TextNode | LineBreakNode,
|
|
40
|
+
D extends CaretDirection,
|
|
41
|
+
>(anchor: T, direction: D): T | CodeHighlightNode | TabNode {
|
|
42
|
+
let matchingNode: T | CodeHighlightNode | TabNode = anchor;
|
|
38
43
|
for (
|
|
39
44
|
let caret: null | SiblingCaret<LexicalNode, D> = $getSiblingCaret(
|
|
40
45
|
anchor,
|
|
@@ -48,15 +53,15 @@ function $getLastMatchingCodeNode<D extends CaretDirection>(
|
|
|
48
53
|
return matchingNode;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
export function $getFirstCodeNodeOfLine(
|
|
52
|
-
anchor:
|
|
53
|
-
):
|
|
56
|
+
export function $getFirstCodeNodeOfLine<T extends TextNode | LineBreakNode>(
|
|
57
|
+
anchor: T,
|
|
58
|
+
): T | CodeHighlightNode | TabNode {
|
|
54
59
|
return $getLastMatchingCodeNode(anchor, 'previous');
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
export function $getLastCodeNodeOfLine(
|
|
58
|
-
anchor:
|
|
59
|
-
):
|
|
62
|
+
export function $getLastCodeNodeOfLine<T extends TextNode | LineBreakNode>(
|
|
63
|
+
anchor: T,
|
|
64
|
+
): T | CodeHighlightNode | TabNode {
|
|
60
65
|
return $getLastMatchingCodeNode(anchor, 'next');
|
|
61
66
|
}
|
|
62
67
|
|