@thisisagile/easy-react 15.8.5 → 15.8.7

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/dist/index.d.ts CHANGED
@@ -1,21 +1,2 @@
1
- import { ReactNode, FunctionComponent } from 'react';
2
- import { Validatable, Optional, List, PageList, PageOptions } from '@thisisagile/easy';
3
-
4
- interface IfProps {
5
- condition: any | undefined;
6
- children?: ReactNode;
7
- }
8
- declare const If: FunctionComponent<IfProps>;
9
-
10
- declare const useToggle: (initialState?: boolean) => [boolean, () => void];
11
- declare const useA: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
12
- declare const useAn: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
13
- declare const useOptional: <E>(item?: Partial<E> | undefined) => [E, (e: Optional<E>) => Optional<E>, () => Optional<E>];
14
- declare const useEntity: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
15
- declare const useList: <E>(...items: E[]) => [List<E>, (e: List<E>) => List<E>];
16
- declare const usePageList: <E>(...items: E[]) => [PageList<E>, (e: PageList<E>) => PageList<E>];
17
- declare const usePaging: <E>(f: (options?: PageOptions) => Promise<PageList<E>>, options?: PageOptions) => [PageList<E>, (options?: PageOptions) => Promise<PageList<E>>, boolean, number, number];
18
- declare const useGet: <E>(f: () => Promise<E>, initial?: Partial<E> | undefined) => [E, () => Promise<E>];
19
- declare const useGetList: <E>(f: () => Promise<List<E>>) => [List<E>, () => Promise<PageList<E>>];
20
-
21
- export { If, IfProps, useA, useAn, useEntity, useGet, useGetList, useList, useOptional, usePageList, usePaging, useToggle };
1
+ export * from './layout';
2
+ export * from './utils';
package/dist/index.js CHANGED
@@ -1 +1,25 @@
1
- "use strict";var c=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var f=(e,t)=>{for(var s in t)c(e,s,{get:t[s],enumerable:!0})},d=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of m(t))!x.call(e,n)&&n!==s&&c(e,n,{get:()=>t[n],enumerable:!(o=L(t,n))||o.enumerable});return e};var O=e=>d(c({},"__esModule",{value:!0}),e);var C={};f(C,{If:()=>b,useA:()=>l,useAn:()=>S,useEntity:()=>R,useGet:()=>y,useGetList:()=>A,useList:()=>I,useOptional:()=>k,usePageList:()=>P,usePaging:()=>V,useToggle:()=>h});module.exports=O(C);var E=require("react/jsx-runtime"),b=({condition:e,children:t})=>e?(0,E.jsx)(E.Fragment,{children:t}):null;var i=require("@thisisagile/easy"),a=require("react"),h=(e=!1)=>{let[t,s]=(0,a.useState)(e);return[t,()=>s(o=>!o)]},l=(e={})=>{let[t,s]=(0,a.useState)({isValid:!1,...e});return[t,o=>(s(o),o)]},S=l,k=e=>{let[t,s]=(0,a.useState)(e),o=n=>(s(n),n);return[t,o,()=>o()]},R=l,I=(...e)=>{let[t,s]=(0,a.useState)((0,i.toList)(...e));return[t,o=>(s(o),o)]},P=(...e)=>{let[t,s]=(0,a.useState)((0,i.toPageList)(e));return[t,o=>(s(o),o)]},V=(e,t)=>{let[s,o]=P(),[n,r]=(0,a.useState)(t?.skip??0),[p]=(0,a.useState)(t?.take??5);return[s,(u={skip:n,take:p})=>e(u).then(g=>(r(n+p),o((0,i.toPageList)(s.add(g),g)))),s.length<(s?.total??0),n,p]},y=(e,t)=>{let[s,o]=(0,a.useState)(t??{});return[s,()=>e().then(r=>(o(r),r))]},A=e=>{let[t,s]=P();return[t,()=>e().then(n=>s((0,i.isPageList)(n)?n:(0,i.toPageList)(n,{total:n.length})))]};0&&(module.exports={If,useA,useAn,useEntity,useGet,useGetList,useList,useOptional,usePageList,usePaging,useToggle});
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./layout"), module.exports);
19
+ __reExport(src_exports, require("./utils"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./layout"),
23
+ ...require("./utils")
24
+ });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './layout';\nexport * from './utils';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,qBAAd;AACA,wBAAc,oBADd;","names":[]}
package/dist/index.mjs CHANGED
@@ -1 +1,3 @@
1
- import{Fragment as g,jsx as u}from"react/jsx-runtime";var f=({condition:o,children:t})=>o?u(g,{children:t}):null;import{isPageList as L,toList as m,toPageList as E}from"@thisisagile/easy";import{useState as a}from"react";var C=(o=!1)=>{let[t,e]=a(o);return[t,()=>e(s=>!s)]},c=(o={})=>{let[t,e]=a({isValid:!1,...o});return[t,s=>(e(s),s)]},F=c,G=o=>{let[t,e]=a(o),s=n=>(e(n),n);return[t,s,()=>s()]},N=c,v=(...o)=>{let[t,e]=a(m(...o));return[t,s=>(e(s),s)]},l=(...o)=>{let[t,e]=a(E(o));return[t,s=>(e(s),s)]},T=(o,t)=>{let[e,s]=l(),[n,i]=a(t?.skip??0),[r]=a(t?.take??5);return[e,(P={skip:n,take:r})=>o(P).then(p=>(i(n+r),s(E(e.add(p),p)))),e.length<(e?.total??0),n,r]},q=(o,t)=>{let[e,s]=a(t??{});return[e,()=>o().then(i=>(s(i),i))]},w=o=>{let[t,e]=l();return[t,()=>o().then(n=>e(L(n)?n:E(n,{total:n.length})))]};export{f as If,c as useA,F as useAn,N as useEntity,q as useGet,w as useGetList,v as useList,G as useOptional,l as usePageList,T as usePaging,C as useToggle};
1
+ export * from "./layout";
2
+ export * from "./utils";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './layout';\nexport * from './utils';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,6 @@
1
+ import { FunctionComponent, ReactNode } from 'react';
2
+ export interface IfProps {
3
+ condition: any | undefined;
4
+ children?: ReactNode;
5
+ }
6
+ export declare const If: FunctionComponent<IfProps>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var If_exports = {};
20
+ __export(If_exports, {
21
+ If: () => If
22
+ });
23
+ module.exports = __toCommonJS(If_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ const If = ({ condition, children }) => condition ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children }) : null;
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ If
29
+ });
30
+ //# sourceMappingURL=If.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ6G;AAAtG,MAAM,KAAiC,CAAC,EAAE,WAAW,SAAS,MAA4B,YAAY,2EAAG,UAAS,IAAM;","names":[]}
@@ -0,0 +1,6 @@
1
+ import { Fragment, jsx } from "react/jsx-runtime";
2
+ const If = ({ condition, children }) => condition ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
3
+ export {
4
+ If
5
+ };
6
+ //# sourceMappingURL=If.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"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":"AAQ6G;AAAtG,MAAM,KAAiC,CAAC,EAAE,WAAW,SAAS,MAA4B,YAAY,gCAAG,UAAS,IAAM;","names":[]}
@@ -0,0 +1 @@
1
+ export * from './If';
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var layout_exports = {};
17
+ module.exports = __toCommonJS(layout_exports);
18
+ __reExport(layout_exports, require("./If"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./If")
22
+ });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/layout/index.ts"],"sourcesContent":["export * from './If';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,2BAAc,iBAAd;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./If";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/layout/index.ts"],"sourcesContent":["export * from './If';\n"],"mappings":"AAAA,cAAc;","names":[]}
@@ -0,0 +1,11 @@
1
+ import { List, Optional, PageList, PageOptions, Validatable } from '@thisisagile/easy';
2
+ export declare const useToggle: (initialState?: boolean) => [boolean, () => void];
3
+ export declare const useA: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
4
+ export declare const useAn: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
5
+ export declare const useOptional: <E>(item?: Partial<E> | undefined) => [E, (e: Optional<E>) => Optional<E>, () => Optional<E>];
6
+ export declare const useEntity: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
7
+ export declare const useList: <E>(...items: E[]) => [List<E>, (e: List<E>) => List<E>];
8
+ export declare const usePageList: <E>(...items: E[]) => [PageList<E>, (e: PageList<E>) => PageList<E>];
9
+ export declare const usePaging: <E>(f: (options?: PageOptions) => Promise<PageList<E>>, options?: PageOptions) => [PageList<E>, (options?: PageOptions) => Promise<PageList<E>>, boolean, number, number];
10
+ export declare const useGet: <E>(f: () => Promise<E>, initial?: Partial<E> | undefined) => [E, () => Promise<E>];
11
+ export declare const useGetList: <E>(f: () => Promise<List<E>>) => [List<E>, () => Promise<PageList<E>>];
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var Hooks_exports = {};
20
+ __export(Hooks_exports, {
21
+ useA: () => useA,
22
+ useAn: () => useAn,
23
+ useEntity: () => useEntity,
24
+ useGet: () => useGet,
25
+ useGetList: () => useGetList,
26
+ useList: () => useList,
27
+ useOptional: () => useOptional,
28
+ usePageList: () => usePageList,
29
+ usePaging: () => usePaging,
30
+ useToggle: () => useToggle
31
+ });
32
+ module.exports = __toCommonJS(Hooks_exports);
33
+ var import_easy = require("@thisisagile/easy");
34
+ var import_react = require("react");
35
+ const useToggle = (initialState = false) => {
36
+ const [state, setState] = (0, import_react.useState)(initialState);
37
+ return [state, () => setState((s) => !s)];
38
+ };
39
+ const useA = (item = {}) => {
40
+ const [state, setState] = (0, import_react.useState)({ isValid: false, ...item });
41
+ return [
42
+ state,
43
+ (e) => {
44
+ setState(e);
45
+ return e;
46
+ }
47
+ ];
48
+ };
49
+ const useAn = useA;
50
+ const useOptional = (item) => {
51
+ const [state, setState] = (0, import_react.useState)(item);
52
+ const set = (e) => {
53
+ setState(e);
54
+ return e;
55
+ };
56
+ return [state, set, () => set()];
57
+ };
58
+ const useEntity = useA;
59
+ const useList = (...items) => {
60
+ const [state, setState] = (0, import_react.useState)((0, import_easy.toList)(...items));
61
+ return [
62
+ state,
63
+ (e) => {
64
+ setState(e);
65
+ return e;
66
+ }
67
+ ];
68
+ };
69
+ const usePageList = (...items) => {
70
+ const [pages, setPages] = (0, import_react.useState)((0, import_easy.toPageList)(items));
71
+ return [
72
+ pages,
73
+ (e) => {
74
+ setPages(e);
75
+ return e;
76
+ }
77
+ ];
78
+ };
79
+ const usePaging = (f, options) => {
80
+ const [list, setList] = usePageList();
81
+ const [skip, setSkip] = (0, import_react.useState)(options?.skip ?? 0);
82
+ const [take] = (0, import_react.useState)(options?.take ?? 5);
83
+ const next = (options2 = { skip, take }) => f(options2).then((items) => {
84
+ setSkip(skip + take);
85
+ return setList((0, import_easy.toPageList)(list.add(items), items));
86
+ });
87
+ return [list, next, list.length < (list?.total ?? 0), skip, take];
88
+ };
89
+ const useGet = (f, initial) => {
90
+ const [item, setItem] = (0, import_react.useState)(initial ?? {});
91
+ const getter = () => f().then((i) => {
92
+ setItem(i);
93
+ return i;
94
+ });
95
+ return [item, getter];
96
+ };
97
+ const useGetList = (f) => {
98
+ const [list, setList] = usePageList();
99
+ const getter = () => f().then((l) => setList((0, import_easy.isPageList)(l) ? l : (0, import_easy.toPageList)(l, { total: l.length })));
100
+ return [list, getter];
101
+ };
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ useA,
105
+ useAn,
106
+ useEntity,
107
+ useGet,
108
+ useGetList,
109
+ useList,
110
+ useOptional,
111
+ usePageList,
112
+ usePaging,
113
+ useToggle
114
+ });
115
+ //# sourceMappingURL=Hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/Hooks.ts"],"sourcesContent":["import { isPageList, List, Optional, PageList, PageOptions, toList, toPageList, Validatable } from '@thisisagile/easy';\nimport { useState } from 'react';\n\nexport const useToggle = (initialState = false): [boolean, () => void] => {\n const [state, setState] = useState<boolean>(initialState);\n return [state, () => setState(s => !s)];\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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmG;AACnG,mBAAyB;AAElB,MAAM,YAAY,CAAC,eAAe,UAAiC;AACxE,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAkB,YAAY;AACxD,SAAO,CAAC,OAAO,MAAM,SAAS,OAAK,CAAC,CAAC,CAAC;AACxC;AAEO,MAAM,OAAO,CAAwB,OAAmB,CAAC,MAAsC;AACpG,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAY,EAAE,SAAS,OAAO,GAAG,KAAK,CAAM;AACtE,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAY;AACX,eAAS,CAAC;AACV,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,QAAQ;AAEd,MAAM,cAAc,CAAI,SAA+E;AAC5G,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAY,IAAS;AAC/C,QAAM,MAAM,CAAC,MAAiC;AAC5C,aAAS,CAAM;AACf,WAAO;AAAA,EACT;AACA,SAAO,CAAC,OAAO,KAAK,MAAmB,IAAI,CAAC;AAC9C;AAEO,MAAM,YAAY;AAElB,MAAM,UAAU,IAAO,UAAmD;AAC/E,QAAM,CAAC,OAAO,QAAQ,QAAI,2BAAkB,oBAAU,GAAG,KAAK,CAAC;AAC/D,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAwB;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
+ import { isPageList, toList, toPageList } from "@thisisagile/easy";
2
+ import { useState } from "react";
3
+ const useToggle = (initialState = false) => {
4
+ const [state, setState] = useState(initialState);
5
+ return [state, () => setState((s) => !s)];
6
+ };
7
+ const useA = (item = {}) => {
8
+ const [state, setState] = useState({ isValid: false, ...item });
9
+ return [
10
+ state,
11
+ (e) => {
12
+ setState(e);
13
+ return e;
14
+ }
15
+ ];
16
+ };
17
+ const useAn = useA;
18
+ const useOptional = (item) => {
19
+ const [state, setState] = useState(item);
20
+ const set = (e) => {
21
+ setState(e);
22
+ return e;
23
+ };
24
+ return [state, set, () => set()];
25
+ };
26
+ const useEntity = useA;
27
+ const useList = (...items) => {
28
+ const [state, setState] = useState(toList(...items));
29
+ return [
30
+ state,
31
+ (e) => {
32
+ setState(e);
33
+ return e;
34
+ }
35
+ ];
36
+ };
37
+ const usePageList = (...items) => {
38
+ const [pages, setPages] = useState(toPageList(items));
39
+ return [
40
+ pages,
41
+ (e) => {
42
+ setPages(e);
43
+ return e;
44
+ }
45
+ ];
46
+ };
47
+ const usePaging = (f, options) => {
48
+ const [list, setList] = usePageList();
49
+ const [skip, setSkip] = useState(options?.skip ?? 0);
50
+ const [take] = useState(options?.take ?? 5);
51
+ const next = (options2 = { skip, take }) => f(options2).then((items) => {
52
+ setSkip(skip + take);
53
+ return setList(toPageList(list.add(items), items));
54
+ });
55
+ return [list, next, list.length < (list?.total ?? 0), skip, take];
56
+ };
57
+ const useGet = (f, initial) => {
58
+ const [item, setItem] = useState(initial ?? {});
59
+ const getter = () => f().then((i) => {
60
+ setItem(i);
61
+ return i;
62
+ });
63
+ return [item, getter];
64
+ };
65
+ const useGetList = (f) => {
66
+ const [list, setList] = usePageList();
67
+ const getter = () => f().then((l) => setList(isPageList(l) ? l : toPageList(l, { total: l.length })));
68
+ return [list, getter];
69
+ };
70
+ export {
71
+ useA,
72
+ useAn,
73
+ useEntity,
74
+ useGet,
75
+ useGetList,
76
+ useList,
77
+ useOptional,
78
+ usePageList,
79
+ usePaging,
80
+ useToggle
81
+ };
82
+ //# sourceMappingURL=Hooks.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/Hooks.ts"],"sourcesContent":["import { isPageList, List, Optional, PageList, PageOptions, toList, toPageList, Validatable } from '@thisisagile/easy';\nimport { useState } from 'react';\n\nexport const useToggle = (initialState = false): [boolean, () => void] => {\n const [state, setState] = useState<boolean>(initialState);\n return [state, () => setState(s => !s)];\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":"AAAA,SAAS,YAAmD,QAAQ,kBAA+B;AACnG,SAAS,gBAAgB;AAElB,MAAM,YAAY,CAAC,eAAe,UAAiC;AACxE,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkB,YAAY;AACxD,SAAO,CAAC,OAAO,MAAM,SAAS,OAAK,CAAC,CAAC,CAAC;AACxC;AAEO,MAAM,OAAO,CAAwB,OAAmB,CAAC,MAAsC;AACpG,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,EAAE,SAAS,OAAO,GAAG,KAAK,CAAM;AACtE,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAY;AACX,eAAS,CAAC;AACV,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,QAAQ;AAEd,MAAM,cAAc,CAAI,SAA+E;AAC5G,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAY,IAAS;AAC/C,QAAM,MAAM,CAAC,MAAiC;AAC5C,aAAS,CAAM;AACf,WAAO;AAAA,EACT;AACA,SAAO,CAAC,OAAO,KAAK,MAAmB,IAAI,CAAC;AAC9C;AAEO,MAAM,YAAY;AAElB,MAAM,UAAU,IAAO,UAAmD;AAC/E,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAkB,OAAU,GAAG,KAAK,CAAC;AAC/D,SAAO;AAAA,IACL;AAAA,IACA,CAAC,MAAwB;AACvB,eAAS,CAAC;AACV,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,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+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var utils_exports = {};
17
+ module.exports = __toCommonJS(utils_exports);
18
+ __reExport(utils_exports, require("./Hooks"), module.exports);
19
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./Hooks")
22
+ });
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './Hooks';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,oBAAd;","names":[]}
@@ -0,0 +1,2 @@
1
+ export * from "./Hooks";
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './Hooks';\n"],"mappings":"AAAA,cAAc;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy-react",
3
- "version": "15.8.5",
3
+ "version": "15.8.7",
4
4
  "description": "Straightforward library building micro applications in react",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
