@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.
- package/.claude/skills/joined/SKILL.md +9 -1
- package/.claude/skills/joined/reference.md +267 -53
- package/.claude/skills/joined-door/SKILL.md +57 -0
- package/README.md +19 -50
- package/docs/design.md +76 -10
- package/docs/introduction.md +18 -18
- package/docs/light-and-shadow.svg +1 -1
- package/examples/README.md +20 -0
- package/examples/account/account.json +1 -0
- package/examples/account/derive.ts +41 -0
- package/examples/account/generated/elements.ts +52 -0
- package/examples/account/generated/rows.ts +22 -0
- package/examples/account/generated/rules.ts +32 -0
- package/examples/account/routes.ts +5 -0
- package/examples/app.css +2 -1
- package/examples/cafe/books.html +2 -2
- package/examples/cafe/cafe.css +9 -16
- package/examples/cafe/generated/books.rows.ts +22 -0
- package/examples/cafe/generated/books.rules.ts +3 -2
- package/examples/cafe/generated/kitchen.rows.ts +27 -0
- package/examples/cafe/generated/kitchen.rules.ts +11 -1
- package/examples/cafe/generated/menu.rows.ts +22 -0
- package/examples/cafe/generated/menu.rules.ts +3 -2
- package/examples/cafe/generated/order.rows.ts +27 -0
- package/examples/cafe/generated/order.rules.ts +11 -1
- package/examples/cafe/generated/staff.rows.ts +22 -0
- package/examples/cafe/generated/staff.rules.ts +6 -1
- package/examples/cafe/generated/supplies.queries.ts +4 -2
- package/examples/cafe/generated/supplies.rows.ts +22 -0
- package/examples/cafe/generated/supplies.rules.ts +12 -1
- package/examples/cafe/generated/till.queries.ts +2 -0
- package/examples/cafe/generated/till.rows.ts +27 -0
- package/examples/cafe/generated/till.rules.ts +11 -1
- package/examples/cafe/index.html +14 -15
- package/examples/cafe/kitchen.ts +1 -1
- package/examples/cafe/look.ts +30 -0
- package/examples/cafe/menu.html +10 -26
- package/examples/cafe/menu.ts +8 -80
- package/examples/cafe/order.html +6 -6
- package/examples/cafe/order.ts +5 -1
- package/examples/cafe/routes.ts +0 -1
- package/examples/cafe/stories.jsonl +3 -1
- package/examples/cafe/supplies.html +34 -34
- package/examples/cafe/supplies.ts +14 -11
- package/examples/cafe/till.ts +5 -1
- package/examples/chart/arches.ts +148 -0
- package/examples/chart/chart.css +6 -0
- package/examples/chart/chart.json +87 -0
- package/examples/chart/generated/elements.ts +105 -0
- package/examples/chart/generated/queries.ts +36 -0
- package/examples/chart/generated/rows.ts +27 -0
- package/examples/chart/generated/rules.ts +111 -0
- package/examples/chart/grid.ts +118 -0
- package/examples/chart/index.html +78 -0
- package/examples/chart/migrations/001-chart.ts +6 -0
- package/examples/chart/migrations/002-create-conditions.ts +6 -0
- package/examples/chart/page.ts +20 -0
- package/examples/chart/routes.ts +7 -0
- package/examples/chart/stories.jsonl +14 -0
- package/examples/chart/teeth.ts +57 -0
- package/examples/desk/generated/rows.ts +22 -0
- package/examples/desk/generated/rules.ts +34 -1
- package/examples/desk/index.html +9 -2
- package/examples/desk/routes.ts +0 -2
- package/examples/desk/stories.jsonl +3 -2
- package/examples/desk/thumbs.ts +2 -2
- package/examples/hello/generated/elements.ts +2 -2
- package/examples/hello/generated/rules.ts +3 -2
- package/examples/hello/hello.css +2 -4
- package/examples/hello/index.html +10 -3
- package/examples/hello/page.ts +4 -4
- package/examples/index.html +4 -5
- package/examples/notes/generated/elements.ts +112 -0
- package/examples/notes/generated/queries.ts +36 -0
- package/examples/notes/generated/rows.ts +27 -0
- package/examples/notes/generated/rules.ts +133 -0
- package/examples/notes/index.html +32 -0
- package/examples/notes/look.ts +41 -0
- package/examples/notes/migrations/001-notes.ts +7 -0
- package/examples/notes/notes.json +78 -0
- package/examples/notes/page.ts +21 -0
- package/examples/notes/routes.ts +6 -0
- package/examples/notes/stories.jsonl +21 -0
- package/examples/people/generated/rows.ts +22 -0
- package/examples/people/generated/rules.ts +11 -1
- package/examples/people/links.ts +2 -1
- package/examples/people/routes.ts +1 -3
- package/examples/people/stories.jsonl +1 -0
- package/examples/people/view.ts +5 -2
- package/examples/trip/generated/elements.ts +4 -2
- package/examples/trip/generated/queries.ts +12 -1
- package/examples/trip/generated/rows.ts +27 -0
- package/examples/trip/generated/rules.ts +56 -2
- package/examples/trip/index.html +58 -12
- package/examples/trip/line.css +186 -0
- package/examples/trip/line.ts +51 -40
- package/examples/trip/page.ts +65 -71
- package/examples/trip/routes.ts +9 -5
- package/examples/trip/stays.css +12 -12
- package/examples/trip/stays.ts +15 -10
- package/examples/trip/stories.jsonl +2 -0
- package/examples/trip/told.ts +3 -26
- package/examples/trip/trip.css +16 -0
- package/examples/trips/generated/rows.ts +22 -0
- package/examples/trips/generated/rules.ts +9 -1
- package/examples/trips/index.html +10 -10
- package/examples/trips/map.ts +3 -14
- package/examples/trips/new-trip.ts +14 -16
- package/examples/weeks/generated/elements.ts +1 -1
- package/examples/weeks/generated/queries.ts +11 -0
- package/examples/weeks/generated/rows.ts +22 -0
- package/examples/weeks/generated/rules.ts +11 -5
- package/examples/weeks/routes.ts +3 -2
- package/examples/weeks/stories.jsonl +1 -0
- package/examples/welcome.css +7 -5
- package/package.json +8 -2
- package/src/awesome.ts +103 -0
- package/src/board.css +75 -0
- package/src/board.ts +173 -0
- package/src/cli.ts +15 -2
- package/src/compile.ts +569 -35
- package/src/definitions.ts +53 -15
- package/src/draft.ts +38 -23
- package/src/drawer.ts +222 -0
- package/src/engine.ts +240 -166
- package/src/fields.ts +268 -0
- package/src/files.ts +6 -4
- package/src/ground.ts +110 -0
- package/src/icon-names.ts +15 -2
- package/src/kit.ts +51 -0
- package/src/link.ts +3 -3
- package/src/map.css +133 -0
- package/src/map.ts +200 -0
- package/src/mcp.ts +106 -22
- package/src/members/demo.ts +13 -12
- package/src/members/generated/rows.ts +22 -0
- package/src/members/generated/rules.ts +3 -2
- package/src/members/group.ts +65 -39
- package/src/members/keys.ts +93 -77
- package/src/members/panel.css +23 -17
- package/src/members/panel.ts +49 -35
- package/src/migrate.ts +120 -104
- package/src/month.css +125 -0
- package/src/month.ts +179 -0
- package/src/page.css +8 -0
- package/src/page.ts +7 -4
- package/src/parts.css +462 -170
- package/src/parts.ts +209 -26
- package/src/plane.css +56 -0
- package/src/plane.ts +151 -0
- package/src/postgres-server.ts +60 -0
- package/src/reading.css +77 -0
- package/src/reading.ts +238 -0
- package/src/rows.css +308 -0
- package/src/rows.ts +780 -0
- package/src/search.css +80 -0
- package/src/search.ts +130 -0
- package/src/server.ts +205 -114
- package/src/settings.ts +9 -4
- package/src/sheet.ts +114 -0
- package/src/skill.ts +40 -0
- package/src/slots.css +94 -0
- package/src/slots.ts +213 -0
- package/src/specs.ts +38 -0
- package/src/starter.ts +5 -2
- package/src/store.ts +184 -143
- package/src/stories.ts +43 -11
- package/src/surface.ts +159 -0
- package/src/timeline.css +111 -0
- package/src/timeline.ts +226 -0
- package/src/toast.ts +21 -48
- package/src/together.ts +0 -7
- package/src/tokens.css +78 -1
- package/src/tokens.json +249 -0
- package/src/tool.ts +211 -0
- package/src/upkeep.ts +18 -20
- package/src/views.css +44 -0
- package/src/views.ts +94 -0
- package/src/week.css +151 -0
- package/src/week.ts +250 -0
- package/src/write.ts +202 -69
- package/starter/CLAUDE.md +3 -3
- package/starter/bunfig +4 -0
- package/starter/prettierignore +4 -0
- package/starter/tests/hello.test.ts +2 -0
- package/docs/learning.md +0 -76
- package/examples/cafe/trust.ts +0 -20
- package/examples/desk/trust.ts +0 -24
- package/examples/people/trust.ts +0 -14
- package/examples/trip/answer-rows.ts +0 -70
- package/examples/trip/bar.ts +0 -89
- package/examples/trip/calendar-map.css +0 -711
- package/examples/trip/calendar-map.ts +0 -249
- package/examples/trip/drags.ts +0 -143
- package/examples/trip/drawer.ts +0 -250
- package/examples/trip/event-form.ts +0 -200
- package/examples/trip/holding.ts +0 -61
- package/examples/trip/map.ts +0 -234
- package/examples/trip/month.ts +0 -87
- package/examples/trip/other-weeks.ts +0 -67
- package/examples/trip/peek.ts +0 -71
- package/examples/trip/people-chips.ts +0 -74
- package/examples/trip/shell.ts +0 -39
- package/examples/trip/trust.ts +0 -51
- package/examples/trip/week.ts +0 -237
- package/examples/trip/writes.ts +0 -91
- package/examples/trip/zones.ts +0 -16
- package/examples/weeks/derive.ts +0 -23
- package/src/scrim.ts +0 -81
package/src/parts.ts
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
// joined's parts (src/parts.css), one sheet, a layer (joined) beneath anything of an app's own, so any rule of an
|
|
2
2
|
// app's wins, whatever its specificity: the page adopts it as this is first imported, and a display adopts it in its
|
|
3
3
|
// shadow by adopt(), before its own. A display or the group imports this; a page holding the group needn't, unless
|
|
4
|
-
// it wants a part's behaviour (the page's line said, a modal that asks first
|
|
5
|
-
//
|
|
6
|
-
//
|
|
4
|
+
// it wants a part's behaviour (the page's line said, a modal that asks first), and a page without one (anonymous:
|
|
5
|
+
// hello) imports it for the look. It brings Web Awesome's components (./awesome.ts): the drawer on a phone, the modal,
|
|
6
|
+
// the peek, the tabs, the fields and the ticks are theirs.
|
|
7
7
|
|
|
8
8
|
import STYLE from "./parts.css" with { type: "text" };
|
|
9
|
+
import { geo, world } from "./geo.ts";
|
|
10
|
+
import { tiles } from "./ground.ts";
|
|
9
11
|
import { hueOf } from "./hues.ts";
|
|
12
|
+
import { icon, iconButton } from "./icons.ts";
|
|
13
|
+
import "./awesome.ts";
|
|
10
14
|
import { keep } from "./keep.ts";
|
|
11
15
|
import type { Answer } from "./page.ts";
|
|
12
|
-
|
|
16
|
+
|
|
17
|
+
/** A phone, as joined's stylesheets have it. */
|
|
18
|
+
export const phone = matchMedia("(max-width: 40rem)");
|
|
19
|
+
|
|
20
|
+
/** Whether a drawer is docked at the screen's side: the page keeps clear of it (src/page.css, wider than a phone),
|
|
21
|
+
* said only as it changes. */
|
|
22
|
+
export function docked(is: boolean) {
|
|
23
|
+
if (document.body.hasAttribute("data-docked") !== is) document.body.toggleAttribute("data-docked", is);
|
|
24
|
+
}
|
|
13
25
|
|
|
14
26
|
export const PARTS = new CSSStyleSheet();
|
|
15
27
|
PARTS.replaceSync(STYLE);
|
|
16
|
-
|
|
17
|
-
const WATCHED = new CSSStyleSheet();
|
|
18
|
-
WATCHED.replaceSync(`@layer joined { :is(dialog, .sheet)::backdrop { background: transparent; } }`);
|
|
19
|
-
document.adoptedStyleSheets = [...document.adoptedStyleSheets, PARTS, WATCHED];
|
|
28
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, PARTS];
|
|
20
29
|
|
|
21
|
-
/** A display's shadow given joined's parts, then its own sheets (which win, joined's being a layer beneath)
|
|
22
|
-
* modals, sheets and drawers dimming the page by its one scrim as the page's do. */
|
|
30
|
+
/** A display's shadow given joined's parts, then its own sheets (which win, joined's being a layer beneath). */
|
|
23
31
|
export function adopt(root: ShadowRoot, ...sheets: CSSStyleSheet[]) {
|
|
24
|
-
root.adoptedStyleSheets = [PARTS,
|
|
25
|
-
watch(root);
|
|
32
|
+
root.adoptedStyleSheets = [PARTS, ...sheets];
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
/** A person's face (Identity): their initial in their hue, their name its title; or, where there's no room (an
|
|
@@ -44,35 +51,211 @@ export function chip(key: number, name: string, words = name) {
|
|
|
44
51
|
return c;
|
|
45
52
|
}
|
|
46
53
|
|
|
54
|
+
/** A row (Row, design.md "A row"): the button that opens it, to put in what holds the row (an item's element),
|
|
55
|
+
* after any tick. All of it is the one target: `open` is what a tap does. `say(words, more)` sets its words and, under
|
|
56
|
+
* them, what more is said, only where they've changed; `mark(is)` says its drawer is open, or isn't; `el.disabled`
|
|
57
|
+
* where this person may not open it, and it's its words alone. */
|
|
58
|
+
export function row(open: () => void) {
|
|
59
|
+
const el = Object.assign(document.createElement("button"), { type: "button", className: "j-open" }),
|
|
60
|
+
words = Object.assign(document.createElement("span"), { className: "j-words" }),
|
|
61
|
+
text = document.createElement("b"),
|
|
62
|
+
under = document.createElement("span");
|
|
63
|
+
words.append(text, under);
|
|
64
|
+
el.append(words, icon("on"));
|
|
65
|
+
el.addEventListener("click", open);
|
|
66
|
+
return {
|
|
67
|
+
el,
|
|
68
|
+
say(said: string, more = "") {
|
|
69
|
+
if (text.textContent !== said) text.textContent = said;
|
|
70
|
+
if (under.textContent !== more) under.textContent = more;
|
|
71
|
+
},
|
|
72
|
+
mark(is: boolean) {
|
|
73
|
+
el.ariaCurrent = is ? "true" : null;
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A tick on a row (Row): a button that does something else than the row does, kept at once. `set(on, what)` says
|
|
79
|
+
* whether it's ticked, and what of ("Buy rice: done"). */
|
|
80
|
+
export function tick(act: () => void) {
|
|
81
|
+
const el = Object.assign(document.createElement("wa-checkbox"), { className: "j-tick" }) as HTMLElement & {
|
|
82
|
+
checked: boolean;
|
|
83
|
+
disabled: boolean;
|
|
84
|
+
};
|
|
85
|
+
const words = document.createElement("span");
|
|
86
|
+
el.append(words);
|
|
87
|
+
// what's ticked is the document's word: put back as it's pressed, and changed as the write lands
|
|
88
|
+
el.addEventListener("change", () => ((el.checked = !el.checked), act()));
|
|
89
|
+
return {
|
|
90
|
+
el,
|
|
91
|
+
set(on: boolean, what: string) {
|
|
92
|
+
el.checked = on;
|
|
93
|
+
if (words.textContent !== what) ((words.textContent = what), (el.title = what));
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** A place as a small map (design.md, "A peek"): OpenStreetMap's tiles round it, its pin at the middle. Drawn once
|
|
99
|
+
* it's on the page and has a width; nothing, where it's no place. */
|
|
100
|
+
export function place(at: string, zoom = 15) {
|
|
101
|
+
const el = Object.assign(document.createElement("div"), { className: "j-place", role: "img" }),
|
|
102
|
+
here = geo(at);
|
|
103
|
+
el.ariaLabel = "A map of it";
|
|
104
|
+
if (!here) return el;
|
|
105
|
+
const { x, y } = world(here.lat, here.lng, zoom);
|
|
106
|
+
new ResizeObserver(() => {
|
|
107
|
+
const [w, h] = [el.clientWidth, el.clientHeight];
|
|
108
|
+
if (!w || el.dataset.drawn === `${w}x${h}`) return;
|
|
109
|
+
el.dataset.drawn = `${w}x${h}`;
|
|
110
|
+
// the point at the middle
|
|
111
|
+
el.replaceChildren(...tiles(zoom, x - w / 2, y - h / 2, w, h), document.createElement("i"));
|
|
112
|
+
}).observe(el);
|
|
113
|
+
return el;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A mention (design.md, "A peek"): a thing named where it isn't its own place, a small tool that peeks at it.
|
|
117
|
+
* `say(words)` sets what it says, only where it's changed. */
|
|
118
|
+
export function mention(act: (by: HTMLElement) => void) {
|
|
119
|
+
const el = Object.assign(document.createElement("button"), { type: "button", className: "j-mention" });
|
|
120
|
+
el.addEventListener("click", () => act(el));
|
|
121
|
+
return {
|
|
122
|
+
el,
|
|
123
|
+
say(words: string) {
|
|
124
|
+
if (el.textContent !== words) el.textContent = words;
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A peek (Peek, design.md "A peek"): a little more of a thing, by what was tapped, read and never typed in, with
|
|
130
|
+
* the way to open it whole (`open`, its foot's one button, said by `deed`). Web Awesome's wa-popover, one for a page,
|
|
131
|
+
* put in it once: `show(by, name)` places it by `by` (under it, or wherever there's room) with the thing's name at its
|
|
132
|
+
* head, its `body` the caller's to fill first; `hide()` takes it away, as its ×, Escape and a tap elsewhere do. While
|
|
133
|
+
* it's open, what it's by says so (aria-expanded). */
|
|
134
|
+
export function peek(open: () => void, deed = "Open") {
|
|
135
|
+
const el = Object.assign(document.createElement("wa-popover"), {
|
|
136
|
+
className: "j-peek",
|
|
137
|
+
placement: "bottom-start",
|
|
138
|
+
}) as HTMLElement & {
|
|
139
|
+
open: boolean;
|
|
140
|
+
anchor: Element | null;
|
|
141
|
+
hasUpdated: boolean;
|
|
142
|
+
updateComplete: Promise<unknown>;
|
|
143
|
+
},
|
|
144
|
+
head = document.createElement("header"),
|
|
145
|
+
name = document.createElement("b"),
|
|
146
|
+
body = Object.assign(document.createElement("div"), { className: "j-peek-body" }),
|
|
147
|
+
foot = document.createElement("footer"),
|
|
148
|
+
whole = Object.assign(document.createElement("button"), { type: "button", className: "act", textContent: deed });
|
|
149
|
+
let by: HTMLElement | null = null;
|
|
150
|
+
const hide = () => (el.open = false);
|
|
151
|
+
head.append(name, iconButton("close", "Close", hide));
|
|
152
|
+
whole.prepend(icon("on"));
|
|
153
|
+
whole.addEventListener("click", () => (hide(), open()));
|
|
154
|
+
foot.append(whole);
|
|
155
|
+
el.append(head, body, foot);
|
|
156
|
+
el.addEventListener("wa-after-hide", (e) => {
|
|
157
|
+
if (e.target !== el || el.open) return;
|
|
158
|
+
by?.removeAttribute("aria-expanded");
|
|
159
|
+
by = null;
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
el,
|
|
163
|
+
body,
|
|
164
|
+
hide,
|
|
165
|
+
/** Its button's words, for what this pop opens whole; none, and it has no button (there's no whole to open). */
|
|
166
|
+
deed(words: string | null) {
|
|
167
|
+
foot.hidden = words === null;
|
|
168
|
+
if (words !== null) whole.lastChild!.textContent = words;
|
|
169
|
+
},
|
|
170
|
+
show(at: HTMLElement, said: string) {
|
|
171
|
+
by?.removeAttribute("aria-expanded");
|
|
172
|
+
name.textContent = said;
|
|
173
|
+
el.ariaLabel = said;
|
|
174
|
+
// anchored once it's first drawn: Web Awesome's popover clears its anchor as it first draws (it has no `for`)
|
|
175
|
+
const go = () => ((el.anchor = at), (el.open = true));
|
|
176
|
+
if (el.hasUpdated) go();
|
|
177
|
+
else void el.updateComplete.then(go);
|
|
178
|
+
(by = at).setAttribute("aria-expanded", "true");
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
47
183
|
/** A line for a request's refusal (Said): emptied as it's sent, its why if it's refused. It returns the
|
|
48
184
|
* refusal, if there was one; done is nothing to say, what it did showing as its change. */
|
|
49
185
|
export async function said(line: Element, request: Promise<Answer>) {
|
|
186
|
+
const callout = line.localName === "wa-callout";
|
|
50
187
|
line.textContent = "";
|
|
188
|
+
if (callout) (line as HTMLElement).hidden = true;
|
|
51
189
|
const why = await request;
|
|
52
190
|
if (why) line.textContent = `Refused: ${why}`;
|
|
191
|
+
if (callout) (((line as HTMLElement).hidden = !why), line.setAttribute("variant", "danger"));
|
|
53
192
|
return why;
|
|
54
193
|
}
|
|
55
194
|
|
|
56
|
-
/** A
|
|
57
|
-
*
|
|
58
|
-
export function
|
|
195
|
+
/** A surface of Web Awesome's (a wa-drawer, a wa-dialog), given its props: on a phone, a drawer rises from the foot
|
|
196
|
+
* (design.md, "Three surfaces"), and from the right wider; light-dismissed, as a tap on the dimmed page closes it. */
|
|
197
|
+
export function surface<K extends "wa-drawer" | "wa-dialog">(tag: K, props: object = {}) {
|
|
198
|
+
const el = Object.assign(document.createElement(tag), props) as HTMLElement & { open: boolean; placement?: string };
|
|
199
|
+
el.setAttribute("light-dismiss", "");
|
|
200
|
+
return tag === "wa-drawer" ? placed(el) : el;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** A drawer placed as the screen is: from the foot on a phone, from the right wider. */
|
|
204
|
+
export function placed<T extends HTMLElement>(drawer: T) {
|
|
205
|
+
const place = () => drawer.setAttribute("placement", phone.matches ? "bottom" : "end");
|
|
206
|
+
phone.addEventListener("change", place);
|
|
207
|
+
place();
|
|
208
|
+
return drawer;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** What follows a removal, said under its question (Apple's alerts: a title that asks, a line that says what happens). */
|
|
212
|
+
export const GONE = "It goes for everyone at once, and can't be put back.";
|
|
213
|
+
|
|
214
|
+
/** A modal that asks first (Modal), a wa-dialog: its question its label, a line saying what follows, then Never mind
|
|
215
|
+
* (keep) or the deed (sure), made in it where it has none. What it returns asks it: the question, what the deed does,
|
|
216
|
+
* and what follows (`follows`, unless said). */
|
|
217
|
+
export function askFirst(dialog: HTMLElement & { open: boolean }, words = "Remove", follows = GONE) {
|
|
59
218
|
let deed = () => {};
|
|
60
|
-
dialog.
|
|
61
|
-
dialog.querySelector("[name=sure]")
|
|
62
|
-
|
|
219
|
+
dialog.classList.add("j-ask");
|
|
220
|
+
if (!dialog.querySelector("[name=sure]")) {
|
|
221
|
+
const foot = Object.assign(document.createElement("footer"), { slot: "footer" });
|
|
222
|
+
foot.append(
|
|
223
|
+
Object.assign(document.createElement("button"), {
|
|
224
|
+
type: "button",
|
|
225
|
+
className: "act",
|
|
226
|
+
name: "keep",
|
|
227
|
+
textContent: "Never mind",
|
|
228
|
+
}),
|
|
229
|
+
Object.assign(document.createElement("button"), {
|
|
230
|
+
type: "button",
|
|
231
|
+
className: "act danger",
|
|
232
|
+
name: "sure",
|
|
233
|
+
textContent: words,
|
|
234
|
+
}),
|
|
235
|
+
);
|
|
236
|
+
dialog.append(Object.assign(document.createElement("h2"), { slot: "label" }), foot);
|
|
237
|
+
}
|
|
238
|
+
const line = dialog.querySelector(":scope > p") ?? dialog.appendChild(document.createElement("p"));
|
|
239
|
+
dialog.querySelector("[name=keep]")!.addEventListener("click", () => (dialog.open = false));
|
|
240
|
+
dialog.querySelector("[name=sure]")!.addEventListener("click", () => ((dialog.open = false), deed()));
|
|
241
|
+
return (question: string, then: () => void, said = follows) => {
|
|
63
242
|
dialog.querySelector("h2")!.textContent = question;
|
|
243
|
+
line.textContent = said;
|
|
64
244
|
deed = then;
|
|
65
|
-
dialog.
|
|
245
|
+
dialog.open = true;
|
|
66
246
|
};
|
|
67
247
|
}
|
|
68
248
|
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
);
|
|
249
|
+
/** The page's own modal that asks first, for what removes from a row in the page (a person off the list, a stay
|
|
250
|
+
* cancelled): one for each deed's words, put in the page as it's first wanted. Removing is always asked first. */
|
|
251
|
+
const pageAsks = new Map<string, ReturnType<typeof askFirst>>();
|
|
252
|
+
export function askOnPage(question: string, then: () => void, words = "Remove", follows = GONE) {
|
|
253
|
+
if (!pageAsks.has(words)) {
|
|
254
|
+
const dialog = surface("wa-dialog", { className: "ask" });
|
|
255
|
+
document.body.append(dialog);
|
|
256
|
+
pageAsks.set(words, askFirst(dialog, words));
|
|
257
|
+
}
|
|
258
|
+
pageAsks.get(words)!(question, then, follows);
|
|
76
259
|
}
|
|
77
260
|
|
|
78
261
|
/** What a display has open, in the URL's hash (`#event=2`), so Back closes it and a link opens it again (design.md,
|
package/src/plane.css
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* <j-plane>'s look (./plane.ts), after what readings share: the picture the page drew, as wide as there is room; its
|
|
2
|
+
marks on the accent, their words in card; a mark picked up lifted; the tools a bar above. */
|
|
3
|
+
.plane {
|
|
4
|
+
border-radius: var(--radius);
|
|
5
|
+
overflow: hidden;
|
|
6
|
+
background: var(--well);
|
|
7
|
+
}
|
|
8
|
+
.frame {
|
|
9
|
+
display: block;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: auto;
|
|
12
|
+
touch-action: none;
|
|
13
|
+
}
|
|
14
|
+
.mark {
|
|
15
|
+
cursor: grab;
|
|
16
|
+
}
|
|
17
|
+
.mark circle {
|
|
18
|
+
fill: var(--accent);
|
|
19
|
+
stroke: var(--card);
|
|
20
|
+
}
|
|
21
|
+
.mark text {
|
|
22
|
+
fill: var(--card);
|
|
23
|
+
font-family: var(--sans);
|
|
24
|
+
font-weight: 600;
|
|
25
|
+
text-anchor: middle;
|
|
26
|
+
pointer-events: none;
|
|
27
|
+
}
|
|
28
|
+
.mark[aria-current="true"] circle,
|
|
29
|
+
.mark[dragged] circle {
|
|
30
|
+
stroke: var(--ink);
|
|
31
|
+
}
|
|
32
|
+
.mark[dragged] {
|
|
33
|
+
cursor: grabbing;
|
|
34
|
+
}
|
|
35
|
+
.tools {
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-wrap: wrap;
|
|
38
|
+
gap: var(--space-8);
|
|
39
|
+
}
|
|
40
|
+
.tools[hidden] {
|
|
41
|
+
display: none;
|
|
42
|
+
}
|
|
43
|
+
.route {
|
|
44
|
+
fill: none;
|
|
45
|
+
stroke-linejoin: round;
|
|
46
|
+
pointer-events: none;
|
|
47
|
+
}
|
|
48
|
+
/* its parts one above another, a space between each, as joined's page spaces what it holds; none where one is empty */
|
|
49
|
+
:host {
|
|
50
|
+
display: grid;
|
|
51
|
+
gap: var(--space-12);
|
|
52
|
+
align-content: start;
|
|
53
|
+
}
|
|
54
|
+
.said:empty {
|
|
55
|
+
display: none;
|
|
56
|
+
}
|
package/src/plane.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// <j-plane for="marks" x="x" y="y" label="name"> (joined/kit): a collection on a picture drawn once, each item a mark
|
|
2
|
+
// where two of its fields put it. The picture is the page's (<svg slot="ground">, its viewBox the plane's units: a
|
|
3
|
+
// course on the water, a floor's plan); the marks are drawn on it, kept by key, each moved only as it changes. A mark
|
|
4
|
+
// pressed and dragged is laid where it's let go, one write of both fields, where its `may` lets it replace them; a
|
|
5
|
+
// mark that may not move doesn't. A mark tapped opens its sheet. Its tools (<j-tool>) float on it: Lay a mark chosen,
|
|
6
|
+
// the picture tapped opens a new mark's sheet on that place, the rest asked. route="courses:order" draws a line for each
|
|
7
|
+
// item of another collection through the marks its field names, in order ("1 2 3", by their labels), back round to the
|
|
8
|
+
// first, from="510 690" where it starts: a fleet's course from the line. A route is drawn, never gestured.
|
|
9
|
+
|
|
10
|
+
import { el, Reading } from "./reading.ts";
|
|
11
|
+
import { hueOf } from "./hues.ts";
|
|
12
|
+
import type { Item } from "./rows.ts";
|
|
13
|
+
import { specOf } from "./specs.ts";
|
|
14
|
+
import { applied, Tools } from "./tool.ts";
|
|
15
|
+
import STYLE from "./plane.css" with { type: "text" };
|
|
16
|
+
|
|
17
|
+
const SHEET = new CSSStyleSheet();
|
|
18
|
+
SHEET.replaceSync(STYLE);
|
|
19
|
+
const NS = "http://www.w3.org/2000/svg";
|
|
20
|
+
const svg = <K extends keyof SVGElementTagNameMap>(tag: K, attrs: Record<string, string | number> = {}) => {
|
|
21
|
+
const e = document.createElementNS(NS, tag);
|
|
22
|
+
for (const [k, v] of Object.entries(attrs)) e.setAttribute(k, String(v));
|
|
23
|
+
return e;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export class JPlane extends Reading {
|
|
27
|
+
static override sheets = [SHEET];
|
|
28
|
+
#tools = new Tools(this);
|
|
29
|
+
#frame = svg("svg", { class: "frame" });
|
|
30
|
+
#ground = svg("g", { class: "ground" });
|
|
31
|
+
#marks = svg("g", { class: "marks" });
|
|
32
|
+
#routes = svg("g", { class: "routes" });
|
|
33
|
+
/** The items drawn as routes, and the field naming their marks in order. */
|
|
34
|
+
#route?: { items: HTMLCollectionOf<Item>; field: string };
|
|
35
|
+
#kept = new Map<number, { shows: string; g: SVGGElement }>();
|
|
36
|
+
#moving = 0;
|
|
37
|
+
/** A mark's size, in the picture's units: a finger's width on a picture shown at its own size. */
|
|
38
|
+
#r = 20;
|
|
39
|
+
|
|
40
|
+
get #x() {
|
|
41
|
+
return this.getAttribute("x") ?? "x";
|
|
42
|
+
}
|
|
43
|
+
get #y() {
|
|
44
|
+
return this.getAttribute("y") ?? "y";
|
|
45
|
+
}
|
|
46
|
+
protected made() {
|
|
47
|
+
const picture = this.querySelector<SVGSVGElement>(':scope > svg[slot="ground"]');
|
|
48
|
+
this.#frame.setAttribute("viewBox", picture?.getAttribute("viewBox") ?? "0 0 1000 1000");
|
|
49
|
+
const box = this.#frame.viewBox.baseVal;
|
|
50
|
+
this.#r = Math.round(Math.min(box.width, box.height) * 0.035);
|
|
51
|
+
this.#frame.setAttribute("role", "img");
|
|
52
|
+
this.#frame.setAttribute("aria-label", this.getAttribute("label-words") ?? this.for);
|
|
53
|
+
for (const child of picture?.children ?? []) this.#ground.append(child.cloneNode(true));
|
|
54
|
+
this.#frame.append(this.#ground, this.#routes, this.#marks);
|
|
55
|
+
const [collection, field] = (this.getAttribute("route") ?? "").split(":");
|
|
56
|
+
if (collection && field)
|
|
57
|
+
specOf(collection, (spec) => {
|
|
58
|
+
this.#route = { items: document.getElementsByTagName(spec.tag) as HTMLCollectionOf<Item>, field };
|
|
59
|
+
this.again();
|
|
60
|
+
});
|
|
61
|
+
// a tap on the picture lays what's chosen there
|
|
62
|
+
this.#ground.addEventListener("pointerdown", (down) => {
|
|
63
|
+
if (down.button !== 0) return;
|
|
64
|
+
this.#ground.addEventListener("pointerup", (up) => void applied(this, this.#tools, null, this.#at(up)), {
|
|
65
|
+
once: true,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
this.root.append(this.#tools.bar, el("div", { className: "plane" }, this.#frame));
|
|
69
|
+
}
|
|
70
|
+
/** A point on the screen, in the picture's units. */
|
|
71
|
+
#at(e: { clientX: number; clientY: number }) {
|
|
72
|
+
const p = new DOMPoint(e.clientX, e.clientY).matrixTransform(this.#frame.getScreenCTM()!.inverse());
|
|
73
|
+
return { [this.#x]: Math.round(p.x), [this.#y]: Math.round(p.y) };
|
|
74
|
+
}
|
|
75
|
+
/** How many of the picture's units a pixel on the screen is. */
|
|
76
|
+
get #scale() {
|
|
77
|
+
const box = this.#frame.viewBox.baseVal;
|
|
78
|
+
return box.width / (this.#frame.getBoundingClientRect().width || box.width);
|
|
79
|
+
}
|
|
80
|
+
protected draw() {
|
|
81
|
+
this.#tools.draw();
|
|
82
|
+
this.#drawRoutes();
|
|
83
|
+
const seen = new Set<number>();
|
|
84
|
+
for (const it of this.items()) {
|
|
85
|
+
const x = Number(it.data[this.#x]),
|
|
86
|
+
y = Number(it.data[this.#y]);
|
|
87
|
+
if (!Number.isFinite(x) || !Number.isFinite(y)) continue;
|
|
88
|
+
seen.add(it.key);
|
|
89
|
+
const words = this.says(it, this.getAttribute("label") ?? "name") || this.named(it),
|
|
90
|
+
// what it may do too: a mark drawn before its `may` came is drawn again, draggable
|
|
91
|
+
shows = `${x} ${y} ${words} ${this.opened(it)} ${it.getAttribute("may")}`,
|
|
92
|
+
k = this.#kept.get(it.key);
|
|
93
|
+
if ((k && k.shows === shows) || this.#moving === it.key) continue;
|
|
94
|
+
const g = this.#mark(it, x, y, words);
|
|
95
|
+
if (k) k.g.replaceWith(g);
|
|
96
|
+
else this.#marks.append(g);
|
|
97
|
+
this.#kept.set(it.key, { shows, g });
|
|
98
|
+
}
|
|
99
|
+
for (const [key, k] of this.#kept) if (!seen.has(key)) (k.g.remove(), this.#kept.delete(key));
|
|
100
|
+
}
|
|
101
|
+
/** Each route: a line from where it starts through the marks it names, in order, and back round to the first. */
|
|
102
|
+
#drawRoutes() {
|
|
103
|
+
const r = this.#route,
|
|
104
|
+
label = this.getAttribute("label") ?? "name";
|
|
105
|
+
if (!r) return;
|
|
106
|
+
const at = new Map(this.items().map((it) => [String(it.data[label]), `${it.data[this.#x]},${it.data[this.#y]}`]));
|
|
107
|
+
const from = (this.getAttribute("from") ?? "").trim().split(/\s+/).filter(Boolean);
|
|
108
|
+
this.#routes.replaceChildren(
|
|
109
|
+
...[...r.items]
|
|
110
|
+
.filter((it) => it.isConnected)
|
|
111
|
+
.flatMap((it) => {
|
|
112
|
+
const stops = String(it.data[r.field] ?? "")
|
|
113
|
+
.split(/\s+/)
|
|
114
|
+
.flatMap((n) => (at.has(n) ? [at.get(n)!] : []));
|
|
115
|
+
if (!stops.length) return [];
|
|
116
|
+
const line = svg("polyline", {
|
|
117
|
+
class: "route",
|
|
118
|
+
points: [...(from.length === 2 ? [from.join(",")] : []), ...stops, stops[0]!].join(" "),
|
|
119
|
+
"stroke-width": Math.max(1, Math.round(this.#r * 0.15)),
|
|
120
|
+
"stroke-dasharray": `${this.#r * 0.6} ${this.#r * 0.4}`,
|
|
121
|
+
});
|
|
122
|
+
line.style.stroke = hueOf(it.key);
|
|
123
|
+
return [line];
|
|
124
|
+
}),
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
/** An item's mark: a dot and its words where its fields put it, dragged where it may move. */
|
|
128
|
+
#mark(it: Item, x: number, y: number, words: string) {
|
|
129
|
+
const g = svg("g", { class: "mark", "data-key": it.key, transform: `translate(${x} ${y})`, tabindex: 0 });
|
|
130
|
+
g.setAttribute("aria-label", words);
|
|
131
|
+
const label = svg("text", { y: Math.round(this.#r * 0.4), "font-size": Math.round(this.#r * 1.1) });
|
|
132
|
+
label.textContent = words;
|
|
133
|
+
g.append(svg("circle", { r: this.#r }), label);
|
|
134
|
+
const moves = this.may(it, this.#x) && this.may(it, this.#y);
|
|
135
|
+
this.press(
|
|
136
|
+
g as unknown as HTMLElement,
|
|
137
|
+
it,
|
|
138
|
+
moves
|
|
139
|
+
? (dx, dy, done) => {
|
|
140
|
+
const s = this.#scale,
|
|
141
|
+
nx = Math.round(x + dx * s),
|
|
142
|
+
ny = Math.round(y + dy * s);
|
|
143
|
+
this.#moving = done ? 0 : it.key;
|
|
144
|
+
g.setAttribute("transform", `translate(${nx} ${ny})`);
|
|
145
|
+
if (done && (dx || dy)) void this.change(it, { [this.#x]: nx, [this.#y]: ny });
|
|
146
|
+
}
|
|
147
|
+
: undefined,
|
|
148
|
+
);
|
|
149
|
+
return g;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The Postgres server joined's store is kept on (src/engine.ts's), by its URL with its password, through Bun.sql. Told
|
|
2
|
+
// by bun run test:postgres (tests/postgres/), against a server in Docker: not the gate's, which has no server.
|
|
3
|
+
|
|
4
|
+
import { postgresOf, type Engine } from "./engine.ts";
|
|
5
|
+
|
|
6
|
+
/** A Postgres server, by its URL (JOINED_POSTGRES: postgres://user:password@host:port/database), through Bun.sql: one
|
|
7
|
+
* connection held for the store, and LISTEN on a connection of its own. `fresh`: a database of its own, made as it
|
|
8
|
+
* opens and dropped as it closes (a test's). */
|
|
9
|
+
export async function server(url: string, { fresh = false } = {}): Promise<Engine> {
|
|
10
|
+
const { SQL } = await import("bun");
|
|
11
|
+
const at = new URL(url);
|
|
12
|
+
let made: string | undefined;
|
|
13
|
+
if (fresh) {
|
|
14
|
+
made = `joined_${crypto.randomUUID().replaceAll("-", "")}`;
|
|
15
|
+
const admin = new SQL(url, { max: 1 });
|
|
16
|
+
try {
|
|
17
|
+
await admin.unsafe(`CREATE DATABASE ${made}`);
|
|
18
|
+
} finally {
|
|
19
|
+
await admin.close();
|
|
20
|
+
}
|
|
21
|
+
at.pathname = `/${made}`;
|
|
22
|
+
}
|
|
23
|
+
const sql = new SQL(at.href, { max: 2 });
|
|
24
|
+
let held: Awaited<ReturnType<typeof sql.reserve>>;
|
|
25
|
+
try {
|
|
26
|
+
held = await sql.reserve();
|
|
27
|
+
} catch (e) {
|
|
28
|
+
await sql.close();
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
const types = (columns: unknown) =>
|
|
32
|
+
new Map(((columns as { name: string; type: number }[] | undefined) ?? []).map((f) => [f.name, f.type]));
|
|
33
|
+
return postgresOf(
|
|
34
|
+
{
|
|
35
|
+
async query(text, values) {
|
|
36
|
+
const r = (await held.unsafe(text, values as never[])) as unknown as Record<string, unknown>[] & {
|
|
37
|
+
count: number | null;
|
|
38
|
+
columns?: unknown;
|
|
39
|
+
};
|
|
40
|
+
return { rows: [...r], changes: r.count ?? 0, types: types(r.columns) };
|
|
41
|
+
},
|
|
42
|
+
many: (text) => held.unsafe(text).simple(),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
listen: async (channel, heard) => void (await sql.listen(channel, heard)),
|
|
46
|
+
notify: (channel, payload) => held.unsafe("SELECT pg_notify($1, $2)", [channel, payload]),
|
|
47
|
+
async close() {
|
|
48
|
+
held.release();
|
|
49
|
+
await sql.close();
|
|
50
|
+
if (!made) return;
|
|
51
|
+
const admin = new SQL(url, { max: 1 });
|
|
52
|
+
try {
|
|
53
|
+
await admin.unsafe(`DROP DATABASE IF EXISTS ${made} WITH (FORCE)`);
|
|
54
|
+
} finally {
|
|
55
|
+
await admin.close();
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
}
|
package/src/reading.css
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* What every reading (./reading.ts) shares, in its shadow: its head (what it shows, the way back and on, Today), an
|
|
2
|
+
item's mark (on a tint of its own colour, a stripe of it at its start; the one open stronger), a mark picked up, and the line
|
|
3
|
+
that says a refusal. Each reading's own sheet places them. */
|
|
4
|
+
:host {
|
|
5
|
+
display: block;
|
|
6
|
+
min-width: 0;
|
|
7
|
+
}
|
|
8
|
+
:host([hidden]) {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
.head {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
gap: var(--space-4);
|
|
15
|
+
padding: var(--space-8) var(--space-8) var(--space-8) var(--space-16);
|
|
16
|
+
}
|
|
17
|
+
.head h3 {
|
|
18
|
+
flex: 1;
|
|
19
|
+
min-width: 0;
|
|
20
|
+
margin: 0;
|
|
21
|
+
font: var(--font-title);
|
|
22
|
+
}
|
|
23
|
+
.head .today {
|
|
24
|
+
margin-inline-end: var(--space-4);
|
|
25
|
+
}
|
|
26
|
+
/* an item, the way into it: its words on a tint of its colour (its key's hue, ./hues.ts), a stripe of it at its start */
|
|
27
|
+
.item {
|
|
28
|
+
box-sizing: border-box;
|
|
29
|
+
display: block;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
min-width: 0;
|
|
32
|
+
padding: var(--space-4) var(--space-6);
|
|
33
|
+
border: 0;
|
|
34
|
+
border-inline-start: var(--size-stripe) solid var(--hue, var(--accent));
|
|
35
|
+
border-radius: var(--radius-inner);
|
|
36
|
+
background: color-mix(in srgb, var(--hue, var(--accent)) var(--tint), var(--card));
|
|
37
|
+
color: var(--ink);
|
|
38
|
+
font: var(--font-tiny);
|
|
39
|
+
text-align: start;
|
|
40
|
+
text-overflow: ellipsis;
|
|
41
|
+
white-space: nowrap;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
touch-action: manipulation;
|
|
44
|
+
}
|
|
45
|
+
.item:hover,
|
|
46
|
+
.item[aria-current="true"] {
|
|
47
|
+
background: color-mix(in srgb, var(--hue, var(--accent)) var(--tint-strong), var(--card));
|
|
48
|
+
}
|
|
49
|
+
.item[aria-current="true"] {
|
|
50
|
+
outline: 1px solid var(--hue, var(--accent));
|
|
51
|
+
}
|
|
52
|
+
.item .at {
|
|
53
|
+
color: var(--muted);
|
|
54
|
+
font-variant-numeric: tabular-nums;
|
|
55
|
+
}
|
|
56
|
+
.item[dragged] {
|
|
57
|
+
z-index: 2;
|
|
58
|
+
box-shadow: var(--drop);
|
|
59
|
+
cursor: grabbing;
|
|
60
|
+
opacity: 0.9;
|
|
61
|
+
}
|
|
62
|
+
/* a refusal, said under it */
|
|
63
|
+
.said {
|
|
64
|
+
margin: 0;
|
|
65
|
+
padding: 0 var(--space-16);
|
|
66
|
+
color: var(--danger-ink);
|
|
67
|
+
font: var(--font-small);
|
|
68
|
+
}
|
|
69
|
+
.said:empty {
|
|
70
|
+
display: none;
|
|
71
|
+
}
|
|
72
|
+
@media (pointer: coarse) {
|
|
73
|
+
.head .icon-only {
|
|
74
|
+
width: var(--size-finger);
|
|
75
|
+
height: var(--size-finger);
|
|
76
|
+
}
|
|
77
|
+
}
|