@lemon-fe/components 1.6.4 → 1.6.6

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.
Files changed (35) hide show
  1. package/es/component-configure/index.d.ts +2 -0
  2. package/es/data-grid/cell-editors/number.d.ts +6 -2
  3. package/es/data-grid/cell-editors/number.js +65 -49
  4. package/es/data-grid/cell-editors/row.js +7 -4
  5. package/es/data-grid/components/custom-panel/field-modal.d.ts +1 -0
  6. package/es/data-grid/components/custom-panel/field-modal.js +9 -3
  7. package/es/data-grid/components/custom-panel/index.d.ts +1 -0
  8. package/es/data-grid/components/custom-panel/index.js +4 -2
  9. package/es/data-grid/components/custom-panel/typings.d.ts +1 -0
  10. package/es/data-grid/index.js +2 -1
  11. package/es/data-grid/index.less +16 -0
  12. package/es/data-grid/locale/en_US.js +2 -1
  13. package/es/data-grid/locale/id.js +2 -1
  14. package/es/data-grid/locale/locale.d.ts +1 -0
  15. package/es/data-grid/locale/vi.js +2 -1
  16. package/es/data-grid/locale/zh_CN.js +2 -1
  17. package/es/data-grid/locale/zh_Hant_HK.js +2 -1
  18. package/es/data-grid/typings.d.ts +4 -0
  19. package/es/formula-calculator/evaluate.d.ts +10 -0
  20. package/es/formula-calculator/evaluate.js +217 -0
  21. package/es/formula-calculator/index.d.ts +24 -0
  22. package/es/formula-calculator/index.js +386 -0
  23. package/es/formula-calculator/index.less +88 -0
  24. package/es/index.d.ts +1 -1
  25. package/es/input-number/index.d.ts +11 -7
  26. package/es/input-number/index.js +55 -8
  27. package/es/input-number/index.less +36 -1
  28. package/es/locale/en_US.js +7 -1
  29. package/es/locale/id.js +7 -1
  30. package/es/locale/locale.d.ts +6 -0
  31. package/es/locale/vi.js +7 -1
  32. package/es/locale/zh_CN.js +7 -1
  33. package/es/locale/zh_Hant_HK.js +7 -1
  34. package/es/styles/index.less +1 -0
  35. package/package.json +3 -3
@@ -0,0 +1,88 @@
1
+ .@{prefixCls}-formula-calculator {
2
+ display: flex;
3
+ flex-direction: column;
4
+ box-sizing: border-box;
5
+ width: 280px;
6
+ max-width: calc(100vw - 16px);
7
+ max-height: calc(100vh - 32px);
8
+
9
+ &-popover .@{ant-prefix}-popover-inner-content {
10
+ padding: 0;
11
+ }
12
+
13
+ &-trigger {
14
+ display: inline-flex;
15
+ flex: none;
16
+ align-items: center;
17
+ justify-content: center;
18
+ width: 22px;
19
+ margin: 0;
20
+ padding: 0;
21
+ color: @primary-color;
22
+ font-size: 14px;
23
+ background: transparent;
24
+ border: none;
25
+ cursor: pointer;
26
+
27
+ &:hover,
28
+ &:focus {
29
+ color: @primary-5;
30
+ }
31
+
32
+ &:disabled {
33
+ color: @disabled-color;
34
+ cursor: not-allowed;
35
+ }
36
+ }
37
+
38
+ &-body {
39
+ display: flex;
40
+ flex: 1 1 auto;
41
+ flex-direction: column;
42
+ min-height: 0;
43
+ padding: 8px 12px;
44
+ }
45
+
46
+ &-expression {
47
+ flex: none;
48
+ width: 100%;
49
+ height: 22px;
50
+ margin: 0;
51
+ padding: 0;
52
+ color: @text-color;
53
+ font-size: 14px;
54
+ line-height: 22px;
55
+ text-align: right;
56
+ background: transparent;
57
+ border: none;
58
+ outline: none;
59
+
60
+ &::placeholder {
61
+ color: @input-placeholder-color;
62
+ }
63
+
64
+ &:placeholder-shown {
65
+ text-align: left;
66
+ }
67
+ }
68
+
69
+ &-result {
70
+ flex: 1 1 auto;
71
+ min-height: 0;
72
+ margin-top: 2px;
73
+ overflow: auto;
74
+ color: @text-color;
75
+ line-height: 22px;
76
+ text-align: right;
77
+ word-break: break-all;
78
+ overscroll-behavior: contain;
79
+ }
80
+
81
+ &-footer {
82
+ flex: none;
83
+ padding: 6px 12px;
84
+ font-size: 12px;
85
+ text-align: center;
86
+ border-top: 1px solid @border-color-split;
87
+ }
88
+ }
package/es/index.d.ts CHANGED
@@ -46,7 +46,7 @@ export { parseLocalTemplate } from './locale/locale';
46
46
  export { default as Table } from './table';
