onchain-lexical-instance 0.0.13 → 0.0.14

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.
@@ -736,12 +736,12 @@ function $registerInstanceHeadingNodeTransform(editor) {
736
736
  });
737
737
  }
738
738
 
739
- /**
740
- * Copyright (c) Meta Platforms, Inc. and affiliates.
741
- *
742
- * This source code is licensed under the MIT license found in the
743
- * LICENSE file in the root directory of this source tree.
744
- *
739
+ /**
740
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
741
+ *
742
+ * This source code is licensed under the MIT license found in the
743
+ * LICENSE file in the root directory of this source tree.
744
+ *
745
745
  */
746
746
  /* eslint-disable @typescript-eslint/no-explicit-any */
747
747
 
@@ -861,9 +861,9 @@ function getLatestValue(data, key) {
861
861
  return data[key];
862
862
  }
863
863
 
864
- /**
865
- * 跳转到指定实例
866
- * dom 属性 data-scrollTo=“false” 时可以禁止跳转
864
+ /**
865
+ * 跳转到指定实例
866
+ * dom 属性 data-scrollTo=“false” 时可以禁止跳转
867
867
  */
868
868
  function $scrollTo(number) {
869
869
  const editor = lexical.$getEditor();
@@ -1143,6 +1143,26 @@ function $addInstancesNode({
1143
1143
  }
1144
1144
  }
1145
1145
  }
1146
+ function $selectDecoratorNode(node) {
1147
+ if (node) {
1148
+ const [previous, next] = [node.getPreviousSibling(), node.getNextSibling()];
1149
+ const rangeSelection = lexical.$createRangeSelection();
1150
+ if (previous) {
1151
+ const isText = lexical.$isTextNode(previous);
1152
+ rangeSelection.anchor.set(isText ? previous.getKey() : node.getParent().getKey(), isText ? previous.getTextContentSize() : node.getPreviousSiblings().length, isText ? 'text' : 'element');
1153
+ } else {
1154
+ const parent = node.getParent();
1155
+ rangeSelection.anchor.set(parent.getKey(), 0, 'element');
1156
+ }
1157
+ if (next) {
1158
+ rangeSelection.focus.set(next.getKey(), 0, lexical.$isTextNode(next) ? 'text' : 'element');
1159
+ } else {
1160
+ const parent = node.getParent();
1161
+ rangeSelection.focus.set(parent.getKey(), node.getPreviousSiblings().length + 1, 'element');
1162
+ }
1163
+ lexical.$setSelection(rangeSelection);
1164
+ }
1165
+ }
1146
1166
 
1147
1167
  /**
1148
1168
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -23792,12 +23812,12 @@ function $createTableNodeWithDimensions(rowCount, columnCount, includeHeaders =
23792
23812
  return tableNode;
23793
23813
  }
23794
23814
 
23795
- /**
23796
- * Copyright (c) Meta Platforms, Inc. and affiliates.
23797
- *
23798
- * This source code is licensed under the MIT license found in the
23799
- * LICENSE file in the root directory of this source tree.
23800
- *
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
+ *
23801
23821
  */
