@blueshed/joined 0.2.1 → 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 +270 -55
- 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 +176 -38
- 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 +11 -7
- 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 +211 -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 +219 -73
- package/starter/CLAUDE.md +3 -3
- package/starter/bunfig +4 -0
- package/starter/prettierignore +4 -0
- package/starter/tests/hello.test.ts +2 -0
- package/docs/learning.md +0 -76
- package/examples/cafe/trust.ts +0 -20
- package/examples/desk/trust.ts +0 -24
- package/examples/people/trust.ts +0 -14
- package/examples/trip/answer-rows.ts +0 -70
- package/examples/trip/bar.ts +0 -89
- package/examples/trip/calendar-map.css +0 -711
- package/examples/trip/calendar-map.ts +0 -249
- package/examples/trip/drags.ts +0 -143
- package/examples/trip/drawer.ts +0 -250
- package/examples/trip/event-form.ts +0 -200
- package/examples/trip/holding.ts +0 -61
- package/examples/trip/map.ts +0 -234
- package/examples/trip/month.ts +0 -87
- package/examples/trip/other-weeks.ts +0 -67
- package/examples/trip/peek.ts +0 -71
- package/examples/trip/people-chips.ts +0 -74
- package/examples/trip/shell.ts +0 -39
- package/examples/trip/trust.ts +0 -51
- package/examples/trip/week.ts +0 -237
- package/examples/trip/writes.ts +0 -91
- package/examples/trip/zones.ts +0 -16
- package/examples/weeks/derive.ts +0 -23
- package/src/scrim.ts +0 -81
package/src/upkeep.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
// What a kept store needs that
|
|
2
|
-
//
|
|
1
|
+
// What a kept store needs that it never does for itself: old changes and files nothing names let go, on any store;
|
|
2
|
+
// and on SQLite, which never gives back the pages a removed row left, gathers what the planner reads, or copies the
|
|
3
|
+
// file anywhere, those too (Postgres has its own autovacuum and backups). joined does it when it's idle: a VACUUM and
|
|
3
4
|
// PRAGMA optimize once enough has been written (what's let go first: `trim`, the old changes), and a backup once a day, a copy the store's own size
|
|
4
5
|
// (VACUUM INTO), the last seven kept. A backup is a store: to go back to one, stop joined and put it in the
|
|
5
6
|
// store's place (JOINED_DB), with no -wal or -shm beside it.
|
|
@@ -23,37 +24,40 @@ export function upkeep(
|
|
|
23
24
|
log: (line: string) => void,
|
|
24
25
|
{
|
|
25
26
|
every = 60_000,
|
|
26
|
-
trim = () => 0,
|
|
27
|
+
trim = async () => 0,
|
|
27
28
|
letGo = async () => 0,
|
|
28
|
-
|
|
29
|
+
sqlite = true,
|
|
30
|
+
}: { every?: number; trim?: () => Promise<number>; letGo?: () => Promise<number>; sqlite?: boolean } = {},
|
|
29
31
|
) {
|
|
30
32
|
let lastWrite = 0,
|
|
31
33
|
writes = 0,
|
|
32
34
|
vacuumedAt = Date.now();
|
|
33
|
-
mkdirSync(backups, { recursive: true });
|
|
34
|
-
const kept = files(backups);
|
|
35
|
+
if (sqlite) mkdirSync(backups, { recursive: true });
|
|
36
|
+
const kept = sqlite ? files(backups) : [];
|
|
35
37
|
let backedUpAt = kept.length ? statSync(`${backups}/${kept.at(-1)}`).mtimeMs : 0;
|
|
36
38
|
|
|
37
39
|
/** Now, or when idle: vacuum if enough was written, back up if a day has passed. */
|
|
38
|
-
function run(now = false) {
|
|
40
|
+
async function run(now = false) {
|
|
39
41
|
const at = Date.now();
|
|
40
42
|
const done: { vacuumed?: boolean; backup?: string; files?: Promise<number> } = {};
|
|
41
43
|
if (!now && at - lastWrite < IDLE) return done;
|
|
42
44
|
if (now || writes >= WRITES || (writes > 0 && at - vacuumedAt > HOUR)) {
|
|
43
|
-
const gone = trim();
|
|
45
|
+
const gone = await trim();
|
|
44
46
|
if (gone) log(`let go ${gone} old changes`);
|
|
45
47
|
done.files = letGo().then(
|
|
46
48
|
(n) => (n && log(`let go ${n} files nothing names`), n),
|
|
47
49
|
(e) => (log(`letting files go failed: ${e}`), 0),
|
|
48
50
|
);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
if (sqlite) {
|
|
52
|
+
await db.run("VACUUM");
|
|
53
|
+
await db.run("PRAGMA optimize");
|
|
54
|
+
log(`vacuumed after ${writes} writes`);
|
|
55
|
+
}
|
|
52
56
|
[writes, vacuumedAt, done.vacuumed] = [0, at, true];
|
|
53
57
|
}
|
|
54
|
-
if (now || at - backedUpAt > DAY) {
|
|
58
|
+
if (sqlite && (now || at - backedUpAt > DAY)) {
|
|
55
59
|
done.backup = `${backups}/${new Date(at).toISOString().replace(/[:.]/g, "-")}.sqlite`;
|
|
56
|
-
db.run("VACUUM INTO ?", [done.backup]);
|
|
60
|
+
await db.run("VACUUM INTO ?", [done.backup]);
|
|
57
61
|
backedUpAt = at;
|
|
58
62
|
for (const old of files(backups).slice(0, -KEEP)) unlinkSync(`${backups}/${old}`);
|
|
59
63
|
log(`backed up to ${done.backup}`);
|
|
@@ -61,13 +65,7 @@ export function upkeep(
|
|
|
61
65
|
return done;
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
const timer = setInterval(() => {
|
|
65
|
-
try {
|
|
66
|
-
run();
|
|
67
|
-
} catch (e) {
|
|
68
|
-
log(`upkeep failed: ${e}`);
|
|
69
|
-
}
|
|
70
|
-
}, every);
|
|
68
|
+
const timer = setInterval(() => run().catch((e) => log(`upkeep failed: ${e}`)), every);
|
|
71
69
|
timer.unref();
|
|
72
70
|
return {
|
|
73
71
|
run,
|
package/src/views.css
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* <j-views> (./views.ts): its tabs (Web Awesome's wa-tab-group, its nav alone), a row at the head of the readings,
|
|
2
|
+
the chosen one marked; under them the chosen reading. On a phone, every tab a finger tall, and every one but the
|
|
3
|
+
chosen its icon alone (its word is its name), so the row fits the screen; where even so they don't fit, it scrolls. */
|
|
4
|
+
:host {
|
|
5
|
+
display: block;
|
|
6
|
+
}
|
|
7
|
+
.tabs {
|
|
8
|
+
padding: 0 var(--space-16);
|
|
9
|
+
}
|
|
10
|
+
.tabs::part(body) {
|
|
11
|
+
display: none;
|
|
12
|
+
}
|
|
13
|
+
.tab {
|
|
14
|
+
font: var(--font-small);
|
|
15
|
+
}
|
|
16
|
+
/* its icon and its word, a space apart: they're laid out in its part, where they're slotted */
|
|
17
|
+
.tab::part(tab) {
|
|
18
|
+
gap: var(--space-6);
|
|
19
|
+
min-height: var(--size-touch);
|
|
20
|
+
padding-block: 0;
|
|
21
|
+
padding-inline: var(--space-12);
|
|
22
|
+
}
|
|
23
|
+
@media (max-width: 40rem), (pointer: coarse) {
|
|
24
|
+
.tab::part(tab) {
|
|
25
|
+
min-height: var(--size-finger);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
@media (max-width: 40rem) {
|
|
29
|
+
.tabs {
|
|
30
|
+
padding-inline: var(--space-12);
|
|
31
|
+
}
|
|
32
|
+
.tab:not([active])::part(tab) {
|
|
33
|
+
justify-content: center;
|
|
34
|
+
min-width: var(--size-finger);
|
|
35
|
+
padding: 0;
|
|
36
|
+
}
|
|
37
|
+
.tab:not([active]) > span {
|
|
38
|
+
display: none;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/* only the chosen reading is shown, whatever display its own sheet gives it */
|
|
42
|
+
::slotted([hidden]) {
|
|
43
|
+
display: none;
|
|
44
|
+
}
|
package/src/views.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// <j-views> (joined/kit): one collection read several ways, one at a time: a tab for each reading it holds (a list, a
|
|
2
|
+
// week, a month, a timeline, a map, a board), its icon and its word, the one chosen shown and the rest hidden. The
|
|
3
|
+
// choice is the page's alone, kept in the address (?view=week), so a reload or a link keeps it. Each reading in it is
|
|
4
|
+
// the way into the same sheet.
|
|
5
|
+
//
|
|
6
|
+
// <j-views>
|
|
7
|
+
// <j-plans-rows label="List"><j-plans></j-plans></j-plans-rows>
|
|
8
|
+
// <j-week for="plans"></j-week>
|
|
9
|
+
// <j-map for="plans"></j-map>
|
|
10
|
+
// </j-views>
|
|
11
|
+
|
|
12
|
+
import { el } from "./fields.ts";
|
|
13
|
+
import { icon } from "./icons.ts";
|
|
14
|
+
import type { IconName } from "./icon-names.ts";
|
|
15
|
+
import { adopt } from "./parts.ts";
|
|
16
|
+
import STYLE from "./views.css" with { type: "text" };
|
|
17
|
+
|
|
18
|
+
const SHEET = new CSSStyleSheet();
|
|
19
|
+
SHEET.replaceSync(STYLE);
|
|
20
|
+
/** Each reading's word and icon, where it doesn't say its own (`label`, `icon`). */
|
|
21
|
+
const READINGS: Record<string, [string, IconName]> = {
|
|
22
|
+
"j-month": ["Month", "month"],
|
|
23
|
+
"j-week": ["Week", "week"],
|
|
24
|
+
"j-timeline": ["Timeline", "timeline"],
|
|
25
|
+
"j-map": ["Map", "map"],
|
|
26
|
+
"j-board": ["Board", "board"],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class JViews extends HTMLElement {
|
|
30
|
+
root = this.attachShadow({ mode: "open" });
|
|
31
|
+
#tabs = el("wa-tab-group" as "div", { className: "tabs", part: "tabs", ariaLabel: "Read as" });
|
|
32
|
+
#watch = new MutationObserver(() => this.#draw());
|
|
33
|
+
|
|
34
|
+
get #param() {
|
|
35
|
+
return this.getAttribute("param") ?? "view";
|
|
36
|
+
}
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
if (!this.root.childElementCount) {
|
|
39
|
+
adopt(this.root, SHEET);
|
|
40
|
+
this.root.append(this.#tabs, el("slot"));
|
|
41
|
+
// a tab chosen: its reading shown, and kept in the address
|
|
42
|
+
this.#tabs.addEventListener("wa-tab-show", (e) => {
|
|
43
|
+
const name = (e as CustomEvent<{ name: string }>).detail.name,
|
|
44
|
+
r = [...this.children].find((r) => this.#word(r).toLowerCase() === name);
|
|
45
|
+
if (r && r !== this.chosen) this.choose(r);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
this.#watch.observe(this, { childList: true });
|
|
49
|
+
this.#draw();
|
|
50
|
+
}
|
|
51
|
+
disconnectedCallback() {
|
|
52
|
+
this.#watch.disconnect();
|
|
53
|
+
}
|
|
54
|
+
/** Each reading's word, its own or its kind's. */
|
|
55
|
+
#word(r: Element) {
|
|
56
|
+
return r.getAttribute("label") ?? READINGS[r.localName]?.[0] ?? "List";
|
|
57
|
+
}
|
|
58
|
+
/** The reading chosen: the address's, else the first. */
|
|
59
|
+
get chosen() {
|
|
60
|
+
const said = new URLSearchParams(location.search).get(this.#param),
|
|
61
|
+
all = [...this.children];
|
|
62
|
+
return all.find((r) => this.#word(r).toLowerCase() === said) ?? all[0];
|
|
63
|
+
}
|
|
64
|
+
/** A reading chosen: shown, and kept in the address. */
|
|
65
|
+
choose(r: Element) {
|
|
66
|
+
const url = new URL(location.href);
|
|
67
|
+
if (r === this.children[0]) url.searchParams.delete(this.#param);
|
|
68
|
+
else url.searchParams.set(this.#param, this.#word(r).toLowerCase());
|
|
69
|
+
history.replaceState(history.state, "", url);
|
|
70
|
+
this.#draw();
|
|
71
|
+
}
|
|
72
|
+
#draw() {
|
|
73
|
+
const chosen = this.chosen,
|
|
74
|
+
all = [...this.children];
|
|
75
|
+
// a tab each (Web Awesome's), made again only when the readings change
|
|
76
|
+
const words = all.map((r) => this.#word(r));
|
|
77
|
+
if (this.#tabs.dataset.shows !== words.join()) {
|
|
78
|
+
this.#tabs.dataset.shows = words.join();
|
|
79
|
+
this.#tabs.replaceChildren(
|
|
80
|
+
...all.map((r, i) =>
|
|
81
|
+
el(
|
|
82
|
+
"wa-tab" as "div",
|
|
83
|
+
{ slot: "nav", className: "tab", ariaLabel: words[i], title: words[i] },
|
|
84
|
+
icon((r.getAttribute("icon") as IconName) ?? READINGS[r.localName]?.[1] ?? "list"),
|
|
85
|
+
el("span", {}, words[i]!),
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
for (const [i, t] of [...this.#tabs.children].entries()) t.setAttribute("panel", words[i]!.toLowerCase());
|
|
90
|
+
}
|
|
91
|
+
this.#tabs.setAttribute("active", this.#word(chosen!).toLowerCase());
|
|
92
|
+
for (const r of all) (r as HTMLElement).hidden = r !== chosen;
|
|
93
|
+
}
|
|
94
|
+
}
|
package/src/week.css
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* <j-week> (./week.ts), in its shadow: its head, the days' strip over their columns, the hours down the side, and
|
|
2
|
+
each item a block placed by its time (--top, in hours from the first shown), its length (--len) and its lane among
|
|
3
|
+
those at once (--lane of --lanes). An hour is --space-48 tall. On a phone, one day: the strip to choose it. */
|
|
4
|
+
:host {
|
|
5
|
+
--hour: var(--space-48);
|
|
6
|
+
--gutter-w: var(--space-48);
|
|
7
|
+
}
|
|
8
|
+
.strip {
|
|
9
|
+
display: grid;
|
|
10
|
+
grid-template-columns: var(--gutter-w) repeat(7, minmax(0, 1fr));
|
|
11
|
+
border-bottom: 1px solid var(--line);
|
|
12
|
+
}
|
|
13
|
+
.strip::before {
|
|
14
|
+
content: "";
|
|
15
|
+
}
|
|
16
|
+
.dayhead {
|
|
17
|
+
display: flex;
|
|
18
|
+
flex-direction: column;
|
|
19
|
+
align-items: center;
|
|
20
|
+
gap: var(--space-4);
|
|
21
|
+
min-width: 0;
|
|
22
|
+
padding: var(--space-4) 0 var(--space-8);
|
|
23
|
+
border: 0;
|
|
24
|
+
background: none;
|
|
25
|
+
color: var(--muted);
|
|
26
|
+
font: var(--font-tiny);
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
}
|
|
29
|
+
.dayhead .dn {
|
|
30
|
+
display: grid;
|
|
31
|
+
place-items: center;
|
|
32
|
+
min-width: var(--space-24);
|
|
33
|
+
height: var(--space-24);
|
|
34
|
+
border: 1px solid transparent;
|
|
35
|
+
border-radius: var(--radius-pill);
|
|
36
|
+
color: var(--ink);
|
|
37
|
+
font: var(--font-small);
|
|
38
|
+
font-variant-numeric: tabular-nums;
|
|
39
|
+
}
|
|
40
|
+
.dayhead[today] .dn {
|
|
41
|
+
border-color: var(--ink);
|
|
42
|
+
}
|
|
43
|
+
.dayhead .mark {
|
|
44
|
+
width: var(--space-4);
|
|
45
|
+
height: var(--space-4);
|
|
46
|
+
border-radius: var(--radius-dot);
|
|
47
|
+
background: var(--accent);
|
|
48
|
+
}
|
|
49
|
+
.dayhead .mark[hidden] {
|
|
50
|
+
visibility: hidden;
|
|
51
|
+
display: block;
|
|
52
|
+
}
|
|
53
|
+
.body {
|
|
54
|
+
display: grid;
|
|
55
|
+
grid-template-columns: var(--gutter-w) minmax(0, 1fr);
|
|
56
|
+
}
|
|
57
|
+
.hours {
|
|
58
|
+
display: grid;
|
|
59
|
+
grid-auto-rows: var(--hour);
|
|
60
|
+
color: var(--muted);
|
|
61
|
+
font: var(--font-tiny);
|
|
62
|
+
font-variant-numeric: tabular-nums;
|
|
63
|
+
}
|
|
64
|
+
.hours span {
|
|
65
|
+
translate: 0 calc(var(--space-6) * -1);
|
|
66
|
+
padding-inline-end: var(--space-6);
|
|
67
|
+
text-align: end;
|
|
68
|
+
}
|
|
69
|
+
.hours span:first-child {
|
|
70
|
+
visibility: hidden;
|
|
71
|
+
}
|
|
72
|
+
.cols {
|
|
73
|
+
display: grid;
|
|
74
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
75
|
+
}
|
|
76
|
+
/* a day: its hours' lines drawn on its ground; an empty hour tapped adds there */
|
|
77
|
+
.col {
|
|
78
|
+
position: relative;
|
|
79
|
+
height: calc(var(--hour) * var(--hours, 12));
|
|
80
|
+
border-left: 1px solid var(--line);
|
|
81
|
+
background: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px var(--hour));
|
|
82
|
+
}
|
|
83
|
+
.block {
|
|
84
|
+
position: absolute;
|
|
85
|
+
top: calc(var(--hour) * var(--top));
|
|
86
|
+
left: calc(100% * var(--lane) / var(--lanes));
|
|
87
|
+
width: calc(100% / var(--lanes) - var(--space-4));
|
|
88
|
+
height: calc(var(--hour) * var(--len) - var(--space-4) / 2);
|
|
89
|
+
margin-inline-start: calc(var(--space-4) / 2);
|
|
90
|
+
white-space: normal;
|
|
91
|
+
line-height: 1.25;
|
|
92
|
+
}
|
|
93
|
+
.block .at {
|
|
94
|
+
display: block;
|
|
95
|
+
}
|
|
96
|
+
.block[short] .at {
|
|
97
|
+
display: inline;
|
|
98
|
+
}
|
|
99
|
+
.block[short] {
|
|
100
|
+
white-space: nowrap;
|
|
101
|
+
}
|
|
102
|
+
/* its foot: dragged, it lasts longer or shorter */
|
|
103
|
+
.foot {
|
|
104
|
+
position: absolute;
|
|
105
|
+
inset: auto 0 0;
|
|
106
|
+
height: var(--size-grip);
|
|
107
|
+
cursor: ns-resize;
|
|
108
|
+
}
|
|
109
|
+
.now {
|
|
110
|
+
position: absolute;
|
|
111
|
+
inset-inline: 0;
|
|
112
|
+
top: calc(var(--hour) * var(--at));
|
|
113
|
+
height: 0;
|
|
114
|
+
border-top: calc(var(--space-4) / 2) solid var(--danger);
|
|
115
|
+
pointer-events: none;
|
|
116
|
+
}
|
|
117
|
+
.now::before {
|
|
118
|
+
content: "";
|
|
119
|
+
position: absolute;
|
|
120
|
+
left: calc(var(--space-4) * -1);
|
|
121
|
+
top: calc(var(--space-4) * -1 - 1px);
|
|
122
|
+
width: var(--space-8);
|
|
123
|
+
height: var(--space-8);
|
|
124
|
+
border-radius: var(--radius-dot);
|
|
125
|
+
background: var(--danger);
|
|
126
|
+
}
|
|
127
|
+
@media (max-width: 40rem) {
|
|
128
|
+
.strip {
|
|
129
|
+
grid-template-columns: repeat(7, minmax(0, 1fr));
|
|
130
|
+
}
|
|
131
|
+
.strip::before {
|
|
132
|
+
display: none;
|
|
133
|
+
}
|
|
134
|
+
.dayhead {
|
|
135
|
+
min-height: var(--size-finger);
|
|
136
|
+
}
|
|
137
|
+
.dayhead[aria-selected="true"] .dn {
|
|
138
|
+
border-color: var(--accent);
|
|
139
|
+
background: var(--accent);
|
|
140
|
+
color: var(--card);
|
|
141
|
+
}
|
|
142
|
+
.cols {
|
|
143
|
+
grid-template-columns: minmax(0, 1fr);
|
|
144
|
+
}
|
|
145
|
+
.col:not([chosen]) {
|
|
146
|
+
display: none;
|
|
147
|
+
}
|
|
148
|
+
.block {
|
|
149
|
+
min-height: var(--size-finger);
|
|
150
|
+
}
|
|
151
|
+
}
|
package/src/week.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// <j-week for="plans" when="when" length="length"> (joined/kit): a collection read by its hours, a week of days side by
|
|
2
|
+
// side, each item a block from its time for its length (an hour where it has none), those at once side by side. A
|
|
3
|
+
// block tapped opens its sheet; dragged, it moves by quarter hours and to another day, and by its foot it lasts
|
|
4
|
+
// longer or shorter (each where its `may` lets it); an empty hour tapped adds one there, the sheet offered that day
|
|
5
|
+
// and hour, still asked. The hours shown are the working day's (8 to 20, `from` and `until`), grown to hold what's
|
|
6
|
+
// there; now is a line across today. On a phone it's one day at a time, the week's days a strip above it to choose
|
|
7
|
+
// from, each marked where it has something. The week shown is kept in the address (?day=2026-11-15).
|
|
8
|
+
|
|
9
|
+
import { follow } from "./follow.ts";
|
|
10
|
+
import { iconButton } from "./icons.ts";
|
|
11
|
+
import { keep, type Row } from "./keep.ts";
|
|
12
|
+
import { el, Reading } from "./reading.ts";
|
|
13
|
+
import type { Item } from "./rows.ts";
|
|
14
|
+
import { DAY, MIN, SNAP, dated, dayOf, iso, lasts, local, mondayOf, now, seconds, wall } from "./time.ts";
|
|
15
|
+
import STYLE from "./week.css" with { type: "text" };
|
|
16
|
+
|
|
17
|
+
const SHEET = new CSSStyleSheet();
|
|
18
|
+
SHEET.replaceSync(STYLE);
|
|
19
|
+
/** An item as the week places it: its day, its minutes from midnight, how long, and its place among those at once. */
|
|
20
|
+
type Placed = { it: Item; day: number; from: number; mins: number; lane: number; lanes: number };
|
|
21
|
+
|
|
22
|
+
export class JWeek extends Reading {
|
|
23
|
+
static override sheets = [SHEET];
|
|
24
|
+
#name = el("h3");
|
|
25
|
+
#strip = el("div", { className: "strip", role: "tablist", ariaLabel: "The week's days" });
|
|
26
|
+
#hours = el("div", { className: "hours", ariaHidden: "true" });
|
|
27
|
+
#cols = el("div", { className: "cols" });
|
|
28
|
+
#heads = new Map<string, { shows: string; el: HTMLElement }>();
|
|
29
|
+
#days = new Map<string, { shows: string; el: HTMLElement }>();
|
|
30
|
+
|
|
31
|
+
get #length() {
|
|
32
|
+
return this.field("length") ?? this.spec?.fields.find((f) => f.type === "duration");
|
|
33
|
+
}
|
|
34
|
+
protected made() {
|
|
35
|
+
const today = el("button", { type: "button", className: "act small today" }, "Today");
|
|
36
|
+
today.addEventListener("click", () => (this.day = dayOf(now())));
|
|
37
|
+
this.root.append(
|
|
38
|
+
el(
|
|
39
|
+
"header",
|
|
40
|
+
{ className: "head" },
|
|
41
|
+
this.#name,
|
|
42
|
+
today,
|
|
43
|
+
iconButton("back", "The week before", () => (this.day = this.day - 7)),
|
|
44
|
+
iconButton("on", "The week after", () => (this.day = this.day + 7)),
|
|
45
|
+
),
|
|
46
|
+
this.#strip,
|
|
47
|
+
el("div", { className: "body" }, this.#hours, this.#cols),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
protected draw() {
|
|
51
|
+
const when = this.when;
|
|
52
|
+
if (!when) return;
|
|
53
|
+
const length = this.#length,
|
|
54
|
+
day = this.day,
|
|
55
|
+
monday = mondayOf(day),
|
|
56
|
+
today = dayOf(now()),
|
|
57
|
+
days = Array.from({ length: 7 }, (_, i) => monday + i);
|
|
58
|
+
this.#name.textContent = `${dated(monday, { day: "numeric", month: "short" })} – ${dated(monday + 6, { day: "numeric", month: "short", year: "numeric" })}`;
|
|
59
|
+
// each item of the week: its day, its minutes, its length; those at once side by side
|
|
60
|
+
const placed: Placed[] = [];
|
|
61
|
+
for (const it of this.items()) {
|
|
62
|
+
const w = it.data[when.name];
|
|
63
|
+
if (typeof w !== "string") continue;
|
|
64
|
+
const d = dayOf(w);
|
|
65
|
+
if (d < monday || d > monday + 6) continue;
|
|
66
|
+
const len = length && typeof it.data[length.name] === "string" ? seconds(it.data[length.name]) / 60 : 0;
|
|
67
|
+
placed.push({ it, day: d, from: (wall(w) - d * DAY) / MIN, mins: Math.max(len || 60, SNAP), lane: 0, lanes: 1 });
|
|
68
|
+
}
|
|
69
|
+
for (const d of days) side(placed.filter((p) => p.day === d));
|
|
70
|
+
// the hours: the working day's, grown to hold what's there
|
|
71
|
+
let first = Number(this.getAttribute("from") ?? 8),
|
|
72
|
+
last = Number(this.getAttribute("until") ?? 20);
|
|
73
|
+
for (const p of placed) {
|
|
74
|
+
first = Math.min(first, Math.floor(p.from / 60));
|
|
75
|
+
last = Math.max(last, Math.min(24, Math.ceil((p.from + p.mins) / 60)));
|
|
76
|
+
}
|
|
77
|
+
this.style.setProperty("--hours", String(last - first));
|
|
78
|
+
this.#hours.replaceChildren(
|
|
79
|
+
...Array.from({ length: last - first }, (_, i) => el("span", {}, `${String(first + i).padStart(2, "0")}:00`)),
|
|
80
|
+
);
|
|
81
|
+
const nowMs = wall(now()),
|
|
82
|
+
had = new Set(placed.map((p) => p.day));
|
|
83
|
+
// the days' strip: each a tab, the one shown on a phone chosen; marked where it has something
|
|
84
|
+
keep(
|
|
85
|
+
this.#strip,
|
|
86
|
+
this.#heads,
|
|
87
|
+
days.map((d): Row => ({
|
|
88
|
+
key: String(d),
|
|
89
|
+
shows: JSON.stringify([d === day, d === today, had.has(d)]),
|
|
90
|
+
make: () => {
|
|
91
|
+
const b = el(
|
|
92
|
+
"button",
|
|
93
|
+
{
|
|
94
|
+
type: "button",
|
|
95
|
+
role: "tab",
|
|
96
|
+
className: "dayhead",
|
|
97
|
+
ariaLabel: dated(d, { weekday: "long", day: "numeric", month: "long" }),
|
|
98
|
+
},
|
|
99
|
+
el("span", { className: "wd" }, dated(d, { weekday: "short" })),
|
|
100
|
+
el("span", { className: "dn" }, String(new Date(d * DAY).getUTCDate())),
|
|
101
|
+
el("i", { className: "mark", hidden: !had.has(d) }),
|
|
102
|
+
);
|
|
103
|
+
b.ariaSelected = String(d === day);
|
|
104
|
+
b.toggleAttribute("today", d === today);
|
|
105
|
+
b.addEventListener("click", () => (this.day = d));
|
|
106
|
+
return b;
|
|
107
|
+
},
|
|
108
|
+
})),
|
|
109
|
+
);
|
|
110
|
+
keep(
|
|
111
|
+
this.#cols,
|
|
112
|
+
this.#days,
|
|
113
|
+
days.map((d): Row => {
|
|
114
|
+
const here = placed.filter((p) => p.day === d),
|
|
115
|
+
nowAt = d === today ? (nowMs - d * DAY) / MIN - first * 60 : null;
|
|
116
|
+
return {
|
|
117
|
+
key: String(d),
|
|
118
|
+
shows: JSON.stringify([
|
|
119
|
+
first,
|
|
120
|
+
last,
|
|
121
|
+
d === day,
|
|
122
|
+
nowAt === null ? null : Math.round(nowAt / 5),
|
|
123
|
+
this.adds,
|
|
124
|
+
here.map((p) => [
|
|
125
|
+
p.it.key,
|
|
126
|
+
this.named(p.it),
|
|
127
|
+
p.from,
|
|
128
|
+
p.mins,
|
|
129
|
+
p.lane,
|
|
130
|
+
p.lanes,
|
|
131
|
+
this.opened(p.it),
|
|
132
|
+
p.it.getAttribute("may"),
|
|
133
|
+
]),
|
|
134
|
+
]),
|
|
135
|
+
make: () => this.#column(d, here, first, nowAt),
|
|
136
|
+
};
|
|
137
|
+
}),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
/** A day's column: its hours' lines, its blocks, now's line; an empty hour tapped, one added there. */
|
|
141
|
+
#column(d: number, here: Placed[], first: number, nowAt: number | null) {
|
|
142
|
+
const col = el("div", {
|
|
143
|
+
className: "col",
|
|
144
|
+
ariaLabel: dated(d, { weekday: "long", day: "numeric", month: "long" }),
|
|
145
|
+
});
|
|
146
|
+
col.toggleAttribute("chosen", d === this.day);
|
|
147
|
+
col.dataset.day = String(d);
|
|
148
|
+
for (const p of here) col.append(this.#block(p, first));
|
|
149
|
+
if (nowAt !== null && nowAt >= 0) {
|
|
150
|
+
const line = el("i", { className: "now", ariaHidden: "true" });
|
|
151
|
+
line.style.setProperty("--at", String(nowAt / 60));
|
|
152
|
+
col.append(line);
|
|
153
|
+
}
|
|
154
|
+
col.addEventListener("click", (e) => {
|
|
155
|
+
const when = this.when;
|
|
156
|
+
if (e.target !== col || !this.adds || !when) return;
|
|
157
|
+
const r = col.getBoundingClientRect(),
|
|
158
|
+
mins = first * 60 + Math.floor((((e.clientY - r.top) / r.height) * this.#span * 60) / 30) * 30,
|
|
159
|
+
length = this.#length;
|
|
160
|
+
this.add({
|
|
161
|
+
[when.name]: local(d * DAY + mins * MIN),
|
|
162
|
+
...(length ? { [length.name]: "PT1H" } : {}),
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
return col;
|
|
166
|
+
}
|
|
167
|
+
get #span() {
|
|
168
|
+
return Number(this.style.getPropertyValue("--hours")) || 12;
|
|
169
|
+
}
|
|
170
|
+
/** An item's block: its time and its words; moved by a drag, made longer or shorter by its foot. */
|
|
171
|
+
#block(p: Placed, first: number) {
|
|
172
|
+
const when = this.when!.name,
|
|
173
|
+
length = this.#length?.name,
|
|
174
|
+
w = String(p.it.data[when]),
|
|
175
|
+
at = local(wall(w)).slice(11, 16),
|
|
176
|
+
b = el(
|
|
177
|
+
"button",
|
|
178
|
+
{ type: "button", className: "item block", title: `${at} ${this.named(p.it)}` },
|
|
179
|
+
el("span", { className: "at" }, at),
|
|
180
|
+
" ",
|
|
181
|
+
el("span", { className: "what" }, this.named(p.it)),
|
|
182
|
+
);
|
|
183
|
+
b.style.setProperty("--top", String((p.from - first * 60) / 60));
|
|
184
|
+
b.style.setProperty("--len", String(p.mins / 60));
|
|
185
|
+
b.style.setProperty("--lane", String(p.lane));
|
|
186
|
+
b.style.setProperty("--lanes", String(p.lanes));
|
|
187
|
+
b.toggleAttribute("short", p.mins < 45);
|
|
188
|
+
const hourPx = () => b.parentElement!.getBoundingClientRect().height / this.#span,
|
|
189
|
+
colPx = () => b.parentElement!.getBoundingClientRect().width;
|
|
190
|
+
this.press(
|
|
191
|
+
b,
|
|
192
|
+
p.it,
|
|
193
|
+
this.may(p.it, when)
|
|
194
|
+
? (dx, dy, done) => {
|
|
195
|
+
const mins = Math.round(((dy / hourPx()) * 60) / SNAP) * SNAP,
|
|
196
|
+
// on a phone, one day is shown: a drag moves within it
|
|
197
|
+
days = matchMedia("(max-width: 40rem)").matches ? 0 : Math.round(dx / colPx());
|
|
198
|
+
b.style.translate = done ? "" : `${days * colPx()}px ${(mins / 60) * hourPx()}px`;
|
|
199
|
+
if (done && (mins || days)) void this.change(p.it, { [when]: local(wall(w) + days * DAY + mins * MIN) });
|
|
200
|
+
}
|
|
201
|
+
: undefined,
|
|
202
|
+
);
|
|
203
|
+
if (length && this.may(p.it, length)) {
|
|
204
|
+
const foot = el("span", { className: "foot", ariaHidden: "true" });
|
|
205
|
+
foot.addEventListener("pointerdown", (down) => {
|
|
206
|
+
down.stopPropagation();
|
|
207
|
+
let mins = p.mins;
|
|
208
|
+
follow(
|
|
209
|
+
down,
|
|
210
|
+
(e) => {
|
|
211
|
+
mins = Math.max(SNAP, Math.round((p.mins + ((e.clientY - down.clientY) / hourPx()) * 60) / SNAP) * SNAP);
|
|
212
|
+
b.style.setProperty("--len", String(mins / 60));
|
|
213
|
+
b.title = lasts(`PT${mins}M`);
|
|
214
|
+
},
|
|
215
|
+
(e) => {
|
|
216
|
+
if (e && mins !== p.mins)
|
|
217
|
+
void this.change(p.it, {
|
|
218
|
+
[length]: iso(mins),
|
|
219
|
+
});
|
|
220
|
+
else this.again();
|
|
221
|
+
},
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
b.append(foot);
|
|
225
|
+
}
|
|
226
|
+
return b;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Those at once on a day, side by side: each its lane, and how many lanes its cluster takes. */
|
|
231
|
+
function side(day: Placed[]) {
|
|
232
|
+
day.sort((a, b) => a.from - b.from || b.mins - a.mins);
|
|
233
|
+
let cluster: Placed[] = [],
|
|
234
|
+
end = -1;
|
|
235
|
+
const close = () => {
|
|
236
|
+
const lanes = Math.max(1, ...cluster.map((p) => p.lane + 1));
|
|
237
|
+
for (const p of cluster) p.lanes = lanes;
|
|
238
|
+
cluster = [];
|
|
239
|
+
};
|
|
240
|
+
for (const p of day) {
|
|
241
|
+
if (p.from >= end) close();
|
|
242
|
+
const taken = new Set(cluster.filter((q) => q.from + q.mins > p.from).map((q) => q.lane));
|
|
243
|
+
let lane = 0;
|
|
244
|
+
while (taken.has(lane)) lane++;
|
|
245
|
+
p.lane = lane;
|
|
246
|
+
cluster.push(p);
|
|
247
|
+
end = Math.max(end, p.from + p.mins);
|
|
248
|
+
}
|
|
249
|
+
close();
|
|
250
|
+
}
|