@sheinx/hooks 3.2.0-rc.4 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. package/cjs/common/use-click-away/index.d.ts.map +1 -1
  2. package/cjs/common/use-click-away/index.js +4 -1
  3. package/cjs/common/use-transform/use-transform.d.ts.map +1 -1
  4. package/cjs/common/use-transform/use-transform.js +1 -0
  5. package/cjs/components/use-button/use-button.js +1 -1
  6. package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts +1 -1
  7. package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
  8. package/cjs/components/use-form/use-form-flow/use-form-datum.js +13 -1
  9. package/cjs/components/use-form/use-form.d.ts.map +1 -1
  10. package/cjs/components/use-form/use-form.js +10 -3
  11. package/cjs/components/use-menu/use-menu-item.d.ts +1 -0
  12. package/cjs/components/use-menu/use-menu-item.d.ts.map +1 -1
  13. package/cjs/components/use-menu/use-menu-item.js +44 -36
  14. package/cjs/components/use-menu/use-menu.d.ts.map +1 -1
  15. package/cjs/components/use-menu/use-menu.js +12 -2
  16. package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
  17. package/cjs/components/use-tree/use-tree.js +20 -14
  18. package/cjs/components/use-tree/use-tree.type.d.ts +3 -1
  19. package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
  20. package/cjs/components/use-upload/use-upload.d.ts.map +1 -1
  21. package/cjs/components/use-upload/use-upload.js +16 -18
  22. package/cjs/utils/rule/rule.type.d.ts +1 -1
  23. package/cjs/utils/rule/rule.type.d.ts.map +1 -1
  24. package/cjs/utils/validate/get-rule.d.ts.map +1 -1
  25. package/cjs/utils/validate/get-rule.js +2 -1
  26. package/esm/common/use-click-away/index.d.ts.map +1 -1
  27. package/esm/common/use-click-away/index.js +4 -1
  28. package/esm/common/use-transform/use-transform.d.ts.map +1 -1
  29. package/esm/common/use-transform/use-transform.js +1 -0
  30. package/esm/components/use-button/use-button.js +1 -1
  31. package/esm/components/use-form/use-form-flow/use-form-datum.d.ts +1 -1
  32. package/esm/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
  33. package/esm/components/use-form/use-form-flow/use-form-datum.js +13 -1
  34. package/esm/components/use-form/use-form.d.ts.map +1 -1
  35. package/esm/components/use-form/use-form.js +10 -3
  36. package/esm/components/use-menu/use-menu-item.d.ts +1 -0
  37. package/esm/components/use-menu/use-menu-item.d.ts.map +1 -1
  38. package/esm/components/use-menu/use-menu-item.js +44 -36
  39. package/esm/components/use-menu/use-menu.d.ts.map +1 -1
  40. package/esm/components/use-menu/use-menu.js +12 -2
  41. package/esm/components/use-tree/use-tree.d.ts.map +1 -1
  42. package/esm/components/use-tree/use-tree.js +20 -14
  43. package/esm/components/use-tree/use-tree.type.d.ts +3 -1
  44. package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
  45. package/esm/components/use-upload/use-upload.d.ts.map +1 -1
  46. package/esm/components/use-upload/use-upload.js +16 -18
  47. package/esm/utils/rule/rule.type.d.ts +1 -1
  48. package/esm/utils/rule/rule.type.d.ts.map +1 -1
  49. package/esm/utils/validate/get-rule.d.ts.map +1 -1
  50. package/esm/utils/validate/get-rule.js +2 -1
  51. package/package.json +1 -1
@@ -53,7 +53,7 @@ var useButton = function useButton() {
53
53
  return mergedEventHandlers;
54
54
  };
55
55
  return {
56
- disabled: disabled,
56
+ disabled: disabled || loading,
57
57
  getAnchorProps: getAnchorProps,
58
58
  getButtonProps: getButtonProps,
59
59
  getSpaceChildren: getSpaceChildren
@@ -1,7 +1,7 @@
1
1
  export interface FormDatum {
2
2
  set: (vals: {
3
3
  [name: string]: any;
4
- }) => void;
4
+ } | string, value?: any) => void;
5
5
  get: (name?: string) => any;
6
6
  }
