@bigmistqke/whiteboard 0.6.0 → 0.7.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.
Files changed (61) hide show
  1. package/README.md +13 -7
  2. package/dist/bin/whiteboard.js +0 -0
  3. package/dist/client/runtime.js +235 -58
  4. package/dist/plugins/badge/README.md +3 -1
  5. package/dist/plugins/badge/public/style.css +17 -0
  6. package/dist/plugins/chat/public/client.js +2 -2
  7. package/dist/plugins/chat/public/style.css +9 -0
  8. package/dist/plugins/comments/public/client.js +7 -2
  9. package/dist/plugins/comments/public/style.css +4 -0
  10. package/dist/plugins/grid/public/style.css +0 -5
  11. package/dist/plugins/index.js +5 -1
  12. package/dist/plugins/timeline/README.md +40 -0
  13. package/dist/plugins/timeline/index.js +82 -0
  14. package/dist/plugins/timeline/public/style.css +118 -0
  15. package/dist/plugins/toc/README.md +13 -13
  16. package/dist/plugins/toc/index.js +5 -3
  17. package/dist/plugins/toc/public/client.js +1 -1
  18. package/dist/plugins/toc/public/style.css +19 -2
  19. package/dist/solid/index.js +2 -1
  20. package/dist/src/auth.js +7 -3
  21. package/dist/src/client/page/base.css +74 -35
  22. package/dist/src/client/page/main.js +15 -4
  23. package/dist/src/entries.js +9 -3
  24. package/dist/src/events.js +4 -2
  25. package/dist/src/hub.js +43 -18
  26. package/dist/src/serve.js +2 -0
  27. package/dist/src/server.js +49 -11
  28. package/dist/src/ws.js +128 -0
  29. package/package.json +1 -1
  30. package/plugins/badge/README.md +3 -1
  31. package/plugins/badge/public/style.css +17 -0
  32. package/plugins/chat/client.tsx +34 -6
  33. package/plugins/chat/public/style.css +9 -0
  34. package/plugins/comments/client.ts +48 -5
  35. package/plugins/comments/public/style.css +4 -0
  36. package/plugins/grid/public/style.css +0 -5
  37. package/plugins/index.ts +6 -1
  38. package/plugins/timeline/README.md +40 -0
  39. package/plugins/timeline/index.ts +92 -0
  40. package/plugins/timeline/public/style.css +118 -0
  41. package/plugins/toc/README.md +13 -13
  42. package/plugins/toc/client.ts +49 -30
  43. package/plugins/toc/index.ts +12 -12
  44. package/plugins/toc/public/style.css +19 -2
  45. package/skills/whiteboard/SKILL.md +1 -2
  46. package/solid/index.tsx +3 -0
  47. package/src/auth.ts +7 -2
  48. package/src/client/forms.ts +102 -5
  49. package/src/client/page/base.css +74 -35
  50. package/src/client/page/elsewhere.ts +12 -3
  51. package/src/client/page/waiting.ts +10 -5
  52. package/src/client/read.ts +16 -3
  53. package/src/client/runtime.ts +134 -45
  54. package/src/client/toast.ts +35 -5
  55. package/src/define.ts +10 -0
  56. package/src/entries.ts +14 -3
  57. package/src/events.ts +7 -1
  58. package/src/hub.ts +54 -22
  59. package/src/serve.ts +2 -0
  60. package/src/server.ts +73 -17
  61. package/src/ws.ts +155 -0
@@ -1,4 +1,4 @@
1
- // The table of contents (index.ts): built from the page's ## and ### headings, again after each
1
+ // The table of contents (index.ts): built from the page's ## to ###### headings, again after each
2
2
  // update; the section being read is the last heading above the top of the view; a section is
3
3
  // marked when an open question (data-wb-open) or an unread message (data-wb-message, or the element
4
4
  // holding one, data-wb-holds) is in it. A click scrolls to the heading, below the header.
@@ -14,6 +14,7 @@ const toggle = document.createElement('button')
14
14
  toggle.type = 'button'
15
15
  toggle.className = 'wb-toc-toggle'
16
16
  toggle.title = toggle.ariaLabel = 'Contents'
17
+ toggle.setAttribute('aria-expanded', 'false')
17
18
  toggle.innerHTML =
18
19
  '<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>'
19
20
 
