@kachina/hooks 0.0.1-beta.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.
Files changed (63) hide show
  1. package/README.md +41 -0
  2. package/dist/cjs/Biz/useDictionary/index.d.ts +32 -0
  3. package/dist/cjs/Biz/useDictionary/index.d.ts.map +1 -0
  4. package/dist/cjs/Biz/useDictionary/index.js +66 -0
  5. package/dist/cjs/Biz/useDictionary/services.d.ts +3 -0
  6. package/dist/cjs/Biz/useDictionary/services.d.ts.map +1 -0
  7. package/dist/cjs/Biz/useDictionary/services.js +42 -0
  8. package/dist/cjs/Biz/useQueryList/index.d.ts +13 -0
  9. package/dist/cjs/Biz/useQueryList/index.d.ts.map +1 -0
  10. package/dist/cjs/Biz/useQueryList/index.js +90 -0
  11. package/dist/cjs/Biz/useQueryList/services.d.ts +8 -0
  12. package/dist/cjs/Biz/useQueryList/services.d.ts.map +1 -0
  13. package/dist/cjs/Biz/useQueryList/services.js +47 -0
  14. package/dist/cjs/Biz/useQueryList/utils.d.ts +36 -0
  15. package/dist/cjs/Biz/useQueryList/utils.d.ts.map +1 -0
  16. package/dist/cjs/Biz/useQueryList/utils.js +63 -0
  17. package/dist/cjs/Effect/useOneValidEffect/index.d.ts +9 -0
  18. package/dist/cjs/Effect/useOneValidEffect/index.d.ts.map +1 -0
  19. package/dist/cjs/Effect/useOneValidEffect/index.js +39 -0
  20. package/dist/cjs/Effect/useUpdateEffect/index.d.ts +8 -0
  21. package/dist/cjs/Effect/useUpdateEffect/index.d.ts.map +1 -0
  22. package/dist/cjs/Effect/useUpdateEffect/index.js +36 -0
  23. package/dist/cjs/State/useDialState/index.d.ts +3 -0
  24. package/dist/cjs/State/useDialState/index.d.ts.map +1 -0
  25. package/dist/cjs/State/useDialState/index.js +35 -0
  26. package/dist/cjs/State/useSwitch/index.d.ts +19 -0
  27. package/dist/cjs/State/useSwitch/index.d.ts.map +1 -0
  28. package/dist/cjs/State/useSwitch/index.js +63 -0
  29. package/dist/cjs/index.d.ts +11 -0
  30. package/dist/cjs/index.d.ts.map +1 -0
  31. package/dist/cjs/index.js +54 -0
  32. package/dist/esm/Biz/useDictionary/index.d.ts +32 -0
  33. package/dist/esm/Biz/useDictionary/index.d.ts.map +1 -0
  34. package/dist/esm/Biz/useDictionary/index.js +70 -0
  35. package/dist/esm/Biz/useDictionary/services.d.ts +3 -0
  36. package/dist/esm/Biz/useDictionary/services.d.ts.map +1 -0
  37. package/dist/esm/Biz/useDictionary/services.js +6 -0
  38. package/dist/esm/Biz/useQueryList/index.d.ts +13 -0
  39. package/dist/esm/Biz/useQueryList/index.d.ts.map +1 -0
  40. package/dist/esm/Biz/useQueryList/index.js +129 -0
  41. package/dist/esm/Biz/useQueryList/services.d.ts +8 -0
  42. package/dist/esm/Biz/useQueryList/services.d.ts.map +1 -0
  43. package/dist/esm/Biz/useQueryList/services.js +12 -0
  44. package/dist/esm/Biz/useQueryList/utils.d.ts +36 -0
  45. package/dist/esm/Biz/useQueryList/utils.d.ts.map +1 -0
  46. package/dist/esm/Biz/useQueryList/utils.js +43 -0
  47. package/dist/esm/Effect/useOneValidEffect/index.d.ts +9 -0
  48. package/dist/esm/Effect/useOneValidEffect/index.d.ts.map +1 -0
  49. package/dist/esm/Effect/useOneValidEffect/index.js +25 -0
  50. package/dist/esm/Effect/useUpdateEffect/index.d.ts +8 -0
  51. package/dist/esm/Effect/useUpdateEffect/index.d.ts.map +1 -0
  52. package/dist/esm/Effect/useUpdateEffect/index.js +17 -0
  53. package/dist/esm/State/useDialState/index.d.ts +3 -0
  54. package/dist/esm/State/useDialState/index.d.ts.map +1 -0
  55. package/dist/esm/State/useDialState/index.js +29 -0
  56. package/dist/esm/State/useSwitch/index.d.ts +19 -0
  57. package/dist/esm/State/useSwitch/index.d.ts.map +1 -0
  58. package/dist/esm/State/useSwitch/index.js +56 -0
  59. package/dist/esm/index.d.ts +11 -0
  60. package/dist/esm/index.d.ts.map +1 -0
  61. package/dist/esm/index.js +11 -0
  62. package/dist/umd/hooks.min.js +1 -0
  63. package/package.json +74 -0
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @tankchao/hooks
2
+
3
+ React hooks collection from work experience.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @tankchao/hooks
9
+ # or
10
+ pnpm add @tankchao/hooks
11
+ # or
12
+ yarn add @tankchao/hooks
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ import { useToggle } from '@tankchao/hooks';
19
+
20
+ function App() {
21
+ const [on, toggle, set] = useToggle(false);
22
+ return (
23
+ <div>
24
+ <p>{on ? 'ON' : 'OFF'}</p>
25
+ <button onClick={toggle}>Toggle</button>
26
+ <button onClick={() => set(false)}>Reset</button>
27
+ </div>
28
+ );
29
+ }
30
+ ```
31
+
32
+ ## Hooks
33
+
34
+ | Hook | Description |
35
+ | ----------- | ---------------------------------------------------------------------------------- |
36
+ | `useToggle` | Boolean toggle with initial value, toggle, and set |
37
+ | `useSwitch` | Manage multiple named switches with async open/close callbacks and per-switch data |
38
+
39
+ ## License
40
+
41
+ MIT
@@ -0,0 +1,32 @@
1
+ export interface DictOption {
2
+ label: string;
3
+ value: string | number;
4
+ [key: string]: unknown;
5
+ }
6
+ export type DictRequestItem = {
7
+ /** 字典名称,同时作为返回对象上的属性名 */
8
+ name: string;
9
+ /** 该字典的请求参数 */
10
+ params?: Record<string, unknown>;
11
+ } | string;
12
+ export type DictFetcher = (item: DictRequestItem) => Promise<DictOption[]>;
13
+ export type GetDictLabel = (options: DictOption[] | undefined, value: DictOption['value'] | null | undefined, defaultLabel?: string) => string;
14
+ export type UseDictionaryResult<T extends string = string> = Record<T, DictOption[]> & {
15
+ /** 是否在获取字典 */
16
+ loading: boolean;
17
+ /** 转码函数:根据字典数组、字典码值、默认反显的 label 返回对应 label */
18
+ getLabel: GetDictLabel;
19
+ };
20
+ /**
21
+ * useDictionary
22
+ * 批量请求字典的 hook。
23
+ * @param options 配置项,配置如service请求接口
24
+ * @param dictList 字典配置数组,如 [{ name: '字典1', params: { type: 'xxx' } }]
25
+ * @param deps 依赖数组,用法同 useEffect 的 deps,变化时重新请求
26
+ * @returns 以字典名为属性名的字典数组集合,附带 loading 标识和 getLabel 转码函数
27
+ */
28
+ export declare const useDictionary: <T extends string = string>({ service, }: {
29
+ service: (list: DictRequestItem[]) => Promise<DictOption[][]>;
30
+ }, dictList: DictRequestItem[], deps?: unknown[]) => UseDictionaryResult<T>;
31
+ export declare const useDictionaryDemo: (dictList: DictRequestItem[], deps?: unknown[] | undefined) => UseDictionaryResult<string>;
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Biz/useDictionary/index.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,GAAG,MAAM,CAAA;AAEV,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAE3E,MAAM,MAAM,YAAY,GAAG,CACzB,OAAO,EAAE,UAAU,EAAE,GAAG,SAAS,EACjC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EAC7C,YAAY,CAAC,EAAE,MAAM,KAClB,MAAM,CAAC;AAEZ,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG;IACrF,cAAc;IACd,OAAO,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,QAAQ,EAAE,YAAY,CAAC;CACxB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;oBAIN,eAAe,EAAE,KAAK,QAAQ,UAAU,EAAE,EAAE,CAAC;aAErD,eAAe,EAAE,SACrB,OAAO,EAAE,KACd,oBAAoB,CAAC,CA6BvB,CAAC;AAQF,eAAO,MAAM,iBAAiB,4FAAgE,CAAA"}
@@ -0,0 +1,66 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/Biz/useDictionary/index.ts
20
+ var useDictionary_exports = {};
21
+ __export(useDictionary_exports, {
22
+ useDictionary: () => useDictionary,
23
+ useDictionaryDemo: () => useDictionaryDemo
24
+ });
25
+ module.exports = __toCommonJS(useDictionary_exports);
26
+ var import_react = require("react");
27
+ var import_services = require("./services");
28
+ var useDictionary = ({
29
+ service
30
+ }, dictList, deps = []) => {
31
+ const [dicts, setDicts] = (0, import_react.useState)(() => {
32
+ const map = {};
33
+ dictList.forEach((item) => {
34
+ map[typeof item === "string" ? item : item.name] = [];
35
+ });
36
+ return map;
37
+ });
38
+ const [loading, setLoading] = (0, import_react.useState)(false);
39
+ (0, import_react.useEffect)(() => {
40
+ setLoading(true);
41
+ service(dictList).then((results) => {
42
+ const map = {};
43
+ dictList.forEach((item, index) => {
44
+ map[typeof item === "string" ? item : item.name] = results[index] ?? [];
45
+ });
46
+ setDicts(map);
47
+ setLoading(false);
48
+ }).catch((error) => {
49
+ console.error(error);
50
+ setLoading(false);
51
+ });
52
+ }, deps);
53
+ return { ...dicts, loading, getLabel };
54
+ };
55
+ var getLabel = (options, value, defaultLabel = "") => {
56
+ if (value === null || value === void 0)
57
+ return defaultLabel;
58
+ const target = options == null ? void 0 : options.find((option) => String(option.value) === String(value));
59
+ return target ? target.label : defaultLabel;
60
+ };
61
+ var useDictionaryDemo = useDictionary.bind(null, { service: import_services.queryDictionaryService });
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ useDictionary,
65
+ useDictionaryDemo
66
+ });
@@ -0,0 +1,3 @@
1
+ import { DictRequestItem } from './index';
2
+ export declare const queryDictionaryService: (dictList: DictRequestItem[]) => Promise<any>;
3
+ //# sourceMappingURL=services.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../src/Biz/useDictionary/services.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,eAAO,MAAM,sBAAsB,aAAa,eAAe,EAAE,iBAGhE,CAAA"}
@@ -0,0 +1,42 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/Biz/useDictionary/services.ts
30
+ var services_exports = {};
31
+ __export(services_exports, {
32
+ queryDictionaryService: () => queryDictionaryService
33
+ });
34
+ module.exports = __toCommonJS(services_exports);
35
+ var import_axios = __toESM(require("axios"));
36
+ var queryDictionaryService = (dictList) => {
37
+ return import_axios.default.post("/mockApi/queryDictionaryService", dictList).then((res) => res.data);
38
+ };
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ queryDictionaryService
42
+ });
@@ -0,0 +1,13 @@
1
+ import { DependencyList } from 'react';
2
+ import { Config, DataType } from './utils';
3
+ interface ParamsType {
4
+ api?: string;
5
+ payload?: Record<string, any>;
6
+ validateFields?: () => Promise<Record<string, any>>;
7
+ fieldsHandle?: (params: Record<string, any>) => Record<string, any>;
8
+ listName?: string;
9
+ }
10
+ export declare const useQueryList: <F>(config: Config, params: ParamsType, deps?: DependencyList) => readonly [DataType, (page?: number, pageSize?: number, emptyRows?: boolean) => Promise<boolean>, (selectedRowKeys: any[], selectedRows: any[]) => void, () => void];
11
+ export declare const useQueryListDemo: (params: ParamsType, deps?: DependencyList | undefined) => readonly [DataType, (page?: number, pageSize?: number, emptyRows?: boolean) => Promise<boolean>, (selectedRowKeys: any[], selectedRows: any[]) => void, () => void];
12
+ export {};
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Biz/useQueryList/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,cAAc,EAAE,MAAM,OAAO,CAAC;AAEjD,OAAO,EAAmB,MAAM,EAA0B,QAAQ,EAAE,MAAM,SAAS,CAAC;AAIpF,UAAU,UAAU;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACpD,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AACD,eAAO,MAAM,YAAY,cACb,MAAM,UACN,UAAU,2GAef,QAAQ,OAAO,CAAC,oEAoCtB,CAAA;AAGD,eAAO,MAAM,gBAAgB,4IAvCtB,QAAQ,OAAO,CAAC,oEAuC4D,CAAC"}
@@ -0,0 +1,90 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/Biz/useQueryList/index.ts
30
+ var useQueryList_exports = {};
31
+ __export(useQueryList_exports, {
32
+ useQueryList: () => useQueryList,
33
+ useQueryListDemo: () => useQueryListDemo
34
+ });
35
+ module.exports = __toCommonJS(useQueryList_exports);
36
+ var import_react = require("react");
37
+ var import_useOneValidEffect = __toESM(require("../../Effect/useOneValidEffect"));
38
+ var import_utils = require("./utils");
39
+ var import_services = require("./services");
40
+ var useQueryList = (config, params, deps = [true]) => {
41
+ const { payload = {}, api, validateFields, fieldsHandle, listName } = params;
42
+ const option = (0, import_utils.setDefaultValue)(config);
43
+ const [data, setData] = (0, import_react.useState)((0, import_utils.getInitData)(option));
44
+ const resetData = () => setData((0, import_utils.getInitData)(option));
45
+ (0, import_useOneValidEffect.default)(() => {
46
+ var _a, _b;
47
+ searchData((_a = data == null ? void 0 : data.pagination) == null ? void 0 : _a.current, (_b = data == null ? void 0 : data.pagination) == null ? void 0 : _b.pageSize);
48
+ }, deps);
49
+ const searchData = async (page = ((_a) => (_a = data == null ? void 0 : data.pagination) == null ? void 0 : _a.current)(), pageSize = ((_b) => (_b = data == null ? void 0 : data.pagination) == null ? void 0 : _b.pageSize)(), emptyRows = true) => {
50
+ setData((i) => ({ ...i, loading: true }));
51
+ let queryParams = {
52
+ ...payload,
53
+ [option.page]: page,
54
+ [option.pageSize]: pageSize
55
+ };
56
+ try {
57
+ if (validateFields) {
58
+ const formData = await validateFields();
59
+ Object.assign(queryParams, formData);
60
+ }
61
+ if (fieldsHandle) {
62
+ queryParams = fieldsHandle(queryParams);
63
+ }
64
+ const result = await option.service({ api, payload: queryParams }, { listName: listName || option.listName });
65
+ if (!result)
66
+ throw new Error();
67
+ const { dataList = [], pagination } = result;
68
+ setData((i) => ({
69
+ ...i,
70
+ list: dataList,
71
+ pagination,
72
+ loading: false,
73
+ selectedRowKeys: emptyRows ? [] : i.selectedRowKeys,
74
+ selectedRows: emptyRows ? [] : i.selectedRows
75
+ }));
76
+ return true;
77
+ } catch (error) {
78
+ setData((i) => ({ ...i, loading: false }));
79
+ console.error(error);
80
+ return false;
81
+ }
82
+ };
83
+ return [data, searchData, (0, import_utils.setSelect)(setData), resetData];
84
+ };
85
+ var useQueryListDemo = useQueryList.bind(null, { service: import_services.queryListDemo });
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ useQueryList,
89
+ useQueryListDemo
90
+ });
@@ -0,0 +1,8 @@
1
+ import { ServiceParams, Pagination } from './utils';
2
+ export declare const queryListDemo: ({ api, payload }: ServiceParams, { listName }: {
3
+ listName: string;
4
+ }) => Promise<{
5
+ dataList: Record<string, any>[];
6
+ pagination: Pagination;
7
+ }>;
8
+ //# sourceMappingURL=services.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../src/Biz/useQueryList/services.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,aAAa,qBAAqB,aAAa;cAA4B,MAAM;MAAI,QAAQ;IAAC,QAAQ,EAAE,OAAO,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IAAC,UAAU,EAAE,UAAU,CAAA;CAAC,CAQlK,CAAA"}
@@ -0,0 +1,47 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/Biz/useQueryList/services.ts
30
+ var services_exports = {};
31
+ __export(services_exports, {
32
+ queryListDemo: () => queryListDemo
33
+ });
34
+ module.exports = __toCommonJS(services_exports);
35
+ var import_axios = __toESM(require("axios"));
36
+ var queryListDemo = ({ api, payload }, { listName }) => {
37
+ return import_axios.default.post(api ?? "/queryListDemoService", payload).then((res) => {
38
+ return {
39
+ dataList: res.data[listName],
40
+ pagination: res.data.pagination
41
+ };
42
+ });
43
+ };
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ queryListDemo
47
+ });
@@ -0,0 +1,36 @@
1
+ import { Dispatch } from 'react';
2
+ export interface Pagination {
3
+ total: number;
4
+ pageSize: number;
5
+ current: number;
6
+ }
7
+ export interface ServiceConfige {
8
+ listName: string;
9
+ }
10
+ export type ServiceParams = {
11
+ api?: string;
12
+ payload?: Record<string, any>;
13
+ };
14
+ export interface Config {
15
+ page?: string;
16
+ pageSize?: string;
17
+ pagination?: Pagination;
18
+ listName?: string;
19
+ service?: (params: ServiceParams, { listName }: ServiceConfige) => Promise<{
20
+ dataList: Record<string, any>[];
21
+ pagination: Pagination;
22
+ }>;
23
+ }
24
+ export declare const setDefaultValue: (option: Config) => Required<Config>;
25
+ export interface DataType {
26
+ list: any[];
27
+ selectedRowKeys: string[] | number[];
28
+ selectedRows: any[];
29
+ pagination: Pagination;
30
+ loading: boolean;
31
+ }
32
+ export declare const getInitData: (option: Required<Config>) => DataType;
33
+ type SetData = Dispatch<React.SetStateAction<DataType>>;
34
+ export declare const setSelect: (setData: SetData) => (selectedRowKeys: any[], selectedRows: any[]) => void;
35
+ export {};
36
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/Biz/useQueryList/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,MAAM,WAAW,UAAU;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAC;CACpB;AACD,MAAM,MAAM,aAAa,GAAG;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACjC,CAAA;AAED,MAAM,WAAW,MAAM;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,QAAQ,EAAE,EAAC,cAAc,KAAK,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;QAAC,UAAU,EAAE,UAAU,CAAA;KAAC,CAAC,CAAC;CACxI;AAGD,eAAO,MAAM,eAAe,WAAY,MAAM,KAAG,SAAS,MAAM,CAU/D,CAAA;AAED,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,eAAe,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;IACrC,YAAY,EAAE,GAAG,EAAE,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CACpB;AAGD,eAAO,MAAM,WAAW,WAAY,SAAS,MAAM,CAAC,KAAG,QAQtD,CAAA;AAED,KAAK,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;AAGxD,eAAO,MAAM,SAAS,YAAa,OAAO,uBACb,GAAG,EAAE,gBAAgB,GAAG,EAAE,KAAG,IAOzD,CAAC"}
@@ -0,0 +1,63 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/Biz/useQueryList/utils.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ getInitData: () => getInitData,
23
+ setDefaultValue: () => setDefaultValue,
24
+ setSelect: () => setSelect
25
+ });
26
+ module.exports = __toCommonJS(utils_exports);
27
+ var setDefaultValue = (option) => {
28
+ if (!option.pagination) {
29
+ option.pagination = { total: 0, pageSize: 10, current: 1 };
30
+ }
31
+ if (!option.listName) {
32
+ option.listName = "dataList";
33
+ }
34
+ if (!option.page)
35
+ option.page = "page";
36
+ if (!option.pageSize)
37
+ option.pageSize = "pageSize";
38
+ return option;
39
+ };
40
+ var getInitData = (option) => {
41
+ return {
42
+ list: [],
43
+ selectedRowKeys: [],
44
+ selectedRows: [],
45
+ loading: false,
46
+ pagination: option.pagination
47
+ };
48
+ };
49
+ var setSelect = (setData) => {
50
+ return (selectedRowKeys, selectedRows) => {
51
+ setData((prevState) => ({
52
+ ...prevState,
53
+ selectedRowKeys,
54
+ selectedRows
55
+ }));
56
+ };
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ getInitData,
61
+ setDefaultValue,
62
+ setSelect
63
+ });
@@ -0,0 +1,9 @@
1
+ import { useEffect } from 'react';
2
+ /**
3
+ * useOneValidEffect
4
+ * 用法与 useEffect 完全一致,但只有当依赖数组中所有值的 Boolean 结果都为 true 时,
5
+ * effect 才会执行;且组件整个生命周期内最多执行一次,之后依赖更新不再触发。
6
+ */
7
+ declare const useOneValidEffect: typeof useEffect;
8
+ export default useOneValidEffect;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Effect/useOneValidEffect/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,MAAM,OAAO,CAAC;AAE1C;;;;GAIG;AACH,QAAA,MAAM,iBAAiB,EAAE,OAAO,SAe/B,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/Effect/useOneValidEffect/index.ts
20
+ var useOneValidEffect_exports = {};
21
+ __export(useOneValidEffect_exports, {
22
+ default: () => useOneValidEffect_default
23
+ });
24
+ module.exports = __toCommonJS(useOneValidEffect_exports);
25
+ var import_react = require("react");
26
+ var useOneValidEffect = (effect, deps) => {
27
+ const hasRun = (0, import_react.useRef)(false);
28
+ (0, import_react.useEffect)(() => {
29
+ if (hasRun.current) {
30
+ return;
31
+ }
32
+ if (deps && deps.some((dep) => !dep)) {
33
+ return;
34
+ }
35
+ hasRun.current = true;
36
+ return effect();
37
+ }, deps);
38
+ };
39
+ var useOneValidEffect_default = useOneValidEffect;
@@ -0,0 +1,8 @@
1
+ import { useEffect } from 'react';
2
+ /**
3
+ * useUpdateEffect
4
+ * 用法与 useEffect 完全一致,但跳过首次挂载,只在依赖更新时执行 effect。
5
+ */
6
+ declare const useUpdateEffect: typeof useEffect;
7
+ export default useUpdateEffect;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Effect/useUpdateEffect/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAU,MAAM,OAAO,CAAC;AAE1C;;;GAGG;AACH,QAAA,MAAM,eAAe,EAAE,OAAO,SAU7B,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,36 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/Effect/useUpdateEffect/index.ts
20
+ var useUpdateEffect_exports = {};
21
+ __export(useUpdateEffect_exports, {
22
+ default: () => useUpdateEffect_default
23
+ });
24
+ module.exports = __toCommonJS(useUpdateEffect_exports);
25
+ var import_react = require("react");
26
+ var useUpdateEffect = (effect, deps) => {
27
+ const isMounted = (0, import_react.useRef)(false);
28
+ (0, import_react.useEffect)(() => {
29
+ if (!isMounted.current) {
30
+ isMounted.current = true;
31
+ } else {
32
+ return effect();
33
+ }
34
+ }, deps);
35
+ };
36
+ var useUpdateEffect_default = useUpdateEffect;
@@ -0,0 +1,3 @@
1
+ declare const useDialState: <T>(getValue: () => T, initialValue: T) => [T, () => void];
2
+ export default useDialState;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/State/useDialState/index.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,YAAY,gBAAiB,MAAM,CAAC,gBAAgB,CAAC,KAAG,CAAC,CAAC,EAAE,MAAM,IAAI,CAU3E,CAAA;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/State/useDialState/index.ts
20
+ var useDialState_exports = {};
21
+ __export(useDialState_exports, {
22
+ default: () => useDialState_default
23
+ });
24
+ module.exports = __toCommonJS(useDialState_exports);
25
+ var import_react = require("react");
26
+ var useDialState = (getValue, initialValue) => {
27
+ const [state, setState] = (0, import_react.useState)(initialValue);
28
+ const [flag, setFlag] = (0, import_react.useState)(true);
29
+ const dial = () => setFlag((i) => !i);
30
+ (0, import_react.useEffect)(() => {
31
+ setState(getValue());
32
+ }, [flag]);
33
+ return [state, dial];
34
+ };
35
+ var useDialState_default = useDialState;
@@ -0,0 +1,19 @@
1
+ type Data = Record<string, any> | undefined;
2
+ export type SwitchTarget = {
3
+ [key: `${string}`]: boolean;
4
+ };
5
+ type Item = string | {
6
+ [key: `${string}`]: boolean;
7
+ };
8
+ export type UseSwitchReturn = [
9
+ Record<string, boolean>,
10
+ (option: SwitchTarget[] | SwitchTarget, record?: {
11
+ [key: `${string}`]: Data;
12
+ }[] | {
13
+ [key: `${string}`]: Data;
14
+ }) => void,
15
+ Record<string, Data>
16
+ ];
17
+ declare const useSwitch: (names: readonly Item[]) => UseSwitchReturn;
18
+ export default useSwitch;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/State/useSwitch/index.ts"],"names":[],"mappings":"AAEA,KAAK,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAC5C,MAAM,MAAM,YAAY,GAAG;IAAE,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE,GAAI,OAAO,CAAA;CAAE,CAAC;AAC5D,KAAK,IAAI,GAAG,MAAM,GAAG;IAAC,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC;CAAC,CAAA;AAEnD,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvB,CACE,MAAM,EAAC,YAAY,EAAE,GAAG,YAAY,EACpC,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE,GAAI,IAAI,CAAA;KAAE,EAAE,GAAG;QAAE,CAAC,GAAG,EAAE,GAAG,MAAM,EAAE,GAAI,IAAI,CAAA;KAAE,KACrE,IAAI;IACT,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;CACrB,CAAC;AAGF,QAAA,MAAM,SAAS,UACN,SAAS,IAAI,EAAE,oBAwCvB,CAAC;AAEF,eAAe,SAAS,CAAC"}