onchain-lexical-instance 0.0.11 → 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
 
@@ -158,8 +161,11 @@ const INSTANCE_TITLE_UPDATE = lexical.createCommand('INSTANCE_TITLE_UPDATE');
158
161
  /** 参数更新 */
159
162
  const PARAMETERS_UPDATE = lexical.createCommand('PARAMETERS_UPDATE');
160
163
 
164
+ /** 添加评论 */
165
+ const ADD_COMMENT = lexical.createCommand('ADD_COMMENT');
166
+
161
167
  /** 获取禁止编辑dom节点选择器 */
162
- const DisableSelector = `[contenteditable='false']:not([ignorecontenteditable])`;
168
+ const DisableSelector = `[usable='false']:not([ignoreusable])`;
163
169
 
164
170
  /**
165
171
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -430,7 +436,7 @@ class PlaceholderDecoratorNode extends lexical.DecoratorNode {
430
436
  pointer-events: none;
431
437
  user-select: none;
432
438
  `;
433
- span.setAttribute('ignorecontenteditable', '');
439
+ span.setAttribute('ignoreusable', '');
434
440
  return span;
435
441
  }
436
442
  updateDOM() {
@@ -557,6 +563,7 @@ class InstanceTitleNode extends InstanceHeadingNode {
557
563
  createDOM(config) {
558
564
  const element = super.createDOM(config);
559
565
  element.classList.add(Styles$7['instance-title']);
566
+ element.setAttribute('instance-title', 'true');
560
567
  setDisable(this, element);
561
568
  element.onmousemove = function (event) {
562
569
  const span = event.target;
@@ -975,27 +982,12 @@ function setDisable(node, element) {
975
982
  const parent = node.getParent();
976
983
  if ($isInstanceNode(parent)) {
977
984
  if (parent.__instance.value.disable) {
978
- element.setAttribute('contenteditable', 'false');
985
+ element.setAttribute('usable', 'false');
979
986
  } else {
980
- element.setAttribute('contenteditable', 'true');
987
+ element.setAttribute('usable', 'true');
981
988
  }
982
989
  }
983
990
  }
984
- function ignoreHistory({
985
- editor,
986
- historyState,
987
- update,
988
- updated
989
- }) {
990
- historyState.isEntry = false;
991
- editor.update(() => {
992
- update();
993
- setTimeout(() => {
994
- historyState.isEntry = true;
995
- updated?.();
996
- });
997
- });
998
- }
999
991
 
1000
992
  /** 更新富文本实例名称 */
