@sheinx/hooks 3.6.0-beta.1 → 3.6.0-beta.11
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-filter/use-filter.d.ts.map +1 -1
- package/cjs/common/use-position-style/check-border.d.ts +6 -0
- package/cjs/common/use-position-style/check-border.d.ts.map +1 -0
- package/cjs/common/use-position-style/check-border.js +35 -0
- package/cjs/common/use-position-style/get-position-style.d.ts +1 -0
- package/cjs/common/use-position-style/get-position-style.d.ts.map +1 -1
- package/cjs/common/use-position-style/get-position-style.js +14 -8
- package/cjs/common/use-position-style/index.d.ts +1 -0
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +15 -8
- package/cjs/components/use-cascader/use-cascader.d.ts.map +1 -1
- package/cjs/components/use-cascader/use-cascader.type.d.ts +2 -1
- package/cjs/components/use-cascader/use-cascader.type.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-control/use-form-control.js +3 -2
- package/cjs/components/use-form/use-form-fieldset/fieldset-context.d.ts +1 -1
- package/cjs/components/use-form/use-form-fieldset/fieldset-context.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-fieldset/fieldset-context.js +3 -2
- package/cjs/components/use-form/use-form-fieldset/index.d.ts +1 -0
- package/cjs/components/use-form/use-form-fieldset/index.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-fieldset/index.js +6 -0
- package/cjs/components/use-form/use-form.d.ts +2 -2
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +62 -13
- package/cjs/components/use-form/use-form.type.d.ts +5 -3
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-format.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-format.js +12 -4
- package/cjs/components/use-table/use-table-sort.d.ts +5 -0
- package/cjs/components/use-table/use-table-sort.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-sort.js +5 -1
- package/cjs/components/use-table/use-table-tree.d.ts +13 -0
- package/cjs/components/use-table/use-table-tree.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-tree.js +68 -1
- package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.js +6 -4
- package/cjs/components/use-tree/index.d.ts +3 -2
- package/cjs/components/use-tree/index.d.ts.map +1 -1
- package/cjs/components/use-tree/index.js +18 -2
- package/cjs/components/use-tree/use-tree-node.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree-node.js +1 -5
- package/cjs/components/use-tree/use-tree-node.type.d.ts +18 -0
- package/cjs/components/use-tree/use-tree-node.type.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree-virtual-node.d.ts +13 -0
- package/cjs/components/use-tree/use-tree-virtual-node.d.ts.map +1 -0
- package/cjs/components/use-tree/use-tree-virtual-node.js +92 -0
- package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree.js +191 -6
- package/cjs/components/use-tree/use-tree.type.d.ts +31 -1
- package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
- package/cjs/components/use-treeselect/use-tiled.d.ts +1 -1
- package/cjs/components/use-treeselect/use-tiled.d.ts.map +1 -1
- package/cjs/components/use-treeselect/use-tiled.js +12 -18
- package/cjs/components/use-treeselect/use-tiled.type.d.ts +2 -0
- package/cjs/components/use-treeselect/use-tiled.type.d.ts.map +1 -1
- package/cjs/utils/is.d.ts +2 -0
- package/cjs/utils/is.d.ts.map +1 -1
- package/cjs/utils/is.js +5 -2
- package/cjs/utils/object.d.ts +12 -0
- package/cjs/utils/object.d.ts.map +1 -1
- package/cjs/utils/object.js +34 -1
- package/cjs/utils/tree.d.ts +1 -1
- package/cjs/utils/tree.d.ts.map +1 -1
- package/cjs/utils/tree.js +3 -9
- package/cjs/utils/warning.js +5 -5
- package/esm/common/use-filter/use-filter.d.ts.map +1 -1
- package/esm/common/use-position-style/check-border.d.ts +6 -0
- package/esm/common/use-position-style/check-border.d.ts.map +1 -0
- package/esm/common/use-position-style/check-border.js +29 -0
- package/esm/common/use-position-style/get-position-style.d.ts +1 -0
- package/esm/common/use-position-style/get-position-style.d.ts.map +1 -1
- package/esm/common/use-position-style/get-position-style.js +14 -8
- package/esm/common/use-position-style/index.d.ts +1 -0
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +15 -8
- package/esm/components/use-cascader/use-cascader.d.ts.map +1 -1
- package/esm/components/use-cascader/use-cascader.type.d.ts +2 -1
- package/esm/components/use-cascader/use-cascader.type.d.ts.map +1 -1
- package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/esm/components/use-form/use-form-control/use-form-control.js +3 -2
- package/esm/components/use-form/use-form-fieldset/fieldset-context.d.ts +1 -1
- package/esm/components/use-form/use-form-fieldset/fieldset-context.d.ts.map +1 -1
- package/esm/components/use-form/use-form-fieldset/fieldset-context.js +2 -1
- package/esm/components/use-form/use-form-fieldset/index.d.ts +1 -0
- package/esm/components/use-form/use-form-fieldset/index.d.ts.map +1 -1
- package/esm/components/use-form/use-form-fieldset/index.js +2 -1
- package/esm/components/use-form/use-form.d.ts +2 -2
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +63 -14
- package/esm/components/use-form/use-form.type.d.ts +5 -3
- package/esm/components/use-form/use-form.type.d.ts.map +1 -1
- package/esm/components/use-input/use-input-format.d.ts.map +1 -1
- package/esm/components/use-input/use-input-format.js +12 -4
- package/esm/components/use-table/use-table-sort.d.ts +5 -0
- package/esm/components/use-table/use-table-sort.d.ts.map +1 -1
- package/esm/components/use-table/use-table-sort.js +5 -1
- package/esm/components/use-table/use-table-tree.d.ts +13 -0
- package/esm/components/use-table/use-table-tree.d.ts.map +1 -1
- package/esm/components/use-table/use-table-tree.js +67 -0
- package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.js +6 -4
- package/esm/components/use-tree/index.d.ts +3 -2
- package/esm/components/use-tree/index.d.ts.map +1 -1
- package/esm/components/use-tree/index.js +3 -2
- package/esm/components/use-tree/use-tree-node.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree-node.js +1 -5
- package/esm/components/use-tree/use-tree-node.type.d.ts +18 -0
- package/esm/components/use-tree/use-tree-node.type.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree-virtual-node.d.ts +13 -0
- package/esm/components/use-tree/use-tree-virtual-node.d.ts.map +1 -0
- package/esm/components/use-tree/use-tree-virtual-node.js +85 -0
- package/esm/components/use-tree/use-tree.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree.js +193 -8
- package/esm/components/use-tree/use-tree.type.d.ts +31 -1
- package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
- package/esm/components/use-treeselect/use-tiled.d.ts +1 -1
- package/esm/components/use-treeselect/use-tiled.d.ts.map +1 -1
- package/esm/components/use-treeselect/use-tiled.js +10 -16
- package/esm/components/use-treeselect/use-tiled.type.d.ts +2 -0
- package/esm/components/use-treeselect/use-tiled.type.d.ts.map +1 -1
- package/esm/utils/is.d.ts +2 -0
- package/esm/utils/is.d.ts.map +1 -1
- package/esm/utils/is.js +4 -1
- package/esm/utils/object.d.ts +12 -0
- package/esm/utils/object.d.ts.map +1 -1
- package/esm/utils/object.js +34 -1
- package/esm/utils/tree.d.ts +1 -1
- package/esm/utils/tree.d.ts.map +1 -1
- package/esm/utils/tree.js +3 -9
- package/esm/utils/warning.js +5 -5
- package/package.json +1 -1
package/cjs/utils/tree.d.ts
CHANGED
@@ -9,6 +9,6 @@ type FilterDatum<DataItem> = {
|
|
9
9
|
getKey: (node: DataItem) => KeygenResult;
|
10
10
|
getDataById: (id: KeygenResult) => DataItem;
|
11
11
|
};
|
12
|
-
export declare const mergeFilteredTree: (
|
12
|
+
export declare const mergeFilteredTree: (filterData: any, rawDatum: FilterDatum<any>, tiledId: KeygenResult[]) => any;
|
13
13
|
export {};
|
14
14
|
//# sourceMappingURL=tree.d.ts.map
|
package/cjs/utils/tree.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,eAAO,MAAM,cAAc,+CAGlB,OAAO,UAkBf,CAAC;AAEF,eAAO,MAAM,aAAa,2CAA4C,YAAY,6EAE5B,OAAO,iCACzC,YAAY,EAAE,GAAG,SAAS,2EAGxB,OAAO,wCACU,IAAI;;yBA4B1C,CAAC;AAEF,KAAK,WAAW,CAAC,QAAQ,IAAI;IAC3B,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,WAAW,EAAE,GAAG,CAAC;IACjB,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,YAAY,CAAC;IACzC,WAAW,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,QAAQ,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,
|
1
|
+
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["tree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,eAAO,MAAM,cAAc,+CAGlB,OAAO,UAkBf,CAAC;AAEF,eAAO,MAAM,aAAa,2CAA4C,YAAY,6EAE5B,OAAO,iCACzC,YAAY,EAAE,GAAG,SAAS,2EAGxB,OAAO,wCACU,IAAI;;yBA4B1C,CAAC;AAEF,KAAK,WAAW,CAAC,QAAQ,IAAI;IAC3B,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,WAAW,EAAE,GAAG,CAAC;IACjB,MAAM,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,YAAY,CAAC;IACzC,WAAW,EAAE,CAAC,EAAE,EAAE,YAAY,KAAK,QAAQ,CAAC;CAC7C,CAAC;AAEF,eAAO,MAAM,iBAAiB,eAChB,GAAG,YACL,YAAY,GAAG,CAAC,WACjB,YAAY,EAAE,QAexB,CAAC"}
|
package/cjs/utils/tree.js
CHANGED
@@ -68,19 +68,13 @@ var getFilterTree = exports.getFilterTree = function getFilterTree(treeNodes, fi
|
|
68
68
|
return node;
|
69
69
|
});
|
70
70
|
};
|
71
|
-
var mergeFilteredTree = exports.mergeFilteredTree = function mergeFilteredTree(
|
72
|
-
var
|
73
|
-
var childrenKey = filterDatum.childrenKey;
|
71
|
+
var mergeFilteredTree = exports.mergeFilteredTree = function mergeFilteredTree(filterData, rawDatum, tiledId) {
|
72
|
+
var childrenKey = rawDatum.childrenKey;
|
74
73
|
if (tiledId.length === 0) return filterData;
|
75
74
|
var recursion = function recursion(node) {
|
76
|
-
var nodeKey =
|
75
|
+
var nodeKey = rawDatum.getKey(node);
|
77
76
|
if (tiledId.indexOf(nodeKey) >= 0) {
|
78
77
|
node[childrenKey] = (0, _clone.deepClone)(rawDatum.getDataById(nodeKey)[childrenKey] || []);
|
79
|
-
} else {
|
80
|
-
var item = filterDatum.getDataById(nodeKey);
|
81
|
-
if (item && item[childrenKey]) {
|
82
|
-
node[childrenKey] = (0, _clone.deepClone)(item[childrenKey] || []);
|
83
|
-
}
|
84
78
|
}
|
85
79
|
var children = node[childrenKey] || [];
|
86
80
|
children.map(recursion);
|
package/cjs/utils/warning.js
CHANGED
@@ -15,29 +15,29 @@ var shouldShowMessage = function shouldShowMessage(message) {
|
|
15
15
|
var deprecated = function deprecated(prop, newProp, component, extraMessage) {
|
16
16
|
if (process.env.NODE_ENV !== 'production') {
|
17
17
|
var msg = "[shineout] '".concat(prop, "' in ").concat(component, " component is deprecated, please use '").concat(newProp, "' instead. ").concat(extraMessage);
|
18
|
-
shouldShowMessage(msg)
|
18
|
+
if (shouldShowMessage(msg)) console.error(msg);
|
19
19
|
}
|
20
20
|
};
|
21
21
|
var breakingChange = function breakingChange(message) {
|
22
22
|
if (process.env.NODE_ENV !== 'production') {
|
23
23
|
var msg = "[shineout] ".concat(message);
|
24
|
-
shouldShowMessage(msg)
|
24
|
+
if (shouldShowMessage(msg)) console.error(msg);
|
25
25
|
}
|
26
26
|
};
|
27
27
|
var devWarn = function devWarn(message) {
|
28
28
|
if (process.env.NODE_ENV !== 'production') {
|
29
|
-
shouldShowMessage(message)
|
29
|
+
if (shouldShowMessage(message)) console.warn("[shineout] ".concat(message));
|
30
30
|
}
|
31
31
|
};
|
32
32
|
var conflictWarning = function conflictWarning(component, prop1, prop2) {
|
33
33
|
if (process.env.NODE_ENV !== 'production') {
|
34
34
|
var msg = "[shineout] ".concat(prop1, " and ").concat(prop2, " cannot be used at the same time in ").concat(component, ".");
|
35
|
-
shouldShowMessage(msg)
|
35
|
+
if (shouldShowMessage(msg)) console.warn(msg);
|
36
36
|
}
|
37
37
|
};
|
38
38
|
var error = function error(message) {
|
39
39
|
var msg = new Error("[shineout] ".concat(message));
|
40
|
-
shouldShowMessage(msg.message)
|
40
|
+
if (shouldShowMessage(msg.message)) console.error(msg);
|
41
41
|
};
|
42
42
|
var devUseWarning = exports.devUseWarning = {
|
43
43
|
error: error,
|
@@ -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;;;;;;;;;;kCAmBkD,OAAO;sBAiB1C,MAAM;sBAKN,MAAM,SAAQ,MAAM;;
|
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;;CAqGjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
interface UseCheckElementBorderWidthOptions {
|
2
|
+
direction?: 'horizontal' | 'vertical';
|
3
|
+
}
|
4
|
+
export declare const useCheckElementBorderWidth: (elementRef: React.RefObject<HTMLElement>, options?: UseCheckElementBorderWidthOptions) => number;
|
5
|
+
export {};
|
6
|
+
//# sourceMappingURL=check-border.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"check-border.d.ts","sourceRoot":"","sources":["check-border.ts"],"names":[],"mappings":"AAEA,UAAU,iCAAiC;IAGzC,SAAS,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;CACvC;AAGD,eAAO,MAAM,0BAA0B,eACzB,MAAM,SAAS,CAAC,WAAW,CAAC,YAC/B,iCAAiC,KACzC,MAqBF,CAAC"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
2
|
+
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."); }
|
3
|
+
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); }
|
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
|
+
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
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
7
|
+
import { useCallback, useEffect, useState } from 'react';
|
8
|
+
export var useCheckElementBorderWidth = function useCheckElementBorderWidth(elementRef) {
|
9
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
10
|
+
var _useState = useState(0),
|
11
|
+
_useState2 = _slicedToArray(_useState, 2),
|
12
|
+
borderWidth = _useState2[0],
|
13
|
+
setBorderWidth = _useState2[1];
|
14
|
+
|
15
|
+
// 获取指定方向上的border宽度之和
|
16
|
+
var getBorderWidth = useCallback(function () {
|
17
|
+
if (elementRef.current) {
|
18
|
+
var _options$direction = options.direction,
|
19
|
+
direction = _options$direction === void 0 ? 'horizontal' : _options$direction;
|
20
|
+
var style = window.getComputedStyle(elementRef.current);
|
21
|
+
var _borderWidth = direction === 'horizontal' ? parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth) : parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
|
22
|
+
setBorderWidth(_borderWidth);
|
23
|
+
}
|
24
|
+
}, [elementRef]);
|
25
|
+
useEffect(function () {
|
26
|
+
getBorderWidth();
|
27
|
+
}, [getBorderWidth]);
|
28
|
+
return borderWidth;
|
29
|
+
};
|
@@ -3,5 +3,6 @@ export declare const getPositionStyle: (position: string, config?: {
|
|
3
3
|
popupGap?: number | undefined;
|
4
4
|
zIndex?: number | undefined;
|
5
5
|
fixedWidth?: boolean | "min" | undefined;
|
6
|
+
parentBorderWidth?: number | undefined;
|
6
7
|
} | undefined) => React.CSSProperties;
|
7
8
|
//# sourceMappingURL=get-position-style.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-position-style.d.ts","sourceRoot":"","sources":["get-position-style.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"get-position-style.d.ts","sourceRoot":"","sources":["get-position-style.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAU1B,eAAO,MAAM,gBAAgB,aACjB,MAAM;;;;;qCA+CjB,CAAC"}
|
@@ -22,6 +22,9 @@ export var getPositionStyle = function getPositionStyle(position, config) {
|
|
22
22
|
if (config !== null && config !== void 0 && config.fixedWidth) {
|
23
23
|
var key = config.fixedWidth === 'min' ? 'minWidth' : 'width';
|
24
24
|
newStyle[key] = '100%';
|
25
|
+
if (config.parentBorderWidth) {
|
26
|
+
newStyle[key] = "calc(100% + ".concat(config.parentBorderWidth, "px)");
|
27
|
+
}
|
25
28
|
}
|
26
29
|
if (position === 'drop-down') {
|
27
30
|
newStyle.top = mainMargin;
|
@@ -33,19 +36,22 @@ export var getPositionStyle = function getPositionStyle(position, config) {
|
|
33
36
|
var positionArr = (position || '').split('-');
|
34
37
|
if (positionArr.length === 2) {
|
35
38
|
var _positionArr = _slicedToArray(positionArr, 2),
|
36
|
-
|
37
|
-
|
38
|
-
newStyle[ReverseDir[
|
39
|
-
newStyle[
|
39
|
+
vDirection = _positionArr[0],
|
40
|
+
hDirection = _positionArr[1];
|
41
|
+
newStyle[ReverseDir[vDirection]] = mainMargin;
|
42
|
+
newStyle[hDirection] = 0;
|
43
|
+
if (config !== null && config !== void 0 && config.parentBorderWidth) {
|
44
|
+
newStyle[hDirection] = -config.parentBorderWidth / 2;
|
45
|
+
}
|
40
46
|
} else {
|
41
47
|
var _positionArr2 = _slicedToArray(positionArr, 1),
|
42
|
-
|
43
|
-
newStyle[ReverseDir[
|
44
|
-
if (
|
48
|
+
_vDirection = _positionArr2[0];
|
49
|
+
newStyle[ReverseDir[_vDirection]] = mainMargin;
|
50
|
+
if (_vDirection === 'left' || _vDirection === 'right') {
|
45
51
|
newStyle.top = halfMargin;
|
46
52
|
newStyle.transform = 'translateY(-50%)';
|
47
53
|
}
|
48
|
-
if (
|
54
|
+
if (_vDirection === 'top' || _vDirection === 'bottom') {
|
49
55
|
newStyle.left = halfMargin;
|
50
56
|
newStyle.transform = 'translateX(-50%)';
|
51
57
|
}
|
@@ -15,6 +15,7 @@ export interface PositionStyleConfig {
|
|
15
15
|
fixedWidth?: boolean | 'min';
|
16
16
|
updateKey?: number | string;
|
17
17
|
adjust?: boolean;
|
18
|
+
offset?: [number, number];
|
18
19
|
}
|
19
20
|
export declare const usePositionStyle: (config: PositionStyleConfig) => {
|
20
21
|
style: React.CSSProperties;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AASnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3B;AAOD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;;;CA8S3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
@@ -8,6 +8,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
8
|
import React, { useEffect, useState } from 'react';
|
9
9
|
import { getPositionStyle } from "./get-position-style";
|
10
10
|
import { useCheckElementPosition } from "./check-position";
|
11
|
+
import { useCheckElementBorderWidth } from "./check-border";
|
11
12
|
import shallowEqual from "../../utils/shallow-equal";
|
12
13
|
import usePersistFn from "../use-persist-fn";
|
13
14
|
import { getCurrentCSSZoom } from "../../utils";
|
@@ -34,7 +35,8 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
34
35
|
popupElRef = _ref.popupElRef,
|
35
36
|
scrollElRef = _ref.scrollElRef,
|
36
37
|
updateKey = _ref.updateKey,
|
37
|
-
adjust = _ref.adjust
|
38
|
+
adjust = _ref.adjust,
|
39
|
+
offset = _ref.offset;
|
38
40
|
// 初次渲染无样式的时候, 隐藏展示
|
39
41
|
var _useState = useState(hideStyle),
|
40
42
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -65,6 +67,9 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
65
67
|
scrollContainer: scrollElRef === null || scrollElRef === void 0 ? void 0 : scrollElRef.current,
|
66
68
|
enable: show && adjust
|
67
69
|
});
|
70
|
+
var parentElBorderWidth = useCheckElementBorderWidth(parentElRef, {
|
71
|
+
direction: 'horizontal'
|
72
|
+
});
|
68
73
|
var adjustPosition = function adjustPosition(position) {
|
69
74
|
var winHeight = docSize.height;
|
70
75
|
if (!verticalPosition.includes(position)) return position;
|
@@ -149,7 +154,7 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
149
154
|
var overRight = 0;
|
150
155
|
var overLeft = 0;
|
151
156
|
if (h === 'left') {
|
152
|
-
style.left = rect.left - containerRect.left + containerScroll.left;
|
157
|
+
style.left = rect.left - containerRect.left + containerScroll.left - (offset ? offset[0] : 0);
|
153
158
|
style.transform = '';
|
154
159
|
arrayStyle.left = "8px";
|
155
160
|
if (adjust) {
|
@@ -159,7 +164,7 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
159
164
|
}
|
160
165
|
}
|
161
166
|
} else if (h === 'right') {
|
162
|
-
style.right = containerRect.right - rect.right + containerScrollBarWidth - containerScroll.left;
|
167
|
+
style.right = containerRect.right - rect.right + containerScrollBarWidth - containerScroll.left - (offset ? offset[0] : 0);
|
163
168
|
style.left = 'auto';
|
164
169
|
style.transform = '';
|
165
170
|
arrayStyle.right = "8px";
|
@@ -216,11 +221,11 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
216
221
|
_h = _targetPosition$split4[0],
|
217
222
|
_v = _targetPosition$split4[1];
|
218
223
|
if (_v === 'top') {
|
219
|
-
style.top = rect.top - containerRect.top + containerScroll.top;
|
224
|
+
style.top = rect.top - containerRect.top + containerScroll.top - (offset ? offset[1] : 0);
|
220
225
|
style.transform = '';
|
221
226
|
arrayStyle.top = "8px";
|
222
227
|
} else if (_v === 'bottom') {
|
223
|
-
style.top = rect.bottom - containerRect.top + containerScroll.top;
|
228
|
+
style.top = rect.bottom - containerRect.top + containerScroll.top + (offset ? offset[1] : 0);
|
224
229
|
arrayStyle.bottom = "8px";
|
225
230
|
style.transform = 'translateY(-100%)';
|
226
231
|
} else {
|
@@ -253,7 +258,7 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
253
258
|
style: hideStyle
|
254
259
|
};
|
255
260
|
var rect = context.parentRect;
|
256
|
-
if (scrollElRef !== null && scrollElRef !== void 0 && scrollElRef.current && (_scrollElRef$current = scrollElRef.current) !== null && _scrollElRef$current !== void 0 && _scrollElRef$current.contains(parentElRef.current)) {
|
261
|
+
if (!show && scrollElRef !== null && scrollElRef !== void 0 && scrollElRef.current && (_scrollElRef$current = scrollElRef.current) !== null && _scrollElRef$current !== void 0 && _scrollElRef$current.contains(parentElRef.current)) {
|
257
262
|
var _scrollElRef$current2;
|
258
263
|
var visibleRect = ((_scrollElRef$current2 = scrollElRef.current) === null || _scrollElRef$current2 === void 0 ? void 0 : _scrollElRef$current2.getBoundingClientRect()) || {};
|
259
264
|
if (rect.bottom < visibleRect.top || rect.top > visibleRect.bottom || rect.right < visibleRect.left || rect.left > visibleRect.right) {
|
@@ -295,17 +300,19 @@ export var usePositionStyle = function usePositionStyle(config) {
|
|
295
300
|
newStyle: style
|
296
301
|
};
|
297
302
|
context.parentRect = parentElRef.current.getBoundingClientRect();
|
303
|
+
var realPosition = position;
|
298
304
|
if (adjust) {
|
299
305
|
var popupInfo = getPopUpInfo(context.parentRect);
|
300
306
|
context.popUpHeight = popupInfo.height;
|
301
307
|
context.popUpWidth = popupInfo.width;
|
308
|
+
realPosition = adjustPosition(position);
|
302
309
|
}
|
303
|
-
var realPosition = adjust ? adjustPosition(position) : position;
|
304
310
|
if (!absolute) {
|
305
311
|
newStyle = getPositionStyle(realPosition, {
|
306
312
|
popupGap: popupGap,
|
307
313
|
zIndex: zIndex,
|
308
|
-
fixedWidth: fixedWidth
|
314
|
+
fixedWidth: fixedWidth,
|
315
|
+
parentBorderWidth: parentElBorderWidth
|
309
316
|
});
|
310
317
|
} else {
|
311
318
|
var _ref3 = getAbsoluteStyle(realPosition),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-cascader.d.ts","sourceRoot":"","sources":["use-cascader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,QAAA,MAAM,WAAW;;;;
|
1
|
+
{"version":3,"file":"use-cascader.d.ts","sourceRoot":"","sources":["use-cascader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,QAAA,MAAM,WAAW;;;;CA2ChB,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { KeygenResult, TreeKeygenType, ObjectKey } from '../../common/type';
|
2
|
+
import { DisabledOption } from '../use-tree';
|
2
3
|
import { TreeModeType } from '../use-tree/use-tree.type';
|
3
4
|
export interface BaseCascaderProps<DataItem, Value extends KeygenResult[]> {
|
4
5
|
value?: Value;
|
@@ -11,7 +12,7 @@ export interface BaseCascaderProps<DataItem, Value extends KeygenResult[]> {
|
|
11
12
|
beforeChange?: (value: Value) => any;
|
12
13
|
mode?: TreeModeType;
|
13
14
|
keygen: TreeKeygenType<DataItem>;
|
14
|
-
disabled?: ((
|
15
|
+
disabled?: DisabledOption<DataItem> | boolean | ((item: DataItem) => boolean);
|
15
16
|
filterSameChange?: boolean;
|
16
17
|
}
|
17
18
|
//# sourceMappingURL=use-cascader.type.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-cascader.type.d.ts","sourceRoot":"","sources":["use-cascader.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,WAAW,iBAAiB,CAAC,QAAQ,EAAE,KAAK,SAAS,YAAY,EAAE;IACvE,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC;IACvD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,GAAG,CAAC;IACrC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,
|
1
|
+
{"version":3,"file":"use-cascader.type.d.ts","sourceRoot":"","sources":["use-cascader.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,WAAW,iBAAiB,CAAC,QAAQ,EAAE,KAAK,SAAS,YAAY,EAAE;IACvE,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC;IACvD,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,GAAG,CAAC;IACrC,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,cAAc,CAAC,QAAQ,CAAC,GAAG,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC;IAC9E,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AA0B/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;
|
1
|
+
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AA0B/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBAkJpC,CAAC,YAAY,GAAG,EAAE;;;;;EAkDrD"}
|
@@ -88,6 +88,7 @@ export default function useFormControl(props) {
|
|
88
88
|
var formValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
89
89
|
var errors = arguments.length > 1 ? arguments[1] : undefined;
|
90
90
|
var severErrors = arguments.length > 2 ? arguments[2] : undefined;
|
91
|
+
var names = arguments.length > 3 ? arguments[3] : undefined;
|
91
92
|
if (!name) return;
|
92
93
|
if (isArray(name)) {
|
93
94
|
var _value = getValue(name, formValue);
|
@@ -99,7 +100,7 @@ export default function useFormControl(props) {
|
|
99
100
|
var dv = isArray(defaultValue) ? defaultValue : [];
|
100
101
|
var nextValue = [];
|
101
102
|
name.forEach(function (n, index) {
|
102
|
-
if (_value[index] === undefined && dv[index] !== undefined) {
|
103
|
+
if (!names.has(n) && _value[index] === undefined && dv[index] !== undefined) {
|
103
104
|
nextValue[index] = dv[index];
|
104
105
|
} else {
|
105
106
|
nextValue[index] = _value[index];
|
@@ -113,7 +114,7 @@ export default function useFormControl(props) {
|
|
113
114
|
setErrorState(_error2);
|
114
115
|
}
|
115
116
|
if (!shallowEqual(_value2, latestInfo.valueState)) {
|
116
|
-
if (_value2 === undefined && defaultValue !== undefined) {
|
117
|
+
if (!names.has(name) && _value2 === undefined && defaultValue !== undefined) {
|
117
118
|
setValueState(defaultValue);
|
118
119
|
} else {
|
119
120
|
setValueState(_value2);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fieldset-context.d.ts","sourceRoot":"","sources":["fieldset-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,
|
1
|
+
{"version":3,"file":"fieldset-context.d.ts","sourceRoot":"","sources":["fieldset-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,eAAO,MAAM,eAAe;;;EAA0D,CAAC;AAGvF,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB;AAiBD,eAAO,MAAM,mBAAmB;;;;CAe/B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -7,10 +7,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
7
7
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
8
8
|
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
9
|
import React, { createContext } from 'react';
|
10
|
-
var FieldsetContext = /*#__PURE__*/createContext({
|
10
|
+
export var FieldsetContext = /*#__PURE__*/createContext({
|
11
11
|
path: '',
|
12
12
|
validateFieldSet: function validateFieldSet() {}
|
13
13
|
});
|
14
|
+
FieldsetContext.displayName = 'FieldsetContext';
|
14
15
|
function extendName() {
|
15
16
|
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
16
17
|
var name = arguments.length > 1 ? arguments[1] : undefined;
|
@@ -1,4 +1,5 @@
|
|
1
1
|
export { default as useFormFieldSet, default } from './use-form-fieldset';
|
2
2
|
export { useFieldSetConsumer } from './fieldset-context';
|
3
|
+
export { FieldsetContext } from './fieldset-context';
|
3
4
|
export type { BaseFormFieldSetProps } from './use-form-fieldset.type';
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD,YAAY,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC"}
|
@@ -21,7 +21,7 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
21
21
|
getErrors: () => ObjectType<Error | undefined>;
|
22
22
|
clearValidate: (names?: string[]) => void;
|
23
23
|
validateFields: (fields?: string | string[], config?: ValidateFnConfig) => Promise<T>;
|
24
|
-
validateFieldset: (name: string) => void;
|
24
|
+
validateFieldset: (name: string, config?: ValidateFnConfig) => void;
|
25
25
|
insertError: (name: string, index: number, error?: Error) => void;
|
26
26
|
spliceError: (name: string, index: number) => void;
|
27
27
|
scrollToField: (name: string, scrollIntoViewOptions?: ScrollIntoViewOptions) => void;
|
@@ -41,7 +41,7 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
41
41
|
getErrors: () => ObjectType<Error | undefined>;
|
42
42
|
clearValidate: (names?: string[]) => void;
|
43
43
|
validateFields: (fields?: string | string[], config?: ValidateFnConfig) => Promise<T>;
|
44
|
-
validateFieldset: (name: string) => void;
|
44
|
+
validateFieldset: (name: string, config?: ValidateFnConfig) => void;
|
45
45
|
insertError: (name: string, index: number, error?: Error) => void;
|
46
46
|
spliceError: (name: string, index: number) => void;
|
47
47
|
scrollToField: (name: string, scrollIntoViewOptions?: ScrollIntoViewOptions) => void;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AA+BA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBA2RC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;aAAE;8BA9Jd,MAAM;oCAiOD,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA5LxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCA8PvB,MAAM,WAAW,gBAAgB;gCA/CzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAnIpD,MAAM,0BAAyB,qBAAqB;;;;;;oBAqEjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE;0BA9Jd,MAAM;gCAiOD,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA5LxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCA8PvB,MAAM,WAAW,gBAAgB;4BA/CzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAnIpD,MAAM,0BAAyB,qBAAqB;;CAoa9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -16,7 +16,7 @@ import { insertValue, spliceValue } from "../../utils/flat";
|
|
16
16
|
import { usePrevious } from "../../common/use-default-value";
|
17
17
|
var globalKey = '__global__&&@@';
|
18
18
|
import { current, produce } from "../../utils/immer";
|
19
|
-
import { deepGet, deepRemove, deepSet, docScroll, extractEventHandlers, isArray, isObject, shallowEqual, wrapFormError, deepClone, getAllKeyPaths, devUseWarning, getFieldId, getClosestScrollContainer } from "../../utils";
|
19
|
+
import { deepGet, deepRemove, deepSet, docScroll, extractEventHandlers, isArray, isObject, shallowEqual, wrapFormError, deepClone, getAllKeyPaths, getCompleteFieldKeys, devUseWarning, getFieldId, getClosestScrollContainer } from "../../utils";
|
20
20
|
var emptyObj = {};
|
21
21
|
var useForm = function useForm(props) {
|
22
22
|
var _props$defaultValue = props.defaultValue,
|
@@ -48,6 +48,7 @@ var useForm = function useForm(props) {
|
|
48
48
|
var _React$useRef = React.useRef({
|
49
49
|
defaultValues: {},
|
50
50
|
validateMap: {},
|
51
|
+
ignoreValidateFields: [],
|
51
52
|
updateMap: {},
|
52
53
|
flowMap: {},
|
53
54
|
removeArr: new Set(),
|
@@ -69,7 +70,7 @@ var useForm = function useForm(props) {
|
|
69
70
|
Object.keys(context.updateMap).forEach(function (key) {
|
70
71
|
var _context$updateMap$ke;
|
71
72
|
(_context$updateMap$ke = context.updateMap[key]) === null || _context$updateMap$ke === void 0 || _context$updateMap$ke.forEach(function (update) {
|
72
|
-
update(context.value, context.errors, context.serverErrors);
|
73
|
+
update(context.value, context.errors, context.serverErrors, context.names);
|
73
74
|
});
|
74
75
|
});
|
75
76
|
Object.keys(context.flowMap).forEach(function (key) {
|
@@ -80,10 +81,21 @@ var useForm = function useForm(props) {
|
|
80
81
|
} else {
|
81
82
|
var names = isArray(name) ? name : [name];
|
82
83
|
names.forEach(function (key) {
|
83
|
-
var _context$
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
var _context$flowMap$key;
|
85
|
+
// 外部直接设置user.name这种格式的,但是又没有显性的声明user.name绑定的表单元素;
|
86
|
+
// 这里需要手动触发,否则会导致Input输入过程中光标跳到末尾的异常
|
87
|
+
if (!context.updateMap[key]) {
|
88
|
+
var _context$updateMap$pa;
|
89
|
+
var parentKey = key.split('.')[0];
|
90
|
+
(_context$updateMap$pa = context.updateMap[parentKey]) === null || _context$updateMap$pa === void 0 || _context$updateMap$pa.forEach(function (update) {
|
91
|
+
update(context.value, context.errors, context.serverErrors, context.names);
|
92
|
+
});
|
93
|
+
} else {
|
94
|
+
var _context$updateMap$ke2;
|
95
|
+
(_context$updateMap$ke2 = context.updateMap[key]) === null || _context$updateMap$ke2 === void 0 || _context$updateMap$ke2.forEach(function (update) {
|
96
|
+
update(context.value, context.errors, context.serverErrors, context.names);
|
97
|
+
});
|
98
|
+
}
|
87
99
|
(_context$flowMap$key = context.flowMap[key]) === null || _context$flowMap$key === void 0 || _context$flowMap$key.forEach(function (update) {
|
88
100
|
update();
|
89
101
|
});
|
@@ -140,11 +152,28 @@ var useForm = function useForm(props) {
|
|
140
152
|
var validateFields = usePersistFn(function (fields) {
|
141
153
|
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
142
154
|
return new Promise(function (resolve, reject) {
|
143
|
-
var finalFields =
|
144
|
-
|
145
|
-
|
155
|
+
var finalFields = Object.keys(context.validateMap);
|
156
|
+
if (fields) {
|
157
|
+
if (config.ignoreChildren || config.ignoreBind) {
|
158
|
+
// 旧行为:仅校验当前字段
|
159
|
+
finalFields = (isArray(fields) ? fields : [fields]).filter(function (key) {
|
160
|
+
return context.validateMap[key];
|
161
|
+
});
|
162
|
+
} else {
|
163
|
+
// 新行为:校验当前字段及其所有子字段
|
164
|
+
// 假设进去的是['user'],那么最终的finalFields是['user', 'user.name', 'user.age']
|
165
|
+
// 假设进去的是['users'],那么最终的finalFields是['users', 'users[0].name', 'users[0].age', 'users[1].name', 'users[1].age']
|
166
|
+
finalFields = getCompleteFieldKeys(fields, finalFields);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
if (context.ignoreValidateFields.length > 0) {
|
170
|
+
finalFields = finalFields.filter(function (key) {
|
171
|
+
return !context.ignoreValidateFields.includes(key);
|
172
|
+
});
|
173
|
+
}
|
146
174
|
var validates = finalFields.map(function (key) {
|
147
175
|
var validateField = context.validateMap[key];
|
176
|
+
if (!validateField) return [];
|
148
177
|
return Array.from(validateField).map(function (validate) {
|
149
178
|
return validate(key, deepGet(context.value, key), context.value, config);
|
150
179
|
});
|
@@ -215,10 +244,20 @@ var useForm = function useForm(props) {
|
|
215
244
|
var isVisibleX = elementRect.left >= parentRect.left && elementRect.right <= parentRect.right;
|
216
245
|
if (!isVisibleY || !isVisibleX) {
|
217
246
|
// 计算元素相对于父元素的偏移量
|
218
|
-
var offsetTop =
|
219
|
-
var offsetLeft =
|
220
|
-
|
221
|
-
|
247
|
+
var offsetTop = elementRect.top - parentRect.top;
|
248
|
+
var offsetLeft = elementRect.left - parentRect.left;
|
249
|
+
// 如果是往上滚动,那么只有当元素的偏移量小于0时才需要滚动
|
250
|
+
if (offsetTop < 0) {
|
251
|
+
parentEl.scrollTop = Math.max(parentEl.scrollTop + offsetTop, 0);
|
252
|
+
} else {
|
253
|
+
parentEl.scrollTop = Math.min(parentEl.scrollTop + offsetTop, parentEl.scrollHeight - parentEl.clientHeight);
|
254
|
+
}
|
255
|
+
// 如果是往左滚动,那么只有当元素的偏移量小于0时才需要滚动
|
256
|
+
if (offsetLeft < 0) {
|
257
|
+
parentEl.scrollLeft = Math.max(parentEl.scrollLeft + offsetLeft, 0);
|
258
|
+
} else {
|
259
|
+
parentEl.scrollLeft = Math.min(parentEl.scrollLeft + offsetLeft, parentEl.scrollWidth - parentEl.clientWidth);
|
260
|
+
}
|
222
261
|
}
|
223
262
|
} else {
|
224
263
|
// 如果没有找到可滚动的父元素,使用默认行为
|
@@ -377,7 +416,7 @@ var useForm = function useForm(props) {
|
|
377
416
|
}, 10);
|
378
417
|
};
|
379
418
|
};
|
380
|
-
var validateFieldset = function validateFieldset(name) {
|
419
|
+
var validateFieldset = function validateFieldset(name, config) {
|
381
420
|
var na = "".concat(name, "[");
|
382
421
|
var no = "".concat(name, ".");
|
383
422
|
var fields = [];
|
@@ -386,6 +425,15 @@ var useForm = function useForm(props) {
|
|
386
425
|
fields.push(key);
|
387
426
|
}
|
388
427
|
});
|
428
|
+
|
429
|
+
// 用户声明了跳过校验子字段
|
430
|
+
if (config !== null && config !== void 0 && config.ignoreChildren) {
|
431
|
+
var parentName = name.split('[')[0];
|
432
|
+
context.ignoreValidateFields = getCompleteFieldKeys(parentName, Array.from(context.names));
|
433
|
+
setTimeout(function () {
|
434
|
+
context.ignoreValidateFields = [];
|
435
|
+
});
|
436
|
+
}
|
389
437
|
validateFields(fields).catch(function () {});
|
390
438
|
};
|
391
439
|
var getDefaultValue = function getDefaultValue() {
|
@@ -459,6 +507,7 @@ var useForm = function useForm(props) {
|
|
459
507
|
}
|
460
508
|
if (validateFieldSet.size === 0 && updateFieldSet.size === 0) {
|
461
509
|
context.names.delete(n);
|
510
|
+
delete context.errors[n];
|
462
511
|
delete context.defaultValues[n];
|
463
512
|
}
|
464
513
|
var finalReserveAble = (_props$reserveAble = props.reserveAble) !== null && _props$reserveAble !== void 0 ? _props$reserveAble : reserveAble;
|
@@ -14,9 +14,10 @@ export interface ValidationError<T> {
|
|
14
14
|
export type ValidateFnConfig = {
|
15
15
|
type?: 'forcePass' | 'withValue';
|
16
16
|
ignoreBind?: boolean;
|
17
|
+
ignoreChildren?: boolean;
|
17
18
|
};
|
18
19
|
export type ValidateFn = (name: string, value: any, formData: ObjectType, config?: ValidateFnConfig) => Promise<true | FormError>;
|
19
|
-
export type UpdateFn = (formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>) => void;
|
20
|
+
export type UpdateFn = (formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>, names: Set<string>) => void;
|
20
21
|
export interface FormContextValueType {
|
21
22
|
func?: {
|
22
23
|
unbind: (n: string, reserveAble?: boolean, validate?: ValidateFn, update?: UpdateFn) => void;
|
@@ -112,7 +113,7 @@ export interface FormFunc<T = any> {
|
|
112
113
|
getErrors: () => ObjectType<Error | undefined>;
|
113
114
|
clearValidate: (names?: string[]) => void;
|
114
115
|
validateFields: (fields?: string | string[], config?: ValidateFnConfig) => Promise<Partial<T>>;
|
115
|
-
validateFieldset: (name: string) => void;
|
116
|
+
validateFieldset: (name: string, config?: ValidateFnConfig) => void;
|
116
117
|
insertError: (name: string, index: number, error?: Error) => void;
|
117
118
|
spliceError: (name: string, index: number) => void;
|
118
119
|
}
|
@@ -197,13 +198,14 @@ export type FormContext = {
|
|
197
198
|
lastValue: ObjectType | undefined;
|
198
199
|
resetTime: number;
|
199
200
|
mounted: boolean;
|
200
|
-
updateMap: ObjectType<Set<(formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>) => void>>;
|
201
|
+
updateMap: ObjectType<Set<(formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>, names: Set<string>) => void>>;
|
201
202
|
flowMap: ObjectType<Set<() => void>>;
|
202
203
|
value: ObjectType;
|
203
204
|
errors: ObjectType<Error | undefined>;
|
204
205
|
serverErrors: ObjectType<Error | undefined>;
|
205
206
|
unmounted: boolean;
|
206
207
|
removeLock: boolean;
|
208
|
+
ignoreValidateFields: string[];
|
207
209
|
};
|
208
210
|
export type UseFormSlotOwnProps = {
|
209
211
|
onSubmit: any;
|