@examind/block-editor 0.1.1 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5329,14 +5329,14 @@ function DistractorButton(props) {
5329
5329
  ] });
5330
5330
  }
5331
5331
 
5332
- // src/plugins/VariablesPlugin/TypeaheadVariablesAgentPlugin.tsx
5332
+ // src/plugins/VariablesPlugin/TypeaheadVariableAgentPlugin.tsx
5333
5333
  import { useLexicalComposerContext as useLexicalComposerContext21 } from "@lexical/react/LexicalComposerContext";
5334
5334
  import { mergeRegister as mergeRegister6 } from "@lexical/utils";
5335
5335
  import { createCommand as createCommand6 } from "lexical";
5336
5336
  import { useEffect as useEffect30 } from "react";
5337
5337
  import { Fragment as Fragment20, jsx as jsx49 } from "react/jsx-runtime";
5338
- var TYPEAHEAD_VARIABLES_COMMAND = createCommand6("TYPEAHEAD_VARIABLES_COMMAND");
5339
- function TypeaheadVariablesAgentPlugin() {
5338
+ var TYPEAHEAD_VARIABLE_COMMAND = createCommand6("TYPEAHEAD_VARIABLE_COMMAND");
5339
+ function TypeaheadVariableAgentPlugin() {
5340
5340
  const { hasModule, modulesNumber } = useBlockEditor();
5341
5341
  const [editor] = useLexicalComposerContext21();
5342
5342
  useEffect30(() => {
@@ -5345,7 +5345,7 @@ function TypeaheadVariablesAgentPlugin() {
5345
5345
  editor.registerUpdateListener(({ tags }) => {
5346
5346
  if (!tags.has("history-merge")) {
5347
5347
  editor.dispatchCommand(
5348
- TYPEAHEAD_VARIABLES_COMMAND,
5348
+ TYPEAHEAD_VARIABLE_COMMAND,
5349
5349
  void 0
5350
5350
  );
5351
5351
  }
@@ -5892,7 +5892,7 @@ function JournalEntryQuestionItemComponent(props) {
5892
5892
  decoratorNode: JournalEntryQuestionNode
5893
5893
  }
5894
5894
  ),
5895
- /* @__PURE__ */ jsx54(TypeaheadVariablesAgentPlugin, {}),
5895
+ /* @__PURE__ */ jsx54(TypeaheadVariableAgentPlugin, {}),
5896
5896
  /* @__PURE__ */ jsx54(VariableComponentPlugin, {})
5897
5897
  ] }) }) }),
5898
5898
  (!debit || !credit) && /* @__PURE__ */ jsxs17("div", { className: "controls", children: [
@@ -5951,7 +5951,7 @@ function JournalEntryQuestionItemComponent(props) {
5951
5951
  decoratorNode: JournalEntryQuestionNode
5952
5952
  }
5953
5953
  ),
5954
- /* @__PURE__ */ jsx54(TypeaheadVariablesAgentPlugin, {}),
5954
+ /* @__PURE__ */ jsx54(TypeaheadVariableAgentPlugin, {}),
5955
5955
  /* @__PURE__ */ jsx54(VariableComponentPlugin, {})
5956
5956
  ] }) }) })
5957
5957
  ]
@@ -5988,7 +5988,7 @@ function JournalEntryQuestionItemComponent(props) {
5988
5988
  decoratorNode: JournalEntryQuestionNode
5989
5989
  }
5990
5990
  ),
5991
- /* @__PURE__ */ jsx54(TypeaheadVariablesAgentPlugin, {}),
5991
+ /* @__PURE__ */ jsx54(TypeaheadVariableAgentPlugin, {}),
5992
5992
  /* @__PURE__ */ jsx54(VariableComponentPlugin, {}),
5993
5993
  /* @__PURE__ */ jsx54(VariableToolbarAgentPlugin, {})
5994
5994
  ] }) }) }),
@@ -6560,7 +6560,7 @@ function QuestionItemComponent(props) {
6560
6560
  ),
6561
6561
  /* @__PURE__ */ jsx58(HistoryPlugin3, { externalHistoryState: historyState }),
6562
6562
  /* @__PURE__ */ jsx58(TextToolbarAgentPlugin, {}),
6563
- /* @__PURE__ */ jsx58(TypeaheadVariablesAgentPlugin, {}),
6563
+ /* @__PURE__ */ jsx58(TypeaheadVariableAgentPlugin, {}),
6564
6564
  /* @__PURE__ */ jsx58(VariableComponentPlugin, {})
6565
6565
  ] }) }) })
6566
6566
  ]
