@fileverse-dev/fortune-react 1.3.12 → 1.3.13-create-1
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/ConditionFormat/ConditionRules.js +15 -5
- package/es/components/ConditionFormat/index.js +3 -0
- package/es/components/ContextMenu/index.js +1 -1
- package/es/components/DataVerification/ColorPicker.js +1 -1
- package/es/components/FxEditor/index.js +316 -60
- 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 +409 -160
- package/es/components/SheetOverlay/drag_and_drop/column-helpers.js +34 -48
- package/es/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
- package/es/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
- package/es/components/SheetOverlay/formula-segment-boundary.js +4 -0
- package/es/components/SheetOverlay/helper.d.ts +7 -0
- package/es/components/SheetOverlay/helper.js +95 -0
- package/es/components/SheetOverlay/index.css +6 -39
- package/es/components/SheetOverlay/index.js +29 -17
- package/es/components/Toolbar/index.js +17 -12
- package/es/components/Workbook/api.d.ts +3 -0
- package/es/components/Workbook/index.d.ts +3 -0
- package/es/components/Workbook/index.js +9 -3
- 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/ConditionFormat/ConditionRules.js +15 -5
- package/lib/components/ConditionFormat/index.js +3 -0
- package/lib/components/ContextMenu/index.js +1 -1
- package/lib/components/DataVerification/ColorPicker.js +1 -1
- package/lib/components/FxEditor/index.js +314 -58
- 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 +407 -158
- package/lib/components/SheetOverlay/drag_and_drop/column-helpers.js +33 -47
- package/lib/components/SheetOverlay/drag_and_drop/row-helpers.js +31 -41
- package/lib/components/SheetOverlay/formula-segment-boundary.d.ts +1 -0
- package/lib/components/SheetOverlay/formula-segment-boundary.js +10 -0
- package/lib/components/SheetOverlay/helper.d.ts +7 -0
- package/lib/components/SheetOverlay/helper.js +99 -0
- package/lib/components/SheetOverlay/index.css +6 -39
- package/lib/components/SheetOverlay/index.js +28 -16
- package/lib/components/Toolbar/index.js +16 -11
- package/lib/components/Workbook/api.d.ts +3 -0
- package/lib/components/Workbook/index.d.ts +3 -0
- package/lib/components/Workbook/index.js +8 -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
|
@@ -133,6 +133,12 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
133
133
|
});
|
|
134
134
|
celldata === null || celldata === void 0 ? void 0 : celldata.forEach(function (d) {
|
|
135
135
|
expandedData_1[d.r][d.c] = d.v;
|
|
136
|
+
var cell = d.v;
|
|
137
|
+
if (cell && cell.ct && cell.ct.t === "d" && (cell.m === undefined || cell.m === null)) {
|
|
138
|
+
try {
|
|
139
|
+
cell.m = (0, _fortuneCore.update)(cell.ct.fa || "General", cell.v);
|
|
140
|
+
} catch (e) {}
|
|
141
|
+
}
|
|
136
142
|
});
|
|
137
143
|
draftCtx.luckysheetfile = (0, _immer.default)(draftCtx.luckysheetfile, function (d) {
|
|
138
144
|
d[index].data = expandedData_1;
|
|
@@ -887,7 +893,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
887
893
|
});
|
|
888
894
|
}
|
|
889
895
|
var nativeEvent = e.nativeEvent;
|
|
890
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
|
|
896
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ" && context.luckysheetCellUpdate.length === 0) {
|
|
891
897
|
if (e.shiftKey) {
|
|
892
898
|
handleRedo();
|
|
893
899
|
} else {
|
|
@@ -896,7 +902,7 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
896
902
|
e.stopPropagation();
|
|
897
903
|
return;
|
|
898
904
|
}
|
|
899
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY") {
|
|
905
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY" && context.luckysheetCellUpdate.length === 0) {
|
|
900
906
|
handleRedo();
|
|
901
907
|
e.stopPropagation();
|
|
902
908
|
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.
|
|
3
|
+
"version": "1.3.13-create-1",
|
|
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.
|
|
19
|
+
"@fileverse-dev/fortune-core": "1.3.13-create-1",
|
|
20
20
|
"@fileverse/ui": "5.0.0",
|
|
21
21
|
"@tippyjs/react": "^4.2.6",
|
|
22
22
|
"@types/regenerator-runtime": "^0.13.6",
|