@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/components/shell.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReactNode, useEffect, useRef } from "react";
|
|
1
|
+
import { Fragment, type ReactNode, useEffect, useId, useRef, useState } from "react";
|
|
2
2
|
import type { RestPerson } from "../api.js";
|
|
3
3
|
import { useWords } from "../i18n/index.js";
|
|
4
4
|
import { Avatar, cx, personName } from "./ui.js";
|
|
@@ -69,30 +69,236 @@ export function isPlainClick(event: {
|
|
|
69
69
|
return event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/** A
|
|
72
|
+
/** A page of a menu, by its name: followed in place for a plain click, and the menu closes. */
|
|
73
|
+
function MenuLink(props: {
|
|
74
|
+
readonly item: NavItem;
|
|
75
|
+
readonly onFollow: (href: string) => void;
|
|
76
|
+
readonly className?: string | undefined;
|
|
77
|
+
}) {
|
|
78
|
+
const { item } = props;
|
|
79
|
+
return (
|
|
80
|
+
<a
|
|
81
|
+
href={item.href}
|
|
82
|
+
className={cx("sc-menu-link", props.className)}
|
|
83
|
+
aria-current={item.current ? "page" : undefined}
|
|
84
|
+
onClick={(event) => {
|
|
85
|
+
if (isPlainClick(event)) {
|
|
86
|
+
event.preventDefault();
|
|
87
|
+
props.onFollow(item.href);
|
|
88
|
+
}
|
|
89
|
+
}}
|
|
90
|
+
>
|
|
91
|
+
{item.label}
|
|
92
|
+
</a>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The widest name a tab shows whole, in Latin letters: the stylesheet stops a wider one short
|
|
98
|
+
* with an ellipsis, about here, and the tab's title carries it whole. A plugin's name runs to
|
|
99
|
+
* 40 characters.
|
|
100
|
+
*/
|
|
101
|
+
const TAB_LABEL_WHOLE = 28;
|
|
102
|
+
|
|
103
|
+
/** The characters a name runs about twice as wide in: Hangul, the Chinese characters, kana, the full-width forms. */
|
|
104
|
+
const WIDE =
|
|
105
|
+
/[\u1100-\u115f\u2e80-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6]/u;
|
|
106
|
+
|
|
107
|
+
/** How wide a name runs, in Latin letters. */
|
|
108
|
+
function widthOf(label: string): number {
|
|
109
|
+
let width = 0;
|
|
110
|
+
for (const character of label) {
|
|
111
|
+
width += WIDE.test(character) ? 2 : 1;
|
|
112
|
+
}
|
|
113
|
+
return width;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A tab's name, as the stylesheet may stop it short, and the title that then says it whole. */
|
|
117
|
+
function tabLabel(label: string): { readonly title: string | undefined } {
|
|
118
|
+
return { title: widthOf(label) > TAB_LABEL_WHOLE ? label : undefined };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** How close to the window's edge a list opened from a tab may come. */
|
|
122
|
+
const PANEL_GUTTER_PX = 8;
|
|
123
|
+
/** How far below its tab, off the header's line, a list opens. */
|
|
124
|
+
const PANEL_DROP_PX = 6;
|
|
125
|
+
/** How far a list's edge stands before the names in it: its own padding and a link's. */
|
|
126
|
+
const PANEL_INSET_PX = 14;
|
|
127
|
+
|
|
128
|
+
/** The least a list is let be tall where the window is short: a few of its pages, scrolled. */
|
|
129
|
+
const PANEL_SHORTEST_PX = 120;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Whether the browser shows a popover. One that does not, as Safari before 17, has the list
|
|
133
|
+
* shown and hidden by the tab itself, without the browser's ways of closing it.
|
|
134
|
+
*/
|
|
135
|
+
const POPOVERS =
|
|
136
|
+
typeof HTMLElement === "undefined" || typeof HTMLElement.prototype.showPopover === "function";
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Puts the list a tab opened under the tab, the names in it lined up with the tab's, within the
|
|
140
|
+
* page's width, the scrollbar left out, and no taller than the window has room for below it, a
|
|
141
|
+
* longer list scrolling within itself: the list is in the top layer, where nothing of the page
|
|
142
|
+
* places it.
|
|
143
|
+
*/
|
|
144
|
+
function placeUnder(tab: HTMLElement | null, box: HTMLElement | null): void {
|
|
145
|
+
if (tab === null || box === null) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const at = tab.getBoundingClientRect();
|
|
149
|
+
const { clientWidth, clientHeight } = document.documentElement;
|
|
150
|
+
const room = clientWidth - box.offsetWidth - PANEL_GUTTER_PX;
|
|
151
|
+
const top = at.bottom + PANEL_DROP_PX;
|
|
152
|
+
box.style.left = `${Math.max(PANEL_GUTTER_PX, Math.min(at.left - PANEL_INSET_PX, room))}px`;
|
|
153
|
+
box.style.top = `${top}px`;
|
|
154
|
+
box.style.maxHeight = `${Math.max(PANEL_SHORTEST_PX, clientHeight - top - PANEL_GUTTER_PX)}px`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Closes a list: the browser's popover, or the list the tab shows by hand where there is none. */
|
|
158
|
+
function hideList(box: HTMLElement | null, setOpen: (open: boolean) => void): void {
|
|
159
|
+
if (!POPOVERS) {
|
|
160
|
+
setOpen(false);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (box?.matches(":popover-open") === true) {
|
|
164
|
+
box.hidePopover();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** How long a mouse rests on a tab before its list opens: one passing along the row opens nothing. */
|
|
169
|
+
const HOVER_OPEN_MS = 80;
|
|
170
|
+
/** How long a list stays once the mouse has left it and its tab: the moment it takes to cross from one to the other. */
|
|
171
|
+
const HOVER_LEAVE_MS = 200;
|
|
172
|
+
|
|
173
|
+
/** Whether a click is a mouse's, which had the list open under it before it clicked; a finger's, a pen's or a key's otherwise. */
|
|
174
|
+
function byMouse(event: Event): boolean {
|
|
175
|
+
return (
|
|
176
|
+
typeof PointerEvent !== "undefined" &&
|
|
177
|
+
event instanceof PointerEvent &&
|
|
178
|
+
event.pointerType === "mouse"
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* A tab that opens a list of pages, as a group of several plugins does. The list is a popover:
|
|
184
|
+
* in the top layer, out of the row of tabs, which scrolls sideways and clips whatever hangs out
|
|
185
|
+
* of it, and dismissed by a click elsewhere or the escape key, as the browser does it. A mouse
|
|
186
|
+
* resting on the tab opens it, and leaving the tab and the list closes it; a mouse's click on
|
|
187
|
+
* the tab, with the list open under it already, goes where the tab leads, the group's first
|
|
188
|
+
* page; a finger, a pen or a key opens and closes the list by a press. Placed under its tab
|
|
189
|
+
* when it opens; closed once used, when the row scrolls or the window changes, and when the
|
|
190
|
+
* window loses the focus, as it does to a click in a plugin's frame, which the page never sees.
|
|
191
|
+
*/
|
|
73
192
|
function TabGroup(props: { readonly item: NavItem; readonly onNavigate: (href: string) => void }) {
|
|
74
|
-
const
|
|
193
|
+
const id = useId();
|
|
194
|
+
const tab = useRef<HTMLButtonElement>(null);
|
|
195
|
+
const panel = useRef<HTMLDivElement>(null);
|
|
196
|
+
const [open, setOpen] = useState(false);
|
|
197
|
+
const resting = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
198
|
+
const { item } = props;
|
|
199
|
+
const after = (ms: number, what: () => void) => {
|
|
200
|
+
clearTimeout(resting.current);
|
|
201
|
+
resting.current = setTimeout(what, ms);
|
|
202
|
+
};
|
|
203
|
+
// Shown here rather than by the browser, and placed at once, before anything is painted: the
|
|
204
|
+
// list has its width only once it shows, and a list placed before that, then again once the
|
|
205
|
+
// browser said it opened, could stand out of the window in between. The button stays its
|
|
206
|
+
// invoker, so that a click on it is not a click outside that closes it first.
|
|
207
|
+
const show = () => {
|
|
208
|
+
const box = panel.current;
|
|
209
|
+
if (box === null) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!POPOVERS) {
|
|
213
|
+
setOpen(true);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (!box.matches(":popover-open")) {
|
|
217
|
+
box.showPopover();
|
|
218
|
+
placeUnder(tab.current, box);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
const hide = () => hideList(panel.current, setOpen);
|
|
75
222
|
useEffect(() => {
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
|
|
223
|
+
const box = panel.current;
|
|
224
|
+
if (box === null) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const onToggle = (event: Event) => {
|
|
228
|
+
setOpen((event as ToggleEvent).newState === "open");
|
|
229
|
+
};
|
|
230
|
+
// Open, it is where its tab is; the row of tabs scrolling, or the window changing, would
|
|
231
|
+
// leave it where the tab no longer is, so either closes it, and so does the window losing
|
|
232
|
+
// the focus. A scroll within the list is the list's own. Heard from the start rather than
|
|
233
|
+
// once the page knows it opened, which comes a moment after it shows.
|
|
234
|
+
const close = (event: Event) => {
|
|
235
|
+
const shown = POPOVERS ? box.matches(":popover-open") : !box.hidden;
|
|
236
|
+
const within =
|
|
237
|
+
event.type === "scroll" && event.target instanceof Node && box.contains(event.target);
|
|
238
|
+
if (shown && !within) {
|
|
239
|
+
hideList(box, setOpen);
|
|
83
240
|
}
|
|
84
241
|
};
|
|
85
|
-
|
|
86
|
-
|
|
242
|
+
box.addEventListener("toggle", onToggle);
|
|
243
|
+
window.addEventListener("resize", close);
|
|
244
|
+
window.addEventListener("scroll", close, true);
|
|
245
|
+
window.addEventListener("blur", close);
|
|
246
|
+
return () => {
|
|
247
|
+
clearTimeout(resting.current);
|
|
248
|
+
box.removeEventListener("toggle", onToggle);
|
|
249
|
+
window.removeEventListener("resize", close);
|
|
250
|
+
window.removeEventListener("scroll", close, true);
|
|
251
|
+
window.removeEventListener("blur", close);
|
|
252
|
+
};
|
|
87
253
|
}, []);
|
|
88
|
-
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
// Shown by the tab itself where the browser has no popover: placed now that it shows.
|
|
256
|
+
if (open && !POPOVERS) {
|
|
257
|
+
placeUnder(tab.current, panel.current);
|
|
258
|
+
}
|
|
259
|
+
}, [open]);
|
|
89
260
|
return (
|
|
90
|
-
<
|
|
91
|
-
|
|
261
|
+
<div
|
|
262
|
+
className="sc-tab-group"
|
|
263
|
+
// The list is a child of this box, wherever the browser draws it: a mouse over either is
|
|
264
|
+
// over the box, and leaving the box is leaving both.
|
|
265
|
+
onPointerEnter={(event) => {
|
|
266
|
+
if (event.pointerType === "mouse") {
|
|
267
|
+
after(HOVER_OPEN_MS, show);
|
|
268
|
+
}
|
|
269
|
+
}}
|
|
270
|
+
onPointerLeave={(event) => {
|
|
271
|
+
if (event.pointerType === "mouse") {
|
|
272
|
+
after(HOVER_LEAVE_MS, hide);
|
|
273
|
+
}
|
|
274
|
+
}}
|
|
275
|
+
>
|
|
276
|
+
<button
|
|
277
|
+
type="button"
|
|
278
|
+
ref={tab}
|
|
92
279
|
className={cx("sc-tab", "sc-tab-summary", item.current && "sc-tab-current")}
|
|
93
280
|
aria-current={item.current ? "page" : undefined}
|
|
281
|
+
aria-expanded={open}
|
|
282
|
+
aria-controls={id}
|
|
283
|
+
popoverTarget={id}
|
|
284
|
+
{...tabLabel(item.label)}
|
|
285
|
+
onClick={(event) => {
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
clearTimeout(resting.current);
|
|
288
|
+
if (byMouse(event.nativeEvent)) {
|
|
289
|
+
hide();
|
|
290
|
+
props.onNavigate(item.href);
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
const shown = POPOVERS ? panel.current?.matches(":popover-open") === true : open;
|
|
294
|
+
if (shown) {
|
|
295
|
+
hide();
|
|
296
|
+
} else {
|
|
297
|
+
show();
|
|
298
|
+
}
|
|
299
|
+
}}
|
|
94
300
|
>
|
|
95
|
-
{item.label}
|
|
301
|
+
<span className="sc-tab-label">{item.label}</span>
|
|
96
302
|
<svg className="sc-menu-caret" viewBox="0 0 16 16" aria-hidden="true">
|
|
97
303
|
<path
|
|
98
304
|
d="M4 6l4 4 4-4"
|
|
@@ -103,31 +309,29 @@ function TabGroup(props: { readonly item: NavItem; readonly onNavigate: (href: s
|
|
|
103
309
|
strokeLinejoin="round"
|
|
104
310
|
/>
|
|
105
311
|
</svg>
|
|
106
|
-
</
|
|
107
|
-
<div
|
|
312
|
+
</button>
|
|
313
|
+
<div
|
|
314
|
+
id={id}
|
|
315
|
+
ref={panel}
|
|
316
|
+
popover="auto"
|
|
317
|
+
hidden={!POPOVERS && !open}
|
|
318
|
+
className="sc-menu-panel sc-tab-group-panel"
|
|
319
|
+
>
|
|
108
320
|
<div className="sc-menu-list">
|
|
109
321
|
{(item.children ?? []).map((child) => (
|
|
110
|
-
<
|
|
322
|
+
<MenuLink
|
|
111
323
|
key={child.href}
|
|
112
|
-
|
|
113
|
-
className="sc-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
event.preventDefault();
|
|
118
|
-
if (details.current !== null) {
|
|
119
|
-
details.current.open = false;
|
|
120
|
-
}
|
|
121
|
-
props.onNavigate(child.href);
|
|
122
|
-
}
|
|
324
|
+
item={child}
|
|
325
|
+
className="sc-group-link"
|
|
326
|
+
onFollow={(href) => {
|
|
327
|
+
hide();
|
|
328
|
+
props.onNavigate(href);
|
|
123
329
|
}}
|
|
124
|
-
|
|
125
|
-
{child.label}
|
|
126
|
-
</a>
|
|
330
|
+
/>
|
|
127
331
|
))}
|
|
128
332
|
</div>
|
|
129
333
|
</div>
|
|
130
|
-
</
|
|
334
|
+
</div>
|
|
131
335
|
);
|
|
132
336
|
}
|
|
133
337
|
|
|
@@ -147,6 +351,10 @@ function PersonMenu(props: {
|
|
|
147
351
|
details.current.open = false;
|
|
148
352
|
}
|
|
149
353
|
};
|
|
354
|
+
const follow = (href: string) => {
|
|
355
|
+
close();
|
|
356
|
+
props.onNavigate(href);
|
|
357
|
+
};
|
|
150
358
|
// A click elsewhere, or the escape key, closes it, as a menu is expected to.
|
|
151
359
|
useEffect(() => {
|
|
152
360
|
const onClick = (event: MouseEvent) => {
|
|
@@ -163,11 +371,19 @@ function PersonMenu(props: {
|
|
|
163
371
|
details.current.open = false;
|
|
164
372
|
}
|
|
165
373
|
};
|
|
374
|
+
// A click in a plugin's frame is a click elsewhere the page never sees: the window loses the focus.
|
|
375
|
+
const onBlur = () => {
|
|
376
|
+
if (details.current !== null) {
|
|
377
|
+
details.current.open = false;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
166
380
|
document.addEventListener("click", onClick);
|
|
167
381
|
document.addEventListener("keydown", onKey);
|
|
382
|
+
window.addEventListener("blur", onBlur);
|
|
168
383
|
return () => {
|
|
169
384
|
document.removeEventListener("click", onClick);
|
|
170
385
|
document.removeEventListener("keydown", onKey);
|
|
386
|
+
window.removeEventListener("blur", onBlur);
|
|
171
387
|
};
|
|
172
388
|
}, []);
|
|
173
389
|
const { person } = props;
|
|
@@ -193,23 +409,19 @@ function PersonMenu(props: {
|
|
|
193
409
|
{person.name !== null && <span className="sc-muted">{person.login}</span>}
|
|
194
410
|
</p>
|
|
195
411
|
<nav className="sc-menu-list" aria-label={words.shell.workspace}>
|
|
196
|
-
{props.items.map((item) =>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
>
|
|
210
|
-
{item.label}
|
|
211
|
-
</a>
|
|
212
|
-
))}
|
|
412
|
+
{props.items.map((item) =>
|
|
413
|
+
item.children !== undefined && item.children.length > 0 ? (
|
|
414
|
+
// A group of plugins, one by one under the group's name: where a tab opens a list.
|
|
415
|
+
<Fragment key={item.href}>
|
|
416
|
+
<p className="sc-menu-heading">{item.label}</p>
|
|
417
|
+
{item.children.map((child) => (
|
|
418
|
+
<MenuLink key={child.href} item={child} onFollow={follow} />
|
|
419
|
+
))}
|
|
420
|
+
</Fragment>
|
|
421
|
+
) : (
|
|
422
|
+
<MenuLink key={item.href} item={item} onFollow={follow} />
|
|
423
|
+
),
|
|
424
|
+
)}
|
|
213
425
|
</nav>
|
|
214
426
|
{props.languages.length > 1 && props.onLanguage !== undefined && (
|
|
215
427
|
<fieldset className="sc-menu-languages">
|
|
@@ -369,9 +581,10 @@ export function Shell(props: ShellProps) {
|
|
|
369
581
|
href={item.href}
|
|
370
582
|
className={cx("sc-tab", item.current && "sc-tab-current")}
|
|
371
583
|
aria-current={item.current ? "page" : undefined}
|
|
584
|
+
{...tabLabel(item.label)}
|
|
372
585
|
onClick={follow(item.href)}
|
|
373
586
|
>
|
|
374
|
-
{item.label}
|
|
587
|
+
<span className="sc-tab-label">{item.label}</span>
|
|
375
588
|
{item.count !== undefined && item.count > 0 && (
|
|
376
589
|
<span className="sc-nav-count">{item.count}</span>
|
|
377
590
|
)}
|
|
@@ -8,7 +8,8 @@ import {
|
|
|
8
8
|
WEEK_STARTS,
|
|
9
9
|
type WeekStart,
|
|
10
10
|
} from "../api.js";
|
|
11
|
-
import { useWords } from "../i18n/index.js";
|
|
11
|
+
import { DEFAULT_LANGUAGES, packFor, useWords } from "../i18n/index.js";
|
|
12
|
+
import { CONSOLE_LANGUAGES } from "../vocabulary.js";
|
|
12
13
|
import { Button } from "./ui.js";
|
|
13
14
|
|
|
14
15
|
// The workspace's own settings (ADR-0035), as an administrator keeps them on the Settings page:
|
|
@@ -34,6 +35,14 @@ export function timeZoneOf(workspace: RestWorkspace | undefined): string | undef
|
|
|
34
35
|
return workspace?.timeZone ?? undefined;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/** The workspace's language (ADR-0081), or none. */
|
|
39
|
+
export function workspaceLanguageOf(workspace: RestWorkspace | undefined): string | undefined {
|
|
40
|
+
return workspace?.language ?? undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A language as it calls itself, `한국어`, from the packs the package ships; the tag where none speaks it. */
|
|
44
|
+
const languageLabel = (tag: string): string => packFor(tag, DEFAULT_LANGUAGES)?.label ?? tag;
|
|
45
|
+
|
|
37
46
|
/** The zones this browser knows, for the picker to offer; none where it cannot say. */
|
|
38
47
|
export function knownTimeZones(): readonly string[] {
|
|
39
48
|
try {
|
|
@@ -133,6 +142,7 @@ export function WorkspaceSettingsView(props: WorkspaceSettingsViewProps) {
|
|
|
133
142
|
const zone = timeZoneOf(props.workspace);
|
|
134
143
|
const device = deviceTimeZone();
|
|
135
144
|
const offset = zone === undefined ? undefined : offsetOf(zone, new Date());
|
|
145
|
+
const language = workspaceLanguageOf(props.workspace);
|
|
136
146
|
return (
|
|
137
147
|
<dl className="sc-settings-list">
|
|
138
148
|
{props.console !== undefined && (
|
|
@@ -170,6 +180,10 @@ export function WorkspaceSettingsView(props: WorkspaceSettingsViewProps) {
|
|
|
170
180
|
)}
|
|
171
181
|
</dd>
|
|
172
182
|
</div>
|
|
183
|
+
<div className="sc-settings-item">
|
|
184
|
+
<dt>{settings.language}</dt>
|
|
185
|
+
<dd>{language === undefined ? settings.languageNone : languageLabel(language)}</dd>
|
|
186
|
+
</div>
|
|
173
187
|
</dl>
|
|
174
188
|
);
|
|
175
189
|
}
|
|
@@ -186,17 +200,19 @@ export interface WorkspaceSettingsFormProps {
|
|
|
186
200
|
export function WorkspaceSettingsForm(props: WorkspaceSettingsFormProps) {
|
|
187
201
|
const words = useWords();
|
|
188
202
|
const settings = words.settings.workspace;
|
|
189
|
-
const ids = { people: useId(), week: useId(), zone: useId() };
|
|
203
|
+
const ids = { people: useId(), week: useId(), zone: useId(), language: useId() };
|
|
190
204
|
const current = {
|
|
191
205
|
peopleVisibility: peopleVisibilityOf(props.workspace),
|
|
192
206
|
weekStart: weekStartOf(props.workspace),
|
|
193
207
|
timeZone: timeZoneOf(props.workspace) ?? "",
|
|
208
|
+
language: workspaceLanguageOf(props.workspace) ?? "",
|
|
194
209
|
};
|
|
195
210
|
const [peopleVisibility, setPeopleVisibility] = useState<PeopleVisibility>(
|
|
196
211
|
current.peopleVisibility,
|
|
197
212
|
);
|
|
198
213
|
const [weekStart, setWeekStart] = useState<WeekStart>(current.weekStart);
|
|
199
214
|
const [timeZone, setTimeZone] = useState(current.timeZone);
|
|
215
|
+
const [language, setLanguage] = useState(current.language);
|
|
200
216
|
const device = useMemo(deviceTimeZone, []);
|
|
201
217
|
// UTC is offered whatever the browser lists, beside the zone set and the device's.
|
|
202
218
|
const groups = useMemo(
|
|
@@ -207,6 +223,11 @@ export function WorkspaceSettingsForm(props: WorkspaceSettingsFormProps) {
|
|
|
207
223
|
...(peopleVisibility === current.peopleVisibility ? {} : { peopleVisibility }),
|
|
208
224
|
...(weekStart === current.weekStart ? {} : { weekStart }),
|
|
209
225
|
...(timeZone === current.timeZone ? {} : { timeZone: timeZone === "" ? null : timeZone }),
|
|
226
|
+
...(language === current.language
|
|
227
|
+
? {}
|
|
228
|
+
: {
|
|
229
|
+
language: CONSOLE_LANGUAGES.find((candidate) => candidate === language) ?? null,
|
|
230
|
+
}),
|
|
210
231
|
};
|
|
211
232
|
const changed = Object.keys(patch).length > 0;
|
|
212
233
|
const submit = (event: FormEvent) => {
|
|
@@ -301,6 +322,29 @@ export function WorkspaceSettingsForm(props: WorkspaceSettingsFormProps) {
|
|
|
301
322
|
)}
|
|
302
323
|
</div>
|
|
303
324
|
</div>
|
|
325
|
+
<div className="sc-settings-row">
|
|
326
|
+
<div className="sc-settings-words">
|
|
327
|
+
<label className="sc-settings-label" htmlFor={ids.language}>
|
|
328
|
+
{settings.language}
|
|
329
|
+
</label>
|
|
330
|
+
<p className="sc-settings-hint">{settings.languageHint}</p>
|
|
331
|
+
</div>
|
|
332
|
+
<div className="sc-settings-control">
|
|
333
|
+
<select
|
|
334
|
+
id={ids.language}
|
|
335
|
+
className="sc-input"
|
|
336
|
+
value={language}
|
|
337
|
+
onChange={(event) => setLanguage(event.target.value)}
|
|
338
|
+
>
|
|
339
|
+
<option value="">{settings.languageNone}</option>
|
|
340
|
+
{CONSOLE_LANGUAGES.map((candidate) => (
|
|
341
|
+
<option key={candidate} value={candidate} lang={candidate}>
|
|
342
|
+
{languageLabel(candidate)}
|
|
343
|
+
</option>
|
|
344
|
+
))}
|
|
345
|
+
</select>
|
|
346
|
+
</div>
|
|
347
|
+
</div>
|
|
304
348
|
<div className="sc-form-actions">
|
|
305
349
|
<Button type="submit" variant="primary" disabled={props.busy === true || !changed}>
|
|
306
350
|
{settings.save}
|