@@ -6594,7 +6594,7 @@ function QuestionItemComponent(props) {
6594
6594
  decoratorNode: MatchingQuestionNode
6595
6595
  }
6596
6596
  ),
6597
- /* @__PURE__ */ jsx58(TypeaheadVariablesAgentPlugin, {}),
6597
+ /* @__PURE__ */ jsx58(TypeaheadVariableAgentPlugin, {}),
6598
6598
  /* @__PURE__ */ jsx58(VariableComponentPlugin, {}),
6599
6599
  /* @__PURE__ */ jsx58(VariableToolbarAgentPlugin, {})
6600
6600
  ] }) }) }),
@@ -6982,7 +6982,7 @@ function MultipleOptionQuestionItemComponent(props) {
6982
6982
  decoratorNode: MultipleOptionQuestionNode
6983
6983
  }
6984
6984
  ),
6985
- /* @__PURE__ */ jsx61(TypeaheadVariablesAgentPlugin, {}),
6985
+ /* @__PURE__ */ jsx61(TypeaheadVariableAgentPlugin, {}),
6986
6986
  /* @__PURE__ */ jsx61(VariableComponentPlugin, {}),
6987
6987
  /* @__PURE__ */ jsx61(VariableToolbarAgentPlugin, {})
6988
6988
  ] }) }) }),
@@ -7435,7 +7435,7 @@ function ShortAnswerQuestionComponent(props) {
7435
7435
  decoratorNode: ShortAnswerQuestionNode
7436
7436
  }
7437
7437
  ),
7438
- /* @__PURE__ */ jsx64(TypeaheadVariablesAgentPlugin, {}),
7438
+ /* @__PURE__ */ jsx64(TypeaheadVariableAgentPlugin, {}),
7439
7439
  /* @__PURE__ */ jsx64(VariableComponentPlugin, {}),
7440
7440
  /* @__PURE__ */ jsx64(VariableToolbarAgentPlugin, {})
7441
7441
  ] }) }) })
@@ -7854,7 +7854,7 @@ function FillInTheBlankQuestionComponent(props) {
7854
7854
  decoratorNode: FillInTheBlankQuestionNode
7855
7855
  }
7856
7856
  ),
7857
- /* @__PURE__ */ jsx69(TypeaheadVariablesAgentPlugin, {}),
7857
+ /* @__PURE__ */ jsx69(TypeaheadVariableAgentPlugin, {}),
7858
7858
  /* @__PURE__ */ jsx69(VariableComponentPlugin, {}),
7859
7859
  /* @__PURE__ */ jsx69(VariableToolbarAgentPlugin, {}),
