@blueshed/joined 0.2.2 → 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 +267 -53
  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 +106 -22
  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 +7 -4
  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 +205 -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 +202 -69
  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,200 +0,0 @@
1
- // The trip's form: one event's fields, in <calendar-map>'s drawer to change the picked event, or in its
2
- // modal to add one. It holds what's typed, dragged on the week or tapped on the map (a Draft, joined/draft)
3
- // until Save, and what it holds, the display draws (its host's redraw): the picked event where the form puts it.
4
- // Its parts are their own: the time zone found by typing (./zones.ts), the place searched for near the map's middle
5
- // (joined/place-search), a chip for each person (./people-chips.ts) and a row for each one's answer (./answer-rows.ts).
6
-
7
- import type { JEventData } from "./generated/elements.ts";
8
- import { Draft } from "joined/draft";
9
- import { icon } from "joined/icons";
10
- import { ANSWERS, answerOf, type Answer } from "./answers.ts";
11
- import { AnswerRows, type Gates } from "./answer-rows.ts";
12
- import { geo } from "joined/geo";
13
- import { PeopleChips } from "./people-chips.ts";
14
- import { PlaceSearch } from "joined/place-search";
15
- import type { Place } from "joined/places";
16
- import { hhmm, iso, MIN, minutes, seconds, SNAP, wall } from "joined/time";
17
- import { zones } from "./zones.ts";
18
-
19
- const INPUTS = ["title", "day", "from", "to", "zone", "location", "coordinates"] as const;
20
- export type Input = (typeof INPUTS)[number];
21
- /** What the form asks of the display it's in: to draw what it holds, the people, and the map's middle. */
22
- type Host = { redraw(): void; people(): Map<number, string>; near(): { lat: number; lng: number } };
23
-
24
- const FORM = `<header><h2 class="mode"></h2></header>
25
- <label>Title<input name="title" autocomplete="off" required></label>
26
- <div class="times"><label>Day<input name="day" type="date"></label><label>Starts<input name="from" type="time" step="900"></label><label>Ends<input name="to" type="time" step="900"></label></div>
27
- <label>Time zone<input name="zone" autocomplete="off" placeholder="Where its clock is: Asia/Tokyo"></label>
28
- <div class="j-choices zones" role="listbox" aria-label="Time zones" hidden></div>
29
- <label>Place<span class="place"><input name="location" autocomplete="off" placeholder="Search, or tap the map"><button type="button" class="icon-only" name="unsettle" title="Not settled" aria-label="Not settled" data-icon="close"></button></span></label>
30
- <details class="at"><summary></summary><input name="coordinates" aria-label="The exact spot" placeholder="geo:35.68,139.76" autocomplete="off"></details>
31
- <div class="found j-choices" role="listbox" aria-label="Places" hidden></div>
32
- <div class="j-chips" role="group" aria-label="People"></div>
33
- <div class="someone" hidden><input aria-label="Add someone" placeholder="Add someone" autocomplete="off"><div class="j-choices" role="listbox" aria-label="People" hidden></div></div>
34
- <div class="answers" role="group" aria-label="Their answers"></div>
35
- <p class="note" role="status"></p>
36
- <footer><button type="button" class="act danger" name="remove" data-icon="remove">Remove</button><button type="button" class="act" name="never">Never mind</button><button class="act ink" type="submit" name="go"><span>Save</span></button></footer>`;
37
-
38
- /** The form's fields for an event as the document has it (or empty, for a new one). */
39
- const fieldsOf = (d?: JEventData): Record<Input, string> => {
40
- const at = wall(d?.start ?? "");
41
- const when = Number.isFinite(at);
42
- return {
43
- title: d?.title ?? "",
44
- day: when ? d!.start.slice(0, 10) : "",
45
- from: when ? d!.start.slice(11, 16) : "",
46
- to: when ? hhmm(at + seconds(d!.duration) * 1000) : "",
47
- zone: d?.zone ?? "",
48
- location: d?.location ?? "",
49
- coordinates: d?.coordinates ?? "",
50
- };
51
- };
52
- const same = (a: readonly number[], b: readonly number[]) => a.length === b.length && a.every((k, i) => k === b[i]);
53
-
54
- export class EventForm {
55
- readonly el = Object.assign(document.createElement("form"), { innerHTML: FORM });
56
- /** What the form holds of the picked event, until Save. */
57
- readonly held = new Draft(this.el, this.el.querySelector(".note")!);
58
- /** Who the event in the form links to, as the form has it. */
59
- chosen: number[] = [];
60
- #was: number[] = []; // who the picked event links to, as the document last had it
61
- /** Each chosen person's answer, as the form has it: yes unless said otherwise. */
62
- answers = new Map<number, Answer>();
63
- /** Who among the chosen comes or goes at the event, as the form has it. */
64
- gates: Gates = { arrives: new Set(), leaves: new Set() };
65
- #chips = new PeopleChips(this.el, {
66
- people: () => this.host.people(),
67
- chosen: () => this.chosen,
68
- choose: (chosen) => this.#choose(chosen),
69
- });
70
- #answers = new AnswerRows(this.el.querySelector(".answers")!, this, () => this.host.redraw());
71
- #places = new PlaceSearch(this.el.querySelector(".found")!, ({ name, coordinates }: Place) => {
72
- this.set("location", name);
73
- this.set("coordinates", coordinates);
74
- });
75
-
76
- constructor(readonly host: Host) {
77
- zones(this.input("zone"), this.el.querySelector<HTMLElement>(".zones")!, (zone) => this.set("zone", zone));
78
- }
79
-
80
- input = (f: Input) => this.el.elements.namedItem(f) as HTMLInputElement;
81
- /** Every field, as it's typed. */
82
- values = () => Object.fromEntries(INPUTS.map((f) => [f, this.input(f).value])) as Record<Input, string>;
83
- /** A field, from a drag, a tap or a pick: not saved until Save. */
84
- set(field: Input, value: string) {
85
- this.input(field).value = value;
86
- this.host.redraw();
87
- }
88
- /** The event as the form has it. */
89
- formed() {
90
- const v = (f: Input) => this.input(f).value;
91
- const [day, from, to] = [v("day"), v("from").slice(0, 5), v("to").slice(0, 5)];
92
- let mins = from && to ? minutes(to) - minutes(from) : 60;
93
- if (mins < 0) mins += 24 * 60; // ends the day after: drawn to midnight
94
- mins ||= SNAP;
95
- return {
96
- title: v("title"),
97
- start: day && from ? `${day}T${from}:00` : "",
98
- duration: iso(mins),
99
- zone: v("zone").trim(),
100
- location: v("location"),
101
- coordinates: v("coordinates"),
102
- };
103
- }
104
- /** A new start keeps the event's length: its end moves with it. */
105
- keepLength() {
106
- const from = this.input("from"),
107
- to = this.input("to"),
108
- was = from.dataset.at;
109
- if (was && from.value && to.value)
110
- to.value = hhmm(((((minutes(to.value) + minutes(from.value) - minutes(was)) % 1440) + 1440) % 1440) * MIN);
111
- from.dataset.at = from.value.slice(0, 5);
112
- }
113
-
114
- /** The form as the document has an event (or empty, for a new one). Opened afresh, every field is set; as the
115
- * event changes elsewhere, only those not being changed here are. */
116
- fill(d: JEventData | undefined, afresh = false) {
117
- this.held.fill(fieldsOf(d), afresh);
118
- const people = d?.people ?? [];
119
- if (afresh || (d && same(this.chosen, this.#was))) {
120
- this.chosen = [...people];
121
- this.answers = new Map(people.map((k) => [k, answerOf(d ?? {}, k)]));
122
- this.gates = { arrives: new Set(d?.arrives ?? []), leaves: new Set(d?.leaves ?? []) };
123
- }
124
- this.#was = [...people];
125
- this.chips();
126
- }
127
- /** What the form has changed of an event: fields to replace, and places emptied, to remove. */
128
- edits(d: JEventData) {
129
- const f = this.formed();
130
- const replaced: Partial<JEventData> = {},
131
- removed: ("zone" | "location" | "coordinates" | (typeof ANSWERS)[number])[] = [];
132
- if (f.title !== d.title) replaced.title = f.title;
133
- if (f.start && f.start !== d.start) replaced.start = f.start;
134
- if (f.start && seconds(f.duration) !== seconds(d.duration)) replaced.duration = f.duration;
135
- for (const k of ["zone", "location", "coordinates"] as const)
136
- if (f[k] !== (d[k] ?? "")) f[k] ? (replaced[k] = f[k]) : removed.push(k);
137
- if (!same(this.chosen, d.people ?? [])) replaced.people = this.chosen;
138
- for (const a of ANSWERS) {
139
- const theirs = this.answered(a);
140
- // an answer no one gives any more: the list gone, as an emptied place is
141
- if (!same(theirs, d[a] ?? [])) theirs.length ? (replaced[a] = theirs) : removed.push(a);
142
- }
143
- return { replaced, removed };
144
- }
145
- /** What the form says it's doing (the picked event's, or a new one), and whether it's kept: true while it has
146
- * changes not kept. */
147
- show(d: JEventData | null) {
148
- const edits = d && this.edits(d),
149
- dirty = !!edits && Object.keys(edits.replaced).length + edits.removed.length + this.gateEdits(d!).length > 0;
150
- const q = <T extends HTMLElement>(s: string) => this.el.querySelector<T>(s)!;
151
- this.input("from").dataset.at = this.input("from").value.slice(0, 5); // the start the length is kept from
152
- q(".mode").textContent = d ? `Editing “${d.title}”` : "New event";
153
- const go = q<HTMLButtonElement>("[name=go]"),
154
- mark = d ? "check" : "add";
155
- // its icon swapped only as what it does changes: not on every change
156
- if (go.dataset.mark !== mark) ((go.dataset.mark = mark), go.querySelector("svg")?.remove(), go.prepend(icon(mark)));
157
- go.querySelector("span")!.textContent = d ? "Save" : "Add";
158
- // kept only with a title: Save (Add) off till it has one
159
- this.held.show(!d ? "new" : dirty ? "changed" : "kept", !!this.input("title").value.trim());
160
- q("[name=remove]").hidden = !d;
161
- const at = geo(this.input("coordinates").value);
162
- q("[name=unsettle]").hidden = !this.input("location").value && !at;
163
- q(".at summary").textContent = at ? "Pinned on the map" : "No pin yet: tap the map, or search";
164
- return dirty;
165
- }
166
-
167
- /** Who the event links to, as the form has it now. */
168
- #choose(chosen: number[]) {
169
- this.chosen = [...chosen].sort((a, b) => a - b);
170
- for (const k of this.answers.keys()) if (!this.chosen.includes(k)) this.answers.delete(k); // off it, no answer
171
- for (const g of Object.values(this.gates)) for (const k of g) if (!this.chosen.includes(k)) g.delete(k);
172
- this.chips();
173
- this.host.redraw();
174
- }
175
- /** Who comes or goes at the event as the form has it, against the document: each id to link, or to unlink. */
176
- gateEdits(d: JEventData) {
177
- return (["arrives", "leaves"] as const).flatMap((g) => [
178
- ...[...this.gates[g]].filter((k) => !(d[g] ?? []).includes(k)).map((k) => ({ g, k, on: true })),
179
- ...(d[g] ?? []).filter((k) => !this.gates[g].has(k)).map((k) => ({ g, k, on: false })),
180
- ]);
181
- }
182
- /** Who among the chosen gave an answer, in key order. */
183
- answered = (a: Answer) => this.chosen.filter((k) => (this.answers.get(k) ?? "yes") === a);
184
- /** The people and their answers, as the form has them: a chip each (./people-chips.ts), and a row each for those
185
- * chosen (./answer-rows.ts). */
186
- chips() {
187
- const people = this.host.people();
188
- this.#chips.draw(people);
189
- this.#answers.draw(people);
190
- }
191
-
192
- /** Places called what's typed, near the map's middle, offered to pick from: one picked puts its pin. */
193
- search() {
194
- this.#places.search(this.input("location").value.trim(), () => this.host.near());
195
- }
196
- /** The places offered (none: the offer let go). */
197
- found(places: Place[]) {
198
- this.#places.found(places);
199
- }
200
- }
@@ -1,61 +0,0 @@
1
- // What <calendar-map> holds: its <j-events>, a window of the trip's events (a week, or read as a month, the six weeks
2
- // of its grid), named by its doc (trip:1?week=2026-11-02). Its events are read at most once a change, and only if
3
- // asked. Another week is the page's to hold, in place of this one: asked for by a "week" event, its Monday (or a
4
- // "month" event, the Monday its grid starts on).
5
-
6
- import type { JEvent, JEvents } from "./generated/elements.ts";
7
- import { collections as trip } from "./generated/rules.ts";
8
- import { DAY, dayOf, gridOf, local } from "joined/time";
9
-
10
- /** What it reads from its display: the week shown, and whether it's read as a month. */
11
- type From = { at: () => { week: number }; monthly: () => boolean };
12
-
13
- export class Holding {
14
- #host: HTMLElement;
15
- #from: From;
16
- #changing = false;
17
- #now: JEvent[] | null = null;
18
-
19
- /** What `host` holds. */
20
- constructor(host: HTMLElement, from: From) {
21
- [this.#host, this.#from] = [host, from];
22
- }
23
-
24
- /** Its <j-events>, and the <j-event>s in it. */
25
- list = () => this.#host.querySelector<JEvents>(`:scope > ${trip.events.place}`);
26
- /** Its events: while a change is drawn, read once, and only if it's asked (`items` copies them each time, and a
27
- * title changed asks for none); else afresh. */
28
- events = () => (this.#changing ? (this.#now ??= this.list()?.items ?? []) : (this.list()?.items ?? []));
29
- /** A change drawn, its events read once. */
30
- changing(draw: () => void) {
31
- this.#changing = true;
32
- try {
33
- draw();
34
- } finally {
35
- [this.#changing, this.#now] = [false, null];
36
- }
37
- }
38
- /** The trip's key, and the week's Monday (a day), or none until the page holds one. */
39
- held = () => {
40
- const [base = "", query] = (this.list()?.getAttribute("doc") ?? "").split("?");
41
- const q = new URLSearchParams(query),
42
- week = q.get("week") ?? q.get("month");
43
- return { trip: Number(base.split(":")[1]), week: week ? dayOf(week) : null };
44
- };
45
- /** Another week asked of the page, by its Monday: the page holds it in place of this one (the one shown, or, read as
46
- * a month, one of its: nothing). */
47
- go = (week: number) => {
48
- const monthly = this.#from.monthly();
49
- if (monthly ? !this.holds(week) : week !== this.#from.at().week)
50
- this.hold(monthly ? "month" : "week", monthly ? gridOf(week + 3) : week);
51
- };
52
- /** Whether a day is held: on the week shown, or the month's six weeks. */
53
- holds = (day: number) => {
54
- const { week } = this.#from.at();
55
- return day >= week && day < week + (this.#from.monthly() ? 42 : 7);
56
- };
57
- /** A week, or a month by the Monday its grid starts on, asked of the page in place of what it holds. */
58
- hold = (by: "week" | "month", day: number) => {
59
- this.#host.dispatchEvent(new CustomEvent(by, { bubbles: true, detail: local(day * DAY).slice(0, 10) }));
60
- };
61
- }
@@ -1,234 +0,0 @@
1
- // The map, drawn by <calendar-map>: OpenStreetMap's tiles for its view, and a pin for each event at its place, made
2
- // once, then only moved. Its view holds the places shown (the week's, or a phone's day's) at the closest zoom with
3
- // room round the edge, until a person moves it, which is kept while that week is shown: dragged, it pans; it comes
4
- // nearer and farther by its buttons, a pinch, or a trackpad's (the wheel with ctrl: the wheel alone scrolls the page).
5
- // A press on a pin picks its event (on a phone, peeks it: ./peek.ts), a drag moves it (./drags.ts), and a press on
6
- // its ground that isn't a drag is a tap there.
7
-
8
- import type { JEvent } from "./generated/elements.ts";
9
- import type { Drags } from "./drags.ts";
10
- import type { Drawer } from "./drawer.ts";
11
- import type { Peek } from "./peek.ts";
12
- import type { Part } from "./shell.ts";
13
- import { follow, held } from "joined/follow";
14
- import { hueOf } from "joined/hues";
15
- import { bounds, geo, placeAt, TILE, tileAt, world } from "joined/geo";
16
-
17
- export const MAP_H = 320; // the map's least height: beside the calendar it's as tall as it
18
- /** Where the map looks: its zoom, and the world's pixel at its top left. */
19
- export type View = { z: number; x: number; y: number };
20
- type Point = { x: number; y: number };
21
-
22
- /** What the map reads from its display: the week and its view and size as drawn, and where a person moved it; the
23
- * frame said again once they have; what a press does; and the drawer, whose events it draws as the form has them. */
24
- type From = {
25
- at: () => { week: number; view: View; W: number; H: number };
26
- chose: { looked: { week: number; view: View } | null };
27
- reframe: () => void;
28
- phone: () => boolean;
29
- pick: (el: JEvent) => void;
30
- drags: () => Drags;
31
- peek: () => Peek;
32
- drawer: () => Drawer;
33
- };
34
-
35
- export class MapView {
36
- readonly el: HTMLElement;
37
- #pins = new Map<JEvent, HTMLElement>();
38
- #tiles: HTMLElement;
39
- #from: From;
40
- #fingers = new Map<number, { clientX: number; clientY: number }>(); // on the map's ground, while it's pressed
41
- #apart = 0; // how far apart two fingers were, at the pinch's last step
42
-
43
- /** Drawn in its parts: its tiles, and its buttons nearer and farther. */
44
- constructor($: Part, from: From) {
45
- [this.el, this.#tiles, this.#from] = [$(".map"), $(".tiles"), from];
46
- this.el.addEventListener(
47
- "pointerdown",
48
- (e) => !(e.target as Element).closest(".pin, a, button, .peek") && (from.peek().show(null), this.#ground(e)),
49
- );
50
- // nearer and farther: its buttons, a pinch, or a trackpad's (the wheel with ctrl); the wheel alone scrolls the page
51
- $("[name=nearer]").addEventListener("click", () => this.#zoom(1));
52
- $("[name=farther]").addEventListener("click", () => this.#zoom(-1));
53
- let wheel = 0;
54
- this.el.addEventListener(
55
- "wheel",
56
- (e) => {
57
- if (!e.ctrlKey) return;
58
- e.preventDefault();
59
- wheel += e.deltaY;
60
- if (Math.abs(wheel) < 40) return;
61
- this.#zoom(wheel < 0 ? 1 : -1, this.#offset(e));
62
- wheel = 0;
63
- },
64
- { passive: false },
65
- );
66
- }
67
-
68
- /** Its view for a week: where a person moved it on that week; else the closest zoom that holds every place shown
69
- * (or, none, the week's), with room round the edge: a place alone, its neighbourhood; none, where it was. */
70
- fit(shown: JEvent[], events: JEvent[], week: number) {
71
- const places = [shown, events]
72
- .map((els) => els.map((el) => geo(el.data.coordinates)).filter((p) => p !== null))
73
- .find((ps) => ps.length);
74
- const W = this.el.clientWidth || 480,
75
- H = this.el.clientHeight || MAP_H,
76
- { view: was } = this.#from.at(),
77
- { looked } = this.#from.chose;
78
- let view: View = was.z ? was : { z: 2, x: 0, y: 0 };
79
- if (looked?.week === week) view = looked.view;
80
- else if (places)
81
- for (let z = 13; z >= 1; z--) {
82
- const pts = places.map((p) => world(p.lat, p.lng, z));
83
- const [x0, x1, y0, y1] = bounds(pts);
84
- view = { z, x: (x0 + x1) / 2 - W / 2, y: (y0 + y1) / 2 - H / 2 };
85
- if (x1 - x0 <= W - 60 && y1 - y0 <= H - 60) break;
86
- }
87
- return { view, W, H };
88
- }
89
- /** Its tiles, for its view. */
90
- draw() {
91
- const { view, W, H } = this.#from.at();
92
- const n = 2 ** view.z,
93
- tiles: HTMLImageElement[] = [];
94
- for (let tx = Math.floor(view.x / TILE); tx * TILE < view.x + W; tx++)
95
- for (let ty = Math.max(0, Math.floor(view.y / TILE)); ty * TILE < view.y + H && ty < n; ty++) {
96
- const img = Object.assign(document.createElement("img"), {
97
- alt: "",
98
- draggable: false,
99
- src: tileAt(view.z, tx, ty),
100
- });
101
- img.style.left = `${tx * TILE - view.x}px`;
102
- img.style.top = `${ty * TILE - view.y}px`;
103
- tiles.push(img);
104
- }
105
- this.#tiles.replaceChildren(...tiles);
106
- }
107
-
108
- /** An event's pin at its place: made once, then only moved. */
109
- place(el: JEvent, title: string, coordinates?: string) {
110
- let pin = this.#pins.get(el);
111
- if (!pin) {
112
- const made = (pin = Object.assign(document.createElement("button"), { className: "pin", type: "button" }));
113
- made.addEventListener("pointerdown", (e) =>
114
- held(
115
- e,
116
- () => this.#from.drags().pin(el, e),
117
- () => this.#ground(e, false),
118
- () => (this.#from.phone() ? this.#from.peek().show(el) : this.#from.pick(el)),
119
- ),
120
- );
121
- this.#pins.set(el, made);
122
- }
123
- pin.style.setProperty("--hue", hueOf(el.key));
124
- pin.ariaLabel = title;
125
- this.pinAt(pin, coordinates);
126
- }
127
- /** A pin at a place, as the map is drawn; no place, no pin. */
128
- pinAt(pin: HTMLElement, coordinates?: string) {
129
- const at = geo(coordinates);
130
- if (at) this.where(pin, world(at.lat, at.lng, this.view.z));
131
- else pin.remove();
132
- }
133
- /** A pin at a point in the world. */
134
- where(pin: HTMLElement, p: Point) {
135
- const { view } = this;
136
- pin.style.left = `${p.x - view.x}px`;
137
- pin.style.top = `${p.y - view.y}px`;
138
- if (pin.parentNode !== this.el) this.el.append(pin);
139
- }
140
-
141
- /** Where it looks, as drawn. */
142
- get view() {
143
- return this.#from.at().view;
144
- }
145
- /** The point in the world under a pointer on the map. */
146
- pointAt(e: PointerEvent) {
147
- const r = this.el.getBoundingClientRect(),
148
- { view } = this;
149
- return { x: e.clientX - r.left + view.x, y: e.clientY - r.top + view.y };
150
- }
151
- /** The place at a point in the world, a geo: URI. */
152
- placeOf = (p: Point) => placeAt(p.x, p.y, this.view.z);
153
- /** The place at its middle, a typed place's search is near. */
154
- near() {
155
- const { view } = this;
156
- return geo(placeAt(view.x + this.el.clientWidth / 2, view.y + this.el.clientHeight / 2, view.z))!;
157
- }
158
-
159
- /** The map's ground pressed: dragged, it pans; let go where it was pressed, it's a tap there (given one). A second
160
- * finger down makes it a pinch, nearer as they part, farther as they close. */
161
- #ground(down: PointerEvent, tap = true) {
162
- this.#fingers.set(down.pointerId, down);
163
- const [first, second] = [...this.#fingers.values()];
164
- // a second finger: how far apart they came down, for the pinch the first finger's press follows
165
- if (second)
166
- return void (this.#apart = Math.hypot(first!.clientX - second.clientX, first!.clientY - second.clientY));
167
- const was = { ...this.view };
168
- let moved = false;
169
- follow(
170
- down,
171
- (e) => {
172
- if (!this.#fingers.has(e.pointerId)) return;
173
- this.#fingers.set(e.pointerId, e);
174
- const [a, b] = [...this.#fingers.values()];
175
- if (b) {
176
- // a pinch: a step nearer or farther each time the fingers part or close by half again
177
- moved = true;
178
- const d = Math.hypot(a!.clientX - b.clientX, a!.clientY - b.clientY);
179
- if (d > this.#apart * 1.5 || d < this.#apart / 1.5) {
180
- const mid = { clientX: (a!.clientX + b.clientX) / 2, clientY: (a!.clientY + b.clientY) / 2 };
181
- this.#zoom(d > this.#apart ? 1 : -1, this.#offset(mid));
182
- this.#apart = d;
183
- }
184
- return;
185
- }
186
- const dx = e.clientX - down.clientX,
187
- dy = e.clientY - down.clientY;
188
- if (!moved && Math.hypot(dx, dy) < 4) return;
189
- moved = true;
190
- this.look({ ...was, x: was.x - dx, y: was.y - dy });
191
- },
192
- (e) => {
193
- this.#fingers.clear();
194
- if (e && !moved && tap) this.#from.drags().tap(down);
195
- },
196
- );
197
- }
198
- /** Where a pointer is on the map. */
199
- #offset(e: { clientX: number; clientY: number }) {
200
- const r = this.el.getBoundingClientRect();
201
- return { x: e.clientX - r.left, y: e.clientY - r.top };
202
- }
203
- /** The map a step nearer or farther, about a point on it (its middle, from its buttons). */
204
- #zoom(by: 1 | -1, at = { x: this.el.clientWidth / 2, y: this.el.clientHeight / 2 }) {
205
- const { view } = this,
206
- z = Math.max(2, Math.min(18, view.z + by)),
207
- k = 2 ** (z - view.z);
208
- if (z !== view.z) this.look({ z, x: (view.x + at.x) * k - at.x, y: (view.y + at.y) * k - at.y });
209
- }
210
- /** The map where a person moved it: its tiles and its pins there, kept while this week is shown. */
211
- look(view: View) {
212
- this.#from.chose.looked = { week: this.#from.at().week, view };
213
- this.#from.reframe();
214
- this.draw();
215
- const drawer = this.#from.drawer();
216
- for (const [el, pin] of this.#pins) this.pinAt(pin, drawer.shown(el).coordinates);
217
- drawer.repin();
218
- }
219
-
220
- /** An event's pin, if it's drawn. */
221
- pinOf = (el: JEvent) => this.#pins.get(el);
222
- /** The picked event's pin marked, the others not. */
223
- mark(picked: JEvent | null) {
224
- for (const [e, pin] of this.#pins) pin.toggleAttribute("picked", e === picked);
225
- }
226
- /** The peeked event's pin marked, the others not. */
227
- peeked(el: JEvent | null) {
228
- for (const [e, pin] of this.#pins) pin.toggleAttribute("peeked", e === el);
229
- }
230
- /** The pins of events no longer in `list` (gone, or on another week) taken away. */
231
- drop(list: Node | null) {
232
- for (const [el, pin] of this.#pins) if (el.parentNode !== list) (pin.remove(), this.#pins.delete(el));
233
- }
234
- }
@@ -1,87 +0,0 @@
1
- // The trip read as a month, drawn by <calendar-map> (view="month") beside its map: a grid of the month's six weeks,
2
- // held as one window of the trip's events, the month's own days in ink and the rest muted; on each day its events by
3
- // when they start, a chip each (its time and title, its hue), a tap picking it. On a phone, too narrow for its events'
4
- // words, a tap on a day opens that day in the calendar. A day is made again only when what it shows has changed.
5
-
6
- import type { JEvent } from "./generated/elements.ts";
7
- import type { Part } from "./shell.ts";
8
- import { keep } from "joined/keep";
9
- import { hueOf } from "joined/hues";
10
- import { DAY, dated, dayOf, firstOf, hhmm, mondayOf, wall } from "joined/time";
11
-
12
- /** What the month reads from its display: the Monday its grid starts on, its events and the one picked, how to pick
13
- * one, whether it's on a phone and the day a phone's calendar shows; and how to read a week as a calendar instead. */
14
- type From = {
15
- at: () => { week: number };
16
- events: () => JEvent[];
17
- picked: () => JEvent | null;
18
- pick: (el: JEvent) => void;
19
- phone: () => boolean;
20
- chose: { day: number; dayWeek: number | null };
21
- readAs: (view: "calendar") => void;
22
- hold: (by: "week" | "month", day: number) => void;
23
- };
24
-
25
- export class Month {
26
- #kept = new Map<string, { shows: string; el: HTMLElement }>();
27
- #cells: HTMLElement;
28
- #from: From;
29
-
30
- /** Drawn in its cells, a day each. */
31
- constructor($: Part, from: From) {
32
- [this.#cells, this.#from] = [$(".month .cells"), from];
33
- }
34
-
35
- draw() {
36
- const { week } = this.#from.at(),
37
- picked = this.#from.picked(),
38
- first = firstOf(week + 7),
39
- month = new Date(first * DAY).getUTCMonth(),
40
- byDay = new Map<number, JEvent[]>();
41
- for (const el of this.#from.events()) {
42
- const d = dayOf(el.data.start);
43
- (byDay.get(d) ?? byDay.set(d, []).get(d)!).push(el);
44
- }
45
- keep(
46
- this.#cells,
47
- this.#kept,
48
- Array.from({ length: 42 }, (_, i) => {
49
- const day = week + i,
50
- ours = new Date(day * DAY).getUTCMonth() === month,
51
- theirs = (byDay.get(day) ?? []).sort((a, b) => a.data.start.localeCompare(b.data.start));
52
- const said = theirs.map((el) => [el.key, hhmm(wall(el.data.start)), el.data.title, el === picked]);
53
- return {
54
- key: String(day),
55
- shows: JSON.stringify([ours, said]),
56
- make: () => {
57
- const cell = Object.assign(document.createElement("div"), { className: ours ? "day" : "day other" });
58
- // on a phone, too narrow for its events' words: a tap on a day is that day, in the calendar
59
- cell.addEventListener("click", () => this.#from.phone() && this.#open(day));
60
- cell.append(Object.assign(document.createElement("span"), { textContent: dated(day, { day: "numeric" }) }));
61
- for (const el of theirs) {
62
- const b = Object.assign(document.createElement("button"), {
63
- type: "button",
64
- className: "entry",
65
- textContent: `${hhmm(wall(el.data.start))} ${el.data.title}`,
66
- });
67
- b.style.setProperty("--hue", hueOf(el.key));
68
- b.toggleAttribute("picked", el === picked);
69
- b.addEventListener("click", () => this.#from.pick(el));
70
- cell.append(b);
71
- }
72
- return cell;
73
- },
74
- };
75
- }),
76
- );
77
- }
78
-
79
- /** A day of the month opened, on a phone: the calendar of its week, on that day. */
80
- #open(day: number) {
81
- const week = mondayOf(day),
82
- { chose } = this.#from;
83
- [chose.day, chose.dayWeek] = [day - week, week];
84
- this.#from.readAs("calendar");
85
- this.#from.hold("week", week);
86
- }
87
- }
@@ -1,67 +0,0 @@
1
- // The trip's other weeks, beneath <calendar-map>'s week: how many events they hold, and a way to each, from its
2
- // <j-weeks> (../weeks), a live list. Hidden when there are none, and when it's read as a month, which shows them.
3
-
4
- import type { JWeek } from "../weeks/generated/elements.ts";
5
- import type { Part } from "./shell.ts";
6
- import { keep, type Row } from "joined/keep";
7
- import { collections as weeks } from "../weeks/generated/rules.ts";
8
- import { DAY, dated, dayOf, local } from "joined/time";
9
-
10
- /** What it reads from its display: the trip held, the week shown, whether it's read as a month, and how to go to a
11
- * week. */
12
- type From = {
13
- held: () => { trip: number };
14
- at: () => { week: number };
15
- monthly: () => boolean;
16
- go: (week: number) => void;
17
- };
18
-
19
- export class OtherWeeks {
20
- #kept = new Map<string, { shows: string; el: HTMLElement }>();
21
- #weeks: HTMLCollectionOf<JWeek>;
22
- #p: HTMLElement;
23
- #from: From;
24
-
25
- /** Drawn in its paragraph, from the weeks `host` holds. */
26
- constructor(host: HTMLElement, $: Part, from: From) {
27
- this.#weeks = host.getElementsByTagName(weeks.weeks.tag) as HTMLCollectionOf<JWeek>;
28
- [this.#p, this.#from] = [$(".others"), from];
29
- }
30
-
31
- draw() {
32
- const p = this.#p,
33
- { trip } = this.#from.held(),
34
- { week } = this.#from.at(),
35
- shown = local(week * DAY).slice(0, 10),
36
- year = dated(week, { year: "numeric" });
37
- const held = [...this.#weeks].map((w) => w.data).filter((w) => w.trip === trip && w.week !== shown);
38
- const n = held.reduce((sum, w) => sum + w.events, 0);
39
- p.hidden = !n || this.#from.monthly(); // a month's are on it
40
- const rows: Row[] = held.map((w) => {
41
- const monday = dayOf(w.week),
42
- on = dated(monday, { year: "numeric" }) === year ? {} : { year: "numeric" as const },
43
- says = `${dated(monday, { day: "numeric", month: "short", ...on })} (${w.events})`;
44
- return {
45
- key: w.week,
46
- shows: says,
47
- make: () => {
48
- const go = Object.assign(document.createElement("button"), {
49
- type: "button",
50
- className: "act small",
51
- textContent: says,
52
- });
53
- go.ariaLabel = `The week of ${dated(monday, { day: "numeric", month: "long", year: "numeric" })}`;
54
- go.addEventListener("click", () => this.#from.go(monday));
55
- return go;
56
- },
57
- };
58
- });
59
- const says = `${n} ${n === 1 ? "event" : "events"} in ${held.length === 1 ? "another week" : "other weeks"}: `;
60
- const said = {
61
- key: "said",
62
- shows: says,
63
- make: () => Object.assign(document.createElement("span"), { textContent: says }),
64
- };
65
- keep(p, this.#kept, n ? [said, ...rows] : []);
66
- }
67
- }