@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/drawer.ts ADDED
@@ -0,0 +1,248 @@
1
+ // The drawer of a sheet (<j-sheet>, ./sheet.ts): one item's fields as this person may change them, held as a
2
+ // Draft until Save, one write; Remove at its foot, apart, asked first in a modal. A new item is a modal's, never the
3
+ // drawer's (design.md: new and delete are modal, edit is the drawer): asked only what it can't be without (what it
4
+ // needs, its title, what's offered filled in), Add off until it has it; the rest is filled in afterwards, in the
5
+ // drawer. A link to one is chosen as design.md's Choosing says: six or
6
+ // fewer, a select; more, a typeahead. What's open is in the address's hash (#option=2), so Back closes it.
7
+
8
+ import { Draft } from "./draft.ts";
9
+ import type { Answer } from "./page.ts";
10
+ import { control, el, type Asked, type Control } from "./fields.ts";
11
+ import { askFirst, inHash, surface } from "./parts.ts";
12
+ import { Surface } from "./surface.ts";
13
+ import { icon } from "./icons.ts";
14
+ import type { Field, Item, Spec } from "./rows.ts";
15
+
16
+ export { el };
17
+
18
+ let forms = 0;
19
+
20
+ /** What a drawer asks of the display it's in: where it's put, what things are called, and how a write is sent. */
21
+ export type Host = {
22
+ root: ShadowRoot;
23
+ label(f: Field): string;
24
+ title(it: Element): string;
25
+ /** The items a link may be to, as they're on the page: each its key and its title. */
26
+ choices(f: Field): [key: number, words: string][];
27
+ /** The document its items are of, as the page holds it (a guest's, with its code): a file is kept for it. */
28
+ doc(): string;
29
+ add(spec: Spec, value: object): Promise<Answer>;
30
+ /** What's said of a write refused once the drawer has closed (a removal). */
31
+ said(request: Promise<Answer>): void;
32
+ /** Told as the drawer opens on an item or closes: what's open is marked on its row. */
33
+ shown(): void;
34
+ };
35
+
36
+ export class Drawer {
37
+ /** The item in it: one of the document's, "new" for one being added, or none. */
38
+ open: Item | "new" | null = null;
39
+ #form = el("form", { id: `j-form-${++forms}` });
40
+ #box: Surface;
41
+ #ask = surface("wa-dialog", { className: "ask" });
42
+ /** Where a new one is asked: the drawer's form and foot, borrowed. */
43
+ #new = surface("wa-dialog", { className: "modal" });
44
+ #go = el("button", { className: "act ink", name: "go" });
45
+ #gone = el("button", { type: "button", className: "act danger", name: "gone" }, icon("remove"), "Remove");
46
+ #draft: Draft;
47
+ #hash: ReturnType<typeof inHash>;
48
+ /** What a new item is given without being asked (the item it's added under). */
49
+ #given: Record<string, number> = {};
50
+ /** What a new item is offered already filled in, still asked (a calendar's day and hour tapped). */
51
+ #filled: Record<string, unknown> = {};
52
+ /** Each field's control, by its name. */
53
+ #controls = new Map<string, Control>();
54
+ constructor(
55
+ readonly host: Host,
56
+ readonly spec: Spec,
57
+ readonly asks: Asked[],
58
+ items: () => Item[],
59
+ signal: AbortSignal,
60
+ ) {
61
+ const note = el("wa-callout", { className: "note", role: "status", hidden: true, size: "small" });
62
+ this.#form.append(...asks.map((f) => this.#asked(f).el), note);
63
+ const form = this.#form.id,
64
+ foot = el(
65
+ "footer",
66
+ { part: "foot" },
67
+ this.#gone,
68
+ el("button", { type: "button", className: "act", name: "never" }, "Never mind"),
69
+ this.#go,
70
+ );
71
+ // its deeds at the drawer's foot, outside the form, are its own still
72
+ for (const b of foot.querySelectorAll("button")) b.setAttribute("form", form);
73
+ this.#box = new Surface("drawer", this.#form, foot, () => this.show(null), { label: `A ${spec.one}` });
74
+ this.#new.append(el("h2", { slot: "label" }));
75
+ host.root.append(...this.#box.els, this.#ask, this.#new);
76
+ // its ×, Escape or a tap away: as Never mind
77
+ this.#new.addEventListener("wa-hide", (e) => e.target === this.#new && this.open === "new" && this.show(null));
78
+ this.#draft = new Draft(this.#form, note);
79
+ const ask = askFirst(this.#ask);
80
+ // Never mind: a new one let go; an item's changes put back
81
+ this.#draft.never(() => (this.open === "new" ? this.show(null) : this.show(this.open, this.#given, this.#filled)));
82
+ // said again once the control has drawn what's typed: Web Awesome's say whether they're valid only then
83
+ this.#form.addEventListener("input", (e) => {
84
+ this.#shown();
85
+ void (e.target as { updateComplete?: Promise<unknown> }).updateComplete?.then(() => this.#shown());
86
+ });
87
+ this.#form.addEventListener("submit", (e) => (e.preventDefault(), void this.#save()));
88
+ this.#gone.addEventListener("click", () => {
89
+ const it = this.open as Item;
90
+ ask(`${host.title(it)} will be removed.`, () => (this.show(null), host.said(it.removeItem!())));
91
+ });
92
+ this.#hash = inHash(
93
+ spec.one,
94
+ items,
95
+ () => (this.open === "new" ? null : this.open),
96
+ (it) => this.show(it, {}, {}, false),
97
+ signal,
98
+ );
99
+ }
100
+ #control = (name: string) => this.#form.elements.namedItem(name) as HTMLInputElement | HTMLSelectElement;
101
+ /** A field as the drawer asks for it, in its label, as its kind says (./fields.ts). */
102
+ #asked(f: Asked) {
103
+ const c = control(f, this.host.label(f), {
104
+ choices: () => this.#offered(f),
105
+ // what's offered may follow what's chosen (a field's `not`)
106
+ changed: () => (this.#shown(), this.asks.some((a) => a.not) && this.#choices()),
107
+ doc: () => this.host.doc(),
108
+ });
109
+ this.#controls.set(f.name, c);
110
+ return c;
111
+ }
112
+ /** What a link may be to: the page's items, but none its field `not` holds now (an owner never offered as their own
113
+ * accountant), unless it's linked to them already. */
114
+ #offered(f: Asked) {
115
+ const all = this.host.choices(f);
116
+ if (!f.not) return all;
117
+ const out = new Set(this.#holds(f.not)),
118
+ mine = new Set(this.#holds(f.name));
119
+ return all.filter(([key]) => !out.has(key) || mine.has(key));
120
+ }
121
+ /** The ids a field holds now: as it's chosen in the form where it's asked, else as the open item has it. */
122
+ #holds(name: string): number[] {
123
+ const c = this.#controls.get(name),
124
+ box = this.#control(name);
125
+ const v = c && box ? c.kept(box.value) : this.open && this.open !== "new" ? this.open.data[name] : undefined;
126
+ return [v ?? []].flat() as number[];
127
+ }
128
+ /** What each control offers, as the page has it now (the items a link may be to, the people to choose). */
129
+ #choices() {
130
+ for (const f of this.asks) {
131
+ const c = this.#controls.get(f.name)!;
132
+ c.refresh();
133
+ // a link an add needs, chosen from a few: asked for by its select, where it's shown
134
+ if (f.how === "one") {
135
+ const select = this.#control(f.name) as HTMLSelectElement;
136
+ select.required = !!f.needed && !select.hidden && !this.#controls.get(f.name)!.el.hidden;
137
+ }
138
+ }
139
+ }
140
+ #values = (it: Item | null) =>
141
+ Object.fromEntries(
142
+ this.asks.map((f) => [
143
+ f.name,
144
+ this.#controls.get(f.name)!.shown(it?.data[f.name] ?? this.#given[f.name] ?? this.#filled[f.name]),
145
+ ]),
146
+ );
147
+ /** Whether what's typed differs from the item; of a new one, whether it has what an add needs. */
148
+ #shown() {
149
+ if (this.open === "new") return this.#draft.show("new", this.#form.checkValidity() && this.#needs());
150
+ // changed, and ready only where what it needs is still there (a title taken away isn't)
151
+ this.#draft.show(Object.keys(this.#draft.edits()).length ? "changed" : "kept", this.#form.checkValidity());
152
+ }
153
+ /** Whether each link an add needs is chosen (a typeahead's is kept unseen, where the form can't ask for it). */
154
+ #needs = () => this.asks.every((f) => !f.needed || !f.to || f.name in this.#given || this.#control(f.name).value);
155
+ /** The page's items came, went or changed: the choices follow; the one open, gone, closes the drawer; changed
156
+ * elsewhere, what isn't being typed in follows it. */
157
+ refresh() {
158
+ this.#choices();
159
+ this.#hash.again();
160
+ if (!this.open || this.open === "new") return;
161
+ if (!this.open.isConnected) return this.show(null);
162
+ this.#offer(this.open);
163
+ this.#draft.fill(this.#values(this.open));
164
+ this.#shown();
165
+ }
166
+ /** The drawer with an item in it, or a new one (given what it's added under, and offered what's `filled`, which it
167
+ * still asks), or closed; marked in the address. */
168
+ show(it: Item | "new" | null, given: Record<string, number> = {}, filled: Record<string, unknown> = {}, mark = true) {
169
+ this.open = it;
170
+ this.#given = it === "new" ? given : {};
171
+ this.#filled = it === "new" ? filled : {};
172
+ // what shows the collection marks the one open (design.md, "A row"), and no other
173
+ document.dispatchEvent(new CustomEvent("j-open", { detail: { for: this.spec.name } }));
174
+ this.#box.open = !!it && it !== "new";
175
+ this.#asking(it === "new");
176
+ if (mark) this.#hash.mark(it && it !== "new" ? it.key : null);
177
+ this.host.shown();
178
+ if (!it) return;
179
+ const item = it === "new" ? null : it;
180
+ this.#box.title.textContent = item ? `Editing “${this.host.title(item)}”` : `A new ${this.spec.one}`;
181
+ this.#offer(item);
182
+ this.#choices();
183
+ this.#draft.refuse("");
184
+ // afresh: WebKit keeps a datetime-local box set back to "" invalid until its form is reset
185
+ this.#form.reset();
186
+ void this.#draft.fill(this.#values(item), true).then(() => this.#shown());
187
+ this.#choices();
188
+ this.#shown();
189
+ }
190
+ /** The fields offered: of an item, what this person may change (its `may`, which may come after it, as a page
191
+ * opened on it from its address is sent it); of a new one, what it can't be without, and isn't given already. */
192
+ #offer(item: Item | null) {
193
+ const may = (item?.getAttribute("may") ?? "").split(" ");
194
+ for (const f of this.asks) {
195
+ const label = this.#controls.get(f.name)!.el;
196
+ // an item's: what this person may change; a new one's: what it can't be without, and isn't given already
197
+ label.hidden = item
198
+ ? !f.readonly && !may.includes(`replace:${f.name}`)
199
+ : f.name in this.#given || !(f.needed || f.name === this.spec.title || f.name in this.#filled);
200
+ if (!f.to && f.type !== "place") {
201
+ const box = this.#control(f.name);
202
+ box.required = !!f.needed && f.type !== "boolean" && !label.hidden;
203
+ // said once it's there, asked as it's added
204
+ if (f.readonly) (box.toggleAttribute("readonly", !!item), box.toggleAttribute("without-steppers", !!item));
205
+ }
206
+ }
207
+ this.#gone.hidden = !may.includes("remove");
208
+ }
209
+ /** A new one asked in the modal, its form and foot borrowed from the drawer; else they're the drawer's again. */
210
+ #asking(on: boolean) {
211
+ const foot = this.#go.parentElement!;
212
+ this.#go.replaceChildren(icon(on ? "add" : "check"), on ? "Add" : "Save");
213
+ if (on) {
214
+ this.#new.querySelector("h2")!.textContent = `A new ${this.spec.one}`;
215
+ foot.slot = "footer";
216
+ this.#new.append(this.#form, foot);
217
+ } else if (this.#form.parentElement === this.#new) this.#box.hold();
218
+ this.#new.open = on;
219
+ }
220
+ /** Save: the changes in one write, or the new item added; refused, why is said here, and what's typed stays. */
221
+ async #save() {
222
+ const adding = this.open === "new",
223
+ item = this.open as Item;
224
+ const typed = Object.entries(this.#draft.edits()).map(
225
+ ([name, v]) => [name, typeof v === "string" ? v.trim() : v] as const,
226
+ );
227
+ // an item's field emptied: words kept as none; anything else taken off it, where a story takes it off
228
+ const words = (name: string) => this.asks.find((f) => f.name === name)?.type === "string",
229
+ cleared = adding ? [] : typed.filter(([name, v]) => v === "" && !words(name)).map(([name]) => name),
230
+ stays = cleared.find((name) => !(item.getAttribute("may") ?? "").split(" ").includes(`remove:${name}`));
231
+ const edits = Object.fromEntries(
232
+ typed
233
+ .filter(([name, v]) => v !== "" || (!adding && words(name)))
234
+ .map(([name, v]) => [name, this.#controls.get(name)!.kept(v)]),
235
+ );
236
+ const was = this.open;
237
+ const why = adding
238
+ ? await this.host.add(this.spec, { ...this.#given, ...this.#filled, ...edits })
239
+ : stays
240
+ ? `${stays} can't be left empty`
241
+ : ((Object.keys(edits).length ? await item.replace!(edits) : undefined) ??
242
+ (cleared.length ? await item.removeField!(...cleared) : undefined));
243
+ // what was saved, if it's open still: one opened meanwhile (a new one asked) is left as it is
244
+ if (this.open !== was) return;
245
+ this.#draft.refuse(why ?? "");
246
+ if (!why) this.show(adding ? null : was);
247
+ }
248
+ }