@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.js CHANGED
@@ -5215,14 +5215,14 @@ function DistractorButton(props) {
5215
5215
  ] });
5216
5216
  }
5217
5217
 
5218
- // src/plugins/VariablesPlugin/TypeaheadVariablesAgentPlugin.tsx
5218
+ // src/plugins/VariablesPlugin/TypeaheadVariableAgentPlugin.tsx
5219
5219
  var import_LexicalComposerContext21 = require("@lexical/react/LexicalComposerContext");
5220
5220
  var import_utils6 = require("@lexical/utils");
5221
5221
  var import_lexical23 = require("lexical");
5222
5222
  var import_react38 = require("react");
5223
5223
  var import_jsx_runtime49 = require("react/jsx-runtime");
5224
- var TYPEAHEAD_VARIABLES_COMMAND = (0, import_lexical23.createCommand)("TYPEAHEAD_VARIABLES_COMMAND");
5225
- function TypeaheadVariablesAgentPlugin() {
5224
+ var TYPEAHEAD_VARIABLE_COMMAND = (0, import_lexical23.createCommand)("TYPEAHEAD_VARIABLE_COMMAND");
5225
+ function TypeaheadVariableAgentPlugin() {
5226
5226
  const { hasModule, modulesNumber } = useBlockEditor();
5227
5227
  const [editor] = (0, import_LexicalComposerContext21.useLexicalComposerContext)();
5228
5228
  (0, import_react38.useEffect)(() => {
@@ -5231,7 +5231,7 @@ function TypeaheadVariablesAgentPlugin() {
5231
5231
  editor.registerUpdateListener(({ tags }) => {
5232
5232
  if (!tags.has("history-merge")) {
5233
5233
  editor.dispatchCommand(
5234
- TYPEAHEAD_VARIABLES_COMMAND,
5234
+ TYPEAHEAD_VARIABLE_COMMAND,
5235
5235
  void 0
5236
5236
  );
5237
5237
  }
@@ -5758,7 +5758,7 @@ function JournalEntryQuestionItemComponent(props) {
5758
5758
  decoratorNode: JournalEntryQuestionNode
5759
5759
  }
5760
5760
  ),
5761
- /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(TypeaheadVariablesAgentPlugin, {}),
5761
+ /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(TypeaheadVariableAgentPlugin, {}),
5762
5762
  /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(VariableComponentPlugin, {})
5763
5763
  ] }) }) }),
5764
5764
  (!debit || !credit) && /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)("div", { className: "controls", children: [
@@ -5817,7 +5817,7 @@ function JournalEntryQuestionItemComponent(props) {
5817
5817
  decoratorNode: JournalEntryQuestionNode
5818
5818
  }
5819
5819
  ),
5820
- /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(TypeaheadVariablesAgentPlugin, {}),
5820
+ /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(TypeaheadVariableAgentPlugin, {}),
5821
5821
  /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(VariableComponentPlugin, {})
5822
5822
  ] }) }) })
5823
5823
  ]
@@ -5854,7 +5854,7 @@ function JournalEntryQuestionItemComponent(props) {
5854
5854
  decoratorNode: JournalEntryQuestionNode
5855
5855
  }
5856
5856
  ),
5857
- /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(TypeaheadVariablesAgentPlugin, {}),
5857
+ /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(TypeaheadVariableAgentPlugin, {}),
5858
5858
  /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(VariableComponentPlugin, {}),
5859
5859
  /* @__PURE__ */ (0, import_jsx_runtime54.jsx)(VariableToolbarAgentPlugin, {})
5860
5860
  ] }) }) }),
@@ -6401,7 +6401,7 @@ function QuestionItemComponent(props) {
6401
6401
  ),
6402
6402
  /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(import_LexicalHistoryPlugin4.HistoryPlugin, { externalHistoryState: historyState }),
6403
6403
  /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(TextToolbarAgentPlugin, {}),
6404
- /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(TypeaheadVariablesAgentPlugin, {}),
6404
+ /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(TypeaheadVariableAgentPlugin, {}),
6405
6405
  /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(VariableComponentPlugin, {})
6406
6406
  ] }) }) })
6407
6407
  ]
@@ -6435,7 +6435,7 @@ function QuestionItemComponent(props) {
6435
6435
  decoratorNode: MatchingQuestionNode
6436
6436
  }
6437
6437
  ),
6438
- /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(TypeaheadVariablesAgentPlugin, {}),
6438
+ /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(TypeaheadVariableAgentPlugin, {}),
6439
6439
  /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(VariableComponentPlugin, {}),
6440
6440
  /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(VariableToolbarAgentPlugin, {})
6441
6441
  ] }) }) }),
@@ -6810,7 +6810,7 @@ function MultipleOptionQuestionItemComponent(props) {
6810
6810
  decoratorNode: MultipleOptionQuestionNode
6811
6811
  }
6812
6812
  ),
6813
- /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(TypeaheadVariablesAgentPlugin, {}),
6813
+ /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(TypeaheadVariableAgentPlugin, {}),
6814
6814
  /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(VariableComponentPlugin, {}),
6815
6815
  /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(VariableToolbarAgentPlugin, {})
6816
6816
  ] }) }) }),
@@ -7253,7 +7253,7 @@ function ShortAnswerQuestionComponent(props) {
7253
7253
  decoratorNode: ShortAnswerQuestionNode
7254
7254
  }
7255
7255
  ),
7256
- /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(TypeaheadVariablesAgentPlugin, {}),
7256
+ /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(TypeaheadVariableAgentPlugin, {}),
7257
7257
  /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(VariableComponentPlugin, {}),
7258
7258
  /* @__PURE__ */ (0, import_jsx_runtime64.jsx)(VariableToolbarAgentPlugin, {})
7259
7259
  ] }) }) })
@@ -7648,7 +7648,7 @@ function FillInTheBlankQuestionComponent(props) {
7648
7648
  decoratorNode: FillInTheBlankQuestionNode
7649
7649
  }
7650
7650
  ),
7651
- /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(TypeaheadVariablesAgentPlugin, {}),
7651
+ /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(TypeaheadVariableAgentPlugin, {}),
7652
7652
  /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(VariableComponentPlugin, {}),
7653
7653
  /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(VariableToolbarAgentPlugin, {}),