1001
993
  function $updateRichInstanceTitle(instance, {
@@ -1099,6 +1091,59 @@ function correctedInstanceParagraph(nodes, createParagraph) {
1099
1091
  return nodes;
1100
1092
  }
1101
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
+
1102
1147
  /**
1103
1148
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1104
1149
  *
@@ -22433,7 +22478,7 @@ class ImageNode extends lexical.DecoratorNode {
22433
22478
  if (className !== undefined) {
22434
22479
  span.className = className;
22435
22480
  }
22436
- span.setAttribute('ignorecontenteditable', '');
22481
+ span.setAttribute('ignoreusable', '');
22437
22482
  return span;
22438
22483
  }
22439
22484
  updateDOM() {
@@ -23239,165 +23284,6 @@ function $handleListInsertParagraph() {
23239
23284
  return true;
23240
23285
  }
23241
23286
 
23242
- /** @noInheritDoc */
23243
- class InstanceListNode extends list.ListNode {
23244
- static getType() {
23245
- return 'List';
23246
- }
23247
- static clone(node) {
23248
- const listType = node.__listType || TAG_TO_LIST_TYPE[node.__tag];
23249
- return new InstanceListNode(listType, node.__start, node.__key);
23250
- }
23251
- static transform() {
23252
- return node => {
23253
- if (!$isInstanceListNode(node)) {
23254
- formatDevErrorMessage(`node is not a InstanceListNode`);
23255
- }
23256
- mergeNextSiblingListIfSameType(node);
23257
- updateChildrenListItemValue(node);
23258
- };
23259
- }
23260
- static importDOM() {
23261
- return {
23262
- ol: () => ({
23263
- conversion: $convertInstanceListNode,
23264
- priority: 0
23265
- }),
23266
- ul: () => ({
23267
- conversion: $convertInstanceListNode,
23268
- priority: 0
23269
- })
23270
- };
23271
- }
23272
- static importJSON(serializedNode) {
23273
- return $createInstanceListNode().updateFromJSON(serializedNode);
23274
- }
23275
- createDOM(config) {
23276
- const element = super.createDOM(config);
23277
- setDisable(this, element);
23278
- return element;
23279
- }
23280
- updateFromJSON(serializedNode) {
23281
- return super.updateFromJSON(serializedNode).setListType(serializedNode.listType).setStart(serializedNode.start);
23282
- }
23283
- exportJSON() {
23284
- return {
23285
- ...super.exportJSON(),
23286
- listType: this.getListType(),
23287
- start: this.getStart(),
23288
- tag: this.getTag()
23289
- };
23290
- }
23291
- splice(start, deleteCount, nodesToInsert) {
23292
- let listItemNodesToInsert = nodesToInsert;
23293
- for (let i = 0; i < nodesToInsert.length; i++) {
23294
- const node = nodesToInsert[i];
23295
- if (!$isInstanceListItemNode(node)) {
23296
- if (listItemNodesToInsert === nodesToInsert) {
23297
- listItemNodesToInsert = [...nodesToInsert];
23298
- }
23299
- listItemNodesToInsert[i] = $createInstanceListItemNode().append(lexical.$isElementNode(node) && !($isInstanceListNode(node) || node.isInline()) ? lexical.$createTextNode(node.getTextContent()) : node);
23300
- }
23301
- }
23302
- return super.splice(start, deleteCount, listItemNodesToInsert);
23303
- }
23304
- extractWithChild(child) {
23305
- return $isInstanceListItemNode(child);
23306
- }
23307
- }
23308
-
23309
- /*
23310
- * This function normalizes the children of a InstanceListNode after the conversion from HTML,
23311
- * ensuring that they are all ListItemNodes and contain either a single nested InstanceListNode
23312
- * or some other inline content.
23313
- */
23314
- function $normalizeChildren(nodes) {
23315
- const normalizedListItems = [];
23316
- for (let i = 0; i < nodes.length; i++) {
23317
- const node = nodes[i];
23318
- if ($isInstanceListItemNode(node)) {
23319
- normalizedListItems.push(node);
23320
- const children = node.getChildren();
23321
- if (children.length > 1) {
23322
- children.forEach(child => {
23323
- if ($isInstanceListNode(child)) {
23324
- normalizedListItems.push($wrapInInstanceListItem(child));
23325
- }
23326
- });
23327
- }
23328
- } else {
23329
- normalizedListItems.push($wrapInInstanceListItem(node));
23330
- }
23331
- }
23332
- return normalizedListItems;
23333
- }
23334
- function isDomChecklist(domNode) {
23335
- if (domNode.getAttribute('__lexicallisttype') === 'check' ||
23336
- // is github checklist
23337
- domNode.classList.contains('contains-task-list')) {
23338
- return true;
23339
- }
23340
- // if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
23341
- for (const child of domNode.childNodes) {
23342
- if (lexical.isHTMLElement(child) && child.hasAttribute('aria-checked')) {
23343
- return true;
23344
- }
23345
- }
23346
- return false;
23347
- }
23348
- function $convertInstanceListNode(domNode) {
23349
- const nodeName = domNode.nodeName.toLowerCase();
23350
- let node = null;
23351
- if (nodeName === 'ol') {
23352
- // @ts-ignore
23353
- const start = domNode.start;
23354
- node = $createInstanceListNode('number', start);
23355
- } else if (nodeName === 'ul') {
23356
- if (isDomChecklist(domNode)) {
23357
- node = $createInstanceListNode('check');
23358
- } else {
23359
- node = $createInstanceListNode('bullet');
23360
- }
23361
- }
23362
- return {
23363
- after: $normalizeChildren,
23364
- node
23365
- };
23366
- }
23367
- const TAG_TO_LIST_TYPE = {
23368
- ol: 'number',
23369
- ul: 'bullet'
23370
- };
23371
-
23372
- /**
23373
- * Wraps a node into a ListItemNode.
23374
- * @param node - The node to be wrapped into a ListItemNode
23375
- * @returns The ListItemNode which the passed node is wrapped in.
23376
- */
23377
- function $wrapInInstanceListItem(node) {
23378
- const listItemWrapper = $createInstanceListItemNode();
23379
- return listItemWrapper.append(node);
23380
- }
23381
-
23382
- /**
23383
- * Creates a InstanceListNode of listType.
23384
- * @param listType - The type of list to be created. Can be 'number', 'bullet', or 'check'.
23385
- * @param start - Where an ordered list starts its count, start = 1 if left undefined.
23386
- * @returns The new InstanceListNode
23387
- */
23388
- function $createInstanceListNode(listType = 'number', start = 1) {
23389
- return lexical.$applyNodeReplacement(new InstanceListNode(listType, start));
23390
- }
23391
-
23392
- /**
23393
- * Checks to see if the node is a InstanceListNode.
23394
- * @param node - The node to be checked.
23395
- * @returns true if the node is a InstanceListNode, false otherwise.
23396
- */
23397
- function $isInstanceListNode(node) {
23398
- return node instanceof InstanceListNode;
23399
- }
23400
-
23401
23287
  /** @noInheritDoc */
23402
23288
  class InstanceListItemNode extends list.ListItemNode {
23403
23289
  static getType() {
@@ -23525,6 +23411,9 @@ class InstanceListItemNode extends list.ListItemNode {
23525
23411
  super.remove(preserveEmptyParent);
23526
23412
  }
23527
23413
  }
23414
+ defaultRemove(preserveEmptyParent) {
23415
+ super.remove(preserveEmptyParent);
23416
+ }
23528
23417
  insertNewAfter(selection$1, restoreSelection = true) {
23529
23418
  const [node] = selection$1.getNodes();
23530
23419
  if ($isInstanceListItemNode(node) && node.getChildren().length === 0) {
@@ -23625,6 +23514,165 @@ function $registerInstanceListItemInsertParagraph(editor) {
23625
23514
  }, lexical.COMMAND_PRIORITY_NORMAL);
23626
23515
  }
23627
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
+
23628
23676
  /** @noInheritDoc */
23629
23677
  class InstanceTableNode extends table.TableNode {
23630
23678
  static getType() {
@@ -23789,49 +23837,131 @@ const InstancePlugin = props => {
23789
23837
  instances,
23790
23838
  isAddChildLevel
23791
23839
  }) => {
23792
- if (insNodeKey) {
23793
- const insNode = lexical.$getNodeByKey(insNodeKey);
23794
- if ($isInstanceNode(insNode)) {
23795
- const newInsNodes = instances.map(instance => {
23796
- const contentText = getTemporaryContentText(instance);
23797
- if (contentText) {
23798
- const node = $createTitleOnlyInstanceNode(instance);
23799
- const fragment = $createFragmentNode();
23800
- onchainLexicalMarkdown.$textToRichNodes(fragment, contentText);
23801
- const nodes = correctedInstanceParagraph(fragment.getChildren(), () => $createInstanceParagraphNode());
23802
- node.append(...nodes);
23803
- return node;
23804
- } else {
23805
- return $createInstanceNode(instance);
23806
- }
23807
- });
23808
- if (isAddChildLevel) {
23809
- const [insChildNode] = insNode.getSelfInstanceChildren();
23810
- if (insChildNode) {
23811
- for (let index = newInsNodes.length - 1; index > -1; index--) {
23812
- const current = newInsNodes[index];
23813
- const pre = newInsNodes[index + 1];
23814
- if (pre) {
23815
- pre.insertBefore(current);
23816
- } else {
23817
- insChildNode.insertBefore(current);
23818
- }
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++;
23819
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));
23820
23900
  } else {
23821
- 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
+ });
23822
23911
  }
23912
+ elementNodes.push(tableNode);
23823
23913
  } else {
23824
- for (let index = 0; index < newInsNodes.length; index++) {
23825
- const current = newInsNodes[index];
23826
- const pre = newInsNodes[index - 1];
23827
- if (pre) {
23828
- pre.insertAfter(current);
23829
- } else {
23830
- 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);
23831
23952
  }
23832
23953
  }
23833
23954
  }
23834
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
+ });
23835
23965
  }
