@livespace/plugin-studio 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +122 -2
- package/dist/auth.js +220 -0
- package/dist/cli.js +67 -0
- package/dist/keys.js +42 -0
- package/dist/manifest.js +16 -0
- package/dist/page/domain/address.js +79 -0
- package/dist/page/domain/connection.js +2 -0
- package/dist/page/domain/display.js +38 -0
- package/dist/page/domain/draft.js +80 -0
- package/dist/page/domain/failures-store.js +41 -0
- package/dist/page/domain/failures.js +75 -0
- package/dist/page/domain/layout-store.js +119 -0
- package/dist/page/domain/log-store.js +37 -0
- package/dist/page/domain/navigation-store.js +17 -0
- package/dist/page/domain/plugin-data.js +70 -0
- package/dist/page/domain/plugin-store.js +257 -0
- package/dist/page/domain/probe-store.js +100 -0
- package/dist/page/domain/profile-session.js +115 -0
- package/dist/page/domain/profile-store.js +51 -0
- package/dist/page/domain/samples.js +221 -0
- package/dist/page/domain/secrets-store.js +159 -0
- package/dist/page/domain/secrets.js +135 -0
- package/dist/page/domain/settings-data.js +64 -0
- package/dist/page/domain/settings-session.js +206 -0
- package/dist/page/domain/settings-store.js +62 -0
- package/dist/page/domain/slot-store.js +50 -0
- package/dist/page/domain/studio.js +162 -0
- package/dist/page/domain/surface-store.js +71 -0
- package/dist/page/domain/toasts-store.js +60 -0
- package/dist/page/domain/view-data.js +122 -0
- package/dist/page/domain/view-store.js +132 -0
- package/dist/page/host.css +907 -0
- package/dist/page/index.html +31 -0
- package/dist/page/main.js +43 -0
- package/dist/page/plugin-studio-logo.svg +4 -0
- package/dist/page/reload.svg +1 -0
- package/dist/page/transport/browser-storage.js +41 -0
- package/dist/page/transport/console-mirror.js +48 -0
- package/dist/page/transport/embed.js +142 -0
- package/dist/page/transport/plugin-keys.js +68 -0
- package/dist/page/transport/studio-api.js +74 -0
- package/dist/page/ui/app.js +61 -0
- package/dist/page/ui/boot.js +44 -0
- package/dist/page/ui/brand.js +3 -0
- package/dist/page/ui/context.js +11 -0
- package/dist/page/ui/json-field.js +19 -0
- package/dist/page/ui/json-tokens.js +40 -0
- package/dist/page/ui/json-view.js +11 -0
- package/dist/page/ui/memo.js +23 -0
- package/dist/page/ui/messages.js +34 -0
- package/dist/page/ui/page-switcher.js +11 -0
- package/dist/page/ui/plugin-frame.js +43 -0
- package/dist/page/ui/profile-page.js +13 -0
- package/dist/page/ui/resize-handle.js +63 -0
- package/dist/page/ui/root.js +9 -0
- package/dist/page/ui/section.js +19 -0
- package/dist/page/ui/settings/config-form.js +59 -0
- package/dist/page/ui/settings/secret-field.js +22 -0
- package/dist/page/ui/settings/settings-page.js +60 -0
- package/dist/page/ui/sidebar/custom-settings-section.js +10 -0
- package/dist/page/ui/sidebar/failures-section.js +27 -0
- package/dist/page/ui/sidebar/installation-section.js +30 -0
- package/dist/page/ui/sidebar/metadata-section.js +9 -0
- package/dist/page/ui/sidebar/plugin-section.js +18 -0
- package/dist/page/ui/sidebar/preferences-section.js +16 -0
- package/dist/page/ui/sidebar/record-section.js +17 -0
- package/dist/page/ui/sidebar/viewer-section.js +8 -0
- package/dist/page/ui/sidebar-group.js +4 -0
- package/dist/page/ui/splash.js +6 -0
- package/dist/page/ui/status.js +10 -0
- package/dist/page/ui/surface.js +23 -0
- package/dist/page/ui/theme.js +13 -0
- package/dist/page/ui/toasts.js +31 -0
- package/dist/page/ui/top-bar.js +37 -0
- package/dist/server.js +519 -0
- package/dist/start.js +108 -0
- package/package.json +55 -5
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Components that re-render only when their props change. Preact's own `memo` lives in
|
|
3
|
+
* `preact/compat`, which the page doesn't load.
|
|
4
|
+
*/
|
|
5
|
+
import { Component, } from "preact";
|
|
6
|
+
const sameProps = (a, b) => {
|
|
7
|
+
const keys = Object.keys(a);
|
|
8
|
+
return (keys.length === Object.keys(b).length &&
|
|
9
|
+
keys.every((key) => a[key] ===
|
|
10
|
+
b[key]));
|
|
11
|
+
};
|
|
12
|
+
/** `render`, re-run only when a prop changes identity. */
|
|
13
|
+
export function memo(render) {
|
|
14
|
+
class Memo extends Component {
|
|
15
|
+
shouldComponentUpdate(next) {
|
|
16
|
+
return !sameProps(this.props, next);
|
|
17
|
+
}
|
|
18
|
+
render(props) {
|
|
19
|
+
return render(props);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return Memo;
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/** The messages pane: the log, newest at the bottom, followed while it's scrolled to the end. */
|
|
3
|
+
import { useLayoutEffect, useRef } from "preact/hooks";
|
|
4
|
+
import { useStudio } from "./context.js";
|
|
5
|
+
import { JsonView } from "./json-view.js";
|
|
6
|
+
import { memo } from "./memo.js";
|
|
7
|
+
const ARROWS = { in: "←", out: "→", note: "·" };
|
|
8
|
+
const timeOf = (at) => new Date(at).toLocaleTimeString(undefined, { hour12: false });
|
|
9
|
+
const Row = memo(function Row({ entry }) {
|
|
10
|
+
const head = (_jsxs(_Fragment, { children: [_jsx("span", { class: "time", children: timeOf(entry.at) }), _jsx("span", { class: "direction", children: ARROWS[entry.direction] }), entry.type, entry.source ? _jsx("span", { class: "source", children: entry.source }) : null] }));
|
|
11
|
+
return (_jsx("li", { class: entry.direction, children: "payload" in entry ? (_jsxs("details", { children: [_jsx("summary", { children: head }), _jsx(JsonView, { value: entry.payload })] })) : (head) }));
|
|
12
|
+
});
|
|
13
|
+
export function Messages() {
|
|
14
|
+
const { log } = useStudio();
|
|
15
|
+
const entries = log.entries.value;
|
|
16
|
+
const list = useRef(null);
|
|
17
|
+
// Whether the list was at its end before this render: if so, it follows the new entries.
|
|
18
|
+
const following = useRef(true);
|
|
19
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: new entries are what it runs on.
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
const element = list.current;
|
|
22
|
+
if (element !== null && following.current) {
|
|
23
|
+
element.scrollTop = element.scrollHeight;
|
|
24
|
+
}
|
|
25
|
+
}, [entries]);
|
|
26
|
+
const scrolled = () => {
|
|
27
|
+
const element = list.current;
|
|
28
|
+
if (element !== null) {
|
|
29
|
+
following.current =
|
|
30
|
+
element.scrollHeight - element.scrollTop - element.clientHeight < 8;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return (_jsxs("aside", { id: "messages", class: "messages", "aria-label": "Messages", children: [_jsxs("header", { class: "messages-head wa-split", children: [_jsx("h2", { children: "Messages" }), _jsx("wa-button", { size: "s", appearance: "plain", onClick: log.clear, children: "Clear" })] }), _jsx("ol", { ref: list, class: "log-list", onScroll: scrolled, children: entries.map((entry) => (_jsx(Row, { entry: entry }, entry.id))) })] }));
|
|
34
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
import { useStudio } from "./context.js";
|
|
3
|
+
const PAGES = [
|
|
4
|
+
{ name: "profile", label: "Profile" },
|
|
5
|
+
{ name: "settings", label: "Settings" },
|
|
6
|
+
];
|
|
7
|
+
export function PageSwitcher() {
|
|
8
|
+
const { navigation } = useStudio();
|
|
9
|
+
const page = navigation.page.value;
|
|
10
|
+
return (_jsx("nav", { "aria-label": "Pages", class: "pages page-switcher wa-cluster wa-gap-3xs", children: PAGES.map(({ name, label }) => (_jsx("a", { href: `#${name}`, "aria-current": page === name ? "page" : undefined, children: label }, name))) }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* One embed of the plugin, as Livespace makes it: its sandbox and permissions, and a listener that
|
|
4
|
+
* hears only this iframe, on the plugin's origin. The iframe is created once per address and never
|
|
5
|
+
* touched by Preact, so nothing the studio renders can reload the plugin.
|
|
6
|
+
*/
|
|
7
|
+
import { IFRAME_ALLOW, IFRAME_SANDBOX } from "@livespace/plugin-sdk";
|
|
8
|
+
import { useEffect, useRef } from "preact/hooks";
|
|
9
|
+
import { memo } from "./memo.js";
|
|
10
|
+
export const PluginFrame = memo(function PluginFrame(props) {
|
|
11
|
+
const host = useRef(null);
|
|
12
|
+
// The latest, without re-embedding when only the callback's identity changes.
|
|
13
|
+
const connect = useRef(props.connect);
|
|
14
|
+
connect.current = props.connect;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const container = host.current;
|
|
17
|
+
if (container === null) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const origin = new URL(props.url).origin;
|
|
21
|
+
const iframe = document.createElement("iframe");
|
|
22
|
+
iframe.title = props.title;
|
|
23
|
+
iframe.setAttribute("sandbox", IFRAME_SANDBOX);
|
|
24
|
+
iframe.allow = IFRAME_ALLOW;
|
|
25
|
+
iframe.referrerPolicy = "no-referrer";
|
|
26
|
+
const session = connect.current((message) => iframe.contentWindow?.postMessage(message, origin));
|
|
27
|
+
const listener = (event) => {
|
|
28
|
+
if (event.origin === origin && event.source === iframe.contentWindow) {
|
|
29
|
+
session.receive(event.data);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
window.addEventListener("message", listener);
|
|
33
|
+
iframe.addEventListener("load", session.loaded);
|
|
34
|
+
iframe.src = props.url;
|
|
35
|
+
container.append(iframe);
|
|
36
|
+
return () => {
|
|
37
|
+
window.removeEventListener("message", listener);
|
|
38
|
+
session.dispose();
|
|
39
|
+
iframe.remove();
|
|
40
|
+
};
|
|
41
|
+
}, [props.url, props.title]);
|
|
42
|
+
return (_jsx("div", { ref: host, id: props.id, class: props.class }));
|
|
43
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
/** The profile page: the plugin in view mode, in Livespace's chrome, in a profile column. */
|
|
3
|
+
import { useEffect } from "preact/hooks";
|
|
4
|
+
import { useStudio } from "./context.js";
|
|
5
|
+
import { PluginFrame } from "./plugin-frame.js";
|
|
6
|
+
import { Surface } from "./surface.js";
|
|
7
|
+
export function ProfilePage({ url }) {
|
|
8
|
+
const { profile, log } = useStudio();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
log.append("note", `Profile page: embedding ${url}`);
|
|
11
|
+
}, [log, url]);
|
|
12
|
+
return (_jsx("section", { id: "profile-page", class: "page", "aria-label": "Profile page", children: _jsx(Surface, { surface: profile.surface, title: "Plugin", children: _jsx(PluginFrame, { id: "slot", class: "slot", url: url, title: "Plugin", connect: profile.connect }) }) }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A handle between two panes: dragged with the pointer, or moved by the arrow keys when focused.
|
|
4
|
+
* While it's dragged, the plugins' iframes let the pointer through (host.css), or an iframe under
|
|
5
|
+
* the pointer would take the moves, pointer capture or not.
|
|
6
|
+
*
|
|
7
|
+
* A drag ends on any sign that the button is up: a release or cancel anywhere in the window, lost
|
|
8
|
+
* pointer capture, the window losing focus, or a move with no button pressed. So it can't be left
|
|
9
|
+
* following the pointer when one of them doesn't reach the handle.
|
|
10
|
+
*/
|
|
11
|
+
import { useEffect, useRef } from "preact/hooks";
|
|
12
|
+
export function ResizeHandle(props) {
|
|
13
|
+
// The latest props, for listeners that outlive a render: the panes re-render on every move.
|
|
14
|
+
const latest = useRef(props);
|
|
15
|
+
latest.current = props;
|
|
16
|
+
/** Ends the drag in progress, if there is one. */
|
|
17
|
+
const end = useRef(null);
|
|
18
|
+
useEffect(() => () => end.current?.(), []);
|
|
19
|
+
const start = (event) => {
|
|
20
|
+
if (event.button !== 0 || end.current !== null) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
const handle = event.currentTarget;
|
|
25
|
+
handle.setPointerCapture(event.pointerId);
|
|
26
|
+
handle.dataset.dragging = "";
|
|
27
|
+
document.body.dataset.resizing = "";
|
|
28
|
+
const move = (moved) => {
|
|
29
|
+
if (moved.buttons === 0) {
|
|
30
|
+
stop();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
latest.current.resize(latest.current.widthAt(moved.clientX));
|
|
34
|
+
};
|
|
35
|
+
const stop = () => {
|
|
36
|
+
window.removeEventListener("pointermove", move);
|
|
37
|
+
window.removeEventListener("pointerup", stop);
|
|
38
|
+
window.removeEventListener("pointercancel", stop);
|
|
39
|
+
window.removeEventListener("blur", stop);
|
|
40
|
+
handle.removeEventListener("lostpointercapture", stop);
|
|
41
|
+
if (handle.hasPointerCapture(event.pointerId)) {
|
|
42
|
+
handle.releasePointerCapture(event.pointerId);
|
|
43
|
+
}
|
|
44
|
+
delete handle.dataset.dragging;
|
|
45
|
+
delete document.body.dataset.resizing;
|
|
46
|
+
end.current = null;
|
|
47
|
+
};
|
|
48
|
+
window.addEventListener("pointermove", move);
|
|
49
|
+
window.addEventListener("pointerup", stop);
|
|
50
|
+
window.addEventListener("pointercancel", stop);
|
|
51
|
+
window.addEventListener("blur", stop);
|
|
52
|
+
handle.addEventListener("lostpointercapture", stop);
|
|
53
|
+
end.current = stop;
|
|
54
|
+
};
|
|
55
|
+
const key = (event) => {
|
|
56
|
+
if (event.key !== "ArrowLeft" && event.key !== "ArrowRight") {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
props.step(event.key === props.grow ? 1 : -1);
|
|
61
|
+
};
|
|
62
|
+
return (_jsx("div", { class: "resize-handle", role: "separator", "aria-orientation": "vertical", "aria-label": props.label, "aria-controls": props.controls, "aria-valuenow": Math.round(props.width), "aria-valuemin": props.min, tabIndex: 0, onPointerDown: start, onKeyDown: key }));
|
|
63
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { App } from "./app.js";
|
|
3
|
+
import { Splash } from "./splash.js";
|
|
4
|
+
export function Root({ phase }) {
|
|
5
|
+
const now = phase.value;
|
|
6
|
+
const drawn = now.kind === "drawing" || now.kind === "ready";
|
|
7
|
+
// Always in the same places, so the app isn't drawn anew, iframes and all, when the splash goes.
|
|
8
|
+
return (_jsxs(_Fragment, { children: [drawn ? _jsx(App, {}) : null, now.kind === "ready" ? null : (_jsx(Splash, { problem: now.kind === "failed" ? now.reason : undefined }))] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useStudio } from "./context.js";
|
|
3
|
+
export function Section(props) {
|
|
4
|
+
const { layout } = useStudio();
|
|
5
|
+
// Read through the signal, so the section follows the store.
|
|
6
|
+
layout.sections.value;
|
|
7
|
+
const open = layout.isOpen(props.name, props.initiallyOpen ?? false);
|
|
8
|
+
// Its own show and hide only: elements inside it fire the same events, and they bubble.
|
|
9
|
+
const toggled = (event, next) => {
|
|
10
|
+
if (event.target === event.currentTarget) {
|
|
11
|
+
layout.setOpen(props.name, next);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
return (_jsxs("wa-details", { class: "section", "data-section": props.name, "data-unused": props.unused ? "" : undefined, appearance: "plain", "icon-placement": "start", open: open, "onwa-show": (event) => toggled(event, true), "onwa-hide": (event) => toggled(event, false), children: [_jsxs("span", { slot: "summary", class: "section-summary", children: [props.title, props.unused ? _jsx(UnusedMark, { reason: props.unused }) : null] }), props.children] }));
|
|
15
|
+
}
|
|
16
|
+
/** A warning triangle; its reason shows on hover, and is read out as its name. */
|
|
17
|
+
function UnusedMark({ reason }) {
|
|
18
|
+
return (_jsx("span", { class: "section-unused", role: "img", "aria-label": reason, title: reason, children: _jsxs("svg", { width: "14", height: "14", viewBox: "0 0 16 16", "aria-hidden": "true", children: [_jsx("path", { class: "sign", d: "M8 1.5 15 14H1L8 1.5Z", "stroke-linejoin": "round" }), _jsx("path", { class: "mark", d: "M8 6v3.75M8 11.75v.1", "stroke-width": "1.6", "stroke-linecap": "round" })] }) }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { isSecretField } from "@livespace/plugin-sdk";
|
|
3
|
+
import { errorText } from "../../domain/settings-data.js";
|
|
4
|
+
import { Status, fieldValue } from "../status.js";
|
|
5
|
+
import { SecretField } from "./secret-field.js";
|
|
6
|
+
const labelOf = (field) => field.label + ("required" in field && field.required ? " *" : "");
|
|
7
|
+
const text = (value) => (value === undefined ? "" : String(value));
|
|
8
|
+
/** One value field's control, set to its value and reporting every change. */
|
|
9
|
+
function ValueControl({ field, value, session, }) {
|
|
10
|
+
const label = labelOf(field);
|
|
11
|
+
const hint = field.helpText;
|
|
12
|
+
const typed = (event) => session.setValue(field, fieldValue(event));
|
|
13
|
+
switch (field.kind) {
|
|
14
|
+
case "checkbox":
|
|
15
|
+
return (_jsx("wa-checkbox", { size: "s", checked: value === true, hint: hint, onChange: (event) => session.setValue(field, event.target.checked), children: label }));
|
|
16
|
+
case "select":
|
|
17
|
+
return (_jsxs("wa-select", { size: "s", label: label, hint: hint, value: typeof value === "string" ? value : "", onChange: typed, children: [_jsx("wa-option", { value: "", children: "\u2014" }), field.options.map((option) => (_jsx("wa-option", { value: option.value, children: option.label }, option.value)))] }));
|
|
18
|
+
case "textarea":
|
|
19
|
+
return (_jsx("wa-textarea", { size: "s", label: label, hint: hint, rows: 4, placeholder: field.placeholder, maxlength: field.maxLength, value: text(value), onInput: typed }));
|
|
20
|
+
case "number":
|
|
21
|
+
return (_jsx("wa-input", { size: "s", type: "number", label: label, hint: hint, min: field.min, max: field.max, step: field.step, value: text(value), onInput: typed }));
|
|
22
|
+
default:
|
|
23
|
+
return (_jsx("wa-input", { size: "s", label: label, hint: hint, placeholder: field.placeholder, value: text(value), onInput: typed }));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function ConfigForm({ form, session, secrets, }) {
|
|
27
|
+
const values = session.values.value;
|
|
28
|
+
const errors = session.errors.value;
|
|
29
|
+
// Fields gather under the section before them, as fieldsets.
|
|
30
|
+
const groups = [{ items: [] }];
|
|
31
|
+
for (const field of form.fields) {
|
|
32
|
+
if (field.kind === "section") {
|
|
33
|
+
groups.push({
|
|
34
|
+
title: field.title,
|
|
35
|
+
description: field.description,
|
|
36
|
+
items: [],
|
|
37
|
+
});
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const group = groups[groups.length - 1];
|
|
41
|
+
if (group === undefined) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (field.kind === "helpText") {
|
|
45
|
+
group.items.push(_jsx("p", { class: "hint", children: field.text }));
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (isSecretField(field)) {
|
|
49
|
+
group.items.push(_jsx(SecretField, { field: field, secrets: secrets, label: labelOf(field) }, field.key));
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const error = errors?.[field.key];
|
|
53
|
+
group.items.push(_jsxs("div", { class: "field", children: [_jsx(ValueControl, { field: field, value: values[field.key], session: session }), _jsx(Status, { error: true, text: error ? errorText(error) : undefined })] }, field.key));
|
|
54
|
+
}
|
|
55
|
+
return (_jsx("form", { class: "config-form wa-stack wa-gap-s", noValidate: true, onSubmit: (event) => {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
void session.save();
|
|
58
|
+
}, children: groups.map((group, index) => group.title === undefined ? (_jsx("div", { class: "wa-stack wa-gap-s", children: group.items }, index)) : (_jsxs("fieldset", { class: "wa-stack wa-gap-s", children: [_jsx("legend", { children: group.title }), group.description ? _jsx("p", { class: "hint", children: group.description }) : null, group.items] }, index))) }));
|
|
59
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { Status, fieldValue } from "../status.js";
|
|
3
|
+
export function SecretField({ field, secrets, label, }) {
|
|
4
|
+
const state = secrets.stateOf(field.key);
|
|
5
|
+
const change = secrets.changes.value[field.key];
|
|
6
|
+
const stored = secrets.stored.value[field.key];
|
|
7
|
+
const error = secrets.errors.value[field.key];
|
|
8
|
+
let control;
|
|
9
|
+
if (state === "set" && change === undefined) {
|
|
10
|
+
control = (_jsxs("div", { class: "wa-stack wa-gap-3xs", children: [_jsx("span", { class: "field-label", children: label }), _jsxs("div", { class: "wa-cluster wa-gap-xs", children: [_jsxs("span", { class: "secret-set", children: ["Set (sealed for ", stored?.kid, ")"] }), _jsx("wa-button", { size: "s", onClick: () => secrets.replace(field.key), children: "Replace" }), field.required ? null : (_jsx("wa-button", { size: "s", onClick: () => secrets.clear(field.key), children: "Clear" }))] })] }));
|
|
11
|
+
}
|
|
12
|
+
else if (change?.kind === "clear") {
|
|
13
|
+
control = (_jsxs("div", { class: "wa-stack wa-gap-3xs", children: [_jsx("span", { class: "field-label", children: label }), _jsxs("div", { class: "wa-cluster wa-gap-xs", children: [_jsx("span", { class: "hint", children: "Will be cleared on Save." }), _jsx("wa-button", { size: "s", onClick: () => secrets.undo(field.key), children: "Undo" })] })] }));
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
// Unset, to enter again, or being replaced: never pre-filled.
|
|
17
|
+
control = (_jsxs("div", { class: "wa-stack wa-gap-3xs", children: [_jsx("wa-input", { size: "s", type: "password", label: label, autocomplete: "off", placeholder: field.placeholder ?? "", value: change?.kind === "replace" ? change.value : "", onInput: (event) => secrets.type(field.key, fieldValue(event)) }), state === "set" ? (_jsx("div", { class: "wa-cluster", children: _jsx("wa-button", { size: "s", onClick: () => secrets.undo(field.key), children: "Cancel" }) })) : null, _jsx(Status, { error: true, text: state === "reenter"
|
|
18
|
+
? `Stored under ${stored?.kid}, a key the plugin no longer lists. Enter it again.`
|
|
19
|
+
: undefined })] }));
|
|
20
|
+
}
|
|
21
|
+
return (_jsxs("div", { class: "field secret", children: [control, field.helpText ? _jsx("p", { class: "hint", children: field.helpText }) : null, _jsx(Status, { error: true, text: error })] }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The settings page, as the plugins-2 settings screen: the plugin's form, as the config probe heard
|
|
4
|
+
* it, beside a live preview. Each visit is a session, gone when the page is.
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useState } from "preact/hooks";
|
|
7
|
+
import { CONFIG_FORM_TIMEOUT_MS } from "../../domain/settings-data.js";
|
|
8
|
+
import { useStudio } from "../context.js";
|
|
9
|
+
import { PluginFrame } from "../plugin-frame.js";
|
|
10
|
+
import { Status } from "../status.js";
|
|
11
|
+
import { Surface } from "../surface.js";
|
|
12
|
+
import { ConfigForm } from "./config-form.js";
|
|
13
|
+
const FORM_STATUS = {
|
|
14
|
+
asking: { text: "Asking the plugin for its form…", isError: false },
|
|
15
|
+
timedOut: {
|
|
16
|
+
text: `The plugin didn't answer with its form in ${CONFIG_FORM_TIMEOUT_MS / 1000} s. Livespace would show an error here; does it answer request-config-form?`,
|
|
17
|
+
isError: true,
|
|
18
|
+
},
|
|
19
|
+
unusable: {
|
|
20
|
+
text: "The plugin's form isn't usable: it needs { fields: [...] }.",
|
|
21
|
+
isError: true,
|
|
22
|
+
},
|
|
23
|
+
empty: {
|
|
24
|
+
text: "The plugin answered with no fields: it has no settings.",
|
|
25
|
+
isError: false,
|
|
26
|
+
},
|
|
27
|
+
ready: {
|
|
28
|
+
text: "The plugin's form, as Livespace renders it.",
|
|
29
|
+
isError: false,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
function Form({ session }) {
|
|
33
|
+
const { secrets } = session;
|
|
34
|
+
const form = session.form.value;
|
|
35
|
+
const status = FORM_STATUS[session.formStatus.value.kind];
|
|
36
|
+
const hasFields = session.valueFields.value.length + session.secretFields.value.length > 0;
|
|
37
|
+
const keys = secrets.keysStatus.value;
|
|
38
|
+
const saveStatus = session.saveStatus.value;
|
|
39
|
+
return (_jsxs("div", { class: "card settings-form wa-stack wa-gap-s", children: [_jsx("h2", { children: "Settings" }), _jsx(Status, { text: status.text, error: status.isError }), session.secretFields.value.length > 0 && keys !== null ? (_jsxs("div", { class: "wa-flank:end wa-gap-xs keys-row", children: [_jsx(Status, { text: keys.text, error: keys.isError }), _jsx("wa-button", { size: "s", onClick: secrets.checkKeys, children: "Check again" })] })) : null, form === null ? null : (_jsx(ConfigForm, { form: form, session: session, secrets: secrets })), _jsx("div", { class: "wa-cluster wa-gap-xs", children: _jsx("wa-button", { size: "s", variant: "brand", disabled: !hasFields, onClick: session.save, children: "Save" }) }), _jsx(Status, { text: saveStatus?.text, error: saveStatus?.isError })] }));
|
|
40
|
+
}
|
|
41
|
+
function Preview({ session, url }) {
|
|
42
|
+
const { width, height, scale } = session.geometry.value;
|
|
43
|
+
// The slot's own width, whatever the surface shows now: the dialog has its own.
|
|
44
|
+
const slot = useStudio().slot.size.value;
|
|
45
|
+
return (_jsxs("div", { class: "preview-pane wa-stack wa-gap-xs", "data-slot": slot.width === null ? "full" : "column", style: slot.width === null ? undefined : { width: `${slot.width}px` }, children: [_jsx("h2", { children: "Preview" }), _jsx(Surface, { surface: session.surface, title: "Preview", children: _jsx("div", { class: "slot preview-box", children: _jsx("div", { class: "preview-scale", style: {
|
|
46
|
+
width: width === null ? "100%" : `${width}px`,
|
|
47
|
+
height: `${height}px`,
|
|
48
|
+
transform: scale === 1 ? "" : `scale(${scale})`,
|
|
49
|
+
}, children: _jsx(PluginFrame, { class: "fill", url: url, title: "Plugin preview", connect: session.connectPreview }) }) }) }), _jsx("p", { class: "hint", children: "Preview mode, in the plugin's slot: no record, and the settings as typed." })] }));
|
|
50
|
+
}
|
|
51
|
+
export function SettingsPage({ url }) {
|
|
52
|
+
const { settings, log } = useStudio();
|
|
53
|
+
// One session per visit and address: App keys this page by its address.
|
|
54
|
+
const [session] = useState(() => settings.open(new URL(url).origin));
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
log.append("note", `Settings page: embedding ${url}`);
|
|
57
|
+
return () => session.dispose();
|
|
58
|
+
}, [log, session, url]);
|
|
59
|
+
return (_jsxs("section", { class: "page settings", "aria-label": "Settings page", children: [_jsx(Form, { session: session }), _jsx(Preview, { session: session, url: url })] }));
|
|
60
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/** What the plugin's own form saved: the config the profile page sends, and the stored secrets. */
|
|
3
|
+
import { useStudio } from "../context.js";
|
|
4
|
+
import { JsonView } from "../json-view.js";
|
|
5
|
+
export function CustomSettingsSection() {
|
|
6
|
+
const { settings } = useStudio();
|
|
7
|
+
const saved = settings.saved.value;
|
|
8
|
+
const secrets = Object.entries(settings.secrets.value);
|
|
9
|
+
return (_jsxs("div", { class: "section-body wa-stack wa-gap-xs", children: [saved === null ? (_jsxs("p", { class: "hint", children: ["Never saved: the profile page sends ", _jsx("code", { children: "config: null" }), "."] })) : (_jsxs("div", { class: "wa-stack wa-gap-3xs", children: [_jsx("span", { class: "field-label", children: "Config" }), _jsx(JsonView, { class: "sidebar-json", value: saved })] })), _jsxs("div", { class: "wa-stack wa-gap-3xs", children: [_jsx("span", { class: "field-label", children: "Secrets" }), secrets.length === 0 ? (_jsx("p", { class: "hint", children: "None stored." })) : (_jsx("ul", { class: "secret-list", children: secrets.map(([key, { kid }]) => (_jsxs("li", { children: [_jsx("code", { children: key }), " ", _jsxs("span", { class: "hint", children: ["sealed for ", kid] })] }, key))) }))] }), _jsx("div", { class: "wa-cluster wa-gap-xs", children: _jsx("wa-button", { size: "s", disabled: saved === null, onClick: settings.forget, children: "Forget saved settings" }) }), _jsx("p", { class: "hint", children: "Saved on the settings page, by the plugin's own form." })] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/** The failure switches. The settings preview asks for nothing they answer. */
|
|
3
|
+
import { CREDENTIALS_CHOICES, EXCHANGE_CHOICES, TOKEN_CHOICES, } from "../../domain/failures.js";
|
|
4
|
+
import { useStudio } from "../context.js";
|
|
5
|
+
import { fieldValue } from "../status.js";
|
|
6
|
+
const SWITCHES = [
|
|
7
|
+
{
|
|
8
|
+
name: "credentials",
|
|
9
|
+
label: "API credentials (api.call)",
|
|
10
|
+
choices: CREDENTIALS_CHOICES,
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: "token",
|
|
14
|
+
label: "Plugin tokens (backend.fetch)",
|
|
15
|
+
choices: TOKEN_CHOICES,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "exchange",
|
|
19
|
+
label: "Token exchange (your backend)",
|
|
20
|
+
choices: EXCHANGE_CHOICES,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
export function FailuresSection() {
|
|
24
|
+
const { failures } = useStudio();
|
|
25
|
+
const current = failures.failures.value;
|
|
26
|
+
return (_jsxs("div", { class: "section-body wa-stack wa-gap-xs", children: [SWITCHES.map(({ name, label, choices }) => (_jsx("wa-select", { size: "s", label: label, value: current[name], onChange: (event) => failures.set(name, fieldValue(event)), children: choices.map(({ value, label: text }) => (_jsx("wa-option", { value: value, children: text }, value))) }, name))), _jsx("p", { class: "hint", children: "There's no real Livespace account behind the studio, so API credentials are always refused." })] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Where the plugin is installed: the profile type, or the apps menu, and the slot, whose column
|
|
4
|
+
* decides its width. Stored, but not by the plugin's own form.
|
|
5
|
+
*/
|
|
6
|
+
import { COLUMN_WIDTHS } from "../../domain/display.js";
|
|
7
|
+
import { MAX_HEIGHT_PX, MIN_HEIGHT_PX } from "../../domain/slot-store.js";
|
|
8
|
+
import { useStudio } from "../context.js";
|
|
9
|
+
import { fieldValue } from "../status.js";
|
|
10
|
+
const FULL = "full";
|
|
11
|
+
/** Where the choices come from, as how accounts add it decides. */
|
|
12
|
+
function installedWhere(distribution, declared, heard) {
|
|
13
|
+
if (distribution === "catalog") {
|
|
14
|
+
return "Where its catalog manifest allows (allowedObjectTypes).";
|
|
15
|
+
}
|
|
16
|
+
if (declared) {
|
|
17
|
+
return "Where the plugin declares it can go (supportedContextTypes).";
|
|
18
|
+
}
|
|
19
|
+
return heard
|
|
20
|
+
? "Anywhere, the apps menu included: it declares no context types."
|
|
21
|
+
: "Anywhere, until the plugin declares otherwise.";
|
|
22
|
+
}
|
|
23
|
+
export function InstallationSection() {
|
|
24
|
+
const { plugin, slot, view } = useStudio();
|
|
25
|
+
const { width, height } = slot.size.value;
|
|
26
|
+
return (_jsxs("div", { class: "section-body wa-stack wa-gap-xs", children: [_jsx("wa-select", { size: "s", label: "Installed on", value: view.choice.value, onChange: (event) => view.choose(fieldValue(event)), children: plugin.recordChoices.value.map(({ value, label }) => (_jsx("wa-option", { value: value, children: label }, value))) }), _jsx("wa-select", { size: "s", label: "Slot", value: width === null ? FULL : String(width), onChange: (event) => {
|
|
27
|
+
const value = fieldValue(event);
|
|
28
|
+
slot.setWidth(value === FULL ? null : Number(value));
|
|
29
|
+
}, children: COLUMN_WIDTHS.map(({ value, label }) => (_jsx("wa-option", { value: value === null ? FULL : String(value), children: label }, String(value)))) }), _jsx("wa-input", { size: "s", type: "number", label: "Height", min: MIN_HEIGHT_PX, max: MAX_HEIGHT_PX, step: 10, value: String(height), onChange: (event) => slot.setHeight(Number(fieldValue(event))) }), _jsx("p", { class: "hint", children: installedWhere(plugin.distribution.value, plugin.metadata.value?.supportedContextTypes, plugin.metadata.value !== null) }), _jsx("p", { class: "hint", children: "Both pages show the plugin inline, in its slot's column. Its toolbar opens the dialog and fullscreen." })] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-runtime";
|
|
2
|
+
/** What the plugin last declared about where it fits, heard by the config probe. */
|
|
3
|
+
import { useStudio } from "../context.js";
|
|
4
|
+
import { JsonView } from "../json-view.js";
|
|
5
|
+
export function MetadataSection() {
|
|
6
|
+
const { plugin } = useStudio();
|
|
7
|
+
const metadata = plugin.metadata.value;
|
|
8
|
+
return (_jsx("div", { class: "section-body wa-stack wa-gap-xs", children: metadata === null ? (_jsx("p", { class: "hint", children: "Nothing declared yet: the hidden config probe hears it when the plugin sends it." })) : (_jsxs(_Fragment, { children: [_jsx(JsonView, { class: "sidebar-json", value: metadata }), _jsxs("p", { class: "hint", children: ["Where it fits, as it declared it with ", _jsx("code", { children: "declareMetadata" }), ", and as Livespace keeps it."] })] })) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The Plugin section, on both pages: the client id, how accounts add the plugin (which decides
|
|
4
|
+
* where its keys are), its catalog manifest, and the env values a backend sets.
|
|
5
|
+
*/
|
|
6
|
+
import { useStudio } from "../context.js";
|
|
7
|
+
import { JsonField } from "../json-field.js";
|
|
8
|
+
import { Status, fieldValue } from "../status.js";
|
|
9
|
+
export function PluginSection() {
|
|
10
|
+
const { plugin } = useStudio();
|
|
11
|
+
const distribution = plugin.distribution.value;
|
|
12
|
+
const suggested = plugin.suggestedClientId.value;
|
|
13
|
+
const manifest = plugin.manifestDraft.parsed.value;
|
|
14
|
+
const env = plugin.env.value;
|
|
15
|
+
return (_jsxs("div", { class: "section-body wa-stack wa-gap-s", children: [_jsxs("div", { class: "wa-stack wa-gap-3xs", children: [_jsx("wa-input", { size: "s", label: "Client id", value: plugin.clientIdDraft.text.value, spellcheck: false, autocomplete: "off", hint: "The plugin's identity as a client: the aud of its tokens, and who your backend signs the exchange as. Not the viewer.", onInput: (event) => plugin.clientIdDraft.edit(fieldValue(event)) }), _jsx(Status, { text: plugin.clientIdProblem.value, error: true }), suggested ? (_jsxs("p", { class: "hint", children: ["The manifest's id makes it", " ", _jsx("button", { type: "button", class: "link", onClick: () => plugin.adoptClientId(suggested), children: suggested }), "."] })) : null] }), _jsxs("wa-radio-group", { size: "s", label: "How accounts add it", value: distribution, onChange: (event) => plugin.setDistribution(fieldValue(event)), children: [_jsxs("wa-radio", { value: "url", children: ["By URL: keys at ", _jsx("code", { children: "/.well-known/livespace/jwks.json" })] }), _jsx("wa-radio", { value: "catalog", children: "From the catalog: keys in its manifest" })] }), distribution === "catalog" ? (_jsxs("div", { class: "wa-stack wa-gap-3xs", children: [_jsx(JsonField, { label: "Catalog manifest", draft: plugin.manifestDraft, describedBy: "manifest-status" }), _jsx("div", { class: "wa-cluster wa-gap-xs", children: _jsx("wa-button", { size: "s", onClick: plugin.loadProjectManifest, children: "Load the project's" }) }), _jsx(Status, { id: "manifest-status", error: !manifest.ok, text: manifest.ok
|
|
16
|
+
? plugin.manifestNote.value
|
|
17
|
+
: `Not used, so the last valid one stays. ${manifest.reason}` })] })) : null, _jsxs("div", { class: "wa-stack wa-gap-3xs", children: [_jsxs("div", { class: "wa-split", children: [_jsx("span", { class: "field-label", children: "Your backend's env" }), _jsx("wa-copy-button", { value: env, "copy-label": "Copy the env values", "success-label": "Copied" })] }), _jsx("pre", { class: "env", children: env })] })] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/** Livespace's settings for the viewer, and the preferences the plugin gets from them. */
|
|
3
|
+
import { PREFERENCE_PRESETS } from "../../domain/view-data.js";
|
|
4
|
+
import { CUSTOM } from "../../domain/view-store.js";
|
|
5
|
+
import { useStudio } from "../context.js";
|
|
6
|
+
import { JsonField } from "../json-field.js";
|
|
7
|
+
import { JsonView } from "../json-view.js";
|
|
8
|
+
import { Status, fieldValue } from "../status.js";
|
|
9
|
+
import { SENT } from "./record-section.js";
|
|
10
|
+
export function PreferencesSection() {
|
|
11
|
+
const { view } = useStudio();
|
|
12
|
+
const parsed = view.preferencesText.parsed.value;
|
|
13
|
+
return (_jsxs("div", { class: "section-body wa-stack wa-gap-xs", children: [_jsxs("wa-select", { size: "s", label: "Preset", class: "label-hidden", value: view.preset.value, onChange: (event) => view.choosePreset(fieldValue(event)), children: [PREFERENCE_PRESETS.map(({ value, label }) => (_jsx("wa-option", { value: value, children: label }, value))), _jsx("wa-option", { value: CUSTOM, children: "Custom" })] }), _jsx("p", { class: "hint", children: "Livespace's own settings, which it resolves into what the plugin gets." }), _jsx(JsonField, { label: "Livespace's settings, as JSON", draft: view.preferencesText, edit: view.editPreferences, describedBy: "preferences-status" }), _jsx(Status, { id: "preferences-status", error: !parsed.ok, text: parsed.ok
|
|
14
|
+
? SENT
|
|
15
|
+
: `Not sent, so the plugin keeps the last valid ones. ${parsed.reason}` }), _jsxs("details", { class: "nested", children: [_jsx("summary", { children: "What the plugin gets" }), _jsx(JsonView, { value: view.preferences.value })] })] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/** The record the plugin is shown with, as JSON, or none in the apps menu. The settings preview has none. */
|
|
3
|
+
import { useStudio } from "../context.js";
|
|
4
|
+
import { JsonField } from "../json-field.js";
|
|
5
|
+
import { Status } from "../status.js";
|
|
6
|
+
export const SENT = "Valid. The plugin gets it on every handshake, and again when it changes.";
|
|
7
|
+
export function RecordSection() {
|
|
8
|
+
const { view } = useStudio();
|
|
9
|
+
const choice = view.choice.value;
|
|
10
|
+
const parsed = view.record.parsed.value;
|
|
11
|
+
if (choice === "none") {
|
|
12
|
+
return (_jsx("div", { class: "section-body wa-stack wa-gap-xs", children: _jsx("p", { class: "hint", children: "Installed in the apps menu: no record, the plugin gets only the viewer." }) }));
|
|
13
|
+
}
|
|
14
|
+
return (_jsxs("div", { class: "section-body wa-stack wa-gap-xs", children: [_jsx(JsonField, { label: "The record, as JSON", draft: view.record, describedBy: "record-status" }), _jsx(Status, { id: "record-status", error: !parsed.ok, text: parsed.ok
|
|
15
|
+
? SENT
|
|
16
|
+
: `Not sent, so the plugin keeps the last valid one. ${parsed.reason}` }), _jsx("div", { class: "wa-cluster wa-gap-xs", children: _jsx("wa-button", { size: "s", disabled: !view.recordEdited.value, onClick: view.resetRecord, children: "Reset to sample" }) })] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/** The viewing user. The settings preview has none. */
|
|
3
|
+
import { useStudio } from "../context.js";
|
|
4
|
+
import { fieldValue } from "../status.js";
|
|
5
|
+
export function ViewerSection() {
|
|
6
|
+
const { view } = useStudio();
|
|
7
|
+
return (_jsxs("div", { class: "section-body wa-stack wa-gap-xs", children: [_jsx("wa-input", { size: "s", label: "User id", placeholder: "No user", spellcheck: false, value: view.viewer.text.value, onInput: (event) => view.viewer.edit(fieldValue(event)) }), _jsxs("p", { class: "hint", children: ["The viewing user: ", _jsx("code", { children: "context.user.id" }), ", and the ", _jsx("code", { children: "sub" }), " ", "of their plugin tokens."] })] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
export function SidebarGroup({ title, children, }) {
|
|
3
|
+
return (_jsxs("section", { class: "sidebar-group", "aria-label": title, children: [_jsx("h2", { class: "sidebar-group-title", children: title }), children] }));
|
|
4
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
/** The studio's name and logo, alone in the middle of the window, while the page starts. */
|
|
3
|
+
import { STUDIO_LOGO, STUDIO_NAME } from "./brand.js";
|
|
4
|
+
export function Splash({ problem }) {
|
|
5
|
+
return (_jsxs("div", { class: "splash", role: problem ? "alert" : "status", "aria-busy": problem ? undefined : "true", children: [_jsx("img", { class: "splash-logo", src: STUDIO_LOGO, alt: "" }), _jsx("strong", { class: "splash-name", children: STUDIO_NAME }), problem ? (_jsxs("p", { class: "problem", children: ["The studio couldn't start: ", problem] })) : null] }));
|
|
6
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
|
+
/** A line under a field: what happened to its value, or why it's wrong. */
|
|
3
|
+
export function Status({ id, text, error = false, }) {
|
|
4
|
+
if (text === undefined || text === "") {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return (_jsx("p", { id: id, class: error ? "status error" : "status", "aria-live": "polite", children: text }));
|
|
8
|
+
}
|
|
9
|
+
/** The value of the element an input event came from: a native control or a Web Awesome one. */
|
|
10
|
+
export const fieldValue = (event) => String(event.target.value ?? "");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "preact/jsx-runtime";
|
|
2
|
+
import { useEffect } from "preact/hooks";
|
|
3
|
+
export function Surface({ surface, title, children }) {
|
|
4
|
+
const display = surface.display.value;
|
|
5
|
+
const { width, height } = surface.frameSize.value;
|
|
6
|
+
// Escape is heard on the studio's page only, so it does nothing while the plugin has focus.
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const key = (event) => {
|
|
9
|
+
if (event.key === "Escape" && surface.display.peek() !== "inline") {
|
|
10
|
+
surface.leave();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
window.addEventListener("keydown", key);
|
|
14
|
+
return () => window.removeEventListener("keydown", key);
|
|
15
|
+
}, [surface]);
|
|
16
|
+
// A click on the dialog's backdrop closes it, as in Livespace.
|
|
17
|
+
const backdrop = (event) => {
|
|
18
|
+
if (event.target === event.currentTarget && display === "dialog") {
|
|
19
|
+
surface.show("inline");
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
return (_jsx("div", { class: "surface", "data-display": display, onClick: backdrop, children: _jsxs("div", { class: "frame", style: { width, height }, children: [_jsxs("div", { class: "chrome-bar", children: [_jsx("span", { class: "chrome-title", children: title }), display === "inline" ? (_jsx("button", { type: "button", onClick: () => surface.show("dialog"), children: "Open in dialog" })) : null, display !== "fullscreen" ? (_jsx("button", { type: "button", onClick: () => surface.show("fullscreen"), children: "Fullscreen" })) : null, display !== "inline" ? (_jsx("button", { type: "button", onClick: surface.leave, children: display === "fullscreen" ? "Exit fullscreen" : "Close" })) : null] }), children] }) }));
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Awesome's light or dark mode, following the system's colour scheme; dark when the system has
|
|
3
|
+
* no preference. `index.html` starts dark, so a dark page never flashes light.
|
|
4
|
+
*/
|
|
5
|
+
export function followColorScheme(root = document.documentElement, matchMedia = (query) => window.matchMedia(query)) {
|
|
6
|
+
const light = matchMedia("(prefers-color-scheme: light)");
|
|
7
|
+
const apply = () => {
|
|
8
|
+
root.classList.toggle("wa-dark", !light.matches);
|
|
9
|
+
root.classList.toggle("wa-light", light.matches);
|
|
10
|
+
};
|
|
11
|
+
apply();
|
|
12
|
+
light.addEventListener("change", apply);
|
|
13
|
+
}
|