@sheinx/hooks 3.6.0-beta.2 → 3.6.0-beta.21
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 +16 -7
- 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-check/use-check.d.ts +1 -1
- package/cjs/components/use-check/use-check.d.ts.map +1 -1
- package/cjs/components/use-check/use-check.js +10 -3
- package/cjs/components/use-form/Provider.d.ts +1 -2
- package/cjs/components/use-form/Provider.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-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 +3 -4
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +63 -16
- package/cjs/components/use-form/use-form.type.d.ts +6 -2
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-format.d.ts +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-input/use-input-number.d.ts +1 -1
- package/cjs/components/use-input/use-input-number.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-number.js +1 -0
- package/cjs/components/use-table/index.d.ts +2 -1
- package/cjs/components/use-table/index.d.ts.map +1 -1
- package/cjs/components/use-table/index.js +7 -0
- package/cjs/components/use-table/use-table-filter.d.ts +19 -0
- package/cjs/components/use-table/use-table-filter.d.ts.map +1 -0
- package/cjs/components/use-table/use-table-filter.js +95 -0
- 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-table/use-table.type.d.ts +93 -0
- package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
- package/cjs/components/use-tabs/context.d.ts +1 -1
- package/cjs/components/use-tabs/context.d.ts.map +1 -1
- package/cjs/components/use-tabs/use-tabs.d.ts +1 -1
- 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 +213 -6
- package/cjs/components/use-tree/use-tree.type.d.ts +35 -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/utils/dom/element.d.ts +1 -1
- package/cjs/utils/dom/element.d.ts.map +1 -1
- package/cjs/utils/dom/element.js +5 -3
- 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/lazyload.d.ts.map +1 -1
- package/cjs/utils/lazyload.js +2 -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/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 +16 -7
- 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-check/use-check.d.ts +1 -1
- package/esm/components/use-check/use-check.d.ts.map +1 -1
- package/esm/components/use-check/use-check.js +10 -3
- package/esm/components/use-form/Provider.d.ts +1 -2
- package/esm/components/use-form/Provider.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-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 +3 -4
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +64 -17
- package/esm/components/use-form/use-form.type.d.ts +6 -2
- package/esm/components/use-form/use-form.type.d.ts.map +1 -1
- package/esm/components/use-input/use-input-format.d.ts +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-input/use-input-number.d.ts +1 -1
- package/esm/components/use-input/use-input-number.d.ts.map +1 -1
- package/esm/components/use-input/use-input-number.js +1 -0
- package/esm/components/use-table/index.d.ts +2 -1
- package/esm/components/use-table/index.d.ts.map +1 -1
- package/esm/components/use-table/index.js +1 -0
- package/esm/components/use-table/use-table-filter.d.ts +19 -0
- package/esm/components/use-table/use-table-filter.d.ts.map +1 -0
- package/esm/components/use-table/use-table-filter.js +88 -0
- 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-table/use-table.type.d.ts +93 -0
- package/esm/components/use-table/use-table.type.d.ts.map +1 -1
- package/esm/components/use-tabs/context.d.ts +1 -1
- package/esm/components/use-tabs/context.d.ts.map +1 -1
- package/esm/components/use-tabs/use-tabs.d.ts +1 -1
- 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 +215 -8
- package/esm/components/use-tree/use-tree.type.d.ts +35 -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/utils/dom/element.d.ts +1 -1
- package/esm/utils/dom/element.d.ts.map +1 -1
- package/esm/utils/dom/element.js +4 -2
- 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/lazyload.d.ts.map +1 -1
- package/esm/utils/lazyload.js +3 -3
- 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/warning.js +5 -5
- package/package.json +1 -1
@@ -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,35 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useCheckElementBorderWidth = void 0;
|
7
|
+
var _react = require("react");
|
8
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
9
|
+
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."); }
|
10
|
+
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); }
|
11
|
+
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; }
|
12
|
+
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; } }
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
14
|
+
var useCheckElementBorderWidth = exports.useCheckElementBorderWidth = function useCheckElementBorderWidth(elementRef) {
|
15
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
16
|
+
var _useState = (0, _react.useState)(0),
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
18
|
+
borderWidth = _useState2[0],
|
19
|
+
setBorderWidth = _useState2[1];
|
20
|
+
|
21
|
+
// 获取指定方向上的border宽度之和
|
22
|
+
var getBorderWidth = (0, _react.useCallback)(function () {
|
23
|
+
if (elementRef.current) {
|
24
|
+
var _options$direction = options.direction,
|
25
|
+
direction = _options$direction === void 0 ? 'horizontal' : _options$direction;
|
26
|
+
var style = window.getComputedStyle(elementRef.current);
|
27
|
+
var _borderWidth = direction === 'horizontal' ? parseFloat(style.borderLeftWidth) + parseFloat(style.borderRightWidth) : parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
|
28
|
+
setBorderWidth(_borderWidth);
|
29
|
+
}
|
30
|
+
}, [elementRef]);
|
31
|
+
(0, _react.useEffect)(function () {
|
32
|
+
getBorderWidth();
|
33
|
+
}, [getBorderWidth]);
|
34
|
+
return borderWidth;
|
35
|
+
};
|
@@ -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"}
|
@@ -28,6 +28,9 @@ var getPositionStyle = exports.getPositionStyle = function getPositionStyle(posi
|
|
28
28
|
if (config !== null && config !== void 0 && config.fixedWidth) {
|
29
29
|
var key = config.fixedWidth === 'min' ? 'minWidth' : 'width';
|
30
30
|
newStyle[key] = '100%';
|
31
|
+
if (config.parentBorderWidth) {
|
32
|
+
newStyle[key] = "calc(100% + ".concat(config.parentBorderWidth, "px)");
|
33
|
+
}
|
31
34
|
}
|
32
35
|
if (position === 'drop-down') {
|
33
36
|
newStyle.top = mainMargin;
|
@@ -39,19 +42,22 @@ var getPositionStyle = exports.getPositionStyle = function getPositionStyle(posi
|
|
39
42
|
var positionArr = (position || '').split('-');
|
40
43
|
if (positionArr.length === 2) {
|
41
44
|
var _positionArr = _slicedToArray(positionArr, 2),
|
42
|
-
|
43
|
-
|
44
|
-
newStyle[ReverseDir[
|
45
|
-
newStyle[
|
45
|
+
vDirection = _positionArr[0],
|
46
|
+
hDirection = _positionArr[1];
|
47
|
+
newStyle[ReverseDir[vDirection]] = mainMargin;
|
48
|
+
newStyle[hDirection] = 0;
|
49
|
+
if (config !== null && config !== void 0 && config.parentBorderWidth) {
|
50
|
+
newStyle[hDirection] = -config.parentBorderWidth / 2;
|
51
|
+
}
|
46
52
|
} else {
|
47
53
|
var _positionArr2 = _slicedToArray(positionArr, 1),
|
48
|
-
|
49
|
-
newStyle[ReverseDir[
|
50
|
-
if (
|
54
|
+
_vDirection = _positionArr2[0];
|
55
|
+
newStyle[ReverseDir[_vDirection]] = mainMargin;
|
56
|
+
if (_vDirection === 'left' || _vDirection === 'right') {
|
51
57
|
newStyle.top = halfMargin;
|
52
58
|
newStyle.transform = 'translateY(-50%)';
|
53
59
|
}
|
54
|
-
if (
|
60
|
+
if (_vDirection === 'top' || _vDirection === 'bottom') {
|
55
61
|
newStyle.left = halfMargin;
|
56
62
|
newStyle.transform = 'translateX(-50%)';
|
57
63
|
}
|
@@ -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;;;CAgT3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
@@ -9,6 +9,7 @@ exports.usePositionStyle = exports.default = void 0;
|
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
10
10
|
var _getPositionStyle = require("./get-position-style");
|
11
11
|
var _checkPosition = require("./check-position");
|
12
|
+
var _checkBorder = require("./check-border");
|
12
13
|
var _shallowEqual = _interopRequireDefault(require("../../utils/shallow-equal"));
|
13
14
|
var _usePersistFn = _interopRequireDefault(require("../use-persist-fn"));
|
14
15
|
var _utils = require("../../utils");
|
@@ -43,7 +44,8 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
43
44
|
popupElRef = _ref.popupElRef,
|
44
45
|
scrollElRef = _ref.scrollElRef,
|
45
46
|
updateKey = _ref.updateKey,
|
46
|
-
adjust = _ref.adjust
|
47
|
+
adjust = _ref.adjust,
|
48
|
+
offset = _ref.offset;
|
47
49
|
// 初次渲染无样式的时候, 隐藏展示
|
48
50
|
var _useState = (0, _react.useState)(hideStyle),
|
49
51
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -74,6 +76,9 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
74
76
|
scrollContainer: scrollElRef === null || scrollElRef === void 0 ? void 0 : scrollElRef.current,
|
75
77
|
enable: show && adjust
|
76
78
|
});
|
79
|
+
var parentElBorderWidth = (0, _checkBorder.useCheckElementBorderWidth)(parentElRef, {
|
80
|
+
direction: 'horizontal'
|
81
|
+
});
|
77
82
|
var adjustPosition = function adjustPosition(position) {
|
78
83
|
var winHeight = _utils.docSize.height;
|
79
84
|
if (!verticalPosition.includes(position)) return position;
|
@@ -158,7 +163,7 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
158
163
|
var overRight = 0;
|
159
164
|
var overLeft = 0;
|
160
165
|
if (h === 'left') {
|
161
|
-
style.left = rect.left - containerRect.left + containerScroll.left;
|
166
|
+
style.left = rect.left - containerRect.left + containerScroll.left - (offset ? offset[0] : 0);
|
162
167
|
style.transform = '';
|
163
168
|
arrayStyle.left = "8px";
|
164
169
|
if (adjust) {
|
@@ -168,7 +173,7 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
168
173
|
}
|
169
174
|
}
|
170
175
|
} else if (h === 'right') {
|
171
|
-
style.right = containerRect.right - rect.right + containerScrollBarWidth - containerScroll.left;
|
176
|
+
style.right = containerRect.right - rect.right + containerScrollBarWidth - containerScroll.left - (offset ? offset[0] : 0);
|
172
177
|
style.left = 'auto';
|
173
178
|
style.transform = '';
|
174
179
|
arrayStyle.right = "8px";
|
@@ -225,11 +230,11 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
225
230
|
_h = _targetPosition$split4[0],
|
226
231
|
_v = _targetPosition$split4[1];
|
227
232
|
if (_v === 'top') {
|
228
|
-
style.top = rect.top - containerRect.top + containerScroll.top;
|
233
|
+
style.top = rect.top - containerRect.top + containerScroll.top - (offset ? offset[1] : 0);
|
229
234
|
style.transform = '';
|
230
235
|
arrayStyle.top = "8px";
|
231
236
|
} else if (_v === 'bottom') {
|
232
|
-
style.top = rect.bottom - containerRect.top + containerScroll.top;
|
237
|
+
style.top = rect.bottom - containerRect.top + containerScroll.top + (offset ? offset[1] : 0);
|
233
238
|
arrayStyle.bottom = "8px";
|
234
239
|
style.transform = 'translateY(-100%)';
|
235
240
|
} else {
|
@@ -304,17 +309,19 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
304
309
|
newStyle: style
|
305
310
|
};
|
306
311
|
context.parentRect = parentElRef.current.getBoundingClientRect();
|
312
|
+
var realPosition = position;
|
307
313
|
if (adjust) {
|
308
314
|
var popupInfo = getPopUpInfo(context.parentRect);
|
309
315
|
context.popUpHeight = popupInfo.height;
|
310
316
|
context.popUpWidth = popupInfo.width;
|
317
|
+
realPosition = adjustPosition(position);
|
311
318
|
}
|
312
|
-
var realPosition = adjust ? adjustPosition(position) : position;
|
313
319
|
if (!absolute) {
|
314
320
|
newStyle = (0, _getPositionStyle.getPositionStyle)(realPosition, {
|
315
321
|
popupGap: popupGap,
|
316
322
|
zIndex: zIndex,
|
317
|
-
fixedWidth: fixedWidth
|
323
|
+
fixedWidth: fixedWidth,
|
324
|
+
parentBorderWidth: parentElBorderWidth
|
318
325
|
});
|
319
326
|
} else {
|
320
327
|
var _ref3 = getAbsoluteStyle(realPosition),
|
@@ -326,6 +333,8 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
326
333
|
// for animation
|
327
334
|
if (realPosition.indexOf('top') === 0) {
|
328
335
|
newStyle.transformOrigin = 'center bottom';
|
336
|
+
} else if (realPosition.indexOf('bottom') === 0) {
|
337
|
+
newStyle.transformOrigin = 'center top';
|
329
338
|
}
|
330
339
|
return {
|
331
340
|
newStyle: newStyle,
|
@@ -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"}
|
@@ -22,7 +22,7 @@ declare const useCheck: (props: BaseCheckProps) => {
|
|
22
22
|
ref: ((instance: HTMLInputElement | null) => void) | null;
|
23
23
|
disabled: boolean | undefined;
|
24
24
|
};
|
25
|
-
getRootProps: <TOther_2 extends ObjectType>(externalProps?: TOther_2) => TOther_2 & {
|
25
|
+
getRootProps: <TOther_2 extends ObjectType>(externalProps?: TOther_2) => Omit<TOther_2, "needStopPropagation"> & {
|
26
26
|
onClick: (event: React.MouseEvent) => void;
|
27
27
|
};
|
28
28
|
disabled: boolean | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-check.d.ts","sourceRoot":"","sources":["use-check.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
1
|
+
{"version":3,"file":"use-check.d.ts","sourceRoot":"","sources":["use-check.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,QAAA,MAAM,QAAQ,UAAW,cAAc;;;;;qBAuDpB,gBAAgB,CAAC,gBAAgB,CAAC;0BArBT,MAAM,WAAW,CAAC,gBAAgB,CAAC;;;;;;;;;;;yBAnBa,gBAAgB;;;;CAiE3G,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
exports.default = void 0;
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
9
9
|
var _utils = require("../../utils");
|
10
|
+
var _ = require("../..");
|
10
11
|
var _useForkRef = _interopRequireDefault(require("../../common/use-fork-ref"));
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12
13
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
@@ -43,9 +44,12 @@ var useCheck = function useCheck(props) {
|
|
43
44
|
};
|
44
45
|
var inputRef = _react.default.useRef(null);
|
45
46
|
var handleInputRef = (0, _useForkRef.default)(inputRef, inputRefPo);
|
46
|
-
var handleClick = function handleClick(otherHandlers) {
|
47
|
+
var handleClick = function handleClick(otherHandlers, needStopPropagation) {
|
47
48
|
return function (event) {
|
48
49
|
var _inputRef$current, _otherHandlers$onClic;
|
50
|
+
if (needStopPropagation) {
|
51
|
+
event.stopPropagation();
|
52
|
+
}
|
49
53
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.click();
|
50
54
|
otherHandlers === null || otherHandlers === void 0 || (_otherHandlers$onClic = otherHandlers.onClick) === null || _otherHandlers$onClic === void 0 || _otherHandlers$onClic.call(otherHandlers, event);
|
51
55
|
};
|
@@ -53,8 +57,10 @@ var useCheck = function useCheck(props) {
|
|
53
57
|
var getRootProps = function getRootProps() {
|
54
58
|
var externalProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
55
59
|
var externalEventHandlers = (0, _utils.extractEventHandlers)(externalProps);
|
56
|
-
return _objectSpread(_objectSpread({}, externalProps
|
57
|
-
|
60
|
+
return _objectSpread(_objectSpread({}, _.util.removeProps(externalProps, {
|
61
|
+
needStopPropagation: true
|
62
|
+
})), {}, {
|
63
|
+
onClick: handleClick(externalEventHandlers, externalProps.needStopPropagation)
|
58
64
|
});
|
59
65
|
//封装点击事件 点击触发input 的点击
|
60
66
|
// disabled 禁用后不可点击
|
@@ -83,6 +89,7 @@ var useCheck = function useCheck(props) {
|
|
83
89
|
disabled: disabled
|
84
90
|
}, checkProps), {}, {
|
85
91
|
onClick: function onClick(e) {
|
92
|
+
// TODO: 这个e.stopPropagation生效不了,外部的触发是通过inputRef.current?.click()方式的;没啥用的代码
|
86
93
|
e.stopPropagation();
|
87
94
|
_onClick === null || _onClick === void 0 || _onClick(e);
|
88
95
|
},
|
@@ -1,4 +1,3 @@
|
|
1
|
-
/// <reference types="react" />
|
2
1
|
import { ProviderProps } from './use-form.type';
|
3
|
-
export declare const Provider: (props: ProviderProps) => JSX.Element;
|
2
|
+
export declare const Provider: (props: ProviderProps) => import("react/jsx-runtime").JSX.Element;
|
4
3
|
//# sourceMappingURL=Provider.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["Provider.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["Provider.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,eAAO,MAAM,QAAQ,UAAW,aAAa,4CAW5C,CAAC"}
|
@@ -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;;kBAiJpC,CAAC,YAAY,GAAG,EAAE;;;;;EAkDrD"}
|
@@ -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"}
|
@@ -4,7 +4,7 @@
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
5
5
|
value: true
|
6
6
|
});
|
7
|
-
exports.useFieldSetConsumer = exports.default = void 0;
|
7
|
+
exports.useFieldSetConsumer = exports.default = exports.FieldsetContext = void 0;
|
8
8
|
var _react = _interopRequireWildcard(require("react"));
|
9
9
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
10
10
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
@@ -14,10 +14,11 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
14
14
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
15
15
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
16
16
|
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); }
|
17
|
-
var FieldsetContext = /*#__PURE__*/(0, _react.createContext)({
|
17
|
+
var FieldsetContext = exports.FieldsetContext = /*#__PURE__*/(0, _react.createContext)({
|
18
18
|
path: '',
|
19
19
|
validateFieldSet: function validateFieldSet() {}
|
20
20
|
});
|
21
|
+
FieldsetContext.displayName = 'FieldsetContext';
|
21
22
|
function extendName() {
|
22
23
|
var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
23
24
|
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"}
|
@@ -4,6 +4,12 @@
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
5
5
|
value: true
|
6
6
|
});
|
7
|
+
Object.defineProperty(exports, "FieldsetContext", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function get() {
|
10
|
+
return _fieldsetContext.FieldsetContext;
|
11
|
+
}
|
12
|
+
});
|
7
13
|
Object.defineProperty(exports, "default", {
|
8
14
|
enumerable: true,
|
9
15
|
get: function get() {
|
@@ -1,9 +1,8 @@
|
|
1
|
-
/// <reference types="react" />
|
2
1
|
import { ProviderProps, UseFormProps, UseFormSlotProps, ValidateFnConfig } from './use-form.type';
|
3
2
|
import { ObjectType } from '../../common/type';
|
4
3
|
declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
5
4
|
getFormProps: <TOther extends ObjectType = ObjectType>(externalProps?: TOther) => UseFormSlotProps<TOther>;
|
6
|
-
Provider: (props: ProviderProps) => JSX.Element;
|
5
|
+
Provider: (props: ProviderProps) => import("react/jsx-runtime").JSX.Element;
|
7
6
|
ProviderProps: {
|
8
7
|
formValue: import("./use-form.type").FormContextValueType;
|
9
8
|
formConfig: import("./use-form.type").FormCommonConfig;
|
@@ -21,7 +20,7 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
21
20
|
getErrors: () => ObjectType<Error | undefined>;
|
22
21
|
clearValidate: (names?: string[]) => void;
|
23
22
|
validateFields: (fields?: string | string[], config?: ValidateFnConfig) => Promise<T>;
|
24
|
-
validateFieldset: (name: string) => void;
|
23
|
+
validateFieldset: (name: string, config?: ValidateFnConfig) => void;
|
25
24
|
insertError: (name: string, index: number, error?: Error) => void;
|
26
25
|
spliceError: (name: string, index: number) => void;
|
27
26
|
scrollToField: (name: string, scrollIntoViewOptions?: ScrollIntoViewOptions) => void;
|
@@ -41,7 +40,7 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
41
40
|
getErrors: () => ObjectType<Error | undefined>;
|
42
41
|
clearValidate: (names?: string[]) => void;
|
43
42
|
validateFields: (fields?: string | string[], config?: ValidateFnConfig) => Promise<T>;
|
44
|
-
validateFieldset: (name: string) => void;
|
43
|
+
validateFieldset: (name: string, config?: ValidateFnConfig) => void;
|
45
44
|
insertError: (name: string, index: number, error?: Error) => void;
|
46
45
|
spliceError: (name: string, index: number) => void;
|
47
46
|
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;;;;;;;;;wBAyRC;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;;CAma9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -53,10 +53,10 @@ var useForm = function useForm(props) {
|
|
53
53
|
forceSet: true
|
54
54
|
};
|
55
55
|
var preValue = (0, _useDefaultValue.usePrevious)(props.value);
|
56
|
-
var formDomRef = React.useRef();
|
57
56
|
var _React$useRef = React.useRef({
|
58
57
|
defaultValues: {},
|
59
58
|
validateMap: {},
|
59
|
+
ignoreValidateFields: [],
|
60
60
|
updateMap: {},
|
61
61
|
flowMap: {},
|
62
62
|
removeArr: new Set(),
|
@@ -89,10 +89,21 @@ var useForm = function useForm(props) {
|
|
89
89
|
} else {
|
90
90
|
var names = (0, _utils.isArray)(name) ? name : [name];
|
91
91
|
names.forEach(function (key) {
|
92
|
-
var _context$
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
var _context$flowMap$key;
|
93
|
+
// 外部直接设置user.name这种格式的,但是又没有显性的声明user.name绑定的表单元素;
|
94
|
+
// 这里需要手动触发,否则会导致Input输入过程中光标跳到末尾的异常
|
95
|
+
if (!context.updateMap[key]) {
|
96
|
+
var _context$updateMap$pa;
|
97
|
+
var parentKey = key.split('.')[0];
|
98
|
+
(_context$updateMap$pa = context.updateMap[parentKey]) === null || _context$updateMap$pa === void 0 || _context$updateMap$pa.forEach(function (update) {
|
99
|
+
update(context.value, context.errors, context.serverErrors);
|
100
|
+
});
|
101
|
+
} else {
|
102
|
+
var _context$updateMap$ke2;
|
103
|
+
(_context$updateMap$ke2 = context.updateMap[key]) === null || _context$updateMap$ke2 === void 0 || _context$updateMap$ke2.forEach(function (update) {
|
104
|
+
update(context.value, context.errors, context.serverErrors);
|
105
|
+
});
|
106
|
+
}
|
96
107
|
(_context$flowMap$key = context.flowMap[key]) === null || _context$flowMap$key === void 0 || _context$flowMap$key.forEach(function (update) {
|
97
108
|
update();
|
98
109
|
});
|
@@ -115,9 +126,9 @@ var useForm = function useForm(props) {
|
|
115
126
|
onError === null || onError === void 0 || onError(err);
|
116
127
|
if (!props.scrollToError) return;
|
117
128
|
setTimeout(function () {
|
118
|
-
var
|
129
|
+
var _props$formElRef$curr;
|
119
130
|
var selector = "[".concat((0, _attribute.getDataAttributeName)('status'), "=\"error\"]");
|
120
|
-
var el = (
|
131
|
+
var el = (_props$formElRef$curr = props.formElRef.current) === null || _props$formElRef$curr === void 0 ? void 0 : _props$formElRef$curr.querySelector(selector);
|
121
132
|
if (el) {
|
122
133
|
el.scrollIntoView();
|
123
134
|
var focusableSelectors = 'textarea, input,[tabindex]:not([tabindex="-1"])';
|
@@ -149,11 +160,28 @@ var useForm = function useForm(props) {
|
|
149
160
|
var validateFields = (0, _usePersistFn.default)(function (fields) {
|
150
161
|
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
151
162
|
return new Promise(function (resolve, reject) {
|
152
|
-
var finalFields =
|
153
|
-
|
154
|
-
|
163
|
+
var finalFields = Object.keys(context.validateMap);
|
164
|
+
if (fields) {
|
165
|
+
if (config.ignoreChildren || config.ignoreBind) {
|
166
|
+
// 旧行为:仅校验当前字段
|
167
|
+
finalFields = ((0, _utils.isArray)(fields) ? fields : [fields]).filter(function (key) {
|
168
|
+
return context.validateMap[key];
|
169
|
+
});
|
170
|
+
} else {
|
171
|
+
// 新行为:校验当前字段及其所有子字段
|
172
|
+
// 假设进去的是['user'],那么最终的finalFields是['user', 'user.name', 'user.age']
|
173
|
+
// 假设进去的是['users'],那么最终的finalFields是['users', 'users[0].name', 'users[0].age', 'users[1].name', 'users[1].age']
|
174
|
+
finalFields = (0, _utils.getCompleteFieldKeys)(fields, finalFields);
|
175
|
+
}
|
176
|
+
}
|
177
|
+
if (context.ignoreValidateFields.length > 0) {
|
178
|
+
finalFields = finalFields.filter(function (key) {
|
179
|
+
return !context.ignoreValidateFields.includes(key);
|
180
|
+
});
|
181
|
+
}
|
155
182
|
var validates = finalFields.map(function (key) {
|
156
183
|
var validateField = context.validateMap[key];
|
184
|
+
if (!validateField) return [];
|
157
185
|
return Array.from(validateField).map(function (validate) {
|
158
186
|
return validate(key, (0, _utils.deepGet)(context.value, key), context.value, config);
|
159
187
|
});
|
@@ -224,10 +252,20 @@ var useForm = function useForm(props) {
|
|
224
252
|
var isVisibleX = elementRect.left >= parentRect.left && elementRect.right <= parentRect.right;
|
225
253
|
if (!isVisibleY || !isVisibleX) {
|
226
254
|
// 计算元素相对于父元素的偏移量
|
227
|
-
var offsetTop =
|
228
|
-
var offsetLeft =
|
229
|
-
|
230
|
-
|
255
|
+
var offsetTop = elementRect.top - parentRect.top;
|
256
|
+
var offsetLeft = elementRect.left - parentRect.left;
|
257
|
+
// 如果是往上滚动,那么只有当元素的偏移量小于0时才需要滚动
|
258
|
+
if (offsetTop < 0) {
|
259
|
+
parentEl.scrollTop = Math.max(parentEl.scrollTop + offsetTop, 0);
|
260
|
+
} else {
|
261
|
+
parentEl.scrollTop = Math.min(parentEl.scrollTop + offsetTop, parentEl.scrollHeight - parentEl.clientHeight);
|
262
|
+
}
|
263
|
+
// 如果是往左滚动,那么只有当元素的偏移量小于0时才需要滚动
|
264
|
+
if (offsetLeft < 0) {
|
265
|
+
parentEl.scrollLeft = Math.max(parentEl.scrollLeft + offsetLeft, 0);
|
266
|
+
} else {
|
267
|
+
parentEl.scrollLeft = Math.min(parentEl.scrollLeft + offsetLeft, parentEl.scrollWidth - parentEl.clientWidth);
|
268
|
+
}
|
231
269
|
}
|
232
270
|
} else {
|
233
271
|
// 如果没有找到可滚动的父元素,使用默认行为
|
@@ -386,7 +424,7 @@ var useForm = function useForm(props) {
|
|
386
424
|
}, 10);
|
387
425
|
};
|
388
426
|
};
|
389
|
-
var validateFieldset = function validateFieldset(name) {
|
427
|
+
var validateFieldset = function validateFieldset(name, config) {
|
390
428
|
var na = "".concat(name, "[");
|
391
429
|
var no = "".concat(name, ".");
|
392
430
|
var fields = [];
|
@@ -395,6 +433,15 @@ var useForm = function useForm(props) {
|
|
395
433
|
fields.push(key);
|
396
434
|
}
|
397
435
|
});
|
436
|
+
|
437
|
+
// 用户声明了跳过校验子字段
|
438
|
+
if (config !== null && config !== void 0 && config.ignoreChildren) {
|
439
|
+
var parentName = name.split('[')[0];
|
440
|
+
context.ignoreValidateFields = (0, _utils.getCompleteFieldKeys)(parentName, Array.from(context.names));
|
441
|
+
setTimeout(function () {
|
442
|
+
context.ignoreValidateFields = [];
|
443
|
+
});
|
444
|
+
}
|
398
445
|
validateFields(fields).catch(function () {});
|
399
446
|
};
|
400
447
|
var getDefaultValue = function getDefaultValue() {
|
@@ -422,7 +469,6 @@ var useForm = function useForm(props) {
|
|
422
469
|
var externalProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
423
470
|
var externalEventHandlers = (0, _utils.extractEventHandlers)(externalProps);
|
424
471
|
return _objectSpread(_objectSpread(_objectSpread({}, externalProps), externalEventHandlers), {}, {
|
425
|
-
ref: formDomRef,
|
426
472
|
disabled: !!disabled,
|
427
473
|
onSubmit: handleSubmit(externalEventHandlers),
|
428
474
|
onReset: handleReset(externalEventHandlers)
|
@@ -468,6 +514,7 @@ var useForm = function useForm(props) {
|
|
468
514
|
}
|
469
515
|
if (validateFieldSet.size === 0 && updateFieldSet.size === 0) {
|
470
516
|
context.names.delete(n);
|
517
|
+
delete context.errors[n];
|
471
518
|
delete context.defaultValues[n];
|
472
519
|
}
|
473
520
|
var finalReserveAble = (_props$reserveAble = props.reserveAble) !== null && _props$reserveAble !== void 0 ? _props$reserveAble : reserveAble;
|
@@ -14,6 +14,7 @@ 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
20
|
export type UpdateFn = (formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>) => 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
|
}
|
@@ -184,7 +185,9 @@ export interface BaseFormProps<T> extends Omit<FormCommonConfig, 'formName'> {
|
|
184
185
|
*/
|
185
186
|
name?: string;
|
186
187
|
}
|
187
|
-
export type UseFormProps<T> = BaseFormProps<T
|
188
|
+
export type UseFormProps<T> = BaseFormProps<T> & {
|
189
|
+
formElRef: React.RefObject<HTMLFormElement>;
|
190
|
+
};
|
188
191
|
export type FormContext = {
|
189
192
|
defaultValues: ObjectType;
|
190
193
|
validateMap: ObjectType<Set<(name: string, v: any, formValue: ObjectType, config?: {
|
@@ -204,6 +207,7 @@ export type FormContext = {
|
|
204
207
|
serverErrors: ObjectType<Error | undefined>;
|
205
208
|
unmounted: boolean;
|
206
209
|
removeLock: boolean;
|
210
|
+
ignoreValidateFields: string[];
|
207
211
|
};
|
208
212
|
export type UseFormSlotOwnProps = {
|
209
213
|
onSubmit: any;
|