@blueshed/joined 0.2.1 → 0.3.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 (209) hide show
  1. package/.claude/skills/joined/SKILL.md +9 -1
  2. package/.claude/skills/joined/reference.md +270 -55
  3. package/.claude/skills/joined-door/SKILL.md +57 -0
  4. package/README.md +19 -50
  5. package/docs/design.md +76 -10
  6. package/docs/introduction.md +18 -18
  7. package/docs/light-and-shadow.svg +1 -1
  8. package/examples/README.md +20 -0
  9. package/examples/account/account.json +1 -0
  10. package/examples/account/derive.ts +41 -0
  11. package/examples/account/generated/elements.ts +52 -0
  12. package/examples/account/generated/rows.ts +22 -0
  13. package/examples/account/generated/rules.ts +32 -0
  14. package/examples/account/routes.ts +5 -0
  15. package/examples/app.css +2 -1
  16. package/examples/cafe/books.html +2 -2
  17. package/examples/cafe/cafe.css +9 -16
  18. package/examples/cafe/generated/books.rows.ts +22 -0
  19. package/examples/cafe/generated/books.rules.ts +3 -2
  20. package/examples/cafe/generated/kitchen.rows.ts +27 -0
  21. package/examples/cafe/generated/kitchen.rules.ts +11 -1
  22. package/examples/cafe/generated/menu.rows.ts +22 -0
  23. package/examples/cafe/generated/menu.rules.ts +3 -2
  24. package/examples/cafe/generated/order.rows.ts +27 -0
  25. package/examples/cafe/generated/order.rules.ts +11 -1
  26. package/examples/cafe/generated/staff.rows.ts +22 -0
  27. package/examples/cafe/generated/staff.rules.ts +6 -1
  28. package/examples/cafe/generated/supplies.queries.ts +4 -2
  29. package/examples/cafe/generated/supplies.rows.ts +22 -0
  30. package/examples/cafe/generated/supplies.rules.ts +12 -1
  31. package/examples/cafe/generated/till.queries.ts +2 -0
  32. package/examples/cafe/generated/till.rows.ts +27 -0
  33. package/examples/cafe/generated/till.rules.ts +11 -1
  34. package/examples/cafe/index.html +14 -15
  35. package/examples/cafe/kitchen.ts +1 -1
  36. package/examples/cafe/look.ts +30 -0
  37. package/examples/cafe/menu.html +10 -26
  38. package/examples/cafe/menu.ts +8 -80
  39. package/examples/cafe/order.html +6 -6
  40. package/examples/cafe/order.ts +5 -1
  41. package/examples/cafe/routes.ts +0 -1
  42. package/examples/cafe/stories.jsonl +3 -1
  43. package/examples/cafe/supplies.html +34 -34
  44. package/examples/cafe/supplies.ts +14 -11
  45. package/examples/cafe/till.ts +5 -1
  46. package/examples/chart/arches.ts +148 -0
  47. package/examples/chart/chart.css +6 -0
  48. package/examples/chart/chart.json +87 -0
  49. package/examples/chart/generated/elements.ts +105 -0
  50. package/examples/chart/generated/queries.ts +36 -0
  51. package/examples/chart/generated/rows.ts +27 -0
  52. package/examples/chart/generated/rules.ts +111 -0
  53. package/examples/chart/grid.ts +118 -0
  54. package/examples/chart/index.html +78 -0
  55. package/examples/chart/migrations/001-chart.ts +6 -0
  56. package/examples/chart/migrations/002-create-conditions.ts +6 -0
  57. package/examples/chart/page.ts +20 -0
  58. package/examples/chart/routes.ts +7 -0
  59. package/examples/chart/stories.jsonl +14 -0
  60. package/examples/chart/teeth.ts +57 -0
  61. package/examples/desk/generated/rows.ts +22 -0
  62. package/examples/desk/generated/rules.ts +34 -1
  63. package/examples/desk/index.html +9 -2
  64. package/examples/desk/routes.ts +0 -2
  65. package/examples/desk/stories.jsonl +3 -2
  66. package/examples/desk/thumbs.ts +2 -2
  67. package/examples/hello/generated/elements.ts +2 -2
  68. package/examples/hello/generated/rules.ts +3 -2
  69. package/examples/hello/hello.css +2 -4
  70. package/examples/hello/index.html +10 -3
  71. package/examples/hello/page.ts +4 -4
  72. package/examples/index.html +4 -5
  73. package/examples/notes/generated/elements.ts +112 -0
  74. package/examples/notes/generated/queries.ts +36 -0
  75. package/examples/notes/generated/rows.ts +27 -0
  76. package/examples/notes/generated/rules.ts +133 -0
  77. package/examples/notes/index.html +32 -0
  78. package/examples/notes/look.ts +41 -0
  79. package/examples/notes/migrations/001-notes.ts +7 -0
  80. package/examples/notes/notes.json +78 -0
  81. package/examples/notes/page.ts +21 -0
  82. package/examples/notes/routes.ts +6 -0
  83. package/examples/notes/stories.jsonl +21 -0
  84. package/examples/people/generated/rows.ts +22 -0
  85. package/examples/people/generated/rules.ts +11 -1
  86. package/examples/people/links.ts +2 -1
  87. package/examples/people/routes.ts +1 -3
  88. package/examples/people/stories.jsonl +1 -0
  89. package/examples/people/view.ts +5 -2
  90. package/examples/trip/generated/elements.ts +4 -2
  91. package/examples/trip/generated/queries.ts +12 -1
  92. package/examples/trip/generated/rows.ts +27 -0
  93. package/examples/trip/generated/rules.ts +56 -2
  94. package/examples/trip/index.html +58 -12
  95. package/examples/trip/line.css +186 -0
  96. package/examples/trip/line.ts +51 -40
  97. package/examples/trip/page.ts +65 -71
  98. package/examples/trip/routes.ts +9 -5
  99. package/examples/trip/stays.css +12 -12
  100. package/examples/trip/stays.ts +15 -10
  101. package/examples/trip/stories.jsonl +2 -0
  102. package/examples/trip/told.ts +3 -26
  103. package/examples/trip/trip.css +16 -0
  104. package/examples/trips/generated/rows.ts +22 -0
  105. package/examples/trips/generated/rules.ts +9 -1
  106. package/examples/trips/index.html +10 -10
  107. package/examples/trips/map.ts +3 -14
  108. package/examples/trips/new-trip.ts +14 -16
  109. package/examples/weeks/generated/elements.ts +1 -1
  110. package/examples/weeks/generated/queries.ts +11 -0
  111. package/examples/weeks/generated/rows.ts +22 -0
  112. package/examples/weeks/generated/rules.ts +11 -5
  113. package/examples/weeks/routes.ts +3 -2
  114. package/examples/weeks/stories.jsonl +1 -0
  115. package/examples/welcome.css +7 -5
  116. package/package.json +8 -2
  117. package/src/awesome.ts +103 -0
  118. package/src/board.css +75 -0
  119. package/src/board.ts +173 -0
  120. package/src/cli.ts +15 -2
  121. package/src/compile.ts +569 -35
  122. package/src/definitions.ts +53 -15
  123. package/src/draft.ts +38 -23
  124. package/src/drawer.ts +222 -0
  125. package/src/engine.ts +240 -166
  126. package/src/fields.ts +268 -0
  127. package/src/files.ts +6 -4
  128. package/src/ground.ts +110 -0
  129. package/src/icon-names.ts +15 -2
  130. package/src/kit.ts +51 -0
  131. package/src/link.ts +3 -3
  132. package/src/map.css +133 -0
  133. package/src/map.ts +200 -0
  134. package/src/mcp.ts +176 -38
  135. package/src/members/demo.ts +13 -12
  136. package/src/members/generated/rows.ts +22 -0
  137. package/src/members/generated/rules.ts +3 -2
  138. package/src/members/group.ts +65 -39
  139. package/src/members/keys.ts +93 -77
  140. package/src/members/panel.css +23 -17
  141. package/src/members/panel.ts +49 -35
  142. package/src/migrate.ts +120 -104
  143. package/src/month.css +125 -0
  144. package/src/month.ts +179 -0
  145. package/src/page.css +8 -0
  146. package/src/page.ts +11 -7
  147. package/src/parts.css +462 -170
  148. package/src/parts.ts +209 -26
  149. package/src/plane.css +56 -0
  150. package/src/plane.ts +151 -0
  151. package/src/postgres-server.ts +60 -0
  152. package/src/reading.css +77 -0
  153. package/src/reading.ts +238 -0
  154. package/src/rows.css +308 -0
  155. package/src/rows.ts +780 -0
  156. package/src/search.css +80 -0
  157. package/src/search.ts +130 -0
  158. package/src/server.ts +211 -114
  159. package/src/settings.ts +9 -4
  160. package/src/sheet.ts +114 -0
  161. package/src/skill.ts +40 -0
  162. package/src/slots.css +94 -0
  163. package/src/slots.ts +213 -0
  164. package/src/specs.ts +38 -0
  165. package/src/starter.ts +5 -2
  166. package/src/store.ts +184 -143
  167. package/src/stories.ts +43 -11
  168. package/src/surface.ts +159 -0
  169. package/src/timeline.css +111 -0
  170. package/src/timeline.ts +226 -0
  171. package/src/toast.ts +21 -48
  172. package/src/together.ts +0 -7
  173. package/src/tokens.css +78 -1
  174. package/src/tokens.json +249 -0
  175. package/src/tool.ts +211 -0
  176. package/src/upkeep.ts +18 -20
  177. package/src/views.css +44 -0
  178. package/src/views.ts +94 -0
  179. package/src/week.css +151 -0
  180. package/src/week.ts +250 -0
  181. package/src/write.ts +219 -73
  182. package/starter/CLAUDE.md +3 -3
  183. package/starter/bunfig +4 -0
  184. package/starter/prettierignore +4 -0
  185. package/starter/tests/hello.test.ts +2 -0
  186. package/docs/learning.md +0 -76
  187. package/examples/cafe/trust.ts +0 -20
  188. package/examples/desk/trust.ts +0 -24
  189. package/examples/people/trust.ts +0 -14
  190. package/examples/trip/answer-rows.ts +0 -70
  191. package/examples/trip/bar.ts +0 -89
  192. package/examples/trip/calendar-map.css +0 -711
  193. package/examples/trip/calendar-map.ts +0 -249
  194. package/examples/trip/drags.ts +0 -143
  195. package/examples/trip/drawer.ts +0 -250
  196. package/examples/trip/event-form.ts +0 -200
  197. package/examples/trip/holding.ts +0 -61
  198. package/examples/trip/map.ts +0 -234
  199. package/examples/trip/month.ts +0 -87
  200. package/examples/trip/other-weeks.ts +0 -67
  201. package/examples/trip/peek.ts +0 -71
  202. package/examples/trip/people-chips.ts +0 -74
  203. package/examples/trip/shell.ts +0 -39
  204. package/examples/trip/trust.ts +0 -51
  205. package/examples/trip/week.ts +0 -237
  206. package/examples/trip/writes.ts +0 -91
  207. package/examples/trip/zones.ts +0 -16
  208. package/examples/weeks/derive.ts +0 -23
  209. package/src/scrim.ts +0 -81