23836
23966
  return true;
23837
23967
  }, lexical.COMMAND_PRIORITY_LOW));
@@ -23843,6 +23973,119 @@ const InstancePlugin = props => {
23843
23973
  }, []);
23844
23974
  return /*#__PURE__*/React.createElement(React.Fragment, {}, /*#__PURE__*/React.createElement(HorizontalRulePlugin));
23845
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
+ }
23846
24089
 
23847
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}";
23848
24091
  var Styles$3 = {"internalLink":"styles-module_internalLink__3B9ii"};
@@ -23938,7 +24181,7 @@ class InternalLinkNode extends lexical.TextDecoratorNode {
23938
24181
  }
23939
24182
  createDOM(config, editor) {
23940
24183
  const span = super.createDOM(config, editor);
23941
- span.setAttribute('ignorecontenteditable', '');
24184
+ span.setAttribute('ignoreusable', '');
23942
24185
  return span;
23943
24186
  }
23944
24187
  updateDOM(prevNode, dom, config) {
@@ -24067,12 +24310,12 @@ function $isPageBreakNode(node) {
24067
24310
  return node instanceof PageBreakNode;
24068
24311
  }
24069
24312
 
24070
- /**
24071
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24072
- *
24073
- * This source code is licensed under the MIT license found in the
24074
- * LICENSE file in the root directory of this source tree.
24075
- *
24313
+ /**
24314
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
24315
+ *
24316
+ * This source code is licensed under the MIT license found in the
24317
+ * LICENSE file in the root directory of this source tree.
24318
+ *
24076
24319
  */
24077
24320
 
24078
24321
  const ParametersComponent = ({
@@ -24087,7 +24330,7 @@ const ParametersComponent = ({
24087
24330
  editor.read(() => {
24088
24331
  const node = lexical.$getNodeByKey(nodeKey);
24089
24332
  if ($isParametersNode(node)) {
24090
- setParameters(node.__parameters);
24333
+ setParameters(node.parameters);
24091
24334
  }
24092
24335
  });
24093
24336
  return utils$1.mergeRegister(editor.registerCommand(PARAMETERS_UPDATE, ({
@@ -24103,7 +24346,7 @@ const ParametersComponent = ({
24103
24346
  setParameters({
24104
24347
  value
24105
24348
  });
24106
- Object.assign(node.__parameters, {
24349
+ Object.assign(node.parameters, {
24107
24350
  value
24108
24351
  });
24109
24352
  }
@@ -24115,37 +24358,45 @@ const ParametersComponent = ({
24115
24358
  });
24116
24359
  };
24117
24360
 
24118
- /**
24119
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24120
- *
24121
- * This source code is licensed under the MIT license found in the
24122
- * LICENSE file in the root directory of this source tree.
24123
- *
24361
+ /**
24362
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
24363
+ *
24364
+ * This source code is licensed under the MIT license found in the
24365
+ * LICENSE file in the root directory of this source tree.
24366
+ *
24124
24367
  */
24125
24368
 
24126
24369
  class ParametersNode extends lexical.TextDecoratorNode {
24370
+ /** 用于存储参数数据,保证每次读取能获取到最新值 */
24371
+ static collection = new Map();
24372
+ /** 初始化值 */
24373
+
24374
+ /** 最新的值 */
24375
+ get parameters() {
24376
+ return ParametersNode.collection.get(this.__parameters.number) || this.__parameters;
24377
+ }
24127
24378
  static getType() {
24128
24379
  return 'Parameters';
24129
24380
  }
24130
24381
  static clone(node) {
24131
- return new ParametersNode(node.__parameters, node.__key);
24382
+ return new ParametersNode(Object.assign({}, node.parameters), node.__key);
24132
24383
  }
24133
24384
  static importJSON(serializedNode) {
24134
24385
  return $createParametersNode(serializedNode.parameters).updateFromJSON(serializedNode);
24135
24386
  }
24136
- constructor(number, key) {
24387
+ constructor(parameters, key) {
24137
24388
  super(key);
24138
- this.__parameters = number;
24389
+ this.__parameters = parameters;
24139
24390
  }
24140
24391
  exportJSON() {
24141
24392
  return {
24142
24393
  ...super.exportJSON(),
24143
- parameters: this.__parameters
24394
+ parameters: this.parameters
24144
24395
  };
24145
24396
  }
24146
24397
  createDOM(config, editor) {
24147
24398
  const span = super.createDOM(config, editor);
24148
- span.setAttribute('ignorecontenteditable', '');
24399
+ span.setAttribute('ignoreusable', '');
24149
24400
  return span;
24150
24401
  }
24151
24402
  updateDOM(prevNode, dom, config) {
@@ -24170,6 +24421,10 @@ function $isParametersNode(node) {
24170
24421
  return node instanceof ParametersNode;
24171
24422
  }
24172
24423
 
24424
+ // export function updateParameters(parameters: Parameters) {
24425
+ // return ParametersNode.collection.set(parameters.number, parameters);
24426
+ // }
24427
+
24173
24428
  /**
24174
24429
  * Copyright (c) Meta Platforms, Inc. and affiliates.
24175
24430
  *
@@ -25193,6 +25448,7 @@ var InlineImageComponent$1 = {
25193
25448
  default: InlineImageComponent
25194
25449
  };
25195
25450
 
25451
+ exports.$addInstancesNode = $addInstancesNode;
25196
25452
  exports.$createBarDecoratorNode = $createBarDecoratorNode;
25197
25453
  exports.$createCollapsibleContainerNode = $createCollapsibleContainerNode;
25198
25454
  exports.$createCollapsibleContentNode = $createCollapsibleContentNode;
@@ -25273,6 +25529,7 @@ exports.$updateRichHistoryStateMap = $updateRichHistoryStateMap;
25273
25529
  exports.$updateRichInstanceContent = $updateRichInstanceContent;
25274
25530
  exports.$updateRichInstanceTitle = $updateRichInstanceTitle;
25275
25531
  exports.$wrapInListItem = $wrapInListItem;
25532
+ exports.ADD_COMMENT = ADD_COMMENT;
25276
25533
  exports.ADD_NEW_INSTANCE_NODE = ADD_NEW_INSTANCE_NODE;
25277
25534
  exports.BarDecoratorNode = BarDecoratorNode;
25278
25535
  exports.COMPONENT_UPDATE = COMPONENT_UPDATE;
@@ -25310,6 +25567,7 @@ exports.PARAMETERS_UPDATE = PARAMETERS_UPDATE;
25310
25567
  exports.PageBreakNode = PageBreakNode;
25311
25568
  exports.ParametersNode = ParametersNode;
25312
25569
  exports.PlaceholderDecoratorNode = PlaceholderDecoratorNode;
25570
+ exports.SPLIT_INSTANCE_NODE = SPLIT_INSTANCE_NODE;
25313
25571
  exports.clearCache = clearCache;
25314
25572
  exports.correctedInstanceParagraph = correctedInstanceParagraph;
25315
25573
  exports.fixedAddress = fixedAddress;
@@ -25321,7 +25579,6 @@ exports.getInstanceBaseInfo = getInstanceBaseInfo;
25321
25579
  exports.getLanguageFriendlyName = getLanguageFriendlyName;
25322
25580
  exports.getLatestValue = getLatestValue;
25323
25581
  exports.getTemporaryContentText = getTemporaryContentText;
25324
- exports.ignoreHistory = ignoreHistory;
25325
25582
  exports.instanceNodeMap = instanceNodeMap;
25326
25583
  exports.internalLinkNameUpdateMap = internalLinkNameUpdateMap;
25327
25584
  exports.isCompleteInstance = isCompleteInstance;