@blueshed/joined 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/.claude/skills/joined/SKILL.md +9 -1
  2. package/.claude/skills/joined/reference.md +316 -63
  3. package/.claude/skills/joined-door/SKILL.md +57 -0
  4. package/README.md +19 -50
  5. package/docs/design.md +158 -37
  6. package/docs/introduction.md +27 -27
  7. package/docs/light-and-shadow.svg +2 -1
  8. package/docs/links-and-trust.svg +1 -0
  9. package/docs/stories-to-code.svg +2 -1
  10. package/docs/wire-op.svg +1 -0
  11. package/examples/README.md +20 -0
  12. package/examples/account/account.json +1 -0
  13. package/examples/account/derive.ts +41 -0
  14. package/examples/account/generated/elements.ts +52 -0
  15. package/examples/account/generated/rows.ts +22 -0
  16. package/examples/account/generated/rules.ts +32 -0
  17. package/examples/account/routes.ts +5 -0
  18. package/examples/app.css +11 -1
  19. package/examples/cafe/books.html +2 -2
  20. package/examples/cafe/cafe.css +96 -85
  21. package/examples/cafe/generated/books.rows.ts +22 -0
  22. package/examples/cafe/generated/books.rules.ts +3 -2
  23. package/examples/cafe/generated/kitchen.rows.ts +27 -0
  24. package/examples/cafe/generated/kitchen.rules.ts +11 -1
  25. package/examples/cafe/generated/menu.rows.ts +22 -0
  26. package/examples/cafe/generated/menu.rules.ts +3 -2
  27. package/examples/cafe/generated/order.rows.ts +27 -0
  28. package/examples/cafe/generated/order.rules.ts +11 -1
  29. package/examples/cafe/generated/staff.elements.ts +7 -2
  30. package/examples/cafe/generated/staff.rows.ts +22 -0
  31. package/examples/cafe/generated/staff.rules.ts +9 -1
  32. package/examples/cafe/generated/supplies.queries.ts +4 -2
  33. package/examples/cafe/generated/supplies.rows.ts +22 -0
  34. package/examples/cafe/generated/supplies.rules.ts +17 -1
  35. package/examples/cafe/generated/till.queries.ts +2 -0
  36. package/examples/cafe/generated/till.rows.ts +27 -0
  37. package/examples/cafe/generated/till.rules.ts +11 -1
  38. package/examples/cafe/index.html +14 -15
  39. package/examples/cafe/kitchen.css +11 -19
  40. package/examples/cafe/kitchen.ts +7 -3
  41. package/examples/cafe/look.ts +30 -0
  42. package/examples/cafe/menu.html +10 -26
  43. package/examples/cafe/menu.ts +8 -80
  44. package/examples/cafe/migrations/002-guard-supplies.ts +15 -0
  45. package/examples/cafe/order.html +8 -7
  46. package/examples/cafe/order.ts +6 -2
  47. package/examples/cafe/routes.ts +0 -1
  48. package/examples/cafe/staff.json +5 -0
  49. package/examples/cafe/stories.jsonl +6 -2
  50. package/examples/cafe/supplies.html +35 -34
  51. package/examples/cafe/supplies.ts +59 -39
  52. package/examples/cafe/till.ts +19 -11
  53. package/examples/cafe/views.ts +7 -5
  54. package/examples/chart/arches.ts +150 -0
  55. package/examples/chart/chart.css +11 -0
  56. package/examples/chart/chart.json +87 -0
  57. package/examples/chart/generated/elements.ts +105 -0
  58. package/examples/chart/generated/queries.ts +36 -0
  59. package/examples/chart/generated/rows.ts +27 -0
  60. package/examples/chart/generated/rules.ts +111 -0
  61. package/examples/chart/grid.ts +118 -0
  62. package/examples/chart/index.html +78 -0
  63. package/examples/chart/migrations/001-chart.ts +6 -0
  64. package/examples/chart/migrations/002-create-conditions.ts +6 -0
  65. package/examples/chart/page.ts +20 -0
  66. package/examples/chart/routes.ts +7 -0
  67. package/examples/chart/stories.jsonl +14 -0
  68. package/examples/chart/teeth.ts +57 -0
  69. package/examples/desk/desk.css +6 -10
  70. package/examples/desk/generated/elements.ts +1 -1
  71. package/examples/desk/generated/rows.ts +22 -0
  72. package/examples/desk/generated/rules.ts +34 -1
  73. package/examples/desk/index.html +10 -3
  74. package/examples/desk/lanes.css +21 -19
  75. package/examples/desk/routes.ts +0 -2
  76. package/examples/desk/stories.jsonl +4 -3
  77. package/examples/desk/tally.css +1 -1
  78. package/examples/desk/thumbs.ts +2 -2
  79. package/examples/docs.ts +7 -4
  80. package/examples/hello/generated/elements.ts +2 -2
  81. package/examples/hello/generated/rules.ts +3 -2
  82. package/examples/hello/hello.css +2 -4
  83. package/examples/hello/index.html +10 -3
  84. package/examples/hello/page.ts +4 -4
  85. package/examples/index.html +20 -12
  86. package/examples/notes/generated/elements.ts +112 -0
  87. package/examples/notes/generated/queries.ts +42 -0
  88. package/examples/notes/generated/rows.ts +27 -0
  89. package/examples/notes/generated/rules.ts +133 -0
  90. package/examples/notes/index.html +32 -0
  91. package/examples/notes/look.ts +41 -0
  92. package/examples/notes/migrations/001-notes.ts +7 -0
  93. package/examples/notes/notes.json +78 -0
  94. package/examples/notes/page.ts +21 -0
  95. package/examples/notes/routes.ts +6 -0
  96. package/examples/notes/stories.jsonl +24 -0
  97. package/examples/page.ts +9 -2
  98. package/examples/people/generated/rows.ts +22 -0
  99. package/examples/people/generated/rules.ts +11 -1
  100. package/examples/people/links.ts +8 -9
  101. package/examples/people/people.css +1 -1
  102. package/examples/people/routes.ts +1 -3
  103. package/examples/people/stories.jsonl +1 -0
  104. package/examples/people/view.ts +5 -2
  105. package/examples/trip/generated/elements.ts +5 -3
  106. package/examples/trip/generated/queries.ts +12 -1
  107. package/examples/trip/generated/rows.ts +27 -0
  108. package/examples/trip/generated/rules.ts +56 -2
  109. package/examples/trip/index.html +58 -12
  110. package/examples/trip/line.css +186 -0
  111. package/examples/trip/line.ts +51 -40
  112. package/examples/trip/page.ts +65 -71
  113. package/examples/trip/routes.ts +9 -5
  114. package/examples/trip/stays.css +13 -13
  115. package/examples/trip/stays.ts +15 -10
  116. package/examples/trip/stories.jsonl +2 -0
  117. package/examples/trip/told.ts +3 -26
  118. package/examples/trip/trip.css +16 -0
  119. package/examples/trips/generated/elements.ts +1 -1
  120. package/examples/trips/generated/rows.ts +22 -0
  121. package/examples/trips/generated/rules.ts +9 -1
  122. package/examples/trips/index.html +10 -10
  123. package/examples/trips/map.ts +3 -14
  124. package/examples/trips/new-trip.ts +14 -16
  125. package/examples/trips/trips.css +24 -23
  126. package/examples/weeks/generated/elements.ts +1 -1
  127. package/examples/weeks/generated/queries.ts +11 -0
  128. package/examples/weeks/generated/rows.ts +22 -0
  129. package/examples/weeks/generated/rules.ts +11 -5
  130. package/examples/weeks/routes.ts +3 -2
  131. package/examples/weeks/stories.jsonl +1 -0
  132. package/examples/welcome.css +43 -33
  133. package/package.json +8 -2
  134. package/src/attachment.ts +17 -2
  135. package/src/awesome.ts +103 -0
  136. package/src/board.css +76 -0
  137. package/src/board.ts +173 -0
  138. package/src/cli.ts +28 -3
  139. package/src/compile.ts +821 -109
  140. package/src/definitions.ts +113 -27
  141. package/src/demo.css +2 -5
  142. package/src/draft.ts +48 -27
  143. package/src/drawer.ts +248 -0
  144. package/src/engine.ts +253 -170
  145. package/src/fields.ts +341 -0
  146. package/src/file-value.ts +12 -2
  147. package/src/files.ts +113 -33
  148. package/src/ground.ts +110 -0
  149. package/src/icon-names.ts +19 -2
  150. package/src/keep.ts +16 -3
  151. package/src/kit.ts +51 -0
  152. package/src/link.ts +3 -3
  153. package/src/map.css +140 -0
  154. package/src/map.ts +200 -0
  155. package/src/mcp.ts +129 -24
  156. package/src/members/demo.ts +13 -12
  157. package/src/members/generated/rows.ts +22 -0
  158. package/src/members/generated/rules.ts +3 -2
  159. package/src/members/group.ts +105 -55
  160. package/src/members/keys.ts +95 -79
  161. package/src/members/panel.css +40 -35
  162. package/src/members/panel.ts +58 -37
  163. package/src/migrate.ts +178 -125
  164. package/src/migrations/005-change-kept.ts +7 -0
  165. package/src/month.css +129 -0
  166. package/src/month.ts +179 -0
  167. package/src/ops.ts +40 -1
  168. package/src/page.css +11 -2
  169. package/src/page.ts +68 -17
  170. package/src/parts.css +614 -230
  171. package/src/parts.ts +259 -36
  172. package/src/plane.css +61 -0
  173. package/src/plane.ts +153 -0
  174. package/src/postgres-server.ts +60 -0
  175. package/src/reading.css +73 -0
  176. package/src/reading.ts +238 -0
  177. package/src/rows.css +289 -0
  178. package/src/rows.ts +864 -0
  179. package/src/search.css +80 -0
  180. package/src/search.ts +130 -0
  181. package/src/server.ts +355 -137
  182. package/src/settings.ts +9 -4
  183. package/src/sheet.ts +116 -0
  184. package/src/skill.ts +40 -0
  185. package/src/slots.css +90 -0
  186. package/src/slots.ts +213 -0
  187. package/src/specs.ts +38 -0
  188. package/src/starter.ts +19 -2
  189. package/src/store.ts +224 -161
  190. package/src/stories.ts +43 -11
  191. package/src/surface.ts +164 -0
  192. package/src/time.ts +2 -0
  193. package/src/timeline.css +111 -0
  194. package/src/timeline.ts +235 -0
  195. package/src/toast.ts +21 -48
  196. package/src/together.ts +15 -24
  197. package/src/tokens.css +89 -3
  198. package/src/tokens.json +287 -7
  199. package/src/tool.ts +210 -0
  200. package/src/upkeep.ts +47 -22
  201. package/src/views.css +43 -0
  202. package/src/views.ts +111 -0
  203. package/src/week.css +150 -0
  204. package/src/week.ts +254 -0
  205. package/src/write.ts +326 -78
  206. package/starter/CHANGELOG.md +8 -0
  207. package/starter/CLAUDE.md +9 -3
  208. package/starter/bunfig +5 -0
  209. package/starter/githooks/pre-commit +13 -0
  210. package/starter/prettierignore +5 -0
  211. package/starter/tests/hello.test.ts +2 -0
  212. package/starter/tests/records.test.ts +40 -0
  213. package/starter/todo.jsonl +0 -0
  214. package/docs/learning.md +0 -76
  215. package/examples/cafe/trust.ts +0 -20
  216. package/examples/desk/trust.ts +0 -24
  217. package/examples/people/trust.ts +0 -14
  218. package/examples/trip/answer-rows.ts +0 -70
  219. package/examples/trip/bar.ts +0 -89
  220. package/examples/trip/calendar-map.css +0 -711
  221. package/examples/trip/calendar-map.ts +0 -249
  222. package/examples/trip/drags.ts +0 -143
  223. package/examples/trip/drawer.ts +0 -250
  224. package/examples/trip/event-form.ts +0 -200
  225. package/examples/trip/holding.ts +0 -61
  226. package/examples/trip/map.ts +0 -234
  227. package/examples/trip/month.ts +0 -87
  228. package/examples/trip/other-weeks.ts +0 -67
  229. package/examples/trip/peek.ts +0 -71
  230. package/examples/trip/people-chips.ts +0 -74
  231. package/examples/trip/shell.ts +0 -39
  232. package/examples/trip/trust.ts +0 -51
  233. package/examples/trip/week.ts +0 -237
  234. package/examples/trip/writes.ts +0 -91
  235. package/examples/trip/zones.ts +0 -16
  236. package/examples/weeks/derive.ts +0 -23
  237. package/src/scrim.ts +0 -81
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueshed/joined",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "Compiled documents, talking to web components as elements in the DOM.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -18,6 +18,10 @@
18
18
  "./draft": "./src/draft.ts",
