@molecule/app-svelte 3.5.1 → 3.7.1

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.
Files changed (62) hide show
  1. package/README.md +287 -76
  2. package/dist/hooks/index.d.ts +2 -0
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.js +2 -0
  5. package/dist/hooks/live-store.d.ts +0 -8
  6. package/dist/hooks/live-store.d.ts.map +1 -1
  7. package/dist/hooks/live-store.js +0 -13
  8. package/dist/hooks/maybe-readable.d.ts +36 -0
  9. package/dist/hooks/maybe-readable.d.ts.map +1 -0
  10. package/dist/hooks/maybe-readable.js +36 -0
  11. package/dist/hooks/useAIModels.d.ts +8 -2
  12. package/dist/hooks/useAIModels.d.ts.map +1 -1
  13. package/dist/hooks/useAIModels.js +44 -17
  14. package/dist/hooks/useAuth.d.ts +10 -4
  15. package/dist/hooks/useAuth.d.ts.map +1 -1
  16. package/dist/hooks/useAuth.js +39 -13
  17. package/dist/hooks/useForm.d.ts +13 -5
  18. package/dist/hooks/useForm.d.ts.map +1 -1
  19. package/dist/hooks/useForm.js +90 -58
  20. package/dist/hooks/useHttp.d.ts +28 -22
  21. package/dist/hooks/useHttp.d.ts.map +1 -1
  22. package/dist/hooks/useHttp.js +67 -96
  23. package/dist/hooks/useOAuth.d.ts +23 -7
  24. package/dist/hooks/useOAuth.d.ts.map +1 -1
  25. package/dist/hooks/useOAuth.js +51 -18
  26. package/dist/hooks/useOptimisticToggle.d.ts +67 -0
  27. package/dist/hooks/useOptimisticToggle.d.ts.map +1 -0
  28. package/dist/hooks/useOptimisticToggle.js +52 -0
  29. package/dist/hooks/useOptimisticValue.d.ts +11 -4
  30. package/dist/hooks/useOptimisticValue.d.ts.map +1 -1
  31. package/dist/hooks/useOptimisticValue.js +40 -49
  32. package/dist/hooks/usePush.d.ts +7 -3
  33. package/dist/hooks/usePush.d.ts.map +1 -1
  34. package/dist/hooks/usePush.js +26 -6
  35. package/dist/hooks/useRouter.d.ts +13 -7
  36. package/dist/hooks/useRouter.d.ts.map +1 -1
  37. package/dist/hooks/useRouter.js +39 -18
  38. package/dist/hooks/useStorage.d.ts +22 -9
  39. package/dist/hooks/useStorage.d.ts.map +1 -1
  40. package/dist/hooks/useStorage.js +146 -69
  41. package/dist/hooks/useStore.d.ts +14 -7
  42. package/dist/hooks/useStore.d.ts.map +1 -1
  43. package/dist/hooks/useStore.js +46 -9
  44. package/dist/hooks/useTranslation.d.ts +6 -2
  45. package/dist/hooks/useTranslation.d.ts.map +1 -1
  46. package/dist/hooks/useTranslation.js +11 -6
  47. package/dist/index.d.ts +4 -0
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +4 -0
  50. package/dist/link/Link.svelte +33 -0
  51. package/dist/link/Link.svelte.d.ts +12 -0
  52. package/dist/link/Link.svelte.d.ts.map +1 -0
  53. package/dist/link/index.d.ts +23 -0
  54. package/dist/link/index.d.ts.map +1 -0
  55. package/dist/link/index.js +22 -0
  56. package/dist/link/types.d.ts +26 -0
  57. package/dist/link/types.d.ts.map +1 -0
  58. package/dist/link/types.js +6 -0
  59. package/dist/stores/chat.d.ts +4 -3
  60. package/dist/stores/chat.d.ts.map +1 -1
  61. package/dist/stores/chat.js +14 -15
  62. package/package.json +5 -5
@@ -28,8 +28,11 @@
28
28
  * @module
29
29
  */
30
30
  import { onDestroy } from 'svelte';
31
+ import { createSubscriber } from 'svelte/reactivity';
32
+ import { get } from 'svelte/store';
31
33
  import { t } from '@molecule/app-i18n';
32
34
  import { useAuthClient } from '../context.js';
35
+ import { toReadable } from './maybe-readable.js';
33
36
  /** What `onError` gets when the server gives no reason of its own. */
