@fileverse-dev/fortune-react 1.3.13-create-4 → 1.3.13-create-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,17 +15,6 @@ function normalizeEditorHtmlSnapshot(html) {
15
15
  }
16
16
  return html !== null && html !== void 0 ? html : "";
17
17
  }
18
- function historyForLog(entries, index) {
19
- return entries.map(function (e, i) {
20
- var _a, _b;
21
- return {
22
- i: i,
23
- active: i === index,
24
- len: ((_a = e.html) !== null && _a !== void 0 ? _a : "").length,
25
- preview: ((_b = e.html) !== null && _b !== void 0 ? _b : "").replace(/\s+/g, " ").slice(0, 24)
26
- };
27
- });
28
- }
29
18
  function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setContext, primary) {
30
19
  var preTextRef = (0, _react.useRef)("");
31
20
  var preHtmlRef = (0, _react.useRef)("");
@@ -51,11 +40,6 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
51
40
  var history = formulaHistoryRef.current;
52
41
  var current = history.entries[history.index];
53
42
  if (current && current.html === entry.html) {
54
- console.log("[Hist:pushSkipDuplicate]", {
55
- currentHtmlLen: current.html.length,
56
- entryHtmlLen: entry.html.length,
57
- index: history.index
58
- });
59
43
  return;
60
44
  }
61
45
  var nextEntries = history.entries.slice(0, history.index + 1);
@@ -64,16 +48,9 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
64
48
  history.entries = nextEntries;
65
49
  history.index = nextEntries.length - 1;
66
50
  history.active = true;
67
- console.log("[Hist:push]", {
68
- htmlLen: entry.html.length,
69
- caret: entry.caret,
70
- entriesLen: history.entries.length,
71
- index: history.index,
72
- entries: historyForLog(history.entries, history.index)
73
- });
74
51
  }, []);
