@picked/svelte 0.0.66 → 0.0.67
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.
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* @file Renders a resolved html-asset field into a shadow root and re-executes its
|
|
4
|
+
* Picked-tagged scripts. On the server the markup is emitted as a declarative shadow DOM
|
|
5
|
+
* template, a parser-only feature the browser attaches as a real shadow root while parsing
|
|
6
|
+
* the response, so content is present from first paint. On the client, the first commit
|
|
7
|
+
* adopts that parser-attached root and only rehydrates its scripts; a client-only mount or a
|
|
8
|
+
* later content change attaches and writes the shadow root imperatively instead.
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
isHtmlAssetValue,
|
|
12
|
+
rehydrateScripts,
|
|
13
|
+
supportsShadowRoot,
|
|
14
|
+
supportsWindow,
|
|
15
|
+
} from '@picked/client'
|
|
4
16
|
|
|
5
17
|
interface Props {
|
|
6
18
|
/** The resolved html-asset field value (for example `content.body`). */
|
|
@@ -11,16 +23,30 @@
|
|
|
11
23
|
|
|
12
24
|
const value = $derived(isHtmlAssetValue(html) ? html : null)
|
|
13
25
|
const markup = $derived(value?.content ?? '')
|
|
26
|
+
const serverMarkup = $derived(
|
|
27
|
+
supportsWindow() ? '' : `<template shadowrootmode="open">${markup}</template>`,
|
|
28
|
+
)
|
|
14
29
|
|
|
15
30
|
let host = $state<HTMLDivElement>()
|
|
31
|
+
let seeded = false
|
|
16
32
|
|
|
17
33
|
$effect(() => {
|
|
18
34
|
if (!supportsShadowRoot() || !host) return
|
|
19
35
|
|
|
20
|
-
const
|
|
36
|
+
const existingShadow = host.shadowRoot
|
|
37
|
+
const isFirstRun = !seeded
|
|
38
|
+
seeded = true
|
|
39
|
+
|
|
40
|
+
if (existingShadow && isFirstRun) {
|
|
41
|
+
if (markup) void rehydrateScripts(existingShadow)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const shadow = existingShadow ?? host.attachShadow({ mode: 'open' })
|
|
21
46
|
shadow.innerHTML = markup
|
|
22
47
|
if (markup) void rehydrateScripts(shadow)
|
|
23
48
|
})
|
|
24
49
|
</script>
|
|
25
50
|
|
|
26
|
-
|
|
51
|
+
<!-- eslint-disable-next-line svelte/no-at-html-tags -- markup is a trusted, Picked-transformed html-asset field, not arbitrary user input -->
|
|
52
|
+
<div bind:this={host}>{@html serverMarkup}</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/svelte",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.67",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"d3": "^7.9.0"
|
|
6
6
|
},
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
},
|
|
107
107
|
"module": "./dist/index.js",
|
|
108
108
|
"peerDependencies": {
|
|
109
|
-
"@picked/client": "0.0.
|
|
109
|
+
"@picked/client": "0.0.67",
|
|
110
110
|
"effector": "^23.3.0",
|
|
111
111
|
"svelte": "^5.46.4"
|
|
112
112
|
},
|