@molecule/app-svelte 3.7.2 → 3.8.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-18T16:22:02.310Z
6
+ Generated: 2026-11-20T06:32:18.746Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-svelte
@@ -55,6 +55,87 @@ then consume services anywhere below via store factories
55
55
  {/if}
56
56
  ```
57
57
 
58
+ ```svelte
59
+ <!-- Dashboard.svelte — the session, the theme and translations as stores -->
60
+ <script lang="ts">
61
+ import { useAuth, useTheme, useTranslation } from '@molecule/app-svelte'
62
+
63
+ const { user, status, logout } = useAuth<{ name?: string }>()
64
+ const { t } = useTranslation()
65
+ const { theme, toggleTheme } = useTheme()
66
+ </script>
67
+
68
+ {#if $status === 'loading'}
69
+ <p>{t('auth.restoring', undefined, { defaultValue: 'Restoring session...' })}</p>
70
+ {:else if $status === 'unauthenticated'}
71
+ <p>{t('auth.required', undefined, { defaultValue: 'Please log in.' })}</p>
72
+ {:else}
73
+ <div style:background={$theme.colors.background}>
74
+ <h1>
75
+ {t('greeting.welcome', { name: $user?.name ?? '' }, { defaultValue: 'Welcome, {{name}}!' })}
76
+ </h1>
77
+ <button onclick={toggleTheme}>
78
+ {t('theme.toggle', undefined, { defaultValue: 'Toggle theme' })}
79
+ </button>
80
+ <button onclick={() => logout()}>
81
+ {t('auth.logout', undefined, { defaultValue: 'Log out' })}
82
+ </button>
83
+ </div>
84
+ {/if}
85
+ ```
86
+
87
+ ```svelte
88
+ <!-- FavoriteButton.svelte — a server-backed favorite that changes at once -->
89
+ <script lang="ts">
90
+ import { useHttpClient, useOptimisticValue, useTranslation } from '@molecule/app-svelte'
91
+
92
+ interface FavoriteRecord {
93
+ slug: string
94
+ favorited: boolean
95
+ favoritesCount: number
96
+ }
97
+
98
+ let {
99
+ article,
100
+ onChanged,
101
+ }: {
102
+ article: FavoriteRecord
103
+ onChanged?: (saved: FavoriteRecord) => void
104
+ } = $props()
105
+
106
+ const http = useHttpClient()
107
+ const { t } = useTranslation()
108
+ const { value: favorite, update } = useOptimisticValue({
109
+ value: { favorited: article.favorited, count: article.favoritesCount },
110
+ commit: async (next) => {
111
+ const path = `/articles/${article.slug}/favorite`
112
+ const response = next.favorited
113
+ ? await http.post<{ article: FavoriteRecord }>(path)
114
+ : await http.delete<{ article: FavoriteRecord }>(path)
115
+ const saved = response.data.article
116
+ onChanged?.(saved)
117
+ return { favorited: saved.favorited, count: saved.favoritesCount }
118
+ },
119
+ })
120
+ </script>
121
+
122
+ <button
123
+ aria-pressed={$favorite.favorited}
124
+ aria-label={t('article.favorite', undefined, { defaultValue: 'Favorite article' })}
125
+ onclick={() =>
126
+ update((current) => ({
127
+ favorited: !current.favorited,
128
+ count: current.count + (current.favorited ? -1 : 1),
129
+ }))}>{$favorite.count}</button
130
+ >
131
+ ```
132
+
133
+ Session state is a three-way decision, not a boolean: `status === 'loading'`
134
+ is undecided, so wait for it and redirect only on
135
+ `status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
136
+ for retry, so a restore that failed with anything other than a 401/403 never
137
+ signs the user out.
138
+
58
139
  ## Type
59
140
 
60
141
  `framework`
@@ -712,46 +793,21 @@ interface HttpClient {
712
793
  */
713
794
  getAuthToken(): string | null
714
795
 
715
- /**
716
- * Registers the LIVE token resolver every request of this client reads, or clears it with
717
- * `null`.
718
- *
719
- * `@molecule/app-http`'s `setAuthTokenSource()` calls this on every client it bonds, and the
720
- * client MUST consult the resolver again each time it assembles a request (and report it from
721
- * `getAuthToken()`). A session can change with no auth event and no observable state change —
722
- * `authClient.setSession()` with the same profile data, or the OAuth callback's
723
- * `setAccessToken()` — so a token pushed only at bond time or on `login`/`logout` events
724
- * leaves every later request carrying the PREVIOUS session's bearer while the UI shows the
725
- * new one.
726
- *
727
- * The resolved token takes the static token's place, with the same precedence: an
728
- * `Authorization` header passed per request or in the client's default headers wins over it
729
- * exactly where it won over a static token in this transport.
730
- *
731
- * A resolver that returns `null` (or `undefined`) means "this session has no body token": the
732
- * request carries no `Authorization` header of the client's own. A cookie-session API issues
733
- * no bearer, and the server prefers the header over the fresh cookie, so a kept bearer
734
- * authenticates as the prior — possibly deleted — session.
735
- *
736
- * Optional, so an implementation written against the previous interface still conforms.
737
- * `setAuthTokenSource()` follows such a client through a request interceptor instead, pushing
738
- * the source with `setAuthToken` before each request: that request carries the change only
739
- * when the transport applies its token after running its interceptors, so a transport that
740
- * applies it earlier sends a session adopted mid-page from the following request on.
741
- *
742
- * @param resolver - Returns the current access token (or null/undefined), or `null` to clear.
743
- */
796
+ /** Registers the LIVE token resolver every request of this client reads, or clears it with `null`. */
744
797
  setAuthTokenResolver?(resolver: AuthTokenResolver | null): void
745
798
 
746
799
  /**
747
- * Registers a handler for authentication errors (401).
800
+ * Registers a handler for authentication errors (401), with the rejected request's metadata.
748
801
  *
802
+ * @param handler - Receives the method, URL and credential state of the rejected request.
749
803
  * @returns An unsubscribe function.
750
804
  */
751
- onAuthError(handler: () => void): () => void
805
+ onAuthError(handler: (event: HttpAuthErrorEvent) => void): () => void
752
806
  }
753
807
  ```
754
808
 
809
+ _(The longest member comment is shortened to its first sentence to fit; the full declaration is in `node_modules/@molecule/app-http/dist/client.d.ts`.)_
810
+
755
811
  #### `I18nProvider`
756
812
 
757
813
  i18n provider interface.
@@ -1180,6 +1236,16 @@ interface Router {
1180
1236
  */
1181
1237
  generatePath(name: string, params?: RouteParams, query?: QueryParams): string
1182
1238
 
1239
+ /**
1240
+ * The `href` an anchor to the in-app `path` carries, as the native router's own link
1241
+ * writes it (its base path prefixed, or `#/…` under a hash history), so a middle-click,
1242
+ * a new tab or a copied link opens the same page a click does.
1243
+ *
1244
+ * @param path - Pathname with optional query string and hash, as passed to `navigate`.
1245
+ * @returns The `href`.
1246
+ */
1247
+ createHref(path: string): string
1248
+
1183
1249
  /**
1184
1250
  * Subscribes to route changes.
1185
1251
  */
@@ -2243,6 +2309,18 @@ interface UseStoreOptions<T, S> {
2243
2309
  }
2244
2310
  ```
2245
2311
 
2312
+ #### `SelectingStoreOptions`
2313
+
2314
+ Options for {@link useStore} that pick part of the store: a selector is
2315
+ required, so the selected type `S` always comes from it.
2316
+
2317
+ ```typescript
2318
+ interface SelectingStoreOptions<T, S> extends UseStoreOptions<T, S> {
2319
+ /** Picks the value the hook returns from the store's state. */
2320
+ selector: (state: T) => S
2321
+ }
2322
+ ```
2323
+
2246
2324
  #### `UseThemeResult`
2247
2325
 
2248
2326
  What {@link useTheme} returns.
@@ -2411,7 +2489,7 @@ Props for `Link`. Every other anchor attribute (`class`, `target`, `rel`,
2411
2489
 
2412
2490
  ```typescript
2413
2491
  interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children'> {
2414
- /** Destination: an app path (`/settings?tab=billing#plan`) or a URL. Rendered as the anchor's `href`. */
2492
+ /** Destination: an app path (`/settings?tab=billing#plan`) or a URL. An app path's `href` is the one the router writes for it (`routerLinkHref`), base path included. */
2415
2493
  to: string
2416
2494
  /**
2417
2495
  * Replace the current history entry instead of pushing one. When omitted, a
@@ -2423,6 +2501,8 @@ interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children'> {
2423
2501
  state?: unknown
2424
2502
  /** The link's content. */
2425
2503
  children?: Snippet
2504
+ /** The rendered anchor (`bind:ref`), as React's `ref` receives it. */
2505
+ ref?: HTMLAnchorElement | null
2426
2506
  }
