@bigmistqke/whiteboard 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -10
- package/bin/whiteboard.ts +98 -4
- package/dist/bin/whiteboard.js +99 -3
- package/dist/client/runtime.js +118 -24
- package/dist/plugins/claude-code/index.js +14 -3
- package/dist/plugins/comments/client.js +3 -3
- package/dist/plugins/details/README.md +3 -1
- package/dist/plugins/form/README.md +6 -4
- package/dist/plugins/form/index.js +9 -1
- package/dist/plugins/form/style.css +3 -0
- package/dist/plugins/toc/README.md +10 -0
- package/dist/plugins/toc/client.js +1 -0
- package/dist/plugins/toc/index.js +17 -0
- package/dist/plugins/toc/style.css +19 -0
- package/dist/src/client/page/base.css +26 -22
- package/dist/src/client/page/main.js +227 -52
- package/dist/src/events.js +127 -9
- package/dist/src/loader.js +4 -0
- package/dist/src/server.js +25 -17
- package/package.json +6 -1
- package/plugins/claude-code/index.ts +16 -7
- package/plugins/comments/client.ts +30 -7
- package/plugins/details/README.md +3 -1
- package/plugins/form/README.md +6 -4
- package/plugins/form/index.ts +9 -1
- package/plugins/form/style.css +3 -0
- package/plugins/toc/README.md +10 -0
- package/plugins/toc/client.ts +130 -0
- package/plugins/toc/index.ts +25 -0
- package/plugins/toc/style.css +19 -0
- package/skills/whiteboard/SKILL.md +41 -9
- package/src/client/forms.ts +32 -1
- package/src/client/page/base.css +26 -22
- package/src/client/page/fresh.ts +18 -23
- package/src/client/page/hold.ts +37 -0
- package/src/client/page/main.ts +81 -6
- package/src/client/page/sticky.ts +45 -0
- package/src/client/page/waiting.ts +30 -27
- package/src/client/runtime.ts +8 -2
- package/src/client/scroll.ts +44 -0
- package/src/client/toast.ts +51 -21
- package/src/define.ts +17 -8
- package/src/events.ts +95 -7
- package/src/loader.ts +1 -1
- package/src/server.ts +28 -7
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
// export default defineConfig({ plugins: [claudeCode()] })
|
|
6
6
|
//
|
|
7
7
|
// `whiteboard claude-code install` adds the hooks to the project's .claude/settings.json. Each runs
|
|
8
|
-
// `whiteboard claude-code hook <stop|prompt|session>`, and none of them ever blocks:
|
|
9
|
-
// - stop (a turn ends):
|
|
8
|
+
// `whiteboard claude-code hook <stop|prompt|session>`, and none of them ever blocks but once:
|
|
9
|
+
// - stop (a turn ends): when the session's pages have questions nobody listens for, the agent's turn
|
|
10
|
+
// goes on once, told to start its wait (it forgot); a turn a hook already continued ends, and the
|
|
11
|
+
// reader sees what is open;
|
|
10
12
|
// - prompt (the reader sends a message): the agent gets, as context, the answers on its pages that
|
|
11
13
|
// no wait picked up, which count as picked up from then on;
|
|
12
14
|
// - session (a session starts): the same, plus what is open on other sessions' pages, without
|
|
@@ -42,7 +44,7 @@ export default function claudeCode(): Plugin {
|
|
|
42
44
|
session: () => process.env.CLAUDE_CODE_SESSION_ID || null,
|
|
43
45
|
commands: {
|
|
44
46
|
hook: {
|
|
45
|
-
description: 'what Claude Code runs on an event (stop, prompt or session): report what is open on the session\'s pages;
|
|
47
|
+
description: 'what Claude Code runs on an event (stop, prompt or session): report what is open on the session\'s pages; a stop with questions nobody listens for continues the turn once, to start a wait',
|
|
46
48
|
args: '<stop|prompt|session>',
|
|
47
49
|
async run(ctx) {
|
|
48
50
|
const mode = ctx.positionals[0] as Mode
|
|
@@ -60,24 +62,31 @@ export default function claudeCode(): Plugin {
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
/** The JSON Claude Code passes a hook on its standard input, or nothing. */
|
|
63
|
-
function hookInput(): { session_id?: string } {
|
|
65
|
+
function hookInput(): { session_id?: string; stop_hook_active?: boolean } {
|
|
64
66
|
if (process.stdin.isTTY) return {}
|
|
65
67
|
try { return JSON.parse(fs.readFileSync(0, 'utf8') || '{}') } catch { return {} }
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
const relFile = (file: string) => path.relative(process.cwd(), file) || file
|
|
69
71
|
async function hook(ctx: CommandContext, mode: Mode) {
|
|
70
|
-
const
|
|
72
|
+
const input = hookInput()
|
|
73
|
+
const session = input.session_id ?? process.env.CLAUDE_CODE_SESSION_ID ?? null
|
|
71
74
|
const pages = await ctx.status()
|
|
72
75
|
const busy = pages.filter(p => p.unpicked.length || p.open.length)
|
|
73
76
|
const mine = busy.filter(p => session && p.owner === session)
|
|
74
77
|
|
|
75
78
|
if (mode === 'stop') {
|
|
76
|
-
//
|
|
79
|
+
// A turn ends with questions on the session's pages nobody listens for, or answers no wait
|
|
80
|
+
// picked up: the agent forgot to wait again. Its turn goes on once, with that as the reason, so
|
|
81
|
+
// it starts the wait; Claude Code marks a turn a hook continued (stop_hook_active), and that
|
|
82
|
+
// one ends, with what is open shown to the reader instead.
|
|
77
83
|
const loose = mine.filter(p => p.unheard.length || p.unpicked.length)
|
|
78
84
|
if (!loose.length) return
|
|
79
85
|
const said = (p: PageStatus) => { const l = openOn(p, { waiting: false }); return `${l.slice(0, -1).join('; ')} ${l.at(-1)}` }
|
|
80
|
-
|
|
86
|
+
const shown = `whiteboard: ${loose.map(p => `${p.page}: ${said(p)}`).join(' · ')}`
|
|
87
|
+
if (input.stop_hook_active) { console.log(JSON.stringify({ systemMessage: shown })); return }
|
|
88
|
+
const reason = loose.map(p => `On your whiteboard page ${p.page}: ${openOn(p, { waiting: false }).slice(0, -1).join('; ')}. Run \`whiteboard wait --page ${relFile(p.file)}\` in the background before ending your turn.`).join('\n')
|
|
89
|
+
console.log(JSON.stringify({ decision: 'block', reason, systemMessage: shown }))
|
|
81
90
|
return
|
|
82
91
|
}
|
|
83
92
|
|
|
@@ -175,13 +175,30 @@ function draw() {
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/** Called after the page re-rendered, and whenever the log changed. */
|
|
178
|
+
/**
|
|
179
|
+
* Change the thread around a reply being typed, and keep that box where it is on screen: a new
|
|
180
|
+
* message above it, or one shown as markdown, would push it down.
|
|
181
|
+
*/
|
|
182
|
+
function holdTyping(change: () => void) {
|
|
183
|
+
const box = popover.querySelector('textarea')
|
|
184
|
+
const typing = !!box && document.activeElement === box
|
|
185
|
+
const top = typing ? box!.getBoundingClientRect().top : 0
|
|
186
|
+
change()
|
|
187
|
+
const now = popover.querySelector('textarea')
|
|
188
|
+
if (!typing || !now || document.activeElement !== now) return
|
|
189
|
+
const moved = now.getBoundingClientRect().top - top
|
|
190
|
+
if (Math.abs(moved) >= 1) scrollBy(0, moved)
|
|
191
|
+
}
|
|
192
|
+
|
|
178
193
|
function refreshComments() {
|
|
179
194
|
if (!root) return
|
|
180
195
|
main = root.querySelector('main') ?? root
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
196
|
+
holdTyping(() => {
|
|
197
|
+
threads = collect()
|
|
198
|
+
if (openThread && !threads.some(t => t.id === openThread)) closePopover()
|
|
199
|
+
else if (openThread) renderPopover()
|
|
200
|
+
draw()
|
|
201
|
+
})
|
|
185
202
|
}
|
|
186
203
|
|
|
187
204
|
// ---- the thread popover ------------------------------------------------------------------------
|
|
@@ -200,7 +217,11 @@ function renderPopover() {
|
|
|
200
217
|
const md = rendered.get(text)
|
|
201
218
|
return html`<div class="wb-thread-message" data-from="${who(e)}" data-wb-message="${e.id}"><span class="wb-thread-who">${who(e)}</span><div class="wb-thread-text"${md != null ? raw(' data-md') : ''}>${md != null ? raw(md) : text}</div></div>`
|
|
202
219
|
}
|
|
203
|
-
|
|
220
|
+
// the reply being typed: its text, and its focus and caret, which a redraw would take
|
|
221
|
+
const box = popover.querySelector('textarea')
|
|
222
|
+
const draft = box?.value ?? ''
|
|
223
|
+
const typing = !!box && document.activeElement === box
|
|
224
|
+
const caret = box ? [box.selectionStart, box.selectionEnd] as const : null
|
|
204
225
|
popover.innerHTML = String(html`
|
|
205
226
|
<blockquote class="wb-thread-quote">${t.comment.data.quote ?? ''}</blockquote>
|
|
206
227
|
${t.comment.data.at && html`<p class="wb-thread-at">${t.comment.data.at}</p>`}
|
|
@@ -210,7 +231,9 @@ function renderPopover() {
|
|
|
210
231
|
<textarea rows="2" placeholder="Reply (Shift+Enter for a new line)"></textarea>
|
|
211
232
|
<div class="wb-thread-actions"><button type="submit" class="wb-comment-button wb-comment-primary">Reply</button><button type="button" class="wb-comment-button" data-close>Close thread</button></div>
|
|
212
233
|
</form>`)
|
|
213
|
-
popover.querySelector('textarea')
|
|
234
|
+
const again = popover.querySelector('textarea')!
|
|
235
|
+
again.value = draft
|
|
236
|
+
if (typing) { again.focus({ preventScroll: true }); if (caret) again.setSelectionRange(caret[0], caret[1]) }
|
|
214
237
|
// the messages not rendered yet: their text only, put in place as each arrives (the rest of the
|
|
215
238
|
// thread, the reply being typed among it, stays as it is)
|
|
216
239
|
for (const e of [t.comment, ...t.replies]) {
|
|
@@ -219,7 +242,7 @@ function renderPopover() {
|
|
|
219
242
|
api.markdown(text).then(md => {
|
|
220
243
|
rendered.set(text, md)
|
|
221
244
|
const el = popover.querySelector<HTMLElement>(`[data-wb-message="${CSS.escape(e.id)}"] .wb-thread-text`)
|
|
222
|
-
if (el && !el.hasAttribute('data-md')) { el.innerHTML = md; el.setAttribute('data-md', '') }
|
|
245
|
+
if (el && !el.hasAttribute('data-md')) holdTyping(() => { el.innerHTML = md; el.setAttribute('data-md', '') })
|
|
223
246
|
}, err => console.error('comments:', err))
|
|
224
247
|
}
|
|
225
248
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
A collapsible section. The label is the summary line; the body is any
|
|
2
2
|
markdown. Use it to keep in-depth explanation out of the way of the main read.
|
|
3
|
-
Unlike a raw `<details>` tag, the body needs no blank-line care.
|
|
3
|
+
Unlike a raw `<details>` tag, the body needs no blank-line care. While it
|
|
4
|
+
is open, its title stays at the top as you scroll through it, and the title
|
|
5
|
+
of a details inside it stacks below.
|
|
4
6
|
|
|
5
7
|
Attributes: `open` (start expanded).
|
|
6
8
|
|
package/plugins/form/README.md
CHANGED
|
@@ -11,6 +11,7 @@ explains it.
|
|
|
11
11
|
| input | written as | sends |
|
|
12
12
|
| --- | --- | --- |
|
|
13
13
|
| one choice | `:radio[This week]{name=when}` per option | the picked label's text, or `null` |
|
|
14
|
+
| an answer not on the list | `:radio[Other]{name=when other}` (or `:check[…]{… other}`) | what the reader typed in its box |
|
|
14
15
|
| several choices | `:check[Android]{name=phones}` per option | an array of the checked labels |
|
|
15
16
|
| one checkbox | `:check[I read it]{name=read}` | `true` or `false` |
|
|
16
17
|
| text | `:text[Title]{name=title placeholder="a short name"}` | the text |
|
|
@@ -23,6 +24,9 @@ explains it.
|
|
|
23
24
|
- The label in `[…]` is markdown. An option sends its label as plain text
|
|
24
25
|
(`:radio[This **week**]` sends `This week`), unless `value=…` says what
|
|
25
26
|
to send instead.
|
|
27
|
+
- `other` makes an option for an answer not on the list: it has a text box,
|
|
28
|
+
typing in it picks the option, and it sends what was typed (`placeholder`
|
|
29
|
+
says what goes in the box). Prefer it to a separate free-text field.
|
|
26
30
|
- `recommended` tags an option as the writer's recommendation; it is never
|
|
27
31
|
preselected, so a choice is only made by picking it. `checked` does
|
|
28
32
|
preselect one; use it for defaults, not for decisions.
|
|
@@ -43,6 +47,7 @@ under it. Such an item reads as a row to pick:
|
|
|
43
47
|
Simple, and the agent waits on one file.
|
|
44
48
|
- :radio[One log per page]{name=where}
|
|
45
49
|
Pages can be moved with their answers.
|
|
50
|
+
- :radio[Somewhere else]{name=where other placeholder="where?"}
|
|
46
51
|
:::
|
|
47
52
|
````
|
|
48
53
|
|
|
@@ -53,6 +58,7 @@ under it. Such an item reads as a row to pick:
|
|
|
53
58
|
Simple, and the agent waits on one file.
|
|
54
59
|
- :radio[One log per page]{name=where}
|
|
55
60
|
Pages can be moved with their answers.
|
|
61
|
+
- :radio[Somewhere else]{name=where other placeholder="where?"}
|
|
56
62
|
:::
|
|
57
63
|
|
|
58
64
|
An option's explanation can be any markdown: a code block, a table, a
|
|
@@ -75,8 +81,6 @@ Runs the migration on a copy first.
|
|
|
75
81
|
The migration is reversible.
|
|
76
82
|
:::
|
|
77
83
|
|
|
78
|
-
:textarea[Notes]{name=notes placeholder="anything to check first"}
|
|
79
|
-
|
|
80
84
|
:button[Approve] :button[Hold]
|
|
81
85
|
::::
|
|
82
86
|
````
|
|
@@ -92,8 +96,6 @@ Runs the migration on a copy first.
|
|
|
92
96
|
The migration is reversible.
|
|
93
97
|
:::
|
|
94
98
|
|
|
95
|
-
:textarea[Notes]{name=notes placeholder="anything to check first"}
|
|
96
|
-
|
|
97
99
|
:button[Approve] :button[Hold]
|
|
98
100
|
::::
|
|
99
101
|
|
package/plugins/form/index.ts
CHANGED
|
@@ -52,9 +52,17 @@ const form: Block = {
|
|
|
52
52
|
/** The label of an inline input as HTML, else its fallback. */
|
|
53
53
|
const labelOf = (c: DirectiveContext, fallback = '') => (c.label ? raw(c.label) : fallback)
|
|
54
54
|
|
|
55
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* :radio[label]{name=… value=… recommended checked} and :check[…]{…}. With `other`, an answer not on
|
|
57
|
+
* the list: the option has a text box, typing in it picks the option, and it sends what was typed
|
|
58
|
+
* (the core's forms.ts, `data-wb-other`).
|
|
59
|
+
*/
|
|
56
60
|
const option = (type: 'radio' | 'checkbox'): Block['html'] => (ctx) => {
|
|
57
61
|
const c = ctx as DirectiveContext
|
|
62
|
+
if ('other' in c.attrs) {
|
|
63
|
+
const placeholder = c.attrs.placeholder ?? 'something else'
|
|
64
|
+
return html`<label class="wb-form-option wb-form-other"><input type="${type}" name="${c.attrs.name}" value="" data-wb-other><span class="wb-form-option-label">${labelOf(c, 'Other')}</span><input type="text" class="wb-form-other-text" data-wb-other-text placeholder="${placeholder}" aria-label="${c.labelText ?? 'Other'}"></label>`
|
|
65
|
+
}
|
|
58
66
|
const value = c.attrs.value ?? c.labelText ?? ''
|
|
59
67
|
return html`<label class="wb-form-option"><input type="${type}" name="${c.attrs.name}" value="${value}"${'checked' in c.attrs && raw(' checked')}><span class="wb-form-option-label">${labelOf(c, value)}</span>${'recommended' in c.attrs && recommendedTag}</label>`
|
|
60
68
|
}
|
package/plugins/form/style.css
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
.wb-form-option + .wb-form-option { margin-left: 18px; }
|
|
15
15
|
.wb-form-option input { margin: 0; translate: 0 .1em; }
|
|
16
16
|
.wb-form-option-label { font-weight: 600; }
|
|
17
|
+
/* an answer not on the list: a text box in the option's line (`other`) */
|
|
18
|
+
.wb-form-other { align-items: center; }
|
|
19
|
+
.wb-form-other .wb-form-other-text { translate: none; font: inherit; padding: 3px 8px; min-width: 12em; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
|
|
17
20
|
.wb-form-recommended { font: 500 .7rem/1.4 var(--sans); color: var(--muted); letter-spacing: .04em; text-transform: uppercase; margin-left: 10px; }
|
|
18
21
|
|
|
19
22
|
/* a list item that starts with an option is a row to pick: no bullet, the picked one tinted, and
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
A table of contents beside the page, from its `##` and `###` headings,
|
|
2
|
+
numbered as the page numbers them. The section being read is marked, a click
|
|
3
|
+
goes to a section, and a section with an unanswered question or an unread
|
|
4
|
+
message has a dot. It sits in the margin left of the text when the window has
|
|
5
|
+
room; else a button in the header opens it. Opt in, in the config:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import toc from '@bigmistqke/whiteboard/toc'
|
|
9
|
+
export default defineConfig({ plugins: [toc()] })
|
|
10
|
+
```
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// The table of contents (index.ts): built from the page's ## and ### headings, again after each
|
|
2
|
+
// update; the section being read is the last heading above the top of the view; a section is
|
|
3
|
+
// marked when an open question (data-wb-open) or an unread message (data-wb-message, or the element
|
|
4
|
+
// holding one, data-wb-holds) is in it. A click scrolls to the heading, below the header.
|
|
5
|
+
import type { Api, PluginMount } from '../../src/define.ts'
|
|
6
|
+
|
|
7
|
+
const panel = document.createElement('nav')
|
|
8
|
+
panel.className = 'wb-toc'
|
|
9
|
+
panel.setAttribute('aria-label', 'Contents')
|
|
10
|
+
const list = document.createElement('ol')
|
|
11
|
+
panel.append(list)
|
|
12
|
+
|
|
13
|
+
const toggle = document.createElement('button')
|
|
14
|
+
toggle.type = 'button'
|
|
15
|
+
toggle.className = 'wb-toc-toggle'
|
|
16
|
+
toggle.title = toggle.ariaLabel = 'Contents'
|
|
17
|
+
toggle.innerHTML = '<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 4h11M2.5 8h11M2.5 12h7"/></svg>'
|
|
18
|
+
|
|
19
|
+
let main: HTMLElement
|
|
20
|
+
let api: Api
|
|
21
|
+
let headings: HTMLElement[] = []
|
|
22
|
+
|
|
23
|
+
const navHeight = () => document.querySelector<HTMLElement>('.wb-nav')?.getBoundingClientRect().height ?? 0
|
|
24
|
+
|
|
25
|
+
/** Is there room left of the text for the panel? Else it opens from the header. */
|
|
26
|
+
function fits() {
|
|
27
|
+
const left = main.getBoundingClientRect().left
|
|
28
|
+
return left >= 230
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function build() {
|
|
32
|
+
headings = [...main.querySelectorAll<HTMLElement>(':scope > h2, :scope > h3')]
|
|
33
|
+
let h2 = 0, h3 = 0
|
|
34
|
+
list.replaceChildren(...headings.map((h, i) => {
|
|
35
|
+
// the page's numbers: 1, 1.1, 1.2, 2 (base.css counts ## and ### alike)
|
|
36
|
+
const number = h.tagName === 'H2' ? `${++h2}` : `${h2}.${++h3}`
|
|
37
|
+
if (h.tagName === 'H2') h3 = 0
|
|
38
|
+
const li = document.createElement('li')
|
|
39
|
+
li.dataset.level = h.tagName === 'H2' ? '2' : '3'
|
|
40
|
+
const a = document.createElement('a')
|
|
41
|
+
a.href = '#'
|
|
42
|
+
a.dataset.index = String(i)
|
|
43
|
+
a.innerHTML = `<span class="wb-toc-number"></span><span class="wb-toc-text"></span>`
|
|
44
|
+
a.querySelector('.wb-toc-number')!.textContent = number
|
|
45
|
+
a.querySelector('.wb-toc-text')!.textContent = h.textContent ?? ''
|
|
46
|
+
li.append(a)
|
|
47
|
+
return li
|
|
48
|
+
}))
|
|
49
|
+
const any = headings.length > 1
|
|
50
|
+
toggle.hidden = !any || fits()
|
|
51
|
+
panel.hidden = !any || (!fits() && !panel.classList.contains('wb-toc-open'))
|
|
52
|
+
panel.classList.toggle('wb-toc-docked', fits())
|
|
53
|
+
mark()
|
|
54
|
+
current()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The section each element is in: the last heading before it. */
|
|
58
|
+
function sectionOf(el: Element): number {
|
|
59
|
+
let at = -1
|
|
60
|
+
for (let i = 0; i < headings.length; i++) {
|
|
61
|
+
if (headings[i].compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING) at = i
|
|
62
|
+
else break
|
|
63
|
+
}
|
|
64
|
+
return at
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A dot on the sections where something waits for the reader. */
|
|
68
|
+
function mark() {
|
|
69
|
+
const waiting = new Set<number>()
|
|
70
|
+
const unread = new Set(api.unread().map(e => e.id))
|
|
71
|
+
const els = [
|
|
72
|
+
...main.querySelectorAll('form[data-wb-open]'),
|
|
73
|
+
...[...main.querySelectorAll<HTMLElement>('[data-wb-message]')].filter(el => unread.has(el.dataset.wbMessage!)),
|
|
74
|
+
]
|
|
75
|
+
for (const el of els) waiting.add(sectionOf(el))
|
|
76
|
+
// a reply in a closed comment thread: its badge sits outside the page's flow, beside the passage
|
|
77
|
+
for (const badge of document.querySelectorAll<HTMLElement>('[data-wb-holds]')) {
|
|
78
|
+
if (!badge.dataset.wbHolds!.split(' ').some(id => unread.has(id))) continue
|
|
79
|
+
const y = badge.getBoundingClientRect().top
|
|
80
|
+
let at = -1
|
|
81
|
+
headings.forEach((h, i) => { if (h.getBoundingClientRect().top <= y) at = i })
|
|
82
|
+
waiting.add(at)
|
|
83
|
+
}
|
|
84
|
+
list.querySelectorAll<HTMLElement>('a').forEach((a, i) => a.toggleAttribute('data-waiting', waiting.has(i)))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The section being read: the last heading above the top of the view. */
|
|
88
|
+
function current() {
|
|
89
|
+
const line = navHeight() + 40
|
|
90
|
+
let at = 0
|
|
91
|
+
headings.forEach((h, i) => { if (h.getBoundingClientRect().top <= line) at = i })
|
|
92
|
+
list.querySelectorAll<HTMLElement>('a').forEach((a, i) => a.toggleAttribute('aria-current', i === at && headings.length > 0))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function go(i: number) {
|
|
96
|
+
const h = headings[i]
|
|
97
|
+
if (!h) return
|
|
98
|
+
scrollTo({ top: Math.max(0, scrollY + h.getBoundingClientRect().top - navHeight() - 12), behavior: 'smooth' })
|
|
99
|
+
if (!fits()) { panel.classList.remove('wb-toc-open'); panel.hidden = true }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const mount: PluginMount = (root, handle, core) => {
|
|
103
|
+
if (handle.kind !== 'page' && handle.kind !== 'file') return
|
|
104
|
+
main = root.querySelector<HTMLElement>('#wb-main') ?? root
|
|
105
|
+
api = core
|
|
106
|
+
document.body.append(panel)
|
|
107
|
+
root.querySelector('.wb-nav .wb-theme')?.before(toggle)
|
|
108
|
+
list.addEventListener('click', e => {
|
|
109
|
+
const a = (e.target as HTMLElement).closest<HTMLElement>('a[data-index]')
|
|
110
|
+
if (!a) return
|
|
111
|
+
e.preventDefault()
|
|
112
|
+
go(Number(a.dataset.index))
|
|
113
|
+
})
|
|
114
|
+
toggle.addEventListener('click', () => {
|
|
115
|
+
const open = !panel.classList.contains('wb-toc-open')
|
|
116
|
+
panel.classList.toggle('wb-toc-open', open)
|
|
117
|
+
panel.hidden = !open
|
|
118
|
+
})
|
|
119
|
+
document.addEventListener('keydown', e => { if (e.key === 'Escape' && panel.classList.contains('wb-toc-open')) toggle.click() })
|
|
120
|
+
let frame = 0
|
|
121
|
+
const soon = (fn: () => void) => () => { cancelAnimationFrame(frame); frame = requestAnimationFrame(fn) }
|
|
122
|
+
addEventListener('scroll', soon(current), { passive: true })
|
|
123
|
+
addEventListener('resize', soon(build))
|
|
124
|
+
api.onRendered(build)
|
|
125
|
+
api.onForms(() => mark())
|
|
126
|
+
api.onEvents(() => requestAnimationFrame(mark))
|
|
127
|
+
build()
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export default mount
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// A table of contents beside the page: its sections (## and ### headings), numbered as the page
|
|
2
|
+
// numbers them, the one being read marked, a dot where something waits for the reader (an
|
|
3
|
+
// unanswered question, an unread message). In the margin left of the text when the window has room
|
|
4
|
+
// for it; else a button in the header that opens it. A project turns it on in its config:
|
|
5
|
+
//
|
|
6
|
+
// import toc from '@bigmistqke/whiteboard/toc'
|
|
7
|
+
// export default defineConfig({ plugins: [toc()] })
|
|
8
|
+
import { packagePath } from '../../src/package.ts'
|
|
9
|
+
import type { Plugin } from '../../src/define.ts'
|
|
10
|
+
|
|
11
|
+
const DOCS = `## Table of contents
|
|
12
|
+
|
|
13
|
+
Pages here have a table of contents beside them, made from their \`##\` and
|
|
14
|
+
\`###\` headings: give a long page headings, and the reader can find their way
|
|
15
|
+
in it. A section with an unanswered question or an unread message has a dot.
|
|
16
|
+
`
|
|
17
|
+
|
|
18
|
+
export default function toc(): Plugin {
|
|
19
|
+
return {
|
|
20
|
+
name: 'toc',
|
|
21
|
+
docs: () => DOCS,
|
|
22
|
+
style: packagePath('dist/plugins/toc/style.css'),
|
|
23
|
+
setup: () => ({ client: packagePath('dist/plugins/toc/client.js') }),
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* the table of contents (client.ts): in the margin left of the text, or opened from the header */
|
|
2
|
+
.wb-toc { position: fixed; z-index: 4; font: .8rem/1.4 var(--sans, sans-serif); }
|
|
3
|
+
.wb-toc[hidden], .wb-toc-toggle[hidden] { display: none; }
|
|
4
|
+
.wb-toc-docked { top: 72px; left: max(16px, calc((100vw - var(--measure, 680px)) / 2 - 250px)); width: 210px; max-height: calc(100vh - 120px - var(--wb-inset-bottom, 0px)); overflow: auto; }
|
|
5
|
+
.wb-toc-open:not(.wb-toc-docked) {
|
|
6
|
+
top: 52px; left: 16px; width: min(300px, 100vw - 32px); max-height: calc(100vh - 100px - var(--wb-inset-bottom, 0px)); overflow: auto;
|
|
7
|
+
padding: 6px; background: var(--bg, Canvas); border: 1px solid var(--border, #e3e5e9); border-radius: 8px; box-shadow: 0 8px 28px rgb(0 0 0 / .16);
|
|
8
|
+
}
|
|
9
|
+
.wb-toc ol { list-style: none; margin: 0; padding: 0; }
|
|
10
|
+
.wb-toc li[data-level="3"] { padding-left: 14px; }
|
|
11
|
+
.wb-toc a { display: flex; gap: 8px; align-items: baseline; padding: 3px 8px; border-radius: 5px; color: var(--muted, #696e76); text-decoration: none; border-left: 2px solid transparent; }
|
|
12
|
+
.wb-toc a:hover { color: var(--text, CanvasText); background: color-mix(in srgb, var(--text, CanvasText) 6%, transparent); }
|
|
13
|
+
.wb-toc a[aria-current] { color: var(--text, CanvasText); border-left-color: var(--accent, #1d5bbf); font-weight: 600; }
|
|
14
|
+
.wb-toc-number { font-variant-numeric: tabular-nums; opacity: .7; flex: none; }
|
|
15
|
+
.wb-toc-text { overflow: hidden; text-overflow: ellipsis; }
|
|
16
|
+
/* something waits for the reader in this section */
|
|
17
|
+
.wb-toc a[data-waiting]::after { content: ''; flex: none; width: 7px; height: 7px; margin-left: auto; align-self: center; border-radius: 50%; background: var(--accent, #1d5bbf); }
|
|
18
|
+
.wb-toc-toggle { flex: none; display: inline-grid; place-items: center; height: 24px; box-sizing: border-box; padding: 0 7px; border-radius: 99px; border: 1px solid var(--border, #e3e5e9); background: none; color: var(--muted, #696e76); cursor: pointer; }
|
|
19
|
+
.wb-toc-toggle:hover { color: var(--text, CanvasText); border-color: var(--muted, #696e76); }
|
|
@@ -32,6 +32,21 @@ PATH, the project has it installed locally: run them as `npx whiteboard …`.
|
|
|
32
32
|
4. Run `whiteboard show <file>`: it starts the server if needed and prints the
|
|
33
33
|
URL. Give the user the URL the first time; after that, just keep editing
|
|
34
34
|
the file — the open page follows.
|
|
35
|
+
5. A page that was only for the moment (one question, a check, a demo):
|
|
36
|
+
once it has done its job and you've acted on its answers, close it with
|
|
37
|
+
`whiteboard close <file>`. That removes the page and its events (answers,
|
|
38
|
+
chats, comments) from the log, so it doesn't linger in the overview or in
|
|
39
|
+
`whiteboard status`. Keep pages the user may come back to (plans, reviews,
|
|
40
|
+
decisions); close only your own, and ask when unsure.
|
|
41
|
+
|
|
42
|
+
Never edit `.whiteboard/events.ndjson` yourself: an answer arriving while you
|
|
43
|
+
write it is lost, and running waits stumble over it. To change what you wrote
|
|
44
|
+
(a chat message, a reply), use `whiteboard edit <event id> --data <json>`: it
|
|
45
|
+
merges into the event's data, keeps its id, and the open page shows the new
|
|
46
|
+
version. To clear a page's history and keep the page, `whiteboard prune
|
|
47
|
+
<file>` (all its events: its questions are open again), with `--type <type>`
|
|
48
|
+
for one kind (`chat:message`) or `--id <event id>` for one. You can edit only
|
|
49
|
+
your own events: what the user sent stays as they sent it.
|
|
35
50
|
|
|
36
51
|
Files that already exist in the repository render too: `whiteboard show
|
|
37
52
|
README.md` (any path in the project) gives a URL that renders that file, and
|
|
@@ -56,8 +71,10 @@ Write for a reader who comes back later:
|
|
|
56
71
|
- A send is a choice, and only that. Questions and remarks about a form go
|
|
57
72
|
in the chat under it (`chat:message` events, see the chat plugin's docs):
|
|
58
73
|
answer them there, and never read a chat message, or a note sent along
|
|
59
|
-
with a submit, as a choice. Don't add a notes field to a
|
|
60
|
-
|
|
74
|
+
with a submit, as a choice. Don't add a notes field to a form; its chat is
|
|
75
|
+
for that. When the user may want an answer you didn't list, add an option
|
|
76
|
+
for it, `:radio[Other]{name=… other}`: it has a text box, and sends what
|
|
77
|
+
they typed.
|
|
61
78
|
- For talk that isn't about a question, put a chat on the page:
|
|
62
79
|
`:::chat{name=…}`, at the end or in a section. It is the same chat as
|
|
63
80
|
under a form, without the question.
|
|
@@ -178,6 +195,15 @@ herdr pane close <id>
|
|
|
178
195
|
- `herdr pane read` returns no text for a pane showing the browser itself,
|
|
179
196
|
since it draws with graphics.
|
|
180
197
|
|
|
198
|
+
### Pointing at a place on the page
|
|
199
|
+
|
|
200
|
+
`whiteboard scroll <file> <where>` scrolls every tab that has the page open
|
|
201
|
+
to a heading (by its text), a form (by its name) or any text on it, opens a
|
|
202
|
+
details around it, and lights it up a moment. Use it when you talk about a
|
|
203
|
+
part of a long page ("see the risks section"), or to bring the user to a
|
|
204
|
+
question you just added. It exits 1 when nothing on the page matches, or when
|
|
205
|
+
no browser has the page open (then `show` it first).
|
|
206
|
+
|
|
181
207
|
## Getting answers
|
|
182
208
|
|
|
183
209
|
Each submit of a named form appends one line to the project's
|
|
@@ -222,9 +248,10 @@ page (`--page plan` also works, and includes the pages below `plan/`).
|
|
|
222
248
|
an answer up after you acted on it.
|
|
223
249
|
|
|
224
250
|
The page shows the user what waits for them: every question without an
|
|
225
|
-
answer is
|
|
226
|
-
haven't read (a reply in a comment thread, a chat message).
|
|
227
|
-
|
|
251
|
+
answer is outlined as waiting for them, and so is a message from you they
|
|
252
|
+
haven't read (a reply in a comment thread, a chat message). Labels in the
|
|
253
|
+
page's corner ("→ unanswered (n)", "→ unread (n)") go from one to the next,
|
|
254
|
+
and the tab title and the header count them. Whether
|
|
228
255
|
your wait runs doesn't change that, so answers given while none runs wait in
|
|
229
256
|
the log for you. So:
|
|
230
257
|
|
|
@@ -250,11 +277,16 @@ that picks them up. Pages are claimed by the session that ran
|
|
|
250
277
|
`whiteboard new` for them, and `status` marks yours. Run it when you resume
|
|
251
278
|
work, or when you're unsure what is still open.
|
|
252
279
|
|
|
280
|
+
When `wait` hands you an answer, it also says (on stderr) what is still
|
|
281
|
+
unanswered on the page, with the command to wait again: run it once you've
|
|
282
|
+
acted on the answer.
|
|
283
|
+
|
|
253
284
|
A project can have Claude Code hooks for this: the Claude Code plugin in
|
|
254
|
-
its config, and `whiteboard claude-code install
|
|
285
|
+
its config, and `whiteboard claude-code install`:
|
|
255
286
|
|
|
256
|
-
- when your turn ends with something on your pages nobody listens for,
|
|
257
|
-
|
|
287
|
+
- when your turn ends with something on your pages nobody listens for, your
|
|
288
|
+
turn goes on once, telling you to start the wait: start it in the
|
|
289
|
+
background and end your turn;
|
|
258
290
|
- when the user sends a message, answers on your pages that no wait picked
|
|
259
291
|
up come with it, and count as picked up from then on;
|
|
260
292
|
- a new session starts with the same, plus what is open on other sessions'
|
|
@@ -288,7 +320,7 @@ git add -N . # new files show in the diff too
|
|
|
288
320
|
git diff HEAD -- "$f"
|
|
289
321
|
printf '````\n:::\n\n'
|
|
290
322
|
done
|
|
291
|
-
printf ':::form{name=review}\n:
|
|
323
|
+
printf ':::form{name=review}\n:button[Approve] :button[Request changes]\n:::\n'
|
|
292
324
|
} > .whiteboard/pages/review.md
|
|
293
325
|
```
|
|
294
326
|
|
package/src/client/forms.ts
CHANGED
|
@@ -35,6 +35,13 @@ const keepsOwnFields = (form: HTMLFormElement) => !!form.closest('[data-wb-self]
|
|
|
35
35
|
|
|
36
36
|
// ---- reading and writing a form ----------------------------------------------------------------
|
|
37
37
|
|
|
38
|
+
// An option for an answer not on the list (`:radio[Other]{name=… other}`): a radio or checkbox
|
|
39
|
+
// marked `data-wb-other`, with a text box (`data-wb-other-text`, no name of its own) in its label.
|
|
40
|
+
// It sends what was typed; typing picks it; an answer that is none of the other options goes back
|
|
41
|
+
// into its box.
|
|
42
|
+
const otherText = (option: HTMLInputElement) => option.closest('label')?.querySelector<HTMLInputElement>('[data-wb-other-text]') ?? null
|
|
43
|
+
const isOther = (el: Element): boolean => el instanceof HTMLInputElement && el.hasAttribute('data-wb-other')
|
|
44
|
+
|
|
38
45
|
function readForm(form: HTMLFormElement): Data {
|
|
39
46
|
const data: Data = {}
|
|
40
47
|
const elements = [...form.elements] as HTMLInputElement[]
|
|
@@ -42,6 +49,7 @@ function readForm(form: HTMLFormElement): Data {
|
|
|
42
49
|
for (const el of elements) if (el.name && el.type === 'checkbox') boxes[el.name] = (boxes[el.name] ?? 0) + 1
|
|
43
50
|
for (const el of elements) {
|
|
44
51
|
if (!el.name || el.type === 'submit' || el.type === 'button' || el.type === 'reset' || el.type === 'file') continue
|
|
52
|
+
if (isOther(el)) el.value = otherText(el)?.value.trim() ?? ''
|
|
45
53
|
if (el.type === 'checkbox') {
|
|
46
54
|
if (boxes[el.name] > 1) { const list = (data[el.name] ??= []) as string[]; if (el.checked) list.push(el.value) }
|
|
47
55
|
else data[el.name] = el.checked
|
|
@@ -56,15 +64,36 @@ function readForm(form: HTMLFormElement): Data {
|
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
function writeForm(form: HTMLFormElement, data: Data) {
|
|
59
|
-
|
|
67
|
+
const elements = [...form.elements] as HTMLInputElement[]
|
|
68
|
+
// what the listed options of a name send, so an answer that is none of them is the other one's
|
|
69
|
+
const listed = (name: string) => elements.filter(e => e.name === name && !isOther(e) && (e.type === 'radio' || e.type === 'checkbox')).map(e => e.value)
|
|
70
|
+
for (const el of elements) {
|
|
60
71
|
if (!el.name || !(el.name in data) || ['submit', 'button', 'hidden', 'file'].includes(el.type)) continue
|
|
61
72
|
const v = data[el.name]
|
|
73
|
+
if (isOther(el)) {
|
|
74
|
+
const own = listed(el.name)
|
|
75
|
+
const rest = (Array.isArray(v) ? v : [v]).filter(x => typeof x === 'string' && x !== '' && !own.includes(x)) as string[]
|
|
76
|
+
el.checked = rest.length > 0
|
|
77
|
+
const text = otherText(el)
|
|
78
|
+
if (text && text !== document.activeElement) text.value = rest.join(', ')
|
|
79
|
+
continue
|
|
80
|
+
}
|
|
62
81
|
if (el.type === 'checkbox') el.checked = Array.isArray(v) ? v.includes(el.value) : !!v
|
|
63
82
|
else if (el.type === 'radio') el.checked = v === el.value
|
|
64
83
|
else el.value = v == null ? '' : String(v)
|
|
65
84
|
}
|
|
66
85
|
}
|
|
67
86
|
|
|
87
|
+
/** Typing in an other-option's box picks it (and an empty box, for a checkbox, unpicks it). */
|
|
88
|
+
function onOtherInput(e: Event) {
|
|
89
|
+
const text = e.target as HTMLInputElement
|
|
90
|
+
if (!text.matches?.('[data-wb-other-text]')) return
|
|
91
|
+
const option = text.closest('label')?.querySelector<HTMLInputElement>('[data-wb-other]')
|
|
92
|
+
if (!option) return
|
|
93
|
+
if (text.value.trim()) option.checked = true
|
|
94
|
+
else if (option.type === 'checkbox') option.checked = false
|
|
95
|
+
}
|
|
96
|
+
|
|
68
97
|
// ---- drafts ------------------------------------------------------------------------------------
|
|
69
98
|
|
|
70
99
|
const draftKey = (form: HTMLFormElement) => `wb-draft:${page}:${form.getAttribute('name')}`
|
|
@@ -167,6 +196,8 @@ export function trackForms(el: HTMLElement, pageId: string, core: Api) {
|
|
|
167
196
|
root = el
|
|
168
197
|
page = pageId
|
|
169
198
|
api = core
|
|
199
|
+
// before the draft is saved: what was typed picks its option
|
|
200
|
+
document.addEventListener('input', onOtherInput)
|
|
170
201
|
document.addEventListener('input', saveDraft)
|
|
171
202
|
document.addEventListener('change', saveDraft)
|
|
172
203
|
document.addEventListener('submit', onSubmit)
|