@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
@@ -0,0 +1,30 @@
1
+ // What bun run look cafe draws: the menu's page, composed of joined's kit, in each state it has, each put there as the
2
+ // manager would (act). Looked at wide and on a phone, light and dark.
3
+
4
+ const rows = `document.querySelector("j-items-rows").shadowRoot`,
5
+ sheet = `document.querySelector("j-sheet").shadowRoot`,
6
+ form = `${sheet}.querySelector("form")`,
7
+ row = (name: string) =>
8
+ `[...${rows}.querySelectorAll("button.open")].find((b) => b.textContent.startsWith("${name}"))`,
9
+ search = `document.querySelector("j-search")`,
10
+ find = `${search}.shadowRoot.querySelector("input")`;
11
+ const type = (box: string, words: string) =>
12
+ `(() => { const b = ${box}; b.value = ${JSON.stringify(words)}; b.dispatchEvent(new Event("input", { bubbles: true })); })()`;
13
+
14
+ export const page = "/cafe/menu";
15
+ export const ready = `${rows}.querySelectorAll("button.open:not([disabled])").length > 0 && ${sheet}.querySelector("form")`;
16
+ export const states = [
17
+ { name: "The menu" },
18
+ { name: "An item open", act: `${row("Latte")}.click()` },
19
+ { name: "Typed, not kept", act: `${row("Latte")}.click(); ${type(`${form}.elements.price`, "3.95")}` },
20
+ { name: "Asked before it goes", act: `${row("Latte")}.click(); ${form}.elements.gone.click()` },
21
+ {
22
+ name: "Found",
23
+ act: `${search}.shadowRoot.querySelector(".look").click(); ${type(find, "cro")}`,
24
+ },
25
+ {
26
+ name: "Found, folded",
27
+ act: `${search}.shadowRoot.querySelector(".look").click(); ${type(find, "a")}; ${find}.blur()`,
28
+ },
29
+ { name: "A new item", act: `${rows}.querySelector("button.adding").click()` },
30
+ ];
@@ -13,7 +13,7 @@
13
13
  <a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
14
14
  <header class="band">
15
15
  <h1>The menu</h1>
16
- <p class="lead">What the cafe sells, its prices and what's left. The manager changes an item in a drawer.</p>
16
+ <p class="lead">What the cafe sells, its prices and what's left. The manager changes an item in its sheet.</p>
17
17
  <nav class="bar">
18
18
  <members-panel></members-panel>
19
19
  <a href="/cafe">The cafe</a> <a href="/cafe/till" data-holds="till">Till</a>
@@ -24,32 +24,16 @@
24
24
  </nav>
25
25
  </header>
26
26
  <main class="cafe menu">
27
- <section class="card" aria-label="The menu">
28
- <j-items doc="menu"></j-items>
29
- </section>
27
+ <wa-card class="card" aria-label="The menu">
28
+ <header class="find"><j-search for="items" placeholder="Find on the menu"></j-search></header>
29
+ <j-items-rows><j-items doc="menu"></j-items></j-items-rows>
30
+ </wa-card>
30
31
  </main>
31
- <aside class="drawer" hidden aria-label="An item">
32
- <form class="item">
33
- <header>
34
- <h2></h2>
35
- <button
36
- type="button"
37
- class="icon-only"
38
- name="close"
39
- aria-label="Close"
40
- title="Close"
41
- data-icon="close"
42
- ></button>
43
- </header>
44
- <label>Name<input name="name" required autocomplete="off" /></label>
45
- <label>Price, £<input name="price" required inputmode="decimal" pattern="\d+(\.\d{1,2})?" /></label>
46
- <p class="note" role="status"></p>
47
- <footer>
48
- <button type="button" class="act" name="never">Never mind</button>
49
- <button class="act ink" name="go" data-icon="check">Save</button>
50
- </footer>
51
- </form>
52
- </aside>
32
+ <j-sheet for="items">
33
+ <j-field name="name"></j-field>
34
+ <j-field name="price" as="money" currency="GBP"></j-field>
35
+ <j-field name="stock" label="Left" readonly></j-field>
36
+ </j-sheet>
53
37
  <script type="module" src="./menu.ts"></script>
54
38
  </body>
55
39
  </html>
