@sheinx/hooks 3.5.0-beta.1 → 3.5.0-beta.10
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/common/use-in-view/index.d.ts +2 -0
- package/cjs/common/use-in-view/index.d.ts.map +1 -0
- package/cjs/common/use-in-view/index.js +14 -0
- package/cjs/common/use-in-view/use-in-view.d.ts +14 -0
- package/cjs/common/use-in-view/use-in-view.d.ts.map +1 -0
- package/cjs/common/use-in-view/use-in-view.js +73 -0
- package/cjs/common/use-position-style/check-position.d.ts +11 -0
- package/cjs/common/use-position-style/check-position.d.ts.map +1 -0
- package/cjs/common/use-position-style/check-position.js +90 -0
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +15 -21
- package/cjs/components/use-form/index.d.ts +1 -0
- package/cjs/components/use-form/index.d.ts.map +1 -1
- package/cjs/components/use-form/index.js +12 -0
- package/cjs/components/use-form/use-form-context.d.ts +6 -0
- package/cjs/components/use-form/use-form-context.d.ts.map +1 -0
- package/cjs/components/use-form/use-form-context.js +22 -0
- package/cjs/components/use-form/use-form-context.type.d.ts +45 -0
- package/cjs/components/use-form/use-form-context.type.d.ts.map +1 -0
- package/cjs/components/use-form/use-form-context.type.js +5 -0
- 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 +30 -11
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +4 -2
- package/cjs/components/use-form/use-form.type.d.ts +7 -0
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- package/cjs/components/use-image/use-image.d.ts.map +1 -1
- package/cjs/components/use-image/use-image.js +7 -0
- package/cjs/components/use-image/use-image.type.d.ts +7 -0
- package/cjs/components/use-image/use-image.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-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 +5 -0
- package/cjs/components/use-table/use-table-group.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-group.js +2 -1
- package/cjs/components/use-table/use-table-layout.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-layout.js +2 -1
- package/cjs/components/use-table/use-table.type.d.ts +26 -0
- package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
- package/cjs/index.d.ts +1 -0
- package/cjs/index.d.ts.map +1 -1
- package/cjs/index.js +12 -0
- package/cjs/utils/dom/document.d.ts +2 -0
- package/cjs/utils/dom/document.d.ts.map +1 -0
- package/cjs/utils/dom/document.js +49 -0
- package/cjs/utils/dom/element.d.ts +1 -1
- package/cjs/utils/dom/element.d.ts.map +1 -1
- package/cjs/utils/dom/index.d.ts +1 -0
- package/cjs/utils/dom/index.d.ts.map +1 -1
- package/cjs/utils/dom/index.js +12 -0
- package/cjs/utils/is.d.ts +0 -1
- package/cjs/utils/is.d.ts.map +1 -1
- package/cjs/utils/is.js +1 -10
- package/cjs/utils/lazyload.d.ts +1 -0
- package/cjs/utils/lazyload.d.ts.map +1 -1
- package/cjs/utils/lazyload.js +3 -0
- package/esm/common/use-in-view/index.d.ts +2 -0
- package/esm/common/use-in-view/index.d.ts.map +1 -0
- package/esm/common/use-in-view/index.js +2 -0
- package/esm/common/use-in-view/use-in-view.d.ts +14 -0
- package/esm/common/use-in-view/use-in-view.d.ts.map +1 -0
- package/esm/common/use-in-view/use-in-view.js +70 -0
- package/esm/common/use-position-style/check-position.d.ts +11 -0
- package/esm/common/use-position-style/check-position.d.ts.map +1 -0
- package/esm/common/use-position-style/check-position.js +84 -0
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +17 -22
- package/esm/components/use-form/index.d.ts +1 -0
- package/esm/components/use-form/index.d.ts.map +1 -1
- package/esm/components/use-form/index.js +1 -0
- package/esm/components/use-form/use-form-context.d.ts +6 -0
- package/esm/components/use-form/use-form-context.d.ts.map +1 -0
- package/esm/components/use-form/use-form-context.js +13 -0
- package/esm/components/use-form/use-form-context.type.d.ts +45 -0
- package/esm/components/use-form/use-form-context.type.d.ts.map +1 -0
- package/esm/components/use-form/use-form-context.type.js +1 -0
- 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 +30 -11
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +4 -2
- package/esm/components/use-form/use-form.type.d.ts +7 -0
- package/esm/components/use-form/use-form.type.d.ts.map +1 -1
- package/esm/components/use-image/use-image.d.ts.map +1 -1
- package/esm/components/use-image/use-image.js +7 -0
- package/esm/components/use-image/use-image.type.d.ts +7 -0
- package/esm/components/use-image/use-image.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-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 +5 -0
- package/esm/components/use-table/use-table-group.d.ts.map +1 -1
- package/esm/components/use-table/use-table-group.js +3 -2
- package/esm/components/use-table/use-table-layout.d.ts.map +1 -1
- package/esm/components/use-table/use-table-layout.js +2 -1
- package/esm/components/use-table/use-table.type.d.ts +26 -0
- package/esm/components/use-table/use-table.type.d.ts.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/utils/dom/document.d.ts +2 -0
- package/esm/utils/dom/document.d.ts.map +1 -0
- package/esm/utils/dom/document.js +43 -0
- package/esm/utils/dom/element.d.ts +1 -1
- package/esm/utils/dom/element.d.ts.map +1 -1
- package/esm/utils/dom/index.d.ts +1 -0
- package/esm/utils/dom/index.d.ts.map +1 -1
- package/esm/utils/dom/index.js +1 -0
- package/esm/utils/is.d.ts +0 -1
- package/esm/utils/is.d.ts.map +1 -1
- package/esm/utils/is.js +0 -9
- package/esm/utils/lazyload.d.ts +1 -0
- package/esm/utils/lazyload.d.ts.map +1 -1
- package/esm/utils/lazyload.js +3 -0
- package/package.json +1 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,eAAe,CAAC"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
"use client";
|
3
|
+
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
Object.defineProperty(exports, "useInView", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function get() {
|
10
|
+
return _useInView.default;
|
11
|
+
}
|
12
|
+
});
|
13
|
+
var _useInView = _interopRequireDefault(require("./use-in-view"));
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
interface UseInViewOptions {
|
3
|
+
root?: HTMLElement | null;
|
4
|
+
rootMargin?: string;
|
5
|
+
threshold?: number | number[];
|
6
|
+
once?: boolean;
|
7
|
+
}
|
8
|
+
declare const useInView: <T extends HTMLElement>(options?: UseInViewOptions) => {
|
9
|
+
ref: import("react").MutableRefObject<T | null>;
|
10
|
+
isInView: boolean;
|
11
|
+
wasInView: boolean;
|
12
|
+
};
|
13
|
+
export default useInView;
|
14
|
+
//# sourceMappingURL=use-in-view.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"use-in-view.d.ts","sourceRoot":"","sources":["use-in-view.ts"],"names":[],"mappings":";AAIA,UAAU,gBAAgB;IACxB,IAAI,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC9B,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,QAAA,MAAM,SAAS,oCAAoC,gBAAgB;;;;CA2ClE,CAAC;AAEF,eAAe,SAAS,CAAC"}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = 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 useInView = function useInView() {
|
15
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
16
|
+
var elementRef = (0, _react.useRef)(null);
|
17
|
+
var _useState = (0, _react.useState)(false),
|
18
|
+
_useState2 = _slicedToArray(_useState, 2),
|
19
|
+
isInView = _useState2[0],
|
20
|
+
setIsInView = _useState2[1];
|
21
|
+
var _useState3 = (0, _react.useState)(false),
|
22
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
23
|
+
wasInView = _useState4[0],
|
24
|
+
setWasInView = _useState4[1];
|
25
|
+
(0, _react.useEffect)(function () {
|
26
|
+
var element = elementRef.current;
|
27
|
+
if (!element) return;
|
28
|
+
if (typeof window === 'undefined' || !window.IntersectionObserver) {
|
29
|
+
setIsInView(true);
|
30
|
+
setWasInView(true);
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
var observer = new IntersectionObserver(function (_ref) {
|
34
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
35
|
+
entry = _ref2[0];
|
36
|
+
var inView = entry.isIntersecting;
|
37
|
+
setIsInView(inView);
|
38
|
+
if (inView) {
|
39
|
+
setWasInView(true);
|
40
|
+
// 如果设置了 once 选项,且元素已经出现过,则取消观察
|
41
|
+
if (options.once) {
|
42
|
+
observer.disconnect();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}, {
|
46
|
+
root: options.root || null,
|
47
|
+
rootMargin: options.rootMargin || '0px',
|
48
|
+
threshold: options.threshold || 0
|
49
|
+
});
|
50
|
+
observer.observe(element);
|
51
|
+
return function () {
|
52
|
+
observer.disconnect();
|
53
|
+
};
|
54
|
+
}, [options.root, options.rootMargin, options.threshold, options.once]);
|
55
|
+
return {
|
56
|
+
ref: elementRef,
|
57
|
+
isInView: isInView,
|
58
|
+
wasInView: wasInView
|
59
|
+
};
|
60
|
+
};
|
61
|
+
var _default = exports.default = useInView; // 使用示例
|
62
|
+
// const Example = () => {
|
63
|
+
// const { ref, isInView } = useInView({
|
64
|
+
// threshold: 0.5,
|
65
|
+
// rootMargin: '50px',
|
66
|
+
// once: true
|
67
|
+
// });
|
68
|
+
// return (
|
69
|
+
// <div ref={ref}>
|
70
|
+
// {isInView ? '元素在视窗中' : '元素不在视窗中'}
|
71
|
+
// </div>
|
72
|
+
// );
|
73
|
+
// };
|
@@ -0,0 +1,11 @@
|
|
1
|
+
interface Position {
|
2
|
+
top: number;
|
3
|
+
left: number;
|
4
|
+
}
|
5
|
+
interface UseCheckElementPositionOptions {
|
6
|
+
enable?: boolean;
|
7
|
+
scrollContainer?: HTMLElement | null;
|
8
|
+
}
|
9
|
+
export declare const useCheckElementPosition: (elementRef: React.RefObject<HTMLElement>, options?: UseCheckElementPositionOptions) => Position | null;
|
10
|
+
export {};
|
11
|
+
//# sourceMappingURL=check-position.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"check-position.d.ts","sourceRoot":"","sources":["check-position.ts"],"names":[],"mappings":"AAEA,UAAU,QAAQ;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,8BAA8B;IAEtC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CACtC;AAED,eAAO,MAAM,uBAAuB,eACtB,MAAM,SAAS,CAAC,WAAW,CAAC,YAC/B,8BAA8B,KACtC,QAAQ,GAAG,IAyEb,CAAC"}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useCheckElementPosition = 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 useCheckElementPosition = exports.useCheckElementPosition = function useCheckElementPosition(elementRef) {
|
15
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
16
|
+
var enable = options.enable,
|
17
|
+
scrollContainer = options.scrollContainer;
|
18
|
+
var _useState = (0, _react.useState)({
|
19
|
+
top: 0,
|
20
|
+
left: 0
|
21
|
+
}),
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
23
|
+
position = _useState2[0],
|
24
|
+
setPosition = _useState2[1];
|
25
|
+
var lastPosition = (0, _react.useRef)({
|
26
|
+
top: 0,
|
27
|
+
left: 0
|
28
|
+
});
|
29
|
+
var checkPosition = (0, _react.useCallback)(function () {
|
30
|
+
if (elementRef.current) {
|
31
|
+
var rect = elementRef.current.getBoundingClientRect();
|
32
|
+
var scrollContainerRect = scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.getBoundingClientRect();
|
33
|
+
var newPosition;
|
34
|
+
if (scrollContainerRect) {
|
35
|
+
newPosition = {
|
36
|
+
top: rect.top - scrollContainerRect.top,
|
37
|
+
left: rect.left - scrollContainerRect.left
|
38
|
+
};
|
39
|
+
} else {
|
40
|
+
newPosition = {
|
41
|
+
top: rect.top,
|
42
|
+
left: rect.left
|
43
|
+
};
|
44
|
+
}
|
45
|
+
if (newPosition.top !== lastPosition.current.top || newPosition.left !== lastPosition.current.left) {
|
46
|
+
setPosition(newPosition);
|
47
|
+
lastPosition.current = newPosition;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}, [elementRef, scrollContainer]);
|
51
|
+
(0, _react.useEffect)(function () {
|
52
|
+
var _window;
|
53
|
+
if (!enable) return;
|
54
|
+
var element = elementRef.current;
|
55
|
+
var container = scrollContainer || window;
|
56
|
+
if (!element) return;
|
57
|
+
|
58
|
+
// 初始检查
|
59
|
+
checkPosition();
|
60
|
+
var resizeObserver = null;
|
61
|
+
if ((_window = window) !== null && _window !== void 0 && _window.ResizeObserver) {
|
62
|
+
resizeObserver = new ResizeObserver(checkPosition);
|
63
|
+
resizeObserver.observe(element);
|
64
|
+
if (container instanceof Element) {
|
65
|
+
resizeObserver.observe(container);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
// 滚动事件监听
|
69
|
+
container.addEventListener('scroll', checkPosition);
|
70
|
+
|
71
|
+
// 如果容器不是 window,我们仍然需要监听 window 的 resize 事件
|
72
|
+
if (container !== window) {
|
73
|
+
window.addEventListener('resize', checkPosition);
|
74
|
+
}
|
75
|
+
|
76
|
+
// 清理函数
|
77
|
+
return function () {
|
78
|
+
var _resizeObserver;
|
79
|
+
(_resizeObserver = resizeObserver) === null || _resizeObserver === void 0 || _resizeObserver.disconnect();
|
80
|
+
container.removeEventListener('scroll', checkPosition);
|
81
|
+
if (container !== window) {
|
82
|
+
window.removeEventListener('resize', checkPosition);
|
83
|
+
}
|
84
|
+
};
|
85
|
+
}, [enable, elementRef, scrollContainer, checkPosition]);
|
86
|
+
if (!enable || !elementRef) {
|
87
|
+
return null;
|
88
|
+
}
|
89
|
+
return position;
|
90
|
+
};
|
@@ -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;AAQnD,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;CAClB;AAOD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB;;;CAyS3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
@@ -8,10 +8,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
8
8
|
exports.usePositionStyle = exports.default = void 0;
|
9
9
|
var _react = _interopRequireWildcard(require("react"));
|
10
10
|
var _getPositionStyle = require("./get-position-style");
|
11
|
+
var _checkPosition = require("./check-position");
|
11
12
|
var _shallowEqual = _interopRequireDefault(require("../../utils/shallow-equal"));
|
12
13
|
var _usePersistFn = _interopRequireDefault(require("../use-persist-fn"));
|
13
14
|
var _utils = require("../../utils");
|
14
|
-
var _element = require("../../utils/dom/element");
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16
16
|
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); }
|
17
17
|
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; }
|
@@ -26,8 +26,7 @@ var verticalPosition = ['bottom-left', 'bottom-right', 'top-left', 'top-right',
|
|
26
26
|
var hideStyle = {
|
27
27
|
pointerEvents: 'none',
|
28
28
|
position: 'fixed',
|
29
|
-
|
30
|
-
opacity: 0
|
29
|
+
visibility: 'hidden'
|
31
30
|
};
|
32
31
|
var usePositionStyle = exports.usePositionStyle = function usePositionStyle(config) {
|
33
32
|
var _ref = config || {},
|
@@ -55,7 +54,6 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
55
54
|
arrayStyle = _useState4[0],
|
56
55
|
setArrayStyle = _useState4[1];
|
57
56
|
var _React$useRef = _react.default.useRef({
|
58
|
-
element: null,
|
59
57
|
containerRect: {
|
60
58
|
left: 0,
|
61
59
|
width: 0
|
@@ -69,10 +67,13 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
69
67
|
width: 0
|
70
68
|
},
|
71
69
|
popUpHeight: 0,
|
72
|
-
popUpWidth: 0
|
73
|
-
opsStyle: {}
|
70
|
+
popUpWidth: 0
|
74
71
|
}),
|
75
72
|
context = _React$useRef.current;
|
73
|
+
var parentElNewPosition = (0, _checkPosition.useCheckElementPosition)(parentElRef, {
|
74
|
+
scrollContainer: scrollElRef === null || scrollElRef === void 0 ? void 0 : scrollElRef.current,
|
75
|
+
enable: show && adjust
|
76
|
+
});
|
76
77
|
var adjustPosition = function adjustPosition(position) {
|
77
78
|
var winHeight = _utils.docSize.height;
|
78
79
|
if (!verticalPosition.includes(position)) return position;
|
@@ -139,7 +140,6 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
139
140
|
}
|
140
141
|
var targetPosition = position;
|
141
142
|
var rootContainer = getContainer() || document.body;
|
142
|
-
var closestScrollContainer = (0, _element.getClosestScrollContainer)(parentElRef.current);
|
143
143
|
var containerRect = rootContainer.getBoundingClientRect();
|
144
144
|
var bodyRect = (document.documentElement || document.body).getBoundingClientRect();
|
145
145
|
var containerScrollBarWidth = rootContainer.offsetWidth - rootContainer.clientWidth;
|
@@ -158,7 +158,7 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
158
158
|
var overRight = 0;
|
159
159
|
var overLeft = 0;
|
160
160
|
if (h === 'left') {
|
161
|
-
style.left = rect.left - containerRect.left + containerScroll.left
|
161
|
+
style.left = rect.left - containerRect.left + containerScroll.left;
|
162
162
|
style.transform = '';
|
163
163
|
arrayStyle.left = "8px";
|
164
164
|
if (adjust) {
|
@@ -257,13 +257,14 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
257
257
|
};
|
258
258
|
};
|
259
259
|
var getAbsoluteStyle = function getAbsoluteStyle(position) {
|
260
|
+
var _scrollElRef$current;
|
260
261
|
if (!parentElRef.current) return {
|
261
262
|
style: hideStyle
|
262
263
|
};
|
263
264
|
var rect = context.parentRect;
|
264
|
-
if (scrollElRef !== null && scrollElRef !== void 0 && scrollElRef.current) {
|
265
|
-
var _scrollElRef$
|
266
|
-
var visibleRect = ((_scrollElRef$
|
265
|
+
if (scrollElRef !== null && scrollElRef !== void 0 && scrollElRef.current && (_scrollElRef$current = scrollElRef.current) !== null && _scrollElRef$current !== void 0 && _scrollElRef$current.contains(parentElRef.current)) {
|
266
|
+
var _scrollElRef$current2;
|
267
|
+
var visibleRect = ((_scrollElRef$current2 = scrollElRef.current) === null || _scrollElRef$current2 === void 0 ? void 0 : _scrollElRef$current2.getBoundingClientRect()) || {};
|
267
268
|
if (rect.bottom < visibleRect.top || rect.top > visibleRect.bottom || rect.right < visibleRect.left || rect.left > visibleRect.right) {
|
268
269
|
return {
|
269
270
|
style: hideStyle
|
@@ -273,15 +274,8 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
273
274
|
var _getAbsolutePositionS = getAbsolutePositionStyle(rect, position),
|
274
275
|
style = _getAbsolutePositionS.style,
|
275
276
|
arrayStyle = _getAbsolutePositionS.arrayStyle;
|
276
|
-
|
277
|
-
|
278
|
-
if (!(0, _utils.isChromeLowerThan)(128)) {
|
279
|
-
// @ts-ignore currentCSSZoom
|
280
|
-
var currentCSSZoom = document.body.currentCSSZoom;
|
281
|
-
if (currentCSSZoom === 1 || !currentCSSZoom) return {
|
282
|
-
style: style,
|
283
|
-
arrayStyle: arrayStyle
|
284
|
-
};
|
277
|
+
var currentCSSZoom = (0, _utils.getCurrentCSSZoom)();
|
278
|
+
if (currentCSSZoom && currentCSSZoom !== 1) {
|
285
279
|
if (style.left && typeof style.left === 'number') {
|
286
280
|
style.left = style.left * (1 / currentCSSZoom);
|
287
281
|
}
|
@@ -347,7 +341,7 @@ var usePositionStyle = exports.usePositionStyle = function usePositionStyle(conf
|
|
347
341
|
setArrayStyle(newArrayStyle || {});
|
348
342
|
}
|
349
343
|
});
|
350
|
-
(0, _react.useEffect)(updateStyle, [show, position, absolute, updateKey, fixedWidth]);
|
344
|
+
(0, _react.useEffect)(updateStyle, [show, position, absolute, updateKey, fixedWidth, parentElNewPosition]);
|
351
345
|
return {
|
352
346
|
style: style,
|
353
347
|
arrayStyle: arrayStyle
|
@@ -2,6 +2,7 @@ export * from './use-form-control';
|
|
2
2
|
export * from './use-form-item';
|
3
3
|
export * from './use-form-fieldset';
|
4
4
|
export * from './use-form-flow';
|
5
|
+
export * from './use-form-context';
|
5
6
|
export { default, default as useForm } from './use-form';
|
6
7
|
export { useFormConfig } from './form-config-context';
|
7
8
|
export { useFormFunc } from './form-func-context';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
@@ -81,6 +81,18 @@ Object.keys(_useFormFlow).forEach(function (key) {
|
|
81
81
|
}
|
82
82
|
});
|
83
83
|
});
|
84
|
+
var _useFormContext = require("./use-form-context");
|
85
|
+
Object.keys(_useFormContext).forEach(function (key) {
|
86
|
+
if (key === "default" || key === "__esModule") return;
|
87
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
88
|
+
if (key in exports && exports[key] === _useFormContext[key]) return;
|
89
|
+
Object.defineProperty(exports, key, {
|
90
|
+
enumerable: true,
|
91
|
+
get: function get() {
|
92
|
+
return _useFormContext[key];
|
93
|
+
}
|
94
|
+
});
|
95
|
+
});
|
84
96
|
var _useForm = _interopRequireDefault(require("./use-form"));
|
85
97
|
var _formConfigContext = require("./form-config-context");
|
86
98
|
var _formFuncContext = require("./form-func-context");
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { FormRef } from './use-form-context.type';
|
3
|
+
export declare const FormContext: React.Context<any>;
|
4
|
+
export declare function useFormRef<V>(): [FormRef<V>, ((formRef: FormRef<V>) => void)];
|
5
|
+
export declare function useFromInstance<V>(): FormRef<V>;
|
6
|
+
//# sourceMappingURL=use-form-context.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"use-form-context.d.ts","sourceRoot":"","sources":["use-form-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,eAAO,MAAM,WAAW,oBAA+B,CAAC;AAExD,wBAAgB,UAAU,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAQ7E;AAED,wBAAgB,eAAe,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAG/C"}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.FormContext = void 0;
|
7
|
+
exports.useFormRef = useFormRef;
|
8
|
+
exports.useFromInstance = useFromInstance;
|
9
|
+
var _react = _interopRequireDefault(require("react"));
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
var FormContext = exports.FormContext = /*#__PURE__*/_react.default.createContext({});
|
12
|
+
function useFormRef() {
|
13
|
+
var ref = _react.default.useRef({});
|
14
|
+
var setFormRef = function setFormRef(formRef) {
|
15
|
+
ref.current = formRef;
|
16
|
+
};
|
17
|
+
return [ref.current, setFormRef];
|
18
|
+
}
|
19
|
+
function useFromInstance() {
|
20
|
+
var formCtx = _react.default.useContext(FormContext);
|
21
|
+
return formCtx;
|
22
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
export interface FormRef<Value> {
|
2
|
+
/**
|
3
|
+
* @en return form value
|
4
|
+
* @cn 返回表单的值
|
5
|
+
*/
|
6
|
+
getValue: (name?: string) => any | Value;
|
7
|
+
/**
|
8
|
+
* @en Validate form
|
9
|
+
* @cn 校验表单
|
10
|
+
*/
|
11
|
+
validate: () => Promise<any>;
|
12
|
+
/**
|
13
|
+
* @en Validation form fields
|
14
|
+
* @cn 校验表单指定字段
|
15
|
+
*/
|
16
|
+
validateFields: (fields: string | string[]) => Promise<any>;
|
17
|
+
/**
|
18
|
+
* @en The verification can get the error message through Promise.catch
|
19
|
+
* @cn 校验可以通过 catch 获取报错信息
|
20
|
+
*/
|
21
|
+
validateFieldsWithError: (fields: string | string[]) => Promise<any>;
|
22
|
+
/**
|
23
|
+
* @en Clear check
|
24
|
+
* @cn 清除校验
|
25
|
+
*/
|
26
|
+
clearValidate: (names?: string[]) => void;
|
27
|
+
/**
|
28
|
+
* @en Submit Form, withValidate: Whether to verify
|
29
|
+
* @cn 提交表单, withValidate: 是否校验
|
30
|
+
*/
|
31
|
+
submit: (withValidate?: boolean) => void;
|
32
|
+
/**
|
33
|
+
* @en reset form
|
34
|
+
* @cn 重置表单
|
35
|
+
*/
|
36
|
+
reset: () => void;
|
37
|
+
/**
|
38
|
+
* @en set field value, key is field path, Example: { 'name': 'sanmao', 'account.name': 'sanmao', 'friends[0].name': 'sanmao' }
|
39
|
+
* @cn 设置字段值, key为字段路径,示例:{ 'name': 'sanmao', 'account.name': 'sanmao', 'friends[0].name': 'sanmao' }
|
40
|
+
*/
|
41
|
+
set: (value: {
|
42
|
+
[key: string]: any;
|
43
|
+
}) => void;
|
44
|
+
}
|
45
|
+
//# sourceMappingURL=use-form-context.type.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"use-form-context.type.d.ts","sourceRoot":"","sources":["use-form-context.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO,CAAC,KAAK;IAC5B;;;OAGG;IACH,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,GAAG,KAAK,CAAC;IACzC;;;OAGG;IACH,QAAQ,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B;;;OAGG;IACH,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5D;;;OAGG;IACH,uBAAuB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACrE;;;OAGG;IACH,aAAa,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC1C;;;OAGG;IACH,MAAM,EAAE,CAAC,YAAY,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;OAGG;IACH,GAAG,EAAE,CAAC,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,KAAK,IAAI,CAAC;CAC9C"}
|
@@ -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;AAyB/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;AAyB/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBA2IpC,CAAC,YAAY,GAAG,EAAE;;;;;EAiDrD"}
|
@@ -97,18 +97,37 @@ function useFormControl(props) {
|
|
97
97
|
var errors = arguments.length > 1 ? arguments[1] : undefined;
|
98
98
|
var severErrors = arguments.length > 2 ? arguments[2] : undefined;
|
99
99
|
if (!name) return;
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
100
|
+
if ((0, _is.isArray)(name)) {
|
101
|
+
var _value = getValue(name, formValue);
|
102
|
+
var _error = getError(name, errors, severErrors);
|
103
|
+
if (_error !== errorState) {
|
104
|
+
setErrorState(_error);
|
105
|
+
}
|
106
|
+
// format defaultValue
|
107
|
+
var dv = (0, _is.isArray)(defaultValue) ? defaultValue : [];
|
108
|
+
var nextValue = [];
|
109
|
+
name.forEach(function (n, index) {
|
110
|
+
if (_value[index] === undefined && dv[index] !== undefined) {
|
111
|
+
nextValue[index] = dv[index];
|
112
|
+
} else {
|
113
|
+
nextValue[index] = _value[index];
|
114
|
+
}
|
115
|
+
});
|
116
|
+
setValueState(nextValue);
|
117
|
+
} else {
|
118
|
+
var _value2 = getValue(name, formValue);
|
119
|
+
var _error2 = getError(name, errors, severErrors);
|
120
|
+
if (_error2 !== errorState) {
|
121
|
+
setErrorState(_error2);
|
122
|
+
}
|
123
|
+
if (!(0, _shallowEqual.shallowEqual)(_value2, latestInfo.valueState)) {
|
124
|
+
if (_value2 === undefined && defaultValue !== undefined) {
|
125
|
+
setValueState(defaultValue);
|
126
|
+
} else {
|
127
|
+
setValueState(_value2);
|
128
|
+
}
|
129
|
+
latestInfo.valueState = _value2;
|
110
130
|
}
|
111
|
-
latestInfo.valueState = value;
|
112
131
|
}
|
113
132
|
});
|
114
133
|
var validateFiled = (0, _usePersistFn.default)(function (name, v, formV) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AA0BA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AA0BA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBA0KC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;aAAE;8BAVd,MAAM;oCAkED,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCAlFN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;qCAgJ5D,MAAM;gCA3CE,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;;;;;;oBAnDjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE;0BAVd,MAAM;gCAkED,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCAlFN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;iCAgJ5D,MAAM;4BA3CE,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;;CAkQ9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -45,6 +45,7 @@ var useForm = function useForm(props) {
|
|
45
45
|
_props$throttle = props.throttle,
|
46
46
|
throttle = _props$throttle === void 0 ? 1000 : _props$throttle,
|
47
47
|
size = props.size,
|
48
|
+
reserveAble = props.reserveAble,
|
48
49
|
scrollParent = props.scrollParent;
|
49
50
|
var deepSetOptions = {
|
50
51
|
removeUndefined: removeUndefined,
|
@@ -443,9 +444,10 @@ var useForm = function useForm(props) {
|
|
443
444
|
keepErrorHeight: keepErrorHeight,
|
444
445
|
inline: inline,
|
445
446
|
disabled: disabled,
|
446
|
-
size: size
|
447
|
+
size: size,
|
448
|
+
reserveAble: reserveAble
|
447
449
|
};
|
448
|
-
}, [labelWidth, labelAlign, labelVerticalAlign, keepErrorHeight, inline, disabled, size]);
|
450
|
+
}, [labelWidth, labelAlign, labelVerticalAlign, keepErrorHeight, inline, disabled, size, reserveAble]);
|
449
451
|
var updateValue = function updateValue() {
|
450
452
|
if (props.value !== context.lastValue && props.value !== context.value) {
|
451
453
|
context.value = (0, _utils.deepClone)(props.value) || emptyObj;
|
@@ -67,6 +67,13 @@ export interface FormCommonConfig extends FormLabelConfig {
|
|
67
67
|
* @default 'default'
|
68
68
|
*/
|
69
69
|
size?: 'small' | 'default' | 'large';
|
70
|
+
/**
|
71
|
+
* @en When set to true, the form items in Form will not automatically delete data after unmounting
|
72
|
+
* @cn 设置为 true 时,表单内所有组件的reserveAble都为 true : 卸载后不自动删除数据
|
73
|
+
* @default false
|
74
|
+
* @version 3.5.0
|
75
|
+
*/
|
76
|
+
reserveAble?: boolean;
|
70
77
|
}
|
71
78
|
export interface FormFunc {
|
72
79
|
setValue: (vals: {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.type.d.ts","sourceRoot":"","sources":["use-form.type.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,MAAM,UAAU,GAAG,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,UAAU,EACpB,MAAM,CAAC,EAAE;IACP,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,KACE,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;AAEjC,MAAM,MAAM,QAAQ,GAAG,CACrB,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,EACrC,YAAY,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,KACxC,IAAI,CAAA;AAET,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAC,UAAU,EAAE,MAAM,CAAC,EAAC,QAAQ,KAAM,IAAI,CAAC;QAC5F,IAAI,EAAE,CACJ,CAAC,EAAE,MAAM,EACT,EAAE,EAAE,GAAG,EACP,QAAQ,EAAE,UAAU,EACpB,MAAM,EAAE,QAAQ,KACb,IAAI,CAAC;QACV,YAAY,EAAE,CAAC,SAAS,EACtB,IAAI,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CAAC,CAAC,CAAC;IACrC,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACtC,YAAY,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAC5C,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,UAAU,CACzE,mBAAmB,EACnB,MAAM,CACP,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-image.d.ts","sourceRoot":"","sources":["use-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAWlD,QAAA,MAAM,QAAQ,WAAW,cAAc;;;;;;;;;;yBA6D3B,gBAAgB,CAAC,gBAAgB,GAAG,cAAc,CAAC;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"use-image.d.ts","sourceRoot":"","sources":["use-image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAWlD,QAAA,MAAM,QAAQ,WAAW,cAAc;;;;;;;;;;yBA6D3B,gBAAgB,CAAC,gBAAgB,GAAG,cAAc,CAAC;;;;;;;;;;;CAmF9D,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
@@ -139,10 +139,17 @@ var useImage = function useImage() {
|
|
139
139
|
offset: typeof lazy === 'number' ? lazy : 0,
|
140
140
|
element: elementRef.current,
|
141
141
|
render: markToRender,
|
142
|
+
offscreen: function offscreen() {
|
143
|
+
setStatus(PLACEHOLDER);
|
144
|
+
},
|
145
|
+
noRemove: props.inViewOnly,
|
142
146
|
container: typeof container === 'string' ? document.querySelector(container) : container
|
143
147
|
});
|
144
148
|
}
|
145
149
|
}
|
150
|
+
return function () {
|
151
|
+
if (lazyId) (0, _utils.removeStack)(lazyId);
|
152
|
+
};
|
146
153
|
}, [src]);
|
147
154
|
return {
|
148
155
|
src: src,
|
@@ -54,6 +54,13 @@ export interface BaseImageProps {
|
|
54
54
|
* @default false
|
55
55
|
*/
|
56
56
|
lazy?: boolean | number;
|
57
|
+
/**
|
58
|
+
* @en Whether to load only when in view
|
59
|
+
* @cn 是否仅在视图内加载
|
60
|
+
* @default false
|
61
|
+
* @version 3.4.5
|
62
|
+
*/
|
63
|
+
inViewOnly?: boolean;
|
57
64
|
/**
|
58
65
|
* @en The original property of html
|
59
66
|
* @cn 是否禁止 img 元素原生 draggable 属性
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-image.type.d.ts","sourceRoot":"","sources":["use-image.type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;AAChE,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;AACjE,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE1E,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B;;;;;;;;;OASG;I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