onchain-lexical-instance 0.0.12 → 0.0.13

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.
@@ -15,10 +15,11 @@ 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 onchainLexicalMarkdown = require('onchain-lexical-markdown');
19
18
  var list = require('@lexical/list');
20
- var selection = require('@lexical/selection');
21
19
  var table = require('@lexical/table');
20
+ var onchainLexicalMarkdown = require('onchain-lexical-markdown');
21
+ var traversal = require('onchain-utility/traversal');
22
+ var selection = require('@lexical/selection');
22
23
  var useLexicalNodeSelection = require('@lexical/react/useLexicalNodeSelection');
23
24
  var hooks = require('onchain-utility/hooks');
24
25
  var richText = require('@lexical/rich-text');
@@ -40,7 +41,6 @@ var sharedHistory = require('onchain-lexical-context/sharedHistory');
40
41
  var ContentEditable = require('onchain-lexical-ui/ContentEditable');
41
42
  var ImageResizer = require('onchain-lexical-ui/ImageResizer');
42
43
  var onchainUtility = require('onchain-utility');
43
- var traversal = require('onchain-utility/traversal');
44
44
  var Skeleton = require('onchain-lexical-ui/Skeleton');
45
45
  var settings = require('onchain-lexical-context/settings');
46
46
  var DropDown = require('onchain-lexical-ui/DropDown');
@@ -143,6 +143,9 @@ const OPEN_CREATE_WINDOW = lexical.createCommand('OPEN_CREATE_WINDOW');
143
143
  /** 添加新的实例节点 */
144
144
  const ADD_NEW_INSTANCE_NODE = lexical.createCommand('ADD_NEW_INSTANCE_NODE');
145
145
 
146
+ /** 拆分的实例节点 */
147
+ const SPLIT_INSTANCE_NODE = lexical.createCommand('ADD_NEW_INSTANCE_NODE');
148
+
146
149
  /** 删除实例节点 */
147
150
  const DELETE_INSTANCE_NODE = 'DELETE_INSTANCE_NODE';
148
151
 
@@ -1088,6 +1091,59 @@ function correctedInstanceParagraph(nodes, createParagraph) {
1088
1091
  return nodes;
1089
1092
  }
1090
1093
 