@@ -1,84 +1,12 @@
1
- // The menu's page: each item a row (its name, its price, what's left), and an item changed in a drawer, the smallest
2
- // to copy: a Draft (joined/draft) holds what's typed until Save, one write; Never mind puts it back; a change made
3
- // elsewhere fills what isn't being typed in, and keeps what is. Refused, why is said in it, and what was typed stays.
4
- // What's open is in the URL's hash (#item=3, inHash), so Back closes it and a link opens it. Only the manager may
5
- // change an item, as its may says: no one else is offered the drawer.
1
+ // The menu's page, composed of joined's kit alone (joined/kit, the skill's §17): its items as rows (joined/rows), a
2
+ // search among them, and an item's sheet, each bound to the menu by the collection's name. What the page says is in
3
+ // its markup: the price is money, in pence kept and in pounds typed and read; what's left is said, never changed
4
+ // there. Only the manager may change an item, as its may says: to anyone else a row is its words alone.
6
5
 
7
6
  import "joined/panel";
8
7
  import "joined/toast";
9
- import { Draft } from "joined/draft";
10
- import { iconButton, iconify } from "joined/icons";
11
- import { inHash } from "joined/parts";
12
- import * as menu from "./generated/menu.rules.ts";
13
- import { JItem } from "./generated/menu.elements.ts";
14
- import { money } from "./views.ts";
8
+ import "joined/kit";
9
+ import { define } from "joined/rows";
10
+ import { JItemsRows } from "./generated/menu.rows.ts";
15
11
 