34
37
  const oauthFailed = () => t('svelte.error.oauthFailed', undefined, { defaultValue: 'OAuth login failed' });
35
38
  /**
@@ -51,32 +54,55 @@ const OAUTH_POPUP_TIMEOUT_MS = 5 * 60 * 1000;
51
54
  * when the callback is running inside a popup we opened, relaying the result
52
55
  * to the opener instead.
53
56
  *
54
- * @param config - Optional OAuth configuration override.
57
+ * The config may be a plain value or a readable store of one (a store holding
58
+ * `undefined` means no config): every field — the provider list, the URL
59
+ * pieces, the callbacks, the `navigate` option — is read at the moment it is
60
+ * used, so setting the store retargets the next `getOAuthUrl`/`redirect`/popup
61
+ * flow on the same component, the way React's re-render does. `providers` is
62
+ * React's `string[]`, read live (see {@link UseOAuthReturn.providers}). The
63
+ * callback exchange, when it finds a `code` in the URL, runs once with the
64
+ * config the hook was called with.
65
+ *
66
+ * @param config - Optional OAuth configuration override (or a store of it).
55
67
  * @returns OAuth helpers: providers, getOAuthUrl, redirect, and loginViaPopup.
56
68
  * @example
57
69
  * ```svelte
58
70
  * <script>
59
71
  * import { useOAuth } from '@molecule/app-svelte'
60
- * const { providers, loginViaPopup } = useOAuth()
72
+ * const oauth = useOAuth()
61
73
  * </script>
62
74
  *
63
- * {#each providers as provider}
64
- * <button onclick={() => loginViaPopup(provider)}>Login with {provider}</button>
75
+ * {#each oauth.providers as provider}
76
+ * <button onclick={() => oauth.loginViaPopup(provider)}>Login with {provider}</button>
65
77
  * {/each}
66
78
  * ```
67
79
  */
68
80
  export function useOAuth(config) {
69
81
  const authClient = useAuthClient();
82
+ const configStore = toReadable(config);
83
+ const current = () => get(configStore);
70
84
  // Whether the component is mounted, read when a flow settles.
71
85
  let mounted = true;
72
86
  onDestroy(() => {
73
87
  mounted = false;
74
88
  });
75
- const providers = config?.oauthProviders ?? [];
76
- const baseURL = config?.baseURL ?? '';
77
- const oauthEndpoint = config?.oauthEndpoint ?? '/oauth';
78
- const loginEndpoint = config?.loginEndpoint ?? '/users/log-in/oauth';
89
+ // `providers` is read live, like React's re-rendered array: a read inside markup or an
90
+ // effect subscribes the config store (a plain config's constant store never notifies),
91
+ // so a changed config re-runs it. The store's synchronous first call is the value the
92
+ // read already returns, not a change.
93
+ const trackConfig = createSubscriber((update) => {
94
+ let started = false;
95
+ const unsubscribe = configStore.subscribe(() => {
96
+ if (started)
97
+ update();
98
+ });
99
+ started = true;
100
+ return unsubscribe;
101
+ });
79
102
  const getOAuthUrl = (provider) => {
103
+ const now = current();
104
+ const baseURL = now?.baseURL ?? '';
105
+ const oauthEndpoint = now?.oauthEndpoint ?? '/oauth';
80
106
  // Encode the provider as a single path segment so a (future) caller passing an
81
107
  // untrusted value can never inject a path/query/scheme into the opened URL —
82
108
  // defense-in-depth on top of the upstream static provider allowlist. Plain
@@ -125,9 +151,9 @@ export function useOAuth(config) {
125
151
  }
126
152
  return false;
127
153
  };
128
- const navigateOption = config?.navigate;
129
154
  /** Leaves the page for the provider: the `navigate` option, else a full-page navigation. */
130
155
  const leaveFor = (url) => {
156
+ const navigateOption = current()?.navigate;
131
157
  if (navigateOption)
132
158
  navigateOption(url);
133
159
  else
@@ -203,13 +229,13 @@ export function useOAuth(config) {
203
229
  if (!mounted)
204
230
  return;
205
231
  if (ok)
206
- config?.onSuccess?.();
232
+ current()?.onSuccess?.();
207
233
  else
208
- config?.onError?.(oauthFailed());
234
+ current()?.onError?.(oauthFailed());
209
235
  });
210
236
  }
