@bigmistqke/whiteboard 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -18
- package/bin/whiteboard.ts +300 -71
- package/dist/bin/whiteboard.js +21 -0
- package/dist/client/runtime.js +132 -54
- package/dist/define.js +21 -2
- package/dist/plugins/callout/index.js +3 -1
- package/dist/plugins/callout/public/style.css +30 -0
- package/dist/plugins/chat/index.js +7 -4
- package/dist/plugins/chat/{client.js → public/client.js} +1 -1
- package/dist/plugins/chat/public/style.css +98 -0
- package/dist/plugins/code/index.js +3 -1
- package/dist/plugins/code/public/style.css +68 -0
- package/dist/plugins/comments/index.js +4 -5
- package/dist/plugins/comments/public/client.js +19 -0
- package/dist/plugins/comments/public/style.css +185 -0
- package/dist/plugins/details/index.js +7 -2
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/form/index.js +37 -8
- package/dist/plugins/form/public/style.css +126 -0
- package/dist/plugins/gallery/index.js +4 -3
- package/dist/plugins/gallery/public/client.js +1 -0
- package/dist/plugins/gallery/public/style.css +90 -0
- package/dist/plugins/grid/index.js +9 -3
- package/dist/plugins/grid/public/style.css +71 -0
- package/dist/plugins/iframe/index.js +13 -14
- package/dist/plugins/iframe/public/style.css +13 -0
- package/dist/plugins/index.js +7 -1
- package/dist/plugins/mermaid/index.js +3 -1
- package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +99 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/index.js +10 -9
- package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +12 -5
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +99 -0
- package/dist/plugins/window/README.md +29 -0
- package/dist/plugins/window/index.js +64 -0
- package/dist/solid/index.js +14 -11
- package/dist/src/auth.js +2 -1
- package/dist/src/client/page/base.css +1078 -199
- package/dist/src/client/page/main.js +188 -39
- package/dist/src/loader.js +14 -3
- package/dist/src/package.js +3 -6
- package/dist/src/pages/blocks.js +8 -13
- package/dist/src/pages/markdown.js +1 -1
- package/dist/src/pages/render.js +106 -20
- package/dist/src/pages/window.js +31 -0
- package/dist/src/public.js +24 -0
- package/dist/src/server.js +251 -23
- package/package.json +5 -2
- package/plugins/callout/index.ts +3 -1
- package/plugins/callout/public/style.css +30 -0
- package/plugins/chat/autosize.ts +43 -9
- package/plugins/chat/client.tsx +22 -5
- package/plugins/chat/index.ts +22 -8
- package/plugins/chat/public/style.css +98 -0
- package/plugins/claude-code/index.ts +49 -14
- package/plugins/code/diff.ts +28 -8
- package/plugins/code/index.ts +33 -21
- package/plugins/code/public/style.css +68 -0
- package/plugins/comments/client.ts +139 -71
- package/plugins/comments/index.ts +9 -7
- package/plugins/comments/public/style.css +185 -0
- package/plugins/details/index.ts +7 -2
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/index.ts +16 -3
- package/plugins/form/index.ts +75 -27
- package/plugins/form/public/style.css +126 -0
- package/plugins/gallery/client.tsx +9 -3
- package/plugins/gallery/index.ts +31 -9
- package/plugins/gallery/public/style.css +90 -0
- package/plugins/grid/index.ts +19 -5
- package/plugins/grid/public/style.css +71 -0
- package/plugins/iframe/index.ts +20 -23
- package/plugins/iframe/public/style.css +13 -0
- package/plugins/index.ts +20 -1
- package/plugins/mermaid/index.ts +7 -3
- package/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +66 -0
- package/plugins/steps/index.ts +127 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +105 -48
- package/plugins/terminal/host.ts +143 -35
- package/plugins/terminal/index.ts +84 -25
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +64 -13
- package/plugins/terminal/sizes.ts +16 -4
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +90 -30
- package/plugins/toc/index.ts +26 -10
- package/plugins/toc/public/style.css +99 -0
- package/plugins/window/README.md +29 -0
- package/plugins/window/index.ts +85 -0
- package/skills/whiteboard/SKILL.md +3 -1
- package/solid/index.tsx +24 -9
- package/src/auth.ts +28 -9
- package/src/client/forms.ts +74 -28
- package/src/client/markdown.ts +15 -4
- package/src/client/page/base.css +1078 -199
- package/src/client/page/elsewhere.ts +32 -15
- package/src/client/page/fresh.ts +91 -23
- package/src/client/page/hold.ts +11 -2
- package/src/client/page/live.ts +10 -6
- package/src/client/page/main.ts +124 -42
- package/src/client/page/orphans.ts +25 -10
- package/src/client/page/sort.ts +14 -4
- package/src/client/page/sticky.ts +11 -3
- package/src/client/page/theme.ts +11 -7
- package/src/client/page/waiting.ts +141 -34
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +17 -10
- package/src/client/runtime.ts +170 -40
- package/src/client/scroll.ts +14 -4
- package/src/client/toast.ts +19 -5
- package/src/config.ts +20 -5
- package/src/define.ts +119 -31
- package/src/events.ts +111 -24
- package/src/html.ts +6 -2
- package/src/icons.ts +4 -2
- package/src/load.ts +10 -2
- package/src/loader.ts +81 -12
- package/src/package.ts +9 -8
- package/src/pages/blocks.ts +20 -14
- package/src/pages/index.ts +2 -2
- package/src/pages/markdown.ts +113 -34
- package/src/pages/render.ts +233 -41
- package/src/pages/window.ts +78 -0
- package/src/plugins.ts +90 -24
- package/src/public.ts +39 -0
- package/src/running.ts +8 -2
- package/src/serve.ts +29 -7
- package/src/server.ts +591 -110
- package/src/status.ts +15 -9
- package/dist/plugins/callout/style.css +0 -12
- package/dist/plugins/chat/style.css +0 -24
- package/dist/plugins/code/style.css +0 -29
- package/dist/plugins/comments/client.js +0 -10
- package/dist/plugins/comments/style.css +0 -40
- package/dist/plugins/details/style.css +0 -3
- package/dist/plugins/form/style.css +0 -44
- package/dist/plugins/gallery/client.js +0 -1
- package/dist/plugins/gallery/style.css +0 -27
- package/dist/plugins/grid/style.css +0 -25
- package/dist/plugins/iframe/client.js +0 -1
- package/dist/plugins/iframe/style.css +0 -29
- package/dist/plugins/toc/client.js +0 -1
- package/dist/plugins/toc/style.css +0 -19
- package/plugins/callout/style.css +0 -12
- package/plugins/chat/style.css +0 -24
- package/plugins/code/style.css +0 -29
- package/plugins/comments/style.css +0 -40
- package/plugins/details/style.css +0 -3
- package/plugins/form/style.css +0 -44
- package/plugins/gallery/style.css +0 -27
- package/plugins/grid/style.css +0 -25
- package/plugins/iframe/client.ts +0 -46
- package/plugins/iframe/style.css +0 -29
- package/plugins/terminal/style.css +0 -71
- package/plugins/toc/style.css +0 -19
- /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* Code blocks highlighted by Shiki: tokens carry both colours; pick the one for the current theme.
|
|
2
|
+
The block keeps the page's own code background. */
|
|
3
|
+
pre.shiki {
|
|
4
|
+
background: var(--code-bg);
|
|
5
|
+
}
|
|
6
|
+
.shiki span {
|
|
7
|
+
color: var(--shiki-light);
|
|
8
|
+
font-style: var(--shiki-light-font-style);
|
|
9
|
+
font-weight: var(--shiki-light-font-weight);
|
|
10
|
+
text-decoration: var(--shiki-light-text-decoration);
|
|
11
|
+
}
|
|
12
|
+
@media (prefers-color-scheme: dark) {
|
|
13
|
+
:root:not([data-theme='light']) .shiki span {
|
|
14
|
+
color: var(--shiki-dark);
|
|
15
|
+
font-style: var(--shiki-dark-font-style);
|
|
16
|
+
font-weight: var(--shiki-dark-font-weight);
|
|
17
|
+
text-decoration: var(--shiki-dark-text-decoration);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
:root[data-theme='dark'] .shiki span {
|
|
21
|
+
color: var(--shiki-dark);
|
|
22
|
+
font-style: var(--shiki-dark-font-style);
|
|
23
|
+
font-weight: var(--shiki-dark-font-weight);
|
|
24
|
+
text-decoration: var(--shiki-dark-text-decoration);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* a diff: one row per line, as wide as the longest (a grid leaves out the line breaks between them,
|
|
28
|
+
which stay in the text), tinted by what it is, with its number in a gutter */
|
|
29
|
+
.shiki code:has(> .line[data-diff]) {
|
|
30
|
+
display: grid;
|
|
31
|
+
width: max-content;
|
|
32
|
+
min-width: 100%;
|
|
33
|
+
}
|
|
34
|
+
.shiki .line[data-diff='add'] {
|
|
35
|
+
background: color-mix(in srgb, #16a34a var(--tint-soft), transparent);
|
|
36
|
+
}
|
|
37
|
+
.shiki .line[data-diff='del'] {
|
|
38
|
+
background: color-mix(in srgb, #dc2626 var(--tint-soft), transparent);
|
|
39
|
+
}
|
|
40
|
+
.shiki .line[data-diff]::before {
|
|
41
|
+
content: attr(data-n);
|
|
42
|
+
display: inline-block;
|
|
43
|
+
width: 4ch;
|
|
44
|
+
margin-right: 1.5ch;
|
|
45
|
+
text-align: right;
|
|
46
|
+
color: var(--muted, #696e76);
|
|
47
|
+
opacity: 0.7;
|
|
48
|
+
user-select: none;
|
|
49
|
+
}
|
|
50
|
+
:root .shiki .line[data-diff='hunk'] {
|
|
51
|
+
color: var(--muted, #696e76);
|
|
52
|
+
line-height: 1.2;
|
|
53
|
+
margin: var(--space-2xs) 0;
|
|
54
|
+
}
|
|
55
|
+
.shiki .line[data-diff='hunk']::before {
|
|
56
|
+
content: '⋯';
|
|
57
|
+
text-align: center;
|
|
58
|
+
}
|
|
59
|
+
.shiki .line[data-diff='file'] {
|
|
60
|
+
font-weight: var(--weight-strong);
|
|
61
|
+
margin-bottom: var(--space-md);
|
|
62
|
+
}
|
|
63
|
+
.shiki .line[data-diff='file']::before {
|
|
64
|
+
content: none;
|
|
65
|
+
}
|
|
66
|
+
.shiki .line[data-diff='file'] + .line[data-diff='hunk'] {
|
|
67
|
+
margin-top: 0;
|
|
68
|
+
}
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
import type { Api, PluginMount, PageHandle, WbEvent } from '../../src/define'
|
|
20
20
|
import { html, raw } from '../../src/html.ts'
|
|
21
21
|
|
|
22
|
-
const NEW = 'comments:new',
|
|
22
|
+
const NEW = 'comments:new',
|
|
23
|
+
REPLY = 'comments:reply',
|
|
24
|
+
RESOLVE = 'comments:resolve'
|
|
23
25
|
|
|
24
26
|
interface Thread {
|
|
25
27
|
id: string
|
|
@@ -57,7 +59,8 @@ function textIndex() {
|
|
|
57
59
|
const nodes: { node: Text; start: number }[] = []
|
|
58
60
|
let text = ''
|
|
59
61
|
const walker = document.createTreeWalker(main, NodeFilter.SHOW_TEXT, {
|
|
60
|
-
acceptNode: n =>
|
|
62
|
+
acceptNode: n =>
|
|
63
|
+
n.parentElement?.closest('script, style, textarea') ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT,
|
|
61
64
|
})
|
|
62
65
|
for (let n = walker.nextNode() as Text | null; n; n = walker.nextNode() as Text | null) {
|
|
63
66
|
nodes.push({ node: n, start: text.length })
|
|
@@ -71,7 +74,8 @@ function point(index: ReturnType<typeof textIndex>, at: number, end: boolean) {
|
|
|
71
74
|
for (let i = 0; i < index.nodes.length; i++) {
|
|
72
75
|
const { node, start } = index.nodes[i]
|
|
73
76
|
const stop = start + node.data.length
|
|
74
|
-
if (at < stop || (end && at === stop) || i === index.nodes.length - 1)
|
|
77
|
+
if (at < stop || (end && at === stop) || i === index.nodes.length - 1)
|
|
78
|
+
return { node, offset: Math.min(Math.max(at - start, 0), node.data.length) }
|
|
75
79
|
}
|
|
76
80
|
return null
|
|
77
81
|
}
|
|
@@ -100,8 +104,10 @@ function offsetsOf(index: ReturnType<typeof textIndex>, range: Range) {
|
|
|
100
104
|
function locate(index: ReturnType<typeof textIndex>, data: Record<string, unknown>): Range | null {
|
|
101
105
|
const quote = String(data.quote ?? '')
|
|
102
106
|
if (!quote) return null
|
|
103
|
-
const before = String(data.before ?? ''),
|
|
104
|
-
|
|
107
|
+
const before = String(data.before ?? ''),
|
|
108
|
+
after = String(data.after ?? '')
|
|
109
|
+
let best = -1,
|
|
110
|
+
bestScore = -1
|
|
105
111
|
for (let at = index.text.indexOf(quote); at >= 0; at = index.text.indexOf(quote, at + 1)) {
|
|
106
112
|
const b = index.text.slice(Math.max(0, at - before.length), at)
|
|
107
113
|
const a = index.text.slice(at + quote.length, at + quote.length + after.length)
|
|
@@ -109,10 +115,14 @@ function locate(index: ReturnType<typeof textIndex>, data: Record<string, unknow
|
|
|
109
115
|
while (score < b.length && b[b.length - 1 - score] === before[before.length - 1 - score]) score++
|
|
110
116
|
let s2 = 0
|
|
111
117
|
while (s2 < a.length && a[s2] === after[s2]) s2++
|
|
112
|
-
if (score + s2 > bestScore) {
|
|
118
|
+
if (score + s2 > bestScore) {
|
|
119
|
+
best = at
|
|
120
|
+
bestScore = score + s2
|
|
121
|
+
}
|
|
113
122
|
}
|
|
114
123
|
if (best < 0) return null
|
|
115
|
-
const s = point(index, best, false),
|
|
124
|
+
const s = point(index, best, false),
|
|
125
|
+
e = point(index, best + quote.length, true)
|
|
116
126
|
if (!s || !e) return null
|
|
117
127
|
const range = document.createRange()
|
|
118
128
|
range.setStart(s.node, s.offset)
|
|
@@ -143,34 +153,39 @@ function draw() {
|
|
|
143
153
|
const highlights = (CSS as unknown as { highlights?: Map<string, unknown> }).highlights
|
|
144
154
|
const HighlightCtor = (window as unknown as { Highlight?: new (...r: Range[]) => unknown }).Highlight
|
|
145
155
|
if (highlights && HighlightCtor) {
|
|
146
|
-
highlights.set(
|
|
156
|
+
highlights.set(
|
|
157
|
+
'wb-comment',
|
|
158
|
+
new HighlightCtor(...threads.filter(t => t.range && t.id !== openThread).map(t => t.range!)),
|
|
159
|
+
)
|
|
147
160
|
const active = threads.find(t => t.id === openThread)?.range
|
|
148
161
|
if (active) highlights.set('wb-comment-active', new HighlightCtor(active))
|
|
149
162
|
else highlights.delete('wb-comment-active')
|
|
150
163
|
}
|
|
151
164
|
const column = main.getBoundingClientRect()
|
|
152
165
|
const unreadIds = new Set(api.unread().map(e => e.id))
|
|
153
|
-
layer.replaceChildren(
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
166
|
+
layer.replaceChildren(
|
|
167
|
+
...threads.map((t, i) => {
|
|
168
|
+
const badge = document.createElement('button')
|
|
169
|
+
badge.type = 'button'
|
|
170
|
+
badge.className = 'wb-comment-badge'
|
|
171
|
+
badge.dataset.thread = t.id
|
|
172
|
+
badge.toggleAttribute('data-agent', lastFromAgent(t))
|
|
173
|
+
// the replies it holds, for the page to find an unread one here (data-wb-holds, see the page)
|
|
174
|
+
badge.dataset.wbHolds = t.replies.map(r => r.id).join(' ')
|
|
175
|
+
const unread = t.replies.some(r => unreadIds.has(r.id))
|
|
176
|
+
badge.toggleAttribute('data-unread', unread)
|
|
177
|
+
badge.title = unread ? 'the agent replied: unread' : lastFromAgent(t) ? 'the agent replied' : 'comment'
|
|
178
|
+
badge.textContent = String(1 + t.replies.length)
|
|
179
|
+
const rect = t.range?.getClientRects()[0]
|
|
180
|
+
// a passage that is gone from the page: its badge waits at the top, still open until closed
|
|
181
|
+
const top = rect ? rect.top + scrollY : column.top + scrollY + i * 30
|
|
182
|
+
const left = Math.min(column.right + 8 + scrollX, document.documentElement.clientWidth - 36 + scrollX)
|
|
183
|
+
badge.style.top = `${top}px`
|
|
184
|
+
badge.style.left = `${left}px`
|
|
185
|
+
if (!rect) badge.dataset.detached = ''
|
|
186
|
+
return badge
|
|
187
|
+
}),
|
|
188
|
+
)
|
|
174
189
|
if (openThread) placePopover()
|
|
175
190
|
}
|
|
176
191
|
|
|
@@ -215,35 +230,52 @@ function renderPopover() {
|
|
|
215
230
|
const message = (e: WbEvent) => {
|
|
216
231
|
const text = String(e.data.text ?? '')
|
|
217
232
|
const md = rendered.get(text)
|
|
218
|
-
return html`<div class="wb-thread-message" data-from="${who(e)}" data-wb-message="${e.id}"
|
|
233
|
+
return html`<div class="wb-thread-message" data-from="${who(e)}" data-wb-message="${e.id}">
|
|
234
|
+
<span class="wb-thread-who">${who(e)}</span>
|
|
235
|
+
<div class="wb-thread-text" ${md != null ? raw(' data-md') : ''}>${md != null ? raw(md) : text}</div>
|
|
236
|
+
</div>`
|
|
219
237
|
}
|
|
220
238
|
// the reply being typed: its text, and its focus and caret, which a redraw would take
|
|
221
239
|
const box = popover.querySelector('textarea')
|
|
222
240
|
const draft = box?.value ?? ''
|
|
223
241
|
const typing = !!box && document.activeElement === box
|
|
224
|
-
const caret = box ? [box.selectionStart, box.selectionEnd] as const : null
|
|
225
|
-
popover.innerHTML = String(
|
|
226
|
-
<blockquote class="wb-thread-quote">${t.comment.data.quote ?? ''}</blockquote>
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
242
|
+
const caret = box ? ([box.selectionStart, box.selectionEnd] as const) : null
|
|
243
|
+
popover.innerHTML = String(
|
|
244
|
+
html` <blockquote class="wb-thread-quote">${t.comment.data.quote ?? ''}</blockquote>
|
|
245
|
+
${t.comment.data.at && html`<p class="wb-thread-at">${t.comment.data.at}</p>`}
|
|
246
|
+
${!t.range && html`<p class="wb-thread-detached">This passage is no longer on the page.</p>`}
|
|
247
|
+
${[t.comment, ...t.replies].map(message)}
|
|
248
|
+
<form class="wb-thread-reply">
|
|
249
|
+
<textarea rows="2" placeholder="Reply (Shift+Enter for a new line)"></textarea>
|
|
250
|
+
<div class="wb-thread-actions">
|
|
251
|
+
<button type="submit" class="wb-comment-button wb-comment-primary">Reply</button
|
|
252
|
+
><button type="button" class="wb-comment-button" data-close>Close thread</button>
|
|
253
|
+
</div>
|
|
254
|
+
</form>`,
|
|
255
|
+
)
|
|
234
256
|
const again = popover.querySelector('textarea')!
|
|
235
257
|
again.value = draft
|
|
236
|
-
if (typing) {
|
|
258
|
+
if (typing) {
|
|
259
|
+
again.focus({ preventScroll: true })
|
|
260
|
+
if (caret) again.setSelectionRange(caret[0], caret[1])
|
|
261
|
+
}
|
|
237
262
|
// the messages not rendered yet: their text only, put in place as each arrives (the rest of the
|
|
238
263
|
// thread, the reply being typed among it, stays as it is)
|
|
239
264
|
for (const e of [t.comment, ...t.replies]) {
|
|
240
265
|
const text = String(e.data.text ?? '')
|
|
241
266
|
if (rendered.has(text)) continue
|
|
242
|
-
api.markdown(text).then(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
267
|
+
api.markdown(text).then(
|
|
268
|
+
md => {
|
|
269
|
+
rendered.set(text, md)
|
|
270
|
+
const el = popover.querySelector<HTMLElement>(`[data-wb-message="${CSS.escape(e.id)}"] .wb-thread-text`)
|
|
271
|
+
if (el && !el.hasAttribute('data-md'))
|
|
272
|
+
holdTyping(() => {
|
|
273
|
+
el.innerHTML = md
|
|
274
|
+
el.setAttribute('data-md', '')
|
|
275
|
+
})
|
|
276
|
+
},
|
|
277
|
+
err => console.error('comments:', err),
|
|
278
|
+
)
|
|
247
279
|
}
|
|
248
280
|
}
|
|
249
281
|
|
|
@@ -252,7 +284,10 @@ function placePopover() {
|
|
|
252
284
|
if (!badge) return
|
|
253
285
|
const top = parseFloat(badge.style.top) + 28
|
|
254
286
|
const width = Math.min(360, document.documentElement.clientWidth - 32)
|
|
255
|
-
const left = Math.max(
|
|
287
|
+
const left = Math.max(
|
|
288
|
+
16 + scrollX,
|
|
289
|
+
Math.min(parseFloat(badge.style.left) + 28 - width, document.documentElement.clientWidth - width - 16 + scrollX),
|
|
290
|
+
)
|
|
256
291
|
popover.style.top = `${top}px`
|
|
257
292
|
popover.style.left = `${left}px`
|
|
258
293
|
popover.style.width = `${width}px`
|
|
@@ -281,10 +316,17 @@ let pending: { quote: string; before: string; after: string; block: number; at?:
|
|
|
281
316
|
function onSelection() {
|
|
282
317
|
main = root.querySelector('main') ?? root
|
|
283
318
|
const sel = getSelection()
|
|
284
|
-
if (!sel || sel.isCollapsed || !sel.rangeCount) {
|
|
319
|
+
if (!sel || sel.isCollapsed || !sel.rangeCount) {
|
|
320
|
+
if (!startButton.matches(':focus')) startButton.hidden = true
|
|
321
|
+
return
|
|
322
|
+
}
|
|
285
323
|
const range = sel.getRangeAt(0)
|
|
286
|
-
const inPage = (n: Node) =>
|
|
287
|
-
|
|
324
|
+
const inPage = (n: Node) =>
|
|
325
|
+
main.contains(n) && !(n instanceof Element ? n : n.parentElement)?.closest('form, input, textarea, select, button')
|
|
326
|
+
if (!inPage(range.startContainer) || !inPage(range.endContainer)) {
|
|
327
|
+
startButton.hidden = true
|
|
328
|
+
return
|
|
329
|
+
}
|
|
288
330
|
startButton.hidden = !prepare(range)
|
|
289
331
|
}
|
|
290
332
|
|
|
@@ -301,7 +343,8 @@ function prepare(range: Range): boolean {
|
|
|
301
343
|
// the quote as it appears in the page's text, trimmed of the whitespace the selection had around it
|
|
302
344
|
const start = index.text.indexOf(quote, at.start)
|
|
303
345
|
const s = start >= 0 && start <= at.end ? start : at.start
|
|
304
|
-
let block: Element | null =
|
|
346
|
+
let block: Element | null =
|
|
347
|
+
range.startContainer instanceof Element ? range.startContainer : range.startContainer.parentElement
|
|
305
348
|
while (block && block.parentElement !== main) block = block.parentElement
|
|
306
349
|
pending = {
|
|
307
350
|
quote,
|
|
@@ -310,8 +353,11 @@ function prepare(range: Range): boolean {
|
|
|
310
353
|
block: block ? [...main.children].indexOf(block) : -1,
|
|
311
354
|
}
|
|
312
355
|
// where the passage is from, when its block says (see the top of this file)
|
|
313
|
-
const places = [...main.querySelectorAll<HTMLElement>('[data-wb-at]')]
|
|
314
|
-
|
|
356
|
+
const places = [...main.querySelectorAll<HTMLElement>('[data-wb-at]')]
|
|
357
|
+
.filter(el => range.intersectsNode(el) && el.textContent)
|
|
358
|
+
.map(el => el.dataset.wbAt!)
|
|
359
|
+
if (places.length)
|
|
360
|
+
pending.at = places.length > 1 && places.at(-1) !== places[0] ? `${places[0]} – ${places.at(-1)}` : places[0]
|
|
315
361
|
const rects = range.getClientRects()
|
|
316
362
|
const last = rects[rects.length - 1] ?? range.getBoundingClientRect()
|
|
317
363
|
startButton.style.top = `${last.bottom + scrollY + 6}px`
|
|
@@ -366,7 +412,8 @@ function onLinePointer(e: MouseEvent) {
|
|
|
366
412
|
drag.to = line
|
|
367
413
|
const highlights = (CSS as unknown as { highlights?: Map<string, unknown> }).highlights
|
|
368
414
|
const HighlightCtor = (window as unknown as { Highlight?: new (...r: Range[]) => unknown }).Highlight
|
|
369
|
-
if (highlights && HighlightCtor)
|
|
415
|
+
if (highlights && HighlightCtor)
|
|
416
|
+
highlights.set('wb-comment-active', new HighlightCtor(linesRange(drag.from, drag.to)))
|
|
370
417
|
}
|
|
371
418
|
return
|
|
372
419
|
}
|
|
@@ -381,16 +428,27 @@ function onLinePointer(e: MouseEvent) {
|
|
|
381
428
|
const box = pre.getBoundingClientRect()
|
|
382
429
|
const plus = lineButton.getBoundingClientRect()
|
|
383
430
|
const inside = e.clientX >= plus.left - 4 && e.clientX <= box.right && e.clientY >= box.top && e.clientY <= box.bottom
|
|
384
|
-
const atHeight = inside
|
|
431
|
+
const atHeight = inside
|
|
432
|
+
? codeLine(document.elementFromPoint(hovered.getBoundingClientRect().left + 4, e.clientY))
|
|
433
|
+
: null
|
|
385
434
|
if (atHeight && pre.contains(atHeight)) showLineButton(atHeight)
|
|
386
|
-
else if (!inside || !(e.clientY >= plus.top - 4 && e.clientY <= plus.bottom + 4)) {
|
|
435
|
+
else if (!inside || !(e.clientY >= plus.top - 4 && e.clientY <= plus.bottom + 4)) {
|
|
436
|
+
lineButton.hidden = true
|
|
437
|
+
hovered = null
|
|
438
|
+
}
|
|
387
439
|
}
|
|
388
440
|
|
|
389
441
|
const composer = document.createElement('form')
|
|
390
442
|
composer.className = 'wb-thread wb-comment-new'
|
|
391
443
|
composer.hidden = true
|
|
392
|
-
composer.innerHTML = String(
|
|
393
|
-
|
|
444
|
+
composer.innerHTML = String(
|
|
445
|
+
html`<blockquote class="wb-thread-quote"></blockquote>
|
|
446
|
+
<textarea rows="3" placeholder="Your comment (Shift+Enter for a new line)"></textarea>
|
|
447
|
+
<div class="wb-thread-actions">
|
|
448
|
+
<button type="submit" class="wb-comment-button wb-comment-primary">Comment</button
|
|
449
|
+
><button type="button" class="wb-comment-button" data-cancel>Cancel</button>
|
|
450
|
+
</div>`,
|
|
451
|
+
)
|
|
394
452
|
|
|
395
453
|
function startComment() {
|
|
396
454
|
if (!pending) return
|
|
@@ -426,7 +484,8 @@ const mount: PluginMount = (el: HTMLElement, handle: PageHandle, core: Api) => {
|
|
|
426
484
|
e.preventDefault()
|
|
427
485
|
const highlights = (CSS as unknown as { highlights?: Map<string, unknown> }).highlights
|
|
428
486
|
const HighlightCtor = (window as unknown as { Highlight?: new (...r: Range[]) => unknown }).Highlight
|
|
429
|
-
if (highlights && HighlightCtor)
|
|
487
|
+
if (highlights && HighlightCtor)
|
|
488
|
+
highlights.set('wb-comment-active', new HighlightCtor(linesRange(hovered, hovered)))
|
|
430
489
|
drag = { pre: hovered.closest('pre')!, from: hovered, to: hovered }
|
|
431
490
|
})
|
|
432
491
|
document.addEventListener('mouseup', () => {
|
|
@@ -439,19 +498,23 @@ const mount: PluginMount = (el: HTMLElement, handle: PageHandle, core: Api) => {
|
|
|
439
498
|
})
|
|
440
499
|
|
|
441
500
|
let selTimer = 0
|
|
442
|
-
document.addEventListener('selectionchange', () => {
|
|
501
|
+
document.addEventListener('selectionchange', () => {
|
|
502
|
+
clearTimeout(selTimer)
|
|
503
|
+
selTimer = window.setTimeout(onSelection, 150)
|
|
504
|
+
})
|
|
443
505
|
// keep the selection when the button is pressed
|
|
444
506
|
startButton.addEventListener('mousedown', e => e.preventDefault())
|
|
445
507
|
startButton.addEventListener('click', startComment)
|
|
446
508
|
|
|
447
509
|
// as in a chat: Enter sends the comment or reply, Shift+Enter starts a new line; not while an
|
|
448
510
|
// input method is composing
|
|
449
|
-
for (const form of [composer, popover] as HTMLElement[])
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
511
|
+
for (const form of [composer, popover] as HTMLElement[])
|
|
512
|
+
form.addEventListener('keydown', e => {
|
|
513
|
+
const box = e.target as HTMLElement
|
|
514
|
+
if (box.tagName !== 'TEXTAREA' || e.key !== 'Enter' || e.shiftKey || e.isComposing) return
|
|
515
|
+
e.preventDefault()
|
|
516
|
+
box.closest('form')?.requestSubmit()
|
|
517
|
+
})
|
|
455
518
|
composer.addEventListener('submit', async e => {
|
|
456
519
|
e.preventDefault()
|
|
457
520
|
const text = composer.querySelector('textarea')!.value.trim()
|
|
@@ -464,11 +527,14 @@ const mount: PluginMount = (el: HTMLElement, handle: PageHandle, core: Api) => {
|
|
|
464
527
|
refreshComments()
|
|
465
528
|
openPopover(saved.id)
|
|
466
529
|
})
|
|
467
|
-
composer.querySelector('[data-cancel]')!.addEventListener('click', () => {
|
|
530
|
+
composer.querySelector('[data-cancel]')!.addEventListener('click', () => {
|
|
531
|
+
composer.hidden = true
|
|
532
|
+
pending = null
|
|
533
|
+
})
|
|
468
534
|
|
|
469
535
|
layer.addEventListener('click', e => {
|
|
470
536
|
const id = (e.target as HTMLElement).closest<HTMLElement>('[data-thread]')?.dataset.thread
|
|
471
|
-
if (id)
|
|
537
|
+
if (id) openThread === id ? closePopover() : openPopover(id)
|
|
472
538
|
})
|
|
473
539
|
popover.addEventListener('submit', async e => {
|
|
474
540
|
e.preventDefault()
|
|
@@ -501,11 +567,13 @@ const mount: PluginMount = (el: HTMLElement, handle: PageHandle, core: Api) => {
|
|
|
501
567
|
})
|
|
502
568
|
document.addEventListener('keydown', e => {
|
|
503
569
|
if (e.key !== 'Escape') return
|
|
504
|
-
if (!composer.hidden) {
|
|
505
|
-
|
|
570
|
+
if (!composer.hidden) {
|
|
571
|
+
composer.hidden = true
|
|
572
|
+
pending = null
|
|
573
|
+
} else if (openThread) closePopover()
|
|
506
574
|
})
|
|
507
575
|
|
|
508
|
-
api.
|
|
576
|
+
api.events.on(refreshComments)
|
|
509
577
|
api.onRendered(refreshComments)
|
|
510
578
|
new ResizeObserver(() => draw()).observe(root)
|
|
511
579
|
addEventListener('resize', () => draw())
|
|
@@ -3,12 +3,9 @@
|
|
|
3
3
|
//
|
|
4
4
|
// A thread is events on the page (see client.ts), so the server has nothing to do but serve the
|
|
5
5
|
// browser module and the styles, and tell agents how to answer (`whiteboard docs`).
|
|
6
|
-
import {
|
|
6
|
+
import { builtinPublic } from '../../src/package.ts'
|
|
7
7
|
import type { Plugin } from '../../src/define.ts'
|
|
8
8
|
|
|
9
|
-
const CLIENT = packagePath('dist/plugins/comments/client.js')
|
|
10
|
-
const STYLE = packagePath('dist/plugins/comments/style.css')
|
|
11
|
-
|
|
12
9
|
const DOCS = `## Comments
|
|
13
10
|
|
|
14
11
|
The reader can select text on any page and comment on it, or comment on
|
|
@@ -44,11 +41,16 @@ export default function comments(): Plugin {
|
|
|
44
41
|
name: 'comments',
|
|
45
42
|
docs: () => DOCS,
|
|
46
43
|
events: {
|
|
47
|
-
'comments:new': {
|
|
44
|
+
'comments:new': {
|
|
45
|
+
handOut: true,
|
|
46
|
+
description:
|
|
47
|
+
"a comment on a passage or lines of code: `{ quote, before, after, block, at?, text }`; its id is the thread's",
|
|
48
|
+
},
|
|
48
49
|
'comments:reply': { handOut: true, forReader: true, description: 'a reply in a thread: `{ replyTo, text }`' },
|
|
49
50
|
'comments:resolve': { description: 'the reader closed a thread: `{ replyTo }`' },
|
|
50
51
|
},
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
public: builtinPublic('comments'),
|
|
53
|
+
style: 'style.css',
|
|
54
|
+
setup: () => ({ client: 'client.js' }),
|
|
53
55
|
}
|
|
54
56
|
}
|
|
@@ -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
|
+
}
|