@lexical/code-core 0.45.1-nightly.20260610.0 → 0.45.1-nightly.20260611.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/CodeExtension.d.ts +10 -0
- package/dist/CodeImportExtension.d.ts +6 -9
- package/dist/LexicalCodeCore.dev.js +58 -46
- package/dist/LexicalCodeCore.dev.mjs +59 -47
- package/dist/LexicalCodeCore.prod.js +1 -1
- package/dist/LexicalCodeCore.prod.mjs +2 -1
- package/dist/index.d.ts +2 -2
- package/package.json +6 -6
- package/src/CodeExtension.ts +31 -1
- package/src/CodeImportExtension.ts +16 -35
- package/src/CodeIndentation.ts +2 -2
- package/src/index.ts +2 -2
package/dist/CodeExtension.d.ts
CHANGED
|
@@ -9,3 +9,13 @@
|
|
|
9
9
|
* Add code blocks to the editor (syntax highlighting provided separately)
|
|
10
10
|
*/
|
|
11
11
|
export declare const CodeExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/code", unknown, unknown>;
|
|
12
|
+
/**
|
|
13
|
+
* Bundles {@link CodeImportRules} together with the runtime
|
|
14
|
+
* {@link CodeExtension}.
|
|
15
|
+
*
|
|
16
|
+
* @experimental
|
|
17
|
+
* @deprecated {@link CodeExtension} now registers
|
|
18
|
+
* {@link CodeImportRules} (and `CoreImportExtension`) itself — depend on
|
|
19
|
+
* it directly instead.
|
|
20
|
+
*/
|
|
21
|
+
export declare const CodeImportExtension: import("lexical").LexicalExtension<import("lexical").ExtensionConfigBase, "@lexical/code/Import", unknown, unknown>;
|
|
@@ -36,15 +36,12 @@ export declare const $installVscodeCodePasteOverlay: DOMPreprocessFn;
|
|
|
36
36
|
* registered before the generic `<table>` / `<tr>` / `<td>` rules so
|
|
37
37
|
* they win dispatch.
|
|
38
38
|
*
|
|
39
|
-
* @
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
* a single dependency. The legacy {@link CodeNode.importDOM} continues to
|
|
45
|
-
* work in parallel; depend on this extension to opt into the new
|
|
46
|
-
* pipeline.
|
|
39
|
+
* Registered by {@link CodeExtension} itself (together with
|
|
40
|
+
* `CoreImportExtension` and the {@link $installVscodeCodePasteOverlay}
|
|
41
|
+
* preprocess), so any editor that uses the code extension can import
|
|
42
|
+
* these shapes through the `DOMImportExtension` pipeline without further
|
|
43
|
+
* configuration.
|
|
47
44
|
*
|
|
48
45
|
* @experimental
|
|
49
46
|
*/
|
|
50
|
-
export declare const
|
|
47
|
+
export declare const CodeImportRules: import("@lexical/html").DOMImportRule<import("@lexical/html").ElementSelectorBuilder<HTMLElement, Record<string, never>>>[];
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
+
var html = require('@lexical/html');
|
|
11
12
|
var lexical = require('lexical');
|
|
12
13
|
var extension = require('@lexical/extension');
|
|
13
|
-
var html = require('@lexical/html');
|
|
14
14
|
var utils = require('@lexical/utils');
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -735,33 +735,6 @@ function $isCodeHighlightNode(node) {
|
|
|
735
735
|
return node instanceof CodeHighlightNode;
|
|
736
736
|
}
|
|
737
737
|
|
|
738
|
-
/**
|
|
739
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
740
|
-
*
|
|
741
|
-
* This source code is licensed under the MIT license found in the
|
|
742
|
-
* LICENSE file in the root directory of this source tree.
|
|
743
|
-
*
|
|
744
|
-
*/
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
/**
|
|
748
|
-
* Add code blocks to the editor (syntax highlighting provided separately)
|
|
749
|
-
*/
|
|
750
|
-
const CodeExtension = lexical.defineExtension({
|
|
751
|
-
name: '@lexical/code',
|
|
752
|
-
nodes: () => [CodeNode, CodeHighlightNode],
|
|
753
|
-
register(editor) {
|
|
754
|
-
return editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
755
|
-
const selection = lexical.$getSelection();
|
|
756
|
-
if (lexical.$isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
|
|
757
|
-
event.preventDefault();
|
|
758
|
-
return true;
|
|
759
|
-
}
|
|
760
|
-
return false;
|
|
761
|
-
}, lexical.COMMAND_PRIORITY_LOW);
|
|
762
|
-
}
|
|
763
|
-
});
|
|
764
|
-
|
|
765
738
|
/**
|
|
766
739
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
767
740
|
*
|
|
@@ -800,12 +773,12 @@ function isMonospaceDescendant(node) {
|
|
|
800
773
|
* the cost of these rules is never paid against unrelated `<tr>` /
|
|
801
774
|
* `<td>` pastes.
|
|
802
775
|
*/
|
|
803
|
-
const GitHubCodeTableOverlayRules = html.defineOverlayRules([html.defineImportRule({
|
|
776
|
+
const GitHubCodeTableOverlayRules = /* @__PURE__ */html.defineOverlayRules([/* @__PURE__ */html.defineImportRule({
|
|
804
777
|
$import: (ctx, el) => ctx.$importChildren(el),
|
|
805
778
|
match: html.sel.tag('tr', 'td'),
|
|
806
779
|
name: '@lexical/code/github-code-table/unwrap'
|
|
807
780
|
})]);
|
|
808
|
-
const PreRule = html.defineImportRule({
|
|
781
|
+
const PreRule = /* @__PURE__ */html.defineImportRule({
|
|
809
782
|
$import: (ctx, el) => [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))],
|
|
810
783
|
match: html.sel.tag('pre'),
|
|
811
784
|
name: '@lexical/code/pre'
|
|
@@ -817,7 +790,7 @@ const PreRule = html.defineImportRule({
|
|
|
817
790
|
* defers to the inline-format rule from `CoreImportExtension` so it
|
|
818
791
|
* becomes a TextNode with IS_CODE.
|
|
819
792
|
*/
|
|
820
|
-
const MultilineCodeRule = html.defineImportRule({
|
|
793
|
+
const MultilineCodeRule = /* @__PURE__ */html.defineImportRule({
|
|
821
794
|
$import: (ctx, el, $next) => {
|
|
822
795
|
const text = el.textContent || '';
|
|
823
796
|
const isMultiLine = /\r?\n/.test(text) || el.querySelector('br') !== null;
|
|
@@ -932,7 +905,7 @@ function looksLikeVscodePaste(root) {
|
|
|
932
905
|
* around per-line `<div>`s and `<br>`s. Emits a single CodeNode whose
|
|
933
906
|
* text is the wrapper's lines joined by `\n`.
|
|
934
907
|
*/
|
|
935
|
-
const VscodeWrapperRule = html.defineImportRule({
|
|
908
|
+
const VscodeWrapperRule = /* @__PURE__ */html.defineImportRule({
|
|
936
909
|
$import: (_ctx, el, $next) => {
|
|
937
910
|
if (!isMonospacePreElement(el) || isMonospaceDescendant(el)) {
|
|
938
911
|
return $next();
|
|
@@ -954,7 +927,7 @@ const VscodeWrapperRule = html.defineImportRule({
|
|
|
954
927
|
* subsequent sibling in the same run, the prev-sibling check below
|
|
955
928
|
* returns `[]` so the run is only emitted once.
|
|
956
929
|
*/
|
|
957
|
-
const VscodeLineRunRule = html.defineImportRule({
|
|
930
|
+
const VscodeLineRunRule = /* @__PURE__ */html.defineImportRule({
|
|
958
931
|
$import: (_ctx, el, $next) => {
|
|
959
932
|
if (!isMonospacePreElement(el) || isMonospaceDescendant(el)) {
|
|
960
933
|
return $next();
|
|
@@ -978,7 +951,7 @@ const VscodeLineRunRule = html.defineImportRule({
|
|
|
978
951
|
match: html.sel.tag('div', 'br'),
|
|
979
952
|
name: '@lexical/code/vscode-line-run'
|
|
980
953
|
});
|
|
981
|
-
const VscodeCodePasteOverlay = html.defineOverlayRules([VscodeWrapperRule, VscodeLineRunRule]);
|
|
954
|
+
const VscodeCodePasteOverlay = /* @__PURE__ */html.defineOverlayRules([VscodeWrapperRule, VscodeLineRunRule]);
|
|
982
955
|
|
|
983
956
|
/**
|
|
984
957
|
* VS Code → browser code-block pastes ship the block as either:
|
|
@@ -1016,7 +989,7 @@ const $installVscodeCodePasteOverlay = (dom, ctx, $next) => {
|
|
|
1016
989
|
* wrapper just unwrap so their text content flows into the surrounding
|
|
1017
990
|
* CodeNode.
|
|
1018
991
|
*/
|
|
1019
|
-
const DivRule = html.defineImportRule({
|
|
992
|
+
const DivRule = /* @__PURE__ */html.defineImportRule({
|
|
1020
993
|
$import: (ctx, el, $next) => {
|
|
1021
994
|
if (isMonospaceElement(el)) {
|
|
1022
995
|
return [$createCodeNode().splice(0, 0, ctx.$importChildren(el))];
|
|
@@ -1038,7 +1011,7 @@ const DivRule = html.defineImportRule({
|
|
|
1038
1011
|
* subtree unwrap unconditionally — without paying the predicate cost
|
|
1039
1012
|
* on every other `<tr>` / `<td>` paste elsewhere.
|
|
1040
1013
|
*/
|
|
1041
|
-
const GitHubCodeTableRule = html.defineImportRule({
|
|
1014
|
+
const GitHubCodeTableRule = /* @__PURE__ */html.defineImportRule({
|
|
1042
1015
|
$import: (ctx, el) => [$createCodeNode().splice(0, 0, ctx.$importChildren(el, {
|
|
1043
1016
|
rules: GitHubCodeTableOverlayRules
|
|
1044
1017
|
}))],
|
|
@@ -1052,7 +1025,7 @@ const GitHubCodeTableRule = html.defineImportRule({
|
|
|
1052
1025
|
* descendant text flows up into whatever context the cell is in. The
|
|
1053
1026
|
* class is part of the selector itself, so no runtime guard.
|
|
1054
1027
|
*/
|
|
1055
|
-
const GitHubCodeCellByClassRule = html.defineImportRule({
|
|
1028
|
+
const GitHubCodeCellByClassRule = /* @__PURE__ */html.defineImportRule({
|
|
1056
1029
|
$import: (ctx, el) => ctx.$importChildren(el),
|
|
1057
1030
|
match: html.sel.tag('td').classAll('js-file-line'),
|
|
1058
1031
|
name: '@lexical/code/github-code-cell-by-class'
|
|
@@ -1065,6 +1038,12 @@ const GitHubCodeCellByClassRule = html.defineImportRule({
|
|
|
1065
1038
|
* registered before the generic `<table>` / `<tr>` / `<td>` rules so
|
|
1066
1039
|
* they win dispatch.
|
|
1067
1040
|
*
|
|
1041
|
+
* Registered by {@link CodeExtension} itself (together with
|
|
1042
|
+
* `CoreImportExtension` and the {@link $installVscodeCodePasteOverlay}
|
|
1043
|
+
* preprocess), so any editor that uses the code extension can import
|
|
1044
|
+
* these shapes through the `DOMImportExtension` pipeline without further
|
|
1045
|
+
* configuration.
|
|
1046
|
+
*
|
|
1068
1047
|
* @experimental
|
|
1069
1048
|
*/
|
|
1070
1049
|
const CodeImportRules = [
|
|
@@ -1072,18 +1051,51 @@ const CodeImportRules = [
|
|
|
1072
1051
|
GitHubCodeTableRule, GitHubCodeCellByClassRule, MultilineCodeRule, PreRule, DivRule];
|
|
1073
1052
|
|
|
1074
1053
|
/**
|
|
1075
|
-
*
|
|
1076
|
-
*
|
|
1077
|
-
*
|
|
1078
|
-
*
|
|
1054
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1055
|
+
*
|
|
1056
|
+
* This source code is licensed under the MIT license found in the
|
|
1057
|
+
* LICENSE file in the root directory of this source tree.
|
|
1079
1058
|
*
|
|
1080
|
-
* @experimental
|
|
1081
1059
|
*/
|
|
1082
|
-
|
|
1083
|
-
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
/**
|
|
1063
|
+
* Add code blocks to the editor (syntax highlighting provided separately)
|
|
1064
|
+
*/
|
|
1065
|
+
const CodeExtension = /* @__PURE__ */lexical.defineExtension({
|
|
1066
|
+
dependencies: [
|
|
1067
|
+
// DOMImportExtension support for the nodes registered here. Inert
|
|
1068
|
+
// unless the editor routes HTML through the pipeline (e.g. via
|
|
1069
|
+
// ClipboardDOMImportExtension or $generateNodesFromDOMViaExtension).
|
|
1070
|
+
html.CoreImportExtension, /* @__PURE__ */lexical.configExtension(html.DOMImportExtension, {
|
|
1084
1071
|
preprocess: [$installVscodeCodePasteOverlay],
|
|
1085
1072
|
rules: CodeImportRules
|
|
1086
1073
|
})],
|
|
1074
|
+
name: '@lexical/code',
|
|
1075
|
+
nodes: () => [CodeNode, CodeHighlightNode],
|
|
1076
|
+
register(editor) {
|
|
1077
|
+
return editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
1078
|
+
const selection = lexical.$getSelection();
|
|
1079
|
+
if (lexical.$isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
|
|
1080
|
+
event.preventDefault();
|
|
1081
|
+
return true;
|
|
1082
|
+
}
|
|
1083
|
+
return false;
|
|
1084
|
+
}, lexical.COMMAND_PRIORITY_LOW);
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Bundles {@link CodeImportRules} together with the runtime
|
|
1090
|
+
* {@link CodeExtension}.
|
|
1091
|
+
*
|
|
1092
|
+
* @experimental
|
|
1093
|
+
* @deprecated {@link CodeExtension} now registers
|
|
1094
|
+
* {@link CodeImportRules} (and `CoreImportExtension`) itself — depend on
|
|
1095
|
+
* it directly instead.
|
|
1096
|
+
*/
|
|
1097
|
+
const CodeImportExtension = /* @__PURE__ */lexical.defineExtension({
|
|
1098
|
+
dependencies: [CodeExtension],
|
|
1087
1099
|
name: '@lexical/code/Import'
|
|
1088
1100
|
});
|
|
1089
1101
|
|
|
@@ -1501,9 +1513,9 @@ function registerCodeIndentation(editor, tabSize, escapeWithArrows) {
|
|
|
1501
1513
|
* Code blocks without syntax highlighting can use this extension on its
|
|
1502
1514
|
* own.
|
|
1503
1515
|
*/
|
|
1504
|
-
const CodeIndentExtension = lexical.defineExtension({
|
|
1516
|
+
const CodeIndentExtension = /* @__PURE__ */lexical.defineExtension({
|
|
1505
1517
|
build: (editor, config) => extension.namedSignals(config),
|
|
1506
|
-
config: lexical.safeCast({
|
|
1518
|
+
config: /* @__PURE__ */lexical.safeCast({
|
|
1507
1519
|
disabled: false,
|
|
1508
1520
|
escapeWithArrows: false,
|
|
1509
1521
|
tabSize: undefined
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { defineImportRule, sel, ImportOverlays, defineOverlayRules, CoreImportExtension, DOMImportExtension } from '@lexical/html';
|
|
10
|
+
import { getTextDirection, $isElementNode, $isTabNode, $isLineBreakNode, tokenizeRawText, $createTabNode, $createLineBreakNode, $getSiblingCaret, $create, ElementNode, addClassNamesToElement, setDOMStyleFromCSS, $getEditor, $isTextNode, $createParagraphNode, isHTMLElement, $applyNodeReplacement, TextNode, removeClassNamesFromElement, isDOMDocumentNode, isDOMTextNode, $generateNodesFromRawText, defineExtension, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, COMMAND_PRIORITY_LOW, configExtension, safeCast, mergeRegister, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_TAB_COMMAND, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, MOVE_TO_START, MOVE_TO_END, $createPoint, $setSelectionFromCaretRange, $getCaretRangeInDirection, $getCaretRange, $getTextPointCaret, $normalizeCaret } from 'lexical';
|
|
10
11
|
import { getPeerDependencyFromEditor, effect, namedSignals } from '@lexical/extension';
|
|
11
|
-
import { CoreImportExtension, DOMImportExtension, defineImportRule, sel, ImportOverlays, defineOverlayRules } from '@lexical/html';
|
|
12
12
|
import { $onEscapeDown, $onEscapeUp } from '@lexical/utils';
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -733,33 +733,6 @@ function $isCodeHighlightNode(node) {
|
|
|
733
733
|
return node instanceof CodeHighlightNode;
|
|
734
734
|
}
|
|
735
735
|
|
|
736
|
-
/**
|
|
737
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
738
|
-
*
|
|
739
|
-
* This source code is licensed under the MIT license found in the
|
|
740
|
-
* LICENSE file in the root directory of this source tree.
|
|
741
|
-
*
|
|
742
|
-
*/
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
/**
|
|
746
|
-
* Add code blocks to the editor (syntax highlighting provided separately)
|
|
747
|
-
*/
|
|
748
|
-
const CodeExtension = defineExtension({
|
|
749
|
-
name: '@lexical/code',
|
|
750
|
-
nodes: () => [CodeNode, CodeHighlightNode],
|
|
751
|
-
register(editor) {
|
|
752
|
-
return editor.registerCommand(KEY_ENTER_COMMAND, event => {
|
|
753
|
-
const selection = $getSelection();
|
|
754
|
-
if ($isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
|
|
755
|
-
event.preventDefault();
|
|
756
|
-
return true;
|
|
757
|
-
}
|
|
758
|
-
return false;
|
|
759
|
-
}, COMMAND_PRIORITY_LOW);
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
|
|
763
736
|
/**
|
|
764
737
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
765
738
|
*
|
|
@@ -798,12 +771,12 @@ function isMonospaceDescendant(node) {
|
|
|
798
771
|
* the cost of these rules is never paid against unrelated `<tr>` /
|
|
799
772
|
* `<td>` pastes.
|
|
800
773
|
*/
|
|
801
|
-
const GitHubCodeTableOverlayRules = defineOverlayRules([defineImportRule({
|
|
774
|
+
const GitHubCodeTableOverlayRules = /* @__PURE__ */defineOverlayRules([/* @__PURE__ */defineImportRule({
|
|
802
775
|
$import: (ctx, el) => ctx.$importChildren(el),
|
|
803
776
|
match: sel.tag('tr', 'td'),
|
|
804
777
|
name: '@lexical/code/github-code-table/unwrap'
|
|
805
778
|
})]);
|
|
806
|
-
const PreRule = defineImportRule({
|
|
779
|
+
const PreRule = /* @__PURE__ */defineImportRule({
|
|
807
780
|
$import: (ctx, el) => [$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE)).splice(0, 0, ctx.$importChildren(el))],
|
|
808
781
|
match: sel.tag('pre'),
|
|
809
782
|
name: '@lexical/code/pre'
|
|
@@ -815,7 +788,7 @@ const PreRule = defineImportRule({
|
|
|
815
788
|
* defers to the inline-format rule from `CoreImportExtension` so it
|
|
816
789
|
* becomes a TextNode with IS_CODE.
|
|
817
790
|
*/
|
|
818
|
-
const MultilineCodeRule = defineImportRule({
|
|
791
|
+
const MultilineCodeRule = /* @__PURE__ */defineImportRule({
|
|
819
792
|
$import: (ctx, el, $next) => {
|
|
820
793
|
const text = el.textContent || '';
|
|
821
794
|
const isMultiLine = /\r?\n/.test(text) || el.querySelector('br') !== null;
|
|
@@ -930,7 +903,7 @@ function looksLikeVscodePaste(root) {
|
|
|
930
903
|
* around per-line `<div>`s and `<br>`s. Emits a single CodeNode whose
|
|
931
904
|
* text is the wrapper's lines joined by `\n`.
|
|
932
905
|
*/
|
|
933
|
-
const VscodeWrapperRule = defineImportRule({
|
|
906
|
+
const VscodeWrapperRule = /* @__PURE__ */defineImportRule({
|
|
934
907
|
$import: (_ctx, el, $next) => {
|
|
935
908
|
if (!isMonospacePreElement(el) || isMonospaceDescendant(el)) {
|
|
936
909
|
return $next();
|
|
@@ -952,7 +925,7 @@ const VscodeWrapperRule = defineImportRule({
|
|
|
952
925
|
* subsequent sibling in the same run, the prev-sibling check below
|
|
953
926
|
* returns `[]` so the run is only emitted once.
|
|
954
927
|
*/
|
|
955
|
-
const VscodeLineRunRule = defineImportRule({
|
|
928
|
+
const VscodeLineRunRule = /* @__PURE__ */defineImportRule({
|
|
956
929
|
$import: (_ctx, el, $next) => {
|
|
957
930
|
if (!isMonospacePreElement(el) || isMonospaceDescendant(el)) {
|
|
958
931
|
return $next();
|
|
@@ -976,7 +949,7 @@ const VscodeLineRunRule = defineImportRule({
|
|
|
976
949
|
match: sel.tag('div', 'br'),
|
|
977
950
|
name: '@lexical/code/vscode-line-run'
|
|
978
951
|
});
|
|
979
|
-
const VscodeCodePasteOverlay = defineOverlayRules([VscodeWrapperRule, VscodeLineRunRule]);
|
|
952
|
+
const VscodeCodePasteOverlay = /* @__PURE__ */defineOverlayRules([VscodeWrapperRule, VscodeLineRunRule]);
|
|
980
953
|
|
|
981
954
|
/**
|
|
982
955
|
* VS Code → browser code-block pastes ship the block as either:
|
|
@@ -1014,7 +987,7 @@ const $installVscodeCodePasteOverlay = (dom, ctx, $next) => {
|
|
|
1014
987
|
* wrapper just unwrap so their text content flows into the surrounding
|
|
1015
988
|
* CodeNode.
|
|
1016
989
|
*/
|
|
1017
|
-
const DivRule = defineImportRule({
|
|
990
|
+
const DivRule = /* @__PURE__ */defineImportRule({
|
|
1018
991
|
$import: (ctx, el, $next) => {
|
|
1019
992
|
if (isMonospaceElement(el)) {
|
|
1020
993
|
return [$createCodeNode().splice(0, 0, ctx.$importChildren(el))];
|
|
@@ -1036,7 +1009,7 @@ const DivRule = defineImportRule({
|
|
|
1036
1009
|
* subtree unwrap unconditionally — without paying the predicate cost
|
|
1037
1010
|
* on every other `<tr>` / `<td>` paste elsewhere.
|
|
1038
1011
|
*/
|
|
1039
|
-
const GitHubCodeTableRule = defineImportRule({
|
|
1012
|
+
const GitHubCodeTableRule = /* @__PURE__ */defineImportRule({
|
|
1040
1013
|
$import: (ctx, el) => [$createCodeNode().splice(0, 0, ctx.$importChildren(el, {
|
|
1041
1014
|
rules: GitHubCodeTableOverlayRules
|
|
1042
1015
|
}))],
|
|
@@ -1050,7 +1023,7 @@ const GitHubCodeTableRule = defineImportRule({
|
|
|
1050
1023
|
* descendant text flows up into whatever context the cell is in. The
|
|
1051
1024
|
* class is part of the selector itself, so no runtime guard.
|
|
1052
1025
|
*/
|
|
1053
|
-
const GitHubCodeCellByClassRule = defineImportRule({
|
|
1026
|
+
const GitHubCodeCellByClassRule = /* @__PURE__ */defineImportRule({
|
|
1054
1027
|
$import: (ctx, el) => ctx.$importChildren(el),
|
|
1055
1028
|
match: sel.tag('td').classAll('js-file-line'),
|
|
1056
1029
|
name: '@lexical/code/github-code-cell-by-class'
|
|
@@ -1063,6 +1036,12 @@ const GitHubCodeCellByClassRule = defineImportRule({
|
|
|
1063
1036
|
* registered before the generic `<table>` / `<tr>` / `<td>` rules so
|
|
1064
1037
|
* they win dispatch.
|
|
1065
1038
|
*
|
|
1039
|
+
* Registered by {@link CodeExtension} itself (together with
|
|
1040
|
+
* `CoreImportExtension` and the {@link $installVscodeCodePasteOverlay}
|
|
1041
|
+
* preprocess), so any editor that uses the code extension can import
|
|
1042
|
+
* these shapes through the `DOMImportExtension` pipeline without further
|
|
1043
|
+
* configuration.
|
|
1044
|
+
*
|
|
1066
1045
|
* @experimental
|
|
1067
1046
|
*/
|
|
1068
1047
|
const CodeImportRules = [
|
|
@@ -1070,18 +1049,51 @@ const CodeImportRules = [
|
|
|
1070
1049
|
GitHubCodeTableRule, GitHubCodeCellByClassRule, MultilineCodeRule, PreRule, DivRule];
|
|
1071
1050
|
|
|
1072
1051
|
/**
|
|
1073
|
-
*
|
|
1074
|
-
* a single dependency. The legacy {@link CodeNode.importDOM} continues to
|
|
1075
|
-
* work in parallel; depend on this extension to opt into the new
|
|
1076
|
-
* pipeline.
|
|
1052
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1077
1053
|
*
|
|
1078
|
-
*
|
|
1054
|
+
* This source code is licensed under the MIT license found in the
|
|
1055
|
+
* LICENSE file in the root directory of this source tree.
|
|
1056
|
+
*
|
|
1057
|
+
*/
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* Add code blocks to the editor (syntax highlighting provided separately)
|
|
1079
1062
|
*/
|
|
1080
|
-
const
|
|
1081
|
-
dependencies: [
|
|
1063
|
+
const CodeExtension = /* @__PURE__ */defineExtension({
|
|
1064
|
+
dependencies: [
|
|
1065
|
+
// DOMImportExtension support for the nodes registered here. Inert
|
|
1066
|
+
// unless the editor routes HTML through the pipeline (e.g. via
|
|
1067
|
+
// ClipboardDOMImportExtension or $generateNodesFromDOMViaExtension).
|
|
1068
|
+
CoreImportExtension, /* @__PURE__ */configExtension(DOMImportExtension, {
|
|
1082
1069
|
preprocess: [$installVscodeCodePasteOverlay],
|
|
1083
1070
|
rules: CodeImportRules
|
|
1084
1071
|
})],
|
|
1072
|
+
name: '@lexical/code',
|
|
1073
|
+
nodes: () => [CodeNode, CodeHighlightNode],
|
|
1074
|
+
register(editor) {
|
|
1075
|
+
return editor.registerCommand(KEY_ENTER_COMMAND, event => {
|
|
1076
|
+
const selection = $getSelection();
|
|
1077
|
+
if ($isRangeSelection(selection) && $exitCodeNodeOnEnter(selection)) {
|
|
1078
|
+
event.preventDefault();
|
|
1079
|
+
return true;
|
|
1080
|
+
}
|
|
1081
|
+
return false;
|
|
1082
|
+
}, COMMAND_PRIORITY_LOW);
|
|
1083
|
+
}
|
|
1084
|
+
});
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Bundles {@link CodeImportRules} together with the runtime
|
|
1088
|
+
* {@link CodeExtension}.
|
|
1089
|
+
*
|
|
1090
|
+
* @experimental
|
|
1091
|
+
* @deprecated {@link CodeExtension} now registers
|
|
1092
|
+
* {@link CodeImportRules} (and `CoreImportExtension`) itself — depend on
|
|
1093
|
+
* it directly instead.
|
|
1094
|
+
*/
|
|
1095
|
+
const CodeImportExtension = /* @__PURE__ */defineExtension({
|
|
1096
|
+
dependencies: [CodeExtension],
|
|
1085
1097
|
name: '@lexical/code/Import'
|
|
1086
1098
|
});
|
|
1087
1099
|
|
|
@@ -1499,9 +1511,9 @@ function registerCodeIndentation(editor, tabSize, escapeWithArrows) {
|
|
|
1499
1511
|
* Code blocks without syntax highlighting can use this extension on its
|
|
1500
1512
|
* own.
|
|
1501
1513
|
*/
|
|
1502
|
-
const CodeIndentExtension = defineExtension({
|
|
1514
|
+
const CodeIndentExtension = /* @__PURE__ */defineExtension({
|
|
1503
1515
|
build: (editor, config) => namedSignals(config),
|
|
1504
|
-
config: safeCast({
|
|
1516
|
+
config: /* @__PURE__ */safeCast({
|
|
1505
1517
|
disabled: false,
|
|
1506
1518
|
escapeWithArrows: false,
|
|
1507
1519
|
tabSize: undefined
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("@lexical/extension"),n=require("@lexical/html"),r=require("@lexical/utils");function i(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function o(t,n){let r=t;for(let i=e.$getSiblingCaret(t,n);i&&(D(i.origin)||e.$isTabNode(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function s(e){return o(e,"previous")}function l(e){return o(e,"next")}function a(t){const n=s(t),r=l(t);let i=n;for(;null!==i;){if(D(i)){const t=e.getTextDirection(i.getTextContent());if(null!==t)return t}if(i===r)break;i=i.getNextSibling()}const o=n.getParent();if(e.$isElementNode(o)){const e=o.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function c(t,n){let r=null,o=null,s=t,l=n,a=t.getTextContent();for(;;){if(0===l){const t=s.getPreviousSibling();if(null===t){s=null;break}if(D(t)||e.$isTabNode(t)||e.$isLineBreakNode(t)||i(167),s=t,e.$isLineBreakNode(s)){r={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),a=s.getTextContent()}else l--;const t=a[l];D(s)&&" "!==t&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<t.getTextContentSize())D(t)&&(c=t.getTextContent()[n]);else{const e=t.getNextSibling();D(e)&&(c=e.getTextContent()[0])}if(null!==c&&" "!==c)return r;{const i=function(t,n){let r=t,i=n,o=t.getTextContent(),s=t.getTextContentSize();for(;;){if(!D(r)||i===s){if(r=r.getNextSibling(),null===r||e.$isLineBreakNode(r))return null;D(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(D(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(t,n);return null!==i?i:r}}function u(t){const n=l(t);return e.$isLineBreakNode(n)&&i(168),n}function g(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,a=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==a&&n.focus.set(s,Math.max(0,a-o),"text"),!0}const d="javascript";function f(t,n){for(const r of t.childNodes){if(e.isHTMLElement(r)&&r.tagName===n)return!0;if(f(r,n))return!0}return!1}const h="data-language",p="data-highlight-language",N="data-theme",m=()=>{};class _ extends e.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new _(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(t){const n=document.createElement("code");e.addClassNamesToElement(n,t.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&e.setDOMStyleFromCSS(n.style,o),n}updateDOM(t,n,r){const i=this.__language,o=t.__language;i?i!==o&&n.setAttribute(h,i):o&&n.removeAttribute(h);const s=this.__isSyntaxHighlightSupported;t.__isSyntaxHighlightSupported&&o?s&&i?i!==o&&n.setAttribute(p,i):n.removeAttribute(p):s&&i&&n.setAttribute(p,i);const l=this.__theme,a=t.__theme;l?l!==a&&n.setAttribute(N,l):a&&n.removeAttribute(N);const c=this.__style,u=t.__style;return c!==u&&e.setDOMStyleFromCSS(n.style,c,u),!1}exportDOM(t){const n=document.createElement("pre");e.addClassNamesToElement(n,t._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&e.setDOMStyleFromCSS(n.style,o),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||f(e,"BR"))?{conversion:x,priority:1}:null,div:()=>({conversion:O,priority:1}),pre:()=>({conversion:x,priority:0}),table:e=>b(e)?{conversion:S,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:M,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:M,priority:3}:null}}}static importJSON(e){return T().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(n,r=!0){if(!t.getPeerDependencyFromEditor(e.$getEditor(),"@lexical/code")){m();const e=E(n);if(e)return e}const{anchor:i,focus:o}=n,l=(i.isBefore(o)?i:o).getNode();if(e.$isTextNode(l)){let t=s(l);const n=[];for(;;)if(e.$isTabNode(t))n.push(e.$createTabNode()),t=t.getNextSibling();else{if(!D(t))break;{let e=0;const r=t.getTextContent(),i=t.getTextContentSize();for(;e<i&&" "===r[e];)e++;if(0!==e&&n.push(A(" ".repeat(e))),e!==i)break;t=t.getNextSibling()}}const r=l.splitText(i.offset)[0],o=0===i.offset?0:1,a=r.getIndexWithinParent()+o,c=l.getParentOrThrow(),u=[e.$createLineBreakNode(),...n];c.splice(a,0,u);const g=n[n.length-1];g?g.select():0===i.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(C(l)){const{offset:t}=n.anchor;l.splice(t,0,[e.$createLineBreakNode()]),l.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const t=e.$createParagraphNode();return this.getChildren().forEach(e=>t.append(e)),this.replace(t),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function T(t,n){return e.$create(_).setLanguage(t).setTheme(n)}function C(e){return e instanceof _}function x(e){return{node:T(e.getAttribute(h))}}function O(e){const t=e,n=$(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if($(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function M(){return{node:null}}function $(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function E(t){const{anchor:n}=t;if(t.isCollapsed()&&"element"===n.type){const t=n.getNode();if(C(t)){const r=t.getChildrenSize();if(r>=2&&n.offset===r){const n=t.getLastChild();if(e.$isLineBreakNode(n)&&e.$isLineBreakNode(n.getPreviousSibling())){const n=e.$createParagraphNode();return t.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class R extends e.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new R(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(t){const n=super.createDOM(t),r=y(t.theme,this.__highlightType);return e.addClassNamesToElement(n,r),n}updateDOM(t,n,r){const i=super.updateDOM(t,n,r),o=y(r.theme,t.__highlightType),s=y(r.theme,this.__highlightType);return o!==s&&(o&&e.removeClassNamesFromElement(n,o),s&&e.addClassNamesToElement(n,s)),i}static importJSON(e){return A().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return T()}}function y(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function A(t="",n){return e.$applyNodeReplacement(new R(t,n))}function D(e){return e instanceof R}const v=e.defineExtension({name:"@lexical/code",nodes:()=>[_,R],register:t=>t.registerCommand(e.KEY_ENTER_COMMAND,t=>{const n=e.$getSelection();return!(!e.$isRangeSelection(n)||!E(n))&&(t.preventDefault(),!0)},e.COMMAND_PRIORITY_LOW)}),I="data-language";function L(e){return null!==e.style.fontFamily.match("monospace")}function P(e){let t=e.parentElement;for(;null!==t;){if(L(t))return!0;t=t.parentElement}return!1}const B=n.defineOverlayRules([n.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:n.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),k=n.defineImportRule({$import:(e,t)=>[T(t.getAttribute(I)).splice(0,0,e.$importChildren(t))],match:n.sel.tag("pre"),name:"@lexical/code/pre"}),W=n.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(I)).splice(0,0,e.$importChildren(t))]:n()},match:n.sel.tag("code"),name:"@lexical/code/code-multiline"});function w(t){if(!e.isHTMLElement(t))return!1;const n=t.style.fontFamily,r=t.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function H(t){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(t.childNodes))if(e.isHTMLElement(l))"DIV"===l.tagName?(s(),r.push(l.textContent||""),n=!0):"BR"===l.tagName?(s(),r.push(""),n=!0):(i+=l.textContent||"",o=!0);else if(e.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function F(t){for(const n of Array.from(t.children)){if(e.isHTMLElement(n)&&w(n)){if(null!==H(n))return!0;const e=n.nextElementSibling;if(e&&w(e))return!0;continue}if(F(n))return!0}return!1}const Y=n.defineImportRule({$import:(t,n,r)=>{if(!w(n)||P(n))return r();const i=H(n);return null===i||0===i.length?r():[T().splice(0,0,e.$generateNodesFromRawText(i.join("\n")))]},match:n.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),K=n.defineImportRule({$import:(t,n,r)=>{if(!w(n)||P(n))return r();const i=n.previousElementSibling;if(i&&w(i))return[];const o=[];let s=n;for(;s&&w(s);)o.push("BR"===s.tagName?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?r():[T().splice(0,0,e.$generateNodesFromRawText(o.join("\n")))]},match:n.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),U=n.defineOverlayRules([Y,K]),z=n.defineImportRule({$import:(e,t,n)=>L(t)?[T().splice(0,0,e.$importChildren(t))]:P(t)?e.$importChildren(t):n(),match:n.sel.tag("div"),name:"@lexical/code/div"}),J=[n.defineImportRule({$import:(e,t)=>[T().splice(0,0,e.$importChildren(t,{rules:B}))],match:n.sel.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),n.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:n.sel.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),W,k,z],j=e.defineExtension({dependencies:[n.CoreImportExtension,v,e.configExtension(n.DOMImportExtension,{preprocess:[(t,r,i)=>{F(e.isDOMDocumentNode(t)?t.body:t)&&r.session.update(n.ImportOverlays,e=>[...e,U]),i()}],rules:J})],name:"@lexical/code/Import"});function q(t){if(!e.$isRangeSelection(t))return!1;const n=t.anchor.getNode(),r=C(n)?n:n.getParent(),i=t.focus.getNode(),o=C(i)?i:i.getParent();return C(r)&&r.is(o)}function V(t){const n=t.getNodes(),r=[];if(1===n.length&&C(n[0]))return r;let o=[];for(let t=0;t<n.length;t++){const s=n[t];D(s)||e.$isTabNode(s)||e.$isLineBreakNode(s)||i(169),e.$isLineBreakNode(s)?o.length>0&&(r.push(o),o=[]):o.push(s)}if(o.length>0){const n=t.isBackward()?t.anchor:t.focus,i=e.$createPoint(o[0].getKey(),0,"text");n.is(i)||r.push(o)}return r}function G(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r)||!q(r))return!1;const i=V(r),o=i.length;if(0===o&&r.isCollapsed())return t===e.INDENT_CONTENT_COMMAND&&r.insertNodes([e.$createTabNode()]),!0;if(0===o&&t===e.INDENT_CONTENT_COMMAND&&"\n"===r.getTextContent()){const t=e.$createTabNode(),n=e.$createLineBreakNode(),i=r.isBackward()?"previous":"next";return r.insertNodes([t,n]),e.$setSelectionFromCaretRange(e.$getCaretRangeInDirection(e.$getCaretRange(e.$getTextPointCaret(t,"next",0),e.$normalizeCaret(e.$getSiblingCaret(n,"next"))),i)),!0}for(let l=0;l<o;l++){const o=i[l];if(o.length>0){let i=o[0];if(0===l&&(i=s(i)),t===e.INDENT_CONTENT_COMMAND){const t=e.$createTabNode();if(i.insertBefore(t),0===l){const n=r.isBackward()?"focus":"anchor",o=e.$createPoint(i.getKey(),0,"text");r[n].is(o)&&r[n].set(t.getKey(),0,"text")}}else e.$isTabNode(i)?i.remove():void 0!==n&&D(i)&&g(i,n,r)}}return!0}function Q(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,a=i.offset,c=o.offset,u=i.getNode(),g=o.getNode(),d=t===e.KEY_ARROW_UP_COMMAND;if(!q(r)||!D(u)&&!e.$isTabNode(u)||!D(g)&&!e.$isTabNode(g))return!1;if(!n.altKey){if(r.isCollapsed()){const e=u.getParentOrThrow();if(d&&0===a&&null===u.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),n.preventDefault(),!1}else if(!d&&a===u.getTextContentSize()&&null===u.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),n.preventDefault(),!1}}return!1}let f,h;if(u.isBefore(g)?(f=s(u),h=l(g)):(f=s(g),h=l(u)),null==f||null==h)return!1;const p=f.getNodesBetween(h);for(let t=0;t<p.length;t++){const n=p[t];if(!D(n)&&!e.$isTabNode(n)&&!e.$isLineBreakNode(n))return!1}n.preventDefault(),n.stopPropagation();const N=d?f.getPreviousSibling():h.getNextSibling();if(!e.$isLineBreakNode(N))return!0;const m=d?N.getPreviousSibling():N.getNextSibling();if(null==m)return!0;const _=D(m)||e.$isTabNode(m)||e.$isLineBreakNode(m)?d?s(m):l(m):null;let T=null!=_?_:m;return N.remove(),p.forEach(e=>e.remove()),t===e.KEY_ARROW_UP_COMMAND?(p.forEach(e=>T.insertBefore(e)),T.insertBefore(N)):(T.insertAfter(N),T=N,p.forEach(e=>{T.insertAfter(e),T=e})),r.setTextNodeRange(u,a,g,c),!0}function X(t,n){const r=e.$getSelection();if(!e.$isRangeSelection(r))return!1;const{anchor:i,focus:o}=r,s=i.getNode(),l=o.getNode(),g=t===e.MOVE_TO_START;if(!q(r)||!D(s)&&!e.$isTabNode(s)||!D(l)&&!e.$isTabNode(l))return!1;const d=l,f="rtl"===a(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const t=c(d,o.offset);if(null!==t){const{node:n,offset:i}=t;e.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else d.getParentOrThrow().selectStart()}else{u(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function Z(t,n,o){return e.mergeRegister(...o?[t.registerCommand(e.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(C),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_RIGHT_COMMAND,()=>r.$onEscapeDown(C),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(C),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_LEFT_COMMAND,()=>r.$onEscapeUp(C),e.COMMAND_PRIORITY_LOW)]:[],t.registerCommand(e.KEY_TAB_COMMAND,n=>{const r=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n)||!q(n))return null;const r=t?e.OUTDENT_CONTENT_COMMAND:e.INDENT_CONTENT_COMMAND,o=t?e.OUTDENT_CONTENT_COMMAND:e.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return o;const u=V(n);if(1!==u.length)return r;const g=u[0];let d,f;0===g.length&&i(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=s(g[0]),p=l(g[0]),N=e.$createPoint(h.getKey(),0,"text"),m=e.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?r:N.isBefore(d)||f.isBefore(m)?o:r}(n.shiftKey);return null!==r&&(n.preventDefault(),t.dispatchCommand(r,void 0),!0)},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.INSERT_TAB_COMMAND,()=>!!q(e.$getSelection())&&(e.$insertNodes([e.$createTabNode()]),!0),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.INDENT_CONTENT_COMMAND,()=>G(e.INDENT_CONTENT_COMMAND),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.OUTDENT_CONTENT_COMMAND,()=>G(e.OUTDENT_CONTENT_COMMAND,n),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_UP_COMMAND,t=>{const n=e.$getSelection();if(!e.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();if(!q(n))return!1;const o=i.getParent();return n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&C(o)&&null===o.getPreviousSibling()?(t.preventDefault(),!0):Q(e.KEY_ARROW_UP_COMMAND,t)},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.KEY_ARROW_DOWN_COMMAND,t=>{const n=e.$getSelection();if(!e.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!q(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&C(i.getParentOrThrow())&&null===i.getParentOrThrow().getNextSibling()?(t.preventDefault(),!0):Q(e.KEY_ARROW_DOWN_COMMAND,t))},e.COMMAND_PRIORITY_LOW),t.registerCommand(e.MOVE_TO_START,t=>X(e.MOVE_TO_START,t),e.COMMAND_PRIORITY_LOW),t.registerCommand(e.MOVE_TO_END,t=>X(e.MOVE_TO_END,t),e.COMMAND_PRIORITY_LOW))}const ee=e.defineExtension({build:(e,n)=>t.namedSignals(n),config:e.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[v],name:"@lexical/code-indent",register:(e,n,r)=>{const i=r.getOutput();return t.effect(()=>{if(!i.disabled.value)return Z(e,i.tabSize.value,i.escapeWithArrows.value)})}});exports.$createCodeHighlightNode=A,exports.$createCodeNode=T,exports.$getCodeLineDirection=a,exports.$getEndOfCodeInLine=u,exports.$getFirstCodeNodeOfLine=s,exports.$getLastCodeNodeOfLine=l,exports.$getStartOfCodeInLine=c,exports.$isCodeHighlightNode=D,exports.$isCodeNode=C,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(t){const n=[];return e.tokenizeRawText(t,{linebreak:()=>n.push(e.$createLineBreakNode()),tab:()=>n.push(e.$createTabNode()),text:e=>n.push(A(e))}),n},exports.CodeExtension=v,exports.CodeHighlightNode=R,exports.CodeImportExtension=j,exports.CodeImportRules=J,exports.CodeIndentExtension=ee,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=Z;
|
|
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&&(D(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(D(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(D(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];D(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(n<e.getTextContentSize())D(e)&&(c=e.getTextContent()[n]);else{const t=e.getNextSibling();D(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(!D(r)||i===s){if(r=r.getNextSibling(),null===r||t.$isLineBreakNode(r))return null;D(r)&&(i=0,o=r.getTextContent(),s=r.getTextContentSize())}if(D(r)){if(" "!==o[i])return{node:r,offset:i};i++}}}(e,n);return null!==i?i:r}}function u(e){const n=l(e);return t.$isLineBreakNode(n)&&i(168),n}function g(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,a=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==a&&n.focus.set(s,Math.max(0,a-o),"text"),!0}const d="javascript";function f(e,n){for(const r of e.childNodes){if(t.isHTMLElement(r)&&r.tagName===n)return!0;if(f(r,n))return!0}return!1}const h="data-language",p="data-highlight-language",N="data-theme",m=()=>{};class _ extends t.ElementNode{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new _(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const n=document.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=document.createElement("pre");t.addClassNamesToElement(n,e._config.theme.code),n.setAttribute("spellcheck","false");const r=this.getLanguage();r&&(n.setAttribute(h,r),this.getIsSyntaxHighlightSupported()&&n.setAttribute(p,r));const i=this.getTheme();i&&n.setAttribute(N,i);const o=this.getStyle();return o&&t.setDOMStyleFromCSS(n.style,o),{element:n}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||f(e,"BR"))?{conversion:x,priority:1}:null,div:()=>({conversion:O,priority:1}),pre:()=>({conversion:x,priority:0}),table:e=>b(e)?{conversion:S,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&b(n)?{conversion:M,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&b(t)?{conversion:M,priority:3}:null}}}static importJSON(e){return T().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(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(!D(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(C(l)){const{offset:n}=e.anchor;l.splice(n,0,[t.$createLineBreakNode()]),l.select(n+1,n+1)}return null}canIndent(){return!1}collapseAtStart(){const e=t.$createParagraphNode();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function T(e,n){return t.$create(_).setLanguage(e).setTheme(n)}function C(e){return e instanceof _}function x(e){return{node:T(e.getAttribute(h))}}function O(e){const t=e,n=$(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if($(t))return!0;t=t.parentElement}return!1}(t)?{node:n?T():null}:{node:null}}function S(){return{node:T()}}function M(){return{node:null}}function $(e){return null!==e.style.fontFamily.match("monospace")}function b(e){return e.classList.contains("js-file-line-container")}function E(e){const{anchor:n}=e;if(e.isCollapsed()&&"element"===n.type){const e=n.getNode();if(C(e)){const r=e.getChildrenSize();if(r>=2&&n.offset===r){const n=e.getLastChild();if(t.$isLineBreakNode(n)&&t.$isLineBreakNode(n.getPreviousSibling())){const n=t.$createParagraphNode();return e.splice(r-2,2,[]).insertAfter(n,!1),n.select(),n}}}}return null}class R extends t.TextNode{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new R(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const n=super.createDOM(e),r=y(e.theme,this.__highlightType);return t.addClassNamesToElement(n,r),n}updateDOM(e,n,r){const i=super.updateDOM(e,n,r),o=y(r.theme,e.__highlightType),s=y(r.theme,this.__highlightType);return o!==s&&(o&&t.removeClassNamesFromElement(n,o),s&&t.addClassNamesToElement(n,s)),i}static importJSON(e){return A().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return T()}}function y(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function A(e="",n){return t.$applyNodeReplacement(new R(e,n))}function D(e){return e instanceof R}const v="data-language";function I(e){return null!==e.style.fontFamily.match("monospace")}function L(e){let t=e.parentElement;for(;null!==t;){if(I(t))return!0;t=t.parentElement}return!1}const P=/* @__PURE__ */e.defineOverlayRules([/* @__PURE__ */e.defineImportRule({$import:(e,t)=>e.$importChildren(t),match:e.sel.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),B=/* @__PURE__ */e.defineImportRule({$import:(e,t)=>[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))],match:e.sel.tag("pre"),name:"@lexical/code/pre"}),k=/* @__PURE__ */e.defineImportRule({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[T(t.getAttribute(v)).splice(0,0,e.$importChildren(t))]:n()},match:e.sel.tag("code"),name:"@lexical/code/code-multiline"});function W(e){if(!t.isHTMLElement(e))return!1;const n=e.style.fontFamily,r=e.style.whiteSpace;return"string"==typeof n&&/monospace/i.test(n)&&"string"==typeof r&&r.startsWith("pre")}function w(e){let n=!1;const r=[];let i="",o=!1;const s=()=>{o&&(r.push(i),i="",o=!1)};for(const l of Array.from(e.childNodes))if(t.isHTMLElement(l))"DIV"===l.tagName?(s(),r.push(l.textContent||""),n=!0):"BR"===l.tagName?(s(),r.push(""),n=!0):(i+=l.textContent||"",o=!0);else if(t.isDOMTextNode(l)){const e=l.textContent||"";e.length>0&&(i+=e,o=!0)}return s(),n?r:null}function H(e){for(const n of Array.from(e.children)){if(t.isHTMLElement(n)&&W(n)){if(null!==w(n))return!0;const e=n.nextElementSibling;if(e&&W(e))return!0;continue}if(H(n))return!0}return!1}const F=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!W(n)||L(n))return r();const i=w(n);return null===i||0===i.length?r():[T().splice(0,0,t.$generateNodesFromRawText(i.join("\n")))]},match:e.sel.tag("div"),name:"@lexical/code/vscode-wrapper"}),Y=/* @__PURE__ */e.defineImportRule({$import:(e,n,r)=>{if(!W(n)||L(n))return r();const i=n.previousElementSibling;if(i&&W(i))return[];const o=[];let s=n;for(;s&&W(s);)o.push("BR"===s.tagName?"":s.textContent||""),s=s.nextElementSibling;return o.length<2?r():[T().splice(0,0,t.$generateNodesFromRawText(o.join("\n")))]},match:e.sel.tag("div","br"),name:"@lexical/code/vscode-line-run"}),K=/* @__PURE__ */e.defineOverlayRules([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"}),k,B,U],J=/* @__PURE__ */t.defineExtension({dependencies:[e.CoreImportExtension,/* @__PURE__ */t.configExtension(e.DOMImportExtension,{preprocess:[(n,r,i)=>{H(t.isDOMDocumentNode(n)?n.body:n)&&r.session.update(e.ImportOverlays,e=>[...e,K]),i()}],rules:z})],name:"@lexical/code",nodes:()=>[_,R],register:e=>e.registerCommand(t.KEY_ENTER_COMMAND,e=>{const n=t.$getSelection();return!(!t.$isRangeSelection(n)||!E(n))&&(e.preventDefault(),!0)},t.COMMAND_PRIORITY_LOW)}),j=/* @__PURE__ */t.defineExtension({dependencies:[J],name:"@lexical/code/Import"});function q(e){if(!t.$isRangeSelection(e))return!1;const n=e.anchor.getNode(),r=C(n)?n:n.getParent(),i=e.focus.getNode(),o=C(i)?i:i.getParent();return C(r)&&r.is(o)}function V(e){const n=e.getNodes(),r=[];if(1===n.length&&C(n[0]))return r;let o=[];for(let e=0;e<n.length;e++){const s=n[e];D(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&&D(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)||!D(u)&&!t.$isTabNode(u)||!D(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(!D(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 _=D(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)||!D(s)&&!t.$isTabNode(s)||!D(l)&&!t.$isTabNode(l))return!1;const d=l,f="rtl"===a(d)?!g:g,h=i.key,p=i.offset,N=i.type;if(f){const e=c(d,o.offset);if(null!==e){const{node:n,offset:i}=e;t.$isLineBreakNode(n)?n.selectNext(0,0):r.setTextNodeRange(n,i,n,i)}else d.getParentOrThrow().selectStart()}else{u(d).select()}return n.shiftKey&&r.anchor.set(h,p,N),n.preventDefault(),n.stopPropagation(),!0}function Z(e,n,o){return t.mergeRegister(...o?[e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>!e.altKey&&r.$onEscapeDown(C),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_RIGHT_COMMAND,()=>r.$onEscapeDown(C),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>!e.altKey&&r.$onEscapeUp(C),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_LEFT_COMMAND,()=>r.$onEscapeUp(C),t.COMMAND_PRIORITY_LOW)]:[],e.registerCommand(t.KEY_TAB_COMMAND,n=>{const r=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!q(n))return null;const r=e?t.OUTDENT_CONTENT_COMMAND:t.INDENT_CONTENT_COMMAND,o=e?t.OUTDENT_CONTENT_COMMAND:t.INSERT_TAB_COMMAND,a=n.anchor,c=n.focus;if(a.is(c))return o;const u=V(n);if(1!==u.length)return r;const g=u[0];let d,f;0===g.length&&i(285),n.isBackward()?(d=c,f=a):(d=a,f=c);const h=s(g[0]),p=l(g[0]),N=t.$createPoint(h.getKey(),0,"text"),m=t.$createPoint(p.getKey(),p.getTextContentSize(),"text");return d.isBefore(N)||m.isBefore(f)?r:N.isBefore(d)||f.isBefore(m)?o:r}(n.shiftKey);return null!==r&&(n.preventDefault(),e.dispatchCommand(r,void 0),!0)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INSERT_TAB_COMMAND,()=>!!q(t.$getSelection())&&(t.$insertNodes([t.$createTabNode()]),!0),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.INDENT_CONTENT_COMMAND,()=>G(t.INDENT_CONTENT_COMMAND),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.OUTDENT_CONTENT_COMMAND,()=>G(t.OUTDENT_CONTENT_COMMAND,n),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_UP_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();if(!q(n))return!1;const o=i.getParent();return n.isCollapsed()&&0===r.offset&&null===i.getPreviousSibling()&&C(o)&&null===o.getPreviousSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_UP_COMMAND,e)},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.KEY_ARROW_DOWN_COMMAND,e=>{const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const{anchor:r}=n,i=r.getNode();return!!q(n)&&(n.isCollapsed()&&r.offset===i.getTextContentSize()&&null===i.getNextSibling()&&C(i.getParentOrThrow())&&null===i.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Q(t.KEY_ARROW_DOWN_COMMAND,e))},t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_START,e=>X(t.MOVE_TO_START,e),t.COMMAND_PRIORITY_LOW),e.registerCommand(t.MOVE_TO_END,e=>X(t.MOVE_TO_END,e),t.COMMAND_PRIORITY_LOW))}const ee=/* @__PURE__ */t.defineExtension({build:(e,t)=>n.namedSignals(t),config:/* @__PURE__ */t.safeCast({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[J],name:"@lexical/code-indent",register:(e,t,r)=>{const i=r.getOutput();return n.effect(()=>{if(!i.disabled.value)return Z(e,i.tabSize.value,i.escapeWithArrows.value)})}});exports.$createCodeHighlightNode=A,exports.$createCodeNode=T,exports.$getCodeLineDirection=a,exports.$getEndOfCodeInLine=u,exports.$getFirstCodeNodeOfLine=s,exports.$getLastCodeNodeOfLine=l,exports.$getStartOfCodeInLine=c,exports.$isCodeHighlightNode=D,exports.$isCodeNode=C,exports.$outdentLeadingSpaces=g,exports.$plainifyCodeContent=function(e){const n=[];return t.tokenizeRawText(e,{linebreak:()=>n.push(t.$createLineBreakNode()),tab:()=>n.push(t.$createTabNode()),text:e=>n.push(A(e))}),n},exports.CodeExtension=J,exports.CodeHighlightNode=R,exports.CodeImportExtension=j,exports.CodeImportRules=z,exports.CodeIndentExtension=ee,exports.CodeNode=_,exports.DEFAULT_CODE_LANGUAGE=d,exports.getDefaultCodeLanguage=()=>d,exports.registerCodeIndentation=Z;
|
|
@@ -6,4 +6,5 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{getTextDirection as e,$isElementNode as t,$isTabNode as n,$isLineBreakNode as r,tokenizeRawText as i,$createTabNode as o,$createLineBreakNode as s,$getSiblingCaret as l,$create as u,ElementNode as c,addClassNamesToElement as a,setDOMStyleFromCSS as g,$getEditor as h,$isTextNode as f,$createParagraphNode as p,isHTMLElement as d,$applyNodeReplacement as m,TextNode as x,removeClassNamesFromElement as _,defineExtension as S,KEY_ENTER_COMMAND as y,$getSelection as b,$isRangeSelection as v,COMMAND_PRIORITY_LOW as C,configExtension as N,isDOMDocumentNode as T,isDOMTextNode as A,$generateNodesFromRawText as O,safeCast as P,mergeRegister as w,KEY_ARROW_DOWN_COMMAND as H,KEY_ARROW_RIGHT_COMMAND as D,KEY_ARROW_UP_COMMAND as k,KEY_ARROW_LEFT_COMMAND as B,KEY_TAB_COMMAND as L,INSERT_TAB_COMMAND as $,$insertNodes as E,INDENT_CONTENT_COMMAND as F,OUTDENT_CONTENT_COMMAND as M,MOVE_TO_START as J,MOVE_TO_END as z,$createPoint as K,$setSelectionFromCaretRange as I,$getCaretRangeInDirection as j,$getCaretRange as R,$getTextPointCaret as W,$normalizeCaret as q}from"lexical";import{getPeerDependencyFromEditor as U,effect as V,namedSignals as G}from"@lexical/extension";import{CoreImportExtension as Q,DOMImportExtension as X,defineImportRule as Y,sel as Z,ImportOverlays as ee,defineOverlayRules as te}from"@lexical/html";import{$onEscapeDown as ne,$onEscapeUp as re}from"@lexical/utils";function ie(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function oe(e,t){let r=e;for(let i=l(e,t);i&&(Be(i.origin)||n(i.origin));i=i.getAdjacentCaret())r=i.origin;return r}function se(e){return oe(e,"previous")}function le(e){return oe(e,"next")}function ue(n){const r=se(n),i=le(n);let o=r;for(;null!==o;){if(Be(o)){const t=e(o.getTextContent());if(null!==t)return t}if(o===i)break;o=o.getNextSibling()}const s=r.getParent();if(t(s)){const e=s.getDirection();if("ltr"===e||"rtl"===e)return e}return null}function ce(e,t){let i=null,o=null,s=e,l=t,u=e.getTextContent();for(;;){if(0===l){const e=s.getPreviousSibling();if(null===e){s=null;break}if(Be(e)||n(e)||r(e)||ie(167),s=e,r(s)){i={node:s,offset:1};break}l=Math.max(0,s.getTextContentSize()-1),u=s.getTextContent()}else l--;const e=u[l];Be(s)&&" "!==e&&(o={node:s,offset:l})}if(null!==o)return o;let c=null;if(t<e.getTextContentSize())Be(e)&&(c=e.getTextContent()[t]);else{const t=e.getNextSibling();Be(t)&&(c=t.getTextContent()[0])}if(null!==c&&" "!==c)return i;{const n=function(e,t){let n=e,i=t,o=e.getTextContent(),s=e.getTextContentSize();for(;;){if(!Be(n)||i===s){if(n=n.getNextSibling(),null===n||r(n))return null;Be(n)&&(i=0,o=n.getTextContent(),s=n.getTextContentSize())}if(Be(n)){if(" "!==o[i])return{node:n,offset:i};i++}}}(e,t);return null!==n?n:i}}function ae(e){const t=le(e);return r(t)&&ie(168),t}function ge(e){const t=[];return i(e,{linebreak:()=>t.push(s()),tab:()=>t.push(o()),text:e=>t.push(ke(e))}),t}function he(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,u=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==u&&n.focus.set(s,Math.max(0,u-o),"text"),!0}const fe="javascript",pe=()=>fe;function de(e,t){for(const n of e.childNodes){if(d(n)&&n.tagName===t)return!0;if(de(n,t))return!0}return!1}const me="data-language",xe="data-highlight-language",_e="data-theme",Se=()=>{};class ye extends c{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new ye(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const t=document.createElement("code");a(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(me,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(xe,n));const r=this.getTheme();r&&t.setAttribute(_e,r);const i=this.getStyle();return i&&g(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(me,r):i&&t.removeAttribute(me);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(xe,r):t.removeAttribute(xe):o&&r&&t.setAttribute(xe,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(_e,s):l&&t.removeAttribute(_e);const u=this.__style,c=e.__style;return u!==c&&g(t.style,u,c),!1}exportDOM(e){const t=document.createElement("pre");a(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(me,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(xe,n));const r=this.getTheme();r&&t.setAttribute(_e,r);const i=this.getStyle();return i&&g(t.style,i),{element:t}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||de(e,"BR"))?{conversion:Ce,priority:1}:null,div:()=>({conversion:Ne,priority:1}),pre:()=>({conversion:Ce,priority:0}),table:e=>Pe(e)?{conversion:Te,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&Pe(n)?{conversion:Ae,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&Pe(t)?{conversion:Ae,priority:3}:null}}}static importJSON(e){return be().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,t=!0){if(!U(h(),"@lexical/code")){Se();const t=we(e);if(t)return t}const{anchor:r,focus:i}=e,l=(r.isBefore(i)?r:i).getNode();if(f(l)){let e=se(l);const t=[];for(;;)if(n(e))t.push(o()),e=e.getNextSibling();else{if(!Be(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(ke(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const i=l.splitText(r.offset)[0],u=0===r.offset?0:1,c=i.getIndexWithinParent()+u,a=l.getParentOrThrow(),g=[s(),...t];a.splice(c,0,g);const h=t[t.length-1];h?h.select():0===r.offset?i.selectPrevious():i.getNextSibling().selectNext(0,0)}if(ve(l)){const{offset:t}=e.anchor;l.splice(t,0,[s()]),l.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=p();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function be(e,t){return u(ye).setLanguage(e).setTheme(t)}function ve(e){return e instanceof ye}function Ce(e){return{node:be(e.getAttribute(me))}}function Ne(e){const t=e,n=Oe(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(Oe(t))return!0;t=t.parentElement}return!1}(t)?{node:n?be():null}:{node:null}}function Te(){return{node:be()}}function Ae(){return{node:null}}function Oe(e){return null!==e.style.fontFamily.match("monospace")}function Pe(e){return e.classList.contains("js-file-line-container")}function we(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(ve(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(r(t)&&r(t.getPreviousSibling())){const t=p();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class He extends x{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new He(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),n=De(e.theme,this.__highlightType);return a(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=De(n.theme,e.__highlightType),o=De(n.theme,this.__highlightType);return i!==o&&(i&&_(t,i),o&&a(t,o)),r}static importJSON(e){return ke().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return be()}}function De(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function ke(e="",t){return m(new He(e,t))}function Be(e){return e instanceof He}const Le=S({name:"@lexical/code",nodes:()=>[ye,He],register:e=>e.registerCommand(y,e=>{const t=b();return!(!v(t)||!we(t))&&(e.preventDefault(),!0)},C)}),$e="data-language";function Ee(e){return null!==e.style.fontFamily.match("monospace")}function Fe(e){let t=e.parentElement;for(;null!==t;){if(Ee(t))return!0;t=t.parentElement}return!1}const Me=te([Y({$import:(e,t)=>e.$importChildren(t),match:Z.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),Je=Y({$import:(e,t)=>[be(t.getAttribute($e)).splice(0,0,e.$importChildren(t))],match:Z.tag("pre"),name:"@lexical/code/pre"}),ze=Y({$import:(e,t,n)=>{const r=t.textContent||"";return/\r?\n/.test(r)||null!==t.querySelector("br")?[be(t.getAttribute($e)).splice(0,0,e.$importChildren(t))]:n()},match:Z.tag("code"),name:"@lexical/code/code-multiline"});function Ke(e){if(!d(e))return!1;const t=e.style.fontFamily,n=e.style.whiteSpace;return"string"==typeof t&&/monospace/i.test(t)&&"string"==typeof n&&n.startsWith("pre")}function Ie(e){let t=!1;const n=[];let r="",i=!1;const o=()=>{i&&(n.push(r),r="",i=!1)};for(const s of Array.from(e.childNodes))if(d(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),t=!0):"BR"===s.tagName?(o(),n.push(""),t=!0):(r+=s.textContent||"",i=!0);else if(A(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function je(e){for(const t of Array.from(e.children)){if(d(t)&&Ke(t)){if(null!==Ie(t))return!0;const e=t.nextElementSibling;if(e&&Ke(e))return!0;continue}if(je(t))return!0}return!1}const Re=te([Y({$import:(e,t,n)=>{if(!Ke(t)||Fe(t))return n();const r=Ie(t);return null===r||0===r.length?n():[be().splice(0,0,O(r.join("\n")))]},match:Z.tag("div"),name:"@lexical/code/vscode-wrapper"}),Y({$import:(e,t,n)=>{if(!Ke(t)||Fe(t))return n();const r=t.previousElementSibling;if(r&&Ke(r))return[];const i=[];let o=t;for(;o&&Ke(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[be().splice(0,0,O(i.join("\n")))]},match:Z.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),We=Y({$import:(e,t,n)=>Ee(t)?[be().splice(0,0,e.$importChildren(t))]:Fe(t)?e.$importChildren(t):n(),match:Z.tag("div"),name:"@lexical/code/div"}),qe=[Y({$import:(e,t)=>[be().splice(0,0,e.$importChildren(t,{rules:Me}))],match:Z.tag("table").classAll("js-file-line-container"),name:"@lexical/code/github-code-table"}),Y({$import:(e,t)=>e.$importChildren(t),match:Z.tag("td").classAll("js-file-line"),name:"@lexical/code/github-code-cell-by-class"}),ze,Je,We],Ue=S({dependencies:[Q,Le,N(X,{preprocess:[(e,t,n)=>{je(T(e)?e.body:e)&&t.session.update(ee,e=>[...e,Re]),n()}],rules:qe})],name:"@lexical/code/Import"});function Ve(e){if(!v(e))return!1;const t=e.anchor.getNode(),n=ve(t)?t:t.getParent(),r=e.focus.getNode(),i=ve(r)?r:r.getParent();return ve(n)&&n.is(i)}function Ge(e){const t=e.getNodes(),i=[];if(1===t.length&&ve(t[0]))return i;let o=[];for(let e=0;e<t.length;e++){const s=t[e];Be(s)||n(s)||r(s)||ie(169),r(s)?o.length>0&&(i.push(o),o=[]):o.push(s)}if(o.length>0){const t=e.isBackward()?e.anchor:e.focus,n=K(o[0].getKey(),0,"text");t.is(n)||i.push(o)}return i}function Qe(e,t){const r=b();if(!v(r)||!Ve(r))return!1;const i=Ge(r),u=i.length;if(0===u&&r.isCollapsed())return e===F&&r.insertNodes([o()]),!0;if(0===u&&e===F&&"\n"===r.getTextContent()){const e=o(),t=s(),n=r.isBackward()?"previous":"next";return r.insertNodes([e,t]),I(j(R(W(e,"next",0),q(l(t,"next"))),n)),!0}for(let s=0;s<u;s++){const l=i[s];if(l.length>0){let i=l[0];if(0===s&&(i=se(i)),e===F){const e=o();if(i.insertBefore(e),0===s){const t=r.isBackward()?"focus":"anchor",n=K(i.getKey(),0,"text");r[t].is(n)&&r[t].set(e.getKey(),0,"text")}}else n(i)?i.remove():void 0!==t&&Be(i)&&he(i,t,r)}}return!0}function Xe(e,t){const i=b();if(!v(i))return!1;const{anchor:o,focus:s}=i,l=o.offset,u=s.offset,c=o.getNode(),a=s.getNode(),g=e===k;if(!Ve(i)||!Be(c)&&!n(c)||!Be(a)&&!n(a))return!1;if(!t.altKey){if(i.isCollapsed()){const e=c.getParentOrThrow();if(g&&0===l&&null===c.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&l===c.getTextContentSize()&&null===c.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let h,f;if(c.isBefore(a)?(h=se(c),f=le(a)):(h=se(a),f=le(c)),null==h||null==f)return!1;const p=h.getNodesBetween(f);for(let e=0;e<p.length;e++){const t=p[e];if(!Be(t)&&!n(t)&&!r(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?h.getPreviousSibling():f.getNextSibling();if(!r(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=Be(m)||n(m)||r(m)?g?se(m):le(m):null;let _=null!=x?x:m;return d.remove(),p.forEach(e=>e.remove()),e===k?(p.forEach(e=>_.insertBefore(e)),_.insertBefore(d)):(_.insertAfter(d),_=d,p.forEach(e=>{_.insertAfter(e),_=e})),i.setTextNodeRange(c,l,a,u),!0}function Ye(e,t){const i=b();if(!v(i))return!1;const{anchor:o,focus:s}=i,l=o.getNode(),u=s.getNode(),c=e===J;if(!Ve(i)||!Be(l)&&!n(l)||!Be(u)&&!n(u))return!1;const a=u,g="rtl"===ue(a)?!c:c,h=o.key,f=o.offset,p=o.type;if(g){const e=ce(a,s.offset);if(null!==e){const{node:t,offset:n}=e;r(t)?t.selectNext(0,0):i.setTextNodeRange(t,n,t,n)}else a.getParentOrThrow().selectStart()}else{ae(a).select()}return t.shiftKey&&i.anchor.set(h,f,p),t.preventDefault(),t.stopPropagation(),!0}function Ze(e,t,n){return w(...n?[e.registerCommand(H,e=>!e.altKey&&ne(ve),C),e.registerCommand(D,()=>ne(ve),C),e.registerCommand(k,e=>!e.altKey&&re(ve),C),e.registerCommand(B,()=>re(ve),C)]:[],e.registerCommand(L,t=>{const n=function(e){const t=b();if(!v(t)||!Ve(t))return null;const n=e?M:F,r=e?M:$,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Ge(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&ie(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=se(l[0]),g=le(l[0]),h=K(a.getKey(),0,"text"),f=K(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(h)||f.isBefore(c)?n:h.isBefore(u)||c.isBefore(f)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n,void 0),!0)},C),e.registerCommand($,()=>!!Ve(b())&&(E([o()]),!0),C),e.registerCommand(F,()=>Qe(F),C),e.registerCommand(M,()=>Qe(M,t),C),e.registerCommand(k,e=>{const t=b();if(!v(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Ve(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&ve(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):Xe(k,e)},C),e.registerCommand(H,e=>{const t=b();if(!v(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Ve(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&ve(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Xe(H,e))},C),e.registerCommand(J,e=>Ye(J,e),C),e.registerCommand(z,e=>Ye(z,e),C))}const et=S({build:(e,t)=>G(t),config:P({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[Le],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return V(()=>{if(!r.disabled.value)return Ze(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{ke as $createCodeHighlightNode,be as $createCodeNode,ue as $getCodeLineDirection,ae as $getEndOfCodeInLine,se as $getFirstCodeNodeOfLine,le as $getLastCodeNodeOfLine,ce as $getStartOfCodeInLine,Be as $isCodeHighlightNode,ve as $isCodeNode,he as $outdentLeadingSpaces,ge as $plainifyCodeContent,Le as CodeExtension,He as CodeHighlightNode,Ue as CodeImportExtension,qe as CodeImportRules,et as CodeIndentExtension,ye as CodeNode,fe as DEFAULT_CODE_LANGUAGE,pe as getDefaultCodeLanguage,Ze as registerCodeIndentation};
|
|
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 h,$getSiblingCaret as f,$create as p,ElementNode as d,addClassNamesToElement as m,setDOMStyleFromCSS as x,$getEditor as _,$isTextNode as S,$createParagraphNode as y,isHTMLElement as b,$applyNodeReplacement as v,TextNode as C,removeClassNamesFromElement as N,isDOMDocumentNode as T,isDOMTextNode as A,$generateNodesFromRawText as O,defineExtension as P,KEY_ENTER_COMMAND as w,$getSelection as H,$isRangeSelection as D,COMMAND_PRIORITY_LOW as k,configExtension as B,safeCast as L,mergeRegister as $,KEY_ARROW_DOWN_COMMAND as E,KEY_ARROW_RIGHT_COMMAND as F,KEY_ARROW_UP_COMMAND as M,KEY_ARROW_LEFT_COMMAND as J,KEY_TAB_COMMAND as z,INSERT_TAB_COMMAND as K,$insertNodes as I,INDENT_CONTENT_COMMAND as j,OUTDENT_CONTENT_COMMAND as R,MOVE_TO_START as W,MOVE_TO_END as q,$createPoint as U,$setSelectionFromCaretRange as V,$getCaretRangeInDirection as G,$getCaretRange as Q,$getTextPointCaret as X,$normalizeCaret as Y}from"lexical";import{getPeerDependencyFromEditor as Z,effect as ee,namedSignals as te}from"@lexical/extension";import{$onEscapeDown as ne,$onEscapeUp as re}from"@lexical/utils";
|
|
10
|
+
/*@__INLINE__*/function ie(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function oe(e,t){let n=e;for(let r=f(e,t);r&&(Be(r.origin)||u(r.origin));r=r.getAdjacentCaret())n=r.origin;return n}function se(e){return oe(e,"previous")}function le(e){return oe(e,"next")}function ue(e){const t=se(e),n=le(e);let r=t;for(;null!==r;){if(Be(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 ce(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(Be(e)||u(e)||c(e)||ie(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];Be(i)&&" "!==e&&(r={node:i,offset:o})}if(null!==r)return r;let l=null;if(t<e.getTextContentSize())Be(e)&&(l=e.getTextContent()[t]);else{const t=e.getNextSibling();Be(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(!Be(n)||r===o){if(n=n.getNextSibling(),null===n||c(n))return null;Be(n)&&(r=0,i=n.getTextContent(),o=n.getTextContentSize())}if(Be(n)){if(" "!==i[r])return{node:n,offset:r};r++}}}(e,t);return null!==r?r:n}}function ae(e){const t=le(e);return c(t)&&ie(168),t}function ge(e){const t=[];return a(e,{linebreak:()=>t.push(h()),tab:()=>t.push(g()),text:e=>t.push(ke(e))}),t}function he(e,t,n){if(!Number.isInteger(t)||t<=0)return!1;const r=e.getTextContent(),i=/^ +/.exec(r);if(!i)return!1;const o=Math.min(t,i[0].length),s=e.getKey(),l=n.anchor.key===s&&"text"===n.anchor.type?n.anchor.offset:null,u=n.focus.key===s&&"text"===n.focus.type?n.focus.offset:null;return e.spliceText(0,o,""),null!==l&&n.anchor.set(s,Math.max(0,l-o),"text"),null!==u&&n.focus.set(s,Math.max(0,u-o),"text"),!0}const fe="javascript",pe=()=>fe;function de(e,t){for(const n of e.childNodes){if(b(n)&&n.tagName===t)return!0;if(de(n,t))return!0}return!1}const me="data-language",xe="data-highlight-language",_e="data-theme",Se=()=>{};class ye extends d{__language;__theme;__isSyntaxHighlightSupported;static getType(){return"code"}static clone(e){return new ye(e.__language,e.__key)}constructor(e,t){super(t),this.__language=e||void 0,this.__isSyntaxHighlightSupported=!1,this.__theme=void 0}afterCloneFrom(e){super.afterCloneFrom(e),this.__language=e.__language,this.__theme=e.__theme,this.__isSyntaxHighlightSupported=e.__isSyntaxHighlightSupported}createDOM(e){const t=document.createElement("code");m(t,e.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(me,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(xe,n));const r=this.getTheme();r&&t.setAttribute(_e,r);const i=this.getStyle();return i&&x(t.style,i),t}updateDOM(e,t,n){const r=this.__language,i=e.__language;r?r!==i&&t.setAttribute(me,r):i&&t.removeAttribute(me);const o=this.__isSyntaxHighlightSupported;e.__isSyntaxHighlightSupported&&i?o&&r?r!==i&&t.setAttribute(xe,r):t.removeAttribute(xe):o&&r&&t.setAttribute(xe,r);const s=this.__theme,l=e.__theme;s?s!==l&&t.setAttribute(_e,s):l&&t.removeAttribute(_e);const u=this.__style,c=e.__style;return u!==c&&x(t.style,u,c),!1}exportDOM(e){const t=document.createElement("pre");m(t,e._config.theme.code),t.setAttribute("spellcheck","false");const n=this.getLanguage();n&&(t.setAttribute(me,n),this.getIsSyntaxHighlightSupported()&&t.setAttribute(xe,n));const r=this.getTheme();r&&t.setAttribute(_e,r);const i=this.getStyle();return i&&x(t.style,i),{element:t}}static importDOM(){return{code:e=>null!=e.textContent&&(/\r?\n/.test(e.textContent)||de(e,"BR"))?{conversion:Ce,priority:1}:null,div:()=>({conversion:Ne,priority:1}),pre:()=>({conversion:Ce,priority:0}),table:e=>Pe(e)?{conversion:Te,priority:3}:null,td:e=>{const t=e,n=t.closest("table");return t.classList.contains("js-file-line")||n&&Pe(n)?{conversion:Ae,priority:3}:null},tr:e=>{const t=e.closest("table");return t&&Pe(t)?{conversion:Ae,priority:3}:null}}}static importJSON(e){return be().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setLanguage(e.language).setTheme(e.theme)}exportJSON(){return{...super.exportJSON(),language:this.getLanguage(),theme:this.getTheme()}}insertNewAfter(e,t=!0){if(!Z(_(),"@lexical/code")){Se();const t=we(e);if(t)return t}const{anchor:n,focus:r}=e,i=(n.isBefore(r)?n:r).getNode();if(S(i)){let e=se(i);const t=[];for(;;)if(u(e))t.push(g()),e=e.getNextSibling();else{if(!Be(e))break;{let n=0;const r=e.getTextContent(),i=e.getTextContentSize();for(;n<i&&" "===r[n];)n++;if(0!==n&&t.push(ke(" ".repeat(n))),n!==i)break;e=e.getNextSibling()}}const r=i.splitText(n.offset)[0],o=0===n.offset?0:1,s=r.getIndexWithinParent()+o,l=i.getParentOrThrow(),c=[h(),...t];l.splice(s,0,c);const a=t[t.length-1];a?a.select():0===n.offset?r.selectPrevious():r.getNextSibling().selectNext(0,0)}if(ve(i)){const{offset:t}=e.anchor;i.splice(t,0,[h()]),i.select(t+1,t+1)}return null}canIndent(){return!1}collapseAtStart(){const e=y();return this.getChildren().forEach(t=>e.append(t)),this.replace(e),!0}setLanguage(e){const t=this.getWritable();return t.__language=e||void 0,t}getLanguage(){return this.getLatest().__language}setIsSyntaxHighlightSupported(e){const t=this.getWritable();return t.__isSyntaxHighlightSupported=e,t}getIsSyntaxHighlightSupported(){return this.getLatest().__isSyntaxHighlightSupported}setTheme(e){const t=this.getWritable();return t.__theme=e||void 0,t}getTheme(){return this.getLatest().__theme}}function be(e,t){return p(ye).setLanguage(e).setTheme(t)}function ve(e){return e instanceof ye}function Ce(e){return{node:be(e.getAttribute(me))}}function Ne(e){const t=e,n=Oe(t);return n||function(e){let t=e.parentElement;for(;null!==t;){if(Oe(t))return!0;t=t.parentElement}return!1}(t)?{node:n?be():null}:{node:null}}function Te(){return{node:be()}}function Ae(){return{node:null}}function Oe(e){return null!==e.style.fontFamily.match("monospace")}function Pe(e){return e.classList.contains("js-file-line-container")}function we(e){const{anchor:t}=e;if(e.isCollapsed()&&"element"===t.type){const e=t.getNode();if(ve(e)){const n=e.getChildrenSize();if(n>=2&&t.offset===n){const t=e.getLastChild();if(c(t)&&c(t.getPreviousSibling())){const t=y();return e.splice(n-2,2,[]).insertAfter(t,!1),t.select(),t}}}}return null}class He extends C{__highlightType;constructor(e="",t,n){super(e,n),this.__highlightType=t}static getType(){return"code-highlight"}static clone(e){return new He(e.__text,e.__highlightType||void 0,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__highlightType=e.__highlightType}getHighlightType(){return this.getLatest().__highlightType}setHighlightType(e){const t=this.getWritable();return t.__highlightType=e||void 0,t}canHaveFormat(){return!1}createDOM(e){const t=super.createDOM(e),n=De(e.theme,this.__highlightType);return m(t,n),t}updateDOM(e,t,n){const r=super.updateDOM(e,t,n),i=De(n.theme,e.__highlightType),o=De(n.theme,this.__highlightType);return i!==o&&(i&&N(t,i),o&&m(t,o)),r}static importJSON(e){return ke().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHighlightType(e.highlightType)}exportJSON(){return{...super.exportJSON(),highlightType:this.getHighlightType()}}setFormat(e){return this}isParentRequired(){return!0}createParentElementNode(){return be()}}function De(e,t){return t&&e&&e.codeHighlight&&e.codeHighlight[t]}function ke(e="",t){return v(new He(e,t))}function Be(e){return e instanceof He}const Le="data-language";function $e(e){return null!==e.style.fontFamily.match("monospace")}function Ee(e){let t=e.parentElement;for(;null!==t;){if($e(t))return!0;t=t.parentElement}return!1}const Fe=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t)=>e.$importChildren(t),match:t.tag("tr","td"),name:"@lexical/code/github-code-table/unwrap"})]),Me=/* @__PURE__ */e({$import:(e,t)=>[be(t.getAttribute(Le)).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")?[be(t.getAttribute(Le)).splice(0,0,e.$importChildren(t))]:n()},match:t.tag("code"),name:"@lexical/code/code-multiline"});function ze(e){if(!b(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 Ke(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(b(s))"DIV"===s.tagName?(o(),n.push(s.textContent||""),t=!0):"BR"===s.tagName?(o(),n.push(""),t=!0):(r+=s.textContent||"",i=!0);else if(A(s)){const e=s.textContent||"";e.length>0&&(r+=e,i=!0)}return o(),t?n:null}function Ie(e){for(const t of Array.from(e.children)){if(b(t)&&ze(t)){if(null!==Ke(t))return!0;const e=t.nextElementSibling;if(e&&ze(e))return!0;continue}if(Ie(t))return!0}return!1}const je=/* @__PURE__ */r([/* @__PURE__ */e({$import:(e,t,n)=>{if(!ze(t)||Ee(t))return n();const r=Ke(t);return null===r||0===r.length?n():[be().splice(0,0,O(r.join("\n")))]},match:t.tag("div"),name:"@lexical/code/vscode-wrapper"}),/* @__PURE__ */e({$import:(e,t,n)=>{if(!ze(t)||Ee(t))return n();const r=t.previousElementSibling;if(r&&ze(r))return[];const i=[];let o=t;for(;o&&ze(o);)i.push("BR"===o.tagName?"":o.textContent||""),o=o.nextElementSibling;return i.length<2?n():[be().splice(0,0,O(i.join("\n")))]},match:t.tag("div","br"),name:"@lexical/code/vscode-line-run"})]),Re=/* @__PURE__ */e({$import:(e,t,n)=>$e(t)?[be().splice(0,0,e.$importChildren(t))]:Ee(t)?e.$importChildren(t):n(),match:t.tag("div"),name:"@lexical/code/div"}),We=[/* @__PURE__ */e({$import:(e,t)=>[be().splice(0,0,e.$importChildren(t,{rules:Fe}))],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,Me,Re],qe=/* @__PURE__ */P({dependencies:[i,/* @__PURE__ */B(o,{preprocess:[(e,t,r)=>{Ie(T(e)?e.body:e)&&t.session.update(n,e=>[...e,je]),r()}],rules:We})],name:"@lexical/code",nodes:()=>[ye,He],register:e=>e.registerCommand(w,e=>{const t=H();return!(!D(t)||!we(t))&&(e.preventDefault(),!0)},k)}),Ue=/* @__PURE__ */P({dependencies:[qe],name:"@lexical/code/Import"});function Ve(e){if(!D(e))return!1;const t=e.anchor.getNode(),n=ve(t)?t:t.getParent(),r=e.focus.getNode(),i=ve(r)?r:r.getParent();return ve(n)&&n.is(i)}function Ge(e){const t=e.getNodes(),n=[];if(1===t.length&&ve(t[0]))return n;let r=[];for(let e=0;e<t.length;e++){const i=t[e];Be(i)||u(i)||c(i)||ie(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=U(r[0].getKey(),0,"text");t.is(i)||n.push(r)}return n}function Qe(e,t){const n=H();if(!D(n)||!Ve(n))return!1;const r=Ge(n),i=r.length;if(0===i&&n.isCollapsed())return e===j&&n.insertNodes([g()]),!0;if(0===i&&e===j&&"\n"===n.getTextContent()){const e=g(),t=h(),r=n.isBackward()?"previous":"next";return n.insertNodes([e,t]),V(G(Q(X(e,"next",0),Y(f(t,"next"))),r)),!0}for(let o=0;o<i;o++){const i=r[o];if(i.length>0){let r=i[0];if(0===o&&(r=se(r)),e===j){const e=g();if(r.insertBefore(e),0===o){const t=n.isBackward()?"focus":"anchor",i=U(r.getKey(),0,"text");n[t].is(i)&&n[t].set(e.getKey(),0,"text")}}else u(r)?r.remove():void 0!==t&&Be(r)&&he(r,t,n)}}return!0}function Xe(e,t){const n=H();if(!D(n))return!1;const{anchor:r,focus:i}=n,o=r.offset,s=i.offset,l=r.getNode(),a=i.getNode(),g=e===M;if(!Ve(n)||!Be(l)&&!u(l)||!Be(a)&&!u(a))return!1;if(!t.altKey){if(n.isCollapsed()){const e=l.getParentOrThrow();if(g&&0===o&&null===l.getPreviousSibling()){if(null===e.getPreviousSibling())return e.selectPrevious(),t.preventDefault(),!1}else if(!g&&o===l.getTextContentSize()&&null===l.getNextSibling()){if(null===e.getNextSibling())return e.selectNext(),t.preventDefault(),!1}}return!1}let h,f;if(l.isBefore(a)?(h=se(l),f=le(a)):(h=se(a),f=le(l)),null==h||null==f)return!1;const p=h.getNodesBetween(f);for(let e=0;e<p.length;e++){const t=p[e];if(!Be(t)&&!u(t)&&!c(t))return!1}t.preventDefault(),t.stopPropagation();const d=g?h.getPreviousSibling():f.getNextSibling();if(!c(d))return!0;const m=g?d.getPreviousSibling():d.getNextSibling();if(null==m)return!0;const x=Be(m)||u(m)||c(m)?g?se(m):le(m):null;let _=null!=x?x:m;return d.remove(),p.forEach(e=>e.remove()),e===M?(p.forEach(e=>_.insertBefore(e)),_.insertBefore(d)):(_.insertAfter(d),_=d,p.forEach(e=>{_.insertAfter(e),_=e})),n.setTextNodeRange(l,o,a,s),!0}function Ye(e,t){const n=H();if(!D(n))return!1;const{anchor:r,focus:i}=n,o=r.getNode(),s=i.getNode(),l=e===W;if(!Ve(n)||!Be(o)&&!u(o)||!Be(s)&&!u(s))return!1;const a=s,g="rtl"===ue(a)?!l:l,h=r.key,f=r.offset,p=r.type;if(g){const e=ce(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{ae(a).select()}return t.shiftKey&&n.anchor.set(h,f,p),t.preventDefault(),t.stopPropagation(),!0}function Ze(e,t,n){return $(...n?[e.registerCommand(E,e=>!e.altKey&&ne(ve),k),e.registerCommand(F,()=>ne(ve),k),e.registerCommand(M,e=>!e.altKey&&re(ve),k),e.registerCommand(J,()=>re(ve),k)]:[],e.registerCommand(z,t=>{const n=function(e){const t=H();if(!D(t)||!Ve(t))return null;const n=e?R:j,r=e?R:K,i=t.anchor,o=t.focus;if(i.is(o))return r;const s=Ge(t);if(1!==s.length)return n;const l=s[0];let u,c;0===l.length&&ie(285),t.isBackward()?(u=o,c=i):(u=i,c=o);const a=se(l[0]),g=le(l[0]),h=U(a.getKey(),0,"text"),f=U(g.getKey(),g.getTextContentSize(),"text");return u.isBefore(h)||f.isBefore(c)?n:h.isBefore(u)||c.isBefore(f)?r:n}(t.shiftKey);return null!==n&&(t.preventDefault(),e.dispatchCommand(n,void 0),!0)},k),e.registerCommand(K,()=>!!Ve(H())&&(I([g()]),!0),k),e.registerCommand(j,()=>Qe(j),k),e.registerCommand(R,()=>Qe(R,t),k),e.registerCommand(M,e=>{const t=H();if(!D(t))return!1;const{anchor:n}=t,r=n.getNode();if(!Ve(t))return!1;const i=r.getParent();return t.isCollapsed()&&0===n.offset&&null===r.getPreviousSibling()&&ve(i)&&null===i.getPreviousSibling()?(e.preventDefault(),!0):Xe(M,e)},k),e.registerCommand(E,e=>{const t=H();if(!D(t))return!1;const{anchor:n}=t,r=n.getNode();return!!Ve(t)&&(t.isCollapsed()&&n.offset===r.getTextContentSize()&&null===r.getNextSibling()&&ve(r.getParentOrThrow())&&null===r.getParentOrThrow().getNextSibling()?(e.preventDefault(),!0):Xe(E,e))},k),e.registerCommand(W,e=>Ye(W,e),k),e.registerCommand(q,e=>Ye(q,e),k))}const et=/* @__PURE__ */P({build:(e,t)=>te(t),config:/* @__PURE__ */L({disabled:!1,escapeWithArrows:!1,tabSize:void 0}),dependencies:[qe],name:"@lexical/code-indent",register:(e,t,n)=>{const r=n.getOutput();return ee(()=>{if(!r.disabled.value)return Ze(e,r.tabSize.value,r.escapeWithArrows.value)})}});export{ke as $createCodeHighlightNode,be as $createCodeNode,ue as $getCodeLineDirection,ae as $getEndOfCodeInLine,se as $getFirstCodeNodeOfLine,le as $getLastCodeNodeOfLine,ce as $getStartOfCodeInLine,Be as $isCodeHighlightNode,ve as $isCodeNode,he as $outdentLeadingSpaces,ge as $plainifyCodeContent,qe as CodeExtension,He as CodeHighlightNode,Ue as CodeImportExtension,We as CodeImportRules,et as CodeIndentExtension,ye as CodeNode,fe as DEFAULT_CODE_LANGUAGE,pe as getDefaultCodeLanguage,Ze as registerCodeIndentation};
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
export { CodeExtension } from './CodeExtension';
|
|
8
|
+
export { CodeExtension, CodeImportExtension } from './CodeExtension';
|
|
9
9
|
export { $createCodeHighlightNode, $isCodeHighlightNode, CodeHighlightNode, } from './CodeHighlightNode';
|
|
10
|
-
export {
|
|
10
|
+
export { CodeImportRules } from './CodeImportExtension';
|
|
11
11
|
export { type CodeIndentConfig, CodeIndentExtension, registerCodeIndentation, } from './CodeIndentation';
|
|
12
12
|
export type { SerializedCodeNode } from './CodeNode';
|
|
13
13
|
export { $createCodeNode, $isCodeNode, CodeNode, DEFAULT_CODE_LANGUAGE, getDefaultCodeLanguage, } from './CodeNode';
|
package/package.json
CHANGED
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"code"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.45.1-nightly.
|
|
11
|
+
"version": "0.45.1-nightly.20260611.0",
|
|
12
12
|
"main": "./dist/LexicalCodeCore.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/extension": "0.45.1-nightly.
|
|
16
|
-
"@lexical/html": "0.45.1-nightly.
|
|
17
|
-
"@lexical/utils": "0.45.1-nightly.
|
|
18
|
-
"lexical": "0.45.1-nightly.
|
|
19
|
-
"@lexical/internal": "0.45.1-nightly.
|
|
15
|
+
"@lexical/extension": "0.45.1-nightly.20260611.0",
|
|
16
|
+
"@lexical/html": "0.45.1-nightly.20260611.0",
|
|
17
|
+
"@lexical/utils": "0.45.1-nightly.20260611.0",
|
|
18
|
+
"lexical": "0.45.1-nightly.20260611.0",
|
|
19
|
+
"@lexical/internal": "0.45.1-nightly.20260611.0"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
package/src/CodeExtension.ts
CHANGED
|
@@ -6,21 +6,37 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import {CoreImportExtension, DOMImportExtension} from '@lexical/html';
|
|
9
10
|
import {
|
|
10
11
|
$getSelection,
|
|
11
12
|
$isRangeSelection,
|
|
12
13
|
COMMAND_PRIORITY_LOW,
|
|
14
|
+
configExtension,
|
|
13
15
|
defineExtension,
|
|
14
16
|
KEY_ENTER_COMMAND,
|
|
15
17
|
} from 'lexical';
|
|
16
18
|
|
|
17
19
|
import {CodeHighlightNode} from './CodeHighlightNode';
|
|
20
|
+
import {
|
|
21
|
+
$installVscodeCodePasteOverlay,
|
|
22
|
+
CodeImportRules,
|
|
23
|
+
} from './CodeImportExtension';
|
|
18
24
|
import {$exitCodeNodeOnEnter, CodeNode} from './CodeNode';
|
|
19
25
|
|
|
20
26
|
/**
|
|
21
27
|
* Add code blocks to the editor (syntax highlighting provided separately)
|
|
22
28
|
*/
|
|
23
|
-
export const CodeExtension = defineExtension({
|
|
29
|
+
export const CodeExtension = /* @__PURE__ */ defineExtension({
|
|
30
|
+
dependencies: [
|
|
31
|
+
// DOMImportExtension support for the nodes registered here. Inert
|
|
32
|
+
// unless the editor routes HTML through the pipeline (e.g. via
|
|
33
|
+
// ClipboardDOMImportExtension or $generateNodesFromDOMViaExtension).
|
|
34
|
+
CoreImportExtension,
|
|
35
|
+
/* @__PURE__ */ configExtension(DOMImportExtension, {
|
|
36
|
+
preprocess: [$installVscodeCodePasteOverlay],
|
|
37
|
+
rules: CodeImportRules,
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
24
40
|
name: '@lexical/code',
|
|
25
41
|
nodes: () => [CodeNode, CodeHighlightNode],
|
|
26
42
|
register(editor) {
|
|
@@ -38,3 +54,17 @@ export const CodeExtension = defineExtension({
|
|
|
38
54
|
);
|
|
39
55
|
},
|
|
40
56
|
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Bundles {@link CodeImportRules} together with the runtime
|
|
60
|
+
* {@link CodeExtension}.
|
|
61
|
+
*
|
|
62
|
+
* @experimental
|
|
63
|
+
* @deprecated {@link CodeExtension} now registers
|
|
64
|
+
* {@link CodeImportRules} (and `CoreImportExtension`) itself — depend on
|
|
65
|
+
* it directly instead.
|
|
66
|
+
*/
|
|
67
|
+
export const CodeImportExtension = /* @__PURE__ */ defineExtension({
|
|
68
|
+
dependencies: [CodeExtension],
|
|
69
|
+
name: '@lexical/code/Import',
|
|
70
|
+
});
|
|
@@ -9,23 +9,18 @@
|
|
|
9
9
|
import type {DOMPreprocessFn} from '@lexical/html';
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
-
CoreImportExtension,
|
|
13
12
|
defineImportRule,
|
|
14
13
|
defineOverlayRules,
|
|
15
|
-
DOMImportExtension,
|
|
16
14
|
ImportOverlays,
|
|
17
15
|
sel,
|
|
18
16
|
} from '@lexical/html';
|
|
19
17
|
import {
|
|
20
18
|
$generateNodesFromRawText,
|
|
21
|
-
configExtension,
|
|
22
|
-
defineExtension,
|
|
23
19
|
isDOMDocumentNode,
|
|
24
20
|
isDOMTextNode,
|
|
25
21
|
isHTMLElement,
|
|
26
22
|
} from 'lexical';
|
|
27
23
|
|
|
28
|
-
import {CodeExtension} from './CodeExtension';
|
|
29
24
|
import {$createCodeNode} from './CodeNode';
|
|
30
25
|
|
|
31
26
|
const LANGUAGE_DATA_ATTRIBUTE = 'data-language';
|
|
@@ -59,15 +54,15 @@ function isMonospaceDescendant(node: HTMLElement): boolean {
|
|
|
59
54
|
* the cost of these rules is never paid against unrelated `<tr>` /
|
|
60
55
|
* `<td>` pastes.
|
|
61
56
|
*/
|
|
62
|
-
const GitHubCodeTableOverlayRules = defineOverlayRules([
|
|
63
|
-
defineImportRule({
|
|
57
|
+
const GitHubCodeTableOverlayRules = /* @__PURE__ */ defineOverlayRules([
|
|
58
|
+
/* @__PURE__ */ defineImportRule({
|
|
64
59
|
$import: (ctx, el) => ctx.$importChildren(el),
|
|
65
60
|
match: sel.tag('tr', 'td'),
|
|
66
61
|
name: '@lexical/code/github-code-table/unwrap',
|
|
67
62
|
}),
|
|
68
63
|
]);
|
|
69
64
|
|
|
70
|
-
const PreRule = defineImportRule({
|
|
65
|
+
const PreRule = /* @__PURE__ */ defineImportRule({
|
|
71
66
|
$import: (ctx, el) => [
|
|
72
67
|
$createCodeNode(el.getAttribute(LANGUAGE_DATA_ATTRIBUTE)).splice(
|
|
73
68
|
0,
|
|
@@ -85,7 +80,7 @@ const PreRule = defineImportRule({
|
|
|
85
80
|
* defers to the inline-format rule from `CoreImportExtension` so it
|
|
86
81
|
* becomes a TextNode with IS_CODE.
|
|
87
82
|
*/
|
|
88
|
-
const MultilineCodeRule = defineImportRule({
|
|
83
|
+
const MultilineCodeRule = /* @__PURE__ */ defineImportRule({
|
|
89
84
|
$import: (ctx, el, $next) => {
|
|
90
85
|
const text = el.textContent || '';
|
|
91
86
|
const isMultiLine = /\r?\n/.test(text) || el.querySelector('br') !== null;
|
|
@@ -211,7 +206,7 @@ function looksLikeVscodePaste(root: ParentNode): boolean {
|
|
|
211
206
|
* around per-line `<div>`s and `<br>`s. Emits a single CodeNode whose
|
|
212
207
|
* text is the wrapper's lines joined by `\n`.
|
|
213
208
|
*/
|
|
214
|
-
const VscodeWrapperRule = defineImportRule({
|
|
209
|
+
const VscodeWrapperRule = /* @__PURE__ */ defineImportRule({
|
|
215
210
|
$import: (_ctx, el, $next) => {
|
|
216
211
|
if (!isMonospacePreElement(el) || isMonospaceDescendant(el)) {
|
|
217
212
|
return $next();
|
|
@@ -239,7 +234,7 @@ const VscodeWrapperRule = defineImportRule({
|
|
|
239
234
|
* subsequent sibling in the same run, the prev-sibling check below
|
|
240
235
|
* returns `[]` so the run is only emitted once.
|
|
241
236
|
*/
|
|
242
|
-
const VscodeLineRunRule = defineImportRule({
|
|
237
|
+
const VscodeLineRunRule = /* @__PURE__ */ defineImportRule({
|
|
243
238
|
$import: (_ctx, el, $next) => {
|
|
244
239
|
if (!isMonospacePreElement(el) || isMonospaceDescendant(el)) {
|
|
245
240
|
return $next();
|
|
@@ -270,7 +265,7 @@ const VscodeLineRunRule = defineImportRule({
|
|
|
270
265
|
name: '@lexical/code/vscode-line-run',
|
|
271
266
|
});
|
|
272
267
|
|
|
273
|
-
const VscodeCodePasteOverlay = defineOverlayRules([
|
|
268
|
+
const VscodeCodePasteOverlay = /* @__PURE__ */ defineOverlayRules([
|
|
274
269
|
VscodeWrapperRule,
|
|
275
270
|
VscodeLineRunRule,
|
|
276
271
|
]);
|
|
@@ -318,7 +313,7 @@ export const $installVscodeCodePasteOverlay: DOMPreprocessFn = (
|
|
|
318
313
|
* wrapper just unwrap so their text content flows into the surrounding
|
|
319
314
|
* CodeNode.
|
|
320
315
|
*/
|
|
321
|
-
const DivRule = defineImportRule({
|
|
316
|
+
const DivRule = /* @__PURE__ */ defineImportRule({
|
|
322
317
|
$import: (ctx, el, $next) => {
|
|
323
318
|
if (isMonospaceElement(el)) {
|
|
324
319
|
return [$createCodeNode().splice(0, 0, ctx.$importChildren(el))];
|
|
@@ -340,7 +335,7 @@ const DivRule = defineImportRule({
|
|
|
340
335
|
* subtree unwrap unconditionally — without paying the predicate cost
|
|
341
336
|
* on every other `<tr>` / `<td>` paste elsewhere.
|
|
342
337
|
*/
|
|
343
|
-
const GitHubCodeTableRule = defineImportRule({
|
|
338
|
+
const GitHubCodeTableRule = /* @__PURE__ */ defineImportRule({
|
|
344
339
|
$import: (ctx, el) => [
|
|
345
340
|
$createCodeNode().splice(
|
|
346
341
|
0,
|
|
@@ -358,7 +353,7 @@ const GitHubCodeTableRule = defineImportRule({
|
|
|
358
353
|
* descendant text flows up into whatever context the cell is in. The
|
|
359
354
|
* class is part of the selector itself, so no runtime guard.
|
|
360
355
|
*/
|
|
361
|
-
const GitHubCodeCellByClassRule = defineImportRule({
|
|
356
|
+
const GitHubCodeCellByClassRule = /* @__PURE__ */ defineImportRule({
|
|
362
357
|
$import: (ctx, el) => ctx.$importChildren(el),
|
|
363
358
|
match: sel.tag('td').classAll('js-file-line'),
|
|
364
359
|
name: '@lexical/code/github-code-cell-by-class',
|
|
@@ -371,6 +366,12 @@ const GitHubCodeCellByClassRule = defineImportRule({
|
|
|
371
366
|
* registered before the generic `<table>` / `<tr>` / `<td>` rules so
|
|
372
367
|
* they win dispatch.
|
|
373
368
|
*
|
|
369
|
+
* Registered by {@link CodeExtension} itself (together with
|
|
370
|
+
* `CoreImportExtension` and the {@link $installVscodeCodePasteOverlay}
|
|
371
|
+
* preprocess), so any editor that uses the code extension can import
|
|
372
|
+
* these shapes through the `DOMImportExtension` pipeline without further
|
|
373
|
+
* configuration.
|
|
374
|
+
*
|
|
374
375
|
* @experimental
|
|
375
376
|
*/
|
|
376
377
|
export const CodeImportRules = [
|
|
@@ -381,23 +382,3 @@ export const CodeImportRules = [
|
|
|
381
382
|
PreRule,
|
|
382
383
|
DivRule,
|
|
383
384
|
];
|
|
384
|
-
|
|
385
|
-
/**
|
|
386
|
-
* Bundles {@link CodeImportRules} (plus {@link CoreImportExtension}) into
|
|
387
|
-
* a single dependency. The legacy {@link CodeNode.importDOM} continues to
|
|
388
|
-
* work in parallel; depend on this extension to opt into the new
|
|
389
|
-
* pipeline.
|
|
390
|
-
*
|
|
391
|
-
* @experimental
|
|
392
|
-
*/
|
|
393
|
-
export const CodeImportExtension = defineExtension({
|
|
394
|
-
dependencies: [
|
|
395
|
-
CoreImportExtension,
|
|
396
|
-
CodeExtension,
|
|
397
|
-
configExtension(DOMImportExtension, {
|
|
398
|
-
preprocess: [$installVscodeCodePasteOverlay],
|
|
399
|
-
rules: CodeImportRules,
|
|
400
|
-
}),
|
|
401
|
-
],
|
|
402
|
-
name: '@lexical/code/Import',
|
|
403
|
-
});
|
package/src/CodeIndentation.ts
CHANGED
|
@@ -677,9 +677,9 @@ export interface CodeIndentConfig {
|
|
|
677
677
|
* Code blocks without syntax highlighting can use this extension on its
|
|
678
678
|
* own.
|
|
679
679
|
*/
|
|
680
|
-
export const CodeIndentExtension = defineExtension({
|
|
680
|
+
export const CodeIndentExtension = /* @__PURE__ */ defineExtension({
|
|
681
681
|
build: (editor, config) => namedSignals(config),
|
|
682
|
-
config: safeCast<CodeIndentConfig>({
|
|
682
|
+
config: /* @__PURE__ */ safeCast<CodeIndentConfig>({
|
|
683
683
|
disabled: false,
|
|
684
684
|
escapeWithArrows: false,
|
|
685
685
|
tabSize: undefined,
|
package/src/index.ts
CHANGED
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
export {CodeExtension} from './CodeExtension';
|
|
9
|
+
export {CodeExtension, CodeImportExtension} from './CodeExtension';
|
|
10
10
|
export {
|
|
11
11
|
$createCodeHighlightNode,
|
|
12
12
|
$isCodeHighlightNode,
|
|
13
13
|
CodeHighlightNode,
|
|
14
14
|
} from './CodeHighlightNode';
|
|
15
|
-
export {
|
|
15
|
+
export {CodeImportRules} from './CodeImportExtension';
|
|
16
16
|
export {
|
|
17
17
|
type CodeIndentConfig,
|
|
18
18
|
CodeIndentExtension,
|