@zhenliang/sheet 0.1.8 → 0.1.9
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.js +8 -7
- package/dist/core/reducers/sideEffectReducer.js +39 -22
- package/dist/core/shell/draggableShell/index.d.ts +0 -1
- package/dist/core/shell/tableShell.d.ts +0 -1
- package/dist/core/table/index.js +4 -2
- package/dist/hooks/useEventBus.d.ts +0 -1
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -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,46 @@ 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
|
|
203
|
-
|
|
204
|
-
|
|
215
|
+
legalChanges = changes.filter(function (_ref5) {
|
|
216
|
+
var _editor$checker;
|
|
217
|
+
var row = _ref5.row,
|
|
218
|
+
col = _ref5.col,
|
|
219
|
+
value = _ref5.value;
|
|
205
220
|
var editor = data[row][col].dataEditor;
|
|
221
|
+
console.log('number-checker', editor === null || editor === void 0 ? void 0 : editor.checker, editor === null || editor === void 0 ? void 0 : (_editor$checker = editor.checker) === null || _editor$checker === void 0 ? void 0 : _editor$checker.call(editor, value));
|
|
206
222
|
if (editor && editor.checker) {
|
|
207
223
|
return editor.checker(value, data[row][col].record);
|
|
208
224
|
}
|
|
209
225
|
return true;
|
|
210
|
-
}).map(function (
|
|
211
|
-
var _data$row$
|
|
212
|
-
var row =
|
|
213
|
-
col =
|
|
214
|
-
value =
|
|
226
|
+
}).map(function (_ref6) {
|
|
227
|
+
var _data$row$col2, _editor$parser;
|
|
228
|
+
var row = _ref6.row,
|
|
229
|
+
col = _ref6.col,
|
|
230
|
+
value = _ref6.value;
|
|
215
231
|
var editor = data[row][col].dataEditor;
|
|
216
232
|
return {
|
|
217
233
|
row: row,
|
|
218
234
|
col: col,
|
|
219
|
-
id: (_data$row$
|
|
235
|
+
id: (_data$row$col2 = data[row][col]) === null || _data$row$col2 === void 0 ? void 0 : _data$row$col2.id,
|
|
220
236
|
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
237
|
};
|
|
222
238
|
});
|
|
239
|
+
console.log('number', changes, legalChanges);
|
|
223
240
|
lastRow = extChanges === null || extChanges === void 0 ? void 0 : (_extChanges$ = extChanges[0]) === null || _extChanges$ === void 0 ? void 0 : _extChanges$.row;
|
|
224
241
|
lastIndex = 1;
|
|
225
|
-
legalExtChanges = extChanges === null || extChanges === void 0 ? void 0 : extChanges.filter(function (
|
|
226
|
-
var value =
|
|
227
|
-
col =
|
|
242
|
+
legalExtChanges = extChanges === null || extChanges === void 0 ? void 0 : extChanges.filter(function (_ref7) {
|
|
243
|
+
var value = _ref7.value,
|
|
244
|
+
col = _ref7.col;
|
|
228
245
|
var editor = data[0][col].dataEditor;
|
|
229
246
|
if (editor && editor.checker) {
|
|
230
247
|
return editor.checker(value);
|
|
231
248
|
}
|
|
232
249
|
return true;
|
|
233
|
-
}).map(function (
|
|
250
|
+
}).map(function (_ref8) {
|
|
234
251
|
var _editor$parser2;
|
|
235
|
-
var row =
|
|
236
|
-
col =
|
|
237
|
-
value =
|
|
252
|
+
var row = _ref8.row,
|
|
253
|
+
col = _ref8.col,
|
|
254
|
+
value = _ref8.value;
|
|
238
255
|
var editor = data[0][col].dataEditor;
|
|
239
256
|
if (lastRow !== row) {
|
|
240
257
|
lastRow = row;
|
|
@@ -269,7 +286,7 @@ export var sideEffectReducer = {
|
|
|
269
286
|
}
|
|
270
287
|
});
|
|
271
288
|
cellChangeHandler && cellChangeHandler(legalChanges, freePaste ? legalExtChanges : []);
|
|
272
|
-
case
|
|
289
|
+
case 19:
|
|
273
290
|
case "end":
|
|
274
291
|
return _context.stop();
|
|
275
292
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { SheetType } from "../../type";
|
|
3
2
|
import './draggableShell/index.less';
|
|
4
3
|
export declare const TableShell: ({ columns, className, showGroup, showSelect, controlProps, controlWidth, }: SheetType.SheetShell) => import("react").FC<{
|
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),
|