@blueshed/joined 0.1.20 → 0.2.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 (71) hide show
  1. package/.claude/skills/joined/SKILL.md +1 -1
  2. package/.claude/skills/joined/reference.md +96 -17
  3. package/docs/design.md +31 -8
  4. package/examples/cafe/kitchen.ts +2 -2
  5. package/examples/desk/card.ts +43 -0
  6. package/examples/desk/desk.css +17 -0
  7. package/examples/desk/desk.json +41 -0
  8. package/examples/desk/generated/elements.ts +69 -0
  9. package/examples/desk/generated/queries.ts +33 -0
  10. package/examples/desk/generated/rules.ts +94 -0
  11. package/examples/desk/index.html +34 -0
  12. package/examples/desk/lanes.css +126 -0
  13. package/examples/desk/lanes.ts +133 -0
  14. package/examples/desk/migrations/001-desk.ts +8 -0
  15. package/examples/desk/page.ts +29 -0
  16. package/examples/desk/pulse.ts +20 -0
  17. package/examples/desk/routes.ts +9 -0
  18. package/examples/desk/steps.ts +32 -0
  19. package/examples/desk/stories.jsonl +18 -0
  20. package/examples/desk/tally.css +62 -0
  21. package/examples/desk/tally.ts +76 -0
  22. package/examples/desk/thumbs.ts +45 -0
  23. package/examples/desk/trust.ts +24 -0
  24. package/examples/desk/words.ts +17 -0
  25. package/examples/trip/bar.ts +1 -1
  26. package/examples/trip/calendar-map.css +2 -0
  27. package/examples/trip/drags.ts +3 -3
  28. package/examples/trip/drawer.ts +5 -5
  29. package/examples/trip/event-form.ts +8 -7
  30. package/examples/trip/holding.ts +1 -1
  31. package/examples/trip/ics.ts +22 -112
  32. package/examples/trip/line-stops.ts +1 -1
  33. package/examples/trip/line-words.ts +1 -1
  34. package/examples/trip/line.ts +1 -1
  35. package/examples/trip/map.ts +1 -1
  36. package/examples/trip/month.ts +1 -1
  37. package/examples/trip/other-weeks.ts +1 -1
  38. package/examples/trip/page.ts +2 -2
  39. package/examples/trip/peek.ts +1 -1
  40. package/examples/trip/routes.ts +3 -3
  41. package/examples/trip/shell.ts +3 -3
  42. package/examples/trip/stays.ts +1 -1
  43. package/examples/trip/week.ts +1 -1
  44. package/examples/trip/writes.ts +1 -1
  45. package/examples/trips/card.ts +1 -1
  46. package/examples/trips/map.ts +1 -1
  47. package/examples/weeks/derive.ts +1 -1
  48. package/package.json +7 -1
  49. package/src/attachment.ts +7 -2
  50. package/src/demo.css +29 -26
  51. package/src/demo.ts +2 -2
  52. package/src/draft.ts +23 -8
  53. package/src/files.ts +24 -8
  54. package/{examples/trip/mercator.ts → src/geo.ts} +13 -3
  55. package/src/icon-names.ts +4 -0
  56. package/src/ics.ts +130 -0
  57. package/src/members/panel.css +208 -201
  58. package/src/members/panel.ts +17 -8
  59. package/src/outbox.ts +70 -0
  60. package/src/page.css +76 -70
  61. package/src/page.ts +79 -14
  62. package/src/parts.css +575 -428
  63. package/src/parts.ts +18 -5
  64. package/{examples/trip → src}/place-search.ts +5 -5
  65. package/{examples/trip → src}/places.ts +9 -7
  66. package/src/rank.ts +20 -0
  67. package/src/scrim.ts +81 -0
  68. package/src/server.ts +28 -1
  69. package/{examples/trip → src}/time.ts +37 -5
  70. package/src/tokens.css +5 -0
  71. package/src/tokens.json +35 -0
