@molecule/app-svelte 3.14.1 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-11-24T00:46:18.586Z
6
+ Generated: 2026-11-25T04:39:31.578Z
7
7
  -->
8
8
 
9
9
  # @molecule/app-svelte
@@ -2210,7 +2210,11 @@ Props for `Link`. Every other anchor attribute (`class`, `target`, `rel`,
2210
2210
 
2211
2211
  ```typescript
2212
2212
  interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children'> {
2213
- /** Destination: an app path (`/settings?tab=billing#plan`) or a URL. An app path's `href` is the one the router writes for it (`routerLinkHref`), base path included. */
2213
+ /**
2214
+ * Destination: an app path (`/settings?tab=billing#plan`) or a URL. An app path's `href` is the
2215
+ * one the router writes for it (`routerLinkHref`), base path included; a URL's is the URL as
2216
+ * written.
2217
+ */
2214
2218
  to: string
2215
2219
  /**
2216
2220
  * Replace the current history entry instead of pushing one. When omitted, a
@@ -3169,6 +3173,29 @@ function useRouterInstance(): Router
3169
3173
 
3170
3174
  **Returns:** The router instance.
3171
3175
 
3176
+ #### `useLinkRouter(path)`
3177
+
3178
+ The router a link navigates through, under React's hook name: the router set
3179
+ in context, or `null` for a URL outside the app when none is. The browser, or
3180
+ on a device the URL handler, opens such a URL, so a link to it renders in an
3181
+ app with no router (a widget, a static page). A link to an app path still
3182
+ fails without one: that is how an app that forgot to mount its router finds
3183
+ out.
3184
+
3185
+ `Link` uses it. With a destination it answers for that one and follows it
3186
+ while the component lives. Without one (the destination is a `$state` prop of
3187
+ a runes component, which is no store) it returns a function to call with the
3188
+ destination wherever it is known; call it during component initialisation,
3189
+ which reads the context once.
3190
+
3191
+ ```typescript
3192
+ function useLinkRouter(path: MaybeReadable<string>): Readable<Router | null>
3193
+ ```
3194
+
3195
+ - `path` — The link's destination: an app path or a URL, or a readable store of one.
3196
+
3197
+ **Returns:** A readable store of the router the link navigates through, or `null` for a URL outside the app with no router in context.
3198
+
3172
3199
  #### `useHttpClient()`
3173
3200
 
3174
3201
  Gets the HTTP client from Svelte context under the React hook's name.
@@ -4153,6 +4180,17 @@ function useThemeColors(): Readable<Theme['colors']>
4153
4180
 
4154
4181
  **Returns:** A readable store of the current theme's colors.
4155
4182
 
4183
+ #### `useRichTranslation()`
4184
+
4185
+ Reads rich catalog messages from the active provider. Call the returned
4186
+ translation function in render so it follows locale and catalog changes.
4187
+
4188
+ ```typescript
4189
+ function useRichTranslation(): RichTranslateFunction
4190
+ ```
4191
+
4192
+ **Returns:** The locale-reactive rich translation function.
4193
+
4156
4194
  #### `useTranslation()`
4157
4195
 
4158
4196
  Internationalization, React's `useTranslation` in Svelte's idiom: call it
@@ -5168,8 +5206,8 @@ Peer dependencies:
5168
5206
  - `@molecule/app-device` ^1.0.1
5169
5207
  - `@molecule/app-forms` ^2.4.0
5170
5208
  - `@molecule/app-http` ^1.0.1
5171
- - `@molecule/app-i18n` ^1.0.1
5172
- - `@molecule/app-ide` ^1.0.1 _(optional)_
5209
+ - `@molecule/app-i18n` ^1.3.0
5210
+ - `@molecule/app-ide` ^1.1.0 _(optional)_
5173
5211
  - `@molecule/app-live-preview` ^1.0.1 _(optional)_
5174
5212
  - `@molecule/app-logger` ^1.0.1
5175
5213
  - `@molecule/app-platform` ^1.0.1
@@ -5178,7 +5216,7 @@ Peer dependencies:
5178
5216
  - `@molecule/app-routing-sveltekit` >=3.0.0 _(optional)_
5179
5217
  - `@molecule/app-state` ^1.2.0
5180
5218
  - `@molecule/app-storage` ^1.1.1
5181
- - `@molecule/app-theme` ^1.0.1
5219
+ - `@molecule/app-theme` ^1.0.2
5182
5220
  - `@molecule/app-ui` ^1.0.1
5183
5221
  - `@molecule/app-utilities` ^1.0.1
5184
5222
  - `@molecule/app-version` ^1.0.1
package/dist/context.d.ts CHANGED
@@ -4,6 +4,7 @@
4
4
  * @module
5
5
  */
6
6
  import type { Component } from 'svelte';
7
+ import { type Readable } from 'svelte/store';
7
8
  import type { ChatProvider } from '@molecule/app-ai-chat';
8
9
  import type { AuthClient, RegisterExtraShape } from '@molecule/app-auth';
9
10
  import type { EditorProvider } from '@molecule/app-code-editor';
@@ -12,10 +13,11 @@ import type { I18nProvider } from '@molecule/app-i18n';
12
13
  import type { WorkspaceProvider } from '@molecule/app-ide';
13
14
  import type { PreviewProvider } from '@molecule/app-live-preview';
14
15
  import type { LoggerProvider } from '@molecule/app-logger';
15
- import type { Router } from '@molecule/app-routing';
16
+ import { type Router } from '@molecule/app-routing';
16
17
  import { type StateProvider } from '@molecule/app-state';
17
18
  import type { StorageProvider } from '@molecule/app-storage';
18
19
  import type { ThemeProvider } from '@molecule/app-theme';
20
+ import { type MaybeReadable } from './hooks/maybe-readable.js';
19
21
  import type { MoleculeConfig } from './types.js';
20
22
  /**
21
23
  * Set all molecule providers in Svelte context.
@@ -218,6 +220,62 @@ export declare function useThemeProvider(): ThemeProvider;
218
220
  * `MoleculeRouterProvider` in the root `+layout.svelte`, or call `setMoleculeContext({ router })`.
219
221
  */
220
222
  export declare function useRouterInstance(): Router;
223
+ /**
224
+ * The router a link navigates through, under React's hook name: the router set
225
+ * in context, or `null` for a URL outside the app when none is. The browser, or
226
+ * on a device the URL handler, opens such a URL, so a link to it renders in an
227
+ * app with no router (a widget, a static page). A link to an app path still
228
+ * fails without one: that is how an app that forgot to mount its router finds
229
+ * out.
230
+ *
231
+ * `Link` uses it. With a destination it answers for that one and follows it
232
+ * while the component lives. Without one (the destination is a `$state` prop of
233
+ * a runes component, which is no store) it returns a function to call with the
234
+ * destination wherever it is known; call it during component initialisation,
235
+ * which reads the context once.
236
+ *
237
+ * @param path - The link's destination: an app path or a URL, or a readable store of one.
238
+ * @returns A readable store of the router the link navigates through, or `null` for a URL
239
+ * outside the app with no router in context.
240
+ * @throws {I18nError} When `path` is an app path and no router is in context: the error
241
+ * {@link useRouterInstance} throws, with the same fix.
242
+ *
243
+ * @example
244
+ * ```svelte
245
+ * <script lang="ts">
246
+ * import type { Snippet } from 'svelte'
247
+ * import { writable } from 'svelte/store'
248
+ *
249
+ * import { routerLinkHref } from '@molecule/app-routing'
250
+ * import { useLinkRouter } from '@molecule/app-svelte'
251
+ *
252
+ * let { children }: { children?: Snippet } = $props()
253
+ * const to = writable('/settings')
254
+ * const router = useLinkRouter(to)
255
+ * </script>
256
+ *
257
+ * <a href={$router === null ? $to : routerLinkHref($to, $router)}>{@render children?.()}</a>
258
+ * ```
259
+ */
260
+ export declare function useLinkRouter(path: MaybeReadable<string>): Readable<Router | null>;
261
+ /**
262
+ * Reads the router without a destination yet.
263
+ *
264
+ * @returns A function that takes a link's destination and gives the router it
265
+ * navigates through, or `null` for a URL outside the app with no router in context.
266
+ * @throws {I18nError} Never here: the returned function throws for an app path with no router in
267
+ * context, the error {@link useRouterInstance} throws.
268
+ *
269
+ * @example
270
+ * ```svelte
271
+ * <script lang="ts">
272
+ * const linkRouter = useLinkRouter()
273
+ * let { to } = $props()
274
+ * const router = $derived(linkRouter(to))
275
+ * </script>
276
+ * ```
277
+ */
278
+ export declare function useLinkRouter(): (to: string) => Router | null;
221
279
  /**
222
280
  * Gets the HTTP client from Svelte context under the React hook's name.
223
281
  * @returns The HTTP client instance.
@@ -1 +1 @@
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,OAA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AAO,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;AAsBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAeD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;AACnF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,IAAI,CAAC,EAAE,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAA;AAc9D;;;;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
@@ -3,9 +3,12 @@
3
3
  *
4
4
  * @module
5
5
  */
6
- import { getContext, setContext } from 'svelte';
6
+ import { getContext, onDestroy, setContext } from 'svelte';
7
+ import { get, writable } from 'svelte/store';
7
8
  import { getProvider as getBondedI18nProvider, I18nError, t } from '@molecule/app-i18n';
9
+ import { resolveLinkPath } from '@molecule/app-routing';
8
10
  import { getProvider as getBondedStateProvider, hasProvider as hasBondedStateProvider, } from '@molecule/app-state';
11
+ import { toReadable } from './hooks/maybe-readable.js';
9
12
  import { setRoutedViewContext } from './routed-view-context.js';
10
13
  // Context keys
11
14
  const STATE_KEY = Symbol('molecule-state');
@@ -366,6 +369,21 @@ export function useThemeProvider() {
366
369
  }));
