@blueshed/joined 0.3.0 → 0.3.2
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/reference.md +57 -18
- package/docs/design.md +93 -38
- package/docs/introduction.md +9 -9
- package/docs/light-and-shadow.svg +1 -0
- package/docs/links-and-trust.svg +1 -0
- package/docs/stories-to-code.svg +2 -1
- package/docs/wire-op.svg +1 -0
- package/examples/app.css +9 -0
- package/examples/cafe/cafe.css +87 -69
- package/examples/cafe/generated/staff.elements.ts +7 -2
- package/examples/cafe/generated/staff.rules.ts +3 -0
- package/examples/cafe/generated/supplies.rules.ts +5 -0
- package/examples/cafe/kitchen.css +11 -19
- package/examples/cafe/kitchen.ts +6 -2
- package/examples/cafe/migrations/002-guard-supplies.ts +15 -0
- package/examples/cafe/order.html +2 -1
- package/examples/cafe/order.ts +1 -1
- package/examples/cafe/staff.json +5 -0
- package/examples/cafe/stories.jsonl +4 -2
- package/examples/cafe/supplies.html +1 -0
- package/examples/cafe/supplies.ts +45 -28
- package/examples/cafe/till.ts +14 -10
- package/examples/cafe/views.ts +7 -5
- package/examples/chart/arches.ts +5 -3
- package/examples/chart/chart.css +7 -2
- package/examples/desk/desk.css +6 -10
- package/examples/desk/generated/elements.ts +1 -1
- package/examples/desk/index.html +1 -1
- package/examples/desk/lanes.css +21 -19
- package/examples/desk/stories.jsonl +1 -1
- package/examples/desk/tally.css +1 -1
- package/examples/docs.ts +7 -4
- package/examples/index.html +16 -7
- package/examples/notes/generated/queries.ts +8 -2
- package/examples/notes/index.html +1 -1
- package/examples/notes/stories.jsonl +3 -0
- package/examples/page.ts +9 -2
- package/examples/people/links.ts +7 -9
- package/examples/people/people.css +1 -1
- package/examples/people/view.ts +1 -1
- package/examples/trip/generated/elements.ts +1 -1
- package/examples/trip/stays.css +1 -1
- package/examples/trip/stays.ts +1 -1
- package/examples/trips/generated/elements.ts +1 -1
- package/examples/trips/trips.css +24 -23
- package/examples/welcome.css +41 -33
- package/package.json +1 -1
- package/src/attachment.ts +17 -2
- package/src/board.css +2 -1
- package/src/board.ts +4 -4
- package/src/cli.ts +14 -2
- package/src/compile.ts +255 -77
- package/src/definitions.ts +62 -14
- package/src/demo.css +2 -5
- package/src/draft.ts +10 -4
- package/src/drawer.ts +30 -4
- package/src/engine.ts +14 -5
- package/src/fields.ts +88 -15
- package/src/file-value.ts +12 -2
- package/src/files.ts +113 -35
- package/src/icon-names.ts +4 -0
- package/src/keep.ts +16 -3
- package/src/map.css +23 -16
- package/src/map.ts +3 -3
- package/src/mcp.ts +24 -3
- package/src/members/group.ts +41 -17
- package/src/members/keys.ts +3 -3
- package/src/members/panel.css +17 -18
- package/src/members/panel.ts +9 -2
- package/src/migrate.ts +58 -21
- package/src/migrations/005-change-kept.ts +7 -0
- package/src/month.css +6 -2
- package/src/month.ts +5 -5
- package/src/ops.ts +40 -1
- package/src/page.css +3 -2
- package/src/page.ts +64 -16
- package/src/parts.css +178 -86
- package/src/parts.ts +60 -20
- package/src/plane.css +9 -4
- package/src/plane.ts +4 -2
- package/src/reading.css +1 -5
- package/src/rows.css +2 -21
- package/src/rows.ts +123 -39
- package/src/server.ts +157 -30
- package/src/sheet.ts +4 -2
- package/src/slots.css +0 -4
- package/src/specs.ts +1 -1
- package/src/starter.ts +15 -1
- package/src/store.ts +40 -18
- package/src/surface.ts +7 -2
- package/src/time.ts +2 -0
- package/src/timeline.ts +14 -5
- package/src/together.ts +15 -17
- package/src/tokens.css +12 -3
- package/src/tokens.json +38 -7
- package/src/tool.ts +6 -7
- package/src/upkeep.ts +31 -4
- package/src/views.css +8 -9
- package/src/views.ts +23 -6
- package/src/week.css +1 -2
- package/src/week.ts +11 -7
- package/src/write.ts +130 -15
- package/starter/CHANGELOG.md +8 -0
- package/starter/CLAUDE.md +7 -1
- package/starter/bunfig +2 -1
- package/starter/githooks/pre-commit +13 -0
- package/starter/prettierignore +1 -0
- package/starter/tests/records.test.ts +40 -0
- package/starter/todo.jsonl +0 -0
package/src/parts.ts
CHANGED
|
@@ -116,12 +116,14 @@ export function place(at: string, zoom = 15) {
|
|
|
116
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
117
|
* `say(words)` sets what it says, only where it's changed. */
|
|
118
118
|
export function mention(act: (by: HTMLElement) => void) {
|
|
119
|
-
|
|
119
|
+
// its words a pill inside it: the button is what's tapped, a finger tall under a finger, the pill only its look
|
|
120
|
+
const el = Object.assign(document.createElement("button"), { type: "button", className: "j-mention" }),
|
|
121
|
+
words = el.appendChild(document.createElement("span"));
|
|
120
122
|
el.addEventListener("click", () => act(el));
|
|
121
123
|
return {
|
|
122
124
|
el,
|
|
123
|
-
say(
|
|
124
|
-
if (
|
|
125
|
+
say(said: string) {
|
|
126
|
+
if (words.textContent !== said) words.textContent = said;
|
|
125
127
|
},
|
|
126
128
|
};
|
|
127
129
|
}
|
|
@@ -208,12 +210,12 @@ export function placed<T extends HTMLElement>(drawer: T) {
|
|
|
208
210
|
return drawer;
|
|
209
211
|
}
|
|
210
212
|
|
|
211
|
-
/** What follows a removal, said under its
|
|
213
|
+
/** What follows a removal, said under its title (Peter, 2 Dec: a modal states, it doesn't ask: the buttons ask). */
|
|
212
214
|
export const GONE = "It goes for everyone at once, and can't be put back.";
|
|
213
215
|
|
|
214
|
-
/** A modal that asks first (Modal), a wa-dialog: its
|
|
215
|
-
* (keep) or the deed (sure),
|
|
216
|
-
* and what follows (`follows`, unless said). */
|
|
216
|
+
/** A modal that asks first (Modal), a wa-dialog: its title saying what will happen ("Soba will be removed."), a line
|
|
217
|
+
* saying what follows, then Never mind (keep) or the deed (sure), a removal's with its icon, made in it where it has
|
|
218
|
+
* none. What it returns asks it: what will happen, what the deed does, and what follows (`follows`, unless said). */
|
|
217
219
|
export function askFirst(dialog: HTMLElement & { open: boolean }, words = "Remove", follows = GONE) {
|
|
218
220
|
let deed = () => {};
|
|
219
221
|
dialog.classList.add("j-ask");
|
|
@@ -233,13 +235,15 @@ export function askFirst(dialog: HTMLElement & { open: boolean }, words = "Remov
|
|
|
233
235
|
textContent: words,
|
|
234
236
|
}),
|
|
235
237
|
);
|
|
238
|
+
// a deed that removes says its word, its icon beside it (design.md, Icons)
|
|
239
|
+
if (/^Remove\b/.test(words)) foot.lastElementChild!.prepend(icon("remove"));
|
|
236
240
|
dialog.append(Object.assign(document.createElement("h2"), { slot: "label" }), foot);
|
|
237
241
|
}
|
|
238
242
|
const line = dialog.querySelector(":scope > p") ?? dialog.appendChild(document.createElement("p"));
|
|
239
243
|
dialog.querySelector("[name=keep]")!.addEventListener("click", () => (dialog.open = false));
|
|
240
244
|
dialog.querySelector("[name=sure]")!.addEventListener("click", () => ((dialog.open = false), deed()));
|
|
241
|
-
return (
|
|
242
|
-
dialog.querySelector("h2")!.textContent =
|
|
245
|
+
return (title: string, then: () => void, said = follows) => {
|
|
246
|
+
dialog.querySelector("h2")!.textContent = title;
|
|
243
247
|
line.textContent = said;
|
|
244
248
|
deed = then;
|
|
245
249
|
dialog.open = true;
|
|
@@ -249,13 +253,13 @@ export function askFirst(dialog: HTMLElement & { open: boolean }, words = "Remov
|
|
|
249
253
|
/** 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
254
|
* cancelled): one for each deed's words, put in the page as it's first wanted. Removing is always asked first. */
|
|
251
255
|
const pageAsks = new Map<string, ReturnType<typeof askFirst>>();
|
|
252
|
-
export function askOnPage(
|
|
256
|
+
export function askOnPage(title: string, then: () => void, words = "Remove", follows = GONE) {
|
|
253
257
|
if (!pageAsks.has(words)) {
|
|
254
258
|
const dialog = surface("wa-dialog", { className: "ask" });
|
|
255
259
|
document.body.append(dialog);
|
|
256
260
|
pageAsks.set(words, askFirst(dialog, words));
|
|
257
261
|
}
|
|
258
|
-
pageAsks.get(words)!(
|
|
262
|
+
pageAsks.get(words)!(title, then, follows);
|
|
259
263
|
}
|
|
260
264
|
|
|
261
265
|
/** What a display has open, in the URL's hash (`#event=2`), so Back closes it and a link opens it again (design.md,
|
|
@@ -303,9 +307,14 @@ export function inHash<T extends { key: number }>(
|
|
|
303
307
|
return { mark, again: () => void (wanted !== null && open()) };
|
|
304
308
|
}
|
|
305
309
|
|
|
310
|
+
/** Each typeahead's list has an id of its own, and its matches theirs by it: what its field names them by. */
|
|
311
|
+
let lists = 0;
|
|
312
|
+
|
|
306
313
|
/** A typeahead (Choosing: more than six): what's typed in `field` matched against what may be chosen, the matches
|
|
307
|
-
* offered beneath it in `list` (the first eight), a list of choices
|
|
308
|
-
*
|
|
314
|
+
* offered beneath it in `list` (the first eight), a list of choices. It's a combobox (WAI-ARIA): the focus stays in
|
|
315
|
+
* the field, which says whether its list is shown and names its active match, the first until the arrows move it,
|
|
316
|
+
* from the last round to the first. One tapped, or the active one on Enter, is chosen and the field emptied; Escape
|
|
317
|
+
* lets them go, leaving what's typed, and the arrows bring them back. An underscore is read as a space
|
|
309
318
|
* (America/New_York, typed "new york"). It returns its offer, to call again when what may be chosen changes. */
|
|
310
319
|
export function typeahead(
|
|
311
320
|
field: HTMLInputElement,
|
|
@@ -314,6 +323,22 @@ export function typeahead(
|
|
|
314
323
|
choose: (key: number) => void,
|
|
315
324
|
) {
|
|
316
325
|
const kept = new Map<string, { shows: string; el: HTMLElement }>();
|
|
326
|
+
let active: string | undefined; // the active match, by its id
|
|
327
|
+
list.id ||= `j-choices-${++lists}`;
|
|
328
|
+
list.role = "listbox";
|
|
329
|
+
field.role = "combobox";
|
|
330
|
+
field.ariaAutoComplete = "list";
|
|
331
|
+
field.setAttribute("aria-controls", list.id);
|
|
332
|
+
/** The list shown or not, and its active match, as the field says them: the one active still, or the first. */
|
|
333
|
+
const say = (shown: boolean) => {
|
|
334
|
+
const matches = [...list.children];
|
|
335
|
+
list.hidden = !shown;
|
|
336
|
+
field.ariaExpanded = String(shown);
|
|
337
|
+
active = shown ? (matches.find((m) => m.id === active) ?? matches[0])!.id : undefined;
|
|
338
|
+
for (const m of matches) m.ariaSelected = String(m.id === active);
|
|
339
|
+
if (active) field.setAttribute("aria-activedescendant", active);
|
|
340
|
+
else field.removeAttribute("aria-activedescendant");
|
|
341
|
+
};
|
|
317
342
|
const offer = () => {
|
|
318
343
|
const said = (s: string) => s.toLowerCase().replaceAll("_", " "),
|
|
319
344
|
q = said(field.value.trim()),
|
|
@@ -322,7 +347,6 @@ export function typeahead(
|
|
|
322
347
|
.filter(([, words]) => said(words).includes(q))
|
|
323
348
|
.slice(0, 8)
|
|
324
349
|
: [];
|
|
325
|
-
list.hidden = !found.length;
|
|
326
350
|
keep(
|
|
327
351
|
list,
|
|
328
352
|
kept,
|
|
@@ -330,19 +354,35 @@ export function typeahead(
|
|
|
330
354
|
key: String(key),
|
|
331
355
|
shows: words,
|
|
332
356
|
make: () => {
|
|
333
|
-
const b = Object.assign(document.createElement("button"), {
|
|
334
|
-
|
|
357
|
+
const b = Object.assign(document.createElement("button"), {
|
|
358
|
+
type: "button",
|
|
359
|
+
role: "option",
|
|
360
|
+
id: `${list.id}-${key}`,
|
|
361
|
+
tabIndex: -1, // the arrows reach it, from the field
|
|
362
|
+
textContent: words,
|
|
363
|
+
});
|
|
335
364
|
b.addEventListener("click", () => ((field.value = ""), offer(), choose(key), field.focus()));
|
|
336
365
|
return b;
|
|
337
366
|
},
|
|
338
367
|
})),
|
|
339
368
|
);
|
|
369
|
+
say(found.length > 0);
|
|
340
370
|
};
|
|
341
|
-
|
|
371
|
+
say(false);
|
|
372
|
+
field.addEventListener("input", () => ((active = undefined), offer()));
|
|
342
373
|
field.addEventListener("keydown", (e) => {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
374
|
+
if (e.isComposing) return; // the keys are the input method's
|
|
375
|
+
const matches = [...list.children] as HTMLElement[],
|
|
376
|
+
at = matches.findIndex((m) => m.id === active);
|
|
377
|
+
if (e.key === "Enter") (e.preventDefault(), matches[at]?.click()); // never the form's Save
|
|
378
|
+
if (e.key === "Escape" && !list.hidden) (e.preventDefault(), say(false));
|
|
379
|
+
if ((e.key === "ArrowDown" || e.key === "ArrowUp") && matches.length) {
|
|
380
|
+
e.preventDefault();
|
|
381
|
+
if (list.hidden) return offer();
|
|
382
|
+
active = matches.at((at + (e.key === "ArrowDown" ? 1 : -1)) % matches.length)!.id;
|
|
383
|
+
say(true);
|
|
384
|
+
matches.find((m) => m.id === active)!.scrollIntoView({ block: "nearest" });
|
|
385
|
+
}
|
|
346
386
|
});
|
|
347
387
|
return offer;
|
|
348
388
|
}
|
package/src/plane.css
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
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
|
|
2
|
+
marks on the accent, their words in card, drawn only when asked for (docs/maps.md: words on demand, never by
|
|
3
|
+
default): a mark pointed at, held by the keys, picked up or open; a mark picked up lifted; the tools a bar above. */
|
|
3
4
|
.plane {
|
|
4
5
|
border-radius: var(--radius);
|
|
5
6
|
overflow: hidden;
|
|
@@ -24,6 +25,13 @@
|
|
|
24
25
|
font-weight: 600;
|
|
25
26
|
text-anchor: middle;
|
|
26
27
|
pointer-events: none;
|
|
28
|
+
visibility: hidden;
|
|
29
|
+
}
|
|
30
|
+
.mark:hover text,
|
|
31
|
+
.mark:focus text,
|
|
32
|
+
.mark[aria-current="true"] text,
|
|
33
|
+
.mark[dragged] text {
|
|
34
|
+
visibility: visible;
|
|
27
35
|
}
|
|
28
36
|
.mark[aria-current="true"] circle,
|
|
29
37
|
.mark[dragged] circle {
|
|
@@ -37,9 +45,6 @@
|
|
|
37
45
|
flex-wrap: wrap;
|
|
38
46
|
gap: var(--space-8);
|
|
39
47
|
}
|
|
40
|
-
.tools[hidden] {
|
|
41
|
-
display: none;
|
|
42
|
-
}
|
|
43
48
|
.route {
|
|
44
49
|
fill: none;
|
|
45
50
|
stroke-linejoin: round;
|
package/src/plane.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
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
|
|
2
|
+
// where two of its fields put it, its name drawn only when it's asked for (pointed at, held, open: docs/maps.md, words
|
|
3
|
+
// on demand). The picture is the page's (<svg slot="ground">, its viewBox the plane's units: a
|
|
3
4
|
// 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
5
|
// pressed and dragged is laid where it's let go, one write of both fields, where its `may` lets it replace them; a
|
|
5
6
|
// mark that may not move doesn't. A mark tapped opens its sheet. Its tools (<j-tool>) float on it: Lay a mark chosen,
|
|
@@ -124,7 +125,8 @@ export class JPlane extends Reading {
|
|
|
124
125
|
}),
|
|
125
126
|
);
|
|
126
127
|
}
|
|
127
|
-
/** An item's mark: a dot
|
|
128
|
+
/** An item's mark: a dot where its fields put it, its words drawn only when asked for (./plane.css) and always its
|
|
129
|
+
* name to a screen reader; dragged where it may move. */
|
|
128
130
|
#mark(it: Item, x: number, y: number, words: string) {
|
|
129
131
|
const g = svg("g", { class: "mark", "data-key": it.key, transform: `translate(${x} ${y})`, tabindex: 0 });
|
|
130
132
|
g.setAttribute("aria-label", words);
|
package/src/reading.css
CHANGED
|
@@ -5,9 +5,6 @@
|
|
|
5
5
|
display: block;
|
|
6
6
|
min-width: 0;
|
|
7
7
|
}
|
|
8
|
-
:host([hidden]) {
|
|
9
|
-
display: none;
|
|
10
|
-
}
|
|
11
8
|
.head {
|
|
12
9
|
display: flex;
|
|
13
10
|
align-items: center;
|
|
@@ -55,7 +52,6 @@
|
|
|
55
52
|
}
|
|
56
53
|
.item[dragged] {
|
|
57
54
|
z-index: 2;
|
|
58
|
-
box-shadow: var(--drop);
|
|
59
55
|
cursor: grabbing;
|
|
60
56
|
opacity: 0.9;
|
|
61
57
|
}
|
|
@@ -63,7 +59,7 @@
|
|
|
63
59
|
.said {
|
|
64
60
|
margin: 0;
|
|
65
61
|
padding: 0 var(--space-16);
|
|
66
|
-
color: var(--danger
|
|
62
|
+
color: var(--danger);
|
|
67
63
|
font: var(--font-small);
|
|
68
64
|
}
|
|
69
65
|
.said:empty {
|
package/src/rows.css
CHANGED
|
@@ -27,9 +27,6 @@ ul {
|
|
|
27
27
|
grid-template-columns: minmax(0, 1fr) max-content;
|
|
28
28
|
column-gap: var(--space-24);
|
|
29
29
|
}
|
|
30
|
-
li[hidden] {
|
|
31
|
-
display: none;
|
|
32
|
-
}
|
|
33
30
|
li {
|
|
34
31
|
grid-column: 1 / -1;
|
|
35
32
|
display: grid;
|
|
@@ -125,16 +122,12 @@ li:has(> .row .open[aria-current])::before {
|
|
|
125
122
|
position: absolute;
|
|
126
123
|
inset-block: 0;
|
|
127
124
|
inset-inline-start: 0;
|
|
128
|
-
width: var(--
|
|
125
|
+
width: var(--size-stripe);
|
|
129
126
|
background: var(--accent);
|
|
130
127
|
}
|
|
131
128
|
button.open:hover .name {
|
|
132
129
|
text-decoration: underline;
|
|
133
130
|
}
|
|
134
|
-
button.open:focus-visible {
|
|
135
|
-
outline: 2px solid var(--accent);
|
|
136
|
-
outline-offset: var(--space-4);
|
|
137
|
-
}
|
|
138
131
|
.name {
|
|
139
132
|
display: flex;
|
|
140
133
|
flex-wrap: wrap;
|
|
@@ -215,10 +208,6 @@ li > .adding {
|
|
|
215
208
|
.said:not(:empty) {
|
|
216
209
|
margin: var(--space-8) var(--inset);
|
|
217
210
|
}
|
|
218
|
-
/* a link's two ways of choosing: one is shown, by how many there are to choose from */
|
|
219
|
-
:is(wa-select, label)[hidden] {
|
|
220
|
-
display: none;
|
|
221
|
-
}
|
|
222
211
|
/* nothing under an item yet: said, where its list would be */
|
|
223
212
|
.under:empty {
|
|
224
213
|
border: 0;
|
|
@@ -231,9 +220,6 @@ li > .adding {
|
|
|
231
220
|
font: var(--font-small);
|
|
232
221
|
}
|
|
233
222
|
@media (max-width: 40rem) {
|
|
234
|
-
.act.small {
|
|
235
|
-
min-height: var(--size-finger);
|
|
236
|
-
}
|
|
237
223
|
/* on a phone, one column: the deeds under the words they're of */
|
|
238
224
|
ul {
|
|
239
225
|
grid-template-columns: minmax(0, 1fr);
|
|
@@ -254,9 +240,6 @@ li > .adding {
|
|
|
254
240
|
}
|
|
255
241
|
|
|
256
242
|
/* whose order it's in, at its head */
|
|
257
|
-
.whose[hidden] {
|
|
258
|
-
display: none;
|
|
259
|
-
}
|
|
260
243
|
.whose {
|
|
261
244
|
display: flex;
|
|
262
245
|
flex-wrap: wrap;
|
|
@@ -272,6 +255,7 @@ li > .adding {
|
|
|
272
255
|
.whose .j-chips > button:has(.j-face) {
|
|
273
256
|
padding-left: var(--space-4);
|
|
274
257
|
}
|
|
258
|
+
/* whose order is shown, pressed: these chips carry no hue of their own (Everyone's is no one's), so marked in ink */
|
|
275
259
|
.whose .j-chips > [aria-pressed="true"] {
|
|
276
260
|
border: 1px solid var(--ink);
|
|
277
261
|
background: var(--card-hover);
|
|
@@ -303,6 +287,3 @@ form.adding.box > input {
|
|
|
303
287
|
form.adding.box > .said {
|
|
304
288
|
flex-basis: 100%;
|
|
305
289
|
}
|
|
306
|
-
form.adding[hidden] {
|
|
307
|
-
display: none;
|
|
308
|
-
}
|
package/src/rows.ts
CHANGED
|
@@ -107,7 +107,10 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
107
107
|
#kept = new Map<string, { shows: string; el: HTMLElement }>();
|
|
108
108
|
/** What's under each item, by its key: its list, kept as the item's row is made again. */
|
|
109
109
|
#under = new Map<string, { list: HTMLElement; kept: Map<string, { shows: string; el: HTMLElement }> }[]>();
|
|
110
|
-
#watch = new MutationObserver(() => this
|
|
110
|
+
#watch = new MutationObserver(() => this.#soon());
|
|
111
|
+
#frame = 0;
|
|
112
|
+
/** What's been looked up for the draw it's in the middle of (none, between them): each thing once. */
|
|
113
|
+
#known?: Map<string, unknown>;
|
|
111
114
|
#away = new AbortController();
|
|
112
115
|
/** The words a search of its collection (<j-search>) looks for: its rows without every one aren't shown. */
|
|
113
116
|
#words: string[] = [];
|
|
@@ -124,7 +127,7 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
124
127
|
this.#away = new AbortController();
|
|
125
128
|
// its own items; and, where one links to another, the page's, wherever that collection is
|
|
126
129
|
this.#watch.observe(linked ? document.body : this, { childList: true, subtree: true, attributes: true });
|
|
127
|
-
signedIn((me) => ((this.me = me), this
|
|
130
|
+
signedIn((me) => ((this.me = me), this.#soon()), this.#away.signal);
|
|
128
131
|
document.addEventListener(
|
|
129
132
|
"j-search",
|
|
130
133
|
(e) => {
|
|
@@ -147,8 +150,46 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
147
150
|
}
|
|
148
151
|
disconnectedCallback() {
|
|
149
152
|
this.#watch.disconnect();
|
|
153
|
+
this.#drawn();
|
|
150
154
|
this.#away.abort();
|
|
151
155
|
}
|
|
156
|
+
/** What's heard (a change, who's signed in and what they may do) is drawn at the next frame, with all else heard by
|
|
157
|
+
* then: once, however much. */
|
|
158
|
+
#soon() {
|
|
159
|
+
this.#frame ||= requestAnimationFrame(() => ((this.#frame = 0), this.draw()));
|
|
160
|
+
}
|
|
161
|
+
/** A draw waiting for its frame, done already or wanted no more. */
|
|
162
|
+
#drawn() {
|
|
163
|
+
cancelAnimationFrame(this.#frame);
|
|
164
|
+
this.#frame = 0;
|
|
165
|
+
}
|
|
166
|
+
/** Something done with what it looks up kept until it's done: the document doesn't change under it. */
|
|
167
|
+
#looking<T>(done: () => T): T {
|
|
168
|
+
if (this.#known) return done();
|
|
169
|
+
this.#known = new Map();
|
|
170
|
+
try {
|
|
171
|
+
return done();
|
|
172
|
+
} finally {
|
|
173
|
+
this.#known = undefined;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** Something looked up: once in a draw, each time between them. */
|
|
177
|
+
#once<T>(what: string, look: () => T): T {
|
|
178
|
+
if (!this.#known) return look();
|
|
179
|
+
if (!this.#known.has(what)) this.#known.set(what, look());
|
|
180
|
+
return this.#known.get(what) as T;
|
|
181
|
+
}
|
|
182
|
+
/** An item on the page, by its element and its key (what a field links to). */
|
|
183
|
+
#at<T extends Element = Element>(tag: string, key: number): T | null {
|
|
184
|
+
if (!this.#known) return document.querySelector<T>(`${tag}[key="${key}"]`);
|
|
185
|
+
const all = this.#once(`at ${tag}`, () => {
|
|
186
|
+
const by = new Map<string | null, Element>();
|
|
187
|
+
for (const it of document.getElementsByTagName(tag))
|
|
188
|
+
if (!by.has(it.getAttribute("key"))) by.set(it.getAttribute("key"), it);
|
|
189
|
+
return by;
|
|
190
|
+
});
|
|
191
|
+
return (all.get(String(key)) as T | undefined) ?? null;
|
|
192
|
+
}
|
|
152
193
|
|
|
153
194
|
// what an app may override: each is asked of an item of this collection, or of one under it
|
|
154
195
|
|
|
@@ -159,7 +200,7 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
159
200
|
/** What the page says of a field (its <j-field> in its collection's sheet, joined/kit). */
|
|
160
201
|
kind(f: Field): Asked {
|
|
161
202
|
const s = specs.find((s) => s.fields.includes(f));
|
|
162
|
-
return { ...f, ...(s ? kindOf(s.name, f.name) : {}) };
|
|
203
|
+
return { ...f, ...(s ? this.#once(`kind ${s.name} ${f.name}`, () => kindOf(s.name, f.name)) : {}) };
|
|
163
204
|
}
|
|
164
205
|
/** What a field is called: what its <j-field> says, else its name, as a label is written. A class extending this
|
|
165
206
|
* says its own words. */
|
|
@@ -190,7 +231,7 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
190
231
|
// words say themselves; anything else, what it's of
|
|
191
232
|
if (!f.to) return f.type === "string" ? String(v) : `${label} ${v}`;
|
|
192
233
|
// what it links to: by its title; people, by their faces
|
|
193
|
-
const of = (key: number) =>
|
|
234
|
+
const of = (key: number) => this.#at(f.to!.tag, key);
|
|
194
235
|
if (f.how !== "ids") return `${label} ${titled(of(v), f.to.title)}`;
|
|
195
236
|
if (!f.to.people) return `${label} ${v.length}`;
|
|
196
237
|
return el("span", { className: "faces" }, `${label} `, ...v.map((k: number) => face(k, titled(of(k)))));
|
|
@@ -267,7 +308,7 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
267
308
|
// a reference: what it points at, each a mention; popped, that thing as its own row says it
|
|
268
309
|
else if (f.ref && f.how !== "filled")
|
|
269
310
|
for (const key of [v].flat() as number[]) {
|
|
270
|
-
const to =
|
|
311
|
+
const to = this.#at<Item>(f.to!.tag, key),
|
|
271
312
|
name = titled(to, f.to!.title);
|
|
272
313
|
made(f.to!.people ? [face(key, name), name] : f.how === "ids" ? name : `${this.label(f)} ${name}`, (by) => {
|
|
273
314
|
if (to) this.refer(to, f, by);
|
|
@@ -306,7 +347,7 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
306
347
|
if (f.how === "mine") {
|
|
307
348
|
const ids: number[] = it.data[f.name] ?? [],
|
|
308
349
|
mine = this.me !== undefined && ids.includes(this.me),
|
|
309
|
-
who = ids.map((k) => titled(
|
|
350
|
+
who = ids.map((k) => titled(f.to ? this.#at(f.to.tag, k) : null));
|
|
310
351
|
const b = el("button", { type: "button", className: "act small mine", part: "mine" }, this.label(f));
|
|
311
352
|
b.append(...ids.map((k, i) => face(k, who[i]!)), el("b", {}, String(ids.length)));
|
|
312
353
|
b.ariaPressed = String(mine);
|
|
@@ -395,6 +436,11 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
395
436
|
asks(s: Spec): Field[] {
|
|
396
437
|
return askable(s);
|
|
397
438
|
}
|
|
439
|
+
/** Whether Add is offered for a collection (under an item, `under`), where the stories let this person add: an
|
|
440
|
+
* app says no where its own rules (its trust.ts) would refuse the add, so it isn't offered and then refused. */
|
|
441
|
+
adds(_s: Spec, _under?: Item): boolean {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
398
444
|
|
|
399
445
|
/** Its items, as the document has them. */
|
|
400
446
|
items() {
|
|
@@ -421,25 +467,36 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
421
467
|
/** The collection that's each member's own place for an item of this one (definitions' mine, its value a number),
|
|
422
468
|
* where the page put its element in: its spec, and the fields that say which item, whose, and where. */
|
|
423
469
|
orderBy() {
|
|
424
|
-
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
470
|
+
return this.#once("order", () => {
|
|
471
|
+
for (const s of nested) {
|
|
472
|
+
const value = s.mine && s.fields.find((f) => (f.type === "decimal" || f.type === "integer") && !f.how);
|
|
473
|
+
if (s.mine && value && this.querySelector(s.place))
|
|
474
|
+
return { s, of: s.mine.of, by: s.mine.by, value: value.name };
|
|
475
|
+
}
|
|
476
|
+
return undefined;
|
|
477
|
+
});
|
|
430
478
|
}
|
|
431
479
|
/** A member's place for an item, if they've said one; and their order: the items by their places, the rest after,
|
|
432
480
|
* as they were added. */
|
|
433
|
-
placeOf(by: number, key: number) {
|
|
481
|
+
placeOf(by: number, key: number): Item | undefined {
|
|
434
482
|
const o = this.orderBy()!;
|
|
435
|
-
return
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
483
|
+
return this.#once("place", () => {
|
|
484
|
+
const all = new Map<string, Item>();
|
|
485
|
+
for (const p of this.getElementsByTagName(o.s.tag) as HTMLCollectionOf<Item>) {
|
|
486
|
+
const whose = `${p.data[o.by]} ${p.data[o.of]}`;
|
|
487
|
+
if (!all.has(whose)) all.set(whose, p);
|
|
488
|
+
}
|
|
489
|
+
return all;
|
|
490
|
+
}).get(`${by} ${key}`);
|
|
491
|
+
}
|
|
492
|
+
orderOf(by: number): Item[] {
|
|
493
|
+
return this.#looking(() => {
|
|
494
|
+
const o = this.orderBy()!;
|
|
495
|
+
return this.items()
|
|
496
|
+
.map((it) => ({ it, at: (this.placeOf(by, it.key)?.data[o.value] as number | undefined) ?? 1e6 + it.key }))
|
|
497
|
+
.sort((a, b) => a.at - b.at)
|
|
498
|
+
.map(({ it }) => it);
|
|
499
|
+
});
|
|
443
500
|
}
|
|
444
501
|
/** Everyone who has an order of their own, me first; and what a member is called. */
|
|
445
502
|
people(): number[] {
|
|
@@ -449,18 +506,24 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
449
506
|
}
|
|
450
507
|
who(by: number) {
|
|
451
508
|
const tag = this.orderBy()!.s.fields.find((f) => f.name === this.orderBy()!.by)?.to?.tag;
|
|
452
|
-
return titled(tag ?
|
|
509
|
+
return titled(tag ? this.#at(tag, by) : null);
|
|
453
510
|
}
|
|
454
511
|
/** Whose order is shown: mine, a member's, or everyone's. */
|
|
455
512
|
shown(): number | "all" {
|
|
456
513
|
return this.whose === "all" ? "all" : this.whose || (this.me ?? 0);
|
|
457
514
|
}
|
|
458
515
|
/** Where each person puts each item, first 1: by item, then by person. */
|
|
459
|
-
places() {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
516
|
+
places(): Map<number, Map<number, number>> {
|
|
517
|
+
return this.#looking(() =>
|
|
518
|
+
this.#once("places", () => {
|
|
519
|
+
const at = new Map<number, Map<number, number>>();
|
|
520
|
+
for (const by of this.people())
|
|
521
|
+
this.orderOf(by).forEach((it, i) =>
|
|
522
|
+
(at.get(it.key) ?? at.set(it.key, new Map()).get(it.key)!).set(by, i + 1),
|
|
523
|
+
);
|
|
524
|
+
return at;
|
|
525
|
+
}),
|
|
526
|
+
);
|
|
464
527
|
}
|
|
465
528
|
/** The items in the order shown: a member's, or everyone's (each by where people put it, on average). */
|
|
466
529
|
ordered(its: Item[]) {
|
|
@@ -623,13 +686,15 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
623
686
|
}
|
|
624
687
|
/** A collection's sheet: the page's (<j-sheet for>, joined/kit), else one put on the page as it's first wanted. */
|
|
625
688
|
sheet(s: Spec) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
689
|
+
return this.#once(`sheet ${s.name}`, () => {
|
|
690
|
+
let sheet = document.querySelector<HTMLElement & { drawer?: Drawer }>(`j-sheet[for="${s.name}"]`);
|
|
691
|
+
if (!sheet) {
|
|
692
|
+
sheet = Object.assign(document.createElement("j-sheet"), { hidden: false });
|
|
693
|
+
sheet.setAttribute("for", s.name);
|
|
694
|
+
document.body.append(sheet);
|
|
695
|
+
}
|
|
696
|
+
return sheet;
|
|
697
|
+
});
|
|
633
698
|
}
|
|
634
699
|
/** A collection's drawer: its sheet's. */
|
|
635
700
|
drawer(s: Spec) {
|
|
@@ -659,6 +724,23 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
659
724
|
{ op: "add", path: `${at(f.name)}/-`, value: this.me },
|
|
660
725
|
];
|
|
661
726
|
}
|
|
727
|
+
/** A collection's items under each of this one's, by its key. */
|
|
728
|
+
#grouped(s: Spec) {
|
|
729
|
+
return this.#once(`under ${s.name}`, () => {
|
|
730
|
+
const by = new Map<number, Item[]>();
|
|
731
|
+
for (const it of this.getElementsByTagName(s.tag) as HTMLCollectionOf<Item>) {
|
|
732
|
+
const key = it.data[s.under!.field] as number,
|
|
733
|
+
its = by.get(key);
|
|
734
|
+
if (its) its.push(it);
|
|
735
|
+
else by.set(key, [it]);
|
|
736
|
+
}
|
|
737
|
+
return by;
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
/** Whether this person may add to a collection, as its element here says. */
|
|
741
|
+
#mayAdd(s: Spec) {
|
|
742
|
+
return this.#once(`add ${s.name}`, () => !!this.querySelector(`${s.place}[may~="add"]`));
|
|
743
|
+
}
|
|
662
744
|
/** A list's rows kept: each made again only as what it shows changes, the rest left as they are. */
|
|
663
745
|
#rows(list: HTMLElement, kept: Map<string, { shows: string; el: HTMLElement }>, its: Item[], inner: Spec[]) {
|
|
664
746
|
const wanted = new Set(its.map((it) => String(it.key)));
|
|
@@ -672,9 +754,7 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
672
754
|
row = () => this.row(it);
|
|
673
755
|
// what's under it: a list for each collection whose element the page put in, kept through its row's remaking
|
|
674
756
|
const under = inner.map((s, i) => {
|
|
675
|
-
const its =
|
|
676
|
-
(c) => c.data[s.under!.field] === it.key,
|
|
677
|
-
);
|
|
757
|
+
const its = this.#grouped(s).get(it.key) ?? [];
|
|
678
758
|
if (!this.#under.has(key)) this.#under.set(key, []);
|
|
679
759
|
const u = (this.#under.get(key)![i] ??= {
|
|
680
760
|
list: el("ul", { className: "under", part: "under" }),
|
|
@@ -682,7 +762,7 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
682
762
|
});
|
|
683
763
|
u.list.dataset.none = `No ${s.name} yet.`;
|
|
684
764
|
this.#rows(u.list, u.kept, its, []);
|
|
685
|
-
return { s, list: u.list, adds:
|
|
765
|
+
return { s, list: u.list, adds: this.#mayAdd(s) && this.adds(s, it) };
|
|
686
766
|
});
|
|
687
767
|
const text = (f: string | Node) => (typeof f === "string" ? f : f.textContent);
|
|
688
768
|
return {
|
|
@@ -711,6 +791,10 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
711
791
|
}
|
|
712
792
|
/** Everything drawn again from the document as it is: only what changed is made again. */
|
|
713
793
|
draw() {
|
|
794
|
+
this.#drawn();
|
|
795
|
+
this.#looking(() => this.#draw());
|
|
796
|
+
}
|
|
797
|
+
#draw() {
|
|
714
798
|
// (a collection of each member's own values for these isn't rows under them)
|
|
715
799
|
const inner = nested.filter((s) => !s.mine && this.querySelector(s.place)),
|
|
716
800
|
its = this.ordered(this.items());
|
|
@@ -728,7 +812,7 @@ export function rows(spec: Spec, items: Record<string, CustomElementConstructor>
|
|
|
728
812
|
shown += Number(is);
|
|
729
813
|
}
|
|
730
814
|
document.dispatchEvent(new CustomEvent("j-found", { detail: { for: spec.name, shown, of: its.length } }));
|
|
731
|
-
this.#add.hidden = !this.
|
|
815
|
+
this.#add.hidden = !this.#mayAdd(spec) || !this.adds(spec);
|
|
732
816
|
this.#heads();
|
|
733
817
|
// a sheet named in the address (a link to it, or Back) is put on the page to be opened
|
|
734
818
|
for (const s of specs) if (location.hash.startsWith(`#${s.one}=`)) this.sheet(s);
|