@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
@@ -0,0 +1,41 @@
1
+ // What bun run look notes draws: the notes' page (drawn by joined from the stories) in each state it has, each put
2
+ // there as a person would (act), from the one before (they're played in order, on one store). Looked at wide and on
3
+ // a phone, light and dark.
4
+
5
+ import { collections } from "./generated/rules.ts";
6
+
7
+ const rows = `document.querySelector("${collections.notes.place}-rows")`,
8
+ R = `${rows}.shadowRoot`;
9
+ const row = (n: number) => `${R}.querySelectorAll('ul[part="list"] > li[data-key]')[${n - 1}]`;
10
+ const drawer = `${R}.querySelector("aside.drawer")`;
11
+ const tab = (name: string) => `${R}.querySelector('[role=tab][name=${name}]').click()`;
12
+
13
+ export const page = "/notes";
14
+ export const ready = `(${R}.querySelectorAll("li[data-key]").length > 0 || document.querySelector("${collections.notes.place}[may]")) && ${rows}.dataset.order`;
15
+ export const states = [
16
+ { name: "The list, in my order" },
17
+ { name: "In Nora's order", act: `${R}.querySelector('.whose [name="3"]').click()` },
18
+ { name: "In everyone's order", act: `${R}.querySelector('.whose [name="all"]').click()` },
19
+ { name: "Read as a board", act: tab("board") },
20
+ { name: "Read as a calendar", act: tab("calendar") },
21
+ { name: "A note's day popped", act: `${row(1)}.querySelector(".j-mention").click()` },
22
+ { name: "A note open", act: `${row(2)}.querySelector("button.open").click()` },
23
+ {
24
+ name: "Typed, not kept",
25
+ act: `${row(2)}.querySelector("button.open").click(); (() => { const b = ${drawer}.querySelector("[name=text]"); b.value = "Call the plumber about the tap"; b.dispatchEvent(new Event("input", { bubbles: true })); })()`,
26
+ },
27
+ {
28
+ name: "Asked before it goes",
29
+ act: `${row(2)}.querySelector("button.open").click(); ${drawer}.querySelector("[name=gone]").click()`,
30
+ },
31
+ {
32
+ name: "Long words",
33
+ act: `(() => { const f = ${R}.querySelector("form.adding"); f.querySelector("input").value = "Ask the neighbours whether they would water the plants on the balcony while we are away in November, and leave them a key"; f.requestSubmit(); })()`,
34
+ settle: `${R}.querySelectorAll("li[data-key]").length === 4`,
35
+ },
36
+ {
37
+ name: "None",
38
+ act: `document.querySelectorAll("${collections.notes.tag}").forEach((n) => n.removeItem())`,
39
+ settle: `${R}.querySelectorAll("li[data-key]").length === 0`,
40
+ },
41
+ ];
@@ -0,0 +1,7 @@
1
+ // Made by `bun run compile` from the stories: what they say beyond the migrations before it.
2
+ import { createTable } from "joined/migrate";
3
+
4
+ export const changes = [
5
+ createTable("notes", { columns: { text: { type: "text", is: { type: "string", said: "text is a string" } }, more: { type: "text", nullable: true, is: { type: "string", said: "more is a string" } }, done: { type: "boolean", nullable: true, is: { type: "boolean", said: "done is a boolean" } }, when: { type: "text", nullable: true, is: { type: "form", form: "^\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01])T([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$", said: "when is a date and time (YYYY-MM-DDTHH:MM:SS)" } } }, strict: true, needs: { columns: ["text"], said: "a note needs text (string); may have more (string), done (boolean), when (date-time)" } }),
6
+ createTable("ranks", { columns: { note: { type: "integer", is: { type: "integer", said: "note is a whole number" }, to: { table: "notes", said: "note links only to notes the notes document holds", held: ["rank in notes links to it", "ranks in notes link to it"] } }, rank: { type: "real", is: { type: "decimal", said: "rank is a number" } }, by: { type: "integer", nullable: true, is: { type: "integer", said: "by is a whole number" }, to: { table: "members", said: "by links only to members the members document holds", onDelete: "set null" } } }, strict: true, needs: { columns: ["note", "rank"], said: "a rank needs note (an id in notes), rank (decimal); may have by (an id in members)" } }),
7
+ ];
@@ -0,0 +1,78 @@
1
+ {
2
+ "version": 1,
3
+ "notes": [
4
+ {
5
+ "id": 1,
6
+ "text": "Buy rice",
7
+ "when": "2026-11-26T09:00:00"
8
+ },
9
+ {
10
+ "id": 2,
11
+ "text": "Call the plumber",
12
+ "more": "The tap in the kitchen drips. Mornings are best.",
13
+ "when": "2026-11-26T09:00:00"
14
+ },
15
+ {
16
+ "id": 3,
17
+ "text": "Return the library books",
18
+ "done": true,
19
+ "when": "2026-11-24T09:00:00"
20
+ }
21
+ ],
22
+ "ranks": [
23
+ {
24
+ "id": 1,
25
+ "note": 1,
26
+ "by": 1,
27
+ "rank": 1
28
+ },
29
+ {
30
+ "id": 2,
31
+ "note": 2,
32
+ "by": 1,
33
+ "rank": 2
34
+ },
35
+ {
36
+ "id": 3,
37
+ "note": 3,
38
+ "by": 1,
39
+ "rank": 3
40
+ },
41
+ {
42
+ "id": 4,
43
+ "note": 3,
44
+ "by": 3,
45
+ "rank": 1
46
+ },
47
+ {
48
+ "id": 5,
49
+ "note": 1,
50
+ "by": 3,
51
+ "rank": 2
52
+ },
53
+ {
54
+ "id": 6,
55
+ "note": 2,
56
+ "by": 3,
57
+ "rank": 3
58
+ },
59
+ {
60
+ "id": 7,
61
+ "note": 2,
62
+ "by": 2,
63
+ "rank": 1
64
+ },
65
+ {
66
+ "id": 8,
67
+ "note": 1,
68
+ "by": 2,
69
+ "rank": 2
70
+ },
71
+ {
72
+ "id": 9,
73
+ "note": 3,
74
+ "by": 2,
75
+ "rank": 3
76
+ }
77
+ ]
78
+ }
@@ -0,0 +1,21 @@
1
+ // The notes' page: its stories, joined's kit (a search, the list and its readings, the sheet) and these few lines:
2
+ // that a note that's done is struck through.
3
+
4
+ import "joined/panel";
5
+ import "joined/toast";
6
+ import "joined/kit";
7
+ import { define } from "joined/rows";
8
+ import { JNotesRows } from "./generated/rows.ts";
9
+
10
+ const STRUCK = new CSSStyleSheet();
11
+ STRUCK.replaceSync(`.row[done] .name { color: var(--muted); text-decoration: line-through; }`);
12
+
13
+ class Notes extends JNotesRows {
14
+ static sheets = [STRUCK];
15
+ row(it: Parameters<InstanceType<typeof JNotesRows>["row"]>[0]) {
16
+ const row = super.row(it);
17
+ row.toggleAttribute("done", it.data.done === true);
18
+ return row;
19
+ }
20
+ }
21
+ define(Notes);
@@ -0,0 +1,6 @@
1
+ // notes: its document, and its page at /notes: its stories and joined's kit.
2
+
3
+ import page from "./index.html";
4
+
5
+ export * as document from "./generated/rules.ts";
6
+ export const routes = { "/notes": page };
@@ -0,0 +1,21 @@
1
+ {"cast":{"phone":"peter"}}
2
+ {"links":{"note":{"to":"notes","one":true,"gone":"with"},"by":{"to":"members","one":true}}}
3
+ {"mine":{"ranks":{"of":"note","by":"by"}}}
4
+ {"story":"Someone writes a note, and every page shows it","as":"peter","does":{"doc":"notes","ops":[{"op":"add","path":"/notes/-","value":{"text":"Water the plants"}}]},"seen":["peter","phone"]}
5
+ {"story":"A note is reworded","as":"peter","does":{"doc":"notes","ops":[{"op":"replace","path":"/notes/1/text","value":"Buy rice and miso"}]},"seen":["peter","phone"]}
6
+ {"story":"A note is given more to say","as":"peter","does":{"doc":"notes","ops":[{"op":"replace","path":"/notes/1/more","value":"The short-grain kind, two kilos."}]},"seen":["peter","phone"]}
7
+ {"story":"What a note says more is taken off","as":"peter","does":{"doc":"notes","ops":[{"op":"remove","path":"/notes/2/more"}]},"seen":["peter","phone"]}
8
+ {"story":"A note is thrown away","as":"peter","does":{"doc":"notes","ops":[{"op":"remove","path":"/notes/3"}]},"seen":["peter","phone"]}
9
+ {"story":"A note needs its words","as":"peter","cannot":{"doc":"notes","ops":[{"op":"add","path":"/notes/-","value":{"more":"Nothing it says"}}]}}
10
+ {"story":"A note is words, not a number","as":"peter","cannot":{"doc":"notes","ops":[{"op":"replace","path":"/notes/1/text","value":7}]}}
11
+ {"story":"A note is ticked done","as":"peter","does":{"doc":"notes","ops":[{"op":"replace","path":"/notes/1/done","value":true}]},"seen":["peter","phone"]}
12
+ {"story":"A note done is not, after all: its tick is taken off","as":"peter","does":{"doc":"notes","ops":[{"op":"remove","path":"/notes/3/done"}]},"seen":["peter","phone"]}
13
+ {"story":"Done is a tick, not words","as":"peter","cannot":{"doc":"notes","ops":[{"op":"replace","path":"/notes/1/done","value":"yes"}]}}
14
+ {"story":"A note is given its day","as":"peter","does":{"doc":"notes","ops":[{"op":"replace","path":"/notes/2/when","value":"2026-11-27T09:00:00"}]},"seen":["peter","phone"]}
15
+ {"story":"A note has no day, after all","as":"peter","does":{"doc":"notes","ops":[{"op":"remove","path":"/notes/1/when"}]},"seen":["peter","phone"]}
16
+ {"story":"A day is a date and a time, not words","as":"peter","cannot":{"doc":"notes","ops":[{"op":"replace","path":"/notes/1/when","value":"on Friday"}]}}
17
+ {"story":"Peter says where a new note comes for him: his own place for it, and everyone sees it","as":"peter","premise":{"peter":[{"doc":"notes","ops":[{"op":"add","path":"/notes/-","value":{"text":"Water the plants"}}]}]},"does":{"doc":"notes","ops":[{"op":"add","path":"/ranks/-","value":{"note":4,"rank":0.5}}]},"seen":["peter","phone","nora"],"then":{"/ranks/10/by":1}}
18
+ {"story":"Nora moves a note up her own order","as":"nora","does":{"doc":"notes","ops":[{"op":"replace","path":"/ranks/5/rank","value":0.5}]},"seen":["peter","nora"]}
19
+ {"story":"Peter can't move a note in Nora's order: it's hers","as":"peter","cannot":{"doc":"notes","ops":[{"op":"replace","path":"/ranks/5/rank","value":9}]},"refused":"ranks are each member's own to change"}
20
+ {"story":"Nora has no place of her own for a note, after all","as":"nora","does":{"doc":"notes","ops":[{"op":"remove","path":"/ranks/6"}]},"seen":["peter","nora"]}
21
+ {"story":"A place in an order is a number, not a word","as":"peter","cannot":{"doc":"notes","ops":[{"op":"replace","path":"/ranks/1/rank","value":"first"}]}}
@@ -0,0 +1,22 @@
1
+ // Written by src/compile.ts from examples/people/stories.jsonl: change the stories, not this.
2
+
3
+ // Each collection of people as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
4
+ // extended, by define() from joined/rows, and holds each collection's element in its rows:
5
+ // <j-people-rows><j-people></j-people></j-people-rows>
6
+ // A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
7
+ // To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
8
+ // step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
9
+ // under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
10
+ // use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
11
+ // elements. Never change this file: change the stories.
12
+
13
+ import { rows, type Spec } from "joined/rows";
14
+ import { JPerson } from "./elements.ts";
15
+
16
+ const people: Spec = {"doc":"people","name":"people","place":"j-people","tag":"j-person","one":"person","title":"name","fields":[{"name":"name","type":"string","needed":true},{"name":"rank","type":"decimal"},{"name":"member","type":"integer","how":"one","to":{"tag":"j-member","people":true},"ref":true}]};
17
+
18
+ /** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
19
+ export const specs = { "people": people };
20
+
21
+ /** <j-people-rows>: people's people as rows, each named by its name. */
22
+ export class JPeopleRows extends rows(people, { "j-person": JPerson }) {}
@@ -3,7 +3,7 @@
3
3
  export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