7654
7654
  /* @__PURE__ */ (0, import_jsx_runtime69.jsx)(
@@ -7827,26 +7827,34 @@ function FinancialStatementQuestionComponent(props) {
7827
7827
  ),
7828
7828
  /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("div", { "data-selectable": "true", children: /* @__PURE__ */ (0, import_jsx_runtime71.jsxs)("table", { "data-selectable": "true", style: { width: "100%" }, children: [
7829
7829
  /* @__PURE__ */ (0, import_jsx_runtime71.jsxs)("thead", { "data-selectable": "true", children: [
7830
- /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("tr", { "data-selectable": "true", children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("th", { colSpan: 2, "data-selectable": "true", children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(import_LexicalNestedComposer7.LexicalNestedComposer, { initialEditor: header, children: /* @__PURE__ */ (0, import_jsx_runtime71.jsxs)(NestedEditor, { nodeKey, children: [
7831
- /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(SettingsPanelNestedAgentPlugin, {}),
7832
- /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
7833
- import_LexicalRichTextPlugin7.RichTextPlugin,
7834
- {
7835
- contentEditable: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(NestedContentEditable, {}),
7836
- ErrorBoundary: import_LexicalErrorBoundary7.LexicalErrorBoundary,
7837
- placeholder: null
7838
- },
7839
- nodeKey
7840
- ),
7841
- /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
7842
- import_LexicalHistoryPlugin8.HistoryPlugin,
7843
- {
7844
- externalHistoryState: historyState
7845
- }
7846
- ),
7847
- /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(TypeaheadVariablesAgentPlugin, {}),
7848
- /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(VariableComponentPlugin, {})
7849
- ] }) }) }) }),
7830
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)("tr", { "data-selectable": "true", children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
7831
+ "td",
7832
+ {
7833
+ className: "financial-statement-question-header",
7834
+ colSpan: 2,
7835
+ "data-selectable": "true",
7836
+ children: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(import_LexicalNestedComposer7.LexicalNestedComposer, { initialEditor: header, children: /* @__PURE__ */ (0, import_jsx_runtime71.jsxs)(NestedEditor, { nodeKey, children: [
7837
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(SettingsPanelNestedAgentPlugin, {}),
7838
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
7839
+ import_LexicalRichTextPlugin7.RichTextPlugin,
7840
+ {
7841
+ contentEditable: /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(NestedContentEditable, {}),
7842
+ ErrorBoundary: import_LexicalErrorBoundary7.LexicalErrorBoundary,
7843
+ placeholder: null
7844
+ },
7845
+ nodeKey
7846
+ ),
7847
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
7848
+ import_LexicalHistoryPlugin8.HistoryPlugin,
7849
+ {
7850
+ externalHistoryState: historyState
7851
+ }
7852
+ ),
7853
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(TypeaheadVariableAgentPlugin, {}),
7854
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(VariableComponentPlugin, {})
7855
+ ] }) })
7856
+ }
7857
+ ) }),
7850
7858
  columnHeaders.length >= 2 && /* @__PURE__ */ (0, import_jsx_runtime71.jsxs)("tr", { "data-selectable": "true", children: [
7851
7859
  /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(
7852
7860
  "th",
@@ -7934,7 +7942,7 @@ function FinancialStatementQuestionComponent(props) {
7934
7942
  externalHistoryState: historyState
7935
7943
  }
7936
7944
  ),
7937
- /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(TypeaheadVariablesAgentPlugin, {}),
7945
+ /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(TypeaheadVariableAgentPlugin, {}),
7938
7946
  /* @__PURE__ */ (0, import_jsx_runtime71.jsx)(VariableComponentPlugin, {})
7939
7947
  ] })
7940
7948
  }
@@ -14123,16 +14131,48 @@ var PopupToolbar = (0, import_react86.forwardRef)((props, ref) => {
14123
14131
 
14124
14132
  // src/content/colorDialog/colorConstants.ts
14125
14133
  var textColorList = [
14126
- { label: "Red", color: "var(--td-editor-text-color-red)" },
14127
- { label: "Green", color: "var(--td-editor-text-color-green)" },
14128
- { label: "Blue", color: "var(--td-editor-text-color-blue)" },
14129
- { label: "Purple", color: "var(--td-editor-text-color-purple)" }
14134
+ {
14135
+ label: "Red",
14136
+ color: "var(--td-editor-text-color-red)",
14137
+ bgColor: "default"
14138
+ },
14139
+ {
14140
+ label: "Green",
14141
+ color: "var(--td-editor-text-color-green)",
14142
+ bgColor: "default"
14143
+ },
14144
+ {
14145
+ label: "Blue",
14146
+ color: "var(--td-editor-text-color-blue)",
14147
+ bgColor: "default"
14148
+ },
14149
+ {
14150
+ label: "Purple",
14151
+ color: "var(--td-editor-text-color-purple)",
14152
+ bgColor: "default"
14153
+ }
14130
14154
  ];
14131
14155
  var bgColorList = [
14132
- { label: "Red", color: "var(--td-editor-bg-color-red)" },
14133
- { label: "Green", color: "var(--td-editor-bg-color-green)" },
14134
- { label: "Blue", color: "var(--td-editor-bg-color-blue)" },
14135
- { label: "Purple", color: "var(--td-editor-bg-color-purple)" }
14156
+ {
14157
+ label: "Red",
14158
+ bgColor: "var(--td-editor-bg-color-red)",
14159
+ color: "var(--td-editor-text-color-red)"
14160
+ },
14161
+ {
14162
+ label: "Green",
14163
+ bgColor: "var(--td-editor-bg-color-green)",
14164
+ color: "var(--td-editor-text-color-green)"
14165
+ },
14166
+ {
14167
+ label: "Blue",
14168
+ bgColor: "var(--td-editor-bg-color-blue)",
14169
+ color: "var(--td-editor-text-color-blue)"
14170
+ },
14171
+ {
14172
+ label: "Purple",
14173
+ bgColor: "var(--td-editor-bg-color-purple)",
14174
+ color: "var(--td-editor-text-color-purple)"
14175
+ }
14136
14176
  ];
14137
14177
 
14138
14178
  // src/components/feedback/ProgressBar.tsx
@@ -14894,8 +14934,8 @@ function replaceWithVariable(variableName, variableFormat, editor, textToReplace
14894
14934
  );
14895
14935
  }
14896
14936
 
14897
- // src/plugins/VariablesPlugin/renderVariablesMenu.tsx
14898
- function renderVariablesMenu(list, popupRef, highlighterRef, activeEditorRef, textToReplaceTargetRef, onUpdateCb) {
14937
+ // src/plugins/VariablesPlugin/renderVariableMenu.tsx
14938
+ function renderVariableMenu(list, popupRef, highlighterRef, activeEditorRef, textToReplaceTargetRef, onUpdateCb) {
14899
14939
  return [...list].map((variableName) => {
14900
14940
  return {
14901
14941
  id: variableName,
@@ -14946,15 +14986,52 @@ function useTypeaheadTriggerMatch(trigger, {
14946
14986
  );
14947
14987
  }
14948
14988
 
14989
+ // src/utils/visitVariableNodes.ts
14990
+ var import_lexical91 = require("lexical");
14991
+ function visitVariableNodes(rootNode, cb) {
14992
+ if ($isVariableNode(rootNode)) {
14993
+ cb(rootNode);
14994
+ }
14995
+ if ((0, import_lexical91.$isElementNode)(rootNode)) {
14996
+ const children = rootNode.getChildren();
14997
+ for (const childNode of children) {
14998
+ visitVariableNodes(childNode, cb);
14999
+ }
15000
+ }
15001
+ }
15002
+
14949
15003
  // src/plugins/VariablesPlugin/VariablesContext.tsx
15004
+ var import_lexical92 = require("lexical");
14950
15005
  var import_react92 = __toESM(require("react"));
14951
15006
  var import_jsx_runtime113 = require("react/jsx-runtime");
14952
15007
  var VariablesContext = import_react92.default.createContext(null);
14953
15008
  function VariablesProvider(props) {
14954
- const { children, variablesSettings, renameVariable } = props;
15009
+ const { getEditor, getAllNestedEditors } = useBlockEditor();
15010
+ const { children, variablesSettings } = props;
14955
15011
  const [variableList, setVariableList] = (0, import_react92.useState)(
14956
15012
  variablesSettings.list
14957
15013
  );
15014
+ const updateVariablesInEditor = (newName, oldName, editor) => {
15015
+ editor.update(() => {
15016
+ visitVariableNodes((0, import_lexical92.$getRoot)(), (variableNode) => {
15017
+ if (variableNode.__variable === oldName) {
15018
+ variableNode.setVariable(newName);
15019
+ }
15020
+ });
15021
+ });
15022
+ };
15023
+ const renameVariable = (newName, oldName) => {
15024
+ const allNestedEditors = getAllNestedEditors();
15025
+ for (const nestedEditor of allNestedEditors) {
15026
+ updateVariablesInEditor(newName, oldName, nestedEditor);
15027
+ }
15028
+ const editorRef = getEditor();
15029
+ if (editorRef) {
15030
+ updateVariablesInEditor(newName, oldName, editorRef);
15031
+ clearVariableSelection(editorRef, newName);
15032
+ setVariableSelection(editorRef, newName);
15033
+ }
15034
+ };
14958
15035
  (0, import_react92.useEffect)(() => {
14959
15036
  setVariableList(variablesSettings.list);
14960
15037
  }, [variablesSettings]);
@@ -14963,13 +15040,17 @@ function VariablesProvider(props) {
14963
15040
  const newVariableList = [...variableList, name];
14964
15041
  setVariableList(newVariableList);
14965
15042
  };
15043
+ const handleOnRenamed = (newName, oldName) => {
15044
+ renameVariable(newName, oldName);
15045
+ variablesSettings.onUpdated(newName, oldName);
15046
+ };
14966
15047
  return /* @__PURE__ */ (0, import_jsx_runtime113.jsx)(
14967
15048
  VariablesContext.Provider,
14968
15049
  {
14969
15050
  value: {
14970
15051
  variableList,
14971
15052
  onCreated: handleOnCreated,
14972
- onRenameVariable: renameVariable
15053
+ onRenamed: handleOnRenamed
14973
15054
  },
14974
15055
  children
14975
15056
  }
@@ -14986,11 +15067,11 @@ var useVariables = () => {
14986
15067
  };
14987
15068
 
14988
15069
  // src/utils/getSelectionDOMRangeRect.ts
14989
- var import_lexical91 = require("lexical");
15070
+ var import_lexical93 = require("lexical");
14990
15071
  function getSelectionDOMRangeRect(editor, leadOffset) {
14991
15072
  const editorWindow = editor._window || window;
14992
15073
  const range = editorWindow.document.createRange();
14993
- const domSelection = (0, import_lexical91.getDOMSelection)(editorWindow);
15074
+ const domSelection = (0, import_lexical93.getDOMSelection)(editorWindow);
14994
15075
  if (domSelection === null || !domSelection.isCollapsed) {
14995
15076
  return;
14996
15077
  }
@@ -15011,7 +15092,7 @@ function getSelectionDOMRangeRect(editor, leadOffset) {
15011
15092
  }
15012
15093
 
15013
15094
  // src/utils/removeTextInDomSelection.ts
15014
- var import_lexical92 = require("lexical");
15095
+ var import_lexical94 = require("lexical");
15015
15096
  function removeText(editorWindow, leadOffset) {
15016
15097
  const domSelection = editorWindow.getSelection();
15017
15098
  if (!domSelection || !domSelection.anchorNode) {
@@ -15036,14 +15117,14 @@ function removeTextInDomSelection(editor, leadOffset, onUpdate) {
15036
15117
  const editorWindow = editor._window || window;
15037
15118
  editor.update(
15038
15119
  () => {
15039
- const selection = (0, import_lexical92.$getSelection)();
15120
+ const selection = (0, import_lexical94.$getSelection)();
15040
15121
  let selectedNode;
15041
- if ((0, import_lexical92.$isRangeSelection)(selection)) {
15122
+ if ((0, import_lexical94.$isRangeSelection)(selection)) {
15042
15123
  selectedNode = selection.focus.getNode();
15043
15124
  }
15044
15125
  removeText(editorWindow, leadOffset);
15045
15126
  if (selectedNode) {
15046
- const selection2 = (0, import_lexical92.$createRangeSelection)();
15127
+ const selection2 = (0, import_lexical94.$createRangeSelection)();
15047
15128
  selection2.anchor.set(
15048
15129
  selectedNode.getKey(),
15049
15130
  leadOffset,
@@ -15054,7 +15135,7 @@ function removeTextInDomSelection(editor, leadOffset, onUpdate) {
15054
15135
  leadOffset,
15055
15136
  "text"
15056
15137
  );
15057
- (0, import_lexical92.$setSelection)(selection2);
15138
+ (0, import_lexical94.$setSelection)(selection2);
15058
15139
  }
15059
15140
  },
15060
15141
  {
@@ -15063,14 +15144,14 @@ function removeTextInDomSelection(editor, leadOffset, onUpdate) {
15063
15144
  );
15064
15145
  }
15065
15146
 
15066
- // src/plugins/VariablesPlugin/TypeaheadVariablesPlugin.tsx
15147
+ // src/plugins/VariablesPlugin/TypeaheadVariablePlugin.tsx
15067
15148
  var import_LexicalComposerContext63 = require("@lexical/react/LexicalComposerContext");
15068
- var import_utils30 = require("@lexical/utils");
15069
- var import_lexical93 = require("lexical");
15149
+ var import_utils31 = require("@lexical/utils");
15150
+ var import_lexical95 = require("lexical");
15070
15151
  var import_react93 = require("react");
15071
15152
  var import_jsx_runtime114 = require("react/jsx-runtime");
15072
- var CREATE_VARIABLE_FROM_SELECTION_COMMAND = (0, import_lexical93.createCommand)("CREATE_VARIABLE_FROM_SELECTION_COMMAND");
15073
- function TypeaheadVariablesPlugin() {
15153
+ var CREATE_VARIABLE_FROM_SELECTION_COMMAND = (0, import_lexical95.createCommand)("CREATE_VARIABLE_FROM_SELECTION_COMMAND");
15154
+ function TypeaheadVariablePlugin() {
15074
15155
  const { variableList, onCreated } = useVariables();
15075
15156
  const [editor] = (0, import_LexicalComposerContext63.useLexicalComposerContext)();
15076
15157
  const triggerVariableFn = useTypeaheadTriggerMatch("@", {
@@ -15082,8 +15163,8 @@ function TypeaheadVariablesPlugin() {
15082
15163
  const textToReplaceTargetRef = (0, import_react93.useRef)();
15083
15164
  const handleUpdate = () => {
15084
15165
  activeEditorRef.current?.getEditorState().read(() => {
15085
- const selection = (0, import_lexical93.$getSelection)();
15086
- if ((0, import_lexical93.$isRangeSelection)(selection)) {
15166
+ const selection = (0, import_lexical95.$getSelection)();
15167
+ if ((0, import_lexical95.$isRangeSelection)(selection)) {
15087
15168
  if (selection.isCollapsed()) {
15088
15169
  const anchor = selection.anchor;
15089
15170
  const isEmpty = anchor.getNode().getTextContent().trim().length === 0;
@@ -15222,35 +15303,35 @@ function TypeaheadVariablesPlugin() {
15222
15303
  return false;
15223
15304
  };
15224
15305
  (0, import_react93.useEffect)(() => {
15225
- return (0, import_utils30.mergeRegister)(
15306
+ return (0, import_utils31.mergeRegister)(
15226
15307
  editor.registerCommand(
15227
- TYPEAHEAD_VARIABLES_COMMAND,
15308
+ TYPEAHEAD_VARIABLE_COMMAND,
15228
15309
  (_payload, activeEditor) => {
15229
15310
  activeEditorRef.current = activeEditor;
15230
15311
  handleUpdate();
15231
15312
  return true;
15232
15313
  },
15233
- import_lexical93.COMMAND_PRIORITY_HIGH
15314
+ import_lexical95.COMMAND_PRIORITY_HIGH
15234
15315
  ),
15235
15316
  editor.registerCommand(
15236
- import_lexical93.KEY_ENTER_COMMAND,
15317
+ import_lexical95.KEY_ENTER_COMMAND,
15237
15318
  execute,
15238
- import_lexical93.COMMAND_PRIORITY_HIGH
15319
+ import_lexical95.COMMAND_PRIORITY_HIGH
15239
15320
  ),
15240
15321
  editor.registerCommand(
15241
- import_lexical93.KEY_ESCAPE_COMMAND,
15322
+ import_lexical95.KEY_ESCAPE_COMMAND,
15242
15323
  hidePopup,
15243
- import_lexical93.COMMAND_PRIORITY_HIGH
15324
+ import_lexical95.COMMAND_PRIORITY_HIGH
15244
15325
  ),
15245
15326
  editor.registerCommand(
15246
- import_lexical93.KEY_ARROW_DOWN_COMMAND,
15327
+ import_lexical95.KEY_ARROW_DOWN_COMMAND,
15247
15328
  handleMenuItemSelect("down"),
15248
- import_lexical93.COMMAND_PRIORITY_HIGH
15329
+ import_lexical95.COMMAND_PRIORITY_HIGH
15249
15330
  ),
15250
15331
  editor.registerCommand(
15251
- import_lexical93.KEY_ARROW_UP_COMMAND,
15332
+ import_lexical95.KEY_ARROW_UP_COMMAND,
15252
15333
  handleMenuItemSelect("up"),
15253
- import_lexical93.COMMAND_PRIORITY_HIGH
15334
+ import_lexical95.COMMAND_PRIORITY_HIGH
15254
15335
  ),
15255
15336
  editor.registerCommand(
15256
15337
  CREATE_VARIABLE_FROM_SELECTION_COMMAND,
@@ -15276,9 +15357,9 @@ function TypeaheadVariablesPlugin() {
15276
15357
  onUpdate: () => {
15277
15358
  if (newNodeKey) {
15278
15359
  activeEditor.update(() => {
15279
- const newSelection = (0, import_lexical93.$createNodeSelection)();
15360
+ const newSelection = (0, import_lexical95.$createNodeSelection)();
15280
15361
  newSelection.add(newNodeKey || "");
15281
- (0, import_lexical93.$setSelection)(newSelection);
15362
+ (0, import_lexical95.$setSelection)(newSelection);
15282
15363
  });
15283
15364
  }
15284
15365
  }
@@ -15286,12 +15367,12 @@ function TypeaheadVariablesPlugin() {
15286
15367
  );
15287
15368
  return true;
15288
15369
  },
15289
- import_lexical93.COMMAND_PRIORITY_HIGH
15370
+ import_lexical95.COMMAND_PRIORITY_HIGH
15290
15371
  )
15291
15372
  );
15292
- }, [editor]);
15373
+ }, [editor, variableList]);
15293
15374
  const menu = (0, import_react93.useMemo)(() => {
15294
- return renderVariablesMenu(
15375
+ return renderVariableMenu(
15295
15376
  variableList || [],
15296
15377
  popupRef,
15297
15378
  highlighterRef,
@@ -15410,8 +15491,8 @@ var import_LexicalComposerContext64 = require("@lexical/react/LexicalComposerCon
15410
15491
  var import_rich_text10 = require("@lexical/rich-text");
15411
15492
  var import_selection2 = require("@lexical/selection");
15412
15493
  var import_table16 = require("@lexical/table");
15413
- var import_utils31 = require("@lexical/utils");
15414
- var import_lexical94 = require("lexical");
15494
+ var import_utils32 = require("@lexical/utils");
15495
+ var import_lexical96 = require("lexical");
15415
15496
  var import_debounce5 = __toESM(require("lodash-es/debounce"));
15416
15497
  var import_lucide_react19 = require("lucide-react");
15417
15498
  var import_react94 = require("react");
@@ -15440,8 +15521,8 @@ function TextToolbarPlugin() {
15440
15521
  const [selectionType, setSelectionType] = (0, import_react94.useState)("paragraph");
15441
15522
  const formatText = (format) => {
15442
15523
  activeEditorRef.current?.update(() => {
15443
- const selection = (0, import_lexical94.$getSelection)();
15444
- if (!(0, import_lexical94.$isRangeSelection)(selection)) {
15524
+ const selection = (0, import_lexical96.$getSelection)();
15525
+ if (!(0, import_lexical96.$isRangeSelection)(selection)) {
15445
15526
  return false;
15446
15527
  }
15447
15528
  selection.formatText(format);
@@ -15449,15 +15530,15 @@ function TextToolbarPlugin() {
15449
15530
  };
15450
15531
  const formatElement = (format) => {
15451
15532
  activeEditorRef.current?.update(() => {
15452
- const selection = (0, import_lexical94.$getSelection)();
15453
- if (!(0, import_lexical94.$isRangeSelection)(selection) && !(0, import_lexical94.$isNodeSelection)(selection)) {
15533
+ const selection = (0, import_lexical96.$getSelection)();
15534
+ if (!(0, import_lexical96.$isRangeSelection)(selection) && !(0, import_lexical96.$isNodeSelection)(selection)) {
15454
15535
  return false;
15455
15536
  }
15456
15537
  const nodes = selection.getNodes();
15457
15538
  for (const node of nodes) {
15458
- const element = (0, import_utils31.$findMatchingParent)(
15539
+ const element = (0, import_utils32.$findMatchingParent)(
15459
15540
  node,
15460
- (parentNode) => (0, import_lexical94.$isElementNode)(parentNode) && !parentNode.isInline()
15541
+ (parentNode) => (0, import_lexical96.$isElementNode)(parentNode) && !parentNode.isInline()
15461
15542
  );
15462
15543
  if (element !== null) {
15463
15544
  element.setFormat(format);
@@ -15468,7 +15549,7 @@ function TextToolbarPlugin() {
15468
15549
  const formatColor = (newColor) => {
15469
15550
  activeEditorRef.current?.update(
15470
15551
  () => {
15471
- const selection = (0, import_lexical94.$getSelection)();
15552
+ const selection = (0, import_lexical96.$getSelection)();
15472
15553
  if (selection !== null) {
15473
15554
  (0, import_selection2.$patchStyleText)(selection, {
15474
15555
  color: newColor !== "default" ? newColor : null,
@@ -15488,19 +15569,19 @@ function TextToolbarPlugin() {
15488
15569
  }
15489
15570
  );
15490
15571
  };
15491
- const formatBackgroundColor = (newColor) => {
15572
+ const formatBackgroundColor = (color, bgColor) => {
15492
15573
  activeEditorRef.current?.update(
15493
15574
  () => {
15494
- const selection = (0, import_lexical94.$getSelection)();
15575
+ const selection = (0, import_lexical96.$getSelection)();
15495
15576
  if (selection !== null) {
15496
15577
  (0, import_selection2.$patchStyleText)(selection, {
15497
- color: null,
15498
- "background-color": newColor !== "default" ? newColor : null,
15499
- "border-radius": newColor !== "default" ? "calc(var(--sl-border-radius-small) * 0.5)" : null,
15500
- "outline-width": newColor !== "default" ? "2px" : null,
15501
- "outline-color": newColor !== "default" ? newColor : null,
15502
- "outline-style": newColor !== "default" ? "solid" : null,
15503
- "padding-inline": newColor !== "default" ? "1px" : null
15578
+ color: color !== "default" ? color : null,
15579
+ "background-color": bgColor !== "default" ? bgColor : null,
15580
+ "border-radius": bgColor !== "default" ? "calc(var(--sl-border-radius-small) * 0.5)" : null,
15581
+ "outline-width": bgColor !== "default" ? "2px" : null,
15582
+ "outline-color": bgColor !== "default" ? bgColor : null,
15583
+ "outline-style": bgColor !== "default" ? "solid" : null,
15584
+ "padding-inline": bgColor !== "default" ? "1px" : null
15504
15585
  });
15505
15586
  }
15506
15587
  },
@@ -15514,7 +15595,7 @@ function TextToolbarPlugin() {
15514
15595
  const clearFormatting = () => {
15515
15596
  activeEditorRef.current?.update(
15516
15597
  () => {
15517
- const selection = (0, import_lexical94.$getSelection)();
15598
+ const selection = (0, import_lexical96.$getSelection)();
15518
15599
  if (selection !== null) {
15519
15600
  (0, import_selection2.$patchStyleText)(selection, {
15520
15601
  "background-color": null,
@@ -15527,10 +15608,10 @@ function TextToolbarPlugin() {
15527
15608
  "font-size": null,
15528
15609
  "font-weight": null
15529
15610
  });
15530
- if ((0, import_lexical94.$isRangeSelection)(selection)) {
15611
+ if ((0, import_lexical96.$isRangeSelection)(selection)) {
15531
15612
  const selectedNodes = selection.getNodes();
15532
15613
  for (const selectedNode of selectedNodes) {
15533
- if ((0, import_lexical94.$isTextNode)(selectedNode)) {
15614
+ if ((0, import_lexical96.$isTextNode)(selectedNode)) {
15534
15615
  if (selectedNode.hasFormat("bold") || selectedNode.hasFormat("italic") || selectedNode.hasFormat("underline") || selectedNode.hasFormat("strikethrough") || selectedNode.hasFormat("subscript") || selectedNode.hasFormat("superscript")) {
15535
15616
  selectedNode.setFormat(0);
15536
15617
  }
@@ -15538,7 +15619,7 @@ function TextToolbarPlugin() {
15538
15619
  }
15539
15620
  const newSelection = selection.clone();
15540
15621
  newSelection.format = 0;
15541
- (0, import_lexical94.$setSelection)(newSelection);
15622
+ (0, import_lexical96.$setSelection)(newSelection);
15542
15623
  }
15543
15624
  }
15544
15625
  },
@@ -15552,7 +15633,7 @@ function TextToolbarPlugin() {
15552
15633
  function createLink() {
15553
15634
  let currentSelection;
15554
15635
  activeEditorRef.current?.getEditorState().read(() => {
15555
- currentSelection = (0, import_lexical94.$getSelection)()?.clone();
15636
+ currentSelection = (0, import_lexical96.$getSelection)()?.clone();
15556
15637
  if (currentSelection) {
15557
15638
  activeEditorRef.current?.dispatchCommand(
15558
15639
  SHOW_LINK_EDITOR_COMMAND,
@@ -15574,7 +15655,7 @@ function TextToolbarPlugin() {
15574
15655
  } else if (!activeDecoratorRef.current) {
15575
15656
  clearFormatting();
15576
15657
  const selectedNode = selectedNodeRef.current;
15577
- if ((0, import_lexical94.$isParagraphNode)(selectedNode)) {
15658
+ if ((0, import_lexical96.$isParagraphNode)(selectedNode)) {
15578
15659
  activeEditorRef.current?.getEditorState().read(() => {
15579
15660
  const foundParentTableNode = getParentNodeType(
15580
15661
  selectedNode,
@@ -15686,7 +15767,7 @@ function TextToolbarPlugin() {
15686
15767
  }
15687
15768
  };
15688
15769
  (0, import_react94.useEffect)(() => {
15689
- return (0, import_utils31.mergeRegister)(
15770
+ return (0, import_utils32.mergeRegister)(
15690
15771
  editor.registerCommand(
15691
15772
  TEXT_TOOLBAR_SELECTION_CHANGE_COMMAND,
15692
15773
  (payload, activeEditor) => {
@@ -15694,18 +15775,18 @@ function TextToolbarPlugin() {
15694
15775
  activeDecoratorRef.current = payload.decoratorNode;
15695
15776
  if (popupToolbarRef.current) {
15696
15777
  activeEditor.getEditorState().read(() => {
15697
- const selection = (0, import_lexical94.$getSelection)();
15778
+ const selection = (0, import_lexical96.$getSelection)();
15698
15779
  if (!selection || selection.isCollapsed()) {
15699
15780
  popupToolbarRef.current?.hideToolbar();
15700
15781
  return false;
15701
15782
  }
15702
- if (!(0, import_lexical94.$isRangeSelection)(selection)) {
15783
+ if (!(0, import_lexical96.$isRangeSelection)(selection)) {
15703
15784
  popupToolbarRef.current?.hideToolbar();
15704
15785
  return false;
15705
15786
  }
15706
15787
  const selectedNodes = selection.getNodes();
15707
15788
  if (selectedNodes.findIndex(
15708
- (node) => (0, import_lexical94.$isDecoratorNode)(node)
15789
+ (node) => (0, import_lexical96.$isDecoratorNode)(node)
15709
15790
  ) >= 0) {
15710
15791
  popupToolbarRef.current?.hideToolbar();
15711
15792
  return false;
@@ -15721,11 +15802,11 @@ function TextToolbarPlugin() {
15721
15802
  return false;
15722
15803
  }
15723
15804
  const anchorNode = selection.anchor.getNode();
15724
- let element = anchorNode.getKey() === "root" ? anchorNode : (0, import_utils31.$findMatchingParent)(
15805
+ let element = anchorNode.getKey() === "root" ? anchorNode : (0, import_utils32.$findMatchingParent)(
15725
15806
  anchorNode,
15726
15807
  (e) => {
15727
15808
  const parent = e.getParent();
15728
- return parent !== null && (0, import_lexical94.$isRootOrShadowRoot)(parent);
15809
+ return parent !== null && (0, import_lexical96.$isRootOrShadowRoot)(parent);
15729
15810
  }
15730
15811
  );
15731
15812
  selectedNodeRef.current = element;
@@ -15736,7 +15817,7 @@ function TextToolbarPlugin() {
15736
15817
  setSelectionType("list");
15737
15818
  } else {
15738
15819
  const type = (0, import_rich_text10.$isHeadingNode)(element) ? element.getTag() : element.getType();
15739
- if (type === import_lexical94.ParagraphNode.getType()) {
15820
+ if (type === import_lexical96.ParagraphNode.getType()) {
15740
15821
  setSelectionType("paragraph");
15741
15822
  } else {
15742
15823
  setSelectionType("headings");
@@ -15784,7 +15865,7 @@ function TextToolbarPlugin() {
15784
15865
  "background-color",
15785
15866
  ""
15786
15867
  );
15787
- if ((0, import_lexical94.$isElementNode)(element)) {
15868
+ if ((0, import_lexical96.$isElementNode)(element)) {
15788
15869
  newToolbarState.textAlign = element.getFormatType();
15789
15870
  } else {
15790
15871
  newToolbarState.textAlign = "left";
@@ -15794,17 +15875,17 @@ function TextToolbarPlugin() {
15794
15875
  }
15795
15876
  return false;
15796
15877
  },
15797
- import_lexical94.COMMAND_PRIORITY_HIGH
15878
+ import_lexical96.COMMAND_PRIORITY_HIGH
15798
15879
  ),
15799
15880
  editor.registerCommand(
15800
- import_lexical94.KEY_ESCAPE_COMMAND,
15881
+ import_lexical96.KEY_ESCAPE_COMMAND,
15801
15882
  () => {
15802
15883
  if (popupToolbarRef.current?.isShown()) {
15803
15884
  popupToolbarRef.current?.hideToolbar();
15804
15885
  }
15805
15886
  return false;
15806
15887
  },
15807
- import_lexical94.COMMAND_PRIORITY_NORMAL
15888
+ import_lexical96.COMMAND_PRIORITY_NORMAL
15808
15889
  ),
15809
15890
  editor.registerRootListener(
15810
15891
  (rootElement, prevRootElement) => {
@@ -15970,7 +16051,7 @@ function TextToolbarPlugin() {
15970
16051
  label: "Default",
15971
16052
  Icon: import_lucide_react19.Circle,
15972
16053
  onClick: () => {
15973
- formatBackgroundColor("default");
16054
+ formatBackgroundColor("default", "default");
15974
16055
  }
15975
16056
  },
15976
16057
  ...bgColorList.map((simpleColor, index) => {
@@ -15981,7 +16062,10 @@ function TextToolbarPlugin() {
15981
16062
  color: bgColorList[index].color,
15982
16063
  bgColor: simpleColor.color,
15983
16064
  onClick: () => {
15984
- formatBackgroundColor(simpleColor.color);
16065
+ formatBackgroundColor(
16066
+ simpleColor.color,
16067
+ simpleColor.bgColor
16068
+ );
15985
16069
  }
15986
16070
  };
15987
16071
  })
@@ -16095,7 +16179,7 @@ function TextToolbarPlugin() {
16095
16179
  onClick: () => {
16096
16180
  clearFormatting();
16097
16181
  const selectedNode = selectedNodeRef.current;
16098
- if ((0, import_lexical94.$isParagraphNode)(selectedNode)) {
16182
+ if ((0, import_lexical96.$isParagraphNode)(selectedNode)) {
16099
16183
  activeEditorRef.current?.getEditorState().read(() => {
16100
16184
  const foundParentTableNode = getParentNodeType(
16101
16185
  selectedNode,
@@ -16208,7 +16292,7 @@ function renderCalloutModuleMenu(popupRef, targetNodeKeyRef, activeEditorRef) {
16208
16292
  // src/plugins/TypeaheadMenuPlugin/renderDefaultComponentsMenu.tsx
16209
16293
  var import_list14 = require("@lexical/list");
16210
16294
  var import_rich_text11 = require("@lexical/rich-text");
16211
- var import_lexical95 = require("lexical");
16295
+ var import_lexical97 = require("lexical");
16212
16296
  var import_lucide_react21 = require("lucide-react");
16213
16297
  function renderDefaultComponentsMenu(popupRef, targetNodeKeyRef, activeEditorRef) {
16214
16298
  return [
@@ -16225,7 +16309,7 @@ function renderDefaultComponentsMenu(popupRef, targetNodeKeyRef, activeEditorRef
16225
16309
  onClick: () => {
16226
16310
  activeEditorRef.current?.update(() => {
16227
16311
  if (targetNodeKeyRef.current) {
16228
- const targetNode = (0, import_lexical95.$getNodeByKey)(
16312
+ const targetNode = (0, import_lexical97.$getNodeByKey)(
16229
16313
  targetNodeKeyRef.current
16230
16314
  );
16231
16315
  if (targetNode) {
@@ -16246,7 +16330,7 @@ function renderDefaultComponentsMenu(popupRef, targetNodeKeyRef, activeEditorRef
16246
16330
  onClick: () => {
16247
16331
  activeEditorRef.current?.update(() => {
16248
16332
  if (targetNodeKeyRef.current) {
16249
- const targetNode = (0, import_lexical95.$getNodeByKey)(
16333
+ const targetNode = (0, import_lexical97.$getNodeByKey)(
16250
16334
  targetNodeKeyRef.current
16251
16335
  );
16252
16336
  if (targetNode) {
@@ -16267,7 +16351,7 @@ function renderDefaultComponentsMenu(popupRef, targetNodeKeyRef, activeEditorRef
16267
16351
  onClick: () => {
16268
16352
  activeEditorRef.current?.update(() => {
16269
16353
  if (targetNodeKeyRef.current) {
16270
- const targetNode = (0, import_lexical95.$getNodeByKey)(
16354
+ const targetNode = (0, import_lexical97.$getNodeByKey)(
16271
16355
  targetNodeKeyRef.current
16272
16356
  );
16273
16357
  if (targetNode) {
@@ -16299,11 +16383,11 @@ function renderDefaultComponentsMenu(popupRef, targetNodeKeyRef, activeEditorRef
16299
16383
  onClick: () => {
16300
16384
  activeEditorRef.current?.update(() => {
16301
16385
  if (targetNodeKeyRef.current) {
16302
- const targetNode = (0, import_lexical95.$getNodeByKey)(
16386
+ const targetNode = (0, import_lexical97.$getNodeByKey)(
16303
16387
  targetNodeKeyRef.current
16304
16388
  );
16305
16389
  if (targetNode) {
16306
- const newParagraphNode = (0, import_lexical95.$createParagraphNode)();
16390
+ const newParagraphNode = (0, import_lexical97.$createParagraphNode)();
16307
16391
  targetNode.replace(newParagraphNode);
16308
16392
  newParagraphNode.select();
16309
16393
  activeEditorRef.current?.dispatchCommand(
@@ -16330,11 +16414,11 @@ function renderDefaultComponentsMenu(popupRef, targetNodeKeyRef, activeEditorRef
16330
16414
  onClick: () => {
16331
16415
  activeEditorRef.current?.update(() => {
16332
16416
  if (targetNodeKeyRef.current) {
16333
- const targetNode = (0, import_lexical95.$getNodeByKey)(
16417
+ const targetNode = (0, import_lexical97.$getNodeByKey)(
16334
16418
  targetNodeKeyRef.current
16335
16419
  );
16336
16420
  if (targetNode) {
16337
- const newParagraphNode = (0, import_lexical95.$createParagraphNode)();
16421
+ const newParagraphNode = (0, import_lexical97.$createParagraphNode)();
16338
16422
  targetNode.replace(newParagraphNode);
16339
16423
  newParagraphNode.select();
16340
16424
  activeEditorRef.current?.dispatchCommand(
@@ -16361,13 +16445,13 @@ function renderDefaultComponentsMenu(popupRef, targetNodeKeyRef, activeEditorRef
16361
16445
  onClick: () => {
16362
16446
  activeEditorRef.current?.update(() => {
16363
16447
  if (targetNodeKeyRef.current) {
16364
- const targetNode = (0, import_lexical95.$getNodeByKey)(
16448
+ const targetNode = (0, import_lexical97.$getNodeByKey)(
16365
16449
  targetNodeKeyRef.current
16366
16450
  );
16367
16451
  if (targetNode) {
16368
16452
  const newNode = $createHorizontalRuleNode();
16369
16453
  targetNode.replace(newNode);
16370
- const newParagraphNode = (0, import_lexical95.$createParagraphNode)();
16454
+ const newParagraphNode = (0, import_lexical97.$createParagraphNode)();
16371
16455
  newNode.insertAfter(newParagraphNode);
16372
16456
  newParagraphNode.selectStart();
16373
16457
  }
@@ -16405,7 +16489,7 @@ function renderImageModuleMenu(popupRef, targetNodeKeyRef, activeEditorRef) {
16405
16489
 
16406
16490
  // src/plugins/FinancialStatementQuestionPlugin/FinancialStatementQuestionSettings.tsx
16407
16491
  var import_LexicalComposerContext65 = require("@lexical/react/LexicalComposerContext");
16408
- var import_lexical96 = require("lexical");
16492
+ var import_lexical98 = require("lexical");
16409
16493
  var import_react95 = require("react");
16410
16494
 
16411
16495
  // src/plugins/FinancialStatementQuestionPlugin/validatePointslnput.ts
@@ -16437,7 +16521,7 @@ function FinancialStatementQuestionSettings(props) {
16437
16521
  (0, import_react95.useEffect)(() => {
16438
16522
  if (nodeKey) {
16439
16523
  editor.getEditorState().read(() => {
16440
- const fillInTheBlankNode = (0, import_lexical96.$getNodeByKey)(nodeKey);
16524
+ const fillInTheBlankNode = (0, import_lexical98.$getNodeByKey)(nodeKey);
16441
16525
  if (fillInTheBlankNode && $isFinancialStatementQuestionNode(fillInTheBlankNode)) {
16442
16526
  setFoundNode(fillInTheBlankNode);
16443
16527
  }
@@ -16460,7 +16544,7 @@ function FinancialStatementQuestionSettings(props) {
16460
16544
  label: "Points",
16461
16545
  onChange: (value) => {
16462
16546
  editor.update(() => {
16463
- const targetNode = (0, import_lexical96.$getNodeByKey)(nodeKey);
16547
+ const targetNode = (0, import_lexical98.$getNodeByKey)(nodeKey);
16464
16548
  if (targetNode && $isFinancialStatementQuestionNode(targetNode)) {
16465
16549
  try {
16466
16550
  validatePointsInput6(value);
@@ -16478,11 +16562,11 @@ function FinancialStatementQuestionSettings(props) {
16478
16562
 
16479
16563
  // src/plugins/FinancialStatementQuestionPlugin/FinancialStatementQuestionPlugin.tsx
16480
16564
  var import_LexicalComposerContext66 = require("@lexical/react/LexicalComposerContext");
16481
- var import_utils32 = require("@lexical/utils");
16482
- var import_lexical97 = require("lexical");
16565
+ var import_utils33 = require("@lexical/utils");
16566
+ var import_lexical99 = require("lexical");
16483
16567
  var import_react96 = require("react");
16484
16568
  var import_jsx_runtime117 = require("react/jsx-runtime");
16485
- var INSERT_FINANCIAL_STATEMENT_QUESTION_COMMAND = (0, import_lexical97.createCommand)("INSERT_FINANCIAL_STATEMENT_QUESTION_COMMAND");
16569
+ var INSERT_FINANCIAL_STATEMENT_QUESTION_COMMAND = (0, import_lexical99.createCommand)("INSERT_FINANCIAL_STATEMENT_QUESTION_COMMAND");
16486
16570
  function FinancialStatementQuestionPlugin() {
16487
16571
  const {
16488
16572
  registerSettingsPanel,
@@ -16493,7 +16577,7 @@ function FinancialStatementQuestionPlugin() {
16493
16577
  const [editor] = (0, import_LexicalComposerContext66.useLexicalComposerContext)();
16494
16578
  const settingsPanelStickyRef = (0, import_react96.useRef)(null);
16495
16579
  (0, import_react96.useEffect)(() => {
16496
- return (0, import_utils32.mergeRegister)(
16580
+ return (0, import_utils33.mergeRegister)(
16497
16581
  editor.registerCommand(
16498
16582
  INSERT_FINANCIAL_STATEMENT_QUESTION_COMMAND,
16499
16583
  (payload, activeEditor) => {
@@ -16501,12 +16585,12 @@ function FinancialStatementQuestionPlugin() {
16501
16585
  const { nodeKey, insertionMode } = payload;
16502
16586
  if (activeEditor === editor && nodeKey) {
16503
16587
  activeEditor.update(() => {
16504
- const targetNode = (0, import_lexical97.$getNodeByKey)(nodeKey);
16588
+ const targetNode = (0, import_lexical99.$getNodeByKey)(nodeKey);
16505
16589
  if (targetNode) {
16506
- const headerEditor = (0, import_lexical97.createEditor)();
16590
+ const headerEditor = (0, import_lexical99.createEditor)();
16507
16591
  headerEditor.update(() => {
16508
- const root = (0, import_lexical97.$getRoot)();
16509
- const paragraph = (0, import_lexical97.$createParagraphNode)();
16592
+ const root = (0, import_lexical99.$getRoot)();
16593
+ const paragraph = (0, import_lexical99.$createParagraphNode)();
16510
16594
  root.append(paragraph);
16511
16595
  });
16512
16596
  const financialStatementNode = $createFinancialStatementQuestionNode(
@@ -16523,16 +16607,16 @@ function FinancialStatementQuestionPlugin() {
16523
16607
  } else if (insertionMode === "before") {
16524
16608
  targetNode.insertBefore(financialStatementNode);
16525
16609
  }
16526
- const selection = (0, import_lexical97.$createNodeSelection)();
16610
+ const selection = (0, import_lexical99.$createNodeSelection)();
16527
16611
  selection.add(financialStatementNode.getKey());
16528
- (0, import_lexical97.$setSelection)(selection);
16612
+ (0, import_lexical99.$setSelection)(selection);
16529
16613
  }
16530
16614
  });
16531
16615
  }
16532
16616
  }
16533
16617
  return true;
16534
16618
  },
16535
- import_lexical97.COMMAND_PRIORITY_EDITOR
16619
+ import_lexical99.COMMAND_PRIORITY_EDITOR
16536
16620
  )
16537
16621
  );
16538
16622
  }, [editor]);
@@ -16802,13 +16886,13 @@ function useTypeaheadTriggerMatch2(trigger, {
16802
16886
  var import_LexicalComposerContext67 = require("@lexical/react/LexicalComposerContext");
16803
16887
  var import_rich_text12 = require("@lexical/rich-text");
16804
16888
  var import_table17 = require("@lexical/table");
16805
- var import_utils33 = require("@lexical/utils");
16806
- var import_lexical99 = require("lexical");
16889
+ var import_utils34 = require("@lexical/utils");
16890
+ var import_lexical101 = require("lexical");
16807
16891
  var import_react98 = require("react");
16808
16892
 
16809
16893
  // src/plugins/TypeaheadMenuPlugin/renderFillInTheBlankMenu.tsx
16810
16894
  var import_list15 = require("@lexical/list");
16811
- var import_lexical98 = require("lexical");
16895
+ var import_lexical100 = require("lexical");
16812
16896
  var import_lucide_react25 = require("lucide-react");
16813
16897
  function renderFillInTheBlankMenu(popupRef, targetNodeKeyRef, activeEditorRef) {
16814
16898
  return [
@@ -16831,11 +16915,11 @@ function renderFillInTheBlankMenu(popupRef, targetNodeKeyRef, activeEditorRef) {
16831
16915
  onClick: () => {
16832
16916
  activeEditorRef.current?.update(() => {
16833
16917
  if (targetNodeKeyRef.current) {
16834
- const targetNode = (0, import_lexical98.$getNodeByKey)(
16918
+ const targetNode = (0, import_lexical100.$getNodeByKey)(
16835
16919
  targetNodeKeyRef.current
16836
16920
  );
16837
16921
  if (targetNode) {
16838
- const newParagraphNode = (0, import_lexical98.$createParagraphNode)();
16922
+ const newParagraphNode = (0, import_lexical100.$createParagraphNode)();
16839
16923
  targetNode.replace(newParagraphNode);
16840
16924
  newParagraphNode.select();
16841
16925
  activeEditorRef.current?.dispatchCommand(
@@ -16862,11 +16946,11 @@ function renderFillInTheBlankMenu(popupRef, targetNodeKeyRef, activeEditorRef) {
16862
16946
  onClick: () => {
16863
16947
  activeEditorRef.current?.update(() => {
16864
16948
  if (targetNodeKeyRef.current) {
16865
- const targetNode = (0, import_lexical98.$getNodeByKey)(
16949
+ const targetNode = (0, import_lexical100.$getNodeByKey)(
16866
16950
  targetNodeKeyRef.current
16867
16951
  );
16868
16952
  if (targetNode) {
16869
- const newParagraphNode = (0, import_lexical98.$createParagraphNode)();
16953
+ const newParagraphNode = (0, import_lexical100.$createParagraphNode)();
16870
16954
  targetNode.replace(newParagraphNode);
16871
16955
  newParagraphNode.select();
16872
16956
  activeEditorRef.current?.dispatchCommand(
@@ -16926,8 +17010,8 @@ function TypeaheadMenuPlugin() {
16926
17010
  const [activeDecorator, setActiveDecorator] = (0, import_react98.useState)();
16927
17011
  const handleUpdate = () => {
16928
17012
  activeEditorRef.current?.getEditorState().read(() => {
16929
- const selection = (0, import_lexical99.$getSelection)();
16930
- if ((0, import_lexical99.$isRangeSelection)(selection)) {
17013
+ const selection = (0, import_lexical101.$getSelection)();
17014
+ if ((0, import_lexical101.$isRangeSelection)(selection)) {
16931
17015
  if (selection.isCollapsed()) {
16932
17016
  const node = selection.focus.getNode();
16933
17017
  const nodeKey = node.getKey();
@@ -16951,12 +17035,19 @@ function TypeaheadMenuPlugin() {
16951
17035
  "data-placeholder",
16952
17036
  `Heading ${level}`
16953
17037
  );
16954
- } else if ((0, import_lexical99.$isParagraphNode)(node)) {
17038
+ } else if ((0, import_lexical101.$isParagraphNode)(node)) {
16955
17039
  if (node.getChildrenSize() === 0) {
16956
- dom.setAttribute(
16957
- "data-placeholder",
16958
- "Type / for commands or @ for variables"
16959
- );
17040
+ if (hasModule("Variables")) {
17041
+ dom.setAttribute(
17042
+ "data-placeholder",
17043
+ "Type / for commands or @ for variables"
17044
+ );
17045
+ } else {
17046
+ dom.setAttribute(
17047
+ "data-placeholder",
17048
+ "Type / for commands"
17049
+ );
17050
+ }
16960
17051
  }
16961
17052
  }
16962
17053
  hidePopup();
@@ -16969,7 +17060,7 @@ function TypeaheadMenuPlugin() {
16969
17060
  const text = anchorNode.getTextContent().slice(0, anchorOffset);
16970
17061
  if (text) {
16971
17062
  if (text.startsWith("/")) {
16972
- if ((0, import_lexical99.$isParagraphNode)(parentNode)) {
17063
+ if ((0, import_lexical101.$isParagraphNode)(parentNode)) {
16973
17064
  const tableCellNode = parentNode.getParent();
16974
17065
  if (!(0, import_table17.$isTableCellNode)(tableCellNode)) {
16975
17066
  const match = triggerFn(text, editor);
@@ -17039,7 +17130,7 @@ function TypeaheadMenuPlugin() {
17039
17130
  return false;
17040
17131
  };
17041
17132
  (0, import_react98.useEffect)(() => {
17042
- return (0, import_utils33.mergeRegister)(
17133
+ return (0, import_utils34.mergeRegister)(
17043
17134
  editor.registerCommand(
17044
17135
  TYPEAHEAD_MENU_COMMAND,
17045
17136
  (payload, activeEditor) => {
@@ -17048,24 +17139,24 @@ function TypeaheadMenuPlugin() {
17048
17139
  handleUpdate();
17049
17140
  return true;
17050
17141
  },
17051
- import_lexical99.COMMAND_PRIORITY_HIGH
17142
+ import_lexical101.COMMAND_PRIORITY_HIGH
17052
17143
  ),
17053
17144
  editor.registerCommand(
17054
- import_lexical99.KEY_ENTER_COMMAND,
17145
+ import_lexical101.KEY_ENTER_COMMAND,
17055
17146
  execute,
17056
- import_lexical99.COMMAND_PRIORITY_HIGH
17147
+ import_lexical101.COMMAND_PRIORITY_HIGH
17057
17148
  ),
17058
17149
  editor.registerCommand(
17059
- import_lexical99.KEY_ESCAPE_COMMAND,
17150
+ import_lexical101.KEY_ESCAPE_COMMAND,
17060
17151
  () => {
17061
17152
  hidePopup();
17062
17153
  editor.update(() => {
17063
17154
  if (targetNodeKeyRef.current) {
17064
- const foundNode = (0, import_lexical99.$getNodeByKey)(
17155
+ const foundNode = (0, import_lexical101.$getNodeByKey)(
17065
17156
  targetNodeKeyRef.current
17066
17157
  );
17067
- if ((0, import_lexical99.$isParagraphNode)(foundNode)) {
17068
- const newParagraph = (0, import_lexical99.$createParagraphNode)();
17158
+ if ((0, import_lexical101.$isParagraphNode)(foundNode)) {
17159
+ const newParagraph = (0, import_lexical101.$createParagraphNode)();
17069
17160
  foundNode.replace(newParagraph);
17070
17161
  newParagraph.selectEnd();
17071
17162
  }
@@ -17073,20 +17164,20 @@ function TypeaheadMenuPlugin() {
17073
17164
  });
17074
17165
  return false;
17075
17166
  },
17076
- import_lexical99.COMMAND_PRIORITY_HIGH
17167
+ import_lexical101.COMMAND_PRIORITY_HIGH
17077
17168
  ),
17078
17169
  editor.registerCommand(
17079
- import_lexical99.KEY_ARROW_DOWN_COMMAND,
17170
+ import_lexical101.KEY_ARROW_DOWN_COMMAND,
17080
17171
  handleMenuItemSelect("down"),
17081
- import_lexical99.COMMAND_PRIORITY_HIGH
17172
+ import_lexical101.COMMAND_PRIORITY_HIGH
17082
17173
  ),
17083
17174
  editor.registerCommand(
17084
- import_lexical99.KEY_ARROW_UP_COMMAND,
17175
+ import_lexical101.KEY_ARROW_UP_COMMAND,
17085
17176
  handleMenuItemSelect("up"),
17086
- import_lexical99.COMMAND_PRIORITY_HIGH
17177
+ import_lexical101.COMMAND_PRIORITY_HIGH
17087
17178
  ),
17088
17179
  editor.registerCommand(
17089
- import_lexical99.BLUR_COMMAND,
17180
+ import_lexical101.BLUR_COMMAND,
17090
17181
  (_payload, activeEditor) => {
17091
17182
  activeEditor.getEditorState().read(() => {
17092
17183
  const allPlaceholders = activeEditor.getRootElement()?.querySelectorAll("[data-placeholder]");
@@ -17097,14 +17188,14 @@ function TypeaheadMenuPlugin() {
17097
17188
  );
17098
17189
  });
17099
17190
  }
17100
- const rootNode = (0, import_lexical99.$getRoot)();
17191
+ const rootNode = (0, import_lexical101.$getRoot)();
17101
17192
  if (rootNode) {
17102
17193
  const childrenKeys = rootNode.getChildrenKeys();
17103
17194
  if (childrenKeys.length > 0) {
17104
17195
  const children = rootNode.getChildren();
17105
17196
  let emptyCounter = 0;
17106
17197
  for (const childNode of children) {
17107
- if ((0, import_lexical99.$isParagraphNode)(childNode) && childNode.getTextContent().trim() === "") {
17198
+ if ((0, import_lexical101.$isParagraphNode)(childNode) && childNode.getTextContent().trim() === "") {
17108
17199
  emptyCounter++;
17109
17200
  }
17110
17201
  }
@@ -17124,7 +17215,7 @@ function TypeaheadMenuPlugin() {
17124
17215
  });
17125
17216
  return false;
17126
17217
  },
17127
- import_lexical99.COMMAND_PRIORITY_HIGH
17218
+ import_lexical101.COMMAND_PRIORITY_HIGH
17128
17219
  )
17129
17220
  );
17130
17221
  }, [editor]);
@@ -17416,6 +17507,15 @@ function BlockEditor(props) {
17416
17507
  getNestedEditor: (nestedEditorId) => {
17417
17508
  return nestedEditorsRef.current[nestedEditorId];
17418
17509
  },
17510
+ getAllNestedEditors: () => {
17511
+ const nestedEditors = [];
17512
+ for (const [_, value] of Object.entries(
17513
+ nestedEditorsRef.current
17514
+ )) {
17515
+ nestedEditors.push(value);
17516
+ }
17517
+ return nestedEditors;
17518
+ },
17419
17519
  unregisterNestedEditor: (nestedEditorId) => {
17420
17520
  delete nestedEditorsRef.current[nestedEditorId];
17421
17521
  },
@@ -17485,7 +17585,7 @@ function BlockEditor(props) {
17485
17585
  /* @__PURE__ */ (0, import_jsx_runtime120.jsx)(NodeMousePlugin, {}),
17486
17586
  /* @__PURE__ */ (0, import_jsx_runtime120.jsx)(TextToolbarPlugin, {}),
17487
17587
  /* @__PURE__ */ (0, import_jsx_runtime120.jsx)(TextToolbarAgentPlugin, {}),
17488
- /* @__PURE__ */ (0, import_jsx_runtime120.jsx)(TypeaheadVariablesAgentPlugin, {}),
17588
+ /* @__PURE__ */ (0, import_jsx_runtime120.jsx)(TypeaheadVariableAgentPlugin, {}),
17489
17589
  /* @__PURE__ */ (0, import_jsx_runtime120.jsx)(VariableComponentPlugin, {}),
17490
17590
  /* @__PURE__ */ (0, import_jsx_runtime120.jsx)(MarkdownPlugin, {})
17491
17591
  ]
@@ -17573,8 +17673,8 @@ function Image(props) {
17573
17673
  // src/plugins/LinkToolbarPlugin/LinkToolbarPlugin.tsx
17574
17674
  var import_link4 = require("@lexical/link");
17575
17675
  var import_LexicalComposerContext69 = require("@lexical/react/LexicalComposerContext");
17576
- var import_utils34 = require("@lexical/utils");
17577
- var import_lexical100 = require("lexical");
17676
+ var import_utils35 = require("@lexical/utils");
17677
+ var import_lexical102 = require("lexical");
17578
17678
  var import_debounce6 = __toESM(require("lodash-es/debounce"));
17579
17679
  var import_lucide_react26 = require("lucide-react");
17580
17680
  var import_react104 = require("react");
@@ -17605,9 +17705,9 @@ function LinkToolbarPlugin() {
17605
17705
  [editor]
17606
17706
  );
17607
17707
  (0, import_react104.useEffect)(() => {
17608
- return (0, import_utils34.mergeRegister)(
17708
+ return (0, import_utils35.mergeRegister)(
17609
17709
  editor.registerCommand(
17610
- import_lexical100.CLICK_COMMAND,
17710
+ import_lexical102.CLICK_COMMAND,
17611
17711
  (event, activeEditor) => {
17612
17712
  if (popupToolbarRef.current) {
17613
17713
  activeEditorRef.current = activeEditor;
@@ -17616,8 +17716,8 @@ function LinkToolbarPlugin() {
17616
17716
  popupToolbarRef.current?.hideToolbar();
17617
17717
  return;
17618
17718
  }
17619
- const selection = (0, import_lexical100.$getSelection)();
17620
- if (!(0, import_lexical100.$isRangeSelection)(selection)) {
17719
+ const selection = (0, import_lexical102.$getSelection)();
17720
+ if (!(0, import_lexical102.$isRangeSelection)(selection)) {
17621
17721
  popupToolbarRef.current?.hideToolbar();
17622
17722
  return;
17623
17723
  }
@@ -17636,7 +17736,7 @@ function LinkToolbarPlugin() {
17636
17736
  return;
17637
17737
  }
17638
17738
  const selectionNode = selection.anchor.getNode();
17639
- if ((0, import_lexical100.$isTextNode)(selectionNode)) {
17739
+ if ((0, import_lexical102.$isTextNode)(selectionNode)) {
17640
17740
  linkTextNodeRef.current = selectionNode;
17641
17741
  linkTextNodeOffsetRef.current = selection.focus.offset;
17642
17742
  }
@@ -17666,15 +17766,15 @@ function LinkToolbarPlugin() {
17666
17766
  }
17667
17767
  return false;
17668
17768
  },
17669
- import_lexical100.COMMAND_PRIORITY_LOW
17769
+ import_lexical102.COMMAND_PRIORITY_LOW
17670
17770
  ),
17671
17771
  editor.registerCommand(
17672
- import_lexical100.KEY_ESCAPE_COMMAND,
17772
+ import_lexical102.KEY_ESCAPE_COMMAND,
17673
17773
  () => {
17674
17774
  handleClose();
17675
17775
  return false;
17676
17776
  },
17677
- import_lexical100.COMMAND_PRIORITY_HIGH
17777
+ import_lexical102.COMMAND_PRIORITY_HIGH
17678
17778
  )
17679
17779
  );
17680
17780
  }, [editor]);
@@ -17733,7 +17833,7 @@ function LinkToolbarPlugin() {
17733
17833
  if (activeEditorRef.current) {
17734
17834
  activeEditorRef.current.update(() => {
17735
17835
  if (linkTextNodeRef.current) {
17736
- const newSelection = (0, import_lexical100.$createRangeSelection)();
17836
+ const newSelection = (0, import_lexical102.$createRangeSelection)();
17737
17837
  newSelection.anchor.set(
17738
17838
  linkTextNodeRef.current.getKey(),
17739
17839
  linkTextNodeOffsetRef.current || 0,
@@ -17778,7 +17878,7 @@ function LinkToolbarPlugin() {
17778
17878
  if (activeEditorRef.current) {
17779
17879
  activeEditorRef.current.update(() => {
17780
17880
  if (linkTextNodeRef.current) {
17781
- const newSelection = (0, import_lexical100.$createRangeSelection)();
17881
+ const newSelection = (0, import_lexical102.$createRangeSelection)();
17782
17882
  newSelection.anchor.set(
17783
17883
  linkTextNodeRef.current.getKey(),
17784
17884
  linkTextNodeOffsetRef.current || 0,
@@ -17791,7 +17891,7 @@ function LinkToolbarPlugin() {
17791
17891
  );
17792
17892
  if (newSelection) {
17793
17893
  popupToolbarRef.current?.hideToolbar();
17794
- (0, import_lexical100.$setSelection)(newSelection);
17894
+ (0, import_lexical102.$setSelection)(newSelection);
17795
17895
  (0, import_link4.$toggleLink)(null);
17796
17896
  }
17797
17897
  }
@@ -17884,7 +17984,7 @@ var import_react109 = require("react");
17884
17984
 
17885
17985
  // src/plugins/VariablesPlugin/VariableSettings.tsx
17886
17986
  var import_LexicalComposerContext70 = require("@lexical/react/LexicalComposerContext");
17887
- var import_lexical101 = require("lexical");
17987
+ var import_lexical103 = require("lexical");
17888
17988
  var import_lucide_react27 = require("lucide-react");
17889
17989
  var import_react108 = require("react");
17890
17990
  var import_jsx_runtime129 = require("react/jsx-runtime");
@@ -17918,7 +18018,7 @@ function VariableSettings(props) {
17918
18018
  setEditingMode,
17919
18019
  getEditingModeDataCallback
17920
18020
  } = useBlockEditor();
17921
- const { variableList, onCreated } = useVariables();
18021
+ const { variableList, onRenamed } = useVariables();
17922
18022
  const [editor] = (0, import_LexicalComposerContext70.useLexicalComposerContext)();
17923
18023
  const activeEditorRef = (0, import_react108.useRef)();
17924
18024
  const [currentVariableNode, setCurrentVariableNode] = (0, import_react108.useState)();
@@ -17929,7 +18029,7 @@ function VariableSettings(props) {
17929
18029
  activeEditorRef.current = nestedEditorId ? getNestedEditor(nestedEditorId) || editor : editor;
17930
18030
  if (activeEditorRef.current) {
17931
18031
  activeEditorRef.current.getEditorState().read(() => {
17932
- const foundNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18032
+ const foundNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
17933
18033
  if ($isVariableNode(foundNode)) {
17934
18034
  setCurrentVariableNode(foundNode);
17935
18035
  }
@@ -17945,7 +18045,7 @@ function VariableSettings(props) {
17945
18045
  onClick: () => {
17946
18046
  activeEditorRef.current?.update(
17947
18047
  () => {
17948
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18048
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
17949
18049
  if ($isVariableNode(foundVariableNode)) {
17950
18050
  foundVariableNode.setVariable(variableItem);
17951
18051
  }
@@ -17954,7 +18054,7 @@ function VariableSettings(props) {
17954
18054
  onUpdate: () => {
17955
18055
  setEditingMode({ mode: "edit" });
17956
18056
  activeEditorRef.current?.update(() => {
17957
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18057
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
17958
18058
  if ($isVariableNode(foundVariableNode)) {
17959
18059
  const rootEditor = getEditor();
17960
18060
  const variableName = foundVariableNode.getVariable();
@@ -17990,7 +18090,7 @@ function VariableSettings(props) {
17990
18090
  onClick: () => {
17991
18091
  activeEditorRef.current?.update(
17992
18092
  () => {
17993
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18093
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
17994
18094
  if (!$isVariableNode(foundVariableNode)) return;
17995
18095
  if (typeItem === "number" && !foundVariableNode.getVariableFormat()) {
17996
18096
  foundVariableNode.setVariableFormat(
@@ -18003,7 +18103,7 @@ function VariableSettings(props) {
18003
18103
  {
18004
18104
  onUpdate: () => {
18005
18105
  activeEditorRef.current?.getEditorState().read(() => {
18006
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18106
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
18007
18107
  if ($isVariableNode(foundVariableNode)) {
18008
18108
  setCurrentVariableNode(foundVariableNode);
18009
18109
  }
@@ -18024,7 +18124,7 @@ function VariableSettings(props) {
18024
18124
  onClick: () => {
18025
18125
  activeEditorRef.current?.update(
18026
18126
  () => {
18027
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18127
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
18028
18128
  if ($isVariableNode(foundVariableNode)) {
18029
18129
  foundVariableNode.setVariableFormat(formatItem);
18030
18130
  }
@@ -18032,7 +18132,7 @@ function VariableSettings(props) {
18032
18132
  {
18033
18133
  onUpdate: () => {
18034
18134
  activeEditorRef.current?.getEditorState().read(() => {
18035
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18135
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
18036
18136
  if ($isVariableNode(foundVariableNode)) {
18037
18137
  setCurrentVariableNode(foundVariableNode);
18038
18138
  }
@@ -18050,35 +18150,56 @@ function VariableSettings(props) {
18050
18150
  const foundVariable = variableList.find(
18051
18151
  (v) => v === variableNameInputRef.current?.getValue()
18052
18152
  );
18153
+ let prevVariableName = void 0;
18053
18154
  activeEditorRef.current?.update(
18054
18155
  () => {
18055
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18156
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
18056
18157
  if ($isVariableNode(foundVariableNode)) {
18158
+ prevVariableName = foundVariableNode.getVariable();
18057
18159
  foundVariableNode.setVariable(newVariableName);
18058
18160
  }
18059
18161
  },
18060
18162
  {
18061
18163
  onUpdate: () => {
18062
- if (!foundVariable) {
18063
- onCreated(newVariableName.toString());
18164
+ if (!foundVariable && prevVariableName) {
18165
+ onRenamed(newVariableName.toString(), prevVariableName);
18166
+ setTimeout(() => {
18167
+ activeEditorRef.current?.getEditorState().read(() => {
18168
+ setEditingMode({ mode: "edit" });
18169
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
18170
+ if ($isVariableNode(foundVariableNode)) {
18171
+ const rootEditor = getEditor();
18172
+ clearVariableSelection(
18173
+ rootEditor || editor,
18174
+ newVariableName
18175
+ );
18176
+ setVariableSelection(
18177
+ rootEditor || editor,
18178
+ newVariableName
18179
+ );
18180
+ setCurrentVariableNode(foundVariableNode);
18181
+ }
18182
+ });
18183
+ }, 300);
18184
+ } else {
18185
+ activeEditorRef.current?.getEditorState().read(() => {
18186
+ setEditingMode({ mode: "edit" });
18187
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
18188
+ if ($isVariableNode(foundVariableNode)) {
18189
+ const rootEditor = getEditor();
18190
+ const variableName = foundVariableNode.getVariable();
18191
+ clearVariableSelection(
18192
+ rootEditor || editor,
18193
+ variableName
18194
+ );
18195
+ setVariableSelection(
18196
+ rootEditor || editor,
18197
+ variableName
18198
+ );
18199
+ setCurrentVariableNode(foundVariableNode);
18200
+ }
18201
+ });
18064
18202
  }
18065
- activeEditorRef.current?.getEditorState().read(() => {
18066
- setEditingMode({ mode: "edit" });
18067
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18068
- if ($isVariableNode(foundVariableNode)) {
18069
- const rootEditor = getEditor();
18070
- const variableName = foundVariableNode.getVariable();
18071
- clearVariableSelection(
18072
- rootEditor || editor,
18073
- variableName
18074
- );
18075
- setVariableSelection(
18076
- rootEditor || editor,
18077
- variableName
18078
- );
18079
- setCurrentVariableNode(foundVariableNode);
18080
- }
18081
- });
18082
18203
  setSettingsEditingMode(false);
18083
18204
  }
18084
18205
  }
@@ -18209,9 +18330,9 @@ function VariableSettings(props) {
18209
18330
  let parentNodeKey;
18210
18331
  activeEditorRef.current?.update(
18211
18332
  () => {
18212
- const foundVariableNode = (0, import_lexical101.$getNodeByKey)(nodeKey);
18333
+ const foundVariableNode = (0, import_lexical103.$getNodeByKey)(nodeKey);
18213
18334
  if ($isVariableNode(foundVariableNode)) {
18214
- const textNode = (0, import_lexical101.$createTextNode)(
18335
+ const textNode = (0, import_lexical103.$createTextNode)(
18215
18336
  foundVariableNode.getVariable()
18216
18337
  );
18217
18338
  foundVariableNode.replace(textNode);
@@ -18224,7 +18345,7 @@ function VariableSettings(props) {
18224
18345
  activeEditorRef.current?.update(() => {
18225
18346
  if (parentNodeKey) {
18226
18347
  activeEditorRef.current?.focus();
18227
- const foundNode = (0, import_lexical101.$getNodeByKey)(parentNodeKey);
18348
+ const foundNode = (0, import_lexical103.$getNodeByKey)(parentNodeKey);
18228
18349
  foundNode?.selectStart();
18229
18350
  }
18230
18351
  });
@@ -18286,8 +18407,8 @@ function VariableSettingsPlugin() {
18286
18407
 
18287
18408
  // src/plugins/VariablesPlugin/VariableToolbarPlugin.tsx
18288
18409
  var import_LexicalComposerContext71 = require("@lexical/react/LexicalComposerContext");
18289
- var import_utils36 = require("@lexical/utils");
18290
- var import_lexical102 = require("lexical");
18410
+ var import_utils37 = require("@lexical/utils");
18411
+ var import_lexical104 = require("lexical");
18291
18412
  var import_debounce7 = __toESM(require("lodash-es/debounce"));
18292
18413
  var import_lucide_react28 = require("lucide-react");
18293
18414
  var import_react110 = require("react");
@@ -18304,7 +18425,7 @@ function VariableToolbarPlugin() {
18304
18425
  });
18305
18426
  function formatVariable(format) {
18306
18427
  activeEditorRef.current?.update(() => {
18307
- const foundNode = (0, import_lexical102.$getNodeByKey)(
18428
+ const foundNode = (0, import_lexical104.$getNodeByKey)(
18308
18429
  selectedNodeRef.current?.getKey() || ""
18309
18430
  );
18310
18431
  if ($isVariableNode(foundNode)) {
@@ -18401,16 +18522,16 @@ function VariableToolbarPlugin() {
18401
18522
  [activeEditorRef.current]
18402
18523
  );
18403
18524
  (0, import_react110.useEffect)(() => {
18404
- return (0, import_utils36.mergeRegister)(
18525
+ return (0, import_utils37.mergeRegister)(
18405
18526
  editor.registerCommand(
18406
18527
  VARIABLE_TOOLBAR_SELECTION_CHANGE_COMMAND,
18407
18528
  (_, activeEditor) => {
18408
18529
  activeEditorRef.current = activeEditor;
18409
18530
  selectedNodeRef.current = void 0;
18410
18531
  activeEditor.getEditorState().read(() => {
18411
- const selection = (0, import_lexical102.$getSelection)();
18532
+ const selection = (0, import_lexical104.$getSelection)();
18412
18533
  if (selection) {
18413
- if ((0, import_lexical102.$isNodeSelection)(selection)) {
18534
+ if ((0, import_lexical104.$isNodeSelection)(selection)) {
18414
18535
  const nodes = selection.extract();
18415
18536
  const focusedNode = nodes[0];
18416
18537
  if ($isVariableNode(focusedNode)) {
@@ -18427,7 +18548,7 @@ function VariableToolbarPlugin() {
18427
18548
  });
18428
18549
  return false;
18429
18550
  },
18430
- import_lexical102.COMMAND_PRIORITY_NORMAL
18551
+ import_lexical104.COMMAND_PRIORITY_NORMAL
18431
18552
  ),
18432
18553
  editor.registerRootListener(
18433
18554
  (rootElement, prevRootElement) => {
@@ -18487,84 +18608,29 @@ function VariableToolbarPlugin() {
18487
18608
  return /* @__PURE__ */ (0, import_jsx_runtime131.jsx)(PopupToolbar, { ref: popupToolbarRef, menu: menuItems });
18488
18609
  }
18489
18610
 
18490
- // src/utils/replaceVariablesInEditorState.ts
18491
- function replaceVariablesInEditorState(node, variablesMap) {
18492
- if (node.type === VariableNode.getType()) {
18493
- const foundPrevVariable = node.variableName ? variablesMap[node.variableName] : void 0;
18494
- if (foundPrevVariable) {
18495
- node.text = foundPrevVariable;
18496
- node.variableName = foundPrevVariable;
18497
- }
18498
- }
18499
- if (node.children && node.children.length > 0) {
18500
- node.children.forEach((child) => {
18501
- replaceVariablesInEditorState(child, variablesMap);
18502
- });
18503
- }
18504
- }
18505
-
18506
18611
  // src/modules/Variables.tsx
18507
18612
  var import_react111 = require("react");
18508
18613
  var import_jsx_runtime132 = require("react/jsx-runtime");
18509
- var Variables = (0, import_react111.forwardRef)(
18510
- (props, ref) => {
18511
- const { variablesSettings } = props;
18512
- const {
18513
- getEditor,
18514
- onChange,
18515
- registerModule,
18516
- setEditingModeDataCallback
18517
- } = useBlockEditor();
18518
- const handleRenameVariable = (prevName, newName) => {
18519
- const editorRef = getEditor();
18520
- if (editorRef) {
18521
- const editorState = editorRef.getEditorState().toJSON();
18522
- if (editorState) {
18523
- replaceVariablesInEditorState(editorState.root, {
18524
- [prevName]: newName
18525
- });
18526
- const parsedEditorState = editorRef.parseEditorState(editorState);
18527
- if (parsedEditorState) {
18528
- editorRef.setEditorState(parsedEditorState, {
18529
- tag: "new_state"
18530
- });
18531
- if (onChange) {
18532
- onChange(editorState);
18533
- }
18534
- }
18535
- }
18536
- }
18537
- };
18538
- (0, import_react111.useImperativeHandle)(ref, () => {
18614
+ function Variables(props) {
18615
+ const { variablesSettings } = props;
18616
+ const { registerModule, setEditingModeDataCallback } = useBlockEditor();
18617
+ (0, import_react111.useEffect)(() => {
18618
+ registerModule("Variables");
18619
+ }, []);
18620
+ (0, import_react111.useEffect)(() => {
18621
+ setEditingModeDataCallback(() => {
18539
18622
  return {
18540
- renameVariable: handleRenameVariable
18623
+ variableValues: variablesSettings.getVariableValues()
18541
18624
  };
18542
18625
  });
18543
- (0, import_react111.useEffect)(() => {
18544
- registerModule("Variables");
18545
- }, []);
18546
- (0, import_react111.useEffect)(() => {
18547
- setEditingModeDataCallback(() => {
18548
- return {
18549
- variableValues: variablesSettings.getVariableValues()
18550
- };
18551
- });
18552
- }, [variablesSettings, setEditingModeDataCallback]);
18553
- return /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)(
18554
- VariablesProvider,
18555
- {
18556
- variablesSettings,
18557
- renameVariable: handleRenameVariable,
18558
- children: [
18559
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(TypeaheadVariablesPlugin, {}),
18560
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(VariableSettingsPlugin, {}),
18561
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(VariableToolbarPlugin, {}),
18562
- /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(VariableToolbarAgentPlugin, {})
18563
- ]
18564
- }
18565
- );
18566
- }
18567
- );
18626
+ }, [variablesSettings, setEditingModeDataCallback]);
18627
+ return /* @__PURE__ */ (0, import_jsx_runtime132.jsxs)(VariablesProvider, { variablesSettings, children: [
18628
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(TypeaheadVariablePlugin, {}),
18629
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(VariableSettingsPlugin, {}),
18630
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(VariableToolbarPlugin, {}),
18631
+ /* @__PURE__ */ (0, import_jsx_runtime132.jsx)(VariableToolbarAgentPlugin, {})
18632
+ ] });
18633
+ }
18568
18634
  // Annotate the CommonJS export names for ESM import in node:
18569
18635
  0 && (module.exports = {
18570
18636
  BlockEditor,