@blueshed/joined 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/joined/SKILL.md +9 -1
- package/.claude/skills/joined/reference.md +316 -63
- package/.claude/skills/joined-door/SKILL.md +57 -0
- package/README.md +19 -50
- package/docs/design.md +158 -37
- package/docs/introduction.md +27 -27
- package/docs/light-and-shadow.svg +2 -1
- 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/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 +11 -1
- package/examples/cafe/books.html +2 -2
- package/examples/cafe/cafe.css +96 -85
- 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.elements.ts +7 -2
- package/examples/cafe/generated/staff.rows.ts +22 -0
- package/examples/cafe/generated/staff.rules.ts +9 -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 +17 -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.css +11 -19
- package/examples/cafe/kitchen.ts +7 -3
- package/examples/cafe/look.ts +30 -0
- package/examples/cafe/menu.html +10 -26
- package/examples/cafe/menu.ts +8 -80
- package/examples/cafe/migrations/002-guard-supplies.ts +15 -0
- package/examples/cafe/order.html +8 -7
- package/examples/cafe/order.ts +6 -2
- package/examples/cafe/routes.ts +0 -1
- package/examples/cafe/staff.json +5 -0
- package/examples/cafe/stories.jsonl +6 -2
- package/examples/cafe/supplies.html +35 -34
- package/examples/cafe/supplies.ts +59 -39
- package/examples/cafe/till.ts +19 -11
- package/examples/cafe/views.ts +7 -5
- package/examples/chart/arches.ts +150 -0
- package/examples/chart/chart.css +11 -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/desk.css +6 -10
- package/examples/desk/generated/elements.ts +1 -1
- package/examples/desk/generated/rows.ts +22 -0
- package/examples/desk/generated/rules.ts +34 -1
- package/examples/desk/index.html +10 -3
- package/examples/desk/lanes.css +21 -19
- package/examples/desk/routes.ts +0 -2
- package/examples/desk/stories.jsonl +4 -3
- package/examples/desk/tally.css +1 -1
- package/examples/desk/thumbs.ts +2 -2
- package/examples/docs.ts +7 -4
- 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 +20 -12
- package/examples/notes/generated/elements.ts +112 -0
- package/examples/notes/generated/queries.ts +42 -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 +24 -0
- package/examples/page.ts +9 -2
- package/examples/people/generated/rows.ts +22 -0
- package/examples/people/generated/rules.ts +11 -1
- package/examples/people/links.ts +8 -9
- package/examples/people/people.css +1 -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 +5 -3
- 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 +13 -13
- 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/elements.ts +1 -1
- 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/trips/trips.css +24 -23
- 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 +43 -33
- package/package.json +8 -2
- package/src/attachment.ts +17 -2
- package/src/awesome.ts +103 -0
- package/src/board.css +76 -0
- package/src/board.ts +173 -0
- package/src/cli.ts +28 -3
- package/src/compile.ts +821 -109
- package/src/definitions.ts +113 -27
- package/src/demo.css +2 -5
- package/src/draft.ts +48 -27
- package/src/drawer.ts +248 -0
- package/src/engine.ts +253 -170
- package/src/fields.ts +341 -0
- package/src/file-value.ts +12 -2
- package/src/files.ts +113 -33
- package/src/ground.ts +110 -0
- package/src/icon-names.ts +19 -2
- package/src/keep.ts +16 -3
- package/src/kit.ts +51 -0
- package/src/link.ts +3 -3
- package/src/map.css +140 -0
- package/src/map.ts +200 -0
- package/src/mcp.ts +129 -24
- 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 +105 -55
- package/src/members/keys.ts +95 -79
- package/src/members/panel.css +40 -35
- package/src/members/panel.ts +58 -37
- package/src/migrate.ts +178 -125
- package/src/migrations/005-change-kept.ts +7 -0
- package/src/month.css +129 -0
- package/src/month.ts +179 -0
- package/src/ops.ts +40 -1
- package/src/page.css +11 -2
- package/src/page.ts +68 -17
- package/src/parts.css +614 -230
- package/src/parts.ts +259 -36
- package/src/plane.css +61 -0
- package/src/plane.ts +153 -0
- package/src/postgres-server.ts +60 -0
- package/src/reading.css +73 -0
- package/src/reading.ts +238 -0
- package/src/rows.css +289 -0
- package/src/rows.ts +864 -0
- package/src/search.css +80 -0
- package/src/search.ts +130 -0
- package/src/server.ts +355 -137
- package/src/settings.ts +9 -4
- package/src/sheet.ts +116 -0
- package/src/skill.ts +40 -0
- package/src/slots.css +90 -0
- package/src/slots.ts +213 -0
- package/src/specs.ts +38 -0
- package/src/starter.ts +19 -2
- package/src/store.ts +224 -161
- package/src/stories.ts +43 -11
- package/src/surface.ts +164 -0
- package/src/time.ts +2 -0
- package/src/timeline.css +111 -0
- package/src/timeline.ts +235 -0
- package/src/toast.ts +21 -48
- package/src/together.ts +15 -24
- package/src/tokens.css +89 -3
- package/src/tokens.json +287 -7
- package/src/tool.ts +210 -0
- package/src/upkeep.ts +47 -22
- package/src/views.css +43 -0
- package/src/views.ts +111 -0
- package/src/week.css +150 -0
- package/src/week.ts +254 -0
- package/src/write.ts +326 -78
- package/starter/CHANGELOG.md +8 -0
- package/starter/CLAUDE.md +9 -3
- package/starter/bunfig +5 -0
- package/starter/githooks/pre-commit +13 -0
- package/starter/prettierignore +5 -0
- package/starter/tests/hello.test.ts +2 -0
- package/starter/tests/records.test.ts +40 -0
- package/starter/todo.jsonl +0 -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/definitions.ts
CHANGED
|
@@ -1,24 +1,43 @@
|
|
|
1
1
|
// An app's definitions (its stories.jsonl's header lines): what its stories can't show, read by the compiler alone and
|
|
2
|
-
// written into its generated/rules.ts as plain code, so nothing reads them as it runs (
|
|
3
|
-
// definitions"). Each key is optional, a line of its own.
|
|
2
|
+
// written into its generated/rules.ts as plain code, so nothing reads them as it runs (the skill's §15). Each key is optional, a line of its own.
|
|
4
3
|
//
|
|
5
4
|
// links a field that links though it isn't named for its collection: { organisers: "members" }, a list;
|
|
6
5
|
// { account: { to: "accounts", one: true } }, one id. Its own document's collection, or another's.
|
|
7
6
|
// { post: { to: "posts", one: true, gone: "with" } }: removing the post removes what links to it, as ops
|
|
7
|
+
// { order: { to: "orders", one: true, part: true } }: structure, not a reference (is a, has a, composition):
|
|
8
|
+
// what the item is part of, one id. A page places it by that and never pops it (docs/design.md, "A peek");
|
|
9
|
+
// a link that goes with what it points at is part of it too. Any other link is a reference, and pops.
|
|
10
|
+
// { supplier: { to: "members", one: true, holds: "staff/posts[role=supplier]@members" } }: whoever it
|
|
11
|
+
// names is one a who-path of collections finds (no role, no @field: it's asked of them, not the writer),
|
|
12
|
+
// refused "supplier names someone who isn't among staff's posts with role supplier", checked by a cannot
|
|
8
13
|
// roles who someone is to the document, beyond a member, each a who-path to them.
|
|
14
|
+
// title the field that names a collection's items, where it isn't the first field of words: { accounts: "name" }
|
|
9
15
|
// owns who sees what: a who-path for the whole document, or one per collection (a collection not named
|
|
10
16
|
// is everyone's). A page is sent, and told of, only the items its person sees.
|
|
11
17
|
// kind { root: "shelves" }: a document for each item of another document's collection (shelf:1,
|
|
12
18
|
// shelf:2), its collections each instance's own; a role's @field is that root item's, or the item's a write
|
|
13
|
-
// is to where it has that field (a post's author).
|
|
19
|
+
// is to where it has that field (a post's author). `files: "apart"` keeps each instance's files in a folder of
|
|
20
|
+
// its own (book-1/), served only to who may hold it, and handed back with it (/export/book-1).
|
|
14
21
|
// fills a field the server fills on every add, and only the server writes (a route's write, a reaction):
|
|
15
|
-
// { cards: { added: "now" }, boards: { count: 0 } }; "now" is the instant it's added, "me" its writer.
|
|
22
|
+
// { cards: { added: "now" }, boards: { count: 0 } }; "now" is the instant it's added, "me" its writer. Where
|
|
23
|
+
// the seed gives the field wall clocks (2026-07-01T12:41:07, no Z), "now" is one: on the clock of the item's
|
|
24
|
+
// own zone (its field named zone, a time zone), else its kind's root's, else the document's own (/zone).
|
|
16
25
|
// unique fields no two items of a collection share: { people: ["name"] }, or several together
|
|
17
26
|
// ({ rooms: [["hotel", "name"]] }); an item without one is held to nothing.
|
|
18
27
|
// noOverlap a collection's items that may not hold one time: { stays: { range: ["from", "until"], same:
|
|
19
28
|
// ["room"] } }, among those whose same fields are equal (none: all of them). A range is half
|
|
20
29
|
// open, from its start until its end, a time or a number, or a duration on from a time; an
|
|
21
30
|
// item without a start or an end is open on that side.
|
|
31
|
+
// mine a list of members that's each member's own: { tasks: ["ups"] }, a member gives and takes only their own
|
|
32
|
+
// id in it, whoever the grants allow; several together ({ tasks: [["ups", "downs"]] }), and nobody is in two
|
|
33
|
+
// of them on one item (a thumb up or down; a vote).
|
|
34
|
+
// Or a collection of values, each one member's for one item of another: { ranks: { of: "note", by: "by" } },
|
|
35
|
+
// my place for a note, my rating, my word on it. `of` is the link to the item (one id), `by` the link to
|
|
36
|
+
// its member (one id), which the server fills with its writer; a member has one for an item at most, and
|
|
37
|
+
// only they change or remove theirs, whoever the grants allow. Everyone sees them (the skill's reference, §15).
|
|
38
|
+
// Or a link to one member, each member's own to say ({ people: ["member"] }: which person you are, as
|
|
39
|
+
// yourself), set only to its writer, and taken back only by them. A field with its own words, refused in them:
|
|
40
|
+
// { people: [{ member: "you say which person you are, as yourself" }] }.
|
|
22
41
|
// window a part of a collection a page may hold alone, by a parameter of its query and its topic
|
|
23
42
|
// (trip?week=2026-11-02): { events: { week: { from: "start", for: "P7D" } } }, the items whose start is
|
|
24
43
|
// in the days from it; with a length too ({ ..., length: "duration" }), those whose time overlaps them; { products: { category: "category" } }, those whose field is it.
|
|
@@ -29,7 +48,17 @@
|
|
|
29
48
|
// timed a field whose time, an instant, comes: { cards: "due" }. Then the server clears it, as its own
|
|
30
49
|
// write, told and reacted to as any is (a clock's next tick is a reaction setting it again).
|
|
31
50
|
// frozen { by: "frozen", refused: "…" }: in a kind, while the root item's field is true, its instance is kept as it
|
|
32
|
-
// is: every page's write refused in those words (src/settings.ts).
|
|
51
|
+
// is: every page's write refused in those words (src/settings.ts). Or an item kept as it is once it's
|
|
52
|
+
// settled, by its own yes-or-no field: { supplies: { by: "delivered", fields: ["price", "terms"], refused:
|
|
53
|
+
// "…" } }, those fields (none named: all of them) changed by no write while it's true (a trigger).
|
|
54
|
+
// addedWith an item added only in the write adding what a link of it points at, never after: { lines: { order:
|
|
55
|
+
// "an order's lines are set when it's placed" } } (a trigger, in those words).
|
|
56
|
+
// within a list's ids each in another list of the same item: { events: [{ lists: ["keen", "asked"], of: "people",
|
|
57
|
+
// refused: "…" }] }, held as the write leaves it (SQLite's by code, Postgres's by a trigger at its end).
|
|
58
|
+
// apart lists of an item no id is in two of: { events: [{ lists: ["keen", "asked", "declined"], refused: "…" }] },
|
|
59
|
+
// held as within is.
|
|
60
|
+
// notEmpty fields of words that are never none, nor only spaces: { notes: ["text"] }, refused "text cannot be empty"
|
|
61
|
+
// (a trigger). One a store holds already, from before it was said, is left until it's changed.
|
|
33
62
|
// waits { by: "moderated", posts: "waiting", refused: "…" }: in a kind, while the root item's field is true, an
|
|
34
63
|
// add to posts gives its field that moves (moves) as that first step, or it's refused in those words.
|
|
35
64
|
//
|
|
@@ -45,14 +74,18 @@ import type { Op } from "./ops.ts";
|
|
|
45
74
|
|
|
46
75
|
/** An app's definitions, as its stories' header lines say them, one a key. */
|
|
47
76
|
export type Definitions = {
|
|
48
|
-
links?: Record<string, string | { to: string; one?: true; gone?: "with" }>;
|
|
77
|
+
links?: Record<string, string | { to: string; one?: true; gone?: "with"; part?: true; holds?: string }>;
|
|
49
78
|
roles?: Record<string, string>;
|
|
79
|
+
/** Each collection's field that names an item (in a row, a chooser, a peek), where it isn't the first field of words
|
|
80
|
+
* the stories give: { accounts: "name" }, not its code. */
|
|
81
|
+
title?: Record<string, string>;
|
|
50
82
|
owns?: string | Record<string, string>;
|
|
51
|
-
kind?: { root: string };
|
|
83
|
+
kind?: { root: string; files?: "apart" };
|
|
52
84
|
fills?: Record<string, Record<string, unknown>>;
|
|
53
85
|
timed?: Record<string, string>;
|
|
54
86
|
unique?: Record<string, (string | string[])[]>;
|
|
55
87
|
noOverlap?: Record<string, { range: [string, string]; same?: string[] }>;
|
|
88
|
+
mine?: Record<string, (string | string[] | Record<string, string>)[] | { of: string; by: string }>;
|
|
56
89
|
window?: Record<string, Record<string, string | { from: string; for: string; length?: string }>>;
|
|
57
90
|
order?: Record<string, string>;
|
|
58
91
|
copies?: Record<string, { from: string; fields: string[] }>;
|
|
@@ -72,12 +105,27 @@ export type Definitions = {
|
|
|
72
105
|
where?: Record<string, Record<string, Where | Where[] | string>>;
|
|
73
106
|
/** In a kind, a yes-or-no field of the root item: while it's true, every page's write to its instance is refused, in
|
|
74
107
|
* these words (a frozen board). src/settings.ts. */
|
|
75
|
-
frozen?: { by: string; refused: string }
|
|
108
|
+
frozen?: { by: string; refused: string } | Record<string, Frozen>;
|
|
109
|
+
/** An item added only in the write adding what a link of it points at, never after: by collection, each link and
|
|
110
|
+
* the words a later add is refused in (an order's lines). */
|
|
111
|
+
addedWith?: Record<string, Record<string, string>>;
|
|
112
|
+
/** A list's ids each in another list of the same item (an answer from someone on the event): by collection. */
|
|
113
|
+
within?: Record<string, { lists: string[]; of: string; refused: string }[]>;
|
|
114
|
+
/** Lists of an item no id is in two of (one answer each): by collection. */
|
|
115
|
+
apart?: Record<string, { lists: string[]; refused: string }[]>;
|
|
116
|
+
/** Fields of words that are never none, nor only spaces: by collection. */
|
|
117
|
+
notEmpty?: Record<string, string[]>;
|
|
76
118
|
/** In a kind, a yes-or-no field of the root item: while it's true, an add to each collection named gives its field
|
|
77
119
|
* that moves as this first step, or it's refused in these words (a board held for approval, a post waiting).
|
|
78
120
|
* src/settings.ts. */
|
|
79
121
|
waits?: { by: string; refused: string; [coll: string]: string };
|
|
80
122
|
};
|
|
123
|
+
/** An item kept as it is once it's settled (definitions' frozen, by collection): while its own yes-or-no field (`by`)
|
|
124
|
+
* is true, its fields (`fields`; none named, all of them) are changed by no write, refused in these words. */
|
|
125
|
+
export type Frozen = { by: string; fields?: string[]; refused: string };
|
|
126
|
+
/** A kind's frozen (its root item's field), or none: the other is an item's own, by collection. */
|
|
127
|
+
export const kindFrozen = (f: Definitions["frozen"]) =>
|
|
128
|
+
f && typeof f.by === "string" ? (f as { by: string; refused: string }) : undefined;
|
|
81
129
|
/** Which rows of a collection a document holds (definitions' where): those whose fields are each the value given,
|
|
82
130
|
* or one of the values; with `last`, the newest so many by a field (`by`). Several: any of them. A collection's
|
|
83
131
|
* name in their place: the rows linking to those its document holds of that one (an order's lines). `holds`, a
|
|
@@ -86,16 +134,20 @@ export type Where = { [field: string]: unknown; last?: number; by?: string };
|
|
|
86
134
|
/** A read-only document over an app's entities, by member (each side's books): a collection each, its items the rows
|
|
87
135
|
* of a table one of whose fields names the member (`sides`, each said as a word), those with `when` true; each with
|
|
88
136
|
* some of its fields, and its total: the sum of a field of the rows naming it, each times another of theirs. */
|
|
89
|
-
export type Query = Record<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
137
|
+
export type Query = Record<string, Sided | Counted>;
|
|
138
|
+
/** A collection of a read-only document: the rows naming the member, each with some of its fields and its total. */
|
|
139
|
+
export type Sided = {
|
|
140
|
+
from: string;
|
|
141
|
+
when?: string;
|
|
142
|
+
sides: Record<string, string>;
|
|
143
|
+
fields: string[];
|
|
144
|
+
total: { sum: string; times?: string };
|
|
145
|
+
};
|
|
146
|
+
/** A collection of a read-only document counting rows by what they link to and the week they're in (each trip's
|
|
147
|
+
* weeks): the rows of `from`, those whose item a link of theirs points at (`by`: the link, and the table it's to) names
|
|
148
|
+
* the member in one of its lists (`seen`), by that item and the Monday of the week a date and time of theirs is in
|
|
149
|
+
* (`week`), how many each (`count`); numbered in that order. Its items: id, the link, week and the count. */
|
|
150
|
+
export type Counted = { from: string; by: Record<string, string>; seen: string[]; week: string; count: string };
|
|
99
151
|
/** A rule over values: a collection's field taken from a field of what a link of it points at, while a field of
|
|
100
152
|
* what another of its links points at is true (an item's quantity from its product's stock, while its order is
|
|
101
153
|
* placed): `{ items: { quantity: "product.stock", while: "order.placed", refused: "…" } }`. Taken or given back as
|
|
@@ -106,21 +158,47 @@ export type Takes = { while: string; refused: string } & Record<string, string>;
|
|
|
106
158
|
* each of its lines' qty times its price. */
|
|
107
159
|
export type Total = { of: string; by: string; sum: string; times?: string };
|
|
108
160
|
|
|
109
|
-
|
|
161
|
+
/** A who-path of collections in words (links' holds): "staff's posts with role supplier". */
|
|
162
|
+
export const pathSaid = (path: string) =>
|
|
163
|
+
path
|
|
164
|
+
.split("|")
|
|
165
|
+
.map((t) => {
|
|
166
|
+
const [, of, coll, not, field, value] = t.trim().match(TERM) ?? [];
|
|
167
|
+
return `${of ? `${of}'s ` : ""}${coll}${field ? (not ? ` with no ${field}` : ` with ${field} ${value}`) : ""}`;
|
|
168
|
+
})
|
|
169
|
+
.join(" or ");
|
|
170
|
+
export const TERM =
|
|
110
171
|
/^(?:([a-z][a-z0-9-]*)\/)?([a-z][a-z0-9-]*)(?:\[(!?)([a-z][a-z0-9-]*)(?:=([^\]]+))?\])?(?:@([a-z][a-z0-9-]*))?$/;
|
|
111
172
|
|
|
112
|
-
/**
|
|
113
|
-
*
|
|
173
|
+
/** The roles named on the way to a role named in a who-path, it last (`seen`, those before it); refused where it's
|
|
174
|
+
* one of them, as a role can't be itself. */
|
|
175
|
+
const onTo = (role: string, seen: string[], where: string) => {
|
|
176
|
+
if (seen.includes(role))
|
|
177
|
+
throw new Error(
|
|
178
|
+
`${where}: the role ${role} names itself (${[...seen.slice(seen.indexOf(role)), role].join(" → ")})`,
|
|
179
|
+
);
|
|
180
|
+
return [...seen, role];
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/** A who-path as a JavaScript expression of m (the member), item, read and doc (this document), true when m
|
|
184
|
+
* is one of them: a role in it, that role's who-path (`roles`, each by name; `seen`, those named on the way to it);
|
|
185
|
+
* `item` the item a role's @field is of. In a kind (`kind`), `item` is the root's `item` the item a role's @field is of. In a kind (`kind`), `item` is the root's
|
|
114
186
|
* and `at` the item a write is to: an @field is the item's where it has that field (a post's author), else the root's
|
|
115
187
|
* (the board's owners). */
|
|
116
|
-
export function whoCode(
|
|
188
|
+
export function whoCode(
|
|
189
|
+
path: string,
|
|
190
|
+
roles: Record<string, string>,
|
|
191
|
+
where: string,
|
|
192
|
+
kind = false,
|
|
193
|
+
seen: string[] = [],
|
|
194
|
+
): string {
|
|
117
195
|
const names = (v: string) => `(${v} === m || (Array.isArray(${v}) && ${v}.includes(m)))`;
|
|
118
196
|
return path
|
|
119
197
|
.split("|")
|
|
120
198
|
.map((t) => t.trim())
|
|
121
199
|
.map((t) => {
|
|
122
200
|
if (t === "member") return "true";
|
|
123
|
-
if (roles
|
|
201
|
+
if (roles[t] !== undefined) return `(${whoCode(roles[t], roles, where, kind, onTo(t, seen, where))})`;
|
|
124
202
|
if (/^@[a-z][a-z0-9-]*$/.test(t)) {
|
|
125
203
|
const f = JSON.stringify(t.slice(1));
|
|
126
204
|
return kind
|
|
@@ -151,7 +229,15 @@ export type WhoOf = {
|
|
|
151
229
|
};
|
|
152
230
|
/** A who-path as SQL of a row (`at`, of collection `coll`): true when $member is one of them. The same path its code
|
|
153
231
|
* is written from (whoCode), so the query holds what's asked of an item. A role's @field is its kind's root item's. */
|
|
154
|
-
export function whoSql(
|
|
232
|
+
export function whoSql(
|
|
233
|
+
path: string,
|
|
234
|
+
coll: string,
|
|
235
|
+
at: string,
|
|
236
|
+
who: WhoOf,
|
|
237
|
+
where: string,
|
|
238
|
+
root = false,
|
|
239
|
+
seen: string[] = [],
|
|
240
|
+
): string {
|
|
155
241
|
const q = (n: string) => `"${n.replaceAll('"', '""')}"`;
|
|
156
242
|
const names = (c: string, a: string, f: string) =>
|
|
157
243
|
who.list(c, f)
|
|
@@ -162,7 +248,7 @@ export function whoSql(path: string, coll: string, at: string, who: WhoOf, where
|
|
|
162
248
|
.map((t) => t.trim())
|
|
163
249
|
.map((t) => {
|
|
164
250
|
if (t === "member") return "TRUE";
|
|
165
|
-
if (who.roles[t]) return `(${whoSql(who.roles[t]!, coll, at, who, where, true)})`;
|
|
251
|
+
if (who.roles[t]) return `(${whoSql(who.roles[t]!, coll, at, who, where, true, onTo(t, seen, where))})`;
|
|
166
252
|
if (/^@[a-z][a-z0-9-]*$/.test(t)) {
|
|
167
253
|
const f = t.slice(1);
|
|
168
254
|
// in a role of a kind, the root item's field
|
|
@@ -210,7 +296,7 @@ export function whoRules(
|
|
|
210
296
|
const where = `${doc}'s definitions`;
|
|
211
297
|
const k = defs.kind;
|
|
212
298
|
let out = k
|
|
213
|
-
? `\n/** ${doc} is one of many: a document for each of ${root}'s ${k.root} (${doc}:1), its items each kept with it. */\nexport const kind = ${JSON.stringify({ root: k.root, doc: root, column: doc })};\n`
|
|
299
|
+
? `\n/** ${doc} is one of many: a document for each of ${root}'s ${k.root} (${doc}:1), its items each kept with it. */\nexport const kind = ${JSON.stringify({ root: k.root, doc: root, column: doc, ...(k.files ? { files: k.files } : {}) })};\n`
|
|
214
300
|
: `\n/** ${doc} is one document. */\nexport const kind = null;\n`;
|
|
215
301
|
out += `\n/** Each grant, read off the stories: the roles whose stories do it (a member: anyone). An op no story
|
|
216
302
|
* does isn't one. */\nexport const grants: Record<string, string[]> = ${JSON.stringify(grants, null, 2)};\n`;
|
|
@@ -226,7 +312,7 @@ export function whoRules(
|
|
|
226
312
|
? `(read(${JSON.stringify(root)})[${JSON.stringify(k.root)}] ?? []).find((i: any) => i.id === Number(doc.split(/[:?]/)[1]))`
|
|
227
313
|
: "at";
|
|
228
314
|
out += `\n/** Who someone is to ${doc} (and to an item of it, \`at\`), beyond a member: each role whose who-path finds them. */\n`;
|
|
229
|
-
out += `export function rolesOf(m: number, read: (doc: string) => any, doc: string, at?: any): string[] {\n const item: any = ${item};\n return [${roles.map((r) => `\n ${whoCode(defs.roles![r]!,
|
|
315
|
+
out += `export function rolesOf(m: number, read: (doc: string) => any, doc: string, at?: any): string[] {\n const item: any = ${item};\n return [${roles.map((r) => `\n ${whoCode(defs.roles![r]!, defs.roles!, where, !!k, [r])} ? ${JSON.stringify(r)} : ""`).join(",")},\n ].filter(Boolean);\n}\n`;
|
|
230
316
|
return out + sight(doc, collections, defs, roles, where);
|
|
231
317
|
}
|
|
232
318
|
|
package/src/demo.css
CHANGED
|
@@ -5,23 +5,20 @@
|
|
|
5
5
|
:host {
|
|
6
6
|
display: block;
|
|
7
7
|
}
|
|
8
|
-
:host([hidden]) {
|
|
9
|
-
display: none;
|
|
10
|
-
}
|
|
11
8
|
nav {
|
|
12
9
|
display: flex;
|
|
13
10
|
flex-wrap: wrap;
|
|
14
11
|
align-items: baseline;
|
|
15
12
|
gap: var(--space-4) var(--space-12);
|
|
16
13
|
padding: var(--space-8) var(--space-12);
|
|
17
|
-
border-radius:
|
|
14
|
+
border-radius: var(--radius);
|
|
18
15
|
background: var(--well);
|
|
19
16
|
color: var(--ink);
|
|
20
17
|
font: var(--font-row);
|
|
21
18
|
}
|
|
22
19
|
a {
|
|
23
20
|
padding: 0 var(--space-8);
|
|
24
|
-
border-radius:
|
|
21
|
+
border-radius: var(--radius-pill);
|
|
25
22
|
color: inherit;
|
|
26
23
|
}
|
|
27
24
|
a[aria-current] {
|
package/src/draft.ts
CHANGED
|
@@ -2,23 +2,25 @@
|
|
|
2
2
|
// Never mind (`never`). Each named control is held against the value the document has, so a change
|
|
3
3
|
// made elsewhere fills the controls not being changed here, and keeps the ones that are. The form
|
|
4
4
|
// says whether it's kept in its note, and why, if a write was refused; Save is off until there's something to keep
|
|
5
|
-
// and it's ready to be kept.
|
|
6
|
-
//
|
|
5
|
+
// and it's ready to be kept. Its drawer (./surface.ts) closes by its ×, Escape and, on a phone, a tap on the
|
|
6
|
+
// dimmed page. Every drawer that changes
|
|
7
7
|
// something is one: a page that wants it imports this; what its changes are as element ops is the page's own, and a
|
|
8
8
|
// drawer that holds no fields against the document says its state by show() alone.
|
|
9
9
|
|
|
10
|
-
import { iconButton } from "./icons.ts";
|
|
11
|
-
|
|
12
10
|
type Value = string | boolean;
|
|
13
11
|
type Control = HTMLInputElement;
|
|
14
12
|
|
|
15
|
-
/** Every draft on the page. */
|
|
16
|
-
const drafts = new Set<Draft
|
|
13
|
+
/** Every draft on the page, held weakly: one its page lets go of is let go here too. */
|
|
14
|
+
const drafts = new Set<WeakRef<Draft>>();
|
|
17
15
|
/** Whether a draft holds changes in a form that's shown: what's typed and not kept, or what its form says isn't (a
|
|
18
16
|
* choice that's no control: the people chosen for an event), which a reload would lose (a page told another build
|
|
19
17
|
* waits for none, src/page.ts). */
|
|
20
18
|
export const unsaved = () =>
|
|
21
|
-
[...drafts].some((
|
|
19
|
+
[...drafts].some((ref) => {
|
|
20
|
+
const d = ref.deref();
|
|
21
|
+
if (!d) return (drafts.delete(ref), false);
|
|
22
|
+
return d.form.checkVisibility() && (d.changed || Object.keys(d.edits()).length > 0);
|
|
23
|
+
});
|
|
22
24
|
|
|
23
25
|
export class Draft {
|
|
24
26
|
/** Whether its form last said it holds changes not kept. */
|
|
@@ -27,24 +29,27 @@ export class Draft {
|
|
|
27
29
|
readonly form: HTMLFormElement,
|
|
28
30
|
readonly note: HTMLElement,
|
|
29
31
|
) {
|
|
30
|
-
drafts.add(this);
|
|
32
|
+
drafts.add(new WeakRef(this));
|
|
31
33
|
}
|
|
32
34
|
/** The form as the document has it: afresh, every control set; as it changes elsewhere, only those
|
|
33
35
|
* not being changed here. */
|
|
34
36
|
fill(saved: Record<string, Value>, afresh = false) {
|
|
37
|
+
const written: (Promise<unknown> | undefined)[] = [];
|
|
35
38
|
for (const [name, value] of Object.entries(saved)) {
|
|
36
39
|
const control = this.#control(name),
|
|
37
40
|
was = control.dataset.saved;
|
|
38
41
|
control.dataset.saved = String(value);
|
|
39
|
-
if (afresh || read(control) === was) write(control, value);
|
|
42
|
+
if (afresh || read(control) === was) written.push(write(control, value));
|
|
40
43
|
}
|
|
44
|
+
/** Settled once each control written has drawn it and said again whether it's valid. */
|
|
45
|
+
return Promise.all(written);
|
|
41
46
|
}
|
|
42
47
|
/** What the form has changed, by name: a tick as a boolean, the rest as strings. */
|
|
43
48
|
edits() {
|
|
44
49
|
const changed: Record<string, Value> = {};
|
|
45
50
|
for (const control of this.form.querySelectorAll<Control>("[data-saved]"))
|
|
46
51
|
if (read(control) !== control.dataset.saved)
|
|
47
|
-
changed[control.name] = control
|
|
52
|
+
changed[control.name] = ticks(control) ? control.checked : read(control);
|
|
48
53
|
return changed;
|
|
49
54
|
}
|
|
50
55
|
/** What the form says: "kept", nothing to save or put back; "changed", not kept yet; "new", not
|
|
@@ -56,29 +61,45 @@ export class Draft {
|
|
|
56
61
|
(this.form.elements.namedItem(name) as HTMLButtonElement).disabled =
|
|
57
62
|
state === "kept" || (name === "go" && !ready);
|
|
58
63
|
if (!this.note.classList.contains("refused"))
|
|
59
|
-
this
|
|
64
|
+
this.#say(state === "changed" ? "Not kept yet: Save keeps it, Never mind puts it back." : "");
|
|
65
|
+
}
|
|
66
|
+
/** Its note's words, said in place (a wa-callout: a refusal its danger), and hidden where there are none. */
|
|
67
|
+
#say(words: string) {
|
|
68
|
+
this.note.textContent = words;
|
|
69
|
+
this.note.hidden = !words;
|
|
70
|
+
this.note.setAttribute("variant", this.note.classList.contains("refused") ? "danger" : "neutral");
|
|
60
71
|
}
|
|
61
72
|
/** Why a write was refused, said in the note; nothing takes it back. */
|
|
62
73
|
refuse(why: string) {
|
|
74
|
+
// (refused, an app's own word for it; j-refused, joined's parts': danger)
|
|
63
75
|
this.note.classList.toggle("refused", !!why);
|
|
64
|
-
this.note.
|
|
76
|
+
this.note.classList.toggle("j-refused", !!why);
|
|
77
|
+
this.#say(why);
|
|
65
78
|
}
|
|
66
|
-
/**
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
let x = this.form.elements.namedItem("close") as HTMLButtonElement | null;
|
|
70
|
-
if (!x)
|
|
71
|
-
((x = Object.assign(iconButton("close", "Close"), { name: "close" })),
|
|
72
|
-
this.form.querySelector("header")!.append(x));
|
|
73
|
-
x.addEventListener("click", close);
|
|
74
|
-
(this.form.elements.namedItem("never") as HTMLButtonElement).addEventListener("click", never);
|
|
75
|
-
// taken as its own, so the page's Escape (./scrim.ts) doesn't close another
|
|
76
|
-
box.addEventListener("keydown", (e) => {
|
|
77
|
-
if ((e as KeyboardEvent).key === "Escape" && !e.defaultPrevented) (e.preventDefault(), close());
|
|
78
|
-
});
|
|
79
|
+
/** Never mind (`never`) puts back what it holds. (Its surface closes itself: src/surface.ts.) */
|
|
80
|
+
never(then: () => void) {
|
|
81
|
+
(this.form.elements.namedItem("never") as HTMLButtonElement).addEventListener("click", then);
|
|
79
82
|
}
|
|
80
83
|
#control = (name: string) => this.form.elements.namedItem(name) as Control;
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
const
|
|
86
|
+
/** Whether a control is a tick (a wa-checkbox, a wa-switch, or the browser's own). */
|
|
87
|
+
const ticks = (c: Control) => c.localName === "wa-checkbox" || c.localName === "wa-switch" || c.type === "checkbox";
|
|
88
|
+
const read = (c: Control) => (ticks(c) ? String(c.checked) : c.localName === "wa-select" ? chosen(c) : c.value);
|
|
89
|
+
/** A control set to a value, settled once it's said again whether it's valid: Web Awesome's control checks the box it
|
|
90
|
+
* draws, which holds a value set from outside only once it's drawn. */
|
|
91
|
+
function write(c: Control, v: Value) {
|
|
92
|
+
if (ticks(c)) c.checked = v === true;
|
|
93
|
+
else if (c.localName === "wa-select") choose(c, String(v));
|
|
94
|
+
else c.value = String(v);
|
|
95
|
+
const wa = c as Control & { updateComplete?: Promise<unknown>; updateValidity?: () => void };
|
|
96
|
+
return wa.updateComplete?.then(() => wa.updateValidity?.());
|
|
97
|
+
}
|
|
98
|
+
type Option = Element & { value: string; selected: boolean };
|
|
99
|
+
/** A choice of Web Awesome's (a wa-select) set to a value: its option chosen too, as it keeps only what's chosen. */
|
|
100
|
+
export function choose(c: { value: string | null } & Element, v: string | null) {
|
|
101
|
+
for (const o of c.querySelectorAll<Option>("wa-option")) o.selected = o.value === v;
|
|
102
|
+
c.value = v;
|
|
103
|
+
}
|
|
104
|
+
/** What a wa-select has chosen, by its option ("" for none): its own value is read from options it learns of later. */
|
|
105
|
+
export const chosen = (c: Element) => [...c.querySelectorAll<Option>("wa-option")].find((o) => o.selected)?.value ?? "";
|