19
19
  "./client": "./src/client.ts",
20
20
  "./parts": "./src/parts.ts",
21
+ "./surface": "./src/surface.ts",
22
+ "./awesome": "./src/awesome.ts",
23
+ "./rows": "./src/rows.ts",
24
+ "./kit": "./src/kit.ts",
21
25
  "./attachment": "./src/attachment.ts",
22
26
  "./follow": "./src/follow.ts",
23
27
  "./icons": "./src/icons.ts",
@@ -25,6 +29,7 @@
25
29
  "./ics": "./src/ics.ts",
26
30
  "./time": "./src/time.ts",
27
31
  "./geo": "./src/geo.ts",
32
+ "./ground": "./src/ground.ts",
28
33
  "./places": "./src/places.ts",
29
34
  "./place-search": "./src/place-search.ts",
30
35
  "./rank": "./src/rank.ts",
@@ -46,16 +51,17 @@
46
51
  "!src/release.ts",
47
52
  "starter",
48
53
  ".claude/skills/joined",
54
+ ".claude/skills/joined-door",
49
55
  "examples",
50
56
  "!examples/film.mp4",
51
57
  "!examples/backups",
52
58
  "docs/introduction.md",
53
59
  "docs/stories.md",
54
60
  "docs/design.md",
55
- "docs/learning.md",
56
61
  "docs/*.svg"
