@sheinx/hooks 3.1.5 → 3.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"use-filter.d.ts","sourceRoot":"","sources":["use-filter.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,QAAA,MAAM,SAAS;;;;;;;;;;kCAoBkD,OAAO;sBAqD1C,MAAM;sBAKN,MAAM,SAAQ,MAAM;;CAiFjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"use-filter.d.ts","sourceRoot":"","sources":["use-filter.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,QAAA,MAAM,SAAS;;;;;;;;;;kCAmBkD,OAAO;sBAiB1C,MAAM;sBAKN,MAAM,SAAQ,MAAM;;CAuGjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -32,26 +32,22 @@ var useFilter = function useFilter(props) {
32
32
  onAdvancedFilter = props.onAdvancedFilter,
33
33
  _props$filterDelay = props.filterDelay,
34
34
  filterDelay = _props$filterDelay === void 0 ? 400 : _props$filterDelay;
35
- var _useState = (0, _react.useState)(data),
35
+ var _useState = (0, _react.useState)(''),
36
36
  _useState2 = _slicedToArray(_useState, 2),
37
- filterData = _useState2[0],
38
- setFilterData = _useState2[1];
39
- var _useState3 = (0, _react.useState)(''),
37
+ filterText = _useState2[0],
38
+ setFilterText = _useState2[1];
39
+ var _useState3 = (0, _react.useState)(undefined),
40
40
  _useState4 = _slicedToArray(_useState3, 2),
41
- filterText = _useState4[0],
42
- setFilterText = _useState4[1];
43
- var _useState5 = (0, _react.useState)(undefined),
41
+ filterFunc = _useState4[0],
42
+ setFilterFunc = _useState4[1];
43
+ var _useState5 = (0, _react.useState)(''),
44
44
  _useState6 = _slicedToArray(_useState5, 2),
45
- filterFunc = _useState6[0],
46
- setFilterFunc = _useState6[1];
47
- var _useState7 = (0, _react.useState)(''),
45
+ inputText = _useState6[0],
46
+ setInputText = _useState6[1];
47
+ var _useState7 = (0, _react.useState)(),
48
48
  _useState8 = _slicedToArray(_useState7, 2),
49
- inputText = _useState8[0],
50
- setInputText = _useState8[1];
51
- var _useState9 = (0, _react.useState)(),
52
- _useState10 = _slicedToArray(_useState9, 2),
53
- createdData = _useState10[0],
54
- setCreatedData = _useState10[1];
49
+ createdData = _useState8[0],
50
+ setCreatedData = _useState8[1];
55
51
  var firstMatchNode = (0, _react.useRef)();
56
52
  var _useRef = (0, _react.useRef)({
57
53
  filterTimer: null
@@ -60,36 +56,6 @@ var useFilter = function useFilter(props) {
60
56
  var filterFn = onFilterWidthCreate || function (item, createdData, key) {
61
57
  return (0, _utils.getKey)(keygen, item) === key;
62
58
  };
63
- var getData = function getData() {
64
- var newData = filterData || [];
65
- if (createdData && !hideCreateOption) {
66
- var newKey = (0, _utils.getKey)(keygen, createdData);
67
- var sameItem = newData.find(function (item) {
68
- return filterFn(item, createdData, newKey);
69
- });
70
- if (!sameItem) return [createdData].concat(_toConsumableArray(newData));
71
- }
72
- return newData;
73
- };
74
- var getFirstMatchNode = function getFirstMatchNode(node) {
75
- if (firstMatchNode.current) return;
76
- firstMatchNode.current = node;
77
- };
78
- var getTreeData = function getTreeData() {
79
- var filterExpandedKeys = expandedProp || [];
80
- var newData = treeData;
81
- if (filterText) {
82
- newData = (0, _utils.getFilterTree)(treeData, onFilter === null || onFilter === void 0 ? void 0 : onFilter(filterText), filterExpandedKeys, function (node) {
83
- return (0, _utils.getKey)(keygen, node);
84
- }, childrenKey, !!showHitDescendants, firstMatch ? getFirstMatchNode : undefined, {
85
- advanced: !!onAdvancedFilter
86
- });
87
- }
88
- return {
89
- newData: newData,
90
- filterExpandedKeys: filterExpandedKeys
91
- };
92
- };
93
59
  var handleClearCreatedData = function handleClearCreatedData() {
94
60
  setCreatedData(undefined);
95
61
  };
@@ -101,17 +67,11 @@ var useFilter = function useFilter(props) {
101
67
  };
102
68
  var handleFilter = function handleFilter(text) {
103
69
  var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'edit';
70
+ if (context.filterTimer) clearTimeout(context.filterTimer);
104
71
  setInputText(text);
105
72
  setFilterText(text);
106
73
  firstMatchNode.current = null;
107
- if (context.filterTimer) clearTimeout(context.filterTimer);
108
74
  if (!text) {
109
- if (data) {
110
- setFilterData(data);
111
- }
112
- if (treeData) {
113
- setFilterData(treeData);
114
- }
115
75
  setFilterFunc(undefined);
116
76
  handleClearCreatedData();
117
77
  // 没有 text 时触发一次 onFilter 以便外部重置数据
@@ -129,32 +89,61 @@ var useFilter = function useFilter(props) {
129
89
  setFilterFunc(function () {
130
90
  return next;
131
91
  });
132
- var nextData = data === null || data === void 0 ? void 0 : data.filter(function (item) {
133
- if (!groupKey) return next(item);
134
- // 剔除分组项
135
- if (item[groupKey]) return item;
136
- return next(item);
137
- });
138
- setFilterData(nextData);
139
92
  }, filterDelay);
140
93
  };
141
- (0, _react.useEffect)(function () {
142
- if (data) setFilterData(data);
143
- }, [data]);
144
94
  (0, _react.useEffect)(function () {
145
95
  if (context.filterTimer) clearTimeout(context.filterTimer);
146
96
  }, []);
147
- var nextData;
148
- var nextExpanded;
149
- if (treeData) {
150
- var _getTreeData = getTreeData(),
151
- newData = _getTreeData.newData,
152
- filterExpandedKeys = _getTreeData.filterExpandedKeys;
153
- nextData = newData;
154
- nextExpanded = filterExpandedKeys;
155
- } else if (data) {
156
- nextData = getData();
157
- }
97
+ var _useMemo = (0, _react.useMemo)(function () {
98
+ if (treeData) {
99
+ var getTreeData = function getTreeData() {
100
+ var getFirstMatchNode = function getFirstMatchNode(node) {
101
+ if (firstMatchNode.current) return;
102
+ firstMatchNode.current = node;
103
+ };
104
+ var filterExpandedKeys = expandedProp || [];
105
+ var newData = treeData;
106
+ if (filterFunc) {
107
+ newData = (0, _utils.getFilterTree)(treeData, filterFunc, filterExpandedKeys, function (node) {
108
+ return (0, _utils.getKey)(keygen, node);
109
+ }, childrenKey, !!showHitDescendants, firstMatch ? getFirstMatchNode : undefined, {
110
+ advanced: !!onAdvancedFilter
111
+ });
112
+ }
113
+ return {
114
+ newData: newData,
115
+ filterExpandedKeys: filterExpandedKeys
116
+ };
117
+ };
118
+ var _getTreeData = getTreeData(),
119
+ newData = _getTreeData.newData,
120
+ filterExpandedKeys = _getTreeData.filterExpandedKeys;
121
+ return [newData, filterExpandedKeys];
122
+ } else if (data) {
123
+ var getData = function getData() {
124
+ var newData = (filterFunc ? data === null || data === void 0 ? void 0 : data.filter(function (item) {
125
+ if (!groupKey) return filterFunc(item);
126
+ // 剔除分组项
127
+ if (item[groupKey]) return item;
128
+ return filterFunc(item);
129
+ }) : data) || [];
130
+ if (createdData && !hideCreateOption) {
131
+ var newKey = (0, _utils.getKey)(keygen, createdData);
132
+ var sameItem = newData.find(function (item) {
133
+ return filterFn(item, createdData, newKey);
134
+ });
135
+ if (!sameItem) return [createdData].concat(_toConsumableArray(newData));
136
+ }
137
+ return newData;
138
+ };
139
+ return [getData(), undefined];
140
+ } else {
141
+ return [undefined, undefined];
142
+ }
143
+ }, [data, treeData, filterFunc, createdData, expandedProp]),
144
+ _useMemo2 = _slicedToArray(_useMemo, 2),
145
+ nextData = _useMemo2[0],
146
+ nextExpanded = _useMemo2[1];
158
147
  return {
159
148
  inputText: inputText,
160
149
  filterText: filterText,
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAsBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;CAwT7F,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAuBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;CAwT7F,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -401,7 +401,7 @@ var useForm = function useForm(props) {
401
401
  React.useEffect(function () {
402
402
  context.removeLock = false;
403
403
  if (props.value === context.lastValue) return;
404
- context.value = props.value || emptyObj;
404
+ context.value = (0, _utils.deepClone)(props.value) || emptyObj;
405
405
  if (initValidate && !context.resetTime) {
406
406
  var keys = Object.keys(context.validateMap).filter(function (key) {
407
407
  var oldValue = (0, _utils.deepGet)(context.lastValue || emptyObj, key);
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-layout.d.ts","sourceRoot":"","sources":["use-table-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAKlE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAcrE,MAAM,WAAW,mBACf,SAAQ,IAAI,CACV,cAAc,CAAC,GAAG,CAAC,EACnB,MAAM,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,OAAO,CAC7E;IACD,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,QAAA,MAAM,cAAc,UAAW,mBAAmB;;;;;;;;;;;yBA8CX,MAAM,UAAU,MAAM;;;;;;;;CA2N5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"use-table-layout.d.ts","sourceRoot":"","sources":["use-table-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAKlE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAcrE,MAAM,WAAW,mBACf,SAAQ,IAAI,CACV,cAAc,CAAC,GAAG,CAAC,EACnB,MAAM,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,OAAO,CAC7E;IACD,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,QAAA,MAAM,cAAc,UAAW,mBAAmB;;;;;;;;;;;yBA8CX,MAAM,UAAU,MAAM;;;;;;;;CA8N5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -50,7 +50,7 @@ var useTableLayout = function useTableLayout(props) {
50
50
  clientWidth: 0
51
51
  }),
52
52
  context = _useRef.current;
53
- var _React$useState = _react.default.useState(false),
53
+ var _React$useState = _react.default.useState(undefined),
54
54
  _React$useState2 = _slicedToArray(_React$useState, 2),
55
55
  isScrollX = _React$useState2[0],
56
56
  setIsScrollX = _React$useState2[1];
@@ -58,7 +58,7 @@ var useTableLayout = function useTableLayout(props) {
58
58
  _React$useState4 = _slicedToArray(_React$useState3, 2),
59
59
  deltaXSum = _React$useState4[0],
60
60
  setDeltaXSum = _React$useState4[1];
61
- var _React$useState5 = _react.default.useState(false),
61
+ var _React$useState5 = _react.default.useState(undefined),
62
62
  _React$useState6 = _slicedToArray(_React$useState5, 2),
63
63
  isScrollY = _React$useState6[0],
64
64
  setIsScrollY = _React$useState6[1];
@@ -160,9 +160,9 @@ var useTableLayout = function useTableLayout(props) {
160
160
  var newColgroup = _toConsumableArray(colgroup);
161
161
  newColgroup[index] = context.dragWidth;
162
162
  if ((0, _is.isFunc)(props.onColumnResize)) {
163
- var newColumns = props.columns.map(function (item) {
163
+ var newColumns = props.columns.map(function (item, i) {
164
164
  return _objectSpread(_objectSpread({}, item), {}, {
165
- width: newColgroup[index]
165
+ width: newColgroup[i]
166
166
  });
167
167
  });
168
168
  props.onColumnResize(newColumns);
@@ -196,13 +196,15 @@ var useTableLayout = function useTableLayout(props) {
196
196
  if (!tr) return;
197
197
  var items = tr.children;
198
198
  var newCols = [];
199
+ var index = 0;
199
200
  var sum = 0;
200
201
  var _loop = function _loop() {
201
202
  var _items$i$getBoundingC = items[i].getBoundingClientRect(),
202
203
  width = _items$i$getBoundingC.width;
203
204
  sum += width;
204
205
  var colspan = items[i].getAttribute('colspan');
205
- var dfWidth = props.columns.slice(i, i + (colspan ? parseInt(colspan, 10) : 1)).map(function (v) {
206
+ var colspanNum = parseInt(colspan || '1', 10);
207
+ var dfWidth = props.columns.slice(index, index + colspanNum).map(function (v) {
206
208
  return v.width;
207
209
  });
208
210
  var tempcols = [];
@@ -231,6 +233,7 @@ var useTableLayout = function useTableLayout(props) {
231
233
  return v ? v : agv;
232
234
  });
233
235
  }
236
+ index += colspanNum;
234
237
  newCols = [].concat(_toConsumableArray(newCols), _toConsumableArray(tempcols));
235
238
  };
236
239
  for (var i = 0, count = items.length; i < count; i++) {
@@ -306,8 +309,8 @@ var useTableLayout = function useTableLayout(props) {
306
309
  var hasNoWith = props.columns.find(function (v) {
307
310
  return v.width === undefined;
308
311
  });
309
- if (hasNoWith && preData && props.data && props.data.length !== preData.length) {
310
- if (preData.length === 0 || props.dataChangeResize) resetColGroup();
312
+ if (preData && props.data && props.data.length !== preData.length) {
313
+ if (preData.length === 0 || props.dataChangeResize || hasNoWith) resetColGroup();
311
314
  }
312
315
  }, [props.columns, props.data, props.dataChangeResize]);
313
316
  (0, _react.useEffect)(function () {
@@ -315,7 +318,8 @@ var useTableLayout = function useTableLayout(props) {
315
318
  syncScrollWidth();
316
319
  if (scrollRef.current) {
317
320
  cancelFunc = (0, _element.addResizeObserver)(scrollRef.current, handleResize, {
318
- direction: true
321
+ direction: true,
322
+ timer: 10
319
323
  });
320
324
  }
321
325
  return function () {
@@ -335,8 +339,8 @@ var useTableLayout = function useTableLayout(props) {
335
339
  }
336
340
  }, [colgroup]);
337
341
  return {
338
- isScrollX: isScrollX,
339
- isScrollY: isScrollY,
342
+ isScrollX: !!isScrollX,
343
+ isScrollY: !!isScrollY,
340
344
  floatLeft: floatLeft,
341
345
  floatRight: floatRight,
342
346
  scrollBarWidth: scrollBarWidth,
@@ -1 +1 @@
1
- {"version":3,"file":"use-filter.d.ts","sourceRoot":"","sources":["use-filter.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,QAAA,MAAM,SAAS;;;;;;;;;;kCAoBkD,OAAO;sBAqD1C,MAAM;sBAKN,MAAM,SAAQ,MAAM;;CAiFjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"use-filter.d.ts","sourceRoot":"","sources":["use-filter.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,QAAA,MAAM,SAAS;;;;;;;;;;kCAmBkD,OAAO;sBAiB1C,MAAM;sBAKN,MAAM,SAAQ,MAAM;;CAuGjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -8,7 +8,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
8
8
  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; }
9
9
  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; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
- import { useState, useEffect, useRef } from 'react';
11
+ import { useState, useEffect, useRef, useMemo } from 'react';
12
12
  import { isFunc, getKey, getFilterTree } from "../../utils";
13
13
  var useFilter = function useFilter(props) {
14
14
  var data = props.data,
@@ -26,26 +26,22 @@ var useFilter = function useFilter(props) {
26
26
  onAdvancedFilter = props.onAdvancedFilter,
27
27
  _props$filterDelay = props.filterDelay,
28
28
  filterDelay = _props$filterDelay === void 0 ? 400 : _props$filterDelay;
29
- var _useState = useState(data),
29
+ var _useState = useState(''),
30
30
  _useState2 = _slicedToArray(_useState, 2),
31
- filterData = _useState2[0],
32
- setFilterData = _useState2[1];
33
- var _useState3 = useState(''),
31
+ filterText = _useState2[0],
32
+ setFilterText = _useState2[1];
33
+ var _useState3 = useState(undefined),
34
34
  _useState4 = _slicedToArray(_useState3, 2),
35
- filterText = _useState4[0],
36
- setFilterText = _useState4[1];
37
- var _useState5 = useState(undefined),
35
+ filterFunc = _useState4[0],
36
+ setFilterFunc = _useState4[1];
37
+ var _useState5 = useState(''),
38
38
  _useState6 = _slicedToArray(_useState5, 2),
39
- filterFunc = _useState6[0],
40
- setFilterFunc = _useState6[1];
41
- var _useState7 = useState(''),
39
+ inputText = _useState6[0],
40
+ setInputText = _useState6[1];
41
+ var _useState7 = useState(),
42
42
  _useState8 = _slicedToArray(_useState7, 2),
43
- inputText = _useState8[0],
44
- setInputText = _useState8[1];
45
- var _useState9 = useState(),
46
- _useState10 = _slicedToArray(_useState9, 2),
47
- createdData = _useState10[0],
48
- setCreatedData = _useState10[1];
43
+ createdData = _useState8[0],
44
+ setCreatedData = _useState8[1];
49
45
  var firstMatchNode = useRef();
50
46
  var _useRef = useRef({
51
47
  filterTimer: null
@@ -54,36 +50,6 @@ var useFilter = function useFilter(props) {
54
50
  var filterFn = onFilterWidthCreate || function (item, createdData, key) {
55
51
  return getKey(keygen, item) === key;
56
52
  };
57
- var getData = function getData() {
58
- var newData = filterData || [];
59
- if (createdData && !hideCreateOption) {
60
- var newKey = getKey(keygen, createdData);
61
- var sameItem = newData.find(function (item) {
62
- return filterFn(item, createdData, newKey);
63
- });
64
- if (!sameItem) return [createdData].concat(_toConsumableArray(newData));
65
- }
66
- return newData;
67
- };
68
- var getFirstMatchNode = function getFirstMatchNode(node) {
69
- if (firstMatchNode.current) return;
70
- firstMatchNode.current = node;
71
- };
72
- var getTreeData = function getTreeData() {
73
- var filterExpandedKeys = expandedProp || [];
74
- var newData = treeData;
75
- if (filterText) {
76
- newData = getFilterTree(treeData, onFilter === null || onFilter === void 0 ? void 0 : onFilter(filterText), filterExpandedKeys, function (node) {
77
- return getKey(keygen, node);
78
- }, childrenKey, !!showHitDescendants, firstMatch ? getFirstMatchNode : undefined, {
79
- advanced: !!onAdvancedFilter
80
- });
81
- }
82
- return {
83
- newData: newData,
84
- filterExpandedKeys: filterExpandedKeys
85
- };
86
- };
87
53
  var handleClearCreatedData = function handleClearCreatedData() {
88
54
  setCreatedData(undefined);
89
55
  };
@@ -95,17 +61,11 @@ var useFilter = function useFilter(props) {
95
61
  };
96
62
  var handleFilter = function handleFilter(text) {
97
63
  var from = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'edit';
64
+ if (context.filterTimer) clearTimeout(context.filterTimer);
98
65
  setInputText(text);
99
66
  setFilterText(text);
100
67
  firstMatchNode.current = null;
101
- if (context.filterTimer) clearTimeout(context.filterTimer);
102
68
  if (!text) {
103
- if (data) {
104
- setFilterData(data);
105
- }
106
- if (treeData) {
107
- setFilterData(treeData);
108
- }
109
69
  setFilterFunc(undefined);
110
70
  handleClearCreatedData();
111
71
  // 没有 text 时触发一次 onFilter 以便外部重置数据
@@ -123,32 +83,61 @@ var useFilter = function useFilter(props) {
123
83
  setFilterFunc(function () {
124
84
  return next;
125
85
  });
126
- var nextData = data === null || data === void 0 ? void 0 : data.filter(function (item) {
127
- if (!groupKey) return next(item);
128
- // 剔除分组项
129
- if (item[groupKey]) return item;
130
- return next(item);
131
- });
132
- setFilterData(nextData);
133
86
  }, filterDelay);
134
87
  };
135
- useEffect(function () {
136
- if (data) setFilterData(data);
137
- }, [data]);
138
88
  useEffect(function () {
139
89
  if (context.filterTimer) clearTimeout(context.filterTimer);
140
90
  }, []);
141
- var nextData;
142
- var nextExpanded;
143
- if (treeData) {
144
- var _getTreeData = getTreeData(),
145
- newData = _getTreeData.newData,
146
- filterExpandedKeys = _getTreeData.filterExpandedKeys;
147
- nextData = newData;
148
- nextExpanded = filterExpandedKeys;
149
- } else if (data) {
150
- nextData = getData();
151
- }
91
+ var _useMemo = useMemo(function () {
92
+ if (treeData) {
93
+ var getTreeData = function getTreeData() {
94
+ var getFirstMatchNode = function getFirstMatchNode(node) {
95
+ if (firstMatchNode.current) return;
96
+ firstMatchNode.current = node;
97
+ };
98
+ var filterExpandedKeys = expandedProp || [];
99
+ var newData = treeData;
100
+ if (filterFunc) {
101
+ newData = getFilterTree(treeData, filterFunc, filterExpandedKeys, function (node) {
102
+ return getKey(keygen, node);
103
+ }, childrenKey, !!showHitDescendants, firstMatch ? getFirstMatchNode : undefined, {
104
+ advanced: !!onAdvancedFilter
105
+ });
106
+ }
107
+ return {
108
+ newData: newData,
109
+ filterExpandedKeys: filterExpandedKeys
110
+ };
111
+ };
112
+ var _getTreeData = getTreeData(),
113
+ newData = _getTreeData.newData,
114
+ filterExpandedKeys = _getTreeData.filterExpandedKeys;
115
+ return [newData, filterExpandedKeys];
116
+ } else if (data) {
117
+ var getData = function getData() {
118
+ var newData = (filterFunc ? data === null || data === void 0 ? void 0 : data.filter(function (item) {
119
+ if (!groupKey) return filterFunc(item);
120
+ // 剔除分组项
121
+ if (item[groupKey]) return item;
122
+ return filterFunc(item);
123
+ }) : data) || [];
124
+ if (createdData && !hideCreateOption) {
125
+ var newKey = getKey(keygen, createdData);
126
+ var sameItem = newData.find(function (item) {
127
+ return filterFn(item, createdData, newKey);
128
+ });
129
+ if (!sameItem) return [createdData].concat(_toConsumableArray(newData));
130
+ }
131
+ return newData;
132
+ };
133
+ return [getData(), undefined];
134
+ } else {
135
+ return [undefined, undefined];
136
+ }
137
+ }, [data, treeData, filterFunc, createdData, expandedProp]),
138
+ _useMemo2 = _slicedToArray(_useMemo, 2),
139
+ nextData = _useMemo2[0],
140
+ nextExpanded = _useMemo2[1];
152
141
  return {
153
142
  inputText: inputText,
154
143
  filterText: filterText,
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAsBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;CAwT7F,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAuBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;CAwT7F,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -14,7 +14,7 @@ import usePersistFn from "../../common/use-persist-fn";
14
14
  import { getDataAttributeName } from "../../utils/attribute";
15
15
  var globalKey = '__global__&&@@';
16
16
  import { current, produce } from "../../utils/immer";
17
- import { deepGet, deepRemove, deepSet, docScroll, extractEventHandlers, isArray, isObject, shallowEqual, wrapFormError } from "../../utils";
17
+ import { deepGet, deepRemove, deepSet, docScroll, extractEventHandlers, isArray, isObject, shallowEqual, wrapFormError, deepClone } from "../../utils";
18
18
  var emptyObj = {};
19
19
  var useForm = function useForm(props) {
20
20
  var _props$defaultValue = props.defaultValue,
@@ -392,7 +392,7 @@ var useForm = function useForm(props) {
392
392
  React.useEffect(function () {
393
393
  context.removeLock = false;
394
394
  if (props.value === context.lastValue) return;
395
- context.value = props.value || emptyObj;
395
+ context.value = deepClone(props.value) || emptyObj;
396
396
  if (initValidate && !context.resetTime) {
397
397
  var keys = Object.keys(context.validateMap).filter(function (key) {
398
398
  var oldValue = deepGet(context.lastValue || emptyObj, key);
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-layout.d.ts","sourceRoot":"","sources":["use-table-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAKlE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAcrE,MAAM,WAAW,mBACf,SAAQ,IAAI,CACV,cAAc,CAAC,GAAG,CAAC,EACnB,MAAM,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,OAAO,CAC7E;IACD,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,QAAA,MAAM,cAAc,UAAW,mBAAmB;;;;;;;;;;;yBA8CX,MAAM,UAAU,MAAM;;;;;;;;CA2N5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"use-table-layout.d.ts","sourceRoot":"","sources":["use-table-layout.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAKlE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAcrE,MAAM,WAAW,mBACf,SAAQ,IAAI,CACV,cAAc,CAAC,GAAG,CAAC,EACnB,MAAM,GAAG,kBAAkB,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,OAAO,CAC7E;IACD,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACvC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,QAAA,MAAM,cAAc,UAAW,mBAAmB;;;;;;;;;;;yBA8CX,MAAM,UAAU,MAAM;;;;;;;;CA8N5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -41,7 +41,7 @@ var useTableLayout = function useTableLayout(props) {
41
41
  clientWidth: 0
42
42
  }),
43
43
  context = _useRef.current;
44
- var _React$useState = React.useState(false),
44
+ var _React$useState = React.useState(undefined),
45
45
  _React$useState2 = _slicedToArray(_React$useState, 2),
46
46
  isScrollX = _React$useState2[0],
47
47
  setIsScrollX = _React$useState2[1];
@@ -49,7 +49,7 @@ var useTableLayout = function useTableLayout(props) {
49
49
  _React$useState4 = _slicedToArray(_React$useState3, 2),
50
50
  deltaXSum = _React$useState4[0],
51
51
  setDeltaXSum = _React$useState4[1];
52
- var _React$useState5 = React.useState(false),
52
+ var _React$useState5 = React.useState(undefined),
53
53
  _React$useState6 = _slicedToArray(_React$useState5, 2),
54
54
  isScrollY = _React$useState6[0],
55
55
  setIsScrollY = _React$useState6[1];
@@ -151,9 +151,9 @@ var useTableLayout = function useTableLayout(props) {
151
151
  var newColgroup = _toConsumableArray(colgroup);
152
152
  newColgroup[index] = context.dragWidth;
153
153
  if (isFunc(props.onColumnResize)) {
154
- var newColumns = props.columns.map(function (item) {
154
+ var newColumns = props.columns.map(function (item, i) {
155
155
  return _objectSpread(_objectSpread({}, item), {}, {
156
- width: newColgroup[index]
156
+ width: newColgroup[i]
157
157
  });
158
158
  });
159
159
  props.onColumnResize(newColumns);
@@ -187,13 +187,15 @@ var useTableLayout = function useTableLayout(props) {
187
187
  if (!tr) return;
188
188
  var items = tr.children;
189
189
  var newCols = [];
190
+ var index = 0;
190
191
  var sum = 0;
191
192
  var _loop = function _loop() {
192
193
  var _items$i$getBoundingC = items[i].getBoundingClientRect(),
193
194
  width = _items$i$getBoundingC.width;
194
195
  sum += width;
195
196
  var colspan = items[i].getAttribute('colspan');
196
- var dfWidth = props.columns.slice(i, i + (colspan ? parseInt(colspan, 10) : 1)).map(function (v) {
197
+ var colspanNum = parseInt(colspan || '1', 10);
198
+ var dfWidth = props.columns.slice(index, index + colspanNum).map(function (v) {
197
199
  return v.width;
198
200
  });
199
201
  var tempcols = [];
@@ -222,6 +224,7 @@ var useTableLayout = function useTableLayout(props) {
222
224
  return v ? v : agv;
223
225
  });
224
226
  }
227
+ index += colspanNum;
225
228
  newCols = [].concat(_toConsumableArray(newCols), _toConsumableArray(tempcols));
226
229
  };
227
230
  for (var i = 0, count = items.length; i < count; i++) {
@@ -297,8 +300,8 @@ var useTableLayout = function useTableLayout(props) {
297
300
  var hasNoWith = props.columns.find(function (v) {
298
301
  return v.width === undefined;
299
302
  });
300
- if (hasNoWith && preData && props.data && props.data.length !== preData.length) {
301
- if (preData.length === 0 || props.dataChangeResize) resetColGroup();
303
+ if (preData && props.data && props.data.length !== preData.length) {
304
+ if (preData.length === 0 || props.dataChangeResize || hasNoWith) resetColGroup();
302
305
  }
303
306
  }, [props.columns, props.data, props.dataChangeResize]);
304
307
  useEffect(function () {
@@ -306,7 +309,8 @@ var useTableLayout = function useTableLayout(props) {
306
309
  syncScrollWidth();
307
310
  if (scrollRef.current) {
308
311
  cancelFunc = addResizeObserver(scrollRef.current, handleResize, {
309
- direction: true
312
+ direction: true,
313
+ timer: 10
310
314
  });
311
315
  }
312
316
  return function () {
@@ -326,8 +330,8 @@ var useTableLayout = function useTableLayout(props) {
326
330
  }
327
331
  }, [colgroup]);
328
332
  return {
329
- isScrollX: isScrollX,
330
- isScrollY: isScrollY,
333
+ isScrollX: !!isScrollX,
334
+ isScrollY: !!isScrollY,
331
335
  floatLeft: floatLeft,
332
336
  floatRight: floatRight,
333
337
  scrollBarWidth: scrollBarWidth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.1.5",
3
+ "version": "3.1.7",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",