@bigmistqke/whiteboard 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -18
- package/bin/whiteboard.ts +300 -71
- package/dist/bin/whiteboard.js +21 -0
- package/dist/client/runtime.js +132 -54
- package/dist/define.js +21 -2
- package/dist/plugins/callout/index.js +3 -1
- package/dist/plugins/callout/public/style.css +30 -0
- package/dist/plugins/chat/index.js +7 -4
- package/dist/plugins/chat/{client.js → public/client.js} +1 -1
- package/dist/plugins/chat/public/style.css +98 -0
- package/dist/plugins/code/index.js +3 -1
- package/dist/plugins/code/public/style.css +68 -0
- package/dist/plugins/comments/index.js +4 -5
- package/dist/plugins/comments/public/client.js +19 -0
- package/dist/plugins/comments/public/style.css +185 -0
- package/dist/plugins/details/index.js +7 -2
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/form/index.js +37 -8
- package/dist/plugins/form/public/style.css +126 -0
- package/dist/plugins/gallery/index.js +4 -3
- package/dist/plugins/gallery/public/client.js +1 -0
- package/dist/plugins/gallery/public/style.css +90 -0
- package/dist/plugins/grid/index.js +9 -3
- package/dist/plugins/grid/public/style.css +71 -0
- package/dist/plugins/iframe/index.js +13 -14
- package/dist/plugins/iframe/public/style.css +13 -0
- package/dist/plugins/index.js +7 -1
- package/dist/plugins/mermaid/index.js +3 -1
- package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +99 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/index.js +10 -9
- package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +12 -5
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +99 -0
- package/dist/plugins/window/README.md +29 -0
- package/dist/plugins/window/index.js +64 -0
- package/dist/solid/index.js +14 -11
- package/dist/src/auth.js +2 -1
- package/dist/src/client/page/base.css +1078 -199
- package/dist/src/client/page/main.js +188 -39
- package/dist/src/loader.js +14 -3
- package/dist/src/package.js +3 -6
- package/dist/src/pages/blocks.js +8 -13
- package/dist/src/pages/markdown.js +1 -1
- package/dist/src/pages/render.js +106 -20
- package/dist/src/pages/window.js +31 -0
- package/dist/src/public.js +24 -0
- package/dist/src/server.js +251 -23
- package/package.json +5 -2
- package/plugins/callout/index.ts +3 -1
- package/plugins/callout/public/style.css +30 -0
- package/plugins/chat/autosize.ts +43 -9
- package/plugins/chat/client.tsx +22 -5
- package/plugins/chat/index.ts +22 -8
- package/plugins/chat/public/style.css +98 -0
- package/plugins/claude-code/index.ts +49 -14
- package/plugins/code/diff.ts +28 -8
- package/plugins/code/index.ts +33 -21
- package/plugins/code/public/style.css +68 -0
- package/plugins/comments/client.ts +139 -71
- package/plugins/comments/index.ts +9 -7
- package/plugins/comments/public/style.css +185 -0
- package/plugins/details/index.ts +7 -2
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/index.ts +16 -3
- package/plugins/form/index.ts +75 -27
- package/plugins/form/public/style.css +126 -0
- package/plugins/gallery/client.tsx +9 -3
- package/plugins/gallery/index.ts +31 -9
- package/plugins/gallery/public/style.css +90 -0
- package/plugins/grid/index.ts +19 -5
- package/plugins/grid/public/style.css +71 -0
- package/plugins/iframe/index.ts +20 -23
- package/plugins/iframe/public/style.css +13 -0
- package/plugins/index.ts +20 -1
- package/plugins/mermaid/index.ts +7 -3
- package/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +66 -0
- package/plugins/steps/index.ts +127 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +105 -48
- package/plugins/terminal/host.ts +143 -35
- package/plugins/terminal/index.ts +84 -25
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +64 -13
- package/plugins/terminal/sizes.ts +16 -4
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +90 -30
- package/plugins/toc/index.ts +26 -10
- package/plugins/toc/public/style.css +99 -0
- package/plugins/window/README.md +29 -0
- package/plugins/window/index.ts +85 -0
- package/skills/whiteboard/SKILL.md +3 -1
- package/solid/index.tsx +24 -9
- package/src/auth.ts +28 -9
- package/src/client/forms.ts +74 -28
- package/src/client/markdown.ts +15 -4
- package/src/client/page/base.css +1078 -199
- package/src/client/page/elsewhere.ts +32 -15
- package/src/client/page/fresh.ts +91 -23
- package/src/client/page/hold.ts +11 -2
- package/src/client/page/live.ts +10 -6
- package/src/client/page/main.ts +124 -42
- package/src/client/page/orphans.ts +25 -10
- package/src/client/page/sort.ts +14 -4
- package/src/client/page/sticky.ts +11 -3
- package/src/client/page/theme.ts +11 -7
- package/src/client/page/waiting.ts +141 -34
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +17 -10
- package/src/client/runtime.ts +170 -40
- package/src/client/scroll.ts +14 -4
- package/src/client/toast.ts +19 -5
- package/src/config.ts +20 -5
- package/src/define.ts +119 -31
- package/src/events.ts +111 -24
- package/src/html.ts +6 -2
- package/src/icons.ts +4 -2
- package/src/load.ts +10 -2
- package/src/loader.ts +81 -12
- package/src/package.ts +9 -8
- package/src/pages/blocks.ts +20 -14
- package/src/pages/index.ts +2 -2
- package/src/pages/markdown.ts +113 -34
- package/src/pages/render.ts +233 -41
- package/src/pages/window.ts +78 -0
- package/src/plugins.ts +90 -24
- package/src/public.ts +39 -0
- package/src/running.ts +8 -2
- package/src/serve.ts +29 -7
- package/src/server.ts +591 -110
- package/src/status.ts +15 -9
- package/dist/plugins/callout/style.css +0 -12
- package/dist/plugins/chat/style.css +0 -24
- package/dist/plugins/code/style.css +0 -29
- package/dist/plugins/comments/client.js +0 -10
- package/dist/plugins/comments/style.css +0 -40
- package/dist/plugins/details/style.css +0 -3
- package/dist/plugins/form/style.css +0 -44
- package/dist/plugins/gallery/client.js +0 -1
- package/dist/plugins/gallery/style.css +0 -27
- package/dist/plugins/grid/style.css +0 -25
- package/dist/plugins/iframe/client.js +0 -1
- package/dist/plugins/iframe/style.css +0 -29
- package/dist/plugins/toc/client.js +0 -1
- package/dist/plugins/toc/style.css +0 -19
- package/plugins/callout/style.css +0 -12
- package/plugins/chat/style.css +0 -24
- package/plugins/code/style.css +0 -29
- package/plugins/comments/style.css +0 -40
- package/plugins/details/style.css +0 -3
- package/plugins/form/style.css +0 -44
- package/plugins/gallery/style.css +0 -27
- package/plugins/grid/style.css +0 -25
- package/plugins/iframe/client.ts +0 -46
- package/plugins/iframe/style.css +0 -29
- package/plugins/terminal/style.css +0 -71
- package/plugins/toc/style.css +0 -19
- /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
.wb-grid {
|
|
2
|
+
display: grid;
|
|
3
|
+
gap: var(--space-3xl);
|
|
4
|
+
margin: 4em 0;
|
|
5
|
+
grid-template-columns: repeat(
|
|
6
|
+
auto-fill,
|
|
7
|
+
minmax(min(100%, calc(var(--wide, 1040px) / var(--wb-grid-cols, 3) - 16px)), 1fr)
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
.wb-grid:not(.wb-wide) {
|
|
11
|
+
grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));
|
|
12
|
+
}
|
|
13
|
+
.wb-card {
|
|
14
|
+
background: var(--surface);
|
|
15
|
+
border: var(--hairline) solid var(--border);
|
|
16
|
+
border-radius: var(--radius);
|
|
17
|
+
padding: var(--space-2xl) var(--space-2xl) var(--space-2xl);
|
|
18
|
+
min-width: 0;
|
|
19
|
+
}
|
|
20
|
+
.wb-card > header {
|
|
21
|
+
display: flex;
|
|
22
|
+
gap: var(--space-lg);
|
|
23
|
+
align-items: baseline;
|
|
24
|
+
justify-content: space-between;
|
|
25
|
+
margin-bottom: 0.55em;
|
|
26
|
+
}
|
|
27
|
+
.wb-card h3 {
|
|
28
|
+
margin: 0;
|
|
29
|
+
font-size: 1.02rem;
|
|
30
|
+
}
|
|
31
|
+
.wb-card-body {
|
|
32
|
+
font-size: var(--ui-text);
|
|
33
|
+
line-height: 1.6;
|
|
34
|
+
}
|
|
35
|
+
.wb-card-body > :first-child {
|
|
36
|
+
margin-top: 0;
|
|
37
|
+
}
|
|
38
|
+
.wb-card-body > :last-child {
|
|
39
|
+
margin-bottom: 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* badge: a coloured dot and a word, not a pill */
|
|
43
|
+
.wb-badge {
|
|
44
|
+
--c: var(--muted);
|
|
45
|
+
flex: none;
|
|
46
|
+
display: inline-flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
gap: var(--space-sm);
|
|
49
|
+
font: 500 var(--ui-tiny)/1 var(--sans);
|
|
50
|
+
color: var(--muted);
|
|
51
|
+
white-space: nowrap;
|
|
52
|
+
}
|
|
53
|
+
.wb-badge::before {
|
|
54
|
+
content: '';
|
|
55
|
+
width: 7px;
|
|
56
|
+
height: 7px;
|
|
57
|
+
border-radius: 50%;
|
|
58
|
+
background: var(--c);
|
|
59
|
+
}
|
|
60
|
+
.wb-badge:is([data-badge='done'], [data-badge='ok'], [data-badge='yes'], [data-badge='good']) {
|
|
61
|
+
--c: var(--ok);
|
|
62
|
+
}
|
|
63
|
+
.wb-badge:is([data-badge='active'], [data-badge='new'], [data-badge='info']) {
|
|
64
|
+
--c: var(--info);
|
|
65
|
+
}
|
|
66
|
+
.wb-badge:is([data-badge='open'], [data-badge='todo'], [data-badge='maybe'], [data-badge='warning']) {
|
|
67
|
+
--c: var(--warn);
|
|
68
|
+
}
|
|
69
|
+
.wb-badge:is([data-badge='blocked'], [data-badge='no'], [data-badge='bad'], [data-badge='error']) {
|
|
70
|
+
--c: var(--bad);
|
|
71
|
+
}
|
package/plugins/iframe/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Another page inside this one: a URL (a dev server, a deployed site) or an HTML file next to the
|
|
2
|
-
// pages (`demo.html` in .whiteboard/pages/ is served as it is)
|
|
3
|
-
//
|
|
4
|
-
// bottom edge.
|
|
2
|
+
// pages (`demo.html` in .whiteboard/pages/ is served as it is), in a window (src/pages/window.ts): a
|
|
3
|
+
// header with its label or address, open on its own, fill the window; the frame can be made taller
|
|
4
|
+
// by dragging its bottom edge.
|
|
5
5
|
import fs from 'node:fs'
|
|
6
|
-
import {
|
|
6
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
7
7
|
import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
8
|
-
import { html,
|
|
8
|
+
import { html, windowFrame, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
9
9
|
|
|
10
10
|
/** http(s), protocol-relative, or a path on this server; never `javascript:` or `data:`. */
|
|
11
11
|
export const safeSrc = (src: string) => /^(https?:)?\/\//i.test(src) || !/^[a-z][a-z0-9+.-]*:/i.test(src)
|
|
@@ -17,38 +17,35 @@ export function height(value: string | undefined): string {
|
|
|
17
17
|
return '480px'
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// the header's buttons, as icons
|
|
21
|
-
const svg = (d: string) => raw(`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">${d}</svg>`)
|
|
22
|
-
const OPEN = svg('<path d="M9 2.5h4.5V7M13.5 2.5 7.5 8.5M11.5 9.5v3a1 1 0 0 1-1 1h-7a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1h3"/>')
|
|
23
|
-
const MAXIMIZE = svg('<path d="M2.5 6V2.5H6M10 2.5h3.5V6M13.5 10v3.5H10M6 13.5H2.5V10"/>')
|
|
24
|
-
const RESTORE = svg('<path d="M6 2.5V6H2.5M13.5 6H10V2.5M10 13.5V10h3.5M2.5 10H6v3.5"/>')
|
|
25
|
-
|
|
26
20
|
export async function render(ctx: DirectiveContext) {
|
|
27
21
|
const src = (ctx.attrs.src ?? '').trim()
|
|
28
22
|
if (!src) return html`<pre class="wb-error">iframe: needs a src, like ::iframe{src="http://localhost:5173"}</pre>`
|
|
29
|
-
if (!safeSrc(src))
|
|
23
|
+
if (!safeSrc(src))
|
|
24
|
+
return html`<pre class="wb-error">iframe: src must be an http(s) URL or a path, not ${src.split(':')[0]}:</pre>`
|
|
30
25
|
const title = ctx.labelText ?? ctx.attrs.title ?? src
|
|
31
|
-
// a
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
// in a window (the page's: its label, or the address; open on its own; fill the window), its
|
|
27
|
+
// body the frame, which the reader can drag taller
|
|
28
|
+
return windowFrame({
|
|
29
|
+
label: ctx.label,
|
|
30
|
+
open: src,
|
|
31
|
+
wide: 'wide' in ctx.attrs,
|
|
32
|
+
bare: 'bare' in ctx.attrs,
|
|
33
|
+
bodyClass: 'wb-iframe-frame',
|
|
34
|
+
height: height(ctx.attrs.height),
|
|
35
|
+
body: html`<iframe src="${src}" title="${title}" loading="lazy" referrerpolicy="no-referrer"></iframe>`,
|
|
36
|
+
})
|
|
40
37
|
}
|
|
41
38
|
|
|
42
39
|
export default function iframe(): Plugin {
|
|
43
40
|
return definePlugin({
|
|
44
41
|
name: 'iframe',
|
|
42
|
+
public: builtinPublic('iframe'),
|
|
45
43
|
blocks: {
|
|
46
44
|
iframe: {
|
|
47
45
|
html: render,
|
|
48
|
-
style:
|
|
46
|
+
style: 'style.css',
|
|
49
47
|
},
|
|
50
48
|
},
|
|
51
|
-
setup: () => ({ client: packagePath('dist/plugins/iframe/client.js') }),
|
|
52
49
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
53
50
|
})
|
|
54
51
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* the iframe in its window (the window's look is the page's): a frame its bottom edge drags taller */
|
|
2
|
+
.wb-iframe-frame {
|
|
3
|
+
resize: vertical;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
min-height: 120px;
|
|
6
|
+
background: #fff;
|
|
7
|
+
}
|
|
8
|
+
.wb-iframe-frame iframe {
|
|
9
|
+
display: block;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
border: 0;
|
|
13
|
+
}
|
package/plugins/index.ts
CHANGED
|
@@ -15,7 +15,26 @@ import grid from './grid/index.ts'
|
|
|
15
15
|
import iframe from './iframe/index.ts'
|
|
16
16
|
import mermaid from './mermaid/index.ts'
|
|
17
17
|
import quiet from './quiet/index.ts'
|
|
18
|
+
import windows from './window/index.ts'
|
|
19
|
+
import steps from './steps/index.ts'
|
|
20
|
+
import draft from './draft/index.ts'
|
|
18
21
|
|
|
19
22
|
export function builtins(): Plugin[] {
|
|
20
|
-
return [
|
|
23
|
+
return [
|
|
24
|
+
callout(),
|
|
25
|
+
chat(),
|
|
26
|
+
code(),
|
|
27
|
+
comments(),
|
|
28
|
+
details(),
|
|
29
|
+
forge(),
|
|
30
|
+
form(),
|
|
31
|
+
gallery(),
|
|
32
|
+
grid(),
|
|
33
|
+
iframe(),
|
|
34
|
+
mermaid(),
|
|
35
|
+
quiet(),
|
|
36
|
+
windows(),
|
|
37
|
+
steps(),
|
|
38
|
+
draft(),
|
|
39
|
+
]
|
|
21
40
|
}
|
package/plugins/mermaid/index.ts
CHANGED
|
@@ -3,9 +3,12 @@ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
|
3
3
|
// Mermaid diagrams rendered to SVG on the server with Pele (https://pele.run): no JavaScript on
|
|
4
4
|
// the page, and colours come from CSS variables, so diagrams follow the light/dark theme.
|
|
5
5
|
import crypto from 'node:crypto'
|
|
6
|
-
|
|
7
|
-
let pele: typeof import('pele') | undefined
|
|
6
|
+
import type * as Pele from 'pele'
|
|
8
7
|
import { html, raw, type FenceContext } from '@bigmistqke/whiteboard'
|
|
8
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
9
|
+
|
|
10
|
+
// loaded the first time a page has a diagram, not with the plugin: the command line loads plugins too
|
|
11
|
+
let pele: typeof Pele | undefined
|
|
9
12
|
|
|
10
13
|
const FONT = 'ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'
|
|
11
14
|
|
|
@@ -28,11 +31,12 @@ export async function render(ctx: FenceContext) {
|
|
|
28
31
|
export default function mermaid(): Plugin {
|
|
29
32
|
return definePlugin({
|
|
30
33
|
name: 'mermaid',
|
|
34
|
+
public: builtinPublic('mermaid'),
|
|
31
35
|
blocks: {
|
|
32
36
|
mermaid: {
|
|
33
37
|
fence: true,
|
|
34
38
|
html: render,
|
|
35
|
-
style:
|
|
39
|
+
style: 'style.css',
|
|
36
40
|
},
|
|
37
41
|
},
|
|
38
42
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* Pele reads its colours from --pele-* variables; map them onto the page's tokens so diagrams
|
|
2
2
|
follow the theme without being re-rendered. */
|
|
3
3
|
.wb-diagram {
|
|
4
|
-
margin: 4em 0;
|
|
4
|
+
margin: 4em 0;
|
|
5
|
+
overflow-x: auto;
|
|
6
|
+
text-align: center;
|
|
5
7
|
--pele-bg: transparent;
|
|
6
8
|
--pele-fg: var(--text);
|
|
7
9
|
--pele-muted: var(--muted);
|
|
@@ -13,4 +15,7 @@
|
|
|
13
15
|
--pele-font: var(--sans);
|
|
14
16
|
--pele-radius: 6px;
|
|
15
17
|
}
|
|
16
|
-
.wb-diagram svg {
|
|
18
|
+
.wb-diagram svg {
|
|
19
|
+
max-width: 100%;
|
|
20
|
+
height: auto;
|
|
21
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
One pane, one item at a time, with ‹ › between them: an A/B, the steps of a
|
|
2
|
+
procedure, versions of a design. It is a window, so ⤢ fills the browser
|
|
3
|
+
window with it (for going through steps, large).
|
|
4
|
+
|
|
5
|
+
Each heading at the shallowest level starts an item; without headings, `---`
|
|
6
|
+
separates them. With up to four items, all titled, the header shows the
|
|
7
|
+
titles as tabs; else it counts (`2 / 5`) and each item shows its title.
|
|
8
|
+
|
|
9
|
+
The items are laid over each other, so the pane is as tall as the tallest
|
|
10
|
+
and flipping doesn't move the page. ← and → step when it has the focus (a
|
|
11
|
+
click in it) or fills the window. Which item shows stays when the page
|
|
12
|
+
updates.
|
|
13
|
+
|
|
14
|
+
Attributes: `count` (count, never tabs), `wide`, `height`.
|
|
15
|
+
|
|
16
|
+
```markdown
|
|
17
|
+
:::steps[Two headers]
|
|
18
|
+
### A
|
|
19
|
+
The label on the left, the buttons on the right.
|
|
20
|
+
|
|
21
|
+
### B
|
|
22
|
+
Everything centred.
|
|
23
|
+
:::
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
:::steps[Two headers]
|
|
27
|
+
### A
|
|
28
|
+
The label on the left, the buttons on the right.
|
|
29
|
+
|
|
30
|
+
### B
|
|
31
|
+
Everything centred.
|
|
32
|
+
:::
|
|
33
|
+
|
|
34
|
+
```markdown
|
|
35
|
+
:::steps[The migration]
|
|
36
|
+
### Copy the table
|
|
37
|
+
`migrate --dry-run` on staging first.
|
|
38
|
+
|
|
39
|
+
### Switch the reads
|
|
40
|
+
…
|
|
41
|
+
:::
|
|
42
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Steps in the browser: which item shows, by the ‹ › buttons, the tabs and ← →, and kept across
|
|
2
|
+
// the page's updates (which write the block anew) by the block's place among the page's steps. It
|
|
3
|
+
// marks only data-wb-* attributes, which a block's signature leaves out: flipping through items is
|
|
4
|
+
// not a change to the page.
|
|
5
|
+
import type { Api, PageHandle, PluginMount } from '../../src/define'
|
|
6
|
+
|
|
7
|
+
const windows = () => [...document.querySelectorAll<HTMLElement>('#wb-main .wb-steps-window')]
|
|
8
|
+
const items = (win: HTMLElement) => [
|
|
9
|
+
...win.querySelectorAll<HTMLElement>(':scope > .wb-window-body > .wb-steps > .wb-steps-item'),
|
|
10
|
+
]
|
|
11
|
+
const marks = (win: HTMLElement) => [...win.querySelectorAll<HTMLElement>(':scope > .wb-window-bar .wb-steps-mark')]
|
|
12
|
+
|
|
13
|
+
/** which item shows, by the block's place */
|
|
14
|
+
const at = new Map<number, number>()
|
|
15
|
+
|
|
16
|
+
function show(win: HTMLElement, place: number, i: number) {
|
|
17
|
+
const all = items(win)
|
|
18
|
+
const n = Math.max(all.length, 1)
|
|
19
|
+
i = Math.min(Math.max(i, 0), n - 1)
|
|
20
|
+
at.set(place, i)
|
|
21
|
+
win.setAttribute('data-wb-step', String(i))
|
|
22
|
+
all.forEach((item, k) => item.toggleAttribute('data-wb-current', k === i))
|
|
23
|
+
marks(win).forEach((mark, k) => mark.toggleAttribute('data-wb-current', k === i))
|
|
24
|
+
win.toggleAttribute('data-wb-first', i === 0)
|
|
25
|
+
win.toggleAttribute('data-wb-last', i === n - 1)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const apply = () => windows().forEach((win, place) => show(win, place, at.get(place) ?? 0))
|
|
29
|
+
|
|
30
|
+
function step(win: HTMLElement, to: 'prev' | 'next' | number) {
|
|
31
|
+
const place = windows().indexOf(win)
|
|
32
|
+
if (place < 0) return
|
|
33
|
+
const now = at.get(place) ?? 0
|
|
34
|
+
show(win, place, to === 'prev' ? now - 1 : to === 'next' ? now + 1 : to)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const typing = (el: Element | null) =>
|
|
38
|
+
!!el?.closest?.('input, textarea, select, [contenteditable]:not([contenteditable="false"])')
|
|
39
|
+
|
|
40
|
+
let listening = false
|
|
41
|
+
const mount: PluginMount = (_el: HTMLElement, _handle: PageHandle, core: Api) => {
|
|
42
|
+
apply()
|
|
43
|
+
core.onRendered(apply)
|
|
44
|
+
if (listening) return
|
|
45
|
+
listening = true
|
|
46
|
+
document.addEventListener('click', e => {
|
|
47
|
+
const button = (e.target as Element).closest?.<HTMLElement>('[data-steps]')
|
|
48
|
+
const win = button?.closest<HTMLElement>('.wb-steps-window')
|
|
49
|
+
if (!button || !win) return
|
|
50
|
+
const to = button.dataset.steps!
|
|
51
|
+
step(win, to === 'prev' || to === 'next' ? to : Number(to))
|
|
52
|
+
})
|
|
53
|
+
document.addEventListener('keydown', e => {
|
|
54
|
+
if ((e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') || e.metaKey || e.ctrlKey || e.altKey) return
|
|
55
|
+
const target = e.target as Element
|
|
56
|
+
if (typing(target)) return
|
|
57
|
+
// the steps that have the focus, or the one filling the window
|
|
58
|
+
const win =
|
|
59
|
+
target.closest?.<HTMLElement>('.wb-steps-window') ??
|
|
60
|
+
document.querySelector<HTMLElement>('#wb-main .wb-steps-window[data-wb-maximized]')
|
|
61
|
+
if (!win) return
|
|
62
|
+
e.preventDefault()
|
|
63
|
+
step(win, e.key === 'ArrowLeft' ? 'prev' : 'next')
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
export default mount
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Steps: one pane, one item at a time, ‹ › between them: an A/B, a sequence of steps, versions of a
|
|
2
|
+
// design. In a window (src/pages/window.ts), so it fills the browser window too. The items are laid
|
|
3
|
+
// over each other, so the pane is as tall as the tallest and flipping doesn't move the page; which
|
|
4
|
+
// one shows is the browser's (client.ts), kept across the page's updates.
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import { definePlugin, html, raw, windowFrame, type DirectiveContext, type Plugin } from '@bigmistqke/whiteboard'
|
|
7
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
8
|
+
|
|
9
|
+
interface Node {
|
|
10
|
+
type: string
|
|
11
|
+
depth?: number
|
|
12
|
+
value?: string
|
|
13
|
+
children?: Node[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Part {
|
|
17
|
+
/** the heading's content, or none */
|
|
18
|
+
title: Node[] | null
|
|
19
|
+
body: Node[]
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The items of a block: one per heading at its shallowest level (what comes before the first is an
|
|
24
|
+
* item of its own); without headings, `---` separates them; else it is one item.
|
|
25
|
+
*/
|
|
26
|
+
export function split(children: Node[]): Part[] {
|
|
27
|
+
const content = children.filter(n => !(n.type === 'text' && !n.value?.trim()))
|
|
28
|
+
const heads = content.filter(n => n.type === 'heading')
|
|
29
|
+
const parts: Part[] = []
|
|
30
|
+
if (heads.length) {
|
|
31
|
+
const depth = Math.min(...heads.map(h => h.depth!))
|
|
32
|
+
for (const n of content) {
|
|
33
|
+
if (n.type === 'heading' && n.depth === depth) parts.push({ title: n.children ?? [], body: [] })
|
|
34
|
+
else if (parts.length) parts.at(-1)!.body.push(n)
|
|
35
|
+
else parts.push({ title: null, body: [n] })
|
|
36
|
+
}
|
|
37
|
+
return parts
|
|
38
|
+
}
|
|
39
|
+
let current: Part = { title: null, body: [] }
|
|
40
|
+
for (const n of content) {
|
|
41
|
+
if (n.type === 'thematicBreak') {
|
|
42
|
+
if (current.body.length) parts.push(current)
|
|
43
|
+
current = { title: null, body: [] }
|
|
44
|
+
} else current.body.push(n)
|
|
45
|
+
}
|
|
46
|
+
if (current.body.length || !parts.length) parts.push(current)
|
|
47
|
+
return parts
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A height in px (a bare number) or a CSS length; else none. */
|
|
51
|
+
const height = (value: string | undefined) =>
|
|
52
|
+
value && /^\d+(\.\d+)?$/.test(value)
|
|
53
|
+
? `${value}px`
|
|
54
|
+
: value && /^\d+(\.\d+)?(px|em|rem|vh|svh|dvh)$/.test(value)
|
|
55
|
+
? value
|
|
56
|
+
: undefined
|
|
57
|
+
|
|
58
|
+
const svg = (d: string) =>
|
|
59
|
+
raw(
|
|
60
|
+
`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`,
|
|
61
|
+
)
|
|
62
|
+
const PREV = svg('M10 3.5 5.5 8l4.5 4.5')
|
|
63
|
+
const NEXT = svg('M6 3.5 10.5 8 6 12.5')
|
|
64
|
+
|
|
65
|
+
/** With this many items or fewer, all titled, the header shows their titles as tabs. */
|
|
66
|
+
const TABS = 4
|
|
67
|
+
|
|
68
|
+
export async function render(ctx: DirectiveContext) {
|
|
69
|
+
const parts = split(ctx.children as Node[])
|
|
70
|
+
const items = await Promise.all(
|
|
71
|
+
parts.map(async p => ({ title: p.title ? await ctx.toHtml(p.title) : null, html: await ctx.toHtml(p.body) })),
|
|
72
|
+
)
|
|
73
|
+
const tabs = !('count' in ctx.attrs) && items.length <= TABS && items.every(i => i.title)
|
|
74
|
+
const n = items.length
|
|
75
|
+
const marks = tabs
|
|
76
|
+
? items.map(
|
|
77
|
+
(item, i) =>
|
|
78
|
+
html`<button type="button" class="wb-steps-tab wb-steps-mark" data-steps="${String(i)}">
|
|
79
|
+
${raw(item.title!)}
|
|
80
|
+
</button>`,
|
|
81
|
+
)
|
|
82
|
+
: html`<span class="wb-steps-count">
|
|
83
|
+
${items.map((_, i) => html`<span class="wb-steps-mark">${String(i + 1)} / ${String(n)}</span>`)}
|
|
84
|
+
</span>`
|
|
85
|
+
const controls = html`<span class="wb-steps-nav">
|
|
86
|
+
<button
|
|
87
|
+
type="button"
|
|
88
|
+
class="wb-window-button wb-steps-prev"
|
|
89
|
+
data-steps="prev"
|
|
90
|
+
title="Previous (←)"
|
|
91
|
+
aria-label="Previous"
|
|
92
|
+
>
|
|
93
|
+
${PREV}
|
|
94
|
+
</button>
|
|
95
|
+
${marks}
|
|
96
|
+
<button type="button" class="wb-window-button wb-steps-next" data-steps="next" title="Next (→)" aria-label="Next">
|
|
97
|
+
${NEXT}
|
|
98
|
+
</button>
|
|
99
|
+
</span>`
|
|
100
|
+
const body = html`<div class="wb-steps" tabindex="0">
|
|
101
|
+
${items.map(
|
|
102
|
+
item =>
|
|
103
|
+
html`<section class="wb-steps-item">
|
|
104
|
+
${!tabs && item.title ? html`<div class="wb-steps-title">${raw(item.title)}</div>` : ''} ${raw(item.html)}
|
|
105
|
+
</section>`,
|
|
106
|
+
)}
|
|
107
|
+
</div>`
|
|
108
|
+
return windowFrame({
|
|
109
|
+
label: ctx.label,
|
|
110
|
+
className: 'wb-steps-window',
|
|
111
|
+
controls,
|
|
112
|
+
wide: 'wide' in ctx.attrs,
|
|
113
|
+
height: height(ctx.attrs.height),
|
|
114
|
+
body,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export default function steps(): Plugin {
|
|
119
|
+
return definePlugin({
|
|
120
|
+
name: 'steps',
|
|
121
|
+
public: builtinPublic('steps'),
|
|
122
|
+
style: 'style.css',
|
|
123
|
+
setup: () => ({ client: 'client.js' }),
|
|
124
|
+
blocks: { steps: { html: render } },
|
|
125
|
+
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
126
|
+
})
|
|
127
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* Steps (index.ts): the items over each other in one grid cell, so the pane is as tall as the
|
|
2
|
+
tallest; one shows. Before the browser marks one (data-wb-step), the first. */
|
|
3
|
+
.wb-steps {
|
|
4
|
+
display: grid;
|
|
5
|
+
outline: none;
|
|
6
|
+
}
|
|
7
|
+
.wb-steps:focus-visible {
|
|
8
|
+
box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
9
|
+
}
|
|
10
|
+
.wb-steps > .wb-steps-item {
|
|
11
|
+
grid-area: 1 / 1;
|
|
12
|
+
min-width: 0;
|
|
13
|
+
}
|
|
14
|
+
.wb-steps > .wb-steps-item > :first-child {
|
|
15
|
+
margin-top: 0;
|
|
16
|
+
}
|
|
17
|
+
.wb-steps > .wb-steps-item > :last-child {
|
|
18
|
+
margin-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-body > .wb-steps > .wb-steps-item:not(:first-child),
|
|
21
|
+
.wb-steps-window[data-wb-step] > .wb-window-body > .wb-steps > .wb-steps-item:not([data-wb-current]) {
|
|
22
|
+
visibility: hidden;
|
|
23
|
+
}
|
|
24
|
+
.wb-steps-title {
|
|
25
|
+
font: var(--weight-strong) var(--ui-small) / var(--ui-line-height) var(--sans);
|
|
26
|
+
color: var(--muted);
|
|
27
|
+
letter-spacing: var(--caps-spacing);
|
|
28
|
+
text-transform: uppercase;
|
|
29
|
+
margin-bottom: var(--space-md);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* the header: ‹ 2 / 5 › or ‹ A B › */
|
|
33
|
+
.wb-steps-nav {
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
gap: var(--space-2xs);
|
|
37
|
+
flex: none;
|
|
38
|
+
}
|
|
39
|
+
.wb-steps-count {
|
|
40
|
+
font: var(--ui-tiny) / 1 var(--sans);
|
|
41
|
+
font-variant-numeric: tabular-nums;
|
|
42
|
+
color: var(--muted);
|
|
43
|
+
padding: 0 var(--space-2xs);
|
|
44
|
+
}
|
|
45
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-count > .wb-steps-mark:not(:first-child),
|
|
46
|
+
.wb-steps-window[data-wb-step] > .wb-window-bar .wb-steps-count > .wb-steps-mark:not([data-wb-current]) {
|
|
47
|
+
display: none;
|
|
48
|
+
}
|
|
49
|
+
.wb-steps-tab {
|
|
50
|
+
font: var(--ui-tiny) / 1 var(--sans);
|
|
51
|
+
color: var(--muted);
|
|
52
|
+
background: none;
|
|
53
|
+
border: var(--hairline) solid transparent;
|
|
54
|
+
border-radius: var(--radius-pill);
|
|
55
|
+
padding: var(--space-xs) var(--space-md);
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
white-space: nowrap;
|
|
58
|
+
}
|
|
59
|
+
.wb-steps-tab > * {
|
|
60
|
+
margin: 0;
|
|
61
|
+
}
|
|
62
|
+
.wb-steps-tab:hover {
|
|
63
|
+
color: var(--text);
|
|
64
|
+
background: color-mix(in srgb, var(--text) var(--tint-faint), transparent);
|
|
65
|
+
}
|
|
66
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-tab:first-of-type,
|
|
67
|
+
.wb-steps-window > .wb-window-bar .wb-steps-tab[data-wb-current] {
|
|
68
|
+
color: var(--accent);
|
|
69
|
+
border-color: color-mix(in srgb, var(--accent) var(--tint-strong), transparent);
|
|
70
|
+
background: color-mix(in srgb, var(--accent) var(--tint-faint), transparent);
|
|
71
|
+
}
|
|
72
|
+
.wb-steps-window:not([data-wb-step]) > .wb-window-bar .wb-steps-prev,
|
|
73
|
+
.wb-steps-window[data-wb-first] > .wb-window-bar .wb-steps-prev,
|
|
74
|
+
.wb-steps-window[data-wb-last] > .wb-window-bar .wb-steps-next {
|
|
75
|
+
opacity: 0.35;
|
|
76
|
+
pointer-events: none;
|
|
77
|
+
}
|