@bridgebrew/plugin-manager 0.0.0-stage → 0.0.2
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/browser/browser.tsx +2173 -0
- package/browser/screen/harness-profiles.tsx +1348 -0
- package/browser/screen/marketplace-model.ts +356 -0
- package/browser/screen/marketplace.tsx +1173 -0
- package/browser/screen/plugin-dependencies.tsx +139 -0
- package/browser/screen/plugin-docs.tsx +142 -0
- package/browser/screen/plugin-logs.tsx +549 -0
- package/browser/screen/plugin-parts.tsx +257 -0
- package/browser/screen/plugin-readme.tsx +152 -0
- package/browser/screen/plugin-settings.tsx +169 -0
- package/browser/screen/plugins-model.ts +427 -0
- package/browser/screen/plugins.tsx +2593 -0
- package/browser/screen/settings-action.ts +42 -0
- package/browser/screen/settings-fields.ts +414 -0
- package/browser/screen/settings-form.tsx +1669 -0
- package/browser/screen/settings-kinds.tsx +918 -0
- package/browser/screen/settings-page.tsx +72 -0
- package/browser/screen/settings-row.tsx +558 -0
- package/browser/screen/update-all.tsx +175 -0
- package/browser/tsconfig.json +15 -0
- package/package.json +61 -4
- package/tsconfig.json +5 -0
- package/README.md +0 -3
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// A plugin's page in Settings (manifest `settingsPage: true`): what it shows rather than what it is configured with
|
|
2
|
+
// (storage: how the workspace's data is made). Configuration stays its `settings` fields; the page sits beside them, in
|
|
3
|
+
// Settings (under its fields, or alone) and in its Plugins Settings tab.
|
|
4
|
+
// The plugin's browser entry registers the page as the slot factory `<key>.settings` (`registerSettingsPage`); the
|
|
5
|
+
// plugin manager draws it with `SettingsPageProps` (`SettingsPageOutlet`). A factory, not a screen: it is reachable from
|
|
6
|
+
// any page whoever serves the plugin's browser entry, `_host` included (storage is `_host`'s, whose screens a workspace
|
|
7
|
+
// never shows), and it is drawn inside another plugin's screen. The page makes no assumption on its frame: the frame
|
|
8
|
+
// says which workspace, its own item, how to open one and where a link goes.
|
|
9
|
+
import * as React from 'react';
|
|
10
|
+
import type { Context } from 'cordis';
|
|
11
|
+
import type { FollowTarget } from '@bridge/ui';
|
|
12
|
+
|
|
13
|
+
export interface SettingsPageProps {
|
|
14
|
+
/** The workspace whose settings these are (`_host`: Bridge's own, in Admin). */
|
|
15
|
+
slug: string;
|
|
16
|
+
/** Fetches as the page does (`/<slug>/api/<key>/…`, `/_bridge/…`): `ctx.workspace.fetch` of the page shown. */
|
|
17
|
+
fetch: (input: string, init?: RequestInit) => Promise<Response>;
|
|
18
|
+
/** The node Settings shows (`root`: the workspace). */
|
|
19
|
+
node: string;
|
|
20
|
+
/** The page's own item: what follows `<slug>/<key>/` in its frame's item; none, its start. */
|
|
21
|
+
item?: string | undefined;
|
|
22
|
+
/** Shows the page's item `item` (none: its start) in its frame, a navigation entry (Back returns). */
|
|
23
|
+
open: (item?: string) => void;
|
|
24
|
+
/** Where a link to the page's item `item` goes: a `ScreenLink`'s `to`. */
|
|
25
|
+
linkTo: (item?: string) => FollowTarget;
|
|
26
|
+
/** Nothing may change from it (an archived node). */
|
|
27
|
+
readOnly: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The factory name of plugin `key`'s settings page. */
|
|
31
|
+
export const settingsPageOf = (key: string) => `${key}.settings`;
|
|
32
|
+
|
|
33
|
+
/** The slot API a factory is registered and drawn with: the names are dynamic (one per plugin), which the slot map's
|
|
34
|
+
* typed names cannot say. */
|
|
35
|
+
interface Factories {
|
|
36
|
+
registerFactory(
|
|
37
|
+
options: { name: string; scope: 'root' },
|
|
38
|
+
component: (props: SettingsPageProps) => React.ReactNode,
|
|
39
|
+
): () => void;
|
|
40
|
+
}
|
|
41
|
+
type RenderFactory = (
|
|
42
|
+
name: string,
|
|
43
|
+
props: SettingsPageProps,
|
|
44
|
+
options?: { fallback?: React.ReactNode },
|
|
45
|
+
) => React.ReactNode;
|
|
46
|
+
|
|
47
|
+
/** Registers `component` as plugin `key`'s settings page (its `<key>.settings` factory), for as long as `ctx` lives. */
|
|
48
|
+
export function registerSettingsPage(
|
|
49
|
+
ctx: Context,
|
|
50
|
+
key: string,
|
|
51
|
+
component: (props: SettingsPageProps) => React.ReactNode,
|
|
52
|
+
) {
|
|
53
|
+
// oxlint-disable-next-line bridge/no-new-unchecked-cast -- typing: the slot map types factory names statically, a settings page's is `<key>.settings`
|
|
54
|
+
const { slots } = ctx as unknown as { slots: Factories };
|
|
55
|
+
return slots.registerFactory({ name: settingsPageOf(key), scope: 'root' }, component);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The renderer's `renderFactorySlot` of the component drawing pages (its slot props), given to the frames below it. */
|
|
59
|
+
export const SettingsPageRenderer = React.createContext<unknown>(undefined);
|
|
60
|
+
|
|
61
|
+
/** Plugin `plugin`'s settings page, drawn with `props`; `fallback` while its browser entry has not registered it (or
|
|
62
|
+
* outside a renderer: a test). */
|
|
63
|
+
export function SettingsPageOutlet({
|
|
64
|
+
plugin,
|
|
65
|
+
fallback = null,
|
|
66
|
+
...props
|
|
67
|
+
}: SettingsPageProps & { plugin: string; fallback?: React.ReactNode }) {
|
|
68
|
+
const render = React.useContext(SettingsPageRenderer);
|
|
69
|
+
if (typeof render !== 'function') return <>{fallback}</>;
|
|
70
|
+
// The renderer's own function; its factory names are dynamic (see Factories).
|
|
71
|
+
return <>{(render as RenderFactory)(settingsPageOf(plugin), props, { fallback })}</>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
// One setting's row (the Settings screen's, and a `_host` plugin's under Bridge › Plugins): its name, its origin beside it
|
|
2
|
+
// (none for Bridge's default), description,
|
|
3
|
+
// control (a checkbox labelled by the description, a select, an input, a colour, swatches, an image, or a form for objects
|
|
4
|
+
// and arrays, ./settings-form.tsx, with "Edit in JSON" as an escape hatch), a left accent bar when set at the level shown, and a gear menu (Reset Setting,
|
|
5
|
+
// Copy Setting ID, Copy Setting as JSON). A change commits the whole value once it validates against the schema
|
|
6
|
+
// (`@bridge/kernel/schema`, as the host does), through `save`; the error shows under the sub-field its path names, the
|
|
7
|
+
// host's refusal under the row. `restart` fields say they restart the workspace. Every field stays usable while a change
|
|
8
|
+
// saves; the last change made meanwhile is saved next. An explicit setting (`x-bridge-commit: "explicit"`)
|
|
9
|
+
// keeps an edit a draft, never written until its `save` action commits it, and Cancel drops it.
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
import {
|
|
12
|
+
Button,
|
|
13
|
+
DropdownMenu,
|
|
14
|
+
DropdownMenuContent,
|
|
15
|
+
DropdownMenuItem,
|
|
16
|
+
DropdownMenuTrigger,
|
|
17
|
+
Field,
|
|
18
|
+
FieldError,
|
|
19
|
+
FieldLabel,
|
|
20
|
+
Icon,
|
|
21
|
+
Textarea,
|
|
22
|
+
Toggle,
|
|
23
|
+
cn,
|
|
24
|
+
copyText,
|
|
25
|
+
isRecord,
|
|
26
|
+
} from '@bridge/ui';
|
|
27
|
+
import { describeError, validate, type SchemaError } from '@bridge/kernel/schema';
|
|
28
|
+
import {
|
|
29
|
+
anchorOf,
|
|
30
|
+
controlOf,
|
|
31
|
+
humanize,
|
|
32
|
+
readValue,
|
|
33
|
+
serialSaver,
|
|
34
|
+
summaryOf,
|
|
35
|
+
textOf,
|
|
36
|
+
originSource,
|
|
37
|
+
type Origin,
|
|
38
|
+
type Schema,
|
|
39
|
+
} from './settings-fields.ts';
|
|
40
|
+
import { Control, Marked, type FormContext, type Path } from './settings-form.tsx';
|
|
41
|
+
|
|
42
|
+
/** Writes (or, `undefined`, removes) the value; resolves to the host's refusal, or nothing once written. */
|
|
43
|
+
export type Save = (value: unknown) => Promise<string | undefined>;
|
|
44
|
+
|
|
45
|
+
/** The deepest field drawn for an error (./fields.ts `anchorOf`), and its message (with the rest of its path). */
|
|
46
|
+
const anchored = (schema: Schema, error: SchemaError | undefined, path: Path) => {
|
|
47
|
+
if (!error) return undefined;
|
|
48
|
+
const anchor = anchorOf(schema, error.path);
|
|
49
|
+
if (anchor.length !== path.length || anchor.some((step, index) => step !== path[index]))
|
|
50
|
+
return undefined;
|
|
51
|
+
const rest = error.path.slice(anchor.length);
|
|
52
|
+
return rest.length ? `${rest.join('.')}: ${error.message}` : error.message;
|
|
53
|
+
};
|
|
54
|
+
const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);
|
|
55
|
+
|
|
56
|
+
/** A DOM id of this copy of the screen: `scope` (React's `useId`) then `name`, word characters and `-` only. */
|
|
57
|
+
export const domId = (scope: string, name: string) => `${scope}-${name}`.replace(/[^\w-]/g, '_');
|
|
58
|
+
|
|
59
|
+
export function SettingRow({
|
|
60
|
+
scope,
|
|
61
|
+
id,
|
|
62
|
+
field,
|
|
63
|
+
property,
|
|
64
|
+
value,
|
|
65
|
+
origin,
|
|
66
|
+
label,
|
|
67
|
+
modified,
|
|
68
|
+
readOnly,
|
|
69
|
+
needle,
|
|
70
|
+
options,
|
|
71
|
+
save,
|
|
72
|
+
form,
|
|
73
|
+
}: {
|
|
74
|
+
/** This copy of the screen's prefix for DOM ids (two Settings windows keep their labels on their own fields). */
|
|
75
|
+
scope: string;
|
|
76
|
+
/** `<plugin>.<field>`. */
|
|
77
|
+
id: string;
|
|
78
|
+
field: string;
|
|
79
|
+
property: Schema;
|
|
80
|
+
value: unknown;
|
|
81
|
+
origin: Origin | undefined;
|
|
82
|
+
label: string;
|
|
83
|
+
/** Set at the level shown: the accent bar, and Reset Setting. */
|
|
84
|
+
modified: boolean;
|
|
85
|
+
readOnly: boolean;
|
|
86
|
+
needle: string;
|
|
87
|
+
options: (kind: string, path?: Path) => string[];
|
|
88
|
+
save: Save;
|
|
89
|
+
/** What visual fields draw with and send to (./settings-kinds.tsx): the section's values, its images, the workspace. */
|
|
90
|
+
form?: Pick<
|
|
91
|
+
FormContext,
|
|
92
|
+
'values' | 'imageOf' | 'workspace' | 'files' | 'optionLabel' | 'runAction' | 'draftSecret'
|
|
93
|
+
>;
|
|
94
|
+
}) {
|
|
95
|
+
const control = controlOf(property);
|
|
96
|
+
/** The value being edited: the host's, then each change (kept while it does not validate). */
|
|
97
|
+
const [draft, setDraft] = React.useState(value);
|
|
98
|
+
const [error, setError] = React.useState<SchemaError>();
|
|
99
|
+
/** The host's refusal, or a JSON editor's parse error. */
|
|
100
|
+
const [refusal, setRefusal] = React.useState('');
|
|
101
|
+
const [busy, setBusy] = React.useState(false);
|
|
102
|
+
/** A short confirmation after a save or a copy. */
|
|
103
|
+
const [note, setNote] = React.useState('');
|
|
104
|
+
/** The JSON escape hatch is open, with its text. */
|
|
105
|
+
const [json, setJson] = React.useState<string>();
|
|
106
|
+
const shown = JSON.stringify(value);
|
|
107
|
+
/** Whether a change is a draft, saved only by a `save: true` action. */
|
|
108
|
+
const explicit = property['x-bridge-commit'] === 'explicit';
|
|
109
|
+
/** Resolves an explicit commit's promise once its save settles. */
|
|
110
|
+
const commitSettled = React.useRef<((refusal: string | undefined) => void) | undefined>(
|
|
111
|
+
undefined,
|
|
112
|
+
);
|
|
113
|
+
/** Writes through `save` one change at a time (`serialSaver`): made once, so it always calls the latest `save`. */
|
|
114
|
+
const saveRef = React.useRef(save);
|
|
115
|
+
saveRef.current = save;
|
|
116
|
+
const [saver] = React.useState(() =>
|
|
117
|
+
serialSaver(
|
|
118
|
+
(next) => saveRef.current(next),
|
|
119
|
+
(next, refused) => {
|
|
120
|
+
setRefusal(refused ?? '');
|
|
121
|
+
setBusy(false);
|
|
122
|
+
if (!refused) {
|
|
123
|
+
setNote(next === undefined ? 'Reset' : 'Saved');
|
|
124
|
+
setJson(undefined);
|
|
125
|
+
}
|
|
126
|
+
commitSettled.current?.(refused);
|
|
127
|
+
commitSettled.current = undefined;
|
|
128
|
+
},
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
/** The last value handed to the saver, until the saves settle. */
|
|
132
|
+
const pushed = React.useRef<{ value: unknown }>(undefined);
|
|
133
|
+
/** The draft changed after the last value pushed (an entry added, kept as a draft while it does not validate). */
|
|
134
|
+
const changedSince = () => !!pushed.current && !same(draft, pushed.current.value);
|
|
135
|
+
// A new value from the host (saved, reset, changed elsewhere) replaces the draft and its errors, but not while changes
|
|
136
|
+
// are being saved (an earlier one's value would undo a later pick). Once the last one settles, the host's value is
|
|
137
|
+
// the draft unless the draft changed since that value was pushed: then it stays, with its errors (#447).
|
|
138
|
+
React.useEffect(() => {
|
|
139
|
+
if (!saver.busy() && !changedSince()) {
|
|
140
|
+
setError(undefined);
|
|
141
|
+
setRefusal('');
|
|
142
|
+
}
|
|
143
|
+
}, [shown]);
|
|
144
|
+
React.useEffect(() => {
|
|
145
|
+
if (saver.busy()) return;
|
|
146
|
+
const keep = changedSince();
|
|
147
|
+
pushed.current = undefined;
|
|
148
|
+
if (!keep) setDraft(value);
|
|
149
|
+
}, [shown, busy]);
|
|
150
|
+
React.useEffect(() => {
|
|
151
|
+
if (!note) return;
|
|
152
|
+
const timer = setTimeout(() => setNote(''), 2000);
|
|
153
|
+
return () => clearTimeout(timer);
|
|
154
|
+
}, [note]);
|
|
155
|
+
const restart = property.applies !== 'live';
|
|
156
|
+
/** Read-only (an archived node) refuses every change. Saving refuses none, whatever the control: a change made
|
|
157
|
+
* meanwhile builds on the draft and the serial saver writes the last one once the current save answers. Only an
|
|
158
|
+
* explicit setting waits while its commit saves, as the host's value then replaces its draft. */
|
|
159
|
+
const locked = readOnly || (busy && explicit);
|
|
160
|
+
/** Saves `next`; `drafted` is the draft it stands for (the current one for a Reset): the host's value replaces it once
|
|
161
|
+
* saved, unless it changes meanwhile. */
|
|
162
|
+
const write = (next: unknown, drafted: unknown = draft) => {
|
|
163
|
+
setBusy(true);
|
|
164
|
+
setNote('');
|
|
165
|
+
pushed.current = { value: drafted };
|
|
166
|
+
saver.push(next);
|
|
167
|
+
};
|
|
168
|
+
/** The whole value after a change: kept as the draft, checked against the schema, then saved when it differs (an
|
|
169
|
+
* explicit setting keeps it a draft until a `save: true` action commits it). */
|
|
170
|
+
const change = (next: unknown) => {
|
|
171
|
+
if (locked) return;
|
|
172
|
+
setDraft(next);
|
|
173
|
+
setRefusal('');
|
|
174
|
+
const invalid = next === undefined ? undefined : validate(property, next);
|
|
175
|
+
setError(invalid);
|
|
176
|
+
if (explicit) return;
|
|
177
|
+
if (invalid || (!saver.busy() && same(next, value))) return;
|
|
178
|
+
write(next, next);
|
|
179
|
+
};
|
|
180
|
+
/** Saves an explicit setting's draft through `save`, resolving with its refusal (or nothing once saved, at once when
|
|
181
|
+
* nothing differs). */
|
|
182
|
+
const commit = (): Promise<string | undefined> => {
|
|
183
|
+
if (!explicit || same(draft, value)) return Promise.resolve(undefined);
|
|
184
|
+
setBusy(true);
|
|
185
|
+
setNote('');
|
|
186
|
+
return new Promise((resolve) => {
|
|
187
|
+
commitSettled.current = resolve;
|
|
188
|
+
pushed.current = { value: draft };
|
|
189
|
+
saver.push(draft);
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
/** `whole` without its sub-field at `path` (objects only; anything else as it is). */
|
|
193
|
+
const without = (whole: unknown, path: Path): unknown => {
|
|
194
|
+
if (!path.length || !isRecord(whole)) return whole;
|
|
195
|
+
const [key, ...rest] = path;
|
|
196
|
+
if (!rest.length) {
|
|
197
|
+
const { [String(key)]: _, ...kept } = whole;
|
|
198
|
+
return kept;
|
|
199
|
+
}
|
|
200
|
+
return { ...whole, [String(key)]: without(whole[String(key)], rest) };
|
|
201
|
+
};
|
|
202
|
+
/** An explicit setting's Remove: saved at once, from the saved value; the draft loses that sub-field too. */
|
|
203
|
+
const remove = (path: Path) => {
|
|
204
|
+
if (locked) return;
|
|
205
|
+
const next = without(draft, path);
|
|
206
|
+
setDraft(next);
|
|
207
|
+
write(without(value, path), next);
|
|
208
|
+
};
|
|
209
|
+
/** Drops an explicit setting's draft: the saved value again, its errors cleared. */
|
|
210
|
+
const discard = () => {
|
|
211
|
+
setDraft(value);
|
|
212
|
+
setError(undefined);
|
|
213
|
+
setRefusal('');
|
|
214
|
+
setNote('');
|
|
215
|
+
};
|
|
216
|
+
const saveJson = () => {
|
|
217
|
+
const read = readValue('json', json ?? '');
|
|
218
|
+
if (!read.ok) return setRefusal(read.message);
|
|
219
|
+
change(read.value);
|
|
220
|
+
};
|
|
221
|
+
const copy = (text: string, what: string) => {
|
|
222
|
+
void copyText(text).then(
|
|
223
|
+
() => setNote(`${what} copied`),
|
|
224
|
+
() => setRefusal('The clipboard is not available here.'),
|
|
225
|
+
);
|
|
226
|
+
};
|
|
227
|
+
const title = property.title ?? humanize(field);
|
|
228
|
+
const titleId = domId(scope, `setting-${id}`);
|
|
229
|
+
const ctx: FormContext = {
|
|
230
|
+
...form,
|
|
231
|
+
disabled: locked,
|
|
232
|
+
errorAt: (path) => anchored(property, error, path),
|
|
233
|
+
options,
|
|
234
|
+
needle,
|
|
235
|
+
saved: value,
|
|
236
|
+
id: titleId,
|
|
237
|
+
...(explicit ? { commit, discard, remove } : {}),
|
|
238
|
+
};
|
|
239
|
+
const composite =
|
|
240
|
+
control === 'object' ||
|
|
241
|
+
control === 'map' ||
|
|
242
|
+
control === 'list' ||
|
|
243
|
+
control === 'tags' ||
|
|
244
|
+
control === 'json';
|
|
245
|
+
|
|
246
|
+
const status = busy ? (
|
|
247
|
+
<span role="status" className="flex items-center gap-1 text-xs text-muted">
|
|
248
|
+
<Icon name="loader-circle" size={12} className="animate-spin motion-reduce:animate-none" />
|
|
249
|
+
{restart ? 'Restarting the workspace…' : 'Saving…'}
|
|
250
|
+
</span>
|
|
251
|
+
) : (
|
|
252
|
+
note && (
|
|
253
|
+
<span role="status" className="flex items-center gap-1 text-xs text-success">
|
|
254
|
+
<Icon name="check" size={12} />
|
|
255
|
+
{note}
|
|
256
|
+
</span>
|
|
257
|
+
)
|
|
258
|
+
);
|
|
259
|
+
const restartNote = restart && !busy && (
|
|
260
|
+
<span data-restart className="flex items-center gap-1 text-xs text-muted">
|
|
261
|
+
<Icon name="activity" size={12} />
|
|
262
|
+
Restarts the workspace
|
|
263
|
+
</span>
|
|
264
|
+
);
|
|
265
|
+
let input: React.ReactNode;
|
|
266
|
+
if (json !== undefined) {
|
|
267
|
+
input = (
|
|
268
|
+
<div className="flex flex-col gap-2">
|
|
269
|
+
<Textarea
|
|
270
|
+
variant="outline"
|
|
271
|
+
aria-labelledby={titleId}
|
|
272
|
+
spellCheck={false}
|
|
273
|
+
autoFocus
|
|
274
|
+
className="min-h-0 font-mono text-xs leading-relaxed"
|
|
275
|
+
placeholder="Not set"
|
|
276
|
+
disabled={locked}
|
|
277
|
+
value={json}
|
|
278
|
+
onChange={(event) => {
|
|
279
|
+
setJson(event.currentTarget.value);
|
|
280
|
+
setRefusal('');
|
|
281
|
+
setError(undefined);
|
|
282
|
+
}}
|
|
283
|
+
onKeyDown={(event) => {
|
|
284
|
+
if (event.key === 'Escape') {
|
|
285
|
+
setJson(undefined);
|
|
286
|
+
setRefusal('');
|
|
287
|
+
setError(undefined);
|
|
288
|
+
}
|
|
289
|
+
}}
|
|
290
|
+
/>
|
|
291
|
+
<div className="flex items-center gap-1.5">
|
|
292
|
+
<Button
|
|
293
|
+
size="sm"
|
|
294
|
+
variant="primary"
|
|
295
|
+
disabled={locked || json === textOf('json', value)}
|
|
296
|
+
onClick={saveJson}
|
|
297
|
+
>
|
|
298
|
+
Save
|
|
299
|
+
</Button>
|
|
300
|
+
<Button
|
|
301
|
+
size="sm"
|
|
302
|
+
disabled={busy}
|
|
303
|
+
onClick={() => {
|
|
304
|
+
setJson(undefined);
|
|
305
|
+
setRefusal('');
|
|
306
|
+
setError(undefined);
|
|
307
|
+
setDraft(value);
|
|
308
|
+
}}
|
|
309
|
+
>
|
|
310
|
+
Discard
|
|
311
|
+
</Button>
|
|
312
|
+
</div>
|
|
313
|
+
</div>
|
|
314
|
+
);
|
|
315
|
+
} else if (control === 'boolean') {
|
|
316
|
+
input = (
|
|
317
|
+
<label className="flex cursor-pointer items-start gap-2 text-[13px] leading-5 text-secondary has-disabled:cursor-default">
|
|
318
|
+
<Toggle
|
|
319
|
+
aria-label={title}
|
|
320
|
+
className="mt-0.5 shrink-0"
|
|
321
|
+
checked={draft === true}
|
|
322
|
+
disabled={locked}
|
|
323
|
+
onCheckedChange={(on) => change(on === true)}
|
|
324
|
+
/>
|
|
325
|
+
<span>
|
|
326
|
+
<Marked text={property.description ?? title} needle={needle} />
|
|
327
|
+
</span>
|
|
328
|
+
</label>
|
|
329
|
+
);
|
|
330
|
+
} else if (control === 'json') {
|
|
331
|
+
input = (
|
|
332
|
+
<code
|
|
333
|
+
data-summary
|
|
334
|
+
className="min-w-0 truncate rounded-sm bg-hover px-1.5 py-0.5 font-mono text-xs text-secondary"
|
|
335
|
+
>
|
|
336
|
+
{summaryOf(value)}
|
|
337
|
+
</code>
|
|
338
|
+
);
|
|
339
|
+
} else {
|
|
340
|
+
const generated = (
|
|
341
|
+
<Control
|
|
342
|
+
schema={property}
|
|
343
|
+
value={draft}
|
|
344
|
+
onChange={change}
|
|
345
|
+
ctx={ctx}
|
|
346
|
+
path={[]}
|
|
347
|
+
label={title}
|
|
348
|
+
labelledBy={titleId}
|
|
349
|
+
/>
|
|
350
|
+
);
|
|
351
|
+
// A group of sub-fields sits in a panel, like a map's cards.
|
|
352
|
+
input =
|
|
353
|
+
control === 'object' ? (
|
|
354
|
+
<div className="rounded-default border border-border bg-surface px-3 py-2">{generated}</div>
|
|
355
|
+
) : (
|
|
356
|
+
generated
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
const jsonLink = composite && json === undefined && (
|
|
360
|
+
<button
|
|
361
|
+
type="button"
|
|
362
|
+
data-json-link
|
|
363
|
+
disabled={readOnly}
|
|
364
|
+
onClick={() => {
|
|
365
|
+
setJson(textOf('json', value));
|
|
366
|
+
setError(undefined);
|
|
367
|
+
}}
|
|
368
|
+
className="cursor-pointer rounded-sm border-0 bg-transparent p-0 font-[inherit] text-xs text-muted underline-offset-2 outline-hidden hover:text-accent hover:underline focus-visible:underline focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-default disabled:opacity-50"
|
|
369
|
+
>
|
|
370
|
+
Edit in JSON
|
|
371
|
+
</button>
|
|
372
|
+
);
|
|
373
|
+
const rowError = json !== undefined && error ? describeError(error) : ctx.errorAt([]);
|
|
374
|
+
|
|
375
|
+
const details = property['x-bridge-details'];
|
|
376
|
+
// Its details, shown when its help button asks: closed by a click elsewhere or Escape.
|
|
377
|
+
const [helping, setHelping] = React.useState(false);
|
|
378
|
+
const line = React.useRef<HTMLDivElement>(null);
|
|
379
|
+
React.useEffect(() => {
|
|
380
|
+
if (!helping) return;
|
|
381
|
+
const close = (event: Event) => {
|
|
382
|
+
if (
|
|
383
|
+
event instanceof KeyboardEvent
|
|
384
|
+
? event.key === 'Escape'
|
|
385
|
+
: !line.current?.contains(event.target as Node)
|
|
386
|
+
)
|
|
387
|
+
setHelping(false);
|
|
388
|
+
};
|
|
389
|
+
document.addEventListener('pointerdown', close);
|
|
390
|
+
document.addEventListener('keydown', close);
|
|
391
|
+
return () => {
|
|
392
|
+
document.removeEventListener('pointerdown', close);
|
|
393
|
+
document.removeEventListener('keydown', close);
|
|
394
|
+
};
|
|
395
|
+
}, [helping]);
|
|
396
|
+
// The row as wide as ever, a column beside it (the screen 280px wider) for its details, shown when its help asks.
|
|
397
|
+
return (
|
|
398
|
+
<div
|
|
399
|
+
ref={line}
|
|
400
|
+
data-setting-line
|
|
401
|
+
data-field={field}
|
|
402
|
+
data-modified={modified || undefined}
|
|
403
|
+
className="flex items-stretch gap-3"
|
|
404
|
+
>
|
|
405
|
+
<Field
|
|
406
|
+
invalid={!!(rowError || refusal)}
|
|
407
|
+
disabled={locked}
|
|
408
|
+
className="group/setting relative min-w-0 flex-1 gap-1.5 rounded-control py-3 pl-5 pr-3"
|
|
409
|
+
>
|
|
410
|
+
{modified && (
|
|
411
|
+
<span
|
|
412
|
+
aria-hidden="true"
|
|
413
|
+
data-modified-bar
|
|
414
|
+
className="absolute inset-y-3 left-1 w-[3px] rounded-full bg-accent"
|
|
415
|
+
/>
|
|
416
|
+
)}
|
|
417
|
+
<div className="flex items-start gap-2">
|
|
418
|
+
<FieldLabel id={titleId} className="min-w-0 flex-1 text-[13px] leading-5">
|
|
419
|
+
<span className="font-semibold text-foreground">
|
|
420
|
+
<Marked text={title} needle={needle} />
|
|
421
|
+
</span>
|
|
422
|
+
</FieldLabel>
|
|
423
|
+
{/* Where the value comes from, on the title's line: one line less a row. */}
|
|
424
|
+
{origin !== undefined && originSource(label) !== '' && (
|
|
425
|
+
<span
|
|
426
|
+
data-origin
|
|
427
|
+
title={label}
|
|
428
|
+
className={cn(
|
|
429
|
+
'inline-flex h-5 max-w-[45%] shrink-0 items-center gap-1 truncate px-1 text-[11px] font-medium leading-5 text-muted',
|
|
430
|
+
// Shown with the buttons: on hover, on focus, while the help is open.
|
|
431
|
+
helping
|
|
432
|
+
? 'opacity-100'
|
|
433
|
+
: 'opacity-0 group-hover/setting:opacity-100 group-focus-within/setting:opacity-100',
|
|
434
|
+
)}
|
|
435
|
+
>
|
|
436
|
+
<Icon
|
|
437
|
+
name={
|
|
438
|
+
{ Custom: 'user', Workspace: 'building', Bridge: 'globe' }[originSource(label)] ??
|
|
439
|
+
'folder'
|
|
440
|
+
}
|
|
441
|
+
size={11}
|
|
442
|
+
/>
|
|
443
|
+
{originSource(label)}
|
|
444
|
+
</span>
|
|
445
|
+
)}
|
|
446
|
+
{/* Help, Reset and the gear in a box of one width: the badges before it line up. */}
|
|
447
|
+
<div className="flex w-[76px] shrink-0 justify-end gap-0.5">
|
|
448
|
+
{details && (
|
|
449
|
+
<Button
|
|
450
|
+
type="button"
|
|
451
|
+
size="icon-sm"
|
|
452
|
+
aria-label={`Help for ${title}`}
|
|
453
|
+
aria-expanded={helping}
|
|
454
|
+
aria-controls={`${titleId}-details`}
|
|
455
|
+
onClick={() => setHelping((was) => !was)}
|
|
456
|
+
className={cn(
|
|
457
|
+
'-my-0.5 size-6 text-muted',
|
|
458
|
+
helping
|
|
459
|
+
? 'bg-active text-foreground'
|
|
460
|
+
: 'opacity-0 group-hover/setting:opacity-100 group-focus-within/setting:opacity-100',
|
|
461
|
+
)}
|
|
462
|
+
>
|
|
463
|
+
<Icon name="circle-help" size={14} />
|
|
464
|
+
</Button>
|
|
465
|
+
)}
|
|
466
|
+
{modified && !readOnly && (
|
|
467
|
+
<Button
|
|
468
|
+
type="button"
|
|
469
|
+
size="icon-sm"
|
|
470
|
+
aria-label={`Reset ${title}`}
|
|
471
|
+
title="Reset Setting"
|
|
472
|
+
onClick={() => void write(undefined)}
|
|
473
|
+
className="-my-0.5 size-6 text-muted opacity-0 focus-visible:opacity-100 group-hover/setting:opacity-100 group-focus-within/setting:opacity-100"
|
|
474
|
+
>
|
|
475
|
+
<Icon name="rotate-ccw" size={14} />
|
|
476
|
+
</Button>
|
|
477
|
+
)}
|
|
478
|
+
<DropdownMenu>
|
|
479
|
+
<DropdownMenuTrigger
|
|
480
|
+
render={
|
|
481
|
+
<Button
|
|
482
|
+
size="icon-sm"
|
|
483
|
+
aria-label={`More actions for ${title}`}
|
|
484
|
+
className="-my-0.5 size-6 text-muted opacity-0 focus-visible:opacity-100 group-hover/setting:opacity-100 group-focus-within/setting:opacity-100 data-[popup-open]:opacity-100"
|
|
485
|
+
/>
|
|
486
|
+
}
|
|
487
|
+
>
|
|
488
|
+
<Icon name="settings" size={14} />
|
|
489
|
+
</DropdownMenuTrigger>
|
|
490
|
+
<DropdownMenuContent align="end">
|
|
491
|
+
{modified && !readOnly && (
|
|
492
|
+
<DropdownMenuItem onSelect={() => void write(undefined)}>
|
|
493
|
+
Reset Setting
|
|
494
|
+
</DropdownMenuItem>
|
|
495
|
+
)}
|
|
496
|
+
<DropdownMenuItem onSelect={() => copy(id, 'Setting ID')}>
|
|
497
|
+
Copy Setting ID
|
|
498
|
+
</DropdownMenuItem>
|
|
499
|
+
<DropdownMenuItem
|
|
500
|
+
onSelect={() => copy(JSON.stringify({ [id]: value ?? null }, null, 2), 'Setting')}
|
|
501
|
+
>
|
|
502
|
+
Copy Setting as JSON
|
|
503
|
+
</DropdownMenuItem>
|
|
504
|
+
</DropdownMenuContent>
|
|
505
|
+
</DropdownMenu>
|
|
506
|
+
</div>
|
|
507
|
+
</div>
|
|
508
|
+
{control !== 'boolean' && property.description && (
|
|
509
|
+
<p className="max-w-[640px] text-[13px] leading-5 text-secondary">
|
|
510
|
+
<Marked text={property.description} needle={needle} />
|
|
511
|
+
</p>
|
|
512
|
+
)}
|
|
513
|
+
{/* Too narrow for the column beside: the details asked for under the description. */}
|
|
514
|
+
{details && helping && (
|
|
515
|
+
<p className="max-w-[640px] text-xs leading-5 text-muted @min-[900px]/settings:hidden">
|
|
516
|
+
<Marked text={details} needle={needle} />
|
|
517
|
+
</p>
|
|
518
|
+
)}
|
|
519
|
+
<div
|
|
520
|
+
className={cn(
|
|
521
|
+
'mt-1',
|
|
522
|
+
composite ? 'flex flex-col gap-2' : 'flex flex-wrap items-center gap-x-3 gap-y-1.5',
|
|
523
|
+
)}
|
|
524
|
+
>
|
|
525
|
+
<div className={cn('min-w-0', composite && 'w-full')}>{input}</div>
|
|
526
|
+
{(restartNote || status || jsonLink) && (
|
|
527
|
+
<div className="flex flex-wrap items-center gap-x-3 gap-y-1">
|
|
528
|
+
{restartNote}
|
|
529
|
+
{status}
|
|
530
|
+
{jsonLink}
|
|
531
|
+
</div>
|
|
532
|
+
)}
|
|
533
|
+
</div>
|
|
534
|
+
<FieldError role="alert">{rowError || refusal}</FieldError>
|
|
535
|
+
</Field>
|
|
536
|
+
{/* Always there, empty or not: every row's block ends at the same edge; its details shown when its help button asks, a dark
|
|
537
|
+
tooltip centred on the row, pointing at it, free to overflow a short row. */}
|
|
538
|
+
<aside className="relative hidden w-64 shrink-0 @min-[900px]/settings:block">
|
|
539
|
+
{details && (
|
|
540
|
+
<div
|
|
541
|
+
data-setting-details
|
|
542
|
+
role="note"
|
|
543
|
+
id={`${titleId}-details`}
|
|
544
|
+
aria-hidden={!helping || undefined}
|
|
545
|
+
className={cn(
|
|
546
|
+
"absolute left-0 right-0 top-1/2 z-10 -translate-y-1/2 rounded-default bg-foreground px-3 py-2.5 text-xs leading-5 text-background transition-[opacity,translate] motion-reduce:translate-x-0 before:absolute before:-left-[4px] before:top-[calc(50%-5px)] before:size-2.5 before:rotate-45 before:bg-foreground before:content-['']",
|
|
547
|
+
helping
|
|
548
|
+
? 'translate-x-0 opacity-100 duration-200 ease-out'
|
|
549
|
+
: 'pointer-events-none -translate-x-1.5 opacity-0 duration-75 ease-in',
|
|
550
|
+
)}
|
|
551
|
+
>
|
|
552
|
+
<Marked text={details} needle={needle} />
|
|
553
|
+
</div>
|
|
554
|
+
)}
|
|
555
|
+
</aside>
|
|
556
|
+
</div>
|
|
557
|
+
);
|
|
558
|
+
}
|