@blueshed/joined 0.0.0-stage → 0.1.19

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 (213) hide show
  1. package/.claude/skills/joined/SKILL.md +17 -0
  2. package/.claude/skills/joined/reference.md +768 -0
  3. package/LICENSE +19 -0
  4. package/README.md +115 -2
  5. package/docs/design.md +148 -0
  6. package/docs/introduction.md +193 -0
  7. package/docs/learning.md +76 -0
  8. package/docs/stories.md +82 -0
  9. package/examples/app.css +27 -0
  10. package/examples/cafe/books.html +38 -0
  11. package/examples/cafe/books.json +13 -0
  12. package/examples/cafe/books.ts +64 -0
  13. package/examples/cafe/cafe.css +512 -0
  14. package/examples/cafe/front.html +115 -0
  15. package/examples/cafe/front.ts +7 -0
  16. package/examples/cafe/generated/books.elements.ts +52 -0
  17. package/examples/cafe/generated/books.queries.ts +11 -0
  18. package/examples/cafe/generated/books.rules.ts +42 -0
  19. package/examples/cafe/generated/kitchen.elements.ts +87 -0
  20. package/examples/cafe/generated/kitchen.queries.ts +47 -0
  21. package/examples/cafe/generated/kitchen.rules.ts +98 -0
  22. package/examples/cafe/generated/menu.elements.ts +61 -0
  23. package/examples/cafe/generated/menu.queries.ts +28 -0
  24. package/examples/cafe/generated/menu.rules.ts +65 -0
  25. package/examples/cafe/generated/order.elements.ts +87 -0
  26. package/examples/cafe/generated/order.queries.ts +47 -0
  27. package/examples/cafe/generated/order.rules.ts +95 -0
  28. package/examples/cafe/generated/staff.elements.ts +55 -0
  29. package/examples/cafe/generated/staff.queries.ts +27 -0
  30. package/examples/cafe/generated/staff.rules.ts +59 -0
  31. package/examples/cafe/generated/supplies.elements.ts +62 -0
  32. package/examples/cafe/generated/supplies.queries.ts +43 -0
  33. package/examples/cafe/generated/supplies.rules.ts +84 -0
  34. package/examples/cafe/generated/till.elements.ts +93 -0
  35. package/examples/cafe/generated/till.queries.ts +57 -0
  36. package/examples/cafe/generated/till.rules.ts +113 -0
  37. package/examples/cafe/index.html +70 -0
  38. package/examples/cafe/kitchen.css +107 -0
  39. package/examples/cafe/kitchen.html +39 -0
  40. package/examples/cafe/kitchen.ts +125 -0
  41. package/examples/cafe/menu.html +55 -0
  42. package/examples/cafe/menu.json +41 -0
  43. package/examples/cafe/menu.ts +84 -0
  44. package/examples/cafe/migrations/001-cafe.ts +11 -0
  45. package/examples/cafe/order.html +37 -0
  46. package/examples/cafe/order.ts +45 -0
  47. package/examples/cafe/rail-drag.ts +30 -0
  48. package/examples/cafe/routes.ts +32 -0
  49. package/examples/cafe/staff.json +20 -0
  50. package/examples/cafe/stories.jsonl +43 -0
  51. package/examples/cafe/supplies.html +77 -0
  52. package/examples/cafe/supplies.json +33 -0
  53. package/examples/cafe/supplies.ts +170 -0
  54. package/examples/cafe/till.json +95 -0
  55. package/examples/cafe/till.ts +122 -0
  56. package/examples/cafe/trust.ts +20 -0
  57. package/examples/cafe/views.ts +171 -0
  58. package/examples/docs.ts +28 -0
  59. package/examples/film.jpg +0 -0
  60. package/examples/hello/generated/elements.ts +45 -0
  61. package/examples/hello/generated/queries.ts +24 -0
  62. package/examples/hello/generated/rules.ts +45 -0
  63. package/examples/hello/hello.css +27 -0
  64. package/examples/hello/hello.json +1 -0
  65. package/examples/hello/index.html +32 -0
  66. package/examples/hello/migrations/001-hello.ts +6 -0
  67. package/examples/hello/page.ts +49 -0
  68. package/examples/hello/routes.ts +6 -0
  69. package/examples/hello/stories.jsonl +3 -0
  70. package/examples/index.html +146 -0
  71. package/examples/page.ts +11 -0
  72. package/examples/people/adding.ts +20 -0
  73. package/examples/people/generated/elements.ts +68 -0
  74. package/examples/people/generated/queries.ts +28 -0
  75. package/examples/people/generated/rules.ts +85 -0
  76. package/examples/people/links.ts +124 -0
  77. package/examples/people/migrations/001-people.ts +6 -0
  78. package/examples/people/migrations/002-add-people-member-and-guard-people.ts +7 -0
  79. package/examples/people/migrations/003-add-people-rank-and-guard-people.ts +7 -0
  80. package/examples/people/order.ts +61 -0
  81. package/examples/people/people.css +65 -0
  82. package/examples/people/people.json +26 -0
  83. package/examples/people/routes.ts +12 -0
  84. package/examples/people/stories.jsonl +20 -0
  85. package/examples/people/trust.ts +14 -0
  86. package/examples/people/view.ts +115 -0
  87. package/examples/routes.ts +11 -0
  88. package/examples/trip/answer-rows.ts +70 -0
  89. package/examples/trip/answers.ts +11 -0
  90. package/examples/trip/bar.ts +89 -0
  91. package/examples/trip/calendar-map.css +709 -0
  92. package/examples/trip/calendar-map.ts +249 -0
  93. package/examples/trip/drags.ts +143 -0
  94. package/examples/trip/drawer.ts +250 -0
  95. package/examples/trip/event-form.ts +199 -0
  96. package/examples/trip/generated/elements.ts +144 -0
  97. package/examples/trip/generated/queries.ts +46 -0
  98. package/examples/trip/generated/rules.ts +239 -0
  99. package/examples/trip/holding.ts +61 -0
  100. package/examples/trip/ics.ts +117 -0
  101. package/examples/trip/index.html +82 -0
  102. package/examples/trip/line-stops.ts +92 -0
  103. package/examples/trip/line-words.ts +79 -0
  104. package/examples/trip/line.ts +121 -0
  105. package/examples/trip/map.ts +234 -0
  106. package/examples/trip/mercator.ts +28 -0
  107. package/examples/trip/migrations/001-trip.ts +7 -0
  108. package/examples/trip/migrations/002-add-events-zone-and-guard-events.ts +7 -0
  109. package/examples/trip/migrations/003-guard-events-and-create-events_asked-and-more.ts +9 -0
  110. package/examples/trip/migrations/004-create-stays.ts +6 -0
  111. package/examples/trip/migrations/005-guard-events-and-create-events_arrives-and-more.ts +8 -0
  112. package/examples/trip/month.ts +87 -0
  113. package/examples/trip/other-weeks.ts +67 -0
  114. package/examples/trip/page.ts +121 -0
  115. package/examples/trip/peek.ts +71 -0
  116. package/examples/trip/people-chips.ts +74 -0
  117. package/examples/trip/place-search.ts +51 -0
  118. package/examples/trip/places.ts +34 -0
  119. package/examples/trip/routes.ts +27 -0
  120. package/examples/trip/shell.ts +39 -0
  121. package/examples/trip/stays.css +51 -0
  122. package/examples/trip/stays.ts +68 -0
  123. package/examples/trip/stories.jsonl +72 -0
  124. package/examples/trip/time.ts +46 -0
  125. package/examples/trip/told.ts +48 -0
  126. package/examples/trip/trip.json +69 -0
  127. package/examples/trip/trust.ts +51 -0
  128. package/examples/trip/week.ts +237 -0
  129. package/examples/trip/words.ts +4 -0
  130. package/examples/trip/writes.ts +91 -0
  131. package/examples/trip/zones.ts +16 -0
  132. package/examples/trips/card.ts +149 -0
  133. package/examples/trips/generated/elements.ts +60 -0
  134. package/examples/trips/generated/queries.ts +28 -0
  135. package/examples/trips/generated/rules.ts +62 -0
  136. package/examples/trips/index.html +47 -0
  137. package/examples/trips/map.ts +52 -0
  138. package/examples/trips/migrations/001-trips.ts +8 -0
  139. package/examples/trips/new-trip.ts +46 -0
  140. package/examples/trips/page.ts +9 -0
  141. package/examples/trips/routes.ts +7 -0
  142. package/examples/trips/stories.jsonl +12 -0
  143. package/examples/trips/trips.css +183 -0
  144. package/examples/trips/trips.json +7 -0
  145. package/examples/weeks/derive.ts +23 -0
  146. package/examples/weeks/generated/elements.ts +52 -0
  147. package/examples/weeks/generated/rules.ts +33 -0
  148. package/examples/weeks/routes.ts +4 -0
  149. package/examples/weeks/weeks.json +1 -0
  150. package/examples/welcome.css +299 -0
  151. package/package.json +51 -4
  152. package/src/attachment.ts +70 -0
  153. package/src/cli.ts +52 -0
  154. package/src/client.ts +98 -0
  155. package/src/compile.ts +2034 -0
  156. package/src/css.d.ts +5 -0
  157. package/src/definitions.ts +268 -0
  158. package/src/demo.css +29 -0
  159. package/src/demo.ts +42 -0
  160. package/src/draft.ts +69 -0
  161. package/src/engine.ts +288 -0
  162. package/src/file-value.ts +13 -0
  163. package/src/files.ts +187 -0
  164. package/src/follow.ts +56 -0
  165. package/src/hues.ts +3 -0
  166. package/src/icon-names.ts +77 -0
  167. package/src/icon.png +0 -0
  168. package/src/icons.ts +32 -0
  169. package/src/keep.ts +33 -0
  170. package/src/link.ts +31 -0
  171. package/src/mcp.ts +252 -0
  172. package/src/members/demo.ts +53 -0
  173. package/src/members/generated/elements.ts +68 -0
  174. package/src/members/generated/queries.ts +29 -0
  175. package/src/members/generated/rules.ts +65 -0
  176. package/src/members/group.ts +294 -0
  177. package/src/members/keys.ts +221 -0
  178. package/src/members/members.json +9 -0
  179. package/src/members/migrations/001-members.ts +6 -0
  180. package/src/members/migrations/002-guard-members.ts +11 -0
  181. package/src/members/migrations/003-add-members-act-and-guard-members.ts +7 -0
  182. package/src/members/panel.css +208 -0
  183. package/src/members/panel.ts +398 -0
  184. package/src/members/routes.ts +4 -0
  185. package/src/members/stories.jsonl +27 -0
  186. package/src/members/trust.ts +116 -0
  187. package/src/migrate.ts +597 -0
  188. package/src/migrations/001-joined.ts +13 -0
  189. package/src/migrations/002-group-keys.ts +16 -0
  190. package/src/migrations/003-change-inverse.ts +10 -0
  191. package/src/migrations/004-change-followed.ts +6 -0
  192. package/src/ops.ts +61 -0
  193. package/src/page.css +79 -0
  194. package/src/page.ts +413 -0
  195. package/src/parts.css +471 -0
  196. package/src/parts.ts +152 -0
  197. package/src/server.ts +862 -0
  198. package/src/settings.ts +94 -0
  199. package/src/starter.ts +89 -0
  200. package/src/store.ts +815 -0
  201. package/src/stories.ts +387 -0
  202. package/src/toast.ts +52 -0
  203. package/src/together.ts +167 -0
  204. package/src/tokens.css +85 -0
  205. package/src/tokens.json +457 -0
  206. package/src/upkeep.ts +86 -0
  207. package/src/visitors.ts +43 -0
  208. package/src/write.ts +567 -0
  209. package/starter/CLAUDE.md +37 -0
  210. package/starter/gitignore +3 -0
  211. package/starter/tests/hello-page.test.ts +14 -0
  212. package/starter/tests/hello.test.ts +8 -0
  213. package/starter/tsconfig.json +17 -0