57
62
  ],
58
63
  "dependencies": {
64
+ "@awesome.me/webawesome": "3.15.0",
59
65
  "lucide": "^1.62.0"
60
66
  },
61
67
  "optionalDependencies": {
package/src/attachment.ts CHANGED
@@ -43,6 +43,17 @@ export function attachment(doc: () => string, put: (file: string) => Promise<Ans
43
43
  const choose = Object.assign(document.createElement("label"), { className: "act small" });
44
44
  choose.append(icon("upload"), words, input);
45
45
  const line = Object.assign(document.createElement("p"), { className: "said", role: "status" });
46
+ // the file just chosen, as this browser has it: shown until the server serves it, which it does only once an item
47
+ // names it (a drawer's draft, before Save)
48
+ let chosen: { value: string; url: string } | null = null;
49
+ picture.addEventListener("error", () => {
50
+ if (
51
+ chosen &&
52
+ picture.getAttribute("src") !== chosen.url &&
53
+ shown.getAttribute("href")?.endsWith(chosen.value.slice("file:".length))
54
+ )
55
+ picture.src = chosen.url;
56
+ });
46
57
  const off = iconButton("remove", "Take the file off", () => void said(line, take!()));
47
58
  el.append(shown, choose, off, line);
48
59
  input.addEventListener("change", async () => {
@@ -53,13 +64,17 @@ export function attachment(doc: () => string, put: (file: string) => Promise<Ans
53
64
  const kept = await upload(doc(), file);
54
65
  [input.disabled, choose.ariaBusy, input.value] = [false, null, ""];
55
66
  if ("refused" in kept) line.textContent = `Refused: ${kept.refused}`;
56
- else await said(line, put(kept.file));
67
+ else {
68
+ if (chosen) URL.revokeObjectURL(chosen.url);
69
+ chosen = { value: kept.file, url: URL.createObjectURL(file) };
70
+ await said(line, put(kept.file));
71
+ }
57
72
  });
58
73
  return {
59
74
  el,
60
75
  /** Drawn as the item has it: its value, and whether its person may put a file in it, or take it off. */
61
76
  draw(value: string | undefined, may: { put?: boolean; take?: boolean } = {}) {
62
- const url = value && fileUrl(value);
77
+ const url = value && fileUrl(value, doc());
63
78
  if (url && shown.getAttribute("href") !== url) {
64
79
  // a PDF or a Markdown file, a link to it, named; a photo or an SVG, its picture
65
80
  const linked = url.endsWith(".pdf") ? "PDF" : url.endsWith(".md") ? "Markdown" : undefined;
package/src/awesome.ts ADDED
@@ -0,0 +1,103 @@
1
+ // Web Awesome (MIT, @awesome.me/webawesome), joined's UI library: the surfaces and the simple controls (a drawer, a
2
+ // modal, a toast, a popover, a box, a tick, a choice of a few, tabs), each a component of its own file, imported here
3
+ // once for every page and display that uses one. joined keeps what knows its meanings: the binding (<j-sheet>,
4
+ // <j-field>, <j-search>), the controls of its kinds (a length, a zone, a place, money, people, a typeahead) and the
5
+ // readings. Its look is joined's: src/tokens.css sets the --wa- tokens to joined's own (tokens.json's "wa"), so
6
+ // light and dark follow the device as joined's do. Its icons are lucide's, for both of its libraries: "default"
7
+ // (<wa-icon name="close">, by joined's own names, src/icon-names.ts) and "system" (the chevrons, ×s and ticks inside
8
+ // its components, by Font Awesome's names, each given lucide's outline here); each drawn as a data: URL, so there's
9
+ // nothing to fetch and no route to serve.
10
+
11
+ import "@awesome.me/webawesome/dist/components/callout/callout.js";
12
+ import "@awesome.me/webawesome/dist/components/card/card.js";
13
+ import "@awesome.me/webawesome/dist/components/checkbox/checkbox.js";
14
+ import "@awesome.me/webawesome/dist/components/dialog/dialog.js";
15
+ import "@awesome.me/webawesome/dist/components/drawer/drawer.js";
16
+ import "@awesome.me/webawesome/dist/components/icon/icon.js";
17
+ import "@awesome.me/webawesome/dist/components/input/input.js";
18
+ import "@awesome.me/webawesome/dist/components/number-input/number-input.js";
19
+ import "@awesome.me/webawesome/dist/components/option/option.js";
20
+ import "@awesome.me/webawesome/dist/components/popover/popover.js";
21
+ import "@awesome.me/webawesome/dist/components/select/select.js";
22
+ import "@awesome.me/webawesome/dist/components/switch/switch.js";
23
+ import "@awesome.me/webawesome/dist/components/tab/tab.js";
24
+ import "@awesome.me/webawesome/dist/components/tab-group/tab-group.js";
25
+ import "@awesome.me/webawesome/dist/components/tab-panel/tab-panel.js";
26
+ import "@awesome.me/webawesome/dist/components/textarea/textarea.js";
27
+ import "@awesome.me/webawesome/dist/components/toast/toast.js";
28
+ import "@awesome.me/webawesome/dist/components/tooltip/tooltip.js";
29
+ import { registerIconLibrary } from "@awesome.me/webawesome/dist/components/icon/library.js";
30
+ import {
31
+ Check,
32
+ ChevronDown,
33
+ ChevronLeft,
34
+ ChevronRight,
35
+ CircleHelp,
36
+ CircleX,
37
+ Clock,
38
+ Copy,
39
+ Ellipsis,
40
+ Eye,
41
+ EyeOff,
42
+ GripVertical,
43
+ Image,
44
+ Menu,
45
+ Minus,
46
+ Pause,
47
+ Pipette,
48
+ Play,
49
+ Plus,
50
+ Star,
51
+ User,
52
+ X,
53
+ ZoomIn,
54
+ ZoomOut,
55
+ type IconNode,
56
+ } from "lucide";
57
+ import { ICONS } from "./icon-names.ts";
58
+
59
+ /** The names Web Awesome's components ask the system library for (Font Awesome's), each as lucide draws it:
60
+ * tests/awesome.test.ts holds this to every name its components ask for. */
61
+ export const SYSTEM: Record<string, IconNode> = {
62
+ bars: Menu,
63
+ check: Check,
64
+ "chevron-down": ChevronDown,
65
+ "chevron-left": ChevronLeft,
66
+ "chevron-right": ChevronRight,
67
+ "circle-xmark": CircleX,
68
+ clock: Clock,
69
+ copy: Copy,
70
+ ellipsis: Ellipsis,
71
+ eye: Eye,
72
+ eyedropper: Pipette,
73
+ "eye-slash": EyeOff,
74
+ "grip-vertical": GripVertical,
75
+ image: Image,
76
+ indeterminate: Minus,
77
+ "magnifying-glass-minus": ZoomOut,
78
+ "magnifying-glass-plus": ZoomIn,
79
+ minus: Minus,
80
+ pause: Pause,
81
+ play: Play,
82
+ plus: Plus,
83
+ star: Star,
84
+ user: User,
85
+ xmark: X,
86
+ };
87
+
88
+ /** An outline as an SVG file's words, as lucide draws it: a 2px stroke on a 24 grid, in the words' colour. */
89
+ export const svgOf = (node: IconNode) =>
90
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${node
91
+ .map(
92
+ ([tag, attrs]) =>
93
+ `<${tag} ${Object.entries(attrs)
94
+ .map(([k, v]) => `${k}="${v}"`)
95
+ .join(" ")}/>`,
96
+ )
97
+ .join("")}</svg>`;
98
+ const url = (node: IconNode) => `data:image/svg+xml,${encodeURIComponent(svgOf(node))}`;
99
+
100
+ registerIconLibrary("default", {
101
+ resolver: (name) => url(ICONS[name as keyof typeof ICONS] ?? CircleHelp),
102
+ });
103
+ registerIconLibrary("system", { resolver: (name) => url(SYSTEM[name] ?? CircleHelp) });
package/src/board.css ADDED
@@ -0,0 +1,76 @@
1
+ /* <j-board> (./board.ts), in its shadow: its lanes side by side, each its name and how many, its cards, and Add at
2
+ its foot; a lane a card may go to marked as it's dragged over. On a phone, lanes to swipe between. */
3
+ .lanes {
4
+ display: grid;
5
+ grid-auto-columns: minmax(0, 1fr);
6
+ grid-auto-flow: column;
7
+ gap: var(--space-12);
8
+ padding: var(--space-12) var(--space-16) var(--space-16);
9
+ overflow-x: auto;
10
+ }
11
+ .lane {
12
+ display: flex;
13
+ flex-direction: column;
14
+ gap: var(--space-8);
15
+ min-width: calc(var(--space-64) * 3);
16
+ padding: var(--space-8);
17
+ border-radius: var(--radius);
18
+ background: var(--well);
19
+ }
20
+ .lane[over] {
21
+ outline: var(--size-ring) solid var(--accent);
22
+ outline-offset: calc(-1 * var(--size-ring));
23
+ }
24
+ .lane h3 {
25
+ display: flex;
26
+ align-items: center;
27
+ gap: var(--space-8);
28
+ margin: 0;
29
+ padding: var(--space-4) var(--space-4) 0;
30
+ font: var(--font-label);
31
+ }
32
+ .count {
33
+ color: var(--muted);
34
+ font: var(--font-small);
35
+ font-variant-numeric: tabular-nums;
36
+ }
37
+ .lane ol {
38
+ display: grid;
39
+ gap: var(--space-8);
40
+ margin: 0;
41
+ padding: 0;
42
+ list-style: none;
43
+ }
44
+ .card {
45
+ display: grid;
46
+ gap: var(--space-4);
47
+ width: 100%;
48
+ padding: var(--space-8) var(--space-12);
49
+ background: var(--card);
50
+ font: var(--font-row);
51
+ white-space: normal;
52
+ }
53
+ .card:hover,
54
+ .card[aria-current="true"] {
55
+ background: var(--card-hover);
56
+ }
57
+ .card .at {
58
+ font: var(--font-small);
59
+ }
60
+ .adding {
61
+ align-self: flex-start;
62
+ }
63
+ @media (max-width: 40rem) {
64
+ .lanes {
65
+ grid-auto-columns: 85%;
66
+ scroll-snap-type: x mandatory;
67
+ overscroll-behavior-x: contain;
68
+ }
69
+ .lane {
70
+ scroll-snap-align: start;
71
+ }
72
+ .card,
73
+ .adding {
74
+ min-height: var(--size-finger);
75
+ }
76
+ }
package/src/board.ts ADDED
@@ -0,0 +1,173 @@
1
+ // <j-board for="plans" by="done"> (joined/kit): a collection in lanes by a field, a board. A lane for each value the
2
+ // field has (yes and no; a step each, of a field the stories move; each item a link may be to, and none; or those
3
+ // `lanes` names, in its order: "idea,booked,done"), each item a card in its lane, the way into it. A card dragged to another lane moves it there, where its
4
+ // `may` lets it (a field the stories move step by step, only to the steps it offers); let go where it may not go, it
5
+ // goes back. Each lane's foot adds one in it, where this person may add (the sheet offered that lane's value, still
6
+ // asked). On a phone the lanes are side by side to swipe between, each nearly the screen's width.
7
+
8
+ import { icon } from "./icons.ts";
9
+ import { keep, type Row } from "./keep.ts";
10
+ import { el, Reading } from "./reading.ts";
11
+ import type { Item } from "./rows.ts";
12
+ import { dated, dayOf } from "./time.ts";
13
+ import STYLE from "./board.css" with { type: "text" };
14
+
15
+ const SHEET = new CSSStyleSheet();
16
+ SHEET.replaceSync(STYLE);
17
+ type Lane = { value: unknown; words: string; its: Item[] };
18
+ type Drawn = {
19
+ el: HTMLElement;
20
+ count: HTMLElement;
21
+ list: HTMLElement;
22
+ add: HTMLButtonElement;
23
+ kept: Map<string, { shows: string; el: HTMLElement }>;
24
+ };
25
+
26
+ export class JBoard extends Reading {
27
+ static override sheets = [SHEET];
28
+ #row = el("div", { className: "lanes" });
29
+ #lanes = new Map<string, Drawn>();
30
+
31
+ get #by() {
32
+ return this.field("by");
33
+ }
34
+ protected made() {
35
+ this.root.append(this.#row);
36
+ }
37
+ /** Its lanes, each a value of its field, in order; and what isn't any of them, last. */
38
+ #values(): Lane[] {
39
+ const f = this.#by!,
40
+ words = (v: string) => (v[0]!.toUpperCase() + v.slice(1)).replaceAll("-", " "),
41
+ named = this.getAttribute("lanes");
42
+ if (named)
43
+ return named
44
+ .split(",")
45
+ .map((v) => v.trim())
46
+ .filter(Boolean)
47
+ .map((v) => ({ value: v, words: words(v), its: [] }));
48
+ // a field the stories move: a lane each step, in their order
49
+ if (f.how === "moves" && f.steps?.length) return f.steps.map((v) => ({ value: v, words: words(v), its: [] }));
50
+ if (f.type === "boolean") {
51
+ const label = this.label(f.name);
52
+ return [
53
+ { value: false, words: `Not ${label.toLowerCase()}`, its: [] },
54
+ { value: true, words: label, its: [] },
55
+ ];
56
+ }
57
+ if (f.to)
58
+ return [
59
+ ...[...document.querySelectorAll(f.to.tag)].map((t) => ({
60
+ value: Number(t.getAttribute("key")),
61
+ words: t.getAttribute(f.to!.title ?? "name") ?? `#${t.getAttribute("key")}`,
62
+ its: [],
63
+ })),
64
+ ...(f.needed ? [] : [{ value: undefined, words: `No ${this.label(f.name).toLowerCase()}`, its: [] }]),
65
+ ];
66
+ const seen = [
67
+ ...new Set(
68
+ this.items()
69
+ .map((it) => it.data[f.name])
70
+ .filter((v) => v !== undefined && v !== null && v !== ""),
71
+ ),
72
+ ];
73
+ return seen.map((v) => ({ value: v, words: words(String(v)), its: [] }));
74
+ }
75
+ protected draw() {
76
+ const f = this.#by;
77
+ if (!f) return;
78
+ const lanes = this.#values(),
79
+ key = (v: unknown) => JSON.stringify(v ?? null),
80
+ of = (it: Item) => (f.type === "boolean" ? it.data[f.name] === true : it.data[f.name]);
81
+ for (const it of this.items()) (lanes.find((l) => key(l.value) === key(of(it))) ?? lanes.at(-1))?.its.push(it);
82
+ const wanted = new Set(lanes.map((l) => key(l.value)));
83
+ for (const [k, d] of this.#lanes) if (!wanted.has(k)) (d.el.remove(), this.#lanes.delete(k));
84
+ const when = this.spec!.fields.find((f) => f.type === "date-time"),
85
+ adds = this.adds;
86
+ lanes.forEach((lane, i) => {
87
+ const k = key(lane.value);
88
+ let d = this.#lanes.get(k);
89
+ if (!d) {
90
+ const count = el("span", { className: "count", part: "count" }),
91
+ list = el("ol"),
92
+ add = el("button", { type: "button", className: "act small adding", part: "add" }, icon("add"), "Add");
93
+ add.addEventListener("click", () => this.add(lane.value === undefined ? {} : { [f.name]: lane.value }));
94
+ const section = el(
95
+ "section",
96
+ { className: "lane", part: "lane", ariaLabel: lane.words },
97
+ el("h3", {}, lane.words, count),
98
+ list,
99
+ add,
100
+ );
101
+ section.dataset.lane = k;
102
+ d = { el: section, count, list, add, kept: new Map() };
103
+ this.#lanes.set(k, d);
104
+ }
105
+ if (this.#row.children[i] !== d.el) this.#row.insertBefore(d.el, this.#row.children[i] ?? null);
106
+ d.count.textContent = String(lane.its.length);
107
+ d.add.hidden = !adds;
108
+ d.add.ariaLabel = `Add to ${lane.words}`;
109
+ keep(
110
+ d.list,
111
+ d.kept,
112
+ lane.its.map((it): Row => ({
113
+ key: String(it.key),
114
+ shows: JSON.stringify([this.named(it), when && it.data[when.name], this.opened(it), it.getAttribute("may")]),
115
+ make: () => el("li", {}, this.#card(it, f.name, when?.name, lanes)),
116
+ })),
117
+ );
118
+ });
119
+ }
120
+ /** Whether an item may go to a lane: a field the stories move, only to a step it offers; another, where it may. */
121
+ #goes(it: Item, field: string, value: unknown) {
122
+ // into none: a field emptied, which a drag doesn't do
123
+ if (value === undefined) return false;
124
+ const may = (it.getAttribute("may") ?? "").split(" ");
125
+ return this.#by!.how === "moves"
126
+ ? may.includes(`replace:${field}>${encodeURIComponent(String(value))}`)
127
+ : may.includes(`replace:${field}`);
128
+ }
129
+ /** A card: its words and when it is; dragged to another lane, moved there where it may go. */
130
+ #card(it: Item, field: string, when: string | undefined, lanes: Lane[]) {
131
+ const w = when ? it.data[when] : undefined,
132
+ card = el(
133
+ "button",
134
+ { type: "button", className: "item card", part: "item" },
135
+ el("span", { className: "what" }, this.named(it)),
136
+ ...(typeof w === "string"
137
+ ? [
138
+ el(
139
+ "span",
140
+ { className: "at" },
141
+ `${dated(dayOf(w), { weekday: "short", day: "numeric", month: "short" })}, ${w.slice(11, 16)}`,
142
+ ),
143
+ ]
144
+ : []),
145
+ );
146
+ const laneAt = (e: PointerEvent) =>
147
+ [...this.#lanes.values()].find((d) => {
148
+ const r = d.el.getBoundingClientRect();
149
+ return e.clientX >= r.left && e.clientX < r.right && e.clientY >= r.top && e.clientY < r.bottom;
150
+ });
151
+ const valueOf = (d: Drawn) => lanes.find((l) => JSON.stringify(l.value ?? null) === d.el.dataset.lane)?.value;
152
+ const moves = lanes.some((l) => this.#goes(it, field, l.value));
153
+ this.press(
154
+ card,
155
+ it,
156
+ moves
157
+ ? (dx, dy, done, e) => {
158
+ card.style.translate = done ? "" : `${dx}px ${dy}px`;
159
+ const over = e ? laneAt(e) : undefined;
160
+ for (const d of this.#lanes.values())
161
+ d.el.toggleAttribute(
162
+ "over",
163
+ !done && d === over && this.#goes(it, field, valueOf(d)) && !d.list.contains(card),
164
+ );
165
+ if (!done || !over || over.list.contains(card)) return;
166
+ const to = valueOf(over);
167
+ if (this.#goes(it, field, to)) void this.change(it, { [field]: to });
168
+ }
169
+ : undefined,
170
+ );
171
+ return card;
172
+ }
173
+ }
package/src/cli.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  // joined init an app's folder begun: hello, the skill, a CLAUDE.md, the scripts (./starter.ts)
5
5
  // joined upgrade [version] joined at another version (the newest, if none is said), the skill refreshed
6
6
  // joined compile [dir] each app's generated/ and its next migration, from its stories
7
- // joined start [dir] the apps served, on PORT or 3380
7
+ // joined start [dir] the apps served, on PORT or 3380, until it's stopped (SIGTERM, Ctrl-C): its store closed
8
8
  // joined link <name> a member's link, printed
9
9
  // joined page show <doc> a document as a member sees it, by their link (JOINED_LINK, never printed)
10
10
  // joined page watch <doc> each change to it, a line each, as it comes
@@ -25,12 +25,24 @@ export async function run([command, arg, ...rest]: string[], dir = arg ? resolve
25
25
  if (command === "init") return init(process.cwd());
26
26
  if (command === "upgrade") return upgrade(arg, process.cwd());
27
27
  if (command === "compile") return [await writeAll(dir)];
28
- if (command === "start") return startUp(await start({ dir }));
28
+ if (command === "start") {
29
+ const server = await start({ dir }),
30
+ stop = stopping(server);
31
+ // stopped by its host (a deploy's SIGTERM, a Ctrl-C): the server stopped and its store closed, then gone
32
+ for (const signal of ["SIGTERM", "SIGINT"] as const) process.once(signal, stop);
33
+ return await startUp(server);
34
+ }
29
35
  if (command === "link") return [await linkFor(arg, {})];
30
36
  if (command === "page") return paged(arg, rest);
31
37
  throw new Error(USAGE);
32
38
  }
33
39
 
40
+ /** How joined goes when it's told to: its server stopped, which closes its store (a SQLite file whole, its -wal folded
41
+ * in), then the process gone, as asked. */
42
+ export const stopping =
43
+ (server: { stop(closeActive?: boolean): Promise<unknown> }, exit: (code: number) => unknown = process.exit) =>
44
+ async () => (await server.stop(true), exit(0));
45
+
34
46
  /** A member's page, from a terminal: by their link in JOINED_LINK, a document shown, watched, or written. */
35
47
  async function paged(what: string | undefined, [doc, ops, why]: string[]) {
36
48
  const link = Bun.env.JOINED_LINK;
@@ -49,4 +61,17 @@ async function paged(what: string | undefined, [doc, ops, why]: string[]) {
49
61
  return [];
50
62
  }
51
63
 
52
- if (import.meta.main) for (const line of await run(Bun.argv.slice(2))) console.log(line);
64
+ /** A command run and said, and how it ended: what it refuses (the stories' mistake, a name it doesn't know) in its
65
+ * words alone, as whoever reads it (a person, an agent) is to act on them; a mistake of joined's own keeps its trace. */
66
+ export async function main(argv: string[], say = console.log, refuse = console.error) {
67
+ try {
68
+ for (const line of await run(argv)) say(line);
69
+ return 0;
70
+ } catch (e) {
71
+ if (!(e instanceof Error) || e.constructor !== Error) throw e;
72
+ refuse(e.message);
73
+ return 1;
74
+ }
75
+ }
76
+
77
+ if (import.meta.main) process.exitCode = await main(Bun.argv.slice(2));