dsh-selection-annotations 0.0.0-stage → 2.1.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/CHANGELOG.md +166 -0
- package/LICENSE +21 -0
- package/README.md +161 -3
- package/README.zh-CN.md +161 -0
- package/client.js +11136 -0
- package/cordis.patch.yml +3 -0
- package/icon.svg +7 -0
- package/lib/annotations-db.js +1157 -0
- package/lib/index.js +1304 -0
- package/package.json +74 -6
- package/scripts/build.mjs +37 -0
- package/scripts/check-build.mjs +10 -0
- package/src/core/annotation-clipboard.js +93 -0
- package/src/core/annotation-utils.js +27 -0
- package/src/core/cards.js +502 -0
- package/src/core/config.js +91 -0
- package/src/core/constants.js +34 -0
- package/src/core/draft-codec.js +77 -0
- package/src/core/draft-store.js +85 -0
- package/src/core/hidden-payload.js +73 -0
- package/src/core/image-codec.js +111 -0
- package/src/core/jump-icon.js +25 -0
- package/src/core/locale.js +59 -0
- package/src/core/log.js +19 -0
- package/src/core/markdown.js +80 -0
- package/src/core/messages.js +311 -0
- package/src/core/note-tone.js +77 -0
- package/src/core/panel-render.js +315 -0
- package/src/core/payload.js +191 -0
- package/src/core/preview-bridge.js +216 -0
- package/src/core/remote-sync.js +206 -0
- package/src/core/scroll-trace.js +177 -0
- package/src/core/sent-store.js +148 -0
- package/src/core/session.js +60 -0
- package/src/core/settings.js +168 -0
- package/src/core/side-tab-state.js +30 -0
- package/src/core/source-capture.js +530 -0
- package/src/core/source-locate.js +220 -0
- package/src/core/source-resolve.js +89 -0
- package/src/core/styles.js +590 -0
- package/src/core/turn-anchor.js +54 -0
- package/src/core/util.js +55 -0
- package/src/core/uuid.js +23 -0
- package/src/core/web-picker.js +426 -0
- package/src/entry.js +22 -0
- package/src/plugin.js +8706 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import { truncateQuote } from './util.js'
|
|
2
|
+
import { mergeReplyBatches } from './annotation-utils.js'
|
|
3
|
+
import { jumpIcon } from './jump-icon.js'
|
|
4
|
+
import { paintNote } from './note-tone.js'
|
|
5
|
+
|
|
6
|
+
export const VERDICT_LABELS = {
|
|
7
|
+
accepted: ['verdict.accepted', 'accepted'],
|
|
8
|
+
partial: ['verdict.partial', 'partial'],
|
|
9
|
+
rejected: ['verdict.rejected', 'rejected'],
|
|
10
|
+
needs_info: ['verdict.needs_info', 'needs_info'],
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 两个区域共用的收展头、矢量箭头与可折展容器,以及已提交批注的卡片。
|
|
15
|
+
*/
|
|
16
|
+
export function createCards({ t, openImageViewer, markdown, isAdopt = () => false, noteView = () => null }) {
|
|
17
|
+
function sectionChevron() {
|
|
18
|
+
const ns = 'http://www.w3.org/2000/svg'
|
|
19
|
+
const svg = document.createElementNS(ns, 'svg')
|
|
20
|
+
svg.setAttribute('class', 'sa-section-chevron')
|
|
21
|
+
svg.setAttribute('viewBox', '0 0 16 16')
|
|
22
|
+
svg.setAttribute('aria-hidden', 'true')
|
|
23
|
+
const path = document.createElementNS(ns, 'path')
|
|
24
|
+
path.setAttribute('d', 'M6.2 3.6 10.7 8l-4.5 4.4')
|
|
25
|
+
path.setAttribute('fill', 'none')
|
|
26
|
+
path.setAttribute('stroke', 'currentColor')
|
|
27
|
+
path.setAttribute('stroke-width', '1.8')
|
|
28
|
+
path.setAttribute('stroke-linecap', 'round')
|
|
29
|
+
path.setAttribute('stroke-linejoin', 'round')
|
|
30
|
+
svg.appendChild(path)
|
|
31
|
+
return svg
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 两个区域共用的收展入口:同一套结构、尺寸与留白。 */
|
|
35
|
+
function buildSectionHead(label, meta, action) {
|
|
36
|
+
const head = document.createElement('button')
|
|
37
|
+
head.type = 'button'
|
|
38
|
+
head.className = 'sa-section-head'
|
|
39
|
+
head.appendChild(sectionChevron())
|
|
40
|
+
const title = document.createElement('span')
|
|
41
|
+
title.className = 'sa-section-title'
|
|
42
|
+
title.textContent = label
|
|
43
|
+
head.appendChild(title)
|
|
44
|
+
if (typeof meta === 'string' && meta !== '') {
|
|
45
|
+
const metaEl = document.createElement('span')
|
|
46
|
+
metaEl.className = 'sa-section-meta'
|
|
47
|
+
metaEl.textContent = meta
|
|
48
|
+
head.appendChild(metaEl)
|
|
49
|
+
}
|
|
50
|
+
if (action !== undefined && action !== null) head.appendChild(action)
|
|
51
|
+
return head
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 回放按钮的图标:两张叠起来的纸,表示「放回复用」。*/
|
|
55
|
+
function replayIcon() {
|
|
56
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
|
57
|
+
svg.setAttribute('viewBox', '0 0 16 16')
|
|
58
|
+
svg.setAttribute('width', '13')
|
|
59
|
+
svg.setAttribute('height', '13')
|
|
60
|
+
svg.setAttribute('fill', 'none')
|
|
61
|
+
svg.setAttribute('aria-hidden', 'true')
|
|
62
|
+
for (const d of ['M5.6 5.6H12.4V12.4H5.6V5.6Z', 'M3.6 3.6H9.4V5.6']) {
|
|
63
|
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path')
|
|
64
|
+
path.setAttribute('d', d)
|
|
65
|
+
path.setAttribute('stroke', 'currentColor')
|
|
66
|
+
path.setAttribute('stroke-width', '1.2')
|
|
67
|
+
svg.appendChild(path)
|
|
68
|
+
}
|
|
69
|
+
return svg
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 「图标常驻、文字悬停出现」的小按钮:回放与查看出处共用这一套观感与交互。
|
|
74
|
+
* 文字节点始终占位,只切换透明度,悬停命中区域不会长大;.sa-reuse 自带 margin-left:auto,
|
|
75
|
+
* 放进 flex 行里就贴最右,不需要额外的定位或包裹层。
|
|
76
|
+
*/
|
|
77
|
+
function hoverTextButton(label, onClick, hint, icon) {
|
|
78
|
+
const button = document.createElement('span')
|
|
79
|
+
button.className = 'sa-reuse'
|
|
80
|
+
button.setAttribute('role', 'button')
|
|
81
|
+
button.setAttribute('tabindex', '0')
|
|
82
|
+
button.setAttribute('aria-label', label)
|
|
83
|
+
if (typeof hint === 'string' && hint !== '') button.title = hint
|
|
84
|
+
const text = document.createElement('span')
|
|
85
|
+
text.className = 'sa-reuse-text'
|
|
86
|
+
text.textContent = label
|
|
87
|
+
// 文字在前、图标贴右:与「回放」的语义一致。
|
|
88
|
+
button.append(text, icon)
|
|
89
|
+
const run = (event) => {
|
|
90
|
+
event.preventDefault()
|
|
91
|
+
event.stopPropagation()
|
|
92
|
+
onClick()
|
|
93
|
+
}
|
|
94
|
+
button.addEventListener('click', run)
|
|
95
|
+
button.addEventListener('keydown', (event) => {
|
|
96
|
+
if (event.key === 'Enter' || event.key === ' ') run(event)
|
|
97
|
+
})
|
|
98
|
+
return button
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 已发送区右上角的「复用」图标:把这些批注重新放回待发送列表。*/
|
|
102
|
+
function reuseButton(label, onClick, hint) {
|
|
103
|
+
return hoverTextButton(label, onClick, hint, replayIcon())
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 「查看出处」按钮:与回放按钮同一套观感(图标常驻、文字悬停出现),
|
|
108
|
+
* 作为「引用原文」那一行的普通子元素贴右,不绝对定位、不覆盖引文。
|
|
109
|
+
*/
|
|
110
|
+
function jumpButton(item, onClick, hint) {
|
|
111
|
+
const button = hoverTextButton(
|
|
112
|
+
t('jump.label'),
|
|
113
|
+
() => onClick(item, button),
|
|
114
|
+
typeof hint === 'string' && hint !== '' ? hint : t('jump.hint'),
|
|
115
|
+
jumpIcon(),
|
|
116
|
+
)
|
|
117
|
+
button.classList.add('sa-jump')
|
|
118
|
+
// 工作区文件这版不打开,置灰;点了仍走一次提示,避免静默。
|
|
119
|
+
if (item?.source?.kind === 'file') button.setAttribute('data-disabled', '1')
|
|
120
|
+
return button
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 可折展容器:0fr↔1fr 撑开内容,收起时不占高度。 */
|
|
124
|
+
function collapsible(body, open) {
|
|
125
|
+
const wrap = document.createElement('div')
|
|
126
|
+
wrap.className = 'sa-collapse'
|
|
127
|
+
// 行内样式优先于样式表,并且用同一个「标题 + 内容」的纵向间隔来表达,
|
|
128
|
+
// 这样两处区域无论内部结构怎样嵌套,视觉间距都完全一致。
|
|
129
|
+
wrap.style.marginTop = '0px'
|
|
130
|
+
wrap.dataset.open = open ? '1' : '0'
|
|
131
|
+
const inner = document.createElement('div')
|
|
132
|
+
inner.className = 'sa-collapse-inner'
|
|
133
|
+
inner.appendChild(body)
|
|
134
|
+
wrap.appendChild(inner)
|
|
135
|
+
return wrap
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function applyCollapsed(head, wrap, open) {
|
|
139
|
+
wrap.dataset.open = open ? '1' : '0'
|
|
140
|
+
head.dataset.open = open ? '1' : '0'
|
|
141
|
+
head.setAttribute('aria-expanded', String(open))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 一条已提交批注在历史里的卡片:默认收起,点开看引文与批注文字。 */
|
|
145
|
+
function buildSentCard(record, anchorKey, options = {}) {
|
|
146
|
+
const card = document.createElement('div')
|
|
147
|
+
card.className = 'sa-sent'
|
|
148
|
+
card.setAttribute('data-sa-ui', 'sent')
|
|
149
|
+
// 记下锚点键:卡片现在插在消息行外,判重要靠它而不是「行内有没有卡片」。
|
|
150
|
+
if (typeof anchorKey === 'string' && anchorKey !== '') card.setAttribute('data-anchor', anchorKey)
|
|
151
|
+
const action = typeof options.onReuse === 'function'
|
|
152
|
+
? reuseButton(t('sent.reuse'), options.onReuse, t('reuse.hint'))
|
|
153
|
+
: undefined
|
|
154
|
+
const head = buildSectionHead(t('sent.title', { n: record.items.length }), undefined, action)
|
|
155
|
+
head.style.marginBottom = '0'
|
|
156
|
+
card.style.display = 'flex'
|
|
157
|
+
card.style.flexDirection = 'column'
|
|
158
|
+
card.style.rowGap = '8px'
|
|
159
|
+
const body = document.createElement('div')
|
|
160
|
+
body.className = 'sa-sent-body'
|
|
161
|
+
// 卡片内部的呼吸感:首行文字离边框 8px,和标题到卡片的 8px 分开控制。
|
|
162
|
+
body.style.padding = '8px'
|
|
163
|
+
const wrap = collapsible(body, true)
|
|
164
|
+
applyCollapsed(head, wrap, true)
|
|
165
|
+
for (const item of record.items) {
|
|
166
|
+
const line = document.createElement('div')
|
|
167
|
+
line.className = 'sa-sent-item'
|
|
168
|
+
line.setAttribute('data-sa-sent-index', Number.isFinite(item.index) ? String(item.index) : '')
|
|
169
|
+
const num = document.createElement('span')
|
|
170
|
+
num.className = 'sa-sent-num'
|
|
171
|
+
num.textContent = Number.isFinite(item.index) ? String(item.index) : ''
|
|
172
|
+
const text = document.createElement('div')
|
|
173
|
+
text.className = 'sa-sent-text'
|
|
174
|
+
const quoteRow = document.createElement('div')
|
|
175
|
+
quoteRow.className = 'sa-sent-quote-row'
|
|
176
|
+
const quote = document.createElement('div')
|
|
177
|
+
quote.className = 'sa-sent-quote'
|
|
178
|
+
quote.setAttribute('data-sa-field', 'quote')
|
|
179
|
+
quote.textContent = truncateQuote(item.quote)
|
|
180
|
+
if (typeof options.onJumpQuote === 'function') {
|
|
181
|
+
// 引文块整块可点:跳转入口只保留这一处。悬停变正文色由 .sa-quote-jump 负责。
|
|
182
|
+
quote.classList.add('sa-quote-jump')
|
|
183
|
+
quote.setAttribute('role', 'button')
|
|
184
|
+
quote.setAttribute('tabindex', '0')
|
|
185
|
+
quote.title = t('jump.hint')
|
|
186
|
+
const runJump = (event) => {
|
|
187
|
+
event.preventDefault()
|
|
188
|
+
event.stopPropagation()
|
|
189
|
+
options.onJumpQuote(item, quote)
|
|
190
|
+
}
|
|
191
|
+
quote.addEventListener('click', runJump)
|
|
192
|
+
quote.addEventListener('keydown', (event) => {
|
|
193
|
+
if (event.key === 'Enter' || event.key === ' ') runJump(event)
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
quoteRow.appendChild(quote)
|
|
197
|
+
// 引文块整块可点后不再重复放按钮,这一行只保留引文本身。
|
|
198
|
+
text.appendChild(quoteRow)
|
|
199
|
+
if (typeof item.note === 'string' && item.note.trim() !== '') {
|
|
200
|
+
const note = document.createElement('div')
|
|
201
|
+
note.className = 'sa-sent-note'
|
|
202
|
+
note.setAttribute('data-sa-field', 'note')
|
|
203
|
+
paintNote(note, item.note, noteView(item.note))
|
|
204
|
+
text.appendChild(note)
|
|
205
|
+
}
|
|
206
|
+
const thumbs = Array.isArray(item.thumbs) ? item.thumbs : []
|
|
207
|
+
if (thumbs.length > 0) {
|
|
208
|
+
const gallery = document.createElement('div')
|
|
209
|
+
gallery.className = 'sa-sent-thumbs'
|
|
210
|
+
for (const thumb of thumbs) {
|
|
211
|
+
if (typeof thumb?.dataUrl !== 'string' || thumb.dataUrl === '') continue
|
|
212
|
+
const img = document.createElement('img')
|
|
213
|
+
img.className = 'sa-sent-thumb'
|
|
214
|
+
img.src = thumb.dataUrl
|
|
215
|
+
img.alt = typeof thumb.name === 'string' ? thumb.name : t('image.alt')
|
|
216
|
+
img.title = t('image.open')
|
|
217
|
+
img.addEventListener('click', (event) => {
|
|
218
|
+
event.preventDefault()
|
|
219
|
+
event.stopPropagation()
|
|
220
|
+
openImageViewer(typeof thumb.preview === 'string' && thumb.preview !== '' ? thumb.preview : thumb.dataUrl, thumb.name)
|
|
221
|
+
})
|
|
222
|
+
gallery.appendChild(img)
|
|
223
|
+
}
|
|
224
|
+
if (gallery.childNodes.length > 0) text.appendChild(gallery)
|
|
225
|
+
}
|
|
226
|
+
line.append(num, text)
|
|
227
|
+
if (typeof options.onReplayItem === 'function') {
|
|
228
|
+
line.appendChild(reuseButton(t('sent.replayItem'), () => options.onReplayItem(item), t('reuse.hint')))
|
|
229
|
+
}
|
|
230
|
+
body.appendChild(line)
|
|
231
|
+
}
|
|
232
|
+
head.addEventListener('click', (event) => {
|
|
233
|
+
event.preventDefault()
|
|
234
|
+
event.stopPropagation()
|
|
235
|
+
applyCollapsed(head, wrap, wrap.dataset.open !== '1')
|
|
236
|
+
})
|
|
237
|
+
card.append(head, wrap)
|
|
238
|
+
return card
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function buildReplySection(batches, items = [], options = {}) {
|
|
242
|
+
const replies = mergeReplyBatches(batches)
|
|
243
|
+
const byIndex = new Map()
|
|
244
|
+
const byUuid = new Map()
|
|
245
|
+
for (const item of Array.isArray(items) ? items : []) {
|
|
246
|
+
if (typeof item?.uuid === 'string' && item.uuid !== '') byUuid.set(item.uuid, item)
|
|
247
|
+
if (Number.isFinite(item?.index)) byIndex.set(item.index, item)
|
|
248
|
+
}
|
|
249
|
+
const card = document.createElement('div')
|
|
250
|
+
card.className = 'sa-replies'
|
|
251
|
+
card.setAttribute('data-sa-ui', 'replies')
|
|
252
|
+
|
|
253
|
+
const counts = { accepted: 0, partial: 0, rejected: 0, needs_info: 0 }
|
|
254
|
+
for (const reply of replies) {
|
|
255
|
+
if (Object.hasOwn(counts, reply.verdict)) counts[reply.verdict] += 1
|
|
256
|
+
}
|
|
257
|
+
const parts = []
|
|
258
|
+
if (counts.accepted) parts.push(t('summary.accepted', { n: counts.accepted }))
|
|
259
|
+
if (counts.partial) parts.push(t('summary.partial', { n: counts.partial }))
|
|
260
|
+
if (counts.rejected) parts.push(t('summary.rejected', { n: counts.rejected }))
|
|
261
|
+
if (counts.needs_info) parts.push(t('summary.needsInfo', { n: counts.needs_info }))
|
|
262
|
+
const headAction = typeof options.onReuseAll === 'function'
|
|
263
|
+
? reuseButton(t('sent.reuse'), options.onReuseAll, t('reuse.hint'))
|
|
264
|
+
: undefined
|
|
265
|
+
const head = buildSectionHead(t('replies.title', { n: replies.length }), parts.join(' · '), headAction)
|
|
266
|
+
card.style.display = 'flex'
|
|
267
|
+
card.style.flexDirection = 'column'
|
|
268
|
+
card.style.rowGap = '8px'
|
|
269
|
+
card.appendChild(head)
|
|
270
|
+
|
|
271
|
+
const body = document.createElement('div')
|
|
272
|
+
body.className = 'sa-replies-body'
|
|
273
|
+
body.style.paddingTop = '0px'
|
|
274
|
+
// 卡片之间也用同一档 8px,标题到首卡、卡到卡完全一致。
|
|
275
|
+
body.style.rowGap = '8px'
|
|
276
|
+
for (const reply of replies) {
|
|
277
|
+
// uuid 是唯一依据;老答复没有 uuid 时才退回按序号配对。
|
|
278
|
+
const item =
|
|
279
|
+
typeof reply.uuid === 'string' && reply.uuid !== ''
|
|
280
|
+
? byUuid.get(reply.uuid)
|
|
281
|
+
: byIndex.get(reply.index)
|
|
282
|
+
// 跨会话答复时本地没有原条目,就显示服务端随答复带回的引文与批注内容。
|
|
283
|
+
const displayItem =
|
|
284
|
+
item ??
|
|
285
|
+
(typeof reply.quote === 'string' || typeof reply.note === 'string'
|
|
286
|
+
? { quote: reply.quote, note: reply.note }
|
|
287
|
+
: undefined)
|
|
288
|
+
const [labelKey, tone] = VERDICT_LABELS[reply.verdict] ?? ['verdict.fallback', 'accepted']
|
|
289
|
+
const group = document.createElement('div')
|
|
290
|
+
group.className = `sa-reply-item sa-tone-${tone}`
|
|
291
|
+
group.setAttribute('data-sa-batch-at', String(Number.isFinite(reply.at) ? reply.at : 0))
|
|
292
|
+
group.setAttribute('data-sa-reply-index', String(reply.index))
|
|
293
|
+
if (typeof reply.uuid === 'string' && reply.uuid !== '') group.setAttribute('data-sa-reply-uuid', reply.uuid)
|
|
294
|
+
|
|
295
|
+
const cardHead = document.createElement('div')
|
|
296
|
+
cardHead.className = 'sa-reply-head'
|
|
297
|
+
const index = document.createElement('span')
|
|
298
|
+
index.className = 'sa-reply-index'
|
|
299
|
+
index.textContent = t('reply.index', { n: reply.index })
|
|
300
|
+
const verdict = document.createElement('span')
|
|
301
|
+
verdict.className = `sa-a-verdict sa-reply-${tone}`
|
|
302
|
+
verdict.textContent = t(labelKey)
|
|
303
|
+
cardHead.append(index, verdict)
|
|
304
|
+
const replayItem = displayItem ?? { quote: reply.quote, note: reply.note }
|
|
305
|
+
if (typeof options.onReplayItem === 'function') {
|
|
306
|
+
cardHead.appendChild(reuseButton(t('replies.replay'), () => options.onReplayItem(replayItem), t('reuse.hint')))
|
|
307
|
+
}
|
|
308
|
+
group.appendChild(cardHead)
|
|
309
|
+
|
|
310
|
+
const content = document.createElement('div')
|
|
311
|
+
content.className = 'sa-reply-body'
|
|
312
|
+
|
|
313
|
+
if (displayItem !== undefined) {
|
|
314
|
+
const q = document.createElement('div')
|
|
315
|
+
q.className = 'sa-q'
|
|
316
|
+
const quoteText = typeof displayItem.quote === 'string' ? displayItem.quote.trim() : ''
|
|
317
|
+
if (quoteText !== '') {
|
|
318
|
+
const qLabel = document.createElement('div')
|
|
319
|
+
qLabel.className = 'sa-q-label'
|
|
320
|
+
qLabel.textContent = t('label.quote')
|
|
321
|
+
const qHead = document.createElement('div')
|
|
322
|
+
qHead.className = 'sa-q-head'
|
|
323
|
+
qHead.appendChild(qLabel)
|
|
324
|
+
// 跳转按钮放在「引用原文」标题行末尾、作为普通子元素;引文块自己的点击仍只管展开。
|
|
325
|
+
if (typeof options.onJumpQuote === 'function') {
|
|
326
|
+
qHead.appendChild(jumpButton(displayItem, options.onJumpQuote))
|
|
327
|
+
}
|
|
328
|
+
q.appendChild(qHead)
|
|
329
|
+
const quote = document.createElement('div')
|
|
330
|
+
quote.className = 'sa-q-quote'
|
|
331
|
+
if (isAdopt(displayItem.note)) quote.dataset.adopt = '1'
|
|
332
|
+
quote.setAttribute('data-sa-field', 'quote')
|
|
333
|
+
quote.textContent = quoteText
|
|
334
|
+
quote.title = t('expand')
|
|
335
|
+
// 超过三行时折叠;点一下展开,再点收回。
|
|
336
|
+
quote.addEventListener('click', () => {
|
|
337
|
+
quote.classList.toggle('sa-q-open')
|
|
338
|
+
})
|
|
339
|
+
q.appendChild(quote)
|
|
340
|
+
}
|
|
341
|
+
if (typeof displayItem.note === 'string' && displayItem.note.trim() !== '') {
|
|
342
|
+
const noteLabel = document.createElement('div')
|
|
343
|
+
noteLabel.className = 'sa-q-label'
|
|
344
|
+
noteLabel.textContent = t('label.note')
|
|
345
|
+
q.appendChild(noteLabel)
|
|
346
|
+
const note = document.createElement('div')
|
|
347
|
+
note.className = 'sa-q-note'
|
|
348
|
+
note.setAttribute('data-sa-field', 'note')
|
|
349
|
+
paintNote(note, displayItem.note, noteView(displayItem.note))
|
|
350
|
+
q.appendChild(note)
|
|
351
|
+
}
|
|
352
|
+
// 原批注带的附图属于「批注」内容,跟在批注正文后面、同一层级里。
|
|
353
|
+
const replyThumbs = Array.isArray(displayItem.thumbs) ? displayItem.thumbs : []
|
|
354
|
+
if (replyThumbs.length > 0) {
|
|
355
|
+
const gallery = document.createElement('div')
|
|
356
|
+
gallery.className = 'sa-sent-thumbs'
|
|
357
|
+
for (const thumb of replyThumbs) {
|
|
358
|
+
if (typeof thumb?.dataUrl !== 'string' || thumb.dataUrl === '') continue
|
|
359
|
+
const img = document.createElement('img')
|
|
360
|
+
img.className = 'sa-sent-thumb'
|
|
361
|
+
img.src = thumb.dataUrl
|
|
362
|
+
img.alt = typeof thumb.name === 'string' ? thumb.name : t('image.alt')
|
|
363
|
+
img.title = t('image.open')
|
|
364
|
+
img.addEventListener('click', (event) => {
|
|
365
|
+
event.preventDefault()
|
|
366
|
+
event.stopPropagation()
|
|
367
|
+
openImageViewer(typeof thumb.preview === 'string' && thumb.preview !== '' ? thumb.preview : thumb.dataUrl, thumb.name)
|
|
368
|
+
})
|
|
369
|
+
gallery.appendChild(img)
|
|
370
|
+
}
|
|
371
|
+
if (gallery.childNodes.length > 0) q.appendChild(gallery)
|
|
372
|
+
}
|
|
373
|
+
content.appendChild(q)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const a = document.createElement('div')
|
|
377
|
+
a.className = 'sa-a'
|
|
378
|
+
const aHead = document.createElement('div')
|
|
379
|
+
aHead.className = 'sa-a-head'
|
|
380
|
+
const aLabel = document.createElement('span')
|
|
381
|
+
aLabel.className = 'sa-a-label'
|
|
382
|
+
aLabel.textContent = displayItem !== undefined ? t('label.answer') : t('reply.fallbackLabel', { n: reply.index })
|
|
383
|
+
aHead.appendChild(aLabel)
|
|
384
|
+
a.appendChild(aHead)
|
|
385
|
+
const reason = document.createElement('div')
|
|
386
|
+
reason.className = 'sa-a-reason'
|
|
387
|
+
reason.setAttribute('data-sa-field', 'reason')
|
|
388
|
+
if (markdown !== undefined && typeof markdown.mount === 'function') {
|
|
389
|
+
markdown.mount(reason, typeof reply.reason === 'string' ? reply.reason : '')
|
|
390
|
+
} else {
|
|
391
|
+
reason.textContent = typeof reply.reason === 'string' ? reply.reason : ''
|
|
392
|
+
}
|
|
393
|
+
a.appendChild(reason)
|
|
394
|
+
if (typeof reply.next === 'string' && reply.next.trim() !== '') {
|
|
395
|
+
const next = document.createElement('div')
|
|
396
|
+
next.className = 'sa-a-next'
|
|
397
|
+
next.setAttribute('data-sa-field', 'next')
|
|
398
|
+
const label = document.createElement('span')
|
|
399
|
+
label.className = 'sa-a-next-label'
|
|
400
|
+
label.textContent = t('next.label')
|
|
401
|
+
const body = document.createElement('div')
|
|
402
|
+
body.className = 'sa-a-next-text'
|
|
403
|
+
if (markdown !== undefined && typeof markdown.mount === 'function') {
|
|
404
|
+
markdown.mount(body, reply.next)
|
|
405
|
+
} else {
|
|
406
|
+
body.textContent = reply.next
|
|
407
|
+
}
|
|
408
|
+
next.append(label, body)
|
|
409
|
+
a.appendChild(next)
|
|
410
|
+
}
|
|
411
|
+
content.appendChild(a)
|
|
412
|
+
group.appendChild(content)
|
|
413
|
+
body.appendChild(group)
|
|
414
|
+
}
|
|
415
|
+
const wrap = collapsible(body, true)
|
|
416
|
+
applyCollapsed(head, wrap, true)
|
|
417
|
+
card.dataset.open = '1'
|
|
418
|
+
head.addEventListener('click', (event) => {
|
|
419
|
+
event.preventDefault()
|
|
420
|
+
event.stopPropagation()
|
|
421
|
+
applyCollapsed(head, wrap, wrap.dataset.open !== '1')
|
|
422
|
+
card.dataset.open = wrap.dataset.open
|
|
423
|
+
})
|
|
424
|
+
card.append(wrap)
|
|
425
|
+
return card
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 只读面板里的答复正文:只把文本按 markdown 渲染,不搬答复卡的底色、内边距与分区造型。
|
|
430
|
+
* @param reply - 答复条目(reason / next)。
|
|
431
|
+
*/
|
|
432
|
+
function buildReplyDetail(reply) {
|
|
433
|
+
const wrap = document.createElement('div')
|
|
434
|
+
wrap.className = 'sa-pop-reply-body'
|
|
435
|
+
wrap.setAttribute('data-sa-reply-detail', '1')
|
|
436
|
+
if (typeof reply.uuid === 'string' && reply.uuid !== '') wrap.setAttribute('data-sa-reply-uuid', reply.uuid)
|
|
437
|
+
|
|
438
|
+
const render = (node, text) => {
|
|
439
|
+
if (markdown !== undefined && typeof markdown.mount === 'function') markdown.mount(node, text)
|
|
440
|
+
else node.textContent = text
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const reasonText = typeof reply.reason === 'string' ? reply.reason : ''
|
|
444
|
+
if (reasonText.trim() !== '') {
|
|
445
|
+
const reason = document.createElement('div')
|
|
446
|
+
reason.className = 'sa-pop-reply-reason'
|
|
447
|
+
reason.setAttribute('data-sa-field', 'reason')
|
|
448
|
+
render(reason, reasonText)
|
|
449
|
+
wrap.appendChild(reason)
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const nextText = typeof reply.next === 'string' ? reply.next : ''
|
|
453
|
+
if (nextText.trim() !== '') {
|
|
454
|
+
const next = document.createElement('div')
|
|
455
|
+
next.className = 'sa-pop-reply-next'
|
|
456
|
+
next.setAttribute('data-sa-field', 'next')
|
|
457
|
+
const label = document.createElement('span')
|
|
458
|
+
label.className = 'sa-pop-reply-next-label'
|
|
459
|
+
label.textContent = t('next.label')
|
|
460
|
+
const body = document.createElement('div')
|
|
461
|
+
body.className = 'sa-pop-reply-next-text'
|
|
462
|
+
render(body, nextText)
|
|
463
|
+
next.append(label, body)
|
|
464
|
+
wrap.appendChild(next)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return wrap
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* 只读面板里答复的结论胶囊:由调用方放到「答复」标题同一行。
|
|
472
|
+
* @param reply - 答复条目(verdict)。
|
|
473
|
+
*/
|
|
474
|
+
function buildReplyVerdict(reply) {
|
|
475
|
+
const [labelKey, tone] = VERDICT_LABELS[reply?.verdict] ?? ['verdict.unknown', 'accepted']
|
|
476
|
+
const verdict = document.createElement('span')
|
|
477
|
+
verdict.className = `sa-a-verdict sa-reply-${tone}`
|
|
478
|
+
verdict.textContent = t(labelKey)
|
|
479
|
+
return verdict
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* 答复的语气(accepted/partial/rejected/needs_info):调用方用它给容器挂颜色。
|
|
484
|
+
* @param reply - 答复条目(verdict)。
|
|
485
|
+
*/
|
|
486
|
+
function replyTone(reply) {
|
|
487
|
+
const [, tone] = VERDICT_LABELS[reply?.verdict] ?? ['verdict.unknown', 'accepted']
|
|
488
|
+
return tone
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
return {
|
|
492
|
+
sectionChevron,
|
|
493
|
+
buildSectionHead,
|
|
494
|
+
collapsible,
|
|
495
|
+
applyCollapsed,
|
|
496
|
+
buildSentCard,
|
|
497
|
+
buildReplySection,
|
|
498
|
+
buildReplyDetail,
|
|
499
|
+
buildReplyVerdict,
|
|
500
|
+
replyTone,
|
|
501
|
+
}
|
|
502
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** 批注负载的文件名;只是给用户看的,宿主靠 JSON 里的 kind 字段认领。 */
|
|
2
|
+
export const ANNOTATION_FILE = '批注.json'
|
|
3
|
+
/** 负载类型标记;客户端与宿主半边共用这个值。*/
|
|
4
|
+
export const PAYLOAD_KIND = 'dsh-selection-annotations'
|
|
5
|
+
export const MAX_QUOTE = 1600
|
|
6
|
+
export const MAX_NOTE = 4000
|
|
7
|
+
/** 单条批注最多能挂几张图;再多会明显拖慢消息序列化。*/
|
|
8
|
+
export const MAX_IMAGES_PER_ANNOTATION = 4
|
|
9
|
+
/** 单张图片的字节上限,超过就拒绝(避免把一条消息撑爆)。*/
|
|
10
|
+
export const MAX_IMAGE_BYTES = 8 * 1024 * 1024
|
|
11
|
+
/** 图片设置键:压缩开关、质量、触发压缩的最小边。*/
|
|
12
|
+
export const IMAGE_SETTINGS_KEY = 'dsh-selection-annotations:image-settings'
|
|
13
|
+
/** 默认设置:80% 质量、最短边超过 100 像素才重编码。 */
|
|
14
|
+
export const DEFAULT_IMAGE_SETTINGS = { compress: true, quality: 0.8, minSize: 100, webShot: 'element' }
|
|
15
|
+
/** 批注指令设置键:随批注数据块发给模型的说明文字。*/
|
|
16
|
+
export const INSTRUCTION_SETTINGS_KEY = 'dsh-selection-annotations:instruction-settings'
|
|
17
|
+
/** 「批注采纳」预填文本:可在插件设置里改,恢复默认回到下面这句。*/
|
|
18
|
+
export const ADOPT_SETTINGS_KEY = 'dsh-selection-annotations:adopt-settings'
|
|
19
|
+
export const DEFAULT_ADOPT_TEXT = '【意见采纳】'
|
|
20
|
+
/** 「批注否决」预填文本:与采纳同一组设置项,可改词,恢复默认回到下面这句。*/
|
|
21
|
+
export const REJECT_SETTINGS_KEY = 'dsh-selection-annotations:reject-settings'
|
|
22
|
+
export const DEFAULT_REJECT_TEXT = '【意见否决】'
|
|
23
|
+
/** 空提示词填充:只发批注、正文为空时自动填入的句子;设为空串即关闭。*/
|
|
24
|
+
export const FALLBACK_SETTINGS_KEY = 'dsh-selection-annotations:fallback-settings'
|
|
25
|
+
/** 弹层尺寸:用户拖拽调整后的宽高按会话记住,下次打开沿用。*/
|
|
26
|
+
export const POPOVER_SIZE_KEY = 'dsh-selection-annotations:popover-size'
|
|
27
|
+
export const DEFAULT_FALLBACK_TEXT = '此轮对话内容均在批注中给出,总计 {count} 条批注。\n此轮消息发起时间:{time}'
|
|
28
|
+
/** 默认批注指令;删掉「必须调用annotation_replies」这句,逐条答复会退化成正文自由文本。*/
|
|
29
|
+
export const DEFAULT_INSTRUCTION = [
|
|
30
|
+
'这是用户随消息附上的批注数据块,与本轮用户正文同属一条用户消息:正文可能在前,也可能只有这份数据。\n',
|
|
31
|
+
'\n',
|
|
32
|
+
'## 怎么读\n',
|
|
33
|
+
'- `quote`:用户选中的原文。\n',
|
|
34
|
+
'- `uuid`:每条顶层自带 `uuid`,它是答复这一条的唯一依据;从捕获到入库不会变,不要拿序号或轮次替代。\n',
|
|
35
|
+
'- `source`:位置。工作区文件用 `path` + `lineStart/lineEnd`(1 基行号)+ `charStart/charEnd`;对话消息用 `role` + `anchorKey` + `charStart/charEnd`。\n',
|
|
36
|
+
'- `kind: "reply"`(逐条答复区域):`batchAt` 是批次时间戳,`uuid` 是条目 uuid,`index` 是序号(只供阅读),`field` 取 `quote` / `note` / `reason` / `next`(跨字段为 `item`)。\n',
|
|
37
|
+
'- `kind: "sent"`(已发送批注区域):`anchorKey` 是卡片所属消息,顶层 `uuid` 是这条批注的 uuid,`source.uuid`(若有)只说明它引用了哪条已发送批注,不是答复目标;`index` 只供阅读。\n',
|
|
38
|
+
'- `charStart/charEnd`:半开区间。`textOrigin: "source"` 指文件原文偏移,`"rendered"` 指渲染文本偏移;能读原文时优先 source。\n',
|
|
39
|
+
'- `images`:该条批注的图片,`order` 是它在消息图片附件里的 1 基顺序。\n',
|
|
40
|
+
'\n',
|
|
41
|
+
'## 怎么答\n',
|
|
42
|
+
'- 处理完必须调用 `annotation_replies` 工具,不要在正文里逐条重复。\n',
|
|
43
|
+
'- replies 里每一项用该条批注顶层的 `uuid` 指定,`uuid` 是唯一依据,不要传序号、轮次。\n',
|
|
44
|
+
'- `verdict` 取 `accepted` / `partial` / `rejected` / `needs_info`。\n',
|
|
45
|
+
'- `reason` 写的内容:基于轮次综合受理结论的视角,逐个应答单条批注的回复。\n',
|
|
46
|
+
'- `next` 写的内容:基于答单条批注的回复内容,对应接下来的具体预期、做法方案。\n',
|
|
47
|
+
'- `reason` 与 `next` 内容均以 Markdown 渲染,加粗、行内代码、代码块与表格都可用;表达上要优先给子弹式要点列表,之后再给相关阐述。\n',
|
|
48
|
+
'- 正文只写整体说明或需要澄清的问题。',
|
|
49
|
+
].join('')
|
|
50
|
+
|
|
51
|
+
/** 英文界面下的批注指令;结构与中文版逐项对应。*/
|
|
52
|
+
export const DEFAULT_INSTRUCTION_EN = [
|
|
53
|
+
'This annotation payload was attached by the user to this message and is part of the user instruction, together with the body (which may come before it, or be absent entirely).\n',
|
|
54
|
+
'\n',
|
|
55
|
+
'## How to read it\n',
|
|
56
|
+
'- `quote`: the text the user selected.\n',
|
|
57
|
+
'- `uuid`: every annotation carries a top-level `uuid`; it is the only key for replying to that annotation. It does not change from capture to storage — do not substitute the sequence number or the turn.\n',
|
|
58
|
+
'- `source`: the position. Workspace files use `path` + `lineStart/lineEnd` (1-based lines) + `charStart/charEnd`; chat messages use `role` + `anchorKey` + `charStart/charEnd`.\n',
|
|
59
|
+
'- `kind: "reply"` (per-answer area): `batchAt` is the batch timestamp, `uuid` is the entry uuid, `index` is the sequence number (for reading only), `field` is `quote` / `note` / `reason` / `next` (`item` when the selection spans fields).\n',
|
|
60
|
+
'- `kind: "sent"` (sent-annotations area): `anchorKey` is the message the card belongs to; the top-level `uuid` is this annotation\'s uuid; `source.uuid` (when present) only says which sent annotation it references — it is not the reply target; `index` is for reading only.\n',
|
|
61
|
+
'- `charStart/charEnd`: a half-open range. `textOrigin: "source"` means offsets in the original file text, `"rendered"` means offsets in the rendered text; prefer source when the file can be read.\n',
|
|
62
|
+
'- `images`: images attached to that annotation; `order` is the 1-based position among this message\'s image attachments.\n',
|
|
63
|
+
'\n',
|
|
64
|
+
'## How to answer\n',
|
|
65
|
+
'- When done, you must call the `annotation_replies` tool instead of repeating replies in the body.\n',
|
|
66
|
+
'- Each entry in replies names its annotation by that annotation\'s top-level `uuid`; the `uuid` is the only key — do not pass the sequence number or the turn.\n',
|
|
67
|
+
'- `verdict` is `accepted` / `partial` / `rejected` / `needs_info`.\n',
|
|
68
|
+
'- `reason` explains the verdict for that annotation, in the context of the whole turn.\n',
|
|
69
|
+
'- `next` states the concrete expectation or plan that follows from the reply to that annotation.\n',
|
|
70
|
+
'- `reason` and `next` render as Markdown: bold, inline code, code fences and tables are supported; prefer bullet lists first, then the supporting explanation.\n',
|
|
71
|
+
'- Use the body only for an overall summary or clarifying questions.',
|
|
72
|
+
].join('')
|
|
73
|
+
|
|
74
|
+
/** 界面文案命名空间;DSH 按语言注册后由 bind 解析。*/
|
|
75
|
+
export const LOCALE_NS = 'selection-annotations'
|
|
76
|
+
/** 构建标记:显示在批注总览底部,用来确认当前页面加载的是哪一版代码。*/
|
|
77
|
+
export const PLUGIN_BUILD = '2.1.0'
|
|
78
|
+
|
|
79
|
+
/** 未提交草稿的本地存储前缀:按会话分键。*/
|
|
80
|
+
export const DRAFT_STORAGE_PREFIX = 'dsh-selection-annotations:draft:'
|
|
81
|
+
export const DRAFT_MAX_SESSIONS = 24
|
|
82
|
+
export const DRAFT_MAX_ITEMS = 200
|
|
83
|
+
/** 已提交批注的本地台账前缀:按会话分键。*/
|
|
84
|
+
export const SENT_STORAGE_PREFIX = 'dsh-selection-annotations:sent:'
|
|
85
|
+
export const SENT_MAX_ENTRIES = 120
|
|
86
|
+
export const SENT_MAX_BYTES = 2 * 1024 * 1024
|
|
87
|
+
/** 轮询宿主答复的间隔;模型答复通常紧跟发送。*/
|
|
88
|
+
export const REPLY_POLL_MS = 6000
|
|
89
|
+
/** 刚发出的批注负载等消息行出现的最长时间。*/
|
|
90
|
+
export const SENT_PENDING_TTL_MS = 60000
|
|
91
|
+
/** 中文原文即现有措辞,保持与既有测试断言一致。*/
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export const DRAFT_MAX_BYTES = 3.5 * 1024 * 1024
|
|
2
|
+
/** 鼠标停在已批注原文上多久打开编辑框。*/
|
|
3
|
+
export const HOVER_OPEN_DELAY_MS = 500
|
|
4
|
+
/** 选区稳定后再弹工具条,避免拖选过程中抖动。*/
|
|
5
|
+
export const SETTLE_MS = 220
|
|
6
|
+
/** 批注集合变化后合并上传,避免每敲一个字都发一次请求。*/
|
|
7
|
+
export const UPLOAD_DEBOUNCE_MS = 450
|
|
8
|
+
/** 编辑弹层里改一个字就写盘会太频繁:停手 300ms 再存,崩溃时最多丢这一段。*/
|
|
9
|
+
export const POP_AUTO_SAVE_MS = 300
|
|
10
|
+
/** 「跳到出处」的高亮闪现时长,到点自动撤掉,不留在正文里。*/
|
|
11
|
+
export const JUMP_FLASH_MS = 2000
|
|
12
|
+
/** 轮次导航按钮点下去后,等目标行挂载出来的上限;超时就提示没加载。*/
|
|
13
|
+
export const JUMP_NAV_TIMEOUT_MS = 3000
|
|
14
|
+
/** 等挂载期间的重试间隔;按宿主重绘节奏给两帧左右。*/
|
|
15
|
+
export const JUMP_NAV_POLL_MS = 120
|
|
16
|
+
/** 跳转滚动后的保护窗口:这段时间内重绘不做位置补偿,避免把刚滚到的目标拽回去。*/
|
|
17
|
+
export const JUMP_SCROLL_GRACE_MS = 1500
|
|
18
|
+
/** 等草稿附件上传就绪的上限;超时就本次不挂,绝不制造发送失败。*/
|
|
19
|
+
export const UPLOAD_READY_TIMEOUT_MS = 10000
|
|
20
|
+
/** 装饰重绘合并窗口。*/
|
|
21
|
+
export const REPAINT_MS = 120
|
|
22
|
+
/** 拉取式消费检测的间隔:不依赖 composer 是否发布通知。*/
|
|
23
|
+
export const CONSUME_POLL_MS = 1000
|
|
24
|
+
/** 输入态说「附件没了」之后,隔多久向运行时求证(提交可能只是暂时移走)。*/
|
|
25
|
+
export const CONSUME_CONFIRM_MS = 400
|
|
26
|
+
/** 读源文件求行号的超时;超时就退回渲染坐标,不拖住保存。*/
|
|
27
|
+
export const SOURCE_LOOKUP_TIMEOUT_MS = 600
|
|
28
|
+
/** 认领「上一轮遗留的孤儿批注附件」的间隔。*/
|
|
29
|
+
export const ORPHAN_SWEEP_MS = 1500
|
|
30
|
+
/** 首次上传最多为在途的位置精修等多也——精修通常几十毫秒,这只是个上限。*/
|
|
31
|
+
export const REFINE_WAIT_MS = 1200
|
|
32
|
+
/** 发出后仍可能被运行时 restore 回来的孤儿附件,要盯多久。 */
|
|
33
|
+
export const STRAY_GUARD_MS = 120000
|
|
34
|
+
|