@lexical/code-core 0.45.1-nightly.20260604.0 → 0.45.1-nightly.20260608.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/CodeIndentation.d.ts +10 -1
- package/dist/LexicalCodeCore.dev.js +14 -7
- package/dist/LexicalCodeCore.dev.mjs +15 -8
- package/dist/LexicalCodeCore.prod.js +1 -1
- package/dist/LexicalCodeCore.prod.mjs +1 -1
- package/dist/typescript-too-old.d.ts +18 -0
- package/package.json +25 -7
- package/src/CodeIndentation.ts +53 -5
|
@@ -21,7 +21,7 @@ import type { LexicalEditor } from 'lexical';
|
|
|
21
21
|
* up to that many leading spaces from a code line. See
|
|
22
22
|
* {@link $outdentLeadingSpaces}.
|
|
23
23
|
*/
|
|
24
|
-
export declare function registerCodeIndentation(editor: LexicalEditor, tabSize?: number): () => void;
|
|
24
|
+
export declare function registerCodeIndentation(editor: LexicalEditor, tabSize?: number, escapeWithArrows?: boolean): () => void;
|
|
25
25
|
export interface CodeIndentConfig {
|
|
26
26
|
/**
|
|
27
27
|
* When true, the indent commands are not registered on the editor.
|
|
@@ -39,6 +39,15 @@ export interface CodeIndentConfig {
|
|
|
39
39
|
* this option.
|
|
40
40
|
*/
|
|
41
41
|
tabSize: number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* When `true`, this enables the ability to exit a code block
|
|
44
|
+
* that has no adjacent elements using the ArrowLeft/ArrowUp keys
|
|
45
|
+
* if the cursor is at the beginning, or the ArrowRight/ArrowDown keys
|
|
46
|
+
* if the cursor is at the end.
|
|
47
|
+
* When `false` (default), pressing the arrow keys will not move the cursor
|
|
48
|
+
* if there are no adjacent elements around the code block
|
|
49
|
+
*/
|
|
50
|
+
escapeWithArrows: boolean;
|
|
42
51
|
}
|
|
43
52
|
/**
|
|
44
53
|
* Adds keyboard-driven indentation to code blocks (Tab / Shift+Tab,
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
var lexical = require('lexical');
|
|
12
12
|
var extension = require('@lexical/extension');
|
|
13
13
|
var html = require('@lexical/html');
|
|
14
|
+
var utils = require('@lexical/utils');
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -1290,14 +1291,14 @@ function $handleShiftLines(type, event) {
|
|
|
1290
1291
|
if (codeNodeSibling === null) {
|
|
1291
1292
|
codeNode.selectPrevious();
|
|
1292
1293
|
event.preventDefault();
|
|
1293
|
-
return
|
|
1294
|
+
return false;
|
|
1294
1295
|
}
|
|
1295
1296
|
} else if (!arrowIsUp && anchorOffset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null) {
|
|
1296
1297
|
const codeNodeSibling = codeNode.getNextSibling();
|
|
1297
1298
|
if (codeNodeSibling === null) {
|
|
1298
1299
|
codeNode.selectNext();
|
|
1299
1300
|
event.preventDefault();
|
|
1300
|
-
return
|
|
1301
|
+
return false;
|
|
1301
1302
|
}
|
|
1302
1303
|
}
|
|
1303
1304
|
}
|
|
@@ -1426,8 +1427,12 @@ function $handleMoveTo(type, event) {
|
|
|
1426
1427
|
* up to that many leading spaces from a code line. See
|
|
1427
1428
|
* {@link $outdentLeadingSpaces}.
|
|
1428
1429
|
*/
|
|
1429
|
-
function registerCodeIndentation(editor, tabSize) {
|
|
1430
|
-
return lexical.mergeRegister(
|
|
1430
|
+
function registerCodeIndentation(editor, tabSize, escapeWithArrows) {
|
|
1431
|
+
return lexical.mergeRegister(
|
|
1432
|
+
// When node is the last child pressing down/right or up/let arrow will insert paragraph
|
|
1433
|
+
// below it to allow adding more content.
|
|
1434
|
+
// These handlers must be executed before $handleShiftLines
|
|
1435
|
+
...(escapeWithArrows ? [editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => event.altKey ? false : utils.$onEscapeDown($isCodeNode), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, () => utils.$onEscapeDown($isCodeNode), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, event => event.altKey ? false : utils.$onEscapeUp($isCodeNode), lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, () => utils.$onEscapeUp($isCodeNode), lexical.COMMAND_PRIORITY_LOW)] : []), editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
|
|
1431
1436
|
const command = $handleTab(event.shiftKey);
|
|
1432
1437
|
if (command === null) {
|
|
1433
1438
|
return false;
|
|
@@ -1455,7 +1460,8 @@ function registerCodeIndentation(editor, tabSize) {
|
|
|
1455
1460
|
return false;
|
|
1456
1461
|
}
|
|
1457
1462
|
// If at the start of a code block, prevent selection from moving out
|
|
1458
|
-
|
|
1463
|
+
const parent = anchorNode.getParent();
|
|
1464
|
+
if (selection.isCollapsed() && anchor.offset === 0 && anchorNode.getPreviousSibling() === null && $isCodeNode(parent) && parent.getPreviousSibling() === null) {
|
|
1459
1465
|
event.preventDefault();
|
|
1460
1466
|
return true;
|
|
1461
1467
|
}
|
|
@@ -1473,7 +1479,7 @@ function registerCodeIndentation(editor, tabSize) {
|
|
|
1473
1479
|
return false;
|
|
1474
1480
|
}
|
|
1475
1481
|
// If at the end of a code block, prevent selection from moving out
|
|
1476
|
-
if (selection.isCollapsed() && anchor.offset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null && $isCodeNode(anchorNode.getParentOrThrow())) {
|
|
1482
|
+
if (selection.isCollapsed() && anchor.offset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null && $isCodeNode(anchorNode.getParentOrThrow()) && anchorNode.getParentOrThrow().getNextSibling() === null) {
|
|
1477
1483
|
event.preventDefault();
|
|
1478
1484
|
return true;
|
|
1479
1485
|
}
|
|
@@ -1495,6 +1501,7 @@ const CodeIndentExtension = lexical.defineExtension({
|
|
|
1495
1501
|
build: (editor, config) => extension.namedSignals(config),
|
|
1496
1502
|
config: lexical.safeCast({
|
|
1497
1503
|
disabled: false,
|
|
1504
|
+
escapeWithArrows: false,
|
|
1498
1505
|
tabSize: undefined
|
|
1499
1506
|
}),
|
|
1500
1507
|
dependencies: [CodeExtension],
|
|
@@ -1505,7 +1512,7 @@ const CodeIndentExtension = lexical.defineExtension({
|
|
|
1505
1512
|
if (stores.disabled.value) {
|
|
1506
1513
|
return;
|
|
1507
1514
|
}
|
|
1508
|
-
return registerCodeIndentation(editor, stores.tabSize.value);
|
|
1515
|
+
return registerCodeIndentation(editor, stores.tabSize.value, stores.escapeWithArrows.value);
|
|
1509
1516
|
});
|
|
1510
1517
|
}
|
|
1511
1518
|
});
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, tokenizeRawText, $createTabNode, $createLineBreakNode, $getSiblingCaret, $create, ElementNode, addClassNamesToElement, setDOMStyleFromCSS, $getEditor, $isTextNode, $createParagraphNode, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, defineExtension, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, configExtension, isDOMDocumentNode, isDOMTextNode, $generateNodesFromRawText, safeCast, mergeRegister, KEY_TAB_COMMAND, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND,
|
|
9
|
+
import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, tokenizeRawText, $createTabNode, $createLineBreakNode, $getSiblingCaret, $create, ElementNode, addClassNamesToElement, setDOMStyleFromCSS, $getEditor, $isTextNode, $createParagraphNode, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, defineExtension, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, configExtension, isDOMDocumentNode, isDOMTextNode, $generateNodesFromRawText, safeCast, mergeRegister, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_TAB_COMMAND, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, MOVE_TO_START, MOVE_TO_END, $createPoint, $setSelectionFromCaretRange, $getCaretRangeInDirection, $getCaretRange, $getTextPointCaret, $normalizeCaret } from 'lexical';
|
|
10
10
|
import { getPeerDependencyFromEditor, effect, namedSignals } from '@lexical/extension';
|
|
11
11
|
import { CoreImportExtension, DOMImportExtension, defineImportRule, sel, ImportOverlays, defineOverlayRules } from '@lexical/html';
|
|
12
|
+
import { $onEscapeDown, $onEscapeUp } from '@lexical/utils';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -1288,14 +1289,14 @@ function $handleShiftLines(type, event) {
|
|
|
1288
1289
|
if (codeNodeSibling === null) {
|
|
1289
1290
|
codeNode.selectPrevious();
|
|
1290
1291
|
event.preventDefault();
|
|
1291
|
-
return
|
|
1292
|
+
return false;
|
|
1292
1293
|
}
|
|
1293
1294
|
} else if (!arrowIsUp && anchorOffset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null) {
|
|
1294
1295
|
const codeNodeSibling = codeNode.getNextSibling();
|
|
1295
1296
|
if (codeNodeSibling === null) {
|
|
1296
1297
|
codeNode.selectNext();
|
|
1297
1298
|
event.preventDefault();
|
|
1298
|
-
return
|
|
1299
|
+
return false;
|
|
1299
1300
|
}
|
|
1300
1301
|
}
|
|
1301
1302
|
}
|
|
@@ -1424,8 +1425,12 @@ function $handleMoveTo(type, event) {
|
|
|
1424
1425
|
* up to that many leading spaces from a code line. See
|
|
1425
1426
|
* {@link $outdentLeadingSpaces}.
|
|
1426
1427
|
*/
|
|
1427
|
-
function registerCodeIndentation(editor, tabSize) {
|
|
1428
|
-
return mergeRegister(
|
|
1428
|
+
function registerCodeIndentation(editor, tabSize, escapeWithArrows) {
|
|
1429
|
+
return mergeRegister(
|
|
1430
|
+
// When node is the last child pressing down/right or up/let arrow will insert paragraph
|
|
1431
|
+
// below it to allow adding more content.
|
|
1432
|
+
// These handlers must be executed before $handleShiftLines
|
|
1433
|
+
...(escapeWithArrows ? [editor.registerCommand(KEY_ARROW_DOWN_COMMAND, event => event.altKey ? false : $onEscapeDown($isCodeNode), COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, () => $onEscapeDown($isCodeNode), COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_UP_COMMAND, event => event.altKey ? false : $onEscapeUp($isCodeNode), COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_ARROW_LEFT_COMMAND, () => $onEscapeUp($isCodeNode), COMMAND_PRIORITY_LOW)] : []), editor.registerCommand(KEY_TAB_COMMAND, event => {
|
|
1429
1434
|
const command = $handleTab(event.shiftKey);
|
|
1430
1435
|
if (command === null) {
|
|
1431
1436
|
return false;
|
|
@@ -1453,7 +1458,8 @@ function registerCodeIndentation(editor, tabSize) {
|
|
|
1453
1458
|
return false;
|
|
1454
1459
|
}
|
|
1455
1460
|
// If at the start of a code block, prevent selection from moving out
|
|
1456
|
-
|
|
1461
|
+
const parent = anchorNode.getParent();
|
|
1462
|
+
if (selection.isCollapsed() && anchor.offset === 0 && anchorNode.getPreviousSibling() === null && $isCodeNode(parent) && parent.getPreviousSibling() === null) {
|
|
1457
1463
|
event.preventDefault();
|
|
1458
1464
|
return true;
|
|
1459
1465
|
}
|
|
@@ -1471,7 +1477,7 @@ function registerCodeIndentation(editor, tabSize) {
|
|
|
1471
1477
|
return false;
|
|
1472
1478
|
}
|
|
1473
1479
|
// If at the end of a code block, prevent selection from moving out
|
|
1474
|
-
if (selection.isCollapsed() && anchor.offset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null && $isCodeNode(anchorNode.getParentOrThrow())) {
|
|
1480
|
+
if (selection.isCollapsed() && anchor.offset === anchorNode.getTextContentSize() && anchorNode.getNextSibling() === null && $isCodeNode(anchorNode.getParentOrThrow()) && anchorNode.getParentOrThrow().getNextSibling() === null) {
|
|
1475
1481
|
event.preventDefault();
|
|
1476
1482
|
return true;
|
|
1477
1483
|
}
|
|
@@ -1493,6 +1499,7 @@ const CodeIndentExtension = defineExtension({
|
|
|
1493
1499
|
build: (editor, config) => namedSignals(config),
|
|
1494
1500
|
config: safeCast({
|
|
1495
1501
|
disabled: false,
|
|
1502
|
+
escapeWithArrows: false,
|
|
1496
1503
|
tabSize: undefined
|
|
1497
1504
|
}),
|
|
1498
1505
|
dependencies: [CodeExtension],
|
|
@@ -1503,7 +1510,7 @@ const CodeIndentExtension = defineExtension({
|
|
|
1503
1510
|
if (stores.disabled.value) {
|
|
1504
1511
|
return;
|
|
1505
1512
|
}
|
|
1506
|
-
return registerCodeIndentation(editor, stores.tabSize.value);
|
|
1513
|
+
return registerCodeIndentation(editor, stores.tabSize.value, stores.escapeWithArrows.value);
|
|
1507
1514
|
});
|
|
1508
1515
|
}
|
|
1509
1516
|
});
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("@lexical/extension"),n=require("@lexical/html");function r(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 i(t,n){let r=t;for(let i=e.$getSiblingCaret(t,n);i&&(A(i.origin)||e.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function o(e){return i(e,"previous")}function s(e){return i(e,"next")}function l(t){const n=o(t),r=s(t);let i=n;for(;null!==i;){if(A(i)){const t=e.getTextDirection(i.getTextContent());if(null!==t)return t}if(i===r)break;i=i.getNextSibling()}const l=n.getParent();if(e.$isElementNode(l)){const e=l.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function a(t,n){let i=null,o=null,s=t,l=n,a=t.getTextContent();for(;;){if(0===l){if(s=s.getPreviousSibling(),null===s)break;if(A(s)||e.$isTabNode(s)||e.$isLineBreakNode(s)||r(167),e.$isLineBreakNode(s)){i={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const t=a[l];A(s)&&" "!==t&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<t.getTextContentSize())A(t)&&(c=t.getTextContent()[n]);else{const e=t.getNextSibling();A(e)&&(c=e.getTextContent()[0])}if(null!==c&&" "!==c)return i;{const r=function(t,n){let r=t,i=n,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!A(r)||i===s){if(r=r.getNextSibling(),null===r||e.$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++}}}(t,n);return null!==r?r:i}}function c(t){const n=s(t);return e.$isLineBreakNode(n)&&r(168),n}function u(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 g="javascript";function d(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;if(d(r,n))return!0}return!1}const f="data-language",h="data-highlight-language",p="data-theme",N=()=>{};class m extends e.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new m(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(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(f,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(h,r));const i=this.getTheme();i&&n.setAttribute(p,i);const o=this.getStyle();return o&&e.setDOMStyleFromCSS(n.style,o),n}updateDOM(t,n,r){const i=this.__language,o=t.__language;i?i!==o&&n.setAttribute(f,i):o&&n.removeAttribute(f);const s=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(h,i):n.removeAttribute(h):s&&i&&n.setAttribute(h,i);const l=this.__theme,a=t.__theme;l?l!==a&&n.setAttribute(p,l):a&&n.removeAttribute(p);const c=this.__style,u=t.__style;return c!==u&&e.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(f,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(h,r));const i=this.getTheme();i&&n.setAttribute(p,i);const o=this.getStyle();return o&&e.setDOMStyleFromCSS(n.style,o),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||d(e,"BR"))?{conversion:x,priority:1}:null,div:()=>({conversion:C,priority:1}),pre:()=>({conversion:x,priority:0}),table:e=>b(e)?{conversion:O,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:S,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:S,priority:3}:null}}}static importJSON(e){return _().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(n,r=!0){if(!t.getPeerDependencyFromEditor(e.$getEditor(),"@lexical/code")){N();const e=M(n);if(e)return e}const{anchor:i,focus:s}=n,l=(i.isBefore(s)?i:s).getNode();if(e.$isTextNode(l)){let t=o(l);const n=[];for(;;)if(e.$isTabNode(t))n.push(e.$createTabNode()),t=t.getNextSibling();else{if(!A(t))break;{let e=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;e<i&&" "===r[e];)e++;if(0!==e&&n.push(D(" ".repeat(e))),e!==i)break;t=t.getNextSibling()}}const r=l.splitText(i.offset)[0],s=0===i.offset?0:1,a=r.getIndexWithinParent()+s,c=l.getParentOrThrow(),u=[e.$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(T(l)){const{offset:t}=n.anchor;l.splice(t,0,[e.$createLineBreakNode()]),l.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const t=e.$createParagraphNode();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!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,n){return e.$create(m).setLanguage(t).setTheme(n)}function T(e){return e instanceof m}function x(e){return{node:_(e.getAttribute(f))}}function C(e){const t=e,n=$(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if($(t))return!0;t=t.parentElement}return!1}(t)?{node:n?_():null}:{node:null}}function O(){return{node:_()}}function S(){return{node:null}}function $(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function M(t){const{anchor:n}=t;if(t.isCollapsed()&&"element"===n.type){const t=n.getNode();if(T(t)){const r=t.getChildrenSize();if(r>=2&&n.offset===r){const n=t.getLastChild();if(e.$isLineBreakNode(n)&&e.$isLineBreakNode(n.getPreviousSibling())){const n=e.$createParagraphNode();return t.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class y extends e.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new y(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(t){const n=super.createDOM(t),r=E(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=E(r.theme,t.__highlightType),s=E(r.theme,this.__highlightType);return o!==s&&(o&&e.removeClassNamesFromElement(n,o),s&&e.addClassNamesToElement(n,s)),i}static importJSON(e){return D().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 _()}}function E(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function D(t="",n){return e.$applyNodeReplacement(new y(t,n))}function A(e){return e instanceof y}const R=e.defineExtension({name:"@lexical/code",nodes:()=>[m,y],register:t=>t.registerCommand(e.KEY_ENTER_COMMAND,t=>{const n=e.$getSelection();return!(!e.$isRangeSelection(n)||!M(n))&&(t.preventDefault(),!0)},e.COMMAND_PRIORITY_LOW)}),v="data-language";function L(e){return null!==e.style.fontFamily.match("monospace")}function I(e){let t=e.parentElement;for(;null!==t;){if(L(t))return!0;t=t.parentElement}return!1}const P=n.defineOverlayRules([n.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:n.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),B=n.defineImportRule({$import:(e,t)=>[_(t.getAttribute(v)).splice(0,0,e.$importChildren(t))],match:n.sel.tag("pre"),name:"@lexical/code/pre"}),k=n.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[_(t.getAttribute(v)).splice(0,0,e.$importChildren(t))]:n()},match:n.sel.tag("code"),name:"@lexical/code/code-multiline"});function H(t){if(!e.isHTMLElement(t))return!1;const n=t.style.fontFamily,r=t.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function F(t){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(t.childNodes))if(e.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(e.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function w(t){for(const n of Array.from(t.children)){if(e.isHTMLElement(n)&&H(n)){if(null!==F(n))return!0;const e=n.nextElementSibling;if(e&&H(e))return!0;continue}if(w(n))return!0}return!1}const W=n.defineImportRule({$import:(t,n,r)=>{if(!H(n)||I(n))return r();const i=F(n);return null===i||0===i.length?r():[_().splice(0,0,e.$generateNodesFromRawText(i.join("\n")))]},match:n.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),K=n.defineImportRule({$import:(t,n,r)=>{if(!H(n)||I(n))return r();const i=n.previousElementSibling;if(i&&H(i))return[];const o=[];let s=n;for(;s&&H(s);)o.push("BR"===s.tagName?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?r():[_().splice(0,0,e.$generateNodesFromRawText(o.join("\n")))]},match:n.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),Y=n.defineOverlayRules([W,K]),z=n.defineImportRule({$import:(e,t,n)=>L(t)?[_().splice(0,0,e.$importChildren(t))]:I(t)?e.$importChildren(t):n(),match:n.sel.tag("div"),name:"@lexical/code/div"}),J=[n.defineImportRule({$import:(e,t)=>[_().splice(0,0,e.$importChildren(t,{rules:P}))],match:n.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),n.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:n.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),k,B,z],U=e.defineExtension({dependencies:[n.CoreImportExtension,R,e.configExtension(n.DOMImportExtension,{preprocess:[(t,r,i)=>{w(e.isDOMDocumentNode(t)?t.body:t)&&r.session.update(n.ImportOverlays,e=>[...e,Y]),i()}],rules:J})],name:"@lexical/code/Import"});function j(t){if(!e.$isRangeSelection(t))return!1;const n=t.anchor.getNode(),r=T(n)?n:n.getParent(),i=t.focus.getNode(),o=T(i)?i:i.getParent();return T(r)&&r.is(o)}function V(t){const n=t.getNodes(),i=[];if(1===n.length&&T(n[0]))return i;let o=[];for(let t=0;t<n.length;t++){const s=n[t];A(s)||e.$isTabNode(s)||e.$isLineBreakNode(s)||r(169),e.$isLineBreakNode(s)?o.length>0&&(i.push(o),o=[]):o.push(s)}if(o.length>0){const n=t.isBackward()?t.anchor:t.focus,r=e.$createPoint(o[0].getKey(),0,"text");n.is(r)||i.push(o)}return i}function q(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r)||!j(r))return!1;const i=V(r),s=i.length;if(0===s&&r.isCollapsed())return t===e.INDENT_CONTENT_COMMAND&&r.insertNodes([e.$createTabNode()]),!0;if(0===s&&t===e.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const t=e.$createTabNode(),n=e.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([t,n]),e.$setSelectionFromCaretRange(e.$getCaretRangeInDirection(e.$getCaretRange(e.$getTextPointCaret(t,"next",0),e.$normalizeCaret(e.$getSiblingCaret(n,"next"))),i)),!0}for(let l=0;l<s;l++){const s=i[l];if(s.length>0){let i=s[0];if(0===l&&(i=o(i)),t===e.INDENT_CONTENT_COMMAND){const t=e.$createTabNode();if(i.insertBefore(t),0===l){const n=r.isBackward()?"focus":"anchor",o=e.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(t.getKey(),0,"text")}}else e.$isTabNode(i)?i.remove():void 0!==n&&A(i)&&u(i,n,r)}}return!0}function G(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r))return!1;const{anchor:i,focus:l}=r,a=i.offset,c=l.offset,u=i.getNode(),g=l.getNode(),d=t===e.KEY_ARROW_UP_COMMAND;if(!j(r)||!A(u)&&!e.$isTabNode(u)||!A(g)&&!e.$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(),!0}else if(!d&&a===u.getTextContentSize()&&null===u.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!0}}return!1}let f,h;if(u.isBefore(g)?(f=o(u),h=s(g)):(f=o(g),h=s(u)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let t=0;t<p.length;t++){const n=p[t];if(!A(n)&&!e.$isTabNode(n)&&!e.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!e.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=A(m)||e.$isTabNode(m)||e.$isLineBreakNode(m)?d?o(m):s(m):null;let T=null!=_?_:m;return N.remove(),p.forEach(e=>e.remove()),t===e.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 Q(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),u=o.getNode(),g=t===e.MOVE_TO_START;if(!j(r)||!A(s)&&!e.$isTabNode(s)||!A(u)&&!e.$isTabNode(u))return!1;const d=u,f="rtl"===l(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const t=a(d,o.offset);if(null!==t){const{node:n,offset:i}=t;e.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else d.getParentOrThrow().selectStart()}else{c(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function X(t,n){return e.mergeRegister(t.registerCommand(e.KEY_TAB_COMMAND,n=>{const i=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n)||!j(n))return null;const i=t?e.OUTDENT_CONTENT_COMMAND:e.INDENT_CONTENT_COMMAND,l=t?e.OUTDENT_CONTENT_COMMAND:e.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return l;const u=V(n);if(1!==u.length)return i;const g=u[0];let d,f;0===g.length&&r(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=o(g[0]),p=s(g[0]),N=e.$createPoint(h.getKey(),0,"text"),m=e.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?i:N.isBefore(d)||f.isBefore(m)?l:i}(n.shiftKey);return null!==i&&(n.preventDefault(),t.dispatchCommand(i,void 0),!0)},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.INSERT_TAB_COMMAND,()=>!!j(e.$getSelection())&&(e.$insertNodes([e.$createTabNode()]),!0),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.INDENT_CONTENT_COMMAND,()=>q(e.INDENT_CONTENT_COMMAND),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.OUTDENT_CONTENT_COMMAND,()=>q(e.OUTDENT_CONTENT_COMMAND,n),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_UP_COMMAND,t=>{const n=e.$getSelection();if(!e.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!j(n)&&(n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&T(i.getParentOrThrow())?(t.preventDefault(),!0):G(e.KEY_ARROW_UP_COMMAND,t))},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_DOWN_COMMAND,t=>{const n=e.$getSelection();if(!e.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!j(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&T(i.getParentOrThrow())?(t.preventDefault(),!0):G(e.KEY_ARROW_DOWN_COMMAND,t))},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.MOVE_TO_START,t=>Q(e.MOVE_TO_START,t),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.MOVE_TO_END,t=>Q(e.MOVE_TO_END,t),e.COMMAND_PRIORITY_LOW))}const Z=e.defineExtension({build:(e,n)=>t.namedSignals(n),config:e.safeCast({disabled:!1,tabSize:void 0}),dependencies:[R],name:"@lexical/code-indent",register:(e,n,r)=>{const i=r.getOutput();return t.effect(()=>{if(!i.disabled.value)return X(e,i.tabSize.value)})}});exports.$createCodeHighlightNode=D,exports.$createCodeNode=_,exports.$getCodeLineDirection=l,exports.$getEndOfCodeInLine=c,exports.$getFirstCodeNodeOfLine=o,exports.$getLastCodeNodeOfLine=s,exports.$getStartOfCodeInLine=a,exports.$isCodeHighlightNode=A,exports.$isCodeNode=T,exports.$outdentLeadingSpaces=u,exports.$plainifyCodeContent=function(t){const n=[];return e.tokenizeRawText(t,{linebreak:()=>n.push(e.$createLineBreakNode()),tab:()=>n.push(e.$createTabNode()),text:e=>n.push(D(e))}),n},exports.CodeExtension=R,exports.CodeHighlightNode=y,exports.CodeImportExtension=U,exports.CodeImportRules=J,exports.CodeIndentExtension=Z,exports.CodeNode=m,exports.DEFAULT_CODE_LANGUAGE=g,exports.getDefaultCodeLanguage=()=>g,exports.registerCodeIndentation=X;
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("@lexical/extension"),n=require("@lexical/html"),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(t,n){let r=t;for(let i=e.$getSiblingCaret(t,n);i&&(D(i.origin)||e.$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(t){const n=s(t),r=l(t);let i=n;for(;null!==i;){if(D(i)){const t=e.getTextDirection(i.getTextContent());if(null!==t)return t}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(e.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function c(t,n){let r=null,o=null,s=t,l=n,a=t.getTextContent();for(;;){if(0===l){if(s=s.getPreviousSibling(),null===s)break;if(D(s)||e.$isTabNode(s)||e.$isLineBreakNode(s)||i(167),e.$isLineBreakNode(s)){r={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const t=a[l];D(s)&&" "!==t&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<t.getTextContentSize())D(t)&&(c=t.getTextContent()[n]);else{const e=t.getNextSibling();D(e)&&(c=e.getTextContent()[0])}if(null!==c&&" "!==c)return r;{const i=function(t,n){let r=t,i=n,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!D(r)||i===s){if(r=r.getNextSibling(),null===r||e.$isLineBreakNode(r))return null;D(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(D(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(t,n);return null!==i?i:r}}function u(t){const n=l(t);return e.$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(t,n){for(const r of t.childNodes){if(e.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 e.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(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.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&&e.setDOMStyleFromCSS(n.style,o),n}updateDOM(t,n,r){const i=this.__language,o=t.__language;i?i!==o&&n.setAttribute(h,i):o&&n.removeAttribute(h);const s=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(p,i):n.removeAttribute(p):s&&i&&n.setAttribute(p,i);const l=this.__theme,a=t.__theme;l?l!==a&&n.setAttribute(N,l):a&&n.removeAttribute(N);const c=this.__style,u=t.__style;return c!==u&&e.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._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&&e.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:M,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:M,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(n,r=!0){if(!t.getPeerDependencyFromEditor(e.$getEditor(),"@lexical/code")){m();const e=E(n);if(e)return e}const{anchor:i,focus:o}=n,l=(i.isBefore(o)?i:o).getNode();if(e.$isTextNode(l)){let t=s(l);const n=[];for(;;)if(e.$isTabNode(t))n.push(e.$createTabNode()),t=t.getNextSibling();else{if(!D(t))break;{let e=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;e<i&&" "===r[e];)e++;if(0!==e&&n.push(A(" ".repeat(e))),e!==i)break;t=t.getNextSibling()}}const r=l.splitText(i.offset)[0],o=0===i.offset?0:1,a=r.getIndexWithinParent()+o,c=l.getParentOrThrow(),u=[e.$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:t}=n.anchor;l.splice(t,0,[e.$createLineBreakNode()]),l.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const t=e.$createParagraphNode();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!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(t,n){return e.$create(_).setLanguage(t).setTheme(n)}function C(e){return e instanceof _}function x(e){return{node:T(e.getAttribute(h))}}function O(e){const t=e,n=$(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if($(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function M(){return{node:null}}function $(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function E(t){const{anchor:n}=t;if(t.isCollapsed()&&"element"===n.type){const t=n.getNode();if(C(t)){const r=t.getChildrenSize();if(r>=2&&n.offset===r){const n=t.getLastChild();if(e.$isLineBreakNode(n)&&e.$isLineBreakNode(n.getPreviousSibling())){const n=e.$createParagraphNode();return t.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class R extends e.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(t){const n=super.createDOM(t),r=y(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=y(r.theme,t.__highlightType),s=y(r.theme,this.__highlightType);return o!==s&&(o&&e.removeClassNamesFromElement(n,o),s&&e.addClassNamesToElement(n,s)),i}static importJSON(e){return A().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 y(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function A(t="",n){return e.$applyNodeReplacement(new R(t,n))}function D(e){return e instanceof R}const v=e.defineExtension({name:"@lexical/code",nodes:()=>[_,R],register:t=>t.registerCommand(e.KEY_ENTER_COMMAND,t=>{const n=e.$getSelection();return!(!e.$isRangeSelection(n)||!E(n))&&(t.preventDefault(),!0)},e.COMMAND_PRIORITY_LOW)}),I="data-language";function L(e){return null!==e.style.fontFamily.match("monospace")}function P(e){let t=e.parentElement;for(;null!==t;){if(L(t))return!0;t=t.parentElement}return!1}const B=n.defineOverlayRules([n.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:n.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),k=n.defineImportRule({$import:(e,t)=>[T(t.getAttribute(I)).splice(0,0,e.$importChildren(t))],match:n.sel.tag("pre"),name:"@lexical/code/pre"}),W=n.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(I)).splice(0,0,e.$importChildren(t))]:n()},match:n.sel.tag("code"),name:"@lexical/code/code-multiline"});function w(t){if(!e.isHTMLElement(t))return!1;const n=t.style.fontFamily,r=t.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function H(t){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(t.childNodes))if(e.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(e.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function F(t){for(const n of Array.from(t.children)){if(e.isHTMLElement(n)&&w(n)){if(null!==H(n))return!0;const e=n.nextElementSibling;if(e&&w(e))return!0;continue}if(F(n))return!0}return!1}const Y=n.defineImportRule({$import:(t,n,r)=>{if(!w(n)||P(n))return r();const i=H(n);return null===i||0===i.length?r():[T().splice(0,0,e.$generateNodesFromRawText(i.join("\n")))]},match:n.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),K=n.defineImportRule({$import:(t,n,r)=>{if(!w(n)||P(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,e.$generateNodesFromRawText(o.join("\n")))]},match:n.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),U=n.defineOverlayRules([Y,K]),z=n.defineImportRule({$import:(e,t,n)=>L(t)?[T().splice(0,0,e.$importChildren(t))]:P(t)?e.$importChildren(t):n(),match:n.sel.tag("div"),name:"@lexical/code/div"}),J=[n.defineImportRule({$import:(e,t)=>[T().splice(0,0,e.$importChildren(t,{rules:B}))],match:n.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),n.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:n.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),W,k,z],j=e.defineExtension({dependencies:[n.CoreImportExtension,v,e.configExtension(n.DOMImportExtension,{preprocess:[(t,r,i)=>{F(e.isDOMDocumentNode(t)?t.body:t)&&r.session.update(n.ImportOverlays,e=>[...e,U]),i()}],rules:J})],name:"@lexical/code/Import"});function q(t){if(!e.$isRangeSelection(t))return!1;const n=t.anchor.getNode(),r=C(n)?n:n.getParent(),i=t.focus.getNode(),o=C(i)?i:i.getParent();return C(r)&&r.is(o)}function V(t){const n=t.getNodes(),r=[];if(1===n.length&&C(n[0]))return r;let o=[];for(let t=0;t<n.length;t++){const s=n[t];D(s)||e.$isTabNode(s)||e.$isLineBreakNode(s)||i(169),e.$isLineBreakNode(s)?o.length>0&&(r.push(o),o=[]):o.push(s)}if(o.length>0){const n=t.isBackward()?t.anchor:t.focus,i=e.$createPoint(o[0].getKey(),0,"text");n.is(i)||r.push(o)}return r}function G(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r)||!q(r))return!1;const i=V(r),o=i.length;if(0===o&&r.isCollapsed())return t===e.INDENT_CONTENT_COMMAND&&r.insertNodes([e.$createTabNode()]),!0;if(0===o&&t===e.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const t=e.$createTabNode(),n=e.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([t,n]),e.$setSelectionFromCaretRange(e.$getCaretRangeInDirection(e.$getCaretRange(e.$getTextPointCaret(t,"next",0),e.$normalizeCaret(e.$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)),t===e.INDENT_CONTENT_COMMAND){const t=e.$createTabNode();if(i.insertBefore(t),0===l){const n=r.isBackward()?"focus":"anchor",o=e.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(t.getKey(),0,"text")}}else e.$isTabNode(i)?i.remove():void 0!==n&&D(i)&&g(i,n,r)}}return!0}function Q(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,a=i.offset,c=o.offset,u=i.getNode(),g=o.getNode(),d=t===e.KEY_ARROW_UP_COMMAND;if(!q(r)||!D(u)&&!e.$isTabNode(u)||!D(g)&&!e.$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 t=0;t<p.length;t++){const n=p[t];if(!D(n)&&!e.$isTabNode(n)&&!e.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!e.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=D(m)||e.$isTabNode(m)||e.$isLineBreakNode(m)?d?s(m):l(m):null;let T=null!=_?_:m;return N.remove(),p.forEach(e=>e.remove()),t===e.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(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),l=o.getNode(),g=t===e.MOVE_TO_START;if(!q(r)||!D(s)&&!e.$isTabNode(s)||!D(l)&&!e.$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 t=c(d,o.offset);if(null!==t){const{node:n,offset:i}=t;e.$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(t,n,o){return e.mergeRegister(...o?[t.registerCommand(e.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(C),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_RIGHT_COMMAND,()=>r.$onEscapeDown(C),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(C),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_LEFT_COMMAND,()=>r.$onEscapeUp(C),e.COMMAND_PRIORITY_LOW)]:[],t.registerCommand(e.KEY_TAB_COMMAND,n=>{const r=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n)||!q(n))return null;const r=t?e.OUTDENT_CONTENT_COMMAND:e.INDENT_CONTENT_COMMAND,o=t?e.OUTDENT_CONTENT_COMMAND:e.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=e.$createPoint(h.getKey(),0,"text"),m=e.$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(),t.dispatchCommand(r,void 0),!0)},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.INSERT_TAB_COMMAND,()=>!!q(e.$getSelection())&&(e.$insertNodes([e.$createTabNode()]),!0),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.INDENT_CONTENT_COMMAND,()=>G(e.INDENT_CONTENT_COMMAND),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.OUTDENT_CONTENT_COMMAND,()=>G(e.OUTDENT_CONTENT_COMMAND,n),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_UP_COMMAND,t=>{const n=e.$getSelection();if(!e.$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()?(t.preventDefault(),!0):Q(e.KEY_ARROW_UP_COMMAND,t)},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_DOWN_COMMAND,t=>{const n=e.$getSelection();if(!e.$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()?(t.preventDefault(),!0):Q(e.KEY_ARROW_DOWN_COMMAND,t))},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.MOVE_TO_START,t=>X(e.MOVE_TO_START,t),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.MOVE_TO_END,t=>X(e.MOVE_TO_END,t),e.COMMAND_PRIORITY_LOW))}const ee=e.defineExtension({build:(e,n)=>t.namedSignals(n),config:e.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[v],name:"@lexical/code-indent",register:(e,n,r)=>{const i=r.getOutput();return t.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=D,exports.$isCodeNode=C,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(t){const n=[];return e.tokenizeRawText(t,{linebreak:()=>n.push(e.$createLineBreakNode()),tab:()=>n.push(e.$createTabNode()),text:e=>n.push(A(e))}),n},exports.CodeExtension=v,exports.CodeHighlightNode=R,exports.CodeImportExtension=j,exports.CodeImportRules=J,exports.CodeIndentExtension=ee,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=Z;
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{getTextDirection as t,$isElementNode as e,$isTabNode as n,$isLineBreakNode as r,tokenizeRawText as i,$createTabNode as o,$createLineBreakNode as s,$getSiblingCaret as l,$create as u,ElementNode as c,addClassNamesToElement as a,setDOMStyleFromCSS as g,$getEditor as h,$isTextNode as f,$createParagraphNode as p,isHTMLElement as d,$applyNodeReplacement as m,TextNode as x,removeClassNamesFromElement as _,defineExtension as S,KEY_ENTER_COMMAND as y,$getSelection as b,$isRangeSelection as v,COMMAND_PRIORITY_LOW as C,configExtension as T,isDOMDocumentNode as N,isDOMTextNode as A,$generateNodesFromRawText as O,safeCast as P,mergeRegister as w,KEY_TAB_COMMAND as H,INSERT_TAB_COMMAND as D,$insertNodes as k,INDENT_CONTENT_COMMAND as B,OUTDENT_CONTENT_COMMAND as L,KEY_ARROW_UP_COMMAND as $,KEY_ARROW_DOWN_COMMAND as E,MOVE_TO_START as F,MOVE_TO_END as M,$createPoint as J,$setSelectionFromCaretRange as z,$getCaretRangeInDirection as I,$getCaretRange as K,$getTextPointCaret as j,$normalizeCaret as R}from"lexical";import{getPeerDependencyFromEditor as W,effect as q,namedSignals as U}from"@lexical/extension";import{CoreImportExtension as V,DOMImportExtension as G,defineImportRule as Q,sel as X,ImportOverlays as Y,defineOverlayRules as Z}from"@lexical/html";function tt(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.`)}function et(t,e){let r=t;for(let i=l(t,e);i&&(wt(i.origin)||n(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function nt(t){return et(t,"previous")}function rt(t){return et(t,"next")}function it(n){const r=nt(n),i=rt(n);let o=r;for(;null!==o;){if(wt(o)){const e=t(o.getTextContent());if(null!==e)return e}if(o===i)break;o=o.getNextSibling()}const s=r.getParent();if(e(s)){const t=s.getDirection();if("ltr"===t||"rtl"===t)return t}return null}function ot(t,e){let i=null,o=null,s=t,l=e,u=t.getTextContent();for(;;){if(0===l){if(s=s.getPreviousSibling(),null===s)break;if(wt(s)||n(s)||r(s)||tt(167),r(s)){i={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),u=s.getTextContent()}else l--;const t=u[l];wt(s)&&" "!==t&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(e<t.getTextContentSize())wt(t)&&(c=t.getTextContent()[e]);else{const e=t.getNextSibling();wt(e)&&(c=e.getTextContent()[0])}if(null!==c&&" "!==c)return i;{const n=function(t,e){let n=t,i=e,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!wt(n)||i===s){if(n=n.getNextSibling(),null===n||r(n))return null;wt(n)&&(i=0,o=n.getTextContent(),s=n.getTextContentSize())}if(wt(n)){if(" "!==o[i])return{node:n,offset:i};i++}}}(t,e);return null!==n?n:i}}function st(t){const e=rt(t);return r(e)&&tt(168),e}function lt(t){const e=[];return i(t,{linebreak:()=>e.push(s()),tab:()=>e.push(o()),text:t=>e.push(Pt(t))}),e}function ut(t,e,n){if(!Number.isInteger(e)||e<=0)return!1;const r=t.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(e,i[0].length),s=t.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 t.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 ct="javascript",at=()=>ct;function gt(t,e){for(const n of t.childNodes){if(d(n)&&n.tagName===e)return!0;if(gt(n,e))return!0}return!1}const ht="data-language",ft="data-highlight-language",pt="data-theme",dt=()=>{};class mt extends c{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(t){return new mt(t.__language,t.__key)}constructor(t,e){super(e),this.__language=t||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(t){super.afterCloneFrom(t),this.__language=t.__language,this.__theme=t.__theme,this.__isSyntaxHighlightSupported=t.__isSyntaxHighlightSupported}createDOM(t){const e=document.createElement("code");a(e,t.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(ht,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(ft,n));const r=this.getTheme();r&&e.setAttribute(pt,r);const i=this.getStyle();return i&&g(e.style,i),e}updateDOM(t,e,n){const r=this.__language,i=t.__language;r?r!==i&&e.setAttribute(ht,r):i&&e.removeAttribute(ht);const o=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&e.setAttribute(ft,r):e.removeAttribute(ft):o&&r&&e.setAttribute(ft,r);const s=this.__theme,l=t.__theme;s?s!==l&&e.setAttribute(pt,s):l&&e.removeAttribute(pt);const u=this.__style,c=t.__style;return u!==c&&g(e.style,u,c),!1}exportDOM(t){const e=document.createElement("pre");a(e,t._config.theme.code),e.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(e.setAttribute(ht,n),this.getIsSyntaxHighlightSupported()&&e.setAttribute(ft,n));const r=this.getTheme();r&&e.setAttribute(pt,r);const i=this.getStyle();return i&&g(e.style,i),{element:e}}static importDOM(){return{code:t=>null!=t.textContent&&(/\r?\n/.test(t.textContent)||gt(t,"BR"))?{conversion:St,priority:1}:null,div:()=>({conversion:yt,priority:1}),pre:()=>({conversion:St,priority:0}),table:t=>Tt(t)?{conversion:bt,priority:3}:null,td:t=>{const e=t,n=e.closest("table");return e.classList.contains("js-file-line")||n&&Tt(n)?{conversion:vt,priority:3}:null},tr:t=>{const e=t.closest("table");return e&&Tt(e)?{conversion:vt,priority:3}:null}}}static importJSON(t){return xt().updateFromJSON(t)}updateFromJSON(t){return super.updateFromJSON(t).setLanguage(t.language).setTheme(t.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(t,e=!0){if(!W(h(),"@lexical/code")){dt();const e=Nt(t);if(e)return e}const{anchor:r,focus:i}=t,l=(r.isBefore(i)?r:i).getNode();if(f(l)){let t=nt(l);const e=[];for(;;)if(n(t))e.push(o()),t=t.getNextSibling();else{if(!wt(t))break;{let n=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&e.push(Pt(" ".repeat(n))),n!==i)break;t=t.getNextSibling()}}const i=l.splitText(r.offset)[0],u=0===r.offset?0:1,c=i.getIndexWithinParent()+u,a=l.getParentOrThrow(),g=[s(),...e];a.splice(c,0,g);const h=e[e.length-1];h?h.select():0===r.offset?i.selectPrevious():i.getNextSibling().selectNext(0,0)}if(_t(l)){const{offset:e}=t.anchor;l.splice(e,0,[s()]),l.select(e+1,e+1)}return null}canIndent(){return!1}collapseAtStart(){const t=p();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}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(t){const e=this.getWritable();return e.__isSyntaxHighlightSupported=t,e}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(t){const e=this.getWritable();return e.__theme=t||void 0,e}getTheme(){return this.getLatest().__theme}}function xt(t,e){return u(mt).setLanguage(t).setTheme(e)}function _t(t){return t instanceof mt}function St(t){return{node:xt(t.getAttribute(ht))}}function yt(t){const e=t,n=Ct(e);return n||function(t){let e=t.parentElement;for(;null!==e;){if(Ct(e))return!0;e=e.parentElement}return!1}(e)?{node:n?xt():null}:{node:null}}function bt(){return{node:xt()}}function vt(){return{node:null}}function Ct(t){return null!==t.style.fontFamily.match("monospace")}function Tt(t){return t.classList.contains("js-file-line-container")}function Nt(t){const{anchor:e}=t;if(t.isCollapsed()&&"element"===e.type){const t=e.getNode();if(_t(t)){const n=t.getChildrenSize();if(n>=2&&e.offset===n){const e=t.getLastChild();if(r(e)&&r(e.getPreviousSibling())){const e=p();return t.splice(n-2,2,[]).insertAfter(e,!1),e.select(),e}}}}return null}class At extends x{__highlightType;constructor(t="",e,n){super(t,n),this.__highlightType=e}static getType(){return"code-highlight"}static clone(t){return new At(t.__text,t.__highlightType||void 0,t.__key)}afterCloneFrom(t){super.afterCloneFrom(t),this.__highlightType=t.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(t){const e=this.getWritable();return e.__highlightType=t||void 0,e}canHaveFormat(){return!1}createDOM(t){const e=super.createDOM(t),n=Ot(t.theme,this.__highlightType);return a(e,n),e}updateDOM(t,e,n){const r=super.updateDOM(t,e,n),i=Ot(n.theme,t.__highlightType),o=Ot(n.theme,this.__highlightType);return i!==o&&(i&&_(e,i),o&&a(e,o)),r}static importJSON(t){return Pt().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 xt()}}function Ot(t,e){return e&&t&&t.codeHighlight&&t.codeHighlight[e]}function Pt(t="",e){return m(new At(t,e))}function wt(t){return t instanceof At}const Ht=S({name:"@lexical/code",nodes:()=>[mt,At],register:t=>t.registerCommand(y,t=>{const e=b();return!(!v(e)||!Nt(e))&&(t.preventDefault(),!0)},C)}),Dt="data-language";function kt(t){return null!==t.style.fontFamily.match("monospace")}function Bt(t){let e=t.parentElement;for(;null!==e;){if(kt(e))return!0;e=e.parentElement}return!1}const Lt=Z([Q({$import:(t,e)=>t.$importChildren(e),match:X.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),$t=Q({$import:(t,e)=>[xt(e.getAttribute(Dt)).splice(0,0,t.$importChildren(e))],match:X.tag("pre"),name:"@lexical/code/pre"}),Et=Q({$import:(t,e,n)=>{const r=e.textContent||"";return/\r?\n/.test(r)||null!==e.querySelector("br")?[xt(e.getAttribute(Dt)).splice(0,0,t.$importChildren(e))]:n()},match:X.tag("code"),name:"@lexical/code/code-multiline"});function Ft(t){if(!d(t))return!1;const e=t.style.fontFamily,n=t.style.whiteSpace;return"string"==typeof e&&/monospace/i.test(e)&&"string"==typeof n&&n.startsWith("pre")}function Mt(t){let e=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(t.childNodes))if(d(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),e=!0):"BR"===s.tagName?(o(),n.push(""),e=!0):(r+=s.textContent||"",i=!0);else if(A(s)){const t=s.textContent||"";t.length>0&&(r+=t,i=!0)}return o(),e?n:null}function Jt(t){for(const e of Array.from(t.children)){if(d(e)&&Ft(e)){if(null!==Mt(e))return!0;const t=e.nextElementSibling;if(t&&Ft(t))return!0;continue}if(Jt(e))return!0}return!1}const zt=Z([Q({$import:(t,e,n)=>{if(!Ft(e)||Bt(e))return n();const r=Mt(e);return null===r||0===r.length?n():[xt().splice(0,0,O(r.join("\n")))]},match:X.tag("div"),name:"@lexical/code/vscode-wrapper"}),Q({$import:(t,e,n)=>{if(!Ft(e)||Bt(e))return n();const r=e.previousElementSibling;if(r&&Ft(r))return[];const i=[];let o=e;for(;o&&Ft(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[xt().splice(0,0,O(i.join("\n")))]},match:X.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),It=Q({$import:(t,e,n)=>kt(e)?[xt().splice(0,0,t.$importChildren(e))]:Bt(e)?t.$importChildren(e):n(),match:X.tag("div"),name:"@lexical/code/div"}),Kt=[Q({$import:(t,e)=>[xt().splice(0,0,t.$importChildren(e,{rules:Lt}))],match:X.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),Q({$import:(t,e)=>t.$importChildren(e),match:X.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),Et,$t,It],jt=S({dependencies:[V,Ht,T(G,{preprocess:[(t,e,n)=>{Jt(N(t)?t.body:t)&&e.session.update(Y,t=>[...t,zt]),n()}],rules:Kt})],name:"@lexical/code/Import"});function Rt(t){if(!v(t))return!1;const e=t.anchor.getNode(),n=_t(e)?e:e.getParent(),r=t.focus.getNode(),i=_t(r)?r:r.getParent();return _t(n)&&n.is(i)}function Wt(t){const e=t.getNodes(),i=[];if(1===e.length&&_t(e[0]))return i;let o=[];for(let t=0;t<e.length;t++){const s=e[t];wt(s)||n(s)||r(s)||tt(169),r(s)?o.length>0&&(i.push(o),o=[]):o.push(s)}if(o.length>0){const e=t.isBackward()?t.anchor:t.focus,n=J(o[0].getKey(),0,"text");e.is(n)||i.push(o)}return i}function qt(t,e){const r=b();if(!v(r)||!Rt(r))return!1;const i=Wt(r),u=i.length;if(0===u&&r.isCollapsed())return t===B&&r.insertNodes([o()]),!0;if(0===u&&t===B&&"\n"===r.getTextContent()){const t=o(),e=s(),n=r.isBackward()?"previous":"next";return r.insertNodes([t,e]),z(I(K(j(t,"next",0),R(l(e,"next"))),n)),!0}for(let s=0;s<u;s++){const l=i[s];if(l.length>0){let i=l[0];if(0===s&&(i=nt(i)),t===B){const t=o();if(i.insertBefore(t),0===s){const e=r.isBackward()?"focus":"anchor",n=J(i.getKey(),0,"text");r[e].is(n)&&r[e].set(t.getKey(),0,"text")}}else n(i)?i.remove():void 0!==e&&wt(i)&&ut(i,e,r)}}return!0}function Ut(t,e){const i=b();if(!v(i))return!1;const{anchor:o,focus:s}=i,l=o.offset,u=s.offset,c=o.getNode(),a=s.getNode(),g=t===$;if(!Rt(i)||!wt(c)&&!n(c)||!wt(a)&&!n(a))return!1;if(!e.altKey){if(i.isCollapsed()){const t=c.getParentOrThrow();if(g&&0===l&&null===c.getPreviousSibling()){if(null===t.getPreviousSibling())return t.selectPrevious(),e.preventDefault(),!0}else if(!g&&l===c.getTextContentSize()&&null===c.getNextSibling()){if(null===t.getNextSibling())return t.selectNext(),e.preventDefault(),!0}}return!1}let h,f;if(c.isBefore(a)?(h=nt(c),f=rt(a)):(h=nt(a),f=rt(c)),null==h||null==f)return!1;const p=h.getNodesBetween(f);for(let t=0;t<p.length;t++){const e=p[t];if(!wt(e)&&!n(e)&&!r(e))return!1}e.preventDefault(),e.stopPropagation();const d=g?h.getPreviousSibling():f.getNextSibling();if(!r(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=wt(m)||n(m)||r(m)?g?nt(m):rt(m):null;let _=null!=x?x:m;return d.remove(),p.forEach(t=>t.remove()),t===$?(p.forEach(t=>_.insertBefore(t)),_.insertBefore(d)):(_.insertAfter(d),_=d,p.forEach(t=>{_.insertAfter(t),_=t})),i.setTextNodeRange(c,l,a,u),!0}function Vt(t,e){const i=b();if(!v(i))return!1;const{anchor:o,focus:s}=i,l=o.getNode(),u=s.getNode(),c=t===F;if(!Rt(i)||!wt(l)&&!n(l)||!wt(u)&&!n(u))return!1;const a=u,g="rtl"===it(a)?!c:c,h=o.key,f=o.offset,p=o.type;if(g){const t=ot(a,s.offset);if(null!==t){const{node:e,offset:n}=t;r(e)?e.selectNext(0,0):i.setTextNodeRange(e,n,e,n)}else a.getParentOrThrow().selectStart()}else{st(a).select()}return e.shiftKey&&i.anchor.set(h,f,p),e.preventDefault(),e.stopPropagation(),!0}function Gt(t,e){return w(t.registerCommand(H,e=>{const n=function(t){const e=b();if(!v(e)||!Rt(e))return null;const n=t?L:B,r=t?L:D,i=e.anchor,o=e.focus;if(i.is(o))return r;const s=Wt(e);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&tt(285),e.isBackward()?(u=o,c=i):(u=i,c=o);const a=nt(l[0]),g=rt(l[0]),h=J(a.getKey(),0,"text"),f=J(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(h)||f.isBefore(c)?n:h.isBefore(u)||c.isBefore(f)?r:n}(e.shiftKey);return null!==n&&(e.preventDefault(),t.dispatchCommand(n,void 0),!0)},C),t.registerCommand(D,()=>!!Rt(b())&&(k([o()]),!0),C),t.registerCommand(B,()=>qt(B),C),t.registerCommand(L,()=>qt(L,e),C),t.registerCommand($,t=>{const e=b();if(!v(e))return!1;const{anchor:n}=e,r=n.getNode();return!!Rt(e)&&(e.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&_t(r.getParentOrThrow())?(t.preventDefault(),!0):Ut($,t))},C),t.registerCommand(E,t=>{const e=b();if(!v(e))return!1;const{anchor:n}=e,r=n.getNode();return!!Rt(e)&&(e.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&_t(r.getParentOrThrow())?(t.preventDefault(),!0):Ut(E,t))},C),t.registerCommand(F,t=>Vt(F,t),C),t.registerCommand(M,t=>Vt(M,t),C))}const Qt=S({build:(t,e)=>U(e),config:P({disabled:!1,tabSize:void 0}),dependencies:[Ht],name:"@lexical/code-indent",register:(t,e,n)=>{const r=n.getOutput();return q(()=>{if(!r.disabled.value)return Gt(t,r.tabSize.value)})}});export{Pt as $createCodeHighlightNode,xt as $createCodeNode,it as $getCodeLineDirection,st as $getEndOfCodeInLine,nt as $getFirstCodeNodeOfLine,rt as $getLastCodeNodeOfLine,ot as $getStartOfCodeInLine,wt as $isCodeHighlightNode,_t as $isCodeNode,ut as $outdentLeadingSpaces,lt as $plainifyCodeContent,Ht as CodeExtension,At as CodeHighlightNode,jt as CodeImportExtension,Kt as CodeImportRules,Qt as CodeIndentExtension,mt as CodeNode,ct as DEFAULT_CODE_LANGUAGE,at as getDefaultCodeLanguage,Gt as registerCodeIndentation};
|
|
9
|
+
import{getTextDirection as e,$isElementNode as t,$isTabNode as n,$isLineBreakNode as r,tokenizeRawText as i,$createTabNode as o,$createLineBreakNode as s,$getSiblingCaret as l,$create as u,ElementNode as c,addClassNamesToElement as a,setDOMStyleFromCSS as g,$getEditor as h,$isTextNode as f,$createParagraphNode as p,isHTMLElement as d,$applyNodeReplacement as m,TextNode as x,removeClassNamesFromElement as _,defineExtension as S,KEY_ENTER_COMMAND as y,$getSelection as b,$isRangeSelection as v,COMMAND_PRIORITY_LOW as C,configExtension as N,isDOMDocumentNode as T,isDOMTextNode as A,$generateNodesFromRawText as O,safeCast as P,mergeRegister as w,KEY_ARROW_DOWN_COMMAND as H,KEY_ARROW_RIGHT_COMMAND as D,KEY_ARROW_UP_COMMAND as k,KEY_ARROW_LEFT_COMMAND as B,KEY_TAB_COMMAND as L,INSERT_TAB_COMMAND as $,$insertNodes as E,INDENT_CONTENT_COMMAND as F,OUTDENT_CONTENT_COMMAND as M,MOVE_TO_START as J,MOVE_TO_END as z,$createPoint as K,$setSelectionFromCaretRange as I,$getCaretRangeInDirection as j,$getCaretRange as R,$getTextPointCaret as W,$normalizeCaret as q}from"lexical";import{getPeerDependencyFromEditor as U,effect as V,namedSignals as G}from"@lexical/extension";import{CoreImportExtension as Q,DOMImportExtension as X,defineImportRule as Y,sel as Z,ImportOverlays as ee,defineOverlayRules as te}from"@lexical/html";import{$onEscapeDown as ne,$onEscapeUp as re}from"@lexical/utils";function ie(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 oe(e,t){let r=e;for(let i=l(e,t);i&&(Be(i.origin)||n(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function se(e){return oe(e,"previous")}function le(e){return oe(e,"next")}function ue(n){const r=se(n),i=le(n);let o=r;for(;null!==o;){if(Be(o)){const t=e(o.getTextContent());if(null!==t)return t}if(o===i)break;o=o.getNextSibling()}const s=r.getParent();if(t(s)){const e=s.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function ce(e,t){let i=null,o=null,s=e,l=t,u=e.getTextContent();for(;;){if(0===l){if(s=s.getPreviousSibling(),null===s)break;if(Be(s)||n(s)||r(s)||ie(167),r(s)){i={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),u=s.getTextContent()}else l--;const e=u[l];Be(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(t<e.getTextContentSize())Be(e)&&(c=e.getTextContent()[t]);else{const t=e.getNextSibling();Be(t)&&(c=t.getTextContent()[0])}if(null!==c&&" "!==c)return i;{const n=function(e,t){let n=e,i=t,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!Be(n)||i===s){if(n=n.getNextSibling(),null===n||r(n))return null;Be(n)&&(i=0,o=n.getTextContent(),s=n.getTextContentSize())}if(Be(n)){if(" "!==o[i])return{node:n,offset:i};i++}}}(e,t);return null!==n?n:i}}function ae(e){const t=le(e);return r(t)&&ie(168),t}function ge(e){const t=[];return i(e,{linebreak:()=>t.push(s()),tab:()=>t.push(o()),text:e=>t.push(ke(e))}),t}function he(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 fe="javascript",pe=()=>fe;function de(e,t){for(const n of e.childNodes){if(d(n)&&n.tagName===t)return!0;if(de(n,t))return!0}return!1}const me="data-language",xe="data-highlight-language",_e="data-theme",Se=()=>{};class ye extends c{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new ye(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=document.createElement("code");a(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(me,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(xe,n));const r=this.getTheme();r&&t.setAttribute(_e,r);const i=this.getStyle();return i&&g(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(me,r):i&&t.removeAttribute(me);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(xe,r):t.removeAttribute(xe):o&&r&&t.setAttribute(xe,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(_e,s):l&&t.removeAttribute(_e);const u=this.__style,c=e.__style;return u!==c&&g(t.style,u,c),!1}exportDOM(e){const t=document.createElement("pre");a(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(me,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(xe,n));const r=this.getTheme();r&&t.setAttribute(_e,r);const i=this.getStyle();return i&&g(t.style,i),{element:t}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||de(e,"BR"))?{conversion:Ce,priority:1}:null,div:()=>({conversion:Ne,priority:1}),pre:()=>({conversion:Ce,priority:0}),table:e=>Pe(e)?{conversion:Te,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&Pe(n)?{conversion:Ae,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&Pe(t)?{conversion:Ae,priority:3}:null}}}static importJSON(e){return be().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(!U(h(),"@lexical/code")){Se();const t=we(e);if(t)return t}const{anchor:r,focus:i}=e,l=(r.isBefore(i)?r:i).getNode();if(f(l)){let e=se(l);const t=[];for(;;)if(n(e))t.push(o()),e=e.getNextSibling();else{if(!Be(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(ke(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const i=l.splitText(r.offset)[0],u=0===r.offset?0:1,c=i.getIndexWithinParent()+u,a=l.getParentOrThrow(),g=[s(),...t];a.splice(c,0,g);const h=t[t.length-1];h?h.select():0===r.offset?i.selectPrevious():i.getNextSibling().selectNext(0,0)}if(ve(l)){const{offset:t}=e.anchor;l.splice(t,0,[s()]),l.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=p();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 be(e,t){return u(ye).setLanguage(e).setTheme(t)}function ve(e){return e instanceof ye}function Ce(e){return{node:be(e.getAttribute(me))}}function Ne(e){const t=e,n=Oe(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(Oe(t))return!0;t=t.parentElement}return!1}(t)?{node:n?be():null}:{node:null}}function Te(){return{node:be()}}function Ae(){return{node:null}}function Oe(e){return null!==e.style.fontFamily.match("monospace")}function Pe(e){return e.classList.contains("js-file-line-container")}function we(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(ve(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(r(t)&&r(t.getPreviousSibling())){const t=p();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class He extends x{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new He(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=De(e.theme,this.__highlightType);return a(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=De(n.theme,e.__highlightType),o=De(n.theme,this.__highlightType);return i!==o&&(i&&_(t,i),o&&a(t,o)),r}static importJSON(e){return ke().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 be()}}function De(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function ke(e="",t){return m(new He(e,t))}function Be(e){return e instanceof He}const Le=S({name:"@lexical/code",nodes:()=>[ye,He],register:e=>e.registerCommand(y,e=>{const t=b();return!(!v(t)||!we(t))&&(e.preventDefault(),!0)},C)}),$e="data-language";function Ee(e){return null!==e.style.fontFamily.match("monospace")}function Fe(e){let t=e.parentElement;for(;null!==t;){if(Ee(t))return!0;t=t.parentElement}return!1}const Me=te([Y({$import:(e,t)=>e.$importChildren(t),match:Z.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),Je=Y({$import:(e,t)=>[be(t.getAttribute($e)).splice(0,0,e.$importChildren(t))],match:Z.tag("pre"),name:"@lexical/code/pre"}),ze=Y({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[be(t.getAttribute($e)).splice(0,0,e.$importChildren(t))]:n()},match:Z.tag("code"),name:"@lexical/code/code-multiline"});function Ke(e){if(!d(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 Ie(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(d(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(A(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function je(e){for(const t of Array.from(e.children)){if(d(t)&&Ke(t)){if(null!==Ie(t))return!0;const e=t.nextElementSibling;if(e&&Ke(e))return!0;continue}if(je(t))return!0}return!1}const Re=te([Y({$import:(e,t,n)=>{if(!Ke(t)||Fe(t))return n();const r=Ie(t);return null===r||0===r.length?n():[be().splice(0,0,O(r.join("\n")))]},match:Z.tag("div"),name:"@lexical/code/vscode-wrapper"}),Y({$import:(e,t,n)=>{if(!Ke(t)||Fe(t))return n();const r=t.previousElementSibling;if(r&&Ke(r))return[];const i=[];let o=t;for(;o&&Ke(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[be().splice(0,0,O(i.join("\n")))]},match:Z.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),We=Y({$import:(e,t,n)=>Ee(t)?[be().splice(0,0,e.$importChildren(t))]:Fe(t)?e.$importChildren(t):n(),match:Z.tag("div"),name:"@lexical/code/div"}),qe=[Y({$import:(e,t)=>[be().splice(0,0,e.$importChildren(t,{rules:Me}))],match:Z.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),Y({$import:(e,t)=>e.$importChildren(t),match:Z.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),ze,Je,We],Ue=S({dependencies:[Q,Le,N(X,{preprocess:[(e,t,n)=>{je(T(e)?e.body:e)&&t.session.update(ee,e=>[...e,Re]),n()}],rules:qe})],name:"@lexical/code/Import"});function Ve(e){if(!v(e))return!1;const t=e.anchor.getNode(),n=ve(t)?t:t.getParent(),r=e.focus.getNode(),i=ve(r)?r:r.getParent();return ve(n)&&n.is(i)}function Ge(e){const t=e.getNodes(),i=[];if(1===t.length&&ve(t[0]))return i;let o=[];for(let e=0;e<t.length;e++){const s=t[e];Be(s)||n(s)||r(s)||ie(169),r(s)?o.length>0&&(i.push(o),o=[]):o.push(s)}if(o.length>0){const t=e.isBackward()?e.anchor:e.focus,n=K(o[0].getKey(),0,"text");t.is(n)||i.push(o)}return i}function Qe(e,t){const r=b();if(!v(r)||!Ve(r))return!1;const i=Ge(r),u=i.length;if(0===u&&r.isCollapsed())return e===F&&r.insertNodes([o()]),!0;if(0===u&&e===F&&"\n"===r.getTextContent()){const e=o(),t=s(),n=r.isBackward()?"previous":"next";return r.insertNodes([e,t]),I(j(R(W(e,"next",0),q(l(t,"next"))),n)),!0}for(let s=0;s<u;s++){const l=i[s];if(l.length>0){let i=l[0];if(0===s&&(i=se(i)),e===F){const e=o();if(i.insertBefore(e),0===s){const t=r.isBackward()?"focus":"anchor",n=K(i.getKey(),0,"text");r[t].is(n)&&r[t].set(e.getKey(),0,"text")}}else n(i)?i.remove():void 0!==t&&Be(i)&&he(i,t,r)}}return!0}function Xe(e,t){const i=b();if(!v(i))return!1;const{anchor:o,focus:s}=i,l=o.offset,u=s.offset,c=o.getNode(),a=s.getNode(),g=e===k;if(!Ve(i)||!Be(c)&&!n(c)||!Be(a)&&!n(a))return!1;if(!t.altKey){if(i.isCollapsed()){const e=c.getParentOrThrow();if(g&&0===l&&null===c.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&l===c.getTextContentSize()&&null===c.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let h,f;if(c.isBefore(a)?(h=se(c),f=le(a)):(h=se(a),f=le(c)),null==h||null==f)return!1;const p=h.getNodesBetween(f);for(let e=0;e<p.length;e++){const t=p[e];if(!Be(t)&&!n(t)&&!r(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?h.getPreviousSibling():f.getNextSibling();if(!r(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=Be(m)||n(m)||r(m)?g?se(m):le(m):null;let _=null!=x?x:m;return d.remove(),p.forEach(e=>e.remove()),e===k?(p.forEach(e=>_.insertBefore(e)),_.insertBefore(d)):(_.insertAfter(d),_=d,p.forEach(e=>{_.insertAfter(e),_=e})),i.setTextNodeRange(c,l,a,u),!0}function Ye(e,t){const i=b();if(!v(i))return!1;const{anchor:o,focus:s}=i,l=o.getNode(),u=s.getNode(),c=e===J;if(!Ve(i)||!Be(l)&&!n(l)||!Be(u)&&!n(u))return!1;const a=u,g="rtl"===ue(a)?!c:c,h=o.key,f=o.offset,p=o.type;if(g){const e=ce(a,s.offset);if(null!==e){const{node:t,offset:n}=e;r(t)?t.selectNext(0,0):i.setTextNodeRange(t,n,t,n)}else a.getParentOrThrow().selectStart()}else{ae(a).select()}return t.shiftKey&&i.anchor.set(h,f,p),t.preventDefault(),t.stopPropagation(),!0}function Ze(e,t,n){return w(...n?[e.registerCommand(H,e=>!e.altKey&&ne(ve),C),e.registerCommand(D,()=>ne(ve),C),e.registerCommand(k,e=>!e.altKey&&re(ve),C),e.registerCommand(B,()=>re(ve),C)]:[],e.registerCommand(L,t=>{const n=function(e){const t=b();if(!v(t)||!Ve(t))return null;const n=e?M:F,r=e?M:$,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Ge(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&ie(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=se(l[0]),g=le(l[0]),h=K(a.getKey(),0,"text"),f=K(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)},C),e.registerCommand($,()=>!!Ve(b())&&(E([o()]),!0),C),e.registerCommand(F,()=>Qe(F),C),e.registerCommand(M,()=>Qe(M,t),C),e.registerCommand(k,e=>{const t=b();if(!v(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Ve(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&ve(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):Xe(k,e)},C),e.registerCommand(H,e=>{const t=b();if(!v(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Ve(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&ve(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Xe(H,e))},C),e.registerCommand(J,e=>Ye(J,e),C),e.registerCommand(z,e=>Ye(z,e),C))}const et=S({build:(e,t)=>G(t),config:P({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[Le],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return V(()=>{if(!r.disabled.value)return Ze(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{ke as $createCodeHighlightNode,be as $createCodeNode,ue as $getCodeLineDirection,ae as $getEndOfCodeInLine,se as $getFirstCodeNodeOfLine,le as $getLastCodeNodeOfLine,ce as $getStartOfCodeInLine,Be as $isCodeHighlightNode,ve as $isCodeNode,he as $outdentLeadingSpaces,ge as $plainifyCodeContent,Le as CodeExtension,He as CodeHighlightNode,Ue as CodeImportExtension,qe as CodeImportRules,et as CodeIndentExtension,ye as CodeNode,fe as DEFAULT_CODE_LANGUAGE,pe as getDefaultCodeLanguage,Ze as registerCodeIndentation};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// You are seeing this declaration file because your TypeScript cannot read
|
|
10
|
+
// Lexical's types through the package.json "exports" field.
|
|
11
|
+
//
|
|
12
|
+
// Lexical requires TypeScript >= 5.2 with "moduleResolution" set to
|
|
13
|
+
// "bundler", "node16", or "nodenext". To fix this:
|
|
14
|
+
// 1. Upgrade TypeScript to >= 5.2.
|
|
15
|
+
// 2. In tsconfig.json set "moduleResolution" to "bundler" (recommended for
|
|
16
|
+
// apps/bundlers) or "node16" / "nodenext", and a matching "module".
|
|
17
|
+
import 'Lexical requires TypeScript >=5.2 with moduleResolution bundler, node16, or nodenext';
|
|
18
|
+
export {};
|
package/package.json
CHANGED
|
@@ -8,14 +8,15 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.45.1-nightly.
|
|
11
|
+
"version": "0.45.1-nightly.20260608.0",
|
|
12
12
|
"main": "./dist/LexicalCodeCore.js",
|
|
13
|
-
"types": "./dist/
|
|
13
|
+
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/extension": "0.45.1-nightly.
|
|
16
|
-
"@lexical/html": "0.45.1-nightly.
|
|
17
|
-
"lexical": "0.45.1-nightly.
|
|
18
|
-
"@lexical/
|
|
15
|
+
"@lexical/extension": "0.45.1-nightly.20260608.0",
|
|
16
|
+
"@lexical/html": "0.45.1-nightly.20260608.0",
|
|
17
|
+
"@lexical/internal": "0.45.1-nightly.20260608.0",
|
|
18
|
+
"@lexical/utils": "0.45.1-nightly.20260608.0",
|
|
19
|
+
"lexical": "0.45.1-nightly.20260608.0"
|
|
19
20
|
},
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
".": {
|
|
29
30
|
"source": "./src/index.ts",
|
|
30
31
|
"import": {
|
|
32
|
+
"types@<5.2": "./dist/typescript-too-old.d.ts",
|
|
31
33
|
"types": "./dist/index.d.ts",
|
|
32
34
|
"development": "./dist/LexicalCodeCore.dev.mjs",
|
|
33
35
|
"production": "./dist/LexicalCodeCore.prod.mjs",
|
|
@@ -35,6 +37,7 @@
|
|
|
35
37
|
"default": "./dist/LexicalCodeCore.mjs"
|
|
36
38
|
},
|
|
37
39
|
"require": {
|
|
40
|
+
"types@<5.2": "./dist/typescript-too-old.d.ts",
|
|
38
41
|
"types": "./dist/index.d.ts",
|
|
39
42
|
"development": "./dist/LexicalCodeCore.dev.js",
|
|
40
43
|
"production": "./dist/LexicalCodeCore.prod.js",
|
|
@@ -54,5 +57,20 @@
|
|
|
54
57
|
"!src/**/*.bench.tsx",
|
|
55
58
|
"README.md",
|
|
56
59
|
"LICENSE"
|
|
57
|
-
]
|
|
60
|
+
],
|
|
61
|
+
"typesVersions": {
|
|
62
|
+
"*": {
|
|
63
|
+
"*": [
|
|
64
|
+
"./dist/typescript-too-old.d.ts"
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"typescript": ">=5.2"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"typescript": {
|
|
73
|
+
"optional": true
|
|
74
|
+
}
|
|
75
|
+
}
|
|
58
76
|
}
|
package/src/CodeIndentation.ts
CHANGED
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
|
|
19
19
|
import {effect, namedSignals} from '@lexical/extension';
|
|
20
20
|
import invariant from '@lexical/internal/invariant';
|
|
21
|
+
import {$onEscapeDown, $onEscapeUp} from '@lexical/utils';
|
|
21
22
|
import {
|
|
22
23
|
$createLineBreakNode,
|
|
23
24
|
$createPoint,
|
|
@@ -38,6 +39,8 @@ import {
|
|
|
38
39
|
INDENT_CONTENT_COMMAND,
|
|
39
40
|
INSERT_TAB_COMMAND,
|
|
40
41
|
KEY_ARROW_DOWN_COMMAND,
|
|
42
|
+
KEY_ARROW_LEFT_COMMAND,
|
|
43
|
+
KEY_ARROW_RIGHT_COMMAND,
|
|
41
44
|
KEY_ARROW_UP_COMMAND,
|
|
42
45
|
KEY_TAB_COMMAND,
|
|
43
46
|
mergeRegister,
|
|
@@ -328,7 +331,7 @@ function $handleShiftLines(
|
|
|
328
331
|
if (codeNodeSibling === null) {
|
|
329
332
|
codeNode.selectPrevious();
|
|
330
333
|
event.preventDefault();
|
|
331
|
-
return
|
|
334
|
+
return false;
|
|
332
335
|
}
|
|
333
336
|
} else if (
|
|
334
337
|
!arrowIsUp &&
|
|
@@ -339,7 +342,7 @@ function $handleShiftLines(
|
|
|
339
342
|
if (codeNodeSibling === null) {
|
|
340
343
|
codeNode.selectNext();
|
|
341
344
|
event.preventDefault();
|
|
342
|
-
return
|
|
345
|
+
return false;
|
|
343
346
|
}
|
|
344
347
|
}
|
|
345
348
|
}
|
|
@@ -502,8 +505,36 @@ function $handleMoveTo(
|
|
|
502
505
|
export function registerCodeIndentation(
|
|
503
506
|
editor: LexicalEditor,
|
|
504
507
|
tabSize?: number,
|
|
508
|
+
escapeWithArrows?: boolean,
|
|
505
509
|
): () => void {
|
|
506
510
|
return mergeRegister(
|
|
511
|
+
// When node is the last child pressing down/right or up/let arrow will insert paragraph
|
|
512
|
+
// below it to allow adding more content.
|
|
513
|
+
// These handlers must be executed before $handleShiftLines
|
|
514
|
+
...(escapeWithArrows
|
|
515
|
+
? [
|
|
516
|
+
editor.registerCommand(
|
|
517
|
+
KEY_ARROW_DOWN_COMMAND,
|
|
518
|
+
event => (event.altKey ? false : $onEscapeDown($isCodeNode)),
|
|
519
|
+
COMMAND_PRIORITY_LOW,
|
|
520
|
+
),
|
|
521
|
+
editor.registerCommand(
|
|
522
|
+
KEY_ARROW_RIGHT_COMMAND,
|
|
523
|
+
() => $onEscapeDown($isCodeNode),
|
|
524
|
+
COMMAND_PRIORITY_LOW,
|
|
525
|
+
),
|
|
526
|
+
editor.registerCommand(
|
|
527
|
+
KEY_ARROW_UP_COMMAND,
|
|
528
|
+
event => (event.altKey ? false : $onEscapeUp($isCodeNode)),
|
|
529
|
+
COMMAND_PRIORITY_LOW,
|
|
530
|
+
),
|
|
531
|
+
editor.registerCommand(
|
|
532
|
+
KEY_ARROW_LEFT_COMMAND,
|
|
533
|
+
() => $onEscapeUp($isCodeNode),
|
|
534
|
+
COMMAND_PRIORITY_LOW,
|
|
535
|
+
),
|
|
536
|
+
]
|
|
537
|
+
: []),
|
|
507
538
|
editor.registerCommand(
|
|
508
539
|
KEY_TAB_COMMAND,
|
|
509
540
|
event => {
|
|
@@ -552,11 +583,13 @@ export function registerCodeIndentation(
|
|
|
552
583
|
return false;
|
|
553
584
|
}
|
|
554
585
|
// If at the start of a code block, prevent selection from moving out
|
|
586
|
+
const parent = anchorNode.getParent();
|
|
555
587
|
if (
|
|
556
588
|
selection.isCollapsed() &&
|
|
557
589
|
anchor.offset === 0 &&
|
|
558
590
|
anchorNode.getPreviousSibling() === null &&
|
|
559
|
-
$isCodeNode(
|
|
591
|
+
$isCodeNode(parent) &&
|
|
592
|
+
parent.getPreviousSibling() === null
|
|
560
593
|
) {
|
|
561
594
|
event.preventDefault();
|
|
562
595
|
return true;
|
|
@@ -582,7 +615,8 @@ export function registerCodeIndentation(
|
|
|
582
615
|
selection.isCollapsed() &&
|
|
583
616
|
anchor.offset === anchorNode.getTextContentSize() &&
|
|
584
617
|
anchorNode.getNextSibling() === null &&
|
|
585
|
-
$isCodeNode(anchorNode.getParentOrThrow())
|
|
618
|
+
$isCodeNode(anchorNode.getParentOrThrow()) &&
|
|
619
|
+
anchorNode.getParentOrThrow().getNextSibling() === null
|
|
586
620
|
) {
|
|
587
621
|
event.preventDefault();
|
|
588
622
|
return true;
|
|
@@ -621,6 +655,15 @@ export interface CodeIndentConfig {
|
|
|
621
655
|
* this option.
|
|
622
656
|
*/
|
|
623
657
|
tabSize: number | undefined;
|
|
658
|
+
/**
|
|
659
|
+
* When `true`, this enables the ability to exit a code block
|
|
660
|
+
* that has no adjacent elements using the ArrowLeft/ArrowUp keys
|
|
661
|
+
* if the cursor is at the beginning, or the ArrowRight/ArrowDown keys
|
|
662
|
+
* if the cursor is at the end.
|
|
663
|
+
* When `false` (default), pressing the arrow keys will not move the cursor
|
|
664
|
+
* if there are no adjacent elements around the code block
|
|
665
|
+
*/
|
|
666
|
+
escapeWithArrows: boolean;
|
|
624
667
|
}
|
|
625
668
|
|
|
626
669
|
/**
|
|
@@ -638,6 +681,7 @@ export const CodeIndentExtension = defineExtension({
|
|
|
638
681
|
build: (editor, config) => namedSignals(config),
|
|
639
682
|
config: safeCast<CodeIndentConfig>({
|
|
640
683
|
disabled: false,
|
|
684
|
+
escapeWithArrows: false,
|
|
641
685
|
tabSize: undefined,
|
|
642
686
|
}),
|
|
643
687
|
dependencies: [CodeExtension],
|
|
@@ -648,7 +692,11 @@ export const CodeIndentExtension = defineExtension({
|
|
|
648
692
|
if (stores.disabled.value) {
|
|
649
693
|
return;
|
|
650
694
|
}
|
|
651
|
-
return registerCodeIndentation(
|
|
695
|
+
return registerCodeIndentation(
|
|
696
|
+
editor,
|
|
697
|
+
stores.tabSize.value,
|
|
698
|
+
stores.escapeWithArrows.value,
|
|
699
|
+
);
|
|
652
700
|
});
|
|
653
701
|
},
|
|
654
702
|
});
|