@lexical/code-core 0.49.1-nightly.20260820.0 → 0.49.1-nightly.20260824.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/LexicalCodeCore.dev.js +54 -10
- package/dist/LexicalCodeCore.dev.mjs +54 -10
- package/dist/LexicalCodeCore.prod.js +1 -1
- package/dist/LexicalCodeCore.prod.mjs +2 -2
- package/package.json +6 -6
- package/src/CodeImportExtension.ts +9 -10
- package/src/CodeIndentation.ts +45 -4
- package/src/CodeNode.ts +4 -1
|
@@ -282,7 +282,7 @@ function hasChildDOMNodeTag(node, tagName) {
|
|
|
282
282
|
}
|
|
283
283
|
const LANGUAGE_DATA_ATTRIBUTE$1 = 'data-language';
|
|
284
284
|
const HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE = 'data-highlight-language';
|
|
285
|
-
const THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
285
|
+
const THEME_DATA_ATTRIBUTE$1 = 'data-theme';
|
|
286
286
|
const noExtensionDeprecation = warnOnlyOnce('Using CodeNode without CodeExtension is deprecated');
|
|
287
287
|
|
|
288
288
|
/** @noInheritDoc */
|
|
@@ -386,7 +386,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
386
386
|
}
|
|
387
387
|
const theme = this.getTheme();
|
|
388
388
|
if (theme) {
|
|
389
|
-
element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
389
|
+
element.setAttribute(THEME_DATA_ATTRIBUTE$1, theme);
|
|
390
390
|
}
|
|
391
391
|
const style = this.getStyle();
|
|
392
392
|
if (style) {
|
|
@@ -421,10 +421,10 @@ class CodeNode extends lexical.ElementNode {
|
|
|
421
421
|
const prevTheme = prevNode.__theme;
|
|
422
422
|
if (theme) {
|
|
423
423
|
if (theme !== prevTheme) {
|
|
424
|
-
dom.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
424
|
+
dom.setAttribute(THEME_DATA_ATTRIBUTE$1, theme);
|
|
425
425
|
}
|
|
426
426
|
} else if (prevTheme) {
|
|
427
|
-
dom.removeAttribute(THEME_DATA_ATTRIBUTE);
|
|
427
|
+
dom.removeAttribute(THEME_DATA_ATTRIBUTE$1);
|
|
428
428
|
}
|
|
429
429
|
const style = this.__style;
|
|
430
430
|
const prevStyle = prevNode.__style;
|
|
@@ -446,7 +446,7 @@ class CodeNode extends lexical.ElementNode {
|
|
|
446
446
|
}
|
|
447
447
|
const theme = this.getTheme();
|
|
448
448
|
if (theme) {
|
|
449
|
-
element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
449
|
+
element.setAttribute(THEME_DATA_ATTRIBUTE$1, theme);
|
|
450
450
|
}
|
|
451
451
|
const style = this.getStyle();
|
|
452
452
|
if (style) {
|
|
@@ -577,8 +577,11 @@ function $isCodeNode(node) {
|
|
|
577
577
|
}
|
|
578
578
|
function $convertPreElement(domNode) {
|
|
579
579
|
const language = domNode.getAttribute(LANGUAGE_DATA_ATTRIBUTE$1);
|
|
580
|
+
// exportDOM writes data-theme next to data-language, so read it back here
|
|
581
|
+
// too — otherwise the theme is dropped on every HTML round trip.
|
|
582
|
+
const theme = domNode.getAttribute(THEME_DATA_ATTRIBUTE$1);
|
|
580
583
|
return {
|
|
581
|
-
node: $createCodeNode(language)
|
|
584
|
+
node: $createCodeNode(language, theme)
|
|
582
585
|
};
|
|
583
586
|
}
|
|
584
587
|
function $convertDivElement(domNode) {
|
|
@@ -742,6 +745,7 @@ function $isCodeHighlightNode(node) {
|
|
|
742
745
|
*/
|
|
743
746
|
|
|
744
747
|
const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
|
|
748
|
+
const THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
745
749
|
|
|
746
750
|
/**
|
|
747
751
|
* True for elements whose `font-family` mentions `monospace` — the
|
|
@@ -777,7 +781,7 @@ const GitHubCodeTableOverlayRules = /* @__PURE__ */html.defineOverlayRules([/* @
|
|
|
777
781
|
name: '@lexical/code/github-code-table/unwrap'
|
|
778
782
|
})]);
|
|
779
783
|
const PreRule = /* @__PURE__ */html.defineImportRule({
|
|
780
|
-
$import: (ctx, el) => [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))],
|
|
784
|
+
$import: (ctx, el) => [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE), el.getAttribute(THEME_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))],
|
|
781
785
|
match: html.sel.tag('pre'),
|
|
782
786
|
name: '@lexical/code/pre'
|
|
783
787
|
});
|
|
@@ -795,7 +799,7 @@ const MultilineCodeRule = /* @__PURE__ */html.defineImportRule({
|
|
|
795
799
|
if (!isMultiLine) {
|
|
796
800
|
return $next();
|
|
797
801
|
}
|
|
798
|
-
return [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))];
|
|
802
|
+
return [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE), el.getAttribute(THEME_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))];
|
|
799
803
|
},
|
|
800
804
|
match: html.sel.tag('code'),
|
|
801
805
|
name: '@lexical/code/code-multiline'
|
|
@@ -1216,6 +1220,29 @@ function $handleTab(shiftKey) {
|
|
|
1216
1220
|
// 5. Selection is matching a full line on non-empty code
|
|
1217
1221
|
return indentOrOutdent;
|
|
1218
1222
|
}
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* Outdent the single line the collapsed caret sits on.
|
|
1226
|
+
*
|
|
1227
|
+
* `$getCodeLines` drops a trailing line when the selection ends exactly at its
|
|
1228
|
+
* start — for a collapsed caret that is always true, so the caret's own line
|
|
1229
|
+
* never reaches the outdent loop and the line has to be resolved from the
|
|
1230
|
+
* anchor here. Applies the same rule as that loop: strip a leading TabNode, or
|
|
1231
|
+
* `tabSize` leading spaces when the extension is configured for them.
|
|
1232
|
+
*/
|
|
1233
|
+
function $outdentLineAtCaret(selection, tabSize) {
|
|
1234
|
+
const anchorNode = selection.anchor.getNode();
|
|
1235
|
+
// An element point (e.g. the caret on a blank line) has no line to outdent.
|
|
1236
|
+
if (!$isCodeHighlightNode(anchorNode) && !lexical.$isTabNode(anchorNode)) {
|
|
1237
|
+
return;
|
|
1238
|
+
}
|
|
1239
|
+
const firstOfLine = $getFirstCodeNodeOfLine(anchorNode);
|
|
1240
|
+
if (lexical.$isTabNode(firstOfLine)) {
|
|
1241
|
+
firstOfLine.remove();
|
|
1242
|
+
} else if (tabSize !== undefined && $isCodeHighlightNode(firstOfLine)) {
|
|
1243
|
+
$outdentLeadingSpaces(firstOfLine, tabSize, selection);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1219
1246
|
function $handleMultilineIndent(type, tabSize) {
|
|
1220
1247
|
const selection = lexical.$getSelection();
|
|
1221
1248
|
if (!lexical.$isRangeSelection(selection) || !$isSelectionInCode(selection)) {
|
|
@@ -1229,6 +1256,8 @@ function $handleMultilineIndent(type, tabSize) {
|
|
|
1229
1256
|
if (codeLinesLength === 0 && selection.isCollapsed()) {
|
|
1230
1257
|
if (type === lexical.INDENT_CONTENT_COMMAND) {
|
|
1231
1258
|
selection.insertNodes([lexical.$createTabNode()]);
|
|
1259
|
+
} else {
|
|
1260
|
+
$outdentLineAtCaret(selection, tabSize);
|
|
1232
1261
|
}
|
|
1233
1262
|
return true;
|
|
1234
1263
|
}
|
|
@@ -1358,11 +1387,26 @@ function $handleShiftLines(type, event) {
|
|
|
1358
1387
|
if (sibling == null) {
|
|
1359
1388
|
return true;
|
|
1360
1389
|
}
|
|
1361
|
-
|
|
1390
|
+
|
|
1391
|
+
// A LineBreakNode sibling means the adjacent line is blank, so it has no
|
|
1392
|
+
// node of its own to anchor the move to — $getFirstCodeNodeOfLine /
|
|
1393
|
+
// $getLastCodeNodeOfLine hand that linebreak straight back, and it belongs
|
|
1394
|
+
// to a *different* line. Anchoring on it splices the moving line into the
|
|
1395
|
+
// line on the far side of the blank one, merging the two.
|
|
1396
|
+
const adjacentLineIsBlank = lexical.$isLineBreakNode(sibling);
|
|
1397
|
+
const maybeInsertionPoint = !adjacentLineIsBlank && ($isCodeHighlightNode(sibling) || lexical.$isTabNode(sibling)) ? arrowIsUp ? $getFirstCodeNodeOfLine(sibling) : $getLastCodeNodeOfLine(sibling) : null;
|
|
1362
1398
|
let insertionPoint = maybeInsertionPoint != null ? maybeInsertionPoint : sibling;
|
|
1363
1399
|
linebreak.remove();
|
|
1364
1400
|
range.forEach(node => node.remove());
|
|
1365
|
-
if (
|
|
1401
|
+
if (adjacentLineIsBlank) {
|
|
1402
|
+
// The blank line's position is immediately after the sibling linebreak,
|
|
1403
|
+
// in both directions.
|
|
1404
|
+
range.forEach(node => {
|
|
1405
|
+
insertionPoint.insertAfter(node);
|
|
1406
|
+
insertionPoint = node;
|
|
1407
|
+
});
|
|
1408
|
+
insertionPoint.insertAfter(linebreak);
|
|
1409
|
+
} else if (type === lexical.KEY_ARROW_UP_COMMAND) {
|
|
1366
1410
|
range.forEach(node => insertionPoint.insertBefore(node));
|
|
1367
1411
|
insertionPoint.insertBefore(linebreak);
|
|
1368
1412
|
} else {
|
|
@@ -280,7 +280,7 @@ function hasChildDOMNodeTag(node, tagName) {
|
|
|
280
280
|
}
|
|
281
281
|
const LANGUAGE_DATA_ATTRIBUTE$1 = 'data-language';
|
|
282
282
|
const HIGHLIGHT_LANGUAGE_DATA_ATTRIBUTE = 'data-highlight-language';
|
|
283
|
-
const THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
283
|
+
const THEME_DATA_ATTRIBUTE$1 = 'data-theme';
|
|
284
284
|
const noExtensionDeprecation = warnOnlyOnce('Using CodeNode without CodeExtension is deprecated');
|
|
285
285
|
|
|
286
286
|
/** @noInheritDoc */
|
|
@@ -384,7 +384,7 @@ class CodeNode extends ElementNode {
|
|
|
384
384
|
}
|
|
385
385
|
const theme = this.getTheme();
|
|
386
386
|
if (theme) {
|
|
387
|
-
element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
387
|
+
element.setAttribute(THEME_DATA_ATTRIBUTE$1, theme);
|
|
388
388
|
}
|
|
389
389
|
const style = this.getStyle();
|
|
390
390
|
if (style) {
|
|
@@ -419,10 +419,10 @@ class CodeNode extends ElementNode {
|
|
|
419
419
|
const prevTheme = prevNode.__theme;
|
|
420
420
|
if (theme) {
|
|
421
421
|
if (theme !== prevTheme) {
|
|
422
|
-
dom.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
422
|
+
dom.setAttribute(THEME_DATA_ATTRIBUTE$1, theme);
|
|
423
423
|
}
|
|
424
424
|
} else if (prevTheme) {
|
|
425
|
-
dom.removeAttribute(THEME_DATA_ATTRIBUTE);
|
|
425
|
+
dom.removeAttribute(THEME_DATA_ATTRIBUTE$1);
|
|
426
426
|
}
|
|
427
427
|
const style = this.__style;
|
|
428
428
|
const prevStyle = prevNode.__style;
|
|
@@ -444,7 +444,7 @@ class CodeNode extends ElementNode {
|
|
|
444
444
|
}
|
|
445
445
|
const theme = this.getTheme();
|
|
446
446
|
if (theme) {
|
|
447
|
-
element.setAttribute(THEME_DATA_ATTRIBUTE, theme);
|
|
447
|
+
element.setAttribute(THEME_DATA_ATTRIBUTE$1, theme);
|
|
448
448
|
}
|
|
449
449
|
const style = this.getStyle();
|
|
450
450
|
if (style) {
|
|
@@ -575,8 +575,11 @@ function $isCodeNode(node) {
|
|
|
575
575
|
}
|
|
576
576
|
function $convertPreElement(domNode) {
|
|
577
577
|
const language = domNode.getAttribute(LANGUAGE_DATA_ATTRIBUTE$1);
|
|
578
|
+
// exportDOM writes data-theme next to data-language, so read it back here
|
|
579
|
+
// too — otherwise the theme is dropped on every HTML round trip.
|
|
580
|
+
const theme = domNode.getAttribute(THEME_DATA_ATTRIBUTE$1);
|
|
578
581
|
return {
|
|
579
|
-
node: $createCodeNode(language)
|
|
582
|
+
node: $createCodeNode(language, theme)
|
|
580
583
|
};
|
|
581
584
|
}
|
|
582
585
|
function $convertDivElement(domNode) {
|
|
@@ -740,6 +743,7 @@ function $isCodeHighlightNode(node) {
|
|
|
740
743
|
*/
|
|
741
744
|
|
|
742
745
|
const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
|
|
746
|
+
const THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
743
747
|
|
|
744
748
|
/**
|
|
745
749
|
* True for elements whose `font-family` mentions `monospace` — the
|
|
@@ -775,7 +779,7 @@ const GitHubCodeTableOverlayRules = /* @__PURE__ */defineOverlayRules([/* @__PUR
|
|
|
775
779
|
name: '@lexical/code/github-code-table/unwrap'
|
|
776
780
|
})]);
|
|
777
781
|
const PreRule = /* @__PURE__ */defineImportRule({
|
|
778
|
-
$import: (ctx, el) => [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))],
|
|
782
|
+
$import: (ctx, el) => [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE), el.getAttribute(THEME_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))],
|
|
779
783
|
match: sel.tag('pre'),
|
|
780
784
|
name: '@lexical/code/pre'
|
|
781
785
|
});
|
|
@@ -793,7 +797,7 @@ const MultilineCodeRule = /* @__PURE__ */defineImportRule({
|
|
|
793
797
|
if (!isMultiLine) {
|
|
794
798
|
return $next();
|
|
795
799
|
}
|
|
796
|
-
return [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))];
|
|
800
|
+
return [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE), el.getAttribute(THEME_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))];
|
|
797
801
|
},
|
|
798
802
|
match: sel.tag('code'),
|
|
799
803
|
name: '@lexical/code/code-multiline'
|
|
@@ -1214,6 +1218,29 @@ function $handleTab(shiftKey) {
|
|
|
1214
1218
|
// 5. Selection is matching a full line on non-empty code
|
|
1215
1219
|
return indentOrOutdent;
|
|
1216
1220
|
}
|
|
1221
|
+
|
|
1222
|
+
/**
|
|
1223
|
+
* Outdent the single line the collapsed caret sits on.
|
|
1224
|
+
*
|
|
1225
|
+
* `$getCodeLines` drops a trailing line when the selection ends exactly at its
|
|
1226
|
+
* start — for a collapsed caret that is always true, so the caret's own line
|
|
1227
|
+
* never reaches the outdent loop and the line has to be resolved from the
|
|
1228
|
+
* anchor here. Applies the same rule as that loop: strip a leading TabNode, or
|
|
1229
|
+
* `tabSize` leading spaces when the extension is configured for them.
|
|
1230
|
+
*/
|
|
1231
|
+
function $outdentLineAtCaret(selection, tabSize) {
|
|
1232
|
+
const anchorNode = selection.anchor.getNode();
|
|
1233
|
+
// An element point (e.g. the caret on a blank line) has no line to outdent.
|
|
1234
|
+
if (!$isCodeHighlightNode(anchorNode) && !$isTabNode(anchorNode)) {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
const firstOfLine = $getFirstCodeNodeOfLine(anchorNode);
|
|
1238
|
+
if ($isTabNode(firstOfLine)) {
|
|
1239
|
+
firstOfLine.remove();
|
|
1240
|
+
} else if (tabSize !== undefined && $isCodeHighlightNode(firstOfLine)) {
|
|
1241
|
+
$outdentLeadingSpaces(firstOfLine, tabSize, selection);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1217
1244
|
function $handleMultilineIndent(type, tabSize) {
|
|
1218
1245
|
const selection = $getSelection();
|
|
1219
1246
|
if (!$isRangeSelection(selection) || !$isSelectionInCode(selection)) {
|
|
@@ -1227,6 +1254,8 @@ function $handleMultilineIndent(type, tabSize) {
|
|
|
1227
1254
|
if (codeLinesLength === 0 && selection.isCollapsed()) {
|
|
1228
1255
|
if (type === INDENT_CONTENT_COMMAND) {
|
|
1229
1256
|
selection.insertNodes([$createTabNode()]);
|
|
1257
|
+
} else {
|
|
1258
|
+
$outdentLineAtCaret(selection, tabSize);
|
|
1230
1259
|
}
|
|
1231
1260
|
return true;
|
|
1232
1261
|
}
|
|
@@ -1356,11 +1385,26 @@ function $handleShiftLines(type, event) {
|
|
|
1356
1385
|
if (sibling == null) {
|
|
1357
1386
|
return true;
|
|
1358
1387
|
}
|
|
1359
|
-
|
|
1388
|
+
|
|
1389
|
+
// A LineBreakNode sibling means the adjacent line is blank, so it has no
|
|
1390
|
+
// node of its own to anchor the move to — $getFirstCodeNodeOfLine /
|
|
1391
|
+
// $getLastCodeNodeOfLine hand that linebreak straight back, and it belongs
|
|
1392
|
+
// to a *different* line. Anchoring on it splices the moving line into the
|
|
1393
|
+
// line on the far side of the blank one, merging the two.
|
|
1394
|
+
const adjacentLineIsBlank = $isLineBreakNode(sibling);
|
|
1395
|
+
const maybeInsertionPoint = !adjacentLineIsBlank && ($isCodeHighlightNode(sibling) || $isTabNode(sibling)) ? arrowIsUp ? $getFirstCodeNodeOfLine(sibling) : $getLastCodeNodeOfLine(sibling) : null;
|
|
1360
1396
|
let insertionPoint = maybeInsertionPoint != null ? maybeInsertionPoint : sibling;
|
|
1361
1397
|
linebreak.remove();
|
|
1362
1398
|
range.forEach(node => node.remove());
|
|
1363
|
-
if (
|
|
1399
|
+
if (adjacentLineIsBlank) {
|
|
1400
|
+
// The blank line's position is immediately after the sibling linebreak,
|
|
1401
|
+
// in both directions.
|
|
1402
|
+
range.forEach(node => {
|
|
1403
|
+
insertionPoint.insertAfter(node);
|
|
1404
|
+
insertionPoint = node;
|
|
1405
|
+
});
|
|
1406
|
+
insertionPoint.insertAfter(linebreak);
|
|
1407
|
+
} else if (type === KEY_ARROW_UP_COMMAND) {
|
|
1364
1408
|
range.forEach(node => insertionPoint.insertBefore(node));
|
|
1365
1409
|
insertionPoint.insertBefore(linebreak);
|
|
1366
1410
|
} else {
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/html"),t=require("lexical"),n=require("@lexical/extension"),r=require("@lexical/utils");function i(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function o(e,n){let r=e;for(let i=t.$getSiblingCaret(e,n);i&&(y(i.origin)||t.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function s(e){return o(e,"previous")}function l(e){return o(e,"next")}function a(e){const n=s(e),r=l(e);let i=n;for(;null!==i;){if(y(i)){const e=t.getTextDirection(i.getTextContent());if(null!==e)return e}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(t.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function c(e,n){let r=null,o=null,s=e,l=n,a=e.getTextContent();for(;;){if(0===l){const e=s.getPreviousSibling();if(null===e){s=null;break}if(y(e)||t.$isTabNode(e)||t.$isLineBreakNode(e)||i(167),s=e,t.$isLineBreakNode(s)){r={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const e=a[l];y(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<e.getTextContentSize())y(e)&&(c=e.getTextContent()[n]);else{const t=e.getNextSibling();y(t)&&(c=t.getTextContent()[0])}if(null!==c&&" "!==c)return r;{const i=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!y(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;y(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(y(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,n);return null!==i?i:r}}function u(e){const n=l(e);return t.$isLineBreakNode(n)&&i(168),n}function g(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,a=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==a&&n.focus.set(s,Math.max(0,a-o),"text"),!0}const d="javascript";function f(e,n){for(const r of e.childNodes){if(t.isHTMLElement(r)&&r.tagName===n)return!0;if(f(r,n))return!0}return!1}const h="data-language",p="data-highlight-language",N="data-theme",m=()=>{};class _ extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:t.ElementNode,importDOM:{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||f(e,"BR"))?{conversion:C,priority:1}:null,div:()=>({conversion:O,priority:1}),pre:()=>({conversion:C,priority:0}),table:e=>b(e)?{conversion:S,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:$,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:$,priority:3}:null}}})}constructor(e=void 0,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const n=t.$getDocument().createElement("code");t.addClassNamesToElement(n,e.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),n}updateDOM(e,n,r){const i=this.__language,o=e.__language;i?i!==o&&n.setAttribute(h,i):o&&n.removeAttribute(h);const s=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(p,i):n.removeAttribute(p):s&&i&&n.setAttribute(p,i);const l=this.__theme,a=e.__theme;l?l!==a&&n.setAttribute(N,l):a&&n.removeAttribute(N);const c=this.__style,u=e.__style;return c!==u&&t.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(e){const n=t.$getDocument().createElement("pre");t.addClassNamesToElement(n,e._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),{element:n}}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,r=!0){if(!n.getPeerDependencyFromEditor(t.$getEditor(),"@lexical/code")){m();const t=E(e);if(t)return t}const{anchor:i,focus:o}=e,l=(i.isBefore(o)?i:o).getNode();if(t.$isTextNode(l)){let e=s(l);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!y(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(A(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=l.splitText(i.offset)[0],o=0===i.offset?0:1,a=r.getIndexWithinParent()+o,c=l.getParentOrThrow(),u=[t.$createLineBreakNode(),...n];c.splice(a,0,u);const g=n[n.length-1];g?g.select():0===i.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(x(l)){const{offset:n}=e.anchor;l.splice(n,0,[t.$createLineBreakNode()]),l.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function T(e,n){return t.$create(_).setLanguage(e).setTheme(n)}function x(e){return e instanceof _}function C(e){return{node:T(e.getAttribute(h))}}function O(e){const t=e,n=M(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(M(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function $(){return{node:null}}function M(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function E(e){const{anchor:n}=e;if(e.isCollapsed()&&"element"===n.type){const e=n.getNode();if(x(e)){const r=e.getChildrenSize();if(r>=2&&n.offset===r){const n=e.getLastChild();if(t.$isLineBreakNode(n)&&t.$isLineBreakNode(n.getPreviousSibling())){const n=t.$createParagraphNode();return e.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class R extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}$config(){return this.config("code-highlight",{extends:t.TextNode})}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const n=super.createDOM(e),r=D(e.theme,this.__highlightType);return t.addClassNamesToElement(n,r),n}updateDOM(e,n,r){const i=super.updateDOM(e,n,r),o=D(r.theme,e.__highlightType),s=D(r.theme,this.__highlightType);return o!==s&&(o&&t.removeClassNamesFromElement(n,o),s&&t.addClassNamesToElement(n,s)),i}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return T()}}function D(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function A(e="",n){return t.$applyNodeReplacement(new R(e,n))}function y(e){return e instanceof R}const v="data-language";function I(e){return null!==e.style.fontFamily.match("monospace")}function L(e){let t=e.parentElement;for(;null!==t;){if(I(t))return!0;t=t.parentElement}return!1}const P=/* @__PURE__ */e.defineOverlayRules([/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),B=/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))],match:e.sel.tag("pre"),name:"@lexical/code/pre"}),W=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))]:n()},match:e.sel.tag("code"),name:"@lexical/code/code-multiline"});function k(e){if(!t.isHTMLElement(e))return!1;const n=e.style.fontFamily,r=e.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function H(e){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(e.childNodes))if(t.isHTMLElement(l))"DIV"===l.tagName?(s(),r.push(l.textContent||""),n=!0):"BR"===l.tagName?(s(),r.push(""),n=!0):(i+=l.textContent||"",o=!0);else if(t.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function w(e){for(const n of Array.from(e.children)){if(t.isHTMLElement(n)&&k(n)){if(null!==H(n))return!0;const e=n.nextElementSibling;if(e&&k(e))return!0;continue}if(w(n))return!0}return!1}const F=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!k(n)||L(n))return r();const i=H(n);return null===i||0===i.length?r():[T().splice(0,0,t.$generateNodesFromRawText(i.join("\n")))]},match:e.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),Y=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!k(n)||L(n))return r();const i=n.previousElementSibling;if(i&&k(i))return[];const o=[];let s=n;for(;s&&k(s);)o.push("BR"===s.tagName?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?r():[T().splice(0,0,t.$generateNodesFromRawText(o.join("\n")))]},match:e.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),K=/* @__PURE__ */e.defineOverlayRules([F,Y]),U=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>I(t)?[T().splice(0,0,e.$importChildren(t))]:L(t)?e.$importChildren(t):n(),match:e.sel.tag("div"),name:"@lexical/code/div"}),z=[/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T().splice(0,0,e.$importChildren(t,{rules:P}))],match:e.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),W,B,U],j=/* @__PURE__ */t.defineExtension({dependencies:[e.CoreImportExtension,/* @__PURE__ */t.configExtension(e.DOMImportExtension,{preprocess:[(n,r,i)=>{w(t.isDOMDocumentNode(n)?n.body:n)&&r.session.update(e.ImportOverlays,e=>[...e,K]),i()}],rules:z})],name:"@lexical/code",nodes:()=>[_,R],register:e=>t.mergeRegister(e.registerCommand(t.KEY_ENTER_COMMAND,e=>{const n=t.$getSelection();return!(!t.$isRangeSelection(n)||!E(n))&&(null!==e&&e.preventDefault(),!0)},t.COMMAND_PRIORITY_LOW),e.registerNodeTransform(t.TabNode,e=>{0!==e.getFormat()&&x(e.getParent())&&e.setFormat(0)}))}),J=/* @__PURE__ */t.defineExtension({dependencies:[j],name:"@lexical/code/Import"});function q(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=x(n)?n:n.getParent(),i=e.focus.getNode(),o=x(i)?i:i.getParent();return x(r)&&r.is(o)}function V(e){const n=e.getNodes(),r=[];if(1===n.length&&x(n[0]))return r;let o=[];for(let e=0;e<n.length;e++){const s=n[e];y(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||i(169),t.$isLineBreakNode(s)?o.length>0&&(r.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,i=t.$createPoint(o[0].getKey(),0,"text");n.is(i)||r.push(o)}return r}function G(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!q(r))return!1;const i=V(r),o=i.length;if(0===o&&r.isCollapsed())return e===t.INDENT_CONTENT_COMMAND&&r.insertNodes([t.$createTabNode()]),!0;if(0===o&&e===t.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const e=t.$createTabNode(),n=t.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([e,n]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(n,"next"))),i)),!0}for(let l=0;l<o;l++){const o=i[l];if(o.length>0){let i=o[0];if(0===l&&(i=s(i)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(i.insertBefore(e),0===l){const n=r.isBackward()?"focus":"anchor",o=t.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(e.getKey(),0,"text")}}else t.$isTabNode(i)?i.remove():void 0!==n&&y(i)&&g(i,n,r)}}return!0}function Q(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,a=i.offset,c=o.offset,u=i.getNode(),g=o.getNode(),d=e===t.KEY_ARROW_UP_COMMAND;if(!q(r)||!y(u)&&!t.$isTabNode(u)||!y(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=u.getParentOrThrow();if(d&&0===a&&null===u.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!1}else if(!d&&a===u.getTextContentSize()&&null===u.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!1}}return!1}let f,h;if(u.isBefore(g)?(f=s(u),h=l(g)):(f=s(g),h=l(u)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const n=p[e];if(!y(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!t.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=y(m)||t.$isTabNode(m)||t.$isLineBreakNode(m)?d?s(m):l(m):null;let T=null!=_?_:m;return N.remove(),p.forEach(e=>e.remove()),e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>T.insertBefore(e)),T.insertBefore(N)):(T.insertAfter(N),T=N,p.forEach(e=>{T.insertAfter(e),T=e})),r.setTextNodeRange(u,a,g,c),!0}function X(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),l=o.getNode(),g=e===t.MOVE_TO_START;if(!q(r)||!y(s)&&!t.$isTabNode(s)||!y(l)&&!t.$isTabNode(l))return!1;const d=l,f="rtl"===a(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const e=c(d,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else d.getParentOrThrow().selectStart()}else{u(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function Z(e,n,o){return t.mergeRegister(...o?[e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_RIGHT_COMMAND,e=>r.$onEscapeDown(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_LEFT_COMMAND,e=>r.$onEscapeUp(x,e),t.COMMAND_PRIORITY_LOW)]:[],e.registerCommand(t.KEY_TAB_COMMAND,n=>{const r=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!q(n))return null;const r=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return o;const u=V(n);if(1!==u.length)return r;const g=u[0];let d,f;0===g.length&&i(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=s(g[0]),p=l(g[0]),N=t.$createPoint(h.getKey(),0,"text"),m=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?r:N.isBefore(d)||f.isBefore(m)?o:r}(n.shiftKey);return null!==r&&(n.preventDefault(),e.dispatchCommand(r),!0)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INSERT_TAB_COMMAND,()=>!!q(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INDENT_CONTENT_COMMAND,()=>G(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.OUTDENT_CONTENT_COMMAND,()=>G(t.OUTDENT_CONTENT_COMMAND,n),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();if(!q(n))return!1;const o=i.getParent();return n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&x(o)&&null===o.getPreviousSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_UP_COMMAND,e)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!q(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&x(i.getParentOrThrow())&&null===i.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_START,e=>X(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_END,e=>X(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW))}const ee=/* @__PURE__ */t.defineExtension({build:(e,t)=>n.namedSignals(t),config:/* @__PURE__ */t.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[j],name:"@lexical/code-indent",register:(e,t,r)=>{const i=r.getOutput();return n.effect(()=>{if(!i.disabled.value)return Z(e,i.tabSize.value,i.escapeWithArrows.value)})}});exports.$createCodeHighlightNode=A,exports.$createCodeNode=T,exports.$getCodeLineDirection=a,exports.$getEndOfCodeInLine=u,exports.$getFirstCodeNodeOfLine=s,exports.$getLastCodeNodeOfLine=l,exports.$getStartOfCodeInLine=c,exports.$isCodeHighlightNode=y,exports.$isCodeNode=x,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(e){const n=[];return t.tokenizeRawText(e,{linebreak:()=>n.push(t.$createLineBreakNode()),tab:()=>n.push(t.$createTabNode()),text:e=>n.push(A(e))}),n},exports.CodeExtension=j,exports.CodeHighlightNode=R,exports.CodeImportExtension=J,exports.CodeImportRules=z,exports.CodeIndentExtension=ee,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=Z;
|
|
9
|
+
"use strict";var e=require("@lexical/html"),t=require("lexical"),n=require("@lexical/extension"),r=require("@lexical/utils");function i(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function o(e,n){let r=e;for(let i=t.$getSiblingCaret(e,n);i&&(y(i.origin)||t.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function s(e){return o(e,"previous")}function l(e){return o(e,"next")}function a(e){const n=s(e),r=l(e);let i=n;for(;null!==i;){if(y(i)){const e=t.getTextDirection(i.getTextContent());if(null!==e)return e}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(t.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function c(e,n){let r=null,o=null,s=e,l=n,a=e.getTextContent();for(;;){if(0===l){const e=s.getPreviousSibling();if(null===e){s=null;break}if(y(e)||t.$isTabNode(e)||t.$isLineBreakNode(e)||i(167),s=e,t.$isLineBreakNode(s)){r={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const e=a[l];y(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<e.getTextContentSize())y(e)&&(c=e.getTextContent()[n]);else{const t=e.getNextSibling();y(t)&&(c=t.getTextContent()[0])}if(null!==c&&" "!==c)return r;{const i=function(e,n){let r=e,i=n,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!y(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;y(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(y(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,n);return null!==i?i:r}}function u(e){const n=l(e);return t.$isLineBreakNode(n)&&i(168),n}function g(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,a=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==a&&n.focus.set(s,Math.max(0,a-o),"text"),!0}const d="javascript";function f(e,n){for(const r of e.childNodes){if(t.isHTMLElement(r)&&r.tagName===n)return!0;if(f(r,n))return!0}return!1}const h="data-language",p="data-highlight-language",N="data-theme",m=()=>{};class _ extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:t.ElementNode,importDOM:{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||f(e,"BR"))?{conversion:C,priority:1}:null,div:()=>({conversion:O,priority:1}),pre:()=>({conversion:C,priority:0}),table:e=>b(e)?{conversion:S,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:$,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:$,priority:3}:null}}})}constructor(e=void 0,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const n=t.$getDocument().createElement("code");t.addClassNamesToElement(n,e.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),n}updateDOM(e,n,r){const i=this.__language,o=e.__language;i?i!==o&&n.setAttribute(h,i):o&&n.removeAttribute(h);const s=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(p,i):n.removeAttribute(p):s&&i&&n.setAttribute(p,i);const l=this.__theme,a=e.__theme;l?l!==a&&n.setAttribute(N,l):a&&n.removeAttribute(N);const c=this.__style,u=e.__style;return c!==u&&t.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(e){const n=t.$getDocument().createElement("pre");t.addClassNamesToElement(n,e._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),{element:n}}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,r=!0){if(!n.getPeerDependencyFromEditor(t.$getEditor(),"@lexical/code")){m();const t=A(e);if(t)return t}const{anchor:i,focus:o}=e,l=(i.isBefore(o)?i:o).getNode();if(t.$isTextNode(l)){let e=s(l);const n=[];for(;;)if(t.$isTabNode(e))n.push(t.$createTabNode()),e=e.getNextSibling();else{if(!y(e))break;{let t=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;t<i&&" "===r[t];)t++;if(0!==t&&n.push(D(" ".repeat(t))),t!==i)break;e=e.getNextSibling()}}const r=l.splitText(i.offset)[0],o=0===i.offset?0:1,a=r.getIndexWithinParent()+o,c=l.getParentOrThrow(),u=[t.$createLineBreakNode(),...n];c.splice(a,0,u);const g=n[n.length-1];g?g.select():0===i.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(x(l)){const{offset:n}=e.anchor;l.splice(n,0,[t.$createLineBreakNode()]),l.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function T(e,n){return t.$create(_).setLanguage(e).setTheme(n)}function x(e){return e instanceof _}function C(e){return{node:T(e.getAttribute(h),e.getAttribute(N))}}function O(e){const t=e,n=M(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(M(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function $(){return{node:null}}function M(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function A(e){const{anchor:n}=e;if(e.isCollapsed()&&"element"===n.type){const e=n.getNode();if(x(e)){const r=e.getChildrenSize();if(r>=2&&n.offset===r){const n=e.getLastChild();if(t.$isLineBreakNode(n)&&t.$isLineBreakNode(n.getPreviousSibling())){const n=t.$createParagraphNode();return e.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class E extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}$config(){return this.config("code-highlight",{extends:t.TextNode})}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const n=super.createDOM(e),r=R(e.theme,this.__highlightType);return t.addClassNamesToElement(n,r),n}updateDOM(e,n,r){const i=super.updateDOM(e,n,r),o=R(r.theme,e.__highlightType),s=R(r.theme,this.__highlightType);return o!==s&&(o&&t.removeClassNamesFromElement(n,o),s&&t.addClassNamesToElement(n,s)),i}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return T()}}function R(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function D(e="",n){return t.$applyNodeReplacement(new E(e,n))}function y(e){return e instanceof E}const v="data-language",I="data-theme";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=/* @__PURE__ */e.defineOverlayRules([/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),W=/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T(t.getAttribute(v),t.getAttribute(I)).splice(0,0,e.$importChildren(t))],match:e.sel.tag("pre"),name:"@lexical/code/pre"}),k=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(v),t.getAttribute(I)).splice(0,0,e.$importChildren(t))]:n()},match:e.sel.tag("code"),name:"@lexical/code/code-multiline"});function H(e){if(!t.isHTMLElement(e))return!1;const n=e.style.fontFamily,r=e.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function w(e){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(e.childNodes))if(t.isHTMLElement(l))"DIV"===l.tagName?(s(),r.push(l.textContent||""),n=!0):"BR"===l.tagName?(s(),r.push(""),n=!0):(i+=l.textContent||"",o=!0);else if(t.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function F(e){for(const n of Array.from(e.children)){if(t.isHTMLElement(n)&&H(n)){if(null!==w(n))return!0;const e=n.nextElementSibling;if(e&&H(e))return!0;continue}if(F(n))return!0}return!1}const Y=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!H(n)||P(n))return r();const i=w(n);return null===i||0===i.length?r():[T().splice(0,0,t.$generateNodesFromRawText(i.join("\n")))]},match:e.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),K=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!H(n)||P(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():[T().splice(0,0,t.$generateNodesFromRawText(o.join("\n")))]},match:e.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),U=/* @__PURE__ */e.defineOverlayRules([Y,K]),z=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>L(t)?[T().splice(0,0,e.$importChildren(t))]:P(t)?e.$importChildren(t):n(),match:e.sel.tag("div"),name:"@lexical/code/div"}),j=[/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T().splice(0,0,e.$importChildren(t,{rules:B}))],match:e.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),k,W,z],J=/* @__PURE__ */t.defineExtension({dependencies:[e.CoreImportExtension,/* @__PURE__ */t.configExtension(e.DOMImportExtension,{preprocess:[(n,r,i)=>{F(t.isDOMDocumentNode(n)?n.body:n)&&r.session.update(e.ImportOverlays,e=>[...e,U]),i()}],rules:j})],name:"@lexical/code",nodes:()=>[_,E],register:e=>t.mergeRegister(e.registerCommand(t.KEY_ENTER_COMMAND,e=>{const n=t.$getSelection();return!(!t.$isRangeSelection(n)||!A(n))&&(null!==e&&e.preventDefault(),!0)},t.COMMAND_PRIORITY_LOW),e.registerNodeTransform(t.TabNode,e=>{0!==e.getFormat()&&x(e.getParent())&&e.setFormat(0)}))}),q=/* @__PURE__ */t.defineExtension({dependencies:[J],name:"@lexical/code/Import"});function V(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=x(n)?n:n.getParent(),i=e.focus.getNode(),o=x(i)?i:i.getParent();return x(r)&&r.is(o)}function G(e){const n=e.getNodes(),r=[];if(1===n.length&&x(n[0]))return r;let o=[];for(let e=0;e<n.length;e++){const s=n[e];y(s)||t.$isTabNode(s)||t.$isLineBreakNode(s)||i(169),t.$isLineBreakNode(s)?o.length>0&&(r.push(o),o=[]):o.push(s)}if(o.length>0){const n=e.isBackward()?e.anchor:e.focus,i=t.$createPoint(o[0].getKey(),0,"text");n.is(i)||r.push(o)}return r}function Q(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r)||!V(r))return!1;const i=G(r),o=i.length;if(0===o&&r.isCollapsed())return e===t.INDENT_CONTENT_COMMAND?r.insertNodes([t.$createTabNode()]):function(e,n){const r=e.anchor.getNode();if(!y(r)&&!t.$isTabNode(r))return;const i=s(r);t.$isTabNode(i)?i.remove():void 0!==n&&y(i)&&g(i,n,e)}(r,n),!0;if(0===o&&e===t.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const e=t.$createTabNode(),n=t.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([e,n]),t.$setSelectionFromCaretRange(t.$getCaretRangeInDirection(t.$getCaretRange(t.$getTextPointCaret(e,"next",0),t.$normalizeCaret(t.$getSiblingCaret(n,"next"))),i)),!0}for(let l=0;l<o;l++){const o=i[l];if(o.length>0){let i=o[0];if(0===l&&(i=s(i)),e===t.INDENT_CONTENT_COMMAND){const e=t.$createTabNode();if(i.insertBefore(e),0===l){const n=r.isBackward()?"focus":"anchor",o=t.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(e.getKey(),0,"text")}}else t.$isTabNode(i)?i.remove():void 0!==n&&y(i)&&g(i,n,r)}}return!0}function X(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,a=i.offset,c=o.offset,u=i.getNode(),g=o.getNode(),d=e===t.KEY_ARROW_UP_COMMAND;if(!V(r)||!y(u)&&!t.$isTabNode(u)||!y(g)&&!t.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=u.getParentOrThrow();if(d&&0===a&&null===u.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!1}else if(!d&&a===u.getTextContentSize()&&null===u.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!1}}return!1}let f,h;if(u.isBefore(g)?(f=s(u),h=l(g)):(f=s(g),h=l(u)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const n=p[e];if(!y(n)&&!t.$isTabNode(n)&&!t.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!t.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=t.$isLineBreakNode(m),T=_||!y(m)&&!t.$isTabNode(m)?null:d?s(m):l(m);let x=null!=T?T:m;return N.remove(),p.forEach(e=>e.remove()),_?(p.forEach(e=>{x.insertAfter(e),x=e}),x.insertAfter(N)):e===t.KEY_ARROW_UP_COMMAND?(p.forEach(e=>x.insertBefore(e)),x.insertBefore(N)):(x.insertAfter(N),x=N,p.forEach(e=>{x.insertAfter(e),x=e})),r.setTextNodeRange(u,a,g,c),!0}function Z(e,n){const r=t.$getSelection();if(!t.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),l=o.getNode(),g=e===t.MOVE_TO_START;if(!V(r)||!y(s)&&!t.$isTabNode(s)||!y(l)&&!t.$isTabNode(l))return!1;const d=l,f="rtl"===a(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const e=c(d,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else d.getParentOrThrow().selectStart()}else{u(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function ee(e,n,o){return t.mergeRegister(...o?[e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_RIGHT_COMMAND,e=>r.$onEscapeDown(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(x,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_LEFT_COMMAND,e=>r.$onEscapeUp(x,e),t.COMMAND_PRIORITY_LOW)]:[],e.registerCommand(t.KEY_TAB_COMMAND,n=>{const r=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!V(n))return null;const r=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return o;const u=G(n);if(1!==u.length)return r;const g=u[0];let d,f;0===g.length&&i(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=s(g[0]),p=l(g[0]),N=t.$createPoint(h.getKey(),0,"text"),m=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?r:N.isBefore(d)||f.isBefore(m)?o:r}(n.shiftKey);return null!==r&&(n.preventDefault(),e.dispatchCommand(r),!0)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INSERT_TAB_COMMAND,()=>!!V(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INDENT_CONTENT_COMMAND,()=>Q(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.OUTDENT_CONTENT_COMMAND,()=>Q(t.OUTDENT_CONTENT_COMMAND,n),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();if(!V(n))return!1;const o=i.getParent();return n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&x(o)&&null===o.getPreviousSibling()?(e.preventDefault(),!0):X(t.KEY_ARROW_UP_COMMAND,e)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!V(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&x(i.getParentOrThrow())&&null===i.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):X(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_START,e=>Z(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_END,e=>Z(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW))}const te=/* @__PURE__ */t.defineExtension({build:(e,t)=>n.namedSignals(t),config:/* @__PURE__ */t.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[J],name:"@lexical/code-indent",register:(e,t,r)=>{const i=r.getOutput();return n.effect(()=>{if(!i.disabled.value)return ee(e,i.tabSize.value,i.escapeWithArrows.value)})}});exports.$createCodeHighlightNode=D,exports.$createCodeNode=T,exports.$getCodeLineDirection=a,exports.$getEndOfCodeInLine=u,exports.$getFirstCodeNodeOfLine=s,exports.$getLastCodeNodeOfLine=l,exports.$getStartOfCodeInLine=c,exports.$isCodeHighlightNode=y,exports.$isCodeNode=x,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(e){const n=[];return t.tokenizeRawText(e,{linebreak:()=>n.push(t.$createLineBreakNode()),tab:()=>n.push(t.$createTabNode()),text:e=>n.push(D(e))}),n},exports.CodeExtension=J,exports.CodeHighlightNode=E,exports.CodeImportExtension=q,exports.CodeImportRules=j,exports.CodeIndentExtension=te,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=ee;
|
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{defineImportRule as e,sel as t,ImportOverlays as n,defineOverlayRules as r,CoreImportExtension as i,DOMImportExtension as o}from"@lexical/html";import{getTextDirection as s,$isElementNode as l,$isTabNode as u,$isLineBreakNode as c,tokenizeRawText as a,$createTabNode as g,$createLineBreakNode as f,$getSiblingCaret as h,$create as p,ElementNode as d,$getDocument as m,addClassNamesToElement as x,setDOMStyleFromCSS as S,$getEditor as
|
|
10
|
-
/*@__INLINE__*/function se(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function le(e,t){let n=e;for(let r=h(e,t);r&&(ke(r.origin)||u(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function ue(e){return le(e,"previous")}function ce(e){return le(e,"next")}function ae(e){const t=ue(e),n=ce(e);let r=t;for(;null!==r;){if(ke(r)){const e=s(r.getTextContent());if(null!==e)return e}if(r===n)break;r=r.getNextSibling()}const i=t.getParent();if(l(i)){const e=i.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function ge(e,t){let n=null,r=null,i=e,o=t,s=e.getTextContent();for(;;){if(0===o){const e=i.getPreviousSibling();if(null===e){i=null;break}if(ke(e)||u(e)||c(e)||se(167),i=e,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const e=s[o];ke(i)&&" "!==e&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(t<e.getTextContentSize())ke(e)&&(l=e.getTextContent()[t]);else{const t=e.getNextSibling();ke(t)&&(l=t.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(e,t){let n=e,r=t,i=e.getTextContent(),o=e.getTextContentSize();for(;;){if(!ke(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;ke(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(ke(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(e,t);return null!==r?r:n}}function fe(e){const t=ce(e);return c(t)&&se(168),t}function he(e){const t=[];return a(e,{linebreak:()=>t.push(f()),tab:()=>t.push(g()),text:e=>t.push(Le(e))}),t}function pe(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,u=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==u&&n.focus.set(s,Math.max(0,u-o),"text"),!0}const de="javascript",me=()=>de;function xe(e,t){for(const n of e.childNodes){if(C(n)&&n.tagName===t)return!0;if(xe(n,t))return!0}return!1}const Se="data-language",ye="data-highlight-language",be="data-theme",_e=()=>{};class Ce extends d{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:d,importDOM:{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||xe(e,"BR"))?{conversion:Ne,priority:1}:null,div:()=>({conversion:Ae,priority:1}),pre:()=>({conversion:Ne,priority:0}),table:e=>He(e)?{conversion:Pe,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&He(n)?{conversion:Oe,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&He(t)?{conversion:Oe,priority:3}:null}}})}constructor(e=void 0,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const t=m().createElement("code");x(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(Se,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(ye,n));const r=this.getTheme();r&&t.setAttribute(be,r);const i=this.getStyle();return i&&S(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(Se,r):i&&t.removeAttribute(Se);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(ye,r):t.removeAttribute(ye):o&&r&&t.setAttribute(ye,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(be,s):l&&t.removeAttribute(be);const u=this.__style,c=e.__style;return u!==c&&S(t.style,u,c),!1}exportDOM(e){const t=m().createElement("pre");x(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(Se,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(ye,n));const r=this.getTheme();r&&t.setAttribute(be,r);const i=this.getStyle();return i&&S(t.style,i),{element:t}}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,t=!0){if(!te(y(),"@lexical/code")){_e();const t=$e(e);if(t)return t}const{anchor:n,focus:r}=e,i=(n.isBefore(r)?n:r).getNode();if(b(i)){let e=ue(i);const t=[];for(;;)if(u(e))t.push(g()),e=e.getNextSibling();else{if(!ke(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(Le(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,l=i.getParentOrThrow(),c=[f(),...t];l.splice(s,0,c);const a=t[t.length-1];a?a.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(Te(i)){const{offset:t}=e.anchor;i.splice(t,0,[f()]),i.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=_();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function ve(e,t){return p(Ce).setLanguage(e).setTheme(t)}function Te(e){return e instanceof Ce}function Ne(e){return{node:ve(e.getAttribute(Se))}}function Ae(e){const t=e,n=we(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(we(t))return!0;t=t.parentElement}return!1}(t)?{node:n?ve():null}:{node:null}}function Pe(){return{node:ve()}}function Oe(){return{node:null}}function we(e){return null!==e.style.fontFamily.match("monospace")}function He(e){return e.classList.contains("js-file-line-container")}function $e(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(Te(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(c(t)&&c(t.getPreviousSibling())){const t=_();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class De extends T{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}$config(){return this.config("code-highlight",{extends:T})}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),n=Be(e.theme,this.__highlightType);return x(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=Be(n.theme,e.__highlightType),o=Be(n.theme,this.__highlightType);return i!==o&&(i&&N(t,i),o&&x(t,o)),r}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return ve()}}function Be(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function Le(e="",t){return v(new De(e,t))}function ke(e){return e instanceof De}const Ee="data-language";function Fe(e){return null!==e.style.fontFamily.match("monospace")}function Me(e){let t=e.parentElement;for(;null!==t;){if(Fe(t))return!0;t=t.parentElement}return!1}const ze=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),Ke=/* @__PURE__ */e({$import:(e,t)=>[ve(t.getAttribute(Ee)).splice(0,0,e.$importChildren(t))],match:t.tag("pre"),name:"@lexical/code/pre"}),Ie=/* @__PURE__ */e({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[ve(t.getAttribute(Ee)).splice(0,0,e.$importChildren(t))]:n()},match:t.tag("code"),name:"@lexical/code/code-multiline"});function je(e){if(!C(e))return!1;const t=e.style.fontFamily,n=e.style.whiteSpace;return"string"==typeof t&&/monospace/i.test(t)&&"string"==typeof n&&n.startsWith("pre")}function Je(e){let t=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(e.childNodes))if(C(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),t=!0):"BR"===s.tagName?(o(),n.push(""),t=!0):(r+=s.textContent||"",i=!0);else if(P(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function Re(e){for(const t of Array.from(e.children)){if(C(t)&&je(t)){if(null!==Je(t))return!0;const e=t.nextElementSibling;if(e&&je(e))return!0;continue}if(Re(t))return!0}return!1}const We=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t,n)=>{if(!je(t)||Me(t))return n();const r=Je(t);return null===r||0===r.length?n():[ve().splice(0,0,O(r.join("\n")))]},match:t.tag("div"),name:"@lexical/code/vscode-wrapper"}),/* @__PURE__ */e({$import:(e,t,n)=>{if(!je(t)||Me(t))return n();const r=t.previousElementSibling;if(r&&je(r))return[];const i=[];let o=t;for(;o&&je(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[ve().splice(0,0,O(i.join("\n")))]},match:t.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),qe=/* @__PURE__ */e({$import:(e,t,n)=>Fe(t)?[ve().splice(0,0,e.$importChildren(t))]:Me(t)?e.$importChildren(t):n(),match:t.tag("div"),name:"@lexical/code/div"}),Ue=[/* @__PURE__ */e({$import:(e,t)=>[ve().splice(0,0,e.$importChildren(t,{rules:ze}))],match:t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),Ie,Ke,qe],Ve=/* @__PURE__ */w({dependencies:[i,/* @__PURE__ */E(o,{preprocess:[(e,t,r)=>{Re(A(e)?e.body:e)&&t.session.update(n,e=>[...e,We]),r()}],rules:Ue})],name:"@lexical/code",nodes:()=>[Ce,De],register:e=>H(e.registerCommand($,e=>{const t=D();return!(!B(t)||!$e(t))&&(null!==e&&e.preventDefault(),!0)},L),e.registerNodeTransform(k,e=>{0!==e.getFormat()&&Te(e.getParent())&&e.setFormat(0)}))}),Ge=/* @__PURE__ */w({dependencies:[Ve],name:"@lexical/code/Import"});function Qe(e){if(!B(e))return!1;const t=e.anchor.getNode(),n=Te(t)?t:t.getParent(),r=e.focus.getNode(),i=Te(r)?r:r.getParent();return Te(n)&&n.is(i)}function Xe(e){const t=e.getNodes(),n=[];if(1===t.length&&Te(t[0]))return n;let r=[];for(let e=0;e<t.length;e++){const i=t[e];ke(i)||u(i)||c(i)||se(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const t=e.isBackward()?e.anchor:e.focus,i=G(r[0].getKey(),0,"text");t.is(i)||n.push(r)}return n}function Ye(e,t){const n=D();if(!B(n)||!Qe(n))return!1;const r=Xe(n),i=r.length;if(0===i&&n.isCollapsed())return e===W&&n.insertNodes([g()]),!0;if(0===i&&e===W&&"\n"===n.getTextContent()){const e=g(),t=f(),r=n.isBackward()?"previous":"next";return n.insertNodes([e,t]),Q(X(Y(Z(e,"next",0),ee(h(t,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=ue(r)),e===W){const e=g();if(r.insertBefore(e),0===o){const t=n.isBackward()?"focus":"anchor",i=G(r.getKey(),0,"text");n[t].is(i)&&n[t].set(e.getKey(),0,"text")}}else u(r)?r.remove():void 0!==t&&ke(r)&&pe(r,t,n)}}return!0}function Ze(e,t){const n=D();if(!B(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),a=i.getNode(),g=e===K;if(!Qe(n)||!ke(l)&&!u(l)||!ke(a)&&!u(a))return!1;if(!t.altKey){if(n.isCollapsed()){const e=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let f,h;if(l.isBefore(a)?(f=ue(l),h=ce(a)):(f=ue(a),h=ce(l)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const t=p[e];if(!ke(t)&&!u(t)&&!c(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?f.getPreviousSibling():h.getNextSibling();if(!c(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=ke(m)||u(m)||c(m)?g?ue(m):ce(m):null;let S=null!=x?x:m;return d.remove(),p.forEach(e=>e.remove()),e===K?(p.forEach(e=>S.insertBefore(e)),S.insertBefore(d)):(S.insertAfter(d),S=d,p.forEach(e=>{S.insertAfter(e),S=e})),n.setTextNodeRange(l,o,a,s),!0}function et(e,t){const n=D();if(!B(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=e===U;if(!Qe(n)||!ke(o)&&!u(o)||!ke(s)&&!u(s))return!1;const a=s,g="rtl"===ae(a)?!l:l,f=r.key,h=r.offset,p=r.type;if(g){const e=ge(a,i.offset);if(null!==e){const{node:t,offset:r}=e;c(t)?t.selectNext(0,0):n.setTextNodeRange(t,r,t,r)}else a.getParentOrThrow().selectStart()}else{fe(a).select()}return t.shiftKey&&n.anchor.set(f,h,p),t.preventDefault(),t.stopPropagation(),!0}function tt(e,t,n){return H(...n?[e.registerCommand(M,e=>!e.altKey&&ie(Te,e),L),e.registerCommand(z,e=>ie(Te,e),L),e.registerCommand(K,e=>!e.altKey&&oe(Te,e),L),e.registerCommand(I,e=>oe(Te,e),L)]:[],e.registerCommand(j,t=>{const n=function(e){const t=D();if(!B(t)||!Qe(t))return null;const n=e?q:W,r=e?q:J,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Xe(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&se(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=ue(l[0]),g=ce(l[0]),f=G(a.getKey(),0,"text"),h=G(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(f)||h.isBefore(c)?n:f.isBefore(u)||c.isBefore(h)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n),!0)},L),e.registerCommand(J,()=>!!Qe(D())&&(R([g()]),!0),L),e.registerCommand(W,()=>Ye(W),L),e.registerCommand(q,()=>Ye(q,t),L),e.registerCommand(K,e=>{const t=D();if(!B(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Qe(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&Te(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):Ze(K,e)},L),e.registerCommand(M,e=>{const t=D();if(!B(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Qe(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&Te(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Ze(M,e))},L),e.registerCommand(U,e=>et(U,e),L),e.registerCommand(V,e=>et(V,e),L))}const nt=/* @__PURE__ */w({build:(e,t)=>re(t),config:/* @__PURE__ */F({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[Ve],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return ne(()=>{if(!r.disabled.value)return tt(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{Le as $createCodeHighlightNode,ve as $createCodeNode,ae as $getCodeLineDirection,fe as $getEndOfCodeInLine,ue as $getFirstCodeNodeOfLine,ce as $getLastCodeNodeOfLine,ge as $getStartOfCodeInLine,ke as $isCodeHighlightNode,Te as $isCodeNode,pe as $outdentLeadingSpaces,he as $plainifyCodeContent,Ve as CodeExtension,De as CodeHighlightNode,Ge as CodeImportExtension,Ue as CodeImportRules,nt as CodeIndentExtension,Ce as CodeNode,de as DEFAULT_CODE_LANGUAGE,me as getDefaultCodeLanguage,tt as registerCodeIndentation};
|
|
9
|
+
import{defineImportRule as e,sel as t,ImportOverlays as n,defineOverlayRules as r,CoreImportExtension as i,DOMImportExtension as o}from"@lexical/html";import{getTextDirection as s,$isElementNode as l,$isTabNode as u,$isLineBreakNode as c,tokenizeRawText as a,$createTabNode as g,$createLineBreakNode as f,$getSiblingCaret as h,$create as p,ElementNode as d,$getDocument as m,addClassNamesToElement as x,setDOMStyleFromCSS as S,$getEditor as b,$isTextNode as y,$createParagraphNode as _,isHTMLElement as v,$applyNodeReplacement as C,TextNode as N,removeClassNamesFromElement as T,isDOMDocumentNode as A,isDOMTextNode as P,$generateNodesFromRawText as O,defineExtension as w,mergeRegister as H,KEY_ENTER_COMMAND as $,$getSelection as D,$isRangeSelection as B,COMMAND_PRIORITY_LOW as L,TabNode as E,configExtension as k,safeCast as F,KEY_ARROW_DOWN_COMMAND as M,KEY_ARROW_RIGHT_COMMAND as z,KEY_ARROW_UP_COMMAND as K,KEY_ARROW_LEFT_COMMAND as I,KEY_TAB_COMMAND as j,INSERT_TAB_COMMAND as J,$insertNodes as R,INDENT_CONTENT_COMMAND as W,OUTDENT_CONTENT_COMMAND as q,MOVE_TO_START as U,MOVE_TO_END as V,$createPoint as G,$setSelectionFromCaretRange as Q,$getCaretRangeInDirection as X,$getCaretRange as Y,$getTextPointCaret as Z,$normalizeCaret as ee}from"lexical";import{getPeerDependencyFromEditor as te,effect as ne,namedSignals as re}from"@lexical/extension";import{$onEscapeDown as ie,$onEscapeUp as oe}from"@lexical/utils";
|
|
10
|
+
/*@__INLINE__*/function se(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function le(e,t){let n=e;for(let r=h(e,t);r&&(Ee(r.origin)||u(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function ue(e){return le(e,"previous")}function ce(e){return le(e,"next")}function ae(e){const t=ue(e),n=ce(e);let r=t;for(;null!==r;){if(Ee(r)){const e=s(r.getTextContent());if(null!==e)return e}if(r===n)break;r=r.getNextSibling()}const i=t.getParent();if(l(i)){const e=i.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function ge(e,t){let n=null,r=null,i=e,o=t,s=e.getTextContent();for(;;){if(0===o){const e=i.getPreviousSibling();if(null===e){i=null;break}if(Ee(e)||u(e)||c(e)||se(167),i=e,c(i)){n={node:i,offset:1};break}o=Math.max(0,i.getTextContentSize()-1),s=i.getTextContent()}else o--;const e=s[o];Ee(i)&&" "!==e&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(t<e.getTextContentSize())Ee(e)&&(l=e.getTextContent()[t]);else{const t=e.getNextSibling();Ee(t)&&(l=t.getTextContent()[0])}if(null!==l&&" "!==l)return n;{const r=function(e,t){let n=e,r=t,i=e.getTextContent(),o=e.getTextContentSize();for(;;){if(!Ee(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Ee(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Ee(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(e,t);return null!==r?r:n}}function fe(e){const t=ce(e);return c(t)&&se(168),t}function he(e){const t=[];return a(e,{linebreak:()=>t.push(f()),tab:()=>t.push(g()),text:e=>t.push(Le(e))}),t}function pe(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,u=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==u&&n.focus.set(s,Math.max(0,u-o),"text"),!0}const de="javascript",me=()=>de;function xe(e,t){for(const n of e.childNodes){if(v(n)&&n.tagName===t)return!0;if(xe(n,t))return!0}return!1}const Se="data-language",be="data-highlight-language",ye="data-theme",_e=()=>{};class ve extends d{__language;__theme;__isSyntaxHighlightSupported;$config(){return this.config("code",{extends:d,importDOM:{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||xe(e,"BR"))?{conversion:Te,priority:1}:null,div:()=>({conversion:Ae,priority:1}),pre:()=>({conversion:Te,priority:0}),table:e=>He(e)?{conversion:Pe,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&He(n)?{conversion:Oe,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&He(t)?{conversion:Oe,priority:3}:null}}})}constructor(e=void 0,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const t=m().createElement("code");x(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(Se,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(be,n));const r=this.getTheme();r&&t.setAttribute(ye,r);const i=this.getStyle();return i&&S(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(Se,r):i&&t.removeAttribute(Se);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(be,r):t.removeAttribute(be):o&&r&&t.setAttribute(be,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(ye,s):l&&t.removeAttribute(ye);const u=this.__style,c=e.__style;return u!==c&&S(t.style,u,c),!1}exportDOM(e){const t=m().createElement("pre");x(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(Se,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(be,n));const r=this.getTheme();r&&t.setAttribute(ye,r);const i=this.getStyle();return i&&S(t.style,i),{element:t}}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,t=!0){if(!te(b(),"@lexical/code")){_e();const t=$e(e);if(t)return t}const{anchor:n,focus:r}=e,i=(n.isBefore(r)?n:r).getNode();if(y(i)){let e=ue(i);const t=[];for(;;)if(u(e))t.push(g()),e=e.getNextSibling();else{if(!Ee(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(Le(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,l=i.getParentOrThrow(),c=[f(),...t];l.splice(s,0,c);const a=t[t.length-1];a?a.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(Ne(i)){const{offset:t}=e.anchor;i.splice(t,0,[f()]),i.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=_();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function Ce(e,t){return p(ve).setLanguage(e).setTheme(t)}function Ne(e){return e instanceof ve}function Te(e){return{node:Ce(e.getAttribute(Se),e.getAttribute(ye))}}function Ae(e){const t=e,n=we(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(we(t))return!0;t=t.parentElement}return!1}(t)?{node:n?Ce():null}:{node:null}}function Pe(){return{node:Ce()}}function Oe(){return{node:null}}function we(e){return null!==e.style.fontFamily.match("monospace")}function He(e){return e.classList.contains("js-file-line-container")}function $e(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(Ne(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(c(t)&&c(t.getPreviousSibling())){const t=_();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class De extends N{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}$config(){return this.config("code-highlight",{extends:N})}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),n=Be(e.theme,this.__highlightType);return x(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=Be(n.theme,e.__highlightType),o=Be(n.theme,this.__highlightType);return i!==o&&(i&&T(t,i),o&&x(t,o)),r}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return Ce()}}function Be(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function Le(e="",t){return C(new De(e,t))}function Ee(e){return e instanceof De}const ke="data-language",Fe="data-theme";function Me(e){return null!==e.style.fontFamily.match("monospace")}function ze(e){let t=e.parentElement;for(;null!==t;){if(Me(t))return!0;t=t.parentElement}return!1}const Ke=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),Ie=/* @__PURE__ */e({$import:(e,t)=>[Ce(t.getAttribute(ke),t.getAttribute(Fe)).splice(0,0,e.$importChildren(t))],match:t.tag("pre"),name:"@lexical/code/pre"}),je=/* @__PURE__ */e({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[Ce(t.getAttribute(ke),t.getAttribute(Fe)).splice(0,0,e.$importChildren(t))]:n()},match:t.tag("code"),name:"@lexical/code/code-multiline"});function Je(e){if(!v(e))return!1;const t=e.style.fontFamily,n=e.style.whiteSpace;return"string"==typeof t&&/monospace/i.test(t)&&"string"==typeof n&&n.startsWith("pre")}function Re(e){let t=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(e.childNodes))if(v(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),t=!0):"BR"===s.tagName?(o(),n.push(""),t=!0):(r+=s.textContent||"",i=!0);else if(P(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function We(e){for(const t of Array.from(e.children)){if(v(t)&&Je(t)){if(null!==Re(t))return!0;const e=t.nextElementSibling;if(e&&Je(e))return!0;continue}if(We(t))return!0}return!1}const qe=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t,n)=>{if(!Je(t)||ze(t))return n();const r=Re(t);return null===r||0===r.length?n():[Ce().splice(0,0,O(r.join("\n")))]},match:t.tag("div"),name:"@lexical/code/vscode-wrapper"}),/* @__PURE__ */e({$import:(e,t,n)=>{if(!Je(t)||ze(t))return n();const r=t.previousElementSibling;if(r&&Je(r))return[];const i=[];let o=t;for(;o&&Je(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[Ce().splice(0,0,O(i.join("\n")))]},match:t.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),Ue=/* @__PURE__ */e({$import:(e,t,n)=>Me(t)?[Ce().splice(0,0,e.$importChildren(t))]:ze(t)?e.$importChildren(t):n(),match:t.tag("div"),name:"@lexical/code/div"}),Ve=[/* @__PURE__ */e({$import:(e,t)=>[Ce().splice(0,0,e.$importChildren(t,{rules:Ke}))],match:t.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),je,Ie,Ue],Ge=/* @__PURE__ */w({dependencies:[i,/* @__PURE__ */k(o,{preprocess:[(e,t,r)=>{We(A(e)?e.body:e)&&t.session.update(n,e=>[...e,qe]),r()}],rules:Ve})],name:"@lexical/code",nodes:()=>[ve,De],register:e=>H(e.registerCommand($,e=>{const t=D();return!(!B(t)||!$e(t))&&(null!==e&&e.preventDefault(),!0)},L),e.registerNodeTransform(E,e=>{0!==e.getFormat()&&Ne(e.getParent())&&e.setFormat(0)}))}),Qe=/* @__PURE__ */w({dependencies:[Ge],name:"@lexical/code/Import"});function Xe(e){if(!B(e))return!1;const t=e.anchor.getNode(),n=Ne(t)?t:t.getParent(),r=e.focus.getNode(),i=Ne(r)?r:r.getParent();return Ne(n)&&n.is(i)}function Ye(e){const t=e.getNodes(),n=[];if(1===t.length&&Ne(t[0]))return n;let r=[];for(let e=0;e<t.length;e++){const i=t[e];Ee(i)||u(i)||c(i)||se(169),c(i)?r.length>0&&(n.push(r),r=[]):r.push(i)}if(r.length>0){const t=e.isBackward()?e.anchor:e.focus,i=G(r[0].getKey(),0,"text");t.is(i)||n.push(r)}return n}function Ze(e,t){const n=D();if(!B(n)||!Xe(n))return!1;const r=Ye(n),i=r.length;if(0===i&&n.isCollapsed())return e===W?n.insertNodes([g()]):function(e,t){const n=e.anchor.getNode();if(!Ee(n)&&!u(n))return;const r=ue(n);u(r)?r.remove():void 0!==t&&Ee(r)&&pe(r,t,e)}(n,t),!0;if(0===i&&e===W&&"\n"===n.getTextContent()){const e=g(),t=f(),r=n.isBackward()?"previous":"next";return n.insertNodes([e,t]),Q(X(Y(Z(e,"next",0),ee(h(t,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=ue(r)),e===W){const e=g();if(r.insertBefore(e),0===o){const t=n.isBackward()?"focus":"anchor",i=G(r.getKey(),0,"text");n[t].is(i)&&n[t].set(e.getKey(),0,"text")}}else u(r)?r.remove():void 0!==t&&Ee(r)&&pe(r,t,n)}}return!0}function et(e,t){const n=D();if(!B(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),a=i.getNode(),g=e===K;if(!Xe(n)||!Ee(l)&&!u(l)||!Ee(a)&&!u(a))return!1;if(!t.altKey){if(n.isCollapsed()){const e=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let f,h;if(l.isBefore(a)?(f=ue(l),h=ce(a)):(f=ue(a),h=ce(l)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let e=0;e<p.length;e++){const t=p[e];if(!Ee(t)&&!u(t)&&!c(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?f.getPreviousSibling():h.getNextSibling();if(!c(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=c(m),S=x||!Ee(m)&&!u(m)?null:g?ue(m):ce(m);let b=null!=S?S:m;return d.remove(),p.forEach(e=>e.remove()),x?(p.forEach(e=>{b.insertAfter(e),b=e}),b.insertAfter(d)):e===K?(p.forEach(e=>b.insertBefore(e)),b.insertBefore(d)):(b.insertAfter(d),b=d,p.forEach(e=>{b.insertAfter(e),b=e})),n.setTextNodeRange(l,o,a,s),!0}function tt(e,t){const n=D();if(!B(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=e===U;if(!Xe(n)||!Ee(o)&&!u(o)||!Ee(s)&&!u(s))return!1;const a=s,g="rtl"===ae(a)?!l:l,f=r.key,h=r.offset,p=r.type;if(g){const e=ge(a,i.offset);if(null!==e){const{node:t,offset:r}=e;c(t)?t.selectNext(0,0):n.setTextNodeRange(t,r,t,r)}else a.getParentOrThrow().selectStart()}else{fe(a).select()}return t.shiftKey&&n.anchor.set(f,h,p),t.preventDefault(),t.stopPropagation(),!0}function nt(e,t,n){return H(...n?[e.registerCommand(M,e=>!e.altKey&&ie(Ne,e),L),e.registerCommand(z,e=>ie(Ne,e),L),e.registerCommand(K,e=>!e.altKey&&oe(Ne,e),L),e.registerCommand(I,e=>oe(Ne,e),L)]:[],e.registerCommand(j,t=>{const n=function(e){const t=D();if(!B(t)||!Xe(t))return null;const n=e?q:W,r=e?q:J,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Ye(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&se(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=ue(l[0]),g=ce(l[0]),f=G(a.getKey(),0,"text"),h=G(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(f)||h.isBefore(c)?n:f.isBefore(u)||c.isBefore(h)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n),!0)},L),e.registerCommand(J,()=>!!Xe(D())&&(R([g()]),!0),L),e.registerCommand(W,()=>Ze(W),L),e.registerCommand(q,()=>Ze(q,t),L),e.registerCommand(K,e=>{const t=D();if(!B(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Xe(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&Ne(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):et(K,e)},L),e.registerCommand(M,e=>{const t=D();if(!B(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Xe(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&Ne(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):et(M,e))},L),e.registerCommand(U,e=>tt(U,e),L),e.registerCommand(V,e=>tt(V,e),L))}const rt=/* @__PURE__ */w({build:(e,t)=>re(t),config:/* @__PURE__ */F({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[Ge],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return ne(()=>{if(!r.disabled.value)return nt(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{Le as $createCodeHighlightNode,Ce as $createCodeNode,ae as $getCodeLineDirection,fe as $getEndOfCodeInLine,ue as $getFirstCodeNodeOfLine,ce as $getLastCodeNodeOfLine,ge as $getStartOfCodeInLine,Ee as $isCodeHighlightNode,Ne as $isCodeNode,pe as $outdentLeadingSpaces,he as $plainifyCodeContent,Ge as CodeExtension,De as CodeHighlightNode,Qe as CodeImportExtension,Ve as CodeImportRules,rt as CodeIndentExtension,ve as CodeNode,de as DEFAULT_CODE_LANGUAGE,me as getDefaultCodeLanguage,nt as registerCodeIndentation};
|
package/package.json
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.49.1-nightly.
|
|
11
|
+
"version": "0.49.1-nightly.20260824.0",
|
|
12
12
|
"main": "./dist/LexicalCodeCore.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/
|
|
16
|
-
"@lexical/
|
|
17
|
-
"@lexical/internal": "0.49.1-nightly.
|
|
18
|
-
"@lexical/utils": "0.49.1-nightly.
|
|
19
|
-
"lexical": "0.49.1-nightly.
|
|
15
|
+
"@lexical/extension": "0.49.1-nightly.20260824.0",
|
|
16
|
+
"@lexical/html": "0.49.1-nightly.20260824.0",
|
|
17
|
+
"@lexical/internal": "0.49.1-nightly.20260824.0",
|
|
18
|
+
"@lexical/utils": "0.49.1-nightly.20260824.0",
|
|
19
|
+
"lexical": "0.49.1-nightly.20260824.0"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
import {$createCodeNode} from './CodeNode';
|
|
24
24
|
|
|
25
25
|
const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
|
|
26
|
+
const THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* True for elements whose `font-family` mentions `monospace` — the
|
|
@@ -63,11 +64,10 @@ const GitHubCodeTableOverlayRules = /* @__PURE__ */ defineOverlayRules([
|
|
|
63
64
|
|
|
64
65
|
const PreRule = /* @__PURE__ */ defineImportRule({
|
|
65
66
|
$import: (ctx, el) => [
|
|
66
|
-
$createCodeNode(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
),
|
|
67
|
+
$createCodeNode(
|
|
68
|
+
el.getAttribute(LANGUAGE_DATA_ATTRIBUTE),
|
|
69
|
+
el.getAttribute(THEME_DATA_ATTRIBUTE),
|
|
70
|
+
).splice(0, 0, ctx.$importChildren(el)),
|
|
71
71
|
],
|
|
72
72
|
match: sel.tag('pre'),
|
|
73
73
|
name: '@lexical/code/pre',
|
|
@@ -87,11 +87,10 @@ const MultilineCodeRule = /* @__PURE__ */ defineImportRule({
|
|
|
87
87
|
return $next();
|
|
88
88
|
}
|
|
89
89
|
return [
|
|
90
|
-
$createCodeNode(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
),
|
|
90
|
+
$createCodeNode(
|
|
91
|
+
el.getAttribute(LANGUAGE_DATA_ATTRIBUTE),
|
|
92
|
+
el.getAttribute(THEME_DATA_ATTRIBUTE),
|
|
93
|
+
).splice(0, 0, ctx.$importChildren(el)),
|
|
95
94
|
];
|
|
96
95
|
},
|
|
97
96
|
match: sel.tag('code'),
|
package/src/CodeIndentation.ts
CHANGED
|
@@ -206,6 +206,32 @@ function $handleTab(shiftKey: boolean): null | LexicalCommand<void> {
|
|
|
206
206
|
return indentOrOutdent;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Outdent the single line the collapsed caret sits on.
|
|
211
|
+
*
|
|
212
|
+
* `$getCodeLines` drops a trailing line when the selection ends exactly at its
|
|
213
|
+
* start — for a collapsed caret that is always true, so the caret's own line
|
|
214
|
+
* never reaches the outdent loop and the line has to be resolved from the
|
|
215
|
+
* anchor here. Applies the same rule as that loop: strip a leading TabNode, or
|
|
216
|
+
* `tabSize` leading spaces when the extension is configured for them.
|
|
217
|
+
*/
|
|
218
|
+
function $outdentLineAtCaret(
|
|
219
|
+
selection: RangeSelection,
|
|
220
|
+
tabSize: number | undefined,
|
|
221
|
+
): void {
|
|
222
|
+
const anchorNode = selection.anchor.getNode();
|
|
223
|
+
// An element point (e.g. the caret on a blank line) has no line to outdent.
|
|
224
|
+
if (!$isCodeHighlightNode(anchorNode) && !$isTabNode(anchorNode)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const firstOfLine = $getFirstCodeNodeOfLine(anchorNode);
|
|
228
|
+
if ($isTabNode(firstOfLine)) {
|
|
229
|
+
firstOfLine.remove();
|
|
230
|
+
} else if (tabSize !== undefined && $isCodeHighlightNode(firstOfLine)) {
|
|
231
|
+
$outdentLeadingSpaces(firstOfLine, tabSize, selection);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
209
235
|
function $handleMultilineIndent(
|
|
210
236
|
type: LexicalCommand<void>,
|
|
211
237
|
tabSize?: number,
|
|
@@ -223,6 +249,8 @@ function $handleMultilineIndent(
|
|
|
223
249
|
if (codeLinesLength === 0 && selection.isCollapsed()) {
|
|
224
250
|
if (type === INDENT_CONTENT_COMMAND) {
|
|
225
251
|
selection.insertNodes([$createTabNode()]);
|
|
252
|
+
} else {
|
|
253
|
+
$outdentLineAtCaret(selection, tabSize);
|
|
226
254
|
}
|
|
227
255
|
return true;
|
|
228
256
|
}
|
|
@@ -392,10 +420,15 @@ function $handleShiftLines(
|
|
|
392
420
|
return true;
|
|
393
421
|
}
|
|
394
422
|
|
|
423
|
+
// A LineBreakNode sibling means the adjacent line is blank, so it has no
|
|
424
|
+
// node of its own to anchor the move to — $getFirstCodeNodeOfLine /
|
|
425
|
+
// $getLastCodeNodeOfLine hand that linebreak straight back, and it belongs
|
|
426
|
+
// to a *different* line. Anchoring on it splices the moving line into the
|
|
427
|
+
// line on the far side of the blank one, merging the two.
|
|
428
|
+
const adjacentLineIsBlank = $isLineBreakNode(sibling);
|
|
395
429
|
const maybeInsertionPoint =
|
|
396
|
-
|
|
397
|
-
$
|
|
398
|
-
$isLineBreakNode(sibling)
|
|
430
|
+
!adjacentLineIsBlank &&
|
|
431
|
+
($isCodeHighlightNode(sibling) || $isTabNode(sibling))
|
|
399
432
|
? arrowIsUp
|
|
400
433
|
? $getFirstCodeNodeOfLine(sibling)
|
|
401
434
|
: $getLastCodeNodeOfLine(sibling)
|
|
@@ -404,7 +437,15 @@ function $handleShiftLines(
|
|
|
404
437
|
maybeInsertionPoint != null ? maybeInsertionPoint : sibling;
|
|
405
438
|
linebreak.remove();
|
|
406
439
|
range.forEach(node => node.remove());
|
|
407
|
-
if (
|
|
440
|
+
if (adjacentLineIsBlank) {
|
|
441
|
+
// The blank line's position is immediately after the sibling linebreak,
|
|
442
|
+
// in both directions.
|
|
443
|
+
range.forEach(node => {
|
|
444
|
+
insertionPoint.insertAfter(node);
|
|
445
|
+
insertionPoint = node;
|
|
446
|
+
});
|
|
447
|
+
insertionPoint.insertAfter(linebreak);
|
|
448
|
+
} else if (type === KEY_ARROW_UP_COMMAND) {
|
|
408
449
|
range.forEach(node => insertionPoint.insertBefore(node));
|
|
409
450
|
insertionPoint.insertBefore(linebreak);
|
|
410
451
|
} else {
|
package/src/CodeNode.ts
CHANGED
|
@@ -417,7 +417,10 @@ export function $isCodeNode(
|
|
|
417
417
|
|
|
418
418
|
function $convertPreElement(domNode: HTMLElement): DOMConversionOutput {
|
|
419
419
|
const language = domNode.getAttribute(LANGUAGE_DATA_ATTRIBUTE);
|
|
420
|
-
|
|
420
|
+
// exportDOM writes data-theme next to data-language, so read it back here
|
|
421
|
+
// too — otherwise the theme is dropped on every HTML round trip.
|
|
422
|
+
const theme = domNode.getAttribute(THEME_DATA_ATTRIBUTE);
|
|
423
|
+
return {node: $createCodeNode(language, theme)};
|
|
421
424
|
}
|
|
422
425
|
|
|
423
426
|
function $convertDivElement(domNode: Node): DOMConversionOutput {
|