@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,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text being typed, and the value read from it. The text follows every keystroke. What it's read
|
|
3
|
+
* as is committed once typing pauses, so the plugin isn't sent a message per keystroke. The last
|
|
4
|
+
* value that read well stays the value while the text doesn't.
|
|
5
|
+
*/
|
|
6
|
+
import { computed, effect, signal, } from "@preact/signals";
|
|
7
|
+
/** How long typing must pause before the text is read. */
|
|
8
|
+
export const COMMIT_DELAY_MS = 300;
|
|
9
|
+
export const timers = {
|
|
10
|
+
later: (run, ms) => setTimeout(run, ms),
|
|
11
|
+
cancel: (timer) => clearTimeout(timer),
|
|
12
|
+
};
|
|
13
|
+
export class Draft {
|
|
14
|
+
scheduler;
|
|
15
|
+
#text;
|
|
16
|
+
#committed;
|
|
17
|
+
#value;
|
|
18
|
+
#stopFollowing;
|
|
19
|
+
#timer;
|
|
20
|
+
/** The committed text, read: a value, or why it isn't one. */
|
|
21
|
+
parsed;
|
|
22
|
+
/** The last value that read well; `fallback` until one has. */
|
|
23
|
+
value;
|
|
24
|
+
constructor(initial,
|
|
25
|
+
/** Read inside a computed: the signals it reads re-read the text when they change. */
|
|
26
|
+
parse, fallback, scheduler = timers) {
|
|
27
|
+
this.scheduler = scheduler;
|
|
28
|
+
this.#text = signal(initial);
|
|
29
|
+
this.#committed = signal(initial);
|
|
30
|
+
this.parsed = computed(() => parse(this.#committed.value));
|
|
31
|
+
// Eager, so a value that read well is remembered whether or not anything was reading it.
|
|
32
|
+
this.#value = signal(fallback);
|
|
33
|
+
this.value = this.#value;
|
|
34
|
+
this.#stopFollowing = effect(() => {
|
|
35
|
+
const parsed = this.parsed.value;
|
|
36
|
+
if (parsed.ok) {
|
|
37
|
+
this.#value.value = parsed.value;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** The text as typed. */
|
|
42
|
+
get text() {
|
|
43
|
+
return this.#text;
|
|
44
|
+
}
|
|
45
|
+
/** The text that's been read, which lags `text` while typing. */
|
|
46
|
+
get committed() {
|
|
47
|
+
return this.#committed;
|
|
48
|
+
}
|
|
49
|
+
/** Typed: read once typing pauses. */
|
|
50
|
+
edit = (text) => {
|
|
51
|
+
this.#text.value = text;
|
|
52
|
+
this.#cancel();
|
|
53
|
+
this.#timer = this.scheduler.later(() => {
|
|
54
|
+
this.#timer = undefined;
|
|
55
|
+
this.#committed.value = this.#text.value;
|
|
56
|
+
}, COMMIT_DELAY_MS);
|
|
57
|
+
};
|
|
58
|
+
/** Set from elsewhere, such as a preset: read at once. */
|
|
59
|
+
set = (text) => {
|
|
60
|
+
this.#cancel();
|
|
61
|
+
this.#text.value = text;
|
|
62
|
+
this.#committed.value = text;
|
|
63
|
+
};
|
|
64
|
+
/** Reads what's been typed now, without waiting. */
|
|
65
|
+
flush = () => {
|
|
66
|
+
if (this.#timer !== undefined) {
|
|
67
|
+
this.set(this.#text.value);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
#cancel() {
|
|
71
|
+
if (this.#timer !== undefined) {
|
|
72
|
+
this.scheduler.cancel(this.#timer);
|
|
73
|
+
this.#timer = undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
dispose() {
|
|
77
|
+
this.#cancel();
|
|
78
|
+
this.#stopFollowing();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failure switches: how the studio answers the plugin's requests for API credentials and
|
|
3
|
+
* plugin tokens, and how the dev account's token exchange refuses. The exchange's lives on the
|
|
4
|
+
* server, which acts on it. Kept in this browser.
|
|
5
|
+
*/
|
|
6
|
+
import { effect, signal, } from "@preact/signals";
|
|
7
|
+
import { ACCEPT, DEFAULT_FAILURES } from "./failures.js";
|
|
8
|
+
export class FailuresStore {
|
|
9
|
+
deps;
|
|
10
|
+
#failures;
|
|
11
|
+
#stopSaving;
|
|
12
|
+
constructor(deps) {
|
|
13
|
+
this.deps = deps;
|
|
14
|
+
this.#failures = signal(deps.storage.read(DEFAULT_FAILURES));
|
|
15
|
+
this.#stopSaving = effect(() => deps.storage.write(this.#failures.value));
|
|
16
|
+
}
|
|
17
|
+
get failures() {
|
|
18
|
+
return this.#failures;
|
|
19
|
+
}
|
|
20
|
+
/** Tells the server how the exchange should answer, as switched. */
|
|
21
|
+
async load() {
|
|
22
|
+
await this.#pushExchange();
|
|
23
|
+
}
|
|
24
|
+
set = async (name, value) => {
|
|
25
|
+
if (this.#failures.value[name] === value) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
this.#failures.value = { ...this.#failures.value, [name]: value };
|
|
29
|
+
this.deps.log("note", `Failures: ${name} → ${value}`);
|
|
30
|
+
if (name === "exchange") {
|
|
31
|
+
await this.#pushExchange();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
#pushExchange() {
|
|
35
|
+
const { exchange } = this.#failures.value;
|
|
36
|
+
return this.deps.api.refuseExchanges(exchange === ACCEPT ? null : exchange);
|
|
37
|
+
}
|
|
38
|
+
dispose() {
|
|
39
|
+
this.#stopSaving();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The failure switches: what the studio answers when the plugin asks for API credentials or a
|
|
3
|
+
* plugin token, and how the dev account's exchange refuses, so a plugin and its backend can be
|
|
4
|
+
* tried against each failure Livespace can give. No DOM here.
|
|
5
|
+
*/
|
|
6
|
+
const CREDENTIAL_CODES = [
|
|
7
|
+
"bad_request",
|
|
8
|
+
"unauthenticated",
|
|
9
|
+
"forbidden",
|
|
10
|
+
"not_found",
|
|
11
|
+
"conflict",
|
|
12
|
+
"server_error",
|
|
13
|
+
];
|
|
14
|
+
export const NO_ANSWER = "no-answer";
|
|
15
|
+
export const CREDENTIALS_CHOICES = [
|
|
16
|
+
...CREDENTIAL_CODES.map((code) => ({
|
|
17
|
+
value: code,
|
|
18
|
+
label: `Refuse: ${code}`,
|
|
19
|
+
})),
|
|
20
|
+
{ value: NO_ANSWER, label: "No answer (the SDK times out)" },
|
|
21
|
+
];
|
|
22
|
+
export const TOKEN = "token";
|
|
23
|
+
export const EVERY_OTHER_EXPIRED = "every-other-expired";
|
|
24
|
+
export const TOKEN_CHOICES = [
|
|
25
|
+
{ value: TOKEN, label: "A token for the viewer" },
|
|
26
|
+
{
|
|
27
|
+
value: EVERY_OTHER_EXPIRED,
|
|
28
|
+
label: "Every other token already expired (exercises the retry after a 401)",
|
|
29
|
+
},
|
|
30
|
+
...[...CREDENTIAL_CODES, "not_purchased"].map((code) => ({
|
|
31
|
+
value: code,
|
|
32
|
+
label: `Refuse: ${code}`,
|
|
33
|
+
})),
|
|
34
|
+
{ value: NO_ANSWER, label: "No answer (the SDK times out)" },
|
|
35
|
+
];
|
|
36
|
+
export const ACCEPT = "accept";
|
|
37
|
+
export const EXCHANGE_CHOICES = [
|
|
38
|
+
{ value: ACCEPT, label: "Exchange it" },
|
|
39
|
+
{ value: "not_installed", label: "Refuse: not_installed" },
|
|
40
|
+
{ value: "not_purchased", label: "Refuse: not_purchased" },
|
|
41
|
+
{ value: "user_not_allowed", label: "Refuse: user_not_allowed" },
|
|
42
|
+
{ value: "invalid_client", label: "Refuse: invalid_client" },
|
|
43
|
+
];
|
|
44
|
+
/** There's no real account behind the studio, so API credentials are always refused. */
|
|
45
|
+
export const DEFAULT_FAILURES = {
|
|
46
|
+
credentials: "unauthenticated",
|
|
47
|
+
token: TOKEN,
|
|
48
|
+
exchange: ACCEPT,
|
|
49
|
+
};
|
|
50
|
+
/** The answer to `request-api-credentials`, or `null` for none at all. */
|
|
51
|
+
export function credentialsAnswer(requestId, choice) {
|
|
52
|
+
if (choice === NO_ANSWER) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const error = CREDENTIAL_CODES.includes(choice)
|
|
56
|
+
? choice
|
|
57
|
+
: "unauthenticated";
|
|
58
|
+
return { requestId, error };
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* What to do with `request-session-token`. "Every other" alternates, starting expired: the SDK
|
|
62
|
+
* keeps a token for its lifetime and asks again after a 401, so the retry gets a good one.
|
|
63
|
+
*/
|
|
64
|
+
export function tokenPlan(choice, lastWasExpired) {
|
|
65
|
+
if (choice === TOKEN) {
|
|
66
|
+
return { kind: "token", expired: false };
|
|
67
|
+
}
|
|
68
|
+
if (choice === EVERY_OTHER_EXPIRED) {
|
|
69
|
+
return { kind: "token", expired: !lastWasExpired };
|
|
70
|
+
}
|
|
71
|
+
if (choice === NO_ANSWER) {
|
|
72
|
+
return { kind: "none" };
|
|
73
|
+
}
|
|
74
|
+
return { kind: "error", code: choice };
|
|
75
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's frame: how wide the sidebar and the messages pane are, whether the messages pane is
|
|
3
|
+
* shown, and which sidebar sections are open. Remembered in this browser.
|
|
4
|
+
*
|
|
5
|
+
* Widths are kept as asked for and fitted to the window when read, so a narrower window squeezes
|
|
6
|
+
* the panes without forgetting what they were.
|
|
7
|
+
*/
|
|
8
|
+
import { batch, computed, effect, signal, } from "@preact/signals";
|
|
9
|
+
export const MIN_SIDEBAR_PX = 240;
|
|
10
|
+
export const DEFAULT_SIDEBAR_PX = 320;
|
|
11
|
+
export const MIN_MESSAGES_PX = 240;
|
|
12
|
+
export const DEFAULT_MESSAGES_PX = 360;
|
|
13
|
+
/** The least the main area keeps: a 420 px column and its padding. */
|
|
14
|
+
export const MIN_MAIN_PX = 480;
|
|
15
|
+
/** Each resize handle's width. */
|
|
16
|
+
export const HANDLE_PX = 6;
|
|
17
|
+
/** How far an arrow key moves a handle. */
|
|
18
|
+
export const KEY_STEP_PX = 16;
|
|
19
|
+
export const DEFAULT_LAYOUT = {
|
|
20
|
+
sidebarWidth: DEFAULT_SIDEBAR_PX,
|
|
21
|
+
messages: true,
|
|
22
|
+
messagesWidth: DEFAULT_MESSAGES_PX,
|
|
23
|
+
sections: {},
|
|
24
|
+
};
|
|
25
|
+
/** `value` within [min, max]; when there's no room for both, the minimum wins. */
|
|
26
|
+
const clamp = (value, min, max) => Math.max(min, Math.min(value, max));
|
|
27
|
+
const finiteOr = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
28
|
+
export class LayoutStore {
|
|
29
|
+
storage;
|
|
30
|
+
viewportWidth;
|
|
31
|
+
#sidebarWidth;
|
|
32
|
+
#messagesShown;
|
|
33
|
+
#messagesWidth;
|
|
34
|
+
#sections;
|
|
35
|
+
#stopSaving;
|
|
36
|
+
/** The sidebar's width, fitted to the window. */
|
|
37
|
+
sidebarWidth;
|
|
38
|
+
/** The messages pane's width, fitted to the window and the sidebar. */
|
|
39
|
+
messagesWidth;
|
|
40
|
+
/** How much of the window's right edge the messages pane covers: 0 when hidden. */
|
|
41
|
+
messagesOffset;
|
|
42
|
+
constructor(storage,
|
|
43
|
+
/** The window's width, kept current by the page. */
|
|
44
|
+
viewportWidth) {
|
|
45
|
+
this.storage = storage;
|
|
46
|
+
this.viewportWidth = viewportWidth;
|
|
47
|
+
const saved = storage.read(DEFAULT_LAYOUT);
|
|
48
|
+
this.#sidebarWidth = signal(finiteOr(saved.sidebarWidth, DEFAULT_SIDEBAR_PX));
|
|
49
|
+
this.#messagesShown = signal(saved.messages !== false);
|
|
50
|
+
this.#messagesWidth = signal(finiteOr(saved.messagesWidth, DEFAULT_MESSAGES_PX));
|
|
51
|
+
this.#sections = signal(saved.sections && typeof saved.sections === "object"
|
|
52
|
+
? { ...saved.sections }
|
|
53
|
+
: {});
|
|
54
|
+
this.sidebarWidth = computed(() => clamp(this.#sidebarWidth.value, MIN_SIDEBAR_PX, this.#maxSidebar()));
|
|
55
|
+
this.messagesWidth = computed(() => clamp(this.#messagesWidth.value, MIN_MESSAGES_PX, this.#maxMessages()));
|
|
56
|
+
this.messagesOffset = computed(() => this.#messagesShown.value ? this.messagesWidth.value + HANDLE_PX : 0);
|
|
57
|
+
// Saves what was asked for, not what the window allows.
|
|
58
|
+
this.#stopSaving = effect(() => {
|
|
59
|
+
this.storage.write({
|
|
60
|
+
sidebarWidth: this.#sidebarWidth.value,
|
|
61
|
+
messages: this.#messagesShown.value,
|
|
62
|
+
messagesWidth: this.#messagesWidth.value,
|
|
63
|
+
sections: this.#sections.value,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
get messagesShown() {
|
|
68
|
+
return this.#messagesShown;
|
|
69
|
+
}
|
|
70
|
+
get sections() {
|
|
71
|
+
return this.#sections;
|
|
72
|
+
}
|
|
73
|
+
/** The widest the sidebar may be: half the window, and room left for the rest. */
|
|
74
|
+
#maxSidebar() {
|
|
75
|
+
const width = this.viewportWidth.value;
|
|
76
|
+
const messages = this.#messagesShown.value
|
|
77
|
+
? this.#messagesWidth.value + HANDLE_PX
|
|
78
|
+
: 0;
|
|
79
|
+
return Math.min(width * 0.5, width - messages - HANDLE_PX - MIN_MAIN_PX);
|
|
80
|
+
}
|
|
81
|
+
#maxMessages() {
|
|
82
|
+
const width = this.viewportWidth.value;
|
|
83
|
+
return Math.min(width * 0.6, width - this.sidebarWidth.value - 2 * HANDLE_PX - MIN_MAIN_PX);
|
|
84
|
+
}
|
|
85
|
+
/** Resizes the sidebar; a drag past the limits stops at them. */
|
|
86
|
+
resizeSidebar = (width) => {
|
|
87
|
+
this.#sidebarWidth.value = clamp(width, MIN_SIDEBAR_PX, this.#maxSidebar());
|
|
88
|
+
};
|
|
89
|
+
resizeMessages = (width) => {
|
|
90
|
+
this.#messagesWidth.value = clamp(width, MIN_MESSAGES_PX, this.#maxMessages());
|
|
91
|
+
};
|
|
92
|
+
/** One arrow-key step: `1` widens, `-1` narrows. */
|
|
93
|
+
stepSidebar = (direction) => {
|
|
94
|
+
this.resizeSidebar(this.sidebarWidth.value + direction * KEY_STEP_PX);
|
|
95
|
+
};
|
|
96
|
+
stepMessages = (direction) => {
|
|
97
|
+
this.resizeMessages(this.messagesWidth.value + direction * KEY_STEP_PX);
|
|
98
|
+
};
|
|
99
|
+
toggleMessages = () => {
|
|
100
|
+
batch(() => {
|
|
101
|
+
// What the pane was squeezed to stays its width when it comes back.
|
|
102
|
+
this.#messagesWidth.value = this.messagesWidth.value;
|
|
103
|
+
this.#messagesShown.value = !this.#messagesShown.value;
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
/** Whether a section is open: as it was left, else `initially`. */
|
|
107
|
+
isOpen(name, initially) {
|
|
108
|
+
return this.#sections.value[name] ?? initially;
|
|
109
|
+
}
|
|
110
|
+
setOpen = (name, open) => {
|
|
111
|
+
if (this.#sections.value[name] === open) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this.#sections.value = { ...this.#sections.value, [name]: open };
|
|
115
|
+
};
|
|
116
|
+
dispose() {
|
|
117
|
+
this.#stopSaving();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The message log: every message between the studio and the plugin, both ways, and the studio's
|
|
3
|
+
* own notes. Oldest first; the oldest go once there are too many to keep.
|
|
4
|
+
*/
|
|
5
|
+
import { signal } from "@preact/signals";
|
|
6
|
+
/** Enough for a long session; past it, the oldest go. */
|
|
7
|
+
export const MAX_ENTRIES = 2000;
|
|
8
|
+
export class LogStore {
|
|
9
|
+
now;
|
|
10
|
+
#entries = signal([]);
|
|
11
|
+
#nextId = 1;
|
|
12
|
+
constructor(now = Date.now) {
|
|
13
|
+
this.now = now;
|
|
14
|
+
}
|
|
15
|
+
get entries() {
|
|
16
|
+
return this.#entries;
|
|
17
|
+
}
|
|
18
|
+
/** Adds an entry. An arrow, as the plugin channel and old page code call it bare. */
|
|
19
|
+
append = (direction, type, payload, source) => {
|
|
20
|
+
const entry = {
|
|
21
|
+
id: this.#nextId++,
|
|
22
|
+
at: this.now(),
|
|
23
|
+
direction,
|
|
24
|
+
type,
|
|
25
|
+
...(payload === undefined ? {} : { payload }),
|
|
26
|
+
...(source === undefined ? {} : { source }),
|
|
27
|
+
};
|
|
28
|
+
const entries = this.#entries.value;
|
|
29
|
+
this.#entries.value =
|
|
30
|
+
entries.length < MAX_ENTRIES
|
|
31
|
+
? [...entries, entry]
|
|
32
|
+
: [...entries.slice(entries.length - MAX_ENTRIES + 1), entry];
|
|
33
|
+
};
|
|
34
|
+
clear = () => {
|
|
35
|
+
this.#entries.value = [];
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Which page is shown: the profile, or the settings screen. It follows the address's hash. */
|
|
2
|
+
import { signal } from "@preact/signals";
|
|
3
|
+
/** The page a hash names; what follows a `?` is the address's params (address.ts). */
|
|
4
|
+
export const pageFor = (hash) => hash.split("?")[0] === "#settings" ? "settings" : "profile";
|
|
5
|
+
export class NavigationStore {
|
|
6
|
+
#page;
|
|
7
|
+
constructor(hash) {
|
|
8
|
+
this.#page = signal(pageFor(hash));
|
|
9
|
+
}
|
|
10
|
+
get page() {
|
|
11
|
+
return this.#page;
|
|
12
|
+
}
|
|
13
|
+
/** The hash changed: the page follows. */
|
|
14
|
+
follow = (hash) => {
|
|
15
|
+
this.#page.value = pageFor(hash);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Plugin section's logic: the address checked as Livespace checks one, a pasted catalog
|
|
3
|
+
* manifest read for what the studio needs from it, and the env values a backend sets. No DOM.
|
|
4
|
+
*/
|
|
5
|
+
import { RECORD_CHOICES } from "./view-data.js";
|
|
6
|
+
/** Why an address can't be embedded, or undefined when it can (as the server checks it too). */
|
|
7
|
+
export function urlProblem(text, devOrigin) {
|
|
8
|
+
let url;
|
|
9
|
+
try {
|
|
10
|
+
url = new URL(text.trim());
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return "That isn't an address: http://… or https://…";
|
|
14
|
+
}
|
|
15
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
16
|
+
return "The address must start with http:// or https://.";
|
|
17
|
+
}
|
|
18
|
+
if (url.origin === devOrigin) {
|
|
19
|
+
return "That's the studio's own origin. Livespace refuses a plugin on its own origin.";
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
/** A catalog manifest, written as JSON, read for its id and where it may go. */
|
|
24
|
+
export function readManifest(text) {
|
|
25
|
+
let value;
|
|
26
|
+
try {
|
|
27
|
+
value = JSON.parse(text);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return { ok: false, reason: error.message };
|
|
31
|
+
}
|
|
32
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
33
|
+
return { ok: false, reason: "A manifest is a JSON object." };
|
|
34
|
+
}
|
|
35
|
+
const manifest = value;
|
|
36
|
+
const id = manifest.id;
|
|
37
|
+
const types = manifest.allowedObjectTypes;
|
|
38
|
+
return {
|
|
39
|
+
ok: true,
|
|
40
|
+
manifest,
|
|
41
|
+
clientId: typeof id === "string" && id !== "" ? `plugin:${id}` : undefined,
|
|
42
|
+
objectTypes: Array.isArray(types)
|
|
43
|
+
? types.filter((type) => typeof type === "string")
|
|
44
|
+
: null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The record choices a catalog plugin can be shown with: the types its manifest lists, or every
|
|
49
|
+
* type and no record when it lists none (`null`, anywhere). A plugin added by URL gets them all.
|
|
50
|
+
*/
|
|
51
|
+
export function recordChoicesFor(objectTypes) {
|
|
52
|
+
if (objectTypes === null) {
|
|
53
|
+
return RECORD_CHOICES;
|
|
54
|
+
}
|
|
55
|
+
return RECORD_CHOICES.filter((choice) => choice.value !== "none" && objectTypes.includes(choice.value));
|
|
56
|
+
}
|
|
57
|
+
/** The first choice a list allows, when the current one isn't among them. */
|
|
58
|
+
export function allowedChoice(current, choices) {
|
|
59
|
+
return choices.some((choice) => choice.value === current)
|
|
60
|
+
? current
|
|
61
|
+
: (choices[0]?.value ?? "none");
|
|
62
|
+
}
|
|
63
|
+
/** What a backend's environment needs to trust the dev account. */
|
|
64
|
+
export function backendEnv(devOrigin, clientId) {
|
|
65
|
+
return [
|
|
66
|
+
`LIVESPACE_KEYS_URL=${devOrigin}/core/api/auth/jwks`,
|
|
67
|
+
`LIVESPACE_AUTH_URL=${devOrigin}`,
|
|
68
|
+
`PLUGIN_CLIENT_ID=${clientId}`,
|
|
69
|
+
].join("\n");
|
|
70
|
+
}
|