@underverse-ui/underverse 1.0.154 → 1.0.155

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "package": "@underverse-ui/underverse",
3
- "version": "1.0.154",
3
+ "version": "1.0.155",
4
4
  "sourceEntry": "src/index.ts",
5
5
  "totalExports": 232,
6
6
  "exports": [
package/dist/index.cjs CHANGED
@@ -30642,6 +30642,20 @@ function safeFindCell2(map, relativePos) {
30642
30642
  function getCellText(cellNode) {
30643
30643
  return cellNode.textBetween(0, cellNode.content.size, "\n").trim();
30644
30644
  }
30645
+ function getSelectionTableCellNode(editor) {
30646
+ const { $from } = editor.state.selection;
30647
+ for (let depth = $from.depth; depth > 0; depth -= 1) {
30648
+ const node = $from.node(depth);
30649
+ if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
30650
+ return node;
30651
+ }
30652
+ }
30653
+ return null;
30654
+ }
30655
+ function isEditingTableFormulaText(editor) {
30656
+ const cellNode = getSelectionTableCellNode(editor);
30657
+ return Boolean(cellNode && getCellText(cellNode).startsWith("="));
30658
+ }
30645
30659
  function createCellDisplayContent(cellNode, displayValue) {
30646
30660
  const paragraphType = cellNode.type.schema.nodes.paragraph;
30647
30661
  if (!paragraphType || !displayValue) {
@@ -38907,6 +38921,17 @@ var UEditor = import_react71.default.forwardRef(({
38907
38921
  const inFlightPrepareRef = (0, import_react71.useRef)(null);
38908
38922
  const lastAppliedContentRef = (0, import_react71.useRef)(content ?? "");
38909
38923
  const scheduledFormulaRecalculateRef = (0, import_react71.useRef)(false);
38924
+ const scheduleFormulaRecalculate = import_react71.default.useCallback((editor2, options) => {
38925
+ if (editor2.isDestroyed || scheduledFormulaRecalculateRef.current) return;
38926
+ if (!options?.force && isEditingTableFormulaText(editor2)) return;
38927
+ scheduledFormulaRecalculateRef.current = true;
38928
+ queueMicrotask(() => {
38929
+ scheduledFormulaRecalculateRef.current = false;
38930
+ if (!editor2.isDestroyed && (options?.force || !isEditingTableFormulaText(editor2))) {
38931
+ recalculateAllTableFormulas(editor2);
38932
+ }
38933
+ });
38934
+ }, []);
38910
38935
  const resolvedUploadFile = (0, import_react71.useMemo)(() => {
38911
38936
  if (uploadFile) return uploadFile;
38912
38937
  if (uploadFileForSave) {
@@ -38971,19 +38996,19 @@ var UEditor = import_react71.default.forwardRef(({
38971
38996
  }
38972
38997
  },
38973
38998
  onUpdate: ({ editor: editor2, transaction }) => {
38974
- if (!transaction.getMeta(UEDITOR_TABLE_FORMULA_RECALCULATE_META) && !scheduledFormulaRecalculateRef.current) {
38975
- scheduledFormulaRecalculateRef.current = true;
38976
- queueMicrotask(() => {
38977
- scheduledFormulaRecalculateRef.current = false;
38978
- if (!editor2.isDestroyed) {
38979
- recalculateAllTableFormulas(editor2);
38980
- }
38981
- });
38999
+ if (!transaction.getMeta(UEDITOR_TABLE_FORMULA_RECALCULATE_META)) {
39000
+ scheduleFormulaRecalculate(editor2);
38982
39001
  }
38983
39002
  const html = editor2.getHTML();
38984
39003
  onChange?.(html);
38985
39004
  onHtmlChange?.(html);
38986
39005
  onJsonChange?.(editor2.getJSON());
39006
+ },
39007
+ onSelectionUpdate: ({ editor: editor2 }) => {
39008
+ scheduleFormulaRecalculate(editor2);
39009
+ },
39010
+ onBlur: ({ editor: editor2 }) => {
39011
+ scheduleFormulaRecalculate(editor2, { force: true });
38987
39012
  }
38988
39013
  });
38989
39014
  const {