@lemon-fe/components 0.1.5 → 0.1.8

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,5 +1,5 @@
1
- var _excluded = ["onWidthChange", "width", "fullTableRef"],
2
- _excluded2 = ["id", "columns", "defaultColumnProps", "rowKey", "children", "summaryTitle", "summaryRecord", "dataSource", "onSortChange", "sort", "scroll", "virtual", "components", "pagination", "onChange", "rowHeight", "tableLayout", "rowActions"];
1
+ var _excluded = ["onWidthChange", "width", "fullTableRef", "children", "className"],
2
+ _excluded2 = ["id", "columns", "defaultColumnProps", "rowKey", "children", "summaryTitle", "summaryRecord", "dataSource", "onSortChange", "sort", "scroll", "virtual", "components", "pagination", "rowHeight", "tableLayout", "rowActions", "style"];
3
3
 
4
4
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
5
 
@@ -37,7 +37,7 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
37
37
  import React, { useMemo, useState, useEffect, useRef } from 'react';
38
38
  import { Table as AntdTable } from 'antd';
39
39
  import { get } from 'lodash';
40
- import { useThrottle } from '@lemon-fe/hooks';
40
+ import ResizeObserver from 'rc-resize-observer';
41
41
  import { isColumnType, getColumnKey } from './utils';
42
42
  import ResizeHeaderCell from './ResizeHeaderCell';
43
43
  import { PREFIX_CLS } from '../constants';
@@ -69,10 +69,25 @@ function Th(props) {
69
69
  var onWidthChange = props.onWidthChange,
70
70
  width = props.width,
71
71
  fullTableRef = props.fullTableRef,
72
+ children = props.children,
73
+ className = props.className,
72
74
  restProps = _objectWithoutProperties(props, _excluded);
73
75
 
76
+ var reg = /\bant-table-cell-ellipsis\b/;
77
+ var content = children;
78
+ var mClassName = className;
79
+
80
+ if (mClassName && reg.test(mClassName)) {
81
+ mClassName = mClassName.replace(reg, '');
82
+ content = /*#__PURE__*/React.createElement("div", {
83
+ className: "ant-table-cell-ellipsis"
84
+ }, content);
85
+ }
86
+
74
87
  if (!width || !onWidthChange) {
75
- return /*#__PURE__*/React.createElement("th", _objectSpread({}, restProps));
88
+ return /*#__PURE__*/React.createElement("th", _objectSpread(_objectSpread({}, restProps), {}, {
89
+ className: mClassName
90
+ }), content);
76
91
  }
77
92
 
78
93
  return /*#__PURE__*/React.createElement(ResizeHeaderCell, {
@@ -80,7 +95,9 @@ function Th(props) {
80
95
  onChange: onWidthChange,
81
96
  fullTableRef: fullTableRef,
82
97
  prefixCls: "".concat(PREFIX_CLS, "-table")
83
- }, /*#__PURE__*/React.createElement("th", _objectSpread({}, restProps)));
98
+ }, /*#__PURE__*/React.createElement("th", _objectSpread(_objectSpread({}, restProps), {}, {
99
+ className: mClassName
100
+ }), content));
84
101
  }
85
102
 
