@openbytes/ts-react-directives 0.1.3 → 0.1.4
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/ts-react-directives.cjs.js +1 -1
- package/dist/ts-react-directives.d.ts +23 -2
- package/dist/ts-react-directives.es.js +1 -6
- package/dist/ts-react-directives.umd.js +1 -1
- package/package.json +9 -9
- package/dist/components/index.d.ts +0 -1
- package/dist/directives/if/index.d.ts +0 -4
- package/dist/directives/index.d.ts +0 -1
- package/dist/fixtures/constants.d.ts +0 -2
- package/dist/fixtures/enums.d.ts +0 -11
- package/dist/fixtures/index.d.ts +0 -2
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/useValidate.d.ts +0 -2
- package/dist/index.d.ts +0 -5
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/validators.d.ts +0 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),I=require("react");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
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react/jsx-runtime"),I=require("react");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 v={[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})=>d.jsx("ol",{className:"error-list",children:e.map((n,l)=>d.jsx("li",{children:v[n]},`${n}-${l}`))}),u=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===f.name||a===h.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,o)=>{const i=I.isValidElement(a)?a.type.name:"unknown",c=l[i]??0;l[i]=c+1,O(i,o,l,n),x(i,o,e.length,l,n),y(i,o,n),w(i,n)}),l[s.name]||n.push(t.IfBlockExpected),n)},O=(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,o)=>{e===h.name&&(a[h.name]>1&&o.push(t.OnlyOneElseBlockExpected),(n===0||n!==l-1)&&o.push(t.InvalidElseBlockOrdinal))},y=(e,n,l)=>{e===f.name&&n===0&&l.push(t.InvalidElseIfBlockOrdinal)},w=(e,n)=>{e!==s.name&&e!==f.name&&e!==h.name&&n.push(t.InvalidElement)};class S{static get(n){let l;switch(n){case r.name:l=B;break;case s.name:case f.name:case h.name:l=u;break;default:l=()=>[]}return l}}const E=(e,n)=>{const{children:l}=e,a=I.Children.toArray(l);return S.get(n)(a)},j=e=>{const n=E(e,r.name);if(n.length)return{children:I.createElement(m,{errors:n})};const{children:l}=e;return{children:I.Children.toArray(l).reduce((i,c)=>{var k,p;return(k=i==null?void 0:i.props)!=null&&k.condition?i:(p=c==null?void 0:c.props)!=null&&p.condition||(c==null?void 0:c.type.name)==="Else"?c:i},null)}},r=e=>{const{children:n}=j(e);return d.jsx(d.Fragment,{children:n})},s=e=>{const n=E(e,s.name),l=n.length===0?e.children:d.jsx(m,{errors:n});return d.jsx(d.Fragment,{children:l})},f=e=>{const n=E(e,f.name),l=n.length===0?e.children:d.jsx(m,{errors:n});return d.jsx(d.Fragment,{children:l})},h=e=>{const n=E(e,h.name),l=n.length===0?e.children:d.jsx(m,{errors:n});return d.jsx(d.Fragment,{children:l})};exports.Else=h;exports.ElseIf=f;exports.If=s;exports.SwitchIf=r;
|
|
@@ -1,2 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { FC } from 'react';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
export declare const Else: FC<ElseProps>;
|
|
6
|
+
|
|
7
|
+
export declare const ElseIf: FC<ElseIfProps>;
|
|
8
|
+
|
|
9
|
+
declare type ElseIfProps<T extends ReactNode = any> = IfProps<T>;
|
|
10
|
+
|
|
11
|
+
declare type ElseProps<T extends ReactNode = any> = PropsWithChildren<T>;
|
|
12
|
+
|
|
13
|
+
export declare const If: FC<IfProps>;
|
|
14
|
+
|
|
15
|
+
declare type IfProps<T extends ReactNode = any> = PropsWithChildren<T> & {
|
|
16
|
+
condition: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export declare const SwitchIf: FC<SwitchIfProps>;
|
|
20
|
+
|
|
21
|
+
declare type SwitchIfProps<T extends ReactNode = any> = PropsWithChildren<T>;
|
|
22
|
+
|
|
23
|
+
export { }
|
|
@@ -76,13 +76,8 @@ const E = (e, n) => {
|
|
|
76
76
|
return /* @__PURE__ */ i(I, { children: l });
|
|
77
77
|
};
|
|
78
78
|
export {
|
|
79
|
-
u as ERRORS,
|
|
80
79
|
h as Else,
|
|
81
80
|
f as ElseIf,
|
|
82
|
-
m as Errors,
|
|
83
81
|
o as If,
|
|
84
|
-
|
|
85
|
-
B as SwitchIf,
|
|
86
|
-
_ as ValidationFactory,
|
|
87
|
-
E as useValidate
|
|
82
|
+
B as SwitchIf
|
|
88
83
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d
|
|
1
|
+
(function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c["ts-react-directives"]={},c["react/jsx-runtime"],c.React))})(this,function(c,d,r){"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})=>d.jsx("ol",{className:"error-list",children:e.map((n,l)=>d.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=r.isValidElement(l)?l.type.name:"unknown";(a===o.name||a===I.name||a===f.name)&&n.push(t.SwitchBlockExpected)}),n)},u=e=>{const n=[],l={};return e.length===0?(n.push(t.ChildrenExpected,t.IfBlockExpected),n):(e.forEach((a,h)=>{const i=r.isValidElement(a)?a.type.name:"unknown",s=l[i]??0;l[i]=s+1,y(i,h,l,n),x(i,h,e.length,l,n),w(i,h,n),S(i,n)}),l[o.name]||n.push(t.IfBlockExpected),n)},y=(e,n,l,a)=>{e===o.name&&(n!==0&&a.push(t.InvalidIfBlockOrdinal),l[o.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===I.name&&n===0&&l.push(t.InvalidElseIfBlockOrdinal)},S=(e,n)=>{e!==o.name&&e!==I.name&&e!==f.name&&n.push(t.InvalidElement)};class C{static get(n){let l;switch(n){case k.name:l=u;break;case o.name:case I.name:case f.name:l=O;break;default:l=()=>[]}return l}}const p=(e,n)=>{const{children:l}=e,a=r.Children.toArray(l);return C.get(n)(a)},b=e=>{const n=p(e,k.name);if(n.length)return{children:r.createElement(E,{errors:n})};const{children:l}=e;return{children:r.Children.toArray(l).reduce((i,s)=>{var v,m;return(v=i==null?void 0:i.props)!=null&&v.condition?i:(m=s==null?void 0:s.props)!=null&&m.condition||(s==null?void 0:s.type.name)==="Else"?s:i},null)}},k=e=>{const{children:n}=b(e);return d.jsx(d.Fragment,{children:n})},o=e=>{const n=p(e,o.name),l=n.length===0?e.children:d.jsx(E,{errors:n});return d.jsx(d.Fragment,{children:l})},I=e=>{const n=p(e,I.name),l=n.length===0?e.children:d.jsx(E,{errors:n});return d.jsx(d.Fragment,{children:l})},f=e=>{const n=p(e,f.name),l=n.length===0?e.children:d.jsx(E,{errors:n});return d.jsx(d.Fragment,{children:l})};c.Else=f,c.ElseIf=I,c.If=o,c.SwitchIf=k,Object.defineProperty(c,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.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SkyCodr (aka: Dulan Sudasinghe)",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@commitlint/cli": "^19.7.1",
|
|
27
27
|
"@commitlint/config-conventional": "^19.7.1",
|
|
28
|
-
"@eslint/js": "^9.
|
|
28
|
+
"@eslint/js": "^9.20.0",
|
|
29
29
|
"@testing-library/jest-dom": "^6.6.3",
|
|
30
30
|
"@testing-library/react": "^16.2.0",
|
|
31
31
|
"@types/react": "^19.0.8",
|
|
@@ -33,19 +33,19 @@
|
|
|
33
33
|
"@vitejs/plugin-react": "^4.3.4",
|
|
34
34
|
"@vitest/coverage-v8": "^3.0.5",
|
|
35
35
|
"@vitest/ui": "^3.0.5",
|
|
36
|
-
"eslint": "^9.
|
|
36
|
+
"eslint": "^9.20.1",
|
|
37
37
|
"eslint-config-prettier": "^10.0.1",
|
|
38
38
|
"eslint-plugin-prettier": "^5.2.3",
|
|
39
39
|
"eslint-plugin-react": "^7.37.4",
|
|
40
|
-
"eslint-plugin-react-hooks": "^5.
|
|
41
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
42
|
-
"globals": "^15.
|
|
40
|
+
"eslint-plugin-react-hooks": "^5.1.0",
|
|
41
|
+
"eslint-plugin-react-refresh": "^0.4.19",
|
|
42
|
+
"globals": "^15.15.0",
|
|
43
43
|
"husky": "^9.1.7",
|
|
44
44
|
"jsdom": "^26.0.0",
|
|
45
45
|
"lint-staged": "^15.4.3",
|
|
46
|
-
"prettier": "^3.
|
|
47
|
-
"typescript": "~5.7.
|
|
48
|
-
"typescript-eslint": "^8.
|
|
46
|
+
"prettier": "^3.5.1",
|
|
47
|
+
"typescript": "~5.7.3",
|
|
48
|
+
"typescript-eslint": "^8.24.0",
|
|
49
49
|
"vite": "^6.1.0",
|
|
50
50
|
"vite-plugin-dts": "^4.5.0",
|
|
51
51
|
"vite-tsconfig-paths": "^5.1.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Errors } from './Errors';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './if';
|
package/dist/fixtures/enums.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare enum LogicErrors {
|
|
2
|
-
IfBlockExpected = 2001,
|
|
3
|
-
OnlyOneIfBlockExpected = 2002,
|
|
4
|
-
OnlyOneElseBlockExpected = 2003,
|
|
5
|
-
SwitchBlockExpected = 2005,
|
|
6
|
-
InvalidIfBlockOrdinal = 2004,
|
|
7
|
-
InvalidElseBlockOrdinal = 2006,
|
|
8
|
-
InvalidElseIfBlockOrdinal = 2007,
|
|
9
|
-
InvalidElement = 3002,
|
|
10
|
-
ChildrenExpected = 3003
|
|
11
|
-
}
|
package/dist/fixtures/index.d.ts
DELETED
package/dist/hooks/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useValidate } from './useValidate';
|
package/dist/index.d.ts
DELETED
package/dist/utils/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ValidationFactory } from './validators';
|