@240xu/dsh-message-ops 0.48.0 → 0.48.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.48.0",
3
+ "version": "0.48.1",
4
4
  "description": "DSH web 插件:消息级回滚 / 删除 / 恢复 / 分叉 / 编辑重发(补 dsh 官方没有的部分)。",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -27,6 +27,38 @@
27
27
  const HOST_CLS = {
28
28
  actions: 'xzv4MW_actions', // MessageIconActions.module.css(官方用户消息动作行)
29
29
  userRow: 'Sixlwa_userRow', // MessageItem.module.css(用户消息容器)
30
+ /**
31
+ * 动作行的 **hash-agnostic 形状**(兜底用,不是新的 hash 快照)。
32
+ *
33
+ * CSS module 产出的类名恒为 `<6 位 base36>_actions`:`xzv4MW_actions`(0.2.3 web)、
34
+ * `1KfHza_actions`(0.2.2-rc.5 Desktop,issue #10 实测)都是这个形状。
35
+ * 宿主换版本后 `actions` 失配时,靠形状在本条消息块内兜底;否则只能退回
36
+ * `mopsUserActionsRow` —— 按钮挂得上,但不跟随官方 hover 显隐。
37
+ *
38
+ * 只按**整段 class token** 比对:`_group_actions` / `n_file_actions` 这类包含
39
+ * `_actions` 子串的类名不会误命中(前缀不是 6 位 base36)。
40
+ */
41
+ actionsShape: /^[A-Za-z0-9]{6}_actions$/,
42
+ }
43
+ /** 元素是否**形状上**是宿主动作行(见 `HOST_CLS.actionsShape`)。 */
44
+ const isHostActionsRow = el => {
45
+ if (!el || el.nodeType !== 1) return false
46
+ const cls = (el.getAttribute && el.getAttribute('class')) || ''
47
+ return String(cls).split(/\s+/).some(c => HOST_CLS.actionsShape.test(c))
48
+ }
49
+ /**
50
+ * `root` 内全部候选动作行:精确 hash 命中项**排在前**(保持精确优先),
51
+ * 其后才是形状匹配的兜底项。宿主有多个 `*_actions` 类(用户动作行 / 其它行),
52
+ * 调用方仍需用 `closest(user 块)` 收窄,见 `actionsRowsIn` 的消费点。
53
+ */
54
+ const actionsRowsIn = root => {
55
+ const out = []
56
+ const exact = root.querySelectorAll('[class*="' + HOST_CLS.actions + '"]')
57
+ for (const el of exact) out.push(el)
58
+ for (const el of root.querySelectorAll('[class*="_actions"]')) {
59
+ if (out.indexOf(el) === -1 && isHostActionsRow(el)) out.push(el)
60
+ }
61
+ return out
30
62
  }
31
63
  // 0.5.2(P2):回滚/恢复成功后广播 → RevertDock 重拉标记(否则 dock 只在切会话时刷新)
32
64
  const CHANGED_EVENT = 'dsh-message-ops:changed'
@@ -98,7 +98,7 @@
98
98
  /** 行内挂载点:气泡栈之后、宿主动作行之前(动作行始终在最下面)。 */
99
99
  function mountInlineEdit(block, el, rowHint) {
100
100
  const rowEl = rowHint || block.querySelector('[class*="userRow"]') || block
101
- const acts = rowEl.querySelector('[class*="' + HOST_CLS.actions + '"]')
101
+ const acts = rowEl.querySelector('[class*="' + HOST_CLS.actions + '"]') || rowEl.querySelector('[class*="_actions"]')
102
102
  if (acts && acts.parentElement === rowEl) rowEl.insertBefore(el, acts)
103
103
  else rowEl.appendChild(el)
104
104
  return rowEl
@@ -211,7 +211,7 @@
211
211
  out.push(el)
212
212
  }
213
213
  }