75
52
  var applyFormulaHistoryEntry = (0, _react.useCallback)(function (entry, preserveSelection) {
76
- var _a, _b, _c, _d, _e;
53
+ var _a, _b, _c;
77
54
  var primaryEl = primaryRef.current;
78
55
  if (!primaryEl) return;
79
56
  isApplyingHistoryRef.current = true;
@@ -94,11 +71,6 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
94
71
  } else {
95
72
  (0, _helper.setCursorPosition)(primaryEl, Math.max(0, textLen));
96
73
  }
97
- console.log("[Hist:apply]", {
98
- entryHtmlLen: ((_d = entry.html) !== null && _d !== void 0 ? _d : "").length,
99
- afterHtmlLen: ((_e = primaryEl.innerHTML) !== null && _e !== void 0 ? _e : "").length,
100
- afterTextLen: textLen
101
- });
102
74
  requestAnimationFrame(function () {
103
75
  requestAnimationFrame(function () {
104
76
  setTimeout(function () {
@@ -108,22 +80,13 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
108
80
  });
109
81
  }, [cellInputRef, fxInputRef, primary, primaryRef]);
110
82
  var handleFormulaHistoryUndoRedo = (0, _react.useCallback)(function (isRedo) {
111
- var _a, _b, _c, _d;
83
+ var _a, _b;
112
84
  var history = formulaHistoryRef.current;
113
85
  if (!history.active || history.entries.length === 0) return false;
114
86
  var nextIndex = isRedo ? history.index + 1 : history.index - 1;
115
87
  if (nextIndex < 0 || nextIndex >= history.entries.length) {
116
- console.log("[Hist:undoRedoBoundary]", {
117
- isRedo: isRedo,
118
- index: history.index,
119
- entriesLen: history.entries.length,
120
- nextIndex: nextIndex,
121
- startedFromEmpty: startedFromEmptyRef.current,
122
- liveHtmlLen: normalizeEditorHtmlSnapshot((_b = (_a = primaryRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML) !== null && _b !== void 0 ? _b : "").length,
123
- entries: historyForLog(history.entries, history.index)
124
- });
125
88
  if (!isRedo && nextIndex < 0 && startedFromEmptyRef.current) {
126
- var liveHtml = normalizeEditorHtmlSnapshot((_d = (_c = primaryRef.current) === null || _c === void 0 ? void 0 : _c.innerHTML) !== null && _d !== void 0 ? _d : "");
89
+ var liveHtml = normalizeEditorHtmlSnapshot((_b = (_a = primaryRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML) !== null && _b !== void 0 ? _b : "");
127
90
  if (liveHtml !== "") {
128
91
  history.entries[0] = {
129
92
  html: "",
@@ -132,11 +95,6 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
132
95
  history.index = 0;
133
96
  var currentSelection_1 = primaryRef.current ? (0, _helper.getSelectionOffsets)(primaryRef.current) : undefined;
134
97
  applyFormulaHistoryEntry(history.entries[0], currentSelection_1);
135
- console.log("[Hist:undoRedoForcedEmpty]", {
136
- entriesLen: history.entries.length,
137
- index: history.index,
138
- entries: historyForLog(history.entries, history.index)
139
- });
140
98
  return true;
141
99
  }
142
100
  }
@@ -146,17 +104,10 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
146
104
  var entry = history.entries[nextIndex];
147
105
  var currentSelection = primaryRef.current ? (0, _helper.getSelectionOffsets)(primaryRef.current) : undefined;
148
106
  applyFormulaHistoryEntry(entry, currentSelection);
149
- console.log("[Hist:undoRedoApplied]", {
150
- isRedo: isRedo,
151
- nextIndex: nextIndex,
152
- entriesLen: history.entries.length,
153
- entryHtmlLen: entry.html.length,
154
- entries: historyForLog(history.entries, history.index)
155
- });
156
107
  return true;
157
108
  }, [applyFormulaHistoryEntry, primaryRef]);
158
109
  var capturePreEditorHistoryState = (0, _react.useCallback)(function () {
159
- var _a, _b, _c;
110
+ var _a;
160
111
  var el = primaryRef.current;
161
112
  if (!el) return;
162
113
  preTextRef.current = el.innerText;
@@ -165,15 +116,6 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
165
116
  if (!formulaHistoryRef.current.active) {
166
117
  startedFromEmptyRef.current = normalizeEditorHtmlSnapshot((_a = preHtmlRef.current) !== null && _a !== void 0 ? _a : "") === "";
167
118
  }
168
- console.log("[Hist:capturePre]", {
169
- preHtmlLen: ((_b = preHtmlRef.current) !== null && _b !== void 0 ? _b : "").length,
170
- preTextLen: ((_c = preTextRef.current) !== null && _c !== void 0 ? _c : "").length,
171
- preCaret: preCaretRef.current,
172
- startedFromEmpty: startedFromEmptyRef.current,
173
- historyActive: formulaHistoryRef.current.active,
174
- entriesLen: formulaHistoryRef.current.entries.length,
175
- index: formulaHistoryRef.current.index
176
- });
177
119
  }, [primaryRef]);
178
120
  var appendEditorHistoryFromPrimaryEditor = (0, _react.useCallback)(function (getCaret) {
179
121
  var _a, _b;
@@ -185,16 +127,6 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
185
127
  var caret = getCaret();
186
128
  var history = formulaHistoryRef.current;
187
129
  var wasInactive = !history.active || history.entries.length === 0;
188
- console.log("[Hist:appendStart]", {
189
- preHtmlLen: preHtmlSnapshot.length,
190
- currentHtmlLen: snapshotHtml.length,
191
- caret: caret,
192
- wasInactive: wasInactive,
193
- historyActive: history.active,
194
- entriesLen: history.entries.length,
195
- index: history.index,
196
- entries: historyForLog(history.entries, history.index)
197
- });
198
130
  if (wasInactive) {
199
131
  startedFromEmptyRef.current = preHtmlSnapshot === "";
200
132
  var seedHtml = preHtmlSnapshot === snapshotHtml ? "" : preHtmlSnapshot !== null && preHtmlSnapshot !== void 0 ? preHtmlSnapshot : "";
@@ -202,12 +134,6 @@ function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, _setConte
202
134
  html: seedHtml,
203
135
  caret: preCaretRef.current
204
136
  });
205
- } else {
206
- console.log("[Hist:seedSkippedAlreadyActive]", {
207
- index: history.index,
208
- entriesLen: history.entries.length,
209
- entries: historyForLog(history.entries, history.index)
210
- });
211
137
  }
212
138
  pushFormulaHistoryEntry({
213
139
  html: snapshotHtml,
@@ -1,2 +1,2 @@
1
1
  import { type RefObject } from "react";
2
- export declare function useRerenderOnFormulaCaret(editorRef: RefObject<HTMLDivElement | null>, editSessionActive: boolean): void;
2
+ export declare function useRerenderOnFormulaCaret(editorRef: RefObject<HTMLDivElement | null>, editSessionActive: boolean, onAfterCaretMove?: () => void): void;
@@ -5,15 +5,17 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useRerenderOnFormulaCaret = useRerenderOnFormulaCaret;
7
7
  var _react = require("react");
8
- function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
8
+ function useRerenderOnFormulaCaret(editorRef, editSessionActive, onAfterCaretMove) {
9
9
  var _a = (0, _react.useState)(0),
10
10
  bump = _a[1];
11
+ var onAfterCaretMoveRef = (0, _react.useRef)(onAfterCaretMove);
12
+ onAfterCaretMoveRef.current = onAfterCaretMove;
11
13
  (0, _react.useEffect)(function () {
12
14
  if (!editSessionActive) {
13
15
  return function () {};
14
16
  }
15
17
  var onSelectionChange = function onSelectionChange() {
16
- var _a, _b;
18
+ var _a, _b, _c;
17
19
  var el = editorRef.current;
18
20
  if (!el) return;
19
21
  var text = (_b = (_a = el.innerText) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
@@ -25,6 +27,7 @@ function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
25
27
  bump(function (n) {
26
28
  return n + 1;
27
29
  });
30
+ (_c = onAfterCaretMoveRef.current) === null || _c === void 0 ? void 0 : _c.call(onAfterCaretMoveRef);
28
31
  };
29
32
  document.addEventListener("selectionchange", onSelectionChange);
30
33
  return function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.3.13-create-4",
3
+ "version": "1.3.13-create-5",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "module": "es/index.js",
@@ -16,7 +16,7 @@
16
16
  "tsc": "tsc"
17
17
  },
18
18
  "dependencies": {
19
- "@fileverse-dev/fortune-core": "1.3.13-create-4",
19
+ "@fileverse-dev/fortune-core": "1.3.13-create-5",
20
20
  "@fileverse/ui": "5.0.0",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",