367
370
  return provider;
368
371
  }
372
+ /**
373
+ * The router the router-reading functions and `Link` navigate through: the one
374
+ * set in context. Both {@link useRouterInstance} and {@link useLinkRouter} fail
375
+ * through this one function, so the error and its text live in one place.
376
+ *
377
+ * @param router - The router read from context, or `undefined` with none set.
378
+ * @returns The router.
379
+ * @throws {I18nError} If no router has been set in context: mount the routing bond's
380
+ * `MoleculeRouterProvider` in the root `+layout.svelte`, or call `setMoleculeContext({ router })`.
381
+ */
382
+ function requireRouter(router) {
383
+ if (!router)
384
+ 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`).');
385
+ return router;
386
+ }
369
387
  /**
370
388
  * Gets the router from Svelte context under the React hook's name.
371
389
  * @returns The router instance.
@@ -373,9 +391,29 @@ export function useThemeProvider() {
373
391
  * `MoleculeRouterProvider` in the root `+layout.svelte`, or call `setMoleculeContext({ router })`.
374
392
  */
375
393
  export function useRouterInstance() {
376
- const router = getContext(ROUTER_KEY);
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. If the app already does this, its routing bond is older than this binding: update it (`npm install @molecule/app-routing-sveltekit@latest`).');
394
+ return requireRouter(getContext(ROUTER_KEY));
395
+ }
396
+ /**
397
+ * The router a link to `to` navigates through, among the routers in context.
398
+ *
399
+ * @param mounted - The router read from context, or `undefined` with none set.
400
+ * @param to - The link's destination: an app path or a URL.
401
+ * @returns The router, or `null` for a URL outside the app with none set.
402
+ * @throws {I18nError} When `to` is an app path and no router is in context.
403
+ */
404
+ function linkRouter(mounted, to) {
405
+ // A URL outside the app opens through the browser or the device's URL handler: no router navigates it.
406
+ return resolveLinkPath(to) === null ? (mounted ?? null) : requireRouter(mounted);
407
+ }
408
+ export function useLinkRouter(path) {
409
+ const mounted = getContext(ROUTER_KEY);
410
+ if (path === undefined)
411
+ return (to) => linkRouter(mounted, to);
412
+ const pathStore = toReadable(path);
413
+ // Read now, so an app path with no router in context fails during initialisation, as a hook that needs a provider does.
414
+ const router = writable(linkRouter(mounted, get(pathStore)));
415
+ const stop = pathStore.subscribe((to) => router.set(linkRouter(mounted, to)));
416
+ onDestroy(stop);
379
417
  return router;
380
418
  }
381
419
  /**
@@ -6,8 +6,15 @@
6
6
  * @module
7
7
  */
8
8
  import { type Readable } from 'svelte/store';
9
- import type { I18nProvider, TranslateOptions } from '@molecule/app-i18n';
9
+ import type { I18nProvider, RichTranslateFunction, TranslateOptions } from '@molecule/app-i18n';
10
10
  import { type MaybeReadable } from './maybe-readable.js';
11
+ /**
12
+ * Reads rich catalog messages from the active provider. Call the returned
13
+ * translation function in render so it follows locale and catalog changes.
14
+ *
15
+ * @returns The locale-reactive rich translation function.
16
+ */
17
+ export declare function useRichTranslation(): RichTranslateFunction;
11
18
  /**
12
19
  * Options for the shorthand form of {@link UseTFunction}: the fallback text
13
20
  * is passed positionally, so only `count` remains here.
@@ -1 +1 @@
1
- {"version":3,"file":"useTranslation.d.ts","sourceRoot":"","sources":["../../src/hooks/useTranslation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAsB,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE1E,OAAO,KAAK,EAEV,YAAY,EAGZ,gBAAgB,EACjB,MAAM,oBAAoB,CAAA;AAI3B,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,qBAAqB,CAAA;AAEpE;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAA;AAEzE;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAA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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"}
@@ -7,9 +7,18 @@
7
7
  */
8
8
  import { onDestroy } from 'svelte';
9
9
  import { derived, fromStore, writable } from 'svelte/store';
10
- import { I18nError } from '@molecule/app-i18n';
10
+ import { createRichTranslator, I18nError } from '@molecule/app-i18n';
11
11
  import { useI18nProvider } from '../context.js';
12
12
  import { toReadable } from './maybe-readable.js';
13
+ /**
14
+ * Reads rich catalog messages from the active provider. Call the returned
15
+ * translation function in render so it follows locale and catalog changes.
16
+ *
17
+ * @returns The locale-reactive rich translation function.
18
+ */
19
+ export function useRichTranslation() {
20
+ return createRichTranslator(useT());
21
+ }
13
22
  /**
14
23
  * Subscribes the calling component to the provider's locale notifications,
15
24
  * like React's `useLocaleSnapshot`.
@@ -3,13 +3,19 @@
3
3
  An `<a href={to}>` that navigates in-app through the molecule router, with
4
4
  react-router `<Link>`'s rules (`followRouterLink` from `@molecule/app-routing`):
5
5
  a plain primary click navigates without a page load; a ctrl/cmd, shift or alt
6
- click, a `target` other than `_self`, a click an `onclick` already prevented,
6
+ click, a `target` other than `_self`, an `onclick` already prevented,
7
7
  and a URL on another origin are left to the browser.
8
+
9
+ A link to a URL outside the app (another origin, `mailto:`, `//host`) needs
10
+ no router: the browser, or on a device the URL handler, opens it. It renders
11
+ with no router in context, the URL as its `href`, and a click is left to the
12
+ browser (`onclick` still runs). A link to an app path needs a router, and
13
+ fails without one with the error `useRouterInstance` throws.
8
14
  -->
9
15
  <script lang="ts">
10
16
  import { followRouterLink, routerLinkHref } from '@molecule/app-routing'
11
17
 
12
- import { useRouterInstance } from '../context.js'
18
+ import { useLinkRouter } from '../context.js'
13
19
  import type { LinkProps } from './types.js'
14
20
 
15
21
  let {
@@ -22,11 +28,17 @@
22
28
  ...anchor
23
29
  }: LinkProps = $props()
24
30
 
25
- const router = useRouterInstance()
31
+ /** Reads the router a destination needs: none for a URL outside the app with no router in context. */
32
+ const linkRouter = useLinkRouter()
33
+ /** The router this link follows: `null` when the browser opens the destination instead. */
34
+ const router = $derived(linkRouter(to))
35
+ /** The anchor's `href`: the URL as written when no router is in context, else the one the router writes. */
36
+ const href = $derived(router === null ? to : routerLinkHref(to, router))
26
37
 
27
38
  /**
28
39
  * Runs the caller's `onclick`, then navigates in-app for a click the router
29
- * should take.
40
+ * should take. With no router (a URL outside the app) the browser follows the
41
+ * anchor instead.
30
42
  *
31
43
  * @param event - The anchor's click event.
32
44
  */
@@ -34,10 +46,8 @@
34
46
  event: MouseEvent & { currentTarget: EventTarget & HTMLAnchorElement },
35
47
  ): void {
36
48
  onclick?.(event)
37
- followRouterLink(event, to, router, { replace, state })
49
+ if (router !== null) followRouterLink(event, to, router, { replace, state })
38
50
  }
