@bigmistqke/whiteboard 0.1.0 → 0.2.1
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 +31 -12
- package/bin/whiteboard.ts +74 -17
- package/dist/bin/whiteboard.js +93 -22
- package/dist/client/runtime.js +164 -11
- package/dist/plugins/chat/README.md +2 -1
- package/dist/plugins/chat/client.js +2 -2
- package/dist/plugins/chat/index.js +1 -0
- package/dist/plugins/chat/style.css +7 -0
- package/dist/plugins/code/diff.js +1 -0
- package/dist/plugins/comments/client.js +6 -6
- package/dist/plugins/comments/index.js +4 -1
- package/dist/plugins/comments/style.css +8 -0
- package/dist/plugins/forge/README.md +12 -0
- package/dist/plugins/forge/index.js +83 -0
- package/dist/plugins/gallery/client.js +1 -1
- package/dist/plugins/iframe/README.md +18 -0
- package/dist/plugins/iframe/client.js +1 -0
- package/dist/plugins/iframe/index.js +40 -0
- package/dist/plugins/iframe/style.css +29 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/mermaid/index.js +1 -0
- package/dist/solid/index.js +2 -1
- package/dist/src/client/page/base.css +33 -12
- package/dist/src/client/page/main.js +250 -26
- package/dist/src/events.js +24 -3
- package/dist/src/icons.js +6 -0
- package/dist/src/loader.js +12 -6
- package/dist/src/pages/blocks.js +1 -0
- package/dist/src/pages/index.js +3 -2
- package/dist/src/pages/markdown.js +107 -4
- package/dist/src/pages/render.js +63 -9
- package/dist/src/server.js +37 -12
- package/dist/src/status.js +38 -10
- package/package.json +1 -1
- package/plugins/chat/README.md +2 -1
- package/plugins/chat/client.tsx +15 -3
- package/plugins/chat/index.ts +1 -1
- package/plugins/chat/style.css +7 -0
- package/plugins/code/diff.ts +7 -1
- package/plugins/comments/client.ts +50 -6
- package/plugins/comments/index.ts +4 -2
- package/plugins/comments/style.css +8 -0
- package/plugins/forge/README.md +12 -0
- package/plugins/forge/index.ts +71 -0
- package/plugins/iframe/README.md +18 -0
- package/plugins/iframe/client.ts +46 -0
- package/plugins/iframe/index.ts +54 -0
- package/plugins/iframe/style.css +29 -0
- package/plugins/index.ts +3 -1
- package/plugins/mermaid/index.ts +1 -0
- package/skills/whiteboard/SKILL.md +17 -7
- package/solid/index.tsx +3 -0
- package/src/client/forms.ts +5 -6
- package/src/client/markdown.ts +36 -0
- package/src/client/page/base.css +33 -12
- package/src/client/page/elsewhere.ts +70 -0
- package/src/client/page/live.ts +30 -0
- package/src/client/page/main.ts +31 -6
- package/src/client/page/sort.ts +38 -0
- package/src/client/page/waiting.ts +102 -29
- package/src/client/read.ts +73 -0
- package/src/client/runtime.ts +13 -0
- package/src/client/toast.ts +25 -0
- package/src/define.ts +79 -13
- package/src/events.ts +27 -3
- package/src/icons.ts +8 -0
- package/src/loader.ts +7 -4
- package/src/pages/blocks.ts +3 -0
- package/src/pages/index.ts +8 -2
- package/src/pages/markdown.ts +92 -4
- package/src/pages/render.ts +49 -12
- package/src/server.ts +35 -12
- package/src/status.ts +64 -20
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Links to a GitHub or GitLab repository's issues and pull/merge requests, as written in a page's
|
|
2
|
+
// text: `#12` is issue 12, `!34` pull or merge request 34, and `owner/repo#12` or
|
|
3
|
+
// `group/project!34` the same in another repository on the same host. Which repository is read
|
|
4
|
+
// from the project's `origin` remote (https or ssh), so self-hosted GitLab works too; without one,
|
|
5
|
+
// or one that is neither GitHub nor GitLab, it links nothing. `forge({ repo, host, kind })` in the
|
|
6
|
+
// config says it instead. Links only: nothing is fetched.
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import { execFileSync } from 'node:child_process'
|
|
9
|
+
import { definePlugin, type Plugin, type TextLink } from '@bigmistqke/whiteboard'
|
|
10
|
+
|
|
11
|
+
export type ForgeKind = 'github' | 'gitlab'
|
|
12
|
+
export interface Forge { kind: ForgeKind; host: string; repo: string }
|
|
13
|
+
|
|
14
|
+
/** A git remote's URL → its host and repository path: https, ssh (`git@host:path`), ssh://. */
|
|
15
|
+
export function parseRemote(url: string): { host: string; repo: string } | null {
|
|
16
|
+
const u = url.trim()
|
|
17
|
+
const scp = /^[\w.-]+@([^:/]+):(.+?)(?:\.git)?\/?$/.exec(u)
|
|
18
|
+
if (scp) return { host: scp[1], repo: scp[2] }
|
|
19
|
+
const full = /^(?:https?|ssh|git):\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/(.+?)(?:\.git)?\/?$/.exec(u)
|
|
20
|
+
if (full) return { host: full[1], repo: full[2] }
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** GitHub or GitLab, by the host's name; null for any other. */
|
|
25
|
+
export const kindOf = (host: string): ForgeKind | null => /(^|\.)github\./.test(host) ? 'github' : /(^|\.)gitlab\./.test(host) || /^gitlab/.test(host) ? 'gitlab' : null
|
|
26
|
+
|
|
27
|
+
/** The links for one forge: issues (`#n`) and pull or merge requests (`!n`), here or in `owner/repo`. */
|
|
28
|
+
export function forgeLinks({ kind, host, repo }: Forge): TextLink[] {
|
|
29
|
+
const base = (path: string | undefined) => `https://${host}/${path ?? repo}`
|
|
30
|
+
// after the start, a space or punctuation, so `C#1`, `a/b.md#12` and `x!3` stay text; an optional
|
|
31
|
+
// repository in front (`owner/repo#12`); then the number, ending at a word's end
|
|
32
|
+
const ref = (sign: string) => new RegExp(`(?<![\\w/.#!-])(?:([\\w.-]+(?:/[\\w.-]+)+))?${sign}(\\d+)(?![\\w-])`, 'g')
|
|
33
|
+
const issue = kind === 'github' ? 'issues' : '-/issues'
|
|
34
|
+
const change = kind === 'github' ? 'pull' : '-/merge_requests'
|
|
35
|
+
const what = kind === 'github' ? 'pull request' : 'merge request'
|
|
36
|
+
return [
|
|
37
|
+
{ pattern: ref('#'), href: m => `${base(m[1])}/${issue}/${m[2]}`, title: m => `issue ${m[1] ?? repo}#${m[2]}` },
|
|
38
|
+
{ pattern: ref('!'), href: m => `${base(m[1])}/${change}/${m[2]}`, title: m => `${what} ${m[1] ?? repo}!${m[2]}` },
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The project's forge, from its `origin` remote; null without one it knows. */
|
|
43
|
+
export function detect(dir: string): Forge | null {
|
|
44
|
+
let url: string
|
|
45
|
+
try { url = execFileSync('git', ['remote', 'get-url', 'origin'], { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }) } catch { return null }
|
|
46
|
+
const remote = parseRemote(url)
|
|
47
|
+
const kind = remote && kindOf(remote.host)
|
|
48
|
+
return remote && kind ? { kind, ...remote } : null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ForgeOptions {
|
|
52
|
+
/** the repository's path on its host: `owner/repo`, `group/subgroup/project` */
|
|
53
|
+
repo?: string
|
|
54
|
+
/** github.com, gitlab.com, or a self-hosted GitLab's host */
|
|
55
|
+
host?: string
|
|
56
|
+
kind?: ForgeKind
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default function forge(options: ForgeOptions = {}): Plugin {
|
|
60
|
+
return definePlugin({
|
|
61
|
+
name: 'forge',
|
|
62
|
+
links({ dir }) {
|
|
63
|
+
const found = detect(dir)
|
|
64
|
+
const host = options.host ?? found?.host
|
|
65
|
+
const repo = options.repo ?? found?.repo
|
|
66
|
+
const kind = options.kind ?? (options.host ? kindOf(options.host) : null) ?? found?.kind
|
|
67
|
+
return host && repo && kind ? forgeLinks({ kind, host, repo }) : []
|
|
68
|
+
},
|
|
69
|
+
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
70
|
+
})
|
|
71
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Another page inside this one: a running app (a dev server), a deployed
|
|
2
|
+
site, or an HTML file next to the pages. A header like a browser window's
|
|
3
|
+
shows its label (or, without one, its address), opens it on its own, and fills the window with
|
|
4
|
+
it (the same button, or Esc, puts it back). Drag the frame's bottom edge to
|
|
5
|
+
make it taller.
|
|
6
|
+
|
|
7
|
+
Attributes: `src` (required: an http(s) URL, or a path such as `demo.html`
|
|
8
|
+
for `.whiteboard/pages/demo.html`), `height` (a number of pixels or a CSS
|
|
9
|
+
length, default 480), `wide` (wider than the text column), `bare` (no
|
|
10
|
+
header: the frame alone).
|
|
11
|
+
|
|
12
|
+
```markdown
|
|
13
|
+
::iframe[The app as it runs now]{src="http://localhost:5173" height=600 wide}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
A site that forbids being framed (most large ones do, with
|
|
17
|
+
`X-Frame-Options` or `frame-ancestors`) shows as a blank or refused frame;
|
|
18
|
+
link to it instead.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// An iframe block filling the window, and back: its header's button, or Escape. Which one is
|
|
2
|
+
// maximized is kept across the page's updates, which put back the block as the server wrote it.
|
|
3
|
+
import type { PluginMount } from '../../src/define.ts'
|
|
4
|
+
|
|
5
|
+
const figures = () => [...document.querySelectorAll<HTMLElement>('#wb-main div.wb-iframe')]
|
|
6
|
+
// the maximized block, by its place among the page's iframe blocks and its address
|
|
7
|
+
let maximized: { index: number; src: string } | null = null
|
|
8
|
+
|
|
9
|
+
function apply() {
|
|
10
|
+
const all = figures()
|
|
11
|
+
let found: HTMLElement | null = null
|
|
12
|
+
all.forEach((fig, i) => {
|
|
13
|
+
const on = !!maximized && i === maximized.index && fig.querySelector('iframe')?.getAttribute('src') === maximized.src
|
|
14
|
+
fig.toggleAttribute('data-maximized', on)
|
|
15
|
+
const button = fig.querySelector<HTMLButtonElement>('[data-wb-maximize]')
|
|
16
|
+
if (button) {
|
|
17
|
+
button.title = on ? 'Back into the page (Esc)' : 'Fill the window'
|
|
18
|
+
button.setAttribute('aria-label', button.title)
|
|
19
|
+
button.setAttribute('aria-pressed', String(on))
|
|
20
|
+
}
|
|
21
|
+
if (on) found = fig
|
|
22
|
+
})
|
|
23
|
+
if (maximized && !found) maximized = null
|
|
24
|
+
document.documentElement.toggleAttribute('data-wb-iframe-maximized', !!found)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function toggle(fig: HTMLElement) {
|
|
28
|
+
const index = figures().indexOf(fig)
|
|
29
|
+
const src = fig.querySelector('iframe')?.getAttribute('src') ?? ''
|
|
30
|
+
maximized = maximized && maximized.index === index ? null : { index, src }
|
|
31
|
+
apply()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const mount: PluginMount = (_root, _handle, api) => {
|
|
35
|
+
document.addEventListener('click', e => {
|
|
36
|
+
const button = (e.target as Element).closest?.('[data-wb-maximize]')
|
|
37
|
+
const fig = button?.closest<HTMLElement>('div.wb-iframe')
|
|
38
|
+
if (fig) toggle(fig)
|
|
39
|
+
})
|
|
40
|
+
document.addEventListener('keydown', e => {
|
|
41
|
+
if (e.key === 'Escape' && maximized) { maximized = null; apply() }
|
|
42
|
+
})
|
|
43
|
+
api.onRendered(apply)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default mount
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Another page inside this one: a URL (a dev server, a deployed site) or an HTML file next to the
|
|
2
|
+
// pages (`demo.html` in .whiteboard/pages/ is served as it is). A header shows its label and address,
|
|
3
|
+
// opens it on its own, and fills the window with it; the frame can be made taller by dragging its
|
|
4
|
+
// bottom edge.
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import { packagePath } from '../../src/package.ts'
|
|
7
|
+
import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
8
|
+
import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
9
|
+
|
|
10
|
+
/** http(s), protocol-relative, or a path on this server; never `javascript:` or `data:`. */
|
|
11
|
+
export const safeSrc = (src: string) => /^(https?:)?\/\//i.test(src) || !/^[a-z][a-z0-9+.-]*:/i.test(src)
|
|
12
|
+
|
|
13
|
+
/** A height in px (a bare number) or a CSS length; else the default. */
|
|
14
|
+
export function height(value: string | undefined): string {
|
|
15
|
+
if (value && /^\d+(\.\d+)?$/.test(value)) return `${value}px`
|
|
16
|
+
if (value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value)) return value
|
|
17
|
+
return '480px'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// the header's buttons, as icons
|
|
21
|
+
const svg = (d: string) => raw(`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">${d}</svg>`)
|
|
22
|
+
const OPEN = svg('<path d="M9 2.5h4.5V7M13.5 2.5 7.5 8.5M11.5 9.5v3a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1h3"/>')
|
|
23
|
+
const MAXIMIZE = svg('<path d="M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10"/>')
|
|
24
|
+
const RESTORE = svg('<path d="M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"/>')
|
|
25
|
+
|
|
26
|
+
export async function render(ctx: DirectiveContext) {
|
|
27
|
+
const src = (ctx.attrs.src ?? '').trim()
|
|
28
|
+
if (!src) return html`<pre class="wb-error">iframe: needs a src, like ::iframe{src="http://localhost:5173"}</pre>`
|
|
29
|
+
if (!safeSrc(src)) return html`<pre class="wb-error">iframe: src must be an http(s) URL or a path, not ${src.split(':')[0]}:</pre>`
|
|
30
|
+
const title = ctx.labelText ?? ctx.attrs.title ?? src
|
|
31
|
+
// a header like a browser window's: the label, or the address without one (hovering the label
|
|
32
|
+
// shows the address), opening it on its own, and filling the window with it (client.ts).
|
|
33
|
+
// `bare`: the frame alone.
|
|
34
|
+
const header = !('bare' in ctx.attrs) && html`<div class="wb-iframe-bar">
|
|
35
|
+
<span class="wb-iframe-name" title="${src}">${ctx.label ? html`<span class="wb-iframe-title">${raw(ctx.label)}</span>` : html`<span class="wb-iframe-url">${src}</span>`}</span>
|
|
36
|
+
<a class="wb-iframe-button" href="${src}" target="_blank" rel="noopener" title="Open on its own" aria-label="Open on its own">${OPEN}</a>
|
|
37
|
+
<button type="button" class="wb-iframe-button" data-wb-maximize title="Fill the window" aria-label="Fill the window"><span class="wb-iframe-max">${MAXIMIZE}</span><span class="wb-iframe-restore">${RESTORE}</span></button>
|
|
38
|
+
</div>`
|
|
39
|
+
return html`<div class="wb-iframe${'wide' in ctx.attrs && raw(' wb-wide')}">${header}<div class="wb-iframe-frame" style="height: ${height(ctx.attrs.height)}"><iframe src="${src}" title="${title}" loading="lazy" referrerpolicy="no-referrer"></iframe></div></div>`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default function iframe(): Plugin {
|
|
43
|
+
return definePlugin({
|
|
44
|
+
name: 'iframe',
|
|
45
|
+
blocks: {
|
|
46
|
+
iframe: {
|
|
47
|
+
html: render,
|
|
48
|
+
style: new URL('./style.css', import.meta.url),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
setup: () => ({ client: packagePath('dist/plugins/iframe/client.js') }),
|
|
52
|
+
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
53
|
+
})
|
|
54
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* a page inside the page, framed like a browser window; its bottom edge drags it taller */
|
|
2
|
+
.wb-iframe { margin: 1.6em 0; border: 1px solid var(--border); border-radius: var(--radius, 6px); overflow: hidden; background: var(--bg); }
|
|
3
|
+
.wb-iframe-frame { resize: vertical; overflow: hidden; min-height: 120px; background: #fff; }
|
|
4
|
+
.wb-iframe iframe { display: block; width: 100%; height: 100%; border: 0; }
|
|
5
|
+
|
|
6
|
+
.wb-iframe-bar {
|
|
7
|
+
display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; min-height: 32px; box-sizing: border-box;
|
|
8
|
+
border-bottom: 1px solid var(--border); background: var(--tint, var(--bg)); font: .8rem/1.4 var(--sans); color: var(--muted);
|
|
9
|
+
}
|
|
10
|
+
.wb-iframe-name { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: baseline; overflow: hidden; white-space: nowrap; }
|
|
11
|
+
.wb-iframe-title { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
|
|
12
|
+
.wb-iframe-url { font-family: var(--mono, monospace); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; }
|
|
13
|
+
.wb-iframe-button {
|
|
14
|
+
flex: none; display: inline-grid; place-items: center; width: 26px; height: 24px; padding: 0; border: 0; border-radius: 5px;
|
|
15
|
+
background: none; color: var(--muted); cursor: pointer;
|
|
16
|
+
}
|
|
17
|
+
.wb-iframe-button:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
|
|
18
|
+
.wb-iframe-restore, .wb-iframe[data-maximized] .wb-iframe-max { display: none; }
|
|
19
|
+
.wb-iframe[data-maximized] .wb-iframe-restore { display: contents; }
|
|
20
|
+
.wb-iframe-max { display: contents; }
|
|
21
|
+
|
|
22
|
+
/* filling the window, above the page and its header; the terminal drawer stays below it. The
|
|
23
|
+
margin is !important: the page indents its blocks with a rule more specific than any here */
|
|
24
|
+
.wb-iframe[data-maximized] {
|
|
25
|
+
position: fixed; inset: 0 0 var(--wb-inset-bottom, 0px) 0; z-index: 40; margin: 0 !important; border-radius: 0; border: 0;
|
|
26
|
+
display: flex; flex-direction: column; width: auto; left: 0; transform: none;
|
|
27
|
+
}
|
|
28
|
+
.wb-iframe[data-maximized] .wb-iframe-frame { flex: 1; height: auto !important; resize: none; }
|
|
29
|
+
:root[data-wb-iframe-maximized] { overflow: hidden; }
|
package/plugins/index.ts
CHANGED
|
@@ -8,12 +8,14 @@ import chat from './chat/index.ts'
|
|
|
8
8
|
import code from './code/index.ts'
|
|
9
9
|
import comments from './comments/index.ts'
|
|
10
10
|
import details from './details/index.ts'
|
|
11
|
+
import forge from './forge/index.ts'
|
|
11
12
|
import form from './form/index.ts'
|
|
12
13
|
import gallery from './gallery/index.ts'
|
|
13
14
|
import grid from './grid/index.ts'
|
|
15
|
+
import iframe from './iframe/index.ts'
|
|
14
16
|
import mermaid from './mermaid/index.ts'
|
|
15
17
|
import quiet from './quiet/index.ts'
|
|
16
18
|
|
|
17
19
|
export function builtins(): Plugin[] {
|
|
18
|
-
return [callout(), chat(), code(), comments(), details(), form(), gallery(), grid(), mermaid(), quiet()]
|
|
20
|
+
return [callout(), chat(), code(), comments(), details(), forge(), form(), gallery(), grid(), iframe(), mermaid(), quiet()]
|
|
19
21
|
}
|
package/plugins/mermaid/index.ts
CHANGED
|
@@ -209,6 +209,11 @@ page (`--page plan` also works, and includes the pages below `plan/`).
|
|
|
209
209
|
every answer on the page once, also those given while no watch ran. Use it
|
|
210
210
|
only with something that reports each printed line as it comes (a
|
|
211
211
|
monitor), and restart it when that expires.
|
|
212
|
+
- Without `--page`, `wait` and `watch` are the project's fallback: they hand
|
|
213
|
+
out only what no other wait or watch would take, on any page (also
|
|
214
|
+
answers left from sessions that ended). One runs per project; a second
|
|
215
|
+
exits 1. Use it only when asked to look after the whole board; for your
|
|
216
|
+
own pages, always pass `--page`.
|
|
212
217
|
- `whiteboard events --page <file> [--type <name>] [--last 1]` lists what was
|
|
213
218
|
submitted so far, for when you need the history rather than the next
|
|
214
219
|
answer. With `--follow` it then prints each new event as it comes, without
|
|
@@ -216,17 +221,22 @@ page (`--page plan` also works, and includes the pages below `plan/`).
|
|
|
216
221
|
yourself. Use these only for something `wait` doesn't do, such as picking
|
|
217
222
|
an answer up after you acted on it.
|
|
218
223
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
224
|
+
The page shows the user what waits for them: every question without an
|
|
225
|
+
answer is marked "waiting for you", and so is a message from you they
|
|
226
|
+
haven't read (a reply in a comment thread, a chat message). A button goes
|
|
227
|
+
from one to the next, and the tab title and the header count them. Whether
|
|
228
|
+
your wait runs doesn't change that, so answers given while none runs wait in
|
|
229
|
+
the log for you. So:
|
|
223
230
|
|
|
224
231
|
- An answer counts as picked up once your `wait` or `watch` hands it to you;
|
|
225
232
|
the form then folds into one line quoting it, as decided. Answers no wait
|
|
226
|
-
has handed out show as waiting for you to pick them up.
|
|
233
|
+
has handed out show as waiting for you to pick them up. Waiting on a
|
|
234
|
+
decided form by name (`--type`) asks the user again: it is open again.
|
|
227
235
|
- Keep a `wait` or `watch` running for as long as you want answers, and only
|
|
228
|
-
then. Don't poll `whiteboard events` in a loop instead:
|
|
229
|
-
|
|
236
|
+
then. Don't poll `whiteboard events` in a loop instead: it picks nothing
|
|
237
|
+
up, so the user's answers never show as received, and the hooks and
|
|
238
|
+
`whiteboard status` keep reporting them. When an answer arrives while no
|
|
239
|
+
wait runs, the user is told nobody is listening right now.
|
|
230
240
|
- When you need the user to read something before you go on, put a form with
|
|
231
241
|
just a button in it (`:button[Read it]`) and wait for it. Then
|
|
232
242
|
everything you wait for is a form the page can point to.
|
package/solid/index.tsx
CHANGED
|
@@ -22,6 +22,8 @@ export interface Whiteboard {
|
|
|
22
22
|
append: ClientApi['append']
|
|
23
23
|
/** the theme in effect. Reactive. */
|
|
24
24
|
theme(): Theme
|
|
25
|
+
/** a message's markdown as HTML, rendered by the server (see Api.markdown) */
|
|
26
|
+
markdown: ClientApi['markdown']
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
const WhiteboardContext = createContext<Whiteboard>()
|
|
@@ -46,6 +48,7 @@ export function solid<Props extends object>(Component: Component<Props>): Mount<
|
|
|
46
48
|
last: type => events().findLast(e => e.type === type),
|
|
47
49
|
append: api.append,
|
|
48
50
|
theme,
|
|
51
|
+
markdown: api.markdown,
|
|
49
52
|
}
|
|
50
53
|
return (
|
|
51
54
|
<WhiteboardContext value={value}>
|
package/src/client/forms.ts
CHANGED
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
// re-renders and reloads;
|
|
10
10
|
// - puts the last answer back into the form, and its button in `data-wb-sent`;
|
|
11
11
|
// - marks where the form stands, from the log and the listeners, with one of these attributes:
|
|
12
|
-
// data-wb-
|
|
13
|
-
//
|
|
14
|
-
// data-wb-unheard no answer, and no agent is listening
|
|
12
|
+
// data-wb-open no answer yet, or the agent asks again (a wait asks for it by name after
|
|
13
|
+
// its answer was picked up)
|
|
15
14
|
// data-wb-pending answered, but no agent has picked the answer up yet
|
|
16
15
|
// data-wb-decided an agent picked up its latest answer; data-wb-outcome quotes it in one line
|
|
17
16
|
// and, for a few seconds after a send went through, `data-wb-just-sent`, to confirm it
|
|
@@ -123,7 +122,7 @@ async function onSubmit(e: SubmitEvent) {
|
|
|
123
122
|
|
|
124
123
|
// ---- where each form stands --------------------------------------------------------------------
|
|
125
124
|
|
|
126
|
-
const ATTR: Record<FormState, string> = {
|
|
125
|
+
const ATTR: Record<FormState, string> = { open: 'data-wb-open', pending: 'data-wb-pending', decided: 'data-wb-decided' }
|
|
127
126
|
|
|
128
127
|
/** One line quoting an answer: what was chosen, then what was written. */
|
|
129
128
|
function outcome(data: Data, action: string | null) {
|
|
@@ -144,10 +143,10 @@ const justSent = new WeakMap<HTMLFormElement, ReturnType<typeof setTimeout>>()
|
|
|
144
143
|
|
|
145
144
|
/** Mark every form from the log and the listeners, then tell whoever follows. */
|
|
146
145
|
function mark() {
|
|
147
|
-
const
|
|
146
|
+
const listening = api.listeners()
|
|
148
147
|
current = forms().map(form => {
|
|
149
148
|
const name = form.getAttribute('name')!
|
|
150
|
-
const { state, last } = questionState(name, api.events(),
|
|
149
|
+
const { state, last } = questionState(name, api.events(), listening, api.pickedUp)
|
|
151
150
|
for (const st of STATES) form.toggleAttribute(ATTR[st], st === state)
|
|
152
151
|
if (state === 'decided') form.dataset.wbOutcome = outcome(last!.data, last!.action)
|
|
153
152
|
else delete form.dataset.wbOutcome
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Messages written in markdown (comments, chat messages), as HTML: rendered on the server like a
|
|
2
|
+
// page (code fences highlighted, `#12` linked), without raw HTML or directives (api.markdown). The
|
|
3
|
+
// texts asked for at once go in one request; each text is rendered once, then cached. A
|
|
4
|
+
// stylesheet a message needs (the code block's) is linked once it is first used.
|
|
5
|
+
|
|
6
|
+
const cache = new Map<string, Promise<string>>()
|
|
7
|
+
let queue: { text: string; resolve: (html: string) => void; reject: (err: unknown) => void }[] = []
|
|
8
|
+
|
|
9
|
+
async function flush() {
|
|
10
|
+
const batch = queue
|
|
11
|
+
queue = []
|
|
12
|
+
try {
|
|
13
|
+
const res = await fetch('/api/markdown', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ texts: batch.map(b => b.text) }) })
|
|
14
|
+
if (!res.ok) throw new Error(await res.text())
|
|
15
|
+
const { html, styles } = await res.json() as { html: string[]; styles: string[] }
|
|
16
|
+
for (const href of styles) {
|
|
17
|
+
if (![...document.querySelectorAll<HTMLLinkElement>('link[rel=stylesheet]')].some(l => new URL(l.href).pathname === new URL(href, location.href).pathname))
|
|
18
|
+
document.head.insertAdjacentHTML('beforeend', `<link rel="stylesheet" href="${href.replace(/"/g, '"')}">`)
|
|
19
|
+
}
|
|
20
|
+
batch.forEach((b, i) => b.resolve(html[i] ?? ''))
|
|
21
|
+
} catch (err) {
|
|
22
|
+
for (const b of batch) { cache.delete(b.text); b.reject(err) }
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function markdown(text: string): Promise<string> {
|
|
27
|
+
let got = cache.get(text)
|
|
28
|
+
if (!got) {
|
|
29
|
+
got = new Promise((resolve, reject) => {
|
|
30
|
+
if (!queue.length) queueMicrotask(flush)
|
|
31
|
+
queue.push({ text, resolve, reject })
|
|
32
|
+
})
|
|
33
|
+
cache.set(text, got)
|
|
34
|
+
}
|
|
35
|
+
return got
|
|
36
|
+
}
|
package/src/client/page/base.css
CHANGED
|
@@ -147,13 +147,32 @@ details[open] > :last-child { margin-bottom: 2em; }
|
|
|
147
147
|
.wb-nav > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
148
148
|
.wb-nav a { color: var(--muted); text-decoration: none; }
|
|
149
149
|
.wb-nav a:hover { color: var(--text); }
|
|
150
|
-
.
|
|
151
|
-
|
|
150
|
+
/* live.ts: a ring while not connected, grey while live with no agent listening, green with one */
|
|
151
|
+
.wb-live { width: 8px; height: 8px; box-sizing: border-box; border-radius: 50%; border: 1.5px solid var(--muted); background: none; flex: none; }
|
|
152
|
+
[data-wb-live] .wb-live { border-color: var(--muted); background: var(--muted); }
|
|
153
|
+
[data-wb-live] .wb-live[data-agent] { border-color: var(--ok); background: var(--ok); }
|
|
152
154
|
.wb-theme {
|
|
153
155
|
font: inherit; color: var(--muted); background: none; border: 1px solid var(--border); border-radius: 99px;
|
|
154
|
-
padding:
|
|
156
|
+
height: 24px; box-sizing: border-box; padding: 0 7px; cursor: pointer; display: inline-flex; align-items: center; flex: none;
|
|
155
157
|
}
|
|
156
158
|
.wb-theme:hover { color: var(--text); border-color: var(--muted); }
|
|
159
|
+
/* what waits for the reader on other pages (elsewhere.ts): a menu of them */
|
|
160
|
+
.wb-elsewhere { position: relative; flex: none; }
|
|
161
|
+
.wb-elsewhere[hidden], .wb-elsewhere-list[hidden] { display: none; }
|
|
162
|
+
.wb-awaiting {
|
|
163
|
+
font: inherit; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent);
|
|
164
|
+
border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 99px; height: 24px; box-sizing: border-box; padding: 0 9px; cursor: pointer;
|
|
165
|
+
display: inline-flex; align-items: center; gap: 5px;
|
|
166
|
+
}
|
|
167
|
+
.wb-awaiting svg { flex: none; }
|
|
168
|
+
.wb-index .wb-awaiting { vertical-align: 1px; margin-left: 4px; font: 600 .8rem/1.4 var(--sans); text-decoration: none; }
|
|
169
|
+
.wb-awaiting:hover { background: color-mix(in srgb, var(--accent) 18%, transparent); }
|
|
170
|
+
.wb-elsewhere-list {
|
|
171
|
+
position: absolute; right: 0; top: calc(100% + 6px); margin: 0; padding: 4px; list-style: none; min-width: 200px; max-width: min(360px, 100vw - 32px);
|
|
172
|
+
background: var(--bg); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 28px rgb(0 0 0 / .16);
|
|
173
|
+
}
|
|
174
|
+
.wb-nav .wb-elsewhere-list a { display: block; padding: 6px 10px; border-radius: 5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
175
|
+
.wb-nav .wb-elsewhere-list a:hover, .wb-nav .wb-elsewhere-list a:focus-visible { background: color-mix(in srgb, var(--accent) 12%, transparent); }
|
|
157
176
|
.wb-meta { color: var(--muted); font: .8rem/1.5 var(--sans); }
|
|
158
177
|
.wb-index { padding: 0; }
|
|
159
178
|
.wb-index li { list-style: none; padding: 12px 0; border-bottom: 1px solid var(--border); }
|
|
@@ -191,8 +210,7 @@ button:hover { border-color: var(--muted); }
|
|
|
191
210
|
.wb-fresh { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
|
|
192
211
|
|
|
193
212
|
form.wb-form[data-wb-folded] { padding: 1em 0; gap: 0; }
|
|
194
|
-
|
|
195
|
-
/* named forms: the core marks where each stands (data-wb-waiting, -unheard, -pending, -decided); this is how that looks */
|
|
213
|
+
/* named forms: the core marks where each stands (data-wb-open, -pending, -decided); this is how that looks */
|
|
196
214
|
form[data-wb-state=sending] { opacity: .7; }
|
|
197
215
|
/* sending: the form's buttons can't send twice */
|
|
198
216
|
form[data-wb-state=sending] button { pointer-events: none; cursor: progress; }
|
|
@@ -203,14 +221,13 @@ form.wb-form[data-wb-state=failed]::before { content: "couldn't send it: try aga
|
|
|
203
221
|
form[data-wb-sent]:not(.wb-form)::after { content: "✓ sent " attr(data-wb-sent); display: block; margin-top: 6px; color: var(--ok); font: .8rem var(--sans); }
|
|
204
222
|
form[data-wb-state=failed]:not(.wb-form)::after { content: "failed to send"; color: var(--bad); }
|
|
205
223
|
|
|
206
|
-
/* the button in the page's corner that
|
|
224
|
+
/* the button in the page's corner that goes to the next thing waiting for the reader */
|
|
207
225
|
.wb-waiting-next { background: var(--accent); color: var(--accent-text); border-color: var(--accent); border-radius: 99px; font-size: .8rem; }
|
|
208
226
|
.wb-waiting-next[hidden] { display: none; }
|
|
209
227
|
|
|
210
|
-
/*
|
|
211
|
-
form[data-wb-
|
|
212
|
-
form[data-wb-
|
|
213
|
-
form[data-wb-unheard]::before { content: "no agent is listening for this right now"; display: block; margin-bottom: 8px; color: var(--muted); font: .75rem/1.4 var(--sans); }
|
|
228
|
+
/* a question the reader hasn't answered, or one the agent asks again */
|
|
229
|
+
form[data-wb-open] { outline: 2px solid var(--accent); outline-offset: 10px; border-radius: 2px; }
|
|
230
|
+
form[data-wb-open]::before { content: "waiting for you"; display: block; margin-bottom: 8px; color: var(--accent); font: 600 .75rem/1.4 var(--sans); letter-spacing: .04em; text-transform: uppercase; }
|
|
214
231
|
form[data-wb-pending]::before { content: "sent · waiting for the agent to pick it up"; display: block; margin-bottom: 8px; color: var(--muted); font: .75rem/1.4 var(--sans); }
|
|
215
232
|
form[data-wb-pending][data-wb-just-sent]::before { content: "✓ sent · waiting for the agent to pick it up"; color: var(--ok); font-weight: 600; }
|
|
216
233
|
|
|
@@ -228,7 +245,7 @@ form[data-wb-folded]:hover::after { color: var(--accent); }
|
|
|
228
245
|
.wb-summary[hidden] { display: none; }
|
|
229
246
|
.wb-summary button { all: unset; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, currentColor 35%, transparent); }
|
|
230
247
|
.wb-summary button:hover { color: var(--text); }
|
|
231
|
-
.wb-summary button[data-state=
|
|
248
|
+
.wb-summary button:is([data-state=open], [data-state=messages]) { color: var(--accent); font-weight: 600; }
|
|
232
249
|
.wb-summary { max-width: calc(var(--measure) + var(--indent, 34px) + 32px); margin: 0 auto; padding: 96px 16px 0; box-sizing: border-box; color: var(--muted); font: .8rem/1.5 var(--sans); }
|
|
233
250
|
/* the summary takes the space above the title that the page would otherwise start with */
|
|
234
251
|
.wb-summary:not([hidden]) + main { padding-top: 20px; }
|
|
@@ -254,7 +271,11 @@ form[data-wb-folded]:hover::after { color: var(--accent); }
|
|
|
254
271
|
|
|
255
272
|
/* the overview's list of the project's documents */
|
|
256
273
|
.wb-documents { margin-top: 2.5em; }
|
|
257
|
-
.wb-documents h2 { font-size: 1.1rem; margin
|
|
274
|
+
.wb-documents h2 { font-size: 1.1rem; margin: 0; }
|
|
275
|
+
/* a list's heading with its sort control at the right (sort.ts) */
|
|
276
|
+
.wb-list-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: .4em; }
|
|
277
|
+
.wb-sort { font: .8rem/1.4 var(--sans); color: var(--muted); display: inline-flex; align-items: baseline; gap: 6px; }
|
|
278
|
+
.wb-sort select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 2px 6px; }
|
|
258
279
|
|
|
259
280
|
/* threads whose form is no longer on the page (orphans.ts): read-only, after the content */
|
|
260
281
|
.wb-orphans { --indent: 34px; max-width: calc(var(--measure) + var(--indent) + 32px); margin: 0 auto; padding: 0 16px 220px; box-sizing: border-box; font: .92rem/1.45 var(--sans); }
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// What waits for the reader on other pages: a menu in the page's header, there only while another
|
|
2
|
+
// page has a question they haven't answered or a message from the agent they haven't read. It
|
|
3
|
+
// lists those pages, each with how many; a click goes to the page, which goes to the first of them
|
|
4
|
+
// (`#wb-waiting`, see waiting.ts). This page's own are in its corner, not here.
|
|
5
|
+
import type { Api, PageHandle, PageStatus } from '../../define.ts'
|
|
6
|
+
import { INBOX_ICON, awaitingLabel } from '../../icons.ts'
|
|
7
|
+
import { awaiting } from '../../status.ts'
|
|
8
|
+
|
|
9
|
+
/** A link to a page that scrolls it to its first waiting question. */
|
|
10
|
+
export const WAITING_HASH = '#wb-waiting'
|
|
11
|
+
|
|
12
|
+
const box = document.createElement('div')
|
|
13
|
+
box.className = 'wb-elsewhere'
|
|
14
|
+
box.hidden = true
|
|
15
|
+
box.innerHTML = '<button type="button" class="wb-elsewhere-toggle wb-awaiting" aria-haspopup="true" aria-expanded="false"></button><ul class="wb-elsewhere-list" hidden></ul>'
|
|
16
|
+
const toggle = box.querySelector('button')!
|
|
17
|
+
// an inbox, and how many questions wait in it
|
|
18
|
+
toggle.innerHTML = `${INBOX_ICON}<span class="wb-elsewhere-count"></span>`
|
|
19
|
+
const count = toggle.querySelector('span')!
|
|
20
|
+
const list = box.querySelector('ul')!
|
|
21
|
+
|
|
22
|
+
function open(yes: boolean) {
|
|
23
|
+
list.hidden = !yes
|
|
24
|
+
toggle.setAttribute('aria-expanded', String(yes))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let current = ''
|
|
28
|
+
|
|
29
|
+
async function load() {
|
|
30
|
+
let pages: PageStatus[]
|
|
31
|
+
try { pages = await (await fetch('/api/status', { cache: 'no-store' })).json() } catch { return }
|
|
32
|
+
const waiting = pages
|
|
33
|
+
.filter(p => p.page !== current)
|
|
34
|
+
.map(p => ({ p, n: awaiting(p) }))
|
|
35
|
+
.filter(({ n }) => n > 0)
|
|
36
|
+
const total = waiting.reduce((sum, { n }) => sum + n, 0)
|
|
37
|
+
box.hidden = total === 0
|
|
38
|
+
if (!total) open(false)
|
|
39
|
+
count.textContent = String(total)
|
|
40
|
+
toggle.title = awaitingLabel(total, ` on ${waiting.length === 1 ? 'another page' : `${waiting.length} other pages`}`)
|
|
41
|
+
toggle.setAttribute('aria-label', toggle.title)
|
|
42
|
+
list.replaceChildren(...waiting.map(({ p, n }) => {
|
|
43
|
+
const li = document.createElement('li')
|
|
44
|
+
const a = document.createElement('a')
|
|
45
|
+
a.href = `/${p.page.split('/').map(encodeURIComponent).join('/')}${WAITING_HASH}`
|
|
46
|
+
a.textContent = `${p.title} (${n})`
|
|
47
|
+
li.append(a)
|
|
48
|
+
return li
|
|
49
|
+
}))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// several changes at once (an answer is an event and a listener less) load once
|
|
53
|
+
let timer = 0
|
|
54
|
+
const reload = () => { clearTimeout(timer); timer = window.setTimeout(load, 100) }
|
|
55
|
+
|
|
56
|
+
export function trackElsewhere(root: HTMLElement, handle: PageHandle, core: Api) {
|
|
57
|
+
current = handle.id
|
|
58
|
+
const nav = root.querySelector('.wb-nav')
|
|
59
|
+
if (!nav) return
|
|
60
|
+
nav.querySelector('.wb-theme')?.before(box)
|
|
61
|
+
toggle.addEventListener('click', () => open(!!list.hidden))
|
|
62
|
+
document.addEventListener('click', e => { if (!box.contains(e.target as Node)) open(false) })
|
|
63
|
+
document.addEventListener('keydown', e => { if (e.key === 'Escape' && !list.hidden) { open(false); toggle.focus() } })
|
|
64
|
+
// what waits changes with an answer (events), a wait starting or ending (listeners), and a page's
|
|
65
|
+
// forms (a page changed)
|
|
66
|
+
core.onEvents(reload)
|
|
67
|
+
core.onListeners(reload)
|
|
68
|
+
handle.onChange(reload)
|
|
69
|
+
load()
|
|
70
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The dot at the end of the header: is the page live, and does an agent take its answers? Green: the
|
|
2
|
+
// live channel is open and a wait or watch covers the page (one with --page on it or above it, or
|
|
3
|
+
// the project-wide one without --page). Grey: live, but no agent listens, so answers wait in the
|
|
4
|
+
// log. A ring: not connected, the page may be out of date (the core reconnects and catches up).
|
|
5
|
+
// What it says on hover tells them apart. Only the overview and folders have no answers: there it
|
|
6
|
+
// says only whether the page is live.
|
|
7
|
+
import type { Api, PageHandle } from '../../define.ts'
|
|
8
|
+
|
|
9
|
+
export function trackLive(root: HTMLElement, handle: PageHandle, api: Api) {
|
|
10
|
+
const dot = root.querySelector<HTMLElement>('.wb-live')
|
|
11
|
+
if (!dot) return
|
|
12
|
+
const hasAnswers = handle.kind === 'page' || handle.kind === 'file'
|
|
13
|
+
const show = () => {
|
|
14
|
+
const live = document.documentElement.hasAttribute('data-wb-live')
|
|
15
|
+
const listeners = hasAnswers ? api.listeners() : []
|
|
16
|
+
const own = listeners.some(l => !l.fallback)
|
|
17
|
+
const anyPage = listeners.some(l => l.fallback)
|
|
18
|
+
const agent = live && (own || anyPage)
|
|
19
|
+
dot.toggleAttribute('data-agent', agent)
|
|
20
|
+
dot.title = !live ? 'Reconnecting… the page may be out of date'
|
|
21
|
+
: !hasAnswers ? 'Live'
|
|
22
|
+
: own ? 'Live · an agent is listening on this page'
|
|
23
|
+
: anyPage ? 'Live · an agent is listening on every page'
|
|
24
|
+
: 'Live · no agent is listening right now; answers wait in the log'
|
|
25
|
+
dot.setAttribute('aria-label', dot.title)
|
|
26
|
+
}
|
|
27
|
+
api.onListeners(show)
|
|
28
|
+
new MutationObserver(show).observe(document.documentElement, { attributes: true, attributeFilter: ['data-wb-live'] })
|
|
29
|
+
show()
|
|
30
|
+
}
|