47
47
  export type { TableRef } from './table/typings';
48
48
  export { default as Alert } from './alert';
49
- export { default as InputNumber } from './input-number';
49
+ export { default as InputNumber, type InputNumberProps } from './input-number';
50
50
  export { default as Empty, EmptyImage } from './empty';
51
51
  export { default as Dropdown } from './dropdown';
52
52
  export { default as Modal, type ModalProps, type ModalFuncProps } from './modal';
@@ -1,8 +1,12 @@
1
- import { type ReactNode } from 'react';
2
- import { type InputNumberProps } from 'antd';
3
- export default function InputNumber<T extends string | number = string | number>(props: InputNumberProps<T> & {
4
- /**
5
- * 后缀,不支持和prefix一起使用
6
- */
1
+ import { type InputNumberProps as AntdInputNumberProps } from 'antd';
2
+ import type { ReactNode } from 'react';
3
+ import type { FormulaCalculatorConfig } from '../formula-calculator';
4
+ export interface InputNumberProps<T extends string | number = string | number> extends AntdInputNumberProps<T> {
5
+ /** 后缀,不支持和 prefix 一起使用 */
7
6
  suffix?: ReactNode;
8
- }): JSX.Element;
7
+ /** 是否启用计算器,未设置时继承全局配置 */
8
+ calculator?: boolean;
9
+ /** 计算器弹窗位置,未设置时继承全局配置,默认 bottomRight */
10
+ calculatorPlacement?: FormulaCalculatorConfig['placement'];
11
+ }
12
+ export default function InputNumber<T extends string | number = string | number>(props: InputNumberProps<T>): JSX.Element;
@@ -1,28 +1,75 @@
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 = ["suffix", "prefix", "className", "controls"];
2
+ var _excluded = ["suffix", "calculator", "calculatorPlacement", "prefix", "className", "controls", "onBlurCapture", "onKeyDown"];
3
3
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
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; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
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); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ 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; }
11
+ 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; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
13
  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; }
8
14
  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; }
9
- import React from 'react';
15
+ import { InputNumber as AntdInputNumber } from 'antd';
16
+ import React, { useRef, useState } from 'react';
17
+ import { createPortal } from 'react-dom';
18
+ import { useFormulaCalculator } from "../formula-calculator";
10
19
  import Icons from "../icons";
11
20
  import { prefixClassName } from "../utils";
12
- import { InputNumber as AntdInputNumber } from 'antd';
13
21
  import classNames from 'classnames';
14
22
  export default function InputNumber(props) {
15
23
  var suffix = props.suffix,
24
+ calculatorEnabled = props.calculator,
25
+ calculatorPlacement = props.calculatorPlacement,
16
26
  prefix = props.prefix,
17
27
  className = props.className,
18
28
  controls = props.controls,
19
- restProps = _objectWithoutProperties(props, _excluded);
29
+ onBlurCapture = props.onBlurCapture,
30
+ onKeyDown = props.onKeyDown,
31
+ inputProps = _objectWithoutProperties(props, _excluded);
32
+ var disabled = inputProps.disabled,
33
+ readOnly = inputProps.readOnly;
20
34
  var prefixCls = prefixClassName('input-number');
21
- return /*#__PURE__*/React.createElement(AntdInputNumber, _extends({
35
+ var inputRef = useRef(null);
36
+ var _useState = useState(null),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ buttonContainer = _useState2[0],
39
+ setButtonContainer = _useState2[1];
40
+ var calculator = useFormulaCalculator({
41
+ inputRef: inputRef,
42
+ enabled: calculatorEnabled,
43
+ placement: calculatorPlacement,
44
+ disabled: disabled || readOnly,
45
+ deferInputBlur: true,
46
+ onInputBlurCapture: onBlurCapture
47
+ });
48
+ var button = calculator.button,
49
+ handleInputBlurCapture = calculator.handleInputBlurCapture,
50
+ handleInputKeyDown = calculator.handleInputKeyDown,
51
+ visible = calculator.visible;
52
+ var setInputRef = function setInputRef(input) {
53
+ inputRef.current = input;
54
+ if (!input) {
55
+ return;
56
+ }
57
+ var container = button ? input.parentElement : null;
58
+ if (container !== buttonContainer) {
59
+ setButtonContainer(container);
60
+ }
61
+ };
62
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(AntdInputNumber, _extends({
22
63
  max: 99999999
23
- }, restProps, {
64
+ }, inputProps, {
65
+ ref: setInputRef,
66
+ onBlurCapture: handleInputBlurCapture,
67
+ onKeyDown: handleInputKeyDown ? function (event) {
68
+ onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
69
+ handleInputKeyDown(event);
70
+ } : onKeyDown,
24
71
  prefix: suffix !== null && suffix !== void 0 ? suffix : prefix,
25
- className: classNames(prefixCls(), className, _defineProperty({}, prefixCls('suffix'), !!suffix)),
72
+ className: classNames(prefixCls(), className, _defineProperty(_defineProperty(_defineProperty(_defineProperty({}, prefixCls('suffix'), !!suffix), prefixCls('calculator'), calculator.enabled), prefixCls('calculator-open'), visible), prefixCls('calculator-controls'), calculator.enabled && controls !== false && !disabled && !readOnly)),
26
73
  controls: controls !== null && controls !== void 0 ? controls : {
27
74
  downIcon: /*#__PURE__*/React.createElement(Icons.Down, null),
28
75
  upIcon: /*#__PURE__*/React.createElement(Icons.Down, {
@@ -31,5 +78,5 @@ export default function InputNumber(props) {
31
78
  }
32
79
  })
33
80
  }
34
- }));
81
+ })), button && buttonContainer && /*#__PURE__*/createPortal(button, buttonContainer));
35
82
  }
