@nifrajs/web-svelte 2.0.0 → 2.2.0

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/Chain.svelte CHANGED
@@ -4,10 +4,15 @@
4
4
  its `children` snippet ({@render children()} in the layout). Recurses on itself. This is the Svelte
5
5
  analogue of the React/Vue `compose` — Svelte components are compiled (not callable), so the fold is a
6
6
  component, not a function returning a node.
7
+
8
+ `layoutData` is the per-layout loader data, aligned with the chain's LEADING layout prefix. It is
9
+ sliced in lockstep with `chain` as each layout is consumed, so a layout always reads its own entry.
10
+ The `_error` boundary marker deliberately does NOT consume from it: the marker sits after every
11
+ layout, so the array is already empty by then, and leaving it alone keeps that true if it ever moves.
7
12
  -->
8
13
  <script>
9
14
  import Self from "./Chain.svelte"
10
- let { chain, props } = $props()
15
+ let { chain, props, layoutData } = $props()
11
16
  </script>
12
17
 
13
18
  {#if chain.length <= 1}
@@ -20,16 +25,16 @@
20
25
  `failed` snippet renders the route's _error component with the serialized error. -->
21
26
  {@const Fallback = chain[0].__nifraErrorBoundary}
22
27
  <svelte:boundary>
23
- <Self chain={chain.slice(1)} {props} />
28
+ <Self chain={chain.slice(1)} {props} {layoutData} />
24
29
  {#snippet failed(error)}
25
30
  <Fallback data={{ name: error?.name ?? "Error", message: String(error?.message ?? error) }} />
26
31
  {/snippet}
27
32
  </svelte:boundary>
28
33
  {:else}
29
34
  {@const Layout = chain[0]}
30
- <Layout>
35
+ <Layout data={layoutData?.[0] ?? null}>
31
36
  {#snippet children()}
32
- <Self chain={chain.slice(1)} {props} />
37
+ <Self chain={chain.slice(1)} {props} layoutData={layoutData?.slice(1)} />
33
38
  {/snippet}
34
39
  </Layout>
35
40
  {/if}
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAenE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,oGAAoG;AACpG,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAE/F;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAI7D"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAenE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE1C,oGAAoG;AACpG,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,GAAG,IAAI,CAK/F;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAI7D"}
package/dist/client.js CHANGED
@@ -14,7 +14,10 @@ import Router from "./Router.svelte";
14
14
  export { errorBoundary } from "./error.js";
15
15
  /** Hydrate a server-rendered Svelte layout `chain` (with the loader `props`) inside `container`. */
16
16
  export function hydrate(chain, props, container) {
17
- svelteHydrate(Chain, { target: container, props: { chain, props } });
17
+ svelteHydrate(Chain, {
18
+ target: container,
19
+ props: { chain, props, layoutData: props.layoutData },
20
+ });
18
21
  }
19
22
  /**
20
23
  * Hydrate a stateful Svelte Router. The `Router` component holds the store snapshot in `$state` and
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAA;AACjD,OAAO,KAAK,MAAM,gBAAgB,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,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C,CAAA;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,OAA2B;IACrD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAC7C,gBAAgB,CAAC,MAAM,CAAC,CAAA,CAAC,+DAA+D;IACxF,aAAa,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,SAAoB,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;AACpF,CAAC"}
package/dist/index.js CHANGED
@@ -21,14 +21,14 @@ export const svelteAdapter = {
21
21
  // `renderToStream` wraps the same string in a one-chunk stream for the deferred path. No streaming
22
22
  // renderer to skip here — but going straight to a string avoids the per-request stream allocation.
23
23
  renderToString(chain, props) {
24
- return render(Chain, { props: { chain, props } }).body;
24
+ return render(Chain, { props: { chain, props, layoutData: props.layoutData } }).body;
25
25
  },
26
26
  renderToStream(chain, props) {
27
27
  // `Chain` folds the layout chain (page innermost gets `props`; layouts wrap via their `children`
28
28
  // snippet). Svelte's `render` returns { head, body }; the body goes into #root. (Svelte's dynamic
29
29
  // `head` — from <svelte:head> — isn't surfaced through the seam's static `hydrationHead`; nifra's
30
30
  // own meta/head API manages the document head instead.)
31
- const { body } = render(Chain, { props: { chain, props } });
31
+ const { body } = render(Chain, { props: { chain, props, layoutData: props.layoutData } });
32
32
  return oneChunk(body);
33
33
  },
34
34
  // Svelte's client `hydrate` reconciles against the existing DOM; no per-document bootstrap script is
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,KAAK,MAAM,gBAAgB,CAAA;AAElC,2FAA2F;AAC3F,qGAAqG;AACrG,2DAA2D;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,8FAA8F;AAC9F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G,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC5C,OAAO,IAAI,cAAc,CAAC;QACxB,KAAK,CAAC,UAAU;YACd,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YACzB,UAAU,CAAC,KAAK,EAAE,CAAA;QACpB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,8EAA8E;AAC9E,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,kGAAkG;IAClG,uFAAuF;IACvF,mGAAmG;IACnG,mGAAmG;IACnG,cAAc,CAAC,KAAK,EAAE,KAAK;QACzB,OAAO,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,IAAI,CAAA;IACtF,CAAC;IACD,cAAc,CAAC,KAAK,EAAE,KAAK;QACzB,iGAAiG;QACjG,kGAAkG;QAClG,kGAAkG;QAClG,wDAAwD;QACxD,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;QACzF,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAA;IACvB,CAAC;IACD,qGAAqG;IACrG,wFAAwF;IACxF,aAAa;QACX,OAAO,EAAE,CAAA;IACX,CAAC;CACF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nifrajs/web-svelte",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Svelte 5 render adapter for @nifrajs/web — SSR + hydration + the .svelte compiler Bun-plugin.",
5
5
  "keywords": [
6
6
  "bun",
@@ -88,9 +88,9 @@
88
88
  "access": "public"
89
89
  },
90
90
  "dependencies": {
91
- "@nifrajs/i18n": "2.0.0",
92
- "@nifrajs/image": "2.0.0",
93
- "@nifrajs/web": "2.0.0"
91
+ "@nifrajs/i18n": "2.2.0",
92
+ "@nifrajs/image": "2.2.0",
93
+ "@nifrajs/web": "2.2.0"
94
94
  },
95
95
  "peerDependencies": {
96
96
  "mdsvex": "^0.12",
package/src/Chain.svelte CHANGED
@@ -4,10 +4,15 @@
4
4
  its `children` snippet ({@render children()} in the layout). Recurses on itself. This is the Svelte
5
5
  analogue of the React/Vue `compose` — Svelte components are compiled (not callable), so the fold is a
6
6
  component, not a function returning a node.
7
+
8
+ `layoutData` is the per-layout loader data, aligned with the chain's LEADING layout prefix. It is
9
+ sliced in lockstep with `chain` as each layout is consumed, so a layout always reads its own entry.
10
+ The `_error` boundary marker deliberately does NOT consume from it: the marker sits after every
11
+ layout, so the array is already empty by then, and leaving it alone keeps that true if it ever moves.
7
12
  -->
8
13
  <script>
9
14
  import Self from "./Chain.svelte"
10
- let { chain, props } = $props()
15
+ let { chain, props, layoutData } = $props()
11
16
  </script>
12
17
 
13
18
  {#if chain.length <= 1}
@@ -20,16 +25,16 @@
20
25
  `failed` snippet renders the route's _error component with the serialized error. -->
21
26
  {@const Fallback = chain[0].__nifraErrorBoundary}
22
27
  <svelte:boundary>
23
- <Self chain={chain.slice(1)} {props} />
28
+ <Self chain={chain.slice(1)} {props} {layoutData} />
24
29
  {#snippet failed(error)}
25
30
  <Fallback data={{ name: error?.name ?? "Error", message: String(error?.message ?? error) }} />
26
31
  {/snippet}
27
32
  </svelte:boundary>
28
33
  {:else}
29
34
  {@const Layout = chain[0]}
30
- <Layout>
35
+ <Layout data={layoutData?.[0] ?? null}>
31
36
  {#snippet children()}
32
- <Self chain={chain.slice(1)} {props} />
37
+ <Self chain={chain.slice(1)} {props} layoutData={layoutData?.slice(1)} />
33
38
  {/snippet}
34
39
  </Layout>
35
40
  {/if}
package/src/client.ts CHANGED
@@ -17,7 +17,10 @@ export { errorBoundary } from "./error.ts"
17
17
 
18
18
  /** Hydrate a server-rendered Svelte layout `chain` (with the loader `props`) inside `container`. */
19
19
  export function hydrate(chain: readonly unknown[], props: RenderProps, container: unknown): void {
20
- svelteHydrate(Chain, { target: container as Element, props: { chain, props } })
20
+ svelteHydrate(Chain, {
21
+ target: container as Element,
22
+ props: { chain, props, layoutData: props.layoutData },
23
+ })
21
24
  }
22
25
 
23
26
  /**
package/src/index.ts CHANGED
@@ -33,14 +33,14 @@ export const svelteAdapter: RenderAdapter = {
33
33
  // `renderToStream` wraps the same string in a one-chunk stream for the deferred path. No streaming
34
34
  // renderer to skip here — but going straight to a string avoids the per-request stream allocation.
35
35
  renderToString(chain, props) {
36
- return render(Chain, { props: { chain, props } }).body
36
+ return render(Chain, { props: { chain, props, layoutData: props.layoutData } }).body
37
37
  },
38
38
  renderToStream(chain, props) {
39
39
  // `Chain` folds the layout chain (page innermost gets `props`; layouts wrap via their `children`
40
40
  // snippet). Svelte's `render` returns { head, body }; the body goes into #root. (Svelte's dynamic
41
41
  // `head` — from <svelte:head> — isn't surfaced through the seam's static `hydrationHead`; nifra's
42
42
  // own meta/head API manages the document head instead.)
43
- const { body } = render(Chain, { props: { chain, props } })
43
+ const { body } = render(Chain, { props: { chain, props, layoutData: props.layoutData } })
44
44
  return oneChunk(body)
45
45
  },
46
46
  // Svelte's client `hydrate` reconciles against the existing DOM; no per-document bootstrap script is