4
4
 
5
5
  /** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
6
- * what each link is to. */
6
+ * what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
7
7
  export const doc = "people";
8
8
  export const collections = {
9
9
  "people": {
@@ -20,6 +20,11 @@ export const collections = {
20
20
  "links": {
21
21
  "member": "members"
22
22
  },
23
+ "pops": {
24
+ "member": {
25
+ "to": "members"
26
+ }
27
+ },
23
28
  "order": "rank"
24
29
  }
25
30
  } as const;
@@ -52,6 +57,11 @@ export function holds(d: Record<string, unknown>, touched: Record<string, number
52
57
  return null;
53
58
  }
54
59
 
60
+ /** The lists that are each member's own (its definitions' mine), or links to one: a member gives and takes only their own id. */
61
+ export const mine: Record<string, string[]> = {"people":["member"]};
62
+ /** The words a write giving or taking another's is refused in, where its mine says them. */
63
+ export const mineSaid: Record<string, Record<string, string>> = {"people":{"member":"you say which person you are, as yourself"}};
64
+
55
65
  /** people is one document. */
56
66
  export const kind = null;
57
67
 
@@ -77,7 +77,8 @@ export class Links {
77
77
  });
78
78
  go.addEventListener("click", () => {
79
79
  el.dispatchEvent(new CustomEvent("pick", { bubbles: true }));
80
- this.of.closest<HTMLElement>("[popover]")?.hidePopover();
80
+ // the sheet it's in closes (joined/surface)
81
+ go.dispatchEvent(new Event("j-close", { bubbles: true }));
81
82
  });
