@bigmistqke/whiteboard 0.0.0-stage → 0.2.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 (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +628 -2
  3. package/bin/whiteboard.ts +488 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.156.0/helpers/esm/taggedTemplateLiteral.js +5 -0
  5. package/dist/bin/whiteboard.js +542 -0
  6. package/dist/client/runtime.js +544 -0
  7. package/dist/define.js +7 -0
  8. package/dist/plugins/callout/README.md +13 -0
  9. package/dist/plugins/callout/index.js +27 -0
  10. package/dist/plugins/callout/style.css +12 -0
  11. package/dist/plugins/chat/README.md +46 -0
  12. package/dist/plugins/chat/client.js +3 -0
  13. package/dist/plugins/chat/index.js +47 -0
  14. package/dist/plugins/chat/style.css +24 -0
  15. package/dist/plugins/claude-code/index.js +120 -0
  16. package/dist/plugins/code/README.md +42 -0
  17. package/dist/plugins/code/diff.js +65 -0
  18. package/dist/plugins/code/index.js +77 -0
  19. package/dist/plugins/code/style.css +29 -0
  20. package/dist/plugins/comments/client.js +10 -0
  21. package/dist/plugins/comments/index.js +54 -0
  22. package/dist/plugins/comments/style.css +40 -0
  23. package/dist/plugins/details/README.md +17 -0
  24. package/dist/plugins/details/index.js +17 -0
  25. package/dist/plugins/details/style.css +3 -0
  26. package/dist/plugins/forge/README.md +12 -0
  27. package/dist/plugins/forge/index.js +83 -0
  28. package/dist/plugins/form/README.md +111 -0
  29. package/dist/plugins/form/index.js +102 -0
  30. package/dist/plugins/form/style.css +41 -0
  31. package/dist/plugins/gallery/README.md +30 -0
  32. package/dist/plugins/gallery/client.js +1 -0
  33. package/dist/plugins/gallery/index.js +74 -0
  34. package/dist/plugins/gallery/style.css +27 -0
  35. package/dist/plugins/grid/README.md +33 -0
  36. package/dist/plugins/grid/index.js +33 -0
  37. package/dist/plugins/grid/style.css +25 -0
  38. package/dist/plugins/iframe/README.md +18 -0
  39. package/dist/plugins/iframe/client.js +1 -0
  40. package/dist/plugins/iframe/index.js +40 -0
  41. package/dist/plugins/iframe/style.css +29 -0
  42. package/dist/plugins/index.js +30 -0
  43. package/dist/plugins/mermaid/README.md +21 -0
  44. package/dist/plugins/mermaid/index.js +35 -0
  45. package/dist/plugins/mermaid/style.css +16 -0
  46. package/dist/plugins/quiet/README.md +26 -0
  47. package/dist/plugins/quiet/index.js +17 -0
  48. package/dist/plugins/terminal/client.js +41 -0
  49. package/dist/plugins/terminal/host.js +332 -0
  50. package/dist/plugins/terminal/index.js +171 -0
  51. package/dist/plugins/terminal/modes.js +32 -0
  52. package/dist/plugins/terminal/server.js +256 -0
  53. package/dist/plugins/terminal/sizes.js +57 -0
  54. package/dist/plugins/terminal/style.css +357 -0
  55. package/dist/solid/index.js +36 -0
  56. package/dist/src/auth.js +54 -0
  57. package/dist/src/client/page/base.css +295 -0
  58. package/dist/src/client/page/main.js +1228 -0
  59. package/dist/src/config.js +76 -0
  60. package/dist/src/events.js +183 -0
  61. package/dist/src/html.js +34 -0
  62. package/dist/src/icons.js +6 -0
  63. package/dist/src/load.js +77 -0
  64. package/dist/src/loader.js +126 -0
  65. package/dist/src/package.js +33 -0
  66. package/dist/src/pages/blocks.js +50 -0
  67. package/dist/src/pages/index.js +15 -0
  68. package/dist/src/pages/markdown.js +410 -0
  69. package/dist/src/pages/render.js +311 -0
  70. package/dist/src/plugins.js +238 -0
  71. package/dist/src/running.js +24 -0
  72. package/dist/src/serve.js +71 -0
  73. package/dist/src/server.js +725 -0
  74. package/dist/src/status.js +71 -0
  75. package/package.json +131 -4
  76. package/plugins/callout/README.md +13 -0
  77. package/plugins/callout/index.ts +25 -0
  78. package/plugins/callout/style.css +12 -0
  79. package/plugins/chat/README.md +46 -0
  80. package/plugins/chat/autosize.ts +101 -0
  81. package/plugins/chat/client.tsx +93 -0
  82. package/plugins/chat/index.ts +61 -0
  83. package/plugins/chat/style.css +24 -0
  84. package/plugins/claude-code/index.ts +136 -0
  85. package/plugins/code/README.md +42 -0
  86. package/plugins/code/diff.ts +64 -0
  87. package/plugins/code/index.ts +94 -0
  88. package/plugins/code/style.css +29 -0
  89. package/plugins/comments/client.ts +492 -0
  90. package/plugins/comments/index.ts +54 -0
  91. package/plugins/comments/style.css +40 -0
  92. package/plugins/details/README.md +17 -0
  93. package/plugins/details/index.ts +21 -0
  94. package/plugins/details/style.css +3 -0
  95. package/plugins/forge/README.md +12 -0
  96. package/plugins/forge/index.ts +71 -0
  97. package/plugins/form/README.md +111 -0
  98. package/plugins/form/index.ts +104 -0
  99. package/plugins/form/style.css +41 -0
  100. package/plugins/gallery/README.md +30 -0
  101. package/plugins/gallery/client.tsx +64 -0
  102. package/plugins/gallery/index.ts +67 -0
  103. package/plugins/gallery/style.css +27 -0
  104. package/plugins/grid/README.md +33 -0
  105. package/plugins/grid/index.ts +36 -0
  106. package/plugins/grid/style.css +25 -0
  107. package/plugins/iframe/README.md +18 -0
  108. package/plugins/iframe/client.ts +46 -0
  109. package/plugins/iframe/index.ts +54 -0
  110. package/plugins/iframe/style.css +29 -0
  111. package/plugins/index.ts +21 -0
  112. package/plugins/mermaid/README.md +21 -0
  113. package/plugins/mermaid/index.ts +40 -0
  114. package/plugins/mermaid/style.css +16 -0
  115. package/plugins/quiet/README.md +26 -0
  116. package/plugins/quiet/index.ts +27 -0
  117. package/plugins/terminal/client.ts +317 -0
  118. package/plugins/terminal/host.ts +326 -0
  119. package/plugins/terminal/index.ts +138 -0
  120. package/plugins/terminal/modes.ts +30 -0
  121. package/plugins/terminal/server.ts +215 -0
  122. package/plugins/terminal/sizes.ts +60 -0
  123. package/plugins/terminal/style.css +71 -0
  124. package/skills/whiteboard/SKILL.md +302 -0
  125. package/solid/index.tsx +59 -0
  126. package/src/auth.ts +66 -0
  127. package/src/client/forms.ts +185 -0
  128. package/src/client/markdown.ts +36 -0
  129. package/src/client/page/base.css +295 -0
  130. package/src/client/page/elsewhere.ts +70 -0
  131. package/src/client/page/fresh.ts +205 -0
  132. package/src/client/page/live.ts +30 -0
  133. package/src/client/page/main.ts +272 -0
  134. package/src/client/page/orphans.ts +46 -0
  135. package/src/client/page/sort.ts +38 -0
  136. package/src/client/page/theme.ts +32 -0
  137. package/src/client/page/view.ts +9 -0
  138. package/src/client/page/waiting.ts +182 -0
  139. package/src/client/read.ts +73 -0
  140. package/src/client/runtime.ts +183 -0
  141. package/src/client/toast.ts +25 -0
  142. package/src/config.ts +96 -0
  143. package/src/define.ts +612 -0
  144. package/src/events.ts +218 -0
  145. package/src/html.ts +40 -0
  146. package/src/icons.ts +8 -0
  147. package/src/load.ts +89 -0
  148. package/src/loader.ts +112 -0
  149. package/src/package.ts +39 -0
  150. package/src/pages/blocks.ts +70 -0
  151. package/src/pages/index.ts +42 -0
  152. package/src/pages/markdown.ts +364 -0
  153. package/src/pages/render.ts +233 -0
  154. package/src/plugins.ts +197 -0
  155. package/src/running.ts +22 -0
  156. package/src/serve.ts +52 -0
  157. package/src/server.ts +667 -0
  158. package/src/status.ts +113 -0
@@ -0,0 +1,71 @@
1
+ // Links to a GitHub or GitLab repository's issues and pull/merge requests, as written in a page's
2
+ // text: `#12` is issue 12, `!34` pull or merge request 34, and `owner/repo#12` or
3
+ // `group/project!34` the same in another repository on the same host. Which repository is read
4
+ // from the project's `origin` remote (https or ssh), so self-hosted GitLab works too; without one,
5
+ // or one that is neither GitHub nor GitLab, it links nothing. `forge({ repo, host, kind })` in the
6
+ // config says it instead. Links only: nothing is fetched.
7
+ import fs from 'node:fs'
8
+ import { execFileSync } from 'node:child_process'
9
+ import { definePlugin, type Plugin, type TextLink } from '@bigmistqke/whiteboard'
10
+
11
+ export type ForgeKind = 'github' | 'gitlab'
12
+ export interface Forge { kind: ForgeKind; host: string; repo: string }
13
+
14
+ /** A git remote's URL → its host and repository path: https, ssh (`git@host:path`), ssh://. */
15
+ export function parseRemote(url: string): { host: string; repo: string } | null {
16
+ const u = url.trim()
17
+ const scp = /^[\w.-]+@([^:/]+):(.+?)(?:\.git)?\/?$/.exec(u)
18
+ if (scp) return { host: scp[1], repo: scp[2] }
19
+ const full = /^(?:https?|ssh|git):\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/(.+?)(?:\.git)?\/?$/.exec(u)
20
+ if (full) return { host: full[1], repo: full[2] }
21
+ return null
22
+ }
23
+
24
+ /** GitHub or GitLab, by the host's name; null for any other. */
25
+ export const kindOf = (host: string): ForgeKind | null => /(^|\.)github\./.test(host) ? 'github' : /(^|\.)gitlab\./.test(host) || /^gitlab/.test(host) ? 'gitlab' : null
26
+
27
+ /** The links for one forge: issues (`#n`) and pull or merge requests (`!n`), here or in `owner/repo`. */
28
+ export function forgeLinks({ kind, host, repo }: Forge): TextLink[] {
29
+ const base = (path: string | undefined) => `https://${host}/${path ?? repo}`
30
+ // after the start, a space or punctuation, so `C#1`, `a/b.md#12` and `x!3` stay text; an optional
31
+ // repository in front (`owner/repo#12`); then the number, ending at a word's end
32
+ const ref = (sign: string) => new RegExp(`(?<![\\w/.#!-])(?:([\\w.-]+(?:/[\\w.-]+)+))?${sign}(\\d+)(?![\\w-])`, 'g')
33
+ const issue = kind === 'github' ? 'issues' : '-/issues'
34
+ const change = kind === 'github' ? 'pull' : '-/merge_requests'
35
+ const what = kind === 'github' ? 'pull request' : 'merge request'
36
+ return [
37
+ { pattern: ref('#'), href: m => `${base(m[1])}/${issue}/${m[2]}`, title: m => `issue ${m[1] ?? repo}#${m[2]}` },
38
+ { pattern: ref('!'), href: m => `${base(m[1])}/${change}/${m[2]}`, title: m => `${what} ${m[1] ?? repo}!${m[2]}` },
39
+ ]
40
+ }
41
+
42
+ /** The project's forge, from its `origin` remote; null without one it knows. */
43
+ export function detect(dir: string): Forge | null {
44
+ let url: string
45
+ try { url = execFileSync('git', ['remote', 'get-url', 'origin'], { cwd: dir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }) } catch { return null }
46
+ const remote = parseRemote(url)
47
+ const kind = remote && kindOf(remote.host)
48
+ return remote && kind ? { kind, ...remote } : null
49
+ }
50
+
51
+ export interface ForgeOptions {
52
+ /** the repository's path on its host: `owner/repo`, `group/subgroup/project` */
53
+ repo?: string
54
+ /** github.com, gitlab.com, or a self-hosted GitLab's host */
55
+ host?: string
56
+ kind?: ForgeKind
57
+ }
58
+
59
+ export default function forge(options: ForgeOptions = {}): Plugin {
60
+ return definePlugin({
61
+ name: 'forge',
62
+ links({ dir }) {
63
+ const found = detect(dir)
64
+ const host = options.host ?? found?.host
65
+ const repo = options.repo ?? found?.repo
66
+ const kind = options.kind ?? (options.host ? kindOf(options.host) : null) ?? found?.kind
67
+ return host && repo && kind ? forgeLinks({ kind, host, repo }) : []
68
+ },
69
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
70
+ })
71
+ }
@@ -0,0 +1,111 @@
1
+ A named form, written as markdown. Submitting it appends
2
+ `{ id, ts, page, type, action, data }` to the events log, where `type` is the
3
+ form's `name`, `action` is the button that was pressed and `data` holds the
4
+ inputs. The form starts from its last answer.
5
+
6
+ The body of `:::form{name=…}` is ordinary markdown, and inputs are inline
7
+ directives that can sit anywhere in it: in a paragraph, a list, a table
8
+ cell, a heading, a grid card. So a question sits with everything that
9
+ explains it.
10
+
11
+ | input | written as | sends |
12
+ | --- | --- | --- |
13
+ | one choice | `:radio[This week]{name=when}` per option | the picked label's text, or `null` |
14
+ | several choices | `:check[Android]{name=phones}` per option | an array of the checked labels |
15
+ | one checkbox | `:check[I read it]{name=read}` | `true` or `false` |
16
+ | text | `:text[Title]{name=title placeholder="a short name"}` | the text |
17
+ | more text | `:textarea[Notes]{name=notes}` | the text |
18
+ | number, date, range | `:number[Count]{name=count min=0 max=10}`, `:date[Due]{name=due}`, `:range[…]{name=… min=0 max=100}` | the value |
19
+ | dropdown | `:select[Target]{name=env options="staging, production"}` | the picked option |
20
+ | fixed value | `:hidden{name=version value=2.3}` | the value |
21
+ | buttons | `:button[Approve]` `:button[Hold]` | which one is `action` |
22
+
23
+ - The label in `[…]` is markdown. An option sends its label as plain text
24
+ (`:radio[This **week**]` sends `This week`), unless `value=…` says what
25
+ to send instead.
26
+ - `recommended` tags an option as the writer's recommendation; it is never
27
+ preselected, so a choice is only made by picking it. `checked` does
28
+ preselect one; use it for defaults, not for decisions.
29
+ - Without a `:button`, the form gets one `Send` button. The first button is
30
+ the primary one.
31
+ - `value=…` on `:text`, `:textarea`, `:select` and the others sets what
32
+ they start with.
33
+
34
+ **Options with what they mean.** When the options of a decision need
35
+ explaining, put each one at the start of a list item, with its explanation
36
+ under it. Such an item reads as a row to pick:
37
+
38
+ ````markdown
39
+ :::form{name=storage}
40
+ **Where are answers kept?**
41
+
42
+ - :radio[One log per project]{name=where recommended}
43
+ Simple, and the agent waits on one file.
44
+ - :radio[One log per page]{name=where}
45
+ Pages can be moved with their answers.
46
+ :::
47
+ ````
48
+
49
+ :::form{name=storage}
50
+ **Where are answers kept?**
51
+
52
+ - :radio[One log per project]{name=where recommended}
53
+ Simple, and the agent waits on one file.
54
+ - :radio[One log per page]{name=where}
55
+ Pages can be moved with their answers.
56
+ :::
57
+
58
+ An option's explanation can be any markdown: a code block, a table, a
59
+ picture, a `:::details` block. Indent it under the item, and mind the
60
+ colons: a container inside the form needs fewer colons than the form, so
61
+ write the form as `::::form` around a `:::details`.
62
+
63
+ **Inputs anywhere.** Since an input is a word-sized element, any layout
64
+ can hold one: a card per option in a grid, a checkbox per row of a table.
65
+
66
+ ````markdown
67
+ ::::form{name=deploy-review}
68
+ Ship **v2.3** to production?
69
+
70
+ :::grid{cols=2}
71
+ ### :radio[Staging]{name=env}
72
+ Runs the migration on a copy first.
73
+
74
+ ### :radio[Production]{name=env recommended}
75
+ The migration is reversible.
76
+ :::
77
+
78
+ :textarea[Notes]{name=notes placeholder="anything to check first"}
79
+
80
+ :button[Approve] :button[Hold]
81
+ ::::
82
+ ````
83
+
84
+ ::::form{name=deploy-review}
85
+ Ship **v2.3** to production?
86
+
87
+ :::grid{cols=2}
88
+ ### :radio[Staging]{name=env}
89
+ Runs the migration on a copy first.
90
+
91
+ ### :radio[Production]{name=env recommended}
92
+ The migration is reversible.
93
+ :::
94
+
95
+ :textarea[Notes]{name=notes placeholder="anything to check first"}
96
+
97
+ :button[Approve] :button[Hold]
98
+ ::::
99
+
100
+ Forms don't nest, and inputs belong inside a form: outside one they show
101
+ but send nothing.
102
+
103
+ **A chat under every form.** The reader can ask about a question without
104
+ answering it: under every form is a chat (see the chat plugin), named
105
+ after the form, whose messages are never a submit, so talking about a choice
106
+ never makes it. Answer there with `whiteboard append --type chat:message
107
+ --data '{"chat":"<form name>","text":"…"}'`, and don't add a free-text field
108
+ for questions to a decision form.
109
+
110
+ A hand-written `<form name="…">` (no `action` attribute) is recorded the same
111
+ way; this block only saves typing.
@@ -0,0 +1,104 @@
1
+ // :::form{name=…} — a named form whose body is ordinary markdown, with inputs written inline anywhere in
2
+ // it: `:radio[This **week**]{name=when}`, `:check[…]`, `:text[…]`, `:button[Send]` and so on. See
3
+ // README.md.
4
+ //
5
+ // Everything here renders on the server as plain HTML: a `<form name>` the core looks after (it
6
+ // sends a submit as an event, keeps drafts, puts the last answer back and marks where the form
7
+ // stands, which the page shows). The chat under the form is the chat plugin's.
8
+ import fs from 'node:fs'
9
+ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
10
+ import { html, raw, type Block, type DirectiveContext } from '@bigmistqke/whiteboard'
11
+ import { chatThread } from '../chat/index.ts'
12
+ import { isQuestionName } from '../../src/status.ts'
13
+
14
+ const style = new URL('./style.css', import.meta.url)
15
+
16
+ const CHOICES = new Set(['radio', 'check', 'select', 'hidden'])
17
+
18
+ interface Node { type: string; name?: string; attributes?: Record<string, string>; children?: Node[] }
19
+
20
+ /** The inputs written inside a form's markdown (forms inside it excluded: forms don't nest). */
21
+ function inputsOf(nodes: Node[]) {
22
+ const found: { name: string; attrs: Record<string, string> }[] = []
23
+ const walk = (node: Node) => {
24
+ if ((node.type === 'textDirective' || node.type === 'leafDirective') && node.name) found.push({ name: node.name, attrs: node.attributes ?? {} })
25
+ if (node.type === 'containerDirective' && node.name === 'form') return
26
+ for (const child of node.children ?? []) walk(child)
27
+ }
28
+ nodes.forEach(walk)
29
+ return found
30
+ }
31
+
32
+ const recommendedTag = html`<span class="wb-form-recommended">recommended</span>`
33
+
34
+ const form: Block = {
35
+ style,
36
+ async html(ctx) {
37
+ const c = ctx as DirectiveContext
38
+ const name = c.attrs.name || c.attrs.id || 'form'
39
+ // a colon marks the events of whiteboard or a plugin (`chat:message`), never an answer
40
+ if (!isQuestionName(name)) throw new Error(`form name "${name}" has a colon: those names are reserved for events of whiteboard and plugins`)
41
+ const inputs = inputsOf(c.children as Node[])
42
+ const choices = [...new Set(inputs.filter(i => CHOICES.has(i.name) && i.attrs.name).map(i => i.attrs.name))]
43
+ const hasButton = inputs.some(i => i.name === 'button')
44
+ // the first button is the form's primary one; the markup is the button block's own
45
+ const body = (await c.toHtml(c.children)).replace('<button name="action"', '<button class="wb-primary" name="action"')
46
+ // the form's chat: talk about the question, named after the form (see ../chat)
47
+ const thread = await chatThread(c, name, { choices })
48
+ return html`<form name="${name}" class="wb-form">${raw(body)}${!hasButton && html`<p><button class="wb-primary">Send</button></p>`}${raw(thread)}</form>`
49
+ },
50
+ }
51
+
52
+ /** The label of an inline input as HTML, else its fallback. */
53
+ const labelOf = (c: DirectiveContext, fallback = '') => (c.label ? raw(c.label) : fallback)
54
+
55
+ /** :radio[label]{name=… value=… recommended checked} and :check[…]{…} */
56
+ const option = (type: 'radio' | 'checkbox'): Block['html'] => (ctx) => {
57
+ const c = ctx as DirectiveContext
58
+ const value = c.attrs.value ?? c.labelText ?? ''
59
+ 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
+ }
61
+
62
+ /** :text[label]{name=… placeholder=…}, and number, date, range */
63
+ const field = (type: string): Block['html'] => (ctx) => {
64
+ const c = ctx as DirectiveContext
65
+ const extra = ['placeholder', 'min', 'max', 'step', 'value'].filter(k => k in c.attrs).map(k => html` ${raw(k)}="${c.attrs[k]}"`)
66
+ return html`<label class="wb-form-field"><span class="wb-form-label">${labelOf(c)}</span><input type="${type}" name="${c.attrs.name}"${extra}></label>`
67
+ }
68
+
69
+ const input = (name: string, render: Block['html']): [string, Block] => [name, { html: render, style }]
70
+
71
+ const inputs: [string, Block][] = [
72
+ input('radio', option('radio')),
73
+ input('check', option('checkbox')),
74
+ input('text', field('text')),
75
+ input('number', field('number')),
76
+ input('date', field('date')),
77
+ input('range', field('range')),
78
+ input('textarea', (ctx) => {
79
+ const c = ctx as DirectiveContext
80
+ return html`<label class="wb-form-field"><span class="wb-form-label">${labelOf(c)}</span><textarea name="${c.attrs.name}" rows="3" placeholder="${c.attrs.placeholder ?? ''}">${c.attrs.value ?? ''}</textarea></label>`
81
+ }),
82
+ input('select', (ctx) => {
83
+ const c = ctx as DirectiveContext
84
+ const options = (c.attrs.options ?? '').split(',').map(s => s.trim()).filter(Boolean)
85
+ return html`<label class="wb-form-field"><span class="wb-form-label">${labelOf(c)}</span><select name="${c.attrs.name}">${options.map(o => html`<option${o === c.attrs.value && raw(' selected')}>${o}</option>`)}</select></label>`
86
+ }),
87
+ input('hidden', (ctx) => {
88
+ const c = ctx as DirectiveContext
89
+ return html`<input type="hidden" name="${c.attrs.name}" value="${c.attrs.value ?? ''}">`
90
+ }),
91
+ input('button', (ctx) => {
92
+ const c = ctx as DirectiveContext
93
+ const value = c.labelText ?? 'Send'
94
+ return html`<button name="action" value="${value}">${labelOf(c, 'Send')}</button>`
95
+ }),
96
+ ]
97
+
98
+ export default function formPlugin(): Plugin {
99
+ return definePlugin({
100
+ name: 'form',
101
+ blocks: { form, ...Object.fromEntries(inputs) },
102
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
103
+ })
104
+ }
@@ -0,0 +1,41 @@
1
+ /* a form reads as a set-off part of the article: hairline rules above and below, no box */
2
+ .wb-form {
3
+ margin: 3.6em 0; padding: 1.6em 0 1.7em; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
4
+ display: grid; gap: 20px;
5
+ }
6
+ .wb-form-pending { min-height: 72px; }
7
+ /* the form's body is markdown: its first and last blocks sit flush with the rules */
8
+ .wb-form > :first-child { margin-top: 0; }
9
+ .wb-form > :last-child { margin-bottom: 0; }
10
+ .wb-form > :is(p, ul, ol, table, .wb-grid, div) { margin-top: 0; margin-bottom: 0; }
11
+
12
+ /* an inline option, :radio[…] or :check[…]: the input and its label read as one */
13
+ .wb-form-option { display: inline-flex; gap: 8px; align-items: baseline; cursor: pointer; }
14
+ .wb-form-option + .wb-form-option { margin-left: 18px; }
15
+ .wb-form-option input { margin: 0; translate: 0 .1em; }
16
+ .wb-form-option-label { font-weight: 600; }
17
+ .wb-form-recommended { font: 500 .7rem/1.4 var(--sans); color: var(--muted); letter-spacing: .04em; text-transform: uppercase; margin-left: 10px; }
18
+
19
+ /* a list item that starts with an option is a row to pick: no bullet, the picked one tinted, and
20
+ the rest of the item reads as what the option means */
21
+ .wb-form li:has(> p:first-child > .wb-form-option:first-child),
22
+ .wb-form li:has(> .wb-form-option:first-child) { list-style: none; margin-left: -1.2em; padding: 6px 10px; border-radius: 6px; }
23
+ .wb-form li:has(> p:first-child > .wb-form-option:first-child):hover,
24
+ .wb-form li:has(> .wb-form-option:first-child):hover { background: var(--tint); }
25
+ .wb-form li:has(> p:first-child > .wb-form-option:first-child input:checked),
26
+ .wb-form li:has(> .wb-form-option:first-child input:checked) { background: color-mix(in srgb, var(--accent) 8%, transparent); }
27
+ .wb-form li > p:first-child { margin-bottom: .2em; }
28
+ .wb-form li > p:first-child > .wb-form-option:first-child,
29
+ .wb-form li > .wb-form-option:first-child { display: flex; margin-bottom: .15em; }
30
+
31
+ /* fields: the label above the input */
32
+ .wb-form-field { display: flex; flex-direction: column; gap: 7px; margin: 0; min-width: 0; }
33
+ .wb-form-field :is(input:not([type=range]), textarea, select) { width: 100%; }
34
+ .wb-form-field textarea { resize: vertical; }
35
+ .wb-form-label { font: 600 .78rem/1.4 var(--sans); color: var(--muted); letter-spacing: .01em; }
36
+ .wb-form-label:empty { display: none; }
37
+
38
+ /* buttons: the first one of a form is its primary one */
39
+ .wb-form button[name=action] + button[name=action] { margin-left: 8px; }
40
+ .wb-form button.wb-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
41
+ .wb-card .wb-form { padding: 0; border: 0; margin: .6em 0 0; }
@@ -0,0 +1,30 @@
1
+ Image cards; clicking one opens a lightbox (arrow keys to step, Esc to close).
2
+
3
+ Each heading at the shallowest level starts an item: the first image under it
4
+ is the picture, the heading is the title and the rest is the caption. Without
5
+ headings, every image in the block is an item and its alt text the title.
6
+ Relative image paths resolve next to the page file.
7
+
8
+ Attributes: `min` (smallest card width, default `240px`).
9
+
10
+ ```markdown
11
+ :::gallery{min=200px}
12
+ ### Dunes
13
+ ![dunes](https://picsum.photos/id/1016/800/600)
14
+ Option A: warm, quiet.
15
+
16
+ ### Coast
17
+ ![coast](https://picsum.photos/id/1015/800/600)
18
+ Option B: more contrast.
19
+ :::
20
+ ```
21
+
22
+ :::gallery{min=200px}
23
+ ### Dunes
24
+ ![dunes](https://picsum.photos/id/1016/800/600)
25
+ Option A: warm, quiet.
26
+
27
+ ### Coast
28
+ ![coast](https://picsum.photos/id/1015/800/600)
29
+ Option B: more contrast.
30
+ :::
@@ -0,0 +1,64 @@
1
+ import { createSignal, For, Show, onSettled } from 'solid-js'
2
+ import { solid } from '@bigmistqke/whiteboard/solid'
3
+ import type { Item } from './index'
4
+
5
+ function Gallery(props: { items: Item[]; min: string | null; narrow: boolean }) {
6
+ const [open, setOpen] = createSignal<number | null>(null)
7
+ const current = () => {
8
+ const i = open()
9
+ return i == null ? undefined : props.items[i]
10
+ }
11
+ const step = (d: number) => setOpen(i => (i == null ? i : (i + d + props.items.length) % props.items.length))
12
+
13
+ onSettled(() => {
14
+ const onKey = (e: KeyboardEvent) => {
15
+ if (open() == null) return
16
+ if (e.key === 'Escape') setOpen(null)
17
+ else if (e.key === 'ArrowRight') step(1)
18
+ else if (e.key === 'ArrowLeft') step(-1)
19
+ }
20
+ addEventListener('keydown', onKey)
21
+ return () => removeEventListener('keydown', onKey)
22
+ })
23
+
24
+ return (
25
+ <>
26
+ <div class={['wb-gallery', { 'wb-wide': !props.narrow }]} style={{ '--wb-gallery-min': props.min ?? '240px' }}>
27
+ <For each={props.items}>
28
+ {(item, i) => (
29
+ <figure class="wb-gallery-item">
30
+ <Show when={item.src}>
31
+ <button type="button" class="wb-gallery-thumb" onClick={() => setOpen(i())}>
32
+ <img src={item.src!} alt={item.alt} loading="lazy" />
33
+ </button>
34
+ </Show>
35
+ <Show when={item.title || item.html}>
36
+ <figcaption>
37
+ <Show when={item.title}>
38
+ <h3 innerHTML={item.title!} />
39
+ </Show>
40
+ <div innerHTML={item.html} />
41
+ </figcaption>
42
+ </Show>
43
+ </figure>
44
+ )}
45
+ </For>
46
+ </div>
47
+ <Show when={current()}>
48
+ {item => (
49
+ <div class="wb-lightbox" onClick={e => e.target === e.currentTarget && setOpen(null)}>
50
+ <img src={item().src ?? ''} alt={item().alt} />
51
+ <div class="wb-lightbox-caption" innerHTML={item().title ?? ''} />
52
+ <Show when={props.items.length > 1}>
53
+ <button type="button" class="wb-lightbox-prev" aria-label="Previous" onClick={() => step(-1)}>‹</button>
54
+ <button type="button" class="wb-lightbox-next" aria-label="Next" onClick={() => step(1)}>›</button>
55
+ </Show>
56
+ <button type="button" class="wb-lightbox-close" aria-label="Close" onClick={() => setOpen(null)}>×</button>
57
+ </div>
58
+ )}
59
+ </Show>
60
+ </>
61
+ )
62
+ }
63
+
64
+ export default solid(Gallery)
@@ -0,0 +1,67 @@
1
+ import fs from 'node:fs'
2
+ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
3
+ // Turns the block's content into gallery items: one per heading (first image in the section is
4
+ // its picture), or one per image when there are no headings.
5
+ import { escape, type DirectiveContext } from '@bigmistqke/whiteboard'
6
+ import { builtFile } from '../../src/package.ts'
7
+
8
+ interface Node { type: string; depth?: number; url?: string; alt?: string; children?: Node[] }
9
+ export interface Item { src: string | null; alt: string; title: string | null; html: string }
10
+
11
+ /** Remove and return the first image in a list of nodes (searching inside paragraphs). */
12
+ function takeImage(nodes: Node[]): Node | null {
13
+ for (let i = 0; i < nodes.length; i++) {
14
+ const n = nodes[i]
15
+ if (n.type === 'image') { nodes.splice(i, 1); return n }
16
+ if (n.children) {
17
+ const found = takeImage(n.children)
18
+ if (found) {
19
+ if (n.type === 'paragraph' && n.children.every(c => c.type === 'text' && !String((c as any).value).trim())) nodes.splice(i, 1)
20
+ return found
21
+ }
22
+ }
23
+ }
24
+ return null
25
+ }
26
+
27
+ export async function props(ctx: DirectiveContext) {
28
+ const children = ctx.children as Node[]
29
+ const heads = children.filter(n => n.type === 'heading')
30
+ const items: Item[] = []
31
+ if (heads.length) {
32
+ const depth = Math.min(...heads.map(h => h.depth!))
33
+ let current: { heading: Node; body: Node[] } | null = null
34
+ const groups: { heading: Node; body: Node[] }[] = []
35
+ for (const n of children) {
36
+ if (n.type === 'heading' && n.depth === depth) groups.push((current = { heading: n, body: [] }))
37
+ else current?.body.push(n)
38
+ }
39
+ for (const g of groups) {
40
+ const img = takeImage(g.body)
41
+ items.push({ src: img?.url ?? null, alt: img?.alt ?? '', title: await ctx.toHtml(g.heading.children ?? []), html: await ctx.toHtml(g.body) })
42
+ }
43
+ } else {
44
+ const walk = (nodes: Node[]) => {
45
+ for (const n of nodes) {
46
+ if (n.type === 'image') items.push({ src: n.url!, alt: n.alt ?? '', title: n.alt ? escape(n.alt) : null, html: '' })
47
+ else if (n.children) walk(n.children)
48
+ }
49
+ }
50
+ walk(children)
51
+ }
52
+ return { items, min: ctx.attrs.min ?? null, narrow: 'narrow' in ctx.attrs }
53
+ }
54
+
55
+ export default function gallery(): Plugin {
56
+ return definePlugin({
57
+ name: 'gallery',
58
+ blocks: {
59
+ gallery: {
60
+ props,
61
+ client: builtFile(import.meta.url, 'client.js'),
62
+ style: new URL('./style.css', import.meta.url),
63
+ },
64
+ },
65
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
66
+ })
67
+ }
@@ -0,0 +1,27 @@
1
+ .wb-gallery {
2
+ display: grid; gap: 40px 24px; margin: 4em 0;
3
+ grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--wb-gallery-min, 240px)), 1fr));
4
+ }
5
+ .wb-gallery-item {
6
+ margin: 0; overflow: hidden; display: flex; flex-direction: column; min-width: 0;
7
+ }
8
+ .wb-gallery-thumb { padding: 0; border: 0; border-radius: var(--radius); overflow: hidden; background: var(--code-bg); cursor: zoom-in; display: block; }
9
+ .wb-gallery-thumb img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 0; }
10
+ .wb-gallery-item figcaption { padding: 14px 2px 0; font: .88rem/1.5 var(--serif); color: var(--text); }
11
+ .wb-gallery-item figcaption h3 { margin: 0 0 .25em; font-size: 1rem; }
12
+ .wb-gallery-item figcaption > div > :first-child { margin-top: 0; }
13
+ .wb-gallery-item figcaption > div > :last-child { margin-bottom: 0; }
14
+
15
+ .wb-lightbox {
16
+ position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .86);
17
+ display: grid; place-items: center; grid-template-rows: 1fr auto; padding: 24px 16px;
18
+ }
19
+ .wb-lightbox img { max-width: 100%; max-height: calc(100vh - 110px); object-fit: contain; border-radius: 4px; }
20
+ .wb-lightbox-caption { color: #eee; text-align: center; padding-top: 10px; }
21
+ .wb-lightbox button {
22
+ position: absolute; background: rgb(255 255 255 / .12); color: #fff; border: 0; font-size: 1.6rem; line-height: 1;
23
+ width: 44px; height: 44px; border-radius: 50%; padding: 0;
24
+ }
25
+ .wb-lightbox-prev { left: 12px; top: 50%; }
26
+ .wb-lightbox-next { right: 12px; top: 50%; }
27
+ .wb-lightbox-close { right: 12px; top: 12px; }
@@ -0,0 +1,33 @@
1
+ Cards in a responsive grid. Each heading at the shallowest level inside the
2
+ block starts a card; everything under it is the card body (any markdown,
3
+ including other blocks). Without headings, each paragraph is a card.
4
+
5
+ A heading that ends in `{word}` gets a badge. `done ok yes good` are green,
6
+ `active new info` blue, `open todo maybe warning` amber,
7
+ `blocked no bad error` red; any other word is grey.
8
+
9
+ Attributes: `cols` (target column count on a wide screen, default 3).
10
+
11
+ ```markdown
12
+ :::grid{cols=3}
13
+ ### Parser {done}
14
+ remark + remark-directive.
15
+
16
+ ### Islands {active}
17
+ Solid components mounted per block.
18
+
19
+ ### Docs {todo}
20
+ Live examples on `/_/docs`.
21
+ :::
22
+ ```
23
+
24
+ :::grid{cols=3}
25
+ ### Parser {done}
26
+ remark + remark-directive.
27
+
28
+ ### Islands {active}
29
+ Solid components mounted per block.
30
+
31
+ ### Docs {todo}
32
+ Live examples on `/_/docs`.
33
+ :::
@@ -0,0 +1,36 @@
1
+ import fs from 'node:fs'
2
+ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
3
+ // Static block: no component, so no JavaScript on the page.
4
+ import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
5
+
6
+ const slug = (s: string) => s.toLowerCase().trim().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
7
+
8
+ export async function render(ctx: DirectiveContext) {
9
+ const { intro, sections } = await ctx.sections()
10
+ const cols = Number(ctx.attrs.cols)
11
+ const style = cols ? html` style="--wb-grid-cols:${cols}"` : null
12
+ const cards = sections.map(s => {
13
+ let title = s.title
14
+ let badge: string | null = null
15
+ const m = title ? /^(.*?)\s*\{([^}]+)\}\s*$/s.exec(title) : null
16
+ if (m) { title = m[1]; badge = m[2].trim() }
17
+ // a section's title and html are HTML already; the badge is text from the heading
18
+ const b = badge && html`<span class="wb-badge" data-badge="${slug(badge)}">${badge}</span>`
19
+ const head = (title || b) && html`<header>${title && html`<h3>${raw(title)}</h3>`}${b}</header>`
20
+ return html`<article class="wb-card"${badge && html` data-badge="${slug(badge)}"`}>${head}<div class="wb-card-body">${raw(s.html)}</div></article>`
21
+ })
22
+ return html`${raw(intro)}<div class="wb-grid${'narrow' in ctx.attrs ? '' : ' wb-wide'}"${style}>${cards}</div>`
23
+ }
24
+
25
+ export default function grid(): Plugin {
26
+ return definePlugin({
27
+ name: 'grid',
28
+ blocks: {
29
+ grid: {
30
+ html: render,
31
+ style: new URL('./style.css', import.meta.url),
32
+ },
33
+ },
34
+ docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
35
+ })
36
+ }
@@ -0,0 +1,25 @@
1
+ .wb-grid {
2
+ display: grid; gap: 22px; margin: 4em 0;
3
+ grid-template-columns: repeat(auto-fill, minmax(min(100%, calc(var(--wide, 1040px) / var(--wb-grid-cols, 3) - 16px)), 1fr));
4
+ }
5
+ .wb-grid:not(.wb-wide) { grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
6
+ .wb-card {
7
+ background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
8
+ padding: 18px 20px 20px; min-width: 0;
9
+ }
10
+ .wb-card > header { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; margin-bottom: .55em; }
11
+ .wb-card h3 { margin: 0; font-size: 1.02rem; }
12
+ .wb-card-body { font-size: .9rem; line-height: 1.6; }
13
+ .wb-card-body > :first-child { margin-top: 0; }
14
+ .wb-card-body > :last-child { margin-bottom: 0; }
15
+
16
+ /* badge: a coloured dot and a word, not a pill */
17
+ .wb-badge {
18
+ --c: var(--muted); flex: none; display: inline-flex; align-items: center; gap: 6px;
19
+ font: 500 .74rem/1 var(--sans); color: var(--muted); white-space: nowrap;
20
+ }
21
+ .wb-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
22
+ .wb-badge:is([data-badge=done], [data-badge=ok], [data-badge=yes], [data-badge=good]) { --c: var(--ok); }
23
+ .wb-badge:is([data-badge=active], [data-badge=new], [data-badge=info]) { --c: var(--info); }
24
+ .wb-badge:is([data-badge=open], [data-badge=todo], [data-badge=maybe], [data-badge=warning]) { --c: var(--warn); }
25
+ .wb-badge:is([data-badge=blocked], [data-badge=no], [data-badge=bad], [data-badge=error]) { --c: var(--bad); }
@@ -0,0 +1,18 @@
1
+ Another page inside this one: a running app (a dev server), a deployed
2
+ site, or an HTML file next to the pages. A header like a browser window's
3
+ shows its label (or, without one, its address), opens it on its own, and fills the window with
4
+ it (the same button, or Esc, puts it back). Drag the frame's bottom edge to
5
+ make it taller.
6
+
7
+ Attributes: `src` (required: an http(s) URL, or a path such as `demo.html`
8
+ for `.whiteboard/pages/demo.html`), `height` (a number of pixels or a CSS
9
+ length, default 480), `wide` (wider than the text column), `bare` (no
10
+ header: the frame alone).
11
+
12
+ ```markdown
13
+ ::iframe[The app as it runs now]{src="http://localhost:5173" height=600 wide}
14
+ ```
15
+
16
+ A site that forbids being framed (most large ones do, with
17
+ `X-Frame-Options` or `frame-ancestors`) shows as a blank or refused frame;
18
+ link to it instead.