16
- const drawer = document.querySelector<HTMLElement>("aside.drawer")!,
17
- form = drawer.querySelector("form")!,
18
- draft = new Draft(form, form.querySelector(".note")!);
19
- /** The item in the drawer, if one is. */
20
- let open: Item | null = null;
21
- /** An item as the drawer holds it: its name, and its price in pounds, as it's typed. */
22
- const fields = (it: Item) => ({ name: it.data.name, price: (it.data.price / 100).toFixed(2) });
23
- /** Whether what's typed differs from the item: Save and Never mind offered then, and said. */
24
- const shown = () => draft.show(Object.keys(draft.edits()).length ? "changed" : "kept");
25
-
26
- /** An item's row: its name, price and what's left, and a way into the drawer where its person may change it. */
27
- class Item extends JItem {
28
- #words = document.createElement("span");
29
- #edit = iconButton("edit", "", () => show(this));
30
- connectedCallback() {
31
- if (!this.childElementCount) this.append(this.#words, this.#edit);
32
- this.draw();
33
- hash.again(); // named in the address before it was on the page: opened now it is
34
- }
35
- draw() {
36
- this.#words.textContent = `${this.data.name} ${money(this.data.price)} (${this.data.stock} left)`;
37
- this.#edit.ariaLabel = `Change ${this.data.name}`;
38
- this.#edit.hidden = !this.matches('[may~="replace:name"], [may~="replace:price"]');
39
- // the one in the drawer, changed elsewhere: what isn't being typed in follows it
40
- if (this === open) (draft.fill(fields(this)), shown());
41
- }
42
- }
43
-
44
- /** The drawer, with an item in it, or closed; marked in the hash as it's opened or closed. */
45
- function show(it: Item | null, mark = true) {
46
- open = it;
47
- drawer.hidden = !it;
48
- if (it) {
49
- drawer.querySelector("h2")!.textContent = it.data.name;
50
- draft.refuse("");
51
- draft.fill(fields(it), true);
52
- shown();
53
- }
54
- if (mark) hash.mark(it?.key ?? null);
55
- }
56
- const items = document.getElementsByTagName(menu.collections.items.tag) as HTMLCollectionOf<Item>;
57
- const hash = inHash(
58
- "item",
59
- () => [...items],
60
- () => open,
61
- (it) => show(it, false),
62
- );
63
-
64
- form.addEventListener("input", shown);
65
- form.addEventListener("submit", async (e) => {
66
- e.preventDefault();
67
- if (!open) return;
68
- const { name, price } = draft.edits() as { name?: string; price?: string };
69
- const why = await open.replace({
70
- ...(name !== undefined ? { name: name.trim() } : {}),
71
- ...(price !== undefined ? { price: Math.round(Number(price) * 100) } : {}),
72
- });
73
- draft.refuse(why ?? "");
74
- // kept: what the drawer holds is the item as it is now
75
- if (!why && open) (draft.fill(fields(open), true), shown());
76
- });
77
- draft.inside(
78
- drawer,
79
- () => show(null),
80
- () => open && (draft.refuse(""), draft.fill(fields(open), true), shown()),
81
- );
82
- iconify();
83
- // defined last, once all it draws with is made
84
- customElements.define(menu.collections.items.tag, Item);
12
+ define(JItemsRows);
@@ -0,0 +1,15 @@
1
+ // Made by `bun run compile` from the stories, its change by hand: a supply's terms.days and terms.by are needed, as
2
+ // every add gives them and every supply of the seed has them in its terms (the compiler read the seed's objects
3
+ // unopened before, so they were left optional). SQLite makes the table again without them empty; Postgres's are
4
+ // made needed in place.
5
+ import { guardTable, type Up } from "joined/migrate";
6
+
7
+ export const changes = [
8
+ guardTable("supplies", { columns: { title: { type: "text", is: { type: "string", said: "title is a string" } }, item: { type: "integer", is: { type: "integer", said: "item is a whole number" }, to: { table: "items", said: "item links only to items the menu document holds", held: ["supply in supplies links to it", "supplys in supplies link to it"] } }, qty: { type: "integer", is: { type: "integer", said: "qty is a whole number" } }, price: { type: "integer", is: { type: "integer", said: "price is a whole number" } }, buyer: { type: "integer", nullable: true, is: { type: "integer", said: "buyer is a whole number" }, to: { table: "members", said: "buyer links only to members the members document holds", onDelete: "set null" } }, supplier: { type: "integer", nullable: true, is: { type: "integer", said: "supplier is a whole number" }, to: { table: "members", said: "supplier links only to members the members document holds", onDelete: "set null" } }, "terms.days": { type: "integer", is: { type: "integer", said: "terms.days is a whole number" } }, "terms.by": { type: "text", is: { type: "string", said: "terms.by is a string" } }, delivered: { type: "boolean", is: { type: "boolean", said: "delivered is a boolean" } } }, strict: true, needs: { columns: ["title", "item", "qty", "price", "buyer", "supplier", "terms.days", "terms.by", "delivered"], said: "a supply needs title (string), item (an id in items), qty (integer), price (integer), buyer (an id in members), supplier (an id in members), terms.days (integer), terms.by (string), delivered (boolean)" } }),
9
+ ];
10
+
11
+ export const up: Up = (db) => {
12
+ if (db.dialect === "postgres")
13
+ for (const column of ["terms.days", "terms.by"])
14
+ db.run(`ALTER TABLE supplies ALTER COLUMN "${column}" SET NOT NULL`);
15
+ };
@@ -10,12 +10,13 @@
10
10
  <link rel="stylesheet" href="./cafe.css" />
11
11
  </head>
12
12
  <body data-flavour="bondi">
13
+ <a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
13
14
  <header class="band">
14
15
  <h1>Your order</h1>
15
16
  </header>
16
17
  <main class="cafe yours">
17
- <section class="card" aria-label="Your order">
18
- <ol class="steps">
18
+ <wa-card class="card" aria-label="Your order">
19
+ <ol class="steps" aria-label="Where it is">
19
20
  <li data-step="placed">Placed</li>
20
21
  <li data-step="being made">Being made</li>
21
22
  <li data-step="ready">Ready</li>
@@ -23,15 +24,15 @@
23
24
  </ol>
24
25
  <j-orders doc="order?code="></j-orders>
25
26
  <j-lines doc="order?code="></j-lines>
26
- </section>
27
+ </wa-card>
27
28
  </main>
28
- <dialog class="ask">
29
- <h2></h2>
30
- <footer>
29
+ <wa-dialog class="ask" light-dismiss>
30
+ <h2 slot="label"></h2>
31
+ <footer slot="footer">
31
32
  <button type="button" class="act" name="keep">Never mind</button>
32
33
  <button type="button" class="act danger" name="sure">Cancel it</button>
33
34
  </footer>
34
- </dialog>
35
+ </wa-dialog>
35
36
  <script type="module" src="./order.ts"></script>
36
37
  </body>
37
38
  </html>
@@ -22,8 +22,12 @@ const SAYS: Record<string, string> = {
22
22
  };
23
23
  const Order = orderView(
24
24
  JOrder,
25
- [{ words: "Cancel my order", from: "placed", to: "cancelled", ask: "Cancel your order?" }],
26
- askFirst(document.querySelector("dialog.ask")!),
25
+ [{ words: "Cancel my order", from: "placed", to: "cancelled", ask: "Your order will be cancelled." }],
26
+ askFirst(
27
+ document.querySelector("wa-dialog.ask")!,
28
+ "Cancel it",
29
+ "The cafe sees it at once, and it can't be taken back.",
30
+ ),
27
31
  { late: false }, // a customer is never told it's late: that's the staff's to know
28
32
  );
29
33
  /** Where the order is, and what the cafe says of it: the order this page holds, as it is now. */
@@ -20,7 +20,6 @@ import * as suppliesDoc from "./generated/supplies.rules.ts";
20
20
  import * as booksDoc from "./generated/books.rules.ts";
21
21
 
22
22
  export const documents = [staffDoc, menuDoc, tillDoc, kitchenDoc, orderDoc, suppliesDoc, booksDoc];
23
- export { trust } from "./trust.ts";
24
23
  export const routes = {
25
24
  "/cafe": front,
26
25
  "/cafe/till": till,
@@ -15,6 +15,11 @@
15
15
  "id": 3,
16
16
  "role": "kitchen",
17
17
  "members": [4, 1]
18
+ },
19
+ {
20
+ "id": 4,
21
+ "role": "supplier",
22
+ "members": [2]
18
23
  }
19
24
  ]