1094
+ /** 添加新实例节点 */
1095
+ function $addInstancesNode({
1096
+ isAddChildLevel,
1097
+ instances,
1098
+ insNodeKey
1099
+ }) {
1100
+ if (insNodeKey) {
1101
+ const insNode = lexical.$getNodeByKey(insNodeKey);
1102
+ if ($isInstanceNode(insNode)) {
1103
+ const newInsNodes = instances.map(instance => {
1104
+ const contentText = getTemporaryContentText(instance);
1105
+ if (contentText) {
1106
+ const node = $createTitleOnlyInstanceNode(instance);
1107
+ const fragment = $createFragmentNode();
1108
+ onchainLexicalMarkdown.$textToRichNodes(fragment, contentText);
1109
+ const nodes = correctedInstanceParagraph(fragment.getChildren(), () => $createInstanceParagraphNode());
1110
+ node.append(...nodes);
1111
+ return node;
1112
+ } else {
1113
+ return $createInstanceNode(instance);
1114
+ }
1115
+ });
1116
+ if (isAddChildLevel) {
1117
+ const [insChildNode] = insNode.getSelfInstanceChildren();
1118
+ if (insChildNode) {
1119
+ for (let index = newInsNodes.length - 1; index > -1; index--) {
1120
+ const current = newInsNodes[index];
1121
+ const pre = newInsNodes[index + 1];
1122
+ if (pre) {
1123
+ pre.insertBefore(current);
1124
+ } else {
1125
+ insChildNode.insertBefore(current);
1126
+ }
1127
+ }
1128
+ } else {
1129
+ insNode.append(...newInsNodes);
1130
+ }
1131
+ } else {
1132
+ for (let index = 0; index < newInsNodes.length; index++) {
1133
+ const current = newInsNodes[index];
1134
+ const pre = newInsNodes[index - 1];
1135
+ if (pre) {
1136
+ pre.insertAfter(current);
1137
+ } else {
1138
+ insNode.insertAfter(current);
1139
+ }
1140
+ }
1141
+ }
1142
+ newInsNodes[0].selectStart();
1143
+ }
1144
+ }
1145
+ }
1146
+
1091
1147
  /**
1092
1148
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1093
1149
  *
@@ -23228,165 +23284,6 @@ function $handleListInsertParagraph() {
23228
23284
  return true;
23229
23285
  }
23230
23286
 
23231
- /** @noInheritDoc */
23232
- class InstanceListNode extends list.ListNode {
23233
- static getType() {
23234
- return 'List';
23235
- }
23236
- static clone(node) {
23237
- const listType = node.__listType || TAG_TO_LIST_TYPE[node.__tag];
23238
- return new InstanceListNode(listType, node.__start, node.__key);
23239
- }
23240
- static transform() {
23241
- return node => {
23242
- if (!$isInstanceListNode(node)) {
23243
- formatDevErrorMessage(`node is not a InstanceListNode`);
23244
- }
23245
- mergeNextSiblingListIfSameType(node);
23246
- updateChildrenListItemValue(node);
23247
- };
23248
- }
23249
- static importDOM() {
23250
- return {
23251
- ol: () => ({
23252
- conversion: $convertInstanceListNode,
23253
- priority: 0
23254
- }),
23255
- ul: () => ({
23256
- conversion: $convertInstanceListNode,
23257
- priority: 0
23258
- })
23259
- };
23260
- }
23261
- static importJSON(serializedNode) {
23262
- return $createInstanceListNode().updateFromJSON(serializedNode);
23263
- }
23264
- createDOM(config) {
23265
- const element = super.createDOM(config);
23266
- setDisable(this, element);
23267
- return element;
23268
- }
23269
- updateFromJSON(serializedNode) {
23270
- return super.updateFromJSON(serializedNode).setListType(serializedNode.listType).setStart(serializedNode.start);
23271
- }
23272
- exportJSON() {
23273
- return {
23274
- ...super.exportJSON(),
23275
- listType: this.getListType(),
23276
- start: this.getStart(),
23277
- tag: this.getTag()
23278
- };
23279
- }
23280
- splice(start, deleteCount, nodesToInsert) {
23281
- let listItemNodesToInsert = nodesToInsert;
23282
- for (let i = 0; i < nodesToInsert.length; i++) {
23283
- const node = nodesToInsert[i];
23284
- if (!$isInstanceListItemNode(node)) {
23285
- if (listItemNodesToInsert === nodesToInsert) {
23286
- listItemNodesToInsert = [...nodesToInsert];
23287
- }
23288
- listItemNodesToInsert[i] = $createInstanceListItemNode().append(lexical.$isElementNode(node) && !($isInstanceListNode(node) || node.isInline()) ? lexical.$createTextNode(node.getTextContent()) : node);
23289
- }
23290
- }
23291
- return super.splice(start, deleteCount, listItemNodesToInsert);
23292
- }
23293
- extractWithChild(child) {
23294
- return $isInstanceListItemNode(child);
23295
- }
23296
- }
23297
-
23298
- /*
23299
- * This function normalizes the children of a InstanceListNode after the conversion from HTML,
23300
- * ensuring that they are all ListItemNodes and contain either a single nested InstanceListNode
23301
- * or some other inline content.
23302
- */
23303
- function $normalizeChildren(nodes) {
23304
- const normalizedListItems = [];
23305
- for (let i = 0; i < nodes.length; i++) {
23306
- const node = nodes[i];
23307
- if ($isInstanceListItemNode(node)) {
23308
- normalizedListItems.push(node);
23309
- const children = node.getChildren();
23310
- if (children.length > 1) {
23311
- children.forEach(child => {
23312
- if ($isInstanceListNode(child)) {
23313
- normalizedListItems.push($wrapInInstanceListItem(child));
23314
- }
23315
- });
23316
- }
23317
- } else {
23318
- normalizedListItems.push($wrapInInstanceListItem(node));
23319
- }
23320
- }
23321
- return normalizedListItems;
23322
- }
23323
- function isDomChecklist(domNode) {
23324
- if (domNode.getAttribute('__lexicallisttype') === 'check' ||
23325
- // is github checklist
23326
- domNode.classList.contains('contains-task-list')) {
23327
- return true;
23328
- }
23329
- // if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
23330
- for (const child of domNode.childNodes) {
23331
- if (lexical.isHTMLElement(child) && child.hasAttribute('aria-checked')) {
23332
- return true;
23333
- }
23334
- }
23335
- return false;
23336
- }
23337
- function $convertInstanceListNode(domNode) {
23338
- const nodeName = domNode.nodeName.toLowerCase();
23339
- let node = null;
23340
- if (nodeName === 'ol') {
23341
- // @ts-ignore
23342
- const start = domNode.start;
23343
- node = $createInstanceListNode('number', start);
23344
- } else if (nodeName === 'ul') {
23345
- if (isDomChecklist(domNode)) {
23346
- node = $createInstanceListNode('check');
23347
- } else {
23348
- node = $createInstanceListNode('bullet');
23349
- }
23350
- }
23351
- return {
23352
- after: $normalizeChildren,
23353
- node
23354
- };
23355
- }
23356
- const TAG_TO_LIST_TYPE = {
23357
- ol: 'number',
23358
- ul: 'bullet'
23359
- };
23360
-
23361
- /**
23362
- * Wraps a node into a ListItemNode.
23363
- * @param node - The node to be wrapped into a ListItemNode
23364
- * @returns The ListItemNode which the passed node is wrapped in.
23365
- */
23366
- function $wrapInInstanceListItem(node) {
23367
- const listItemWrapper = $createInstanceListItemNode();
23368
- return listItemWrapper.append(node);
23369
- }
23370
-
23371
- /**
23372
- * Creates a InstanceListNode of listType.
23373
- * @param listType - The type of list to be created. Can be 'number', 'bullet', or 'check'.
23374
- * @param start - Where an ordered list starts its count, start = 1 if left undefined.
23375
- * @returns The new InstanceListNode
23376
- */
23377
- function $createInstanceListNode(listType = 'number', start = 1) {
23378
- return lexical.$applyNodeReplacement(new InstanceListNode(listType, start));
23379
- }
23380
-
23381
- /**
23382
- * Checks to see if the node is a InstanceListNode.
23383
- * @param node - The node to be checked.
23384
- * @returns true if the node is a InstanceListNode, false otherwise.
23385
- */
23386
- function $isInstanceListNode(node) {
23387
- return node instanceof InstanceListNode;
23388
- }
23389
-
23390
23287
  /** @noInheritDoc */
