@blueshed/joined 0.1.20 → 0.2.1

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 (84) hide show
  1. package/.claude/skills/joined/SKILL.md +1 -1
  2. package/.claude/skills/joined/reference.md +99 -18
  3. package/README.md +6 -4
  4. package/docs/design.md +31 -8
  5. package/docs/introduction.md +1 -1
  6. package/docs/learning.md +1 -1
  7. package/docs/light-and-shadow.svg +119 -0
  8. package/docs/links-and-trust.svg +93 -0
  9. package/docs/logo.svg +47 -0
  10. package/docs/stories-to-code.svg +86 -0
  11. package/docs/wire-op.svg +99 -0
  12. package/examples/cafe/kitchen.ts +2 -2
  13. package/examples/desk/card.ts +43 -0
  14. package/examples/desk/desk.css +17 -0
  15. package/examples/desk/desk.json +41 -0
  16. package/examples/desk/generated/elements.ts +69 -0
  17. package/examples/desk/generated/queries.ts +33 -0
  18. package/examples/desk/generated/rules.ts +94 -0
  19. package/examples/desk/index.html +34 -0
  20. package/examples/desk/lanes.css +126 -0
  21. package/examples/desk/lanes.ts +133 -0
  22. package/examples/desk/migrations/001-desk.ts +8 -0
  23. package/examples/desk/page.ts +29 -0
  24. package/examples/desk/pulse.ts +20 -0
  25. package/examples/desk/routes.ts +9 -0
  26. package/examples/desk/steps.ts +32 -0
  27. package/examples/desk/stories.jsonl +18 -0
  28. package/examples/desk/tally.css +62 -0
  29. package/examples/desk/tally.ts +76 -0
  30. package/examples/desk/thumbs.ts +45 -0
  31. package/examples/desk/trust.ts +24 -0
  32. package/examples/desk/words.ts +17 -0
  33. package/examples/trip/bar.ts +1 -1
  34. package/examples/trip/calendar-map.css +2 -0
  35. package/examples/trip/drags.ts +3 -3
  36. package/examples/trip/drawer.ts +5 -5
  37. package/examples/trip/event-form.ts +8 -7
  38. package/examples/trip/holding.ts +1 -1
  39. package/examples/trip/ics.ts +22 -112
  40. package/examples/trip/line-stops.ts +1 -1
  41. package/examples/trip/line-words.ts +1 -1
  42. package/examples/trip/line.ts +1 -1
  43. package/examples/trip/map.ts +1 -1
  44. package/examples/trip/month.ts +1 -1
  45. package/examples/trip/other-weeks.ts +1 -1
  46. package/examples/trip/page.ts +2 -2
  47. package/examples/trip/peek.ts +1 -1
  48. package/examples/trip/routes.ts +3 -3
  49. package/examples/trip/shell.ts +3 -3
  50. package/examples/trip/stays.ts +1 -1
  51. package/examples/trip/week.ts +1 -1
  52. package/examples/trip/writes.ts +1 -1
  53. package/examples/trips/card.ts +1 -1
  54. package/examples/trips/map.ts +1 -1
  55. package/examples/weeks/derive.ts +1 -1
  56. package/package.json +9 -2
  57. package/src/attachment.ts +18 -11
  58. package/src/client.ts +7 -0
  59. package/src/demo.css +29 -26
  60. package/src/demo.ts +2 -2
  61. package/src/draft.ts +23 -8
  62. package/src/files.ts +25 -9
  63. package/{examples/trip/mercator.ts → src/geo.ts} +13 -3
  64. package/src/icon-names.ts +4 -0
  65. package/src/ics.ts +130 -0
  66. package/src/members/group.ts +3 -1
  67. package/src/members/panel.css +208 -201
  68. package/src/members/panel.ts +17 -8
  69. package/src/ops.ts +5 -0
  70. package/src/outbox.ts +70 -0
  71. package/src/page.css +76 -70
  72. package/src/page.ts +86 -15
  73. package/src/parts.css +575 -428
  74. package/src/parts.ts +18 -5
  75. package/{examples/trip → src}/place-search.ts +5 -5
  76. package/{examples/trip → src}/places.ts +9 -7
  77. package/src/rank.ts +20 -0
  78. package/src/scrim.ts +81 -0
  79. package/src/server.ts +59 -13
  80. package/{examples/trip → src}/time.ts +37 -5
  81. package/src/together.ts +2 -6
  82. package/src/tokens.css +5 -0
  83. package/src/tokens.json +35 -0
  84. package/src/write.ts +29 -14
