@molecule/app-svelte 3.10.0 → 3.13.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.
Files changed (40) hide show
  1. package/README.md +88 -15
  2. package/dist/components/BodyPortal.svelte +43 -0
  3. package/dist/components/BodyPortal.svelte.d.ts +11 -0
  4. package/dist/components/BodyPortal.svelte.d.ts.map +1 -0
  5. package/dist/components/PortalContent.svelte +12 -0
  6. package/dist/components/PortalContent.svelte.d.ts +8 -0
  7. package/dist/components/PortalContent.svelte.d.ts.map +1 -0
  8. package/dist/components/PresentWhileContent.svelte +58 -0
  9. package/dist/components/PresentWhileContent.svelte.d.ts +12 -0
  10. package/dist/components/PresentWhileContent.svelte.d.ts.map +1 -0
  11. package/dist/components/index.d.ts +11 -0
  12. package/dist/components/index.d.ts.map +1 -0
  13. package/dist/components/index.js +10 -0
  14. package/dist/content.d.ts +37 -0
  15. package/dist/content.d.ts.map +1 -0
  16. package/dist/content.js +40 -0
  17. package/dist/context.js +2 -2
  18. package/dist/hooks/useForm.d.ts +13 -3
  19. package/dist/hooks/useForm.d.ts.map +1 -1
  20. package/dist/hooks/useForm.js +13 -3
  21. package/dist/hooks/useOptimisticToggle.d.ts +4 -0
  22. package/dist/hooks/useOptimisticToggle.d.ts.map +1 -1
  23. package/dist/hooks/useOptimisticToggle.js +4 -0
  24. package/dist/hooks/useOptimisticValue.d.ts +19 -3
  25. package/dist/hooks/useOptimisticValue.d.ts.map +1 -1
  26. package/dist/hooks/useOptimisticValue.js +19 -3
  27. package/dist/hooks/usePromise.d.ts +3 -2
  28. package/dist/hooks/usePromise.d.ts.map +1 -1
  29. package/dist/hooks/usePromise.js +3 -2
  30. package/dist/hooks/useTranslation.d.ts +6 -2
  31. package/dist/hooks/useTranslation.d.ts.map +1 -1
  32. package/dist/hooks/useTranslation.js +6 -2
  33. package/dist/index.d.ts +24 -3
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +24 -3
  36. package/dist/stores/http.d.ts +6 -6
  37. package/dist/stores/http.js +6 -6
  38. package/dist/stores/version.d.ts +4 -4
  39. package/dist/stores/version.js +4 -4
  40. package/package.json +6 -2
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-23T19:31:56.893Z
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
  ```
@@ -130,6 +135,15 @@ then consume services anywhere below via store factories
130
135
  >
131
136
  ```
132
137
 
138
+ ```svelte
139
+ <!-- PortaledNode.svelte — content in document.body, exactly as React renders it -->
140
+ <script lang="ts">
141
+ import { BodyPortal } from '@molecule/app-svelte'
142
+ </script>
143
+
144
+ <BodyPortal><div role="dialog">…</div></BodyPortal>
145
+ ```
146
+
133
147
  Session state is a three-way decision, not a boolean: `status === 'loading'`
134
148
  is undecided, so wait for it and redirect only on
135
149
  `status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
@@ -143,7 +157,7 @@ signs the user out.
143
157
  ## Installation
144
158
 
145
159
  ```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
160
+ 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
161
  ```
148
162
 
149
163
  ## API
@@ -954,7 +968,8 @@ interface Router {
954
968
  getHash(): string
955
969
 
956
970
  /**
957
- * Navigates to a path.
971
+ * Navigates to a path. A path that is only a query or a hash (`'?tab=2'`, `'#top'`) stays on
972
+ * the current page, as React Router's `navigate` does; a hash alone drops the current query.
958
973
  */
959
974
  navigate(path: string, options?: NavigateOptions): void
960
975
 
@@ -1021,7 +1036,9 @@ interface Router {
1021
1036
  /**
1022
1037
  * The `href` an anchor to the in-app `path` carries, as the native router's own link
1023
1038
  * 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.
1039
+ * a new tab or a copied link opens the same page a click does. A `path` that is only a
1040
+ * query or a hash (`'?tab=2'`, `'#top'`) is the current page's, as `navigate` reads it
1041
+ * and as React Router's `<Link>` writes it: `'#top'` on `/docs?x=1` is `/docs#top`.
1025
1042
  *
