@thisisagile/easy-react 19.1.3 → 20.0.0

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 (74) hide show
  1. package/dist/index.d.ts +11 -2
  2. package/dist/index.js +9 -195
  3. package/dist/layout/If.d.ts +6 -3
  4. package/dist/layout/If.js +8 -0
  5. package/dist/layout/If.js.map +1 -0
  6. package/dist/layout/index.d.ts +2 -1
  7. package/dist/layout/index.js +1 -0
  8. package/dist/utils/Children.d.ts +5 -2
  9. package/dist/utils/Children.js +8 -0
  10. package/dist/utils/Children.js.map +1 -0
  11. package/dist/utils/Hooks.d.ts +9 -6
  12. package/dist/utils/Hooks.js +92 -0
  13. package/dist/utils/Hooks.js.map +1 -0
  14. package/dist/utils/index.d.ts +8 -7
  15. package/dist/utils/index.js +8 -0
  16. package/dist/utils/toClasses.d.ts +4 -1
  17. package/dist/utils/toClasses.js +7 -0
  18. package/dist/utils/toClasses.js.map +1 -0
  19. package/dist/utils/useOnce.d.ts +6 -3
  20. package/dist/utils/useOnce.js +11 -0
  21. package/dist/utils/useOnce.js.map +1 -0
  22. package/dist/utils/useRev.d.ts +6 -3
  23. package/dist/utils/useRev.js +15 -0
  24. package/dist/utils/useRev.js.map +1 -0
  25. package/dist/utils/useState.d.ts +4 -1
  26. package/dist/utils/useState.js +15 -0
  27. package/dist/utils/useState.js.map +1 -0
  28. package/dist/utils/useToggle.d.ts +3 -0
  29. package/dist/utils/useToggle.js +19 -0
  30. package/dist/utils/useToggle.js.map +1 -0
  31. package/package.json +20 -19
  32. package/dist/chunk-3NRZNMHB.mjs +0 -89
  33. package/dist/chunk-3NRZNMHB.mjs.map +0 -1
  34. package/dist/chunk-M2BG3FAA.mjs +0 -1
  35. package/dist/chunk-M2BG3FAA.mjs.map +0 -1
  36. package/dist/chunk-M3I4MUWH.mjs +0 -1
  37. package/dist/chunk-M3I4MUWH.mjs.map +0 -1
  38. package/dist/chunk-S5QJ6HAZ.mjs +0 -12
  39. package/dist/chunk-S5QJ6HAZ.mjs.map +0 -1
  40. package/dist/chunk-SASVI5SH.mjs +0 -19
  41. package/dist/chunk-SASVI5SH.mjs.map +0 -1
  42. package/dist/chunk-VLU7TTX5.mjs +0 -8
  43. package/dist/chunk-VLU7TTX5.mjs.map +0 -1
  44. package/dist/chunk-XFIUD32G.mjs +0 -12
  45. package/dist/chunk-XFIUD32G.mjs.map +0 -1
  46. package/dist/chunk-XZLKJ4HU.mjs +0 -9
  47. package/dist/chunk-XZLKJ4HU.mjs.map +0 -1
  48. package/dist/chunk-ZGJ22EVC.mjs +0 -15
  49. package/dist/chunk-ZGJ22EVC.mjs.map +0 -1
  50. package/dist/chunk-ZW2CHFPD.mjs +0 -8
  51. package/dist/chunk-ZW2CHFPD.mjs.map +0 -1
  52. package/dist/index.js.map +0 -1
  53. package/dist/index.mjs +0 -55
  54. package/dist/index.mjs.map +0 -1
  55. package/dist/layout/If.mjs +0 -7
  56. package/dist/layout/If.mjs.map +0 -1
  57. package/dist/layout/index.mjs +0 -8
  58. package/dist/layout/index.mjs.map +0 -1
  59. package/dist/utils/Children.mjs +0 -7
  60. package/dist/utils/Children.mjs.map +0 -1
  61. package/dist/utils/Hooks.mjs +0 -25
  62. package/dist/utils/Hooks.mjs.map +0 -1
  63. package/dist/utils/index.mjs +0 -50
  64. package/dist/utils/index.mjs.map +0 -1
  65. package/dist/utils/toClasses.mjs +0 -7
  66. package/dist/utils/toClasses.mjs.map +0 -1
  67. package/dist/utils/useOnce.mjs +0 -7
  68. package/dist/utils/useOnce.mjs.map +0 -1
  69. package/dist/utils/useRev.mjs +0 -8
  70. package/dist/utils/useRev.mjs.map +0 -1
  71. package/dist/utils/useState.mjs +0 -7
  72. package/dist/utils/useState.mjs.map +0 -1
  73. package/dist/utils/useToggle.mjs +0 -8
  74. package/dist/utils/useToggle.mjs.map +0 -1