@@ -0,0 +1,86 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 880 390" font-family="system-ui, -apple-system, sans-serif">
2
+ <defs>
3
+ <marker id="arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
4
+ <path d="M 0 1.5 L 8.5 5 L 0 8.5 z" fill="#666"/>
5
+ </marker>
6
+ <marker id="arrow-blue" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
7
+ <path d="M 0 1.5 L 8.5 5 L 0 8.5 z" fill="#4e79a7"/>
8
+ </marker>
9
+ </defs>
10
+
11
+ <!-- Background -->
12
+ <rect width="880" height="390" rx="10" fill="#fafafa" stroke="#e5e5e5"/>
13
+
14
+ <!-- 1. Top Box: stories.jsonl -->
15
+ <g transform="translate(30, 22)">
16
+ <rect width="820" height="104" rx="8" fill="#ffffff" stroke="#ccc"/>
17
+ <rect width="820" height="28" rx="8" fill="#f3f4f6"/>
18
+ <path d="M 0 22 H 820" stroke="#e5e5e5" fill="none"/>
19
+ <circle cx="16" cy="14" r="4.5" fill="#e15759"/>
20
+ <circle cx="30" cy="14" r="4.5" fill="#edc948"/>
21
+ <circle cx="44" cy="14" r="4.5" fill="#59a14f"/>
22
+ <text x="62" y="18" font-size="12" font-weight="600" fill="#222">examples/trip/stories.jsonl</text>
23
+ <text x="804" y="18" font-size="11" fill="#666" text-anchor="end">the single source of truth — schema, migrations &amp; tests</text>
24
+
25
+ <g font-family="ui-monospace, SFMono-Regular, Menlo, monospace" font-size="9.2" fill="#222">
26
+ <text x="16" y="48">
27
+ <tspan fill="#666">{"story":</tspan><tspan fill="#59a14f">"Add dinner"</tspan><tspan fill="#666">,"as":"peter","does":{"doc":</tspan><tspan fill="#4e79a7" font-weight="600">"trip:1"</tspan><tspan fill="#666">,"ops":[{"op":</tspan><tspan fill="#f28e2b" font-weight="600">"add"</tspan><tspan fill="#666">,"path":</tspan><tspan fill="#4e79a7" font-weight="600">"/events/-"</tspan><tspan fill="#666">,"value":{"people":[1,2],…}}]}}</tspan>
28
+ </text>
29
+ <text x="16" y="70">
30
+ <tspan fill="#666">{"story":</tspan><tspan fill="#59a14f">"Move train"</tspan><tspan fill="#666">,"as":"phone","does":{"doc":</tspan><tspan fill="#4e79a7" font-weight="600">"trip:1"</tspan><tspan fill="#666">,"ops":[{"op":</tspan><tspan fill="#f28e2b" font-weight="600">"replace"</tspan><tspan fill="#666">,"path":</tspan><tspan fill="#4e79a7" font-weight="600">"/events/3/start"</tspan><tspan fill="#666">,"value":"2026-11-06T10:00"}]}}</tspan>
31
+ </text>
32
+ <text x="16" y="92">
33
+ <tspan fill="#666">{"story":</tspan><tspan fill="#59a14f">"Clear place"</tspan><tspan fill="#666">,"as":"peter","does":{"doc":</tspan><tspan fill="#4e79a7" font-weight="600">"trip:1"</tspan><tspan fill="#666">,"ops":[{"op":</tspan><tspan fill="#e15759" font-weight="600">"remove"</tspan><tspan fill="#666">,"path":</tspan><tspan fill="#4e79a7" font-weight="600">"/events/2/location"</tspan><tspan fill="#666">}]}}</tspan>
34
+ </text>
35
+ </g>
36
+ </g>
37
+
38
+ <!-- Arrow down to compiler -->
39
+ <line x1="440" y1="126" x2="440" y2="156" stroke="#666" stroke-width="1.5" marker-end="url(#arrow)"/>
40
+ <text x="450" y="146" font-size="11" fill="#666">reduce stories → model</text>
41
+
42
+ <!-- 2. Middle Box: src/compile.ts -->
43
+ <g transform="translate(190, 160)">
44
+ <rect width="500" height="58" rx="8" fill="#222" stroke="#222"/>
45
+ <text x="250" y="23" font-size="13" font-weight="600" fill="#fff" text-anchor="middle">src/compile.ts — modelOf(stories)</text>
46
+ <text x="250" y="43" font-family="ui-monospace, SFMono-Regular, Menlo, monospace" font-size="10.5" fill="#ddd" text-anchor="middle">
47
+ events → &lt;j-events&gt;&lt;j-event&gt; · tables · required · replace · clear · links
48
+ </text>
49
+ </g>
50
+
51
+ <!-- Split arrows left and right -->
52
+ <path d="M 320 218 L 320 236 L 220 236 L 220 254" fill="none" stroke="#4e79a7" stroke-width="1.5" marker-end="url(#arrow-blue)"/>
53
+ <path d="M 560 218 L 560 236 L 660 236 L 660 254" fill="none" stroke="#4e79a7" stroke-width="1.5" marker-end="url(#arrow-blue)"/>
54
+ <text x="260" y="231" font-size="11" fill="#4e79a7" text-anchor="end">for the server &amp; store</text>
55
+ <text x="620" y="231" font-size="11" fill="#4e79a7">for the page</text>
56
+
57
+ <!-- 3A. Left Box: generated/rules.ts & migrations/ -->
58
+ <g transform="translate(30, 258)">
59
+ <rect width="395" height="112" rx="8" fill="#ffffff" stroke="#4e79a7" stroke-width="1.5"/>
60
+ <rect x="0.75" y="0.75" width="393.5" height="26" rx="7" fill="#eef3f8"/>
61
+ <text x="14" y="18" font-size="12" font-weight="600" fill="#2c5282">generated/rules.ts &amp; migrations/</text>
62
+ <text x="382" y="18" font-size="11" fill="#4e79a7" text-anchor="end">guards &amp; SQLite tables</text>
63
+
64
+ <g font-family="ui-monospace, SFMono-Regular, Menlo, monospace" font-size="10.5" fill="#222">
65
+ <text x="14" y="47"><tspan fill="#666">export function</tspan> <tspan fill="#2c5282" font-weight="600">check</tspan>(o: Op, has: Has): string | null</text>
66
+ <text x="14" y="66" font-family="system-ui, sans-serif" font-size="10.5" fill="#555">• Refuses any collection, field, or op no story did</text>
67
+ <text x="14" y="84" font-family="system-ui, sans-serif" font-size="10.5" fill="#555">• Checks every id in <tspan font-family="ui-monospace, monospace" fill="#222">people: [1, 2]</tspan> exists in <tspan font-family="ui-monospace, monospace" fill="#222">people</tspan></text>
68
+ <text x="14" y="102" font-family="system-ui, sans-serif" font-size="10.5" fill="#555">• Writes SQLite migrations (<tspan font-family="ui-monospace, monospace" fill="#222">events</tspan>, <tspan font-family="ui-monospace, monospace" fill="#222">events_people</tspan>)</text>
69
+ </g>
70
+ </g>
71
+
72
+ <!-- 3B. Right Box: generated/elements.ts -->
73
+ <g transform="translate(455, 258)">
74
+ <rect width="395" height="112" rx="8" fill="#ffffff" stroke="#4e79a7" stroke-width="1.5"/>
75
+ <rect x="0.75" y="0.75" width="393.5" height="26" rx="7" fill="#eef3f8"/>
76
+ <text x="14" y="18" font-size="12" font-weight="600" fill="#2c5282">generated/elements.ts</text>
77
+ <text x="382" y="18" font-size="11" fill="#4e79a7" text-anchor="end">web components in the DOM</text>
78
+
79
+ <g font-family="ui-monospace, SFMono-Regular, Menlo, monospace" font-size="10.5" fill="#222">
80
+ <text x="14" y="47"><tspan fill="#2c5282" font-weight="600">&lt;j-events&gt;</tspan> → <tspan fill="#666">hold("trip:1?week=…"), items, add(...events)</tspan></text>
81
+ <text x="14" y="67"><tspan fill="#2c5282" font-weight="600">&lt;j-event&gt;</tspan> → <tspan fill="#666">key, data (cached &amp; frozen)</tspan></text>
82
+ <text x="14" y="86" font-family="system-ui, sans-serif" font-size="10.5" fill="#555">• Only the ops stories do: <tspan font-family="ui-monospace, monospace" fill="#222">change({…}), clear(…), drop()</tspan></text>
83
+ <text x="14" y="103" font-family="system-ui, sans-serif" font-size="10.5" fill="#555">• No story removes a title → <tspan font-family="ui-monospace, monospace" fill="#222">clear("title")</tspan> does not exist</text>
84
+ </g>
85
+ </g>
86
+ </svg>
@@ -0,0 +1,99 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 880 310" font-family="system-ui, -apple-system, sans-serif">
2
+ <defs>
3
+ <marker id="w-arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
4
+ <path d="M 0 1.5 L 8.5 5 L 0 8.5 z" fill="#4e79a7"/>
5
+ </marker>
6
+ <marker id="w-arrow-green" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
7
+ <path d="M 0 1.5 L 8.5 5 L 0 8.5 z" fill="#59a14f"/>
8
+ </marker>
9
+ </defs>
10
+
11
+ <rect width="880" height="310" rx="10" fill="#fafafa" stroke="#e5e5e5"/>
12
+
13
+ <!-- Column 1: Peter's Laptop -->
14
+ <g transform="translate(16, 24)">
15
+ <rect width="214" height="262" rx="8" fill="#ffffff" stroke="#ccc"/>
16
+ <rect x="0.75" y="0.75" width="212.5" height="28" rx="7" fill="#f3f4f6"/>
17
+ <text x="12" y="19" font-size="11.5" font-weight="600" fill="#222">1. Peter’s laptop</text>
18
+ <text x="202" y="19" font-size="10.5" fill="#666" text-anchor="end">one /ws per tab</text>
19
+
20
+ <text x="12" y="50" font-size="11" fill="#555">Drags the shinkansen to 10:00</text>
21
+ <text x="12" y="66" font-size="11" fill="#555">and presses <tspan font-weight="600" fill="#222">Save</tspan>:</text>
22
+
23
+ <rect x="12" y="78" width="190" height="52" rx="5" fill="#eef3f8" stroke="#4e79a7"/>
24
+ <text x="20" y="94" font-family="ui-monospace, monospace" font-size="10" fill="#2c5282" font-weight="600">el.change({</text>
25
+ <text x="20" y="109" font-family="ui-monospace, monospace" font-size="9.5" fill="#222"> start: "2026-11-06T10:00"</text>
26
+ <text x="20" y="123" font-family="ui-monospace, monospace" font-size="10" fill="#2c5282" font-weight="600">})</text>
27
+
28
+ <line x1="12" y1="146" x2="202" y2="146" stroke="#eee"/>
29
+
30
+ <text x="12" y="168" font-size="11" font-weight="600" fill="#59a14f">4a. On broadcast:</text>
31
+ <text x="12" y="187" font-family="ui-monospace, monospace" font-size="10" fill="#222">items.get("3")</text>
32
+ <text x="12" y="203" font-family="ui-monospace, monospace" font-size="10" fill="#222"> .setAttribute("start", …)</text>
33
+ <text x="12" y="226" font-size="10.5" fill="#555">Only <tspan font-family="ui-monospace, monospace" fill="#222">key="3"</tspan> moves; Save resets.</text>
34
+ <text x="12" y="246" font-family="ui-monospace, monospace" font-size="10" fill="#666">body[data-trip_1_week_…="2"]</text>
35
+ </g>
36
+
37
+ <!-- Arrow 1 -> 2 (Send Op) -->
38
+ <path d="M 236 96 L 342 96" fill="none" stroke="#4e79a7" stroke-width="1.8" marker-end="url(#w-arrow)"/>
39
+ <text x="289" y="75" font-family="ui-monospace, monospace" font-size="9.5" fill="#2c5282" text-anchor="middle">replace</text>
40
+ <text x="289" y="88" font-family="ui-monospace, monospace" font-size="9" fill="#4e79a7" text-anchor="middle">/events/3/start</text>
41
+
42
+ <!-- Arrow 2 -> 1 (Broadcast back) -->
43
+ <path d="M 342 188 L 236 188" fill="none" stroke="#59a14f" stroke-width="1.8" marker-end="url(#w-arrow-green)"/>
44
+ <text x="289" y="179" font-family="ui-monospace, monospace" font-size="9" fill="#59a14f" text-anchor="middle">{ version: 2, ops }</text>
45
+
46
+ <!-- Column 2: The Server -->
47
+ <g transform="translate(348, 24)">
48
+ <rect width="218" height="262" rx="8" fill="#ffffff" stroke="#222" stroke-width="1.5"/>
49
+ <rect x="0.75" y="0.75" width="216.5" height="28" rx="7" fill="#222"/>
50
+ <text x="109" y="19" font-size="11.5" font-weight="600" fill="#fff" text-anchor="middle">2. src/server.ts &amp; store.ts</text>
51
+
52
+ <g transform="translate(12, 44)" font-size="11" fill="#222">
53
+ <rect width="194" height="36" rx="5" fill="#f8f9fa" stroke="#e5e5e5"/>
54
+ <text x="10" y="15" font-weight="600">1. rules.check(op, has)</text>
55
+ <text x="10" y="29" font-size="10" fill="#666">Allowed by stories? Links valid?</text>
56
+
57
+ <rect y="44" width="194" height="36" rx="5" fill="#f8f9fa" stroke="#e5e5e5"/>
58
+ <text x="10" y="59" font-weight="600">2. group.mayWrite(doc, ops, …)</text>
59
+ <text x="10" y="73" font-size="10" fill="#666">Signed in? Not read-only? Trust ok?</text>
60
+
61
+ <rect y="88" width="194" height="36" rx="5" fill="#f8f9fa" stroke="#e5e5e5"/>
62
+ <text x="10" y="103" font-weight="600">3. store.write(doc, ops, …)</text>
63
+ <text x="10" y="117" font-size="10" fill="#666">1 SQLite transaction + changes row</text>
64
+
65
+ <rect y="132" width="194" height="44" rx="5" fill="#eef7ec" stroke="#59a14f"/>
66
+ <text x="10" y="149" font-weight="600" fill="#2b6e22">4. told(change) — pub/sub</text>
67
+ <text x="10" y="166" font-family="ui-monospace, monospace" font-size="9.2" fill="#222">{ doc, version: 2, ops, by: 1 }</text>
68
+ </g>
69
+
70
+ <text x="109" y="246" font-size="10" fill="#a33" text-anchor="middle">Refused? Tells sender "refused" + why</text>
71
+ </g>
72
+
73
+ <!-- Arrow 2 -> 3 (Broadcast to phone) -->
74
+ <path d="M 572 188 L 644 188" fill="none" stroke="#59a14f" stroke-width="1.8" marker-end="url(#w-arrow-green)"/>
75
+ <text x="608" y="179" font-family="ui-monospace, monospace" font-size="9.5" fill="#59a14f" text-anchor="middle">~25 ms</text>
76
+
77
+ <!-- Column 3: Peter's Phone -->
78
+ <g transform="translate(650, 24)">
79
+ <rect width="214" height="262" rx="8" fill="#ffffff" stroke="#ccc"/>
80
+ <rect x="0.75" y="0.75" width="212.5" height="28" rx="7" fill="#f3f4f6"/>
81
+ <text x="12" y="19" font-size="11.5" font-weight="600" fill="#222">3. Peter’s phone</text>
82
+ <text x="202" y="19" font-size="10.5" fill="#666" text-anchor="end">the same week</text>
83
+
84
+ <text x="12" y="52" font-size="11" fill="#555">Hears the same op on its socket:</text>
85
+
86
+ <rect x="12" y="64" width="190" height="58" rx="5" fill="#f8f9fa" stroke="#ddd"/>
87
+ <text x="20" y="82" font-family="ui-monospace, monospace" font-size="9.8" fill="#666">&lt;j-event <tspan fill="#222">key="3"</tspan></text>
88
+ <text x="20" y="98" font-family="ui-monospace, monospace" font-size="9.8" fill="#59a14f" font-weight="600"> start="2026-11-06T10:00"</text>
89
+ <text x="20" y="113" font-family="ui-monospace, monospace" font-size="9.8" fill="#666"> title="Shinkansen to Kyoto"&gt;</text>
90
+
91
+ <line x1="12" y1="146" x2="202" y2="146" stroke="#eee"/>
92
+
93
+ <text x="12" y="168" font-size="11" font-weight="600" fill="#59a14f">4b. Surgical update:</text>
94
+ <text x="12" y="188" font-size="10.2" fill="#555">• <tspan font-family="ui-monospace, monospace" fill="#222">MutationObserver</tspan> sees <tspan font-family="ui-monospace, monospace" fill="#222">key="3"</tspan></text>
95
+ <text x="12" y="207" font-size="10.5" fill="#555">• Moves only the Shinkansen block</text>
96
+ <text x="12" y="226" font-size="10.5" fill="#555">• Every other node stays untouched</text>
97
+ <text x="12" y="246" font-family="ui-monospace, monospace" font-size="10" fill="#666">body[data-trip_1_week_…="2"]</text>
98
+ </g>
99
+ </svg>
@@ -10,7 +10,7 @@
10
10
  import "joined/panel";
