@react-fabric/lexical 1.0.0-beta.47 → 1.0.0-beta.48
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/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +9 -9
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +142 -75
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +25 -21
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +10 -3
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +147 -103
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +254 -178
- package/dist/cjs/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +19 -16
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +53 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +176 -194
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +25 -18
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +1925 -793
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +48 -40
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +426 -144
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +11 -1
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +46 -32
- package/dist/cjs/node_modules/prismjs/prism.js +1 -1
- package/dist/cjs/packages/lexical/src/editor/LexicalEditor.js +1 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +29 -19
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.js +1 -1
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +139 -76
- package/dist/esm/node_modules/@lexical/code/LexicalCode.js +1 -1
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +11 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.js +1 -1
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +149 -105
- package/dist/esm/node_modules/@lexical/link/LexicalLink.js +1 -1
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +253 -180
- package/dist/esm/node_modules/@lexical/list/LexicalList.js +1 -1
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -30
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.js +1 -1
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +171 -196
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +1 -1
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +1920 -796
- package/dist/esm/node_modules/@lexical/table/LexicalTable.js +1 -1
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +413 -145
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +7 -2
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
- package/dist/esm/node_modules/prismjs/prism.js +1 -1
- package/dist/esm/packages/lexical/src/editor/LexicalEditor.js +1 -1
- package/package.json +7 -8
- package/src/components/StickyComponent.tsx +1 -1
- package/src/editor/LexicalEditor.tsx +25 -21
- package/src/plugins/ToolbarPlugin.tsx +20 -4
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { addClassNamesToElement, removeClassNamesFromElement, mergeRegister, isHTMLElement, $getAdjacentCaret } from '../utils/LexicalUtils.js';
|
|
4
|
+
import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabNode, $createLineBreakNode, $applyNodeReplacement, TextNode, $isLineBreakNode, $getNodeByKey, KEY_TAB_COMMAND, COMMAND_PRIORITY_LOW, INSERT_TAB_COMMAND, $getSelection, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, $isRangeSelection, KEY_ARROW_DOWN_COMMAND, MOVE_TO_START, MOVE_TO_END, $getSiblingCaret, $createTextNode } from 'lexical';
|
|
3
5
|
import '../../prismjs/prism.js';
|
|
4
6
|
import '../../prismjs/components/prism-clike.js';
|
|
5
7
|
import '../../prismjs/components/prism-javascript.js';
|
|
@@ -16,8 +18,6 @@ import '../../prismjs/components/prism-swift.js';
|
|
|
16
18
|
import '../../prismjs/components/prism-typescript.js';
|
|
17
19
|
import '../../prismjs/components/prism-java.js';
|
|
18
20
|
import '../../prismjs/components/prism-cpp.js';
|
|
19
|
-
import { addClassNamesToElement, removeClassNamesFromElement, mergeRegister, isHTMLElement } from '../utils/LexicalUtils.js';
|
|
20
|
-
import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabNode, $createLineBreakNode, $applyNodeReplacement, TextNode, $isLineBreakNode, $getNodeByKey, KEY_TAB_COMMAND, COMMAND_PRIORITY_LOW, INSERT_TAB_COMMAND, $getSelection, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_DOWN_COMMAND, MOVE_TO_END, MOVE_TO_START, $createTextNode, $isRangeSelection } from 'lexical';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -28,6 +28,30 @@ import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabN
|
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the MIT license found in the
|
|
35
|
+
* LICENSE file in the root directory of this source tree.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
// Do not require this module directly! Use normal `invariant` calls.
|
|
40
|
+
|
|
41
|
+
function formatDevErrorMessage(message) {
|
|
42
|
+
throw new Error(message);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
47
|
+
*
|
|
48
|
+
* This source code is licensed under the MIT license found in the
|
|
49
|
+
* LICENSE file in the root directory of this source tree.
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
const Prism = globalThis.Prism || window.Prism;
|
|
54
|
+
|
|
31
55
|
/**
|
|
32
56
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
33
57
|
*
|
|
@@ -39,7 +63,7 @@ import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabN
|
|
|
39
63
|
const isLanguageSupportedByPrism = language => {
|
|
40
64
|
try {
|
|
41
65
|
// eslint-disable-next-line no-prototype-builtins
|
|
42
|
-
return language ?
|
|
66
|
+
return language ? Prism.languages.hasOwnProperty(language) : false;
|
|
43
67
|
} catch (_unused) {
|
|
44
68
|
return false;
|
|
45
69
|
}
|
|
@@ -70,7 +94,7 @@ class CodeNode extends ElementNode {
|
|
|
70
94
|
}
|
|
71
95
|
constructor(language, key) {
|
|
72
96
|
super(key);
|
|
73
|
-
this.__language = language;
|
|
97
|
+
this.__language = language || undefined;
|
|
74
98
|
this.__isSyntaxHighlightSupported = isLanguageSupportedByPrism(language);
|
|
75
99
|
}
|
|
76
100
|
|
|
@@ -181,18 +205,15 @@ class CodeNode extends ElementNode {
|
|
|
181
205
|
};
|
|
182
206
|
}
|
|
183
207
|
static importJSON(serializedNode) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return node;
|
|
208
|
+
return $createCodeNode().updateFromJSON(serializedNode);
|
|
209
|
+
}
|
|
210
|
+
updateFromJSON(serializedNode) {
|
|
211
|
+
return super.updateFromJSON(serializedNode).setLanguage(serializedNode.language);
|
|
189
212
|
}
|
|
190
213
|
exportJSON() {
|
|
191
214
|
return {
|
|
192
215
|
...super.exportJSON(),
|
|
193
|
-
language: this.getLanguage()
|
|
194
|
-
type: 'code',
|
|
195
|
-
version: 1
|
|
216
|
+
language: this.getLanguage()
|
|
196
217
|
};
|
|
197
218
|
}
|
|
198
219
|
|
|
@@ -218,7 +239,7 @@ class CodeNode extends ElementNode {
|
|
|
218
239
|
const firstPoint = anchor.isBefore(focus) ? anchor : focus;
|
|
219
240
|
const firstSelectionNode = firstPoint.getNode();
|
|
220
241
|
if ($isTextNode(firstSelectionNode)) {
|
|
221
|
-
let node = getFirstCodeNodeOfLine(firstSelectionNode);
|
|
242
|
+
let node = $getFirstCodeNodeOfLine(firstSelectionNode);
|
|
222
243
|
const insertNodes = [];
|
|
223
244
|
// eslint-disable-next-line no-constant-condition
|
|
224
245
|
while (true) {
|
|
@@ -279,8 +300,9 @@ class CodeNode extends ElementNode {
|
|
|
279
300
|
}
|
|
280
301
|
setLanguage(language) {
|
|
281
302
|
const writable = this.getWritable();
|
|
282
|
-
writable.__language = language;
|
|
303
|
+
writable.__language = language || undefined;
|
|
283
304
|
writable.__isSyntaxHighlightSupported = isLanguageSupportedByPrism(language);
|
|
305
|
+
return writable;
|
|
284
306
|
}
|
|
285
307
|
getLanguage() {
|
|
286
308
|
return this.getLatest().__language;
|
|
@@ -390,16 +412,16 @@ function getLanguageFriendlyName(lang) {
|
|
|
390
412
|
return CODE_LANGUAGE_FRIENDLY_NAME_MAP[_lang] || _lang;
|
|
391
413
|
}
|
|
392
414
|
const getDefaultCodeLanguage = () => DEFAULT_CODE_LANGUAGE;
|
|
393
|
-
const getCodeLanguages = () => Object.keys(
|
|
415
|
+
const getCodeLanguages = () => Object.keys(Prism.languages).filter(
|
|
394
416
|
// Prism has several language helpers mixed into languages object
|
|
395
417
|
// so filtering them out here to get langs list
|
|
396
|
-
language => typeof
|
|
418
|
+
language => typeof Prism.languages[language] !== 'function').sort();
|
|
397
419
|
|
|
398
420
|
/** @noInheritDoc */
|
|
399
421
|
class CodeHighlightNode extends TextNode {
|
|
400
422
|
/** @internal */
|
|
401
423
|
|
|
402
|
-
constructor(text, highlightType, key) {
|
|
424
|
+
constructor(text = '', highlightType, key) {
|
|
403
425
|
super(text, key);
|
|
404
426
|
this.__highlightType = highlightType;
|
|
405
427
|
}
|
|
@@ -413,6 +435,11 @@ class CodeHighlightNode extends TextNode {
|
|
|
413
435
|
const self = this.getLatest();
|
|
414
436
|
return self.__highlightType;
|
|
415
437
|
}
|
|
438
|
+
setHighlightType(highlightType) {
|
|
439
|
+
const self = this.getWritable();
|
|
440
|
+
self.__highlightType = highlightType || undefined;
|
|
441
|
+
return self;
|
|
442
|
+
}
|
|
416
443
|
canHaveFormat() {
|
|
417
444
|
return false;
|
|
418
445
|
}
|
|
@@ -437,19 +464,15 @@ class CodeHighlightNode extends TextNode {
|
|
|
437
464
|
return update;
|
|
438
465
|
}
|
|
439
466
|
static importJSON(serializedNode) {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
node.setStyle(serializedNode.style);
|
|
445
|
-
return node;
|
|
467
|
+
return $createCodeHighlightNode().updateFromJSON(serializedNode);
|
|
468
|
+
}
|
|
469
|
+
updateFromJSON(serializedNode) {
|
|
470
|
+
return super.updateFromJSON(serializedNode).setHighlightType(serializedNode.highlightType);
|
|
446
471
|
}
|
|
447
472
|
exportJSON() {
|
|
448
473
|
return {
|
|
449
474
|
...super.exportJSON(),
|
|
450
|
-
highlightType: this.getHighlightType()
|
|
451
|
-
type: 'code-highlight',
|
|
452
|
-
version: 1
|
|
475
|
+
highlightType: this.getHighlightType()
|
|
453
476
|
};
|
|
454
477
|
}
|
|
455
478
|
|
|
@@ -467,46 +490,33 @@ class CodeHighlightNode extends TextNode {
|
|
|
467
490
|
function getHighlightThemeClass(theme, highlightType) {
|
|
468
491
|
return highlightType && theme && theme.codeHighlight && theme.codeHighlight[highlightType];
|
|
469
492
|
}
|
|
470
|
-
function $createCodeHighlightNode(text, highlightType) {
|
|
493
|
+
function $createCodeHighlightNode(text = '', highlightType) {
|
|
471
494
|
return $applyNodeReplacement(new CodeHighlightNode(text, highlightType));
|
|
472
495
|
}
|
|
473
496
|
function $isCodeHighlightNode(node) {
|
|
474
497
|
return node instanceof CodeHighlightNode;
|
|
475
498
|
}
|
|
476
|
-
function
|
|
477
|
-
let
|
|
478
|
-
let
|
|
479
|
-
|
|
480
|
-
previousNode = node;
|
|
481
|
-
node = node.getPreviousSibling();
|
|
499
|
+
function $getLastMatchingCodeNode(anchor, direction) {
|
|
500
|
+
let matchingNode = anchor;
|
|
501
|
+
for (let caret = $getSiblingCaret(anchor, direction); caret && ($isCodeHighlightNode(caret.origin) || $isTabNode(caret.origin)); caret = $getAdjacentCaret(caret)) {
|
|
502
|
+
matchingNode = caret.origin;
|
|
482
503
|
}
|
|
483
|
-
return
|
|
504
|
+
return matchingNode;
|
|
484
505
|
}
|
|
485
|
-
function
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
node = node.getNextSibling();
|
|
491
|
-
}
|
|
492
|
-
return nextNode;
|
|
506
|
+
function $getFirstCodeNodeOfLine(anchor) {
|
|
507
|
+
return $getLastMatchingCodeNode(anchor, 'previous');
|
|
508
|
+
}
|
|
509
|
+
function $getLastCodeNodeOfLine(anchor) {
|
|
510
|
+
return $getLastMatchingCodeNode(anchor, 'next');
|
|
493
511
|
}
|
|
494
|
-
|
|
495
|
-
/**
|
|
496
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
497
|
-
*
|
|
498
|
-
* This source code is licensed under the MIT license found in the
|
|
499
|
-
* LICENSE file in the root directory of this source tree.
|
|
500
|
-
*
|
|
501
|
-
*/
|
|
502
512
|
|
|
503
513
|
const PrismTokenizer = {
|
|
504
514
|
defaultLanguage: DEFAULT_CODE_LANGUAGE,
|
|
505
515
|
tokenize(code, language) {
|
|
506
|
-
return
|
|
516
|
+
return Prism.tokenize(code, Prism.languages[language || ''] || Prism.languages[this.defaultLanguage]);
|
|
507
517
|
}
|
|
508
518
|
};
|
|
509
|
-
function getStartOfCodeInLine(anchor, offset) {
|
|
519
|
+
function $getStartOfCodeInLine(anchor, offset) {
|
|
510
520
|
let last = null;
|
|
511
521
|
let lastNonBlank = null;
|
|
512
522
|
let node = anchor;
|
|
@@ -520,7 +530,7 @@ function getStartOfCodeInLine(anchor, offset) {
|
|
|
520
530
|
break;
|
|
521
531
|
}
|
|
522
532
|
if (!($isCodeHighlightNode(node) || $isTabNode(node) || $isLineBreakNode(node))) {
|
|
523
|
-
|
|
533
|
+
formatDevErrorMessage(`Expected a valid Code Node: CodeHighlightNode, TabNode, LineBreakNode`);
|
|
524
534
|
}
|
|
525
535
|
if ($isLineBreakNode(node)) {
|
|
526
536
|
last = {
|
|
@@ -599,10 +609,10 @@ function findNextNonBlankInLine(anchor, offset) {
|
|
|
599
609
|
}
|
|
600
610
|
}
|
|
601
611
|
}
|
|
602
|
-
function getEndOfCodeInLine(anchor) {
|
|
603
|
-
const lastNode = getLastCodeNodeOfLine(anchor);
|
|
612
|
+
function $getEndOfCodeInLine(anchor) {
|
|
613
|
+
const lastNode = $getLastCodeNodeOfLine(anchor);
|
|
604
614
|
if (!!$isLineBreakNode(lastNode)) {
|
|
605
|
-
|
|
615
|
+
formatDevErrorMessage(`Unexpected lineBreakNode in getEndOfCodeInLine`);
|
|
606
616
|
}
|
|
607
617
|
return lastNode;
|
|
608
618
|
}
|
|
@@ -835,7 +845,7 @@ function $getCodeLines(selection) {
|
|
|
835
845
|
for (let i = 0; i < nodes.length; i++) {
|
|
836
846
|
const node = nodes[i];
|
|
837
847
|
if (!($isCodeHighlightNode(node) || $isTabNode(node) || $isLineBreakNode(node))) {
|
|
838
|
-
|
|
848
|
+
formatDevErrorMessage(`Expected selection to be inside CodeBlock and consisting of CodeHighlightNode, TabNode and LineBreakNode`);
|
|
839
849
|
}
|
|
840
850
|
if ($isLineBreakNode(node)) {
|
|
841
851
|
if (i !== 0 && lastLine.length > 0) {
|
|
@@ -864,13 +874,13 @@ function $handleTab(shiftKey) {
|
|
|
864
874
|
const selectionNodes = selection.getNodes();
|
|
865
875
|
const firstNode = selectionNodes[0];
|
|
866
876
|
if (!($isCodeNode(firstNode) || $isCodeHighlightNode(firstNode) || $isTabNode(firstNode) || $isLineBreakNode(firstNode))) {
|
|
867
|
-
|
|
877
|
+
formatDevErrorMessage(`Expected selection firstNode to be CodeHighlightNode or TabNode`);
|
|
868
878
|
}
|
|
869
879
|
if ($isCodeNode(firstNode)) {
|
|
870
880
|
return indentOrOutdent;
|
|
871
881
|
}
|
|
872
|
-
const firstOfLine = getFirstCodeNodeOfLine(firstNode);
|
|
873
|
-
const lastOfLine = getLastCodeNodeOfLine(firstNode);
|
|
882
|
+
const firstOfLine = $getFirstCodeNodeOfLine(firstNode);
|
|
883
|
+
const lastOfLine = $getLastCodeNodeOfLine(firstNode);
|
|
874
884
|
const anchor = selection.anchor;
|
|
875
885
|
const focus = selection.focus;
|
|
876
886
|
let selectionFirst;
|
|
@@ -903,7 +913,7 @@ function $handleMultilineIndent(type) {
|
|
|
903
913
|
let firstOfLine = line[0];
|
|
904
914
|
// First and last lines might not be complete
|
|
905
915
|
if (i === 0) {
|
|
906
|
-
firstOfLine = getFirstCodeNodeOfLine(firstOfLine);
|
|
916
|
+
firstOfLine = $getFirstCodeNodeOfLine(firstOfLine);
|
|
907
917
|
}
|
|
908
918
|
if (firstOfLine !== null) {
|
|
909
919
|
if (type === INDENT_CONTENT_COMMAND) {
|
|
@@ -920,7 +930,7 @@ function $handleMultilineIndent(type) {
|
|
|
920
930
|
const selectionNodes = selection.getNodes();
|
|
921
931
|
const firstNode = selectionNodes[0];
|
|
922
932
|
if (!($isCodeNode(firstNode) || $isCodeHighlightNode(firstNode) || $isTabNode(firstNode) || $isLineBreakNode(firstNode))) {
|
|
923
|
-
|
|
933
|
+
formatDevErrorMessage(`Expected selection firstNode to be CodeHighlightNode or CodeTabNode`);
|
|
924
934
|
}
|
|
925
935
|
if ($isCodeNode(firstNode)) {
|
|
926
936
|
// CodeNode is empty
|
|
@@ -929,10 +939,7 @@ function $handleMultilineIndent(type) {
|
|
|
929
939
|
}
|
|
930
940
|
return true;
|
|
931
941
|
}
|
|
932
|
-
const firstOfLine = getFirstCodeNodeOfLine(firstNode);
|
|
933
|
-
if (!(firstOfLine !== null)) {
|
|
934
|
-
throw Error(`Expected getFirstCodeNodeOfLine to return a valid Code Node`);
|
|
935
|
-
}
|
|
942
|
+
const firstOfLine = $getFirstCodeNodeOfLine(firstNode);
|
|
936
943
|
if (type === INDENT_CONTENT_COMMAND) {
|
|
937
944
|
if ($isLineBreakNode(firstOfLine)) {
|
|
938
945
|
firstOfLine.insertAfter($createTabNode());
|
|
@@ -993,11 +1000,11 @@ function $handleShiftLines(type, event) {
|
|
|
993
1000
|
let start;
|
|
994
1001
|
let end;
|
|
995
1002
|
if (anchorNode.isBefore(focusNode)) {
|
|
996
|
-
start = getFirstCodeNodeOfLine(anchorNode);
|
|
997
|
-
end = getLastCodeNodeOfLine(focusNode);
|
|
1003
|
+
start = $getFirstCodeNodeOfLine(anchorNode);
|
|
1004
|
+
end = $getLastCodeNodeOfLine(focusNode);
|
|
998
1005
|
} else {
|
|
999
|
-
start = getFirstCodeNodeOfLine(focusNode);
|
|
1000
|
-
end = getLastCodeNodeOfLine(anchorNode);
|
|
1006
|
+
start = $getFirstCodeNodeOfLine(focusNode);
|
|
1007
|
+
end = $getLastCodeNodeOfLine(anchorNode);
|
|
1001
1008
|
}
|
|
1002
1009
|
if (start == null || end == null) {
|
|
1003
1010
|
return false;
|
|
@@ -1024,7 +1031,7 @@ function $handleShiftLines(type, event) {
|
|
|
1024
1031
|
if (sibling == null) {
|
|
1025
1032
|
return true;
|
|
1026
1033
|
}
|
|
1027
|
-
const maybeInsertionPoint = $isCodeHighlightNode(sibling) || $isTabNode(sibling) || $isLineBreakNode(sibling) ? arrowIsUp ? getFirstCodeNodeOfLine(sibling) : getLastCodeNodeOfLine(sibling) : null;
|
|
1034
|
+
const maybeInsertionPoint = $isCodeHighlightNode(sibling) || $isTabNode(sibling) || $isLineBreakNode(sibling) ? arrowIsUp ? $getFirstCodeNodeOfLine(sibling) : $getLastCodeNodeOfLine(sibling) : null;
|
|
1028
1035
|
let insertionPoint = maybeInsertionPoint != null ? maybeInsertionPoint : sibling;
|
|
1029
1036
|
linebreak.remove();
|
|
1030
1037
|
range.forEach(node => node.remove());
|
|
@@ -1054,11 +1061,13 @@ function $handleMoveTo(type, event) {
|
|
|
1054
1061
|
const anchorNode = anchor.getNode();
|
|
1055
1062
|
const focusNode = focus.getNode();
|
|
1056
1063
|
const isMoveToStart = type === MOVE_TO_START;
|
|
1057
|
-
|
|
1064
|
+
|
|
1065
|
+
// Ensure the selection is within the codeblock
|
|
1066
|
+
if (!$isSelectionInCode(selection) || !($isCodeHighlightNode(anchorNode) || $isTabNode(anchorNode)) || !($isCodeHighlightNode(focusNode) || $isTabNode(focusNode))) {
|
|
1058
1067
|
return false;
|
|
1059
1068
|
}
|
|
1060
1069
|
if (isMoveToStart) {
|
|
1061
|
-
const start = getStartOfCodeInLine(focusNode, focus.offset);
|
|
1070
|
+
const start = $getStartOfCodeInLine(focusNode, focus.offset);
|
|
1062
1071
|
if (start !== null) {
|
|
1063
1072
|
const {
|
|
1064
1073
|
node,
|
|
@@ -1073,7 +1082,7 @@ function $handleMoveTo(type, event) {
|
|
|
1073
1082
|
focusNode.getParentOrThrow().selectStart();
|
|
1074
1083
|
}
|
|
1075
1084
|
} else {
|
|
1076
|
-
const node = getEndOfCodeInLine(focusNode);
|
|
1085
|
+
const node = $getEndOfCodeInLine(focusNode);
|
|
1077
1086
|
node.select();
|
|
1078
1087
|
}
|
|
1079
1088
|
event.preventDefault();
|
|
@@ -1115,7 +1124,61 @@ function registerCodeHighlighting(editor, tokenizer) {
|
|
|
1115
1124
|
}
|
|
1116
1125
|
$insertNodes([$createTabNode()]);
|
|
1117
1126
|
return true;
|
|
1118
|
-
}, COMMAND_PRIORITY_LOW), editor.registerCommand(INDENT_CONTENT_COMMAND, payload => $handleMultilineIndent(INDENT_CONTENT_COMMAND), COMMAND_PRIORITY_LOW), editor.registerCommand(OUTDENT_CONTENT_COMMAND, payload => $handleMultilineIndent(OUTDENT_CONTENT_COMMAND), COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_UP_COMMAND,
|
|
1127
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(INDENT_CONTENT_COMMAND, payload => $handleMultilineIndent(INDENT_CONTENT_COMMAND), COMMAND_PRIORITY_LOW), editor.registerCommand(OUTDENT_CONTENT_COMMAND, payload => $handleMultilineIndent(OUTDENT_CONTENT_COMMAND), COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_UP_COMMAND, event => {
|
|
1128
|
+
const selection = $getSelection();
|
|
1129
|
+
if (!$isRangeSelection(selection)) {
|
|
1130
|
+
return false;
|
|
1131
|
+
}
|
|
1132
|
+
const {
|
|
1133
|
+
anchor
|
|
1134
|
+
} = selection;
|
|
1135
|
+
const anchorNode = anchor.getNode();
|
|
1136
|
+
if (!$isSelectionInCode(selection)) {
|
|
1137
|
+
return false;
|
|
1138
|
+
}
|
|
1139
|
+
// If at the start of a code block, prevent selection from moving out
|
|
1140
|
+
if (selection.isCollapsed() && anchor.offset === 0 && anchorNode.getPreviousSibling() === null && $isCodeNode(anchorNode.getParentOrThrow())) {
|
|
1141
|
+
event.preventDefault();
|
|
1142
|
+
return true;
|
|
1143
|
+
}
|
|
1144
|
+
return $handleShiftLines(KEY_ARROW_UP_COMMAND, event);
|
|
1145
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_DOWN_COMMAND, event => {
|
|
1146
|
+
const selection = $getSelection();
|
|
1147
|
+
if (!$isRangeSelection(selection)) {
|
|
1148
|
+
return false;
|
|
1149
|
+
}
|
|
1150
|
+
const {
|
|
1151
|
+
anchor
|
|
1152
|
+
} = selection;
|
|
1153
|
+
const anchorNode = anchor.getNode();
|
|
1154
|
+
if (!$isSelectionInCode(selection)) {
|
|
1155
|
+
return false;
|
|
1156
|
+
}
|
|
1157
|
+
// If at the end of a code block, prevent selection from moving out
|
|
1158
|
+
if (selection.isCollapsed() && anchor.offset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null && $isCodeNode(anchorNode.getParentOrThrow())) {
|
|
1159
|
+
event.preventDefault();
|
|
1160
|
+
return true;
|
|
1161
|
+
}
|
|
1162
|
+
return $handleShiftLines(KEY_ARROW_DOWN_COMMAND, event);
|
|
1163
|
+
}, COMMAND_PRIORITY_LOW), editor.registerCommand(MOVE_TO_START, event => $handleMoveTo(MOVE_TO_START, event), COMMAND_PRIORITY_LOW), editor.registerCommand(MOVE_TO_END, event => $handleMoveTo(MOVE_TO_END, event), COMMAND_PRIORITY_LOW));
|
|
1119
1164
|
}
|
|
1120
1165
|
|
|
1121
|
-
|
|
1166
|
+
/**
|
|
1167
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1168
|
+
*
|
|
1169
|
+
* This source code is licensed under the MIT license found in the
|
|
1170
|
+
* LICENSE file in the root directory of this source tree.
|
|
1171
|
+
*
|
|
1172
|
+
*/
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
/** @deprecated renamed to {@link $getFirstCodeNodeOfLine} by @lexical/eslint-plugin rules-of-lexical */
|
|
1176
|
+
const getFirstCodeNodeOfLine = $getFirstCodeNodeOfLine;
|
|
1177
|
+
/** @deprecated renamed to {@link $getLastCodeNodeOfLine} by @lexical/eslint-plugin rules-of-lexical */
|
|
1178
|
+
const getLastCodeNodeOfLine = $getLastCodeNodeOfLine;
|
|
1179
|
+
/** @deprecated renamed to {@link $getEndOfCodeInLine} by @lexical/eslint-plugin rules-of-lexical */
|
|
1180
|
+
const getEndOfCodeInLine = $getEndOfCodeInLine;
|
|
1181
|
+
/** @deprecated renamed to {@link $getStartOfCodeInLine} by @lexical/eslint-plugin rules-of-lexical */
|
|
1182
|
+
const getStartOfCodeInLine = $getStartOfCodeInLine;
|
|
1183
|
+
|
|
1184
|
+
export { $createCodeHighlightNode, $createCodeNode, $getEndOfCodeInLine, $getFirstCodeNodeOfLine, $getLastCodeNodeOfLine, $getStartOfCodeInLine, $isCodeHighlightNode, $isCodeNode, CODE_LANGUAGE_FRIENDLY_NAME_MAP, CODE_LANGUAGE_MAP, CodeHighlightNode, CodeNode, DEFAULT_CODE_LANGUAGE, PrismTokenizer, getCodeLanguages, getDefaultCodeLanguage, getEndOfCodeInLine, getFirstCodeNodeOfLine, getLanguageFriendlyName, getLastCodeNodeOfLine, getStartOfCodeInLine, normalizeCodeLang, registerCodeHighlighting };
|
|
@@ -11,7 +11,7 @@ import * as LexicalCode_prod from './LexicalCode.prod.js';
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const mod = process.env.NODE_ENV
|
|
14
|
+
const mod = process.env.NODE_ENV !== 'production' ? LexicalCode_dev : LexicalCode_prod;
|
|
15
15
|
const $createCodeNode = mod.$createCodeNode;
|
|
16
16
|
const $isCodeNode = mod.$isCodeNode;
|
|
17
17
|
const CODE_LANGUAGE_MAP = mod.CODE_LANGUAGE_MAP;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
+
import { addClassNamesToElement, removeClassNamesFromElement, mergeRegister, isHTMLElement, $getAdjacentCaret } from '../utils/LexicalUtils.js';
|
|
4
|
+
import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabNode, $createLineBreakNode, $applyNodeReplacement, TextNode, $isLineBreakNode, $getNodeByKey, KEY_TAB_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_DOWN_COMMAND, MOVE_TO_START, MOVE_TO_END, $getSiblingCaret, $createTextNode } from 'lexical';
|
|
3
5
|
import '../../prismjs/prism.js';
|
|
4
6
|
import '../../prismjs/components/prism-clike.js';
|
|
5
7
|
import '../../prismjs/components/prism-javascript.js';
|
|
@@ -16,8 +18,6 @@ import '../../prismjs/components/prism-swift.js';
|
|
|
16
18
|
import '../../prismjs/components/prism-typescript.js';
|
|
17
19
|
import '../../prismjs/components/prism-java.js';
|
|
18
20
|
import '../../prismjs/components/prism-cpp.js';
|
|
19
|
-
import { addClassNamesToElement, removeClassNamesFromElement, mergeRegister, isHTMLElement } from '../utils/LexicalUtils.js';
|
|
20
|
-
import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabNode, $createLineBreakNode, $applyNodeReplacement, TextNode, $isLineBreakNode, $getNodeByKey, KEY_TAB_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_DOWN_COMMAND, MOVE_TO_END, MOVE_TO_START, $createTextNode } from 'lexical';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -27,6 +27,6 @@ import { ElementNode, $createParagraphNode, $isTextNode, $isTabNode, $createTabN
|
|
|
27
27
|
*
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
-
function w(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var P=w((function(t){const e=new URLSearchParams;e.append("code",t);for(let t=1;t<arguments.length;t++)e.append("v",arguments[t]);throw Error(`Minified Lexical error #${t}; visit https://lexical.dev/docs/error?${e} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));const k=t=>{try{return !!t&&window.Prism.languages.hasOwnProperty(t)}catch(t){return !1}};function L(e,n){for(const r of e.childNodes){if(isHTMLElement(r)&&r.tagName===n)return !0;L(r,n);}return !1}const A="data-language",O="data-highlight-language";class M extends ElementNode{static getType(){return "code"}static clone(t){return new M(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t,this.__isSyntaxHighlightSupported=k(t);}createDOM(t){const n=document.createElement("code");addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(A,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(O,r)),n}updateDOM(t,e,n){const r=this.__language,o=t.__language;return r?r!==o&&(e.setAttribute(A,r),this.__isSyntaxHighlightSupported&&e.setAttribute(O,r)):o&&(e.removeAttribute(A),t.__isSyntaxHighlightSupported&&e.removeAttribute(O)),!1}exportDOM(t){const n=document.createElement("pre");addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(A,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(O,r)),{element:n}}static importDOM(){return {code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||L(t,"BR"))?{conversion:z,priority:1}:null,div:()=>({conversion:E,priority:1}),pre:()=>({conversion:z,priority:0}),table:t=>R(t)?{conversion:B,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&R(n)?{conversion:I,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&R(e)?{conversion:I,priority:3}:null}}}static importJSON(t){const e=H(t.language);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return {...super.exportJSON(),language:this.getLanguage(),type:"code",version:1}}insertNewAfter(t,e=!0){const n=this.getChildren(),r=n.length;if(r>=2&&"\n"===n[r-1].getTextContent()&&"\n"===n[r-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===r){n[r-1].remove(),n[r-2].remove();const t=$createParagraphNode();return this.insertAfter(t,e),t}const{anchor:o,focus:a}=t,g=(o.isBefore(a)?o:a).getNode();if($isTextNode(g)){let t=Z(g);const e=[];for(;;)if($isTabNode(t))e.push($createTabNode()),t=t.getNextSibling();else {if(!Y(t))break;{let n=0;const r=t.getTextContent(),o=t.getTextContentSize();for(;n<o&&" "===r[n];)n++;if(0!==n&&e.push(V(" ".repeat(n))),n!==o)break;t=t.getNextSibling();}}const n=g.splitText(o.offset)[0],r=0===o.offset?0:1,i=n.getIndexWithinParent()+r,s=g.getParentOrThrow(),a=[$createLineBreakNode(),...e];s.splice(i,0,a);const f=e[e.length-1];f?f.select():0===o.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0);}if(D(g)){const{offset:e}=t.anchor;g.splice(e,0,[$createLineBreakNode()]),g.select(e+1,e+1);}return null}canIndent(){return !1}collapseAtStart(){const t=$createParagraphNode();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}setLanguage(t){const e=this.getWritable();e.__language=t,e.__isSyntaxHighlightSupported=k(t);}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function H(t){return $applyNodeReplacement(new M(t))}function D(t){return t instanceof M}function z(t){return {node:H(t.getAttribute(A))}}function E(t){const e=t,n=J(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(J(e))return !0;e=e.parentElement;}return !1}(e)?{node:n?H():null}:{node:null}}function B(){return {node:H()}}function I(){return {node:null}}function J(t){return null!==t.style.fontFamily.match("monospace")}function R(t){return t.classList.contains("js-file-line-container")}const F="javascript",K={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},q={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function U(t){return q[t]||t}function W(t){const e=U(t);return K[e]||e}const $=()=>F,Q=()=>Object.keys(window.Prism.languages).filter((t=>"function"!=typeof window.Prism.languages[t])).sort();class X extends TextNode{constructor(t,e,n){super(t,n),this.__highlightType=e;}static getType(){return "code-highlight"}static clone(t){return new X(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}canHaveFormat(){return !1}createDOM(t){const n=super.createDOM(t),r=G(t.theme,this.__highlightType);return addClassNamesToElement(n,r),n}updateDOM(t,r,o){const i=super.updateDOM(t,r,o),s=G(o.theme,t.__highlightType),l=G(o.theme,this.__highlightType);return s!==l&&(s&&removeClassNamesFromElement(r,s),l&&addClassNamesToElement(r,l)),i}static importJSON(t){const e=V(t.text,t.highlightType);return e.setFormat(t.format),e.setDetail(t.detail),e.setMode(t.mode),e.setStyle(t.style),e}exportJSON(){return {...super.exportJSON(),highlightType:this.getHighlightType(),type:"code-highlight",version:1}}setFormat(t){return this}isParentRequired(){return !0}createParentElementNode(){return H()}}function G(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function V(t,e){return $applyNodeReplacement(new X(t,e))}function Y(t){return t instanceof X}function Z(t){let e=t,n=t;for(;Y(n)||$isTabNode(n);)e=n,n=n.getPreviousSibling();return e}function tt(t){let e=t,n=t;for(;Y(n)||$isTabNode(n);)e=n,n=n.getNextSibling();return e}const et={defaultLanguage:F,tokenize(t,e){return window.Prism.tokenize(t,window.Prism.languages[e||""]||window.Prism.languages[this.defaultLanguage])}};function nt(t,e){let n=null,r=null,o=t,i=e,s=t.getTextContent();for(;;){if(0===i){if(o=o.getPreviousSibling(),null===o)break;if(Y(o)||$isTabNode(o)||$isLineBreakNode(o)||P(167),$isLineBreakNode(o)){n={node:o,offset:1};break}i=Math.max(0,o.getTextContentSize()-1),s=o.getTextContent();}else i--;const t=s[i];Y(o)&&" "!==t&&(r={node:o,offset:i});}if(null!==r)return r;let u=null;if(e<t.getTextContentSize())Y(t)&&(u=t.getTextContent()[e]);else {const e=t.getNextSibling();Y(e)&&(u=e.getTextContent()[0]);}if(null!==u&&" "!==u)return n;{const r=function(t,e){let n=t,r=e,o=t.getTextContent(),i=t.getTextContentSize();for(;;){if(!Y(n)||r===i){if(n=n.getNextSibling(),null===n||$isLineBreakNode(n))return null;Y(n)&&(r=0,o=n.getTextContent(),i=n.getTextContentSize());}if(Y(n)){if(" "!==o[r])return {node:n,offset:r};r++;}}}(t,e);return null!==r?r:n}}function rt(t){const e=tt(t);return $isLineBreakNode(e)&&P(168),e}function ot(t,e,n){const r=t.getParent();D(r)?lt(r,e,n):Y(t)&&t.replace($createTextNode(t.__text));}function it(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),o=r.length;if(o===n.__cachedChildrenLength)return;n.__cachedChildrenLength=o;let i="1",s=1;for(let t=0;t<o;t++)$isLineBreakNode(r[t])&&(i+="\n"+ ++s);n.setAttribute("data-gutter",i);}const st=new Set;function lt(t,e,n){const r=t.getKey();st.has(r)||(st.add(r),void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage),e.update((()=>{!function(t,e){const n=$getNodeByKey(t);if(!D(n)||!n.isAttached())return;const r=$getSelection();if(!$isRangeSelection(r))return void e();const o=r.anchor,i=o.offset,l="element"===o.type&&$isLineBreakNode(n.getChildAtIndex(o.offset-1));let u=0;if(!l){const t=o.getNode();u=i+t.getPreviousSiblings().reduce(((t,e)=>t+e.getTextContentSize()),0);}if(!e())return;if(l)return void o.getNode().select(i,i);n.getChildren().some((t=>{const e=$isTextNode(t);if(e||$isLineBreakNode(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n;}return !1}));}(r,(()=>{const e=$getNodeByKey(r);if(!D(e)||!e.isAttached())return !1;const o=e.getTextContent(),i=ut(n.tokenize(o,e.getLanguage()||n.defaultLanguage)),s=function(t,e){let n=0;for(;n<t.length&&ct(t[n],e[n]);)n++;const r=t.length,o=e.length,i=Math.min(r,o)-n;let s=0;for(;s<i;)if(s++,!ct(t[r-s],e[o-s])){s--;break}const l=n,u=r-s,c=e.slice(n,o-s);return {from:l,nodesForReplacement:c,to:u}}(e.getChildren(),i),{from:l,to:u,nodesForReplacement:c}=s;return !(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)}));}),{onUpdate:()=>{st.delete(r);},skipTransforms:!0}));}function ut(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),o=t.length;for(let r=0;r<o;r++){const o=t[r];"\n"===o||"\r\n"===o?n.push($createLineBreakNode()):"\t"===o?n.push($createTabNode()):o.length>0&&n.push(V(o,e));}}else {const{content:t}=r;"string"==typeof t?n.push(...ut([t],r.type)):Array.isArray(t)&&n.push(...ut(t,r.type));}return n}function ct(t,e){return Y(t)&&Y(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||$isTabNode(t)&&$isTabNode(e)||$isLineBreakNode(t)&&$isLineBreakNode(e)}function at(t){if(!$isRangeSelection(t))return !1;const e=t.anchor.getNode(),n=t.focus.getNode();if(e.is(n)&&D(e))return !0;const r=e.getParent();return D(r)&&r.is(n.getParent())}function gt(t){const e=t.getNodes(),n=[[]];if(1===e.length&&D(e[0]))return n;let r=n[0];for(let t=0;t<e.length;t++){const o=e[t];Y(o)||$isTabNode(o)||$isLineBreakNode(o)||P(169),$isLineBreakNode(o)?0!==t&&r.length>0&&(r=[],n.push(r)):r.push(o);}return n}function ft(t){const e=$getSelection();if(!$isRangeSelection(e)||!at(e))return !1;const n=gt(e),r=n.length;if(n.length>1){for(let e=0;e<r;e++){const r=n[e];if(r.length>0){let n=r[0];0===e&&(n=Z(n)),null!==n&&(t===INDENT_CONTENT_COMMAND?n.insertBefore($createTabNode()):$isTabNode(n)&&n.remove());}}return !0}const o=e.getNodes()[0];if(D(o)||Y(o)||$isTabNode(o)||$isLineBreakNode(o)||P(171),D(o))return t===INDENT_CONTENT_COMMAND&&e.insertNodes([$createTabNode()]),!0;const i=Z(o);return null===i&&P(172),t===INDENT_CONTENT_COMMAND?$isLineBreakNode(i)?i.insertAfter($createTabNode()):i.insertBefore($createTabNode()):$isTabNode(i)&&i.remove(),!0}function pt(t,e){const n=$getSelection();if(!$isRangeSelection(n))return !1;const{anchor:r,focus:o}=n,i=r.offset,s=o.offset,u=r.getNode(),c=o.getNode(),a=t===KEY_ARROW_UP_COMMAND;if(!at(n)||!Y(u)&&!$isTabNode(u)||!Y(c)&&!$isTabNode(c))return !1;if(!e.altKey){if(n.isCollapsed()){const t=u.getParentOrThrow();if(a&&0===i&&null===u.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!a&&i===u.getTextContentSize()&&null===u.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return !1}let g,p;if(u.isBefore(c)?(g=Z(u),p=tt(c)):(g=Z(c),p=tt(u)),null==g||null==p)return !1;const h=g.getNodesBetween(p);for(let t=0;t<h.length;t++){const e=h[t];if(!Y(e)&&!$isTabNode(e)&&!$isLineBreakNode(e))return !1}e.preventDefault(),e.stopPropagation();const y=a?g.getPreviousSibling():p.getNextSibling();if(!$isLineBreakNode(y))return !0;const x=a?y.getPreviousSibling():y.getNextSibling();if(null==x)return !0;const S=Y(x)||$isTabNode(x)||$isLineBreakNode(x)?a?Z(x):tt(x):null;let v=null!=S?S:x;return y.remove(),h.forEach((t=>t.remove())),t===KEY_ARROW_UP_COMMAND?(h.forEach((t=>v.insertBefore(t))),v.insertBefore(y)):(v.insertAfter(y),v=y,h.forEach((t=>{v.insertAfter(t),v=t;}))),n.setTextNodeRange(u,i,c,s),!0}function ht(t,e){const n=$getSelection();if(!$isRangeSelection(n))return !1;const{anchor:r,focus:o}=n,i=r.getNode(),s=o.getNode(),u=t===MOVE_TO_START;if(!Y(i)&&!$isTabNode(i)||!Y(s)&&!$isTabNode(s))return !1;if(u){const t=nt(s,o.offset);if(null!==t){const{node:e,offset:r}=t;$isLineBreakNode(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r);}else s.getParentOrThrow().selectStart();}else {rt(s).select();}return e.preventDefault(),e.stopPropagation(),!0}function dt(t,e){if(!t.hasNodes([M,X]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==e&&(e=et),mergeRegister(t.registerMutationListener(M,(e=>{t.update((()=>{for(const[n,r]of e)if("destroyed"!==r){const e=$getNodeByKey(n);null!==e&&it(e,t);}}));}),{skipInitialization:!1}),t.registerNodeTransform(M,(n=>lt(n,t,e))),t.registerNodeTransform(TextNode,(n=>ot(n,t,e))),t.registerNodeTransform(X,(n=>ot(n,t,e))),t.registerCommand(KEY_TAB_COMMAND,(e=>{const n=function(t){const e=$getSelection();if(!$isRangeSelection(e)||!at(e))return null;const n=t?OUTDENT_CONTENT_COMMAND:INDENT_CONTENT_COMMAND,r=t?OUTDENT_CONTENT_COMMAND:INSERT_TAB_COMMAND;if(gt(e).length>1)return n;const o=e.getNodes()[0];if(D(o)||Y(o)||$isTabNode(o)||$isLineBreakNode(o)||P(170),D(o))return n;const i=Z(o),s=tt(o),u=e.anchor,c=e.focus;let a,g;return c.isBefore(u)?(a=c,g=u):(a=u,g=c),null!==i&&null!==s&&a.key===i.getKey()&&0===a.offset&&g.key===s.getKey()&&g.offset===s.getTextContentSize()?n:r}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)}),COMMAND_PRIORITY_LOW),t.registerCommand(INSERT_TAB_COMMAND,(()=>!!at($getSelection())&&($insertNodes([$createTabNode()]),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(INDENT_CONTENT_COMMAND,(t=>ft(INDENT_CONTENT_COMMAND)),COMMAND_PRIORITY_LOW),t.registerCommand(OUTDENT_CONTENT_COMMAND,(t=>ft(OUTDENT_CONTENT_COMMAND)),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_ARROW_UP_COMMAND,(t=>pt(KEY_ARROW_UP_COMMAND,t)),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_ARROW_DOWN_COMMAND,(t=>pt(KEY_ARROW_DOWN_COMMAND,t)),COMMAND_PRIORITY_LOW),t.registerCommand(MOVE_TO_END,(t=>ht(MOVE_TO_END,t)),COMMAND_PRIORITY_LOW),t.registerCommand(MOVE_TO_START,(t=>ht(MOVE_TO_START,t)),COMMAND_PRIORITY_LOW))}
|
|
30
|
+
function O(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const k=globalThis.Prism||window.Prism,L=t=>{try{return !!t&&k.languages.hasOwnProperty(t)}catch(t){return !1}};function A(e,n){for(const r of e.childNodes){if(isHTMLElement(r)&&r.tagName===n)return !0;A(r,n);}return !1}const H="data-language",D="data-highlight-language";class M extends ElementNode{static getType(){return "code"}static clone(t){return new M(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=L(t);}createDOM(t){const n=document.createElement("code");addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(H,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(D,r)),n}updateDOM(t,e,n){const r=this.__language,o=t.__language;return r?r!==o&&(e.setAttribute(H,r),this.__isSyntaxHighlightSupported&&e.setAttribute(D,r)):o&&(e.removeAttribute(H),t.__isSyntaxHighlightSupported&&e.removeAttribute(D)),!1}exportDOM(t){const n=document.createElement("pre");addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();return r&&(n.setAttribute(H,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(D,r)),{element:n}}static importDOM(){return {code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||A(t,"BR"))?{conversion:E,priority:1}:null,div:()=>({conversion:F,priority:1}),pre:()=>({conversion:E,priority:0}),table:t=>K(t)?{conversion:B,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&K(n)?{conversion:R,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&K(e)?{conversion:R,priority:3}:null}}}static importJSON(t){return z().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language)}exportJSON(){return {...super.exportJSON(),language:this.getLanguage()}}insertNewAfter(t,e=!0){const n=this.getChildren(),r=n.length;if(r>=2&&"\n"===n[r-1].getTextContent()&&"\n"===n[r-2].getTextContent()&&t.isCollapsed()&&t.anchor.key===this.__key&&t.anchor.offset===r){n[r-1].remove(),n[r-2].remove();const t=$createParagraphNode();return this.insertAfter(t,e),t}const{anchor:o,focus:i}=t,a=(o.isBefore(i)?o:i).getNode();if($isTextNode(a)){let t=nt(a);const e=[];for(;;)if($isTabNode(t))e.push($createTabNode()),t=t.getNextSibling();else {if(!tt(t))break;{let n=0;const r=t.getTextContent(),o=t.getTextContentSize();for(;n<o&&" "===r[n];)n++;if(0!==n&&e.push(Z(" ".repeat(n))),n!==o)break;t=t.getNextSibling();}}const n=a.splitText(o.offset)[0],r=0===o.offset?0:1,i=n.getIndexWithinParent()+r,s=a.getParentOrThrow(),l=[$createLineBreakNode(),...e];s.splice(i,0,l);const p=e[e.length-1];p?p.select():0===o.offset?n.selectPrevious():n.getNextSibling().selectNext(0,0);}if(J(a)){const{offset:e}=t.anchor;a.splice(e,0,[$createLineBreakNode()]),a.select(e+1,e+1);}return null}canIndent(){return !1}collapseAtStart(){const t=$createParagraphNode();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}setLanguage(t){const e=this.getWritable();return e.__language=t||void 0,e.__isSyntaxHighlightSupported=L(t),e}getLanguage(){return this.getLatest().__language}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}}function z(t){return $applyNodeReplacement(new M(t))}function J(t){return t instanceof M}function E(t){return {node:z(t.getAttribute(H))}}function F(t){const e=t,n=I(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(I(e))return !0;e=e.parentElement;}return !1}(e)?{node:n?z():null}:{node:null}}function B(){return {node:z()}}function R(){return {node:null}}function I(t){return null!==t.style.fontFamily.match("monospace")}function K(t){return t.classList.contains("js-file-line-container")}const q="javascript",U={c:"C",clike:"C-like",cpp:"C++",css:"CSS",html:"HTML",java:"Java",js:"JavaScript",markdown:"Markdown",objc:"Objective-C",plain:"Plain Text",powershell:"PowerShell",py:"Python",rust:"Rust",sql:"SQL",swift:"Swift",typescript:"TypeScript",xml:"XML"},W={cpp:"cpp",java:"java",javascript:"js",md:"markdown",plaintext:"plain",python:"py",text:"plain",ts:"typescript"};function $(t){return W[t]||t}function Q(t){const e=$(t);return U[e]||e}const X=()=>q,G=()=>Object.keys(k.languages).filter((t=>"function"!=typeof k.languages[t])).sort();class V extends TextNode{constructor(t="",e,n){super(t,n),this.__highlightType=e;}static getType(){return "code-highlight"}static clone(t){return new V(t.__text,t.__highlightType||void 0,t.__key)}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return !1}createDOM(t){const n=super.createDOM(t),r=Y(t.theme,this.__highlightType);return addClassNamesToElement(n,r),n}updateDOM(t,r,o){const i=super.updateDOM(t,r,o),s=Y(o.theme,t.__highlightType),l=Y(o.theme,this.__highlightType);return s!==l&&(s&&removeClassNamesFromElement(r,s),l&&addClassNamesToElement(r,l)),i}static importJSON(t){return Z().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setHighlightType(t.highlightType)}exportJSON(){return {...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(t){return this}isParentRequired(){return !0}createParentElementNode(){return z()}}function Y(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Z(t="",e){return $applyNodeReplacement(new V(t,e))}function tt(t){return t instanceof V}function et(t,e){let n=t;for(let o=$getSiblingCaret(t,e);o&&(tt(o.origin)||$isTabNode(o.origin));o=$getAdjacentCaret(o))n=o.origin;return n}function nt(t){return et(t,"previous")}function rt(t){return et(t,"next")}const ot={defaultLanguage:q,tokenize(t,e){return k.tokenize(t,k.languages[e||""]||k.languages[this.defaultLanguage])}};function it(t,e){let n=null,r=null,o=t,i=e,s=t.getTextContent();for(;;){if(0===i){if(o=o.getPreviousSibling(),null===o)break;if(tt(o)||$isTabNode(o)||$isLineBreakNode(o)||O(167),$isLineBreakNode(o)){n={node:o,offset:1};break}i=Math.max(0,o.getTextContentSize()-1),s=o.getTextContent();}else i--;const t=s[i];tt(o)&&" "!==t&&(r={node:o,offset:i});}if(null!==r)return r;let l=null;if(e<t.getTextContentSize())tt(t)&&(l=t.getTextContent()[e]);else {const e=t.getNextSibling();tt(e)&&(l=e.getTextContent()[0]);}if(null!==l&&" "!==l)return n;{const r=function(t,e){let n=t,r=e,o=t.getTextContent(),i=t.getTextContentSize();for(;;){if(!tt(n)||r===i){if(n=n.getNextSibling(),null===n||$isLineBreakNode(n))return null;tt(n)&&(r=0,o=n.getTextContent(),i=n.getTextContentSize());}if(tt(n)){if(" "!==o[r])return {node:n,offset:r};r++;}}}(t,e);return null!==r?r:n}}function st(t){const e=rt(t);return $isLineBreakNode(e)&&O(168),e}function lt(t,e,n){const r=t.getParent();J(r)?gt(r,e,n):tt(t)&&t.replace($createTextNode(t.__text));}function ut(t,e){const n=e.getElementByKey(t.getKey());if(null===n)return;const r=t.getChildren(),o=r.length;if(o===n.__cachedChildrenLength)return;n.__cachedChildrenLength=o;let i="1",s=1;for(let t=0;t<o;t++)$isLineBreakNode(r[t])&&(i+="\n"+ ++s);n.setAttribute("data-gutter",i);}const ct=new Set;function gt(t,e,n){const r=t.getKey();ct.has(r)||(ct.add(r),void 0===t.getLanguage()&&t.setLanguage(n.defaultLanguage),e.update((()=>{!function(t,e){const n=$getNodeByKey(t);if(!J(n)||!n.isAttached())return;const r=$getSelection();if(!$isRangeSelection(r))return void e();const o=r.anchor,i=o.offset,s="element"===o.type&&$isLineBreakNode(n.getChildAtIndex(o.offset-1));let u=0;if(!s){const t=o.getNode();u=i+t.getPreviousSiblings().reduce(((t,e)=>t+e.getTextContentSize()),0);}if(!e())return;if(s)return void o.getNode().select(i,i);n.getChildren().some((t=>{const e=$isTextNode(t);if(e||$isLineBreakNode(t)){const n=t.getTextContentSize();if(e&&n>=u)return t.select(u,u),!0;u-=n;}return !1}));}(r,(()=>{const e=$getNodeByKey(r);if(!J(e)||!e.isAttached())return !1;const o=e.getTextContent(),i=at(n.tokenize(o,e.getLanguage()||n.defaultLanguage)),s=function(t,e){let n=0;for(;n<t.length&&pt(t[n],e[n]);)n++;const r=t.length,o=e.length,i=Math.min(r,o)-n;let s=0;for(;s<i;)if(s++,!pt(t[r-s],e[o-s])){s--;break}const l=n,u=r-s,c=e.slice(n,o-s);return {from:l,nodesForReplacement:c,to:u}}(e.getChildren(),i),{from:l,to:u,nodesForReplacement:c}=s;return !(l===u&&!c.length)&&(t.splice(l,u-l,c),!0)}));}),{onUpdate:()=>{ct.delete(r);},skipTransforms:!0}));}function at(t,e){const n=[];for(const r of t)if("string"==typeof r){const t=r.split(/(\n|\t)/),o=t.length;for(let r=0;r<o;r++){const o=t[r];"\n"===o||"\r\n"===o?n.push($createLineBreakNode()):"\t"===o?n.push($createTabNode()):o.length>0&&n.push(Z(o,e));}}else {const{content:t}=r;"string"==typeof t?n.push(...at([t],r.type)):Array.isArray(t)&&n.push(...at(t,r.type));}return n}function pt(t,e){return tt(t)&&tt(e)&&t.__text===e.__text&&t.__highlightType===e.__highlightType||$isTabNode(t)&&$isTabNode(e)||$isLineBreakNode(t)&&$isLineBreakNode(e)}function ft(t){if(!$isRangeSelection(t))return !1;const e=t.anchor.getNode(),n=t.focus.getNode();if(e.is(n)&&J(e))return !0;const r=e.getParent();return J(r)&&r.is(n.getParent())}function ht(t){const e=t.getNodes(),n=[[]];if(1===e.length&&J(e[0]))return n;let r=n[0];for(let t=0;t<e.length;t++){const o=e[t];tt(o)||$isTabNode(o)||$isLineBreakNode(o)||O(169),$isLineBreakNode(o)?0!==t&&r.length>0&&(r=[],n.push(r)):r.push(o);}return n}function dt(t){const e=$getSelection();if(!$isRangeSelection(e)||!ft(e))return !1;const n=ht(e),r=n.length;if(n.length>1){for(let e=0;e<r;e++){const r=n[e];if(r.length>0){let n=r[0];0===e&&(n=nt(n)),null!==n&&(t===INDENT_CONTENT_COMMAND?n.insertBefore($createTabNode()):$isTabNode(n)&&n.remove());}}return !0}const o=e.getNodes()[0];if(J(o)||tt(o)||$isTabNode(o)||$isLineBreakNode(o)||O(171),J(o))return t===INDENT_CONTENT_COMMAND&&e.insertNodes([$createTabNode()]),!0;const i=nt(o);return t===INDENT_CONTENT_COMMAND?$isLineBreakNode(i)?i.insertAfter($createTabNode()):i.insertBefore($createTabNode()):$isTabNode(i)&&i.remove(),!0}function mt(t,e){const n=$getSelection();if(!$isRangeSelection(n))return !1;const{anchor:r,focus:o}=n,i=r.offset,s=o.offset,l=r.getNode(),c=o.getNode(),g=t===KEY_ARROW_UP_COMMAND;if(!ft(n)||!tt(l)&&!$isTabNode(l)||!tt(c)&&!$isTabNode(c))return !1;if(!e.altKey){if(n.isCollapsed()){const t=l.getParentOrThrow();if(g&&0===i&&null===l.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&i===l.getTextContentSize()&&null===l.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return !1}let a,p;if(l.isBefore(c)?(a=nt(l),p=rt(c)):(a=nt(c),p=rt(l)),null==a||null==p)return !1;const f=a.getNodesBetween(p);for(let t=0;t<f.length;t++){const e=f[t];if(!tt(e)&&!$isTabNode(e)&&!$isLineBreakNode(e))return !1}e.preventDefault(),e.stopPropagation();const d=g?a.getPreviousSibling():p.getNextSibling();if(!$isLineBreakNode(d))return !0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return !0;const S=tt(m)||$isTabNode(m)||$isLineBreakNode(m)?g?nt(m):rt(m):null;let _=null!=S?S:m;return d.remove(),f.forEach((t=>t.remove())),t===KEY_ARROW_UP_COMMAND?(f.forEach((t=>_.insertBefore(t))),_.insertBefore(d)):(_.insertAfter(d),_=d,f.forEach((t=>{_.insertAfter(t),_=t;}))),n.setTextNodeRange(l,i,c,s),!0}function xt(t,e){const n=$getSelection();if(!$isRangeSelection(n))return !1;const{anchor:r,focus:o}=n,i=r.getNode(),s=o.getNode(),l=t===MOVE_TO_START;if(!ft(n)||!tt(i)&&!$isTabNode(i)||!tt(s)&&!$isTabNode(s))return !1;if(l){const t=it(s,o.offset);if(null!==t){const{node:e,offset:r}=t;$isLineBreakNode(e)?e.selectNext(0,0):n.setTextNodeRange(e,r,e,r);}else s.getParentOrThrow().selectStart();}else {st(s).select();}return e.preventDefault(),e.stopPropagation(),!0}function yt(t,e){if(!t.hasNodes([M,V]))throw new Error("CodeHighlightPlugin: CodeNode or CodeHighlightNode not registered on editor");return null==e&&(e=ot),mergeRegister(t.registerMutationListener(M,(e=>{t.update((()=>{for(const[n,r]of e)if("destroyed"!==r){const e=$getNodeByKey(n);null!==e&&ut(e,t);}}));}),{skipInitialization:!1}),t.registerNodeTransform(M,(n=>gt(n,t,e))),t.registerNodeTransform(TextNode,(n=>lt(n,t,e))),t.registerNodeTransform(V,(n=>lt(n,t,e))),t.registerCommand(KEY_TAB_COMMAND,(e=>{const n=function(t){const e=$getSelection();if(!$isRangeSelection(e)||!ft(e))return null;const n=t?OUTDENT_CONTENT_COMMAND:INDENT_CONTENT_COMMAND,r=t?OUTDENT_CONTENT_COMMAND:INSERT_TAB_COMMAND;if(ht(e).length>1)return n;const o=e.getNodes()[0];if(J(o)||tt(o)||$isTabNode(o)||$isLineBreakNode(o)||O(170),J(o))return n;const i=nt(o),s=rt(o),l=e.anchor,c=e.focus;let g,a;return c.isBefore(l)?(g=c,a=l):(g=l,a=c),null!==i&&null!==s&&g.key===i.getKey()&&0===g.offset&&a.key===s.getKey()&&a.offset===s.getTextContentSize()?n:r}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)}),COMMAND_PRIORITY_LOW),t.registerCommand(INSERT_TAB_COMMAND,(()=>!!ft($getSelection())&&($insertNodes([$createTabNode()]),!0)),COMMAND_PRIORITY_LOW),t.registerCommand(INDENT_CONTENT_COMMAND,(t=>dt(INDENT_CONTENT_COMMAND)),COMMAND_PRIORITY_LOW),t.registerCommand(OUTDENT_CONTENT_COMMAND,(t=>dt(OUTDENT_CONTENT_COMMAND)),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_ARROW_UP_COMMAND,(t=>{const e=$getSelection();if(!$isRangeSelection(e))return !1;const{anchor:n}=e,r=n.getNode();return !!ft(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&J(r.getParentOrThrow())?(t.preventDefault(),!0):mt(KEY_ARROW_UP_COMMAND,t))}),COMMAND_PRIORITY_LOW),t.registerCommand(KEY_ARROW_DOWN_COMMAND,(t=>{const e=$getSelection();if(!$isRangeSelection(e))return !1;const{anchor:n}=e,r=n.getNode();return !!ft(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&J(r.getParentOrThrow())?(t.preventDefault(),!0):mt(KEY_ARROW_DOWN_COMMAND,t))}),COMMAND_PRIORITY_LOW),t.registerCommand(MOVE_TO_START,(t=>xt(MOVE_TO_START,t)),COMMAND_PRIORITY_LOW),t.registerCommand(MOVE_TO_END,(t=>xt(MOVE_TO_END,t)),COMMAND_PRIORITY_LOW))}const St=nt,_t=rt,vt=st,Nt=it;
|
|
31
31
|
|
|
32
|
-
export {
|
|
32
|
+
export { Z as $createCodeHighlightNode, z as $createCodeNode, st as $getEndOfCodeInLine, nt as $getFirstCodeNodeOfLine, rt as $getLastCodeNodeOfLine, it as $getStartOfCodeInLine, tt as $isCodeHighlightNode, J as $isCodeNode, U as CODE_LANGUAGE_FRIENDLY_NAME_MAP, W as CODE_LANGUAGE_MAP, V as CodeHighlightNode, M as CodeNode, q as DEFAULT_CODE_LANGUAGE, ot as PrismTokenizer, G as getCodeLanguages, X as getDefaultCodeLanguage, vt as getEndOfCodeInLine, St as getFirstCodeNodeOfLine, Q as getLanguageFriendlyName, _t as getLastCodeNodeOfLine, Nt as getStartOfCodeInLine, $ as normalizeCodeLang, yt as registerCodeHighlighting };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { $sliceSelectedTextNodeContent } from '../selection/LexicalSelection.js';
|
|
4
4
|
import { isHTMLElement, isBlockDomNode } from '../utils/LexicalUtils.js';
|
|
5
|
-
import { $getRoot, $isElementNode, $cloneWithProperties, $isTextNode, $isRootOrShadowRoot, $isBlockElementNode, $createLineBreakNode, ArtificialNode__DO_NOT_USE, isInlineDomNode, $createParagraphNode } from 'lexical';
|
|
5
|
+
import { $getRoot, $isElementNode, $cloneWithProperties, $isTextNode, isDocumentFragment, $isRootOrShadowRoot, $isBlockElementNode, $createLineBreakNode, ArtificialNode__DO_NOT_USE, isInlineDomNode, $createParagraphNode } from 'lexical';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -91,14 +91,18 @@ function $appendNodesToHTML(editor, currentNode, parentElement, selection = null
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
if (shouldInclude && !shouldExclude) {
|
|
94
|
-
if (isHTMLElement(element)) {
|
|
94
|
+
if (isHTMLElement(element) || isDocumentFragment(element)) {
|
|
95
95
|
element.append(fragment);
|
|
96
96
|
}
|
|
97
97
|
parentElement.append(element);
|
|
98
98
|
if (after) {
|
|
99
99
|
const newElement = after.call(target, element);
|
|
100
100
|
if (newElement) {
|
|
101
|
-
element
|
|
101
|
+
if (isDocumentFragment(element)) {
|
|
102
|
+
element.replaceChildren(newElement);
|
|
103
|
+
} else {
|
|
104
|
+
element.replaceWith(newElement);
|
|
105
|
+
}
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
108
|
} else {
|
|
@@ -115,7 +119,10 @@ function getConversionFunction(domNode, editor) {
|
|
|
115
119
|
if (cachedConversions !== undefined) {
|
|
116
120
|
for (const cachedConversion of cachedConversions) {
|
|
117
121
|
const domConversion = cachedConversion(domNode);
|
|
118
|
-
if (domConversion !== null && (currentConversion === null ||
|
|
122
|
+
if (domConversion !== null && (currentConversion === null ||
|
|
123
|
+
// Given equal priority, prefer the last registered importer
|
|
124
|
+
// which is typically an application custom node or HTMLConfig['import']
|
|
125
|
+
(currentConversion.priority || 0) <= (domConversion.priority || 0))) {
|
|
119
126
|
currentConversion = domConversion;
|
|
120
127
|
}
|
|
121
128
|
}
|
|
@@ -11,7 +11,7 @@ import * as LexicalHtml_prod from './LexicalHtml.prod.js';
|
|
|
11
11
|
*
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
const mod = process.env.NODE_ENV
|
|
14
|
+
const mod = process.env.NODE_ENV !== 'production' ? LexicalHtml_dev : LexicalHtml_prod;
|
|
15
15
|
const $generateHtmlFromNodes = mod.$generateHtmlFromNodes;
|
|
16
16
|
const $generateNodesFromDOM = mod.$generateNodesFromDOM;
|
|
17
17
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { $sliceSelectedTextNodeContent } from '../selection/LexicalSelection.js';
|
|
4
4
|
import { isHTMLElement, isBlockDomNode } from '../utils/LexicalUtils.js';
|
|
5
|
-
import { ArtificialNode__DO_NOT_USE, $createLineBreakNode, $getRoot, $isElementNode, $cloneWithProperties, $isTextNode, $isRootOrShadowRoot, $isBlockElementNode, isInlineDomNode, $createParagraphNode } from 'lexical';
|
|
5
|
+
import { ArtificialNode__DO_NOT_USE, $createLineBreakNode, $getRoot, $isElementNode, $cloneWithProperties, $isTextNode, isDocumentFragment, $isRootOrShadowRoot, $isBlockElementNode, isInlineDomNode, $createParagraphNode } from 'lexical';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -12,6 +12,6 @@ import { ArtificialNode__DO_NOT_USE, $createLineBreakNode, $getRoot, $isElementN
|
|
|
12
12
|
*
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
function
|
|
15
|
+
function h(e,n){const t=n.body?n.body.childNodes:[];let o=[];const l=[];for(let n=0;n<t.length;n++){const r=t[n];if(!x.has(r.nodeName)){const n=y(r,e,l,!1);null!==n&&(o=o.concat(n));}}return function(e){for(const n of e)n.getNextSibling()instanceof ArtificialNode__DO_NOT_USE&&n.insertAfter($createLineBreakNode());for(const n of e){const e=n.getChildren();for(const t of e)n.insertBefore(t);n.remove();}}(l),o}function m(e,n){if("undefined"==typeof document||"undefined"==typeof window&&void 0===global.window)throw new Error("To use $generateHtmlFromNodes in headless mode please initialize a headless browser implementation such as JSDom before calling this function.");const t=document.createElement("div"),l=$getRoot().getChildren();for(let o=0;o<l.length;o++){g(e,l[o],t,n);}return t.innerHTML}function g(t,o,c,u=null){let f=null===u||o.isSelected(u);const a=$isElementNode(o)&&o.excludeFromCopy("html");let d=o;if(null!==u){let n=$cloneWithProperties(o);n=$isTextNode(n)&&null!==u?$sliceSelectedTextNodeContent(u,n):n,d=n;}const p=$isElementNode(d)?d.getChildren():[],h=t._nodes.get(d.getType());let m;m=h&&void 0!==h.exportDOM?h.exportDOM(t,d):d.exportDOM(t);const{element:x,after:y}=m;if(!x)return !1;const w=document.createDocumentFragment();for(let e=0;e<p.length;e++){const n=p[e],r=g(t,n,w,u);!f&&$isElementNode(o)&&r&&o.extractWithChild(n,u,"html")&&(f=!0);}if(f&&!a){if((isHTMLElement(x)||isDocumentFragment(x))&&x.append(w),c.append(x),y){const e=y.call(d,x);e&&(isDocumentFragment(x)?x.replaceChildren(e):x.replaceWith(e));}}else c.append(w);return f}const x=new Set(["STYLE","SCRIPT"]);function y(e,n,o,r,i=new Map,s){let h=[];if(x.has(e.nodeName))return h;let m=null;const g=function(e,n){const{nodeName:t}=e,o=n._htmlConversions.get(t.toLowerCase());let l=null;if(void 0!==o)for(const n of o){const t=n(e);null!==t&&(null===l||(l.priority||0)<=(t.priority||0))&&(l=t);}return null!==l?l.conversion:null}(e,n),b=g?g(e):null;let C=null;if(null!==b){C=b.after;const n=b.node;if(m=Array.isArray(n)?n[n.length-1]:n,null!==m){for(const[,e]of i)if(m=e(m,s),!m)break;m&&h.push(...Array.isArray(n)?n:[m]);}null!=b.forChild&&i.set(e.nodeName,b.forChild);}const S=e.childNodes;let v=[];const N=(null==m||!$isRootOrShadowRoot(m))&&(null!=m&&$isBlockElementNode(m)||r);for(let e=0;e<S.length;e++)v.push(...y(S[e],n,o,N,new Map(i),m));return null!=C&&(v=C(v)),isBlockDomNode(e)&&(v=w(e,v,N?()=>{const e=new ArtificialNode__DO_NOT_USE;return o.push(e),e}:$createParagraphNode)),null==m?v.length>0?h=h.concat(v):isBlockDomNode(e)&&function(e){if(null==e.nextSibling||null==e.previousSibling)return !1;return isInlineDomNode(e.nextSibling)&&isInlineDomNode(e.previousSibling)}(e)&&(h=h.concat($createLineBreakNode())):$isElementNode(m)&&m.append(...v),h}function w(e,n,t){const o=e.style.textAlign,l=[];let r=[];for(let e=0;e<n.length;e++){const i=n[e];if($isBlockElementNode(i))o&&!i.getFormat()&&i.setFormat(o),l.push(i);else if(r.push(i),e===n.length-1||e<n.length-1&&$isBlockElementNode(n[e+1])){const e=t();e.setFormat(o),e.append(...r),l.push(e),r=[];}}return l}
|
|
16
16
|
|
|
17
|
-
export {
|
|
17
|
+
export { m as $generateHtmlFromNodes, h as $generateNodesFromDOM };
|