package/dist/index.d.ts CHANGED
@@ -1,2 +1,11 @@
1
- export * from './layout';
2
- export * from './utils';
1
+ import { If, IfProps } from "./layout/If.js";
2
+ import "./layout/index.js";
3
+ import { toChildren } from "./utils/Children.js";
4
+ import { toClasses } from "./utils/toClasses.js";
5
+ import { useA, useAn, useEntity, useGet, useGetList, useList, useOptional, usePageList, usePaging, useSwitch } from "./utils/Hooks.js";
6
+ import { UseOnceOptions, useOnce } from "./utils/useOnce.js";
7
+ import { useRev } from "./utils/useRev.js";
8
+ import { useState } from "./utils/useState.js";
9
+ import { useToggle } from "./utils/useToggle.js";
10
+ import "./utils/index.js";
11
+ export { If, IfProps, UseOnceOptions, toChildren, toClasses, useA, useAn, useEntity, useGet, useGetList, useList, useOnce, useOptional, usePageList, usePaging, useRev, useState, useSwitch, useToggle };
package/dist/index.js CHANGED
@@ -1,195 +1,9 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var src_exports = {};
32
- __export(src_exports, {
33
- If: () => If,
34
- toChildren: () => toChildren,
35
- toClasses: () => toClasses,
36
- useA: () => useA,
37
- useAn: () => useAn,
38
- useEntity: () => useEntity,
39
- useGet: () => useGet,
40
- useGetList: () => useGetList,
41
- useList: () => useList,
42
- useOnce: () => useOnce,
43
- useOptional: () => useOptional,
44
- usePageList: () => usePageList,
45
- usePaging: () => usePaging,
46
- useRev: () => useRev,
47
- useState: () => useState3,
48
- useSwitch: () => useSwitch,
49
- useToggle: () => useToggle
50
- });
51
- module.exports = __toCommonJS(src_exports);
52
-
53
- // src/layout/If.tsx
54
- var import_jsx_runtime = require("react/jsx-runtime");
55
- var If = ({ condition, children }) => condition ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children }) : null;
56
-
57
- // src/utils/Children.ts
58
- var import_easy = require("@thisisagile/easy");
59
- var import_react = __toESM(require("react"));
60
- var toChildren = (children) => (0, import_easy.toList)(import_react.default.Children.toArray(children).filter(import_easy.isDefined));
61
-
62
- // src/utils/toClasses.ts
63
- var import_easy2 = require("@thisisagile/easy");
64
- var toClasses = (styles, classes, props) => [...(0, import_easy2.toArray)(classes).map((c) => styles[c]), ...(0, import_easy2.entries)(props).map(([key, val]) => (0, import_easy2.ifTrue)(val, styles[key]))].filter(Boolean).join(" ");
65
-
66
- // src/utils/Hooks.ts
67
- var import_easy3 = require("@thisisagile/easy");
68
- var import_react2 = require("react");
69
- function useSwitch(...states) {
70
- const [state, setState] = (0, import_react2.useState)(states[0]);
71
- const next = () => setState((s) => states[(states.indexOf(s) + 1) % states.length]);
72
- const isState = (t) => state === t;
73
- function ifState(t, yes, no) {
74
- return (0, import_easy3.ofGet)(state === t ? yes : no, t);
75
- }
76
- return { state, next, states, isState, ifState };
77
- }
78
- var useA = (item = {}) => {
79
- const [state, setState] = (0, import_react2.useState)({ isValid: false, ...item });
80
- return [
81
- state,
82
- (e) => {
83
- setState(e);
84
- return e;
85
- }
86
- ];
87
- };
88
- var useAn = useA;
89
- var useOptional = (item) => {
90
- const [state, setState] = (0, import_react2.useState)(item);
91
- const set = (e) => {
92
- setState(e);
93
- return e;
94
- };
95
- return [state, set, () => set()];
96
- };
97
- var useEntity = useA;
98
- var useList = (...items) => {
99
- const [state, setState] = (0, import_react2.useState)((0, import_easy3.toList)(...items));
100
- return [
101
- state,
102
- (e) => {
103
- setState(e);
104
- return e;
105
- }
106
- ];
107
- };
108
- var usePageList = (...items) => {
109
- const [pages, setPages] = (0, import_react2.useState)((0, import_easy3.toPageList)(items));
110
- return [
111
- pages,
112
- (e) => {
113
- setPages(e);
114
- return e;
115
- }
116
- ];
117
- };
118
- var usePaging = (f, options) => {
119
- const [list, setList] = usePageList();
120
- const [skip, setSkip] = (0, import_react2.useState)(options?.skip ?? 0);
121
- const [take] = (0, import_react2.useState)(options?.take ?? 5);
122
- const next = (options2 = { skip, take }) => f(options2).then((items) => {
123
- setSkip(skip + take);
124
- return setList((0, import_easy3.toPageList)(list.add(items), items));
125
- });
126
- return [list, next, list.length < (list?.total ?? 0), skip, take];
127
- };
128
- var useGet = (f, initial) => {
129
- const [item, setItem] = (0, import_react2.useState)(initial ?? {});
130
- const getter = () => f().then((i) => {
131
- setItem(i);
132
- return i;
133
- });
134
- return [item, getter];
135
- };
136
- var useGetList = (f) => {
137
- const [list, setList] = usePageList();
138
- const getter = () => f().then((l) => setList((0, import_easy3.isPageList)(l) ? l : (0, import_easy3.toPageList)(l, { total: l.length })));
139
- return [list, getter];
140
- };
141
-
142
- // src/utils/useOnce.ts
143
- var import_react3 = require("react");
144
- function useOnce(f, options) {
145
- const [item, setItem] = (0, import_react3.useState)(options?.initial);
146
- (0, import_react3.useEffect)(() => void f().then((i) => setItem(i)), options?.deps ?? []);
147
- return [item];
148
- }
149
-
150
- // src/utils/useState.ts
151
- var import_react4 = require("react");
152
- function useState3(initial) {
153
- const [state, setState] = (0, import_react4.useState)(initial);
154
- const reset = () => setState(initial);
155
- return [state, setState, reset];
156
- }
157
-
158
- // src/utils/useRev.ts
159
- var useRev = (initial = 0) => {
160
- const [rev, setRev, reset] = useState3(initial);
161
- const revalidate = () => setRev((r) => r + 1);
162
- return { rev, revalidate, reset };
163
- };
164
-
165
- // src/utils/useToggle.ts
166
- function useToggle(initial = false) {
167
- const [state, setState] = useState3(initial);
168
- const toggle = () => setState((s) => !s);
169
- const flip = (fn) => {
170
- setState((s) => !s);
171
- return fn().finally(() => setState((s) => !s));
172
- };
173
- return [state, toggle, flip];
174
- }
175
- // Annotate the CommonJS export names for ESM import in node:
176
- 0 && (module.exports = {
177
- If,
178
- toChildren,
179
- toClasses,
180
- useA,
181
- useAn,
182
- useEntity,
183
- useGet,
184
- useGetList,
185
- useList,
186
- useOnce,
187
- useOptional,
188
- usePageList,
189
- usePaging,
190
- useRev,
191
- useState,
192
- useSwitch,
193
- useToggle
194
- });
195
- //# sourceMappingURL=index.js.map
1
+ import { If } from "./layout/If.js";
2
+ import { toChildren } from "./utils/Children.js";
3
+ import { toClasses } from "./utils/toClasses.js";
4
+ import { useA, useAn, useEntity, useGet, useGetList, useList, useOptional, usePageList, usePaging, useSwitch } from "./utils/Hooks.js";
5
+ import { useOnce } from "./utils/useOnce.js";
6
+ import { useState } from "./utils/useState.js";
7
+ import { useRev } from "./utils/useRev.js";
8
+ import { useToggle } from "./utils/useToggle.js";
9
+ export { If, toChildren, toClasses, useA, useAn, useEntity, useGet, useGetList, useList, useOnce, useOptional, usePageList, usePaging, useRev, useState, useSwitch, useToggle };
@@ -1,6 +1,9 @@
1
- import { FunctionComponent, ReactNode } from 'react';
1
+ import { FunctionComponent, ReactNode } from "react";
2
+ //#region src/layout/If.d.ts
2
3
  export interface IfProps {
3
- condition: any | undefined;
4
- children?: ReactNode;
4
+ condition: any | undefined;
5
+ children?: ReactNode;
5
6
  }
