@fileverse-dev/fortune-react 1.3.11-input-ref → 1.3.11-input-ref-2
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/es/components/ContextMenu/index.js +1 -1
- package/es/components/FxEditor/index.js +296 -55
- package/es/components/SheetOverlay/FormulaHint/index.js +46 -25
- package/es/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
- package/es/components/SheetOverlay/FormulaSearch/index.js +58 -29
- package/es/components/SheetOverlay/InputBox.js +164 -69
- package/es/components/SheetOverlay/helper.d.ts +2 -0
- package/es/components/SheetOverlay/helper.js +43 -0
- package/es/components/SheetOverlay/index.css +4 -4
- package/es/components/SheetOverlay/index.js +9 -2
- package/es/components/Workbook/index.js +2 -2
- package/es/hooks/useFormulaEditorHistory.d.ts +24 -0
- package/es/hooks/useFormulaEditorHistory.js +119 -0
- package/es/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
- package/es/hooks/useRerenderOnFormulaCaret.js +28 -0
- package/lib/components/ContextMenu/index.js +1 -1
- package/lib/components/FxEditor/index.js +294 -53
- package/lib/components/SheetOverlay/FormulaHint/index.js +45 -24
- package/lib/components/SheetOverlay/FormulaSearch/index.d.ts +3 -1
- package/lib/components/SheetOverlay/FormulaSearch/index.js +57 -28
- package/lib/components/SheetOverlay/InputBox.js +162 -67
- package/lib/components/SheetOverlay/helper.d.ts +2 -0
- package/lib/components/SheetOverlay/helper.js +45 -0
- package/lib/components/SheetOverlay/index.css +4 -4
- package/lib/components/SheetOverlay/index.js +8 -1
- package/lib/components/Workbook/index.js +2 -2
- package/lib/hooks/useFormulaEditorHistory.d.ts +24 -0
- package/lib/hooks/useFormulaEditorHistory.js +126 -0
- package/lib/hooks/useRerenderOnFormulaCaret.d.ts +2 -0
- package/lib/hooks/useRerenderOnFormulaCaret.js +34 -0
- package/package.json +2 -2
|
@@ -336,9 +336,9 @@
|
|
|
336
336
|
overflow: hidden;
|
|
337
337
|
white-space: pre-wrap;
|
|
338
338
|
outline: none;
|
|
339
|
-
-webkit-box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
|
|
340
|
-
-moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
|
|
341
|
-
box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
|
|
339
|
+
/* -webkit-box-shadow: 0 2px 5px rgb(0 0 0 / 40%);
|
|
340
|
+
-moz-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); */
|
|
341
|
+
/* box-shadow: 0 2px 5px rgb(0 0 0 / 40%); */
|
|
342
342
|
word-wrap: break-word;
|
|
343
343
|
background-color: rgb(255, 255, 255);
|
|
344
344
|
font-size: 13px;
|
|
@@ -356,7 +356,7 @@
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
.luckysheet-formula-text-color {
|
|
359
|
-
color:
|
|
359
|
+
color: darkred;
|
|
360
360
|
}
|
|
361
361
|
|
|
362
362
|
.luckysheet-formula-text-string {
|
|
@@ -58,6 +58,7 @@ var SheetOverlay = function SheetOverlay() {
|
|
|
58
58
|
setContext(function (draftCtx) {
|
|
59
59
|
var _a;
|
|
60
60
|
(0, _fortuneCore.handleCellAreaMouseDown)(draftCtx, refs.globalCache, nativeEvent, refs.cellInput.current, refs.cellArea.current, refs.fxInput.current, refs.canvas.current.getContext("2d"));
|
|
61
|
+
var keepFormulaBarFocused = draftCtx.luckysheetCellUpdate.length > 0 && draftCtx.formulaCache.formulaEditorOwner === "fx" && (draftCtx.formulaCache.rangestart || draftCtx.formulaCache.rangedrag_column_start || draftCtx.formulaCache.rangedrag_row_start || (0, _fortuneCore.israngeseleciton)(draftCtx));
|
|
61
62
|
if (!_lodash.default.isEmpty((_a = draftCtx.luckysheet_select_save) === null || _a === void 0 ? void 0 : _a[0]) && refs.cellInput.current) {
|
|
62
63
|
if (!(0, _fortuneCore.isAllowEdit)(draftCtx)) {
|
|
63
64
|
setTimeout(function () {
|
|
@@ -69,7 +70,13 @@ var SheetOverlay = function SheetOverlay() {
|
|
|
69
70
|
} else {
|
|
70
71
|
setTimeout(function () {
|
|
71
72
|
var _a;
|
|
72
|
-
(
|
|
73
|
+
if (keepFormulaBarFocused && refs.fxInput.current) {
|
|
74
|
+
refs.fxInput.current.focus({
|
|
75
|
+
preventScroll: true
|
|
76
|
+
});
|
|
77
|
+
} else {
|
|
78
|
+
(_a = refs.cellInput.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
79
|
+
}
|
|
73
80
|
});
|
|
74
81
|
}
|
|
75
82
|
}
|
|
@@ -887,7 +887,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
887
887
|
});
|
|
888
888
|
}
|
|
889
889
|
var nativeEvent = e.nativeEvent;
|
|
890
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
|
|
890
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ" && context.luckysheetCellUpdate.length === 0) {
|
|
891
891
|
if (e.shiftKey) {
|
|
892
892
|
handleRedo();
|
|
893
893
|
} else {
|
|
@@ -896,7 +896,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
896
896
|
e.stopPropagation();
|
|
897
897
|
return;
|
|
898
898
|
}
|
|
899
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY") {
|
|
899
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY" && context.luckysheetCellUpdate.length === 0) {
|
|
900
900
|
handleRedo();
|
|
901
901
|
e.stopPropagation();
|
|
902
902
|
e.preventDefault();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import { type Context } from "@fileverse-dev/fortune-core";
|
|
3
|
+
import type { SetContextOptions } from "../context";
|
|
4
|
+
export type FormulaHistoryEntry = {
|
|
5
|
+
text: string;
|
|
6
|
+
caret: number;
|
|
7
|
+
spanValues: string[];
|
|
8
|
+
};
|
|
9
|
+
export type FormulaEditorHistoryPrimary = "cell" | "fx";
|
|
10
|
+
type SetContext = (recipe: (ctx: Context) => void, options?: SetContextOptions) => void;
|
|
11
|
+
export declare function useFormulaEditorHistory(primaryRef: RefObject<HTMLDivElement | null>, cellInputRef: RefObject<HTMLDivElement | null>, fxInputRef: RefObject<HTMLDivElement | null>, setContext: SetContext, primary: FormulaEditorHistoryPrimary): {
|
|
12
|
+
formulaHistoryRef: RefObject<{
|
|
13
|
+
active: boolean;
|
|
14
|
+
entries: FormulaHistoryEntry[];
|
|
15
|
+
index: number;
|
|
16
|
+
}>;
|
|
17
|
+
preTextRef: RefObject<string>;
|
|
18
|
+
preFormulaSpanValuesRef: RefObject<string[] | null>;
|
|
19
|
+
resetFormulaHistory: () => void;
|
|
20
|
+
handleFormulaHistoryUndoRedo: (isRedo: boolean) => boolean;
|
|
21
|
+
capturePreFormulaState: () => void;
|
|
22
|
+
appendFormulaHistoryFromPrimaryEditor: (getCaret: () => number) => void;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useFormulaEditorHistory = useFormulaEditorHistory;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
9
|
+
var _fortuneCore = require("@fileverse-dev/fortune-core");
|
|
10
|
+
var _helper = require("../components/SheetOverlay/helper");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
var MAX_FORMULA_HISTORY = 100;
|
|
13
|
+
function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, setContext, primary) {
|
|
14
|
+
var preTextRef = (0, _react.useRef)("");
|
|
15
|
+
var preFormulaSpanValuesRef = (0, _react.useRef)(null);
|
|
16
|
+
var formulaHistoryRef = (0, _react.useRef)({
|
|
17
|
+
active: false,
|
|
18
|
+
entries: [],
|
|
19
|
+
index: -1
|
|
20
|
+
});
|
|
21
|
+
var resetFormulaHistory = (0, _react.useCallback)(function () {
|
|
22
|
+
formulaHistoryRef.current = {
|
|
23
|
+
active: false,
|
|
24
|
+
entries: [],
|
|
25
|
+
index: -1
|
|
26
|
+
};
|
|
27
|
+
preFormulaSpanValuesRef.current = null;
|
|
28
|
+
}, []);
|
|
29
|
+
var pushFormulaHistoryEntry = (0, _react.useCallback)(function (entry) {
|
|
30
|
+
var history = formulaHistoryRef.current;
|
|
31
|
+
var current = history.entries[history.index];
|
|
32
|
+
if (current && current.spanValues.length > 0 && entry.spanValues.length > 0 && _lodash.default.isEqual(current.spanValues, entry.spanValues)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (current && current.spanValues.length === 0 && entry.spanValues.length === 0 && current.text === entry.text && current.caret === entry.caret) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
var nextEntries = history.entries.slice(0, history.index + 1);
|
|
39
|
+
nextEntries.push(entry);
|
|
40
|
+
if (nextEntries.length > MAX_FORMULA_HISTORY) {
|
|
41
|
+
nextEntries.shift();
|
|
42
|
+
}
|
|
43
|
+
history.entries = nextEntries;
|
|
44
|
+
history.index = nextEntries.length - 1;
|
|
45
|
+
history.active = true;
|
|
46
|
+
}, []);
|
|
47
|
+
var applyFormulaHistoryEntry = (0, _react.useCallback)(function (entry) {
|
|
48
|
+
var primaryEl = primaryRef.current;
|
|
49
|
+
if (!primaryEl) return;
|
|
50
|
+
var safeText = (0, _fortuneCore.escapeScriptTag)(entry.text || "");
|
|
51
|
+
var html = safeText.startsWith("=") ? (0, _fortuneCore.functionHTMLGenerate)(safeText) : (0, _fortuneCore.escapeHTMLTag)(safeText);
|
|
52
|
+
var cell = cellInputRef.current;
|
|
53
|
+
var fx = fxInputRef.current;
|
|
54
|
+
primaryEl.innerHTML = html;
|
|
55
|
+
if (primary === "cell") {
|
|
56
|
+
if (fx) fx.innerHTML = html;
|
|
57
|
+
} else if (cell) {
|
|
58
|
+
cell.innerHTML = html;
|
|
59
|
+
}
|
|
60
|
+
(0, _helper.setCursorPosition)(primaryEl, Math.min(entry.caret, entry.text.length));
|
|
61
|
+
setContext(function (draftCtx) {
|
|
62
|
+
if (primary === "cell") {
|
|
63
|
+
if (!cellInputRef.current) return;
|
|
64
|
+
(0, _fortuneCore.handleFormulaInput)(draftCtx, fxInputRef.current, cellInputRef.current, 0);
|
|
65
|
+
} else {
|
|
66
|
+
if (!fxInputRef.current) return;
|
|
67
|
+
(0, _fortuneCore.handleFormulaInput)(draftCtx, cellInputRef.current, fxInputRef.current, 0);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}, [cellInputRef, fxInputRef, primary, primaryRef, setContext]);
|
|
71
|
+
var handleFormulaHistoryUndoRedo = (0, _react.useCallback)(function (isRedo) {
|
|
72
|
+
var history = formulaHistoryRef.current;
|
|
73
|
+
if (!history.active || history.entries.length === 0) return false;
|
|
74
|
+
var nextIndex = isRedo ? history.index + 1 : history.index - 1;
|
|
75
|
+
if (nextIndex < 0 || nextIndex >= history.entries.length) return true;
|
|
76
|
+
history.index = nextIndex;
|
|
77
|
+
applyFormulaHistoryEntry(history.entries[nextIndex]);
|
|
78
|
+
return true;
|
|
79
|
+
}, [applyFormulaHistoryEntry]);
|
|
80
|
+
var capturePreFormulaState = (0, _react.useCallback)(function () {
|
|
81
|
+
var el = primaryRef.current;
|
|
82
|
+
if (!el) return;
|
|
83
|
+
preTextRef.current = el.innerText;
|
|
84
|
+
preFormulaSpanValuesRef.current = Array.from(el.querySelectorAll("span.fortune-formula-functionrange-cell")).map(function (node) {
|
|
85
|
+
var _a;
|
|
86
|
+
return (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
|
|
87
|
+
});
|
|
88
|
+
}, [primaryRef]);
|
|
89
|
+
var appendFormulaHistoryFromPrimaryEditor = (0, _react.useCallback)(function (getCaret) {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
var el = primaryRef.current;
|
|
92
|
+
if (!el) return;
|
|
93
|
+
var currentText = el.innerText || "";
|
|
94
|
+
if (currentText.startsWith("=")) {
|
|
95
|
+
var caret = getCaret();
|
|
96
|
+
var spanValues = Array.from(el.querySelectorAll("span.fortune-formula-functionrange-cell")).map(function (node) {
|
|
97
|
+
var _a;
|
|
98
|
+
return (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
|
|
99
|
+
});
|
|
100
|
+
if (!formulaHistoryRef.current.active) {
|
|
101
|
+
var seedText = preTextRef.current || "";
|
|
102
|
+
pushFormulaHistoryEntry({
|
|
103
|
+
text: seedText,
|
|
104
|
+
caret: Math.min(caret, seedText.length),
|
|
105
|
+
spanValues: (_b = (_a = preFormulaSpanValuesRef.current) !== null && _a !== void 0 ? _a : spanValues) !== null && _b !== void 0 ? _b : []
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
pushFormulaHistoryEntry({
|
|
109
|
+
text: currentText,
|
|
110
|
+
caret: caret,
|
|
111
|
+
spanValues: spanValues
|
|
112
|
+
});
|
|
113
|
+
} else if (formulaHistoryRef.current.active) {
|
|
114
|
+
resetFormulaHistory();
|
|
115
|
+
}
|
|
116
|
+
}, [primaryRef, pushFormulaHistoryEntry, resetFormulaHistory]);
|
|
117
|
+
return {
|
|
118
|
+
formulaHistoryRef: formulaHistoryRef,
|
|
119
|
+
preTextRef: preTextRef,
|
|
120
|
+
preFormulaSpanValuesRef: preFormulaSpanValuesRef,
|
|
121
|
+
resetFormulaHistory: resetFormulaHistory,
|
|
122
|
+
handleFormulaHistoryUndoRedo: handleFormulaHistoryUndoRedo,
|
|
123
|
+
capturePreFormulaState: capturePreFormulaState,
|
|
124
|
+
appendFormulaHistoryFromPrimaryEditor: appendFormulaHistoryFromPrimaryEditor
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useRerenderOnFormulaCaret = useRerenderOnFormulaCaret;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
|
|
9
|
+
var _a = (0, _react.useState)(0),
|
|
10
|
+
bump = _a[1];
|
|
11
|
+
(0, _react.useEffect)(function () {
|
|
12
|
+
if (!editSessionActive) {
|
|
13
|
+
return function () {};
|
|
14
|
+
}
|
|
15
|
+
var onSelectionChange = function onSelectionChange() {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
var el = editorRef.current;
|
|
18
|
+
if (!el) return;
|
|
19
|
+
var text = (_b = (_a = el.innerText) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
|
|
20
|
+
if (!text.startsWith("=")) return;
|
|
21
|
+
var sel = window.getSelection();
|
|
22
|
+
if (!(sel === null || sel === void 0 ? void 0 : sel.rangeCount) || !el.contains(sel.getRangeAt(0).startContainer)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
bump(function (n) {
|
|
26
|
+
return n + 1;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
document.addEventListener("selectionchange", onSelectionChange);
|
|
30
|
+
return function () {
|
|
31
|
+
document.removeEventListener("selectionchange", onSelectionChange);
|
|
32
|
+
};
|
|
33
|
+
}, [editSessionActive, editorRef]);
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fileverse-dev/fortune-react",
|
|
3
|
-
"version": "1.3.11-input-ref",
|
|
3
|
+
"version": "1.3.11-input-ref-2",
|
|
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.11-input-ref",
|
|
19
|
+
"@fileverse-dev/fortune-core": "1.3.11-input-ref-2",
|
|
20
20
|
"@fileverse/ui": "5.0.0",
|
|
21
21
|
"@tippyjs/react": "^4.2.6",
|
|
22
22
|
"@types/regenerator-runtime": "^0.13.6",
|