@@ -0,0 +1,34 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>joined: the desk</title>
7
+ <link rel="stylesheet" href="joined/tokens.css" />
8
+ <link rel="stylesheet" href="joined/page.css" />
9
+ <link rel="stylesheet" href="../app.css" />
10
+ <link rel="stylesheet" href="./desk.css" />
11
+ </head>
12
+ <body>
13
+ <a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
14
+ <header class="band">
15
+ <h1>The desk</h1>
16
+ <p class="lead">
17
+ Tasks an agent works through and a person steers: queued, working, up for review, then approved or sent back.
18
+ Drag a card to another lane, or up and down its own; what just changed glows.
19
+ </p>
20
+ <nav class="bar"><members-panel></members-panel></nav>
21
+ </header>
22
+ <main class="desk">
23
+ <section class="card tally" aria-label="How it's going"><desk-tally></desk-tally></section>
24
+ <desk-lanes><j-tasks></j-tasks></desk-lanes>
25
+ <form class="add">
26
+ <input name="title" placeholder="A task" aria-label="A task" required autocomplete="off" />
27
+ <input name="points" type="number" min="0" value="1" aria-label="Its points" />
28
+ <button class="act ink" data-icon="add">Put it on the desk</button>
29
+ <p class="said" role="status"></p>
30
+ </form>
31
+ </main>
32
+ <script type="module" src="./page.ts"></script>
33
+ </body>
34
+ </html>
@@ -0,0 +1,126 @@
1
+ /* <desk-lanes>'s look, in its shadow (with joined's parts): a lane for each status side by side where there's room,
2
+ one under another on a phone; each its name and how many, and its cards, each a card in its edge: its title, who
3
+ put it there and its points, its thumbs, its moves. The lane a card may go to is marked as it's held over it; a
4
+ card just changed glows a moment (./pulse.ts), and doesn't where the device asks for less motion. */
5
+ :host {
6
+ display: block;
7
+ }
8
+ .lanes {
9
+ display: grid;
10
+ grid-template-columns: repeat(4, minmax(0, 1fr));
11
+ gap: var(--space-12);
12
+ }
13
+ @media (max-width: 52rem) {
14
+ .lanes {
15
+ grid-template-columns: repeat(2, minmax(0, 1fr));
16
+ }
17
+ }
18
+ @media (max-width: 30rem) {
19
+ .lanes {
20
+ grid-template-columns: minmax(0, 1fr);
21
+ }
22
+ }
23
+ section {
24
+ min-height: 6rem;
25
+ border-radius: 4px;
26
+ }
27
+ section[over] {
28
+ outline: 2px dashed var(--ink);
29
+ outline-offset: 2px;
30
+ }
31
+ h3 {
32
+ display: flex;
33
+ justify-content: space-between;
34
+ margin: 0 0 var(--space-8);
35
+ font: var(--font-label);
36
+ color: var(--muted);
37
+ }
38
+ ol {
39
+ display: grid;
40
+ gap: var(--space-8);
41
+ margin: 0;
42
+ padding: 0;
43
+ list-style: none;
44
+ }
45
+ .card {
46
+ display: grid;
47
+ gap: var(--space-8);
48
+ padding: var(--space-12);
49
+ border: 1px solid var(--edge);
50
+ border-radius: 4px;
51
+ background: var(--card);
52
+ color: var(--ink);
53
+ touch-action: pan-y;
54
+ cursor: grab;
55
+ }
56
+ .card[dragged] {
57
+ position: relative;
58
+ z-index: 1;
59
+ cursor: grabbing;
60
+ box-shadow: 0 4px 16px rgb(0 0 0 / 0.16);
61
+ }
62
+ .card p {
63
+ margin: 0;
64
+ }
65
+ .meta {
66
+ display: flex;
67
+ align-items: center;
68
+ gap: var(--space-4);
69
+ font: var(--font-small);
70
+ color: var(--muted);
71
+ }
72
+ .thumbs {
73
+ display: flex;
74
+ gap: var(--space-4);
75
+ }
76
+ .thumb {
77
+ display: inline-flex;
78
+ align-items: center;
79
+ gap: var(--space-4);
80
+ min-height: 32px;
81
+ padding: 0 var(--space-8);
82
+ border: 1px solid var(--line);
83
+ border-radius: 99px;
84
+ background: none;
85
+ color: var(--muted);
86
+ font: var(--font-small);
87
+ }
88
+ button.thumb {
89
+ cursor: pointer;
90
+ }
91
+ .thumb[aria-pressed="true"] {
92
+ border-color: var(--ink);
93
+ color: var(--ink);
94
+ }
95
+ .acts {
96
+ display: flex;
97
+ flex-wrap: wrap;
98
+ gap: var(--space-8);
99
+ }
100
+ .acts:empty {
101
+ display: none;
102
+ }
103
+ .said:empty {
104
+ display: none;
105
+ }
106
+ .said {
107
+ color: var(--danger);
108
+ font: var(--font-small);
109
+ }
110
+ /* what just changed (./pulse.ts): a ring that fades */
111
+ .pulse {
112
+ animation: pulse 1.6s ease-out;
113
+ }
114
+ @keyframes pulse {
115
+ from {
116
+ box-shadow: 0 0 0 3px var(--hue-5);
117
+ }
118
+ to {
119
+ box-shadow: 0 0 0 3px transparent;
120
+ }
121
+ }
122
+ @media (prefers-reduced-motion: reduce) {
123
+ .pulse {
124
+ animation: none;
125
+ }
126
+ }
@@ -0,0 +1,133 @@
1
+ // Recipe: a collection in lanes by a field, each lane in the collection's order, a card dragged within a lane or to
2
+ // another. <desk-lanes> is a display: it holds <j-tasks> and never shows it, and draws a lane for each status in its
3
+ // shadow, the tasks there kept by key (keep), so a change makes again only the card it changed, which glows a moment
4
+ // (./pulse.ts). A card let go in another lane makes that move where its person may (the step its may offers, as its
5
+ // button does: ./steps.ts), and lands between the cards it's let go between (joined/rank) where they may rank it: one
6
+ // write, both at once. Let go where it may not go, it goes back. The kitchen's rail is the same with fixed moves;
7
+ // cardlet's columns, lanes the board's own.
8
+
9
+ import "joined/panel";
10
+ import { follow, held } from "joined/follow";
11
+ import { keep } from "joined/keep";
12
+ import { PARTS } from "joined/parts";
13
+ import { collections } from "./generated/rules.ts";
14
+ import { JTask } from "./generated/elements.ts";
15
+ import { card } from "./card.ts";
16
+ import { pulsing } from "./pulse.ts";
17
+ import { landing } from "joined/rank";
18
+ import { stepsOf } from "./steps.ts";
19
+ import { STATUS } from "./words.ts";
20
+ import STYLE from "./lanes.css" with { type: "text" };
21
+
22
+ const SHEET = new CSSStyleSheet();
23
+ SHEET.replaceSync(STYLE);
24
+ type Lane = {
25
+ el: HTMLElement;
26
+ count: HTMLElement;
27
+ list: HTMLOListElement;
28
+ kept: Map<string, { shows: string; el: HTMLElement }>;
29
+ };
30
+
31
+ class DeskLanes extends HTMLElement {
32
+ #root = this.attachShadow({ mode: "open" });
33
+ #row = Object.assign(document.createElement("div"), { className: "lanes" });
34
+ /** Each lane, by status: made once. */
35
+ #lanes = new Map<string, Lane>(
36
+ Object.entries(STATUS).map(([status, words]) => {
37
+ const el = Object.assign(document.createElement("section"), { ariaLabel: words }),
38
+ count = Object.assign(document.createElement("span"), { className: "count" }),
39
+ head = Object.assign(document.createElement("h3"), { textContent: words }),
40
+ list = document.createElement("ol");
41
+ head.append(count);
42
+ el.append(head, list);
43
+ el.dataset.status = status;
44
+ this.#row.append(el);
45
+ return [status, { el, count, list, kept: new Map() }];
46
+ }),
47
+ );
48
+ #tasks = this.getElementsByTagName(collections.tasks.tag) as HTMLCollectionOf<JTask>;
49
+ #watching = new MutationObserver(() => this.#draw());
50
+ #drawn = false;
51
+ /** Who the page is signed in as: its thumbs are theirs. */
52
+ #me?: number;
53
+ set me(me: number | undefined) {
54
+ this.#me = me;
55
+ // drawn again for someone else: nothing glows, as nothing in the document changed
56
+ this.#drawn = false;
57
+ this.#draw();
58
+ }
59
+ connectedCallback() {
60
+ if (!this.#row.parentNode) ((this.#root.adoptedStyleSheets = [PARTS, SHEET]), this.#root.append(this.#row));
61
+ this.#watching.observe(this, { subtree: true, childList: true, attributes: true });
62
+ this.#draw();
63
+ }
64
+ disconnectedCallback() {
65
+ this.#watching.disconnect();
66
+ }
67
+ /** The tasks in a lane, in the collection's order. */
68
+ #here(status: string) {
69
+ return [...this.#tasks].filter((t) => (t.data.status ?? "queued") === status);
70
+ }
71
+ /** Each lane's cards, in the collection's order (its rank), made again only where what they show has changed. */
72
+ #draw() {
73
+ for (const [status, { list, kept, count }] of this.#lanes) {
74
+ const here = this.#here(status);
75
+ count.textContent = String(here.length);
76
+ const rows = pulsing(
77
+ here.map((t) => card(t, this.#me)),
78
+ () => this.#drawn,
79
+ );
80
+ keep(list, kept, rows);
81
+ for (const t of here) kept.get(String(t.key))!.el.onpointerdown = (e) => this.#drag(e, t);
82
+ }
83
+ this.#drawn = this.#tasks.length > 0;
84
+ }
85
+ /** A card picked up and followed; let go in a lane, the move and the rank it may make there, in one write. */
86
+ #drag(down: PointerEvent, task: JTask) {
87
+ if ((down.target as Element).closest("button")) return;
88
+ const el = down.currentTarget as HTMLElement,
89
+ from = task.data.status ?? "queued",
90
+ laneAt = (e: PointerEvent) =>
91
+ [...this.#lanes].find(([, l]) => {
92
+ const r = l.el.getBoundingClientRect();
93
+ return e.clientX >= r.left && e.clientX <= r.right && e.clientY >= r.top && e.clientY <= r.bottom;
94
+ });
95
+ const here = (status: string) => this.#here(status),
96
+ may = (status: string) => status === from || stepsOf(task, "status").includes(status);
97
+ held(down, () => {
98
+ el.toggleAttribute("dragged", true);
99
+ follow(
100
+ down,
101
+ (e) => {
102
+ el.style.translate = `${e.clientX - down.clientX}px ${e.clientY - down.clientY}px`;
103
+ for (const [s, l] of this.#lanes) l.el.toggleAttribute("over", s !== from && s === laneAt(e)?.[0] && may(s));
104
+ },
105
+ (e) => {
106
+ el.style.translate = "";
107
+ el.toggleAttribute("dragged", false);
108
+ for (const [, l] of this.#lanes) l.el.toggleAttribute("over", false);
109
+ const lane = e && laneAt(e);
110
+ if (!lane || !may(lane[0])) return;
111
+ const [status, { list }] = lane,
112
+ others = here(status).filter((t) => t !== task),
113
+ rows = others.map((t) => list.querySelector<HTMLElement>(`[data-key="${t.key}"]`)!),
114
+ { at, rank } = landing(
115
+ rows,
116
+ others.map((t) => t.data.rank),
117
+ e.clientY,
118
+ ),
119
+ moved = status !== from,
120
+ // where it was among the others: let go there, it's where it was
121
+ was = moved ? -1 : here(status).indexOf(task),
122
+ fields: { status?: string; rank?: number } = moved ? { status } : {};
123
+ if (task.matches('[may~="replace:rank"]') && at !== was) fields.rank = rank;
124
+ if (Object.keys(fields).length) void task.replace(fields);
125
+ },
126
+ );
127
+ });
128
+ }
129
+ }
130
+
131
+ // defined last, once all it draws with is made: the document's tasks, as they are, then the lanes that draw them
132
+ customElements.define(collections.tasks.tag, JTask);
133
+ customElements.define("desk-lanes", DeskLanes);
@@ -0,0 +1,8 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { createTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ createTable("tasks", { columns: { title: { type: "text", is: { type: "string", said: "title is a string" } }, points: { type: "integer", is: { type: "integer", said: "points is a whole number" } }, rank: { type: "real", is: { type: "decimal", said: "rank is a number" } }, status: { type: "text", nullable: true, is: { type: "string", said: "status is a string" } }, by: { type: "integer", nullable: true, is: { type: "integer", said: "by is a whole number" }, to: { table: "members", said: "by links only to members the members document holds", onDelete: "set null" } }, added: { type: "text", nullable: true, is: { type: "form", form: "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(\\.\\d{3})?Z$", said: "added is an instant (YYYY-MM-DDTHH:MM:SSZ)" } } }, strict: true, needs: { columns: ["title", "points", "rank"], said: "a task needs title (string), points (integer), rank (decimal); may have status (string), ups (ids in members), downs (ids in members), by (an id in members), added (instant)" } }),
6
+ createTable("tasks_downs", { columns: { tasks: { type: "integer", to: { table: "tasks", said: "tasks is one of tasks", onDelete: "cascade" } }, downs: { type: "integer", to: { table: "members", said: "downs links only to members the members document holds", onDelete: "cascade" } } }, unique: [["tasks", "downs"]], strict: true, once: "downs links to {downs} already" }),
7
+ createTable("tasks_ups", { columns: { tasks: { type: "integer", to: { table: "tasks", said: "tasks is one of tasks", onDelete: "cascade" } }, ups: { type: "integer", to: { table: "members", said: "ups links only to members the members document holds", onDelete: "cascade" } } }, unique: [["tasks", "ups"]], strict: true, once: "ups links to {ups} already" }),
8
+ ];
@@ -0,0 +1,29 @@
1
+ // The desk's page: the tally (./tally.ts) over the lanes (./lanes.ts), and a form that puts a task at the foot of the
2
+ // queue. Each part is a recipe to copy (the skill's §16).
3
+
4
+ import { signedIn } from "joined/panel";
5
+ import "joined/toast";
6
+ import { iconify } from "joined/icons";
7
+ import { said } from "joined/parts";
8
+ import { collections } from "./generated/rules.ts";
9
+ import type { JTasks } from "./generated/elements.ts";
10
+ import { between } from "joined/rank";
11
+ import "./lanes.ts";
12
+ import "./tally.ts";
13
+
14
+ const lanes = document.querySelector<HTMLElement & { me?: number }>("desk-lanes")!,
15
+ tasks = document.querySelector<JTasks>(collections.tasks.place)!,
16
+ form = document.querySelector<HTMLFormElement>("form.add")!;
17
+ signedIn((me) => (lanes.me = me));
18
+
19
+ form.addEventListener("submit", async (e) => {
20
+ e.preventDefault();
21
+ const field = (n: string) => (form.elements.namedItem(n) as HTMLInputElement).value.trim();
22
+ const last = tasks.items.at(-1)?.data.rank;
23
+ const why = await said(
24
+ form.querySelector(".said")!,
25
+ tasks.add({ title: field("title"), points: Number(field("points")) || 0, rank: between(last) }),
26
+ );
27
+ if (!why) form.reset();
28
+ });
29
+ iconify();
@@ -0,0 +1,20 @@
1
+ // Recipe: what just changed, shown a moment. A display's row made again for a change (keep makes one again only as
2
+ // what it shows changes) glows as it's made, unless it's the first drawing: so a person watching sees what an agent,
3
+ // another screen, or their own write once it's kept, just touched, and nothing else moves. It's the row in the
4
+ // display's shadow that glows (its own class, its own animation), never the document's element: only the applier
5
+ // writes those. Its look is `.pulse` in the display's stylesheet, still where the device asks for less motion.
6
+
7
+ import type { Row } from "joined/keep";
8
+
9
+ /** Glow `el` a moment, again if it's glowing. */
10
+ export function pulse(el: HTMLElement) {
11
+ el.classList.remove("pulse");
12
+ void el.offsetWidth; // a restart: the class put back after a layout starts the animation again
13
+ el.classList.add("pulse");
14
+ el.addEventListener("animationend", () => el.classList.remove("pulse"), { once: true });
15
+ }
16
+
17
+ /** Rows whose make glows once `drawn()` says the display has drawn already. */
18
+ export const pulsing = (rows: Row[], drawn: () => boolean): Row[] =>
19
+ rows.map((r) => ({ ...r, make: () => (drawn() ? pulsed(r.make()) : r.make()) }));
20
+ const pulsed = (el: HTMLElement) => (pulse(el), el);
@@ -0,0 +1,9 @@
1
+ // The desk: tasks an agent works through and a person steers, its page at /desk. Each part of its page is a recipe
2
+ // to copy (the skill's §16): the lanes, the moves a task may make, thumbs, the tally, and what just changed.
3
+
4
+ import page from "./index.html";
5
+
6
+ export * as document from "./generated/rules.ts";
7
+ /** The desk's own rule: a thumb is your own, one a task (./trust.ts). */
8
+ export { trust } from "./trust.ts";
9
+ export const routes = { "/desk": page };
@@ -0,0 +1,32 @@
1
+ // Recipe: the moves an item may make from where it is, a button each, read off its `may`. A field the stories move
2
+ // (`{"moves":{"tasks":"status"}}`) is offered step by step as `replace:status>review` (the step's value as a URL's),
3
+ // only the steps its person's roles make from where the item is now: so the page names no rule, and a move a story
4
+ // doesn't make, or that isn't theirs, is never a button. The words are the page's, by where it's from and to ("Send
5
+ // back" is review to working, "Start" queued to working); a step without words says the value it's to. Copy it for
6
+ // any state machine: an order's, a post held for approval, an agent's task waiting on a person.
7
+
8
+ import type { Answer } from "joined/page";
9
+ import { said } from "joined/parts";
10
+
11
+ type Moving = Element & { replace(fields: Record<string, string>): Promise<Answer> };
12
+
13
+ /** The values `field` may step to from here, as the item's `may` offers them. */
14
+ export const stepsOf = (el: Element, field: string) =>
15
+ (el.getAttribute("may") ?? "")
16
+ .split(" ")
17
+ .filter((m) => m.startsWith(`replace:${field}>`))
18
+ .map((m) => decodeURIComponent(m.slice(`replace:${field}>`.length)));
19
+
20
+ /** A button for each step `field` may make from `from`, each its words (by "from>to"); pressed, it's made, and a
21
+ * refusal said in `line`. The first is the one to make (inked); the rest are quiet. */
22
+ export function steps(el: Moving, field: string, from: string, words: Record<string, string>, line: Element) {
23
+ return stepsOf(el, field).map((to, i) => {
24
+ const b = Object.assign(document.createElement("button"), {
25
+ type: "button",
26
+ className: i ? "act" : "act ink",
27
+ textContent: words[`${from}>${to}`] ?? to,
28
+ });
29
+ b.addEventListener("click", (e) => (e.stopPropagation(), void said(line, el.replace({ [field]: to }))));
30
+ return b;
31
+ });
32
+ }
@@ -0,0 +1,18 @@
1
+ {"cast":{"phone":"peter","agent":"nick"}}
2
+ {"links":{"by":{"to":"members","one":true},"ups":"members","downs":"members"}}
3
+ {"order":{"tasks":"rank"}}
4
+ {"fills":{"tasks":{"status":"queued","by":"me","added":"now"}}}
5
+ {"moves":{"tasks":"status"}}
6
+ {"story":"Peter puts a task on the desk: it's queued, his, and dated","as":"peter","does":{"doc":"desk","ops":[{"op":"add","path":"/tasks/-","value":{"title":"Print the badges","points":1,"rank":5}}]},"seen":["peter","phone","agent"],"then":{"/tasks/5/status":"queued","/tasks/5/by":1}}
7
+ {"story":"Peter can't say whose a task is: the desk fills it","as":"peter","cannot":{"doc":"desk","ops":[{"op":"add","path":"/tasks/-","value":{"title":"Print the badges","by":2}}]},"refused":"by is the server's to fill"}
8
+ {"story":"The agent starts the welcome","as":"agent","does":{"doc":"desk","ops":[{"op":"replace","path":"/tasks/1/status","value":"working"}]},"seen":["peter","agent"]}
9
+ {"story":"The agent puts the rota up for review","as":"agent","does":{"doc":"desk","ops":[{"op":"replace","path":"/tasks/2/status","value":"review"}]},"seen":["peter","agent"]}
10
+ {"story":"Peter approves the hall: it's done","as":"peter","does":{"doc":"desk","ops":[{"op":"replace","path":"/tasks/3/status","value":"done"}]},"seen":["peter","agent"]}
11
+ {"story":"Peter sends the hall back: the agent's working on it again","as":"peter","does":{"doc":"desk","ops":[{"op":"replace","path":"/tasks/3/status","value":"working"}]},"seen":["peter","agent"]}
12
+ {"story":"No one skips review: the welcome can't go from queued to done","as":"agent","cannot":{"doc":"desk","ops":[{"op":"replace","path":"/tasks/1/status","value":"done"}]},"refused":"that isn't a move you can make"}
13
+ {"story":"Peter moves the invitations to the top","as":"peter","does":{"doc":"desk","ops":[{"op":"replace","path":"/tasks/4/rank","value":0.5}]},"seen":["peter","agent"]}
14
+ {"story":"Nora thumbs the welcome up","as":"nora","does":{"doc":"desk","ops":[{"op":"add","path":"/tasks/1/ups/-","value":3}]},"seen":["nora","peter"],"then":{"/tasks/1/ups":[3]}}
15
+ {"story":"Nora changes her mind: up becomes down, in one write","as":"nora","premise":{"nora":[{"doc":"desk","ops":[{"op":"add","path":"/tasks/1/ups/-","value":3}]}]},"does":{"doc":"desk","ops":[{"op":"remove","path":"/tasks/1/ups/3"},{"op":"add","path":"/tasks/1/downs/-","value":3}]},"seen":["nora","peter"],"then":{"/tasks/1/downs":[3]}}
16
+ {"story":"Nora takes her thumb back","as":"nora","premise":{"nora":[{"doc":"desk","ops":[{"op":"add","path":"/tasks/1/downs/-","value":3}]}]},"does":{"doc":"desk","ops":[{"op":"remove","path":"/tasks/1/downs/3"}]},"seen":["nora","peter"]}
17
+ {"story":"Nora can't thumb for Nick","as":"nora","cannot":{"doc":"desk","ops":[{"op":"add","path":"/tasks/1/ups/-","value":2}]},"refused":"You thumb only for yourself."}
18
+ {"story":"Nora can't thumb the hall both ways","as":"nora","premise":{"nora":[{"doc":"desk","ops":[{"op":"add","path":"/tasks/3/ups/-","value":3}]}]},"cannot":{"doc":"desk","ops":[{"op":"add","path":"/tasks/3/downs/-","value":3}]},"refused":"One thumb a task: take the other back first."}
@@ -0,0 +1,62 @@
1
+ /* <desk-tally>'s look, in its shadow: a line of how much is done, a bar a part for each status (its width how many
2
+ are there, a tone of ink, deeper as a task goes on: hues are people's), and its key under it, each status and how
3
+ many. */
4
+ :host {
5
+ display: grid;
6
+ gap: var(--space-8);
7
+ }
8
+ .head {
9
+ margin: 0;
10
+ font: var(--font-heading);
11
+ }
12
+ .bar {
13
+ display: flex;
14
+ height: var(--space-12);
15
+ border-radius: 99px;
16
+ overflow: hidden;
17
+ background: var(--line);
18
+ }
19
+ .bar i {
20
+ flex: 0 0 0;
21
+ min-width: 0;
22
+ transition: flex-grow 0.3s ease;
23
+ }
24
+ .key {
25
+ display: flex;
26
+ flex-wrap: wrap;
27
+ gap: var(--space-4) var(--space-16);
28
+ margin: 0;
29
+ padding: 0;
30
+ list-style: none;
31
+ font: var(--font-small);
32
+ color: var(--muted);
33
+ }
34
+ .key li::before {
35
+ content: "";
36
+ display: inline-block;
37
+ width: 0.75em;
38
+ height: 0.75em;
39
+ margin-inline-end: var(--space-4);
40
+ border-radius: 2px;
41
+ background: var(--lane);
42
+ }
43
+ .queued {
44
+ --lane: color-mix(in srgb, var(--ink) 20%, transparent);
45
+ }
46
+ .working {
47
+ --lane: color-mix(in srgb, var(--ink) 40%, transparent);
48
+ }
49
+ .review {
50
+ --lane: color-mix(in srgb, var(--ink) 65%, transparent);
51
+ }
52
+ .done {
53
+ --lane: var(--ink);
54
+ }
55
+ .bar i {
56
+ background: var(--lane);
57
+ }
58
+ @media (prefers-reduced-motion: reduce) {
59
+ .bar i {
60
+ transition: none;
61
+ }
62
+ }
@@ -0,0 +1,76 @@
1
+ // Recipe (the views plan's V6, a summary strip): a summary of a collection, kept as its items change: how many are where (a bar, a part for each, its
2
+ // width how many), how many are done of all, and their points so. <desk-tally> holds nothing: it reads the tasks
3
+ // the page holds (a live list, made once) and watches their collection for what it shows alone (items come and
4
+ // go, and their status and points: an attributeFilter), so a thumb or a rank changes nothing here. It's made once
5
+ // and moves only what changed: a part's width and its words; the changes of one moment summed once (queueMicrotask,
6
+ // as the cafe's books are). Its parts are tones of ink, not hues: a hue is a person's. bluecount's totals and its "where it went" are this.
7
+
8
+ import { PARTS } from "joined/parts";
9
+ import { collections } from "./generated/rules.ts";
10
+ import type { JTask } from "./generated/elements.ts";
11
+ import { STATUS } from "./words.ts";
12
+ import STYLE from "./tally.css" with { type: "text" };
13
+
14
+ const SHEET = new CSSStyleSheet();
15
+ SHEET.replaceSync(STYLE);
16
+ /** A text's words set only where they've changed. */
17
+ const say = (el: HTMLElement, words: string) => void (el.textContent !== words && (el.textContent = words));
18
+
19
+ class DeskTally extends HTMLElement {
20
+ #root = this.attachShadow({ mode: "open" });
21
+ #head = Object.assign(document.createElement("p"), { className: "head" });
22
+ #bar = Object.assign(document.createElement("div"), { className: "bar", role: "img" });
23
+ #key = Object.assign(document.createElement("ul"), { className: "key" });
24
+ /** Each status's part of the bar and its line in the key, made once. */
25
+ #parts = new Map(
26
+ Object.entries(STATUS).map(([status, words]) => {
27
+ const part = Object.assign(document.createElement("i"), { className: status }),
28
+ line = Object.assign(document.createElement("li"), { className: status });
29
+ this.#bar.append(part);
30
+ this.#key.append(line);
31
+ return [status, { words, part, line }];
32
+ }),
33
+ );
34
+ #tasks = document.getElementsByTagName(collections.tasks.tag) as HTMLCollectionOf<JTask>;
35
+ #watching = new MutationObserver(() => this.#soon());
36
+ #summing = false;
37
+ /** Summed once for all that changed at one time, not again for each. */
38
+ #soon() {
39
+ if (!this.#summing) ((this.#summing = true), queueMicrotask(() => this.#draw()));
40
+ }
41
+ connectedCallback() {
42
+ if (!this.#head.parentNode)
43
+ ((this.#root.adoptedStyleSheets = [PARTS, SHEET]), this.#root.append(this.#head, this.#bar, this.#key));
44
+ const held = document.querySelector(collections.tasks.place);
45
+ if (held) this.#watching.observe(held, { childList: true, subtree: true, attributeFilter: ["status", "points"] });
46
+ this.#draw();
47
+ }
48
+ disconnectedCallback() {
49
+ this.#watching.disconnect();
50
+ }
51
+ #draw() {
52
+ this.#summing = false;
53
+ const count = new Map<string, number>();
54
+ let points = 0,
55
+ donePoints = 0;
56
+ for (const t of this.#tasks) {
57
+ const status = t.data.status ?? "queued";
58
+ count.set(status, (count.get(status) ?? 0) + 1);
59
+ points += t.data.points;
60
+ if (status === "done") donePoints += t.data.points;
61
+ }
62
+ const all = this.#tasks.length,
63
+ done = count.get("done") ?? 0;
64
+ say(this.#head, all ? `${done} of ${all} done · ${donePoints} of ${points} points` : "Nothing on the desk.");
65
+ this.#bar.ariaLabel = [...this.#parts].map(([s, p]) => `${p.words} ${count.get(s) ?? 0}`).join(", ");
66
+ for (const [status, { words, part, line }] of this.#parts) {
67
+ const n = count.get(status) ?? 0,
68
+ grow = String(n);
69
+ if (part.style.flexGrow !== grow) part.style.flexGrow = grow;
70
+ say(line, `${words} ${n}`);
71
+ }
72
+ }
73
+ }
74
+
75
+ // defined last, once all it draws with is made
76
+ customElements.define("desk-tally", DeskTally);
@@ -0,0 +1,45 @@
1
+ // Recipe: a thumb up or down, each person's own, as two lists of ids on the item (`ups` and `downs`, links to
2
+ // members): the buttons say how many, yours pressed; pressed, your thumb is given, the other taken back in the same
3
+ // write; pressed again, taken back. Offered where `may` offers adding to the list; the app's trust.ts holds a thumb
4
+ // to its giver and one an item (no story can say that). idea-cards' thumbs and cardlet's votes are this.
5
+
6
+ import { icon } from "joined/icons";
7
+ import { said } from "joined/parts";
8
+ import { write, type DeskOp, type JTask } from "./generated/elements.ts";
9
+
10
+ type Way = "ups" | "downs";
11
+
12
+ /** The ops that give `me`'s thumb `way` on a task (the other taken back), or take it back where it's given. */
13
+ export function thumbOps(task: JTask, me: number, way: Way): DeskOp[] {
14
+ const other: Way = way === "ups" ? "downs" : "ups",
15
+ at = (list: Way) => `/tasks/${task.key}/${list}` as const;
16
+ if (task.data[way].includes(me)) return [{ op: "remove", path: `${at(way)}/${me}` }];
17
+ return [
18
+ ...(task.data[other].includes(me) ? [{ op: "remove" as const, path: `${at(other)}/${me}` as const }] : []),
19
+ { op: "add", path: `${at(way)}/-`, value: me },
20
+ ];
21
+ }
22
+
23
+ /** A task's thumbs: up and down, each how many; buttons where `me` may thumb, else just said. */
24
+ export function thumbs(task: JTask, me: number | undefined, line: Element) {
25
+ const bar = Object.assign(document.createElement("span"), { className: "thumbs" }),
26
+ may = me !== undefined && task.matches('[may~="add:ups[]"]');
27
+ for (const [way, mark, words] of [
28
+ ["ups", "up", "Thumb up"],
29
+ ["downs", "down", "Thumb down"],
30
+ ] as const) {
31
+ const n = task.data[way].length,
32
+ mine = me !== undefined && task.data[way].includes(me),
33
+ say = `${words}: ${n}${mine ? ", yours" : ""}`;
34
+ const b = may
35
+ ? Object.assign(document.createElement("button"), { type: "button", className: "thumb" })
36
+ : Object.assign(document.createElement("span"), { className: "thumb" });
37
+ Object.assign(b, { title: say, ariaLabel: say });
38
+ b.setAttribute("aria-pressed", String(mine));
39
+ b.append(icon(mark), String(n));
40
+ if (may)
41
+ b.addEventListener("click", (e) => (e.stopPropagation(), void said(line, write(task, thumbOps(task, me!, way)))));
42
+ bar.append(b);
43
+ }
44
+ return bar;
45
+ }
@@ -0,0 +1,24 @@
1
+ // The desk's own rule, which no story can say: a thumb is your own, and a task has one of yours at most (up or down,
2
+ // the other taken back in the same write). idea-cards' and cardlet's votes are this rule.
3
+
4
+ import type { Trust } from "joined/server";
5
+
6
+ const THUMB = /^\/tasks\/(\d+)\/(ups|downs)\/(-|\d+)$/;
7
+ type Task = { id: number; ups?: number[]; downs?: number[] };
8
+
9
+ export const trust: Trust = ({ doc, ops }, { member }, read) => {
10
+ const thumbs = ops.flatMap((o) => {
11
+ const m = THUMB.exec(o.path);
12
+ const who = m && (o.op === "add" ? o.value : Number(m[3]));
13
+ return m ? [{ add: o.op === "add", task: Number(m[1]), list: m[2] as "ups" | "downs", who }] : [];
14
+ });
15
+ if (thumbs.some((t) => t.who !== member)) return "You thumb only for yourself.";
16
+ const tasks = read(doc).tasks as Task[];
17
+ for (const t of thumbs.filter((t) => t.add)) {
18
+ const other = t.list === "ups" ? "downs" : "ups";
19
+ const taken = thumbs.some((o) => !o.add && o.task === t.task && o.list === other);
20
+ if (!taken && tasks.find((x) => x.id === t.task)?.[other]?.includes(member))
21
+ return "One thumb a task: take the other back first.";
22
+ }
23
+ return null;
24
+ };
@@ -0,0 +1,17 @@
1
+ // The desk's words: where a task is, as its lanes and the tally say it, in the order it goes; and each move it makes,
2
+ // by where it's from and to, as its buttons say it.
3
+
4
+ /** Where a task is, in the order it goes. */
5
+ export const STATUS: Record<string, string> = {
6
+ queued: "Queued",
7
+ working: "Working",
8
+ review: "For review",
9
+ done: "Done",
10
+ };
11
+ /** Each move's words, by "from>to". */
12
+ export const MOVES: Record<string, string> = {
13
+ "queued>working": "Start",
14
+ "working>review": "Up for review",
15
+ "review>done": "Approve",
16
+ "review>working": "Send back",
17
+ };