6
7
  export declare const If: FunctionComponent<IfProps>;
8
+ //#endregion
9
+ //# sourceMappingURL=If.d.ts.map
@@ -0,0 +1,8 @@
1
+ import "react";
2
+ import { Fragment, jsx } from "react/jsx-runtime";
3
+ //#region src/layout/If.tsx
4
+ const If = ({ condition, children }) => condition ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
5
+ //#endregion
6
+ export { If };
7
+
8
+ //# sourceMappingURL=If.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"If.js","names":[],"sources":["../../src/layout/If.tsx"],"sourcesContent":["import * as React from 'react';\nimport { FunctionComponent, ReactElement, ReactNode } from 'react';\n\nexport interface IfProps {\n condition: any | undefined;\n children?: ReactNode;\n}\n\nexport const If: FunctionComponent<IfProps> = ({ condition, children }): ReactElement | null => (condition ? <>{children}</> : null);\n"],"mappings":";;;AAQA,MAAa,MAAkC,EAAE,WAAW,eAAqC,YAAY,oBAAA,UAAA,EAAG,SAAW,CAAA,IAAI"}
@@ -1 +1,2 @@
1
- export * from './If';
1
+ import { If, IfProps } from "./If.js";
2
+ export { If, IfProps };
@@ -0,0 +1 @@
1
+ export { If } from "./If.js";
@@ -1,3 +1,6 @@
1
- import { List } from '@thisisagile/easy';
2
- import { ReactNode } from 'react';
1
+ import { ReactNode } from "react";
2
+ import { List } from "@thisisagile/easy";
3
+ //#region src/utils/Children.d.ts
3
4
  export declare const toChildren: (children: ReactNode) => List<ReactNode>;
