@blueshed/joined 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/.claude/skills/joined/SKILL.md +9 -1
  2. package/.claude/skills/joined/reference.md +316 -63
  3. package/.claude/skills/joined-door/SKILL.md +57 -0
  4. package/README.md +19 -50
  5. package/docs/design.md +158 -37
  6. package/docs/introduction.md +27 -27
  7. package/docs/light-and-shadow.svg +2 -1
  8. package/docs/links-and-trust.svg +1 -0
  9. package/docs/stories-to-code.svg +2 -1
  10. package/docs/wire-op.svg +1 -0
  11. package/examples/README.md +20 -0
  12. package/examples/account/account.json +1 -0
  13. package/examples/account/derive.ts +41 -0
  14. package/examples/account/generated/elements.ts +52 -0
  15. package/examples/account/generated/rows.ts +22 -0
  16. package/examples/account/generated/rules.ts +32 -0
  17. package/examples/account/routes.ts +5 -0
  18. package/examples/app.css +11 -1
  19. package/examples/cafe/books.html +2 -2
  20. package/examples/cafe/cafe.css +96 -85
  21. package/examples/cafe/generated/books.rows.ts +22 -0
  22. package/examples/cafe/generated/books.rules.ts +3 -2
  23. package/examples/cafe/generated/kitchen.rows.ts +27 -0
  24. package/examples/cafe/generated/kitchen.rules.ts +11 -1
  25. package/examples/cafe/generated/menu.rows.ts +22 -0
  26. package/examples/cafe/generated/menu.rules.ts +3 -2
  27. package/examples/cafe/generated/order.rows.ts +27 -0
  28. package/examples/cafe/generated/order.rules.ts +11 -1
  29. package/examples/cafe/generated/staff.elements.ts +7 -2
  30. package/examples/cafe/generated/staff.rows.ts +22 -0
  31. package/examples/cafe/generated/staff.rules.ts +9 -1
  32. package/examples/cafe/generated/supplies.queries.ts +4 -2
  33. package/examples/cafe/generated/supplies.rows.ts +22 -0
  34. package/examples/cafe/generated/supplies.rules.ts +17 -1
  35. package/examples/cafe/generated/till.queries.ts +2 -0
  36. package/examples/cafe/generated/till.rows.ts +27 -0
  37. package/examples/cafe/generated/till.rules.ts +11 -1
  38. package/examples/cafe/index.html +14 -15
  39. package/examples/cafe/kitchen.css +11 -19
  40. package/examples/cafe/kitchen.ts +7 -3
  41. package/examples/cafe/look.ts +30 -0
  42. package/examples/cafe/menu.html +10 -26
  43. package/examples/cafe/menu.ts +8 -80
  44. package/examples/cafe/migrations/002-guard-supplies.ts +15 -0
  45. package/examples/cafe/order.html +8 -7
  46. package/examples/cafe/order.ts +6 -2
  47. package/examples/cafe/routes.ts +0 -1
  48. package/examples/cafe/staff.json +5 -0
  49. package/examples/cafe/stories.jsonl +6 -2
  50. package/examples/cafe/supplies.html +35 -34
  51. package/examples/cafe/supplies.ts +59 -39
  52. package/examples/cafe/till.ts +19 -11
  53. package/examples/cafe/views.ts +7 -5
  54. package/examples/chart/arches.ts +150 -0
  55. package/examples/chart/chart.css +11 -0
  56. package/examples/chart/chart.json +87 -0
  57. package/examples/chart/generated/elements.ts +105 -0
  58. package/examples/chart/generated/queries.ts +36 -0
  59. package/examples/chart/generated/rows.ts +27 -0
  60. package/examples/chart/generated/rules.ts +111 -0
  61. package/examples/chart/grid.ts +118 -0
  62. package/examples/chart/index.html +78 -0
  63. package/examples/chart/migrations/001-chart.ts +6 -0
  64. package/examples/chart/migrations/002-create-conditions.ts +6 -0
  65. package/examples/chart/page.ts +20 -0
  66. package/examples/chart/routes.ts +7 -0
  67. package/examples/chart/stories.jsonl +14 -0
  68. package/examples/chart/teeth.ts +57 -0
  69. package/examples/desk/desk.css +6 -10
  70. package/examples/desk/generated/elements.ts +1 -1
  71. package/examples/desk/generated/rows.ts +22 -0
  72. package/examples/desk/generated/rules.ts +34 -1
  73. package/examples/desk/index.html +10 -3
  74. package/examples/desk/lanes.css +21 -19
  75. package/examples/desk/routes.ts +0 -2
  76. package/examples/desk/stories.jsonl +4 -3
  77. package/examples/desk/tally.css +1 -1
  78. package/examples/desk/thumbs.ts +2 -2
  79. package/examples/docs.ts +7 -4
  80. package/examples/hello/generated/elements.ts +2 -2
  81. package/examples/hello/generated/rules.ts +3 -2
  82. package/examples/hello/hello.css +2 -4
  83. package/examples/hello/index.html +10 -3
  84. package/examples/hello/page.ts +4 -4
  85. package/examples/index.html +20 -12
  86. package/examples/notes/generated/elements.ts +112 -0
  87. package/examples/notes/generated/queries.ts +42 -0
  88. package/examples/notes/generated/rows.ts +27 -0
  89. package/examples/notes/generated/rules.ts +133 -0
  90. package/examples/notes/index.html +32 -0
  91. package/examples/notes/look.ts +41 -0
  92. package/examples/notes/migrations/001-notes.ts +7 -0
  93. package/examples/notes/notes.json +78 -0
  94. package/examples/notes/page.ts +21 -0
  95. package/examples/notes/routes.ts +6 -0
  96. package/examples/notes/stories.jsonl +24 -0
  97. package/examples/page.ts +9 -2
  98. package/examples/people/generated/rows.ts +22 -0
  99. package/examples/people/generated/rules.ts +11 -1
  100. package/examples/people/links.ts +8 -9
  101. package/examples/people/people.css +1 -1
  102. package/examples/people/routes.ts +1 -3
  103. package/examples/people/stories.jsonl +1 -0
  104. package/examples/people/view.ts +5 -2
  105. package/examples/trip/generated/elements.ts +5 -3
  106. package/examples/trip/generated/queries.ts +12 -1
  107. package/examples/trip/generated/rows.ts +27 -0
  108. package/examples/trip/generated/rules.ts +56 -2
  109. package/examples/trip/index.html +58 -12
  110. package/examples/trip/line.css +186 -0
  111. package/examples/trip/line.ts +51 -40
  112. package/examples/trip/page.ts +65 -71
  113. package/examples/trip/routes.ts +9 -5
  114. package/examples/trip/stays.css +13 -13
  115. package/examples/trip/stays.ts +15 -10
  116. package/examples/trip/stories.jsonl +2 -0
  117. package/examples/trip/told.ts +3 -26
  118. package/examples/trip/trip.css +16 -0
  119. package/examples/trips/generated/elements.ts +1 -1
  120. package/examples/trips/generated/rows.ts +22 -0
  121. package/examples/trips/generated/rules.ts +9 -1
  122. package/examples/trips/index.html +10 -10
  123. package/examples/trips/map.ts +3 -14
  124. package/examples/trips/new-trip.ts +14 -16
  125. package/examples/trips/trips.css +24 -23
  126. package/examples/weeks/generated/elements.ts +1 -1
  127. package/examples/weeks/generated/queries.ts +11 -0
  128. package/examples/weeks/generated/rows.ts +22 -0
  129. package/examples/weeks/generated/rules.ts +11 -5
  130. package/examples/weeks/routes.ts +3 -2
  131. package/examples/weeks/stories.jsonl +1 -0
  132. package/examples/welcome.css +43 -33
  133. package/package.json +8 -2
  134. package/src/attachment.ts +17 -2
  135. package/src/awesome.ts +103 -0
  136. package/src/board.css +76 -0
  137. package/src/board.ts +173 -0
  138. package/src/cli.ts +28 -3
  139. package/src/compile.ts +821 -109
  140. package/src/definitions.ts +113 -27
  141. package/src/demo.css +2 -5
  142. package/src/draft.ts +48 -27
  143. package/src/drawer.ts +248 -0
  144. package/src/engine.ts +253 -170
  145. package/src/fields.ts +341 -0
  146. package/src/file-value.ts +12 -2
  147. package/src/files.ts +113 -33
  148. package/src/ground.ts +110 -0
  149. package/src/icon-names.ts +19 -2
  150. package/src/keep.ts +16 -3
  151. package/src/kit.ts +51 -0
  152. package/src/link.ts +3 -3
  153. package/src/map.css +140 -0
  154. package/src/map.ts +200 -0
  155. package/src/mcp.ts +129 -24
  156. package/src/members/demo.ts +13 -12
  157. package/src/members/generated/rows.ts +22 -0
  158. package/src/members/generated/rules.ts +3 -2
  159. package/src/members/group.ts +105 -55
  160. package/src/members/keys.ts +95 -79
  161. package/src/members/panel.css +40 -35
  162. package/src/members/panel.ts +58 -37
  163. package/src/migrate.ts +178 -125
  164. package/src/migrations/005-change-kept.ts +7 -0
  165. package/src/month.css +129 -0
  166. package/src/month.ts +179 -0
  167. package/src/ops.ts +40 -1
  168. package/src/page.css +11 -2
  169. package/src/page.ts +68 -17
  170. package/src/parts.css +614 -230
  171. package/src/parts.ts +259 -36
  172. package/src/plane.css +61 -0
  173. package/src/plane.ts +153 -0
  174. package/src/postgres-server.ts +60 -0
  175. package/src/reading.css +73 -0
  176. package/src/reading.ts +238 -0
  177. package/src/rows.css +289 -0
  178. package/src/rows.ts +864 -0
  179. package/src/search.css +80 -0
  180. package/src/search.ts +130 -0
  181. package/src/server.ts +355 -137
  182. package/src/settings.ts +9 -4
  183. package/src/sheet.ts +116 -0
  184. package/src/skill.ts +40 -0
  185. package/src/slots.css +90 -0
  186. package/src/slots.ts +213 -0
  187. package/src/specs.ts +38 -0
  188. package/src/starter.ts +19 -2
  189. package/src/store.ts +224 -161
  190. package/src/stories.ts +43 -11
  191. package/src/surface.ts +164 -0
  192. package/src/time.ts +2 -0
  193. package/src/timeline.css +111 -0
  194. package/src/timeline.ts +235 -0
  195. package/src/toast.ts +21 -48
  196. package/src/together.ts +15 -24
  197. package/src/tokens.css +89 -3
  198. package/src/tokens.json +287 -7
  199. package/src/tool.ts +210 -0
  200. package/src/upkeep.ts +47 -22
  201. package/src/views.css +43 -0
  202. package/src/views.ts +111 -0
  203. package/src/week.css +150 -0
  204. package/src/week.ts +254 -0
  205. package/src/write.ts +326 -78
  206. package/starter/CHANGELOG.md +8 -0
  207. package/starter/CLAUDE.md +9 -3
  208. package/starter/bunfig +5 -0
  209. package/starter/githooks/pre-commit +13 -0
  210. package/starter/prettierignore +5 -0
  211. package/starter/tests/hello.test.ts +2 -0
  212. package/starter/tests/records.test.ts +40 -0
  213. package/starter/todo.jsonl +0 -0
  214. package/docs/learning.md +0 -76
  215. package/examples/cafe/trust.ts +0 -20
  216. package/examples/desk/trust.ts +0 -24
  217. package/examples/people/trust.ts +0 -14
  218. package/examples/trip/answer-rows.ts +0 -70
  219. package/examples/trip/bar.ts +0 -89
  220. package/examples/trip/calendar-map.css +0 -711
  221. package/examples/trip/calendar-map.ts +0 -249
  222. package/examples/trip/drags.ts +0 -143
  223. package/examples/trip/drawer.ts +0 -250
  224. package/examples/trip/event-form.ts +0 -200
  225. package/examples/trip/holding.ts +0 -61
  226. package/examples/trip/map.ts +0 -234
  227. package/examples/trip/month.ts +0 -87
  228. package/examples/trip/other-weeks.ts +0 -67
  229. package/examples/trip/peek.ts +0 -71
  230. package/examples/trip/people-chips.ts +0 -74
  231. package/examples/trip/shell.ts +0 -39
  232. package/examples/trip/trust.ts +0 -51
  233. package/examples/trip/week.ts +0 -237
  234. package/examples/trip/writes.ts +0 -91
  235. package/examples/trip/zones.ts +0 -16
  236. package/examples/weeks/derive.ts +0 -23
  237. package/src/scrim.ts +0 -81
