@bigmistqke/whiteboard 0.4.0 → 0.6.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/README.md +177 -26
- package/bin/whiteboard.ts +331 -16
- package/dist/bin/whiteboard.js +268 -17
- package/dist/client/runtime.js +66 -23
- package/dist/plugins/ansi/README.md +36 -0
- package/dist/plugins/ansi/index.js +64 -0
- package/dist/plugins/ansi/public/style.css +28 -0
- package/dist/plugins/badge/README.md +28 -0
- package/dist/plugins/badge/index.js +24 -0
- package/dist/plugins/badge/public/style.css +30 -0
- package/dist/plugins/chat/public/style.css +7 -2
- package/dist/plugins/code/README.md +4 -2
- package/dist/plugins/code/diff.js +12 -2
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/grid/README.md +12 -12
- package/dist/plugins/grid/index.js +7 -19
- package/dist/plugins/grid/public/style.css +4 -33
- package/dist/plugins/iframe/README.md +7 -7
- package/dist/plugins/iframe/index.js +11 -11
- package/dist/plugins/iframe/public/style.css +15 -0
- package/dist/plugins/index.js +11 -3
- package/dist/plugins/lightbox/README.md +22 -0
- package/dist/plugins/lightbox/index.js +20 -0
- package/dist/plugins/lightbox/public/client.js +4 -0
- package/dist/plugins/lightbox/public/style.css +66 -0
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +60 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/public/client.js +1 -1
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +8 -2
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +10 -4
- package/dist/plugins/window/README.md +34 -14
- package/dist/plugins/window/index.js +21 -13
- package/dist/src/auth.js +6 -4
- package/dist/src/client/page/base.css +61 -1
- package/dist/src/client/page/main.js +74 -20
- package/dist/src/entries.js +211 -0
- package/dist/src/events.js +1 -1
- package/dist/src/hub.js +272 -0
- package/dist/src/loader.js +12 -3
- package/dist/src/package.js +23 -1
- package/dist/src/pages/blocks.js +1 -0
- package/dist/src/pages/index.js +1 -1
- package/dist/src/pages/markdown.js +87 -33
- package/dist/src/pages/render.js +157 -28
- package/dist/src/pages/window.js +17 -18
- package/dist/src/running.js +37 -2
- package/dist/src/serve.js +111 -2
- package/dist/src/server.js +264 -23
- package/package.json +3 -2
- package/plugins/ansi/README.md +36 -0
- package/plugins/ansi/index.ts +95 -0
- package/plugins/ansi/public/style.css +28 -0
- package/plugins/badge/README.md +28 -0
- package/plugins/badge/index.ts +35 -0
- package/plugins/badge/public/style.css +30 -0
- package/plugins/chat/public/style.css +7 -2
- package/plugins/code/README.md +4 -2
- package/plugins/code/diff.ts +14 -2
- package/plugins/code/index.ts +3 -1
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/grid/README.md +12 -12
- package/plugins/grid/index.ts +11 -26
- package/plugins/grid/public/style.css +4 -33
- package/plugins/iframe/README.md +7 -7
- package/plugins/iframe/index.ts +15 -15
- package/plugins/iframe/public/style.css +15 -0
- package/plugins/index.ts +10 -2
- package/plugins/lightbox/README.md +22 -0
- package/plugins/lightbox/client.ts +99 -0
- package/plugins/lightbox/index.ts +25 -0
- package/plugins/lightbox/public/style.css +66 -0
- package/plugins/mermaid/index.ts +4 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +75 -0
- package/plugins/steps/index.ts +84 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +16 -7
- package/plugins/terminal/host.ts +12 -6
- package/plugins/terminal/sizes.ts +3 -1
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +47 -6
- package/plugins/toc/index.ts +19 -6
- package/plugins/toc/public/style.css +10 -4
- package/plugins/window/README.md +34 -14
- package/plugins/window/index.ts +20 -13
- package/skills/whiteboard/SKILL.md +18 -10
- package/src/auth.ts +8 -5
- package/src/client/base.ts +19 -0
- package/src/client/forms.ts +2 -1
- package/src/client/markdown.ts +2 -1
- package/src/client/page/base.css +61 -1
- package/src/client/page/elsewhere.ts +72 -16
- package/src/client/page/fresh.ts +2 -1
- package/src/client/page/main.ts +18 -6
- package/src/client/page/sort.ts +2 -1
- package/src/client/runtime.ts +62 -25
- package/src/define.ts +126 -19
- package/src/entries.ts +258 -0
- package/src/events.ts +2 -1
- package/src/hub.ts +355 -0
- package/src/loader.ts +14 -3
- package/src/package.ts +22 -0
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +6 -4
- package/src/pages/markdown.ts +89 -32
- package/src/pages/render.ts +181 -28
- package/src/pages/window.ts +23 -25
- package/src/running.ts +47 -1
- package/src/serve.ts +114 -1
- package/src/server.ts +332 -26
- package/dist/plugins/gallery/README.md +0 -30
- package/dist/plugins/gallery/index.js +0 -75
- package/dist/plugins/gallery/public/client.js +0 -1
- package/dist/plugins/gallery/public/style.css +0 -90
- package/plugins/gallery/README.md +0 -30
- package/plugins/gallery/client.tsx +0 -70
- package/plugins/gallery/index.ts +0 -89
- package/plugins/gallery/public/style.css +0 -90
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
/* the table of contents (client.ts): in the margin left of the text, or opened from the header */
|
|
2
|
+
/* it fits its items, between a minimum and a maximum (client.ts sets them from the options and the
|
|
3
|
+
page's frontmatter); docked, never wider than the room left of the text */
|
|
2
4
|
.wb-toc {
|
|
3
5
|
position: fixed;
|
|
4
6
|
z-index: var(--layer-aside);
|
|
5
|
-
font: var(--ui-small)/var(--ui-line-height) var(--sans, sans-serif);
|
|
7
|
+
font: var(--ui-small) / var(--ui-line-height) var(--sans, sans-serif);
|
|
8
|
+
box-sizing: border-box;
|
|
9
|
+
width: max-content;
|
|
10
|
+
min-width: var(--wb-toc-min-width, 160px);
|
|
11
|
+
max-width: var(--wb-toc-max-width, 320px);
|
|
6
12
|
}
|
|
7
13
|
.wb-toc[hidden],
|
|
8
14
|
.wb-toc-toggle[hidden] {
|
|
@@ -10,15 +16,15 @@
|
|
|
10
16
|
}
|
|
11
17
|
.wb-toc-docked {
|
|
12
18
|
top: 72px;
|
|
13
|
-
|
|
14
|
-
width:
|
|
19
|
+
right: var(--wb-toc-right);
|
|
20
|
+
max-width: min(var(--wb-toc-max-width, 320px), var(--wb-toc-room, 320px));
|
|
15
21
|
max-height: calc(100vh - 120px - var(--wb-inset-bottom, 0px));
|
|
16
22
|
overflow: auto;
|
|
17
23
|
}
|
|
18
24
|
.wb-toc-open:not(.wb-toc-docked) {
|
|
19
25
|
top: 52px;
|
|
20
26
|
left: 16px;
|
|
21
|
-
width: min(
|
|
27
|
+
max-width: min(var(--wb-toc-max-width, 320px), 100vw - 32px);
|
|
22
28
|
max-height: calc(100vh - 100px - var(--wb-inset-bottom, 0px));
|
|
23
29
|
overflow: auto;
|
|
24
30
|
padding: var(--space-sm);
|
package/plugins/window/README.md
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
A window: a header with a label, a button that fills the browser window with
|
|
2
2
|
what it shows (the same button, or Esc, puts it back), and one that opens it on
|
|
3
|
-
its own.
|
|
4
|
-
column; `height` (pixels or a CSS length) fixes its height, scrolling inside.
|
|
3
|
+
its own.
|
|
5
4
|
|
|
6
|
-
**
|
|
5
|
+
**Any block goes in one with `compose=window`**: an image, a video, another
|
|
6
|
+
page, a diagram, a grid. Its label is the window's title (or `title="A
|
|
7
|
+
title"`, for a block without a label, such as a fence), and ↗ opens what it
|
|
8
|
+
shows on its own, an image's file or a page's address. `wide` makes it wider
|
|
9
|
+
than the text column.
|
|
10
|
+
|
|
11
|
+
````markdown
|
|
12
|
+
::image[The new onboarding]{src="onboarding.png" compose=window}
|
|
13
|
+
|
|
14
|
+
```mermaid {compose=window title="How a page is served"}
|
|
15
|
+
graph LR; file --> server --> browser
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
:::grid{cols=2 compose=window title="Two options"}
|
|
19
|
+
…
|
|
20
|
+
:::
|
|
21
|
+
````
|
|
22
|
+
|
|
23
|
+
**One image or video**, without it, is just itself:
|
|
7
24
|
|
|
8
25
|
```markdown
|
|
9
26
|
::image[The new onboarding]{src="onboarding.png"}
|
|
@@ -13,17 +30,20 @@ column; `height` (pixels or a CSS length) fixes its height, scrolling inside.
|
|
|
13
30
|
|
|
14
31
|
A video has its controls; `loop`, `autoplay` (which starts it muted, as
|
|
15
32
|
browsers require) and `poster` are as for a `<video>`. A plain markdown image,
|
|
16
|
-
``,
|
|
33
|
+
``, is the same as `::image` without it.
|
|
17
34
|
|
|
18
|
-
**Any markdown**, in `:::window`: a
|
|
19
|
-
|
|
35
|
+
**Any markdown**, in `:::window`: a table, a screenshot with words under it,
|
|
36
|
+
what has no block of its own. When it holds one image or video, ↗ opens that
|
|
37
|
+
file. `height` (pixels or a CSS length) fixes its height, scrolling inside.
|
|
20
38
|
|
|
21
|
-
|
|
22
|
-
:::window[
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
39
|
+
```markdown
|
|
40
|
+
:::window[What each one takes]
|
|
41
|
+
| block | what |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| `::image` | one image |
|
|
26
44
|
:::
|
|
27
|
-
|
|
45
|
+
```
|
|
28
46
|
|
|
29
|
-
|
|
47
|
+
`compose=window` is this plugin's `compose`: any plugin can compose itself
|
|
48
|
+
around blocks the same way, and a block names several in order:
|
|
49
|
+
`compose=lightbox,window`.
|
package/plugins/window/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Windows (src/pages/window.ts): a header with a label, a button that fills the browser window, and
|
|
2
2
|
// one that opens what it shows on its own. `:::window[label] … :::` puts any markdown in one (a
|
|
3
|
-
//
|
|
4
|
-
// are one image or video
|
|
3
|
+
// table, a screenshot with text); any other block is put in one with `compose=window` (this plugin's
|
|
4
|
+
// compose). `::image[label]{src}` and `::video[label]{src}` are one image or video: alone, or in a
|
|
5
|
+
// window with `compose=window`.
|
|
5
6
|
import fs from 'node:fs'
|
|
6
7
|
import { definePlugin, html, raw, windowFrame, type DirectiveContext, type Plugin } from '@bigmistqke/whiteboard'
|
|
7
8
|
|
|
@@ -34,7 +35,7 @@ const height = (value: string | undefined) =>
|
|
|
34
35
|
/** http(s), protocol-relative, or a path on this server; never `javascript:` or `data:`. */
|
|
35
36
|
const safeSrc = (src: string) => /^(https?:)?\/\//i.test(src) || !/^[a-z][a-z0-9+.-]*:/i.test(src)
|
|
36
37
|
|
|
37
|
-
/** ::image[label]{src} and ::video[label]{src loop autoplay muted poster}: one file
|
|
38
|
+
/** ::image[label]{src} and ::video[label]{src loop autoplay muted poster}: one file (in a window with `compose=window`). */
|
|
38
39
|
const media = (kind: 'image' | 'video') => (ctx: DirectiveContext) => {
|
|
39
40
|
const src = (ctx.attrs.src ?? '').trim()
|
|
40
41
|
if (!src)
|
|
@@ -55,14 +56,13 @@ ${kind}: needs a src, like ::${kind}[a label]{src="${kind === 'image' ? 'shot.pn
|
|
|
55
56
|
preload="metadata"
|
|
56
57
|
${poster}${alt ? html` aria-label="${alt}"` : ''}
|
|
57
58
|
></video>`
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})
|
|
59
|
+
return body
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** What an image or video shows on its own, for the ↗ of a window around it: its file. */
|
|
63
|
+
const mediaOpen = (ctx: DirectiveContext) => {
|
|
64
|
+
const src = (ctx.attrs.src ?? '').trim()
|
|
65
|
+
return src && safeSrc(src) ? src : null
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export async function render(ctx: DirectiveContext) {
|
|
@@ -70,7 +70,6 @@ export async function render(ctx: DirectiveContext) {
|
|
|
70
70
|
label: ctx.label,
|
|
71
71
|
open: openOf(ctx.children as Node[]),
|
|
72
72
|
wide: 'wide' in ctx.attrs,
|
|
73
|
-
bare: 'bare' in ctx.attrs,
|
|
74
73
|
height: height(ctx.attrs.height),
|
|
75
74
|
body: await ctx.toHtml(ctx.children),
|
|
76
75
|
})
|
|
@@ -79,7 +78,15 @@ export async function render(ctx: DirectiveContext) {
|
|
|
79
78
|
export default function windows(): Plugin {
|
|
80
79
|
return definePlugin({
|
|
81
80
|
name: 'window',
|
|
82
|
-
|
|
81
|
+
// any block that says `compose=window` goes in one: its `title` or label the window's title,
|
|
82
|
+
// its ↗ what the block shows on its own
|
|
83
|
+
compose: ({ children, label, open, attrs }) =>
|
|
84
|
+
windowFrame({ label: attrs.title ? html`${attrs.title}` : label, open, wide: 'wide' in attrs, body: children }),
|
|
85
|
+
blocks: {
|
|
86
|
+
window: { html: render },
|
|
87
|
+
image: { html: media('image'), open: mediaOpen },
|
|
88
|
+
video: { html: media('video'), open: mediaOpen },
|
|
89
|
+
},
|
|
83
90
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
84
91
|
})
|
|
85
92
|
}
|
|
@@ -6,8 +6,9 @@ description: Show the user a live HTML page written in markdown, and get answers
|
|
|
6
6
|
# whiteboard
|
|
7
7
|
|
|
8
8
|
Pages are markdown files. In a repository set up for whiteboard they live in
|
|
9
|
-
`.whiteboard/pages/` and are served by the project's
|
|
10
|
-
`whiteboard show` prints
|
|
9
|
+
`.whiteboard/pages/` and are served by the project's server, at the address
|
|
10
|
+
`whiteboard show` prints: the project's own, or one server the user runs for
|
|
11
|
+
many projects (their worktrees and job folders), under the project's path. The user keeps them open in a browser; every save
|
|
11
12
|
of the file updates the open page in place, and the blocks that changed are
|
|
12
13
|
marked until the user has seen them. Forms on a page write the user's answers
|
|
13
14
|
to an ndjson log you can wait on.
|
|
@@ -29,9 +30,13 @@ PATH, the project has it installed locally: run them as `npx whiteboard …`.
|
|
|
29
30
|
agents may be writing pages in the same project, so never write a page you
|
|
30
31
|
did not get from `whiteboard new`, and never pick a page name yourself.
|
|
31
32
|
3. Write the page into that file.
|
|
32
|
-
4. Run `whiteboard show <file>`: it starts the server if needed and
|
|
33
|
-
URL. Give the user the URL the first time; after that, just
|
|
34
|
-
the file — the open page follows.
|
|
33
|
+
4. Run `whiteboard show <file>`: it starts the project's server if needed and
|
|
34
|
+
prints the URL. Give the user the URL the first time; after that, just
|
|
35
|
+
keep editing the file — the open page follows. When the project is served
|
|
36
|
+
by the user's shared server and that isn't running, `show` says so and
|
|
37
|
+
starts nothing: tell the user, don't try to start it yourself (it is
|
|
38
|
+
started outside your sandbox). A `wait` meanwhile still works: it waits
|
|
39
|
+
for the server, and answers in the log reach it either way.
|
|
35
40
|
5. A page that was only for the moment (one question, a check, a demo):
|
|
36
41
|
once it has done its job and you've acted on its answers, close it with
|
|
37
42
|
`whiteboard close <file>`. That removes the page and its events (answers,
|
|
@@ -235,11 +240,14 @@ page (`--page plan` also works, and includes the pages below `plan/`).
|
|
|
235
240
|
every answer on the page once, also those given while no watch ran. Use it
|
|
236
241
|
only with something that reports each printed line as it comes (a
|
|
237
242
|
monitor), and restart it when that expires.
|
|
238
|
-
- Without `--page`, `wait` and `watch` are the
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
+
- Without `--page`, `wait` and `watch` are the fallback: they hand out only
|
|
244
|
+
what no other wait or watch would take, on any page (also answers left
|
|
245
|
+
from sessions that ended). In a project of the user's shared server it
|
|
246
|
+
covers every project served with it (all their worktrees and job folders),
|
|
247
|
+
and each answer says where it is from: `project` (its folder) and `url`;
|
|
248
|
+
act on it in that folder. One runs at a time (per project, or per shared
|
|
249
|
+
group); a second exits 1. Use it only when asked to look after the whole
|
|
250
|
+
board; for your own pages, always pass `--page`.
|
|
243
251
|
- `whiteboard events --page <file> [--type <name>] [--last 1]` lists what was
|
|
244
252
|
submitted so far, for when you need the history rather than the next
|
|
245
253
|
answer. With `--follow` it then prints each new event as it comes, without
|
package/src/auth.ts
CHANGED
|
@@ -32,7 +32,8 @@ export function projectToken(wb: string): string {
|
|
|
32
32
|
return token
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
/** `base`: the path the project is served under (see ServerOptions), which its cookie is kept to. */
|
|
36
|
+
export function createAuth(wb: string, base = '') {
|
|
36
37
|
const token = projectToken(wb)
|
|
37
38
|
const same = (a: unknown, b: string): boolean =>
|
|
38
39
|
typeof a === 'string' && a.length === b.length && crypto.timingSafeEqual(Buffer.from(a), Buffer.from(b))
|
|
@@ -44,8 +45,9 @@ export function createAuth(wb: string) {
|
|
|
44
45
|
.filter(([k]) => k),
|
|
45
46
|
)
|
|
46
47
|
|
|
47
|
-
/** Has this request the token, from this origin? */
|
|
48
|
-
function authorized(req: IncomingMessage): boolean {
|
|
48
|
+
/** Has this request the token, from this origin? No request (a page being built) has none. */
|
|
49
|
+
function authorized(req: IncomingMessage | null): boolean {
|
|
50
|
+
if (!req) return false
|
|
49
51
|
const jar = cookies(req)
|
|
50
52
|
const has = same(jar[COOKIE], token) || same(req.headers['x-whiteboard-token'], token)
|
|
51
53
|
if (!has) return false
|
|
@@ -73,8 +75,9 @@ export function createAuth(wb: string) {
|
|
|
73
75
|
}
|
|
74
76
|
const to = typeof q.to === 'string' && q.to.startsWith('/') && !q.to.startsWith('//') ? q.to : '/'
|
|
75
77
|
res.writeHead(302, {
|
|
76
|
-
'
|
|
77
|
-
|
|
78
|
+
// under a shared server, each project's token is sent only to its own path
|
|
79
|
+
'set-cookie': `${COOKIE}=${token}; Path=${base || '/'}; HttpOnly; SameSite=Lax; Max-Age=31536000`,
|
|
80
|
+
location: base + to,
|
|
78
81
|
})
|
|
79
82
|
res.end()
|
|
80
83
|
return true
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The path the page's project is served under: '' on a server of its own, `/rg/develop` under a
|
|
2
|
+
// shared server (see Entries in DESIGN.md). The server says it in the page's handoff. Every request
|
|
3
|
+
// the page makes, and every link it writes, starts with it; what the browser keeps (drafts, what
|
|
4
|
+
// was seen) is kept per project with it, since the projects of a shared server share one origin.
|
|
5
|
+
const handoff = (() => {
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(document.getElementById('wb-page')?.textContent ?? '{}') as { base?: string }
|
|
8
|
+
} catch {
|
|
9
|
+
return {}
|
|
10
|
+
}
|
|
11
|
+
})()
|
|
12
|
+
|
|
13
|
+
export const base: string = handoff.base ?? ''
|
|
14
|
+
|
|
15
|
+
/** A path of the project's server (`/api/events`) as this page requests it. */
|
|
16
|
+
export const url = (path: string): string => base + path
|
|
17
|
+
|
|
18
|
+
/** A localStorage key, kept apart from other projects' on the same origin. */
|
|
19
|
+
export const storageKey = (key: string): string => (base ? `${base}|${key}` : key)
|
package/src/client/forms.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
import type { Api, FormState, FormStatus } from '../define'
|
|
22
22
|
import { STATES, isQuestionName, questionState } from '../status.ts'
|
|
23
23
|
import { reactive } from './reactive'
|
|
24
|
+
import { storageKey } from './base.ts'
|
|
24
25
|
|
|
25
26
|
type Data = Record<string, unknown>
|
|
26
27
|
|
|
@@ -107,7 +108,7 @@ function onOtherInput(e: Event) {
|
|
|
107
108
|
|
|
108
109
|
// ---- drafts ------------------------------------------------------------------------------------
|
|
109
110
|
|
|
110
|
-
const draftKey = (form: HTMLFormElement) => `wb-draft:${page}:${form.getAttribute('name')}`
|
|
111
|
+
const draftKey = (form: HTMLFormElement) => storageKey(`wb-draft:${page}:${form.getAttribute('name')}`)
|
|
111
112
|
|
|
112
113
|
function saveDraft(e: Event) {
|
|
113
114
|
const form = (e.target as Element | null)?.closest?.('form')
|
package/src/client/markdown.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// page (code fences highlighted, `#12` linked), without raw HTML or directives (api.markdown). The
|
|
3
3
|
// texts asked for at once go in one request; each text is rendered once, then cached. A
|
|
4
4
|
// stylesheet a message needs (the code block's) is linked once it is first used.
|
|
5
|
+
import { url } from './base.ts'
|
|
5
6
|
|
|
6
7
|
const cache = new Map<string, Promise<string>>()
|
|
7
8
|
let queue: { text: string; resolve: (html: string) => void; reject: (err: unknown) => void }[] = []
|
|
@@ -10,7 +11,7 @@ async function flush() {
|
|
|
10
11
|
const batch = queue
|
|
11
12
|
queue = []
|
|
12
13
|
try {
|
|
13
|
-
const res = await fetch('/api/markdown', {
|
|
14
|
+
const res = await fetch(url('/api/markdown'), {
|
|
14
15
|
method: 'POST',
|
|
15
16
|
headers: { 'content-type': 'application/json' },
|
|
16
17
|
body: JSON.stringify({ texts: batch.map(b => b.text) }),
|
package/src/client/page/base.css
CHANGED
|
@@ -565,6 +565,23 @@ details[open] > :last-child {
|
|
|
565
565
|
text-overflow: ellipsis;
|
|
566
566
|
white-space: nowrap;
|
|
567
567
|
}
|
|
568
|
+
/* under a shared server, the other projects' pages, under each project's name */
|
|
569
|
+
.wb-elsewhere-group {
|
|
570
|
+
padding: var(--space-sm) var(--space-lg) var(--space-xs);
|
|
571
|
+
overflow: hidden;
|
|
572
|
+
text-overflow: ellipsis;
|
|
573
|
+
white-space: nowrap;
|
|
574
|
+
color: var(--muted);
|
|
575
|
+
font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
|
|
576
|
+
}
|
|
577
|
+
.wb-elsewhere-group:not(:first-child) {
|
|
578
|
+
margin-top: var(--space-xs);
|
|
579
|
+
border-top: var(--hairline) solid var(--border);
|
|
580
|
+
}
|
|
581
|
+
.wb-elsewhere-list {
|
|
582
|
+
max-height: min(70vh, 480px);
|
|
583
|
+
overflow-y: auto;
|
|
584
|
+
}
|
|
568
585
|
.wb-nav .wb-elsewhere-list a:hover,
|
|
569
586
|
.wb-nav .wb-elsewhere-list a:focus-visible {
|
|
570
587
|
background: color-mix(in srgb, var(--accent) var(--tint-soft), transparent);
|
|
@@ -908,6 +925,49 @@ form[data-wb-just-sent] .wb-folded-change {
|
|
|
908
925
|
font-size: 1.1rem;
|
|
909
926
|
margin: 0;
|
|
910
927
|
}
|
|
928
|
+
/* the shared server's overview (/): each project's pages under its name, as quiet as the
|
|
929
|
+
documents' heading above, and the projects without pages folded at the end */
|
|
930
|
+
.wb-project {
|
|
931
|
+
margin-top: calc(var(--rhythm) * 2.5);
|
|
932
|
+
}
|
|
933
|
+
.wb-project h2 {
|
|
934
|
+
font-size: 1.25rem;
|
|
935
|
+
margin: 0;
|
|
936
|
+
}
|
|
937
|
+
.wb-project > .wb-meta {
|
|
938
|
+
margin: var(--space-xs) 0 0;
|
|
939
|
+
}
|
|
940
|
+
.wb-folded-documents {
|
|
941
|
+
margin-top: var(--rhythm);
|
|
942
|
+
}
|
|
943
|
+
.wb-folded-documents > summary {
|
|
944
|
+
cursor: pointer;
|
|
945
|
+
font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
|
|
946
|
+
color: var(--muted);
|
|
947
|
+
}
|
|
948
|
+
.wb-folded-documents .wb-folder {
|
|
949
|
+
margin: var(--space-xs) 0 0 var(--space-xl);
|
|
950
|
+
}
|
|
951
|
+
.wb-folded-documents .wb-folder > summary {
|
|
952
|
+
cursor: pointer;
|
|
953
|
+
font: var(--ui-small)/var(--ui-line-height) var(--mono);
|
|
954
|
+
color: var(--muted);
|
|
955
|
+
}
|
|
956
|
+
.wb-folded-documents .wb-index li {
|
|
957
|
+
padding: var(--space-md) 0;
|
|
958
|
+
}
|
|
959
|
+
.wb-empty-projects {
|
|
960
|
+
margin-top: calc(var(--rhythm) * 2.5);
|
|
961
|
+
color: var(--muted);
|
|
962
|
+
font: var(--ui-small)/var(--ui-line-height) var(--sans);
|
|
963
|
+
}
|
|
964
|
+
.wb-empty-projects summary {
|
|
965
|
+
cursor: pointer;
|
|
966
|
+
}
|
|
967
|
+
.wb-empty-projects ul {
|
|
968
|
+
margin: var(--space-sm) 0 0;
|
|
969
|
+
padding-left: var(--space-xl);
|
|
970
|
+
}
|
|
911
971
|
/* a list's heading with its sort control at the right (sort.ts) */
|
|
912
972
|
.wb-list-head {
|
|
913
973
|
display: flex;
|
|
@@ -1073,7 +1133,7 @@ main:has(+ .wb-orphans:not([hidden])) {
|
|
|
1073
1133
|
.wb-window-body > :last-child {
|
|
1074
1134
|
margin-bottom: 0;
|
|
1075
1135
|
}
|
|
1076
|
-
.wb-window-body
|
|
1136
|
+
.wb-window-body {
|
|
1077
1137
|
padding: var(--space-xl) var(--space-xl);
|
|
1078
1138
|
overflow: auto;
|
|
1079
1139
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { Api, PageHandle, PageStatus } from '../../define.ts'
|
|
6
6
|
import { INBOX_ICON, awaitingLabel } from '../../icons.ts'
|
|
7
7
|
import { awaiting } from '../../status.ts'
|
|
8
|
+
import { base, url } from '../base.ts'
|
|
8
9
|
|
|
9
10
|
/** A link to a page that scrolls it to its first waiting question. */
|
|
10
11
|
export const WAITING_HASH = '#wb-waiting'
|
|
@@ -27,32 +28,85 @@ function open(yes: boolean) {
|
|
|
27
28
|
|
|
28
29
|
let current = ''
|
|
29
30
|
|
|
31
|
+
/** A page with something waiting, in a group of the menu (its project, under a shared server). */
|
|
32
|
+
interface Waiting {
|
|
33
|
+
href: string
|
|
34
|
+
title: string
|
|
35
|
+
n: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** This project's pages with something waiting, but this one. */
|
|
39
|
+
async function here(): Promise<Waiting[]> {
|
|
40
|
+
const pages = (await (await fetch(url('/api/status'), { cache: 'no-store' })).json()) as PageStatus[]
|
|
41
|
+
return pages
|
|
42
|
+
.filter(p => p.page !== current)
|
|
43
|
+
.map(p => ({
|
|
44
|
+
href: `${base}/${p.page.split('/').map(encodeURIComponent).join('/')}${WAITING_HASH}`,
|
|
45
|
+
title: p.title,
|
|
46
|
+
n: awaiting(p),
|
|
47
|
+
}))
|
|
48
|
+
.filter(w => w.n > 0)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Under a shared server (see Entries in DESIGN.md): the other projects of this one's entry, by
|
|
53
|
+
* project, as the server's index has them; empty on a server of its own, or when it can't say.
|
|
54
|
+
*/
|
|
55
|
+
async function others(): Promise<{ label: string; pages: Waiting[] }[]> {
|
|
56
|
+
if (!base) return []
|
|
57
|
+
const entry = base.split('/')[1]
|
|
58
|
+
try {
|
|
59
|
+
const res = await fetch(`/api/index?entry=${encodeURIComponent(entry ?? '')}`, { cache: 'no-store' })
|
|
60
|
+
if (!res.ok) return []
|
|
61
|
+
const projects = (await res.json()) as {
|
|
62
|
+
label: string
|
|
63
|
+
base: string
|
|
64
|
+
pages: { title: string; url: string; open: string[]; unread: number }[]
|
|
65
|
+
}[]
|
|
66
|
+
return projects
|
|
67
|
+
.filter(p => p.base !== base)
|
|
68
|
+
.map(p => ({
|
|
69
|
+
label: p.label,
|
|
70
|
+
pages: p.pages
|
|
71
|
+
.map(x => ({ href: `${x.url}${WAITING_HASH}`, title: x.title, n: x.open.length + x.unread }))
|
|
72
|
+
.filter(w => w.n > 0),
|
|
73
|
+
}))
|
|
74
|
+
.filter(g => g.pages.length)
|
|
75
|
+
} catch {
|
|
76
|
+
return []
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
30
80
|
async function load() {
|
|
31
|
-
let
|
|
81
|
+
let mine: Waiting[]
|
|
82
|
+
let rest: { label: string; pages: Waiting[] }[]
|
|
32
83
|
try {
|
|
33
|
-
|
|
84
|
+
;[mine, rest] = await Promise.all([here(), others()])
|
|
34
85
|
} catch {
|
|
35
86
|
return
|
|
36
87
|
}
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
.map(p => ({ p, n: awaiting(p) }))
|
|
40
|
-
.filter(({ n }) => n > 0)
|
|
41
|
-
const total = waiting.reduce((sum, { n }) => sum + n, 0)
|
|
88
|
+
const all = [...mine, ...rest.flatMap(g => g.pages)]
|
|
89
|
+
const total = all.reduce((sum, w) => sum + w.n, 0)
|
|
42
90
|
box.hidden = total === 0
|
|
43
91
|
if (!total) open(false)
|
|
44
92
|
count.textContent = String(total)
|
|
45
|
-
toggle.title = awaitingLabel(total, ` on ${
|
|
93
|
+
toggle.title = awaitingLabel(total, ` on ${all.length === 1 ? 'another page' : `${all.length} other pages`}`)
|
|
46
94
|
toggle.setAttribute('aria-label', toggle.title)
|
|
95
|
+
const item = (w: Waiting) => {
|
|
96
|
+
const li = document.createElement('li')
|
|
97
|
+
const a = document.createElement('a')
|
|
98
|
+
a.href = w.href
|
|
99
|
+
a.textContent = `${w.title} (${w.n})`
|
|
100
|
+
li.append(a)
|
|
101
|
+
return li
|
|
102
|
+
}
|
|
103
|
+
const heading = (text: string) =>
|
|
104
|
+
Object.assign(document.createElement('li'), { className: 'wb-elsewhere-group', textContent: text, title: text })
|
|
105
|
+
// this project's own first; the others by project, named only when there are others
|
|
47
106
|
list.replaceChildren(
|
|
48
|
-
...
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
a.href = `/${p.page.split('/').map(encodeURIComponent).join('/')}${WAITING_HASH}`
|
|
52
|
-
a.textContent = `${p.title} (${n})`
|
|
53
|
-
li.append(a)
|
|
54
|
-
return li
|
|
55
|
-
}),
|
|
107
|
+
...(rest.length && mine.length ? [heading('here')] : []),
|
|
108
|
+
...mine.map(item),
|
|
109
|
+
...rest.flatMap(g => [heading(g.label), ...g.pages.map(item)]),
|
|
56
110
|
)
|
|
57
111
|
}
|
|
58
112
|
|
|
@@ -84,4 +138,6 @@ export function trackElsewhere(root: HTMLElement, handle: PageHandle, core: Api)
|
|
|
84
138
|
core.listeners.on(reload)
|
|
85
139
|
handle.onChange(reload)
|
|
86
140
|
load()
|
|
141
|
+
// other projects' pages change without this page hearing of it: look again now and then
|
|
142
|
+
if (base) setInterval(reload, 5000)
|
|
87
143
|
}
|
package/src/client/page/fresh.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { html } from '../../html.ts'
|
|
7
7
|
import type { Api, Toast } from '../../define.ts'
|
|
8
8
|
import { viewBottom } from './view'
|
|
9
|
+
import { storageKey } from '../base.ts'
|
|
9
10
|
|
|
10
11
|
const DWELL_MS = 600
|
|
11
12
|
const FADE_MS = 2500
|
|
@@ -236,7 +237,7 @@ export function trackInitial(main: HTMLElement, page: string, api: Api) {
|
|
|
236
237
|
upToast.hide()
|
|
237
238
|
downToast.hide()
|
|
238
239
|
mainEl = main
|
|
239
|
-
storeKey = `wb-seen:${page}`
|
|
240
|
+
storeKey = storageKey(`wb-seen:${page}`)
|
|
240
241
|
const blocks = [...main.children]
|
|
241
242
|
const sigs = blocks.map(signature)
|
|
242
243
|
blocks.forEach((el, i) => sigOf.set(el, sigs[i]))
|
package/src/client/page/main.ts
CHANGED
|
@@ -41,7 +41,7 @@ async function mountOne(el: HTMLElement) {
|
|
|
41
41
|
el.dataset.wbMounted = ''
|
|
42
42
|
if (!island) return
|
|
43
43
|
try {
|
|
44
|
-
const mod = await import(island.client)
|
|
44
|
+
const mod = await import(new URL(island.client, document.baseURI).href)
|
|
45
45
|
if (!el.isConnected) return
|
|
46
46
|
const mount: Mount = mod.default
|
|
47
47
|
if (typeof mount !== 'function')
|
|
@@ -314,16 +314,25 @@ function keepPlace(place: ReturnType<typeof placeOf>, sigs: string[]) {
|
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
/** The new render of the page, patched in. */
|
|
317
|
+
// the page is going (its own reload below, or the reader went elsewhere): a render still in flight is
|
|
318
|
+
// cut off then, and its failure is not the page's
|
|
319
|
+
let leaving = false
|
|
320
|
+
addEventListener('pagehide', () => {
|
|
321
|
+
leaving = true
|
|
322
|
+
})
|
|
323
|
+
|
|
317
324
|
async function refresh() {
|
|
318
325
|
let next: Awaited<ReturnType<PageHandle['render']>>
|
|
319
326
|
try {
|
|
320
327
|
next = await currentPage.render()
|
|
321
328
|
} catch (err) {
|
|
329
|
+
if (leaving) return
|
|
322
330
|
// the page is gone (closed, deleted): load what its address shows now, the "Not found" page,
|
|
323
331
|
// which turns into the page again if it is written back. Already that page (it has no file, so
|
|
324
332
|
// no time it was edited): still not there, nothing to do
|
|
325
333
|
if (/: 404$/.test((err as Error).message)) {
|
|
326
334
|
if ((currentPage.data() as Data | null)?.mtime == null) return
|
|
335
|
+
leaving = true
|
|
327
336
|
return location.reload()
|
|
328
337
|
}
|
|
329
338
|
throw err
|
|
@@ -402,10 +411,13 @@ const mount: PluginMount = async (root: HTMLElement, handle: PageHandle, coreApi
|
|
|
402
411
|
if (isDir) core.listeners.on(() => refresh())
|
|
403
412
|
|
|
404
413
|
blockSigs = [...main.children].map(signature)
|
|
405
|
-
|
|
406
|
-
if (
|
|
407
|
-
|
|
408
|
-
|
|
414
|
+
// what is new, what waits, what is elsewhere, whether it's live: the server's, not a built page's
|
|
415
|
+
if (handle.live) {
|
|
416
|
+
if (!isDir) trackInitial(main, page, core)
|
|
417
|
+
if (!isDir) trackWaiting(main, core)
|
|
418
|
+
trackElsewhere(root, handle, core)
|
|
419
|
+
trackLive(root, handle, core)
|
|
420
|
+
}
|
|
409
421
|
if (isDir) {
|
|
410
422
|
trackSorts()
|
|
411
423
|
core.onRendered(applySorts)
|
|
@@ -413,7 +425,7 @@ const mount: PluginMount = async (root: HTMLElement, handle: PageHandle, coreApi
|
|
|
413
425
|
trackSticky(main, fn => core.onRendered(fn))
|
|
414
426
|
trackHold()
|
|
415
427
|
trackWindows(core)
|
|
416
|
-
if (!isDir) trackOrphanThreads(main, core)
|
|
428
|
+
if (!isDir && handle.live) trackOrphanThreads(main, core)
|
|
417
429
|
await mountIslands()
|
|
418
430
|
tickTimes()
|
|
419
431
|
}
|
package/src/client/page/sort.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
// by what each `li` carries (`data-order`, `data-updated`, `data-title`: the overview's documents).
|
|
3
3
|
// The choice is kept per list in this browser, and put back after a live update, which writes the
|
|
4
4
|
// list again in the server's order.
|
|
5
|
-
|
|
5
|
+
import { storageKey } from '../base.ts'
|
|
6
|
+
const KEY = (name: string) => storageKey(`wb-sort:${name}`)
|
|
6
7
|
|
|
7
8
|
function sortList(select: HTMLSelectElement) {
|
|
8
9
|
const list = select.closest('section')?.querySelector('ul')
|