@@ -22,7 +22,7 @@
22
22
  "lint": "yarn g:eslint . --ext .js,.jsx,.ts,.tsx --fix",
23
23
  "format": "yarn g:prettier --check --write src test *.json",
24
24
  "build": "yarn g:tsc",
25
- "build:tsup": "yarn g:tsup",
25
+ "build:tsup": "yarn g:tsup --onSuccess \"yarn g:tsc --emitDeclarationOnly --declaration\"",
26
26
  "postbuild": "copyfiles -u 1 src/**/*.scss dist",
27
27
  "test": "yarn g:jest --coverage",
28
28
  "prepack": "yarn g:copy-readme",
@@ -36,8 +36,8 @@
36
36
  "access": "public"
37
37
  },
38
38
  "devDependencies": {
39
- "@thisisagile/easy-test": "15.8.5",
40
- "@thisisagile/easy-test-react": "15.8.5",
39
+ "@thisisagile/easy-test": "15.8.7",
40
+ "@thisisagile/easy-test-react": "15.8.7",
41
41
  "@types/copyfiles": "^2.4.1",
42
42
  "copyfiles": "^2.4.1",
43
43
  "jest-environment-jsdom": "^29.5.0",
@@ -46,7 +46,7 @@
46
46
  "next-transpile-modules": "^10.0.0"
47
47
  },
