@sheinx/hooks 3.5.0-beta.9 → 3.5.0-fix.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.
- package/cjs/common/use-input-able/use-Input-able.d.ts.map +1 -1
- package/cjs/common/use-input-able/use-Input-able.js +6 -7
- package/cjs/components/use-image/use-image.type.d.ts +2 -2
- 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/common/use-input-able/use-Input-able.d.ts.map +1 -1
- package/esm/common/use-input-able/use-Input-able.js +7 -8
- package/esm/components/use-image/use-image.type.d.ts +2 -2
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-Input-able.d.ts","sourceRoot":"","sources":["use-Input-able.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"use-Input-able.d.ts","sourceRoot":"","sources":["use-Input-able.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;;;;EAuE3F"}
|
|
@@ -45,19 +45,18 @@ function useInputAble(props) {
|
|
|
45
45
|
var render = (0, _useRender.useRender)(syncValue);
|
|
46
46
|
var shouldUseState = delay || !control;
|
|
47
47
|
var value = shouldUseState ? stateValue : valuePo;
|
|
48
|
-
(0, _react.
|
|
49
|
-
if (context.timer) {
|
|
50
|
-
clearTimeout(context.timer);
|
|
51
|
-
context.timer = null;
|
|
52
|
-
}
|
|
48
|
+
(0, _react.useLayoutEffect)(function () {
|
|
53
49
|
if (delay && control && props.value !== stateValue) {
|
|
54
50
|
changeStateValue(props.value);
|
|
51
|
+
} else if (context.timer) {
|
|
52
|
+
clearTimeout(context.timer);
|
|
53
|
+
context.timer = null;
|
|
55
54
|
}
|
|
56
55
|
}, [props.value, delay, control]);
|
|
57
56
|
var forceDelayChange = (0, _usePersistFn.default)(function () {
|
|
58
|
-
if (context.
|
|
57
|
+
if (context.delayChange) context.delayChange();
|
|
58
|
+
if (context.timer) {
|
|
59
59
|
clearTimeout(context.timer);
|
|
60
|
-
context.delayChange();
|
|
61
60
|
context.timer = null;
|
|
62
61
|
context.delayChange = null;
|
|
63
62
|
}
|
|
@@ -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-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,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-Input-able.d.ts","sourceRoot":"","sources":["use-Input-able.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"use-Input-able.d.ts","sourceRoot":"","sources":["use-Input-able.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;;;;EAuE3F"}
|
|
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
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; }
|
|
5
5
|
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; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import {
|
|
7
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
8
8
|
import { isFunc } from "../../utils/is";
|
|
9
9
|
import { shallowEqual } from "../../utils/shallow-equal";
|
|
10
10
|
import usePersistFn from "../use-persist-fn";
|
|
@@ -38,19 +38,18 @@ export default function useInputAble(props) {
|
|
|
38
38
|
var render = useRender(syncValue);
|
|
39
39
|
var shouldUseState = delay || !control;
|
|
40
40
|
var value = shouldUseState ? stateValue : valuePo;
|
|
41
|
-
|
|
42
|
-
if (context.timer) {
|
|
43
|
-
clearTimeout(context.timer);
|
|
44
|
-
context.timer = null;
|
|
45
|
-
}
|
|
41
|
+
useLayoutEffect(function () {
|
|
46
42
|
if (delay && control && props.value !== stateValue) {
|
|
47
43
|
changeStateValue(props.value);
|
|
44
|
+
} else if (context.timer) {
|
|
45
|
+
clearTimeout(context.timer);
|
|
46
|
+
context.timer = null;
|
|
48
47
|
}
|
|
49
48
|
}, [props.value, delay, control]);
|
|
50
49
|
var forceDelayChange = usePersistFn(function () {
|
|
51
|
-
if (context.
|
|
50
|
+
if (context.delayChange) context.delayChange();
|
|
51
|
+
if (context.timer) {
|
|
52
52
|
clearTimeout(context.timer);
|
|
53
|
-
context.delayChange();
|
|
54
53
|
context.timer = null;
|
|
55
54
|
context.delayChange = null;
|
|
56
55
|
}
|
|
@@ -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-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,
|