7
7
  declare const useFormDatum: () => FormDatum | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"use-form-datum.d.ts","sourceRoot":"","sources":["use-form-datum.tsx"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,CAAC,IAAI,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,KAAK,IAAI,CAAC;IAC7C,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;CAC7B;AACD,QAAA,MAAM,YAAY,6BAQjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"use-form-datum.d.ts","sourceRoot":"","sources":["use-form-datum.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,CAAC,IAAI,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACnE,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;CAC7B;AAED,QAAA,MAAM,YAAY,6BAgBjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,9 +1,21 @@
1
+ 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; }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
3
+ 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); }
4
+ 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); }
1
5
  import useLatestObj from "../../../common/use-latest-obj";
6
+ import { usePersistFn } from "../../../common/use-persist-fn";
2
7
  import { useFormFunc } from "../form-func-context";
3
8
  var useFormDatum = function useFormDatum() {
4
9
  var formFunc = useFormFunc();
10
+ var set = usePersistFn(function (vals, value) {
11
+ if (_typeof(vals) === 'object') {
12
+ formFunc === null || formFunc === void 0 || formFunc.setValue(vals);
13
+ } else {
14
+ formFunc === null || formFunc === void 0 || formFunc.setValue(_defineProperty({}, vals, value));
15
+ }
16
+ });
5
17
  var func = useLatestObj({
6
- set: formFunc === null || formFunc === void 0 ? void 0 : formFunc.setValue,
18
+ set: set,
7
19
  get: formFunc === null || formFunc === void 0 ? void 0 : formFunc.getValue
8
20
  });
9
21
  var datum = formFunc ? func : undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAuBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;CAwT7F,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAuBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;CAiU7F,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -48,7 +48,7 @@ var useForm = function useForm(props) {
48
48
  removeArr: new Set(),
49
49
  names: new Set(),
50
50
  submitLock: false,
51
- value: props.value || emptyObj,
51
+ value: deepClone(props.value) || emptyObj,
52
52
  errors: {},
53
53
  serverErrors: {},
54
54
  lastValue: props.value || emptyObj,
@@ -375,6 +375,13 @@ var useForm = function useForm(props) {
375
375
  size: size
376
376
  };
377
377
  }, [labelWidth, labelAlign, labelVerticalAlign, keepErrorHeight, inline, disabled, size]);
