@underverse-ui/underverse 1.0.204 → 1.0.206

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.
Files changed (31) hide show
  1. package/api-reference.json +1 -1
  2. package/dist/{EmojiPicker-UN6N7YVB.js → EmojiPicker-FEJJDAWZ.js} +4 -4
  3. package/dist/{chunk-CC3QO2YM.js → chunk-4E43DRP2.js} +243 -57
  4. package/dist/chunk-4E43DRP2.js.map +1 -0
  5. package/dist/{chunk-KFTYWTJR.js → chunk-AMAILXHP.js} +81 -36
  6. package/dist/chunk-AMAILXHP.js.map +1 -0
  7. package/dist/{chunk-GSBRTFP2.js → chunk-BRDGIALS.js} +28 -17
  8. package/dist/chunk-BRDGIALS.js.map +1 -0
  9. package/dist/{chunk-ZUAIBY2Z.js → chunk-CYCBSKWI.js} +2 -2
  10. package/dist/{chunk-CKKLFVOY.js → chunk-F6A7HJE4.js} +3 -3
  11. package/dist/{chunk-QVQTWZ24.js → chunk-GKY5DHGR.js} +3 -3
  12. package/dist/index.cjs +328 -90
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +16 -0
  15. package/dist/index.d.ts +16 -0
  16. package/dist/index.js +6 -6
  17. package/dist/{menu-bar-6U5S4PS7.js → menu-bar-6GS5LLTD.js} +4 -4
  18. package/dist/ueditor.cjs +338 -101
  19. package/dist/ueditor.cjs.map +1 -1
  20. package/dist/ueditor.d.cts +6 -0
  21. package/dist/ueditor.d.ts +6 -0
  22. package/dist/ueditor.js +4 -4
  23. package/package.json +1 -1
  24. package/dist/chunk-CC3QO2YM.js.map +0 -1
  25. package/dist/chunk-GSBRTFP2.js.map +0 -1
  26. package/dist/chunk-KFTYWTJR.js.map +0 -1
  27. /package/dist/{EmojiPicker-UN6N7YVB.js.map → EmojiPicker-FEJJDAWZ.js.map} +0 -0
  28. /package/dist/{chunk-ZUAIBY2Z.js.map → chunk-CYCBSKWI.js.map} +0 -0
  29. /package/dist/{chunk-CKKLFVOY.js.map → chunk-F6A7HJE4.js.map} +0 -0
  30. /package/dist/{chunk-QVQTWZ24.js.map → chunk-GKY5DHGR.js.map} +0 -0
  31. /package/dist/{menu-bar-6U5S4PS7.js.map → menu-bar-6GS5LLTD.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -498,7 +498,9 @@ var init_en = __esm({
498
498
  alignVerticalBottom: "Bottom Align",
499
499
  textDirection: "Text Direction",
500
500
  horizontalText: "Horizontal Text",
501
- verticalText: "Vertical Text"
501
+ verticalText: "Vertical Text",
502
+ wrapText: "Wrap Text",
503
+ noWrapText: "Don't Wrap Text"
502
504
  },
503
505
  callout: {
504
506
  selectEmoji: "Select Emoji",
@@ -954,7 +956,9 @@ var init_vi = __esm({
954
956
  alignVerticalBottom: "C\u0103n d\u01B0\u1EDBi",
955
957
  textDirection: "H\u01B0\u1EDBng ch\u1EEF",
956
958
  horizontalText: "Ch\u1EEF ngang",
957
- verticalText: "Ch\u1EEF d\u1ECDc"
959
+ verticalText: "Ch\u1EEF d\u1ECDc",
960
+ wrapText: "T\u1EF1 xu\u1ED1ng d\xF2ng",
961
+ noWrapText: "Kh\xF4ng xu\u1ED1ng d\xF2ng"
958
962
  },
959
963
  callout: {
960
964
  selectEmoji: "Ch\u1ECDn Bi\u1EC3u t\u01B0\u1EE3ng",
@@ -1410,7 +1414,9 @@ var init_ko = __esm({
1410
1414
  alignVerticalBottom: "\uC544\uB798\uCABD \uB9DE\uCDA4",
1411
1415
  textDirection: "\uD14D\uC2A4\uD2B8 \uBC29\uD5A5",
1412
1416
  horizontalText: "\uAC00\uB85C\uC4F0\uAE30",
1413
- verticalText: "\uC138\uB85C\uC4F0\uAE30"
1417
+ verticalText: "\uC138\uB85C\uC4F0\uAE30",
1418
+ wrapText: "\uD14D\uC2A4\uD2B8 \uC904 \uBC14\uAFC8",
1419
+ noWrapText: "\uC904 \uBC14\uAFC8 \uC548 \uD568"
1414
1420
  },
1415
1421
  callout: {
1416
1422
  selectEmoji: "\uC774\uBAA8\uC9C0 \uC120\uD0DD",
@@ -1866,7 +1872,9 @@ var init_ja = __esm({
1866
1872
  alignVerticalBottom: "\u4E0B\u63C3\u3048",
1867
1873
  textDirection: "\u6587\u5B57\u65B9\u5411",
1868
1874
  horizontalText: "\u6A2A\u66F8\u304D",
1869
- verticalText: "\u7E26\u66F8\u304D"
1875
+ verticalText: "\u7E26\u66F8\u304D",
1876
+ wrapText: "\u30C6\u30AD\u30B9\u30C8\u3092\u6298\u308A\u8FD4\u3059",
1877
+ noWrapText: "\u6298\u308A\u8FD4\u3055\u306A\u3044"
1870
1878
  },
1871
1879
  callout: {
1872
1880
  selectEmoji: "\u7D75\u6587\u5B57\u3092\u9078\u629E",
@@ -2028,16 +2036,19 @@ var init_TranslationContext = __esm({
2028
2036
  },
2029
2037
  [locale, translations]
2030
2038
  );
2031
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(GlobalI18nProvider, { i18n, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TranslationContext.Provider, { value: { locale, t }, children }) });
2039
+ const value = React6.useMemo(() => ({ locale, t }), [locale, t]);
2040
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(GlobalI18nProvider, { i18n, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TranslationContext.Provider, { value, children }) });
2032
2041
  };
2033
2042
  useUnderverseTranslations = (namespace) => {
2034
2043
  const context = React6.useContext(TranslationContext);
2035
- if (!context) {
2036
- return (key) => {
2037
- return getUnderverseDefaultTranslation("en", namespace, key);
2038
- };
2039
- }
2040
- return context.t(namespace);
2044
+ return React6.useMemo(() => {
2045
+ if (!context) {
2046
+ return (key) => {
2047
+ return getUnderverseDefaultTranslation("en", namespace, key);
2048
+ };
2049
+ }
2050
+ return context.t(namespace);
2051
+ }, [context, namespace]);
2041
2052
  };
2042
2053
  useUnderverseLocale = () => {
2043
2054
  const context = React6.useContext(TranslationContext);
@@ -2191,10 +2202,10 @@ function useSmartTranslations(namespace) {
2191
2202
  setEnvironmentLocale(detected);
2192
2203
  }
2193
2204
  }, [forceInternal, internalLocale, nextIntlBridge]);
2194
- if (forceInternal) {
2195
- return internalT;
2196
- }
2197
- return (key) => {
2205
+ return React8.useCallback((key) => {
2206
+ if (forceInternal) {
2207
+ return internalT(key);
2208
+ }
2198
2209
  const resolvedEnvironmentLocale = environmentLocale && environmentLocale !== internalLocale ? environmentLocale : null;
2199
2210
  const primaryLocale = nextIntlBridge?.locale ?? resolvedEnvironmentLocale ?? internalLocale;
2200
2211
  const fallbackLocale = resolvedEnvironmentLocale && resolvedEnvironmentLocale !== primaryLocale ? resolvedEnvironmentLocale : null;
@@ -2223,7 +2234,7 @@ function useSmartTranslations(namespace) {
2223
2234
  return internalValue;
2224
2235
  }
2225
2236
  return key;
2226
- };
2237
+ }, [environmentLocale, forceInternal, internalLocale, internalT, namespace, nextIntlBridge]);
2227
2238
  }
2228
2239
  function useSmartLocale() {
2229
2240
  const forceInternal = React8.useContext(ForceInternalContext);
@@ -5774,6 +5785,25 @@ function resolveEventElement(target) {
5774
5785
  if (target instanceof Node) return target.parentElement;
5775
5786
  return null;
5776
5787
  }
5788
+ function isPointOverRenderedText(root, clientX, clientY) {
5789
+ const view = root.ownerDocument.defaultView;
5790
+ if (!view) return false;
5791
+ const walker = root.ownerDocument.createTreeWalker(root, view.NodeFilter.SHOW_TEXT);
5792
+ let textNode = walker.nextNode();
5793
+ while (textNode) {
5794
+ if (textNode.textContent?.length) {
5795
+ const range = root.ownerDocument.createRange();
5796
+ range.selectNodeContents(textNode);
5797
+ const textRects = Array.from(range.getClientRects());
5798
+ range.detach?.();
5799
+ if (textRects.some((rect) => clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom)) {
5800
+ return true;
5801
+ }
5802
+ }
5803
+ textNode = walker.nextNode();
5804
+ }
5805
+ return false;
5806
+ }
5777
5807
  function getSelectionTableCell(view) {
5778
5808
  const browserSelection = window.getSelection();
5779
5809
  const anchorElement = resolveEventElement(browserSelection?.anchorNode ?? null);
@@ -5897,16 +5927,19 @@ function applyTableAlignment(editor, tableAlign, anchorPos) {
5897
5927
  const tableDom = editor.view.nodeDOM(tableInfo.pos);
5898
5928
  const tableElement = domAtTableElement?.closest?.("table") ?? (tableDom instanceof HTMLTableElement ? tableDom : tableDom instanceof HTMLElement ? tableDom.querySelector("table") : null) ?? (editor.view.dom.querySelectorAll("table").length === 1 ? editor.view.dom.querySelector("table") : null);
5899
5929
  if (tableElement instanceof HTMLTableElement) {
5930
+ tableElement.style.tableLayout = "fixed";
5931
+ if (tableElement.style.width === "max-content") {
5932
+ tableElement.style.removeProperty("width");
5933
+ }
5934
+ if (tableElement.style.maxWidth === "100%") {
5935
+ tableElement.style.removeProperty("max-width");
5936
+ }
5900
5937
  if (tableAlign) {
5901
5938
  tableElement.setAttribute("data-table-align", tableAlign);
5902
- tableElement.style.width = "max-content";
5903
- tableElement.style.maxWidth = "100%";
5904
5939
  tableElement.style.marginLeft = tableAlign === "center" || tableAlign === "right" ? "auto" : "0";
5905
5940
  tableElement.style.marginRight = tableAlign === "center" ? "auto" : tableAlign === "right" ? "0" : "auto";
5906
5941
  } else {
5907
5942
  tableElement.removeAttribute("data-table-align");
5908
- tableElement.style.removeProperty("width");
5909
- tableElement.style.removeProperty("max-width");
5910
5943
  tableElement.style.removeProperty("margin-left");
5911
5944
  tableElement.style.removeProperty("margin-right");
5912
5945
  }
@@ -7052,6 +7085,7 @@ function computeEditorUiRenderState(editor) {
7052
7085
  formula: tableCell.formula ?? tableHeader.formula ?? null,
7053
7086
  numberFormat: tableCell.numberFormat ?? tableHeader.numberFormat ?? null,
7054
7087
  textDirection: tableCell.textDirection ?? tableHeader.textDirection ?? null,
7088
+ textWrap: tableCell.textWrap ?? tableHeader.textWrap ?? "wrap",
7055
7089
  verticalAlign: tableCell.verticalAlign ?? tableHeader.verticalAlign ?? null
7056
7090
  },
7057
7091
  can: {
@@ -7263,6 +7297,7 @@ var init_toolbar = __esm({
7263
7297
  const canSplitCell = hasTableContext && editor.can().splitCell();
7264
7298
  const currentCellVerticalAlign = normalizeStyleValue(editor.getAttributes("tableCell").verticalAlign || editor.getAttributes("tableHeader").verticalAlign) || "";
7265
7299
  const currentCellTextDirection = normalizeStyleValue(editor.getAttributes("tableCell").textDirection || editor.getAttributes("tableHeader").textDirection) || "horizontal";
7300
+ const currentCellTextWrap = normalizeStyleValue(editor.getAttributes("tableCell").textWrap || editor.getAttributes("tableHeader").textWrap) || "wrap";
7266
7301
  const currentFontFamily = normalizeStyleValue(textStyleAttrs.fontFamily);
7267
7302
  const currentFontSize = normalizeStyleValue(textStyleAttrs.fontSize);
7268
7303
  const currentTextColor = normalizeStyleValue(textStyleAttrs.color) || "inherit";
@@ -7773,33 +7808,44 @@ var init_toolbar = __esm({
7773
7808
  ]
7774
7809
  }
7775
7810
  ),
7776
- hasTableContext && /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(
7777
- DropdownMenu,
7778
- {
7779
- trigger: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(ToolbarButton, { onClick: () => {
7780
- }, title: t("tableMenu.textDirection"), children: currentCellTextDirection === "vertical" ? /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.ArrowDown, { className: "w-4 h-4" }) : /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.ArrowRight, { className: "w-4 h-4" }) }),
7781
- children: [
7782
- /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
7783
- DropdownMenuItem,
7784
- {
7785
- icon: import_lucide_react52.ArrowRight,
7786
- label: t("tableMenu.horizontalText"),
7787
- onClick: () => applyTableCellAttribute(editor, "textDirection", null),
7788
- active: currentCellTextDirection === "horizontal"
7789
- }
7790
- ),
7791
- /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
7792
- DropdownMenuItem,
7793
- {
7794
- icon: import_lucide_react52.ArrowDown,
7795
- label: t("tableMenu.verticalText"),
7796
- onClick: () => applyTableCellAttribute(editor, "textDirection", "vertical"),
7797
- active: currentCellTextDirection === "vertical"
7798
- }
7799
- )
7800
- ]
7801
- }
7802
- )
7811
+ hasTableContext && /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(import_jsx_runtime93.Fragment, { children: [
7812
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(
7813
+ DropdownMenu,
7814
+ {
7815
+ trigger: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(ToolbarButton, { onClick: () => {
7816
+ }, title: t("tableMenu.textDirection"), children: currentCellTextDirection === "vertical" ? /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.ArrowDown, { className: "w-4 h-4" }) : /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.ArrowRight, { className: "w-4 h-4" }) }),
7817
+ children: [
7818
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
7819
+ DropdownMenuItem,
7820
+ {
7821
+ icon: import_lucide_react52.ArrowRight,
7822
+ label: t("tableMenu.horizontalText"),
7823
+ onClick: () => applyTableCellAttribute(editor, "textDirection", null),
7824
+ active: currentCellTextDirection === "horizontal"
7825
+ }
7826
+ ),
7827
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
7828
+ DropdownMenuItem,
7829
+ {
7830
+ icon: import_lucide_react52.ArrowDown,
7831
+ label: t("tableMenu.verticalText"),
7832
+ onClick: () => applyTableCellAttribute(editor, "textDirection", "vertical"),
7833
+ active: currentCellTextDirection === "vertical"
7834
+ }
7835
+ )
7836
+ ]
7837
+ }
7838
+ ),
7839
+ /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(
7840
+ ToolbarButton,
7841
+ {
7842
+ onClick: () => applyTableCellAttribute(editor, "textWrap", currentCellTextWrap === "nowrap" ? "wrap" : "nowrap"),
7843
+ active: currentCellTextWrap !== "nowrap",
7844
+ title: currentCellTextWrap === "nowrap" ? t("tableMenu.wrapText") : t("tableMenu.noWrapText"),
7845
+ children: /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(import_lucide_react52.WrapText, { className: "h-4 w-4" })
7846
+ }
7847
+ )
7848
+ ] })
7803
7849
  ] }),
