@240xu/dsh-message-ops 0.11.7 → 0.11.8

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/client.js +46 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@240xu/dsh-message-ops",
3
- "version": "0.11.7",
3
+ "version": "0.11.8",
4
4
  "description": "DSH web 插件:消息级回滚 / 删除 / 恢复(补 dsh 官方没有的部分)。分支与导出用官方内置能力。",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/client.js CHANGED
@@ -1097,15 +1097,53 @@ window.__ModuleLoader__.load({
1097
1097
  else if (panelRef.current) panelRef.current.focus()
1098
1098
  }, 0)
1099
1099
  const scrim = scrimRef.current
1100
- const parent = scrim && scrim.parentElement
1101
1100
  const hidden = []
1102
- if (parent) {
1103
- for (const child of Array.from(parent.children)) {
1104
- if (child === scrim || child.tagName === 'SCRIPT' || child.tagName === 'STYLE') continue
1101
+ // 0.11.8:槽位会把 scrim 挂进一个**只有 scrim 自己**的独立容器,
1102
+ // 于是「遍历 parent.children」永远遍历不到真实背景 —— inert 形同虚设
1103
+ // (实测:inert=false,Tab 能跑到背后的会话列表,读屏也读得到)。
1104
+ // 正确做法是从宿主挂载点(body 直接子节点)出发,把**包含 scrim 的那条
1105
+ // 祖先链之外**的兄弟节点全部隔离;祖先链本身不能 inert(会连面板一起废掉)。
1106
+ if (scrim && document.body) {
1107
+ const chain = new Set()
1108
+ for (let el = scrim; el && el !== document.body; el = el.parentElement) chain.add(el)
1109
+ for (const child of Array.from(document.body.children)) {
1110
+ if (chain.has(child)) continue
1111
+ if (child.tagName === 'SCRIPT' || child.tagName === 'STYLE' || child.tagName === 'LINK') continue
1105
1112
  hidden.push({ child, inert: child.hasAttribute('inert'), aria: child.getAttribute('aria-hidden') })
1106
1113
  child.setAttribute('inert', '')
1107
1114
  child.setAttribute('aria-hidden', 'true')
1108
1115
  }
1116
+ // 祖先链上的每一层:把**除当前链节点以外**的兄弟也隔离掉。
1117
+ // 典型结构 body > #root > ... > 槽位容器 > scrim,中途每层都可能带界面。
1118
+ for (const el of chain) {
1119
+ const parent = el.parentElement
1120
+ if (!parent || parent === document.body) continue
1121
+ for (const sib of Array.from(parent.children)) {
1122
+ if (sib === el || chain.has(sib)) continue
1123
+ if (sib.tagName === 'SCRIPT' || sib.tagName === 'STYLE' || sib.tagName === 'LINK') continue
1124
+ hidden.push({ child: sib, inert: sib.hasAttribute('inert'), aria: sib.getAttribute('aria-hidden') })
1125
+ sib.setAttribute('inert', '')
1126
+ sib.setAttribute('aria-hidden', 'true')
1127
+ }
1128
+ }
1129
+ }
1130
+ // 居中模态必须锁背景滚动:否则滚轮/触屏拖拽会把背后的会话列表滚走,
1131
+ // 关闭后视口停在别处。用 overflow:hidden 而非 position:fixed,
1132
+ // 后者会丢失滚动位置。保留原有内联值以便精确还原。
1133
+ const body = document.body
1134
+ const prevOverflow = body && body.style ? body.style.overflow : ''
1135
+ const prevPaddingRight = body && body.style ? body.style.paddingRight : ''
1136
+ let scrollbarW = 0
1137
+ try {
1138
+ scrollbarW = window.innerWidth - document.documentElement.clientWidth
1139
+ } catch { /* non-browser */ }
1140
+ if (body && body.style) {
1141
+ body.style.overflow = 'hidden'
1142
+ // 为被隐藏的经典滚动条补回等宽内边距,避免整页横向跳动。
1143
+ if (scrollbarW > 0) {
1144
+ const base = Number.parseFloat(getComputedStyle(body).paddingRight) || 0
1145
+ body.style.paddingRight = (base + scrollbarW) + 'px'
1146
+ }
1109
1147
  }
1110
1148
  return () => {
1111
1149
  clearTimeout(timer)
@@ -1114,6 +1152,10 @@ window.__ModuleLoader__.load({
1114
1152
  if (item.aria === null) item.child.removeAttribute('aria-hidden')
1115
1153
  else item.child.setAttribute('aria-hidden', item.aria)
1116
1154
  }
1155
+ if (body && body.style) {
1156
+ body.style.overflow = prevOverflow
1157
+ body.style.paddingRight = prevPaddingRight
1158
+ }
1117
1159
  if (openRef.current) return
1118
1160
  const trigger = triggerRef.current
1119
1161
  triggerRef.current = null