onchain-lexical-instance 0.0.14 → 0.0.16
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/OnchainLexicalInstance.js +468 -214
- package/dist/OnchainLexicalInstance.mjs +468 -224
- package/package.json +6 -5
- package/src/base.ts +48 -0
- package/src/code/codeHighlighter.ts +35 -35
- package/src/collapsible/index.ts +1 -1
- package/src/const.ts +11 -6
- package/src/equation/EquationComponent.tsx +24 -17
- package/src/equation/index.tsx +173 -172
- package/src/index.ts +10 -4
- package/src/instancePlugin.ts +606 -465
- package/src/internalLink/index.tsx +118 -114
- package/src/list/index.ts +1 -0
- package/src/number/styles.module.less +10 -2
- package/src/parameters/index.tsx +135 -149
- package/src/parameters/parametersComponent.tsx +120 -82
- package/src/parameters/styles.module.less +9 -0
- package/src/parameters/types.d.ts +10 -3
- package/src/utils.ts +694 -607
- /package/src/collapsible/{titleNode.ts → title.ts} +0 -0
|
@@ -15,17 +15,18 @@ var LexicalHorizontalRuleNode = require('@lexical/react/LexicalHorizontalRuleNod
|
|
|
15
15
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
16
16
|
var React = require('react');
|
|
17
17
|
var jsxRuntime = require('react/jsx-runtime');
|
|
18
|
+
var clipboard = require('@lexical/clipboard');
|
|
18
19
|
var list = require('@lexical/list');
|
|
20
|
+
var richText = require('@lexical/rich-text');
|
|
19
21
|
var table = require('@lexical/table');
|
|
20
22
|
var onchainLexicalMarkdown = require('onchain-lexical-markdown');
|
|
21
23
|
var traversal = require('onchain-utility/traversal');
|
|
22
24
|
var selection = require('@lexical/selection');
|
|
23
25
|
var useLexicalNodeSelection = require('@lexical/react/useLexicalNodeSelection');
|
|
24
|
-
var hooks = require('onchain-utility/hooks');
|
|
25
|
-
var richText = require('@lexical/rich-text');
|
|
26
26
|
var useLexicalEditable = require('@lexical/react/useLexicalEditable');
|
|
27
27
|
var EquationEditor = require('onchain-lexical-ui/EquationEditor');
|
|
28
28
|
var KatexRenderer = require('onchain-lexical-ui/KatexRenderer');
|
|
29
|
+
var base64 = require('onchain-utility/base64');
|
|
29
30
|
var LexicalAutoFocusPlugin = require('@lexical/react/LexicalAutoFocusPlugin');
|
|
30
31
|
var LexicalCollaborationContext = require('@lexical/react/LexicalCollaborationContext');
|
|
31
32
|
var LexicalCollaborationPlugin = require('@lexical/react/LexicalCollaborationPlugin');
|
|
@@ -45,6 +46,8 @@ var Skeleton = require('onchain-lexical-ui/Skeleton');
|
|
|
45
46
|
var settings = require('onchain-lexical-context/settings');
|
|
46
47
|
var DropDown = require('onchain-lexical-ui/DropDown');
|
|
47
48
|
var Icon = require('onchain-lexical-ui/Icon');
|
|
49
|
+
var hooks = require('onchain-utility/hooks');
|
|
50
|
+
var language = require('onchain-utility/language');
|
|
48
51
|
var hashtag = require('@lexical/hashtag');
|
|
49
52
|
var Button = require('onchain-lexical-ui/Button');
|
|
50
53
|
var Dialog = require('onchain-lexical-ui/Dialog');
|
|
@@ -90,9 +93,9 @@ function styleInject(css, ref) {
|
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
|
|
93
|
-
var css_248z$
|
|
94
|
-
var Styles$
|
|
95
|
-
styleInject(css_248z$
|
|
96
|
+
var css_248z$9 = ".base-module_instance__4TS7Q>p:first-of-type{word-wrap:normal;border-bottom:1px solid #d8d8d8;height:38px;line-height:38px;margin-bottom:4px}";
|
|
97
|
+
var Styles$9 = {"instance":"base-module_instance__4TS7Q"};
|
|
98
|
+
styleInject(css_248z$9);
|
|
96
99
|
|
|
97
100
|
/**
|
|
98
101
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -164,6 +167,9 @@ const PARAMETERS_UPDATE = lexical.createCommand('PARAMETERS_UPDATE');
|
|
|
164
167
|
/** 添加评论 */
|
|
165
168
|
const ADD_COMMENT = lexical.createCommand('ADD_COMMENT');
|
|
166
169
|
|
|
170
|
+
/** 打开参数列表 */
|
|
171
|
+
const OPEN_PARAMS = lexical.createCommand('OPEN_PARAMS');
|
|
172
|
+
|
|
167
173
|
/** 获取禁止编辑dom节点选择器 */
|
|
168
174
|
const DisableSelector = `[usable='false']:not([ignoreusable])`;
|
|
169
175
|
|
|
@@ -483,9 +489,9 @@ function $isPlaceholderDecoratorNode(node) {
|
|
|
483
489
|
return node instanceof PlaceholderDecoratorNode;
|
|
484
490
|
}
|
|
485
491
|
|
|
486
|
-
var css_248z$
|
|
487
|
-
var Styles$
|
|
488
|
-
styleInject(css_248z$
|
|
492
|
+
var css_248z$8 = ".styles-module_instance-title__Xh6UG{height:100%;overflow:hidden;padding-right:68px;text-overflow:ellipsis;white-space:nowrap}.styles-module_instance-title__Xh6UG.styles-module_title-hover__9nE-K{overflow:initial;white-space:normal}.styles-module_instance-title__Xh6UG.styles-module_title-hover__9nE-K>span:nth-of-type(2){background-color:#f9f9f9;border:1px solid #d8d8d8;border-top-color:transparent;display:inline-block;left:-5px;line-height:36px;min-height:100%;padding:0 4px;position:relative;z-index:1}.styles-module_instance-title__Xh6UG.styles-module_title-hover__9nE-K>span:nth-of-type(2):after,.styles-module_instance-title__Xh6UG.styles-module_title-hover__9nE-K>span:nth-of-type(2):before{background-color:#f9f9f9;content:\"\";display:inline-block;height:37px;pointer-events:none;position:absolute;top:-1px;width:5px;z-index:2}.styles-module_instance-title__Xh6UG.styles-module_title-hover__9nE-K>span:nth-of-type(2):before{left:-4px}.styles-module_instance-title__Xh6UG.styles-module_title-hover__9nE-K>span:nth-of-type(2):after{right:-4px}";
|
|
493
|
+
var Styles$8 = {"instance-title":"styles-module_instance-title__Xh6UG","title-hover":"styles-module_title-hover__9nE-K"};
|
|
494
|
+
styleInject(css_248z$8);
|
|
489
495
|
|
|
490
496
|
/**
|
|
491
497
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -562,7 +568,7 @@ class InstanceTitleNode extends InstanceHeadingNode {
|
|
|
562
568
|
}
|
|
563
569
|
createDOM(config) {
|
|
564
570
|
const element = super.createDOM(config);
|
|
565
|
-
element.classList.add(Styles$
|
|
571
|
+
element.classList.add(Styles$8['instance-title']);
|
|
566
572
|
element.setAttribute('instance-title', 'true');
|
|
567
573
|
setDisable(this, element);
|
|
568
574
|
element.onmousemove = function (event) {
|
|
@@ -579,9 +585,9 @@ class InstanceTitleNode extends InstanceHeadingNode {
|
|
|
579
585
|
};
|
|
580
586
|
const display = headingWidth - paddingRight.value - paddingLeft.value;
|
|
581
587
|
if (display <= titleWidth) {
|
|
582
|
-
element.classList.add(Styles$
|
|
588
|
+
element.classList.add(Styles$8['title-hover']);
|
|
583
589
|
span.onmouseout = function (event) {
|
|
584
|
-
element.classList.remove(Styles$
|
|
590
|
+
element.classList.remove(Styles$8['title-hover']);
|
|
585
591
|
};
|
|
586
592
|
}
|
|
587
593
|
}
|
|
@@ -736,12 +742,197 @@ function $registerInstanceHeadingNodeTransform(editor) {
|
|
|
736
742
|
});
|
|
737
743
|
}
|
|
738
744
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
*
|
|
745
|
+
var css_248z$7 = ".styles-module_parameter__fieN0{color:#0563b0;padding:0 2px}.styles-module_parameter__fieN0.styles-module_pointer__089d2{cursor:pointer}";
|
|
746
|
+
var Styles$7 = {"parameter":"styles-module_parameter__fieN0","pointer":"styles-module_pointer__089d2"};
|
|
747
|
+
styleInject(css_248z$7);
|
|
748
|
+
|
|
749
|
+
/**
|
|
750
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
751
|
+
*
|
|
752
|
+
* This source code is licensed under the MIT license found in the
|
|
753
|
+
* LICENSE file in the root directory of this source tree.
|
|
754
|
+
*
|
|
755
|
+
*/
|
|
756
|
+
|
|
757
|
+
const ParametersComponent = /*#__PURE__*/React.forwardRef(({
|
|
758
|
+
nodeKey
|
|
759
|
+
}, ref) => {
|
|
760
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
761
|
+
const {
|
|
762
|
+
preview,
|
|
763
|
+
parameterUnified
|
|
764
|
+
} = instanceConfig.useInstanceConfig();
|
|
765
|
+
const spanRef = React.useRef(null);
|
|
766
|
+
const [parameter, setParameter,, latestParameter] = hooks.useStore({
|
|
767
|
+
insId: '',
|
|
768
|
+
number: '',
|
|
769
|
+
value: ''
|
|
770
|
+
});
|
|
771
|
+
const isCanUse = !preview;
|
|
772
|
+
React.useEffect(() => {
|
|
773
|
+
editor.read(() => {
|
|
774
|
+
const node = lexical.$getNodeByKey(nodeKey);
|
|
775
|
+
if ($isParametersNode(node)) {
|
|
776
|
+
const parameter = node.parameter;
|
|
777
|
+
setParameter(Object.assign(node.parameter, {
|
|
778
|
+
value: parameterUnified.getParameterValue(parameter.insId)
|
|
779
|
+
}));
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
return utils$1.mergeRegister(editor.registerCommand(PARAMETERS_UPDATE, ({
|
|
783
|
+
parameters
|
|
784
|
+
}) => {
|
|
785
|
+
const latest = latestParameter.current;
|
|
786
|
+
const parameter = parameters.find(parameter => parameter.insId === latest.insId);
|
|
787
|
+
if (!parameter) {
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
const node = lexical.$getNodeByKey(nodeKey);
|
|
791
|
+
if ($isParametersNode(node)) {
|
|
792
|
+
Promise.resolve().then(() => {
|
|
793
|
+
const value = parameterUnified.setParameter(parameter).getParameterValue(parameter.insId);
|
|
794
|
+
setParameter({
|
|
795
|
+
value
|
|
796
|
+
});
|
|
797
|
+
Object.assign(node.parameter, {
|
|
798
|
+
value
|
|
799
|
+
});
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
return false;
|
|
803
|
+
}, lexical.COMMAND_PRIORITY_EDITOR));
|
|
804
|
+
}, [parameterUnified]);
|
|
805
|
+
React.useImperativeHandle(ref, () => {
|
|
806
|
+
return {
|
|
807
|
+
getParameter() {
|
|
808
|
+
return latestParameter.current;
|
|
809
|
+
},
|
|
810
|
+
getValue() {
|
|
811
|
+
return parameterUnified.getParameterValue(latestParameter.current.insId);
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
}, [parameterUnified]);
|
|
815
|
+
return /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
816
|
+
className: `parameter ${Styles$7.parameter} ${isCanUse ? Styles$7.pointer : ''}`,
|
|
817
|
+
title: language.translateI18n('[TODO] Parameter', {
|
|
818
|
+
placeholder: '参数'
|
|
819
|
+
}),
|
|
820
|
+
ref: spanRef,
|
|
821
|
+
role: "button",
|
|
822
|
+
tabIndex: 0,
|
|
823
|
+
onClick: () => {
|
|
824
|
+
if (isCanUse) {
|
|
825
|
+
editor.dispatchCommand(INSERT_PARAMETERS, {
|
|
826
|
+
instance: editor.read(() => {
|
|
827
|
+
return $getInstanceNodeByChild(lexical.$getNodeByKey(nodeKey))?.__instance.value;
|
|
828
|
+
}),
|
|
829
|
+
nodeKey,
|
|
830
|
+
target: parameter.insId
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
},
|
|
834
|
+
children: parameter.value
|
|
835
|
+
});
|
|
836
|
+
});
|
|
837
|
+
|
|
838
|
+
/**
|
|
839
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
840
|
+
*
|
|
841
|
+
* This source code is licensed under the MIT license found in the
|
|
842
|
+
* LICENSE file in the root directory of this source tree.
|
|
843
|
+
*
|
|
844
|
+
*/
|
|
845
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
846
|
+
|
|
847
|
+
class ParametersNode extends lexical.TextDecoratorNode {
|
|
848
|
+
/** 初始化值 */
|
|
849
|
+
|
|
850
|
+
__ref = /*#__PURE__*/React.createRef();
|
|
851
|
+
|
|
852
|
+
/** 最新的值 */
|
|
853
|
+
get parameter() {
|
|
854
|
+
return this.__parameter.isolation;
|
|
855
|
+
}
|
|
856
|
+
static getType() {
|
|
857
|
+
return 'Parameter';
|
|
858
|
+
}
|
|
859
|
+
static clone(node) {
|
|
860
|
+
return new ParametersNode(Object.assign({}, node.parameter), node.__key);
|
|
861
|
+
}
|
|
862
|
+
static importJSON(serializedNode) {
|
|
863
|
+
return $createParametersNode(serializedNode.parameter).updateFromJSON(serializedNode);
|
|
864
|
+
}
|
|
865
|
+
constructor(parameter, key) {
|
|
866
|
+
super(key);
|
|
867
|
+
this.__parameter = {
|
|
868
|
+
isolation: parameter
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
exportJSON() {
|
|
872
|
+
return {
|
|
873
|
+
...super.exportJSON(),
|
|
874
|
+
parameter: this.parameter
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
exportDOM(editor) {
|
|
878
|
+
const element = document.createElement('section');
|
|
879
|
+
element.setAttribute('parameter', '');
|
|
880
|
+
element.setAttribute('data-parameter', base64.toBase64UTF8(JSON.stringify(this.parameter)));
|
|
881
|
+
element.textContent = this.parameter.value;
|
|
882
|
+
return {
|
|
883
|
+
element
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
createDOM(config, editor) {
|
|
887
|
+
const span = super.createDOM(config, editor);
|
|
888
|
+
span.setAttribute('ignoreusable', '');
|
|
889
|
+
span.setAttribute('key', this.getKey());
|
|
890
|
+
return span;
|
|
891
|
+
}
|
|
892
|
+
updateDOM(prevNode, dom, config) {
|
|
893
|
+
return super.updateDOM(prevNode, dom, config);
|
|
894
|
+
}
|
|
895
|
+
collapseAtStart() {
|
|
896
|
+
return true;
|
|
897
|
+
}
|
|
898
|
+
isInline() {
|
|
899
|
+
return true;
|
|
900
|
+
}
|
|
901
|
+
getTextContent() {
|
|
902
|
+
return this.__ref.current?.getValue() || '';
|
|
903
|
+
}
|
|
904
|
+
decorate(editor, config) {
|
|
905
|
+
return /*#__PURE__*/jsxRuntime.jsx(ParametersComponent, {
|
|
906
|
+
ref: this.__ref,
|
|
907
|
+
nodeKey: this.getKey()
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
function $createParametersNode(parameters) {
|
|
912
|
+
return lexical.$applyNodeReplacement(new ParametersNode(parameters));
|
|
913
|
+
}
|
|
914
|
+
function $isParametersNode(node) {
|
|
915
|
+
return node instanceof ParametersNode;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// export function updateParameters(parameters: Parameter) {
|
|
919
|
+
// return ParametersNode.collection.set(parameters.number, parameters);
|
|
920
|
+
// }
|
|
921
|
+
|
|
922
|
+
function $unifiedCreateParametersNode(unified, parameter) {
|
|
923
|
+
return $createParametersNode({
|
|
924
|
+
insId: parameter.insId,
|
|
925
|
+
number: parameter.number,
|
|
926
|
+
value: unified.setParameter(parameter).getParameterValue(parameter)
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/**
|
|
931
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
932
|
+
*
|
|
933
|
+
* This source code is licensed under the MIT license found in the
|
|
934
|
+
* LICENSE file in the root directory of this source tree.
|
|
935
|
+
*
|
|
745
936
|
*/
|
|
746
937
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
747
938
|
|
|
@@ -861,11 +1052,13 @@ function getLatestValue(data, key) {
|
|
|
861
1052
|
return data[key];
|
|
862
1053
|
}
|
|
863
1054
|
|
|
864
|
-
/**
|
|
865
|
-
* 跳转到指定实例
|
|
866
|
-
* dom 属性 data-scrollTo=“false” 时可以禁止跳转
|
|
1055
|
+
/**
|
|
1056
|
+
* 跳转到指定实例
|
|
1057
|
+
* dom 属性 data-scrollTo=“false” 时可以禁止跳转
|
|
867
1058
|
*/
|
|
868
|
-
function $scrollTo(number
|
|
1059
|
+
function $scrollTo(number, config = {
|
|
1060
|
+
isFocus: true
|
|
1061
|
+
}) {
|
|
869
1062
|
const editor = lexical.$getEditor();
|
|
870
1063
|
const nodeKey = numberNodeKey.get(number);
|
|
871
1064
|
const rootElement = editor.getRootElement();
|
|
@@ -875,7 +1068,25 @@ function $scrollTo(number) {
|
|
|
875
1068
|
const target = editor.getElementByKey(numberNode.getKey() || nodeKey);
|
|
876
1069
|
if (target) {
|
|
877
1070
|
lexical.scrollIntoViewIfNeeded(editor, target.getBoundingClientRect(), rootElement, document.querySelector('.top-container.editor-container'));
|
|
878
|
-
|
|
1071
|
+
if (config.isFocus) {
|
|
1072
|
+
lexical.$getNodeByKey(nodeKey)?.selectStart();
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
function $scrollToByNode(node, config = {
|
|
1078
|
+
isFocus: true
|
|
1079
|
+
}) {
|
|
1080
|
+
const editor = lexical.$getEditor();
|
|
1081
|
+
const rootElement = editor.getRootElement();
|
|
1082
|
+
const nodeKey = node.getKey();
|
|
1083
|
+
if (rootElement) {
|
|
1084
|
+
const target = editor.getElementByKey(nodeKey);
|
|
1085
|
+
if (target) {
|
|
1086
|
+
lexical.scrollIntoViewIfNeeded(editor, target.getBoundingClientRect(), rootElement, document.querySelector('.top-container.editor-container'));
|
|
1087
|
+
if (config.isFocus) {
|
|
1088
|
+
node.selectStart();
|
|
1089
|
+
}
|
|
879
1090
|
}
|
|
880
1091
|
}
|
|
881
1092
|
}
|
|
@@ -1057,15 +1268,22 @@ function setHSEntryMap(hs, instanceNode) {
|
|
|
1057
1268
|
return state;
|
|
1058
1269
|
});
|
|
1059
1270
|
}
|
|
1271
|
+
function isTemporaryInsId(insId) {
|
|
1272
|
+
return insId?.startsWith('_temporary_');
|
|
1273
|
+
}
|
|
1060
1274
|
function useContentEditable() {
|
|
1061
1275
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
1062
1276
|
const [contentEditable, setContentEditable] = React.useState(true);
|
|
1277
|
+
const [isTemporaryInstance, setIsTemporaryInstance] = React.useState(true);
|
|
1063
1278
|
const $updateContentEditable = React.useCallback(() => {
|
|
1064
1279
|
const selection = lexical.$getSelection();
|
|
1065
1280
|
if (selection) {
|
|
1066
|
-
|
|
1281
|
+
const nodes = selection.getNodes();
|
|
1282
|
+
setContentEditable(!nodes.some(node => {
|
|
1067
1283
|
return editor.getElementByKey(node.getKey())?.closest(DisableSelector) || $isInInstanceTitleNode(node);
|
|
1068
1284
|
}));
|
|
1285
|
+
const ids = Array.from(new Set(nodes.map(n => $getInstanceNodeByChild(n)?.__instance.value.insId)));
|
|
1286
|
+
setIsTemporaryInstance(ids.some(id => isTemporaryInsId(id)));
|
|
1069
1287
|
}
|
|
1070
1288
|
}, [editor]);
|
|
1071
1289
|
React.useEffect(() => {
|
|
@@ -1075,7 +1293,37 @@ function useContentEditable() {
|
|
|
1075
1293
|
}, lexical.COMMAND_PRIORITY_CRITICAL);
|
|
1076
1294
|
}, [editor, $updateContentEditable]);
|
|
1077
1295
|
return {
|
|
1078
|
-
contentEditable
|
|
1296
|
+
contentEditable,
|
|
1297
|
+
isTemporaryInstance
|
|
1298
|
+
};
|
|
1299
|
+
}
|
|
1300
|
+
function useSelectedIds() {
|
|
1301
|
+
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
1302
|
+
const [selectedIds, setSelectedId] = React.useState([]);
|
|
1303
|
+
const [isTemporaryInstance, setIsTemporaryInstance] = React.useState(true);
|
|
1304
|
+
const $updateContentEditable = React.useCallback(() => {
|
|
1305
|
+
editor.read(() => {
|
|
1306
|
+
const selection = lexical.$getSelection();
|
|
1307
|
+
if (selection) {
|
|
1308
|
+
const nodes = selection.getNodes();
|
|
1309
|
+
const ids = Array.from(new Set(nodes.map(n => $getInstanceNodeByChild(n)?.__instance.value.insId)));
|
|
1310
|
+
setSelectedId(ids);
|
|
1311
|
+
setIsTemporaryInstance(ids.some(id => isTemporaryInsId(id)));
|
|
1312
|
+
}
|
|
1313
|
+
});
|
|
1314
|
+
}, [editor]);
|
|
1315
|
+
React.useEffect(() => {
|
|
1316
|
+
editor.read(() => {
|
|
1317
|
+
$updateContentEditable();
|
|
1318
|
+
});
|
|
1319
|
+
return editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, _payload => {
|
|
1320
|
+
$updateContentEditable();
|
|
1321
|
+
return false;
|
|
1322
|
+
}, lexical.COMMAND_PRIORITY_CRITICAL);
|
|
1323
|
+
}, [editor, $updateContentEditable]);
|
|
1324
|
+
return {
|
|
1325
|
+
isTemporaryInstance,
|
|
1326
|
+
selectedIds
|
|
1079
1327
|
};
|
|
1080
1328
|
}
|
|
1081
1329
|
|
|
@@ -1143,8 +1391,8 @@ function $addInstancesNode({
|
|
|
1143
1391
|
}
|
|
1144
1392
|
}
|
|
1145
1393
|
}
|
|
1146
|
-
function $
|
|
1147
|
-
if (node) {
|
|
1394
|
+
function $selectTextDecoratorNode(node) {
|
|
1395
|
+
if (lexical.$isTextDecoratorNode(node) && !$isParametersNode(node)) {
|
|
1148
1396
|
const [previous, next] = [node.getPreviousSibling(), node.getNextSibling()];
|
|
1149
1397
|
const rangeSelection = lexical.$createRangeSelection();
|
|
1150
1398
|
if (previous) {
|
|
@@ -1365,7 +1613,7 @@ const Number$1 = props => {
|
|
|
1365
1613
|
});
|
|
1366
1614
|
};
|
|
1367
1615
|
|
|
1368
|
-
var css_248z$6 = ".styles-module_instance-number__yIPpS{align-items:center;display:inline-flex;height:38px;justify-content:flex-start;left:0;position:absolute;top:0;user-select:none;z-index:2}.styles-module_instance-number__yIPpS>div>span:first-of-type:not(:empty){padding-right:4px}";
|
|
1616
|
+
var css_248z$6 = ".styles-module_instance-number__yIPpS{align-items:center;display:inline-flex;height:38px;justify-content:flex-start;left:0;position:absolute;top:0;user-select:none;z-index:2}.styles-module_instance-number__yIPpS>div>span:first-of-type{color:#0563b0}.styles-module_instance-number__yIPpS>div>span:first-of-type:not(:empty){padding-right:4px}.styles-module_instance-number__yIPpS>div>span:nth-of-type(2){color:#0563b0}";
|
|
1369
1617
|
var Styles$6 = {"instance-number":"styles-module_instance-number__yIPpS"};
|
|
1370
1618
|
styleInject(css_248z$6);
|
|
1371
1619
|
|
|
@@ -1641,7 +1889,7 @@ class InstanceNode extends lexical.ElementNode {
|
|
|
1641
1889
|
|
|
1642
1890
|
createDOM(config) {
|
|
1643
1891
|
const dom = document.createElement('div');
|
|
1644
|
-
const classNames = [Styles$
|
|
1892
|
+
const classNames = [Styles$9.instance, 'rich-text-instance', getCachedClassNameArray(config.theme, 'instance') ?? []];
|
|
1645
1893
|
if (classNames !== undefined) {
|
|
1646
1894
|
const domClassList = dom.classList;
|
|
1647
1895
|
domClassList.add(...classNames.flat(1));
|
|
@@ -1874,6 +2122,38 @@ function $checkAllParagraphsEmpty(parent) {
|
|
|
1874
2122
|
function isFixedAddress(instance) {
|
|
1875
2123
|
return !!instance && Object.keys(instance).length === 1 && typeof instance.value === 'object';
|
|
1876
2124
|
}
|
|
2125
|
+
class InstanceContentNode extends lexical.ElementNode {
|
|
2126
|
+
static getType() {
|
|
2127
|
+
return 'Content';
|
|
2128
|
+
}
|
|
2129
|
+
static clone(node) {
|
|
2130
|
+
return new InstanceContentNode(node.__key);
|
|
2131
|
+
}
|
|
2132
|
+
static importJSON(serializedNode) {
|
|
2133
|
+
return new InstanceContentNode().updateFromJSON(serializedNode);
|
|
2134
|
+
}
|
|
2135
|
+
exportJSON() {
|
|
2136
|
+
return {
|
|
2137
|
+
...super.exportJSON()
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
createDOM(config) {
|
|
2141
|
+
const element = document.createElement('div');
|
|
2142
|
+
element.setAttribute('content', 'true');
|
|
2143
|
+
element.setAttribute('key', this.getKey());
|
|
2144
|
+
setDisable(this, element);
|
|
2145
|
+
return element;
|
|
2146
|
+
}
|
|
2147
|
+
updateDOM(prevNode, dom, config) {
|
|
2148
|
+
return false;
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
function $createInstanceContentNode() {
|
|
2152
|
+
return lexical.$applyNodeReplacement(new InstanceContentNode());
|
|
2153
|
+
}
|
|
2154
|
+
function $isInstanceContentNode(node) {
|
|
2155
|
+
return node instanceof InstanceNode;
|
|
2156
|
+
}
|
|
1877
2157
|
|
|
1878
2158
|
var css_248z$5 = ".styles-module_left__CN0nC{align-items:center;display:flex;flex-direction:column;left:0;position:absolute;transform:translate(-26px);user-select:none;width:26px}.styles-module_left__CN0nC .styles-module_link__M-1Wq{margin-bottom:6px}.styles-module_left__CN0nC .styles-module_link__M-1Wq>button>span>div{position:relative}.styles-module_left__CN0nC .styles-module_link__M-1Wq>button>span>div>i{align-items:center;background-color:#0563b0;border-radius:50%;bottom:-2px;color:#fff;display:flex;font-size:10px;font-style:normal;height:12px;justify-content:center;position:absolute;right:-2px;width:12px}.styles-module_left__CN0nC .styles-module_hiddenLinkCount__ThNp5>button>span>div>i,.styles-module_left__CN0nC .styles-module_link__M-1Wq>button>span>div>i:empty{display:none}.styles-module_left__CN0nC>*{align-items:center;display:inline-flex;justify-content:center}.styles-module_left__CN0nC>span:first-of-type{height:38px}.styles-module_right__sxVYl{align-items:center;display:inline-flex;height:38px;justify-content:flex-end;position:absolute;right:0;top:0;user-select:none;z-index:2}.styles-module_right__sxVYl>span{cursor:pointer;margin-left:10px}.styles-module_hasChildren__FqxrJ,.styles-module_hover__IeKlt:hover,.styles-module_selected__dpCTX{color:#0563b0}.styles-module_empty__g2IcU{cursor:default!important}";
|
|
1879
2159
|
var Styles$5 = {"left":"styles-module_left__CN0nC","link":"styles-module_link__M-1Wq","hiddenLinkCount":"styles-module_hiddenLinkCount__ThNp5","right":"styles-module_right__sxVYl","selected":"styles-module_selected__dpCTX","hasChildren":"styles-module_hasChildren__FqxrJ","hover":"styles-module_hover__IeKlt","empty":"styles-module_empty__g2IcU"};
|
|
@@ -2691,7 +2971,7 @@ function $textNodeTransform(node, editor, tokenizer) {
|
|
|
2691
2971
|
// if node's parent is a code node and run highlighting if so
|
|
2692
2972
|
const parentNode = node.getParent();
|
|
2693
2973
|
if ($isInstanceCodeNode(parentNode)) {
|
|
2694
|
-
codeNodeTransform(parentNode,
|
|
2974
|
+
codeNodeTransform(parentNode, null, tokenizer);
|
|
2695
2975
|
} else if ($isInstanceCodeHighlightNode(node)) {
|
|
2696
2976
|
// When code block converted into paragraph or other element
|
|
2697
2977
|
// code highlight nodes converted back to normal text
|
|
@@ -2731,9 +3011,9 @@ function updateCodeGutter(node, editor) {
|
|
|
2731
3011
|
// Especially when pasting code into CodeBlock.
|
|
2732
3012
|
|
|
2733
3013
|
const nodesCurrentlyHighlighting = new Set();
|
|
2734
|
-
function codeNodeTransform(node, editor, tokenizer) {
|
|
3014
|
+
function codeNodeTransform(node, editor, tokenizer, isEnforcement) {
|
|
2735
3015
|
const nodeKey = node.getKey();
|
|
2736
|
-
if (nodesCurrentlyHighlighting.has(nodeKey)) {
|
|
3016
|
+
if (nodesCurrentlyHighlighting.has(nodeKey) && !isEnforcement) {
|
|
2737
3017
|
return;
|
|
2738
3018
|
}
|
|
2739
3019
|
nodesCurrentlyHighlighting.add(nodeKey);
|
|
@@ -2746,7 +3026,8 @@ function codeNodeTransform(node, editor, tokenizer) {
|
|
|
2746
3026
|
// Using nested update call to pass `skipTransforms` since we don't want
|
|
2747
3027
|
// each individual InstanceCodeHighlightNode to be transformed again as it's already
|
|
2748
3028
|
// in its final state
|
|
2749
|
-
|
|
3029
|
+
// eslint-disable-next-line @lexical/rules-of-lexical
|
|
3030
|
+
const transform = () => {
|
|
2750
3031
|
$updateAndRetainSelection(nodeKey, () => {
|
|
2751
3032
|
const currentNode = lexical.$getNodeByKey(nodeKey);
|
|
2752
3033
|
if (!$isInstanceCodeNode(currentNode) || !currentNode.isAttached()) {
|
|
@@ -2767,12 +3048,17 @@ function codeNodeTransform(node, editor, tokenizer) {
|
|
|
2767
3048
|
}
|
|
2768
3049
|
return false;
|
|
2769
3050
|
});
|
|
2770
|
-
}
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
3051
|
+
};
|
|
3052
|
+
if (editor) {
|
|
3053
|
+
editor.update(transform, {
|
|
3054
|
+
onUpdate: () => {
|
|
3055
|
+
nodesCurrentlyHighlighting.delete(nodeKey);
|
|
3056
|
+
},
|
|
3057
|
+
skipTransforms: true
|
|
3058
|
+
});
|
|
3059
|
+
} else {
|
|
3060
|
+
transform();
|
|
3061
|
+
}
|
|
2776
3062
|
}
|
|
2777
3063
|
function $getHighlightNodes(tokens, type) {
|
|
2778
3064
|
const nodes = [];
|
|
@@ -3179,7 +3465,7 @@ function registerCodeHighlighting(editor, tokenizer) {
|
|
|
3179
3465
|
});
|
|
3180
3466
|
}, {
|
|
3181
3467
|
skipInitialization: false
|
|
3182
|
-
}), editor.registerNodeTransform(InstanceCodeNode, node => codeNodeTransform(node,
|
|
3468
|
+
}), editor.registerNodeTransform(InstanceCodeNode, node => codeNodeTransform(node, null, tokenizer)), editor.registerNodeTransform(lexical.TextNode, node => $textNodeTransform(node, editor, tokenizer)), editor.registerNodeTransform(InstanceCodeHighlightNode, node => $textNodeTransform(node, editor, tokenizer)), editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
|
|
3183
3469
|
const command = $handleTab(event.shiftKey);
|
|
3184
3470
|
if (command === null) {
|
|
3185
3471
|
return false;
|
|
@@ -22123,12 +22409,12 @@ var katex = {
|
|
|
22123
22409
|
__domTree
|
|
22124
22410
|
};
|
|
22125
22411
|
|
|
22126
|
-
/**
|
|
22127
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
22128
|
-
*
|
|
22129
|
-
* This source code is licensed under the MIT license found in the
|
|
22130
|
-
* LICENSE file in the root directory of this source tree.
|
|
22131
|
-
*
|
|
22412
|
+
/**
|
|
22413
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
22414
|
+
*
|
|
22415
|
+
* This source code is licensed under the MIT license found in the
|
|
22416
|
+
* LICENSE file in the root directory of this source tree.
|
|
22417
|
+
*
|
|
22132
22418
|
*/
|
|
22133
22419
|
|
|
22134
22420
|
const EquationComponent$2 = /*#__PURE__*/React__namespace.lazy(() => Promise.resolve().then(function () { return EquationComponent$1; }));
|
|
@@ -22174,9 +22460,9 @@ class InstanceEquationNode extends lexical.DecoratorNode {
|
|
|
22174
22460
|
return element;
|
|
22175
22461
|
}
|
|
22176
22462
|
exportDOM() {
|
|
22177
|
-
const element = document.createElement('
|
|
22463
|
+
const element = document.createElement('equation');
|
|
22178
22464
|
// Encode the equation as base64 to avoid issues with special characters
|
|
22179
|
-
const equation =
|
|
22465
|
+
const equation = base64.toBase64UTF8(this.__equation);
|
|
22180
22466
|
element.setAttribute('data-lexical-equation', equation);
|
|
22181
22467
|
element.setAttribute('data-lexical-inline', `${this.__inline}`);
|
|
22182
22468
|
katex.render(this.__equation, element, {
|
|
@@ -23570,6 +23856,7 @@ class InstanceListNode extends list.ListNode {
|
|
|
23570
23856
|
createDOM(config) {
|
|
23571
23857
|
const element = super.createDOM(config);
|
|
23572
23858
|
setDisable(this, element);
|
|
23859
|
+
element.setAttribute('list-type', this.getListType());
|
|
23573
23860
|
return element;
|
|
23574
23861
|
}
|
|
23575
23862
|
updateFromJSON(serializedNode) {
|
|
@@ -23812,13 +24099,15 @@ function $createTableNodeWithDimensions(rowCount, columnCount, includeHeaders =
|
|
|
23812
24099
|
return tableNode;
|
|
23813
24100
|
}
|
|
23814
24101
|
|
|
23815
|
-
/**
|
|
23816
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
23817
|
-
*
|
|
23818
|
-
* This source code is licensed under the MIT license found in the
|
|
23819
|
-
* LICENSE file in the root directory of this source tree.
|
|
23820
|
-
*
|
|
24102
|
+
/**
|
|
24103
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24104
|
+
*
|
|
24105
|
+
* This source code is licensed under the MIT license found in the
|
|
24106
|
+
* LICENSE file in the root directory of this source tree.
|
|
24107
|
+
*
|
|
23821
24108
|
*/
|
|
24109
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
24110
|
+
|
|
23822
24111
|
const InstancePlugin = props => {
|
|
23823
24112
|
const {
|
|
23824
24113
|
placeholder
|
|
@@ -23830,13 +24119,48 @@ const InstancePlugin = props => {
|
|
|
23830
24119
|
placeholder
|
|
23831
24120
|
}), $registerInstanceHeadingNodeTransform(editor), $registerInstanceListItemInsertParagraph(editor), $registerNumberDecoratorNodeUpdate(editor), $registerNumberDecoratorDomUpdate(editor), $registerTableCommand(editor),
|
|
23832
24121
|
// $selectionChange(editor, setSelectedInstance),
|
|
23833
|
-
editor.
|
|
24122
|
+
editor.registerRootListener((rootElement, prevRootElement) => {
|
|
24123
|
+
if (rootElement) {
|
|
24124
|
+
const handle = e => {
|
|
24125
|
+
e.preventDefault();
|
|
24126
|
+
e.stopPropagation();
|
|
24127
|
+
const isDisable = editor.read(() => {
|
|
24128
|
+
const selection = lexical.$getSelection();
|
|
24129
|
+
if (selection) {
|
|
24130
|
+
const nodes = selection.getNodes();
|
|
24131
|
+
return nodes.some(node => {
|
|
24132
|
+
return editor.getElementByKey(node.getKey())?.closest(DisableSelector);
|
|
24133
|
+
});
|
|
24134
|
+
}
|
|
24135
|
+
});
|
|
24136
|
+
if (isDisable) {
|
|
24137
|
+
rootElement.blur();
|
|
24138
|
+
window.focus();
|
|
24139
|
+
}
|
|
24140
|
+
};
|
|
24141
|
+
rootElement.addEventListener('compositionstart', handle, true);
|
|
24142
|
+
rootElement.addEventListener('compositionend', handle, true);
|
|
24143
|
+
}
|
|
24144
|
+
}), editor.registerCommand(lexical.PASTE_COMMAND, event => {
|
|
24145
|
+
const [, files, hasTextContent] = richText.eventFiles(event);
|
|
24146
|
+
if (files.length > 0 && !hasTextContent) {
|
|
24147
|
+
editor.dispatchCommand(richText.DRAG_DROP_PASTE, files);
|
|
24148
|
+
return true;
|
|
24149
|
+
}
|
|
24150
|
+
if (lexical.isDOMNode(event.target) && lexical.isSelectionCapturedInDecoratorInput(event.target)) {
|
|
24151
|
+
return false;
|
|
24152
|
+
}
|
|
24153
|
+
const selection = lexical.$getSelection();
|
|
24154
|
+
if (selection !== null) {
|
|
24155
|
+
onPasteForRichText(event, editor);
|
|
24156
|
+
return true;
|
|
24157
|
+
}
|
|
24158
|
+
return false;
|
|
24159
|
+
}, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, () => {
|
|
23834
24160
|
const selection = lexical.$getSelection();
|
|
23835
24161
|
if (lexical.$isNodeSelection(selection)) {
|
|
23836
24162
|
const [node] = selection.getNodes();
|
|
23837
|
-
|
|
23838
|
-
$selectDecoratorNode(node);
|
|
23839
|
-
}
|
|
24163
|
+
$selectTextDecoratorNode(node);
|
|
23840
24164
|
}
|
|
23841
24165
|
return false;
|
|
23842
24166
|
}, lexical.COMMAND_PRIORITY_CRITICAL), editor.registerCommand(lexical.CLICK_COMMAND, event => {
|
|
@@ -23846,7 +24170,7 @@ const InstancePlugin = props => {
|
|
|
23846
24170
|
const key = decoratorRootEle.getAttribute('key');
|
|
23847
24171
|
if (key) {
|
|
23848
24172
|
const node = lexical.$getNodeByKey(key);
|
|
23849
|
-
$
|
|
24173
|
+
$selectTextDecoratorNode(node);
|
|
23850
24174
|
}
|
|
23851
24175
|
}
|
|
23852
24176
|
}
|
|
@@ -23967,21 +24291,31 @@ const InstancePlugin = props => {
|
|
|
23967
24291
|
});
|
|
23968
24292
|
const next = $getFollowUpNode({
|
|
23969
24293
|
node: startNode,
|
|
24294
|
+
siblingTerminates: [endNode, ...endAncestors],
|
|
23970
24295
|
terminate: sameLevel.get('start'),
|
|
23971
24296
|
type: 'getNextSiblings'
|
|
23972
24297
|
});
|
|
23973
24298
|
const previous = $getFollowUpNode({
|
|
23974
24299
|
node: endNode.getNextSibling() || endNode,
|
|
24300
|
+
siblingTerminates: [startNode, ...startAncestors],
|
|
23975
24301
|
terminate: sameLevel.get('end'),
|
|
23976
24302
|
type: 'getPreviousSiblings'
|
|
23977
24303
|
});
|
|
24304
|
+
const terminates = Array.from(sameLevel.values()).filter(Boolean);
|
|
23978
24305
|
let node = next.original.getNextSibling();
|
|
23979
|
-
while (node && node.getKey() !== previous.original.getKey()) {
|
|
24306
|
+
while (node && node.getKey() !== previous.original.getKey() && terminates.length === 2) {
|
|
23980
24307
|
elementNodes.push(node);
|
|
23981
24308
|
node = node.getNextSibling();
|
|
23982
24309
|
}
|
|
23983
|
-
|
|
23984
|
-
|
|
24310
|
+
if (terminates.length !== 2) {
|
|
24311
|
+
const nodes = [...next.nodes, ...previous.nodes];
|
|
24312
|
+
const p = $createInstanceParagraphNode();
|
|
24313
|
+
p.append(...nodes.map(n => $isInstanceParagraphNode(n) ? n.getChildren() : n).flat());
|
|
24314
|
+
elementNodes.push(p);
|
|
24315
|
+
} else {
|
|
24316
|
+
elementNodes.unshift(...next.nodes);
|
|
24317
|
+
elementNodes.push(...previous.nodes);
|
|
24318
|
+
}
|
|
23985
24319
|
// 添加嵌套Item父List
|
|
23986
24320
|
if (elementNodes.every(node => list.$isListItemNode(node))) {
|
|
23987
24321
|
const originalListNode = utils$1.$findMatchingParent(next.original, node => $isInstanceListNode(node));
|
|
@@ -24045,7 +24379,8 @@ function getAncestors(node) {
|
|
|
24045
24379
|
function $getFollowUpNode({
|
|
24046
24380
|
node,
|
|
24047
24381
|
terminate,
|
|
24048
|
-
type
|
|
24382
|
+
type,
|
|
24383
|
+
siblingTerminates = []
|
|
24049
24384
|
}) {
|
|
24050
24385
|
const isTableCellNode = table.$isTableCellNode(node);
|
|
24051
24386
|
if (isTableCellNode) {
|
|
@@ -24080,6 +24415,11 @@ function $getFollowUpNode({
|
|
|
24080
24415
|
const parentKey = parent?.getKey();
|
|
24081
24416
|
const isStop = parentKey === termKey;
|
|
24082
24417
|
const siblings = node[type]();
|
|
24418
|
+
const siblingTerminateKeys = new Set(siblingTerminates.map(st => st.getKey()));
|
|
24419
|
+
const idx = siblings.findIndex(sibling => siblingTerminateKeys.has(sibling.getKey()));
|
|
24420
|
+
if (idx > -1) {
|
|
24421
|
+
siblings.splice(type === 'getNextSiblings' ? idx : 0, type === 'getNextSiblings' ? Infinity : idx + 1);
|
|
24422
|
+
}
|
|
24083
24423
|
siblings.forEach(sibling => {
|
|
24084
24424
|
if ($isInstanceListItemNode(sibling)) {
|
|
24085
24425
|
sibling.defaultRemove();
|
|
@@ -24127,6 +24467,26 @@ function $getFollowUpNode({
|
|
|
24127
24467
|
original
|
|
24128
24468
|
};
|
|
24129
24469
|
}
|
|
24470
|
+
function onPasteForRichText(event, editor) {
|
|
24471
|
+
event.preventDefault();
|
|
24472
|
+
editor.update(() => {
|
|
24473
|
+
const selection = lexical.$getSelection();
|
|
24474
|
+
const clipboardData = utils$1.objectKlassEquals(event, InputEvent) || utils$1.objectKlassEquals(event, KeyboardEvent) ? null : event.clipboardData;
|
|
24475
|
+
if (clipboardData != null && selection !== null) {
|
|
24476
|
+
clipboard.$insertDataTransferForRichText(clipboardData, selection, editor, nodes => {
|
|
24477
|
+
traversal.dfs(nodes, (node, parent) => {
|
|
24478
|
+
if (node.type === ParametersNode.getType()) {
|
|
24479
|
+
Object.assign(node, lexical.$createTextNode(node.parameter.value).exportJSON());
|
|
24480
|
+
}
|
|
24481
|
+
return node?.children || [];
|
|
24482
|
+
});
|
|
24483
|
+
return nodes;
|
|
24484
|
+
});
|
|
24485
|
+
}
|
|
24486
|
+
}, {
|
|
24487
|
+
tag: lexical.PASTE_TAG
|
|
24488
|
+
});
|
|
24489
|
+
}
|
|
24130
24490
|
|
|
24131
24491
|
var css_248z$3 = ".styles-module_internalLink__3B9ii{color:#0563b0;cursor:pointer}.styles-module_internalLink__3B9ii>span:first-of-type:not(:empty){padding-right:4px}.styles-module_internalLink__3B9ii:hover{color:#0563b0}.styles-module_internalLink__3B9ii:hover>span:nth-of-type(2){text-decoration:underline}";
|
|
24132
24492
|
var Styles$3 = {"internalLink":"styles-module_internalLink__3B9ii"};
|
|
@@ -24192,12 +24552,12 @@ function InternalLinkComponent(props) {
|
|
|
24192
24552
|
}
|
|
24193
24553
|
}
|
|
24194
24554
|
|
|
24195
|
-
/**
|
|
24196
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24197
|
-
*
|
|
24198
|
-
* This source code is licensed under the MIT license found in the
|
|
24199
|
-
* LICENSE file in the root directory of this source tree.
|
|
24200
|
-
*
|
|
24555
|
+
/**
|
|
24556
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24557
|
+
*
|
|
24558
|
+
* This source code is licensed under the MIT license found in the
|
|
24559
|
+
* LICENSE file in the root directory of this source tree.
|
|
24560
|
+
*
|
|
24201
24561
|
*/
|
|
24202
24562
|
|
|
24203
24563
|
class InternalLinkNode extends lexical.TextDecoratorNode {
|
|
@@ -24225,6 +24585,15 @@ class InternalLinkNode extends lexical.TextDecoratorNode {
|
|
|
24225
24585
|
number: this.__number
|
|
24226
24586
|
};
|
|
24227
24587
|
}
|
|
24588
|
+
exportDOM(editor) {
|
|
24589
|
+
const element = document.createElement('section');
|
|
24590
|
+
element.setAttribute('internal-link', '');
|
|
24591
|
+
element.setAttribute('data-internal-link-number', this.__number);
|
|
24592
|
+
element.textContent = this.getTextContent();
|
|
24593
|
+
return {
|
|
24594
|
+
element
|
|
24595
|
+
};
|
|
24596
|
+
}
|
|
24228
24597
|
createDOM(config, editor) {
|
|
24229
24598
|
const span = super.createDOM(config, editor);
|
|
24230
24599
|
span.setAttribute('ignoreusable', '');
|
|
@@ -24240,9 +24609,6 @@ class InternalLinkNode extends lexical.TextDecoratorNode {
|
|
|
24240
24609
|
isInline() {
|
|
24241
24610
|
return true;
|
|
24242
24611
|
}
|
|
24243
|
-
isSelected(selection) {
|
|
24244
|
-
return true;
|
|
24245
|
-
}
|
|
24246
24612
|
getTextContent() {
|
|
24247
24613
|
const insNode = $getInstanceNodeByNumber(this.__number);
|
|
24248
24614
|
if (insNode) {
|
|
@@ -24367,135 +24733,6 @@ function $isPageBreakNode(node) {
|
|
|
24367
24733
|
return node instanceof PageBreakNode;
|
|
24368
24734
|
}
|
|
24369
24735
|
|
|
24370
|
-
/**
|
|
24371
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24372
|
-
*
|
|
24373
|
-
* This source code is licensed under the MIT license found in the
|
|
24374
|
-
* LICENSE file in the root directory of this source tree.
|
|
24375
|
-
*
|
|
24376
|
-
*/
|
|
24377
|
-
|
|
24378
|
-
const ParametersComponent = /*#__PURE__*/React.forwardRef(({
|
|
24379
|
-
nodeKey
|
|
24380
|
-
}, ref) => {
|
|
24381
|
-
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
24382
|
-
const spanRef = React.useRef(null);
|
|
24383
|
-
const [parameters, setParameters,, latestParameters] = hooks.useStore({
|
|
24384
|
-
number: '',
|
|
24385
|
-
value: ''
|
|
24386
|
-
});
|
|
24387
|
-
React.useEffect(() => {
|
|
24388
|
-
editor.read(() => {
|
|
24389
|
-
const node = lexical.$getNodeByKey(nodeKey);
|
|
24390
|
-
if ($isParametersNode(node)) {
|
|
24391
|
-
setParameters(node.parameters);
|
|
24392
|
-
}
|
|
24393
|
-
});
|
|
24394
|
-
return utils$1.mergeRegister(editor.registerCommand(PARAMETERS_UPDATE, ({
|
|
24395
|
-
number,
|
|
24396
|
-
value
|
|
24397
|
-
}) => {
|
|
24398
|
-
const latest = latestParameters.current;
|
|
24399
|
-
if (number !== latest.number) {
|
|
24400
|
-
return false;
|
|
24401
|
-
}
|
|
24402
|
-
const node = lexical.$getNodeByKey(nodeKey);
|
|
24403
|
-
if ($isParametersNode(node)) {
|
|
24404
|
-
setParameters({
|
|
24405
|
-
value
|
|
24406
|
-
});
|
|
24407
|
-
Object.assign(node.parameters, {
|
|
24408
|
-
value
|
|
24409
|
-
});
|
|
24410
|
-
}
|
|
24411
|
-
return true;
|
|
24412
|
-
}, lexical.COMMAND_PRIORITY_EDITOR));
|
|
24413
|
-
}, []);
|
|
24414
|
-
React.useImperativeHandle(ref, () => {
|
|
24415
|
-
return {
|
|
24416
|
-
getValue() {
|
|
24417
|
-
return latestParameters.current.value;
|
|
24418
|
-
}
|
|
24419
|
-
};
|
|
24420
|
-
}, []);
|
|
24421
|
-
return /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
24422
|
-
ref: spanRef,
|
|
24423
|
-
role: "button",
|
|
24424
|
-
tabIndex: 0,
|
|
24425
|
-
children: parameters.value
|
|
24426
|
-
});
|
|
24427
|
-
});
|
|
24428
|
-
|
|
24429
|
-
/**
|
|
24430
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24431
|
-
*
|
|
24432
|
-
* This source code is licensed under the MIT license found in the
|
|
24433
|
-
* LICENSE file in the root directory of this source tree.
|
|
24434
|
-
*
|
|
24435
|
-
*/
|
|
24436
|
-
|
|
24437
|
-
class ParametersNode extends lexical.TextDecoratorNode {
|
|
24438
|
-
/** 用于存储参数数据,保证每次读取能获取到最新值 */
|
|
24439
|
-
static collection = new Map();
|
|
24440
|
-
/** 初始化值 */
|
|
24441
|
-
|
|
24442
|
-
__ref = /*#__PURE__*/React.createRef();
|
|
24443
|
-
|
|
24444
|
-
/** 最新的值 */
|
|
24445
|
-
get parameters() {
|
|
24446
|
-
return ParametersNode.collection.get(this.__parameters.number) || this.__parameters;
|
|
24447
|
-
}
|
|
24448
|
-
static getType() {
|
|
24449
|
-
return 'Parameters';
|
|
24450
|
-
}
|
|
24451
|
-
static clone(node) {
|
|
24452
|
-
return new ParametersNode(Object.assign({}, node.parameters), node.__key);
|
|
24453
|
-
}
|
|
24454
|
-
static importJSON(serializedNode) {
|
|
24455
|
-
return $createParametersNode(serializedNode.parameters).updateFromJSON(serializedNode);
|
|
24456
|
-
}
|
|
24457
|
-
constructor(parameters, key) {
|
|
24458
|
-
super(key);
|
|
24459
|
-
this.__parameters = parameters;
|
|
24460
|
-
}
|
|
24461
|
-
exportJSON() {
|
|
24462
|
-
return {
|
|
24463
|
-
...super.exportJSON(),
|
|
24464
|
-
parameters: this.parameters
|
|
24465
|
-
};
|
|
24466
|
-
}
|
|
24467
|
-
createDOM(config, editor) {
|
|
24468
|
-
const span = super.createDOM(config, editor);
|
|
24469
|
-
span.setAttribute('ignoreusable', '');
|
|
24470
|
-
span.setAttribute('key', this.getKey());
|
|
24471
|
-
return span;
|
|
24472
|
-
}
|
|
24473
|
-
updateDOM(prevNode, dom, config) {
|
|
24474
|
-
return super.updateDOM(prevNode, dom, config);
|
|
24475
|
-
}
|
|
24476
|
-
collapseAtStart() {
|
|
24477
|
-
return true;
|
|
24478
|
-
}
|
|
24479
|
-
isInline() {
|
|
24480
|
-
return true;
|
|
24481
|
-
}
|
|
24482
|
-
getTextContent() {
|
|
24483
|
-
return this.__ref.current?.getValue() || '';
|
|
24484
|
-
}
|
|
24485
|
-
decorate(editor, config) {
|
|
24486
|
-
return /*#__PURE__*/jsxRuntime.jsx(ParametersComponent, {
|
|
24487
|
-
ref: this.__ref,
|
|
24488
|
-
nodeKey: this.getKey()
|
|
24489
|
-
});
|
|
24490
|
-
}
|
|
24491
|
-
}
|
|
24492
|
-
function $createParametersNode(parameters) {
|
|
24493
|
-
return lexical.$applyNodeReplacement(new ParametersNode(parameters));
|
|
24494
|
-
}
|
|
24495
|
-
function $isParametersNode(node) {
|
|
24496
|
-
return node instanceof ParametersNode;
|
|
24497
|
-
}
|
|
24498
|
-
|
|
24499
24736
|
/**
|
|
24500
24737
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
24501
24738
|
*
|
|
@@ -24770,9 +25007,12 @@ function EquationComponent({
|
|
|
24770
25007
|
editor.update(() => {
|
|
24771
25008
|
const node = lexical.$getNodeByKey(nodeKey);
|
|
24772
25009
|
if ($isInstanceEquationNode(node)) {
|
|
24773
|
-
node.
|
|
24774
|
-
if (
|
|
24775
|
-
node.
|
|
25010
|
+
const oldValue = node.getEquation();
|
|
25011
|
+
if (oldValue !== equationValue) {
|
|
25012
|
+
node.setEquation(equationValue);
|
|
25013
|
+
if (restoreSelection) {
|
|
25014
|
+
node.selectNext(0, 0);
|
|
25015
|
+
}
|
|
24776
25016
|
}
|
|
24777
25017
|
}
|
|
24778
25018
|
});
|
|
@@ -24809,17 +25049,21 @@ function EquationComponent({
|
|
|
24809
25049
|
return false;
|
|
24810
25050
|
}, lexical.COMMAND_PRIORITY_HIGH));
|
|
24811
25051
|
} else {
|
|
24812
|
-
return editor.registerUpdateListener(
|
|
24813
|
-
|
|
24814
|
-
|
|
24815
|
-
|
|
24816
|
-
|
|
24817
|
-
|
|
24818
|
-
|
|
24819
|
-
|
|
24820
|
-
|
|
25052
|
+
return utils$1.mergeRegister(editor.registerUpdateListener(listener => {
|
|
25053
|
+
const {
|
|
25054
|
+
editorState,
|
|
25055
|
+
tags
|
|
25056
|
+
} = listener;
|
|
25057
|
+
if (!tags.has('historic')) {
|
|
25058
|
+
const isSelected = editorState.read(() => {
|
|
25059
|
+
const selection = lexical.$getSelection();
|
|
25060
|
+
return lexical.$isNodeSelection(selection) && selection.has(nodeKey) && selection.getNodes().length === 1;
|
|
25061
|
+
});
|
|
25062
|
+
if (isSelected) {
|
|
25063
|
+
setShowEquationEditor(true);
|
|
25064
|
+
}
|
|
24821
25065
|
}
|
|
24822
|
-
});
|
|
25066
|
+
}));
|
|
24823
25067
|
}
|
|
24824
25068
|
}, [editor, nodeKey, onHide, showEquationEditor, isEditable]);
|
|
24825
25069
|
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
@@ -25529,6 +25773,7 @@ exports.$createImageNode = $createImageNode;
|
|
|
25529
25773
|
exports.$createInlineImageNode = $createInlineImageNode;
|
|
25530
25774
|
exports.$createInstanceCodeHighlightNode = $createInstanceCodeHighlightNode;
|
|
25531
25775
|
exports.$createInstanceCodeNode = $createInstanceCodeNode;
|
|
25776
|
+
exports.$createInstanceContentNode = $createInstanceContentNode;
|
|
25532
25777
|
exports.$createInstanceEquationNode = $createInstanceEquationNode;
|
|
25533
25778
|
exports.$createInstanceHeadingNode = $createInstanceHeadingNode;
|
|
25534
25779
|
exports.$createInstanceHorizontalRuleNode = $createInstanceHorizontalRuleNode;
|
|
@@ -25570,6 +25815,7 @@ exports.$isInInstanceTitleNode = $isInInstanceTitleNode;
|
|
|
25570
25815
|
exports.$isInlineImageNode = $isInlineImageNode;
|
|
25571
25816
|
exports.$isInstanceCodeHighlightNode = $isInstanceCodeHighlightNode;
|
|
25572
25817
|
exports.$isInstanceCodeNode = $isInstanceCodeNode;
|
|
25818
|
+
exports.$isInstanceContentNode = $isInstanceContentNode;
|
|
25573
25819
|
exports.$isInstanceEquationNode = $isInstanceEquationNode;
|
|
25574
25820
|
exports.$isInstanceHeadingNode = $isInstanceHeadingNode;
|
|
25575
25821
|
exports.$isInstanceHorizontalRuleNode = $isInstanceHorizontalRuleNode;
|
|
@@ -25596,7 +25842,9 @@ exports.$nodeUpgrade = $nodeUpgrade;
|
|
|
25596
25842
|
exports.$removeHighestEmptyListParent = $removeHighestEmptyListParent;
|
|
25597
25843
|
exports.$removeList = $removeList;
|
|
25598
25844
|
exports.$scrollTo = $scrollTo;
|
|
25599
|
-
exports.$
|
|
25845
|
+
exports.$scrollToByNode = $scrollToByNode;
|
|
25846
|
+
exports.$selectTextDecoratorNode = $selectTextDecoratorNode;
|
|
25847
|
+
exports.$unifiedCreateParametersNode = $unifiedCreateParametersNode;
|
|
25600
25848
|
exports.$updateRichHistoryStateMap = $updateRichHistoryStateMap;
|
|
25601
25849
|
exports.$updateRichInstanceContent = $updateRichInstanceContent;
|
|
25602
25850
|
exports.$updateRichInstanceTitle = $updateRichInstanceTitle;
|
|
@@ -25619,6 +25867,7 @@ exports.ImageNode = ImageNode;
|
|
|
25619
25867
|
exports.InlineImageNode = InlineImageNode;
|
|
25620
25868
|
exports.InstanceCodeHighlightNode = InstanceCodeHighlightNode;
|
|
25621
25869
|
exports.InstanceCodeNode = InstanceCodeNode;
|
|
25870
|
+
exports.InstanceContentNode = InstanceContentNode;
|
|
25622
25871
|
exports.InstanceEquationNode = InstanceEquationNode;
|
|
25623
25872
|
exports.InstanceHeadingNode = InstanceHeadingNode;
|
|
25624
25873
|
exports.InstanceHorizontalRuleNode = InstanceHorizontalRuleNode;
|
|
@@ -25635,12 +25884,15 @@ exports.InternalLinkNode = InternalLinkNode;
|
|
|
25635
25884
|
exports.KeywordNode = KeywordNode;
|
|
25636
25885
|
exports.NumberDecoratorNode = NumberDecoratorNode;
|
|
25637
25886
|
exports.OPEN_CREATE_WINDOW = OPEN_CREATE_WINDOW;
|
|
25887
|
+
exports.OPEN_PARAMS = OPEN_PARAMS;
|
|
25638
25888
|
exports.PARAMETERS_UPDATE = PARAMETERS_UPDATE;
|
|
25639
25889
|
exports.PageBreakNode = PageBreakNode;
|
|
25640
25890
|
exports.ParametersNode = ParametersNode;
|
|
25641
25891
|
exports.PlaceholderDecoratorNode = PlaceholderDecoratorNode;
|
|
25892
|
+
exports.PrismTokenizer = PrismTokenizer;
|
|
25642
25893
|
exports.SPLIT_INSTANCE_NODE = SPLIT_INSTANCE_NODE;
|
|
25643
25894
|
exports.clearCache = clearCache;
|
|
25895
|
+
exports.codeNodeTransform = codeNodeTransform;
|
|
25644
25896
|
exports.correctedInstanceParagraph = correctedInstanceParagraph;
|
|
25645
25897
|
exports.fixedAddress = fixedAddress;
|
|
25646
25898
|
exports.getCachedClassNameArray = getCachedClassNameArray;
|
|
@@ -25655,6 +25907,7 @@ exports.instanceNodeMap = instanceNodeMap;
|
|
|
25655
25907
|
exports.internalLinkNameUpdateMap = internalLinkNameUpdateMap;
|
|
25656
25908
|
exports.isCompleteInstance = isCompleteInstance;
|
|
25657
25909
|
exports.isNestedListNode = isNestedListNode;
|
|
25910
|
+
exports.isTemporaryInsId = isTemporaryInsId;
|
|
25658
25911
|
exports.mergeLists = mergeLists;
|
|
25659
25912
|
exports.mergeNextSiblingListIfSameType = mergeNextSiblingListIfSameType;
|
|
25660
25913
|
exports.nodeMoveDown = nodeMoveDown;
|
|
@@ -25669,3 +25922,4 @@ exports.setTemporaryContentText = setTemporaryContentText;
|
|
|
25669
25922
|
exports.updateChildrenListItemValue = updateChildrenListItemValue;
|
|
25670
25923
|
exports.updateRelatedInternalLink = updateRelatedInternalLink;
|
|
25671
25924
|
exports.useContentEditable = useContentEditable;
|
|
25925
|
+
exports.useSelectedIds = useSelectedIds;
|