@bigmistqke/whiteboard 0.6.1 → 0.8.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 (101) hide show
  1. package/README.md +23 -216
  2. package/bin/whiteboard.ts +82 -239
  3. package/dist/bin/whiteboard.js +70 -200
  4. package/dist/client/runtime.js +297 -61
  5. package/dist/plugins/badge/README.md +3 -1
  6. package/dist/plugins/badge/public/style.css +17 -0
  7. package/dist/plugins/chat/public/client.js +2 -2
  8. package/dist/plugins/chat/public/style.css +19 -6
  9. package/dist/plugins/code/README.md +10 -0
  10. package/dist/plugins/code/index.js +31 -22
  11. package/dist/plugins/code/public/client.js +1 -0
  12. package/dist/plugins/code/public/style.css +33 -2
  13. package/dist/plugins/comments/public/client.js +7 -2
  14. package/dist/plugins/comments/public/style.css +4 -0
  15. package/dist/plugins/form/public/style.css +2 -0
  16. package/dist/plugins/grid/public/style.css +0 -5
  17. package/dist/plugins/iframe/index.js +2 -2
  18. package/dist/plugins/index.js +5 -1
  19. package/dist/plugins/lightbox/public/client.js +1 -1
  20. package/dist/plugins/terminal/index.js +7 -9
  21. package/dist/plugins/terminal/public/client.js +1 -1
  22. package/dist/plugins/terminal/public/style.css +3 -3
  23. package/dist/plugins/timeline/README.md +40 -0
  24. package/dist/plugins/timeline/index.js +82 -0
  25. package/dist/plugins/timeline/public/style.css +118 -0
  26. package/dist/plugins/toc/README.md +13 -13
  27. package/dist/plugins/toc/index.js +6 -4
  28. package/dist/plugins/toc/public/client.js +1 -1
  29. package/dist/plugins/toc/public/style.css +19 -2
  30. package/dist/plugins/window/index.js +4 -4
  31. package/dist/solid/index.js +2 -1
  32. package/dist/src/auth.js +7 -3
  33. package/dist/src/build.js +159 -0
  34. package/dist/src/client/page/base.css +74 -35
  35. package/dist/src/client/page/main.js +16 -5
  36. package/dist/src/document.js +93 -0
  37. package/dist/src/events.js +7 -15
  38. package/dist/src/hub.js +90 -53
  39. package/dist/src/listen.js +100 -0
  40. package/dist/src/listeners.js +67 -0
  41. package/dist/src/pages/index.js +1 -1
  42. package/dist/src/pages/markdown.js +23 -11
  43. package/dist/src/pages/render.js +13 -8
  44. package/dist/src/serve.js +2 -0
  45. package/dist/src/server.js +204 -514
  46. package/dist/src/site.js +173 -0
  47. package/dist/src/status.js +63 -1
  48. package/dist/src/ws.js +128 -0
  49. package/package.json +1 -1
  50. package/plugins/README.md +258 -0
  51. package/plugins/badge/README.md +3 -1
  52. package/plugins/badge/public/style.css +17 -0
  53. package/plugins/chat/client.tsx +34 -6
  54. package/plugins/chat/public/style.css +19 -6
  55. package/plugins/code/README.md +10 -0
  56. package/plugins/code/client.ts +73 -0
  57. package/plugins/code/index.ts +38 -26
  58. package/plugins/code/public/style.css +33 -2
  59. package/plugins/comments/client.ts +56 -6
  60. package/plugins/comments/public/style.css +4 -0
  61. package/plugins/form/public/style.css +2 -0
  62. package/plugins/grid/public/style.css +0 -5
  63. package/plugins/iframe/index.ts +2 -2
  64. package/plugins/index.ts +6 -1
  65. package/plugins/lightbox/client.ts +13 -3
  66. package/plugins/terminal/client.ts +10 -2
  67. package/plugins/terminal/index.ts +8 -6
  68. package/plugins/terminal/public/style.css +3 -3
  69. package/plugins/timeline/README.md +40 -0
  70. package/plugins/timeline/index.ts +92 -0
  71. package/plugins/timeline/public/style.css +118 -0
  72. package/plugins/toc/README.md +13 -13
  73. package/plugins/toc/client.ts +58 -32
  74. package/plugins/toc/index.ts +13 -13
  75. package/plugins/toc/public/style.css +19 -2
  76. package/plugins/window/index.ts +4 -4
  77. package/skills/whiteboard/SKILL.md +3 -1
  78. package/solid/index.tsx +3 -0
  79. package/src/auth.ts +7 -2
  80. package/src/build.ts +213 -0
  81. package/src/client/forms.ts +102 -5
  82. package/src/client/page/base.css +74 -35
  83. package/src/client/page/elsewhere.ts +14 -4
  84. package/src/client/page/waiting.ts +10 -5
  85. package/src/client/read.ts +16 -3
  86. package/src/client/runtime.ts +219 -52
  87. package/src/client/toast.ts +36 -6
  88. package/src/define.ts +44 -18
  89. package/src/document.ts +191 -0
  90. package/src/events.ts +18 -17
  91. package/src/hub.ts +102 -56
  92. package/src/listen.ts +125 -0
  93. package/src/listeners.ts +95 -0
  94. package/src/pages/index.ts +1 -1
  95. package/src/pages/markdown.ts +29 -18
  96. package/src/pages/render.ts +13 -8
  97. package/src/serve.ts +2 -0
  98. package/src/server.ts +223 -611
  99. package/src/site.ts +165 -0
  100. package/src/status.ts +100 -0
  101. package/src/ws.ts +155 -0