48
48
  "dependencies": {
49
- "@thisisagile/easy": "^15.8.5",
49
+ "@thisisagile/easy": "^15.8.7",
50
50
  "react": "^18.2.0",
51
51
  "react-dom": "^18.2.0",
52
52
  "sass": "^1.62.1"
package/dist/index.d.mts DELETED
@@ -1,21 +0,0 @@
1
- import { ReactNode, FunctionComponent } from 'react';
2
- import { Validatable, Optional, List, PageList, PageOptions } from '@thisisagile/easy';
3
-
4
- interface IfProps {
5
- condition: any | undefined;
6
- children?: ReactNode;
7
- }
8
- declare const If: FunctionComponent<IfProps>;
9
-
10
- declare const useToggle: (initialState?: boolean) => [boolean, () => void];
11
- declare const useA: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
12
- declare const useAn: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
13
- declare const useOptional: <E>(item?: Partial<E> | undefined) => [E, (e: Optional<E>) => Optional<E>, () => Optional<E>];
14
- declare const useEntity: <E extends Validatable>(item?: Partial<E>) => [E, (e: E) => E];
15
- declare const useList: <E>(...items: E[]) => [List<E>, (e: List<E>) => List<E>];
16
- declare const usePageList: <E>(...items: E[]) => [PageList<E>, (e: PageList<E>) => PageList<E>];
17
- declare const usePaging: <E>(f: (options?: PageOptions) => Promise<PageList<E>>, options?: PageOptions) => [PageList<E>, (options?: PageOptions) => Promise<PageList<E>>, boolean, number, number];
18
- declare const useGet: <E>(f: () => Promise<E>, initial?: Partial<E> | undefined) => [E, () => Promise<E>];
19
- declare const useGetList: <E>(f: () => Promise<List<E>>) => [List<E>, () => Promise<PageList<E>>];
20
-
21
- export { If, IfProps, useA, useAn, useEntity, useGet, useGetList, useList, useOptional, usePageList, usePaging, useToggle };