@skillcdn/console 0.5.3 → 0.6.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.
Files changed (65) hide show
  1. package/README.md +18 -14
  2. package/SKILLCDN.md +3 -2
  3. package/dist/cli/cli.d.ts.map +1 -1
  4. package/dist/cli/cli.js +29 -6
  5. package/dist/cli/cli.js.map +1 -1
  6. package/dist/cli/pack.d.ts +8 -0
  7. package/dist/cli/pack.d.ts.map +1 -1
  8. package/dist/cli/pack.js +12 -1
  9. package/dist/cli/pack.js.map +1 -1
  10. package/dist/compat.d.ts +1 -1
  11. package/dist/compat.js +2 -2
  12. package/dist/components/home.d.ts.map +1 -1
  13. package/dist/components/home.js +40 -8
  14. package/dist/components/home.js.map +1 -1
  15. package/dist/components/popover.d.ts +24 -0
  16. package/dist/components/popover.d.ts.map +1 -0
  17. package/dist/components/popover.js +127 -0
  18. package/dist/components/popover.js.map +1 -0
  19. package/dist/components/shell.d.ts.map +1 -1
  20. package/dist/components/shell.js +5 -106
  21. package/dist/components/shell.js.map +1 -1
  22. package/dist/console.css +83 -45
  23. package/dist/i18n/en.d.ts +2 -0
  24. package/dist/i18n/en.d.ts.map +1 -1
  25. package/dist/i18n/en.js +2 -0
  26. package/dist/i18n/en.js.map +1 -1
  27. package/dist/i18n/ko.d.ts.map +1 -1
  28. package/dist/i18n/ko.js +1 -0
  29. package/dist/i18n/ko.js.map +1 -1
  30. package/dist/plugin-web.d.ts +1 -0
  31. package/dist/plugin-web.d.ts.map +1 -1
  32. package/dist/plugin-web.js +3 -1
  33. package/dist/plugin-web.js.map +1 -1
  34. package/dist/plugin.d.ts +1 -0
  35. package/dist/plugin.d.ts.map +1 -1
  36. package/dist/plugin.js +4 -0
  37. package/dist/plugin.js.map +1 -1
  38. package/dist/schemas.d.ts +15 -0
  39. package/dist/schemas.d.ts.map +1 -1
  40. package/docs/specs/cli.md +3 -3
  41. package/docs/specs/plugins.md +18 -8
  42. package/docs/specs/rest.md +1 -1
  43. package/docs/specs/runner.md +1 -1
  44. package/docs/start.md +48 -0
  45. package/package.json +4 -4
  46. package/skills/building-a-plugin/SKILL.md +2 -2
  47. package/skills/working-the-board/SKILL.md +1 -1
  48. package/skills/working-the-board/references/the-pack.md +1 -1
  49. package/src/cli/cli.ts +33 -7
  50. package/src/cli/pack.ts +20 -1
  51. package/src/compat.ts +2 -2
  52. package/src/components/home.tsx +108 -18
  53. package/src/components/popover.ts +145 -0
  54. package/src/components/shell.tsx +5 -112
  55. package/src/i18n/en.ts +2 -0
  56. package/src/i18n/ko.ts +1 -0
  57. package/src/plugin-web.ts +3 -1
  58. package/src/plugin.ts +4 -0
  59. package/src/styles/README.md +1 -1
  60. package/src/styles/pages/home.css +32 -5
  61. package/src/styles/parts/button.css +8 -4
  62. package/src/styles/parts/detail.css +3 -13
  63. package/src/styles/parts/menu.css +33 -0
  64. package/src/styles/parts/page.css +6 -16
  65. package/src/styles/parts/tabs.css +1 -7
package/src/cli/cli.ts CHANGED
@@ -2267,7 +2267,10 @@ async function readSkill(
2267
2267
  }
2268
2268
  // The skill, its rules first, as load_skill lays them out: whole, or the part that begins at
2269
2269
  // the cursor, ending with the command that reads the next, asked as this one was.