7860
7860
  /* @__PURE__ */ jsx69(
@@ -8043,26 +8043,34 @@ function FinancialStatementQuestionComponent(props) {
8043
8043
  ),
8044
8044
  /* @__PURE__ */ jsx71("div", { "data-selectable": "true", children: /* @__PURE__ */ jsxs26("table", { "data-selectable": "true", style: { width: "100%" }, children: [
8045
8045
  /* @__PURE__ */ jsxs26("thead", { "data-selectable": "true", children: [
8046
- /* @__PURE__ */ jsx71("tr", { "data-selectable": "true", children: /* @__PURE__ */ jsx71("th", { colSpan: 2, "data-selectable": "true", children: /* @__PURE__ */ jsx71(LexicalNestedComposer7, { initialEditor: header, children: /* @__PURE__ */ jsxs26(NestedEditor, { nodeKey, children: [
8047
- /* @__PURE__ */ jsx71(SettingsPanelNestedAgentPlugin, {}),
8048
- /* @__PURE__ */ jsx71(
8049
- RichTextPlugin7,
8050
- {
8051
- contentEditable: /* @__PURE__ */ jsx71(NestedContentEditable, {}),
8052
- ErrorBoundary: LexicalErrorBoundary7,
8053
- placeholder: null
8054
- },
8055
- nodeKey
8056
- ),
8057
- /* @__PURE__ */ jsx71(
8058
- HistoryPlugin7,
8059
- {
8060
- externalHistoryState: historyState
8061
- }
8062
- ),
8063
- /* @__PURE__ */ jsx71(TypeaheadVariablesAgentPlugin, {}),
8064
- /* @__PURE__ */ jsx71(VariableComponentPlugin, {})
8065
- ] }) }) }) }),
8046
+ /* @__PURE__ */ jsx71("tr", { "data-selectable": "true", children: /* @__PURE__ */ jsx71(
8047
+ "td",
8048
+ {
8049
+ className: "financial-statement-question-header",
8050
+ colSpan: 2,
8051
+ "data-selectable": "true",
8052
+ children: /* @__PURE__ */ jsx71(LexicalNestedComposer7, { initialEditor: header, children: /* @__PURE__ */ jsxs26(NestedEditor, { nodeKey, children: [
8053
+ /* @__PURE__ */ jsx71(SettingsPanelNestedAgentPlugin, {}),
8054
+ /* @__PURE__ */ jsx71(
8055
+ RichTextPlugin7,
8056
+ {
8057
+ contentEditable: /* @__PURE__ */ jsx71(NestedContentEditable, {}),
8058
+ ErrorBoundary: LexicalErrorBoundary7,
8059
+ placeholder: null
8060
+ },
8061
+ nodeKey
8062
+ ),
8063
+ /* @__PURE__ */ jsx71(
8064
+ HistoryPlugin7,
8065
+ {
8066
+ externalHistoryState: historyState
8067
+ }
8068
+ ),
8069
+ /* @__PURE__ */ jsx71(TypeaheadVariableAgentPlugin, {}),
8070
+ /* @__PURE__ */ jsx71(VariableComponentPlugin, {})
8071
+ ] }) })
8072
+ }
8073
+ ) }),
8066
8074
  columnHeaders.length >= 2 && /* @__PURE__ */ jsxs26("tr", { "data-selectable": "true", children: [
8067
8075
  /* @__PURE__ */ jsx71(
8068
8076
  "th",
@@ -8150,7 +8158,7 @@ function FinancialStatementQuestionComponent(props) {
8150
8158
  externalHistoryState: historyState
8151
8159
  }
8152
8160
  ),
8153
- /* @__PURE__ */ jsx71(TypeaheadVariablesAgentPlugin, {}),
8161
+ /* @__PURE__ */ jsx71(TypeaheadVariableAgentPlugin, {}),
8154
8162
  /* @__PURE__ */ jsx71(VariableComponentPlugin, {})
8155
8163
  ] })
8156
8164
  }
@@ -14589,16 +14597,48 @@ var PopupToolbar = forwardRef12((props, ref) => {
14589
14597
 
14590
14598
  // src/content/colorDialog/colorConstants.ts
14591
14599
  var textColorList = [
14592
- { label: "Red", color: "var(--td-editor-text-color-red)" },
14593
- { label: "Green", color: "var(--td-editor-text-color-green)" },
14594
- { label: "Blue", color: "var(--td-editor-text-color-blue)" },
14595
- { label: "Purple", color: "var(--td-editor-text-color-purple)" }
14600
+ {
14601
+ label: "Red",
14602
+ color: "var(--td-editor-text-color-red)",
14603
+ bgColor: "default"
14604
+ },
14605
+ {
14606
+ label: "Green",
14607
+ color: "var(--td-editor-text-color-green)",
14608
+ bgColor: "default"
14609
+ },
14610
+ {
14611
+ label: "Blue",
14612
+ color: "var(--td-editor-text-color-blue)",
14613
+ bgColor: "default"
14614
+ },
14615
+ {
14616
+ label: "Purple",
14617
+ color: "var(--td-editor-text-color-purple)",
14618
+ bgColor: "default"
14619
+ }
14596
14620
  ];
14597
14621
  var bgColorList = [
14598
- { label: "Red", color: "var(--td-editor-bg-color-red)" },
14599
- { label: "Green", color: "var(--td-editor-bg-color-green)" },
14600
- { label: "Blue", color: "var(--td-editor-bg-color-blue)" },
14601
- { label: "Purple", color: "var(--td-editor-bg-color-purple)" }
14622
+ {
14623
+ label: "Red",
14624
+ bgColor: "var(--td-editor-bg-color-red)",
14625
+ color: "var(--td-editor-text-color-red)"
14626
+ },
14627
+ {
14628
+ label: "Green",
14629
+ bgColor: "var(--td-editor-bg-color-green)",
14630
+ color: "var(--td-editor-text-color-green)"
14631
+ },
14632
+ {
14633
+ label: "Blue",
14634
+ bgColor: "var(--td-editor-bg-color-blue)",
14635
+ color: "var(--td-editor-text-color-blue)"
14636
+ },
14637
+ {
14638
+ label: "Purple",
14639
+ bgColor: "var(--td-editor-bg-color-purple)",
14640
+ color: "var(--td-editor-text-color-purple)"
14641
+ }
14602
14642
  ];
14603
14643
 
14604
14644
  // src/components/feedback/ProgressBar.tsx
@@ -15386,8 +15426,8 @@ function replaceWithVariable(variableName, variableFormat, editor, textToReplace
15386
15426
  );
15387
15427
  }
15388
15428
 
15389
- // src/plugins/VariablesPlugin/renderVariablesMenu.tsx
15390
- function renderVariablesMenu(list, popupRef, highlighterRef, activeEditorRef, textToReplaceTargetRef, onUpdateCb) {
15429
+ // src/plugins/VariablesPlugin/renderVariableMenu.tsx
15430
+ function renderVariableMenu(list, popupRef, highlighterRef, activeEditorRef, textToReplaceTargetRef, onUpdateCb) {
15391
15431
  return [...list].map((variableName) => {
15392
15432
  return {
15393
15433
  id: variableName,
@@ -15438,7 +15478,22 @@ function useTypeaheadTriggerMatch(trigger, {
15438
15478
  );
15439
15479
  }
15440
15480
 
15481
+ // src/utils/visitVariableNodes.ts
15482
+ import { $isElementNode as $isElementNode4 } from "lexical";
15483
+ function visitVariableNodes(rootNode, cb) {
15484
+ if ($isVariableNode(rootNode)) {
15485
+ cb(rootNode);
15486
+ }
15487
+ if ($isElementNode4(rootNode)) {
15488
+ const children = rootNode.getChildren();
15489
+ for (const childNode of children) {
15490
+ visitVariableNodes(childNode, cb);
15491
+ }
15492
+ }
15493
+ }
15494
+
15441
15495
  // src/plugins/VariablesPlugin/VariablesContext.tsx
15496
+ import { $getRoot as $getRoot22 } from "lexical";
15442
15497
  import React20, {
15443
15498
  useContext as useContext4,
15444
15499
  useEffect as useEffect75,
@@ -15447,10 +15502,32 @@ import React20, {
15447
15502
  import { jsx as jsx113 } from "react/jsx-runtime";
15448
15503
  var VariablesContext = React20.createContext(null);
15449
15504
  function VariablesProvider(props) {
15450
- const { children, variablesSettings, renameVariable } = props;
15505
+ const { getEditor, getAllNestedEditors } = useBlockEditor();
15506
+ const { children, variablesSettings } = props;
15451
15507
  const [variableList, setVariableList] = useState15(
15452
15508
  variablesSettings.list
15453
15509
  );
15510
+ const updateVariablesInEditor = (newName, oldName, editor) => {
15511
+ editor.update(() => {
15512
+ visitVariableNodes($getRoot22(), (variableNode) => {
15513
+ if (variableNode.__variable === oldName) {
15514
+ variableNode.setVariable(newName);
15515
+ }
15516
+ });
15517
+ });
15518
+ };
15519
+ const renameVariable = (newName, oldName) => {
15520
+ const allNestedEditors = getAllNestedEditors();
15521
+ for (const nestedEditor of allNestedEditors) {
15522
+ updateVariablesInEditor(newName, oldName, nestedEditor);
15523
+ }
15524
+ const editorRef = getEditor();
15525
+ if (editorRef) {
15526
+ updateVariablesInEditor(newName, oldName, editorRef);
15527
+ clearVariableSelection(editorRef, newName);
15528
+ setVariableSelection(editorRef, newName);
15529
+ }
15530
+ };
15454
15531
  useEffect75(() => {
15455
15532
  setVariableList(variablesSettings.list);
15456
15533
  }, [variablesSettings]);
@@ -15459,13 +15536,17 @@ function VariablesProvider(props) {
15459
15536
  const newVariableList = [...variableList, name];
15460
15537
  setVariableList(newVariableList);
15461
15538
  };
15539
+ const handleOnRenamed = (newName, oldName) => {
15540
+ renameVariable(newName, oldName);
15541
+ variablesSettings.onUpdated(newName, oldName);
15542
+ };
15462
15543
  return /* @__PURE__ */ jsx113(
15463
15544
  VariablesContext.Provider,
15464
15545
  {
15465
15546
  value: {
15466
15547
  variableList,
15467
15548
  onCreated: handleOnCreated,
15468
- onRenameVariable: renameVariable
15549
+ onRenamed: handleOnRenamed
15469
15550
  },
15470
15551
  children
15471
15552
  }
@@ -15564,7 +15645,7 @@ function removeTextInDomSelection(editor, leadOffset, onUpdate) {
15564
15645
  );
15565
15646
  }
15566
15647
 
15567
- // src/plugins/VariablesPlugin/TypeaheadVariablesPlugin.tsx
15648
+ // src/plugins/VariablesPlugin/TypeaheadVariablePlugin.tsx
15568
15649
  import { useLexicalComposerContext as useLexicalComposerContext63 } from "@lexical/react/LexicalComposerContext";
15569
15650
  import { mergeRegister as mergeRegister25 } from "@lexical/utils";
15570
15651
  import {
@@ -15582,7 +15663,7 @@ import {
15582
15663
  import { useEffect as useEffect76, useMemo as useMemo12, useRef as useRef52 } from "react";
15583
15664
  import { Fragment as Fragment46, jsx as jsx114, jsxs as jsxs42 } from "react/jsx-runtime";
15584
15665
  var CREATE_VARIABLE_FROM_SELECTION_COMMAND = createCommand20("CREATE_VARIABLE_FROM_SELECTION_COMMAND");
15585
- function TypeaheadVariablesPlugin() {
15666
+ function TypeaheadVariablePlugin() {
15586
15667
  const { variableList, onCreated } = useVariables();
15587
15668
  const [editor] = useLexicalComposerContext63();
15588
15669
  const triggerVariableFn = useTypeaheadTriggerMatch("@", {
@@ -15736,7 +15817,7 @@ function TypeaheadVariablesPlugin() {
15736
15817
  useEffect76(() => {
15737
15818
  return mergeRegister25(
15738
15819
  editor.registerCommand(
15739
- TYPEAHEAD_VARIABLES_COMMAND,
15820
+ TYPEAHEAD_VARIABLE_COMMAND,
15740
15821
  (_payload, activeEditor) => {
15741
15822
  activeEditorRef.current = activeEditor;
15742
15823
  handleUpdate();
@@ -15801,9 +15882,9 @@ function TypeaheadVariablesPlugin() {
15801
15882
  COMMAND_PRIORITY_HIGH4
15802
15883
  )
15803
15884
  );
15804
- }, [editor]);
15885
+ }, [editor, variableList]);
15805
15886
  const menu = useMemo12(() => {
15806
- return renderVariablesMenu(
15887
+ return renderVariableMenu(
15807
15888
  variableList || [],
15808
15889
  popupRef,
15809
15890
  highlighterRef,
@@ -15933,7 +16014,7 @@ import { $findMatchingParent as $findMatchingParent2, mergeRegister as mergeRegi
15933
16014
  import {
15934
16015
  $getSelection as $getSelection14,
15935
16016
  $isDecoratorNode as $isDecoratorNode2,
15936
- $isElementNode as $isElementNode4,
16017
+ $isElementNode as $isElementNode5,
15937
16018
  $isNodeSelection as $isNodeSelection5,
15938
16019
  $isParagraphNode as $isParagraphNode6,
15939
16020
  $isRangeSelection as $isRangeSelection9,
@@ -16014,7 +16095,7 @@ function TextToolbarPlugin() {
16014
16095
  for (const node of nodes) {
16015
16096
  const element = $findMatchingParent2(
16016
16097
  node,
16017
- (parentNode) => $isElementNode4(parentNode) && !parentNode.isInline()
16098
+ (parentNode) => $isElementNode5(parentNode) && !parentNode.isInline()
16018
16099
  );
16019
16100
  if (element !== null) {
16020
16101
  element.setFormat(format);
@@ -16045,19 +16126,19 @@ function TextToolbarPlugin() {
16045
16126
  }
16046
16127
  );
16047
16128
  };
16048
- const formatBackgroundColor = (newColor) => {
16129
+ const formatBackgroundColor = (color, bgColor) => {
16049
16130
  activeEditorRef.current?.update(
16050
16131
  () => {
16051
16132
  const selection = $getSelection14();
16052
16133
  if (selection !== null) {
16053
16134
  $patchStyleText(selection, {
16054
- color: null,
16055
- "background-color": newColor !== "default" ? newColor : null,
16056
- "border-radius": newColor !== "default" ? "calc(var(--sl-border-radius-small) * 0.5)" : null,
16057
- "outline-width": newColor !== "default" ? "2px" : null,
16058
- "outline-color": newColor !== "default" ? newColor : null,
16059
- "outline-style": newColor !== "default" ? "solid" : null,
16060
- "padding-inline": newColor !== "default" ? "1px" : null
16135
+ color: color !== "default" ? color : null,
16136
+ "background-color": bgColor !== "default" ? bgColor : null,
16137
+ "border-radius": bgColor !== "default" ? "calc(var(--sl-border-radius-small) * 0.5)" : null,
16138
+ "outline-width": bgColor !== "default" ? "2px" : null,
16139
+ "outline-color": bgColor !== "default" ? bgColor : null,
16140
+ "outline-style": bgColor !== "default" ? "solid" : null,
16141
+ "padding-inline": bgColor !== "default" ? "1px" : null
16061
16142
  });
16062
16143
  }
16063
16144
  },
@@ -16341,7 +16422,7 @@ function TextToolbarPlugin() {
16341
16422
  "background-color",
16342
16423
  ""
16343
16424
  );
16344
- if ($isElementNode4(element)) {
16425
+ if ($isElementNode5(element)) {
16345
16426
  newToolbarState.textAlign = element.getFormatType();
16346
16427
  } else {
16347
16428
  newToolbarState.textAlign = "left";
@@ -16527,7 +16608,7 @@ function TextToolbarPlugin() {
16527
16608
  label: "Default",
16528
16609
  Icon: Circle,
16529
16610
  onClick: () => {
16530
- formatBackgroundColor("default");
16611
+ formatBackgroundColor("default", "default");
16531
16612
  }
16532
16613
  },
16533
16614
  ...bgColorList.map((simpleColor, index) => {
@@ -16538,7 +16619,10 @@ function TextToolbarPlugin() {
16538
16619
  color: bgColorList[index].color,
16539
16620
  bgColor: simpleColor.color,
16540
16621
  onClick: () => {
16541
- formatBackgroundColor(simpleColor.color);
16622
+ formatBackgroundColor(
16623
+ simpleColor.color,
16624
+ simpleColor.bgColor
16625
+ );
16542
16626
  }
16543
16627
  };
16544
16628
  })
@@ -17053,7 +17137,7 @@ import {
17053
17137
  $createNodeSelection as $createNodeSelection20,
17054
17138
  $createParagraphNode as $createParagraphNode23,
17055
17139
  $getNodeByKey as $getNodeByKey55,
17056
- $getRoot as $getRoot22,
17140
+ $getRoot as $getRoot23,
17057
17141
  $setSelection as $setSelection23,
17058
17142
  COMMAND_PRIORITY_EDITOR as COMMAND_PRIORITY_EDITOR16,
17059
17143
  createCommand as createCommand21,
@@ -17084,7 +17168,7 @@ function FinancialStatementQuestionPlugin() {
17084
17168
  if (targetNode) {
17085
17169
  const headerEditor = createEditor9();
17086
17170
  headerEditor.update(() => {
17087
- const root = $getRoot22();
17171
+ const root = $getRoot23();
17088
17172
  const paragraph = $createParagraphNode23();
17089
17173
  root.append(paragraph);
17090
17174
  });
@@ -17392,7 +17476,7 @@ import { mergeRegister as mergeRegister28 } from "@lexical/utils";
17392
17476
  import {
17393
17477
  $createParagraphNode as $createParagraphNode25,
17394
17478
  $getNodeByKey as $getNodeByKey57,
17395
- $getRoot as $getRoot23,
17479
+ $getRoot as $getRoot24,
17396
17480
  $getSelection as $getSelection15,
17397
17481
  $isParagraphNode as $isParagraphNode7,
17398
17482
  $isRangeSelection as $isRangeSelection10,
@@ -17558,10 +17642,17 @@ function TypeaheadMenuPlugin() {
17558
17642
  );
17559
17643
  } else if ($isParagraphNode7(node)) {
17560
17644
  if (node.getChildrenSize() === 0) {
17561
- dom.setAttribute(
17562
- "data-placeholder",
17563
- "Type / for commands or @ for variables"
17564
- );
17645
+ if (hasModule("Variables")) {
17646
+ dom.setAttribute(
17647
+ "data-placeholder",
17648
+ "Type / for commands or @ for variables"
17649
+ );
17650
+ } else {
17651
+ dom.setAttribute(
17652
+ "data-placeholder",
17653
+ "Type / for commands"
17654
+ );
17655
+ }
17565
17656
  }
17566
17657
  }
17567
17658
  hidePopup();
@@ -17702,7 +17793,7 @@ function TypeaheadMenuPlugin() {
17702
17793
  );
17703
17794
  });
17704
17795
  }
17705
- const rootNode = $getRoot23();
17796
+ const rootNode = $getRoot24();
17706
17797
  if (rootNode) {
17707
17798
  const childrenKeys = rootNode.getChildrenKeys();
17708
17799
  if (childrenKeys.length > 0) {
@@ -18033,6 +18124,15 @@ function BlockEditor(props) {
18033
18124
  getNestedEditor: (nestedEditorId) => {
18034
18125
  return nestedEditorsRef.current[nestedEditorId];
18035
18126
  },
18127
+ getAllNestedEditors: () => {
18128
+ const nestedEditors = [];
18129
+ for (const [_, value] of Object.entries(
18130
+ nestedEditorsRef.current
18131
+ )) {
18132
+ nestedEditors.push(value);
18133
+ }
18134
+ return nestedEditors;
18135
+ },
18036
18136
  unregisterNestedEditor: (nestedEditorId) => {
18037
18137
  delete nestedEditorsRef.current[nestedEditorId];
18038
18138
  },
@@ -18102,7 +18202,7 @@ function BlockEditor(props) {
18102
18202
  /* @__PURE__ */ jsx120(NodeMousePlugin, {}),
18103
18203
  /* @__PURE__ */ jsx120(TextToolbarPlugin, {}),
18104
18204
  /* @__PURE__ */ jsx120(TextToolbarAgentPlugin, {}),
18105
- /* @__PURE__ */ jsx120(TypeaheadVariablesAgentPlugin, {}),
18205
+ /* @__PURE__ */ jsx120(TypeaheadVariableAgentPlugin, {}),
18106
18206
  /* @__PURE__ */ jsx120(VariableComponentPlugin, {}),
18107
18207
  /* @__PURE__ */ jsx120(MarkdownPlugin, {})
18108
18208
  ]
@@ -18553,7 +18653,7 @@ function VariableSettings(props) {
18553
18653
  setEditingMode,
18554
18654
  getEditingModeDataCallback
18555
18655
  } = useBlockEditor();
18556
- const { variableList, onCreated } = useVariables();
18656
+ const { variableList, onRenamed } = useVariables();
18557
18657
  const [editor] = useLexicalComposerContext70();
18558
18658
  const activeEditorRef = useRef60();
18559
18659
  const [currentVariableNode, setCurrentVariableNode] = useState22();
@@ -18685,35 +18785,56 @@ function VariableSettings(props) {
18685
18785
  const foundVariable = variableList.find(
18686
18786
  (v) => v === variableNameInputRef.current?.getValue()
18687
18787
  );
18788
+ let prevVariableName = void 0;
18688
18789
  activeEditorRef.current?.update(
18689
18790
  () => {
18690
18791
  const foundVariableNode = $getNodeByKey58(nodeKey);
18691
18792
  if ($isVariableNode(foundVariableNode)) {
18793
+ prevVariableName = foundVariableNode.getVariable();
18692
18794
  foundVariableNode.setVariable(newVariableName);
18693
18795
  }
18694
18796
  },
18695
18797
  {
18696
18798
  onUpdate: () => {
18697
- if (!foundVariable) {
18698
- onCreated(newVariableName.toString());
18799
+ if (!foundVariable && prevVariableName) {
18800
+ onRenamed(newVariableName.toString(), prevVariableName);
18801
+ setTimeout(() => {
18802
+ activeEditorRef.current?.getEditorState().read(() => {
18803
+ setEditingMode({ mode: "edit" });
18804
+ const foundVariableNode = $getNodeByKey58(nodeKey);
18805
+ if ($isVariableNode(foundVariableNode)) {
18806
+ const rootEditor = getEditor();
18807
+ clearVariableSelection(
18808
+ rootEditor || editor,
18809
+ newVariableName
18810
+ );
18811
+ setVariableSelection(
18812
+ rootEditor || editor,
18813
+ newVariableName
18814
+ );
18815
+ setCurrentVariableNode(foundVariableNode);
18816
+ }
18817
+ });
18818
+ }, 300);
18819
+ } else {
18820
+ activeEditorRef.current?.getEditorState().read(() => {
18821
+ setEditingMode({ mode: "edit" });
18822
+ const foundVariableNode = $getNodeByKey58(nodeKey);
18823
+ if ($isVariableNode(foundVariableNode)) {
18824
+ const rootEditor = getEditor();
18825
+ const variableName = foundVariableNode.getVariable();
18826
+ clearVariableSelection(
18827
+ rootEditor || editor,
18828
+ variableName
18829
+ );
18830
+ setVariableSelection(
18831
+ rootEditor || editor,
18832
+ variableName
18833
+ );
18834
+ setCurrentVariableNode(foundVariableNode);
18835
+ }
18836
+ });
18699
18837
  }
18700
- activeEditorRef.current?.getEditorState().read(() => {
18701
- setEditingMode({ mode: "edit" });
18702
- const foundVariableNode = $getNodeByKey58(nodeKey);
18703
- if ($isVariableNode(foundVariableNode)) {
18704
- const rootEditor = getEditor();
18705
- const variableName = foundVariableNode.getVariable();
18706
- clearVariableSelection(
18707
- rootEditor || editor,
18708
- variableName
18709
- );
18710
- setVariableSelection(
18711
- rootEditor || editor,
18712
- variableName
18713
- );
18714
- setCurrentVariableNode(foundVariableNode);
18715
- }
18716
- });
18717
18838
  setSettingsEditingMode(false);
18718
18839
  }
18719
18840
  }
@@ -19133,88 +19254,29 @@ function VariableToolbarPlugin() {
19133
19254
  return /* @__PURE__ */ jsx131(PopupToolbar, { ref: popupToolbarRef, menu: menuItems });
19134
19255
  }
19135
19256
 
19136
- // src/utils/replaceVariablesInEditorState.ts
19137
- function replaceVariablesInEditorState(node, variablesMap) {
19138
- if (node.type === VariableNode.getType()) {
19139
- const foundPrevVariable = node.variableName ? variablesMap[node.variableName] : void 0;
19140
- if (foundPrevVariable) {
19141
- node.text = foundPrevVariable;
19142
- node.variableName = foundPrevVariable;
19143
- }
19144
- }
19145
- if (node.children && node.children.length > 0) {
19146
- node.children.forEach((child) => {
19147
- replaceVariablesInEditorState(child, variablesMap);
19148
- });
19149
- }
19150
- }
19151
-
19152
19257
  // src/modules/Variables.tsx
19153
- import {
19154
- forwardRef as forwardRef16,
19155
- useEffect as useEffect93,
19156
- useImperativeHandle as useImperativeHandle16
19157
- } from "react";
19258
+ import { useEffect as useEffect93 } from "react";
19158
19259
  import { jsx as jsx132, jsxs as jsxs49 } from "react/jsx-runtime";
19159
- var Variables = forwardRef16(
19160
- (props, ref) => {
19161
- const { variablesSettings } = props;
19162
- const {
19163
- getEditor,
19164
- onChange,
19165
- registerModule,
19166
- setEditingModeDataCallback
19167
- } = useBlockEditor();
19168
- const handleRenameVariable = (prevName, newName) => {
19169
- const editorRef = getEditor();
19170
- if (editorRef) {
19171
- const editorState = editorRef.getEditorState().toJSON();
19172
- if (editorState) {
19173
- replaceVariablesInEditorState(editorState.root, {
19174
- [prevName]: newName
19175
- });
19176
- const parsedEditorState = editorRef.parseEditorState(editorState);
19177
- if (parsedEditorState) {
19178
- editorRef.setEditorState(parsedEditorState, {
19179
- tag: "new_state"
19180
- });
19181
- if (onChange) {
19182
- onChange(editorState);
19183
- }
19184
- }
19185
- }
19186
- }
19187
- };
19188
- useImperativeHandle16(ref, () => {
19260
+ function Variables(props) {
19261
+ const { variablesSettings } = props;
19262
+ const { registerModule, setEditingModeDataCallback } = useBlockEditor();
19263
+ useEffect93(() => {
19264
+ registerModule("Variables");
19265
+ }, []);
19266
+ useEffect93(() => {
19267
+ setEditingModeDataCallback(() => {
19189
19268
  return {
19190
- renameVariable: handleRenameVariable
19269
+ variableValues: variablesSettings.getVariableValues()
19191
19270
  };
19192
19271
  });
19193
- useEffect93(() => {
19194
- registerModule("Variables");
19195
- }, []);
19196
- useEffect93(() => {
19197
- setEditingModeDataCallback(() => {
19198
- return {
19199
- variableValues: variablesSettings.getVariableValues()
19200
- };
19201
- });
19202
- }, [variablesSettings, setEditingModeDataCallback]);
19203
- return /* @__PURE__ */ jsxs49(
19204
- VariablesProvider,
19205
- {
19206
- variablesSettings,
19207
- renameVariable: handleRenameVariable,
19208
- children: [
19209
- /* @__PURE__ */ jsx132(TypeaheadVariablesPlugin, {}),
19210
- /* @__PURE__ */ jsx132(VariableSettingsPlugin, {}),
19211
- /* @__PURE__ */ jsx132(VariableToolbarPlugin, {}),
19212
- /* @__PURE__ */ jsx132(VariableToolbarAgentPlugin, {})
19213
- ]
19214
- }
19215
- );
19216
- }
19217
- );
19272
+ }, [variablesSettings, setEditingModeDataCallback]);
19273
+ return /* @__PURE__ */ jsxs49(VariablesProvider, { variablesSettings, children: [
19274
+ /* @__PURE__ */ jsx132(TypeaheadVariablePlugin, {}),
19275
+ /* @__PURE__ */ jsx132(VariableSettingsPlugin, {}),
19276
+ /* @__PURE__ */ jsx132(VariableToolbarPlugin, {}),
19277
+ /* @__PURE__ */ jsx132(VariableToolbarAgentPlugin, {})
19278
+ ] });
19279
+ }
19218
19280
  export {
19219
19281
  BlockEditor,
19220
19282
  Callout,