@molecule/app-svelte 3.11.0 → 3.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -4
- package/dist/components/BodyPortal.svelte +43 -0
- package/dist/components/BodyPortal.svelte.d.ts +11 -0
- package/dist/components/BodyPortal.svelte.d.ts.map +1 -0
- package/dist/components/PortalContent.svelte +12 -0
- package/dist/components/PortalContent.svelte.d.ts +8 -0
- package/dist/components/PortalContent.svelte.d.ts.map +1 -0
- package/dist/components/PresentWhileContent.svelte +58 -0
- package/dist/components/PresentWhileContent.svelte.d.ts +12 -0
- package/dist/components/PresentWhileContent.svelte.d.ts.map +1 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +10 -0
- package/dist/content.d.ts +37 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +40 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-11-
|
|
6
|
+
Generated: 2026-11-23T19:31:56.893Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-svelte
|
|
@@ -135,6 +135,15 @@ then consume services anywhere below via store factories
|
|
|
135
135
|
>
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
+
```svelte
|
|
139
|
+
<!-- PortaledNode.svelte — content in document.body, exactly as React renders it -->
|
|
140
|
+
<script lang="ts">
|
|
141
|
+
import { BodyPortal } from '@molecule/app-svelte'
|
|
142
|
+
</script>
|
|
143
|
+
|
|
144
|
+
<BodyPortal><div role="dialog">…</div></BodyPortal>
|
|
145
|
+
```
|
|
146
|
+
|
|
138
147
|
Session state is a three-way decision, not a boolean: `status === 'loading'`
|
|
139
148
|
is undecided, so wait for it and redirect only on
|
|
140
149
|
`status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
|
|
@@ -1041,8 +1050,8 @@ interface Router {
|
|
|
1041
1050
|
* link, the back button, `navigate`), with the new location and the navigation action.
|
|
1042
1051
|
* A router calls it before the browser paints the new page, so a component that renders
|
|
1043
1052
|
* from a listener (the framework bindings' `useLocation` and `useParams` do) shows the new
|
|
1044
|
-
* location in the same paint as the new page.
|
|
1045
|
-
*
|
|
1053
|
+
* location in the same paint as the new page. Molecule's router conformance tests check
|
|
1054
|
+
* that at every paint.
|
|
1046
1055
|
*
|
|
1047
1056
|
* @param listener - Called with the new location and the navigation action.
|
|
1048
1057
|
* @returns Stops calling `listener`.
|
|
@@ -2802,6 +2811,36 @@ type SignupStore<T = unknown> = PromiseStore<AuthResult<T>, [RegisterData]>
|
|
|
2802
2811
|
|
|
2803
2812
|
### Functions
|
|
2804
2813
|
|
|
2814
|
+
#### `contentNodes(node)`
|
|
2815
|
+
|
|
2816
|
+
The children of a node that render something: elements, and text nodes with text. Comments
|
|
2817
|
+
and empty text nodes are Svelte's own anchors (and other components' placeholders), not
|
|
2818
|
+
content.
|
|
2819
|
+
|
|
2820
|
+
```typescript
|
|
2821
|
+
function contentNodes(node: Node): ChildNode[]
|
|
2822
|
+
```
|
|
2823
|
+
|
|
2824
|
+
- `node` — The node whose children are read.
|
|
2825
|
+
|
|
2826
|
+
**Returns:** Those children, in order.
|
|
2827
|
+
|
|
2828
|
+
#### `rendersContent(node)`
|
|
2829
|
+
|
|
2830
|
+
Whether a node's children render anything (see {@link contentNodes}). A Svelte component
|
|
2831
|
+
cannot tell from a snippet's value whether it renders anything (`{#each}` over no rows,
|
|
2832
|
+
`{#if false}`), so a component that renders a wrapper only while its content has something to
|
|
2833
|
+
show, as React's `slot(children) !== undefined && <div>…</div>` does, asks the rendered DOM
|
|
2834
|
+
instead (see `PresentWhileContent`).
|
|
2835
|
+
|
|
2836
|
+
```typescript
|
|
2837
|
+
function rendersContent(node: Node): boolean
|
|
2838
|
+
```
|
|
2839
|
+
|
|
2840
|
+
- `node` — The node whose children are read.
|
|
2841
|
+
|
|
2842
|
+
**Returns:** True when one of them renders something.
|
|
2843
|
+
|
|
2805
2844
|
#### `setMoleculeContext(config)`
|
|
2806
2845
|
|
|
2807
2846
|
Set all molecule providers in Svelte context.
|
|
@@ -4892,6 +4931,18 @@ function createVersionStores(): {
|
|
|
4892
4931
|
|
|
4893
4932
|
### Constants
|
|
4894
4933
|
|
|
4934
|
+
#### `BodyPortal`
|
|
4935
|
+
|
|
4936
|
+
```typescript
|
|
4937
|
+
const BodyPortal: LegacyComponentType
|
|
4938
|
+
```
|
|
4939
|
+
|
|
4940
|
+
#### `PresentWhileContent`
|
|
4941
|
+
|
|
4942
|
+
```typescript
|
|
4943
|
+
const PresentWhileContent: LegacyComponentType
|
|
4944
|
+
```
|
|
4945
|
+
|
|
4895
4946
|
#### `Link`
|
|
4896
4947
|
|
|
4897
4948
|
```typescript
|
|
@@ -5112,7 +5163,7 @@ Peer dependencies:
|
|
|
5112
5163
|
- `@molecule/app-ui` ^1.0.1
|
|
5113
5164
|
- `@molecule/app-utilities` ^1.0.1
|
|
5114
5165
|
- `@molecule/app-version` ^1.0.1
|
|
5115
|
-
- `svelte` ^5.
|
|
5166
|
+
- `svelte` ^5.43.15
|
|
5116
5167
|
|
|
5117
5168
|
### Runtime Dependencies
|
|
5118
5169
|
|
|
@@ -5151,6 +5202,10 @@ Peer dependencies:
|
|
|
5151
5202
|
- In-app links are `Link` (`<Link to="/settings">`): it navigates through the router with
|
|
5152
5203
|
react-router `<Link>`'s click rules. A hand-written click handler that calls `navigate()`
|
|
5153
5204
|
breaks ctrl/cmd-click (new tab) unless it repeats those rules.
|
|
5205
|
+
- `BodyPortal` is React's `createPortal(children, document.body)` for Svelte: Svelte itself
|
|
5206
|
+
renders the content in the target (a nested `mount`), so no node is moved after Svelte
|
|
5207
|
+
placed it. Nothing renders on the server; `target` replaces the body and `null` renders
|
|
5208
|
+
nothing until a target exists.
|
|
5154
5209
|
|
|
5155
5210
|
## Translations
|
|
5156
5211
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
BodyPortal: renders its children as direct children of `document.body` (or of
|
|
3
|
+
`target`), with no wrapper element — React's `createPortal(children, target)`.
|
|
4
|
+
|
|
5
|
+
Svelte itself places the nodes there: a second `mount()` whose content is this
|
|
6
|
+
component's `children` snippet. No node is ever moved after Svelte placed it, so
|
|
7
|
+
every block range, anchor and keyed item inside the portal stays where Svelte
|
|
8
|
+
put it, and the portal's content is unmounted with this component.
|
|
9
|
+
|
|
10
|
+
Context flows through (`getAllContexts`), the snippet stays reactive, delegated
|
|
11
|
+
events reach the content (the mount registers them on the target) and nothing
|
|
12
|
+
renders on the server, as with React's portals.
|
|
13
|
+
-->
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { flushSync, getAllContexts, mount, type Snippet, unmount } from 'svelte'
|
|
16
|
+
|
|
17
|
+
import PortalContent from './PortalContent.svelte'
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
target,
|
|
21
|
+
children,
|
|
22
|
+
}: {
|
|
23
|
+
/** Where the children render. Defaults to `document.body`; `null` renders nothing yet. */
|
|
24
|
+
target?: Element | null
|
|
25
|
+
/** The portaled content. */
|
|
26
|
+
children?: Snippet
|
|
27
|
+
} = $props()
|
|
28
|
+
|
|
29
|
+
const context = getAllContexts()
|
|
30
|
+
|
|
31
|
+
$effect(() => {
|
|
32
|
+
const parent = target === undefined ? document.body : target
|
|
33
|
+
const content = children
|
|
34
|
+
if (!parent || !content) return
|
|
35
|
+
const instance = mount(PortalContent, { target: parent, props: { children: content }, context })
|
|
36
|
+
// The content's own bindings, actions and effects run now, before the effects of the
|
|
37
|
+
// component that declared the portal: the order inline markup would give them.
|
|
38
|
+
flushSync()
|
|
39
|
+
return () => {
|
|
40
|
+
void unmount(instance)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
</script>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
/** Where the children render. Defaults to `document.body`; `null` renders nothing yet. */
|
|
4
|
+
target?: Element | null;
|
|
5
|
+
/** The portaled content. */
|
|
6
|
+
children?: Snippet;
|
|
7
|
+
};
|
|
8
|
+
declare const BodyPortal: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type BodyPortal = ReturnType<typeof BodyPortal>;
|
|
10
|
+
export default BodyPortal;
|
|
11
|
+
//# sourceMappingURL=BodyPortal.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BodyPortal.svelte.d.ts","sourceRoot":"","sources":["../../src/components/BodyPortal.svelte"],"names":[],"mappings":"AAGA,OAAO,EAAoC,KAAK,OAAO,EAAW,MAAM,QAAQ,CAAA;AAI/E,KAAK,gBAAgB,GAAI;IACtB,0FAA0F;IAC1F,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACvB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAC;AA8BJ,QAAA,MAAM,UAAU,sDAAwC,CAAC;AACzD,KAAK,UAAU,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAChD,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
The root a `BodyPortal` mounts in its target: the portal's children and nothing
|
|
3
|
+
else, so the target receives exactly the nodes the declaring component rendered
|
|
4
|
+
(React's `createPortal(children, target)` renders no wrapper either).
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { Snippet } from 'svelte'
|
|
8
|
+
|
|
9
|
+
let { children }: { children: Snippet } = $props()
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
{@render children?.()}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
children: Snippet;
|
|
4
|
+
};
|
|
5
|
+
declare const PortalContent: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type PortalContent = ReturnType<typeof PortalContent>;
|
|
7
|
+
export default PortalContent;
|
|
8
|
+
//# sourceMappingURL=PortalContent.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PortalContent.svelte.d.ts","sourceRoot":"","sources":["../../src/components/PortalContent.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAErC,KAAK,gBAAgB,GAAI;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAYhD,QAAA,MAAM,aAAa,sDAAwC,CAAC;AAC5D,KAAK,aAAa,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACtD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
PresentWhileContent: an element that is in the page only while its content renders something
|
|
3
|
+
(an element, or text) — React's `slot(children) !== undefined ? <div>{children}</div> : null`,
|
|
4
|
+
which a Svelte component cannot decide from a snippet's value (an `{#each}` over no rows, an
|
|
5
|
+
`{#if false}`). `tag` names the element (`div` by default); every other prop is an attribute of
|
|
6
|
+
it.
|
|
7
|
+
|
|
8
|
+
The element is the only node of its own `svelte:element` block. While its content is empty it
|
|
9
|
+
leaves the page and waits just before that block's anchor comment, which Svelte moves with the
|
|
10
|
+
block, so it comes back in its place; a `MutationObserver` on it (which keeps reporting while
|
|
11
|
+
it is out of the page) decides again after every change Svelte makes to the content. The
|
|
12
|
+
observer reports in a microtask, before the browser paints.
|
|
13
|
+
-->
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import type { Snippet } from 'svelte'
|
|
16
|
+
import type { Attachment } from 'svelte/attachments'
|
|
17
|
+
import type { HTMLAttributes } from 'svelte/elements'
|
|
18
|
+
|
|
19
|
+
import { rendersContent } from '../content.js'
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
tag = 'div',
|
|
23
|
+
children,
|
|
24
|
+
...attributes
|
|
25
|
+
}: HTMLAttributes<HTMLElement> & {
|
|
26
|
+
/** The element's tag. */
|
|
27
|
+
tag?: string
|
|
28
|
+
/** The content; the element is in the page only while it renders something. */
|
|
29
|
+
children?: Snippet
|
|
30
|
+
} = $props()
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Keeps the element in the page exactly while its content renders something.
|
|
34
|
+
*
|
|
35
|
+
* @param element - The element.
|
|
36
|
+
* @returns The cleanup.
|
|
37
|
+
*/
|
|
38
|
+
const presentWhileContent: Attachment<HTMLElement> = (element) => {
|
|
39
|
+
// The block's anchor: Svelte inserts the element in front of it and moves the two together.
|
|
40
|
+
const anchor = element.nextSibling
|
|
41
|
+
const sync = (): void => {
|
|
42
|
+
if (rendersContent(element)) {
|
|
43
|
+
if (!element.isConnected && anchor?.parentNode)
|
|
44
|
+
anchor.parentNode.insertBefore(element, anchor)
|
|
45
|
+
} else if (element.parentNode) {
|
|
46
|
+
element.remove()
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
sync()
|
|
50
|
+
const observer = new MutationObserver(sync)
|
|
51
|
+
observer.observe(element, { childList: true, characterData: true, subtree: true })
|
|
52
|
+
return () => observer.disconnect()
|
|
53
|
+
}
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<svelte:element this={tag} {...attributes} {@attach presentWhileContent}
|
|
57
|
+
>{@render children?.()}</svelte:element
|
|
58
|
+
>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
type $$ComponentProps = HTMLAttributes<HTMLElement> & {
|
|
4
|
+
/** The element's tag. */
|
|
5
|
+
tag?: string;
|
|
6
|
+
/** The content; the element is in the page only while it renders something. */
|
|
7
|
+
children?: Snippet;
|
|
8
|
+
};
|
|
9
|
+
declare const PresentWhileContent: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
10
|
+
type PresentWhileContent = ReturnType<typeof PresentWhileContent>;
|
|
11
|
+
export default PresentWhileContent;
|
|
12
|
+
//# sourceMappingURL=PresentWhileContent.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PresentWhileContent.svelte.d.ts","sourceRoot":"","sources":["../../src/components/PresentWhileContent.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAErC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAIpD,KAAK,gBAAgB,GAAI,cAAc,CAAC,WAAW,CAAC,GAAG;IACpD,yBAAyB;IACzB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAC;AA2CJ,QAAA,MAAM,mBAAmB,sDAAwC,CAAC;AAClE,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAClE,eAAe,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The components that are not tied to one service: `BodyPortal`, React's
|
|
3
|
+
* `createPortal` for `document.body`, as a Svelte component, and
|
|
4
|
+
* `PresentWhileContent`, an element in the page only while its content renders
|
|
5
|
+
* something (React's `slot(children) !== undefined && <div>…</div>`).
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export { default as BodyPortal } from './BodyPortal.svelte';
|
|
10
|
+
export { default as PresentWhileContent } from './PresentWhileContent.svelte';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,8BAA8B,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The components that are not tied to one service: `BodyPortal`, React's
|
|
3
|
+
* `createPortal` for `document.body`, as a Svelte component, and
|
|
4
|
+
* `PresentWhileContent`, an element in the page only while its content renders
|
|
5
|
+
* something (React's `slot(children) !== undefined && <div>…</div>`).
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export { default as BodyPortal } from './BodyPortal.svelte';
|
|
10
|
+
export { default as PresentWhileContent } from './PresentWhileContent.svelte';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendered DOM content, read by React's `slot(node)` rule.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The children of a node that render something: elements, and text nodes with text. Comments
|
|
8
|
+
* and empty text nodes are Svelte's own anchors (and other components' placeholders), not
|
|
9
|
+
* content.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const nodes = contentNodes(titleEl)
|
|
14
|
+
* const text = nodes.length === 1 && nodes[0].nodeType === 3 ? nodes[0].textContent : ''
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param node - The node whose children are read.
|
|
18
|
+
* @returns Those children, in order.
|
|
19
|
+
*/
|
|
20
|
+
export declare function contentNodes(node: Node): ChildNode[];
|
|
21
|
+
/**
|
|
22
|
+
* Whether a node's children render anything (see {@link contentNodes}). A Svelte component
|
|
23
|
+
* cannot tell from a snippet's value whether it renders anything (`{#each}` over no rows,
|
|
24
|
+
* `{#if false}`), so a component that renders a wrapper only while its content has something to
|
|
25
|
+
* show, as React's `slot(children) !== undefined && <div>…</div>` does, asks the rendered DOM
|
|
26
|
+
* instead (see `PresentWhileContent`).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* rendersContent(panel) // false while the panel's snippet renders an empty list
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param node - The node whose children are read.
|
|
34
|
+
* @returns True when one of them renders something.
|
|
35
|
+
*/
|
|
36
|
+
export declare function rendersContent(node: Node): boolean;
|
|
37
|
+
//# sourceMappingURL=content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,CAIpD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAElD"}
|
package/dist/content.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendered DOM content, read by React's `slot(node)` rule.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The children of a node that render something: elements, and text nodes with text. Comments
|
|
8
|
+
* and empty text nodes are Svelte's own anchors (and other components' placeholders), not
|
|
9
|
+
* content.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const nodes = contentNodes(titleEl)
|
|
14
|
+
* const text = nodes.length === 1 && nodes[0].nodeType === 3 ? nodes[0].textContent : ''
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param node - The node whose children are read.
|
|
18
|
+
* @returns Those children, in order.
|
|
19
|
+
*/
|
|
20
|
+
export function contentNodes(node) {
|
|
21
|
+
return Array.from(node.childNodes).filter((child) => child.nodeType === 1 || (child.nodeType === 3 && (child.textContent ?? '') !== ''));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether a node's children render anything (see {@link contentNodes}). A Svelte component
|
|
25
|
+
* cannot tell from a snippet's value whether it renders anything (`{#each}` over no rows,
|
|
26
|
+
* `{#if false}`), so a component that renders a wrapper only while its content has something to
|
|
27
|
+
* show, as React's `slot(children) !== undefined && <div>…</div>` does, asks the rendered DOM
|
|
28
|
+
* instead (see `PresentWhileContent`).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* rendersContent(panel) // false while the panel's snippet renders an empty list
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param node - The node whose children are read.
|
|
36
|
+
* @returns True when one of them renders something.
|
|
37
|
+
*/
|
|
38
|
+
export function rendersContent(node) {
|
|
39
|
+
return contentNodes(node).length > 0;
|
|
40
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -119,6 +119,16 @@
|
|
|
119
119
|
* >{$favorite.count}</button>
|
|
120
120
|
* ```
|
|
121
121
|
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```svelte
|
|
124
|
+
* <!-- PortaledNode.svelte — content in document.body, exactly as React renders it -->
|
|
125
|
+
* <script lang="ts">
|
|
126
|
+
* import { BodyPortal } from '@molecule/app-svelte'
|
|
127
|
+
* </script>
|
|
128
|
+
*
|
|
129
|
+
* <BodyPortal><div role="dialog">…</div></BodyPortal>
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
122
132
|
* Session state is a three-way decision, not a boolean: `status === 'loading'`
|
|
123
133
|
* is undecided, so wait for it and redirect only on
|
|
124
134
|
* `status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
|
|
@@ -138,10 +148,16 @@
|
|
|
138
148
|
* - In-app links are `Link` (`<Link to="/settings">`): it navigates through the router with
|
|
139
149
|
* react-router `<Link>`'s click rules. A hand-written click handler that calls `navigate()`
|
|
140
150
|
* breaks ctrl/cmd-click (new tab) unless it repeats those rules.
|
|
151
|
+
* - `BodyPortal` is React's `createPortal(children, document.body)` for Svelte: Svelte itself
|
|
152
|
+
* renders the content in the target (a nested `mount`), so no node is moved after Svelte
|
|
153
|
+
* placed it. Nothing renders on the server; `target` replaces the body and `null` renders
|
|
154
|
+
* nothing until a target exists.
|
|
141
155
|
*
|
|
142
156
|
* @module
|
|
143
157
|
*/
|
|
144
158
|
export * from './agent-identity.js';
|
|
159
|
+
export * from './components/index.js';
|
|
160
|
+
export * from './content.js';
|
|
145
161
|
export * from './context.js';
|
|
146
162
|
export * from './hooks/index.js';
|
|
147
163
|
export * from './link/index.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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4JG;AAEH,cAAc,qBAAqB,CAAA;AACnC,cAAc,uBAAuB,CAAA;AACrC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,sBAAsB,CAAA;AACpC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -119,6 +119,16 @@
|
|
|
119
119
|
* >{$favorite.count}</button>
|
|
120
120
|
* ```
|
|
121
121
|
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```svelte
|
|
124
|
+
* <!-- PortaledNode.svelte — content in document.body, exactly as React renders it -->
|
|
125
|
+
* <script lang="ts">
|
|
126
|
+
* import { BodyPortal } from '@molecule/app-svelte'
|
|
127
|
+
* </script>
|
|
128
|
+
*
|
|
129
|
+
* <BodyPortal><div role="dialog">…</div></BodyPortal>
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
122
132
|
* Session state is a three-way decision, not a boolean: `status === 'loading'`
|
|
123
133
|
* is undecided, so wait for it and redirect only on
|
|
124
134
|
* `status === 'unauthenticated'`; `'unavailable'` keeps the session candidate
|
|
@@ -138,10 +148,16 @@
|
|
|
138
148
|
* - In-app links are `Link` (`<Link to="/settings">`): it navigates through the router with
|
|
139
149
|
* react-router `<Link>`'s click rules. A hand-written click handler that calls `navigate()`
|
|
140
150
|
* breaks ctrl/cmd-click (new tab) unless it repeats those rules.
|
|
151
|
+
* - `BodyPortal` is React's `createPortal(children, document.body)` for Svelte: Svelte itself
|
|
152
|
+
* renders the content in the target (a nested `mount`), so no node is moved after Svelte
|
|
153
|
+
* placed it. Nothing renders on the server; `target` replaces the body and `null` renders
|
|
154
|
+
* nothing until a target exists.
|
|
141
155
|
*
|
|
142
156
|
* @module
|
|
143
157
|
*/
|
|
144
158
|
export * from './agent-identity.js';
|
|
159
|
+
export * from './components/index.js';
|
|
160
|
+
export * from './content.js';
|
|
145
161
|
export * from './context.js';
|
|
146
162
|
export * from './hooks/index.js';
|
|
147
163
|
export * from './link/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-svelte",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.0",
|
|
4
4
|
"description": "Svelte framework bindings for molecule.dev",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@molecule/app-ui": "^1.0.1",
|
|
60
60
|
"@molecule/app-utilities": "^1.0.1",
|
|
61
61
|
"@molecule/app-version": "^1.0.1",
|
|
62
|
-
"svelte": "^5.
|
|
62
|
+
"svelte": "^5.43.15"
|
|
63
63
|
},
|
|
64
64
|
"peerDependenciesMeta": {
|
|
65
65
|
"@molecule/app-code-editor": {
|