@molecule/app-svelte 3.10.0 → 3.11.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/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-11-22T07:13:44.407Z
6
+ Generated: 2026-11-22T19:01:00.165Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-svelte
@@ -24,6 +24,7 @@ then consume services anywhere below via store factories
24
24
  ```svelte
25
25
  <!-- +layout.svelte — wire providers ONCE, during component init -->
26
26
  <script lang="ts">
27
+ import type { Snippet } from 'svelte'
27
28
  import { setMoleculeContext } from '@molecule/app-svelte'
28
29
  import { provider as stateProvider } from '@molecule/app-state-zustand'
29
30
  import { provider as themeProvider } from '@molecule/app-theme-css-variables'
@@ -34,10 +35,14 @@ then consume services anywhere below via store factories
34
35
  auth: createJWTAuthClient({ baseURL: '/api' }),
35
36
  theme: themeProvider,
36
37
  })
38
+
39
+ let { children }: { children: Snippet } = $props()
37
40
  </script>
38
41
 
39
- <slot />
42
+ {@render children()}
43
+ ```
40
44
 
45
+ ```svelte
41
46
  <!-- Component.svelte — consume via stores -->
42
47
  <script lang="ts">
43
48
  import { createAuthStores, createThemeStores } from '@molecule/app-svelte'
@@ -49,8 +54,8 @@ then consume services anywhere below via store factories
49
54
  {#if $isAuthenticated}
50
55
  <div style:background={$theme.colors.background}>
51
56
  <h1>Welcome, {$user?.name}!</h1>
52
- <button on:click={toggleTheme}>Toggle ({$mode})</button>
53
- <button on:click={() => logout()}>Logout</button>
57
+ <button onclick={toggleTheme}>Toggle ({$mode})</button>
58
+ <button onclick={() => logout()}>Logout</button>
54
59
  </div>
55
60
  {/if}
56
61
  ```
@@ -143,7 +148,7 @@ signs the user out.
143
148
  ## Installation
144
149
 
145
150
  ```bash
146
- npm install @molecule/app-svelte @molecule/app-ai-chat @molecule/app-ai-models @molecule/app-auth @molecule/app-code-editor @molecule/app-device @molecule/app-forms @molecule/app-http @molecule/app-i18n @molecule/app-ide @molecule/app-live-preview @molecule/app-logger @molecule/app-platform @molecule/app-push @molecule/app-routing @molecule/app-state @molecule/app-storage @molecule/app-theme @molecule/app-ui @molecule/app-utilities @molecule/app-version svelte
151
+ npm install @molecule/app-svelte @molecule/app-ai-chat @molecule/app-ai-models @molecule/app-auth @molecule/app-device @molecule/app-forms @molecule/app-http @molecule/app-i18n @molecule/app-logger @molecule/app-platform @molecule/app-push @molecule/app-routing @molecule/app-state @molecule/app-storage @molecule/app-theme @molecule/app-ui @molecule/app-utilities @molecule/app-version svelte
147
152
  ```
148
153
 
149
154
  ## API
