@openbytes/ts-react-directives 0.2.3 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/dist/ts-react-directives.cjs.js +1 -2
- package/dist/ts-react-directives.d.ts +5 -5
- package/dist/ts-react-directives.es.js +48 -54
- package/dist/ts-react-directives.umd.js +2 -3
- package/package.json +37 -7
- package/dist/ts-react-directives.cjs.js.map +0 -1
- package/dist/ts-react-directives.es.js.map +0 -1
- package/dist/ts-react-directives.umd.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,6 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
**ts-react-directives** is a small React/Typescript library designed to mimic 'Angular' directives. This is not static library. It's meant to be used as declarative component. Also, it alleviates the limitations and cognitive complexity created by the ternary operations when using conditional rendering.
|
|
6
6
|
|
|
7
|
+
## How to install
|
|
8
|
+
|
|
9
|
+
Using NPM
|
|
10
|
+
|
|
11
|
+
```npm
|
|
12
|
+
npm install @openbytes/ts-react-directives
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Using PNPM (preferred)
|
|
16
|
+
|
|
17
|
+
```pnpm
|
|
18
|
+
pnpm add @openbytes/ts-react-directives
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Demo
|
|
22
|
+
|
|
23
|
+
[Go to the demo/examples project](https://skycodr.github.io/ts-react-directives/)
|
|
24
|
+
|
|
7
25
|
## Authors
|
|
8
26
|
|
|
9
27
|
[AUTHORS](./AUTHORS.md)
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const
|
|
2
|
-
//# sourceMappingURL=ts-react-directives.cjs.js.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require('./index.css');const d=require("react/jsx-runtime"),o=require("react");var c=(e=>(e[e.IfBlockExpected=2001]="IfBlockExpected",e[e.OnlyOneIfBlockExpected=2002]="OnlyOneIfBlockExpected",e[e.OnlyOneElseBlockExpected=2003]="OnlyOneElseBlockExpected",e[e.CheckBlockExpected=2005]="CheckBlockExpected",e[e.InvalidIfBlockOrdinal=2004]="InvalidIfBlockOrdinal",e[e.InvalidElseBlockOrdinal=2006]="InvalidElseBlockOrdinal",e[e.InvalidElseIfBlockOrdinal=2007]="InvalidElseIfBlockOrdinal",e[e.InvalidElement=3002]="InvalidElement",e[e.ChildrenExpected=3003]="ChildrenExpected",e))(c||{}),t=(e=>(e.If="If",e.ElseIf="ElseIf",e.Else="Else",e.Check="Check",e.Unknown="Unknown",e))(t||{});const p={[c.IfBlockExpected]:"Missing 'If'",[c.OnlyOneIfBlockExpected]:"Can only have one 'If'",[c.OnlyOneElseBlockExpected]:"Can only have one 'Else'",[c.CheckBlockExpected]:"'If', 'ElseIf', 'Else' need to be wrapped in 'Check'",[c.InvalidElseBlockOrdinal]:"Invalid ordinals, 'Else' should be the last",[c.InvalidIfBlockOrdinal]:"Invalid ordinals, 'If' block should be the first",[c.InvalidElseIfBlockOrdinal]:"Invalid ordinals, cannot have 'ElseIf' before 'If'",[c.ChildrenExpected]:"Should at least have one child",[c.InvalidElement]:"Invalid element"},f=({errors:e})=>d.jsx("ol",{className:"trd-error-list",children:e.map((l,n)=>d.jsx("li",{children:p[l]},`${l}-${n}`))}),v=e=>{const l=[];return e.length===0?(l.push(c.ChildrenExpected),l):(e.forEach(n=>{const{displayName:s=t.Unknown}=n.type??{};(s===t.If||s===t.ElseIf||s===t.Else)&&(l.push(c.InvalidElement),l.push(c.CheckBlockExpected))}),l)},B=e=>{const l=[],n={};return e.length===0?(l.push(c.ChildrenExpected,c.IfBlockExpected),l):(e.forEach((s,a)=>{const{displayName:i=t.Unknown}=s.type,u=n[i]??0;n[i]=u+1,O(i,a,n,l),x(i,a,e.length,n,l),C(i,a,l),m(i,l)}),n[t.If]||l.push(c.IfBlockExpected),l)},O=(e,l,n,s)=>{e===t.If&&(l!==0&&s.push(c.InvalidIfBlockOrdinal),n[t.If]>1&&s.push(c.OnlyOneIfBlockExpected))},x=(e,l,n,s,a)=>{e===t.Else&&(s[t.Else]>1&&a.push(c.OnlyOneElseBlockExpected),(l===0||l!==n-1)&&a.push(c.InvalidElseBlockOrdinal))},C=(e,l,n)=>{e===t.ElseIf&&l===0&&n.push(c.InvalidElseIfBlockOrdinal)},m=(e,l)=>{e!==t.If&&e!==t.ElseIf&&e!==t.Else&&l.push(c.InvalidElement)};class y{static get(l){let n=()=>[];switch(l){case t.Check:n=B;break;case t.If:case t.ElseIf:case t.Else:n=v;break}return n}}const I=(e,l)=>{const{children:n}=e,s=o.Children.toArray(n);return y.get(l)(s)},j=e=>{const l=I(e,t.Check);if(l.length)return{children:o.createElement(f,{errors:l})};const s=o.Children.toArray(e.children).filter(o.isValidElement);return{children:b(s)}},b=e=>{for(const l of e){if(!l||!o.isValidElement(l))continue;const{displayName:n}=l.type;if(n){const{condition:s}=l.props;if((n==="If"||n==="ElseIf")&&s===!0||n==="Else")return l}}return null},h=e=>{const{children:l}=j(e);return d.jsx(d.Fragment,{children:l})};h.displayName=t.Check;const E=e=>{const l=I(e,"If"),{condition:n}=e,s=l.length===0?e.children:d.jsx(f,{errors:l});return d.jsx(d.Fragment,{children:n&&s})};E.displayName=t.If;const r=e=>{const l=I(e,"ElseIf"),{condition:n}=e,s=l.length===0?e.children:d.jsx(f,{errors:l});return d.jsx(d.Fragment,{children:n&&s})};r.displayName=t.ElseIf;const k=e=>{const l=I(e,"Else"),n=l.length===0?e.children:d.jsx(f,{errors:l});return d.jsx(d.Fragment,{children:n})};k.displayName=t.Else;exports.Check=h;exports.Else=k;exports.ElseIf=r;exports.If=E;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
|
+
export declare const Check: FC<PropsWithChildren<CheckProps>>;
|
|
5
|
+
|
|
6
|
+
export declare type CheckProps = {};
|
|
7
|
+
|
|
4
8
|
export declare const Else: FC<PropsWithChildren<ElseProps>>;
|
|
5
9
|
|
|
6
10
|
export declare const ElseIf: FC<ElseIfProps>;
|
|
@@ -9,7 +13,7 @@ export declare type ElseIfProps = PropsWithChildren<{
|
|
|
9
13
|
condition: boolean;
|
|
10
14
|
}>;
|
|
11
15
|
|
|
12
|
-
declare type ElseProps = {};
|
|
16
|
+
export declare type ElseProps = {};
|
|
13
17
|
|
|
14
18
|
export declare const If: FC<IfProps>;
|
|
15
19
|
|
|
@@ -17,8 +21,4 @@ export declare type IfProps = PropsWithChildren<{
|
|
|
17
21
|
condition: boolean;
|
|
18
22
|
}>;
|
|
19
23
|
|
|
20
|
-
export declare const SwitchIf: FC<PropsWithChildren<SwitchIfProps>>;
|
|
21
|
-
|
|
22
|
-
declare type SwitchIfProps = {};
|
|
23
|
-
|
|
24
24
|
export { }
|
|
@@ -1,103 +1,97 @@
|
|
|
1
|
-
import { jsx as s, Fragment as
|
|
2
|
-
import { Children as
|
|
3
|
-
import './index.css';var c = /* @__PURE__ */ ((e) => (e[e.IfBlockExpected = 2001] = "IfBlockExpected", e[e.OnlyOneIfBlockExpected = 2002] = "OnlyOneIfBlockExpected", e[e.OnlyOneElseBlockExpected = 2003] = "OnlyOneElseBlockExpected", e[e.
|
|
4
|
-
const
|
|
1
|
+
import { jsx as s, Fragment as o } from "react/jsx-runtime";
|
|
2
|
+
import { Children as h, createElement as r, isValidElement as E } from "react";
|
|
3
|
+
import './index.css';var c = /* @__PURE__ */ ((e) => (e[e.IfBlockExpected = 2001] = "IfBlockExpected", e[e.OnlyOneIfBlockExpected = 2002] = "OnlyOneIfBlockExpected", e[e.OnlyOneElseBlockExpected = 2003] = "OnlyOneElseBlockExpected", e[e.CheckBlockExpected = 2005] = "CheckBlockExpected", e[e.InvalidIfBlockOrdinal = 2004] = "InvalidIfBlockOrdinal", e[e.InvalidElseBlockOrdinal = 2006] = "InvalidElseBlockOrdinal", e[e.InvalidElseIfBlockOrdinal = 2007] = "InvalidElseIfBlockOrdinal", e[e.InvalidElement = 3002] = "InvalidElement", e[e.ChildrenExpected = 3003] = "ChildrenExpected", e))(c || {}), t = /* @__PURE__ */ ((e) => (e.If = "If", e.ElseIf = "ElseIf", e.Else = "Else", e.Check = "Check", e.Unknown = "Unknown", e))(t || {});
|
|
4
|
+
const p = {
|
|
5
5
|
[c.IfBlockExpected]: "Missing 'If'",
|
|
6
6
|
[c.OnlyOneIfBlockExpected]: "Can only have one 'If'",
|
|
7
7
|
[c.OnlyOneElseBlockExpected]: "Can only have one 'Else'",
|
|
8
|
-
[c.
|
|
8
|
+
[c.CheckBlockExpected]: "'If', 'ElseIf', 'Else' need to be wrapped in 'Check'",
|
|
9
9
|
[c.InvalidElseBlockOrdinal]: "Invalid ordinals, 'Else' should be the last",
|
|
10
10
|
[c.InvalidIfBlockOrdinal]: "Invalid ordinals, 'If' block should be the first",
|
|
11
11
|
[c.InvalidElseIfBlockOrdinal]: "Invalid ordinals, cannot have 'ElseIf' before 'If'",
|
|
12
12
|
[c.ChildrenExpected]: "Should at least have one child",
|
|
13
13
|
[c.InvalidElement]: "Invalid element"
|
|
14
|
-
},
|
|
14
|
+
}, f = ({ errors: e }) => /* @__PURE__ */ s("ol", { className: "trd-error-list", children: e.map((l, n) => /* @__PURE__ */ s("li", { children: p[l] }, `${l}-${n}`)) }), u = (e) => {
|
|
15
15
|
const l = [];
|
|
16
16
|
return e.length === 0 ? (l.push(c.ChildrenExpected), l) : (e.forEach((n) => {
|
|
17
|
-
const { displayName:
|
|
18
|
-
(
|
|
17
|
+
const { displayName: d = t.Unknown } = n.type ?? {};
|
|
18
|
+
(d === t.If || d === t.ElseIf || d === t.Else) && (l.push(c.InvalidElement), l.push(c.CheckBlockExpected));
|
|
19
19
|
}), l);
|
|
20
|
-
},
|
|
20
|
+
}, v = (e) => {
|
|
21
21
|
const l = [], n = {};
|
|
22
|
-
return
|
|
23
|
-
const { displayName:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}, O = (e, l, n,
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
e === t.Else && (i[t.Else] > 1 && a.push(c.OnlyOneElseBlockExpected), (l === 0 || l !== n - 1) && a.push(c.InvalidElseBlockOrdinal));
|
|
32
|
-
}, y = (e, l, n) => {
|
|
22
|
+
return e.length === 0 ? (l.push(c.ChildrenExpected, c.IfBlockExpected), l) : (e.forEach((d, a) => {
|
|
23
|
+
const { displayName: i = t.Unknown } = d.type, k = n[i] ?? 0;
|
|
24
|
+
n[i] = k + 1, B(i, a, n, l), O(i, a, e.length, n, l), C(i, a, l), m(i, l);
|
|
25
|
+
}), n[t.If] || l.push(c.IfBlockExpected), l);
|
|
26
|
+
}, B = (e, l, n, d) => {
|
|
27
|
+
e === t.If && (l !== 0 && d.push(c.InvalidIfBlockOrdinal), n[t.If] > 1 && d.push(c.OnlyOneIfBlockExpected));
|
|
28
|
+
}, O = (e, l, n, d, a) => {
|
|
29
|
+
e === t.Else && (d[t.Else] > 1 && a.push(c.OnlyOneElseBlockExpected), (l === 0 || l !== n - 1) && a.push(c.InvalidElseBlockOrdinal));
|
|
30
|
+
}, C = (e, l, n) => {
|
|
33
31
|
e === t.ElseIf && l === 0 && n.push(c.InvalidElseIfBlockOrdinal);
|
|
34
|
-
},
|
|
32
|
+
}, m = (e, l) => {
|
|
35
33
|
e !== t.If && e !== t.ElseIf && e !== t.Else && l.push(c.InvalidElement);
|
|
36
34
|
};
|
|
37
|
-
class
|
|
35
|
+
class y {
|
|
38
36
|
static get(l) {
|
|
39
37
|
let n = () => [];
|
|
40
38
|
switch (l) {
|
|
41
|
-
case t.
|
|
42
|
-
|
|
39
|
+
case t.Check:
|
|
40
|
+
n = v;
|
|
43
41
|
break;
|
|
44
42
|
case t.If:
|
|
45
43
|
case t.ElseIf:
|
|
46
44
|
case t.Else:
|
|
47
|
-
|
|
45
|
+
n = u;
|
|
48
46
|
break;
|
|
49
47
|
}
|
|
50
48
|
return n;
|
|
51
49
|
}
|
|
52
50
|
}
|
|
53
|
-
const
|
|
54
|
-
const n =
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
const
|
|
58
|
-
return m.get(l)(i);
|
|
59
|
-
}, S = (e) => {
|
|
60
|
-
const l = h(e, "SwitchIf");
|
|
51
|
+
const I = (e, l) => {
|
|
52
|
+
const { children: n } = e, d = h.toArray(n);
|
|
53
|
+
return y.get(l)(d);
|
|
54
|
+
}, x = (e) => {
|
|
55
|
+
const l = I(e, t.Check);
|
|
61
56
|
if (l.length)
|
|
62
|
-
return { children:
|
|
63
|
-
const
|
|
64
|
-
return { children: b(
|
|
57
|
+
return { children: r(f, { errors: l }) };
|
|
58
|
+
const d = h.toArray(e.children).filter(E);
|
|
59
|
+
return { children: b(d) };
|
|
65
60
|
}, b = (e) => {
|
|
66
61
|
for (const l of e) {
|
|
67
|
-
if (!l || !
|
|
62
|
+
if (!l || !E(l))
|
|
68
63
|
continue;
|
|
69
64
|
const { displayName: n } = l.type;
|
|
70
65
|
if (n) {
|
|
71
|
-
const { condition:
|
|
72
|
-
if ((n === "If" || n === "ElseIf") &&
|
|
66
|
+
const { condition: d } = l.props;
|
|
67
|
+
if ((n === "If" || n === "ElseIf") && d === !0 || n === "Else")
|
|
73
68
|
return l;
|
|
74
69
|
}
|
|
75
70
|
}
|
|
76
71
|
return null;
|
|
77
|
-
},
|
|
78
|
-
const { children: l } =
|
|
79
|
-
return /* @__PURE__ */ s(
|
|
72
|
+
}, w = (e) => {
|
|
73
|
+
const { children: l } = x(e);
|
|
74
|
+
return /* @__PURE__ */ s(o, { children: l });
|
|
80
75
|
};
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
const l =
|
|
84
|
-
return /* @__PURE__ */ s(
|
|
76
|
+
w.displayName = t.Check;
|
|
77
|
+
const N = (e) => {
|
|
78
|
+
const l = I(e, "If"), { condition: n } = e, d = l.length === 0 ? e.children : /* @__PURE__ */ s(f, { errors: l });
|
|
79
|
+
return /* @__PURE__ */ s(o, { children: n && d });
|
|
85
80
|
};
|
|
86
|
-
|
|
81
|
+
N.displayName = t.If;
|
|
87
82
|
const U = (e) => {
|
|
88
|
-
const l =
|
|
89
|
-
return /* @__PURE__ */ s(
|
|
83
|
+
const l = I(e, "ElseIf"), { condition: n } = e, d = l.length === 0 ? e.children : /* @__PURE__ */ s(f, { errors: l });
|
|
84
|
+
return /* @__PURE__ */ s(o, { children: n && d });
|
|
90
85
|
};
|
|
91
86
|
U.displayName = t.ElseIf;
|
|
92
87
|
const F = (e) => {
|
|
93
|
-
const l =
|
|
94
|
-
return /* @__PURE__ */ s(
|
|
88
|
+
const l = I(e, "Else"), n = l.length === 0 ? e.children : /* @__PURE__ */ s(f, { errors: l });
|
|
89
|
+
return /* @__PURE__ */ s(o, { children: n });
|
|
95
90
|
};
|
|
96
91
|
F.displayName = t.Else;
|
|
97
92
|
export {
|
|
93
|
+
w as Check,
|
|
98
94
|
F as Else,
|
|
99
95
|
U as ElseIf,
|
|
100
|
-
|
|
101
|
-
C as SwitchIf
|
|
96
|
+
N as If
|
|
102
97
|
};
|
|
103
|
-
//# sourceMappingURL=ts-react-directives.es.js.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
(function(o
|
|
2
|
-
/*$vite$:1*/`,document.head.appendChild(
|
|
3
|
-
//# sourceMappingURL=ts-react-directives.umd.js.map
|
|
1
|
+
(function(a,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],o):(a=typeof globalThis<"u"?globalThis:a||self,o(a["ts-react-directives"]={},a["react/jsx-runtime"],a.React))})(this,function(a,o,i){"use strict";var I=document.createElement("style");I.textContent=`:root{--trd-color: 255, 100, 200;--trd-bg-color: 0, 100, 200}ol.trd-error-list{border:.2rem double rgb(var(--trd-bg-color));background-color:rgba(var(--trd-bg-color),.1);list-style-type:none;box-sizing:border-box;padding:.5rem;margin:0}.trd-error-list>li{color:#000;background-color:rgba(var(--trd-color),.1);padding:.125rem;margin:.125rem;border:2px solid rgb(var(--trd-color));font-size:1.5rem;font-family:monospace}.trd-error-list>li:before{content:"🛈 ";font-size:1.5rem;padding-left:.125rem;margin-right:.125rem}
|
|
2
|
+
/*$vite$:1*/`,document.head.appendChild(I);var d=(e=>(e[e.IfBlockExpected=2001]="IfBlockExpected",e[e.OnlyOneIfBlockExpected=2002]="OnlyOneIfBlockExpected",e[e.OnlyOneElseBlockExpected=2003]="OnlyOneElseBlockExpected",e[e.CheckBlockExpected=2005]="CheckBlockExpected",e[e.InvalidIfBlockOrdinal=2004]="InvalidIfBlockOrdinal",e[e.InvalidElseBlockOrdinal=2006]="InvalidElseBlockOrdinal",e[e.InvalidElseIfBlockOrdinal=2007]="InvalidElseIfBlockOrdinal",e[e.InvalidElement=3002]="InvalidElement",e[e.ChildrenExpected=3003]="ChildrenExpected",e))(d||{}),t=(e=>(e.If="If",e.ElseIf="ElseIf",e.Else="Else",e.Check="Check",e.Unknown="Unknown",e))(t||{});const v={[d.IfBlockExpected]:"Missing 'If'",[d.OnlyOneIfBlockExpected]:"Can only have one 'If'",[d.OnlyOneElseBlockExpected]:"Can only have one 'Else'",[d.CheckBlockExpected]:"'If', 'ElseIf', 'Else' need to be wrapped in 'Check'",[d.InvalidElseBlockOrdinal]:"Invalid ordinals, 'Else' should be the last",[d.InvalidIfBlockOrdinal]:"Invalid ordinals, 'If' block should be the first",[d.InvalidElseIfBlockOrdinal]:"Invalid ordinals, cannot have 'ElseIf' before 'If'",[d.ChildrenExpected]:"Should at least have one child",[d.InvalidElement]:"Invalid element"},f=({errors:e})=>o.jsx("ol",{className:"trd-error-list",children:e.map((l,n)=>o.jsx("li",{children:v[l]},`${l}-${n}`))}),m=e=>{const l=[];return e.length===0?(l.push(d.ChildrenExpected),l):(e.forEach(n=>{const{displayName:c=t.Unknown}=n.type??{};(c===t.If||c===t.ElseIf||c===t.Else)&&(l.push(d.InvalidElement),l.push(d.CheckBlockExpected))}),l)},y=e=>{const l=[],n={};return e.length===0?(l.push(d.ChildrenExpected,d.IfBlockExpected),l):(e.forEach((c,s)=>{const{displayName:r=t.Unknown}=c.type,F=n[r]??0;n[r]=F+1,B(r,s,n,l),O(r,s,e.length,n,l),C(r,s,l),b(r,l)}),n[t.If]||l.push(d.IfBlockExpected),l)},B=(e,l,n,c)=>{e===t.If&&(l!==0&&c.push(d.InvalidIfBlockOrdinal),n[t.If]>1&&c.push(d.OnlyOneIfBlockExpected))},O=(e,l,n,c,s)=>{e===t.Else&&(c[t.Else]>1&&s.push(d.OnlyOneElseBlockExpected),(l===0||l!==n-1)&&s.push(d.InvalidElseBlockOrdinal))},C=(e,l,n)=>{e===t.ElseIf&&l===0&&n.push(d.InvalidElseIfBlockOrdinal)},b=(e,l)=>{e!==t.If&&e!==t.ElseIf&&e!==t.Else&&l.push(d.InvalidElement)};class x{static get(l){let n=()=>[];switch(l){case t.Check:n=y;break;case t.If:case t.ElseIf:case t.Else:n=m;break}return n}}const h=(e,l)=>{const{children:n}=e,c=i.Children.toArray(n);return x.get(l)(c)},g=e=>{const l=h(e,t.Check);if(l.length)return{children:i.createElement(f,{errors:l})};const c=i.Children.toArray(e.children).filter(i.isValidElement);return{children:w(c)}},w=e=>{for(const l of e){if(!l||!i.isValidElement(l))continue;const{displayName:n}=l.type;if(n){const{condition:c}=l.props;if((n==="If"||n==="ElseIf")&&c===!0||n==="Else")return l}}return null},E=e=>{const{children:l}=g(e);return o.jsx(o.Fragment,{children:l})};E.displayName=t.Check;const k=e=>{const l=h(e,"If"),{condition:n}=e,c=l.length===0?e.children:o.jsx(f,{errors:l});return o.jsx(o.Fragment,{children:n&&c})};k.displayName=t.If;const p=e=>{const l=h(e,"ElseIf"),{condition:n}=e,c=l.length===0?e.children:o.jsx(f,{errors:l});return o.jsx(o.Fragment,{children:n&&c})};p.displayName=t.ElseIf;const u=e=>{const l=h(e,"Else"),n=l.length===0?e.children:o.jsx(f,{errors:l});return o.jsx(o.Fragment,{children:n})};u.displayName=t.Else,a.Check=E,a.Else=u,a.ElseIf=p,a.If=k,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openbytes/ts-react-directives",
|
|
3
|
-
"
|
|
3
|
+
"description": "A collection of React directives to simplify conditional rendering and loops.",
|
|
4
|
+
"version": "1.0.1",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"author": {
|
|
6
7
|
"name": "SkyCodr (aka: Dulan Sudasinghe)",
|
|
@@ -8,9 +9,29 @@
|
|
|
8
9
|
},
|
|
9
10
|
"license": "MIT",
|
|
10
11
|
"files": [
|
|
11
|
-
"dist"
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
12
14
|
],
|
|
13
|
-
"
|
|
15
|
+
"keywords": [
|
|
16
|
+
"react",
|
|
17
|
+
"typescript",
|
|
18
|
+
"directives",
|
|
19
|
+
"conditionals",
|
|
20
|
+
"if",
|
|
21
|
+
"loops",
|
|
22
|
+
"rendering",
|
|
23
|
+
"conditional rendering"
|
|
24
|
+
],
|
|
25
|
+
"homepage": "https://skycodr.github.io/ts-react-directives/",
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/skycodr/ts-react-directives.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/skycodr/ts-react-directives/issues"
|
|
32
|
+
},
|
|
33
|
+
"readme": "README.md",
|
|
34
|
+
"types": "dist/ts-react-directives.d.ts",
|
|
14
35
|
"main": "dist/ts-react-directives.cjs.js",
|
|
15
36
|
"module": "dist/ts-react-directives.es.js",
|
|
16
37
|
"exports": {
|
|
@@ -37,6 +58,7 @@
|
|
|
37
58
|
"@testing-library/react": "^16.2.0",
|
|
38
59
|
"@types/react": "^19.0.8",
|
|
39
60
|
"@types/react-dom": "^19.0.3",
|
|
61
|
+
"@types/react-syntax-highlighter": "^15.5.13",
|
|
40
62
|
"@vitejs/plugin-react": "^4.3.4",
|
|
41
63
|
"@vitest/coverage-v8": "^3.0.5",
|
|
42
64
|
"@vitest/ui": "^3.0.5",
|
|
@@ -46,11 +68,15 @@
|
|
|
46
68
|
"eslint-plugin-react": "^7.37.4",
|
|
47
69
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
48
70
|
"eslint-plugin-react-refresh": "^0.4.19",
|
|
71
|
+
"gh-pages": "^6.3.0",
|
|
49
72
|
"globals": "^15.15.0",
|
|
50
73
|
"husky": "^9.1.7",
|
|
51
74
|
"jsdom": "^26.0.0",
|
|
52
75
|
"lint-staged": "^15.4.3",
|
|
53
76
|
"prettier": "^3.5.1",
|
|
77
|
+
"react-syntax-highlighter": "^15.6.1",
|
|
78
|
+
"react-tabs": "^6.1.0",
|
|
79
|
+
"rimraf": "^6.0.1",
|
|
54
80
|
"typescript": "~5.7.3",
|
|
55
81
|
"typescript-eslint": "^8.24.0",
|
|
56
82
|
"vite": "^6.1.0",
|
|
@@ -68,15 +94,19 @@
|
|
|
68
94
|
},
|
|
69
95
|
"scripts": {
|
|
70
96
|
"dev": "vite",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
97
|
+
"clean": "rimraf dist",
|
|
98
|
+
"preview": "vite preview --config vite.config.examples.ts",
|
|
99
|
+
"build:lib": "tsc -b && vite build",
|
|
100
|
+
"build:examples": "tsc -b && vite build --config vite.config.examples.ts",
|
|
101
|
+
"build": "&& pnpm build:lib && pnpm build:examples",
|
|
73
102
|
"lint": "eslint src/**/*.{ts,tsx}",
|
|
74
103
|
"lint:fix": "eslint --fix src/**/*.{ts,tsx}",
|
|
104
|
+
"format": "prettier --check src/**/*.{ts,tsx}",
|
|
75
105
|
"format:fix": "prettier --write src/**/*.{ts,tsx}",
|
|
76
|
-
"format:check": "prettier --check src/**/*.{ts,tsx}",
|
|
77
106
|
"test": "vitest",
|
|
78
107
|
"test:ui": "vitest --ui",
|
|
79
108
|
"test:coverage": "vitest --coverage",
|
|
80
|
-
"publish:registry": "pnpm publish"
|
|
109
|
+
"publish:registry": "pnpm publish",
|
|
110
|
+
"publish:gh-pages": "pnpm build:examples && pnpm gh-pages -d dist/examples"
|
|
81
111
|
}
|
|
82
112
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ts-react-directives.cjs.js","sources":["../src/fixtures/enums.ts","../src/fixtures/constants.ts","../src/components/Errors.tsx","../src/utils/validators.ts","../src/utils/logger.ts","../src/hooks/useValidate.ts","../src/directives/if/SwitchIf.tsx","../src/directives/if/If.tsx","../src/directives/if/ElseIf.tsx","../src/directives/if/Else.tsx"],"sourcesContent":["export enum LogicErrors {\r\n // Switch\r\n IfBlockExpected = 2001,\r\n OnlyOneIfBlockExpected = 2002,\r\n OnlyOneElseBlockExpected = 2003,\r\n SwitchBlockExpected = 2005,\r\n InvalidIfBlockOrdinal = 2004,\r\n InvalidElseBlockOrdinal = 2006,\r\n InvalidElseIfBlockOrdinal = 2007,\r\n\r\n // General\r\n\r\n InvalidElement = 3002,\r\n ChildrenExpected = 3003,\r\n}\r\n\r\nexport enum DirectiveNames {\r\n If = 'If',\r\n ElseIf = 'ElseIf',\r\n Else = 'Else',\r\n SwitchIf = 'SwitchIf',\r\n Unknown = 'Unknown',\r\n}\r\n","import { LogicErrors } from './enums';\r\n\r\nexport const ERRORS: Record<LogicErrors, string> = {\r\n [LogicErrors.IfBlockExpected]: \"Missing 'If'\",\r\n [LogicErrors.OnlyOneIfBlockExpected]: \"Can only have one 'If'\",\r\n [LogicErrors.OnlyOneElseBlockExpected]: \"Can only have one 'Else'\",\r\n [LogicErrors.SwitchBlockExpected]: \"'If', 'ElseIf', 'Else' need to be wrapped in 'Switch'\",\r\n [LogicErrors.InvalidElseBlockOrdinal]: \"Invalid ordinals, 'Else' should be the last\",\r\n [LogicErrors.InvalidIfBlockOrdinal]: \"Invalid ordinals, 'If' block should be the first\",\r\n [LogicErrors.InvalidElseIfBlockOrdinal]: \"Invalid ordinals, cannot have 'ElseIf' before 'If'\",\r\n [LogicErrors.ChildrenExpected]: 'Should at least have one child',\r\n [LogicErrors.InvalidElement]: 'Invalid element',\r\n};\r\n","import { FC } from 'react';\r\nimport { ERRORS, LogicErrors } from '@fixtures';\r\n\r\nimport '@assets/index.css';\r\n\r\ntype ErrorProps = { errors: LogicErrors[] };\r\n\r\nconst Errors: FC<ErrorProps> = ({ errors }) => (\r\n <ol className=\"trd-error-list\">\r\n {errors.map((error, index) => (\r\n <li key={`${error}-${index}`}>{ERRORS[error]}</li>\r\n ))}\r\n </ol>\r\n);\r\n\r\nexport default Errors;\r\n","import { DirectiveNames, LogicErrors } from '@fixtures';\r\nimport { log } from '@utils';\r\n\r\nimport { ReactNode } from 'react';\r\n\r\ntype ValidatorFn = (children: Array<Exclude<ReactNode, boolean | null | undefined>>) => number[];\r\n\r\n/**\r\n * Validate the children of SwitchIf directive\r\n * @param children\r\n * @returns\r\n */\r\nconst validateSwitchIfChildren: ValidatorFn = (children) => {\r\n const errors: LogicErrors[] = [];\r\n\r\n if (children.length === 0) {\r\n errors.push(LogicErrors.ChildrenExpected);\r\n return errors;\r\n }\r\n\r\n children.forEach((child) => {\r\n // @ts-expect-error child.type exist\r\n const { displayName = DirectiveNames.Unknown } = child.type ?? {};\r\n\r\n // If, ElseIf, Else cannot be direct children of If, ElseIf, Else\r\n if (\r\n displayName === DirectiveNames.If ||\r\n displayName === DirectiveNames.ElseIf ||\r\n displayName === DirectiveNames.Else\r\n ) {\r\n log('If, ElseIf, Else cannot be direct children of If, ElseIf, Else');\r\n errors.push(LogicErrors.InvalidElement);\r\n errors.push(LogicErrors.SwitchBlockExpected);\r\n }\r\n });\r\n\r\n return errors;\r\n};\r\n\r\n/**\r\n * Validate the SwitchIf directive\r\n * @param children\r\n * @returns\r\n */\r\nconst validateSwitchIf: ValidatorFn = (children) => {\r\n const errors: LogicErrors[] = [];\r\n const lookupTable: Record<string, number> = {};\r\n\r\n log('1. validate switch if');\r\n\r\n if (children.length === 0) {\r\n log('2. children expected');\r\n errors.push(LogicErrors.ChildrenExpected, LogicErrors.IfBlockExpected);\r\n return errors;\r\n }\r\n\r\n children.forEach((child, index) => {\r\n // @ts-expect-error child.type exist\r\n const { displayName = DirectiveNames.Unknown } = child.type;\r\n log('3. validate switch if - display name', displayName);\r\n\r\n const count = lookupTable[displayName] ?? 0;\r\n lookupTable[displayName] = count + 1;\r\n\r\n log('4. element look up', lookupTable);\r\n\r\n validateIfBlock(displayName, index, lookupTable, errors);\r\n validateElseBlock(displayName, index, children.length, lookupTable, errors);\r\n validateElseIfBlock(displayName, index, errors);\r\n validateSwitchIfInvalidElement(displayName, errors);\r\n });\r\n\r\n if (!lookupTable[DirectiveNames.If]) {\r\n log('5. if block expected - no if in lookup');\r\n errors.push(LogicErrors.IfBlockExpected);\r\n }\r\n\r\n return errors;\r\n};\r\n\r\nconst validateIfBlock = (\r\n elementName: string,\r\n index: number,\r\n elements: Record<string, number>,\r\n errors: LogicErrors[],\r\n) => {\r\n log('6. validate if block', elementName, index, elements);\r\n if (elementName === DirectiveNames.If) {\r\n if (index !== 0) {\r\n errors.push(LogicErrors.InvalidIfBlockOrdinal);\r\n }\r\n\r\n if (elements[DirectiveNames.If] > 1) {\r\n errors.push(LogicErrors.OnlyOneIfBlockExpected);\r\n }\r\n }\r\n};\r\n\r\nconst validateElseBlock = (\r\n elementName: string,\r\n index: number,\r\n length: number,\r\n elements: Record<string, number>,\r\n errors: LogicErrors[],\r\n) => {\r\n if (elementName === DirectiveNames.Else) {\r\n if (elements[DirectiveNames.Else] > 1) {\r\n errors.push(LogicErrors.OnlyOneElseBlockExpected);\r\n }\r\n if (index === 0 || index !== length - 1) {\r\n errors.push(LogicErrors.InvalidElseBlockOrdinal);\r\n }\r\n }\r\n};\r\n\r\nconst validateElseIfBlock = (elementName: string, index: number, errors: LogicErrors[]) => {\r\n if (elementName === DirectiveNames.ElseIf && index === 0) {\r\n errors.push(LogicErrors.InvalidElseIfBlockOrdinal);\r\n }\r\n};\r\n\r\nconst validateSwitchIfInvalidElement = (elementName: string, errors: LogicErrors[]) => {\r\n if (\r\n elementName !== DirectiveNames.If &&\r\n elementName !== DirectiveNames.ElseIf &&\r\n elementName !== DirectiveNames.Else\r\n ) {\r\n errors.push(LogicErrors.InvalidElement);\r\n }\r\n};\r\n\r\nexport class ValidationFactory {\r\n static get(validator: string) {\r\n let validatorFn: ValidatorFn = () => [];\r\n switch (validator) {\r\n case DirectiveNames.SwitchIf:\r\n log('getting validation fn for switch if');\r\n validatorFn = validateSwitchIf;\r\n break;\r\n case DirectiveNames.If:\r\n case DirectiveNames.ElseIf:\r\n case DirectiveNames.Else:\r\n log('getting validation fn for switch if children');\r\n validatorFn = validateSwitchIfChildren;\r\n break;\r\n }\r\n\r\n return validatorFn;\r\n }\r\n}\r\n","export const log = (message: string, ...args: any[]) => {\r\n const msg = `__${message\r\n .trim()\r\n .toLocaleUpperCase()\r\n .replace(/(' ')+/g, '_')}__`;\r\n console.log(msg, ...args);\r\n};\r\n","import { ValidationFactory } from '@utils';\r\nimport { Children, PropsWithChildren } from 'react';\r\n\r\nexport const useValidate = (props: PropsWithChildren, name: string) => {\r\n const { children } = props;\r\n const _children = Children.toArray(children);\r\n\r\n return ValidationFactory.get(name)(_children);\r\n};\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\n\r\nimport {\r\n Children,\r\n createElement,\r\n FC,\r\n FunctionComponent,\r\n isValidElement,\r\n NamedExoticComponent,\r\n PropsWithChildren,\r\n ReactElement,\r\n} from 'react';\r\n\r\nexport type SwitchIfProps = {};\r\n\r\nconst useSwitchIf = (props: PropsWithChildren) => {\r\n const errors = useValidate(props, 'SwitchIf');\r\n\r\n if (errors.length) {\r\n return { children: createElement(Errors, { errors }) };\r\n }\r\n\r\n const elements = Children.toArray(props.children);\r\n const validElements = elements.filter(isValidElement);\r\n const child = findChild(validElements);\r\n\r\n return { children: child };\r\n};\r\n\r\nconst findChild = (elements: ReactElement[]) => {\r\n for (const element of elements) {\r\n if (!element || !isValidElement(element)) {\r\n continue;\r\n }\r\n\r\n const { displayName } = element.type as NamedExoticComponent | FunctionComponent;\r\n\r\n if (displayName) {\r\n const { condition } = element.props as { condition: boolean };\r\n\r\n if ((displayName === 'If' || displayName === 'ElseIf') && condition === true) {\r\n return element;\r\n }\r\n\r\n if (displayName === 'Else') {\r\n return element;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\nconst SwitchIf: FC<PropsWithChildren<SwitchIfProps>> = (props) => {\r\n const { children } = useSwitchIf(props);\r\n return <>{children}</>;\r\n};\r\n\r\nSwitchIf.displayName = DirectiveNames.SwitchIf;\r\n\r\nexport default SwitchIf;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\n\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type IfProps = PropsWithChildren<{\r\n condition: boolean;\r\n}>;\r\n\r\nconst If: FC<IfProps> = (props) => {\r\n const errors = useValidate(props, 'If');\r\n const { condition } = props;\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{condition && children}</>;\r\n};\r\n\r\nIf.displayName = DirectiveNames.If;\r\n\r\nexport default If;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type ElseIfProps = PropsWithChildren<{\r\n condition: boolean;\r\n}>;\r\n\r\nconst ElseIf: FC<ElseIfProps> = (props) => {\r\n const errors = useValidate(props, 'ElseIf');\r\n const { condition } = props;\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{condition && children}</>;\r\n};\r\n\r\nElseIf.displayName = DirectiveNames.ElseIf;\r\n\r\nexport default ElseIf;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type ElseProps = {};\r\n\r\nconst Else: FC<PropsWithChildren<ElseProps>> = (props) => {\r\n const errors = useValidate(props, 'Else');\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{children}</>;\r\n};\r\n\r\nElse.displayName = DirectiveNames.Else;\r\n\r\nexport default Else;\r\n"],"names":["LogicErrors","DirectiveNames","ERRORS","Errors","errors","error","index","jsx","validateSwitchIfChildren","children","child","displayName","log","validateSwitchIf","lookupTable","count","validateIfBlock","validateElseBlock","validateElseIfBlock","validateSwitchIfInvalidElement","elementName","elements","length","ValidationFactory","validator","validatorFn","message","args","msg","useValidate","props","name","_children","Children","useSwitchIf","createElement","validElements","isValidElement","findChild","element","condition","SwitchIf","If","Fragment","ElseIf","Else"],"mappings":"wIAAY,IAAAA,GAAAA,IAEVA,EAAAA,EAAA,gBAAkB,IAAlB,EAAA,kBACAA,EAAAA,EAAA,uBAAyB,IAAzB,EAAA,yBACAA,EAAAA,EAAA,yBAA2B,IAA3B,EAAA,2BACAA,EAAAA,EAAA,oBAAsB,IAAtB,EAAA,sBACAA,EAAAA,EAAA,sBAAwB,IAAxB,EAAA,wBACAA,EAAAA,EAAA,wBAA0B,IAA1B,EAAA,0BACAA,EAAAA,EAAA,0BAA4B,IAA5B,EAAA,4BAIAA,EAAAA,EAAA,eAAiB,IAAjB,EAAA,iBACAA,EAAAA,EAAA,iBAAmB,IAAnB,EAAA,mBAbUA,IAAAA,GAAA,CAAA,CAAA,EAgBAC,GAAAA,IACVA,EAAA,GAAK,KACLA,EAAA,OAAS,SACTA,EAAA,KAAO,OACPA,EAAA,SAAW,WACXA,EAAA,QAAU,UALAA,IAAAA,GAAA,CAAA,CAAA,ECdL,MAAMC,EAAsC,CACjD,CAACF,EAAY,eAAe,EAAG,eAC/B,CAACA,EAAY,sBAAsB,EAAG,yBACtC,CAACA,EAAY,wBA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CAC3B,MAAA1B,EAASyB,EAAYC,EAAO,IAAI,EAChC,CAAE,UAAAU,GAAcV,EAChBrB,EAAWL,EAAO,SAAW,EAAI0B,EAAM,SAAWvB,MAACJ,GAAO,OAAAC,EAAgB,EAEzE,OAAAG,EAAAA,IAAAoC,EAAAA,SAAA,CAAG,YAAalC,CAAS,CAAA,CAClC,EAEAiC,EAAG,YAAczC,EAAe,GCT1B,MAAA2C,EAA2Bd,GAAU,CACnC,MAAA1B,EAASyB,EAAYC,EAAO,QAAQ,EACpC,CAAE,UAAAU,GAAcV,EAChBrB,EAAWL,EAAO,SAAW,EAAI0B,EAAM,SAAWvB,MAACJ,GAAO,OAAAC,EAAgB,EAEzE,OAAAG,EAAAA,IAAAoC,EAAAA,SAAA,CAAG,YAAalC,CAAS,CAAA,CAClC,EAEAmC,EAAO,YAAc3C,EAAe,OCV9B,MAAA4C,EAA0Cf,GAAU,CAClD,MAAA1B,EAASyB,EAAYC,EAAO,MAAM,EAClCrB,EAAWL,EAAO,SAAW,EAAI0B,EAAM,SAAWvB,MAACJ,GAAO,OAAAC,EAAgB,EAEhF,yBAAU,SAAAK,EAAS,CACrB,EAEAoC,EAAK,YAAc5C,EAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ts-react-directives.es.js","sources":["../src/fixtures/enums.ts","../src/fixtures/constants.ts","../src/components/Errors.tsx","../src/utils/validators.ts","../src/utils/logger.ts","../src/hooks/useValidate.ts","../src/directives/if/SwitchIf.tsx","../src/directives/if/If.tsx","../src/directives/if/ElseIf.tsx","../src/directives/if/Else.tsx"],"sourcesContent":["export enum LogicErrors {\r\n // Switch\r\n IfBlockExpected = 2001,\r\n OnlyOneIfBlockExpected = 2002,\r\n OnlyOneElseBlockExpected = 2003,\r\n SwitchBlockExpected = 2005,\r\n InvalidIfBlockOrdinal = 2004,\r\n InvalidElseBlockOrdinal = 2006,\r\n InvalidElseIfBlockOrdinal = 2007,\r\n\r\n // General\r\n\r\n InvalidElement = 3002,\r\n ChildrenExpected = 3003,\r\n}\r\n\r\nexport enum DirectiveNames {\r\n If = 'If',\r\n ElseIf = 'ElseIf',\r\n Else = 'Else',\r\n SwitchIf = 'SwitchIf',\r\n Unknown = 'Unknown',\r\n}\r\n","import { LogicErrors } from './enums';\r\n\r\nexport const ERRORS: Record<LogicErrors, string> = {\r\n [LogicErrors.IfBlockExpected]: \"Missing 'If'\",\r\n [LogicErrors.OnlyOneIfBlockExpected]: \"Can only have one 'If'\",\r\n [LogicErrors.OnlyOneElseBlockExpected]: \"Can only have one 'Else'\",\r\n [LogicErrors.SwitchBlockExpected]: \"'If', 'ElseIf', 'Else' need to be wrapped in 'Switch'\",\r\n [LogicErrors.InvalidElseBlockOrdinal]: \"Invalid ordinals, 'Else' should be the last\",\r\n [LogicErrors.InvalidIfBlockOrdinal]: \"Invalid ordinals, 'If' block should be the first\",\r\n [LogicErrors.InvalidElseIfBlockOrdinal]: \"Invalid ordinals, cannot have 'ElseIf' before 'If'\",\r\n [LogicErrors.ChildrenExpected]: 'Should at least have one child',\r\n [LogicErrors.InvalidElement]: 'Invalid element',\r\n};\r\n","import { FC } from 'react';\r\nimport { ERRORS, LogicErrors } from '@fixtures';\r\n\r\nimport '@assets/index.css';\r\n\r\ntype ErrorProps = { errors: LogicErrors[] };\r\n\r\nconst Errors: FC<ErrorProps> = ({ errors }) => (\r\n <ol className=\"trd-error-list\">\r\n {errors.map((error, index) => (\r\n <li key={`${error}-${index}`}>{ERRORS[error]}</li>\r\n ))}\r\n </ol>\r\n);\r\n\r\nexport default Errors;\r\n","import { DirectiveNames, LogicErrors } from '@fixtures';\r\nimport { log } from '@utils';\r\n\r\nimport { ReactNode } from 'react';\r\n\r\ntype ValidatorFn = (children: Array<Exclude<ReactNode, boolean | null | undefined>>) => number[];\r\n\r\n/**\r\n * Validate the children of SwitchIf directive\r\n * @param children\r\n * @returns\r\n */\r\nconst validateSwitchIfChildren: ValidatorFn = (children) => {\r\n const errors: LogicErrors[] = [];\r\n\r\n if (children.length === 0) {\r\n errors.push(LogicErrors.ChildrenExpected);\r\n return errors;\r\n }\r\n\r\n children.forEach((child) => {\r\n // @ts-expect-error child.type exist\r\n const { displayName = DirectiveNames.Unknown } = child.type ?? {};\r\n\r\n // If, ElseIf, Else cannot be direct children of If, ElseIf, Else\r\n if (\r\n displayName === DirectiveNames.If ||\r\n displayName === DirectiveNames.ElseIf ||\r\n displayName === DirectiveNames.Else\r\n ) {\r\n log('If, ElseIf, Else cannot be direct children of If, ElseIf, Else');\r\n errors.push(LogicErrors.InvalidElement);\r\n errors.push(LogicErrors.SwitchBlockExpected);\r\n }\r\n });\r\n\r\n return errors;\r\n};\r\n\r\n/**\r\n * Validate the SwitchIf directive\r\n * @param children\r\n * @returns\r\n */\r\nconst validateSwitchIf: ValidatorFn = (children) => {\r\n const errors: LogicErrors[] = [];\r\n const lookupTable: Record<string, number> = {};\r\n\r\n log('1. validate switch if');\r\n\r\n if (children.length === 0) {\r\n log('2. children expected');\r\n errors.push(LogicErrors.ChildrenExpected, LogicErrors.IfBlockExpected);\r\n return errors;\r\n }\r\n\r\n children.forEach((child, index) => {\r\n // @ts-expect-error child.type exist\r\n const { displayName = DirectiveNames.Unknown } = child.type;\r\n log('3. validate switch if - display name', displayName);\r\n\r\n const count = lookupTable[displayName] ?? 0;\r\n lookupTable[displayName] = count + 1;\r\n\r\n log('4. element look up', lookupTable);\r\n\r\n validateIfBlock(displayName, index, lookupTable, errors);\r\n validateElseBlock(displayName, index, children.length, lookupTable, errors);\r\n validateElseIfBlock(displayName, index, errors);\r\n validateSwitchIfInvalidElement(displayName, errors);\r\n });\r\n\r\n if (!lookupTable[DirectiveNames.If]) {\r\n log('5. if block expected - no if in lookup');\r\n errors.push(LogicErrors.IfBlockExpected);\r\n }\r\n\r\n return errors;\r\n};\r\n\r\nconst validateIfBlock = (\r\n elementName: string,\r\n index: number,\r\n elements: Record<string, number>,\r\n errors: LogicErrors[],\r\n) => {\r\n log('6. validate if block', elementName, index, elements);\r\n if (elementName === DirectiveNames.If) {\r\n if (index !== 0) {\r\n errors.push(LogicErrors.InvalidIfBlockOrdinal);\r\n }\r\n\r\n if (elements[DirectiveNames.If] > 1) {\r\n errors.push(LogicErrors.OnlyOneIfBlockExpected);\r\n }\r\n }\r\n};\r\n\r\nconst validateElseBlock = (\r\n elementName: string,\r\n index: number,\r\n length: number,\r\n elements: Record<string, number>,\r\n errors: LogicErrors[],\r\n) => {\r\n if (elementName === DirectiveNames.Else) {\r\n if (elements[DirectiveNames.Else] > 1) {\r\n errors.push(LogicErrors.OnlyOneElseBlockExpected);\r\n }\r\n if (index === 0 || index !== length - 1) {\r\n errors.push(LogicErrors.InvalidElseBlockOrdinal);\r\n }\r\n }\r\n};\r\n\r\nconst validateElseIfBlock = (elementName: string, index: number, errors: LogicErrors[]) => {\r\n if (elementName === DirectiveNames.ElseIf && index === 0) {\r\n errors.push(LogicErrors.InvalidElseIfBlockOrdinal);\r\n }\r\n};\r\n\r\nconst validateSwitchIfInvalidElement = (elementName: string, errors: LogicErrors[]) => {\r\n if (\r\n elementName !== DirectiveNames.If &&\r\n elementName !== DirectiveNames.ElseIf &&\r\n elementName !== DirectiveNames.Else\r\n ) {\r\n errors.push(LogicErrors.InvalidElement);\r\n }\r\n};\r\n\r\nexport class ValidationFactory {\r\n static get(validator: string) {\r\n let validatorFn: ValidatorFn = () => [];\r\n switch (validator) {\r\n case DirectiveNames.SwitchIf:\r\n log('getting validation fn for switch if');\r\n validatorFn = validateSwitchIf;\r\n break;\r\n case DirectiveNames.If:\r\n case DirectiveNames.ElseIf:\r\n case DirectiveNames.Else:\r\n log('getting validation fn for switch if children');\r\n validatorFn = validateSwitchIfChildren;\r\n break;\r\n }\r\n\r\n return validatorFn;\r\n }\r\n}\r\n","export const log = (message: string, ...args: any[]) => {\r\n const msg = `__${message\r\n .trim()\r\n .toLocaleUpperCase()\r\n .replace(/(' ')+/g, '_')}__`;\r\n console.log(msg, ...args);\r\n};\r\n","import { ValidationFactory } from '@utils';\r\nimport { Children, PropsWithChildren } from 'react';\r\n\r\nexport const useValidate = (props: PropsWithChildren, name: string) => {\r\n const { children } = props;\r\n const _children = Children.toArray(children);\r\n\r\n return ValidationFactory.get(name)(_children);\r\n};\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\n\r\nimport {\r\n Children,\r\n createElement,\r\n FC,\r\n FunctionComponent,\r\n isValidElement,\r\n NamedExoticComponent,\r\n PropsWithChildren,\r\n ReactElement,\r\n} from 'react';\r\n\r\nexport type SwitchIfProps = {};\r\n\r\nconst useSwitchIf = (props: PropsWithChildren) => {\r\n const errors = useValidate(props, 'SwitchIf');\r\n\r\n if (errors.length) {\r\n return { children: createElement(Errors, { errors }) };\r\n }\r\n\r\n const elements = Children.toArray(props.children);\r\n const validElements = elements.filter(isValidElement);\r\n const child = findChild(validElements);\r\n\r\n return { children: child };\r\n};\r\n\r\nconst findChild = (elements: ReactElement[]) => {\r\n for (const element of elements) {\r\n if (!element || !isValidElement(element)) {\r\n continue;\r\n }\r\n\r\n const { displayName } = element.type as NamedExoticComponent | FunctionComponent;\r\n\r\n if (displayName) {\r\n const { condition } = element.props as { condition: boolean };\r\n\r\n if ((displayName === 'If' || displayName === 'ElseIf') && condition === true) {\r\n return element;\r\n }\r\n\r\n if (displayName === 'Else') {\r\n return element;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\nconst SwitchIf: FC<PropsWithChildren<SwitchIfProps>> = (props) => {\r\n const { children } = useSwitchIf(props);\r\n return <>{children}</>;\r\n};\r\n\r\nSwitchIf.displayName = DirectiveNames.SwitchIf;\r\n\r\nexport default SwitchIf;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\n\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type IfProps = PropsWithChildren<{\r\n condition: boolean;\r\n}>;\r\n\r\nconst If: FC<IfProps> = (props) => {\r\n const errors = useValidate(props, 'If');\r\n const { condition } = props;\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{condition && children}</>;\r\n};\r\n\r\nIf.displayName = DirectiveNames.If;\r\n\r\nexport default If;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type ElseIfProps = PropsWithChildren<{\r\n condition: boolean;\r\n}>;\r\n\r\nconst ElseIf: FC<ElseIfProps> = (props) => {\r\n const errors = useValidate(props, 'ElseIf');\r\n const { condition } = props;\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{condition && children}</>;\r\n};\r\n\r\nElseIf.displayName = DirectiveNames.ElseIf;\r\n\r\nexport default ElseIf;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type ElseProps = {};\r\n\r\nconst Else: FC<PropsWithChildren<ElseProps>> = (props) => {\r\n const errors = useValidate(props, 'Else');\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{children}</>;\r\n};\r\n\r\nElse.displayName = DirectiveNames.Else;\r\n\r\nexport default Else;\r\n"],"names":["LogicErrors","DirectiveNames","ERRORS","Errors","errors","error","index","jsx","validateSwitchIfChildren","children","child","displayName","log","validateSwitchIf","lookupTable","count","validateIfBlock","validateElseBlock","validateElseIfBlock","validateSwitchIfInvalidElement","elementName","elements","length","ValidationFactory","validator","validatorFn","message","args","msg","useValidate","props","name","_children","Children","useSwitchIf","createElement","validElements","isValidElement","findChild","element","condition","SwitchIf","If","Fragment","ElseIf","Else"],"mappings":";;AAAY,IAAAA,sBAAAA,OAEVA,EAAAA,EAAA,kBAAkB,IAAlB,IAAA,mBACAA,EAAAA,EAAA,yBAAyB,IAAzB,IAAA,0BACAA,EAA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AS,CAAA;AAClC;AAEAmC,EAAO,cAAc3C,EAAe;ACV9B,MAAA4C,IAAyC,CAACf,MAAU;AAClD,QAAA1B,IAASyB,EAAYC,GAAO,MAAM,GAClCrB,IAAWL,EAAO,WAAW,IAAI0B,EAAM,WAAW,gBAAAvB,EAACJ,KAAO,QAAAC,GAAgB;AAEhF,gCAAU,UAAAK,GAAS;AACrB;AAEAoC,EAAK,cAAc5C,EAAe;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ts-react-directives.umd.js","sources":["../src/fixtures/enums.ts","../src/fixtures/constants.ts","../src/components/Errors.tsx","../src/utils/validators.ts","../src/utils/logger.ts","../src/hooks/useValidate.ts","../src/directives/if/SwitchIf.tsx","../src/directives/if/If.tsx","../src/directives/if/ElseIf.tsx","../src/directives/if/Else.tsx"],"sourcesContent":["export enum LogicErrors {\r\n // Switch\r\n IfBlockExpected = 2001,\r\n OnlyOneIfBlockExpected = 2002,\r\n OnlyOneElseBlockExpected = 2003,\r\n SwitchBlockExpected = 2005,\r\n InvalidIfBlockOrdinal = 2004,\r\n InvalidElseBlockOrdinal = 2006,\r\n InvalidElseIfBlockOrdinal = 2007,\r\n\r\n // General\r\n\r\n InvalidElement = 3002,\r\n ChildrenExpected = 3003,\r\n}\r\n\r\nexport enum DirectiveNames {\r\n If = 'If',\r\n ElseIf = 'ElseIf',\r\n Else = 'Else',\r\n SwitchIf = 'SwitchIf',\r\n Unknown = 'Unknown',\r\n}\r\n","import { LogicErrors } from './enums';\r\n\r\nexport const ERRORS: Record<LogicErrors, string> = {\r\n [LogicErrors.IfBlockExpected]: \"Missing 'If'\",\r\n [LogicErrors.OnlyOneIfBlockExpected]: \"Can only have one 'If'\",\r\n [LogicErrors.OnlyOneElseBlockExpected]: \"Can only have one 'Else'\",\r\n [LogicErrors.SwitchBlockExpected]: \"'If', 'ElseIf', 'Else' need to be wrapped in 'Switch'\",\r\n [LogicErrors.InvalidElseBlockOrdinal]: \"Invalid ordinals, 'Else' should be the last\",\r\n [LogicErrors.InvalidIfBlockOrdinal]: \"Invalid ordinals, 'If' block should be the first\",\r\n [LogicErrors.InvalidElseIfBlockOrdinal]: \"Invalid ordinals, cannot have 'ElseIf' before 'If'\",\r\n [LogicErrors.ChildrenExpected]: 'Should at least have one child',\r\n [LogicErrors.InvalidElement]: 'Invalid element',\r\n};\r\n","import { FC } from 'react';\r\nimport { ERRORS, LogicErrors } from '@fixtures';\r\n\r\nimport '@assets/index.css';\r\n\r\ntype ErrorProps = { errors: LogicErrors[] };\r\n\r\nconst Errors: FC<ErrorProps> = ({ errors }) => (\r\n <ol className=\"trd-error-list\">\r\n {errors.map((error, index) => (\r\n <li key={`${error}-${index}`}>{ERRORS[error]}</li>\r\n ))}\r\n </ol>\r\n);\r\n\r\nexport default Errors;\r\n","import { DirectiveNames, LogicErrors } from '@fixtures';\r\nimport { log } from '@utils';\r\n\r\nimport { ReactNode } from 'react';\r\n\r\ntype ValidatorFn = (children: Array<Exclude<ReactNode, boolean | null | undefined>>) => number[];\r\n\r\n/**\r\n * Validate the children of SwitchIf directive\r\n * @param children\r\n * @returns\r\n */\r\nconst validateSwitchIfChildren: ValidatorFn = (children) => {\r\n const errors: LogicErrors[] = [];\r\n\r\n if (children.length === 0) {\r\n errors.push(LogicErrors.ChildrenExpected);\r\n return errors;\r\n }\r\n\r\n children.forEach((child) => {\r\n // @ts-expect-error child.type exist\r\n const { displayName = DirectiveNames.Unknown } = child.type ?? {};\r\n\r\n // If, ElseIf, Else cannot be direct children of If, ElseIf, Else\r\n if (\r\n displayName === DirectiveNames.If ||\r\n displayName === DirectiveNames.ElseIf ||\r\n displayName === DirectiveNames.Else\r\n ) {\r\n log('If, ElseIf, Else cannot be direct children of If, ElseIf, Else');\r\n errors.push(LogicErrors.InvalidElement);\r\n errors.push(LogicErrors.SwitchBlockExpected);\r\n }\r\n });\r\n\r\n return errors;\r\n};\r\n\r\n/**\r\n * Validate the SwitchIf directive\r\n * @param children\r\n * @returns\r\n */\r\nconst validateSwitchIf: ValidatorFn = (children) => {\r\n const errors: LogicErrors[] = [];\r\n const lookupTable: Record<string, number> = {};\r\n\r\n log('1. validate switch if');\r\n\r\n if (children.length === 0) {\r\n log('2. children expected');\r\n errors.push(LogicErrors.ChildrenExpected, LogicErrors.IfBlockExpected);\r\n return errors;\r\n }\r\n\r\n children.forEach((child, index) => {\r\n // @ts-expect-error child.type exist\r\n const { displayName = DirectiveNames.Unknown } = child.type;\r\n log('3. validate switch if - display name', displayName);\r\n\r\n const count = lookupTable[displayName] ?? 0;\r\n lookupTable[displayName] = count + 1;\r\n\r\n log('4. element look up', lookupTable);\r\n\r\n validateIfBlock(displayName, index, lookupTable, errors);\r\n validateElseBlock(displayName, index, children.length, lookupTable, errors);\r\n validateElseIfBlock(displayName, index, errors);\r\n validateSwitchIfInvalidElement(displayName, errors);\r\n });\r\n\r\n if (!lookupTable[DirectiveNames.If]) {\r\n log('5. if block expected - no if in lookup');\r\n errors.push(LogicErrors.IfBlockExpected);\r\n }\r\n\r\n return errors;\r\n};\r\n\r\nconst validateIfBlock = (\r\n elementName: string,\r\n index: number,\r\n elements: Record<string, number>,\r\n errors: LogicErrors[],\r\n) => {\r\n log('6. validate if block', elementName, index, elements);\r\n if (elementName === DirectiveNames.If) {\r\n if (index !== 0) {\r\n errors.push(LogicErrors.InvalidIfBlockOrdinal);\r\n }\r\n\r\n if (elements[DirectiveNames.If] > 1) {\r\n errors.push(LogicErrors.OnlyOneIfBlockExpected);\r\n }\r\n }\r\n};\r\n\r\nconst validateElseBlock = (\r\n elementName: string,\r\n index: number,\r\n length: number,\r\n elements: Record<string, number>,\r\n errors: LogicErrors[],\r\n) => {\r\n if (elementName === DirectiveNames.Else) {\r\n if (elements[DirectiveNames.Else] > 1) {\r\n errors.push(LogicErrors.OnlyOneElseBlockExpected);\r\n }\r\n if (index === 0 || index !== length - 1) {\r\n errors.push(LogicErrors.InvalidElseBlockOrdinal);\r\n }\r\n }\r\n};\r\n\r\nconst validateElseIfBlock = (elementName: string, index: number, errors: LogicErrors[]) => {\r\n if (elementName === DirectiveNames.ElseIf && index === 0) {\r\n errors.push(LogicErrors.InvalidElseIfBlockOrdinal);\r\n }\r\n};\r\n\r\nconst validateSwitchIfInvalidElement = (elementName: string, errors: LogicErrors[]) => {\r\n if (\r\n elementName !== DirectiveNames.If &&\r\n elementName !== DirectiveNames.ElseIf &&\r\n elementName !== DirectiveNames.Else\r\n ) {\r\n errors.push(LogicErrors.InvalidElement);\r\n }\r\n};\r\n\r\nexport class ValidationFactory {\r\n static get(validator: string) {\r\n let validatorFn: ValidatorFn = () => [];\r\n switch (validator) {\r\n case DirectiveNames.SwitchIf:\r\n log('getting validation fn for switch if');\r\n validatorFn = validateSwitchIf;\r\n break;\r\n case DirectiveNames.If:\r\n case DirectiveNames.ElseIf:\r\n case DirectiveNames.Else:\r\n log('getting validation fn for switch if children');\r\n validatorFn = validateSwitchIfChildren;\r\n break;\r\n }\r\n\r\n return validatorFn;\r\n }\r\n}\r\n","export const log = (message: string, ...args: any[]) => {\r\n const msg = `__${message\r\n .trim()\r\n .toLocaleUpperCase()\r\n .replace(/(' ')+/g, '_')}__`;\r\n console.log(msg, ...args);\r\n};\r\n","import { ValidationFactory } from '@utils';\r\nimport { Children, PropsWithChildren } from 'react';\r\n\r\nexport const useValidate = (props: PropsWithChildren, name: string) => {\r\n const { children } = props;\r\n const _children = Children.toArray(children);\r\n\r\n return ValidationFactory.get(name)(_children);\r\n};\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\n\r\nimport {\r\n Children,\r\n createElement,\r\n FC,\r\n FunctionComponent,\r\n isValidElement,\r\n NamedExoticComponent,\r\n PropsWithChildren,\r\n ReactElement,\r\n} from 'react';\r\n\r\nexport type SwitchIfProps = {};\r\n\r\nconst useSwitchIf = (props: PropsWithChildren) => {\r\n const errors = useValidate(props, 'SwitchIf');\r\n\r\n if (errors.length) {\r\n return { children: createElement(Errors, { errors }) };\r\n }\r\n\r\n const elements = Children.toArray(props.children);\r\n const validElements = elements.filter(isValidElement);\r\n const child = findChild(validElements);\r\n\r\n return { children: child };\r\n};\r\n\r\nconst findChild = (elements: ReactElement[]) => {\r\n for (const element of elements) {\r\n if (!element || !isValidElement(element)) {\r\n continue;\r\n }\r\n\r\n const { displayName } = element.type as NamedExoticComponent | FunctionComponent;\r\n\r\n if (displayName) {\r\n const { condition } = element.props as { condition: boolean };\r\n\r\n if ((displayName === 'If' || displayName === 'ElseIf') && condition === true) {\r\n return element;\r\n }\r\n\r\n if (displayName === 'Else') {\r\n return element;\r\n }\r\n }\r\n }\r\n\r\n return null;\r\n};\r\n\r\nconst SwitchIf: FC<PropsWithChildren<SwitchIfProps>> = (props) => {\r\n const { children } = useSwitchIf(props);\r\n return <>{children}</>;\r\n};\r\n\r\nSwitchIf.displayName = DirectiveNames.SwitchIf;\r\n\r\nexport default SwitchIf;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\n\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type IfProps = PropsWithChildren<{\r\n condition: boolean;\r\n}>;\r\n\r\nconst If: FC<IfProps> = (props) => {\r\n const errors = useValidate(props, 'If');\r\n const { condition } = props;\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{condition && children}</>;\r\n};\r\n\r\nIf.displayName = DirectiveNames.If;\r\n\r\nexport default If;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type ElseIfProps = PropsWithChildren<{\r\n condition: boolean;\r\n}>;\r\n\r\nconst ElseIf: FC<ElseIfProps> = (props) => {\r\n const errors = useValidate(props, 'ElseIf');\r\n const { condition } = props;\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{condition && children}</>;\r\n};\r\n\r\nElseIf.displayName = DirectiveNames.ElseIf;\r\n\r\nexport default ElseIf;\r\n","import { Errors } from '@components';\r\nimport { DirectiveNames } from '@fixtures';\r\nimport { useValidate } from '@hooks';\r\nimport { FC, PropsWithChildren } from 'react';\r\n\r\nexport type ElseProps = {};\r\n\r\nconst Else: FC<PropsWithChildren<ElseProps>> = (props) => {\r\n const errors = useValidate(props, 'Else');\r\n const children = errors.length === 0 ? props.children : <Errors errors={errors} />;\r\n\r\n return <>{children}</>;\r\n};\r\n\r\nElse.displayName = DirectiveNames.Else;\r\n\r\nexport default Else;\r\n"],"names":["LogicErrors","DirectiveNames","ERRORS","Errors","errors","error","index","jsx","validateSwitchIfChildren","children","child","displayName","log","validateSwitchIf","lookupTable","count","validateIfBlock","validateElseBlock","validateElseIfBlock","validateSwitchIfInvalidElement","elementName","elements","length","ValidationFactory","validator","validatorFn","message","args","msg","useValidate","props","name","_children","Children","useSwitchIf","createElement","validElements","isValidElement","findChild","element","condition","SwitchIf","If","Fragment","ElseIf","Else"],"mappings":";2CAAY,IAAAA,GAAAA,IAEVA,EAAAA,EAAA,gBAAkB,IAAlB,EAAA,kBACAA,EAAAA,EAAA,uBAAyB,IAAzB,EAAA,yBACAA,EAAAA,EAAA,yBAA2B,IAA3B,EAAA,2BACAA,EAAAA,EAAA,oBAAsB,IAAtB,EAAA,sBACAA,EAAAA,EAAA,sBAAwB,IAAxB,EAAA,wBACAA,EAAAA,EAAA,wBAA0B,IAA1B,EAAA,0BACAA,EAAAA,EAAA,0BAA4B,IAA5B,EAAA,4BAIAA,EAAAA,EAAA,eAAiB,IAAjB,EAAA,iBACAA,EAAAA,EAAA,iBAAmB,IAAnB,EAAA,mBAbUA,IAAAA,GAAA,CAAA,CAAA,EAgBAC,GAAAA,IACVA,EAAA,GAAK,KACLA,EAAA,OAAS,SACTA,EAAA,KAAO,OACPA,EAAA,SAAW,WACXA,EAAA,QAAU,UALAA,IAAAA,GAAA,CAAA,CAAA,ECdL,MAAMC,EAAsC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