1026
1043
  * @param path - Pathname with optional query string and hash, as passed to `navigate`.
1027
1044
  * @returns The `href`.
@@ -1029,7 +1046,15 @@ interface Router {
1029
1046
  createHref(path: string): string
1030
1047
 
1031
1048
  /**
1032
- * Subscribes to route changes.
1049
+ * Calls `listener` once after each navigation the router commits, however it started (a
1050
+ * link, the back button, `navigate`), with the new location and the navigation action.
1051
+ * A router calls it before the browser paints the new page, so a component that renders
1052
+ * from a listener (the framework bindings' `useLocation` and `useParams` do) shows the new
1053
+ * location in the same paint as the new page. Molecule's router conformance tests check
1054
+ * that at every paint.
1055
+ *
1056
+ * @param listener - Called with the new location and the navigation action.
1057
+ * @returns Stops calling `listener`.
1033
1058
  */
1034
1059
  subscribe(listener: RouteChangeListener): () => void
1035
1060
 
@@ -2786,6 +2811,36 @@ type SignupStore<T = unknown> = PromiseStore<AuthResult<T>, [RegisterData]>
2786
2811
 
2787
2812
  ### Functions
2788
2813
 
2814
+ #### `contentNodes(node)`
2815
+
2816
+ The children of a node that render something: elements, and text nodes with text. Comments
2817
+ and empty text nodes are Svelte's own anchors (and other components' placeholders), not
2818
+ content.
2819
+
2820
+ ```typescript
2821
+ function contentNodes(node: Node): ChildNode[]
2822
+ ```
2823
+
2824
+ - `node` — The node whose children are read.
2825
+
2826
+ **Returns:** Those children, in order.
2827
+
2828
+ #### `rendersContent(node)`
2829
+
2830
+ Whether a node's children render anything (see {@link contentNodes}). A Svelte component
2831
+ cannot tell from a snippet's value whether it renders anything (`{#each}` over no rows,
2832
+ `{#if false}`), so a component that renders a wrapper only while its content has something to
2833
+ show, as React's `slot(children) !== undefined && <div>…</div>` does, asks the rendered DOM
2834
+ instead (see `PresentWhileContent`).
2835
+
2836
+ ```typescript
2837
+ function rendersContent(node: Node): boolean
2838
+ ```
2839
+
2840
+ - `node` — The node whose children are read.
2841
+
2842
+ **Returns:** True when one of them renders something.
2843
+
2789
2844
  #### `setMoleculeContext(config)`
2790
2845
 
2791
2846
  Set all molecule providers in Svelte context.
