@zhenliang/sheet 0.1.89 → 0.1.90-beta.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.
@@ -2,7 +2,13 @@ import type { SheetType } from "../../../type";
2
2
  import { InputNumberProps } from 'antd';
3
3
  import 'antd/es/input-number/style/index.css';
4
4
  import './index.less';
5
- type inputProps = Partial<Pick<InputNumberProps, 'max' | 'min' | 'addonBefore' | 'addonAfter' | 'precision'>>;
5
+ type inputProps = Partial<Pick<InputNumberProps, 'max' | 'min' | 'addonBefore' | 'addonAfter' | 'precision'> & {
6
+ warnMethod?: (record: any) => void;
7
+ rangeMethod?: (record: any) => {
8
+ max: number;
9
+ min: number;
10
+ };
11
+ }>;
6
12
  export declare const NumberEditor: SheetType.CellEditor;
7
13
  export declare const getNumberEditor: (extraProps?: inputProps, getExtraProps?: ((props: SheetType.CellEditorProps) => inputProps) | undefined) => SheetType.CellEditor;
8
14
  export {};
@@ -1,22 +1,38 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["precision"];
3
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
4
  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; }
6
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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; }
7
+ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
10
8
  import { formatPrecision } from "../../../standardUtils";
11
- import { InputNumber as AntInputNumber } from 'antd';
9
+ import { InputNumber as AntInputNumber, Input } from 'antd';
12
10
  import 'antd/es/input-number/style/index.css';
13
- import { isNil, isNumber } from 'lodash';
11
+ import { isNil } from 'lodash';
12
+ import { evaluate } from 'mathjs';
14
13
  import { useCallback, useEffect, useRef } from 'react';
15
14
  import "./index.less";
16
15
  import { jsx as _jsx } from "react/jsx-runtime";
17
- var isNumeric = function isNumeric(str) {
18
- // 使用正则表达式匹配数字,包括整数和小数
19
- return /^-?\d+(\.\d+)?$/.test(str);
16
+ var formulaString = function formulaString(value, currentValue, precision, max, min, isEdit) {
17
+ var curNumber = currentValue !== null && currentValue !== void 0 ? currentValue : 0;
18
+ var formula = String(value).replace('=', '').replace(/x/g, String(curNumber));
19
+ try {
20
+ var result = evaluate(formula);
21
+ if (max && result > max) {
22
+ result = max;
23
+ } else if (min && result < min) {
24
+ result = min;
25
+ }
26
+ if (precision) {
27
+ result = formatPrecision(result);
28
+ }
29
+ return parseFloat(result);
30
+ } catch (_unused) {
31
+ if (isEdit) {
32
+ return Infinity;
33
+ }
34
+ return currentValue;
35
+ }
20
36
  };
21
37
  export var NumberEditor = function NumberEditor(props) {
22
38
  var value = props.value,
@@ -39,15 +55,19 @@ export var NumberEditor = function NumberEditor(props) {
39
55
  });
40
56
  };
41
57
  export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps) {
58
+ var _ref = extraProps || {},
59
+ warnMethod = _ref.warnMethod,
60
+ rangeMethod = _ref.rangeMethod,
61
+ precision = _ref.precision,
62
+ max = _ref.max,
63
+ min = _ref.min;
42
64
  var NumberEditor = function NumberEditor(props) {
65
+ var _ref3;
43
66
  var value = props.value,
44
67
  onChange = props.onChange;
45
68
  var inputNumberRef = useRef(null);
46
- var _ref = getExtraProps ? getExtraProps(props) : extraProps !== null && extraProps !== void 0 ? extraProps : {},
47
- precision = _ref.precision,
48
- inputArgs = _objectWithoutProperties(_ref, _excluded);
49
- var max = inputArgs.max,
50
- min = inputArgs.min;
69
+ var _ref2 = getExtraProps ? getExtraProps(props) : extraProps !== null && extraProps !== void 0 ? extraProps : {},
70
+ inputArgs = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
51
71
  var handleChange = useCallback(function (value) {
52
72
  onChange(!isNil(value) ? value : null);
53
73
  }, [onChange]);
@@ -55,57 +75,27 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
55
75
  var _inputNumberRef$curre2;
56
76
  inputNumberRef === null || inputNumberRef === void 0 || (_inputNumberRef$curre2 = inputNumberRef.current) === null || _inputNumberRef$curre2 === void 0 || _inputNumberRef$curre2.focus();
57
77
  }, []);