82
83
  return go;
83
84
  },
@@ -1,9 +1,7 @@
1
1
  // The people: a document other pages hold, with no page of its own.
2
2
 
3
3
  export * as document from "./generated/rules.ts";
4
- /** The people's own rule: you say which person you are, as yourself (./trust.ts). */
5
- export { trust } from "./trust.ts";
6
- /** An invitation's act: once they're in, the person they were invited as is them (said as them, as the trust asks). */
4
+ /** An invitation's act: once they're in, the person they were invited as is them (said as them, as its mine asks). */
7
5
  export const acts = {
8
6
  person: (member: number, key: string) => ({
9
7
  doc: "people",
@@ -2,6 +2,7 @@
2
2
  {"unique":{"people":["name","member"]}}
3
3
  {"order":{"people":"rank"}}
4
4
  {"links":{"member":{"to":"members","one":true}}}
5
+ {"mine":{"people":[{"member":"you say which person you are, as yourself"}]}}
5
6
  {"story":"Peter adds Hana to the people, and his phone's list shows her","as":"peter","does":{"doc":"people","ops":[{"op":"add","path":"/people/-","value":{"name":"Hana"}}]},"seen":["peter","phone"]}
6
7
  {"story":"He gives Kenji's whole name","as":"peter","does":{"doc":"people","ops":[{"op":"replace","path":"/people/2/name","value":"Kenji Sato"}]},"seen":["peter","phone"]}
7
8
  {"story":"He takes Yuki off the list: nothing links to her","as":"peter","does":{"doc":"people","ops":[{"op":"remove","path":"/people/4"}]},"seen":["peter","phone"]}
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { icon, iconButton } from "joined/icons";
7
7
  import { hueOf } from "joined/hues";
8
- import { said } from "joined/parts";
8
+ import { askOnPage, said } from "joined/parts";
9
9
  import { group, members, signedIn } from "joined/panel";
10
10
  import { JPerson } from "./generated/elements.ts";
11
11
  import { collections } from "./generated/rules.ts";
@@ -23,7 +23,10 @@ export class Person extends JPerson {
23
23
  #invite = Object.assign(document.createElement("button"), { type: "button", className: "act small invite" });
24
24
  #invited = Object.assign(document.createElement("span"), { className: "invited", textContent: "Invited" });
25
25
  #said = Object.assign(document.createElement("p"), { className: "said", role: "status" }); // a refusal's why
26
- #gone = iconButton("person-remove", "", () => said(this.#said, this.removeItem()));
26
+ // taken off the list: asked first, in a modal (design.md)
27
+ #gone = iconButton("person-remove", "", () =>
28
+ askOnPage(`Take ${this.data.name} off the list?`, () => said(this.#said, this.removeItem())),
29
+ );
27
30
  connectedCallback() {
28
31
  if (this.childElementCount) return this.draw();
29
32
  // renamed, or taken off: refused, why, in its row, and its name as the document has it
@@ -37,9 +37,11 @@ export class JEvent extends HTMLElement {
37
37
  replace(fields: Partial<Pick<JEventData, "start" | "title" | "duration" | "location" | "coordinates" | "zone" | "people" | "keen" | "declined" | "asked">>, why?: string) {
38
38
  return send(this, Object.entries(fields).filter(([, value]) => value !== undefined).flatMap(([field, value]) => ["people","keen","declined","asked"].includes(field) ? this.#ids(field as "people" | "keen" | "declined" | "asked", value as number[]) : [{ op: "replace", path: `${this.path}/${field.replace(".", "/")}`, value }]), why);
39
39
  }
40
- /** A list's ids, as the ids added to it and taken from it. */
40
+ /** A list's ids, as the ids added to it and taken from it; emptied, where this person may take the whole list and not
41
+ * its ids one by one (an answer taken back), the list taken. */
41
42
  #ids(field: "people" | "keen" | "declined" | "asked", ids: number[]) {
42
- const had = this.data[field];
43
+ const had = this.data[field], may = (this.getAttribute("may") ?? "").split(" ");
44
+ if (!ids.length && had.length && may.includes(`remove:${field}`) && !may.includes(`remove:${field}[]`)) return [{ op: "remove", path: `${this.path}/${field}` }];
43
45
  return [...ids.filter((id) => !had.includes(id)).map((id) => ({ op: "add", path: `${this.path}/${field}/-`, value: id })), ...had.filter((id) => !ids.includes(id)).map((id) => ({ op: "remove", path: `${this.path}/${field}/${id}` }))];
44
46
  }
45
47
  /** Link it to one more id in a list (people, asked, keen, declined, arrives, leaves): the ids there already are left as they are. */
@@ -42,5 +42,16 @@ export const postgres = {
42
42
  "stays": "json_strip_nulls(json_build_object('id', t.id,\n 'name', t.\"name\",\n 'from', t.\"from\",\n 'until', t.\"until\",\n 'location', t.\"location\",\n 'coordinates', t.\"coordinates\"))"
43
43
  },
44
44
  "query": "SELECT json_build_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),\n 'events', (SELECT COALESCE(json_agg(json_strip_nulls(json_build_object('id', t.id,\n 'title', t.\"title\",\n 'start', t.\"start\",\n 'duration', t.\"duration\",\n 'location', t.\"location\",\n 'coordinates', t.\"coordinates\",\n 'people', (SELECT json_agg(p.\"people\" ORDER BY p.id) FROM \"events_people\" p WHERE p.\"events\" = t.id),\n 'zone', t.\"zone\",\n 'asked', (SELECT json_agg(p.\"asked\" ORDER BY p.id) FROM \"events_asked\" p WHERE p.\"events\" = t.id),\n 'keen', (SELECT json_agg(p.\"keen\" ORDER BY p.id) FROM \"events_keen\" p WHERE p.\"events\" = t.id),\n 'declined', (SELECT json_agg(p.\"declined\" ORDER BY p.id) FROM \"events_declined\" p WHERE p.\"events\" = t.id),\n 'arrives', (SELECT json_agg(p.\"arrives\" ORDER BY p.id) FROM \"events_arrives\" p WHERE p.\"events\" = t.id),\n 'leaves', (SELECT json_agg(p.\"leaves\" ORDER BY p.id) FROM \"events_leaves\" p WHERE p.\"events\" = t.id))) ORDER BY t.id), '[]')\n FROM \"events\" t WHERE t.\"trip\" = $key AND ($week IS NULL OR (t.\"start\" < to_char(CAST($week AS timestamp) + interval '7 days', 'YYYY-MM-DD\"T\"HH24:MI:SS') AND to_char(CAST(t.\"start\" AS timestamp) + CAST(t.\"duration\" AS interval), 'YYYY-MM-DD\"T\"HH24:MI:SS') > to_char(CAST($week AS timestamp) + interval '0 days', 'YYYY-MM-DD\"T\"HH24:MI:SS'))) AND ($month IS NULL OR (t.\"start\" < to_char(CAST($month AS timestamp) + interval '42 days', 'YYYY-MM-DD\"T\"HH24:MI:SS') AND to_char(CAST(t.\"start\" AS timestamp) + CAST(t.\"duration\" AS interval), 'YYYY-MM-DD\"T\"HH24:MI:SS') > to_char(CAST($month AS timestamp) + interval '0 days', 'YYYY-MM-DD\"T\"HH24:MI:SS'))) AND ($member IS NULL OR ((EXISTS (SELECT 1 FROM \"trips_organisers\" p WHERE p.\"trips\" = $key AND p.\"organisers\" = $member)) OR (EXISTS (SELECT 1 FROM \"trips_travellers\" p WHERE p.\"trips\" = $key AND p.\"travellers\" = $member))))),\n 'stays', (SELECT COALESCE(json_agg(json_strip_nulls(json_build_object('id', t.id,\n 'name', t.\"name\",\n 'from', t.\"from\",\n 'until', t.\"until\",\n 'location', t.\"location\",\n 'coordinates', t.\"coordinates\")) ORDER BY t.id), '[]')\n FROM \"stays\" t WHERE t.\"trip\" = $key AND ($member IS NULL OR ((EXISTS (SELECT 1 FROM \"trips_organisers\" p WHERE p.\"trips\" = $key AND p.\"organisers\" = $member)) OR (EXISTS (SELECT 1 FROM \"trips_travellers\" p WHERE p.\"trips\" = $key AND p.\"travellers\" = $member)))))) AS doc",
45
- "triggers": []
45
+ "triggers": [
46
+ "CREATE OR REPLACE FUNCTION \"joined_within_events_0_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT 1 FROM \"events_keen\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"keen\")) OR EXISTS (SELECT 1 FROM \"events_asked\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"asked\")) OR EXISTS (SELECT 1 FROM \"events_declined\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"declined\")) THEN RAISE EXCEPTION '%', 'an answer is from someone on the event'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_within_events_0_0\" AFTER INSERT ON \"events_keen\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_within_events_0_fn\"()",
47
+ "CREATE OR REPLACE FUNCTION \"joined_within_events_0_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT 1 FROM \"events_keen\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"keen\")) OR EXISTS (SELECT 1 FROM \"events_asked\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"asked\")) OR EXISTS (SELECT 1 FROM \"events_declined\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"declined\")) THEN RAISE EXCEPTION '%', 'an answer is from someone on the event'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_within_events_0_1\" AFTER INSERT ON \"events_asked\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_within_events_0_fn\"()",
48
+ "CREATE OR REPLACE FUNCTION \"joined_within_events_0_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT 1 FROM \"events_keen\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"keen\")) OR EXISTS (SELECT 1 FROM \"events_asked\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"asked\")) OR EXISTS (SELECT 1 FROM \"events_declined\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"declined\")) THEN RAISE EXCEPTION '%', 'an answer is from someone on the event'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_within_events_0_2\" AFTER INSERT ON \"events_declined\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_within_events_0_fn\"()",
49
+ "CREATE OR REPLACE FUNCTION \"joined_within_events_0_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT 1 FROM \"events_keen\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"keen\")) OR EXISTS (SELECT 1 FROM \"events_asked\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"asked\")) OR EXISTS (SELECT 1 FROM \"events_declined\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"declined\")) THEN RAISE EXCEPTION '%', 'an answer is from someone on the event'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_within_events_0_3\" AFTER DELETE ON \"events_people\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_within_events_0_fn\"()",
50
+ "CREATE OR REPLACE FUNCTION \"joined_within_events_1_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT 1 FROM \"events_arrives\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"arrives\")) OR EXISTS (SELECT 1 FROM \"events_leaves\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"leaves\")) THEN RAISE EXCEPTION '%', 'who comes or goes at an event is on it'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_within_events_1_0\" AFTER INSERT ON \"events_arrives\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_within_events_1_fn\"()",
51
+ "CREATE OR REPLACE FUNCTION \"joined_within_events_1_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT 1 FROM \"events_arrives\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"arrives\")) OR EXISTS (SELECT 1 FROM \"events_leaves\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"leaves\")) THEN RAISE EXCEPTION '%', 'who comes or goes at an event is on it'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_within_events_1_1\" AFTER INSERT ON \"events_leaves\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_within_events_1_fn\"()",
52
+ "CREATE OR REPLACE FUNCTION \"joined_within_events_1_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT 1 FROM \"events_arrives\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"arrives\")) OR EXISTS (SELECT 1 FROM \"events_leaves\" l WHERE l.\"events\" = item AND NOT EXISTS (SELECT 1 FROM \"events_people\" p WHERE p.\"events\" = item AND p.\"people\" = l.\"leaves\")) THEN RAISE EXCEPTION '%', 'who comes or goes at an event is on it'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_within_events_1_2\" AFTER DELETE ON \"events_people\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_within_events_1_fn\"()",
53
+ "CREATE OR REPLACE FUNCTION \"joined_apart_events_2_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT v FROM (SELECT \"keen\" AS v FROM \"events_keen\" WHERE \"events\" = item UNION ALL SELECT \"asked\" AS v FROM \"events_asked\" WHERE \"events\" = item UNION ALL SELECT \"declined\" AS v FROM \"events_declined\" WHERE \"events\" = item) a GROUP BY v HAVING COUNT(*) > 1) THEN RAISE EXCEPTION '%', 'one answer each'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_apart_events_2_0\" AFTER INSERT ON \"events_keen\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_apart_events_2_fn\"()",
54
+ "CREATE OR REPLACE FUNCTION \"joined_apart_events_2_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT v FROM (SELECT \"keen\" AS v FROM \"events_keen\" WHERE \"events\" = item UNION ALL SELECT \"asked\" AS v FROM \"events_asked\" WHERE \"events\" = item UNION ALL SELECT \"declined\" AS v FROM \"events_declined\" WHERE \"events\" = item) a GROUP BY v HAVING COUNT(*) > 1) THEN RAISE EXCEPTION '%', 'one answer each'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_apart_events_2_1\" AFTER INSERT ON \"events_asked\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_apart_events_2_fn\"()",
55
+ "CREATE OR REPLACE FUNCTION \"joined_apart_events_2_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ DECLARE item INTEGER; BEGIN IF TG_OP = 'DELETE' THEN item := OLD.\"events\"; ELSE item := NEW.\"events\"; END IF; IF EXISTS (SELECT v FROM (SELECT \"keen\" AS v FROM \"events_keen\" WHERE \"events\" = item UNION ALL SELECT \"asked\" AS v FROM \"events_asked\" WHERE \"events\" = item UNION ALL SELECT \"declined\" AS v FROM \"events_declined\" WHERE \"events\" = item) a GROUP BY v HAVING COUNT(*) > 1) THEN RAISE EXCEPTION '%', 'one answer each'; END IF; RETURN NULL; END $joined$; CREATE CONSTRAINT TRIGGER \"joined_apart_events_2_2\" AFTER INSERT ON \"events_declined\" DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION \"joined_apart_events_2_fn\"()"
56
+ ]
46
57
  };
@@ -0,0 +1,27 @@
1
+ // Written by src/compile.ts from examples/trip/stories.jsonl: change the stories, not this.
2
+
3
+ // Each collection of trip as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
4
+ // extended, by define() from joined/rows, and holds each collection's element in its rows:
5
+ // <j-events-rows><j-events></j-events></j-events-rows>
6
+ // <j-stays-rows><j-stays></j-stays></j-stays-rows>
7
+ // A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
8
+ // To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
9
+ // step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
10
+ // under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
11
+ // use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
12
+ // elements. Never change this file: change the stories.
13
+
14
+ import { rows, type Spec } from "joined/rows";
15
+ import { JEvent, JStay } from "./elements.ts";
16
+
17
+ const events: Spec = {"doc":"trip","name":"events","place":"j-events","tag":"j-event","one":"event","title":"title","fields":[{"name":"title","type":"string","needed":true},{"name":"start","type":"date-time","needed":true},{"name":"duration","type":"duration","needed":true},{"name":"location","type":"string"},{"name":"coordinates","type":"place"},{"name":"people","type":"ids","how":"ids","to":{"tag":"j-person"},"ref":true},{"name":"zone","type":"zone"},{"name":"asked","type":"ids","how":"ids","to":{"tag":"j-person"},"ref":true},{"name":"keen","type":"ids","how":"ids","to":{"tag":"j-person"},"ref":true},{"name":"declined","type":"ids","how":"ids","to":{"tag":"j-person"},"ref":true},{"name":"arrives","type":"ids","how":"ids","to":{"tag":"j-person"},"ref":true},{"name":"leaves","type":"ids","how":"ids","to":{"tag":"j-person"},"ref":true}]};
18
+ const stays: Spec = {"doc":"trip","name":"stays","place":"j-stays","tag":"j-stay","one":"stay","title":"name","fields":[{"name":"name","type":"string","needed":true},{"name":"from","type":"date-time","needed":true},{"name":"until","type":"date-time","needed":true},{"name":"location","type":"string"},{"name":"coordinates","type":"place"}]};
19
+
20
+ /** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
21
+ export const specs = { "events": events, "stays": stays };
22
+
23
+ /** <j-events-rows>: trip's events as rows, each named by its title. */
24
+ export class JEventsRows extends rows(events, { "j-event": JEvent }) {}
25
+
26
+ /** <j-stays-rows>: trip's stays as rows, each named by its name. */
27
+ export class JStaysRows extends rows(stays, { "j-stay": JStay }) {}
@@ -3,7 +3,7 @@
3
3
  export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
4
4
 
5
5
  /** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
6
- * what each link is to. */
6
+ * what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
7
7
  export const doc = "trip";
8
8
  export const collections = {
9
9
  "events": {
@@ -35,6 +35,32 @@ export const collections = {
35
35
  "declined": "people",
36
36
  "arrives": "people",
37
37
  "leaves": "people"
38
+ },
39
+ "pops": {
40
+ "start": {
41
+ "form": "date-time"
42
+ },
43
+ "coordinates": {
44
+ "form": "place"
45
+ },
46
+ "people": {
47
+ "to": "people"
48
+ },
49
+ "asked": {
50
+ "to": "people"
51
+ },
52
+ "keen": {
53
+ "to": "people"
54
+ },
55
+ "declined": {
56
+ "to": "people"
57
+ },
58
+ "arrives": {
59
+ "to": "people"
60
+ },
61
+ "leaves": {
62
+ "to": "people"
63
+ }
38
64
  }
39
65
  },
40
66
  "stays": {
@@ -52,7 +78,18 @@ export const collections = {
52
78
  "from",
53
79
  "until"
54
80
  ],
55
- "links": {}
81
+ "links": {},
82
+ "pops": {
83
+ "from": {
84
+ "form": "date-time"
85
+ },
86
+ "until": {
87
+ "form": "date-time"
88
+ },
89
+ "coordinates": {
90
+ "form": "place"
91
+ }
92
+ }
56
93
  }
57
94
  } as const;
58
95
  /** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */
@@ -90,6 +127,23 @@ export function holds(d: Record<string, unknown>, touched: Record<string, number
90
127
  return null;
91
128
  }
92
129
 
130
+ /** Why the lists of an item the write touched don't hold as it leaves them (its definitions' within and apart), or null:
131
+ * asked on SQLite, as Postgres's triggers ask it at the write's end. */
132
+ export function listsHold(d: Record<string, unknown>, touched: Record<string, number[]>): string | null {
133
+ for (const id of touched["events"] ?? []) {
134
+ const a = ((d["events"] ?? []) as any[]).find((i) => i.id === id);
135
+ if (!a) continue;
136
+ const ids = (l: string): number[] => a[l] ?? [];
137
+ if (!["keen","asked","declined"].every((l) => ids(l).every((k) => ids("people").includes(k)))) return "an answer is from someone on the event";
138
+ if (!["arrives","leaves"].every((l) => ids(l).every((k) => ids("people").includes(k)))) return "who comes or goes at an event is on it";
139
+ {
140
+ const given = ["keen","asked","declined"].flatMap(ids);
141
+ if (new Set(given).size !== given.length) return "one answer each";
142
+ }
143
+ }
144
+ return null;
145
+ }
146
+
93
147
  /** trip is one of many: a document for each of trips's trips (trip:1), its items each kept with it. */
94
148
  export const kind = {"root":"trips","doc":"trips","column":"trip"};
95
149
 
@@ -9,13 +9,14 @@
9
9
  <link rel="stylesheet" href="../app.css" />
10
10
  <link rel="stylesheet" href="../people/people.css" />
11
11
  <link rel="stylesheet" href="./stays.css" />
12
+ <link rel="stylesheet" href="./trip.css" />
12
13
  </head>
13
14
  <body>
14
15
  <a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
15
16
  <h1 class="trip-name">The trip</h1>
16
17
  <p class="lead">
17
- Its week, as a calendar or a line, or its month, beside its map. Drag down a day to add an event, or tap the map;
18
- drag one to another day, or its pin to another place. Open it on another device to see each change arrive.
18
+ Its week, as a calendar or a line, or its month, beside its map. Tap an hour to add an event; drag one to another
19
+ day, or its pin to another place. Open it on another device to see each change arrive.
19
20
  <a href="/trips">← Your trips</a>
20
21
  </p>
21
22
  <p class="bar">
@@ -38,10 +39,17 @@
38
39
  data-icon="close"
39
40
  ></button>
40
41
  </header>
41
- <j-people></j-people>
42
+ <j-people id="the-people"></j-people>
42
43
  <footer>
43
44
  <form class="add">
44
- <input name="name" placeholder="A new person" required autocomplete="off" />
45
+ <wa-input
46
+ class="j-bare"
47
+ name="name"
48
+ label="A new person"
49
+ placeholder="A new person"
50
+ required
51
+ autocomplete="off"
52
+ ></wa-input>
45
53
  <button class="act ink" data-icon="person-add">Add</button>
46
54
  <p class="said" role="status"></p>
47
55
  </form>
@@ -60,23 +68,61 @@
60
68
  data-icon="close"
61
69
  ></button>
62
70
  </header>
71
+ <div id="the-stays"></div>
63
72
  <footer>
64
- <form class="add book">
65
- <input name="name" placeholder="Where we stay" required autocomplete="off" aria-label="Where we stay" />
66
- <label>From<input name="day" type="date" required /></label>
67
- <label>Nights<input name="nights" type="number" min="1" value="1" required /></label>
68
- <button class="act ink" data-icon="add">Book</button>
69
- <p class="said" role="status"></p>
70
- </form>
73
+ <button type="button" class="act ink" name="book" data-icon="add">Book a stay</button>
74
+ </footer>
75
+ </div>
76
+ <!-- a new stay asked in a modal, as anything new is (design.md): what it can't be without -->
77
+ <wa-dialog id="booking" class="modal" light-dismiss>
78
+ <h2 slot="label">Book a stay</h2>
79
+ <form class="book" id="booking-form">
80
+ <wa-input
81
+ name="name"
82
+ label="Where we stay"
83
+ placeholder="A hotel, a ryokan"
84
+ required
85
+ autocomplete="off"
86
+ ></wa-input>
87
+ <wa-input name="day" type="date" label="From" required></wa-input>
88
+ <wa-number-input name="nights" label="Nights" min="1" value="1" required></wa-number-input>
89
+ <p class="said" role="status"></p>
90
+ </form>
91
+ <footer slot="footer">
92
+ <button type="button" class="act" name="keep">Never mind</button>
93
+ <button class="act ink" form="booking-form" data-icon="add">Book</button>
71
94
  </footer>
95
+ </wa-dialog>
96
+ <!-- the trip as joined's kit reads it: a week, the line (the trip's own reading) or a month, beside its map -->
97
+ <div class="beside">
98
+ <j-views>
99
+ <j-week for="events" when="start" length="duration"></j-week>
100
+ <trip-line for="events" label="Line" icon="line" people="the-people" stays="the-stays"></trip-line>
101
+ <j-month for="events" when="start"></j-month>
102
+ </j-views>
103
+ <j-map for="events" at="coordinates"></j-map>
72
104
  </div>
73
- <calendar-map people="people" stays="stays"><j-weeks></j-weeks></calendar-map>
105
+ <div id="held" hidden></div>
74
106
  <p class="edge">
75
107
  <a href="trip.ics" download="trip.ics" data-icon="download">Download .ics</a>
76
108
  <label data-icon="upload">Add from .ics <input type="file" accept=".ics,text/calendar" /></label>
77
109
  </p>
78
110
  <p id="said" role="status"></p>
79
111
  </main>
112
+ <j-sheet for="events">
113
+ <j-field name="title"></j-field>
114
+ <j-field name="start" label="When"></j-field>
115
+ <j-field name="duration" label="How long"></j-field>
116
+ <j-field name="zone"></j-field>
117
+ <j-field name="location" label="Where"></j-field>
118
+ <j-field name="coordinates" label="On the map"></j-field>
119
+ <j-field name="people" label="Who's on it"></j-field>
120
+ <j-field name="keen" label="Keen"></j-field>
121
+ <j-field name="asked" label="Asked"></j-field>
122
+ <j-field name="declined" label="Not coming"></j-field>
123
+ <j-field name="arrives" label="Comes partway"></j-field>
124
+ <j-field name="leaves" label="Goes home"></j-field>
125
+ </j-sheet>
80
126
  <script type="module" src="./page.ts"></script>
81
127
  </body>
82
128
  </html>