23802
23822
  const InstancePlugin = props => {
23803
23823
  const {
@@ -23810,7 +23830,28 @@ const InstancePlugin = props => {
23810
23830
  placeholder
23811
23831
  }), $registerInstanceHeadingNodeTransform(editor), $registerInstanceListItemInsertParagraph(editor), $registerNumberDecoratorNodeUpdate(editor), $registerNumberDecoratorDomUpdate(editor), $registerTableCommand(editor),
23812
23832
  // $selectionChange(editor, setSelectedInstance),
23813
- editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, event => {
23833
+ editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, () => {
23834
+ const selection = lexical.$getSelection();
23835
+ if (lexical.$isNodeSelection(selection)) {
23836
+ const [node] = selection.getNodes();
23837
+ if (lexical.$isDecoratorNode(node)) {
23838
+ $selectDecoratorNode(node);
23839
+ }
23840
+ }
23841
+ return false;
23842
+ }, lexical.COMMAND_PRIORITY_CRITICAL), editor.registerCommand(lexical.CLICK_COMMAND, event => {
23843
+ if (event.target instanceof HTMLElement) {
23844
+ const decoratorRootEle = event.target.closest('[data-lexical-decorator="true"]');
23845
+ if (decoratorRootEle) {
23846
+ const key = decoratorRootEle.getAttribute('key');
23847
+ if (key) {
23848
+ const node = lexical.$getNodeByKey(key);
23849
+ $selectDecoratorNode(node);
23850
+ }
23851
+ }
23852
+ }
23853
+ return false;
23854
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, event => {
23814
23855
  const selection = lexical.$getSelection();
23815
23856
  if (selection) {
23816
23857
  return selection.getNodes().some(node => {
@@ -24151,12 +24192,12 @@ function InternalLinkComponent(props) {
24151
24192
  }
24152
24193
  }
24153
24194
 
24154
- /**
24155
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24156
- *
24157
- * This source code is licensed under the MIT license found in the
24158
- * LICENSE file in the root directory of this source tree.
24159
- *
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
+ *
24160
24201
  */
24161
24202
 
24162
24203
  class InternalLinkNode extends lexical.TextDecoratorNode {
@@ -24173,6 +24214,11 @@ class InternalLinkNode extends lexical.TextDecoratorNode {
24173
24214
  super(key);
24174
24215
  this.__number = number;
24175
24216
  }
24217
+
24218
+ // get contentEditable() {
24219
+ // return 'true'
24220
+ // }
24221
+
24176
24222
  exportJSON() {
24177
24223
  return {
24178
24224
  ...super.exportJSON(),
@@ -24182,6 +24228,7 @@ class InternalLinkNode extends lexical.TextDecoratorNode {
24182
24228
  createDOM(config, editor) {
24183
24229
  const span = super.createDOM(config, editor);
24184
24230
  span.setAttribute('ignoreusable', '');
24231
+ span.setAttribute('decorator', 'text');
24185
24232
  return span;
24186
24233
  }
24187
24234
  updateDOM(prevNode, dom, config) {
@@ -24193,6 +24240,16 @@ class InternalLinkNode extends lexical.TextDecoratorNode {
24193
24240
  isInline() {
24194
24241
  return true;
24195
24242
  }
24243
+ isSelected(selection) {
24244
+ return true;
24245
+ }
24246
+ getTextContent() {
24247
+ const insNode = $getInstanceNodeByNumber(this.__number);
24248
+ if (insNode) {
24249
+ return getLatestValue(insNode.__instance.value, 'insDesc') || '';
24250
+ }
24251
+ return '';
24252
+ }
24196
24253
  decorate(editor, config) {
24197
24254
  return /*#__PURE__*/jsxRuntime.jsx(InternalLinkComponent, {
24198
24255
  editor: editor,
@@ -24310,18 +24367,19 @@ function $isPageBreakNode(node) {
24310
24367
  return node instanceof PageBreakNode;
24311
24368
  }
24312
24369
 
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
- *
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
+ *
24319
24376
  */
24320
24377
 
24321
- const ParametersComponent = ({
24378
+ const ParametersComponent = /*#__PURE__*/React.forwardRef(({
24322
24379
  nodeKey
24323
- }) => {
24380
+ }, ref) => {
24324
24381
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
24382
+ const spanRef = React.useRef(null);
24325
24383
  const [parameters, setParameters,, latestParameters] = hooks.useStore({
24326
24384
  number: '',
24327
24385
  value: ''
@@ -24353,17 +24411,27 @@ const ParametersComponent = ({
24353
24411
  return true;
24354
24412
  }, lexical.COMMAND_PRIORITY_EDITOR));
24355
24413
  }, []);
24414
+ React.useImperativeHandle(ref, () => {
24415
+ return {
24416
+ getValue() {
24417
+ return latestParameters.current.value;
24418
+ }
24419
+ };
24420
+ }, []);
24356
24421
  return /*#__PURE__*/jsxRuntime.jsx("span", {
24422
+ ref: spanRef,
24423
+ role: "button",
24424
+ tabIndex: 0,
24357
24425
  children: parameters.value
24358
24426
  });
24359
- };
24427
+ });
24360
24428
 
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
- *
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
+ *
24367
24435
  */
24368
24436
 
24369
24437
  class ParametersNode extends lexical.TextDecoratorNode {
@@ -24371,6 +24439,8 @@ class ParametersNode extends lexical.TextDecoratorNode {
24371
24439
  static collection = new Map();
24372
24440
  /** 初始化值 */
24373
24441
 
24442
+ __ref = /*#__PURE__*/React.createRef();
24443
+
24374
24444
  /** 最新的值 */
24375
24445
  get parameters() {
24376
24446
  return ParametersNode.collection.get(this.__parameters.number) || this.__parameters;
@@ -24397,6 +24467,7 @@ class ParametersNode extends lexical.TextDecoratorNode {
24397
24467
  createDOM(config, editor) {
24398
24468
  const span = super.createDOM(config, editor);
24399
24469
  span.setAttribute('ignoreusable', '');
24470
+ span.setAttribute('key', this.getKey());
24400
24471
  return span;
24401
24472
  }
24402
24473
  updateDOM(prevNode, dom, config) {
@@ -24408,8 +24479,12 @@ class ParametersNode extends lexical.TextDecoratorNode {
24408
24479
  isInline() {
24409
24480
  return true;
24410
24481
  }
24482
+ getTextContent() {
24483
+ return this.__ref.current?.getValue() || '';
24484
+ }
24411
24485
  decorate(editor, config) {
24412
24486
  return /*#__PURE__*/jsxRuntime.jsx(ParametersComponent, {
24487
+ ref: this.__ref,
24413
24488
  nodeKey: this.getKey()
24414
24489
  });
24415
24490
  }
@@ -24421,10 +24496,6 @@ function $isParametersNode(node) {
24421
24496
  return node instanceof ParametersNode;
24422
24497
  }
24423
24498
 
24424
- // export function updateParameters(parameters: Parameters) {
24425
- // return ParametersNode.collection.set(parameters.number, parameters);
24426
- // }
24427
-
24428
24499
  /**
24429
24500
  * Copyright (c) Meta Platforms, Inc. and affiliates.
24430
24501
  *
@@ -25525,6 +25596,7 @@ exports.$nodeUpgrade = $nodeUpgrade;
25525
25596
  exports.$removeHighestEmptyListParent = $removeHighestEmptyListParent;
25526
25597
  exports.$removeList = $removeList;
25527
25598
  exports.$scrollTo = $scrollTo;
25599
+ exports.$selectDecoratorNode = $selectDecoratorNode;
25528
25600
  exports.$updateRichHistoryStateMap = $updateRichHistoryStateMap;
25529
25601
  exports.$updateRichInstanceContent = $updateRichInstanceContent;
25530
25602
  exports.$updateRichInstanceTitle = $updateRichInstanceTitle;
@@ -8,11 +8,11 @@
8
8
 
9
9
  import { $isCodeNode, CodeNode } from '@lexical/code';
10
10
  import { $findMatchingParent, addClassNamesToElement, mergeRegister, removeClassNamesFromElement, $getAdjacentCaret, isHTMLElement as isHTMLElement$1, IS_CHROME, $insertNodeToNearestRoot, $getNearestNodeOfType, $descendantsMatching } from '@lexical/utils';
11
- import { createCommand, ElementNode, $applyNodeReplacement, isHTMLElement, setNodeIndentFromDOM, DecoratorNode, $getEditor, $isTextNode, $createTextNode, TextNode as TextNode$1, $getSelection, $isRootOrShadowRoot, $isRootNode, $getNodeByKey, scrollIntoViewIfNeeded, $isElementNode, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, ParagraphNode, COMMAND_PRIORITY_EDITOR, $getSiblingCaret, $isTabNode, $createTabNode, $createLineBreakNode, KEY_TAB_COMMAND, COMMAND_PRIORITY_LOW, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, $isRangeSelection, KEY_ARROW_DOWN_COMMAND, MOVE_TO_START, MOVE_TO_END, $isLineBreakNode, $rewindSiblingCaret, $createParagraphNode, createEditor, RootNode, LineBreakNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, INSERT_PARAGRAPH_COMMAND, COMMAND_PRIORITY_NORMAL, $getPreviousSelection, DELETE_CHARACTER_COMMAND, $setSelection, $createRangeSelection, exportNodeToJSON, TextDecoratorNode, COMMAND_PRIORITY_HIGH, CLICK_COMMAND, KEY_ESCAPE_COMMAND, $isNodeSelection, $createNodeSelection, DRAGSTART_COMMAND, KEY_ENTER_COMMAND } from 'lexical';
11
+ import { createCommand, ElementNode, $applyNodeReplacement, isHTMLElement, setNodeIndentFromDOM, DecoratorNode, $getEditor, $isTextNode, $createTextNode, TextNode as TextNode$1, $getSelection, $isRootOrShadowRoot, $isRootNode, $getNodeByKey, scrollIntoViewIfNeeded, $isElementNode, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_CRITICAL, $createRangeSelection, $setSelection, ParagraphNode, COMMAND_PRIORITY_EDITOR, $getSiblingCaret, $isTabNode, $createTabNode, $createLineBreakNode, KEY_TAB_COMMAND, COMMAND_PRIORITY_LOW, INSERT_TAB_COMMAND, $insertNodes, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, $isRangeSelection, KEY_ARROW_DOWN_COMMAND, MOVE_TO_START, MOVE_TO_END, $isLineBreakNode, $rewindSiblingCaret, $createParagraphNode, createEditor, RootNode, LineBreakNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, INSERT_PARAGRAPH_COMMAND, COMMAND_PRIORITY_NORMAL, $getPreviousSelection, $isNodeSelection, $isDecoratorNode, CLICK_COMMAND, DELETE_CHARACTER_COMMAND, exportNodeToJSON, TextDecoratorNode, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, $createNodeSelection, DRAGSTART_COMMAND, KEY_ENTER_COMMAND } from 'lexical';
12
12
  import { HorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
13
13
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
14
14
  import * as React from 'react';
15
- import React__default, { useState, useCallback, useEffect, useMemo, useRef, Suspense } from 'react';
15
+ import React__default, { useState, useCallback, useEffect, useMemo, useRef, useImperativeHandle, Suspense } from 'react';
16
16
  import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
17
17
  import { $isListNode, $isListItemNode, $createListItemNode, ListItemNode, ListNode } from '@lexical/list';
18
18
  import { TableNode, INSERT_TABLE_COMMAND, $findTableNode, PIXEL_VALUE_REG_EXP, $isTableRowNode, $createTableRowNode, $createTableCellNode, TableCellHeaderStates, $isTableSelection, $isTableCellNode } from '@lexical/table';
@@ -722,12 +722,12 @@ function $registerInstanceHeadingNodeTransform(editor) {
722
722
  });
723
723
  }
724
724
 
725
- /**
726
- * Copyright (c) Meta Platforms, Inc. and affiliates.
727
- *
728
- * This source code is licensed under the MIT license found in the
729
- * LICENSE file in the root directory of this source tree.
730
- *
725
+ /**
726
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
727
+ *
728
+ * This source code is licensed under the MIT license found in the
729
+ * LICENSE file in the root directory of this source tree.
730
+ *
731
731
  */
732
732
  /* eslint-disable @typescript-eslint/no-explicit-any */
733
733
 
@@ -847,9 +847,9 @@ function getLatestValue(data, key) {
847
847
  return data[key];
848
848
  }
849
849
 
850
- /**
851
- * 跳转到指定实例
852
- * dom 属性 data-scrollTo=“false” 时可以禁止跳转
850
+ /**
851
+ * 跳转到指定实例
852
+ * dom 属性 data-scrollTo=“false” 时可以禁止跳转
853
853
  */
854
854
  function $scrollTo(number) {
855
855
  const editor = $getEditor();
@@ -1129,6 +1129,26 @@ function $addInstancesNode({
1129
1129
  }
1130
1130
  }
1131
1131
  }
1132
+ function $selectDecoratorNode(node) {
1133
+ if (node) {
1134
+ const [previous, next] = [node.getPreviousSibling(), node.getNextSibling()];
1135
+ const rangeSelection = $createRangeSelection();
1136
+ if (previous) {
1137
+ const isText = $isTextNode(previous);
1138
+ rangeSelection.anchor.set(isText ? previous.getKey() : node.getParent().getKey(), isText ? previous.getTextContentSize() : node.getPreviousSiblings().length, isText ? 'text' : 'element');
1139
+ } else {
1140
+ const parent = node.getParent();
1141
+ rangeSelection.anchor.set(parent.getKey(), 0, 'element');
1142
+ }
1143
+ if (next) {
1144
+ rangeSelection.focus.set(next.getKey(), 0, $isTextNode(next) ? 'text' : 'element');
1145
+ } else {
1146
+ const parent = node.getParent();
1147
+ rangeSelection.focus.set(parent.getKey(), node.getPreviousSiblings().length + 1, 'element');
1148
+ }
1149
+ $setSelection(rangeSelection);
1150
+ }
1151
+ }
1132
1152
 
1133
1153
  /**
1134
1154
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -23778,12 +23798,12 @@ function $createTableNodeWithDimensions(rowCount, columnCount, includeHeaders =
23778
23798
  return tableNode;
23779
23799
  }
23780
23800
 
23781
- /**
23782
- * Copyright (c) Meta Platforms, Inc. and affiliates.
23783
- *
23784
- * This source code is licensed under the MIT license found in the
23785
- * LICENSE file in the root directory of this source tree.
23786
- *
23801
+ /**
23802
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
23803
+ *
23804
+ * This source code is licensed under the MIT license found in the
23805
+ * LICENSE file in the root directory of this source tree.
23806
+ *
23787
23807
  */
23788
23808
  const InstancePlugin = props => {
23789
23809
  const {
@@ -23796,7 +23816,28 @@ const InstancePlugin = props => {
23796
23816
  placeholder
23797
23817
  }), $registerInstanceHeadingNodeTransform(editor), $registerInstanceListItemInsertParagraph(editor), $registerNumberDecoratorNodeUpdate(editor), $registerNumberDecoratorDomUpdate(editor), $registerTableCommand(editor),
23798
23818
  // $selectionChange(editor, setSelectedInstance),
23799
- editor.registerCommand(DELETE_CHARACTER_COMMAND, event => {
23819
+ editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
23820
+ const selection = $getSelection();
23821
+ if ($isNodeSelection(selection)) {
23822
+ const [node] = selection.getNodes();
23823
+ if ($isDecoratorNode(node)) {
23824
+ $selectDecoratorNode(node);
23825
+ }
23826
+ }
23827
+ return false;
23828
+ }, COMMAND_PRIORITY_CRITICAL), editor.registerCommand(CLICK_COMMAND, event => {
23829
+ if (event.target instanceof HTMLElement) {
23830
+ const decoratorRootEle = event.target.closest('[data-lexical-decorator="true"]');
23831
+ if (decoratorRootEle) {
23832
+ const key = decoratorRootEle.getAttribute('key');
23833
+ if (key) {
23834
+ const node = $getNodeByKey(key);
23835
+ $selectDecoratorNode(node);
23836
+ }
23837
+ }
23838
+ }
23839
+ return false;
23840
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(DELETE_CHARACTER_COMMAND, event => {
23800
23841
  const selection = $getSelection();
23801
23842
  if (selection) {
23802
23843
  return selection.getNodes().some(node => {
@@ -24137,12 +24178,12 @@ function InternalLinkComponent(props) {
24137
24178
  }
24138
24179
  }
24139
24180
 
24140
- /**
24141
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24142
- *
24143
- * This source code is licensed under the MIT license found in the
24144
- * LICENSE file in the root directory of this source tree.
24145
- *
24181
+ /**
24182
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
24183
+ *
24184
+ * This source code is licensed under the MIT license found in the
24185
+ * LICENSE file in the root directory of this source tree.
24186
+ *
24146
24187
  */
24147
24188
 
24148
24189
  class InternalLinkNode extends TextDecoratorNode {
@@ -24159,6 +24200,11 @@ class InternalLinkNode extends TextDecoratorNode {
24159
24200
  super(key);
24160
24201
  this.__number = number;
24161
24202
  }
24203
+
24204
+ // get contentEditable() {
24205
+ // return 'true'
24206
+ // }
24207
+
24162
24208
  exportJSON() {
24163
24209
  return {
24164
24210
  ...super.exportJSON(),
@@ -24168,6 +24214,7 @@ class InternalLinkNode extends TextDecoratorNode {
24168
24214
  createDOM(config, editor) {
24169
24215
  const span = super.createDOM(config, editor);
24170
24216
  span.setAttribute('ignoreusable', '');
24217
+ span.setAttribute('decorator', 'text');
24171
24218
  return span;
24172
24219
  }
24173
24220
  updateDOM(prevNode, dom, config) {
@@ -24179,6 +24226,16 @@ class InternalLinkNode extends TextDecoratorNode {
24179
24226
  isInline() {
24180
24227
  return true;
24181
24228
  }
24229
+ isSelected(selection) {
24230
+ return true;
24231
+ }
24232
+ getTextContent() {
24233
+ const insNode = $getInstanceNodeByNumber(this.__number);
24234
+ if (insNode) {
24235
+ return getLatestValue(insNode.__instance.value, 'insDesc') || '';
24236
+ }
24237
+ return '';
24238
+ }
24182
24239
  decorate(editor, config) {
24183
24240
  return /*#__PURE__*/jsx(InternalLinkComponent, {
24184
24241
  editor: editor,
@@ -24296,18 +24353,19 @@ function $isPageBreakNode(node) {
24296
24353
  return node instanceof PageBreakNode;
24297
24354
  }
24298
24355
 
24299
- /**
24300
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24301
- *
24302
- * This source code is licensed under the MIT license found in the
24303
- * LICENSE file in the root directory of this source tree.
24304
- *
24356
+ /**
24357
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
24358
+ *
24359
+ * This source code is licensed under the MIT license found in the
24360
+ * LICENSE file in the root directory of this source tree.
24361
+ *
24305
24362
  */
24306
24363
 
24307
- const ParametersComponent = ({
24364
+ const ParametersComponent = /*#__PURE__*/React__default.forwardRef(({
24308
24365
  nodeKey
24309
- }) => {
24366
+ }, ref) => {
24310
24367
  const [editor] = useLexicalComposerContext();
24368
+ const spanRef = useRef(null);
24311
24369
  const [parameters, setParameters,, latestParameters] = useStore({
24312
24370
  number: '',
24313
24371
  value: ''
@@ -24339,17 +24397,27 @@ const ParametersComponent = ({
24339
24397
  return true;
24340
24398
  }, COMMAND_PRIORITY_EDITOR));
24341
24399
  }, []);
24400
+ useImperativeHandle(ref, () => {
24401
+ return {
24402
+ getValue() {
24403
+ return latestParameters.current.value;
24404
+ }
24405
+ };
24406
+ }, []);
24342
24407
  return /*#__PURE__*/jsx("span", {
24408
+ ref: spanRef,
24409
+ role: "button",
24410
+ tabIndex: 0,
24343
24411
  children: parameters.value
24344
24412
  });
24345
- };
24413
+ });
24346
24414
 
24347
- /**
24348
- * Copyright (c) Meta Platforms, Inc. and affiliates.
24349
- *
24350
- * This source code is licensed under the MIT license found in the
24351
- * LICENSE file in the root directory of this source tree.
24352
- *
24415
+ /**
24416
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
24417
+ *
24418
+ * This source code is licensed under the MIT license found in the
24419
+ * LICENSE file in the root directory of this source tree.
24420
+ *
24353
24421
  */
24354
24422
 
24355
24423
  class ParametersNode extends TextDecoratorNode {
@@ -24357,6 +24425,8 @@ class ParametersNode extends TextDecoratorNode {
24357
24425
  static collection = new Map();
24358
24426
  /** 初始化值 */
24359
24427
 
24428
+ __ref = /*#__PURE__*/React__default.createRef();
24429
+
24360
24430
  /** 最新的值 */
24361
24431
  get parameters() {
24362
24432
  return ParametersNode.collection.get(this.__parameters.number) || this.__parameters;
@@ -24383,6 +24453,7 @@ class ParametersNode extends TextDecoratorNode {
24383
24453
  createDOM(config, editor) {
24384
24454
  const span = super.createDOM(config, editor);
24385
24455
  span.setAttribute('ignoreusable', '');
24456
+ span.setAttribute('key', this.getKey());
24386
24457
  return span;
24387
24458
  }
24388
24459
  updateDOM(prevNode, dom, config) {
@@ -24394,8 +24465,12 @@ class ParametersNode extends TextDecoratorNode {
24394
24465
  isInline() {
24395
24466
  return true;
24396
24467
  }
24468
+ getTextContent() {
24469
+ return this.__ref.current?.getValue() || '';
24470
+ }
24397
24471
  decorate(editor, config) {
24398
24472
  return /*#__PURE__*/jsx(ParametersComponent, {
24473
+ ref: this.__ref,
24399
24474
  nodeKey: this.getKey()
24400
24475
  });
24401
24476
  }
@@ -24407,10 +24482,6 @@ function $isParametersNode(node) {
24407
24482
  return node instanceof ParametersNode;
24408
24483
  }
24409
24484
 
24410
- // export function updateParameters(parameters: Parameters) {
24411
- // return ParametersNode.collection.set(parameters.number, parameters);
24412
- // }
24413
-
24414
24485
  /**
24415
24486
  * Copyright (c) Meta Platforms, Inc. and affiliates.
24416
24487
  *
@@ -25434,4 +25505,4 @@ var InlineImageComponent$1 = {
25434
25505
  default: InlineImageComponent
25435
25506
  };
25436
25507
 
25437
- export { $addInstancesNode, $createBarDecoratorNode, $createCollapsibleContainerNode, $createCollapsibleContentNode, $createCollapsibleTitleNode, $createFragmentNode, $createImageNode, $createInlineImageNode, $createInstanceCodeHighlightNode, $createInstanceCodeNode, $createInstanceEquationNode, $createInstanceHeadingNode, $createInstanceHorizontalRuleNode, $createInstanceListItemNode, $createInstanceListNode, $createInstanceNode, $createInstanceParagraphNode, $createInstanceQuoteNode, $createInstanceTableNode, $createInstanceTitleNode, $createInternalLinkNode, $createKeywordNode, $createNumberDecoratorNode, $createPageBreakNode, $createParametersNode, $createPlaceholderDecoratorNode, $createTitleOnlyInstanceNode, $findNearestListItemNode, $getAllListItems, $getAnchorRootNode, $getInstanceNodeByChild, $getInstanceNodeByNumber, $getInstanceNodeKeyByNumber, $getListDepth, $getTitleNodeByChild, $getTopListNode, $handleIndent, $handleListInsertParagraph, $handleOutdent, $insertInstanceList, $isBarDecoratorNode, $isCollapsibleContainerNode, $isCollapsibleContentNode, $isCollapsibleTitleNode, $isEmptyInstanceParagraphNode, $isEmptyParagraphNode, $isImageNode, $isInInstanceTitleNode, $isInlineImageNode, $isInstanceCodeHighlightNode, $isInstanceCodeNode, $isInstanceEquationNode, $isInstanceHeadingNode, $isInstanceHorizontalRuleNode, $isInstanceListItemNode, $isInstanceListNode, $isInstanceNode, $isInstanceParagraphFormalNode, $isInstanceParagraphNode, $isInstanceQuoteNode, $isInstanceTableNode, $isInstanceTitleNode, $isInternalLinkNode, $isKeywordNode, $isLastItemInList, $isNumberDecoratorNode, $isPageBreakNode, $isParametersNode, $isPlaceholderDecoratorNode, $isRemoved, $isSelectedTitleNode, $isTextTypeNode, $nodeDowngrade, $nodeUpgrade, $removeHighestEmptyListParent, $removeList, $scrollTo, $updateRichHistoryStateMap, $updateRichInstanceContent, $updateRichInstanceTitle, $wrapInListItem, ADD_COMMENT, ADD_NEW_INSTANCE_NODE, BarDecoratorNode, COMPONENT_UPDATE, CollapsibleContainerNode, CollapsibleContentNode, CollapsibleTitleNode, DELETE_INSTANCE_NODE, DisableSelector, Fragment, INSERT_COLLAPSIBLE_COMMAND, INSERT_INS_HORIZONTAL_RULE_COMMAND, INSERT_PARAMETERS, INSTANCE_TITLE_UPDATE, ImageNode, InlineImageNode, InstanceCodeHighlightNode, InstanceCodeNode, InstanceEquationNode, InstanceHeadingNode, InstanceHorizontalRuleNode, InstanceListItemNode, InstanceListNode, InstanceNode, InstanceParagraphNode, InstanceParagraphType, InstancePlugin, InstanceQuoteNode, InstanceTableNode, InstanceTitleNode, InternalLinkNode, KeywordNode, NumberDecoratorNode, OPEN_CREATE_WINDOW, PARAMETERS_UPDATE, PageBreakNode, ParametersNode, PlaceholderDecoratorNode, SPLIT_INSTANCE_NODE, clearCache, correctedInstanceParagraph, fixedAddress, getCachedClassNameArray, getCodeLanguages, getDefaultCodeLanguage, getInstanceAttrValue, getInstanceBaseInfo, getLanguageFriendlyName, getLatestValue, getTemporaryContentText, instanceNodeMap, internalLinkNameUpdateMap, isCompleteInstance, isNestedListNode, mergeLists, mergeNextSiblingListIfSameType, nodeMoveDown, nodeMoveUp, normalizeCodeLang, numberNodeKey, paragraphSymbol, registerCodeHighlighting, setDisable, setInstanceAttrValue, setTemporaryContentText, updateChildrenListItemValue, updateRelatedInternalLink, useContentEditable };
25508
+ export { $addInstancesNode, $createBarDecoratorNode, $createCollapsibleContainerNode, $createCollapsibleContentNode, $createCollapsibleTitleNode, $createFragmentNode, $createImageNode, $createInlineImageNode, $createInstanceCodeHighlightNode, $createInstanceCodeNode, $createInstanceEquationNode, $createInstanceHeadingNode, $createInstanceHorizontalRuleNode, $createInstanceListItemNode, $createInstanceListNode, $createInstanceNode, $createInstanceParagraphNode, $createInstanceQuoteNode, $createInstanceTableNode, $createInstanceTitleNode, $createInternalLinkNode, $createKeywordNode, $createNumberDecoratorNode, $createPageBreakNode, $createParametersNode, $createPlaceholderDecoratorNode, $createTitleOnlyInstanceNode, $findNearestListItemNode, $getAllListItems, $getAnchorRootNode, $getInstanceNodeByChild, $getInstanceNodeByNumber, $getInstanceNodeKeyByNumber, $getListDepth, $getTitleNodeByChild, $getTopListNode, $handleIndent, $handleListInsertParagraph, $handleOutdent, $insertInstanceList, $isBarDecoratorNode, $isCollapsibleContainerNode, $isCollapsibleContentNode, $isCollapsibleTitleNode, $isEmptyInstanceParagraphNode, $isEmptyParagraphNode, $isImageNode, $isInInstanceTitleNode, $isInlineImageNode, $isInstanceCodeHighlightNode, $isInstanceCodeNode, $isInstanceEquationNode, $isInstanceHeadingNode, $isInstanceHorizontalRuleNode, $isInstanceListItemNode, $isInstanceListNode, $isInstanceNode, $isInstanceParagraphFormalNode, $isInstanceParagraphNode, $isInstanceQuoteNode, $isInstanceTableNode, $isInstanceTitleNode, $isInternalLinkNode, $isKeywordNode, $isLastItemInList, $isNumberDecoratorNode, $isPageBreakNode, $isParametersNode, $isPlaceholderDecoratorNode, $isRemoved, $isSelectedTitleNode, $isTextTypeNode, $nodeDowngrade, $nodeUpgrade, $removeHighestEmptyListParent, $removeList, $scrollTo, $selectDecoratorNode, $updateRichHistoryStateMap, $updateRichInstanceContent, $updateRichInstanceTitle, $wrapInListItem, ADD_COMMENT, ADD_NEW_INSTANCE_NODE, BarDecoratorNode, COMPONENT_UPDATE, CollapsibleContainerNode, CollapsibleContentNode, CollapsibleTitleNode, DELETE_INSTANCE_NODE, DisableSelector, Fragment, INSERT_COLLAPSIBLE_COMMAND, INSERT_INS_HORIZONTAL_RULE_COMMAND, INSERT_PARAMETERS, INSTANCE_TITLE_UPDATE, ImageNode, InlineImageNode, InstanceCodeHighlightNode, InstanceCodeNode, InstanceEquationNode, InstanceHeadingNode, InstanceHorizontalRuleNode, InstanceListItemNode, InstanceListNode, InstanceNode, InstanceParagraphNode, InstanceParagraphType, InstancePlugin, InstanceQuoteNode, InstanceTableNode, InstanceTitleNode, InternalLinkNode, KeywordNode, NumberDecoratorNode, OPEN_CREATE_WINDOW, PARAMETERS_UPDATE, PageBreakNode, ParametersNode, PlaceholderDecoratorNode, SPLIT_INSTANCE_NODE, clearCache, correctedInstanceParagraph, fixedAddress, getCachedClassNameArray, getCodeLanguages, getDefaultCodeLanguage, getInstanceAttrValue, getInstanceBaseInfo, getLanguageFriendlyName, getLatestValue, getTemporaryContentText, instanceNodeMap, internalLinkNameUpdateMap, isCompleteInstance, isNestedListNode, mergeLists, mergeNextSiblingListIfSameType, nodeMoveDown, nodeMoveUp, normalizeCodeLang, numberNodeKey, paragraphSymbol, registerCodeHighlighting, setDisable, setInstanceAttrValue, setTemporaryContentText, updateChildrenListItemValue, updateRelatedInternalLink, useContentEditable };
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "instance"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.0.13",
10
+ "version": "0.0.14",
11
11
  "types": "index.d.ts",
12
12
  "files": [
13
13
  "dist",
@@ -24,7 +24,7 @@
24
24
  "@lexical/utils": "^0.30.0",
25
25
  "lexical": "0.30.0",
26
26
  "onchain-lexical-context": "^0.0.12",
27
- "onchain-lexical-markdown": "^0.0.12",
27
+ "onchain-lexical-markdown": "^0.0.13",
28
28
  "onchain-lexical-ui": "^0.0.12",
29
29
  "onchain-utility": "^0.0.10"
30
30
  },