@@ -66,6 +67,13 @@ function place() {
66
67
 
67
68
  let handle: PageHandle
68
69
 
70
+ /** Opened from the header (or closed again): the panel shows, and the button says it is open. */
71
+ function setOpen(open: boolean) {
72
+ panel.classList.toggle('wb-toc-open', open)
73
+ panel.hidden = !open
74
+ toggle.setAttribute('aria-expanded', String(open))
75
+ }
76
+
69
77
  /** Does this page have it: what its settings say, and whether it is on everywhere. */
70
78
  function wanted() {
71
79
  // its settings (`plugins: { toc: … }`): true, or { minWidth, maxWidth }: on; false: off; else as
@@ -77,27 +85,45 @@ function wanted() {
77
85
  return always
78
86
  }
79
87
 
88
+ /** A heading's text, without a badge that ends it (a status, not part of the title). */
89
+ function titleOf(h: HTMLElement) {
90
+ const copy = h.cloneNode(true) as HTMLElement
91
+ copy.querySelectorAll('.wb-badge').forEach(b => b.remove())
92
+ return copy.textContent?.trim() ?? ''
93
+ }
94
+
95
+ const SECTIONS = ':scope > :is(h2, h3, h4, h5, h6)'
96
+
97
+ /**
98
+ * The outline as nested lists: a heading's subsections in a list inside its item, which the style
99
+ * hangs on a rail under it. A level skipped (## then ####) nests once, under the nearest above.
100
+ */
80
101
  function build() {
81
- headings = wanted() ? [...main.querySelectorAll<HTMLElement>(':scope > h2, :scope > h3')] : []
82
- let h2 = 0,
83
- h3 = 0
84
- list.replaceChildren(
85
- ...headings.map((h, i) => {
86
- // the page's numbers: 1, 1.1, 1.2, 2 (base.css counts ## and ### alike)
87
- const number = h.tagName === 'H2' ? `${++h2}` : `${h2}.${++h3}`
88
- if (h.tagName === 'H2') h3 = 0
89
- const li = document.createElement('li')
90
- li.dataset.level = h.tagName === 'H2' ? '2' : '3'
91
- const a = document.createElement('a')
92
- a.href = '#'
93
- a.dataset.index = String(i)
94
- a.innerHTML = `<span class="wb-toc-number"></span><span class="wb-toc-text"></span>`
95
- a.querySelector('.wb-toc-number')!.textContent = number
96
- a.querySelector('.wb-toc-text')!.textContent = h.textContent ?? ''
97
- li.append(a)
98
- return li
99
- }),
100
- )
102
+ headings = wanted() ? [...main.querySelectorAll<HTMLElement>(SECTIONS)] : []
103
+ // the page's numbers: 1, 1.1, 1.1.1 (base.css counts ## to ###### alike)
104
+ const counts = [0, 0, 0, 0, 0]
105
+ const open: { level: number; list: HTMLOListElement; item?: HTMLLIElement }[] = [{ level: 1, list }]
106
+ list.replaceChildren()
107
+ headings.forEach((h, i) => {
108
+ const level = Number(h.tagName[1])
109
+ counts[level - 2]++
110
+ counts.fill(0, level - 1)
111
+ while (open.length > 1 && open.at(-1)!.level >= level) open.pop()
112
+ const parent = open.at(-1)!
113
+ if (parent.item && !parent.item.querySelector(':scope > ol')) parent.item.append(document.createElement('ol'))
114
+ const into = parent.item ? parent.item.querySelector<HTMLOListElement>(':scope > ol')! : parent.list
115
+ const li = document.createElement('li')
116
+ li.dataset.level = String(level)
117
+ const a = document.createElement('a')
118
+ a.href = '#'
119
+ a.dataset.index = String(i)
120
+ a.innerHTML = `<span class="wb-toc-number"></span><span class="wb-toc-text"></span>`
121
+ a.querySelector('.wb-toc-number')!.textContent = counts.slice(0, level - 1).join('.')
122
+ a.querySelector('.wb-toc-text')!.textContent = titleOf(h)
123
+ li.append(a)
124
+ into.append(li)
125
+ open.push({ level, list: into, item: li })
126
+ })
101
127
  const any = headings.length > 1
102
128
  bounds()
103
129
  place()
@@ -156,10 +182,7 @@ function go(i: number) {
156
182
  const h = headings[i]
157
183
  if (!h) return
158
184
  scrollTo({ top: Math.max(0, scrollY + h.getBoundingClientRect().top - navHeight() - 12), behavior: 'smooth' })
159
- if (!fits()) {
160
- panel.classList.remove('wb-toc-open')
161
- panel.hidden = true
162
- }
185
+ if (!fits()) setOpen(false)
163
186
  }
164
187
 
165
188
  const mount: PluginMount = (root, page, core) => {
@@ -175,11 +198,7 @@ const mount: PluginMount = (root, page, core) => {
175
198
  e.preventDefault()
176
199
  go(Number(a.dataset.index))
177
200
  })
178
- toggle.addEventListener('click', () => {
179
- const open = !panel.classList.contains('wb-toc-open')
180
- panel.classList.toggle('wb-toc-open', open)
181
- panel.hidden = !open
182
- })
201
+ toggle.addEventListener('click', () => setOpen(!panel.classList.contains('wb-toc-open')))
183
202
  document.addEventListener('keydown', e => {
184
203
  if (e.key === 'Escape' && panel.classList.contains('wb-toc-open')) toggle.click()
185
204
  })
@@ -1,22 +1,22 @@
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:
1
+ // A table of contents beside the page: its sections (## to ###### headings), numbered as the page
2
+ // numbers them, each one's subsections on a rail under it, the one being read marked, a dot where
3
+ // something waits for the reader (an unanswered question, an unread message). In the margin left
4
+ // of the text when the window has room for it; else a button in the header that opens it.
5
5
  //
6
- // import toc from '@bigmistqke/whiteboard/toc'
7
- // export default defineConfig({ plugins: [toc()] })
8
- //
9
- // A page has it when its frontmatter says so, under `plugins:` (`plugins: { toc: true }`). With
10
- // `toc({ always: true })`, every page has it, unless its frontmatter says `toc: false` there.
6
+ // Built in (plugins/index.ts): a page has it when its frontmatter says so, under `plugins:`
7
+ // (`plugins: { toc: true }`). A config that replaces it with `toc({ always: true })` puts it on
8
+ // every page, unless a page's frontmatter says `toc: false` there.
11
9
  import { builtinPublic } from '../../src/package.ts'
12
10
  import { html } from '../../src/html.ts'
13
11
  import type { Plugin } from '../../src/define.ts'
14
12
 
15
13
  const DOCS = `## Table of contents
16
14
 
17
- Pages here have a table of contents beside them, made from their \`##\` and
18
- \`###\` headings: give a long page headings, and the reader can find their way
19
- in it. A section with an unanswered question or an unread message has a dot.
15
+ Pages here have a table of contents beside them, made from their headings,
16
+ \`##\` down to \`######\`: give a long page headings, and the reader can find
17
+ their way in it. Each section's subsections hang on a line under it, so the
18
+ nesting shows. A section with an unanswered question or an unread message has
19
+ a dot.
20
20
  `
21
21
 
22
22
  export interface TocOptions {
@@ -38,8 +38,19 @@
38
38
  margin: 0;
39
39
  padding: 0;
40
40
  }
41
- .wb-toc li[data-level='3'] {
42
- padding-left: var(--space-xl);
41
+ /* the same space above every item, also the first of a nested list (the page's li + li alone
42
+ would leave that one tight against its section) */
43
+ .wb-toc li {
44
+ margin-top: 0.8em;
45
+ }
46
+ .wb-toc > ol > li:first-child {
47
+ margin-top: 0;
48
+ }
49
+ /* a section's subsections hang on a rail under its number, one rail per level */
50
+ .wb-toc ol ol {
51
+ margin-left: var(--space-md);
52
+ padding-left: var(--space-sm);
53
+ border-left: var(--hairline) solid var(--border, #e3e5e9);
43
54
  }
44
55
  .wb-toc a {
45
56
  display: flex;
@@ -97,3 +108,9 @@
97
108
  color: var(--text, CanvasText);
98
109
  border-color: var(--muted, #696e76);
99
110
  }
111
+ /* the panel is open from it */
112
+ .wb-toc-toggle[aria-expanded='true'] {
113
+ color: var(--accent, #1d5bbf);
114
+ border-color: var(--accent, #1d5bbf);
115
+ background: color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-faint), transparent);
116
+ }
@@ -34,8 +34,7 @@ PATH, the project has it installed locally: run them as `npx whiteboard …`.
34
34
  prints the URL. Give the user the URL the first time; after that, just
35
35
  keep editing the file — the open page follows. When the project is served
36
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
37
+ starts nothing: tell the user, don't try to start it yourself (it is started outside your sandbox). Should a command say it `cannot read` whiteboard's config, your sandbox lacks a grant for it: tell the user, rather than working around it. A `wait` meanwhile still works: it waits
39
38
  for the server, and answers in the log reach it either way.
40
39
  5. A page that was only for the moment (one question, a check, a demo):
41
40
  once it has done its job and you've acted on its answers, close it with
package/solid/index.tsx CHANGED
@@ -30,6 +30,8 @@ export interface Whiteboard {
30
30
  unread(): WbEvent[]
31
31
  /** a message's markdown as HTML, rendered by the server (see Api.markdown) */
32
32
  markdown: ClientApi['markdown']
33
+ /** a short note in the page's corner (see Api.toast) */
34
+ toast: ClientApi['toast']
33
35
  }
34
36
 
35
37
  const WhiteboardContext = createContext<Whiteboard>()
@@ -64,6 +66,7 @@ export function solid<Props extends object>(Component: Component<Props>): Mount<
64
66
  forms,
65
67
  unread,
66
68
  markdown: api.markdown,
69
+ toast: api.toast,
67
70
  }
68
71
  return (
69
72
  <WhiteboardContext value={value}>
package/src/auth.ts CHANGED
@@ -32,6 +32,12 @@ export function projectToken(wb: string): string {
32
32
  return token
33
33
  }
34
34
 
35
+ /** From a page of a whiteboard server on this machine, or from no page at all (the command line)? */
36
+ export const sameSite = (req: IncomingMessage): boolean => {
37
+ const origin = req.headers.origin
38
+ return !origin || /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)
39
+ }
40
+
35
41
  /** `base`: the path the project is served under (see ServerOptions), which its cookie is kept to. */
36
42
  export function createAuth(wb: string, base = '') {
37
43
  const token = projectToken(wb)
@@ -51,8 +57,7 @@ export function createAuth(wb: string, base = '') {
51
57
  const jar = cookies(req)
52
58
  const has = same(jar[COOKIE], token) || same(req.headers['x-whiteboard-token'], token)
53
59
  if (!has) return false
54
- const origin = req.headers.origin
55
- if (origin && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)) return false
60
+ if (!sameSite(req)) return false
56
61
  const site = req.headers['sec-fetch-site']
57
62
  if (site && site !== 'same-origin' && site !== 'none' && !opensPage(req)) return false
58
63
  return true
@@ -4,7 +4,8 @@
4
4
  // every page.
5
5
  //
6
6
  // What the core does with such a form, without drawing anything:
7
- // - sends a submit as an event, and says how that went: `data-wb-state` is sending, sent or failed;
7
+ // - sends a submit as an event, shown at once (optimistic), and says how that went: `data-wb-state`
8
+ // is sending (shown, not yet confirmed), sent or failed (taken back);
8
9
  // - keeps what the reader typed until it is sent (localStorage, per page and form), across
9
10
  // re-renders and reloads;
10
11
  // - puts the last answer back into the form, and its button in `data-wb-sent`;
@@ -152,34 +153,129 @@ function restoreLast(prefill: boolean) {
152
153
  }
153
154
  }
154
155
 
156
+ /** What each form is sending now, as sent: the same answer again is not sent twice. */
157
+ const inFlight = new WeakMap<HTMLFormElement, string>()
158
+
159
+ // The button that sent it says how that goes, in its own text and colour (`data-wb-send` on it):
160
+ // "Sending…" (grey) while on its way, "✓ Sent" (green) a moment once the server has it, then its own
161
+ // label again; "Try again" (red) when no try got through, until it is pressed. It keeps its width
162
+ // meanwhile.
163
+ type Send = 'sending' | 'sent' | 'failed'
164
+ /** A button's own label, while it says how a send goes. */
165
+ const labelOf = (button: HTMLButtonElement) => {
166
+ const el = document.createElement('div')
167
+ el.innerHTML = labels.get(button)!.html
168
+ return el.textContent?.trim() ?? ''
169
+ }
170
+ const SEND_TEXT: Record<Send, string> = { sending: 'Sending…', sent: '✓ Sent', failed: 'Try again' }
171
+ const labels = new WeakMap<HTMLButtonElement, { html: string; timer?: ReturnType<typeof setTimeout> }>()
172
+
173
+ function sendState(button: HTMLButtonElement | null, state: Send | null) {
174
+ if (!button) return
175
+ let saved = labels.get(button)
176
+ clearTimeout(saved?.timer)
177
+ if (!state) {
178
+ if (!saved) return
179
+ button.innerHTML = saved.html
180
+ button.style.minWidth = ''
181
+ delete button.dataset.wbSend
182
+ labels.delete(button)
183
+ return
184
+ }
185
+ if (!saved) {
186
+ saved = { html: button.innerHTML }
187
+ labels.set(button, saved)
188
+ button.style.minWidth = `${button.getBoundingClientRect().width}px`
189
+ }
190
+ button.dataset.wbSend = state
191
+ button.textContent = SEND_TEXT[state]
192
+ // confirmed: said for a moment, then the button is itself again
193
+ if (state === 'sent') saved.timer = setTimeout(() => sendState(button, null), 2000)
194
+ }
195
+
196
+ // Optimistic: the answer is the form's at once (api.append puts it in the events, so the form is
197
+ // marked pending), with `data-wb-state="sending"` saying it is still on its way, and its button
198
+ // saying so (sendState); `sent` once the server has it, with the short `data-wb-just-sent` to
199
+ // confirm it. Should it not get through, the answer leaves the form again: `failed`, the button
200
+ // the form had before, the draft kept.
155
201
  async function onSubmit(e: SubmitEvent) {
156
202
  const form = e.target as HTMLFormElement
157
203
  if (!managed(form) || !root.contains(form)) return
158
204
  e.preventDefault()
159
205
  const button = e.submitter as HTMLButtonElement | null
160
- const action = button ? button.value || button.textContent?.trim() || null : null
206
+ // its label as it is, not as it says how a send goes
207
+ const label = button ? (labels.get(button) ? labelOf(button) : button.textContent?.trim()) : null
208
+ const action = button ? button.value || label || null : null
209
+ const data = readForm(form)
210
+ const sent = JSON.stringify([action, data])
211
+ if (inFlight.get(form) === sent) return
212
+ inFlight.set(form, sent)
213
+ const before = form.dataset.wbSent
161
214
  form.dataset.wbState = 'sending'
215
+ form.dataset.wbSent = action ?? ''
216
+ form.removeAttribute('data-wb-just-sent')
217
+ sendState(button, 'sending')
218
+ showStatus(form)
162
219
  try {
163
- await api.append(form.getAttribute('name')!, readForm(form), action)
220
+ await api.append(form.getAttribute('name')!, data, action)
221
+ if (inFlight.get(form) !== sent) return // a newer answer took its place
164
222
  dropDraft(form)
165
223
  form.dataset.wbState = 'sent'
166
- form.dataset.wbSent = action ?? ''
224
+ sendState(button, 'sent')
167
225
  // for the page to confirm the send: set for a few seconds after it, also once the form
168
226
  // folds because an agent picked the answer up at once
169
227
  form.toggleAttribute('data-wb-just-sent', true)
170
228
  clearTimeout(justSent.get(form))
171
229
  justSent.set(
172
230
  form,
173
- setTimeout(() => form.removeAttribute('data-wb-just-sent'), 3000),
231
+ setTimeout(() => {
232
+ form.removeAttribute('data-wb-just-sent')
233
+ showStatus(form)
234
+ }, 3000),
174
235
  )
236
+ showStatus(form)
175
237
  } catch (err) {
238
+ if (inFlight.get(form) !== sent) return
176
239
  form.dataset.wbState = 'failed'
240
+ sendState(button, 'failed')
241
+ if (before == null) delete form.dataset.wbSent
242
+ else form.dataset.wbSent = before
243
+ showStatus(form)
177
244
  console.error(err)
245
+ } finally {
246
+ if (inFlight.get(form) === sent) inFlight.delete(form)
178
247
  }
179
248
  }
180
249
 
181
250
  // ---- where each form stands --------------------------------------------------------------------
182
251
 
252
+ // What a sent answer came to, said beside the form's last send button, where the eye is when it is
253
+ // pressed (a line over the form was out of view below a long list of options): `.wb-form-status`,
254
+ // "waiting for the agent to pick it up", or `data-kind="bad"` "couldn't send it". Never what the
255
+ // button says already (sendState): nothing while sending, no "sent".
256
+ const sendButtons = (form: HTMLFormElement) =>
257
+ [...form.querySelectorAll<HTMLButtonElement | HTMLInputElement>('button, input[type=submit]')].filter(
258
+ b => (b instanceof HTMLInputElement || (b.type !== 'button' && b.type !== 'reset')) && b.form === form,
259
+ )
260
+
261
+ function showStatus(form: HTMLFormElement) {
262
+ const text =
263
+ form.dataset.wbState === 'failed'
264
+ ? (["couldn't send it", 'bad'] as const)
265
+ : form.dataset.wbState === 'sending' || !form.hasAttribute('data-wb-pending')
266
+ ? null
267
+ : (['waiting for the agent to pick it up', null] as const)
268
+ let el = form.querySelector<HTMLElement>('.wb-form-status')
269
+ const last = sendButtons(form).at(-1)
270
+ if (!text || !last) return void el?.remove()
271
+ if (!el) el = Object.assign(document.createElement('span'), { className: 'wb-form-status' })
272
+ el.setAttribute('role', 'status')
273
+ if (el.previousElementSibling !== last) last.after(el)
274
+ el.textContent = text[0]
275
+ if (text[1]) el.dataset.kind = text[1]
276
+ else delete el.dataset.kind
277
+ }
278
+
183
279
  const ATTR: Record<FormState, string> = { open: 'data-wb-open', pending: 'data-wb-pending', decided: 'data-wb-decided' }
184
280
 
185
281
  /** One line quoting an answer: what was chosen, then what was written. */
@@ -225,6 +321,7 @@ function mark() {
225
321
  for (const st of STATES) form.toggleAttribute(ATTR[st], st === state)
226
322
  if (state === 'decided') form.dataset.wbOutcome = outcome(last!.data, last!.action)
227
323
  else delete form.dataset.wbOutcome
324
+ showStatus(form)
228
325
  return { form, name, state, last }
229
326
  })
230
327
  forms_.notify()
@@ -19,6 +19,10 @@
19
19
  --warn: light-dark(#6b4fc0, #b4a0ff);
20
20
  --bad: light-dark(#c4352b, #ff6f66);
21
21
  --info: light-dark(#1d5bbf, #82aaff);
22
+ /* what the reader sent, shown at once but not yet confirmed by the server (an event with
23
+ `sending`): grey, in whatever carries it (a button, a bubble, a comment's text). Confirmed, it
24
+ takes its usual colour (a button flashes --ok first); never got there, --bad */
25
+ --wb-sending: light-dark(#9a9fa7, #6c717a);
22
26
  --shadow: none;
23
27
 
24
28
  /* Type. The article is set in --serif at --text-size; everything in it (its margins, its
@@ -302,7 +306,7 @@ hr::after {
302
306
  letter-spacing: 0.3em;
303
307
  }
304
308
 
305
- /* section numbers hanging in the margin: 1, 1.1, 1.1.1, in italic oldstyle figures. Only the
309
+ /* section numbers hanging in the margin: 1, 1.1, 1.1.1, down to h6, in italic oldstyle figures. Only the
306
310
  page's own headings (direct children of main), so headings inside cards stay unnumbered. The
307
311
  number is an inline-block pulled into the margin, so it shares the heading's baseline. */
308
312
  #wb-main {
@@ -318,8 +322,16 @@ hr::after {
318
322
  }
319
323
  #wb-main > h4 {
320
324
  counter-increment: h4;
325
+ counter-reset: h5;
321
326
  }
322
- #wb-main > :is(h2, h3, h4)::before {
327
+ #wb-main > h5 {
328
+ counter-increment: h5;
329
+ counter-reset: h6;
330
+ }
331
+ #wb-main > h6 {
332
+ counter-increment: h6;
333
+ }
334
+ #wb-main > :is(h2, h3, h4, h5, h6)::before {
323
335
  display: inline-block;
324
336
  box-sizing: content-box;
325
337
  width: 64px;
@@ -347,12 +359,18 @@ hr::after {
347
359
  content: counter(h2) '.' counter(h3) '.' counter(h4);
348
360
  font-size: 1.3em;
349
361
  }
362
+ #wb-main > h5::before {
363
+ content: counter(h2) '.' counter(h3) '.' counter(h4) '.' counter(h5);
364
+ }
365
+ #wb-main > h6::before {
366
+ content: counter(h2) '.' counter(h3) '.' counter(h4) '.' counter(h5) '.' counter(h6);
367
+ }
350
368
  /* no margin to hang them in: set the number in front of the heading, and indent less */
351
369
  @media (max-width: 860px) {
352
370
  main {
353
371
  --indent: 0px;
354
372
  }
355
- #wb-main > :is(h2, h3, h4)::before {
373
+ #wb-main > :is(h2, h3, h4, h5, h6)::before {
356
374
  width: auto;
357
375
  margin-left: 0;
358
376
  margin-right: 0.6em;
@@ -682,14 +700,32 @@ form.wb-form[data-wb-folded] {
682
700
  gap: 0;
683
701
  }
684
702
  /* named forms: the core marks where each stands (data-wb-open, -pending, -decided); this is how that looks */
685
- form[data-wb-state='sending'] {
686
- opacity: 0.7;
687
- }
688
- /* sending: the form's buttons can't send twice */
689
- form[data-wb-state='sending'] button {
690
- pointer-events: none;
703
+ /* the button a form was sent with says how that goes (forms.ts): the answer is the form's already
704
+ (optimistic), the button grey while the server hasn't confirmed it, green a moment once it has,
705
+ red ("Try again") when it never got there. The form stays usable: the same answer isn't sent twice. !important: a send's
706
+ state outranks however a plugin or the project styles its buttons (.wb-primary) */
707
+ form button[data-wb-send] {
708
+ transition:
709
+ background-color 0.2s,
710
+ border-color 0.2s,
711
+ color 0.2s;
712
+ }
713
+ form button[data-wb-send='sending'] {
714
+ background: var(--wb-sending) !important;
715
+ border-color: var(--wb-sending) !important;
716
+ color: var(--bg) !important;
691
717
  cursor: progress;
692
718
  }
719
+ form button[data-wb-send='sent'] {
720
+ background: var(--ok) !important;
721
+ border-color: var(--ok) !important;
722
+ color: var(--bg) !important;
723
+ }
724
+ form button[data-wb-send='failed'] {
725
+ background: var(--bad) !important;
726
+ border-color: var(--bad) !important;
727
+ color: var(--bg) !important;
728
+ }
693
729
  /* just sent: a short green flash, and a line saying what happened, for a few seconds */
694
730
  @keyframes wb-sent {
695
731
  from {
@@ -702,23 +738,16 @@ form[data-wb-state='sending'] button {
702
738
  form[data-wb-just-sent] {
703
739
  animation: wb-sent 1.4s ease-out;
704
740
  }
705
- form.wb-form[data-wb-state='failed']::before {
706
- content: "couldn't send it: try again";
707
- display: block;
708
- margin-bottom: var(--space-md);
709
- color: var(--bad);
710
- font: var(--weight-strong) var(--ui-tiny)/var(--ui-line-height) var(--sans);
711
- }
712
- form[data-wb-sent]:not(.wb-form)::after {
713
- content: '✓ sent ' attr(data-wb-sent);
714
- display: block;
715
- margin-top: var(--space-sm);
716
- color: var(--ok);
717
- font: var(--ui-small) var(--sans);
741
+ /* what a sent answer came to, beside the form's last send button (forms.ts): waiting for the agent
742
+ (muted), couldn't send (red) */
743
+ .wb-form-status {
744
+ margin-left: var(--space-md);
745
+ color: var(--muted);
746
+ font: var(--ui-tiny)/var(--ui-line-height) var(--sans);
718
747
  }
719
- form[data-wb-state='failed']:not(.wb-form)::after {
720
- content: 'failed to send';
748
+ .wb-form-status[data-kind='bad'] {
721
749
  color: var(--bad);
750
+ font-weight: var(--weight-strong);
722
751
  }
723
752
 
724
753
  /* a question the reader hasn't answered, or one the agent asks again: outlined, without a label of
@@ -730,21 +759,25 @@ form[data-wb-open] {
730
759
  }
731
760
  /* the outline sets it off: the form's rules above and below (its borders, which the outline would
732
761
  enclose) step aside meanwhile */
733
- form.wb-form[data-wb-open] {
762
+ form.wb-form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
734
763
  border-top-color: transparent;
735
764
  border-bottom-color: transparent;
736
765
  }
737
- form[data-wb-pending]::before {
738
- content: 'sent · waiting for the agent to pick it up';
739
- display: block;
740
- margin-bottom: var(--space-md);
741
- color: var(--muted);
742
- font: var(--ui-tiny)/var(--ui-line-height) var(--sans);
766
+ /* the outline speaks the language of a send too: grey while the answer is on its way (it is the
767
+ form's already, so no longer outlined as unanswered) and while it waits for the agent to pick it
768
+ up, red when it never got there; gone once the agent took it (decided) */
769
+ form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
770
+ transition: outline-color 0.2s;
743
771
  }
744
- form[data-wb-pending][data-wb-just-sent]::before {
745
- content: '✓ sent · waiting for the agent to pick it up';
746
- color: var(--ok);
747
- font-weight: var(--weight-strong);
772
+ form:is([data-wb-state='sending'], [data-wb-pending]) {
773
+ outline: 2px solid var(--wb-sending);
774
+ outline-offset: 10px;
775
+ border-radius: var(--radius-sm);
776
+ }
777
+ form[data-wb-state='failed'] {
778
+ outline: 2px solid var(--bad);
779
+ outline-offset: 10px;
780
+ border-radius: var(--radius-sm);
748
781
  }
749
782
 
750
783
  /* decided: the agent picked up the latest answer; the form folds into one line quoting it */
@@ -1236,3 +1269,9 @@ main:has(+ .wb-orphans:not([hidden])) {
1236
1269
  :root[data-wb-window-maximized] {
1237
1270
  overflow: hidden;
1238
1271
  }
1272
+ @media (prefers-reduced-motion: reduce) {
1273
+ form button[data-wb-send],
1274
+ form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
1275
+ transition: none;
1276
+ }
1277
+ }
@@ -110,12 +110,20 @@ async function load() {
110
110
  )
111
111
  }
112
112
 
113
- // several changes at once (an answer is an event and a listener less) load once
113
+ // several changes at once (an answer is an event and a listener less) load once; a hidden tab
114
+ // loads once it is shown, and not before (the index asks every project of the server)
114
115
  let timer = 0
116
+ let stale = false
115
117
  const reload = () => {
116
118
  clearTimeout(timer)
119
+ if (document.hidden) return void (stale = true)
117
120
  timer = window.setTimeout(load, 100)
118
121
  }
122
+ document.addEventListener('visibilitychange', () => {
123
+ if (document.hidden || !stale) return
124
+ stale = false
125
+ reload()
126
+ })
119
127
 
120
128
  export function trackElsewhere(root: HTMLElement, handle: PageHandle, core: Api) {
121
129
  current = handle.id
@@ -138,6 +146,7 @@ export function trackElsewhere(root: HTMLElement, handle: PageHandle, core: Api)
138
146
  core.listeners.on(reload)
139
147
  handle.onChange(reload)
140
148
  load()
141
- // other projects' pages change without this page hearing of it: look again now and then
142
- if (base) setInterval(reload, 5000)
149
+ // another project's pages, log or listeners changed: the shared server says so on the live
150
+ // channel (and the channel opening again may have missed some)
151
+ if (base) document.addEventListener('wb-elsewhere', reload)
143
152
  }
@@ -280,12 +280,17 @@ export function trackWaiting(root: HTMLElement, core: Api) {
280
280
  if (form.dataset.wbState === 'sending') return
281
281
  sent.disconnect()
282
282
  if (form.dataset.wbState !== 'sent') return
283
- if (fallback) api.toast('Sent. No agent waits on this page; the fallback agent picks it up.', { name: 'sent' })
283
+ if (fallback)
284
+ api.toast('Sent · to the fallback agent', {
285
+ name: 'sent',
286
+ details: 'No agent waits on this page, so the fallback agent picks it up.',
287
+ })
284
288
  else
285
- api.toast(
286
- 'Sent, but no agent is listening right now. Your answer stays in the log until one checks this page.',
287
- { kind: 'warn', name: 'sent' },
288
- )
289
+ api.toast('Sent · no agent listening', {
290
+ kind: 'warn',
291
+ name: 'sent',
292
+ details: 'Your answer stays in the log until an agent checks this page.',
293
+ })
289
294
  })
290
295
  sent.observe(form, { attributes: true, attributeFilter: ['data-wb-state'] })
291
296
  })