@carats/render 0.0.8 → 0.0.9

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.d.ts CHANGED
@@ -6,15 +6,19 @@ interface CaratsComponent<T = any> extends JSX.FunctionComponent<T> {
6
6
  }
7
7
  interface Facets {
8
8
  inAppRouting?: boolean;
9
- routes: {
10
- [key: string]: CaratsComponent;
11
- };
9
+ routes: Record<string, CaratsComponent>;
12
10
  suspense: {
13
11
  loading: () => JSX.Element;
14
12
  error: (error: Error) => JSX.Element;
15
13
  notFound: () => JSX.Element;
16
14
  };
17
15
  }
16
+ interface PartialFacets {
17
+ inAppRouting?: boolean;
18
+ routes?: Record<string, CaratsComponent>;
19
+ suspense?: Partial<Facets['suspense']>;
20
+ }
21
+ declare function defineFacets(facets: PartialFacets): Facets;
18
22
  interface PageComponentResult {
19
23
  component: CaratsComponent<any>;
20
24
  params: Record<string, string>;
@@ -27,4 +31,4 @@ interface BurnishOptions {
27
31
  }
28
32
  declare function Burnish<T = any>(component: CaratsComponent<T>, options?: BurnishOptions): CaratsComponent<T>;
29
33
 
30
- export { Burnish, type CaratsComponent, type Facets, type PageComponentResult, getPageComponent, renderPage };
34
+ export { Burnish, type CaratsComponent, type Facets, type PageComponentResult, defineFacets, getPageComponent, renderPage };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{matchRoute as c}from"@carats/url";import{transpile as p}from"jjsx";function l(e){let{routes:t,suspense:o}=this,u=new URL(e,"http://localhost").pathname;for(let n in t){let r=t[n],s=c(n,u);if(s)return r instanceof Promise?{component:()=>{let a=`carats-suspense-${n}`;return r.then(i=>{document.getElementById(a)?.replaceWith(p(i))}).catch(i=>{document.getElementById(a)?.replaceWith(p(o.error(i)))}),JJSX.jsxFactory("div",{id:a},o.loading())},params:s,route:n}:{component:r,params:s,route:n}}return{component:o.notFound,params:{},route:"/not-found"}}async function C(e,t){return p(e(t))}function g(e,t){return e.burnished=!0,t?.recast&&(e.recast=!0),e}export{g as Burnish,l as getPageComponent,C as renderPage};
1
+ import{matchRoute as c}from"@carats/url";import{transpile as p}from"jjsx";function g(e){return{inAppRouting:e.inAppRouting??!0,routes:e.routes??{},suspense:{loading:e.suspense?.loading??(()=>JJSX.jsxFactory(JJSX.fragmentFactory,null,"\u{1F48E} Loading...")),error:e.suspense?.error??(n=>JJSX.jsxFactory(JJSX.fragmentFactory,null,"\u{1F48E} Error: ",n.message)),notFound:e.suspense?.notFound??(()=>JJSX.jsxFactory(JJSX.fragmentFactory,null,"\u{1F48E} Not Found"))}}}function h(e){let{routes:n,suspense:o}=this,u=new URL(e,"http://localhost").pathname;for(let t in n){let r=n[t],s=c(t,u);if(s)return r instanceof Promise?{component:()=>{let a=`carats-suspense-${t}`;return r.then(i=>{document.getElementById(a)?.replaceWith(p(i))}).catch(i=>{document.getElementById(a)?.replaceWith(p(o.error(i)))}),JJSX.jsxFactory("div",{id:a},o.loading())},params:s,route:t}:{component:r,params:s,route:t}}return{component:o.notFound,params:{},route:"/not-found"}}async function C(e,n){return p(e(n))}function f(e,n){return e.burnished=!0,n?.recast&&(e.recast=!0),e}export{f as Burnish,g as defineFacets,h as getPageComponent,C as renderPage};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carats/render",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "Render module for Carats",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",