2427
2507
  ```
2428
2508
 
@@ -2516,8 +2596,8 @@ interface PasswordResetStores {
2516
2596
  Promise store with action methods.
2517
2597
 
2518
2598
  ```typescript
2519
- interface PromiseStore<T> extends Readable<PromiseState<T>> {
2520
- call: (...args: any[]) => Promise<T>
2599
+ interface PromiseStore<T, A extends unknown[] = unknown[]> extends Readable<PromiseState<T>> {
2600
+ call: (...args: A) => Promise<T>
2521
2601
  cancel: (message?: string) => void
2522
2602
  reset: () => void
2523
2603
  }
@@ -2744,7 +2824,7 @@ type CapacitorAppStore = Readable<CapacitorAppState> & {
2744
2824
  Change password store type.
2745
2825
 
2746
2826
  ```typescript
2747
- type ChangePasswordStore = PromiseStore<void>
2827
+ type ChangePasswordStore = PromiseStore<void, [string, string]>
2748
2828
  ```
2749
2829
 
2750
2830
  #### `UseChatOptions`
@@ -2779,7 +2859,7 @@ type UseChatResult = {
2779
2859
  Login store type.
2780
2860
 
2781
2861
  ```typescript
2782
- type LoginStore<T = unknown> = PromiseStore<AuthResult<T>>
2862
+ type LoginStore<T = unknown> = PromiseStore<AuthResult<T>, [LoginCredentials]>
2783
2863
  ```
2784
2864
 
2785
2865
  #### `SignupStore`
@@ -2787,7 +2867,7 @@ type LoginStore<T = unknown> = PromiseStore<AuthResult<T>>
2787
2867
  Signup store type.
2788
2868
 
2789
2869
  ```typescript
2790
- type SignupStore<T = unknown> = PromiseStore<AuthResult<T>>
2870
+ type SignupStore<T = unknown> = PromiseStore<AuthResult<T>, [RegisterData]>
2791
2871
  ```
2792
2872
 
2793
2873
  ### Functions
@@ -3372,13 +3452,13 @@ a readable store of the field's current value.
3372
3452
 
3373
3453
  ```typescript
3374
3454
  function useWatch<T extends FormValuesConstraint<T>, K extends keyof T>(
3375
- form: FormController<T>,
3376
- name: K,
3455
+ form: MaybeReadable<FormController<T>>,
3456
+ name: MaybeReadable<K>,
3377
3457
  ): Readable<T[K]>
3378
3458
  ```
3379
3459
 
3380
- - `form` — Form controller
3381
- - `name` — Field name to watch
3460
+ - `form` — Form controller, or a readable store of one
3461
+ - `name` — Field name to watch, or a readable store of one
3382
3462
 
3383
3463
  **Returns:** A readable store of the current field value
3384
3464
 
@@ -3389,13 +3469,13 @@ readable store of the field's state.
3389
3469
 
3390
3470
  ```typescript
3391
3471
  function useFieldState<T extends FormValuesConstraint<T>>(
3392
- form: FormController<T>,
3393
- name: keyof T,
3472
+ form: MaybeReadable<FormController<T>>,
3473
+ name: MaybeReadable<keyof T>,
3394
3474
  ): Readable<FieldState<T[keyof T]>>
3395
3475
  ```
3396
3476
 
3397
- - `form` — Form controller
3398
- - `name` — Field name
3477
+ - `form` — Form controller, or a readable store of one
3478
+ - `name` — Field name, or a readable store of one
3399
3479
 
3400
3480
  **Returns:** A readable store of the field state (value, error, touched, dirty, valid, validating)
3401
3481
 
@@ -4005,10 +4085,10 @@ The selector and equality function run with the same cadence as React's
4005
4085
  every render; {@link useSyncExternalStore} documents the cadence.
4006
4086
 
4007
4087
  ```typescript
4008
- function useStore<T, S = T>(
4088
+ function useStore<T>(
4009
4089
  store: MaybeReadable<Store<T>>,
4010
- options?: MaybeReadable<UseStoreOptions<T, S> | undefined>,
4011
- ): Readable<S>
4090
+ options?: MaybeReadable<UseStoreOptions<T, T> | undefined>,
4091
+ ): Readable<T>
4012
4092
  ```
4013
4093
 
4014
4094
  - `store` — The store to subscribe to (or a readable store of it).
@@ -4639,9 +4719,9 @@ function createPlatformStores(): {
4639
4719
  Creates a store that tracks async function state.
4640
4720
 
4641
4721
  ```typescript
4642
- function createPromiseStore<T extends (...args: any[]) => Promise<any>>(
4643
- asyncFn: T,
4644
- ): PromiseStore<Awaited<ReturnType<T>>>
4722
+ function createPromiseStore<T, A extends unknown[]>(
4723
+ asyncFn: (...args: A) => Promise<T>,
4724
+ ): PromiseStore<T, A>
4645
4725
  ```
4646
4726
 
4647
4727
  - `asyncFn` — The async function to track
@@ -4970,7 +5050,7 @@ Peer dependencies:
4970
5050
  - `@molecule/app-logger` ^1.0.1
4971
5051
  - `@molecule/app-platform` ^1.0.1
4972
5052
  - `@molecule/app-push` ^1.0.1
4973
- - `@molecule/app-routing` ^1.3.0
5053
+ - `@molecule/app-routing` ^1.4.0
4974
5054
  - `@molecule/app-state` ^1.2.0
4975
5055
  - `@molecule/app-storage` ^1.1.1
4976
5056
  - `@molecule/app-theme` ^1.0.1
@@ -13,6 +13,20 @@
13
13
  import { type Readable } from 'svelte/store';
14
14
  import type { PromiseStatus } from '@molecule/app-utilities';
15
15
  import type { UsePromiseStore } from './usePromise.js';
16
+ /**
17
+ * A readable store that always holds `read()`'s value, plus a way to re-read
18
+ * the service now (`refresh`), which a hydrating hook uses to move from the
19
+ * value the server rendered to the live one.
20
+ *
21
+ * @template T - The value the store holds.
22
+ */
23
+ export interface LiveStore<T> extends Readable<T> {
24
+ /**
25
+ * Re-reads the service immediately and publishes the value, without waiting
26
+ * for the service to notify. React's binding does this right after hydration.
27
+ */
28
+ refresh(): void;
29
+ }
16
30
  /**
17
31
  * A readable store that always holds `read()`'s value.
18
32
  *
@@ -23,9 +37,11 @@ import type { UsePromiseStore } from './usePromise.js';
23
37
  *
24
38
  * @param read - Reads the service's current value.
25
39
  * @param subscribe - Subscribes the service; returns its unsubscribe.
26
- * @returns A readable store of the current value.
40
+ * @param initial - The value before the first live read, when a caller has
41
+ * one (a hydrating hook seeds the server's value, then calls `refresh`).
42
+ * @returns A readable store of the current value, with `refresh`.
27
43
  */
28
- export declare function liveStore<T>(read: () => T, subscribe: (notify: () => void) => () => void): Readable<T>;
44
+ export declare function liveStore<T>(read: () => T, subscribe: (notify: () => void) => () => void, initial?: T): LiveStore<T>;
29
45
  /**
30
46
  * One picked field of a state store, as its own readable store.
31
47
  *
@@ -1 +1 @@
1
- {"version":3,"file":"live-store.d.ts","sourceRoot":"","sources":["../../src/hooks/live-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAgB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAE5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,IAAI,EAA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import { derived, get, writable } from 'svelte/store';
22
22
  *
23
23
  * @param read - Reads the service's current value.
24
24
  * @param subscribe - Subscribes the service; returns its unsubscribe.
25
- * @returns A readable store of the current value.
25
+ * @param initial - The value before the first live read, when a caller has
26
+ * one (a hydrating hook seeds the server's value, then calls `refresh`).
27
+ * @returns A readable store of the current value, with `refresh`.
26
28
  */
27
- export function liveStore(read, subscribe) {
28
- const store = writable(read());
29
- const stop = subscribe(() => store.set(read()));
29
+ export function liveStore(read, subscribe, initial = read()) {
30
+ const store = writable(initial);
31
+ /** Re-reads the service now; `subscribe`'s callback is the same read. */
32
+ const refresh = () => store.set(read());
33
+ const stop = subscribe(refresh);
30
34
  onDestroy(stop);
31
- return { subscribe: store.subscribe };
35
+ return { subscribe: store.subscribe, refresh };
32
36
  }
33
37
  /**
34
38
  * One picked field of a state store, as its own readable store.
@@ -118,8 +118,8 @@ export declare function useForm<T extends FormValuesConstraint<T> = Record<strin
118
118
  * Hook to watch a specific field value, React's `useWatch` in Svelte's idiom:
119
119
  * a readable store of the field's current value.
120
120
  *
121
- * @param form - Form controller
122
- * @param name - Field name to watch
121
+ * @param form - Form controller, or a readable store of one
122
+ * @param name - Field name to watch, or a readable store of one
123
123
  * @returns A readable store of the current field value
124
124
  * @example
125
125
  * ```svelte
@@ -132,14 +132,14 @@ export declare function useForm<T extends FormValuesConstraint<T> = Record<strin
132
132
  * <p>{$country}</p>
133
133
  * ```
134
134
  */
135
- export declare function useWatch<T extends FormValuesConstraint<T>, K extends keyof T>(form: FormController<T>, name: K): Readable<T[K]>;
135
+ export declare function useWatch<T extends FormValuesConstraint<T>, K extends keyof T>(form: MaybeReadable<FormController<T>>, name: MaybeReadable<K>): Readable<T[K]>;
136
136
  /**
137
137
  * Hook to get field-level state, React's `useFieldState` in Svelte's idiom: a
138
138
  * readable store of the field's state.
139
139
  *
140
- * @param form - Form controller
141
- * @param name - Field name
140
+ * @param form - Form controller, or a readable store of one
141
+ * @param name - Field name, or a readable store of one
142
142
  * @returns A readable store of the field state (value, error, touched, dirty, valid, validating)
143
143
  */
144
- export declare function useFieldState<T extends FormValuesConstraint<T>>(form: FormController<T>, name: keyof T): Readable<FieldState<T[keyof T]>>;
144
+ export declare function useFieldState<T extends FormValuesConstraint<T>>(form: MaybeReadable<FormController<T>>, name: MaybeReadable<keyof T>): Readable<FieldState<T[keyof T]>>;
145
145
  //# sourceMappingURL=useForm.d.ts.map
@@ -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,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,CAAC;IACvF,+GAA+G;IAC/G,YAAY,CAAC,EAAE,gBAAgB,CAAA;IAC/B,+GAA+G;IAC/G,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAA;IACpD;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,CAAA;CAC5D;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC;IAC9D,4BAA4B;IAC5B,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IACjC,6CAA6C;IAC7C,OAAO,E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,CAAC,CAAC,CAAC,KAAK,IAAI;KACnD,CAAA;IACD,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;CACjC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjF,OAAO,GAAE,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,SAAS,CAAM,GACzD,aAAa,CAAC,CAAC,CAAC,CAiMlB;AAuDD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAC3E,IAAI,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACtC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GACrB,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"}
@@ -202,12 +202,57 @@ export function useForm(options = {}) {
202
202
  validate,
203
203
  };
204
204
  }
205
+ /**
206
+ * Subscribes a controller selection and republishes what `read` returns.
207
+ *
208
+ * The controller and the field name are each a plain value or a readable
209
+ * store (React's `rerender` with new props is a store the app sets): a change
210
+ * re-subscribes the new controller — the old subscription is ended, so an
211
+ * update to a controller or field that is no longer selected is not read.
212
+ *
213
+ * @param form - The controller, or a store of it.
214
+ * @param name - The field name, or a store of it.
215
+ * @param read - Reads the selected field's published value from the controller.
216
+ * @returns The selected value as a readable store.
217
+ */
218
+ function followField(form, name, read) {
219
+ const formSource = toReadable(form);
220
+ const nameSource = toReadable(name);
221
+ const state = writable(read(get(formSource), get(nameSource)));
222
+ let subscribed = null;
223
+ let stopController = null;
224
+ const follow = () => {
225
+ const controller = get(formSource);
226
+ const field = get(nameSource);
227
+ if (subscribed !== null && subscribed.controller === controller && subscribed.field === field) {
228
+ return;
229
+ }
230
+ stopController?.();
231
+ subscribed = { controller, field };
232
+ stopController = controller.subscribe(() => {
233
+ state.set(read(controller, field));
234
+ });
235
+ // A controller can change after the first read but before the subscription
236
+ // settles (React's refresh right after subscribing).
237
+ state.set(read(controller, field));
238
+ };
239
+ // A store calls back at once with its current value; a plain value arrives as
240
+ // a constant store, so the first callback is the creation read's follow-up.
241
+ const stopForm = formSource.subscribe(follow);
242
+ const stopName = nameSource.subscribe(follow);
243
+ onDestroy(() => {
244
+ stopForm();
245
+ stopName();
246
+ stopController?.();
247
+ });
248
+ return { subscribe: state.subscribe };
249
+ }
205
250
  /**
206
251
  * Hook to watch a specific field value, React's `useWatch` in Svelte's idiom:
207
252
  * a readable store of the field's current value.
208
253
  *
209
- * @param form - Form controller
210
- * @param name - Field name to watch
254
+ * @param form - Form controller, or a readable store of one
255
+ * @param name - Field name to watch, or a readable store of one
211
256
  * @returns A readable store of the current field value
212
257
  * @example
213
258
  * ```svelte
@@ -221,33 +266,16 @@ export function useForm(options = {}) {
221
266
  * ```
222
267
  */
223
268
  export function useWatch(form, name) {
224
- // The whole state as the cached snapshot (React's useFormSnapshot over
225
- // getValue), one read at creation, one re-read after subscribing, one per
226
- // notification.
227
- const state = writable(form.getState());
228
- const refresh = () => {
229
- state.set(form.getState());
230
- };
231
- const unsubscribe = form.subscribe(refresh);
232
- refresh();
233
- onDestroy(unsubscribe);
234
- return derived(state, (current) => current.values[name]);
269
+ return followField(form, name, (controller, field) => controller.getState().values[field]);
235
270
  }
236
271
  /**
237
272
  * Hook to get field-level state, React's `useFieldState` in Svelte's idiom: a
238
273
  * readable store of the field's state.
239
274
  *
240
- * @param form - Form controller
241
- * @param name - Field name
275
+ * @param form - Form controller, or a readable store of one
276
+ * @param name - Field name, or a readable store of one
242
277
  * @returns A readable store of the field state (value, error, touched, dirty, valid, validating)
243
278
  */
244
279
  export function useFieldState(form, name) {
245
- const state = writable(form.getFieldState(name));
246
- const refresh = () => {
247
- state.set(form.getFieldState(name));
248
- };
249
- const unsubscribe = form.subscribe(refresh);
250
- refresh();
251
- onDestroy(unsubscribe);
252
- return { subscribe: state.subscribe };
280
+ return followField(form, name, (controller, field) => controller.getFieldState(field));
253
281
  }
@@ -13,6 +13,14 @@ export interface UseStoreOptions<T, S> {
13
13
  /** Compares two selected values; equal keeps the previous result. */
14
14
  equalityFn?: (a: S, b: S) => boolean;
15
15
  }
16
+ /**
17
+ * Options for {@link useStore} that pick part of the store: a selector is
18
+ * required, so the selected type `S` always comes from it.
19
+ */
20
+ export interface SelectingStoreOptions<T, S> extends UseStoreOptions<T, S> {
21
+ /** Picks the value the hook returns from the store's state. */
22
+ selector: (state: T) => S;
23
+ }
16
24
  /**
17
25
  * Subscribes a store with an optional selector and equality function, React's
18
26
  * `useStore` in Svelte's idiom: a readable store of the selected value.
@@ -46,7 +54,16 @@ export interface UseStoreOptions<T, S> {
46
54
  * <p>{$count} / {$doubled}</p>
47
55
  * ```
48
56
  */
49
- export declare function useStore<T, S = T>(store: MaybeReadable<Store<T>>, options?: MaybeReadable<UseStoreOptions<T, S> | undefined>): Readable<S>;
57
+ export declare function useStore<T>(store: MaybeReadable<Store<T>>, options?: MaybeReadable<UseStoreOptions<T, T> | undefined>): Readable<T>;
58
+ /**
59
+ * Subscribes to the part of a store a selector picks.
60
+ *
61
+ * @param store - The store to subscribe to (or a readable store of it).
62
+ * @param options - The selector, and an optional equality function for its
63
+ * results, or a store of them.
64
+ * @returns A readable store of the selected value.
65
+ */
66
+ export declare function useStore<T, S>(store: MaybeReadable<Store<T>>, options: MaybeReadable<SelectingStoreOptions<T, S>>): Readable<S>;
50
67
  /**
51
68
  * The store's setState function, React's `useSetStore` in Svelte's idiom.
52
69
  *
@@ -1 +1 @@
1
- {"version":3,"file":"useStore.d.ts","sourceRoot":"","sources":["../../src/hooks/useStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAO,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAGhD,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAEpE,oCAAoC;AACpC,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,CAAC;IACnC,iCAAiC;IACjC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAA;IAC1B,qEAAqE;IACrE,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAC/B,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC9B,OAAO,CAAC,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,GACzD,QAAQ,CAAC,CAAC,CAAC,CAiDb;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAEpE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,SAAS,OAAO,EAAE,EAAE,CAAC,EACzD,KAAK,EAAE,KAAK,CAAC,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,CAAC,CAAA;AACd;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAC9B,OAAO,EAAE,aAAa,CAAC,qBAAqB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAClD,QAAQ,CAAC,CAAC,CAAC,CAAA;AA+Dd;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAEpE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,SAAS,OAAO,EAAE,EAAE,CAAC,EACzD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EACf,MAAM,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,GAC/F,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,CAGtB"}
@@ -7,37 +7,12 @@ import { get } from 'svelte/store';
7
7
  import { useSyncExternalStore } from './external-store.js';
8
8
  import { toReadable } from './maybe-readable.js';
9
9
  /**
10
- * Subscribes a store with an optional selector and equality function, React's
11
- * `useStore` in Svelte's idiom: a readable store of the selected value.
12
- *
13
- * The store argument may be the store itself (a molecule store has `getState`
14
- * AND `subscribe`, and is always a VALUE, never a source) or a readable store
15
- * OF a store: setting it re-subscribes to the new store and re-reads its
16
- * snapshot on the same component, the way React's re-render does. The options
17
- * (or a store of them) are read whenever the snapshot is.
18
- *
19
- * The store is the argument, so this hook needs NO state provider: it reads
20
- * `store.getState()` and subscribes with `store.subscribe()`. When `equalityFn`
21
- * says a new selected value equals the previous one, the previous result is
22
- * kept (the same value, not a fresh object).
23
- *
24
- * The selector and equality function run with the same cadence as React's
25
- * `useSyncExternalStore` binding, because React re-reads its snapshot around
26
- * every render; {@link useSyncExternalStore} documents the cadence.
10
+ * The implementation both signatures share: without a selector the selected
11
+ * value is the state itself, which the first signature types as `T`.
27
12
  *
28
13
  * @param store - The store to subscribe to (or a readable store of it).
29
14
  * @param options - Hook options (selector, equalityFn), or a store of them.
30
- * @returns A readable store of the selected state.
31
- * @example
32
- * ```svelte
33
- * <script>
34
- * import { useStore } from '@molecule/app-svelte'
35
- * const count = useStore(counterStore, { selector: (s) => s.count })
36
- * const doubled = useStore(counterStore, { selector: (s) => s.count * 2 })
37
- * </script>
38
- *
39
- * <p>{$count} / {$doubled}</p>
40
- * ```
15
+ * @returns A readable store of the selected value.
41
16
  */
42
17
  export function useStore(store, options) {
43
18
  const storeStore = toReadable(store);
@@ -53,6 +28,7 @@ export function useStore(store, options) {
53
28
  const getSnapshot = () => {
54
29
  const { selector, equalityFn } = get(optionsStore) ?? {};
55
30
  const state = currentStore.getState();
31
+ // Without a selector the selection IS the store's state.
56
32
  const selected = selector ? selector(state) : state;
57
33
  // With an equality function and a previous value, an equal selection
58
34
  // keeps the previous result — the same value, not a fresh object.
@@ -68,8 +44,7 @@ export function useStore(store, options) {
68
44
  // A new store in the source re-subscribes and re-checks the snapshot, the
69
45
  // way React's useSyncExternalStore does when its subscribe function
70
46
  // changes. The store calls back at once with the store already read.
71
- stopSource = storeStore.subscribe((next) => {
72
- const incoming = next;
47
+ stopSource = storeStore.subscribe((incoming) => {
73
48
  if (Object.is(incoming, currentStore))
74
49
  return;
75
50
  currentStore = incoming;
@@ -1 +1 @@
1
- {"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/useTheme.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,KAAK,EAAE,KAAK,EAA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B,2CAA2C;IAC3C,IAAI,EAAE,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,CAAA;CACjC;AAyCD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,IAAI,cAAc,CA6CzC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,QAAQ,CAAC,KAAK,CAAC,CAGjD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,CAGzD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAG1D"}
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @module
5
5
  */
6
+ import { onMount } from 'svelte';
6
7
  import { derived } from 'svelte/store';
7
8
  import { useThemeProvider } from '../context.js';
8
9
  import { fieldStore, liveStore } from './live-store.js';
@@ -16,13 +17,34 @@ import { fieldStore, liveStore } from './live-store.js';
16
17
  */
17
18
  function subscribeToThemeProvider(provider, callback) {
18
19
  if (typeof provider.subscribe === 'function') {
20
+ // A listener that takes no argument satisfies one that receives the theme.
19
21
  return provider.subscribe(callback);
20
22
  }
21
- const legacy = provider;
22
- if (typeof legacy.onThemeChange === 'function') {
23
- return legacy.onThemeChange(callback);
23
+ // `onThemeChange` is not part of `ThemeProvider`; a provider that predates
24
+ // `subscribe` may still expose it. Read it as an unknown function rather
25
+ // than asserting the provider's shape.
26
+ const legacy = Reflect.get(provider, 'onThemeChange');
27
+ if (typeof legacy !== 'function')
28
+ return () => { };
29
+ const stop = legacy(callback);
30
+ return typeof stop === 'function' ? () => stop() : () => { };
31
+ }
32
+ /**
33
+ * The active theme's name. `getThemeName()` is not part of `ThemeProvider`;
34
+ * probe it the way React does, so a provider that predates the theme object's
35
+ * `name` still works.
36
+ *
37
+ * @param provider - The theme provider to read.
38
+ * @returns The active theme's name.
39
+ */
40
+ function readThemeName(provider) {
41
+ const named = Reflect.get(provider, 'getThemeName');
42
+ if (typeof named === 'function') {
43
+ const name = named();
44
+ if (typeof name === 'string')
45
+ return name;
24
46
  }
25
- return () => { };
47
+ return provider.getTheme().name;
26
48
  }
27
49
  /**
28
50
  * Theme state and actions, React's `useTheme` in Svelte's idiom: call it
@@ -41,13 +63,20 @@ function subscribeToThemeProvider(provider, callback) {
41
63
  */
42
64
  export function useTheme() {
43
65
  const provider = useThemeProvider();
44
- // `getThemeName()` is not part of `ThemeProvider`; probe it the way React
45
- // does, so a provider that predates the theme object's `name` still works.
46
- const providerWithName = provider;
47
- const readName = () => typeof providerWithName.getThemeName === 'function'
48
- ? providerWithName.getThemeName()
49
- : provider.getTheme().name;
50
- const state = liveStore(() => ({ theme: provider.getTheme(), name: readName() }), (notify) => subscribeToThemeProvider(provider, notify));
66
+ const readName = () => readThemeName(provider);
67
+ const readTheme = () => ({
68
+ theme: provider.getTheme(),
69
+ name: readName(),
70
+ });
71
+ // A static site prerenders on a server that reads no storage and no OS
72
+ // preference, then hydrates in a browser that reads both. The first value is
73
+ // the theme that markup was rendered with (`getServerTheme()` when the
74
+ // provider has one), so hydration matches; the mount below switches to the
75
+ // live theme, as React's binding does right after hydration. A server render
76
+ // never mounts, so it keeps the server theme.
77
+ const serverTheme = provider.getServerTheme?.();
78
+ const state = liveStore(readTheme, (notify) => subscribeToThemeProvider(provider, notify), serverTheme === undefined ? undefined : { theme: serverTheme, name: serverTheme.name });
79
+ onMount(() => state.refresh());
51
80
  const toggleTheme = () => {
52
81
  // Prefer the provider's purpose-built light/dark toggle — unlike
53
82
  // `getThemes()`, which is optional, so the index-cycle below silently
@@ -61,9 +90,9 @@ export function useTheme() {
61
90
  if (themes.length === 0)
62
91
  return;
63
92
  const currentName = readName();
64
- const currentIndex = themes.findIndex((entry) => typeof entry === 'string' ? entry === currentName : entry.name === currentName);
93
+ const currentIndex = themes.findIndex((entry) => entry.name === currentName);
65
94
  const next = themes[(currentIndex + 1) % themes.length];
66
- provider.setTheme(typeof next === 'string' ? next : next.name);
95
+ provider.setTheme(next.name);
67
96
  };
68
97
  return {
69
98
  theme: fieldStore(state, 'theme'),
package/dist/index.d.ts CHANGED
@@ -41,6 +41,85 @@
41
41
  * {/if}
42
42
  * ```
43
43
  *
44
+ * @example
45
+ * ```svelte
46
+ * <!-- Dashboard.svelte — the session, the theme and translations as stores -->
47
+ * <script lang="ts">
48
+ * import { useAuth, useTheme, useTranslation } from '@molecule/app-svelte'
49
+ *
50
+ * const { user, status, logout } = useAuth<{ name?: string }>()
51
+ * const { t } = useTranslation()
52
+ * const { theme, toggleTheme } = useTheme()
53
+ * </script>
54
+ *
55
+ * {#if $status === 'loading'}
56
+ * <p>{t('auth.restoring', undefined, { defaultValue: 'Restoring session...' })}</p>
57
+ * {:else if $status === 'unauthenticated'}
58
+ * <p>{t('auth.required', undefined, { defaultValue: 'Please log in.' })}</p>
59
+ * {:else}
60
+ * <div style:background={$theme.colors.background}>
61
+ * <h1>
62
+ * {t('greeting.welcome', { name: $user?.name ?? '' }, { defaultValue: 'Welcome, {{name}}!' })}
63
+ * </h1>
64
+ * <button onclick={toggleTheme}>
65
+ * {t('theme.toggle', undefined, { defaultValue: 'Toggle theme' })}
66
+ * </button>
67
+ * <button onclick={() => logout()}>
68
+ * {t('auth.logout', undefined, { defaultValue: 'Log out' })}
69
+ * </button>
70
+ * </div>
71
+ * {/if}
72
+ * ```
73
+ *
74
+ * @example
75
+ * ```svelte
76
+ * <!-- FavoriteButton.svelte — a server-backed favorite that changes at once -->
77
+ * <script lang="ts">
78
+ * import { useHttpClient, useOptimisticValue, useTranslation } from '@molecule/app-svelte'
79
+ *
80
+ * interface FavoriteRecord {
81
+ * slug: string
82
+ * favorited: boolean
83
+ * favoritesCount: number
84
+ * }
85
+ *
86
+ * let { article, onChanged }: {
87
+ * article: FavoriteRecord
88
+ * onChanged?: (saved: FavoriteRecord) => void
89
+ * } = $props()
90
+ *
91
+ * const http = useHttpClient()
92
+ * const { t } = useTranslation()
93
+ * const { value: favorite, update } = useOptimisticValue({
94
+ * value: { favorited: article.favorited, count: article.favoritesCount },
95
+ * commit: async (next) => {
96
+ * const path = `/articles/${article.slug}/favorite`
97
+ * const response = next.favorited
98
+ * ? await http.post<{ article: FavoriteRecord }>(path)
99
+ * : await http.delete<{ article: FavoriteRecord }>(path)
100
+ * const saved = response.data.article
101
+ * onChanged?.(saved)
102
+ * return { favorited: saved.favorited, count: saved.favoritesCount }
103
+ * },
104
+ * })
105
+ * </script>
106
+ *
107
+ * <button
108
+ * aria-pressed={$favorite.favorited}
109
+ * aria-label={t('article.favorite', undefined, { defaultValue: 'Favorite article' })}
110
+ * onclick={() => update((current) => ({
111
+ * favorited: !current.favorited,
112
+ * count: current.count + (current.favorited ? -1 : 1),
113
+ * }))}
114
+ * >{$favorite.count}</button>
115
+ * ```
116
+ *
117
+ * Session state is a three-way decision, not a boolean: `status === 'loading'`
118
+ * is undecided, so wait for it and redirect only on
119
+ * `status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
120
+ * for retry, so a restore that failed with anything other than a 401/403 never
121
+ * signs the user out.
122
+ *
44
123
  * @remarks
45
124
  * - **`setMoleculeContext` and every `create*Stores` factory use Svelte context — they are only
46
125
  * legal during component initialization** (the top level of a component `<script>`), never in
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyIG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -41,6 +41,85 @@
41
41
  * {/if}
42
42
  * ```
43
43
  *
44
+ * @example
45
+ * ```svelte
46
+ * <!-- Dashboard.svelte — the session, the theme and translations as stores -->
47
+ * <script lang="ts">
48
+ * import { useAuth, useTheme, useTranslation } from '@molecule/app-svelte'
49
+ *
50
+ * const { user, status, logout } = useAuth<{ name?: string }>()
51
+ * const { t } = useTranslation()
52
+ * const { theme, toggleTheme } = useTheme()
53
+ * </script>
54
+ *
55
+ * {#if $status === 'loading'}
56
+ * <p>{t('auth.restoring', undefined, { defaultValue: 'Restoring session...' })}</p>
57
+ * {:else if $status === 'unauthenticated'}
58
+ * <p>{t('auth.required', undefined, { defaultValue: 'Please log in.' })}</p>
59
+ * {:else}
60
+ * <div style:background={$theme.colors.background}>
61
+ * <h1>
62
+ * {t('greeting.welcome', { name: $user?.name ?? '' }, { defaultValue: 'Welcome, {{name}}!' })}
63
+ * </h1>
64
+ * <button onclick={toggleTheme}>
65
+ * {t('theme.toggle', undefined, { defaultValue: 'Toggle theme' })}
66
+ * </button>
67
+ * <button onclick={() => logout()}>
68
+ * {t('auth.logout', undefined, { defaultValue: 'Log out' })}
69
+ * </button>
70
+ * </div>
71
+ * {/if}
72
+ * ```
73
+ *
74
+ * @example
75
+ * ```svelte
76
+ * <!-- FavoriteButton.svelte — a server-backed favorite that changes at once -->
77
+ * <script lang="ts">
78
+ * import { useHttpClient, useOptimisticValue, useTranslation } from '@molecule/app-svelte'
79
+ *
80
+ * interface FavoriteRecord {
81
+ * slug: string
82
+ * favorited: boolean
83
+ * favoritesCount: number
84
+ * }
85
+ *
86
+ * let { article, onChanged }: {
87
+ * article: FavoriteRecord
88
+ * onChanged?: (saved: FavoriteRecord) => void
89
+ * } = $props()
90
+ *
91
+ * const http = useHttpClient()
92
+ * const { t } = useTranslation()
93
+ * const { value: favorite, update } = useOptimisticValue({
94
+ * value: { favorited: article.favorited, count: article.favoritesCount },
95
+ * commit: async (next) => {
96
+ * const path = `/articles/${article.slug}/favorite`
97
+ * const response = next.favorited
98
+ * ? await http.post<{ article: FavoriteRecord }>(path)
99
+ * : await http.delete<{ article: FavoriteRecord }>(path)
100
+ * const saved = response.data.article
101
+ * onChanged?.(saved)
102
+ * return { favorited: saved.favorited, count: saved.favoritesCount }
103
+ * },
104
+ * })
105
+ * </script>
106
+ *
107
+ * <button
108
+ * aria-pressed={$favorite.favorited}
109
+ * aria-label={t('article.favorite', undefined, { defaultValue: 'Favorite article' })}
110
+ * onclick={() => update((current) => ({
111
+ * favorited: !current.favorited,
112
+ * count: current.count + (current.favorited ? -1 : 1),
113
+ * }))}
114
+ * >{$favorite.count}</button>
115
+ * ```
116
+ *
117
+ * Session state is a three-way decision, not a boolean: `status === 'loading'`
118
+ * is undecided, so wait for it and redirect only on
119
+ * `status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
120
+ * for retry, so a restore that failed with anything other than a 401/403 never
121
+ * signs the user out.
122
+ *
44
123
  * @remarks
45
124
  * - **`setMoleculeContext` and every `create*Stores` factory use Svelte context — they are only
46
125
  * legal during component initialization** (the top level of a component `<script>`), never in
@@ -7,12 +7,20 @@
7
7
  and a URL on another origin are left to the browser.
8
8
  -->
9
9
  <script lang="ts">
10
- import { followRouterLink } from '@molecule/app-routing'
10
+ import { followRouterLink, routerLinkHref } from '@molecule/app-routing'
11
11
 
12
12
  import { useRouterInstance } from '../context.js'
13
13
  import type { LinkProps } from './types.js'
14
14
 
15
- let { to, replace, state, children, onclick, ...anchor }: LinkProps = $props()
15
+ let {
16
+ to,
17
+ replace,
18
+ state,
19
+ children,
20
+ onclick,
21
+ ref = $bindable(null),
22
+ ...anchor
23
+ }: LinkProps = $props()
16
24
 
17
25
  const router = useRouterInstance()
18
26
 
@@ -30,4 +38,6 @@
30
38
  }
31
39
  </script>
32
40
 
33
- <a {...anchor} href={to} onclick={handleClick}>{@render children?.()}</a>
41
+ <a {...anchor} bind:this={ref} href={routerLinkHref(to, router)} onclick={handleClick}
42
+ >{@render children?.()}</a
43
+ >
@@ -6,7 +6,7 @@ import type { LinkProps } from './types.js';
6
6
  * click, a `target` other than `_self`, a click an `onclick` already prevented,
7
7
  * and a URL on another origin are left to the browser.
8
8
  */
9
- declare const Link: import("svelte").Component<LinkProps, {}, "">;
9
+ declare const Link: import("svelte").Component<LinkProps, {}, "ref">;
10
10
  type Link = ReturnType<typeof Link>;
11
11
  export default Link;
12
12
  //# sourceMappingURL=Link.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Link.svelte.d.ts","sourceRoot":"","sources":["../../src/link/Link.svelte"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA+B5C;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,+CAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"Link.svelte.d.ts","sourceRoot":"","sources":["../../src/link/Link.svelte"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAuC5C;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,kDAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
@@ -10,7 +10,7 @@ import type { HTMLAnchorAttributes } from 'svelte/elements';
10
10
  * `aria-*`, `data-*`, `onclick`) goes on the anchor.
11
11
  */
12
12
  export interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children'> {
13
- /** Destination: an app path (`/settings?tab=billing#plan`) or a URL. Rendered as the anchor's `href`. */
13
+ /** Destination: an app path (`/settings?tab=billing#plan`) or a URL. An app path's `href` is the one the router writes for it (`routerLinkHref`), base path included. */
14
14
  to: string;
15
15
  /**
16
16
  * Replace the current history entry instead of pushing one. When omitted, a
@@ -22,5 +22,7 @@ export interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children
22
22
  state?: unknown;
23
23
  /** The link's content. */
24
24
  children?: Snippet;
25
+ /** The rendered anchor (`bind:ref`), as React's `ref` receives it. */
26
+ ref?: HTMLAnchorElement | null;
25
27
  }
26
28
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/link/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,UAAU,CAAC;IAChF,yGAAyG;IACzG,EAAE,EAAE,MAAM,CAAA;IACV;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/link/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,UAAU,CAAC;IAChF,yKAAyK;IACzK,EAAE,EAAE,MAAM,CAAA;IACV;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,sEAAsE;IACtE,GAAG,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAC/B"}
@@ -7,7 +7,7 @@ import { type PromiseStore } from './promise.js';
7
7
  /**
8
8
  * Change password store type.
9
9
  */
10
- export type ChangePasswordStore = PromiseStore<void>;
10
+ export type ChangePasswordStore = PromiseStore<void, [string, string]>;
11
11
  /**
12
12
  * Creates a change password store with async state tracking.
13
13
  *
@@ -1 +1 @@
1
- {"version":3,"file":"change-password.d.ts","sourceRoot":"","sources":["../../src/stores/change-password.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAEpE;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;AAEpD;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,mBAAmB,CAK/D"}
1
+ {"version":3,"file":"change-password.d.ts","sourceRoot":"","sources":["../../src/stores/change-password.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAEpE;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;AAEtE;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,mBAAmB,CAK/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"forms.d.ts","sourceRoot":"","sources":["../../src/stores/forms.ts"],"names":[],"mappings":"AAAA;;;;GAI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;IAC/D,oFAAoF;IACpF,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC3E,KAAK,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IACpC,QAAQ,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;IAChC,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAAA;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAChE,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,UAAU,CAAC,CAAC,CAAC,CAmGf;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EACnF,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,EAC7B,IAAI,EAAE,CAAC,GACN,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAI5B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EACnF,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,EAC7B,IAAI,EAAE,CAAC,GACN,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAIhB"}
@@ -73,17 +73,15 @@ export function createFormStores(provider, options) {
73
73
  return controller.getValue(name);
74
74
  };
75
75
  const setValue = (name, value, opts) => {
76
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
- controller.setValue(name, value, opts);
76
+ // Field names arrive as keys; the controller addresses them as strings.
77
+ controller.setValue(String(name), value, opts);
78
78
  };
79
79
  const getError = (name) => {
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- return controller.getError(name);
80
+ return controller.getError(String(name));
82
81
  };
83
82
  const setError = (name, error) => {
84
83
  if (error !== undefined) {
85
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
- controller.setError(name, error);
84
+ controller.setError(String(name), error);
87
85
  }
88
86
  else {
89
87
  controller.clearError(name);
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import type { AuthResult } from '@molecule/app-auth';
6
+ import type { AuthResult, LoginCredentials } from '@molecule/app-auth';
7
7
  import { type PromiseStore } from './promise.js';
8
8
  /**
9
9
  * Login store type.
10
10
  */
11
- export type LoginStore<T = unknown> = PromiseStore<AuthResult<T>>;
11
+ export type LoginStore<T = unknown> = PromiseStore<AuthResult<T>, [LoginCredentials]>;
12
12
  /**
13
13
  * Creates a login store with async state tracking.
14
14
  *
@@ -1 +1 @@
1
- {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/stores/login.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAoB,MAAM,oBAAoB,CAAA;AAGtE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAEpE;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAEjE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,CAG7D"}
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/stores/login.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAGtE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAEpE;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,GAAG,OAAO,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAA;AAErF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,GAAG,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,CAG7D"}
@@ -7,9 +7,12 @@ import { type Readable } from 'svelte/store';
7
7
  import type { PromiseState } from '@molecule/app-utilities';
8
8
  /**
9
9
  * Promise store with action methods.
10
+ *
11
+ * @template T - The value the tracked function resolves with.
12
+ * @template A - The tracked function's argument list.
10
13
  */
11
- export interface PromiseStore<T> extends Readable<PromiseState<T>> {
12
- call: (...args: any[]) => Promise<T>;
14
+ export interface PromiseStore<T, A extends unknown[] = unknown[]> extends Readable<PromiseState<T>> {
15
+ call: (...args: A) => Promise<T>;
13
16
  cancel: (message?: string) => void;
14
17
  reset: () => void;
15
18
  }
@@ -37,5 +40,5 @@ export interface PromiseStore<T> extends Readable<PromiseState<T>> {
37
40
  * {/if}
38
41
  * ```
39
42
  */
40
- export declare const createPromiseStore: <T extends (...args: any[]) => Promise<any>>(asyncFn: T) => PromiseStore<Awaited<ReturnType<T>>>;
43
+ export declare const createPromiseStore: <T, A extends unknown[]>(asyncFn: (...args: A) => Promise<T>) => PromiseStore<T, A>;
41
44
  //# sourceMappingURL=promise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"promise.d.ts","sourceRoot":"","sources":["../../src/stores/promise.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEtD,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,yBAAyB,CAAA;AAE1E;;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CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,KAClC,YAAY,CAAC,CAAC,EAAE,CAAC,CA0DnB,CAAA"}
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- /* eslint-disable @typescript-eslint/no-explicit-any */
7
6
  import { writable } from 'svelte/store';
8
7
  /**
9
8
  * Creates a store that tracks async function state.
@@ -3,12 +3,12 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import type { AuthResult } from '@molecule/app-auth';
6
+ import type { AuthResult, RegisterData } from '@molecule/app-auth';
7
7
  import { type PromiseStore } from './promise.js';
8
8
  /**
9
9
  * Signup store type.
10
10
  */
11
- export type SignupStore<T = unknown> = PromiseStore<AuthResult<T>>;
11
+ export type SignupStore<T = unknown> = PromiseStore<AuthResult<T>, [RegisterData]>;
12
12
  /**
13
13
  * Creates a signup store with async state tracking.
14
14
  *
@@ -1 +1 @@
1
- {"version":3,"file":"signup.d.ts","sourceRoot":"","sources":["../../src/stores/signup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,oBAAoB,CAAA;AAGlE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAEpE;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAElE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,CAG/D"}
1
+ {"version":3,"file":"signup.d.ts","sourceRoot":"","sources":["../../src/stores/signup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGlE,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,cAAc,CAAA;AAEpE;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;AAElF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,GAAG,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,CAG/D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-svelte",
3
- "version": "3.7.2",
3
+ "version": "3.8.0",
4
4
  "description": "Svelte framework bindings for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -46,7 +46,7 @@
46
46
  "@molecule/app-logger": "^1.0.1",
47
47
  "@molecule/app-platform": "^1.0.1",
48
48
  "@molecule/app-push": "^1.0.1",
49
- "@molecule/app-routing": "^1.3.0",
49
+ "@molecule/app-routing": "^1.4.0",
50
50
  "@molecule/app-state": "^1.2.0",
51
51
  "@molecule/app-storage": "^1.1.1",
52
52
  "@molecule/app-theme": "^1.0.1",