5
+ //#endregion
6
+ //# sourceMappingURL=Children.d.ts.map
@@ -0,0 +1,8 @@
1
+ import React from "react";
2
+ import { isDefined, toList } from "@thisisagile/easy";
3
+ //#region src/utils/Children.ts
4
+ const toChildren = (children) => toList(React.Children.toArray(children).filter(isDefined));
5
+ //#endregion
6
+ export { toChildren };
7
+
8
+ //# sourceMappingURL=Children.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Children.js","names":[],"sources":["../../src/utils/Children.ts"],"sourcesContent":["import { isDefined, List, toList } from '@thisisagile/easy';\nimport React, { ReactNode } from 'react';\n\nexport const toChildren = (children: ReactNode): List<ReactNode> => toList(React.Children.toArray(children).filter(isDefined));\n"],"mappings":";;;AAGA,MAAa,cAAc,aAAyC,OAAO,MAAM,SAAS,QAAQ,QAAQ,CAAC,CAAC,OAAO,SAAS,CAAC"}
@@ -1,10 +1,11 @@
1
- import { Get, List, Optional, PageList, PageOptions, Predicate, Validatable } from '@thisisagile/easy';
1
+ import { Get, List, Optional, PageList, PageOptions, Predicate, Validatable } from "@thisisagile/easy";
2
+ //#region src/utils/Hooks.d.ts
2
3
  export declare function useSwitch<T>(...states: T[]): {
3
- state: T;
4
- next: () => void;
5
- states: T[];
6
- isState: Predicate<T>;
7
- ifState: <U>(t: T, yes: Get<U, T>, no: Get<U, T>) => U;
4
+ state: T;
5
+ next: () => void;
6
+ states: T[];
7
+ isState: Predicate<T>;
8
+ ifState: <U>(t: T, yes: Get<U, T>, no: Get<U, T>) => U;
8
9
  };
9
10
  export declare const useA: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
10
11
  export declare const useAn: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