58
- var baseFormatter = useCallback(function (value) {
59
- if (!value) {
60
- return '';
61
- }
62
- if (!isNumeric("".concat(value))) {
63
- return value;
64
- }
65
- var hasDecimal = +value - Math.floor(+value) > 0;
66
- if (hasDecimal) {
67
- return formatPrecision(value, precision);
68
- }
69
- return String(value);
70
- }, []);
71
- // 去掉多余的0
72
- var valueFormatter = useCallback(function (value) {
73
- var baseValue = baseFormatter(value);
74
- return baseValue ? "".concat(parseFloat(baseValue)) : '';
75
- }, []);
76
- /**
77
- * 重新声明,后面有需求可以改一下
78
- */
79
- var valueParser = baseFormatter;
80
- return /*#__PURE__*/_jsx(AntInputNumber, _objectSpread(_objectSpread({
78
+ return /*#__PURE__*/_jsx(Input, _objectSpread(_objectSpread({
81
79
  ref: inputNumberRef
82
80
  }, inputArgs), {}, {
83
- formatter: valueFormatter,
84
- parser: valueParser,
85
- controls: false,
86
81
  className: "number-editor",
87
82
  onMouseDown: function onMouseDown(e) {
88
83
  return e.stopPropagation();
89
84
  },
90
- value: value,
91
- onChange: handleChange,
92
- onInput: function onInput(value) {
93
- // 将截断最大最小放到 input 事件中
94
- if (!isNumber(+value)) {
95
- return;
96
- }
97
- if (!value) {
98
- handleChange(null);
99
- return;
100
- }
101
- if (max && +value > max) {
102
- handleChange(max);
103
- } else if (min && +value < min) {
104
- handleChange(min);
105
- }
85
+ value: (_ref3 = value) !== null && _ref3 !== void 0 ? _ref3 : '',
86
+ onChange: function onChange(e) {
87
+ handleChange(e.target.value);
106
88
  }
107
89
  }));
108
90
  };
91
+ NumberEditor.formula = function (value, currentValue) {
92
+ if (isNil(value)) {
93
+ return null;
94
+ }
95
+ return formulaString(value, currentValue, precision, max, min, true);
96
+ };
97
+
98
+ // 复制的时候会触发
109
99
  NumberEditor.formatter = function (value) {
110
100
  var _String;
111
101
  if (isNil(value) || isNaN(value)) {
@@ -114,21 +104,36 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
114
104
  var result = parseFloat((_String = String(value)) === null || _String === void 0 ? void 0 : _String.replace(/,/g, ''));
115
105
  return result;
116
106
  };
117
- NumberEditor.parser = function (value) {
118
- var _String2, _extraProps$precision;
119
- var result = parseFloat((_String2 = String(value)) === null || _String2 === void 0 ? void 0 : _String2.replace(/,/g, ''));
107
+ // 粘贴上去的时候触发
108
+ NumberEditor.parser = function (value, currentValue) {
109
+ var _String2;
110
+ var result = (_String2 = String(value)) === null || _String2 === void 0 ? void 0 : _String2.replace(/,/g, '');
111
+ result = formulaString(result, currentValue);
120
112
  if (isNil(result) || isNaN(result)) {
121
113
  return null;
122
114
  }
123
- return Number(formatPrecision(result, (_extraProps$precision = extraProps === null || extraProps === void 0 ? void 0 : extraProps.precision) !== null && _extraProps$precision !== void 0 ? _extraProps$precision : 0));
115
+ return result;
124
116
  };
125
- NumberEditor.checker = function (value) {
117
+ NumberEditor.checker = function (value, record, currentValue) {
126
118
  var _String3;
127
119
  if (isNil(value)) {
128
120
  return true;
129
121
  }
122
+ var result = (_String3 = String(value)) === null || _String3 === void 0 ? void 0 : _String3.replace(/,/g, '');
123
+ result = formulaString(result, currentValue);
130
124
  // parse number with thousands separator
131
- var result = parseFloat((_String3 = String(value)) === null || _String3 === void 0 ? void 0 : _String3.replace(/,/g, ''));
125
+ var range = rangeMethod === null || rangeMethod === void 0 ? void 0 : rangeMethod(record);
126
+ if (!isNil(range === null || range === void 0 ? void 0 : range.max) && !isNil(range === null || range === void 0 ? void 0 : range.min)) {
127
+ var _ref4 = range || {},
128
+ _ref4$max = _ref4.max,
129
+ _max = _ref4$max === void 0 ? 0 : _ref4$max,
130
+ _ref4$min = _ref4.min,
131
+ _min = _ref4$min === void 0 ? 0 : _ref4$min;
132
+ if (result < _min || result > _max) {
133
+ warnMethod === null || warnMethod === void 0 || warnMethod(record);
134
+ return false;
135
+ }
136
+ }
132
137
  if (isNaN(result)) {
133
138
  return false;
134
139
  }
@@ -1,30 +1,30 @@
1
- .harvest-sheet-container .number-editor{
1
+ .harvest-sheet-container .number-editor {
2
2
  border: none !important;
3
3
  background: transparent !important;
4
- width:100%;
5
- height:var(--cell-inner-height) ;
6
- display: block;
7
- font-size: 12px;
4
+ width: 100% !important;
5
+ height: var(--cell-inner-height) !important;
6
+ display: block !important;
7
+ font-size: 12px !important;
8
8
  box-shadow: none !important;
9
9
  text-align: inherit !important;
10
-
11
- .ant-input-number-wrapper{
12
- text-align: inherit !important;
10
+ padding-left: 0;
13
11
 
12
+ .ant-input-number-wrapper {
13
+ text-align: inherit !important;
14
14
  }
15
15
 
16
- .ant-input-number-input{
16
+ .ant-input-number-input {
17
17
  text-align: inherit !important;
18
18
  }
19
19
 
20
- .ant-input-number-input-wrap >input{
21
- padding:0;
20
+ .ant-input-number-input-wrap > input {
21
+ padding: 0;
22
22
  height: 38px;
23
23
  }
24
-
25
- .ant-input-number-group-addon{
24
+
25
+ .ant-input-number-group-addon {
26
26
  background: transparent;
27
27
  border: none;
28
- padding:0
28
+ padding: 0;
29
29
  }
30
- }
30
+ }
@@ -1,5 +1,5 @@
1
1
  import type { SheetType } from "../../type";
2
- export type SheetAction = 'change' | 'changes' | 'rowMove' | 'colMove' | 'editFinish' | 'pushHistory' | 'popHistory' | 'select' | 'selectOneRow' | 'changeSearch' | 'closeSearch' | 'openSearch' | 'changeFixedPosition' | 'clearSelect' | 'clearSelectIfNotSingleRow' | 'clearEdit' | 'mouseDown' | 'mouseOver' | 'mouseUp' | 'selectRow' | 'selectCol' | 'loseFocus' | 'doubleClick' | 'mouseLeaveInterval' | 'move' | 'selectAll' | 'escape' | 'reverse' | 'delete' | 'enter' | 'otherInput' | 'none';
2
+ export type SheetAction = 'change' | 'changes' | 'rowMove' | 'colMove' | 'editFinish' | 'pushHistory' | 'popHistory' | 'select' | 'selectOneRow' | 'changeSearch' | 'closeSearch' | 'openSearch' | 'changeFixedPosition' | 'clearSelect' | 'clearSelectIfNotSingleRow' | 'clearEdit' | 'selectEdit' | 'mouseDown' | 'mouseOver' | 'mouseUp' | 'selectRow' | 'selectCol' | 'loseFocus' | 'doubleClick' | 'mouseLeaveInterval' | 'move' | 'selectAll' | 'escape' | 'reverse' | 'delete' | 'enter' | 'otherInput' | 'none';
3
3
  export 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;
@@ -15,6 +15,7 @@ var sheetReducer = function sheetReducer(state, action) {
15
15
  case 'clearSelect':
16
16
  case 'clearSelectIfNotSingleRow':
17
17
  case 'clearEdit':
18
+ case 'selectEdit':
18
19
  case 'changeSearch':
19
20
  case 'closeSearch':
20
21
  case 'openSearch':
@@ -133,6 +133,9 @@ export var sideEffectReducer = {
133
133
  value: editing.value
134
134
  });
135
135
  }
136
+ if ((editing === null || editing === void 0 ? void 0 : editing.col) === (lastEditing === null || lastEditing === void 0 ? void 0 : lastEditing.col) && (editing === null || editing === void 0 ? void 0 : editing.row) === (lastEditing === null || lastEditing === void 0 ? void 0 : lastEditing.row)) {
137
+ return;
138
+ }
136
139
  if (!isNil(lastEditing === null || lastEditing === void 0 ? void 0 : lastEditing.col) && !isNil(lastEditing === null || lastEditing === void 0 ? void 0 : lastEditing.row)) {
137
140
  //清空上一个编辑cell的状态
138
141
  eventBus.emit("cell-".concat(lastEditing.row, "-").concat(lastEditing.col, "-change"), {
@@ -247,7 +250,7 @@ export var sideEffectReducer = {
247
250
  return false;
248
251
  }
249
252
  if (editor && editor.checker) {
250
- return editor.checker(value, data[row][col].record);
253
+ return editor.checker(value, data[row][col].record, data[row][col].value);
251
254
  }
252
255
  return true;
253
256
  }).map(function (_ref6) {
@@ -260,17 +263,18 @@ export var sideEffectReducer = {
260
263
  row: row,
261
264
  col: col,
262
265
  id: (_data$row$col2 = data[row][col]) === null || _data$row$col2 === void 0 ? void 0 : _data$row$col2.id,
263
- 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) : 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].value) : value
264
267
  };
265
268
  });
266
269
  lastRow = extChanges === null || extChanges === void 0 || (_extChanges$ = extChanges[0]) === null || _extChanges$ === void 0 ? void 0 : _extChanges$.row;
267
270
  lastIndex = 1;
268
271
  legalExtChanges = extChanges === null || extChanges === void 0 ? void 0 : extChanges.filter(function (_ref7) {
269
- var value = _ref7.value,
272
+ var row = _ref7.row,
273
+ value = _ref7.value,
270
274
  col = _ref7.col;
271
275
  var editor = data[0][col].dataEditor;
272
276
  if (editor && editor.checker) {
273
- return editor.checker(value);
277
+ return editor.checker(value, data[row][col].record, data[row][col].value);
274
278
  }
275
279
  return true;
276
280
  }).map(function (_ref8) {
@@ -286,7 +290,7 @@ export var sideEffectReducer = {
286
290
  return {
287
291
  row: row,
288
292
  col: col,
289
- 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) : 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][col].value) : value,
290
294
  id: -lastIndex
291
295
  };
292
296
  });
@@ -265,5 +265,29 @@ export var stateReducer = _objectSpread({
265
265
  editing: undefined,
266
266
  lastEditing: editing
267
267
  });
268
+ },
269
+ selectEdit: function selectEdit(state, payload) {
270
+ var _ref4 = payload,
271
+ row = _ref4.row,
272
+ col = _ref4.col;
273
+ return _objectSpread(_objectSpread({}, state), {}, {
274
+ editing: {
275
+ row: row,
276
+ col: col
277
+ },
278
+ start: {
279
+ row: row,
280
+ col: col
281
+ },
282
+ end: {
283
+ row: row,
284
+ col: col
285
+ },
286
+ lastSelected: {
287
+ start: state.start,
288
+ end: state.end
289
+ },
290
+ lastEditing: undefined
291
+ });
268
292
  }
269
293
  }, searchReducer);
@@ -4,6 +4,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
4
4
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
5
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { ExclamationCircleOutlined } from '@ant-design/icons';
8
+ import { Modal } from 'antd';
7
9
  import { isNil } from 'lodash';
8
10
  import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
9
11
  import { useSetState, useSheetEvent } from "../../hooks";
@@ -12,6 +14,7 @@ import DataEditor from "./DataEditor";
12
14
  import DefaultCell from "./DefaultCell";
13
15
  import ValueViewer from "./ValueViewer";
14
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
+ var antConfirm = Modal.confirm;
15
18
  function initialData(_ref) {
16
19
  var cell = _ref.cell;
17
20
  return renderValue(cell);
@@ -57,7 +60,7 @@ var Cell = function Cell(props) {
57
60
  } else if (eventInfo.value && eventInfo.editing) {
58
61
  var _cell$dataEditor, _cell$dataEditor2, _cell$dataEditor2$par;
59
62
  // 单元格直接键盘编辑,设置为输入值
60
- 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) : 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, valueRef.current) : eventInfo.value);
61
64
  }
62
65
  setEventState(eventInfo);
63
66
  };
@@ -75,12 +78,44 @@ var Cell = function Cell(props) {
75
78
  return;
76
79
  }
77
80
  if (confirm) {
81
+ var _cell$dataEditor3;
78
82
  setEventState({
79
83
  confirm: false
80
84
  });
81
- if (value !== valueRef.current) {
82
- var _cell$dataEditor3, _cell$dataEditor4, _cell$dataEditor4$che;
83
- if (cell !== null && cell !== void 0 && (_cell$dataEditor3 = cell.dataEditor) !== null && _cell$dataEditor3 !== void 0 && _cell$dataEditor3.checker && !((_cell$dataEditor4 = cell.dataEditor) !== null && _cell$dataEditor4 !== void 0 && (_cell$dataEditor4$che = _cell$dataEditor4.checker) !== null && _cell$dataEditor4$che !== void 0 && _cell$dataEditor4$che.call(_cell$dataEditor4, value, cell.record))) {
85
+ var newValue = value;
86
+ // 转化一下公式
87
+ if (cell !== null && cell !== void 0 && (_cell$dataEditor3 = cell.dataEditor) !== null && _cell$dataEditor3 !== void 0 && _cell$dataEditor3.formula) {
88
+ var _cell$dataEditor4;
89
+ newValue = cell === null || cell === void 0 || (_cell$dataEditor4 = cell.dataEditor) === null || _cell$dataEditor4 === void 0 ? void 0 : _cell$dataEditor4.formula(value, valueRef.current);
90
+ if (newValue === Infinity) {
91
+ antConfirm({
92
+ title: '公式有误',
93
+ icon: /*#__PURE__*/_jsx(ExclamationCircleOutlined, {}),
94
+ content: '当前录入的公式有误,请检查后再试。',
95
+ onOk: function onOk() {
96
+ eventBus.emit('select-edit', {
97
+ row: row,
98
+ col: col
99
+ });
100
+ },
101
+ onCancel: function onCancel() {
102
+ eventBus.emit('cell-change', {
103
+ row: row,
104
+ col: col,
105
+ id: cell.id,
106
+ value: valueRef.current,
107
+ key: cell.dataIndex
108
+ });
109
+ },
110
+ okText: '重新编辑',
111
+ cancelText: '取消'
112
+ });
113
+ return;
114
+ }
115
+ }
116
+ if (newValue !== valueRef.current) {
117
+ var _cell$dataEditor5, _cell$dataEditor6, _cell$dataEditor6$che;
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 ? void 0 : _cell$dataEditor6$che.call(_cell$dataEditor6, newValue, cell.record)) === false) {
84
119
  setValue(valueRef.current);
85
120
  return;
86
121
  }
@@ -88,22 +123,18 @@ var Cell = function Cell(props) {
88
123
  row: row,
89
124
  col: col,
90
125
  id: cell.id,
91
- value: value,
126
+ value: newValue,
92
127
  key: cell.dataIndex
93
- // 没必要format value 已经是legal 的值了
94
- // value: cell.dataEditor?.formatter
95
- // ? cell.dataEditor.formatter?.(value)
96
- // : value,
97
128
  });
98
129
  }
99
130
  }