20
25
  }
@@ -1,5 +1,5 @@
1
1
  {"cast":{"wai":"nora","cook":"dev","manager":"peter","buyer":"peter","roaster":"nick"}}
2
- {"links":{"item":{"to":"items","one":true},"order":{"to":"orders","one":true},"buyer":{"to":"members","one":true},"supplier":{"to":"members","one":true}}}
2
+ {"links":{"item":{"to":"items","one":true},"order":{"to":"orders","one":true,"part":true},"buyer":{"to":"members","one":true},"supplier":{"to":"members","one":true,"holds":"staff/posts[role=supplier]@members"}}}
3
3
  {"roles":{"manager":"staff/posts[role=manager]@members","till":"staff/posts[role=till]@members","kitchen":"staff/posts[role=kitchen]@members","buyer":"@buyer","supplier":"@supplier"}}
4
4
  {"owns":{"supplies":"@buyer | @supplier"}}
5
5
  {"fills":{"orders":{"status":"placed","placed":"now","code":"random","total":0}}}
@@ -12,7 +12,10 @@
12
12
  {"takes":{"lines":{"qty":"item.stock","while":"order.status!=cancelled","refused":"The kitchen has {stock} of {name}: not enough to take {qty}."}}}
13
13
  {"gives":{"supplies":{"qty":"item.stock","while":"delivered","refused":"The kitchen has {stock} of {name}: not enough to take {qty}."}}}
14
14
  {"documents":{"books":{"entries":{"from":"supplies","when":"delivered","sides":{"buyer":"bought","supplier":"sold"},"fields":["title","buyer","supplier"],"total":{"sum":"qty","times":"price"}}}}}
15
+ {"addedWith":{"lines":{"order":"an order's lines are set when it's placed"}}}
16
+ {"frozen":{"supplies":{"by":"delivered","fields":["price","terms"],"refused":"a delivered supply keeps its price and terms"}}}
15
17
  {"story":"Peter puts Dev in the kitchen too","as":"manager","does":{"doc":"staff","ops":[{"op":"add","path":"/posts/-","value":{"role":"kitchen","members":[4]}}]},"seen":["manager"]}
18
+ {"story":"Peter takes Nora off the till","as":"manager","does":{"doc":"staff","ops":[{"op":"replace","path":"/posts/2/members","value":[1]}]},"seen":["manager"]}
16
19
  {"story":"Wai can't give anyone a role","as":"wai","cannot":{"doc":"staff","ops":[{"op":"add","path":"/posts/-","value":{"role":"till","members":[4]}}]},"refused":"you may not add at /posts/-"}
17
20
  {"story":"Peter puts muffins on the menu","as":"manager","does":{"doc":"menu","ops":[{"op":"add","path":"/items/-","value":{"name":"Muffin","price":300,"stock":12}}]},"seen":["manager","wai"]}
18
21
  {"story":"Peter prices a latte at £3.80","as":"manager","does":{"doc":"menu","ops":[{"op":"replace","path":"/items/3/price","value":380}]},"seen":["manager","wai"]}
@@ -39,5 +42,6 @@
39
42
  {"story":"Nick delivers: the kitchen has twenty more croissants","as":"roaster","does":{"doc":"supplies","ops":[{"op":"replace","path":"/supplies/1/delivered","value":true}]},"seen":["roaster","buyer"],"then":{"menu/items/5/stock":22}}
40
43
  {"story":"Peter can't say it's delivered: that's Nick's","as":"buyer","cannot":{"doc":"supplies","ops":[{"op":"replace","path":"/supplies/1/delivered","value":true}]},"refused":"you may not replace at /supplies/1/delivered"}
