@openbytes/ts-react-directives 0.1.5 → 0.1.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.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
: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}
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { isValidElement as
|
|
3
|
-
var
|
|
1
|
+
import { jsx as s, Fragment as r } from "react/jsx-runtime";
|
|
2
|
+
import { isValidElement as O, Children as u, createElement as _ } from "react";
|
|
3
|
+
import './index.css';var a = /* @__PURE__ */ ((e) => (e[e.IfBlockExpected = 2001] = "IfBlockExpected", e[e.OnlyOneIfBlockExpected = 2002] = "OnlyOneIfBlockExpected", e[e.OnlyOneElseBlockExpected = 2003] = "OnlyOneElseBlockExpected", e[e.SwitchBlockExpected = 2005] = "SwitchBlockExpected", 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))(a || {});
|
|
4
4
|
const x = {
|
|
5
|
-
[
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
},
|
|
5
|
+
[a.IfBlockExpected]: "Missing 'If'",
|
|
6
|
+
[a.OnlyOneIfBlockExpected]: "Can only have one 'If'",
|
|
7
|
+
[a.OnlyOneElseBlockExpected]: "Can only have one 'Else'",
|
|
8
|
+
[a.SwitchBlockExpected]: "'If', 'ElseIf', 'Else' need to be wrapped in 'Switch'",
|
|
9
|
+
[a.InvalidElseBlockOrdinal]: "Invalid ordinals, 'Else' should be the last",
|
|
10
|
+
[a.InvalidIfBlockOrdinal]: "Invalid ordinals, 'If' block should be the first",
|
|
11
|
+
[a.InvalidElseIfBlockOrdinal]: "Invalid ordinals, cannot have 'ElseIf' before 'If'",
|
|
12
|
+
[a.ChildrenExpected]: "Should at least have one child",
|
|
13
|
+
[a.InvalidElement]: "Invalid element"
|
|
14
|
+
}, m = ({ errors: e }) => /* @__PURE__ */ s("ol", { className: "error-list", children: e.map((n, l) => /* @__PURE__ */ s("li", { children: x[n] }, `${n}-${l}`)) }), w = (e) => {
|
|
15
15
|
const n = [];
|
|
16
|
-
return e.length === 0 ? (n.push(
|
|
17
|
-
const
|
|
18
|
-
(
|
|
16
|
+
return e.length === 0 ? (n.push(a.ChildrenExpected), n) : (e.forEach((l) => {
|
|
17
|
+
const t = O(l) ? l.type.name : "unknown";
|
|
18
|
+
(t === o.name || t === E.name || t === h.name) && n.push(a.SwitchBlockExpected);
|
|
19
19
|
}), n);
|
|
20
|
-
},
|
|
20
|
+
}, y = (e) => {
|
|
21
21
|
const n = [], l = {};
|
|
22
|
-
return e.length === 0 ? (n.push(
|
|
23
|
-
const
|
|
24
|
-
l[
|
|
25
|
-
}), l[o.name] || n.push(
|
|
26
|
-
}, S = (e, n, l,
|
|
27
|
-
e === o.name && (n !== 0 &&
|
|
28
|
-
}, C = (e, n, l,
|
|
29
|
-
e ===
|
|
22
|
+
return e.length === 0 ? (n.push(a.ChildrenExpected, a.IfBlockExpected), n) : (e.forEach((t, c) => {
|
|
23
|
+
const d = O(t) ? t.type.name : "unknown", i = l[d] ?? 0;
|
|
24
|
+
l[d] = i + 1, S(d, c, l, n), C(d, c, e.length, l, n), b(d, c, n), N(d, n);
|
|
25
|
+
}), l[o.name] || n.push(a.IfBlockExpected), n);
|
|
26
|
+
}, S = (e, n, l, t) => {
|
|
27
|
+
e === o.name && (n !== 0 && t.push(a.InvalidIfBlockOrdinal), l[o.name] > 1 && t.push(a.OnlyOneIfBlockExpected));
|
|
28
|
+
}, C = (e, n, l, t, c) => {
|
|
29
|
+
e === h.name && (t[h.name] > 1 && c.push(a.OnlyOneElseBlockExpected), (n === 0 || n !== l - 1) && c.push(a.InvalidElseBlockOrdinal));
|
|
30
30
|
}, b = (e, n, l) => {
|
|
31
|
-
e ===
|
|
32
|
-
},
|
|
33
|
-
e !== o.name && e !==
|
|
31
|
+
e === E.name && n === 0 && l.push(a.InvalidElseIfBlockOrdinal);
|
|
32
|
+
}, N = (e, n) => {
|
|
33
|
+
e !== o.name && e !== E.name && e !== h.name && n.push(a.InvalidElement);
|
|
34
34
|
};
|
|
35
|
-
class
|
|
35
|
+
class F {
|
|
36
36
|
static get(n) {
|
|
37
37
|
let l;
|
|
38
38
|
switch (n) {
|
|
39
39
|
case v.name:
|
|
40
|
-
l =
|
|
40
|
+
l = y;
|
|
41
41
|
break;
|
|
42
42
|
case o.name:
|
|
43
|
+
case E.name:
|
|
43
44
|
case h.name:
|
|
44
|
-
|
|
45
|
-
l = y;
|
|
45
|
+
l = w;
|
|
46
46
|
break;
|
|
47
47
|
default:
|
|
48
48
|
l = () => [];
|
|
@@ -50,41 +50,52 @@ class R {
|
|
|
50
50
|
return l;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
const
|
|
54
|
-
const { children: l } = e,
|
|
55
|
-
return
|
|
56
|
-
},
|
|
57
|
-
|
|
53
|
+
const k = (e, n) => {
|
|
54
|
+
const { children: l } = e, t = u.toArray(l);
|
|
55
|
+
return F.get(n)(t);
|
|
56
|
+
}, { log: I, warn: R } = console, D = (e) => {
|
|
57
|
+
var d;
|
|
58
|
+
const n = k(e, v.name);
|
|
58
59
|
if (n.length)
|
|
59
|
-
return { children:
|
|
60
|
-
const { children: l } = e;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const {
|
|
67
|
-
if ((
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
return R("__ERRORS__", n), { children: _(m, { errors: n }) };
|
|
61
|
+
const { children: l } = e, t = u.toArray(l);
|
|
62
|
+
let c = null;
|
|
63
|
+
if (t.length) {
|
|
64
|
+
let i = 0;
|
|
65
|
+
I("__FOUND_ELEMENTS__", t);
|
|
66
|
+
do {
|
|
67
|
+
const { type: p } = t[i] ?? {};
|
|
68
|
+
if (I("__INSIDE_LOOP__", i, p), p) {
|
|
69
|
+
const { name: f } = p, { condition: B } = ((d = t[i]) == null ? void 0 : d.props) ?? {};
|
|
70
|
+
if ((f === "If" || f === "ElseIf") && B === !0) {
|
|
71
|
+
I("__ELEMENT_FOUND_1__", f), c = t[i];
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (f === "Else") {
|
|
75
|
+
I("__ELEMENT_FOUND_2__", f), c = t[i];
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
i++;
|
|
80
|
+
} while (i < t.length);
|
|
81
|
+
}
|
|
82
|
+
return I("__CHILD__", c), { children: c };
|
|
72
83
|
}, v = (e) => {
|
|
73
|
-
const { children: n } =
|
|
74
|
-
return /* @__PURE__ */
|
|
84
|
+
const { children: n } = D(e);
|
|
85
|
+
return /* @__PURE__ */ s(r, { children: n });
|
|
75
86
|
}, o = (e) => {
|
|
76
|
-
const n =
|
|
77
|
-
return /* @__PURE__ */
|
|
87
|
+
const n = k(e, o.name), l = n.length === 0 ? e.children : /* @__PURE__ */ s(m, { errors: n });
|
|
88
|
+
return /* @__PURE__ */ s(r, { children: l });
|
|
89
|
+
}, E = (e) => {
|
|
90
|
+
const n = k(e, E.name), l = n.length === 0 ? e.children : /* @__PURE__ */ s(m, { errors: n });
|
|
91
|
+
return /* @__PURE__ */ s(r, { children: l });
|
|
78
92
|
}, h = (e) => {
|
|
79
|
-
const n =
|
|
80
|
-
return /* @__PURE__ */
|
|
81
|
-
}, f = (e) => {
|
|
82
|
-
const n = u(e, f.name), l = n.length === 0 ? e.children : /* @__PURE__ */ d(r, { errors: n });
|
|
83
|
-
return /* @__PURE__ */ d(I, { children: l });
|
|
93
|
+
const n = k(e, h.name), l = n.length === 0 ? e.children : /* @__PURE__ */ s(m, { errors: n });
|
|
94
|
+
return /* @__PURE__ */ s(r, { children: l });
|
|
84
95
|
};
|
|
85
96
|
export {
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
h as Else,
|
|
98
|
+
E as ElseIf,
|
|
88
99
|
o as If,
|
|
89
100
|
v as SwitchIf
|
|
90
101
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openbytes/ts-react-directives",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SkyCodr (aka: Dulan Sudasinghe)",
|
|
@@ -9,13 +9,11 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
|
-
"main": "dist/ts-react-directives.umd.js",
|
|
13
12
|
"module": "dist/ts-react-directives.es.js",
|
|
14
13
|
"types": "dist/ts-react-directives.d.ts",
|
|
15
14
|
"exports": {
|
|
16
15
|
".": {
|
|
17
|
-
"import": "./dist/ts-react-directives.es.js"
|
|
18
|
-
"require": "./dist/ts-react-directives.umd.js"
|
|
16
|
+
"import": "./dist/ts-react-directives.es.js"
|
|
19
17
|
}
|
|
20
18
|
},
|
|
21
19
|
"dependencies": {
|
|
@@ -48,6 +46,7 @@
|
|
|
48
46
|
"typescript-eslint": "^8.24.0",
|
|
49
47
|
"vite": "^6.1.0",
|
|
50
48
|
"vite-plugin-dts": "^4.5.0",
|
|
49
|
+
"vite-plugin-lib-inject-css": "^2.2.1",
|
|
51
50
|
"vite-tsconfig-paths": "^5.1.4",
|
|
52
51
|
"vitest": "^3.0.5"
|
|
53
52
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
:root{--color: 255, 100, 200;--bg-color: 0, 100, 200}ol.error-list{border:.2rem double rgb(var(--bg-color));background-color:rgba(var(--bg-color),.1);list-style-type:none;box-sizing:border-box;padding:.5rem;margin:0}.error-list>li{color:#000;background-color:rgba(var(--color),.1);padding:.125rem;margin:.125rem;border:2px solid rgb(var(--color));font-size:1.5rem;font-family:monospace}.error-list>li:before{content:"🛈 ";font-size:1.5rem;padding-left:.125rem;margin-right:.125rem}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(d,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],c):(d=typeof globalThis<"u"?globalThis:d||self,c(d["ts-react-directives"]={},d["react/jsx-runtime"],d.React))})(this,function(d,c,I){"use strict";var t=(e=>(e[e.IfBlockExpected=2001]="IfBlockExpected",e[e.OnlyOneIfBlockExpected=2002]="OnlyOneIfBlockExpected",e[e.OnlyOneElseBlockExpected=2003]="OnlyOneElseBlockExpected",e[e.SwitchBlockExpected=2005]="SwitchBlockExpected",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))(t||{});const B={[t.IfBlockExpected]:"Missing 'If'",[t.OnlyOneIfBlockExpected]:"Can only have one 'If'",[t.OnlyOneElseBlockExpected]:"Can only have one 'Else'",[t.SwitchBlockExpected]:"'If', 'ElseIf', 'Else' need to be wrapped in 'Switch'",[t.InvalidElseBlockOrdinal]:"Invalid ordinals, 'Else' should be the last",[t.InvalidIfBlockOrdinal]:"Invalid ordinals, 'If' block should be the first",[t.InvalidElseIfBlockOrdinal]:"Invalid ordinals, cannot have 'ElseIf' before 'If'",[t.ChildrenExpected]:"Should at least have one child",[t.InvalidElement]:"Invalid element"},E=({errors:e})=>c.jsx("ol",{className:"error-list",children:e.map((n,l)=>c.jsx("li",{children:B[n]},`${n}-${l}`))}),O=e=>{const n=[];return e.length===0?(n.push(t.ChildrenExpected),n):(e.forEach(l=>{const a=I.isValidElement(l)?l.type.name:"unknown";(a===s.name||a===r.name||a===f.name)&&n.push(t.SwitchBlockExpected)}),n)},m=e=>{const n=[],l={};return e.length===0?(n.push(t.ChildrenExpected,t.IfBlockExpected),n):(e.forEach((a,h)=>{const i=I.isValidElement(a)?a.type.name:"unknown",o=l[i]??0;l[i]=o+1,y(i,h,l,n),x(i,h,e.length,l,n),w(i,h,n),S(i,n)}),l[s.name]||n.push(t.IfBlockExpected),n)},y=(e,n,l,a)=>{e===s.name&&(n!==0&&a.push(t.InvalidIfBlockOrdinal),l[s.name]>1&&a.push(t.OnlyOneIfBlockExpected))},x=(e,n,l,a,h)=>{e===f.name&&(a[f.name]>1&&h.push(t.OnlyOneElseBlockExpected),(n===0||n!==l-1)&&h.push(t.InvalidElseBlockOrdinal))},w=(e,n,l)=>{e===r.name&&n===0&&l.push(t.InvalidElseIfBlockOrdinal)},S=(e,n)=>{e!==s.name&&e!==r.name&&e!==f.name&&n.push(t.InvalidElement)};class C{static get(n){let l;switch(n){case k.name:l=m;break;case s.name:case r.name:case f.name:l=O;break;default:l=()=>[]}return l}}const u=(e,n)=>{const{children:l}=e,a=I.Children.toArray(l);return C.get(n)(a)},b=e=>{const n=u(e,k.name);if(n.length)return{children:I.createElement(E,{errors:n})};const{children:l}=e;return{children:I.Children.toArray(l).reduce((i,o)=>{if(i)return i;const{type:v}=o??{};if(v){const{name:p}=v,{condition:F}=(o==null?void 0:o.props)??{};if((p==="If"||p==="ElseIf")&&F===!0||p==="Else")return o}return null},null)}},k=e=>{const{children:n}=b(e);return c.jsx(c.Fragment,{children:n})},s=e=>{const n=u(e,s.name),l=n.length===0?e.children:c.jsx(E,{errors:n});return c.jsx(c.Fragment,{children:l})},r=e=>{const n=u(e,r.name),l=n.length===0?e.children:c.jsx(E,{errors:n});return c.jsx(c.Fragment,{children:l})},f=e=>{const n=u(e,f.name),l=n.length===0?e.children:c.jsx(E,{errors:n});return c.jsx(c.Fragment,{children:l})};d.Else=f,d.ElseIf=r,d.If=s,d.SwitchIf=k,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|