@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/settings.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// a page's write the grants allow is asked them in its transaction, and what a page may do is asked them too.
|
|
4
4
|
|
|
5
5
|
import type { Story } from "./compile.ts";
|
|
6
|
-
import type
|
|
6
|
+
import { kindFrozen, type Definitions } from "./definitions.ts";
|
|
7
7
|
import { parts, type Op } from "./ops.ts";
|
|
8
8
|
import type { Rules } from "./write.ts";
|
|
9
9
|
|
|
@@ -21,6 +21,10 @@ const KEYS = ["frozen", "waits"] as const;
|
|
|
21
21
|
const NONE: Now = { frozen: false, first: {} };
|
|
22
22
|
|
|
23
23
|
/** The collections waits names, and the first step each: its keys but by and refused. */
|
|
24
|
+
/** A kind's setting, as its definitions say it: frozen, the kind's (an item's own is said by collection, not here). */
|
|
25
|
+
const setting = (defs: Definitions, key: (typeof KEYS)[number]) =>
|
|
26
|
+
key === "frozen" ? kindFrozen(defs.frozen) : defs.waits;
|
|
27
|
+
|
|
24
28
|
const waitsFor = (waits: NonNullable<Definitions["waits"]>) =>
|
|
25
29
|
Object.entries(waits).filter(([k]) => k !== "by" && k !== "refused");
|
|
26
30
|
|
|
@@ -28,7 +32,7 @@ const waitsFor = (waits: NonNullable<Definitions["waits"]>) =>
|
|
|
28
32
|
* root (`fields`, a collection's, wherever it's held); a collection waits by its field that moves. */
|
|
29
33
|
export function settingsSaid(defs: Definitions, fields: (coll: string) => Record<string, string> | undefined) {
|
|
30
34
|
for (const key of KEYS) {
|
|
31
|
-
const s = defs
|
|
35
|
+
const s = setting(defs, key);
|
|
32
36
|
if (!s) continue;
|
|
33
37
|
if (!defs.kind) return `${key} is a kind's, its root item's setting, and there's no kind`;
|
|
34
38
|
if (typeof s.refused !== "string") return `${key} says the words a write is refused in: refused`;
|
|
@@ -44,7 +48,7 @@ export function settingsSaid(defs: Definitions, fields: (coll: string) => Record
|
|
|
44
48
|
* gives, by a story adding one so (its grant), or a held instance would take no add from anyone. */
|
|
45
49
|
export function settingsUnchecked(defs: Definitions, stories: Story[], grants: Record<string, string[]>) {
|
|
46
50
|
for (const key of KEYS)
|
|
47
|
-
if (defs
|
|
51
|
+
if (setting(defs, key) && !stories.some((s) => s.cannot && s.refused === setting(defs, key)!.refused))
|
|
48
52
|
return `${key} is checked by no story: none cannot, refused in its words`;
|
|
49
53
|
for (const [coll, first] of defs.waits ? waitsFor(defs.waits) : [])
|
|
50
54
|
if (!grants[`add ${coll}.${defs.moves![coll]}:>${first}`])
|
|
@@ -54,7 +58,8 @@ export function settingsUnchecked(defs: Definitions, stories: Story[], grants: R
|
|
|
54
58
|
|
|
55
59
|
/** generated/rules.ts's settings: none, where there are none. */
|
|
56
60
|
export function settingsCode(doc: string, defs: Definitions) {
|
|
57
|
-
const {
|
|
61
|
+
const { waits } = defs,
|
|
62
|
+
frozen = kindFrozen(defs.frozen);
|
|
58
63
|
if (!frozen && !waits) return "";
|
|
59
64
|
const settings: Settings = {
|
|
60
65
|
...(frozen && { frozen }),
|
package/src/sheet.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// <j-sheet for="items"> (joined/kit): one item of a collection, its fields as the stories hold them, in a drawer docked
|
|
2
|
+
// at the right, on a phone a sheet risen from the foot (design.md, "Three surfaces"). What's typed and picked waits for
|
|
3
|
+
// Save, one write; Never mind puts it back; Remove at its foot, asked first; a refusal is said in the story's words. It
|
|
4
|
+
// offers only what this person may change. What's open is in the address (#item=3), so Back closes it and a link opens
|
|
5
|
+
// it; a row of the collection's rows opens it, and so may anything of the page's, by show(item).
|
|
6
|
+
//
|
|
7
|
+
// <j-sheet for="items">
|
|
8
|
+
// <j-field name="name"></j-field>
|
|
9
|
+
// <j-field name="price" as="money" currency="GBP"></j-field>
|
|
10
|
+
// </j-sheet>
|
|
11
|
+
//
|
|
12
|
+
// Its <j-field>s say which fields it asks for, in their order, and how each is read (./fields.ts): none, every field
|
|
13
|
+
// a person may give it. A field's label is its name until it says its own (label="Price").
|
|
14
|
+
|
|
15
|
+
import { type Asked } from "./fields.ts";
|
|
16
|
+
import { kindOf, specOf } from "./specs.ts";
|
|
17
|
+
import { adopt, docked, said } from "./parts.ts";
|
|
18
|
+
import { Drawer, el } from "./drawer.ts";
|
|
19
|
+
import type { Answer } from "./page.ts";
|
|
20
|
+
import type { Field, Item, Spec } from "./rows.ts";
|
|
21
|
+
|
|
22
|
+
/** What names an item: its title, else its name, else its key. */
|
|
23
|
+
export const titled = (it: Element | null | undefined, title?: string) =>
|
|
24
|
+
(it && ((title && it.getAttribute(title)) || it.getAttribute("name"))) || `#${it?.getAttribute("key") ?? "?"}`;
|
|
25
|
+
/** A field's words, as a label is written. */
|
|
26
|
+
export const worded = (f: Field) => (f.name[0]!.toUpperCase() + f.name.slice(1)).replaceAll("-", " ");
|
|
27
|
+
/** The fields a person may give an item, in their order: the one that names it first; never what the server fills, a
|
|
28
|
+
* field that moves by its steps, or a list that's each member's own. */
|
|
29
|
+
export const askable = (s: Spec) => {
|
|
30
|
+
const plain = s.fields.filter((f) => !f.how || f.how === "one" || (f.how === "ids" && f.to?.people));
|
|
31
|
+
return [...plain.filter((f) => f.name === s.title), ...plain.filter((f) => f.name !== s.title)];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Ops sent from an element of the document, as the compiled elements send theirs. */
|
|
35
|
+
export const send = (from: Element, doc: string, ops: object[]) =>
|
|
36
|
+
new Promise<Answer>((answer) =>
|
|
37
|
+
from.dispatchEvent(
|
|
38
|
+
new CustomEvent("ops", {
|
|
39
|
+
bubbles: true,
|
|
40
|
+
composed: true,
|
|
41
|
+
detail: { doc: from.closest("[doc]")?.getAttribute("doc") ?? doc, ops, answer },
|
|
42
|
+
}),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
export class JSheet extends HTMLElement {
|
|
47
|
+
root = this.attachShadow({ mode: "open" });
|
|
48
|
+
#drawer?: Drawer;
|
|
49
|
+
#line = el("p", { className: "said", role: "status" });
|
|
50
|
+
#watch = new MutationObserver(() => this.#again());
|
|
51
|
+
#away = new AbortController();
|
|
52
|
+
#due = false;
|
|
53
|
+
|
|
54
|
+
/** Its drawer, once its collection is given. */
|
|
55
|
+
get drawer() {
|
|
56
|
+
return this.#drawer;
|
|
57
|
+
}
|
|
58
|
+
connectedCallback() {
|
|
59
|
+
this.#away = new AbortController();
|
|
60
|
+
specOf(this.getAttribute("for") ?? "", (s) => this.#made(s));
|
|
61
|
+
}
|
|
62
|
+
disconnectedCallback() {
|
|
63
|
+
this.#watch.disconnect();
|
|
64
|
+
this.#away.abort();
|
|
65
|
+
}
|
|
66
|
+
/** The sheet with an item in it, or a new one (given what it's added under, offered what's `filled`), or closed. */
|
|
67
|
+
show(it: Item | "new" | null, given: Record<string, number> = {}, filled: Record<string, unknown> = {}) {
|
|
68
|
+
this.#drawer?.show(it, given, filled);
|
|
69
|
+
}
|
|
70
|
+
#made(s: Spec) {
|
|
71
|
+
if (this.#drawer) return;
|
|
72
|
+
adopt(this.root);
|
|
73
|
+
const asked: Asked[] = [...this.querySelectorAll(":scope > j-field")].flatMap((j) => {
|
|
74
|
+
const f = s.fields.find((f) => f.name === j.getAttribute("name"));
|
|
75
|
+
return f ? [{ ...f, ...kindOf(s.name, f.name) }] : [];
|
|
76
|
+
});
|
|
77
|
+
const asks = asked.length ? asked : askable(s).map((f) => ({ ...f, ...kindOf(s.name, f.name) }));
|
|
78
|
+
const items = () => [...(document.getElementsByTagName(s.tag) as HTMLCollectionOf<Item>)];
|
|
79
|
+
this.#drawer = new Drawer(
|
|
80
|
+
{
|
|
81
|
+
root: this.root,
|
|
82
|
+
label: (f) => (f as Asked).label ?? worded(f),
|
|
83
|
+
title: (it) => titled(it, s.title),
|
|
84
|
+
choices: (f) =>
|
|
85
|
+
[...document.querySelectorAll(f.to!.tag)].map((t) => [Number(t.getAttribute("key")), titled(t, f.to!.title)]),
|
|
86
|
+
add: (s, value) => send(document.querySelector(s.place)!, s.doc, [{ op: "add", path: `/${s.name}/-`, value }]),
|
|
87
|
+
said: (request) => void said(this.#line, request),
|
|
88
|
+
// a drawer docked at the screen's side: the page keeps clear of it (src/page.css), said only as it changes
|
|
89
|
+
shown: () => docked(!!this.#drawer?.open),
|
|
90
|
+
},
|
|
91
|
+
s,
|
|
92
|
+
asks,
|
|
93
|
+
items,
|
|
94
|
+
this.#away.signal,
|
|
95
|
+
);
|
|
96
|
+
this.root.append(this.#line);
|
|
97
|
+
// the items it may hold, and those a link may be to, wherever they are on the page
|
|
98
|
+
this.#watch.observe(document.body, { childList: true, subtree: true, attributes: true });
|
|
99
|
+
this.#again();
|
|
100
|
+
}
|
|
101
|
+
/** The page changed: what's open follows, once a moment however much changed. */
|
|
102
|
+
#again() {
|
|
103
|
+
if (this.#due) return;
|
|
104
|
+
this.#due = true;
|
|
105
|
+
queueMicrotask(() => ((this.#due = false), this.#drawer?.refresh()));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** <j-field name="price" as="money">: what a sheet says of one field. It draws nothing of its own. */
|
|
110
|
+
export class JField extends HTMLElement {
|
|
111
|
+
connectedCallback() {
|
|
112
|
+
this.hidden = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
package/src/skill.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The door's skill (.claude/skills/joined-door): how any joined document is read and written through the MCP door,
|
|
2
|
+
// served as MCP's skills extension (SEP-2640, io.modelcontextprotocol/skills) says: its SKILL.md a resource at
|
|
3
|
+
// skill://<name>/SKILL.md, and its entry (its frontmatter as written, each file's sha256 digest and size) for
|
|
4
|
+
// skills/list and skills/get. One text, read from its file: what the door says as it opens is cut from it, never kept
|
|
5
|
+
// apart from it.
|
|
6
|
+
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
|
|
9
|
+
/** The extension's name, as a server declares it among its capabilities' extensions. */
|
|
10
|
+
export const SKILLS = "io.modelcontextprotocol/skills";
|
|
11
|
+
|
|
12
|
+
const text = await Bun.file(new URL("../.claude/skills/joined-door/SKILL.md", import.meta.url)).text();
|
|
13
|
+
const [, front = "", body = ""] = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/.exec(text) ?? [];
|
|
14
|
+
/** Its frontmatter, as YAML reads it: its name and description, and whatever else it says. */
|
|
15
|
+
const frontmatter = Bun.YAML.parse(front) as { name: string; description: string };
|
|
16
|
+
const uri = `skill://${frontmatter.name}/SKILL.md`,
|
|
17
|
+
bytes = new TextEncoder().encode(text);
|
|
18
|
+
|
|
19
|
+
/** The door's skill: its SKILL.md whole, the words below its frontmatter, and how the extension and a resource say it. */
|
|
20
|
+
export const skill = {
|
|
21
|
+
uri,
|
|
22
|
+
text,
|
|
23
|
+
body: body.trim(),
|
|
24
|
+
/** A skills/list entry, and skills/get's: its one file is its SKILL.md. */
|
|
25
|
+
entry: {
|
|
26
|
+
uri,
|
|
27
|
+
frontmatter,
|
|
28
|
+
resources: [{ uri, digest: `sha256:${createHash("sha256").update(bytes).digest("hex")}`, size: bytes.length }],
|
|
29
|
+
},
|
|
30
|
+
/** It as resources/list names it. */
|
|
31
|
+
resource: {
|
|
32
|
+
uri,
|
|
33
|
+
name: frontmatter.name,
|
|
34
|
+
description: frontmatter.description,
|
|
35
|
+
mimeType: "text/markdown",
|
|
36
|
+
size: bytes.length,
|
|
37
|
+
},
|
|
38
|
+
/** What instructions say of it to a client that loads skills itself: where it is, not what it says. */
|
|
39
|
+
pointer: `How any joined document is read and written here is the skill ${frontmatter.name} (${uri}): load it before a write.`,
|
|
40
|
+
};
|
package/src/slots.css
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* <j-slots>'s look (./slots.ts), after what readings share. With a picture: the page's drawing, each named place a
|
|
2
|
+
card's colour until its item colours it, pale where it says, the place under the pointer outlined. Without: a slot
|
|
3
|
+
for each item in a grid, its words, a dot for each thing counted of it, and a flag where one is flagged. */
|
|
4
|
+
.picture {
|
|
5
|
+
display: block;
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: auto;
|
|
8
|
+
}
|
|
9
|
+
.picture [data-slot] {
|
|
10
|
+
fill: var(--card);
|
|
11
|
+
stroke: var(--muted);
|
|
12
|
+
cursor: pointer;
|
|
13
|
+
}
|
|
14
|
+
.picture [data-slot]:hover {
|
|
15
|
+
stroke: var(--ink);
|
|
16
|
+
}
|
|
17
|
+
.picture [data-pale] {
|
|
18
|
+
fill-opacity: 0.45;
|
|
19
|
+
}
|
|
20
|
+
.slots {
|
|
21
|
+
display: grid;
|
|
22
|
+
grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(var(--size-finger) * 3)), 1fr));
|
|
23
|
+
gap: var(--space-8);
|
|
24
|
+
}
|
|
25
|
+
.slot {
|
|
26
|
+
display: grid;
|
|
27
|
+
grid-template-columns: 1fr auto;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: var(--space-6);
|
|
30
|
+
min-height: var(--size-finger);
|
|
31
|
+
padding: var(--space-8) var(--space-12);
|
|
32
|
+
border: 1px solid var(--control-edge);
|
|
33
|
+
border-radius: var(--radius);
|
|
34
|
+
background: var(--card);
|
|
35
|
+
color: var(--ink);
|
|
36
|
+
font: var(--font-title);
|
|
37
|
+
text-align: start;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
}
|
|
40
|
+
.slot:hover {
|
|
41
|
+
background: var(--card-hover);
|
|
42
|
+
}
|
|
43
|
+
.dots {
|
|
44
|
+
grid-column: 1;
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-wrap: wrap;
|
|
47
|
+
gap: var(--space-4);
|
|
48
|
+
}
|
|
49
|
+
.dot {
|
|
50
|
+
width: var(--size-dot);
|
|
51
|
+
height: var(--size-dot);
|
|
52
|
+
border-radius: var(--radius-dot);
|
|
53
|
+
background: var(--accent);
|
|
54
|
+
}
|
|
55
|
+
.flag {
|
|
56
|
+
grid-column: 2;
|
|
57
|
+
grid-row: 1 / span 2;
|
|
58
|
+
width: var(--size-pin);
|
|
59
|
+
height: var(--size-pin);
|
|
60
|
+
background: repeating-conic-gradient(var(--ink) 0 25%, var(--card) 0 50%) 0 0 / 50% 50%;
|
|
61
|
+
border: 1px solid var(--ink);
|
|
62
|
+
}
|
|
63
|
+
.tools {
|
|
64
|
+
display: flex;
|
|
65
|
+
flex-wrap: wrap;
|
|
66
|
+
gap: var(--space-8);
|
|
67
|
+
}
|
|
68
|
+
/* a group's tabs: Web Awesome's, its nav alone, a finger tall on a phone (as joined's views) */
|
|
69
|
+
.tabs::part(body) {
|
|
70
|
+
display: none;
|
|
71
|
+
}
|
|
72
|
+
.tab::part(tab) {
|
|
73
|
+
min-height: var(--size-touch);
|
|
74
|
+
padding-block: 0;
|
|
75
|
+
padding-inline: var(--space-12);
|
|
76
|
+
}
|
|
77
|
+
@media (max-width: 40rem), (pointer: coarse) {
|
|
78
|
+
.tab::part(tab) {
|
|
79
|
+
min-height: var(--size-finger);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
.tools[hidden],
|
|
83
|
+
.tabs[hidden] {
|
|
84
|
+
display: none;
|
|
85
|
+
}
|
|
86
|
+
/* its parts one above another, a space between each, as joined's page spaces what it holds; none where one is empty */
|
|
87
|
+
:host {
|
|
88
|
+
display: grid;
|
|
89
|
+
gap: var(--space-12);
|
|
90
|
+
align-content: start;
|
|
91
|
+
}
|
|
92
|
+
.said:empty {
|
|
93
|
+
display: none;
|
|
94
|
+
}
|
package/src/slots.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// <j-slots for="boats" label="sail"> (joined/kit): a collection in its slots, each item in its own place. Given a
|
|
2
|
+
// picture (<svg slot="ground">) whose places are named (data-slot="UR6 M"), each place is the item whose fields name
|
|
3
|
+
// it (slot="tooth surface"), drawn by a field (hue="status", coloured by its value; pale="material:composite"), an
|
|
4
|
+
// empty place none: a tooth's surfaces. Given none, each item is a slot of its own in a grid, its words and what's
|
|
5
|
+
// counted of it: dots="crossings", the items of that collection linking to it, a dot each, flag="finished" a flag where
|
|
6
|
+
// one of them is (a boat's laps, and its finish). group="fleet" shows one group at a time, by tabs.
|
|
7
|
+
// Tapped with tools chosen (<j-tool>), a slot is written as they say: an item added for it, or its fields set (an empty
|
|
8
|
+
// place given the fields that name it). Tapped with none, its sheet opens. What's counted is drawn, never gestured.
|
|
9
|
+
// layer="conditions" layer-by="state" layer-says="status": a place named by fewer fields (data-slot="UR6", a whole
|
|
10
|
+
// tooth around its surfaces) says that collection's items for it, each by what it is (data-crown="to do",
|
|
11
|
+
// data-root-filling="existing"), for the picture's own style to draw: a cross, a crown's ring, a root filled. A tap goes to the place under it, never to the tooth around.
|
|
12
|
+
|
|
13
|
+
import { hueOf } from "./hues.ts";
|
|
14
|
+
import { keep } from "./keep.ts";
|
|
15
|
+
import { el, Reading } from "./reading.ts";
|
|
16
|
+
import type { Item, Spec } from "./rows.ts";
|
|
17
|
+
import { specOf } from "./specs.ts";
|
|
18
|
+
import { applied, Tools } from "./tool.ts";
|
|
19
|
+
import STYLE from "./slots.css" with { type: "text" };
|
|
20
|
+
|
|
21
|
+
const SHEET = new CSSStyleSheet();
|
|
22
|
+
SHEET.replaceSync(STYLE);
|
|
23
|
+
|
|
24
|
+
export class JSlots extends Reading {
|
|
25
|
+
static override sheets = [SHEET];
|
|
26
|
+
#tools = new Tools(this);
|
|
27
|
+
#tabs = el("wa-tab-group" as "div", { className: "tabs", part: "tabs", hidden: true });
|
|
28
|
+
#grid = el("div", { className: "slots" });
|
|
29
|
+
#kept = new Map<string, { shows: string; el: HTMLElement }>();
|
|
30
|
+
#picture?: SVGSVGElement;
|
|
31
|
+
#counted?: { spec: Spec; link: string; items: HTMLCollectionOf<Item> };
|
|
32
|
+
#group: unknown;
|
|
33
|
+
/** The values the group has, in order: a tab each. */
|
|
34
|
+
#values: unknown[] = [];
|
|
35
|
+
#layer?: HTMLCollectionOf<Item>;
|
|
36
|
+
#layerSpec?: Spec;
|
|
37
|
+
|
|
38
|
+
/** The fields that name a place, in order. */
|
|
39
|
+
get #by() {
|
|
40
|
+
return (this.getAttribute("slot") ?? "").split(" ").filter(Boolean);
|
|
41
|
+
}
|
|
42
|
+
protected made() {
|
|
43
|
+
const picture = this.querySelector<SVGSVGElement>(':scope > svg[slot="ground"]');
|
|
44
|
+
if (picture) {
|
|
45
|
+
this.#picture = picture.cloneNode(true) as SVGSVGElement;
|
|
46
|
+
this.#picture.removeAttribute("slot");
|
|
47
|
+
this.#picture.classList.add("picture");
|
|
48
|
+
for (const place of this.#picture.querySelectorAll<SVGElement>("[data-slot]"))
|
|
49
|
+
this.#tap(place, place.dataset.slot!);
|
|
50
|
+
}
|
|
51
|
+
const dots = this.getAttribute("dots");
|
|
52
|
+
if (dots)
|
|
53
|
+
specOf(dots, (spec) => {
|
|
54
|
+
const link = spec.fields.find((f) => f.to?.tag === this.spec?.tag)?.name;
|
|
55
|
+
if (link)
|
|
56
|
+
this.#counted = { spec, link, items: document.getElementsByTagName(spec.tag) as HTMLCollectionOf<Item> };
|
|
57
|
+
this.again();
|
|
58
|
+
});
|
|
59
|
+
const layer = this.getAttribute("layer");
|
|
60
|
+
if (layer)
|
|
61
|
+
specOf(layer, (spec) => {
|
|
62
|
+
this.#layerSpec = spec;
|
|
63
|
+
this.#layer = document.getElementsByTagName(spec.tag) as HTMLCollectionOf<Item>;
|
|
64
|
+
this.again();
|
|
65
|
+
});
|
|
66
|
+
// a group chosen by its tab (Web Awesome's, as joined's views have them)
|
|
67
|
+
this.#tabs.addEventListener("wa-tab-show", (e) => {
|
|
68
|
+
const name = (e as CustomEvent<{ name: string }>).detail.name;
|
|
69
|
+
if (name !== String(this.#group)) ((this.#group = this.#values.find((v) => String(v) === name)), this.again());
|
|
70
|
+
});
|
|
71
|
+
this.root.append(this.#tools.bar, this.#tabs, this.#picture ?? this.#grid);
|
|
72
|
+
}
|
|
73
|
+
/** A place pressed: what the tools chosen say, or its sheet. */
|
|
74
|
+
#tap(place: Element, key: string) {
|
|
75
|
+
// the place under the pointer alone: a surface, never the tooth around it too
|
|
76
|
+
const mine = (e: Event) => (e.target as Element).closest?.("[data-slot]") === place || e.target === place;
|
|
77
|
+
place.addEventListener("pointerdown", (down) => {
|
|
78
|
+
if ((down as PointerEvent).button !== 0 || !mine(down)) return;
|
|
79
|
+
place.addEventListener("pointerup", () => void this.#act(key), { once: true });
|
|
80
|
+
});
|
|
81
|
+
place.addEventListener("click", (e) => (e as MouseEvent).detail === 0 && mine(e) && void this.#act(key));
|
|
82
|
+
}
|
|
83
|
+
async #act(key: string) {
|
|
84
|
+
const it = this.#item(key) ?? null,
|
|
85
|
+
at = Object.fromEntries(this.#by.map((f, i) => [f, key.split(" ")[i]]));
|
|
86
|
+
if (!(await applied(this, this.#tools, it, at)) && it) this.open(it);
|
|
87
|
+
}
|
|
88
|
+
/** The item in a place: by the fields that name it, or (a slot of its own) by its key. */
|
|
89
|
+
#item(key: string) {
|
|
90
|
+
return this.items().find((it) =>
|
|
91
|
+
this.#by.length ? this.#by.map((f) => it.data[f]).join(" ") === key : String(it.key) === key,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
/** What's counted of an item: those linking to it, and whether one is flagged. */
|
|
95
|
+
#count(it: Item) {
|
|
96
|
+
const c = this.#counted,
|
|
97
|
+
flag = this.getAttribute("flag");
|
|
98
|
+
const its = c ? [...c.items].filter((x) => x.isConnected && x.data[c.link] === it.key) : [];
|
|
99
|
+
return { dots: its.length, flagged: !!flag && its.some((x) => !!x.data[flag]) };
|
|
100
|
+
}
|
|
101
|
+
/** A field's value drawn as a colour: the page's (hues="to do:danger,done:accent"), else a hue by its order. */
|
|
102
|
+
#hue(value: unknown) {
|
|
103
|
+
const named = Object.fromEntries(
|
|
104
|
+
(this.getAttribute("hues") ?? "")
|
|
105
|
+
.split(",")
|
|
106
|
+
.filter(Boolean)
|
|
107
|
+
.map((p) => p.split(":").map((s) => s.trim())),
|
|
108
|
+
);
|
|
109
|
+
const seen = [...new Set(this.items().map((it) => String(it.data[this.getAttribute("hue")!])))].sort();
|
|
110
|
+
return named[String(value)] ? `var(--${named[String(value)]})` : hueOf(seen.indexOf(String(value)) + 1);
|
|
111
|
+
}
|
|
112
|
+
protected draw() {
|
|
113
|
+
this.#tools.draw();
|
|
114
|
+
if (this.#picture) return this.#drawPicture();
|
|
115
|
+
this.#drawTabs();
|
|
116
|
+
const group = this.getAttribute("group");
|
|
117
|
+
keep(
|
|
118
|
+
this.#grid,
|
|
119
|
+
this.#kept,
|
|
120
|
+
this.items()
|
|
121
|
+
.filter((it) => !group || it.data[group] === this.#group)
|
|
122
|
+
.map((it) => {
|
|
123
|
+
const { dots, flagged } = this.#count(it),
|
|
124
|
+
words = this.says(it, this.getAttribute("label") ?? "name") || this.named(it);
|
|
125
|
+
return {
|
|
126
|
+
key: String(it.key),
|
|
127
|
+
shows: JSON.stringify([words, dots, flagged, this.opened(it)]),
|
|
128
|
+
make: () => {
|
|
129
|
+
const b = el(
|
|
130
|
+
"button",
|
|
131
|
+
{ type: "button", className: "slot" },
|
|
132
|
+
el("span", { className: "label", textContent: words }),
|
|
133
|
+
el(
|
|
134
|
+
"span",
|
|
135
|
+
{ className: "dots" },
|
|
136
|
+
...Array.from({ length: dots }, () => el("span", { className: "dot" })),
|
|
137
|
+
),
|
|
138
|
+
);
|
|
139
|
+
if (flagged) b.append(el("span", { className: "flag", ariaLabel: "Finished" }));
|
|
140
|
+
b.dataset.key = String(it.key);
|
|
141
|
+
b.ariaLabel = `${words}: ${dots}${flagged ? ", finished" : ""}`;
|
|
142
|
+
this.#tap(b, String(it.key));
|
|
143
|
+
return b;
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}),
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
/** One group at a time, by tabs: each value its field has, the first chosen. */
|
|
150
|
+
#drawTabs() {
|
|
151
|
+
const group = this.getAttribute("group"),
|
|
152
|
+
f = group ? this.field("group") : undefined;
|
|
153
|
+
this.#tabs.hidden = !f;
|
|
154
|
+
if (!f) return;
|
|
155
|
+
const values = (this.#values = [...new Set(this.items().map((it) => it.data[f.name]))]);
|
|
156
|
+
if (!values.includes(this.#group)) this.#group = values[0];
|
|
157
|
+
const words = (v: unknown) =>
|
|
158
|
+
f.to
|
|
159
|
+
? (document.querySelector(`${f.to.tag}[key="${v}"]`)?.getAttribute(f.to.title ?? "name") ?? `#${v}`)
|
|
160
|
+
: String(v);
|
|
161
|
+
// a tab each, made again only when the values change
|
|
162
|
+
const said = values.map((v) => `${v}:${words(v)}`).join();
|
|
163
|
+
if (this.#tabs.dataset.shows !== said) {
|
|
164
|
+
this.#tabs.dataset.shows = said;
|
|
165
|
+
this.#tabs.replaceChildren(
|
|
166
|
+
...values.map((v) => {
|
|
167
|
+
const t = el("wa-tab" as "div", { slot: "nav", className: "tab", textContent: words(v) });
|
|
168
|
+
t.setAttribute("panel", String(v));
|
|
169
|
+
return t;
|
|
170
|
+
}),
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
this.#tabs.setAttribute("active", String(this.#group));
|
|
174
|
+
}
|
|
175
|
+
/** Each named place as its item has it: coloured by its field, pale where it says, nothing where it's empty. */
|
|
176
|
+
#drawPicture() {
|
|
177
|
+
const hue = this.getAttribute("hue"),
|
|
178
|
+
[paleField, paleValue] = (this.getAttribute("pale") ?? "").split(":");
|
|
179
|
+
for (const place of this.#picture!.querySelectorAll<SVGElement>("[data-slot]")) {
|
|
180
|
+
if (place.dataset.slot!.split(" ").length < this.#by.length) {
|
|
181
|
+
this.#drawLayer(place);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const it = this.#item(place.dataset.slot!),
|
|
185
|
+
value = it && hue ? it.data[hue] : undefined;
|
|
186
|
+
place.toggleAttribute("data-filled", !!it);
|
|
187
|
+
if (value === undefined) (place.removeAttribute("data-hue"), place.style.removeProperty("fill"));
|
|
188
|
+
else (place.setAttribute("data-hue", String(value)), place.style.setProperty("fill", this.#hue(value)));
|
|
189
|
+
place.toggleAttribute("data-pale", !!it && !!paleField && String(it.data[paleField]) === paleValue);
|
|
190
|
+
place.setAttribute("aria-label", `${place.dataset.slot}${value === undefined ? "" : `: ${value}`}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** A whole thing's place (a tooth around its surfaces), its layer's item said on it, field by field. */
|
|
194
|
+
#drawLayer(place: SVGElement) {
|
|
195
|
+
const parts = place.dataset.slot!.split(" "),
|
|
196
|
+
fields = this.#by.slice(0, parts.length),
|
|
197
|
+
its = [...(this.#layer ?? [])].filter((x) => x.isConnected && fields.every((f, i) => x.data[f] === parts[i])),
|
|
198
|
+
by = this.getAttribute("layer-by"),
|
|
199
|
+
says = this.getAttribute("layer-says");
|
|
200
|
+
// several items of a thing, each by what it is (layer-by="state"): one attribute each, data-crown="to do",
|
|
201
|
+
// data-root-filling="existing", so a tooth crowned and root filled says both; else its one item, field by field
|
|
202
|
+
const now: Record<string, string> = {};
|
|
203
|
+
if (by && says) for (const x of its) now[`data-${String(x.data[by]).replaceAll(" ", "-")}`] = String(x.data[says]);
|
|
204
|
+
else
|
|
205
|
+
for (const f of this.#layerSpec?.fields ?? [])
|
|
206
|
+
if (!fields.includes(f.name) && its[0]?.data[f.name] != null)
|
|
207
|
+
now[`data-${f.name}`] = String(its[0].data[f.name]);
|
|
208
|
+
for (const name of (place.dataset.layered ?? "").split(" ").filter(Boolean))
|
|
209
|
+
if (!(name in now)) place.removeAttribute(name);
|
|
210
|
+
for (const [name, v] of Object.entries(now)) place.setAttribute(name, v);
|
|
211
|
+
place.dataset.layered = Object.keys(now).join(" ");
|
|
212
|
+
}
|
|
213
|
+
}
|
package/src/specs.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// The collections joined's kit (./kit.ts) is bound to, each by its name: the compiler's (generated/rows.ts `specs`),
|
|
2
|
+
// given once by use(), or by joined/rows' define() for the rows it draws; and what the page says of a field, by its
|
|
3
|
+
// <j-field> in the collection's sheet.
|
|
4
|
+
|
|
5
|
+
import type { Kind } from "./fields.ts";
|
|
6
|
+
import type { Spec } from "./rows.ts";
|
|
7
|
+
|
|
8
|
+
/** Every collection the page has been given, by its name. */
|
|
9
|
+
const specs = new Map<string, Spec>();
|
|
10
|
+
/** Collections waited for by a part put on the page before they were given. */
|
|
11
|
+
const waiting = new Map<string, ((s: Spec) => void)[]>();
|
|
12
|
+
|
|
13
|
+
/** The page's collections, given once: each part finds its own by name. */
|
|
14
|
+
export function use(...given: (Spec | Record<string, Spec>)[]) {
|
|
15
|
+
for (const g of given)
|
|
16
|
+
for (const s of "fields" in g ? [g as Spec] : Object.values(g as Record<string, Spec>)) {
|
|
17
|
+
specs.set(s.name, s);
|
|
18
|
+
for (const ready of waiting.get(s.name) ?? []) ready(s);
|
|
19
|
+
waiting.delete(s.name);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** A collection by its name, as soon as it's given. */
|
|
23
|
+
export function specOf(name: string, ready: (s: Spec) => void) {
|
|
24
|
+
const s = specs.get(name);
|
|
25
|
+
if (s) return ready(s);
|
|
26
|
+
waiting.set(name, [...(waiting.get(name) ?? []), ready]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** What the page says of a field (its <j-field> in the collection's sheet): its words and how it's read. */
|
|
30
|
+
export function kindOf(collection: string, field: string): Kind {
|
|
31
|
+
const f = document.querySelector(`j-sheet[for="${collection}"] > j-field[name="${field}"]`);
|
|
32
|
+
if (!f) return {};
|
|
33
|
+
return Object.fromEntries(
|
|
34
|
+
(["label", "as", "currency", "readonly"] as const).flatMap((k) =>
|
|
35
|
+
f.hasAttribute(k) ? [[k, k === "readonly" ? true : f.getAttribute(k)!]] : [],
|
|
36
|
+
),
|
|
37
|
+
) as Kind;
|
|
38
|
+
}
|
package/src/starter.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// An app's folder, begun and kept up: `joined init` puts in a folder (a project taking joined as its dependency) what
|
|
2
2
|
// an app on joined starts from, never over what's there, and `joined upgrade` moves joined to another version.
|
|
3
3
|
// init hello (examples/hello, anyone's, no sign-in) in apps/, the apps' look, the skill, a CLAUDE.md, a
|
|
4
|
-
// .gitignore, a tsconfig, tests telling hello's stories (and its page's, in a browser), the scripts; then
|
|
4
|
+
// .gitignore, bun fmt's settings (never what the compiler writes), a tsconfig, tests telling hello's stories (and its page's, in a browser), the scripts; then
|
|
5
5
|
// compiled
|
|
6
6
|
// upgrade joined at another version (the newest, a version, or any spec Bun takes: a tarball), the skill
|
|
7
7
|
// refreshed from it, and the apps compiled by it
|
|
@@ -23,7 +23,8 @@ import page from "./index.html";
|
|
|
23
23
|
export * as document from "./generated/rules.ts";
|
|
24
24
|
export const routes = { "/": page, "/hello": page };
|
|
25
25
|
`;
|
|
26
|
-
/** What an app's folder starts from: each file, from joined's (or written here), to the app's.
|
|
26
|
+
/** What an app's folder starts from: each file, from joined's (or written here), to the app's. A dotfile, or a bunfig.toml,
|
|
27
|
+
* is kept under another name, as a pack leaves those out. */
|
|
27
28
|
const STARTER: [string | { text: string }, string][] = [
|
|
28
29
|
...["stories.jsonl", "hello.json", "index.html", "page.ts", "hello.css"].map((f): [string, string] => [
|
|
29
30
|
`examples/hello/${f}`,
|
|
@@ -35,6 +36,8 @@ const STARTER: [string | { text: string }, string][] = [
|
|
|
35
36
|
[".claude/skills/joined/reference.md", ".claude/skills/joined/reference.md"],
|
|
36
37
|
["starter/CLAUDE.md", "CLAUDE.md"],
|
|
37
38
|
["starter/gitignore", ".gitignore"],
|
|
39
|
+
["starter/bunfig", "bunfig.toml"],
|
|
40
|
+
["starter/prettierignore", ".prettierignore"],
|
|
38
41
|
["starter/tsconfig.json", "tsconfig.json"],
|
|
39
42
|
["starter/tests/hello.test.ts", "tests/hello.test.ts"],
|
|
40
43
|
["starter/tests/hello-page.test.ts", "tests/hello-page.test.ts"],
|