41
44
  {"story":"Nora can't order in Peter's name","as":"wai","cannot":{"doc":"supplies","ops":[{"op":"add","path":"/supplies/-","value":{"title":"Croissants, Monday","item":5,"qty":20,"price":120,"buyer":1,"supplier":2,"terms":{"days":14,"by":"invoice"},"delivered":false}}]},"refused":"you may not add at /supplies/-"}
45
+ {"story":"Peter can't order from Nora: she isn't a supplier","as":"buyer","cannot":{"doc":"supplies","ops":[{"op":"add","path":"/supplies/-","value":{"title":"Croissants, Monday","item":5,"qty":20,"price":120,"buyer":1,"supplier":3,"terms":{"days":14,"by":"invoice"},"delivered":false}}]},"refused":"supplier names someone who isn't among staff's posts with role supplier"}
42
46
  {"story":"Nick can't change his price once it's delivered: both books have it","as":"roaster","cannot":{"doc":"supplies","ops":[{"op":"replace","path":"/supplies/2/price","value":200}]},"refused":"a delivered supply keeps its price and terms"}
43
- {"story":"Nick can't take back a delivery the kitchen has used","as":"roaster","cannot":{"doc":"supplies","ops":[{"op":"replace","path":"/supplies/2/delivered","value":false}]},"refused":"The kitchen has 2 of Croissant: not enough to take 30."}
47
+ {"story":"Taking back a delivery takes it from stock, while there's stock: Nick can't take back 30 croissants when the kitchen has 2","as":"roaster","cannot":{"doc":"supplies","ops":[{"op":"replace","path":"/supplies/2/delivered","value":false}]},"refused":"The kitchen has 2 of Croissant: not enough to take 30."}
@@ -28,50 +28,51 @@
28
28
  </nav>
29
29
  </header>
30
30
  <main class="cafe supplies">
31
- <section class="card" aria-label="Order a supply">
31
+ <wa-card class="card" aria-label="Order a supply">
32
32
  <h2>Order a supply</h2>
33
33
  <form class="add buy">
34
- <label
35
- >What it's for<input name="title" placeholder="Croissants, Monday" required autocomplete="off"
36
- /></label>
37
- <label>Of<select name="item"></select></label>
38
- <label>How many<input name="qty" type="number" min="1" value="10" /></label>
39
- <label
40
- >Price each, £<input name="price" type="number" min="0" step="0.01" value="1.00" inputmode="decimal"
41
- /></label>
42
- <label>From<select name="supplier"></select></label>
34
+ <wa-input
35
+ name="title"
36
+ label="What it's for"
37
+ placeholder="Croissants, Monday"
38
+ required
39
+ autocomplete="off"
40
+ ></wa-input>
41
+ <wa-select name="item" label="Of"></wa-select>
42
+ <wa-number-input name="qty" label="How many" min="1" value="10"></wa-number-input>
43
+ <wa-number-input
44
+ name="price"
45
+ label="Price each, £"
46
+ min="0"
47
+ step="0.01"
48
+ value="1.00"
49
+ inputmode="decimal"
50
+ without-steppers
51
+ ></wa-number-input>
52
+ <wa-select name="supplier" label="From"></wa-select>
43
53
  <button class="act ink" data-icon="add">Order</button>
44
54
  <p class="said" role="status"></p>
45
55
  </form>
46
56
  <j-items doc="menu" hidden></j-items>
47
- </section>
48
- <section class="card" aria-label="Supplies">
57
+ <j-posts doc="staff" hidden></j-posts>
58
+ </wa-card>
59
+ <wa-card class="card" aria-label="Supplies">
49
60
  <h2>Supplies</h2>
50
61
  <j-supplies doc="supplies"></j-supplies>
51
- </section>
62
+ </wa-card>
52
63
  </main>