86
103
  function BaseTable(props) {
@@ -99,26 +116,29 @@ function BaseTable(props) {
99
116
  virtual = props.virtual,
100
117
  componentsProp = props.components,
101
118
  paginationProp = props.pagination,
102
- onChangeProp = props.onChange,
103
119
  rowHeight = props.rowHeight,
104
120
  _props$tableLayout = props.tableLayout,
105
121
  tableLayout = _props$tableLayout === void 0 ? 'fixed' : _props$tableLayout,
106
122
  rowActions = props.rowActions,
123
+ style = props.style,
107
124
  restProps = _objectWithoutProperties(props, _excluded2);
108
125
 
109
126
  var fullTableRef = useRef(null);
110
127
 
111
- var _useState = useState(0),
128
+ var _useState = useState(new Map()),
112
129
  _useState2 = _slicedToArray(_useState, 2),
113
- scrollY = _useState2[0],
114
- setScrollY = _useState2[1];
130
+ colsState = _useState2[0],
131
+ setColsState = _useState2[1];
132
+
133
+ var scrollYProp = scroll === null || scroll === void 0 ? void 0 : scroll.y;
115
134
 
116
- var _useState3 = useState(new Map()),
135
+ var _useState3 = useState(scrollYProp === true ? 0 : scrollYProp),
117
136
  _useState4 = _slicedToArray(_useState3, 2),
118
- colsState = _useState4[0],
119
- setColsState = _useState4[1];
120
- /** auto scroll y */
137
+ scrollY = _useState4[0],
138
+ setScrollY = _useState4[1];
121
139
 
140
+ var memoHeight = useRef(0);
141
+ /** auto scroll y */
122
142
 
123
143
  var calcScrollY = function calcScrollY() {
124
144
  var wrapper = fullTableRef.current;
@@ -164,31 +184,34 @@ function BaseTable(props) {
164
184
  return contentHeight;
165
185
  };
166
186
 
167
- var changeScrollY = useThrottle(function () {
168
- var nextScrollY = scrollY;
169
-
170
- if ((scroll === null || scroll === void 0 ? void 0 : scroll.y) === true) {
171
- var y = calcScrollY();
172
- nextScrollY = y || undefined;
173
- } else {
174
- nextScrollY = scroll === null || scroll === void 0 ? void 0 : scroll.y;
187
+ var changeScrollY = function changeScrollY(height) {
188
+ if (height === memoHeight.current) {
189
+ return;
175
190
  }
176
191
 
177
- setScrollY(nextScrollY);
192
+ memoHeight.current = height;
193
+ setScrollY(calcScrollY() || undefined);
194
+ };
178
195
 
179
- if (fullTableRef.current !== null) {
196
+ useEffect(function () {
197
+ if (scrollYProp !== true) {
198
+ setScrollY(scrollYProp);
199
+ }
200
+ }, [scrollYProp]);
201
+ useEffect(function () {
202
+ if (scrollY !== undefined && fullTableRef.current !== null) {
180
203
  var body = fullTableRef.current.querySelector('.ant-table-body');
181
204
 
182
205
  if (body !== null) {
183
- var dataType = _typeof(nextScrollY);
206
+ var dataType = _typeof(scrollY);
184
207
 
185
208
  switch (dataType) {
186
209
  case 'string':
187
- body.style.height = nextScrollY;
210
+ body.style.height = scrollY;
188
211
  break;
189
212
 
190
213
  case 'number':
191
- body.style.height = nextScrollY + 'px';
214
+ body.style.height = scrollY + 'px';
192
215
  break;
193
216
 
194
217
  default:
@@ -196,29 +219,9 @@ function BaseTable(props) {
196
219
  }
197
220
  }
198
221
  }
199
- }, 100, {
200
- trailing: true
201
- });
202
- useEffect(function () {
203
- changeScrollY();
204
- }, [scroll === null || scroll === void 0 ? void 0 : scroll.y, dataSource]);
205
- useEffect(function () {
206
- window.addEventListener('resize', changeScrollY);
207
- return function () {
208
- window.removeEventListener('resize', changeScrollY);
209
- };
210
- }, []);
211
-
212
- var handleChange = function handleChange() {
213
- changeScrollY();
214
-
215
- if (onChangeProp) {
216
- onChangeProp.apply(void 0, arguments);
217
- }
218
- };
222
+ }, [scrollY]);
219
223
  /** resizable column */
220
224
 
221
-
222
225
  var _useMemo = useMemo(function () {
223
226
  var flattenCols = [];
224
227
  var isFixedLayout = tableLayout === 'fixed';
@@ -383,22 +386,22 @@ function BaseTable(props) {
383
386
  rowHeight: rowHeight
384
387
  };
385
388
  }, [scrollY, rowHeight]);
386
- return /*#__PURE__*/React.createElement(BaseTableContext.Provider, {
387
- value: ctx
388
- }, /*#__PURE__*/React.createElement(AntdTable, _objectSpread(_objectSpread({
389
+ var tableNode = /*#__PURE__*/React.createElement(AntdTable, _objectSpread(_objectSpread({
389
390
  size: "small",
390
391
  ref: fullTableRef,
391
392
  columns: formatedColumns,
392
393
  dataSource: dataSource,
393
394
  rowKey: rowKey,
394
395
  summary: summary,
396
+ components: components,
397
+ tableLayout: tableLayout,
395
398
  scroll: {
396
399
  x: (scroll === null || scroll === void 0 ? void 0 : scroll.x) || '100%',
397
400
  y: scrollY
398
401
  },
399
- components: components,
400
- onChange: handleChange,
401
- tableLayout: tableLayout,
402
+ style: scrollYProp === true ? _objectSpread(_objectSpread({}, style), {}, {
403
+ height: '100%'
404
+ }) : style,
402
405
  locale: {
403
406
  emptyText: /*#__PURE__*/React.createElement("div", {
404
407
  className: "".concat(PREFIX_CLS, "-table-empty")
@@ -417,7 +420,19 @@ function BaseTable(props) {
417
420
  },
418
421
  defaultPageSize: 20
419
422
  }, paginationProp) : false
420
- })));
423
+ }));
424
+
425
+ if (scrollYProp === true) {
426
+ tableNode = /*#__PURE__*/React.createElement(ResizeObserver, {
427
+ onResize: function onResize(size) {
428
+ return changeScrollY(size.height);
429
+ }
430
+ }, tableNode);
431
+ }
432
+
433
+ return /*#__PURE__*/React.createElement(BaseTableContext.Provider, {
434
+ value: ctx
435
+ }, tableNode);
421
436
  }
422
437
 
423
438
  BaseTable.Summary = AntdTable.Summary;
@@ -77,8 +77,12 @@
77
77
  content: '';
78
78
  }
79
79
 
80
- &-column::after {
81
- display: none !important;
80
+ &-column {
81
+ border-right: none !important;
82
+
83
+ &::after {
84
+ display: none !important;
85
+ }
82
86
  }
83
87
 
84
88
  &-item {
@@ -157,22 +161,28 @@
157
161
  width: 11px;
158
162
  height: 12px;
159
163
  margin-top: -6px;
164
+ padding: 0 5px;
165
+ background-color: #bbb;
166
+ background-clip: content-box;
160
167
  cursor: col-resize;
168
+ }
161
169
 
162
- & > div {
163
- width: 1px;
164
- height: 100%;
165
- margin: 0 auto;
166
- background-color: #bbb;
167
- }
170
+ .ant-table-bordered &-resizable-handle {
171
+ right: -6px;
172
+ background-color: transparent;
168
173
  }
169
174
 
170
175
  &-resizable-indicator {
171
176
  position: absolute;
172
177
  top: 0;
173
178
  z-index: 20;
174
- width: 1px;
179
+ box-sizing: border-box;
180
+ width: 11px;
181
+ margin-left: -5px;
182
+ padding: 0 5px;
175
183
  background-color: @resize-indicator-color;
184
+ background-clip: content-box;
185
+ cursor: col-resize;
176
186
  }
177
187
 
178
188
  &-resizing-col thead th {
@@ -136,11 +136,6 @@ export default function DurationPicker(props) {
136
136
  value = _useState2[0],
137
137
  setValue = _useState2[1];
138
138
 
139
- useEffect(function () {
140
- if (value !== defaultValue && value !== valueProp && onChange) {
141
- onChange(value);
142
- }
143
- }, [value]);
144
139
  useEffect(function () {
145
140
  if (valueProp !== undefined) {
146
141
  setValue(valueProp);
@@ -164,40 +159,48 @@ export default function DurationPicker(props) {
164
159
  }, [value]);
165
160
 
166
161
  var handleChangeType = function handleChangeType(item) {
167
- setValue(function (prev) {
168
- if (item.value === prev.type) {
169
- return prev;
170
- }
171
-
172
- return _objectSpread(_objectSpread({}, prev), {}, {
162
+ if (value.type !== item.value) {
163
+ var newValue = _objectSpread(_objectSpread({}, value), {}, {
173
164
  type: item.value
174
165
  });
175
- });
176
- };
177
166
 
178
- var handleChangeOption = function handleChangeOption(item) {
179
- setValue(function (prev) {
180
- if (item.label === prev.option) {
181
- return prev;
167
+ setValue(newValue);
168
+
169
+ if (onChange) {
170
+ onChange(newValue);
182
171
  }
172
+ }
173
+ };
183
174
 
184
- return _objectSpread(_objectSpread({}, prev), {}, {
185
- option: item.label,
175
+ var handleChangeOption = function handleChangeOption(item) {
176
+ if (value.option !== item.label) {
177
+ var newValue = _objectSpread(_objectSpread({}, value), {}, {
186
178
  dates: item.value !== null ? item.value().map(function (date) {
187
179
  return date.format(dateFormat);
188
- }) : undefined
180
+ }) : undefined,
181
+ option: item.label
189
182
  });
190
- });
183
+
184
+ setValue(newValue);
185
+
186
+ if (onChange) {
187
+ onChange(newValue);
188
+ }
189
+ }
191
190
  };
192
191
 
193
192
  var handleChangeDates = function handleChangeDates(dates) {
194
- setValue(function (prev) {
195
- return _objectSpread(_objectSpread({}, prev), {}, {
196
- dates: dates ? dates.map(function (item) {
197
- return item.format(dateFormat);
198
- }) : undefined
199
- });
193
+ var newValue = _objectSpread(_objectSpread({}, value), {}, {
194
+ dates: dates ? dates.map(function (item) {
195
+ return item.format(dateFormat);
196
+ }) : undefined
200
197
  });
198
+
199
+ setValue(newValue);
200
+
201
+ if (onChange) {
202
+ onChange(newValue);
203
+ }
201
204
  };
202
205
 
203
206
  return /*#__PURE__*/React.createElement("div", {
@@ -23,7 +23,7 @@
23
23
  }
24
24
 
25
25
  &-type.ant-dropdown-trigger {
26
- flex: 0 0 124px;
26
+ flex: 0 0 auto;
27
27
  margin-right: 8px;
28
28
  border: 1px solid @select-border-color;
29
29
  border-radius: @border-radius-base;
@@ -2,5 +2,6 @@ import type { ComponentOption, FilterProps } from './typings';
2
2
  declare function Filter<T extends Record<string, any> = Record<string, any>>(props: FilterProps<T>): JSX.Element;
3
3
  declare namespace Filter {
4
4
  var setComponents: (items: ComponentOption[]) => void;
5
+ var setStorage: <T>(getData: (storageKey: string) => T | Promise<T>, setData: <T_1>(storageKey: string, data: T_1) => void | Promise<void>) => void;
5
6
  }
6
7
  export default Filter;
@@ -67,6 +67,21 @@ var components = [{
67
67
  }, item.extraProps));
68
68
  }
69
69
  }];
70
+
71
+ var getStorageData = function getData(storageKey) {
72
+ var data = localStorage.getItem("filter-storage-".concat(storageKey));
73
+
74
+ if (data) {
75
+ return JSON.parse(data);
76
+ }
77
+
78
+ return null;
79
+ };
80
+
81
+ var setStorageData = function setData(storageKey, data) {
82
+ localStorage.setItem("filter-storage-".concat(storageKey), JSON.stringify(data));
83
+ };
84
+
70
85
  var DEFAULT_TAB_TITLE = '默认';
71
86
 
72
87
  function setComponents(items) {
@@ -79,6 +94,11 @@ function setComponents(items) {
79
94
  components = _toConsumableArray(compMap.values());
80
95
  }
81
96
 
97
+ function setStorage(getData, setData) {
98
+ getStorageData = getData;
99
+ setStorageData = setData;
100
+ }
101
+
82
102
  function Filter(props) {
83
103
  var data = props.data,
84
104
  defaultValueProp = props.defaultValue,
@@ -144,7 +164,7 @@ function Filter(props) {
144
164
  form = _Form$useForm4[0];
145
165
 
146
166
  var _useRequest = useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
147
- var tabsJson;
167
+ var tabsData;
148
168
  return regeneratorRuntime.wrap(function _callee$(_context) {
149
169
  while (1) {
150
170
  switch (_context.prev = _context.next) {
@@ -157,17 +177,12 @@ function Filter(props) {
157
177
  return _context.abrupt("return", null);
158
178
 
159
179
  case 2:
160
- tabsJson = localStorage.getItem("filter-storage-".concat(storageKey));
180
+ _context.next = 4;
181
+ return getStorageData(storageKey);
161
182
 
162
- if (!tabsJson) {
163
- _context.next = 5;
164
- break;
165
- }
166
-
167
- return _context.abrupt("return", JSON.parse(tabsJson));
168
-
169
- case 5:
170
- return _context.abrupt("return", null);
183
+ case 4:
184
+ tabsData = _context.sent;
185
+ return _context.abrupt("return", tabsData);
171
186
 
172
187
  case 6:
173
188
  case "end":
@@ -227,6 +242,10 @@ function Filter(props) {
227
242
  next.push(tab);
228
243
  }
229
244
 
245
+ if (!!storageKey) {
246
+ setStorageData(storageKey, next.slice(1));
247
+ }
248
+
230
249
  setTabs(next);
231
250
  setActive(index);
232
251
  setShowModal(false);
@@ -306,6 +325,12 @@ function Filter(props) {
306
325
  return next;
307
326
  });
308
327
  setActive(active - 1);
328
+
329
+ if (!!storageKey) {
330
+ setStorageData(storageKey, tabs.filter(function (item) {
331
+ return item.title !== tabs[active].title && item.title !== '默认';
332
+ }));
333
+ }
309
334
  }
310
335
  });
311
336
  };
@@ -525,4 +550,5 @@ function Filter(props) {
525
550
  }
526
551
 
527
552
  Filter.setComponents = setComponents;
553
+ Filter.setStorage = setStorage;
528
554
  export default Filter;
@@ -74,6 +74,7 @@
74
74
 
75
75
  &-item {
76
76
  margin-top: 16px;
77
+ overflow: hidden;
77
78
 
78
79
  .ant-checkbox-wrapper {
79
80
  color: #888;
@@ -18,6 +18,7 @@
18
18
 
19
19
  &-flex &-body {
20
20
  flex: 1 1 100%;
21
+ min-height: 0;
21
22
  }
22
23
 
23
24
  &-header {
@@ -63,7 +63,8 @@ export default function TreeNodeTitle(props) {
63
63
  var others = (_operation$others = operation.others) === null || _operation$others === void 0 ? void 0 : _operation$others.call(operation, item);
64
64
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
65
65
  className: "".concat(prefixCls, "-title-content"),
66
- ref: trigger
66
+ ref: trigger,
67
+ title: item.title.toString()
67
68
  }, item.title), /*#__PURE__*/React.createElement("div", {
68
69
  className: "".concat(prefixCls, "-title-operators"),
69
70
  style: {
@@ -69,6 +69,7 @@
69
69
  &-unit {
70
70
  display: inline-block;
71
71
  width: @indentWidth;
72
+ vertical-align: top;
72
73
  }
73
74
  }
74
75
 
@@ -121,7 +122,7 @@
121
122
  flex: 1;
122
123
  align-items: center;
123
124
  justify-content: space-between;
124
- min-width: 0;
125
+ min-width: 56px;
125
126
  padding: 0 8px;
126
127
  border-radius: 4px;
127
128
  cursor: pointer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/components",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
4
4
  "description": "> TODO: description",
5
5
  "author": "鲁盛杰 <lusj@cnlemon.net>",
6
6
  "homepage": "",
@@ -17,11 +17,8 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@lemon-fe/hooks": "^0.1.2",
20
- "antd": "^4.20.2",
21
20
  "classnames": "^2.2.6",
22
21
  "lodash": "^4.17.21",
23
- "react": "^17.0.2",
24
- "react-dom": "^17.0.2",
25
22
  "react-resizable": "^3.0.4"
26
23
  },
27
24
  "peerDependencies": {
@@ -30,6 +27,7 @@
30
27
  "classnames": ">=2.2.6",
31
28
  "color-string": ">=1.0.0",
32
29
  "lodash": ">=4.17.0",
30
+ "rc-resize-observer": "^1.0.0",
33
31
  "rc-tree": ">=4.0.0",
34
32
  "react": ">=16.9.0",
35
33
  "react-dom": ">=16.9.0"
@@ -37,7 +35,11 @@
37
35
  "devDependencies": {
38
36
  "@types/color-string": "^1.5.2",
39
37
  "@types/lodash": "^4.14.179",
40
- "@types/react-resizable": "^1.7.4"
38
+ "@types/react-resizable": "^1.7.4",
39
+ "antd": "^4.20.2",
40
+ "rc-resize-observer": "^1.2.0",
41
+ "react": "^17.0.2",
42
+ "react-dom": "^17.0.2"
41
43
  },
42
- "gitHead": "03156b8418da16a062304610592219d40df9e313"
44
+ "gitHead": "4ccc4baa581c66b4820373dffec12433c3ae7712"
43
45
  }