@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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Every commit carries its record (CLAUDE.md, "The record"): CHANGELOG.md, where this app has been, or todo.jsonl,
|
|
3
|
+
# what's open, staged beside the change. A small fix is a line added to the entry it belongs to.
|
|
4
|
+
staged=$(git diff --cached --name-only)
|
|
5
|
+
[ -z "$staged" ] && exit 0
|
|
6
|
+
if echo "$staged" | grep -qx -e CHANGELOG.md -e todo.jsonl; then
|
|
7
|
+
# and what it says holds: each "Not yet" names its todo (quick: the record's test alone)
|
|
8
|
+
bun test tests/records.test.ts >/dev/null 2>&1 && exit 0
|
|
9
|
+
echo "Refused: the record doesn't hold. Run: bun test tests/records.test.ts" >&2
|
|
10
|
+
exit 1
|
|
11
|
+
fi
|
|
12
|
+
echo "Refused: a commit carries its record. Stage CHANGELOG.md (a line in the entry the change belongs to) or todo.jsonl beside it." >&2
|
|
13
|
+
exit 1
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// hello's stories, told: each does what it says, and what it says can't be done is refused (joined/stories).
|
|
2
|
+
// tell() is by app folder, not by document: an app whose stories write several documents (apps/race/, a race and
|
|
3
|
+
// its entries) is told whole by tell("race"), every document it writes; tell("entries") is refused, saying whose.
|
|
2
4
|
|
|
3
5
|
import { expect, test } from "bun:test";
|
|
4
6
|
import { tell } from "joined/stories";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// The record (CLAUDE.md): CHANGELOG.md says where this app has been, todo.jsonl what's open, a JSON object a line,
|
|
2
|
+
// each with its number, `n`. Every "Not yet" in the CHANGELOG names the todo that holds it (`todo 4`, or `#4`), each
|
|
3
|
+
// of its parts (split by ";") one, and every todo it names is there; and this checkout's commits pass through
|
|
4
|
+
// .githooks/pre-commit, which refuses a commit without its record.
|
|
5
|
+
|
|
6
|
+
import { expect, test } from "bun:test";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
|
|
10
|
+
const root = `${import.meta.dir}/..`;
|
|
11
|
+
const todos = new Set(
|
|
12
|
+
(await Bun.file(`${root}/todo.jsonl`).text())
|
|
13
|
+
.split("\n")
|
|
14
|
+
.filter(Boolean)
|
|
15
|
+
.map((l) => (JSON.parse(l) as { n: number }).n),
|
|
16
|
+
);
|
|
17
|
+
const entries = (await Bun.file(`${root}/CHANGELOG.md`).text()).split(/\n(?=- )/).map((e) => e.replace(/\s+/g, " "));
|
|
18
|
+
/** A todo named: `todo 4`, or `#4`. */
|
|
19
|
+
const TODO = /(?:todo |#)(\d+)\b/g;
|
|
20
|
+
|
|
21
|
+
test("every Not yet in the CHANGELOG names its todo", () => {
|
|
22
|
+
const untracked: string[] = [];
|
|
23
|
+
for (const e of entries)
|
|
24
|
+
for (const m of e.matchAll(/Not yet(?:, [^:.]{0,40}:|:)?\s([^]*?)(?=\. [A-Z*]|\.$|$)/g))
|
|
25
|
+
for (const part of m[1]!.split(";"))
|
|
26
|
+
if (!new RegExp(TODO.source).test(part)) untracked.push(`${e.slice(2, 60)}…: Not yet${part}`);
|
|
27
|
+
expect(untracked).toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("every todo the CHANGELOG names is in todo.jsonl", () => {
|
|
31
|
+
const named = entries.flatMap((e) => [...e.matchAll(TODO)].map((m) => Number(m[1])));
|
|
32
|
+
expect(named.filter((n) => !todos.has(n))).toEqual([]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("commits here pass through the record's hook", async () => {
|
|
36
|
+
if (!existsSync(`${root}/.git`)) return;
|
|
37
|
+
// (said as it's wired, or whole, as a worktree's tools write it)
|
|
38
|
+
const path = (await Bun.$`git -C ${root} config core.hooksPath`.nothrow().text()).trim();
|
|
39
|
+
expect(resolve(root, path), "run `bun install` (its prepare wires .githooks)").toBe(resolve(root, ".githooks"));
|
|
40
|
+
});
|
|
File without changes
|
package/docs/learning.md
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
# Learning joined
|
|
2
|
-
|
|
3
|
-
Why joined is hard to pick up, and what would make it easier. It isn't the size: the compiler, the
|
|
4
|
-
server, the page's side and the store are about 4,700 lines of code, and every line is tested. It's that a
|
|
5
|
-
newcomer meets several unfamiliar things at once, with nothing familiar to hold on to.
|
|
6
|
-
|
|
7
|
-
## Why it's hard
|
|
8
|
-
|
|
9
|
-
### Its own words, chosen for how they read
|
|
10
|
-
|
|
11
|
-
- **The code's names are joined's, not the trade's:** `say()`, `seen()`, `once()`,
|
|
12
|
-
`whole()`, `keep()`, `held`, `behind`, `again`; the group's doors `at`, `admit`, `within`, `after`,
|
|
13
|
-
`edge`. Someone searching for _broadcast_, _subscribe_, _permission_, _validate_ or _schema_ finds
|
|
14
|
-
nothing: those words aren't used.
|
|
15
|
-
- **Some words mean two things.** A _link_ is a field (`people="1 3"`) and a sign-in link. _Told_ is a
|
|
16
|
-
story's refusal words, the page's event, and the server's publish. A _key_ is an item's id
|
|
17
|
-
attribute and a member's secret.
|
|
18
|
-
- **The comments are compressed:** "A link is who you are." "The light DOM is the document; the
|
|
19
|
-
shadow DOM is the display." Each is right, and lovely once you know the system; before that, each
|
|
20
|
-
is a riddle.
|
|
21
|
-
|
|
22
|
-
### About forty ideas before anything past hello
|
|
23
|
-
|
|
24
|
-
The plan's table of words has over thirty: story, cast, premise, seen, unseen, document, kind,
|
|
25
|
-
instance, collection, item, field, link, role, owns, grant, may, trust, the group, BDFL, agent's
|
|
26
|
-
link, view, display, reading, applier and more. Then the who-paths have a syntax of their own:
|
|
27
|
-
`posts[role=keeper]@members`, `members/members[!inviter]`, `@owners`. Each is simple; you need most
|
|
28
|
-
of them at once.
|
|
29
|
-
|
|
30
|
-
### What's allowed is inferred, so it can't be read
|
|
31
|
-
|
|
32
|
-
A field is needed if every story that adds one gives it. An op is granted to its teller's
|
|
33
|
-
narrowest role, as the seeds have them. So to know why a write is refused, you run the compiler in
|
|
34
|
-
your head. `generated/rules.ts` is readable, but it's what came out, not what you wrote, and nothing
|
|
35
|
-
says which story granted what. (`bun run compile` now says when a story lets a needed field go.)
|
|
36
|
-
|
|
37
|
-
### Stories are written for the machine
|
|
38
|
-
|
|
39
|
-
A story is one JSON line of about 250 characters, with JSON Patch inside. Its ids are the seed's
|
|
40
|
-
(`/events/2`), so the seed is held in your head as you write. There's no shorthand, and no `then` to
|
|
41
|
-
say what the document holds after (todo 36).
|
|
42
|
-
|
|
43
|
-
### The model is new, and nothing is around it
|
|
44
|
-
|
|
45
|
-
The DOM is the state, a field is a string attribute, and a display is a custom element watching
|
|
46
|
-
its children with a `MutationObserver`. Someone who thinks in components and reactive stores has to
|
|
47
|
-
put that down first. There's no community, no answers to search, and the models that help people code
|
|
48
|
-
don't know joined. The trip's display alone is about 800 lines of DOM by hand.
|
|
49
|
-
|
|
50
|
-
### The docs are for those who know
|
|
51
|
-
|
|
52
|
-
The best guide, the skill's `reference.md`, is written for an AI, as `CLAUDE.md` is. The README and
|
|
53
|
-
the introduction are good, with pictures, but in the same compressed voice. Until 30 October,
|
|
54
|
-
`docs/plan.md` described another joined.
|
|
55
|
-
|
|
56
|
-
### A narrow way in
|
|
57
|
-
|
|
58
|
-
Bun only, and Bun 1.4's own (HTML imports, `Bun.WebView`); TypeScript 7; hot reload off; not
|
|
59
|
-
published, so a project takes a tarball; the page tests ran only on a Mac until 30 October; and the
|
|
60
|
-
gate holds every line and function to its tests before a first contribution lands.
|
|
61
|
-
|
|
62
|
-
## What would help, cheapest first
|
|
63
|
-
|
|
64
|
-
1. **Plain names in the code, the voice in the docs.** `catchUp` for `behind` (`publish` is
|
|
65
|
-
`told()` no more); or keep joined's and give a table from each to the trade's word.
|
|
66
|
-
2. **A tutorial:** one small app, from its first story to a display, showing what the compiler
|
|
67
|
-
writes at each step.
|
|
68
|
-
3. **`joined why <doc> <op>`:** which check refuses it, or which story grants it, and to whom.
|
|
69
|
-
4. **Stories a person writes:** a shorter form, `then`, and a way to make them that shows what each
|
|
70
|
-
part may be (see below).
|
|
71
|
-
|
|
72
|
-
## Stories from blocks
|
|
73
|
-
|
|
74
|
-
Item 4 goes further than a shorter syntax: stories made of blocks, each shaped by what it is, so only
|
|
75
|
-
what fits goes together, in the file's own words: one block a key, and the ops add, replace and remove
|
|
76
|
-
(`docs/blocks.md`).
|
package/examples/cafe/trust.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// The cafe's own rules, which no definition can say: an order's lines are set in the write that places it, and
|
|
2
|
-
// never after (a line added to an order there already is refused); and a supply delivered keeps its price and terms,
|
|
3
|
-
// as both sides' books have them.
|
|
4
|
-
import type { Trust } from "joined/server";
|
|
5
|
-
|
|
6
|
-
export const trust: Trust = ({ doc, ops }, _who, read) => {
|
|
7
|
-
if (
|
|
8
|
-
ops.some((o) => o.op === "add" && o.path === "/lines/-") &&
|
|
9
|
-
!ops.some((o) => o.op === "add" && o.path === "/orders/-")
|
|
10
|
-
)
|
|
11
|
-
return "an order's lines are set when it's placed";
|
|
12
|
-
if (doc === "supplies") {
|
|
13
|
-
const delivered = new Set(
|
|
14
|
-
(read("supplies").supplies as { id: number; delivered: boolean }[]).filter((s) => s.delivered).map((s) => s.id),
|
|
15
|
-
);
|
|
16
|
-
const kept = (path: string) => delivered.has(Number(path.match(/^\/supplies\/(\d+)\/(price|terms)/)?.[1]));
|
|
17
|
-
if (ops.some((o) => kept(o.path))) return "a delivered supply keeps its price and terms";
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
};
|
package/examples/desk/trust.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// The desk's own rule, which no story can say: a thumb is your own, and a task has one of yours at most (up or down,
|
|
2
|
-
// the other taken back in the same write). idea-cards' and cardlet's votes are this rule.
|
|
3
|
-
|
|
4
|
-
import type { Trust } from "joined/server";
|
|
5
|
-
|
|
6
|
-
const THUMB = /^\/tasks\/(\d+)\/(ups|downs)\/(-|\d+)$/;
|
|
7
|
-
type Task = { id: number; ups?: number[]; downs?: number[] };
|
|
8
|
-
|
|
9
|
-
export const trust: Trust = ({ doc, ops }, { member }, read) => {
|
|
10
|
-
const thumbs = ops.flatMap((o) => {
|
|
11
|
-
const m = THUMB.exec(o.path);
|
|
12
|
-
const who = m && (o.op === "add" ? o.value : Number(m[3]));
|
|
13
|
-
return m ? [{ add: o.op === "add", task: Number(m[1]), list: m[2] as "ups" | "downs", who }] : [];
|
|
14
|
-
});
|
|
15
|
-
if (thumbs.some((t) => t.who !== member)) return "You thumb only for yourself.";
|
|
16
|
-
const tasks = read(doc).tasks as Task[];
|
|
17
|
-
for (const t of thumbs.filter((t) => t.add)) {
|
|
18
|
-
const other = t.list === "ups" ? "downs" : "ups";
|
|
19
|
-
const taken = thumbs.some((o) => !o.add && o.task === t.task && o.list === other);
|
|
20
|
-
if (!taken && tasks.find((x) => x.id === t.task)?.[other]?.includes(member))
|
|
21
|
-
return "One thumb a task: take the other back first.";
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
};
|
package/examples/people/trust.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// The people's own rule, which no definition can say: which person you are (their member) is yours to say, as
|
|
2
|
-
// yourself, and to take back; nobody says it for someone else.
|
|
3
|
-
import type { Trust } from "joined/server";
|
|
4
|
-
|
|
5
|
-
export const trust: Trust = ({ doc, ops }, { member }, read) => {
|
|
6
|
-
const people = (read(doc).people ?? []) as { id: number; member?: number }[];
|
|
7
|
-
for (const o of ops) {
|
|
8
|
-
const [, coll, id, field] = o.path.split("/");
|
|
9
|
-
if (coll !== "people" || field !== "member") continue;
|
|
10
|
-
const now = people.find((p) => p.id === Number(id))?.member;
|
|
11
|
-
if (o.op === "remove" ? now !== member : o.value !== member) return "you say which person you are, as yourself";
|
|
12
|
-
}
|
|
13
|
-
return null;
|
|
14
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// The answers in an event's form: a row for each person on it, their face and name, their answer (yes unless said
|
|
2
|
-
// otherwise: ./answers.ts) and whether they come or go there (the line lands them, or sends them home). A change is
|
|
3
|
-
// the form's, until Save.
|
|
4
|
-
|
|
5
|
-
import { hueOf } from "joined/hues";
|
|
6
|
-
import { keep } from "joined/keep";
|
|
7
|
-
import { face } from "joined/parts";
|
|
8
|
-
import { ANSWERS, SAID, type Answer } from "./answers.ts";
|
|
9
|
-
|
|
10
|
-
/** Who among an event's people comes or goes at it. */
|
|
11
|
-
export type Gates = { arrives: Set<number>; leaves: Set<number> };
|
|
12
|
-
/** What the rows read of their form, when drawn and when changed: who's on it, their answers, who comes and goes. */
|
|
13
|
-
type Of = { readonly chosen: readonly number[]; readonly answers: Map<number, Answer>; readonly gates: Gates };
|
|
14
|
-
|
|
15
|
-
export class AnswerRows {
|
|
16
|
-
#kept = new Map<string, { shows: string; el: HTMLElement }>();
|
|
17
|
-
|
|
18
|
-
/** Drawn in `list`, from the form `of`; a change told to `redraw`. */
|
|
19
|
-
constructor(
|
|
20
|
-
readonly list: HTMLElement,
|
|
21
|
-
readonly of: Of,
|
|
22
|
-
readonly redraw: () => void,
|
|
23
|
-
) {}
|
|
24
|
-
|
|
25
|
-
/** A row each for those chosen, named from `people`: made again only as its name, answer or comings change. */
|
|
26
|
-
draw(people: Map<number, string>) {
|
|
27
|
-
keep(
|
|
28
|
-
this.list,
|
|
29
|
-
this.#kept,
|
|
30
|
-
this.of.chosen.map((key) => {
|
|
31
|
-
const name = people.get(key) ?? "",
|
|
32
|
-
now = this.of.answers.get(key) ?? "yes";
|
|
33
|
-
return {
|
|
34
|
-
key: String(key),
|
|
35
|
-
shows: `${name} ${now} ${this.of.gates.arrives.has(key)} ${this.of.gates.leaves.has(key)}`,
|
|
36
|
-
make: () => this.#row(key, name, now),
|
|
37
|
-
};
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** One person's row: their face and name, a select of their answer, and one of whether they come or go here. */
|
|
43
|
-
#row(key: number, name: string, now: Answer) {
|
|
44
|
-
const row = Object.assign(document.createElement("label"), { className: "answer" });
|
|
45
|
-
row.style.setProperty("--hue", hueOf(key));
|
|
46
|
-
const pick = Object.assign(document.createElement("select"), { ariaLabel: `${name}'s answer` });
|
|
47
|
-
for (const a of ["yes", ...ANSWERS] as Answer[]) pick.append(new Option(SAID[a], a, false, a === now));
|
|
48
|
-
pick.addEventListener("change", () => {
|
|
49
|
-
this.of.answers.set(key, pick.value as Answer);
|
|
50
|
-
this.redraw();
|
|
51
|
-
});
|
|
52
|
-
// whether they come or go here: the line lands them, or sends them home
|
|
53
|
-
const gate = Object.assign(document.createElement("select"), { ariaLabel: `Whether ${name} comes or goes here` });
|
|
54
|
-
const was = `${+this.of.gates.arrives.has(key)}${+this.of.gates.leaves.has(key)}`;
|
|
55
|
-
for (const [v, words] of [
|
|
56
|
-
["00", "Here"],
|
|
57
|
-
["10", "Arrives"],
|
|
58
|
-
["01", "Leaves"],
|
|
59
|
-
["11", "Arrives, leaves"],
|
|
60
|
-
])
|
|
61
|
-
gate.append(new Option(words, v, false, v === was));
|
|
62
|
-
gate.addEventListener("change", () => {
|
|
63
|
-
for (const [i, g] of (["arrives", "leaves"] as const).entries())
|
|
64
|
-
gate.value[i] === "1" ? this.of.gates[g].add(key) : this.of.gates[g].delete(key);
|
|
65
|
-
this.redraw();
|
|
66
|
-
});
|
|
67
|
-
row.append(face(key, name), Object.assign(document.createElement("span"), { textContent: name }), pick, gate);
|
|
68
|
-
return row;
|
|
69
|
-
}
|
|
70
|
-
}
|
package/examples/trip/bar.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// The bar atop <calendar-map>: the week's name, the week before and after (read as a month, the month before and
|
|
2
|
-
// after), how it's read (a calendar, a line or a month: its own attribute, told to the page for its address), and Add.
|
|
3
|
-
// How it's read is which of its panes is shown: the calendar (and a phone's strip of its days), the line, or the month.
|
|
4
|
-
|
|
5
|
-
import type { Part } from "./shell.ts";
|
|
6
|
-
import { dated, firstOf, gridOf, mondayOf } from "joined/time";
|
|
7
|
-
|
|
8
|
-
const VIEWS = ["calendar", "line", "month"] as const;
|
|
9
|
-
/** Its panes, and how the week is read when each is shown. */
|
|
10
|
-
const PANES = [
|
|
11
|
-
[".cal", "calendar"],
|
|
12
|
-
[".strip", "calendar"],
|
|
13
|
-
[".reading", "line"],
|
|
14
|
-
[".month", "month"],
|
|
15
|
-
] as const;
|
|
16
|
-
/** How the week is read. */
|
|
17
|
-
export type Reading = (typeof VIEWS)[number];
|
|
18
|
-
|
|
19
|
-
/** What the bar reads from its display: the week shown, whether it's read as a month, and what its buttons ask. */
|
|
20
|
-
type From = {
|
|
21
|
-
at: () => { week: number };
|
|
22
|
-
lined: () => boolean;
|
|
23
|
-
monthly: () => boolean;
|
|
24
|
-
go: (week: number) => void;
|
|
25
|
-
hold: (by: "week" | "month", day: number) => void;
|
|
26
|
-
read: () => void;
|
|
27
|
-
add: () => void;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export class Bar {
|
|
31
|
-
#name: HTMLElement;
|
|
32
|
-
#views: Map<Reading, HTMLElement>;
|
|
33
|
-
#panes: [HTMLElement, Reading][];
|
|
34
|
-
#host: HTMLElement;
|
|
35
|
-
#from: From;
|
|
36
|
-
|
|
37
|
-
/** In its parts; `host` is the display, whose `view` attribute says how it's read. */
|
|
38
|
-
constructor(host: HTMLElement, $: Part, from: From) {
|
|
39
|
-
this.#host = host;
|
|
40
|
-
this.#name = $(".week");
|
|
41
|
-
this.#views = new Map(VIEWS.map((view) => [view, $(`[name=${view}]`)]));
|
|
42
|
-
this.#panes = PANES.map(([pane, view]) => [$(pane), view]);
|
|
43
|
-
this.#from = from;
|
|
44
|
-
const { at } = from;
|
|
45
|
-
// the week before and after; read as a month, the month before and after
|
|
46
|
-
$("[name=back]").addEventListener("click", () =>
|
|
47
|
-
from.monthly() ? from.hold("month", gridOf(firstOf(at().week + 7) - 1)) : from.go(at().week - 7),
|
|
48
|
-
);
|
|
49
|
-
$("[name=on]").addEventListener("click", () =>
|
|
50
|
-
from.monthly() ? from.hold("month", gridOf(firstOf(at().week + 7) + 31)) : from.go(at().week + 7),
|
|
51
|
-
);
|
|
52
|
-
$("[name=new]").addEventListener("click", () => from.add());
|
|
53
|
-
for (const [view, b] of this.#views)
|
|
54
|
-
b.addEventListener("click", () => {
|
|
55
|
-
const was = from.monthly();
|
|
56
|
-
this.readAs(view);
|
|
57
|
-
// a month is held as its six weeks, a week as itself: the month the week's in, or that month's first week
|
|
58
|
-
if (view === "month" && !was) from.hold("month", gridOf(at().week + 3));
|
|
59
|
-
else if (view !== "month" && was) from.hold("week", mondayOf(firstOf(at().week + 7) + 3));
|
|
60
|
-
else from.read();
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Its name: the month, read as one; else the week's days, its months whole, or short on a phone, where it shares
|
|
65
|
-
* its line with the views and Add (and leaves out its year: there's room for them beside it only so). */
|
|
66
|
-
name(phone: boolean) {
|
|
67
|
-
const { week } = this.#from.at(),
|
|
68
|
-
[a, b] = [week, week + 6],
|
|
69
|
-
month = phone ? "short" : "long",
|
|
70
|
-
year = phone ? {} : { year: "numeric" as const };
|
|
71
|
-
this.#name.textContent = this.#from.monthly()
|
|
72
|
-
? dated(firstOf(week + 7), { month, year: "numeric" })
|
|
73
|
-
: dated(a, { month }) === dated(b, { month })
|
|
74
|
-
? `${dated(a, { day: "numeric" })}–${dated(b, { day: "numeric", month, ...year })}`
|
|
75
|
-
: `${dated(a, { day: "numeric", month })} – ${dated(b, { day: "numeric", month, ...year })}`;
|
|
76
|
-
}
|
|
77
|
-
/** Read as a calendar, a line or a month: its own attribute, and told to the page, for its address. */
|
|
78
|
-
readAs(view: Reading) {
|
|
79
|
-
this.#host.setAttribute("view", view);
|
|
80
|
-
this.#host.dispatchEvent(new CustomEvent("view", { bubbles: true, detail: view }));
|
|
81
|
-
}
|
|
82
|
-
/** How it's read, shown: its pane, and its button pressed. */
|
|
83
|
-
show(): Reading {
|
|
84
|
-
const shown = this.#from.monthly() ? "month" : this.#from.lined() ? "line" : "calendar";
|
|
85
|
-
for (const [pane, view] of this.#panes) pane.hidden = view !== shown;
|
|
86
|
-
for (const [view, b] of this.#views) b.setAttribute("aria-pressed", String(view === shown));
|
|
87
|
-
return shown;
|
|
88
|
-
}
|
|
89
|
-
}
|