@carats/csr 0.0.3 → 0.0.5

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
@@ -1,18 +1,12 @@
1
- import { getConfig, CaratsComponent } from '@carats/core';
1
+ import { CaratsRenderContext } from '@carats/core';
2
2
 
3
- interface PageComponentResult {
4
- component: CaratsComponent<any>;
5
- params: Record<string, string>;
3
+ declare global {
4
+ interface HTMLAnchorElement {
5
+ _isHandled: boolean;
6
+ }
6
7
  }
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;
8
+ declare function BuildCarats(config: CaratsRenderContext): {
9
+ clientRender: (url: string) => Promise<void>;
10
+ };
17
11
 
18
- export { CaratsClientSideBuilder as default };
12
+ export { BuildCarats as default };
package/dist/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import{renderPage as s}from"@carats/core";import{clearHydrations as c}from"@carats/hooks";import{transpile as m}from"jjsx";function u(a){let{suspense:e,inAppRouting:d=!0}=a;e.loading=e.loading??(()=>JJSX.jsxFactory(JJSX.fragmentFactory,null,"\u{1F48E} Loading...")),e.error=e.error??(n=>JJSX.jsxFactory(JJSX.fragmentFactory,null,"\u{1F48E} Error: ",n.message)),e.notFound=e.notFound??(()=>JJSX.jsxFactory(JJSX.fragmentFactory,null,"\u{1F48E} Not Found"));async function i(n){let t=setTimeout(()=>document.getElementById("loading-indicator")?.classList.remove("hide"),250);await c();try{let r=await s.call(a,n,async o=>await fetch(o).then(l=>l.json()));document.getElementById("app").innerHTML=r}catch(r){document.getElementById("app").innerHTML=m(e.error(r))}finally{clearTimeout(t),history.pushState(null,"",n),window.dispatchEvent(new Event("load")),document.getElementById("loading-indicator")?.classList.add("hide")}}return d&&window.addEventListener("load",()=>{document.querySelectorAll("a").forEach(t=>{t._isHandled||(t.addEventListener("click",r=>{let o=new URL(t.href);o.origin!==location.origin||t.download||(r.preventDefault(),i(o.pathname+o.search))}),t._isHandled=!0)})}),{clientRender:i}}export{u as default};
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@carats/csr",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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.6",
9
+ "@carats/core": "^0.0.7",
10
+ "@carats/hooks": "^0.0.2",
10
11
  "@carats/url": "^0.0.1"
11
12
  },
12
13
  "description": "CSR module for Carats",