@molecule/app-svelte 3.9.0 → 3.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -16
- package/dist/context.d.ts +11 -3
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +14 -8
- package/dist/hooks/useForm.d.ts +13 -3
- package/dist/hooks/useForm.d.ts.map +1 -1
- package/dist/hooks/useForm.js +13 -3
- package/dist/hooks/useOptimisticToggle.d.ts +4 -0
- package/dist/hooks/useOptimisticToggle.d.ts.map +1 -1
- package/dist/hooks/useOptimisticToggle.js +4 -0
- package/dist/hooks/useOptimisticValue.d.ts +19 -3
- package/dist/hooks/useOptimisticValue.d.ts.map +1 -1
- package/dist/hooks/useOptimisticValue.js +19 -3
- package/dist/hooks/usePromise.d.ts +3 -2
- package/dist/hooks/usePromise.d.ts.map +1 -1
- package/dist/hooks/usePromise.js +3 -2
- package/dist/hooks/useTranslation.d.ts +6 -2
- package/dist/hooks/useTranslation.d.ts.map +1 -1
- package/dist/hooks/useTranslation.js +6 -2
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/providers/Provided.svelte +12 -4
- package/dist/providers/Provided.svelte.d.ts +3 -2
- package/dist/providers/Provided.svelte.d.ts.map +1 -1
- package/dist/providers/RouterProvider.svelte +8 -5
- package/dist/providers/RouterProvider.svelte.d.ts.map +1 -1
- package/dist/routed-view/RoutedView.svelte +13 -0
- package/dist/routed-view/RoutedView.svelte.d.ts +19 -0
- package/dist/routed-view/RoutedView.svelte.d.ts.map +1 -0
- package/dist/routed-view/index.d.ts +8 -0
- package/dist/routed-view/index.d.ts.map +1 -0
- package/dist/routed-view/index.js +7 -0
- package/dist/routed-view-context.d.ts +25 -0
- package/dist/routed-view-context.d.ts.map +1 -0
- package/dist/routed-view-context.js +34 -0
- package/dist/stores/http.d.ts +6 -6
- package/dist/stores/http.js +6 -6
- package/dist/stores/version.d.ts +4 -4
- package/dist/stores/version.js +4 -4
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -1
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-
|
|
6
|
+
Generated: 2026-11-22T19:01:00.165Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-svelte
|
|
@@ -24,6 +24,7 @@ then consume services anywhere below via store factories
|
|
|
24
24
|
```svelte
|
|
25
25
|
<!-- +layout.svelte — wire providers ONCE, during component init -->
|
|
26
26
|
<script lang="ts">
|
|
27
|
+
import type { Snippet } from 'svelte'
|
|
27
28
|
import { setMoleculeContext } from '@molecule/app-svelte'
|
|
28
29
|
import { provider as stateProvider } from '@molecule/app-state-zustand'
|
|
29
30
|
import { provider as themeProvider } from '@molecule/app-theme-css-variables'
|
|
@@ -34,10 +35,14 @@ then consume services anywhere below via store factories
|
|
|
34
35
|
auth: createJWTAuthClient({ baseURL: '/api' }),
|
|
35
36
|
theme: themeProvider,
|
|
36
37
|
})
|
|
38
|
+
|
|
39
|
+
let { children }: { children: Snippet } = $props()
|
|
37
40
|
</script>
|
|
38
41
|
|
|
39
|
-
|
|
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
|
|
53
|
-
<button
|
|
57
|
+
<button onclick={toggleTheme}>Toggle ({$mode})</button>
|
|
58
|
+
<button onclick={() => logout()}>Logout</button>
|
|
54
59
|
</div>
|
|
55
60
|
{/if}
|
|
56
61
|
```
|
|
@@ -143,7 +148,7 @@ signs the user out.
|
|
|
143
148
|
## Installation
|
|
144
149
|
|
|
145
150
|
```bash
|
|
146
|
-
npm install @molecule/app-svelte @molecule/app-ai-chat @molecule/app-ai-models @molecule/app-auth @molecule/app-
|
|
151
|
+
npm install @molecule/app-svelte @molecule/app-ai-chat @molecule/app-ai-models @molecule/app-auth @molecule/app-device @molecule/app-forms @molecule/app-http @molecule/app-i18n @molecule/app-logger @molecule/app-platform @molecule/app-push @molecule/app-routing @molecule/app-state @molecule/app-storage @molecule/app-theme @molecule/app-ui @molecule/app-utilities @molecule/app-version svelte
|
|
147
152
|
```
|
|
148
153
|
|
|
149
154
|
## API
|
|
@@ -954,7 +959,8 @@ interface Router {
|
|
|
954
959
|
getHash(): string
|
|
955
960
|
|
|
956
961
|
/**
|
|
957
|
-
* Navigates to a path.
|
|
962
|
+
* Navigates to a path. A path that is only a query or a hash (`'?tab=2'`, `'#top'`) stays on
|
|
963
|
+
* the current page, as React Router's `navigate` does; a hash alone drops the current query.
|
|
958
964
|
*/
|
|
959
965
|
navigate(path: string, options?: NavigateOptions): void
|
|
960
966
|
|
|
@@ -1021,7 +1027,9 @@ interface Router {
|
|
|
1021
1027
|
/**
|
|
1022
1028
|
* The `href` an anchor to the in-app `path` carries, as the native router's own link
|
|
1023
1029
|
* writes it (its base path prefixed, or `#/…` under a hash history), so a middle-click,
|
|
1024
|
-
* a new tab or a copied link opens the same page a click does.
|
|
1030
|
+
* a new tab or a copied link opens the same page a click does. A `path` that is only a
|
|
1031
|
+
* query or a hash (`'?tab=2'`, `'#top'`) is the current page's, as `navigate` reads it
|
|
1032
|
+
* and as React Router's `<Link>` writes it: `'#top'` on `/docs?x=1` is `/docs#top`.
|
|
1025
1033
|
*
|
|
1026
1034
|
* @param path - Pathname with optional query string and hash, as passed to `navigate`.
|
|
1027
1035
|
* @returns The `href`.
|
|
@@ -1029,7 +1037,15 @@ interface Router {
|
|
|
1029
1037
|
createHref(path: string): string
|
|
1030
1038
|
|
|
1031
1039
|
/**
|
|
1032
|
-
*
|
|
1040
|
+
* Calls `listener` once after each navigation the router commits, however it started (a
|
|
1041
|
+
* link, the back button, `navigate`), with the new location and the navigation action.
|
|
1042
|
+
* A router calls it before the browser paints the new page, so a component that renders
|
|
1043
|
+
* from a listener (the framework bindings' `useLocation` and `useParams` do) shows the new
|
|
1044
|
+
* location in the same paint as the new page. The router conformance cases of
|
|
1045
|
+
* `@molecule/app-framework-conformance/routing` check that at every paint.
|
|
1046
|
+
*
|
|
1047
|
+
* @param listener - Called with the new location and the navigation action.
|
|
1048
|
+
* @returns Stops calling `listener`.
|
|
1033
1049
|
*/
|
|
1034
1050
|
subscribe(listener: RouteChangeListener): () => void
|
|
1035
1051
|
|
|
@@ -2399,6 +2415,13 @@ Props for the `RouterProvider` component.
|
|
|
2399
2415
|
```typescript
|
|
2400
2416
|
interface RouterProviderProps extends ProviderProps {
|
|
2401
2417
|
router: Router
|
|
2418
|
+
/**
|
|
2419
|
+
* The component that renders the matched child route where a layout or guard puts it, so
|
|
2420
|
+
* `<RoutedView />` works under any routing bond. A routing bond passes it; leave it out when
|
|
2421
|
+
* the bond has none (SvelteKit gives a layout its page as `children`), and `<RoutedView />`
|
|
2422
|
+
* then throws an error saying so.
|
|
2423
|
+
*/
|
|
2424
|
+
routedView?: Component
|
|
2402
2425
|
}
|
|
2403
2426
|
```
|
|
2404
2427
|
|
|
@@ -2825,15 +2848,17 @@ function setThemeContext(provider: ThemeProvider): void
|
|
|
2825
2848
|
|
|
2826
2849
|
- `provider` — The theme provider to store in Svelte context.
|
|
2827
2850
|
|
|
2828
|
-
#### `setRouterContext(router)`
|
|
2851
|
+
#### `setRouterContext(router, options)`
|
|
2829
2852
|
|
|
2830
2853
|
Sets the router context.
|
|
2831
2854
|
|
|
2832
2855
|
```typescript
|
|
2833
|
-
function setRouterContext(router: Router): void
|
|
2856
|
+
function setRouterContext(router: Router, options?: { routedView?: Component }): void
|
|
2834
2857
|
```
|
|
2835
2858
|
|
|
2836
2859
|
- `router` — The router instance to store in Svelte context.
|
|
2860
|
+
- `options` — From a routing bond: its routed view (see `RoutedView`). Given, it is set too (`null` without `routedView`).
|
|
2861
|
+
- `options.routedView` — The component that renders the matched child route.
|
|
2837
2862
|
|
|
2838
2863
|
#### `setI18nContext(provider)`
|
|
2839
2864
|
|
|
@@ -4873,6 +4898,12 @@ function createVersionStores(): {
|
|
|
4873
4898
|
const Link: LegacyComponentType
|
|
4874
4899
|
```
|
|
4875
4900
|
|
|
4901
|
+
#### `RoutedView`
|
|
4902
|
+
|
|
4903
|
+
```typescript
|
|
4904
|
+
const RoutedView: LegacyComponentType
|
|
4905
|
+
```
|
|
4906
|
+
|
|
4876
4907
|
#### `SessionReady`
|
|
4877
4908
|
|
|
4878
4909
|
```typescript
|
|
@@ -5063,17 +5094,18 @@ Peer dependencies:
|
|
|
5063
5094
|
- `@molecule/app-ai-chat` ^1.8.0
|
|
5064
5095
|
- `@molecule/app-ai-models` ^1.0.1
|
|
5065
5096
|
- `@molecule/app-auth` ^3.0.0
|
|
5066
|
-
- `@molecule/app-code-editor` ^1.0.1
|
|
5097
|
+
- `@molecule/app-code-editor` ^1.0.1 _(optional)_
|
|
5067
5098
|
- `@molecule/app-device` ^1.0.1
|
|
5068
5099
|
- `@molecule/app-forms` ^2.4.0
|
|
5069
5100
|
- `@molecule/app-http` ^1.0.1
|
|
5070
5101
|
- `@molecule/app-i18n` ^1.0.1
|
|
5071
|
-
- `@molecule/app-ide` ^1.0.1
|
|
5072
|
-
- `@molecule/app-live-preview` ^1.0.1
|
|
5102
|
+
- `@molecule/app-ide` ^1.0.1 _(optional)_
|
|
5103
|
+
- `@molecule/app-live-preview` ^1.0.1 _(optional)_
|
|
5073
5104
|
- `@molecule/app-logger` ^1.0.1
|
|
5074
5105
|
- `@molecule/app-platform` ^1.0.1
|
|
5075
5106
|
- `@molecule/app-push` ^1.0.1
|
|
5076
5107
|
- `@molecule/app-routing` ^1.4.0
|
|
5108
|
+
- `@molecule/app-routing-sveltekit` >=3.0.0 _(optional)_
|
|
5077
5109
|
- `@molecule/app-state` ^1.2.0
|
|
5078
5110
|
- `@molecule/app-storage` ^1.1.1
|
|
5079
5111
|
- `@molecule/app-theme` ^1.0.1
|
|
@@ -5087,17 +5119,18 @@ Peer dependencies:
|
|
|
5087
5119
|
- `@molecule/app-ai-chat`
|
|
5088
5120
|
- `@molecule/app-ai-models`
|
|
5089
5121
|
- `@molecule/app-auth`
|
|
5090
|
-
- `@molecule/app-code-editor`
|
|
5122
|
+
- `@molecule/app-code-editor` _(optional)_
|
|
5091
5123
|
- `@molecule/app-device`
|
|
5092
5124
|
- `@molecule/app-forms`
|
|
5093
5125
|
- `@molecule/app-http`
|
|
5094
5126
|
- `@molecule/app-i18n`
|
|
5095
|
-
- `@molecule/app-ide`
|
|
5096
|
-
- `@molecule/app-live-preview`
|
|
5127
|
+
- `@molecule/app-ide` _(optional)_
|
|
5128
|
+
- `@molecule/app-live-preview` _(optional)_
|
|
5097
5129
|
- `@molecule/app-logger`
|
|
5098
5130
|
- `@molecule/app-platform`
|
|
5099
5131
|
- `@molecule/app-push`
|
|
5100
5132
|
- `@molecule/app-routing`
|
|
5133
|
+
- `@molecule/app-routing-sveltekit` _(optional)_
|
|
5101
5134
|
- `@molecule/app-state`
|
|
5102
5135
|
- `@molecule/app-storage`
|
|
5103
5136
|
- `@molecule/app-theme`
|
package/dist/context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
+
import type { Component } from 'svelte';
|
|
6
7
|
import type { ChatProvider } from '@molecule/app-ai-chat';
|
|
7
8
|
import type { AuthClient, RegisterExtraShape } from '@molecule/app-auth';
|
|
8
9
|
import type { EditorProvider } from '@molecule/app-code-editor';
|
|
@@ -61,8 +62,13 @@ export declare function setThemeContext(provider: ThemeProvider): void;
|
|
|
61
62
|
/**
|
|
62
63
|
* Sets the router context.
|
|
63
64
|
* @param router - The router instance to store in Svelte context.
|
|
65
|
+
* @param options - From a routing bond: its routed view (see `RoutedView`). Given, it is set
|
|
66
|
+
* too (`null` without `routedView`).
|
|
67
|
+
* @param options.routedView - The component that renders the matched child route.
|
|
64
68
|
*/
|
|
65
|
-
export declare function setRouterContext(router: Router
|
|
69
|
+
export declare function setRouterContext(router: Router, options?: {
|
|
70
|
+
routedView?: Component;
|
|
71
|
+
}): void;
|
|
66
72
|
/**
|
|
67
73
|
* Sets the i18n context.
|
|
68
74
|
* @param provider - The i18n provider to store in Svelte context.
|
|
@@ -124,7 +130,8 @@ export declare function getThemeProvider(): ThemeProvider;
|
|
|
124
130
|
/**
|
|
125
131
|
* Gets the router from Svelte context.
|
|
126
132
|
* @returns The router instance.
|
|
127
|
-
* @throws {
|
|
133
|
+
* @throws {I18nError} If no router has been set in context: mount the routing bond's
|
|
134
|
+
* `MoleculeRouterProvider` in the root `+layout.svelte`, or call `setMoleculeContext({ router })`.
|
|
128
135
|
*/
|
|
129
136
|
export declare function getRouter(): Router;
|
|
130
137
|
/**
|
|
@@ -207,7 +214,8 @@ export declare function useThemeProvider(): ThemeProvider;
|
|
|
207
214
|
/**
|
|
208
215
|
* Gets the router from Svelte context under the React hook's name.
|
|
209
216
|
* @returns The router instance.
|
|
210
|
-
* @throws {
|
|
217
|
+
* @throws {I18nError} If no router has been set in context: mount the routing bond's
|
|
218
|
+
* `MoleculeRouterProvider` in the root `+layout.svelte`, or call `setMoleculeContext({ router })`.
|
|
211
219
|
*/
|
|
212
220
|
export declare function useRouterInstance(): Router;
|
|
213
221
|
/**
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAgBhD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAgB/D;AAGD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAE7D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,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M,CASlC;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAS9C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAS1C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CASpD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CASlD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAS9C;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI,iBAAiB,CASxD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CASlD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CASpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,CAAC,GAAG,OAAO,EACX,SAAS,SAAS,kBAAkB,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,KACnE,UAAU,CAAC,CAAC,EAAE,SAAS,CAAC,CAS5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAE9C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAShD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAS1C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAS1C;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CASpD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,CASlD;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAShD"}
|
package/dist/context.js
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
import { getContext, setContext } from 'svelte';
|
|
7
|
-
import { getProvider as getBondedI18nProvider, t } from '@molecule/app-i18n';
|
|
7
|
+
import { getProvider as getBondedI18nProvider, I18nError, t } from '@molecule/app-i18n';
|
|
8
8
|
import { getProvider as getBondedStateProvider, hasProvider as hasBondedStateProvider, } from '@molecule/app-state';
|
|
9
|
+
import { setRoutedViewContext } from './routed-view-context.js';
|
|
9
10
|
// Context keys
|
|
10
11
|
const STATE_KEY = Symbol('molecule-state');
|
|
11
12
|
const AUTH_KEY = Symbol('molecule-auth');
|
|
@@ -99,9 +100,14 @@ export function setThemeContext(provider) {
|
|
|
99
100
|
/**
|
|
100
101
|
* Sets the router context.
|
|
101
102
|
* @param router - The router instance to store in Svelte context.
|
|
103
|
+
* @param options - From a routing bond: its routed view (see `RoutedView`). Given, it is set
|
|
104
|
+
* too (`null` without `routedView`).
|
|
105
|
+
* @param options.routedView - The component that renders the matched child route.
|
|
102
106
|
*/
|
|
103
|
-
export function setRouterContext(router) {
|
|
107
|
+
export function setRouterContext(router, options) {
|
|
104
108
|
setContext(ROUTER_KEY, router);
|
|
109
|
+
if (options)
|
|
110
|
+
setRoutedViewContext(options.routedView ?? null);
|
|
105
111
|
}
|
|
106
112
|
/**
|
|
107
113
|
* Sets the i18n context.
|
|
@@ -202,12 +208,13 @@ export function getThemeProvider() {
|
|
|
202
208
|
/**
|
|
203
209
|
* Gets the router from Svelte context.
|
|
204
210
|
* @returns The router instance.
|
|
205
|
-
* @throws {
|
|
211
|
+
* @throws {I18nError} If no router has been set in context: mount the routing bond's
|
|
212
|
+
* `MoleculeRouterProvider` in the root `+layout.svelte`, or call `setMoleculeContext({ router })`.
|
|
206
213
|
*/
|
|
207
214
|
export function getRouter() {
|
|
208
215
|
const router = getContext(ROUTER_KEY);
|
|
209
216
|
if (!router)
|
|
210
|
-
throw new
|
|
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`).');
|
|
211
218
|
return router;
|
|
212
219
|
}
|
|
213
220
|
/**
|
|
@@ -362,14 +369,13 @@ export function useThemeProvider() {
|
|
|
362
369
|
/**
|
|
363
370
|
* Gets the router from Svelte context under the React hook's name.
|
|
364
371
|
* @returns The router instance.
|
|
365
|
-
* @throws {
|
|
372
|
+
* @throws {I18nError} If no router has been set in context: mount the routing bond's
|
|
373
|
+
* `MoleculeRouterProvider` in the root `+layout.svelte`, or call `setMoleculeContext({ router })`.
|
|
366
374
|
*/
|
|
367
375
|
export function useRouterInstance() {
|
|
368
376
|
const router = getContext(ROUTER_KEY);
|
|
369
377
|
if (!router)
|
|
370
|
-
throw new
|
|
371
|
-
defaultValue: 'useRouterInstance must be used within a RouterProvider',
|
|
372
|
-
}));
|
|
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`).');
|
|
373
379
|
return router;
|
|
374
380
|
}
|
|
375
381
|
/**
|
package/dist/hooks/useForm.d.ts
CHANGED
|
@@ -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) => {
|
|
108
|
+
* const onSubmit = handleSubmit(async (values) => {
|
|
109
|
+
* await login(values)
|
|
110
|
+
* })
|
|
109
111
|
* </script>
|
|
110
112
|
*
|
|
111
113
|
* <form onsubmit={onSubmit}>
|
|
112
|
-
* <input {
|
|
114
|
+
* <input {...register('email', { required: true, email: true })} />
|
|
115
|
+
* {#if $formState.errors.email}<span>{$formState.errors.email}</span>{/if}
|
|
116
|
+
*
|
|
117
|
+
* <input {...register('password', { required: true, minLength: 8 })} type="password" />
|
|
118
|
+
* {#if $formState.errors.password}<span>{$formState.errors.password}</span>{/if}
|
|
119
|
+
*
|
|
120
|
+
* <button type="submit" disabled={$isSubmitting}>
|
|
121
|
+
* {$isSubmitting ? 'Logging in...' : 'Log In'}
|
|
122
|
+
* </button>
|
|
113
123
|
* </form>
|
|
114
124
|
* ```
|
|
115
125
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAgB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAEpE,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAO5B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAEpE;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,oBAAoB,CAAC,CAAC,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,C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,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"}
|
package/dist/hooks/useForm.js
CHANGED
|
@@ -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) => {
|
|
40
|
+
* const onSubmit = handleSubmit(async (values) => {
|
|
41
|
+
* await login(values)
|
|
42
|
+
* })
|
|
41
43
|
* </script>
|
|
42
44
|
*
|
|
43
45
|
* <form onsubmit={onSubmit}>
|
|
44
|
-
* <input {
|
|
46
|
+
* <input {...register('email', { required: true, email: true })} />
|
|
47
|
+
* {#if $formState.errors.email}<span>{$formState.errors.email}</span>{/if}
|
|
48
|
+
*
|
|
49
|
+
* <input {...register('password', { required: true, minLength: 8 })} type="password" />
|
|
50
|
+
* {#if $formState.errors.password}<span>{$formState.errors.password}</span>{/if}
|
|
51
|
+
*
|
|
52
|
+
* <button type="submit" disabled={$isSubmitting}>
|
|
53
|
+
* {$isSubmitting ? 'Logging in...' : 'Log In'}
|
|
54
|
+
* </button>
|
|
45
55
|
* </form>
|
|
46
56
|
* ```
|
|
47
57
|
*/
|
|
@@ -47,6 +47,8 @@ export interface UseOptimisticToggleResult {
|
|
|
47
47
|
* @example
|
|
48
48
|
* ```svelte
|
|
49
49
|
* <script lang="ts">
|
|
50
|
+
* import { useOptimisticToggle } from '@molecule/app-svelte'
|
|
51
|
+
*
|
|
50
52
|
* const subscription = useOptimisticToggle({
|
|
51
53
|
* value: thread.subscribed,
|
|
52
54
|
* commit: async (desired) => {
|
|
@@ -61,6 +63,8 @@ export interface UseOptimisticToggleResult {
|
|
|
61
63
|
* </script>
|
|
62
64
|
*
|
|
63
65
|
* <button type="button" aria-pressed={$value} aria-busy={$pending} onclick={subscription.toggle}>
|
|
66
|
+
* {$value ? 'Unsubscribe' : 'Subscribe'}
|
|
67
|
+
* </button>
|
|
64
68
|
* ```
|
|
65
69
|
*/
|
|
66
70
|
export declare const useOptimisticToggle: (options: MaybeReadable<UseOptimisticToggleOptions>) => UseOptimisticToggleResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOptimisticToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useOptimisticToggle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAGpE,+CAA+C;AAC/C,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,KAAK,EAAE,OAAO,CAAA;IACd,yFAAyF;IACzF,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9C,0FAA0F;IAC1F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnD;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,2BAA2B;IAC3B,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,4CAA4C;IAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,wCAAwC;IACxC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,0FAA0F;IAC1F,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED
|
|
1
|
+
{"version":3,"file":"useOptimisticToggle.d.ts","sourceRoot":"","sources":["../../src/hooks/useOptimisticToggle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAA;AAErD,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAGpE,+CAA+C;AAC/C,MAAM,WAAW,0BAA0B;IACzC,+EAA+E;IAC/E,KAAK,EAAE,OAAO,CAAA;IACd,yFAAyF;IACzF,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9C,0FAA0F;IAC1F,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAA;CACnD;AAED;;;GAGG;AACH,MAAM,WAAW,yBAAyB;IACxC,2BAA2B;IAC3B,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,4CAA4C;IAC5C,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,wCAAwC;IACxC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;IACxB,0FAA0F;IAC1F,MAAM,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,aAAa,CAAC,0BAA0B,CAAC,KACjD,yBAUF,CAAA"}
|
|
@@ -25,6 +25,8 @@ import { useOptimisticValue } from './useOptimisticValue.js';
|
|
|
25
25
|
* @example
|
|
26
26
|
* ```svelte
|
|
27
27
|
* <script lang="ts">
|
|
28
|
+
* import { useOptimisticToggle } from '@molecule/app-svelte'
|
|
29
|
+
*
|
|
28
30
|
* const subscription = useOptimisticToggle({
|
|
29
31
|
* value: thread.subscribed,
|
|
30
32
|
* commit: async (desired) => {
|
|
@@ -39,6 +41,8 @@ import { useOptimisticValue } from './useOptimisticValue.js';
|
|
|
39
41
|
* </script>
|
|
40
42
|
*
|
|
41
43
|
* <button type="button" aria-pressed={$value} aria-busy={$pending} onclick={subscription.toggle}>
|
|
44
|
+
* {$value ? 'Unsubscribe' : 'Subscribe'}
|
|
45
|
+
* </button>
|
|
42
46
|
* ```
|
|
43
47
|
*/
|
|
44
48
|
export const useOptimisticToggle = (options) => {
|
|
@@ -49,16 +49,32 @@ export interface UseOptimisticValueResult<T> {
|
|
|
49
49
|
* and `set`/`update`.
|
|
50
50
|
* @example
|
|
51
51
|
* ```svelte
|
|
52
|
-
* <script>
|
|
52
|
+
* <script lang="ts">
|
|
53
53
|
* import { useOptimisticValue } from '@molecule/app-svelte'
|
|
54
54
|
* // `value` is the store; the result itself is not, so take the store out to read it with `$`.
|
|
55
55
|
* const { value: star, update } = useOptimisticValue({
|
|
56
56
|
* value: { starred: repository.starred, stars: repository.stars },
|
|
57
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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;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,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAClC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAmEvB"}
|
package/dist/hooks/usePromise.js
CHANGED
|
@@ -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
|
-
*
|
|
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":[],"m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tD;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
|
-
*
|
|
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
|
|
39
|
-
* <button
|
|
43
|
+
* <button onclick={toggleTheme}>Toggle ({$mode})</button>
|
|
44
|
+
* <button onclick={() => logout()}>Logout</button>
|
|
40
45
|
* </div>
|
|
41
46
|
* {/if}
|
|
42
47
|
* ```
|
|
@@ -141,6 +146,7 @@ export * from './context.js';
|
|
|
141
146
|
export * from './hooks/index.js';
|
|
142
147
|
export * from './link/index.js';
|
|
143
148
|
export * from './providers/index.js';
|
|
149
|
+
export * from './routed-view/index.js';
|
|
144
150
|
export * from './session-ready/index.js';
|
|
145
151
|
export * from './stores/index.js';
|
|
146
152
|
export * from './types.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8IG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* ```svelte
|
|
11
11
|
* <!-- +layout.svelte — wire providers ONCE, during component init -->
|
|
12
12
|
* <script lang="ts">
|
|
13
|
+
* import type { Snippet } from 'svelte'
|
|
13
14
|
* import { setMoleculeContext } from '@molecule/app-svelte'
|
|
14
15
|
* import { provider as stateProvider } from '@molecule/app-state-zustand'
|
|
15
16
|
* import { provider as themeProvider } from '@molecule/app-theme-css-variables'
|
|
@@ -20,10 +21,14 @@
|
|
|
20
21
|
* auth: createJWTAuthClient({ baseURL: '/api' }),
|
|
21
22
|
* theme: themeProvider,
|
|
22
23
|
* })
|
|
24
|
+
*
|
|
25
|
+
* let { children }: { children: Snippet } = $props()
|
|
23
26
|
* </script>
|
|
24
27
|
*
|
|
25
|
-
*
|
|
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
|
|
39
|
-
* <button
|
|
43
|
+
* <button onclick={toggleTheme}>Toggle ({$mode})</button>
|
|
44
|
+
* <button onclick={() => logout()}>Logout</button>
|
|
40
45
|
* </div>
|
|
41
46
|
* {/if}
|
|
42
47
|
* ```
|
|
@@ -141,6 +146,7 @@ export * from './context.js';
|
|
|
141
146
|
export * from './hooks/index.js';
|
|
142
147
|
export * from './link/index.js';
|
|
143
148
|
export * from './providers/index.js';
|
|
149
|
+
export * from './routed-view/index.js';
|
|
144
150
|
export * from './session-ready/index.js';
|
|
145
151
|
export * from './stores/index.js';
|
|
146
152
|
export * from './types.js';
|
|
@@ -4,16 +4,24 @@
|
|
|
4
4
|
`{#key servicesKey(services)}`, so a replaced service initializes it again.
|
|
5
5
|
-->
|
|
6
6
|
<script lang="ts">
|
|
7
|
-
import { type Snippet, untrack } from 'svelte'
|
|
7
|
+
import { type Component, type Snippet, untrack } from 'svelte'
|
|
8
8
|
|
|
9
|
+
import { setRoutedViewContext } from '../routed-view-context.js'
|
|
9
10
|
import type { MoleculeConfig } from '../types.js'
|
|
10
11
|
import { setServiceContexts } from './services.js'
|
|
11
12
|
|
|
12
|
-
let {
|
|
13
|
+
let {
|
|
14
|
+
services,
|
|
15
|
+
routedView,
|
|
16
|
+
children,
|
|
17
|
+
}: { services: MoleculeConfig; routedView?: Component | null; children?: Snippet } = $props()
|
|
13
18
|
|
|
14
19
|
// Context is set once, at initialization; the parent's `{#key}` re-creates this
|
|
15
|
-
// component when a service changes.
|
|
16
|
-
untrack(() =>
|
|
20
|
+
// component when a service changes. `routedView` is set only by RouterProvider.
|
|
21
|
+
untrack(() => {
|
|
22
|
+
setServiceContexts(services)
|
|
23
|
+
if (routedView !== undefined) setRoutedViewContext(routedView)
|
|
24
|
+
})
|
|
17
25
|
</script>
|
|
18
26
|
|
|
19
27
|
{@render children?.()}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { type Snippet } from 'svelte';
|
|
1
|
+
import { type Component, type Snippet } from 'svelte';
|
|
2
2
|
import type { MoleculeConfig } from '../types.js';
|
|
3
3
|
type $$ComponentProps = {
|
|
4
4
|
services: MoleculeConfig;
|
|
5
|
+
routedView?: Component | null;
|
|
5
6
|
children?: Snippet;
|
|
6
7
|
};
|
|
7
|
-
declare const Provided:
|
|
8
|
+
declare const Provided: Component<$$ComponentProps, {}, "">;
|
|
8
9
|
type Provided = ReturnType<typeof Provided>;
|
|
9
10
|
export default Provided;
|
|
10
11
|
//# sourceMappingURL=Provided.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provided.svelte.d.ts","sourceRoot":"","sources":["../../src/providers/Provided.svelte"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"Provided.svelte.d.ts","sourceRoot":"","sources":["../../src/providers/Provided.svelte"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,OAAO,EAAW,MAAM,QAAQ,CAAA;AAG9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAGhD,KAAK,gBAAgB,GAAI;IAAE,QAAQ,EAAE,cAAc,CAAC;IAAC,UAAU,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AA2B1G,QAAA,MAAM,QAAQ,qCAAwC,CAAC;AACvD,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC5C,eAAe,QAAQ,CAAC"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
Provider for routing, as @molecule/app-react's RouterProvider
|
|
2
|
+
Provider for routing, as @molecule/app-react's RouterProvider: the router and, from a routing
|
|
3
|
+
bond that has one, the routed view RoutedView renders (none without one).
|
|
3
4
|
-->
|
|
4
5
|
<script lang="ts">
|
|
5
6
|
import type { RouterProviderProps } from '../types.js'
|
|
6
7
|
import Provided from './Provided.svelte'
|
|
7
8
|
|
|
8
|
-
let { router, children }: RouterProviderProps = $props()
|
|
9
|
+
let { router, routedView, children }: RouterProviderProps = $props()
|
|
9
10
|
</script>
|
|
10
11
|
|
|
11
12
|
{#key router}
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
|
|
13
|
+
{#key routedView}
|
|
14
|
+
<Provided services={{ router }} routedView={routedView ?? null}>
|
|
15
|
+
{@render children?.()}
|
|
16
|
+
</Provided>
|
|
17
|
+
{/key}
|
|
15
18
|
{/key}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterProvider.svelte.d.ts","sourceRoot":"","sources":["../../src/providers/RouterProvider.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"RouterProvider.svelte.d.ts","sourceRoot":"","sources":["../../src/providers/RouterProvider.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAqBtD,QAAA,MAAM,cAAc,yDAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Renders the matched child route, as @molecule/app-react's RoutedView, through whichever routing
|
|
3
|
+
bond the app wired. A layout or guard renders it where its page goes when it was given no
|
|
4
|
+
children. It throws when the routing bond has no routed view (SvelteKit gives a layout its page
|
|
5
|
+
as `children`): rendering nothing there would show a blank page with no error.
|
|
6
|
+
-->
|
|
7
|
+
<script lang="ts">
|
|
8
|
+
import { routedViewOrThrow } from '../routed-view-context.js'
|
|
9
|
+
|
|
10
|
+
const View = routedViewOrThrow()
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<View />
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
+
$$bindings?: Bindings;
|
|
4
|
+
} & Exports;
|
|
5
|
+
(internal: unknown, props: {
|
|
6
|
+
$$events?: Events;
|
|
7
|
+
$$slots?: Slots;
|
|
8
|
+
}): Exports & {
|
|
9
|
+
$set?: any;
|
|
10
|
+
$on?: any;
|
|
11
|
+
};
|
|
12
|
+
z_$$bindings?: Bindings;
|
|
13
|
+
}
|
|
14
|
+
declare const RoutedView: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
}, {}, {}, string>;
|
|
17
|
+
type RoutedView = InstanceType<typeof RoutedView>;
|
|
18
|
+
export default RoutedView;
|
|
19
|
+
//# sourceMappingURL=RoutedView.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoutedView.svelte.d.ts","sourceRoot":"","sources":["../../src/routed-view/RoutedView.svelte"],"names":[],"mappings":"AAgBA,UAAU,kCAAkC,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,GAAG,MAAM;IACpM,KAAK,OAAO,EAAE,OAAO,QAAQ,EAAE,2BAA2B,CAAC,KAAK,CAAC,GAAG,OAAO,QAAQ,EAAE,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG;QAAE,UAAU,CAAC,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC;IACjK,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,KAAK,CAAA;KAAC,GAAG,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,GAAG,CAAC;QAAC,GAAG,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IACtG,YAAY,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAKD,QAAA,MAAM,UAAU;;kBAA+E,CAAC;AAC9E,KAAK,UAAU,GAAG,YAAY,CAAC,OAAO,UAAU,CAAC,CAAC;AACpD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/routed-view/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The routed view's Svelte context. Kept out of the package's exports, as in
|
|
3
|
+
* `@molecule/app-react`: a routed view is provided only with a router (`RouterProvider`'s
|
|
4
|
+
* `routedView`, or `setRouterContext(router, { routedView })`).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { Component } from 'svelte';
|
|
9
|
+
/**
|
|
10
|
+
* Sets the component the routing bond renders where the matched child route goes. Call it
|
|
11
|
+
* during component initialization.
|
|
12
|
+
*
|
|
13
|
+
* @param view - The routed view, or `null` when the routing bond has none.
|
|
14
|
+
*/
|
|
15
|
+
export declare function setRoutedViewContext(view: Component | null): void;
|
|
16
|
+
/**
|
|
17
|
+
* The routed view from Svelte context, for `RoutedView`. Call it during component
|
|
18
|
+
* initialization.
|
|
19
|
+
*
|
|
20
|
+
* @returns The routing bond's routed view.
|
|
21
|
+
* @throws {I18nError} When the routing bond has none (SvelteKit gives a layout its page as
|
|
22
|
+
* `children`).
|
|
23
|
+
*/
|
|
24
|
+
export declare function routedViewOrThrow(): Component;
|
|
25
|
+
//# sourceMappingURL=routed-view-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routed-view-context.d.ts","sourceRoot":"","sources":["../src/routed-view-context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAOvC;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAEjE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,IAAI,SAAS,CAU7C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The routed view's Svelte context. Kept out of the package's exports, as in
|
|
3
|
+
* `@molecule/app-react`: a routed view is provided only with a router (`RouterProvider`'s
|
|
4
|
+
* `routedView`, or `setRouterContext(router, { routedView })`).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import { getContext, setContext } from 'svelte';
|
|
9
|
+
import { I18nError } from '@molecule/app-i18n';
|
|
10
|
+
const ROUTED_VIEW_KEY = Symbol('molecule-routed-view');
|
|
11
|
+
/**
|
|
12
|
+
* Sets the component the routing bond renders where the matched child route goes. Call it
|
|
13
|
+
* during component initialization.
|
|
14
|
+
*
|
|
15
|
+
* @param view - The routed view, or `null` when the routing bond has none.
|
|
16
|
+
*/
|
|
17
|
+
export function setRoutedViewContext(view) {
|
|
18
|
+
setContext(ROUTED_VIEW_KEY, view);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The routed view from Svelte context, for `RoutedView`. Call it during component
|
|
22
|
+
* initialization.
|
|
23
|
+
*
|
|
24
|
+
* @returns The routing bond's routed view.
|
|
25
|
+
* @throws {I18nError} When the routing bond has none (SvelteKit gives a layout its page as
|
|
26
|
+
* `children`).
|
|
27
|
+
*/
|
|
28
|
+
export function routedViewOrThrow() {
|
|
29
|
+
const view = getContext(ROUTED_VIEW_KEY);
|
|
30
|
+
if (!view) {
|
|
31
|
+
throw new I18nError('svelte.error.noRoutedView', undefined, 'No routed view here. SvelteKit gives a layout its page as `children`: pass `{@render children()}` inside this component.');
|
|
32
|
+
}
|
|
33
|
+
return view;
|
|
34
|
+
}
|
package/dist/stores/http.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
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>
|
package/dist/stores/http.js
CHANGED
|
@@ -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
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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>
|
package/dist/stores/version.d.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
25
|
-
* <button
|
|
24
|
+
* <button onclick={() => applyUpdate()}>Update</button>
|
|
25
|
+
* <button onclick={dismissUpdate}>Dismiss</button>
|
|
26
26
|
* </div>
|
|
27
27
|
* {/if}
|
|
28
28
|
* ```
|
package/dist/stores/version.js
CHANGED
|
@@ -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 {
|
|
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
|
|
25
|
-
* <button
|
|
24
|
+
* <button onclick={() => applyUpdate()}>Update</button>
|
|
25
|
+
* <button onclick={dismissUpdate}>Dismiss</button>
|
|
26
26
|
* </div>
|
|
27
27
|
* {/if}
|
|
28
28
|
* ```
|
package/dist/types.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import type { Snippet } from 'svelte';
|
|
6
|
+
import type { Component, Snippet } from 'svelte';
|
|
7
7
|
import type { Readable, Writable } from 'svelte/store';
|
|
8
8
|
import type { ChatProvider } from '@molecule/app-ai-chat';
|
|
9
9
|
import type { AuthClient, AuthState } from '@molecule/app-auth';
|
|
@@ -92,6 +92,13 @@ export interface ThemeProviderProps extends ProviderProps {
|
|
|
92
92
|
*/
|
|
93
93
|
export interface RouterProviderProps extends ProviderProps {
|
|
94
94
|
router: Router;
|
|
95
|
+
/**
|
|
96
|
+
* The component that renders the matched child route where a layout or guard puts it, so
|
|
97
|
+
* `<RoutedView />` works under any routing bond. A routing bond passes it; leave it out when
|
|
98
|
+
* the bond has none (SvelteKit gives a layout its page as `children`), and `<RoutedView />`
|
|
99
|
+
* then throws an error saying so.
|
|
100
|
+
*/
|
|
101
|
+
routedView?: Component;
|
|
95
102
|
}
|
|
96
103
|
/**
|
|
97
104
|
* Props for the `I18nProvider` component.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAChD,OA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b,WAAW,EACX,QAAQ,EACR,aAAa,EACb,WAAW,EACX,MAAM,EACN,YAAY,EACZ,KAAK,EACL,WAAW,EACX,KAAK,EACL,QAAQ,GACT,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-svelte",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.11.0",
|
|
4
4
|
"description": "Svelte framework bindings for molecule.dev",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"@molecule/app-platform": "^1.0.1",
|
|
53
53
|
"@molecule/app-push": "^1.0.1",
|
|
54
54
|
"@molecule/app-routing": "^1.4.0",
|
|
55
|
+
"@molecule/app-routing-sveltekit": ">=3.0.0",
|
|
55
56
|
"@molecule/app-state": "^1.2.0",
|
|
56
57
|
"@molecule/app-storage": "^1.1.1",
|
|
57
58
|
"@molecule/app-theme": "^1.0.1",
|
|
@@ -69,6 +70,9 @@
|
|
|
69
70
|
},
|
|
70
71
|
"@molecule/app-live-preview": {
|
|
71
72
|
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"@molecule/app-routing-sveltekit": {
|
|
75
|
+
"optional": true
|
|
72
76
|
}
|
|
73
77
|
},
|
|
74
78
|
"devDependencies": {
|