@zhenliang/sheet 0.1.8 → 0.1.10
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/cascaderEditor/index.d.ts +1 -1
- package/dist/core/editor/cascaderEditor/index.js +5 -3
- package/dist/core/editor/numberEditor/index.js +8 -7
- package/dist/core/editor/numberEditor/index.less +1 -0
- package/dist/core/editor/selectEditor/index.d.ts +1 -1
- package/dist/core/editor/selectEditor/index.js +3 -1
- package/dist/core/reducers/sideEffectReducer.js +35 -21
- package/dist/core/sheet/Cell.js +1 -1
- package/dist/core/sheet/index.js +5 -2
- package/dist/core/table/index.js +4 -2
- package/dist/core/util.d.ts +1 -1
- package/dist/core/viewer/groupViewer/index.js +3 -0
- package/dist/type/sheet.d.ts +2 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SheetType } from "../../../type";
|
|
2
2
|
import 'antd/es/cascader/style/index.css';
|
|
3
3
|
import './index.less';
|
|
4
|
-
declare const getCascaderEditor: (options: SheetType.OptionsType[]) => SheetType.CellEditor;
|
|
4
|
+
declare const getCascaderEditor: (options: SheetType.OptionsType[], getCustomOptions?: ((props: SheetType.CellEditorProps) => SheetType.OptionsType[]) | undefined) => SheetType.CellEditor;
|
|
5
5
|
export default getCascaderEditor;
|
|
@@ -4,7 +4,7 @@ import { useMemo } from 'react';
|
|
|
4
4
|
import { optionsToValuesFromLabelOrValue, valuesTransferToLabel } from "../../util";
|
|
5
5
|
import "./index.less";
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
var getCascaderEditor = function getCascaderEditor(options) {
|
|
7
|
+
var getCascaderEditor = function getCascaderEditor(options, getCustomOptions) {
|
|
8
8
|
var CascaderEditor = function CascaderEditor(props) {
|
|
9
9
|
var value = props.value,
|
|
10
10
|
onConfirm = props.onConfirm;
|
|
@@ -15,6 +15,7 @@ var getCascaderEditor = function getCascaderEditor(options) {
|
|
|
15
15
|
var handleChange = function handleChange(opt) {
|
|
16
16
|
onConfirm(opt ? opt[opt.length - 1] : null);
|
|
17
17
|
};
|
|
18
|
+
var customOptions = getCustomOptions ? getCustomOptions(props) : options;
|
|
18
19
|
return /*#__PURE__*/_jsx(Cascader, {
|
|
19
20
|
autoFocus: true,
|
|
20
21
|
open: true,
|
|
@@ -22,7 +23,8 @@ var getCascaderEditor = function getCascaderEditor(options) {
|
|
|
22
23
|
onMouseDown: function onMouseDown(event) {
|
|
23
24
|
event.stopPropagation();
|
|
24
25
|
},
|
|
25
|
-
value: val
|
|
26
|
+
value: val,
|
|
27
|
+
allowClear: true
|
|
26
28
|
// allowClear={false}
|
|
27
29
|
,
|
|
28
30
|
displayRender: function displayRender(label) {
|
|
@@ -32,7 +34,7 @@ var getCascaderEditor = function getCascaderEditor(options) {
|
|
|
32
34
|
// onBlur={handleBlur}
|
|
33
35
|
// onKeyDown={handleKeyDown}
|
|
34
36
|
,
|
|
35
|
-
options:
|
|
37
|
+
options: customOptions
|
|
36
38
|
});
|
|
37
39
|
};
|
|
38
40
|
CascaderEditor.formatter = function (value) {
|
|
@@ -84,20 +84,21 @@ export var getNumberEditor = function getNumberEditor(extraProps) {
|
|
|
84
84
|
return result;
|
|
85
85
|
};
|
|
86
86
|
NumberEditor.parser = function (value) {
|
|
87
|
-
var _extraProps$precision;
|
|
88
|
-
|
|
87
|
+
var _String2, _extraProps$precision;
|
|
88
|
+
var result = parseFloat((_String2 = String(value)) === null || _String2 === void 0 ? void 0 : _String2.replace(/,/g, ''));
|
|
89
|
+
if (isNil(result) || isNaN(result)) {
|
|
89
90
|
return null;
|
|
90
91
|
}
|
|
91
|
-
return Number(formatPrecision(
|
|
92
|
+
return Number(formatPrecision(result, (_extraProps$precision = extraProps === null || extraProps === void 0 ? void 0 : extraProps.precision) !== null && _extraProps$precision !== void 0 ? _extraProps$precision : 0));
|
|
92
93
|
};
|
|
93
94
|
NumberEditor.checker = function (value) {
|
|
94
|
-
var
|
|
95
|
-
if (
|
|
95
|
+
var _String3;
|
|
96
|
+
if (isNil(value)) {
|
|
96
97
|
return true;
|
|
97
98
|
}
|
|
98
99
|
// parse number with thousands separator
|
|
99
|
-
var result = parseFloat((
|
|
100
|
-
if (isNaN(result)
|
|
100
|
+
var result = parseFloat((_String3 = String(value)) === null || _String3 === void 0 ? void 0 : _String3.replace(/,/g, ''));
|
|
101
|
+
if (isNaN(result)) {
|
|
101
102
|
return false;
|
|
102
103
|
}
|
|
103
104
|
return true;
|
|
@@ -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
|
|
5
|
+
export declare const getSelectEditor: (options: SheetType.Options[], valueKey?: string, extra?: React.ReactNode, selectProps?: Partial<SelectProps>, getCustomOptions?: ((props: SheetType.CellEditorProps) => SheetType.Options[]) | undefined) => SheetType.CellEditor;
|
|
6
6
|
export default getSelectEditor;
|
|
@@ -24,6 +24,7 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
24
24
|
var valueKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'value';
|
|
25
25
|
var extra = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : /*#__PURE__*/_jsx(_Fragment, {});
|
|
26
26
|
var selectProps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
27
|
+
var getCustomOptions = arguments.length > 4 ? arguments[4] : undefined;
|
|
27
28
|
var SelectEditor = function SelectEditor(props) {
|
|
28
29
|
var _useState = useState(true),
|
|
29
30
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -49,6 +50,7 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
49
50
|
children: [menu, extra]
|
|
50
51
|
});
|
|
51
52
|
};
|
|
53
|
+
var customOptions = getCustomOptions ? getCustomOptions(props) : options;
|
|
52
54
|
return /*#__PURE__*/_jsx(Select, _objectSpread(_objectSpread({}, selectProps), {}, {
|
|
53
55
|
autoFocus: true,
|
|
54
56
|
className: "select-editor",
|
|
@@ -60,7 +62,7 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
60
62
|
value: SelectEditor.formatter ? SelectEditor.formatter(value) : value,
|
|
61
63
|
onChange: handleChange,
|
|
62
64
|
onKeyDown: handleKeyDown,
|
|
63
|
-
options:
|
|
65
|
+
options: customOptions,
|
|
64
66
|
popupClassName: 'excelTablePopupClassName',
|
|
65
67
|
dropdownRender: dropdown
|
|
66
68
|
}));
|
|
@@ -14,7 +14,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
14
14
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
15
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
16
|
import { head, isNil, last, pick } from 'lodash';
|
|
17
|
-
import { clipboardDataToString,
|
|
17
|
+
import { clipboardDataToString, flatRowCol, flatRowColIndex, formatDataToCell, getRowColConfig, groupConfigToGroupMap, stringToClipboardData } from "../util";
|
|
18
18
|
export var sideEffectReducer = {
|
|
19
19
|
init: function init(dispatch, getState) {
|
|
20
20
|
var _getState = getState(),
|
|
@@ -137,7 +137,6 @@ export var sideEffectReducer = {
|
|
|
137
137
|
var cellIndex = flatRowColIndex(start, end);
|
|
138
138
|
var groupMap = groupConfigToGroupMap(groupConfig);
|
|
139
139
|
var copyData = cellIndex.reduce(function (left, _ref3) {
|
|
140
|
-
var _data$row$col$dataEdi, _data$row$col$dataEdi2, _data$row$col$dataEdi3;
|
|
141
140
|
var _ref3$row = _ref3.row,
|
|
142
141
|
row = _ref3$row === void 0 ? 0 : _ref3$row,
|
|
143
142
|
_ref3$col = _ref3.col,
|
|
@@ -156,7 +155,22 @@ export var sideEffectReducer = {
|
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
// 复制到剪贴板的时候执行 formatter
|
|
159
|
-
var
|
|
158
|
+
var _data$row$col = data[row][col],
|
|
159
|
+
dataValue = _data$row$col.value,
|
|
160
|
+
dataEditor = _data$row$col.dataEditor;
|
|
161
|
+
var _ref4 = dataEditor || {},
|
|
162
|
+
dataFormatter = _ref4.formatter;
|
|
163
|
+
var formattedValue = dataFormatter ? dataFormatter(dataValue) : dataValue;
|
|
164
|
+
if (isNil(dataValue)) {
|
|
165
|
+
formattedValue = ' ';
|
|
166
|
+
}
|
|
167
|
+
if (currentRow === -1) {
|
|
168
|
+
return {
|
|
169
|
+
currentRow: row,
|
|
170
|
+
value: formattedValue
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
var currentValue = "".concat(value).concat(currentRow === row ? '\t' : '\n', " ").concat(formattedValue);
|
|
160
174
|
return {
|
|
161
175
|
currentRow: row,
|
|
162
176
|
value: currentValue
|
|
@@ -165,7 +179,7 @@ export var sideEffectReducer = {
|
|
|
165
179
|
currentRow: -1,
|
|
166
180
|
value: ''
|
|
167
181
|
});
|
|
168
|
-
var text = copyData.value
|
|
182
|
+
var text = copyData.value;
|
|
169
183
|
stringToClipboardData(text, cellIndex.length);
|
|
170
184
|
},
|
|
171
185
|
paste: function paste(dispatch, getState) {
|
|
@@ -198,43 +212,43 @@ export var sideEffectReducer = {
|
|
|
198
212
|
return _context.abrupt("return");
|
|
199
213
|
case 9:
|
|
200
214
|
changes = changeInfo.changes, extChanges = changeInfo.extChanges;
|
|
201
|
-
legalChanges = changes.filter(function (
|
|
202
|
-
var row =
|
|
203
|
-
col =
|
|
204
|
-
value =
|
|
215
|
+
legalChanges = changes.filter(function (_ref5) {
|
|
216
|
+
var row = _ref5.row,
|
|
217
|
+
col = _ref5.col,
|
|
218
|
+
value = _ref5.value;
|
|
205
219
|
var editor = data[row][col].dataEditor;
|
|
206
220
|
if (editor && editor.checker) {
|
|
207
221
|
return editor.checker(value, data[row][col].record);
|
|
208
222
|
}
|
|
209
223
|
return true;
|
|
210
|
-
}).map(function (
|
|
211
|
-
var _data$row$
|
|
212
|
-
var row =
|
|
213
|
-
col =
|
|
214
|
-
value =
|
|
224
|
+
}).map(function (_ref6) {
|
|
225
|
+
var _data$row$col2, _editor$parser;
|
|
226
|
+
var row = _ref6.row,
|
|
227
|
+
col = _ref6.col,
|
|
228
|
+
value = _ref6.value;
|
|
215
229
|
var editor = data[row][col].dataEditor;
|
|
216
230
|
return {
|
|
217
231
|
row: row,
|
|
218
232
|
col: col,
|
|
219
|
-
id: (_data$row$
|
|
233
|
+
id: (_data$row$col2 = data[row][col]) === null || _data$row$col2 === void 0 ? void 0 : _data$row$col2.id,
|
|
220
234
|
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 ? void 0 : (_editor$parser = editor.parser) === null || _editor$parser === void 0 ? void 0 : _editor$parser.call(editor, value) : value
|
|
221
235
|
};
|
|
222
236
|
});
|
|
223
237
|
lastRow = extChanges === null || extChanges === void 0 ? void 0 : (_extChanges$ = extChanges[0]) === null || _extChanges$ === void 0 ? void 0 : _extChanges$.row;
|
|
224
238
|
lastIndex = 1;
|
|
225
|
-
legalExtChanges = extChanges === null || extChanges === void 0 ? void 0 : extChanges.filter(function (
|
|
226
|
-
var value =
|
|
227
|
-
col =
|
|
239
|
+
legalExtChanges = extChanges === null || extChanges === void 0 ? void 0 : extChanges.filter(function (_ref7) {
|
|
240
|
+
var value = _ref7.value,
|
|
241
|
+
col = _ref7.col;
|
|
228
242
|
var editor = data[0][col].dataEditor;
|
|
229
243
|
if (editor && editor.checker) {
|
|
230
244
|
return editor.checker(value);
|
|
231
245
|
}
|
|
232
246
|
return true;
|
|
233
|
-
}).map(function (
|
|
247
|
+
}).map(function (_ref8) {
|
|
234
248
|
var _editor$parser2;
|
|
235
|
-
var row =
|
|
236
|
-
col =
|
|
237
|
-
value =
|
|
249
|
+
var row = _ref8.row,
|
|
250
|
+
col = _ref8.col,
|
|
251
|
+
value = _ref8.value;
|
|
238
252
|
var editor = data[0][col].dataEditor;
|
|
239
253
|
if (lastRow !== row) {
|
|
240
254
|
lastRow = row;
|
package/dist/core/sheet/Cell.js
CHANGED
|
@@ -115,7 +115,7 @@ var Cell = function Cell(props) {
|
|
|
115
115
|
if (valueRef.current === value) {
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
if (cell !== null && cell !== void 0 && (_cell$dataEditor5 = cell.dataEditor) !== null && _cell$dataEditor5 !== void 0 && _cell$dataEditor5.checker && !((_cell$dataEditor6 = cell.dataEditor) !== null && _cell$dataEditor6 !== void 0 && (_cell$dataEditor6$che = _cell$dataEditor6.checker) !== null && _cell$dataEditor6$che !== void 0 && _cell$dataEditor6$che.call(_cell$dataEditor6, value, cell.record))) {
|
|
118
|
+
if (value !== null && cell !== null && cell !== void 0 && (_cell$dataEditor5 = cell.dataEditor) !== null && _cell$dataEditor5 !== void 0 && _cell$dataEditor5.checker && !((_cell$dataEditor6 = cell.dataEditor) !== null && _cell$dataEditor6 !== void 0 && (_cell$dataEditor6$che = _cell$dataEditor6.checker) !== null && _cell$dataEditor6$che !== void 0 && _cell$dataEditor6$che.call(_cell$dataEditor6, value, cell.record))) {
|
|
119
119
|
setValue(valueRef.current);
|
|
120
120
|
return;
|
|
121
121
|
}
|
package/dist/core/sheet/index.js
CHANGED
|
@@ -11,7 +11,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
11
11
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
13
|
import { useEffect, useMemo, useRef } from 'react';
|
|
14
|
-
import ReduxLogger from 'redux-logger';
|
|
14
|
+
// import ReduxLogger from 'redux-logger';
|
|
15
15
|
import ReduxThunk from 'redux-thunk';
|
|
16
16
|
import DefaultRow from "./DefaultRow";
|
|
17
17
|
import DefaultShell from "./DefaultShell";
|
|
@@ -43,6 +43,7 @@ var Sheet = function Sheet(props) {
|
|
|
43
43
|
ContextMenu = props.menuRenderer,
|
|
44
44
|
_props$virtualized = props.virtualized,
|
|
45
45
|
virtualized = _props$virtualized === void 0 ? false : _props$virtualized,
|
|
46
|
+
sticky = props.sticky,
|
|
46
47
|
className = props.className,
|
|
47
48
|
data = props.data,
|
|
48
49
|
_props$freePaste = props.freePaste,
|
|
@@ -66,7 +67,9 @@ var Sheet = function Sheet(props) {
|
|
|
66
67
|
lastFocus: [],
|
|
67
68
|
groupConfig: groupConfig,
|
|
68
69
|
eventBus: eventBus
|
|
69
|
-
},
|
|
70
|
+
},
|
|
71
|
+
// [ReduxThunk, ReduxLogger],
|
|
72
|
+
[ReduxThunk]),
|
|
70
73
|
_useMiddlewareReducer2 = _slicedToArray(_useMiddlewareReducer, 2),
|
|
71
74
|
state = _useMiddlewareReducer2[0],
|
|
72
75
|
dispatch = _useMiddlewareReducer2[1];
|
package/dist/core/table/index.js
CHANGED
|
@@ -55,10 +55,12 @@ var Table = function Table(_ref) {
|
|
|
55
55
|
widths = _useSetState2[0],
|
|
56
56
|
setWidth = _useSetState2[1];
|
|
57
57
|
var sheetInstance = sheetRef || _sheetInstance;
|
|
58
|
-
var
|
|
58
|
+
var dataHasChildren = dataSource === null || dataSource === void 0 ? void 0 : dataSource.some(function (item) {
|
|
59
59
|
var _item$children;
|
|
60
60
|
return (item === null || item === void 0 ? void 0 : (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0;
|
|
61
|
-
})
|
|
61
|
+
});
|
|
62
|
+
var configWithChildren = !!groupConfig && !!dataSource.length;
|
|
63
|
+
var hasChildren = dataHasChildren || configWithChildren;
|
|
62
64
|
var hasControl = hasChildren || !!rowSelection;
|
|
63
65
|
var _useRowSelection = useRowSelection(dataSource, rowSelection, hasChildren),
|
|
64
66
|
_useRowSelection2 = _slicedToArray(_useRowSelection, 2),
|
package/dist/core/util.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare const defaultValueRenderer: (cell: SheetType.Cell) => string | nu
|
|
|
31
31
|
export declare function renderValue(cell: SheetType.Cell): string | number;
|
|
32
32
|
export declare const optionsToValuesFromLabelOrValue: (options: SheetType.OptionsType[], val: string) => string[];
|
|
33
33
|
export declare const optionsTransferToValue: (options: SheetType.OptionsType[], val: string, key?: string) => string[];
|
|
34
|
-
export declare const optionsTransferToValue2: (options?: SheetType.OptionsType[], value?: string, path?: string[]) => string[];
|
|
34
|
+
export declare const optionsTransferToValue2: (options?: SheetType.OptionsType[], value?: string, path?: string[]) => (string | number)[];
|
|
35
35
|
export declare const valuesTransferToLabel: (options?: SheetType.OptionsType[], value?: string) => string | null;
|
|
36
36
|
export declare const groupConfigToGroupMap: (rowGroupConfig?: SheetType.RowGroupConfig) => Map<number, SheetType.RowGroup & {
|
|
37
37
|
isStart: boolean;
|
|
@@ -20,6 +20,9 @@ export var GroupViewer = function GroupViewer(props) {
|
|
|
20
20
|
}, [eventBus, row, record === null || record === void 0 ? void 0 : record.open]);
|
|
21
21
|
if (value) {
|
|
22
22
|
return /*#__PURE__*/_jsx("span", {
|
|
23
|
+
style: {
|
|
24
|
+
cursor: 'pointer'
|
|
25
|
+
},
|
|
23
26
|
onMouseDown: function onMouseDown(e) {
|
|
24
27
|
return e.stopPropagation();
|
|
25
28
|
},
|
package/dist/type/sheet.d.ts
CHANGED
|
@@ -96,6 +96,7 @@ export declare type SheetProps = {
|
|
|
96
96
|
virtualized?: boolean;
|
|
97
97
|
showBackEdit?: boolean;
|
|
98
98
|
backEditStyle?: Partial<CSSStyleDeclaration>;
|
|
99
|
+
sticky?: boolean;
|
|
99
100
|
groupConfig?: RowGroupConfig;
|
|
100
101
|
onCellsChanged?: CellChangeHandler;
|
|
101
102
|
menuRenderer?: React.FC<MenuRenderProps>;
|
|
@@ -185,7 +186,7 @@ export declare type UpdateStateType = {
|
|
|
185
186
|
};
|
|
186
187
|
export declare type UpdateFocus = (start: CellPosition, end: CellPosition) => void;
|
|
187
188
|
export declare type Options<T = any> = {
|
|
188
|
-
value: string;
|
|
189
|
+
value: string | number;
|
|
189
190
|
label: string;
|
|
190
191
|
} & T;
|
|
191
192
|
export declare type OptionsType = Options<{
|