@carats/csr 0.0.1 → 0.0.3
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 +12 -4
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import { CaratsComponent } from '@carats/core';
|
|
1
|
+
import { getConfig, CaratsComponent } from '@carats/core';
|
|
2
2
|
|
|
3
3
|
interface PageComponentResult {
|
|
4
4
|
component: CaratsComponent<any>;
|
|
5
5
|
params: Record<string, string>;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type Fetcher<T> = (url: string) => Promise<T>;
|
|
8
|
+
interface CaratsClientSideAPI {
|
|
9
|
+
getPageComponent: (path: string) => PageComponentResult;
|
|
10
|
+
renderPage: <T = any>(url: string, fetcher: Fetcher<T>) => Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
interface CaratsClientSideBuilderConfig {
|
|
13
|
+
routes: Awaited<ReturnType<typeof getConfig>>['routes'];
|
|
14
|
+
suspense: Awaited<ReturnType<typeof getConfig>>['suspense'];
|
|
15
|
+
}
|
|
16
|
+
declare function CaratsClientSideBuilder(config: CaratsClientSideBuilderConfig): CaratsClientSideAPI;
|
|
9
17
|
|
|
10
|
-
export {
|
|
18
|
+
export { CaratsClientSideBuilder as default };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{transpile as
|
|
1
|
+
import{transpile as c}from"jjsx";import{matchRoute as d,parseUrl as C,qs as f,replaceParams as P}from"@carats/url";function h(g){function m(o){let{routes:i,suspense:r}=g,s=Object.fromEntries(Object.entries(i).filter(([e,t])=>t.public));for(let e in s){let{component:t}=s[e],n=d(e,o);if(n)return t instanceof Promise?{component:()=>{let a=`carats-suspense-${e}`;return t.then(p=>{document.getElementById(a)?.replaceWith(c(p))}).catch(p=>{document.getElementById(a)?.replaceWith(c(r.error(p)))}),JJSX.jsxFactory("div",{id:a},r.loading({id:a}))},params:n}:{component:t,params:n}}return{component:r.notFound,params:{}}}async function l(o,i){let{path:r,query:s}=C(o),{component:e,params:t}=m(r),n=e.ssp?P(e.ssp+f(s),t):null,u=n?await i(n):e.defaultProps||{url:o,params:t};return c(e(u))}return{getPageComponent:m,renderPage:l}}export{h as default};
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carats/csr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"jjsx": "^3.3.0"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {
|
|
9
|
-
"@carats/core": "^0.0.
|
|
9
|
+
"@carats/core": "^0.0.6",
|
|
10
10
|
"@carats/url": "^0.0.1"
|
|
11
11
|
},
|
|
12
12
|
"description": "CSR module for Carats",
|