@underverse-ui/underverse 1.0.202 → 1.0.203

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.cjs CHANGED
@@ -998,6 +998,8 @@ var en_default = {
998
998
  alignCenter: "Align Center",
999
999
  alignRight: "Align Right",
1000
1000
  justify: "Justify",
1001
+ decreaseIndent: "Decrease Indent",
1002
+ increaseIndent: "Increase Indent",
1001
1003
  bulletList: "Bullet List",
1002
1004
  orderedList: "Numbered List",
1003
1005
  taskList: "Task List",
@@ -1447,6 +1449,8 @@ var vi_default = {
1447
1449
  alignCenter: "C\u0103n gi\u1EEFa",
1448
1450
  alignRight: "C\u0103n ph\u1EA3i",
1449
1451
  justify: "C\u0103n \u0111\u1EC1u",
1452
+ decreaseIndent: "Gi\u1EA3m l\u1EC1",
1453
+ increaseIndent: "T\u0103ng l\u1EC1",
1450
1454
  bulletList: "Danh s\xE1ch d\u1EA5u ch\u1EA5m",
1451
1455
  orderedList: "Danh s\xE1ch s\u1ED1",
1452
1456
  taskList: "Danh s\xE1ch c\xF4ng vi\u1EC7c",
@@ -1896,6 +1900,8 @@ var ko_default = {
1896
1900
  alignCenter: "\uAC00\uC6B4\uB370 \uC815\uB82C",
1897
1901
  alignRight: "\uC624\uB978\uCABD \uC815\uB82C",
1898
1902
  justify: "\uC591\uCABD \uB9DE\uCDA4",
1903
+ decreaseIndent: "\uB0B4\uC5B4\uC4F0\uAE30",
1904
+ increaseIndent: "\uB4E4\uC5EC\uC4F0\uAE30",
1899
1905
  bulletList: "\uAE00\uBA38\uB9AC \uAE30\uD638 \uBAA9\uB85D",
1900
1906
  orderedList: "\uBC88\uD638 \uB9E4\uAE30\uAE30 \uBAA9\uB85D",
1901
1907
  taskList: "\uD560 \uC77C \uBAA9\uB85D",
@@ -2345,6 +2351,8 @@ var ja_default = {
2345
2351
  alignCenter: "\u4E2D\u592E\u63C3\u3048",
2346
2352
  alignRight: "\u53F3\u63C3\u3048",
2347
2353
  justify: "\u4E21\u7AEF\u63C3\u3048",
2354
+ decreaseIndent: "\u30A4\u30F3\u30C7\u30F3\u30C8\u3092\u6E1B\u3089\u3059",
2355
+ increaseIndent: "\u30A4\u30F3\u30C7\u30F3\u30C8\u3092\u5897\u3084\u3059",
2348
2356
  bulletList: "\u7B87\u6761\u66F8\u304D",
2349
2357
  orderedList: "\u756A\u53F7\u4ED8\u304D\u30EA\u30B9\u30C8",
2350
2358
  taskList: "\u30BF\u30B9\u30AF\u30EA\u30B9\u30C8",
@@ -28127,11 +28135,11 @@ function useLocale2() {
28127
28135
  }
28128
28136
 
28129
28137
  // src/components/UEditor/UEditor.tsx
28130
- var import_react84 = __toESM(require("react"), 1);
28131
- var import_react85 = require("@tiptap/react");
28138
+ var import_react85 = __toESM(require("react"), 1);
28139
+ var import_react86 = require("@tiptap/react");
28132
28140
 
28133
28141
  // src/components/UEditor/extensions.ts
28134
- var import_core16 = require("@tiptap/core");
28142
+ var import_core17 = require("@tiptap/core");
28135
28143
  var import_extension_document = __toESM(require("@tiptap/extension-document"), 1);
28136
28144
  var import_extension_paragraph = __toESM(require("@tiptap/extension-paragraph"), 1);
28137
28145
  var import_extension_text = __toESM(require("@tiptap/extension-text"), 1);
@@ -28147,7 +28155,7 @@ var import_extension_task_list = __toESM(require("@tiptap/extension-task-list"),
28147
28155
  var import_extension_task_item = __toESM(require("@tiptap/extension-task-item"), 1);
28148
28156
  var import_extension_blockquote = __toESM(require("@tiptap/extension-blockquote"), 1);
28149
28157
  var import_extension_code = __toESM(require("@tiptap/extension-code"), 1);
28150
- var import_core17 = require("@tiptap/core");
28158
+ var import_core18 = require("@tiptap/core");
28151
28159
  var import_react68 = require("@tiptap/react");
28152
28160
 
28153
28161
  // src/components/UEditor/callout.ts
@@ -31660,15 +31668,208 @@ var LetterSpacing = import_core15.Extension.create({
31660
31668
  });
31661
31669
  var letter_spacing_default = LetterSpacing;
31662
31670
 
31671
+ // src/components/UEditor/indent.ts
31672
+ var import_core16 = require("@tiptap/core");
31673
+ var import_tables = require("@tiptap/pm/tables");
31674
+ var DEFAULT_MAX_LEVEL = 6;
31675
+ var DEFAULT_MIN_LEVEL = 0;
31676
+ var DEFAULT_STEP_REM = 2;
31677
+ var INLINE_TAB_SPACES = "\xA0".repeat(4);
31678
+ var LIST_ITEM_TYPES = /* @__PURE__ */ new Set(["listItem", "taskItem"]);
31679
+ var TABLE_CELL_TYPES = /* @__PURE__ */ new Set(["tableCell", "tableHeader"]);
31680
+ function clampIndentLevel(value, minLevel, maxLevel) {
31681
+ const numericValue = typeof value === "number" ? value : Number.parseInt(String(value ?? ""), 10);
31682
+ if (!Number.isFinite(numericValue)) return minLevel;
31683
+ return Math.min(maxLevel, Math.max(minLevel, Math.round(numericValue)));
31684
+ }
31685
+ function parseIndentLevel(element, options) {
31686
+ const dataIndent = element.getAttribute("data-indent");
31687
+ if (dataIndent !== null) {
31688
+ return clampIndentLevel(dataIndent, options.minLevel, options.maxLevel);
31689
+ }
31690
+ const marginLeft = element.style.marginLeft.trim();
31691
+ const match = marginLeft.match(/^(-?\d+(?:\.\d+)?)(rem|em|px)$/i);
31692
+ if (!match) return options.minLevel;
31693
+ const value = Number.parseFloat(match[1] ?? "0");
31694
+ const unit = match[2]?.toLowerCase();
31695
+ const remValue = unit === "px" ? value / 16 : value;
31696
+ return clampIndentLevel(remValue / options.stepRem, options.minLevel, options.maxLevel);
31697
+ }
31698
+ function getNodePos($pos, depth) {
31699
+ return depth > 0 ? $pos.before(depth) : 0;
31700
+ }
31701
+ function getIndentTargetAt($pos, indentTypes) {
31702
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
31703
+ const nodeName = $pos.node(depth).type.name;
31704
+ if (LIST_ITEM_TYPES.has(nodeName) || TABLE_CELL_TYPES.has(nodeName)) return null;
31705
+ }
31706
+ if (indentTypes.has("blockquote")) {
31707
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
31708
+ const node = $pos.node(depth);
31709
+ if (node.type.name === "blockquote") {
31710
+ return { node, pos: getNodePos($pos, depth) };
31711
+ }
31712
+ }
31713
+ }
31714
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
31715
+ const node = $pos.node(depth);
31716
+ if (indentTypes.has(node.type.name)) {
31717
+ return { node, pos: getNodePos($pos, depth) };
31718
+ }
31719
+ }
31720
+ return null;
31721
+ }
31722
+ function getIndentTargets(state, types) {
31723
+ if ((0, import_tables.isInTable)(state)) return [];
31724
+ const indentTypes = new Set(types);
31725
+ const targets = /* @__PURE__ */ new Map();
31726
+ const addTarget = (target) => {
31727
+ if (target) targets.set(target.pos, target);
31728
+ };
31729
+ addTarget(getIndentTargetAt(state.selection.$from, indentTypes));
31730
+ addTarget(getIndentTargetAt(state.selection.$to, indentTypes));
31731
+ if (!state.selection.empty) {
31732
+ state.doc.nodesBetween(state.selection.from, state.selection.to, (node, pos) => {
31733
+ if (!indentTypes.has(node.type.name)) return true;
31734
+ const resolvedPos = state.doc.resolve(Math.min(pos + 1, state.doc.content.size));
31735
+ addTarget(getIndentTargetAt(resolvedPos, indentTypes));
31736
+ return node.type.name !== "blockquote";
31737
+ });
31738
+ }
31739
+ return Array.from(targets.values()).sort((a, b) => a.pos - b.pos);
31740
+ }
31741
+ function updateBlockIndent({
31742
+ state,
31743
+ dispatch,
31744
+ options,
31745
+ delta
31746
+ }) {
31747
+ const targets = getIndentTargets(state, options.types);
31748
+ let transaction = state.tr;
31749
+ let changed = false;
31750
+ for (const target of targets) {
31751
+ const currentLevel = clampIndentLevel(target.node.attrs.indent, options.minLevel, options.maxLevel);
31752
+ const nextLevel = clampIndentLevel(currentLevel + delta, options.minLevel, options.maxLevel);
31753
+ if (nextLevel === currentLevel) continue;
31754
+ transaction = transaction.setNodeMarkup(target.pos, void 0, {
31755
+ ...target.node.attrs,
31756
+ indent: nextLevel
31757
+ });
31758
+ changed = true;
31759
+ }
31760
+ if (changed && dispatch) dispatch(transaction.scrollIntoView());
31761
+ return changed;
31762
+ }
31763
+ function insertTabAtCursor(state, dispatch) {
31764
+ if (!state.selection.empty) return false;
31765
+ if (dispatch) {
31766
+ dispatch(state.tr.insertText(INLINE_TAB_SPACES, state.selection.from).scrollIntoView());
31767
+ }
31768
+ return true;
31769
+ }
31770
+ function removeTabBeforeCursor(state, dispatch) {
31771
+ if (!state.selection.empty || state.selection.$from.parentOffset <= 0) return false;
31772
+ const cursorPos = state.selection.from;
31773
+ const tabStartPos = cursorPos - INLINE_TAB_SPACES.length;
31774
+ if (tabStartPos < 0 || state.doc.textBetween(tabStartPos, cursorPos) !== INLINE_TAB_SPACES) return false;
31775
+ if (dispatch) {
31776
+ dispatch(state.tr.delete(tabStartPos, cursorPos).scrollIntoView());
31777
+ }
31778
+ return true;
31779
+ }
31780
+ var Indent = import_core16.Extension.create({
31781
+ name: "indent",
31782
+ addOptions() {
31783
+ return {
31784
+ maxLevel: DEFAULT_MAX_LEVEL,
31785
+ minLevel: DEFAULT_MIN_LEVEL,
31786
+ stepRem: DEFAULT_STEP_REM,
31787
+ types: ["paragraph", "blockquote"]
31788
+ };
31789
+ },
31790
+ addGlobalAttributes() {
31791
+ return [
31792
+ {
31793
+ types: this.options.types,
31794
+ attributes: {
31795
+ indent: {
31796
+ default: this.options.minLevel,
31797
+ parseHTML: (element) => parseIndentLevel(element, this.options),
31798
+ renderHTML: (attributes) => {
31799
+ const level = clampIndentLevel(attributes.indent, this.options.minLevel, this.options.maxLevel);
31800
+ if (level <= this.options.minLevel) return {};
31801
+ return {
31802
+ "data-indent": String(level),
31803
+ style: `margin-left: ${level * this.options.stepRem}rem`
31804
+ };
31805
+ }
31806
+ }
31807
+ }
31808
+ }
31809
+ ];
31810
+ },
31811
+ addCommands() {
31812
+ return {
31813
+ increaseIndent: () => ({ editor, commands, state, dispatch }) => {
31814
+ if (editor.isActive("taskItem")) return commands.sinkListItem("taskItem");
31815
+ if (editor.isActive("listItem")) return commands.sinkListItem("listItem");
31816
+ return updateBlockIndent({
31817
+ state,
31818
+ dispatch,
31819
+ options: this.options,
31820
+ delta: 1
31821
+ });
31822
+ },
31823
+ decreaseIndent: () => ({ editor, commands, state, dispatch }) => {
31824
+ if (editor.isActive("taskItem")) return commands.liftListItem("taskItem");
31825
+ if (editor.isActive("listItem")) return commands.liftListItem("listItem");
31826
+ return updateBlockIndent({
31827
+ state,
31828
+ dispatch,
31829
+ options: this.options,
31830
+ delta: -1
31831
+ });
31832
+ }
31833
+ };
31834
+ },
31835
+ addKeyboardShortcuts() {
31836
+ const handleBlockIndent = (delta) => {
31837
+ const { state } = this.editor;
31838
+ const hasBlockTarget = getIndentTargets(state, this.options.types).length > 0;
31839
+ if (!hasBlockTarget) {
31840
+ return delta > 0 ? this.editor.commands.increaseIndent() : this.editor.commands.decreaseIndent();
31841
+ }
31842
+ if (state.selection.empty && state.selection.$from.parentOffset > 0) {
31843
+ if (delta > 0) {
31844
+ return insertTabAtCursor(state, (transaction) => this.editor.view.dispatch(transaction));
31845
+ }
31846
+ removeTabBeforeCursor(state, (transaction) => this.editor.view.dispatch(transaction));
31847
+ return true;
31848
+ }
31849
+ if (delta > 0) {
31850
+ this.editor.commands.increaseIndent();
31851
+ } else {
31852
+ this.editor.commands.decreaseIndent();
31853
+ }
31854
+ return true;
31855
+ };
31856
+ return {
31857
+ Tab: () => handleBlockIndent(1),
31858
+ "Shift-Tab": () => handleBlockIndent(-1)
31859
+ };
31860
+ }
31861
+ });
31862
+ var indent_default = Indent;
31863
+
31663
31864
  // src/components/UEditor/table-align.ts
31664
31865
  var import_extension_table = require("@tiptap/extension-table");
31665
31866
  var import_state7 = require("@tiptap/pm/state");
31666
- var import_tables2 = require("@tiptap/pm/tables");
31867
+ var import_tables3 = require("@tiptap/pm/tables");
31667
31868
 
31668
31869
  // src/components/UEditor/table-column-resize.ts
31669
31870
  var import_state6 = require("@tiptap/pm/state");
31670
31871
  var import_view2 = require("@tiptap/pm/view");
31671
- var import_tables = require("@tiptap/pm/tables");
31872
+ var import_tables2 = require("@tiptap/pm/tables");
31672
31873
  var DEFAULT_TABLE_COLUMN_WIDTH = 100;
31673
31874
  var MIN_RESIZED_TABLE_COLUMN_WIDTH = 25;
31674
31875
  function getDynamicColumnMinWidth(startWidth, fallbackMinWidth) {
@@ -31788,20 +31989,20 @@ function edgeCell(view, event, side, handleWidth) {
31788
31989
  top: event.clientY
31789
31990
  });
31790
31991
  if (!found2) return -1;
31791
- const $cell = (0, import_tables.cellAround)(view.state.doc.resolve(found2.pos));
31992
+ const $cell = (0, import_tables2.cellAround)(view.state.doc.resolve(found2.pos));
31792
31993
  if (!$cell) return -1;
31793
31994
  if (side === "right") return $cell.pos;
31794
- const map = import_tables.TableMap.get($cell.node(-1));
31995
+ const map = import_tables2.TableMap.get($cell.node(-1));
31795
31996
  const start = $cell.start(-1);
31796
31997
  const index = map.map.indexOf($cell.pos - start);
31797
31998
  return index % map.width === 0 ? -1 : start + map.map[index - 1];
31798
31999
  }
31799
32000
  function updateHandle(view, value) {
31800
- view.dispatch(view.state.tr.setMeta(import_tables.columnResizingPluginKey, { setHandle: value }));
32001
+ view.dispatch(view.state.tr.setMeta(import_tables2.columnResizingPluginKey, { setHandle: value }));
31801
32002
  }
31802
32003
  function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
31803
32004
  if (!view.editable) return;
31804
- const pluginState = import_tables.columnResizingPluginKey.getState(view.state);
32005
+ const pluginState = import_tables2.columnResizingPluginKey.getState(view.state);
31805
32006
  if (!pluginState || pluginState.dragging) return;
31806
32007
  const target = domCellAround(event.target);
31807
32008
  let cell = -1;
@@ -31814,7 +32015,7 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
31814
32015
  if (!lastColumnResizable && cell !== -1) {
31815
32016
  const $cell = view.state.doc.resolve(cell);
31816
32017
  const table = $cell.node(-1);
31817
- const map = import_tables.TableMap.get(table);
32018
+ const map = import_tables2.TableMap.get(table);
31818
32019
  const tableStart = $cell.start(-1);
31819
32020
  const nodeAfter = $cell.nodeAfter;
31820
32021
  if (!nodeAfter) return;
@@ -31824,7 +32025,7 @@ function handleMouseMove(view, event, handleWidth, lastColumnResizable) {
31824
32025
  }
31825
32026
  function handleMouseLeave(view) {
31826
32027
  if (!view.editable) return;
31827
- const pluginState = import_tables.columnResizingPluginKey.getState(view.state);
32028
+ const pluginState = import_tables2.columnResizingPluginKey.getState(view.state);
31828
32029
  if (pluginState && pluginState.activeHandle > -1 && !pluginState.dragging) {
31829
32030
  updateHandle(view, -1);
31830
32031
  }
@@ -31832,7 +32033,7 @@ function handleMouseLeave(view) {
31832
32033
  function updateColumnWidth(view, cell, width) {
31833
32034
  const $cell = view.state.doc.resolve(cell);
31834
32035
  const table = $cell.node(-1);
31835
- const map = import_tables.TableMap.get(table);
32036
+ const map = import_tables2.TableMap.get(table);
31836
32037
  const start = $cell.start(-1);
31837
32038
  const nodeAfter = $cell.nodeAfter;
31838
32039
  if (!nodeAfter) return;
@@ -31857,7 +32058,7 @@ function updateColumnWidth(view, cell, width) {
31857
32058
  if (tr.docChanged) view.dispatch(tr);
31858
32059
  }
31859
32060
  function getActiveDragging(state) {
31860
- const dragging = import_tables.columnResizingPluginKey.getState(state)?.dragging;
32061
+ const dragging = import_tables2.columnResizingPluginKey.getState(state)?.dragging;
31861
32062
  return dragging ? dragging : null;
31862
32063
  }
31863
32064
  function getColumnResizeGhost(view) {
@@ -31902,7 +32103,7 @@ function showColumnResizeGhost(view, cell, dragging, width) {
31902
32103
  function handleMouseDown(view, event, cellMinWidth) {
31903
32104
  if (!view.editable) return false;
31904
32105
  const win = view.dom.ownerDocument.defaultView ?? window;
31905
- const pluginState = import_tables.columnResizingPluginKey.getState(view.state);
32106
+ const pluginState = import_tables2.columnResizingPluginKey.getState(view.state);
31906
32107
  if (!pluginState || pluginState.activeHandle === -1 || pluginState.dragging) return false;
31907
32108
  const cell = view.state.doc.nodeAt(pluginState.activeHandle);
31908
32109
  if (!cell) return false;
@@ -31917,22 +32118,22 @@ function handleMouseDown(view, event, cellMinWidth) {
31917
32118
  startWidth: width,
31918
32119
  minWidth
31919
32120
  };
31920
- view.dispatch(view.state.tr.setMeta(import_tables.columnResizingPluginKey, { setDragging: dragging }));
32121
+ view.dispatch(view.state.tr.setMeta(import_tables2.columnResizingPluginKey, { setDragging: dragging }));
31921
32122
  function finish(nextEvent) {
31922
32123
  win.removeEventListener("mouseup", finish);
31923
32124
  win.removeEventListener("mousemove", move);
31924
32125
  const activeDragging = getActiveDragging(view.state);
31925
- const activeHandle = import_tables.columnResizingPluginKey.getState(view.state)?.activeHandle ?? -1;
32126
+ const activeHandle = import_tables2.columnResizingPluginKey.getState(view.state)?.activeHandle ?? -1;
31926
32127
  if (activeDragging && activeHandle > -1) {
31927
32128
  updateColumnWidth(view, activeHandle, getDraggedWidth(activeDragging, nextEvent));
31928
- view.dispatch(view.state.tr.setMeta(import_tables.columnResizingPluginKey, { setDragging: null }));
32129
+ view.dispatch(view.state.tr.setMeta(import_tables2.columnResizingPluginKey, { setDragging: null }));
31929
32130
  }
31930
32131
  hideColumnResizeGhost(view);
31931
32132
  }
31932
32133
  function move(nextEvent) {
31933
32134
  if (!nextEvent.buttons) return finish(nextEvent);
31934
32135
  const activeDragging = getActiveDragging(view.state);
31935
- const activeHandle = import_tables.columnResizingPluginKey.getState(view.state)?.activeHandle ?? -1;
32136
+ const activeHandle = import_tables2.columnResizingPluginKey.getState(view.state)?.activeHandle ?? -1;
31936
32137
  if (activeDragging && activeHandle > -1) {
31937
32138
  showColumnResizeGhost(view, activeHandle, activeDragging, getDraggedWidth(activeDragging, nextEvent));
31938
32139
  }
@@ -31948,7 +32149,7 @@ function handleDecorations(state, cell) {
31948
32149
  const $cell = state.doc.resolve(cell);
31949
32150
  const table = $cell.node(-1);
31950
32151
  if (!table) return import_view2.DecorationSet.empty;
31951
- const map = import_tables.TableMap.get(table);
32152
+ const map = import_tables2.TableMap.get(table);
31952
32153
  const start = $cell.start(-1);
31953
32154
  const nodeAfter = $cell.nodeAfter;
31954
32155
  if (!nodeAfter) return import_view2.DecorationSet.empty;
@@ -31962,7 +32163,7 @@ function handleDecorations(state, cell) {
31962
32163
  const pos = start + cellPos + cellNode.nodeSize - 1;
31963
32164
  const dom = document.createElement("div");
31964
32165
  dom.className = "column-resize-handle";
31965
- if (import_tables.columnResizingPluginKey.getState(state)?.dragging) {
32166
+ if (import_tables2.columnResizingPluginKey.getState(state)?.dragging) {
31966
32167
  decorations.push(import_view2.Decoration.node(start + cellPos, start + cellPos + cellNode.nodeSize, { class: "column-resize-dragging" }));
31967
32168
  }
31968
32169
  decorations.push(import_view2.Decoration.widget(pos, dom));
@@ -31978,15 +32179,15 @@ function dynamicColumnResizing({
31978
32179
  lastColumnResizable = true
31979
32180
  } = {}) {
31980
32181
  const plugin = new import_state6.Plugin({
31981
- key: import_tables.columnResizingPluginKey,
32182
+ key: import_tables2.columnResizingPluginKey,
31982
32183
  state: {
31983
32184
  init(_, state) {
31984
32185
  const nodeViews = plugin.spec.props?.nodeViews;
31985
- const tableName = (0, import_tables.tableNodeTypes)(state.schema).table.name;
32186
+ const tableName = (0, import_tables2.tableNodeTypes)(state.schema).table.name;
31986
32187
  if (View && nodeViews) {
31987
32188
  nodeViews[tableName] = (node, view) => new View(node, defaultCellMinWidth, view);
31988
32189
  }
31989
- return new import_tables.ResizeState(-1, false);
32190
+ return new import_tables2.ResizeState(-1, false);
31990
32191
  },
31991
32192
  apply(tr, prev) {
31992
32193
  return prev.apply(tr);
@@ -31994,7 +32195,7 @@ function dynamicColumnResizing({
31994
32195
  },
31995
32196
  props: {
31996
32197
  attributes: (state) => {
31997
- const pluginState = import_tables.columnResizingPluginKey.getState(state);
32198
+ const pluginState = import_tables2.columnResizingPluginKey.getState(state);
31998
32199
  return pluginState && pluginState.activeHandle > -1 ? { class: "resize-cursor" } : {};
31999
32200
  },
32000
32201
  handleDOMEvents: {
@@ -32007,7 +32208,7 @@ function dynamicColumnResizing({
32007
32208
  mousedown: (view, event) => handleMouseDown(view, event, cellMinWidth)
32008
32209
  },
32009
32210
  decorations: (state) => {
32010
- const pluginState = import_tables.columnResizingPluginKey.getState(state);
32211
+ const pluginState = import_tables2.columnResizingPluginKey.getState(state);
32011
32212
  if (pluginState && pluginState.activeHandle > -1) {
32012
32213
  return handleDecorations(state, pluginState.activeHandle);
32013
32214
  }
@@ -32164,7 +32365,7 @@ var UEditorTable = import_extension_table.Table.extend({
32164
32365
  lastColumnResizable: this.options.lastColumnResizable
32165
32366
  })
32166
32367
  ] : [],
32167
- (0, import_tables2.tableEditing)({
32368
+ (0, import_tables3.tableEditing)({
32168
32369
  allowTableNodeSelection: this.options.allowTableNodeSelection
32169
32370
  }),
32170
32371
  new import_state7.Plugin({
@@ -32433,7 +32634,7 @@ var CustomTableCell = import_extension_table_cell.default.extend({
32433
32634
  mergedStyle = mergedStyle.replace(/^;/, "").trim();
32434
32635
  return [
32435
32636
  "td",
32436
- (0, import_core16.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, getFormulaStateAttributes(HTMLAttributes), mergedStyle ? { style: mergedStyle } : {}),
32637
+ (0, import_core17.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, getFormulaStateAttributes(HTMLAttributes), mergedStyle ? { style: mergedStyle } : {}),
32437
32638
  0
32438
32639
  ];
32439
32640
  }
@@ -32559,7 +32760,7 @@ var CustomTableHeader = import_extension_table_header.default.extend({
32559
32760
  mergedStyle = mergedStyle.replace(/^;/, "").trim();
32560
32761
  return [
32561
32762
  "th",
32562
- (0, import_core16.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, getFormulaStateAttributes(HTMLAttributes), mergedStyle ? { style: mergedStyle } : {}),
32763
+ (0, import_core17.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, getFormulaStateAttributes(HTMLAttributes), mergedStyle ? { style: mergedStyle } : {}),
32563
32764
  0
32564
32765
  ];
32565
32766
  }
@@ -32567,15 +32768,15 @@ var CustomTableHeader = import_extension_table_header.default.extend({
32567
32768
  var CustomTaskList = import_extension_task_list.default.extend({
32568
32769
  addInputRules() {
32569
32770
  return [
32570
- (0, import_core17.wrappingInputRule)({
32771
+ (0, import_core18.wrappingInputRule)({
32571
32772
  find: /^\s*(\[ \]|\[\])\s$/,
32572
32773
  type: this.type
32573
32774
  }),
32574
- (0, import_core17.wrappingInputRule)({
32775
+ (0, import_core18.wrappingInputRule)({
32575
32776
  find: /^\s*(-\s*\[ \]|-\s*\[\])\s$/,
32576
32777
  type: this.type
32577
32778
  }),
32578
- (0, import_core17.wrappingInputRule)({
32779
+ (0, import_core18.wrappingInputRule)({
32579
32780
  find: /^\s*(\*\s*\[ \]|-\s*\[\])\s$/,
32580
32781
  type: this.type
32581
32782
  })
@@ -32671,6 +32872,7 @@ function buildUEditorExtensions({
32671
32872
  font_size_default,
32672
32873
  line_height_default,
32673
32874
  letter_spacing_default,
32875
+ indent_default,
32674
32876
  import_extension_color.default,
32675
32877
  import_extension_highlight.default.configure({
32676
32878
  multicolor: true
@@ -32738,7 +32940,7 @@ function buildUEditorExtensions({
32738
32940
  var import_react72 = __toESM(require("react"), 1);
32739
32941
  var import_react73 = require("@tiptap/react");
32740
32942
  var import_lucide_react52 = require("lucide-react");
32741
- var import_tables4 = require("@tiptap/pm/tables");
32943
+ var import_tables5 = require("@tiptap/pm/tables");
32742
32944
 
32743
32945
  // src/components/UEditor/colors.tsx
32744
32946
  var import_react70 = require("react");
@@ -33395,7 +33597,7 @@ function applyEditorLink(editor, href) {
33395
33597
 
33396
33598
  // src/components/UEditor/table-cell-commands.ts
33397
33599
  var import_state10 = require("@tiptap/pm/state");
33398
- var import_tables3 = require("@tiptap/pm/tables");
33600
+ var import_tables4 = require("@tiptap/pm/tables");
33399
33601
  function getCellSelectionPositions(selection) {
33400
33602
  const value = selection;
33401
33603
  const anchor = value.$anchorCell?.pos;
@@ -33487,7 +33689,7 @@ function getSelectedTableRect(editor) {
33487
33689
  if (cellSelection) {
33488
33690
  const tableInfo = findTableInfoFromCellPos(editor, cellSelection.anchor);
33489
33691
  if (tableInfo) {
33490
- const map = import_tables3.TableMap.get(tableInfo.table);
33692
+ const map = import_tables4.TableMap.get(tableInfo.table);
33491
33693
  const rect = map.rectBetween(
33492
33694
  cellSelection.anchor - tableInfo.tableStart,
33493
33695
  cellSelection.head - tableInfo.tableStart
@@ -33500,7 +33702,7 @@ function getSelectedTableRect(editor) {
33500
33702
  };
33501
33703
  }
33502
33704
  }
33503
- return (0, import_tables3.selectedRect)(editor.state);
33705
+ return (0, import_tables4.selectedRect)(editor.state);
33504
33706
  }
33505
33707
  function parsePixelWidth(value) {
33506
33708
  if (!value) return null;
@@ -33583,7 +33785,7 @@ function runTableCommandAtCellPos(editor, cellPos, command) {
33583
33785
  function getTableCornerCellPos(editor, activePos) {
33584
33786
  const tableInfo = findTableInfoFromCellPos(editor, activePos);
33585
33787
  if (!tableInfo) return null;
33586
- const map = import_tables3.TableMap.get(tableInfo.table);
33788
+ const map = import_tables4.TableMap.get(tableInfo.table);
33587
33789
  return tableInfo.tableStart + map.positionAt(map.height - 1, map.width - 1, tableInfo.table);
33588
33790
  }
33589
33791
  function replaceTableAtCellPos(editor, cellPos, updateTable) {
@@ -33607,7 +33809,7 @@ function duplicateTableRowAt(editor, rowIndex, cellPos) {
33607
33809
  }
33608
33810
  function clearTableRowAt(editor, rowIndex, cellPos) {
33609
33811
  return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
33610
- const map = import_tables3.TableMap.get(tableNode);
33812
+ const map = import_tables4.TableMap.get(tableNode);
33611
33813
  if (rowIndex < 0 || rowIndex >= map.height) return null;
33612
33814
  const rows = getTableRows(tableNode).map((rowInfo) => {
33613
33815
  const cells = collectChildren(rowInfo.node);
@@ -33623,7 +33825,7 @@ function clearTableRowAt(editor, rowIndex, cellPos) {
33623
33825
  }
33624
33826
  function duplicateTableColumnAt(editor, columnIndex, cellPos) {
33625
33827
  return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
33626
- const map = import_tables3.TableMap.get(tableNode);
33828
+ const map = import_tables4.TableMap.get(tableNode);
33627
33829
  if (columnIndex < 0 || columnIndex >= map.width) return null;
33628
33830
  const rows = getTableRows(tableNode).map((rowInfo, rowIndex) => {
33629
33831
  const cells = collectChildren(rowInfo.node);
@@ -33645,7 +33847,7 @@ function duplicateTableColumnAt(editor, columnIndex, cellPos) {
33645
33847
  }
33646
33848
  function clearTableColumnAt(editor, columnIndex, cellPos) {
33647
33849
  return replaceTableAtCellPos(editor, cellPos, (tableNode) => {
33648
- const map = import_tables3.TableMap.get(tableNode);
33850
+ const map = import_tables4.TableMap.get(tableNode);
33649
33851
  if (columnIndex < 0 || columnIndex >= map.width) return null;
33650
33852
  const rows = getTableRows(tableNode).map((rowInfo) => {
33651
33853
  const cells = collectChildren(rowInfo.node);
@@ -33775,6 +33977,77 @@ function getTableAnchorPos(editor) {
33775
33977
  const firstCell = tables[0]?.querySelector("th,td");
33776
33978
  return firstCell instanceof HTMLTableCellElement ? editor.view.posAtDOM(firstCell, 0) + 1 : null;
33777
33979
  }
33980
+ var EDITOR_UI_ACTIVE_MARKS = [
33981
+ "blockquote",
33982
+ "bold",
33983
+ "bulletList",
33984
+ "code",
33985
+ "codeBlock",
33986
+ "formCheckbox",
33987
+ "highlight",
33988
+ "image",
33989
+ "italic",
33990
+ "link",
33991
+ "orderedList",
33992
+ "paragraph",
33993
+ "strike",
33994
+ "subscript",
33995
+ "superscript",
33996
+ "taskList",
33997
+ "underline"
33998
+ ];
33999
+ function getEditorUiRenderState(editor) {
34000
+ const textStyle = editor.getAttributes("textStyle");
34001
+ const highlight = editor.getAttributes("highlight");
34002
+ const image = editor.getAttributes("image");
34003
+ const link = editor.getAttributes("link");
34004
+ const tableCell = editor.getAttributes("tableCell");
34005
+ const tableHeader = editor.getAttributes("tableHeader");
34006
+ const hasTableContext = getTableAnchorPos(editor) !== null;
34007
+ const can = editor.can();
34008
+ return {
34009
+ active: EDITOR_UI_ACTIVE_MARKS.map((name) => editor.isActive(name)),
34010
+ alignment: ["left", "center", "right", "justify"].map((textAlign) => editor.isActive({ textAlign })),
34011
+ heading: [1, 2, 3].map((level) => editor.isActive("heading", { level })),
34012
+ textStyle: {
34013
+ color: textStyle.color ?? null,
34014
+ fontFamily: textStyle.fontFamily ?? null,
34015
+ fontSize: textStyle.fontSize ?? null,
34016
+ letterSpacing: textStyle.letterSpacing ?? null,
34017
+ lineHeight: textStyle.lineHeight ?? null
34018
+ },
34019
+ highlightColor: highlight.color ?? null,
34020
+ image: {
34021
+ imageLayout: image.imageLayout ?? null,
34022
+ imageWidthPreset: image.imageWidthPreset ?? null
34023
+ },
34024
+ linkHref: link.href ?? null,
34025
+ tableCell: {
34026
+ backgroundColor: tableCell.backgroundColor ?? tableHeader.backgroundColor ?? null,
34027
+ borderColor: tableCell.borderColor ?? tableHeader.borderColor ?? null,
34028
+ borderStyle: tableCell.borderStyle ?? tableHeader.borderStyle ?? null,
34029
+ borderWidth: tableCell.borderWidth ?? tableHeader.borderWidth ?? null,
34030
+ formula: tableCell.formula ?? tableHeader.formula ?? null,
34031
+ numberFormat: tableCell.numberFormat ?? tableHeader.numberFormat ?? null,
34032
+ textDirection: tableCell.textDirection ?? tableHeader.textDirection ?? null,
34033
+ verticalAlign: tableCell.verticalAlign ?? tableHeader.verticalAlign ?? null
34034
+ },
34035
+ can: {
34036
+ addColumnAfter: hasTableContext && can.addColumnAfter(),
34037
+ addColumnBefore: hasTableContext && can.addColumnBefore(),
34038
+ addRowAfter: hasTableContext && can.addRowAfter(),
34039
+ addRowBefore: hasTableContext && can.addRowBefore(),
34040
+ decreaseIndent: can.decreaseIndent(),
34041
+ increaseIndent: can.increaseIndent(),
34042
+ mergeCells: hasTableContext && can.mergeCells(),
34043
+ redo: can.redo(),
34044
+ splitCell: hasTableContext && can.splitCell(),
34045
+ undo: can.undo()
34046
+ },
34047
+ hasTableContext,
34048
+ isEmpty: editor.isEmpty
34049
+ };
34050
+ }
33778
34051
  function fileToDataUrl2(file) {
33779
34052
  return new Promise((resolve, reject) => {
33780
34053
  const reader = new FileReader();
@@ -33828,7 +34101,7 @@ var TableInsertGrid = ({
33828
34101
  const maxCols = 8;
33829
34102
  return /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)("div", { className: "mb-2 rounded-xl border border-border/60 bg-muted/20 p-2", children: [
33830
34103
  /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("div", { className: "mb-2 text-sm font-medium text-foreground", children: formatTableInsertLabel(previewTemplate, selection.rows, selection.cols) }),
33831
- /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("div", { className: "grid grid-cols-8 gap-1", onMouseLeave: () => setSelection((prev) => prev), children: Array.from({ length: maxRows }).map(
34104
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)("div", { className: "grid grid-cols-8 gap-1", children: Array.from({ length: maxRows }).map(
33832
34105
  (_, rowIndex) => Array.from({ length: maxCols }).map((__, colIndex) => {
33833
34106
  const rows = rowIndex + 1;
33834
34107
  const cols = colIndex + 1;
@@ -33856,7 +34129,7 @@ var TableInsertGrid = ({
33856
34129
  };
33857
34130
  function applyTableCellAttribute(editor, name, value) {
33858
34131
  const { state, view } = editor;
33859
- const applied = (0, import_tables4.setCellAttr)(name, value)(state, view.dispatch.bind(view));
34132
+ const applied = (0, import_tables5.setCellAttr)(name, value)(state, view.dispatch.bind(view));
33860
34133
  if (applied) {
33861
34134
  view.focus();
33862
34135
  return;
@@ -33876,9 +34149,9 @@ var EditorToolbar = ({
33876
34149
  letterSpacings
33877
34150
  }) => {
33878
34151
  const t = useSmartTranslations("UEditor");
33879
- (0, import_react73.useEditorState)({
34152
+ const editorUiState = (0, import_react73.useEditorState)({
33880
34153
  editor,
33881
- selector: ({ transactionNumber }) => transactionNumber
34154
+ selector: ({ editor: currentEditor }) => getEditorUiRenderState(currentEditor)
33882
34155
  });
33883
34156
  const { textColors, highlightColors } = useEditorColors();
33884
34157
  const [showImageInput, setShowImageInput] = (0, import_react72.useState)(false);
@@ -33960,6 +34233,24 @@ var EditorToolbar = ({
33960
34233
  children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(FigmaListIcon, { className: "h-4 w-4" })
33961
34234
  }
33962
34235
  ),
34236
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
34237
+ ToolbarButton,
34238
+ {
34239
+ onClick: () => editor.chain().focus().decreaseIndent().run(),
34240
+ disabled: !editorUiState.can.decreaseIndent,
34241
+ title: t("toolbar.decreaseIndent"),
34242
+ children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.IndentDecrease, { className: "h-4 w-4" })
34243
+ }
34244
+ ),
34245
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
34246
+ ToolbarButton,
34247
+ {
34248
+ onClick: () => editor.chain().focus().increaseIndent().run(),
34249
+ disabled: !editorUiState.can.increaseIndent,
34250
+ title: t("toolbar.increaseIndent"),
34251
+ children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.IndentIncrease, { className: "h-4 w-4" })
34252
+ }
34253
+ ),
33963
34254
  /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(
33964
34255
  DropdownMenu,
33965
34256
  {
@@ -34460,6 +34751,24 @@ var EditorToolbar = ({
34460
34751
  ]
34461
34752
  }
34462
34753
  ),
34754
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
34755
+ ToolbarButton,
34756
+ {
34757
+ onClick: () => editor.chain().focus().decreaseIndent().run(),
34758
+ disabled: !editorUiState.can.decreaseIndent,
34759
+ title: t("toolbar.decreaseIndent"),
34760
+ children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.IndentDecrease, { className: "h-4 w-4" })
34761
+ }
34762
+ ),
34763
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
34764
+ ToolbarButton,
34765
+ {
34766
+ onClick: () => editor.chain().focus().increaseIndent().run(),
34767
+ disabled: !editorUiState.can.increaseIndent,
34768
+ title: t("toolbar.increaseIndent"),
34769
+ children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.IndentIncrease, { className: "h-4 w-4" })
34770
+ }
34771
+ ),
34463
34772
  /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(
34464
34773
  DropdownMenu,
34465
34774
  {
@@ -34726,12 +35035,12 @@ var EditorToolbar = ({
34726
35035
  // src/components/UEditor/menus.tsx
34727
35036
  var import_react74 = require("react");
34728
35037
  var import_react75 = require("@tiptap/react");
34729
- var import_tables7 = require("@tiptap/pm/tables");
35038
+ var import_tables8 = require("@tiptap/pm/tables");
34730
35039
  var import_react_dom8 = require("react-dom");
34731
35040
  var import_lucide_react53 = require("lucide-react");
34732
35041
 
34733
35042
  // src/components/UEditor/table-border-commands.ts
34734
- var import_tables5 = require("@tiptap/pm/tables");
35043
+ var import_tables6 = require("@tiptap/pm/tables");
34735
35044
  var SIDES = ["top", "right", "bottom", "left"];
34736
35045
  var OPPOSITE_SIDE = {
34737
35046
  top: "bottom",
@@ -34802,7 +35111,7 @@ function getAppliedSides(position, cell, selection) {
34802
35111
  }
34803
35112
  function applyTableCellBorders(editor, position, format, options = {}) {
34804
35113
  const { state, view } = editor;
34805
- const selection = (0, import_tables5.selectedRect)(state);
35114
+ const selection = (0, import_tables6.selectedRect)(state);
34806
35115
  const transaction = state.tr;
34807
35116
  const cellPositions = new Set(selection.map.cellsInRect(selection));
34808
35117
  const sidesByCell = /* @__PURE__ */ new Map();
@@ -34860,7 +35169,7 @@ function applyTableCellBorders(editor, position, format, options = {}) {
34860
35169
 
34861
35170
  // src/components/UEditor/table-formula-commands.ts
34862
35171
  var import_state11 = require("@tiptap/pm/state");
34863
- var import_tables6 = require("@tiptap/pm/tables");
35172
+ var import_tables7 = require("@tiptap/pm/tables");
34864
35173
 
34865
35174
  // src/components/UEditor/table-formula.ts
34866
35175
  var CELL_ADDRESS_RE = /^([A-Z]+)([1-9]\d*)$/i;
@@ -35451,7 +35760,7 @@ function getSelectionTableCellAnchor(editor) {
35451
35760
  const tableNode = $cell.node(depth);
35452
35761
  if (tableNode.type.name !== "table") continue;
35453
35762
  const tableStart = $cell.start(depth);
35454
- const rect = safeFindCell2(import_tables6.TableMap.get(tableNode), cellPos - tableStart);
35763
+ const rect = safeFindCell2(import_tables7.TableMap.get(tableNode), cellPos - tableStart);
35455
35764
  if (!rect) return null;
35456
35765
  return {
35457
35766
  cellPos,
@@ -35467,7 +35776,7 @@ function getSelectionTableCellAnchor(editor) {
35467
35776
  function restoreSelectionAtTableCell(editor, anchor) {
35468
35777
  const tableNode = editor.state.doc.nodeAt(anchor.tablePos);
35469
35778
  if (!tableNode || tableNode.type.name !== "table") return false;
35470
- const map = import_tables6.TableMap.get(tableNode);
35779
+ const map = import_tables7.TableMap.get(tableNode);
35471
35780
  if (anchor.row >= map.height || anchor.column >= map.width) return false;
35472
35781
  const relativeCellPos = map.positionAt(anchor.row, anchor.column, tableNode);
35473
35782
  const cellPos = anchor.tablePos + 1 + relativeCellPos;
@@ -35523,7 +35832,7 @@ function getSelectionTableCellLabel(editor) {
35523
35832
  const tableNode = $from.node(tableDepth);
35524
35833
  const tableStart = $from.start(tableDepth);
35525
35834
  const relativeCellPos = $from.before(cellDepth) - tableStart;
35526
- const rect = safeFindCell2(import_tables6.TableMap.get(tableNode), relativeCellPos);
35835
+ const rect = safeFindCell2(import_tables7.TableMap.get(tableNode), relativeCellPos);
35527
35836
  if (!rect) return null;
35528
35837
  return `${indexToColumnName(rect.left)}${rect.top + 1}`;
35529
35838
  }
@@ -35561,7 +35870,7 @@ function removeSelectedTableCellFormula(editor, clearContent) {
35561
35870
  return true;
35562
35871
  }
35563
35872
  function buildTableValueMap(tableNode) {
35564
- const map = import_tables6.TableMap.get(tableNode);
35873
+ const map = import_tables7.TableMap.get(tableNode);
35565
35874
  const values = /* @__PURE__ */ new Map();
35566
35875
  for (const rowInfo of getTableRows2(tableNode)) {
35567
35876
  for (const entry of rowInfo.cells) {
@@ -35586,8 +35895,8 @@ function setSelectedTableCellFormula(editor, formula) {
35586
35895
  if (!normalized) {
35587
35896
  return clearSelectedTableCellFormula(editor);
35588
35897
  }
35589
- const appliedFormula = (0, import_tables6.setCellAttr)("formula", normalized)(state, view.dispatch.bind(view));
35590
- const clearedValue = (0, import_tables6.setCellAttr)("computedValue", null)(editor.state, view.dispatch.bind(view));
35898
+ const appliedFormula = (0, import_tables7.setCellAttr)("formula", normalized)(state, view.dispatch.bind(view));
35899
+ const clearedValue = (0, import_tables7.setCellAttr)("computedValue", null)(editor.state, view.dispatch.bind(view));
35591
35900
  if (appliedFormula || clearedValue) {
35592
35901
  recalculateActiveTableFormulas(editor);
35593
35902
  if (selectionAnchor) restoreSelectionAtTableCell(editor, selectionAnchor);
@@ -35606,7 +35915,7 @@ function convertSelectedTableCellFormulaToValue(editor) {
35606
35915
  function setSelectedTableCellNumberFormat(editor, numberFormat) {
35607
35916
  const value = numberFormat && numberFormat !== "text" ? numberFormat : null;
35608
35917
  const { state, view } = editor;
35609
- const applied = (0, import_tables6.setCellAttr)("numberFormat", value)(state, view.dispatch.bind(view));
35918
+ const applied = (0, import_tables7.setCellAttr)("numberFormat", value)(state, view.dispatch.bind(view));
35610
35919
  if (!applied) return false;
35611
35920
  recalculateSelectedTable(editor);
35612
35921
  view.focus();
@@ -35678,7 +35987,7 @@ function promoteFormulaTextInTableNode(tableNode) {
35678
35987
  function recalculateTableNode(tableNode, options) {
35679
35988
  const promoted = promoteFormulaTextInTableNode(tableNode);
35680
35989
  tableNode = promoted.tableNode;
35681
- const map = import_tables6.TableMap.get(tableNode);
35990
+ const map = import_tables7.TableMap.get(tableNode);
35682
35991
  const values = buildTableValueMap(tableNode);
35683
35992
  const formulaEntries = /* @__PURE__ */ new Map();
35684
35993
  let changed = false;
@@ -35749,7 +36058,7 @@ function recalculateTableNode(tableNode, options) {
35749
36058
  return tableNode.type.create(tableNode.attrs, rows);
35750
36059
  }
35751
36060
  function recalculateSelectedTable(editor) {
35752
- const rect = (0, import_tables6.selectedRect)(editor.state);
36061
+ const rect = (0, import_tables7.selectedRect)(editor.state);
35753
36062
  const tableNode = rect.table;
35754
36063
  const nextTable = recalculateTableNode(tableNode);
35755
36064
  if (!nextTable) return false;
@@ -35856,7 +36165,7 @@ var FloatingMenuContent = ({ editor }) => {
35856
36165
  function applyTableCellBackground(editor, color) {
35857
36166
  const value = color || null;
35858
36167
  const { state, view } = editor;
35859
- const applied = (0, import_tables7.setCellAttr)("backgroundColor", value)(state, view.dispatch.bind(view));
36168
+ const applied = (0, import_tables8.setCellAttr)("backgroundColor", value)(state, view.dispatch.bind(view));
35860
36169
  if (applied) {
35861
36170
  view.focus();
35862
36171
  return;
@@ -35866,7 +36175,7 @@ function applyTableCellBackground(editor, color) {
35866
36175
  function applyTableCellAttribute2(editor, name, value, options = {}) {
35867
36176
  const shouldFocus = options.focus ?? true;
35868
36177
  const { state, view } = editor;
35869
- const applied = (0, import_tables7.setCellAttr)(name, value)(state, view.dispatch.bind(view));
36178
+ const applied = (0, import_tables8.setCellAttr)(name, value)(state, view.dispatch.bind(view));
35870
36179
  if (applied) {
35871
36180
  if (shouldFocus) view.focus();
35872
36181
  return;
@@ -35922,7 +36231,7 @@ function BorderPositionPreviewIcon({ position }) {
35922
36231
  function getBubbleMenuContext(editor) {
35923
36232
  const { selection } = editor.state;
35924
36233
  if (editor.isActive("image")) return "image";
35925
- if (selection instanceof import_tables7.CellSelection) return "table-cell";
36234
+ if (selection instanceof import_tables8.CellSelection) return "table-cell";
35926
36235
  if (editor.isActive("link")) return "link";
35927
36236
  if (!selection.empty) return "text";
35928
36237
  return "none";
@@ -35940,7 +36249,7 @@ var BubbleMenuContent = ({
35940
36249
  const t = useSmartTranslations("UEditor");
35941
36250
  (0, import_react75.useEditorState)({
35942
36251
  editor,
35943
- selector: ({ transactionNumber }) => transactionNumber
36252
+ selector: ({ editor: currentEditor }) => getEditorUiRenderState(currentEditor)
35944
36253
  });
35945
36254
  const { textColors, highlightColors } = useEditorColors();
35946
36255
  const [showLinkInput, setShowLinkInput] = (0, import_react74.useState)(initialShowLinkInput);
@@ -35976,9 +36285,9 @@ var BubbleMenuContent = ({
35976
36285
  const [activeBorderPosition, setActiveBorderPosition] = (0, import_react74.useState)("all");
35977
36286
  const currentCellVerticalAlign = normalizeStyleValue(editor.getAttributes("tableCell").verticalAlign || editor.getAttributes("tableHeader").verticalAlign) || "";
35978
36287
  const currentCellTextDirection = normalizeStyleValue(editor.getAttributes("tableCell").textDirection || editor.getAttributes("tableHeader").textDirection) || "horizontal";
35979
- const isInTable2 = (0, import_tables7.isInTable)(editor.state);
35980
- const canMergeCells = isInTable2 && editor.can().mergeCells();
35981
- const canSplitCell = isInTable2 && editor.can().splitCell();
36288
+ const isInTable3 = (0, import_tables8.isInTable)(editor.state);
36289
+ const canMergeCells = isInTable3 && editor.can().mergeCells();
36290
+ const canSplitCell = isInTable3 && editor.can().splitCell();
35982
36291
  const currentFontSize = normalizeStyleValue(textStyleAttrs.fontSize);
35983
36292
  const currentLineHeight = normalizeStyleValue(textStyleAttrs.lineHeight);
35984
36293
  const quickFontSizes = (0, import_react74.useMemo)(
@@ -36324,7 +36633,7 @@ var BubbleMenuContent = ({
36324
36633
  )
36325
36634
  ] });
36326
36635
  }
36327
- if (showFormulaPanel && isInTable2) {
36636
+ if (showFormulaPanel && isInTable3) {
36328
36637
  return /* @__PURE__ */ (0, import_jsx_runtime94.jsxs)("div", { className: "w-72 p-2", children: [
36329
36638
  /* @__PURE__ */ (0, import_jsx_runtime94.jsxs)("div", { className: "mb-2 flex items-center justify-between gap-2", children: [
36330
36639
  /* @__PURE__ */ (0, import_jsx_runtime94.jsx)("span", { className: "px-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground", children: t("tableMenu.formula") || "Formula" }),
@@ -36888,20 +37197,24 @@ var CustomBubbleMenu = ({
36888
37197
  setIsVisible(false);
36889
37198
  }
36890
37199
  };
36891
- editor.on("selectionUpdate", updatePosition);
36892
- editor.on("focus", updatePosition);
37200
+ let animationFrameId = null;
37201
+ const schedulePositionUpdate = () => {
37202
+ if (animationFrameId !== null) return;
37203
+ animationFrameId = requestAnimationFrame(() => {
37204
+ animationFrameId = null;
37205
+ updatePosition();
37206
+ });
37207
+ };
37208
+ editor.on("transaction", schedulePositionUpdate);
37209
+ editor.on("focus", schedulePositionUpdate);
36893
37210
  editor.on("blur", handleBlur);
36894
- editor.on("transaction", updatePosition);
36895
- editor.on("update", updatePosition);
36896
- const animationFrameId = requestAnimationFrame(updatePosition);
37211
+ schedulePositionUpdate();
36897
37212
  return () => {
36898
- cancelAnimationFrame(animationFrameId);
37213
+ if (animationFrameId !== null) cancelAnimationFrame(animationFrameId);
36899
37214
  clearShowTimeout();
36900
- editor.off("selectionUpdate", updatePosition);
36901
- editor.off("focus", updatePosition);
37215
+ editor.off("transaction", schedulePositionUpdate);
37216
+ editor.off("focus", schedulePositionUpdate);
36902
37217
  editor.off("blur", handleBlur);
36903
- editor.off("transaction", updatePosition);
36904
- editor.off("update", updatePosition);
36905
37218
  };
36906
37219
  }, [editor]);
36907
37220
  (0, import_react74.useEffect)(() => {
@@ -36991,15 +37304,23 @@ var CustomFloatingMenu = ({ editor }) => {
36991
37304
  setIsVisible(true);
36992
37305
  };
36993
37306
  const handleBlur = () => setIsVisible(false);
36994
- editor.on("selectionUpdate", updatePosition);
36995
- editor.on("focus", updatePosition);
37307
+ let animationFrameId = null;
37308
+ const schedulePositionUpdate = () => {
37309
+ if (animationFrameId !== null) return;
37310
+ animationFrameId = requestAnimationFrame(() => {
37311
+ animationFrameId = null;
37312
+ updatePosition();
37313
+ });
37314
+ };
37315
+ editor.on("transaction", schedulePositionUpdate);
37316
+ editor.on("focus", schedulePositionUpdate);
36996
37317
  editor.on("blur", handleBlur);
36997
- editor.on("update", updatePosition);
37318
+ schedulePositionUpdate();
36998
37319
  return () => {
36999
- editor.off("selectionUpdate", updatePosition);
37000
- editor.off("focus", updatePosition);
37320
+ if (animationFrameId !== null) cancelAnimationFrame(animationFrameId);
37321
+ editor.off("transaction", schedulePositionUpdate);
37322
+ editor.off("focus", schedulePositionUpdate);
37001
37323
  editor.off("blur", handleBlur);
37002
- editor.off("update", updatePosition);
37003
37324
  };
37004
37325
  }, [editor]);
37005
37326
  if (!isVisible) return null;
@@ -37023,12 +37344,20 @@ var CustomFloatingMenu = ({ editor }) => {
37023
37344
  };
37024
37345
 
37025
37346
  // src/components/UEditor/CharacterCount.tsx
37347
+ var import_react76 = require("@tiptap/react");
37026
37348
  var import_jsx_runtime95 = require("react/jsx-runtime");
37027
37349
  var CharacterCountDisplay = ({ editor, maxCharacters }) => {
37028
37350
  const t = useSmartTranslations("UEditor");
37029
- const storage = editor.storage;
37030
- const characterCount = storage.characterCount?.characters?.() ?? 0;
37031
- const wordCount = storage.characterCount?.words?.() ?? 0;
37351
+ const { characterCount, wordCount } = (0, import_react76.useEditorState)({
37352
+ editor,
37353
+ selector: ({ editor: currentEditor }) => {
37354
+ const storage = currentEditor.storage;
37355
+ return {
37356
+ characterCount: storage.characterCount?.characters?.() ?? 0,
37357
+ wordCount: storage.characterCount?.words?.() ?? 0
37358
+ };
37359
+ }
37360
+ });
37032
37361
  const percentage = maxCharacters ? Math.round(characterCount / maxCharacters * 100) : 0;
37033
37362
  return /* @__PURE__ */ (0, import_jsx_runtime95.jsxs)("div", { className: "flex items-center gap-3 px-3 py-2 text-xs text-muted-foreground border-t border-border/30 bg-muted/20", children: [
37034
37363
  /* @__PURE__ */ (0, import_jsx_runtime95.jsxs)("span", { children: [
@@ -37462,7 +37791,7 @@ async function prepareUEditorContentForSave({
37462
37791
  }
37463
37792
 
37464
37793
  // src/components/UEditor/table-controls.tsx
37465
- var import_react76 = __toESM(require("react"), 1);
37794
+ var import_react77 = __toESM(require("react"), 1);
37466
37795
 
37467
37796
  // node_modules/prosemirror-model/dist/index.js
37468
37797
  function findDiffStart(a, b, pos) {
@@ -40916,7 +41245,7 @@ function cellAround2($pos) {
40916
41245
  for (let d = $pos.depth - 1; d > 0; d--) if ($pos.node(d).type.spec.tableRole == "row") return $pos.node(0).resolve($pos.before(d + 1));
40917
41246
  return null;
40918
41247
  }
40919
- function isInTable(state) {
41248
+ function isInTable2(state) {
40920
41249
  const $head = state.selection.$head;
40921
41250
  for (let d = $head.depth; d > 0; d--) if ($head.node(d).type.spec.tableRole == "row") return true;
40922
41251
  return false;
@@ -41432,7 +41761,7 @@ function selectedRect4(state) {
41432
41761
  }
41433
41762
  function deprecated_toggleHeader(type) {
41434
41763
  return function(state, dispatch) {
41435
- if (!isInTable(state)) return false;
41764
+ if (!isInTable2(state)) return false;
41436
41765
  if (dispatch) {
41437
41766
  const types = tableNodeTypes2(state.schema);
41438
41767
  const rect = selectedRect4(state), tr = state.tr;
@@ -41472,7 +41801,7 @@ function toggleHeader(type, options) {
41472
41801
  options = options || { useDeprecatedLogic: false };
41473
41802
  if (options.useDeprecatedLogic) return deprecated_toggleHeader(type);
41474
41803
  return function(state, dispatch) {
41475
- if (!isInTable(state)) return false;
41804
+ if (!isInTable2(state)) return false;
41476
41805
  if (dispatch) {
41477
41806
  const types = tableNodeTypes2(state.schema);
41478
41807
  const rect = selectedRect4(state), tr = state.tr;
@@ -42602,20 +42931,20 @@ function getSelectedCell(editor) {
42602
42931
  }
42603
42932
  function TableControls({ editor, containerRef, showCellInspector = true }) {
42604
42933
  const t = useSmartTranslations("UEditor");
42605
- const [layout, setLayout] = import_react76.default.useState(null);
42606
- const [dragPreview, setDragPreview] = import_react76.default.useState(null);
42607
- const [tableResizeActive, setTableResizeActive] = import_react76.default.useState(false);
42608
- const [hoverState, setHoverState] = import_react76.default.useState(DEFAULT_TABLE_HOVER_STATE);
42609
- const [openMenuKey, setOpenMenuKey] = import_react76.default.useState(null);
42610
- const layoutRef = import_react76.default.useRef(null);
42611
- const dragStateRef = import_react76.default.useRef(null);
42612
- const syncFrameRef = import_react76.default.useRef(null);
42613
- const tableResizeFrameRef = import_react76.default.useRef(null);
42614
- const tableResizePreviewFrameRef = import_react76.default.useRef(null);
42615
- import_react76.default.useEffect(() => {
42934
+ const [layout, setLayout] = import_react77.default.useState(null);
42935
+ const [dragPreview, setDragPreview] = import_react77.default.useState(null);
42936
+ const [tableResizeActive, setTableResizeActive] = import_react77.default.useState(false);
42937
+ const [hoverState, setHoverState] = import_react77.default.useState(DEFAULT_TABLE_HOVER_STATE);
42938
+ const [openMenuKey, setOpenMenuKey] = import_react77.default.useState(null);
42939
+ const layoutRef = import_react77.default.useRef(null);
42940
+ const dragStateRef = import_react77.default.useRef(null);
42941
+ const syncFrameRef = import_react77.default.useRef(null);
42942
+ const tableResizeFrameRef = import_react77.default.useRef(null);
42943
+ const tableResizePreviewFrameRef = import_react77.default.useRef(null);
42944
+ import_react77.default.useEffect(() => {
42616
42945
  layoutRef.current = layout;
42617
42946
  }, [layout]);
42618
- const syncFromCell = import_react76.default.useCallback((cell) => {
42947
+ const syncFromCell = import_react77.default.useCallback((cell) => {
42619
42948
  const surface = containerRef.current;
42620
42949
  if (!surface || !cell) {
42621
42950
  setLayout(null);
@@ -42623,23 +42952,23 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42623
42952
  }
42624
42953
  setLayout(buildTableControlLayout(editor, surface, cell));
42625
42954
  }, [containerRef, editor]);
42626
- const syncFromSelection = import_react76.default.useCallback(() => {
42955
+ const syncFromSelection = import_react77.default.useCallback(() => {
42627
42956
  syncFromCell(getSelectedCell(editor));
42628
42957
  }, [editor, syncFromCell]);
42629
- const scheduleSyncFromSelection = import_react76.default.useCallback(() => {
42958
+ const scheduleSyncFromSelection = import_react77.default.useCallback(() => {
42630
42959
  if (syncFrameRef.current !== null) return;
42631
42960
  syncFrameRef.current = window.requestAnimationFrame(() => {
42632
42961
  syncFrameRef.current = null;
42633
42962
  syncFromSelection();
42634
42963
  });
42635
42964
  }, [syncFromSelection]);
42636
- import_react76.default.useEffect(() => () => {
42965
+ import_react77.default.useEffect(() => () => {
42637
42966
  if (syncFrameRef.current !== null) {
42638
42967
  window.cancelAnimationFrame(syncFrameRef.current);
42639
42968
  syncFrameRef.current = null;
42640
42969
  }
42641
42970
  }, []);
42642
- const refreshCurrentLayout = import_react76.default.useCallback(() => {
42971
+ const refreshCurrentLayout = import_react77.default.useCallback(() => {
42643
42972
  setLayout((prev) => {
42644
42973
  if (!prev) return prev;
42645
42974
  const surface = containerRef.current;
@@ -42649,7 +42978,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42649
42978
  return cell ? buildTableControlLayout(editor, surface, cell) : null;
42650
42979
  });
42651
42980
  }, [containerRef, editor]);
42652
- const updateTableResizePreview = import_react76.default.useCallback((dimensions) => {
42981
+ const updateTableResizePreview = import_react77.default.useCallback((dimensions) => {
42653
42982
  const frame = tableResizeFrameRef.current;
42654
42983
  if (!frame) return;
42655
42984
  frame.style.width = `${dimensions.width}px`;
@@ -42659,7 +42988,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42659
42988
  dimensionsLabel.textContent = `${dimensions.width} \xD7 ${dimensions.height}`;
42660
42989
  }
42661
42990
  }, []);
42662
- const resetTableResizePreview = import_react76.default.useCallback(() => {
42991
+ const resetTableResizePreview = import_react77.default.useCallback(() => {
42663
42992
  const activeLayout = layoutRef.current;
42664
42993
  if (!activeLayout) return;
42665
42994
  updateTableResizePreview({
@@ -42667,7 +42996,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42667
42996
  height: Math.round(activeLayout.tableHeight)
42668
42997
  });
42669
42998
  }, [updateTableResizePreview]);
42670
- const clearDrag = import_react76.default.useCallback(() => {
42999
+ const clearDrag = import_react77.default.useCallback(() => {
42671
43000
  const dragState = dragStateRef.current;
42672
43001
  if (dragState?.kind === "resize-table") {
42673
43002
  try {
@@ -42687,7 +43016,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42687
43016
  resetTableResizePreview();
42688
43017
  document.body.style.cursor = "";
42689
43018
  }, [resetTableResizePreview]);
42690
- const updateHoverState = import_react76.default.useCallback((event) => {
43019
+ const updateHoverState = import_react77.default.useCallback((event) => {
42691
43020
  const activeLayout = layoutRef.current;
42692
43021
  const surface = containerRef.current;
42693
43022
  if (!activeLayout || !surface || dragStateRef.current) {
@@ -42703,7 +43032,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42703
43032
  return areTableHoverStatesEqual(prev, nextState) ? prev : nextState;
42704
43033
  });
42705
43034
  }, [containerRef]);
42706
- import_react76.default.useEffect(() => {
43035
+ import_react77.default.useEffect(() => {
42707
43036
  const proseMirror = editor.view.dom;
42708
43037
  const surface = containerRef.current;
42709
43038
  if (!surface) return void 0;
@@ -42772,37 +43101,37 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42772
43101
  editor.off("update", refreshCurrentLayout);
42773
43102
  };
42774
43103
  }, [clearDrag, containerRef, editor, refreshCurrentLayout, syncFromCell, syncFromSelection, updateHoverState]);
42775
- const runAtCellPos = import_react76.default.useCallback((cellPos, command, options) => {
43104
+ const runAtCellPos = import_react77.default.useCallback((cellPos, command, options) => {
42776
43105
  const result = runTableCommandAtCellPos(editor, cellPos, command);
42777
43106
  if (options?.sync !== false) {
42778
43107
  scheduleSyncFromSelection();
42779
43108
  }
42780
43109
  return result;
42781
43110
  }, [editor, scheduleSyncFromSelection]);
42782
- const runAtActiveCell = import_react76.default.useCallback((command, options) => {
43111
+ const runAtActiveCell = import_react77.default.useCallback((command, options) => {
42783
43112
  return runAtCellPos(layoutRef.current?.cellPos ?? null, command, options);
42784
43113
  }, [runAtCellPos]);
42785
- const duplicateRowAt = import_react76.default.useCallback((rowIndex, cellPos) => {
43114
+ const duplicateRowAt = import_react77.default.useCallback((rowIndex, cellPos) => {
42786
43115
  const result = duplicateTableRowAt(editor, rowIndex, cellPos);
42787
43116
  scheduleSyncFromSelection();
42788
43117
  return result;
42789
43118
  }, [editor, scheduleSyncFromSelection]);
42790
- const clearRowAt = import_react76.default.useCallback((rowIndex, cellPos) => {
43119
+ const clearRowAt = import_react77.default.useCallback((rowIndex, cellPos) => {
42791
43120
  const result = clearTableRowAt(editor, rowIndex, cellPos);
42792
43121
  scheduleSyncFromSelection();
42793
43122
  return result;
42794
43123
  }, [editor, scheduleSyncFromSelection]);
42795
- const duplicateColumnAt = import_react76.default.useCallback((columnIndex, cellPos) => {
43124
+ const duplicateColumnAt = import_react77.default.useCallback((columnIndex, cellPos) => {
42796
43125
  const result = duplicateTableColumnAt(editor, columnIndex, cellPos);
42797
43126
  scheduleSyncFromSelection();
42798
43127
  return result;
42799
43128
  }, [editor, scheduleSyncFromSelection]);
42800
- const clearColumnAt = import_react76.default.useCallback((columnIndex, cellPos) => {
43129
+ const clearColumnAt = import_react77.default.useCallback((columnIndex, cellPos) => {
42801
43130
  const result = clearTableColumnAt(editor, columnIndex, cellPos);
42802
43131
  scheduleSyncFromSelection();
42803
43132
  return result;
42804
43133
  }, [editor, scheduleSyncFromSelection]);
42805
- const expandTableBy = import_react76.default.useCallback((rows, cols) => {
43134
+ const expandTableBy = import_react77.default.useCallback((rows, cols) => {
42806
43135
  const activeCellPos = layoutRef.current?.cellPos ?? editor.state.selection.from;
42807
43136
  const result = expandTableFromCell(editor, activeCellPos, rows, cols);
42808
43137
  scheduleSyncFromSelection();
@@ -42811,7 +43140,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42811
43140
  const canExpandTable = Boolean(layout);
42812
43141
  const controlsVisible = dragPreview !== null;
42813
43142
  const tableMenuOpen = openMenuKey === "table";
42814
- const startTableResize = import_react76.default.useCallback((event) => {
43143
+ const startTableResize = import_react77.default.useCallback((event) => {
42815
43144
  if (event.button !== 0 || dragStateRef.current) return;
42816
43145
  const activeLayout = layoutRef.current;
42817
43146
  if (!activeLayout) return;
@@ -42847,19 +43176,19 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42847
43176
  updateTableResizePreview(pendingDimensions);
42848
43177
  document.body.style.cursor = "nwse-resize";
42849
43178
  }, [editor, updateTableResizePreview]);
42850
- const startAddColumnDrag = import_react76.default.useCallback(() => {
43179
+ const startAddColumnDrag = import_react77.default.useCallback(() => {
42851
43180
  setOpenMenuKey(null);
42852
43181
  dragStateRef.current = { kind: "add-column", previewCols: 1 };
42853
43182
  setDragPreview({ kind: "add-column", previewCols: 1 });
42854
43183
  document.body.style.cursor = "ew-resize";
42855
43184
  }, []);
42856
- const startAddRowDrag = import_react76.default.useCallback(() => {
43185
+ const startAddRowDrag = import_react77.default.useCallback(() => {
42857
43186
  setOpenMenuKey(null);
42858
43187
  dragStateRef.current = { kind: "add-row", previewRows: 1 };
42859
43188
  setDragPreview({ kind: "add-row", previewRows: 1 });
42860
43189
  document.body.style.cursor = "ns-resize";
42861
43190
  }, []);
42862
- const startRowDrag = import_react76.default.useCallback((rowHandle) => {
43191
+ const startRowDrag = import_react77.default.useCallback((rowHandle) => {
42863
43192
  setOpenMenuKey(null);
42864
43193
  dragStateRef.current = {
42865
43194
  kind: "row",
@@ -42876,7 +43205,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42876
43205
  });
42877
43206
  document.body.style.cursor = "grabbing";
42878
43207
  }, []);
42879
- const startColumnDrag = import_react76.default.useCallback((columnHandle) => {
43208
+ const startColumnDrag = import_react77.default.useCallback((columnHandle) => {
42880
43209
  setOpenMenuKey(null);
42881
43210
  dragStateRef.current = {
42882
43211
  kind: "column",
@@ -42893,7 +43222,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42893
43222
  });
42894
43223
  document.body.style.cursor = "grabbing";
42895
43224
  }, []);
42896
- import_react76.default.useEffect(() => {
43225
+ import_react77.default.useEffect(() => {
42897
43226
  const handleMouseMove2 = (event) => {
42898
43227
  const dragState = dragStateRef.current;
42899
43228
  const activeLayout = layoutRef.current;
@@ -42985,7 +43314,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
42985
43314
  window.removeEventListener("blur", clearDrag);
42986
43315
  };
42987
43316
  }, [clearDrag, containerRef, editor, expandTableBy, scheduleSyncFromSelection]);
42988
- import_react76.default.useEffect(() => {
43317
+ import_react77.default.useEffect(() => {
42989
43318
  const handlePointerMove = (event) => {
42990
43319
  const dragState = dragStateRef.current;
42991
43320
  if (!dragState || dragState.kind !== "resize-table" || event.pointerId !== dragState.pointerId) return;
@@ -43035,7 +43364,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
43035
43364
  }
43036
43365
  };
43037
43366
  }, [clearDrag, editor, scheduleSyncFromSelection, updateTableResizePreview]);
43038
- const openCellInspector = import_react76.default.useCallback(() => {
43367
+ const openCellInspector = import_react77.default.useCallback(() => {
43039
43368
  const cellPos = layoutRef.current?.cellPos;
43040
43369
  if (!showCellInspector || cellPos == null) return;
43041
43370
  const didSelect = editor.commands.setCellSelection({
@@ -43047,7 +43376,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
43047
43376
  if (!editor.isDestroyed) editor.view.focus();
43048
43377
  });
43049
43378
  }, [editor, showCellInspector]);
43050
- const menuItems = import_react76.default.useMemo(() => {
43379
+ const menuItems = import_react77.default.useMemo(() => {
43051
43380
  if (!layout) return [];
43052
43381
  return [
43053
43382
  ...showCellInspector ? [{
@@ -43120,7 +43449,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
43120
43449
  }
43121
43450
  ];
43122
43451
  }, [editor, layout, openCellInspector, runAtActiveCell, showCellInspector, t]);
43123
- const getRowHandleMenuItems = import_react76.default.useCallback((rowHandle) => [
43452
+ const getRowHandleMenuItems = import_react77.default.useCallback((rowHandle) => [
43124
43453
  {
43125
43454
  label: t("tableMenu.addRowBefore"),
43126
43455
  icon: import_lucide_react57.ArrowUp,
@@ -43148,7 +43477,7 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
43148
43477
  destructive: true
43149
43478
  }
43150
43479
  ], [clearRowAt, duplicateRowAt, runAtCellPos, t]);
43151
- const getColumnHandleMenuItems = import_react76.default.useCallback((columnHandle) => [
43480
+ const getColumnHandleMenuItems = import_react77.default.useCallback((columnHandle) => [
43152
43481
  {
43153
43482
  label: t("tableMenu.addColumnBefore"),
43154
43483
  icon: import_lucide_react57.ArrowLeft,
@@ -43476,10 +43805,10 @@ var UEDITOR_PROSEMIRROR_CLASS_NAME = cn(
43476
43805
  );
43477
43806
 
43478
43807
  // src/components/UEditor/use-table-interactions.ts
43479
- var import_react78 = __toESM(require("react"), 1);
43808
+ var import_react79 = __toESM(require("react"), 1);
43480
43809
 
43481
43810
  // src/components/UEditor/use-table-row-resize.ts
43482
- var import_react77 = __toESM(require("react"), 1);
43811
+ var import_react78 = __toESM(require("react"), 1);
43483
43812
  function useTableRowResize({
43484
43813
  editor,
43485
43814
  setHoveredTableCell,
@@ -43488,16 +43817,16 @@ function useTableRowResize({
43488
43817
  clearAllTableResizeHover,
43489
43818
  scheduleTableLayoutSync
43490
43819
  }) {
43491
- const stateRef = (0, import_react77.useRef)(null);
43492
- const syncActiveGuide = import_react77.default.useCallback(() => {
43820
+ const stateRef = (0, import_react78.useRef)(null);
43821
+ const syncActiveGuide = import_react78.default.useCallback(() => {
43493
43822
  const state = stateRef.current;
43494
43823
  if (!state) return false;
43495
43824
  setHoveredTableCell(state.cellElement);
43496
43825
  showRowGuide(state.tableElement, state.rowElement, state.cellElement, state.pendingHeight);
43497
43826
  return true;
43498
43827
  }, [setHoveredTableCell, showRowGuide]);
43499
- const isResizing = import_react77.default.useCallback(() => stateRef.current !== null, []);
43500
- const beginResize = import_react77.default.useCallback((event, table, row, cell) => {
43828
+ const isResizing = import_react78.default.useCallback(() => stateRef.current !== null, []);
43829
+ const beginResize = import_react78.default.useCallback((event, table, row, cell) => {
43501
43830
  if (!editor || !isRowResizeHotspot(cell, event.clientX, event.clientY)) {
43502
43831
  return false;
43503
43832
  }
@@ -43523,7 +43852,7 @@ function useTableRowResize({
43523
43852
  event.stopPropagation();
43524
43853
  return true;
43525
43854
  }, [editor, setHoveredTableCell, showRowGuide]);
43526
- const handlePointerMove = import_react77.default.useCallback((event) => {
43855
+ const handlePointerMove = import_react78.default.useCallback((event) => {
43527
43856
  const state = stateRef.current;
43528
43857
  if (!state) return;
43529
43858
  const nextHeight = Math.max(
@@ -43540,7 +43869,7 @@ function useTableRowResize({
43540
43869
  document.body.style.cursor = "row-resize";
43541
43870
  showRowGuide(state.tableElement, state.rowElement, state.cellElement, nextHeight);
43542
43871
  }, [showRowGuide]);
43543
- const handlePointerUp = import_react77.default.useCallback((event) => {
43872
+ const handlePointerUp = import_react78.default.useCallback((event) => {
43544
43873
  if (!editor) return;
43545
43874
  const state = stateRef.current;
43546
43875
  if (!state) return;
@@ -43564,7 +43893,7 @@ function useTableRowResize({
43564
43893
  clearAllTableResizeHover();
43565
43894
  scheduleTableLayoutSync();
43566
43895
  }, [clearAllTableResizeHover, clearHoveredTableCell, editor, scheduleTableLayoutSync]);
43567
- const cancelResize = import_react77.default.useCallback(() => {
43896
+ const cancelResize = import_react78.default.useCallback(() => {
43568
43897
  if (!stateRef.current) return;
43569
43898
  stateRef.current = null;
43570
43899
  document.body.style.cursor = "";
@@ -43572,7 +43901,7 @@ function useTableRowResize({
43572
43901
  clearAllTableResizeHover();
43573
43902
  scheduleTableLayoutSync();
43574
43903
  }, [clearAllTableResizeHover, clearHoveredTableCell, scheduleTableLayoutSync]);
43575
- const cleanup = import_react77.default.useCallback(() => {
43904
+ const cleanup = import_react78.default.useCallback(() => {
43576
43905
  stateRef.current = null;
43577
43906
  document.body.style.cursor = "";
43578
43907
  }, []);
@@ -43589,24 +43918,24 @@ function useTableRowResize({
43589
43918
 
43590
43919
  // src/components/UEditor/use-table-interactions.ts
43591
43920
  function useUEditorTableInteractions(editor, editable = true) {
43592
- const editorContentRef = (0, import_react78.useRef)(null);
43593
- const tableColumnGuideRef = (0, import_react78.useRef)(null);
43594
- const tableRowGuideRef = (0, import_react78.useRef)(null);
43595
- const activeTableCellHighlightRef = (0, import_react78.useRef)(null);
43596
- const hoveredTableCellRef = (0, import_react78.useRef)(null);
43597
- const activeTableCellRef = (0, import_react78.useRef)(null);
43598
- const suppressActiveCellHighlightRef = (0, import_react78.useRef)(false);
43599
- const tableLayoutSyncFrameRef = (0, import_react78.useRef)(null);
43600
- const getProseMirrorElement = import_react78.default.useCallback(() => {
43921
+ const editorContentRef = (0, import_react79.useRef)(null);
43922
+ const tableColumnGuideRef = (0, import_react79.useRef)(null);
43923
+ const tableRowGuideRef = (0, import_react79.useRef)(null);
43924
+ const activeTableCellHighlightRef = (0, import_react79.useRef)(null);
43925
+ const hoveredTableCellRef = (0, import_react79.useRef)(null);
43926
+ const activeTableCellRef = (0, import_react79.useRef)(null);
43927
+ const suppressActiveCellHighlightRef = (0, import_react79.useRef)(false);
43928
+ const tableLayoutSyncFrameRef = (0, import_react79.useRef)(null);
43929
+ const getProseMirrorElement = import_react79.default.useCallback(() => {
43601
43930
  return editorContentRef.current?.querySelector(".ProseMirror");
43602
43931
  }, []);
43603
- const setEditorResizeCursor = import_react78.default.useCallback((cursor) => {
43932
+ const setEditorResizeCursor = import_react79.default.useCallback((cursor) => {
43604
43933
  const proseMirror = getProseMirrorElement();
43605
43934
  if (proseMirror) {
43606
43935
  proseMirror.style.cursor = cursor;
43607
43936
  }
43608
43937
  }, [getProseMirrorElement]);
43609
- const hideColumnGuide = import_react78.default.useCallback(() => {
43938
+ const hideColumnGuide = import_react79.default.useCallback(() => {
43610
43939
  editorContentRef.current?.classList.remove("resize-cursor");
43611
43940
  getProseMirrorElement()?.classList.remove("resize-cursor");
43612
43941
  const guide = tableColumnGuideRef.current;
@@ -43614,7 +43943,7 @@ function useUEditorTableInteractions(editor, editable = true) {
43614
43943
  guide.style.opacity = "0";
43615
43944
  }
43616
43945
  }, [getProseMirrorElement]);
43617
- const hideRowGuide = import_react78.default.useCallback(() => {
43946
+ const hideRowGuide = import_react79.default.useCallback(() => {
43618
43947
  editorContentRef.current?.classList.remove("resize-row-cursor");
43619
43948
  getProseMirrorElement()?.classList.remove("resize-row-cursor");
43620
43949
  const guide = tableRowGuideRef.current;
@@ -43622,12 +43951,12 @@ function useUEditorTableInteractions(editor, editable = true) {
43622
43951
  guide.style.opacity = "0";
43623
43952
  }
43624
43953
  }, [getProseMirrorElement]);
43625
- const clearAllTableResizeHover = import_react78.default.useCallback(() => {
43954
+ const clearAllTableResizeHover = import_react79.default.useCallback(() => {
43626
43955
  setEditorResizeCursor("");
43627
43956
  hideColumnGuide();
43628
43957
  hideRowGuide();
43629
43958
  }, [hideColumnGuide, hideRowGuide, setEditorResizeCursor]);
43630
- const updateActiveCellHighlight = import_react78.default.useCallback((cell) => {
43959
+ const updateActiveCellHighlight = import_react79.default.useCallback((cell) => {
43631
43960
  const surface = editorContentRef.current;
43632
43961
  const highlight = activeTableCellHighlightRef.current;
43633
43962
  if (!highlight) return;
@@ -43642,7 +43971,7 @@ function useUEditorTableInteractions(editor, editable = true) {
43642
43971
  highlight.style.width = `${metrics.width}px`;
43643
43972
  highlight.style.height = `${metrics.height}px`;
43644
43973
  }, []);
43645
- const scheduleTableLayoutSync = import_react78.default.useCallback(() => {
43974
+ const scheduleTableLayoutSync = import_react79.default.useCallback(() => {
43646
43975
  if (tableLayoutSyncFrameRef.current !== null) return;
43647
43976
  tableLayoutSyncFrameRef.current = window.requestAnimationFrame(() => {
43648
43977
  tableLayoutSyncFrameRef.current = null;
@@ -43650,7 +43979,7 @@ function useUEditorTableInteractions(editor, editable = true) {
43650
43979
  editorContentRef.current?.dispatchEvent(new CustomEvent(UEDITOR_TABLE_LAYOUT_CHANGE_EVENT));
43651
43980
  });
43652
43981
  }, [updateActiveCellHighlight]);
43653
- const setActiveTableCell = import_react78.default.useCallback((cell) => {
43982
+ const setActiveTableCell = import_react79.default.useCallback((cell) => {
43654
43983
  if (activeTableCellRef.current === cell) {
43655
43984
  updateActiveCellHighlight(cell);
43656
43985
  return;
@@ -43658,17 +43987,17 @@ function useUEditorTableInteractions(editor, editable = true) {
43658
43987
  activeTableCellRef.current = cell;
43659
43988
  updateActiveCellHighlight(activeTableCellRef.current);
43660
43989
  }, [updateActiveCellHighlight]);
43661
- const clearActiveTableCell = import_react78.default.useCallback(() => {
43990
+ const clearActiveTableCell = import_react79.default.useCallback(() => {
43662
43991
  activeTableCellRef.current = null;
43663
43992
  updateActiveCellHighlight(null);
43664
43993
  }, [updateActiveCellHighlight]);
43665
- const setHoveredTableCell = import_react78.default.useCallback((cell) => {
43994
+ const setHoveredTableCell = import_react79.default.useCallback((cell) => {
43666
43995
  hoveredTableCellRef.current = cell;
43667
43996
  }, []);
43668
- const clearHoveredTableCell = import_react78.default.useCallback(() => {
43997
+ const clearHoveredTableCell = import_react79.default.useCallback(() => {
43669
43998
  hoveredTableCellRef.current = null;
43670
43999
  }, []);
43671
- const showColumnGuide = import_react78.default.useCallback((table, row, cell) => {
44000
+ const showColumnGuide = import_react79.default.useCallback((table, row, cell) => {
43672
44001
  const surface = editorContentRef.current;
43673
44002
  const guide = tableColumnGuideRef.current;
43674
44003
  if (!surface || !guide) return;
@@ -43682,7 +44011,7 @@ function useUEditorTableInteractions(editor, editable = true) {
43682
44011
  getProseMirrorElement()?.classList.add("resize-cursor");
43683
44012
  setEditorResizeCursor("col-resize");
43684
44013
  }, [getProseMirrorElement, setEditorResizeCursor]);
43685
- const showRowGuide = import_react78.default.useCallback((table, row, cell, previewHeight) => {
44014
+ const showRowGuide = import_react79.default.useCallback((table, row, cell, previewHeight) => {
43686
44015
  const surface = editorContentRef.current;
43687
44016
  const guide = tableRowGuideRef.current;
43688
44017
  if (!surface || !guide) return;
@@ -43714,7 +44043,7 @@ function useUEditorTableInteractions(editor, editable = true) {
43714
44043
  clearAllTableResizeHover,
43715
44044
  scheduleTableLayoutSync
43716
44045
  });
43717
- const syncActiveTableCellFromSelection = import_react78.default.useCallback(() => {
44046
+ const syncActiveTableCellFromSelection = import_react79.default.useCallback(() => {
43718
44047
  if (!editor) return;
43719
44048
  if (!editor.isFocused) {
43720
44049
  clearActiveTableCell();
@@ -43722,7 +44051,7 @@ function useUEditorTableInteractions(editor, editable = true) {
43722
44051
  }
43723
44052
  setActiveTableCell(getSelectionTableCell(editor.view));
43724
44053
  }, [clearActiveTableCell, editor, setActiveTableCell]);
43725
- (0, import_react78.useEffect)(() => {
44054
+ (0, import_react79.useEffect)(() => {
43726
44055
  if (!editor || !editable) return void 0;
43727
44056
  const proseMirror = editor.view.dom;
43728
44057
  const surface = editorContentRef.current;
@@ -43897,12 +44226,12 @@ function useUEditorTableInteractions(editor, editable = true) {
43897
44226
  }
43898
44227
 
43899
44228
  // src/components/UEditor/use-formula-coordinate-overlay.ts
43900
- var import_react79 = require("react");
43901
- var import_tables9 = require("@tiptap/pm/tables");
44229
+ var import_react80 = require("react");
44230
+ var import_tables10 = require("@tiptap/pm/tables");
43902
44231
 
43903
44232
  // src/components/UEditor/table-formula-range-picker.ts
43904
44233
  var import_state12 = require("@tiptap/pm/state");
43905
- var import_tables8 = require("@tiptap/pm/tables");
44234
+ var import_tables9 = require("@tiptap/pm/tables");
43906
44235
  function getCellText2(cellNode) {
43907
44236
  return cellNode.textBetween(0, cellNode.content.size, "\n").trim();
43908
44237
  }
@@ -43920,7 +44249,7 @@ function getFormulaEditingTableContext(view) {
43920
44249
  if (!tableNode || tableNode.type.name !== "table") return null;
43921
44250
  const tableDom = cellDom.closest("table");
43922
44251
  if (!(tableDom instanceof HTMLTableElement)) return null;
43923
- const tableMap = import_tables8.TableMap.get(tableNode);
44252
+ const tableMap = import_tables9.TableMap.get(tableNode);
43924
44253
  const tableStart = $from.start(tableDepth);
43925
44254
  const formulaCellRect = tableMap.findCell(cellPos - tableStart);
43926
44255
  return {
@@ -43937,7 +44266,7 @@ function getFormulaEditingTableContext(view) {
43937
44266
  return null;
43938
44267
  }
43939
44268
  function collectTableFormulaCells(tableNode) {
43940
- const tableMap = import_tables8.TableMap.get(tableNode);
44269
+ const tableMap = import_tables9.TableMap.get(tableNode);
43941
44270
  const formulas = [];
43942
44271
  tableNode.forEach((rowNode, rowOffset) => {
43943
44272
  rowNode.forEach((cellNode, cellOffset) => {
@@ -44023,7 +44352,7 @@ function getFormulaTableCellInfo(view, target, tablePos) {
44023
44352
  const domPos = view.posAtDOM(cell, 0);
44024
44353
  const tableInfo = findTableForPos(view, domPos);
44025
44354
  if (!tableInfo || tableInfo.pos !== tablePos) return null;
44026
- const map = import_tables8.TableMap.get(tableInfo.node);
44355
+ const map = import_tables9.TableMap.get(tableInfo.node);
44027
44356
  const relativeCellPos = getCellRelativePosFromDomPos2(map, tableInfo.start, domPos);
44028
44357
  if (relativeCellPos == null) return null;
44029
44358
  const rect = map.findCell(relativeCellPos);
@@ -44167,8 +44496,8 @@ function createBlockedReferenceHighlight(label) {
44167
44496
  return element;
44168
44497
  }
44169
44498
  function useFormulaCoordinateOverlay(editor, containerRef, labels) {
44170
- const overlayRef = (0, import_react79.useRef)(null);
44171
- (0, import_react79.useEffect)(() => {
44499
+ const overlayRef = (0, import_react80.useRef)(null);
44500
+ (0, import_react80.useEffect)(() => {
44172
44501
  if (!editor) return void 0;
44173
44502
  const overlay = overlayRef.current;
44174
44503
  const container = containerRef.current;
@@ -44197,7 +44526,7 @@ function useFormulaCoordinateOverlay(editor, containerRef, labels) {
44197
44526
  const tableRect = context.tableDom.getBoundingClientRect();
44198
44527
  const tableLeft = tableRect.left - containerRect.left + container.scrollLeft;
44199
44528
  const tableTop = tableRect.top - containerRect.top + container.scrollTop;
44200
- const map = import_tables9.TableMap.get(context.tableNode);
44529
+ const map = import_tables10.TableMap.get(context.tableNode);
44201
44530
  const columnSegments = Array(map.width);
44202
44531
  const rowSegments = Array(map.height);
44203
44532
  const cellInfos = [];
@@ -44375,8 +44704,8 @@ function useFormulaCoordinateOverlay(editor, containerRef, labels) {
44375
44704
  }
44376
44705
 
44377
44706
  // src/components/UEditor/menu-bar.tsx
44378
- var import_react80 = __toESM(require("react"), 1);
44379
- var import_react81 = require("@tiptap/react");
44707
+ var import_react81 = __toESM(require("react"), 1);
44708
+ var import_react82 = require("@tiptap/react");
44380
44709
  var import_lucide_react58 = require("lucide-react");
44381
44710
 
44382
44711
  // src/components/UEditor/preview-html.ts
@@ -44557,7 +44886,7 @@ function renderMenuItems(items) {
44557
44886
  case "sub":
44558
44887
  return /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(DropdownMenuSub, { label: item.label, icon: item.icon, disabled: item.disabled, children: renderMenuItems(item.items) }, i);
44559
44888
  case "custom":
44560
- return /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(import_react80.default.Fragment, { children: item.render() }, item.key);
44889
+ return /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(import_react81.default.Fragment, { children: item.render() }, item.key);
44561
44890
  }
44562
44891
  });
44563
44892
  }
@@ -44933,7 +45262,7 @@ function buildTableMenuItems(t, editor, onInsertTable) {
44933
45262
  }
44934
45263
  ];
44935
45264
  }
44936
- var MenuBarTrigger = import_react80.default.forwardRef(
45265
+ var MenuBarTrigger = import_react81.default.forwardRef(
44937
45266
  ({ children, className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime102.jsx)(
44938
45267
  "button",
44939
45268
  {
@@ -44965,18 +45294,18 @@ var MenuBar = ({
44965
45294
  onPreview
44966
45295
  }) => {
44967
45296
  const t = useSmartTranslations("UEditor");
44968
- (0, import_react81.useEditorState)({
45297
+ (0, import_react82.useEditorState)({
44969
45298
  editor,
44970
- selector: ({ transactionNumber }) => transactionNumber
45299
+ selector: ({ editor: currentEditor }) => getEditorUiRenderState(currentEditor)
44971
45300
  });
44972
- const fileInputRef = (0, import_react80.useRef)(null);
44973
- const [showImageInput, setShowImageInput] = (0, import_react80.useState)(false);
44974
- const [showLinkInput, setShowLinkInput] = (0, import_react80.useState)(false);
44975
- const [openMenuKey, setOpenMenuKey] = (0, import_react80.useState)(null);
44976
- const [showSourceDialog, setShowSourceDialog] = (0, import_react80.useState)(false);
44977
- const [sourceHtml, setSourceHtml] = (0, import_react80.useState)("");
44978
- const [showPreviewDialog, setShowPreviewDialog] = (0, import_react80.useState)(false);
44979
- const previewHtml = (0, import_react80.useMemo)(
45301
+ const fileInputRef = (0, import_react81.useRef)(null);
45302
+ const [showImageInput, setShowImageInput] = (0, import_react81.useState)(false);
45303
+ const [showLinkInput, setShowLinkInput] = (0, import_react81.useState)(false);
45304
+ const [openMenuKey, setOpenMenuKey] = (0, import_react81.useState)(null);
45305
+ const [showSourceDialog, setShowSourceDialog] = (0, import_react81.useState)(false);
45306
+ const [sourceHtml, setSourceHtml] = (0, import_react81.useState)("");
45307
+ const [showPreviewDialog, setShowPreviewDialog] = (0, import_react81.useState)(false);
45308
+ const previewHtml = (0, import_react81.useMemo)(
44980
45309
  () => showPreviewDialog ? prepareUEditorPreviewHtml(editor.getHTML()) : "",
44981
45310
  [editor, showPreviewDialog]
44982
45311
  );
@@ -45262,20 +45591,33 @@ var MenuBar = ({
45262
45591
  };
45263
45592
 
45264
45593
  // src/components/UEditor/table-formula-bar.tsx
45265
- var import_react82 = require("react");
45266
- var import_react83 = require("@tiptap/react");
45594
+ var import_react83 = require("react");
45595
+ var import_react84 = require("@tiptap/react");
45267
45596
  var import_lucide_react59 = require("lucide-react");
45268
45597
  var import_jsx_runtime103 = require("react/jsx-runtime");
45269
45598
  function TableFormulaBar({ editor }) {
45270
45599
  const t = useSmartTranslations("UEditor");
45271
- const inputRef = (0, import_react82.useRef)(null);
45272
- const [draftState, setDraftState] = (0, import_react82.useState)(null);
45273
- (0, import_react83.useEditorState)({
45600
+ const inputRef = (0, import_react83.useRef)(null);
45601
+ const [draftState, setDraftState] = (0, import_react83.useState)(null);
45602
+ const selectedFormulaState = (0, import_react84.useEditorState)({
45274
45603
  editor,
45275
- selector: ({ transactionNumber }) => transactionNumber
45604
+ selector: ({ editor: currentEditor }) => {
45605
+ const cell = getSelectedTableFormulaCell(currentEditor);
45606
+ if (!cell) return null;
45607
+ return {
45608
+ cellPos: cell.cellPos,
45609
+ column: cell.column,
45610
+ computedValue: cell.computedValue,
45611
+ formula: cell.formula,
45612
+ formulaState: cell.formulaState,
45613
+ label: cell.label,
45614
+ row: cell.row,
45615
+ tablePos: cell.tablePos
45616
+ };
45617
+ }
45276
45618
  });
45277
- const selectedCell = getSelectedTableFormulaCell(editor);
45278
- (0, import_react82.useEffect)(() => {
45619
+ const selectedCell = selectedFormulaState ? getSelectedTableFormulaCell(editor) : null;
45620
+ (0, import_react83.useEffect)(() => {
45279
45621
  const focusFormulaInput = () => {
45280
45622
  inputRef.current?.focus();
45281
45623
  };
@@ -45410,7 +45752,7 @@ function TableFormulaBar({ editor }) {
45410
45752
 
45411
45753
  // src/components/UEditor/UEditor.tsx
45412
45754
  var import_jsx_runtime104 = require("react/jsx-runtime");
45413
- var UEditor = import_react84.default.forwardRef(({
45755
+ var UEditor = import_react85.default.forwardRef(({
45414
45756
  content = "",
45415
45757
  onChange,
45416
45758
  onHtmlChange,
@@ -45452,14 +45794,15 @@ var UEditor = import_react84.default.forwardRef(({
45452
45794
  }, ref) => {
45453
45795
  const t = useSmartTranslations("UEditor");
45454
45796
  const effectivePlaceholder = placeholder ?? t("placeholder");
45455
- const inFlightPrepareRef = (0, import_react84.useRef)(null);
45456
- const lastAppliedContentRef = (0, import_react84.useRef)(content ?? "");
45457
- const scheduledFormulaRecalculateRef = (0, import_react84.useRef)(false);
45458
- const editorInstanceRef = (0, import_react84.useRef)(null);
45459
- const formulaRangePickRef = (0, import_react84.useRef)(null);
45460
- const formulaRangeSurfaceRef = (0, import_react84.useRef)(null);
45461
- const [formulaRangeHighlight, setFormulaRangeHighlight] = import_react84.default.useState(null);
45462
- const scheduleFormulaRecalculate = import_react84.default.useCallback((editor2, options) => {
45797
+ const inFlightPrepareRef = (0, import_react85.useRef)(null);
45798
+ const lastAppliedContentRef = (0, import_react85.useRef)(content ?? "");
45799
+ const scheduledFormulaRecalculateRef = (0, import_react85.useRef)(false);
45800
+ const pendingFormulaTextRecalculateRef = (0, import_react85.useRef)(false);
45801
+ const editorInstanceRef = (0, import_react85.useRef)(null);
45802
+ const formulaRangePickRef = (0, import_react85.useRef)(null);
45803
+ const formulaRangeSurfaceRef = (0, import_react85.useRef)(null);
45804
+ const [formulaRangeHighlight, setFormulaRangeHighlight] = import_react85.default.useState(null);
45805
+ const scheduleFormulaRecalculate = import_react85.default.useCallback((editor2, options) => {
45463
45806
  if (editor2.isDestroyed || scheduledFormulaRecalculateRef.current) return;
45464
45807
  if (!options?.force && isEditingTableFormulaText(editor2)) return;
45465
45808
  scheduledFormulaRecalculateRef.current = true;
@@ -45470,7 +45813,7 @@ var UEditor = import_react84.default.forwardRef(({
45470
45813
  }
45471
45814
  });
45472
45815
  }, []);
45473
- const resolvedUploadFile = (0, import_react84.useMemo)(() => {
45816
+ const resolvedUploadFile = (0, import_react85.useMemo)(() => {
45474
45817
  if (uploadFile) return uploadFile;
45475
45818
  if (uploadFileForSave) {
45476
45819
  return async (file) => {
@@ -45480,7 +45823,7 @@ var UEditor = import_react84.default.forwardRef(({
45480
45823
  }
45481
45824
  return uploadImage;
45482
45825
  }, [uploadFile, uploadFileForSave, uploadImage]);
45483
- const extensions = (0, import_react84.useMemo)(
45826
+ const extensions = (0, import_react85.useMemo)(
45484
45827
  () => [
45485
45828
  ...buildUEditorExtensions({
45486
45829
  placeholder: effectivePlaceholder,
@@ -45499,11 +45842,11 @@ var UEditor = import_react84.default.forwardRef(({
45499
45842
  ],
45500
45843
  [effectivePlaceholder, t, maxCharacters, uploadImage, resolvedUploadFile, imageInsertMode, maxImageFileSize, allowedImageMimeTypes, fallbackToDataUrl, editable, fetchMetadata, extraExtensions]
45501
45844
  );
45502
- const syncFormulaRangeHighlight = import_react84.default.useCallback((pickState) => {
45845
+ const syncFormulaRangeHighlight = import_react85.default.useCallback((pickState) => {
45503
45846
  const container = formulaRangeSurfaceRef.current;
45504
45847
  setFormulaRangeHighlight(container && pickState ? getFormulaRangePickHighlight(container, pickState) : null);
45505
45848
  }, []);
45506
- const editor = (0, import_react85.useEditor)({
45849
+ const editor = (0, import_react86.useEditor)({
45507
45850
  immediatelyRender: false,
45508
45851
  extensions,
45509
45852
  content,
@@ -45593,23 +45936,36 @@ var UEditor = import_react84.default.forwardRef(({
45593
45936
  },
45594
45937
  onUpdate: ({ editor: editor2, transaction }) => {
45595
45938
  if (!transaction.getMeta(UEDITOR_TABLE_FORMULA_RECALCULATE_META)) {
45596
- scheduleFormulaRecalculate(editor2);
45939
+ if (isEditingTableFormulaText(editor2)) {
45940
+ pendingFormulaTextRecalculateRef.current = true;
45941
+ } else {
45942
+ pendingFormulaTextRecalculateRef.current = false;
45943
+ scheduleFormulaRecalculate(editor2);
45944
+ }
45945
+ }
45946
+ if (onChange || onHtmlChange) {
45947
+ const html = editor2.getHTML();
45948
+ onChange?.(html);
45949
+ onHtmlChange?.(html);
45950
+ }
45951
+ if (onJsonChange) {
45952
+ onJsonChange(editor2.getJSON());
45597
45953
  }
45598
- const html = editor2.getHTML();
45599
- onChange?.(html);
45600
- onHtmlChange?.(html);
45601
- onJsonChange?.(editor2.getJSON());
45602
45954
  },
45603
45955
  onSelectionUpdate: ({ editor: editor2 }) => {
45604
- scheduleFormulaRecalculate(editor2);
45956
+ if (pendingFormulaTextRecalculateRef.current && !isEditingTableFormulaText(editor2)) {
45957
+ pendingFormulaTextRecalculateRef.current = false;
45958
+ scheduleFormulaRecalculate(editor2);
45959
+ }
45605
45960
  },
45606
45961
  onBlur: ({ editor: editor2, event }) => {
45607
45962
  const nextTarget = event.relatedTarget;
45608
45963
  if (nextTarget instanceof Element && nextTarget.closest("[data-ueditor-formula-bar]")) return;
45964
+ pendingFormulaTextRecalculateRef.current = false;
45609
45965
  scheduleFormulaRecalculate(editor2, { force: true });
45610
45966
  }
45611
45967
  });
45612
- (0, import_react84.useEffect)(() => {
45968
+ (0, import_react85.useEffect)(() => {
45613
45969
  editorInstanceRef.current = editor;
45614
45970
  return () => {
45615
45971
  if (editorInstanceRef.current === editor) editorInstanceRef.current = null;
@@ -45625,7 +45981,7 @@ var UEditor = import_react84.default.forwardRef(({
45625
45981
  apply: t("tableMenu.apply"),
45626
45982
  cancel: t("imageInput.cancelBtn")
45627
45983
  });
45628
- (0, import_react84.useImperativeHandle)(
45984
+ (0, import_react85.useImperativeHandle)(
45629
45985
  ref,
45630
45986
  () => ({
45631
45987
  editor,
@@ -45650,7 +46006,7 @@ var UEditor = import_react84.default.forwardRef(({
45650
46006
  }),
45651
46007
  [content, editor, uploadImageForSave, uploadFileForSave, uploadImageConcurrency]
45652
46008
  );
45653
- (0, import_react84.useEffect)(() => {
46009
+ (0, import_react85.useEffect)(() => {
45654
46010
  if (!editor) return;
45655
46011
  queueMicrotask(() => {
45656
46012
  if (!editor.isDestroyed) {
@@ -45658,7 +46014,7 @@ var UEditor = import_react84.default.forwardRef(({
45658
46014
  }
45659
46015
  });
45660
46016
  }, [editor]);
45661
- (0, import_react84.useEffect)(() => {
46017
+ (0, import_react85.useEffect)(() => {
45662
46018
  if (!editor) return;
45663
46019
  const nextContent = content ?? "";
45664
46020
  if (lastAppliedContentRef.current === nextContent) return;
@@ -45815,7 +46171,7 @@ var UEditor = import_react84.default.forwardRef(({
45815
46171
  }
45816
46172
  ),
45817
46173
  /* @__PURE__ */ (0, import_jsx_runtime104.jsx)(
45818
- import_react85.EditorContent,
46174
+ import_react86.EditorContent,
45819
46175
  {
45820
46176
  editor,
45821
46177
  className: "min-h-full"