53
- <aside class="drawer" hidden aria-label="A supply's terms">
54
- <form class="terms">
55
- <header>
56
- <h2></h2>
57
- <button
58
- type="button"
59
- class="icon-only"
60
- name="close"
61
- aria-label="Close"
62
- title="Close"
63
- data-icon="close"
64
- ></button>
65
- </header>
66
- <label>Price each, £<input name="price" required inputmode="decimal" pattern="\d+(\.\d{1,2})?" /></label>
67
- <label>Days to pay<input name="days" required type="number" min="0" step="1" /></label>
68
- <p class="note" role="status"></p>
69
- <footer>
70
- <button type="button" class="act" name="never">Never mind</button>
71
- <button class="act ink" name="go" data-icon="check">Save</button>
72
- </footer>
64
+ <!-- a supply's terms: the drawer (joined/surface) is made of these -->
65
+ <template class="terms">
66
+ <form class="terms" id="terms">
67
+ <wa-input name="price" label="Price each, £" required inputmode="decimal" pattern="\d+(\.\d{1,2})?"></wa-input>
68
+ <wa-number-input name="days" label="Days to pay" required min="0" step="1"></wa-number-input>
69
+ <wa-callout class="note" role="status" size="small" hidden></wa-callout>
73
70
  </form>
74
- </aside>
71
+ <footer>
72
+ <button type="button" class="act" name="never" form="terms">Never mind</button>
73
+ <button class="act ink" name="go" form="terms" data-icon="check">Save</button>
74
+ </footer>
75
+ </template>
75
76
  <script type="module" src="./supplies.ts"></script>
76
77
  </body>
77
78
  </html>
@@ -1,15 +1,18 @@
1
- // The supplies page: the supplies its person is party to, as buyer or supplier, each read from their side and saying
2
- // whose each part is. The supplier sets the price and the days to pay (in the menu's drawer: a Draft, in the hash as
3
- // #supply=1) and says it's delivered, as its may says; the buyer is offered none of it. Delivered, the menu has more
1
+ // The supplies page: the supplies its person is party to, as buyer or supplier, each a row (Row) read from their side
2
+ // and saying whose each part is. Its supplier opens it to set the price and the days to pay (in a drawer: a Draft, in
3
+ // the hash as #supply=1) and says it's delivered by its own button, as its may says; to the buyer each is its words. Delivered, the menu has more
4
4
  // (its gives), and both sides' books have it. Anyone orders one, as its buyer, from another member.
5
5
 
6
6
  import { members, signedIn } from "joined/panel";
7
7
  import "joined/toast";
8
8
  import { Draft } from "joined/draft";
9
- import { iconButton, iconify } from "joined/icons";
10
- import { inHash, said } from "joined/parts";
9
+ import { iconify } from "joined/icons";
10
+ import { docked, inHash, row, said } from "joined/parts";
11
+ import { Surface } from "joined/surface";
11
12
  import * as menu from "./generated/menu.rules.ts";
12
13
  import { JItem } from "./generated/menu.elements.ts";
14
+ import * as staff from "./generated/staff.rules.ts";
15
+ import { JPost } from "./generated/staff.elements.ts";
13
16
  import * as supplies from "./generated/supplies.rules.ts";
14
17
  import { JSupply, type JSupplies } from "./generated/supplies.elements.ts";
15
18
  import { money, nameOf } from "./views.ts";
@@ -23,15 +26,14 @@ const items = document.getElementsByTagName(menu.collections.items.tag) as HTMLC
23
26
  /** Who's who on a supply, from this page's side: you, or their name. */
24
27
  const who = (id?: number) => (id === me ? "you" : nameOf(members, id));
25
28
 
