@skillcdn/console 0.5.2 → 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.
- package/README.md +18 -14
- package/SKILLCDN.md +3 -2
- package/dist/cli/cli.d.ts.map +1 -1
- package/dist/cli/cli.js +29 -6
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/pack.d.ts +8 -0
- package/dist/cli/pack.d.ts.map +1 -1
- package/dist/cli/pack.js +12 -1
- package/dist/cli/pack.js.map +1 -1
- package/dist/compat.d.ts +1 -1
- package/dist/compat.js +2 -2
- package/dist/components/home.d.ts.map +1 -1
- package/dist/components/home.js +52 -28
- package/dist/components/home.js.map +1 -1
- package/dist/components/popover.d.ts +24 -0
- package/dist/components/popover.d.ts.map +1 -0
- package/dist/components/popover.js +127 -0
- package/dist/components/popover.js.map +1 -0
- package/dist/components/shell.d.ts.map +1 -1
- package/dist/components/shell.js +5 -106
- package/dist/components/shell.js.map +1 -1
- package/dist/console.css +83 -45
- package/dist/home-tiles.d.ts +19 -37
- package/dist/home-tiles.d.ts.map +1 -1
- package/dist/home-tiles.js +52 -328
- package/dist/home-tiles.js.map +1 -1
- package/dist/i18n/en.d.ts +4 -2
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +4 -2
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/ko.d.ts.map +1 -1
- package/dist/i18n/ko.js +1 -0
- package/dist/i18n/ko.js.map +1 -1
- package/dist/plugin/manifest.d.ts.map +1 -1
- package/dist/plugin/manifest.js +3 -2
- package/dist/plugin/manifest.js.map +1 -1
- package/dist/plugin-web.d.ts +1 -0
- package/dist/plugin-web.d.ts.map +1 -1
- package/dist/plugin-web.js +3 -1
- package/dist/plugin-web.js.map +1 -1
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +4 -0
- package/dist/plugin.js.map +1 -1
- package/dist/runner/desk.js +1 -1
- package/dist/schemas.d.ts +15 -0
- package/dist/schemas.d.ts.map +1 -1
- package/docs/specs/cli.md +3 -3
- package/docs/specs/plugins.md +21 -11
- package/docs/specs/rest.md +1 -1
- package/docs/specs/runner.md +1 -1
- package/docs/start.md +48 -0
- package/package.json +4 -4
- package/skills/building-a-plugin/SKILL.md +3 -3
- package/skills/running-an-agent/SKILL.md +2 -2
- package/skills/working-the-board/SKILL.md +1 -1
- package/skills/working-the-board/references/the-pack.md +1 -1
- package/src/cli/cli.ts +33 -7
- package/src/cli/pack.ts +20 -1
- package/src/compat.ts +2 -2
- package/src/components/home.tsx +121 -52
- package/src/components/popover.ts +145 -0
- package/src/components/shell.tsx +5 -112
- package/src/home-tiles.ts +57 -376
- package/src/i18n/en.ts +4 -2
- package/src/i18n/ko.ts +1 -0
- package/src/plugin/manifest.ts +3 -2
- package/src/plugin-web.ts +3 -1
- package/src/plugin.ts +4 -0
- package/src/runner/desk.ts +1 -1
- package/src/styles/README.md +1 -1
- package/src/styles/pages/home.css +32 -5
- package/src/styles/parts/button.css +8 -4
- package/src/styles/parts/detail.css +3 -13
- package/src/styles/parts/menu.css +33 -0
- package/src/styles/parts/page.css +6 -16
- package/src/styles/parts/tabs.css +1 -7
|
@@ -5,7 +5,7 @@ license: MIT
|
|
|
5
5
|
compatibility: Needs a shell with the console command on the PATH (npm install -g @skillcdn/console, Node.js 24 or newer), signed in by a person. Nothing else; the command needs no key of its own and the agent never sees a token.
|
|
6
6
|
metadata:
|
|
7
7
|
author: skillcdn
|
|
8
|
-
version: "1.
|
|
8
|
+
version: "1.41"
|
|
9
9
|
skillcdn:
|
|
10
10
|
translations:
|
|
11
11
|
ko:
|
|
@@ -7,7 +7,7 @@ Which pack a command reads follows the directory: where a project is named (`con
|
|
|
7
7
|
| To | Command | What comes back |
|
|
8
8
|
|---|---|---|
|
|
9
9
|
| Find a skill, or a page, by words | `console skills --search <words> --limit <n> [<folder>]` (or `--path <folder>`) | What the words find, as `search_repo` does: skills first, with the files of theirs that matched, then documents, each with the sections that matched and the offset and limit that read each; in the pack's language, and by meaning too where the deployment searches by it, which the result then says; ten unless `--limit` says otherwise, up to 25, and `--cursor` continues where more matched. A hit is some hundreds of characters and the skill a task needs is among the first: a `--limit` of three to five finds it. |
|
|
10
|
-
| Read a skill | `console skill <path>` | The skill, as `load_skill` gives it to a model: the rules of the repository from its root to the nearest manifest, the instructions, the files it includes, then its supporting files and what it refers to. A long skill comes in parts: a part that ends with `The skill continues. Read the next part before using it: console skill <path> --cursor <cursor>` and the
|
|
10
|
+
| Read a skill | `console skill <path>` | The skill, as `load_skill` gives it to a model: the rules of the repository from its root to the nearest manifest, the instructions, the files it includes, then its supporting files and what it refers to. A long skill comes in parts: a part that ends with `The skill continues. Read the next part before using it: console skill <path> --cursor <cursor>` and the lines after it is not the whole skill, so run that command, and the one the next part ends with, until a part ends with `The skill is complete: this was its last part.` Where the pack counts them, a part says how many pages of the skill follow it. The command is printed so that bash and PowerShell both run it as it is; for a path no one spelling keeps whole in both, the line says to run the command you ran again with `--cursor <cursor>`, quoted for your shell. `<path>` is the `SKILL.md`'s path as `console skills` lists it, or the skill's folder, or the URI the pack names it by (`skill://<host>/<owner>/<name>/<path>`). |
|
|
11
11
|
| Look into a folder | `console skills <folder>` (`.` for the root) | A page of what it holds, as `browse_repo` lays it out for a model: its skills, its folders with the README that introduces each, its files; 50 entries unless `--limit` says otherwise, and a page that ends before the folder does names its `nextCursor`, which `--cursor` continues. |
|
|
12
12
|
| Look around the pack | `console skills` | Where the pack is, at a deployment or on the console's machine, and how the read went; what a client is told of it on connect; every skill with the path of its `SKILL.md` and every document; where the console's own skills are on this machine. As long as the pack has skills and documents, tens of thousands of characters for a large one: for getting to know a pack, never for finding one skill. |
|
|
13
13
|
| Read a file of it | `console skill --file <path>` | A page of the file, as `read_repo_file` does, or what a folder holds: 24,000 characters, ended at a line, unless `--limit` says otherwise, and a page that ends before the file does says the offset the next begins at, which `--offset` reads. |
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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 {
|
package/src/components/home.tsx
CHANGED
|
@@ -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,
|
|
@@ -14,11 +15,7 @@ import { daysBetween, today } from "../dates.js";
|
|
|
14
15
|
import {
|
|
15
16
|
added,
|
|
16
17
|
arranged,
|
|
17
|
-
COMPOSED_HOME,
|
|
18
|
-
type ComposedTile,
|
|
19
18
|
columnsFor,
|
|
20
|
-
composed,
|
|
21
|
-
composedRows,
|
|
22
19
|
footprintOf,
|
|
23
20
|
GLANCE_REM,
|
|
24
21
|
GLANCE_ROOM_GUESS,
|
|
@@ -33,14 +30,14 @@ import {
|
|
|
33
30
|
homeWith,
|
|
34
31
|
isGlanceSize,
|
|
35
32
|
moved,
|
|
36
|
-
nobodyArranged,
|
|
37
33
|
type PlacedTile,
|
|
38
34
|
resized,
|
|
39
35
|
rowsOf,
|
|
40
36
|
sameArrangement,
|
|
41
37
|
sizesAt,
|
|
42
|
-
|
|
38
|
+
standsUnarranged,
|
|
43
39
|
tidied,
|
|
40
|
+
UNARRANGED_HOME,
|
|
44
41
|
waitToGiveWay,
|
|
45
42
|
} from "../home-tiles.js";
|
|
46
43
|
import { useWords } from "../i18n/index.js";
|
|
@@ -54,6 +51,8 @@ import type {
|
|
|
54
51
|
} from "../schemas.js";
|
|
55
52
|
import { useAction } from "../use-action.js";
|
|
56
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";
|
|
57
56
|
import { ProjectMark, ProjectRoleBadge } from "./projects.js";
|
|
58
57
|
import { Badge, Button, Callout, cx, Day, DueBadge, ProgressBar, Workers } from "./ui.js";
|
|
59
58
|
|
|
@@ -67,7 +66,6 @@ import { Badge, Button, Callout, cx, Day, DueBadge, ProgressBar, Workers } from
|
|
|
67
66
|
const SPARE_ROWS = 2;
|
|
68
67
|
|
|
69
68
|
const NONE: readonly string[] = [];
|
|
70
|
-
const NOT_PLACED: readonly PlacedTile[] = [];
|
|
71
69
|
|
|
72
70
|
/**
|
|
73
71
|
* What a project's tile at a glance reads of its board (ADR-0105): the one answer of
|
|
@@ -416,6 +414,22 @@ export function ProjectTile(props: ProjectTileProps) {
|
|
|
416
414
|
}
|
|
417
415
|
|
|
418
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
|
+
|
|
419
433
|
function SizeChoice(props: {
|
|
420
434
|
readonly tile: PlacedTile;
|
|
421
435
|
readonly sizes: readonly HomeTileSize[];
|
|
@@ -434,21 +448,81 @@ function SizeChoice(props: {
|
|
|
434
448
|
title={words.sizes[size]}
|
|
435
449
|
onClick={() => props.onChoose(size)}
|
|
436
450
|
>
|
|
437
|
-
<
|
|
438
|
-
className="sc-tile-size-glyph"
|
|
439
|
-
style={
|
|
440
|
-
{
|
|
441
|
-
"--sc-tile-w": HOME_TILE_CELLS[size].columns,
|
|
442
|
-
"--sc-tile-h": HOME_TILE_CELLS[size].rows,
|
|
443
|
-
} as CSSProperties
|
|
444
|
-
}
|
|
445
|
-
/>
|
|
451
|
+
<SizeGlyph size={size} />
|
|
446
452
|
</button>
|
|
447
453
|
))}
|
|
448
454
|
</fieldset>
|
|
449
455
|
);
|
|
450
456
|
}
|
|
451
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
|
+
|
|
452
526
|
interface Point {
|
|
453
527
|
readonly x: number;
|
|
454
528
|
readonly y: number;
|
|
@@ -533,13 +607,10 @@ export function HomeGrid(props: HomeGridProps) {
|
|
|
533
607
|
const [draft, setDraft] = useState<RestHome | null>(null);
|
|
534
608
|
const working = draft ?? home;
|
|
535
609
|
const hidden = working?.hidden ?? NONE;
|
|
536
|
-
//
|
|
537
|
-
//
|
|
538
|
-
//
|
|
539
|
-
const placed = useMemo(
|
|
540
|
-
() => (!editing && nobodyArranged(working) ? NOT_PLACED : arranged(tiles, working, columns)),
|
|
541
|
-
[editing, tiles, working, columns],
|
|
542
|
-
);
|
|
610
|
+
// The page stands on the same cells whether it is looked at or arranged (ADR-0147), so that
|
|
611
|
+
// arranging starts from what the person saw and Done keeps what they see: worked out once a
|
|
612
|
+
// render, not once a pointer's move.
|
|
613
|
+
const placed = useMemo(() => arranged(tiles, working, columns), [tiles, working, columns]);
|
|
543
614
|
const [drag, setDrag] = useState<Drag | null>(null);
|
|
544
615
|
const { busy, error, act } = useAction();
|
|
545
616
|
/** The tile in hand, once it has come loose; nothing while one is merely pressed. */
|
|
@@ -561,10 +632,11 @@ export function HomeGrid(props: HomeGridProps) {
|
|
|
561
632
|
const loose = useRef(false);
|
|
562
633
|
|
|
563
634
|
const press = (tile: PlacedTile, event: ReactPointerEvent<HTMLElement>) => {
|
|
564
|
-
// The tile's own buttons are pressed for themselves; everything
|
|
635
|
+
// The tile's own buttons, and the list of its sizes, are pressed for themselves; everything
|
|
636
|
+
// else takes hold of it.
|
|
565
637
|
if (
|
|
566
638
|
event.button !== 0 ||
|
|
567
|
-
(event.target instanceof Element && event.target.closest("button") !== null)
|
|
639
|
+
(event.target instanceof Element && event.target.closest("button, [popover]") !== null)
|
|
568
640
|
) {
|
|
569
641
|
return;
|
|
570
642
|
}
|
|
@@ -756,10 +828,10 @@ export function HomeGrid(props: HomeGridProps) {
|
|
|
756
828
|
setDraft(null);
|
|
757
829
|
props.onDone();
|
|
758
830
|
};
|
|
759
|
-
/** The page as
|
|
760
|
-
const reset = () => setDraft(
|
|
761
|
-
// The page closed up (ADR-
|
|
762
|
-
//
|
|
831
|
+
/** The page as nobody arranged it, every tile back on it: kept by Done like any change, let go by Cancel. */
|
|
832
|
+
const reset = () => setDraft(UNARRANGED_HOME);
|
|
833
|
+
// The page closed up (ADR-0147), worked out while it is arranged alone: the tiles moved up into
|
|
834
|
+
// the gaps at the sizes they have, the way to it offered only where it would move something.
|
|
763
835
|
const closed = useMemo(
|
|
764
836
|
() => (editing ? tidied(placed, columns) : placed),
|
|
765
837
|
[editing, placed, columns],
|
|
@@ -770,16 +842,7 @@ export function HomeGrid(props: HomeGridProps) {
|
|
|
770
842
|
tile.kind === "project" ? tile.project.name : nameOf(tile.widget.name);
|
|
771
843
|
// Moved in the page, a frame would load again: the tiles keep the order they came in for as
|
|
772
844
|
// long as the page is open, and each stands where its style says.
|
|
773
|
-
|
|
774
|
-
// it puts the same tiles on the grid's cells, closed up, where they move from (ADR-0139).
|
|
775
|
-
const composing = !editing && nobodyArranged(working);
|
|
776
|
-
const boxes: readonly ComposedTile[] = useMemo(
|
|
777
|
-
() =>
|
|
778
|
-
composing
|
|
779
|
-
? composed(tiles, working, columns)
|
|
780
|
-
: shown.map((tile) => ({ ...tile, ...footprintOf(tile.size, columns) })),
|
|
781
|
-
[composing, tiles, working, columns, shown],
|
|
782
|
-
);
|
|
845
|
+
const boxes = shown.map((tile) => ({ ...tile, ...footprintOf(tile.size, columns) }));
|
|
783
846
|
const order = useRef<readonly string[]>(NONE);
|
|
784
847
|
const inOrder = [...boxes].sort((a, b) => a.y - b.y || a.x - b.x).map((tile) => tile.tile.id);
|
|
785
848
|
order.current = [
|
|
@@ -793,9 +856,7 @@ export function HomeGrid(props: HomeGridProps) {
|
|
|
793
856
|
? tiles.filter((tile) => !shown.some((candidate) => candidate.tile.id === tile.id))
|
|
794
857
|
: [];
|
|
795
858
|
const slot = dragging === null ? undefined : shown.find((tile) => tile.tile.id === dragging.id);
|
|
796
|
-
const rows =
|
|
797
|
-
? composedRows(boxes)
|
|
798
|
-
: rowsOf(shown, columns) + (editing ? SPARE_ROWS : 0);
|
|
859
|
+
const rows = rowsOf(shown, columns) + (editing ? SPARE_ROWS : 0);
|
|
799
860
|
// The boards of the projects at a glance are read by whoever composes the page, once for each
|
|
800
861
|
// set of them: the ids in order say when it changed.
|
|
801
862
|
const glancing = glanceProjects(boxes);
|
|
@@ -821,7 +882,7 @@ export function HomeGrid(props: HomeGridProps) {
|
|
|
821
882
|
<Button
|
|
822
883
|
size="sm"
|
|
823
884
|
variant="ghost"
|
|
824
|
-
disabled={busy ||
|
|
885
|
+
disabled={busy || standsUnarranged(working)}
|
|
825
886
|
onClick={reset}
|
|
826
887
|
>
|
|
827
888
|
{words.reset}
|
|
@@ -864,8 +925,6 @@ export function HomeGrid(props: HomeGridProps) {
|
|
|
864
925
|
))}
|
|
865
926
|
</div>
|
|
866
927
|
)}
|
|
867
|
-
{/* What stands on the page, composed or arranged: the tiles drawn, not the arranged ones,
|
|
868
|
-
which are not worked out while the page stands composed. */}
|
|
869
928
|
{boxes.length === 0 && !editing && (props.empty ?? null)}
|
|
870
929
|
<ul
|
|
871
930
|
ref={grid}
|
|
@@ -936,13 +995,23 @@ export function HomeGrid(props: HomeGridProps) {
|
|
|
936
995
|
>
|
|
937
996
|
×
|
|
938
997
|
</button>
|
|
939
|
-
{sizesAt(tile.tile, columns).length > 1 &&
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
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
|
+
))}
|
|
946
1015
|
</>
|
|
947
1016
|
)}
|
|
948
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
|
+
}
|