@skillcdn/console 0.4.5 → 0.4.7
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/README.md +4 -4
- package/dist/api.d.ts +2 -2
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +2 -2
- package/dist/api.js.map +1 -1
- package/dist/cli/cli.d.ts +6 -0
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +83 -42
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/format.d.ts +8 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +11 -2
- package/dist/cli/format.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +22 -10
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/keys.d.ts +10 -0
- package/dist/cli/keys.d.ts.map +1 -0
- package/dist/cli/keys.js +59 -0
- package/dist/cli/keys.js.map +1 -0
- package/dist/cli/main.js +2 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/terminal.d.ts +7 -0
- package/dist/cli/terminal.d.ts.map +1 -1
- package/dist/cli/terminal.js +39 -0
- package/dist/cli/terminal.js.map +1 -1
- package/dist/client.d.ts +9 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +5 -1
- package/dist/client.js.map +1 -1
- package/dist/components/plugin-frame.d.ts.map +1 -1
- package/dist/components/plugin-frame.js +73 -17
- package/dist/components/plugin-frame.js.map +1 -1
- package/dist/components/sessions.d.ts +15 -0
- package/dist/components/sessions.d.ts.map +1 -0
- package/dist/components/sessions.js +17 -0
- package/dist/components/sessions.js.map +1 -0
- package/dist/components/shell.d.ts.map +1 -1
- package/dist/components/shell.js +198 -28
- package/dist/components/shell.js.map +1 -1
- package/dist/components/workspace.d.ts +2 -0
- package/dist/components/workspace.d.ts.map +1 -1
- package/dist/components/workspace.js +19 -4
- package/dist/components/workspace.js.map +1 -1
- package/dist/console.css +228 -21
- package/dist/console.d.ts +5 -2
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +106 -21
- package/dist/console.js.map +1 -1
- package/dist/data.d.ts +7 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +26 -5
- package/dist/data.js.map +1 -1
- package/dist/i18n/en.d.ts +24 -0
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +21 -0
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/index.d.ts +2 -2
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +7 -3
- package/dist/i18n/index.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +23 -2
- package/dist/i18n/ko.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugin/bridge.d.ts +7 -3
- package/dist/plugin/bridge.d.ts.map +1 -1
- package/dist/plugin/bridge.js +1 -0
- package/dist/plugin/bridge.js.map +1 -1
- package/dist/plugin/context.d.ts +16 -1
- package/dist/plugin/context.d.ts.map +1 -1
- package/dist/plugin/define.d.ts.map +1 -1
- package/dist/plugin/define.js +6 -3
- package/dist/plugin/define.js.map +1 -1
- package/dist/plugin/sandbox.d.ts.map +1 -1
- package/dist/plugin/sandbox.js +8 -1
- package/dist/plugin/sandbox.js.map +1 -1
- package/dist/plugin/web.d.ts +16 -3
- package/dist/plugin/web.d.ts.map +1 -1
- package/dist/plugin/web.js +8 -1
- package/dist/plugin/web.js.map +1 -1
- package/dist/router.d.ts +6 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +5 -0
- package/dist/router.js.map +1 -1
- package/dist/routes.d.ts +3 -1
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +2 -0
- package/dist/routes.js.map +1 -1
- package/dist/schemas.d.ts +38 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +37 -1
- package/dist/schemas.js.map +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/tokens.js +1 -0
- package/dist/tokens.js.map +1 -1
- package/dist/vocabulary.d.ts +6 -0
- package/dist/vocabulary.d.ts.map +1 -1
- package/dist/vocabulary.js +7 -0
- package/dist/vocabulary.js.map +1 -1
- package/docs/specs/cli.md +5 -5
- package/docs/specs/plugins.md +28 -15
- package/docs/specs/rest.md +12 -8
- package/package.json +1 -1
- package/skills/building-a-plugin/SKILL.md +3 -3
- package/skills/planning-the-board/references/setting-up.md +1 -1
- package/src/api.ts +6 -0
- package/src/cli/cli.ts +115 -43
- package/src/cli/format.ts +15 -2
- package/src/cli/help.ts +22 -10
- package/src/cli/keys.ts +69 -0
- package/src/cli/main.ts +2 -1
- package/src/cli/terminal.ts +40 -0
- package/src/client.ts +18 -0
- package/src/components/plugin-frame.tsx +92 -24
- package/src/components/sessions.tsx +108 -0
- package/src/components/shell.tsx +265 -52
- package/src/components/workspace.tsx +46 -2
- package/src/console.tsx +181 -16
- package/src/data.ts +33 -5
- package/src/i18n/en.ts +25 -0
- package/src/i18n/index.ts +11 -3
- package/src/i18n/ko.ts +27 -2
- package/src/index.ts +1 -0
- package/src/plugin/bridge.ts +8 -3
- package/src/plugin/context.ts +16 -1
- package/src/plugin/define.ts +10 -2
- package/src/plugin/sandbox.ts +9 -1
- package/src/plugin/web.ts +21 -4
- package/src/router.ts +7 -0
- package/src/routes.ts +3 -1
- package/src/schemas.ts +41 -0
- package/src/styles/console.css +228 -21
- package/src/tokens.ts +1 -0
- package/src/vocabulary.ts +9 -0
package/src/cli/terminal.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
3
|
import process from "node:process";
|
|
4
|
+
import { secretKeys } from "./keys.js";
|
|
4
5
|
|
|
5
6
|
// The terminal's side of the command: what is read from it. Nothing here is reached by tests,
|
|
6
7
|
// which hand the command readers of their own.
|
|
@@ -18,6 +19,45 @@ export function readStdin(): Promise<string> {
|
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
/**
|
|
23
|
+
* A secret typed at the terminal, unseen: the prompt goes to standard error, what is typed is
|
|
24
|
+
* echoed nowhere, Enter ends it, Backspace takes a character back, and Ctrl-C gives the command
|
|
25
|
+
* up as it does elsewhere; what a key that types nothing sends is not taken ({@link secretKeys}). A pipe or a file in place of the terminal is read whole, as
|
|
26
|
+
* {@link readStdin} reads it, so that a script hands the value over as before.
|
|
27
|
+
*/
|
|
28
|
+
export function readSecret(prompt: string): Promise<string> {
|
|
29
|
+
const { stdin, stderr } = process;
|
|
30
|
+
if (!stdin.isTTY) {
|
|
31
|
+
return readStdin();
|
|
32
|
+
}
|
|
33
|
+
stderr.write(prompt);
|
|
34
|
+
stdin.setRawMode(true);
|
|
35
|
+
stdin.resume();
|
|
36
|
+
stdin.setEncoding("utf8");
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
const keys = secretKeys();
|
|
39
|
+
const finish = (interrupted: boolean): void => {
|
|
40
|
+
stdin.off("data", onData);
|
|
41
|
+
stdin.setRawMode(false);
|
|
42
|
+
stdin.pause();
|
|
43
|
+
stderr.write("\n");
|
|
44
|
+
if (interrupted) {
|
|
45
|
+
// Raw mode delivers no signal for Ctrl-C: the command ends as any does on one.
|
|
46
|
+
process.kill(process.pid, "SIGINT");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
resolve(keys.typed);
|
|
50
|
+
};
|
|
51
|
+
const onData = (chunk: string): void => {
|
|
52
|
+
const state = keys.take(chunk);
|
|
53
|
+
if (state !== "reading") {
|
|
54
|
+
finish(state === "interrupted");
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
stdin.on("data", onData);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
21
61
|
/** A file named on the command line, as text. */
|
|
22
62
|
export function readFileAt(path: string): Promise<string> {
|
|
23
63
|
return readFile(path, "utf8");
|
package/src/client.ts
CHANGED
|
@@ -83,6 +83,7 @@ import {
|
|
|
83
83
|
type RestRunEndInput,
|
|
84
84
|
type RestRunInput,
|
|
85
85
|
type RestRuns,
|
|
86
|
+
type RestSessions,
|
|
86
87
|
type RestSkillBrowse,
|
|
87
88
|
type RestSkillFile,
|
|
88
89
|
type RestSkillFind,
|
|
@@ -148,6 +149,7 @@ import {
|
|
|
148
149
|
restRulesSchema,
|
|
149
150
|
restRunSchema,
|
|
150
151
|
restRunsSchema,
|
|
152
|
+
restSessionsSchema,
|
|
151
153
|
restSkillBrowseSchema,
|
|
152
154
|
restSkillFileSchema,
|
|
153
155
|
restSkillFindSchema,
|
|
@@ -665,10 +667,18 @@ export interface ConsoleClient {
|
|
|
665
667
|
* see or not (ADR-0068), as the project's `fileUrl` is for whoever may see the project.
|
|
666
668
|
*/
|
|
667
669
|
decisionFileUrl(decisionId: string, fileId: string): string;
|
|
670
|
+
/** The bytes of a file put on a decision, read at the decision's own address: wherever the decision is, as `decisionFileUrl` names it. */
|
|
671
|
+
readDecisionFile(decisionId: string, fileId: string, signal?: AbortSignal): Promise<FileRead>;
|
|
668
672
|
/** Another person's plate, within what the asker may see: for an administrator, or an owner of a project they are in. */
|
|
669
673
|
personWork(personId: string, signal?: AbortSignal): Promise<RestPersonWork>;
|
|
670
674
|
/** The tokens of whoever asks. */
|
|
671
675
|
tokens(signal?: AbortSignal): Promise<RestTokens>;
|
|
676
|
+
/** The browsers whoever asks is signed in on (board #309): the current first, then the last used first. */
|
|
677
|
+
sessions(signal?: AbortSignal): Promise<RestSessions>;
|
|
678
|
+
/** Ends one of the asker's sessions; the current one ends with the cookie. */
|
|
679
|
+
endSession(id: string): Promise<void>;
|
|
680
|
+
/** Ends every session of the asker but the one the request is made on. */
|
|
681
|
+
endOtherSessions(): Promise<void>;
|
|
672
682
|
/** The tokens of another person: for an administrator. */
|
|
673
683
|
personTokens(personId: string, signal?: AbortSignal): Promise<RestTokens>;
|
|
674
684
|
/** Takes another person's token away: for an administrator. */
|
|
@@ -1401,10 +1411,18 @@ export function createClient(options: ClientOptions = {}): ConsoleClient {
|
|
|
1401
1411
|
answerDecision: (id, input) =>
|
|
1402
1412
|
request("POST", `${base}${decisionPath(id)}/answer`, input, restDecisionSchema),
|
|
1403
1413
|
decisionFileUrl: (decisionId, fileId) => `${base}${decisionFilePath(decisionId, fileId)}`,
|
|
1414
|
+
readDecisionFile: (decisionId, fileId, signal) =>
|
|
1415
|
+
read(`${base}${decisionFilePath(decisionId, fileId)}`, fileId, signal),
|
|
1404
1416
|
personWork: (personId, signal) =>
|
|
1405
1417
|
request("GET", `${base}${personWorkPath(personId)}`, undefined, restPersonWorkSchema, signal),
|
|
1406
1418
|
tokens: (signal) =>
|
|
1407
1419
|
request("GET", `${base}${REST_ROUTES.tokens}`, undefined, restTokensSchema, signal),
|
|
1420
|
+
sessions: (signal) =>
|
|
1421
|
+
request("GET", `${base}${REST_ROUTES.sessions}`, undefined, restSessionsSchema, signal),
|
|
1422
|
+
endSession: (id) =>
|
|
1423
|
+
request("DELETE", `${base}${restPath("sessions", id)}`, undefined, undefined),
|
|
1424
|
+
endOtherSessions: () =>
|
|
1425
|
+
request("DELETE", `${base}${REST_ROUTES.sessions}/others`, undefined, undefined),
|
|
1408
1426
|
createToken: (input) =>
|
|
1409
1427
|
request("POST", `${base}${REST_ROUTES.tokens}`, input, restTokenCreatedSchema),
|
|
1410
1428
|
revokeToken: (id) =>
|
|
@@ -17,7 +17,8 @@ import type { Navigation } from "../router.js";
|
|
|
17
17
|
import type { RestEvent, RestMe, RestPlugin, RestProject } from "../schemas.js";
|
|
18
18
|
import { CONSOLE_TOKENS } from "../tokens.js";
|
|
19
19
|
import { wordsForFailure } from "../use-action.js";
|
|
20
|
-
import { CONSOLE_LANGUAGES } from "../vocabulary.js";
|
|
20
|
+
import { CONSOLE_LANGUAGES, languagesFirst } from "../vocabulary.js";
|
|
21
|
+
import { cx, Spinner } from "./ui.js";
|
|
21
22
|
import { weekStartOf } from "./workspace.js";
|
|
22
23
|
|
|
23
24
|
// A plugin's page or widget on the console's page (ADR-0054, docs/specs/plugins.md, "Pages"):
|
|
@@ -30,6 +31,11 @@ import { weekStartOf } from "./workspace.js";
|
|
|
30
31
|
const MAX_PAGE_HEIGHT = 20_000;
|
|
31
32
|
/** How often the plugin's own events are asked for while a frame listens for them. */
|
|
32
33
|
const EVENTS_POLL_MS = 5_000;
|
|
34
|
+
/**
|
|
35
|
+
* How long after a frame has loaded, or said it is ready, the spinner stands in its place when
|
|
36
|
+
* the page has not grown: a page that draws nothing to measure, or says no height.
|
|
37
|
+
*/
|
|
38
|
+
const DRAW_WAIT_MS = 5_000;
|
|
33
39
|
|
|
34
40
|
export interface PluginFrameProps {
|
|
35
41
|
readonly plugin: RestPlugin;
|
|
@@ -162,12 +168,20 @@ export async function performBridgeCall(
|
|
|
162
168
|
|
|
163
169
|
/** The console's computed design tokens, as the page's root has them: what a frame is told to look like. */
|
|
164
170
|
/**
|
|
165
|
-
* Whether a person pressed something a moment ago, as
|
|
166
|
-
*
|
|
167
|
-
*
|
|
171
|
+
* Whether a person pressed something in this frame a moment ago, as far as the page can tell, for
|
|
172
|
+
* a bundle built before 0.4.6, which asks the page to open its links (ADR-0067). The browser
|
|
173
|
+
* keeps a press for the whole page, wherever it was, so the page takes a press for the frame's
|
|
174
|
+
* only while the frame holds the page's focus, which a press in it gives it and a press anywhere
|
|
175
|
+
* else takes away. That is as far as a page sees into a frame: one that takes the focus itself is
|
|
176
|
+
* not told apart, which is why a frame opens its own links since 0.4.6, held by the browser to a
|
|
177
|
+
* press in it (ADR-0078). A browser without the API is left to decide for itself, as it does for
|
|
178
|
+
* any page.
|
|
168
179
|
*/
|
|
169
|
-
function
|
|
170
|
-
if (typeof navigator === "undefined") {
|
|
180
|
+
function pressedIn(element: HTMLIFrameElement | null): boolean {
|
|
181
|
+
if (typeof navigator === "undefined" || typeof document === "undefined" || element === null) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
if (document.activeElement !== element) {
|
|
171
185
|
return false;
|
|
172
186
|
}
|
|
173
187
|
const activation = (navigator as Navigator & { userActivation?: { isActive: boolean } })
|
|
@@ -223,6 +237,14 @@ export function PluginFrame(props: PluginFrameProps) {
|
|
|
223
237
|
const [height, setHeight] = useState(480);
|
|
224
238
|
/** Whether the console served the frame nothing to show: a plugin turned off since the page read it, say. */
|
|
225
239
|
const [unavailable, setUnavailable] = useState(false);
|
|
240
|
+
/**
|
|
241
|
+
* Whether the plugin's page has yet to draw: a spinner stands in the frame's place until the
|
|
242
|
+
* page grows past the height it had before it drew anything, which it says first, or for a
|
|
243
|
+
* while after the frame loaded, so that a page that draws nothing is shown as it is.
|
|
244
|
+
*/
|
|
245
|
+
const [drawing, setDrawing] = useState(true);
|
|
246
|
+
const drawWait = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
247
|
+
const emptyHeight = useRef<number | undefined>(undefined);
|
|
226
248
|
const subscribed = useRef<Set<BridgeEventKind>>(new Set());
|
|
227
249
|
const ready = useRef(false);
|
|
228
250
|
const lastPluginEvent = useRef(0);
|
|
@@ -239,7 +261,22 @@ export function PluginFrame(props: PluginFrameProps) {
|
|
|
239
261
|
[scoped, page, widget, project],
|
|
240
262
|
);
|
|
241
263
|
// biome-ignore lint/correctness/useExhaustiveDependencies: another address is another document
|
|
242
|
-
useEffect(() =>
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
setUnavailable(false);
|
|
266
|
+
setDrawing(true);
|
|
267
|
+
emptyHeight.current = undefined;
|
|
268
|
+
clearTimeout(drawWait.current);
|
|
269
|
+
}, [src]);
|
|
270
|
+
useEffect(() => () => clearTimeout(drawWait.current), []);
|
|
271
|
+
const drawn = useCallback(() => {
|
|
272
|
+
clearTimeout(drawWait.current);
|
|
273
|
+
setDrawing(false);
|
|
274
|
+
}, []);
|
|
275
|
+
/** The page is shown as it stands a while from now, whether or not it says a height by then. */
|
|
276
|
+
const drawnSoon = useCallback(() => {
|
|
277
|
+
clearTimeout(drawWait.current);
|
|
278
|
+
drawWait.current = setTimeout(() => setDrawing(false), DRAW_WAIT_MS);
|
|
279
|
+
}, []);
|
|
243
280
|
|
|
244
281
|
const post = useCallback((message: BridgeToFrame, transfer?: Transferable[]) => {
|
|
245
282
|
// The frame's origin is opaque, so the target is any: the frame itself checks the sender.
|
|
@@ -266,6 +303,7 @@ export function PluginFrame(props: PluginFrameProps) {
|
|
|
266
303
|
return;
|
|
267
304
|
case "ready":
|
|
268
305
|
ready.current = true;
|
|
306
|
+
drawnSoon();
|
|
269
307
|
post({
|
|
270
308
|
v: PLUGIN_BRIDGE_VERSION,
|
|
271
309
|
t: "init",
|
|
@@ -283,7 +321,8 @@ export function PluginFrame(props: PluginFrameProps) {
|
|
|
283
321
|
},
|
|
284
322
|
workspace: {
|
|
285
323
|
name: me.workspace.name,
|
|
286
|
-
|
|
324
|
+
language: me.workspace.language ?? CONSOLE_LANGUAGES[0],
|
|
325
|
+
languages: languagesFirst(me.workspace.language ?? CONSOLE_LANGUAGES[0]),
|
|
287
326
|
timeZone: me.workspace.timeZone ?? "UTC",
|
|
288
327
|
weekStart: weekStartOf(me.workspace),
|
|
289
328
|
firstDay: firstDayOfWeek(language, weekStartOf(me.workspace)),
|
|
@@ -318,6 +357,13 @@ export function PluginFrame(props: PluginFrameProps) {
|
|
|
318
357
|
}
|
|
319
358
|
return;
|
|
320
359
|
case "resize":
|
|
360
|
+
// The first height is the empty page's, said before the page drew anything, its own
|
|
361
|
+
// padding included; a greater one is the page drawn.
|
|
362
|
+
if (emptyHeight.current === undefined) {
|
|
363
|
+
emptyHeight.current = message.height;
|
|
364
|
+
} else if (message.height > emptyHeight.current) {
|
|
365
|
+
drawn();
|
|
366
|
+
}
|
|
321
367
|
// A widget fills the cells its size gives it (ADR-0059); a page is as tall as it asks.
|
|
322
368
|
if (!isWidget) {
|
|
323
369
|
setHeight(Math.max(40, Math.min(Math.ceil(message.height), MAX_PAGE_HEIGHT)));
|
|
@@ -337,11 +383,14 @@ export function PluginFrame(props: PluginFrameProps) {
|
|
|
337
383
|
return;
|
|
338
384
|
}
|
|
339
385
|
case "open":
|
|
340
|
-
// A link a
|
|
341
|
-
// new tab with no opener and no referrer,
|
|
342
|
-
//
|
|
343
|
-
|
|
386
|
+
// A link a frame built before 0.4.6 asks the page to open (ADR-0067): a web or a mail
|
|
387
|
+
// address, in a new tab with no opener and no referrer, while a press is recent and the
|
|
388
|
+
// frame holds the focus, which the page takes back as it opens one, so that another tab
|
|
389
|
+
// takes another press. A frame since opens its own links, held to a press in it by the
|
|
390
|
+
// browser (ADR-0078); the page stops hearing this at the next line.
|
|
391
|
+
if (isOpenableFrom(message.url, window.location.origin) && pressedIn(frame.current)) {
|
|
344
392
|
window.open(message.url, "_blank", "noopener,noreferrer");
|
|
393
|
+
frame.current?.blur();
|
|
345
394
|
}
|
|
346
395
|
return;
|
|
347
396
|
case "subscribe":
|
|
@@ -442,18 +491,37 @@ export function PluginFrame(props: PluginFrameProps) {
|
|
|
442
491
|
return <p className="sc-plugin-frame-unavailable">{words.frameUnavailable}</p>;
|
|
443
492
|
}
|
|
444
493
|
return (
|
|
445
|
-
<
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
isWidget ? "sc-plugin-frame
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
title={props.title}
|
|
452
|
-
// As the document's own policy says: scripts, and forms firing their submit event, which
|
|
453
|
-
// the policy's form-action 'none' keeps from going anywhere.
|
|
454
|
-
sandbox="allow-scripts allow-forms"
|
|
455
|
-
referrerPolicy="origin"
|
|
494
|
+
<div
|
|
495
|
+
className={cx(
|
|
496
|
+
"sc-plugin-frame-box",
|
|
497
|
+
isWidget ? "sc-plugin-frame-box-widget" : "sc-plugin-frame-box-page",
|
|
498
|
+
drawing && "sc-plugin-frame-loading",
|
|
499
|
+
)}
|
|
456
500
|
style={isWidget ? undefined : { height: `${height}px` }}
|
|
457
|
-
|
|
501
|
+
>
|
|
502
|
+
<iframe
|
|
503
|
+
ref={frame}
|
|
504
|
+
className={
|
|
505
|
+
isWidget
|
|
506
|
+
? "sc-plugin-frame sc-plugin-frame-widget"
|
|
507
|
+
: "sc-plugin-frame sc-plugin-frame-page"
|
|
508
|
+
}
|
|
509
|
+
src={src}
|
|
510
|
+
title={props.title}
|
|
511
|
+
// As the document's own policy says: scripts; forms firing their submit event, which the
|
|
512
|
+
// policy's form-action 'none' keeps from going anywhere; and a window for a link a person
|
|
513
|
+
// pressed in the frame, which the browser holds to the press (ADR-0078), opened out of the
|
|
514
|
+
// sandbox so that the page it shows is a page as any.
|
|
515
|
+
sandbox="allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox"
|
|
516
|
+
referrerPolicy="origin"
|
|
517
|
+
// Loaded, with its scripts run: a page that never says it is ready is shown as it is.
|
|
518
|
+
onLoad={drawnSoon}
|
|
519
|
+
/>
|
|
520
|
+
{drawing && (
|
|
521
|
+
<div className="sc-plugin-frame-wait">
|
|
522
|
+
<Spinner label={pack.common.loading} />
|
|
523
|
+
</div>
|
|
524
|
+
)}
|
|
525
|
+
</div>
|
|
458
526
|
);
|
|
459
527
|
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { RestSession } from "../api.js";
|
|
3
|
+
import { useWords } from "../i18n/index.js";
|
|
4
|
+
import { Badge, Button, cx, Time } from "./ui.js";
|
|
5
|
+
|
|
6
|
+
// The browsers a person is signed in on (board #309), on a page of the settings of their own: each
|
|
7
|
+
// with what it is, when it was last used, where it last came from and the day it signed in, the
|
|
8
|
+
// one they look from marked; the way to sign any other out, and all the others at once. Takes its
|
|
9
|
+
// data as props and nothing from the network.
|
|
10
|
+
|
|
11
|
+
export interface SessionListProps {
|
|
12
|
+
readonly sessions: readonly RestSession[];
|
|
13
|
+
/** How many days a session lasts without being used; left out, the page does not say. */
|
|
14
|
+
readonly idleDays?: number | undefined;
|
|
15
|
+
/** Called to end a session that is not the current one. Left out, sessions cannot be ended here. */
|
|
16
|
+
readonly onEnd?: ((session: RestSession) => void) | undefined;
|
|
17
|
+
/** Called to end every session but the current one. Left out, there is no such button. */
|
|
18
|
+
readonly onEndOthers?: (() => void) | undefined;
|
|
19
|
+
readonly busy?: boolean | undefined;
|
|
20
|
+
readonly empty?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The platforms held in a hand, as the server names them: drawn as a phone, the rest as a screen. */
|
|
24
|
+
const HANDHELD: ReadonlySet<string> = new Set(["iOS", "Android"]);
|
|
25
|
+
|
|
26
|
+
function DeviceIcon(props: { readonly handheld: boolean }) {
|
|
27
|
+
return (
|
|
28
|
+
<span className="sc-session-icon">
|
|
29
|
+
<svg viewBox="0 0 20 20" aria-hidden="true">
|
|
30
|
+
{props.handheld ? (
|
|
31
|
+
<>
|
|
32
|
+
<rect x="5.5" y="2.5" width="9" height="15" rx="2" />
|
|
33
|
+
<path d="M9 14.75h2" />
|
|
34
|
+
</>
|
|
35
|
+
) : (
|
|
36
|
+
<>
|
|
37
|
+
<rect x="2.5" y="3.5" width="15" height="10" rx="1.5" />
|
|
38
|
+
<path d="M7 16.5h6M10 13.5v3" />
|
|
39
|
+
</>
|
|
40
|
+
)}
|
|
41
|
+
</svg>
|
|
42
|
+
</span>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function SessionList(props: SessionListProps) {
|
|
47
|
+
const words = useWords().sessions;
|
|
48
|
+
const others = props.sessions.filter((session) => !session.current);
|
|
49
|
+
const deviceOf = (session: RestSession): string =>
|
|
50
|
+
session.browser !== null && session.platform !== null
|
|
51
|
+
? words.on(session.browser, session.platform)
|
|
52
|
+
: (session.browser ?? session.platform ?? words.unknownBrowser);
|
|
53
|
+
return (
|
|
54
|
+
<section className="sc-panel sc-sessions" aria-label={words.title}>
|
|
55
|
+
<div className="sc-section-head">
|
|
56
|
+
<h2 className="sc-section-title">{words.title}</h2>
|
|
57
|
+
{props.onEndOthers !== undefined && others.length > 0 && (
|
|
58
|
+
<Button size="sm" disabled={props.busy} onClick={props.onEndOthers}>
|
|
59
|
+
{words.endOthers}
|
|
60
|
+
</Button>
|
|
61
|
+
)}
|
|
62
|
+
</div>
|
|
63
|
+
<p className="sc-settings-hint">
|
|
64
|
+
{props.idleDays === undefined ? words.intro : words.introIdle(String(props.idleDays))}
|
|
65
|
+
</p>
|
|
66
|
+
{props.sessions.length === 0 ? (
|
|
67
|
+
(props.empty ?? null)
|
|
68
|
+
) : (
|
|
69
|
+
<ul className="sc-session-list" aria-label={words.list}>
|
|
70
|
+
{props.sessions.map((session) => (
|
|
71
|
+
<li
|
|
72
|
+
key={session.id}
|
|
73
|
+
className={cx("sc-session", session.current && "sc-session-current")}
|
|
74
|
+
>
|
|
75
|
+
<DeviceIcon handheld={session.platform !== null && HANDHELD.has(session.platform)} />
|
|
76
|
+
<div className="sc-session-body">
|
|
77
|
+
<p className="sc-session-name">
|
|
78
|
+
<span>{deviceOf(session)}</span>
|
|
79
|
+
{session.current && <Badge tone="accent">{words.current}</Badge>}
|
|
80
|
+
</p>
|
|
81
|
+
<p className="sc-session-meta">
|
|
82
|
+
<span>
|
|
83
|
+
{words.lastActive} <Time iso={session.lastSeenAt} />
|
|
84
|
+
</span>
|
|
85
|
+
{session.address !== null && <span>{words.from(session.address)}</span>}
|
|
86
|
+
<span>
|
|
87
|
+
{words.signedIn} <Time iso={session.createdAt} precision="day" />
|
|
88
|
+
</span>
|
|
89
|
+
</p>
|
|
90
|
+
</div>
|
|
91
|
+
{!session.current && props.onEnd !== undefined && (
|
|
92
|
+
<Button
|
|
93
|
+
size="sm"
|
|
94
|
+
variant="ghost"
|
|
95
|
+
className="sc-session-end"
|
|
96
|
+
disabled={props.busy}
|
|
97
|
+
onClick={() => props.onEnd?.(session)}
|
|
98
|
+
>
|
|
99
|
+
{words.end}
|
|
100
|
+
</Button>
|
|
101
|
+
)}
|
|
102
|
+
</li>
|
|
103
|
+
))}
|
|
104
|
+
</ul>
|
|
105
|
+
)}
|
|
106
|
+
</section>
|
|
107
|
+
);
|
|
108
|
+
}
|