@zhenliang/sheet 0.1.92 → 0.1.94
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/numberEditor/index.d.ts +2 -2
- package/dist/core/editor/numberEditor/index.js +26 -8
- package/dist/core/editor/selectEditor/index.d.ts +1 -1
- package/dist/core/editor/selectEditor/index.js +18 -14
- package/dist/core/reducers/keyboardReducer.js +10 -7
- package/dist/core/reducers/sideEffectReducer.js +3 -3
- package/dist/core/sheet/Cell.js +3 -2
- package/dist/core/table/useRowSelection.d.ts +1 -1
- package/dist/type/sheet.d.ts +2 -1
- package/package.json +1 -1
|
@@ -5,8 +5,8 @@ import './index.less';
|
|
|
5
5
|
type inputProps = Partial<Pick<InputNumberProps, 'max' | 'min' | 'addonBefore' | 'addonAfter' | 'precision'> & {
|
|
6
6
|
warnMethod?: (record: any) => void;
|
|
7
7
|
rangeMethod?: (record: any) => {
|
|
8
|
-
max
|
|
9
|
-
min
|
|
8
|
+
max?: number;
|
|
9
|
+
min?: number;
|
|
10
10
|
};
|
|
11
11
|
}>;
|
|
12
12
|
export declare const NumberEditor: SheetType.CellEditor;
|
|
@@ -8,16 +8,24 @@ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("
|
|
|
8
8
|
import { formatPrecision } from "../../../standardUtils";
|
|
9
9
|
import { InputNumber as AntInputNumber, Input } from 'antd';
|
|
10
10
|
import 'antd/es/input-number/style/index.css';
|
|
11
|
-
import { isNil } from 'lodash';
|
|
11
|
+
import { head, isNil } from 'lodash';
|
|
12
12
|
import { evaluate } from 'mathjs';
|
|
13
13
|
import { useCallback, useEffect, useRef } from 'react';
|
|
14
14
|
import "./index.less";
|
|
15
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
16
|
var formulaString = function formulaString(value, currentValue, precision, max, min, isEdit) {
|
|
17
17
|
var curNumber = currentValue !== null && currentValue !== void 0 ? currentValue : 0;
|
|
18
|
-
var
|
|
18
|
+
var headStr = head(String(value).trim());
|
|
19
|
+
var formula = String(value).replace('=', '');
|
|
20
|
+
var hasAdjacent = /\d+[xX]|[xX]+\d+/g.test(formula);
|
|
19
21
|
try {
|
|
20
|
-
|
|
22
|
+
if (isNaN(value) && headStr !== '=' || hasAdjacent) {
|
|
23
|
+
throw false;
|
|
24
|
+
}
|
|
25
|
+
var result = evaluate(formula, {
|
|
26
|
+
x: curNumber,
|
|
27
|
+
X: curNumber
|
|
28
|
+
});
|
|
21
29
|
if (max && result > max) {
|
|
22
30
|
result = max;
|
|
23
31
|
} else if (min && result < min) {
|
|
@@ -64,7 +72,8 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
|
|
|
64
72
|
var NumberEditor = function NumberEditor(props) {
|
|
65
73
|
var _ref3;
|
|
66
74
|
var value = props.value,
|
|
67
|
-
onChange = props.onChange
|
|
75
|
+
onChange = props.onChange,
|
|
76
|
+
isEditing = props.isEditing;
|
|
68
77
|
var inputNumberRef = useRef(null);
|
|
69
78
|
var _ref2 = getExtraProps ? getExtraProps(props) : extraProps !== null && extraProps !== void 0 ? extraProps : {},
|
|
70
79
|
inputArgs = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
|
|
@@ -72,9 +81,17 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
|
|
|
72
81
|
onChange(!isNil(value) ? value : null);
|
|
73
82
|
}, [onChange]);
|
|
74
83
|
useEffect(function () {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
if (isEditing) {
|
|
85
|
+
var _inputNumberRef$curre2;
|
|
86
|
+
inputNumberRef === null || inputNumberRef === void 0 || (_inputNumberRef$curre2 = inputNumberRef.current) === null || _inputNumberRef$curre2 === void 0 || _inputNumberRef$curre2.focus();
|
|
87
|
+
}
|
|
88
|
+
}, [isEditing]);
|
|
89
|
+
var reFocus = useCallback(function () {
|
|
90
|
+
if (isEditing) {
|
|
91
|
+
var _inputNumberRef$curre3;
|
|
92
|
+
inputNumberRef === null || inputNumberRef === void 0 || (_inputNumberRef$curre3 = inputNumberRef.current) === null || _inputNumberRef$curre3 === void 0 || _inputNumberRef$curre3.focus();
|
|
93
|
+
}
|
|
94
|
+
}, [isEditing]);
|
|
78
95
|
return /*#__PURE__*/_jsx(Input, _objectSpread(_objectSpread({
|
|
79
96
|
ref: inputNumberRef
|
|
80
97
|
}, inputArgs), {}, {
|
|
@@ -82,6 +99,7 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
|
|
|
82
99
|
onMouseDown: function onMouseDown(e) {
|
|
83
100
|
return e.stopPropagation();
|
|
84
101
|
},
|
|
102
|
+
onBlur: reFocus,
|
|
85
103
|
value: (_ref3 = value) !== null && _ref3 !== void 0 ? _ref3 : '',
|
|
86
104
|
onChange: function onChange(e) {
|
|
87
105
|
handleChange(e.target.value);
|
|
@@ -105,7 +123,7 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
|
|
|
105
123
|
return result;
|
|
106
124
|
};
|
|
107
125
|
// 粘贴上去的时候触发
|
|
108
|
-
NumberEditor.parser = function (value, currentValue) {
|
|
126
|
+
NumberEditor.parser = function (value, record, currentValue) {
|
|
109
127
|
var _String2;
|
|
110
128
|
var result = (_String2 = String(value)) === null || _String2 === void 0 ? void 0 : _String2.replace(/,/g, '');
|
|
111
129
|
result = formulaString(result, currentValue);
|
|
@@ -2,5 +2,5 @@ import type { SheetType } from "../../../type";
|
|
|
2
2
|
import { SelectProps } from 'antd';
|
|
3
3
|
import 'antd/es/select/style/index.css';
|
|
4
4
|
import './index.less';
|
|
5
|
-
export declare const getSelectEditor: (options: SheetType.Options[], valueKey?: string, extra?: React.ReactNode, selectProps?: Partial<SelectProps>, getCustomOptions?: ((
|
|
5
|
+
export declare const getSelectEditor: (options: SheetType.Options[], valueKey?: string, extra?: React.ReactNode, selectProps?: Partial<SelectProps>, getCustomOptions?: ((record: any) => SheetType.Options[]) | undefined) => SheetType.CellEditor;
|
|
6
6
|
export default getSelectEditor;
|
|
@@ -26,6 +26,7 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
26
26
|
var selectProps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
27
27
|
var getCustomOptions = arguments.length > 4 ? arguments[4] : undefined;
|
|
28
28
|
var SelectEditor = function SelectEditor(props) {
|
|
29
|
+
var _props$record;
|
|
29
30
|
var _useState = useState(true),
|
|
30
31
|
_useState2 = _slicedToArray(_useState, 2),
|
|
31
32
|
isOpen = _useState2[0],
|
|
@@ -50,7 +51,7 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
50
51
|
children: [menu, extra]
|
|
51
52
|
});
|
|
52
53
|
};
|
|
53
|
-
var customOptions = getCustomOptions ? getCustomOptions(props) : options;
|
|
54
|
+
var customOptions = getCustomOptions ? getCustomOptions((_props$record = props === null || props === void 0 ? void 0 : props.record) !== null && _props$record !== void 0 ? _props$record : {}) : options;
|
|
54
55
|
return /*#__PURE__*/_jsx(Select, _objectSpread({
|
|
55
56
|
autoFocus: true,
|
|
56
57
|
className: "select-editor",
|
|
@@ -67,29 +68,32 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
67
68
|
allowClear: true
|
|
68
69
|
}, selectProps));
|
|
69
70
|
};
|
|
70
|
-
SelectEditor.checker = function (value) {
|
|
71
|
+
SelectEditor.checker = function (value, record) {
|
|
71
72
|
if (isNil(value) && selectProps.allowClear !== false) return true;
|
|
72
|
-
|
|
73
|
+
var customOptions = getCustomOptions ? getCustomOptions(record !== null && record !== void 0 ? record : {}) : options;
|
|
74
|
+
return customOptions.some(function (item) {
|
|
73
75
|
return item.value == value;
|
|
74
|
-
}) ||
|
|
76
|
+
}) || customOptions.some(function (item) {
|
|
75
77
|
return item.label === value;
|
|
76
78
|
});
|
|
77
79
|
};
|
|
78
|
-
SelectEditor.parser = function (value) {
|
|
79
|
-
var
|
|
80
|
-
|
|
80
|
+
SelectEditor.parser = function (value, record) {
|
|
81
|
+
var _customOptions$find, _customOptions$find2;
|
|
82
|
+
var customOptions = getCustomOptions ? getCustomOptions(record !== null && record !== void 0 ? record : {}) : options;
|
|
83
|
+
return ((_customOptions$find = customOptions.find(function (item) {
|
|
81
84
|
return item.value == value;
|
|
82
|
-
})) === null ||
|
|
85
|
+
})) === null || _customOptions$find === void 0 ? void 0 : _customOptions$find[valueKey]) || ((_customOptions$find2 = customOptions.find(function (item) {
|
|
83
86
|
return item.label === value;
|
|
84
|
-
})) === null ||
|
|
87
|
+
})) === null || _customOptions$find2 === void 0 ? void 0 : _customOptions$find2[valueKey]);
|
|
85
88
|
};
|
|
86
|
-
SelectEditor.formatter = function (value) {
|
|
87
|
-
var
|
|
88
|
-
|
|
89
|
+
SelectEditor.formatter = function (value, record) {
|
|
90
|
+
var _customOptions$find3, _customOptions$find4;
|
|
91
|
+
var customOptions = getCustomOptions ? getCustomOptions(record !== null && record !== void 0 ? record : {}) : options;
|
|
92
|
+
return ((_customOptions$find3 = customOptions.find(function (item) {
|
|
89
93
|
return item.value == value;
|
|
90
|
-
})) === null ||
|
|
94
|
+
})) === null || _customOptions$find3 === void 0 ? void 0 : _customOptions$find3.label) || ((_customOptions$find4 = customOptions.find(function (item) {
|
|
91
95
|
return item.label === value;
|
|
92
|
-
})) === null ||
|
|
96
|
+
})) === null || _customOptions$find4 === void 0 ? void 0 : _customOptions$find4.label);
|
|
93
97
|
};
|
|
94
98
|
return SelectEditor;
|
|
95
99
|
};
|
|
@@ -30,8 +30,17 @@ export var keyboardReducer = {
|
|
|
30
30
|
minCol++;
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
|
+
var lastEditing = state.lastEditing;
|
|
34
|
+
if (state.editing) {
|
|
35
|
+
lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
|
|
36
|
+
confirm: true
|
|
37
|
+
});
|
|
38
|
+
}
|
|
33
39
|
if (newRow > maxRow || newRow < 0 || newCol > maxCol || newCol < minCol) {
|
|
34
|
-
return state
|
|
40
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
41
|
+
editing: undefined,
|
|
42
|
+
lastEditing: lastEditing
|
|
43
|
+
});
|
|
35
44
|
}
|
|
36
45
|
// 跟随滚动
|
|
37
46
|
if (optCol !== 0) {
|
|
@@ -56,12 +65,6 @@ export var keyboardReducer = {
|
|
|
56
65
|
row: newRow,
|
|
57
66
|
col: newCol
|
|
58
67
|
};
|
|
59
|
-
var lastEditing = state.lastEditing;
|
|
60
|
-
if (state.editing) {
|
|
61
|
-
lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
|
|
62
|
-
confirm: true
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
68
|
var isOut = isNil(currentPos.row);
|
|
66
69
|
var newState = _objectSpread(_objectSpread({}, state), {}, {
|
|
67
70
|
start: isOut ? undefined : currentPos,
|
|
@@ -263,7 +263,7 @@ export var sideEffectReducer = {
|
|
|
263
263
|
row: row,
|
|
264
264
|
col: col,
|
|
265
265
|
id: (_data$row$col2 = data[row][col]) === null || _data$row$col2 === void 0 ? void 0 : _data$row$col2.id,
|
|
266
|
-
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 || (_editor$parser = editor.parser) === null || _editor$parser === void 0 ? void 0 : _editor$parser.call(editor, value, data[row][col].value) : value
|
|
266
|
+
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 || (_editor$parser = editor.parser) === null || _editor$parser === void 0 ? void 0 : _editor$parser.call(editor, value, data[row][col].record, data[row][col].value) : value
|
|
267
267
|
};
|
|
268
268
|
});
|
|
269
269
|
lastRow = extChanges === null || extChanges === void 0 || (_extChanges$ = extChanges[0]) === null || _extChanges$ === void 0 ? void 0 : _extChanges$.row;
|
|
@@ -274,7 +274,7 @@ export var sideEffectReducer = {
|
|
|
274
274
|
col = _ref7.col;
|
|
275
275
|
var editor = data[0][col].dataEditor;
|
|
276
276
|
if (editor && editor.checker) {
|
|
277
|
-
return editor.checker(value, data[row][col].record, data[row][col].value);
|
|
277
|
+
return editor.checker(value, data[row] ? data[row][col].record : {}, data[row] ? data[row][col].value : null);
|
|
278
278
|
}
|
|
279
279
|
return true;
|
|
280
280
|
}).map(function (_ref8) {
|
|
@@ -290,7 +290,7 @@ export var sideEffectReducer = {
|
|
|
290
290
|
return {
|
|
291
291
|
row: row,
|
|
292
292
|
col: col,
|
|
293
|
-
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 || (_editor$parser2 = editor.parser) === null || _editor$parser2 === void 0 ? void 0 : _editor$parser2.call(editor, value, data[row][col].value) : value,
|
|
293
|
+
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 || (_editor$parser2 = editor.parser) === null || _editor$parser2 === void 0 ? void 0 : _editor$parser2.call(editor, value, data[row] ? data[row][col].record : {}, data[row] ? data[row][col].value : null) : value,
|
|
294
294
|
id: -lastIndex
|
|
295
295
|
};
|
|
296
296
|
});
|
package/dist/core/sheet/Cell.js
CHANGED
|
@@ -60,7 +60,7 @@ var Cell = function Cell(props) {
|
|
|
60
60
|
} else if (eventInfo.value && eventInfo.editing) {
|
|
61
61
|
var _cell$dataEditor, _cell$dataEditor2, _cell$dataEditor2$par;
|
|
62
62
|
// 单元格直接键盘编辑,设置为输入值
|
|
63
|
-
setValue((_cell$dataEditor = cell.dataEditor) !== null && _cell$dataEditor !== void 0 && _cell$dataEditor.parser ? cell === null || cell === void 0 || (_cell$dataEditor2 = cell.dataEditor) === null || _cell$dataEditor2 === void 0 || (_cell$dataEditor2$par = _cell$dataEditor2.parser) === null || _cell$dataEditor2$par === void 0 ? void 0 : _cell$dataEditor2$par.call(_cell$dataEditor2, eventInfo.value, valueRef.current) : eventInfo.value);
|
|
63
|
+
setValue((_cell$dataEditor = cell.dataEditor) !== null && _cell$dataEditor !== void 0 && _cell$dataEditor.parser ? cell === null || cell === void 0 || (_cell$dataEditor2 = cell.dataEditor) === null || _cell$dataEditor2 === void 0 || (_cell$dataEditor2$par = _cell$dataEditor2.parser) === null || _cell$dataEditor2$par === void 0 ? void 0 : _cell$dataEditor2$par.call(_cell$dataEditor2, eventInfo.value, cell.record, valueRef.current) : eventInfo.value);
|
|
64
64
|
}
|
|
65
65
|
setEventState(eventInfo);
|
|
66
66
|
};
|
|
@@ -158,7 +158,8 @@ var Cell = function Cell(props) {
|
|
|
158
158
|
value: value,
|
|
159
159
|
record: cel.record,
|
|
160
160
|
onConfirm: handleCommit,
|
|
161
|
-
onChange: setValue
|
|
161
|
+
onChange: setValue,
|
|
162
|
+
isEditing: isEditing
|
|
162
163
|
});
|
|
163
164
|
}
|
|
164
165
|
return null;
|
|
@@ -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, "columns" | "
|
|
3
|
+
export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "columns" | "dataSource" | "rowKey" | "showRemark" | "rowSelection"> & {
|
|
4
4
|
checked: boolean[];
|
|
5
5
|
}) => any[][];
|
package/dist/type/sheet.d.ts
CHANGED
|
@@ -51,11 +51,12 @@ export type CellEditorProps = {
|
|
|
51
51
|
cell?: Cell;
|
|
52
52
|
onChange: (value: unknown) => void;
|
|
53
53
|
onConfirm: (value: unknown) => void;
|
|
54
|
+
isEditing?: boolean;
|
|
54
55
|
} & CellViewerProps;
|
|
55
56
|
export type CellEditor = React.FC<CellEditorProps> & {
|
|
56
57
|
checker?: (value: unknown, record?: Record<string, unknown>, currentValue?: unknown) => boolean;
|
|
57
58
|
formatter?: (value: unknown, record?: Record<string, unknown>) => unknown;
|
|
58
|
-
parser?: (value: unknown, currentValue?: unknown) => unknown;
|
|
59
|
+
parser?: (value: unknown, record?: Record<string, unknown>, currentValue?: unknown) => unknown;
|
|
59
60
|
formula?: (value: unknown, record?: Record<string, unknown>, currentValue?: unknown) => unknown;
|
|
60
61
|
};
|
|
61
62
|
export type CellViewer = React.FC<CellViewerProps>;
|