378
+ var updateValue = function updateValue() {
379
+ if (props.value !== context.lastValue && props.value !== context.value) {
380
+ context.value = deepClone(props.value) || emptyObj;
381
+ context.lastValue = props.value;
382
+ }
383
+ };
384
+ updateValue();
378
385
  React.useEffect(function () {
379
386
  // 服务端错误更新
380
387
  if (!props.error) context.serverErrors = {};else {
@@ -391,8 +398,8 @@ var useForm = function useForm(props) {
391
398
  // 默认值更新
392
399
  React.useEffect(function () {
393
400
  context.removeLock = false;
394
- if (props.value === context.lastValue) return;
395
- context.value = deepClone(props.value) || emptyObj;
401
+ // 内部 onChange 改的 value, 不需要更新
402
+ if (props.value === context.value) return;
396
403
  if (initValidate && !context.resetTime) {
397
404
  var keys = Object.keys(context.validateMap).filter(function (key) {
398
405
  var oldValue = deepGet(context.lastValue || emptyObj, key);
@@ -11,6 +11,7 @@ declare const useMenuItem: (props: UseMenuItemProps) => {
11
11
  handleMouseEnter: (e: React.MouseEvent) => void;
12
12
  handleMouseLeave: () => void;
13
13
  handleExpandClick: (e: React.MouseEvent) => void;
14
+ isLeaf: boolean;
14
15
  };
15
16
  export default useMenuItem;
16
17
  //# sourceMappingURL=use-menu-item.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-menu-item.d.ts","sourceRoot":"","sources":["use-menu-item.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AAEpE,QAAA,MAAM,WAAW,UAAW,gBAAgB;;;;;;;;yBA4BD,gBAAgB;0BA2Df,gBAAgB;;2BAhCf,gBAAgB;CA6E5D,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"use-menu-item.d.ts","sourceRoot":"","sources":["use-menu-item.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AAEpE,QAAA,MAAM,WAAW,UAAW,gBAAgB;;;;;;;;yBA8BD,gBAAgB;0BA8Df,gBAAgB;;2BAhCf,gBAAgB;;CAgF5D,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -10,15 +10,13 @@ import { getUidStr } from "../../utils/uid";
10
10
  var useMenuItem = function useMenuItem(props) {
11
11
  var _useRef = useRef({
12
12
  id: '',
13
- timer: null,
14
- isUp: false
13
+ timer: null
15
14
  }),
16
15
  context = _useRef.current;
17
16
  var _props$parentId = props.parentId,
18
17
  parentId = _props$parentId === void 0 ? '' : _props$parentId,
19
- dataItem = props.dataItem,
20
- _props$toggleDuration = props.toggleDuration,
21
- toggleDuration = _props$toggleDuration === void 0 ? 200 : _props$toggleDuration;
18
+ dataItem = props.dataItem;
19
+ var isLeaf = ((dataItem || {}).children || []).length === 0;
22
20
  if (!context.id) {
23
21
  context.id = "".concat(parentId, ",").concat(getUidStr());
24
22
  }
@@ -33,6 +31,10 @@ var useMenuItem = function useMenuItem(props) {
33
31
  _useState4 = _slicedToArray(_useState3, 2),
34
32
  isInPath = _useState4[0],
35
33
  setInPath = _useState4[1];
34
+ var _useState5 = useState(false),
35
+ _useState6 = _slicedToArray(_useState5, 2),
36
+ isUp = _useState6[0],
37
+ setIsUp = _useState6[1];
36
38
  var update = usePersistFn(function (getStatus) {
37
39
  var status = getStatus(context.id, props.dataItem);
38
40
  if (isChecked !== status.isChecked) {
@@ -65,8 +67,11 @@ var useMenuItem = function useMenuItem(props) {
65
67
  props.onClick(dataItem);
66
68
  }
67
69
  }
68
- var isLeaf = ((dataItem || {}).children || []).length === 0;
69
- if (!isLeaf) e.nativeEvent.stopImmediatePropagation();
70
+ // 阻止冒泡
71
+ if (!isLeaf) {
72
+ e.stopPropagation();
73
+ e.nativeEvent.stopImmediatePropagation();
74
+ }
70
75
  });
71
76
  var handleExpandClick = usePersistFn(function (e) {
72
77
  e.stopPropagation();
@@ -83,29 +88,29 @@ var useMenuItem = function useMenuItem(props) {
83
88
  }
84
89
  });
85
90
  var handleMouseLeave = usePersistFn(function () {
86
- if (expandAble && props.mode !== 'inline') {
87
- if (context.timer) {
88
- clearTimeout(context.timer);
89
- context.timer = null;
90
- }
91
- context.timer = setTimeout(function () {
92
- props.onOpenChange(function (before) {
93
- var openKeySet = new Set(before);
94
- openKeySet.delete(props.keyResult);
95
- return Array.from(openKeySet);
96
- });
97
- }, toggleDuration);
98
- document.removeEventListener('click', handleMouseLeave);
99
- }
91
+ // if (expandAble && props.mode !== 'inline') {
92
+ // if (context.timer) {
93
+ // clearTimeout(context.timer);
94
+ // context.timer = null;
95
+ // }
96
+ // context.timer = setTimeout(() => {
97
+ // props.onOpenChange((before) => {
98
+ // const openKeySet = new Set(before);
99
+ // openKeySet.delete(props.keyResult);
100
+ // return Array.from(openKeySet);
101
+ // });
102
+ // }, toggleDuration);
103
+ // document.removeEventListener('click', handleMouseLeave);
104
+ // }
100
105
  });
101
106
  var handleMouseEnter = usePersistFn(function (e) {
102
107
  if (expandAble && props.mode !== 'inline') {
103
108
  var _props$scrollRef;
104
- if (context.timer) {
105
- clearTimeout(context.timer);
106
- context.timer = null;
107
- }
108
- var isUp = false;
109
+ // if (context.timer) {
110
+ // clearTimeout(context.timer);
111
+ // context.timer = null;
112
+ // }
113
+ var up = false;
109
114
  if (props.mode === 'vertical-auto' && (_props$scrollRef = props.scrollRef) !== null && _props$scrollRef !== void 0 && _props$scrollRef.current) {
110
115
  var _props$scrollRef$curr;
111
116
  var target = e.currentTarget;
@@ -113,15 +118,17 @@ var useMenuItem = function useMenuItem(props) {
113
118
  var scrollRect = (_props$scrollRef$curr = props.scrollRef.current) === null || _props$scrollRef$curr === void 0 ? void 0 : _props$scrollRef$curr.getBoundingClientRect();
114
119
  var topLine = scrollRect === null || scrollRect === void 0 ? void 0 : scrollRect.top;
115
120
  var bottomLine = scrollRect === null || scrollRect === void 0 ? void 0 : scrollRect.bottom;
116
- isUp = rect.bottom - topLine > (bottomLine - topLine) / 2;
121
+ up = rect.bottom - topLine > (bottomLine - topLine) / 2;
117
122
  }
118
- context.isUp = isUp;
119
- props.onOpenChange(function (before) {
120
- var openKeySet = new Set(before);
121
- openKeySet.add(props.keyResult);
122
- return Array.from(openKeySet);
123
- });
124
- document.addEventListener('click', handleMouseLeave);
123
+ if (isUp !== up) {
124
+ setIsUp(up);
125
+ }
126
+ // props.onOpenChange((before) => {
127
+ // const openKeySet = new Set(before);
128
+ // openKeySet.add(props.keyResult);
129
+ // return Array.from(openKeySet);
130
+ // });
131
+ // document.addEventListener('click', handleMouseLeave);
125
132
  }
126
133
  });
127
134
  useEffect(function () {
@@ -137,11 +144,12 @@ var useMenuItem = function useMenuItem(props) {
137
144
  isOpen: gopenKeySet.has(props.keyResult),
138
145
  isDisabled: isDisabled,
139
146
  expandAble: expandAble,
140
- isUp: context.isUp,
147
+ isUp: isUp,
141
148
  handleItemClick: handleItemClick,
142
149
  handleMouseEnter: handleMouseEnter,
143
150
  handleMouseLeave: handleMouseLeave,
144
- handleExpandClick: handleExpandClick
151
+ handleExpandClick: handleExpandClick,
152
+ isLeaf: isLeaf
145
153
  };
146
154
  };
147
155
  export default useMenuItem;
@@ -1 +1 @@
1
- {"version":3,"file":"use-menu.d.ts","sourceRoot":"","sources":["use-menu.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,QAAA,MAAM,OAAO,UAAW,YAAY;;gCAwBgB,YAAY,EAAE,KAAK,YAAY,EAAE;qBAyC3D,MAAM,cAAc,UAAU;uBAI5B,MAAM;yBA5DS,MAAM;CA0EhD,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"use-menu.d.ts","sourceRoot":"","sources":["use-menu.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,QAAA,MAAM,OAAO,UAAW,YAAY;;gCAyBgB,YAAY,EAAE,KAAK,YAAY,EAAE;qBAkD3D,MAAM,cAAc,UAAU;uBAK5B,MAAM;yBAtES,MAAM;CAqFhD,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -6,7 +6,8 @@ var useMenu = function useMenu(props) {
6
6
  var _useRef = useRef({
7
7
  updateMap: new Map(),
8
8
  activeId: '',
9
- cachedOpenKeys: props.openKeys || []
9
+ cachedOpenKeys: props.openKeys || [],
10
+ updateTimer: 0
10
11
  }),
11
12
  context = _useRef.current;
12
13
  var render = useRender();
@@ -61,14 +62,23 @@ var useMenu = function useMenu(props) {
61
62
  updateItem(getStatus);
62
63
  });
63
64
  });
65
+ var updateWithThreshold = usePersistFn(function () {
66
+ if (context.updateTimer) clearTimeout(context.updateTimer);
67
+ context.updateTimer = window.setTimeout(function () {
68
+ update();
69
+ // 需要更新两次 否则 inPath 状态错误
70
+ update();
71
+ }, 50);
72
+ });
64
73
  var bindUpdate = function bindUpdate(id, updateItem) {
65
74
  context.updateMap.set(id, updateItem);
75
+ updateWithThreshold();
66
76
  };
67
77
  var unbindUpdate = function unbindUpdate(id) {
68
78
  context.updateMap.delete(id);
69
79
  };
70
80
  useEffect(function () {
71
- update();
81
+ updateWithThreshold();
72
82
  });
73
83
  return {
74
84
  openKeys: value,
@@ -1 +1 @@
1
- {"version":3,"file":"use-tree.d.ts","sourceRoot":"","sources":["use-tree.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EAKb,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,eAAO,MAAM,IAAI;IACf;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEJ,CAAC;AAEF,QAAA,MAAM,OAAO;;;;CA6aZ,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"use-tree.d.ts","sourceRoot":"","sources":["use-tree.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EAKb,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AASjD,eAAO,MAAM,IAAI;IACf;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEJ,CAAC;AAEF,QAAA,MAAM,OAAO;;;;CA6aZ,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -9,6 +9,11 @@ import useLatestObj from "../../common/use-latest-obj";
9
9
  import { useInputAble } from "../../common/use-input-able";
10
10
  import { usePersistFn } from "../../common/use-persist-fn";
11
11
  import { isFunc, isString, isNumber, isArray, isUnMatchedData } from "../../utils/is";
12
+ function toArray(value) {
13
+ if (!value) return [];
14
+ if (!Array.isArray(value)) return [value];
15
+ return value;
16
+ }
12
17
  export var MODE = {
13
18
  /**
14
19
  * 返回全选数据,包含父节点和子节点
@@ -68,7 +73,6 @@ var useTree = function useTree(props) {
68
73
  valueMap: new Map(),
69
74
  updateMap: new Map(),
70
75
  unmatchedValueMap: new Map(),
71
- disabled: false,
72
76
  value: undefined,
73
77
  data: [],
74
78
  cachedValue: [],
@@ -158,14 +162,14 @@ var useTree = function useTree(props) {
158
162
  var getPath = function getPath(id) {
159
163
  return context.pathMap.get(id);
160
164
  };
161
- var getDisabled = function getDisabled() {
165
+ var getDisabled = usePersistFn(function () {
162
166
  if (isFunc(disabledProps)) {
163
167
  return disabledProps;
164
168
  }
165
169
  return function () {
166
- return !!disabledProps;
170
+ return false;
167
171
  };
168
- };
172
+ });
169
173
  var getChecked = function getChecked(id) {
170
174
  var value = get(id);
171
175
  var checked = value === 1;
@@ -220,8 +224,8 @@ var useTree = function useTree(props) {
220
224
  // 制作 data mapping
221
225
  context.dataMap.set(id, item);
222
226
  var _isDisabled = !!disabled;
223
- if (_isDisabled === false && isFunc(context.disabled)) {
224
- _isDisabled = context.disabled(item);
227
+ if (_isDisabled === false) {
228
+ _isDisabled = getDisabled()(item);
225
229
  }
226
230
  var indexPath = [].concat(_toConsumableArray(index), [i]);
227
231
  ids.push(id);
@@ -296,16 +300,19 @@ var useTree = function useTree(props) {
296
300
  return checked;
297
301
  };
298
302
  var setValue = function setValue(value) {
299
- context.value = value;
300
- if (value && value !== context.cachedValue) {
303
+ context.value = toArray(value);
304
+ if (value !== context.cachedValue) {
301
305
  initValue();
302
306
  }
303
307
  setUnmatedValue();
304
308
  };
305
309
  var isDisabled = function isDisabled(id) {
306
- var node = context.pathMap.get(id);
307
- if (node) return node.isDisabled;
308
- return false;
310
+ if (isFunc(disabledProps)) {
311
+ var node = context.pathMap.get(id);
312
+ if (node) return node.isDisabled;
313
+ return false;
314
+ }
315
+ return !!disabledProps;
309
316
  };
310
317
  var checkStatusStack = function checkStatusStack(stack, defaultStatus) {
311
318
  if (!stack || stack.length <= 0) return defaultStatus;
@@ -325,10 +332,9 @@ var useTree = function useTree(props) {
325
332
  context.dataMap = new Map();
326
333
  context.valueMap = new Map();
327
334
  context.unmatchedValueMap = new Map();
328
- context.disabled = getDisabled();
329
- context.data = data;
335
+ context.data = toArray(data);
330
336
  if (!data) return;
331
- initData(data, []);
337
+ initData(context.data, []);
332
338
  initValue();
333
339
  setValue(prevValue);
334
340
  };
@@ -9,7 +9,6 @@ export interface TreeContext<DataItem> {
9
9
  unmatchedValueMap: Map<any, any>;
10
10
  updateMap: Map<KeygenResult, UpdateFunc>;
11
11
  forceUpdateMap: Map<KeygenResult, () => void>;
12
- disabled: boolean | ((item: DataItem) => boolean);
13
12
  value?: KeygenResult[];
14
13
  cachedValue: KeygenResult[];
15
14
  data?: DataItem[];
@@ -103,6 +102,9 @@ export interface BaseTreeProps<DataItem> {
103
102
  * @private 保持数据缓存
104
103
  */
105
104
  keepCache?: boolean;
105
+ /**
106
+ * @private 内部数据处理
107
+ */
106
108
  datum?: TreeDatum<DataItem>;
107
109
  }
108
110
  export interface TreeDatum<DataItem> {
@@ -1 +1 @@
1
- {"version":3,"file":"use-tree.type.d.ts","sourceRoot":"","sources":["use-tree.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEpF,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE1C,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE7C,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CA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;IACpB,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,OAAO,EAAE,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IACzC,OAAO,EAAE,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;IACrC,QAAQ,EAAE,GAAG,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;CAChD"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["use-upload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAa,MAAM,mBAAmB,CAAC;AAgC1E,QAAA,MAAM,SAAS;;;;;;0BAyLkB,IAAI,EAAE;yBAqEb,MAAM;6BAqBF,MAAM;8BAqBL,MAAM;;CA2BpC,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["use-upload.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAa,MAAM,mBAAmB,CAAC;AAgC1E,QAAA,MAAM,SAAS;;;;;;0BAuL+B,IAAI,EAAE;yBAqEb,MAAM;6BAqBF,MAAM;8BAqBL,MAAM;;CA2BjD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -165,10 +165,9 @@ var useUpload = function useUpload(props) {
165
165
  });
166
166
  });
167
167
  };
168
- var getCurrent = usePersistFn(function () {
169
- return {
170
- filesState: filesState
171
- };
168
+ var latestState = useLatestObj({
169
+ filesState: filesState,
170
+ value: value
172
171
  });
173
172
  var uploadFile = function uploadFile(id, file, data) {
174
173
  var request = props.request || xhrUpload;
@@ -189,8 +188,7 @@ var useUpload = function useUpload(props) {
189
188
  throttle = false;
190
189
  }, 16);
191
190
  var percent = typeof e.percent === 'number' ? e.percent : e.loaded / e.total * 100;
192
- var _getCurrent = getCurrent(),
193
- filesState = _getCurrent.filesState;
191
+ var filesState = latestState.filesState;
194
192
  var newFiles = _objectSpread({}, filesState);
195
193
  if (!newFiles[id]) return;
196
194
  newFiles[id].process = percent;
@@ -227,7 +225,7 @@ var useUpload = function useUpload(props) {
227
225
  });
228
226
  });
229
227
  // add value
230
- var values = produce(value, function (draft) {
228
+ var values = produce(latestState.value, function (draft) {
231
229
  draft.push(result);
232
230
  });
233
231
  props.onChange(values);
@@ -280,7 +278,7 @@ var useUpload = function useUpload(props) {
280
278
  reader.readAsDataURL(blob);
281
279
  });
282
280
  };
283
- var addFiles = /*#__PURE__*/function () {
281
+ var addFiles = usePersistFn( /*#__PURE__*/function () {
284
282
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(files) {
285
283
  var fileList, newFiles, resetLength, list, _loop, _ret, i;
286
284
  return _regeneratorRuntime().wrap(function _callee2$(_context3) {
@@ -419,11 +417,11 @@ var useUpload = function useUpload(props) {
419
417
  }
420
418
  }, _callee2);
421
419
  }));
422
- return function addFiles(_x3) {
420
+ return function (_x3) {
423
421
  return _ref2.apply(this, arguments);
424
422
  };
425
- }();
426
- var removeFile = function removeFile(id) {
423
+ }());
424
+ var removeFile = usePersistFn(function (id) {
427
425
  var beforeCancel = props.beforeCancel,
428
426
  onErrorRemove = props.onErrorRemove;
429
427
  var file = filesState[id];
@@ -441,8 +439,8 @@ var useUpload = function useUpload(props) {
441
439
  onErrorRemove(file.xhr, file.blob, file);
442
440
  }
443
441
  }
444
- };
445
- var removeValue = function removeValue(index) {
442
+ });
443
+ var removeValue = usePersistFn(function (index) {
446
444
  if (props.disabled) return;
447
445
  var recoverAble = props.recoverAble,
448
446
  beforeRemove = props.beforeRemove;
@@ -454,15 +452,15 @@ var useUpload = function useUpload(props) {
454
452
  newRecycle.push(value[index]);
455
453
  }
456
454
  setRecycleValues(newRecycle);
457
- var newValue = produce(props.value, function (draft) {
455
+ var newValue = produce(latestState.value, function (draft) {
458
456
  draft.splice(index, 1);
459
457
  });
460
458
  props.onChange(newValue);
461
459
  }).catch(function () {});
462
- };
463
- var recoverValue = function recoverValue(index) {
460
+ });
461
+ var recoverValue = usePersistFn(function (index) {
464
462
  if (props.disabled) return;
465
- props.onChange(produce(props.value, function (draft) {
463
+ props.onChange(produce(latestState.value, function (draft) {
466
464
  draft.push(recycleValues[index]);
467
465
  }));
468
466
  setRecycleValues(function (pre) {
@@ -470,7 +468,7 @@ var useUpload = function useUpload(props) {
470
468
  newRecycle.splice(index, 1);
471
469
  return newRecycle;
472
470
  });
473
- };
471
+ });
474
472
  var func = useLatestObj({
475
473
  addFiles: addFiles,
476
474
  removeFile: removeFile,
@@ -105,7 +105,7 @@ export interface RuleFuncResult {
105
105
  export type RuleResult = {
106
106
  [key: string]: RuleFuncResult;
107
107
  } | RuleCommonResult;
108
- export type RuleResultValue = ValueOf<RuleResult>;
108
+ export type RuleResultValue = RuleFuncResult | ValueOf<RuleCommonResult>;
109
109
  export type FormItemObjectRule = Type & RegExpParams & Range & Min & Max & Required & {
110
110
  func?: ValidFunc;
111
111
  args?: any;
@@ -1 +1 @@
1
- {"version":3,"file":"rule.type.d.ts","sourceRoot":"","sources":["rule.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAEpC,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,GAAG;IAChC,CACE,KAAK,EAAE,CAAC,GAAG,SAAS,EACpB,SAAS,EAAE,UAAU,EACrB,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,EAClC,KAAK,EAAE,GAAG,GACT,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACxB;AAED,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AACpG,MAAM,MAAM,WAAW,GAAG,MAAM,G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,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,MAAM,CAAC,EAAE,IAAI,CAAC;IACd,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,CAAC,QAAQ,EAAE,MAAM,GACb;QACE,IAAI,CAAC,EAAE,SAAS,CAAC;QACjB,OAAO,CAAC,EAAE,WAAW,CAAC;KACvB,GACD,SAAS,GACT,SAAS,CAAC;CACf;AAGD,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG;IAAE,gBAAgB,EAAE,IAAI,CAAA;CAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-rule.d.ts","sourceRoot":"","sources":["get-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmB,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAM/C,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAK,EACnC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EACjC,KAAK,EAAE,UAAU,GAChB,SAAS,CAAC,KAAK,CAAC,CAuGlB"}
1
+ {"version":3,"file":"get-rule.d.ts","sourceRoot":"","sources":["get-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmB,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAO/C,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,KAAK,EACnC,IAAI,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EACjC,KAAK,EAAE,UAAU,GAChB,SAAS,CAAC,KAAK,CAAC,CAuGlB"}
@@ -2,6 +2,7 @@ import nullable from "./nullable";
2
2
  import { isEmpty } from "../is";
3
3
  import typeOf from "./type";
4
4
  import { FormError } from "./error";
5
+ import { substitute } from "../string";
5
6
  export default function getRule(rule, props) {
6
7
  var po = props;
7
8
  var rulePo = rule;
@@ -23,7 +24,7 @@ export default function getRule(rule, props) {
23
24
  max: max,
24
25
  args: args
25
26
  });
26
- po.message = typeof message === 'function' ? message(po) : message;
27
+ po.message = typeof message === 'function' ? message(po) : substitute(message, po);
27
28
  var cb = function cb() {};
28
29
  if (func) {
29
30
  cb = function cb(value, formData, callback) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.2.0-rc.4",
3
+ "version": "3.2.0",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",