@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,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the view page sends: the record and viewer as plugin-slot puts them in `context`
|
|
3
|
+
* (ls-fe plugin-slot core/src/domain/context-object.ts), and the viewer's preferences as
|
|
4
|
+
* Livespace builds them from its own settings. Text in, payload or a reason out; no DOM.
|
|
5
|
+
*/
|
|
6
|
+
import { resolvePluginPreferences, } from "@livespace/plugin-sdk";
|
|
7
|
+
export const RECORD_CHOICES = [
|
|
8
|
+
{ value: "deal", label: "Deal" },
|
|
9
|
+
{ value: "company", label: "Company" },
|
|
10
|
+
{ value: "person", label: "Person" },
|
|
11
|
+
{ value: "space", label: "Space" },
|
|
12
|
+
{ value: "none", label: "No record (apps menu)" },
|
|
13
|
+
];
|
|
14
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
|
+
function parseJson(text) {
|
|
16
|
+
try {
|
|
17
|
+
return { ok: true, value: JSON.parse(text) };
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return { ok: false, reason: error.message };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The context for a record written as JSON. Like plugin-slot, it needs an `id` and a `name`; a
|
|
25
|
+
* `type` that names another type is refused, as plugin-slot ignores a description of another
|
|
26
|
+
* object. `viewer` empty means no user.
|
|
27
|
+
*/
|
|
28
|
+
export function contextFrom(choice, recordText, viewer) {
|
|
29
|
+
const user = viewer.trim() === "" ? null : { id: viewer.trim() };
|
|
30
|
+
if (choice === "none") {
|
|
31
|
+
return { ok: true, value: { user } };
|
|
32
|
+
}
|
|
33
|
+
const parsed = parseJson(recordText);
|
|
34
|
+
if (!parsed.ok) {
|
|
35
|
+
return parsed;
|
|
36
|
+
}
|
|
37
|
+
const record = parsed.value;
|
|
38
|
+
if (!isRecord(record)) {
|
|
39
|
+
return { ok: false, reason: "The record must be a JSON object." };
|
|
40
|
+
}
|
|
41
|
+
if (typeof record.id !== "string" || record.id === "") {
|
|
42
|
+
return { ok: false, reason: 'The record needs an "id" string.' };
|
|
43
|
+
}
|
|
44
|
+
if (typeof record.name !== "string") {
|
|
45
|
+
return { ok: false, reason: 'The record needs a "name" string.' };
|
|
46
|
+
}
|
|
47
|
+
if (record.type !== undefined && record.type !== choice) {
|
|
48
|
+
return {
|
|
49
|
+
ok: false,
|
|
50
|
+
reason: `"type" is "${String(record.type)}", but this is a ${choice}.`,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return { ok: true, value: { [choice]: record, user } };
|
|
54
|
+
}
|
|
55
|
+
/** What a real Livespace page provides, in Polish and in US English. */
|
|
56
|
+
export const PREFERENCE_PRESETS = [
|
|
57
|
+
{
|
|
58
|
+
value: "pl",
|
|
59
|
+
label: "Polish",
|
|
60
|
+
host: {
|
|
61
|
+
language: "pl",
|
|
62
|
+
formats: {
|
|
63
|
+
decimalSymbol: ",",
|
|
64
|
+
thousandsSeparator: " ",
|
|
65
|
+
dateFormat: "Y-m-d",
|
|
66
|
+
timeFormat: "H:i",
|
|
67
|
+
dateTimeFormat: "Y-m-d H:i",
|
|
68
|
+
currencySymbol: "PLN",
|
|
69
|
+
moneyFormat: "%n %c",
|
|
70
|
+
decimalAccuracy: "2",
|
|
71
|
+
firstWeekDay: 1,
|
|
72
|
+
timezone: "Europe/Warsaw",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
value: "en-US",
|
|
78
|
+
label: "English (US)",
|
|
79
|
+
host: {
|
|
80
|
+
language: "en-US",
|
|
81
|
+
formats: {
|
|
82
|
+
decimalSymbol: ".",
|
|
83
|
+
thousandsSeparator: ",",
|
|
84
|
+
dateFormat: "m/d/Y",
|
|
85
|
+
timeFormat: "g:i A",
|
|
86
|
+
dateTimeFormat: "m/d/Y g:i A",
|
|
87
|
+
currencySymbol: "$",
|
|
88
|
+
moneyFormat: "%c%n",
|
|
89
|
+
decimalAccuracy: "2",
|
|
90
|
+
firstWeekDay: 7,
|
|
91
|
+
timezone: "America/New_York",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{ value: "none", label: "None (an older Livespace)", host: null },
|
|
96
|
+
];
|
|
97
|
+
/**
|
|
98
|
+
* The preferences a plugin gets from Livespace settings written as JSON, through the SDK's
|
|
99
|
+
* `resolvePluginPreferences` as every Livespace host does: what it can't read comes out `null`.
|
|
100
|
+
*/
|
|
101
|
+
export function preferencesFrom(hostText) {
|
|
102
|
+
if (hostText.trim() === "" || hostText.trim() === "null") {
|
|
103
|
+
return { ok: true, value: null };
|
|
104
|
+
}
|
|
105
|
+
const parsed = parseJson(hostText);
|
|
106
|
+
if (!parsed.ok) {
|
|
107
|
+
return parsed;
|
|
108
|
+
}
|
|
109
|
+
if (!isRecord(parsed.value)) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
reason: 'Livespace\'s settings are an object: { "language", "formats" }.',
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
ok: true,
|
|
117
|
+
value: resolvePluginPreferences({
|
|
118
|
+
language: parsed.value.language,
|
|
119
|
+
formats: parsed.value.formats,
|
|
120
|
+
}),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Livespace sends a plugin about where it's shown: the record (or none, in the apps menu),
|
|
3
|
+
* the viewer, and the viewer's preferences as Livespace builds them from its own settings. Each is
|
|
4
|
+
* typed as JSON or text, and what reads well is what's sent. Kept in this browser.
|
|
5
|
+
*/
|
|
6
|
+
import { batch, computed, effect, signal, } from "@preact/signals";
|
|
7
|
+
import { timers, Draft } from "./draft.js";
|
|
8
|
+
import { allowedChoice } from "./plugin-data.js";
|
|
9
|
+
import { SAMPLES } from "./samples.js";
|
|
10
|
+
import { PREFERENCE_PRESETS, RECORD_CHOICES, contextFrom, preferencesFrom, } from "./view-data.js";
|
|
11
|
+
/** The preset name for preferences typed by hand. */
|
|
12
|
+
export const CUSTOM = "custom";
|
|
13
|
+
export const sampleText = (choice) => choice === "none" ? "" : JSON.stringify(SAMPLES[choice], null, 2);
|
|
14
|
+
export const presetText = (preset) => JSON.stringify(PREFERENCE_PRESETS.find((p) => p.value === preset)?.host ?? null, null, 2);
|
|
15
|
+
export const DEFAULT_VIEW = {
|
|
16
|
+
choice: "deal",
|
|
17
|
+
records: {},
|
|
18
|
+
viewer: SAMPLES.deal.owners?.[0]?.id ?? "dev-user",
|
|
19
|
+
preset: "pl",
|
|
20
|
+
preferences: presetText("pl"),
|
|
21
|
+
};
|
|
22
|
+
export class ViewStore {
|
|
23
|
+
#choice;
|
|
24
|
+
#records;
|
|
25
|
+
#preset;
|
|
26
|
+
#stops = [];
|
|
27
|
+
/** The viewer's id, as typed; empty is no user. */
|
|
28
|
+
viewer;
|
|
29
|
+
/** The record's JSON, as typed. */
|
|
30
|
+
record;
|
|
31
|
+
/** Livespace's settings for the viewer, as JSON. */
|
|
32
|
+
preferencesText;
|
|
33
|
+
/** The context the plugin gets: the last one that read well. */
|
|
34
|
+
context;
|
|
35
|
+
/** The preferences the plugin gets: the last that read well. */
|
|
36
|
+
preferences;
|
|
37
|
+
/** Whether the record's sample has been edited, so it can be reset. */
|
|
38
|
+
recordEdited;
|
|
39
|
+
constructor(deps) {
|
|
40
|
+
const scheduler = deps.scheduler ?? timers;
|
|
41
|
+
const saved = deps.storage.read(DEFAULT_VIEW);
|
|
42
|
+
const known = RECORD_CHOICES.some((c) => c.value === saved.choice);
|
|
43
|
+
this.#choice = signal(known ? saved.choice : DEFAULT_VIEW.choice);
|
|
44
|
+
this.#records = signal({ ...saved.records });
|
|
45
|
+
this.#preset = signal(saved.preset);
|
|
46
|
+
this.viewer = new Draft(saved.viewer, (text) => ({ ok: true, value: text }), saved.viewer, scheduler);
|
|
47
|
+
this.record = new Draft(this.#recordText(this.#choice.value), (text) => contextFrom(this.#choice.value, text, this.viewer.committed.value), { user: null }, scheduler);
|
|
48
|
+
this.preferencesText = new Draft(saved.preferences, preferencesFrom, null, scheduler);
|
|
49
|
+
this.context = this.record.value;
|
|
50
|
+
this.preferences = this.preferencesText.value;
|
|
51
|
+
this.recordEdited = computed(() => this.#records.value[this.#choice.value] !== undefined);
|
|
52
|
+
// A record type the plugin can't be shown with gives way to one it can.
|
|
53
|
+
this.#stops.push(effect(() => {
|
|
54
|
+
const allowed = allowedChoice(this.#choice.value, deps.choices.value);
|
|
55
|
+
if (allowed !== this.#choice.peek()) {
|
|
56
|
+
this.choose(allowed);
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
// An edited record is kept per type; one that's back to the sample isn't.
|
|
60
|
+
this.#stops.push(effect(() => {
|
|
61
|
+
const text = this.record.committed.value;
|
|
62
|
+
const choice = this.#choice.peek();
|
|
63
|
+
if (choice === "none") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const records = this.#records.peek();
|
|
67
|
+
const edited = text !== sampleText(choice);
|
|
68
|
+
if (edited ? records[choice] !== text : choice in records) {
|
|
69
|
+
const next = { ...records };
|
|
70
|
+
if (edited) {
|
|
71
|
+
next[choice] = text;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
delete next[choice];
|
|
75
|
+
}
|
|
76
|
+
this.#records.value = next;
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
this.#stops.push(effect(() => {
|
|
80
|
+
deps.storage.write({
|
|
81
|
+
choice: this.#choice.value,
|
|
82
|
+
records: this.#records.value,
|
|
83
|
+
viewer: this.viewer.committed.value,
|
|
84
|
+
preset: this.#preset.value,
|
|
85
|
+
preferences: this.preferencesText.committed.value,
|
|
86
|
+
});
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
get choice() {
|
|
90
|
+
return this.#choice;
|
|
91
|
+
}
|
|
92
|
+
get preset() {
|
|
93
|
+
return this.#preset;
|
|
94
|
+
}
|
|
95
|
+
#recordText(choice) {
|
|
96
|
+
return this.#records.peek()[choice] ?? sampleText(choice);
|
|
97
|
+
}
|
|
98
|
+
choose = (choice) => {
|
|
99
|
+
// What was being typed is kept for the type it was typed for, before the type changes.
|
|
100
|
+
this.record.flush();
|
|
101
|
+
batch(() => {
|
|
102
|
+
this.#choice.value = choice;
|
|
103
|
+
this.record.set(this.#recordText(choice));
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
/** Back to the sample for this record type. */
|
|
107
|
+
resetRecord = () => {
|
|
108
|
+
this.record.set(sampleText(this.#choice.value));
|
|
109
|
+
};
|
|
110
|
+
choosePreset = (preset) => {
|
|
111
|
+
if (preset === CUSTOM) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
batch(() => {
|
|
115
|
+
this.#preset.value = preset;
|
|
116
|
+
this.preferencesText.set(presetText(preset));
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
/** Preferences typed by hand: no longer a preset. */
|
|
120
|
+
editPreferences = (text) => {
|
|
121
|
+
this.#preset.value = CUSTOM;
|
|
122
|
+
this.preferencesText.edit(text);
|
|
123
|
+
};
|
|
124
|
+
dispose() {
|
|
125
|
+
for (const stop of this.#stops) {
|
|
126
|
+
stop();
|
|
127
|
+
}
|
|
128
|
+
this.viewer.dispose();
|
|
129
|
+
this.record.dispose();
|
|
130
|
+
this.preferencesText.dispose();
|
|
131
|
+
}
|
|
132
|
+
}
|