2270
- let continues = false;
2270
+ // The library asks for that line of every run of pages it tries, the runs it goes on from
2271
+ // among them, so a line was asked for of a skill that is then printed to its end: the part
2272
+ // goes on only where what is printed ends with the line.
2273
+ const offered: { readonly cursor: string; readonly line: string }[] = [];
2271
2274
  const loaded = await readThrough(
2272
2275
  io,
2273
2276
  session,
@@ -2279,19 +2282,28 @@ async function readSkill(
2279
2282
  // Spelled so that bash and PowerShell run it as it is; where a word has no such spelling,
2280
2283
  // the command that was run is run again, with the cursor, and the line says why.
2281
2284
  nextPart: (next) => {
2282
- continues = true;
2283
- return (
2285
+ const line =
2284
2286
  commandLine(command, [given, "--cursor", next, ...again]) ??
2285
- `the command you ran, with --cursor ${commandWord(next) ?? JSON.stringify(next)} in place of any it had, each word quoted for your shell. ${NO_LINE_TO_RUN}`
2286
- );
2287
+ `the command you ran, with --cursor ${commandWord(next) ?? JSON.stringify(next)} in place of any it had, each word quoted for your shell. ${NO_LINE_TO_RUN}`;
2288
+ offered.push({ cursor: next, line });
2289
+ return line;
2287
2290
  },
2288
2291
  },
2289
2292
  );
2293
+ const goesOn = offered.findLast((one) => loaded.text.endsWith(one.line));
2290
2294
  // A part that is not the last ends with the console's own words after the library's line: a
2291
2295
  // fresh agent read one part of four, saw that the skill continued, and planned from that part,
2292
- // since "before using it" did not read as now to a session that meant only to plan.
2296
+ // since "before using it" did not read as now to a session that meant only to plan. The last
2297
+ // part of a skill read in parts says that it is the last, so that the end is said and not
2298
+ // only missed.
2299
+ const closing =
2300
+ goesOn !== undefined
2301
+ ? partEndsHere(pack.pagesAfter(goesOn.cursor))
2302
+ : cursor !== undefined && pack.skillEnded()
2303
+ ? SKILL_ENDS_HERE
2304
+ : undefined;
2293
2305
  say(jsonOfRead(session, pack, loaded), () =>
2294
- continues ? `${loaded.text}\n${PART_ENDS_HERE}` : loaded.text,
2306
+ closing === undefined ? loaded.text : `${loaded.text}\n${closing}`,
2295
2307
  );
2296
2308
  return EXIT.ok;
2297
2309
  }
