@sheinx/hooks 3.6.0-beta.3 → 3.6.0-beta.30

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.
Files changed (173) hide show
  1. package/cjs/common/use-filter/use-filter.d.ts.map +1 -1
  2. package/cjs/common/use-pagination-list/index.d.ts.map +1 -1
  3. package/cjs/common/use-pagination-list/index.js +6 -1
  4. package/cjs/common/use-position-style/check-border.d.ts +6 -0
  5. package/cjs/common/use-position-style/check-border.d.ts.map +1 -0
  6. package/cjs/common/use-position-style/check-border.js +35 -0
  7. package/cjs/common/use-position-style/get-position-style.d.ts +1 -0
  8. package/cjs/common/use-position-style/get-position-style.d.ts.map +1 -1
  9. package/cjs/common/use-position-style/get-position-style.js +14 -8
  10. package/cjs/common/use-position-style/index.d.ts +1 -0
  11. package/cjs/common/use-position-style/index.d.ts.map +1 -1
  12. package/cjs/common/use-position-style/index.js +21 -10
  13. package/cjs/components/use-cascader/use-cascader.d.ts.map +1 -1
  14. package/cjs/components/use-cascader/use-cascader.type.d.ts +2 -1
  15. package/cjs/components/use-cascader/use-cascader.type.d.ts.map +1 -1
  16. package/cjs/components/use-check/use-check.d.ts +1 -1
  17. package/cjs/components/use-check/use-check.d.ts.map +1 -1
  18. package/cjs/components/use-check/use-check.js +10 -3
  19. package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  20. package/cjs/components/use-datepicker/use-datepicker-format.js +4 -0
  21. package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts +1 -1
  22. package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
  23. package/cjs/components/use-form/Provider.d.ts +1 -2
  24. package/cjs/components/use-form/Provider.d.ts.map +1 -1
  25. package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  26. package/cjs/components/use-form/use-form-fieldset/fieldset-context.d.ts +1 -1
  27. package/cjs/components/use-form/use-form-fieldset/fieldset-context.d.ts.map +1 -1
  28. package/cjs/components/use-form/use-form-fieldset/fieldset-context.js +3 -2
  29. package/cjs/components/use-form/use-form-fieldset/index.d.ts +1 -0
  30. package/cjs/components/use-form/use-form-fieldset/index.d.ts.map +1 -1
  31. package/cjs/components/use-form/use-form-fieldset/index.js +6 -0
  32. package/cjs/components/use-form/use-form.d.ts +1 -2
  33. package/cjs/components/use-form/use-form.d.ts.map +1 -1
  34. package/cjs/components/use-form/use-form.js +19 -9
  35. package/cjs/components/use-form/use-form.type.d.ts +3 -1
  36. package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
  37. package/cjs/components/use-input/use-input-format.d.ts +1 -1
  38. package/cjs/components/use-input/use-input-format.d.ts.map +1 -1
  39. package/cjs/components/use-input/use-input-format.js +12 -4
  40. package/cjs/components/use-input/use-input-number.d.ts +1 -1
  41. package/cjs/components/use-input/use-input-number.d.ts.map +1 -1
  42. package/cjs/components/use-input/use-input-number.js +1 -0
  43. package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
  44. package/cjs/components/use-popup/use-popup.js +5 -0
  45. package/cjs/components/use-table/index.d.ts +2 -1
  46. package/cjs/components/use-table/index.d.ts.map +1 -1
  47. package/cjs/components/use-table/index.js +7 -0
  48. package/cjs/components/use-table/use-table-filter.d.ts +19 -0
  49. package/cjs/components/use-table/use-table-filter.d.ts.map +1 -0
  50. package/cjs/components/use-table/use-table-filter.js +96 -0
  51. package/cjs/components/use-table/use-table-tree.d.ts +13 -0
  52. package/cjs/components/use-table/use-table-tree.d.ts.map +1 -1
  53. package/cjs/components/use-table/use-table-tree.js +68 -1
  54. package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
  55. package/cjs/components/use-table/use-table-virtual.js +6 -4
  56. package/cjs/components/use-table/use-table.type.d.ts +93 -0
  57. package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
  58. package/cjs/components/use-tabs/context.d.ts +1 -1
  59. package/cjs/components/use-tabs/context.d.ts.map +1 -1
  60. package/cjs/components/use-tabs/use-tabs.d.ts +1 -1
  61. package/cjs/components/use-tree/index.d.ts +3 -2
  62. package/cjs/components/use-tree/index.d.ts.map +1 -1
  63. package/cjs/components/use-tree/index.js +18 -2
  64. package/cjs/components/use-tree/use-tree-node.d.ts.map +1 -1
  65. package/cjs/components/use-tree/use-tree-node.js +1 -5
  66. package/cjs/components/use-tree/use-tree-node.type.d.ts +18 -0
  67. package/cjs/components/use-tree/use-tree-node.type.d.ts.map +1 -1
  68. package/cjs/components/use-tree/use-tree-virtual-node.d.ts +13 -0
  69. package/cjs/components/use-tree/use-tree-virtual-node.d.ts.map +1 -0
  70. package/cjs/components/use-tree/use-tree-virtual-node.js +92 -0
  71. package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
  72. package/cjs/components/use-tree/use-tree.js +236 -18
  73. package/cjs/components/use-tree/use-tree.type.d.ts +35 -1
  74. package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
  75. package/cjs/components/use-treeselect/use-tiled.d.ts +1 -1
  76. package/cjs/utils/dom/element.d.ts +1 -1
  77. package/cjs/utils/dom/element.d.ts.map +1 -1
  78. package/cjs/utils/dom/element.js +5 -3
  79. package/cjs/utils/is.d.ts +2 -0
  80. package/cjs/utils/is.d.ts.map +1 -1
  81. package/cjs/utils/is.js +5 -2
  82. package/cjs/utils/lazyload.d.ts.map +1 -1
  83. package/cjs/utils/lazyload.js +2 -2
  84. package/cjs/utils/object.d.ts.map +1 -1
  85. package/cjs/utils/object.js +6 -1
  86. package/cjs/utils/warning.js +5 -5
  87. package/esm/common/use-filter/use-filter.d.ts.map +1 -1
  88. package/esm/common/use-pagination-list/index.d.ts.map +1 -1
  89. package/esm/common/use-pagination-list/index.js +6 -1
  90. package/esm/common/use-position-style/check-border.d.ts +6 -0
  91. package/esm/common/use-position-style/check-border.d.ts.map +1 -0
  92. package/esm/common/use-position-style/check-border.js +29 -0
  93. package/esm/common/use-position-style/get-position-style.d.ts +1 -0
  94. package/esm/common/use-position-style/get-position-style.d.ts.map +1 -1
  95. package/esm/common/use-position-style/get-position-style.js +14 -8
  96. package/esm/common/use-position-style/index.d.ts +1 -0
  97. package/esm/common/use-position-style/index.d.ts.map +1 -1
  98. package/esm/common/use-position-style/index.js +21 -10
  99. package/esm/components/use-cascader/use-cascader.d.ts.map +1 -1
  100. package/esm/components/use-cascader/use-cascader.type.d.ts +2 -1
  101. package/esm/components/use-cascader/use-cascader.type.d.ts.map +1 -1
  102. package/esm/components/use-check/use-check.d.ts +1 -1
  103. package/esm/components/use-check/use-check.d.ts.map +1 -1
  104. package/esm/components/use-check/use-check.js +10 -3
  105. package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  106. package/esm/components/use-datepicker/use-datepicker-format.js +4 -0
  107. package/esm/components/use-datepicker/use-datepicker-format.type.d.ts +1 -1
  108. package/esm/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
  109. package/esm/components/use-form/Provider.d.ts +1 -2
  110. package/esm/components/use-form/Provider.d.ts.map +1 -1
  111. package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  112. package/esm/components/use-form/use-form-fieldset/fieldset-context.d.ts +1 -1
  113. package/esm/components/use-form/use-form-fieldset/fieldset-context.d.ts.map +1 -1
  114. package/esm/components/use-form/use-form-fieldset/fieldset-context.js +2 -1
  115. package/esm/components/use-form/use-form-fieldset/index.d.ts +1 -0
  116. package/esm/components/use-form/use-form-fieldset/index.d.ts.map +1 -1
  117. package/esm/components/use-form/use-form-fieldset/index.js +2 -1
  118. package/esm/components/use-form/use-form.d.ts +1 -2
  119. package/esm/components/use-form/use-form.d.ts.map +1 -1
  120. package/esm/components/use-form/use-form.js +19 -9
  121. package/esm/components/use-form/use-form.type.d.ts +3 -1
  122. package/esm/components/use-form/use-form.type.d.ts.map +1 -1
  123. package/esm/components/use-input/use-input-format.d.ts +1 -1
  124. package/esm/components/use-input/use-input-format.d.ts.map +1 -1
  125. package/esm/components/use-input/use-input-format.js +12 -4
  126. package/esm/components/use-input/use-input-number.d.ts +1 -1
  127. package/esm/components/use-input/use-input-number.d.ts.map +1 -1
  128. package/esm/components/use-input/use-input-number.js +1 -0
  129. package/esm/components/use-popup/use-popup.d.ts.map +1 -1
  130. package/esm/components/use-popup/use-popup.js +5 -0
  131. package/esm/components/use-table/index.d.ts +2 -1
  132. package/esm/components/use-table/index.d.ts.map +1 -1
  133. package/esm/components/use-table/index.js +1 -0
  134. package/esm/components/use-table/use-table-filter.d.ts +19 -0
  135. package/esm/components/use-table/use-table-filter.d.ts.map +1 -0
  136. package/esm/components/use-table/use-table-filter.js +89 -0
  137. package/esm/components/use-table/use-table-tree.d.ts +13 -0
  138. package/esm/components/use-table/use-table-tree.d.ts.map +1 -1
  139. package/esm/components/use-table/use-table-tree.js +67 -0
  140. package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
  141. package/esm/components/use-table/use-table-virtual.js +6 -4
  142. package/esm/components/use-table/use-table.type.d.ts +93 -0
  143. package/esm/components/use-table/use-table.type.d.ts.map +1 -1
  144. package/esm/components/use-tabs/context.d.ts +1 -1
  145. package/esm/components/use-tabs/context.d.ts.map +1 -1
  146. package/esm/components/use-tabs/use-tabs.d.ts +1 -1
  147. package/esm/components/use-tree/index.d.ts +3 -2
  148. package/esm/components/use-tree/index.d.ts.map +1 -1
  149. package/esm/components/use-tree/index.js +3 -2
  150. package/esm/components/use-tree/use-tree-node.d.ts.map +1 -1
  151. package/esm/components/use-tree/use-tree-node.js +1 -5
  152. package/esm/components/use-tree/use-tree-node.type.d.ts +18 -0
  153. package/esm/components/use-tree/use-tree-node.type.d.ts.map +1 -1
  154. package/esm/components/use-tree/use-tree-virtual-node.d.ts +13 -0
  155. package/esm/components/use-tree/use-tree-virtual-node.d.ts.map +1 -0
  156. package/esm/components/use-tree/use-tree-virtual-node.js +85 -0
  157. package/esm/components/use-tree/use-tree.d.ts.map +1 -1
  158. package/esm/components/use-tree/use-tree.js +238 -20
  159. package/esm/components/use-tree/use-tree.type.d.ts +35 -1
  160. package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
  161. package/esm/components/use-treeselect/use-tiled.d.ts +1 -1
  162. package/esm/utils/dom/element.d.ts +1 -1
  163. package/esm/utils/dom/element.d.ts.map +1 -1
  164. package/esm/utils/dom/element.js +4 -2
  165. package/esm/utils/is.d.ts +2 -0
  166. package/esm/utils/is.d.ts.map +1 -1
  167. package/esm/utils/is.js +4 -1
  168. package/esm/utils/lazyload.d.ts.map +1 -1
  169. package/esm/utils/lazyload.js +3 -3
  170. package/esm/utils/object.d.ts.map +1 -1
  171. package/esm/utils/object.js +6 -1
  172. package/esm/utils/warning.js +5 -5
  173. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- declare const FieldsetContext: React.Context<{
2
+ export declare const FieldsetContext: React.Context<{
3
3
  path: string;
4
4
  validateFieldSet: () => void;
5
5
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"fieldset-context.d.ts","sourceRoot":"","sources":["fieldset-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,QAAA,MAAM,eAAe;;;EAA0D,CAAC;AAEhF,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB;AAiBD,eAAO,MAAM,mBAAmB;;;;CAe/B,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"fieldset-context.d.ts","sourceRoot":"","sources":["fieldset-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,eAAO,MAAM,eAAe;;;EAA0D,CAAC;AAGvF,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB;AAiBD,eAAO,MAAM,mBAAmB;;;;CAe/B,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -7,10 +7,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
7
7
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
8
8
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9
9
  import React, { createContext } from 'react';
10
- var FieldsetContext = /*#__PURE__*/createContext({
10
+ export var FieldsetContext = /*#__PURE__*/createContext({
11
11
  path: '',
12
12
  validateFieldSet: function validateFieldSet() {}
13
13
  });
14
+ FieldsetContext.displayName = 'FieldsetContext';
14
15
  function extendName() {
15
16
  var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
16
17
  var name = arguments.length > 1 ? arguments[1] : undefined;
@@ -1,4 +1,5 @@
1
1
  export { default as useFormFieldSet, default } from './use-form-fieldset';
2
2
  export { useFieldSetConsumer } from './fieldset-context';
3
+ export { FieldsetContext } from './fieldset-context';
3
4
  export type { BaseFormFieldSetProps } from './use-form-fieldset.type';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD,YAAY,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD,YAAY,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1,3 +1,4 @@
1
1
  "use client";
2
2
  export { default as useFormFieldSet, default } from "./use-form-fieldset";
3
- export { useFieldSetConsumer } from "./fieldset-context";
3
+ export { useFieldSetConsumer } from "./fieldset-context";
4
+ export { FieldsetContext } from "./fieldset-context";
@@ -1,9 +1,8 @@
1
- /// <reference types="react" />
2
1
  import { ProviderProps, UseFormProps, UseFormSlotProps, ValidateFnConfig } from './use-form.type';
3
2
  import { ObjectType } from '../../common/type';
4
3
  declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
5
4
  getFormProps: <TOther extends ObjectType = ObjectType>(externalProps?: TOther) => UseFormSlotProps<TOther>;
6
- Provider: (props: ProviderProps) => JSX.Element;
5
+ Provider: (props: ProviderProps) => import("react/jsx-runtime").JSX.Element;
7
6
  ProviderProps: {
8
7
  formValue: import("./use-form.type").FormContextValueType;
9
8
  formConfig: import("./use-form.type").FormCommonConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AA+BA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBA8QC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;aAAE;8BAjJd,MAAM;oCAoND,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA/KxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCAiPvB,MAAM,WAAW,gBAAgB;gCA/CzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAzHpD,MAA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5LxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCA8PvB,MAAM,WAAW,gBAAgB;4BA/CzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAnIpD,MAAM,0BAAyB,qBAAqB;;CAma9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -44,7 +44,6 @@ var useForm = function useForm(props) {
44
44
  forceSet: true
45
45
  };
46
46
  var preValue = usePrevious(props.value);
47
- var formDomRef = React.useRef();
48
47
  var _React$useRef = React.useRef({
49
48
  defaultValues: {},
50
49
  validateMap: {},
@@ -118,9 +117,9 @@ var useForm = function useForm(props) {
118
117
  onError === null || onError === void 0 || onError(err);
119
118
  if (!props.scrollToError) return;
120
119
  setTimeout(function () {
121
- var _formDomRef$current;
120
+ var _props$formElRef$curr;
122
121
  var selector = "[".concat(getDataAttributeName('status'), "=\"error\"]");
123
- var el = (_formDomRef$current = formDomRef.current) === null || _formDomRef$current === void 0 ? void 0 : _formDomRef$current.querySelector(selector);
122
+ var el = (_props$formElRef$curr = props.formElRef.current) === null || _props$formElRef$curr === void 0 ? void 0 : _props$formElRef$curr.querySelector(selector);
124
123
  if (el) {
125
124
  el.scrollIntoView();
126
125
  var focusableSelectors = 'textarea, input,[tabindex]:not([tabindex="-1"])';
@@ -154,7 +153,7 @@ var useForm = function useForm(props) {
154
153
  return new Promise(function (resolve, reject) {
155
154
  var finalFields = Object.keys(context.validateMap);
156
155
  if (fields) {
157
- if (config.ignoreChildren) {
156
+ if (config.ignoreChildren || config.ignoreBind) {
158
157
  // 旧行为:仅校验当前字段
159
158
  finalFields = (isArray(fields) ? fields : [fields]).filter(function (key) {
160
159
  return context.validateMap[key];
@@ -173,6 +172,7 @@ var useForm = function useForm(props) {
173
172
  }
174
173
  var validates = finalFields.map(function (key) {
175
174
  var validateField = context.validateMap[key];
175
+ if (!validateField) return [];
176
176
  return Array.from(validateField).map(function (validate) {
177
177
  return validate(key, deepGet(context.value, key), context.value, config);
178
178
  });
@@ -243,10 +243,20 @@ var useForm = function useForm(props) {
243
243
  var isVisibleX = elementRect.left >= parentRect.left && elementRect.right <= parentRect.right;
244
244
  if (!isVisibleY || !isVisibleX) {
245
245
  // 计算元素相对于父元素的偏移量
246
- var offsetTop = element.offsetTop - parentEl.offsetTop;
247
- var offsetLeft = element.offsetLeft - parentEl.offsetLeft;
248
- parentEl.scrollTop = offsetTop;
249
- parentEl.scrollLeft = offsetLeft;
246
+ var offsetTop = elementRect.top - parentRect.top;
247
+ var offsetLeft = elementRect.left - parentRect.left;
248
+ // 如果是往上滚动,那么只有当元素的偏移量小于0时才需要滚动
249
+ if (offsetTop < 0) {
250
+ parentEl.scrollTop = Math.max(parentEl.scrollTop + offsetTop, 0);
251
+ } else {
252
+ parentEl.scrollTop = Math.min(parentEl.scrollTop + offsetTop, parentEl.scrollHeight - parentEl.clientHeight);
253
+ }
254
+ // 如果是往左滚动,那么只有当元素的偏移量小于0时才需要滚动
255
+ if (offsetLeft < 0) {
256
+ parentEl.scrollLeft = Math.max(parentEl.scrollLeft + offsetLeft, 0);
257
+ } else {
258
+ parentEl.scrollLeft = Math.min(parentEl.scrollLeft + offsetLeft, parentEl.scrollWidth - parentEl.clientWidth);
259
+ }
250
260
  }
251
261
  } else {
252
262
  // 如果没有找到可滚动的父元素,使用默认行为
@@ -450,7 +460,6 @@ var useForm = function useForm(props) {
450
460
  var externalProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
451
461
  var externalEventHandlers = extractEventHandlers(externalProps);
452
462
  return _objectSpread(_objectSpread(_objectSpread({}, externalProps), externalEventHandlers), {}, {
453
- ref: formDomRef,
454
463
  disabled: !!disabled,
455
464
  onSubmit: handleSubmit(externalEventHandlers),
456
465
  onReset: handleReset(externalEventHandlers)
@@ -496,6 +505,7 @@ var useForm = function useForm(props) {
496
505
  }
497
506
  if (validateFieldSet.size === 0 && updateFieldSet.size === 0) {
498
507
  context.names.delete(n);
508
+ delete context.errors[n];
499
509
  delete context.defaultValues[n];
500
510
  }
501
511
  var finalReserveAble = (_props$reserveAble = props.reserveAble) !== null && _props$reserveAble !== void 0 ? _props$reserveAble : reserveAble;
@@ -185,7 +185,9 @@ export interface BaseFormProps<T> extends Omit<FormCommonConfig, 'formName'> {
185
185
  */
186
186
  name?: string;
187
187
  }
188
- export type UseFormProps<T> = BaseFormProps<T>;
188
+ export type UseFormProps<T> = BaseFormProps<T> & {
189
+ formElRef: React.RefObject<HTMLFormElement>;
190
+ };
189
191
  export type FormContext = {
190
192
  defaultValues: ObjectType;
191
193
  validateMap: ObjectType<Set<(name: string, v: any, formValue: ObjectType, config?: {
@@ -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,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE/C,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC;IACV,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB,EAAE,CAAC;CACL;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,CAAC,EAAE,WAAW,GAAG,WAAW,CAAC;IACjC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,UAAU,EACpB,MAAM,CAAC,EAAE,gBAAgB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GAAG,SAAS,CAAC,EACrC,YAAY,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,KACxC,IAAI,CACV,CACF,CAAC;IAEF,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,MAAM,IAAI,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;IACpB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,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"}
@@ -5,7 +5,7 @@ declare const useInputFormat: (props: InputFormatProps) => {
5
5
  onBlur: (e: React.FocusEvent) => void;
6
6
  onFocus: (e: React.FocusEvent) => void;
7
7
  value: string | undefined;
8
- type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "hidden" | "checkbox" | "radio" | "date" | "datetime-local" | "file" | "month" | "password" | "week" | undefined;
8
+ type: "search" | (string & {}) | "color" | "button" | "time" | "reset" | "submit" | "email" | "url" | "range" | "tel" | "hidden" | "checkbox" | "radio" | "text" | "date" | "datetime-local" | "file" | "image" | "month" | "password" | "week" | undefined;
9
9
  };
10
10
  export default useInputFormat;
11
11
  //# sourceMappingURL=use-input-format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-format.d.ts","sourceRoot":"","sources":["use-input-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAM3D,QAAA,MAAM,cAAc,UAAW,gBAAgB;kBAsBP,MAAM,GAAG,SAAS;gBA4BpB,gBAAgB;iBAgDd,gBAAgB;;;CAwBvD,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"use-input-format.d.ts","sourceRoot":"","sources":["use-input-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAM3D,QAAA,MAAM,cAAc,UAAW,gBAAgB;kBAsBP,MAAM,GAAG,SAAS;gBAoCpB,gBAAgB;iBAgDd,gBAAgB;;;CAyBvD,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -21,7 +21,7 @@ var useInputFormat = function useInputFormat(props) {
21
21
  autoFix = props.autoFix,
22
22
  coin = props.coin,
23
23
  cancelBlurChange = props.cancelBlurChange;
24
- var _React$useState = React.useState(false),
24
+ var _React$useState = React.useState(coin),
25
25
  _React$useState2 = _slicedToArray(_React$useState, 2),
26
26
  showCoin = _React$useState2[0],
27
27
  setShowCoin = _React$useState2[1];
@@ -48,6 +48,13 @@ var useInputFormat = function useInputFormat(props) {
48
48
  var noNeg = numType === 'non-negative' || numType === 'positive';
49
49
  var regExp = new RegExp("^(".concat(noNeg ? '' : '-', ")?(\\d").concat(regLength(integerLimit), ")(").concat(digits !== 0 ? "\\.\\d".concat(regLength(digits)) : '', ")?.*$"), 'g');
50
50
  value = value.replace(regExp, '$1$2$3');
51
+
52
+ // 修正小数位数
53
+ var _value = v.split('.');
54
+ var __value = value.split('.');
55
+ if (_value[1] !== undefined && __value[1] === undefined && digits !== 0) {
56
+ value = "".concat(value, ".").concat(_value[1]);
57
+ }
51
58
  }
52
59
  onChange(value);
53
60
  });
@@ -105,14 +112,15 @@ var useInputFormat = function useInputFormat(props) {
105
112
  });
106
113
  function getValue(str) {
107
114
  if (type === 'number' && coin) {
108
- if (showCoin && str) {
109
- return "".concat(str).replace(/\d+/, function (n) {
115
+ var _str = str;
116
+ if (showCoin && _str) {
117
+ return "".concat(_str).replace(/\d+/, function (n) {
110
118
  return n.replace(/(\d)(?=(\d{3})+$)/g, function ($1) {
111
119
  return "".concat($1, ",");
112
120
  });
113
121
  });
114
122
  }
115
- return "".concat(str || '').replace(/,/g, '');
123
+ return "".concat(_str === 0 ? _str : _str || '').replace(/,/g, '');
116
124
  }
117
125
  return str;
118
126
  }
@@ -7,7 +7,7 @@ declare const useNumberFormat: (props: InputNumberProps) => {
7
7
  onBlur: (e: React.FocusEvent<Element, Element>) => void;
8
8
  onFocus: (e: React.FocusEvent<Element, Element>) => void;
9
9
  value: string | undefined;
10
- type: "search" | "color" | "button" | "time" | "image" | "text" | "reset" | "submit" | "email" | "url" | "range" | "tel" | (string & {}) | "hidden" | "checkbox" | "radio" | "date" | "datetime-local" | "file" | "month" | "password" | "week" | undefined;
10
+ type: "search" | (string & {}) | "color" | "button" | "time" | "reset" | "submit" | "email" | "url" | "range" | "tel" | "hidden" | "checkbox" | "radio" | "text" | "date" | "datetime-local" | "file" | "image" | "month" | "password" | "week" | undefined;
11
11
  };
12
12
  export default useNumberFormat;
13
13
  //# sourceMappingURL=use-input-number.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;CAuJ/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;CAwJ/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -66,6 +66,7 @@ var useNumberFormat = function useNumberFormat(props) {
66
66
  var onInnerChange = usePersistFn(function (val) {
67
67
  setInternalInputValue(getStringValue(val));
68
68
  if (typeof val === 'string') {
69
+ if (val.endsWith('.')) return;
69
70
  var num = parseFloat(val);
70
71
  if (val === '') {
71
72
  // 如果允许空值,则返回 null,否则返回 undefined
@@ -1 +1 @@
1
- {"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOhE,QAAA,MAAM,QAAQ,UAAW,cAAc;;;;;;;0BAyHK;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;0BAM9B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;qBA5B7B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;;;;;;;;;;;;;;;;;;;;;2BA6ElD,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;6BAGxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;;CAsBpE,CAAC;AAEF,eAAe,QAAQ,CAAC"}
1
+ {"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOhE,QAAA,MAAM,QAAQ,UAAW,cAAc;;;;;;;0BA8HK;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;0BAM9B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;qBA5B7B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;;;;;;;;;;;;;;;;;;;;;2BA6ElD,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;6BAGxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;;CAsBpE,CAAC;AAEF,eAAe,QAAQ,CAAC"}
@@ -72,6 +72,11 @@ var usePopup = function usePopup(props) {
72
72
  updatePosition();
73
73
  }
74
74
  setOpenState(!!props.open);
75
+
76
+ // 外部传了open时,需要正常的触发onCollapse;触发了onCollapse才能让组件内部的edit状态正确,否则可能会出现弹出层打开了但是用户却无法选择的情况
77
+ if (props.open !== undefined) {
78
+ changeOpen(!!props.open);
79
+ }
75
80
  }, [props.open]);
76
81
 
77
82
  // const getPopUpHeight = () => {
@@ -2,9 +2,10 @@ export { default, default as useTableLayout } from './use-table-layout';
2
2
  export { default as useTableColumns } from './use-table-columns';
3
3
  export { default as useTableGroup } from './use-table-group';
4
4
  export { default as useTableSort } from './use-table-sort';
5
+ export { default as useTableFilter } from './use-table-filter';
5
6
  export { default as useTableRow } from './use-table-row';
6
7
  export { default as useTableExpand } from './use-table-expand';
7
8
  export { default as useTableTree } from './use-table-tree';
8
9
  export { default as useTableVirtual } from './use-table-virtual';
9
- export type { TableFormatColumn, TableColumnItem, TableHeadColumn, TableGroupColumn, TableSorterInfo, BaseTableProps, } from './use-table.type';
10
+ export type { TableFormatColumn, TableColumnItem, TableHeadColumn, TableGroupColumn, TableSorterInfo, BaseTableProps, TableColumnFilter, TableFilterData, } from './use-table.type';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,M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f,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,kBAAkB,CAAC"}
@@ -3,6 +3,7 @@ export { default, default as useTableLayout } from "./use-table-layout";
3
3
  export { default as useTableColumns } from "./use-table-columns";
4
4
  export { default as useTableGroup } from "./use-table-group";
5
5
  export { default as useTableSort } from "./use-table-sort";
6
+ export { default as useTableFilter } from "./use-table-filter";
6
7
  export { default as useTableRow } from "./use-table-row";
7
8
  export { default as useTableExpand } from "./use-table-expand";
8
9
  export { default as useTableTree } from "./use-table-tree";
@@ -0,0 +1,19 @@
1
+ /// <reference types="react" />
2
+ import { TableColumnItem, BaseTableProps } from './use-table.type';
3
+ import { KeygenResult } from '../../common/type';
4
+ export interface UseTableFilterProps<Item = any> extends Pick<BaseTableProps<Item>, 'onSortCancel' | 'sorter' | 'data'> {
5
+ columns?: TableColumnItem<Item>[];
6
+ }
7
+ export interface FilterInfo<T> {
8
+ value?: any;
9
+ onFilter?: (value: any, row: T) => boolean;
10
+ }
11
+ export type FilterMap<T> = Map<KeygenResult, FilterInfo<T>>;
12
+ declare const useTableFilter: <Item = any>(props: UseTableFilterProps<Item>) => {
13
+ filterInfo: FilterMap<Item>;
14
+ setFilterInfo: import("react").Dispatch<import("react").SetStateAction<FilterMap<Item>>>;
15
+ filteredData: Item[] | undefined;
16
+ onFilterChange: (columnKey: KeygenResult, value: any) => void;
17
+ };
18
+ export default useTableFilter;
19
+ //# sourceMappingURL=use-table-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-table-filter.d.ts","sourceRoot":"","sources":["use-table-filter.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,mBAAmB,CAAC,IAAI,GAAG,GAAG,CAC7C,SAAQ,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,cAAc,GAAG,QAAQ,GAAG,MAAM,CAAC;IACtE,OAAO,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;CACnC;AACD,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC;CAC5C;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5D,QAAA,MAAM,cAAc;;;;gCA6BH,YAAY,SAAS,GAAG;CAoDxC,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -0,0 +1,89 @@
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); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ 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."); }
9
+ 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); }
10
+ 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; }
11
+ 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; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import { useState, useMemo, useEffect } from 'react';
14
+ import usePersistFn from "../../common/use-persist-fn";
15
+ import { isFunc } from "../../utils/is";
16
+ var useTableFilter = function useTableFilter(props) {
17
+ var _useState = useState(new Map()),
18
+ _useState2 = _slicedToArray(_useState, 2),
19
+ filterInfo = _useState2[0],
20
+ setFilterInfo = _useState2[1];
21
+ var activeFilters = useMemo(function () {
22
+ return Array.from(filterInfo.keys()).filter(function (key) {
23
+ var _filterInfo$get;
24
+ return ((_filterInfo$get = filterInfo.get(key)) === null || _filterInfo$get === void 0 ? void 0 : _filterInfo$get.value) !== undefined;
25
+ });
26
+ }, [filterInfo]);
27
+ var filteredData = useMemo(function () {
28
+ var _props$data;
29
+ if (activeFilters.length === 0) return props.data;
30
+ return (_props$data = props.data) === null || _props$data === void 0 ? void 0 : _props$data.filter(function (item) {
31
+ return activeFilters.every(function (key) {
32
+ var filter = filterInfo.get(key);
33
+ if ((filter === null || filter === void 0 ? void 0 : filter.value) === undefined) return true;
34
+ if (Array.isArray(filter.value) && filter.value.length === 0) return true;
35
+ if (filter !== null && filter !== void 0 && filter.onFilter && isFunc(filter.onFilter)) {
36
+ return filter.onFilter(filter.value, item);
37
+ }
38
+ return true;
39
+ });
40
+ });
41
+ }, [activeFilters, props.data]);
42
+ var onFilterChange = usePersistFn(function (columnKey, value) {
43
+ // TODO: 暂未开放reset全部筛选条件
44
+ if (columnKey === '__reset__') {
45
+ setFilterInfo(function (prev) {
46
+ var next = new Map(prev);
47
+ next.forEach(function (v, k) {
48
+ next.set(k, _objectSpread(_objectSpread({}, v), {}, {
49
+ value: undefined
50
+ }));
51
+ });
52
+ return next;
53
+ });
54
+ } else {
55
+ setFilterInfo(function (prev) {
56
+ var _prev$get;
57
+ var next = new Map(prev);
58
+ next.set(columnKey, {
59
+ value: value,
60
+ onFilter: (_prev$get = prev.get(columnKey)) === null || _prev$get === void 0 ? void 0 : _prev$get.onFilter
61
+ });
62
+ return next;
63
+ });
64
+ }
65
+ });
66
+
67
+ // 根据columns生成filterInfo
68
+ useEffect(function () {
69
+ var _props$columns;
70
+ var _filterInfo = props === null || props === void 0 || (_props$columns = props.columns) === null || _props$columns === void 0 ? void 0 : _props$columns.reduce(function (acc, column, index) {
71
+ var _column$filter;
72
+ if (!column.filter) return acc;
73
+ var columnKey = typeof column.render === 'string' ? column.render : String(index);
74
+ acc.set(columnKey, {
75
+ value: undefined,
76
+ onFilter: (_column$filter = column.filter) === null || _column$filter === void 0 ? void 0 : _column$filter.onFilter
77
+ });
78
+ return acc;
79
+ }, new Map());
80
+ if (_filterInfo) setFilterInfo(_filterInfo);
81
+ }, [props.columns]);
82
+ return {
83
+ filterInfo: filterInfo,
84
+ setFilterInfo: setFilterInfo,
85
+ filteredData: filteredData,
86
+ onFilterChange: onFilterChange
87
+ };
88
+ };
89
+ export default useTableFilter;
@@ -1,5 +1,18 @@
1
1
  import type { BaseTableProps } from './use-table.type';
2
2
  import { OptionalToRequired } from '../../common/type';
3
+ type treeDataInfoType = {
4
+ id: string | number;
5
+ level: number;
6
+ data: any;
7
+ pid: null | string | number;
8
+ };
9
+ interface GetExpandDataVirtualResult {
10
+ treeData: any[];
11
+ treeExpandLevel: Map<any, number>;
12
+ unmatchExpandKeys: (string | number)[];
13
+ treeDataInfo: treeDataInfoType[];
14
+ }
15
+ export declare const getExpandVirtualData: (_treeData: any[], keys: (string | number)[], keygen: any, treeColumnsName?: string) => GetExpandDataVirtualResult;
3
16
  export interface UseTableTreeProps extends Pick<OptionalToRequired<BaseTableProps<any>>, 'onTreeExpand' | 'treeExpandKeys' | 'defaultTreeExpandKeys' | 'keygen'> {
4
17
  treeColumnsName: string | undefined;
5
18
  data: any[];
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-tree.d.ts","sourceRoot":"","sources":["use-table-tree.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AA+CvD,MAAM,WAAW,iBACf,SAAQ,IAAI,CACV,kBAAkB,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EACvC,cAAc,GAAG,gBAAgB,GAAG,uBAAuB,GAAG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AAiB;;;;;;+BA6BR,GAAG,SAAS,MAAM;iCAjBhB,GAAG,SAAS,MAAM;;CA4DhE,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -54,6 +54,73 @@ var getExpandData = function getExpandData(_treeData, keys, keygen, treeColumnsN
54
54
  unmatchExpandKeys: unmatchExpandKeys
55
55
  };
56
56
  };
57
+ export var getExpandVirtualData = function getExpandVirtualData(_treeData, keys, keygen, treeColumnsName) {
58
+ var expandKeys = keys;
59
+ var expandSet = new Set(expandKeys);
60
+ var unmatchExpandKeys = [];
61
+ var treeExpandLevel = new Map();
62
+ if (expandSet.size === 0 || !treeColumnsName) {
63
+ var _treeDataInfo = _treeData.map(function (item, index) {
64
+ return {
65
+ id: getKey(keygen, item, index),
66
+ level: 1,
67
+ data: item,
68
+ pid: null
69
+ };
70
+ });
71
+ return {
72
+ treeData: _treeData,
73
+ treeExpandLevel: treeExpandLevel,
74
+ unmatchExpandKeys: unmatchExpandKeys,
75
+ treeDataInfo: _treeDataInfo
76
+ };
77
+ }
78
+ var treeData = _toConsumableArray(_treeData || []);
79
+ var treeDataInfo = treeData.map(function (item) {
80
+ return {
81
+ id: getKey(keygen, item),
82
+ level: 1,
83
+ data: item,
84
+ pid: null
85
+ };
86
+ });
87
+ var _loop2 = function _loop2() {
88
+ if (expandSet.size === 0) return 1; // break
89
+ var item = treeData[i];
90
+ var key = getKey(keygen, item, i);
91
+ var parentLevel = treeExpandLevel.get(key) || 0;
92
+ var children = isObject(item) && item[treeColumnsName];
93
+ if (expandSet.has(key)) {
94
+ if (children && children.length > 0) {
95
+ var nodes = [];
96
+ children.forEach(function (child) {
97
+ var node = {
98
+ id: getKey(keygen, child),
99
+ level: parentLevel + 2,
100
+ data: child,
101
+ pid: key
102
+ };
103
+ nodes.push(node);
104
+ treeExpandLevel.set(getKey(keygen, child), parentLevel + 1);
105
+ });
106
+ treeData.splice.apply(treeData, [i + 1, 0].concat(_toConsumableArray(children)));
107
+ treeDataInfo.splice.apply(treeDataInfo, [i + 1, 0].concat(nodes));
108
+ expandSet.delete(key);
109
+ } else {
110
+ unmatchExpandKeys.push(key);
111
+ }
112
+ }
113
+ };
114
+ for (var i = 0; i < treeData.length; i++) {
115
+ if (_loop2()) break;
116
+ }
117
+ return {
118
+ treeData: treeData,
119
+ treeExpandLevel: treeExpandLevel,
120
+ unmatchExpandKeys: unmatchExpandKeys,
121
+ treeDataInfo: treeDataInfo
122
+ };
123
+ };
57
124
  export var useTableTree = function useTableTree(props) {
58
125
  var _useState = useState(props.defaultTreeExpandKeys || []),
59
126
  _useState2 = _slicedToArray(_useState, 2),
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAWrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;CAC3C;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAuMpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAnGuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BA+JnB,MAAM,aAAa,MAAM,IAAI;qCAoBnB,MAAM;mCAWR,MAAM,GAAG,MAAM;CAyFnE,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAWrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;IAClC,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;CAC3C;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAuMpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAnGuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BA+JnB,MAAM,aAAa,MAAM,IAAI;qCAoBnB,MAAM;mCAWR,MAAM,GAAG,MAAM;CA2FnE,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -163,7 +163,7 @@ var useTableVirtual = function useTableVirtual(props) {
163
163
  });
164
164
  }
165
165
  });
166
- var updateIndexAndTopFromTop = function updateIndexAndTopFromTop(scrollTop) {
166
+ var updateIndexAndTopFromTop = function updateIndexAndTopFromTop(scrollTop, fromDrag) {
167
167
  var _props$scrollRef$curr;
168
168
  if (props.disabled) return;
169
169
  var sum = 0;
@@ -203,7 +203,7 @@ var useTableVirtual = function useTableVirtual(props) {
203
203
  setStartIndex(currentIndex);
204
204
 
205
205
  // startIndex处于上方某个合并行的中间一行时,可能引起translate闪烁
206
- if (startIndex < currentIndex) {
206
+ if (rowSpanInfo && !fromDrag && startIndex < currentIndex) {
207
207
  context.autoAddRows = currentIndex - startIndex;
208
208
  setTimeout(function () {
209
209
  context.autoAddRows = 0;
@@ -263,7 +263,7 @@ var useTableVirtual = function useTableVirtual(props) {
263
263
  // 拖动滚动条
264
264
  if (fromDrag) {
265
265
  var top = y * max;
266
- updateIndexAndTopFromTop(top);
266
+ updateIndexAndTopFromTop(top, fromDrag);
267
267
  if (context.rateTimer) clearTimeout(context.rateTimer);
268
268
  context.rateTimer = setTimeout(function () {
269
269
  updateRateScroll(y);
@@ -365,8 +365,10 @@ var useTableVirtual = function useTableVirtual(props) {
365
365
  if (props.disabled) return;
366
366
  if (context.heightCallback) {
367
367
  var cb = context.heightCallback;
368
- context.heightCallback = null;
369
368
  cb();
369
+ setTimeout(function () {
370
+ context.heightCallback = null;
371
+ }, 300);
370
372
  }
371
373
  }, [scrollHeight]);
372
374
  var finalRowsInView = rowsInView + context.rowSpanRows + context.autoAddRows;