@@ -1,3 +1,5 @@
1
+ @input-number-handler-width: 18px;
2
+
1
3
  .@{prefixCls}-input-number {
2
4
  .@{ant-prefix}-input-number-prefix {
3
5
  color: #666;
@@ -7,7 +9,7 @@
7
9
  border-left: none;
8
10
 
9
11
  &-wrap {
10
- width: 18px;
12
+ width: @input-number-handler-width;
11
13
  }
12
14
 
13
15
  &-up-inner {
@@ -56,3 +58,36 @@
56
58
  }
57
59
  }
58
60
  }
61
+
62
+ .@{prefixCls}-input-number-calculator {
63
+ .@{ant-prefix}-input-number-input-wrap {
64
+ position: relative;
65
+
66
+ > .@{prefixCls}-formula-calculator-trigger {
67
+ position: absolute;
68
+ display: none;
69
+ inset-block: 0;
70
+ inset-inline-end: var(--input-number-calculator-inset, 0);
71
+ }
72
+ }
73
+
74
+ .@{ant-prefix}-input-number-input-wrap:focus-within,
75
+ &-open .@{ant-prefix}-input-number-input-wrap {
76
+ > .@{ant-prefix}-input-number-input {
77
+ padding-inline-end: calc(24px + var(--input-number-calculator-inset, 0px));
78
+ }
79
+
80
+ > .@{prefixCls}-formula-calculator-trigger {
81
+ display: inline-flex;
82
+ }
83
+ }
84
+
85
+ &-controls .@{ant-prefix}-input-number-input-wrap {
86
+ --input-number-calculator-inset: @input-number-handler-width;
87
+ }
88
+
89
+ &.@{ant-prefix}-input-number-affix-wrapper-has-feedback .@{ant-prefix}-input-number-input-wrap,
90
+ .@{ant-prefix}-input-number-affix-wrapper-has-feedback .@{ant-prefix}-input-number-input-wrap {
91
+ --input-number-calculator-inset: calc(1em + @input-padding-horizontal-base);
92
+ }
93
+ }
@@ -26,6 +26,12 @@ var enUS = _objectSpread(_objectSpread({}, antEnUS), {}, {
26
26
  SelectView: SelectViewLocale,
27
27
  SelectPanel: SelectPanelLocale,
28
28
  DurationPicker: DurationPickerLocale,
29
- RequestErrorMessage: RequestErrorMessageLocale
29
+ RequestErrorMessage: RequestErrorMessageLocale,
30
+ FormulaCalculator: {
31
+ label: 'Calculator',
32
+ placeholder: 'Example: 1.5+3*(4-2)/2',
33
+ invalidFormula: 'Invalid formula',
34
+ keysHint: 'Enter applies a valid result. Esc closes.'
35
+ }
30
36
  });
31
37
  export default enUS;
