dsh-quote-annotate-pro 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/lib/client.js +73 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
本项目的所有重要变更都记在这里。版本号遵循 [SemVer](https://semver.org/lang/zh-CN/)。
|
|
4
4
|
|
|
5
|
+
## 0.2.9 — 编辑框定位再修:排除"贴文档原点"的退化矩形
|
|
6
|
+
|
|
7
|
+
- 0.2.8 只拦了"尺寸为 0"的矩形;实测选区被打断后 `getBoundingClientRect()` 会返回**贴文档原点、但高度非 0** 的退化矩形,仍会算出 `left≈12 / top≈8`(窗口左上角)
|
|
8
|
+
- 现在取值优先级为:**当前还活着的选区** → 存下来的矩形(需通过 `plausibleRect()`:有限值、有尺寸、**不在原点附近**、不越出视口)→ **视口底部居中**
|
|
9
|
+
- 新增诊断 `editor:anchor`(只记来源与矩形,不记内容),便于下次一眼定位
|
|
10
|
+
- 文本与模型侧行为不变
|
|
11
|
+
|
|
12
|
+
## 0.2.8 — 修复"批注编辑框跑到窗口左上角 / 引用不了"
|
|
13
|
+
|
|
14
|
+
- **现象**:选中文字点「批注」后,编辑框出现在窗口左上角(压住侧边栏),看起来像引用功能坏了
|
|
15
|
+
- **根因**:装饰逻辑会替换消息里的文本节点;若用户**正在那条消息里划词**,替换会让选区失效,`getBoundingClientRect()` 随即返回全 0 —— 用这个矩形算出来的位置正好是 `left=12 / top=8`(窗口左上角)
|
|
16
|
+
- **修复**
|
|
17
|
+
- **不再动用户正在划词的那条消息**:`selectionTouches(row)` 守卫,等选区释放后再装饰
|
|
18
|
+
- **`safeRect()` 兜底**:矩形无效时先用当前选区重算,仍无效则退回视口底部居中 —— 编辑框不会再跑到左上角
|
|
19
|
+
- 文本与模型侧行为不变(位置行仍只对模型可见)
|
|
20
|
+
|
|
5
21
|
## 0.2.7 — 引用渲染定版:输入框与对话区都不再"先露原文"
|
|
6
22
|
|
|
7
23
|
- **输入框侧(本次)**:插入引用后**同一帧内**完成装饰 —— 不再走 `setTimeout`,改为在 `MutationObserver` 回调里同步执行(回调先于绘制),消除此前约 40ms 的"先露出完整引用块"窗口
|
package/lib/client.js
CHANGED
|
@@ -683,7 +683,11 @@ window.__ModuleLoader__.load({
|
|
|
683
683
|
anchorKey: sel.anchorKey,
|
|
684
684
|
turn: sel.turn,
|
|
685
685
|
kind: sel.kind,
|
|
686
|
-
}, sel.rect)
|
|
686
|
+
}, anchorRect(sel.rect))
|
|
687
|
+
try {
|
|
688
|
+
const r = anchorRect(sel.rect)
|
|
689
|
+
report('editor:anchor', { src: r.__dshq === 'fallback' ? 'fallback' : (liveSelectionRect() ? 'live' : 'stored'), rect: [Math.round(r.left), Math.round(r.top), Math.round(r.right - r.left), Math.round(r.bottom - r.top)] })
|
|
690
|
+
} catch (e) { /* ignore */ }
|
|
687
691
|
finish()
|
|
688
692
|
}
|
|
689
693
|
return React.createElement('div', { className: 'dshq-toolbar', style: { left, top } },
|
|
@@ -704,6 +708,49 @@ window.__ModuleLoader__.load({
|
|
|
704
708
|
}
|
|
705
709
|
|
|
706
710
|
// ============ 组件三:悬浮批注编辑框(评论输入框元素永久驻留,复用时输入法上下文不重建) ============
|
|
711
|
+
/**
|
|
712
|
+
* 选区矩形兜底。矩形失效(节点被装饰/重渲染替换后 getBoundingClientRect 会返回"文档原点附近"的退化矩形)
|
|
713
|
+
* 时,直接用它会算出 left≈12 / top≈8 —— 编辑框就跑到窗口左上角(用户反馈的现象)。
|
|
714
|
+
* 取值优先级:**当前还活着的选区** → 存下来的矩形(且看着正常)→ 视口底部居中。
|
|
715
|
+
*/
|
|
716
|
+
function liveSelectionRect() {
|
|
717
|
+
try {
|
|
718
|
+
const s = typeof window !== 'undefined' ? window.getSelection() : null
|
|
719
|
+
if (!s || s.rangeCount === 0 || s.isCollapsed) return null
|
|
720
|
+
const r = s.getRangeAt(0).getBoundingClientRect()
|
|
721
|
+
return plausibleRect(r) ? r : null
|
|
722
|
+
} catch (e) { return null }
|
|
723
|
+
}
|
|
724
|
+
/** 排除"贴文档原点"的退化矩形:那是选区失效后的典型产物 */
|
|
725
|
+
function plausibleRect(r) {
|
|
726
|
+
if (!r) return false
|
|
727
|
+
if (!(Number.isFinite(r.left) && Number.isFinite(r.top) && Number.isFinite(r.right) && Number.isFinite(r.bottom))) return false
|
|
728
|
+
const w = r.right - r.left
|
|
729
|
+
const h = r.bottom - r.top
|
|
730
|
+
if (!(w > 0 || h > 0)) return false
|
|
731
|
+
if (r.left < 24 && r.top < 24) return false // 原点附近 → 视为失效
|
|
732
|
+
const vw = typeof window !== 'undefined' ? window.innerWidth : 1024
|
|
733
|
+
const vh = typeof window !== 'undefined' ? window.innerHeight : 768
|
|
734
|
+
if (r.left > vw || r.top > vh) return false
|
|
735
|
+
return true
|
|
736
|
+
}
|
|
737
|
+
function bottomCenterRect() {
|
|
738
|
+
const vw = typeof window !== 'undefined' ? window.innerWidth : 1024
|
|
739
|
+
const vh = typeof window !== 'undefined' ? window.innerHeight : 768
|
|
740
|
+
const left = Math.max(12, Math.round(vw / 2 - 140))
|
|
741
|
+
const top = Math.max(12, Math.round(vh - 200))
|
|
742
|
+
return { left, right: left + 280, top, bottom: top + 24, width: 280, height: 24, __dshq: 'fallback' }
|
|
743
|
+
}
|
|
744
|
+
function anchorRect(stored) {
|
|
745
|
+
const live = liveSelectionRect()
|
|
746
|
+
if (live) return live
|
|
747
|
+
if (plausibleRect(stored)) return stored
|
|
748
|
+
return bottomCenterRect()
|
|
749
|
+
}
|
|
750
|
+
function safeRect(rect) {
|
|
751
|
+
return anchorRect(rect)
|
|
752
|
+
}
|
|
753
|
+
|
|
707
754
|
const AnnotationEditor = () => {
|
|
708
755
|
const state = useEditor()
|
|
709
756
|
const inputRef = React.useRef(null)
|
|
@@ -721,18 +768,22 @@ window.__ModuleLoader__.load({
|
|
|
721
768
|
const vw = typeof window !== 'undefined' ? window.innerWidth : 1024
|
|
722
769
|
const vh = typeof window !== 'undefined' ? window.innerHeight : 768
|
|
723
770
|
const item = state.item
|
|
771
|
+
const rect = open ? anchorRect(state.rect) : null
|
|
772
|
+
if (rect && rect.__dshq === 'fallback') {
|
|
773
|
+
try { report('editor:anchor', { src: 'fallback' }) } catch (e) { /* ignore */ }
|
|
774
|
+
}
|
|
724
775
|
let left = -9999
|
|
725
776
|
let top = -9999
|
|
726
777
|
let w = 200
|
|
727
|
-
if (open) {
|
|
778
|
+
if (open && rect) {
|
|
728
779
|
// 宽度:默认约 10 字(120px),随评论输入变宽,封顶 340px
|
|
729
780
|
const quoteW = Math.min(220, item.text.length * 12 + 16)
|
|
730
781
|
const inputW = Math.min(300, Math.max(140, comment.length * 13 + 44))
|
|
731
782
|
w = Math.max(120, Math.min(340, Math.max(quoteW, inputW)))
|
|
732
|
-
const center =
|
|
783
|
+
const center = rect.left + (rect.right - rect.left) / 2
|
|
733
784
|
left = Math.max(12, Math.min(center - w / 2, vw - w - 12))
|
|
734
785
|
const estH = 200
|
|
735
|
-
top =
|
|
786
|
+
top = rect.bottom + 8 + estH <= vh - 8 ? rect.bottom + 8 : Math.max(8, rect.top - estH - 8)
|
|
736
787
|
}
|
|
737
788
|
const insert = () => {
|
|
738
789
|
if (!open || !item) return
|
|
@@ -1293,6 +1344,20 @@ window.__ModuleLoader__.load({
|
|
|
1293
1344
|
})
|
|
1294
1345
|
return wrap
|
|
1295
1346
|
}
|
|
1347
|
+
/** 用户当前选区是否落在这个行里(是则暂缓装饰,别动 DOM 把选区搞失效) */
|
|
1348
|
+
const selectionTouches = (row) => {
|
|
1349
|
+
try {
|
|
1350
|
+
const s = typeof window !== 'undefined' ? window.getSelection() : null
|
|
1351
|
+
if (!s || s.rangeCount === 0 || s.isCollapsed) return false
|
|
1352
|
+
for (let i = 0; i < s.rangeCount; i++) {
|
|
1353
|
+
const r = s.getRangeAt(i)
|
|
1354
|
+
const a = r.startContainer
|
|
1355
|
+
const b = r.endContainer
|
|
1356
|
+
if ((a && row.contains(a)) || (b && row.contains(b))) return true
|
|
1357
|
+
}
|
|
1358
|
+
} catch (e) { /* ignore */ }
|
|
1359
|
+
return false
|
|
1360
|
+
}
|
|
1296
1361
|
/** 把承载「【引用…】\n原文…」的文本节点拆成:隐藏头部 + 紧凑引用块 + 其余文本 */
|
|
1297
1362
|
const transformTextNode = (node) => {
|
|
1298
1363
|
const raw = node.nodeValue || ''
|
|
@@ -1326,10 +1391,12 @@ window.__ModuleLoader__.load({
|
|
|
1326
1391
|
}
|
|
1327
1392
|
const scan = () => {
|
|
1328
1393
|
timer = null
|
|
1329
|
-
try {
|
|
1330
|
-
for (const row of document.querySelectorAll(USER_ROW_SEL)) {
|
|
1394
|
+
try { for (const row of document.querySelectorAll(USER_ROW_SEL)) {
|
|
1331
1395
|
const kind = row.getAttribute('data-chat-flow-kind')
|
|
1332
1396
|
if (kind && kind !== 'user') continue
|
|
1397
|
+
// 用户正在这条消息里划词时**不要动它的 DOM**:替换文本节点会让选区失效,
|
|
1398
|
+
// 选区矩形随即变成全 0,批注气泡/编辑框就会定位到左上角(用户反馈过)。
|
|
1399
|
+
if (selectionTouches(row)) continue
|
|
1333
1400
|
let walker
|
|
1334
1401
|
try { walker = document.createTreeWalker(row, NodeFilter.SHOW_TEXT, null) } catch (e) { continue }
|
|
1335
1402
|
const targets = []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-quote-annotate-pro",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "选区引用与锚点批注(增强 fork):划词 → 批注 → 带精确锚点的引用;输入框上方只显示原文片段,点一下跳回原文;发送时把轮次/角色写入引用块,让模型精确知道你指的是哪一处。",
|
|
5
5
|
"keywords": ["dsh", "dsh-plugin", "deepseek-harness", "quote", "annotate", "selection", "reference", "anchor"],
|
|
6
6
|
"license": "MIT",
|