11
11
  import "joined/toast";
12
12
  import { keep, type Row } from "joined/keep";
13
- import { PARTS, said } from "joined/parts";
13
+ import { adopt, said } from "joined/parts";
14
14
  import * as kitchen from "./generated/kitchen.rules.ts";
15
15
  import { JLine, JOrder } from "./generated/kitchen.elements.ts";
16
16
  import { dragged } from "./rail-drag.ts";
@@ -48,7 +48,7 @@ class KitchenRail extends HTMLElement {
48
48
  #ticking?: ReturnType<typeof setInterval>;
49
49
  // on the page, it watches what it holds and the clock; off it, neither
50
50
  connectedCallback() {
51
- if (!this.#rail.parentNode) ((this.#root.adoptedStyleSheets = [PARTS, SHEET]), this.#root.append(this.#rail));
51
+ if (!this.#rail.parentNode) (adopt(this.#root, SHEET), this.#root.append(this.#rail));
52
52
  this.#watching.observe(this, { subtree: true, childList: true, attributes: true });
53
53
  this.#ticking = setInterval(() => this.#draw(), 60_000);
54
54
  this.#draw();
@@ -0,0 +1,43 @@
1
+ // A task's card, as the lanes draw it (a row kept by key, made again only as what it shows changes): its title, who
2
+ // put it on the desk (their face and name: the server filled it, "me") and its points, its thumbs (./thumbs.ts), and
3
+ // the moves its person may make from where it is (./steps.ts), a refusal said under them.
4
+
5
+ import type { Row } from "joined/keep";
6
+ import { members } from "joined/panel";
7
+ import { face } from "joined/parts";
8
+ import type { JTask } from "./generated/elements.ts";
9
+ import { steps } from "./steps.ts";
10
+ import { thumbs } from "./thumbs.ts";
11
+ import { MOVES } from "./words.ts";
12
+
13
+ /** A member's name, as the group on the page has it: none, once they've left. */
14
+ export const nameOf = (id?: number) =>
15
+ id === undefined ? "" : ([...members].find((m) => m.key === id)?.data.name ?? "");
16
+
17
+ /** A task's card, for `me` (none: signed in as nobody). */
18
+ export function card(task: JTask, me: number | undefined): Row {
19
+ const { title, points, by, status = "queued" } = task.data,
20
+ who = nameOf(by);
21
+ return {
22
+ key: String(task.key),
23
+ shows: JSON.stringify([task.data, task.getAttribute("may"), me, who]),
24
+ make: () => {
25
+ const li = Object.assign(document.createElement("li"), { className: "card" }),
26
+ line = Object.assign(document.createElement("p"), { className: "said", role: "status" }),
27
+ meta = Object.assign(document.createElement("p"), { className: "meta" }),
28
+ acts = Object.assign(document.createElement("p"), { className: "acts" });
29
+ li.dataset.key = String(task.key);
30
+ if (who) meta.append(face(by!, who), who, " · ");
31
+ meta.append(`${points} point${points === 1 ? "" : "s"}`);
32
+ acts.append(...steps(task, "status", status, MOVES, line));
33
+ li.append(
34
+ Object.assign(document.createElement("b"), { textContent: title }),
35
+ meta,
36
+ thumbs(task, me, line),
37
+ acts,
38
+ line,
39
+ );
40
+ return li;
41
+ },
42
+ };
43
+ }
@@ -0,0 +1,17 @@
1
+ /* The desk's page: the tally in a card over the lanes, and the form to add a task under them. */
2
+ main.desk {
3
+ display: grid;
4
+ gap: var(--space-24);
5
+ }
6
+ .card.tally {
7
+ padding: var(--space-16);
8
+ border: 1px solid var(--edge);
9
+ border-radius: 4px;
10
+ background: var(--card);
11
+ }
12
+ form.add input[type="number"] {
13
+ flex: 0 0 6rem;
14
+ }
15
+ form.add input[name="title"] {
16
+ flex-basis: 12rem;
17
+ }
@@ -0,0 +1,41 @@
1
+ {
2
+ "version": 1,
3
+ "tasks": [
4
+ {
5
+ "id": 1,
6
+ "title": "Write the welcome",
7
+ "status": "queued",
8
+ "points": 2,
9
+ "rank": 1,
10
+ "by": 1,
11
+ "added": "2026-11-10T09:00:00Z"
12
+ },
13
+ {
14
+ "id": 2,
15
+ "title": "Draw up the rota",
16
+ "status": "working",
17
+ "points": 3,
18
+ "rank": 2,
19
+ "by": 1,
20
+ "added": "2026-11-10T09:05:00Z"
21
+ },
22
+ {
23
+ "id": 3,
24
+ "title": "Book the hall",
25
+ "status": "review",
26
+ "points": 1,
27
+ "rank": 3,
28
+ "by": 2,
29
+ "added": "2026-11-10T09:10:00Z"
30
+ },
31
+ {
32
+ "id": 4,
33
+ "title": "Send the invitations",
34
+ "status": "done",
35
+ "points": 2,
36
+ "rank": 4,
37
+ "by": 3,
38
+ "added": "2026-11-10T09:15:00Z"
39
+ }
40
+ ]
41
+ }
@@ -0,0 +1,69 @@
1
+ // Written by src/compile.ts from examples/desk/stories.jsonl: change the stories, not this.
2
+
3
+ // Each collection is an element, defined here: on a page, it holds the document, and its items
4
+ // are put inside it. Each item is an element, defined by the page: as it is, or by a view that
5
+ // extends it. A field is an attribute (a list of ids as IDREFS: "1 3"), and an item's key the
6
+ // document's id for it. How an item looks is the app's: its view, or a display holding the
7
+ // collection draws it. Ops go up as an "ops" event, for the page to send to desk, with why they
8
+ // were made if it's said; only the ops the stories allow can be sent. Each returns its write's answer.
9
+
10
+ import { hold, letGo, type Answer } from "joined/page";
11
+
12
+ // the document an element is of: its collection's doc attribute (an instance of a kind, shelf:1), or desk
13
+ const docOf = (el: Element) => el.closest("[doc]")?.getAttribute("doc") ?? "desk";
14
+ // an element's ops go up as an "ops" event; what it returns is the write's answer, done or refused
15
+ const send = (from: Element, ops: object[], why?: string) => new Promise<Answer>((answer) => from.dispatchEvent(new CustomEvent("ops", { bubbles: true, composed: true, detail: { doc: docOf(from), ops, why, answer } })));
16
+
17
+ /** A task's fields, as the stories give them. */
18
+ export type JTaskData = { "title": string; "points": number; "rank": number; "status"?: string; "ups"?: number[]; "downs"?: number[]; "by"?: number; "added"?: string };
19
+ /** An add of a task, as it's sent: its fields as the stories write them. */
20
+ export type JTaskValue = { "title": string; "points": number; "rank": number; "status"?: string; "ups"?: number[]; "downs"?: number[]; "by"?: number | `$${number}`; "added"?: string };
21
+
22
+ /** <j-task key>: title (string), points (integer), rank (decimal), status (string), ups (ids in members), downs (ids in members), by (an id in members), added (instant), each an attribute. */
23
+ export class JTask extends HTMLElement {
24
+ static observedAttributes = ["title","points","rank","status","ups","downs","by","added","may"];
25
+ #data?: JTaskData & Required<Pick<JTaskData, "ups" | "downs">>;
26
+ /** Its id in the document. */
27
+ get key() { return Number(this.getAttribute("key")); }
28
+ get path() { return `/tasks/${this.key}`; }
29
+ /** Its fields, read from its attributes once and again when one changes: frozen, since they're shared. */
30
+ get data(): JTaskData & Required<Pick<JTaskData, "ups" | "downs">> {
31
+ return (this.#data ??= Object.freeze({ "title": this.getAttribute("title") ?? "", "points": Number(this.getAttribute("points")), "rank": Number(this.getAttribute("rank")), "status": this.getAttribute("status") ?? undefined, "ups": Object.freeze((this.getAttribute("ups") ?? "").split(" ").filter(Boolean).map(Number)), "downs": Object.freeze((this.getAttribute("downs") ?? "").split(" ").filter(Boolean).map(Number)), "by": this.hasAttribute("by") ? Number(this.getAttribute("by")) : undefined, "added": this.getAttribute("added") ?? undefined }) as JTaskData & Required<Pick<JTaskData, "ups" | "downs">>);
32
+ }
33
+ /** How a view shows it, drawn again whenever an attribute changes (what its person may do, its may, too). */
34
+ draw?(): void;
35
+ attributeChangedCallback() { this.#data = undefined; this.draw?.(); }
36
+ /** Replace some of its fields (status, rank): one write for all of them. */
37
+ replace(fields: Partial<Pick<JTaskData, "status" | "rank">>, why?: string) {
38
+ return send(this, Object.entries(fields).filter(([, value]) => value !== undefined).map(([field, value]) => ({ op: "replace", path: `${this.path}/${field.replace(".", "/")}`, value })), why);
39
+ }
40
+ /** Link it to one more id in a list (ups, downs): the ids there already are left as they are. */
41
+ link(field: "ups" | "downs", id: number, why?: string) { return send(this, [{ op: "add", path: `${this.path}/${field}/-`, value: id }], why); }
42
+ /** Take one id from a list (ups, downs). */
43
+ unlink(field: "ups" | "downs", id: number, why?: string) { return send(this, [{ op: "remove", path: `${this.path}/${field}/${id}` }], why); }
44
+ }
45
+
46
+ /** <j-tasks>: the document's tasks, each a <j-task> inside it. */
47
+ export class JTasks extends HTMLElement {
48
+ connectedCallback() { hold(this, docOf(this), "tasks", "j-task", {"title":"string","points":"integer","rank":"decimal","status":"string","ups":"ids","downs":"ids","by":"integer","added":"instant"}, false, "rank"); }
49
+ disconnectedCallback() { letGo(this); }
50
+ /** Its tasks, as the document has them. */
51
+ get items() { return [...this.children].filter((el): el is JTask => el.localName === "j-task"); }
52
+ /** Add tasks: one write for all of them. */
53
+ add(...values: JTaskValue[]) { return send(this, values.map((value) => ({ op: "add", path: "/tasks/-", value }))); }
54
+ }
55
+ customElements.define("j-tasks", JTasks);
56
+
57
+ /** An op on desk the stories allow, in any of its collections. */
58
+ export type DeskOp =
59
+ | { op: "add"; path: "/tasks/-"; value: JTaskValue }
60
+ | { op: "replace"; path: `/tasks/${number}/status`; value: string }
61
+ | { op: "replace"; path: `/tasks/${number}/rank`; value: number }
62
+ | { op: "add"; path: `/tasks/${number}/ups/-`; value: number }
63
+ | { op: "add"; path: `/tasks/${number}/downs/-`; value: number }
64
+ | { op: "remove"; path: `/tasks/${number}/ups/${number}` }
65
+ | { op: "remove"; path: `/tasks/${number}/downs/${number}` };
66
+
67
+ /** One write to desk across its collections (a move with its legs): sent from an element of it, checked
68
+ * whole by its rules, and made whole or not at all. */
69
+ export function write(from: Element, ops: DeskOp[], why?: string) { return send(from, ops, why); }
@@ -0,0 +1,33 @@
1
+ // Written by src/compile.ts from examples/desk/stories.jsonl: change the stories, not this.
2
+
3
+ /** Each collection's item, as one row of its table (`t`) is it: what the query gathers, and what the store keeps of a
4
+ * row a write changes, before and after, to tell each document holding it. */
5
+ export const items: Record<string, string> = {
6
+ "tasks": "json_patch('{}', json_object('id', t.id,\n 'title', t.\"title\",\n 'points', t.\"points\",\n 'rank', t.\"rank\",\n 'status', t.\"status\",\n 'ups', json(NULLIF((SELECT json_group_array(p.\"ups\" ORDER BY p.id) FROM \"tasks_ups\" p WHERE p.\"tasks\" = t.id), '[]')),\n 'downs', json(NULLIF((SELECT json_group_array(p.\"downs\" ORDER BY p.id) FROM \"tasks_downs\" p WHERE p.\"tasks\" = t.id), '[]')),\n 'by', t.\"by\",\n 'added', t.\"added\"))"
7
+ };
8
+
9
+ /** desk, whole, as one statement over its tables (SQLite): its parameters $doc. */
10
+ export const query = `SELECT json_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),
11
+ 'tasks', json((SELECT json_group_array(json_patch('{}', json_object('id', t.id,
12
+ 'title', t."title",
13
+ 'points', t."points",
14
+ 'rank', t."rank",
15
+ 'status', t."status",
16
+ 'ups', json(NULLIF((SELECT json_group_array(p."ups" ORDER BY p.id) FROM "tasks_ups" p WHERE p."tasks" = t.id), '[]')),
17
+ 'downs', json(NULLIF((SELECT json_group_array(p."downs" ORDER BY p.id) FROM "tasks_downs" p WHERE p."tasks" = t.id), '[]')),
18
+ 'by', t."by",
19
+ 'added', t."added")) ORDER BY COALESCE(t."rank", t.id), t.id)
20
+ FROM "tasks" t))) AS doc`;
21
+
22
+ /** Its rules over values (definitions' takes, gives and totals), as triggers the store makes in its database: run in
23
+ * each write's transaction, and told as any change is. */
24
+ export const triggers: string[] = [];
25
+
26
+ /** Its items, its query and its triggers, as Postgres says them. */
27
+ export const postgres = {
28
+ "items": {
29
+ "tasks": "json_strip_nulls(json_build_object('id', t.id,\n 'title', t.\"title\",\n 'points', t.\"points\",\n 'rank', t.\"rank\",\n 'status', t.\"status\",\n 'ups', (SELECT json_agg(p.\"ups\" ORDER BY p.id) FROM \"tasks_ups\" p WHERE p.\"tasks\" = t.id),\n 'downs', (SELECT json_agg(p.\"downs\" ORDER BY p.id) FROM \"tasks_downs\" p WHERE p.\"tasks\" = t.id),\n 'by', t.\"by\",\n 'added', t.\"added\"))"
30
+ },
31
+ "query": "SELECT json_build_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),\n 'tasks', (SELECT COALESCE(json_agg(json_strip_nulls(json_build_object('id', t.id,\n 'title', t.\"title\",\n 'points', t.\"points\",\n 'rank', t.\"rank\",\n 'status', t.\"status\",\n 'ups', (SELECT json_agg(p.\"ups\" ORDER BY p.id) FROM \"tasks_ups\" p WHERE p.\"tasks\" = t.id),\n 'downs', (SELECT json_agg(p.\"downs\" ORDER BY p.id) FROM \"tasks_downs\" p WHERE p.\"tasks\" = t.id),\n 'by', t.\"by\",\n 'added', t.\"added\")) ORDER BY COALESCE(t.\"rank\", t.id), t.id), '[]')\n FROM \"tasks\" t)) AS doc",
32
+ "triggers": []
33
+ };
@@ -0,0 +1,94 @@
1
+ // Written by src/compile.ts from examples/desk/stories.jsonl: change the stories, not this.
2
+
3
+ export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
4
+
5
+ /** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
6
+ * what each link is to. */
7
+ export const doc = "desk";
8
+ export const collections = {
9
+ "tasks": {
10
+ "place": "j-tasks",
11
+ "tag": "j-task",
12
+ "fields": {
13
+ "title": "string",
14
+ "points": "integer",
15
+ "rank": "decimal",
16
+ "status": "string",
17
+ "ups": "ids",
18
+ "downs": "ids",
19
+ "by": "integer",
20
+ "added": "instant"
21
+ },
22
+ "needs": [
23
+ "title",
24
+ "points",
25
+ "rank"
26
+ ],
27
+ "links": {
28
+ "ups": "members",
29
+ "downs": "members",
30
+ "by": "members"
31
+ },
32
+ "order": "rank",
33
+ "fills": {
34
+ "status": "queued",
35
+ "by": "me",
36
+ "added": "now"
37
+ }
38
+ }
39
+ } as const;
40
+ /** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */
41
+ export const anonymous = false;
42
+ /** What kind of document desk is, by the flows it uses: static, changed only with a release (a page reads it, and
43
+ * never subscribes); read-only, live, but no page writes it (derived); or shared, its members' to write. */
44
+ export const type = "shared";
45
+ /** The parts of desk a page may hold alone, by its query's parameters (its definitions' window): null, none. */
46
+ export const window = null;
47
+ /** Each field whose value moves only as the stories move it, each step by its roles (its definitions' moves). */
48
+ export const moves = {"tasks":"status"};
49
+ /** The document as one statement over its tables (generated/queries.ts). */
50
+ export { query, postgres, items, triggers } from "./queries.ts";
51
+
52
+ /** desk is one document. */
53
+ export const kind = null;
54
+
55
+ /** Each grant, read off the stories: the roles whose stories do it (a member: anyone). An op no story
56
+ * does isn't one. */
57
+ export const grants: Record<string, string[]> = {
58
+ "add tasks": [
59
+ "member"
60
+ ],
61
+ "add tasks.downs[]": [
62
+ "member"
63
+ ],
64
+ "add tasks.ups[]": [
65
+ "member"
66
+ ],
67
+ "remove tasks.downs[]": [
68
+ "member"
69
+ ],
70
+ "remove tasks.ups[]": [
71
+ "member"
72
+ ],
73
+ "replace tasks.rank": [
74
+ "member"
75
+ ],
76
+ "replace tasks.status:queued>working": [
77
+ "member"
78
+ ],
79
+ "replace tasks.status:review>done": [
80
+ "member"
81
+ ],
82
+ "replace tasks.status:review>working": [
83
+ "member"
84
+ ],
85
+ "replace tasks.status:working>review": [
86
+ "member"
87
+ ]
88
+ };
89
+
90
+ /** Who someone is to desk: a member, as it names no roles. */
91
+ export const rolesOf = (_m: number, _read: (doc: string) => any, _doc: string, _at?: any): string[] => [];
92
+
93
+ /** What someone sees: all of desk, as it has no owns. */
94
+ export const sees = null;
@@ -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>