@lemon-fe/components 1.1.2 → 1.1.3-alpha.1

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.
@@ -1,8 +1,9 @@
1
- import { type ReactElement } from 'react';
2
- import type { CSSProperties } from 'react';
3
1
  import { type ButtonProps } from 'antd';
2
+ import { type ReactElement, type ReactNode } from 'react';
3
+ import type { CSSProperties } from 'react';
4
4
  interface ActionBtn extends ButtonProps {
5
5
  text: string | ReactElement;
6
+ label?: ReactNode;
6
7
  onClick?: () => void;
7
8
  /**
8
9
  * @deprecated
@@ -11,6 +12,7 @@ interface ActionBtn extends ButtonProps {
11
12
  action?: () => void;
12
13
  dropDown?: ({
13
14
  text: string | ReactElement;
15
+ label?: ReactNode;
14
16
  onClick?: () => void;
15
17
  disabled?: boolean;
16
18
  } | ReactElement | null)[] | ReactElement;
@@ -24,6 +26,7 @@ interface Props {
24
26
  * @description 默认无限大
25
27
  */
26
28
  maxShowCount?: number;
29
+ trackEventAttr?: string;
27
30
  }
28
31
  declare function Actions(props: Props): JSX.Element;
29
32
  export default Actions;
@@ -1,19 +1,21 @@
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 = ["disabled", "dropDown", "text", "onClick", "icon", "action"];
3
- 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; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
- 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); }
2
+ var _excluded = ["dropDown", "text", "onClick", "action", "label"];
3
+ 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
+ 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; }
6
5
  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); }
7
6
  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
7
  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; }
8
+ 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; }
9
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
10
+ 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); }
9
11
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
10
12
  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."); }
11
13
  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); }
12
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; }
13
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; } }
14
16
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
- import React, { Fragment, useState, isValidElement } from 'react';
16
17
  import { Space, Dropdown, Menu, Button, Popover } from 'antd';
18
+ import React, { Fragment, useState, isValidElement } from 'react';
17
19
  import classNames from 'classnames';
18
20
  import { PREFIX_CLS } from "../constants";
19
21
  import Icons from "../icons";
