@blueshed/joined 0.2.1 → 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 +270 -55
  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 +176 -38
  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 +11 -7
  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 +211 -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 +219 -73
  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,105 @@
1
+ // Written by src/compile.ts from examples/chart/stories.jsonl: change the stories, not this.
2
+
3
+ // Each collection is an element, defined here: on a page, it holds the document, and its items
4
+ // are put inside it. Each item is an element, defined by the page: as it is, or by a view that
5
+ // extends it. A field is an attribute (a list of ids as IDREFS: "1 3"), and an item's key the
6
+ // document's id for it. How an item looks is the app's: its view, or a display holding the
7
+ // collection draws it. Ops go up as an "ops" event, for the page to send to chart, with why they
8
+ // were made if it's said; only the ops the stories allow can be sent. Each returns its write's answer.
9
+
10
+ import { hold, letGo, type Answer } from "joined/page";
11
+
12
+ // the document an element is of: its collection's doc attribute (an instance of a kind, shelf:1), or chart
13
+ const docOf = (el: Element) => el.closest("[doc]")?.getAttribute("doc") ?? "chart";
14
+ // an element's ops go up as an "ops" event; what it returns is the write's answer, done or refused
15
+ const send = (from: Element, ops: object[], why?: string) => new Promise<Answer>((answer) => from.dispatchEvent(new CustomEvent("ops", { bubbles: true, composed: true, detail: { doc: docOf(from), ops, why, answer } })));
16
+
17
+ /** A surface's fields, as the stories give them. */
18
+ export type JSurfaceData = { "tooth": string; "surface": string; "material": string; "status": string };
19
+ /** An add of a surface, as it's sent: its fields as the stories write them. */
20
+ export type JSurfaceValue = { "tooth": string; "surface": string; "material": string; "status": string };
21
+
22
+ /** <j-surface key>: tooth (string), surface (string), material (string), status (string), each an attribute. */
23
+ export class JSurface extends HTMLElement {
24
+ static observedAttributes = ["tooth","surface","material","status","may"];
25
+ #data?: JSurfaceData;
26
+ /** Its id in the document. */
27
+ get key() { return Number(this.getAttribute("key")); }
28
+ get path() { return `/surfaces/${this.key}`; }
29
+ /** Its fields, read from its attributes once and again when one changes: frozen, since they're shared. */
30
+ get data(): JSurfaceData {
31
+ return (this.#data ??= Object.freeze({ "tooth": this.getAttribute("tooth") ?? "", "surface": this.getAttribute("surface") ?? "", "material": this.getAttribute("material") ?? "", "status": this.getAttribute("status") ?? "" }) as JSurfaceData);
32
+ }
33
+ /** How a view shows it, drawn again whenever an attribute changes (what its person may do, its may, too). */
34
+ draw?(): void;
35
+ attributeChangedCallback() { this.#data = undefined; this.draw?.(); }
36
+ /** Replace some of its fields (status, material): one write for all of them. */
37
+ replace(fields: Partial<Pick<JSurfaceData, "status" | "material">>, why?: string) {
38
+ return send(this, Object.entries(fields).filter(([, value]) => value !== undefined).map(([field, value]) => ({ op: "replace", path: `${this.path}/${field.replace(".", "/")}`, value })), why);
39
+ }
40
+ /** Remove it from the document. */
41
+ removeItem(why?: string) { return send(this, [{ op: "remove", path: this.path }], why); }
42
+ }
43
+
44
+ /** <j-surfaces>: the document's surfaces, each a <j-surface> inside it. */
45
+ export class JSurfaces extends HTMLElement {
46
+ connectedCallback() { hold(this, docOf(this), "surfaces", "j-surface", {"tooth":"string","surface":"string","material":"string","status":"string"}); }
47
+ disconnectedCallback() { letGo(this); }
48
+ /** Its surfaces, as the document has them. */
49
+ get items() { return [...this.children].filter((el): el is JSurface => el.localName === "j-surface"); }
50
+ /** Add surfaces: one write for all of them. */
51
+ add(...values: JSurfaceValue[]) { return send(this, values.map((value) => ({ op: "add", path: "/surfaces/-", value }))); }
52
+ }
53
+ customElements.define("j-surfaces", JSurfaces);
54
+
55
+ /** A condition's fields, as the stories give them. */
56
+ export type JConditionData = { "tooth": string; "state": string; "status": string };
57
+ /** An add of a condition, as it's sent: its fields as the stories write them. */
58
+ export type JConditionValue = { "tooth": string; "state": string; "status": string };
59
+
60
+ /** <j-condition key>: tooth (string), state (string), status (string), each an attribute. */
61
+ export class JCondition extends HTMLElement {
62
+ static observedAttributes = ["tooth","state","status","may"];
63
+ #data?: JConditionData;
64
+ /** Its id in the document. */
65
+ get key() { return Number(this.getAttribute("key")); }
66
+ get path() { return `/conditions/${this.key}`; }
67
+ /** Its fields, read from its attributes once and again when one changes: frozen, since they're shared. */
68
+ get data(): JConditionData {
69
+ return (this.#data ??= Object.freeze({ "tooth": this.getAttribute("tooth") ?? "", "state": this.getAttribute("state") ?? "", "status": this.getAttribute("status") ?? "" }) as JConditionData);
70
+ }
71
+ /** How a view shows it, drawn again whenever an attribute changes (what its person may do, its may, too). */
72
+ draw?(): void;
73
+ attributeChangedCallback() { this.#data = undefined; this.draw?.(); }
74
+ /** Replace some of its fields (status): one write for all of them. */
75
+ replace(fields: Partial<Pick<JConditionData, "status">>, why?: string) {
76
+ return send(this, Object.entries(fields).filter(([, value]) => value !== undefined).map(([field, value]) => ({ op: "replace", path: `${this.path}/${field.replace(".", "/")}`, value })), why);
77
+ }
78
+ /** Remove it from the document. */
79
+ removeItem(why?: string) { return send(this, [{ op: "remove", path: this.path }], why); }
80
+ }
81
+
82
+ /** <j-conditions>: the document's conditions, each a <j-condition> inside it. */
83
+ export class JConditions extends HTMLElement {
84
+ connectedCallback() { hold(this, docOf(this), "conditions", "j-condition", {"tooth":"string","state":"string","status":"string"}); }
85
+ disconnectedCallback() { letGo(this); }
86
+ /** Its conditions, as the document has them. */
87
+ get items() { return [...this.children].filter((el): el is JCondition => el.localName === "j-condition"); }
88
+ /** Add conditions: one write for all of them. */
89
+ add(...values: JConditionValue[]) { return send(this, values.map((value) => ({ op: "add", path: "/conditions/-", value }))); }
90
+ }
91
+ customElements.define("j-conditions", JConditions);
92
+
93
+ /** An op on chart the stories allow, in any of its collections. */
94
+ export type ChartOp =
95
+ | { op: "add"; path: "/surfaces/-"; value: JSurfaceValue }
96
+ | { op: "replace"; path: `/surfaces/${number}/status`; value: string }
97
+ | { op: "replace"; path: `/surfaces/${number}/material`; value: string }
98
+ | { op: "remove"; path: `/surfaces/${number}` }
99
+ | { op: "add"; path: "/conditions/-"; value: JConditionValue }
100
+ | { op: "replace"; path: `/conditions/${number}/status`; value: string }
101
+ | { op: "remove"; path: `/conditions/${number}` };
102
+
103
+ /** One write to chart across its collections (a move with its legs): sent from an element of it, checked
104
+ * whole by its rules, and made whole or not at all. */
105
+ export function write(from: Element, ops: ChartOp[], why?: string) { return send(from, ops, why); }
@@ -0,0 +1,36 @@
1
+ // Written by src/compile.ts from examples/chart/stories.jsonl: change the stories, not this.
2
+
3
+ /** Each collection's item, as one row of its table (`t`) is it: what the query gathers, and what the store keeps of a
4
+ * row a write changes, before and after, to tell each document holding it. */
5
+ export const items: Record<string, string> = {
6
+ "surfaces": "json_patch('{}', json_object('id', t.id,\n 'tooth', t.\"tooth\",\n 'surface', t.\"surface\",\n 'material', t.\"material\",\n 'status', t.\"status\"))",
7
+ "conditions": "json_patch('{}', json_object('id', t.id,\n 'tooth', t.\"tooth\",\n 'state', t.\"state\",\n 'status', t.\"status\"))"
8
+ };
9
+
10
+ /** chart, whole, as one statement over its tables (SQLite): its parameters $doc. */
11
+ export const query = `SELECT json_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),
12
+ 'surfaces', json((SELECT json_group_array(json_patch('{}', json_object('id', t.id,
13
+ 'tooth', t."tooth",
14
+ 'surface', t."surface",
15
+ 'material', t."material",
16
+ 'status', t."status")) ORDER BY t.id)
17
+ FROM "surfaces" t)),
18
+ 'conditions', json((SELECT json_group_array(json_patch('{}', json_object('id', t.id,
19
+ 'tooth', t."tooth",
20
+ 'state', t."state",
21
+ 'status', t."status")) ORDER BY t.id)
22
+ FROM "conditions" t))) AS doc`;
23
+
24
+ /** Its rules over values (definitions' takes, gives and totals), as triggers the store makes in its database: run in
25
+ * each write's transaction, and told as any change is. */
26
+ export const triggers: string[] = [];
27
+
28
+ /** Its items, its query and its triggers, as Postgres says them. */
29
+ export const postgres = {
30
+ "items": {
31
+ "surfaces": "json_strip_nulls(json_build_object('id', t.id,\n 'tooth', t.\"tooth\",\n 'surface', t.\"surface\",\n 'material', t.\"material\",\n 'status', t.\"status\"))",
32
+ "conditions": "json_strip_nulls(json_build_object('id', t.id,\n 'tooth', t.\"tooth\",\n 'state', t.\"state\",\n 'status', t.\"status\"))"
33
+ },
34
+ "query": "SELECT json_build_object('version', COALESCE((SELECT version FROM documents WHERE name = $doc), 0),\n 'surfaces', (SELECT COALESCE(json_agg(json_strip_nulls(json_build_object('id', t.id,\n 'tooth', t.\"tooth\",\n 'surface', t.\"surface\",\n 'material', t.\"material\",\n 'status', t.\"status\")) ORDER BY t.id), '[]')\n FROM \"surfaces\" t),\n 'conditions', (SELECT COALESCE(json_agg(json_strip_nulls(json_build_object('id', t.id,\n 'tooth', t.\"tooth\",\n 'state', t.\"state\",\n 'status', t.\"status\")) ORDER BY t.id), '[]')\n FROM \"conditions\" t)) AS doc",
35
+ "triggers": []
36
+ };
@@ -0,0 +1,27 @@
1
+ // Written by src/compile.ts from examples/chart/stories.jsonl: change the stories, not this.
2
+
3
+ // Each collection of chart 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-surfaces-rows><j-surfaces></j-surfaces></j-surfaces-rows>
6
+ // <j-conditions-rows><j-conditions></j-conditions></j-conditions-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 { JSurface, JCondition } from "./elements.ts";
16
+
17
+ const surfaces: Spec = {"doc":"chart","name":"surfaces","place":"j-surfaces","tag":"j-surface","one":"surface","title":"tooth","fields":[{"name":"tooth","type":"string","needed":true},{"name":"surface","type":"string","needed":true},{"name":"material","type":"string","needed":true},{"name":"status","type":"string","needed":true}]};
18
+ const conditions: Spec = {"doc":"chart","name":"conditions","place":"j-conditions","tag":"j-condition","one":"condition","title":"tooth","fields":[{"name":"tooth","type":"string","needed":true},{"name":"state","type":"string","needed":true},{"name":"status","type":"string","needed":true}]};
19
+
20
+ /** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
21
+ export const specs = { "surfaces": surfaces, "conditions": conditions };
22
+
23
+ /** <j-surfaces-rows>: chart's surfaces as rows, each named by its tooth. */
24
+ export class JSurfacesRows extends rows(surfaces, { "j-surface": JSurface }) {}
25
+
26
+ /** <j-conditions-rows>: chart's conditions as rows, each named by its tooth. */
27
+ export class JConditionsRows extends rows(conditions, { "j-condition": JCondition }) {}
@@ -0,0 +1,111 @@
1
+ // Written by src/compile.ts from examples/chart/stories.jsonl: change the stories, not this.
2
+
3
+ export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
4
+
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 and what each field pops (a value with a form, its view; a reference, what it points at). */
7
+ export const doc = "chart";
8
+ export const collections = {
9
+ "surfaces": {
10
+ "place": "j-surfaces",
11
+ "tag": "j-surface",
12
+ "fields": {
13
+ "tooth": "string",
14
+ "surface": "string",
15
+ "material": "string",
16
+ "status": "string"
17
+ },
18
+ "needs": [
19
+ "tooth",
20
+ "surface",
21
+ "material",
22
+ "status"
23
+ ],
24
+ "links": {},
25
+ "pops": {}
26
+ },
27
+ "conditions": {
28
+ "place": "j-conditions",
29
+ "tag": "j-condition",
30
+ "fields": {
31
+ "tooth": "string",
32
+ "state": "string",
33
+ "status": "string"
34
+ },
35
+ "needs": [
36
+ "tooth",
37
+ "state",
38
+ "status"
39
+ ],
40
+ "links": {},
41
+ "pops": {}
42
+ }
43
+ } as const;
44
+ /** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */
45
+ export const anonymous = true;
46
+ /** What kind of document chart is, by the flows it uses: static, changed only with a release (a page reads it, and
47
+ * never subscribes); read-only, live, but no page writes it (derived); or shared, its members' to write. */
48
+ export const type = "shared";
49
+ /** The parts of chart a page may hold alone, by its query's parameters (its definitions' window): null, none. */
50
+ export const window = null;
51
+ /** The document as one statement over its tables (generated/queries.ts). */
52
+ export { query, postgres, items, triggers } from "./queries.ts";
53
+
54
+ /** Why the document, as a write leaves it, breaks what its definitions hold (unique, noOverlap): each item the
55
+ * write touched, against the rest of its collection. Null if it holds. */
56
+ export function holds(d: Record<string, unknown>, touched: Record<string, number[]>): string | null {
57
+ for (const id of touched["surfaces"] ?? []) {
58
+ const all = (d["surfaces"] ?? []) as any[];
59
+ const a = all.find((i) => i.id === id);
60
+ if (!a) continue;
61
+ {
62
+ const b = all.find((i) => i.id !== a.id && a["tooth"] !== undefined && i["tooth"] === a["tooth"] && a["surface"] !== undefined && i["surface"] === a["surface"]);
63
+ if (b) return "surfaces " + b.id + " has that tooth and surface already";
64
+ }
65
+ }
66
+ for (const id of touched["conditions"] ?? []) {
67
+ const all = (d["conditions"] ?? []) as any[];
68
+ const a = all.find((i) => i.id === id);
69
+ if (!a) continue;
70
+ {
71
+ const b = all.find((i) => i.id !== a.id && a["tooth"] !== undefined && i["tooth"] === a["tooth"] && a["state"] !== undefined && i["state"] === a["state"]);
72
+ if (b) return "conditions " + b.id + " has that tooth and state already";
73
+ }
74
+ }
75
+ return null;
76
+ }
77
+
78
+ /** chart is one document. */
79
+ export const kind = null;
80
+
81
+ /** Each grant, read off the stories: the roles whose stories do it (a member: anyone). An op no story
82
+ * does isn't one. */
83
+ export const grants: Record<string, string[]> = {
84
+ "add conditions": [
85
+ "member"
86
+ ],
87
+ "add surfaces": [
88
+ "member"
89
+ ],
90
+ "remove conditions": [
91
+ "member"
92
+ ],
93
+ "remove surfaces": [
94
+ "member"
95
+ ],
96
+ "replace conditions.status": [
97
+ "member"
98
+ ],
99
+ "replace surfaces.material": [
100
+ "member"
101
+ ],
102
+ "replace surfaces.status": [
103
+ "member"
104
+ ]
105
+ };
106
+
107
+ /** Who someone is to chart: a member, as it names no roles. */
108
+ export const rolesOf = (_m: number, _read: (doc: string) => any, _doc: string, _at?: any): string[] => [];
109
+
110
+ /** What someone sees: all of chart, as it has no owns. */
111
+ export const sees = null;
@@ -0,0 +1,118 @@
1
+ // The NHS grid, drawn once: a five-surface box for each tooth in the Palmer grid (data-slot="UR6 M"), the patient's
2
+ // right on the left, each tooth in profile above and below (its crown and roots); each tooth a place of its own around
3
+ // its box (data-slot="UR6"), its condition drawn across it: a cross, a ring, its roots filled.
4
+
5
+ import { conditionStyle, s, sides, TEETH, type Tooth } from "./teeth.ts";
6
+
7
+ /** A tooth in profile, above or below its box: its crown, and its roots (upper molars three, lower two). */
8
+ function profile(t: Tooth, cx: number) {
9
+ const up = t.row === "U",
10
+ neck = up ? 72 : 212,
11
+ Y = (v: number) => (up ? 72 + v : 212 - v),
12
+ dir = up ? -1 : 1,
13
+ cw = { 1: 22, 2: 18, 3: 22, 4: 21, 5: 21, 6: 32, 7: 30, 8: 28 }[t.n]!,
14
+ roots = up ? (t.n <= 3 ? 1 : t.n === 4 ? 2 : t.n === 5 ? 1 : 3) : t.n <= 5 ? 1 : 2,
15
+ len = t.n === 3 ? 44 : 36,
16
+ sw = cw * 0.7;
17
+ const g = s("g", { style: "pointer-events: none" });
18
+ for (let r = 0; r < roots; r++) {
19
+ const bx = cx - sw / 2 + (sw * (r + 0.5)) / roots,
20
+ bw = (sw / roots) * 0.95,
21
+ ay = neck + dir * len * (roots === 3 && r === 1 ? 0.82 : 1);
22
+ g.append(
23
+ s("path", {
24
+ style: "fill: var(--well); stroke: var(--muted)",
25
+ d: `M${bx - bw / 2},${neck} C${bx - bw / 2},${(neck + ay) / 2} ${bx - bw * 0.2},${ay} ${bx},${ay} C${bx + bw * 0.2},${ay} ${bx + bw / 2},${(neck + ay) / 2} ${bx + bw / 2},${neck} Z`,
26
+ }),
27
+ s("path", { d: `M${bx},${neck} L${bx},${ay - dir * 4}`, class: "rootfill" }),
28
+ );
29
+ }
30
+ const L = cx - cw / 2,
31
+ R = cx + cw / 2,
32
+ edge =
33
+ t.n >= 6
34
+ ? `Q${cx - cw * 0.21},${Y(30)} ${cx},${Y(26)} Q${cx + cw * 0.21},${Y(30)} ${cx + cw * 0.42},${Y(26)}`
35
+ : t.n >= 3
36
+ ? `Q${cx},${Y(t.n === 3 ? 33 : 30)} ${cx + cw * 0.42},${Y(26)}`
37
+ : `L${cx + cw * 0.42},${Y(26)}`;
38
+ g.append(
39
+ s("path", {
40
+ style: "fill: var(--card); stroke: var(--muted)",
41
+ d: `M${cx - cw * 0.37},${Y(0)} C${L - cw * 0.06},${Y(4)} ${L - cw * 0.02},${Y(18)} ${cx - cw * 0.42},${Y(26)} ${edge} C${R + cw * 0.02},${Y(18)} ${R + cw * 0.06},${Y(4)} ${cx + cw * 0.37},${Y(0)} Z`,
42
+ }),
43
+ );
44
+ return g;
45
+ }
46
+
47
+ /** The NHS grid: a five-surface box for each tooth in the Palmer grid, its name, and the tooth in profile. */
48
+ export function grid() {
49
+ const svg = s("svg", {
50
+ slot: "ground",
51
+ viewBox: "0 0 680 285",
52
+ role: "img",
53
+ "aria-label": "The teeth, as the NHS grid charts them",
54
+ });
55
+ svg.append(conditionStyle());
56
+ for (const t of TEETH) {
57
+ const x = 20 + t.i * 40,
58
+ y = t.row === "U" ? 102 : 142,
59
+ ant = t.n <= 3,
60
+ size = 40,
61
+ ax = ant ? size * 0.18 : size * 0.3,
62
+ ay = ant ? size * 0.42 : size * 0.3,
63
+ side = sides(t);
64
+ const P: Record<string, number[][]> = {
65
+ top: [
66
+ [0, 0],
67
+ [size, 0],
68
+ [size - ax, ay],
69
+ [ax, ay],
70
+ ],
71
+ bot: [
72
+ [0, size],
73
+ [size, size],
74
+ [size - ax, size - ay],
75
+ [ax, size - ay],
76
+ ],
77
+ left: [
78
+ [0, 0],
79
+ [ax, ay],
80
+ [ax, size - ay],
81
+ [0, size],
82
+ ],
83
+ right: [
84
+ [size, 0],
85
+ [size, size],
86
+ [size - ax, size - ay],
87
+ [size - ax, ay],
88
+ ],
89
+ };
90
+ const box = s("g", { transform: `translate(${x} ${y})` });
91
+ for (const [k, pts] of Object.entries(P))
92
+ box.append(
93
+ s("polygon", {
94
+ points: pts.map((p) => p.join(",")).join(" "),
95
+ "data-slot": `${t.key} ${side[k as keyof typeof side]}`,
96
+ }),
97
+ );
98
+ box.append(
99
+ s("rect", { x: ax, y: ay, width: size - 2 * ax, height: size - 2 * ay, "data-slot": `${t.key} O` }),
100
+ s("rect", { x: 2, y: 2, width: size - 4, height: size - 4, class: "ring" }),
101
+ s("path", { d: `M3,3 L${size - 3},${size - 3} M${size - 3},3 L3,${size - 3}`, class: "x" }),
102
+ );
103
+ const name = s("text", {
104
+ x: x + 20,
105
+ y: t.row === "U" ? 12 : 274,
106
+ "font-size": 11,
107
+ style: "fill: var(--muted)",
108
+ "text-anchor": "middle",
109
+ });
110
+ name.textContent = t.key;
111
+ svg.append(s("g", { "data-slot": t.key }, profile(t, x + 20), box), name);
112
+ }
113
+ svg.append(
114
+ s("line", { x1: 340, y1: 20, x2: 340, y2: 262, style: "stroke: var(--ink); stroke-width: 1.6" }),
115
+ s("line", { x1: 20, y1: 142, x2: 660, y2: 142, style: "stroke: var(--ink); stroke-width: 1.4" }),
116
+ );
117
+ return svg;
118
+ }
@@ -0,0 +1,78 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>joined: a dental chart</title>
7
+ <link rel="stylesheet" href="joined/tokens.css" />
8
+ <link rel="stylesheet" href="joined/page.css" />
9
+ <link rel="stylesheet" href="../app.css" />
10
+ <link rel="stylesheet" href="./chart.css" />
11
+ </head>
12
+ <body>
13
+ <a class="brand" href="/"><img src="joined/icon.png" alt="" width="28" height="28" />joined</a>
14
+ <h1>A dental chart</h1>
15
+ <p class="lead">
16
+ Choose what's there and, for this course, To do or Done, then tap a surface on either drawing: it's charted on
17
+ both at once, and the account takes care of itself. Both off, it's charted as found. Extract, Crown and Root
18
+ filling chart the whole tooth (a root filling on the grid, where roots are drawn): Extract with both off, it's
19
+ missing. Clear takes off what's tapped; Undo puts back the last change.
20
+ </p>
21
+ <main class="chart">
22
+ <section class="card" aria-label="The arches">
23
+ <h2>The arches</h2>
24
+ <j-slots
25
+ for="surfaces"
26
+ slot="tooth surface"
27
+ hue="status"
28
+ hues="to do:hue-2,done:hue-0,existing:ink"
29
+ layer="conditions"
30
+ layer-by="state"
31
+ layer-says="status"
32
+ pale="material:composite"
33
+ class="arches"
34
+ >
35
+ <j-tool sets="material" value="amalgam">Amalgam</j-tool>
36
+ <j-tool sets="material" value="composite">Composite</j-tool>
37
+ <j-tool sets="status" value="to do">To do</j-tool>
38
+ <j-tool sets="status" value="done">Done</j-tool>
39
+ <j-tool sets="status" value="existing" default></j-tool>
40
+ <j-tool clears>Clear</j-tool>
41
+ <j-tool for="conditions" sets="state" value="extract">Extract</j-tool>
42
+ <j-tool for="conditions" sets="state" value="crown">Crown</j-tool>
43
+ </j-slots>
44
+ </section>
45
+ <section class="card" aria-label="The NHS grid">
46
+ <h2>The NHS grid</h2>
47
+ <j-slots
48
+ for="surfaces"
49
+ slot="tooth surface"
50
+ hue="status"
51
+ hues="to do:hue-2,done:hue-0,existing:ink"
52
+ layer="conditions"
53
+ layer-by="state"
54
+ layer-says="status"
55
+ pale="material:composite"
56
+ class="grid"
57
+ >
58
+ <j-tool sets="material" value="amalgam">Amalgam</j-tool>
59
+ <j-tool sets="material" value="composite">Composite</j-tool>
60
+ <j-tool sets="status" value="to do">To do</j-tool>
61
+ <j-tool sets="status" value="done">Done</j-tool>
62
+ <j-tool sets="status" value="existing" default></j-tool>
63
+ <j-tool clears>Clear</j-tool>
64
+ <j-tool for="conditions" sets="state" value="extract">Extract</j-tool>
65
+ <j-tool for="conditions" sets="state" value="crown">Crown</j-tool>
66
+ <j-tool for="conditions" sets="state" value="root filling">Root filling</j-tool>
67
+ </j-slots>
68
+ </section>
69
+ <section class="card" aria-label="The account">
70
+ <h2>The account</h2>
71
+ <j-charges-rows><j-charges doc="account"></j-charges></j-charges-rows>
72
+ </section>
73
+ <div hidden><j-surfaces doc="chart"></j-surfaces><j-conditions doc="chart"></j-conditions></div>
74
+ </main>
75
+ <j-sheet for="surfaces"></j-sheet>
76
+ <script type="module" src="./page.ts"></script>
77
+ </body>
78
+ </html>
@@ -0,0 +1,6 @@
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("surfaces", { columns: { tooth: { type: "text", is: { type: "string", said: "tooth is a string" } }, surface: { type: "text", is: { type: "string", said: "surface is a string" } }, material: { type: "text", is: { type: "string", said: "material is a string" } }, status: { type: "text", is: { type: "string", said: "status is a string" } } }, strict: true, needs: { columns: ["tooth", "surface", "material", "status"], said: "a surface needs tooth (string), surface (string), material (string), status (string)" } }),
6
+ ];
@@ -0,0 +1,6 @@
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("conditions", { columns: { tooth: { type: "text", is: { type: "string", said: "tooth is a string" } }, state: { type: "text", is: { type: "string", said: "state is a string" } }, status: { type: "text", is: { type: "string", said: "status is a string" } } }, strict: true, needs: { columns: ["tooth", "state", "status"], said: "a condition needs tooth (string), state (string), status (string)" } }),
6
+ ];
@@ -0,0 +1,20 @@
1
+ // The chart's page: the mouth drawn once, both ways (./arches.ts, ./grid.ts), put in each map before joined's kit is given the
2
+ // chart's collections; the account's rows as the compiler writes them; the surfaces' elements as compiled.
3
+
4
+ import "joined/toast";
5
+ import "joined/kit";
6
+ import { use } from "joined/kit";
7
+ import { define } from "joined/rows";
8
+ import { specs } from "./generated/rows.ts";
9
+ import { collections } from "./generated/rules.ts";
10
+ import { JCondition, JSurface } from "./generated/elements.ts";
11
+ import { JChargesRows } from "../account/generated/rows.ts";
12
+ import { arches } from "./arches.ts";
13
+ import { grid } from "./grid.ts";
14
+
15
+ document.querySelector("j-slots.arches")!.append(arches());
16
+ document.querySelector("j-slots.grid")!.append(grid());
17
+ use(specs);
18
+ define(JChargesRows);
19
+ customElements.define(collections.surfaces.tag, JSurface);
20
+ customElements.define(collections.conditions.tag, JCondition);
@@ -0,0 +1,7 @@
1
+ // A dental chart: a patient's teeth, each surface charted with what's to be done to it and what's done, drawn two
2
+ // ways as dentists draw it (the arches, and the NHS grid), with the course's account derived from it (../account).
3
+
4
+ import page from "./index.html";
5
+
6
+ export * as document from "./generated/rules.ts";
7
+ export const routes = { "/chart": page };
@@ -0,0 +1,14 @@
1
+ {"unique":{"surfaces":[["tooth","surface"]],"conditions":[["tooth","state"]]}}
2
+ {"story":"The dentist charts a cavity in UR5's mesial surface, to fill with amalgam","does":{"doc":"chart","ops":[{"op":"add","path":"/surfaces/-","value":{"tooth":"UR5","surface":"M","material":"amalgam","status":"to do"}}]}}
3
+ {"story":"The filling is done","does":{"doc":"chart","ops":[{"op":"replace","path":"/surfaces/2/status","value":"done"}]}}
4
+ {"story":"It's filled with composite instead","does":{"doc":"chart","ops":[{"op":"replace","path":"/surfaces/2/material","value":"composite"}]}}
5
+ {"story":"A surface charted by mistake is taken off","does":{"doc":"chart","ops":[{"op":"remove","path":"/surfaces/3"}]}}
6
+ {"story":"A surface is charted once: what's done to it is changed, never charted again","cannot":{"doc":"chart","ops":[{"op":"add","path":"/surfaces/-","value":{"tooth":"UR6","surface":"M","material":"composite","status":"to do"}}]}}
7
+ {"story":"A surface needs its tooth","cannot":{"doc":"chart","ops":[{"op":"add","path":"/surfaces/-","value":{"surface":"M","material":"amalgam","status":"to do"}}]}}
8
+ {"story":"At the first look, a filling already there is charted as it is: pre-existing","does":{"doc":"chart","ops":[{"op":"add","path":"/surfaces/-","value":{"tooth":"LL5","surface":"O","material":"amalgam","status":"existing"}}]}}
9
+ {"story":"UR8 is to be extracted","does":{"doc":"chart","ops":[{"op":"add","path":"/conditions/-","value":{"tooth":"UR8","state":"extract","status":"to do"}}]}}
10
+ {"story":"LR8 is extracted","does":{"doc":"chart","ops":[{"op":"replace","path":"/conditions/2/status","value":"done"}]}}
11
+ {"story":"A tooth's condition charted by mistake is taken off","does":{"doc":"chart","ops":[{"op":"remove","path":"/conditions/1"}]}}
12
+ {"story":"LR7, root filled, is to be crowned too: both are kept","does":{"doc":"chart","ops":[{"op":"add","path":"/conditions/-","value":{"tooth":"LR7","state":"crown","status":"to do"}}]}}
13
+ {"story":"LR7's root filling is done","does":{"doc":"chart","ops":[{"op":"replace","path":"/conditions/3/status","value":"done"}]}}
14
+ {"story":"A tooth is crowned once: its crown is changed, never charted again","cannot":{"doc":"chart","ops":[{"op":"add","path":"/conditions/-","value":{"tooth":"LL6","state":"crown","status":"to do"}}]}}
@@ -0,0 +1,57 @@
1
+ // The teeth a chart draws: the 32 by their Palmer names, each kind's size, which side of a box is which surface, and an
2
+ // SVG element made. What the two pictures (./arches.ts, ./grid.ts) share.
3
+
4
+ const NS = "http://www.w3.org/2000/svg";
5
+ export const s = (tag: string, attrs: Record<string, string | number> = {}, ...inside: Element[]) => {
6
+ const e = document.createElementNS(NS, tag);
7
+ for (const [k, v] of Object.entries(attrs)) e.setAttribute(k, String(v));
8
+ e.append(...inside);
9
+ return e;
10
+ };
11
+ /** The 32 teeth: upper then lower, each row from the patient's right to their left, as Palmer names them. */
12
+ export const TEETH = ["U", "L"].flatMap((row) =>
13
+ Array.from({ length: 16 }, (_, i) => ({
14
+ row,
15
+ i,
16
+ key: `${row}${i < 8 ? "R" : "L"}${i < 8 ? 8 - i : i - 7}`,
17
+ n: i < 8 ? 8 - i : i - 7,
18
+ })),
19
+ );
20
+ export type Tooth = (typeof TEETH)[number];
21
+ /** Its mesio-distal width and bucco-lingual depth, by its kind. */
22
+ export const DIM: Record<number, [number, number]> = {
23
+ 1: [13, 10],
24
+ 2: [11, 9.5],
25
+ 3: [12, 12],
26
+ 4: [11.5, 13.5],
27
+ 5: [11, 13],
28
+ 6: [15, 16],
29
+ 7: [14, 15],
30
+ 8: [13, 14],
31
+ };
32
+ /** Which of a box's sides is which surface, as the chart has it: buccal outside, mesial toward the midline. */
33
+ export const sides = (t: Tooth) => ({
34
+ top: t.row === "U" ? "B" : "L",
35
+ bot: t.row === "U" ? "L" : "B",
36
+ left: t.i < 8 ? "D" : "M",
37
+ right: t.i < 8 ? "M" : "D",
38
+ });
39
+
40
+ /** How a tooth's conditions are drawn, as its place says them (data-extract, data-crown, data-root-filling, each its
41
+ * status): missing (to extract, as found) faint; a cross to extract; a crown's ring; its roots filled; red to do,
42
+ * blue done, ink as found. Put in each picture, so it's drawn in the map's own shadow. */
43
+ export const conditionStyle = () => {
44
+ const style = document.createElementNS("http://www.w3.org/2000/svg", "style");
45
+ const by = (status: string, colour: string) =>
46
+ `[data-extract="${status}"] .x, [data-crown="${status}"] .ring, [data-root-filling="${status}"] .rootfill { display: inline; stroke: var(--${colour}); }`;
47
+ style.textContent = `
48
+ .outline { fill: none; stroke: var(--ink); pointer-events: none; }
49
+ .x, .ring, .rootfill { display: none; fill: none; stroke-width: 2.5; stroke-linecap: round; pointer-events: none; }
50
+ ${by("to do", "hue-2")}
51
+ ${by("done", "hue-0")}
52
+ [data-crown="existing"] .ring, [data-root-filling="existing"] .rootfill { display: inline; stroke: var(--ink); }
53
+ [data-extract="existing"] { opacity: 0.25; }
54
+ [data-extract="done"] { opacity: 0.4; }
55
+ `;
56
+ return style;
57
+ };
@@ -0,0 +1,22 @@
1
+ // Written by src/compile.ts from examples/desk/stories.jsonl: change the stories, not this.
2
+
3
+ // Each collection of desk 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-tasks-rows><j-tasks></j-tasks></j-tasks-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 { JTask } from "./elements.ts";
15
+
16
+ const tasks: Spec = {"doc":"desk","name":"tasks","place":"j-tasks","tag":"j-task","one":"task","title":"title","fields":[{"name":"title","type":"string","needed":true},{"name":"points","type":"integer","needed":true},{"name":"rank","type":"decimal","needed":true},{"name":"status","type":"string","how":"moves","steps":["queued","working","review","done"]},{"name":"ups","type":"ids","how":"mine","with":["downs"],"to":{"tag":"j-member","people":true},"ref":true},{"name":"downs","type":"ids","how":"mine","with":["ups"],"to":{"tag":"j-member","people":true},"ref":true},{"name":"by","type":"integer","how":"filled","to":{"tag":"j-member","people":true},"ref":true},{"name":"added","type":"instant","how":"filled"}]};
17
+
18
+ /** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
19
+ export const specs = { "tasks": tasks };
20
+
21
+ /** <j-tasks-rows>: desk's tasks as rows, each named by its title. */
22
+ export class JTasksRows extends rows(tasks, { "j-task": JTask }) {}