package/src/week.ts ADDED
@@ -0,0 +1,254 @@
1
+ // <j-week for="plans" when="when" length="length"> (joined/kit): a collection read by its hours, a week of days side by
2
+ // side, each item a block from its time for its length (an hour where it has none), those at once side by side. A
3
+ // block tapped opens its sheet; dragged, it moves by quarter hours and to another day, and by its foot it lasts
4
+ // longer or shorter (each where its `may` lets it); an empty hour tapped adds one there, the sheet offered that day
5
+ // and hour, still asked. The hours shown are the working day's (8 to 20, `from` and `until`), grown to hold what's
6
+ // there; now is a line across today. On a phone it's one day at a time, the week's days a strip above it to choose
7
+ // from, each marked where it has something. The week shown is kept in the address (?day=2026-11-15).
8
+
9
+ import { follow } from "./follow.ts";
10
+ import { phone } from "./parts.ts";
11
+ import { iconButton } from "./icons.ts";
12
+ import { keep, type Row } from "./keep.ts";
13
+ import { el, Reading } from "./reading.ts";
14
+ import type { Item } from "./rows.ts";
15
+ import { DAY, MIN, SNAP, dated, dayOf, iso, lasts, local, mondayOf, now, seconds, wall } from "./time.ts";
16
+ import STYLE from "./week.css" with { type: "text" };
17
+
18
+ const SHEET = new CSSStyleSheet();
19
+ SHEET.replaceSync(STYLE);
20
+ /** An item as the week places it: its day, its minutes from midnight, how long, and its place among those at once. */
21
+ type Placed = { it: Item; day: number; from: number; mins: number; lane: number; lanes: number };
22
+
23
+ export class JWeek extends Reading {
24
+ static override sheets = [SHEET];
25
+ #name = el("h3");
26
+ #strip = el("div", { className: "strip", role: "tablist", ariaLabel: "The week's days" });
27
+ #hours = el("div", { className: "hours", part: "hours", ariaHidden: "true" });
28
+ #cols = el("div", { className: "cols" });
29
+ #heads = new Map<string, { shows: string; el: HTMLElement }>();
30
+ #days = new Map<string, { shows: string; el: HTMLElement }>();
31
+
32
+ get #length() {
33
+ return this.field("length") ?? this.spec?.fields.find((f) => f.type === "duration");
34
+ }
35
+ protected made() {
36
+ const today = el("button", { type: "button", className: "act small today", part: "today" }, "Today");
37
+ today.addEventListener("click", () => (this.day = dayOf(now())));
38
+ this.root.append(
39
+ el(
40
+ "header",
41
+ { className: "head", part: "head" },
42
+ this.#name,
43
+ today,
44
+ iconButton("back", "The week before", () => (this.day = this.day - 7)),
45
+ iconButton("on", "The week after", () => (this.day = this.day + 7)),
46
+ ),
47
+ this.#strip,
48
+ el("div", { className: "body" }, this.#hours, this.#cols),
49
+ );
50
+ }
51
+ protected draw() {
52
+ const when = this.when;
53
+ if (!when) return;
54
+ const length = this.#length,
55
+ day = this.day,
56
+ monday = mondayOf(day),
57
+ today = dayOf(now()),
58
+ days = Array.from({ length: 7 }, (_, i) => monday + i);
59
+ this.#name.textContent = `${dated(monday, { day: "numeric", month: "short" })} – ${dated(monday + 6, { day: "numeric", month: "short", year: "numeric" })}`;
60
+ // each item of the week: its day, its minutes, its length; those at once side by side
61
+ const placed: Placed[] = [];
62
+ for (const it of this.items()) {
63
+ const w = it.data[when.name];
64
+ if (typeof w !== "string") continue;
65
+ const d = dayOf(w);
66
+ if (d < monday || d > monday + 6) continue;
67
+ const len = length && typeof it.data[length.name] === "string" ? seconds(it.data[length.name]) / 60 : 0;
68
+ placed.push({ it, day: d, from: (wall(w) - d * DAY) / MIN, mins: Math.max(len || 60, SNAP), lane: 0, lanes: 1 });
69
+ }
70
+ for (const d of days) side(placed.filter((p) => p.day === d));
71
+ // the hours: the working day's, grown to hold what's there
72
+ let first = Number(this.getAttribute("from") ?? 8),
73
+ last = Number(this.getAttribute("until") ?? 20);
74
+ for (const p of placed) {
75
+ first = Math.min(first, Math.floor(p.from / 60));
76
+ last = Math.max(last, Math.min(24, Math.ceil((p.from + p.mins) / 60)));
77
+ }
78
+ this.style.setProperty("--hours", String(last - first));
79
+ this.#hours.replaceChildren(
80
+ ...Array.from({ length: last - first }, (_, i) => el("span", {}, `${String(first + i).padStart(2, "0")}:00`)),
81
+ );
82
+ const nowMs = wall(now()),
83
+ had = new Set(placed.map((p) => p.day));
84
+ // the days' strip: each a tab, the one shown on a phone chosen; marked where it has something
85
+ keep(
86
+ this.#strip,
87
+ this.#heads,
88
+ days.map((d): Row => ({
89
+ key: String(d),
90
+ shows: JSON.stringify([d === day, d === today, had.has(d)]),
91
+ make: () => {
92
+ const b = el(
93
+ "button",
94
+ {
95
+ type: "button",
96
+ role: "tab",
97
+ className: "dayhead",
98
+ part: "day-head",
99
+ ariaLabel: dated(d, { weekday: "long", day: "numeric", month: "long" }),
100
+ },
101
+ el("span", { className: "wd" }, dated(d, { weekday: "short" })),
102
+ el("span", { className: "dn" }, String(new Date(d * DAY).getUTCDate())),
103
+ // a day with nothing on keeps its mark's room, the mark unseen (never hidden: hidden takes the room too)
104
+ el("i", { className: had.has(d) ? "mark" : "mark none" }),
105
+ );
106
+ b.ariaSelected = String(d === day);
107
+ b.toggleAttribute("today", d === today);
108
+ b.addEventListener("click", () => (this.day = d));
109
+ return b;
110
+ },
111
+ })),
112
+ );
113
+ keep(
114
+ this.#cols,
115
+ this.#days,
116
+ days.map((d): Row => {
117
+ const here = placed.filter((p) => p.day === d),
118
+ nowAt = d === today ? (nowMs - d * DAY) / MIN - first * 60 : null;
119
+ return {
120
+ key: String(d),
121
+ shows: JSON.stringify([
122
+ first,
123
+ last,
124
+ d === day,
125
+ nowAt === null ? null : Math.round(nowAt / 5),
126
+ this.adds,
127
+ here.map((p) => [
128
+ p.it.key,
129
+ this.named(p.it),
130
+ p.from,
131
+ p.mins,
132
+ p.lane,
133
+ p.lanes,
134
+ this.opened(p.it),
135
+ p.it.getAttribute("may"),
136
+ ]),
137
+ ]),
138
+ make: () => this.#column(d, here, first, nowAt),
139
+ };
140
+ }),
141
+ );
142
+ }
143
+ /** A day's column: its hours' lines, its blocks, now's line; an empty hour tapped, one added there. */
144
+ #column(d: number, here: Placed[], first: number, nowAt: number | null) {
145
+ const col = el("div", {
146
+ className: "col",
147
+ part: "day",
148
+ ariaLabel: dated(d, { weekday: "long", day: "numeric", month: "long" }),
149
+ });
150
+ col.toggleAttribute("chosen", d === this.day);
151
+ col.dataset.day = String(d);
152
+ for (const p of here) col.append(this.#block(p, first));
153
+ if (nowAt !== null && nowAt >= 0) {
154
+ const line = el("i", { className: "now", part: "now", ariaHidden: "true" });
155
+ line.style.setProperty("--at", String(nowAt / 60));
156
+ col.append(line);
157
+ }
158
+ col.addEventListener("click", (e) => {
159
+ const when = this.when;
160
+ if (e.target !== col || !this.adds || !when) return;
161
+ const r = col.getBoundingClientRect(),
162
+ mins = first * 60 + Math.floor((((e.clientY - r.top) / r.height) * this.#span * 60) / 30) * 30,
163
+ length = this.#length;
164
+ this.add({
165
+ [when.name]: local(d * DAY + mins * MIN),
166
+ ...(length ? { [length.name]: "PT1H" } : {}),
167
+ });
168
+ });
169
+ return col;
170
+ }
171
+ get #span() {
172
+ return Number(this.style.getPropertyValue("--hours")) || 12;
173
+ }
174
+ /** An item's block: its time and its words; moved by a drag, made longer or shorter by its foot. */
175
+ #block(p: Placed, first: number) {
176
+ const when = this.when!.name,
177
+ length = this.#length?.name,
178
+ w = String(p.it.data[when]),
179
+ at = local(wall(w)).slice(11, 16),
180
+ b = el(
181
+ "button",
182
+ { type: "button", className: "item block", part: "item", title: `${at} ${this.named(p.it)}` },
183
+ el("span", { className: "at" }, at),
184
+ " ",
185
+ el("span", { className: "what" }, this.named(p.it)),
186
+ );
187
+ b.style.setProperty("--top", String((p.from - first * 60) / 60));
188
+ b.style.setProperty("--len", String(p.mins / 60));
189
+ b.style.setProperty("--lane", String(p.lane));
190
+ b.style.setProperty("--lanes", String(p.lanes));
191
+ b.toggleAttribute("short", p.mins < 45);
192
+ const hourPx = () => b.parentElement!.getBoundingClientRect().height / this.#span,
193
+ colPx = () => b.parentElement!.getBoundingClientRect().width;
194
+ this.press(
195
+ b,
196
+ p.it,
197
+ this.may(p.it, when)
198
+ ? (dx, dy, done) => {
199
+ const mins = Math.round(((dy / hourPx()) * 60) / SNAP) * SNAP,
200
+ // on a phone, one day is shown: a drag moves within it
201
+ days = phone.matches ? 0 : Math.round(dx / colPx());
202
+ b.style.translate = done ? "" : `${days * colPx()}px ${(mins / 60) * hourPx()}px`;
203
+ if (done && (mins || days)) void this.change(p.it, { [when]: local(wall(w) + days * DAY + mins * MIN) });
204
+ }
205
+ : undefined,
206
+ );
207
+ if (length && this.may(p.it, length)) {
208
+ const foot = el("span", { className: "foot", ariaHidden: "true" });
209
+ foot.addEventListener("pointerdown", (down) => {
210
+ down.stopPropagation();
211
+ let mins = p.mins;
212
+ follow(
213
+ down,
214
+ (e) => {
215
+ mins = Math.max(SNAP, Math.round((p.mins + ((e.clientY - down.clientY) / hourPx()) * 60) / SNAP) * SNAP);
216
+ b.style.setProperty("--len", String(mins / 60));
217
+ b.title = lasts(`PT${mins}M`);
218
+ },
219
+ (e) => {
220
+ if (e && mins !== p.mins)
221
+ void this.change(p.it, {
222
+ [length]: iso(mins),
223
+ });
224
+ else this.again();
225
+ },
226
+ );
227
+ });
228
+ b.append(foot);
229
+ }
230
+ return b;
231
+ }
232
+ }
233
+
234
+ /** Those at once on a day, side by side: each its lane, and how many lanes its cluster takes. */
235
+ function side(day: Placed[]) {
236
+ day.sort((a, b) => a.from - b.from || b.mins - a.mins);
237
+ let cluster: Placed[] = [],
238
+ end = -1;
239
+ const close = () => {
240
+ const lanes = Math.max(1, ...cluster.map((p) => p.lane + 1));
241
+ for (const p of cluster) p.lanes = lanes;
242
+ cluster = [];
243
+ };
244
+ for (const p of day) {
245
+ if (p.from >= end) close();
246
+ const taken = new Set(cluster.filter((q) => q.from + q.mins > p.from).map((q) => q.lane));
247
+ let lane = 0;
248
+ while (taken.has(lane)) lane++;
249
+ p.lane = lane;
250
+ cluster.push(p);
251
+ end = Math.max(end, p.from + p.mins);
252
+ }
253
+ close();
254
+ }