@blueshed/joined 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/joined/SKILL.md +9 -1
- package/.claude/skills/joined/reference.md +267 -53
- package/.claude/skills/joined-door/SKILL.md +57 -0
- package/README.md +19 -50
- package/docs/design.md +76 -10
- package/docs/introduction.md +18 -18
- package/docs/light-and-shadow.svg +1 -1
- package/examples/README.md +20 -0
- package/examples/account/account.json +1 -0
- package/examples/account/derive.ts +41 -0
- package/examples/account/generated/elements.ts +52 -0
- package/examples/account/generated/rows.ts +22 -0
- package/examples/account/generated/rules.ts +32 -0
- package/examples/account/routes.ts +5 -0
- package/examples/app.css +2 -1
- package/examples/cafe/books.html +2 -2
- package/examples/cafe/cafe.css +9 -16
- package/examples/cafe/generated/books.rows.ts +22 -0
- package/examples/cafe/generated/books.rules.ts +3 -2
- package/examples/cafe/generated/kitchen.rows.ts +27 -0
- package/examples/cafe/generated/kitchen.rules.ts +11 -1
- package/examples/cafe/generated/menu.rows.ts +22 -0
- package/examples/cafe/generated/menu.rules.ts +3 -2
- package/examples/cafe/generated/order.rows.ts +27 -0
- package/examples/cafe/generated/order.rules.ts +11 -1
- package/examples/cafe/generated/staff.rows.ts +22 -0
- package/examples/cafe/generated/staff.rules.ts +6 -1
- package/examples/cafe/generated/supplies.queries.ts +4 -2
- package/examples/cafe/generated/supplies.rows.ts +22 -0
- package/examples/cafe/generated/supplies.rules.ts +12 -1
- package/examples/cafe/generated/till.queries.ts +2 -0
- package/examples/cafe/generated/till.rows.ts +27 -0
- package/examples/cafe/generated/till.rules.ts +11 -1
- package/examples/cafe/index.html +14 -15
- package/examples/cafe/kitchen.ts +1 -1
- package/examples/cafe/look.ts +30 -0
- package/examples/cafe/menu.html +10 -26
- package/examples/cafe/menu.ts +8 -80
- package/examples/cafe/order.html +6 -6
- package/examples/cafe/order.ts +5 -1
- package/examples/cafe/routes.ts +0 -1
- package/examples/cafe/stories.jsonl +3 -1
- package/examples/cafe/supplies.html +34 -34
- package/examples/cafe/supplies.ts +14 -11
- package/examples/cafe/till.ts +5 -1
- package/examples/chart/arches.ts +148 -0
- package/examples/chart/chart.css +6 -0
- package/examples/chart/chart.json +87 -0
- package/examples/chart/generated/elements.ts +105 -0
- package/examples/chart/generated/queries.ts +36 -0
- package/examples/chart/generated/rows.ts +27 -0
- package/examples/chart/generated/rules.ts +111 -0
- package/examples/chart/grid.ts +118 -0
- package/examples/chart/index.html +78 -0
- package/examples/chart/migrations/001-chart.ts +6 -0
- package/examples/chart/migrations/002-create-conditions.ts +6 -0
- package/examples/chart/page.ts +20 -0
- package/examples/chart/routes.ts +7 -0
- package/examples/chart/stories.jsonl +14 -0
- package/examples/chart/teeth.ts +57 -0
- package/examples/desk/generated/rows.ts +22 -0
- package/examples/desk/generated/rules.ts +34 -1
- package/examples/desk/index.html +9 -2
- package/examples/desk/routes.ts +0 -2
- package/examples/desk/stories.jsonl +3 -2
- package/examples/desk/thumbs.ts +2 -2
- package/examples/hello/generated/elements.ts +2 -2
- package/examples/hello/generated/rules.ts +3 -2
- package/examples/hello/hello.css +2 -4
- package/examples/hello/index.html +10 -3
- package/examples/hello/page.ts +4 -4
- package/examples/index.html +4 -5
- package/examples/notes/generated/elements.ts +112 -0
- package/examples/notes/generated/queries.ts +36 -0
- package/examples/notes/generated/rows.ts +27 -0
- package/examples/notes/generated/rules.ts +133 -0
- package/examples/notes/index.html +32 -0
- package/examples/notes/look.ts +41 -0
- package/examples/notes/migrations/001-notes.ts +7 -0
- package/examples/notes/notes.json +78 -0
- package/examples/notes/page.ts +21 -0
- package/examples/notes/routes.ts +6 -0
- package/examples/notes/stories.jsonl +21 -0
- package/examples/people/generated/rows.ts +22 -0
- package/examples/people/generated/rules.ts +11 -1
- package/examples/people/links.ts +2 -1
- package/examples/people/routes.ts +1 -3
- package/examples/people/stories.jsonl +1 -0
- package/examples/people/view.ts +5 -2
- package/examples/trip/generated/elements.ts +4 -2
- package/examples/trip/generated/queries.ts +12 -1
- package/examples/trip/generated/rows.ts +27 -0
- package/examples/trip/generated/rules.ts +56 -2
- package/examples/trip/index.html +58 -12
- package/examples/trip/line.css +186 -0
- package/examples/trip/line.ts +51 -40
- package/examples/trip/page.ts +65 -71
- package/examples/trip/routes.ts +9 -5
- package/examples/trip/stays.css +12 -12
- package/examples/trip/stays.ts +15 -10
- package/examples/trip/stories.jsonl +2 -0
- package/examples/trip/told.ts +3 -26
- package/examples/trip/trip.css +16 -0
- package/examples/trips/generated/rows.ts +22 -0
- package/examples/trips/generated/rules.ts +9 -1
- package/examples/trips/index.html +10 -10
- package/examples/trips/map.ts +3 -14
- package/examples/trips/new-trip.ts +14 -16
- package/examples/weeks/generated/elements.ts +1 -1
- package/examples/weeks/generated/queries.ts +11 -0
- package/examples/weeks/generated/rows.ts +22 -0
- package/examples/weeks/generated/rules.ts +11 -5
- package/examples/weeks/routes.ts +3 -2
- package/examples/weeks/stories.jsonl +1 -0
- package/examples/welcome.css +7 -5
- package/package.json +8 -2
- package/src/awesome.ts +103 -0
- package/src/board.css +75 -0
- package/src/board.ts +173 -0
- package/src/cli.ts +15 -2
- package/src/compile.ts +569 -35
- package/src/definitions.ts +53 -15
- package/src/draft.ts +38 -23
- package/src/drawer.ts +222 -0
- package/src/engine.ts +240 -166
- package/src/fields.ts +268 -0
- package/src/files.ts +6 -4
- package/src/ground.ts +110 -0
- package/src/icon-names.ts +15 -2
- package/src/kit.ts +51 -0
- package/src/link.ts +3 -3
- package/src/map.css +133 -0
- package/src/map.ts +200 -0
- package/src/mcp.ts +106 -22
- package/src/members/demo.ts +13 -12
- package/src/members/generated/rows.ts +22 -0
- package/src/members/generated/rules.ts +3 -2
- package/src/members/group.ts +65 -39
- package/src/members/keys.ts +93 -77
- package/src/members/panel.css +23 -17
- package/src/members/panel.ts +49 -35
- package/src/migrate.ts +120 -104
- package/src/month.css +125 -0
- package/src/month.ts +179 -0
- package/src/page.css +8 -0
- package/src/page.ts +7 -4
- package/src/parts.css +462 -170
- package/src/parts.ts +209 -26
- package/src/plane.css +56 -0
- package/src/plane.ts +151 -0
- package/src/postgres-server.ts +60 -0
- package/src/reading.css +77 -0
- package/src/reading.ts +238 -0
- package/src/rows.css +308 -0
- package/src/rows.ts +780 -0
- package/src/search.css +80 -0
- package/src/search.ts +130 -0
- package/src/server.ts +205 -114
- package/src/settings.ts +9 -4
- package/src/sheet.ts +114 -0
- package/src/skill.ts +40 -0
- package/src/slots.css +94 -0
- package/src/slots.ts +213 -0
- package/src/specs.ts +38 -0
- package/src/starter.ts +5 -2
- package/src/store.ts +184 -143
- package/src/stories.ts +43 -11
- package/src/surface.ts +159 -0
- package/src/timeline.css +111 -0
- package/src/timeline.ts +226 -0
- package/src/toast.ts +21 -48
- package/src/together.ts +0 -7
- package/src/tokens.css +78 -1
- package/src/tokens.json +249 -0
- package/src/tool.ts +211 -0
- package/src/upkeep.ts +18 -20
- package/src/views.css +44 -0
- package/src/views.ts +94 -0
- package/src/week.css +151 -0
- package/src/week.ts +250 -0
- package/src/write.ts +202 -69
- package/starter/CLAUDE.md +3 -3
- package/starter/bunfig +4 -0
- package/starter/prettierignore +4 -0
- package/starter/tests/hello.test.ts +2 -0
- package/docs/learning.md +0 -76
- package/examples/cafe/trust.ts +0 -20
- package/examples/desk/trust.ts +0 -24
- package/examples/people/trust.ts +0 -14
- package/examples/trip/answer-rows.ts +0 -70
- package/examples/trip/bar.ts +0 -89
- package/examples/trip/calendar-map.css +0 -711
- package/examples/trip/calendar-map.ts +0 -249
- package/examples/trip/drags.ts +0 -143
- package/examples/trip/drawer.ts +0 -250
- package/examples/trip/event-form.ts +0 -200
- package/examples/trip/holding.ts +0 -61
- package/examples/trip/map.ts +0 -234
- package/examples/trip/month.ts +0 -87
- package/examples/trip/other-weeks.ts +0 -67
- package/examples/trip/peek.ts +0 -71
- package/examples/trip/people-chips.ts +0 -74
- package/examples/trip/shell.ts +0 -39
- package/examples/trip/trust.ts +0 -51
- package/examples/trip/week.ts +0 -237
- package/examples/trip/writes.ts +0 -91
- package/examples/trip/zones.ts +0 -16
- package/examples/weeks/derive.ts +0 -23
- package/src/scrim.ts +0 -81
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
// <calendar-map>: the trip's events as a week and a map. It holds a week of the document's events, a
|
|
2
|
-
// <j-events doc="trip:1?week=2026-11-02"> of <j-event>s (each field an attribute), and never shows them: it watches
|
|
3
|
-
// that child and draws both in its shadow, moving only the event that changed; read as a line or a month, too.
|
|
4
|
-
// Picking an event on either picks it on both and opens it in a drawer, and a "pick" sent to one of its events (from
|
|
5
|
-
// the people's links) picks it. What's open is in the URL's hash (#event=2; another calendar on the page names its
|
|
6
|
-
// own, hash="…"): Back closes it, and a link with it opens it again.
|
|
7
|
-
// This file is what it holds, its lifecycle, and how a change reaches each part, a file each: what it holds
|
|
8
|
-
// (./holding.ts) and is told of (./told.ts), its shadow (./shell.ts), its bar (./bar.ts), the week as a calendar
|
|
9
|
-
// (./week.ts), the map (./map.ts) and a pin peeked on it (./peek.ts), the month (./month.ts), the line (./line.ts),
|
|
10
|
-
// the other weeks (./other-weeks.ts), the drawer round the event's form (./drawer.ts, ./event-form.ts) and its writes
|
|
11
|
-
// (./writes.ts), and what a hand gives by dragging (./drags.ts).
|
|
12
|
-
|
|
13
|
-
import type { JEvent } from "./generated/elements.ts";
|
|
14
|
-
import { iconify } from "joined/icons";
|
|
15
|
-
import { inHash } from "joined/parts";
|
|
16
|
-
import { collections as trip } from "./generated/rules.ts";
|
|
17
|
-
import { collections as weeks } from "../weeks/generated/rules.ts";
|
|
18
|
-
import { type Part, shell } from "./shell.ts";
|
|
19
|
-
import { Holding } from "./holding.ts";
|
|
20
|
-
import { Told } from "./told.ts";
|
|
21
|
-
import { Bar, type Reading } from "./bar.ts";
|
|
22
|
-
import { EARLY, LATE, Week } from "./week.ts";
|
|
23
|
-
import { MapView, type View } from "./map.ts";
|
|
24
|
-
import { Peek } from "./peek.ts";
|
|
25
|
-
import { Month } from "./month.ts";
|
|
26
|
-
import { Line } from "./line.ts";
|
|
27
|
-
import { OtherWeeks } from "./other-weeks.ts";
|
|
28
|
-
import { Drawer } from "./drawer.ts";
|
|
29
|
-
import { Drags } from "./drags.ts";
|
|
30
|
-
|
|
31
|
-
/** What the week, its hours and the map's view read of an event: a change to anything else of it moves it alone. */
|
|
32
|
-
const FRAMED = ["start", "duration", "coordinates"];
|
|
33
|
-
/** Every change beneath what it watches. */
|
|
34
|
-
const EVERY = { childList: true, subtree: true, attributes: true };
|
|
35
|
-
/** What everything is drawn by, as last drawn: the week, its hours, and the map's view and size. Said as a string with
|
|
36
|
-
* a phone's day and whether it's a month, it's compared: a change that leaves it as it was moves only what changed. */
|
|
37
|
-
type Frame = { week: number; from: number; to: number; view: View; W: number; H: number };
|
|
38
|
-
|
|
39
|
-
class CalendarMap extends HTMLElement {
|
|
40
|
-
#root = this.attachShadow({ mode: "open" });
|
|
41
|
-
/** One of its own parts, found once: searched for on each change, it's sought past every block the week holds. */
|
|
42
|
-
#parts = new Map<string, HTMLElement>();
|
|
43
|
-
#part: Part = (s) => this.#parts.get(s) ?? this.#parts.set(s, this.#root.querySelector<HTMLElement>(s)!).get(s)!;
|
|
44
|
-
#frame = "";
|
|
45
|
-
#at: Frame = { week: 0, from: EARLY, to: LATE, view: { z: 0, x: 0, y: 0 }, W: 0, H: 0 };
|
|
46
|
-
#picked: JEvent | null = null;
|
|
47
|
-
#moved: { key: number; week: number } | null = null; // an event kept on another week, to open once it's held
|
|
48
|
-
/** What a person chose, kept while it's moved or put back: the day a phone shows (and the week it was chosen in),
|
|
49
|
-
* and where they moved the map, on the week they moved it. */
|
|
50
|
-
#chose = { day: 0, dayWeek: null as number | null, looked: null as { week: number; view: View } | null };
|
|
51
|
-
/** What it listens to beyond its shadow (the window, the page, the lists it's told of): let go once it's gone from
|
|
52
|
-
* the page, and made again if it's put back. */
|
|
53
|
-
#gone: AbortController | null = null;
|
|
54
|
-
/** The event open, in the URL's hash (#event=2): Back closes it, and a link with it opens it again. */
|
|
55
|
-
#hash!: ReturnType<typeof inHash>;
|
|
56
|
-
#phone = matchMedia("(max-width: 40rem)"); // a phone: one day of the week shown, picked in the strip
|
|
57
|
-
/** The week read as a line (view="line"), or the trip as a month (view="month"); else as a calendar. */
|
|
58
|
-
#lined = () => this.getAttribute("view") === "line";
|
|
59
|
-
#monthly = () => this.getAttribute("view") === "month";
|
|
60
|
-
#holding = new Holding(this, { at: () => this.#at, monthly: this.#monthly });
|
|
61
|
-
#told = new Told(this);
|
|
62
|
-
// its parts, made again each time it's put on the page
|
|
63
|
-
#bar!: Bar;
|
|
64
|
-
#week!: Week;
|
|
65
|
-
#map!: MapView;
|
|
66
|
-
#peek!: Peek;
|
|
67
|
-
#month!: Month;
|
|
68
|
-
#line!: Line;
|
|
69
|
-
#others!: OtherWeeks;
|
|
70
|
-
#drawer!: Drawer;
|
|
71
|
-
#drags!: Drags;
|
|
72
|
-
|
|
73
|
-
connectedCallback() {
|
|
74
|
-
if (this.#gone && !this.#gone.signal.aborted) return; // moved on the page: it listens as it did
|
|
75
|
-
const { signal } = (this.#gone = new AbortController());
|
|
76
|
-
/** A watcher of what's beyond its shadow, let go with it. */
|
|
77
|
-
const watch = <O extends { disconnect(): void }>(o: O) => (
|
|
78
|
-
signal.addEventListener("abort", () => o.disconnect()),
|
|
79
|
-
o
|
|
80
|
-
);
|
|
81
|
-
// put back: drawn afresh
|
|
82
|
-
[this.#parts, this.#frame, this.#picked] = [new Map(), "", null];
|
|
83
|
-
const { events, list, held, go, holds, hold } = this.#holding,
|
|
84
|
-
{ people, persons, stays } = this.#told,
|
|
85
|
-
picked = () => this.#picked,
|
|
86
|
-
opened = (el: JEvent | null) => this.#pick(el, true, false); // as the hash says: marked there already
|
|
87
|
-
this.#hash = inHash(this.getAttribute("hash") ?? "event", events, picked, opened, signal);
|
|
88
|
-
shell(this, this.#root);
|
|
89
|
-
const $ = this.#part;
|
|
90
|
-
// what its parts read of it and ask of it, each part's own From saying which
|
|
91
|
-
const cal = {
|
|
92
|
-
...{ events, list, held, go, holds, hold, people, persons, stays, picked, chose: this.#chose },
|
|
93
|
-
at: () => this.#at,
|
|
94
|
-
week: () => this.#at.week,
|
|
95
|
-
pick: (el: JEvent | null, dock?: boolean, mark?: boolean) => this.#pick(el, dock, mark),
|
|
96
|
-
place: (el: JEvent) => this.#place(el),
|
|
97
|
-
placeAll: () => this.#placeAll(),
|
|
98
|
-
changed: () => this.#changed([]),
|
|
99
|
-
reframe: () => (this.#at = JSON.parse((this.#frame = this.#frameOf()))),
|
|
100
|
-
phone: () => this.#phone.matches,
|
|
101
|
-
lined: this.#lined,
|
|
102
|
-
monthly: this.#monthly,
|
|
103
|
-
read: () => this.#read(),
|
|
104
|
-
readAs: (view: Reading) => this.#bar.readAs(view),
|
|
105
|
-
moving: (moved: { key: number; week: number } | null) => (this.#moved = moved),
|
|
106
|
-
add: () => this.#drawer.new(),
|
|
107
|
-
drags: () => this.#drags,
|
|
108
|
-
peek: () => this.#peek,
|
|
109
|
-
drawer: () => this.#drawer,
|
|
110
|
-
};
|
|
111
|
-
this.#bar = new Bar(this, $, cal);
|
|
112
|
-
this.#week = new Week(this, $, cal);
|
|
113
|
-
this.#map = new MapView($, cal);
|
|
114
|
-
this.#peek = new Peek($, this.#map, cal, this.#root, signal);
|
|
115
|
-
this.#month = new Month($, cal);
|
|
116
|
-
this.#line = new Line($(".faces"), $(".line"), cal, signal);
|
|
117
|
-
this.#others = new OtherWeeks(this, $, cal);
|
|
118
|
-
this.#drawer = new Drawer(this, $, this.#week, this.#map, cal, signal);
|
|
119
|
-
this.#drags = new Drags(this.#week, this.#map, this.#drawer, this.#peek, cal);
|
|
120
|
-
iconify(this.#root);
|
|
121
|
-
this.#phone.addEventListener("change", () => ((this.#frame = ""), this.#changed([])), { signal });
|
|
122
|
-
this.addEventListener(
|
|
123
|
-
"pick",
|
|
124
|
-
(e) => (e.target as Element).localName === trip.events.tag && this.#pick(e.target as JEvent),
|
|
125
|
-
{ signal },
|
|
126
|
-
);
|
|
127
|
-
watch(new MutationObserver((records) => this.#changed(records))).observe(this, EVERY);
|
|
128
|
-
this.#told.watch(
|
|
129
|
-
watch,
|
|
130
|
-
// a person renamed, or one come or gone, or said to be someone: only the events that link to them placed again
|
|
131
|
-
(keys) => {
|
|
132
|
-
const names = people();
|
|
133
|
-
for (const el of events()) if (el.data.people.some((k) => keys.has(k))) this.#place(el, names);
|
|
134
|
-
this.#drawer.form.chips();
|
|
135
|
-
this.#read();
|
|
136
|
-
},
|
|
137
|
-
// a stay booked, changed or cancelled: the line, which draws them, again
|
|
138
|
-
() => this.#read(),
|
|
139
|
-
);
|
|
140
|
-
// drawn once an event is an element of its own: the page defines it after this, over events it may hold
|
|
141
|
-
// already (served with the page); then what the URL's hash says is open, opened
|
|
142
|
-
customElements.whenDefined(trip.events.tag).then(() => (opened(null), this.#changed([])));
|
|
143
|
-
// the map's size follows the page (a window resized, a phone turned): its view is fitted again
|
|
144
|
-
watch(new ResizeObserver(() => this.#changed([]))).observe(this.#map.el);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
disconnectedCallback() {
|
|
148
|
-
// gone from the page, not moved (a move connects it again first): what it listens to beyond itself let go
|
|
149
|
-
queueMicrotask(() => this.isConnected || this.#gone?.abort());
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/** A change drawn, its events read at most once (./holding.ts). */
|
|
153
|
-
#changed = (records: MutationRecord[]) => this.#holding.changing(() => this.#onChange(records));
|
|
154
|
-
#onChange(records: MutationRecord[]) {
|
|
155
|
-
const { events, list: listed, held } = this.#holding;
|
|
156
|
-
// the trip's weeks changed, and nothing else: what's on its other weeks is said again
|
|
157
|
-
if (records.length && records.every((r) => (r.target as Element).closest(weeks.weeks.place)))
|
|
158
|
-
return void (listed() && this.#others.draw());
|
|
159
|
-
if (!held().week) return; // no week held yet: nothing to draw
|
|
160
|
-
// what moves the week, its hours, the map's view and the lists: an event come or gone, an event's day, length or
|
|
161
|
-
// place, anything but an event changed, or nothing said (drawn afresh). Any other change (a title, its people)
|
|
162
|
-
// moves only its own block and pin, so a change costs the same however many events there are
|
|
163
|
-
const framed =
|
|
164
|
-
!records.length ||
|
|
165
|
-
records.some(
|
|
166
|
-
(r) =>
|
|
167
|
-
r.type === "childList" ||
|
|
168
|
-
(r.target as Element).localName !== trip.events.tag ||
|
|
169
|
-
FRAMED.includes(r.attributeName!),
|
|
170
|
-
);
|
|
171
|
-
const list = listed();
|
|
172
|
-
if (framed) {
|
|
173
|
-
(this.#week.drop(list), this.#map.drop(list));
|
|
174
|
-
// the picked event gone (from the week, or moved off it here: its hash kept, for the week it's opened on)
|
|
175
|
-
if (this.#picked && this.#picked.parentNode !== list)
|
|
176
|
-
this.#pick(null, true, this.#picked.key !== this.#moved?.key);
|
|
177
|
-
}
|
|
178
|
-
const touched = new Set<Node>(records.flatMap((r) => (r.type === "attributes" ? [r.target] : [...r.addedNodes])));
|
|
179
|
-
// the form first, whatever moves: the event in it is drawn as the form has it, on the week it's on
|
|
180
|
-
if (this.#picked && touched.has(this.#picked)) (this.#drawer.fill(this.#picked), this.#week.follow(this.#picked));
|
|
181
|
-
// the week shown, its hours and the map's view follow the events: if they move, everything is placed again
|
|
182
|
-
const frame = framed ? this.#frameOf() : this.#frame;
|
|
183
|
-
if (frame !== this.#frame) {
|
|
184
|
-
[this.#frame, this.#at] = [frame, JSON.parse(frame)];
|
|
185
|
-
this.#bar.name(this.#phone.matches);
|
|
186
|
-
this.#week.draw();
|
|
187
|
-
this.#map.draw();
|
|
188
|
-
this.#placeAll();
|
|
189
|
-
} else {
|
|
190
|
-
const names = this.#told.people();
|
|
191
|
-
for (const el of touched)
|
|
192
|
-
if ((el as Element).localName === trip.events.tag && el.parentNode === list) this.#place(el as JEvent, names);
|
|
193
|
-
}
|
|
194
|
-
if (framed) (this.#others.draw(), this.#week.showDay());
|
|
195
|
-
this.#drawer.mode();
|
|
196
|
-
this.#read();
|
|
197
|
-
const { key, week } = this.#moved ?? {},
|
|
198
|
-
moved = week === this.#at.week && events().find((e) => e.key === key);
|
|
199
|
-
if (moved) ((this.#moved = null), this.#pick(moved));
|
|
200
|
-
else this.#hash.again();
|
|
201
|
-
}
|
|
202
|
-
/** The frame its events give it: the week's hours (./week.ts) and the map's view (./map.ts), as a string. */
|
|
203
|
-
#frameOf() {
|
|
204
|
-
const events = this.#holding.events(),
|
|
205
|
-
week = this.#holding.held().week!,
|
|
206
|
-
phone = this.#phone.matches && !this.#lined() && !this.#monthly();
|
|
207
|
-
const { shown, from, to } = this.#week.hours(events, week, phone);
|
|
208
|
-
const { view, W, H } = this.#map.fit(shown, events, week);
|
|
209
|
-
return JSON.stringify({ week, from, to, view, W, H, phone, day: this.#chose.day, month: this.#monthly() });
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** Each event's block on its day and its pin at its place (made once, then only moved), and what the form has. */
|
|
213
|
-
#placeAll() {
|
|
214
|
-
const names = this.#told.people();
|
|
215
|
-
for (const el of this.#holding.events()) this.#place(el, names);
|
|
216
|
-
this.#drawer.redraw();
|
|
217
|
-
}
|
|
218
|
-
#place(el: JEvent, names = this.#told.people()) {
|
|
219
|
-
const shown = this.#drawer.shown(el);
|
|
220
|
-
this.#week.place(el, shown, names);
|
|
221
|
-
this.#map.place(el, shown.title, shown.coordinates);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
/** Pick an event on both, and open it in the drawer; null closes it. What wasn't saved goes back.
|
|
225
|
-
* Picked by a press, the page makes room for the drawer once it's let go: not under the finger. What's open
|
|
226
|
-
* is marked in the URL's hash, but where the hash is what opened it. */
|
|
227
|
-
#pick(el: JEvent | null, dock = true, mark = true) {
|
|
228
|
-
// picked again: shown, what the drawer holds kept
|
|
229
|
-
if (el && el === this.#picked) return void (this.#week.follow(el) && this.#changed([]));
|
|
230
|
-
const was = this.#picked;
|
|
231
|
-
this.#week.mark(el);
|
|
232
|
-
this.#map.mark(el);
|
|
233
|
-
this.#picked = el;
|
|
234
|
-
this.#drawer.open(el);
|
|
235
|
-
if (was && was !== el && this.#week.blockOf(was)) this.#place(was);
|
|
236
|
-
if (el && this.#week.follow(el)) this.#changed([]);
|
|
237
|
-
if (dock) (this.#drawer.dock(), this.#drawer.reveal(true));
|
|
238
|
-
if (mark) this.#hash.mark(el?.key ?? null);
|
|
239
|
-
this.#read();
|
|
240
|
-
}
|
|
241
|
-
/** The week as it's read (a calendar, a line or a month), shown (./bar.ts) and drawn; read as a line, the week
|
|
242
|
-
* whole on a phone too. */
|
|
243
|
-
#read() {
|
|
244
|
-
const shown = this.#bar.show();
|
|
245
|
-
if (shown === "line") this.#line.draw();
|
|
246
|
-
if (shown === "month") this.#month.draw();
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
customElements.define("calendar-map", CalendarMap);
|
package/examples/trip/drags.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
// What a hand gives on <calendar-map>, so nothing needs typing that a hand can do: when, dragged on the week (a block
|
|
2
|
-
// moved, its length changed by its foot, or a range on a day's hours for a new event), and where, on the map (a pin
|
|
3
|
-
// moved, which names its place, or a tap to put one). Each follows the pointer (joined/follow), and once let go waits
|
|
4
|
-
// in the drawer, or, new, in the modal (./drawer.ts), until Save keeps it.
|
|
5
|
-
|
|
6
|
-
import type { JEvent } from "./generated/elements.ts";
|
|
7
|
-
import type { Drawer } from "./drawer.ts";
|
|
8
|
-
import type { MapView } from "./map.ts";
|
|
9
|
-
import type { Peek } from "./peek.ts";
|
|
10
|
-
import { label, type Week } from "./week.ts";
|
|
11
|
-
import { follow } from "joined/follow";
|
|
12
|
-
import { geo } from "joined/geo";
|
|
13
|
-
import { nameOf } from "joined/places";
|
|
14
|
-
import { DAY, hhmm, iso, local, MIN, seconds, snap, SNAP, wall } from "joined/time";
|
|
15
|
-
|
|
16
|
-
/** What a drag reads from its display: the event picked, how to pick one (making room for the drawer, or not yet, the
|
|
17
|
-
* finger still down), how to draw one again, and whether it's on a phone. */
|
|
18
|
-
type From = {
|
|
19
|
-
picked: () => JEvent | null;
|
|
20
|
-
pick: (el: JEvent | null, dock?: boolean) => void;
|
|
21
|
-
place: (el: JEvent) => void;
|
|
22
|
-
phone: () => boolean;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export class Drags {
|
|
26
|
-
#week: Week;
|
|
27
|
-
#map: MapView;
|
|
28
|
-
#drawer: Drawer;
|
|
29
|
-
#peek: Peek;
|
|
30
|
-
#from: From;
|
|
31
|
-
|
|
32
|
-
/** The week and the map it's dragged on, the drawer it waits in, and the card a pin peeks. */
|
|
33
|
-
constructor(week: Week, map: MapView, drawer: Drawer, peek: Peek, from: From) {
|
|
34
|
-
[this.#week, this.#map, this.#drawer, this.#peek, this.#from] = [week, map, drawer, peek, from];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** A block dragged to a new start, or by its foot to a new length; let go, it's in the drawer. */
|
|
38
|
-
block(el: JEvent, down: PointerEvent, foot: boolean) {
|
|
39
|
-
const week = this.#week,
|
|
40
|
-
drawer = this.#drawer;
|
|
41
|
-
this.#from.pick(el, false);
|
|
42
|
-
const block = week.blockOf(el)!;
|
|
43
|
-
const shown = drawer.shown(el),
|
|
44
|
-
start = wall(shown.start),
|
|
45
|
-
mins = seconds(shown.duration) / 60,
|
|
46
|
-
grab = week.timeAt(down) - start;
|
|
47
|
-
let to = foot ? mins : start;
|
|
48
|
-
follow(
|
|
49
|
-
down,
|
|
50
|
-
(e) => {
|
|
51
|
-
to = foot ? Math.max(SNAP, (snap(week.timeAt(e)) - start) / MIN) : snap(week.timeAt(e) - grab);
|
|
52
|
-
week.when(block, foot ? start : to, foot ? to : mins);
|
|
53
|
-
},
|
|
54
|
-
(e) => {
|
|
55
|
-
if (e && to !== (foot ? mins : start)) {
|
|
56
|
-
const at = foot ? start : to;
|
|
57
|
-
drawer.form.set("day", local(at).slice(0, 10));
|
|
58
|
-
drawer.form.set("from", hhmm(at));
|
|
59
|
-
drawer.form.set("to", hhmm(at + (foot ? to : mins) * MIN));
|
|
60
|
-
}
|
|
61
|
-
this.#from.place(el);
|
|
62
|
-
drawer.mode();
|
|
63
|
-
drawer.dock();
|
|
64
|
-
drawer.reveal(true);
|
|
65
|
-
},
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** A range dragged on a day's hours: a new event, its when given, to be asked the rest. */
|
|
70
|
-
range(down: PointerEvent) {
|
|
71
|
-
const week = this.#week,
|
|
72
|
-
drawer = this.#drawer,
|
|
73
|
-
{ block } = drawer.draft,
|
|
74
|
-
from = snap(week.timeAt(down)),
|
|
75
|
-
day = Math.floor(from / DAY);
|
|
76
|
-
let to = from + 60 * MIN;
|
|
77
|
-
this.#from.pick(null, false);
|
|
78
|
-
block.style.setProperty("--hue", drawer.hue());
|
|
79
|
-
const show = () => {
|
|
80
|
-
const [a, b] = [Math.min(from, to), Math.max(from, to)];
|
|
81
|
-
label(block, "New event", local(a), iso((b - a) / MIN));
|
|
82
|
-
week.when(block, a, (b - a) / MIN);
|
|
83
|
-
};
|
|
84
|
-
show();
|
|
85
|
-
follow(
|
|
86
|
-
down,
|
|
87
|
-
(e) => {
|
|
88
|
-
const t = snap(day * DAY + (week.timeAt(e) % DAY));
|
|
89
|
-
to = t === from ? from + SNAP * MIN : t;
|
|
90
|
-
show();
|
|
91
|
-
},
|
|
92
|
-
(e) => {
|
|
93
|
-
if (!e) return (block.remove(), drawer.dock());
|
|
94
|
-
const [a, b] = [Math.min(from, to), Math.max(from, to)];
|
|
95
|
-
drawer.new({ day: local(a).slice(0, 10), from: hhmm(a), to: hhmm(b) });
|
|
96
|
-
},
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** A pin dragged to a new place, which it names; let go, it's in the drawer. On a phone, a pin is picked once it
|
|
101
|
-
* moves: tapped, it's peeked. */
|
|
102
|
-
pin(el: JEvent, down: PointerEvent) {
|
|
103
|
-
const map = this.#map,
|
|
104
|
-
drawer = this.#drawer,
|
|
105
|
-
phone = this.#from.phone();
|
|
106
|
-
this.#peek.show(null);
|
|
107
|
-
if (!phone) this.#from.pick(el, false);
|
|
108
|
-
const pin = map.pinOf(el)!;
|
|
109
|
-
let moved = false;
|
|
110
|
-
follow(
|
|
111
|
-
down,
|
|
112
|
-
(e) => {
|
|
113
|
-
if (!moved && phone) this.#from.pick(el, false);
|
|
114
|
-
moved = true;
|
|
115
|
-
map.where(pin, map.pointAt(e));
|
|
116
|
-
},
|
|
117
|
-
(e) => {
|
|
118
|
-
if (!moved && phone) return this.#peek.show(el);
|
|
119
|
-
if (e && moved) this.#put(map.pointAt(e));
|
|
120
|
-
this.#from.place(el);
|
|
121
|
-
drawer.mode();
|
|
122
|
-
drawer.dock();
|
|
123
|
-
drawer.reveal(false);
|
|
124
|
-
},
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** A tap on the map: a pin for the picked event if it has none, or a new event there. */
|
|
129
|
-
tap(down: PointerEvent) {
|
|
130
|
-
const p = this.#map.pointAt(down),
|
|
131
|
-
picked = this.#from.picked();
|
|
132
|
-
if (picked && this.#drawer.shown(picked).coordinates) return;
|
|
133
|
-
if (!picked) this.#drawer.new();
|
|
134
|
-
this.#put(p);
|
|
135
|
-
}
|
|
136
|
-
/** A pin put at a point: its place in the form, and the place's name once it's known. */
|
|
137
|
-
#put(p: { x: number; y: number }) {
|
|
138
|
-
const at = this.#map.placeOf(p),
|
|
139
|
-
{ form } = this.#drawer;
|
|
140
|
-
form.set("coordinates", at);
|
|
141
|
-
nameOf(geo(at)!).then((name) => name && form.input("coordinates").value === at && form.set("location", name));
|
|
142
|
-
}
|
|
143
|
-
}
|
package/examples/trip/drawer.ts
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
// The drawer and the modal of <calendar-map>: one form (./event-form.ts), in the drawer to change the picked event,
|
|
2
|
-
// in the modal to add one. What it holds is drawn as it has it, the picked event where the form puts it with the saved
|
|
3
|
-
// one faint behind, a new one behind the modal; Save (or Enter, Go on a phone) keeps it in one write (./writes.ts),
|
|
4
|
-
// Never mind puts it back, × and Escape close it, and Remove asks first. The drawer docks beside the calendar and map,
|
|
5
|
-
// which make room for it; on a phone it's a sheet, with room under them.
|
|
6
|
-
|
|
7
|
-
import type { JEvent, JEventData, JEvents } from "./generated/elements.ts";
|
|
8
|
-
import type { MapView } from "./map.ts";
|
|
9
|
-
import { label, type Week } from "./week.ts";
|
|
10
|
-
import type { Part } from "./shell.ts";
|
|
11
|
-
import { EventForm, type Input } from "./event-form.ts";
|
|
12
|
-
import { askFirst } from "joined/parts";
|
|
13
|
-
import { hueOf } from "joined/hues";
|
|
14
|
-
import { seconds, wall } from "joined/time";
|
|
15
|
-
import { Writes } from "./writes.ts";
|
|
16
|
-
|
|
17
|
-
/** An event as it's drawn: as the document has it, or, while it's in the drawer, as the form has it. */
|
|
18
|
-
export type Shown = JEventData & { people: number[] };
|
|
19
|
-
|
|
20
|
-
/** What the drawer reads from its display: the event picked and how to pick one, how to draw one or all again, its
|
|
21
|
-
* events, the people; and what its writes read (./writes.ts): the events' list, the week shown, whether a week is
|
|
22
|
-
* held and how to go to one, and the event kept on another week, to open there once it's held. */
|
|
23
|
-
type From = {
|
|
24
|
-
picked: () => JEvent | null;
|
|
25
|
-
pick: (el: JEvent | null) => void;
|
|
26
|
-
place: (el: JEvent) => void;
|
|
27
|
-
placeAll: () => void;
|
|
28
|
-
events: () => JEvent[];
|
|
29
|
-
list: () => JEvents | null;
|
|
30
|
-
people: () => Map<number, string>;
|
|
31
|
-
at: () => { week: number };
|
|
32
|
-
holds: (day: number) => boolean;
|
|
33
|
-
go: (week: number) => void;
|
|
34
|
-
moving: (moved: { key: number; week: number } | null) => void;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export class Drawer {
|
|
38
|
-
readonly form: EventForm;
|
|
39
|
-
/** A new event, drawn behind the modal as the form has it. */
|
|
40
|
-
readonly draft = {
|
|
41
|
-
block: Object.assign(document.createElement("div"), {
|
|
42
|
-
className: "block draft",
|
|
43
|
-
innerHTML: "<b></b><span></span>",
|
|
44
|
-
}),
|
|
45
|
-
pin: Object.assign(document.createElement("div"), { className: "pin draft" }),
|
|
46
|
-
};
|
|
47
|
-
/** The picked event as the document has it, drawn faintly while the form has it elsewhere. */
|
|
48
|
-
#ghost = {
|
|
49
|
-
block: Object.assign(document.createElement("div"), { className: "block ghost" }),
|
|
50
|
-
pin: Object.assign(document.createElement("div"), { className: "pin ghost" }),
|
|
51
|
-
};
|
|
52
|
-
#parts: {
|
|
53
|
-
host: HTMLElement;
|
|
54
|
-
drawer: HTMLElement;
|
|
55
|
-
modal: HTMLDialogElement;
|
|
56
|
-
ask: HTMLDialogElement;
|
|
57
|
-
cal: HTMLElement;
|
|
58
|
-
};
|
|
59
|
-
#ask: ReturnType<typeof askFirst>; // Remove asks first (joined/parts)
|
|
60
|
-
#week: Week;
|
|
61
|
-
#map: MapView;
|
|
62
|
-
#from: From;
|
|
63
|
-
|
|
64
|
-
/** In its parts (`host` the display, whose calendar and map make room for it), drawing on the week and the map;
|
|
65
|
-
* it follows the window's size until `signal` lets it go. */
|
|
66
|
-
constructor(host: HTMLElement, $: Part, week: Week, map: MapView, from: From, signal: AbortSignal) {
|
|
67
|
-
const modal = $("dialog:not(.ask)") as HTMLDialogElement,
|
|
68
|
-
parts = { host, drawer: $(".drawer"), modal, ask: $("dialog.ask") as HTMLDialogElement, cal: $(".cal") };
|
|
69
|
-
[this.#parts, this.#week, this.#map, this.#from] = [parts, week, map, from];
|
|
70
|
-
const { drawer } = parts,
|
|
71
|
-
form = (this.form = new EventForm({ redraw: () => this.redraw(), people: from.people, near: () => map.near() }));
|
|
72
|
-
this.#ask = askFirst(parts.ask);
|
|
73
|
-
const writes = new Writes(form, {
|
|
74
|
-
...from,
|
|
75
|
-
say: (why) => this.say(why),
|
|
76
|
-
new: (given) => this.new(given),
|
|
77
|
-
redraw: () => this.redraw(),
|
|
78
|
-
close: () => modal.close(),
|
|
79
|
-
});
|
|
80
|
-
drawer.append(form.el);
|
|
81
|
-
// each change drawn as the form has it, and kept by Save, one write; nothing until then
|
|
82
|
-
form.el.addEventListener("input", (e) => {
|
|
83
|
-
const name = (e.target as Element).getAttribute("name");
|
|
84
|
-
if (name === "from") form.keepLength();
|
|
85
|
-
if (name === "location") form.search();
|
|
86
|
-
this.say("");
|
|
87
|
-
this.redraw();
|
|
88
|
-
});
|
|
89
|
-
form.el.addEventListener("submit", (e) => {
|
|
90
|
-
e.preventDefault();
|
|
91
|
-
const picked = from.picked();
|
|
92
|
-
if (picked) writes.save(picked);
|
|
93
|
-
else writes.add();
|
|
94
|
-
});
|
|
95
|
-
// × and Escape close it, Never mind puts it back: the drawer's picked event, or the modal's new one
|
|
96
|
-
form.held.inside(
|
|
97
|
-
drawer,
|
|
98
|
-
() => (from.picked() ? from.pick(null) : modal.close()),
|
|
99
|
-
() => {
|
|
100
|
-
const picked = from.picked();
|
|
101
|
-
return picked ? (this.fill(picked, true), from.place(picked)) : modal.close();
|
|
102
|
-
},
|
|
103
|
-
);
|
|
104
|
-
form.el.querySelector("[name=unsettle]")!.addEventListener("click", () => {
|
|
105
|
-
form.set("location", "");
|
|
106
|
-
form.set("coordinates", "");
|
|
107
|
-
});
|
|
108
|
-
form.el.querySelector("[name=location]")!.addEventListener("keydown", (e) => {
|
|
109
|
-
const first = form.el.querySelector<HTMLButtonElement>(".found:not([hidden]) button");
|
|
110
|
-
const key = (e as KeyboardEvent).key;
|
|
111
|
-
if (key === "Enter" && first) (e.preventDefault(), first.click());
|
|
112
|
-
if (key === "Escape" && first) (e.preventDefault(), form.found([]));
|
|
113
|
-
});
|
|
114
|
-
// its close event comes a moment after it closes: opened again since, the draft is the new one's
|
|
115
|
-
modal.addEventListener("close", () => {
|
|
116
|
-
if (modal.open) return;
|
|
117
|
-
this.draft.block.remove();
|
|
118
|
-
this.draft.pin.remove();
|
|
119
|
-
form.found([]);
|
|
120
|
-
});
|
|
121
|
-
form.el
|
|
122
|
-
.querySelector("[name=remove]")!
|
|
123
|
-
.addEventListener("click", () =>
|
|
124
|
-
this.#ask(`Take away “${from.picked()?.data.title}”?`, () => writes.answered(from.picked()?.removeItem())),
|
|
125
|
-
);
|
|
126
|
-
addEventListener("resize", () => this.dock(), { signal });
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** Opened on the picked event, or closed (none): the modal closed, what wasn't saved put back. */
|
|
130
|
-
open(el: JEvent | null) {
|
|
131
|
-
const { drawer, modal } = this.#parts;
|
|
132
|
-
if (el && modal.open) modal.close();
|
|
133
|
-
if (el) drawer.append(this.form.el);
|
|
134
|
-
drawer.hidden = !el;
|
|
135
|
-
this.say("");
|
|
136
|
-
this.form.found([]);
|
|
137
|
-
this.fill(el, true);
|
|
138
|
-
}
|
|
139
|
-
/** A new event asked in the modal: what's given (a range drawn, a place tapped) filled in. */
|
|
140
|
-
new(given: Partial<Record<Input, string>> = {}) {
|
|
141
|
-
const { modal } = this.#parts,
|
|
142
|
-
form = this.form;
|
|
143
|
-
this.#from.pick(null);
|
|
144
|
-
this.fill(null, true);
|
|
145
|
-
for (const [f, v] of Object.entries(given)) form.input(f as Input).value = v;
|
|
146
|
-
// in the zone of the event before it, as the trip goes on in one place until it's said otherwise
|
|
147
|
-
if (given.zone === undefined) form.input("zone").value = this.#zoneBefore(given.day);
|
|
148
|
-
this.draft.block.style.setProperty("--hue", this.hue());
|
|
149
|
-
this.draft.pin.style.setProperty("--hue", this.hue());
|
|
150
|
-
modal.append(form.el);
|
|
151
|
-
if (!modal.open) modal.showModal();
|
|
152
|
-
this.redraw();
|
|
153
|
-
// beside what's drawn behind it, not over it
|
|
154
|
-
const bar = this.draft.block.isConnected && this.draft.block.getBoundingClientRect();
|
|
155
|
-
modal.dataset.side = bar ? (bar.left + bar.width / 2 < innerWidth / 2 ? "right" : "left") : "";
|
|
156
|
-
form.input("title").focus();
|
|
157
|
-
}
|
|
158
|
-
/** The zone of the last event on or before a day (or the first event's, with none before), or none. */
|
|
159
|
-
#zoneBefore(day = "") {
|
|
160
|
-
const zoned = this.#from
|
|
161
|
-
.events()
|
|
162
|
-
.map((el) => el.data)
|
|
163
|
-
.filter((d) => d.zone)
|
|
164
|
-
.sort((a, b) => a.start.localeCompare(b.start));
|
|
165
|
-
return (zoned.findLast((d) => d.start.slice(0, 10) <= day) ?? zoned[0])?.zone ?? "";
|
|
166
|
-
}
|
|
167
|
-
/** The colour a new event will have: the next key's. */
|
|
168
|
-
hue = () => hueOf(Math.max(0, ...this.#from.events().map((el) => el.key)) + 1);
|
|
169
|
-
|
|
170
|
-
/** An event as it's drawn: as the document has it, or, while it's in the drawer, as the form has it. */
|
|
171
|
-
shown(el: JEvent): Shown {
|
|
172
|
-
if (el !== this.#from.picked()) return el.data;
|
|
173
|
-
const f = this.form.formed();
|
|
174
|
-
return {
|
|
175
|
-
title: f.title,
|
|
176
|
-
start: f.start || el.data.start,
|
|
177
|
-
duration: f.start ? f.duration : el.data.duration,
|
|
178
|
-
location: f.location || undefined,
|
|
179
|
-
coordinates: f.coordinates || undefined,
|
|
180
|
-
people: this.form.chosen,
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
/** What the form has, drawn: the picked event where the form puts it, or the new one behind the modal. */
|
|
184
|
-
redraw() {
|
|
185
|
-
const picked = this.#from.picked();
|
|
186
|
-
if (picked) this.#from.place(picked);
|
|
187
|
-
if (this.#parts.modal.open) {
|
|
188
|
-
const f = this.form.formed(),
|
|
189
|
-
{ block } = this.draft;
|
|
190
|
-
if (f.start) {
|
|
191
|
-
label(block, f.title || "New event", f.start, f.duration);
|
|
192
|
-
this.#week.when(block, wall(f.start), seconds(f.duration) / 60);
|
|
193
|
-
} else block.remove();
|
|
194
|
-
this.#map.pinAt(this.draft.pin, f.coordinates);
|
|
195
|
-
}
|
|
196
|
-
this.mode();
|
|
197
|
-
}
|
|
198
|
-
/** The new event's pin where the map now is. */
|
|
199
|
-
repin() {
|
|
200
|
-
if (this.#parts.modal.open) this.#map.pinAt(this.draft.pin, this.form.formed().coordinates);
|
|
201
|
-
}
|
|
202
|
-
/** The form as the document has the picked event (or empty, for a new one), and what it says. */
|
|
203
|
-
fill(el: JEvent | null, afresh = false) {
|
|
204
|
-
this.form.fill(el?.data, afresh);
|
|
205
|
-
this.mode();
|
|
206
|
-
}
|
|
207
|
-
/** What the form says it's doing, and the saved event drawn faintly behind it while its changes aren't kept. */
|
|
208
|
-
mode() {
|
|
209
|
-
const el = this.#from.picked();
|
|
210
|
-
if (this.form.show(el?.data ?? null) && el) {
|
|
211
|
-
this.#week.when(this.#ghost.block, wall(el.data.start), seconds(el.data.duration) / 60);
|
|
212
|
-
this.#map.pinAt(this.#ghost.pin, el.data.coordinates);
|
|
213
|
-
} else (this.#ghost.block.remove(), this.#ghost.pin.remove());
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/** The drawer docked beside the page: the calendar and map make room for it, if it would cover them; or, a sheet,
|
|
217
|
-
* room under them. */
|
|
218
|
-
dock() {
|
|
219
|
-
const { host, drawer } = this.#parts;
|
|
220
|
-
host.style.paddingRight = host.style.paddingBottom = "";
|
|
221
|
-
if (drawer.hidden) return;
|
|
222
|
-
// where it sits, not where it is as it comes into place (an offset leaves out the transform)
|
|
223
|
-
const left = drawer.offsetLeft,
|
|
224
|
-
top = drawer.offsetTop,
|
|
225
|
-
right = host.getBoundingClientRect().right;
|
|
226
|
-
if (top <= 0 && right > left) host.style.paddingRight = `${right - left + 16}px`;
|
|
227
|
-
// a phone's sheet: room below the calendar, so what it covers can be scrolled above it
|
|
228
|
-
else if (top > 0) host.style.paddingBottom = `${drawer.offsetHeight}px`;
|
|
229
|
-
}
|
|
230
|
-
/** The picked event in sight: its day scrolled to, on a week too wide for the room the drawer leaves; and, picked on
|
|
231
|
-
* the calendar, the page scrolled to put it above a phone's sheet (never from the map, where the finger is). */
|
|
232
|
-
reveal(above: boolean) {
|
|
233
|
-
const picked = this.#from.picked(),
|
|
234
|
-
block = picked && this.#week.blockOf(picked);
|
|
235
|
-
if (!block?.isConnected) return;
|
|
236
|
-
const { cal, drawer } = this.#parts,
|
|
237
|
-
c = cal.getBoundingClientRect(),
|
|
238
|
-
r = block.getBoundingClientRect();
|
|
239
|
-
if (r.right > c.right) cal.scrollLeft += r.right - c.right + 8;
|
|
240
|
-
else if (r.left < c.left) cal.scrollLeft -= c.left - r.left + 8;
|
|
241
|
-
const sheet = drawer.offsetTop; // where it sits, not where it is as it rises
|
|
242
|
-
if (above && sheet > 0 && r.bottom > sheet - 8) scrollBy(0, Math.min(r.bottom - sheet + 8, r.top - 8));
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/** Why a write was refused, in the form; nothing, to say again what it's doing. */
|
|
246
|
-
say(why: string) {
|
|
247
|
-
this.form.held.refuse(why);
|
|
248
|
-
if (!why) this.mode();
|
|
249
|
-
}
|
|
250
|
-
}
|