211
237
  else if (mounted) {
212
- config?.onError?.(typeof data.error === 'string' ? data.error : oauthFailed());
238
+ current()?.onError?.(typeof data.error === 'string' ? data.error : oauthFailed());
213
239
  }
214
240
  };
215
241
  window.addEventListener('message', onMessage);
@@ -285,7 +311,11 @@ export function useOAuth(config) {
285
311
  /* best-effort */
286
312
  }
287
313
  };
288
- // Exchange code for session
314
+ // Exchange code for session, with the config the hook was called with
315
+ // (React's mount effect reads its config once).
316
+ const configNow = current();
317
+ const baseURL = configNow?.baseURL ?? '';
318
+ const loginEndpoint = configNow?.loginEndpoint ?? '/users/log-in/oauth';
289
319
  const exchangeCode = async () => {
290
320
  try {
291
321
  const response = await fetch(`${baseURL}${loginEndpoint}`, {
@@ -310,7 +340,7 @@ export function useOAuth(config) {
310
340
  return;
311
341
  }
312
342
  if (mounted)
313
- config?.onError?.(error);
343
+ configNow?.onError?.(error);
314
344
  return;
315
345
  }
316
346
  // A body that is not JSON carries no user; the token comes from the header.
@@ -336,9 +366,9 @@ export function useOAuth(config) {
336
366
  if (!mounted)
337
367
  return;
338
368
  if (ok)
339
- config?.onSuccess?.();
369
+ configNow?.onSuccess?.();
340
370
  else
341
- config?.onError?.(oauthFailed());
371
+ configNow?.onError?.(oauthFailed());
342
372
  }
343
373
  catch (err) {
344
374
  const error = err instanceof Error ? err.message : oauthFailed();
@@ -347,7 +377,7 @@ export function useOAuth(config) {
347
377
  return;
348
378
  }
349
379
  if (mounted)
350
- config?.onError?.(error);
380
+ configNow?.onError?.(error);
351
381
  }
352
382
  };
353
383
  void exchangeCode();
@@ -355,7 +385,10 @@ export function useOAuth(config) {
355
385
  }
356
386
  }
357
387
  return {
358
- providers,
388
+ get providers() {
389
+ trackConfig();
390
+ return current()?.oauthProviders ?? [];
391
+ },
359
392
  getOAuthUrl,
360
393
  redirect,
361
394
  loginViaPopup,
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Svelte hook for a server-backed boolean toggle rendered with the app's own markup,
3
+ * porting React's `useOptimisticToggle`.
4
+ *
5
+ * @module
6
+ */
7
+ import { type Readable } from 'svelte/store';
8
+ import { type MaybeReadable } from './maybe-readable.js';
9
+ /** Options for {@link useOptimisticToggle}. */
10
+ export interface UseOptimisticToggleOptions {
11
+ /** The loaded server value. Mount the control only after its record exists. */
12
+ value: boolean;
13
+ /** Saves the DESIRED value and returns the server-confirmed value; reject on failure. */
14
+ commit: (desired: boolean) => Promise<boolean>;
15
+ /** Receives the newest failed save and the confirmed value restored by the controller. */
16
+ onError?: (error: unknown, value: boolean) => void;
17
+ }
18
+ /**
19
+ * What {@link useOptimisticToggle} returns: the boolean to render as readable stores and
20
+ * an argument-free action (the same names React returns).
21
+ */
22
+ export interface UseOptimisticToggleResult {
23
+ /** The value to render. */
24
+ value: Readable<boolean>;
25
+ /** Whether a save is running or waiting. */
26
+ pending: Readable<boolean>;
27
+ /** The failure of the newest change. */
28
+ error: Readable<unknown>;
29
+ /** Flips the value shown now and saves it; the same function for the component's life. */
30
+ toggle: () => void;
31
+ }
32
+ /**
33
+ * Owns the state and save ordering of a follow, favorite, star or subscription control
34
+ * while all markup stays in the app. Pass `toggle` straight to the click handler: it takes
35
+ * no argument and flips the value shown now. `commit(desired)` receives the value to SAVE,
36
+ * never the old one, and returns the server's boolean answer. Only the newest failure
37
+ * rolls the shown value back.
38
+ *
39
+ * Saves run one at a time; clicks during a save coalesce to the newest desired value. Use
40
+ * `pending` for feedback, not to disable the control or drop a click. Mount it only after
41
+ * the record loads, key it by record identity, and keep it mounted through refetches. For
42
+ * a flag with a related count, use `useOptimisticValue` with both fields in one value.
43
+ *
44
+ * @param options - The server value, the save and an optional error callback (or a
45
+ * readable store of them: a new `value` syncs in while nothing is saving).
46
+ * @returns The value, pending and error state as readable stores, and the stable `toggle`.
47
+ * @example
48
+ * ```svelte
49
+ * <script lang="ts">
50
+ * const subscription = useOptimisticToggle({
51
+ * value: thread.subscribed,
52
+ * commit: async (desired) => {
53
+ * const path = `/threads/${encodeURIComponent(thread.id)}/subscription`
54
+ * const response = desired
55
+ * ? await http.put<{ subscribed: boolean }>(path)
56
+ * : await http.delete<{ subscribed: boolean }>(path)
57
+ * return response.data.subscribed
58
+ * },
59
+ * })
60
+ * const { value, pending } = subscription
61
+ * </script>
62
+ *
63
+ * <button type="button" aria-pressed={$value} aria-busy={$pending} onclick={subscription.toggle}>
64
+ * ```
65
+ */
66
+ export declare const useOptimisticToggle: (options: MaybeReadable<UseOptimisticToggleOptions>) => UseOptimisticToggleResult;
67
+ //# sourceMappingURL=useOptimisticToggle.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Svelte hook for a server-backed boolean toggle rendered with the app's own markup,
3
+ * porting React's `useOptimisticToggle`.
4
+ *
5
+ * @module
6
+ */
7
+ import { derived } from 'svelte/store';
8
+ import { toReadable } from './maybe-readable.js';
9
+ import { useOptimisticValue } from './useOptimisticValue.js';
10
+ /**
11
+ * Owns the state and save ordering of a follow, favorite, star or subscription control
12
+ * while all markup stays in the app. Pass `toggle` straight to the click handler: it takes
13
+ * no argument and flips the value shown now. `commit(desired)` receives the value to SAVE,
14
+ * never the old one, and returns the server's boolean answer. Only the newest failure
15
+ * rolls the shown value back.
16
+ *
17
+ * Saves run one at a time; clicks during a save coalesce to the newest desired value. Use
18
+ * `pending` for feedback, not to disable the control or drop a click. Mount it only after
19
+ * the record loads, key it by record identity, and keep it mounted through refetches. For
20
+ * a flag with a related count, use `useOptimisticValue` with both fields in one value.
21
+ *
22
+ * @param options - The server value, the save and an optional error callback (or a
23
+ * readable store of them: a new `value` syncs in while nothing is saving).
24
+ * @returns The value, pending and error state as readable stores, and the stable `toggle`.
25
+ * @example
26
+ * ```svelte
27
+ * <script lang="ts">
28
+ * const subscription = useOptimisticToggle({
29
+ * value: thread.subscribed,
30
+ * commit: async (desired) => {
31
+ * const path = `/threads/${encodeURIComponent(thread.id)}/subscription`
32
+ * const response = desired
33
+ * ? await http.put<{ subscribed: boolean }>(path)
34
+ * : await http.delete<{ subscribed: boolean }>(path)
35
+ * return response.data.subscribed
36
+ * },
37
+ * })
38
+ * const { value, pending } = subscription
39
+ * </script>
40
+ *
41
+ * <button type="button" aria-pressed={$value} aria-busy={$pending} onclick={subscription.toggle}>
42
+ * ```
43
+ */
44
+ export const useOptimisticToggle = (options) => {
45
+ // `commit` gets only the desired boolean, never the previous value or a confirm callback.
46
+ const { value, pending, error, update } = useOptimisticValue(derived(toReadable(options), (current) => ({
47
+ ...current,
48
+ commit: (desired) => current.commit(desired),
49
+ })));
50
+ const toggle = () => update((current) => !current);
51
+ return { value, pending, error, toggle };
52
+ };
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { type Readable } from 'svelte/store';
8
8
  import type { OptimisticValueOptions } from '@molecule/app-state';
9
+ import { type MaybeReadable } from './maybe-readable.js';
9
10
  /**
10
11
  * What {@link useOptimisticValue} returns: the state to render as readable
11
12
  * stores and the two ways to change it (the same names React returns).
@@ -38,21 +39,27 @@ export interface UseOptimisticValueResult<T> {
38
39
  * a favorite flag and its count, in the SAME value. Let commit reject on
39
40
  * failure: a catch that returns old data hides the failure.
40
41
  *
41
- * @param options - The server's current value and how to save a change.
42
+ * The options may be a plain value or a readable store of one: setting the
43
+ * store applies the new server value (and the new `commit`, `equals` and
44
+ * `onError`) on the same component, the way React's re-render does — the
45
+ * controller, and any save it is running, survive the change.
46
+ *
47
+ * @param options - The server's current value and how to save a change (or a store of them).
42
48
  * @returns The value to render, whether a save is pending, the newest failure,
43
49
  * and `set`/`update`.
44
50
  * @example
45
51
  * ```svelte
46
52
  * <script>
47
53
  * import { useOptimisticValue } from '@molecule/app-svelte'
48
- * const star = useOptimisticValue({
54
+ * // `value` is the store; the result itself is not, so take the store out to read it with `$`.
55
+ * const { value: star, update } = useOptimisticValue({
49
56
  * value: { starred: repository.starred, stars: repository.stars },
50
57
  * commit: async (next) => { /* save and return the server's value * },
51
58
  * })
52
59
  * </script>
53
60
  *
54
- * <button aria-pressed={$star.value.starred} onclick={() => star.update((on) => ({ ...on, starred: !on.starred }))}>
61
+ * <button aria-pressed={$star.starred} onclick={() => update((on) => ({ ...on, starred: !on.starred }))}>
55
62
  * ```
56
63
  */
57
- export declare const useOptimisticValue: <T>(options: OptimisticValueOptions<T>) => UseOptimisticValueResult<T>;
64
+ export declare const useOptimisticValue: <T>(options: MaybeReadable<OptimisticValueOptions<T>>) => UseOptimisticValueResult<T>;
58
65
  //# sourceMappingURL=useOptimisticValue.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useOptimisticValue.d.ts","sourceRoot":"","sources":["../../src/hooks/useOptimisticValue.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEtD,OAAO,KAAK,EAEV,sBAAsB,EAEvB,MAAM,qBAAqB,CAAA;AAuB5B;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,2BAA2B;IAC3B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClB,4CAA4C;IAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,wCAAwC;IACxC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,yEAAyE;IACzE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IACtB,6EAA6E;IAC7E,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAA;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,SAAS,sBAAsB,CAAC,CAAC,CAAC,KACjC,wBAAwB,CAAC,CAAC,CA2D5B,CAAA"}
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;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB,CAAC,CAAC;IACzC,2BAA2B;IAC3B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAClB,4CAA4C;IAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,wCAAwC;IACxC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,yEAAyE;IACzE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IACtB,6EAA6E;IAC7E,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,KAAK,IAAI,CAAA;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,SAAS,aAAa,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,KAChD,wBAAwB,CAAC,CAAC,CA6C5B,CAAA"}
@@ -5,11 +5,10 @@
5
5
  * @module
6
6
  */
7
7
  import { onDestroy } from 'svelte';
8
- import { writable } from 'svelte/store';
8
+ import { get, writable } from 'svelte/store';
9
9
  import { createOptimisticValue, shallowEqual } from '@molecule/app-state';
10
10
  import { fieldStore } from './live-store.js';
11
- /** The previous host's handoff, alive until its disarm timer runs. */
12
- let optimisticHandoff = null;
11
+ import { toReadable } from './maybe-readable.js';
13
12
  /**
14
13
  * A server-backed value — a favorite, follow, like or bookmark button, a
15
14
  * rating, a quantity, a setting switch — that changes on the first render
@@ -24,70 +23,62 @@ let optimisticHandoff = null;
24
23
  * a favorite flag and its count, in the SAME value. Let commit reject on
25
24
  * failure: a catch that returns old data hides the failure.
26
25
  *
27
- * @param options - The server's current value and how to save a change.
26
+ * The options may be a plain value or a readable store of one: setting the
27
+ * store applies the new server value (and the new `commit`, `equals` and
28
+ * `onError`) on the same component, the way React's re-render does — the
29
+ * controller, and any save it is running, survive the change.
30
+ *
31
+ * @param options - The server's current value and how to save a change (or a store of them).
28
32
  * @returns The value to render, whether a save is pending, the newest failure,
29
33
  * and `set`/`update`.
30
34
  * @example
31
35
  * ```svelte
32
36
  * <script>
33
37
  * import { useOptimisticValue } from '@molecule/app-svelte'
34
- * const star = useOptimisticValue({
38
+ * // `value` is the store; the result itself is not, so take the store out to read it with `$`.
39
+ * const { value: star, update } = useOptimisticValue({
35
40
  * value: { starred: repository.starred, stars: repository.stars },
36
41
  * commit: async (next) => { /* save and return the server's value * },
37
42
  * })
38
43
  * </script>
39
44
  *
40
- * <button aria-pressed={$star.value.starred} onclick={() => star.update((on) => ({ ...on, starred: !on.starred }))}>
45
+ * <button aria-pressed={$star.starred} onclick={() => update((on) => ({ ...on, starred: !on.starred }))}>
41
46
  * ```
42
47
  */
43
48
  export const useOptimisticValue = (options) => {
44
- // Actions read the latest options, so an adopting mount re-arms them (React
45
- // publishes them from committed renders).
46
- const latest = options;
47
- // A mount in the same turn as the previous host's destroy is React's
48
- // re-render (an args step), not a new component: adopt its controller so the
49
- // pending save continues and the value does not flip.
50
- const adopted = optimisticHandoff;
51
- optimisticHandoff = null;
52
- if (adopted)
53
- adopted.adopted = true;
54
- const controller = (adopted?.controller ??
55
- createOptimisticValue({
56
- value: options.value,
57
- commit: (next, previous, confirm) => latest.commit(next, previous, confirm),
58
- equals: (a, b) => (latest.equals ?? shallowEqual)(a, b),
59
- onError: (error, value) => latest.onError?.(error, value),
60
- }));
61
- // The handoff carries the value type-erased (it outlives one generic
62
- // instantiation); the adopting mount is the same component, so its `T` is
63
- // the one the controller was created with.
64
- const received = {
65
- current: adopted ? adopted.received : options.value,
66
- };
49
+ const optionsStore = toReadable(options);
50
+ // Actions read the latest options (React publishes them from committed
51
+ // renders), so a changed source re-arms them at once.
52
+ const current = () => get(optionsStore);
53
+ const initial = current();
54
+ const controller = createOptimisticValue({
55
+ value: initial.value,
56
+ commit: (next, previous, confirm) => current().commit(next, previous, confirm),
57
+ equals: (a, b) => (current().equals ?? shallowEqual)(a, b),
58
+ onError: (error, value) => current().onError?.(error, value),
59
+ });
60
+ // The last server value the hook received (React's `received` ref); it
61
+ // survives an argument change, so only a genuinely different value syncs.
62
+ const received = { current: initial.value };
67
63
  const state = writable(controller.getState());
68
64
  const unsubscribe = controller.subscribe((next) => state.set(next));
69
- onDestroy(() => {
70
- unsubscribe();
71
- const offer = {
72
- adopted: false,
73
- controller: controller,
74
- received: received.current,
75
- };
76
- optimisticHandoff = offer;
77
- // An unadopted handoff was a real unmount; the timer drops it so the next
78
- // mount starts clean. A mount in the same turn adopts first.
79
- setTimeout(() => {
80
- if (optimisticHandoff === offer && !offer.adopted)
81
- optimisticHandoff = null;
82
- }, 0);
83
- });
65
+ onDestroy(unsubscribe);
84
66
  // A new server value is taken when it differs from the one last received
85
67
  // and nothing is being saved (the controller's `sync` decides that) —
86
- // React's value effect, which also runs only for a changed value.
87
- if (!(latest.equals ?? shallowEqual)(received.current, options.value)) {
88
- received.current = options.value;
89
- controller.sync(options.value);
90
- }
68
+ // React's value effect, which also runs only for a changed value. The
69
+ // store's immediate callback IS the mount check (with the options the
70
+ // controller was created from, it changes nothing).
71
+ const syncIfChanged = (optionsNow) => {
72
+ const { value, equals } = optionsNow;
73
+ if ((equals ?? shallowEqual)(received.current, value))
74
+ return;
75
+ received.current = value;
76
+ controller.sync(value);
77
+ };
78
+ const stopOptions = optionsStore.subscribe((next) => {
79
+ syncIfChanged(next);
80
+ });
81
+ onDestroy(stopOptions);
91
82
  return {
92
83
  value: fieldStore(state, 'value'),
93
84
  pending: fieldStore(state, 'pending'),
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { type Readable } from 'svelte/store';
7
7
  import type { NotificationActionListener, NotificationReceivedListener, PermissionStatus, PushRegisterOptions, PushToken, TokenChangeListener } from '@molecule/app-push';
8
+ import { type MaybeReadable } from './maybe-readable.js';
8
9
  /**
9
10
  * Hook return type.
10
11
  */
@@ -37,7 +38,8 @@ export interface UsePushResult {
37
38
  */
38
39
  export interface UsePushOptions {
39
40
  /**
40
- * Whether to check permission status on mount.
41
+ * Whether to check permission status on mount, and again when the flag turns
42
+ * on later on the same component.
41
43
  */
42
44
  checkOnMount?: boolean;
43
45
  }
@@ -50,7 +52,9 @@ export interface UsePushOptions {
50
52
  * context-provided. The provider's listeners are caller-managed: the returned
51
53
  * `on*` unsubscribes are the caller's to call, like React's.
52
54
  *
53
- * @param options - Hook options
55
+ * @param options - Hook options (or a store of them): setting `checkOnMount`
56
+ * later runs its check on the same component, the way React's re-render
57
+ * re-runs its effect.
54
58
  * @returns Push notification state and action methods
55
59
  * @example
56
60
  * ```svelte
@@ -64,5 +68,5 @@ export interface UsePushOptions {
64
68
  * {/if}
65
69
  * ```
66
70
  */
67
- export declare function usePush(options?: UsePushOptions): UsePushResult;
71
+ export declare function usePush(options?: MaybeReadable<UsePushOptions | undefined>): UsePushResult;
68
72
  //# sourceMappingURL=usePush.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePush.d.ts","sourceRoot":"","sources":["../../src/hooks/usePush.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,QAA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EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1C,wBAAwB;IACxB,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,OAAO,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,cAAc,GAAG,SAAS,CAAC,GAAG,aAAa,CAkE1F"}
@@ -3,9 +3,11 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { writable } from 'svelte/store';
6
+ import { onDestroy } from 'svelte';
7
+ import { get, writable } from 'svelte/store';
7
8
  import { getLogger } from '@molecule/app-logger';
8
9
  import { getProvider } from '@molecule/app-push';
10
+ import { toReadable } from './maybe-readable.js';
9
11
  /**
10
12
  * Push notification state and actions, React's `usePush` in Svelte's idiom:
11
13
  * called during component init, `permission` and `token` are readable stores
@@ -15,7 +17,9 @@ import { getProvider } from '@molecule/app-push';
15
17
  * context-provided. The provider's listeners are caller-managed: the returned
16
18
  * `on*` unsubscribes are the caller's to call, like React's.
17
19
  *
18
- * @param options - Hook options
20
+ * @param options - Hook options (or a store of them): setting `checkOnMount`
21
+ * later runs its check on the same component, the way React's re-render
22
+ * re-runs its effect.
19
23
  * @returns Push notification state and action methods
20
24
  * @example
21
25
  * ```svelte
@@ -30,20 +34,36 @@ import { getProvider } from '@molecule/app-push';
30
34
  * ```
31
35
  */
32
36
  export function usePush(options) {
33
- const { checkOnMount = false } = options ?? {};
37
+ const optionsStore = toReadable(options);
34
38
  const provider = getProvider();
35
39
  const permission = writable(null);
36
40
  const token = writable(null);
37
- // React's mount effect: a failed mount check leaves the permission unknown
38
- // until checkPermission() runs again; the failure goes to the logger.
39
- if (checkOnMount) {
41
+ // React's mount effect ([checkOnMount]): a failed check leaves the
42
+ // permission unknown until checkPermission() runs again; the failure goes to
43
+ // the logger. Turning the flag on later checks once more; turning it off
44
+ // does nothing, exactly as the effect body's truthiness test.
45
+ const runCheck = () => {
40
46
  provider
41
47
  .checkPermission()
42
48
  .then((status) => permission.set(status))
43
49
  .catch((error) => {
50
+ // The permission stays unknown until checkPermission() is called again.
44
51
  getLogger('usePush').warn('Checking push permission on mount failed', { error });
45
52
  });
53
+ };
54
+ let lastCheckOnMount = get(optionsStore)?.checkOnMount ?? false;
55
+ if (lastCheckOnMount) {
56
+ runCheck();
46
57
  }
58
+ const stopOptions = optionsStore.subscribe(() => {
59
+ const next = get(optionsStore)?.checkOnMount ?? false;
60
+ if (Object.is(next, lastCheckOnMount))
61
+ return;
62
+ lastCheckOnMount = next;
63
+ if (next)
64
+ runCheck();
65
+ });
66
+ onDestroy(stopOptions);
47
67
  return {
48
68
  permission: { subscribe: permission.subscribe },
49
69
  token: { subscribe: token.subscribe },
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { type Readable } from 'svelte/store';
7
7
  import type { ListRouteOptions, ListRouteResult, NavigateOptions, QueryParams, RouteLocation, RouteParams, Router } from '@molecule/app-routing';
8
+ import { type MaybeReadable } from './maybe-readable.js';
8
9
  /** What {@link useRouter} returns. */
9
10
  export interface UseRouterResult {
10
11
  /** The current location. */
@@ -71,11 +72,15 @@ export declare function useNavigate(): (path: string, options?: NavigateOptions)
71
72
  * Whether a path is active, React's `useIsActive` in Svelte's idiom: a
72
73
  * readable store that re-evaluates on every route change.
73
74
  *
74
- * @param path - The path to check.
75
- * @param exact - Whether to match exactly (default: false).
75
+ * Both arguments may be a plain value or a readable store of one: the store
76
+ * re-evaluates when one changes (the way React's re-render re-reads its
77
+ * snapshot), so a navigation-driven nav link can take its path from a store.
78
+ *
79
+ * @param path - The path to check (or a store of it).
80
+ * @param exact - Whether to match exactly (default: false; or a store of it).
76
81
  * @returns A readable store of whether the path is active.
77
82
  */
78
- export declare function useIsActive(path: string, exact?: boolean): Readable<boolean>;
83
+ export declare function useIsActive(path: MaybeReadable<string>, exact?: MaybeReadable<boolean>): Readable<boolean>;
79
84
  /** What {@link useListRoute} returns: each list field as a readable store, the actions as plain functions. */
80
85
  export interface UseListRouteResult<Filter extends string = string, Selection extends string = string> {
81
86
  /** The current 1-indexed page. */
@@ -122,9 +127,10 @@ export type UseConsumedSearchParamStore = Readable<readonly [string, (value: str
122
127
  * `options.auth.redirectTo`, carrying `state.returnTo`; until auth is confirmed
123
128
  * `canLoad` is `false`.
124
129
  *
125
- * The options may be a readable store: an auth status moving from `loading` to
126
- * `unauthenticated` re-resolves the list — and performs the sign-in redirect —
127
- * on the same component, the way React re-renders `useListRoute`.
130
+ * The options may be a plain value or a readable store of one (a store holding
131
+ * `undefined` means the default options): an auth status moving from `loading`
132
+ * to `unauthenticated` re-resolves the list — and performs the sign-in
133
+ * redirect — on the same component, the way React re-renders `useListRoute`.
128
134
  *
129
135
  * @param options - Filter sources, view paths, pagination and optional auth readiness (or a store of them).
130
136
  * @returns Each list field as a readable store, and its link builder and navigation actions.
@@ -141,7 +147,7 @@ export type UseConsumedSearchParamStore = Readable<readonly [string, (value: str
141
147
  * <a href={href({ page: $page + 1 })}>Next</a>
142
148
  * ```
143
149
  */
144
- export declare function useListRoute<Filter extends string = string, Selection extends string = string>(options?: ListRouteOptions<Filter, Selection> | Readable<ListRouteOptions<Filter, Selection>>): UseListRouteResult<Filter, Selection>;
150
+ export declare function useListRoute<Filter extends string = string, Selection extends string = string>(options?: MaybeReadable<ListRouteOptions<Filter, Selection> | undefined>): UseListRouteResult<Filter, Selection>;
145
151
  /**
146
152
  * Takes a one-time credential (a reset `token`, an OAuth `code`) out of the URL
147
153
  * and keeps it in memory, React's `useConsumedSearchParam` in Svelte's idiom: a
@@ -1 +1 @@
1
- {"version":3,"file":"useRouter.d.ts","sourceRoot":"","sources":["../../src/hooks/useRouter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAO,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE3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