@bigmistqke/whiteboard 0.3.0 → 0.4.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 +67 -17
- package/bin/whiteboard.ts +268 -71
- package/dist/client/runtime.js +88 -41
- 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/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 +3 -1
- package/dist/plugins/mermaid/index.js +3 -1
- package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/dist/plugins/terminal/index.js +10 -9
- package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
- package/dist/plugins/toc/README.md +12 -0
- package/dist/plugins/toc/index.js +9 -5
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +93 -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/client/page/base.css +1078 -199
- package/dist/src/client/page/main.js +174 -32
- package/dist/src/loader.js +7 -2
- 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 +73 -13
- package/dist/src/pages/window.js +30 -0
- package/dist/src/public.js +24 -0
- package/dist/src/server.js +37 -15
- package/package.json +3 -1
- 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 +30 -20
- 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/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 +16 -1
- package/plugins/mermaid/index.ts +3 -1
- package/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/plugins/terminal/client.ts +105 -48
- package/plugins/terminal/host.ts +131 -29
- 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 +13 -3
- package/plugins/toc/README.md +12 -0
- package/plugins/toc/client.ts +58 -29
- package/plugins/toc/index.ts +22 -5
- package/plugins/toc/public/style.css +93 -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 +25 -7
- 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 +106 -34
- 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 +130 -35
- package/src/client/scroll.ts +14 -4
- package/src/client/toast.ts +19 -5
- package/src/config.ts +20 -5
- package/src/define.ts +67 -23
- 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 +75 -11
- package/src/package.ts +9 -8
- package/src/pages/blocks.ts +20 -14
- package/src/pages/markdown.ts +113 -34
- package/src/pages/render.ts +198 -37
- package/src/pages/window.ts +71 -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 +351 -108
- 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,90 @@
|
|
|
1
|
+
.wb-gallery {
|
|
2
|
+
display: grid;
|
|
3
|
+
gap: 40px var(--space-3xl);
|
|
4
|
+
margin: 4em 0;
|
|
5
|
+
grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--wb-gallery-min, 240px)), 1fr));
|
|
6
|
+
}
|
|
7
|
+
.wb-gallery-item {
|
|
8
|
+
margin: 0;
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
min-width: 0;
|
|
13
|
+
}
|
|
14
|
+
.wb-gallery-thumb {
|
|
15
|
+
padding: 0;
|
|
16
|
+
border: 0;
|
|
17
|
+
border-radius: var(--radius);
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
background: var(--code-bg);
|
|
20
|
+
cursor: zoom-in;
|
|
21
|
+
display: block;
|
|
22
|
+
}
|
|
23
|
+
.wb-gallery-thumb img {
|
|
24
|
+
display: block;
|
|
25
|
+
width: 100%;
|
|
26
|
+
aspect-ratio: 4 / 3;
|
|
27
|
+
object-fit: cover;
|
|
28
|
+
border-radius: 0;
|
|
29
|
+
}
|
|
30
|
+
.wb-gallery-item figcaption {
|
|
31
|
+
padding: var(--space-xl) var(--space-2xs) 0;
|
|
32
|
+
font: var(--ui-text)/var(--ui-line-height) var(--serif);
|
|
33
|
+
color: var(--text);
|
|
34
|
+
}
|
|
35
|
+
.wb-gallery-item figcaption h3 {
|
|
36
|
+
margin: 0 0 0.25em;
|
|
37
|
+
font-size: 1rem;
|
|
38
|
+
}
|
|
39
|
+
.wb-gallery-item figcaption > div > :first-child {
|
|
40
|
+
margin-top: 0;
|
|
41
|
+
}
|
|
42
|
+
.wb-gallery-item figcaption > div > :last-child {
|
|
43
|
+
margin-bottom: 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.wb-lightbox {
|
|
47
|
+
position: fixed;
|
|
48
|
+
inset: 0;
|
|
49
|
+
z-index: var(--layer-top);
|
|
50
|
+
background: rgb(0 0 0 / 0.86);
|
|
51
|
+
display: grid;
|
|
52
|
+
place-items: center;
|
|
53
|
+
grid-template-rows: 1fr auto;
|
|
54
|
+
padding: var(--space-3xl) var(--space-2xl);
|
|
55
|
+
}
|
|
56
|
+
.wb-lightbox img {
|
|
57
|
+
max-width: 100%;
|
|
58
|
+
max-height: calc(100vh - 110px);
|
|
59
|
+
object-fit: contain;
|
|
60
|
+
border-radius: var(--radius-sm);
|
|
61
|
+
}
|
|
62
|
+
.wb-lightbox-caption {
|
|
63
|
+
color: #eee;
|
|
64
|
+
text-align: center;
|
|
65
|
+
padding-top: var(--space-lg);
|
|
66
|
+
}
|
|
67
|
+
.wb-lightbox button {
|
|
68
|
+
position: absolute;
|
|
69
|
+
background: rgb(255 255 255 / 0.12);
|
|
70
|
+
color: #fff;
|
|
71
|
+
border: 0;
|
|
72
|
+
font-size: 1.6rem;
|
|
73
|
+
line-height: 1;
|
|
74
|
+
width: 44px;
|
|
75
|
+
height: 44px;
|
|
76
|
+
border-radius: 50%;
|
|
77
|
+
padding: 0;
|
|
78
|
+
}
|
|
79
|
+
.wb-lightbox-prev {
|
|
80
|
+
left: 12px;
|
|
81
|
+
top: 50%;
|
|
82
|
+
}
|
|
83
|
+
.wb-lightbox-next {
|
|
84
|
+
right: 12px;
|
|
85
|
+
top: 50%;
|
|
86
|
+
}
|
|
87
|
+
.wb-lightbox-close {
|
|
88
|
+
right: 12px;
|
|
89
|
+
top: 12px;
|
|
90
|
+
}
|
package/plugins/grid/index.ts
CHANGED
|
@@ -2,8 +2,14 @@ import fs from 'node:fs'
|
|
|
2
2
|
import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
3
3
|
// Static block: no component, so no JavaScript on the page.
|
|
4
4
|
import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
5
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
5
6
|
|
|
6
|
-
const slug = (s: string) =>
|
|
7
|
+
const slug = (s: string) =>
|
|
8
|
+
s
|
|
9
|
+
.toLowerCase()
|
|
10
|
+
.trim()
|
|
11
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
12
|
+
.replace(/^-|-$/g, '')
|
|
7
13
|
|
|
8
14
|
export async function render(ctx: DirectiveContext) {
|
|
9
15
|
const { intro, sections } = await ctx.sections()
|
|
@@ -13,22 +19,30 @@ export async function render(ctx: DirectiveContext) {
|
|
|
13
19
|
let title = s.title
|
|
14
20
|
let badge: string | null = null
|
|
15
21
|
const m = title ? /^(.*?)\s*\{([^}]+)\}\s*$/s.exec(title) : null
|
|
16
|
-
if (m) {
|
|
22
|
+
if (m) {
|
|
23
|
+
title = m[1]
|
|
24
|
+
badge = m[2].trim()
|
|
25
|
+
}
|
|
17
26
|
// a section's title and html are HTML already; the badge is text from the heading
|
|
18
27
|
const b = badge && html`<span class="wb-badge" data-badge="${slug(badge)}">${badge}</span>`
|
|
19
28
|
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)}"`}
|
|
29
|
+
return html`<article class="wb-card" ${badge && html` data-badge="${slug(badge)}"`}>
|
|
30
|
+
${head}
|
|
31
|
+
<div class="wb-card-body">${raw(s.html)}</div>
|
|
32
|
+
</article>`
|
|
21
33
|
})
|
|
22
|
-
return html`${raw(intro)}
|
|
34
|
+
return html`${raw(intro)}
|
|
35
|
+
<div class="wb-grid${'narrow' in ctx.attrs ? '' : ' wb-wide'}" ${style}>${cards}</div>`
|
|
23
36
|
}
|
|
24
37
|
|
|
25
38
|
export default function grid(): Plugin {
|
|
26
39
|
return definePlugin({
|
|
27
40
|
name: 'grid',
|
|
41
|
+
public: builtinPublic('grid'),
|
|
28
42
|
blocks: {
|
|
29
43
|
grid: {
|
|
30
44
|
html: render,
|
|
31
|
-
style:
|
|
45
|
+
style: 'style.css',
|
|
32
46
|
},
|
|
33
47
|
},
|
|
34
48
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
@@ -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,22 @@ 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'
|
|
18
19
|
|
|
19
20
|
export function builtins(): Plugin[] {
|
|
20
|
-
return [
|
|
21
|
+
return [
|
|
22
|
+
callout(),
|
|
23
|
+
chat(),
|
|
24
|
+
code(),
|
|
25
|
+
comments(),
|
|
26
|
+
details(),
|
|
27
|
+
forge(),
|
|
28
|
+
form(),
|
|
29
|
+
gallery(),
|
|
30
|
+
grid(),
|
|
31
|
+
iframe(),
|
|
32
|
+
mermaid(),
|
|
33
|
+
quiet(),
|
|
34
|
+
windows(),
|
|
35
|
+
]
|
|
21
36
|
}
|
package/plugins/mermaid/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import crypto from 'node:crypto'
|
|
|
6
6
|
// pele loads the first time a page has a diagram, not with the plugin
|
|
7
7
|
let pele: typeof import('pele') | undefined
|
|
8
8
|
import { html, raw, type FenceContext } from '@bigmistqke/whiteboard'
|
|
9
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
9
10
|
|
|
10
11
|
const FONT = 'ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif'
|
|
11
12
|
|
|
@@ -28,11 +29,12 @@ export async function render(ctx: FenceContext) {
|
|
|
28
29
|
export default function mermaid(): Plugin {
|
|
29
30
|
return definePlugin({
|
|
30
31
|
name: 'mermaid',
|
|
32
|
+
public: builtinPublic('mermaid'),
|
|
31
33
|
blocks: {
|
|
32
34
|
mermaid: {
|
|
33
35
|
fence: true,
|
|
34
36
|
html: render,
|
|
35
|
-
style:
|
|
37
|
+
style: 'style.css',
|
|
36
38
|
},
|
|
37
39
|
},
|
|
38
40
|
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
|
+
}
|
|
@@ -10,11 +10,28 @@ import { Terminal } from '@xterm/xterm'
|
|
|
10
10
|
import { FitAddon } from '@xterm/addon-fit'
|
|
11
11
|
|
|
12
12
|
const store = {
|
|
13
|
-
get: (k: string) => {
|
|
14
|
-
|
|
13
|
+
get: (k: string) => {
|
|
14
|
+
try {
|
|
15
|
+
return sessionStorage.getItem(k)
|
|
16
|
+
} catch {
|
|
17
|
+
return null
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
set: (k: string, v: string) => {
|
|
21
|
+
try {
|
|
22
|
+
sessionStorage.setItem(k, v)
|
|
23
|
+
} catch {
|
|
24
|
+
/* storage unavailable */
|
|
25
|
+
}
|
|
26
|
+
},
|
|
15
27
|
}
|
|
16
28
|
|
|
17
|
-
interface Session {
|
|
29
|
+
interface Session {
|
|
30
|
+
id: string
|
|
31
|
+
label: string
|
|
32
|
+
running: boolean
|
|
33
|
+
exited: number | null
|
|
34
|
+
}
|
|
18
35
|
|
|
19
36
|
function init(drawer: HTMLElement) {
|
|
20
37
|
const screen = drawer.querySelector<HTMLElement>('.wb-term-screen')!
|
|
@@ -25,7 +42,12 @@ function init(drawer: HTMLElement) {
|
|
|
25
42
|
const grip = drawer.querySelector<HTMLElement>('.wb-term-grip')!
|
|
26
43
|
// the sessions as the server wrote them into the page, and the tab this browser tab shows
|
|
27
44
|
let sessions: Session[] = []
|
|
28
|
-
try {
|
|
45
|
+
try {
|
|
46
|
+
;({ sessions } = JSON.parse(drawer.dataset.sessions ?? '{}'))
|
|
47
|
+
sessions ??= []
|
|
48
|
+
} catch {
|
|
49
|
+
/* none */
|
|
50
|
+
}
|
|
29
51
|
let current: string | null = drawer.dataset.tab ?? sessions[0]?.id ?? null
|
|
30
52
|
|
|
31
53
|
const term = new Terminal({
|
|
@@ -77,7 +99,10 @@ function init(drawer: HTMLElement) {
|
|
|
77
99
|
sent = key
|
|
78
100
|
post('/api/terminal/resize', { id: current, viewer, cols: dims.cols, rows: dims.rows, active: claim })
|
|
79
101
|
// it is ours from now on; the host confirms with a `size`
|
|
80
|
-
if (claim) {
|
|
102
|
+
if (claim) {
|
|
103
|
+
active = viewer
|
|
104
|
+
claim = false
|
|
105
|
+
}
|
|
81
106
|
}
|
|
82
107
|
show()
|
|
83
108
|
}
|
|
@@ -86,7 +111,8 @@ function init(drawer: HTMLElement) {
|
|
|
86
111
|
function show() {
|
|
87
112
|
const dims = fit.proposeDimensions()
|
|
88
113
|
const size = mine() || !session ? dims : session
|
|
89
|
-
if (size?.cols && size?.rows && (size.cols !== term.cols || size.rows !== term.rows))
|
|
114
|
+
if (size?.cols && size?.rows && (size.cols !== term.cols || size.rows !== term.rows))
|
|
115
|
+
term.resize(size.cols, size.rows)
|
|
90
116
|
}
|
|
91
117
|
|
|
92
118
|
/** The reader uses this drawer: the session takes its size. */
|
|
@@ -109,11 +135,18 @@ function init(drawer: HTMLElement) {
|
|
|
109
135
|
const vt = (document as any).startViewTransition
|
|
110
136
|
if (vt && !matchMedia('(prefers-reduced-motion: reduce)').matches) vt.call(document, apply)
|
|
111
137
|
else apply()
|
|
112
|
-
requestAnimationFrame(() => {
|
|
138
|
+
requestAnimationFrame(() => {
|
|
139
|
+
if (open) use()
|
|
140
|
+
refit()
|
|
141
|
+
if (open) term.focus()
|
|
142
|
+
})
|
|
113
143
|
}
|
|
114
144
|
toggle.addEventListener('click', () => setOpen(!isOpen()))
|
|
115
145
|
addEventListener('keydown', e => {
|
|
116
|
-
if (e.ctrlKey && e.key === '`') {
|
|
146
|
+
if (e.ctrlKey && e.key === '`') {
|
|
147
|
+
e.preventDefault()
|
|
148
|
+
setOpen(!isOpen())
|
|
149
|
+
}
|
|
117
150
|
})
|
|
118
151
|
|
|
119
152
|
// ---- height --------------------------------------------------------------------------------
|
|
@@ -145,50 +178,60 @@ function init(drawer: HTMLElement) {
|
|
|
145
178
|
if (!current) return
|
|
146
179
|
use()
|
|
147
180
|
const id = current
|
|
148
|
-
if (!pending)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
181
|
+
if (!pending)
|
|
182
|
+
queueMicrotask(() => {
|
|
183
|
+
const data = pending
|
|
184
|
+
pending = ''
|
|
185
|
+
chain = chain
|
|
186
|
+
.then(() => post('/api/terminal/input', { id, data }))
|
|
187
|
+
.then(
|
|
188
|
+
() => {},
|
|
189
|
+
() => {},
|
|
190
|
+
)
|
|
191
|
+
})
|
|
153
192
|
pending += d
|
|
154
193
|
})
|
|
155
194
|
|
|
156
195
|
// ---- the session ---------------------------------------------------------------------------
|
|
157
196
|
function setStatus(text: string, buttons: [string, () => void][] = []) {
|
|
158
197
|
status.textContent = text
|
|
159
|
-
actions.replaceChildren(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
198
|
+
actions.replaceChildren(
|
|
199
|
+
...buttons.map(([label, run]) => {
|
|
200
|
+
const b = document.createElement('button')
|
|
201
|
+
b.type = 'button'
|
|
202
|
+
b.textContent = label
|
|
203
|
+
b.addEventListener('click', run)
|
|
204
|
+
return b
|
|
205
|
+
}),
|
|
206
|
+
)
|
|
166
207
|
}
|
|
167
208
|
|
|
168
209
|
// ---- tabs ----------------------------------------------------------------------------------
|
|
169
210
|
function drawTabs() {
|
|
170
|
-
tabs.replaceChildren(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
211
|
+
tabs.replaceChildren(
|
|
212
|
+
...sessions.map(x => {
|
|
213
|
+
const tab = document.createElement('span')
|
|
214
|
+
tab.className = 'wb-term-tab'
|
|
215
|
+
tab.dataset.id = x.id
|
|
216
|
+
tab.classList.toggle('wb-current', x.id === current)
|
|
217
|
+
tab.toggleAttribute('data-exited', !x.running)
|
|
218
|
+
const name = document.createElement('button')
|
|
219
|
+
name.type = 'button'
|
|
220
|
+
name.className = 'wb-term-tab-name'
|
|
221
|
+
name.textContent = x.label
|
|
222
|
+
name.title = x.running ? x.label : `${x.label}: exited (${x.exited})`
|
|
223
|
+
name.addEventListener('click', () => select(x.id))
|
|
224
|
+
tab.append(name)
|
|
225
|
+
const close = document.createElement('button')
|
|
226
|
+
close.type = 'button'
|
|
227
|
+
close.className = 'wb-term-tab-close'
|
|
228
|
+
close.title = 'Close this tab (ends its program)'
|
|
229
|
+
close.textContent = '×'
|
|
230
|
+
close.addEventListener('click', () => closeTab(x.id))
|
|
231
|
+
tab.append(close)
|
|
232
|
+
return tab
|
|
233
|
+
}),
|
|
234
|
+
)
|
|
192
235
|
showStatus()
|
|
193
236
|
}
|
|
194
237
|
|
|
@@ -206,12 +249,17 @@ function init(drawer: HTMLElement) {
|
|
|
206
249
|
// no tab yet: "+" opens one
|
|
207
250
|
if (!x) return setStatus('', [])
|
|
208
251
|
if (x.running) return setStatus('', [])
|
|
209
|
-
setStatus(x.exited == null ? 'stopped' : `exited (${x.exited})`, [
|
|
252
|
+
setStatus(x.exited == null ? 'stopped' : `exited (${x.exited})`, [
|
|
253
|
+
['Start again', () => start({ id: x.id, restart: true })],
|
|
254
|
+
])
|
|
210
255
|
}
|
|
211
256
|
|
|
212
257
|
function select(id: string | null) {
|
|
213
258
|
// the tab that shows already: just give it the keyboard back
|
|
214
|
-
if (id === current && stream) {
|
|
259
|
+
if (id === current && stream) {
|
|
260
|
+
if (isOpen()) term.focus()
|
|
261
|
+
return
|
|
262
|
+
}
|
|
215
263
|
current = id
|
|
216
264
|
if (id) store.set('wb-terminal-tab', id)
|
|
217
265
|
drawTabs()
|
|
@@ -242,7 +290,9 @@ function init(drawer: HTMLElement) {
|
|
|
242
290
|
try {
|
|
243
291
|
const res = await fetch('/api/terminal/sessions')
|
|
244
292
|
if (res.ok) ({ sessions } = await res.json())
|
|
245
|
-
} catch {
|
|
293
|
+
} catch {
|
|
294
|
+
/* the server is away: the stream reconnects */
|
|
295
|
+
}
|
|
246
296
|
drawTabs()
|
|
247
297
|
}
|
|
248
298
|
|
|
@@ -253,7 +303,9 @@ function init(drawer: HTMLElement) {
|
|
|
253
303
|
sent = ''
|
|
254
304
|
if (!current) showStatus()
|
|
255
305
|
// without a tab too: the host tells it when one appears (started from the command line, say)
|
|
256
|
-
stream = new EventSource(
|
|
306
|
+
stream = new EventSource(
|
|
307
|
+
`/api/terminal/stream?${current ? `id=${encodeURIComponent(current)}&` : ''}viewer=${viewer}`,
|
|
308
|
+
)
|
|
257
309
|
stream.addEventListener('sessions', e => {
|
|
258
310
|
sessions = JSON.parse((e as MessageEvent).data).sessions
|
|
259
311
|
// the current tab is gone, or there was none and one appeared: show the last
|
|
@@ -297,13 +349,18 @@ function init(drawer: HTMLElement) {
|
|
|
297
349
|
stream.addEventListener('exit', e => {
|
|
298
350
|
const code = JSON.parse((e as MessageEvent).data).code
|
|
299
351
|
const x = sessions.find(y => y.id === current)
|
|
300
|
-
if (x) {
|
|
352
|
+
if (x) {
|
|
353
|
+
x.running = false
|
|
354
|
+
x.exited = code
|
|
355
|
+
}
|
|
301
356
|
drawTabs()
|
|
302
357
|
})
|
|
303
358
|
}
|
|
304
359
|
|
|
305
360
|
// whether the terminal had the keyboard, for the next page
|
|
306
|
-
addEventListener('pagehide', () =>
|
|
361
|
+
addEventListener('pagehide', () =>
|
|
362
|
+
store.set('wb-terminal-focus', drawer.contains(document.activeElement) ? '1' : '0'),
|
|
363
|
+
)
|
|
307
364
|
|
|
308
365
|
drawTabs()
|
|
309
366
|
connect()
|