@zhenliang/sheet 0.0.8 → 0.1.0
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/README.md +3 -2
- package/dist/core/config.js +1 -2
- package/dist/core/editor/cascaderEditor/index.js +14 -7
- package/dist/core/editor/dateEditor/index.d.ts +1 -1
- package/dist/core/editor/dateEditor/index.js +2 -3
- package/dist/core/editor/index.d.ts +1 -1
- package/dist/core/editor/index.js +2 -3
- package/dist/core/editor/numberEditor/index.js +50 -6
- 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 +23 -5
- package/dist/core/reducers/index.d.ts +1 -1
- package/dist/core/reducers/index.js +3 -2
- package/dist/core/reducers/keyboardReducer.js +2 -3
- package/dist/core/reducers/mouseReducer.js +1 -2
- package/dist/core/reducers/sideEffectReducer.js +49 -25
- package/dist/core/reducers/stateReducer.js +35 -10
- package/dist/core/sheet/Cell.js +37 -16
- package/dist/core/sheet/DataEditor.js +4 -2
- package/dist/core/sheet/DefaultCell.js +1 -2
- package/dist/core/sheet/DefaultRow.d.ts +1 -0
- package/dist/core/sheet/DefaultRow.js +5 -3
- package/dist/core/sheet/DefaultRowMapper.js +1 -2
- package/dist/core/sheet/DefaultShell.js +1 -2
- package/dist/core/sheet/Event.js +2 -3
- package/dist/core/sheet/ValueViewer.js +1 -2
- package/dist/core/sheet/index.js +54 -15
- package/dist/core/sheet/index.less +20 -11
- package/dist/core/sheet/useCellEvent.js +1 -2
- package/dist/core/sheet/useContextMenu.d.ts +1 -1
- package/dist/core/sheet/useContextMenu.js +2 -3
- package/dist/core/sheet/useKeyBoardEvent.js +15 -3
- package/dist/core/sheet/useMouseEvent.js +3 -4
- package/dist/core/sheet/useSelectVisible.d.ts +2 -0
- package/dist/core/sheet/useSelectVisible.js +48 -0
- package/dist/core/sheet/useVirtualList.d.ts +1 -1
- package/dist/core/sheet/useVirtualList.js +24 -20
- package/dist/core/shell/draggableShell/index.d.ts +0 -1
- package/dist/core/shell/draggableShell/index.js +21 -13
- package/dist/core/shell/tableShell.d.ts +0 -1
- package/dist/core/shell/tableShell.js +9 -6
- package/dist/core/table/events.d.ts +15 -0
- package/dist/core/table/events.js +94 -0
- package/dist/core/table/index.js +91 -112
- package/dist/core/table/useGroupConfig.js +24 -7
- package/dist/core/table/useRowSelection.d.ts +2 -1
- package/dist/core/table/useRowSelection.js +1 -2
- package/dist/core/table/util.js +2 -3
- package/dist/core/util.d.ts +5 -2
- package/dist/core/util.js +97 -16
- package/dist/core/viewer/btnViewer/index.js +2 -3
- package/dist/core/viewer/cascaderViewer/index.d.ts +2 -0
- package/dist/core/viewer/cascaderViewer/index.js +11 -0
- package/dist/core/viewer/checkViewer/index.js +2 -3
- package/dist/core/viewer/editViewer/index.js +2 -3
- package/dist/core/viewer/groupViewer/index.js +5 -3
- package/dist/core/viewer/index.d.ts +1 -0
- package/dist/core/viewer/index.js +2 -2
- package/dist/core/viewer/selectorViewer/index.d.ts +2 -0
- package/dist/core/viewer/selectorViewer/index.js +12 -0
- package/dist/core/viewer/switchViewer/index.js +2 -3
- package/dist/example/antComponent.js +60 -14
- package/dist/example/basic.js +2 -3
- package/dist/example/ellipsis.js +1 -2
- package/dist/example/fixed.js +1 -2
- package/dist/example/group.js +42 -4
- package/dist/example/selection.js +2 -3
- package/dist/example/sheet.js +52 -16
- package/dist/example/valuationAnalyze.js +20 -18
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useEventBus.d.ts +0 -1
- package/dist/hooks/useEventBus.js +1 -2
- package/dist/hooks/useKeyboard.js +1 -2
- package/dist/hooks/useMiddlewareReducer.js +1 -2
- package/dist/hooks/useMouse.js +1 -2
- package/dist/hooks/useSetState.js +1 -2
- package/dist/hooks/useSheetEvent.js +1 -2
- package/dist/hooks/useWidthConfig.d.ts +4 -0
- package/dist/hooks/useWidthConfig.js +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -1
- package/dist/standardUtils/index.js +2 -3
- package/dist/type/index.js +1 -2
- package/dist/type/sheet.d.ts +14 -3
- package/dist/type/sheet.js +1 -2
- package/dist/type/sheetTable.d.ts +43 -14
- package/dist/type/sheetTable.js +1 -2
- package/package.json +1 -1
- package/dist/core/config.js.map +0 -1
- package/dist/core/editor/cascaderEditor/index.js.map +0 -1
- package/dist/core/editor/dateEditor/index.js.map +0 -1
- package/dist/core/editor/index.js.map +0 -1
- package/dist/core/editor/numberEditor/index.js.map +0 -1
- package/dist/core/editor/selectEditor/index.js.map +0 -1
- package/dist/core/reducers/index.js.map +0 -1
- package/dist/core/reducers/keyboardReducer.js.map +0 -1
- package/dist/core/reducers/mouseReducer.js.map +0 -1
- package/dist/core/reducers/sideEffectReducer.js.map +0 -1
- package/dist/core/reducers/stateReducer.js.map +0 -1
- package/dist/core/sheet/Cell.js.map +0 -1
- package/dist/core/sheet/DataEditor.js.map +0 -1
- package/dist/core/sheet/DefaultCell.js.map +0 -1
- package/dist/core/sheet/DefaultRow.js.map +0 -1
- package/dist/core/sheet/DefaultRowMapper.js.map +0 -1
- package/dist/core/sheet/DefaultShell.js.map +0 -1
- package/dist/core/sheet/Event.js.map +0 -1
- package/dist/core/sheet/ValueViewer.js.map +0 -1
- package/dist/core/sheet/index.js.map +0 -1
- package/dist/core/sheet/useCellEvent.js.map +0 -1
- package/dist/core/sheet/useContextMenu.js.map +0 -1
- package/dist/core/sheet/useKeyBoardEvent.js.map +0 -1
- package/dist/core/sheet/useMouseEvent.js.map +0 -1
- package/dist/core/sheet/useVirtualList.js.map +0 -1
- package/dist/core/shell/draggableShell/index.js.map +0 -1
- package/dist/core/shell/tableShell.js.map +0 -1
- package/dist/core/table/index.js.map +0 -1
- package/dist/core/table/useGroupConfig.js.map +0 -1
- package/dist/core/table/useRowSelection.js.map +0 -1
- package/dist/core/table/util.js.map +0 -1
- package/dist/core/util.js.map +0 -1
- package/dist/core/viewer/btnViewer/index.js.map +0 -1
- package/dist/core/viewer/checkViewer/index.js.map +0 -1
- package/dist/core/viewer/editViewer/index.js.map +0 -1
- package/dist/core/viewer/groupViewer/index.js.map +0 -1
- package/dist/core/viewer/index.js.map +0 -1
- package/dist/core/viewer/switchViewer/index.js.map +0 -1
- package/dist/example/antComponent.js.map +0 -1
- package/dist/example/basic.js.map +0 -1
- package/dist/example/ellipsis.js.map +0 -1
- package/dist/example/fixed.js.map +0 -1
- package/dist/example/group.js.map +0 -1
- package/dist/example/selection.js.map +0 -1
- package/dist/example/sheet.js.map +0 -1
- package/dist/example/valuationAnalyze.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useEventBus.js.map +0 -1
- package/dist/hooks/useKeyboard.js.map +0 -1
- package/dist/hooks/useMiddlewareReducer.js.map +0 -1
- package/dist/hooks/useMouse.js.map +0 -1
- package/dist/hooks/useSetState.js.map +0 -1
- package/dist/hooks/useSheetEvent.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/standardUtils/index.js.map +0 -1
- package/dist/type/index.js.map +0 -1
- package/dist/type/sheet.js.map +0 -1
- package/dist/type/sheetTable.js.map +0 -1
package/README.md
CHANGED
package/dist/core/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Cascader } from 'antd';
|
|
2
2
|
import 'antd/es/cascader/style/index.css';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { optionsToValuesFromLabelOrValue, valuesTransferToLabel } from "../../util";
|
|
5
5
|
import "./index.less";
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
var getCascaderEditor = function getCascaderEditor(options) {
|
|
@@ -9,10 +9,10 @@ var getCascaderEditor = function getCascaderEditor(options) {
|
|
|
9
9
|
var value = props.value,
|
|
10
10
|
onConfirm = props.onConfirm;
|
|
11
11
|
var val = useMemo(function () {
|
|
12
|
-
|
|
12
|
+
var res = optionsToValuesFromLabelOrValue(options, value);
|
|
13
|
+
return res;
|
|
13
14
|
}, [value, options]);
|
|
14
15
|
var handleChange = function handleChange(opt) {
|
|
15
|
-
console.log(opt);
|
|
16
16
|
onConfirm(opt ? opt[opt.length - 1] : null);
|
|
17
17
|
};
|
|
18
18
|
return /*#__PURE__*/_jsx(Cascader, {
|
|
@@ -35,11 +35,18 @@ var getCascaderEditor = function getCascaderEditor(options) {
|
|
|
35
35
|
options: options
|
|
36
36
|
});
|
|
37
37
|
};
|
|
38
|
+
CascaderEditor.formatter = function (value) {
|
|
39
|
+
var res = optionsToValuesFromLabelOrValue(options, value);
|
|
40
|
+
return !(res !== null && res !== void 0 && res.length) ? '' : valuesTransferToLabel(options, res[res.length - 1]);
|
|
41
|
+
};
|
|
42
|
+
CascaderEditor.parser = function (value) {
|
|
43
|
+
var res = optionsToValuesFromLabelOrValue(options, value);
|
|
44
|
+
return res.length ? res[res.length - 1] : null;
|
|
45
|
+
};
|
|
38
46
|
CascaderEditor.checker = function (value) {
|
|
39
|
-
var res =
|
|
40
|
-
return res
|
|
47
|
+
var res = optionsToValuesFromLabelOrValue(options, value);
|
|
48
|
+
return !!res.length;
|
|
41
49
|
};
|
|
42
50
|
return CascaderEditor;
|
|
43
51
|
};
|
|
44
|
-
export default getCascaderEditor;
|
|
45
|
-
//# sourceMappingURL=index.js.map
|
|
52
|
+
export default getCascaderEditor;
|
|
@@ -2,4 +2,4 @@ import { DatePickerProps } from 'antd';
|
|
|
2
2
|
import 'antd/es/date-picker/style/index.css';
|
|
3
3
|
import type { SheetType } from "../../../type";
|
|
4
4
|
import './index.less';
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const getDateEditor: (dateProps?: Pick<DatePickerProps, 'disabledDate' | 'disabled' | 'allowClear' | 'placeholder'>) => SheetType.CellEditor;
|
|
@@ -10,7 +10,7 @@ import moment from 'moment';
|
|
|
10
10
|
import { useEffect, useMemo, useRef } from 'react';
|
|
11
11
|
import "./index.less";
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
export var
|
|
13
|
+
export var getDateEditor = function getDateEditor(dateProps) {
|
|
14
14
|
var DateEditor = function DateEditor(props) {
|
|
15
15
|
var value = props.value,
|
|
16
16
|
onChange = props.onChange,
|
|
@@ -48,5 +48,4 @@ export var GetDateEditor = function GetDateEditor(dateProps) {
|
|
|
48
48
|
return value.replace('/', '-').replace('/', '-');
|
|
49
49
|
};
|
|
50
50
|
return DateEditor;
|
|
51
|
-
};
|
|
52
|
-
//# sourceMappingURL=index.js.map
|
|
51
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as getCascaderEditor } from './cascaderEditor';
|
|
2
|
-
export {
|
|
2
|
+
export { getDateEditor } from './dateEditor';
|
|
3
3
|
export { getNumberEditor, NumberEditor } from './numberEditor';
|
|
4
4
|
export { default as getSelectEditor } from './selectEditor';
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { default as getCascaderEditor } from "./cascaderEditor";
|
|
2
|
-
export {
|
|
2
|
+
export { getDateEditor } from "./dateEditor";
|
|
3
3
|
export { getNumberEditor, NumberEditor } from "./numberEditor";
|
|
4
|
-
export { default as getSelectEditor } from "./selectEditor";
|
|
5
|
-
//# sourceMappingURL=index.js.map
|
|
4
|
+
export { default as getSelectEditor } from "./selectEditor";
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
var _excluded = ["precision"];
|
|
2
3
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
4
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
6
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
7
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
9
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
10
|
+
import { formatPrecision } from "../../../standardUtils";
|
|
7
11
|
import { InputNumber as AntInputNumber } from 'antd';
|
|
8
12
|
import 'antd/es/input-number/style/index.css';
|
|
9
13
|
import { isNil } from 'lodash';
|
|
10
|
-
import { useEffect, useRef } from 'react';
|
|
14
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
11
15
|
import "./index.less";
|
|
12
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
17
|
export var NumberEditor = function NumberEditor(props) {
|
|
@@ -39,21 +43,61 @@ export var getNumberEditor = function getNumberEditor(extraProps) {
|
|
|
39
43
|
var _inputNumberRef$curre2;
|
|
40
44
|
inputNumberRef === null || inputNumberRef === void 0 ? void 0 : (_inputNumberRef$curre2 = inputNumberRef.current) === null || _inputNumberRef$curre2 === void 0 ? void 0 : _inputNumberRef$curre2.focus();
|
|
41
45
|
}, []);
|
|
46
|
+
var _ref = extraProps || {},
|
|
47
|
+
precision = _ref.precision,
|
|
48
|
+
inputArgs = _objectWithoutProperties(_ref, _excluded);
|
|
49
|
+
var valueFormatter = useCallback(function (value) {
|
|
50
|
+
if (!value) {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === 'string') {
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
var hasDecimal = value - Math.floor(value) > 0;
|
|
57
|
+
if (hasDecimal) {
|
|
58
|
+
return formatPrecision(value, precision);
|
|
59
|
+
}
|
|
60
|
+
return String(value);
|
|
61
|
+
}, []);
|
|
62
|
+
var handleChange = useCallback(function (value) {
|
|
63
|
+
onChange && onChange(value ? value : null);
|
|
64
|
+
}, [onChange]);
|
|
42
65
|
return /*#__PURE__*/_jsx(AntInputNumber, _objectSpread(_objectSpread({
|
|
43
66
|
ref: inputNumberRef
|
|
44
|
-
},
|
|
67
|
+
}, inputArgs), {}, {
|
|
68
|
+
formatter: valueFormatter,
|
|
45
69
|
controls: false,
|
|
46
70
|
className: "number-editor",
|
|
47
71
|
onMouseDown: function onMouseDown(e) {
|
|
48
72
|
return e.stopPropagation();
|
|
49
73
|
},
|
|
50
74
|
value: value,
|
|
51
|
-
onChange:
|
|
75
|
+
onChange: handleChange
|
|
52
76
|
}));
|
|
53
77
|
};
|
|
54
78
|
NumberEditor.formatter = function (value) {
|
|
55
|
-
|
|
79
|
+
var _String;
|
|
80
|
+
if (isNil(value) || isNaN(value)) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
var result = parseFloat((_String = String(value)) === null || _String === void 0 ? void 0 : _String.replace(/,/g, ''));
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
NumberEditor.parser = function (value) {
|
|
87
|
+
var _extraProps$precision;
|
|
88
|
+
if (isNil(value) || isNaN(value)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return Number(formatPrecision(value, (_extraProps$precision = extraProps === null || extraProps === void 0 ? void 0 : extraProps.precision) !== null && _extraProps$precision !== void 0 ? _extraProps$precision : 0));
|
|
92
|
+
};
|
|
93
|
+
NumberEditor.checker = function (value) {
|
|
94
|
+
var _String2;
|
|
95
|
+
// parse number with thousands separator
|
|
96
|
+
var result = parseFloat((_String2 = String(value)) === null || _String2 === void 0 ? void 0 : _String2.replace(/,/g, ''));
|
|
97
|
+
if (isNaN(result) || isNaN(value)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
56
101
|
};
|
|
57
102
|
return NumberEditor;
|
|
58
|
-
};
|
|
59
|
-
//# sourceMappingURL=index.js.map
|
|
103
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SheetType } from "../../../type";
|
|
2
2
|
import 'antd/es/select/style/index.css';
|
|
3
3
|
import './index.less';
|
|
4
|
-
export declare const getSelectEditor: (options: SheetType.Options[], valueKey?: string) => SheetType.CellEditor;
|
|
4
|
+
export declare const getSelectEditor: (options: SheetType.Options[], valueKey?: string, extra?: React.ReactNode) => SheetType.CellEditor;
|
|
5
5
|
export default getSelectEditor;
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { Select } from 'antd';
|
|
4
4
|
import 'antd/es/select/style/index.css';
|
|
5
|
+
import { isNil } from 'lodash';
|
|
5
6
|
import "./index.less";
|
|
7
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
6
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
10
|
export var getSelectEditor = function getSelectEditor(options) {
|
|
8
|
-
var valueKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '
|
|
11
|
+
var valueKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'value';
|
|
12
|
+
var extra = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : /*#__PURE__*/_jsx(_Fragment, {});
|
|
9
13
|
var SelectEditor = function SelectEditor(props) {
|
|
10
14
|
var value = props.value,
|
|
11
15
|
onConfirm = props.onConfirm;
|
|
@@ -19,6 +23,11 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
19
23
|
ev.persist();
|
|
20
24
|
}
|
|
21
25
|
};
|
|
26
|
+
var dropdown = function dropdown(menu) {
|
|
27
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
28
|
+
children: [menu, extra]
|
|
29
|
+
});
|
|
30
|
+
};
|
|
22
31
|
return /*#__PURE__*/_jsx(Select, {
|
|
23
32
|
autoFocus: true,
|
|
24
33
|
className: "select-editor",
|
|
@@ -32,17 +41,19 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
32
41
|
onChange: handleChange,
|
|
33
42
|
onKeyDown: handleKeyDown,
|
|
34
43
|
options: options,
|
|
35
|
-
popupClassName: 'excelTablePopupClassName'
|
|
44
|
+
popupClassName: 'excelTablePopupClassName',
|
|
45
|
+
dropdownRender: dropdown
|
|
36
46
|
});
|
|
37
47
|
};
|
|
38
48
|
SelectEditor.checker = function (value) {
|
|
49
|
+
if (isNil(value)) return true;
|
|
39
50
|
return options.some(function (item) {
|
|
40
51
|
return item.value == value;
|
|
41
52
|
}) || options.some(function (item) {
|
|
42
53
|
return item.label === value;
|
|
43
54
|
});
|
|
44
55
|
};
|
|
45
|
-
SelectEditor.
|
|
56
|
+
SelectEditor.parser = function (value) {
|
|
46
57
|
var _options$find, _options$find2;
|
|
47
58
|
return ((_options$find = options.find(function (item) {
|
|
48
59
|
return item.value == value;
|
|
@@ -50,7 +61,14 @@ export var getSelectEditor = function getSelectEditor(options) {
|
|
|
50
61
|
return item.label === value;
|
|
51
62
|
})) === null || _options$find2 === void 0 ? void 0 : _options$find2[valueKey]);
|
|
52
63
|
};
|
|
64
|
+
SelectEditor.formatter = function (value) {
|
|
65
|
+
var _options$find3, _options$find4;
|
|
66
|
+
return ((_options$find3 = options.find(function (item) {
|
|
67
|
+
return item.value == value;
|
|
68
|
+
})) === null || _options$find3 === void 0 ? void 0 : _options$find3.label) || ((_options$find4 = options.find(function (item) {
|
|
69
|
+
return item.label === value;
|
|
70
|
+
})) === null || _options$find4 === void 0 ? void 0 : _options$find4.label);
|
|
71
|
+
};
|
|
53
72
|
return SelectEditor;
|
|
54
73
|
};
|
|
55
|
-
export default getSelectEditor;
|
|
56
|
-
//# sourceMappingURL=index.js.map
|
|
74
|
+
export default getSelectEditor;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SheetType } from "../../type";
|
|
2
|
-
export declare type SheetAction = 'change' | 'changes' | 'rowMove' | 'colMove' | 'editFinish' | 'pushHistory' | 'selectRow' | 'clearSelect' | 'clearSelectIfNotSingleRow' | 'clearEdit' | 'mouseDown' | 'mouseOver' | 'mouseUp' | 'loseFocus' | 'doubleClick' | 'mouseLeaveInterval' | 'move' | 'escape' | 'reverse' | 'delete' | 'enter' | 'otherInput' | 'none';
|
|
2
|
+
export declare type SheetAction = 'change' | 'changes' | 'rowMove' | 'colMove' | 'editFinish' | 'pushHistory' | 'popHistory' | 'selectRow' | 'select' | 'clearSelect' | 'clearSelectIfNotSingleRow' | 'clearEdit' | 'mouseDown' | 'mouseOver' | 'mouseUp' | 'loseFocus' | 'doubleClick' | 'mouseLeaveInterval' | 'move' | 'escape' | 'reverse' | 'delete' | 'enter' | 'otherInput' | 'none';
|
|
3
3
|
export declare type reducerAction = (type: Partial<SheetType.UpdateStateType>, payload?: unknown) => Partial<SheetType.UpdateStateType>;
|
|
4
4
|
declare const sheetReducer: (state: Partial<SheetType.UpdateStateType>, action: {
|
|
5
5
|
type: SheetAction;
|
|
@@ -9,7 +9,9 @@ var sheetReducer = function sheetReducer(state, action) {
|
|
|
9
9
|
case 'colMove':
|
|
10
10
|
case 'editFinish':
|
|
11
11
|
case 'pushHistory':
|
|
12
|
+
case 'popHistory':
|
|
12
13
|
case 'selectRow':
|
|
14
|
+
case 'select':
|
|
13
15
|
case 'clearSelect':
|
|
14
16
|
case 'clearSelectIfNotSingleRow':
|
|
15
17
|
case 'clearEdit':
|
|
@@ -33,5 +35,4 @@ var sheetReducer = function sheetReducer(state, action) {
|
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
37
|
export default sheetReducer;
|
|
36
|
-
export { sideEffectReducer } from "./sideEffectReducer";
|
|
37
|
-
//# sourceMappingURL=index.js.map
|
|
38
|
+
export { sideEffectReducer } from "./sideEffectReducer";
|
|
@@ -17,7 +17,7 @@ export var keyboardReducer = {
|
|
|
17
17
|
data = _state$data === void 0 ? [] : _state$data;
|
|
18
18
|
var newRow = (((_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.row) || 0) + row;
|
|
19
19
|
if (groupConfig) {
|
|
20
|
-
newRow = getNextVisibleRow(newRow, data.length, groupConfigToGroupMap(groupConfig));
|
|
20
|
+
newRow = getNextVisibleRow(newRow, data.length, groupConfigToGroupMap(groupConfig), row < 0 ? -1 : 1);
|
|
21
21
|
}
|
|
22
22
|
var currentPos = {
|
|
23
23
|
row: newRow,
|
|
@@ -90,5 +90,4 @@ export var keyboardReducer = {
|
|
|
90
90
|
if (state.editing) return state;
|
|
91
91
|
return keyboardReducer.enter(state, payload);
|
|
92
92
|
}
|
|
93
|
-
};
|
|
94
|
-
//# sourceMappingURL=keyboardReducer.js.map
|
|
93
|
+
};
|
|
@@ -23,13 +23,13 @@ export var sideEffectReducer = {
|
|
|
23
23
|
dispatch(function () {
|
|
24
24
|
var _getState2 = getState(),
|
|
25
25
|
cellChangeHandler = _getState2.cellChangeHandler;
|
|
26
|
-
cellChangeHandler && cellChangeHandler([cell]);
|
|
27
26
|
dispatch({
|
|
28
27
|
type: 'editFinish',
|
|
29
28
|
payload: {
|
|
30
29
|
cell: cell
|
|
31
30
|
}
|
|
32
31
|
});
|
|
32
|
+
cellChangeHandler && cellChangeHandler([cell]);
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
eventBus.on('cell-create', function (_ref) {
|
|
@@ -131,9 +131,13 @@ export var sideEffectReducer = {
|
|
|
131
131
|
end = _getState7.end,
|
|
132
132
|
data = _getState7.data,
|
|
133
133
|
groupConfig = _getState7.groupConfig;
|
|
134
|
+
if (!start || !end) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
134
137
|
var cellIndex = flatRowColIndex(start, end);
|
|
135
138
|
var groupMap = groupConfigToGroupMap(groupConfig);
|
|
136
139
|
var copyData = cellIndex.reduce(function (left, _ref3) {
|
|
140
|
+
var _data$row$col$dataEdi, _data$row$col$dataEdi2, _data$row$col$dataEdi3;
|
|
137
141
|
var _ref3$row = _ref3.row,
|
|
138
142
|
row = _ref3$row === void 0 ? 0 : _ref3$row,
|
|
139
143
|
_ref3$col = _ref3.col,
|
|
@@ -150,7 +154,9 @@ export var sideEffectReducer = {
|
|
|
150
154
|
};
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
|
-
|
|
157
|
+
|
|
158
|
+
// 复制到剪贴板的时候执行 formatter
|
|
159
|
+
var currentValue = "".concat(value).concat(currentRow === row ? '\t' : '\n', " ").concat((_data$row$col$dataEdi = data[row][col].dataEditor) !== null && _data$row$col$dataEdi !== void 0 && _data$row$col$dataEdi.formatter ? (_data$row$col$dataEdi2 = data[row][col].dataEditor) === null || _data$row$col$dataEdi2 === void 0 ? void 0 : (_data$row$col$dataEdi3 = _data$row$col$dataEdi2.formatter) === null || _data$row$col$dataEdi3 === void 0 ? void 0 : _data$row$col$dataEdi3.call(_data$row$col$dataEdi2, data[row][col].value) : defaultValueRenderer(data[row][col]));
|
|
154
160
|
return {
|
|
155
161
|
currentRow: row,
|
|
156
162
|
value: currentValue
|
|
@@ -164,14 +170,21 @@ export var sideEffectReducer = {
|
|
|
164
170
|
},
|
|
165
171
|
paste: function paste(dispatch, getState) {
|
|
166
172
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
167
|
-
var
|
|
173
|
+
var _extChanges$;
|
|
174
|
+
var _getState8, start, end, cellChangeHandler, history, _getState8$freePaste, freePaste, data, groupConfig, pasteData, changeInfo, changes, extChanges, legalChanges, lastRow, lastIndex, legalExtChanges, newHistory;
|
|
168
175
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
169
176
|
while (1) switch (_context.prev = _context.next) {
|
|
170
177
|
case 0:
|
|
171
178
|
_getState8 = getState(), start = _getState8.start, end = _getState8.end, cellChangeHandler = _getState8.cellChangeHandler, history = _getState8.history, _getState8$freePaste = _getState8.freePaste, freePaste = _getState8$freePaste === void 0 ? false : _getState8$freePaste, data = _getState8.data, groupConfig = _getState8.groupConfig;
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
if (!(!start || !end)) {
|
|
180
|
+
_context.next = 3;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
return _context.abrupt("return");
|
|
174
184
|
case 3:
|
|
185
|
+
_context.next = 5;
|
|
186
|
+
return clipboardDataToString();
|
|
187
|
+
case 5:
|
|
175
188
|
pasteData = _context.sent;
|
|
176
189
|
changeInfo = formatDataToCell(_objectSpread(_objectSpread({}, pick(getState(), ['data', 'start', 'end', 'editing'])), {}, {
|
|
177
190
|
pasteData: pasteData,
|
|
@@ -179,11 +192,11 @@ export var sideEffectReducer = {
|
|
|
179
192
|
freePaste: freePaste
|
|
180
193
|
}));
|
|
181
194
|
if (changeInfo) {
|
|
182
|
-
_context.next =
|
|
195
|
+
_context.next = 9;
|
|
183
196
|
break;
|
|
184
197
|
}
|
|
185
198
|
return _context.abrupt("return");
|
|
186
|
-
case
|
|
199
|
+
case 9:
|
|
187
200
|
changes = changeInfo.changes, extChanges = changeInfo.extChanges;
|
|
188
201
|
legalChanges = changes.filter(function (_ref4) {
|
|
189
202
|
var row = _ref4.row,
|
|
@@ -191,11 +204,11 @@ export var sideEffectReducer = {
|
|
|
191
204
|
value = _ref4.value;
|
|
192
205
|
var editor = data[row][col].dataEditor;
|
|
193
206
|
if (editor && editor.checker) {
|
|
194
|
-
return editor.checker(value);
|
|
207
|
+
return editor.checker(value, data[row][col].record);
|
|
195
208
|
}
|
|
196
209
|
return true;
|
|
197
210
|
}).map(function (_ref5) {
|
|
198
|
-
var _editor$
|
|
211
|
+
var _data$row$col, _editor$parser;
|
|
199
212
|
var row = _ref5.row,
|
|
200
213
|
col = _ref5.col,
|
|
201
214
|
value = _ref5.value;
|
|
@@ -203,9 +216,12 @@ export var sideEffectReducer = {
|
|
|
203
216
|
return {
|
|
204
217
|
row: row,
|
|
205
218
|
col: col,
|
|
206
|
-
|
|
219
|
+
id: (_data$row$col = data[row][col]) === null || _data$row$col === void 0 ? void 0 : _data$row$col.id,
|
|
220
|
+
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
|
|
207
221
|
};
|
|
208
222
|
});
|
|
223
|
+
lastRow = extChanges === null || extChanges === void 0 ? void 0 : (_extChanges$ = extChanges[0]) === null || _extChanges$ === void 0 ? void 0 : _extChanges$.row;
|
|
224
|
+
lastIndex = 1;
|
|
209
225
|
legalExtChanges = extChanges === null || extChanges === void 0 ? void 0 : extChanges.filter(function (_ref6) {
|
|
210
226
|
var value = _ref6.value,
|
|
211
227
|
col = _ref6.col;
|
|
@@ -214,8 +230,23 @@ export var sideEffectReducer = {
|
|
|
214
230
|
return editor.checker(value);
|
|
215
231
|
}
|
|
216
232
|
return true;
|
|
233
|
+
}).map(function (_ref7) {
|
|
234
|
+
var _editor$parser2;
|
|
235
|
+
var row = _ref7.row,
|
|
236
|
+
col = _ref7.col,
|
|
237
|
+
value = _ref7.value;
|
|
238
|
+
var editor = data[0][col].dataEditor;
|
|
239
|
+
if (lastRow !== row) {
|
|
240
|
+
lastRow = row;
|
|
241
|
+
lastIndex++;
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
row: row,
|
|
245
|
+
col: col,
|
|
246
|
+
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 ? void 0 : (_editor$parser2 = editor.parser) === null || _editor$parser2 === void 0 ? void 0 : _editor$parser2.call(editor, value) : value,
|
|
247
|
+
id: -lastIndex
|
|
248
|
+
};
|
|
217
249
|
});
|
|
218
|
-
cellChangeHandler && cellChangeHandler(legalChanges, legalExtChanges);
|
|
219
250
|
newHistory = _toConsumableArray(history || []);
|
|
220
251
|
newHistory.push({
|
|
221
252
|
changes: legalChanges.map(function (item) {
|
|
@@ -237,7 +268,8 @@ export var sideEffectReducer = {
|
|
|
237
268
|
}
|
|
238
269
|
}
|
|
239
270
|
});
|
|
240
|
-
|
|
271
|
+
cellChangeHandler && cellChangeHandler(legalChanges, freePaste ? legalExtChanges : []);
|
|
272
|
+
case 18:
|
|
241
273
|
case "end":
|
|
242
274
|
return _context.stop();
|
|
243
275
|
}
|
|
@@ -265,12 +297,13 @@ export var sideEffectReducer = {
|
|
|
265
297
|
var _groupMap$get3, _groupMap$get4;
|
|
266
298
|
return !(groupMap.get(item.row) && !((_groupMap$get3 = groupMap.get(item.row)) !== null && _groupMap$get3 !== void 0 && _groupMap$get3.isStart) && !((_groupMap$get4 = groupMap.get(item.row)) !== null && _groupMap$get4 !== void 0 && _groupMap$get4.isOpen));
|
|
267
299
|
}).map(function (item) {
|
|
268
|
-
var _data$item$row2;
|
|
300
|
+
var _data$item$row2, _data$item$row3;
|
|
269
301
|
return {
|
|
270
302
|
cell: data === null || data === void 0 ? void 0 : (_data$item$row2 = data[item.row]) === null || _data$item$row2 === void 0 ? void 0 : _data$item$row2[item.col],
|
|
271
303
|
row: item.row,
|
|
272
304
|
col: item.col,
|
|
273
|
-
value:
|
|
305
|
+
value: null,
|
|
306
|
+
id: data === null || data === void 0 ? void 0 : (_data$item$row3 = data[item.row]) === null || _data$item$row3 === void 0 ? void 0 : _data$item$row3[item.col].id
|
|
274
307
|
};
|
|
275
308
|
});
|
|
276
309
|
var newHistory = _toConsumableArray(history || []);
|
|
@@ -282,13 +315,13 @@ export var sideEffectReducer = {
|
|
|
282
315
|
}),
|
|
283
316
|
type: 'Delete'
|
|
284
317
|
});
|
|
285
|
-
cellChangeHandler && cellChangeHandler(changes);
|
|
286
318
|
dispatch({
|
|
287
319
|
type: 'changes',
|
|
288
320
|
payload: {
|
|
289
321
|
history: newHistory
|
|
290
322
|
}
|
|
291
323
|
});
|
|
324
|
+
cellChangeHandler && cellChangeHandler(changes);
|
|
292
325
|
},
|
|
293
326
|
reverse: function reverse(dispatch, getState) {
|
|
294
327
|
var _getState10 = getState(),
|
|
@@ -298,19 +331,11 @@ export var sideEffectReducer = {
|
|
|
298
331
|
cellChangeHandler = _getState10.cellChangeHandler,
|
|
299
332
|
eventBus = _getState10.eventBus;
|
|
300
333
|
if (!(history !== null && history !== void 0 && history.length)) return;
|
|
301
|
-
console.log(history.length);
|
|
302
334
|
var changeHistory = _toConsumableArray(history);
|
|
303
335
|
var change = changeHistory.pop();
|
|
304
336
|
var type = change.type;
|
|
305
337
|
if (!['Edit', 'Paste', 'Delete'].includes(type)) {
|
|
306
338
|
eventBus.emit('reverse', change);
|
|
307
|
-
if (type === 'DeleteRow') {
|
|
308
|
-
// console.log(change.rowInfo?.deleteRow);
|
|
309
|
-
// dispatch({
|
|
310
|
-
// type: 'selectRow',
|
|
311
|
-
// payload: change.rowInfo?.deleteRow as number,
|
|
312
|
-
// });
|
|
313
|
-
}
|
|
314
339
|
dispatch({
|
|
315
340
|
type: 'changes',
|
|
316
341
|
payload: {
|
|
@@ -333,5 +358,4 @@ export var sideEffectReducer = {
|
|
|
333
358
|
}
|
|
334
359
|
});
|
|
335
360
|
}
|
|
336
|
-
};
|
|
337
|
-
//# sourceMappingURL=sideEffectReducer.js.map
|
|
361
|
+
};
|
|
@@ -10,7 +10,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
10
10
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
11
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
12
12
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
13
|
-
import { SheetType } from "
|
|
13
|
+
import { SheetType } from "../..";
|
|
14
14
|
export var stateReducer = {
|
|
15
15
|
change: function change(state, payload) {
|
|
16
16
|
var _ref = payload,
|
|
@@ -52,15 +52,16 @@ export var stateReducer = {
|
|
|
52
52
|
_ref2$cell = _ref2.cell,
|
|
53
53
|
row = _ref2$cell.row,
|
|
54
54
|
col = _ref2$cell.col,
|
|
55
|
-
confirm = _ref2$cell.confirm
|
|
55
|
+
confirm = _ref2$cell.confirm,
|
|
56
|
+
id = _ref2$cell.id;
|
|
56
57
|
var history = _toConsumableArray(state.history || []);
|
|
57
58
|
var current = data === null || data === void 0 ? void 0 : (_data$row = data[row]) === null || _data$row === void 0 ? void 0 : _data$row[col].value;
|
|
58
|
-
console.log(history.length, current);
|
|
59
59
|
history.push({
|
|
60
60
|
changes: [{
|
|
61
61
|
row: row,
|
|
62
62
|
col: col,
|
|
63
|
-
value: current
|
|
63
|
+
value: current,
|
|
64
|
+
id: id
|
|
64
65
|
}],
|
|
65
66
|
type: 'Edit'
|
|
66
67
|
});
|
|
@@ -75,19 +76,43 @@ export var stateReducer = {
|
|
|
75
76
|
history: history
|
|
76
77
|
});
|
|
77
78
|
},
|
|
79
|
+
popHistory: function popHistory(state) {
|
|
80
|
+
var _state$history = state.history,
|
|
81
|
+
history = _state$history === void 0 ? [] : _state$history;
|
|
82
|
+
var newHistory = _toConsumableArray(history);
|
|
83
|
+
newHistory.pop();
|
|
84
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
85
|
+
history: newHistory
|
|
86
|
+
});
|
|
87
|
+
},
|
|
78
88
|
pushHistory: function pushHistory(state, payload) {
|
|
79
89
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
80
90
|
history: [].concat(_toConsumableArray(state.history || []), [payload])
|
|
81
91
|
});
|
|
82
92
|
},
|
|
93
|
+
select: function select(state, payload) {
|
|
94
|
+
var oldStart = state.start,
|
|
95
|
+
oldEnd = state.end;
|
|
96
|
+
var _ref3 = payload,
|
|
97
|
+
start = _ref3.start,
|
|
98
|
+
end = _ref3.end;
|
|
99
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
100
|
+
start: start,
|
|
101
|
+
end: end,
|
|
102
|
+
lastSelected: {
|
|
103
|
+
start: oldStart,
|
|
104
|
+
end: oldEnd
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
},
|
|
83
108
|
selectRow: function selectRow(state, payload) {
|
|
84
|
-
var _state$data4, _state$data4$, _state$data5, _state$data5$;
|
|
109
|
+
var _state$data4, _state$data4$, _state$data5, _state$data5$, _state$data6, _state$data6$;
|
|
85
110
|
var startCol = ((_state$data4 = state.data) === null || _state$data4 === void 0 ? void 0 : (_state$data4$ = _state$data4[0]) === null || _state$data4$ === void 0 ? void 0 : _state$data4$.findIndex(function (item) {
|
|
86
111
|
return !item.fixed;
|
|
87
112
|
})) || 0;
|
|
88
113
|
var endCol = (((_state$data5 = state.data) === null || _state$data5 === void 0 ? void 0 : (_state$data5$ = _state$data5[0]) === null || _state$data5$ === void 0 ? void 0 : _state$data5$.findIndex(function (item) {
|
|
89
114
|
return item.fixed === SheetType.CellAlign.right;
|
|
90
|
-
})) || 0) - 1;
|
|
115
|
+
})) || ((_state$data6 = state.data) === null || _state$data6 === void 0 ? void 0 : (_state$data6$ = _state$data6[0]) === null || _state$data6$ === void 0 ? void 0 : _state$data6$.length) || 0) - 1;
|
|
91
116
|
// const endCol = (state.data?.[0].length || 0) - 1;
|
|
92
117
|
if (startCol >= 0 && endCol >= 0) {
|
|
93
118
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
@@ -122,8 +147,8 @@ export var stateReducer = {
|
|
|
122
147
|
clearSelectIfNotSingleRow: function clearSelectIfNotSingleRow(state) {
|
|
123
148
|
var start = state.start,
|
|
124
149
|
end = state.end;
|
|
125
|
-
if ((start === null || start === void 0 ? void 0 : start.row) === (end === null || end === void 0 ? void 0 : end.row)) {
|
|
126
|
-
return
|
|
150
|
+
if (!start || !end || (start === null || start === void 0 ? void 0 : start.row) === (end === null || end === void 0 ? void 0 : end.row)) {
|
|
151
|
+
return state;
|
|
127
152
|
}
|
|
128
153
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
129
154
|
start: undefined,
|
|
@@ -136,10 +161,10 @@ export var stateReducer = {
|
|
|
136
161
|
},
|
|
137
162
|
clearEdit: function clearEdit(state) {
|
|
138
163
|
var editing = state.editing;
|
|
164
|
+
if (!editing) return state;
|
|
139
165
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
140
166
|
editing: undefined,
|
|
141
167
|
lastEditing: editing
|
|
142
168
|
});
|
|
143
169
|
}
|
|
144
|
-
};
|
|
145
|
-
//# sourceMappingURL=stateReducer.js.map
|
|
170
|
+
};
|