@sheinx/hooks 3.6.0-beta.8 → 3.6.0-fix.1
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-input-able/use-Input-able.d.ts.map +1 -1
- package/cjs/common/use-input-able/use-Input-able.js +6 -7
- package/cjs/common/use-pagination-list/index.d.ts.map +1 -1
- package/cjs/common/use-pagination-list/index.js +6 -1
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +7 -3
- package/cjs/components/use-check/use-check.d.ts +1 -1
- package/cjs/components/use-check/use-check.d.ts.map +1 -1
- package/cjs/components/use-check/use-check.js +10 -3
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.js +4 -0
- package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
- package/cjs/components/use-form/Provider.d.ts +1 -2
- package/cjs/components/use-form/Provider.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-control/use-form-control.js +2 -3
- package/cjs/components/use-form/use-form-fieldset/fieldset-context.d.ts +1 -1
- package/cjs/components/use-form/use-form-fieldset/fieldset-context.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-fieldset/fieldset-context.js +3 -2
- package/cjs/components/use-form/use-form-fieldset/index.d.ts +1 -0
- package/cjs/components/use-form/use-form-fieldset/index.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-fieldset/index.js +6 -0
- package/cjs/components/use-form/use-form.d.ts +1 -2
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +20 -11
- package/cjs/components/use-form/use-form.type.d.ts +5 -3
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-format.d.ts +1 -1
- package/cjs/components/use-input/use-input-number.d.ts +1 -1
- package/cjs/components/use-input/use-input-number.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-number.js +1 -0
- package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
- package/cjs/components/use-popup/use-popup.js +5 -0
- package/cjs/components/use-table/index.d.ts +2 -1
- package/cjs/components/use-table/index.d.ts.map +1 -1
- package/cjs/components/use-table/index.js +7 -0
- package/cjs/components/use-table/use-table-filter.d.ts +19 -0
- package/cjs/components/use-table/use-table-filter.d.ts.map +1 -0
- package/cjs/components/use-table/use-table-filter.js +96 -0
- package/cjs/components/use-table/use-table.type.d.ts +93 -0
- package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
- package/cjs/components/use-tabs/context.d.ts +1 -1
- package/cjs/components/use-tabs/context.d.ts.map +1 -1
- package/cjs/components/use-tabs/use-tabs.d.ts +1 -1
- package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree.js +58 -13
- package/cjs/components/use-tree/use-tree.type.d.ts +4 -0
- package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
- package/cjs/components/use-treeselect/use-tiled.d.ts +1 -1
- package/cjs/utils/dom/element.d.ts +1 -1
- package/cjs/utils/dom/element.d.ts.map +1 -1
- package/cjs/utils/dom/element.js +5 -3
- package/cjs/utils/lazyload.d.ts.map +1 -1
- package/cjs/utils/lazyload.js +2 -2
- package/esm/common/use-input-able/use-Input-able.d.ts.map +1 -1
- package/esm/common/use-input-able/use-Input-able.js +7 -8
- package/esm/common/use-pagination-list/index.d.ts.map +1 -1
- package/esm/common/use-pagination-list/index.js +6 -1
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +7 -3
- package/esm/components/use-check/use-check.d.ts +1 -1
- package/esm/components/use-check/use-check.d.ts.map +1 -1
- package/esm/components/use-check/use-check.js +10 -3
- package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.js +4 -0
- package/esm/components/use-datepicker/use-datepicker-format.type.d.ts +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
- package/esm/components/use-form/Provider.d.ts +1 -2
- package/esm/components/use-form/Provider.d.ts.map +1 -1
- package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/esm/components/use-form/use-form-control/use-form-control.js +2 -3
- package/esm/components/use-form/use-form-fieldset/fieldset-context.d.ts +1 -1
- package/esm/components/use-form/use-form-fieldset/fieldset-context.d.ts.map +1 -1
- package/esm/components/use-form/use-form-fieldset/fieldset-context.js +2 -1
- package/esm/components/use-form/use-form-fieldset/index.d.ts +1 -0
- package/esm/components/use-form/use-form-fieldset/index.d.ts.map +1 -1
- package/esm/components/use-form/use-form-fieldset/index.js +2 -1
- package/esm/components/use-form/use-form.d.ts +1 -2
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +20 -11
- package/esm/components/use-form/use-form.type.d.ts +5 -3
- package/esm/components/use-form/use-form.type.d.ts.map +1 -1
- package/esm/components/use-input/use-input-format.d.ts +1 -1
- package/esm/components/use-input/use-input-number.d.ts +1 -1
- package/esm/components/use-input/use-input-number.d.ts.map +1 -1
- package/esm/components/use-input/use-input-number.js +1 -0
- package/esm/components/use-popup/use-popup.d.ts.map +1 -1
- package/esm/components/use-popup/use-popup.js +5 -0
- package/esm/components/use-table/index.d.ts +2 -1
- package/esm/components/use-table/index.d.ts.map +1 -1
- package/esm/components/use-table/index.js +1 -0
- package/esm/components/use-table/use-table-filter.d.ts +19 -0
- package/esm/components/use-table/use-table-filter.d.ts.map +1 -0
- package/esm/components/use-table/use-table-filter.js +89 -0
- package/esm/components/use-table/use-table.type.d.ts +93 -0
- package/esm/components/use-table/use-table.type.d.ts.map +1 -1
- package/esm/components/use-tabs/context.d.ts +1 -1
- package/esm/components/use-tabs/context.d.ts.map +1 -1
- package/esm/components/use-tabs/use-tabs.d.ts +1 -1
- package/esm/components/use-tree/use-tree.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree.js +58 -13
- package/esm/components/use-tree/use-tree.type.d.ts +4 -0
- package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
- package/esm/components/use-treeselect/use-tiled.d.ts +1 -1
- package/esm/utils/dom/element.d.ts +1 -1
- package/esm/utils/dom/element.d.ts.map +1 -1
- package/esm/utils/dom/element.js +4 -2
- package/esm/utils/lazyload.d.ts.map +1 -1
- package/esm/utils/lazyload.js +3 -3
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
17
17
|
*/
|
|
18
18
|
import React from 'react';
|
|
19
19
|
import { extractEventHandlers } from "../../utils";
|
|
20
|
+
import { util } from "../..";
|
|
20
21
|
import useForkRef from "../../common/use-fork-ref";
|
|
21
22
|
var useCheck = function useCheck(props) {
|
|
22
23
|
var checked = props.checked,
|
|
@@ -37,9 +38,12 @@ var useCheck = function useCheck(props) {
|
|
|
37
38
|
};
|
|
38
39
|
var inputRef = React.useRef(null);
|
|
39
40
|
var handleInputRef = useForkRef(inputRef, inputRefPo);
|
|
40
|
-
var handleClick = function handleClick(otherHandlers) {
|
|
41
|
+
var handleClick = function handleClick(otherHandlers, needStopPropagation) {
|
|
41
42
|
return function (event) {
|
|
42
43
|
var _inputRef$current, _otherHandlers$onClic;
|
|
44
|
+
if (needStopPropagation) {
|
|
45
|
+
event.stopPropagation();
|
|
46
|
+
}
|
|
43
47
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.click();
|
|
44
48
|
otherHandlers === null || otherHandlers === void 0 || (_otherHandlers$onClic = otherHandlers.onClick) === null || _otherHandlers$onClic === void 0 || _otherHandlers$onClic.call(otherHandlers, event);
|
|
45
49
|
};
|
|
@@ -47,8 +51,10 @@ var useCheck = function useCheck(props) {
|
|
|
47
51
|
var getRootProps = function getRootProps() {
|
|
48
52
|
var externalProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
49
53
|
var externalEventHandlers = extractEventHandlers(externalProps);
|
|
50
|
-
return _objectSpread(_objectSpread({}, externalProps
|
|
51
|
-
|
|
54
|
+
return _objectSpread(_objectSpread({}, util.removeProps(externalProps, {
|
|
55
|
+
needStopPropagation: true
|
|
56
|
+
})), {}, {
|
|
57
|
+
onClick: handleClick(externalEventHandlers, externalProps.needStopPropagation)
|
|
52
58
|
});
|
|
53
59
|
//封装点击事件 点击触发input 的点击
|
|
54
60
|
// disabled 禁用后不可点击
|
|
@@ -77,6 +83,7 @@ var useCheck = function useCheck(props) {
|
|
|
77
83
|
disabled: disabled
|
|
78
84
|
}, checkProps), {}, {
|
|
79
85
|
onClick: function onClick(e) {
|
|
86
|
+
// TODO: 这个e.stopPropagation生效不了,外部的触发是通过inputRef.current?.click()方式的;没啥用的代码
|
|
80
87
|
e.stopPropagation();
|
|
81
88
|
_onClick === null || _onClick === void 0 || _onClick(e);
|
|
82
89
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-datepicker-format.d.ts","sourceRoot":"","sources":["use-datepicker-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,8BAA8B,CAAC;AAkEtC,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"use-datepicker-format.d.ts","sourceRoot":"","sources":["use-datepicker-format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,EACzB,MAAM,8BAA8B,CAAC;AAkEtC,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;;;0BAuMe,gBAAgB;sCAiEJ,MAAM;iCA7BX,MAAM,SAAS,MAAM;yCAxLrD,OAAO,GAAG,KAAK,GAAG,SAAS,QAAQ,MAAM,UAAU,IAAI,KAAK,OAAO;uCAWvE,MAAM,cAAc,CAAC,IAAI,EAAE,CAAC,QAC3B,MAAM;kBACG,MAAM,SAAS;mBAAS,GAAG;;+BA4CrC,IAAI,YAAY,OAAO,GAAG,KAAK,GAAG,SAAS,gBAAgB,MAAM;;CAwN3E,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
|
@@ -204,6 +204,10 @@ var useDatePickerFormat = function useDatePickerFormat(props) {
|
|
|
204
204
|
if (props.formatResult) {
|
|
205
205
|
if (typeof props.formatResult === 'string') {
|
|
206
206
|
return getFormatValueArr(dateArr, props.formatResult);
|
|
207
|
+
} else if (typeof props.formatResult === 'function') {
|
|
208
|
+
return dateArr.map(function (item) {
|
|
209
|
+
return props.formatResult(item);
|
|
210
|
+
});
|
|
207
211
|
} else {
|
|
208
212
|
return dateArr.map(function (item) {
|
|
209
213
|
if (!item) return '';
|
|
@@ -5,7 +5,7 @@ export type DatePickerModeType = 'year' | 'month' | 'quarter' | 'time' | 'day';
|
|
|
5
5
|
export interface UseDatePickerFormatProps<Value extends DatePickerValueType> {
|
|
6
6
|
type: 'date' | 'datetime' | 'month' | 'time' | 'week' | 'year' | 'quarter';
|
|
7
7
|
format: string | undefined;
|
|
8
|
-
formatResult
|
|
8
|
+
formatResult?: string | ((date?: Date) => string);
|
|
9
9
|
range: boolean | undefined | number;
|
|
10
10
|
value: Value | undefined;
|
|
11
11
|
onChange: ((value: Value extends any[] ? string[] : string, ...args: any) => void) | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-datepicker-format.type.d.ts","sourceRoot":"","sources":["use-datepicker-format.type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAC9D,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG,YAAY,EAAE,CAAC;AAChE,MAAM,MAAM,kBAAkB,GA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AS,GAAG,MAAM,CAAC;IACpC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,SAAS,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC/F,OAAO,EACH;QACE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,GACD,SAAS,CAAC;IACd,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,kBAAkB,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IAClC,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC,cAAc,EAAE,mBAAmB,CAAC;IACpC,cAAc,EACV,CAAC,CACC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,EACvB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,EACnC,IAAI,EAAE,kBAAkB,KACrB,IAAI,CAAC,GACV,SAAS,CAAC;IACd,QAAQ,EACJ,OAAO,GACP,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,OAAO,GAAG,KAAK,EAAE,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,GACvF,KAAK,CAAC,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,GAC1C,SAAS,CAAC;CACf"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { ProviderProps } from './use-form.type';
|
|
3
|
-
export declare const Provider: (props: ProviderProps) => JSX.Element;
|
|
2
|
+
export declare const Provider: (props: ProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
4
3
|
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["Provider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["Provider.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,eAAO,MAAM,QAAQ,UAAW,aAAa,4CAW5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AA0B/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;
|
|
1
|
+
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AA0B/D,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBAiJpC,CAAC,YAAY,GAAG,EAAE;;;;;EAkDrD"}
|
|
@@ -88,7 +88,6 @@ export default function useFormControl(props) {
|
|
|
88
88
|
var formValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
89
89
|
var errors = arguments.length > 1 ? arguments[1] : undefined;
|
|
90
90
|
var severErrors = arguments.length > 2 ? arguments[2] : undefined;
|
|
91
|
-
var names = arguments.length > 3 ? arguments[3] : undefined;
|
|
92
91
|
if (!name) return;
|
|
93
92
|
if (isArray(name)) {
|
|
94
93
|
var _value = getValue(name, formValue);
|
|
@@ -100,7 +99,7 @@ export default function useFormControl(props) {
|
|
|
100
99
|
var dv = isArray(defaultValue) ? defaultValue : [];
|
|
101
100
|
var nextValue = [];
|
|
102
101
|
name.forEach(function (n, index) {
|
|
103
|
-
if (
|
|
102
|
+
if (_value[index] === undefined && dv[index] !== undefined) {
|
|
104
103
|
nextValue[index] = dv[index];
|
|
105
104
|
} else {
|
|
106
105
|
nextValue[index] = _value[index];
|
|
@@ -114,7 +113,7 @@ export default function useFormControl(props) {
|
|
|
114
113
|
setErrorState(_error2);
|
|
115
114
|
}
|
|
116
115
|
if (!shallowEqual(_value2, latestInfo.valueState)) {
|
|
117
|
-
if (
|
|
116
|
+
if (_value2 === undefined && defaultValue !== undefined) {
|
|
118
117
|
setValueState(defaultValue);
|
|
119
118
|
} else {
|
|
120
119
|
setValueState(_value2);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fieldset-context.d.ts","sourceRoot":"","sources":["fieldset-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,
|
|
1
|
+
{"version":3,"file":"fieldset-context.d.ts","sourceRoot":"","sources":["fieldset-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAE7C,eAAO,MAAM,eAAe;;;EAA0D,CAAC;AAGvF,UAAU,cAAc;IACtB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACzB;AAiBD,eAAO,MAAM,mBAAmB;;;;CAe/B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -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;
|
|
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,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":"
|
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AA+BA,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAyRC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;aAAE;8BA9Jd,MAAM;oCAiOD,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA5LxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCA8PvB,MAAM,WAAW,gBAAgB;gCA/CzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAnIpD,MAAM,0BAAyB,qBAAqB;;;;;;oBAqEjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE;0BA9Jd,MAAM;gCAiOD,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA5LxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCA8PvB,MAAM,WAAW,gBAAgB;4BA/CzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAnIpD,MAAM,0BAAyB,qBAAqB;;CAma9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -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: {},
|
|
@@ -70,7 +69,7 @@ var useForm = function useForm(props) {
|
|
|
70
69
|
Object.keys(context.updateMap).forEach(function (key) {
|
|
71
70
|
var _context$updateMap$ke;
|
|
72
71
|
(_context$updateMap$ke = context.updateMap[key]) === null || _context$updateMap$ke === void 0 || _context$updateMap$ke.forEach(function (update) {
|
|
73
|
-
update(context.value, context.errors, context.serverErrors
|
|
72
|
+
update(context.value, context.errors, context.serverErrors);
|
|
74
73
|
});
|
|
75
74
|
});
|
|
76
75
|
Object.keys(context.flowMap).forEach(function (key) {
|
|
@@ -88,12 +87,12 @@ var useForm = function useForm(props) {
|
|
|
88
87
|
var _context$updateMap$pa;
|
|
89
88
|
var parentKey = key.split('.')[0];
|
|
90
89
|
(_context$updateMap$pa = context.updateMap[parentKey]) === null || _context$updateMap$pa === void 0 || _context$updateMap$pa.forEach(function (update) {
|
|
91
|
-
update(context.value, context.errors, context.serverErrors
|
|
90
|
+
update(context.value, context.errors, context.serverErrors);
|
|
92
91
|
});
|
|
93
92
|
} else {
|
|
94
93
|
var _context$updateMap$ke2;
|
|
95
94
|
(_context$updateMap$ke2 = context.updateMap[key]) === null || _context$updateMap$ke2 === void 0 || _context$updateMap$ke2.forEach(function (update) {
|
|
96
|
-
update(context.value, context.errors, context.serverErrors
|
|
95
|
+
update(context.value, context.errors, context.serverErrors);
|
|
97
96
|
});
|
|
98
97
|
}
|
|
99
98
|
(_context$flowMap$key = context.flowMap[key]) === null || _context$flowMap$key === void 0 || _context$flowMap$key.forEach(function (update) {
|
|
@@ -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
|
|
120
|
+
var _props$formElRef$curr;
|
|
122
121
|
var selector = "[".concat(getDataAttributeName('status'), "=\"error\"]");
|
|
123
|
-
var el = (
|
|
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"])';
|
|
@@ -244,10 +243,20 @@ var useForm = function useForm(props) {
|
|
|
244
243
|
var isVisibleX = elementRect.left >= parentRect.left && elementRect.right <= parentRect.right;
|
|
245
244
|
if (!isVisibleY || !isVisibleX) {
|
|
246
245
|
// 计算元素相对于父元素的偏移量
|
|
247
|
-
var offsetTop =
|
|
248
|
-
var offsetLeft =
|
|
249
|
-
|
|
250
|
-
|
|
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
|
+
}
|
|
251
260
|
}
|
|
252
261
|
} else {
|
|
253
262
|
// 如果没有找到可滚动的父元素,使用默认行为
|
|
@@ -451,7 +460,6 @@ var useForm = function useForm(props) {
|
|
|
451
460
|
var externalProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
452
461
|
var externalEventHandlers = extractEventHandlers(externalProps);
|
|
453
462
|
return _objectSpread(_objectSpread(_objectSpread({}, externalProps), externalEventHandlers), {}, {
|
|
454
|
-
ref: formDomRef,
|
|
455
463
|
disabled: !!disabled,
|
|
456
464
|
onSubmit: handleSubmit(externalEventHandlers),
|
|
457
465
|
onReset: handleReset(externalEventHandlers)
|
|
@@ -497,6 +505,7 @@ var useForm = function useForm(props) {
|
|
|
497
505
|
}
|
|
498
506
|
if (validateFieldSet.size === 0 && updateFieldSet.size === 0) {
|
|
499
507
|
context.names.delete(n);
|
|
508
|
+
delete context.errors[n];
|
|
500
509
|
delete context.defaultValues[n];
|
|
501
510
|
}
|
|
502
511
|
var finalReserveAble = (_props$reserveAble = props.reserveAble) !== null && _props$reserveAble !== void 0 ? _props$reserveAble : reserveAble;
|
|
@@ -17,7 +17,7 @@ export type ValidateFnConfig = {
|
|
|
17
17
|
ignoreChildren?: boolean;
|
|
18
18
|
};
|
|
19
19
|
export type ValidateFn = (name: string, value: any, formData: ObjectType, config?: ValidateFnConfig) => Promise<true | FormError>;
|
|
20
|
-
export type UpdateFn = (formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined
|
|
20
|
+
export type UpdateFn = (formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>) => void;
|
|
21
21
|
export interface FormContextValueType {
|
|
22
22
|
func?: {
|
|
23
23
|
unbind: (n: string, reserveAble?: boolean, validate?: ValidateFn, update?: UpdateFn) => void;
|
|
@@ -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?: {
|
|
@@ -198,7 +200,7 @@ export type FormContext = {
|
|
|
198
200
|
lastValue: ObjectType | undefined;
|
|
199
201
|
resetTime: number;
|
|
200
202
|
mounted: boolean;
|
|
201
|
-
updateMap: ObjectType<Set<(formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined
|
|
203
|
+
updateMap: ObjectType<Set<(formValue: ObjectType, errors: ObjectType<Error | undefined>, serverErrors: ObjectType<Error | undefined>) => void>>;
|
|
202
204
|
flowMap: ObjectType<Set<() => void>>;
|
|
203
205
|
value: ObjectType;
|
|
204
206
|
errors: ObjectType<Error | undefined>;
|
|
@@ -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,O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IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,UAAU,GAAG,SAAS,CAAC;IAElC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IAEjB,SAAS,EAAE,UAAU,CACnB,GAAG,CACD,CACE,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,UAAU,CAAC,KAAK,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" |
|
|
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
|
|
@@ -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" |
|
|
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;;;;;;;;
|
|
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;;;;;;;
|
|
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,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEjE,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,cAAc,
|
|
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,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEjE,YAAY,EACV,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,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;
|