214
- const rows = Array.from(document.querySelectorAll('[class*="' + HOST_CLS.actions + '"]'))
214
+ const rows = actionsRowsIn(document)
215
215
  for (const r of rows) {
216
216
  const block =
217
217
  r.closest('[data-chat-flow-kind="user"]') ||
@@ -444,6 +444,18 @@
444
444
  var ensureActionsHost = block => {
445
445
  // ① 宿主动作行(可见性跟随 hover 显隐,首选)
446
446
  let host = block.querySelector('[class*="' + HOST_CLS.actions + '"]')
447
+ // ①b hash 漂移兜底:宿主换版本后 `HOST_CLS.actions` 会 0 命中(issue #10:
448
+ // 0.2.2-rc.5 的动作行是 `1KfHza_actions`)。不兜底就只能退回 ② 的自建行 ——
449
+ // 按钮还在,但不跟随官方 hover 显隐,行高也与官方行脱节。
450
+ // 形状正则来自 `HOST_CLS.actionsShape`(单点定义,避免再散落一份 hash 知识)。
451
+ if (!host && typeof block.querySelectorAll === 'function') {
452
+ for (const el of block.querySelectorAll('[class*="_actions"]')) {
453
+ if (isHostActionsRow(el)) {
454
+ host = el
455
+ break
456
+ }
457
+ }
458
+ }
447
459
  if (host) return { host: host, created: false }
448
460
  // ② **我们上一轮建的兜底行**:必须一起查,否则第二个工厂查不到就再建一行
449
461
  // (原实现正是这样:`ensureBtn` 建了一行、`ensureEditBtn` 又建一行 →
@@ -570,7 +582,12 @@
570
582
  ensureEditBtn(block)
571
583
  // 宿主重建动作行后旧按钮可能被替换:保证标记只落在第一颗上
572
584
  if (first && !first.hasAttribute('data-mops-first')) {
573
- const marked = block.querySelector('[class*="' + HOST_CLS.actions + '"] [data-mops-first="1"]')
585
+ const rows = actionsRowsIn(block)
586
+ let marked = null
587
+ for (const row of rows) {
588
+ marked = row.querySelector('[data-mops-first="1"]')
589
+ if (marked) break
590
+ }
574
591
  if (!marked) first.setAttribute('data-mops-first', '1')
575
592
  }
576
593
  }
@@ -698,7 +715,7 @@
698
715
  // ④ `data-chat-flow-kind` / `class*` 只认 **added/removed 节点**(attributeFilter
699
716
  // 不含 className 与 flow-kind,见下方 observe 选项);hash 单点见 HOST_CLS。
700
717
  var MO_SEL =
701
- '[data-chat-node-key],[data-chat-flow-kind="user"],[class*="' + HOST_CLS.actions + '"],[class*="_userRow"],[data-turn-tail]'
718
+ '[data-chat-node-key],[data-chat-flow-kind="user"],[class*="' + HOST_CLS.actions + '"],[class*="_actions"],[class*="_userRow"],[data-turn-tail]'
702
719
  var scanPendingSince = 0
703
720
  var scheduleScan = () => {
704
721
  var now = Date.now()
package/src/client.js CHANGED
@@ -40,6 +40,38 @@ window.__ModuleLoader__.load({
40
40
  const HOST_CLS = {
41
41
  actions: 'xzv4MW_actions', // MessageIconActions.module.css(官方用户消息动作行)
42
42
  userRow: 'Sixlwa_userRow', // MessageItem.module.css(用户消息容器)
43
+ /**
44
+ * 动作行的 **hash-agnostic 形状**(兜底用,不是新的 hash 快照)。
45
+ *
46
+ * CSS module 产出的类名恒为 `<6 位 base36>_actions`:`xzv4MW_actions`(0.2.3 web)、
47
+ * `1KfHza_actions`(0.2.2-rc.5 Desktop,issue #10 实测)都是这个形状。
48
+ * 宿主换版本后 `actions` 失配时,靠形状在本条消息块内兜底;否则只能退回
49
+ * `mopsUserActionsRow` —— 按钮挂得上,但不跟随官方 hover 显隐。
50
+ *
51
+ * 只按**整段 class token** 比对:`_group_actions` / `n_file_actions` 这类包含
52
+ * `_actions` 子串的类名不会误命中(前缀不是 6 位 base36)。
53
+ */
54
+ actionsShape: /^[A-Za-z0-9]{6}_actions$/,
55
+ }
56
+ /** 元素是否**形状上**是宿主动作行(见 `HOST_CLS.actionsShape`)。 */
57
+ const isHostActionsRow = el => {
58
+ if (!el || el.nodeType !== 1) return false
59
+ const cls = (el.getAttribute && el.getAttribute('class')) || ''
60
+ return String(cls).split(/\s+/).some(c => HOST_CLS.actionsShape.test(c))
61
+ }
62
+ /**
63
+ * `root` 内全部候选动作行:精确 hash 命中项**排在前**(保持精确优先),
64
+ * 其后才是形状匹配的兜底项。宿主有多个 `*_actions` 类(用户动作行 / 其它行),
65
+ * 调用方仍需用 `closest(user 块)` 收窄,见 `actionsRowsIn` 的消费点。
66
+ */
67
+ const actionsRowsIn = root => {
68
+ const out = []
69
+ const exact = root.querySelectorAll('[class*="' + HOST_CLS.actions + '"]')
70
+ for (const el of exact) out.push(el)
71
+ for (const el of root.querySelectorAll('[class*="_actions"]')) {
72
+ if (out.indexOf(el) === -1 && isHostActionsRow(el)) out.push(el)
73
+ }
74
+ return out
43
75
  }
44
76
  // 0.5.2(P2):回滚/恢复成功后广播 → RevertDock 重拉标记(否则 dock 只在切会话时刷新)
45
77
  const CHANGED_EVENT = 'dsh-message-ops:changed'
@@ -2646,7 +2678,7 @@ window.__ModuleLoader__.load({
2646
2678
  /** 行内挂载点:气泡栈之后、宿主动作行之前(动作行始终在最下面)。 */
2647
2679
  function mountInlineEdit(block, el, rowHint) {
2648
2680
  const rowEl = rowHint || block.querySelector('[class*="userRow"]') || block
2649
- const acts = rowEl.querySelector('[class*="' + HOST_CLS.actions + '"]')
2681
+ const acts = rowEl.querySelector('[class*="' + HOST_CLS.actions + '"]') || rowEl.querySelector('[class*="_actions"]')
2650
2682
  if (acts && acts.parentElement === rowEl) rowEl.insertBefore(el, acts)
2651
2683
  else rowEl.appendChild(el)
2652
2684
  return rowEl
@@ -4142,7 +4174,7 @@ window.__ModuleLoader__.load({
4142
4174
  out.push(el)
4143
4175
  }
4144
4176
  }
4145
- const rows = Array.from(document.querySelectorAll('[class*="' + HOST_CLS.actions + '"]'))
4177
+ const rows = actionsRowsIn(document)
4146
4178
  for (const r of rows) {
4147
4179
  const block =
4148
4180
  r.closest('[data-chat-flow-kind="user"]') ||
@@ -4375,6 +4407,18 @@ window.__ModuleLoader__.load({
4375
4407
  var ensureActionsHost = block => {
4376
4408
  // ① 宿主动作行(可见性跟随 hover 显隐,首选)
4377
4409
  let host = block.querySelector('[class*="' + HOST_CLS.actions + '"]')
4410
+ // ①b hash 漂移兜底:宿主换版本后 `HOST_CLS.actions` 会 0 命中(issue #10:
4411
+ // 0.2.2-rc.5 的动作行是 `1KfHza_actions`)。不兜底就只能退回 ② 的自建行 ——
4412
+ // 按钮还在,但不跟随官方 hover 显隐,行高也与官方行脱节。
4413
+ // 形状正则来自 `HOST_CLS.actionsShape`(单点定义,避免再散落一份 hash 知识)。
4414
+ if (!host && typeof block.querySelectorAll === 'function') {
4415
+ for (const el of block.querySelectorAll('[class*="_actions"]')) {
4416
+ if (isHostActionsRow(el)) {
4417
+ host = el
4418
+ break
4419
+ }
4420
+ }
4421
+ }
4378
4422
  if (host) return { host: host, created: false }
4379
4423
  // ② **我们上一轮建的兜底行**:必须一起查,否则第二个工厂查不到就再建一行
4380
4424
  // (原实现正是这样:`ensureBtn` 建了一行、`ensureEditBtn` 又建一行 →
@@ -4501,7 +4545,12 @@ window.__ModuleLoader__.load({
4501
4545
  ensureEditBtn(block)
4502
4546
  // 宿主重建动作行后旧按钮可能被替换:保证标记只落在第一颗上
4503
4547
  if (first && !first.hasAttribute('data-mops-first')) {
4504
- const marked = block.querySelector('[class*="' + HOST_CLS.actions + '"] [data-mops-first="1"]')
4548
+ const rows = actionsRowsIn(block)
4549
+ let marked = null
4550
+ for (const row of rows) {
4551
+ marked = row.querySelector('[data-mops-first="1"]')
4552
+ if (marked) break
4553
+ }
4505
4554
  if (!marked) first.setAttribute('data-mops-first', '1')
4506
4555
  }
4507
4556
  }
@@ -4629,7 +4678,7 @@ window.__ModuleLoader__.load({
4629
4678
  // ④ `data-chat-flow-kind` / `class*` 只认 **added/removed 节点**(attributeFilter
4630
4679
  // 不含 className 与 flow-kind,见下方 observe 选项);hash 单点见 HOST_CLS。
4631
4680
  var MO_SEL =
4632
- '[data-chat-node-key],[data-chat-flow-kind="user"],[class*="' + HOST_CLS.actions + '"],[class*="_userRow"],[data-turn-tail]'
4681
+ '[data-chat-node-key],[data-chat-flow-kind="user"],[class*="' + HOST_CLS.actions + '"],[class*="_actions"],[class*="_userRow"],[data-turn-tail]'
4633
4682
  var scanPendingSince = 0
4634
4683
  var scheduleScan = () => {
4635
4684
  var now = Date.now()