39
51
  </script>
40
52
 
41
- <a {...anchor} bind:this={ref} href={routerLinkHref(to, router)} onclick={handleClick}
42
- >{@render children?.()}</a
43
- >
53
+ <a {...anchor} bind:this={ref} {href} onclick={handleClick}>{@render children?.()}</a>
@@ -3,8 +3,14 @@ import type { LinkProps } from './types.js';
3
3
  * An `<a href={to}>` that navigates in-app through the molecule router, with
4
4
  * react-router `<Link>`'s rules (`followRouterLink` from `@molecule/app-routing`):
5
5
  * a plain primary click navigates without a page load; a ctrl/cmd, shift or alt
6
- * click, a `target` other than `_self`, a click an `onclick` already prevented,
6
+ * click, a `target` other than `_self`, an `onclick` already prevented,
7
7
  * and a URL on another origin are left to the browser.
8
+ *
9
+ * A link to a URL outside the app (another origin, `mailto:`, `//host`) needs
10
+ * no router: the browser, or on a device the URL handler, opens it. It renders
11
+ * with no router in context, the URL as its `href`, and a click is left to the
12
+ * browser (`onclick` still runs). A link to an app path needs a router, and
13
+ * fails without one with the error `useRouterInstance` throws.
8
14
  */
9
15
  declare const Link: import("svelte").Component<LinkProps, {}, "ref">;
