@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
package/src/month.css ADDED
@@ -0,0 +1,125 @@
1
+ /* <j-month> (./month.ts), in its shadow: its head, the days' names, six weeks of days, and under them the marked
2
+ day's items with Add. Wide, each day says its items; on a phone, a mark, and the marked day's are listed. */
3
+ .names,
4
+ .days {
5
+ display: grid;
6
+ grid-template-columns: repeat(7, minmax(0, 1fr));
7
+ }
8
+ .names {
9
+ padding: 0 0 var(--space-4);
10
+ color: var(--muted);
11
+ font: var(--font-tiny);
12
+ text-align: center;
13
+ }
14
+ .days {
15
+ border-top: 1px solid var(--line);
16
+ }
17
+ .day {
18
+ position: relative;
19
+ box-sizing: border-box;
20
+ min-width: 0;
21
+ min-height: calc(var(--space-64) + var(--space-24));
22
+ display: flex;
23
+ flex-direction: column;
24
+ align-items: stretch;
25
+ gap: var(--space-4);
26
+ padding: var(--space-4);
27
+ border-bottom: 1px solid var(--line);
28
+ border-left: 1px solid var(--line);
29
+ }
30
+ .day:nth-child(7n + 1) {
31
+ border-left: 0;
32
+ }
33
+ .day[away] > .n {
34
+ color: var(--edge);
35
+ }
36
+ .day[over] {
37
+ background: var(--card-hover);
38
+ box-shadow: inset 0 0 0 1px var(--accent);
39
+ }
40
+ /* a day's number: a tap marks the day. Today's is ringed; the marked day's filled */
41
+ .n {
42
+ align-self: flex-start;
43
+ box-sizing: border-box;
44
+ min-width: var(--space-24);
45
+ height: var(--space-24);
46
+ padding: 0 var(--space-4);
47
+ border: 1px solid transparent;
48
+ border-radius: var(--radius-pill);
49
+ background: none;
50
+ color: var(--ink);
51
+ font: var(--font-small);
52
+ font-variant-numeric: tabular-nums;
53
+ cursor: pointer;
54
+ }
55
+ .n:hover {
56
+ border-color: var(--control-edge);
57
+ }
58
+ .n[today] {
59
+ border-color: var(--ink);
60
+ }
61
+ .n[aria-current] {
62
+ border-color: var(--accent);
63
+ background: var(--accent);
64
+ color: var(--card);
65
+ }
66
+ /* the mark that a day has items: shown where their words aren't (on a phone) */
67
+ .mark {
68
+ display: none;
69
+ align-self: center;
70
+ width: var(--space-6);
71
+ height: var(--space-6);
72
+ border-radius: var(--radius-dot);
73
+ background: var(--accent);
74
+ }
75
+ /* the marked day, under the month: its name, Add, and its items, each a row */
76
+ .that-day {
77
+ padding: var(--space-8) var(--space-16) var(--space-12);
78
+ }
79
+ .that-day > header {
80
+ display: flex;
81
+ align-items: center;
82
+ gap: var(--space-8);
83
+ min-height: var(--size-touch);
84
+ }
85
+ .that-day h4 {
86
+ flex: 1;
87
+ margin: 0;
88
+ font: var(--font-label);
89
+ }
90
+ .that-day ul {
91
+ display: grid;
92
+ gap: var(--space-6);
93
+ margin: var(--space-8) 0 0;
94
+ padding: 0;
95
+ list-style: none;
96
+ }
97
+ .that-day ul:empty {
98
+ display: none;
99
+ }
100
+ .that-day .item {
101
+ width: 100%;
102
+ min-height: var(--size-touch);
103
+ padding: 0 var(--space-12);
104
+ font: var(--font-row);
105
+ }
106
+ @media (max-width: 40rem) {
107
+ .day {
108
+ min-height: var(--size-finger);
109
+ align-items: center;
110
+ padding: var(--space-4) 0;
111
+ }
112
+ .n {
113
+ align-self: center;
114
+ }
115
+ .day > .item {
116
+ display: none;
117
+ }
118
+ .mark {
119
+ display: block;
120
+ }
121
+ .that-day .item,
122
+ .that-day .adding {
123
+ min-height: var(--size-finger);
124
+ }
125
+ }
package/src/month.ts ADDED
@@ -0,0 +1,179 @@
1
+ // <j-month for="plans" when="when"> (joined/kit): a collection read by its days, a month of them. Each day its number
2
+ // and the items that are that day's, each its time and its words, the way into it; a day tapped is marked, and under
3
+ // the month its items are listed, with Add on that day where this person may add (the sheet offered that day, still
4
+ // asked). An item dragged to another day keeps its hour (where its `may` lets it move). On a phone a day's items are
5
+ // a mark, and the marked day's are listed under the month, each a finger tall. The month shown is kept in the address.
6
+ // Small (`small`, what a time in a row pops), each day's items are a mark alone, and the month shown is its own `day`.
7
+
8
+ import { icon, iconButton } from "./icons.ts";
9
+ import { keep, type Row } from "./keep.ts";
10
+ import { el, Reading } from "./reading.ts";
11
+ import type { Item } from "./rows.ts";
12
+ import { DAY, dated, dayOf, firstOf, gridOf, local, now, wall } from "./time.ts";
13
+ import STYLE from "./month.css" with { type: "text" };
14
+
15
+ const SHEET = new CSSStyleSheet();
16
+ SHEET.replaceSync(STYLE);
17
+ const LONG: Intl.DateTimeFormatOptions = { weekday: "long", day: "numeric", month: "long" };
18
+
19
+ export class JMonth extends Reading {
20
+ static override sheets = [SHEET];
21
+ static observedAttributes = ["day", "small"];
22
+ #name = el("h3");
23
+ #grid = el("div", { className: "days", role: "grid" });
24
+ #under = el("section", { className: "that-day" });
25
+ #heading = el("h4");
26
+ #adding = el("button", { type: "button", className: "act small adding" });
27
+ #list = el("ul");
28
+ #days = new Map<string, { shows: string; el: HTMLElement }>();
29
+ #rows = new Map<string, { shows: string; el: HTMLElement }>();
30
+
31
+ attributeChangedCallback() {
32
+ this.again();
33
+ }
34
+ get small() {
35
+ return this.hasAttribute("small");
36
+ }
37
+ override get day() {
38
+ const own = this.getAttribute("day");
39
+ return this.small && own ? dayOf(own) : super.day;
40
+ }
41
+ /** Small, the month shown is its own, never the address's. */
42
+ override set day(d: number) {
43
+ if (this.small) this.setAttribute("day", local(d * DAY).slice(0, 10));
44
+ else super.day = d;
45
+ }
46
+ protected made() {
47
+ const names = el("div", { className: "names", ariaHidden: "true" });
48
+ // Monday first, as the grid is
49
+ for (let i = 0; i < 7; i++) names.append(el("span", {}, dated(4 + i, { weekday: "short" })));
50
+ const step = (by: number) => () => {
51
+ const d = new Date(this.day * DAY),
52
+ to = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + by, 1)),
53
+ last = new Date(Date.UTC(to.getUTCFullYear(), to.getUTCMonth() + 1, 0)).getUTCDate();
54
+ to.setUTCDate(Math.min(d.getUTCDate(), last));
55
+ this.day = to.getTime() / DAY;
56
+ };
57
+ const today = el("button", { type: "button", className: "act small today" }, "Today");
58
+ today.addEventListener("click", () => (this.day = dayOf(now())));
59
+ this.#adding.addEventListener("click", () => {
60
+ const f = this.when;
61
+ if (f) this.add({ [f.name]: `${local(this.day * DAY).slice(0, 10)}T09:00:00` });
62
+ });
63
+ this.#under.append(el("header", {}, this.#heading, this.#adding), this.#list);
64
+ this.root.append(
65
+ el(
66
+ "header",
67
+ { className: "head" },
68
+ this.#name,
69
+ today,
70
+ iconButton("back", "The month before", step(-1)),
71
+ iconButton("on", "The month after", step(1)),
72
+ ),
73
+ names,
74
+ this.#grid,
75
+ this.#under,
76
+ );
77
+ }
78
+ protected draw() {
79
+ const f = this.when;
80
+ if (!f) return;
81
+ const day = this.day,
82
+ first = firstOf(day),
83
+ today = dayOf(now()),
84
+ month = new Date(first * DAY).getUTCMonth();
85
+ this.#name.textContent = dated(first, { month: "long", year: "numeric" });
86
+ const by = new Map<number, Item[]>();
87
+ for (const it of this.items()) {
88
+ const w = it.data[f.name];
89
+ if (typeof w !== "string") continue;
90
+ const d = dayOf(w);
91
+ (by.get(d) ?? by.set(d, []).get(d)!).push(it);
92
+ }
93
+ for (const its of by.values()) its.sort((a, b) => String(a.data[f.name]).localeCompare(String(b.data[f.name])));
94
+ const moves = (it: Item) => this.may(it, f.name);
95
+ keep(
96
+ this.#grid,
97
+ this.#days,
98
+ Array.from({ length: 42 }, (_, i) => gridOf(day) + i).map((d): Row => {
99
+ const its = by.get(d) ?? [],
100
+ away = new Date(d * DAY).getUTCMonth() !== month;
101
+ return {
102
+ key: String(d),
103
+ shows: JSON.stringify([
104
+ away,
105
+ this.small,
106
+ d === day,
107
+ d === today,
108
+ its.map((it) => [it.key, this.named(it), it.data[f.name], this.opened(it), moves(it)]),
109
+ ]),
110
+ make: () => {
111
+ const cell = el("div", { className: "day", role: "gridcell" });
112
+ cell.dataset.day = String(d);
113
+ cell.toggleAttribute("away", away);
114
+ const n = el("button", {
115
+ type: "button",
116
+ className: "n",
117
+ textContent: String(new Date(d * DAY).getUTCDate()),
118
+ ariaLabel: `${dated(d, LONG)}${its.length ? `, ${its.length}` : ""}`,
119
+ });
120
+ if (d === day) n.ariaCurrent = "date";
121
+ n.toggleAttribute("today", d === today);
122
+ n.addEventListener("click", () => (this.day = d));
123
+ cell.append(n);
124
+ if (its.length) cell.append(el("i", { className: "mark" }));
125
+ if (!this.small) cell.append(...its.map((it) => this.#item(it, f.name)));
126
+ return cell;
127
+ },
128
+ };
129
+ }),
130
+ );
131
+ // the marked day's items, under the month: each the way into it, and Add on that day
132
+ this.#under.hidden = this.small;
133
+ this.#heading.textContent = dated(day, LONG);
134
+ this.#adding.hidden = !this.adds;
135
+ if (!this.#adding.childElementCount) this.#adding.append(icon("add"), "Add");
136
+ this.#adding.ariaLabel = `Add on ${dated(day, LONG)}`;
137
+ keep(
138
+ this.#list,
139
+ this.#rows,
140
+ (by.get(day) ?? []).map((it): Row => ({
141
+ key: String(it.key),
142
+ shows: JSON.stringify([this.named(it), it.data[f.name], this.opened(it)]),
143
+ make: () => el("li", {}, this.#item(it, f.name)),
144
+ })),
145
+ );
146
+ this.#list.ariaLabel = dated(day, LONG);
147
+ }
148
+ /** An item on its day: its time (where it has one) and its words; dragged to another day, moved there. */
149
+ #item(it: Item, field: string) {
150
+ const w = String(it.data[field]),
151
+ at = w.slice(11, 16),
152
+ b = el(
153
+ "button",
154
+ { type: "button", className: "item", title: this.named(it) },
155
+ ...(at && at !== "00:00" ? [el("span", { className: "at" }, at), " "] : []),
156
+ this.named(it),
157
+ );
158
+ const cellAt = (e: PointerEvent) =>
159
+ [...this.#grid.children].find((c) => {
160
+ const r = c.getBoundingClientRect();
161
+ return e.clientX >= r.left && e.clientX < r.right && e.clientY >= r.top && e.clientY < r.bottom;
162
+ }) as HTMLElement | undefined;
163
+ this.press(
164
+ b,
165
+ it,
166
+ this.may(it, field)
167
+ ? (dx, dy, done, e) => {
168
+ b.style.translate = done ? "" : `${dx}px ${dy}px`;
169
+ for (const c of this.#grid.children) c.toggleAttribute("over", !done && !!e && c === cellAt(e));
170
+ const to = done && e && cellAt(e);
171
+ if (!to) return;
172
+ const d = Number(to.dataset.day);
173
+ if (d !== dayOf(w)) void this.change(it, { [field]: local(d * DAY + (wall(w) - dayOf(w) * DAY)) });
174
+ }
175
+ : undefined,
176
+ );
177
+ return b;
178
+ }
179
+ }
package/src/page.css CHANGED
@@ -70,6 +70,14 @@
70
70
  opacity: 0.6;
71
71
  }
72
72
 
73
+ /* a drawer docked at the screen's side (the compiled rows say so): the page keeps clear of it, so nothing it's
74
+ about is under it. On a phone it rises from the foot, over the page */
75
+ @media (min-width: 40rem) {
76
+ body[data-docked] {
77
+ margin-inline-end: var(--size-panel);
78
+ }
79
+ }
80
+
73
81
  .bar {
74
82
  display: flex;
75
83
  flex-wrap: wrap;
package/src/page.ts CHANGED
@@ -93,8 +93,9 @@ const socket = {
93
93
  };
94
94
  /** Why a stranger's page is refused a document, the server's words. */
95
95
  const SIGN_IN = "sign in with your link first";
96
- /** How long a socket asked, on waking, has to answer before it's taken as gone. */
97
- const ANSWER = 5000;
96
+ /** How long a socket asked, on waking, has to answer before it's taken as gone: five seconds, unless the page's
97
+ * root says otherwise (`data-answer`, in milliseconds: a test's, so it needn't wait five seconds to see it). */
98
+ const answerIn = () => Number(document.documentElement.dataset.answer) || 5000;
98
99
  const isOpen = () => socket.ws?.readyState === WebSocket.OPEN;
99
100
 
100
101
  // holding a document
@@ -377,8 +378,10 @@ function stillThere(s: WebSocket) {
377
378
  socket.asked = setTimeout(() => {
378
379
  ((s.onclose = s.onmessage = null), s.close());
379
380
  gone(1006);
380
- }, ANSWER);
381
- s.send(JSON.stringify({ subscribe: doc, id: 0 }));
381
+ }, answerIn());
382
+ // (with the version it has: sent only what it missed, and told afresh what it may do, which answers it)
383
+ const had = document.body.dataset[versionKey(doc)];
384
+ s.send(JSON.stringify({ subscribe: doc, id: 0, ...(had ? { since: Number(had) } : {}) }));
382
385
  }
383
386
 
384
387
  /** The socket again, now: when it's time, or as soon as the phone wakes or the network comes back; one that