@@ -17,10 +17,10 @@
17
17
  --wb-term-h: 320px;
18
18
  --wb-term-bar: 34px;
19
19
  }
20
- :root:has(body > #wb-terminal) {
20
+ :root:has(#wb-terminal) {
21
21
  --wb-inset-bottom: var(--wb-term-bar);
22
22
  }
23
- :root:has(body > #wb-terminal[data-state='open']) {
23
+ :root:has(#wb-terminal[data-state='open']) {
24
24
  --wb-inset-bottom: calc(var(--wb-term-bar) + var(--wb-term-h));
25
25
  }
26
26
 
@@ -42,7 +42,7 @@
42
42
  system-ui,
43
43
  sans-serif;
44
44
  }
45
- body:has(> #wb-terminal) {
45
+ body:has(#wb-terminal) {
46
46
  padding-bottom: var(--wb-inset-bottom);
47
47
  }
48
48
 
@@ -0,0 +1,40 @@
1
+ Steps in order down a line, a dot per step: what was done and what it showed.
2
+ Each step has room for full sentences, unlike a diagram's boxes.
3
+
4
+ A heading starts a step, titled by it: the shallowest headings in the block are
5
+ its steps, whatever their level. Deeper headings are the step's own and stay
6
+ headings in its body ("What it does", "Result"). A step's body is any markdown,
7
+ blocks too: a takeaway that should stand out can be a `:::callout` (the
8
+ timeline around it then takes four colons, `::::timeline`). A `---` starts an
9
+ untitled step. A badge ending a step's heading sits at its right. A
10
+ `:when[2026-11-21 10:43]` in a step's heading is when it happened: shown above
11
+ the title, as written.
12
+
13
+ **Sub steps.** A timeline inside a step is that step's sub steps: drawn a level
14
+ in, on a thinner line, and a timeline inside one of those again a level
15
+ further, to any depth. The outer timeline then needs more colons than the inner
16
+ one (`::::timeline` around `:::timeline`). That is also how steps are grouped:
17
+ a step for the group, its steps in a timeline inside it.
18
+
19
+ ````markdown
20
+ ::::timeline[Steps so far]
21
+ ### :when[2026-11-21 10:43] Made a minimal repro :badge[done]
22
+ A chain of 6,400 closures overflows the stack: the crash is the chain, not
23
+ Solid.
24
+
25
+ ### Counted the visits
26
+ 5,150 visits for 100 links: each link walks the whole chain again.
27
+
28
+ :::timeline
29
+ ### With the probe off
30
+ #### What it does
31
+ Runs the same chain with the probe switched off.
32
+
33
+ #### Result
34
+ The same 5,150: the probe isn't what walks it.
35
+
36
+ ### With the cache on
37
+ 100 visits: one per link.
38
+ :::
39
+ ::::
40
+ ````
@@ -0,0 +1,92 @@
1
+ // Timeline: steps in order down a line, a dot per step, each with room for full sentences: what was
2
+ // done and what it showed. The shallowest headings in it are its steps; deeper headings are a
3
+ // step's own. A `:when[…]` in a step's heading is when it happened. A timeline inside a step is
4
+ // that step's sub steps, drawn a level in (style.css). Rendered on the server; no script.
5
+ import fs from 'node:fs'
6
+ import { definePlugin, html, raw, type DirectiveContext, type Plugin } from '@bigmistqke/whiteboard'
7
+ import { builtinPublic } from '../../src/package.ts'
8
+
9
+ type Node = {
10
+ type: string
11
+ name?: string
12
+ value?: string
13
+ depth?: number
14
+ children?: Node[]
15
+ }
16
+
17
+ interface Step {
18
+ title: Node[] | null
19
+ body: Node[]
20
+ }
21
+
22
+ const text = (node: Node): string => node.value ?? (node.children ?? []).map(text).join('')
23
+
24
+ /** A when's text. Its `:59` in `19:59` parses as a directive named `59`: put it back as written. */
25
+ const whenText = (node: Node): string =>
26
+ (node.children ?? [])
27
+ .map(n => (n.type === 'textDirective' ? `:${n.name}${n.children?.length ? `[${text(n)}]` : ''}` : text(n)))
28
+ .join('')
29
+
30
+ /** Takes a `:when[…]` out of a heading: its text, and the heading without it. */
31
+ export function when(title: Node[]): { when: string | null; title: Node[] } {
32
+ const found = title.find(n => n.type === 'textDirective' && n.name === 'when')
33
+ if (!found) return { when: null, title }
34
+ const rest = title.filter(n => n !== found)
35
+ // the space that separated it from the title
36
+ const last = rest[rest.length - 1]
37
+ if (last?.type === 'text' && last.value) last.value = last.value.trimEnd()
38
+ const first = rest[0]
39
+ if (first?.type === 'text' && first.value) first.value = first.value.trimStart()
40
+ return { when: whenText(found).trim(), title: rest }
41
+ }
42
+
43
+ /**
44
+ * Splits the block's content into steps: a heading at the shallowest level in it starts one, titled
45
+ * by it, and so does a `---`, untitled. Deeper headings are part of a step's body. Content before
46
+ * the first heading is an untitled step.
47
+ */
48
+ export function parse(children: Node[]): Step[] {
49
+ const depth = Math.min(...children.filter(n => n.type === 'heading').map(n => n.depth!))
50
+ const steps: Step[] = []
51
+ for (const node of children) {
52
+ if (node.type === 'heading' && node.depth === depth) steps.push({ title: node.children ?? [], body: [] })
53
+ else if (node.type === 'thematicBreak') steps.push({ title: null, body: [] })
54
+ else {
55
+ if (!steps.length) steps.push({ title: null, body: [] })
56
+ steps[steps.length - 1].body.push(node)
57
+ }
58
+ }
59
+ return steps
60
+ }
61
+
62
+ /** A step: when, title and body; a timeline in its body (its sub steps) renders as its own block. */
63
+ async function renderStep(ctx: DirectiveContext, step: Step) {
64
+ const split = step.title ? when(step.title) : { when: null, title: null }
65
+ const title = split.title && (await ctx.toHtml(split.title))
66
+ const body = await ctx.toHtml(step.body)
67
+ return html`<li class="wb-tl-step">
68
+ ${split.when && html`<time class="wb-tl-when">${split.when}</time>`}
69
+ ${title && html`<div class="wb-tl-title" data-wb-title>${raw(title)}</div>`}
70
+ ${body.trim() && html`<div class="wb-tl-body">${raw(body)}</div>`}
71
+ </li>`
72
+ }
73
+
74
+ async function render(ctx: DirectiveContext) {
75
+ const steps = await Promise.all(parse(ctx.children as Node[]).map(step => renderStep(ctx, step)))
76
+ return html`<div class="wb-timeline">
77
+ ${ctx.label && html`<div class="wb-tl-caption">${raw(ctx.label)}</div>`}
78
+ <ol class="wb-tl-steps">
79
+ ${steps}
80
+ </ol>
81
+ </div>`
82
+ }
83
+
84
+ export default function timeline(): Plugin {
85
+ return definePlugin({
86
+ name: 'timeline',
87
+ public: builtinPublic('timeline'),
88
+ style: 'style.css',
89
+ blocks: { timeline: { html: render } },
90
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
91
+ })
92
+ }
@@ -0,0 +1,118 @@
1
+ .wb-timeline {
2
+ margin: 3em 0;
3
+ text-align: left;
4
+ }
5
+ .wb-tl-caption {
6
+ font-family: var(--sans);
7
+ font-size: var(--ui-small);
8
+ color: var(--muted);
9
+ text-transform: uppercase;
10
+ letter-spacing: 0.06em;
11
+ margin-bottom: var(--space-2xl);
12
+ }
13
+ .wb-tl-steps {
14
+ list-style: none;
15
+ margin: 0;
16
+ padding: 0;
17
+ }
18
+
19
+ /* a line down the left, a dot per step */
20
+ .wb-tl-steps {
21
+ position: relative;
22
+ padding-left: 28px;
23
+ }
24
+ .wb-tl-steps::before {
25
+ content: '';
26
+ position: absolute;
27
+ left: 7px;
28
+ top: 6px;
29
+ bottom: 6px;
30
+ width: 2px;
31
+ background: var(--border);
32
+ }
33
+ .wb-tl-step {
34
+ position: relative;
35
+ padding-bottom: var(--space-2xl);
36
+ }
37
+ .wb-tl-step:last-child {
38
+ padding-bottom: 0;
39
+ }
40
+ /* the dot sits on the title's first line; a step without a title has it at its top */
41
+ .wb-tl-step:has(> .wb-tl-title)::before {
42
+ display: none;
43
+ }
44
+ .wb-tl-title {
45
+ position: relative;
46
+ }
47
+ .wb-tl-step::before,
48
+ .wb-tl-title::before {
49
+ content: '';
50
+ position: absolute;
51
+ left: -27px;
52
+ top: 0.45em;
53
+ width: 12px;
54
+ height: 12px;
55
+ border-radius: 50%;
56
+ background: var(--bg);
57
+ border: 2px solid var(--accent);
58
+ box-sizing: border-box;
59
+ }
60
+ .wb-tl-when {
61
+ display: block;
62
+ font-family: var(--mono);
63
+ font-size: var(--ui-tiny);
64
+ color: var(--muted);
65
+ line-height: 1.4;
66
+ }
67
+ /* centred on the title's first line (line-height 1.4: its middle is 0.7em down) */
68
+ .wb-tl-title::before {
69
+ top: calc(0.7em - 6px);
70
+ }
71
+ .wb-tl-title {
72
+ font-weight: 600;
73
+ line-height: 1.4;
74
+ }
75
+ .wb-tl-body {
76
+ font-size: var(--ui-text);
77
+ line-height: 1.6;
78
+ margin-top: var(--space-xs);
79
+ }
80
+ .wb-timeline .wb-tl-body > * {
81
+ margin-top: var(--space-md);
82
+ margin-bottom: 0;
83
+ }
84
+ .wb-timeline .wb-tl-body > :first-child {
85
+ margin-top: 0;
86
+ }
87
+
88
+ /* a timeline inside a step is its sub steps: a level in, a thinner line and smaller rings, the
89
+ same at every depth */
90
+ .wb-tl-body .wb-timeline {
91
+ margin: var(--space-md) 0 0;
92
+ }
93
+ .wb-tl-body .wb-tl-steps {
94
+ padding-left: 20px;
95
+ }
96
+ .wb-tl-body .wb-tl-steps::before {
97
+ left: 4px;
98
+ width: 1px;
99
+ }
100
+ .wb-tl-body .wb-tl-step {
101
+ padding-bottom: var(--space-md);
102
+ }
103
+ .wb-tl-body .wb-tl-step:last-child {
104
+ padding-bottom: 0;
105
+ }
106
+ .wb-tl-body .wb-tl-step::before,
107
+ .wb-tl-body .wb-tl-title::before {
108
+ left: -20px;
109
+ width: 9px;
110
+ height: 9px;
111
+ border-width: 1.5px;
112
+ }
113
+ .wb-tl-body .wb-tl-title::before {
114
+ top: calc(0.7em - 4.5px);
115
+ }
116
+ .wb-tl-body .wb-tl-title {
117
+ font-size: var(--ui-text);
118
+ }
@@ -1,16 +1,11 @@
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
1
+ A table of contents beside the page, from its headings (`##` down to
2
+ `######`), numbered as the page numbers them, each section's subsections on a
3
+ line under it. The section being read is marked, a click
3
4
  goes to a section, and a section with an unanswered question or an unread
4
5
  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
- ```
11
-
12
- A page has it when its frontmatter asks, under `plugins:` (where every
13
- plugin's settings for a page go, by the plugin's name):
6
+ room; else a button in the header opens it. It is built in: a page has it
7
+ when its frontmatter asks, under `plugins:` (where every plugin's settings for
8
+ a page go, by the plugin's name):
14
9
 
15
10
  ```markdown
16
11
  ---
@@ -20,8 +15,13 @@ plugins:
20
15
  # A long page
21
16
  ```
22
17
 
23
- To have it on every page, `toc({ always: true })`; a page then goes without
24
- with `toc: false` there.
18
+ To have it on every page, replace the built-in one in the config; a page then
19
+ goes without with `toc: false` there:
20
+
21
+ ```ts
22
+ import toc from '@bigmistqke/whiteboard/toc'
23
+ export default defineConfig({ plugins: [toc({ always: true })] })
24
+ ```
25
25
 
26
26
  The panel fits its items, between a minimum and a maximum width (160px and
27
27
  320px by default). A project sets its own in the options, and a page in its
@@ -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) => {
@@ -167,19 +190,22 @@ const mount: PluginMount = (root, page, core) => {
167
190
  handle = page
168
191
  main = root.querySelector<HTMLElement>('#wb-main') ?? root
169
192
  api = core
170
- document.body.append(panel)
171
- root.querySelector('.wb-nav .wb-theme')?.before(toggle)
193
+ // the panel beside the text, its button in the header bar
194
+ core.slot('aside', place => {
195
+ place.append(panel)
196
+ return () => panel.remove()
197
+ })
198
+ core.slot('header', place => {
199
+ place.append(toggle)
200
+ return () => toggle.remove()
201
+ })
172
202
  list.addEventListener('click', e => {
173
203
  const a = (e.target as HTMLElement).closest<HTMLElement>('a[data-index]')
174
204
  if (!a) return
175
205
  e.preventDefault()
176
206
  go(Number(a.dataset.index))
177
207
  })
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
- })
208
+ toggle.addEventListener('click', () => setOpen(!panel.classList.contains('wb-toc-open')))
183
209
  document.addEventListener('keydown', e => {
184
210
  if (e.key === 'Escape' && panel.classList.contains('wb-toc-open')) toggle.click()
185
211
  })
@@ -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 {
@@ -42,7 +42,7 @@ export default function toc(options: TocOptions = {}): Plugin {
42
42
  setup: () => ({
43
43
  client: 'client.js',
44
44
  // how the browser part knows: on every page, or only where the frontmatter asks
45
- shell: () => ({
45
+ slots: () => ({
46
46
  head: html`<meta
47
47
  name="wb-toc"
48
48
  content="${options.always ? 'always' : 'opt-in'}"
@@ -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
+ }
@@ -45,12 +45,12 @@ ${kind}: needs a src, like ::${kind}[a label]{src="${kind === 'image' ? 'shot.pn
45
45
  return html`<pre class="wb-error">${kind}: src must be an http(s) URL or a path, not ${src.split(':')[0]}:</pre>`
46
46
  const alt = ctx.labelText ?? ctx.attrs.alt ?? ''
47
47
  const flag = (name: string) => name in ctx.attrs && raw(` ${name}`)
48
- const poster = ctx.attrs.poster && safeSrc(ctx.attrs.poster) ? html` poster="${ctx.attrs.poster}"` : ''
48
+ const poster = ctx.attrs.poster && safeSrc(ctx.attrs.poster) ? html` poster="${ctx.fileUrl(ctx.attrs.poster)}"` : ''
49
49
  const body =
50
50
  kind === 'image'
51
- ? html`<img src="${src}" alt="${alt}" loading="lazy" />`
51
+ ? html`<img src="${ctx.fileUrl(src)}" alt="${alt}" loading="lazy" />`
52
52
  : html`<video
53
- src="${src}"
53
+ src="${ctx.fileUrl(src)}"
54
54
  controls${flag('loop')}${flag('autoplay')}${'autoplay' in ctx.attrs || 'muted' in ctx.attrs ? raw(' muted') : ''}
55
55
  playsinline
56
56
  preload="metadata"
@@ -62,7 +62,7 @@ ${kind}: needs a src, like ::${kind}[a label]{src="${kind === 'image' ? 'shot.pn
62
62
  /** What an image or video shows on its own, for the ↗ of a window around it: its file. */
63
63
  const mediaOpen = (ctx: DirectiveContext) => {
64
64
  const src = (ctx.attrs.src ?? '').trim()
65
- return src && safeSrc(src) ? src : null
65
+ return src && safeSrc(src) ? ctx.fileUrl(src) : null
66
66
  }
67
67
 
68
68
  export async function render(ctx: DirectiveContext) {
@@ -206,7 +206,9 @@ to a heading (by its text), a form (by its name) or any text on it, opens a
206
206
  details around it, and lights it up a moment. Use it when you talk about a
207
207
  part of a long page ("see the risks section"), or to bring the user to a
208
208
  question you just added. It exits 1 when nothing on the page matches, or when
209
- no browser has the page open (then `show` it first).
209
+ no tab of the page is connected now: then a tab that is open still scrolls
210
+ there once it is back (a background tab connects again when it is shown);
211
+ else `show` the page first.
210
212
 
211
213
  ## Getting answers
212
214
 
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