@@ -15,3 +16,5 @@ export declare const usePageList: <E>(...items: E[]) => [PageList<E>, (e: PageLi
15
16
  export declare const usePaging: <E>(f: (options?: PageOptions) => Promise<PageList<E>>, options?: PageOptions) => [PageList<E>, (options?: PageOptions) => Promise<PageList<E>>, boolean, number, number];
16
17
  export declare const useGet: <E>(f: () => Promise<E>, initial?: Partial<E>) => [E, () => Promise<E>];
17
18
  export declare const useGetList: <E>(f: () => Promise<List<E>>) => [List<E>, () => Promise<PageList<E>>];
19
+ //#endregion
20
+ //# sourceMappingURL=Hooks.d.ts.map
@@ -0,0 +1,92 @@
1
+ import { useState } from "react";
2
+ import { isPageList, ofGet, toList, toPageList } from "@thisisagile/easy";
3
+ //#region src/utils/Hooks.ts
4
+ function useSwitch(...states) {
5
+ const [state, setState] = useState(states[0]);
6
+ const next = () => setState((s) => states[(states.indexOf(s) + 1) % states.length]);
7
+ const isState = (t) => state === t;
8
+ function ifState(t, yes, no) {
9
+ return ofGet(state === t ? yes : no, t);
10
+ }
11
+ return {
12
+ state,
13
+ next,
14
+ states,
15
+ isState,
16
+ ifState
17
+ };
18
+ }
19
+ const useA = (item = {}) => {
20
+ const [state, setState] = useState({
21
+ isValid: false,
22
+ ...item
23
+ });
24
+ return [state, (e) => {
25
+ setState(e);
26
+ return e;
27
+ }];
28
+ };
29
+ const useAn = useA;
30
+ const useOptional = (item) => {
31
+ const [state, setState] = useState(item);
32
+ const set = (e) => {
33
+ setState(e);
34
+ return e;
35
+ };
36
+ return [
37
+ state,
38
+ set,
39
+ () => set()
40
+ ];
41
+ };
42
+ const useEntity = useA;
43
+ const useList = (...items) => {
44
+ const [state, setState] = useState(toList(...items));
45
+ return [state, (e) => {
46
+ setState(e);
47
+ return e;
48
+ }];
49
+ };
50
+ const usePageList = (...items) => {
51
+ const [pages, setPages] = useState(toPageList(items));
52
+ return [pages, (e) => {
53
+ setPages(e);
54
+ return e;
55
+ }];
56
+ };
57
+ const usePaging = (f, options) => {
58
+ const [list, setList] = usePageList();
59
+ const [skip, setSkip] = useState(options?.skip ?? 0);
60
+ const [take] = useState(options?.take ?? 5);
61
+ const next = (options = {
62
+ skip,
63
+ take
64
+ }) => f(options).then((items) => {
65
+ setSkip(skip + take);
66
+ return setList(toPageList(list.add(items), items));
67
+ });
68
+ return [
69
+ list,
70
+ next,
71
+ list.length < (list?.total ?? 0),
72
+ skip,
73
+ take
74
+ ];
75
+ };
76
+ const useGet = (f, initial) => {
77
+ const [item, setItem] = useState(initial ?? {});
78
+ const getter = () => f().then((i) => {
79
+ setItem(i);
80
+ return i;
81
+ });
82
+ return [item, getter];
83
+ };
84
+ const useGetList = (f) => {
85
+ const [list, setList] = usePageList();
86
+ const getter = () => f().then((l) => setList(isPageList(l) ? l : toPageList(l, { total: l.length })));
87
+ return [list, getter];
88
+ };
89
+ //#endregion
90
+ export { useA, useAn, useEntity, useGet, useGetList, useList, useOptional, usePageList, usePaging, useSwitch };
91
+
92
+ //# sourceMappingURL=Hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Hooks.js","names":[],"sources":["../../src/utils/Hooks.ts"],"sourcesContent":["import { Get, isPageList, List, ofGet, Optional, PageList, PageOptions, Predicate, toList, toPageList, Validatable } from '@thisisagile/easy';\nimport { useState } from 'react';\n\n// export const useToggle = (initialState = false): [boolean, () => void] => {\n// const [state, setState] = useState<boolean>(initialState);\n// return [state, () => setState(s => !s)];\n// };\n\nexport function useSwitch<T>(...states: T[]): {\n state: T;\n next: () => void;\n states: T[];\n isState: Predicate<T>;\n ifState: <U>(t: T, yes: Get<U, T>, no: Get<U, T>) => U;\n} {\n const [state, setState] = useState(states[0]);\n const next = () => setState(s => states[(states.indexOf(s) + 1) % states.length]);\n const isState = (t: T) => state === t;\n\n function ifState<U>(t: T, yes: Get<U, T>, no: Get<U, T>): U {\n return ofGet(state === t ? yes : no, t);\n }\n\n return { state, next, states, isState, ifState };\n}\n\nexport const useA = <E extends Validatable>(item: Partial<E> = {} as Partial<E>): [E, (e: E) => E] => {\n const [state, setState] = useState<E>({ isValid: false, ...item } as E);\n return [\n state,\n (e: E): E => {\n setState(e);\n return e;\n },\n ];\n};\n\nexport const useAn = useA;\n\nexport const useOptional = <E>(item?: Partial<E>): [E, (e: Optional<E>) => Optional<E>, () => Optional<E>] => {\n const [state, setState] = useState<E>(item as E);\n const set = (e?: Optional<E>): Optional<E> => {\n setState(e as E);\n return e;\n };\n return [state, set, (): Optional<E> => set()];\n};\n\nexport const useEntity = useA;\n\nexport const useList = <E>(...items: E[]): [List<E>, (e: List<E>) => List<E>] => {\n const [state, setState] = useState<List<E>>(toList<E>(...items));\n return [\n state,\n (e: List<E>): List<E> => {\n setState(e);\n return e;\n },\n ];\n};\n\nexport const usePageList = <E>(...items: E[]): [PageList<E>, (e: PageList<E>) => PageList<E>] => {\n const [pages, setPages] = useState<PageList<E>>(toPageList<E>(items));\n return [\n pages,\n (e: PageList<E>): PageList<E> => {\n setPages(e);\n return e;\n },\n ];\n};\n\nexport const usePaging = <E>(\n f: (options?: PageOptions) => Promise<PageList<E>>,\n options?: PageOptions\n): [PageList<E>, (options?: PageOptions) => Promise<PageList<E>>, boolean, number, number] => {\n const [list, setList] = usePageList<E>();\n const [skip, setSkip] = useState(options?.skip ?? 0);\n const [take] = useState(options?.take ?? 5);\n const next = (options: PageOptions = { skip, take }) =>\n f(options).then(items => {\n setSkip(skip + take);\n return setList(toPageList(list.add(items), items));\n });\n return [list, next, list.length < (list?.total ?? 0), skip, take];\n};\n\nexport const useGet = <E>(f: () => Promise<E>, initial?: Partial<E>): [E, () => Promise<E>] => {\n const [item, setItem] = useState((initial ?? {}) as E);\n const getter = () =>\n f().then(i => {\n setItem(i);\n return i;\n });\n return [item, getter];\n};\n\nexport const useGetList = <E>(f: () => Promise<List<E>>): [List<E>, () => Promise<PageList<E>>] => {\n const [list, setList] = usePageList<E>();\n const getter = () => f().then(l => setList(isPageList<E>(l) ? l : toPageList(l, { total: l.length })));\n return [list, getter];\n};\n"],"mappings":";;;AAQA,SAAgB,UAAa,GAAG,QAM9B;CACA,MAAM,CAAC,OAAO,YAAY,SAAS,OAAO,EAAE;CAC5C,MAAM,aAAa,UAAS,MAAK,QAAQ,OAAO,QAAQ,CAAC,IAAI,KAAK,OAAO,OAAO;CAChF,MAAM,WAAW,MAAS,UAAU;CAEpC,SAAS,QAAW,GAAM,KAAgB,IAAkB;EAC1D,OAAO,MAAM,UAAU,IAAI,MAAM,IAAI,CAAC;CACxC;CAEA,OAAO;EAAE;EAAO;EAAM;EAAQ;EAAS;CAAQ;AACjD;AAEA,MAAa,QAA+B,OAAmB,CAAC,MAAsC;CACpG,MAAM,CAAC,OAAO,YAAY,SAAY;EAAE,SAAS;EAAO,GAAG;CAAK,CAAM;CACtE,OAAO,CACL,QACC,MAAY;EACX,SAAS,CAAC;EACV,OAAO;CACT,CACF;AACF;AAEA,MAAa,QAAQ;AAErB,MAAa,eAAkB,SAA+E;CAC5G,MAAM,CAAC,OAAO,YAAY,SAAY,IAAS;CAC/C,MAAM,OAAO,MAAiC;EAC5C,SAAS,CAAM;EACf,OAAO;CACT;CACA,OAAO;EAAC;EAAO;QAAwB,IAAI;CAAC;AAC9C;AAEA,MAAa,YAAY;AAEzB,MAAa,WAAc,GAAG,UAAmD;CAC/E,MAAM,CAAC,OAAO,YAAY,SAAkB,OAAU,GAAG,KAAK,CAAC;CAC/D,OAAO,CACL,QACC,MAAwB;EACvB,SAAS,CAAC;EACV,OAAO;CACT,CACF;AACF;AAEA,MAAa,eAAkB,GAAG,UAA+D;CAC/F,MAAM,CAAC,OAAO,YAAY,SAAsB,WAAc,KAAK,CAAC;CACpE,OAAO,CACL,QACC,MAAgC;EAC/B,SAAS,CAAC;EACV,OAAO;CACT,CACF;AACF;AAEA,MAAa,aACX,GACA,YAC4F;CAC5F,MAAM,CAAC,MAAM,WAAW,YAAe;CACvC,MAAM,CAAC,MAAM,WAAW,SAAS,SAAS,QAAQ,CAAC;CACnD,MAAM,CAAC,QAAQ,SAAS,SAAS,QAAQ,CAAC;CAC1C,MAAM,QAAQ,UAAuB;EAAE;EAAM;CAAK,MAChD,EAAE,OAAO,CAAC,CAAC,MAAK,UAAS;EACvB,QAAQ,OAAO,IAAI;EACnB,OAAO,QAAQ,WAAW,KAAK,IAAI,KAAK,GAAG,KAAK,CAAC;CACnD,CAAC;CACH,OAAO;EAAC;EAAM;EAAM,KAAK,UAAU,MAAM,SAAS;EAAI;EAAM;CAAI;AAClE;AAEA,MAAa,UAAa,GAAqB,YAAgD;CAC7F,MAAM,CAAC,MAAM,WAAW,SAAU,WAAW,CAAC,CAAO;CACrD,MAAM,eACJ,EAAE,CAAC,CAAC,MAAK,MAAK;EACZ,QAAQ,CAAC;EACT,OAAO;CACT,CAAC;CACH,OAAO,CAAC,MAAM,MAAM;AACtB;AAEA,MAAa,cAAiB,MAAqE;CACjG,MAAM,CAAC,MAAM,WAAW,YAAe;CACvC,MAAM,eAAe,EAAE,CAAC,CAAC,MAAK,MAAK,QAAQ,WAAc,CAAC,IAAI,IAAI,WAAW,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;CACrG,OAAO,CAAC,MAAM,MAAM;AACtB"}
@@ -1,7 +1,8 @@
1
- export * from './Children';
2
- export * from './toClasses';
3
- export * from './Hooks';
4
- export * from './useOnce';
5
- export * from './useRev';
6
- export * from './useState';
7
- export * from './useToggle';
1
+ import { toChildren } from "./Children.js";
2
+ import { toClasses } from "./toClasses.js";
3
+ import { useA, useAn, useEntity, useGet, useGetList, useList, useOptional, usePageList, usePaging, useSwitch } from "./Hooks.js";
4
+ import { UseOnceOptions, useOnce } from "./useOnce.js";
5
+ import { useRev } from "./useRev.js";
6
+ import { useState } from "./useState.js";
7
+ import { useToggle } from "./useToggle.js";
8
+ export { UseOnceOptions, toChildren, toClasses, useA, useAn, useEntity, useGet, useGetList, useList, useOnce, useOptional, usePageList, usePaging, useRev, useState, useSwitch, useToggle };
@@ -0,0 +1,8 @@
1
+ import { toChildren } from "./Children.js";
2
+ import { toClasses } from "./toClasses.js";
3
+ import { useA, useAn, useEntity, useGet, useGetList, useList, useOptional, usePageList, usePaging, useSwitch } from "./Hooks.js";
4
+ import { useOnce } from "./useOnce.js";
5
+ import { useState } from "./useState.js";
6
+ import { useRev } from "./useRev.js";
7
+ import { useToggle } from "./useToggle.js";
8
+ export { toChildren, toClasses, useA, useAn, useEntity, useGet, useGetList, useList, useOnce, useOptional, usePageList, usePaging, useRev, useState, useSwitch, useToggle };
@@ -1,2 +1,5 @@
1
- import { OneOrMore, Optional } from '@thisisagile/easy';
1
+ import { OneOrMore, Optional } from "@thisisagile/easy";
2
+ //#region src/utils/toClasses.d.ts
2
3
  export declare const toClasses: (styles: Record<string, string>, classes: OneOrMore<string>, props: Record<string, Optional<boolean>>) => string;
4
+ //#endregion
5
+ //# sourceMappingURL=toClasses.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { entries, ifTrue, toArray } from "@thisisagile/easy";
2
+ //#region src/utils/toClasses.ts
3
+ const toClasses = (styles, classes, props) => [...toArray(classes).map((c) => styles[c]), ...entries(props).map(([key, val]) => ifTrue(val, styles[key]))].filter(Boolean).join(" ");
4
+ //#endregion
5
+ export { toClasses };
6
+
7
+ //# sourceMappingURL=toClasses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toClasses.js","names":[],"sources":["../../src/utils/toClasses.ts"],"sourcesContent":["import { entries, ifTrue, OneOrMore, Optional, toArray } from '@thisisagile/easy';\n\nexport const toClasses = (styles: Record<string, string>, classes: OneOrMore<string>, props: Record<string, Optional<boolean>>): string =>\n [...toArray(classes).map(c => styles[c]), ...entries(props).map(([key, val]) => ifTrue(val, styles[key]))].filter(Boolean).join(' ');\n"],"mappings":";;AAEA,MAAa,aAAa,QAAgC,SAA4B,UACpF,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC,KAAI,MAAK,OAAO,EAAE,GAAG,GAAG,QAAQ,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,SAAS,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG"}
@@ -1,6 +1,9 @@
1
- import { DependencyList } from 'react';
1
+ import { DependencyList } from "react";
2
+ //#region src/utils/useOnce.d.ts
2
3
  export type UseOnceOptions<E> = {
3
- deps?: DependencyList;
4
- initial?: Partial<E>;
4
+ deps?: DependencyList;
5
+ initial?: Partial<E>;
5
6
  };
6
7
  export declare function useOnce<E>(f: () => Promise<E>, options?: UseOnceOptions<E>): [E];
8
+ //#endregion
9
+ //# sourceMappingURL=useOnce.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { useEffect, useState } from "react";
2
+ //#region src/utils/useOnce.ts
3
+ function useOnce(f, options) {
4
+ const [item, setItem] = useState(options?.initial);
5
+ useEffect(() => void f().then((i) => setItem(i)), options?.deps ?? []);
6
+ return [item];
7
+ }
8
+ //#endregion
9
+ export { useOnce };
10
+
11
+ //# sourceMappingURL=useOnce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useOnce.js","names":[],"sources":["../../src/utils/useOnce.ts"],"sourcesContent":["import { DependencyList, useEffect, useState } from 'react';\n\nexport type UseOnceOptions<E> = {\n deps?: DependencyList;\n initial?: Partial<E>;\n};\n\nexport function useOnce<E>(f: () => Promise<E>, options?: UseOnceOptions<E>): [E] {\n const [item, setItem] = useState(options?.initial as E);\n useEffect(() => void f().then(i => setItem(i)), options?.deps ?? []);\n return [item];\n}\n"],"mappings":";;AAOA,SAAgB,QAAW,GAAqB,SAAkC;CAChF,MAAM,CAAC,MAAM,WAAW,SAAS,SAAS,OAAY;CACtD,gBAAgB,KAAK,EAAE,CAAC,CAAC,MAAK,MAAK,QAAQ,CAAC,CAAC,GAAG,SAAS,QAAQ,CAAC,CAAC;CACnE,OAAO,CAAC,IAAI;AACd"}
@@ -1,5 +1,8 @@
1
+ //#region src/utils/useRev.d.ts
1
2
  export declare const useRev: (initial?: number) => {
2
- rev: number;
3
- revalidate: () => void;
4
- reset: () => void;
3
+ rev: number;
4
+ revalidate: () => void;
5
+ reset: () => void;
5
6
  };
7
+ //#endregion
8
+ //# sourceMappingURL=useRev.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { useState } from "./useState.js";
2
+ //#region src/utils/useRev.ts
3
+ const useRev = (initial = 0) => {
4
+ const [rev, setRev, reset] = useState(initial);
5
+ const revalidate = () => setRev((r) => r + 1);
6
+ return {
7
+ rev,
8
+ revalidate,
9
+ reset
10
+ };
11
+ };
12
+ //#endregion
13
+ export { useRev };
14
+
15
+ //# sourceMappingURL=useRev.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRev.js","names":[],"sources":["../../src/utils/useRev.ts"],"sourcesContent":["import { useState } from './useState';\n\nexport const useRev = (initial = 0) => {\n const [rev, setRev, reset] = useState(initial);\n const revalidate = () => setRev(r => r + 1);\n return { rev, revalidate, reset };\n};\n"],"mappings":";;AAEA,MAAa,UAAU,UAAU,MAAM;CACrC,MAAM,CAAC,KAAK,QAAQ,SAAS,SAAS,OAAO;CAC7C,MAAM,mBAAmB,QAAO,MAAK,IAAI,CAAC;CAC1C,OAAO;EAAE;EAAK;EAAY;CAAM;AAClC"}
@@ -1,3 +1,6 @@
1
- import { Dispatch, SetStateAction } from 'react';
1
+ import { Dispatch, SetStateAction } from "react";
2
+ //#region src/utils/useState.d.ts
2
3
  export declare function useState<T>(): [T | undefined, Dispatch<SetStateAction<T | undefined>>, () => void];
3
4
  export declare function useState<T>(initial: T): [T, Dispatch<SetStateAction<T>>, () => void];
5
+ //#endregion
6
+ //# sourceMappingURL=useState.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { useState as useState$1 } from "react";
2
+ //#region src/utils/useState.ts
3
+ function useState(initial) {
4
+ const [state, setState] = useState$1(initial);
5
+ const reset = () => setState(initial);
6
+ return [
7
+ state,
8
+ setState,
9
+ reset
10
+ ];
11
+ }
12
+ //#endregion
13
+ export { useState };
14
+
15
+ //# sourceMappingURL=useState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useState.js","names":["useReactState"],"sources":["../../src/utils/useState.ts"],"sourcesContent":["import { Dispatch, SetStateAction, useState as useReactState } from 'react';\n\nexport function useState<T>(): [T | undefined, Dispatch<SetStateAction<T | undefined>>, () => void];\nexport function useState<T>(initial: T): [T, Dispatch<SetStateAction<T>>, () => void];\nexport function useState<T>(initial?: T) {\n const [state, setState] = useReactState(initial);\n const reset = () => setState(initial);\n return [state, setState, reset] as const;\n}\n"],"mappings":";;AAIA,SAAgB,SAAY,SAAa;CACvC,MAAM,CAAC,OAAO,YAAYA,WAAc,OAAO;CAC/C,MAAM,cAAc,SAAS,OAAO;CACpC,OAAO;EAAC;EAAO;EAAU;CAAK;AAChC"}
@@ -1 +1,4 @@
1
+ //#region src/utils/useToggle.d.ts
1
2
  export declare function useToggle(initial?: boolean): [boolean, () => void, <T>(fn: () => Promise<T>) => Promise<T>];
3
+ //#endregion
4
+ //# sourceMappingURL=useToggle.d.ts.map
@@ -0,0 +1,19 @@
1
+ import { useState } from "./useState.js";
2
+ //#region src/utils/useToggle.ts
3
+ function useToggle(initial = false) {
4
+ const [state, setState] = useState(initial);
5
+ const toggle = () => setState((s) => !s);
6
+ const flip = (fn) => {
7
+ setState((s) => !s);
8
+ return fn().finally(() => setState((s) => !s));
9
+ };
10
+ return [
11
+ state,
12
+ toggle,
13
+ flip
14
+ ];
15
+ }
16
+ //#endregion
17
+ export { useToggle };
18
+
19
+ //# sourceMappingURL=useToggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useToggle.js","names":[],"sources":["../../src/utils/useToggle.ts"],"sourcesContent":["import { useState } from './useState';\n\nexport function useToggle(initial = false): [boolean, () => void, <T>(fn: () => Promise<T>) => Promise<T>] {\n const [state, setState] = useState(initial);\n const toggle = () => setState(s => !s);\n const flip = <T>(fn: () => Promise<T>) => {\n setState(s => !s);\n return fn().finally(() => setState(s => !s));\n };\n return [state, toggle, flip];\n}\n"],"mappings":";;AAEA,SAAgB,UAAU,UAAU,OAAuE;CACzG,MAAM,CAAC,OAAO,YAAY,SAAS,OAAO;CAC1C,MAAM,eAAe,UAAS,MAAK,CAAC,CAAC;CACrC,MAAM,QAAW,OAAyB;EACxC,UAAS,MAAK,CAAC,CAAC;EAChB,OAAO,GAAG,CAAC,CAAC,cAAc,UAAS,MAAK,CAAC,CAAC,CAAC;CAC7C;CACA,OAAO;EAAC;EAAO;EAAQ;CAAI;AAC7B"}