@blueshed/joined 0.0.0-stage → 0.1.19
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 +17 -0
- package/.claude/skills/joined/reference.md +768 -0
- package/LICENSE +19 -0
- package/README.md +115 -2
- package/docs/design.md +148 -0
- package/docs/introduction.md +193 -0
- package/docs/learning.md +76 -0
- package/docs/stories.md +82 -0
- package/examples/app.css +27 -0
- package/examples/cafe/books.html +38 -0
- package/examples/cafe/books.json +13 -0
- package/examples/cafe/books.ts +64 -0
- package/examples/cafe/cafe.css +512 -0
- package/examples/cafe/front.html +115 -0
- package/examples/cafe/front.ts +7 -0
- package/examples/cafe/generated/books.elements.ts +52 -0
- package/examples/cafe/generated/books.queries.ts +11 -0
- package/examples/cafe/generated/books.rules.ts +42 -0
- package/examples/cafe/generated/kitchen.elements.ts +87 -0
- package/examples/cafe/generated/kitchen.queries.ts +47 -0
- package/examples/cafe/generated/kitchen.rules.ts +98 -0
- package/examples/cafe/generated/menu.elements.ts +61 -0
- package/examples/cafe/generated/menu.queries.ts +28 -0
- package/examples/cafe/generated/menu.rules.ts +65 -0
- package/examples/cafe/generated/order.elements.ts +87 -0
- package/examples/cafe/generated/order.queries.ts +47 -0
- package/examples/cafe/generated/order.rules.ts +95 -0
- package/examples/cafe/generated/staff.elements.ts +55 -0
- package/examples/cafe/generated/staff.queries.ts +27 -0
- package/examples/cafe/generated/staff.rules.ts +59 -0
- package/examples/cafe/generated/supplies.elements.ts +62 -0
- package/examples/cafe/generated/supplies.queries.ts +43 -0
- package/examples/cafe/generated/supplies.rules.ts +84 -0
- package/examples/cafe/generated/till.elements.ts +93 -0
- package/examples/cafe/generated/till.queries.ts +57 -0
- package/examples/cafe/generated/till.rules.ts +113 -0
- package/examples/cafe/index.html +70 -0
- package/examples/cafe/kitchen.css +107 -0
- package/examples/cafe/kitchen.html +39 -0
- package/examples/cafe/kitchen.ts +125 -0
- package/examples/cafe/menu.html +55 -0
- package/examples/cafe/menu.json +41 -0
- package/examples/cafe/menu.ts +84 -0
- package/examples/cafe/migrations/001-cafe.ts +11 -0
- package/examples/cafe/order.html +37 -0
- package/examples/cafe/order.ts +45 -0
- package/examples/cafe/rail-drag.ts +30 -0
- package/examples/cafe/routes.ts +32 -0
- package/examples/cafe/staff.json +20 -0
- package/examples/cafe/stories.jsonl +43 -0
- package/examples/cafe/supplies.html +77 -0
- package/examples/cafe/supplies.json +33 -0
- package/examples/cafe/supplies.ts +170 -0
- package/examples/cafe/till.json +95 -0
- package/examples/cafe/till.ts +122 -0
- package/examples/cafe/trust.ts +20 -0
- package/examples/cafe/views.ts +171 -0
- package/examples/docs.ts +28 -0
- package/examples/film.jpg +0 -0
- package/examples/hello/generated/elements.ts +45 -0
- package/examples/hello/generated/queries.ts +24 -0
- package/examples/hello/generated/rules.ts +45 -0
- package/examples/hello/hello.css +27 -0
- package/examples/hello/hello.json +1 -0
- package/examples/hello/index.html +32 -0
- package/examples/hello/migrations/001-hello.ts +6 -0
- package/examples/hello/page.ts +49 -0
- package/examples/hello/routes.ts +6 -0
- package/examples/hello/stories.jsonl +3 -0
- package/examples/index.html +146 -0
- package/examples/page.ts +11 -0
- package/examples/people/adding.ts +20 -0
- package/examples/people/generated/elements.ts +68 -0
- package/examples/people/generated/queries.ts +28 -0
- package/examples/people/generated/rules.ts +85 -0
- package/examples/people/links.ts +124 -0
- package/examples/people/migrations/001-people.ts +6 -0
- package/examples/people/migrations/002-add-people-member-and-guard-people.ts +7 -0
- package/examples/people/migrations/003-add-people-rank-and-guard-people.ts +7 -0
- package/examples/people/order.ts +61 -0
- package/examples/people/people.css +65 -0
- package/examples/people/people.json +26 -0
- package/examples/people/routes.ts +12 -0
- package/examples/people/stories.jsonl +20 -0
- package/examples/people/trust.ts +14 -0
- package/examples/people/view.ts +115 -0
- package/examples/routes.ts +11 -0
- package/examples/trip/answer-rows.ts +70 -0
- package/examples/trip/answers.ts +11 -0
- package/examples/trip/bar.ts +89 -0
- package/examples/trip/calendar-map.css +709 -0
- package/examples/trip/calendar-map.ts +249 -0
- package/examples/trip/drags.ts +143 -0
- package/examples/trip/drawer.ts +250 -0
- package/examples/trip/event-form.ts +199 -0
- package/examples/trip/generated/elements.ts +144 -0
- package/examples/trip/generated/queries.ts +46 -0
- package/examples/trip/generated/rules.ts +239 -0
- package/examples/trip/holding.ts +61 -0
- package/examples/trip/ics.ts +117 -0
- package/examples/trip/index.html +82 -0
- package/examples/trip/line-stops.ts +92 -0
- package/examples/trip/line-words.ts +79 -0
- package/examples/trip/line.ts +121 -0
- package/examples/trip/map.ts +234 -0
- package/examples/trip/mercator.ts +28 -0
- package/examples/trip/migrations/001-trip.ts +7 -0
- package/examples/trip/migrations/002-add-events-zone-and-guard-events.ts +7 -0
- package/examples/trip/migrations/003-guard-events-and-create-events_asked-and-more.ts +9 -0
- package/examples/trip/migrations/004-create-stays.ts +6 -0
- package/examples/trip/migrations/005-guard-events-and-create-events_arrives-and-more.ts +8 -0
- package/examples/trip/month.ts +87 -0
- package/examples/trip/other-weeks.ts +67 -0
- package/examples/trip/page.ts +121 -0
- package/examples/trip/peek.ts +71 -0
- package/examples/trip/people-chips.ts +74 -0
- package/examples/trip/place-search.ts +51 -0
- package/examples/trip/places.ts +34 -0
- package/examples/trip/routes.ts +27 -0
- package/examples/trip/shell.ts +39 -0
- package/examples/trip/stays.css +51 -0
- package/examples/trip/stays.ts +68 -0
- package/examples/trip/stories.jsonl +72 -0
- package/examples/trip/time.ts +46 -0
- package/examples/trip/told.ts +48 -0
- package/examples/trip/trip.json +69 -0
- package/examples/trip/trust.ts +51 -0
- package/examples/trip/week.ts +237 -0
- package/examples/trip/words.ts +4 -0
- package/examples/trip/writes.ts +91 -0
- package/examples/trip/zones.ts +16 -0
- package/examples/trips/card.ts +149 -0
- package/examples/trips/generated/elements.ts +60 -0
- package/examples/trips/generated/queries.ts +28 -0
- package/examples/trips/generated/rules.ts +62 -0
- package/examples/trips/index.html +47 -0
- package/examples/trips/map.ts +52 -0
- package/examples/trips/migrations/001-trips.ts +8 -0
- package/examples/trips/new-trip.ts +46 -0
- package/examples/trips/page.ts +9 -0
- package/examples/trips/routes.ts +7 -0
- package/examples/trips/stories.jsonl +12 -0
- package/examples/trips/trips.css +183 -0
- package/examples/trips/trips.json +7 -0
- package/examples/weeks/derive.ts +23 -0
- package/examples/weeks/generated/elements.ts +52 -0
- package/examples/weeks/generated/rules.ts +33 -0
- package/examples/weeks/routes.ts +4 -0
- package/examples/weeks/weeks.json +1 -0
- package/examples/welcome.css +299 -0
- package/package.json +51 -4
- package/src/attachment.ts +70 -0
- package/src/cli.ts +52 -0
- package/src/client.ts +98 -0
- package/src/compile.ts +2034 -0
- package/src/css.d.ts +5 -0
- package/src/definitions.ts +268 -0
- package/src/demo.css +29 -0
- package/src/demo.ts +42 -0
- package/src/draft.ts +69 -0
- package/src/engine.ts +288 -0
- package/src/file-value.ts +13 -0
- package/src/files.ts +187 -0
- package/src/follow.ts +56 -0
- package/src/hues.ts +3 -0
- package/src/icon-names.ts +77 -0
- package/src/icon.png +0 -0
- package/src/icons.ts +32 -0
- package/src/keep.ts +33 -0
- package/src/link.ts +31 -0
- package/src/mcp.ts +252 -0
- package/src/members/demo.ts +53 -0
- package/src/members/generated/elements.ts +68 -0
- package/src/members/generated/queries.ts +29 -0
- package/src/members/generated/rules.ts +65 -0
- package/src/members/group.ts +294 -0
- package/src/members/keys.ts +221 -0
- package/src/members/members.json +9 -0
- package/src/members/migrations/001-members.ts +6 -0
- package/src/members/migrations/002-guard-members.ts +11 -0
- package/src/members/migrations/003-add-members-act-and-guard-members.ts +7 -0
- package/src/members/panel.css +208 -0
- package/src/members/panel.ts +398 -0
- package/src/members/routes.ts +4 -0
- package/src/members/stories.jsonl +27 -0
- package/src/members/trust.ts +116 -0
- package/src/migrate.ts +597 -0
- package/src/migrations/001-joined.ts +13 -0
- package/src/migrations/002-group-keys.ts +16 -0
- package/src/migrations/003-change-inverse.ts +10 -0
- package/src/migrations/004-change-followed.ts +6 -0
- package/src/ops.ts +61 -0
- package/src/page.css +79 -0
- package/src/page.ts +413 -0
- package/src/parts.css +471 -0
- package/src/parts.ts +152 -0
- package/src/server.ts +862 -0
- package/src/settings.ts +94 -0
- package/src/starter.ts +89 -0
- package/src/store.ts +815 -0
- package/src/stories.ts +387 -0
- package/src/toast.ts +52 -0
- package/src/together.ts +167 -0
- package/src/tokens.css +85 -0
- package/src/tokens.json +457 -0
- package/src/upkeep.ts +86 -0
- package/src/visitors.ts +43 -0
- package/src/write.ts +567 -0
- package/starter/CLAUDE.md +37 -0
- package/starter/gitignore +3 -0
- package/starter/tests/hello-page.test.ts +14 -0
- package/starter/tests/hello.test.ts +8 -0
- package/starter/tsconfig.json +17 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The lists <calendar-map> is told of by id, beyond it on the page, each read from a live list, never a search: the
|
|
2
|
+
// people (people="…"), who give each event its people's colours and the form a chip for each, watched for a person
|
|
3
|
+
// renamed, come or gone, or said to be someone; and the stays (stays="…"), drawn on the line, watched for one booked,
|
|
4
|
+
// changed or cancelled.
|
|
5
|
+
|
|
6
|
+
import type { JPerson } from "../people/generated/elements.ts";
|
|
7
|
+
import type { JStay } from "./generated/elements.ts";
|
|
8
|
+
import { collections as people } from "../people/generated/rules.ts";
|
|
9
|
+
import { collections as trip } from "./generated/rules.ts";
|
|
10
|
+
|
|
11
|
+
export class Told {
|
|
12
|
+
#host: HTMLElement;
|
|
13
|
+
|
|
14
|
+
/** What `host` is told of. */
|
|
15
|
+
constructor(host: HTMLElement) {
|
|
16
|
+
this.#host = host;
|
|
17
|
+
}
|
|
18
|
+
#list = (attribute: string) => document.getElementById(this.#host.getAttribute(attribute) ?? "");
|
|
19
|
+
|
|
20
|
+
/** The people, by key: their names. */
|
|
21
|
+
people = () => new Map([...this.persons()].map((p) => [p.key, p.data.name]));
|
|
22
|
+
/** The people, as their elements. */
|
|
23
|
+
persons = () => (this.#list("people")?.getElementsByTagName(people.people.tag) ?? []) as Iterable<JPerson>;
|
|
24
|
+
/** The stays, as their elements. */
|
|
25
|
+
stays = () => [...((this.#list("stays")?.getElementsByTagName(trip.stays.tag) ?? []) as Iterable<JStay>)];
|
|
26
|
+
|
|
27
|
+
/** Both watched, by `watch` (let go with the display): the keys of the people changed, and that a stay has. */
|
|
28
|
+
watch(watch: <O extends MutationObserver>(o: O) => O, changed: (keys: Set<number>) => void, stayed: () => void) {
|
|
29
|
+
const list = this.#list("people");
|
|
30
|
+
if (list)
|
|
31
|
+
watch(
|
|
32
|
+
new MutationObserver((records) => {
|
|
33
|
+
const keys = new Set(
|
|
34
|
+
records.flatMap((r) =>
|
|
35
|
+
r.type === "attributes"
|
|
36
|
+
? [(r.target as JPerson).key]
|
|
37
|
+
: (r.target as Element).localName === people.people.place
|
|
38
|
+
? [...r.addedNodes, ...r.removedNodes].map((n) => (n as JPerson).key)
|
|
39
|
+
: [],
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
if (keys.size) changed(keys);
|
|
43
|
+
}),
|
|
44
|
+
).observe(list, { childList: true, subtree: true, attributeFilter: ["name", "member"] });
|
|
45
|
+
const stays = this.#list("stays");
|
|
46
|
+
if (stays) watch(new MutationObserver(stayed)).observe(stays, { childList: true, subtree: true, attributes: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"events": [
|
|
4
|
+
{
|
|
5
|
+
"id": 1,
|
|
6
|
+
"trip": 1,
|
|
7
|
+
"title": "Land at Haneda",
|
|
8
|
+
"start": "2026-11-03T17:00:00",
|
|
9
|
+
"duration": "PT1H",
|
|
10
|
+
"location": "Haneda Airport",
|
|
11
|
+
"coordinates": "geo:35.5494,139.7798",
|
|
12
|
+
"people": [1]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": 2,
|
|
16
|
+
"trip": 1,
|
|
17
|
+
"title": "Dinner in Shinjuku",
|
|
18
|
+
"start": "2026-11-04T19:00:00",
|
|
19
|
+
"duration": "PT2H",
|
|
20
|
+
"location": "Shinjuku, Tokyo",
|
|
21
|
+
"coordinates": "geo:35.6938,139.7034",
|
|
22
|
+
"people": [1, 2],
|
|
23
|
+
"zone": "Asia/Tokyo"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": 3,
|
|
27
|
+
"trip": 1,
|
|
28
|
+
"title": "Shinkansen to Kyoto",
|
|
29
|
+
"start": "2026-11-06T09:00:00",
|
|
30
|
+
"duration": "PT2H15M",
|
|
31
|
+
"location": "Tokyo Station",
|
|
32
|
+
"coordinates": "geo:35.6812,139.7671",
|
|
33
|
+
"people": [1],
|
|
34
|
+
"zone": "Asia/Tokyo"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": 4,
|
|
38
|
+
"trip": 1,
|
|
39
|
+
"title": "Fushimi Inari at dawn",
|
|
40
|
+
"start": "2026-11-07T06:30:00",
|
|
41
|
+
"duration": "PT3H",
|
|
42
|
+
"location": "Fushimi Inari, Kyoto",
|
|
43
|
+
"coordinates": "geo:34.9671,135.7727",
|
|
44
|
+
"people": [1, 3],
|
|
45
|
+
"zone": "Asia/Tokyo",
|
|
46
|
+
"asked": [3]
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"stays": [
|
|
50
|
+
{
|
|
51
|
+
"id": 1,
|
|
52
|
+
"trip": 1,
|
|
53
|
+
"name": "Hotel Gracery",
|
|
54
|
+
"from": "2026-11-03T15:00:00",
|
|
55
|
+
"until": "2026-11-06T10:00:00",
|
|
56
|
+
"location": "Shinjuku, Tokyo",
|
|
57
|
+
"coordinates": "geo:35.6950,139.7020"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": 2,
|
|
61
|
+
"trip": 1,
|
|
62
|
+
"name": "Ryokan in Gion",
|
|
63
|
+
"from": "2026-11-06T15:00:00",
|
|
64
|
+
"until": "2026-11-09T10:00:00",
|
|
65
|
+
"location": "Gion, Kyoto",
|
|
66
|
+
"coordinates": "geo:35.0037,135.7752"
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// The trip's own rule, which no definition can say: an answer to an event (keen, asked, declined; yes is being on it
|
|
2
|
+
// and saying none of them) is from someone on it, and each person gives one; and who comes or goes at an event
|
|
3
|
+
// (arrives, leaves: the line lands them there, or sends them home) is on it. Held to each event as the write leaves it.
|
|
4
|
+
import type { Trust } from "joined/server";
|
|
5
|
+
import { ANSWERS } from "./answers.ts";
|
|
6
|
+
|
|
7
|
+
const GATES = ["arrives", "leaves"] as const;
|
|
8
|
+
const LISTS = [...ANSWERS, ...GATES];
|
|
9
|
+
type List = "people" | (typeof LISTS)[number];
|
|
10
|
+
type Event = { id: number } & { [l in List]?: number[] };
|
|
11
|
+
|
|
12
|
+
export const trust: Trust = ({ doc, ops }, _who, read) => {
|
|
13
|
+
const touched = new Map<number, Event>();
|
|
14
|
+
const events = () => (read(doc.split("?")[0]!).events ?? []) as Event[];
|
|
15
|
+
const at = (id: number) => {
|
|
16
|
+
if (!touched.has(id)) {
|
|
17
|
+
const e = events().find((x) => x.id === id);
|
|
18
|
+
touched.set(id, {
|
|
19
|
+
...e,
|
|
20
|
+
id,
|
|
21
|
+
people: [...(e?.people ?? [])],
|
|
22
|
+
...Object.fromEntries(LISTS.map((a) => [a, [...(e?.[a] ?? [])]])),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return touched.get(id)!;
|
|
26
|
+
};
|
|
27
|
+
for (const o of ops) {
|
|
28
|
+
const [, coll, id, field, which] = o.path.split("/");
|
|
29
|
+
if (coll !== "events") continue;
|
|
30
|
+
if (id === "-") {
|
|
31
|
+
// an event added whole: its own lists
|
|
32
|
+
const v = o.value as Event;
|
|
33
|
+
if (LISTS.some((a) => v[a]?.length)) touched.set(-touched.size - 1, { ...v, id: -1 });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const list = field as List;
|
|
37
|
+
if (list !== "people" && !LISTS.includes(list as never)) continue;
|
|
38
|
+
const e = at(Number(id));
|
|
39
|
+
if (o.op === "replace" && which === undefined) e[list] = [...(o.value as number[])];
|
|
40
|
+
else if (o.op === "add" && which === "-") e[list] = [...(e[list] ?? []), o.value as number];
|
|
41
|
+
else if (o.op === "remove") e[list] = which === undefined ? [] : (e[list] ?? []).filter((k) => k !== Number(which));
|
|
42
|
+
}
|
|
43
|
+
for (const e of touched.values()) {
|
|
44
|
+
const on = (k: number) => (e.people ?? []).includes(k);
|
|
45
|
+
const given = ANSWERS.flatMap((a) => e[a] ?? []);
|
|
46
|
+
if (!given.every(on)) return "an answer is from someone on the event";
|
|
47
|
+
if (new Set(given).size !== given.length) return "one answer each";
|
|
48
|
+
if (!GATES.every((g) => (e[g] ?? []).every(on))) return "who comes or goes at an event is on it";
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// The week as a calendar, drawn by <calendar-map>: a ruler of its hours and its seven days, each event a block on its
|
|
2
|
+
// day from its start for its length, and past midnight the rest of it on each day after, saying until when. A block
|
|
3
|
+
// is made once, then only moved. Its hours are the day's waking ones, and any its events need. On a phone it's a strip
|
|
4
|
+
// of the week's days with one day shown, its hours and its places: a day pressed in the strip shows it, as picking an
|
|
5
|
+
// event shows its day. A press on a block picks its event, and a drag moves it, or by its foot changes its length; a
|
|
6
|
+
// drag on a day's hours is a new event's range (./drags.ts).
|
|
7
|
+
|
|
8
|
+
import type { JEvent } from "./generated/elements.ts";
|
|
9
|
+
import type { Drags } from "./drags.ts";
|
|
10
|
+
import type { Shown } from "./drawer.ts";
|
|
11
|
+
import type { Part } from "./shell.ts";
|
|
12
|
+
import { held } from "joined/follow";
|
|
13
|
+
import { hueOf } from "joined/hues";
|
|
14
|
+
import { keep } from "joined/keep";
|
|
15
|
+
import { face } from "joined/parts";
|
|
16
|
+
import { DAY, dated, dayOf, hhmm, hours, MIN, on, seconds, wall } from "./time.ts";
|
|
17
|
+
|
|
18
|
+
export const HOUR = 36,
|
|
19
|
+
EARLY = 6, // the hours a week shows, more if its events need them
|
|
20
|
+
LATE = 22;
|
|
21
|
+
type Kept = Map<string, { shows: string; el: HTMLElement }>;
|
|
22
|
+
|
|
23
|
+
/** What the week reads from its display: the week and hours it's drawn on, the day a phone shows (and the week it was
|
|
24
|
+
* chosen in), its events and the one picked, and what a press does. */
|
|
25
|
+
type From = {
|
|
26
|
+
at: () => { week: number; from: number; to: number };
|
|
27
|
+
chose: { day: number; dayWeek: number | null };
|
|
28
|
+
events: () => JEvent[];
|
|
29
|
+
picked: () => JEvent | null;
|
|
30
|
+
pick: (el: JEvent) => void;
|
|
31
|
+
changed: () => void;
|
|
32
|
+
drags: () => Drags;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** A block's words: its title, and from when to when. */
|
|
36
|
+
export function label(block: HTMLElement, title: string, start: string, duration: string) {
|
|
37
|
+
block.querySelector("b")!.textContent = title;
|
|
38
|
+
block.querySelector("span")!.textContent = hours(start, duration);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class Week {
|
|
42
|
+
#blocks = new Map<JEvent, { block: HTMLElement; who: Kept; rests: HTMLElement[] }>();
|
|
43
|
+
#host: HTMLElement;
|
|
44
|
+
#ruler: HTMLElement;
|
|
45
|
+
#days: HTMLElement;
|
|
46
|
+
#strip: HTMLElement;
|
|
47
|
+
#from: From;
|
|
48
|
+
|
|
49
|
+
/** Drawn in its parts; `host` is the display, the span of its hours (--span) set on it. */
|
|
50
|
+
constructor(host: HTMLElement, $: Part, from: From) {
|
|
51
|
+
[this.#host, this.#ruler, this.#days, this.#strip, this.#from] = [host, $(".ruler"), $(".days"), $(".strip"), from];
|
|
52
|
+
this.#strip.addEventListener("click", (e) => {
|
|
53
|
+
const b = (e.target as Element).closest<HTMLButtonElement>("button");
|
|
54
|
+
if (b) ((from.chose.day = Number(b.value)), from.changed());
|
|
55
|
+
});
|
|
56
|
+
this.#days.addEventListener(
|
|
57
|
+
"pointerdown",
|
|
58
|
+
(e) => (e.target as Element).classList.contains("hours") && held(e, () => from.drags().range(e)),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The hours the week shows, from the events it shows (a phone's day's, else the week's), which it gives back. A week
|
|
63
|
+
* newly shown, once its events are here, shows its first day with one, or the picked event's. */
|
|
64
|
+
hours(events: JEvent[], week: number, phone: boolean) {
|
|
65
|
+
const { chose } = this.#from;
|
|
66
|
+
if (chose.dayWeek !== week && events.length) {
|
|
67
|
+
const el = this.#from.picked(),
|
|
68
|
+
picked = el && dayOf(el.data.start) - week;
|
|
69
|
+
chose.day =
|
|
70
|
+
picked !== null && picked >= 0 && picked < 7
|
|
71
|
+
? picked
|
|
72
|
+
: Math.max(
|
|
73
|
+
0,
|
|
74
|
+
events.reduce((least, el) => Math.min(least, dayOf(el.data.start) - week), Infinity),
|
|
75
|
+
);
|
|
76
|
+
chose.dayWeek = week;
|
|
77
|
+
}
|
|
78
|
+
const shown = phone ? events.filter((el) => on(el.data, week + chose.day)) : events;
|
|
79
|
+
// the day's waking hours, and any its events need
|
|
80
|
+
let from = EARLY,
|
|
81
|
+
to = LATE;
|
|
82
|
+
for (const el of shown) {
|
|
83
|
+
const h = (wall(el.data.start) % DAY) / MIN / 60,
|
|
84
|
+
end = h + seconds(el.data.duration) / 3600;
|
|
85
|
+
from = Math.min(from, Math.floor(h), end > 24 ? 0 : 24);
|
|
86
|
+
to = Math.max(to, Math.min(24, Math.ceil(end)));
|
|
87
|
+
}
|
|
88
|
+
return { shown, from, to };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Its frame, for the week and hours it's on: the ruler, the days (their blocks placed after) and the strip. */
|
|
92
|
+
draw() {
|
|
93
|
+
const { week, from, to } = this.#from.at();
|
|
94
|
+
this.#host.style.setProperty("--span", String(to - from));
|
|
95
|
+
this.#ruler.innerHTML = `<h3></h3><div>${Array.from({ length: Math.ceil((to - from) / 2) }, (_, i) => `<span style="top: ${i * 2 * HOUR}px">${String(from + i * 2).padStart(2, "0")}:00</span>`).join("")}</div>`;
|
|
96
|
+
this.#days.replaceChildren(
|
|
97
|
+
...Array.from({ length: 7 }, (_, i) => {
|
|
98
|
+
const day = Object.assign(document.createElement("div"), { className: "day" });
|
|
99
|
+
day.innerHTML = `<h3>${dated(week + i, { weekday: "short", day: "numeric" })}</h3><div class="hours"></div>`;
|
|
100
|
+
return day;
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
this.#strip.replaceChildren(
|
|
104
|
+
...Array.from({ length: 7 }, (_, i) => {
|
|
105
|
+
const b = Object.assign(document.createElement("button"), { type: "button", value: String(i) });
|
|
106
|
+
b.ariaLabel = dated(week + i, { weekday: "long", day: "numeric", month: "long" });
|
|
107
|
+
b.innerHTML = `<span>${dated(week + i, { weekday: "short" })}</span><b>${dated(week + i, { day: "numeric" })}</b>`;
|
|
108
|
+
return b;
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** An event's block on its day (and the rest of it on the days after): made once, then only moved. */
|
|
114
|
+
place(el: JEvent, shown: Shown, names: Map<number, string>) {
|
|
115
|
+
let drawn = this.#blocks.get(el);
|
|
116
|
+
if (!drawn) {
|
|
117
|
+
const block = Object.assign(document.createElement("div"), {
|
|
118
|
+
className: "block",
|
|
119
|
+
innerHTML: `<b></b><span></span><span class="who"></span><span class="grip"></span>`,
|
|
120
|
+
});
|
|
121
|
+
this.#press(block, el);
|
|
122
|
+
this.#blocks.set(el, (drawn = { block, who: new Map(), rests: [] }));
|
|
123
|
+
}
|
|
124
|
+
const { block } = drawn;
|
|
125
|
+
const { title, start, duration, location, people = [] } = shown;
|
|
126
|
+
const who = people.filter((k) => names.has(k));
|
|
127
|
+
block.style.setProperty("--hue", hueOf(el.key));
|
|
128
|
+
label(block, title, start, duration);
|
|
129
|
+
block.title = [title, location, who.map((k) => names.get(k)).join(", ")].filter(Boolean).join(" · ");
|
|
130
|
+
keep(
|
|
131
|
+
block.querySelector(".who")!,
|
|
132
|
+
drawn.who,
|
|
133
|
+
who.map((k) => ({
|
|
134
|
+
key: String(k),
|
|
135
|
+
shows: names.get(k)!,
|
|
136
|
+
make: () => face(k, names.get(k)!, true),
|
|
137
|
+
})),
|
|
138
|
+
);
|
|
139
|
+
this.when(block, wall(start), seconds(duration) / 60);
|
|
140
|
+
this.#rest(el, drawn.rests, title, wall(start), seconds(duration) / 60);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** What an event runs into past midnight: a block on each day after its first, from midnight to its end (or the
|
|
144
|
+
* day's), saying until when; a press on one is a press on the event. */
|
|
145
|
+
/** A block, or its rest, pressed: held, it's dragged (by its grip, its length); tapped, picked. */
|
|
146
|
+
#press(block: HTMLElement, el: JEvent) {
|
|
147
|
+
block.addEventListener("pointerdown", (e) =>
|
|
148
|
+
held(
|
|
149
|
+
e,
|
|
150
|
+
() => this.#from.drags().block(el, e, (e.target as Element).classList.contains("grip")),
|
|
151
|
+
undefined,
|
|
152
|
+
() => this.#from.pick(el),
|
|
153
|
+
),
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
#rest(el: JEvent, rests: HTMLElement[], title: string, from: number, mins: number) {
|
|
157
|
+
const end = from + mins * MIN,
|
|
158
|
+
days: number[] = [];
|
|
159
|
+
for (let d = Math.floor(from / DAY) + 1; d * DAY < end; d++) days.push(d);
|
|
160
|
+
while (rests.length > days.length) rests.pop()!.remove();
|
|
161
|
+
while (rests.length < days.length) {
|
|
162
|
+
const r = Object.assign(document.createElement("div"), {
|
|
163
|
+
className: "block rest",
|
|
164
|
+
innerHTML: "<b></b><span></span>",
|
|
165
|
+
});
|
|
166
|
+
this.#press(r, el);
|
|
167
|
+
r.toggleAttribute("picked", el === this.#from.picked());
|
|
168
|
+
rests.push(r);
|
|
169
|
+
}
|
|
170
|
+
days.forEach((d, i) => {
|
|
171
|
+
const r = rests[i]!,
|
|
172
|
+
until = Math.min(end, (d + 1) * DAY);
|
|
173
|
+
r.style.setProperty("--hue", hueOf(el.key));
|
|
174
|
+
r.querySelector("b")!.textContent = title;
|
|
175
|
+
r.querySelector("span")!.textContent = until === (d + 1) * DAY ? "all day" : `until ${hhmm(until)}`;
|
|
176
|
+
this.when(r, d * DAY, (until - d * DAY) / MIN);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** A block on the day it starts, from its start for its length, within the hours shown. */
|
|
181
|
+
when(block: HTMLElement, from: number, mins: number) {
|
|
182
|
+
const at = this.#from.at(),
|
|
183
|
+
into = (from % DAY) / MIN - at.from * 60;
|
|
184
|
+
block.style.top = `${(into / 60) * HOUR}px`;
|
|
185
|
+
block.style.height = `${Math.max(14, (Math.min(mins, at.to * 60 - (from % DAY) / MIN) / 60) * HOUR - 2)}px`;
|
|
186
|
+
const hours = this.#days.children[Math.floor(from / DAY) - at.week]?.querySelector(".hours");
|
|
187
|
+
if (!hours)
|
|
188
|
+
block.remove(); // not on this week
|
|
189
|
+
else if (block.parentNode !== hours) hours.append(block);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The strip of the week's days (a phone's), the day shown pressed and those with events in ink; on a phone, only
|
|
193
|
+
* that day's column. */
|
|
194
|
+
showDay() {
|
|
195
|
+
const { week } = this.#from.at(),
|
|
196
|
+
{ day } = this.#from.chose,
|
|
197
|
+
busy = new Set(this.#from.events().map((el) => dayOf(el.data.start) - week));
|
|
198
|
+
[...this.#strip.children].forEach((b, i) => {
|
|
199
|
+
b.setAttribute("aria-pressed", String(i === day));
|
|
200
|
+
b.classList.toggle("busy", busy.has(i));
|
|
201
|
+
});
|
|
202
|
+
[...this.#days.children].forEach((d, i) => d.toggleAttribute("shown", i === day));
|
|
203
|
+
}
|
|
204
|
+
/** The day shown (a phone's) moved to an event's, if it isn't shown: whether it moved. */
|
|
205
|
+
follow(el: JEvent) {
|
|
206
|
+
const day = dayOf(el.data.start) - this.#from.at().week;
|
|
207
|
+
if (day < 0 || day > 6 || day === this.#from.chose.day) return false;
|
|
208
|
+
this.#from.chose.day = day;
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The time under a pointer on the calendar: its day's, at its height, within the hours shown. */
|
|
213
|
+
timeAt(e: PointerEvent) {
|
|
214
|
+
// the day under it, of those shown (a phone shows one)
|
|
215
|
+
const days = [...this.#days.children] as HTMLElement[],
|
|
216
|
+
shown = days.filter((d) => d.offsetWidth),
|
|
217
|
+
day = shown.find((d) => e.clientX < d.getBoundingClientRect().right) ?? shown.at(-1)!,
|
|
218
|
+
i = days.indexOf(day),
|
|
219
|
+
top = day.querySelector(".hours")!.getBoundingClientRect().top;
|
|
220
|
+
const { week, from, to } = this.#from.at();
|
|
221
|
+
const mins = Math.max(from * 60, Math.min(to * 60, from * 60 + ((e.clientY - top) / HOUR) * 60));
|
|
222
|
+
return (week + i) * DAY + mins * MIN;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** An event's block, if it's drawn. */
|
|
226
|
+
blockOf = (el: JEvent) => this.#blocks.get(el)?.block;
|
|
227
|
+
/** The picked event's block and its rest marked, the others not. */
|
|
228
|
+
mark(picked: JEvent | null) {
|
|
229
|
+
for (const [e, { block, rests }] of this.#blocks)
|
|
230
|
+
for (const part of [block, ...rests]) part.toggleAttribute("picked", e === picked);
|
|
231
|
+
}
|
|
232
|
+
/** The blocks of events no longer in `list` (gone, or on another week) taken away. */
|
|
233
|
+
drop(list: Node | null) {
|
|
234
|
+
for (const [el, { block, rests }] of this.#blocks)
|
|
235
|
+
if (el.parentNode !== list) (block.remove(), rests.forEach((r) => r.remove()), this.#blocks.delete(el));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The writes <calendar-map>'s form sends (./drawer.ts): the picked event's changes, an emptied place removed and the
|
|
2
|
+
// rest in one write, who comes or goes linked and unlinked as the stories write them; and a new event, added. Each
|
|
3
|
+
// is the event element's own ops. Refused, why is said in the form, which keeps what it holds, to be saved again or
|
|
4
|
+
// put back, and nothing is drawn as saved that wasn't; done is nothing, as the change shows. An event kept on
|
|
5
|
+
// another week is opened there.
|
|
6
|
+
|
|
7
|
+
import type { JEvent, JEvents, JEventValue } from "./generated/elements.ts";
|
|
8
|
+
import type { EventForm, Input } from "./event-form.ts";
|
|
9
|
+
import type { Answer } from "joined/page";
|
|
10
|
+
import { ANSWERS } from "./answers.ts";
|
|
11
|
+
import { dayOf, mondayOf } from "./time.ts";
|
|
12
|
+
|
|
13
|
+
/** What the writes read from the drawer and its display: how to say why, draw all again, ask for a new event again
|
|
14
|
+
* (and draw it) and close the modal; the events' list, the week shown, whether a week is held and how to go to one;
|
|
15
|
+
* and the event kept on another week, to open there once it's held. */
|
|
16
|
+
type From = {
|
|
17
|
+
say: (why: string) => void;
|
|
18
|
+
placeAll: () => void;
|
|
19
|
+
new: (given: Partial<Record<Input, string>>) => void;
|
|
20
|
+
redraw: () => void;
|
|
21
|
+
close: () => void;
|
|
22
|
+
list: () => JEvents | null;
|
|
23
|
+
at: () => { week: number };
|
|
24
|
+
holds: (day: number) => boolean;
|
|
25
|
+
go: (week: number) => void;
|
|
26
|
+
moving: (moved: { key: number; week: number } | null) => void;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class Writes {
|
|
30
|
+
#form: EventForm;
|
|
31
|
+
#from: From;
|
|
32
|
+
|
|
33
|
+
/** Sent from `form`. */
|
|
34
|
+
constructor(form: EventForm, from: From) {
|
|
35
|
+
[this.#form, this.#from] = [form, from];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A write sent: refused, why, in the form, and everything drawn from the document again. Whether it was done. */
|
|
39
|
+
async answered(request: Promise<Answer> | undefined) {
|
|
40
|
+
const why = await request;
|
|
41
|
+
if (why) (this.#from.say(why), this.#from.placeAll());
|
|
42
|
+
return !why;
|
|
43
|
+
}
|
|
44
|
+
/** The picked event's changes, as the form has them. */
|
|
45
|
+
async save(el: JEvent) {
|
|
46
|
+
const { replaced, removed } = this.#form.edits(el.data),
|
|
47
|
+
gates = this.#form.gateEdits(el.data);
|
|
48
|
+
if (removed.length) this.answered(el.removeField(...removed));
|
|
49
|
+
// who comes or goes, each id linked or unlinked as the stories write them: those going off it before it changes,
|
|
50
|
+
// so nobody comes or goes at an event they're not on; those coming, once they're on it
|
|
51
|
+
for (const { g, k } of gates.filter((x) => !x.on)) await this.answered(el.unlink(g, k));
|
|
52
|
+
const linking = () => Promise.all(gates.filter((x) => x.on).map(({ g, k }) => this.answered(el.link(g, k))));
|
|
53
|
+
if (!Object.keys(replaced).length) return void linking();
|
|
54
|
+
// moved off the week: known before it's told gone, which may come before the answer
|
|
55
|
+
const week = replaced.start ? mondayOf(dayOf(replaced.start)) : this.#from.at().week;
|
|
56
|
+
if (!this.#from.holds(week)) this.#from.moving({ key: el.key, week });
|
|
57
|
+
const ok = await this.answered(el.replace(replaced));
|
|
58
|
+
await linking();
|
|
59
|
+
if (ok) this.#from.go(week);
|
|
60
|
+
else this.#from.moving(null);
|
|
61
|
+
}
|
|
62
|
+
/** The new event, as the form has it: sent, the modal closes, and the event comes as its change; refused, it's asked
|
|
63
|
+
* again as it was, saying why. */
|
|
64
|
+
async add() {
|
|
65
|
+
const form = this.#form,
|
|
66
|
+
{ title, start, duration, zone, location, coordinates } = form.formed();
|
|
67
|
+
const typed = form.values(),
|
|
68
|
+
chosen = form.chosen;
|
|
69
|
+
this.#from.close();
|
|
70
|
+
const why = await this.#from.list()!.add({
|
|
71
|
+
title,
|
|
72
|
+
...(start ? { start, duration } : {}),
|
|
73
|
+
...(zone ? { zone } : {}),
|
|
74
|
+
...(location ? { location } : {}),
|
|
75
|
+
...(coordinates ? { coordinates } : {}),
|
|
76
|
+
...(form.chosen.length ? { people: form.chosen } : {}),
|
|
77
|
+
...Object.fromEntries(ANSWERS.map((a) => [a, form.answered(a)]).filter(([, ks]) => ks!.length)),
|
|
78
|
+
...Object.fromEntries(
|
|
79
|
+
(["arrives", "leaves"] as const)
|
|
80
|
+
.map((g) => [g, [...form.gates[g]].sort((a, b) => a - b)])
|
|
81
|
+
.filter(([, ks]) => ks!.length),
|
|
82
|
+
),
|
|
83
|
+
} as JEventValue);
|
|
84
|
+
if (!why) return void (start && this.#from.go(mondayOf(dayOf(start))));
|
|
85
|
+
this.#from.new(typed);
|
|
86
|
+
form.chosen = chosen;
|
|
87
|
+
form.chips();
|
|
88
|
+
this.#from.redraw();
|
|
89
|
+
this.#from.say(why);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The time zone an event's clock is in: one the world names, as this browser knows them, found by typing in the
|
|
2
|
+
// event's form (docs/design.md, "Choosing": there are hundreds, too many to offer as chips).
|
|
3
|
+
|
|
4
|
+
import { typeahead } from "joined/parts";
|
|
5
|
+
|
|
6
|
+
/** The time zones the world names, as this browser knows them. */
|
|
7
|
+
const ZONES = ["UTC", ...Intl.supportedValuesOf("timeZone")];
|
|
8
|
+
|
|
9
|
+
/** A zone's field: the zones holding what's typed offered beneath it in `list`; one picked is told to `pick`. */
|
|
10
|
+
export const zones = (field: HTMLInputElement, list: HTMLElement, pick: (zone: string) => void) =>
|
|
11
|
+
typeahead(
|
|
12
|
+
field,
|
|
13
|
+
list,
|
|
14
|
+
() => ZONES.map((z, i) => [i, z]),
|
|
15
|
+
(i) => pick(ZONES[i]!),
|
|
16
|
+
);
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// A trip's card on the trips' page, <j-trip> given a look: a link to the trip's own page, /trip/<key>, drawn from the
|
|
2
|
+
// trip and that trip's events (trip:<key>, held whole beside the trips while the card is on the page): its map with
|
|
3
|
+
// a pin for each event (./map.ts), its name, its days and places, what's next, and who's on it. It's made again only
|
|
4
|
+
// when what it shows has changed.
|
|
5
|
+
|
|
6
|
+
import { members, signedIn } from "joined/panel";
|
|
7
|
+
import { chip } from "joined/parts";
|
|
8
|
+
import { collections } from "./generated/rules.ts";
|
|
9
|
+
import { JTrip } from "./generated/elements.ts";
|
|
10
|
+
import { collections as trip } from "../trip/generated/rules.ts";
|
|
11
|
+
import { JEvent, type JEvents } from "../trip/generated/elements.ts";
|
|
12
|
+
import { DAY, dated, dayOf, hhmm, now, wall } from "../trip/time.ts";
|
|
13
|
+
import { and } from "../trip/words.ts";
|
|
14
|
+
import { mapOf } from "./map.ts";
|
|
15
|
+
|
|
16
|
+
const held = document.querySelector<HTMLElement>(".held")!;
|
|
17
|
+
let me: number | undefined;
|
|
18
|
+
|
|
19
|
+
/** A member's name, as the group's document has it. */
|
|
20
|
+
const nameOf = (id: number) => [...members].find((m) => m.key === id)?.data.name ?? "Someone";
|
|
21
|
+
const today = () => dayOf(now());
|
|
22
|
+
|
|
23
|
+
type Event = { key: number; title: string; start: string; location?: string; coordinates?: string };
|
|
24
|
+
|
|
25
|
+
/** The trip's events, as its document holds them, in order. */
|
|
26
|
+
function eventsOf(key: number): Event[] {
|
|
27
|
+
const els = held.querySelector<JEvents>(`[doc="trip:${key}"]`)?.items ?? [];
|
|
28
|
+
return els
|
|
29
|
+
.map((el) => ({ key: el.key, ...(el.data as Omit<Event, "key">) }))
|
|
30
|
+
.sort((a, b) => a.start.localeCompare(b.start));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Its days: "3–7 November 2026", "30 October – 2 November 2026", or one day. */
|
|
34
|
+
function daysOf(first: number, last: number) {
|
|
35
|
+
if (first === last) return dated(first, { day: "numeric", month: "long", year: "numeric" });
|
|
36
|
+
const [a, b] = [new Date(first * DAY), new Date(last * DAY)];
|
|
37
|
+
const sameMonth = a.getUTCMonth() === b.getUTCMonth() && a.getUTCFullYear() === b.getUTCFullYear();
|
|
38
|
+
return sameMonth
|
|
39
|
+
? `${a.getUTCDate()}–${dated(last, { day: "numeric", month: "long", year: "numeric" })}`
|
|
40
|
+
: `${dated(first, { day: "numeric", month: "long" })} – ${dated(last, { day: "numeric", month: "long", year: "numeric" })}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** When an event is, as a person would say it from today: "today", "tomorrow", or its day. */
|
|
44
|
+
function whenOf(e: Event) {
|
|
45
|
+
const d = dayOf(e.start),
|
|
46
|
+
gap = d - today();
|
|
47
|
+
return gap === 0 ? "today" : gap === 1 ? "tomorrow" : dated(d, { weekday: "short", day: "numeric", month: "short" });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
class Trip extends JTrip {
|
|
51
|
+
#card = Object.assign(document.createElement("a"), { className: "card" });
|
|
52
|
+
#shows = ""; // what its card last showed: drawn again only when that's changed
|
|
53
|
+
connectedCallback() {
|
|
54
|
+
if (!this.#card.isConnected) this.append(this.#card);
|
|
55
|
+
// its events, held beside the trips while it's here
|
|
56
|
+
if (!held.querySelector(`[doc="trip:${this.key}"]`)) {
|
|
57
|
+
const events = document.createElement(trip.events.place);
|
|
58
|
+
events.setAttribute("doc", `trip:${this.key}`);
|
|
59
|
+
new MutationObserver(() => this.draw()).observe(events, { subtree: true, childList: true, attributes: true });
|
|
60
|
+
held.append(events);
|
|
61
|
+
}
|
|
62
|
+
this.draw();
|
|
63
|
+
}
|
|
64
|
+
disconnectedCallback() {
|
|
65
|
+
held.querySelector(`[doc="trip:${this.key}"]`)?.remove();
|
|
66
|
+
}
|
|
67
|
+
/** Its card: its map, its name, its days and places, what's next, and who's on it; made again only when what it
|
|
68
|
+
* shows has changed (an event's other fields, or a name not on it, leave it as it is). */
|
|
69
|
+
draw() {
|
|
70
|
+
const events = eventsOf(this.key),
|
|
71
|
+
{ name, organisers, travellers } = this.data;
|
|
72
|
+
const shows = JSON.stringify([
|
|
73
|
+
events,
|
|
74
|
+
name,
|
|
75
|
+
organisers,
|
|
76
|
+
travellers,
|
|
77
|
+
me,
|
|
78
|
+
[...organisers, ...travellers].map(nameOf),
|
|
79
|
+
now().slice(0, 16),
|
|
80
|
+
]);
|
|
81
|
+
if (shows === this.#shows) return;
|
|
82
|
+
this.#shows = shows;
|
|
83
|
+
const body = Object.assign(document.createElement("div"), { className: "body" });
|
|
84
|
+
const title = Object.assign(document.createElement("b"), { className: "name", textContent: name });
|
|
85
|
+
const about = Object.assign(document.createElement("span"), { className: "about" });
|
|
86
|
+
const next = Object.assign(document.createElement("div"), { className: "next" });
|
|
87
|
+
if (events.length) {
|
|
88
|
+
const places = [
|
|
89
|
+
...new Set(events.flatMap((e) => (e.location?.includes(",") ? [e.location.split(",").at(-1)!.trim()] : []))),
|
|
90
|
+
];
|
|
91
|
+
about.textContent = [
|
|
92
|
+
daysOf(dayOf(events[0]!.start), dayOf(events.at(-1)!.start)),
|
|
93
|
+
`${events.length} event${events.length === 1 ? "" : "s"}`,
|
|
94
|
+
...(places.length ? [and(places)] : []),
|
|
95
|
+
].join(" · ");
|
|
96
|
+
const coming = events.find((e) => e.start >= now().slice(0, 16));
|
|
97
|
+
const e = coming ?? events.at(-1)!;
|
|
98
|
+
next.append(
|
|
99
|
+
Object.assign(document.createElement("span"), {
|
|
100
|
+
className: "label",
|
|
101
|
+
textContent: `${coming ? "Next" : "Last"} · ${whenOf(e)}`,
|
|
102
|
+
}),
|
|
103
|
+
Object.assign(document.createElement("b"), { textContent: e.title }),
|
|
104
|
+
Object.assign(document.createElement("span"), {
|
|
105
|
+
textContent: [
|
|
106
|
+
`${dated(dayOf(e.start), { weekday: "short", day: "numeric", month: "short" })}, ${hhmm(wall(e.start))}`,
|
|
107
|
+
...(e.location ? [e.location] : []),
|
|
108
|
+
].join(" · "),
|
|
109
|
+
}),
|
|
110
|
+
);
|
|
111
|
+
} else {
|
|
112
|
+
about.textContent = "No dates yet";
|
|
113
|
+
next.classList.add("empty");
|
|
114
|
+
next.append(
|
|
115
|
+
Object.assign(document.createElement("b"), { textContent: "Nothing planned yet" }),
|
|
116
|
+
Object.assign(document.createElement("span"), {
|
|
117
|
+
textContent: "Open it and drag down a day to add the first event, or tap its map.",
|
|
118
|
+
}),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
const people = Object.assign(document.createElement("div"), { className: "people" });
|
|
122
|
+
people.append(
|
|
123
|
+
...organisers.map((id) => chip(id, nameOf(id), `${id === me ? "You" : nameOf(id)}, organising`)),
|
|
124
|
+
...travellers
|
|
125
|
+
.filter((id) => !organisers.includes(id))
|
|
126
|
+
.map((id) => chip(id, nameOf(id), id === me ? "You" : nameOf(id))),
|
|
127
|
+
);
|
|
128
|
+
body.append(title, about, next, people);
|
|
129
|
+
this.#card.href = `/trip/${this.key}`;
|
|
130
|
+
this.#card.replaceChildren(mapOf(events), body);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** The trips on the page: a live list. */
|
|
134
|
+
const cards = document.getElementsByTagName(collections.trips.tag) as HTMLCollectionOf<Trip>;
|
|
135
|
+
// who this page is: told by the group's document, and the cards drawn again with "You" in them
|
|
136
|
+
signedIn((m) => {
|
|
137
|
+
me = m;
|
|
138
|
+
for (const t of cards) t.draw();
|
|
139
|
+
});
|
|
140
|
+
// a name changed in the group: the cards that name them say it
|
|
141
|
+
const group = document.querySelector("members-panel");
|
|
142
|
+
if (group)
|
|
143
|
+
new MutationObserver(() => {
|
|
144
|
+
for (const t of cards) t.draw();
|
|
145
|
+
}).observe(group, { subtree: true, attributes: true, attributeFilter: ["name"] });
|
|
146
|
+
|
|
147
|
+
// defined last, once all they draw with is made: a trip's events, held as they are, which its card draws; and the trips
|
|
148
|
+
customElements.define(trip.events.tag, JEvent);
|
|
149
|
+
customElements.define(collections.trips.tag, Trip);
|