@serene-pub/ui-preview 0.6.0-pr-1
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/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +157 -0
- package/package.json +66 -0
- package/server.d.ts +15 -0
- package/server.js +48 -0
- package/src/app.css +144 -0
- package/src/app.html +34 -0
- package/src/lib/ComponentStage.svelte +224 -0
- package/src/lib/FrameStage.svelte +478 -0
- package/src/lib/Problems.svelte +20 -0
- package/src/lib/SurfaceSettings.svelte +86 -0
- package/src/lib/ThemePicker.svelte +51 -0
- package/src/lib/defaults.ts +16 -0
- package/src/lib/fixtures.ts +108 -0
- package/src/lib/framePort.ts +295 -0
- package/src/lib/samples.ts +90 -0
- package/src/lib/theme.svelte.ts +59 -0
- package/src/lib/virtual.d.ts +15 -0
- package/src/routes/+layout.svelte +122 -0
- package/src/routes/+layout.ts +7 -0
- package/src/routes/+page.svelte +89 -0
- package/src/routes/controls/+page.svelte +157 -0
- package/src/routes/t/[id]/+page.svelte +205 -0
- package/static/favicon.svg +1 -0
- package/svelte.config.js +16 -0
- package/vite/surfaces.ts +371 -0
- package/vite.config.ts +55 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A frame surface, in the sandbox it will actually live in.
|
|
4
|
+
*
|
|
5
|
+
* This is the host half of frame **protocol 2** (`FRAME_PROTOCOL`), and it
|
|
6
|
+
* is deliberately the *same* protocol the app's `PluginFrame.svelte` speaks
|
|
7
|
+
* — the message union is declared once in the SDK
|
|
8
|
+
* (`HostFrameMessage`/`FrameHostMessage`) and both hosts pin to it, so a
|
|
9
|
+
* surface that works here is not working against a friendlier harness. The
|
|
10
|
+
* decisions live in `framePort.ts`, which has no DOM in it and is what the
|
|
11
|
+
* SDK suite pins; this file owns the iframe, the port and the chrome.
|
|
12
|
+
*
|
|
13
|
+
* ⚠ Core is still a protocol-**1** host: it answers none of `error`,
|
|
14
|
+
* `request` or `save-state`. A surface must therefore treat `page` and
|
|
15
|
+
* `state` as messages that may never arrive, exactly as it already treats
|
|
16
|
+
* `theme`. In particular the harness keeps the two properties that make the
|
|
17
|
+
* sandbox mean something:
|
|
18
|
+
*
|
|
19
|
+
* · `sandbox="allow-scripts"` with **no** `allow-same-origin` — opaque
|
|
20
|
+
* origin, no cookies, no DOM reach into the harness.
|
|
21
|
+
*
|
|
22
|
+
* The one thing the harness adds is visibility: every message in both
|
|
23
|
+
* directions is logged, because "the frame did nothing" is otherwise
|
|
24
|
+
* indistinguishable from "the frame never got the post".
|
|
25
|
+
*/
|
|
26
|
+
import { onDestroy, untrack } from 'svelte'
|
|
27
|
+
import type { FramePoint, PreviewTarget } from '@serene-pub/sdk'
|
|
28
|
+
import { FRAME_PROTOCOL } from '@serene-pub/sdk'
|
|
29
|
+
import { answerFrameMessage, initMessage, savedFrameState } from './framePort.js'
|
|
30
|
+
import { themeCssPath } from 'virtual:serene-pub/surfaces'
|
|
31
|
+
import { theme } from './theme.svelte.js'
|
|
32
|
+
import type { Fixtures } from './fixtures.js'
|
|
33
|
+
|
|
34
|
+
interface Props {
|
|
35
|
+
target: PreviewTarget
|
|
36
|
+
src: string
|
|
37
|
+
fixtures: Fixtures
|
|
38
|
+
/** Bumped by the harness to force a document reload. */
|
|
39
|
+
reloadKey: number
|
|
40
|
+
}
|
|
41
|
+
let { target, src, fixtures, reloadKey }: Props = $props()
|
|
42
|
+
|
|
43
|
+
type LogEntry = {
|
|
44
|
+
dir: 'down' | 'up'
|
|
45
|
+
t: string
|
|
46
|
+
detail: string
|
|
47
|
+
at: string
|
|
48
|
+
level?: 'error' | 'fatal'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let frame = $state<HTMLIFrameElement | null>(null)
|
|
52
|
+
let port: MessagePort | null = null
|
|
53
|
+
let ready = $state(false)
|
|
54
|
+
let lastSuspended = false
|
|
55
|
+
let suspended = $state(false)
|
|
56
|
+
let log = $state<LogEntry[]>([])
|
|
57
|
+
/**
|
|
58
|
+
* The last failure the frame reported (protocol 2's `error`), shown in the
|
|
59
|
+
* bar rather than only in the log — a broken total-conversion surface should
|
|
60
|
+
* say so rather than sit blank, which is the whole reason the message exists.
|
|
61
|
+
*/
|
|
62
|
+
let failure = $state<{ message: string; fatal: boolean } | null>(null)
|
|
63
|
+
|
|
64
|
+
const surface = $derived<FramePoint>(target.point as FramePoint)
|
|
65
|
+
|
|
66
|
+
const stamp = () => new Date().toISOString().slice(11, 23)
|
|
67
|
+
|
|
68
|
+
function record(dir: 'down' | 'up', t: string, detail: unknown, level?: 'error' | 'fatal') {
|
|
69
|
+
// `untrack` is load-bearing, not tidy. `record` runs inside the push
|
|
70
|
+
// effect and appending reads the existing log — a read and a write of
|
|
71
|
+
// the same state in one effect, which is an infinite loop. The symptom
|
|
72
|
+
// is not an error but a wedged page, so it is worth naming here.
|
|
73
|
+
untrack(() => appendLog(dir, t, detail, level))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function appendLog(dir: 'down' | 'up', t: string, detail: unknown, level?: 'error' | 'fatal') {
|
|
77
|
+
log = [
|
|
78
|
+
{
|
|
79
|
+
dir,
|
|
80
|
+
t,
|
|
81
|
+
detail: typeof detail === 'string' ? detail : JSON.stringify(detail),
|
|
82
|
+
at: stamp(),
|
|
83
|
+
...(level ? { level } : {})
|
|
84
|
+
},
|
|
85
|
+
...log
|
|
86
|
+
].slice(0, 200)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function post(msg: Record<string, unknown>) {
|
|
90
|
+
try {
|
|
91
|
+
// `$state.snapshot` is load-bearing, not tidiness: the fixtures are
|
|
92
|
+
// reactive state, and a Svelte proxy is not structured-cloneable —
|
|
93
|
+
// every post would be dropped. Core hands `PluginFrame` plain rows
|
|
94
|
+
// off the wire, so this is the harness matching core's shape rather
|
|
95
|
+
// than the frame having to tolerate the harness's.
|
|
96
|
+
port?.postMessage($state.snapshot(msg))
|
|
97
|
+
record('down', String(msg.t), summarise(msg))
|
|
98
|
+
} catch (e) {
|
|
99
|
+
// The guard stays even so: a fixture file is the modder's, and a
|
|
100
|
+
// DataCloneError that killed the rest of the push would look like
|
|
101
|
+
// the surface ignoring messages it never received.
|
|
102
|
+
record('down', String(msg.t), `DROPPED — uncloneable: ${(e as Error).message}`)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function summarise(msg: Record<string, unknown>): string {
|
|
107
|
+
if (msg.t === 'channel') return `${msg.channel}: ${(msg.messages as unknown[]).length} message(s)`
|
|
108
|
+
if (msg.t === 'messages') return `${(msg.messages as unknown[]).length} message(s)`
|
|
109
|
+
if (msg.t === 'props') return Object.keys(msg.props as object).join(', ')
|
|
110
|
+
if (msg.t === 'page')
|
|
111
|
+
return `#${msg.requestId}: ${(msg.rows as unknown[]).length} row(s)${
|
|
112
|
+
msg.nextCursor ? ', more to come' : ''
|
|
113
|
+
}`
|
|
114
|
+
if (msg.t === 'state') return `${Object.keys(msg.state as object).length} restored key(s)`
|
|
115
|
+
return ''
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function handleLoad() {
|
|
119
|
+
// A fresh channel per document load — a reloaded frame must never
|
|
120
|
+
// receive a stale port. `lastSuspended` resets with it: a reloaded
|
|
121
|
+
// document has never been told to idle, so leaving the flag set would
|
|
122
|
+
// let a running frame sit behind a UI that says "suspended". `failure`
|
|
123
|
+
// resets too: a reloaded document has not failed yet, and a stale FATAL
|
|
124
|
+
// in the bar would be the harness lying about the surface in front of it.
|
|
125
|
+
port?.close()
|
|
126
|
+
ready = false
|
|
127
|
+
lastSuspended = false
|
|
128
|
+
failure = null
|
|
129
|
+
const channel = new MessageChannel()
|
|
130
|
+
port = channel.port1
|
|
131
|
+
port.onmessage = (e) => {
|
|
132
|
+
// Every decision is `framePort.ts`'s — this half only moves the
|
|
133
|
+
// bytes and paints the outcome, so what the harness answers can be
|
|
134
|
+
// pinned without a browser.
|
|
135
|
+
const reply = answerFrameMessage(e.data, {
|
|
136
|
+
surfaceId: target.id,
|
|
137
|
+
source: { messages: $state.snapshot(fixtures.messages) },
|
|
138
|
+
state: savedFrameState
|
|
139
|
+
})
|
|
140
|
+
if (!reply) return
|
|
141
|
+
record('up', reply.log.t, reply.log.detail, reply.log.level)
|
|
142
|
+
if (reply.error) failure = reply.error
|
|
143
|
+
for (const msg of reply.post) post(msg as Record<string, unknown>)
|
|
144
|
+
// Flipped LAST. `ready` is read inside `push`, which runs inside the
|
|
145
|
+
// effect, so flipping it re-runs the effect and the batch goes out
|
|
146
|
+
// once — and it goes out after any `state` the host just restored,
|
|
147
|
+
// which is the order a remounting surface needs.
|
|
148
|
+
if (reply.ready) ready = true
|
|
149
|
+
}
|
|
150
|
+
frame?.contentWindow?.postMessage(initMessage(surface), '*', [channel.port2])
|
|
151
|
+
record('down', 'init', `surface=${surface} · protocol ${FRAME_PROTOCOL}`)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* What the host posts, scoped by surface point — because core scopes it,
|
|
156
|
+
* and a harness that fed every frame everything would be teaching a surface
|
|
157
|
+
* to depend on data an instance never sends it.
|
|
158
|
+
*
|
|
159
|
+
* Read off the two call sites a package declares rather than invented (a
|
|
160
|
+
* document inside a component, `sp-frame`, is previewed with its
|
|
161
|
+
* component, never on its own):
|
|
162
|
+
*
|
|
163
|
+
* `session-view` sessions/[id] passes session and messages. No props: the
|
|
164
|
+
* prop is not passed, so PluginFrame's `!== undefined`
|
|
165
|
+
* guard means `{t:'props'}` is never posted at all.
|
|
166
|
+
* `page` routes/x/[...rest] passes src, title and surface only.
|
|
167
|
+
* A page frame receives `init` and nothing else, ever.
|
|
168
|
+
*
|
|
169
|
+
* `theme` is the one message the harness adds, and it is marked as such
|
|
170
|
+
* everywhere it appears.
|
|
171
|
+
*/
|
|
172
|
+
function push() {
|
|
173
|
+
// `ready` is read first, unconditionally, and that ordering is the
|
|
174
|
+
// whole reason the first batch arrives at all. `!port || !ready`
|
|
175
|
+
// short-circuits: on the very first run `port` is still null, so
|
|
176
|
+
// `ready` was never read, so the effect never depended on it, so
|
|
177
|
+
// flipping it later re-ran nothing. The frame sat there having said
|
|
178
|
+
// `ready` to a host that had stopped listening.
|
|
179
|
+
const isReady = ready
|
|
180
|
+
if (!port || !isReady) return
|
|
181
|
+
|
|
182
|
+
if (surface === 'session-view') {
|
|
183
|
+
post({ t: 'session', session: fixtures.session })
|
|
184
|
+
post({ t: 'messages', messages: fixtures.messages })
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// The active theme, as data (10 §6). A frame is its own document, so it
|
|
188
|
+
// inherits no custom properties from ours — it applies the id and the
|
|
189
|
+
// mode to its own root and lets the token stylesheet it linked resolve
|
|
190
|
+
// them. Core does not send this yet; the harness does, so a surface can
|
|
191
|
+
// be built against it.
|
|
192
|
+
post({ t: 'theme', theme: theme.current.theme, mode: theme.current.mode })
|
|
193
|
+
// The viewer's language (`locale.v1`), as core sends it last. The
|
|
194
|
+
// browser's, here: the preview has no user to ask.
|
|
195
|
+
post({ t: 'locale', locale: (navigator.language || 'en').split('-')[0] })
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Re-feed on any change to what the host would post — the frame renders
|
|
200
|
+
* what core chose to send it, which is the whole privacy story: it can
|
|
201
|
+
* only ever scrape this.
|
|
202
|
+
*
|
|
203
|
+
* The signature is a deep read, and it has to be. Naming `fixtures` in the
|
|
204
|
+
* effect subscribes to the *reference*, not to the fields inside it, and
|
|
205
|
+
* the deep read that does happen — `$state.snapshot` in `post` — is
|
|
206
|
+
* specifically designed **not** to create dependencies. Without this, a
|
|
207
|
+
* fixture edit changes the editor and nothing else: the value is right,
|
|
208
|
+
* the frame never hears about it.
|
|
209
|
+
*/
|
|
210
|
+
const signature = $derived.by(() => {
|
|
211
|
+
try {
|
|
212
|
+
return JSON.stringify({
|
|
213
|
+
session: fixtures.session,
|
|
214
|
+
messages: fixtures.messages,
|
|
215
|
+
surface,
|
|
216
|
+
theme: theme.current,
|
|
217
|
+
})
|
|
218
|
+
} catch {
|
|
219
|
+
// Unserialisable fixtures are the modder's business and `post`
|
|
220
|
+
// already reports the drop; re-pushing every tick beats going deaf.
|
|
221
|
+
return String(Math.random())
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
$effect(() => {
|
|
226
|
+
void signature
|
|
227
|
+
push()
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
$effect(() => {
|
|
231
|
+
const s = suspended
|
|
232
|
+
if (!port || !ready) return
|
|
233
|
+
if (s !== lastSuspended) {
|
|
234
|
+
lastSuspended = s
|
|
235
|
+
post({ t: s ? 'suspend' : 'resume' })
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
onDestroy(() => port?.close())
|
|
240
|
+
</script>
|
|
241
|
+
|
|
242
|
+
<div class="stage">
|
|
243
|
+
<div class="bar">
|
|
244
|
+
<span class="pill" class:on={ready}>{ready ? 'ready' : 'waiting for ready'}</span>
|
|
245
|
+
<span class="muted">{surface}</span>
|
|
246
|
+
<!-- Protocol 2's `error`, in the chrome and not only in the log: a broken
|
|
247
|
+
total-conversion surface should say so rather than sit blank. -->
|
|
248
|
+
{#if failure}
|
|
249
|
+
<span class="pill bad" title={failure.message}>
|
|
250
|
+
{failure.fatal ? 'fatal' : 'error'}: {failure.message}
|
|
251
|
+
</span>
|
|
252
|
+
{/if}
|
|
253
|
+
<button aria-pressed={suspended} onclick={() => (suspended = !suspended)}>
|
|
254
|
+
{suspended ? 'suspended' : 'suspend'}
|
|
255
|
+
</button>
|
|
256
|
+
<span class="grow"></span>
|
|
257
|
+
<code class="muted" title="Served under core's frame CSP, with connect-src widened to reach Vite's HMR socket — the one dev relaxation."
|
|
258
|
+
>{target.entry}</code
|
|
259
|
+
>
|
|
260
|
+
</div>
|
|
261
|
+
|
|
262
|
+
<details class="hint">
|
|
263
|
+
<summary>Theming this frame</summary>
|
|
264
|
+
<p>
|
|
265
|
+
A frame is its own document under an opaque origin, so it inherits nothing from the
|
|
266
|
+
page around it. Link the harness's token stylesheet and apply what arrives on the
|
|
267
|
+
channel — the same two attributes the app sets on its own root:
|
|
268
|
+
</p>
|
|
269
|
+
<pre><code>{`<link rel="stylesheet" href="${themeCssPath}">`}</code></pre>
|
|
270
|
+
<pre><code>{`port.onmessage = (e) => {
|
|
271
|
+
if (e.data.t !== 'theme') return
|
|
272
|
+
document.documentElement.dataset.theme = e.data.theme
|
|
273
|
+
document.documentElement.dataset.mode = e.data.mode
|
|
274
|
+
}`}</code></pre>
|
|
275
|
+
<p>
|
|
276
|
+
The stylesheet carries every stock theme's custom properties and nothing else — no
|
|
277
|
+
utility classes, because your own build owns those. That means the
|
|
278
|
+
<em>palette</em> follows the theme automatically, but the light/dark
|
|
279
|
+
<em>mapping</em> is yours: Skeleton builds that on top with <code>light-dark()</code>
|
|
280
|
+
in a base layer written in Tailwind at-rules, which cannot be served as plain CSS.
|
|
281
|
+
Pick your own sides of the ramp:
|
|
282
|
+
</p>
|
|
283
|
+
<pre><code>{`body { background: var(--color-surface-50) }
|
|
284
|
+
[data-mode="dark"] body { background: var(--color-surface-950) }`}</code></pre>
|
|
285
|
+
<p>
|
|
286
|
+
Two constraints this frame enforces because production does. It is served under
|
|
287
|
+
core's CSP (<code>script-src 'self'</code>), so an <em>inline</em> script is
|
|
288
|
+
blocked — load your surface from a file. And a frame is an
|
|
289
|
+
<strong>opaque origin</strong>, so it sends <code>Origin: null</code> and a
|
|
290
|
+
<code><script type="module"></code> — which is always CORS-fetched — is
|
|
291
|
+
refused, because neither core's plugin-ui route nor this harness answers with
|
|
292
|
+
<code>Access-Control-Allow-Origin</code>. Use a classic
|
|
293
|
+
<code><script src="…"></code>; it is not CORS-fetched and loads fine.
|
|
294
|
+
</p>
|
|
295
|
+
</details>
|
|
296
|
+
|
|
297
|
+
<details class="hint">
|
|
298
|
+
<summary>Where this harness is not production</summary>
|
|
299
|
+
<p>
|
|
300
|
+
Everything the harness does differently, in one place, because a fidelity tool that
|
|
301
|
+
hid its own divergences would be the worst kind:
|
|
302
|
+
</p>
|
|
303
|
+
<ul>
|
|
304
|
+
<li>
|
|
305
|
+
<strong><code>{'{ t: "theme" }'}</code> is harness-only.</strong> Core does not send it.
|
|
306
|
+
Read it defensively and keep a default.
|
|
307
|
+
</li>
|
|
308
|
+
<li>
|
|
309
|
+
<strong><code>{themeCssPath}</code> is harness-only.</strong> Core serves nothing at
|
|
310
|
+
that URL. Guard the link, or ship your own tokens, until it does.
|
|
311
|
+
</li>
|
|
312
|
+
<li>
|
|
313
|
+
<strong>Protocol 2 is harness-only, for now.</strong> This host answers
|
|
314
|
+
<code>request</code> with a <code>page</code>, holds <code>save-state</code> for the
|
|
315
|
+
harness session and returns it as <code>state</code>, and shows <code>error</code> in
|
|
316
|
+
the bar. Core is still a protocol-<strong>1</strong> host and answers none of them, so
|
|
317
|
+
treat <code>page</code> and <code>state</code> as messages that may never arrive. The
|
|
318
|
+
page size and the cursor's spelling are this harness's choice — read
|
|
319
|
+
<code>nextCursor</code> and hand it back; never parse it.
|
|
320
|
+
</li>
|
|
321
|
+
<li>
|
|
322
|
+
<strong><code>connect-src</code> is wider here.</strong> Production grants only the
|
|
323
|
+
hosts your manifest declares; this frame also reaches Vite's HMR socket, because
|
|
324
|
+
otherwise nothing hot-reloads.
|
|
325
|
+
</li>
|
|
326
|
+
<li>
|
|
327
|
+
<strong>Your files go through Vite.</strong> Core serves the installed bytes verbatim,
|
|
328
|
+
hash and all. A transform that only happens in dev is a difference you should not
|
|
329
|
+
build on.
|
|
330
|
+
</li>
|
|
331
|
+
</ul>
|
|
332
|
+
<p>
|
|
333
|
+
What is <em>not</em> different, deliberately: the sandbox attributes, the CSP's other
|
|
334
|
+
directives, the message <em>shapes</em> (one union, declared in the SDK), and which
|
|
335
|
+
messages each surface point receives unprompted — a <code>page</code> surface gets
|
|
336
|
+
<code>init</code> and nothing else here, exactly as in the app.
|
|
337
|
+
</p>
|
|
338
|
+
</details>
|
|
339
|
+
|
|
340
|
+
<div class="body" class:suspended>
|
|
341
|
+
{#key reloadKey}
|
|
342
|
+
<iframe
|
|
343
|
+
bind:this={frame}
|
|
344
|
+
{src}
|
|
345
|
+
title={target.label}
|
|
346
|
+
sandbox="allow-scripts"
|
|
347
|
+
onload={handleLoad}
|
|
348
|
+
></iframe>
|
|
349
|
+
{/key}
|
|
350
|
+
</div>
|
|
351
|
+
|
|
352
|
+
<details class="log" open>
|
|
353
|
+
<summary>Channel log <span class="muted">({log.length})</span></summary>
|
|
354
|
+
<ol>
|
|
355
|
+
{#each log as e}
|
|
356
|
+
<li class={e.dir}>
|
|
357
|
+
<span class="at">{e.at}</span>
|
|
358
|
+
<span class="arrow">{e.dir === 'down' ? '→' : '←'}</span>
|
|
359
|
+
<strong class:err={!!e.level}>{e.t}</strong>
|
|
360
|
+
<span class="muted">{e.detail}</span>
|
|
361
|
+
</li>
|
|
362
|
+
{/each}
|
|
363
|
+
{#if !log.length}
|
|
364
|
+
<li class="muted">
|
|
365
|
+
Nothing yet. A surface joins the conversation by posting <code>{'{ t: "ready" }'}</code>
|
|
366
|
+
back through the port it receives in <code>init</code>.
|
|
367
|
+
</li>
|
|
368
|
+
{/if}
|
|
369
|
+
</ol>
|
|
370
|
+
</details>
|
|
371
|
+
</div>
|
|
372
|
+
|
|
373
|
+
<style>
|
|
374
|
+
.stage {
|
|
375
|
+
display: flex;
|
|
376
|
+
flex-direction: column;
|
|
377
|
+
min-height: 0;
|
|
378
|
+
flex: 1;
|
|
379
|
+
}
|
|
380
|
+
.bar {
|
|
381
|
+
display: flex;
|
|
382
|
+
gap: 0.5rem;
|
|
383
|
+
align-items: center;
|
|
384
|
+
padding: 0.5rem 0.8rem;
|
|
385
|
+
border-bottom: 1px solid var(--line);
|
|
386
|
+
}
|
|
387
|
+
.grow {
|
|
388
|
+
flex: 1;
|
|
389
|
+
}
|
|
390
|
+
.pill {
|
|
391
|
+
font-size: 0.74rem;
|
|
392
|
+
border: 1px solid var(--line);
|
|
393
|
+
border-radius: 999px;
|
|
394
|
+
padding: 0.1rem 0.55rem;
|
|
395
|
+
color: var(--muted);
|
|
396
|
+
}
|
|
397
|
+
.pill.on {
|
|
398
|
+
color: var(--accent);
|
|
399
|
+
border-color: var(--accent);
|
|
400
|
+
}
|
|
401
|
+
.pill.bad {
|
|
402
|
+
color: #d94b4b;
|
|
403
|
+
border-color: #d94b4b;
|
|
404
|
+
max-width: 40ch;
|
|
405
|
+
overflow: hidden;
|
|
406
|
+
text-overflow: ellipsis;
|
|
407
|
+
white-space: nowrap;
|
|
408
|
+
}
|
|
409
|
+
li.up strong.err {
|
|
410
|
+
color: #d94b4b;
|
|
411
|
+
}
|
|
412
|
+
.body {
|
|
413
|
+
flex: 1;
|
|
414
|
+
min-height: 0;
|
|
415
|
+
background: var(--panel);
|
|
416
|
+
}
|
|
417
|
+
.body.suspended {
|
|
418
|
+
opacity: 0.55;
|
|
419
|
+
}
|
|
420
|
+
iframe {
|
|
421
|
+
width: 100%;
|
|
422
|
+
height: 100%;
|
|
423
|
+
border: 0;
|
|
424
|
+
display: block;
|
|
425
|
+
}
|
|
426
|
+
.hint {
|
|
427
|
+
border-top: 1px solid var(--line, currentColor);
|
|
428
|
+
padding: 0 0.8rem 0.6rem;
|
|
429
|
+
font-size: 0.8rem;
|
|
430
|
+
}
|
|
431
|
+
.hint summary {
|
|
432
|
+
cursor: pointer;
|
|
433
|
+
padding: 0.5rem 0;
|
|
434
|
+
font-size: 0.8rem;
|
|
435
|
+
letter-spacing: 0.06em;
|
|
436
|
+
text-transform: uppercase;
|
|
437
|
+
opacity: 0.7;
|
|
438
|
+
}
|
|
439
|
+
.hint pre {
|
|
440
|
+
overflow-x: auto;
|
|
441
|
+
font-size: 0.74rem;
|
|
442
|
+
}
|
|
443
|
+
.log {
|
|
444
|
+
border-top: 1px solid var(--line);
|
|
445
|
+
max-height: 34vh;
|
|
446
|
+
overflow-y: auto;
|
|
447
|
+
padding: 0 0.8rem 0.6rem;
|
|
448
|
+
}
|
|
449
|
+
summary {
|
|
450
|
+
cursor: pointer;
|
|
451
|
+
padding: 0.5rem 0;
|
|
452
|
+
font-size: 0.8rem;
|
|
453
|
+
letter-spacing: 0.06em;
|
|
454
|
+
text-transform: uppercase;
|
|
455
|
+
color: var(--muted);
|
|
456
|
+
}
|
|
457
|
+
ol {
|
|
458
|
+
list-style: none;
|
|
459
|
+
margin: 0;
|
|
460
|
+
padding: 0;
|
|
461
|
+
font-family: ui-monospace, Menlo, monospace;
|
|
462
|
+
font-size: 0.76rem;
|
|
463
|
+
}
|
|
464
|
+
li {
|
|
465
|
+
display: flex;
|
|
466
|
+
gap: 0.5rem;
|
|
467
|
+
padding: 0.1rem 0;
|
|
468
|
+
}
|
|
469
|
+
li.up strong {
|
|
470
|
+
color: var(--accent);
|
|
471
|
+
}
|
|
472
|
+
.at {
|
|
473
|
+
color: var(--muted);
|
|
474
|
+
}
|
|
475
|
+
.arrow {
|
|
476
|
+
width: 1ch;
|
|
477
|
+
}
|
|
478
|
+
</style>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Declarations the harness could not read. Shown, never thrown: a
|
|
4
|
+
* half-typed entry path must not empty the list of everything else that
|
|
5
|
+
* works — the same tolerance the app's manifest reader has.
|
|
6
|
+
*/
|
|
7
|
+
let { problems }: { problems: string[] } = $props()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
{#if problems.length}
|
|
11
|
+
<div class="problems">
|
|
12
|
+
<h3>{problems.length} declaration {problems.length === 1 ? 'problem' : 'problems'}</h3>
|
|
13
|
+
<ul>
|
|
14
|
+
{#each problems as p}
|
|
15
|
+
<li>{p}</li>
|
|
16
|
+
{/each}
|
|
17
|
+
</ul>
|
|
18
|
+
</div>
|
|
19
|
+
{/if}
|
|
20
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The generated controls for one declared component.
|
|
4
|
+
*
|
|
5
|
+
* A component declares its settings as a `SettingsSchema`; core renders
|
|
6
|
+
* forms from schemas; therefore the component gets an editor without
|
|
7
|
+
* shipping one. This panel is that editor, and the values go straight down
|
|
8
|
+
* the same pipe an instance uses — `ctx.settings` — so what a modder edits
|
|
9
|
+
* here is what their component receives. (A page or session-view frame is
|
|
10
|
+
* handed no declared values, so it never gets this panel.)
|
|
11
|
+
*
|
|
12
|
+
* Schema problems are reported through the SDK's own `checkSchema` rather
|
|
13
|
+
* than a second opinion invented here. The one worth naming out loud is a
|
|
14
|
+
* `secret` on a surface: a surface runs in the browser, so a secret
|
|
15
|
+
* declared on one would be delivered to it.
|
|
16
|
+
*/
|
|
17
|
+
import { SchemaForm } from '@serene-pub/controls'
|
|
18
|
+
import { checkSchema, configState, type SettingsSchema } from '@serene-pub/sdk'
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
schema: SettingsSchema
|
|
22
|
+
values: Record<string, unknown>
|
|
23
|
+
/** How these values reach the surface, said plainly in the panel. */
|
|
24
|
+
delivery: string
|
|
25
|
+
}
|
|
26
|
+
let { schema, values = $bindable(), delivery }: Props = $props()
|
|
27
|
+
|
|
28
|
+
/** A schema a modder is halfway through writing must not throw. */
|
|
29
|
+
const findings = $derived.by(() => {
|
|
30
|
+
try {
|
|
31
|
+
return checkSchema(schema)
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return [{ severity: 'error', message: (e as Error).message } as never]
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Guarded on the same terms as `checkSchema`, and for the same reason: both
|
|
38
|
+
// read a schema a modder is halfway through writing, and an exception in
|
|
39
|
+
// either would blank the panel that was about to explain why.
|
|
40
|
+
const state = $derived.by(() => {
|
|
41
|
+
try {
|
|
42
|
+
return configState(schema, values)
|
|
43
|
+
} catch {
|
|
44
|
+
return { state: 'ready' } as ReturnType<typeof configState>
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
const errors = $derived(findings.filter((f: any) => f.severity === 'error'))
|
|
48
|
+
const warnings = $derived(findings.filter((f: any) => f.severity !== 'error'))
|
|
49
|
+
const secrets = $derived.by(() => {
|
|
50
|
+
try {
|
|
51
|
+
return Object.entries(schema)
|
|
52
|
+
.filter(([, d]) => d?.type === 'secret')
|
|
53
|
+
.map(([k]) => k)
|
|
54
|
+
} catch {
|
|
55
|
+
return []
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<div class="flex flex-col gap-3">
|
|
61
|
+
<p class="text-surface-600-400 text-xs">
|
|
62
|
+
Generated from the surface's declaration. Values arrive as <code>{delivery}</code>.
|
|
63
|
+
</p>
|
|
64
|
+
|
|
65
|
+
{#if secrets.length}
|
|
66
|
+
<div class="preset-tonal-error rounded p-2 text-xs">
|
|
67
|
+
<strong>{secrets.join(', ')}</strong>
|
|
68
|
+
{secrets.length === 1 ? 'is a secret' : 'are secrets'} on a surface. A surface runs
|
|
69
|
+
in the browser, so the value would be delivered to it — declare secrets
|
|
70
|
+
extension-side and read them from a hook.
|
|
71
|
+
</div>
|
|
72
|
+
{/if}
|
|
73
|
+
|
|
74
|
+
{#each errors as f}
|
|
75
|
+
<div class="preset-tonal-error rounded p-2 text-xs">{f.message}</div>
|
|
76
|
+
{/each}
|
|
77
|
+
{#each warnings as f}
|
|
78
|
+
<div class="preset-tonal-warning rounded p-2 text-xs">{f.message}</div>
|
|
79
|
+
{/each}
|
|
80
|
+
|
|
81
|
+
{#if state.state === 'needs-configuration'}
|
|
82
|
+
<div class="preset-tonal-warning rounded p-2 text-xs">{state.message}</div>
|
|
83
|
+
{/if}
|
|
84
|
+
|
|
85
|
+
<SchemaForm {schema} bind:values idPrefix="surface" />
|
|
86
|
+
</div>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Every stock Skeleton theme, and the light/dark switch.
|
|
4
|
+
*
|
|
5
|
+
* The list is read off the installed `@skeletonlabs/skeleton` rather than
|
|
6
|
+
* written down, so a Skeleton release that adds a theme adds it here too.
|
|
7
|
+
* SP maintains no token compatibility of any kind (RESEARCH §7b) — the
|
|
8
|
+
* token surface is whatever Skeleton version core currently ships — and a
|
|
9
|
+
* hardcoded list would be exactly the artifact that ruling refuses.
|
|
10
|
+
*/
|
|
11
|
+
import { themes } from 'virtual:serene-pub/surfaces'
|
|
12
|
+
import { theme } from './theme.svelte.js'
|
|
13
|
+
|
|
14
|
+
const label = (t: string) => t.charAt(0).toUpperCase() + t.slice(1)
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<div class="flex items-center gap-2">
|
|
18
|
+
<label class="sr-only" for="harness-theme">Theme</label>
|
|
19
|
+
<select
|
|
20
|
+
id="harness-theme"
|
|
21
|
+
class="select w-full text-xs"
|
|
22
|
+
value={theme.current.theme}
|
|
23
|
+
onchange={(e) => theme.set({ theme: e.currentTarget.value })}
|
|
24
|
+
>
|
|
25
|
+
{#each themes as t (t)}
|
|
26
|
+
<option value={t}>{label(t)}</option>
|
|
27
|
+
{/each}
|
|
28
|
+
{#if !themes.length}
|
|
29
|
+
<option value={theme.current.theme}>{label(theme.current.theme)}</option>
|
|
30
|
+
{/if}
|
|
31
|
+
</select>
|
|
32
|
+
<button
|
|
33
|
+
type="button"
|
|
34
|
+
class="btn btn-sm preset-tonal"
|
|
35
|
+
title="Switch between light and dark"
|
|
36
|
+
aria-pressed={theme.current.mode === 'dark'}
|
|
37
|
+
onclick={() => theme.toggleMode()}
|
|
38
|
+
>
|
|
39
|
+
{theme.current.mode === 'dark' ? '🌙' : '☀️'}
|
|
40
|
+
</button>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<style>
|
|
44
|
+
.sr-only {
|
|
45
|
+
position: absolute;
|
|
46
|
+
width: 1px;
|
|
47
|
+
height: 1px;
|
|
48
|
+
overflow: hidden;
|
|
49
|
+
clip-path: inset(50%);
|
|
50
|
+
}
|
|
51
|
+
</style>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A schema's shipped defaults, through the SDK's own settings entry point so
|
|
3
|
+
* "unset inherits the shipped default" means here exactly what it means at
|
|
4
|
+
* install. `defineSettings` validates as it builds, and a modder halfway
|
|
5
|
+
* through writing a schema must not get a blank page for it — so a refusal
|
|
6
|
+
* degrades to "no defaults" and the form still renders.
|
|
7
|
+
*/
|
|
8
|
+
import { defineSettings, type SettingsSchema } from '@serene-pub/sdk'
|
|
9
|
+
|
|
10
|
+
export function defaultsOf(schema: SettingsSchema): Record<string, unknown> {
|
|
11
|
+
try {
|
|
12
|
+
return defineSettings(schema as never).defaults()
|
|
13
|
+
} catch {
|
|
14
|
+
return {}
|
|
15
|
+
}
|
|
16
|
+
}
|