@zhenliang/sheet 0.1.92-beta.0 → 0.1.92-beta.4

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.
@@ -8,16 +8,23 @@ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("
8
8
  import { formatPrecision } from "../../../standardUtils";
9
9
  import { InputNumber as AntInputNumber, Input } from 'antd';
10
10
  import 'antd/es/input-number/style/index.css';
11
- import { isNil } from 'lodash';
11
+ import { head, isNil } from 'lodash';
12
12
  import { evaluate } from 'mathjs';
13
13
  import { useCallback, useEffect, useRef } from 'react';
14
14
  import "./index.less";
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  var formulaString = function formulaString(value, currentValue, precision, max, min, isEdit) {
17
17
  var curNumber = currentValue !== null && currentValue !== void 0 ? currentValue : 0;
18
- var formula = String(value).replace('=', '').replace(/[xX]+/g, String(curNumber));
18
+ var headStr = head(String(value).trim());
19
+ var formula = String(value).replace('=', '');
19
20
  try {
20
- var result = evaluate(formula);
21
+ if (isNaN(value) && headStr !== '=') {
22
+ throw false;
23
+ }
24
+ var result = evaluate(formula, {
25
+ x: curNumber,
26
+ X: curNumber
27
+ });
21
28
  if (max && result > max) {
22
29
  result = max;
23
30
  } else if (min && result < min) {
@@ -64,7 +71,8 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
64
71
  var NumberEditor = function NumberEditor(props) {
65
72
  var _ref3;
66
73
  var value = props.value,
67
- onChange = props.onChange;
74
+ onChange = props.onChange,
75
+ isEditing = props.isEditing;
68
76
  var inputNumberRef = useRef(null);
69
77
  var _ref2 = getExtraProps ? getExtraProps(props) : extraProps !== null && extraProps !== void 0 ? extraProps : {},
70
78
  inputArgs = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
@@ -72,9 +80,18 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
72
80
  onChange(!isNil(value) ? value : null);
73
81
  }, [onChange]);
74
82
  useEffect(function () {
75
- var _inputNumberRef$curre2;
76
- inputNumberRef === null || inputNumberRef === void 0 || (_inputNumberRef$curre2 = inputNumberRef.current) === null || _inputNumberRef$curre2 === void 0 || _inputNumberRef$curre2.focus();
77
- }, []);
83
+ if (isEditing) {
84
+ var _inputNumberRef$curre2;
85
+ console.log('isEditing', isEditing);
86
+ inputNumberRef === null || inputNumberRef === void 0 || (_inputNumberRef$curre2 = inputNumberRef.current) === null || _inputNumberRef$curre2 === void 0 || _inputNumberRef$curre2.focus();
87
+ }
88
+ }, [isEditing]);
89
+ var reFocus = useCallback(function () {
90
+ if (isEditing) {
91
+ var _inputNumberRef$curre3;
92
+ inputNumberRef === null || inputNumberRef === void 0 || (_inputNumberRef$curre3 = inputNumberRef.current) === null || _inputNumberRef$curre3 === void 0 || _inputNumberRef$curre3.focus();
93
+ }
94
+ }, [isEditing]);
78
95
  return /*#__PURE__*/_jsx(Input, _objectSpread(_objectSpread({
79
96
  ref: inputNumberRef
80
97
  }, inputArgs), {}, {
@@ -82,6 +99,7 @@ export var getNumberEditor = function getNumberEditor(extraProps, getExtraProps)
82
99
  onMouseDown: function onMouseDown(e) {
83
100
  return e.stopPropagation();
84
101
  },
102
+ onBlur: reFocus,
85
103
  value: (_ref3 = value) !== null && _ref3 !== void 0 ? _ref3 : '',
86
104
  onChange: function onChange(e) {
87
105
  handleChange(e.target.value);
@@ -9,20 +9,25 @@
9
9
  text-align: inherit !important;
10
10
  padding-left: 0;
11
11
 
12
- .ant-input-number-wrapper {
12
+ .ant-input-wrapper {
13
13
  text-align: inherit !important;
14
14
  }
15
15
 
16
- .ant-input-number-input {
16
+ .ant-input {
17
17
  text-align: inherit !important;
18
18
  }
19
19
 
20
- .ant-input-number-input-wrap > input {
20
+ .ant-input-wrapper > input {
21
21
  padding: 0;
22
22
  height: 38px;
23
+ border: none;
24
+ outline: none;
25
+ box-shadow: none;
26
+ background: transparent;
27
+ font-size: 12px;
23
28
  }
24
29
 
25
- .ant-input-number-group-addon {
30
+ .ant-input-group-addon {
26
31
  background: transparent;
27
32
  border: none;
28
33
  padding: 0;
@@ -30,8 +30,17 @@ export var keyboardReducer = {
30
30
  minCol++;
31
31
  }
32
32
  });
33
+ var lastEditing = state.lastEditing;
34
+ if (state.editing) {
35
+ lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
36
+ confirm: true
37
+ });
38
+ }
33
39
  if (newRow > maxRow || newRow < 0 || newCol > maxCol || newCol < minCol) {
34
- return state;
40
+ return _objectSpread(_objectSpread({}, state), {}, {
41
+ editing: undefined,
42
+ lastEditing: lastEditing
43
+ });
35
44
  }
36
45
  // 跟随滚动
37
46
  if (optCol !== 0) {
@@ -56,12 +65,6 @@ export var keyboardReducer = {
56
65
  row: newRow,
57
66
  col: newCol
58
67
  };
59
- var lastEditing = state.lastEditing;
60
- if (state.editing) {
61
- lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
62
- confirm: true
63
- });
64
- }
65
68
  var isOut = isNil(currentPos.row);
66
69
  var newState = _objectSpread(_objectSpread({}, state), {}, {
67
70
  start: isOut ? undefined : currentPos,
@@ -158,7 +158,8 @@ var Cell = function Cell(props) {
158
158
  value: value,
159
159
  record: cel.record,
160
160
  onConfirm: handleCommit,
161
- onChange: setValue
161
+ onChange: setValue,
162
+ isEditing: isEditing
162
163
  });
163
164
  }
164
165
  return null;
@@ -1,5 +1,5 @@
1
1
  import { SheetTableType } from "../..";
2
2
  export declare const useRowSelection: (dataSource: Record<string, unknown>[], rowSelection?: SheetTableType.TableRowSelection, hasChildren?: boolean) => [boolean[], (value: boolean[]) => void];
3
- export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "columns" | "showRemark" | "rowSelection" | "dataSource" | "rowKey"> & {
3
+ export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "columns" | "dataSource" | "rowKey" | "showRemark" | "rowSelection"> & {
4
4
  checked: boolean[];
5
5
  }) => any[][];
@@ -51,6 +51,7 @@ export type CellEditorProps = {
51
51
  cell?: Cell;
52
52
  onChange: (value: unknown) => void;
53
53
  onConfirm: (value: unknown) => void;
54
+ isEditing?: boolean;
54
55
  } & CellViewerProps;
55
56
  export type CellEditor = React.FC<CellEditorProps> & {
56
57
  checker?: (value: unknown, record?: Record<string, unknown>, currentValue?: unknown) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.92-beta.0",
3
+ "version": "0.1.92-beta.4",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",