website-xp-phone 2.3.0 → 2.4.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/build/blogDirsPlugin.ts +100 -0
- package/package.json +9 -6
- package/public/blog/archive/eighth-post-lost-in-the-sauce.json +36 -0
- package/public/blog/archive/noise/eleventh-post-discussion-java-gist.md +5 -0
- package/public/blog/archive/noise/fifteenth-post-very-rare-windows-funny.md +8 -0
- package/public/blog/archive/noise/fourth-post-meta-blog.md +3 -0
- package/public/blog/archive/noise/sixteenth-post-meta-fantasy-blog.md +4 -0
- package/public/blog/archive/noise/tenth-post-meta-funny-redacted-and-timetravelled.md +3 -0
- package/public/blog/archive/noise/twelfth-post-mixing-phase-technique-audio-music.md +48 -0
- package/public/blog/archive/noise/welcome-back-ramble-meta.md +6 -0
- package/public/blog/archive/noise/welcome-to-my-blog-meta-blog-welcome-to-my-website.md +7 -0
- package/public/blog/archive/seventh-post-lie-theory-na2000.json +22 -0
- package/public/blog/archive/sophus-lie.json +36 -0
- package/public/blog/hlwm_and_herbstutil.md +11 -0
- package/public/blog/writing/hot-action-under-a-cold-moon.json +9 -0
- package/public/checksums.txt +90 -66
- package/public/documents/drift-report.json +13 -1
- package/scripts/refresh-soundcloud.mjs +54 -8
- package/src/content/blog.json +16 -363
- package/src/content/blogDirs.ts +196 -0
- package/src/content/configs.json +1 -1
- package/src/content/contacts.json +2 -2
- package/src/content/includes/make-recipes.md +18 -0
- package/src/content/index.ts +156 -57
- package/src/content/music-ext.json +1 -1
- package/src/content/projects/doftiles.json +88 -4
- package/src/content/projects/herbctl.json +58 -0
- package/src/content/projects/herbstutil.json +50 -20
- package/src/content/projects/on-deploy.json +57 -0
- package/src/content/projects/polyframes.json +83 -0
- package/src/content/schema.ts +7 -4
- package/src/content/sections.json +11 -10
- package/src/content/soundcloud.json +61 -13
- package/src/lib/clippy.ts +29 -8
- package/src/lib/history.ts +152 -0
- package/src/lib/markdown.tsx +11 -1
- package/src/lib/scrollTo.ts +45 -0
- package/src/lib/signals.tsx +271 -0
- package/src/main.tsx +20 -4
- package/src/pages/BlogDirPage.tsx +36 -0
- package/src/pages/BlogPostPage.tsx +76 -3
- package/src/pages/ProjectPage.tsx +9 -3
- package/src/pages/WowPage.tsx +8 -3
- package/src/pages/index.ts +2 -0
- package/src/shell/App.tsx +14 -8
- package/src/shell/Clippy.tsx +13 -3
- package/src/shell/MenuBar.tsx +7 -4
- package/src/shell/resolveRoute.ts +41 -2
- package/src/shell/routerSignals.ts +34 -0
- package/src/styles/extras.css +20 -0
- package/src/styles/layout.css +2 -2
- package/src/styles/menu.css +1 -1
- package/src/styles/window.css +9 -2
- package/src/themes/pageSlide/index.ts +120 -42
- package/src/themes/pageSlide/pageSlide.css +20 -9
- package/src/virtual.d.ts +14 -0
- package/src/window/MaximizedWindow.tsx +97 -64
- package/src/window/OkButton.tsx +42 -25
- package/src/window/PageWindows.tsx +7 -0
- package/src/window/TitleBar.tsx +3 -1
- package/src/window/Window.tsx +132 -87
- package/src/window/closeSounds.ts +27 -0
- package/src/window/model.ts +11 -0
- package/src/window/state.tsx +290 -50
- package/src/window/themes.ts +23 -2
- package/test/content.test.js +15 -10
- package/test/deploy-pipeline.test.js +11 -11
- package/test/markdown-tables.test.js +96 -0
- package/test/soundcloud-refresh.test.js +68 -0
- package/tsconfig.node.tsbuildinfo +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.config.ts +7 -1
- package/public/blog/4th.md +0 -28
- package/public/blog/wsl.1.md +0 -40
- package/src/window/hidden.ts +0 -22
- /package/public/blog/{ → archive/noise/}/321/200/321/203/320/275/320/270/321/201/321/207-/320/263/320/273/320/276/321/201/321/201/320/260/321/200/320/270/320/271.md" +0 -0
- /package/src/content/{characters.json → includes/characters.json} +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { onSignal } from "@/lib/signals";
|
|
2
|
+
|
|
3
|
+
/** The history owner: the ONE module that writes the window system's
|
|
4
|
+
* bookmarks into the session history. The bus carries the commands (the
|
|
5
|
+
* maximized view's push, the off-site departure's hash-free bookmark,
|
|
6
|
+
* the post-dismissal settle) and the handlers attached at boot perform
|
|
7
|
+
* them; nothing else in the app writes our state key.
|
|
8
|
+
*
|
|
9
|
+
* The bookmark lives in the entry's STATE payload, not the URL: an
|
|
10
|
+
* entry that names a window keeps a clean address bar, and the payload
|
|
11
|
+
* survives the cross-document round trip (leave through the maximized
|
|
12
|
+
* OK, come back through the browser back — a fresh boot reads the
|
|
13
|
+
* bookmark and reveals the section without any hash to restore it
|
|
14
|
+
* from). Whatever state the entry already holds (react-router's
|
|
15
|
+
* usr/key/idx) is preserved: the bookmark is one merged key.
|
|
16
|
+
*
|
|
17
|
+
* The pushState WRAPPER is not ours — the pageSlide theme intercepts
|
|
18
|
+
* history.pushState to drive its page transitions. Same-path pushes
|
|
19
|
+
* (every anchor this module writes) stay silent there by design: the
|
|
20
|
+
* maximized view's entry is a UI entry, not a page arrival. */
|
|
21
|
+
|
|
22
|
+
/** The shape of the state payloads this module reads and writes. */
|
|
23
|
+
type EntryState = { window?: string } & Record<string, unknown>;
|
|
24
|
+
|
|
25
|
+
/** The current entry's state with our key merged in (react-router's own
|
|
26
|
+
* keys survive the merge — they are read back on popstate traversals). */
|
|
27
|
+
const withBookmark = (id?: string): EntryState => {
|
|
28
|
+
const state: EntryState = { ...((history.state ?? {}) as EntryState) };
|
|
29
|
+
if (id) state.window = id;
|
|
30
|
+
else delete state.window;
|
|
31
|
+
return state;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function attachHistoryBookmarks(): () => void {
|
|
35
|
+
const offAnchor = onSignal("history:anchor", ({ id, url, mode }) => {
|
|
36
|
+
if (mode === "push") history.pushState(withBookmark(id), "", url);
|
|
37
|
+
else history.replaceState(withBookmark(id), "", url);
|
|
38
|
+
});
|
|
39
|
+
const offRemember = onSignal("history:remember", ({ id, url }) => {
|
|
40
|
+
history.replaceState({ ...withBookmark(id), window: id }, "", url);
|
|
41
|
+
});
|
|
42
|
+
// The arrival marker: every in-document page commit is a TRAVERSAL —
|
|
43
|
+
// this document is a browsing session, never a fresh permalink again
|
|
44
|
+
// (see traversedOnce). The pageSlide theme announces commits on the
|
|
45
|
+
// bus: page:navigated for the pushState wrapper's and the popstate
|
|
46
|
+
// theme's cross-page commits, page:returned for the same-path
|
|
47
|
+
// traversals. Both are dispatched synchronously BEFORE the router's
|
|
48
|
+
// re-render remounts a page — a landing's initialFlags reads the
|
|
49
|
+
// marker in time.
|
|
50
|
+
const offNavigated = onSignal("page:navigated", () => {
|
|
51
|
+
traversedOnce = true;
|
|
52
|
+
});
|
|
53
|
+
const offReturned = onSignal("page:returned", () => {
|
|
54
|
+
traversedOnce = true;
|
|
55
|
+
});
|
|
56
|
+
return () => {
|
|
57
|
+
offAnchor();
|
|
58
|
+
offRemember();
|
|
59
|
+
offNavigated();
|
|
60
|
+
offReturned();
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** How THIS document arrived, per the Navigation Timing API: "navigate"
|
|
65
|
+
* (a fresh entry — nothing of ours can live in its state), "reload"
|
|
66
|
+
* (the entry's state survives the reload) and "back_forward" (the
|
|
67
|
+
* returned-to entry's state carries whatever it left with). NOTE: a
|
|
68
|
+
* same-document SPA traversal (the router's back onto the home page)
|
|
69
|
+
* keeps the ORIGINAL load's type — "navigate" — so a bookmark read back
|
|
70
|
+
* in that state is still ours-in-this-document, not a fresh arrival.
|
|
71
|
+
* See windowBookmark: the key's presence is the only gate it needs. */
|
|
72
|
+
export const navigationType = (): "navigate" | "reload" | "back_forward" => {
|
|
73
|
+
const entry = performance.getEntriesByType?.("navigation")[0] as
|
|
74
|
+
PerformanceNavigationTiming | undefined;
|
|
75
|
+
return entry?.type ?? "navigate";
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** The window the CURRENT entry is bookmarked to, or null. NO timing
|
|
79
|
+
* gate: the bookmark key is written by this module alone, merged into
|
|
80
|
+
* the entry the writer stood on — either within this very document (an
|
|
81
|
+
* internal link's bookmark, read back by the SAME document when the
|
|
82
|
+
* browser back remounts the page) or across one (the off-site
|
|
83
|
+
* departure, read back by a back_forward/reload arrival). A fresh
|
|
84
|
+
* cross-document navigation ("navigate" type) starts on a NEW entry
|
|
85
|
+
* whose state is null — it can never carry this key by accident, so
|
|
86
|
+
* the key's presence is already proof the entry is one of ours. The
|
|
87
|
+
* earlier timing gate actively BROKE the internal round trip: the SPA
|
|
88
|
+
* back shares the original load's "navigate" timing entry, so the
|
|
89
|
+
* bookmark written seconds before was refused on return. Gating on
|
|
90
|
+
* presence is exact. */
|
|
91
|
+
export function windowBookmark(): string | null {
|
|
92
|
+
const id = (history.state as EntryState | null)?.window;
|
|
93
|
+
return typeof id === "string" && id ? id : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Whether a traversal ALREADY happened in THIS document. Any in-document
|
|
97
|
+
* page commit (the pageSlide theme announces every SPA push and every
|
|
98
|
+
* history traversal on the bus — see attachHistoryBookmarks) sets this.
|
|
99
|
+
* Module scope: a fresh document load starts false. Once set, this
|
|
100
|
+
* document is a browsing session — a hyperlink landing on a section URL
|
|
101
|
+
* must be the INLINE reveal it always was, never the maximized permalink
|
|
102
|
+
* page (a permalink page is only for genuinely fresh arrivals). */
|
|
103
|
+
let traversedOnce = false;
|
|
104
|
+
|
|
105
|
+
/** Whether THIS document followed a same-site hyperlink in: an in-site
|
|
106
|
+
* raw anchor's cross-document arrival carries a same-origin referrer
|
|
107
|
+
* (full document loads bypass every SPA hook, so the click is invisible
|
|
108
|
+
* to the app). That click IS the traversal into the section, not a
|
|
109
|
+
* fresh permalink — the landing is inline. Typed URLs, out-of-site
|
|
110
|
+
* shared links and the Permalink button (window.open ... noreferrer)
|
|
111
|
+
* arrive REFERRER-LESS; the maximized landing stays theirs. */
|
|
112
|
+
const inSiteLinkArrival = (): boolean => {
|
|
113
|
+
if (!document.referrer) return false;
|
|
114
|
+
try {
|
|
115
|
+
return new URL(document.referrer).origin === window.location.origin;
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** Whether THIS document arrived FRESH — typed, shared, or opened by a
|
|
122
|
+
* permalink button in a new tab: the "navigate" timing type, an entry
|
|
123
|
+
* that carries none of our window state, no earlier in-document
|
|
124
|
+
* traversal (traversedOnce) and no same-site referrer
|
|
125
|
+
* (inSiteLinkArrival). A same-document SPA traversal shares the
|
|
126
|
+
* original load's "navigate" type, and an in-site hyperlink's
|
|
127
|
+
* cross-document load shares the same shape — BOTH are traversals, and
|
|
128
|
+
* both land on the inline reveal they always had. The maximized
|
|
129
|
+
* permalink landing is only for genuinely fresh arrivals: returns never
|
|
130
|
+
* re-maximize, and a hyperlink NEVER lifts the section out of the page
|
|
131
|
+
* it was read on.
|
|
132
|
+
*
|
|
133
|
+
* The decision is MEMOIZED at the first call: the permalink landing
|
|
134
|
+
* itself anchors its entry (history:anchor writes the bookmark) within
|
|
135
|
+
* its first render cycle, and a later evaluation of the raw conditions
|
|
136
|
+
* would read that bookmark and un-decide the landing mid-flight —
|
|
137
|
+
* StrictMode's double-invoked effects flipped maximized landings into
|
|
138
|
+
* inline reveals in dev, and nothing could rely on the answer staying
|
|
139
|
+
* put. The memo lives until a traversal happens, after which this
|
|
140
|
+
* document is a browsing session and every answer is false. */
|
|
141
|
+
let freshAtLoad: boolean | null = null;
|
|
142
|
+
|
|
143
|
+
export function freshArrival(): boolean {
|
|
144
|
+
if (traversedOnce) return false;
|
|
145
|
+
if (freshAtLoad === null) {
|
|
146
|
+
freshAtLoad =
|
|
147
|
+
navigationType() === "navigate" &&
|
|
148
|
+
windowBookmark() === null &&
|
|
149
|
+
!inSiteLinkArrival();
|
|
150
|
+
}
|
|
151
|
+
return freshAtLoad;
|
|
152
|
+
}
|
package/src/lib/markdown.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import Markdown from "react-markdown";
|
|
2
2
|
import rehypeRaw from "rehype-raw";
|
|
3
3
|
import rehypeSanitize from "rehype-sanitize";
|
|
4
|
+
import remarkBreaks from "remark-breaks";
|
|
5
|
+
import remarkGfm from "remark-gfm";
|
|
4
6
|
import { Link } from "react-router-dom";
|
|
5
7
|
import { rehypeYoutubeEmbed } from "@/lib/rehypeYoutubeEmbed";
|
|
6
8
|
import { sanitizeSchema } from "@/lib/sanitizeSchema";
|
|
@@ -8,9 +10,17 @@ import { CLIPPY_LINK, onClippyTriggerClick } from "./clippy";
|
|
|
8
10
|
|
|
9
11
|
type Props = { children: string; inline?: boolean };
|
|
10
12
|
|
|
11
|
-
export function Md({ children }: Props) {
|
|
13
|
+
export function Md({ children }: Readonly<Props>) {
|
|
12
14
|
return (
|
|
13
15
|
<Markdown
|
|
16
|
+
// remarkBreaks: a single newline prints as a line break, not a
|
|
17
|
+
// soft-break space — line-oriented writing (transcripts, rants,
|
|
18
|
+
// verse) keeps its authored line shape instead of flowing into
|
|
19
|
+
// one paragraph; a blank line still opens a new paragraph.
|
|
20
|
+
// remarkGfm: CommonMark pipes tables (| Recipe | Effect |) so
|
|
21
|
+
// content files need no raw <table> HTML; strikethrough and
|
|
22
|
+
// task lists come along (unused today).
|
|
23
|
+
remarkPlugins={[remarkBreaks, remarkGfm]}
|
|
14
24
|
rehypePlugins={[
|
|
15
25
|
rehypeRaw,
|
|
16
26
|
rehypeYoutubeEmbed,
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Scrolls the named element into view — inside its scrolling window (a
|
|
2
|
+
* maximized window scrolls its own revealed content) or the page. A
|
|
3
|
+
* target already fully on screen is left exactly where it is: the
|
|
4
|
+
* landing scroll exists to reveal an off-screen section, so yanking a
|
|
5
|
+
* visible one to the top row would only scramble the reader's place.
|
|
6
|
+
* The element can mount after the route commit (lazy pages), and the
|
|
7
|
+
* fresh page's height GROWS around the arrival (lazy embeds, images) —
|
|
8
|
+
* an early scroll into a document still shorter than the target is
|
|
9
|
+
* clamped to the top by the browser. So the landing re-aims on every
|
|
10
|
+
* tick while it may have missed: as soon as the element mounts off
|
|
11
|
+
* screen it gets aimed at, and the loop stops the moment the layout
|
|
12
|
+
* settles with it on screen.
|
|
13
|
+
*
|
|
14
|
+
* Lives in lib (not in the pageSlide theme) because two owners aim
|
|
15
|
+
* landings: the theme — every hash navigation, boot, popstate and the
|
|
16
|
+
* alias re-land — and the window system, whose dismissals of SEEDED
|
|
17
|
+
* maximized landings (a permalink opened the section maximized; the OK
|
|
18
|
+
* press minimized it into the page) are the reader's arrival at the
|
|
19
|
+
* section's inline resting place. */
|
|
20
|
+
export function scrollToId(id: string, attempts = 12): void {
|
|
21
|
+
if (!id) return;
|
|
22
|
+
const tick = (left: number) => {
|
|
23
|
+
const el = document.getElementById(id);
|
|
24
|
+
if (!el) {
|
|
25
|
+
// The element can mount after the route commit (lazy pages).
|
|
26
|
+
if (left > 0) window.setTimeout(() => tick(left - 1), 100);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Maximized windows are viewport-fixed overlays; scrolling the page
|
|
30
|
+
// behind them just resets the background while the overlay hides
|
|
31
|
+
// it. The restored window scrolls itself to the target on dismissal
|
|
32
|
+
// instead.
|
|
33
|
+
if (!el.closest(".maximized-backdrop")) {
|
|
34
|
+
const rect = el.getBoundingClientRect();
|
|
35
|
+
if (rect.top < 0 || rect.bottom > window.innerHeight) {
|
|
36
|
+
el.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
37
|
+
// The aim may have been clamped (the document was shorter than
|
|
38
|
+
// the target's position): keep aiming until it sticks.
|
|
39
|
+
if (left > 0) window.setTimeout(() => tick(left - 1), 100);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
tick(attempts);
|
|
45
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
useCallback,
|
|
4
|
+
useContext,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
useSyncExternalStore,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
} from "react";
|
|
11
|
+
|
|
12
|
+
/** The named signals of the app: every entry declares a signal's
|
|
13
|
+
* payload, and dispatching and handling are checked against it. Four
|
|
14
|
+
* shapes live here — commands ("app:navigate": a handler performs the
|
|
15
|
+
* behaviour), notices ("page:loaded", "page:navigated": fire-and-forget
|
|
16
|
+
* monitoring), refusable requests ("window:close": handlers may call
|
|
17
|
+
* refuse() before the dispatch returns) and RETAINED notices
|
|
18
|
+
* ("window:hidden": the last snapshot stays readable, see RETAINED).
|
|
19
|
+
* Handlers run synchronously inside the dispatching stack: keep them
|
|
20
|
+
* side-effect-first, no long work, no awaits. */
|
|
21
|
+
export type SignalManifest = {
|
|
22
|
+
"app:navigate": { to: string };
|
|
23
|
+
"page:loaded": { path: string };
|
|
24
|
+
"page:navigated": { from: string; to: string };
|
|
25
|
+
/** History traversal landed on a route (browser back/forward): the
|
|
26
|
+
* page RETURNED — unlike a permalink arrival, a same-path traversal
|
|
27
|
+
* does not remount it, so the page holds the flags it left with. */
|
|
28
|
+
"page:returned": { path: string; hash: string };
|
|
29
|
+
/** The page's ADDRESS changed within the same route: the router
|
|
30
|
+
* pushed a same-path entry whose query or hash names a new target
|
|
31
|
+
* (?post=, #id — an in-site link click, not a traversal). The page
|
|
32
|
+
* does not remount, so holders of pre-address state repair
|
|
33
|
+
* themselves the way a history RETURN does: maximized windows the
|
|
34
|
+
* new address no longer names minimize, the named target reveals.
|
|
35
|
+
* The window system's own anchor pushes carry the state bookmark and
|
|
36
|
+
* never announce (they are UI entries, not content addresses). */
|
|
37
|
+
"page:addressed": { path: string; hash: string };
|
|
38
|
+
"window:close": { id: string; refuse: () => void };
|
|
39
|
+
/** Notice — Clippy parked the window the ✕ was pressed on (the
|
|
40
|
+
* mascot-on-screen easter egg): the successful close routed through
|
|
41
|
+
* Clippy's keep. Clippy owns the outcome and pipes up ("oh where did
|
|
42
|
+
* that go?.. I can help!"), offering its unhide roster. */
|
|
43
|
+
"clippy:hid": { id: string };
|
|
44
|
+
/** THE close's outcome NOTICE, with its sound DECLARED: the ✕ press
|
|
45
|
+
* dispatches which sound should play — the crunchy kick for every
|
|
46
|
+
* press that stays on the page (refusals, collapses, parks,
|
|
47
|
+
* maximized restores), the Click.ogg for the press that navigates
|
|
48
|
+
* away. One renderer (closeSounds.ts) plays what is declared. */
|
|
49
|
+
"window:closed": { id: string; sound: "kick" | "click" };
|
|
50
|
+
/** Command — the listening window's controller lifts the maximized
|
|
51
|
+
* view (the OK middleware rides this instead of threading a callback
|
|
52
|
+
* prop through the tree). */
|
|
53
|
+
"window:maximize": { id: string };
|
|
54
|
+
/** Command — restore/silently-dismiss the maximized view: ✕ on a
|
|
55
|
+
* maximized window, Escape, the out-of-bounds backdrop click and the
|
|
56
|
+
* title-bar Restore all ride this; the window's controller restores
|
|
57
|
+
* the flags it left with. `reveal: true` additionally reveals the
|
|
58
|
+
* content inline after the restore (the rail's OK/Cancel pair) —
|
|
59
|
+
* restore alone is the silent framing dismissal it always was. */
|
|
60
|
+
"window:dismiss": { id: string; reveal?: boolean | undefined };
|
|
61
|
+
/** Command — THE minimize: one path for every minimize gesture and
|
|
62
|
+
* its callbacks. On a maximized window the dismissal plays the
|
|
63
|
+
* minimize click (Click.ogg), slides the window off and either
|
|
64
|
+
* RESTORES the section underneath exactly as it stood at maximize
|
|
65
|
+
* time (park unset — the browser back out of the maximized view: the
|
|
66
|
+
* traversal pops the maximize push and the page:returned repair
|
|
67
|
+
* dispatches this) or COLLAPSES it the way the inline minimize
|
|
68
|
+
* handler always does (park set — the title-bar minimize button, and
|
|
69
|
+
* the double-click on the maximized title bar: the maximized overlay
|
|
70
|
+
* AND the section underneath both minimize; the section lands in its
|
|
71
|
+
* normal resting shape, OK bottom-right). Inline the depth-0 fold
|
|
72
|
+
* navigates away; every other inline window collapses to its title
|
|
73
|
+
* bar's ok row. The window's own controller performs the branch —
|
|
74
|
+
* every window listens, only the named one acts. */
|
|
75
|
+
"window:minimize": { id: string; park?: boolean };
|
|
76
|
+
/** Command — expand the named window WITHOUT lifting it: its lineage
|
|
77
|
+
* always opens (a collapsed parent never mounts its target), then
|
|
78
|
+
* either nothing but the target itself ("none" — the maximized view
|
|
79
|
+
* restored inline: a framing, not a reveal — collapsed sections stay
|
|
80
|
+
* collapsed), its direct children, or the whole subtree ("all"). The
|
|
81
|
+
* maximized framing keeps a returned section's inner sections as
|
|
82
|
+
* they stood — no force-open cascade behind the backdrop. */
|
|
83
|
+
"window:reveal": { id: string; descendants: "none" | "direct" | "all" };
|
|
84
|
+
/** Command — the history owner (lib/history) writes the named window
|
|
85
|
+
* into the CURRENT history entry: the id rides the entry's state
|
|
86
|
+
* payload ("window" key), the URL goes to what the caller computed.
|
|
87
|
+
* mode "push" is the maximized view's own history entry (browser back
|
|
88
|
+
* then pops INTO it: one entry per maximize, back un-maximizes);
|
|
89
|
+
* mode "replace" settles the URL after an in-page dismissal, dropping
|
|
90
|
+
* the bookmark when no maximized window remains. */
|
|
91
|
+
"history:anchor": {
|
|
92
|
+
/** Absent: clear the entry's bookmark (the last maximized window
|
|
93
|
+
* was dismissed); present: the window the entry names. */
|
|
94
|
+
id?: string | undefined;
|
|
95
|
+
url: string;
|
|
96
|
+
mode: "push" | "replace";
|
|
97
|
+
};
|
|
98
|
+
/** Command — bookmark the named window for an OFF-SITE departure: the
|
|
99
|
+
* CURRENT entry's state gains "window" and the URL lands on the
|
|
100
|
+
* caller's hash-free form, so navigating back to this entry (cross
|
|
101
|
+
* document, a fresh boot) reveals and scrolls to the section while
|
|
102
|
+
* the address bar carries no hash of it. */
|
|
103
|
+
"history:remember": { id: string; url: string };
|
|
104
|
+
"window:hidden": {
|
|
105
|
+
items: Array<{ id: string; label: string }>;
|
|
106
|
+
restore: (id: string) => void;
|
|
107
|
+
}; // retained — the parked-window roster; readers hold no state of their own
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** The roster of no parked windows: both the retained seed and the
|
|
111
|
+
* answer broadcasters send when the roster empties, so snapshot
|
|
112
|
+
* identity is stable across every empty interval. */
|
|
113
|
+
export const EMPTY_HIDDEN: SignalManifest["window:hidden"] = {
|
|
114
|
+
items: [],
|
|
115
|
+
restore: () => {},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/** Which signals RETAIN their last payload at module scope, seeded
|
|
119
|
+
* before the first dispatch. A retained signal's consumers are
|
|
120
|
+
* render-time READERS (useSignalValue) instead of effect-bound
|
|
121
|
+
* handlers: no useState bridge, no subscription management. A retained
|
|
122
|
+
* publisher must send a fresh snapshot object per change and never
|
|
123
|
+
* recompute the current one on read — useRetained does both. */
|
|
124
|
+
export const RETAINED: Partial<Record<SignalName, SignalManifest[SignalName]>> =
|
|
125
|
+
{
|
|
126
|
+
"window:hidden": EMPTY_HIDDEN,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export type SignalName = keyof SignalManifest;
|
|
130
|
+
|
|
131
|
+
export type SignalHandler<Name extends SignalName = SignalName> = (
|
|
132
|
+
payload: SignalManifest[Name],
|
|
133
|
+
) => void;
|
|
134
|
+
|
|
135
|
+
/** Handlers registered per signal name. The never-parameter shape keeps
|
|
136
|
+
* the registry untyped internally while dispatch/on stay fully typed. */
|
|
137
|
+
type AnyHandler = (payload: never) => void;
|
|
138
|
+
const handlers = new Map<SignalName, Set<AnyHandler>>();
|
|
139
|
+
|
|
140
|
+
/** The last dispatched payload of each retained signal, and the cached
|
|
141
|
+
* getSnapshot of every one: identity is stable between dispatches, as
|
|
142
|
+
* useSyncExternalStore requires. */
|
|
143
|
+
const lastRetained = new Map<SignalName, SignalManifest[SignalName]>();
|
|
144
|
+
const retainedListeners = new Map<SignalName, Set<() => void>>();
|
|
145
|
+
const cachedSnapshot = (name: SignalName): SignalManifest[SignalName] =>
|
|
146
|
+
lastRetained.get(name) ?? RETAINED[name] ?? EMPTY_HIDDEN;
|
|
147
|
+
|
|
148
|
+
/** Dispatches a named signal: every current handler runs synchronously,
|
|
149
|
+
* in registration order, over a snapshot (handlers may unsubscribe or
|
|
150
|
+
* dispatch further signals mid-flight). Retained signals take their new
|
|
151
|
+
* snapshot BEFORE the handlers run (handlers read a consistent world)
|
|
152
|
+
* and their readers re-render AFTER they settle (no mid-dispatch
|
|
153
|
+
* render). The bus lives at module scope so machinery outside React —
|
|
154
|
+
* the pageSlide theme, lib singletons — dispatches and listens too; the
|
|
155
|
+
* context below makes it ambient for components. */
|
|
156
|
+
export function dispatchSignal<Name extends SignalName>(
|
|
157
|
+
name: Name,
|
|
158
|
+
payload: SignalManifest[Name],
|
|
159
|
+
): void {
|
|
160
|
+
if (name in RETAINED) lastRetained.set(name, payload);
|
|
161
|
+
const registered = handlers.get(name);
|
|
162
|
+
if (registered) {
|
|
163
|
+
for (const handler of [...registered]) {
|
|
164
|
+
(handler as SignalHandler<Name>)(payload);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const listeners = retainedListeners.get(name);
|
|
168
|
+
if (listeners) {
|
|
169
|
+
for (const listener of [...listeners]) listener();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Subscribes a handler to a named signal; returns the unsubscribe. */
|
|
174
|
+
export function onSignal<Name extends SignalName>(
|
|
175
|
+
name: Name,
|
|
176
|
+
handler: SignalHandler<Name>,
|
|
177
|
+
): () => void {
|
|
178
|
+
let registered = handlers.get(name);
|
|
179
|
+
if (!registered) handlers.set(name, (registered = new Set()));
|
|
180
|
+
const entry = handler as AnyHandler;
|
|
181
|
+
registered.add(entry);
|
|
182
|
+
return () => {
|
|
183
|
+
registered?.delete(entry);
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Subscribes a render-time reader of a retained signal's snapshots;
|
|
188
|
+
* returns the unsubscribe. The never-parameter shape defers to the same
|
|
189
|
+
* internal typing as the handler registry. */
|
|
190
|
+
function onRetained(name: SignalName, listener: () => void): () => void {
|
|
191
|
+
let registered = retainedListeners.get(name);
|
|
192
|
+
if (!registered) retainedListeners.set(name, (registered = new Set()));
|
|
193
|
+
registered.add(listener);
|
|
194
|
+
return () => {
|
|
195
|
+
registered?.delete(listener);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
type SignalBus = {
|
|
200
|
+
dispatch: typeof dispatchSignal;
|
|
201
|
+
on: typeof onSignal;
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const Ctx = createContext<SignalBus | null>(null);
|
|
205
|
+
|
|
206
|
+
/** Wraps the app in the abstract signal context. The bus is shared and
|
|
207
|
+
* stable, so the provider never re-renders consumers — signals are
|
|
208
|
+
* events, not state. */
|
|
209
|
+
export function SignalProvider({ children }: { children: ReactNode }) {
|
|
210
|
+
const bus = useMemo<SignalBus>(
|
|
211
|
+
() => ({ dispatch: dispatchSignal, on: onSignal }),
|
|
212
|
+
[],
|
|
213
|
+
);
|
|
214
|
+
return <Ctx.Provider value={bus}>{children}</Ctx.Provider>;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function useSignals(): SignalBus {
|
|
218
|
+
const bus = useContext(Ctx);
|
|
219
|
+
if (!bus) throw new Error("useSignals needs a SignalProvider");
|
|
220
|
+
return bus;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Subscribes a handler for the component's lifetime; the latest handler
|
|
224
|
+
* closure runs on every dispatch (no resubscription churn). THE one
|
|
225
|
+
* component-scoped escape hatch: for handlers that must close over
|
|
226
|
+
* component state no module-level attach can reach (e.g. the window
|
|
227
|
+
* store's return repair). Behaviours with a module owner attach via
|
|
228
|
+
* onSignal instead of calling this. */
|
|
229
|
+
export function useSignalHandler<Name extends SignalName>(
|
|
230
|
+
name: Name,
|
|
231
|
+
handler: SignalHandler<Name>,
|
|
232
|
+
): void {
|
|
233
|
+
const { on } = useSignals();
|
|
234
|
+
const latest = useRef(handler);
|
|
235
|
+
latest.current = handler;
|
|
236
|
+
useEffect(() => on(name, (payload) => latest.current(payload)), [name, on]);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Reads a retained signal's current snapshot at render time: the
|
|
240
|
+
* subscription lifecycle is useSyncExternalStore's business, not the
|
|
241
|
+
* component's — no useState bridge, no manual effect, no missed first
|
|
242
|
+
* publish. */
|
|
243
|
+
export function useSignalValue<Name extends SignalName>(
|
|
244
|
+
name: Name,
|
|
245
|
+
): SignalManifest[Name] {
|
|
246
|
+
const subscribe = useCallback(
|
|
247
|
+
(onChange: () => void) => onRetained(name, onChange),
|
|
248
|
+
[name],
|
|
249
|
+
);
|
|
250
|
+
return useSyncExternalStore(
|
|
251
|
+
subscribe,
|
|
252
|
+
() => cachedSnapshot(name) as SignalManifest[Name],
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Declares a retained publication: the publisher hands in the
|
|
257
|
+
* snapshot it currently holds (a fresh object per change) and commits
|
|
258
|
+
* nothing itself — the library broadcasts it post-render whenever its
|
|
259
|
+
* identity changes and restores the manifest seed on unmount, so a
|
|
260
|
+
* publisher's reader never sees a stale roster after the page that
|
|
261
|
+
* parked the window is gone. Publishers stay declarative: no dispatch
|
|
262
|
+
* choreography, no teardown effect. */
|
|
263
|
+
export function useRetained<Name extends SignalName>(
|
|
264
|
+
name: Name,
|
|
265
|
+
snapshot: SignalManifest[Name],
|
|
266
|
+
): void {
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
dispatchSignal(name, snapshot);
|
|
269
|
+
return () => dispatchSignal(name, RETAINED[name] as SignalManifest[Name]);
|
|
270
|
+
}, [name, snapshot]);
|
|
271
|
+
}
|
package/src/main.tsx
CHANGED
|
@@ -5,15 +5,29 @@ import "xp.css/dist/98.css";
|
|
|
5
5
|
import "react-toastify/dist/ReactToastify.css";
|
|
6
6
|
import "./styles/index.css";
|
|
7
7
|
import { App } from "./shell/App";
|
|
8
|
+
import { SignalProvider } from "./lib/signals";
|
|
9
|
+
import { attachHistoryBookmarks } from "./lib/history";
|
|
10
|
+
import { attachRouterSignals } from "./shell/routerSignals";
|
|
11
|
+
import { attachCloseSounds } from "./window/closeSounds";
|
|
8
12
|
import { enablePageSlide } from "./themes/pageSlide";
|
|
9
13
|
|
|
10
14
|
document.body.classList.add("styles-loaded");
|
|
15
|
+
// Attach the shell's signal handlers at boot, next to the theme: the
|
|
16
|
+
// bus carries navigation commands, route-change notices and window
|
|
17
|
+
// events; handlers live here and in lib modules, not in components.
|
|
18
|
+
attachRouterSignals();
|
|
19
|
+
attachCloseSounds();
|
|
20
|
+
// The history bookmarker (maximized-view pushes, hash-free off-site
|
|
21
|
+
// bookmarks, dismissal settles) attaches at boot too: the maximized
|
|
22
|
+
// view's push rides the pageSlide pushState wrapper, so the owner must
|
|
23
|
+
// be live before any window can lift.
|
|
24
|
+
attachHistoryBookmarks();
|
|
11
25
|
// Always install the page-slide theme: its hooks drive window
|
|
12
26
|
// minimisation, navigation choreography and sounds. When the page is
|
|
13
27
|
// loaded directly ONTO a hyperlinked window target (a #hash or ?post=
|
|
14
|
-
// the route
|
|
15
|
-
// — so the entrance
|
|
16
|
-
// the
|
|
28
|
+
// slug the route reveals), the theme starts "parked" — zero slide
|
|
29
|
+
// distance — so the entrance plays from nowhere and disturbs nothing
|
|
30
|
+
// before the reveal scrolls to the linked section. Page loads without a
|
|
17
31
|
// hyperlink target slide in from the top as usual; later navigations
|
|
18
32
|
// apply a real direction and slide as usual.
|
|
19
33
|
enablePageSlide();
|
|
@@ -21,7 +35,9 @@ enablePageSlide();
|
|
|
21
35
|
createRoot(document.getElementById("root")!).render(
|
|
22
36
|
<StrictMode>
|
|
23
37
|
<BrowserRouter>
|
|
24
|
-
<
|
|
38
|
+
<SignalProvider>
|
|
39
|
+
<App />
|
|
40
|
+
</SignalProvider>
|
|
25
41
|
</BrowserRouter>
|
|
26
42
|
</StrictMode>,
|
|
27
43
|
);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { blogDirListed, blogDirListing, findBlogDir } from "@/content";
|
|
2
|
+
import { useSignals } from "@/lib/signals";
|
|
3
|
+
import { useLocation } from "react-router-dom";
|
|
4
|
+
import { PageWindows } from "@/window";
|
|
5
|
+
|
|
6
|
+
/** A configured directory under /blog/ (src/content/blogDirs.ts): the
|
|
7
|
+
* page is the directory's LISTING — one window naming each shown file,
|
|
8
|
+
* linked to its post page or raw asset. The route exists only for
|
|
9
|
+
* configured directories (resolveRoute), so an unconfigured pathname
|
|
10
|
+
* renders nothing here.
|
|
11
|
+
*
|
|
12
|
+
* The title-bar Minimize and ✕ fold UP a level: the page's onLeave (the
|
|
13
|
+
* depth-0 fold — the same wiring that returns a project page to its
|
|
14
|
+
* index) navigates to the directory above, with the fold animation and
|
|
15
|
+
* the navigating sounds the window system already owns. The parent is
|
|
16
|
+
* the literal parent path; when that parent is a blog subdirectory that
|
|
17
|
+
* does not list (an opted-out shelf), the fold lands on the blog root
|
|
18
|
+
* instead of a dead end. */
|
|
19
|
+
export const BlogDirPage = () => {
|
|
20
|
+
const { pathname } = useLocation();
|
|
21
|
+
const { dispatch } = useSignals();
|
|
22
|
+
const listing = blogDirListing(pathname);
|
|
23
|
+
if (!listing) return null;
|
|
24
|
+
const parent = pathname.replace(/\/+$/, "").replace(/\/[^/]*$/, "") || "/";
|
|
25
|
+
const parentLists =
|
|
26
|
+
parent === "/blog" ||
|
|
27
|
+
(Boolean(findBlogDir(parent)) && blogDirListed(parent));
|
|
28
|
+
return (
|
|
29
|
+
<PageWindows
|
|
30
|
+
content={listing}
|
|
31
|
+
onLeave={() =>
|
|
32
|
+
dispatch("app:navigate", { to: parentLists ? parent : "/blog" })
|
|
33
|
+
}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
blogDirListed,
|
|
3
|
+
findBlogDir,
|
|
4
|
+
type Section,
|
|
5
|
+
type ThemeName,
|
|
6
|
+
} from "@/content";
|
|
7
|
+
import { useSignals } from "@/lib/signals";
|
|
8
|
+
import { useEffect, useMemo, useState } from "react";
|
|
2
9
|
import { useLocation } from "react-router-dom";
|
|
3
10
|
import { PageWindows } from "@/window";
|
|
4
11
|
|
|
5
|
-
/** A markdown file from public/blog/, addressed directly by its URL.
|
|
12
|
+
/** A markdown file from public/blog/, addressed directly by its URL.
|
|
13
|
+
*
|
|
14
|
+
* Posts may also be authored as .json Section trees (the same shape the
|
|
15
|
+
* content JSON files use). The parent directory's generated snapshot
|
|
16
|
+
* (src/content/blogDirs.json) tells the two forms apart: a `<name>.json`
|
|
17
|
+
* entry in the listing means the address renders THAT file — fetched at
|
|
18
|
+
* runtime and mounted through the same PageWindows tree any authored
|
|
19
|
+
* post uses; everything else embeds the markdown `<path>.md`.
|
|
20
|
+
*
|
|
21
|
+
* A post INSIDE a listed blog directory folds UP a level: its title-bar
|
|
22
|
+
* Minimize and ✕ navigate back to the parent directory's listing — the
|
|
23
|
+
* same depth-0 onLeave fold the listing page itself uses. Posts at the
|
|
24
|
+
* /blog root keep the plain page behaviour (their parent is the curated
|
|
25
|
+
* blog page, not a directory listing). */
|
|
6
26
|
export const BlogPostPage = () => {
|
|
7
27
|
const { pathname } = useLocation();
|
|
28
|
+
const { dispatch } = useSignals();
|
|
8
29
|
const content = useMemo(() => {
|
|
9
30
|
const src = decodeURI(pathname);
|
|
10
31
|
return {
|
|
@@ -12,5 +33,57 @@ export const BlogPostPage = () => {
|
|
|
12
33
|
embed: `${pathname}.md`,
|
|
13
34
|
};
|
|
14
35
|
}, [pathname]);
|
|
15
|
-
|
|
36
|
+
const isJson = useMemo(() => {
|
|
37
|
+
const parent = pathname.replace(/\/+$/, "").replace(/\/[^/]*$/, "") || "/";
|
|
38
|
+
const base = decodeURI(pathname).split("/").pop() ?? "";
|
|
39
|
+
return Boolean(findBlogDir(parent)?.files.includes(`${base}.json`));
|
|
40
|
+
}, [pathname]);
|
|
41
|
+
const [jsonPost, setJsonPost] = useState<Section | null>(null);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!isJson) return;
|
|
44
|
+
let live = true;
|
|
45
|
+
setJsonPost(null);
|
|
46
|
+
fetch(`${pathname}.json`)
|
|
47
|
+
.then((r) => {
|
|
48
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
49
|
+
return r.json() as Promise<Section>;
|
|
50
|
+
})
|
|
51
|
+
.then((section) => {
|
|
52
|
+
if (live) setJsonPost(section);
|
|
53
|
+
})
|
|
54
|
+
.catch(() => {
|
|
55
|
+
if (live) setJsonPost(null);
|
|
56
|
+
});
|
|
57
|
+
return () => {
|
|
58
|
+
live = false;
|
|
59
|
+
};
|
|
60
|
+
}, [isJson, pathname]);
|
|
61
|
+
const parent = pathname.replace(/\/+$/, "").replace(/\/[^/]*$/, "") || "/";
|
|
62
|
+
const parentDir = findBlogDir(parent);
|
|
63
|
+
const foldsUp = Boolean(parentDir) && blogDirListed(parentDir?.path ?? "");
|
|
64
|
+
// A .md post's embed forces its window expanded; a .json post's tree
|
|
65
|
+
// must read the same way — the root window opens (theme "open" merged
|
|
66
|
+
// into whatever the author set) so its children mount, exactly like
|
|
67
|
+
// the authored posts on the blog page itself.
|
|
68
|
+
const post = useMemo(() => {
|
|
69
|
+
if (!isJson) return content;
|
|
70
|
+
if (!jsonPost) return null;
|
|
71
|
+
const themes = jsonPost.theme
|
|
72
|
+
? Array.isArray(jsonPost.theme)
|
|
73
|
+
? jsonPost.theme
|
|
74
|
+
: [jsonPost.theme]
|
|
75
|
+
: [];
|
|
76
|
+
return themes.includes("open")
|
|
77
|
+
? jsonPost
|
|
78
|
+
: { ...jsonPost, theme: [...themes, "open"] as ThemeName[] };
|
|
79
|
+
}, [isJson, jsonPost, content]);
|
|
80
|
+
if (!post) return null;
|
|
81
|
+
return (
|
|
82
|
+
<PageWindows
|
|
83
|
+
content={post}
|
|
84
|
+
onLeave={
|
|
85
|
+
foldsUp ? () => dispatch("app:navigate", { to: parent }) : undefined
|
|
86
|
+
}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
16
89
|
};
|