100
131
  }, [confirm, eventBus, value, cell]);
101
132
  var handleCommit = useCallback(function (value) {
102
- var _cell$dataEditor5, _cell$dataEditor6, _cell$dataEditor6$che;
133
+ var _cell$dataEditor7, _cell$dataEditor8, _cell$dataEditor8$che;
103
134
  if (valueRef.current === value) {
104
135
  return;
105
136
  }
106
- 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))) {
137
+ if (value !== null && cell !== null && cell !== void 0 && (_cell$dataEditor7 = cell.dataEditor) !== null && _cell$dataEditor7 !== void 0 && _cell$dataEditor7.checker && !((_cell$dataEditor8 = cell.dataEditor) !== null && _cell$dataEditor8 !== void 0 && (_cell$dataEditor8$che = _cell$dataEditor8.checker) !== null && _cell$dataEditor8$che !== void 0 && _cell$dataEditor8$che.call(_cell$dataEditor8, value, cell.record))) {
107
138
  setValue(valueRef.current);
108
139
  return;
109
140
  }
@@ -406,6 +406,12 @@ var Sheet = function Sheet(props) {
406
406
  if (sheetWrapperRef.current) {
407
407
  handleScroll();
408
408
  }
409
+ eventBus.on('select-edit', function (value) {
410
+ dispatch({
411
+ type: 'selectEdit',
412
+ payload: value
413
+ });
414
+ });
409
415
  }, []);