7804
7850
  /* @__PURE__ */ (0, import_jsx_runtime93.jsx)(ToolbarDivider, {}),
7805
7851
  /* @__PURE__ */ (0, import_jsx_runtime93.jsxs)(
@@ -8186,8 +8232,6 @@ var init_editor_styles = __esm({
8186
8232
  "[&_table]:table-fixed",
8187
8233
  "[&_table]:overflow-hidden",
8188
8234
  "[&_table]:select-text",
8189
- "[&_table[data-table-align]]:w-max",
8190
- "[&_table[data-table-align]]:max-w-full",
8191
8235
  "[&_table[data-table-align='center']]:mx-auto",
8192
8236
  "[&_table[data-table-align='right']]:ml-auto",
8193
8237
  "[&_table[data-table-align='right']]:mr-0",
@@ -8197,6 +8241,11 @@ var init_editor_styles = __esm({
8197
8241
  "[&_td]:select-text",
8198
8242
  "[&_td]:px-2",
8199
8243
  "[&_td]:py-0",
8244
+ "[&_td]:whitespace-normal",
8245
+ "[&_td]:[overflow-wrap:anywhere]",
8246
+ "[&_td]:[word-break:normal]",
8247
+ "[&_td[data-text-wrap='nowrap']]:whitespace-nowrap",
8248
+ "[&_td[data-text-wrap='nowrap']]:[overflow-wrap:normal]",
8200
8249
  "[&_td_p]:my-0",
8201
8250
  "[&_th]:relative",
8202
8251
  "[&_th]:align-top",
@@ -8204,6 +8253,11 @@ var init_editor_styles = __esm({
8204
8253
  "[&_th]:select-text",
8205
8254
  "[&_th]:px-2",
8206
8255
  "[&_th]:py-0",
8256
+ "[&_th]:whitespace-normal",
8257
+ "[&_th]:[overflow-wrap:anywhere]",
8258
+ "[&_th]:[word-break:normal]",
8259
+ "[&_th[data-text-wrap='nowrap']]:whitespace-nowrap",
8260
+ "[&_th[data-text-wrap='nowrap']]:[overflow-wrap:normal]",
8207
8261
  "[&_th_p]:my-0",
8208
8262
  "[&_td[data-formula]]:pr-7",
8209
8263
  "[&_th[data-formula]]:pr-7",
@@ -32916,7 +32970,7 @@ var import_react85 = require("@tiptap/react");
32916
32970
  init_cn();
32917
32971
 
32918
32972
  // src/components/UEditor/extensions.ts
32919
- var import_core19 = require("@tiptap/core");
32973
+ var import_core20 = require("@tiptap/core");
32920
32974
  var import_extension_document = require("@tiptap/extension-document");
32921
32975
  var import_extension_paragraph = require("@tiptap/extension-paragraph");
32922
32976
  var import_extension_text = require("@tiptap/extension-text");
@@ -32933,7 +32987,7 @@ var import_extension_task_list = require("@tiptap/extension-task-list");
32933
32987
  var import_extension_task_item = require("@tiptap/extension-task-item");
32934
32988
  var import_extension_blockquote = require("@tiptap/extension-blockquote");
32935
32989
  var import_extension_code = require("@tiptap/extension-code");
32936
- var import_core20 = require("@tiptap/core");
32990
+ var import_core21 = require("@tiptap/core");
32937
32991
  var import_react69 = require("@tiptap/react");
32938
32992
 
32939
32993
  // src/components/UEditor/callout.ts
@@ -35756,6 +35810,7 @@ var Indent = import_core16.Extension.create({
35756
35810
  var indent_default = Indent;
35757
35811
 
35758
35812
  // src/components/UEditor/table-align.ts
35813
+ var import_core17 = require("@tiptap/core");
35759
35814
  var import_extension_table = require("@tiptap/extension-table");
35760
35815
  var import_state7 = require("@tiptap/pm/state");
35761
35816
  var import_tables3 = require("@tiptap/pm/tables");
@@ -35766,12 +35821,13 @@ var import_view2 = require("@tiptap/pm/view");
35766
35821
  var import_tables2 = require("@tiptap/pm/tables");
35767
35822
  var DEFAULT_TABLE_COLUMN_WIDTH = 100;
35768
35823
  var MIN_RESIZED_TABLE_COLUMN_WIDTH = 25;
35769
- function getDynamicColumnMinWidth(startWidth, fallbackMinWidth) {
35770
- return Math.max(fallbackMinWidth, Math.round(startWidth / 3));
35824
+ function getColumnResizeMinWidth(configuredMinWidth) {
35825
+ const normalizedMinWidth = Number.isFinite(configuredMinWidth) && configuredMinWidth > 0 ? Math.round(configuredMinWidth) : MIN_RESIZED_TABLE_COLUMN_WIDTH;
35826
+ return Math.max(MIN_RESIZED_TABLE_COLUMN_WIDTH, normalizedMinWidth);
35771
35827
  }
35772
35828
  function setColumnStyle(column, width) {
35773
35829
  if (width == null) {
35774
- column.style.width = "";
35830
+ column.style.width = `${DEFAULT_TABLE_COLUMN_WIDTH}px`;
35775
35831
  column.style.minWidth = `${DEFAULT_TABLE_COLUMN_WIDTH}px`;
35776
35832
  return;
35777
35833
  }
@@ -35783,7 +35839,6 @@ function isTableColumnElement(node) {
35783
35839
  }
35784
35840
  function updateDynamicColumns(node, colgroup, table, overrideCol, overrideValue) {
35785
35841
  let totalWidth = 0;
35786
- let fixedWidth = true;
35787
35842
  let nextDOM = colgroup.firstChild;
35788
35843
  const row = node.firstChild;
35789
35844
  if (row) {
@@ -35793,9 +35848,6 @@ function updateDynamicColumns(node, colgroup, table, overrideCol, overrideValue)
35793
35848
  const rawWidth = overrideCol === col ? overrideValue : colwidth?.[spanIndex];
35794
35849
  const width = rawWidth ? Math.max(rawWidth, MIN_RESIZED_TABLE_COLUMN_WIDTH) : null;
35795
35850
  totalWidth += width ?? DEFAULT_TABLE_COLUMN_WIDTH;
35796
- if (!width) {
35797
- fixedWidth = false;
35798
- }
35799
35851
  const colElement = isTableColumnElement(nextDOM) ? nextDOM : colgroup.appendChild(document.createElement("col"));
35800
35852
  setColumnStyle(colElement, width);
35801
35853
  nextDOM = colElement.nextSibling;
@@ -35808,11 +35860,10 @@ function updateDynamicColumns(node, colgroup, table, overrideCol, overrideValue)
35808
35860
  nextDOM = after;
35809
35861
  }
35810
35862
  const hasUserWidth = typeof node.attrs.style === "string" && /\bwidth\s*:/i.test(node.attrs.style);
35811
- if (fixedWidth && !hasUserWidth) {
35863
+ if (!hasUserWidth) {
35812
35864
  table.style.width = `${totalWidth}px`;
35813
35865
  table.style.minWidth = "";
35814
35866
  } else {
35815
- table.style.width = "";
35816
35867
  table.style.minWidth = `${totalWidth}px`;
35817
35868
  }
35818
35869
  }
@@ -35825,6 +35876,7 @@ var UEditorTableView = class {
35825
35876
  if (node.attrs.style) {
35826
35877
  this.table.style.cssText = node.attrs.style;
35827
35878
  }
35879
+ this.table.style.tableLayout = "fixed";
35828
35880
  this.colgroup = this.table.appendChild(document.createElement("colgroup"));
35829
35881
  updateDynamicColumns(node, this.colgroup, this.table);
35830
35882
  this.contentDOM = this.table.appendChild(document.createElement("tbody"));
@@ -36006,7 +36058,7 @@ function handleMouseDown(view, event, cellMinWidth) {
36006
36058
  colspan: attrs.colspan ?? 1,
36007
36059
  colwidth: attrs.colwidth
36008
36060
  });
36009
- const minWidth = getDynamicColumnMinWidth(width, cellMinWidth);
36061
+ const minWidth = getColumnResizeMinWidth(cellMinWidth);
36010
36062
  const dragging = {
36011
36063
  startX: event.clientX,
36012
36064
  startWidth: width,
@@ -36135,15 +36187,37 @@ function parseTableAlign(element) {
36135
36187
  function renderTableAlignStyle(tableAlign) {
36136
36188
  switch (tableAlign) {
36137
36189
  case "center":
36138
- return "width: max-content; max-width: 100%; margin-left: auto; margin-right: auto;";
36190
+ return "table-layout: fixed; margin-left: auto; margin-right: auto;";
36139
36191
  case "right":
36140
- return "width: max-content; max-width: 100%; margin-left: auto; margin-right: 0;";
36192
+ return "table-layout: fixed; margin-left: auto; margin-right: 0;";
36141
36193
  case "left":
36142
- return "width: max-content; max-width: 100%; margin-left: 0; margin-right: auto;";
36194
+ return "table-layout: fixed; margin-left: 0; margin-right: auto;";
36143
36195
  default:
36144
36196
  return "";
36145
36197
  }
36146
36198
  }
36199
+ function createUEditorColGroup(node) {
36200
+ const columns = [];
36201
+ let totalWidth = 0;
36202
+ const firstRow = node.firstChild;
36203
+ if (firstRow) {
36204
+ for (let cellIndex = 0; cellIndex < firstRow.childCount; cellIndex += 1) {
36205
+ const cell = firstRow.child(cellIndex);
36206
+ const colspan = Math.max(1, Number(cell.attrs.colspan) || 1);
36207
+ const colwidth = Array.isArray(cell.attrs.colwidth) ? cell.attrs.colwidth : [];
36208
+ for (let spanIndex = 0; spanIndex < colspan; spanIndex += 1) {
36209
+ const storedWidth = Number(colwidth[spanIndex]);
36210
+ const width = Number.isFinite(storedWidth) && storedWidth > 0 ? Math.max(MIN_RESIZED_TABLE_COLUMN_WIDTH, Math.round(storedWidth)) : DEFAULT_TABLE_COLUMN_WIDTH;
36211
+ totalWidth += width;
36212
+ columns.push(["col", { style: `width: ${width}px; min-width: ${width}px;`, width: String(width) }]);
36213
+ }
36214
+ }
36215
+ }
36216
+ return {
36217
+ colgroup: ["colgroup", {}, ...columns],
36218
+ tableWidth: totalWidth > 0 ? `${totalWidth}px` : ""
36219
+ };
36220
+ }
36147
36221
  var UEditorTable = import_extension_table.Table.extend({
36148
36222
  addGlobalAttributes() {
36149
36223
  return [
@@ -36197,6 +36271,18 @@ var UEditorTable = import_extension_table.Table.extend({
36197
36271
  }
36198
36272
  };
36199
36273
  },
36274
+ renderHTML({ node, HTMLAttributes }) {
36275
+ const { colgroup, tableWidth } = createUEditorColGroup(node);
36276
+ const table = [
36277
+ "table",
36278
+ (0, import_core17.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {
36279
+ style: tableWidth ? `width: ${tableWidth};` : "table-layout: fixed;"
36280
+ }),
36281
+ colgroup,
36282
+ ["tbody", 0]
36283
+ ];
36284
+ return this.options.renderWrapper ? ["div", { class: "tableWrapper" }, table] : table;
36285
+ },
36200
36286
  addProseMirrorPlugins() {
36201
36287
  const isResizable = this.options.resizable && this.editor.isEditable;
36202
36288
  return [
@@ -36350,7 +36436,7 @@ var CodeBlockView = ({
36350
36436
  };
36351
36437
 
36352
36438
  // src/components/UEditor/optimized-lowlight.ts
36353
- var import_core17 = require("@tiptap/core");
36439
+ var import_core18 = require("@tiptap/core");
36354
36440
  var import_state8 = require("@tiptap/pm/state");
36355
36441
  var import_view3 = require("@tiptap/pm/view");
36356
36442
  function parseHighlightNodes(nodes, inheritedClasses = []) {
@@ -36397,7 +36483,7 @@ function buildLowlightDecorations({
36397
36483
  nodeName
36398
36484
  }) {
36399
36485
  const decorations = [];
36400
- for (const block of (0, import_core17.findChildren)(doc, (node) => node.type.name === nodeName)) {
36486
+ for (const block of (0, import_core18.findChildren)(doc, (node) => node.type.name === nodeName)) {
36401
36487
  let from = block.pos + 1;
36402
36488
  const language = block.node.attrs.language || defaultLanguage;
36403
36489
  const result = highlightCode(lowlight, language, block.node.textContent);
@@ -36538,7 +36624,7 @@ function createOptimizedLowlightPlugin({
36538
36624
  }
36539
36625
 
36540
36626
  // src/components/UEditor/table-formula-recalculation.ts
36541
- var import_core18 = require("@tiptap/core");
36627
+ var import_core19 = require("@tiptap/core");
36542
36628
  var import_state11 = require("@tiptap/pm/state");
36543
36629
 
36544
36630
  // src/components/UEditor/table-formula-commands.ts
@@ -37562,7 +37648,7 @@ function recalculateAllTableFormulas(editor) {
37562
37648
  }
37563
37649
 
37564
37650
  // src/components/UEditor/table-formula-recalculation.ts
37565
- var TableFormulaRecalculation = import_core18.Extension.create({
37651
+ var TableFormulaRecalculation = import_core19.Extension.create({
37566
37652
  name: "tableFormulaRecalculation",
37567
37653
  addProseMirrorPlugins() {
37568
37654
  return [
@@ -37593,6 +37679,21 @@ function getFormulaStateAttributes(attributes) {
37593
37679
  "data-formula-state": computedValue.startsWith("#") ? "error" : "computed"
37594
37680
  };
37595
37681
  }
37682
+ function normalizeTableCellTextWrap(value) {
37683
+ return value === "nowrap" ? "nowrap" : "wrap";
37684
+ }
37685
+ function parseTableCellTextWrap(element) {
37686
+ if (element.getAttribute("data-text-wrap") === "nowrap" || element.style.whiteSpace === "nowrap") {
37687
+ return "nowrap";
37688
+ }
37689
+ return "wrap";
37690
+ }
37691
+ function renderTableCellTextWrap(attributes) {
37692
+ return normalizeTableCellTextWrap(attributes.textWrap) === "nowrap" ? { "data-text-wrap": "nowrap" } : {};
37693
+ }
37694
+ function getTableCellTextWrapStyle(value) {
37695
+ return normalizeTableCellTextWrap(value) === "nowrap" ? "white-space: nowrap; overflow-wrap: normal; word-break: normal" : "white-space: normal; overflow-wrap: anywhere; word-break: normal";
37696
+ }
37596
37697
  var CustomTableCell = import_extension_table_cell.TableCell.extend({
37597
37698
  addAttributes() {
37598
37699
  return {
@@ -37693,6 +37794,11 @@ var CustomTableCell = import_extension_table_cell.TableCell.extend({
37693
37794
  default: null,
37694
37795
  parseHTML: (element) => element.getAttribute("data-text-direction") === "vertical" || ["sideways-lr", "vertical-lr", "vertical-rl"].includes(element.style.writingMode) ? "vertical" : null,
37695
37796
  renderHTML: (attributes) => attributes.textDirection === "vertical" ? { "data-text-direction": "vertical" } : {}
37797
+ },
37798
+ textWrap: {
37799
+ default: "wrap",
37800
+ parseHTML: parseTableCellTextWrap,
37801
+ renderHTML: renderTableCellTextWrap
37696
37802
  }
37697
37803
  };
37698
37804
  },
@@ -37704,6 +37810,7 @@ var CustomTableCell = import_extension_table_cell.TableCell.extend({
37704
37810
  const borderWidth = HTMLAttributes["data-border-width"];
37705
37811
  const verticalAlign = HTMLAttributes["data-vertical-align"];
37706
37812
  const textDirection = HTMLAttributes["data-text-direction"];
37813
+ const textWrap = HTMLAttributes["data-text-wrap"];
37707
37814
  let mergedStyle = style;
37708
37815
  if (bg) mergedStyle += `; background-color: ${bg}`;
37709
37816
  if (borderColor) mergedStyle += `; border-color: ${borderColor}`;
@@ -37711,10 +37818,11 @@ var CustomTableCell = import_extension_table_cell.TableCell.extend({
37711
37818
  if (borderWidth) mergedStyle += `; border-width: ${borderWidth}`;
37712
37819
  if (verticalAlign) mergedStyle += `; vertical-align: ${verticalAlign}`;
37713
37820
  if (textDirection === "vertical") mergedStyle += "; writing-mode: sideways-lr; text-orientation: mixed";
37821
+ mergedStyle += `; ${getTableCellTextWrapStyle(textWrap)}`;
37714
37822
  mergedStyle = mergedStyle.replace(/^;/, "").trim();
37715
37823
  return [
37716
37824
  "td",
37717
- (0, import_core19.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, getFormulaStateAttributes(HTMLAttributes), mergedStyle ? { style: mergedStyle } : {}),
37825
+ (0, import_core20.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, getFormulaStateAttributes(HTMLAttributes), mergedStyle ? { style: mergedStyle } : {}),
37718
37826
  0
37719
37827
  ];
37720
37828
  }
@@ -37819,6 +37927,11 @@ var CustomTableHeader = import_extension_table_header.TableHeader.extend({
37819
37927
  default: null,
37820
37928
  parseHTML: (element) => element.getAttribute("data-text-direction") === "vertical" || ["sideways-lr", "vertical-lr", "vertical-rl"].includes(element.style.writingMode) ? "vertical" : null,
37821
37929
  renderHTML: (attributes) => attributes.textDirection === "vertical" ? { "data-text-direction": "vertical" } : {}
37930
+ },
37931
+ textWrap: {
37932
+ default: "wrap",
37933
+ parseHTML: parseTableCellTextWrap,
37934
+ renderHTML: renderTableCellTextWrap
37822
37935
  }
37823
37936
  };
37824
37937
  },
@@ -37830,6 +37943,7 @@ var CustomTableHeader = import_extension_table_header.TableHeader.extend({
37830
37943
  const borderWidth = HTMLAttributes["data-border-width"];
37831
37944
  const verticalAlign = HTMLAttributes["data-vertical-align"];
37832
37945
  const textDirection = HTMLAttributes["data-text-direction"];
37946
+ const textWrap = HTMLAttributes["data-text-wrap"];
37833
37947
  let mergedStyle = style;
37834
37948
  if (bg) mergedStyle += `; background-color: ${bg}`;
37835
37949
  if (borderColor) mergedStyle += `; border-color: ${borderColor}`;
@@ -37837,10 +37951,11 @@ var CustomTableHeader = import_extension_table_header.TableHeader.extend({
37837
37951
  if (borderWidth) mergedStyle += `; border-width: ${borderWidth}`;
37838
37952
  if (verticalAlign) mergedStyle += `; vertical-align: ${verticalAlign}`;
37839
37953
  if (textDirection === "vertical") mergedStyle += "; writing-mode: sideways-lr; text-orientation: mixed";
37954
+ mergedStyle += `; ${getTableCellTextWrapStyle(textWrap)}`;
37840
37955
  mergedStyle = mergedStyle.replace(/^;/, "").trim();
37841
37956
  return [
37842
37957
  "th",
37843
- (0, import_core19.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, getFormulaStateAttributes(HTMLAttributes), mergedStyle ? { style: mergedStyle } : {}),
37958
+ (0, import_core20.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, getFormulaStateAttributes(HTMLAttributes), mergedStyle ? { style: mergedStyle } : {}),
37844
37959
  0
37845
37960
  ];
37846
37961
  }
@@ -37848,15 +37963,15 @@ var CustomTableHeader = import_extension_table_header.TableHeader.extend({
37848
37963
  var CustomTaskList = import_extension_task_list.TaskList.extend({
37849
37964
  addInputRules() {
37850
37965
  return [
37851
- (0, import_core20.wrappingInputRule)({
37966
+ (0, import_core21.wrappingInputRule)({
37852
37967
  find: /^\s*(\[ \]|\[\])\s$/,
37853
37968
  type: this.type
37854
37969
  }),
37855
- (0, import_core20.wrappingInputRule)({
37970
+ (0, import_core21.wrappingInputRule)({
37856
37971
  find: /^\s*(-\s*\[ \]|-\s*\[\])\s$/,
37857
37972
  type: this.type
37858
37973
  }),
37859
- (0, import_core20.wrappingInputRule)({
37974
+ (0, import_core21.wrappingInputRule)({
37860
37975
  find: /^\s*(\*\s*\[ \]|-\s*\[\])\s$/,
37861
37976
  type: this.type
37862
37977
  })
@@ -38002,7 +38117,8 @@ function buildUEditorExtensions({
38002
38117
  handleWidth: 10,
38003
38118
  allowTableNodeSelection: true,
38004
38119
  HTMLAttributes: {
38005
- class: "border-collapse my-4"
38120
+ class: "border-collapse my-4",
38121
+ style: "table-layout: fixed;"
38006
38122
  }
38007
38123
  }),
38008
38124
  table_row_default,
@@ -38415,6 +38531,7 @@ var BubbleMenuContent = ({
38415
38531
  const [activeBorderPosition, setActiveBorderPosition] = (0, import_react75.useState)("all");
38416
38532
  const currentCellVerticalAlign = normalizeStyleValue(editor.getAttributes("tableCell").verticalAlign || editor.getAttributes("tableHeader").verticalAlign) || "";
38417
38533
  const currentCellTextDirection = normalizeStyleValue(editor.getAttributes("tableCell").textDirection || editor.getAttributes("tableHeader").textDirection) || "horizontal";
38534
+ const currentCellTextWrap = normalizeStyleValue(editor.getAttributes("tableCell").textWrap || editor.getAttributes("tableHeader").textWrap) || "wrap";
38418
38535
  const isInTable3 = (0, import_tables8.isInTable)(editor.state);
38419
38536
  const canMergeCells = isInTable3 && editor.can().mergeCells();
38420
38537
  const canSplitCell = isInTable3 && editor.can().splitCell();
@@ -39075,6 +39192,20 @@ var BubbleMenuContent = ({
39075
39192
  children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_lucide_react53.TableCellsMerge, { className: "w-4 h-4" })
39076
39193
  }
39077
39194
  ),
39195
+ /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(
39196
+ ToolbarButton,
39197
+ {
39198
+ onClick: () => applyTableCellAttribute2(
39199
+ editor,
39200
+ "textWrap",
39201
+ currentCellTextWrap === "nowrap" ? "wrap" : "nowrap",
39202
+ { focus: false }
39203
+ ),
39204
+ active: currentCellTextWrap !== "nowrap",
39205
+ title: currentCellTextWrap === "nowrap" ? t("tableMenu.wrapText") : t("tableMenu.noWrapText"),
39206
+ children: /* @__PURE__ */ (0, import_jsx_runtime94.jsx)(import_lucide_react53.WrapText, { className: "h-4 w-4" })
39207
+ }
39208
+ ),
39078
39209
  /* @__PURE__ */ (0, import_jsx_runtime94.jsxs)(
39079
39210
  DropdownMenu,
39080
39211
  {
@@ -44299,6 +44430,22 @@ function buildLogicalRowMetrics({
44299
44430
  };
44300
44431
  });
44301
44432
  }
44433
+ function getTableCellTextSelectionRange(editor, cellPos) {
44434
+ const cellNode = editor.state.doc.nodeAt(cellPos);
44435
+ if (!cellNode || cellNode.type.name !== "tableCell" && cellNode.type.name !== "tableHeader") {
44436
+ return null;
44437
+ }
44438
+ let from = null;
44439
+ let to = null;
44440
+ cellNode.descendants((node, relativePos) => {
44441
+ if (!node.isText || node.nodeSize === 0) return true;
44442
+ const textStart = cellPos + 1 + relativePos;
44443
+ from ?? (from = textStart);
44444
+ to = textStart + node.nodeSize;
44445
+ return true;
44446
+ });
44447
+ return from !== null && to !== null && from < to ? { from, to } : null;
44448
+ }
44302
44449
  function buildTableControlLayout(editor, surface, cell) {
44303
44450
  const row = cell.closest("tr");
44304
44451
  const table = cell.closest("table");
@@ -44404,6 +44551,9 @@ function buildTableHoverState({
44404
44551
  layout,
44405
44552
  surface
44406
44553
  }) {
44554
+ if (event.buttons !== 0) {
44555
+ return DEFAULT_TABLE_HOVER_STATE;
44556
+ }
44407
44557
  const surfaceRect = surface.getBoundingClientRect();
44408
44558
  const relativeX = event.clientX - surfaceRect.left + surface.scrollLeft;
44409
44559
  const relativeY = event.clientY - surfaceRect.top + surface.scrollTop;
@@ -44413,8 +44563,8 @@ function buildTableHoverState({
44413
44563
  const directTableMenu = targetElement?.closest?.("[data-table-control='table-menu']");
44414
44564
  const directAddColumn = targetElement?.closest?.("[data-table-control='add-column']");
44415
44565
  const directAddRow = targetElement?.closest?.("[data-table-control='add-row']");
44416
- const directRowHandleIndex = directRowHandle instanceof HTMLElement ? Number.parseInt(directRowHandle.dataset.rowHandleIndex ?? "", 10) : Number.NaN;
44417
- const directColumnHandleIndex = directColumnHandle instanceof HTMLElement ? Number.parseInt(directColumnHandle.dataset.columnHandleIndex ?? "", 10) : Number.NaN;
44566
+ const directRowHandleIndex = directRowHandle instanceof HTMLElement && relativeX <= layout.tableLeft ? Number.parseInt(directRowHandle.dataset.rowHandleIndex ?? "", 10) : Number.NaN;
44567
+ const directColumnHandleIndex = directColumnHandle instanceof HTMLElement && relativeY <= layout.tableTop ? Number.parseInt(directColumnHandle.dataset.columnHandleIndex ?? "", 10) : Number.NaN;
44418
44568
  const visibleBounds = getVisibleTableBounds(layout);
44419
44569
  const rowRailTop = layout.wrapperTop + layout.wrapperHeight;
44420
44570
  const isMouseInTable = relativeX >= layout.tableLeft && relativeX <= layout.tableLeft + layout.tableWidth && relativeY >= layout.tableTop && relativeY <= layout.tableTop + layout.tableHeight;
@@ -44733,7 +44883,8 @@ function TableRowHandles({
44733
44883
  "data-row-handle-index": rowHandle.index,
44734
44884
  style: {
44735
44885
  top: Math.max(8, rowHandle.center - 12),
44736
- left: rowHandleLeft
44886
+ left: rowHandleLeft,
44887
+ pointerEvents: visible ? "auto" : "none"
44737
44888
  },
44738
44889
  children: /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(
44739
44890
  Tooltip,
@@ -44766,7 +44917,10 @@ function TableRowHandles({
44766
44917
  style: {
44767
44918
  opacity: isShown ? 1 : 0,
44768
44919
  transform: isShown ? "scale(1)" : `scale(${IDLE_HANDLE_SCALE})`,
44769
- pointerEvents: isShown ? "auto" : "none"
44920
+ // The idle marker is only a location hint. Keeping it
44921
+ // pointer-transparent prevents it from stealing a text
44922
+ // selection near the first character of a table cell.
44923
+ pointerEvents: visible ? "auto" : "none"
44770
44924
  },
44771
44925
  children: visible ? /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(import_lucide_react55.GripVertical, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ (0, import_jsx_runtime99.jsx)("div", { className: "h-3 w-1 rounded-full bg-muted-foreground/50 hover:bg-muted-foreground" })
44772
44926
  }
@@ -44804,7 +44958,8 @@ function TableColumnHandles({
44804
44958
  "data-column-handle-index": columnHandle.index,
44805
44959
  style: {
44806
44960
  top: columnHandleTop,
44807
- left: Math.max(8, columnHandle.center - 12)
44961
+ left: Math.max(8, columnHandle.center - 12),
44962
+ pointerEvents: visible ? "auto" : "none"
44808
44963
  },
44809
44964
  children: /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(
44810
44965
  Tooltip,
@@ -44837,7 +44992,7 @@ function TableColumnHandles({
44837
44992
  style: {
44838
44993
  opacity: isShown ? 1 : 0,
44839
44994
  transform: isShown ? "scale(1)" : `scale(${IDLE_HANDLE_SCALE})`,
44840
- pointerEvents: isShown ? "auto" : "none"
44995
+ pointerEvents: visible ? "auto" : "none"
44841
44996
  },
44842
44997
  children: visible ? /* @__PURE__ */ (0, import_jsx_runtime99.jsx)(import_lucide_react55.GripHorizontal, { className: "h-3.5 w-3.5" }) : /* @__PURE__ */ (0, import_jsx_runtime99.jsx)("div", { className: "h-1 w-3 rounded-full bg-muted-foreground/50 hover:bg-muted-foreground" })
44843
44998
  }
@@ -45085,6 +45240,7 @@ function applyTableSize(editor, snapshot, dimensions) {
45085
45240
  // src/components/UEditor/table-controls.tsx
45086
45241
  var import_jsx_runtime101 = require("react/jsx-runtime");
45087
45242
  var TABLE_MENU_TOP_OFFSET = 10;
45243
+ var AXIS_HANDLE_RADIUS = 12;
45088
45244
  function nearestIndex(centers, position) {
45089
45245
  let bestIndex = 0;
45090
45246
  let bestDistance = Number.POSITIVE_INFINITY;
@@ -45262,6 +45418,20 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
45262
45418
  const surface2 = containerRef.current;
45263
45419
  const nextLayout = surface2 ? buildTableControlLayout(editor, surface2, cell) : null;
45264
45420
  if (!nextLayout) return;
45421
+ if (isPointOverRenderedText(cell, event.clientX, event.clientY)) {
45422
+ const textSelection = getTableCellTextSelectionRange(editor, nextLayout.cellPos);
45423
+ if (textSelection) {
45424
+ event.preventDefault();
45425
+ const didSelectText = editor.commands.setTextSelection(textSelection);
45426
+ if (didSelectText) {
45427
+ editor.view.focus();
45428
+ layoutRef.current = nextLayout;
45429
+ setLayout(nextLayout);
45430
+ setHoverState(DEFAULT_TABLE_HOVER_STATE);
45431
+ return;
45432
+ }
45433
+ }
45434
+ }
45265
45435
  const didSelect = editor.commands.setCellSelection({
45266
45436
  anchorCell: nextLayout.cellPos,
45267
45437
  headCell: nextLayout.cellPos
@@ -45728,8 +45898,8 @@ function TableControls({ editor, containerRef, showCellInspector = true }) {
45728
45898
  }
45729
45899
  const menuTop = Math.max(8, layout.tableTop - TABLE_MENU_TOP_OFFSET);
45730
45900
  const menuLeft = Math.max(8, layout.tableLeft);
45731
- const rowHandleLeft = layout.tableLeft - 12;
45732
- const columnHandleTop = layout.tableTop - 12;
45901
+ const rowHandleLeft = layout.tableLeft - AXIS_HANDLE_RADIUS;
45902
+ const columnHandleTop = layout.tableTop - AXIS_HANDLE_RADIUS;
45733
45903
  return /* @__PURE__ */ (0, import_jsx_runtime101.jsxs)(import_jsx_runtime101.Fragment, { children: [
45734
45904
  /* @__PURE__ */ (0, import_jsx_runtime101.jsx)(
45735
45905
  TableRowHandles,
@@ -46916,6 +47086,73 @@ function TableFormulaBar({ editor }) {
46916
47086
  );
46917
47087
  }
46918
47088
 
47089
+ // src/components/UEditor/use-editor-output.ts
47090
+ var React91 = __toESM(require("react"), 1);
47091
+ function normalizeDebounceMs(value) {
47092
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
47093
+ }
47094
+ function useUEditorOutput({
47095
+ onChange,
47096
+ onHtmlChange,
47097
+ onJsonChange,
47098
+ outputDebounceMs
47099
+ }) {
47100
+ const callbacksRef = React91.useRef({});
47101
+ const pendingEditorRef = React91.useRef(null);
47102
+ const timeoutRef = React91.useRef(null);
47103
+ const debounceMs = normalizeDebounceMs(outputDebounceMs);
47104
+ callbacksRef.current = { onChange, onHtmlChange, onJsonChange };
47105
+ const flushOutputUpdates = React91.useCallback(() => {
47106
+ if (timeoutRef.current !== null) {
47107
+ clearTimeout(timeoutRef.current);
47108
+ timeoutRef.current = null;
47109
+ }
47110
+ const editor = pendingEditorRef.current;
47111
+ pendingEditorRef.current = null;
47112
+ if (!editor || editor.isDestroyed) return;
47113
+ const callbacks = callbacksRef.current;
47114
+ if (callbacks.onChange || callbacks.onHtmlChange) {
47115
+ const html = editor.getHTML();
47116
+ callbacks.onChange?.(html);
47117
+ callbacks.onHtmlChange?.(html);
47118
+ }
47119
+ if (callbacks.onJsonChange) {
47120
+ callbacks.onJsonChange(editor.getJSON());
47121
+ }
47122
+ }, []);
47123
+ const scheduleOutputUpdate = React91.useCallback((editor) => {
47124
+ const callbacks = callbacksRef.current;
47125
+ if (!callbacks.onChange && !callbacks.onHtmlChange && !callbacks.onJsonChange) return;
47126
+ pendingEditorRef.current = editor;
47127
+ if (timeoutRef.current !== null) {
47128
+ clearTimeout(timeoutRef.current);
47129
+ timeoutRef.current = null;
47130
+ }
47131
+ if (debounceMs === 0) {
47132
+ flushOutputUpdates();
47133
+ return;
47134
+ }
47135
+ timeoutRef.current = setTimeout(flushOutputUpdates, debounceMs);
47136
+ }, [debounceMs, flushOutputUpdates]);
47137
+ React91.useEffect(() => {
47138
+ if (!pendingEditorRef.current || timeoutRef.current === null) return;
47139
+ clearTimeout(timeoutRef.current);
47140
+ timeoutRef.current = debounceMs === 0 ? null : setTimeout(flushOutputUpdates, debounceMs);
47141
+ if (debounceMs === 0) flushOutputUpdates();
47142
+ }, [debounceMs, flushOutputUpdates]);
47143
+ React91.useEffect(() => () => {
47144
+ if (timeoutRef.current !== null) {
47145
+ clearTimeout(timeoutRef.current);
47146
+ timeoutRef.current = null;
47147
+ }
47148
+ pendingEditorRef.current = null;
47149
+ }, []);
47150
+ return {
47151
+ flushOutputUpdates,
47152
+ scheduleOutputUpdate
47153
+ };
47154
+ }
47155
+
46919
47156
  // src/components/UEditor/UEditor.tsx
46920
47157
  var import_jsx_runtime104 = require("react/jsx-runtime");
46921
47158
  var LazyMenuBar = import_react84.default.lazy(async () => {
@@ -46927,6 +47164,7 @@ var UEditor = import_react84.default.forwardRef(({
46927
47164
  onChange,
46928
47165
  onHtmlChange,
46929
47166
  onJsonChange,
47167
+ outputDebounceMs = 0,
46930
47168
  uploadImage,
46931
47169
  uploadImageForSave,
46932
47170
  uploadImageConcurrency = 3,
@@ -46972,6 +47210,12 @@ var UEditor = import_react84.default.forwardRef(({
46972
47210
  const formulaRangePickRef = (0, import_react84.useRef)(null);
46973
47211
  const formulaRangeSurfaceRef = (0, import_react84.useRef)(null);
46974
47212
  const [formulaRangeHighlight, setFormulaRangeHighlight] = import_react84.default.useState(null);
47213
+ const { flushOutputUpdates, scheduleOutputUpdate } = useUEditorOutput({
47214
+ onChange,
47215
+ onHtmlChange,
47216
+ onJsonChange,
47217
+ outputDebounceMs
47218
+ });
46975
47219
  const scheduleFormulaRecalculate = import_react84.default.useCallback((editor2, options) => {
46976
47220
  if (editor2.isDestroyed || scheduledFormulaRecalculateRef.current) return;
46977
47221
  if (!options?.force && isEditingTableFormulaText(editor2)) return;
@@ -47113,14 +47357,7 @@ var UEditor = import_react84.default.forwardRef(({
47113
47357
  pendingFormulaTextRecalculateRef.current = false;
47114
47358
  }
47115
47359
  }
47116
- if (onChange || onHtmlChange) {
47117
- const html = editor2.getHTML();
47118
- onChange?.(html);
47119
- onHtmlChange?.(html);
47120
- }
47121
- if (onJsonChange) {
47122
- onJsonChange(editor2.getJSON());
47123
- }
47360
+ scheduleOutputUpdate(editor2);
47124
47361
  },
47125
47362
  onSelectionUpdate: ({ editor: editor2 }) => {
47126
47363
  if (pendingFormulaTextRecalculateRef.current && !isEditingTableFormulaText(editor2)) {
@@ -47134,6 +47371,7 @@ var UEditor = import_react84.default.forwardRef(({
47134
47371
  const shouldRecalculate = pendingFormulaTextRecalculateRef.current;
47135
47372
  pendingFormulaTextRecalculateRef.current = false;
47136
47373
  if (shouldRecalculate) scheduleFormulaRecalculate(editor2, { force: true });
47374
+ queueMicrotask(flushOutputUpdates);
47137
47375
  }
47138
47376
  });
47139
47377
  (0, import_react84.useEffect)(() => {