package/es/locale/id.js CHANGED
@@ -26,6 +26,12 @@ var id = _objectSpread(_objectSpread({}, antId), {}, {
26
26
  SelectView: SelectViewLocale,
27
27
  SelectPanel: SelectPanelLocale,
28
28
  DurationPicker: DurationPickerLocale,
29
- RequestErrorMessage: RequestErrorMessageLocale
29
+ RequestErrorMessage: RequestErrorMessageLocale,
30
+ FormulaCalculator: {
31
+ label: 'Kalkulator',
32
+ placeholder: 'Contoh: 1.5+3*(4-2)/2',
33
+ invalidFormula: 'Rumus tidak valid',
34
+ keysHint: 'Enter menerapkan hasil yang valid. Esc menutup.'
35
+ }
30
36
  });
31
37
  export default id;
@@ -18,5 +18,11 @@ export interface Locale extends AntLocale {
18
18
  SelectPanel: SelectPanelLocale;
19
19
  DurationPicker: DurationPickerLocale;
20
20
  RequestErrorMessage: RequestErrorMessageLocale;
21
+ FormulaCalculator?: {
22
+ label: string;
23
+ placeholder: string;
24
+ invalidFormula: string;
25
+ keysHint: string;
26
+ };
21
27
  }
22
28
  export declare function parseLocalTemplate(template: string, context: Record<string | number, any>): string;
package/es/locale/vi.js CHANGED
@@ -26,6 +26,12 @@ var vi = _objectSpread(_objectSpread({}, antVi), {}, {
26
26
  SelectView: SelectViewLocale,
27
27
  SelectPanel: SelectPanelLocale,
28
28
  DurationPicker: DurationPickerLocale,
29
- RequestErrorMessage: RequestErrorMessageLocale
29
+ RequestErrorMessage: RequestErrorMessageLocale,
30
+ FormulaCalculator: {
31
+ label: 'Máy tính',
32
+ placeholder: 'Ví dụ: 1.5+3*(4-2)/2',
33
+ invalidFormula: 'Công thức không hợp lệ',
34
+ keysHint: 'Enter điền kết quả hợp lệ. Esc đóng.'
35
+ }
30
36
  });
31
37
  export default vi;
@@ -26,6 +26,12 @@ var zhCN = _objectSpread(_objectSpread({}, antZhCN), {}, {
26
26
  SiderTree: SiderTreeLocale,
27
27
  SelectView: SelectViewLocale,
28
28
  SelectPanel: SelectPanelLocale,
29
- RequestErrorMessage: RequestErrorMessageLocale
29
+ RequestErrorMessage: RequestErrorMessageLocale,
30
+ FormulaCalculator: {
31
+ label: '计算器',
32
+ placeholder: '示例:1.5+3*(4-2)/2',
33
+ invalidFormula: '公式错误',
34
+ keysHint: 'Enter 回填有效结果,Esc 关闭'
35
+ }
30
36
  });
31
37
  export default zhCN;
@@ -26,6 +26,12 @@ var zhHantHk = _objectSpread(_objectSpread({}, antZhHk), {}, {
26
26
  SelectView: SelectViewLocale,
27
27
  SelectPanel: SelectPanelLocale,
28
28
  DurationPicker: DurationPickerLocale,
29
- RequestErrorMessage: RequestErrorMessageLocale
29
+ RequestErrorMessage: RequestErrorMessageLocale,
30
+ FormulaCalculator: {
31
+ label: '計算器',
32
+ placeholder: '範例:1.5+3*(4-2)/2',
33
+ invalidFormula: '公式錯誤',
34
+ keysHint: 'Enter 回填有效結果,Esc 關閉'
35
+ }
30
36
  });
31
37
  export default zhHantHk;
@@ -24,6 +24,7 @@
24
24
  @import '../state/index.less';
25
25
  @import '../grey-panel/index.less';
26
26
  @import '../input-number/index.less';
27
+ @import '../formula-calculator/index.less';
27
28
  @import '../input-compact/index.less';
28
29
  @import '../select-panel/index.less';
29
30
  @import '../modal/index.less';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/components",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@dnd-kit/core": ">=6.0.0",
24
- "@lemon-fe/hooks": "^1.5.8",
24
+ "@lemon-fe/hooks": "^1.6.6",
25
25
  "@lemon-fe/utils": "^1.4.15",
26
26
  "ag-grid-community": "29.2.0",
27
27
  "ag-grid-enterprise": "29.2.0",
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "registry": "https://registry.npmjs.org"
60
60
  },
61
- "gitHead": "9242c3ded70d88daf87fbaf9fd911c931f24b101"
61
+ "gitHead": "e188887c76431607140aec1982f3d50bf682761f"
62
62
  }