@carats/render 0.0.1

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.
@@ -0,0 +1,21 @@
1
+ interface CaratsComponent<T = any> extends JSX.FunctionComponent<T> {
2
+ ssp?: string;
3
+ defaultProps?: T;
4
+ }
5
+ interface CaratsRenderContext {
6
+ inAppRouting?: boolean;
7
+ routes: Record<string, CaratsComponent>;
8
+ suspense: {
9
+ loading: () => JSX.Element;
10
+ error: (error: Error) => JSX.Element;
11
+ notFound: () => JSX.Element;
12
+ };
13
+ }
14
+ interface PageComponentResult {
15
+ component: CaratsComponent<any>;
16
+ params: Record<string, string>;
17
+ }
18
+ declare function getPageComponent(this: CaratsRenderContext, path: string): PageComponentResult;
19
+ declare function renderPage<T = any>(this: CaratsRenderContext, component: CaratsComponent<T>, props: T): Promise<string>;
20
+
21
+ export { type CaratsRenderContext, getPageComponent, renderPage };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{matchRoute as i}from"@carats/url";import{transpile as m}from"jjsx";function C(n){let{routes:e,suspense:t}=this;for(let o in e){let r=e[o],s=i(o,n);if(s)return r instanceof Promise?{component:()=>{let a=`carats-suspense-${o}`;return r.then(p=>{document.getElementById(a)?.replaceWith(m(p))}).catch(p=>{document.getElementById(a)?.replaceWith(m(t.error(p)))}),JJSX.jsxFactory("div",{id:a},t.loading())},params:s}:{component:r,params:s}}return{component:t.notFound,params:{}}}async function g(n,e){return m(n(e))}export{C as getPageComponent,g as renderPage};
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@carats/render",
3
+ "version": "0.0.1",
4
+ "description": "Render module for Carats",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": ["dist"],
8
+ "type": "module",
9
+ "scripts": {
10
+ "build": "tsup src/index.tsx --config ../../tsup.config.ts"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "peerDependencies": {
16
+ "@carats/url": "^0.0.1",
17
+ "jjsx": "^3.3.0"
18
+ }
19
+ }