410
416
  var _useMemo = useMemo(function () {
411
417
  var history = state.history,
@@ -14,7 +14,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
14
14
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
15
15
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
16
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
- import { Table } from "./..";
17
+ import { Table, getNumberEditor } from "./..";
18
18
  import { Space, Tag } from 'antd';
19
19
  import 'antd/dist/antd.css';
20
20
  import React, { useCallback, useState } from 'react';
@@ -37,7 +37,12 @@ var columns = [{
37
37
  title: 'Age',
38
38
  dataIndex: 'age',
39
39
  key: 'age',
40
- width: 100
40
+ width: 100,
41
+ editor: getNumberEditor({
42
+ max: 1000000,
43
+ min: 0,
44
+ precision: 2
45
+ })
41
46
  }, {
42
47
  title: 'Address',
43
48
  editable: false,
@@ -53,9 +53,10 @@ export type CellEditorProps = {
53
53
  onConfirm: (value: unknown) => void;
54
54
  } & CellViewerProps;
55
55
  export type CellEditor = React.FC<CellEditorProps> & {
56
- checker?: (value: unknown, record?: Record<string, unknown>) => boolean;
56
+ checker?: (value: unknown, record?: Record<string, unknown>, currentValue?: unknown) => boolean;
57
57
  formatter?: (value: unknown, record?: Record<string, unknown>) => unknown;
58
- parser?: (value: unknown, record?: Record<string, unknown>) => unknown;
58
+ parser?: (value: unknown, currentValue?: unknown) => unknown;
59
+ formula?: (value: unknown, record?: Record<string, unknown>, currentValue?: unknown) => unknown;
59
60
  };
60
61
  export type CellViewer = React.FC<CellViewerProps>;
61
62
  export type CellPosition = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.89",
3
+ "version": "0.1.90-beta.0",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -51,8 +51,9 @@
51
51
  "antd": "^4.24.0",
52
52
  "events": "^3.3.0",
53
53
  "lodash": "^4.17.21",
54
+ "mathjs": "^14.6.0",
54
55
  "moment": "^2.29.4",
55
- "react": "17.x",
56
+ "react": "^17.0.2",
56
57
  "react-dom": "17.x",
57
58
  "redux-logger": "^3.0.6",
58
59
  "redux-thunk": "^2.4.2"
@@ -61,8 +62,8 @@
61
62
  "@commitlint/cli": "^17.1.2",
62
63
  "@commitlint/config-conventional": "^17.1.0",
63
64
  "@types/lodash": "^4.14.195",
64
- "@types/react": "17.0.40",
65
- "@types/react-dom": "17.0.13",
65
+ "@types/react": "^17.0.40",
66
+ "@types/react-dom": "^17.0.13",
66
67
  "@umijs/lint": "^4.0.0",
67
68
  "dumi": "^2.2.0",
68
69
  "eslint": "^8.23.0",
@@ -75,7 +76,6 @@
75
76
  "stylelint": "^14.9.1"
76
77
  },
77
78
  "peerDependencies": {
78
- "react": "17.x",
79
79
  "react-dom": "17.x"
80
80
  },
81
81
  "publishConfig": {
@@ -85,5 +85,4 @@
85
85
  "fizz.zhou@ap.jll.com"
86
86
  ],
87
87
  "preid": "beta"
88
-
89
- }
88
+ }