@fileverse-dev/fortune-react 1.3.12 → 1.3.13-create-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/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 +421 -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 +419 -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
|
@@ -25,7 +25,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
|
25
25
|
}
|
|
26
26
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
27
27
|
};
|
|
28
|
-
import { defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, getSheetIndex, handlePaste, filterPatch, patchToOp, inverseRowColOptions, ensureSheetIndex, insertRowCol, deleteRowCol, groupValuesRefresh, insertDuneChart, getFlowdata, api, handlePasteByClick } from "@fileverse-dev/fortune-core";
|
|
28
|
+
import { defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, getSheetIndex, handlePaste, filterPatch, patchToOp, inverseRowColOptions, ensureSheetIndex, insertRowCol, deleteRowCol, groupValuesRefresh, insertDuneChart, getFlowdata, api, handlePasteByClick, update } from "@fileverse-dev/fortune-core";
|
|
29
29
|
import React, { useMemo, useState, useCallback, useEffect, useRef, useImperativeHandle } from "react";
|
|
30
30
|
import "./index.css";
|
|
31
31
|
import produce, { applyPatches, enablePatches, produceWithPatches } from "immer";
|
|
@@ -124,6 +124,12 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
124
124
|
});
|
|
125
125
|
celldata === null || celldata === void 0 ? void 0 : celldata.forEach(function (d) {
|
|
126
126
|
expandedData_1[d.r][d.c] = d.v;
|
|
127
|
+
var cell = d.v;
|
|
128
|
+
if (cell && cell.ct && cell.ct.t === "d" && (cell.m === undefined || cell.m === null)) {
|
|
129
|
+
try {
|
|
130
|
+
cell.m = update(cell.ct.fa || "General", cell.v);
|
|
131
|
+
} catch (e) {}
|
|
132
|
+
}
|
|
127
133
|
});
|
|
128
134
|
draftCtx.luckysheetfile = produce(draftCtx.luckysheetfile, function (d) {
|
|
129
135
|
d[index].data = expandedData_1;
|
|
@@ -878,7 +884,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
878
884
|
});
|
|
879
885
|
}
|
|
880
886
|
var nativeEvent = e.nativeEvent;
|
|
881
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
|
|
887
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ" && context.luckysheetCellUpdate.length === 0) {
|
|
882
888
|
if (e.shiftKey) {
|
|
883
889
|
handleRedo();
|
|
884
890
|
} else {
|
|
@@ -887,7 +893,7 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
887
893
|
e.stopPropagation();
|
|
888
894
|
return;
|
|
889
895
|
}
|
|
890
|
-
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY") {
|
|
896
|
+
if ((e.ctrlKey || e.metaKey) && e.code === "KeyY" && context.luckysheetCellUpdate.length === 0) {
|
|
891
897
|
handleRedo();
|
|
892
898
|
e.stopPropagation();
|
|
893
899
|
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,119 @@
|
|
|
1
|
+
import { useCallback, useRef } from "react";
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
import { escapeScriptTag, functionHTMLGenerate, escapeHTMLTag, handleFormulaInput } from "@fileverse-dev/fortune-core";
|
|
4
|
+
import { setCursorPosition } from "../components/SheetOverlay/helper";
|
|
5
|
+
var MAX_FORMULA_HISTORY = 100;
|
|
6
|
+
export function useFormulaEditorHistory(primaryRef, cellInputRef, fxInputRef, setContext, primary) {
|
|
7
|
+
var preTextRef = useRef("");
|
|
8
|
+
var preFormulaSpanValuesRef = useRef(null);
|
|
9
|
+
var formulaHistoryRef = useRef({
|
|
10
|
+
active: false,
|
|
11
|
+
entries: [],
|
|
12
|
+
index: -1
|
|
13
|
+
});
|
|
14
|
+
var resetFormulaHistory = useCallback(function () {
|
|
15
|
+
formulaHistoryRef.current = {
|
|
16
|
+
active: false,
|
|
17
|
+
entries: [],
|
|
18
|
+
index: -1
|
|
19
|
+
};
|
|
20
|
+
preFormulaSpanValuesRef.current = null;
|
|
21
|
+
}, []);
|
|
22
|
+
var pushFormulaHistoryEntry = useCallback(function (entry) {
|
|
23
|
+
var history = formulaHistoryRef.current;
|
|
24
|
+
var current = history.entries[history.index];
|
|
25
|
+
if (current && current.spanValues.length > 0 && entry.spanValues.length > 0 && _.isEqual(current.spanValues, entry.spanValues)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (current && current.spanValues.length === 0 && entry.spanValues.length === 0 && current.text === entry.text && current.caret === entry.caret) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
var nextEntries = history.entries.slice(0, history.index + 1);
|
|
32
|
+
nextEntries.push(entry);
|
|
33
|
+
if (nextEntries.length > MAX_FORMULA_HISTORY) {
|
|
34
|
+
nextEntries.shift();
|
|
35
|
+
}
|
|
36
|
+
history.entries = nextEntries;
|
|
37
|
+
history.index = nextEntries.length - 1;
|
|
38
|
+
history.active = true;
|
|
39
|
+
}, []);
|
|
40
|
+
var applyFormulaHistoryEntry = useCallback(function (entry) {
|
|
41
|
+
var primaryEl = primaryRef.current;
|
|
42
|
+
if (!primaryEl) return;
|
|
43
|
+
var safeText = escapeScriptTag(entry.text || "");
|
|
44
|
+
var html = safeText.startsWith("=") ? functionHTMLGenerate(safeText) : escapeHTMLTag(safeText);
|
|
45
|
+
var cell = cellInputRef.current;
|
|
46
|
+
var fx = fxInputRef.current;
|
|
47
|
+
primaryEl.innerHTML = html;
|
|
48
|
+
if (primary === "cell") {
|
|
49
|
+
if (fx) fx.innerHTML = html;
|
|
50
|
+
} else if (cell) {
|
|
51
|
+
cell.innerHTML = html;
|
|
52
|
+
}
|
|
53
|
+
setCursorPosition(primaryEl, Math.min(entry.caret, entry.text.length));
|
|
54
|
+
setContext(function (draftCtx) {
|
|
55
|
+
if (primary === "cell") {
|
|
56
|
+
if (!cellInputRef.current) return;
|
|
57
|
+
handleFormulaInput(draftCtx, fxInputRef.current, cellInputRef.current, 0);
|
|
58
|
+
} else {
|
|
59
|
+
if (!fxInputRef.current) return;
|
|
60
|
+
handleFormulaInput(draftCtx, cellInputRef.current, fxInputRef.current, 0);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}, [cellInputRef, fxInputRef, primary, primaryRef, setContext]);
|
|
64
|
+
var handleFormulaHistoryUndoRedo = useCallback(function (isRedo) {
|
|
65
|
+
var history = formulaHistoryRef.current;
|
|
66
|
+
if (!history.active || history.entries.length === 0) return false;
|
|
67
|
+
var nextIndex = isRedo ? history.index + 1 : history.index - 1;
|
|
68
|
+
if (nextIndex < 0 || nextIndex >= history.entries.length) return true;
|
|
69
|
+
history.index = nextIndex;
|
|
70
|
+
applyFormulaHistoryEntry(history.entries[nextIndex]);
|
|
71
|
+
return true;
|
|
72
|
+
}, [applyFormulaHistoryEntry]);
|
|
73
|
+
var capturePreFormulaState = useCallback(function () {
|
|
74
|
+
var el = primaryRef.current;
|
|
75
|
+
if (!el) return;
|
|
76
|
+
preTextRef.current = el.innerText;
|
|
77
|
+
preFormulaSpanValuesRef.current = Array.from(el.querySelectorAll("span.fortune-formula-functionrange-cell")).map(function (node) {
|
|
78
|
+
var _a;
|
|
79
|
+
return (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
|
|
80
|
+
});
|
|
81
|
+
}, [primaryRef]);
|
|
82
|
+
var appendFormulaHistoryFromPrimaryEditor = useCallback(function (getCaret) {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
var el = primaryRef.current;
|
|
85
|
+
if (!el) return;
|
|
86
|
+
var currentText = el.innerText || "";
|
|
87
|
+
if (currentText.startsWith("=")) {
|
|
88
|
+
var caret = getCaret();
|
|
89
|
+
var spanValues = Array.from(el.querySelectorAll("span.fortune-formula-functionrange-cell")).map(function (node) {
|
|
90
|
+
var _a;
|
|
91
|
+
return (_a = node.textContent) !== null && _a !== void 0 ? _a : "";
|
|
92
|
+
});
|
|
93
|
+
if (!formulaHistoryRef.current.active) {
|
|
94
|
+
var seedText = preTextRef.current || "";
|
|
95
|
+
pushFormulaHistoryEntry({
|
|
96
|
+
text: seedText,
|
|
97
|
+
caret: Math.min(caret, seedText.length),
|
|
98
|
+
spanValues: (_b = (_a = preFormulaSpanValuesRef.current) !== null && _a !== void 0 ? _a : spanValues) !== null && _b !== void 0 ? _b : []
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
pushFormulaHistoryEntry({
|
|
102
|
+
text: currentText,
|
|
103
|
+
caret: caret,
|
|
104
|
+
spanValues: spanValues
|
|
105
|
+
});
|
|
106
|
+
} else if (formulaHistoryRef.current.active) {
|
|
107
|
+
resetFormulaHistory();
|
|
108
|
+
}
|
|
109
|
+
}, [primaryRef, pushFormulaHistoryEntry, resetFormulaHistory]);
|
|
110
|
+
return {
|
|
111
|
+
formulaHistoryRef: formulaHistoryRef,
|
|
112
|
+
preTextRef: preTextRef,
|
|
113
|
+
preFormulaSpanValuesRef: preFormulaSpanValuesRef,
|
|
114
|
+
resetFormulaHistory: resetFormulaHistory,
|
|
115
|
+
handleFormulaHistoryUndoRedo: handleFormulaHistoryUndoRedo,
|
|
116
|
+
capturePreFormulaState: capturePreFormulaState,
|
|
117
|
+
appendFormulaHistoryFromPrimaryEditor: appendFormulaHistoryFromPrimaryEditor
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
export function useRerenderOnFormulaCaret(editorRef, editSessionActive) {
|
|
3
|
+
var _a = useState(0),
|
|
4
|
+
bump = _a[1];
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
if (!editSessionActive) {
|
|
7
|
+
return function () {};
|
|
8
|
+
}
|
|
9
|
+
var onSelectionChange = function onSelectionChange() {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
var el = editorRef.current;
|
|
12
|
+
if (!el) return;
|
|
13
|
+
var text = (_b = (_a = el.innerText) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
|
|
14
|
+
if (!text.startsWith("=")) return;
|
|
15
|
+
var sel = window.getSelection();
|
|
16
|
+
if (!(sel === null || sel === void 0 ? void 0 : sel.rangeCount) || !el.contains(sel.getRangeAt(0).startContainer)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
bump(function (n) {
|
|
20
|
+
return n + 1;
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
document.addEventListener("selectionchange", onSelectionChange);
|
|
24
|
+
return function () {
|
|
25
|
+
document.removeEventListener("selectionchange", onSelectionChange);
|
|
26
|
+
};
|
|
27
|
+
}, [editSessionActive, editorRef]);
|
|
28
|
+
}
|
|
@@ -303,6 +303,10 @@ var ConditionRules = function ConditionRules(_a) {
|
|
|
303
303
|
text: "textContains",
|
|
304
304
|
value: "()",
|
|
305
305
|
label: "Text Contains"
|
|
306
|
+
}, {
|
|
307
|
+
text: "empty",
|
|
308
|
+
value: "",
|
|
309
|
+
label: "Empty"
|
|
306
310
|
}, {
|
|
307
311
|
text: "occurrenceDate",
|
|
308
312
|
value: conditionformat.yesterday,
|
|
@@ -343,7 +347,7 @@ var ConditionRules = function ConditionRules(_a) {
|
|
|
343
347
|
marginBottom: "16px"
|
|
344
348
|
}
|
|
345
349
|
}, matchedConditionFormatKey.map(function (key) {
|
|
346
|
-
var _a, _b;
|
|
350
|
+
var _a, _b, _c;
|
|
347
351
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
348
352
|
onClick: function onClick() {
|
|
349
353
|
var _a;
|
|
@@ -394,10 +398,10 @@ var ConditionRules = function ConditionRules(_a) {
|
|
|
394
398
|
}, /*#__PURE__*/_react.default.createElement("h3", {
|
|
395
399
|
className: "fortune-condition-rules__heading condition-list-type",
|
|
396
400
|
"data-testid": "condition-rules-heading-".concat(key)
|
|
397
|
-
}, conditionformat[allConditionFormats[key].conditionName], " "
|
|
401
|
+
}, conditionformat[allConditionFormats[key].conditionName], allConditionFormats[key].conditionName !== "empty" && " ".concat((_b = (_a = allConditionFormats[key].conditionValue) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : "")), /*#__PURE__*/_react.default.createElement("p", {
|
|
398
402
|
className: "fortune-condition-rules__para condition-list-range",
|
|
399
403
|
"data-testid": "condition-rules-para-".concat(key)
|
|
400
|
-
}, (
|
|
404
|
+
}, (_c = allConditionFormats[key].cellrange) === null || _c === void 0 ? void 0 : _c.map(function (range) {
|
|
401
405
|
var startCol = (0, _helper.numberToColumn)(range.column[0] + 1);
|
|
402
406
|
var endCol = (0, _helper.numberToColumn)(range.column[1] + 1);
|
|
403
407
|
var startRow = range.row[0] + 1;
|
|
@@ -476,6 +480,12 @@ var ConditionRules = function ConditionRules(_a) {
|
|
|
476
480
|
}, "Format cells if"), /*#__PURE__*/_react.default.createElement(_ui.Select, {
|
|
477
481
|
value: type,
|
|
478
482
|
onValueChange: function onValueChange(value) {
|
|
483
|
+
if (value === "empty" || type === "empty") {
|
|
484
|
+
setContext(function (ctx) {
|
|
485
|
+
ctx.conditionRules.rulesValue = "";
|
|
486
|
+
});
|
|
487
|
+
setEditConditionFormatValue(null);
|
|
488
|
+
}
|
|
479
489
|
setType(value);
|
|
480
490
|
}
|
|
481
491
|
}, /*#__PURE__*/_react.default.createElement(_ui.SelectTrigger, null, /*#__PURE__*/_react.default.createElement(_ui.SelectValue, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -813,7 +823,7 @@ var ConditionRules = function ConditionRules(_a) {
|
|
|
813
823
|
},
|
|
814
824
|
tabIndex: 0
|
|
815
825
|
}, button.cancel), editConditionFormatKey !== null ? (/*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
816
|
-
disabled: context.conditionRules.rulesValue === "",
|
|
826
|
+
disabled: context.conditionRules.rulesValue === "" && type !== "empty",
|
|
817
827
|
variant: "default",
|
|
818
828
|
style: {
|
|
819
829
|
minWidth: "80px"
|
|
@@ -823,7 +833,7 @@ var ConditionRules = function ConditionRules(_a) {
|
|
|
823
833
|
},
|
|
824
834
|
tabIndex: 0
|
|
825
835
|
}, "Update rule")) : (/*#__PURE__*/_react.default.createElement(_ui.Button, {
|
|
826
|
-
disabled: context.conditionRules.rulesValue === "",
|
|
836
|
+
disabled: context.conditionRules.rulesValue === "" && type !== "empty",
|
|
827
837
|
variant: "default",
|
|
828
838
|
style: {
|
|
829
839
|
minWidth: "80px"
|
|
@@ -21,7 +21,7 @@ require("./index.css");
|
|
|
21
21
|
var _Menu = _interopRequireDefault(require("./Menu"));
|
|
22
22
|
require("tippy.js/dist/tippy.css");
|
|
23
23
|
var _SVGIcon = _interopRequireDefault(require("../SVGIcon"));
|
|
24
|
-
var _LucideIcon = require("
|
|
24
|
+
var _LucideIcon = require("../SheetOverlay/LucideIcon");
|
|
25
25
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
26
26
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
27
27
|
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|