@@ -954,7 +959,8 @@ interface Router {
954
959
  getHash(): string
955
960
 
956
961
  /**
957
- * Navigates to a path.
962
+ * Navigates to a path. A path that is only a query or a hash (`'?tab=2'`, `'#top'`) stays on
963
+ * the current page, as React Router's `navigate` does; a hash alone drops the current query.
958
964
  */
959
965
  navigate(path: string, options?: NavigateOptions): void
960
966
 
@@ -1021,7 +1027,9 @@ interface Router {
1021
1027
  /**
1022
1028
  * The `href` an anchor to the in-app `path` carries, as the native router's own link
1023
1029
  * writes it (its base path prefixed, or `#/…` under a hash history), so a middle-click,
1024
- * a new tab or a copied link opens the same page a click does.
1030
+ * a new tab or a copied link opens the same page a click does. A `path` that is only a
1031
+ * query or a hash (`'?tab=2'`, `'#top'`) is the current page's, as `navigate` reads it
1032
+ * and as React Router's `<Link>` writes it: `'#top'` on `/docs?x=1` is `/docs#top`.
1025
1033
  *
1026
1034
  * @param path - Pathname with optional query string and hash, as passed to `navigate`.
1027
1035
  * @returns The `href`.
@@ -1029,7 +1037,15 @@ interface Router {
1029
1037
  createHref(path: string): string
1030
1038
 
1031
1039
  /**
1032
- * Subscribes to route changes.
1040
+ * Calls `listener` once after each navigation the router commits, however it started (a
1041
+ * link, the back button, `navigate`), with the new location and the navigation action.
1042
+ * A router calls it before the browser paints the new page, so a component that renders
1043
+ * from a listener (the framework bindings' `useLocation` and `useParams` do) shows the new
1044
+ * location in the same paint as the new page. The router conformance cases of
1045
+ * `@molecule/app-framework-conformance/routing` check that at every paint.
1046
+ *
1047
+ * @param listener - Called with the new location and the navigation action.
1048
+ * @returns Stops calling `listener`.
1033
1049
  */
1034
1050
  subscribe(listener: RouteChangeListener): () => void
1035
1051
 
@@ -5078,17 +5094,18 @@ Peer dependencies:
5078
5094
  - `@molecule/app-ai-chat` ^1.8.0
5079
5095
  - `@molecule/app-ai-models` ^1.0.1
5080
5096
  - `@molecule/app-auth` ^3.0.0
5081
- - `@molecule/app-code-editor` ^1.0.1
5097
+ - `@molecule/app-code-editor` ^1.0.1 _(optional)_
5082
5098
  - `@molecule/app-device` ^1.0.1
5083
5099
  - `@molecule/app-forms` ^2.4.0
5084
5100
  - `@molecule/app-http` ^1.0.1
5085
5101
  - `@molecule/app-i18n` ^1.0.1
5086
- - `@molecule/app-ide` ^1.0.1
5087
- - `@molecule/app-live-preview` ^1.0.1
5102
+ - `@molecule/app-ide` ^1.0.1 _(optional)_
5103
+ - `@molecule/app-live-preview` ^1.0.1 _(optional)_
5088
5104
  - `@molecule/app-logger` ^1.0.1
5089
5105
  - `@molecule/app-platform` ^1.0.1
5090
5106
  - `@molecule/app-push` ^1.0.1
5091
5107
  - `@molecule/app-routing` ^1.4.0
5108
+ - `@molecule/app-routing-sveltekit` >=3.0.0 _(optional)_
5092
5109
  - `@molecule/app-state` ^1.2.0
5093
5110
  - `@molecule/app-storage` ^1.1.1
5094
5111
  - `@molecule/app-theme` ^1.0.1
@@ -5102,17 +5119,18 @@ Peer dependencies:
5102
5119
  - `@molecule/app-ai-chat`
5103
5120
  - `@molecule/app-ai-models`
5104
5121
  - `@molecule/app-auth`
5105
- - `@molecule/app-code-editor`
5122
+ - `@molecule/app-code-editor` _(optional)_
5106
5123
  - `@molecule/app-device`
5107
5124
  - `@molecule/app-forms`
5108
5125
  - `@molecule/app-http`
5109
5126
  - `@molecule/app-i18n`
5110
- - `@molecule/app-ide`
5111
- - `@molecule/app-live-preview`
5127
+ - `@molecule/app-ide` _(optional)_
5128
+ - `@molecule/app-live-preview` _(optional)_
5112
5129
  - `@molecule/app-logger`
5113
5130
  - `@molecule/app-platform`
5114
5131
  - `@molecule/app-push`
5115
5132
  - `@molecule/app-routing`
5133
+ - `@molecule/app-routing-sveltekit` _(optional)_
5116
5134
  - `@molecule/app-state`
5117
5135
  - `@molecule/app-storage`
5118
5136
  - `@molecule/app-theme`
package/dist/context.js CHANGED
@@ -214,7 +214,7 @@ export function getThemeProvider() {
214
214
  export function getRouter() {
215
215
  const router = getContext(ROUTER_KEY);
216
216
  if (!router)
217
- throw new I18nError('svelte.error.noRouter', undefined, 'No router here. Mount `MoleculeRouterProvider` from the routing bond (`@molecule/app-routing-sveltekit`) in the root `+layout.svelte`, or call `setMoleculeContext({ router })` there.');
217
+ throw new I18nError('svelte.error.noRouter', undefined, 'No router here. Mount `MoleculeRouterProvider` from the routing bond (`@molecule/app-routing-sveltekit`) in the root `+layout.svelte`, or call `setMoleculeContext({ router })` there. If the app already does this, its routing bond is older than this binding: update it (`npm install @molecule/app-routing-sveltekit@latest`).');
218
218
  return router;
219
219
  }
220
220
  /**
@@ -375,7 +375,7 @@ export function useThemeProvider() {
375
375
  export function useRouterInstance() {
376
376
  const router = getContext(ROUTER_KEY);
377
377
  if (!router)
378
- throw new I18nError('svelte.error.useRouterOutsideProvider', undefined, 'No router here. Mount `MoleculeRouterProvider` from the routing bond (`@molecule/app-routing-sveltekit`) in the root `+layout.svelte`, or call `setMoleculeContext({ router })` there.');
378
+ throw new I18nError('svelte.error.useRouterOutsideProvider', undefined, 'No router here. Mount `MoleculeRouterProvider` from the routing bond (`@molecule/app-routing-sveltekit`) in the root `+layout.svelte`, or call `setMoleculeContext({ router })` there. If the app already does this, its routing bond is older than this binding: update it (`npm install @molecule/app-routing-sveltekit@latest`).');
379
379
  return router;
380
380
  }
381
381
  /**
@@ -100,16 +100,26 @@ export interface UseFormResult<T extends FormValuesConstraint<T>> {
100
100
  * @returns Form state stores and methods
101
101
  * @example
102
102
  * ```svelte
103
- * <script>
103
+ * <script lang="ts">
104
104
  * import { useForm } from '@molecule/app-svelte'
105
105
  * const { register, handleSubmit, formState, isSubmitting } = useForm({
106
106
  * defaultValues: { email: '', password: '' },
107
107
  * })
108
- * const onSubmit = handleSubmit(async (values) => { await login(values) })
108
+ * const onSubmit = handleSubmit(async (values) => {
109
+ * await login(values)
110
+ * })
109
111
  * </script>
110
112
  *
111
113
  * <form onsubmit={onSubmit}>
112
- * <input {...$registerNotNeeded} />
114
+ * <input {...register('email', { required: true, email: true })} />
115
+ * {#if $formState.errors.email}<span>{$formState.errors.email}</span>{/if}
116
+ *
117
+ * <input {...register('password', { required: true, minLength: 8 })} type="password" />
118
+ * {#if $formState.errors.password}<span>{$formState.errors.password}</span>{/if}
119
+ *
120
+ * <button type="submit" disabled={$isSubmitting}>
121
+ * {$isSubmitting ? 'Logging in...' : 'Log In'}
122
+ * </button>
113
123
  * </form>
114
124
  * ```
115
125
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAgB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAO5B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,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B,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAEhB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAC7D,IAAI,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACtC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,GAC3B,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAElC"}
@@ -32,16 +32,26 @@ import { toReadable } from './maybe-readable.js';
32
32
  * @returns Form state stores and methods
33
33
  * @example
34
34
  * ```svelte
35
- * <script>
35
+ * <script lang="ts">
36
36
  * import { useForm } from '@molecule/app-svelte'
37
37
  * const { register, handleSubmit, formState, isSubmitting } = useForm({
38
38
  * defaultValues: { email: '', password: '' },
39
39
  * })
40
- * const onSubmit = handleSubmit(async (values) => { await login(values) })
40
+ * const onSubmit = handleSubmit(async (values) => {
41
+ * await login(values)
42
+ * })
41
43
  * </script>
42
44
  *
43
45
  * <form onsubmit={onSubmit}>
44
- * <input {...$registerNotNeeded} />
46
+ * <input {...register('email', { required: true, email: true })} />
47
+ * {#if $formState.errors.email}<span>{$formState.errors.email}</span>{/if}
48
+ *
49
+ * <input {...register('password', { required: true, minLength: 8 })} type="password" />
50
+ * {#if $formState.errors.password}<span>{$formState.errors.password}</span>{/if}
51
+ *
52
+ * <button type="submit" disabled={$isSubmitting}>
53
+ * {$isSubmitting ? 'Logging in...' : 'Log In'}
54
+ * </button>
45
55
  * </form>
46
56
  * ```
47
57
  */
@@ -47,6 +47,8 @@ export interface UseOptimisticToggleResult {
47
47
  * @example
48
48
  * ```svelte
49
49
  * <script lang="ts">
50
+ * import { useOptimisticToggle } from '@molecule/app-svelte'
51
+ *
50
52
  * const subscription = useOptimisticToggle({
51
53
  * value: thread.subscribed,
52
54
  * commit: async (desired) => {
@@ -61,6 +63,8 @@ export interface UseOptimisticToggleResult {
61
63
  * </script>
62
64
  *
63
65
  * <button type="button" aria-pressed={$value} aria-busy={$pending} onclick={subscription.toggle}>
66
+ * {$value ? 'Unsubscribe' : 'Subscribe'}
67
+ * </button>
64
68
  * ```
65
69
  */
66
70
  export declare const useOptimisticToggle: (options: MaybeReadable<UseOptimisticToggleOptions>) => UseOptimisticToggleResult;
@@ -1 +1 @@
1
- {"version":3,"file":"useOptimisticToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useOptimisticToggle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAGpE,+CAA+C;AAC/C,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,KAAK,EAAE,OAAO,CAAA;IACd,yFAAyF;IACzF,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9C,0FAA0F;IAC1F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnD;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,2BAA2B;IAC3B,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,4CAA4C;IAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,wCAAwC;IACxC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,0FAA0F;IAC1F,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,aAAa,CAAC,0BAA0B,CAAC,KACjD,yBAUF,CAAA"}
1
+ {"version":3,"file":"useOptimisticToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useOptimisticToggle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAGpE,+CAA+C;AAC/C,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,KAAK,EAAE,OAAO,CAAA;IACd,yFAAyF;IACzF,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9C,0FAA0F;IAC1F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnD;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,2BAA2B;IAC3B,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,4CAA4C;IAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,wCAAwC;IACxC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,0FAA0F;IAC1F,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,aAAa,CAAC,0BAA0B,CAAC,KACjD,yBAUF,CAAA"}
@@ -25,6 +25,8 @@ import { useOptimisticValue } from './useOptimisticValue.js';
25
25
  * @example
26
26
  * ```svelte
27
27
  * <script lang="ts">
28
+ * import { useOptimisticToggle } from '@molecule/app-svelte'
29
+ *
28
30
  * const subscription = useOptimisticToggle({
29
31
  * value: thread.subscribed,
30
32
  * commit: async (desired) => {
@@ -39,6 +41,8 @@ import { useOptimisticValue } from './useOptimisticValue.js';
39
41
  * </script>
40
42
  *
41
43
  * <button type="button" aria-pressed={$value} aria-busy={$pending} onclick={subscription.toggle}>
44
+ * {$value ? 'Unsubscribe' : 'Subscribe'}
45
+ * </button>
42
46
  * ```
43
47
  */
44
48
  export const useOptimisticToggle = (options) => {
@@ -49,16 +49,32 @@ export interface UseOptimisticValueResult<T> {
49
49
  * and `set`/`update`.
50
50
  * @example
51
51
  * ```svelte
52
- * <script>
52
+ * <script lang="ts">
53
53
  * import { useOptimisticValue } from '@molecule/app-svelte'
54
54
  * // `value` is the store; the result itself is not, so take the store out to read it with `$`.
55
55
  * const { value: star, update } = useOptimisticValue({
56
56
  * value: { starred: repository.starred, stars: repository.stars },
57
- * commit: async (next) => { /* save and return the server's value * },
57
+ * equals: (a, b) => a.starred === b.starred && a.stars === b.stars,
58
+ * commit: async (next) => {
59
+ * const response = next.starred
60
+ * ? await http.put(`/repositories/${repository.id}/star`)
61
+ * : await http.delete(`/repositories/${repository.id}/star`)
62
+ * return { starred: response.data.starred, stars: response.data.stars }
63
+ * },
58
64
  * })
59
65
  * </script>
60
66
  *
61
- * <button aria-pressed={$star.starred} onclick={() => update((on) => ({ ...on, starred: !on.starred }))}>
67
+ * <!-- Never disable the button while a save is pending. -->
68
+ * <button
69
+ * aria-pressed={$star.starred}
70
+ * onclick={() =>
71
+ * update((current) => ({
72
+ * starred: !current.starred,
73
+ * stars: current.stars + (current.starred ? -1 : 1),
74
+ * }))}
75
+ * >
76
+ * {$star.stars}
77
+ * </button>
62
78
  * ```
63
79
  */
64
80
  export declare const useOptimisticValue: <T>(options: MaybeReadable<OptimisticValueOptions<T>>) => UseOptimisticValueResult<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"useOptimisticValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useOptimisticValue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAO,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAwB,MAAM,qBAAqB,CAAA;AAIvF,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAEpE;;;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A6E;IAC7E,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAA;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,SAAS,aAAa,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,KAChD,wBAAwB,CAAC,CAAC,CA6C5B,CAAA"}
@@ -33,16 +33,32 @@ import { toReadable } from './maybe-readable.js';
33
33
  * and `set`/`update`.
34
34
  * @example
35
35
  * ```svelte
36
- * <script>
36
+ * <script lang="ts">
37
37
  * import { useOptimisticValue } from '@molecule/app-svelte'
38
38
  * // `value` is the store; the result itself is not, so take the store out to read it with `$`.
39
39
  * const { value: star, update } = useOptimisticValue({
40
40
  * value: { starred: repository.starred, stars: repository.stars },
41
- * commit: async (next) => { /* save and return the server's value * },
41
+ * equals: (a, b) => a.starred === b.starred && a.stars === b.stars,
42
+ * commit: async (next) => {
43
+ * const response = next.starred
44
+ * ? await http.put(`/repositories/${repository.id}/star`)
45
+ * : await http.delete(`/repositories/${repository.id}/star`)
46
+ * return { starred: response.data.starred, stars: response.data.stars }
47
+ * },
42
48
  * })
43
49
  * </script>
44
50
  *
45
- * <button aria-pressed={$star.starred} onclick={() => update((on) => ({ ...on, starred: !on.starred }))}>
51
+ * <!-- Never disable the button while a save is pending. -->
52
+ * <button
53
+ * aria-pressed={$star.starred}
54
+ * onclick={() =>
55
+ * update((current) => ({
56
+ * starred: !current.starred,
57
+ * stars: current.stars + (current.starred ? -1 : 1),
58
+ * }))}
59
+ * >
60
+ * {$star.stars}
61
+ * </button>
46
62
  * ```
47
63
  */
48
64
  export const useOptimisticValue = (options) => {
@@ -45,10 +45,11 @@ export type UsePromiseStore<T, A extends unknown[]> = Readable<readonly [UseProm
45
45
  * @returns A readable store of the [state, wrappedFunction] tuple.
46
46
  * @example
47
47
  * ```svelte
48
- * <script>
48
+ * <script lang="ts">
49
49
  * import { usePromise } from '@molecule/app-svelte'
50
50
  * const fetchUser = usePromise((id: string) => api.getUser(id))
51
- * const [state, call] = $fetchUser
51
+ * // `$fetchUser` is the [state, call] tuple; `$derived` keeps it current.
52
+ * const [state, call] = $derived($fetchUser)
52
53
  * </script>
53
54
  *
54
55
  * <button onclick={() => call('123')} disabled={state.status === 'pending'}>
@@ -1 +1 @@
1
- {"version":3,"file":"usePromise.d.ts","sourceRoot":"","sources":["../../src/hooks/usePromise.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,QAAQ,EAA2B,MAAM,cAAc,CAAA;AAErE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,IAAI,QAAQ,CAC5D,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAC1D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAC/C,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAClC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAmEvB"}
1
+ {"version":3,"file":"usePromise.d.ts","sourceRoot":"","sources":["../../src/hooks/usePromise.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,QAAQ,EAA2B,MAAM,cAAc,CAAA;AAErE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,aAAa,CAAA;IACrB,KAAK,EAAE,CAAC,GAAG,IAAI,CAAA;IACf,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,IAAI,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,IAAI,QAAQ,CAC5D,SAAS,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAC1D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,EAC/C,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAClC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAmEvB"}
@@ -31,10 +31,11 @@ import { writable } from 'svelte/store';
31
31
  * @returns A readable store of the [state, wrappedFunction] tuple.
32
32
  * @example
33
33
  * ```svelte
34
- * <script>
34
+ * <script lang="ts">
35
35
  * import { usePromise } from '@molecule/app-svelte'
36
36
  * const fetchUser = usePromise((id: string) => api.getUser(id))
37
- * const [state, call] = $fetchUser
37
+ * // `$fetchUser` is the [state, call] tuple; `$derived` keeps it current.
38
+ * const [state, call] = $derived($fetchUser)
38
39
  * </script>
39
40
  *
40
41
  * <button onclick={() => call('123')} disabled={state.status === 'pending'}>
@@ -56,13 +56,17 @@ export interface UseTranslationResult {
56
56
  * @returns The translation function and the locale values as stores.
57
57
  * @example
58
58
  * ```svelte
59
- * <script>
59
+ * <script lang="ts">
60
60
  * import { useTranslation } from '@molecule/app-svelte'
61
- * const { t, locale } = useTranslation()
61
+ * const { t, locale, locales, setLocale } = useTranslation()
62
62
  * </script>
63
63
  *
64
64
  * <h1>{t('welcome.title', { name: 'User' })}</h1>
65
65
  * <select value={$locale} onchange={(e) => setLocale(e.currentTarget.value)}>
66
+ * {#each $locales as option (option.code)}
67
+ * <option value={option.code}>{option.name}</option>
68
+ * {/each}
69
+ * </select>
66
70
  * ```
67
71
  */
68
72
  export declare function useTranslation(): UseTranslationResult;
@@ -1 +1 @@
1
- {"version":3,"file":"useTranslation.d.ts","sourceRoot":"","sources":["../../src/hooks/useTranslation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAsB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE1E,OAAO,KAAK,EAEV,YAAY,EAGZ,gBAAgB,EACjB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAEpE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAA;AAEzE;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG;IAC7C,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAA;CACxE,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,CAAA;IACpB,8BAA8B;IAC9B,MAAM,EAAE,QAAQ,CA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
64
64
  * @returns The translation function and the locale values as stores.
65
65
  * @example
66
66
  * ```svelte
67
- * <script>
67
+ * <script lang="ts">
68
68
  * import { useTranslation } from '@molecule/app-svelte'
69
- * const { t, locale } = useTranslation()
69
+ * const { t, locale, locales, setLocale } = useTranslation()
70
70
  * </script>
71
71
  *
72
72
  * <h1>{t('welcome.title', { name: 'User' })}</h1>
73
73
  * <select value={$locale} onchange={(e) => setLocale(e.currentTarget.value)}>
74
+ * {#each $locales as option (option.code)}
75
+ * <option value={option.code}>{option.name}</option>
76
+ * {/each}
77
+ * </select>
74
78
  * ```
75
79
  */
76
80
  export function useTranslation() {
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@
10
10
  * ```svelte
11
11
  * <!-- +layout.svelte — wire providers ONCE, during component init -->
12
12
  * <script lang="ts">
13
+ * import type { Snippet } from 'svelte'
13
14
  * import { setMoleculeContext } from '@molecule/app-svelte'
14
15
  * import { provider as stateProvider } from '@molecule/app-state-zustand'
15
16
  * import { provider as themeProvider } from '@molecule/app-theme-css-variables'
@@ -20,10 +21,14 @@
20
21
  * auth: createJWTAuthClient({ baseURL: '/api' }),
21
22
  * theme: themeProvider,
22
23
  * })
24
+ *
25
+ * let { children }: { children: Snippet } = $props()
23
26
  * </script>
24
27
  *
25
- * <slot />
28
+ * {@render children()}
29
+ * ```
26
30
  *
31
+ * ```svelte
27
32
  * <!-- Component.svelte — consume via stores -->
28
33
  * <script lang="ts">
29
34
  * import { createAuthStores, createThemeStores } from '@molecule/app-svelte'
@@ -35,8 +40,8 @@
35
40
  * {#if $isAuthenticated}
36
41
  * <div style:background={$theme.colors.background}>
37
42
  * <h1>Welcome, {$user?.name}!</h1>
38
- * <button on:click={toggleTheme}>Toggle ({$mode})</button>
39
- * <button on:click={() => logout()}>Logout</button>
43
+ * <button onclick={toggleTheme}>Toggle ({$mode})</button>
44
+ * <button onclick={() => logout()}>Logout</button>
40
45
  * </div>
41
46
  * {/if}
42
47
  * ```
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyIG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8IG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@
10
10
  * ```svelte
11
11
  * <!-- +layout.svelte — wire providers ONCE, during component init -->
12
12
  * <script lang="ts">
13
+ * import type { Snippet } from 'svelte'
13
14
  * import { setMoleculeContext } from '@molecule/app-svelte'
14
15
  * import { provider as stateProvider } from '@molecule/app-state-zustand'
15
16
  * import { provider as themeProvider } from '@molecule/app-theme-css-variables'
@@ -20,10 +21,14 @@
20
21
  * auth: createJWTAuthClient({ baseURL: '/api' }),
21
22
  * theme: themeProvider,
22
23
  * })
24
+ *
25
+ * let { children }: { children: Snippet } = $props()
23
26
  * </script>
24
27
  *
25
- * <slot />
28
+ * {@render children()}
29
+ * ```
26
30
  *
31
+ * ```svelte
27
32
  * <!-- Component.svelte — consume via stores -->
28
33
  * <script lang="ts">
29
34
  * import { createAuthStores, createThemeStores } from '@molecule/app-svelte'
@@ -35,8 +40,8 @@
35
40
  * {#if $isAuthenticated}
36
41
  * <div style:background={$theme.colors.background}>
37
42
  * <h1>Welcome, {$user?.name}!</h1>
38
- * <button on:click={toggleTheme}>Toggle ({$mode})</button>
39
- * <button on:click={() => logout()}>Logout</button>
43
+ * <button onclick={toggleTheme}>Toggle ({$mode})</button>
44
+ * <button onclick={() => logout()}>Logout</button>
40
45
  * </div>
41
46
  * {/if}
42
47
  * ```
@@ -42,14 +42,14 @@ interface HttpStoreFactory {
42
42
  *
43
43
  * @example
44
44
  * ```svelte
45
- * <script>
45
+ * <script lang="ts">
46
46
  * import { createHttpStore } from '@molecule/app-svelte'
47
47
  *
48
- * const users = createHttpStore('GET', '/api/users')
48
+ * const users = createHttpStore<{ id: string; name: string }[]>('GET', '/api/users')
49
49
  *
50
- * $: if ($users.loading) console.log('Loading...')
51
- * $: if ($users.error) console.error($users.error)
52
- * $: if ($users.data) console.log('Users:', $users.data)
50
+ * $effect(() => {
51
+ * if ($users.error) console.error($users.error)
52
+ * })
53
53
  *
54
54
  * users.execute()
55
55
  * </script>
@@ -60,7 +60,7 @@ interface HttpStoreFactory {
60
60
  * <p>Error: {$users.error.message}</p>
61
61
  * {:else if $users.data}
62
62
  * <ul>
63
- * {#each $users.data as user}
63
+ * {#each $users.data as user (user.id)}
64
64
  * <li>{user.name}</li>
65
65
  * {/each}
66
66
  * </ul>
@@ -15,14 +15,14 @@ import { getHttpClient } from '../context.js';
15
15
  *
16
16
  * @example
17
17
  * ```svelte
18
- * <script>
18
+ * <script lang="ts">
19
19
  * import { createHttpStore } from '@molecule/app-svelte'
20
20
  *
21
- * const users = createHttpStore('GET', '/api/users')
21
+ * const users = createHttpStore<{ id: string; name: string }[]>('GET', '/api/users')
22
22
  *
23
- * $: if ($users.loading) console.log('Loading...')
24
- * $: if ($users.error) console.error($users.error)
25
- * $: if ($users.data) console.log('Users:', $users.data)
23
+ * $effect(() => {
24
+ * if ($users.error) console.error($users.error)
25
+ * })
26
26
  *
27
27
  * users.execute()
28
28
  * </script>
@@ -33,7 +33,7 @@ import { getHttpClient } from '../context.js';
33
33
  * <p>Error: {$users.error.message}</p>
34
34
  * {:else if $users.data}
35
35
  * <ul>
36
- * {#each $users.data as user}
36
+ * {#each $users.data as user (user.id)}
37
37
  * <li>{user.name}</li>
38
38
  * {/each}
39
39
  * </ul>
@@ -12,17 +12,17 @@ import type { UpdateCheckOptions, VersionState } from '@molecule/app-version';
12
12
  *
13
13
  * @example
14
14
  * ```svelte
15
- * <script>
15
+ * <script lang="ts">
16
16
  * import { createVersionStores } from '@molecule/app-svelte'
17
17
  *
18
- * const { state, isUpdateAvailable, applyUpdate, dismissUpdate } = createVersionStores()
18
+ * const { isUpdateAvailable, newVersion, applyUpdate, dismissUpdate } = createVersionStores()
19
19
  * </script>
20
20
  *
21
21
  * {#if $isUpdateAvailable}
22
22
  * <div>
23
23
  * <p>New version available: {$newVersion}</p>
24
- * <button on:click={() => applyUpdate()}>Update</button>
25
- * <button on:click={dismissUpdate}>Dismiss</button>
24
+ * <button onclick={() => applyUpdate()}>Update</button>
25
+ * <button onclick={dismissUpdate}>Dismiss</button>
26
26
  * </div>
27
27
  * {/if}
28
28
  * ```
@@ -12,17 +12,17 @@ import { getProvider } from '@molecule/app-version';
12
12
  *
13
13
  * @example
14
14
  * ```svelte
15
- * <script>
15
+ * <script lang="ts">
16
16
  * import { createVersionStores } from '@molecule/app-svelte'
17
17
  *
18
- * const { state, isUpdateAvailable, applyUpdate, dismissUpdate } = createVersionStores()
18
+ * const { isUpdateAvailable, newVersion, applyUpdate, dismissUpdate } = createVersionStores()
19
19
  * </script>
20
20
  *
21
21
  * {#if $isUpdateAvailable}
22
22
  * <div>
23
23
  * <p>New version available: {$newVersion}</p>
24
- * <button on:click={() => applyUpdate()}>Update</button>
25
- * <button on:click={dismissUpdate}>Dismiss</button>
24
+ * <button onclick={() => applyUpdate()}>Update</button>
25
+ * <button onclick={dismissUpdate}>Dismiss</button>
26
26
  * </div>
27
27
  * {/if}
28
28
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-svelte",
3
- "version": "3.10.0",
3
+ "version": "3.11.0",
4
4
  "description": "Svelte framework bindings for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -52,6 +52,7 @@
52
52
  "@molecule/app-platform": "^1.0.1",
53
53
  "@molecule/app-push": "^1.0.1",
54
54
  "@molecule/app-routing": "^1.4.0",
55
+ "@molecule/app-routing-sveltekit": ">=3.0.0",
55
56
  "@molecule/app-state": "^1.2.0",
56
57
  "@molecule/app-storage": "^1.1.1",
57
58
  "@molecule/app-theme": "^1.0.1",
@@ -69,6 +70,9 @@
69
70
  },
70
71
  "@molecule/app-live-preview": {
71
72
  "optional": true
73
+ },
74
+ "@molecule/app-routing-sveltekit": {
75
+ "optional": true
72
76
  }
73
77
  },
74
78
  "devDependencies": {