@@ -0,0 +1,124 @@
1
+ // What links to a person. A link to a person is an attribute named for the collection, people="1 3", on an element
2
+ // of any document, so CSS finds them all: [people~="2"]. The links are kept in an index, by person, as they come,
3
+ // change and go, so a person's row draws its links searching nothing; and a link changed anywhere on the page (one
4
+ // come or gone, its title) is drawn again in the rows of those it links to alone, so a change costs the same however
5
+ // many things link to them. Pressing a link sends its element a "pick" event, for whatever holds it to act on.
6
+
7
+ import { keep, type Row } from "joined/keep";
8
+
9
+ /** A person's row, as the links know it: its key, and how it's told one link changed. */
10
+ type Linked = HTMLElement & { key: number; linked(el: Element): void };
11
+
12
+ /** An element linking to people, by its key: its kind and its own key. */
13
+ const keyOf = (el: Element) => `${el.localName} ${el.getAttribute("key")}`;
14
+ /** What links to each person, by their key: kept as links come, change and go, so a person's draw searches nothing. */
15
+ const linksTo = new Map<number, Set<Element>>();
16
+ const keysIn = (people: string | null) =>
17
+ (people ?? "").split(/\s+/).filter(Boolean).map(Number).filter(Number.isInteger);
18
+ /** An element's links, from those it had to those it has. */
19
+ const relink = (el: Element, had: string | null, has: string | null) => {
20
+ for (const k of keysIn(had)) linksTo.get(k)?.delete(el);
21
+ for (const k of keysIn(has)) (linksTo.get(k) ?? linksTo.set(k, new Set()).get(k)!).add(el);
22
+ };
23
+ /** Two elements in the order the page has them. */
24
+ const inPlace = (a: Element, b: Element) => (a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
25
+
26
+ /** A person's links, in their row: a button for each element linking to them, its title, which picks it. */
27
+ export class Links {
28
+ readonly el = Object.assign(document.createElement("p"), { className: "links" });
29
+ #kept = new Map<string, { shows: string; el: HTMLElement }>();
30
+
31
+ constructor(readonly of: HTMLElement & { key: number }) {}
32
+
33
+ /** Every link to them, from the index, in the page's order; none, said so. */
34
+ draw() {
35
+ const links = [...(linksTo.get(this.of.key) ?? [])].filter((el) => el.isConnected).sort(inPlace);
36
+ keep(
37
+ this.el,
38
+ this.#kept,
39
+ links.length
40
+ ? links.map((el) => this.#row(el))
41
+ : [
42
+ {
43
+ key: "none",
44
+ shows: "",
45
+ make: () => Object.assign(document.createElement("span"), { textContent: "Nothing links here yet" }),
46
+ },
47
+ ],
48
+ );
49
+ }
50
+ /** One element's link to them, as it is now: its row made, said again, or taken away, and the rest as they are. */
51
+ linked(el: Element) {
52
+ const key = keyOf(el),
53
+ k = this.#kept.get(key);
54
+ if (!(el.isConnected && el.matches(`[people~="${this.of.key}"]`))) {
55
+ if (k) (k.el.remove(), this.#kept.delete(key));
56
+ return void (!this.#kept.size && this.draw());
57
+ }
58
+ // the first to link to them, in place of "nothing links here": drawn whole
59
+ if (this.#kept.has("none")) return this.draw();
60
+ const row = this.#row(el);
61
+ if (k?.shows === row.shows) return;
62
+ const made = row.make();
63
+ k ? k.el.replaceWith(made) : this.el.append(made);
64
+ this.#kept.set(key, { shows: row.shows, el: made });
65
+ }
66
+ /** An element linking to them, as its row: its title, which picks it. */
67
+ #row(el: Element): Row {
68
+ const title = el.getAttribute("title") ?? el.localName;
69
+ return {
70
+ key: keyOf(el),
71
+ shows: title,
72
+ make: () => {
73
+ const go = Object.assign(document.createElement("button"), {
74
+ type: "button",
75
+ className: "act small",
76
+ textContent: title,
77
+ });
78
+ go.addEventListener("click", () => {
79
+ el.dispatchEvent(new CustomEvent("pick", { bubbles: true }));
80
+ this.of.closest<HTMLElement>("[popover]")?.hidePopover();
81
+ });
82
+ return go;
83
+ },
84
+ };
85
+ }
86
+ }
87
+
88
+ /** The page's links indexed, and watched: a link or the title of something linking changed, or something linking
89
+ * came or went (an element with people="…", or holding some); the index kept, and each person it links to, or did,
90
+ * told that one link, from `persons`, a live list of their rows. */
91
+ export function watchLinks(persons: HTMLCollectionOf<Linked>) {
92
+ for (const el of document.querySelectorAll("[people]")) relink(el, null, el.getAttribute("people"));
93
+ new MutationObserver((records) => {
94
+ const people = new Map([...persons].map((p) => [p.key, p]));
95
+ const told = (el: Element, keys: string) => {
96
+ for (const k of new Set(keysIn(keys))) people.get(k)?.linked(el);
97
+ };
98
+ const linking = (n: Node) =>
99
+ n instanceof Element ? [n, ...n.querySelectorAll("[people]")].filter((el) => el.hasAttribute("people")) : [];
100
+ for (const r of records)
101
+ if (r.type === "attributes") {
102
+ const el = r.target as Element,
103
+ had = r.attributeName === "people" ? r.oldValue : null;
104
+ if (r.attributeName === "people") relink(el, had, el.getAttribute("people"));
105
+ told(el, `${had ?? ""} ${el.getAttribute("people") ?? ""}`);
106
+ } else {
107
+ for (const [nodes, gone] of [
108
+ [r.removedNodes, true],
109
+ [r.addedNodes, false],
110
+ ] as const)
111
+ for (const n of nodes)
112
+ for (const el of linking(n)) {
113
+ const people = el.getAttribute("people");
114
+ relink(el, gone ? people : null, gone ? null : people);
115
+ told(el, people!);
116
+ }
117
+ }
118
+ }).observe(document.documentElement, {
119
+ subtree: true,
120
+ childList: true,
121
+ attributeFilter: ["people", "title"],
122
+ attributeOldValue: true,
123
+ });
124
+ }
@@ -0,0 +1,6 @@
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("people", { columns: { name: { type: "text", is: { type: "string", said: "name is a string" } } }, strict: true, needs: { columns: ["name"], said: "a person needs name (string)" } }),
6
+ ];
@@ -0,0 +1,7 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { addColumn, guardTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ addColumn("people", "member", { type: "integer", nullable: true, is: { type: "integer", said: "member is a whole number" }, to: { table: "members", said: "member links only to members the members document holds", onDelete: "set null" } }),
6
+ guardTable("people", { columns: { name: { type: "text", is: { type: "string", said: "name is a string" } }, member: { type: "integer", is: { type: "integer", said: "member is a whole number" }, to: { table: "members", said: "member links only to members the members document holds", onDelete: "set null" }, nullable: true } }, strict: true, needs: { columns: ["name"], said: "a person needs name (string); may have member (an id in members)" } }),
7
+ ];
@@ -0,0 +1,7 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { addColumn, guardTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ addColumn("people", "rank", { type: "real", nullable: true, is: { type: "decimal", said: "rank is a number" } }),
6
+ guardTable("people", { columns: { name: { type: "text", is: { type: "string", said: "name is a string" } }, rank: { type: "real", is: { type: "decimal", said: "rank is a number" }, nullable: true }, member: { type: "integer", is: { type: "integer", said: "member is a whole number" }, to: { table: "members", said: "member links only to members the members document holds", onDelete: "set null" }, nullable: true } }, strict: true, needs: { columns: ["name"], said: "a person needs name (string); may have rank (decimal), member (an id in members)" } }),
7
+ ];
@@ -0,0 +1,61 @@
1
+ // A row's place in its list's order, by a grip: dragged (held, by a finger) up or down, the row following the
2
+ // pointer, or moved by the arrow keys. Let go, it's given a rank between those it then sits between, and the page
3
+ // places it once the document's told.
4
+
5
+ import { follow, held } from "joined/follow";
6
+
7
+ /** A row in an ordered list: its key, and its rank (without one, its key, as the page places it). */
8
+ type Ranked = HTMLElement & { key: number; data: { rank?: number } };
9
+
10
+ /** The rows in their order, as the list a row is in has them: its siblings of its kind. */
11
+ const order = <T extends Ranked>(row: T) =>
12
+ [...row.parentElement!.children].filter((c): c is T => c.localName === row.localName);
13
+
14
+ /** The rank that puts `row` at `at` among the others, or none where it's alone in its list. */
15
+ const rankAt = (row: Ranked, at: number) => {
16
+ const others = order(row).filter((p) => p !== row),
17
+ rank = (p: Ranked) => p.data.rank ?? p.key; // without one, its id, as the page places it
18
+ const [before, after] = [others[at - 1], others[at]];
19
+ if (!before && !after) return null; // alone in its list: nowhere to move
20
+ return before && after ? (rank(before) + rank(after)) / 2 : before ? rank(before) + 1 : rank(after!) - 1;
21
+ };
22
+
23
+ /** Dragged up or down the list: it follows the pointer, and let go, it's moved to where it was let go. */
24
+ const drag = (row: Ranked, down: PointerEvent, to: (at: number) => void) => {
25
+ const all = order(row),
26
+ tops = all.map((p) => p.getBoundingClientRect().top);
27
+ let at = all.indexOf(row);
28
+ row.toggleAttribute("dragged", true);
29
+ follow(
30
+ down,
31
+ (e) => {
32
+ row.style.translate = `0 ${e.clientY - down.clientY}px`;
33
+ at = Math.max(
34
+ 0,
35
+ tops.findLastIndex((t) => t <= e.clientY),
36
+ );
37
+ },
38
+ (e) => {
39
+ row.style.translate = "";
40
+ row.toggleAttribute("dragged", false);
41
+ if (e && at !== all.indexOf(row)) to(at);
42
+ },
43
+ );
44
+ };
45
+
46
+ /** A grip, `handle`, that moves `row` in its list: a new place's rank told to `rank`, to send as the row's own replace. */
47
+ export function grip(row: Ranked, handle: HTMLElement, rank: (value: number) => void) {
48
+ const to = (at: number) => {
49
+ const value = rankAt(row, at);
50
+ if (value !== null) rank(value);
51
+ };
52
+ handle.addEventListener("pointerdown", (e) => held(e, () => drag(row, e, to)));
53
+ handle.addEventListener("keydown", (e) => {
54
+ const by = e.key === "ArrowUp" ? -1 : e.key === "ArrowDown" ? 1 : 0;
55
+ if (!by) return;
56
+ e.preventDefault();
57
+ const all = order(row),
58
+ at = all.indexOf(row) + by;
59
+ if (at >= 0 && at < all.length) to(at);
60
+ });
61
+ }
@@ -0,0 +1,65 @@
1
+ /* The people document's look: each person, wherever a page holds them. */
2
+
3
+ /* the people open from their button, under it, and flip to keep on the page; on a phone, rising from the foot */
4
+ [popovertarget="people"] {
5
+ anchor-name: --people;
6
+ }
7
+ #people {
8
+ position-anchor: --people;
9
+ position-area: block-end span-inline-end;
10
+ position-try-fallbacks: flip-inline;
11
+ inset: auto;
12
+ margin: 4px 0 0;
13
+ }
14
+ @media (max-width: 40rem) {
15
+ #people {
16
+ position-area: none;
17
+ inset: auto 0 0;
18
+ margin: 0;
19
+ }
20
+ }
21
+ j-people {
22
+ display: grid;
23
+ gap: var(--space-10);
24
+ margin-bottom: var(--space-12);
25
+ }
26
+ j-person {
27
+ display: grid;
28
+ grid-template-columns: auto auto 1fr auto auto auto auto;
29
+ gap: 2px var(--space-8);
30
+ align-items: center;
31
+ }
32
+ /* a name, changed where it is: a field, 16px (src/parts.css), a line under it in place of its edge */
33
+ j-person input {
34
+ border: 0;
35
+ border-bottom: 1px solid var(--line);
36
+ padding: 2px 0;
37
+ }
38
+ j-person .said {
39
+ grid-column: 3 / -1;
40
+ }
41
+ j-person .links {
42
+ grid-column: 3 / -1;
43
+ margin: 0;
44
+ display: flex;
45
+ flex-wrap: wrap;
46
+ gap: var(--space-4);
47
+ font: var(--font-small);
48
+ color: var(--muted);
49
+ }
50
+ /* a person nobody is yet: Invite them; invited, said until they're in */
51
+ j-person .invited {
52
+ font: var(--font-small);
53
+ color: var(--muted);
54
+ }
55
+ /* a person's place in the order: their grip, dragged; while it is, the row lifted above the rest */
56
+ j-person .grip {
57
+ cursor: grab;
58
+ touch-action: pan-x pan-y;
59
+ }
60
+ j-person[dragged] {
61
+ position: relative;
62
+ z-index: 1;
63
+ background: var(--card);
64
+ outline: 1px solid var(--edge);
65
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "version": 1,
3
+ "people": [
4
+ {
5
+ "id": 1,
6
+ "name": "Peter",
7
+ "member": 1,
8
+ "rank": 1
9
+ },
10
+ {
11
+ "id": 2,
12
+ "name": "Kenji",
13
+ "rank": 2
14
+ },
15
+ {
16
+ "id": 3,
17
+ "name": "Aiko",
18
+ "rank": 3
19
+ },
20
+ {
21
+ "id": 4,
22
+ "name": "Yuki",
23
+ "rank": 4
24
+ }
25
+ ]
26
+ }
@@ -0,0 +1,12 @@
1
+ // The people: a document other pages hold, with no page of its own.
2
+
3
+ export * as document from "./generated/rules.ts";
4
+ /** The people's own rule: you say which person you are, as yourself (./trust.ts). */
5
+ export { trust } from "./trust.ts";
6
+ /** An invitation's act: once they're in, the person they were invited as is them (said as them, as the trust asks). */
7
+ export const acts = {
8
+ person: (member: number, key: string) => ({
9
+ doc: "people",
10
+ ops: [{ op: "replace" as const, path: `/people/${key}/member`, value: member }],
11
+ }),
12
+ };
@@ -0,0 +1,20 @@
1
+ {"cast":{"phone":"peter"}}
2
+ {"unique":{"people":["name","member"]}}
3
+ {"order":{"people":"rank"}}
4
+ {"links":{"member":{"to":"members","one":true}}}
5
+ {"story":"Peter adds Hana to the people, and his phone's list shows her","as":"peter","does":{"doc":"people","ops":[{"op":"add","path":"/people/-","value":{"name":"Hana"}}]},"seen":["peter","phone"]}
6
+ {"story":"He gives Kenji's whole name","as":"peter","does":{"doc":"people","ops":[{"op":"replace","path":"/people/2/name","value":"Kenji Sato"}]},"seen":["peter","phone"]}
7
+ {"story":"He takes Yuki off the list: nothing links to her","as":"peter","does":{"doc":"people","ops":[{"op":"remove","path":"/people/4"}]},"seen":["peter","phone"]}
8
+ {"story":"Peter puts Aiko first, dragging her to the top: every page's list in his order","as":"peter","does":{"doc":"people","ops":[{"op":"replace","path":"/people/3/rank","value":0.5}]},"seen":["peter","phone","nora"]}
9
+ {"story":"Nora puts Kenji last, between nobody and the end","as":"nora","does":{"doc":"people","ops":[{"op":"replace","path":"/people/2/rank","value":5}]},"seen":["peter","nora"]}
10
+ {"story":"A place in the order is a number, not a word","as":"peter","cannot":{"doc":"people","ops":[{"op":"replace","path":"/people/3/rank","value":"first"}]}}
11
+ {"story":"Nora says she's Aiko: on the line, Aiko is her","as":"nora","does":{"doc":"people","ops":[{"op":"replace","path":"/people/3/member","value":3}]},"seen":["peter","phone","nora"]}
12
+ {"story":"Nora isn't Aiko after all: she takes it back","as":"nora","premise":{"nora":[{"doc":"people","ops":[{"op":"replace","path":"/people/3/member","value":3}]}]},"does":{"doc":"people","ops":[{"op":"remove","path":"/people/3/member"}]},"seen":["peter","nora"]}
13
+ {"story":"You say who you are, as yourself: Nick can't say Nora is Aiko","as":"nick","cannot":{"doc":"people","ops":[{"op":"replace","path":"/people/3/member","value":3}]},"refused":"you say which person you are, as yourself"}
14
+ {"story":"Nor take it back for her","as":"nick","premise":{"nora":[{"doc":"people","ops":[{"op":"replace","path":"/people/3/member","value":3}]}]},"cannot":{"doc":"people","ops":[{"op":"remove","path":"/people/3/member"}]},"refused":"you say which person you are, as yourself"}
15
+ {"story":"One person each: Nora, Aiko, can't be Kenji too","as":"nora","premise":{"nora":[{"doc":"people","ops":[{"op":"replace","path":"/people/3/member","value":3}]}]},"cannot":{"doc":"people","ops":[{"op":"replace","path":"/people/2/member","value":3}]}}
16
+ {"story":"Kenji can't be taken off the list: the dinner links to him","as":"peter","cannot":{"doc":"people","ops":[{"op":"remove","path":"/people/2"}]}}
17
+ {"story":"A person needs a name","as":"peter","cannot":{"doc":"people","ops":[{"op":"add","path":"/people/-","value":{}}]}}
18
+ {"story":"A name is words, not a number","as":"peter","cannot":{"doc":"people","ops":[{"op":"replace","path":"/people/2/name","value":7}]}}
19
+ {"story":"Two people aren't named the same: Aiko is on the list already","as":"peter","cannot":{"doc":"people","ops":[{"op":"add","path":"/people/-","value":{"name":"Aiko"}}]},"refused":"people 3 has that name already"}
20
+ {"story":"The people are names and nothing more: there are no pets","as":"peter","cannot":{"doc":"people","ops":[{"op":"replace","path":"/pets/1/name","value":"Rex"}]}}
@@ -0,0 +1,14 @@
1
+ // The people's own rule, which no definition can say: which person you are (their member) is yours to say, as
2
+ // yourself, and to take back; nobody says it for someone else.
3
+ import type { Trust } from "joined/server";
4
+
5
+ export const trust: Trust = ({ doc, ops }, { member }, read) => {
6
+ const people = (read(doc).people ?? []) as { id: number; member?: number }[];
7
+ for (const o of ops) {
8
+ const [, coll, id, field] = o.path.split("/");
9
+ if (coll !== "people" || field !== "member") continue;
10
+ const now = people.find((p) => p.id === Number(id))?.member;
11
+ if (o.op === "remove" ? now !== member : o.value !== member) return "you say which person you are, as yourself";
12
+ }
13
+ return null;
14
+ };
@@ -0,0 +1,115 @@
1
+ // The people document's view: <j-person>, a person's row, given its colour, its name to change, which person you
2
+ // are, an invitation to the group as them, a way to take it off the list (refused while anything links to it, and
3
+ // why said in its row), its place in the order by a grip (./order.ts), and what links to it (./links.ts). A page
4
+ // adds people by its form (./adding.ts).
5
+
6
+ import { icon, iconButton } from "joined/icons";
7
+ import { hueOf } from "joined/hues";
8
+ import { said } from "joined/parts";
9
+ import { group, members, signedIn } from "joined/panel";
10
+ import { JPerson } from "./generated/elements.ts";
11
+ import { collections } from "./generated/rules.ts";
12
+ import { Links, watchLinks } from "./links.ts";
13
+ import { grip } from "./order.ts";
14
+
15
+ export class Person extends JPerson {
16
+ #name = Object.assign(document.createElement("input"), { ariaLabel: "Name" });
17
+ #links = new Links(this);
18
+ #face = Object.assign(document.createElement("i"), { className: "j-face" }); // in the row's hue
19
+ #you = iconButton("you", "");
20
+ // their place in the order: dragged (held, by a finger), or moved by the arrow keys
21
+ #grip = iconButton("grip", "");
22
+ // someone nobody is yet, invited to the group as them: once they're in, the person is them (people's act, person)
23
+ #invite = Object.assign(document.createElement("button"), { type: "button", className: "act small invite" });
24
+ #invited = Object.assign(document.createElement("span"), { className: "invited", textContent: "Invited" });
25
+ #said = Object.assign(document.createElement("p"), { className: "said", role: "status" }); // a refusal's why
26
+ #gone = iconButton("person-remove", "", () => said(this.#said, this.removeItem()));
27
+ connectedCallback() {
28
+ if (this.childElementCount) return this.draw();
29
+ // renamed, or taken off: refused, why, in its row, and its name as the document has it
30
+ this.#name.addEventListener(
31
+ "change",
32
+ async () =>
33
+ this.#name.value.trim() &&
34
+ (await said(this.#said, this.replace({ name: this.#name.value.trim() }))) &&
35
+ this.draw(),
36
+ );
37
+ this.#gone.classList.add("gone");
38
+ // which person you are: pressed on yours; on someone else's, nothing to press
39
+ this.#you.addEventListener("click", () =>
40
+ said(this.#said, this.data.member === me ? this.removeField("member") : this.replace({ member: me! })),
41
+ );
42
+ this.#invite.append(icon("person-add"), "Invite");
43
+ this.#invite.addEventListener("click", () =>
44
+ said(
45
+ this.#said,
46
+ group()!.add({
47
+ name: this.data.name,
48
+ inviter: me!,
49
+ act: `person ${this.key}`,
50
+ }),
51
+ ),
52
+ );
53
+ this.#grip.classList.add("grip");
54
+ grip(this, this.#grip, (rank) => said(this.#said, this.replace({ rank })));
55
+ this.append(
56
+ this.#grip,
57
+ this.#face,
58
+ this.#name,
59
+ this.#you,
60
+ this.#invite,
61
+ this.#invited,
62
+ this.#gone,
63
+ this.#links.el,
64
+ this.#said,
65
+ );
66
+ this.draw();
67
+ }
68
+ /** Its name, unless it is being changed, and what links to it. */
69
+ draw() {
70
+ if (!this.isConnected) return;
71
+ this.style.setProperty("--hue", hueOf(this.key));
72
+ // its face, by its name as the document has it
73
+ if (this.#face.title !== this.data.name)
74
+ Object.assign(this.#face, { title: this.data.name }).dataset.initial = this.data.name.slice(0, 1);
75
+ if (this.#name !== document.activeElement) this.#name.value = this.data.name;
76
+ const mine = me !== null && this.data.member === me,
77
+ label = mine ? `${this.data.name} is you` : `Say ${this.data.name} is you`;
78
+ const hidden = me === null || (this.data.member !== undefined && !mine) || (!mine && youAre() !== null);
79
+ if (this.#you.hidden !== hidden) this.#you.hidden = hidden;
80
+ if (this.#you.ariaLabel !== label) Object.assign(this.#you, { ariaLabel: label, title: label });
81
+ if (this.#you.ariaPressed !== String(mine)) this.#you.ariaPressed = String(mine);
82
+ const move = `Move ${this.data.name}: drag, or the arrow keys`;
83
+ if (this.#grip.ariaLabel !== move) Object.assign(this.#grip, { ariaLabel: move, title: move });
84
+ const remove = `Remove ${this.data.name}`;
85
+ if (this.#gone.ariaLabel !== remove) Object.assign(this.#gone, { ariaLabel: remove, title: remove });
86
+ // invited and not yet in: said; nobody, and not invited: Invite, to a member who may
87
+ const invited = me !== null && this.data.member === undefined && pending().has(`person ${this.key}`);
88
+ const may = me !== null && this.data.member === undefined && !invited;
89
+ if (this.#invite.hidden !== !may) this.#invite.hidden = !may;
90
+ if (this.#invited.hidden !== !invited) this.#invited.hidden = !invited;
91
+ const asks = `Invite ${this.data.name} to the group, as this person`;
92
+ if (this.#invite.title !== asks) Object.assign(this.#invite, { title: asks, ariaLabel: asks });
93
+ this.#links.draw();
94
+ }
95
+ /** One element's link to it, as it is now: that one link drawn again in its row (./links.ts). */
96
+ linked(el: Element) {
97
+ this.#links.linked(el);
98
+ }
99
+ }
100
+ /** Every person on the page, a live list: read on each change, never a search of the whole page past its events. */
101
+ const persons = document.getElementsByTagName(collections.people.tag) as HTMLCollectionOf<Person>;
102
+ /** The acts the group's invitations still wait to do: once each is in, it's done and gone. */
103
+ const pending = () => new Set([...members].flatMap((m) => (m.data.act ? [m.data.act] : [])));
104
+ /** Who this page is, a member, told by the group's document; and the person who's them, if one is. */
105
+ let me: number | null = null;
106
+ const youAre = () => [...persons].find((p) => p.data.member === me)?.key ?? null;
107
+ const drawAll = () => [...persons].forEach((p) => p.draw());
108
+ watchLinks(persons);
109
+ signedIn((m) => ((me = m), drawAll()));
110
+ // one person said to be you: the people drawn again; and an invitation sent or used, in the group
111
+ new MutationObserver(drawAll).observe(document, { subtree: true, attributeFilter: ["member"] });
112
+ const panel = document.querySelector("members-panel");
113
+ if (panel) new MutationObserver(drawAll).observe(panel, { subtree: true, childList: true, attributeFilter: ["act"] });
114
+ // defined last, once all it draws with is made: those the page has already are drawn as it's defined
115
+ customElements.define(collections.people.tag, Person);
@@ -0,0 +1,11 @@
1
+ // The root: its page, saying what joined is, with the trip's picture and the film on it, and docs/.
2
+
3
+ import { docs } from "./docs.ts";
4
+ import page from "./index.html";
5
+
6
+ export const routes = {
7
+ "/": page,
8
+ "/docs/:file": docs,
9
+ // the film, a file (Bun answers it in ranges, as Safari asks a video), for anyone
10
+ "/film.mp4": new Response(Bun.file(`${import.meta.dir}/film.mp4`)),
11
+ };
@@ -0,0 +1,70 @@
1
+ // The answers in an event's form: a row for each person on it, their face and name, their answer (yes unless said
2
+ // otherwise: ./answers.ts) and whether they come or go there (the line lands them, or sends them home). A change is
3
+ // the form's, until Save.
4
+
5
+ import { hueOf } from "joined/hues";
6
+ import { keep } from "joined/keep";
7
+ import { face } from "joined/parts";
8
+ import { ANSWERS, SAID, type Answer } from "./answers.ts";
9
+
10
+ /** Who among an event's people comes or goes at it. */
11
+ export type Gates = { arrives: Set<number>; leaves: Set<number> };
12
+ /** What the rows read of their form, when drawn and when changed: who's on it, their answers, who comes and goes. */
13
+ type Of = { readonly chosen: readonly number[]; readonly answers: Map<number, Answer>; readonly gates: Gates };
14
+
15
+ export class AnswerRows {
16
+ #kept = new Map<string, { shows: string; el: HTMLElement }>();
17
+
18
+ /** Drawn in `list`, from the form `of`; a change told to `redraw`. */
19
+ constructor(
20
+ readonly list: HTMLElement,
21
+ readonly of: Of,
22
+ readonly redraw: () => void,
23
+ ) {}
24
+
25
+ /** A row each for those chosen, named from `people`: made again only as its name, answer or comings change. */
26
+ draw(people: Map<number, string>) {
27
+ keep(
28
+ this.list,
29
+ this.#kept,
30
+ this.of.chosen.map((key) => {
31
+ const name = people.get(key) ?? "",
32
+ now = this.of.answers.get(key) ?? "yes";
33
+ return {
34
+ key: String(key),
35
+ shows: `${name} ${now} ${this.of.gates.arrives.has(key)} ${this.of.gates.leaves.has(key)}`,
36
+ make: () => this.#row(key, name, now),
37
+ };
38
+ }),
39
+ );
40
+ }
41
+
42
+ /** One person's row: their face and name, a select of their answer, and one of whether they come or go here. */
43
+ #row(key: number, name: string, now: Answer) {
44
+ const row = Object.assign(document.createElement("label"), { className: "answer" });
45
+ row.style.setProperty("--hue", hueOf(key));
46
+ const pick = Object.assign(document.createElement("select"), { ariaLabel: `${name}'s answer` });
47
+ for (const a of ["yes", ...ANSWERS] as Answer[]) pick.append(new Option(SAID[a], a, false, a === now));
48
+ pick.addEventListener("change", () => {
49
+ this.of.answers.set(key, pick.value as Answer);
50
+ this.redraw();
51
+ });
52
+ // whether they come or go here: the line lands them, or sends them home
53
+ const gate = Object.assign(document.createElement("select"), { ariaLabel: `Whether ${name} comes or goes here` });
54
+ const was = `${+this.of.gates.arrives.has(key)}${+this.of.gates.leaves.has(key)}`;
55
+ for (const [v, words] of [
56
+ ["00", "Here"],
57
+ ["10", "Arrives"],
58
+ ["01", "Leaves"],
59
+ ["11", "Arrives, leaves"],
60
+ ])
61
+ gate.append(new Option(words, v, false, v === was));
62
+ gate.addEventListener("change", () => {
63
+ for (const [i, g] of (["arrives", "leaves"] as const).entries())
64
+ gate.value[i] === "1" ? this.of.gates[g].add(key) : this.of.gates[g].delete(key);
65
+ this.redraw();
66
+ });
67
+ row.append(face(key, name), Object.assign(document.createElement("span"), { textContent: name }), pick, gate);
68
+ return row;
69
+ }
70
+ }
@@ -0,0 +1,11 @@
1
+ // A person's answer to an event (Can You's line): being on it is a yes, unless they've said otherwise, keen, still
2
+ // asked, or declined; each answer but yes a list of the people on it who gave it.
3
+
4
+ export const ANSWERS = ["keen", "asked", "declined"] as const;
5
+ export type Answer = "yes" | (typeof ANSWERS)[number];
6
+ type Answered = { keen?: readonly number[]; asked?: readonly number[]; declined?: readonly number[] };
7
+
8
+ /** A person's answer to an event: the list they're on, or yes. */
9
+ export const answerOf = (e: Answered, key: number): Answer => ANSWERS.find((a) => e[a]?.includes(key)) ?? "yes";
10
+ /** An answer in words, as a select offers it. */
11
+ export const SAID: Record<Answer, string> = { yes: "Yes", keen: "Keen", asked: "Asked", declined: "No" };