@@ -24,13 +26,21 @@ function Actions(props) {
24
26
  _props$prefixCls = props.prefixCls,
25
27
  prefixCls = _props$prefixCls === void 0 ? PREFIX_CLS : _props$prefixCls,
26
28
  _props$maxShowCount = props.maxShowCount,
27
- maxShowCount = _props$maxShowCount === void 0 ? Infinity : _props$maxShowCount;
29
+ maxShowCount = _props$maxShowCount === void 0 ? Infinity : _props$maxShowCount,
30
+ _props$trackEventAttr = props.trackEventAttr,
31
+ trackEventAttr = _props$trackEventAttr === void 0 ? 'data-track-event' : _props$trackEventAttr;
28
32
  var _useState = useState(false),
29
33
  _useState2 = _slicedToArray(_useState, 2),
30
34
  visible = _useState2[0],
31
35
  setVisible = _useState2[1];
32
36
  var visibleBtns = actions.slice(0, maxShowCount);
33
37
  var collapsedBtns = actions.slice(maxShowCount);
38
+ var getTrackAttr = function getTrackAttr(text) {
39
+ if (typeof text === 'string') {
40
+ return _defineProperty({}, trackEventAttr, text);
41
+ }
42
+ return undefined;
43
+ };
34
44
  return /*#__PURE__*/React.createElement("div", {
35
45
  className: classNames("".concat(prefixCls, "-actions"), className),
36
46
  style: style
@@ -46,18 +56,23 @@ function Actions(props) {
46
56
  key: index
47
57
  }, item);
48
58
  }
49
- var disabled = item.disabled,
50
- dropDown = item.dropDown,
59
+ var dropDown = item.dropDown,
51
60
  text = item.text,
52
61
  onClick = item.onClick,
53
- icon = item.icon,
54
62
  action = item.action,
63
+ label = item.label,
55
64
  rest = _objectWithoutProperties(item, _excluded);
65
+ var trackAttr = getTrackAttr(text);
56
66
  if ( /*#__PURE__*/isValidElement(text)) {
57
67
  return /*#__PURE__*/React.createElement(Fragment, {
58
68
  key: index
59
69
  }, text);
60
70
  }
71
+ if (label !== undefined) {
72
+ return /*#__PURE__*/React.createElement("div", _extends({
73
+ key: index
74
+ }, trackAttr), label);
75
+ }
61
76
  var handleClick = onClick || action;
62
77
  if (dropDown !== undefined) {
63
78
  var overlay;
@@ -65,18 +80,19 @@ function Actions(props) {
65
80
  overlay = /*#__PURE__*/React.createElement(Menu, {
66
81
  items: dropDown.filter(Boolean).map(function (subItem, idx) {
67
82
  if ( /*#__PURE__*/isValidElement(subItem)) {
83
+ console.error('请使用MenuItemType的label属性');
68
84
  return {
69
85
  label: subItem,
70
86
  key: idx
71
87
  };
72
88
  }
73
89
  var target = subItem;
74
- return {
75
- label: target.text,
90
+ return _objectSpread({
91
+ label: target.label || target.text,
76
92
  key: idx,
77
93
  disabled: target.disabled,
78
94
  onClick: target.onClick
79
- };
95
+ }, getTrackAttr(target.text));
80
96
  })
81
97
  });
82
98
  } else {
@@ -85,33 +101,30 @@ function Actions(props) {
85
101
  if (handleClick !== undefined) {
86
102
  return /*#__PURE__*/React.createElement(Dropdown.Button, _extends({
87
103
  key: text,
88
- disabled: disabled,
104
+ disabled: rest.disabled,
89
105
  overlay: overlay,
90
106
  onClick: handleClick,
91
107
  trigger: ['click'],
92
108
  overlayStyle: {
93
109
  minWidth: 80
94
110
  },
95
- buttonsRender: function buttonsRender(_ref) {
96
- var _ref2 = _slicedToArray(_ref, 1),
97
- leftBtn = _ref2[0];
111
+ buttonsRender: function buttonsRender(_ref2) {
112
+ var _ref3 = _slicedToArray(_ref2, 1),
113
+ leftBtn = _ref3[0];
98
114
  return [leftBtn, /*#__PURE__*/React.createElement(Button, {
99
115
  icon: /*#__PURE__*/React.createElement(Icons.More, null),
100
116
  type: rest.type,
101
117
  key: "more"
102
118
  })];
103
119
  }
104
- }, rest), text);
120
+ }, rest), /*#__PURE__*/React.createElement("span", trackAttr, text));
105
121
  }
106
122
  return /*#__PURE__*/React.createElement(Dropdown, {
107
123
  key: text,
108
- disabled: disabled,
124
+ disabled: rest.disabled,
109
125
  overlay: overlay,
110
126
  trigger: ['click']
111
- }, /*#__PURE__*/React.createElement(Button, _extends({
112
- disabled: disabled,
113
- icon: icon
114
- }, rest), text, /*#__PURE__*/React.createElement(Icons.Down, {
127
+ }, /*#__PURE__*/React.createElement(Button, rest, text, /*#__PURE__*/React.createElement(Icons.Down, {
115
128
  style: {
116
129
  opacity: 0.7
117
130
  }
@@ -119,10 +132,8 @@ function Actions(props) {
119
132
  }
120
133
  return /*#__PURE__*/React.createElement(Button, _extends({
121
134
  key: text,
122
- disabled: disabled,
123
- onClick: handleClick,
124
- icon: icon
125
- }, rest), text);
135
+ onClick: handleClick
136
+ }, trackAttr, rest), text);
126
137
  }), collapsedBtns.length > 0 ? /*#__PURE__*/React.createElement(Popover, {
127
138
  placement: "bottomRight",
128
139
  overlayClassName: "".concat(prefixCls, "-actions-popover"),
@@ -139,8 +150,9 @@ function Actions(props) {
139
150
  }, item);
140
151
  }
141
152
  var disabled = item.disabled;
142
- return /*#__PURE__*/React.createElement("div", {
143
- className: classNames("".concat(prefixCls, "-actions-popover-item"), _defineProperty({}, "".concat(prefixCls, "-actions-popover-item-disabled"), disabled)),
153
+ return /*#__PURE__*/React.createElement("div", _extends({
154
+ className: classNames("".concat(prefixCls, "-actions-popover-item"), _defineProperty({}, "".concat(prefixCls, "-actions-popover-item-disabled"), disabled))
155
+ }, getTrackAttr(item.text), {
144
156
  key: index,
145
157
  onClick: function onClick() {
146
158
  if (!disabled) {
@@ -151,7 +163,7 @@ function Actions(props) {
151
163
  }
152
164
  }
153
165
  }
154
- }, item.text);
166
+ }), item.text);
155
167
  })
156
168
  }, /*#__PURE__*/React.createElement(Button, {
157
169
  icon: /*#__PURE__*/React.createElement(Icons.More, null)
@@ -19,6 +19,7 @@ export default class DataGrid<TData extends Record<string, any>> extends Compone
19
19
  private searchRef;
20
20
  private prevFocusedCell;
21
21
  private fields;
22
+ private fieldSuffix;
22
23
  static contextType?: React.Context<any> | undefined;
23
24
  static defaultProps: Partial<DataGridProps<any>>;
24
25
  static SummaryFlag: symbol;
@@ -150,6 +150,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
150
150
  _defineProperty(_assertThisInitialized(_this), "searchRef", /*#__PURE__*/createRef());
151
151
  _defineProperty(_assertThisInitialized(_this), "prevFocusedCell", null);
152
152
  _defineProperty(_assertThisInitialized(_this), "fields", []);
153
+ _defineProperty(_assertThisInitialized(_this), "fieldSuffix", /(%)$/);
153
154
  _defineProperty(_assertThisInitialized(_this), "getFieldsSummary", memoizeOne(function (dataSource, fields) {
154
155
  var summaryField = fields.filter(function (field) {
155
156
  return field.summary;
@@ -188,7 +189,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
188
189
  if (summary[field.id] === undefined) {
189
190
  summary[field.id] = new BigNumber(0);
190
191
  }
191
- summary[field.id] = summary[field.id].plus(value);
192
+ summary[field.id] = summary[field.id].plus(typeof value === 'string' ? value.replace(_this.fieldSuffix, '') : value);
192
193
  });
193
194
  });
194
195
  return summary;
@@ -991,12 +992,14 @@ var DataGrid = /*#__PURE__*/function (_Component) {
991
992
  if (suppressFieldValueGetter) {
992
993
  fieldCol.field = field.id;
993
994
  } else {
995
+ var _this5$fieldSuffix$ex;
994
996
  /**
995
997
  * 预校验是否可以进行四则运算,可能会有边界情况没考虑到
996
998
  */
997
999
  var scopeMap = {};
998
1000
  var reg = /\$\{([^{}]+)\}/g;
999
- var expression = field.expression.replace(reg, function (match, p1) {
1001
+ var expressionSuffix = ((_this5$fieldSuffix$ex = _this5.fieldSuffix.exec(field.expression)) === null || _this5$fieldSuffix$ex === void 0 ? void 0 : _this5$fieldSuffix$ex[1]) || '';
1002
+ var expression = field.expression.replace(_this5.fieldSuffix, '').replace(reg, function (match, p1) {
1000
1003
  if (p1) {
1001
1004
  var mapKey = "a".concat(Object.keys(scopeMap).length);
1002
1005
  scopeMap[mapKey] = p1;
@@ -1066,7 +1069,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1066
1069
  return null;
1067
1070
  }
1068
1071
  } else {
1069
- return field.expression.replace(reg, function (match, p1) {
1072
+ return field.expression.replace(_this5.fieldSuffix, '').replace(reg, function (match, p1) {
1070
1073
  if (p1) {
1071
1074
  return getValue(p1) || '';
1072
1075
  }
@@ -1077,9 +1080,16 @@ var DataGrid = /*#__PURE__*/function (_Component) {
1077
1080
  return null;
1078
1081
  };
1079
1082
  fieldCol.valueFormatter = function (params) {
1080
- if (Number.isNaN(params.value) || typeof params.value === 'number' && !Number.isFinite(params.value) || BigNumber.isBigNumber(params.value) && (params.value.isNaN() || !params.value.isFinite())) {
1083
+ if (typeof params.value === 'number' && (Number.isNaN(params.value) || !Number.isFinite(params.value)) || BigNumber.isBigNumber(params.value) && (params.value.isNaN() || !params.value.isFinite())) {
1081
1084
  return '-';
1082
1085
  }
1086
+ if (params.value !== undefined && params.value !== null) {
1087
+ var val = params.value;
1088
+ if (typeof val === 'number' || BigNumber.isBigNumber(val)) {
1089
+ val = new BigNumber(val).dp(2);
1090
+ }
1091
+ return "".concat(val).concat(expressionSuffix);
1092
+ }
1083
1093
  return params.value;
1084
1094
  };
1085
1095
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/components",
3
- "version": "1.1.2",
3
+ "version": "1.1.3-alpha.1",
4
4
  "description": "> TODO: description",
5
5
  "homepage": "",
6
6
  "license": "ISC",
@@ -62,5 +62,5 @@
62
62
  "publishConfig": {
63
63
  "registry": "https://registry.npmjs.org"
64
64
  },
65
- "gitHead": "37ad5368a2c745b0bea0bfe9e5ad2c4aeffe1635"
65
+ "gitHead": "9f776b18500b0819aa7008b18c580aaf8748b4d8"
66
66
  }