@openbytes/ts-react-directives 0.1.5 → 0.1.6
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 i, Fragment as r } from "react/jsx-runtime";
|
|
2
|
+
import { isValidElement as u, Children as v, 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__ */ i("ol", { className: "error-list", children: e.map((n, l) => /* @__PURE__ */ i("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 = u(l) ? l.type.name : "unknown";
|
|
18
|
+
(t === o.name || t === I.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 = u(t) ? t.type.name : "unknown", s = l[d] ?? 0;
|
|
24
|
+
l[d] = s + 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 === I.name && n === 0 && l.push(a.InvalidElseIfBlockOrdinal);
|
|
32
|
+
}, N = (e, n) => {
|
|
33
|
+
e !== o.name && e !== I.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
|
-
case
|
|
40
|
-
l =
|
|
39
|
+
case O.name:
|
|
40
|
+
l = y;
|
|
41
41
|
break;
|
|
42
42
|
case o.name:
|
|
43
|
+
case I.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 = v.toArray(l);
|
|
55
|
+
return F.get(n)(t);
|
|
56
|
+
}, { log: E, warn: R } = console, D = (e) => {
|
|
57
|
+
var d;
|
|
58
|
+
const n = k(e, O.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
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
60
|
+
return R("__ERRORS__", n), { children: _(m, { errors: n }) };
|
|
61
|
+
const { children: l } = e, t = v.toArray(l);
|
|
62
|
+
let c = null;
|
|
63
|
+
if (t.length) {
|
|
64
|
+
let s = 0;
|
|
65
|
+
E("__FOUND_ELEMENTS__", t.length);
|
|
66
|
+
do {
|
|
67
|
+
const { type: p } = t[s] ?? {};
|
|
68
|
+
if (p) {
|
|
69
|
+
const { name: f } = p, { condition: B } = ((d = t[s]) == null ? void 0 : d.props) ?? {};
|
|
70
|
+
if ((f === "If" || f === "ElseIf") && B === !0) {
|
|
71
|
+
E("__ELEMENT_FOUND_1__", f), c = t[s];
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (f === "Else") {
|
|
75
|
+
E("__ELEMENT_FOUND_2__", f), c = t[s];
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
s++;
|
|
80
|
+
} while (s < t.length);
|
|
81
|
+
}
|
|
82
|
+
return E("__CHILD__", c), { children: c };
|
|
83
|
+
}, O = (e) => {
|
|
84
|
+
const { children: n } = D(e);
|
|
85
|
+
return /* @__PURE__ */ i(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__ */ i(m, { errors: n });
|
|
88
|
+
return /* @__PURE__ */ i(r, { children: l });
|
|
89
|
+
}, I = (e) => {
|
|
90
|
+
const n = k(e, I.name), l = n.length === 0 ? e.children : /* @__PURE__ */ i(m, { errors: n });
|
|
91
|
+
return /* @__PURE__ */ i(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__ */ i(m, { errors: n });
|
|
94
|
+
return /* @__PURE__ */ i(r, { children: l });
|
|
84
95
|
};
|
|
85
96
|
export {
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
h as Else,
|
|
98
|
+
I as ElseIf,
|
|
88
99
|
o as If,
|
|
89
|
-
|
|
100
|
+
O as SwitchIf
|
|
90
101
|
};
|
|
@@ -1 +1,2 @@
|
|
|
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
|
|
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 u=document.createElement("style");u.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(u);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"},m=({errors:e})=>c.jsx("ol",{className:"error-list",children:e.map((n,l)=>c.jsx("li",{children:B[n]},`${n}-${l}`))}),_=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===r.name||a===h.name||a===f.name)&&n.push(t.SwitchBlockExpected)}),n)},b=e=>{const n=[],l={};return e.length===0?(n.push(t.ChildrenExpected,t.IfBlockExpected),n):(e.forEach((a,i)=>{const o=I.isValidElement(a)?a.type.name:"unknown",s=l[o]??0;l[o]=s+1,y(o,i,l,n),x(o,i,e.length,l,n),g(o,i,n),w(o,n)}),l[r.name]||n.push(t.IfBlockExpected),n)},y=(e,n,l,a)=>{e===r.name&&(n!==0&&a.push(t.InvalidIfBlockOrdinal),l[r.name]>1&&a.push(t.OnlyOneIfBlockExpected))},x=(e,n,l,a,i)=>{e===f.name&&(a[f.name]>1&&i.push(t.OnlyOneElseBlockExpected),(n===0||n!==l-1)&&i.push(t.InvalidElseBlockOrdinal))},g=(e,n,l)=>{e===h.name&&n===0&&l.push(t.InvalidElseIfBlockOrdinal)},w=(e,n)=>{e!==r.name&&e!==h.name&&e!==f.name&&n.push(t.InvalidElement)};class S{static get(n){let l;switch(n){case k.name:l=b;break;case r.name:case h.name:case f.name:l=_;break;default:l=()=>[]}return l}}const p=(e,n)=>{const{children:l}=e,a=I.Children.toArray(l);return S.get(n)(a)},{log:v,warn:C}=console,F=e=>{var o;const n=p(e,k.name);if(n.length)return C("__ERRORS__",n),{children:I.createElement(m,{errors:n})};const{children:l}=e,a=I.Children.toArray(l);let i=null;if(a.length){let s=0;v("__FOUND_ELEMENTS__",a.length);do{const{type:O}=a[s]??{};if(O){const{name:E}=O,{condition:N}=((o=a[s])==null?void 0:o.props)??{};if((E==="If"||E==="ElseIf")&&N===!0){v("__ELEMENT_FOUND_1__",E),i=a[s];break}if(E==="Else"){v("__ELEMENT_FOUND_2__",E),i=a[s];break}}s++}while(s<a.length)}return v("__CHILD__",i),{children:i}},k=e=>{const{children:n}=F(e);return c.jsx(c.Fragment,{children:n})},r=e=>{const n=p(e,r.name),l=n.length===0?e.children:c.jsx(m,{errors:n});return c.jsx(c.Fragment,{children:l})},h=e=>{const n=p(e,h.name),l=n.length===0?e.children:c.jsx(m,{errors:n});return c.jsx(c.Fragment,{children:l})},f=e=>{const n=p(e,f.name),l=n.length===0?e.children:c.jsx(m,{errors:n});return c.jsx(c.Fragment,{children:l})};d.Else=f,d.ElseIf=h,d.If=r,d.SwitchIf=k,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
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.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SkyCodr (aka: Dulan Sudasinghe)",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"typescript-eslint": "^8.24.0",
|
|
49
49
|
"vite": "^6.1.0",
|
|
50
50
|
"vite-plugin-dts": "^4.5.0",
|
|
51
|
+
"vite-plugin-lib-inject-css": "^2.2.1",
|
|
51
52
|
"vite-tsconfig-paths": "^5.1.4",
|
|
52
53
|
"vitest": "^3.0.5"
|
|
53
54
|
},
|
|
@@ -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}
|