@@ -4876,6 +4931,18 @@ function createVersionStores(): {
4876
4931
 
4877
4932
  ### Constants
4878
4933
 
4934
+ #### `BodyPortal`
4935
+
4936
+ ```typescript
4937
+ const BodyPortal: LegacyComponentType
4938
+ ```
4939
+
4940
+ #### `PresentWhileContent`
4941
+
4942
+ ```typescript
4943
+ const PresentWhileContent: LegacyComponentType
4944
+ ```
4945
+
4879
4946
  #### `Link`
4880
4947
 
4881
4948
  ```typescript
@@ -5078,41 +5145,43 @@ Peer dependencies:
5078
5145
  - `@molecule/app-ai-chat` ^1.8.0
5079
5146
  - `@molecule/app-ai-models` ^1.0.1
5080
5147
  - `@molecule/app-auth` ^3.0.0
5081
- - `@molecule/app-code-editor` ^1.0.1
5148
+ - `@molecule/app-code-editor` ^1.0.1 _(optional)_
5082
5149
  - `@molecule/app-device` ^1.0.1
5083
5150
  - `@molecule/app-forms` ^2.4.0
5084
5151
  - `@molecule/app-http` ^1.0.1
5085
5152
  - `@molecule/app-i18n` ^1.0.1
5086
- - `@molecule/app-ide` ^1.0.1
5087
- - `@molecule/app-live-preview` ^1.0.1
5153
+ - `@molecule/app-ide` ^1.0.1 _(optional)_
5154
+ - `@molecule/app-live-preview` ^1.0.1 _(optional)_
5088
5155
  - `@molecule/app-logger` ^1.0.1
5089
5156
  - `@molecule/app-platform` ^1.0.1
5090
5157
  - `@molecule/app-push` ^1.0.1
5091
5158
  - `@molecule/app-routing` ^1.4.0
5159
+ - `@molecule/app-routing-sveltekit` >=3.0.0 _(optional)_
5092
5160
  - `@molecule/app-state` ^1.2.0
5093
5161
  - `@molecule/app-storage` ^1.1.1
5094
5162
  - `@molecule/app-theme` ^1.0.1
5095
5163
  - `@molecule/app-ui` ^1.0.1
5096
5164
  - `@molecule/app-utilities` ^1.0.1
5097
5165
  - `@molecule/app-version` ^1.0.1
5098
- - `svelte` ^5.7.0
5166
+ - `svelte` ^5.43.15
5099
5167
 
5100
5168
  ### Runtime Dependencies
5101
5169
 
5102
5170
  - `@molecule/app-ai-chat`
5103
5171
  - `@molecule/app-ai-models`
5104
5172
  - `@molecule/app-auth`
5105
- - `@molecule/app-code-editor`
5173
+ - `@molecule/app-code-editor` _(optional)_
5106
5174
  - `@molecule/app-device`
5107
5175
  - `@molecule/app-forms`
5108
5176
  - `@molecule/app-http`
5109
5177
  - `@molecule/app-i18n`
5110
- - `@molecule/app-ide`
5111
- - `@molecule/app-live-preview`
5178
+ - `@molecule/app-ide` _(optional)_
5179
+ - `@molecule/app-live-preview` _(optional)_
5112
5180
  - `@molecule/app-logger`
5113
5181
  - `@molecule/app-platform`
5114
5182
  - `@molecule/app-push`
5115
5183
  - `@molecule/app-routing`
5184
+ - `@molecule/app-routing-sveltekit` _(optional)_
5116
5185
  - `@molecule/app-state`
5117
5186
  - `@molecule/app-storage`
5118
5187
  - `@molecule/app-theme`
@@ -5133,6 +5202,10 @@ Peer dependencies:
5133
5202
  - In-app links are `Link` (`<Link to="/settings">`): it navigates through the router with
5134
5203
  react-router `<Link>`'s click rules. A hand-written click handler that calls `navigate()`
5135
5204
  breaks ctrl/cmd-click (new tab) unless it repeats those rules.
5205
+ - `BodyPortal` is React's `createPortal(children, document.body)` for Svelte: Svelte itself
5206
+ renders the content in the target (a nested `mount`), so no node is moved after Svelte
5207
+ placed it. Nothing renders on the server; `target` replaces the body and `null` renders
5208
+ nothing until a target exists.
5136
5209
 
5137
5210
  ## Translations
5138
5211
 
@@ -0,0 +1,43 @@
1
+ <!--
2
+ BodyPortal: renders its children as direct children of `document.body` (or of
3
+ `target`), with no wrapper element — React's `createPortal(children, target)`.
4
+
5
+ Svelte itself places the nodes there: a second `mount()` whose content is this
6
+ component's `children` snippet. No node is ever moved after Svelte placed it, so
7
+ every block range, anchor and keyed item inside the portal stays where Svelte
8
+ put it, and the portal's content is unmounted with this component.
9
+
10
+ Context flows through (`getAllContexts`), the snippet stays reactive, delegated
11
+ events reach the content (the mount registers them on the target) and nothing
12
+ renders on the server, as with React's portals.
13
+ -->
14
+ <script lang="ts">
15
+ import { flushSync, getAllContexts, mount, type Snippet, unmount } from 'svelte'
16
+
17
+ import PortalContent from './PortalContent.svelte'
18
+
19
+ let {
20
+ target,
21
+ children,
22
+ }: {
23
+ /** Where the children render. Defaults to `document.body`; `null` renders nothing yet. */
24
+ target?: Element | null
25
+ /** The portaled content. */
26
+ children?: Snippet
27
+ } = $props()
28
+
29
+ const context = getAllContexts()
30
+
31
+ $effect(() => {
32
+ const parent = target === undefined ? document.body : target
33
+ const content = children
34
+ if (!parent || !content) return
35
+ const instance = mount(PortalContent, { target: parent, props: { children: content }, context })
36
+ // The content's own bindings, actions and effects run now, before the effects of the
37
+ // component that declared the portal: the order inline markup would give them.
38
+ flushSync()
39
+ return () => {
40
+ void unmount(instance)
41
+ }
42
+ })
43
+ </script>
@@ -0,0 +1,11 @@
1
+ import { type Snippet } from 'svelte';
2
+ type $$ComponentProps = {
3
+ /** Where the children render. Defaults to `document.body`; `null` renders nothing yet. */
4
+ target?: Element | null;
5
+ /** The portaled content. */
6
+ children?: Snippet;
7
+ };
8
+ declare const BodyPortal: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type BodyPortal = ReturnType<typeof BodyPortal>;
10
+ export default BodyPortal;
11
+ //# sourceMappingURL=BodyPortal.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BodyPortal.svelte.d.ts","sourceRoot":"","sources":["../../src/components/BodyPortal.svelte"],"names":[],"mappings":"AAGA,OAAO,EAAoC,KAAK,OAAO,EAAW,MAAM,QAAQ,CAAA;AAI/E,KAAK,gBAAgB,GAAI;IACtB,0FAA0F;IAC1F,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACvB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAC;AA8BJ,QAAA,MAAM,UAAU,sDAAwC,CAAC;AACzD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAChD,eAAe,UAAU,CAAC"}
@@ -0,0 +1,12 @@
1
+ <!--
2
+ The root a `BodyPortal` mounts in its target: the portal's children and nothing
3
+ else, so the target receives exactly the nodes the declaring component rendered
4
+ (React's `createPortal(children, target)` renders no wrapper either).
5
+ -->
6
+ <script lang="ts">
7
+ import type { Snippet } from 'svelte'
8
+
9
+ let { children }: { children: Snippet } = $props()
10
+ </script>
11
+
12
+ {@render children?.()}
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from 'svelte';
2
+ type $$ComponentProps = {
3
+ children: Snippet;
4
+ };
5
+ declare const PortalContent: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type PortalContent = ReturnType<typeof PortalContent>;
7
+ export default PortalContent;
8
+ //# sourceMappingURL=PortalContent.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PortalContent.svelte.d.ts","sourceRoot":"","sources":["../../src/components/PortalContent.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAErC,KAAK,gBAAgB,GAAI;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAYhD,QAAA,MAAM,aAAa,sDAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
@@ -0,0 +1,58 @@
1
+ <!--
2
+ PresentWhileContent: an element that is in the page only while its content renders something
3
+ (an element, or text) — React's `slot(children) !== undefined ? <div>{children}</div> : null`,
4
+ which a Svelte component cannot decide from a snippet's value (an `{#each}` over no rows, an
5
+ `{#if false}`). `tag` names the element (`div` by default); every other prop is an attribute of
6
+ it.
7
+
8
+ The element is the only node of its own `svelte:element` block. While its content is empty it
9
+ leaves the page and waits just before that block's anchor comment, which Svelte moves with the
10
+ block, so it comes back in its place; a `MutationObserver` on it (which keeps reporting while
11
+ it is out of the page) decides again after every change Svelte makes to the content. The
12
+ observer reports in a microtask, before the browser paints.
13
+ -->
14
+ <script lang="ts">
15
+ import type { Snippet } from 'svelte'
16
+ import type { Attachment } from 'svelte/attachments'
17
+ import type { HTMLAttributes } from 'svelte/elements'
18
+
19
+ import { rendersContent } from '../content.js'
20
+
21
+ let {
22
+ tag = 'div',
23
+ children,
24
+ ...attributes
25
+ }: HTMLAttributes<HTMLElement> & {
26
+ /** The element's tag. */
27
+ tag?: string
28
+ /** The content; the element is in the page only while it renders something. */
29
+ children?: Snippet
30
+ } = $props()
31
+
32
+ /**
33
+ * Keeps the element in the page exactly while its content renders something.
34
+ *
35
+ * @param element - The element.
36
+ * @returns The cleanup.
37
+ */
38
+ const presentWhileContent: Attachment<HTMLElement> = (element) => {
39
+ // The block's anchor: Svelte inserts the element in front of it and moves the two together.
40
+ const anchor = element.nextSibling
41
+ const sync = (): void => {
42
+ if (rendersContent(element)) {
43
+ if (!element.isConnected && anchor?.parentNode)
44
+ anchor.parentNode.insertBefore(element, anchor)
45
+ } else if (element.parentNode) {
46
+ element.remove()
47
+ }
48
+ }
49
+ sync()
50
+ const observer = new MutationObserver(sync)
51
+ observer.observe(element, { childList: true, characterData: true, subtree: true })
52
+ return () => observer.disconnect()
53
+ }
54
+ </script>
55
+
56
+ <svelte:element this={tag} {...attributes} {@attach presentWhileContent}
57
+ >{@render children?.()}</svelte:element
58
+ >
@@ -0,0 +1,12 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ type $$ComponentProps = HTMLAttributes<HTMLElement> & {
4
+ /** The element's tag. */
5
+ tag?: string;
6
+ /** The content; the element is in the page only while it renders something. */
7
+ children?: Snippet;
8
+ };
9
+ declare const PresentWhileContent: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type PresentWhileContent = ReturnType<typeof PresentWhileContent>;
11
+ export default PresentWhileContent;
12
+ //# sourceMappingURL=PresentWhileContent.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PresentWhileContent.svelte.d.ts","sourceRoot":"","sources":["../../src/components/PresentWhileContent.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAIpD,KAAK,gBAAgB,GAAI,cAAc,CAAC,WAAW,CAAC,GAAG;IACpD,yBAAyB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAC;AA2CJ,QAAA,MAAM,mBAAmB,sDAAwC,CAAC;AAClE,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAClE,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The components that are not tied to one service: `BodyPortal`, React's
3
+ * `createPortal` for `document.body`, as a Svelte component, and
4
+ * `PresentWhileContent`, an element in the page only while its content renders
5
+ * something (React's `slot(children) !== undefined && <div>…</div>`).
6
+ *
7
+ * @module
8
+ */
9
+ export { default as BodyPortal } from './BodyPortal.svelte';
10
+ export { default as PresentWhileContent } from './PresentWhileContent.svelte';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The components that are not tied to one service: `BodyPortal`, React's
3
+ * `createPortal` for `document.body`, as a Svelte component, and
4
+ * `PresentWhileContent`, an element in the page only while its content renders
5
+ * something (React's `slot(children) !== undefined && <div>…</div>`).
6
+ *
7
+ * @module
8
+ */
9
+ export { default as BodyPortal } from './BodyPortal.svelte';
10
+ export { default as PresentWhileContent } from './PresentWhileContent.svelte';
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Rendered DOM content, read by React's `slot(node)` rule.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * The children of a node that render something: elements, and text nodes with text. Comments
8
+ * and empty text nodes are Svelte's own anchors (and other components' placeholders), not
9
+ * content.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const nodes = contentNodes(titleEl)
14
+ * const text = nodes.length === 1 && nodes[0].nodeType === 3 ? nodes[0].textContent : ''
15
+ * ```
16
+ *
17
+ * @param node - The node whose children are read.
18
+ * @returns Those children, in order.
19
+ */
20
+ export declare function contentNodes(node: Node): ChildNode[];
21
+ /**
22
+ * Whether a node's children render anything (see {@link contentNodes}). A Svelte component
23
+ * cannot tell from a snippet's value whether it renders anything (`{#each}` over no rows,
24
+ * `{#if false}`), so a component that renders a wrapper only while its content has something to
25
+ * show, as React's `slot(children) !== undefined && <div>…</div>` does, asks the rendered DOM
26
+ * instead (see `PresentWhileContent`).
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * rendersContent(panel) // false while the panel's snippet renders an empty list
31
+ * ```
32
+ *
33
+ * @param node - The node whose children are read.
34
+ * @returns True when one of them renders something.
35
+ */
36
+ export declare function rendersContent(node: Node): boolean;
37
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,CAIpD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAElD"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Rendered DOM content, read by React's `slot(node)` rule.
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * The children of a node that render something: elements, and text nodes with text. Comments
8
+ * and empty text nodes are Svelte's own anchors (and other components' placeholders), not
9
+ * content.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const nodes = contentNodes(titleEl)
14
+ * const text = nodes.length === 1 && nodes[0].nodeType === 3 ? nodes[0].textContent : ''
15
+ * ```
16
+ *
17
+ * @param node - The node whose children are read.
18
+ * @returns Those children, in order.
19
+ */
20
+ export function contentNodes(node) {
21
+ return Array.from(node.childNodes).filter((child) => child.nodeType === 1 || (child.nodeType === 3 && (child.textContent ?? '') !== ''));
22
+ }
23
+ /**
24
+ * Whether a node's children render anything (see {@link contentNodes}). A Svelte component
25
+ * cannot tell from a snippet's value whether it renders anything (`{#each}` over no rows,
26
+ * `{#if false}`), so a component that renders a wrapper only while its content has something to
27
+ * show, as React's `slot(children) !== undefined && <div>…</div>` does, asks the rendered DOM
28
+ * instead (see `PresentWhileContent`).
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * rendersContent(panel) // false while the panel's snippet renders an empty list
33
+ * ```
34
+ *
35
+ * @param node - The node whose children are read.
36
+ * @returns True when one of them renders something.
37
+ */
38
+ export function rendersContent(node) {
39
+ return contentNodes(node).length > 0;
40
+ }
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 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ACH,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"}
@@ -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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;;;;;;;;;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;;;;;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"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,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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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BAAgB,cAAc,IAAI,oBAAoB,CAmBrD;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,IAAI,YAAY,CAenC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC,CAG5C;AAED;;;;GAIG;AACH,wBAAgB,YAAY,IAAI,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,CAGtD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,aAAa,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,GAC7C,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAazB"}
@@ -64,13 +64,17 @@ function localeValue(version, read) {
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
  * ```
@@ -114,6 +119,16 @@
114
119
  * >{$favorite.count}</button>
115
120
  * ```
116
121
  *
122
+ * @example
123
+ * ```svelte
124
+ * <!-- PortaledNode.svelte — content in document.body, exactly as React renders it -->
125
+ * <script lang="ts">
126
+ * import { BodyPortal } from '@molecule/app-svelte'
127
+ * </script>
128
+ *
129
+ * <BodyPortal><div role="dialog">…</div></BodyPortal>
130
+ * ```
131
+ *
117
132
  * Session state is a three-way decision, not a boolean: `status === 'loading'`
118
133
  * is undecided, so wait for it and redirect only on
119
134
  * `status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
@@ -133,10 +148,16 @@
133
148
  * - In-app links are `Link` (`<Link to="/settings">`): it navigates through the router with
134
149
  * react-router `<Link>`'s click rules. A hand-written click handler that calls `navigate()`
135
150
  * breaks ctrl/cmd-click (new tab) unless it repeats those rules.
151
+ * - `BodyPortal` is React's `createPortal(children, document.body)` for Svelte: Svelte itself
152
+ * renders the content in the target (a nested `mount`), so no node is moved after Svelte
153
+ * placed it. Nothing renders on the server; `target` replaces the body and `null` renders
154
+ * nothing until a target exists.
136
155
  *
137
156
  * @module
138
157
  */
139
158
  export * from './agent-identity.js';
159
+ export * from './components/index.js';
160
+ export * from './content.js';
140
161
  export * from './context.js';
141
162
  export * from './hooks/index.js';
142
163
  export * from './link/index.js';
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4JG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,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
  * ```
@@ -114,6 +119,16 @@
114
119
  * >{$favorite.count}</button>
115
120
  * ```
116
121
  *
122
+ * @example
123
+ * ```svelte
124
+ * <!-- PortaledNode.svelte — content in document.body, exactly as React renders it -->
125
+ * <script lang="ts">
126
+ * import { BodyPortal } from '@molecule/app-svelte'
127
+ * </script>
128
+ *
129
+ * <BodyPortal><div role="dialog">…</div></BodyPortal>
130
+ * ```
131
+ *
117
132
  * Session state is a three-way decision, not a boolean: `status === 'loading'`
118
133
  * is undecided, so wait for it and redirect only on
119
134
  * `status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
@@ -133,10 +148,16 @@
133
148
  * - In-app links are `Link` (`<Link to="/settings">`): it navigates through the router with
134
149
  * react-router `<Link>`'s click rules. A hand-written click handler that calls `navigate()`
135
150
  * breaks ctrl/cmd-click (new tab) unless it repeats those rules.
151
+ * - `BodyPortal` is React's `createPortal(children, document.body)` for Svelte: Svelte itself
152
+ * renders the content in the target (a nested `mount`), so no node is moved after Svelte
153
+ * placed it. Nothing renders on the server; `target` replaces the body and `null` renders
154
+ * nothing until a target exists.
136
155
  *
137
156
  * @module
138
157
  */
139
158
  export * from './agent-identity.js';
159
+ export * from './components/index.js';
160
+ export * from './content.js';
140
161
  export * from './context.js';
141
162
  export * from './hooks/index.js';
142
163
  export * from './link/index.js';
@@ -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.13.0",
4
4
  "description": "Svelte framework bindings for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -52,13 +52,14 @@
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",
58
59
  "@molecule/app-ui": "^1.0.1",
59
60
  "@molecule/app-utilities": "^1.0.1",
60
61
  "@molecule/app-version": "^1.0.1",
61
- "svelte": "^5.7.0"
62
+ "svelte": "^5.43.15"
62
63
  },
63
64
  "peerDependenciesMeta": {
64
65
  "@molecule/app-code-editor": {
@@ -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": {