@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,185 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Comments: highlights through the CSS Highlight API, badges and threads above the page. Colors
|
|
3
|
+
* and fonts come from the page's theme variables, else from
|
|
4
|
+
* the fallbacks here.
|
|
5
|
+
*/
|
|
6
|
+
::highlight(wb-comment) {
|
|
7
|
+
background-color: color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-soft), transparent);
|
|
8
|
+
}
|
|
9
|
+
::highlight(wb-comment-active) {
|
|
10
|
+
background-color: color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-strong), transparent);
|
|
11
|
+
}
|
|
12
|
+
.wb-comment-start,
|
|
13
|
+
.wb-comment-badge,
|
|
14
|
+
.wb-thread {
|
|
15
|
+
position: absolute;
|
|
16
|
+
z-index: var(--layer-popover);
|
|
17
|
+
font-family: var(--sans, sans-serif);
|
|
18
|
+
}
|
|
19
|
+
.wb-comment-start[hidden],
|
|
20
|
+
.wb-thread[hidden],
|
|
21
|
+
.wb-line-comment[hidden] {
|
|
22
|
+
display: none;
|
|
23
|
+
}
|
|
24
|
+
.wb-comment-start {
|
|
25
|
+
background: var(--accent, #1d5bbf);
|
|
26
|
+
color: var(--accent-text, #fff);
|
|
27
|
+
border-color: var(--accent, #1d5bbf);
|
|
28
|
+
border-radius: var(--radius-pill);
|
|
29
|
+
font-size: var(--ui-small);
|
|
30
|
+
padding: var(--space-2xs) var(--space-lg);
|
|
31
|
+
box-shadow: 0 2px 8px rgb(0 0 0 / 0.15);
|
|
32
|
+
}
|
|
33
|
+
.wb-comment-badge {
|
|
34
|
+
min-width: 24px;
|
|
35
|
+
height: 24px;
|
|
36
|
+
padding: 0 var(--space-sm);
|
|
37
|
+
border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm);
|
|
38
|
+
font-size: var(--ui-tiny);
|
|
39
|
+
font-weight: var(--weight-strong);
|
|
40
|
+
background: var(--bg, Canvas);
|
|
41
|
+
color: var(--accent, #1d5bbf);
|
|
42
|
+
border: var(--hairline) solid color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-strong), transparent);
|
|
43
|
+
}
|
|
44
|
+
.wb-comment-badge[data-agent] {
|
|
45
|
+
background: var(--accent, #1d5bbf);
|
|
46
|
+
color: var(--accent-text, #fff);
|
|
47
|
+
}
|
|
48
|
+
.wb-comment-badge[data-detached] {
|
|
49
|
+
border-style: dashed;
|
|
50
|
+
}
|
|
51
|
+
/* a reply the reader hasn't read: a dot on the badge until its thread is open and it is in view */
|
|
52
|
+
.wb-comment-badge[data-unread]::after {
|
|
53
|
+
content: '';
|
|
54
|
+
position: absolute;
|
|
55
|
+
top: -3px;
|
|
56
|
+
right: -3px;
|
|
57
|
+
width: 9px;
|
|
58
|
+
height: 9px;
|
|
59
|
+
border-radius: 50%;
|
|
60
|
+
background: var(--bad, #c4352b);
|
|
61
|
+
border: 2px solid var(--bg, Canvas);
|
|
62
|
+
}
|
|
63
|
+
.wb-thread {
|
|
64
|
+
background: var(--bg, Canvas);
|
|
65
|
+
border: var(--hairline) solid var(--border, #e3e5e9);
|
|
66
|
+
border-radius: var(--radius);
|
|
67
|
+
padding: var(--space-xl) var(--space-xl);
|
|
68
|
+
box-shadow: var(--shadow-pop);
|
|
69
|
+
display: grid;
|
|
70
|
+
gap: var(--space-lg);
|
|
71
|
+
font-size: var(--ui-text);
|
|
72
|
+
}
|
|
73
|
+
.wb-thread-quote {
|
|
74
|
+
margin: 0;
|
|
75
|
+
padding-left: var(--space-lg);
|
|
76
|
+
border-left: 3px solid color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-strong), transparent);
|
|
77
|
+
color: var(--muted, #696e76);
|
|
78
|
+
font-size: var(--ui-small);
|
|
79
|
+
max-height: 6.5em;
|
|
80
|
+
overflow: auto;
|
|
81
|
+
white-space: pre-wrap;
|
|
82
|
+
}
|
|
83
|
+
.wb-thread-detached {
|
|
84
|
+
margin: 0;
|
|
85
|
+
color: var(--muted, #696e76);
|
|
86
|
+
font-size: var(--ui-small);
|
|
87
|
+
}
|
|
88
|
+
.wb-thread-message {
|
|
89
|
+
display: grid;
|
|
90
|
+
gap: var(--space-2xs);
|
|
91
|
+
}
|
|
92
|
+
.wb-thread-who {
|
|
93
|
+
font-size: var(--ui-tiny);
|
|
94
|
+
font-weight: var(--weight-strong);
|
|
95
|
+
letter-spacing: var(--caps-spacing);
|
|
96
|
+
text-transform: uppercase;
|
|
97
|
+
color: var(--muted, #696e76);
|
|
98
|
+
}
|
|
99
|
+
.wb-thread-message[data-from='agent'] .wb-thread-who {
|
|
100
|
+
color: var(--accent, #1d5bbf);
|
|
101
|
+
}
|
|
102
|
+
.wb-thread-text {
|
|
103
|
+
white-space: pre-wrap;
|
|
104
|
+
line-height: var(--ui-line-height);
|
|
105
|
+
}
|
|
106
|
+
/* rendered from markdown: its paragraphs and code carry the spacing */
|
|
107
|
+
.wb-thread-text[data-md] {
|
|
108
|
+
white-space: normal;
|
|
109
|
+
overflow-wrap: anywhere;
|
|
110
|
+
}
|
|
111
|
+
.wb-thread-text[data-md] > :first-child {
|
|
112
|
+
margin-top: 0;
|
|
113
|
+
}
|
|
114
|
+
.wb-thread-text[data-md] > :last-child {
|
|
115
|
+
margin-bottom: 0;
|
|
116
|
+
}
|
|
117
|
+
.wb-thread-text[data-md] :is(p, ul, ol, pre, blockquote) {
|
|
118
|
+
margin: 0 0 0.5em;
|
|
119
|
+
}
|
|
120
|
+
.wb-thread-text[data-md] pre {
|
|
121
|
+
font-size: var(--ui-small);
|
|
122
|
+
padding: var(--space-md) var(--space-lg);
|
|
123
|
+
border-radius: var(--radius-sm);
|
|
124
|
+
overflow-x: auto;
|
|
125
|
+
max-width: 100%;
|
|
126
|
+
}
|
|
127
|
+
.wb-thread textarea {
|
|
128
|
+
width: 100%;
|
|
129
|
+
resize: vertical;
|
|
130
|
+
font: inherit;
|
|
131
|
+
}
|
|
132
|
+
.wb-thread-reply {
|
|
133
|
+
display: grid;
|
|
134
|
+
gap: var(--space-md);
|
|
135
|
+
margin: 0;
|
|
136
|
+
}
|
|
137
|
+
.wb-thread-actions {
|
|
138
|
+
display: flex;
|
|
139
|
+
gap: var(--space-md);
|
|
140
|
+
}
|
|
141
|
+
/* its own buttons, styled here rather than borrowed from the page */
|
|
142
|
+
.wb-comment-button {
|
|
143
|
+
font: 500 var(--ui-small)/1.3 var(--sans, sans-serif);
|
|
144
|
+
padding: var(--space-sm) var(--space-xl);
|
|
145
|
+
border-radius: var(--radius-sm);
|
|
146
|
+
cursor: pointer;
|
|
147
|
+
border: var(--hairline) solid var(--border, #e3e5e9);
|
|
148
|
+
background: var(--surface, Canvas);
|
|
149
|
+
color: var(--text, CanvasText);
|
|
150
|
+
}
|
|
151
|
+
.wb-comment-button:hover {
|
|
152
|
+
border-color: var(--muted, #696e76);
|
|
153
|
+
}
|
|
154
|
+
.wb-comment-primary {
|
|
155
|
+
background: var(--accent, #1d5bbf);
|
|
156
|
+
color: var(--accent-text, #fff);
|
|
157
|
+
border-color: var(--accent, #1d5bbf);
|
|
158
|
+
}
|
|
159
|
+
.wb-comment-start,
|
|
160
|
+
.wb-comment-badge {
|
|
161
|
+
cursor: pointer;
|
|
162
|
+
border-style: solid;
|
|
163
|
+
border-width: var(--hairline);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* "+" beside a line of code: comment on it, or drag over several */
|
|
167
|
+
.wb-line-comment {
|
|
168
|
+
position: absolute;
|
|
169
|
+
z-index: var(--layer-popover);
|
|
170
|
+
width: 20px;
|
|
171
|
+
height: 20px;
|
|
172
|
+
padding: 0;
|
|
173
|
+
border-radius: var(--radius-sm);
|
|
174
|
+
cursor: pointer;
|
|
175
|
+
font: var(--weight-strong) 14px/1 var(--sans, sans-serif);
|
|
176
|
+
background: var(--accent, #1d5bbf);
|
|
177
|
+
color: var(--accent-text, #fff);
|
|
178
|
+
border: none;
|
|
179
|
+
box-shadow: 0 1px 4px rgb(0 0 0 / 0.2);
|
|
180
|
+
}
|
|
181
|
+
.wb-thread-at {
|
|
182
|
+
margin: -4px 0 0;
|
|
183
|
+
font: var(--ui-small) var(--mono, monospace);
|
|
184
|
+
color: var(--muted, #696e76);
|
|
185
|
+
}
|
package/plugins/details/index.ts
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
3
3
|
import { html, raw, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
4
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
4
5
|
|
|
5
6
|
export async function render(ctx: DirectiveContext) {
|
|
6
7
|
// the label and content are HTML already
|
|
7
|
-
return html`<details class="wb-details"${'open' in ctx.attrs && raw(' open')}
|
|
8
|
+
return html`<details class="wb-details" ${'open' in ctx.attrs && raw(' open')}>
|
|
9
|
+
<summary>${ctx.label ? raw(ctx.label) : 'Details'}</summary>
|
|
10
|
+
<div class="wb-details-body">${raw(await ctx.toHtml(ctx.children))}</div>
|
|
11
|
+
</details>`
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
export default function details(): Plugin {
|
|
11
15
|
return definePlugin({
|
|
12
16
|
name: 'details',
|
|
17
|
+
public: builtinPublic('details'),
|
|
13
18
|
blocks: {
|
|
14
19
|
details: {
|
|
15
20
|
html: render,
|
|
16
|
-
style:
|
|
21
|
+
style: 'style.css',
|
|
17
22
|
},
|
|
18
23
|
},
|
|
19
24
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
package/plugins/forge/index.ts
CHANGED
|
@@ -9,7 +9,11 @@ import { execFileSync } from 'node:child_process'
|
|
|
9
9
|
import { definePlugin, type Plugin, type TextLink } from '@bigmistqke/whiteboard'
|
|
10
10
|
|
|
11
11
|
export type ForgeKind = 'github' | 'gitlab'
|
|
12
|
-
export interface Forge {
|
|
12
|
+
export interface Forge {
|
|
13
|
+
kind: ForgeKind
|
|
14
|
+
host: string
|
|
15
|
+
repo: string
|
|
16
|
+
}
|
|
13
17
|
|
|
14
18
|
/** A git remote's URL → its host and repository path: https, ssh (`git@host:path`), ssh://. */
|
|
15
19
|
export function parseRemote(url: string): { host: string; repo: string } | null {
|
|
@@ -22,7 +26,8 @@ export function parseRemote(url: string): { host: string; repo: string } | null
|
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
/** GitHub or GitLab, by the host's name; null for any other. */
|
|
25
|
-
export const kindOf = (host: string): ForgeKind | null =>
|
|
29
|
+
export const kindOf = (host: string): ForgeKind | null =>
|
|
30
|
+
/(^|\.)github\./.test(host) ? 'github' : /(^|\.)gitlab\./.test(host) || /^gitlab/.test(host) ? 'gitlab' : null
|
|
26
31
|
|
|
27
32
|
/** The links for one forge: issues (`#n`) and pull or merge requests (`!n`), here or in `owner/repo`. */
|
|
28
33
|
export function forgeLinks({ kind, host, repo }: Forge): TextLink[] {
|
|
@@ -42,7 +47,15 @@ export function forgeLinks({ kind, host, repo }: Forge): TextLink[] {
|
|
|
42
47
|
/** The project's forge, from its `origin` remote; null without one it knows. */
|
|
43
48
|
export function detect(dir: string): Forge | null {
|
|
44
49
|
let url: string
|
|
45
|
-
try {
|
|
50
|
+
try {
|
|
51
|
+
url = execFileSync('git', ['remote', 'get-url', 'origin'], {
|
|
52
|
+
cwd: dir,
|
|
53
|
+
encoding: 'utf8',
|
|
54
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
55
|
+
})
|
|
56
|
+
} catch {
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
46
59
|
const remote = parseRemote(url)
|
|
47
60
|
const kind = remote && kindOf(remote.host)
|
|
48
61
|
return remote && kind ? { kind, ...remote } : null
|
package/plugins/form/index.ts
CHANGED
|
@@ -10,18 +10,25 @@ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
|
10
10
|
import { html, raw, type Block, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
11
11
|
import { chatThread } from '../chat/index.ts'
|
|
12
12
|
import { isQuestionName } from '../../src/status.ts'
|
|
13
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
13
14
|
|
|
14
|
-
const style =
|
|
15
|
+
const style = 'style.css'
|
|
15
16
|
|
|
16
17
|
const CHOICES = new Set(['radio', 'check', 'select', 'hidden'])
|
|
17
18
|
|
|
18
|
-
interface Node {
|
|
19
|
+
interface Node {
|
|
20
|
+
type: string
|
|
21
|
+
name?: string
|
|
22
|
+
attributes?: Record<string, string>
|
|
23
|
+
children?: Node[]
|
|
24
|
+
}
|
|
19
25
|
|
|
20
26
|
/** The inputs written inside a form's markdown (forms inside it excluded: forms don't nest). */
|
|
21
27
|
function inputsOf(nodes: Node[]) {
|
|
22
28
|
const found: { name: string; attrs: Record<string, string> }[] = []
|
|
23
29
|
const walk = (node: Node) => {
|
|
24
|
-
if ((node.type === 'textDirective' || node.type === 'leafDirective') && node.name)
|
|
30
|
+
if ((node.type === 'textDirective' || node.type === 'leafDirective') && node.name)
|
|
31
|
+
found.push({ name: node.name, attrs: node.attributes ?? {} })
|
|
25
32
|
if (node.type === 'containerDirective' && node.name === 'form') return
|
|
26
33
|
for (const child of node.children ?? []) walk(child)
|
|
27
34
|
}
|
|
@@ -37,15 +44,21 @@ const form: Block = {
|
|
|
37
44
|
const c = ctx as DirectiveContext
|
|
38
45
|
const name = c.attrs.name || c.attrs.id || 'form'
|
|
39
46
|
// a colon marks the events of whiteboard or a plugin (`chat:message`), never an answer
|
|
40
|
-
if (!isQuestionName(name))
|
|
47
|
+
if (!isQuestionName(name))
|
|
48
|
+
throw new Error(`form name "${name}" has a colon: those names are reserved for events of whiteboard and plugins`)
|
|
41
49
|
const inputs = inputsOf(c.children as Node[])
|
|
42
50
|
const choices = [...new Set(inputs.filter(i => CHOICES.has(i.name) && i.attrs.name).map(i => i.attrs.name))]
|
|
43
51
|
const hasButton = inputs.some(i => i.name === 'button')
|
|
44
52
|
// 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(
|
|
53
|
+
const body = (await c.toHtml(c.children)).replace(
|
|
54
|
+
'<button name="action"',
|
|
55
|
+
'<button class="wb-primary" name="action"',
|
|
56
|
+
)
|
|
46
57
|
// the form's chat: talk about the question, named after the form (see ../chat)
|
|
47
58
|
const thread = await chatThread(c, name, { choices })
|
|
48
|
-
return html`<form name="${name}" class="wb-form"
|
|
59
|
+
return html`<form name="${name}" class="wb-form">
|
|
60
|
+
${raw(body)}${!hasButton && html`<p><button class="wb-primary">Send</button></p>`}${raw(thread)}
|
|
61
|
+
</form>`
|
|
49
62
|
},
|
|
50
63
|
}
|
|
51
64
|
|
|
@@ -57,22 +70,44 @@ const labelOf = (c: DirectiveContext, fallback = '') => (c.label ? raw(c.label)
|
|
|
57
70
|
* the list: the option has a text box, typing in it picks the option, and it sends what was typed
|
|
58
71
|
* (the core's forms.ts, `data-wb-other`).
|
|
59
72
|
*/
|
|
60
|
-
const option =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
73
|
+
const option =
|
|
74
|
+
(type: 'radio' | 'checkbox'): Block['html'] =>
|
|
75
|
+
ctx => {
|
|
76
|
+
const c = ctx as DirectiveContext
|
|
77
|
+
if ('other' in c.attrs) {
|
|
78
|
+
const placeholder = c.attrs.placeholder ?? 'something else'
|
|
79
|
+
return html`<label class="wb-form-option wb-form-other"
|
|
80
|
+
><input type="${type}" name="${c.attrs.name}" value="" data-wb-other /><span class="wb-form-option-label"
|
|
81
|
+
>${labelOf(c, 'Other')}</span
|
|
82
|
+
><input
|
|
83
|
+
type="text"
|
|
84
|
+
class="wb-form-other-text"
|
|
85
|
+
data-wb-other-text
|
|
86
|
+
placeholder="${placeholder}"
|
|
87
|
+
aria-label="${c.labelText ?? 'Other'}"
|
|
88
|
+
/></label>`
|
|
89
|
+
}
|
|
90
|
+
const value = c.attrs.value ?? c.labelText ?? ''
|
|
91
|
+
return html`<label class="wb-form-option"
|
|
92
|
+
><input type="${type}" name="${c.attrs.name}" value="${value}" ${'checked' in c.attrs && raw(' checked')} /><span
|
|
93
|
+
class="wb-form-option-label"
|
|
94
|
+
>${labelOf(c, value)}</span
|
|
95
|
+
>${'recommended' in c.attrs && recommendedTag}</label
|
|
96
|
+
>`
|
|
65
97
|
}
|
|
66
|
-
const value = c.attrs.value ?? c.labelText ?? ''
|
|
67
|
-
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>`
|
|
68
|
-
}
|
|
69
98
|
|
|
70
99
|
/** :text[label]{name=… placeholder=…}, and number, date, range */
|
|
71
|
-
const field =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
100
|
+
const field =
|
|
101
|
+
(type: string): Block['html'] =>
|
|
102
|
+
ctx => {
|
|
103
|
+
const c = ctx as DirectiveContext
|
|
104
|
+
const extra = ['placeholder', 'min', 'max', 'step', 'value']
|
|
105
|
+
.filter(k => k in c.attrs)
|
|
106
|
+
.map(k => html` ${raw(k)}="${c.attrs[k]}"`)
|
|
107
|
+
return html`<label class="wb-form-field"
|
|
108
|
+
><span class="wb-form-label">${labelOf(c)}</span><input type="${type}" name="${c.attrs.name}" ${extra}
|
|
109
|
+
/></label>`
|
|
110
|
+
}
|
|
76
111
|
|
|
77
112
|
const input = (name: string, render: Block['html']): [string, Block] => [name, { html: render, style }]
|
|
78
113
|
|
|
@@ -83,20 +118,32 @@ const inputs: [string, Block][] = [
|
|
|
83
118
|
input('number', field('number')),
|
|
84
119
|
input('date', field('date')),
|
|
85
120
|
input('range', field('range')),
|
|
86
|
-
input('textarea',
|
|
121
|
+
input('textarea', ctx => {
|
|
87
122
|
const c = ctx as DirectiveContext
|
|
88
|
-
return html`<label class="wb-form-field"
|
|
123
|
+
return html`<label class="wb-form-field"
|
|
124
|
+
><span class="wb-form-label">${labelOf(c)}</span
|
|
125
|
+
><textarea name="${c.attrs.name}" rows="3" placeholder="${c.attrs.placeholder ?? ''}">
|
|
126
|
+
${c.attrs.value ?? ''}</textarea>
|
|
127
|
+
</label>`
|
|
89
128
|
}),
|
|
90
|
-
input('select',
|
|
129
|
+
input('select', ctx => {
|
|
91
130
|
const c = ctx as DirectiveContext
|
|
92
|
-
const options = (c.attrs.options ?? '')
|
|
93
|
-
|
|
131
|
+
const options = (c.attrs.options ?? '')
|
|
132
|
+
.split(',')
|
|
133
|
+
.map(s => s.trim())
|
|
134
|
+
.filter(Boolean)
|
|
135
|
+
return html`<label class="wb-form-field"
|
|
136
|
+
><span class="wb-form-label">${labelOf(c)}</span
|
|
137
|
+
><select name="${c.attrs.name}">
|
|
138
|
+
${options.map(o => html`<option${o === c.attrs.value && raw(' selected')}>${o}</option>`)}
|
|
139
|
+
</select></label
|
|
140
|
+
>`
|
|
94
141
|
}),
|
|
95
|
-
input('hidden',
|
|
142
|
+
input('hidden', ctx => {
|
|
96
143
|
const c = ctx as DirectiveContext
|
|
97
|
-
return html`<input type="hidden" name="${c.attrs.name}" value="${c.attrs.value ?? ''}"
|
|
144
|
+
return html`<input type="hidden" name="${c.attrs.name}" value="${c.attrs.value ?? ''}" />`
|
|
98
145
|
}),
|
|
99
|
-
input('button',
|
|
146
|
+
input('button', ctx => {
|
|
100
147
|
const c = ctx as DirectiveContext
|
|
101
148
|
const value = c.labelText ?? 'Send'
|
|
102
149
|
return html`<button name="action" value="${value}">${labelOf(c, 'Send')}</button>`
|
|
@@ -106,6 +153,7 @@ const inputs: [string, Block][] = [
|
|
|
106
153
|
export default function formPlugin(): Plugin {
|
|
107
154
|
return definePlugin({
|
|
108
155
|
name: 'form',
|
|
156
|
+
public: builtinPublic('form'),
|
|
109
157
|
blocks: { form, ...Object.fromEntries(inputs) },
|
|
110
158
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|
|
111
159
|
})
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/* a form reads as a set-off part of the article: hairline rules above and below, no box */
|
|
2
|
+
.wb-form {
|
|
3
|
+
margin: calc(var(--rhythm) * 3) 0;
|
|
4
|
+
padding: 1.6em 0 1.7em;
|
|
5
|
+
border-top: var(--hairline) solid var(--border);
|
|
6
|
+
border-bottom: var(--hairline) solid var(--border);
|
|
7
|
+
display: grid;
|
|
8
|
+
gap: var(--space-2xl);
|
|
9
|
+
}
|
|
10
|
+
.wb-form-pending {
|
|
11
|
+
min-height: 72px;
|
|
12
|
+
}
|
|
13
|
+
/* the form's body is markdown: its first and last blocks sit flush with the rules */
|
|
14
|
+
.wb-form > :first-child {
|
|
15
|
+
margin-top: 0;
|
|
16
|
+
}
|
|
17
|
+
.wb-form > :last-child {
|
|
18
|
+
margin-bottom: 0;
|
|
19
|
+
}
|
|
20
|
+
.wb-form > :is(p, ul, ol, table, .wb-grid, div) {
|
|
21
|
+
margin-top: 0;
|
|
22
|
+
margin-bottom: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* an inline option, :radio[…] or :check[…]: the input and its label read as one */
|
|
26
|
+
.wb-form-option {
|
|
27
|
+
display: inline-flex;
|
|
28
|
+
gap: var(--space-md);
|
|
29
|
+
align-items: baseline;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
}
|
|
32
|
+
.wb-form-option + .wb-form-option {
|
|
33
|
+
margin-left: var(--space-2xl);
|
|
34
|
+
}
|
|
35
|
+
.wb-form-option input {
|
|
36
|
+
margin: 0;
|
|
37
|
+
translate: 0 0.1em;
|
|
38
|
+
}
|
|
39
|
+
.wb-form-option-label {
|
|
40
|
+
font-weight: var(--weight-strong);
|
|
41
|
+
}
|
|
42
|
+
/* an answer not on the list: a text box in the option's line (`other`) */
|
|
43
|
+
.wb-form-other {
|
|
44
|
+
align-items: center;
|
|
45
|
+
}
|
|
46
|
+
.wb-form-other .wb-form-other-text {
|
|
47
|
+
translate: none;
|
|
48
|
+
font: inherit;
|
|
49
|
+
padding: var(--space-2xs) var(--space-md);
|
|
50
|
+
min-width: 12em;
|
|
51
|
+
border: var(--hairline) solid var(--border);
|
|
52
|
+
border-radius: var(--radius-sm);
|
|
53
|
+
background: var(--bg);
|
|
54
|
+
color: var(--text);
|
|
55
|
+
}
|
|
56
|
+
.wb-form-recommended {
|
|
57
|
+
font: 500 var(--ui-tiny)/var(--ui-line-height) var(--sans);
|
|
58
|
+
color: var(--muted);
|
|
59
|
+
letter-spacing: var(--caps-spacing);
|
|
60
|
+
text-transform: uppercase;
|
|
61
|
+
margin-left: var(--space-lg);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* a list item that starts with an option is a row to pick: no bullet, the picked one tinted, and
|
|
65
|
+
the rest of the item reads as what the option means */
|
|
66
|
+
.wb-form li:has(> p:first-child > .wb-form-option:first-child),
|
|
67
|
+
.wb-form li:has(> .wb-form-option:first-child) {
|
|
68
|
+
list-style: none;
|
|
69
|
+
margin-left: -1.2em;
|
|
70
|
+
padding: var(--space-sm) var(--space-lg);
|
|
71
|
+
border-radius: var(--radius-sm);
|
|
72
|
+
}
|
|
73
|
+
.wb-form li:has(> p:first-child > .wb-form-option:first-child):hover,
|
|
74
|
+
.wb-form li:has(> .wb-form-option:first-child):hover {
|
|
75
|
+
background: var(--tint);
|
|
76
|
+
}
|
|
77
|
+
.wb-form li:has(> p:first-child > .wb-form-option:first-child input:checked),
|
|
78
|
+
.wb-form li:has(> .wb-form-option:first-child input:checked) {
|
|
79
|
+
background: color-mix(in srgb, var(--accent) var(--tint-faint), transparent);
|
|
80
|
+
}
|
|
81
|
+
.wb-form li > p:first-child {
|
|
82
|
+
margin-bottom: 0.2em;
|
|
83
|
+
}
|
|
84
|
+
.wb-form li > p:first-child > .wb-form-option:first-child,
|
|
85
|
+
.wb-form li > .wb-form-option:first-child {
|
|
86
|
+
display: flex;
|
|
87
|
+
margin-bottom: 0.15em;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* fields: the label above the input */
|
|
91
|
+
.wb-form-field {
|
|
92
|
+
display: flex;
|
|
93
|
+
flex-direction: column;
|
|
94
|
+
gap: var(--space-sm);
|
|
95
|
+
margin: 0;
|
|
96
|
+
min-width: 0;
|
|
97
|
+
}
|
|
98
|
+
.wb-form-field :is(input:not([type='range']), textarea, select) {
|
|
99
|
+
width: 100%;
|
|
100
|
+
}
|
|
101
|
+
.wb-form-field textarea {
|
|
102
|
+
resize: vertical;
|
|
103
|
+
}
|
|
104
|
+
.wb-form-label {
|
|
105
|
+
font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
|
|
106
|
+
color: var(--muted);
|
|
107
|
+
letter-spacing: 0.01em;
|
|
108
|
+
}
|
|
109
|
+
.wb-form-label:empty {
|
|
110
|
+
display: none;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* buttons: the first one of a form is its primary one */
|
|
114
|
+
.wb-form button[name='action'] + button[name='action'] {
|
|
115
|
+
margin-left: var(--space-md);
|
|
116
|
+
}
|
|
117
|
+
.wb-form button.wb-primary {
|
|
118
|
+
background: var(--accent);
|
|
119
|
+
color: var(--accent-text);
|
|
120
|
+
border-color: var(--accent);
|
|
121
|
+
}
|
|
122
|
+
.wb-card .wb-form {
|
|
123
|
+
padding: 0;
|
|
124
|
+
border: 0;
|
|
125
|
+
margin: 0.6em 0 0;
|
|
126
|
+
}
|
|
@@ -50,10 +50,16 @@ function Gallery(props: { items: Item[]; min: string | null; narrow: boolean })
|
|
|
50
50
|
<img src={item().src ?? ''} alt={item().alt} />
|
|
51
51
|
<div class="wb-lightbox-caption" innerHTML={item().title ?? ''} />
|
|
52
52
|
<Show when={props.items.length > 1}>
|
|
53
|
-
<button type="button" class="wb-lightbox-prev" aria-label="Previous" onClick={() => step(-1)}
|
|
54
|
-
|
|
53
|
+
<button type="button" class="wb-lightbox-prev" aria-label="Previous" onClick={() => step(-1)}>
|
|
54
|
+
‹
|
|
55
|
+
</button>
|
|
56
|
+
<button type="button" class="wb-lightbox-next" aria-label="Next" onClick={() => step(1)}>
|
|
57
|
+
›
|
|
58
|
+
</button>
|
|
55
59
|
</Show>
|
|
56
|
-
<button type="button" class="wb-lightbox-close" aria-label="Close" onClick={() => setOpen(null)}
|
|
60
|
+
<button type="button" class="wb-lightbox-close" aria-label="Close" onClick={() => setOpen(null)}>
|
|
61
|
+
×
|
|
62
|
+
</button>
|
|
57
63
|
</div>
|
|
58
64
|
)}
|
|
59
65
|
</Show>
|
package/plugins/gallery/index.ts
CHANGED
|
@@ -3,20 +3,35 @@ import { definePlugin, type Plugin } from '@bigmistqke/whiteboard'
|
|
|
3
3
|
// Turns the block's content into gallery items: one per heading (first image in the section is
|
|
4
4
|
// its picture), or one per image when there are no headings.
|
|
5
5
|
import { escape, type DirectiveContext } from '@bigmistqke/whiteboard'
|
|
6
|
-
import {
|
|
6
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
7
7
|
|
|
8
|
-
interface Node {
|
|
9
|
-
|
|
8
|
+
interface Node {
|
|
9
|
+
type: string
|
|
10
|
+
depth?: number
|
|
11
|
+
url?: string
|
|
12
|
+
alt?: string
|
|
13
|
+
children?: Node[]
|
|
14
|
+
}
|
|
15
|
+
export interface Item {
|
|
16
|
+
src: string | null
|
|
17
|
+
alt: string
|
|
18
|
+
title: string | null
|
|
19
|
+
html: string
|
|
20
|
+
}
|
|
10
21
|
|
|
11
22
|
/** Remove and return the first image in a list of nodes (searching inside paragraphs). */
|
|
12
23
|
function takeImage(nodes: Node[]): Node | null {
|
|
13
24
|
for (let i = 0; i < nodes.length; i++) {
|
|
14
25
|
const n = nodes[i]
|
|
15
|
-
if (n.type === 'image') {
|
|
26
|
+
if (n.type === 'image') {
|
|
27
|
+
nodes.splice(i, 1)
|
|
28
|
+
return n
|
|
29
|
+
}
|
|
16
30
|
if (n.children) {
|
|
17
31
|
const found = takeImage(n.children)
|
|
18
32
|
if (found) {
|
|
19
|
-
if (n.type === 'paragraph' && n.children.every(c => c.type === 'text' && !String((c as any).value).trim()))
|
|
33
|
+
if (n.type === 'paragraph' && n.children.every(c => c.type === 'text' && !String((c as any).value).trim()))
|
|
34
|
+
nodes.splice(i, 1)
|
|
20
35
|
return found
|
|
21
36
|
}
|
|
22
37
|
}
|
|
@@ -38,12 +53,18 @@ export async function props(ctx: DirectiveContext) {
|
|
|
38
53
|
}
|
|
39
54
|
for (const g of groups) {
|
|
40
55
|
const img = takeImage(g.body)
|
|
41
|
-
items.push({
|
|
56
|
+
items.push({
|
|
57
|
+
src: img?.url ?? null,
|
|
58
|
+
alt: img?.alt ?? '',
|
|
59
|
+
title: await ctx.toHtml(g.heading.children ?? []),
|
|
60
|
+
html: await ctx.toHtml(g.body),
|
|
61
|
+
})
|
|
42
62
|
}
|
|
43
63
|
} else {
|
|
44
64
|
const walk = (nodes: Node[]) => {
|
|
45
65
|
for (const n of nodes) {
|
|
46
|
-
if (n.type === 'image')
|
|
66
|
+
if (n.type === 'image')
|
|
67
|
+
items.push({ src: n.url!, alt: n.alt ?? '', title: n.alt ? escape(n.alt) : null, html: '' })
|
|
47
68
|
else if (n.children) walk(n.children)
|
|
48
69
|
}
|
|
49
70
|
}
|
|
@@ -55,11 +76,12 @@ export async function props(ctx: DirectiveContext) {
|
|
|
55
76
|
export default function gallery(): Plugin {
|
|
56
77
|
return definePlugin({
|
|
57
78
|
name: 'gallery',
|
|
79
|
+
public: builtinPublic('gallery'),
|
|
58
80
|
blocks: {
|
|
59
81
|
gallery: {
|
|
60
82
|
props,
|
|
61
|
-
client:
|
|
62
|
-
style:
|
|
83
|
+
client: 'client.js',
|
|
84
|
+
style: 'style.css',
|
|
63
85
|
},
|
|
64
86
|
},
|
|
65
87
|
docs: () => fs.readFileSync(new URL('./README.md', import.meta.url), 'utf8'),
|