@molecule/app-svelte 3.13.0 → 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 +62 -5
- package/dist/components/ContentOrElse.svelte +105 -0
- package/dist/components/ContentOrElse.svelte.d.ts +16 -0
- package/dist/components/ContentOrElse.svelte.d.ts.map +1 -0
- package/dist/components/PresentWhileContent.svelte +39 -10
- package/dist/components/PresentWhileContent.svelte.d.ts +6 -4
- package/dist/components/PresentWhileContent.svelte.d.ts.map +1 -1
- package/dist/components/index.d.ts +4 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +4 -1
- package/dist/content.d.ts +13 -0
- package/dist/content.d.ts.map +1 -1
- package/dist/content.js +16 -1
- package/dist/context.d.ts +59 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +42 -4
- package/dist/hooks/useTranslation.d.ts +8 -1
- package/dist/hooks/useTranslation.d.ts.map +1 -1
- package/dist/hooks/useTranslation.js +10 -1
- package/dist/link/Link.svelte +18 -8
- package/dist/link/Link.svelte.d.ts +7 -1
- package/dist/link/Link.svelte.d.ts.map +1 -1
- package/dist/link/types.d.ts +5 -1
- package/dist/link/types.d.ts.map +1 -1
- package/package.json +4 -4
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-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
|
-
/**
|
|
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
|
|
@@ -2825,6 +2829,19 @@ function contentNodes(node: Node): ChildNode[]
|
|
|
2825
2829
|
|
|
2826
2830
|
**Returns:** Those children, in order.
|
|
2827
2831
|
|
|
2832
|
+
#### `isContentNode(node)`
|
|
2833
|
+
|
|
2834
|
+
Whether one node renders something: an element, or a text node with text. Comments and empty
|
|
2835
|
+
text nodes are Svelte's own anchors (and other components' placeholders), not content.
|
|
2836
|
+
|
|
2837
|
+
```typescript
|
|
2838
|
+
function isContentNode(node: Node): boolean
|
|
2839
|
+
```
|
|
2840
|
+
|
|
2841
|
+
- `node` — The node.
|
|
2842
|
+
|
|
2843
|
+
**Returns:** True when it renders something.
|
|
2844
|
+
|
|
2828
2845
|
#### `rendersContent(node)`
|
|
2829
2846
|
|
|
2830
2847
|
Whether a node's children render anything (see {@link contentNodes}). A Svelte component
|
|
@@ -3156,6 +3173,29 @@ function useRouterInstance(): Router
|
|
|
3156
3173
|
|
|
3157
3174
|
**Returns:** The router instance.
|
|
3158
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
|
+
|
|
3159
3199
|
#### `useHttpClient()`
|
|
3160
3200
|
|
|
3161
3201
|
Gets the HTTP client from Svelte context under the React hook's name.
|
|
@@ -4140,6 +4180,17 @@ function useThemeColors(): Readable<Theme['colors']>
|
|
|
4140
4180
|
|
|
4141
4181
|
**Returns:** A readable store of the current theme's colors.
|
|
4142
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
|
+
|
|
4143
4194
|
#### `useTranslation()`
|
|
4144
4195
|
|
|
4145
4196
|
Internationalization, React's `useTranslation` in Svelte's idiom: call it
|
|
@@ -4937,6 +4988,12 @@ function createVersionStores(): {
|
|
|
4937
4988
|
const BodyPortal: LegacyComponentType
|
|
4938
4989
|
```
|
|
4939
4990
|
|
|
4991
|
+
#### `ContentOrElse`
|
|
4992
|
+
|
|
4993
|
+
```typescript
|
|
4994
|
+
const ContentOrElse: LegacyComponentType
|
|
4995
|
+
```
|
|
4996
|
+
|
|
4940
4997
|
#### `PresentWhileContent`
|
|
4941
4998
|
|
|
4942
4999
|
```typescript
|
|
@@ -5149,8 +5206,8 @@ Peer dependencies:
|
|
|
5149
5206
|
- `@molecule/app-device` ^1.0.1
|
|
5150
5207
|
- `@molecule/app-forms` ^2.4.0
|
|
5151
5208
|
- `@molecule/app-http` ^1.0.1
|
|
5152
|
-
- `@molecule/app-i18n` ^1.0
|
|
5153
|
-
- `@molecule/app-ide` ^1.0
|
|
5209
|
+
- `@molecule/app-i18n` ^1.3.0
|
|
5210
|
+
- `@molecule/app-ide` ^1.1.0 _(optional)_
|
|
5154
5211
|
- `@molecule/app-live-preview` ^1.0.1 _(optional)_
|
|
5155
5212
|
- `@molecule/app-logger` ^1.0.1
|
|
5156
5213
|
- `@molecule/app-platform` ^1.0.1
|
|
@@ -5159,7 +5216,7 @@ Peer dependencies:
|
|
|
5159
5216
|
- `@molecule/app-routing-sveltekit` >=3.0.0 _(optional)_
|
|
5160
5217
|
- `@molecule/app-state` ^1.2.0
|
|
5161
5218
|
- `@molecule/app-storage` ^1.1.1
|
|
5162
|
-
- `@molecule/app-theme` ^1.0.
|
|
5219
|
+
- `@molecule/app-theme` ^1.0.2
|
|
5163
5220
|
- `@molecule/app-ui` ^1.0.1
|
|
5164
5221
|
- `@molecule/app-utilities` ^1.0.1
|
|
5165
5222
|
- `@molecule/app-version` ^1.0.1
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
ContentOrElse: its content in the page, with no element of its own, while that content renders
|
|
3
|
+
something (an element, or text), and `otherwise` in its place while it renders nothing. React's
|
|
4
|
+
`slot(emptyState) ? <>{emptyState}</> : <div>…</div>`: a feed's empty state takes the place of
|
|
5
|
+
the feed's element only while it shows something, which a Svelte component cannot decide from a
|
|
6
|
+
snippet's value (an `{#each}` over no rows, an `{#if false}`).
|
|
7
|
+
|
|
8
|
+
The content renders once, between two anchor comments that Svelte owns and moves with this
|
|
9
|
+
component: the blocks of two `svelte:element`s whose elements leave the page as soon as they are
|
|
10
|
+
created. Its components therefore live exactly as long as this component, and nothing else is
|
|
11
|
+
rendered between the two anchors, so the range read is the content's. `otherwise` waits for the
|
|
12
|
+
first decision, made once the content has rendered, so content that shows something at mount
|
|
13
|
+
never creates it; a `MutationObserver` then decides again after every change, in a microtask
|
|
14
|
+
before the browser paints.
|
|
15
|
+
|
|
16
|
+
`bind:present` reports the decision, for an element around the content that another component
|
|
17
|
+
renders (`<PresentWhileContent present={…}>` around a Button whose label is the content: the
|
|
18
|
+
Button's own whitespace is not the label). Use `PresentWhileContent` alone when the content sits
|
|
19
|
+
directly in the element that comes and goes.
|
|
20
|
+
|
|
21
|
+
It is `undefined` until the first decision, so a sibling that renders only while the content
|
|
22
|
+
is empty (`{#if present === false}`) is never created for content that shows something.
|
|
23
|
+
-->
|
|
24
|
+
<script lang="ts">
|
|
25
|
+
import type { Snippet } from 'svelte'
|
|
26
|
+
import type { Attachment } from 'svelte/attachments'
|
|
27
|
+
|
|
28
|
+
import { isContentNode } from '../content.js'
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
children,
|
|
32
|
+
otherwise,
|
|
33
|
+
present = $bindable(),
|
|
34
|
+
}: {
|
|
35
|
+
/** The content; in the page, without a wrapper, while it renders something. */
|
|
36
|
+
children?: Snippet
|
|
37
|
+
/** What renders in the content's place while the content renders nothing. */
|
|
38
|
+
otherwise?: Snippet
|
|
39
|
+
/**
|
|
40
|
+
* Whether the content renders something, read with `bind:present`: `undefined` until the
|
|
41
|
+
* content has rendered and been read once.
|
|
42
|
+
*/
|
|
43
|
+
present?: boolean
|
|
44
|
+
} = $props()
|
|
45
|
+
|
|
46
|
+
/** Whether the content has rendered and been read once. */
|
|
47
|
+
let decided = $state(false)
|
|
48
|
+
/** The anchor comment in front of the content. */
|
|
49
|
+
let start: Node | null = null
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Records the anchor that opens the content's range and takes the marker element out.
|
|
53
|
+
*
|
|
54
|
+
* @param element - The marker element.
|
|
55
|
+
*/
|
|
56
|
+
const markStart: Attachment<HTMLElement> = (element) => {
|
|
57
|
+
start = element.nextSibling
|
|
58
|
+
element.remove()
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Records the anchor that closes the content's range, takes the marker element out, decides,
|
|
63
|
+
* and keeps deciding after every change in the range's parent.
|
|
64
|
+
*
|
|
65
|
+
* @param element - The marker element.
|
|
66
|
+
* @returns The cleanup.
|
|
67
|
+
*/
|
|
68
|
+
const markEnd: Attachment<HTMLElement> = (element) => {
|
|
69
|
+
const end = element.nextSibling
|
|
70
|
+
element.remove()
|
|
71
|
+
const from = start
|
|
72
|
+
if (!from || !end) return
|
|
73
|
+
const sync = (): void => {
|
|
74
|
+
let next = from.nextSibling
|
|
75
|
+
while (next && next !== end && !isContentNode(next)) next = next.nextSibling
|
|
76
|
+
present = !!next && next !== end
|
|
77
|
+
decided = true
|
|
78
|
+
}
|
|
79
|
+
sync()
|
|
80
|
+
// The range is created inside a fragment that Svelte then moves into the page, and a block
|
|
81
|
+
// can move it again: observe whatever parent it has now, and follow it when it changes.
|
|
82
|
+
let observed: Node | null = null
|
|
83
|
+
const observer = new MutationObserver(() => {
|
|
84
|
+
if (from.parentNode !== observed) observe()
|
|
85
|
+
sync()
|
|
86
|
+
})
|
|
87
|
+
const observe = (): void => {
|
|
88
|
+
observer.disconnect()
|
|
89
|
+
observed = from.parentNode
|
|
90
|
+
if (observed)
|
|
91
|
+
observer.observe(observed, { childList: true, characterData: true, subtree: true })
|
|
92
|
+
}
|
|
93
|
+
observe()
|
|
94
|
+
return () => {
|
|
95
|
+
observer.disconnect()
|
|
96
|
+
// Removed, the content renders nothing.
|
|
97
|
+
present = false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
</script>
|
|
101
|
+
|
|
102
|
+
<svelte:element this={"i"} {@attach markStart} />{@render children?.()}<svelte:element
|
|
103
|
+
this={"i"}
|
|
104
|
+
{@attach markEnd}
|
|
105
|
+
/>{#if decided && !present}{@render otherwise?.()}{/if}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
/** The content; in the page, without a wrapper, while it renders something. */
|
|
4
|
+
children?: Snippet;
|
|
5
|
+
/** What renders in the content's place while the content renders nothing. */
|
|
6
|
+
otherwise?: Snippet;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the content renders something, read with `bind:present`: `undefined` until the
|
|
9
|
+
* content has rendered and been read once.
|
|
10
|
+
*/
|
|
11
|
+
present?: boolean;
|
|
12
|
+
};
|
|
13
|
+
declare const ContentOrElse: import("svelte").Component<$$ComponentProps, {}, "present">;
|
|
14
|
+
type ContentOrElse = ReturnType<typeof ContentOrElse>;
|
|
15
|
+
export default ContentOrElse;
|
|
16
|
+
//# sourceMappingURL=ContentOrElse.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContentOrElse.svelte.d.ts","sourceRoot":"","sources":["../../src/components/ContentOrElse.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAKpC,KAAK,gBAAgB,GAAI;IACtB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,6EAA6E;IAC7E,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAC;AA0EJ,QAAA,MAAM,aAAa,6DAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
|
|
@@ -10,24 +10,44 @@
|
|
|
10
10
|
block, so it comes back in its place; a `MutationObserver` on it (which keeps reporting while
|
|
11
11
|
it is out of the page) decides again after every change Svelte makes to the content. The
|
|
12
12
|
observer reports in a microtask, before the browser paints.
|
|
13
|
+
|
|
14
|
+
`present`, when given, decides instead of the element's own content: for content whose
|
|
15
|
+
presence is a node nested in another component (a Button's label, read with
|
|
16
|
+
`<ContentOrElse bind:present>`), where the element always holds that component's markup.
|
|
17
|
+
|
|
18
|
+
One case differs from React: content whose only node is a component that renders nothing
|
|
19
|
+
leaves no node in the page, so the element leaves too, where React's `slot()` counts the
|
|
20
|
+
component's element and keeps an empty wrapper. Neither framework can see what a component
|
|
21
|
+
renders before it renders, and the page holds the same anchors either way.
|
|
13
22
|
-->
|
|
14
23
|
<script lang="ts">
|
|
15
|
-
import type
|
|
24
|
+
import { type Snippet, untrack } from 'svelte'
|
|
16
25
|
import type { Attachment } from 'svelte/attachments'
|
|
17
|
-
import type { HTMLAttributes } from 'svelte/elements'
|
|
26
|
+
import type { HTMLAnchorAttributes, HTMLAttributes } from 'svelte/elements'
|
|
18
27
|
|
|
19
28
|
import { rendersContent } from '../content.js'
|
|
20
29
|
|
|
21
30
|
let {
|
|
22
31
|
tag = 'div',
|
|
23
32
|
children,
|
|
33
|
+
present,
|
|
24
34
|
...attributes
|
|
25
|
-
}: HTMLAttributes<HTMLElement> &
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
}: HTMLAttributes<HTMLElement> &
|
|
36
|
+
// A link's own attributes, for `tag="a"`.
|
|
37
|
+
Pick<
|
|
38
|
+
HTMLAnchorAttributes,
|
|
39
|
+
'href' | 'target' | 'rel' | 'download' | 'hreflang' | 'referrerpolicy'
|
|
40
|
+
> & {
|
|
41
|
+
/** The element's tag; every other prop is an attribute of it. */
|
|
42
|
+
tag?: string
|
|
43
|
+
/** The content; the element is in the page only while it renders something. */
|
|
44
|
+
children?: Snippet
|
|
45
|
+
/** Decides instead of the content when given (see above). */
|
|
46
|
+
present?: boolean
|
|
47
|
+
} = $props()
|
|
48
|
+
|
|
49
|
+
/** Decides again; set while the element exists. */
|
|
50
|
+
let decide: (() => void) | null = null
|
|
31
51
|
|
|
32
52
|
/**
|
|
33
53
|
* Keeps the element in the page exactly while its content renders something.
|
|
@@ -39,7 +59,7 @@
|
|
|
39
59
|
// The block's anchor: Svelte inserts the element in front of it and moves the two together.
|
|
40
60
|
const anchor = element.nextSibling
|
|
41
61
|
const sync = (): void => {
|
|
42
|
-
if (rendersContent(element)) {
|
|
62
|
+
if (untrack(() => present) ?? rendersContent(element)) {
|
|
43
63
|
if (!element.isConnected && anchor?.parentNode)
|
|
44
64
|
anchor.parentNode.insertBefore(element, anchor)
|
|
45
65
|
} else if (element.parentNode) {
|
|
@@ -47,10 +67,19 @@
|
|
|
47
67
|
}
|
|
48
68
|
}
|
|
49
69
|
sync()
|
|
70
|
+
decide = sync
|
|
50
71
|
const observer = new MutationObserver(sync)
|
|
51
72
|
observer.observe(element, { childList: true, characterData: true, subtree: true })
|
|
52
|
-
return () =>
|
|
73
|
+
return () => {
|
|
74
|
+
observer.disconnect()
|
|
75
|
+
decide = null
|
|
76
|
+
}
|
|
53
77
|
}
|
|
78
|
+
|
|
79
|
+
$effect.pre(() => {
|
|
80
|
+
void present
|
|
81
|
+
untrack(() => decide?.())
|
|
82
|
+
})
|
|
54
83
|
</script>
|
|
55
84
|
|
|
56
85
|
<svelte:element this={tag} {...attributes} {@attach presentWhileContent}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
-
type $$ComponentProps = HTMLAttributes<HTMLElement> & {
|
|
4
|
-
/** The element's tag. */
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAnchorAttributes, HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
type $$ComponentProps = HTMLAttributes<HTMLElement> & Pick<HTMLAnchorAttributes, 'href' | 'target' | 'rel' | 'download' | 'hreflang' | 'referrerpolicy'> & {
|
|
4
|
+
/** The element's tag; every other prop is an attribute of it. */
|
|
5
5
|
tag?: string;
|
|
6
6
|
/** The content; the element is in the page only while it renders something. */
|
|
7
7
|
children?: Snippet;
|
|
8
|
+
/** Decides instead of the content when given (see above). */
|
|
9
|
+
present?: boolean;
|
|
8
10
|
};
|
|
9
11
|
declare const PresentWhileContent: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
12
|
type PresentWhileContent = ReturnType<typeof PresentWhileContent>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PresentWhileContent.svelte.d.ts","sourceRoot":"","sources":["../../src/components/PresentWhileContent.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"PresentWhileContent.svelte.d.ts","sourceRoot":"","sources":["../../src/components/PresentWhileContent.svelte"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAW,MAAM,QAAQ,CAAA;AAE9C,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAI1E,KAAK,gBAAgB,GAAI,cAAc,CAAC,WAAW,CAAC,GAEjD,IAAI,CACF,oBAAoB,EACpB,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,UAAU,GAAG,gBAAgB,CACvE,GAAG;IACF,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAC;AAwDN,QAAA,MAAM,mBAAmB,sDAAwC,CAAC;AAClE,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAClE,eAAe,mBAAmB,CAAC"}
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
* The components that are not tied to one service: `BodyPortal`, React's
|
|
3
3
|
* `createPortal` for `document.body`, as a Svelte component, and
|
|
4
4
|
* `PresentWhileContent`, an element in the page only while its content renders
|
|
5
|
-
* something (React's `slot(children) !== undefined && <div>…</div>`)
|
|
5
|
+
* something (React's `slot(children) !== undefined && <div>…</div>`), and
|
|
6
|
+
* `ContentOrElse`, its content alone while it renders something and `otherwise` in
|
|
7
|
+
* its place while it does not (React's `slot(node) ? <>{node}</> : <div>…</div>`).
|
|
6
8
|
*
|
|
7
9
|
* @module
|
|
8
10
|
*/
|
|
9
11
|
export { default as BodyPortal } from './BodyPortal.svelte';
|
|
12
|
+
export { default as ContentOrElse } from './ContentOrElse.svelte';
|
|
10
13
|
export { default as PresentWhileContent } from './PresentWhileContent.svelte';
|
|
11
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAA"}
|
package/dist/components/index.js
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
* The components that are not tied to one service: `BodyPortal`, React's
|
|
3
3
|
* `createPortal` for `document.body`, as a Svelte component, and
|
|
4
4
|
* `PresentWhileContent`, an element in the page only while its content renders
|
|
5
|
-
* something (React's `slot(children) !== undefined && <div>…</div>`)
|
|
5
|
+
* something (React's `slot(children) !== undefined && <div>…</div>`), and
|
|
6
|
+
* `ContentOrElse`, its content alone while it renders something and `otherwise` in
|
|
7
|
+
* its place while it does not (React's `slot(node) ? <>{node}</> : <div>…</div>`).
|
|
6
8
|
*
|
|
7
9
|
* @module
|
|
8
10
|
*/
|
|
9
11
|
export { default as BodyPortal } from './BodyPortal.svelte';
|
|
12
|
+
export { default as ContentOrElse } from './ContentOrElse.svelte';
|
|
10
13
|
export { default as PresentWhileContent } from './PresentWhileContent.svelte';
|
package/dist/content.d.ts
CHANGED
|
@@ -18,6 +18,19 @@
|
|
|
18
18
|
* @returns Those children, in order.
|
|
19
19
|
*/
|
|
20
20
|
export declare function contentNodes(node: Node): ChildNode[];
|
|
21
|
+
/**
|
|
22
|
+
* Whether one node renders something: an element, or a text node with text. Comments and empty
|
|
23
|
+
* text nodes are Svelte's own anchors (and other components' placeholders), not content.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* isContentNode(document.createComment('')) // false
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param node - The node.
|
|
31
|
+
* @returns True when it renders something.
|
|
32
|
+
*/
|
|
33
|
+
export declare function isContentNode(node: Node): boolean;
|
|
21
34
|
/**
|
|
22
35
|
* Whether a node's children render anything (see {@link contentNodes}). A Svelte component
|
|
23
36
|
* cannot tell from a snippet's value whether it renders anything (`{#each}` over no rows,
|
package/dist/content.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,CAEpD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAEjD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAElD"}
|
package/dist/content.js
CHANGED
|
@@ -18,7 +18,22 @@
|
|
|
18
18
|
* @returns Those children, in order.
|
|
19
19
|
*/
|
|
20
20
|
export function contentNodes(node) {
|
|
21
|
-
return Array.from(node.childNodes).filter(
|
|
21
|
+
return Array.from(node.childNodes).filter(isContentNode);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether one node renders something: an element, or a text node with text. Comments and empty
|
|
25
|
+
* text nodes are Svelte's own anchors (and other components' placeholders), not content.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* isContentNode(document.createComment('')) // false
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param node - The node.
|
|
33
|
+
* @returns True when it renders something.
|
|
34
|
+
*/
|
|
35
|
+
export function isContentNode(node) {
|
|
36
|
+
return node.nodeType === 1 || (node.nodeType === 3 && (node.textContent ?? '') !== '');
|
|
22
37
|
}
|
|
23
38
|
/**
|
|
24
39
|
* Whether a node's children render anything (see {@link contentNodes}). A Svelte component
|
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
|
|
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.
|
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;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;
|
|
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;AAEvC,OAAO,EAAO,KAAK,QAAQ,EAAY,MAAM,cAAc,CAAA;AAE3D,OAAO,KAAK,EAAE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
|
|
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
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG;IAC7C,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAA;CACxE,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,CAAA;IACpB,8BAA8B;IAC9B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxB,kCAAkC;IAClC,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC,CAAA;IACpC,8BAA8B;IAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IACzD,8CAA8C;IAC9C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,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,MAAM,CAAA;CACxE,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,CAAC,EAAE,YAAY,CAAC,GAAG,CAAC,CAAA;IACpB,8BAA8B;IAC9B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxB,kCAAkC;IAClC,SAAS,EAAE,YAAY,CAAC,WAAW,CAAC,CAAA;IACpC,8BAA8B;IAC9B,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IACzD,8CAA8C;IAC9C,YAAY,EAAE,YAAY,CAAC,cAAc,CAAC,CAAA;IAC1C,4CAA4C;IAC5C,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC,CAAA;IACtC,0CAA0C;IAC1C,SAAS,EAAE,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,CAAA;CACnC;AAqDD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,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"}
|
|
@@ -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`.
|
package/dist/link/Link.svelte
CHANGED
|
@@ -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`,
|
|
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 {
|
|
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
|
-
|
|
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
|
|
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`,
|
|
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;
|
|
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"}
|
package/dist/link/types.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
package/dist/link/types.d.ts.map
CHANGED
|
@@ -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
|
|
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.
|
|
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
|
|
49
|
-
"@molecule/app-ide": "^1.0
|
|
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.
|
|
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",
|