10
16
  type Link = ReturnType<typeof Link>;
@@ -1 +1 @@
1
- {"version":3,"file":"Link.svelte.d.ts","sourceRoot":"","sources":["../../src/link/Link.svelte"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAuC5C;;;;;;GAMG;AACH,QAAA,MAAM,IAAI,kDAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
1
+ {"version":3,"file":"Link.svelte.d.ts","sourceRoot":"","sources":["../../src/link/Link.svelte"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA6C5C;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,IAAI,kDAAwC,CAAC;AACnD,KAAK,IAAI,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AACpC,eAAe,IAAI,CAAC"}
@@ -10,7 +10,11 @@ import type { HTMLAnchorAttributes } from 'svelte/elements';
10
10
  * `aria-*`, `data-*`, `onclick`) goes on the anchor.
11
11
  */
12
12
  export interface LinkProps extends Omit<HTMLAnchorAttributes, 'href' | 'children'> {
13
- /** Destination: an app path (`/settings?tab=billing#plan`) or a URL. An app path's `href` is the one the router writes for it (`routerLinkHref`), base path included. */
13
+ /**
14
+ * Destination: an app path (`/settings?tab=billing#plan`) or a URL. An app path's `href` is the
15
+ * one the router writes for it (`routerLinkHref`), base path included; a URL's is the URL as
16
+ * written.
17
+ */
14
18
  to: string;
15
19
  /**
16
20
  * Replace the current history entry instead of pushing one. When omitted, a
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/link/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,UAAU,CAAC;IAChF,yKAAyK;IACzK,EAAE,EAAE,MAAM,CAAA;IACV;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,sEAAsE;IACtE,GAAG,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAC/B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/link/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAE3D;;;GAGG;AACH,MAAM,WAAW,SAAU,SAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,UAAU,CAAC;IAChF;;;;OAIG;IACH,EAAE,EAAE,MAAM,CAAA;IACV;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gFAAgF;IAChF,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,sEAAsE;IACtE,GAAG,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAA;CAC/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-svelte",
3
- "version": "3.14.1",
3
+ "version": "3.16.0",
4
4
  "description": "Svelte framework bindings for molecule.dev",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -45,8 +45,8 @@
45
45
  "@molecule/app-device": "^1.0.1",
46
46
  "@molecule/app-forms": "^2.4.0",
47
47
  "@molecule/app-http": "^1.0.1",
48
- "@molecule/app-i18n": "^1.0.1",
49
- "@molecule/app-ide": "^1.0.1",
48
+ "@molecule/app-i18n": "^1.3.0",
49
+ "@molecule/app-ide": "^1.1.0",
50
50
  "@molecule/app-live-preview": "^1.0.1",
51
51
  "@molecule/app-logger": "^1.0.1",
52
52
  "@molecule/app-platform": "^1.0.1",
@@ -55,7 +55,7 @@
55
55
  "@molecule/app-routing-sveltekit": ">=3.0.0",
56
56
  "@molecule/app-state": "^1.2.0",
57
57
  "@molecule/app-storage": "^1.1.1",
58
- "@molecule/app-theme": "^1.0.1",
58
+ "@molecule/app-theme": "^1.0.2",
59
59
  "@molecule/app-ui": "^1.0.1",
60
60
  "@molecule/app-utilities": "^1.0.1",
61
61
  "@molecule/app-version": "^1.0.1",