@sheinx/hooks 3.5.0-beta.9 → 3.5.1-beta.1
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/components/use-image/use-image.type.d.ts +2 -2
- package/cjs/components/use-table/use-table-layout.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-layout.js +10 -1
- package/cjs/components/use-table/use-table-tree.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-tree.js +48 -22
- package/esm/components/use-image/use-image.type.d.ts +2 -2
- package/esm/components/use-table/use-table-layout.d.ts.map +1 -1
- package/esm/components/use-table/use-table-layout.js +10 -1
- package/esm/components/use-table/use-table-tree.d.ts.map +1 -1
- package/esm/components/use-table/use-table-tree.js +48 -22
- package/package.json +1 -1
@@ -101,13 +101,13 @@ export interface BaseImageProps {
|
|
101
101
|
/**
|
102
102
|
* @en The width of the image
|
103
103
|
* @cn 图片宽度
|
104
|
-
* @default
|
104
|
+
* @default 100%
|
105
105
|
*/
|
106
106
|
width?: number | string;
|
107
107
|
/**
|
108
108
|
* @en The height of the image
|
109
109
|
* @cn 图片高度
|
110
|
-
* @default
|
110
|
+
* @default 100%
|
111
111
|
*/
|
112
112
|
height?: number | string;
|
113
113
|
/**
|
@@ -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;AAerE,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;;;;;;;;;;;yBA+CX,MAAM,UAAU,MAAM;;;;;;;;
|
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;AAerE,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;;;;;;;;;;;yBA+CX,MAAM,UAAU,MAAM;;;;;;;;CA+O5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
@@ -347,7 +347,16 @@ var useTableLayout = function useTableLayout(props) {
|
|
347
347
|
checkScroll();
|
348
348
|
checkFloat();
|
349
349
|
}, [colgroup]);
|
350
|
-
var tableWidth =
|
350
|
+
var tableWidth = props.width;
|
351
|
+
if (typeof props.width === 'string' && props.width.endsWith('%')) {
|
352
|
+
tableWidth = props.width;
|
353
|
+
} else if (typeof props.width === 'number') {
|
354
|
+
tableWidth = props.width + deltaXSum;
|
355
|
+
} else if (!isNaN(Number(props.width))) {
|
356
|
+
tableWidth = props.width;
|
357
|
+
} else {
|
358
|
+
tableWidth = undefined;
|
359
|
+
}
|
351
360
|
return {
|
352
361
|
isScrollX: !!isScrollX,
|
353
362
|
isScrollY: !!isScrollY,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-table-tree.d.ts","sourceRoot":"","sources":["use-table-tree.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;
|
1
|
+
{"version":3,"file":"use-table-tree.d.ts","sourceRoot":"","sources":["use-table-tree.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AA8CvD,MAAM,WAAW,iBACf,SAAQ,IAAI,CACV,kBAAkB,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EACvC,cAAc,GAAG,gBAAgB,GAAG,uBAAuB,GAAG,QAAQ,CACvE;IACD,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB;;;;;;+BA6BR,GAAG,SAAS,MAAM;iCAjBhB,GAAG,SAAS,MAAM;;CAuDhE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
@@ -19,35 +19,47 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
19
19
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
20
20
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
21
21
|
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; }
|
22
|
-
var getExpandData = function getExpandData(
|
22
|
+
var getExpandData = function getExpandData(_treeData, keys, keygen, treeColumnsName) {
|
23
23
|
var expandKeys = keys;
|
24
24
|
var expandSet = new Set(expandKeys);
|
25
|
-
var
|
25
|
+
var unmatchExpandKeys = [];
|
26
|
+
var treeExpandLevel = new Map();
|
26
27
|
if (expandSet.size === 0 || !treeColumnsName) {
|
27
|
-
return
|
28
|
+
return {
|
29
|
+
treeData: _treeData,
|
30
|
+
treeExpandLevel: treeExpandLevel,
|
31
|
+
unmatchExpandKeys: unmatchExpandKeys
|
32
|
+
};
|
28
33
|
}
|
29
|
-
var
|
34
|
+
var treeData = _toConsumableArray(_treeData || []);
|
30
35
|
var _loop = function _loop() {
|
31
36
|
if (expandSet.size === 0) return 1; // break
|
32
|
-
var item =
|
37
|
+
var item = treeData[i];
|
33
38
|
var key = (0, _render.getKey)(keygen, item, i);
|
34
|
-
var parentLevel =
|
39
|
+
var parentLevel = treeExpandLevel.get(key) || 0;
|
35
40
|
var children = (0, _is.isObject)(item) && item[treeColumnsName];
|
36
|
-
if (expandSet.has(key)
|
37
|
-
children.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
41
|
+
if (expandSet.has(key)) {
|
42
|
+
if (children && children.length > 0) {
|
43
|
+
children.forEach(function (child) {
|
44
|
+
treeExpandLevel.set((0, _render.getKey)(keygen, child), parentLevel + 1);
|
45
|
+
});
|
46
|
+
treeData.splice.apply(treeData, [i + 1, 0].concat(_toConsumableArray(children)));
|
47
|
+
expandSet.delete(key);
|
48
|
+
} else {
|
49
|
+
unmatchExpandKeys.push(key);
|
50
|
+
}
|
42
51
|
}
|
43
52
|
};
|
44
|
-
for (var i = 0; i <
|
53
|
+
for (var i = 0; i < treeData.length; i++) {
|
45
54
|
if (_loop()) break;
|
46
55
|
}
|
47
|
-
return
|
56
|
+
return {
|
57
|
+
treeData: treeData,
|
58
|
+
treeExpandLevel: treeExpandLevel,
|
59
|
+
unmatchExpandKeys: unmatchExpandKeys
|
60
|
+
};
|
48
61
|
};
|
49
62
|
var useTableTree = exports.useTableTree = function useTableTree(props) {
|
50
|
-
var _props$data$filter;
|
51
63
|
var _useState = (0, _react.useState)(props.defaultTreeExpandKeys || []),
|
52
64
|
_useState2 = _slicedToArray(_useState, 2),
|
53
65
|
expandKeysState = _useState2[0],
|
@@ -88,13 +100,27 @@ var useTableTree = exports.useTableTree = function useTableTree(props) {
|
|
88
100
|
var _useMemo = (0, _react.useMemo)(function () {
|
89
101
|
return getExpandData(props.data, expandKeys, props.keygen, props.treeColumnsName);
|
90
102
|
}, [props.data, expandKeys, props.treeColumnsName]),
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
var isEmptyTree = (
|
95
|
-
var
|
96
|
-
return (
|
97
|
-
|
103
|
+
treeData = _useMemo.treeData,
|
104
|
+
treeExpandLevel = _useMemo.treeExpandLevel,
|
105
|
+
unmatchExpandKeys = _useMemo.unmatchExpandKeys;
|
106
|
+
var isEmptyTree = (0, _react.useMemo)(function () {
|
107
|
+
var _props$data$filter;
|
108
|
+
return ((_props$data$filter = props.data.filter(function (item) {
|
109
|
+
var _item;
|
110
|
+
return (_item = item[props.treeColumnsName]) === null || _item === void 0 ? void 0 : _item.length;
|
111
|
+
})) === null || _props$data$filter === void 0 ? void 0 : _props$data$filter.length) === 0;
|
112
|
+
}, [props.data, props.treeColumnsName]);
|
113
|
+
(0, _react.useEffect)(function () {
|
114
|
+
if (!unmatchExpandKeys.length || !expandKeysState.length) {
|
115
|
+
return;
|
116
|
+
}
|
117
|
+
|
118
|
+
// 检查treeData中的每一项,对比expandKeysState,如果expandKeysState有但是children是空的,则需要修正expandKeysState
|
119
|
+
var newExpandKeys = expandKeysState.filter(function (key) {
|
120
|
+
return !unmatchExpandKeys.includes(key);
|
121
|
+
});
|
122
|
+
setExpandKeysState(newExpandKeys);
|
123
|
+
}, [unmatchExpandKeys, expandKeysState]);
|
98
124
|
return {
|
99
125
|
data: treeData,
|
100
126
|
treeExpandLevel: treeExpandLevel,
|
@@ -101,13 +101,13 @@ export interface BaseImageProps {
|
|
101
101
|
/**
|
102
102
|
* @en The width of the image
|
103
103
|
* @cn 图片宽度
|
104
|
-
* @default
|
104
|
+
* @default 100%
|
105
105
|
*/
|
106
106
|
width?: number | string;
|
107
107
|
/**
|
108
108
|
* @en The height of the image
|
109
109
|
* @cn 图片高度
|
110
|
-
* @default
|
110
|
+
* @default 100%
|
111
111
|
*/
|
112
112
|
height?: number | string;
|
113
113
|
/**
|
@@ -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;AAerE,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;;;;;;;;;;;yBA+CX,MAAM,UAAU,MAAM;;;;;;;;
|
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;AAerE,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;;;;;;;;;;;yBA+CX,MAAM,UAAU,MAAM;;;;;;;;CA+O5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
@@ -338,7 +338,16 @@ var useTableLayout = function useTableLayout(props) {
|
|
338
338
|
checkScroll();
|
339
339
|
checkFloat();
|
340
340
|
}, [colgroup]);
|
341
|
-
var tableWidth =
|
341
|
+
var tableWidth = props.width;
|
342
|
+
if (typeof props.width === 'string' && props.width.endsWith('%')) {
|
343
|
+
tableWidth = props.width;
|
344
|
+
} else if (typeof props.width === 'number') {
|
345
|
+
tableWidth = props.width + deltaXSum;
|
346
|
+
} else if (!isNaN(Number(props.width))) {
|
347
|
+
tableWidth = props.width;
|
348
|
+
} else {
|
349
|
+
tableWidth = undefined;
|
350
|
+
}
|
342
351
|
return {
|
343
352
|
isScrollX: !!isScrollX,
|
344
353
|
isScrollY: !!isScrollY,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-table-tree.d.ts","sourceRoot":"","sources":["use-table-tree.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;
|
1
|
+
{"version":3,"file":"use-table-tree.d.ts","sourceRoot":"","sources":["use-table-tree.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AA8CvD,MAAM,WAAW,iBACf,SAAQ,IAAI,CACV,kBAAkB,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EACvC,cAAc,GAAG,gBAAgB,GAAG,uBAAuB,GAAG,QAAQ,CACvE;IACD,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,IAAI,EAAE,GAAG,EAAE,CAAC;CACb;AAED,eAAO,MAAM,YAAY,UAAW,iBAAiB;;;;;;+BA6BR,GAAG,SAAS,MAAM;iCAjBhB,GAAG,SAAS,MAAM;;CAuDhE,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
@@ -13,35 +13,47 @@ import { usePersistFn } from "../../common/use-persist-fn";
|
|
13
13
|
import { getKey } from "../../utils/render";
|
14
14
|
import { isObject } from "../../utils/is";
|
15
15
|
import { useLatestObj } from "../../common/use-latest-obj";
|
16
|
-
var getExpandData = function getExpandData(
|
16
|
+
var getExpandData = function getExpandData(_treeData, keys, keygen, treeColumnsName) {
|
17
17
|
var expandKeys = keys;
|
18
18
|
var expandSet = new Set(expandKeys);
|
19
|
-
var
|
19
|
+
var unmatchExpandKeys = [];
|
20
|
+
var treeExpandLevel = new Map();
|
20
21
|
if (expandSet.size === 0 || !treeColumnsName) {
|
21
|
-
return
|
22
|
+
return {
|
23
|
+
treeData: _treeData,
|
24
|
+
treeExpandLevel: treeExpandLevel,
|
25
|
+
unmatchExpandKeys: unmatchExpandKeys
|
26
|
+
};
|
22
27
|
}
|
23
|
-
var
|
28
|
+
var treeData = _toConsumableArray(_treeData || []);
|
24
29
|
var _loop = function _loop() {
|
25
30
|
if (expandSet.size === 0) return 1; // break
|
26
|
-
var item =
|
31
|
+
var item = treeData[i];
|
27
32
|
var key = getKey(keygen, item, i);
|
28
|
-
var parentLevel =
|
33
|
+
var parentLevel = treeExpandLevel.get(key) || 0;
|
29
34
|
var children = isObject(item) && item[treeColumnsName];
|
30
|
-
if (expandSet.has(key)
|
31
|
-
children.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
if (expandSet.has(key)) {
|
36
|
+
if (children && children.length > 0) {
|
37
|
+
children.forEach(function (child) {
|
38
|
+
treeExpandLevel.set(getKey(keygen, child), parentLevel + 1);
|
39
|
+
});
|
40
|
+
treeData.splice.apply(treeData, [i + 1, 0].concat(_toConsumableArray(children)));
|
41
|
+
expandSet.delete(key);
|
42
|
+
} else {
|
43
|
+
unmatchExpandKeys.push(key);
|
44
|
+
}
|
36
45
|
}
|
37
46
|
};
|
38
|
-
for (var i = 0; i <
|
47
|
+
for (var i = 0; i < treeData.length; i++) {
|
39
48
|
if (_loop()) break;
|
40
49
|
}
|
41
|
-
return
|
50
|
+
return {
|
51
|
+
treeData: treeData,
|
52
|
+
treeExpandLevel: treeExpandLevel,
|
53
|
+
unmatchExpandKeys: unmatchExpandKeys
|
54
|
+
};
|
42
55
|
};
|
43
56
|
export var useTableTree = function useTableTree(props) {
|
44
|
-
var _props$data$filter;
|
45
57
|
var _useState = useState(props.defaultTreeExpandKeys || []),
|
46
58
|
_useState2 = _slicedToArray(_useState, 2),
|
47
59
|
expandKeysState = _useState2[0],
|
@@ -82,13 +94,27 @@ export var useTableTree = function useTableTree(props) {
|
|
82
94
|
var _useMemo = useMemo(function () {
|
83
95
|
return getExpandData(props.data, expandKeys, props.keygen, props.treeColumnsName);
|
84
96
|
}, [props.data, expandKeys, props.treeColumnsName]),
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
var isEmptyTree = (
|
89
|
-
var
|
90
|
-
return (
|
91
|
-
|
97
|
+
treeData = _useMemo.treeData,
|
98
|
+
treeExpandLevel = _useMemo.treeExpandLevel,
|
99
|
+
unmatchExpandKeys = _useMemo.unmatchExpandKeys;
|
100
|
+
var isEmptyTree = useMemo(function () {
|
101
|
+
var _props$data$filter;
|
102
|
+
return ((_props$data$filter = props.data.filter(function (item) {
|
103
|
+
var _item;
|
104
|
+
return (_item = item[props.treeColumnsName]) === null || _item === void 0 ? void 0 : _item.length;
|
105
|
+
})) === null || _props$data$filter === void 0 ? void 0 : _props$data$filter.length) === 0;
|
106
|
+
}, [props.data, props.treeColumnsName]);
|
107
|
+
useEffect(function () {
|
108
|
+
if (!unmatchExpandKeys.length || !expandKeysState.length) {
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
|
112
|
+
// 检查treeData中的每一项,对比expandKeysState,如果expandKeysState有但是children是空的,则需要修正expandKeysState
|
113
|
+
var newExpandKeys = expandKeysState.filter(function (key) {
|
114
|
+
return !unmatchExpandKeys.includes(key);
|
115
|
+
});
|
116
|
+
setExpandKeysState(newExpandKeys);
|
117
|
+
}, [unmatchExpandKeys, expandKeysState]);
|
92
118
|
return {
|
93
119
|
data: treeData,
|
94
120
|
treeExpandLevel: treeExpandLevel,
|