@@ -1,71 +0,0 @@
1
- // A pin peeked, on a phone, in <calendar-map>'s map (./map.ts): a card by it saying what, when, where and who, to grow
2
- // into the drawer, or to close (its Close, Escape, or a tap on the map). Under its pin, or over it where there's no
3
- // room below, within the map's sides; with room for it neither way, the map moves.
4
-
5
- import type { JEvent } from "./generated/elements.ts";
6
- import type { MapView } from "./map.ts";
7
- import type { Part } from "./shell.ts";
8
- import { hueOf } from "joined/hues";
9
- import { DAY, dated, hours, wall } from "joined/time";
10
-
11
- /** What the card reads from its display: the people by key, and how to pick an event. */
12
- type From = { people: () => Map<number, string>; pick: (el: JEvent) => void };
13
-
14
- export class Peek {
15
- /** The event peeked, or none. */
16
- peeked: JEvent | null = null;
17
- #card: HTMLElement;
18
- #map: MapView;
19
- #from: From;
20
-
21
- /** The card, in the map; it listens for Escape in `root` until `signal` lets it go. */
22
- constructor($: Part, map: MapView, from: From, root: ShadowRoot, signal: AbortSignal) {
23
- [this.#card, this.#map, this.#from] = [$(".peek"), map, from];
24
- // grown into the drawer, or closed
25
- $("[name=grow]").addEventListener("click", () => {
26
- const el = this.peeked;
27
- this.show(null);
28
- if (el) from.pick(el);
29
- });
30
- $("[name=unpeek]").addEventListener("click", () => this.show(null));
31
- root.addEventListener("keydown", (e) => (e as KeyboardEvent).key === "Escape" && this.peeked && this.show(null), {
32
- signal,
33
- });
34
- }
35
-
36
- /** An event's card shown by its pin; null closes it. */
37
- show(el: JEvent | null) {
38
- const card = this.#card;
39
- this.#map.peeked(el);
40
- this.peeked = el;
41
- card.hidden = !el;
42
- if (!el) return;
43
- const { title, start, duration, location, people = [] } = el.data,
44
- names = this.#from.people(),
45
- at = wall(start),
46
- who = people.map((k) => names.get(k)).filter(Boolean) as string[];
47
- card.style.setProperty("--hue", hueOf(el.key));
48
- card.ariaLabel = title;
49
- card.querySelector("b")!.textContent = title;
50
- card.querySelector(".when")!.textContent =
51
- `${dated(Math.floor(at / DAY), { weekday: "short", day: "numeric", month: "short" })} · ${hours(start, duration)}`;
52
- card.querySelector(".where")!.textContent = location ?? "";
53
- card.querySelector(".who")!.textContent = who.join(", ");
54
- // under its pin, or over it where there's no room below; within the map's sides
55
- const map = this.#map,
56
- pin = map.pinOf(el)!,
57
- w = card.offsetWidth,
58
- h = card.offsetHeight,
59
- W = map.el.clientWidth,
60
- H = map.el.clientHeight;
61
- // no room above it or below: the map moves, the pin near its top, the card under it
62
- if (pin.offsetTop + 18 + h > H && pin.offsetTop - 18 - h < 8)
63
- map.look({ ...map.view, y: map.view.y + pin.offsetTop - 30 });
64
- const x = pin.offsetLeft,
65
- y = pin.offsetTop,
66
- below = y + 18 + h <= H;
67
- card.style.left = `${Math.max(8, Math.min(W - w - 8, x - w / 2))}px`;
68
- card.style.top = `${Math.max(8, Math.min(H - h - 8, below ? y + 18 : y - 18 - h))}px`;
69
- card.querySelector<HTMLButtonElement>("[name=grow]")!.focus();
70
- }
71
- }
@@ -1,74 +0,0 @@
1
- // The people on an event, in its form (docs/design.md, "Choosing"): six or fewer, a chip each to press, pressed where
2
- // the event links to them, a press linking or unlinking; more, a chip each for those it links to, its × to take them
3
- // off, and the rest found by typing. A press changes who the form has chosen, not the event, until Save.
4
-
5
- import { iconButton } from "joined/icons";
6
- import { hueOf } from "joined/hues";
7
- import { keep } from "joined/keep";
8
- import { chip, face, typeahead } from "joined/parts";
9
-
10
- const MANY = 6; // more people than this, and they're found by typing
11
-
12
- /** What the chips ask of their form: who may be chosen, who is, and how to choose. */
13
- type Of = { people(): Map<number, string>; chosen(): readonly number[]; choose(chosen: number[]): void };
14
-
15
- export class PeopleChips {
16
- #kept = new Map<string, { shows: string; el: HTMLElement }>();
17
- #chips: HTMLElement;
18
- #someone: HTMLElement;
19
- #ask: () => void;
20
-
21
- /** Drawn in the form's `.j-chips`; past six people, typed for in its `.someone`. */
22
- constructor(
23
- form: HTMLElement,
24
- readonly of: Of,
25
- ) {
26
- this.#chips = form.querySelector(".j-chips")!;
27
- this.#someone = form.querySelector(".someone")!;
28
- // past six people, who isn't on it yet, found by typing
29
- this.#ask = typeahead(
30
- this.#someone.querySelector("input")!,
31
- this.#someone.querySelector<HTMLElement>(".j-choices")!,
32
- () => [...of.people()].filter(([key]) => !of.chosen().includes(key)),
33
- (key) => of.choose([...of.chosen(), key]),
34
- );
35
- }
36
-
37
- /** The chips for `people`, as the form has them chosen: a chip made again only as its name or its press changes. */
38
- draw(people: Map<number, string>) {
39
- const many = people.size > MANY;
40
- // who's chosen is read when a chip is pressed: a chip is kept while its name and its press are
41
- const chosen = () => this.of.chosen();
42
- this.#someone.hidden = !many;
43
- if (many) this.#ask();
44
- keep(
45
- this.#chips,
46
- this.#kept,
47
- [...people]
48
- .filter(([key]) => !many || chosen().includes(key))
49
- .map(([key, name]) => ({
50
- key: String(key),
51
- shows: `${name} ${chosen().includes(key)} ${many}`,
52
- make: () => {
53
- if (many) {
54
- const one = chip(key, name);
55
- one.append(
56
- iconButton("close", `Take ${name} off`, () => this.of.choose(chosen().filter((k) => k !== key))),
57
- );
58
- return one;
59
- }
60
- // six or fewer: each a chip to press (People chips), pressed where they're on it
61
- const press = Object.assign(document.createElement("button"), { type: "button" });
62
- press.style.setProperty("--hue", hueOf(key));
63
- press.append(face(key, name), name);
64
- press.setAttribute("aria-pressed", String(chosen().includes(key)));
65
- press.addEventListener("click", () => {
66
- const now = chosen();
67
- this.of.choose(now.includes(key) ? now.filter((k) => k !== key) : [...now, key]);
68
- });
69
- return press;
70
- },
71
- })),
72
- );
73
- }
74
- }
@@ -1,39 +0,0 @@
1
- // The shadow <calendar-map> draws in: its look (./calendar-map.css, one sheet shared by every calendar on the page,
2
- // over joined's parts), the sizes its stylesheet draws by, and its parts, each found once by the one that draws it:
3
- // the bar, a phone's strip of the week's days, the map (its tiles, a peeked pin's card, nearer and farther), the
4
- // calendar (its ruler and days), the line, the month, the other weeks, the drawer, the modal, and the modal that asks
5
- // before Remove.
6
-
7
- import { adopt } from "joined/parts";
8
- import { HOUR } from "./week.ts";
9
- import { MAP_H } from "./map.ts";
10
- import { TILE } from "joined/geo";
11
- import STYLE from "./calendar-map.css" with { type: "text" };
12
-
13
- /** One of the shadow's parts, found once (the display keeps them): its parts are found by it, never searched for on
14
- * a change. */
15
- export type Part = (selector: string) => HTMLElement;
16
-
17
- const SHEET = new CSSStyleSheet();
18
- SHEET.replaceSync(STYLE);
19
- const DAYS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
20
- const HTML = `
21
- <div class="top"><button type="button" class="icon-only" name="back" title="The week before" aria-label="The week before" data-icon="back"></button><h2 class="week"></h2><button type="button" class="icon-only" name="on" title="The week after" aria-label="The week after" data-icon="on"></button><span class="views" role="group" aria-label="Read as"><button type="button" class="act" name="calendar" data-icon="calendar">Calendar</button><button type="button" class="act" name="line" data-icon="line">Line</button><button type="button" class="act" name="month" data-icon="month">Month</button></span><button type="button" class="act ink" name="new" data-icon="add">Add</button></div>
22
- <div class="strip" role="group" aria-label="The week's days"></div>
23
- <div class="map"><div class="tiles"></div><div class="peek" role="dialog" hidden><header><b></b></header><p class="when"></p><p class="where"></p><p class="who"></p><footer><button type="button" class="act quiet" name="grow" data-icon="grow">Grow</button><button type="button" class="act quiet" name="unpeek" data-icon="close">Close</button></footer></div><div class="zoom"><button type="button" class="icon-only" name="nearer" data-icon="zoom-in" title="Nearer" aria-label="Nearer"></button><button type="button" class="icon-only" name="farther" data-icon="zoom-out" title="Farther" aria-label="Farther"></button></div><small>© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a></small></div>
24
- <div class="when"><div class="cal"><div class="ruler"></div><div class="days"></div></div><div class="reading" hidden><div class="faces j-chips" role="group" aria-label="Whose line"></div><ol class="line" aria-label="The week, day by day"></ol></div><div class="month" hidden><div class="names">${DAYS.map((d) => `<span>${d}</span>`).join("")}</div><div class="cells"></div></div><p class="others" hidden></p></div>
25
- <aside class="drawer" hidden></aside>
26
- <dialog class="modal"></dialog>
27
- <dialog class="modal ask"><h2></h2><footer><button type="button" class="act" name="keep">Never mind</button><button type="button" class="act danger" name="sure" data-icon="remove">Remove</button></footer></dialog>`;
28
-
29
- /** The display's shadow made afresh: its look, its sizes, and its parts, empty until they're drawn. */
30
- export function shell(host: HTMLElement, root: ShadowRoot) {
31
- adopt(root, SHEET);
32
- for (const [name, px] of [
33
- ["--hour", HOUR],
34
- ["--tile", TILE],
35
- ["--map-h", MAP_H],
36
- ] as const)
37
- host.style.setProperty(name, `${px}px`);
38
- root.innerHTML = HTML;
39
- }
@@ -1,51 +0,0 @@
1
- // The trip's own rule, which no definition can say: an answer to an event (keen, asked, declined; yes is being on it
2
- // and saying none of them) is from someone on it, and each person gives one; and who comes or goes at an event
3
- // (arrives, leaves: the line lands them there, or sends them home) is on it. Held to each event as the write leaves it.
4
- import type { Trust } from "joined/server";
5
- import { ANSWERS } from "./answers.ts";
6
-
7
- const GATES = ["arrives", "leaves"] as const;
8
- const LISTS = [...ANSWERS, ...GATES];
9
- type List = "people" | (typeof LISTS)[number];
10
- type Event = { id: number } & { [l in List]?: number[] };
11
-
12
- export const trust: Trust = ({ doc, ops }, _who, read) => {
13
- const touched = new Map<number, Event>();
14
- const events = () => (read(doc.split("?")[0]!).events ?? []) as Event[];
15
- const at = (id: number) => {
16
- if (!touched.has(id)) {
17
- const e = events().find((x) => x.id === id);
18
- touched.set(id, {
19
- ...e,
20
- id,
21
- people: [...(e?.people ?? [])],
22
- ...Object.fromEntries(LISTS.map((a) => [a, [...(e?.[a] ?? [])]])),
23
- });
24
- }
25
- return touched.get(id)!;
26
- };
27
- for (const o of ops) {
28
- const [, coll, id, field, which] = o.path.split("/");
29
- if (coll !== "events") continue;
30
- if (id === "-") {
31
- // an event added whole: its own lists
32
- const v = o.value as Event;
33
- if (LISTS.some((a) => v[a]?.length)) touched.set(-touched.size - 1, { ...v, id: -1 });
34
- continue;
35
- }
36
- const list = field as List;
37
- if (list !== "people" && !LISTS.includes(list as never)) continue;
38
- const e = at(Number(id));
39
- if (o.op === "replace" && which === undefined) e[list] = [...(o.value as number[])];
40
- else if (o.op === "add" && which === "-") e[list] = [...(e[list] ?? []), o.value as number];
41
- else if (o.op === "remove") e[list] = which === undefined ? [] : (e[list] ?? []).filter((k) => k !== Number(which));
42
- }
43
- for (const e of touched.values()) {
44
- const on = (k: number) => (e.people ?? []).includes(k);
45
- const given = ANSWERS.flatMap((a) => e[a] ?? []);
46
- if (!given.every(on)) return "an answer is from someone on the event";
47
- if (new Set(given).size !== given.length) return "one answer each";
48
- if (!GATES.every((g) => (e[g] ?? []).every(on))) return "who comes or goes at an event is on it";
49
- }
50
- return null;
51
- };
@@ -1,237 +0,0 @@
1
- // The week as a calendar, drawn by <calendar-map>: a ruler of its hours and its seven days, each event a block on its
2
- // day from its start for its length, and past midnight the rest of it on each day after, saying until when. A block
3
- // is made once, then only moved. Its hours are the day's waking ones, and any its events need. On a phone it's a strip
4
- // of the week's days with one day shown, its hours and its places: a day pressed in the strip shows it, as picking an
5
- // event shows its day. A press on a block picks its event, and a drag moves it, or by its foot changes its length; a
6
- // drag on a day's hours is a new event's range (./drags.ts).
7
-
8
- import type { JEvent } from "./generated/elements.ts";
9
- import type { Drags } from "./drags.ts";
10
- import type { Shown } from "./drawer.ts";
11
- import type { Part } from "./shell.ts";
12
- import { held } from "joined/follow";
13
- import { hueOf } from "joined/hues";
14
- import { keep } from "joined/keep";
15
- import { face } from "joined/parts";
16
- import { DAY, dated, dayOf, hhmm, hours, MIN, on, seconds, wall } from "joined/time";
17
-
18
- export const HOUR = 36,
19
- EARLY = 6, // the hours a week shows, more if its events need them
20
- LATE = 22;
21
- type Kept = Map<string, { shows: string; el: HTMLElement }>;
22
-
23
- /** What the week reads from its display: the week and hours it's drawn on, the day a phone shows (and the week it was
24
- * chosen in), its events and the one picked, and what a press does. */
25
- type From = {
26
- at: () => { week: number; from: number; to: number };
27
- chose: { day: number; dayWeek: number | null };
28
- events: () => JEvent[];
29
- picked: () => JEvent | null;
30
- pick: (el: JEvent) => void;
31
- changed: () => void;
32
- drags: () => Drags;
33
- };
34
-
35
- /** A block's words: its title, and from when to when. */
36
- export function label(block: HTMLElement, title: string, start: string, duration: string) {
37
- block.querySelector("b")!.textContent = title;
38
- block.querySelector("span")!.textContent = hours(start, duration);
39
- }
40
-
41
- export class Week {
42
- #blocks = new Map<JEvent, { block: HTMLElement; who: Kept; rests: HTMLElement[] }>();
43
- #host: HTMLElement;
44
- #ruler: HTMLElement;
45
- #days: HTMLElement;
46
- #strip: HTMLElement;
47
- #from: From;
48
-
49
- /** Drawn in its parts; `host` is the display, the span of its hours (--span) set on it. */
50
- constructor(host: HTMLElement, $: Part, from: From) {
51
- [this.#host, this.#ruler, this.#days, this.#strip, this.#from] = [host, $(".ruler"), $(".days"), $(".strip"), from];
52
- this.#strip.addEventListener("click", (e) => {
53
- const b = (e.target as Element).closest<HTMLButtonElement>("button");
54
- if (b) ((from.chose.day = Number(b.value)), from.changed());
55
- });
56
- this.#days.addEventListener(
57
- "pointerdown",
58
- (e) => (e.target as Element).classList.contains("hours") && held(e, () => from.drags().range(e)),
59
- );
60
- }
61
-
62
- /** The hours the week shows, from the events it shows (a phone's day's, else the week's), which it gives back. A week
63
- * newly shown, once its events are here, shows its first day with one, or the picked event's. */
64
- hours(events: JEvent[], week: number, phone: boolean) {
65
- const { chose } = this.#from;
66
- if (chose.dayWeek !== week && events.length) {
67
- const el = this.#from.picked(),
68
- picked = el && dayOf(el.data.start) - week;
69
- chose.day =
70
- picked !== null && picked >= 0 && picked < 7
71
- ? picked
72
- : Math.max(
73
- 0,
74
- events.reduce((least, el) => Math.min(least, dayOf(el.data.start) - week), Infinity),
75
- );
76
- chose.dayWeek = week;
77
- }
78
- const shown = phone ? events.filter((el) => on(el.data, week + chose.day)) : events;
79
- // the day's waking hours, and any its events need
80
- let from = EARLY,
81
- to = LATE;
82
- for (const el of shown) {
83
- const h = (wall(el.data.start) % DAY) / MIN / 60,
84
- end = h + seconds(el.data.duration) / 3600;
85
- from = Math.min(from, Math.floor(h), end > 24 ? 0 : 24);
86
- to = Math.max(to, Math.min(24, Math.ceil(end)));
87
- }
88
- return { shown, from, to };
89
- }
90
-
91
- /** Its frame, for the week and hours it's on: the ruler, the days (their blocks placed after) and the strip. */
92
- draw() {
93
- const { week, from, to } = this.#from.at();
94
- this.#host.style.setProperty("--span", String(to - from));
95
- this.#ruler.innerHTML = `<h3></h3><div>${Array.from({ length: Math.ceil((to - from) / 2) }, (_, i) => `<span style="top: ${i * 2 * HOUR}px">${String(from + i * 2).padStart(2, "0")}:00</span>`).join("")}</div>`;
96
- this.#days.replaceChildren(
97
- ...Array.from({ length: 7 }, (_, i) => {
98
- const day = Object.assign(document.createElement("div"), { className: "day" });
99
- day.innerHTML = `<h3>${dated(week + i, { weekday: "short", day: "numeric" })}</h3><div class="hours"></div>`;
100
- return day;
101
- }),
102
- );
103
- this.#strip.replaceChildren(
104
- ...Array.from({ length: 7 }, (_, i) => {
105
- const b = Object.assign(document.createElement("button"), { type: "button", value: String(i) });
106
- b.ariaLabel = dated(week + i, { weekday: "long", day: "numeric", month: "long" });
107
- b.innerHTML = `<span>${dated(week + i, { weekday: "short" })}</span><b>${dated(week + i, { day: "numeric" })}</b>`;
108
- return b;
109
- }),
110
- );
111
- }
112
-
113
- /** An event's block on its day (and the rest of it on the days after): made once, then only moved. */
114
- place(el: JEvent, shown: Shown, names: Map<number, string>) {
115
- let drawn = this.#blocks.get(el);
116
- if (!drawn) {
117
- const block = Object.assign(document.createElement("div"), {
118
- className: "block",
119
- innerHTML: `<b></b><span></span><span class="who"></span><span class="grip"></span>`,
120
- });
121
- this.#press(block, el);
122
- this.#blocks.set(el, (drawn = { block, who: new Map(), rests: [] }));
123
- }
124
- const { block } = drawn;
125
- const { title, start, duration, location, people = [] } = shown;
126
- const who = people.filter((k) => names.has(k));
127
- block.style.setProperty("--hue", hueOf(el.key));
128
- label(block, title, start, duration);
129
- block.title = [title, location, who.map((k) => names.get(k)).join(", ")].filter(Boolean).join(" · ");
130
- keep(
131
- block.querySelector(".who")!,
132
- drawn.who,
133
- who.map((k) => ({
134
- key: String(k),
135
- shows: names.get(k)!,
136
- make: () => face(k, names.get(k)!, true),
137
- })),
138
- );
139
- this.when(block, wall(start), seconds(duration) / 60);
140
- this.#rest(el, drawn.rests, title, wall(start), seconds(duration) / 60);
141
- }
142
-
143
- /** What an event runs into past midnight: a block on each day after its first, from midnight to its end (or the
144
- * day's), saying until when; a press on one is a press on the event. */
145
- /** A block, or its rest, pressed: held, it's dragged (by its grip, its length); tapped, picked. */
146
- #press(block: HTMLElement, el: JEvent) {
147
- block.addEventListener("pointerdown", (e) =>
148
- held(
149
- e,
150
- () => this.#from.drags().block(el, e, (e.target as Element).classList.contains("grip")),
151
- undefined,
152
- () => this.#from.pick(el),
153
- ),
154
- );
155
- }
156
- #rest(el: JEvent, rests: HTMLElement[], title: string, from: number, mins: number) {
157
- const end = from + mins * MIN,
158
- days: number[] = [];
159
- for (let d = Math.floor(from / DAY) + 1; d * DAY < end; d++) days.push(d);
160
- while (rests.length > days.length) rests.pop()!.remove();
161
- while (rests.length < days.length) {
162
- const r = Object.assign(document.createElement("div"), {
163
- className: "block rest",
164
- innerHTML: "<b></b><span></span>",
165
- });
166
- this.#press(r, el);
167
- r.toggleAttribute("picked", el === this.#from.picked());
168
- rests.push(r);
169
- }
170
- days.forEach((d, i) => {
171
- const r = rests[i]!,
172
- until = Math.min(end, (d + 1) * DAY);
173
- r.style.setProperty("--hue", hueOf(el.key));
174
- r.querySelector("b")!.textContent = title;
175
- r.querySelector("span")!.textContent = until === (d + 1) * DAY ? "all day" : `until ${hhmm(until)}`;
176
- this.when(r, d * DAY, (until - d * DAY) / MIN);
177
- });
178
- }
179
-
180
- /** A block on the day it starts, from its start for its length, within the hours shown. */
181
- when(block: HTMLElement, from: number, mins: number) {
182
- const at = this.#from.at(),
183
- into = (from % DAY) / MIN - at.from * 60;
184
- block.style.top = `${(into / 60) * HOUR}px`;
185
- block.style.height = `${Math.max(14, (Math.min(mins, at.to * 60 - (from % DAY) / MIN) / 60) * HOUR - 2)}px`;
186
- const hours = this.#days.children[Math.floor(from / DAY) - at.week]?.querySelector(".hours");
187
- if (!hours)
188
- block.remove(); // not on this week
189
- else if (block.parentNode !== hours) hours.append(block);
190
- }
191
-
192
- /** The strip of the week's days (a phone's), the day shown pressed and those with events in ink; on a phone, only
193
- * that day's column. */
194
- showDay() {
195
- const { week } = this.#from.at(),
196
- { day } = this.#from.chose,
197
- busy = new Set(this.#from.events().map((el) => dayOf(el.data.start) - week));
198
- [...this.#strip.children].forEach((b, i) => {
199
- b.setAttribute("aria-pressed", String(i === day));
200
- b.classList.toggle("busy", busy.has(i));
201
- });
202
- [...this.#days.children].forEach((d, i) => d.toggleAttribute("shown", i === day));
203
- }
204
- /** The day shown (a phone's) moved to an event's, if it isn't shown: whether it moved. */
205
- follow(el: JEvent) {
206
- const day = dayOf(el.data.start) - this.#from.at().week;
207
- if (day < 0 || day > 6 || day === this.#from.chose.day) return false;
208
- this.#from.chose.day = day;
209
- return true;
210
- }
211
-
212
- /** The time under a pointer on the calendar: its day's, at its height, within the hours shown. */
213
- timeAt(e: PointerEvent) {
214
- // the day under it, of those shown (a phone shows one)
215
- const days = [...this.#days.children] as HTMLElement[],
216
- shown = days.filter((d) => d.offsetWidth),
217
- day = shown.find((d) => e.clientX < d.getBoundingClientRect().right) ?? shown.at(-1)!,
218
- i = days.indexOf(day),
219
- top = day.querySelector(".hours")!.getBoundingClientRect().top;
220
- const { week, from, to } = this.#from.at();
221
- const mins = Math.max(from * 60, Math.min(to * 60, from * 60 + ((e.clientY - top) / HOUR) * 60));
222
- return (week + i) * DAY + mins * MIN;
223
- }
224
-
225
- /** An event's block, if it's drawn. */
226
- blockOf = (el: JEvent) => this.#blocks.get(el)?.block;
227
- /** The picked event's block and its rest marked, the others not. */
228
- mark(picked: JEvent | null) {
229
- for (const [e, { block, rests }] of this.#blocks)
230
- for (const part of [block, ...rests]) part.toggleAttribute("picked", e === picked);
231
- }
232
- /** The blocks of events no longer in `list` (gone, or on another week) taken away. */
233
- drop(list: Node | null) {
234
- for (const [el, { block, rests }] of this.#blocks)
235
- if (el.parentNode !== list) (block.remove(), rests.forEach((r) => r.remove()), this.#blocks.delete(el));
236
- }
237
- }
@@ -1,91 +0,0 @@
1
- // The writes <calendar-map>'s form sends (./drawer.ts): the picked event's changes, an emptied place removed and the
2
- // rest in one write, who comes or goes linked and unlinked as the stories write them; and a new event, added. Each
3
- // is the event element's own ops. Refused, why is said in the form, which keeps what it holds, to be saved again or
4
- // put back, and nothing is drawn as saved that wasn't; done is nothing, as the change shows. An event kept on
5
- // another week is opened there.
6
-
7
- import type { JEvent, JEvents, JEventValue } from "./generated/elements.ts";
8
- import type { EventForm, Input } from "./event-form.ts";
9
- import type { Answer } from "joined/page";
10
- import { ANSWERS } from "./answers.ts";
11
- import { dayOf, mondayOf } from "joined/time";
12
-
13
- /** What the writes read from the drawer and its display: how to say why, draw all again, ask for a new event again
14
- * (and draw it) and close the modal; the events' list, the week shown, whether a week is held and how to go to one;
15
- * and the event kept on another week, to open there once it's held. */
16
- type From = {
17
- say: (why: string) => void;
18
- placeAll: () => void;
19
- new: (given: Partial<Record<Input, string>>) => void;
20
- redraw: () => void;
21
- close: () => void;
22
- list: () => JEvents | null;
23
- at: () => { week: number };
24
- holds: (day: number) => boolean;
25
- go: (week: number) => void;
26
- moving: (moved: { key: number; week: number } | null) => void;
27
- };
28
-
29
- export class Writes {
30
- #form: EventForm;
31
- #from: From;
32
-
33
- /** Sent from `form`. */
34
- constructor(form: EventForm, from: From) {
35
- [this.#form, this.#from] = [form, from];
36
- }
37
-
38
- /** A write sent: refused, why, in the form, and everything drawn from the document again. Whether it was done. */
39
- async answered(request: Promise<Answer> | undefined) {
40
- const why = await request;
41
- if (why) (this.#from.say(why), this.#from.placeAll());
42
- return !why;
43
- }
44
- /** The picked event's changes, as the form has them. */
45
- async save(el: JEvent) {
46
- const { replaced, removed } = this.#form.edits(el.data),
47
- gates = this.#form.gateEdits(el.data);
48
- if (removed.length) this.answered(el.removeField(...removed));
49
- // who comes or goes, each id linked or unlinked as the stories write them: those going off it before it changes,
50
- // so nobody comes or goes at an event they're not on; those coming, once they're on it
51
- for (const { g, k } of gates.filter((x) => !x.on)) await this.answered(el.unlink(g, k));
52
- const linking = () => Promise.all(gates.filter((x) => x.on).map(({ g, k }) => this.answered(el.link(g, k))));
53
- if (!Object.keys(replaced).length) return void linking();
54
- // moved off the week: known before it's told gone, which may come before the answer
55
- const week = replaced.start ? mondayOf(dayOf(replaced.start)) : this.#from.at().week;
56
- if (!this.#from.holds(week)) this.#from.moving({ key: el.key, week });
57
- const ok = await this.answered(el.replace(replaced));
58
- await linking();
59
- if (ok) this.#from.go(week);
60
- else this.#from.moving(null);
61
- }
62
- /** The new event, as the form has it: sent, the modal closes, and the event comes as its change; refused, it's asked
63
- * again as it was, saying why. */
64
- async add() {
65
- const form = this.#form,
66
- { title, start, duration, zone, location, coordinates } = form.formed();
67
- const typed = form.values(),
68
- chosen = form.chosen;
69
- this.#from.close();
70
- const why = await this.#from.list()!.add({
71
- title,
72
- ...(start ? { start, duration } : {}),
73
- ...(zone ? { zone } : {}),
74
- ...(location ? { location } : {}),
75
- ...(coordinates ? { coordinates } : {}),
76
- ...(form.chosen.length ? { people: form.chosen } : {}),
77
- ...Object.fromEntries(ANSWERS.map((a) => [a, form.answered(a)]).filter(([, ks]) => ks!.length)),
78
- ...Object.fromEntries(
79
- (["arrives", "leaves"] as const)
80
- .map((g) => [g, [...form.gates[g]].sort((a, b) => a - b)])
81
- .filter(([, ks]) => ks!.length),
82
- ),
83
- } as JEventValue);
84
- if (!why) return void (start && this.#from.go(mondayOf(dayOf(start))));
85
- this.#from.new(typed);
86
- form.chosen = chosen;
87
- form.chips();
88
- this.#from.redraw();
89
- this.#from.say(why);
90
- }
91
- }
@@ -1,16 +0,0 @@
1
- // The time zone an event's clock is in: one the world names, as this browser knows them, found by typing in the
2
- // event's form (docs/design.md, "Choosing": there are hundreds, too many to offer as chips).
3
-
4
- import { typeahead } from "joined/parts";
5
-
6
- /** The time zones the world names, as this browser knows them. */
7
- const ZONES = ["UTC", ...Intl.supportedValuesOf("timeZone")];
8
-
9
- /** A zone's field: the zones holding what's typed offered beneath it in `list`; one picked is told to `pick`. */
10
- export const zones = (field: HTMLInputElement, list: HTMLElement, pick: (zone: string) => void) =>
11
- typeahead(
12
- field,
13
- list,
14
- () => ZONES.map((z, i) => [i, z]),
15
- (i) => pick(ZONES[i]!),
16
- );
@@ -1,23 +0,0 @@
1
- // The weeks of each trip a member is on (../trips), and how many of its events each holds, derived from the trips:
2
- // a trip's page holds one week (trip:1?week=2026-11-02), and says beneath it what's on its other weeks, a way to
3
- // each. Read as the member sees each trip, so a trip they aren't on has no weeks of theirs; again on a write to one.
4
-
5
- import type { Read } from "joined/server";
6
- import { weekOf } from "joined/time";
7
-
8
- export const doc = "weeks";
9
- export const from = ["trips", "trip"];
10
-
11
- export function derive(read: Read, member: number) {
12
- const weeks: { id: number; trip: number; week: string; events: number }[] = [];
13
- for (const { id } of read("trips", member).trips as { id: number }[]) {
14
- const held = new Map<string, number>();
15
- for (const e of read(`trip:${id}`, member).events as { start: string }[]) {
16
- const week = weekOf(e.start);
17
- held.set(week, (held.get(week) ?? 0) + 1);
18
- }
19
- for (const [week, events] of [...held].sort(([a], [b]) => a.localeCompare(b)))
20
- weeks.push({ id: weeks.length + 1, trip: id, week, events });
21
- }
22
- return { weeks };
23
- }