26
- /** A supply: what, how many, at what price and terms, from whom to whom, and whose each part is; where its person is
27
- * its supplier, the way into the drawer for its price and days to pay, and Delivered. */
29
+ /** A supply, a row: its title, and under it where it is, how many at what price and terms, and whose each part is.
30
+ * Its supplier opens it, for its price and days to pay, until it's delivered (then both books have them, kept:
31
+ * trust.ts); to anyone else it's its words alone. Delivered is a button of its own, for it does what opening doesn't. */
28
32
  class Supply extends JSupply {
29
- #head = Object.assign(document.createElement("p"), { className: "head" });
30
- #what = Object.assign(document.createElement("p"), { className: "what" });
31
- #whose = Object.assign(document.createElement("p"), { className: "whose" });
32
- #acts = Object.assign(document.createElement("p"), { className: "acts" });
33
+ #row = row(() => show(this));
34
+ #what = this.#row.el.querySelector(".j-words > span")!;
35
+ #whose = Object.assign(document.createElement("span"), { className: "whose" });
33
36
  #said = Object.assign(document.createElement("p"), { className: "said", role: "status" });
34
- #edit = iconButton("edit", "", () => show(this));
35
37
  #delivered = Object.assign(document.createElement("button"), {
36
38
  type: "button",
37
39
  className: "act ink",
@@ -39,7 +41,11 @@ class Supply extends JSupply {
39
41
  onclick: () => said(this.#said, this.replace({ delivered: true })),
40
42
  });
41
43
  connectedCallback() {
42
- if (!this.childElementCount) this.append(this.#head, this.#what, this.#whose, this.#acts, this.#said);
44
+ if (!this.childElementCount) {
45
+ this.#what.className = "what";
46
+ this.#what.after(this.#whose);
47
+ this.append(this.#row.el, this.#said);
48
+ }
43
49
  this.draw();
44
50
  hash.again(); // named in the address before it was on the page: opened now it is
45
51
  }
@@ -47,24 +53,20 @@ class Supply extends JSupply {
47
53
  if (!this.isConnected) return;
48
54
  const d = this.data;
49
55
  const item = [...items].find((i) => i.key === d.item)?.data.name ?? `item ${d.item}`;
50
- this.#head.replaceChildren(
51
- Object.assign(document.createElement("b"), { textContent: d.title }),
52
- Object.assign(document.createElement("span"), {
53
- className: `pill${d.delivered ? " here" : ""}`,
54
- textContent: d.delivered ? "delivered" : "on its way",
55
- }),
56
+ this.#row.say(
57
+ d.title,
58
+ `${d.delivered ? "Delivered" : "On its way"} · ${d.qty} × ${item} at ${money(d.price)} each, ${money(d.qty * d.price)} · ${d["terms.days"]} days to pay`,
56
59
  );
57
- this.#what.textContent = `${d.qty} × ${item} at ${money(d.price)} each, ${money(d.qty * d.price)} · ${d["terms.days"]} days to pay`;
58
60
  // whose each part is, as this page's person reads it
59
61
  const buying = d.buyer === me,
60
62
  supplying = d.supplier === me;
61
63
  this.#whose.textContent = `${cap(who(d.buyer))} ${buying ? "buy" : "buys"} from ${who(d.supplier)}. ${cap(who(d.supplier))} ${supplying ? "set" : "sets"} the price and the days to pay, and ${supplying ? "say" : "says"} when it's delivered.`;
62
- this.#edit.ariaLabel = `Change your terms for ${d.title}`;
63
- this.#acts.replaceChildren(
64
- // its terms, until it's delivered: then both books have them, kept (trust.ts)
65
- ...(this.matches('[may~="replace:price"], [may~="replace:terms.days"]') && !d.delivered ? [this.#edit] : []),
66
- ...(this.matches('[may~="replace:delivered"]') && !d.delivered ? [this.#delivered] : []),
67
- );
64
+ // its terms, until it's delivered: the row opens them; to anyone else, its words alone
65
+ this.#row.el.disabled = !this.matches('[may~="replace:price"], [may~="replace:terms.days"]') || !!d.delivered;
66
+ this.#row.mark(this === open);
67
+ const delivers = this.matches('[may~="replace:delivered"]') && !d.delivered;
68
+ if (delivers && !this.#delivered.isConnected) this.#row.el.after(this.#delivered);
69
+ if (!delivers) this.#delivered.remove();
68
70
  // the one in the drawer, changed elsewhere: what isn't being typed in follows it
69
71
  if (this === open) (draft.fill(fields(this)), shown());
70
72
  }
@@ -72,8 +74,9 @@ class Supply extends JSupply {
72
74
  const cap = (s: string) => s[0]!.toUpperCase() + s.slice(1);
73
75
 
74
76
  // the supplier's terms, in a drawer, as the menu's item is: held until Save, put back by Never mind
75
- const drawer = document.querySelector<HTMLElement>("aside.drawer")!,
76
- terms = drawer.querySelector("form")!,
77
+ const made = document.querySelector<HTMLTemplateElement>("template.terms")!.content,
78
+ terms = made.querySelector("form")!,
79
+ drawer = new Surface("drawer", terms, made.querySelector("footer")!, () => show(null), { label: "A supply's terms" }),
77
80
  draft = new Draft(terms, terms.querySelector(".note")!);
78
81
  /** The supply in the drawer, if one is. */
79
82
  let open: Supply | null = null;
@@ -83,10 +86,15 @@ const fields = (s: Supply) => ({ price: (s.data.price / 100).toFixed(2), days: S
83
86
  const shown = () => draft.show(Object.keys(draft.edits()).length ? "changed" : "kept");
84
87
  /** The drawer, with a supply in it, or closed; marked in the hash as it's opened or closed. */
85
88
  function show(s: Supply | null, mark = true) {
89
+ const was = open;
86
90
  open = s;
87
- drawer.hidden = !s;
91
+ // docked at the screen's side, the page keeps clear of it (joined/page.css)
92
+ docked(!!s);
93
+ was?.draw();
94
+ s?.draw();
95
+ drawer.open = !!s;
88
96
  if (s) {
89
- drawer.querySelector("h2")!.textContent = `Your terms: ${s.data.title}`;
97
+ drawer.title.textContent = `Your terms: ${s.data.title}`;
90
98
  draft.refuse("");
91
99
  draft.fill(fields(s), true);
92
100
  shown();
@@ -106,11 +114,8 @@ terms.addEventListener("submit", async (e) => {
106
114
  // kept: what the drawer holds is the supply as it is now
107
115
  if (!why && open) (draft.fill(fields(open), true), shown());
108
116
  });
109
- draft.inside(
110
- drawer,
111
- () => show(null),
112
- () => open && (draft.refuse(""), draft.fill(fields(open), true), shown()),
113
- );
117
+ document.body.append(...drawer.els);
118
+ draft.never(() => open && (draft.refuse(""), draft.fill(fields(open), true), shown()));
114
119
  iconify();
115
120
 
116
121
  const form = document.querySelector<HTMLFormElement>("form.buy")!;
@@ -119,21 +124,31 @@ const fill = () => {
119
124
  const options = (sel: string, list: { value: number; text: string }[]) => {
120
125
  const s = form.elements.namedItem(sel) as HTMLSelectElement;
121
126
  const was = s.value;
122
- s.replaceChildren(...list.map((o) => new Option(o.text, String(o.value))));
127
+ s.replaceChildren(
128
+ ...list.map((o) =>
129
+ Object.assign(document.createElement("wa-option"), { value: String(o.value), textContent: o.text }),
130
+ ),
131
+ );
123
132
  if (was) s.value = was;
124
133
  // what was chosen gone from the list (you, before the page knew you): the first chosen, never none
125
- if (s.selectedIndex < 0) s.selectedIndex = 0;
134
+ if (!list.some((o) => String(o.value) === s.value) && list[0]) s.value = String(list[0].value);
126
135
  };
127
136
  options(
128
137
  "item",
129
138
  [...items].map((i) => ({ value: i.key, text: i.data.name })),
130
139
  );
140
+ // a supplier is one of staff's supplier posts (the stories' links, holds): no one else is offered
141
+ const sellers = new Set(
142
+ [...posts].filter((p) => p.data.role === "supplier").flatMap((p) => p.data.members as number[]),
143
+ );
131
144
  options(
132
145
  "supplier",
133
- [...members].filter((m) => m.key !== me).map((m) => ({ value: m.key, text: m.data.name })),
146
+ [...members].filter((m) => m.key !== me && sellers.has(m.key)).map((m) => ({ value: m.key, text: m.data.name })),
134
147
  );
135
148
  for (const s of listed) s.draw();
136
149
  };
150
+ /** The staff's posts, a live list: who supplies. */
151
+ const posts = document.getElementsByTagName(staff.collections.posts.tag) as HTMLCollectionOf<JPost>;
137
152
  /** The supplies on the page, a live list. */
138
153
  const listed = document.getElementsByTagName(supplies.collections.supplies.tag) as HTMLCollectionOf<Supply>;
139
154
  const hash = inHash(
@@ -144,7 +159,11 @@ const hash = inHash(
144
159
  );
145
160
  // (the menu and the members, not the supplies it draws: those it draws again, and never watches)
146
161
  const watching = new MutationObserver(fill);
147
- for (const el of [document.querySelector(menu.collections.items.place), document.querySelector("members-panel")])
162
+ for (const el of [
163
+ document.querySelector(menu.collections.items.place),
164
+ document.querySelector(staff.collections.posts.place),
165
+ document.querySelector("members-panel"),
166
+ ])
148
167
  if (el) watching.observe(el, { subtree: true, childList: true, attributes: true });
149
168
  form.addEventListener("submit", (e) => {
150
169
  e.preventDefault();
@@ -167,4 +186,5 @@ form.addEventListener("submit", (e) => {
167
186
 
168
187
  // defined last, once all they draw with is made: the items first, so a supply drawn as it's defined names its item
169
188
  customElements.define(menu.collections.items.tag, class extends JItem {});
189
+ customElements.define(staff.collections.posts.tag, class extends JPost {});
170
190
  customElements.define(supplies.collections.supplies.tag, Supply);