@zhenliang/sheet 0.2.5-beta.12 → 0.2.5-beta.13
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/core/editor/InputOptionsEditor/index.js +7 -17
- package/dist/core/editor/InputOptionsEditor/keyEventEffect.d.ts +2 -1
- package/dist/core/editor/InputOptionsEditor/keyEventEffect.js +2 -0
- package/dist/core/table/useRowSelection.d.ts +1 -1
- package/dist/example/basic.js +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ import { formulaString } from "../numberEditor";
|
|
|
18
18
|
import DropMenu from "./DropMenu";
|
|
19
19
|
import "./index.less";
|
|
20
20
|
import { useKeyEventEffect } from "./keyEventEffect";
|
|
21
|
-
import { createSpan, flattenOptions, getStringDiff, moveCursorToSpan, replaceLabelsWithValues,
|
|
21
|
+
import { createSpan, flattenOptions, getStringDiff, moveCursorToSpan, replaceLabelsWithValues, replaceValuesWithLabels, SpanType, tokenize, validateVariables } from "./utils";
|
|
22
22
|
import validateCalculationExpr from "./vaildFormula";
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
var OPERATORS = ['=', '+', '-', '*', '/', '('];
|
|
@@ -67,7 +67,6 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
67
67
|
setInputAfterDropDownShow = _useState10[1];
|
|
68
68
|
var tempSpanRef = useRef(null);
|
|
69
69
|
var containerRef = useRef(null);
|
|
70
|
-
var inputOperatorPosition = useRef(0);
|
|
71
70
|
|
|
72
71
|
// 扁平化所有选项
|
|
73
72
|
var flatOptions = useMemo(function () {
|
|
@@ -124,12 +123,6 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
124
123
|
setOpen(false);
|
|
125
124
|
return;
|
|
126
125
|
}
|
|
127
|
-
// 原逻辑:删除 inputAfterDropDownShow,插入新 label
|
|
128
|
-
var newValueUser = replaceLongestDiff(containerValueSnapShot.current, opt.label, inputOperatorPosition.current);
|
|
129
|
-
var expr = newValueUser;
|
|
130
|
-
var valueExprUser = replaceLabelsWithValues(expr, flatOptions);
|
|
131
|
-
setContainerValue(valueExprUser);
|
|
132
|
-
onChange(valueExprUser);
|
|
133
126
|
var range = selection.getRangeAt(0);
|
|
134
127
|
var startContainer = range.startContainer;
|
|
135
128
|
var currentSpan = startContainer.nodeType === Node.TEXT_NODE ? startContainer.parentElement : startContainer;
|
|
@@ -174,6 +167,11 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
174
167
|
targetSpan = createSpan(OTHER, '');
|
|
175
168
|
labelSpan.after(targetSpan);
|
|
176
169
|
}
|
|
170
|
+
var newValueUser = container.textContent || '';
|
|
171
|
+
var expr = newValueUser;
|
|
172
|
+
var valueExprUser = replaceLabelsWithValues(expr, flatOptions);
|
|
173
|
+
setContainerValue(valueExprUser);
|
|
174
|
+
onChange(valueExprUser);
|
|
177
175
|
moveCursorToSpan(targetSpan, true, selection);
|
|
178
176
|
setOpen(false);
|
|
179
177
|
}, [inputAfterDropDownShow]);
|
|
@@ -189,14 +187,6 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
189
187
|
var processedValue = newValue;
|
|
190
188
|
var expr = processedValue;
|
|
191
189
|
var valueExpr = replaceLabelsWithValues(expr, flatOptions);
|
|
192
|
-
var oldLabelText = replaceValuesWithLabels(containerValue, flatOptions);
|
|
193
|
-
var firstDiffPosition = 0;
|
|
194
|
-
for (var i = 0; i < newValue.length; i++) {
|
|
195
|
-
if (newValue[i] !== oldLabelText[i]) {
|
|
196
|
-
firstDiffPosition = i;
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
190
|
var _getStringDiff = getStringDiff(containerValue, valueExpr),
|
|
201
191
|
added = _getStringDiff.added,
|
|
202
192
|
removed = _getStringDiff.removed;
|
|
@@ -215,7 +205,6 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
215
205
|
// 按下了运算符,下拉框刚打开,重置输入记录
|
|
216
206
|
containerValueSnapShot.current = expr;
|
|
217
207
|
inputStringAfterDropDownShow = '';
|
|
218
|
-
inputOperatorPosition.current = firstDiffPosition;
|
|
219
208
|
|
|
220
209
|
// 获取当前光标距离 containerRef 最左边的距离
|
|
221
210
|
var selection = window.getSelection();
|
|
@@ -241,6 +230,7 @@ export var getFormulaInputEditor = function getFormulaInputEditor(options, repla
|
|
|
241
230
|
closeDorpDown: closeDorpDown,
|
|
242
231
|
setOffsetX: setOffsetX,
|
|
243
232
|
setOpen: setOpen,
|
|
233
|
+
handleInput: handleInput,
|
|
244
234
|
containerRef: containerRef,
|
|
245
235
|
tempSpanRef: tempSpanRef,
|
|
246
236
|
inputAfterDropDownShow: inputAfterDropDownShow,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
|
|
2
2
|
import { OptionItem } from './utils';
|
|
3
|
-
declare const useKeyEventEffect: ({ closeDorpDown, setOffsetX, setOpen, containerRef, tempSpanRef, inputAfterDropDownShow, options }: {
|
|
3
|
+
declare const useKeyEventEffect: ({ closeDorpDown, setOffsetX, setOpen, handleInput, containerRef, tempSpanRef, inputAfterDropDownShow, options }: {
|
|
4
4
|
closeDorpDown: () => void;
|
|
5
5
|
setOffsetX: (value: React.SetStateAction<number>) => void;
|
|
6
6
|
setOpen: (value: React.SetStateAction<boolean>) => void;
|
|
7
|
+
handleInput: () => void;
|
|
7
8
|
containerRef: React.RefObject<HTMLDivElement>;
|
|
8
9
|
tempSpanRef: React.MutableRefObject<HTMLElement | null>;
|
|
9
10
|
inputAfterDropDownShow: string;
|
|
@@ -13,6 +13,7 @@ var useKeyEventEffect = function useKeyEventEffect(_ref) {
|
|
|
13
13
|
var closeDorpDown = _ref.closeDorpDown,
|
|
14
14
|
setOffsetX = _ref.setOffsetX,
|
|
15
15
|
setOpen = _ref.setOpen,
|
|
16
|
+
handleInput = _ref.handleInput,
|
|
16
17
|
containerRef = _ref.containerRef,
|
|
17
18
|
tempSpanRef = _ref.tempSpanRef,
|
|
18
19
|
inputAfterDropDownShow = _ref.inputAfterDropDownShow,
|
|
@@ -187,6 +188,7 @@ var useKeyEventEffect = function useKeyEventEffect(_ref) {
|
|
|
187
188
|
_prevSpan.textContent = prevText.slice(0, -1);
|
|
188
189
|
}
|
|
189
190
|
moveCursorToSpan(_prevSpan, false, selection);
|
|
191
|
+
handleInput();
|
|
190
192
|
}
|
|
191
193
|
}
|
|
192
194
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SheetTableType } from "../..";
|
|
2
2
|
export declare const useRowSelection: (dataSource: Record<string, unknown>[], rowSelection?: SheetTableType.TableRowSelection, hasChildren?: boolean) => [boolean[], (value: boolean[]) => void];
|
|
3
|
-
export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "
|
|
3
|
+
export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "dataSource" | "columns" | "rowKey" | "showRemark" | "rowSelection"> & {
|
|
4
4
|
checked: boolean[];
|
|
5
5
|
}) => any[][];
|
package/dist/example/basic.js
CHANGED