@@ -2303,6 +2315,20 @@ async function readSkill(
2303
2315
  const PART_ENDS_HERE =
2304
2316
  "This part stops in the middle of the skill: its later steps, its checkpoints and its rules are in the parts that follow, and nothing above is complete without them. Run that command now, before a plan, an answer or any other step, and each next one, until a part ends without these lines.";
2305
2317
 
2318
+ /**
2319
+ * The same with how far the skill goes on before it, where the pack counts the pages left
2320
+ * (SkillCDN 0.6.1): a reader told how many pages follow reads a skill to its end far more often
2321
+ * than one told only that it continues. A part is a run of pages, so the count is the pack's
2322
+ * own, of pages, and falls from part to part.
2323
+ */
2324
+ const partEndsHere = (left: number | undefined): string =>
2325
+ left === undefined || left < 1
2326
+ ? PART_ENDS_HERE
2327
+ : `${left} more ${left === 1 ? "page" : "pages"} of the skill ${left === 1 ? "follows" : "follow"} this part. ${PART_ENDS_HERE}`;
2328
+
2329
+ /** What the last part of a skill read in parts ends with. */
2330
+ const SKILL_ENDS_HERE = "The skill is complete: this was its last part.";
2331
+
2306
2332
  const skill: Command = async (args, io) => {
2307
2333
  const { values, positionals } = parse(args, SKILL_OPTIONS);
2308
2334
  const session = await open(io, values);
package/src/cli/pack.ts CHANGED
@@ -249,6 +249,14 @@ const MAX_PAGES = 64;
249
249
  export interface ConsolePack extends Pack {
250
250
  /** The console's answer to the last read made of the pack: what `--json` prints around the pack's own answer, and what a refusal is said from. */
251
251
  answered(): PackAnswer | undefined;
252
+ /**
253
+ * How many pages of a skill follow the page that named `cursor` as the next, where the pack
254
+ * said (`pagesLeft`, SkillCDN 0.6.1): what the command says of a part that ends there.
255
+ * Nothing for a cursor no page of this pack named, or a pack that counts none.
256
+ */
257
+ pagesAfter(cursor: string): number | undefined;
258
+ /** Whether the last page of a skill this pack answered was the skill's last. */
259
+ skillEnded(): boolean;
252
260
  }
253
261
 
254
262
  /**
@@ -272,6 +280,9 @@ export function consolePack(
272
280
  }
273
281
  let last: PackAnswer | undefined;
274
282
  let pages = 0;
283
+ /** By the cursor a page of a skill named as the next: how many pages the pack said follow that page. */
284
+ const left = new Map<string, number>();
285
+ let ended = false;
275
286
  /** One more page of a read the command joins, within what one command follows. */
276
287
  const another = (what: string, path: string | undefined): void => {
277
288
  pages += 1;
@@ -342,8 +353,16 @@ export function consolePack(
342
353
  "The pack answers more pages of a skill than one read takes.",
343
354
  );
344
355
  }
345
- return ready("skill", await reader.skill(path, cursor));
356
+ const read = ready("skill", await reader.skill(path, cursor));
357
+ const { nextCursor, pagesLeft, complete } = read.skill;
358
+ if (typeof nextCursor === "string" && pagesLeft !== undefined) {
359
+ left.set(nextCursor, pagesLeft);
360
+ }
361
+ ended = complete === true;
362
+ return read;
346
363
  },
364
+ pagesAfter: (cursor: string) => left.get(cursor),
365
+ skillEnded: () => ended,
347
366
  file: async (query: FileQuery): Promise<RestFile> =>
348
367
  taken(
349
368
  "file",
package/src/compat.ts CHANGED
@@ -113,7 +113,7 @@ export interface ClientPolicy {
113
113
  * last changed what the command reads or sends (ADR-0038), whose changelog entry begins with
114
114
  * `Breaking:`; `pnpm check` holds it to a version the package has, or is about to have.
115
115
  */
116
- export const CLIENT_POLICY: ClientPolicy = { atLeast: "0.5.0" };
116
+ export const CLIENT_POLICY: ClientPolicy = { atLeast: "0.6.0" };
117
117
 
118
118
  /**
119
119
  * The oldest console this command works with (ADR-0038): raised by the release that last
@@ -122,7 +122,7 @@ export const CLIENT_POLICY: ClientPolicy = { atLeast: "0.5.0" };
122
122
  * itself, naming the command to install instead; `pnpm check` holds it as it holds the
123
123
  * console's floor.
124
124
  */
125
- export const CONSOLE_AT_LEAST = "0.5.0";
125
+ export const CONSOLE_AT_LEAST = "0.6.0";
126
126
 
127
127
  /** `common` from `atLeast` on, where that floor is within it; `common` as it is otherwise. */
128
128
  function narrowed(common: VersionRange, atLeast: string | undefined): VersionRange {
@@ -5,6 +5,7 @@ import {
5
5
  type PointerEvent as ReactPointerEvent,
6
6
  type RefObject,
7
7
  useEffect,
8
+ useId,
8
9
  useLayoutEffect,
9
10
  useMemo,
10
11
  useRef,
@@ -50,6 +51,8 @@ import type {
50
51
  } from "../schemas.js";
51
52
  import { useAction } from "../use-action.js";
52
53
  import { DRAG_SLACK, edgeScrollOf, HOLD_MS, HOLD_SLACK } from "./board.js";
54
+ import { Icon } from "./icon.js";
55
+ import { POPOVERS, useListPopover } from "./popover.js";
53
56
  import { ProjectMark, ProjectRoleBadge } from "./projects.js";
54
57
  import { Badge, Button, Callout, cx, Day, DueBadge, ProgressBar, Workers } from "./ui.js";
55
58
 
@@ -411,6 +414,22 @@ export function ProjectTile(props: ProjectTileProps) {
411
414
  }
412
415
 
413
416
  /** The sizes a tile comes in, each a little picture of its shape, the one it has lit. */
417
+ /** A size's shape in small: the cells it takes. */
418
+ function SizeGlyph(props: { readonly size: HomeTileSize }) {
419
+ return (
420
+ <span
421
+ className="sc-tile-size-glyph"
422
+ aria-hidden="true"
423
+ style={
424
+ {
425
+ "--sc-tile-w": HOME_TILE_CELLS[props.size].columns,
426
+ "--sc-tile-h": HOME_TILE_CELLS[props.size].rows,
427
+ } as CSSProperties
428
+ }
429
+ />
430
+ );
431
+ }
432
+
414
433
  function SizeChoice(props: {
415
434
  readonly tile: PlacedTile;
416
435
  readonly sizes: readonly HomeTileSize[];
@@ -429,21 +448,81 @@ function SizeChoice(props: {
429
448
  title={words.sizes[size]}
430
449
  onClick={() => props.onChoose(size)}
431
450
  >
432
- <span
433
- className="sc-tile-size-glyph"
434
- style={
435
- {
436
- "--sc-tile-w": HOME_TILE_CELLS[size].columns,
437
- "--sc-tile-h": HOME_TILE_CELLS[size].rows,
438
- } as CSSProperties
439
- }
440
- />
451
+ <SizeGlyph size={size} />
441
452
  </button>
442
453
  ))}
443
454
  </fieldset>
444
455
  );
445
456
  }
446
457
 
458
+ /**
459
+ * The sizes of a tile one cell wide, behind one button: a row of them, folded into its cell,
460
+ * covers what the tile shows. The button is the pack's "more", read at once as a list to open,
461
+ * where one size alone, lit, read as a choice already made; its label says the size the tile
462
+ * has. The list stands over the tiles, each size by its shape and its name.
463
+ */
464
+ function SizeMenu(props: {
465
+ readonly tile: PlacedTile;
466
+ readonly sizes: readonly HomeTileSize[];
467
+ readonly onChoose: (size: HomeTileSize) => void;
468
+ }) {
469
+ const words = useWords().home;
470
+ const id = useId();
471
+ const button = useRef<HTMLButtonElement>(null);
472
+ const panel = useRef<HTMLDivElement>(null);
473
+ const list = useListPopover(button, panel);
474
+ const now = props.tile.size;
475
+ return (
476
+ <div className="sc-home-size-one">
477
+ <button
478
+ type="button"
479
+ ref={button}
480
+ className="sc-tile-size"
481
+ aria-label={words.sizeIs(words.sizes[now])}
482
+ title={words.sizeIs(words.sizes[now])}
483
+ aria-expanded={list.open}
484
+ aria-controls={id}
485
+ popoverTarget={id}
486
+ onClick={(event) => {
487
+ event.preventDefault();
488
+ list.toggle();
489
+ }}
490
+ >
491
+ <Icon name="more" size="md" />
492
+ </button>
493
+ <div
494
+ id={id}
495
+ ref={panel}
496
+ popover="auto"
497
+ hidden={!POPOVERS && !list.open}
498
+ className="sc-menu-panel sc-menu-popover sc-home-size-menu"
499
+ >
500
+ <div className="sc-menu-list">
501
+ {props.sizes.map((size) => (
502
+ <button
503
+ key={size}
504
+ type="button"
505
+ className={cx(
506
+ "sc-menu-link",
507
+ "sc-home-size-option",
508
+ size === now && "sc-menu-chosen",
509
+ )}
510
+ aria-pressed={size === now}
511
+ onClick={() => {
512
+ list.hide();
513
+ props.onChoose(size);
514
+ }}
515
+ >
516
+ <SizeGlyph size={size} />
517
+ {words.sizes[size]}
518
+ </button>
519
+ ))}
520
+ </div>
521
+ </div>
522
+ </div>
523
+ );
524
+ }
525
+
447
526
  interface Point {
448
527
  readonly x: number;
449
528
  readonly y: number;
@@ -553,10 +632,11 @@ export function HomeGrid(props: HomeGridProps) {
553
632
  const loose = useRef(false);
554
633
 
555
634
  const press = (tile: PlacedTile, event: ReactPointerEvent<HTMLElement>) => {
556
- // The tile's own buttons are pressed for themselves; everything else takes hold of it.
635
+ // The tile's own buttons, and the list of its sizes, are pressed for themselves; everything
636
+ // else takes hold of it.
557
637
  if (
558
638
  event.button !== 0 ||
559
- (event.target instanceof Element && event.target.closest("button") !== null)
639
+ (event.target instanceof Element && event.target.closest("button, [popover]") !== null)
560
640
  ) {
561
641
  return;
562
642
  }
@@ -915,13 +995,23 @@ export function HomeGrid(props: HomeGridProps) {
915
995
  >
916
996
  ×
917
997
  </button>
918
- {sizesAt(tile.tile, columns).length > 1 && (
919
- <SizeChoice
920
- tile={tile}
921
- sizes={sizesAt(tile.tile, columns)}
922
- onChoose={(size) => change(resized(placed, tile.tile.id, size, columns))}
923
- />
924
- )}
998
+ {sizesAt(tile.tile, columns).length > 1 &&
999
+ // One cell is narrower than the row of sizes, at every width of the grid:
1000
+ // they fold behind one button, where the browser can open its list over the
1001
+ // tiles.
1002
+ (w === 1 && POPOVERS ? (
1003
+ <SizeMenu
1004
+ tile={tile}
1005
+ sizes={sizesAt(tile.tile, columns)}
1006
+ onChoose={(size) => change(resized(placed, tile.tile.id, size, columns))}
1007
+ />
1008
+ ) : (
1009
+ <SizeChoice
1010
+ tile={tile}
1011
+ sizes={sizesAt(tile.tile, columns)}
1012
+ onChoose={(size) => change(resized(placed, tile.tile.id, size, columns))}
1013
+ />
1014
+ ))}
925
1015
  </>
926
1016
  )}
927
1017
  </li>
@@ -0,0 +1,145 @@
1
+ import { type RefObject, useEffect, useState } from "react";
2
+
3
+ // A list a button opens over the page, as a popover in the top layer: out of whatever around the
4
+ // button clips or stacks over what hangs out of it, a row of tabs that scrolls sideways or a tile
5
+ // of the front page, and dismissed by a click elsewhere or the escape key, as the browser does it.
6
+
7
+ /** How close to the window's edge a list may come. */
8
+ const PANEL_GUTTER_PX = 8;
9
+ /** How far below its button, or above it, off the line the button stands on, a list opens. */
10
+ const PANEL_DROP_PX = 6;
11
+ /** How far a list's edge stands before the names in it: its own padding and a link's. */
12
+ const PANEL_INSET_PX = 14;
13
+ /** The least a list is let be tall where the window is short: a few of its items, scrolled. */
14
+ const PANEL_SHORTEST_PX = 120;
15
+
16
+ /**
17
+ * Whether the browser shows a popover. One that does not, as Safari before 17, has the list
18
+ * shown and hidden by its button, without the browser's ways of closing it.
19
+ */
20
+ export const POPOVERS =
21
+ typeof HTMLElement === "undefined" || typeof HTMLElement.prototype.showPopover === "function";
22
+
23
+ /**
24
+ * Puts a list by the button that opened it, the names in it lined up with the button's, within
25
+ * the page's width, the scrollbar left out: the list is in the top layer, where nothing of the
26
+ * page places it. It opens under the button, or over it where the window has no room below for
27
+ * the whole of it and more above, as for a tile near the foot of the window; no taller than the
28
+ * window has room for on its side, a longer list scrolling within itself.
29
+ */
30
+ function place(button: HTMLElement | null, box: HTMLElement | null): void {
31
+ if (button === null || box === null) {
32
+ return;
33
+ }
34
+ const at = button.getBoundingClientRect();
35
+ const { clientWidth, clientHeight } = document.documentElement;
36
+ const room = clientWidth - box.offsetWidth - PANEL_GUTTER_PX;
37
+ const below = clientHeight - at.bottom - PANEL_DROP_PX - PANEL_GUTTER_PX;
38
+ const above = at.top - PANEL_DROP_PX - PANEL_GUTTER_PX;
39
+ // Its whole height, however short it was held the last time it opened: its items, its padding
40
+ // and its border.
41
+ const whole = box.scrollHeight + box.offsetHeight - box.clientHeight;
42
+ const over = whole > below && above > below;
43
+ const tallest = Math.max(PANEL_SHORTEST_PX, over ? above : below);
44
+ const top = over ? at.top - PANEL_DROP_PX - Math.min(whole, tallest) : at.bottom + PANEL_DROP_PX;
45
+ box.style.left = `${Math.max(PANEL_GUTTER_PX, Math.min(at.left - PANEL_INSET_PX, room))}px`;
46
+ box.style.top = `${Math.max(PANEL_GUTTER_PX, top)}px`;
47
+ box.style.maxHeight = `${tallest}px`;
48
+ }
49
+
50
+ /** Closes a list: the browser's popover, or the list its button shows by hand where there is none. */
51
+ function hideList(box: HTMLElement | null, setOpen: (open: boolean) => void): void {
52
+ if (!POPOVERS) {
53
+ setOpen(false);
54
+ return;
55
+ }
56
+ if (box?.matches(":popover-open") === true) {
57
+ box.hidePopover();
58
+ }
59
+ }
60
+
61
+ /** A list a button opens: whether it is open, and the ways to open and close it. */
62
+ export interface ListPopover {
63
+ readonly open: boolean;
64
+ readonly show: () => void;
65
+ readonly hide: () => void;
66
+ /** Opens it where it is closed, and closes it where it is open. */
67
+ readonly toggle: () => void;
68
+ }
69
+
70
+ /**
71
+ * The list `panel` (with `popover="auto"`, and `hidden` where there are no popovers) that the
72
+ * button `anchor` opens (with `popoverTarget` naming it, so that a click on the button is not a
73
+ * click outside that closes the list first). Placed under the button when it opens; closed when
74
+ * the page scrolls under it or the window changes, which would leave it where the button no
75
+ * longer is, and when the window loses the focus, as it does to a click in a plugin's frame,
76
+ * which the page never sees.
77
+ */
78
+ export function useListPopover(
79
+ anchor: RefObject<HTMLElement | null>,
80
+ panel: RefObject<HTMLElement | null>,
81
+ ): ListPopover {
82
+ const [open, setOpen] = useState(false);
83
+ // Shown here rather than by the browser, and placed at once, before anything is painted: the
84
+ // list has its width only once it shows, and a list placed before that, then again once the
85
+ // browser said it opened, could stand out of the window in between.
86
+ const show = () => {
87
+ const box = panel.current;
88
+ if (box === null) {
89
+ return;
90
+ }
91
+ if (!POPOVERS) {
92
+ setOpen(true);
93
+ return;
94
+ }
95
+ if (!box.matches(":popover-open")) {
96
+ box.showPopover();
97
+ place(anchor.current, box);
98
+ }
99
+ };
100
+ const hide = () => hideList(panel.current, setOpen);
101
+ const toggle = () => {
102
+ const shown = POPOVERS ? panel.current?.matches(":popover-open") === true : open;
103
+ if (shown) {
104
+ hide();
105
+ } else {
106
+ show();
107
+ }
108
+ };
109
+ useEffect(() => {
110
+ const box = panel.current;
111
+ if (box === null) {
112
+ return;
113
+ }
114
+ const onToggle = (event: Event) => {
115
+ setOpen((event as ToggleEvent).newState === "open");
116
+ };
117
+ // Heard from the start rather than once the page knows it opened, which comes a moment after
118
+ // it shows. A scroll within the list is the list's own.
119
+ const close = (event: Event) => {
120
+ const shown = POPOVERS ? box.matches(":popover-open") : !box.hidden;
121
+ const within =
122
+ event.type === "scroll" && event.target instanceof Node && box.contains(event.target);
123
+ if (shown && !within) {
124
+ hideList(box, setOpen);
125
+ }
126
+ };
127
+ box.addEventListener("toggle", onToggle);
128
+ window.addEventListener("resize", close);
129
+ window.addEventListener("scroll", close, true);
130
+ window.addEventListener("blur", close);
131
+ return () => {
132
+ box.removeEventListener("toggle", onToggle);
133
+ window.removeEventListener("resize", close);
134
+ window.removeEventListener("scroll", close, true);
135
+ window.removeEventListener("blur", close);
136
+ };
137
+ }, [panel]);
138
+ useEffect(() => {
139
+ // Shown by the button itself where the browser has no popover: placed now that it shows.
140
+ if (open && !POPOVERS) {
141
+ place(anchor.current, panel.current);
142
+ }
143
+ }, [open, anchor, panel]);
144
+ return { open, show, hide, toggle };
145
+ }
@@ -1,7 +1,8 @@
1
- import { Fragment, type ReactNode, useEffect, useId, useRef, useState } from "react";
1
+ import { Fragment, type ReactNode, useEffect, useId, useRef } from "react";
2
2
  import type { RestPerson } from "../api.js";
3
3
  import { useWords } from "../i18n/index.js";
4
4
  import { Icon } from "./icon.js";
5
+ import { POPOVERS, useListPopover } from "./popover.js";
5
6
  import { Avatar, cx, personName } from "./ui.js";
6
7
 
7
8
  // The frame every page sits in (ADR-0010): a header that names the workspace and the project the
@@ -119,53 +120,6 @@ function tabLabel(label: string): { readonly title: string | undefined } {
119
120
  return { title: widthOf(label) > TAB_LABEL_WHOLE ? label : undefined };
120
121
  }
121
122
 
122
- /** How close to the window's edge a list opened from a tab may come. */
123
- const PANEL_GUTTER_PX = 8;
124
- /** How far below its tab, off the header's line, a list opens. */
125
- const PANEL_DROP_PX = 6;
126
- /** How far a list's edge stands before the names in it: its own padding and a link's. */
127
- const PANEL_INSET_PX = 14;
128
-
129
- /** The least a list is let be tall where the window is short: a few of its pages, scrolled. */
130
- const PANEL_SHORTEST_PX = 120;
131
-
132
- /**
133
- * Whether the browser shows a popover. One that does not, as Safari before 17, has the list
134
- * shown and hidden by the tab itself, without the browser's ways of closing it.
135
- */
136
- const POPOVERS =
137
- typeof HTMLElement === "undefined" || typeof HTMLElement.prototype.showPopover === "function";
138
-
139
- /**
140
- * Puts the list a tab opened under the tab, the names in it lined up with the tab's, within the
141
- * page's width, the scrollbar left out, and no taller than the window has room for below it, a
142
- * longer list scrolling within itself: the list is in the top layer, where nothing of the page
143
- * places it.
144
- */
145
- function placeUnder(tab: HTMLElement | null, box: HTMLElement | null): void {
146
- if (tab === null || box === null) {
147
- return;
148
- }
149
- const at = tab.getBoundingClientRect();
150
- const { clientWidth, clientHeight } = document.documentElement;
151
- const room = clientWidth - box.offsetWidth - PANEL_GUTTER_PX;
152
- const top = at.bottom + PANEL_DROP_PX;
153
- box.style.left = `${Math.max(PANEL_GUTTER_PX, Math.min(at.left - PANEL_INSET_PX, room))}px`;
154
- box.style.top = `${top}px`;
155
- box.style.maxHeight = `${Math.max(PANEL_SHORTEST_PX, clientHeight - top - PANEL_GUTTER_PX)}px`;
156
- }
157
-
158
- /** Closes a list: the browser's popover, or the list the tab shows by hand where there is none. */
159
- function hideList(box: HTMLElement | null, setOpen: (open: boolean) => void): void {
160
- if (!POPOVERS) {
161
- setOpen(false);
162
- return;
163
- }
164
- if (box?.matches(":popover-open") === true) {
165
- box.hidePopover();
166
- }
167
- }
168
-
169
123
  /** How long a mouse rests on a tab before its list opens: one passing along the row opens nothing. */
170
124
  const HOVER_OPEN_MS = 80;
171
125
  /** 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. */
@@ -194,70 +148,14 @@ function TabGroup(props: { readonly item: NavItem; readonly onNavigate: (href: s
194
148
  const id = useId();
195
149
  const tab = useRef<HTMLButtonElement>(null);
196
150
  const panel = useRef<HTMLDivElement>(null);
197
- const [open, setOpen] = useState(false);
151
+ const { open, show, hide, toggle } = useListPopover(tab, panel);
198
152
  const resting = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
199
153
  const { item } = props;
200
154
  const after = (ms: number, what: () => void) => {
201
155
  clearTimeout(resting.current);
202
156
  resting.current = setTimeout(what, ms);
203
157
  };
204
- // Shown here rather than by the browser, and placed at once, before anything is painted: the
205
- // list has its width only once it shows, and a list placed before that, then again once the
206
- // browser said it opened, could stand out of the window in between. The button stays its
207
- // invoker, so that a click on it is not a click outside that closes it first.
208
- const show = () => {
209
- const box = panel.current;
210
- if (box === null) {
211
- return;
212
- }
213
- if (!POPOVERS) {
214
- setOpen(true);
215
- return;
216
- }
217
- if (!box.matches(":popover-open")) {
218
- box.showPopover();
219
- placeUnder(tab.current, box);
220
- }
221
- };
222
- const hide = () => hideList(panel.current, setOpen);
223
- useEffect(() => {
224
- const box = panel.current;
225
- if (box === null) {
226
- return;
227
- }
228
- const onToggle = (event: Event) => {
229
- setOpen((event as ToggleEvent).newState === "open");
230
- };
231
- // Open, it is where its tab is; the row of tabs scrolling, or the window changing, would
232
- // leave it where the tab no longer is, so either closes it, and so does the window losing
233
- // the focus. A scroll within the list is the list's own. Heard from the start rather than
234
- // once the page knows it opened, which comes a moment after it shows.
235
- const close = (event: Event) => {
236
- const shown = POPOVERS ? box.matches(":popover-open") : !box.hidden;
237
- const within =
238
- event.type === "scroll" && event.target instanceof Node && box.contains(event.target);
239
- if (shown && !within) {
240
- hideList(box, setOpen);
241
- }
242
- };
243
- box.addEventListener("toggle", onToggle);
244
- window.addEventListener("resize", close);
245
- window.addEventListener("scroll", close, true);
246
- window.addEventListener("blur", close);
247
- return () => {
248
- clearTimeout(resting.current);
249
- box.removeEventListener("toggle", onToggle);
250
- window.removeEventListener("resize", close);
251
- window.removeEventListener("scroll", close, true);
252
- window.removeEventListener("blur", close);
253
- };
254
- }, []);
255
- useEffect(() => {
256
- // Shown by the tab itself where the browser has no popover: placed now that it shows.
257
- if (open && !POPOVERS) {
258
- placeUnder(tab.current, panel.current);
259
- }
260
- }, [open]);
158
+ useEffect(() => () => clearTimeout(resting.current), []);
261
159
  return (
262
160
  <div
263
161
  className="sc-tab-group"
@@ -291,12 +189,7 @@ function TabGroup(props: { readonly item: NavItem; readonly onNavigate: (href: s
291
189
  props.onNavigate(item.href);
292
190
  return;
293
191
  }
294
- const shown = POPOVERS ? panel.current?.matches(":popover-open") === true : open;
295
- if (shown) {
296
- hide();
297
- } else {
298
- show();
299
- }
192
+ toggle();
300
193
  }}
301
194
  >
302
195
  <span className="sc-tab-label">{item.label}</span>
package/src/i18n/en.ts CHANGED
@@ -1689,6 +1689,8 @@ export const en = {
1689
1689
  add: "Add",
1690
1690
  remove: "Remove from this page",
1691
1691
  size: "Size",
1692
+ /** The one button of a tile a cell wide, which opens the list of its sizes: the size it has. */
1693
+ sizeIs: (size: string) => `Size: ${size}`,
1692
1694
  sizes: {
1693
1695
  icon: "Icon",
1694
1696
  small: "Small",
package/src/i18n/ko.ts CHANGED
@@ -1598,6 +1598,7 @@ export const ko: Messages = {
1598
1598
  add: "추가",
1599
1599
  remove: "화면에서 제거",
1600
1600
  size: "크기",
1601
+ sizeIs: (size) => `크기: ${size}`,
1601
1602
  sizes: {
1602
1603
  icon: "아이콘",
1603
1604
  small: "소형",
package/src/plugin-web.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  // The frame's side of the bridge (docs/specs/plugins.md, "The bridge"), for a plugin's web bundle:
2
- // `connect()` and the messages. Depends on nothing; runs in a browser.
2
+ // `connect()` and the messages, and the Korean particles of two forms as the console's own pages
3
+ // write them (ADR-0137), for a page's words. Depends on nothing; runs in a browser.
3
4
 
5
+ export { asObject, asSubject, asWay } from "./i18n/particles.js";
4
6
  export {
5
7
  BRIDGE_EVENT_KINDS,
6
8
  BRIDGE_METHODS,
package/src/plugin.ts CHANGED
@@ -5,6 +5,10 @@
5
5
  // console, which reads the description the module yields.
6
6
 
7
7
  export * as z from "zod";
8
+ // The Korean particles that take one of two forms, as the console's own Korean writes them
9
+ // (ADR-0137): a sentence a plugin writes for people, a decision's question or a task's title,
10
+ // reads as the console's sentences beside it do.
11
+ export { asObject, asSubject, asWay } from "./i18n/particles.js";
8
12
  export {
9
13
  ARG_TYPES,
10
14
  type ArgDefinition,
@@ -53,7 +53,7 @@ A part is a file under `parts/` and a row here, with the classes that are its ow
53
53
  | `files` | `sc-file*`, `sc-chosen*` | | Files to choose, and the ones chosen with the way to take each out. |
54
54
  | `toggle` | `sc-toggle*` | | One choice among a few, each a chip, the chosen one filled. |
55
55
  | `picker` | `sc-picker*`, `sc-person-option*` | `Picker` | One thing chosen out of a listing that is searched: a person, a project, a goal, a task. `sc-picker-quiet` where it is a fact changed in place, `sc-picker-add` at the end of a row of chips. |
56
- | `menu` | `sc-menu*` | | What opens from a button over the page: the person's menu, a card's. |
56
+ | `menu` | `sc-menu*` | | What opens from a button over the page: the person's menu, a card's. `sc-menu-popover` is a panel opened in the top layer, over whatever around its button would clip or cover it, as a front page tile's sizes are. |
57
57
  | `tabs` | `sc-tab*`, `sc-tabs*`, `sc-subtabs*` | | The pages of a project (`sc-tabs`), and the views of one page (`sc-subtabs` of `sc-tab`s), the current one marked. |
58
58
  | `pager` | `sc-pager*`, `sc-show*` | `Pager`, `ShowMore` | A long list a page at a time: turned by pages, or grown by "show more". |
59
59
  | `badge` | `sc-badge*`, `sc-kind*` | `Badge`, `DueBadge`, `GoalStateBadge`, `RoleBadge`, `RunStatusBadge` | A state or a kind in a word. The tone is the meaning: neutral, accent, success, warning, point, danger. Nothing stands before its words but the dot of one that is `live`. |