@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.
package/dist/index.js CHANGED
@@ -30547,6 +30547,20 @@ function safeFindCell2(map, relativePos) {
30547
30547
  function getCellText(cellNode) {
30548
30548
  return cellNode.textBetween(0, cellNode.content.size, "\n").trim();
30549
30549
  }
30550
+ function getSelectionTableCellNode(editor) {
30551
+ const { $from } = editor.state.selection;
30552
+ for (let depth = $from.depth; depth > 0; depth -= 1) {
30553
+ const node = $from.node(depth);
30554
+ if (node.type.name === "tableCell" || node.type.name === "tableHeader") {
30555
+ return node;
30556
+ }
30557
+ }
30558
+ return null;
30559
+ }
30560
+ function isEditingTableFormulaText(editor) {
30561
+ const cellNode = getSelectionTableCellNode(editor);
30562
+ return Boolean(cellNode && getCellText(cellNode).startsWith("="));
30563
+ }
30550
30564
  function createCellDisplayContent(cellNode, displayValue) {
30551
30565
  const paragraphType = cellNode.type.schema.nodes.paragraph;
30552
30566
  if (!paragraphType || !displayValue) {
@@ -38851,6 +38865,17 @@ var UEditor = React83.forwardRef(({
38851
38865
  const inFlightPrepareRef = useRef37(null);
38852
38866
  const lastAppliedContentRef = useRef37(content ?? "");
38853
38867
  const scheduledFormulaRecalculateRef = useRef37(false);
38868
+ const scheduleFormulaRecalculate = React83.useCallback((editor2, options) => {
38869
+ if (editor2.isDestroyed || scheduledFormulaRecalculateRef.current) return;
38870
+ if (!options?.force && isEditingTableFormulaText(editor2)) return;
38871
+ scheduledFormulaRecalculateRef.current = true;
38872
+ queueMicrotask(() => {
38873
+ scheduledFormulaRecalculateRef.current = false;
38874
+ if (!editor2.isDestroyed && (options?.force || !isEditingTableFormulaText(editor2))) {
38875
+ recalculateAllTableFormulas(editor2);
38876
+ }
38877
+ });
38878
+ }, []);
38854
38879
  const resolvedUploadFile = useMemo24(() => {
38855
38880
  if (uploadFile) return uploadFile;
38856
38881
  if (uploadFileForSave) {
@@ -38915,19 +38940,19 @@ var UEditor = React83.forwardRef(({
38915
38940
  }
38916
38941
  },
38917
38942
  onUpdate: ({ editor: editor2, transaction }) => {
38918
- if (!transaction.getMeta(UEDITOR_TABLE_FORMULA_RECALCULATE_META) && !scheduledFormulaRecalculateRef.current) {
38919
- scheduledFormulaRecalculateRef.current = true;
38920
- queueMicrotask(() => {
38921
- scheduledFormulaRecalculateRef.current = false;
38922
- if (!editor2.isDestroyed) {
38923
- recalculateAllTableFormulas(editor2);
38924
- }
38925
- });
38943
+ if (!transaction.getMeta(UEDITOR_TABLE_FORMULA_RECALCULATE_META)) {
38944
+ scheduleFormulaRecalculate(editor2);
38926
38945
  }
38927
38946
  const html = editor2.getHTML();
38928
38947
  onChange?.(html);
38929
38948
  onHtmlChange?.(html);
38930
38949
  onJsonChange?.(editor2.getJSON());
38950
+ },
38951
+ onSelectionUpdate: ({ editor: editor2 }) => {
38952
+ scheduleFormulaRecalculate(editor2);
38953
+ },
38954
+ onBlur: ({ editor: editor2 }) => {
38955
+ scheduleFormulaRecalculate(editor2, { force: true });
38931
38956
  }
38932
38957
  });
38933
38958
  const {