@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.
@@ -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 u={[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"},r=({errors:e})=>d.jsx("ol",{className:"error-list",children:e.map((n,l)=>d.jsx("li",{children:u[n]},`${n}-${l}`))}),B=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)},O=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,x(i,o,l,n),y(i,o,e.length,l,n),S(i,o,n),w(i,n)}),l[s.name]||n.push(t.IfBlockExpected),n)},x=(e,n,l,a)=>{e===s.name&&(n!==0&&a.push(t.InvalidIfBlockOrdinal),l[s.name]>1&&a.push(t.OnlyOneIfBlockExpected))},y=(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))},S=(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 v{static get(n){let l;switch(n){case m.name:l=O;break;case s.name:case f.name:case h.name:l=B;break;default:l=()=>[]}return l}}const E=(e,n)=>{const{children:l}=e,a=I.Children.toArray(l);return v.get(n)(a)},j=e=>{const n=E(e,m.name);if(n.length)return{children:I.createElement(r,{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)}},m=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(r,{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(r,{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(r,{errors:n});return d.jsx(d.Fragment,{children:l})};exports.ERRORS=u;exports.Else=h;exports.ElseIf=f;exports.Errors=r;exports.If=s;exports.LogicErrors=t;exports.SwitchIf=m;exports.ValidationFactory=v;exports.useValidate=E;
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
- export * from './index'
2
- export {}
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
- t as LogicErrors,
85
- B as SwitchIf,
86
- _ as ValidationFactory,
87
- E as useValidate
82
+ B as SwitchIf
88
83
  };
@@ -1 +1 @@
1
- (function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d["ts-react-directives"]={},d["react/jsx-runtime"],d.React))})(this,function(d,a,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 m={[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})=>a.jsx("ol",{className:"error-list",children:e.map((n,l)=>a.jsx("li",{children:m[n]},`${n}-${l}`))}),u=e=>{const n=[];return e.length===0?(n.push(t.ChildrenExpected),n):(e.forEach(l=>{const i=r.isValidElement(l)?l.type.name:"unknown";(i===o.name||i===I.name||i===f.name)&&n.push(t.SwitchBlockExpected)}),n)},y=e=>{const n=[],l={};return e.length===0?(n.push(t.ChildrenExpected,t.IfBlockExpected),n):(e.forEach((i,h)=>{const c=r.isValidElement(i)?i.type.name:"unknown",s=l[c]??0;l[c]=s+1,S(c,h,l,n),w(c,h,e.length,l,n),x(c,h,n),C(c,n)}),l[o.name]||n.push(t.IfBlockExpected),n)},S=(e,n,l,i)=>{e===o.name&&(n!==0&&i.push(t.InvalidIfBlockOrdinal),l[o.name]>1&&i.push(t.OnlyOneIfBlockExpected))},w=(e,n,l,i,h)=>{e===f.name&&(i[f.name]>1&&h.push(t.OnlyOneElseBlockExpected),(n===0||n!==l-1)&&h.push(t.InvalidElseBlockOrdinal))},x=(e,n,l)=>{e===I.name&&n===0&&l.push(t.InvalidElseIfBlockOrdinal)},C=(e,n)=>{e!==o.name&&e!==I.name&&e!==f.name&&n.push(t.InvalidElement)};class p{static get(n){let l;switch(n){case v.name:l=y;break;case o.name:case I.name:case f.name:l=u;break;default:l=()=>[]}return l}}const k=(e,n)=>{const{children:l}=e,i=r.Children.toArray(l);return p.get(n)(i)},b=e=>{const n=k(e,v.name);if(n.length)return{children:r.createElement(E,{errors:n})};const{children:l}=e;return{children:r.Children.toArray(l).reduce((c,s)=>{var B,O;return(B=c==null?void 0:c.props)!=null&&B.condition?c:(O=s==null?void 0:s.props)!=null&&O.condition||(s==null?void 0:s.type.name)==="Else"?s:c},null)}},v=e=>{const{children:n}=b(e);return a.jsx(a.Fragment,{children:n})},o=e=>{const n=k(e,o.name),l=n.length===0?e.children:a.jsx(E,{errors:n});return a.jsx(a.Fragment,{children:l})},I=e=>{const n=k(e,I.name),l=n.length===0?e.children:a.jsx(E,{errors:n});return a.jsx(a.Fragment,{children:l})},f=e=>{const n=k(e,f.name),l=n.length===0?e.children:a.jsx(E,{errors:n});return a.jsx(a.Fragment,{children:l})};d.ERRORS=m,d.Else=f,d.ElseIf=I,d.Errors=E,d.If=o,d.LogicErrors=t,d.SwitchIf=v,d.ValidationFactory=p,d.useValidate=k,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
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",
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.19.0",
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.19.0",
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.0.0",
41
- "eslint-plugin-react-refresh": "^0.4.18",
42
- "globals": "^15.14.0",
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.4.2",
47
- "typescript": "~5.7.2",
48
- "typescript-eslint": "^8.22.0",
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,4 +0,0 @@
1
- export { default as SwitchIf } from './SwitchIf';
2
- export { default as If } from './If';
3
- export { default as ElseIf } from './ElseIf';
4
- export { default as Else } from './Else';
@@ -1 +0,0 @@
1
- export * from './if';
@@ -1,2 +0,0 @@
1
- import { LogicErrors } from './enums';
2
- export declare const ERRORS: Record<LogicErrors, string>;
@@ -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
- }
@@ -1,2 +0,0 @@
1
- export * from './enums';
2
- export * from './constants';
@@ -1 +0,0 @@
1
- export { useValidate } from './useValidate';
@@ -1,2 +0,0 @@
1
- import { PropsWithChildren, ReactNode } from 'react';
2
- export declare const useValidate: <T extends ReactNode>(props: PropsWithChildren<T>, name: string) => number[];
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './components';
2
- export * from './directives';
3
- export * from './fixtures';
4
- export * from './hooks';
5
- export * from './utils';
@@ -1 +0,0 @@
1
- export { ValidationFactory } from './validators';
@@ -1,3 +0,0 @@
1
- export declare class ValidationFactory {
2
- static get(validator: string): ValidatorFn;
3
- }