@sheinx/hooks 3.8.0-beta.3 → 3.8.0-beta.31
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-position-style/check-border.d.ts +1 -0
- package/cjs/common/use-position-style/check-border.d.ts.map +1 -1
- package/cjs/common/use-position-style/check-border.js +2 -2
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +10 -4
- package/cjs/components/use-datepicker/use-date.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-date.js +12 -4
- package/cjs/components/use-datepicker/use-date.type.d.ts +2 -1
- package/cjs/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts +2 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.js +22 -5
- package/cjs/components/use-datepicker/use-datepicker-range.js +2 -2
- package/cjs/components/use-datepicker/use-time.d.ts +10 -8
- package/cjs/components/use-datepicker/use-time.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-time.js +19 -5
- package/cjs/components/use-datepicker/use-time.type.d.ts +5 -1
- package/cjs/components/use-datepicker/use-time.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.d.ts +7 -1
- package/cjs/components/use-datepicker/util.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.js +21 -2
- package/cjs/components/use-form/Provider.d.ts.map +1 -1
- package/cjs/components/use-form/Provider.js +7 -2
- package/cjs/components/use-form/form-schema-context.d.ts +6 -0
- package/cjs/components/use-form/form-schema-context.d.ts.map +1 -0
- package/cjs/components/use-form/form-schema-context.js +16 -0
- package/cjs/components/use-form/index.d.ts +2 -0
- package/cjs/components/use-form/index.d.ts.map +1 -1
- package/cjs/components/use-form/index.js +21 -1
- package/cjs/components/use-form/use-form-context.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-context.js +11 -5
- package/cjs/components/use-form/use-form-context.type.d.ts +6 -0
- package/cjs/components/use-form/use-form-context.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 +12 -3
- package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
- package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
- package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-item/form-item-context.d.ts +1 -0
- package/cjs/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-item/form-item-context.js +2 -1
- package/cjs/components/use-form/use-form-item/index.d.ts +1 -0
- package/cjs/components/use-form/use-form-item/index.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-item/index.js +7 -0
- package/cjs/components/use-form/use-form-item/use-form-item.d.ts +1 -1
- package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts +49 -0
- package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
- package/cjs/components/use-form/use-form-schema/form-schema-builder.js +330 -0
- package/cjs/components/use-form/use-form-schema/index.d.ts +3 -0
- package/cjs/components/use-form/use-form-schema/index.d.ts.map +1 -0
- package/cjs/components/use-form/use-form-schema/index.js +13 -0
- package/cjs/components/use-form/use-form.d.ts +4 -0
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +22 -11
- package/cjs/components/use-form/use-form.type.d.ts +46 -39
- 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 +2 -1
- package/cjs/components/use-input/use-input.d.ts.map +1 -1
- package/cjs/components/use-input/use-input.js +4 -1
- package/cjs/components/use-pagination/use-pagination.d.ts.map +1 -1
- package/cjs/components/use-pagination/use-pagination.js +2 -1
- package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
- package/cjs/components/use-popup/use-popup.js +7 -4
- package/cjs/components/use-select/use-select.type.d.ts +27 -18
- package/cjs/components/use-select/use-select.type.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.d.ts +6 -1
- package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.js +5 -4
- package/cjs/components/use-table/use-table.type.d.ts +70 -92
- package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree-node.d.ts +7 -1
- package/cjs/components/use-tree/use-tree-node.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree-node.js +19 -1
- package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree.js +14 -9
- package/cjs/components/use-tree/use-tree.type.d.ts +7 -1
- package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
- package/cjs/utils/dom/document.d.ts +4 -0
- package/cjs/utils/dom/document.d.ts.map +1 -1
- package/cjs/utils/dom/document.js +19 -2
- package/cjs/utils/dom/element.d.ts +1 -0
- package/cjs/utils/dom/element.d.ts.map +1 -1
- package/cjs/utils/dom/element.js +5 -1
- package/cjs/utils/highlight.d.ts.map +1 -1
- package/cjs/utils/highlight.js +24 -11
- package/cjs/utils/lazyload.d.ts.map +1 -1
- package/cjs/utils/lazyload.js +33 -1
- package/cjs/utils/number.d.ts +10 -0
- package/cjs/utils/number.d.ts.map +1 -1
- package/cjs/utils/number.js +99 -1
- package/cjs/utils/object.d.ts +6 -0
- package/cjs/utils/object.d.ts.map +1 -1
- package/cjs/utils/object.js +21 -1
- package/cjs/utils/shallow-equal.d.ts +1 -0
- package/cjs/utils/shallow-equal.d.ts.map +1 -1
- package/cjs/utils/shallow-equal.js +9 -0
- package/esm/common/use-position-style/check-border.d.ts +1 -0
- package/esm/common/use-position-style/check-border.d.ts.map +1 -1
- package/esm/common/use-position-style/check-border.js +2 -2
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +11 -5
- package/esm/components/use-datepicker/use-date.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-date.js +12 -4
- package/esm/components/use-datepicker/use-date.type.d.ts +2 -1
- package/esm/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts +2 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.js +19 -5
- package/esm/components/use-datepicker/use-datepicker-range.js +2 -2
- package/esm/components/use-datepicker/use-time.d.ts +10 -8
- package/esm/components/use-datepicker/use-time.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-time.js +19 -5
- package/esm/components/use-datepicker/use-time.type.d.ts +5 -1
- package/esm/components/use-datepicker/use-time.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.d.ts +7 -1
- package/esm/components/use-datepicker/util.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.js +21 -2
- package/esm/components/use-form/Provider.d.ts.map +1 -1
- package/esm/components/use-form/Provider.js +7 -2
- package/esm/components/use-form/form-schema-context.d.ts +6 -0
- package/esm/components/use-form/form-schema-context.d.ts.map +1 -0
- package/esm/components/use-form/form-schema-context.js +8 -0
- package/esm/components/use-form/index.d.ts +2 -0
- package/esm/components/use-form/index.d.ts.map +1 -1
- package/esm/components/use-form/index.js +3 -1
- package/esm/components/use-form/use-form-context.d.ts.map +1 -1
- package/esm/components/use-form/use-form-context.js +11 -5
- package/esm/components/use-form/use-form-context.type.d.ts +6 -0
- package/esm/components/use-form/use-form-context.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 +12 -3
- package/esm/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
- package/esm/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
- package/esm/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
- package/esm/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
- package/esm/components/use-form/use-form-item/form-item-context.d.ts +1 -0
- package/esm/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
- package/esm/components/use-form/use-form-item/form-item-context.js +2 -1
- package/esm/components/use-form/use-form-item/index.d.ts +1 -0
- package/esm/components/use-form/use-form-item/index.d.ts.map +1 -1
- package/esm/components/use-form/use-form-item/index.js +2 -1
- package/esm/components/use-form/use-form-item/use-form-item.d.ts +1 -1
- package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts +49 -0
- package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
- package/esm/components/use-form/use-form-schema/form-schema-builder.js +324 -0
- package/esm/components/use-form/use-form-schema/index.d.ts +3 -0
- package/esm/components/use-form/use-form-schema/index.d.ts.map +1 -0
- package/esm/components/use-form/use-form-schema/index.js +2 -0
- package/esm/components/use-form/use-form.d.ts +4 -0
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +22 -11
- package/esm/components/use-form/use-form.type.d.ts +46 -39
- 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 +2 -1
- package/esm/components/use-input/use-input.d.ts.map +1 -1
- package/esm/components/use-input/use-input.js +4 -1
- package/esm/components/use-pagination/use-pagination.d.ts.map +1 -1
- package/esm/components/use-pagination/use-pagination.js +2 -1
- package/esm/components/use-popup/use-popup.d.ts.map +1 -1
- package/esm/components/use-popup/use-popup.js +7 -4
- package/esm/components/use-select/use-select.type.d.ts +27 -18
- package/esm/components/use-select/use-select.type.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.d.ts +6 -1
- package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.js +5 -4
- package/esm/components/use-table/use-table.type.d.ts +70 -92
- package/esm/components/use-table/use-table.type.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree-node.d.ts +7 -1
- package/esm/components/use-tree/use-tree-node.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree-node.js +19 -1
- package/esm/components/use-tree/use-tree.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree.js +14 -9
- package/esm/components/use-tree/use-tree.type.d.ts +7 -1
- package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
- package/esm/utils/dom/document.d.ts +4 -0
- package/esm/utils/dom/document.d.ts.map +1 -1
- package/esm/utils/dom/document.js +18 -1
- package/esm/utils/dom/element.d.ts +1 -0
- package/esm/utils/dom/element.d.ts.map +1 -1
- package/esm/utils/dom/element.js +4 -0
- package/esm/utils/highlight.d.ts.map +1 -1
- package/esm/utils/highlight.js +24 -10
- package/esm/utils/lazyload.d.ts.map +1 -1
- package/esm/utils/lazyload.js +33 -1
- package/esm/utils/number.d.ts +10 -0
- package/esm/utils/number.d.ts.map +1 -1
- package/esm/utils/number.js +98 -1
- package/esm/utils/object.d.ts +6 -0
- package/esm/utils/object.d.ts.map +1 -1
- package/esm/utils/object.js +20 -0
- package/esm/utils/shallow-equal.d.ts +1 -0
- package/esm/utils/shallow-equal.d.ts.map +1 -1
- package/esm/utils/shallow-equal.js +8 -0
- package/package.json +3 -3
package/esm/utils/highlight.js
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
2
|
+
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; }
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
4
|
+
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; }
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
6
|
+
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); }
|
1
7
|
import React, { cloneElement } from 'react';
|
2
8
|
import { escapeRegExp } from "./string";
|
3
9
|
import { isArray } from "./is";
|
@@ -11,22 +17,31 @@ export function getHighlightText(_ref) {
|
|
11
17
|
if (!enable || !searchWords) {
|
12
18
|
return nodeList;
|
13
19
|
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
20
|
+
|
21
|
+
// 递归转换节点
|
22
|
+
var transformNode = function transformNode(node, index) {
|
23
|
+
// 如果是合法的 React 元素
|
24
|
+
if ( /*#__PURE__*/React.isValidElement(node) && node.props && node.props.children) {
|
25
|
+
// 对 children 递归调用 getHighlightText 进行转换
|
26
|
+
var transformedChildren = getHighlightText({
|
27
|
+
nodeList: node.props.children,
|
19
28
|
searchWords: searchWords,
|
20
|
-
highlightClassName: highlightClassName
|
21
|
-
|
29
|
+
highlightClassName: highlightClassName,
|
30
|
+
enable: enable
|
31
|
+
});
|
32
|
+
return /*#__PURE__*/cloneElement(node, _objectSpread(_objectSpread({}, node.props), {}, {
|
33
|
+
key: index
|
34
|
+
}), transformedChildren);
|
22
35
|
}
|
23
|
-
|
36
|
+
// 如果节点为字符串,则直接高亮替换
|
37
|
+
if (typeof node === 'string') {
|
24
38
|
return /*#__PURE__*/_jsx(HighlightText, {
|
25
39
|
textToHighlight: node,
|
26
40
|
searchWords: searchWords,
|
27
41
|
highlightClassName: highlightClassName
|
28
42
|
});
|
29
43
|
}
|
44
|
+
// 其他情况直接返回原节点
|
30
45
|
return node;
|
31
46
|
};
|
32
47
|
return isArray(nodeList) ? nodeList.map(transformNode) : transformNode(nodeList);
|
@@ -42,8 +57,7 @@ function HighlightText(_ref2) {
|
|
42
57
|
searchWords = searchWords.slice(0, 500);
|
43
58
|
}
|
44
59
|
|
45
|
-
//
|
46
|
-
// 从而在strArr中可以保留匹配文本
|
60
|
+
// 带 capture group 的正则用于 split 保留匹配文本
|
47
61
|
var re = new RegExp("(".concat(escapeRegExp(searchWords), ")"), 'i');
|
48
62
|
var strArr = textToHighlight.split(re);
|
49
63
|
return /*#__PURE__*/_jsx(_Fragment, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"lazyload.d.ts","sourceRoot":"","sources":["lazyload.ts"],"names":[],"mappings":"AAKA,KAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CACjC,CAAC;AAsBF,wBAAgB,QAAQ,SAgBvB;AAWD,wBAAgB,WAAW,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,cAAc,CAAC,EAAE,OAAO,QAUvE;
|
1
|
+
{"version":3,"file":"lazyload.d.ts","sourceRoot":"","sources":["lazyload.ts"],"names":[],"mappings":"AAKA,KAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,oBAAoB,CAAC;CACjC,CAAC;AAsBF,wBAAgB,QAAQ,SAgBvB;AAWD,wBAAgB,WAAW,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,EAAE,cAAc,CAAC,EAAE,OAAO,QAUvE;AA4DD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,iBA4BvC"}
|
package/esm/utils/lazyload.js
CHANGED
@@ -58,6 +58,34 @@ export function removeStack(id, removeListener) {
|
|
58
58
|
}
|
59
59
|
delete components[id];
|
60
60
|
}
|
61
|
+
|
62
|
+
// 检测容器是否高度受限
|
63
|
+
var isRootHeightConstrained = function isRootHeightConstrained(root, targetElement) {
|
64
|
+
if (!root || root === document.body) {
|
65
|
+
var bodyRect = document.body.getBoundingClientRect();
|
66
|
+
var _targetRect = targetElement.getBoundingClientRect();
|
67
|
+
// body的底部和targetElement的顶部永远不可能有相交,则是受限的
|
68
|
+
if (bodyRect.bottom < _targetRect.top) {
|
69
|
+
return true;
|
70
|
+
} else {
|
71
|
+
return false;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
// 当root的overflow是auto或hidden,则认为不是受限的
|
76
|
+
var rootStyle = window.getComputedStyle(root);
|
77
|
+
if (rootStyle.overflow === 'auto' || rootStyle.overflow === 'hidden') {
|
78
|
+
return false;
|
79
|
+
}
|
80
|
+
|
81
|
+
// 当root的底部与targetElement的顶部永远不可能有相交,则是受限的
|
82
|
+
var rootRect = root.getBoundingClientRect();
|
83
|
+
var targetRect = targetElement.getBoundingClientRect();
|
84
|
+
if (rootRect.top > targetRect.bottom || rootRect.bottom < targetRect.top) {
|
85
|
+
return true;
|
86
|
+
}
|
87
|
+
return false;
|
88
|
+
};
|
61
89
|
function getObserver(obj, id) {
|
62
90
|
var _obj$container = obj.container,
|
63
91
|
container = _obj$container === void 0 ? null : _obj$container,
|
@@ -67,6 +95,10 @@ function getObserver(obj, id) {
|
|
67
95
|
offscreen = obj.offscreen,
|
68
96
|
noRemove = obj.noRemove;
|
69
97
|
var fixedContainer = getClosestPositionedContainer(element, ['fixed', 'absolute']);
|
98
|
+
|
99
|
+
// 获取最优的观察器配置
|
100
|
+
var candidateRoot = fixedContainer || container;
|
101
|
+
var observerRoot = isRootHeightConstrained(candidateRoot, element) ? null : candidateRoot;
|
70
102
|
var observer = new IntersectionObserver(function (entries) {
|
71
103
|
entries.forEach(function (en) {
|
72
104
|
if (en.isIntersecting || en.intersectionRatio > 0) {
|
@@ -78,7 +110,7 @@ function getObserver(obj, id) {
|
|
78
110
|
}
|
79
111
|
});
|
80
112
|
}, {
|
81
|
-
root:
|
113
|
+
root: observerRoot,
|
82
114
|
rootMargin: "".concat(offset, "px")
|
83
115
|
});
|
84
116
|
obj.observer = observer;
|
package/esm/utils/number.d.ts
CHANGED
@@ -5,4 +5,14 @@ export declare function isE(number: unknown): boolean;
|
|
5
5
|
export declare function getNumberPrecision(number: unknown): number;
|
6
6
|
export declare function sub(num1: number, num2: number): number;
|
7
7
|
export declare function toNum(v: number | string | undefined): number;
|
8
|
+
/**
|
9
|
+
* 格式化数字字符串到指定小数位
|
10
|
+
* @param {string} value 数字字符串
|
11
|
+
* @param {number} precision 小数位数
|
12
|
+
* @returns {string} 格式化后的字符串
|
13
|
+
* @example
|
14
|
+
* console.log(preciseString('111111111111111.888', 2)) // "111111111111111.89"
|
15
|
+
* console.log(preciseString('9.999', 2)) // "10.00"
|
16
|
+
*/
|
17
|
+
export declare const preciseString: (value: string, precision?: number) => string;
|
8
18
|
//# sourceMappingURL=number.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["number.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,SAAI,YAM3C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAK,UAEtD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,WAgB1C;AACD,wBAAgB,GAAG,CAAC,MAAM,EAAE,OAAO,WAIlC;AACD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,UAgBjD;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAY7C;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAe5D"}
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["number.ts"],"names":[],"mappings":"AAEA,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,SAAI,YAM3C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAK,UAEtD;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,WAgB1C;AACD,wBAAgB,GAAG,CAAC,MAAM,EAAE,OAAO,WAIlC;AACD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,UAgBjD;AAED,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAY7C;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAe5D;AAmED;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,UAAW,MAAM,+BAwB1C,CAAA"}
|
package/esm/utils/number.js
CHANGED
@@ -73,4 +73,101 @@ export function toNum(v) {
|
|
73
73
|
return isNaN(parsedValue) ? 0 : parsedValue;
|
74
74
|
}
|
75
75
|
return 0;
|
76
|
-
}
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* 在字符串层面实现四舍五入
|
80
|
+
* @param {string} numStr 数字字符串
|
81
|
+
* @param {number} precision 精度
|
82
|
+
* @returns {string} 四舍五入后的字符串
|
83
|
+
*/
|
84
|
+
function roundString(numStr, precision) {
|
85
|
+
if (precision < 0) return numStr;
|
86
|
+
var parts = numStr.split('.');
|
87
|
+
var intPart = parts[0];
|
88
|
+
var decimalPart = parts[1] || '';
|
89
|
+
if (decimalPart.length <= precision) {
|
90
|
+
return intPart + (decimalPart ? ".".concat(decimalPart.padEnd(precision, '0')) : '');
|
91
|
+
}
|
92
|
+
|
93
|
+
// 需要进行四舍五入
|
94
|
+
var roundPos = precision;
|
95
|
+
var carry = 0;
|
96
|
+
|
97
|
+
// 确定是否需要进位
|
98
|
+
if (parseInt(decimalPart[roundPos], 10) >= 5) carry = 1;
|
99
|
+
|
100
|
+
// 如果不需要进位,直接截断
|
101
|
+
if (carry === 0) {
|
102
|
+
return intPart + (precision > 0 ? ".".concat(decimalPart.slice(0, precision)) : '');
|
103
|
+
}
|
104
|
+
|
105
|
+
// 处理进位
|
106
|
+
var digits = (intPart + (decimalPart ? ".".concat(decimalPart) : '')).replace('.', '').split('');
|
107
|
+
var dotPos = intPart.length;
|
108
|
+
|
109
|
+
// 从小数位开始向前进位
|
110
|
+
var i = dotPos + precision - 1;
|
111
|
+
while (carry > 0 && i >= 0) {
|
112
|
+
// 跳过小数点
|
113
|
+
if (i === dotPos - 1) {
|
114
|
+
i -= 1;
|
115
|
+
continue;
|
116
|
+
}
|
117
|
+
var d = parseInt(digits[i], 10) + carry;
|
118
|
+
digits[i] = (d % 10).toString();
|
119
|
+
carry = Math.floor(d / 10);
|
120
|
+
i -= 1;
|
121
|
+
}
|
122
|
+
|
123
|
+
// 处理最高位进位
|
124
|
+
var result = '';
|
125
|
+
if (carry > 0) result = '1';
|
126
|
+
|
127
|
+
// 重建数字字符串
|
128
|
+
for (var j = 0; j < digits.length; j++) {
|
129
|
+
// 插入小数点
|
130
|
+
if (j === dotPos && precision > 0) result += '.';
|
131
|
+
// 只添加到所需精度
|
132
|
+
if (j < dotPos || j < dotPos + precision) {
|
133
|
+
result += digits[j];
|
134
|
+
}
|
135
|
+
}
|
136
|
+
return result;
|
137
|
+
}
|
138
|
+
|
139
|
+
/**
|
140
|
+
* 格式化数字字符串到指定小数位
|
141
|
+
* @param {string} value 数字字符串
|
142
|
+
* @param {number} precision 小数位数
|
143
|
+
* @returns {string} 格式化后的字符串
|
144
|
+
* @example
|
145
|
+
* console.log(preciseString('111111111111111.888', 2)) // "111111111111111.89"
|
146
|
+
* console.log(preciseString('9.999', 2)) // "10.00"
|
147
|
+
*/
|
148
|
+
export var preciseString = function preciseString(value) {
|
149
|
+
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1;
|
150
|
+
// 如果不是数字字符串,则返回原值
|
151
|
+
if (!/^-?\d+(\.\d+)?$/.test(value)) {
|
152
|
+
return value;
|
153
|
+
}
|
154
|
+
|
155
|
+
// 如果不需要格式化精度,直接返回
|
156
|
+
if (precision < 0) return value;
|
157
|
+
|
158
|
+
// 分离整数和小数部分
|
159
|
+
var parts = value.split('.');
|
160
|
+
var intPart = parts[0];
|
161
|
+
var decimalPart = parts[1] || '';
|
162
|
+
|
163
|
+
// 截断或补零
|
164
|
+
if (decimalPart.length > precision) {
|
165
|
+
// 需要四舍五入
|
166
|
+
if (precision < decimalPart.length && parseInt(decimalPart[precision], 10) >= 5) {
|
167
|
+
// 手动实现字符串层面的四舍五入
|
168
|
+
return roundString("".concat(intPart, ".").concat(decimalPart), precision);
|
169
|
+
}
|
170
|
+
return intPart + (precision > 0 ? ".".concat(decimalPart.slice(0, precision)) : '');
|
171
|
+
}
|
172
|
+
return intPart + (precision > 0 ? ".".concat(decimalPart.padEnd(precision, '0')) : '');
|
173
|
+
};
|
package/esm/utils/object.d.ts
CHANGED
@@ -45,5 +45,11 @@ export declare const getAllKeyPaths: (obj: ObjectType, parentKey?: string) => st
|
|
45
45
|
* console.log(completeFields) // ['user', 'user.name', 'user.age', 'user[0].name', 'user[0].age', 'user[1].name', 'user[1].age']
|
46
46
|
*/
|
47
47
|
export declare const getCompleteFieldKeys: (fields: string | string[], allFields: string[]) => string[];
|
48
|
+
/**
|
49
|
+
* 将对象中的所有值设置为空, 如果值是数组,重置为空数组,如果是对象,重置为空对象,如果是基础类型,重置为undefined
|
50
|
+
* @param obj 对象
|
51
|
+
* @returns 空对象
|
52
|
+
*/
|
53
|
+
export declare const clearValue: (obj: ObjectType) => any;
|
48
54
|
export {};
|
49
55
|
//# sourceMappingURL=object.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAGvC;AASD,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAGD,eAAO,MAAM,YAAY,QAAS,UAAU,UAG3C,CAAC;AAGF,eAAO,MAAM,SAAS,2CAEZ,UAAU,YACT,WAAW,eAwBrB,CAAC;AAEF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,+DA4BxC;AAED,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,OAAO,WACV,UAAU,QACZ,MAAM,SACL,GAAG,YACD,cAAc,eAiDxB,CAAC;AAEF,eAAO,MAAM,OAAO,WAAY,UAAU,QAAQ,MAAM,YAAW,WAAW,YAyB7E,CAAC;AAEF,eAAO,MAAM,UAAU,WAAY,UAAU,QAAQ,MAAM,eA0B1D,CAAC;AAEF,eAAO,MAAM,OAAO,WAAY,UAAU,QAAQ,MAAM,YAavD,CAAC;AAEF,eAAO,MAAM,OAAO,QAAS,UAAU,YAItC,CAAC;AAEF,eAAO,MAAM,WAAW,wFAQvB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,QAAS,UAAU,cAAa,MAAM,KAAQ,MAAM,EAoB9E,CAAC;AAGF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,WAAY,MAAM,GAAG,MAAM,EAAE,aAAa,MAAM,EAAE,KAAG,MAAM,EAmB3F,CAAA"}
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAGvC;AASD,UAAU,WAAW;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAGD,eAAO,MAAM,YAAY,QAAS,UAAU,UAG3C,CAAC;AAGF,eAAO,MAAM,SAAS,2CAEZ,UAAU,YACT,WAAW,eAwBrB,CAAC;AAEF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,+DA4BxC;AAED,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,OAAO,WACV,UAAU,QACZ,MAAM,SACL,GAAG,YACD,cAAc,eAiDxB,CAAC;AAEF,eAAO,MAAM,OAAO,WAAY,UAAU,QAAQ,MAAM,YAAW,WAAW,YAyB7E,CAAC;AAEF,eAAO,MAAM,UAAU,WAAY,UAAU,QAAQ,MAAM,eA0B1D,CAAC;AAEF,eAAO,MAAM,OAAO,WAAY,UAAU,QAAQ,MAAM,YAavD,CAAC;AAEF,eAAO,MAAM,OAAO,QAAS,UAAU,YAItC,CAAC;AAEF,eAAO,MAAM,WAAW,wFAQvB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,QAAS,UAAU,cAAa,MAAM,KAAQ,MAAM,EAoB9E,CAAC;AAGF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,WAAY,MAAM,GAAG,MAAM,EAAE,aAAa,MAAM,EAAE,KAAG,MAAM,EAmB3F,CAAA;AAGD;;;;GAIG;AACH,eAAO,MAAM,UAAU,QAAS,UAAU,KAAG,GAW5C,CAAC"}
|
package/esm/utils/object.js
CHANGED
@@ -325,4 +325,24 @@ export var getCompleteFieldKeys = function getCompleteFieldKeys(fields, allField
|
|
325
325
|
|
326
326
|
// 返回之前去重
|
327
327
|
return Array.from(new Set(completeFields));
|
328
|
+
};
|
329
|
+
|
330
|
+
/**
|
331
|
+
* 将对象中的所有值设置为空, 如果值是数组,重置为空数组,如果是对象,重置为空对象,如果是基础类型,重置为undefined
|
332
|
+
* @param obj 对象
|
333
|
+
* @returns 空对象
|
334
|
+
*/
|
335
|
+
export var clearValue = function clearValue(obj) {
|
336
|
+
if (isArray(obj)) {
|
337
|
+
return obj.map(function (item) {
|
338
|
+
return clearValue(item);
|
339
|
+
});
|
340
|
+
}
|
341
|
+
if (isObject(obj)) {
|
342
|
+
return Object.keys(obj).reduce(function (acc, key) {
|
343
|
+
acc[key] = clearValue(obj[key]);
|
344
|
+
return acc;
|
345
|
+
}, {});
|
346
|
+
}
|
347
|
+
return undefined;
|
328
348
|
};
|
@@ -4,5 +4,6 @@ interface Column {
|
|
4
4
|
}
|
5
5
|
export declare function compareColumns(columns1?: Column[], columns2?: Column[]): boolean;
|
6
6
|
export declare function shallowEqual(objA: any, objB?: any, options?: {}): boolean;
|
7
|
+
export declare function shallowEqualExceptFalsely(objA: any, objB?: any, options?: {}): boolean;
|
7
8
|
export default shallowEqual;
|
8
9
|
//# sourceMappingURL=shallow-equal.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"shallow-equal.d.ts","sourceRoot":"","sources":["shallow-equal.ts"],"names":[],"mappings":"AAqBA,UAAU,MAAM;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AACD,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,WActE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,KAAK,WAyC/D;AAED,eAAe,YAAY,CAAC"}
|
1
|
+
{"version":3,"file":"shallow-equal.d.ts","sourceRoot":"","sources":["shallow-equal.ts"],"names":[],"mappings":"AAqBA,UAAU,MAAM;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AACD,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,WActE;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,KAAK,WAyC/D;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,KAAK,WAO5E;AAED,eAAe,YAAY,CAAC"}
|
@@ -65,4 +65,12 @@ export function shallowEqual(objA, objB) {
|
|
65
65
|
}
|
66
66
|
return true;
|
67
67
|
}
|
68
|
+
export function shallowEqualExceptFalsely(objA, objB) {
|
69
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
70
|
+
var falselys = [false, 0, '', null, undefined, NaN];
|
71
|
+
if (falselys.includes(objA) && falselys.includes(objB)) {
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
return shallowEqual(objA, objB, options);
|
75
|
+
}
|
68
76
|
export default shallowEqual;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sheinx/hooks",
|
3
|
-
"version": "3.8.0-beta.
|
3
|
+
"version": "3.8.0-beta.31",
|
4
4
|
"description": "",
|
5
5
|
"keywords": [],
|
6
6
|
"license": "MIT",
|
@@ -18,8 +18,8 @@
|
|
18
18
|
"immer": "10.0.2"
|
19
19
|
},
|
20
20
|
"peerDependencies": {
|
21
|
-
"react": ">=16.
|
22
|
-
"react-dom": ">=16.
|
21
|
+
"react": ">=16.14.0",
|
22
|
+
"react-dom": ">=16.14.0",
|
23
23
|
"core-js": ">=3"
|
24
24
|
},
|
25
25
|
"repository": {
|