@bigmistqke/whiteboard 0.6.1 → 0.7.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 +13 -7
- package/dist/bin/whiteboard.js +0 -0
- package/dist/client/runtime.js +235 -58
- package/dist/plugins/badge/README.md +3 -1
- package/dist/plugins/badge/public/style.css +17 -0
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +9 -0
- package/dist/plugins/comments/public/client.js +7 -2
- package/dist/plugins/comments/public/style.css +4 -0
- package/dist/plugins/grid/public/style.css +0 -5
- package/dist/plugins/index.js +5 -1
- package/dist/plugins/timeline/README.md +40 -0
- package/dist/plugins/timeline/index.js +82 -0
- package/dist/plugins/timeline/public/style.css +118 -0
- package/dist/plugins/toc/README.md +13 -13
- package/dist/plugins/toc/index.js +5 -3
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +19 -2
- package/dist/solid/index.js +2 -1
- package/dist/src/auth.js +7 -3
- package/dist/src/client/page/base.css +74 -35
- package/dist/src/client/page/main.js +15 -4
- package/dist/src/events.js +4 -2
- package/dist/src/hub.js +43 -18
- package/dist/src/serve.js +2 -0
- package/dist/src/server.js +49 -11
- package/dist/src/ws.js +128 -0
- package/package.json +1 -1
- package/plugins/badge/README.md +3 -1
- package/plugins/badge/public/style.css +17 -0
- package/plugins/chat/client.tsx +34 -6
- package/plugins/chat/public/style.css +9 -0
- package/plugins/comments/client.ts +48 -5
- package/plugins/comments/public/style.css +4 -0
- package/plugins/grid/public/style.css +0 -5
- package/plugins/index.ts +6 -1
- package/plugins/timeline/README.md +40 -0
- package/plugins/timeline/index.ts +92 -0
- package/plugins/timeline/public/style.css +118 -0
- package/plugins/toc/README.md +13 -13
- package/plugins/toc/client.ts +49 -30
- package/plugins/toc/index.ts +12 -12
- package/plugins/toc/public/style.css +19 -2
- package/solid/index.tsx +3 -0
- package/src/auth.ts +7 -2
- package/src/client/forms.ts +102 -5
- package/src/client/page/base.css +74 -35
- package/src/client/page/elsewhere.ts +12 -3
- package/src/client/page/waiting.ts +10 -5
- package/src/client/read.ts +16 -3
- package/src/client/runtime.ts +134 -45
- package/src/client/toast.ts +35 -5
- package/src/define.ts +10 -0
- package/src/events.ts +7 -1
- package/src/hub.ts +54 -22
- package/src/serve.ts +2 -0
- package/src/server.ts +73 -17
- package/src/ws.ts +155 -0
package/plugins/toc/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// The table of contents (index.ts): built from the page's ##
|
|
1
|
+
// The table of contents (index.ts): built from the page's ## to ###### headings, again after each
|
|
2
2
|
// update; the section being read is the last heading above the top of the view; a section is
|
|
3
3
|
// marked when an open question (data-wb-open) or an unread message (data-wb-message, or the element
|
|
4
4
|
// holding one, data-wb-holds) is in it. A click scrolls to the heading, below the header.
|
|
@@ -14,6 +14,7 @@ const toggle = document.createElement('button')
|
|
|
14
14
|
toggle.type = 'button'
|
|
15
15
|
toggle.className = 'wb-toc-toggle'
|
|
16
16
|
toggle.title = toggle.ariaLabel = 'Contents'
|
|
17
|
+
toggle.setAttribute('aria-expanded', 'false')
|
|
17
18
|
toggle.innerHTML =
|
|
18
19
|
'<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 4h11M2.5 8h11M2.5 12h7"/></svg>'
|
|
19
20
|
|
|
@@ -66,6 +67,13 @@ function place() {
|
|
|
66
67
|
|
|
67
68
|
let handle: PageHandle
|
|
68
69
|
|
|
70
|
+
/** Opened from the header (or closed again): the panel shows, and the button says it is open. */
|
|
71
|
+
function setOpen(open: boolean) {
|
|
72
|
+
panel.classList.toggle('wb-toc-open', open)
|
|
73
|
+
panel.hidden = !open
|
|
74
|
+
toggle.setAttribute('aria-expanded', String(open))
|
|
75
|
+
}
|
|
76
|
+
|
|
69
77
|
/** Does this page have it: what its settings say, and whether it is on everywhere. */
|
|
70
78
|
function wanted() {
|
|
71
79
|
// its settings (`plugins: { toc: … }`): true, or { minWidth, maxWidth }: on; false: off; else as
|
|
@@ -77,27 +85,45 @@ function wanted() {
|
|
|
77
85
|
return always
|
|
78
86
|
}
|
|
79
87
|
|
|
88
|
+
/** A heading's text, without a badge that ends it (a status, not part of the title). */
|
|
89
|
+
function titleOf(h: HTMLElement) {
|
|
90
|
+
const copy = h.cloneNode(true) as HTMLElement
|
|
91
|
+
copy.querySelectorAll('.wb-badge').forEach(b => b.remove())
|
|
92
|
+
return copy.textContent?.trim() ?? ''
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const SECTIONS = ':scope > :is(h2, h3, h4, h5, h6)'
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The outline as nested lists: a heading's subsections in a list inside its item, which the style
|
|
99
|
+
* hangs on a rail under it. A level skipped (## then ####) nests once, under the nearest above.
|
|
100
|
+
*/
|
|
80
101
|
function build() {
|
|
81
|
-
headings = wanted() ? [...main.querySelectorAll<HTMLElement>(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
list
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
102
|
+
headings = wanted() ? [...main.querySelectorAll<HTMLElement>(SECTIONS)] : []
|
|
103
|
+
// the page's numbers: 1, 1.1, 1.1.1 (base.css counts ## to ###### alike)
|
|
104
|
+
const counts = [0, 0, 0, 0, 0]
|
|
105
|
+
const open: { level: number; list: HTMLOListElement; item?: HTMLLIElement }[] = [{ level: 1, list }]
|
|
106
|
+
list.replaceChildren()
|
|
107
|
+
headings.forEach((h, i) => {
|
|
108
|
+
const level = Number(h.tagName[1])
|
|
109
|
+
counts[level - 2]++
|
|
110
|
+
counts.fill(0, level - 1)
|
|
111
|
+
while (open.length > 1 && open.at(-1)!.level >= level) open.pop()
|
|
112
|
+
const parent = open.at(-1)!
|
|
113
|
+
if (parent.item && !parent.item.querySelector(':scope > ol')) parent.item.append(document.createElement('ol'))
|
|
114
|
+
const into = parent.item ? parent.item.querySelector<HTMLOListElement>(':scope > ol')! : parent.list
|
|
115
|
+
const li = document.createElement('li')
|
|
116
|
+
li.dataset.level = String(level)
|
|
117
|
+
const a = document.createElement('a')
|
|
118
|
+
a.href = '#'
|
|
119
|
+
a.dataset.index = String(i)
|
|
120
|
+
a.innerHTML = `<span class="wb-toc-number"></span><span class="wb-toc-text"></span>`
|
|
121
|
+
a.querySelector('.wb-toc-number')!.textContent = counts.slice(0, level - 1).join('.')
|
|
122
|
+
a.querySelector('.wb-toc-text')!.textContent = titleOf(h)
|
|
123
|
+
li.append(a)
|
|
124
|
+
into.append(li)
|
|
125
|
+
open.push({ level, list: into, item: li })
|
|
126
|
+
})
|
|
101
127
|
const any = headings.length > 1
|
|
102
128
|
bounds()
|
|
103
129
|
place()
|
|
@@ -156,10 +182,7 @@ function go(i: number) {
|
|
|
156
182
|
const h = headings[i]
|
|
157
183
|
if (!h) return
|
|
158
184
|
scrollTo({ top: Math.max(0, scrollY + h.getBoundingClientRect().top - navHeight() - 12), behavior: 'smooth' })
|
|
159
|
-
if (!fits())
|
|
160
|
-
panel.classList.remove('wb-toc-open')
|
|
161
|
-
panel.hidden = true
|
|
162
|
-
}
|
|
185
|
+
if (!fits()) setOpen(false)
|
|
163
186
|
}
|
|
164
187
|
|
|
165
188
|
const mount: PluginMount = (root, page, core) => {
|
|
@@ -175,11 +198,7 @@ const mount: PluginMount = (root, page, core) => {
|
|
|
175
198
|
e.preventDefault()
|
|
176
199
|
go(Number(a.dataset.index))
|
|
177
200
|
})
|
|
178
|
-
toggle.addEventListener('click', () =>
|
|
179
|
-
const open = !panel.classList.contains('wb-toc-open')
|
|
180
|
-
panel.classList.toggle('wb-toc-open', open)
|
|
181
|
-
panel.hidden = !open
|
|
182
|
-
})
|
|
201
|
+
toggle.addEventListener('click', () => setOpen(!panel.classList.contains('wb-toc-open')))
|
|
183
202
|
document.addEventListener('keydown', e => {
|
|
184
203
|
if (e.key === 'Escape' && panel.classList.contains('wb-toc-open')) toggle.click()
|
|
185
204
|
})
|
package/plugins/toc/index.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
// A table of contents beside the page: its sections (##
|
|
2
|
-
// numbers them, the one being read marked, a dot where
|
|
3
|
-
// unanswered question, an unread message). In the margin left
|
|
4
|
-
// for it; else a button in the header that opens it.
|
|
1
|
+
// A table of contents beside the page: its sections (## to ###### headings), numbered as the page
|
|
2
|
+
// numbers them, each one's subsections on a rail under it, the one being read marked, a dot where
|
|
3
|
+
// something waits for the reader (an unanswered question, an unread message). In the margin left
|
|
4
|
+
// of the text when the window has room for it; else a button in the header that opens it.
|
|
5
5
|
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
// A page has it when its frontmatter says so, under `plugins:` (`plugins: { toc: true }`). With
|
|
10
|
-
// `toc({ always: true })`, every page has it, unless its frontmatter says `toc: false` there.
|
|
6
|
+
// Built in (plugins/index.ts): a page has it when its frontmatter says so, under `plugins:`
|
|
7
|
+
// (`plugins: { toc: true }`). A config that replaces it with `toc({ always: true })` puts it on
|
|
8
|
+
// every page, unless a page's frontmatter says `toc: false` there.
|
|
11
9
|
import { builtinPublic } from '../../src/package.ts'
|
|
12
10
|
import { html } from '../../src/html.ts'
|
|
13
11
|
import type { Plugin } from '../../src/define.ts'
|
|
14
12
|
|
|
15
13
|
const DOCS = `## Table of contents
|
|
16
14
|
|
|
17
|
-
Pages here have a table of contents beside them, made from their
|
|
18
|
-
|
|
19
|
-
in it.
|
|
15
|
+
Pages here have a table of contents beside them, made from their headings,
|
|
16
|
+
\`##\` down to \`######\`: give a long page headings, and the reader can find
|
|
17
|
+
their way in it. Each section's subsections hang on a line under it, so the
|
|
18
|
+
nesting shows. A section with an unanswered question or an unread message has
|
|
19
|
+
a dot.
|
|
20
20
|
`
|
|
21
21
|
|
|
22
22
|
export interface TocOptions {
|
|
@@ -38,8 +38,19 @@
|
|
|
38
38
|
margin: 0;
|
|
39
39
|
padding: 0;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
/* the same space above every item, also the first of a nested list (the page's li + li alone
|
|
42
|
+
would leave that one tight against its section) */
|
|
43
|
+
.wb-toc li {
|
|
44
|
+
margin-top: 0.8em;
|
|
45
|
+
}
|
|
46
|
+
.wb-toc > ol > li:first-child {
|
|
47
|
+
margin-top: 0;
|
|
48
|
+
}
|
|
49
|
+
/* a section's subsections hang on a rail under its number, one rail per level */
|
|
50
|
+
.wb-toc ol ol {
|
|
51
|
+
margin-left: var(--space-md);
|
|
52
|
+
padding-left: var(--space-sm);
|
|
53
|
+
border-left: var(--hairline) solid var(--border, #e3e5e9);
|
|
43
54
|
}
|
|
44
55
|
.wb-toc a {
|
|
45
56
|
display: flex;
|
|
@@ -97,3 +108,9 @@
|
|
|
97
108
|
color: var(--text, CanvasText);
|
|
98
109
|
border-color: var(--muted, #696e76);
|
|
99
110
|
}
|
|
111
|
+
/* the panel is open from it */
|
|
112
|
+
.wb-toc-toggle[aria-expanded='true'] {
|
|
113
|
+
color: var(--accent, #1d5bbf);
|
|
114
|
+
border-color: var(--accent, #1d5bbf);
|
|
115
|
+
background: color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-faint), transparent);
|
|
116
|
+
}
|
package/solid/index.tsx
CHANGED
|
@@ -30,6 +30,8 @@ export interface Whiteboard {
|
|
|
30
30
|
unread(): WbEvent[]
|
|
31
31
|
/** a message's markdown as HTML, rendered by the server (see Api.markdown) */
|
|
32
32
|
markdown: ClientApi['markdown']
|
|
33
|
+
/** a short note in the page's corner (see Api.toast) */
|
|
34
|
+
toast: ClientApi['toast']
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const WhiteboardContext = createContext<Whiteboard>()
|
|
@@ -64,6 +66,7 @@ export function solid<Props extends object>(Component: Component<Props>): Mount<
|
|
|
64
66
|
forms,
|
|
65
67
|
unread,
|
|
66
68
|
markdown: api.markdown,
|
|
69
|
+
toast: api.toast,
|
|
67
70
|
}
|
|
68
71
|
return (
|
|
69
72
|
<WhiteboardContext value={value}>
|
package/src/auth.ts
CHANGED
|
@@ -32,6 +32,12 @@ export function projectToken(wb: string): string {
|
|
|
32
32
|
return token
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/** From a page of a whiteboard server on this machine, or from no page at all (the command line)? */
|
|
36
|
+
export const sameSite = (req: IncomingMessage): boolean => {
|
|
37
|
+
const origin = req.headers.origin
|
|
38
|
+
return !origin || /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)
|
|
39
|
+
}
|
|
40
|
+
|
|
35
41
|
/** `base`: the path the project is served under (see ServerOptions), which its cookie is kept to. */
|
|
36
42
|
export function createAuth(wb: string, base = '') {
|
|
37
43
|
const token = projectToken(wb)
|
|
@@ -51,8 +57,7 @@ export function createAuth(wb: string, base = '') {
|
|
|
51
57
|
const jar = cookies(req)
|
|
52
58
|
const has = same(jar[COOKIE], token) || same(req.headers['x-whiteboard-token'], token)
|
|
53
59
|
if (!has) return false
|
|
54
|
-
|
|
55
|
-
if (origin && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)) return false
|
|
60
|
+
if (!sameSite(req)) return false
|
|
56
61
|
const site = req.headers['sec-fetch-site']
|
|
57
62
|
if (site && site !== 'same-origin' && site !== 'none' && !opensPage(req)) return false
|
|
58
63
|
return true
|
package/src/client/forms.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
// every page.
|
|
5
5
|
//
|
|
6
6
|
// What the core does with such a form, without drawing anything:
|
|
7
|
-
// - sends a submit as an event, and says how that went: `data-wb-state`
|
|
7
|
+
// - sends a submit as an event, shown at once (optimistic), and says how that went: `data-wb-state`
|
|
8
|
+
// is sending (shown, not yet confirmed), sent or failed (taken back);
|
|
8
9
|
// - keeps what the reader typed until it is sent (localStorage, per page and form), across
|
|
9
10
|
// re-renders and reloads;
|
|
10
11
|
// - puts the last answer back into the form, and its button in `data-wb-sent`;
|
|
@@ -152,34 +153,129 @@ function restoreLast(prefill: boolean) {
|
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
155
|
|
|
156
|
+
/** What each form is sending now, as sent: the same answer again is not sent twice. */
|
|
157
|
+
const inFlight = new WeakMap<HTMLFormElement, string>()
|
|
158
|
+
|
|
159
|
+
// The button that sent it says how that goes, in its own text and colour (`data-wb-send` on it):
|
|
160
|
+
// "Sending…" (grey) while on its way, "✓ Sent" (green) a moment once the server has it, then its own
|
|
161
|
+
// label again; "Try again" (red) when no try got through, until it is pressed. It keeps its width
|
|
162
|
+
// meanwhile.
|
|
163
|
+
type Send = 'sending' | 'sent' | 'failed'
|
|
164
|
+
/** A button's own label, while it says how a send goes. */
|
|
165
|
+
const labelOf = (button: HTMLButtonElement) => {
|
|
166
|
+
const el = document.createElement('div')
|
|
167
|
+
el.innerHTML = labels.get(button)!.html
|
|
168
|
+
return el.textContent?.trim() ?? ''
|
|
169
|
+
}
|
|
170
|
+
const SEND_TEXT: Record<Send, string> = { sending: 'Sending…', sent: '✓ Sent', failed: 'Try again' }
|
|
171
|
+
const labels = new WeakMap<HTMLButtonElement, { html: string; timer?: ReturnType<typeof setTimeout> }>()
|
|
172
|
+
|
|
173
|
+
function sendState(button: HTMLButtonElement | null, state: Send | null) {
|
|
174
|
+
if (!button) return
|
|
175
|
+
let saved = labels.get(button)
|
|
176
|
+
clearTimeout(saved?.timer)
|
|
177
|
+
if (!state) {
|
|
178
|
+
if (!saved) return
|
|
179
|
+
button.innerHTML = saved.html
|
|
180
|
+
button.style.minWidth = ''
|
|
181
|
+
delete button.dataset.wbSend
|
|
182
|
+
labels.delete(button)
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
if (!saved) {
|
|
186
|
+
saved = { html: button.innerHTML }
|
|
187
|
+
labels.set(button, saved)
|
|
188
|
+
button.style.minWidth = `${button.getBoundingClientRect().width}px`
|
|
189
|
+
}
|
|
190
|
+
button.dataset.wbSend = state
|
|
191
|
+
button.textContent = SEND_TEXT[state]
|
|
192
|
+
// confirmed: said for a moment, then the button is itself again
|
|
193
|
+
if (state === 'sent') saved.timer = setTimeout(() => sendState(button, null), 2000)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Optimistic: the answer is the form's at once (api.append puts it in the events, so the form is
|
|
197
|
+
// marked pending), with `data-wb-state="sending"` saying it is still on its way, and its button
|
|
198
|
+
// saying so (sendState); `sent` once the server has it, with the short `data-wb-just-sent` to
|
|
199
|
+
// confirm it. Should it not get through, the answer leaves the form again: `failed`, the button
|
|
200
|
+
// the form had before, the draft kept.
|
|
155
201
|
async function onSubmit(e: SubmitEvent) {
|
|
156
202
|
const form = e.target as HTMLFormElement
|
|
157
203
|
if (!managed(form) || !root.contains(form)) return
|
|
158
204
|
e.preventDefault()
|
|
159
205
|
const button = e.submitter as HTMLButtonElement | null
|
|
160
|
-
|
|
206
|
+
// its label as it is, not as it says how a send goes
|
|
207
|
+
const label = button ? (labels.get(button) ? labelOf(button) : button.textContent?.trim()) : null
|
|
208
|
+
const action = button ? button.value || label || null : null
|
|
209
|
+
const data = readForm(form)
|
|
210
|
+
const sent = JSON.stringify([action, data])
|
|
211
|
+
if (inFlight.get(form) === sent) return
|
|
212
|
+
inFlight.set(form, sent)
|
|
213
|
+
const before = form.dataset.wbSent
|
|
161
214
|
form.dataset.wbState = 'sending'
|
|
215
|
+
form.dataset.wbSent = action ?? ''
|
|
216
|
+
form.removeAttribute('data-wb-just-sent')
|
|
217
|
+
sendState(button, 'sending')
|
|
218
|
+
showStatus(form)
|
|
162
219
|
try {
|
|
163
|
-
await api.append(form.getAttribute('name')!,
|
|
220
|
+
await api.append(form.getAttribute('name')!, data, action)
|
|
221
|
+
if (inFlight.get(form) !== sent) return // a newer answer took its place
|
|
164
222
|
dropDraft(form)
|
|
165
223
|
form.dataset.wbState = 'sent'
|
|
166
|
-
|
|
224
|
+
sendState(button, 'sent')
|
|
167
225
|
// for the page to confirm the send: set for a few seconds after it, also once the form
|
|
168
226
|
// folds because an agent picked the answer up at once
|
|
169
227
|
form.toggleAttribute('data-wb-just-sent', true)
|
|
170
228
|
clearTimeout(justSent.get(form))
|
|
171
229
|
justSent.set(
|
|
172
230
|
form,
|
|
173
|
-
setTimeout(() =>
|
|
231
|
+
setTimeout(() => {
|
|
232
|
+
form.removeAttribute('data-wb-just-sent')
|
|
233
|
+
showStatus(form)
|
|
234
|
+
}, 3000),
|
|
174
235
|
)
|
|
236
|
+
showStatus(form)
|
|
175
237
|
} catch (err) {
|
|
238
|
+
if (inFlight.get(form) !== sent) return
|
|
176
239
|
form.dataset.wbState = 'failed'
|
|
240
|
+
sendState(button, 'failed')
|
|
241
|
+
if (before == null) delete form.dataset.wbSent
|
|
242
|
+
else form.dataset.wbSent = before
|
|
243
|
+
showStatus(form)
|
|
177
244
|
console.error(err)
|
|
245
|
+
} finally {
|
|
246
|
+
if (inFlight.get(form) === sent) inFlight.delete(form)
|
|
178
247
|
}
|
|
179
248
|
}
|
|
180
249
|
|
|
181
250
|
// ---- where each form stands --------------------------------------------------------------------
|
|
182
251
|
|
|
252
|
+
// What a sent answer came to, said beside the form's last send button, where the eye is when it is
|
|
253
|
+
// pressed (a line over the form was out of view below a long list of options): `.wb-form-status`,
|
|
254
|
+
// "waiting for the agent to pick it up", or `data-kind="bad"` "couldn't send it". Never what the
|
|
255
|
+
// button says already (sendState): nothing while sending, no "sent".
|
|
256
|
+
const sendButtons = (form: HTMLFormElement) =>
|
|
257
|
+
[...form.querySelectorAll<HTMLButtonElement | HTMLInputElement>('button, input[type=submit]')].filter(
|
|
258
|
+
b => (b instanceof HTMLInputElement || (b.type !== 'button' && b.type !== 'reset')) && b.form === form,
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
function showStatus(form: HTMLFormElement) {
|
|
262
|
+
const text =
|
|
263
|
+
form.dataset.wbState === 'failed'
|
|
264
|
+
? (["couldn't send it", 'bad'] as const)
|
|
265
|
+
: form.dataset.wbState === 'sending' || !form.hasAttribute('data-wb-pending')
|
|
266
|
+
? null
|
|
267
|
+
: (['waiting for the agent to pick it up', null] as const)
|
|
268
|
+
let el = form.querySelector<HTMLElement>('.wb-form-status')
|
|
269
|
+
const last = sendButtons(form).at(-1)
|
|
270
|
+
if (!text || !last) return void el?.remove()
|
|
271
|
+
if (!el) el = Object.assign(document.createElement('span'), { className: 'wb-form-status' })
|
|
272
|
+
el.setAttribute('role', 'status')
|
|
273
|
+
if (el.previousElementSibling !== last) last.after(el)
|
|
274
|
+
el.textContent = text[0]
|
|
275
|
+
if (text[1]) el.dataset.kind = text[1]
|
|
276
|
+
else delete el.dataset.kind
|
|
277
|
+
}
|
|
278
|
+
|
|
183
279
|
const ATTR: Record<FormState, string> = { open: 'data-wb-open', pending: 'data-wb-pending', decided: 'data-wb-decided' }
|
|
184
280
|
|
|
185
281
|
/** One line quoting an answer: what was chosen, then what was written. */
|
|
@@ -225,6 +321,7 @@ function mark() {
|
|
|
225
321
|
for (const st of STATES) form.toggleAttribute(ATTR[st], st === state)
|
|
226
322
|
if (state === 'decided') form.dataset.wbOutcome = outcome(last!.data, last!.action)
|
|
227
323
|
else delete form.dataset.wbOutcome
|
|
324
|
+
showStatus(form)
|
|
228
325
|
return { form, name, state, last }
|
|
229
326
|
})
|
|
230
327
|
forms_.notify()
|
package/src/client/page/base.css
CHANGED
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
--warn: light-dark(#6b4fc0, #b4a0ff);
|
|
20
20
|
--bad: light-dark(#c4352b, #ff6f66);
|
|
21
21
|
--info: light-dark(#1d5bbf, #82aaff);
|
|
22
|
+
/* what the reader sent, shown at once but not yet confirmed by the server (an event with
|
|
23
|
+
`sending`): grey, in whatever carries it (a button, a bubble, a comment's text). Confirmed, it
|
|
24
|
+
takes its usual colour (a button flashes --ok first); never got there, --bad */
|
|
25
|
+
--wb-sending: light-dark(#9a9fa7, #6c717a);
|
|
22
26
|
--shadow: none;
|
|
23
27
|
|
|
24
28
|
/* Type. The article is set in --serif at --text-size; everything in it (its margins, its
|
|
@@ -302,7 +306,7 @@ hr::after {
|
|
|
302
306
|
letter-spacing: 0.3em;
|
|
303
307
|
}
|
|
304
308
|
|
|
305
|
-
/* section numbers hanging in the margin: 1, 1.1, 1.1.1, in italic oldstyle figures. Only the
|
|
309
|
+
/* section numbers hanging in the margin: 1, 1.1, 1.1.1, down to h6, in italic oldstyle figures. Only the
|
|
306
310
|
page's own headings (direct children of main), so headings inside cards stay unnumbered. The
|
|
307
311
|
number is an inline-block pulled into the margin, so it shares the heading's baseline. */
|
|
308
312
|
#wb-main {
|
|
@@ -318,8 +322,16 @@ hr::after {
|
|
|
318
322
|
}
|
|
319
323
|
#wb-main > h4 {
|
|
320
324
|
counter-increment: h4;
|
|
325
|
+
counter-reset: h5;
|
|
321
326
|
}
|
|
322
|
-
#wb-main >
|
|
327
|
+
#wb-main > h5 {
|
|
328
|
+
counter-increment: h5;
|
|
329
|
+
counter-reset: h6;
|
|
330
|
+
}
|
|
331
|
+
#wb-main > h6 {
|
|
332
|
+
counter-increment: h6;
|
|
333
|
+
}
|
|
334
|
+
#wb-main > :is(h2, h3, h4, h5, h6)::before {
|
|
323
335
|
display: inline-block;
|
|
324
336
|
box-sizing: content-box;
|
|
325
337
|
width: 64px;
|
|
@@ -347,12 +359,18 @@ hr::after {
|
|
|
347
359
|
content: counter(h2) '.' counter(h3) '.' counter(h4);
|
|
348
360
|
font-size: 1.3em;
|
|
349
361
|
}
|
|
362
|
+
#wb-main > h5::before {
|
|
363
|
+
content: counter(h2) '.' counter(h3) '.' counter(h4) '.' counter(h5);
|
|
364
|
+
}
|
|
365
|
+
#wb-main > h6::before {
|
|
366
|
+
content: counter(h2) '.' counter(h3) '.' counter(h4) '.' counter(h5) '.' counter(h6);
|
|
367
|
+
}
|
|
350
368
|
/* no margin to hang them in: set the number in front of the heading, and indent less */
|
|
351
369
|
@media (max-width: 860px) {
|
|
352
370
|
main {
|
|
353
371
|
--indent: 0px;
|
|
354
372
|
}
|
|
355
|
-
#wb-main > :is(h2, h3, h4)::before {
|
|
373
|
+
#wb-main > :is(h2, h3, h4, h5, h6)::before {
|
|
356
374
|
width: auto;
|
|
357
375
|
margin-left: 0;
|
|
358
376
|
margin-right: 0.6em;
|
|
@@ -682,14 +700,32 @@ form.wb-form[data-wb-folded] {
|
|
|
682
700
|
gap: 0;
|
|
683
701
|
}
|
|
684
702
|
/* named forms: the core marks where each stands (data-wb-open, -pending, -decided); this is how that looks */
|
|
685
|
-
form
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
form[data-wb-
|
|
690
|
-
|
|
703
|
+
/* the button a form was sent with says how that goes (forms.ts): the answer is the form's already
|
|
704
|
+
(optimistic), the button grey while the server hasn't confirmed it, green a moment once it has,
|
|
705
|
+
red ("Try again") when it never got there. The form stays usable: the same answer isn't sent twice. !important: a send's
|
|
706
|
+
state outranks however a plugin or the project styles its buttons (.wb-primary) */
|
|
707
|
+
form button[data-wb-send] {
|
|
708
|
+
transition:
|
|
709
|
+
background-color 0.2s,
|
|
710
|
+
border-color 0.2s,
|
|
711
|
+
color 0.2s;
|
|
712
|
+
}
|
|
713
|
+
form button[data-wb-send='sending'] {
|
|
714
|
+
background: var(--wb-sending) !important;
|
|
715
|
+
border-color: var(--wb-sending) !important;
|
|
716
|
+
color: var(--bg) !important;
|
|
691
717
|
cursor: progress;
|
|
692
718
|
}
|
|
719
|
+
form button[data-wb-send='sent'] {
|
|
720
|
+
background: var(--ok) !important;
|
|
721
|
+
border-color: var(--ok) !important;
|
|
722
|
+
color: var(--bg) !important;
|
|
723
|
+
}
|
|
724
|
+
form button[data-wb-send='failed'] {
|
|
725
|
+
background: var(--bad) !important;
|
|
726
|
+
border-color: var(--bad) !important;
|
|
727
|
+
color: var(--bg) !important;
|
|
728
|
+
}
|
|
693
729
|
/* just sent: a short green flash, and a line saying what happened, for a few seconds */
|
|
694
730
|
@keyframes wb-sent {
|
|
695
731
|
from {
|
|
@@ -702,23 +738,16 @@ form[data-wb-state='sending'] button {
|
|
|
702
738
|
form[data-wb-just-sent] {
|
|
703
739
|
animation: wb-sent 1.4s ease-out;
|
|
704
740
|
}
|
|
705
|
-
form
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
margin-
|
|
709
|
-
color: var(--
|
|
710
|
-
font: var(--
|
|
711
|
-
}
|
|
712
|
-
form[data-wb-sent]:not(.wb-form)::after {
|
|
713
|
-
content: '✓ sent ' attr(data-wb-sent);
|
|
714
|
-
display: block;
|
|
715
|
-
margin-top: var(--space-sm);
|
|
716
|
-
color: var(--ok);
|
|
717
|
-
font: var(--ui-small) var(--sans);
|
|
741
|
+
/* what a sent answer came to, beside the form's last send button (forms.ts): waiting for the agent
|
|
742
|
+
(muted), couldn't send (red) */
|
|
743
|
+
.wb-form-status {
|
|
744
|
+
margin-left: var(--space-md);
|
|
745
|
+
color: var(--muted);
|
|
746
|
+
font: var(--ui-tiny)/var(--ui-line-height) var(--sans);
|
|
718
747
|
}
|
|
719
|
-
form[data-
|
|
720
|
-
content: 'failed to send';
|
|
748
|
+
.wb-form-status[data-kind='bad'] {
|
|
721
749
|
color: var(--bad);
|
|
750
|
+
font-weight: var(--weight-strong);
|
|
722
751
|
}
|
|
723
752
|
|
|
724
753
|
/* a question the reader hasn't answered, or one the agent asks again: outlined, without a label of
|
|
@@ -730,21 +759,25 @@ form[data-wb-open] {
|
|
|
730
759
|
}
|
|
731
760
|
/* the outline sets it off: the form's rules above and below (its borders, which the outline would
|
|
732
761
|
enclose) step aside meanwhile */
|
|
733
|
-
form.wb-form[data-wb-open] {
|
|
762
|
+
form.wb-form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
|
|
734
763
|
border-top-color: transparent;
|
|
735
764
|
border-bottom-color: transparent;
|
|
736
765
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
font: var(--ui-tiny)/var(--ui-line-height) var(--sans);
|
|
766
|
+
/* the outline speaks the language of a send too: grey while the answer is on its way (it is the
|
|
767
|
+
form's already, so no longer outlined as unanswered) and while it waits for the agent to pick it
|
|
768
|
+
up, red when it never got there; gone once the agent took it (decided) */
|
|
769
|
+
form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
|
|
770
|
+
transition: outline-color 0.2s;
|
|
743
771
|
}
|
|
744
|
-
form[data-wb-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
772
|
+
form:is([data-wb-state='sending'], [data-wb-pending]) {
|
|
773
|
+
outline: 2px solid var(--wb-sending);
|
|
774
|
+
outline-offset: 10px;
|
|
775
|
+
border-radius: var(--radius-sm);
|
|
776
|
+
}
|
|
777
|
+
form[data-wb-state='failed'] {
|
|
778
|
+
outline: 2px solid var(--bad);
|
|
779
|
+
outline-offset: 10px;
|
|
780
|
+
border-radius: var(--radius-sm);
|
|
748
781
|
}
|
|
749
782
|
|
|
750
783
|
/* decided: the agent picked up the latest answer; the form folds into one line quoting it */
|
|
@@ -1236,3 +1269,9 @@ main:has(+ .wb-orphans:not([hidden])) {
|
|
|
1236
1269
|
:root[data-wb-window-maximized] {
|
|
1237
1270
|
overflow: hidden;
|
|
1238
1271
|
}
|
|
1272
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1273
|
+
form button[data-wb-send],
|
|
1274
|
+
form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
|
|
1275
|
+
transition: none;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
@@ -110,12 +110,20 @@ async function load() {
|
|
|
110
110
|
)
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
// several changes at once (an answer is an event and a listener less) load once
|
|
113
|
+
// several changes at once (an answer is an event and a listener less) load once; a hidden tab
|
|
114
|
+
// loads once it is shown, and not before (the index asks every project of the server)
|
|
114
115
|
let timer = 0
|
|
116
|
+
let stale = false
|
|
115
117
|
const reload = () => {
|
|
116
118
|
clearTimeout(timer)
|
|
119
|
+
if (document.hidden) return void (stale = true)
|
|
117
120
|
timer = window.setTimeout(load, 100)
|
|
118
121
|
}
|
|
122
|
+
document.addEventListener('visibilitychange', () => {
|
|
123
|
+
if (document.hidden || !stale) return
|
|
124
|
+
stale = false
|
|
125
|
+
reload()
|
|
126
|
+
})
|
|
119
127
|
|
|
120
128
|
export function trackElsewhere(root: HTMLElement, handle: PageHandle, core: Api) {
|
|
121
129
|
current = handle.id
|
|
@@ -138,6 +146,7 @@ export function trackElsewhere(root: HTMLElement, handle: PageHandle, core: Api)
|
|
|
138
146
|
core.listeners.on(reload)
|
|
139
147
|
handle.onChange(reload)
|
|
140
148
|
load()
|
|
141
|
-
//
|
|
142
|
-
|
|
149
|
+
// another project's pages, log or listeners changed: the shared server says so on the live
|
|
150
|
+
// channel (and the channel opening again may have missed some)
|
|
151
|
+
if (base) document.addEventListener('wb-elsewhere', reload)
|
|
143
152
|
}
|
|
@@ -280,12 +280,17 @@ export function trackWaiting(root: HTMLElement, core: Api) {
|
|
|
280
280
|
if (form.dataset.wbState === 'sending') return
|
|
281
281
|
sent.disconnect()
|
|
282
282
|
if (form.dataset.wbState !== 'sent') return
|
|
283
|
-
if (fallback)
|
|
283
|
+
if (fallback)
|
|
284
|
+
api.toast('Sent · to the fallback agent', {
|
|
285
|
+
name: 'sent',
|
|
286
|
+
details: 'No agent waits on this page, so the fallback agent picks it up.',
|
|
287
|
+
})
|
|
284
288
|
else
|
|
285
|
-
api.toast(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
+
api.toast('Sent · no agent listening', {
|
|
290
|
+
kind: 'warn',
|
|
291
|
+
name: 'sent',
|
|
292
|
+
details: 'Your answer stays in the log until an agent checks this page.',
|
|
293
|
+
})
|
|
289
294
|
})
|
|
290
295
|
sent.observe(form, { attributes: true, attributeFilter: ['data-wb-state'] })
|
|
291
296
|
})
|
package/src/client/read.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The agent's messages the reader hasn't read (status.ts: unreadMessages), and reading them: an
|
|
2
2
|
// element marked `data-wb-message="<event id>"` (a reply in an open thread, a chat bubble) reads
|
|
3
|
-
// its message once it has been mostly in view
|
|
3
|
+
// its message once it has been mostly in view (most of it on screen, or filling most of the window)
|
|
4
|
+
// while the tab is visible. Reads are sent together, a
|
|
4
5
|
// moment later, as one `whiteboard:read` event.
|
|
5
6
|
import type { WbEvent } from '../define.ts'
|
|
6
7
|
import { READ, unreadMessages } from '../status.ts'
|
|
@@ -38,18 +39,30 @@ export function readsArrived(events: WbEvent[]) {
|
|
|
38
39
|
if (e.type === READ) for (const id of (e.data?.ids as unknown[] | undefined) ?? []) sending.delete(String(id))
|
|
39
40
|
}
|
|
40
41
|
|
|
42
|
+
// Mostly in view: most of the message is on screen, or, for one taller than the window, it fills
|
|
43
|
+
// most of the window.
|
|
44
|
+
const MOSTLY = 0.6
|
|
45
|
+
function mostlyInView(entry: IntersectionObserverEntry) {
|
|
46
|
+
if (!entry.isIntersecting) return false
|
|
47
|
+
if (entry.intersectionRatio >= MOSTLY) return true
|
|
48
|
+
const viewport = entry.rootBounds?.height ?? window.innerHeight
|
|
49
|
+
return entry.intersectionRect.height >= MOSTLY * viewport
|
|
50
|
+
}
|
|
51
|
+
|
|
41
52
|
// what is in view now, read once the tab is visible too
|
|
42
53
|
const inView = new Set<string>()
|
|
43
54
|
const seen = new IntersectionObserver(
|
|
44
55
|
entries => {
|
|
45
56
|
for (const entry of entries) {
|
|
46
57
|
const id = (entry.target as HTMLElement).dataset.wbMessage!
|
|
47
|
-
if (entry
|
|
58
|
+
if (mostlyInView(entry)) inView.add(id)
|
|
48
59
|
else inView.delete(id)
|
|
49
60
|
}
|
|
50
61
|
readVisible()
|
|
51
62
|
},
|
|
52
|
-
|
|
63
|
+
// steps: a message taller than the window never reaches 0.6 of itself in view, so its share is
|
|
64
|
+
// reported as it scrolls by
|
|
65
|
+
{ threshold: Array.from({ length: 21 }, (_, i) => i / 20) },
|
|
53
66
|
)
|
|
54
67
|
|
|
55
68
|
function readVisible() {
|