23391
23288
  class InstanceListItemNode extends list.ListItemNode {
23392
23289
  static getType() {
@@ -23514,6 +23411,9 @@ class InstanceListItemNode extends list.ListItemNode {
23514
23411
  super.remove(preserveEmptyParent);
23515
23412
  }
23516
23413
  }
23414
+ defaultRemove(preserveEmptyParent) {
23415
+ super.remove(preserveEmptyParent);
23416
+ }
23517
23417
  insertNewAfter(selection$1, restoreSelection = true) {
23518
23418
  const [node] = selection$1.getNodes();
23519
23419
  if ($isInstanceListItemNode(node) && node.getChildren().length === 0) {
@@ -23614,6 +23514,165 @@ function $registerInstanceListItemInsertParagraph(editor) {
23614
23514
  }, lexical.COMMAND_PRIORITY_NORMAL);
23615
23515
  }
23616
23516
 
23517
+ /** @noInheritDoc */
23518
+ class InstanceListNode extends list.ListNode {
23519
+ static getType() {
23520
+ return 'List';
23521
+ }
23522
+ static clone(node) {
23523
+ const listType = node.__listType || TAG_TO_LIST_TYPE[node.__tag];
23524
+ return new InstanceListNode(listType, node.__start, node.__key);
23525
+ }
23526
+ static transform() {
23527
+ return node => {
23528
+ if (!$isInstanceListNode(node)) {
23529
+ formatDevErrorMessage(`node is not a InstanceListNode`);
23530
+ }
23531
+ mergeNextSiblingListIfSameType(node);
23532
+ updateChildrenListItemValue(node);
23533
+ };
23534
+ }
23535
+ static importDOM() {
23536
+ return {
23537
+ ol: () => ({
23538
+ conversion: $convertInstanceListNode,
23539
+ priority: 0
23540
+ }),
23541
+ ul: () => ({
23542
+ conversion: $convertInstanceListNode,
23543
+ priority: 0
23544
+ })
23545
+ };
23546
+ }
23547
+ static importJSON(serializedNode) {
23548
+ return $createInstanceListNode().updateFromJSON(serializedNode);
23549
+ }
23550
+ createDOM(config) {
23551
+ const element = super.createDOM(config);
23552
+ setDisable(this, element);
23553
+ return element;
23554
+ }
23555
+ updateFromJSON(serializedNode) {
23556
+ return super.updateFromJSON(serializedNode).setListType(serializedNode.listType).setStart(serializedNode.start);
23557
+ }
23558
+ exportJSON() {
23559
+ return {
23560
+ ...super.exportJSON(),
23561
+ listType: this.getListType(),
23562
+ start: this.getStart(),
23563
+ tag: this.getTag()
23564
+ };
23565
+ }
23566
+ splice(start, deleteCount, nodesToInsert) {
23567
+ let listItemNodesToInsert = nodesToInsert;
23568
+ for (let i = 0; i < nodesToInsert.length; i++) {
23569
+ const node = nodesToInsert[i];
23570
+ if (!$isInstanceListItemNode(node)) {
23571
+ if (listItemNodesToInsert === nodesToInsert) {
23572
+ listItemNodesToInsert = [...nodesToInsert];
23573
+ }
23574
+ listItemNodesToInsert[i] = $createInstanceListItemNode().append(lexical.$isElementNode(node) && !($isInstanceListNode(node) || node.isInline()) ? lexical.$createTextNode(node.getTextContent()) : node);
23575
+ }
23576
+ }
23577
+ return super.splice(start, deleteCount, listItemNodesToInsert);
23578
+ }
23579
+ extractWithChild(child) {
23580
+ return $isInstanceListItemNode(child);
23581
+ }
23582
+ }
23583
+
23584
+ /*
23585
+ * This function normalizes the children of a InstanceListNode after the conversion from HTML,
23586
+ * ensuring that they are all ListItemNodes and contain either a single nested InstanceListNode
23587
+ * or some other inline content.
23588
+ */
23589
+ function $normalizeChildren(nodes) {
23590
+ const normalizedListItems = [];
23591
+ for (let i = 0; i < nodes.length; i++) {
23592
+ const node = nodes[i];
23593
+ if ($isInstanceListItemNode(node)) {
23594
+ normalizedListItems.push(node);
23595
+ const children = node.getChildren();
23596
+ if (children.length > 1) {
23597
+ children.forEach(child => {
23598
+ if ($isInstanceListNode(child)) {
23599
+ normalizedListItems.push($wrapInInstanceListItem(child));
23600
+ }
23601
+ });
23602
+ }
23603
+ } else {
23604
+ normalizedListItems.push($wrapInInstanceListItem(node));
23605
+ }
23606
+ }
23607
+ return normalizedListItems;
23608
+ }
23609
+ function isDomChecklist(domNode) {
23610
+ if (domNode.getAttribute('__lexicallisttype') === 'check' ||
23611
+ // is github checklist
23612
+ domNode.classList.contains('contains-task-list')) {
23613
+ return true;
23614
+ }
23615
+ // if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
23616
+ for (const child of domNode.childNodes) {
23617
+ if (lexical.isHTMLElement(child) && child.hasAttribute('aria-checked')) {
23618
+ return true;
23619
+ }
23620
+ }
23621
+ return false;
23622
+ }
23623
+ function $convertInstanceListNode(domNode) {
23624
+ const nodeName = domNode.nodeName.toLowerCase();
23625
+ let node = null;
23626
+ if (nodeName === 'ol') {
23627
+ // @ts-ignore
23628
+ const start = domNode.start;
23629
+ node = $createInstanceListNode('number', start);
23630
+ } else if (nodeName === 'ul') {
23631
+ if (isDomChecklist(domNode)) {
23632
+ node = $createInstanceListNode('check');
23633
+ } else {
23634
+ node = $createInstanceListNode('bullet');
23635
+ }
23636
+ }
23637
+ return {
23638
+ after: $normalizeChildren,
23639
+ node
23640
+ };
23641
+ }
23642
+ const TAG_TO_LIST_TYPE = {
23643
+ ol: 'number',
23644
+ ul: 'bullet'
23645
+ };
23646
+
23647
+ /**
23648
+ * Wraps a node into a ListItemNode.
23649
+ * @param node - The node to be wrapped into a ListItemNode
23650
+ * @returns The ListItemNode which the passed node is wrapped in.
23651
+ */
23652
+ function $wrapInInstanceListItem(node) {
23653
+ const listItemWrapper = $createInstanceListItemNode();
23654
+ return listItemWrapper.append(node);
23655
+ }
23656
+
23657
+ /**
23658
+ * Creates a InstanceListNode of listType.
23659
+ * @param listType - The type of list to be created. Can be 'number', 'bullet', or 'check'.
23660
+ * @param start - Where an ordered list starts its count, start = 1 if left undefined.
23661
+ * @returns The new InstanceListNode
23662
+ */
23663
+ function $createInstanceListNode(listType = 'number', start = 1) {
23664
+ return lexical.$applyNodeReplacement(new InstanceListNode(listType, start));
23665
+ }
23666
+
23667
+ /**
23668
+ * Checks to see if the node is a InstanceListNode.
23669
+ * @param node - The node to be checked.
23670
+ * @returns true if the node is a InstanceListNode, false otherwise.
23671
+ */
23672
+ function $isInstanceListNode(node) {
23673
+ return node instanceof InstanceListNode;
23674
+ }
23675
+
23617
23676
  /** @noInheritDoc */
23618
23677
  class InstanceTableNode extends table.TableNode {
23619
23678
  static getType() {
@@ -23778,49 +23837,131 @@ const InstancePlugin = props => {
23778
23837
  instances,
23779
23838
  isAddChildLevel
23780
23839
  }) => {
23781
- if (insNodeKey) {
23782
- const insNode = lexical.$getNodeByKey(insNodeKey);
23783
- if ($isInstanceNode(insNode)) {
23784
- const newInsNodes = instances.map(instance => {
23785
- const contentText = getTemporaryContentText(instance);
23786
- if (contentText) {
23787
- const node = $createTitleOnlyInstanceNode(instance);
23788
- const fragment = $createFragmentNode();
23789
- onchainLexicalMarkdown.$textToRichNodes(fragment, contentText);
23790
- const nodes = correctedInstanceParagraph(fragment.getChildren(), () => $createInstanceParagraphNode());
23791
- node.append(...nodes);
23792
- return node;
23793
- } else {
23794
- return $createInstanceNode(instance);
23795
- }
23796
- });
23797
- if (isAddChildLevel) {
23798
- const [insChildNode] = insNode.getSelfInstanceChildren();
23799
- if (insChildNode) {
23800
- for (let index = newInsNodes.length - 1; index > -1; index--) {
23801
- const current = newInsNodes[index];
23802
- const pre = newInsNodes[index + 1];
23803
- if (pre) {
23804
- pre.insertBefore(current);
23805
- } else {
23806
- insChildNode.insertBefore(current);
23807
- }
23840
+ $addInstancesNode({
23841
+ insNodeKey,
23842
+ instances,
23843
+ isAddChildLevel
23844
+ });
23845
+ return true;
23846
+ }, lexical.COMMAND_PRIORITY_LOW), /** 需求拆分 */
23847
+ editor.registerCommand(SPLIT_INSTANCE_NODE, ({
23848
+ selection,
23849
+ insNodeKey,
23850
+ instance,
23851
+ isAddChildLevel
23852
+ }) => {
23853
+ lexical.$setSelection(null);
23854
+ if (lexical.$isRangeSelection(selection) || table.$isTableSelection(selection)) {
23855
+ const forwardSelection = lexical.$createRangeSelection();
23856
+ const [startPoint, endPoint] = selection.isBackward() ? [selection.focus, selection.anchor] : [selection.anchor, selection.focus];
23857
+ forwardSelection.anchor.set(startPoint.key, startPoint.offset, startPoint.type);
23858
+ forwardSelection.focus.set(endPoint.key, endPoint.offset, endPoint.type);
23859
+ const nodes = forwardSelection.extract();
23860
+ const hasElementNode = nodes.some(node => lexical.$isElementNode(node));
23861
+ const elementNodes = [];
23862
+ if (!hasElementNode) {
23863
+ const paragraph = $createInstanceParagraphNode();
23864
+ nodes.forEach(node => node.remove());
23865
+ paragraph.append(...nodes);
23866
+ elementNodes.push(paragraph);
23867
+ } else {
23868
+ if (table.$isTableSelection(selection)) {
23869
+ const size = {
23870
+ cell: 0,
23871
+ row: 0,
23872
+ rowIndex: Infinity
23873
+ };
23874
+ const newRowMap = new Map();
23875
+ const configs = selection.getNodes().filter(node => table.$isTableCellNode(node)).map(node => {
23876
+ const row = node.getParent();
23877
+ const rowIndex = row.getIndexWithinParent();
23878
+ if (size.rowIndex !== rowIndex) {
23879
+ size.rowIndex = rowIndex;
23880
+ size.cell = 1;
23881
+ size.row++;
23882
+ } else {
23883
+ size.cell++;
23808
23884
  }
23885
+ if (!newRowMap.has(rowIndex)) {
23886
+ newRowMap.set(rowIndex, table.$createTableRowNode());
23887
+ }
23888
+ return {
23889
+ col: node.getIndexWithinParent(),
23890
+ node,
23891
+ rowIndex: rowIndex,
23892
+ rowNode: row
23893
+ };
23894
+ });
23895
+ const tableNode = $createInstanceTableNode();
23896
+ const maxCellSize = configs[0].rowNode.getChildrenSize();
23897
+ const maxRowSize = configs[0].rowNode.getParent()?.getChildrenSize();
23898
+ if (size.cell === maxCellSize) {
23899
+ tableNode.append(...configs.map(config => config.rowNode));
23809
23900
  } else {
23810
- insNode.append(...newInsNodes);
23901
+ configs.forEach(config => {
23902
+ const rowNode = newRowMap.get(config.rowIndex) || newRowMap.set(config.rowIndex, table.$createTableRowNode()).get(config.rowIndex);
23903
+ if (size.row !== maxRowSize) {
23904
+ config.node.replace(table.$createTableCellNode());
23905
+ }
23906
+ rowNode.append(config.node);
23907
+ });
23908
+ newRowMap.values().forEach(row => {
23909
+ tableNode.append(row);
23910
+ });
23811
23911
  }
23912
+ elementNodes.push(tableNode);
23812
23913
  } else {
23813
- for (let index = 0; index < newInsNodes.length; index++) {
23814
- const current = newInsNodes[index];
23815
- const pre = newInsNodes[index - 1];
23816
- if (pre) {
23817
- pre.insertAfter(current);
23818
- } else {
23819
- insNode.insertAfter(current);
23914
+ const [startNode, endNode] = [startPoint.getNode(), endPoint.getNode()];
23915
+ const startAncestors = getAncestors(startNode);
23916
+ const endAncestors = getAncestors(endNode);
23917
+ const sameLevel = new Map();
23918
+ startAncestors.some((sa, idx) => {
23919
+ const eaIdx = endAncestors.findIndex((ea, idx) => ea.getKey() === sa.getKey());
23920
+ const isSame = eaIdx > -1;
23921
+ if (isSame) {
23922
+ sameLevel.set('start', startAncestors[idx - 1]);
23923
+ sameLevel.set('end', endAncestors[eaIdx - 1]);
23924
+ }
23925
+ return isSame;
23926
+ });
23927
+ const next = $getFollowUpNode({
23928
+ node: startNode,
23929
+ terminate: sameLevel.get('start'),
23930
+ type: 'getNextSiblings'
23931
+ });
23932
+ const previous = $getFollowUpNode({
23933
+ node: endNode.getNextSibling() || endNode,
23934
+ terminate: sameLevel.get('end'),
23935
+ type: 'getPreviousSiblings'
23936
+ });
23937
+ let node = next.original.getNextSibling();
23938
+ while (node && node.getKey() !== previous.original.getKey()) {
23939
+ elementNodes.push(node);
23940
+ node = node.getNextSibling();
23941
+ }
23942
+ elementNodes.unshift(...next.nodes);
23943
+ elementNodes.push(...previous.nodes);
23944
+ // 添加嵌套Item父List
23945
+ if (elementNodes.every(node => list.$isListItemNode(node))) {
23946
+ const originalListNode = utils$1.$findMatchingParent(next.original, node => $isInstanceListNode(node));
23947
+ if (originalListNode) {
23948
+ const listNode = $createInstanceListNode(originalListNode.getListType());
23949
+ listNode.append(...elementNodes);
23950
+ elementNodes.length = 0;
23951
+ elementNodes.push(listNode);
23820
23952
  }
23821
23953
  }
23822
23954
  }
23823
23955
  }
23956
+ const paragraph = $createInstanceParagraphNode();
23957
+ paragraph.append(...elementNodes);
23958
+ const json = lexical.exportNodeToJSON(paragraph);
23959
+ setTemporaryContentText(instance, onchainLexicalMarkdown.getStorageSerializedString(json.children));
23960
+ $addInstancesNode({
23961
+ insNodeKey,
23962
+ instances: [instance],
23963
+ isAddChildLevel
23964
+ });
23824
23965
  }
23825
23966
  return true;
23826
23967
  }, lexical.COMMAND_PRIORITY_LOW));
@@ -23832,6 +23973,119 @@ const InstancePlugin = props => {
23832
23973
  }, []);
23833
23974
  return /*#__PURE__*/React.createElement(React.Fragment, {}, /*#__PURE__*/React.createElement(HorizontalRulePlugin));
23834
23975
  };
23976
+ function getDescendants(node) {
23977
+ if (lexical.$isElementNode(node)) {
23978
+ return traversal.dfs(node.getChildren(), node => {
23979
+ if (lexical.$isElementNode(node)) {
23980
+ return node.getChildren();
23981
+ } else {
23982
+ return [];
23983
+ }
23984
+ });
23985
+ } else {
23986
+ return [];
23987
+ }
23988
+ }
23989
+ function getAncestors(node) {
23990
+ const parent = node.getParent();
23991
+ if (parent) {
23992
+ return traversal.dfs([parent], node => {
23993
+ const parent = node.getParent();
23994
+ if (parent) {
23995
+ return [parent];
23996
+ } else {
23997
+ return [];
23998
+ }
23999
+ });
24000
+ } else {
24001
+ return [];
24002
+ }
24003
+ }
24004
+ function $getFollowUpNode({
24005
+ node,
24006
+ terminate,
24007
+ type
24008
+ }) {
24009
+ const isTableCellNode = table.$isTableCellNode(node);
24010
+ if (isTableCellNode) {
24011
+ const descendants = getDescendants(node);
24012
+ const text = lexical.$createTextNode('');
24013
+ node = text;
24014
+ if (type === 'getNextSiblings') {
24015
+ descendants[0].insertBefore(text);
24016
+ } else {
24017
+ descendants[descendants.length - 1].insertAfter(text);
24018
+ }
24019
+ }
24020
+ const ancestors = terminate ? [terminate] : getAncestors(node);
24021
+ const index = ancestors.findIndex(node => $isInstanceNode(node));
24022
+ const term = ancestors[index - 1] || ancestors[ancestors.length - 1];
24023
+ const original = term;
24024
+
24025
+ // console.log(
24026
+ // {
24027
+ // node,
24028
+ // original,
24029
+ // terminate,
24030
+ // type,
24031
+ // },
24032
+ // 'getFollowUpNode',
24033
+ // );
24034
+
24035
+ const set = new Set();
24036
+ const termKey = term.getKey();
24037
+ traversal.dfs([node], node => {
24038
+ const parent = node.getParent();
24039
+ const parentKey = parent?.getKey();
24040
+ const isStop = parentKey === termKey;
24041
+ const siblings = node[type]();
24042
+ siblings.forEach(sibling => {
24043
+ if ($isInstanceListItemNode(sibling)) {
24044
+ sibling.defaultRemove();
24045
+ return;
24046
+ }
24047
+ sibling.remove();
24048
+ });
24049
+ if (parent) {
24050
+ const constructor = parent.constructor;
24051
+ const newParent = constructor.importJSON(parent.exportJSON());
24052
+ newParent.append(...siblings);
24053
+ if (set.size) {
24054
+ const children = Array.from(set)[0];
24055
+ if (type === 'getNextSiblings') {
24056
+ if (siblings.length) {
24057
+ siblings[0].insertBefore(children);
24058
+ } else {
24059
+ newParent.append(children);
24060
+ }
24061
+ } else {
24062
+ if (siblings.length) {
24063
+ siblings[siblings.length - 1].insertAfter(children);
24064
+ } else {
24065
+ newParent.append(children);
24066
+ }
24067
+ }
24068
+ set.clear();
24069
+ }
24070
+ set.add(newParent);
24071
+ }
24072
+ if (isStop || !parent) {
24073
+ return [];
24074
+ } else {
24075
+ return [parent].filter(Boolean);
24076
+ }
24077
+ });
24078
+ if (isTableCellNode) {
24079
+ const tableNode = utils$1.$findMatchingParent(node, node => $isInstanceTableNode(node));
24080
+ if (tableNode) {
24081
+ tableNode.remove();
24082
+ }
24083
+ }
24084
+ return {
24085
+ nodes: Array.from(set.values()),
24086
+ original
24087
+ };
24088
+ }
23835
24089
 
23836
24090
  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}";
23837
24091
  var Styles$3 = {"internalLink":"styles-module_internalLink__3B9ii"};
@@ -25194,6 +25448,7 @@ var InlineImageComponent$1 = {
25194
25448
  default: InlineImageComponent
25195
25449
  };
25196
25450
 
25451
+ exports.$addInstancesNode = $addInstancesNode;
25197
25452
  exports.$createBarDecoratorNode = $createBarDecoratorNode;
25198
25453
  exports.$createCollapsibleContainerNode = $createCollapsibleContainerNode;
25199
25454
  exports.$createCollapsibleContentNode = $createCollapsibleContentNode;
@@ -25312,6 +25567,7 @@ exports.PARAMETERS_UPDATE = PARAMETERS_UPDATE;
25312
25567
  exports.PageBreakNode = PageBreakNode;
25313
25568
  exports.ParametersNode = ParametersNode;
25314
25569
  exports.PlaceholderDecoratorNode = PlaceholderDecoratorNode;
25570
+ exports.SPLIT_INSTANCE_NODE = SPLIT_INSTANCE_NODE;
25315
25571
  exports.clearCache = clearCache;
25316
25572
  exports.correctedInstanceParagraph = correctedInstanceParagraph;
25317
25573
  exports.fixedAddress = fixedAddress;