@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
package/src/client/forms.ts
CHANGED
|
@@ -15,21 +15,22 @@
|
|
|
15
15
|
// data-wb-decided an agent picked up its latest answer; data-wb-outcome quotes it in one line
|
|
16
16
|
// and, for a few seconds after a send went through, `data-wb-just-sent`, to confirm it
|
|
17
17
|
//
|
|
18
|
-
// How that looks is the page's: it styles the attributes, and can follow `api.
|
|
18
|
+
// How that looks is the page's: it styles the attributes, and can follow `api.forms.on`. A form
|
|
19
19
|
// marked `data-wb-self` (or inside an element that is) keeps its own fields: no drafts and no last
|
|
20
20
|
// answer are written into it, for a block's component that shows them itself.
|
|
21
21
|
import type { Api, FormState, FormStatus } from '../define'
|
|
22
22
|
import { STATES, isQuestionName, questionState } from '../status.ts'
|
|
23
|
+
import { reactive } from './reactive'
|
|
23
24
|
|
|
24
25
|
type Data = Record<string, unknown>
|
|
25
26
|
|
|
26
27
|
let root: HTMLElement
|
|
27
28
|
let api: Api
|
|
28
29
|
let page = ''
|
|
29
|
-
const listeners = new Set<(forms: FormStatus[]) => void>()
|
|
30
30
|
|
|
31
31
|
/** The forms the core looks after: named (a name without a colon: see isQuestionName), without an action. */
|
|
32
|
-
const managed = (form: HTMLFormElement) =>
|
|
32
|
+
const managed = (form: HTMLFormElement) =>
|
|
33
|
+
isQuestionName(form.getAttribute('name') ?? '') && !form.hasAttribute('action')
|
|
33
34
|
const forms = () => [...root.querySelectorAll('form')].filter(managed)
|
|
34
35
|
const keepsOwnFields = (form: HTMLFormElement) => !!form.closest('[data-wb-self]')
|
|
35
36
|
|
|
@@ -39,7 +40,8 @@ const keepsOwnFields = (form: HTMLFormElement) => !!form.closest('[data-wb-self]
|
|
|
39
40
|
// marked `data-wb-other`, with a text box (`data-wb-other-text`, no name of its own) in its label.
|
|
40
41
|
// It sends what was typed; typing picks it; an answer that is none of the other options goes back
|
|
41
42
|
// into its box.
|
|
42
|
-
const otherText = (option: HTMLInputElement) =>
|
|
43
|
+
const otherText = (option: HTMLInputElement) =>
|
|
44
|
+
option.closest('label')?.querySelector<HTMLInputElement>('[data-wb-other-text]') ?? null
|
|
43
45
|
const isOther = (el: Element): boolean => el instanceof HTMLInputElement && el.hasAttribute('data-wb-other')
|
|
44
46
|
|
|
45
47
|
function readForm(form: HTMLFormElement): Data {
|
|
@@ -49,12 +51,16 @@ function readForm(form: HTMLFormElement): Data {
|
|
|
49
51
|
for (const el of elements) if (el.name && el.type === 'checkbox') boxes[el.name] = (boxes[el.name] ?? 0) + 1
|
|
50
52
|
for (const el of elements) {
|
|
51
53
|
if (!el.name || el.type === 'submit' || el.type === 'button' || el.type === 'reset' || el.type === 'file') continue
|
|
52
|
-
|
|
54
|
+
// an other-option sends what was typed in its box: read, not written into the option (for a
|
|
55
|
+
// radio or checkbox that would change its value attribute, and so the page's HTML)
|
|
56
|
+
const value = isOther(el) ? (otherText(el)?.value.trim() ?? '') : el.value
|
|
53
57
|
if (el.type === 'checkbox') {
|
|
54
|
-
if (boxes[el.name] > 1) {
|
|
55
|
-
|
|
58
|
+
if (boxes[el.name] > 1) {
|
|
59
|
+
const list = (data[el.name] ??= []) as string[]
|
|
60
|
+
if (el.checked) list.push(value)
|
|
61
|
+
} else data[el.name] = el.checked
|
|
56
62
|
} else if (el.type === 'radio') {
|
|
57
|
-
if (el.checked) data[el.name] =
|
|
63
|
+
if (el.checked) data[el.name] = value
|
|
58
64
|
else data[el.name] ??= null
|
|
59
65
|
} else if ((el as unknown) instanceof HTMLSelectElement && (el as unknown as HTMLSelectElement).multiple) {
|
|
60
66
|
data[el.name] = [...(el as unknown as HTMLSelectElement).selectedOptions].map(o => o.value)
|
|
@@ -66,13 +72,18 @@ function readForm(form: HTMLFormElement): Data {
|
|
|
66
72
|
function writeForm(form: HTMLFormElement, data: Data) {
|
|
67
73
|
const elements = [...form.elements] as HTMLInputElement[]
|
|
68
74
|
// what the listed options of a name send, so an answer that is none of them is the other one's
|
|
69
|
-
const listed = (name: string) =>
|
|
75
|
+
const listed = (name: string) =>
|
|
76
|
+
elements
|
|
77
|
+
.filter(e => e.name === name && !isOther(e) && (e.type === 'radio' || e.type === 'checkbox'))
|
|
78
|
+
.map(e => e.value)
|
|
70
79
|
for (const el of elements) {
|
|
71
80
|
if (!el.name || !(el.name in data) || ['submit', 'button', 'hidden', 'file'].includes(el.type)) continue
|
|
72
81
|
const v = data[el.name]
|
|
73
82
|
if (isOther(el)) {
|
|
74
83
|
const own = listed(el.name)
|
|
75
|
-
const rest = (Array.isArray(v) ? v : [v]).filter(
|
|
84
|
+
const rest = (Array.isArray(v) ? v : [v]).filter(
|
|
85
|
+
x => typeof x === 'string' && x !== '' && !own.includes(x),
|
|
86
|
+
) as string[]
|
|
76
87
|
el.checked = rest.length > 0
|
|
77
88
|
const text = otherText(el)
|
|
78
89
|
if (text && text !== document.activeElement) text.value = rest.join(', ')
|
|
@@ -101,7 +112,11 @@ const draftKey = (form: HTMLFormElement) => `wb-draft:${page}:${form.getAttribut
|
|
|
101
112
|
function saveDraft(e: Event) {
|
|
102
113
|
const form = (e.target as Element | null)?.closest?.('form')
|
|
103
114
|
if (!form || !managed(form) || !root.contains(form) || keepsOwnFields(form)) return
|
|
104
|
-
try {
|
|
115
|
+
try {
|
|
116
|
+
localStorage.setItem(draftKey(form), JSON.stringify(readForm(form)))
|
|
117
|
+
} catch {
|
|
118
|
+
/* storage unavailable */
|
|
119
|
+
}
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
/** Unsent drafts back into their forms; a form being typed in is left alone. */
|
|
@@ -109,12 +124,22 @@ function restoreDrafts() {
|
|
|
109
124
|
for (const form of forms()) {
|
|
110
125
|
if (keepsOwnFields(form) || form.contains(document.activeElement)) continue
|
|
111
126
|
let draft: Data | null = null
|
|
112
|
-
try {
|
|
127
|
+
try {
|
|
128
|
+
draft = JSON.parse(localStorage.getItem(draftKey(form)) ?? 'null')
|
|
129
|
+
} catch {
|
|
130
|
+
/* storage unavailable */
|
|
131
|
+
}
|
|
113
132
|
if (draft) writeForm(form, draft)
|
|
114
133
|
}
|
|
115
134
|
}
|
|
116
135
|
|
|
117
|
-
const dropDraft = (form: HTMLFormElement) => {
|
|
136
|
+
const dropDraft = (form: HTMLFormElement) => {
|
|
137
|
+
try {
|
|
138
|
+
localStorage.removeItem(draftKey(form))
|
|
139
|
+
} catch {
|
|
140
|
+
/* storage unavailable */
|
|
141
|
+
}
|
|
142
|
+
}
|
|
118
143
|
|
|
119
144
|
/** Each form's last answer: its button in data-wb-sent, and with `prefill` its fields. */
|
|
120
145
|
function restoreLast(prefill: boolean) {
|
|
@@ -142,7 +167,10 @@ async function onSubmit(e: SubmitEvent) {
|
|
|
142
167
|
// folds because an agent picked the answer up at once
|
|
143
168
|
form.toggleAttribute('data-wb-just-sent', true)
|
|
144
169
|
clearTimeout(justSent.get(form))
|
|
145
|
-
justSent.set(
|
|
170
|
+
justSent.set(
|
|
171
|
+
form,
|
|
172
|
+
setTimeout(() => form.removeAttribute('data-wb-just-sent'), 3000),
|
|
173
|
+
)
|
|
146
174
|
} catch (err) {
|
|
147
175
|
form.dataset.wbState = 'failed'
|
|
148
176
|
console.error(err)
|
|
@@ -154,17 +182,34 @@ async function onSubmit(e: SubmitEvent) {
|
|
|
154
182
|
const ATTR: Record<FormState, string> = { open: 'data-wb-open', pending: 'data-wb-pending', decided: 'data-wb-decided' }
|
|
155
183
|
|
|
156
184
|
/** One line quoting an answer: what was chosen, then what was written. */
|
|
157
|
-
|
|
158
|
-
|
|
185
|
+
/**
|
|
186
|
+
* An answer, told apart: the button it was sent with (none for a plain Send), what was chosen
|
|
187
|
+
* (options, short values), and what was written.
|
|
188
|
+
*/
|
|
189
|
+
export function answerParts(
|
|
190
|
+
data: Data,
|
|
191
|
+
action: string | null,
|
|
192
|
+
): { action: string | null; chosen: string[]; written: string[] } {
|
|
193
|
+
const chosen: string[] = [],
|
|
194
|
+
written: string[] = []
|
|
159
195
|
for (const v of Object.values(data)) {
|
|
160
196
|
if (v == null || v === '' || v === false) continue
|
|
161
|
-
if (Array.isArray(v)) {
|
|
162
|
-
|
|
197
|
+
if (Array.isArray(v)) {
|
|
198
|
+
if (v.length) chosen.push(v.join(', '))
|
|
199
|
+
} else if (v === true) continue
|
|
163
200
|
else if (String(v).length > 60 || String(v).includes('\n')) written.push(String(v))
|
|
164
201
|
else chosen.push(String(v))
|
|
165
202
|
}
|
|
166
|
-
|
|
167
|
-
|
|
203
|
+
return { action: action && !['Send', 'Submit'].includes(action) ? action : null, chosen, written }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** One line quoting an answer: what was chosen, then what was written. */
|
|
207
|
+
function outcome(data: Data, action: string | null) {
|
|
208
|
+
const { action: button, chosen, written } = answerParts(data, action)
|
|
209
|
+
return [
|
|
210
|
+
[button, ...chosen].filter(Boolean).join(' · ') || 'sent',
|
|
211
|
+
...written.map(w => `“${w.length > 240 ? w.slice(0, 240) + '…' : w}”`),
|
|
212
|
+
].join('\n')
|
|
168
213
|
}
|
|
169
214
|
|
|
170
215
|
let current: FormStatus[] = []
|
|
@@ -181,7 +226,7 @@ function mark() {
|
|
|
181
226
|
else delete form.dataset.wbOutcome
|
|
182
227
|
return { form, name, state, last }
|
|
183
228
|
})
|
|
184
|
-
|
|
229
|
+
forms_.notify()
|
|
185
230
|
}
|
|
186
231
|
|
|
187
232
|
/** After the page re-rendered: answers, drafts and marks back on its forms. */
|
|
@@ -202,15 +247,16 @@ export function trackForms(el: HTMLElement, pageId: string, core: Api) {
|
|
|
202
247
|
document.addEventListener('change', saveDraft)
|
|
203
248
|
document.addEventListener('submit', onSubmit)
|
|
204
249
|
api.onRendered(refresh)
|
|
205
|
-
api.
|
|
206
|
-
api.
|
|
250
|
+
api.listeners.on(mark)
|
|
251
|
+
api.events.on(() => {
|
|
252
|
+
restoreLast(false)
|
|
253
|
+
mark()
|
|
254
|
+
})
|
|
207
255
|
restoreLast(true)
|
|
208
256
|
restoreDrafts()
|
|
209
257
|
mark()
|
|
210
258
|
}
|
|
211
259
|
|
|
212
|
-
/** For the api: every named form and where it stands,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
onForms(fn: (forms: FormStatus[]) => void) { listeners.add(fn); return () => { listeners.delete(fn) } },
|
|
216
|
-
}
|
|
260
|
+
/** For the api: every named form and where it stands, as it changes. */
|
|
261
|
+
const forms_ = reactive((): FormStatus[] => current)
|
|
262
|
+
export const formsApi = { forms: forms_ }
|
package/src/client/markdown.ts
CHANGED
|
@@ -10,16 +10,27 @@ async function flush() {
|
|
|
10
10
|
const batch = queue
|
|
11
11
|
queue = []
|
|
12
12
|
try {
|
|
13
|
-
const res = await fetch('/api/markdown', {
|
|
13
|
+
const res = await fetch('/api/markdown', {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: { 'content-type': 'application/json' },
|
|
16
|
+
body: JSON.stringify({ texts: batch.map(b => b.text) }),
|
|
17
|
+
})
|
|
14
18
|
if (!res.ok) throw new Error(await res.text())
|
|
15
|
-
const { html, styles } = await res.json() as { html: string[]; styles: string[] }
|
|
19
|
+
const { html, styles } = (await res.json()) as { html: string[]; styles: string[] }
|
|
16
20
|
for (const href of styles) {
|
|
17
|
-
if (
|
|
21
|
+
if (
|
|
22
|
+
![...document.querySelectorAll<HTMLLinkElement>('link[rel=stylesheet]')].some(
|
|
23
|
+
l => new URL(l.href).pathname === new URL(href, location.href).pathname,
|
|
24
|
+
)
|
|
25
|
+
)
|
|
18
26
|
document.head.insertAdjacentHTML('beforeend', `<link rel="stylesheet" href="${href.replace(/"/g, '"')}">`)
|
|
19
27
|
}
|
|
20
28
|
batch.forEach((b, i) => b.resolve(html[i] ?? ''))
|
|
21
29
|
} catch (err) {
|
|
22
|
-
for (const b of batch) {
|
|
30
|
+
for (const b of batch) {
|
|
31
|
+
cache.delete(b.text)
|
|
32
|
+
b.reject(err)
|
|
33
|
+
}
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
36
|
|