dsh-prompt-pool 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/client.js +2525 -180
- package/package.json +1 -1
package/client.js
CHANGED
|
@@ -19,7 +19,7 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
const NATIVE_TAB_ID = 'dsh-prompt-pool';
|
|
20
20
|
const NATIVE_TAB_KIND = 'prompt-pool';
|
|
21
21
|
/** Shown in the settings about card; keep in step with plugin/package.json. */
|
|
22
|
-
const PLUGIN_VERSION = '1.
|
|
22
|
+
const PLUGIN_VERSION = '1.4.0';
|
|
23
23
|
const PLUGIN_AUTHOR = 'GanttShen';
|
|
24
24
|
/** Replace once the public repository exists; the row hides while it is empty. */
|
|
25
25
|
const PLUGIN_REPO = 'https://github.com/Ganttfly/dsh-prompt-pool';
|
|
@@ -64,7 +64,7 @@ window.__ModuleLoader__.load({
|
|
|
64
64
|
'button.pending': '待发送 {n} 条',
|
|
65
65
|
'panel.title': '提示池',
|
|
66
66
|
'panel.close': '关闭',
|
|
67
|
-
'panel.capture': '
|
|
67
|
+
'panel.capture': '保存草稿',
|
|
68
68
|
'panel.captureHint': '把输入框里的内容复制一份存进池子(图片附件一起存);输入框里的字会保留',
|
|
69
69
|
'panel.resize': '拖动调整高度,双击还原',
|
|
70
70
|
'panel.resizeWidth': '拖动调整宽度,双击还原',
|
|
@@ -98,12 +98,11 @@ window.__ModuleLoader__.load({
|
|
|
98
98
|
'mention.sessionClosed': '会话未打开,无法读取技能目录',
|
|
99
99
|
'mention.failed': '读取失败',
|
|
100
100
|
'mention.timeout': '读取超时:宿主没有响应(可能没有活跃会话)',
|
|
101
|
-
'row.insert': '
|
|
101
|
+
'row.insert': '生成草稿',
|
|
102
102
|
'row.select': '加入待发送队列',
|
|
103
103
|
'row.duplicate': '复制一份,追加到池子末尾',
|
|
104
104
|
'page.title': '提示池',
|
|
105
105
|
'tab.description': '暂存、编辑、编排你的提示词,按住顺序一次性释放',
|
|
106
|
-
'page.count': '共 {n} 条',
|
|
107
106
|
'page.search': '搜索标题或内容…',
|
|
108
107
|
'page.empty': '还没有内容。点右上角「+ 提示词」开始。',
|
|
109
108
|
'page.emptyOftenuse': '还没有常用条目。把条目的「分组」改成「常用」即可。',
|
|
@@ -115,6 +114,16 @@ window.__ModuleLoader__.load({
|
|
|
115
114
|
'settings.open': '提示池设置',
|
|
116
115
|
'settings.button': '设置',
|
|
117
116
|
'settings.tab.order': '分组',
|
|
117
|
+
'settings.defaultTab': '打开时默认选中',
|
|
118
|
+
'settings.defaultTabNotes': '批注',
|
|
119
|
+
'settings.defaultTabWorkspace': '当前工作区',
|
|
120
|
+
'settings.defaultTabOther': '其他',
|
|
121
|
+
'settings.tab.notes': '批注',
|
|
122
|
+
'settings.notesIntro': '批注和当前会话绑定。\n在正文中添加的批注同时也会出现在提示池的【批注】页面,也可以把它存为提示词,或直接插入会话输入框。',
|
|
123
|
+
'settings.notesKeepDraft': '生成草稿后,仍旧保留',
|
|
124
|
+
'settings.notesKeepDraftHint': '关闭后,生成草稿成功的批注会从列表移除。',
|
|
125
|
+
'settings.notesKeepStore': '存为提示词后,仍旧保留',
|
|
126
|
+
'settings.notesKeepStoreHint': '关闭后,存成提示词成功的批注会从列表移除。',
|
|
118
127
|
'settings.table': '分组的顺序与显示',
|
|
119
128
|
'settings.tableHint': '箭头调整先后顺序;右侧三列决定这一组怎么显示。',
|
|
120
129
|
'settings.tableGroup': '分组',
|
|
@@ -134,6 +143,17 @@ window.__ModuleLoader__.load({
|
|
|
134
143
|
'settings.keepInsertHint': '关闭后,插入成功的条目会从池子移出;提示条上的「撤销」可以恢复。',
|
|
135
144
|
'settings.keepQueue': '加入待发送队列后,仍旧保留在池子中',
|
|
136
145
|
'settings.keepQueueHint': '关闭后,条目一加入队列就从池子移出;队列里的那一条不受影响。',
|
|
146
|
+
'settings.seedCard': '内置提示词',
|
|
147
|
+
'settings.seedHint': '当前有 {builtin} 条内置提示词,其中 {edited} 条已编辑。重置只影响内置条目,自定义条目和队列不受影响。',
|
|
148
|
+
'settings.seedLanguageZh': '中文',
|
|
149
|
+
'settings.seedLanguageEn': 'English',
|
|
150
|
+
'settings.seedNote': '将按当前界面语言「{language}」重置。',
|
|
151
|
+
'settings.seedKeepEdited': '保留已编辑的内置条目',
|
|
152
|
+
'settings.seedKeepEditedHint': '勾选后,编辑过的内置条目会转成普通条目保留;未勾选则一起删除。',
|
|
153
|
+
'settings.seedResetButton': '重置内置提示词',
|
|
154
|
+
'settings.seedResetTitle': '重置内置提示词?',
|
|
155
|
+
'settings.seedResetConfirm': '将移除 {removed} 条内置提示词,保留 {kept} 条编辑为普通条目,并按「{language}」重新写入 {added} 条。',
|
|
156
|
+
'settings.seedResetDone': '已重置:移除 {removed} 条,保留 {kept} 条编辑,写入 {added} 条。',
|
|
137
157
|
'settings.about': '插件信息',
|
|
138
158
|
'settings.aboutAuthor': '作者',
|
|
139
159
|
'settings.aboutRepo': '仓库',
|
|
@@ -195,9 +215,41 @@ window.__ModuleLoader__.load({
|
|
|
195
215
|
'status.savedPartialTo': '已存入「{group}」,但 {n} 个附件没有保存',
|
|
196
216
|
'capture.title': '存到哪个分组?',
|
|
197
217
|
'menu.title': '添加到提示池',
|
|
218
|
+
'menu.pool': '+ 提示词',
|
|
219
|
+
'menu.group': '提示池',
|
|
198
220
|
'menu.copy': '复制',
|
|
199
221
|
'menu.copied': '已复制',
|
|
200
222
|
'menu.copyFailed': '复制失败:请按 {shortcut}',
|
|
223
|
+
'note.add': '+ 批注',
|
|
224
|
+
'note.title': '批注',
|
|
225
|
+
'note.placeholder': '写点什么:回答、疑问或修改意见',
|
|
226
|
+
'note.empty': '没有匹配的批注',
|
|
227
|
+
'note.emptyIntro': '还没有批注。在会话区选中一句话,右键「+ 批注」即可添加。',
|
|
228
|
+
'note.save': '保存',
|
|
229
|
+
'note.cancel': '取消',
|
|
230
|
+
'note.delete': '删除',
|
|
231
|
+
'note.compose': '生成草稿',
|
|
232
|
+
'note.composeHint': '把列表中全部批注生成一份草稿放入对话框',
|
|
233
|
+
'note.composeStoreHint': '把列表中全部批注存成一条提示词',
|
|
234
|
+
'note.insert': '插入',
|
|
235
|
+
'note.locate': '定位',
|
|
236
|
+
'note.locateFailed': '这条批注暂时找不到原文(回复可能被折叠或改写了)。',
|
|
237
|
+
'note.deleteConfirm': '删除这条批注?',
|
|
238
|
+
'note.default': '默认',
|
|
239
|
+
'note.reset': '重置位置',
|
|
240
|
+
'note.store': '存成提示词',
|
|
241
|
+
'note.stored': '已存入 {group}',
|
|
242
|
+
'note.composeStore': '存成提示词',
|
|
243
|
+
'note.composeStored': '已存成提示词到 {group}',
|
|
244
|
+
'note.inserted': '已插入输入框',
|
|
245
|
+
'note.insertFailed': '输入框暂不可用,稍后再试',
|
|
246
|
+
'note.quoteMissing': '这条批注暂时找不到原文位置(回复可能被折叠或改写了)。',
|
|
247
|
+
'note.kind.comment': '意见',
|
|
248
|
+
'note.kind.question': '提问',
|
|
249
|
+
'note.kind.agree': '同意',
|
|
250
|
+
'note.kind.disagree': '反对',
|
|
251
|
+
'note.kind.idea': '想法',
|
|
252
|
+
'note.kind.todo': '待办',
|
|
201
253
|
'menu.last': '上次',
|
|
202
254
|
'menu.count': '{n} 条',
|
|
203
255
|
'menu.saved': '已加入「{group}」',
|
|
@@ -264,12 +316,11 @@ window.__ModuleLoader__.load({
|
|
|
264
316
|
'mention.sessionClosed': 'The session is not open, so the catalog is unavailable',
|
|
265
317
|
'mention.failed': 'Failed to load',
|
|
266
318
|
'mention.timeout': 'Timed out: the host did not answer (no live session?)',
|
|
267
|
-
'row.insert': '
|
|
319
|
+
'row.insert': 'Generate draft',
|
|
268
320
|
'row.select': 'Add to the send queue',
|
|
269
321
|
'row.duplicate': 'Duplicate and append to the pool',
|
|
270
322
|
'page.title': 'Prompt pool',
|
|
271
323
|
'tab.description': 'Stage, edit and arrange prompts, then release them in order',
|
|
272
|
-
'page.count': '{n} items',
|
|
273
324
|
'page.search': 'Search title or text…',
|
|
274
325
|
'page.empty': 'Nothing yet. Use “+ Prompt” in the top right.',
|
|
275
326
|
'page.emptyOftenuse': 'Nothing here yet. Set an item’s group to Frequent.',
|
|
@@ -281,6 +332,16 @@ window.__ModuleLoader__.load({
|
|
|
281
332
|
'settings.open': 'Prompt pool settings',
|
|
282
333
|
'settings.button': 'Settings',
|
|
283
334
|
'settings.tab.order': 'Groups',
|
|
335
|
+
'settings.defaultTab': 'Open on',
|
|
336
|
+
'settings.defaultTabNotes': 'Annotations',
|
|
337
|
+
'settings.defaultTabWorkspace': 'Current workspace',
|
|
338
|
+
'settings.defaultTabOther': 'Other',
|
|
339
|
+
'settings.tab.notes': 'Annotations',
|
|
340
|
+
'settings.notesIntro': 'Annotations are bound to the current session.\nAnnotations added in the transcript also appear in the prompt pool\'s Annotations tab; they can also be saved as a prompt or inserted straight into the conversation composer.',
|
|
341
|
+
'settings.notesKeepDraft': 'Keep annotations after generating a draft',
|
|
342
|
+
'settings.notesKeepDraftHint': 'Turned off, annotations leave the list once a draft is generated.',
|
|
343
|
+
'settings.notesKeepStore': 'Keep annotations after saving as a prompt',
|
|
344
|
+
'settings.notesKeepStoreHint': 'Turned off, annotations leave the list once saved as a prompt.',
|
|
284
345
|
'settings.table': 'Group order and display',
|
|
285
346
|
'settings.tableHint': 'Use the arrows to reorder; the three columns decide how each family shows up.',
|
|
286
347
|
'settings.tableGroup': 'Group',
|
|
@@ -300,6 +361,17 @@ window.__ModuleLoader__.load({
|
|
|
300
361
|
'settings.keepInsertHint': 'Turned off, an inserted item leaves the pool; the toast offers an undo.',
|
|
301
362
|
'settings.keepQueue': 'Keep it in the pool after adding it to the send queue',
|
|
302
363
|
'settings.keepQueueHint': 'Turned off, the item leaves the pool as soon as it is queued; the queued copy stays.',
|
|
364
|
+
'settings.seedCard': 'Built-in prompts',
|
|
365
|
+
'settings.seedHint': 'The pool has {builtin} built-in prompts, {edited} of them edited. Resetting only touches built-ins; custom items and the queue are left alone.',
|
|
366
|
+
'settings.seedLanguageZh': 'Chinese',
|
|
367
|
+
'settings.seedLanguageEn': 'English',
|
|
368
|
+
'settings.seedNote': 'Resets in the current interface language: {language}.',
|
|
369
|
+
'settings.seedKeepEdited': 'Keep edited built-in items',
|
|
370
|
+
'settings.seedKeepEditedHint': 'Checked, edited built-ins become ordinary items; unchecked, they are removed too.',
|
|
371
|
+
'settings.seedResetButton': 'Reset built-in prompts',
|
|
372
|
+
'settings.seedResetTitle': 'Reset built-in prompts?',
|
|
373
|
+
'settings.seedResetConfirm': 'Remove {removed} built-in prompts, keep {kept} edited as ordinary items, and add {added} in {language}.',
|
|
374
|
+
'settings.seedResetDone': 'Reset: {removed} removed, {kept} edits kept, {added} added.',
|
|
303
375
|
'settings.about': 'Plugin info',
|
|
304
376
|
'settings.aboutAuthor': 'Author',
|
|
305
377
|
'settings.aboutRepo': 'Repository',
|
|
@@ -361,9 +433,41 @@ window.__ModuleLoader__.load({
|
|
|
361
433
|
'status.savedPartialTo': 'Saved to {group}; {n} attachment(s) were not captured',
|
|
362
434
|
'capture.title': 'Save to which group?',
|
|
363
435
|
'menu.title': 'Add to the prompt pool',
|
|
436
|
+
'menu.pool': '+ Prompt',
|
|
437
|
+
'menu.group': 'Prompt pool',
|
|
364
438
|
'menu.copy': 'Copy',
|
|
365
439
|
'menu.copied': 'Copied',
|
|
366
440
|
'menu.copyFailed': 'Copy failed: press {shortcut}',
|
|
441
|
+
'note.add': '+ Annotate',
|
|
442
|
+
'note.title': 'Annotations',
|
|
443
|
+
'note.placeholder': 'Write an answer, a question or a correction',
|
|
444
|
+
'note.empty': 'No matching annotations',
|
|
445
|
+
'note.emptyIntro': 'No annotations yet. Select a passage in the conversation area and right-click “+ Annotate” to add one.',
|
|
446
|
+
'note.save': 'Save',
|
|
447
|
+
'note.cancel': 'Cancel',
|
|
448
|
+
'note.delete': 'Delete',
|
|
449
|
+
'note.compose': 'Generate draft',
|
|
450
|
+
'note.composeHint': 'Turn every annotation in the list into one draft in the composer',
|
|
451
|
+
'note.composeStoreHint': 'Save every annotation in the list as one prompt',
|
|
452
|
+
'note.insert': 'Insert',
|
|
453
|
+
'note.locate': 'Locate',
|
|
454
|
+
'note.locateFailed': 'This note cannot find its passage right now (the reply may be folded or rewritten).',
|
|
455
|
+
'note.deleteConfirm': 'Delete this annotation?',
|
|
456
|
+
'note.default': 'Default',
|
|
457
|
+
'note.reset': 'Reset position',
|
|
458
|
+
'note.store': 'Save as prompt',
|
|
459
|
+
'note.stored': 'Saved to {group}',
|
|
460
|
+
'note.composeStore': 'Save as prompt',
|
|
461
|
+
'note.composeStored': 'Saved as a prompt in {group}',
|
|
462
|
+
'note.inserted': 'Inserted into the composer',
|
|
463
|
+
'note.insertFailed': 'The composer is not available; try again',
|
|
464
|
+
'note.quoteMissing': 'This note cannot find its text right now (the reply may be folded or rewritten).',
|
|
465
|
+
'note.kind.comment': 'Note',
|
|
466
|
+
'note.kind.question': 'Question',
|
|
467
|
+
'note.kind.agree': 'Agree',
|
|
468
|
+
'note.kind.disagree': 'Disagree',
|
|
469
|
+
'note.kind.idea': 'Idea',
|
|
470
|
+
'note.kind.todo': 'To do',
|
|
367
471
|
'menu.last': 'Last used',
|
|
368
472
|
'menu.count': '{n} item(s)',
|
|
369
473
|
'menu.saved': 'Added to {group}',
|
|
@@ -829,6 +933,8 @@ window.__ModuleLoader__.load({
|
|
|
829
933
|
images,
|
|
830
934
|
createdAt: Number.isFinite(raw.createdAt) ? raw.createdAt : now,
|
|
831
935
|
updatedAt: Number.isFinite(raw.updatedAt) ? raw.updatedAt : now,
|
|
936
|
+
...(raw.seed === true ? { seed: true } : {}),
|
|
937
|
+
...(raw.locale === 'zh' || raw.locale === 'en' ? { locale: raw.locale } : {}),
|
|
832
938
|
};
|
|
833
939
|
}
|
|
834
940
|
|
|
@@ -1004,6 +1110,26 @@ window.__ModuleLoader__.load({
|
|
|
1004
1110
|
];
|
|
1005
1111
|
}
|
|
1006
1112
|
|
|
1113
|
+
/**
|
|
1114
|
+
* The tab a freshly opened pool lands on. An unavailable preference (a
|
|
1115
|
+
* deleted group, a hidden workspace, no annotations yet) falls back to all.
|
|
1116
|
+
*/
|
|
1117
|
+
function resolveDefaultTab(pref, tabs, currentWorkspaceId, hasNotes) {
|
|
1118
|
+
if (!pref) return '';
|
|
1119
|
+
const ids = (tabs || []).map((tab) => tab.id);
|
|
1120
|
+
// The annotation tab always exists now, so the preference always applies.
|
|
1121
|
+
if (pref === 'notes') return 'notes';
|
|
1122
|
+
if (pref === '__workspace__') {
|
|
1123
|
+
const id = currentWorkspaceId ? 'workspace:' + currentWorkspaceId : '';
|
|
1124
|
+
return id && ids.indexOf(id) >= 0 ? id : 'all';
|
|
1125
|
+
}
|
|
1126
|
+
if (pref.indexOf('tab:') === 0) {
|
|
1127
|
+
const id = pref.slice(4);
|
|
1128
|
+
return ids.indexOf(id) >= 0 ? id : 'all';
|
|
1129
|
+
}
|
|
1130
|
+
return '';
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1007
1133
|
/** Small chooser: where should the captured draft go? */
|
|
1008
1134
|
function CaptureMenu(props) {
|
|
1009
1135
|
useEffect(() => {
|
|
@@ -1163,6 +1289,23 @@ window.__ModuleLoader__.load({
|
|
|
1163
1289
|
});
|
|
1164
1290
|
}
|
|
1165
1291
|
|
|
1292
|
+
/** Confirmation before the built-in set is replaced with a fresh language batch. */
|
|
1293
|
+
function SeedResetConfirm(props) {
|
|
1294
|
+
return h(ConfirmModal, {
|
|
1295
|
+
label: translate('settings.seedResetTitle'),
|
|
1296
|
+
text: translate('settings.seedResetConfirm', {
|
|
1297
|
+
removed: props.removed,
|
|
1298
|
+
kept: props.kept,
|
|
1299
|
+
added: props.added,
|
|
1300
|
+
language: props.language,
|
|
1301
|
+
}),
|
|
1302
|
+
cancelText: translate('row.cancel'),
|
|
1303
|
+
confirmText: translate('settings.seedResetButton'),
|
|
1304
|
+
onCancel: props.onCancel,
|
|
1305
|
+
onConfirm: props.onConfirm,
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1166
1309
|
/** The workspace rail, or just its items when there is nothing to switch between. */
|
|
1167
1310
|
function renderWorkspacePanes(props) {
|
|
1168
1311
|
const rail = props.rail || [];
|
|
@@ -1258,97 +1401,176 @@ window.__ModuleLoader__.load({
|
|
|
1258
1401
|
}
|
|
1259
1402
|
|
|
1260
1403
|
function emptyPool() {
|
|
1261
|
-
return { version: POOL_VERSION, categories: [], items: [], tray: [], settings: normalizeSettings(undefined), seeded:
|
|
1404
|
+
return { version: POOL_VERSION, categories: [], items: [], tray: [], settings: normalizeSettings(undefined), seeded: SEED_LEVEL };
|
|
1262
1405
|
}
|
|
1263
1406
|
|
|
1264
1407
|
/**
|
|
1265
1408
|
* First-run content: five behaviour switches that stay valid as one-liners.
|
|
1266
|
-
* They land in the 常用 group and stay ordinary, deletable items.
|
|
1409
|
+
* They land in the 常用 / Frequent group and stay ordinary, deletable items.
|
|
1410
|
+
* The locale is fixed at first run; switching languages later does not rewrite
|
|
1411
|
+
* items the user may already have edited.
|
|
1267
1412
|
*/
|
|
1268
|
-
const SEED_PROMPTS =
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1413
|
+
const SEED_PROMPTS = {
|
|
1414
|
+
zh: [
|
|
1415
|
+
['seed:plan-first', '先给方案', '先列改动清单:要改哪些文件、每处改什么、怎么验证。等我确认后再动手。'],
|
|
1416
|
+
['seed:scope-guard', '不动无关代码', '只改与目标直接相关的行;看到别的问题只记录,不顺手修。'],
|
|
1417
|
+
[
|
|
1418
|
+
'seed:pre-delivery',
|
|
1419
|
+
'交付前自检',
|
|
1420
|
+
'交付前给一条最小验证(命令或测试),并回答三件事:最可能出问题的地方、怎么回滚、哪些假设我没验证过。',
|
|
1421
|
+
],
|
|
1422
|
+
['seed:stop-restate', '停下重述', '停一下:重述我的原始要求和当前实际在做的事,指出偏差,再决定继续还是回退。'],
|
|
1423
|
+
['seed:commands', '给命令不给描述', '需要我操作时直接给可粘贴的命令、路径或代码块。'],
|
|
1275
1424
|
],
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1425
|
+
en: [
|
|
1426
|
+
[
|
|
1427
|
+
'seed:plan-first',
|
|
1428
|
+
'Plan first',
|
|
1429
|
+
'List the changes before touching code: which files, what changes in each, and how you will verify. Wait for my go-ahead before editing.',
|
|
1430
|
+
],
|
|
1431
|
+
[
|
|
1432
|
+
'seed:scope-guard',
|
|
1433
|
+
'Stay in scope',
|
|
1434
|
+
'Change only the lines directly related to the goal. If you spot other issues, note them instead of fixing them.',
|
|
1435
|
+
],
|
|
1436
|
+
[
|
|
1437
|
+
'seed:pre-delivery',
|
|
1438
|
+
'Check before delivery',
|
|
1439
|
+
'Before delivering, give one minimal verification (a command or test) and answer three things: what is most likely to break, how to roll back, and which assumptions I have not verified.',
|
|
1440
|
+
],
|
|
1441
|
+
[
|
|
1442
|
+
'seed:stop-restate',
|
|
1443
|
+
'Stop and restate',
|
|
1444
|
+
'Pause: restate my original request and what you are actually doing, call out the drift, then decide whether to continue or roll back.',
|
|
1445
|
+
],
|
|
1446
|
+
[
|
|
1447
|
+
'seed:commands',
|
|
1448
|
+
'Commands, not prose',
|
|
1449
|
+
'When I need to act, give me commands, paths, or code blocks I can paste directly.',
|
|
1450
|
+
],
|
|
1451
|
+
],
|
|
1452
|
+
};
|
|
1279
1453
|
|
|
1280
1454
|
/** Templates: each one has a hole to fill and a shape the answer must take. */
|
|
1281
|
-
const SEED_TEMPLATES =
|
|
1282
|
-
[
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1455
|
+
const SEED_TEMPLATES = {
|
|
1456
|
+
zh: [
|
|
1457
|
+
[
|
|
1458
|
+
'seed:review',
|
|
1459
|
+
'代码审查',
|
|
1460
|
+
'审阅 {{贴 diff 或文件}}:先用一句话给结论(能否合入、卡在哪);再按「阻塞 / 建议 / 可选」分级列问题,每条给行号、触发条件、修法。不要重述代码在做什么。',
|
|
1461
|
+
],
|
|
1462
|
+
[
|
|
1463
|
+
'seed:options',
|
|
1464
|
+
'方案对比',
|
|
1465
|
+
'针对 {{决策点}} 给 2–3 个候选方案,用表格对比:改动范围、风险、回滚难度、后续维护成本;最后给推荐项和一句理由。',
|
|
1466
|
+
],
|
|
1467
|
+
[
|
|
1468
|
+
'seed:acceptance',
|
|
1469
|
+
'验收清单',
|
|
1470
|
+
'为 {{功能名}} 输出可勾选清单,按「正常路径 / 边界 / 失败恢复」分组;每条写成一个可观察的结果,能被执行或验证。',
|
|
1471
|
+
],
|
|
1472
|
+
[
|
|
1473
|
+
'seed:changelog',
|
|
1474
|
+
'变更说明',
|
|
1475
|
+
'按 Keep a Changelog 写 {{版本号}} 的变更说明:动词开头、一条一个变更、修复与新增不混在同一条;破坏性变更单独列一节。',
|
|
1476
|
+
],
|
|
1477
|
+
[
|
|
1478
|
+
'seed:explain',
|
|
1479
|
+
'解释这段代码',
|
|
1480
|
+
'解释 {{代码或模块}}:先用一句话说它解决什么问题,再说依赖的关键不变量、最容易踩的坑、以及改动时不能破坏的东西。',
|
|
1481
|
+
],
|
|
1296
1482
|
],
|
|
1297
|
-
[
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1483
|
+
en: [
|
|
1484
|
+
[
|
|
1485
|
+
'seed:review',
|
|
1486
|
+
'Code review',
|
|
1487
|
+
'Review {{paste a diff or file}}: open with a one-sentence verdict (mergeable, and where it is blocked), then list issues as Blocking / Suggestion / Optional, each with line number, trigger, and fix. Do not restate what the code does.',
|
|
1488
|
+
],
|
|
1489
|
+
[
|
|
1490
|
+
'seed:options',
|
|
1491
|
+
'Compare options',
|
|
1492
|
+
'For {{decision point}}, give 2–3 candidates in a table comparing change scope, risk, rollback difficulty, and maintenance cost. End with the recommended option and one reason.',
|
|
1493
|
+
],
|
|
1494
|
+
[
|
|
1495
|
+
'seed:acceptance',
|
|
1496
|
+
'Acceptance checklist',
|
|
1497
|
+
'For {{feature name}}, output a checkable list grouped by Happy path / Edge cases / Failure recovery; each line must be an observable result that can be executed or verified.',
|
|
1498
|
+
],
|
|
1499
|
+
[
|
|
1500
|
+
'seed:changelog',
|
|
1501
|
+
'Changelog entry',
|
|
1502
|
+
'Write the {{version}} entry in Keep a Changelog style: start each line with a verb, one change per line, and do not mix fixes with additions. Give breaking changes their own section.',
|
|
1503
|
+
],
|
|
1504
|
+
[
|
|
1505
|
+
'seed:explain',
|
|
1506
|
+
'Explain this code',
|
|
1507
|
+
'Explain {{code or module}}: one sentence on the problem it solves, then the key invariants it relies on, the most likely pitfalls, and what must not break when changing it.',
|
|
1508
|
+
],
|
|
1301
1509
|
],
|
|
1302
|
-
|
|
1303
|
-
'seed:explain',
|
|
1304
|
-
'解释这段代码',
|
|
1305
|
-
'解释 {{代码或模块}}:先用一句话说它解决什么问题,再说依赖的关键不变量、最容易踩的坑、以及改动时不能破坏的东西。',
|
|
1306
|
-
],
|
|
1307
|
-
];
|
|
1510
|
+
};
|
|
1308
1511
|
|
|
1309
1512
|
/** A build bumps this and adds one batch; older pools receive only the new batch. */
|
|
1310
1513
|
/** Bump when the stored item shape changes: older pools are reseeded, not migrated. */
|
|
1311
1514
|
const POOL_VERSION = 2;
|
|
1312
1515
|
|
|
1313
1516
|
const SEED_LEVEL = 2;
|
|
1517
|
+
const SEED_TOTAL = SEED_PROMPTS.en.length + SEED_TEMPLATES.en.length;
|
|
1518
|
+
|
|
1519
|
+
function seedItem([id, title, body], group, now, locale) {
|
|
1520
|
+
return { id, group, title, body, seed: true, locale, createdAt: now, updatedAt: now };
|
|
1521
|
+
}
|
|
1314
1522
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1523
|
+
/**
|
|
1524
|
+
* Every built-in id knows both language variants. The locale marker on a
|
|
1525
|
+
* saved item plus an exact title/body match is what proves it is still the
|
|
1526
|
+
* untouched built-in rather than a user edit.
|
|
1527
|
+
*/
|
|
1528
|
+
const SEED_CATALOG = new Map();
|
|
1529
|
+
function registerSeedBatch(entries, locale, level, group) {
|
|
1530
|
+
for (const [id, title, body] of entries) {
|
|
1531
|
+
const record = SEED_CATALOG.get(id) || { level, group, content: {} };
|
|
1532
|
+
record.content[locale] = { title, body };
|
|
1533
|
+
SEED_CATALOG.set(id, record);
|
|
1534
|
+
}
|
|
1317
1535
|
}
|
|
1536
|
+
registerSeedBatch(SEED_PROMPTS.zh, 'zh', 1, BUILTIN_GROUP.oftenuse);
|
|
1537
|
+
registerSeedBatch(SEED_PROMPTS.en, 'en', 1, BUILTIN_GROUP.oftenuse);
|
|
1538
|
+
registerSeedBatch(SEED_TEMPLATES.zh, 'zh', 2, BUILTIN_GROUP.template);
|
|
1539
|
+
registerSeedBatch(SEED_TEMPLATES.en, 'en', 2, BUILTIN_GROUP.template);
|
|
1318
1540
|
|
|
1319
|
-
function seedsAbove(level, now) {
|
|
1541
|
+
function seedsAbove(level, now, locale) {
|
|
1542
|
+
const language = locale === 'zh' ? 'zh' : 'en';
|
|
1320
1543
|
const batches = [
|
|
1321
|
-
{ level: 1, items: SEED_PROMPTS.map((entry) => seedItem(entry, BUILTIN_GROUP.oftenuse, now)) },
|
|
1322
|
-
{ level: 2, items: SEED_TEMPLATES.map((entry) => seedItem(entry, BUILTIN_GROUP.template, now)) },
|
|
1544
|
+
{ level: 1, items: SEED_PROMPTS[language].map((entry) => seedItem(entry, BUILTIN_GROUP.oftenuse, now, language)) },
|
|
1545
|
+
{ level: 2, items: SEED_TEMPLATES[language].map((entry) => seedItem(entry, BUILTIN_GROUP.template, now, language)) },
|
|
1323
1546
|
];
|
|
1324
1547
|
return batches.filter((batch) => batch.level > level).reduce((list, batch) => list.concat(batch.items), []);
|
|
1325
1548
|
}
|
|
1326
1549
|
|
|
1327
|
-
|
|
1550
|
+
/**
|
|
1551
|
+
* An untitled empty pool is not the same as a deliberate empty one: it waits
|
|
1552
|
+
* for apply() so the first-run seeds can follow the host locale.
|
|
1553
|
+
*/
|
|
1554
|
+
function pendingPool() {
|
|
1328
1555
|
return {
|
|
1329
1556
|
version: POOL_VERSION,
|
|
1330
1557
|
categories: [],
|
|
1331
|
-
items:
|
|
1558
|
+
items: [],
|
|
1332
1559
|
tray: [],
|
|
1333
1560
|
settings: normalizeSettings(undefined),
|
|
1334
|
-
seeded:
|
|
1561
|
+
seeded: 0,
|
|
1335
1562
|
};
|
|
1336
1563
|
}
|
|
1337
1564
|
|
|
1338
|
-
function seedItems(existing, level) {
|
|
1565
|
+
function seedItems(existing, level, locale) {
|
|
1339
1566
|
const taken = new Set(existing.map((item) => item.id));
|
|
1340
|
-
return seedsAbove(level, Date.now()).filter((item) => !taken.has(item.id));
|
|
1567
|
+
return seedsAbove(level, Date.now(), locale).filter((item) => !taken.has(item.id));
|
|
1341
1568
|
}
|
|
1342
1569
|
|
|
1343
1570
|
function loadPool() {
|
|
1344
1571
|
try {
|
|
1345
1572
|
const raw = localStorage.getItem(STORAGE_KEY);
|
|
1346
|
-
if (!raw)
|
|
1347
|
-
// Brand-new install only: an existing (even empty) pool is never reseeded.
|
|
1348
|
-
const seeded = seededPool();
|
|
1349
|
-
persist(seeded);
|
|
1350
|
-
return seeded;
|
|
1351
|
-
}
|
|
1573
|
+
if (!raw) return pendingPool();
|
|
1352
1574
|
const parsed = JSON.parse(raw);
|
|
1353
1575
|
const storedVersion = parsed && typeof parsed.version === 'number' ? parsed.version : 1;
|
|
1354
1576
|
if (storedVersion < POOL_VERSION) {
|
|
@@ -1360,12 +1582,8 @@ window.__ModuleLoader__.load({
|
|
|
1360
1582
|
/* the backup is best effort; the pool itself still loads */
|
|
1361
1583
|
}
|
|
1362
1584
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
if (storedVersion >= POOL_VERSION && level >= SEED_LEVEL) return pool;
|
|
1366
|
-
const migrated = level >= SEED_LEVEL ? pool : { ...pool, items: [...pool.items, ...seedItems(pool.items, level)], seeded: SEED_LEVEL };
|
|
1367
|
-
persist(migrated);
|
|
1368
|
-
return migrated;
|
|
1585
|
+
// Seed batches are added in apply(), where the host locale is known.
|
|
1586
|
+
return normalizePool(parsed);
|
|
1369
1587
|
} catch (_error) {
|
|
1370
1588
|
return emptyPool();
|
|
1371
1589
|
}
|
|
@@ -1487,6 +1705,14 @@ window.__ModuleLoader__.load({
|
|
|
1487
1705
|
queueCollapsed: settings.queueCollapsed === true,
|
|
1488
1706
|
// The group the right-click menu offered last, so it can lead the list.
|
|
1489
1707
|
lastCaptureGroup: typeof settings.lastCaptureGroup === 'string' ? settings.lastCaptureGroup : '',
|
|
1708
|
+
// Annotations: where their markers draw, not what they hold.
|
|
1709
|
+
notesHighlight: settings.notesHighlight !== false,
|
|
1710
|
+
// Which tab a freshly opened pool lands on: notes, this workspace, or a
|
|
1711
|
+
// concrete tab ("tab:<id>").
|
|
1712
|
+
defaultTab: typeof settings.defaultTab === 'string' ? settings.defaultTab : '',
|
|
1713
|
+
// Annotations survive the two actions unless the user opts out.
|
|
1714
|
+
noteKeepAfterDraft: settings.noteKeepAfterDraft !== false,
|
|
1715
|
+
noteKeepAfterStore: settings.noteKeepAfterStore !== false,
|
|
1490
1716
|
// Whether an item leaves the pool after it is used.
|
|
1491
1717
|
keepAfterInsert: settings.keepAfterInsert !== false,
|
|
1492
1718
|
keepAfterQueue: settings.keepAfterQueue !== false,
|
|
@@ -1634,6 +1860,76 @@ window.__ModuleLoader__.load({
|
|
|
1634
1860
|
}
|
|
1635
1861
|
}
|
|
1636
1862
|
|
|
1863
|
+
/**
|
|
1864
|
+
* Screenshot/test override: setting this key to 'en' or 'zh' makes the
|
|
1865
|
+
* plugin's own copy and its new seed batches use that language without
|
|
1866
|
+
* changing the host UI. Unset in normal use.
|
|
1867
|
+
*/
|
|
1868
|
+
const PREVIEW_LOCALE_KEY = 'dsh.prompt-pool.preview-locale';
|
|
1869
|
+
|
|
1870
|
+
function previewLocaleId() {
|
|
1871
|
+
try {
|
|
1872
|
+
const value = localStorage.getItem(PREVIEW_LOCALE_KEY);
|
|
1873
|
+
return value === 'zh' || value === 'en' ? value : null;
|
|
1874
|
+
} catch (_error) {
|
|
1875
|
+
return null;
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
/** The host locale at first run; unsupported locales fall back to English seeds. */
|
|
1880
|
+
function activeLocaleId() {
|
|
1881
|
+
const preview = previewLocaleId();
|
|
1882
|
+
if (preview) return preview;
|
|
1883
|
+
try {
|
|
1884
|
+
const snapshot =
|
|
1885
|
+
localeCtx && typeof localeCtx.getLocale === 'function'
|
|
1886
|
+
? localeCtx.getLocale()
|
|
1887
|
+
: localeCtx && typeof localeCtx.getSnapshot === 'function'
|
|
1888
|
+
? localeCtx.getSnapshot()
|
|
1889
|
+
: null;
|
|
1890
|
+
const active = snapshot && (snapshot.active || snapshot.id || snapshot.locale || snapshot.language);
|
|
1891
|
+
if (typeof active === 'string' && active) return active.toLowerCase().startsWith('zh') ? 'zh' : 'en';
|
|
1892
|
+
} catch (_error) {
|
|
1893
|
+
/* a locale service that cannot answer still gets the document fallback */
|
|
1894
|
+
}
|
|
1895
|
+
try {
|
|
1896
|
+
const htmlLang = typeof document !== 'undefined' && document.documentElement ? document.documentElement.lang : '';
|
|
1897
|
+
if (typeof htmlLang === 'string' && htmlLang) return htmlLang.toLowerCase().startsWith('zh') ? 'zh' : 'en';
|
|
1898
|
+
} catch (_error) {
|
|
1899
|
+
/* no document in a non-browser host */
|
|
1900
|
+
}
|
|
1901
|
+
return 'en';
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
/**
|
|
1905
|
+
* Add the missing seed batches now that apply() knows the host locale. A
|
|
1906
|
+
* brand-new pool is seeded only here; an existing pool keeps every saved
|
|
1907
|
+
* item, and its ids prevent a batch from being duplicated.
|
|
1908
|
+
*/
|
|
1909
|
+
function seedPoolIfNeeded() {
|
|
1910
|
+
const current = pool.get();
|
|
1911
|
+
const level = current.seeded === true ? SEED_LEVEL : Number(current.seeded) || 0;
|
|
1912
|
+
if (level >= SEED_LEVEL) return;
|
|
1913
|
+
const missing = seedItems(current.items, level, activeLocaleId());
|
|
1914
|
+
const next = { ...current, items: [...current.items, ...missing], seeded: SEED_LEVEL };
|
|
1915
|
+
persist(next);
|
|
1916
|
+
pool.set(next);
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
/** Which language variant this item still exactly matches, or null once edited. */
|
|
1920
|
+
function seedContentLocale(item, record) {
|
|
1921
|
+
for (const locale of ['zh', 'en']) {
|
|
1922
|
+
const content = record.content[locale];
|
|
1923
|
+
if (content && item.title === content.title && item.body === content.body) return locale;
|
|
1924
|
+
}
|
|
1925
|
+
return null;
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
/** An extra image also counts as an edit, because a reset would lose it. */
|
|
1929
|
+
function seedIsEdited(item, record) {
|
|
1930
|
+
return seedContentLocale(item, record) === null || (Array.isArray(item.images) && item.images.length > 0);
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1637
1933
|
function mutate(fn) {
|
|
1638
1934
|
const prev = pool.get();
|
|
1639
1935
|
const next = fn(prev);
|
|
@@ -1647,6 +1943,40 @@ window.__ModuleLoader__.load({
|
|
|
1647
1943
|
mutate((state) => ({ ...state, items: [...state.items, item] }));
|
|
1648
1944
|
return item;
|
|
1649
1945
|
},
|
|
1946
|
+
/**
|
|
1947
|
+
* Replace every built-in item with a fresh set in `target`. A kept edit
|
|
1948
|
+
* becomes an ordinary item with a new id, so the incoming set can use the
|
|
1949
|
+
* canonical ids without a duplicate. Custom items and the tray are untouched.
|
|
1950
|
+
*/
|
|
1951
|
+
resetBuiltins(target, keepEdited) {
|
|
1952
|
+
const language = target === 'zh' ? 'zh' : 'en';
|
|
1953
|
+
const current = pool.get();
|
|
1954
|
+
const now = Date.now();
|
|
1955
|
+
const items = [];
|
|
1956
|
+
let removed = 0;
|
|
1957
|
+
let kept = 0;
|
|
1958
|
+
for (const item of current.items) {
|
|
1959
|
+
const record = SEED_CATALOG.get(item.id);
|
|
1960
|
+
if (!record) {
|
|
1961
|
+
items.push(item);
|
|
1962
|
+
continue;
|
|
1963
|
+
}
|
|
1964
|
+
if (keepEdited && seedIsEdited(item, record)) {
|
|
1965
|
+
const preserved = { ...item, id: uid() };
|
|
1966
|
+
delete preserved.seed;
|
|
1967
|
+
delete preserved.locale;
|
|
1968
|
+
items.push(preserved);
|
|
1969
|
+
kept += 1;
|
|
1970
|
+
} else {
|
|
1971
|
+
removed += 1;
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
const fresh = seedsAbove(0, now, language);
|
|
1975
|
+
const next = { ...current, items: [...items, ...fresh], seeded: SEED_LEVEL };
|
|
1976
|
+
persist(next);
|
|
1977
|
+
pool.set(next);
|
|
1978
|
+
return { removed, kept, added: fresh.length, language };
|
|
1979
|
+
},
|
|
1650
1980
|
/** Copy one pool item (current text) and append the copy last. */
|
|
1651
1981
|
duplicateItem(id) {
|
|
1652
1982
|
mutate((state) => {
|
|
@@ -2161,7 +2491,15 @@ window.__ModuleLoader__.load({
|
|
|
2161
2491
|
h('path', { d: 'M4.3 7.6H2.6A1.2 1.2 0 0 1 1.4 6.4V2.6A1.2 1.2 0 0 1 2.6 1.4h3.8a1.2 1.2 0 0 1 1.2 1.2v1.7' }),
|
|
2162
2492
|
);
|
|
2163
2493
|
case 'insert':
|
|
2164
|
-
|
|
2494
|
+
// The same glyph as an annotation's "generate draft" action: an arrow
|
|
2495
|
+
// dropping into the composer box.
|
|
2496
|
+
return h(
|
|
2497
|
+
'svg',
|
|
2498
|
+
{ width: 15, height: 15, viewBox: '0 0 20 20', fill: 'none', stroke: 'currentColor', strokeWidth: 1.6, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true },
|
|
2499
|
+
h('path', { d: 'M3.6 12.4h12.8v3.4H3.6z' }),
|
|
2500
|
+
h('path', { d: 'M10 3v6.4' }),
|
|
2501
|
+
h('path', { d: 'M7.4 6.9 10 9.4l2.6-2.5' }),
|
|
2502
|
+
);
|
|
2165
2503
|
case 'close':
|
|
2166
2504
|
return h('svg', base, h('path', { d: 'M3 3l6 6M9 3l-6 6' }));
|
|
2167
2505
|
case 'chevronDown':
|
|
@@ -2572,6 +2910,7 @@ window.__ModuleLoader__.load({
|
|
|
2572
2910
|
type: 'button',
|
|
2573
2911
|
className: 'pp-tab',
|
|
2574
2912
|
'data-active': active ? 'true' : 'false',
|
|
2913
|
+
'data-group': tab.group,
|
|
2575
2914
|
title: tab.category ? translate('tab.renameHint') : undefined,
|
|
2576
2915
|
onClick: () => props.onSelect(tab.id),
|
|
2577
2916
|
onDoubleClick: tab.category ? () => setRenaming({ id: tab.id, name: tab.label, original: tab.label }) : undefined,
|
|
@@ -2679,6 +3018,7 @@ window.__ModuleLoader__.load({
|
|
|
2679
3018
|
const state = usePoolState();
|
|
2680
3019
|
const storage = useStorageState();
|
|
2681
3020
|
const releaseInfo = useReleaseState();
|
|
3021
|
+
const noteBar = useNoteStatus();
|
|
2682
3022
|
const queueCollapsed = state.settings && state.settings.queueCollapsed === true;
|
|
2683
3023
|
const workspaces = useWorkspaceDir();
|
|
2684
3024
|
const sessionHint = useSessionDir().sessionId;
|
|
@@ -2697,14 +3037,32 @@ window.__ModuleLoader__.load({
|
|
|
2697
3037
|
return pool.length > 0 ? pool[pool.length - 1] : '';
|
|
2698
3038
|
})();
|
|
2699
3039
|
const activeSessionId = pageSessionId || sessionHint || workspaceSession || '';
|
|
2700
|
-
const
|
|
3040
|
+
const notesState = useNotesState();
|
|
3041
|
+
const notesList = notesState.items
|
|
3042
|
+
.filter((note) => note.sessionId === activeSessionId)
|
|
3043
|
+
.sort((left, right) => (left.order - right.order) || (left.createdAt - right.createdAt));
|
|
3044
|
+
const baseTabs = buildTabs(state.categories, workspaceList, state.settings, currentWorkspaceId);
|
|
3045
|
+
// The annotation tab is always present, so the feature stays discoverable.
|
|
3046
|
+
const tabs = [{ id: 'notes', label: translate('note.title'), group: 'notes' }, ...baseTabs];
|
|
2701
3047
|
const captureGroups = captureChoices(state.categories, workspaceList, currentWorkspaceId, state.settings);
|
|
2702
|
-
const tabCounts =
|
|
3048
|
+
const tabCounts = {
|
|
3049
|
+
...tabCountsOf(state.items),
|
|
3050
|
+
notes: notesList.length,
|
|
3051
|
+
};
|
|
2703
3052
|
const [tab, setPageTab] = useState(() => pageTabState.get().id || 'all');
|
|
2704
3053
|
const setTab = (id) => {
|
|
2705
3054
|
pageTabState.set({ id });
|
|
2706
3055
|
setPageTab(id);
|
|
2707
3056
|
};
|
|
3057
|
+
// The page opens on the tab chosen in Settings (once per mount).
|
|
3058
|
+
const defaultAppliedRef = useRef(false);
|
|
3059
|
+
useEffect(() => {
|
|
3060
|
+
if (defaultAppliedRef.current) return;
|
|
3061
|
+
defaultAppliedRef.current = true;
|
|
3062
|
+
const pref = normalizeSettings(state.settings).defaultTab;
|
|
3063
|
+
const resolved = resolveDefaultTab(pref, tabs, currentWorkspaceId, notesList.length > 0);
|
|
3064
|
+
if (resolved) setTab(resolved);
|
|
3065
|
+
}, []);
|
|
2708
3066
|
const [query, setQuery] = useState('');
|
|
2709
3067
|
const [settingsOpen, setSettingsOpen] = useState(false);
|
|
2710
3068
|
const [pendingCategory, setPendingCategory] = useState(null);
|
|
@@ -2870,6 +3228,75 @@ window.__ModuleLoader__.load({
|
|
|
2870
3228
|
);
|
|
2871
3229
|
};
|
|
2872
3230
|
|
|
3231
|
+
/** The page has no composer, so the mounted panel inserts the reply. */
|
|
3232
|
+
const composeSessionNotes = () => {
|
|
3233
|
+
let result;
|
|
3234
|
+
try {
|
|
3235
|
+
result = bridge.request({ type: 'compose-notes' });
|
|
3236
|
+
} catch (_error) {
|
|
3237
|
+
return false;
|
|
3238
|
+
}
|
|
3239
|
+
const ok = Boolean(result && result.ok);
|
|
3240
|
+
if (ok && normalizeSettings(state.settings).noteKeepAfterDraft === false) {
|
|
3241
|
+
notesActions.clearSession(activeSessionId);
|
|
3242
|
+
}
|
|
3243
|
+
return ok;
|
|
3244
|
+
};
|
|
3245
|
+
|
|
3246
|
+
/** The page cannot write the composer, so the mounted panel inserts the note. */
|
|
3247
|
+
const insertNote = (note) => {
|
|
3248
|
+
let result;
|
|
3249
|
+
try {
|
|
3250
|
+
result = bridge.request({ type: 'insert-text', text: composeNoteLine(note) });
|
|
3251
|
+
} catch (_error) {
|
|
3252
|
+
return false;
|
|
3253
|
+
}
|
|
3254
|
+
return Boolean(result && result.ok);
|
|
3255
|
+
};
|
|
3256
|
+
|
|
3257
|
+
/** Store the session's annotations as one prompt, from the page header. */
|
|
3258
|
+
const storeNotesPrompt = (event) => {
|
|
3259
|
+
const choices = captureChoices(state.categories, workspaceList, currentWorkspaceId, state.settings);
|
|
3260
|
+
const preferred = currentWorkspaceId && choices.some((entry) => entry.value === 'workspace:' + currentWorkspaceId)
|
|
3261
|
+
? 'workspace:' + currentWorkspaceId
|
|
3262
|
+
: BUILTIN_GROUP.oftenuse;
|
|
3263
|
+
const ordered = choices.some((entry) => entry.value === preferred)
|
|
3264
|
+
? [...choices.filter((entry) => entry.value === preferred), ...choices.filter((entry) => entry.value !== preferred)]
|
|
3265
|
+
: choices;
|
|
3266
|
+
const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
|
|
3267
|
+
? event.currentTarget.getBoundingClientRect()
|
|
3268
|
+
: null;
|
|
3269
|
+
notePrompt.set({
|
|
3270
|
+
open: true,
|
|
3271
|
+
target: { kind: 'reply' },
|
|
3272
|
+
choices: ordered,
|
|
3273
|
+
defaultValue: preferred,
|
|
3274
|
+
anchor: rect
|
|
3275
|
+
? { left: Math.round(rect.left), right: Math.round(rect.right), top: Math.round(rect.top), bottom: Math.round(rect.bottom) }
|
|
3276
|
+
: { left: 120, right: 160, top: 60, bottom: 90 },
|
|
3277
|
+
token: Date.now(),
|
|
3278
|
+
onPick: (group) => {
|
|
3279
|
+
closeNotePrompt();
|
|
3280
|
+
if (!group) return;
|
|
3281
|
+
const text = composeNotesReply(notesList);
|
|
3282
|
+
poolActions.add({
|
|
3283
|
+
id: uid(),
|
|
3284
|
+
group,
|
|
3285
|
+
title: draftTitle(text),
|
|
3286
|
+
body: text,
|
|
3287
|
+
images: [],
|
|
3288
|
+
createdAt: Date.now(),
|
|
3289
|
+
updatedAt: Date.now(),
|
|
3290
|
+
});
|
|
3291
|
+
if (normalizeSettings(state.settings).noteKeepAfterStore === false) {
|
|
3292
|
+
notesActions.clearSession(activeSessionId);
|
|
3293
|
+
}
|
|
3294
|
+
const resolved = resolveGroup(group, state.categories, workspaceList);
|
|
3295
|
+
showToast(translate('note.composeStored', { group: resolved ? resolved.label : translate('row.noCategory') }), 'ok');
|
|
3296
|
+
},
|
|
3297
|
+
});
|
|
3298
|
+
};
|
|
3299
|
+
|
|
2873
3300
|
/** The page cannot read the composer, so the mounted panel performs it. */
|
|
2874
3301
|
const captureDraft = (group) => {
|
|
2875
3302
|
let result;
|
|
@@ -3025,18 +3452,23 @@ window.__ModuleLoader__.load({
|
|
|
3025
3452
|
h(
|
|
3026
3453
|
'div',
|
|
3027
3454
|
{ className: 'pp-page-head' },
|
|
3028
|
-
h('span', { className: 'pp-page-title' }, translate('page.title')),
|
|
3029
|
-
h('span', { className: 'pp-page-sub' }, translate('page.count', { n: state.items.length })),
|
|
3030
|
-
h('span', { className: 'pp-grow' }),
|
|
3031
3455
|
h('input', {
|
|
3456
|
+
key: 'search',
|
|
3032
3457
|
className: 'pp-search',
|
|
3033
3458
|
value: query,
|
|
3034
3459
|
placeholder: translate('page.search'),
|
|
3035
3460
|
'aria-label': translate('page.search'),
|
|
3036
3461
|
onChange: (event) => setQuery(event.target.value),
|
|
3037
3462
|
}),
|
|
3038
|
-
|
|
3039
|
-
|
|
3463
|
+
tab === 'notes'
|
|
3464
|
+
? [
|
|
3465
|
+
h('button', { key: 'store', type: 'button', className: 'pp-mini', title: translate('note.composeStoreHint'), onClick: storeNotesPrompt }, translate('note.composeStore')),
|
|
3466
|
+
h('button', { key: 'draft', type: 'button', className: 'pp-mini', title: translate('note.composeHint'), onClick: composeSessionNotes }, translate('note.compose')),
|
|
3467
|
+
]
|
|
3468
|
+
: [
|
|
3469
|
+
h('button', { key: 'new', type: 'button', className: 'pp-mini', onClick: create }, '+ ', translate('page.new')),
|
|
3470
|
+
h('button', { key: 'capture', type: 'button', className: 'pp-mini', title: translate('panel.captureHint'), onClick: openCapture }, translate('panel.capture')),
|
|
3471
|
+
],
|
|
3040
3472
|
h(SettingsButton, { active: settingsOpen, onClick: () => setSettingsOpen(!settingsOpen) }),
|
|
3041
3473
|
),
|
|
3042
3474
|
h(
|
|
@@ -3107,7 +3539,20 @@ window.__ModuleLoader__.load({
|
|
|
3107
3539
|
{ className: 'pp-page-body', ref: pageListRef },
|
|
3108
3540
|
settingsOpen
|
|
3109
3541
|
? h(PromptPoolSettings, { currentWorkspaceId })
|
|
3110
|
-
:
|
|
3542
|
+
: tab === 'notes'
|
|
3543
|
+
? h(NotesView, {
|
|
3544
|
+
notes: notesList,
|
|
3545
|
+
sessionId: activeSessionId,
|
|
3546
|
+
onCompose: composeSessionNotes,
|
|
3547
|
+
onInsertNote: insertNote,
|
|
3548
|
+
hideActions: true,
|
|
3549
|
+
filter: query,
|
|
3550
|
+
categories: state.categories,
|
|
3551
|
+
workspaces: workspaceList,
|
|
3552
|
+
currentWorkspaceId,
|
|
3553
|
+
settings: state.settings,
|
|
3554
|
+
})
|
|
3555
|
+
: nestedView
|
|
3111
3556
|
? renderWorkspacePanes({
|
|
3112
3557
|
rail: nestedView.rail,
|
|
3113
3558
|
items: nestedView.scoped,
|
|
@@ -3136,6 +3581,9 @@ window.__ModuleLoader__.load({
|
|
|
3136
3581
|
h(
|
|
3137
3582
|
'div',
|
|
3138
3583
|
{ className: 'pp-queue-dock' },
|
|
3584
|
+
tab === 'notes' && noteBar.text
|
|
3585
|
+
? h('div', { className: 'pp-notes-bar', 'data-kind': noteBar.kind, role: 'status' }, noteBar.text)
|
|
3586
|
+
: null,
|
|
3139
3587
|
notice
|
|
3140
3588
|
? h(
|
|
3141
3589
|
'div',
|
|
@@ -3156,7 +3604,7 @@ window.__ModuleLoader__.load({
|
|
|
3156
3604
|
: null,
|
|
3157
3605
|
)
|
|
3158
3606
|
: null,
|
|
3159
|
-
settingsOpen
|
|
3607
|
+
settingsOpen || tab === 'notes'
|
|
3160
3608
|
? null
|
|
3161
3609
|
: renderTrayCard({
|
|
3162
3610
|
entries: state.tray,
|
|
@@ -3213,6 +3661,30 @@ window.__ModuleLoader__.load({
|
|
|
3213
3661
|
poolActions.setSetting('hiddenWorkspaces', next);
|
|
3214
3662
|
};
|
|
3215
3663
|
const [section, setSection] = useState('order');
|
|
3664
|
+
const tabOptions = buildTabs(state.categories, wsItems, settings, wsCurrentId);
|
|
3665
|
+
const defaultTab = settings.defaultTab || '';
|
|
3666
|
+
const defaultTabMode = defaultTab === 'notes'
|
|
3667
|
+
? 'notes'
|
|
3668
|
+
: defaultTab === '__workspace__'
|
|
3669
|
+
? 'workspace'
|
|
3670
|
+
: defaultTab.indexOf('tab:') === 0
|
|
3671
|
+
? 'custom'
|
|
3672
|
+
: '';
|
|
3673
|
+
const [seedKeepEdited, setSeedKeepEdited] = useState(true);
|
|
3674
|
+
const [seedConfirm, setSeedConfirm] = useState(false);
|
|
3675
|
+
const [seedStatus, setSeedStatus] = useState('');
|
|
3676
|
+
const seedItems = state.items.filter((item) => SEED_CATALOG.has(item.id));
|
|
3677
|
+
const editedSeeds = seedItems.filter((item) => seedIsEdited(item, SEED_CATALOG.get(item.id)));
|
|
3678
|
+
const seedLanguageLabel = translate(
|
|
3679
|
+
activeLocaleId() === 'zh' ? 'settings.seedLanguageZh' : 'settings.seedLanguageEn',
|
|
3680
|
+
);
|
|
3681
|
+
const seedRemoveCount = seedItems.length - (seedKeepEdited ? editedSeeds.length : 0);
|
|
3682
|
+
const seedKeptCount = seedKeepEdited ? editedSeeds.length : 0;
|
|
3683
|
+
const resetSeeds = () => {
|
|
3684
|
+
const result = poolActions.resetBuiltins(activeLocaleId(), seedKeepEdited);
|
|
3685
|
+
setSeedConfirm(false);
|
|
3686
|
+
setSeedStatus(translate('settings.seedResetDone', result));
|
|
3687
|
+
};
|
|
3216
3688
|
const moveOrder = (index, delta) => {
|
|
3217
3689
|
const order = settings.order.slice();
|
|
3218
3690
|
const to = index + delta;
|
|
@@ -3235,7 +3707,7 @@ window.__ModuleLoader__.load({
|
|
|
3235
3707
|
}),
|
|
3236
3708
|
h('span', null, translate(label)),
|
|
3237
3709
|
),
|
|
3238
|
-
h('div', { className: 'pp-hint pp-set-hint' }, translate(hint)),
|
|
3710
|
+
hint ? h('div', { className: 'pp-hint pp-set-hint' }, translate(hint)) : null,
|
|
3239
3711
|
);
|
|
3240
3712
|
return h(
|
|
3241
3713
|
'div',
|
|
@@ -3276,6 +3748,25 @@ window.__ModuleLoader__.load({
|
|
|
3276
3748
|
},
|
|
3277
3749
|
translate('settings.tab.prompts'),
|
|
3278
3750
|
),
|
|
3751
|
+
h(
|
|
3752
|
+
'button',
|
|
3753
|
+
{
|
|
3754
|
+
type: 'button',
|
|
3755
|
+
className: 'pp-tab',
|
|
3756
|
+
'data-active': section === 'notes' ? 'true' : 'false',
|
|
3757
|
+
onClick: () => setSection('notes'),
|
|
3758
|
+
},
|
|
3759
|
+
translate('settings.tab.notes'),
|
|
3760
|
+
),
|
|
3761
|
+
),
|
|
3762
|
+
h(
|
|
3763
|
+
'div',
|
|
3764
|
+
{ className: 'pp-set-group pp-set-card', style: { display: section === 'notes' ? '' : 'none' } },
|
|
3765
|
+
h('div', { className: 'pp-hint pp-set-intro' }, translate('settings.notesIntro')),
|
|
3766
|
+
h('div', { className: 'pp-set-divider' }),
|
|
3767
|
+
check('noteKeepAfterDraft', 'settings.notesKeepDraft', 'settings.notesKeepDraftHint'),
|
|
3768
|
+
h('div', { className: 'pp-set-divider' }),
|
|
3769
|
+
check('noteKeepAfterStore', 'settings.notesKeepStore', 'settings.notesKeepStoreHint'),
|
|
3279
3770
|
),
|
|
3280
3771
|
h(
|
|
3281
3772
|
'div',
|
|
@@ -3285,6 +3776,48 @@ window.__ModuleLoader__.load({
|
|
|
3285
3776
|
h('div', { className: 'pp-set-divider' }),
|
|
3286
3777
|
check('keepAfterQueue', 'settings.keepQueue', 'settings.keepQueueHint'),
|
|
3287
3778
|
),
|
|
3779
|
+
h(
|
|
3780
|
+
'div',
|
|
3781
|
+
{ className: 'pp-set-group pp-set-card', style: { display: section === 'prompts' ? '' : 'none' } },
|
|
3782
|
+
h('div', { className: 'pp-set-label' }, translate('settings.seedCard')),
|
|
3783
|
+
h(
|
|
3784
|
+
'div',
|
|
3785
|
+
{ className: 'pp-hint' },
|
|
3786
|
+
translate('settings.seedHint', { builtin: seedItems.length, edited: editedSeeds.length }),
|
|
3787
|
+
),
|
|
3788
|
+
h(
|
|
3789
|
+
'label',
|
|
3790
|
+
{ className: 'pp-set-row' },
|
|
3791
|
+
h('input', {
|
|
3792
|
+
type: 'checkbox',
|
|
3793
|
+
name: 'seedKeepEdited',
|
|
3794
|
+
checked: seedKeepEdited,
|
|
3795
|
+
onChange: () => setSeedKeepEdited((value) => !value),
|
|
3796
|
+
}),
|
|
3797
|
+
h('span', null, translate('settings.seedKeepEdited')),
|
|
3798
|
+
),
|
|
3799
|
+
h('div', { className: 'pp-hint pp-set-hint' }, translate('settings.seedKeepEditedHint')),
|
|
3800
|
+
h(
|
|
3801
|
+
'div',
|
|
3802
|
+
{ className: 'pp-set-actions' },
|
|
3803
|
+
h(
|
|
3804
|
+
'span',
|
|
3805
|
+
{ className: 'pp-hint pp-set-note' },
|
|
3806
|
+
translate('settings.seedNote', { language: seedLanguageLabel }),
|
|
3807
|
+
),
|
|
3808
|
+
h(
|
|
3809
|
+
'button',
|
|
3810
|
+
{
|
|
3811
|
+
type: 'button',
|
|
3812
|
+
className: 'pp-mini',
|
|
3813
|
+
'data-pp': 'seed-reset',
|
|
3814
|
+
onClick: () => setSeedConfirm(true),
|
|
3815
|
+
},
|
|
3816
|
+
translate('settings.seedResetButton'),
|
|
3817
|
+
),
|
|
3818
|
+
),
|
|
3819
|
+
seedStatus ? h('div', { className: 'pp-hint' }, seedStatus) : null,
|
|
3820
|
+
),
|
|
3288
3821
|
h(
|
|
3289
3822
|
'div',
|
|
3290
3823
|
{ className: 'pp-set-group pp-set-card', style: { display: section === 'workspace' ? '' : 'none' } },
|
|
@@ -3312,6 +3845,59 @@ window.__ModuleLoader__.load({
|
|
|
3312
3845
|
),
|
|
3313
3846
|
),
|
|
3314
3847
|
),
|
|
3848
|
+
h(
|
|
3849
|
+
'div',
|
|
3850
|
+
{ className: 'pp-set-group pp-set-card', style: { display: section === 'order' ? '' : 'none' } },
|
|
3851
|
+
h('div', { className: 'pp-set-label' }, translate('settings.defaultTab')),
|
|
3852
|
+
h(
|
|
3853
|
+
'div',
|
|
3854
|
+
{ className: 'pp-set-radios' },
|
|
3855
|
+
[
|
|
3856
|
+
{ mode: 'notes', key: 'settings.defaultTabNotes', value: 'notes' },
|
|
3857
|
+
{ mode: 'workspace', key: 'settings.defaultTabWorkspace', value: '__workspace__' },
|
|
3858
|
+
{ mode: 'custom', key: 'settings.defaultTabOther', value: '' },
|
|
3859
|
+
].map((entry) => h(
|
|
3860
|
+
'div',
|
|
3861
|
+
{ key: entry.mode, className: 'pp-set-radio-row' },
|
|
3862
|
+
h(
|
|
3863
|
+
'label',
|
|
3864
|
+
{ className: 'pp-set-radio' },
|
|
3865
|
+
h('input', {
|
|
3866
|
+
type: 'radio',
|
|
3867
|
+
name: 'pp-default-tab',
|
|
3868
|
+
checked: defaultTabMode === entry.mode,
|
|
3869
|
+
onChange: () => {
|
|
3870
|
+
if (entry.mode === 'custom') {
|
|
3871
|
+
const previous = defaultTab.indexOf('tab:') === 0 ? defaultTab : '';
|
|
3872
|
+
const first = tabOptions[0];
|
|
3873
|
+
poolActions.setSetting('defaultTab', previous || (first ? 'tab:' + first.id : ''));
|
|
3874
|
+
return;
|
|
3875
|
+
}
|
|
3876
|
+
poolActions.setSetting('defaultTab', entry.value);
|
|
3877
|
+
},
|
|
3878
|
+
}),
|
|
3879
|
+
h('span', null, translate(entry.key)),
|
|
3880
|
+
),
|
|
3881
|
+
entry.mode === 'custom'
|
|
3882
|
+
? h(
|
|
3883
|
+
'select',
|
|
3884
|
+
{
|
|
3885
|
+
className: 'pp-select',
|
|
3886
|
+
// Always visible next to "other"; picking a tab here also
|
|
3887
|
+
// switches the choice to it.
|
|
3888
|
+
value: defaultTabMode === 'custom' ? defaultTab.slice(4) : (tabOptions[0] ? tabOptions[0].id : ''),
|
|
3889
|
+
onChange: (event) => poolActions.setSetting('defaultTab', 'tab:' + event.target.value),
|
|
3890
|
+
},
|
|
3891
|
+
tabOptions.map((tab) => h(
|
|
3892
|
+
'option',
|
|
3893
|
+
{ key: tab.id, value: tab.id },
|
|
3894
|
+
tab.label,
|
|
3895
|
+
)),
|
|
3896
|
+
)
|
|
3897
|
+
: null,
|
|
3898
|
+
)),
|
|
3899
|
+
),
|
|
3900
|
+
),
|
|
3315
3901
|
h(
|
|
3316
3902
|
'div',
|
|
3317
3903
|
{ className: 'pp-set-group pp-set-card', style: { display: section === 'order' ? '' : 'none' } },
|
|
@@ -3399,6 +3985,16 @@ window.__ModuleLoader__.load({
|
|
|
3399
3985
|
)
|
|
3400
3986
|
: null,
|
|
3401
3987
|
),
|
|
3988
|
+
seedConfirm
|
|
3989
|
+
? h(SeedResetConfirm, {
|
|
3990
|
+
removed: seedRemoveCount,
|
|
3991
|
+
kept: seedKeptCount,
|
|
3992
|
+
added: SEED_TOTAL,
|
|
3993
|
+
language: seedLanguageLabel,
|
|
3994
|
+
onCancel: () => setSeedConfirm(false),
|
|
3995
|
+
onConfirm: resetSeeds,
|
|
3996
|
+
})
|
|
3997
|
+
: null,
|
|
3402
3998
|
);
|
|
3403
3999
|
}
|
|
3404
4000
|
|
|
@@ -3716,100 +4312,1591 @@ window.__ModuleLoader__.load({
|
|
|
3716
4312
|
);
|
|
3717
4313
|
}
|
|
3718
4314
|
|
|
3719
|
-
//
|
|
4315
|
+
// ------------------------------------------------------------------ notes
|
|
3720
4316
|
/**
|
|
3721
|
-
*
|
|
3722
|
-
*
|
|
3723
|
-
*
|
|
3724
|
-
* groups on show. Picking a group stores the selection there, and the group
|
|
3725
|
-
* used last time leads that submenu. The surface only exists while the Chat
|
|
3726
|
-
* view is mounted, and a selection lost between the gesture and this mount
|
|
3727
|
-
* leaves it with nothing to offer.
|
|
4317
|
+
* Annotations on a rendered assistant reply. They are stored by value (the
|
|
4318
|
+
* quoted text plus its surroundings) instead of by DOM node, so a re-render,
|
|
4319
|
+
* a fold or a paging remount costs the pin only until the text is back.
|
|
3728
4320
|
*/
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
}
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
if (!body) dismiss();
|
|
3754
|
-
}, [body, dismiss]);
|
|
4321
|
+
const NOTES_KEY = 'dsh.prompt-pool.notes.v1';
|
|
4322
|
+
const NOTES_SINGLETON = '__dshPromptPoolNotesV1';
|
|
4323
|
+
/** One Highlight object carries every annotated range. */
|
|
4324
|
+
const NOTE_HIGHLIGHT = 'prompt-pool-note';
|
|
4325
|
+
/** The always-open note card: fixed width so the gutter test is exact. */
|
|
4326
|
+
/** Narrower columns fall back to numbered pins instead of cards. */
|
|
4327
|
+
/** Tallest a card can get, for the occlusion test against a floating panel. */
|
|
4328
|
+
|
|
4329
|
+
/** Bumped when badge placement changes, so old chips are rebuilt in place. */
|
|
4330
|
+
const NOTE_CHIP_VERSION = '3';
|
|
4331
|
+
|
|
4332
|
+
/** Annotation kinds: the glyph, tint and label drive the badge and highlight. */
|
|
4333
|
+
const NOTE_KINDS = [
|
|
4334
|
+
{ id: 'comment', icon: '✎', tint: '255,191,36', label: 'note.kind.comment' },
|
|
4335
|
+
{ id: 'question', icon: '?', tint: '244,114,114', label: 'note.kind.question' },
|
|
4336
|
+
{ id: 'agree', icon: '✓', tint: '74,222,128', label: 'note.kind.agree' },
|
|
4337
|
+
{ id: 'disagree', icon: '✕', tint: '239,68,68', label: 'note.kind.disagree' },
|
|
4338
|
+
{ id: 'idea', icon: '💡', tint: '96,165,250', label: 'note.kind.idea' },
|
|
4339
|
+
{ id: 'todo', icon: '□', tint: '251,191,36', label: 'note.kind.todo' },
|
|
4340
|
+
];
|
|
4341
|
+
const NOTE_KIND_IDS = NOTE_KINDS.map((kind) => kind.id);
|
|
4342
|
+
const NOTE_KIND_DEFAULT = 'comment';
|
|
4343
|
+
/** Inline annotations are a short badge: ten characters at most. */
|
|
4344
|
+
const NOTE_BODY_MAX = 10;
|
|
3755
4345
|
|
|
3756
|
-
|
|
4346
|
+
function noteKind(kind) {
|
|
4347
|
+
return NOTE_KINDS.find((entry) => entry.id === kind) || NOTE_KINDS[0];
|
|
4348
|
+
}
|
|
3757
4349
|
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
const
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
for (const item of state.items) {
|
|
3764
|
-
const group = groupOf(item);
|
|
3765
|
-
counts[group] = (counts[group] || 0) + 1;
|
|
3766
|
-
}
|
|
4350
|
+
/** The visible badge text, whitespace-collapsed and capped. */
|
|
4351
|
+
function noteBodyText(body) {
|
|
4352
|
+
const text = String(body || '').replace(/\s+/g, ' ').trim();
|
|
4353
|
+
return text.length > NOTE_BODY_MAX ? text.slice(0, NOTE_BODY_MAX) + '…' : text;
|
|
4354
|
+
}
|
|
3767
4355
|
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
//
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
4356
|
+
/** Keep only fields the annotation UI reads; anything else is dropped. */
|
|
4357
|
+
function normalizeNote(raw) {
|
|
4358
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
4359
|
+
const quote = typeof raw.quote === 'string' ? raw.quote : '';
|
|
4360
|
+
if (!quote.trim()) return null;
|
|
4361
|
+
return {
|
|
4362
|
+
id: typeof raw.id === 'string' && raw.id ? raw.id : uid(),
|
|
4363
|
+
sessionId: typeof raw.sessionId === 'string' ? raw.sessionId : '',
|
|
4364
|
+
nodeKey: typeof raw.nodeKey === 'string' ? raw.nodeKey : '',
|
|
4365
|
+
quote,
|
|
4366
|
+
prefix: typeof raw.prefix === 'string' ? raw.prefix : '',
|
|
4367
|
+
suffix: typeof raw.suffix === 'string' ? raw.suffix : '',
|
|
4368
|
+
offset: Number.isFinite(Number(raw.offset)) ? Number(raw.offset) : 0,
|
|
4369
|
+
order: Number.isFinite(Number(raw.order)) ? Number(raw.order) : 0,
|
|
4370
|
+
kind: NOTE_KIND_IDS.indexOf(raw.kind) >= 0 ? raw.kind : NOTE_KIND_DEFAULT,
|
|
4371
|
+
// Where the user dragged this note's card, relative to its passage.
|
|
4372
|
+
dx: Number.isFinite(Number(raw.dx)) ? Number(raw.dx) : 0,
|
|
4373
|
+
dy: Number.isFinite(Number(raw.dy)) ? Number(raw.dy) : 0,
|
|
4374
|
+
// Set once the note was promoted into a pool group; the row keeps it
|
|
4375
|
+
// visible with a "stored" marker instead of deleting the record.
|
|
4376
|
+
promotedGroup: typeof raw.promotedGroup === 'string' ? raw.promotedGroup : '',
|
|
4377
|
+
promotedAt: Number.isFinite(Number(raw.promotedAt)) ? Number(raw.promotedAt) : 0,
|
|
4378
|
+
body: typeof raw.body === 'string' ? raw.body : '',
|
|
4379
|
+
createdAt: Number.isFinite(Number(raw.createdAt)) ? Number(raw.createdAt) : Date.now(),
|
|
4380
|
+
updatedAt: Number.isFinite(Number(raw.updatedAt)) ? Number(raw.updatedAt) : Date.now(),
|
|
3787
4381
|
};
|
|
4382
|
+
}
|
|
3788
4383
|
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
};
|
|
4384
|
+
function loadNotes() {
|
|
4385
|
+
try {
|
|
4386
|
+
const raw = localStorage.getItem(NOTES_KEY);
|
|
4387
|
+
const parsed = raw ? JSON.parse(raw) : null;
|
|
4388
|
+
const items = Array.isArray(parsed && parsed.items) ? parsed.items.map(normalizeNote).filter(Boolean) : [];
|
|
4389
|
+
return { version: 1, items };
|
|
4390
|
+
} catch (_error) {
|
|
4391
|
+
return { version: 1, items: [] };
|
|
4392
|
+
}
|
|
4393
|
+
}
|
|
3800
4394
|
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
4395
|
+
const notes = (() => {
|
|
4396
|
+
if (typeof window === 'undefined') return createStore({ version: 1, items: [] });
|
|
4397
|
+
if (!window[NOTES_SINGLETON]) window[NOTES_SINGLETON] = createStore(loadNotes());
|
|
4398
|
+
return window[NOTES_SINGLETON];
|
|
4399
|
+
})();
|
|
3806
4400
|
|
|
3807
|
-
|
|
3808
|
-
const
|
|
3809
|
-
const
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
4401
|
+
function mutateNotes(fn) {
|
|
4402
|
+
const prev = notes.get();
|
|
4403
|
+
const next = fn(prev);
|
|
4404
|
+
if (!next || next === prev) return;
|
|
4405
|
+
notes.set(next);
|
|
4406
|
+
try {
|
|
4407
|
+
localStorage.setItem(NOTES_KEY, JSON.stringify(next));
|
|
4408
|
+
} catch (_error) {
|
|
4409
|
+
/* a full store keeps the in-memory copy; the pool reports write failures */
|
|
4410
|
+
}
|
|
4411
|
+
}
|
|
4412
|
+
|
|
4413
|
+
const notesActions = {
|
|
4414
|
+
add(note) {
|
|
4415
|
+
mutateNotes((state) => ({ ...state, items: [...state.items, note] }));
|
|
4416
|
+
return note;
|
|
4417
|
+
},
|
|
4418
|
+
patch(id, fields) {
|
|
4419
|
+
mutateNotes((state) => ({
|
|
4420
|
+
...state,
|
|
4421
|
+
items: state.items.map((note) => (note.id === id ? { ...note, ...fields, updatedAt: Date.now() } : note)),
|
|
4422
|
+
}));
|
|
4423
|
+
},
|
|
4424
|
+
remove(id) {
|
|
4425
|
+
mutateNotes((state) => (state.items.some((note) => note.id === id)
|
|
4426
|
+
? { ...state, items: state.items.filter((note) => note.id !== id) }
|
|
4427
|
+
: null));
|
|
4428
|
+
},
|
|
4429
|
+
clearSession(sessionId) {
|
|
4430
|
+
mutateNotes((state) => {
|
|
4431
|
+
const items = state.items.filter((note) => note.sessionId !== sessionId);
|
|
4432
|
+
return items.length === state.items.length ? null : { ...state, items };
|
|
4433
|
+
});
|
|
4434
|
+
},
|
|
4435
|
+
/** Drop every drag offset in one session: the cards return to their anchors. */
|
|
4436
|
+
resetPositions(sessionId) {
|
|
4437
|
+
mutateNotes((state) => {
|
|
4438
|
+
let touched = false;
|
|
4439
|
+
const items = state.items.map((note) => {
|
|
4440
|
+
if (note.sessionId !== sessionId) return note;
|
|
4441
|
+
if ((note.dx || 0) === 0 && (note.dy || 0) === 0) return note;
|
|
4442
|
+
touched = true;
|
|
4443
|
+
return { ...note, dx: 0, dy: 0 };
|
|
4444
|
+
});
|
|
4445
|
+
return touched ? { ...state, items } : null;
|
|
4446
|
+
});
|
|
4447
|
+
},
|
|
4448
|
+
};
|
|
4449
|
+
|
|
4450
|
+
/**
|
|
4451
|
+
* A frame-level toast. The notes views live inside the composer overlay or a
|
|
4452
|
+
* sidebar column, so an inline status would be clipped or lost in the list;
|
|
4453
|
+
* the toast is appended to the body and floats above every surface.
|
|
4454
|
+
*/
|
|
4455
|
+
let toastNode = null;
|
|
4456
|
+
let toastTimer = 0;
|
|
4457
|
+
function ensureToastStyle() {
|
|
4458
|
+
if (typeof document === 'undefined') return;
|
|
4459
|
+
if (document.querySelector('style[data-pp-toast]')) return;
|
|
4460
|
+
const style = document.createElement('style');
|
|
4461
|
+
style.setAttribute('data-pp-toast', '');
|
|
4462
|
+
style.textContent = '.pp-toast{position:fixed;left:50%;bottom:30px;z-index:2147483000;max-width:min(520px,calc(100vw - 32px));padding:7px 13px;border-radius:8px;background:rgba(24,24,26,.94);color:#fff;font-size:12px;line-height:1.5;box-shadow:0 12px 30px rgba(0,0,0,.28);opacity:0;transform:translate(-50%,8px);transition:opacity .16s ease,transform .16s ease;pointer-events:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.pp-toast[data-show="true"]{opacity:1;transform:translate(-50%,0)}.pp-toast[data-kind="error"]{background:rgba(160,38,38,.95)}';
|
|
4463
|
+
document.head.appendChild(style);
|
|
4464
|
+
}
|
|
4465
|
+
function showToast(text, kind) {
|
|
4466
|
+
if (typeof document === 'undefined' || !text) return;
|
|
4467
|
+
ensureToastStyle();
|
|
4468
|
+
if (!toastNode) {
|
|
4469
|
+
toastNode = document.createElement('div');
|
|
4470
|
+
toastNode.className = 'pp-toast';
|
|
4471
|
+
toastNode.setAttribute('role', 'status');
|
|
4472
|
+
document.body.appendChild(toastNode);
|
|
4473
|
+
}
|
|
4474
|
+
toastNode.textContent = text;
|
|
4475
|
+
toastNode.setAttribute('data-kind', kind === 'error' ? 'error' : 'ok');
|
|
4476
|
+
toastNode.setAttribute('data-show', 'true');
|
|
4477
|
+
window.clearTimeout(toastTimer);
|
|
4478
|
+
toastTimer = window.setTimeout(() => {
|
|
4479
|
+
if (toastNode) toastNode.removeAttribute('data-show');
|
|
4480
|
+
}, 2300);
|
|
4481
|
+
}
|
|
4482
|
+
|
|
4483
|
+
/** The session whose transcript is on screen; published by the notes layer. */
|
|
4484
|
+
const chatView = (() => {
|
|
4485
|
+
if (typeof window === 'undefined') return createStore({ sessionId: '' });
|
|
4486
|
+
if (!window.__dshPromptPoolNotesViewV1) window.__dshPromptPoolNotesViewV1 = createStore({ sessionId: '' });
|
|
4487
|
+
return window.__dshPromptPoolNotesViewV1;
|
|
4488
|
+
})();
|
|
4489
|
+
/** A newly captured anchor waiting for the overlay to open its editor. */
|
|
4490
|
+
const noteDraft = (() => {
|
|
4491
|
+
if (typeof window === 'undefined') return createStore({ anchor: null, sessionId: '', token: 0 });
|
|
4492
|
+
if (!window.__dshPromptPoolNotesDraftV1) window.__dshPromptPoolNotesDraftV1 = createStore({ anchor: null, sessionId: '', token: 0 });
|
|
4493
|
+
return window.__dshPromptPoolNotesDraftV1;
|
|
4494
|
+
})();
|
|
4495
|
+
/** A request to scroll to one annotation and open it. */
|
|
4496
|
+
const noteFocus = (() => {
|
|
4497
|
+
if (typeof window === 'undefined') return createStore({ id: '', token: 0 });
|
|
4498
|
+
if (!window.__dshPromptPoolNotesFocusV1) window.__dshPromptPoolNotesFocusV1 = createStore({ id: '', token: 0 });
|
|
4499
|
+
return window.__dshPromptPoolNotesFocusV1;
|
|
4500
|
+
})();
|
|
4501
|
+
|
|
4502
|
+
/**
|
|
4503
|
+
* The "pick a group" popup for storing a prompt. It lives in the frame
|
|
4504
|
+
* overlay (not in the pool list) so it can float over the panel instead of
|
|
4505
|
+
* pushing content around or being clipped by the list.
|
|
4506
|
+
*/
|
|
4507
|
+
const notePrompt = (() => {
|
|
4508
|
+
const empty = { open: false, target: null, choices: [], anchor: null, defaultValue: '', onPick: null, token: 0 };
|
|
4509
|
+
if (typeof window === 'undefined') return createStore(empty);
|
|
4510
|
+
if (!window.__dshPromptPoolNotePromptV1) window.__dshPromptPoolNotePromptV1 = createStore(empty);
|
|
4511
|
+
return window.__dshPromptPoolNotePromptV1;
|
|
4512
|
+
})();
|
|
4513
|
+
const closeNotePrompt = () => notePrompt.set({ open: false, target: null, choices: [], anchor: null, defaultValue: '', onPick: null, token: 0 });
|
|
4514
|
+
|
|
4515
|
+
/** The "delete this annotation?" popup; the confirmation floats, never inline. */
|
|
4516
|
+
const noteConfirm = (() => {
|
|
4517
|
+
const empty = { open: false, anchor: null, onConfirm: null, token: 0 };
|
|
4518
|
+
if (typeof window === 'undefined') return createStore(empty);
|
|
4519
|
+
if (!window.__dshPromptPoolNoteConfirmV1) window.__dshPromptPoolNoteConfirmV1 = createStore(empty);
|
|
4520
|
+
return window.__dshPromptPoolNoteConfirmV1;
|
|
4521
|
+
})();
|
|
4522
|
+
const closeNoteConfirm = () => noteConfirm.set({ open: false, anchor: null, onConfirm: null, token: 0 });
|
|
4523
|
+
|
|
4524
|
+
/** A short status line in the annotations tab's bottom strip (locate misses). */
|
|
4525
|
+
const noteStatus = (() => {
|
|
4526
|
+
const empty = { text: '', kind: '', token: 0 };
|
|
4527
|
+
if (typeof window === 'undefined') return createStore(empty);
|
|
4528
|
+
if (!window.__dshPromptPoolNoteStatusV1) window.__dshPromptPoolNoteStatusV1 = createStore(empty);
|
|
4529
|
+
return window.__dshPromptPoolNoteStatusV1;
|
|
4530
|
+
})();
|
|
4531
|
+
function showNoteStatus(text, kind) {
|
|
4532
|
+
const token = Date.now();
|
|
4533
|
+
noteStatus.set({ text: String(text || ''), kind: kind === 'error' ? 'error' : 'ok', token });
|
|
4534
|
+
if (typeof window !== 'undefined') {
|
|
4535
|
+
window.setTimeout(() => {
|
|
4536
|
+
if (noteStatus.get().token === token) noteStatus.set({ text: '', kind: '', token: 0 });
|
|
4537
|
+
}, 2800);
|
|
4538
|
+
}
|
|
4539
|
+
}
|
|
4540
|
+
function openNoteConfirm(run, event) {
|
|
4541
|
+
const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
|
|
4542
|
+
? event.currentTarget.getBoundingClientRect()
|
|
4543
|
+
: null;
|
|
4544
|
+
noteConfirm.set({
|
|
4545
|
+
open: true,
|
|
4546
|
+
anchor: rect
|
|
4547
|
+
? { left: Math.round(rect.left), right: Math.round(rect.right), top: Math.round(rect.top), bottom: Math.round(rect.bottom) }
|
|
4548
|
+
: { left: 120, right: 160, top: 90, bottom: 120 },
|
|
4549
|
+
onConfirm: typeof run === 'function' ? run : null,
|
|
4550
|
+
token: Date.now(),
|
|
4551
|
+
});
|
|
4552
|
+
}
|
|
4553
|
+
|
|
4554
|
+
const useNotesState = () => useSyncExternalStore(notes.subscribe, notes.get, notes.get);
|
|
4555
|
+
const useChatView = () => useSyncExternalStore(chatView.subscribe, chatView.get, chatView.get);
|
|
4556
|
+
const useNoteDraft = () => useSyncExternalStore(noteDraft.subscribe, noteDraft.get, noteDraft.get);
|
|
4557
|
+
const useNoteFocus = () => useSyncExternalStore(noteFocus.subscribe, noteFocus.get, noteFocus.get);
|
|
4558
|
+
const useNotePrompt = () => useSyncExternalStore(notePrompt.subscribe, notePrompt.get, notePrompt.get);
|
|
4559
|
+
const useNoteConfirm = () => useSyncExternalStore(noteConfirm.subscribe, noteConfirm.get, noteConfirm.get);
|
|
4560
|
+
const useNoteStatus = () => useSyncExternalStore(noteStatus.subscribe, noteStatus.get, noteStatus.get);
|
|
4561
|
+
|
|
4562
|
+
/** One line of quote text for a row, a pin tooltip or the composed reply. */
|
|
4563
|
+
function noteQuoteText(quote, limit) {
|
|
4564
|
+
const text = String(quote || '').replace(/\s+/g, ' ').trim();
|
|
4565
|
+
const max = limit || 80;
|
|
4566
|
+
return text.length > max ? text.slice(0, max) + '…' : text;
|
|
4567
|
+
}
|
|
4568
|
+
|
|
4569
|
+
/** The reply a session's annotations produce: numbered, each with its quote. */
|
|
4570
|
+
/** One note as a prompt line, without a number (single-note drafts). */
|
|
4571
|
+
function composeNoteLine(note) {
|
|
4572
|
+
const kind = noteKind(note.kind);
|
|
4573
|
+
const label = translate(kind.label);
|
|
4574
|
+
const body = String(note.body || '').replace(/\s+/g, ' ').trim();
|
|
4575
|
+
return `【${label}】「${noteQuoteText(note.quote)}」${body ? ':' + body : ''}`;
|
|
4576
|
+
}
|
|
4577
|
+
|
|
4578
|
+
/** The reply a session's annotations produce: numbered, each with its quote. */
|
|
4579
|
+
function composeNotesReply(list) {
|
|
4580
|
+
return list
|
|
4581
|
+
.slice()
|
|
4582
|
+
.sort((left, right) => (left.order - right.order) || (left.createdAt - right.createdAt))
|
|
4583
|
+
.map((note, index) => `${index + 1}. ${composeNoteLine(note)}`)
|
|
4584
|
+
.join('\n');
|
|
4585
|
+
}
|
|
4586
|
+
|
|
4587
|
+
/** The selection's start as an index into the element's plain textContent. */
|
|
4588
|
+
function textOffsetIn(source, container, offset) {
|
|
4589
|
+
try {
|
|
4590
|
+
const walker = document.createTreeWalker(source, typeof NodeFilter === 'undefined' ? 4 : NodeFilter.SHOW_TEXT);
|
|
4591
|
+
let total = 0;
|
|
4592
|
+
let node = walker.nextNode();
|
|
4593
|
+
while (node) {
|
|
4594
|
+
if (node === container) return total + offset;
|
|
4595
|
+
total += node.nodeValue ? node.nodeValue.length : 0;
|
|
4596
|
+
node = walker.nextNode();
|
|
4597
|
+
}
|
|
4598
|
+
if (container.nodeType !== 1) return total;
|
|
4599
|
+
// An element boundary: sum the text before its child at `offset`.
|
|
4600
|
+
let before = 0;
|
|
4601
|
+
const probe = document.createRange();
|
|
4602
|
+
probe.selectNodeContents(source);
|
|
4603
|
+
try {
|
|
4604
|
+
probe.setEnd(container, offset);
|
|
4605
|
+
} catch (_error) {
|
|
4606
|
+
return total;
|
|
4607
|
+
}
|
|
4608
|
+
const inner = document.createTreeWalker(source, typeof NodeFilter === 'undefined' ? 4 : NodeFilter.SHOW_TEXT);
|
|
4609
|
+
let text = inner.nextNode();
|
|
4610
|
+
while (text) {
|
|
4611
|
+
const nodeRange = document.createRange();
|
|
4612
|
+
nodeRange.selectNodeContents(text);
|
|
4613
|
+
if (probe.compareBoundaryPoints(Range.END_TO_END, nodeRange) >= 0) {
|
|
4614
|
+
before += text.nodeValue ? text.nodeValue.length : 0;
|
|
4615
|
+
}
|
|
4616
|
+
text = inner.nextNode();
|
|
4617
|
+
}
|
|
4618
|
+
return before;
|
|
4619
|
+
} catch (_error) {
|
|
4620
|
+
return 0;
|
|
4621
|
+
}
|
|
4622
|
+
}
|
|
4623
|
+
|
|
4624
|
+
/**
|
|
4625
|
+
* Capture the selected assistant text as a value anchor. Runs while the
|
|
4626
|
+
* gesture still owns the selection, so it reads the live DOM once and never
|
|
4627
|
+
* depends on that DOM again.
|
|
4628
|
+
*/
|
|
4629
|
+
function captureNoteAnchor(sessionId) {
|
|
4630
|
+
try {
|
|
4631
|
+
if (typeof document === 'undefined') return null;
|
|
4632
|
+
const selection = document.getSelection();
|
|
4633
|
+
if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null;
|
|
4634
|
+
const range = selection.getRangeAt(0);
|
|
4635
|
+
if (!range || range.collapsed) return null;
|
|
4636
|
+
const startNode = range.startContainer;
|
|
4637
|
+
const startElement = startNode && startNode.nodeType === 1 ? startNode : startNode && startNode.parentElement;
|
|
4638
|
+
const endNode = range.endContainer;
|
|
4639
|
+
const endElement = endNode && endNode.nodeType === 1 ? endNode : endNode && endNode.parentElement;
|
|
4640
|
+
if (!startElement || !startElement.closest || !endElement || !endElement.closest) return null;
|
|
4641
|
+
const source = startElement.closest('[data-text-interaction-source]');
|
|
4642
|
+
if (!source || endElement.closest('[data-text-interaction-source]') !== source) return null;
|
|
4643
|
+
const row = source.closest('[data-chat-flow-kind]');
|
|
4644
|
+
if (!row || row.getAttribute('data-chat-flow-kind') !== 'assistant-step') return null;
|
|
4645
|
+
const keyed = source.closest('[data-chat-node-key]');
|
|
4646
|
+
const nodeKey = keyed ? keyed.getAttribute('data-chat-node-key') || '' : '';
|
|
4647
|
+
if (!nodeKey) return null;
|
|
4648
|
+
const rawQuote = range.toString();
|
|
4649
|
+
const quote = rawQuote.trim();
|
|
4650
|
+
if (!quote) return null;
|
|
4651
|
+
// A browser selection often starts on the whitespace that ends the
|
|
4652
|
+
// previous line; trimmed here so the anchor (and its inline badge) starts
|
|
4653
|
+
// on the first visible character instead of the line above.
|
|
4654
|
+
const lead = rawQuote.length - rawQuote.trimStart().length;
|
|
4655
|
+
// Offsets are stored against the element's textContent (block boundaries
|
|
4656
|
+
// are not characters there), which is also what resolution walks.
|
|
4657
|
+
const offset = textOffsetIn(source, range.startContainer, range.startOffset) + lead;
|
|
4658
|
+
const text = source.textContent || '';
|
|
4659
|
+
const prefix = text.slice(Math.max(0, offset - 24), offset);
|
|
4660
|
+
const suffix = text.slice(offset + quote.length, offset + quote.length + 24);
|
|
4661
|
+
let rowIndex = 0;
|
|
4662
|
+
const scroll = noteChatRoot(sessionId);
|
|
4663
|
+
if (scroll) {
|
|
4664
|
+
const rows = scroll.querySelectorAll('[data-chat-node-key]');
|
|
4665
|
+
// A row that is not in this list (a nested copy, a paging remount) must
|
|
4666
|
+
// sort last rather than first: order 0 would put a later note above the
|
|
4667
|
+
// earlier ones and drag their cards down with it.
|
|
4668
|
+
const at = Array.prototype.indexOf.call(rows, keyed);
|
|
4669
|
+
rowIndex = at >= 0 ? at : rows.length;
|
|
4670
|
+
}
|
|
4671
|
+
return { nodeKey, quote, prefix, suffix, offset, order: rowIndex * 1000000 + offset };
|
|
4672
|
+
} catch (_error) {
|
|
4673
|
+
return null;
|
|
4674
|
+
}
|
|
4675
|
+
}
|
|
4676
|
+
|
|
4677
|
+
/**
|
|
4678
|
+
* Find the stored quote inside one element's text. Context match wins over
|
|
4679
|
+
* the stored offset, because a reply can be re-rendered with different
|
|
4680
|
+
* neighbour nodes while its text stays the same.
|
|
4681
|
+
*/
|
|
4682
|
+
function locateQuote(text, quote, prefix, suffix, offset) {
|
|
4683
|
+
if (!text || !quote) return -1;
|
|
4684
|
+
let best = -1;
|
|
4685
|
+
let bestScore = -Infinity;
|
|
4686
|
+
let index = text.indexOf(quote);
|
|
4687
|
+
while (index >= 0) {
|
|
4688
|
+
let score = 0;
|
|
4689
|
+
if (prefix && text.slice(Math.max(0, index - prefix.length), index) === prefix) score += 2;
|
|
4690
|
+
if (suffix && text.slice(index + quote.length, index + quote.length + suffix.length) === suffix) score += 2;
|
|
4691
|
+
score -= Math.abs(index - offset) / Math.max(1, text.length);
|
|
4692
|
+
if (score > bestScore) {
|
|
4693
|
+
bestScore = score;
|
|
4694
|
+
best = index;
|
|
4695
|
+
}
|
|
4696
|
+
index = text.indexOf(quote, index + 1);
|
|
4697
|
+
}
|
|
4698
|
+
return best;
|
|
4699
|
+
}
|
|
4700
|
+
|
|
4701
|
+
/** Collapse whitespace runs for a tolerant comparison. */
|
|
4702
|
+
function collapseWhitespace(value) {
|
|
4703
|
+
return String(value || '').replace(/\s+/g, ' ').trim();
|
|
4704
|
+
}
|
|
4705
|
+
|
|
4706
|
+
/** One collapsed string plus, per character, its index in the original. */
|
|
4707
|
+
function collapsedText(text) {
|
|
4708
|
+
const chars = [];
|
|
4709
|
+
const positions = [];
|
|
4710
|
+
let pendingSpace = false;
|
|
4711
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
4712
|
+
const char = text[index];
|
|
4713
|
+
if (/\s/u.test(char)) {
|
|
4714
|
+
pendingSpace = chars.length > 0;
|
|
4715
|
+
continue;
|
|
4716
|
+
}
|
|
4717
|
+
if (pendingSpace) {
|
|
4718
|
+
chars.push(' ');
|
|
4719
|
+
positions.push(index);
|
|
4720
|
+
pendingSpace = false;
|
|
4721
|
+
}
|
|
4722
|
+
chars.push(char);
|
|
4723
|
+
positions.push(index);
|
|
4724
|
+
}
|
|
4725
|
+
return { text: chars.join(''), positions };
|
|
4726
|
+
}
|
|
4727
|
+
|
|
4728
|
+
/**
|
|
4729
|
+
* The span of one quoted passage inside a source's text. The exact match wins;
|
|
4730
|
+
* a re-render can serialize the same words with different whitespace, so a
|
|
4731
|
+
* collapsed comparison is the fallback.
|
|
4732
|
+
*/
|
|
4733
|
+
function findQuoteSpan(text, quote, prefix, suffix, offset) {
|
|
4734
|
+
if (!text || !quote) return null;
|
|
4735
|
+
// Older anchors may carry the whitespace that ended the previous line; the
|
|
4736
|
+
// passage itself starts on the first visible character.
|
|
4737
|
+
const clean = String(quote).trim();
|
|
4738
|
+
if (!clean) return null;
|
|
4739
|
+
const exact = locateQuote(text, clean, prefix, suffix, offset);
|
|
4740
|
+
if (exact >= 0) return { start: exact, end: exact + clean.length };
|
|
4741
|
+
const target = collapseWhitespace(clean);
|
|
4742
|
+
if (!target) return null;
|
|
4743
|
+
const collapsed = collapsedText(text);
|
|
4744
|
+
const at = collapsed.text.indexOf(target);
|
|
4745
|
+
if (at < 0) return null;
|
|
4746
|
+
const start = collapsed.positions[at];
|
|
4747
|
+
const end = collapsed.positions[at + target.length - 1] + 1;
|
|
4748
|
+
return end > start ? { start, end } : null;
|
|
4749
|
+
}
|
|
4750
|
+
|
|
4751
|
+
/** Build a live DOM Range for a character span of one element's text. */
|
|
4752
|
+
function rangeFromTextOffset(source, start, length) {
|
|
4753
|
+
if (typeof document === 'undefined' || length <= 0) return null;
|
|
4754
|
+
try {
|
|
4755
|
+
const walker = document.createTreeWalker(source, typeof NodeFilter === 'undefined' ? 4 : NodeFilter.SHOW_TEXT);
|
|
4756
|
+
let node = walker.nextNode();
|
|
4757
|
+
let consumed = 0;
|
|
4758
|
+
let from = null;
|
|
4759
|
+
while (node) {
|
|
4760
|
+
const size = node.nodeValue ? node.nodeValue.length : 0;
|
|
4761
|
+
if (from === null && consumed + size >= start) from = { node, offset: start - consumed };
|
|
4762
|
+
if (from !== null && consumed + size >= start + length) {
|
|
4763
|
+
const range = document.createRange();
|
|
4764
|
+
range.setStart(from.node, from.offset);
|
|
4765
|
+
range.setEnd(node, start + length - consumed);
|
|
4766
|
+
return range;
|
|
4767
|
+
}
|
|
4768
|
+
consumed += size;
|
|
4769
|
+
node = walker.nextNode();
|
|
4770
|
+
}
|
|
4771
|
+
} catch (_error) {
|
|
4772
|
+
/* a half-built tree during a re-render */
|
|
4773
|
+
}
|
|
4774
|
+
return null;
|
|
4775
|
+
}
|
|
4776
|
+
|
|
4777
|
+
/**
|
|
4778
|
+
* The main conversation's scroll container. The sidebar renders session
|
|
4779
|
+
* previews with the same conversation attributes, so pick the container that
|
|
4780
|
+
* belongs to this session and owns the composer (previews own neither).
|
|
4781
|
+
*/
|
|
4782
|
+
function noteChatRoot(sessionId) {
|
|
4783
|
+
if (typeof document === 'undefined') return null;
|
|
4784
|
+
const candidates = Array.from(document.querySelectorAll('[data-conversation-scroll]'));
|
|
4785
|
+
if (candidates.length === 0) return null;
|
|
4786
|
+
const sameSession = sessionId
|
|
4787
|
+
? candidates.filter((element) => {
|
|
4788
|
+
const owner = element.closest('[data-conversation-session]');
|
|
4789
|
+
return owner !== null && owner.getAttribute('data-conversation-session') === sessionId;
|
|
4790
|
+
})
|
|
4791
|
+
: [];
|
|
4792
|
+
const pool = sameSession.length > 0 ? sameSession : candidates;
|
|
4793
|
+
const withComposer = pool.filter((element) => element.querySelector('[data-composer-seat]') !== null);
|
|
4794
|
+
const preferred = withComposer.length > 0 ? withComposer : pool;
|
|
4795
|
+
let best = null;
|
|
4796
|
+
let bestWidth = 0;
|
|
4797
|
+
for (const element of preferred) {
|
|
4798
|
+
const rect = element.getBoundingClientRect();
|
|
4799
|
+
if (rect.height > 0 && rect.width > bestWidth) {
|
|
4800
|
+
best = element;
|
|
4801
|
+
bestWidth = rect.width;
|
|
4802
|
+
}
|
|
4803
|
+
}
|
|
4804
|
+
return best || preferred[0] || null;
|
|
4805
|
+
}
|
|
4806
|
+
|
|
4807
|
+
|
|
4808
|
+
/** Resolve an anchor or a stored note to its live range and transcript row. */
|
|
4809
|
+
function resolveNote(anchor, root) {
|
|
4810
|
+
if (!root || !anchor || typeof document === 'undefined') return null;
|
|
4811
|
+
const rows = root.querySelectorAll('[data-chat-node-key]');
|
|
4812
|
+
// Prefer the row the note was captured from; if its key changed, the same
|
|
4813
|
+
// words can still be found elsewhere in the transcript.
|
|
4814
|
+
const ordered = [];
|
|
4815
|
+
const rest = [];
|
|
4816
|
+
for (const row of rows) {
|
|
4817
|
+
if (row.getAttribute('data-chat-node-key') === anchor.nodeKey) ordered.push(row);
|
|
4818
|
+
else rest.push(row);
|
|
4819
|
+
}
|
|
4820
|
+
for (const row of [...ordered, ...rest]) {
|
|
4821
|
+
const sources = row.querySelectorAll('[data-text-interaction-source]');
|
|
4822
|
+
for (const source of sources) {
|
|
4823
|
+
const text = source.textContent || '';
|
|
4824
|
+
const span = findQuoteSpan(text, anchor.quote, anchor.prefix, anchor.suffix, anchor.offset);
|
|
4825
|
+
if (!span) continue;
|
|
4826
|
+
const range = rangeFromTextOffset(source, span.start, span.end - span.start);
|
|
4827
|
+
if (range) return { range, row };
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4830
|
+
return null;
|
|
4831
|
+
}
|
|
4832
|
+
|
|
4833
|
+
/** The range alone, for callers that only need to paint or scroll it. */
|
|
4834
|
+
function resolveNoteRange(anchor, root) {
|
|
4835
|
+
const resolved = resolveNote(anchor, root);
|
|
4836
|
+
return resolved ? resolved.range : null;
|
|
4837
|
+
}
|
|
4838
|
+
|
|
4839
|
+
/** Paint every annotated range, tinted by its kind. */
|
|
4840
|
+
function applyNoteHighlights(items) {
|
|
4841
|
+
try {
|
|
4842
|
+
// The module has its own `CSS` string for the pool panel, so reach for
|
|
4843
|
+
// the browser namespace explicitly.
|
|
4844
|
+
const registry = typeof globalThis === 'undefined' ? undefined : globalThis.CSS;
|
|
4845
|
+
const HighlightType = typeof globalThis === 'undefined' ? undefined : globalThis.Highlight;
|
|
4846
|
+
if (!registry || !registry.highlights || typeof HighlightType !== 'function') return;
|
|
4847
|
+
for (const id of NOTE_KIND_IDS) registry.highlights.delete(NOTE_HIGHLIGHT + '-' + id);
|
|
4848
|
+
if (!items || items.length === 0) return;
|
|
4849
|
+
const buckets = new Map();
|
|
4850
|
+
for (const item of items) {
|
|
4851
|
+
if (!item || !item.range) continue;
|
|
4852
|
+
const id = noteKind(item.kind).id;
|
|
4853
|
+
if (!buckets.has(id)) buckets.set(id, []);
|
|
4854
|
+
buckets.get(id).push(item.range);
|
|
4855
|
+
}
|
|
4856
|
+
for (const [id, ranges] of buckets) {
|
|
4857
|
+
registry.highlights.set(NOTE_HIGHLIGHT + '-' + id, new HighlightType(...ranges));
|
|
4858
|
+
}
|
|
4859
|
+
} catch (_error) {
|
|
4860
|
+
/* older engines: the inline badges still work */
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
|
|
4864
|
+
/**
|
|
4865
|
+
* Pins, highlights and the inline editor, drawn into the frame-wide overlay.
|
|
4866
|
+
* The markdown DOM is never touched: live ranges are measured and the layer is
|
|
4867
|
+
* positioned over them, so selection, copy and the host's rendering still work.
|
|
4868
|
+
*/
|
|
4869
|
+
function NotesLayer() {
|
|
4870
|
+
useLocaleTick();
|
|
4871
|
+
const notesState = useNotesState();
|
|
4872
|
+
const view = useChatView();
|
|
4873
|
+
const draft = useNoteDraft();
|
|
4874
|
+
const focus = useNoteFocus();
|
|
4875
|
+
const prompt = useNotePrompt();
|
|
4876
|
+
const confirm = useNoteConfirm();
|
|
4877
|
+
const pool = usePoolState();
|
|
4878
|
+
const [editing, setEditing] = useState(null);
|
|
4879
|
+
const [body, setBody] = useState('');
|
|
4880
|
+
const [kind, setKind] = useState(NOTE_KIND_DEFAULT);
|
|
4881
|
+
const [missing, setMissing] = useState(false);
|
|
4882
|
+
const [anchorPoint, setAnchorPoint] = useState(null);
|
|
4883
|
+
const bubbleRef = useRef(null);
|
|
4884
|
+
const frameRef = useRef(0);
|
|
4885
|
+
const sessionId = view.sessionId;
|
|
4886
|
+
const sessionNotes = notesState.items
|
|
4887
|
+
.filter((note) => note.sessionId === sessionId)
|
|
4888
|
+
.sort((left, right) => (left.order - right.order) || (left.createdAt - right.createdAt));
|
|
4889
|
+
const notesRef = useRef(sessionNotes);
|
|
4890
|
+
notesRef.current = sessionNotes;
|
|
4891
|
+
// The open editor's passage: highlighted (and tinted by the pending kind)
|
|
4892
|
+
// before anything is saved, and dropped again when the bubble closes.
|
|
4893
|
+
const draftRef = useRef(null);
|
|
4894
|
+
draftRef.current = editing ? { id: editing.id || '', anchor: editing.anchor || null, kind } : null;
|
|
4895
|
+
const highlightOn = !pool.settings || pool.settings.notesHighlight !== false;
|
|
4896
|
+
const highlightRef = useRef(highlightOn);
|
|
4897
|
+
highlightRef.current = highlightOn;
|
|
4898
|
+
|
|
4899
|
+
/**
|
|
4900
|
+
* The last visible character of a passage. Trailing whitespace in the
|
|
4901
|
+
* selection is skipped so the badge sits right after the text.
|
|
4902
|
+
*/
|
|
4903
|
+
const visibleEnd = (range) => {
|
|
4904
|
+
try {
|
|
4905
|
+
const take = (node, offset) => {
|
|
4906
|
+
const data = node.nodeValue || '';
|
|
4907
|
+
let at = Math.min(offset, data.length);
|
|
4908
|
+
while (at > 0 && /\s/.test(data[at - 1])) at -= 1;
|
|
4909
|
+
return at > 0 ? { node, offset: at } : null;
|
|
4910
|
+
};
|
|
4911
|
+
if (range.endContainer.nodeType === 3) {
|
|
4912
|
+
const hit = take(range.endContainer, range.endOffset);
|
|
4913
|
+
if (hit) return hit;
|
|
4914
|
+
}
|
|
4915
|
+
const walker = document.createTreeWalker(range.commonAncestorContainer, typeof NodeFilter === 'undefined' ? 4 : NodeFilter.SHOW_TEXT);
|
|
4916
|
+
let node = walker.nextNode();
|
|
4917
|
+
let last = null;
|
|
4918
|
+
while (node) {
|
|
4919
|
+
const position = range.comparePoint(node, 0);
|
|
4920
|
+
if (position === 1) break;
|
|
4921
|
+
if (position === 0 || node === range.startContainer) last = node;
|
|
4922
|
+
node = walker.nextNode();
|
|
4923
|
+
}
|
|
4924
|
+
if (last) {
|
|
4925
|
+
const hit = take(last, last.nodeValue ? last.nodeValue.length : 0);
|
|
4926
|
+
if (hit) return hit;
|
|
4927
|
+
}
|
|
4928
|
+
} catch (_error) {
|
|
4929
|
+
/* fall back to the range's own end */
|
|
4930
|
+
}
|
|
4931
|
+
return { node: range.endContainer, offset: range.endOffset };
|
|
4932
|
+
};
|
|
4933
|
+
|
|
4934
|
+
/**
|
|
4935
|
+
* The inline badge: a short chip inserted right before the passage. It is
|
|
4936
|
+
* foreign to the host's React tree, so it is re-inserted whenever a
|
|
4937
|
+
* re-render drops it; the chip itself carries no text the transcript would
|
|
4938
|
+
* copy (it is user-select:none and clickable).
|
|
4939
|
+
*/
|
|
4940
|
+
const insertChip = (range, note, meta, shown) => {
|
|
4941
|
+
if (!range || !range.startContainer) return;
|
|
4942
|
+
try {
|
|
4943
|
+
const chip = document.createElement('span');
|
|
4944
|
+
chip.className = 'pp-note-inline';
|
|
4945
|
+
chip.setAttribute('data-pp-inline', note.id);
|
|
4946
|
+
chip.setAttribute('data-kind', meta.id);
|
|
4947
|
+
chip.setAttribute('data-text', shown);
|
|
4948
|
+
chip.setAttribute('data-version', NOTE_CHIP_VERSION);
|
|
4949
|
+
chip.setAttribute('role', 'button');
|
|
4950
|
+
chip.setAttribute('tabindex', '0');
|
|
4951
|
+
chip.setAttribute('title', shown ? `${translate(meta.label)}:${shown}` : translate(meta.label));
|
|
4952
|
+
const icon = document.createElement('span');
|
|
4953
|
+
icon.className = 'pp-note-inline-icon';
|
|
4954
|
+
icon.textContent = meta.icon;
|
|
4955
|
+
const text = document.createElement('span');
|
|
4956
|
+
text.className = 'pp-note-inline-text';
|
|
4957
|
+
// A kind-only note is just its glyph.
|
|
4958
|
+
text.textContent = shown;
|
|
4959
|
+
chip.appendChild(icon);
|
|
4960
|
+
if (shown) chip.appendChild(text);
|
|
4961
|
+
const open = (event) => {
|
|
4962
|
+
event.preventDefault();
|
|
4963
|
+
event.stopPropagation();
|
|
4964
|
+
openNote(note.id);
|
|
4965
|
+
};
|
|
4966
|
+
chip.addEventListener('click', open);
|
|
4967
|
+
chip.addEventListener('pointerdown', (event) => {
|
|
4968
|
+
// Keep the pointer from starting a text selection; the click itself
|
|
4969
|
+
// still has to reach the badge.
|
|
4970
|
+
event.stopPropagation();
|
|
4971
|
+
});
|
|
4972
|
+
chip.addEventListener('keydown', (event) => {
|
|
4973
|
+
if (event.key === 'Enter' || event.key === ' ') open(event);
|
|
4974
|
+
});
|
|
4975
|
+
const at = document.createRange();
|
|
4976
|
+
const end = visibleEnd(range);
|
|
4977
|
+
at.setStart(end.node, end.offset);
|
|
4978
|
+
at.collapse(true);
|
|
4979
|
+
at.insertNode(chip);
|
|
4980
|
+
} catch (_error) {
|
|
4981
|
+
/* the passage moved or the node refused insertion; the tab still lists it */
|
|
4982
|
+
}
|
|
4983
|
+
};
|
|
4984
|
+
|
|
4985
|
+
const syncChips = () => {
|
|
4986
|
+
if (typeof document === 'undefined') return;
|
|
4987
|
+
const root = noteChatRoot(sessionId);
|
|
4988
|
+
if (!root) return;
|
|
4989
|
+
const wanted = new Map();
|
|
4990
|
+
for (const note of notesRef.current) wanted.set(note.id, note);
|
|
4991
|
+
// A fresh layer (or a session switch) rebuilds every badge once, so
|
|
4992
|
+
// anchors placed by an older insertion rule are corrected too.
|
|
4993
|
+
const resetKey = sessionId;
|
|
4994
|
+
const fresh = chipResetRef.current !== resetKey;
|
|
4995
|
+
chipResetRef.current = resetKey;
|
|
4996
|
+
if (fresh) {
|
|
4997
|
+
for (const chip of root.querySelectorAll('[data-pp-inline]')) chip.remove();
|
|
4998
|
+
}
|
|
4999
|
+
for (const chip of root.querySelectorAll('[data-pp-inline]')) {
|
|
5000
|
+
if (!wanted.has(chip.getAttribute('data-pp-inline'))) chip.remove();
|
|
5001
|
+
}
|
|
5002
|
+
for (const note of wanted.values()) {
|
|
5003
|
+
const meta = noteKind(note.kind);
|
|
5004
|
+
const shown = noteBodyText(note.body);
|
|
5005
|
+
const existing = root.querySelector('[data-pp-inline="' + note.id + '"]');
|
|
5006
|
+
if (existing) {
|
|
5007
|
+
const same = existing.getAttribute('data-kind') === meta.id
|
|
5008
|
+
&& existing.getAttribute('data-text') === shown
|
|
5009
|
+
&& existing.getAttribute('data-version') === NOTE_CHIP_VERSION;
|
|
5010
|
+
if (same) continue;
|
|
5011
|
+
existing.remove();
|
|
5012
|
+
}
|
|
5013
|
+
const hit = resolveNote(note, root);
|
|
5014
|
+
if (!hit) continue;
|
|
5015
|
+
// A streaming row rebuilds every token; only settled text keeps a badge.
|
|
5016
|
+
if (hit.row && hit.row.querySelector('[data-streaming]')) continue;
|
|
5017
|
+
insertChip(hit.range, note, meta, shown);
|
|
5018
|
+
}
|
|
5019
|
+
};
|
|
5020
|
+
const syncRef = useRef(syncChips);
|
|
5021
|
+
syncRef.current = syncChips;
|
|
5022
|
+
const chipResetRef = useRef('');
|
|
5023
|
+
|
|
5024
|
+
const measure = useCallback(() => {
|
|
5025
|
+
const list = notesRef.current;
|
|
5026
|
+
const root = noteChatRoot(sessionId);
|
|
5027
|
+
if (!root || list.length === 0) {
|
|
5028
|
+
applyNoteHighlights([]);
|
|
5029
|
+
return;
|
|
5030
|
+
}
|
|
5031
|
+
const items = [];
|
|
5032
|
+
for (const note of list) {
|
|
5033
|
+
const hit = resolveNote(note, root);
|
|
5034
|
+
if (hit) items.push({ id: note.id, range: hit.range, kind: note.kind });
|
|
5035
|
+
}
|
|
5036
|
+
// The open bubble's passage is underlined immediately, following the
|
|
5037
|
+
// pending kind until Save or Cancel.
|
|
5038
|
+
const draftNote = draftRef.current;
|
|
5039
|
+
if (draftNote) {
|
|
5040
|
+
if (draftNote.id) {
|
|
5041
|
+
const at = items.findIndex((item) => item.id === draftNote.id);
|
|
5042
|
+
if (at >= 0) items[at] = { ...items[at], kind: draftNote.kind };
|
|
5043
|
+
else {
|
|
5044
|
+
const note = notesRef.current.find((entry) => entry.id === draftNote.id);
|
|
5045
|
+
const hit = note ? resolveNote(note, root) : null;
|
|
5046
|
+
if (hit) items.push({ id: draftNote.id, range: hit.range, kind: draftNote.kind });
|
|
5047
|
+
}
|
|
5048
|
+
} else if (draftNote.anchor) {
|
|
5049
|
+
const range = resolveNoteRange(draftNote.anchor, root);
|
|
5050
|
+
if (range) items.push({ id: '', range, kind: draftNote.kind });
|
|
5051
|
+
}
|
|
5052
|
+
}
|
|
5053
|
+
if (highlightRef.current) applyNoteHighlights(items);
|
|
5054
|
+
else applyNoteHighlights([]);
|
|
5055
|
+
}, [sessionId]);
|
|
5056
|
+
|
|
5057
|
+
useEffect(() => {
|
|
5058
|
+
if (typeof document === 'undefined') return undefined;
|
|
5059
|
+
const root = noteChatRoot(sessionId);
|
|
5060
|
+
if (!root || notesRef.current.length === 0) {
|
|
5061
|
+
applyNoteHighlights([]);
|
|
5062
|
+
return undefined;
|
|
5063
|
+
}
|
|
5064
|
+
// The flow can mount after the effect (switching back to Chat from another
|
|
5065
|
+
// view); the observer below schedules a measure once its rows appear.
|
|
5066
|
+
const schedule = () => {
|
|
5067
|
+
if (frameRef.current) return;
|
|
5068
|
+
const run = () => {
|
|
5069
|
+
frameRef.current = 0;
|
|
5070
|
+
measure();
|
|
5071
|
+
syncRef.current();
|
|
5072
|
+
};
|
|
5073
|
+
frameRef.current = typeof window !== 'undefined' && window.requestAnimationFrame
|
|
5074
|
+
? window.requestAnimationFrame(run)
|
|
5075
|
+
: window.setTimeout(run, 16);
|
|
5076
|
+
};
|
|
5077
|
+
root.addEventListener('scroll', schedule, true);
|
|
5078
|
+
window.addEventListener('resize', schedule);
|
|
5079
|
+
const resizer = typeof ResizeObserver === 'function' ? new ResizeObserver(schedule) : null;
|
|
5080
|
+
if (resizer) resizer.observe(root);
|
|
5081
|
+
const observer = typeof MutationObserver === 'function' ? new MutationObserver(schedule) : null;
|
|
5082
|
+
if (observer) observer.observe(root, { childList: true, subtree: true, characterData: true });
|
|
5083
|
+
schedule();
|
|
5084
|
+
return () => {
|
|
5085
|
+
root.removeEventListener('scroll', schedule, true);
|
|
5086
|
+
window.removeEventListener('resize', schedule);
|
|
5087
|
+
if (resizer) resizer.disconnect();
|
|
5088
|
+
if (observer) observer.disconnect();
|
|
5089
|
+
if (frameRef.current && typeof window !== 'undefined' && window.cancelAnimationFrame) window.cancelAnimationFrame(frameRef.current);
|
|
5090
|
+
frameRef.current = 0;
|
|
5091
|
+
};
|
|
5092
|
+
}, [measure, sessionId, sessionNotes.length]);
|
|
5093
|
+
|
|
5094
|
+
// Adding, editing or deleting a note redraws the inline badges; the text
|
|
5095
|
+
// itself never changes.
|
|
5096
|
+
useEffect(() => {
|
|
5097
|
+
syncRef.current();
|
|
5098
|
+
}, [notesState.items, sessionId]);
|
|
5099
|
+
|
|
5100
|
+
useEffect(() => {
|
|
5101
|
+
if (!draft.anchor || (draft.sessionId && draft.sessionId !== sessionId)) return;
|
|
5102
|
+
setEditing({ id: '', anchor: draft.anchor, body: '' });
|
|
5103
|
+
setBody('');
|
|
5104
|
+
setKind(NOTE_KIND_DEFAULT);
|
|
5105
|
+
setMissing(false);
|
|
5106
|
+
// The bubble follows the passage, so the note is written where it belongs.
|
|
5107
|
+
const root = noteChatRoot(sessionId);
|
|
5108
|
+
const range = root ? resolveNoteRange(draft.anchor, root) : null;
|
|
5109
|
+
if (range && root) {
|
|
5110
|
+
const rect = range.getBoundingClientRect();
|
|
5111
|
+
setAnchorPoint({ x: rect.right, y: Math.round(rect.top + rect.height / 2) });
|
|
5112
|
+
const box = root.getBoundingClientRect();
|
|
5113
|
+
if (rect.top < box.top + 40 || rect.bottom > box.bottom - 40) {
|
|
5114
|
+
root.scrollTop += rect.top - box.top - Math.min(120, box.height / 3);
|
|
5115
|
+
}
|
|
5116
|
+
} else {
|
|
5117
|
+
setAnchorPoint(null);
|
|
5118
|
+
}
|
|
5119
|
+
noteDraft.set({ anchor: null, sessionId: '', token: 0 });
|
|
5120
|
+
}, [draft.anchor, draft.sessionId, draft.token, sessionId]);
|
|
5121
|
+
|
|
5122
|
+
// The open bubble's passage is underlined while it is being written; a
|
|
5123
|
+
// kind switch re-tints it live instead of waiting for Save.
|
|
5124
|
+
useEffect(() => {
|
|
5125
|
+
measure();
|
|
5126
|
+
}, [editing, kind, measure]);
|
|
5127
|
+
|
|
5128
|
+
// The floating popups (group picker, delete confirmation); a click outside
|
|
5129
|
+
// or Escape puts them away without changing anything.
|
|
5130
|
+
useEffect(() => {
|
|
5131
|
+
if ((!prompt.open && !confirm.open) || typeof document === 'undefined') return undefined;
|
|
5132
|
+
const onDown = (event) => {
|
|
5133
|
+
const element = event.target instanceof Element ? event.target : null;
|
|
5134
|
+
if (element && element.closest && element.closest('.pp-note-prompt')) return;
|
|
5135
|
+
closeNotePrompt();
|
|
5136
|
+
closeNoteConfirm();
|
|
5137
|
+
};
|
|
5138
|
+
const onKey = (event) => {
|
|
5139
|
+
if (event.key !== 'Escape') return;
|
|
5140
|
+
closeNotePrompt();
|
|
5141
|
+
closeNoteConfirm();
|
|
5142
|
+
};
|
|
5143
|
+
document.addEventListener('pointerdown', onDown, true);
|
|
5144
|
+
document.addEventListener('keydown', onKey, true);
|
|
5145
|
+
return () => {
|
|
5146
|
+
document.removeEventListener('pointerdown', onDown, true);
|
|
5147
|
+
document.removeEventListener('keydown', onKey, true);
|
|
5148
|
+
};
|
|
5149
|
+
}, [prompt.open, prompt.token, confirm.open, confirm.token]);
|
|
5150
|
+
|
|
5151
|
+
useEffect(() => {
|
|
5152
|
+
if (!focus.id) return;
|
|
5153
|
+
const note = notesState.items.find((entry) => entry.id === focus.id);
|
|
5154
|
+
const wantsEditor = focus.edit === true;
|
|
5155
|
+
noteFocus.set({ id: '', token: 0, edit: false });
|
|
5156
|
+
if (!note) return;
|
|
5157
|
+
const root = noteChatRoot(sessionId);
|
|
5158
|
+
const range = root ? resolveNoteRange(note, root) : null;
|
|
5159
|
+
// 定位 means locate: scroll the passage into view (editing is explicit).
|
|
5160
|
+
// only an explicit edit opens the bubble.
|
|
5161
|
+
if (!wantsEditor) {
|
|
5162
|
+
if (!range || !root) return;
|
|
5163
|
+
const rect = range.getBoundingClientRect();
|
|
5164
|
+
const box = root.getBoundingClientRect();
|
|
5165
|
+
if (rect.top < box.top + 40 || rect.bottom > box.bottom - 40) {
|
|
5166
|
+
root.scrollTop += rect.top - box.top - Math.min(120, box.height / 3);
|
|
5167
|
+
}
|
|
5168
|
+
return;
|
|
5169
|
+
}
|
|
5170
|
+
setEditing({ id: note.id, anchor: null, body: note.body });
|
|
5171
|
+
setBody(note.body);
|
|
5172
|
+
setMissing(!range);
|
|
5173
|
+
if (range) {
|
|
5174
|
+
setAnchorPoint({ x: range.getBoundingClientRect().right, y: Math.round(range.getBoundingClientRect().top + range.getBoundingClientRect().height / 2) });
|
|
5175
|
+
} else {
|
|
5176
|
+
setAnchorPoint(null);
|
|
5177
|
+
}
|
|
5178
|
+
if (range && root) {
|
|
5179
|
+
const rect = range.getBoundingClientRect();
|
|
5180
|
+
const box = root.getBoundingClientRect();
|
|
5181
|
+
if (rect.top < box.top + 40 || rect.bottom > box.bottom - 40) {
|
|
5182
|
+
root.scrollTop += rect.top - box.top - Math.min(120, box.height / 3);
|
|
5183
|
+
}
|
|
5184
|
+
}
|
|
5185
|
+
}, [focus.id, focus.token, notesState.items]);
|
|
5186
|
+
|
|
5187
|
+
|
|
5188
|
+
useEffect(() => {
|
|
5189
|
+
if (highlightOn) return;
|
|
5190
|
+
applyNoteHighlights([]);
|
|
5191
|
+
}, [highlightOn]);
|
|
5192
|
+
|
|
5193
|
+
useEffect(() => () => {
|
|
5194
|
+
applyNoteHighlights([]);
|
|
5195
|
+
}, []);
|
|
5196
|
+
|
|
5197
|
+
|
|
5198
|
+
/** Open one saved note; its pin is on screen, so the bubble anchors there. */
|
|
5199
|
+
const openNote = (id) => {
|
|
5200
|
+
const note = notesRef.current.find((entry) => entry.id === id);
|
|
5201
|
+
if (!note) return;
|
|
5202
|
+
setEditing({ id, anchor: null, body: note.body });
|
|
5203
|
+
setBody(note.body);
|
|
5204
|
+
setKind(noteKind(note.kind).id);
|
|
5205
|
+
setMissing(false);
|
|
5206
|
+
const root = noteChatRoot(sessionId);
|
|
5207
|
+
const range = root ? resolveNoteRange(note, root) : null;
|
|
5208
|
+
if (range) {
|
|
5209
|
+
const rect = range.getBoundingClientRect();
|
|
5210
|
+
setAnchorPoint({ x: rect.right, y: Math.round(rect.top + rect.height / 2) });
|
|
5211
|
+
} else {
|
|
5212
|
+
setAnchorPoint(null);
|
|
5213
|
+
}
|
|
5214
|
+
};
|
|
5215
|
+
|
|
5216
|
+
const cancelEditing = () => {
|
|
5217
|
+
setEditing(null);
|
|
5218
|
+
setBody('');
|
|
5219
|
+
setMissing(false);
|
|
5220
|
+
setAnchorPoint(null);
|
|
5221
|
+
};
|
|
5222
|
+
|
|
5223
|
+
const save = () => {
|
|
5224
|
+
if (!editing) return;
|
|
5225
|
+
const value = body.trim();
|
|
5226
|
+
if (editing.id) {
|
|
5227
|
+
notesActions.patch(editing.id, { body: value, kind });
|
|
5228
|
+
} else if (editing.anchor) {
|
|
5229
|
+
notesActions.add({
|
|
5230
|
+
id: uid(),
|
|
5231
|
+
sessionId,
|
|
5232
|
+
nodeKey: editing.anchor.nodeKey,
|
|
5233
|
+
quote: editing.anchor.quote,
|
|
5234
|
+
prefix: editing.anchor.prefix,
|
|
5235
|
+
suffix: editing.anchor.suffix,
|
|
5236
|
+
offset: editing.anchor.offset,
|
|
5237
|
+
order: editing.anchor.order,
|
|
5238
|
+
kind,
|
|
5239
|
+
body: value,
|
|
5240
|
+
createdAt: Date.now(),
|
|
5241
|
+
updatedAt: Date.now(),
|
|
5242
|
+
});
|
|
5243
|
+
}
|
|
5244
|
+
setEditing(null);
|
|
5245
|
+
setBody('');
|
|
5246
|
+
setAnchorPoint(null);
|
|
5247
|
+
};
|
|
5248
|
+
|
|
5249
|
+
const removeEditing = () => {
|
|
5250
|
+
if (!editing || !editing.id) return;
|
|
5251
|
+
notesActions.remove(editing.id);
|
|
5252
|
+
setEditing(null);
|
|
5253
|
+
setBody('');
|
|
5254
|
+
setAnchorPoint(null);
|
|
5255
|
+
};
|
|
5256
|
+
|
|
5257
|
+
// Clicking anywhere else saves a non-empty note and drops an empty draft.
|
|
5258
|
+
useEffect(() => {
|
|
5259
|
+
if (!editing || typeof document === 'undefined') return undefined;
|
|
5260
|
+
const onDown = (event) => {
|
|
5261
|
+
const bubble = bubbleRef.current;
|
|
5262
|
+
if (bubble && event.target instanceof Node && bubble.contains(event.target)) return;
|
|
5263
|
+
const element = event.target instanceof Element ? event.target : null;
|
|
5264
|
+
if (element && element.closest && element.closest('.pp-note-prompt')) return;
|
|
5265
|
+
if (body.trim()) save();
|
|
5266
|
+
else cancelEditing();
|
|
5267
|
+
};
|
|
5268
|
+
document.addEventListener('pointerdown', onDown, true);
|
|
5269
|
+
return () => document.removeEventListener('pointerdown', onDown, true);
|
|
5270
|
+
});
|
|
5271
|
+
|
|
5272
|
+
const onEditorKeyDown = (event) => {
|
|
5273
|
+
if (event.key === 'Escape') {
|
|
5274
|
+
event.preventDefault();
|
|
5275
|
+
cancelEditing();
|
|
5276
|
+
return;
|
|
5277
|
+
}
|
|
5278
|
+
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
|
|
5279
|
+
event.preventDefault();
|
|
5280
|
+
save();
|
|
5281
|
+
}
|
|
5282
|
+
};
|
|
5283
|
+
|
|
5284
|
+
const editingNote = editing && editing.id ? sessionNotes.find((note) => note.id === editing.id) : null;
|
|
5285
|
+
const point = anchorPoint;
|
|
5286
|
+
const docElement = typeof document === 'undefined' ? null : document.documentElement;
|
|
5287
|
+
const viewportWidth = typeof window === 'undefined'
|
|
5288
|
+
? 0
|
|
5289
|
+
: Math.min(window.innerWidth, (docElement && docElement.clientWidth) || window.innerWidth);
|
|
5290
|
+
const viewportHeight = typeof window === 'undefined'
|
|
5291
|
+
? 0
|
|
5292
|
+
: Math.min(window.innerHeight, (docElement && docElement.clientHeight) || window.innerHeight);
|
|
5293
|
+
// The bubble opens on the passage's right, but flips to its left when the
|
|
5294
|
+
// right edge would land on the window border or its scrollbar (the save
|
|
5295
|
+
// button used to sit on the scrollbar and could not be clicked).
|
|
5296
|
+
const bubbleStyle = point && viewportWidth > 0
|
|
5297
|
+
? (() => {
|
|
5298
|
+
const width = 300;
|
|
5299
|
+
const margin = 16;
|
|
5300
|
+
const right = point.x + 14;
|
|
5301
|
+
const left = right + width <= viewportWidth - margin
|
|
5302
|
+
? right
|
|
5303
|
+
: Math.max(margin, point.x - width - 14);
|
|
5304
|
+
const top = Math.min(Math.max(margin, point.y - 24), Math.max(margin, viewportHeight - 250));
|
|
5305
|
+
return {
|
|
5306
|
+
left: Math.round(Math.max(margin, Math.min(left, viewportWidth - width - margin))) + 'px',
|
|
5307
|
+
top: Math.round(top) + 'px',
|
|
5308
|
+
};
|
|
5309
|
+
})()
|
|
5310
|
+
: { left: '50%', top: '38%', transform: 'translate(-50%, -50%)' };
|
|
5311
|
+
|
|
5312
|
+
// The group popup: anchored under the button that opened it, flipped above
|
|
5313
|
+
// when it would leave the frame, and always in the overlay (never clipped
|
|
5314
|
+
// by the pool list).
|
|
5315
|
+
const placePopup = (anchor, width, height) => {
|
|
5316
|
+
if (!anchor) return null;
|
|
5317
|
+
const docElement = typeof document === 'undefined' ? null : document.documentElement;
|
|
5318
|
+
const vw = typeof window === 'undefined' ? 0 : Math.min(window.innerWidth, (docElement && docElement.clientWidth) || window.innerWidth);
|
|
5319
|
+
const vh = typeof window === 'undefined' ? 0 : Math.min(window.innerHeight, (docElement && docElement.clientHeight) || window.innerHeight);
|
|
5320
|
+
// Right-aligned with the button when left-alignment would leave the frame.
|
|
5321
|
+
const left = anchor.left + width + 8 <= vw ? anchor.left : anchor.right - width;
|
|
5322
|
+
const x = Math.max(8, Math.min(left, Math.max(8, vw - width - 8)));
|
|
5323
|
+
let y = anchor.bottom + 6;
|
|
5324
|
+
if (y + height > vh - 8) y = Math.max(8, anchor.top - height - 6);
|
|
5325
|
+
return { left: Math.round(x) + 'px', top: Math.round(y) + 'px' };
|
|
5326
|
+
};
|
|
5327
|
+
const promptStyle = prompt.open && prompt.anchor ? placePopup(prompt.anchor, 210, 280) : null;
|
|
5328
|
+
const confirmStyle = confirm.open && confirm.anchor ? placePopup(confirm.anchor, 240, 110) : null;
|
|
5329
|
+
|
|
5330
|
+
return h(
|
|
5331
|
+
'div',
|
|
5332
|
+
{ className: 'pp-note-layer' },
|
|
5333
|
+
h('style', { key: 'css' }, NOTES_CSS),
|
|
5334
|
+
prompt.open && promptStyle
|
|
5335
|
+
? h(
|
|
5336
|
+
'div',
|
|
5337
|
+
{
|
|
5338
|
+
key: 'prompt',
|
|
5339
|
+
className: 'pp-note-prompt',
|
|
5340
|
+
style: promptStyle,
|
|
5341
|
+
role: 'dialog',
|
|
5342
|
+
'aria-label': translate('capture.title'),
|
|
5343
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
5344
|
+
},
|
|
5345
|
+
h('div', { key: 'title', className: 'pp-note-prompt-title' }, translate('capture.title')),
|
|
5346
|
+
h(
|
|
5347
|
+
'div',
|
|
5348
|
+
{ key: 'list', className: 'pp-note-prompt-list' },
|
|
5349
|
+
(prompt.choices || []).map((choice) => h(
|
|
5350
|
+
'button',
|
|
5351
|
+
{
|
|
5352
|
+
key: choice.value,
|
|
5353
|
+
type: 'button',
|
|
5354
|
+
className: 'pp-note-prompt-row',
|
|
5355
|
+
onClick: () => {
|
|
5356
|
+
const pick = notePrompt.get().onPick;
|
|
5357
|
+
if (typeof pick === 'function') pick(choice.value);
|
|
5358
|
+
},
|
|
5359
|
+
},
|
|
5360
|
+
h('span', { key: 'name', className: 'pp-note-prompt-name' }, choice.label),
|
|
5361
|
+
choice.value === prompt.defaultValue
|
|
5362
|
+
? h('span', { key: 'default', className: 'pp-note-prompt-tag' }, translate('note.default'))
|
|
5363
|
+
: null,
|
|
5364
|
+
)),
|
|
5365
|
+
),
|
|
5366
|
+
h('div', { key: 'sep', className: 'pp-note-prompt-sep' }),
|
|
5367
|
+
h('button', { key: 'cancel', type: 'button', className: 'pp-note-prompt-row pp-note-prompt-cancel', onClick: () => closeNotePrompt() }, translate('note.cancel')),
|
|
5368
|
+
)
|
|
5369
|
+
: null,
|
|
5370
|
+
confirm.open && confirmStyle
|
|
5371
|
+
? h(
|
|
5372
|
+
'div',
|
|
5373
|
+
{
|
|
5374
|
+
key: 'confirm',
|
|
5375
|
+
className: 'pp-note-prompt',
|
|
5376
|
+
style: confirmStyle,
|
|
5377
|
+
role: 'alertdialog',
|
|
5378
|
+
'aria-label': translate('note.deleteConfirm'),
|
|
5379
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
5380
|
+
},
|
|
5381
|
+
h('div', { key: 'msg', className: 'pp-note-prompt-message' }, translate('note.deleteConfirm')),
|
|
5382
|
+
h(
|
|
5383
|
+
'div',
|
|
5384
|
+
{ key: 'actions', className: 'pp-note-prompt-actions' },
|
|
5385
|
+
h('button', { key: 'no', type: 'button', className: 'pp-note-btn', onClick: () => closeNoteConfirm() }, translate('note.cancel')),
|
|
5386
|
+
h(
|
|
5387
|
+
'button',
|
|
5388
|
+
{
|
|
5389
|
+
key: 'yes',
|
|
5390
|
+
type: 'button',
|
|
5391
|
+
className: 'pp-note-btn pp-note-btn-danger',
|
|
5392
|
+
onClick: () => {
|
|
5393
|
+
const run = noteConfirm.get().onConfirm;
|
|
5394
|
+
closeNoteConfirm();
|
|
5395
|
+
if (typeof run === 'function') run();
|
|
5396
|
+
},
|
|
5397
|
+
},
|
|
5398
|
+
translate('note.delete'),
|
|
5399
|
+
),
|
|
5400
|
+
),
|
|
5401
|
+
)
|
|
5402
|
+
: null,
|
|
5403
|
+
editing
|
|
5404
|
+
? h(
|
|
5405
|
+
'div',
|
|
5406
|
+
{
|
|
5407
|
+
key: 'bubble',
|
|
5408
|
+
ref: bubbleRef,
|
|
5409
|
+
className: 'pp-note-bubble',
|
|
5410
|
+
style: { ...bubbleStyle, '--pp-bubble-tint': noteKind(kind).tint },
|
|
5411
|
+
'data-kind': kind,
|
|
5412
|
+
onPointerDown: (event) => event.stopPropagation(),
|
|
5413
|
+
},
|
|
5414
|
+
h(
|
|
5415
|
+
'div',
|
|
5416
|
+
{ className: 'pp-note-bubble-quote' },
|
|
5417
|
+
h('span', { className: 'pp-note-bubble-quote-icon' }, noteKind(kind).icon),
|
|
5418
|
+
noteQuoteText(editingNote ? editingNote.quote : editing.anchor.quote, 10),
|
|
5419
|
+
),
|
|
5420
|
+
missing
|
|
5421
|
+
? h(
|
|
5422
|
+
'div',
|
|
5423
|
+
{ className: 'pp-note-bubble-hint' },
|
|
5424
|
+
translate('note.quoteMissing'),
|
|
5425
|
+
)
|
|
5426
|
+
: null,
|
|
5427
|
+
h(
|
|
5428
|
+
'div',
|
|
5429
|
+
{ className: 'pp-note-kinds' },
|
|
5430
|
+
NOTE_KINDS.map((entry) => h(
|
|
5431
|
+
'button',
|
|
5432
|
+
{
|
|
5433
|
+
key: entry.id,
|
|
5434
|
+
type: 'button',
|
|
5435
|
+
className: 'pp-note-kind',
|
|
5436
|
+
'data-kind': entry.id,
|
|
5437
|
+
'data-active': kind === entry.id ? 'true' : 'false',
|
|
5438
|
+
onClick: () => setKind(entry.id),
|
|
5439
|
+
},
|
|
5440
|
+
h('span', { className: 'pp-note-kind-icon' }, entry.icon),
|
|
5441
|
+
translate(entry.label),
|
|
5442
|
+
)),
|
|
5443
|
+
),
|
|
5444
|
+
h('textarea', {
|
|
5445
|
+
className: 'pp-note-input',
|
|
5446
|
+
value: body,
|
|
5447
|
+
rows: 2,
|
|
5448
|
+
maxLength: NOTE_BODY_MAX,
|
|
5449
|
+
placeholder: translate('note.placeholder'),
|
|
5450
|
+
autoFocus: true,
|
|
5451
|
+
onChange: (event) => setBody(event.target.value),
|
|
5452
|
+
onKeyDown: onEditorKeyDown,
|
|
5453
|
+
}),
|
|
5454
|
+
h(
|
|
5455
|
+
'div',
|
|
5456
|
+
{ className: 'pp-note-bubble-foot' },
|
|
5457
|
+
editingNote
|
|
5458
|
+
? h(
|
|
5459
|
+
'button',
|
|
5460
|
+
{
|
|
5461
|
+
key: 'remove',
|
|
5462
|
+
type: 'button',
|
|
5463
|
+
className: 'pp-note-btn pp-note-btn-quiet-danger',
|
|
5464
|
+
onClick: (event) => openNoteConfirm(removeEditing, event),
|
|
5465
|
+
},
|
|
5466
|
+
translate('note.delete'),
|
|
5467
|
+
)
|
|
5468
|
+
: null,
|
|
5469
|
+
h(
|
|
5470
|
+
'span',
|
|
5471
|
+
{ key: 'limit', className: 'pp-note-limit' },
|
|
5472
|
+
h('span', { className: 'pp-note-limit-count' }, `${body.trim().length}/${NOTE_BODY_MAX}`),
|
|
5473
|
+
),
|
|
5474
|
+
h(
|
|
5475
|
+
'div',
|
|
5476
|
+
{ key: 'acts', className: 'pp-note-bubble-actions' },
|
|
5477
|
+
h('button', { type: 'button', className: 'pp-note-btn', onClick: cancelEditing }, translate('note.cancel')),
|
|
5478
|
+
h(
|
|
5479
|
+
'button',
|
|
5480
|
+
{ type: 'button', className: 'pp-note-btn pp-note-btn-primary', onClick: save },
|
|
5481
|
+
translate('note.save'),
|
|
5482
|
+
),
|
|
5483
|
+
),
|
|
5484
|
+
),
|
|
5485
|
+
)
|
|
5486
|
+
: null,
|
|
5487
|
+
);
|
|
5488
|
+
}
|
|
5489
|
+
|
|
5490
|
+
/**
|
|
5491
|
+
* The session's annotations, shown as a tab inside both prompt-pool views.
|
|
5492
|
+
* A note can be promoted into a pool group (defaulting to this session's
|
|
5493
|
+
* workspace); the caller keeps the compose path: the composer panel inserts
|
|
5494
|
+
* directly, the sidebar page asks the panel over the bridge.
|
|
5495
|
+
*/
|
|
5496
|
+
/** Tiny stroke icons for the annotation row actions. */
|
|
5497
|
+
function NoteActionIcon(props) {
|
|
5498
|
+
const kind = props.kind;
|
|
5499
|
+
const common = {
|
|
5500
|
+
width: 14,
|
|
5501
|
+
height: 14,
|
|
5502
|
+
viewBox: '0 0 20 20',
|
|
5503
|
+
fill: 'none',
|
|
5504
|
+
stroke: 'currentColor',
|
|
5505
|
+
strokeWidth: 1.6,
|
|
5506
|
+
strokeLinecap: 'round',
|
|
5507
|
+
strokeLinejoin: 'round',
|
|
5508
|
+
'aria-hidden': true,
|
|
5509
|
+
style: { display: 'block' },
|
|
5510
|
+
};
|
|
5511
|
+
if (kind === 'edit') {
|
|
5512
|
+
return h('svg', common, h('path', { d: 'M4 16l.6-3.6 9-9a1.7 1.7 0 0 1 2.4 2.4l-9 9L4 16z' }));
|
|
5513
|
+
}
|
|
5514
|
+
if (kind === 'insert') {
|
|
5515
|
+
return h(
|
|
5516
|
+
'svg',
|
|
5517
|
+
common,
|
|
5518
|
+
h('path', { d: 'M3.6 12.4h12.8v3.4H3.6z' }),
|
|
5519
|
+
h('path', { d: 'M10 3v6.4' }),
|
|
5520
|
+
h('path', { d: 'M7.4 6.9 10 9.4l2.6-2.5' }),
|
|
5521
|
+
);
|
|
5522
|
+
}
|
|
5523
|
+
if (kind === 'store') {
|
|
5524
|
+
return h(
|
|
5525
|
+
'svg',
|
|
5526
|
+
common,
|
|
5527
|
+
h('path', { d: 'M10 3v7' }),
|
|
5528
|
+
h('path', { d: 'M7 7.2 10 10l3-2.8' }),
|
|
5529
|
+
h('path', { d: 'M3.6 13.6v2.6h12.8v-2.6' }),
|
|
5530
|
+
);
|
|
5531
|
+
}
|
|
5532
|
+
if (kind === 'locate') {
|
|
5533
|
+
return h(
|
|
5534
|
+
'svg',
|
|
5535
|
+
common,
|
|
5536
|
+
h('circle', { cx: 10, cy: 10, r: 4.6 }),
|
|
5537
|
+
h('path', { d: 'M10 2.2v2.6M10 15.2v2.6M2.2 10h2.6M15.2 10h2.6' }),
|
|
5538
|
+
);
|
|
5539
|
+
}
|
|
5540
|
+
return h(
|
|
5541
|
+
'svg',
|
|
5542
|
+
common,
|
|
5543
|
+
h('path', { d: 'M4 6h12' }),
|
|
5544
|
+
h('path', { d: 'M8 6V4h4v2' }),
|
|
5545
|
+
h('path', { d: 'M6 6l.7 10h6.6L14 6' }),
|
|
5546
|
+
);
|
|
5547
|
+
}
|
|
5548
|
+
|
|
5549
|
+
function NotesView(props) {
|
|
5550
|
+
useLocaleTick();
|
|
5551
|
+
const list = Array.isArray(props.notes) ? props.notes : [];
|
|
5552
|
+
const sessionId = typeof props.sessionId === 'string' ? props.sessionId : '';
|
|
5553
|
+
const categories = Array.isArray(props.categories) ? props.categories : [];
|
|
5554
|
+
const workspaceList = Array.isArray(props.workspaces) ? props.workspaces : [];
|
|
5555
|
+
const currentWorkspaceId = typeof props.currentWorkspaceId === 'string' ? props.currentWorkspaceId : '';
|
|
5556
|
+
const filter = typeof props.filter === 'string' ? props.filter.trim().toLowerCase() : '';
|
|
5557
|
+
const matches = (note) => !filter
|
|
5558
|
+
|| String(note.quote || '').toLowerCase().indexOf(filter) >= 0
|
|
5559
|
+
|| String(note.body || '').toLowerCase().indexOf(filter) >= 0
|
|
5560
|
+
|| translate(noteKind(note.kind).label).toLowerCase().indexOf(filter) >= 0;
|
|
5561
|
+
|
|
5562
|
+
const flash = (text, kind) => showToast(text, kind);
|
|
5563
|
+
|
|
5564
|
+
const compose = () => {
|
|
5565
|
+
let ok = false;
|
|
5566
|
+
try {
|
|
5567
|
+
ok = props.onCompose() === true;
|
|
5568
|
+
} catch (_error) {
|
|
5569
|
+
ok = false;
|
|
5570
|
+
}
|
|
5571
|
+
if (ok && normalizeSettings(props.settings).noteKeepAfterDraft === false) {
|
|
5572
|
+
notesActions.clearSession(sessionId);
|
|
5573
|
+
}
|
|
5574
|
+
flash(ok ? translate('note.inserted') : translate('note.insertFailed'), ok ? 'ok' : 'error');
|
|
5575
|
+
};
|
|
5576
|
+
|
|
5577
|
+
const labelOfGroup = (group) => {
|
|
5578
|
+
const resolved = resolveGroup(group, categories, workspaceList);
|
|
5579
|
+
return resolved ? resolved.label : translate('row.noCategory');
|
|
5580
|
+
};
|
|
5581
|
+
|
|
5582
|
+
// The workspace this session belongs to leads the chooser; 常用 is the
|
|
5583
|
+
// fallback when the workspace family is hidden or unknown.
|
|
5584
|
+
const choices = captureChoices(categories, workspaceList, currentWorkspaceId, props.settings);
|
|
5585
|
+
const preferred = currentWorkspaceId && choices.some((entry) => entry.value === 'workspace:' + currentWorkspaceId)
|
|
5586
|
+
? 'workspace:' + currentWorkspaceId
|
|
5587
|
+
: BUILTIN_GROUP.oftenuse;
|
|
5588
|
+
const ordered = choices.some((entry) => entry.value === preferred)
|
|
5589
|
+
? [...choices.filter((entry) => entry.value === preferred), ...choices.filter((entry) => entry.value !== preferred)]
|
|
5590
|
+
: choices;
|
|
5591
|
+
|
|
5592
|
+
const promote = (note, group) => {
|
|
5593
|
+
poolActions.add({
|
|
5594
|
+
id: uid(),
|
|
5595
|
+
group,
|
|
5596
|
+
title: draftTitle(note.quote),
|
|
5597
|
+
// The prompt carries the quoted passage, so inserting it into the
|
|
5598
|
+
// composer later still has the original text (the title is only a label).
|
|
5599
|
+
body: composeNoteLine(note),
|
|
5600
|
+
images: [],
|
|
5601
|
+
createdAt: Date.now(),
|
|
5602
|
+
updatedAt: Date.now(),
|
|
5603
|
+
});
|
|
5604
|
+
if (normalizeSettings(props.settings).noteKeepAfterStore === false) {
|
|
5605
|
+
notesActions.remove(note.id);
|
|
5606
|
+
} else {
|
|
5607
|
+
// The record stays: the row keeps a "stored" marker so the note is not
|
|
5608
|
+
// silently lost from the conversation it belongs to.
|
|
5609
|
+
notesActions.patch(note.id, { promotedGroup: group, promotedAt: Date.now() });
|
|
5610
|
+
}
|
|
5611
|
+
flash(translate('note.stored', { group: labelOfGroup(group) }), 'ok');
|
|
5612
|
+
};
|
|
5613
|
+
|
|
5614
|
+
/** Compose the annotations into one prompt and file it in a group. */
|
|
5615
|
+
const storePrompt = (group) => {
|
|
5616
|
+
const text = composeNotesReply(list);
|
|
5617
|
+
poolActions.add({
|
|
5618
|
+
id: uid(),
|
|
5619
|
+
group,
|
|
5620
|
+
title: draftTitle(text),
|
|
5621
|
+
body: text,
|
|
5622
|
+
images: [],
|
|
5623
|
+
createdAt: Date.now(),
|
|
5624
|
+
updatedAt: Date.now(),
|
|
5625
|
+
});
|
|
5626
|
+
if (normalizeSettings(props.settings).noteKeepAfterStore === false) {
|
|
5627
|
+
notesActions.clearSession(sessionId);
|
|
5628
|
+
}
|
|
5629
|
+
flash(translate('note.composeStored', { group: labelOfGroup(group) }), 'ok');
|
|
5630
|
+
};
|
|
5631
|
+
|
|
5632
|
+
/** Open the group popup just under the button that asked for it. */
|
|
5633
|
+
const openPrompt = (target, event) => {
|
|
5634
|
+
const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
|
|
5635
|
+
? event.currentTarget.getBoundingClientRect()
|
|
5636
|
+
: null;
|
|
5637
|
+
notePrompt.set({
|
|
5638
|
+
open: true,
|
|
5639
|
+
target,
|
|
5640
|
+
choices: ordered,
|
|
5641
|
+
defaultValue: preferred,
|
|
5642
|
+
anchor: rect
|
|
5643
|
+
? { left: Math.round(rect.left), right: Math.round(rect.right), top: Math.round(rect.top), bottom: Math.round(rect.bottom) }
|
|
5644
|
+
: { left: Math.round((window.innerWidth || 0) / 2), right: Math.round((window.innerWidth || 0) / 2) + 40, top: 60, bottom: 90 },
|
|
5645
|
+
onPick: (group) => {
|
|
5646
|
+
closeNotePrompt();
|
|
5647
|
+
if (!group) return;
|
|
5648
|
+
if (target && target.kind === 'note' && target.note) promote(target.note, group);
|
|
5649
|
+
else storePrompt(group);
|
|
5650
|
+
},
|
|
5651
|
+
token: Date.now(),
|
|
5652
|
+
});
|
|
5653
|
+
};
|
|
5654
|
+
|
|
5655
|
+
/** Scroll the transcript to this note. */
|
|
5656
|
+
const locate = (note) => {
|
|
5657
|
+
const root = noteChatRoot(sessionId);
|
|
5658
|
+
const hit = root ? resolveNote(note, root) : null;
|
|
5659
|
+
if (!hit) {
|
|
5660
|
+
showNoteStatus(translate('note.locateFailed'), 'error');
|
|
5661
|
+
return;
|
|
5662
|
+
}
|
|
5663
|
+
const rect = hit.range.getBoundingClientRect();
|
|
5664
|
+
const box = root.getBoundingClientRect();
|
|
5665
|
+
if (rect.top < box.top + 40 || rect.bottom > box.bottom - 40) {
|
|
5666
|
+
root.scrollTop += rect.top - box.top - Math.min(120, box.height / 3);
|
|
5667
|
+
}
|
|
5668
|
+
noteFocus.set({ id: note.id, token: Date.now(), edit: false });
|
|
5669
|
+
};
|
|
5670
|
+
|
|
5671
|
+
/** Insert one note (as a one-line prompt) into the composer. */
|
|
5672
|
+
const insertNote = (note) => {
|
|
5673
|
+
let ok = false;
|
|
5674
|
+
try {
|
|
5675
|
+
ok = props.onInsertNote ? props.onInsertNote(note) === true : false;
|
|
5676
|
+
} catch (_error) {
|
|
5677
|
+
ok = false;
|
|
5678
|
+
}
|
|
5679
|
+
if (ok && normalizeSettings(props.settings).noteKeepAfterDraft === false) {
|
|
5680
|
+
notesActions.remove(note.id);
|
|
5681
|
+
}
|
|
5682
|
+
flash(ok ? translate('note.inserted') : translate('note.insertFailed'), ok ? 'ok' : 'error');
|
|
5683
|
+
};
|
|
5684
|
+
|
|
5685
|
+
return h(
|
|
5686
|
+
'div',
|
|
5687
|
+
{ className: 'pp-notes pp-notes-embedded' },
|
|
5688
|
+
h('style', { key: 'css' }, NOTES_CSS),
|
|
5689
|
+
props.hideActions !== true || list.some((note) => (note.dx || 0) !== 0 || (note.dy || 0) !== 0)
|
|
5690
|
+
? h(
|
|
5691
|
+
'div',
|
|
5692
|
+
{ className: 'pp-notes-head' },
|
|
5693
|
+
h('span', { className: 'pp-notes-grow' }),
|
|
5694
|
+
props.hideActions !== true
|
|
5695
|
+
? [
|
|
5696
|
+
h(
|
|
5697
|
+
'button',
|
|
5698
|
+
{ key: 'compose-store', type: 'button', className: 'pp-note-btn pp-note-btn-primary', onClick: (event) => openPrompt({ kind: 'reply' }, event) },
|
|
5699
|
+
translate('note.composeStore'),
|
|
5700
|
+
),
|
|
5701
|
+
h('button', { key: 'compose', type: 'button', className: 'pp-note-btn', onClick: compose }, translate('note.compose')),
|
|
5702
|
+
]
|
|
5703
|
+
: null,
|
|
5704
|
+
list.some((note) => (note.dx || 0) !== 0 || (note.dy || 0) !== 0)
|
|
5705
|
+
? h(
|
|
5706
|
+
'button',
|
|
5707
|
+
{ key: 'reset', type: 'button', className: 'pp-note-link', onClick: () => notesActions.resetPositions(sessionId) },
|
|
5708
|
+
translate('note.reset'),
|
|
5709
|
+
)
|
|
5710
|
+
: null,
|
|
5711
|
+
)
|
|
5712
|
+
: null,
|
|
5713
|
+
h(
|
|
5714
|
+
'div',
|
|
5715
|
+
{ className: 'pp-notes-list' },
|
|
5716
|
+
list.map((note, index) => {
|
|
5717
|
+
if (!matches(note)) return null;
|
|
5718
|
+
const meta = noteKind(note.kind);
|
|
5719
|
+
return h(
|
|
5720
|
+
'div',
|
|
5721
|
+
{
|
|
5722
|
+
className: 'pp-notes-row',
|
|
5723
|
+
key: note.id,
|
|
5724
|
+
'data-promoted': note.promotedGroup ? 'true' : undefined,
|
|
5725
|
+
},
|
|
5726
|
+
h(
|
|
5727
|
+
'button',
|
|
5728
|
+
{
|
|
5729
|
+
type: 'button',
|
|
5730
|
+
className: 'pp-note-icon pp-note-insert',
|
|
5731
|
+
title: translate('note.insert'),
|
|
5732
|
+
'aria-label': translate('note.insert'),
|
|
5733
|
+
onClick: () => insertNote(note),
|
|
5734
|
+
},
|
|
5735
|
+
h(NoteActionIcon, { kind: 'insert' }),
|
|
5736
|
+
),
|
|
5737
|
+
h(
|
|
5738
|
+
'button',
|
|
5739
|
+
{
|
|
5740
|
+
type: 'button',
|
|
5741
|
+
className: 'pp-note-icon pp-note-locate',
|
|
5742
|
+
title: translate('note.locate'),
|
|
5743
|
+
'aria-label': translate('note.locate'),
|
|
5744
|
+
onClick: () => locate(note),
|
|
5745
|
+
},
|
|
5746
|
+
h(NoteActionIcon, { kind: 'locate' }),
|
|
5747
|
+
),
|
|
5748
|
+
h('span', { className: 'pp-notes-n' }, String(index + 1)),
|
|
5749
|
+
h(
|
|
5750
|
+
'div',
|
|
5751
|
+
{ className: 'pp-notes-main' },
|
|
5752
|
+
h(
|
|
5753
|
+
'div',
|
|
5754
|
+
{ className: 'pp-notes-quote', title: note.quote },
|
|
5755
|
+
h('span', { className: 'pp-notes-kind', 'data-kind': meta.id, title: translate(meta.label) }, meta.icon),
|
|
5756
|
+
h('span', { className: 'pp-notes-quote-text' }, noteQuoteText(note.quote)),
|
|
5757
|
+
note.promotedGroup
|
|
5758
|
+
? h('span', { className: 'pp-notes-tag' }, translate('note.stored', { group: labelOfGroup(note.promotedGroup) }))
|
|
5759
|
+
: null,
|
|
5760
|
+
),
|
|
5761
|
+
h('div', { className: 'pp-notes-text' }, note.body || translate(meta.label)),
|
|
5762
|
+
),
|
|
5763
|
+
h(
|
|
5764
|
+
'button',
|
|
5765
|
+
{
|
|
5766
|
+
type: 'button',
|
|
5767
|
+
className: 'pp-note-icon',
|
|
5768
|
+
title: translate('note.store'),
|
|
5769
|
+
'aria-label': translate('note.store'),
|
|
5770
|
+
onClick: (event) => openPrompt({ kind: 'note', note }, event),
|
|
5771
|
+
},
|
|
5772
|
+
h(NoteActionIcon, { kind: 'store' }),
|
|
5773
|
+
),
|
|
5774
|
+
h(
|
|
5775
|
+
'button',
|
|
5776
|
+
{
|
|
5777
|
+
type: 'button',
|
|
5778
|
+
className: 'pp-note-icon pp-note-link-danger',
|
|
5779
|
+
title: translate('note.delete'),
|
|
5780
|
+
'aria-label': translate('note.delete'),
|
|
5781
|
+
onClick: (event) => openNoteConfirm(() => notesActions.remove(note.id), event),
|
|
5782
|
+
},
|
|
5783
|
+
h(NoteActionIcon, { kind: 'delete' }),
|
|
5784
|
+
),
|
|
5785
|
+
);
|
|
5786
|
+
}),
|
|
5787
|
+
),
|
|
5788
|
+
list.length === 0
|
|
5789
|
+
? h('div', { key: 'intro', className: 'pp-notes-empty' }, translate('note.emptyIntro'))
|
|
5790
|
+
: filter && !list.some(matches)
|
|
5791
|
+
? h('div', { key: 'empty', className: 'pp-notes-empty' }, translate('note.empty'))
|
|
5792
|
+
: null,
|
|
5793
|
+
);
|
|
5794
|
+
}
|
|
5795
|
+
|
|
5796
|
+
// --------------------------------------------------- conversation selection
|
|
5797
|
+
/**
|
|
5798
|
+
* Right-click destinations for text selected in the conversation. The host
|
|
5799
|
+
* opens this surface at the pointer; the top level keeps Copy (the menu
|
|
5800
|
+
* replaces the browser's own) and one pool entry whose submenu lists the
|
|
5801
|
+
* groups on show. Picking a group stores the selection there, and the group
|
|
5802
|
+
* used last time leads that submenu. The surface only exists while the Chat
|
|
5803
|
+
* view is mounted, and a selection lost between the gesture and this mount
|
|
5804
|
+
* leaves it with nothing to offer.
|
|
5805
|
+
*/
|
|
5806
|
+
function SelectionMenu(props) {
|
|
5807
|
+
useLocaleTick();
|
|
5808
|
+
const state = usePoolState();
|
|
5809
|
+
const published = useWorkspaceDir();
|
|
5810
|
+
// The Chat view can read the workspace roster itself; the module store is
|
|
5811
|
+
// the fallback for a host that does not hand `useWorkspaces` to this seat.
|
|
5812
|
+
const snapshot = typeof props.useWorkspaces === 'function' ? props.useWorkspaces(selectAllInput) : undefined;
|
|
5813
|
+
const workspaces = snapshot ? workspaceEntriesOf(snapshot) : published.items || [];
|
|
5814
|
+
const currentWorkspaceId = snapshot ? currentWorkspaceOf(snapshot, props.sessionId) : published.currentId || '';
|
|
5815
|
+
// The gesture captured the text before this surface mounted; keeping it in
|
|
5816
|
+
// state means a collapsed selection cannot empty the menu mid-click.
|
|
5817
|
+
const [body] = useState(() => {
|
|
5818
|
+
const text = typeof props.readText === 'function' ? props.readText() : null;
|
|
5819
|
+
return typeof text === 'string' ? text.replace(/\r\n?/g, '\n').trim() : '';
|
|
5820
|
+
});
|
|
5821
|
+
const [done, setDone] = useState(null);
|
|
5822
|
+
// The group list lives one level down; Copy stays at the top.
|
|
5823
|
+
const [submenu, setSubmenu] = useState(false);
|
|
5824
|
+
// Annotating needs the assistant row and its text, captured while the
|
|
5825
|
+
// selection still owns the DOM.
|
|
5826
|
+
const [anchor] = useState(() => captureNoteAnchor(props.sessionId));
|
|
5827
|
+
const timer = useRef(0);
|
|
5828
|
+
const dismiss = typeof props.dismiss === 'function' ? props.dismiss : () => {};
|
|
5829
|
+
|
|
5830
|
+
useEffect(() => () => window.clearTimeout(timer.current), []);
|
|
5831
|
+
useEffect(() => {
|
|
5832
|
+
// The selection was gone before the surface mounted; nothing to offer.
|
|
5833
|
+
if (!body) dismiss();
|
|
5834
|
+
}, [body, dismiss]);
|
|
5835
|
+
|
|
5836
|
+
if (!body) return null;
|
|
5837
|
+
|
|
5838
|
+
const choices = captureChoices(state.categories, workspaces, currentWorkspaceId, state.settings);
|
|
5839
|
+
const last = state.settings && state.settings.lastCaptureGroup;
|
|
5840
|
+
const remembered = choices.find((choice) => choice.value === last) || null;
|
|
5841
|
+
const ordered = remembered ? [remembered, ...choices.filter((choice) => choice !== remembered)] : choices;
|
|
5842
|
+
const counts = {};
|
|
5843
|
+
for (const item of state.items) {
|
|
5844
|
+
const group = groupOf(item);
|
|
5845
|
+
counts[group] = (counts[group] || 0) + 1;
|
|
5846
|
+
}
|
|
5847
|
+
|
|
5848
|
+
const pick = (choice) => {
|
|
5849
|
+
if (done) return;
|
|
5850
|
+
const now = Date.now();
|
|
5851
|
+
poolActions.add({
|
|
5852
|
+
id: uid(),
|
|
5853
|
+
group: choice.value,
|
|
5854
|
+
title: draftTitle(body),
|
|
5855
|
+
body,
|
|
5856
|
+
images: [],
|
|
5857
|
+
createdAt: now,
|
|
5858
|
+
updatedAt: now,
|
|
5859
|
+
});
|
|
5860
|
+
// Remembering the destination makes the next right-click a single pick.
|
|
5861
|
+
poolActions.setSetting('lastCaptureGroup', choice.value);
|
|
5862
|
+
// The write can fail on a full or blocked store; say so instead of
|
|
5863
|
+
// claiming a save the pool would lose on reload.
|
|
5864
|
+
const failed = storageState.get().failed === true;
|
|
5865
|
+
setDone({ kind: failed ? 'failed' : 'saved', label: choice.label });
|
|
5866
|
+
timer.current = window.setTimeout(() => dismiss(), failed ? 2600 : 900);
|
|
5867
|
+
};
|
|
5868
|
+
|
|
5869
|
+
/**
|
|
5870
|
+
* The menu replaces the browser's own menu, so it has to keep Copy. The
|
|
5871
|
+
* selection is already captured, and the click still counts as a gesture.
|
|
5872
|
+
*/
|
|
5873
|
+
const copySelection = () => {
|
|
5874
|
+
if (done) return;
|
|
5875
|
+
const copied = copyText(body);
|
|
5876
|
+
setDone({ kind: copied ? 'copied' : 'copyFailed' });
|
|
5877
|
+
// A failed copy stays up so the shortcut hint can be read and used.
|
|
5878
|
+
if (copied) timer.current = window.setTimeout(() => dismiss(), 900);
|
|
5879
|
+
};
|
|
5880
|
+
|
|
5881
|
+
/** Open the destination submenu; a click serves touch, hover serves mouse. */
|
|
5882
|
+
const openGroups = () => {
|
|
5883
|
+
if (done !== null) return;
|
|
5884
|
+
setSubmenu(true);
|
|
5885
|
+
};
|
|
5886
|
+
|
|
5887
|
+
/** Hand the captured anchor to the overlay, which opens its editor. */
|
|
5888
|
+
const startNote = () => {
|
|
5889
|
+
if (!anchor) return;
|
|
5890
|
+
noteDraft.set({ anchor, sessionId: props.sessionId || '', token: Date.now() });
|
|
5891
|
+
dismiss();
|
|
5892
|
+
};
|
|
5893
|
+
|
|
5894
|
+
const error = done !== null && (done.kind === 'failed' || done.kind === 'copyFailed');
|
|
5895
|
+
const shortcut = /Mac|iPhone|iPad/.test(typeof navigator === 'undefined' ? '' : String(navigator.userAgent || '')) ? '⌘C' : 'Ctrl+C';
|
|
5896
|
+
const doneText = done === null
|
|
5897
|
+
? ''
|
|
5898
|
+
: done.kind === 'saved'
|
|
5899
|
+
? translate('menu.saved', { group: done.label })
|
|
3813
5900
|
: done.kind === 'copied'
|
|
3814
5901
|
? translate('menu.copied')
|
|
3815
5902
|
: done.kind === 'copyFailed'
|
|
@@ -3855,7 +5942,24 @@ window.__ModuleLoader__.load({
|
|
|
3855
5942
|
h('span', { key: 'name', className: 'pp-selname' }, translate('menu.copy')),
|
|
3856
5943
|
h('span', { key: 'key', className: 'pp-selkey' }, shortcut),
|
|
3857
5944
|
),
|
|
3858
|
-
h(
|
|
5945
|
+
h(
|
|
5946
|
+
'div',
|
|
5947
|
+
{ key: 'poolgroup', className: 'pp-selgroup' },
|
|
5948
|
+
h('div', { key: 'label', className: 'pp-selgroup-label' }, h(PromptPoolIcon, { key: 'icon', size: 12 }), translate('menu.group')),
|
|
5949
|
+
anchor
|
|
5950
|
+
? h(
|
|
5951
|
+
'button',
|
|
5952
|
+
{
|
|
5953
|
+
key: 'note',
|
|
5954
|
+
type: 'button',
|
|
5955
|
+
role: 'menuitem',
|
|
5956
|
+
className: 'pp-selrow',
|
|
5957
|
+
onClick: startNote,
|
|
5958
|
+
onPointerEnter: () => setSubmenu(false),
|
|
5959
|
+
},
|
|
5960
|
+
h('span', { key: 'name', className: 'pp-selname' }, translate('note.add')),
|
|
5961
|
+
)
|
|
5962
|
+
: null,
|
|
3859
5963
|
h(
|
|
3860
5964
|
'button',
|
|
3861
5965
|
{
|
|
@@ -3868,14 +5972,15 @@ window.__ModuleLoader__.load({
|
|
|
3868
5972
|
onClick: openGroups,
|
|
3869
5973
|
onPointerEnter: openGroups,
|
|
3870
5974
|
},
|
|
3871
|
-
h('span', { key: 'name', className: 'pp-selname' }, translate('menu.
|
|
5975
|
+
h('span', { key: 'name', className: 'pp-selname' }, translate('menu.pool')),
|
|
3872
5976
|
h('span', { key: 'chev', className: 'pp-selchev', 'aria-hidden': true }, '▸'),
|
|
3873
5977
|
),
|
|
5978
|
+
),
|
|
3874
5979
|
),
|
|
3875
5980
|
submenu
|
|
3876
5981
|
? h(
|
|
3877
5982
|
'div',
|
|
3878
|
-
{ key: 'groups', className: 'pp-selpanel', role: 'menu', 'aria-label': translate('menu.
|
|
5983
|
+
{ key: 'groups', className: 'pp-selpanel', role: 'menu', 'aria-label': translate('menu.pool') },
|
|
3879
5984
|
h(
|
|
3880
5985
|
'div',
|
|
3881
5986
|
{ key: 'list', className: 'pp-sellist' },
|
|
@@ -3918,13 +6023,22 @@ window.__ModuleLoader__.load({
|
|
|
3918
6023
|
const storage = useStorageState();
|
|
3919
6024
|
const releaseInfo = useReleaseState();
|
|
3920
6025
|
const view = useUiState();
|
|
6026
|
+
const noteBar = useNoteStatus();
|
|
3921
6027
|
const workspaces = useWorkspaceDir();
|
|
3922
6028
|
const sessionHint = useSessionDir().sessionId;
|
|
6029
|
+
const notesState = useNotesState();
|
|
6030
|
+
const notesSessionId = typeof props.sessionId === 'string' ? props.sessionId : '';
|
|
6031
|
+
const notesList = notesState.items
|
|
6032
|
+
.filter((note) => note.sessionId === notesSessionId)
|
|
6033
|
+
.sort((left, right) => (left.order - right.order) || (left.createdAt - right.createdAt));
|
|
3923
6034
|
|
|
3924
6035
|
// This view can read the workspace roster; publish it for both views.
|
|
3925
6036
|
const wsSnapshot = typeof props.useWorkspaces === 'function' ? props.useWorkspaces(selectAllInput) : undefined;
|
|
3926
6037
|
useEffect(() => {
|
|
3927
6038
|
sessionDir.set({ sessionId: props.sessionId || '' });
|
|
6039
|
+
// The overlay is root-scoped; this session-scoped seat tells it which
|
|
6040
|
+
// transcript the annotation cards belong to.
|
|
6041
|
+
chatView.set({ sessionId: props.sessionId || '' });
|
|
3928
6042
|
}, [props.sessionId]);
|
|
3929
6043
|
const wsEntries = workspaceEntriesOf(wsSnapshot);
|
|
3930
6044
|
const wsCurrent = currentWorkspaceOf(wsSnapshot, props.sessionId);
|
|
@@ -4558,11 +6672,76 @@ window.__ModuleLoader__.load({
|
|
|
4558
6672
|
|
|
4559
6673
|
// The sidebar tab has no composer access, so it posts commands here.
|
|
4560
6674
|
const bridgeRef = useRef(null);
|
|
4561
|
-
|
|
6675
|
+
/** The annotations tab's reply: numbered, each note quotes its passage. */
|
|
6676
|
+
/** Write a block of text into the composer through the host's actions. */
|
|
6677
|
+
const insertComposerText = (text) => {
|
|
6678
|
+
const actions = props.inputActions;
|
|
6679
|
+
if (!actions || typeof actions.insertText !== 'function') return false;
|
|
6680
|
+
try {
|
|
6681
|
+
const span = typeof actions.captureInsertion === 'function' ? actions.captureInsertion() : undefined;
|
|
6682
|
+
return actions.insertText(text, span) === true;
|
|
6683
|
+
} catch (_error) {
|
|
6684
|
+
return false;
|
|
6685
|
+
}
|
|
6686
|
+
};
|
|
6687
|
+
const composeSessionNotes = () => insertComposerText(composeNotesReply(notesList));
|
|
6688
|
+
const insertNoteText = (note) => insertComposerText(composeNoteLine(note));
|
|
6689
|
+
|
|
6690
|
+
/** Store the session's annotations as one prompt, from the panel header. */
|
|
6691
|
+
const storeNotesPrompt = (event) => {
|
|
6692
|
+
const choices = captureChoices(state.categories, workspaces.items, currentWorkspaceId, state.settings);
|
|
6693
|
+
const preferred = currentWorkspaceId && choices.some((entry) => entry.value === 'workspace:' + currentWorkspaceId)
|
|
6694
|
+
? 'workspace:' + currentWorkspaceId
|
|
6695
|
+
: BUILTIN_GROUP.oftenuse;
|
|
6696
|
+
const ordered = choices.some((entry) => entry.value === preferred)
|
|
6697
|
+
? [...choices.filter((entry) => entry.value === preferred), ...choices.filter((entry) => entry.value !== preferred)]
|
|
6698
|
+
: choices;
|
|
6699
|
+
const rect = event && event.currentTarget && event.currentTarget.getBoundingClientRect
|
|
6700
|
+
? event.currentTarget.getBoundingClientRect()
|
|
6701
|
+
: null;
|
|
6702
|
+
notePrompt.set({
|
|
6703
|
+
open: true,
|
|
6704
|
+
target: { kind: 'reply' },
|
|
6705
|
+
choices: ordered,
|
|
6706
|
+
defaultValue: preferred,
|
|
6707
|
+
anchor: rect
|
|
6708
|
+
? { left: Math.round(rect.left), right: Math.round(rect.right), top: Math.round(rect.top), bottom: Math.round(rect.bottom) }
|
|
6709
|
+
: { left: 120, right: 160, top: 60, bottom: 90 },
|
|
6710
|
+
token: Date.now(),
|
|
6711
|
+
onPick: (group) => {
|
|
6712
|
+
closeNotePrompt();
|
|
6713
|
+
if (!group) return;
|
|
6714
|
+
const text = composeNotesReply(notesList);
|
|
6715
|
+
poolActions.add({
|
|
6716
|
+
id: uid(),
|
|
6717
|
+
group,
|
|
6718
|
+
title: draftTitle(text),
|
|
6719
|
+
body: text,
|
|
6720
|
+
images: [],
|
|
6721
|
+
createdAt: Date.now(),
|
|
6722
|
+
updatedAt: Date.now(),
|
|
6723
|
+
});
|
|
6724
|
+
if (normalizeSettings(state.settings).noteKeepAfterStore === false) {
|
|
6725
|
+
notesActions.clearSession(notesSessionId);
|
|
6726
|
+
}
|
|
6727
|
+
const resolved = resolveGroup(group, state.categories, workspaces.items);
|
|
6728
|
+
showToast(translate('note.composeStored', { group: resolved ? resolved.label : translate('row.noCategory') }), 'ok');
|
|
6729
|
+
},
|
|
6730
|
+
});
|
|
6731
|
+
};
|
|
6732
|
+
|
|
6733
|
+
bridgeRef.current = { insert: insertItem, release, capture: captureDraft, composeNotes: composeSessionNotes, insertText: insertComposerText };
|
|
4562
6734
|
useEffect(() => {
|
|
4563
6735
|
return bridge.listen((command) => {
|
|
4564
6736
|
const api = bridgeRef.current;
|
|
4565
6737
|
if (!api || !command) return { ok: false, reason: 'unavailable' };
|
|
6738
|
+
if (command.type === 'compose-notes') {
|
|
6739
|
+
return { ok: api.composeNotes() === true };
|
|
6740
|
+
}
|
|
6741
|
+
if (command.type === 'insert-text') {
|
|
6742
|
+
if (typeof command.text !== 'string') return { ok: false, reason: 'bad-command' };
|
|
6743
|
+
return { ok: api.insertText(command.text) === true };
|
|
6744
|
+
}
|
|
4566
6745
|
if (command.type === 'insert') {
|
|
4567
6746
|
if (typeof command.text !== 'string') return { ok: false, reason: 'bad-command' };
|
|
4568
6747
|
return Promise.resolve(api.insert({ body: command.text, images: normalizeImages(command.images) }))
|
|
@@ -4594,11 +6773,31 @@ window.__ModuleLoader__.load({
|
|
|
4594
6773
|
});
|
|
4595
6774
|
}, []);
|
|
4596
6775
|
|
|
6776
|
+
// The panel lands on the Settings default each time it opens. The tab list
|
|
6777
|
+
// is built here because render-time tabs are computed after this hook.
|
|
6778
|
+
const wasOpenRef = useRef(false);
|
|
6779
|
+
useEffect(() => {
|
|
6780
|
+
const open = view.open === true;
|
|
6781
|
+
if (open && !wasOpenRef.current) {
|
|
6782
|
+
const pref = normalizeSettings(state.settings).defaultTab;
|
|
6783
|
+
const baseTabs = buildTabs(state.categories, workspaces.items, state.settings, currentWorkspaceId);
|
|
6784
|
+
const resolved = resolveDefaultTab(pref, baseTabs, currentWorkspaceId, notesList.length > 0);
|
|
6785
|
+
if (resolved) setTab(resolved);
|
|
6786
|
+
}
|
|
6787
|
+
wasOpenRef.current = open;
|
|
6788
|
+
}, [view.open]);
|
|
6789
|
+
|
|
4597
6790
|
if (!view.open) return null;
|
|
4598
6791
|
|
|
4599
6792
|
const panelCount = state.items.length;
|
|
4600
6793
|
const captureGroups = captureChoices(state.categories, workspaces.items, currentWorkspaceId, state.settings);
|
|
4601
|
-
const
|
|
6794
|
+
const baseTabs = buildTabs(state.categories, workspaces.items, state.settings, currentWorkspaceId);
|
|
6795
|
+
// The annotation tab is always present, so the feature stays discoverable.
|
|
6796
|
+
const tabs = [{ id: 'notes', label: translate('note.title'), group: 'notes' }, ...baseTabs];
|
|
6797
|
+
const tabCounts = {
|
|
6798
|
+
...tabCountsOf(state.items),
|
|
6799
|
+
notes: notesList.length,
|
|
6800
|
+
};
|
|
4602
6801
|
|
|
4603
6802
|
// A folded family renders its groups as chips inside one tab.
|
|
4604
6803
|
const customGroups = state.categories.map((category) => ({ id: 'custom:' + category.id, name: category.name }));
|
|
@@ -4698,18 +6897,29 @@ window.__ModuleLoader__.load({
|
|
|
4698
6897
|
h(
|
|
4699
6898
|
'div',
|
|
4700
6899
|
{ className: 'pp-page-head' },
|
|
4701
|
-
h(
|
|
4702
|
-
|
|
4703
|
-
|
|
6900
|
+
h(
|
|
6901
|
+
'span',
|
|
6902
|
+
{ className: 'pp-page-title pp-panel-title' },
|
|
6903
|
+
h(PromptPoolIcon, { key: 'icon', size: 16 }),
|
|
6904
|
+
translate('panel.title'),
|
|
6905
|
+
),
|
|
4704
6906
|
h('input', {
|
|
6907
|
+
key: 'search',
|
|
4705
6908
|
className: 'pp-search',
|
|
4706
6909
|
value: query,
|
|
4707
6910
|
placeholder: translate('page.search'),
|
|
4708
6911
|
'aria-label': translate('page.search'),
|
|
4709
6912
|
onChange: (event) => setQuery(event.target.value),
|
|
4710
6913
|
}),
|
|
4711
|
-
|
|
4712
|
-
|
|
6914
|
+
tab === 'notes'
|
|
6915
|
+
? [
|
|
6916
|
+
h('button', { key: 'store', type: 'button', className: 'pp-mini', title: translate('note.composeStoreHint'), onClick: storeNotesPrompt }, translate('note.composeStore')),
|
|
6917
|
+
h('button', { key: 'draft', type: 'button', className: 'pp-mini', title: translate('note.composeHint'), onClick: composeSessionNotes }, translate('note.compose')),
|
|
6918
|
+
]
|
|
6919
|
+
: [
|
|
6920
|
+
h('button', { key: 'new', type: 'button', className: 'pp-mini', onClick: newItem }, '+ ', translate('page.new')),
|
|
6921
|
+
h('button', { key: 'capture', type: 'button', className: 'pp-mini', title: translate('panel.captureHint'), onClick: openCapture }, translate('panel.capture')),
|
|
6922
|
+
],
|
|
4713
6923
|
h(SettingsButton, { active: settingsOpen, onClick: () => setSettingsOpen(!settingsOpen) }),
|
|
4714
6924
|
h(IconButton, {
|
|
4715
6925
|
name: 'pin',
|
|
@@ -4727,7 +6937,7 @@ window.__ModuleLoader__.load({
|
|
|
4727
6937
|
'div',
|
|
4728
6938
|
{ className: 'pp-bar', style: { padding: '8px 12px 2px' } },
|
|
4729
6939
|
h(TabBar, {
|
|
4730
|
-
tabs
|
|
6940
|
+
tabs,
|
|
4731
6941
|
counts: tabCounts,
|
|
4732
6942
|
active: tab,
|
|
4733
6943
|
...tabHandlers((next) => {
|
|
@@ -4791,7 +7001,20 @@ window.__ModuleLoader__.load({
|
|
|
4791
7001
|
{ className: 'pp-list', ref: listRef },
|
|
4792
7002
|
settingsOpen
|
|
4793
7003
|
? h(PromptPoolSettings, { currentWorkspaceId })
|
|
4794
|
-
:
|
|
7004
|
+
: tab === 'notes'
|
|
7005
|
+
? h(NotesView, {
|
|
7006
|
+
notes: notesList,
|
|
7007
|
+
sessionId: notesSessionId,
|
|
7008
|
+
onCompose: composeSessionNotes,
|
|
7009
|
+
onInsertNote: insertNoteText,
|
|
7010
|
+
hideActions: true,
|
|
7011
|
+
filter: query,
|
|
7012
|
+
categories: state.categories,
|
|
7013
|
+
workspaces: workspaces.items,
|
|
7014
|
+
currentWorkspaceId,
|
|
7015
|
+
settings: state.settings,
|
|
7016
|
+
})
|
|
7017
|
+
: nestedView
|
|
4795
7018
|
? renderWorkspacePanes({
|
|
4796
7019
|
rail: nestedView.rail,
|
|
4797
7020
|
items: nestedView.scoped,
|
|
@@ -4820,6 +7043,9 @@ window.__ModuleLoader__.load({
|
|
|
4820
7043
|
h(
|
|
4821
7044
|
'div',
|
|
4822
7045
|
{ className: 'pp-panel-dock' },
|
|
7046
|
+
tab === 'notes' && noteBar.text
|
|
7047
|
+
? h('div', { className: 'pp-notes-bar', 'data-kind': noteBar.kind, role: 'status' }, noteBar.text)
|
|
7048
|
+
: null,
|
|
4823
7049
|
notice
|
|
4824
7050
|
? h(
|
|
4825
7051
|
'div',
|
|
@@ -4840,7 +7066,7 @@ window.__ModuleLoader__.load({
|
|
|
4840
7066
|
: null,
|
|
4841
7067
|
)
|
|
4842
7068
|
: null,
|
|
4843
|
-
!settingsOpen
|
|
7069
|
+
!settingsOpen && tab !== 'notes'
|
|
4844
7070
|
? renderTrayCard({
|
|
4845
7071
|
entries: tray,
|
|
4846
7072
|
queuePending: queue.length,
|
|
@@ -4930,10 +7156,20 @@ window.__ModuleLoader__.load({
|
|
|
4930
7156
|
'.pp-x:hover{background:var(--pp-hover);color:var(--pp-ink)}' +
|
|
4931
7157
|
'.pp-bar{display:flex;align-items:center;gap:6px;padding:0 12px 8px;flex-wrap:wrap}' +
|
|
4932
7158
|
'.pp-tab{height:24px;padding:0 9px;border-radius:7px;border:1px solid transparent;background:transparent;color:var(--pp-ink-2);font:inherit;font-size:12px;cursor:pointer}' +
|
|
7159
|
+
'.pp-tab:not([data-active="true"]){color:color-mix(in srgb,var(--pp-accent) 78%,var(--pp-ink-2))}' +
|
|
7160
|
+
'.pp-tab[data-group="notes"]:not([data-active="true"]){color:#8a6200}' +
|
|
4933
7161
|
'.pp-tab:hover{background:var(--pp-hover)}' +
|
|
4934
7162
|
'.pp-tab[data-active="true"]{border-color:var(--pp-accent);background:var(--pp-accent-soft);color:var(--pp-accent);font-weight:600}' +
|
|
7163
|
+
'.pp-tab[data-group="notes"][data-active="true"]{border-color:rgba(232,176,40,.9);background:rgba(232,176,40,.2);color:#9a6b00}' +
|
|
7164
|
+
'.pp-tab[data-group="notes"] .pp-tab-count{background:rgba(232,176,40,.22);color:#8a6200}' +
|
|
4935
7165
|
'.pp-tab-count{margin-left:5px;padding:0 5px;vertical-align:1px;border-radius:999px;background:color-mix(in srgb, currentColor 12%, transparent);color:inherit;font-size:10px;font-weight:600;line-height:16px;height:16px;display:inline-flex;align-items:center}' +
|
|
7166
|
+
'.pp-tab:not([data-group="notes"]) .pp-tab-count{background:color-mix(in srgb,var(--pp-accent) 12%,transparent);color:var(--pp-accent)}' +
|
|
4936
7167
|
'.pp-tab-add{padding:0 7px;color:var(--pp-ink-2)}' +
|
|
7168
|
+
'.pp-select{height:26px;min-width:170px;max-width:100%;padding:0 8px;border:1px solid var(--pp-line);border-radius:7px;background:var(--pp-surface);color:var(--pp-ink);font:inherit;font-size:12px}' +
|
|
7169
|
+
'.pp-set-intro{white-space:pre-line}' +
|
|
7170
|
+
'.pp-set-radios{display:flex;flex-direction:column;gap:4px;padding:2px 0 4px}' +
|
|
7171
|
+
'.pp-set-radio-row{display:flex;align-items:center;gap:10px}' +
|
|
7172
|
+
'.pp-set-radio{display:inline-flex;align-items:center;gap:6px;cursor:pointer}' +
|
|
4937
7173
|
'.pp-tab-addwrap{display:inline-flex;align-items:center}' +
|
|
4938
7174
|
'.pp-tab-sep{flex:none;width:1px;height:16px;margin:0 7px;background:color-mix(in srgb, var(--pp-ink-2) 45%, transparent)}' +
|
|
4939
7175
|
'.pp-tab-x{margin-left:4px;padding:0 2px;border-radius:4px;font-size:11px;line-height:1;color:var(--pp-ink-2);cursor:pointer}' +
|
|
@@ -4959,6 +7195,7 @@ window.__ModuleLoader__.load({
|
|
|
4959
7195
|
'.pp-page{position:relative;display:flex;flex-direction:column;height:100%;min-height:0;background:var(--dsw-alias-bg-base);color:var(--pp-ink);font-size:13px;line-height:1.5}' +
|
|
4960
7196
|
'.pp-page-head{display:flex;align-items:center;gap:8px;padding:12px 12px 8px;border-bottom:1px solid var(--pp-line);flex-wrap:wrap}' +
|
|
4961
7197
|
'.pp-page-title{font-size:14px;font-weight:600}' +
|
|
7198
|
+
'.pp-panel-title{display:inline-flex;align-items:center;gap:6px;flex:none;margin-right:2px}' +
|
|
4962
7199
|
'.pp-page-sub{color:var(--pp-ink-2);font-size:12px}' +
|
|
4963
7200
|
'.pp-search{height:26px;flex:1;min-width:120px;border:1px solid var(--pp-line);border-radius:8px;background:var(--pp-surface);color:inherit;font:inherit;font-size:12px;padding:0 9px;outline:none}' +
|
|
4964
7201
|
'.pp-search:focus{border-color:var(--pp-accent)}' +
|
|
@@ -4988,6 +7225,8 @@ window.__ModuleLoader__.load({
|
|
|
4988
7225
|
'.pp-set-ws-tag{margin-left:6px;padding:0 5px;border-radius:5px;background:var(--pp-accent-soft);color:var(--pp-accent);font-size:10px}' +
|
|
4989
7226
|
'.pp-set-ws-path{margin-left:auto;color:var(--pp-ink-2);font-size:11px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:340px}' +
|
|
4990
7227
|
'.pp-set-label{font-size:12px;color:var(--pp-ink-2);margin:2px 0 4px}' +
|
|
7228
|
+
'.pp-set-note{margin-right:auto;padding:0;line-height:1.4}' +
|
|
7229
|
+
'.pp-set-actions{display:flex;align-items:center;justify-content:flex-end;gap:8px;margin-top:8px}' +
|
|
4991
7230
|
'.pp-set-card{padding:10px 12px;border:1px solid var(--pp-line-2);border-radius:10px;background:var(--pp-surface);box-shadow:0 1px 3px rgba(0,0,0,.08)}' +
|
|
4992
7231
|
'.pp-set-card .pp-set-label{margin:0 0 6px;font-size:12px;font-weight:600;color:var(--pp-ink)}' +
|
|
4993
7232
|
'.pp-set-card .pp-set-row{padding:3px 0}' +
|
|
@@ -5024,7 +7263,7 @@ window.__ModuleLoader__.load({
|
|
|
5024
7263
|
'.pp-page-item:hover .pp-actions{opacity:1}' +
|
|
5025
7264
|
'.pp-empty{padding:22px 16px;color:var(--pp-ink-2);text-align:center;font-size:12px}' +
|
|
5026
7265
|
'.pp-row{display:flex;align-items:flex-start;gap:8px;padding:7px 8px;border-radius:8px}' +
|
|
5027
|
-
'.pp-row:hover{background:var(--pp-
|
|
7266
|
+
'.pp-row:hover{background:color-mix(in srgb,var(--pp-accent) 10%,transparent)}' +
|
|
5028
7267
|
'.pp-toggle{width:26px;height:26px;flex:none;margin-top:-1px;border:0;border-radius:6px;background:transparent;color:var(--pp-ink-2);cursor:pointer;display:inline-flex;align-items:center;justify-content:center;padding:0}' +
|
|
5029
7268
|
'.pp-toggle:hover{background:var(--pp-hover);color:var(--pp-ink)}' +
|
|
5030
7269
|
'.pp-toggle[data-selected="true"]{color:var(--pp-accent)}' +
|
|
@@ -5097,6 +7336,8 @@ window.__ModuleLoader__.load({
|
|
|
5097
7336
|
'.pp-status[data-kind="error"]{color:var(--pp-danger)}' +
|
|
5098
7337
|
'.pp-status[data-kind="ok"]{color:var(--pp-ok)}' +
|
|
5099
7338
|
'.pp-queue-dock,.pp-panel-dock{position:relative;flex:none;display:flex;flex-direction:column}' +
|
|
7339
|
+
'.pp-notes-bar{margin:0 10px 10px;padding:8px 12px;border:1px solid color-mix(in srgb,var(--pp-danger) 30%,var(--pp-line-2));border-radius:9px;background:color-mix(in srgb,var(--pp-danger) 9%,transparent);color:var(--pp-danger);font-size:12px;line-height:1.5}' +
|
|
7340
|
+
'.pp-notes-bar[data-kind="ok"]{border-color:color-mix(in srgb,var(--pp-ok) 30%,var(--pp-line-2));background:color-mix(in srgb,var(--pp-ok) 9%,transparent);color:var(--pp-ok)}' +
|
|
5100
7341
|
'.pp-status-float{position:absolute;left:10px;right:auto;width:max-content;max-width:calc(100% - 20px);bottom:100%;margin-bottom:6px;padding:6px 12px;border:1px solid var(--pp-line-2);border-radius:8px;background:var(--pp-surface);box-shadow:0 4px 14px rgba(0,0,0,.10);z-index:5;pointer-events:none;animation:pp-status-in .16s ease}' +
|
|
5101
7342
|
'.pp-panel .pp-status-float{pointer-events:auto}' +
|
|
5102
7343
|
// The page's status float stays click-through, so only the undo link takes clicks.
|
|
@@ -5120,6 +7361,8 @@ window.__ModuleLoader__.load({
|
|
|
5120
7361
|
'.pp-seldonecard{width:280px}' +
|
|
5121
7362
|
'.pp-sellist{display:flex;flex-direction:column;min-height:0;overflow-y:auto}' +
|
|
5122
7363
|
'.pp-selrule{height:1px;margin:3px 4px;background:var(--pp-line)}' +
|
|
7364
|
+
'.pp-selgroup{display:flex;flex-direction:column;margin-top:4px;padding:3px 3px 4px;border:1px solid var(--pp-line);border-radius:8px;background:color-mix(in srgb,var(--pp-ink) 3%,transparent)}' +
|
|
7365
|
+
'.pp-selgroup-label{display:flex;align-items:center;gap:4px;padding:1px 8px 3px;color:var(--pp-ink-2);font-size:10px;letter-spacing:.02em}' +
|
|
5123
7366
|
'.pp-selrow{display:flex;align-items:center;gap:8px;width:100%;height:26px;padding:0 8px;border:0;border-radius:6px;background:transparent;color:var(--pp-ink);font:inherit;font-size:12px;text-align:left;cursor:pointer}' +
|
|
5124
7367
|
'.pp-selrow:hover,.pp-selrow:focus-visible{background:color-mix(in srgb,var(--pp-accent) 11%,transparent)}' +
|
|
5125
7368
|
'.pp-selrow:focus-visible{outline:2px solid var(--pp-accent);outline-offset:-2px}' +
|
|
@@ -5134,12 +7377,103 @@ window.__ModuleLoader__.load({
|
|
|
5134
7377
|
'.pp-seldone-mark{flex:none;color:var(--pp-ok);font-size:12px}' +
|
|
5135
7378
|
'.pp-seldone[data-kind="error"] .pp-seldone-mark{color:var(--pp-danger)}';
|
|
5136
7379
|
|
|
7380
|
+
/**
|
|
7381
|
+
* Annotations live in the frame overlay and in the composer dock, so they
|
|
7382
|
+
* carry their own tokens and controls. The highlight rule is global: the
|
|
7383
|
+
* Highlight API paints ranges that the markdown DOM never contains.
|
|
7384
|
+
*/
|
|
7385
|
+
const NOTES_CSS =
|
|
7386
|
+
'::highlight(prompt-pool-note-comment){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(255,191,36,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
|
|
7387
|
+
'::highlight(prompt-pool-note-question){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(244,114,114,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
|
|
7388
|
+
'::highlight(prompt-pool-note-agree){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(74,222,128,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
|
|
7389
|
+
'::highlight(prompt-pool-note-disagree){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(239,68,68,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
|
|
7390
|
+
'::highlight(prompt-pool-note-idea){text-decoration-line:underline;text-decoration-style:solid;text-decoration-color:rgba(96,165,250,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
|
|
7391
|
+
'::highlight(prompt-pool-note-todo){text-decoration-line:underline;text-decoration-style:dashed;text-decoration-color:rgba(251,191,36,.95);text-decoration-thickness:1px;text-underline-offset:2px}' +
|
|
7392
|
+
'.pp-note-layer{--pp-note-accent:var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary));--pp-note-ink:var(--dsw-alias-label-primary);--pp-note-ink-2:var(--dsw-alias-label-secondary);--pp-note-line:var(--dsw-alias-border-l1);--pp-note-surface:var(--dsw-alias-bg-overlay);--pp-note-hover:color-mix(in srgb,var(--pp-note-ink) 8%,transparent);--pp-note-danger:var(--dsw-alias-state-error-primary);--pp-note-ok:var(--dsw-alias-state-success-primary);position:fixed;inset:0;z-index:2147482000;pointer-events:none}' +
|
|
7393
|
+
'.pp-note-bubble{position:fixed;z-index:1;display:flex;flex-direction:column;gap:8px;width:310px;max-width:calc(100vw - 24px);max-height:calc(100vh - 24px);overflow:auto;box-sizing:border-box;padding:11px;border:1px solid var(--pp-note-line);border-radius:12px;background:var(--pp-note-surface);box-shadow:0 18px 48px rgba(0,0,0,.22),0 2px 6px rgba(0,0,0,.08);color:var(--pp-note-ink);font-size:12px;line-height:1.5;text-align:left;pointer-events:auto}' +
|
|
7394
|
+
'.pp-note-bubble-quote{box-sizing:border-box;padding:6px 8px;border-radius:8px;background:rgba(var(--pp-bubble-tint),.10);color:var(--pp-note-ink-2);font-size:11px;line-height:1.5;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden}.pp-note-bubble-quote-icon{margin-right:4px;color:rgb(var(--pp-bubble-tint))}' +
|
|
7395
|
+
'.pp-note-bubble-hint{color:var(--pp-note-danger);font-size:11px}' +
|
|
7396
|
+
|
|
7397
|
+
'.pp-note-input{width:100%;box-sizing:border-box;min-height:48px;max-height:120px;padding:6px 8px;border:1px solid var(--pp-note-line);border-radius:8px;background:color-mix(in srgb,var(--pp-note-ink) 3%,transparent);color:inherit;font:inherit;font-size:12px;line-height:1.5;resize:none;outline:none}' +
|
|
7398
|
+
'.pp-note-input:focus{border-color:rgba(var(--pp-bubble-tint),.9);box-shadow:0 0 0 2px rgba(var(--pp-bubble-tint),.14)}' +
|
|
7399
|
+
'.pp-note-bubble-foot{display:flex;align-items:center;gap:8px}.pp-note-bubble-ask{flex:1;color:var(--pp-note-ink-2);font-size:11px;line-height:1.4}.pp-note-bubble-actions{display:flex;gap:6px;margin-left:auto}.pp-note-bubble .pp-note-btn{height:24px;padding:0 9px;font-size:11px;border-radius:7px}.pp-note-btn-quiet-danger{border-color:transparent;background:transparent;color:var(--pp-note-danger)}.pp-note-btn-quiet-danger:hover{background:rgba(var(--pp-note-danger-rgb,239,68,68),.10)}' +
|
|
7400
|
+
'.pp-note-btn{height:24px;padding:0 10px;border:1px solid var(--pp-note-line);border-radius:7px;background:transparent;color:var(--pp-note-ink);font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}' +
|
|
7401
|
+
'.pp-note-btn:hover{background:var(--pp-note-hover)}' +
|
|
7402
|
+
'.pp-note-btn:disabled{opacity:.45;cursor:default}' +
|
|
7403
|
+
'.pp-note-btn-primary{border-color:var(--pp-note-accent);background:var(--pp-note-accent);color:#fff}' +
|
|
7404
|
+
'.pp-note-btn-primary:hover{background:var(--pp-note-accent);filter:brightness(1.05)}' +
|
|
7405
|
+
'.pp-note-btn-danger{color:var(--pp-note-danger);border-color:color-mix(in srgb,var(--pp-note-danger) 40%,transparent)}' +
|
|
7406
|
+
'.pp-note-btn-danger:hover{background:color-mix(in srgb,var(--pp-note-danger) 10%,transparent)}' +
|
|
7407
|
+
'.pp-notes{--pp-note-accent:var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary));--pp-note-ink:var(--dsw-alias-label-primary);--pp-note-ink-2:var(--dsw-alias-label-secondary);--pp-note-line:var(--dsw-alias-border-l1);--pp-note-surface:var(--dsw-alias-bg-overlay);--pp-note-hover:color-mix(in srgb,var(--pp-note-ink) 8%,transparent);--pp-note-danger:var(--dsw-alias-state-error-primary);--pp-note-ok:var(--dsw-alias-state-success-primary);display:flex;flex-direction:column;box-sizing:border-box;width:100%;border:1px solid var(--pp-note-line);border-radius:10px;background:color-mix(in srgb,var(--dsw-alias-state-warn-primary,#e0a800) 5%,var(--dsw-alias-bg-base,#fff));color:var(--pp-note-ink);font-size:12px;line-height:1.5}' +
|
|
7408
|
+
'.pp-notes-embedded{border:0;border-radius:0;background:transparent}' +
|
|
7409
|
+
'.pp-notes-embedded .pp-notes-head{padding:8px 2px 4px}' +
|
|
7410
|
+
'.pp-notes-embedded .pp-notes-list{max-height:none;overflow:visible;padding:0}' +
|
|
7411
|
+
'.pp-notes-embedded .pp-notes-row{background:transparent}' +
|
|
7412
|
+
'.pp-notes-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap;min-height:32px;padding:5px 10px}' +
|
|
7413
|
+
'.pp-notes-title{font-weight:600}' +
|
|
7414
|
+
'.pp-notes-count{color:var(--pp-note-ink-2);font-size:11px;font-variant-numeric:tabular-nums}' +
|
|
7415
|
+
'.pp-notes-status{font-size:11px}' +
|
|
7416
|
+
'.pp-notes-status[data-kind="error"]{color:var(--pp-note-danger)}' +
|
|
7417
|
+
'.pp-notes-status[data-kind="ok"]{color:var(--pp-note-ok)}' +
|
|
7418
|
+
'.pp-notes-grow{flex:1;min-width:8px}' +
|
|
7419
|
+
'.pp-notes-ask{color:var(--pp-note-ink-2);font-size:11px}' +
|
|
7420
|
+
'.pp-notes-list{display:flex;flex-direction:column;gap:4px;max-height:180px;overflow-y:auto;padding:0 8px 8px}' +
|
|
7421
|
+
'.pp-notes-row{display:flex;align-items:flex-start;gap:8px;padding:6px 7px;border:1px solid transparent;border-radius:8px;background:transparent}' +
|
|
7422
|
+
'.pp-notes-row:hover{background:rgba(232,176,40,.22)}' +
|
|
7423
|
+
'.pp-notes-n{flex:none;min-width:16px;height:16px;margin-top:1px;border-radius:999px;background:rgba(232,176,40,.22);color:var(--pp-note-ink-2);font-size:10px;line-height:16px;text-align:center}' +
|
|
7424
|
+
'.pp-notes-main{flex:1;min-width:0}' +
|
|
7425
|
+
'.pp-notes-quote{display:flex;align-items:center;gap:6px;color:var(--pp-note-ink-2);font-size:11px;white-space:nowrap;overflow:hidden}' +
|
|
7426
|
+
'.pp-notes-quote-text{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis}' +
|
|
7427
|
+
'.pp-notes-empty{padding:14px 12px;color:var(--pp-note-ink-2);font-size:12px;line-height:1.6}' +
|
|
7428
|
+
'.pp-notes-tag{flex:none;padding:0 5px;border-radius:5px;background:color-mix(in srgb,var(--dsw-alias-state-success-primary,#2f9e63) 14%,transparent);color:var(--dsw-alias-state-success-primary,#2f9e63);font-size:10px;line-height:16px}' +
|
|
7429
|
+
'.pp-notes-row[data-promoted="true"]{border-color:color-mix(in srgb,var(--dsw-alias-state-success-primary,#2f9e63) 35%,var(--pp-note-line))}' +
|
|
7430
|
+
'.pp-notes-kind{flex:none;display:inline-flex;align-items:center;justify-content:center;width:15px;height:15px;margin-right:4px;border-radius:4px;background:rgba(var(--pp-inline-tint),.18);color:rgb(var(--pp-inline-tint));font-size:10px;line-height:1}' +
|
|
7431
|
+
'.pp-note-inline[data-kind="comment"],.pp-notes-kind[data-kind="comment"],.pp-note-kind[data-kind="comment"]{--pp-inline-tint:255,191,36}' +
|
|
7432
|
+
'.pp-note-inline[data-kind="question"],.pp-notes-kind[data-kind="question"],.pp-note-kind[data-kind="question"]{--pp-inline-tint:244,114,114}' +
|
|
7433
|
+
'.pp-note-inline[data-kind="agree"],.pp-notes-kind[data-kind="agree"],.pp-note-kind[data-kind="agree"]{--pp-inline-tint:74,222,128}' +
|
|
7434
|
+
'.pp-note-inline[data-kind="disagree"],.pp-notes-kind[data-kind="disagree"],.pp-note-kind[data-kind="disagree"]{--pp-inline-tint:239,68,68}' +
|
|
7435
|
+
'.pp-note-inline[data-kind="idea"],.pp-notes-kind[data-kind="idea"],.pp-note-kind[data-kind="idea"]{--pp-inline-tint:96,165,250}' +
|
|
7436
|
+
'.pp-note-inline[data-kind="todo"],.pp-notes-kind[data-kind="todo"],.pp-note-kind[data-kind="todo"]{--pp-inline-tint:251,191,36}' +
|
|
7437
|
+
'.pp-note-inline{display:inline-flex;align-items:center;gap:3px;height:17px;margin:0 1px 0 4px;padding:0 5px;border:1px dashed rgba(var(--pp-inline-tint),.85);border-radius:5px;background:rgba(var(--pp-inline-tint),.15);color:inherit;font:inherit;font-size:11px;line-height:17px;vertical-align:middle;white-space:nowrap;user-select:none;-webkit-user-select:none;cursor:pointer}' +
|
|
7438
|
+
'.pp-note-inline-icon{font-size:10px;line-height:1;color:rgb(var(--pp-inline-tint))}' +
|
|
7439
|
+
'.pp-note-inline-text{white-space:nowrap}' +
|
|
7440
|
+
'.pp-note-inline:hover{border-color:rgb(var(--pp-inline-tint));background:rgba(var(--pp-inline-tint),.26)}' +
|
|
7441
|
+
'.pp-note-kinds{display:flex;flex-wrap:wrap;gap:2px;margin:0}' +
|
|
7442
|
+
'.pp-note-kind{display:inline-flex;align-items:center;gap:3px;height:20px;padding:0 5px;border:1px solid var(--pp-note-line);border-radius:999px;background:transparent;color:var(--pp-note-ink-2);font:inherit;font-size:10.5px;cursor:pointer}' +
|
|
7443
|
+
'.pp-note-kind[data-active="true"]{border-color:rgba(var(--pp-inline-tint),.9);color:var(--pp-note-ink);background:rgba(var(--pp-inline-tint),.16)}' +
|
|
7444
|
+
'.pp-note-kind-icon{font-size:10px;line-height:1;color:rgb(var(--pp-inline-tint))}' +
|
|
7445
|
+
'.pp-note-limit{color:var(--pp-note-ink-2);font-size:10px;font-variant-numeric:tabular-nums}' +
|
|
7446
|
+
'.pp-note-limit-count{font-variant-numeric:tabular-nums}' +
|
|
7447
|
+
'.pp-note-prompt{position:fixed;z-index:3;display:flex;flex-direction:column;gap:2px;width:210px;box-sizing:border-box;padding:5px;border:1px solid var(--pp-note-line);border-radius:10px;background:var(--pp-note-surface);box-shadow:0 14px 34px rgba(0,0,0,.2);color:var(--pp-note-ink);font-size:12px;line-height:1.5;text-align:left;pointer-events:auto}' +
|
|
7448
|
+
'.pp-note-prompt-title{padding:2px 8px 4px;color:var(--pp-note-ink-2);font-size:11px}' +
|
|
7449
|
+
'.pp-note-prompt-list{display:flex;flex-direction:column;max-height:250px;overflow-y:auto}' +
|
|
7450
|
+
'.pp-note-prompt-row{display:flex;align-items:center;gap:6px;width:100%;height:26px;padding:0 8px;border:0;border-radius:6px;background:transparent;color:var(--pp-note-ink);font:inherit;font-size:12px;text-align:left;cursor:pointer}' +
|
|
7451
|
+
'.pp-note-prompt-row:hover,.pp-note-prompt-row:focus-visible{background:var(--pp-note-hover);outline:none}' +
|
|
7452
|
+
'.pp-note-prompt-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}' +
|
|
7453
|
+
'.pp-note-prompt-tag{flex:none;padding:0 5px;border-radius:5px;background:rgba(var(--pp-bubble-tint,232,176,40),.16);color:var(--pp-note-ink-2);font-size:10px;line-height:16px}' +
|
|
7454
|
+
'.pp-note-prompt-sep{height:1px;margin:3px 6px;background:var(--pp-note-line)}' +
|
|
7455
|
+
'.pp-note-prompt-cancel{color:var(--pp-note-ink-2)}' +
|
|
7456
|
+
'.pp-note-prompt-message{padding:2px 8px;color:var(--pp-note-ink);font-size:12px;line-height:1.5}' +
|
|
7457
|
+
'.pp-note-prompt-actions{display:flex;justify-content:flex-end;gap:6px;padding:2px}' +
|
|
7458
|
+
'.pp-note-groups{display:flex;flex-direction:column;gap:4px;margin:2px 0 6px;padding:8px;border:1px solid var(--pp-note-line);border-radius:8px;background:var(--pp-note-surface)}' +
|
|
7459
|
+
'.pp-note-groups-title{font-size:11px;color:var(--pp-note-ink-2)}' +
|
|
7460
|
+
'.pp-note-groups-list{display:flex;flex-wrap:wrap;gap:4px}' +
|
|
7461
|
+
'.pp-note-group{display:inline-flex;align-items:center;gap:4px;height:24px;padding:0 9px;border:1px solid var(--pp-note-line);border-radius:7px;background:transparent;color:var(--pp-note-ink);font:inherit;font-size:12px;cursor:pointer;white-space:nowrap}' +
|
|
7462
|
+
'.pp-note-group:hover{border-color:var(--pp-note-accent)}' +
|
|
7463
|
+
'.pp-note-group[data-default="true"]{border-color:var(--pp-note-accent);background:color-mix(in srgb,var(--pp-note-accent) 10%,transparent)}' +
|
|
7464
|
+
'.pp-note-group-default{font-size:10px;color:var(--pp-note-accent)}' +
|
|
7465
|
+
'.pp-notes-text{white-space:pre-wrap;word-break:break-word;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden}' +
|
|
7466
|
+
'.pp-note-link{border:0;background:transparent;color:var(--pp-note-ink-2);font:inherit;font-size:11px;cursor:pointer;padding:2px 0;white-space:nowrap}' +
|
|
7467
|
+
'.pp-note-link:hover{color:var(--pp-note-ink);text-decoration:underline;text-underline-offset:2px}' +
|
|
7468
|
+
'.pp-note-link-danger:hover{color:var(--pp-note-danger)}.pp-note-icon{display:inline-flex;align-items:center;justify-content:center;flex:none;width:22px;height:22px;padding:0;border:1px solid transparent;border-radius:6px;background:transparent;color:var(--pp-note-ink-2);cursor:pointer}.pp-note-icon:hover{background:var(--pp-note-hover);color:var(--pp-note-ink)}.pp-note-icon.pp-note-link-danger:hover{color:var(--pp-note-danger)}.pp-note-ask{display:inline-flex;align-items:center;gap:4px;color:var(--pp-note-ink-2);font-size:11px;white-space:nowrap}';
|
|
7469
|
+
|
|
5137
7470
|
// ------------------------------------------------------------------- plugin
|
|
5138
7471
|
return {
|
|
5139
7472
|
inject: ['slots', 'locale'],
|
|
5140
7473
|
apply(ctx) {
|
|
5141
7474
|
localeCtx = ctx.locale;
|
|
5142
7475
|
pluginCtx = ctx;
|
|
7476
|
+
seedPoolIfNeeded();
|
|
5143
7477
|
// Optional services: bind late, and stay idle when they never mount.
|
|
5144
7478
|
const bindOptional = (names, assign) => {
|
|
5145
7479
|
const run = (target) => {
|
|
@@ -5208,7 +7542,13 @@ window.__ModuleLoader__.load({
|
|
|
5208
7542
|
});
|
|
5209
7543
|
if (ctx.locale && typeof ctx.locale.register === 'function' && typeof ctx.locale.bind === 'function') {
|
|
5210
7544
|
ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }));
|
|
5211
|
-
|
|
7545
|
+
const preview = previewLocaleId();
|
|
7546
|
+
if (preview) {
|
|
7547
|
+
const table = preview === 'zh' ? ZH : EN;
|
|
7548
|
+
translate = (key, params) => interpolate(table[key] || key, params);
|
|
7549
|
+
} else {
|
|
7550
|
+
translate = ctx.locale.bind(NS);
|
|
7551
|
+
}
|
|
5212
7552
|
}
|
|
5213
7553
|
// The composer keeps two pieces: the trigger beside the input, and the
|
|
5214
7554
|
// overlay panel. The overlay stays mounted even while closed, which is
|
|
@@ -5233,6 +7573,14 @@ window.__ModuleLoader__.load({
|
|
|
5233
7573
|
SelectionMenu,
|
|
5234
7574
|
),
|
|
5235
7575
|
);
|
|
7576
|
+
// Annotations: cards and the inline editor in the frame overlay; the list
|
|
7577
|
+
// and the composed reply live in the prompt pool views' annotation tab.
|
|
7578
|
+
ctx.slots.inject('shell.overlay', () =>
|
|
7579
|
+
ctx.slots.register(
|
|
7580
|
+
{ name: 'shell.overlay', id: 'prompt-pool-notes', order: 30, label: () => translate('note.title') },
|
|
7581
|
+
NotesLayer,
|
|
7582
|
+
),
|
|
7583
|
+
);
|
|
5236
7584
|
|
|
5237
7585
|
ctx.slots.inject('settings.section', () =>
|
|
5238
7586
|
ctx.slots.register(
|
|
@@ -5340,7 +7688,4 @@ window.__ModuleLoader__.load({
|
|
|
5340
7688
|
},
|
|
5341
7689
|
};
|
|
5342
7690
|
},
|
|
5343
|
-
});
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
7691
|
+
});
|