@andy.ian/dsh-homing 2.3.7 → 2.3.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.
- package/lib/mobile-patch.mjs +21 -5
- package/package.json +1 -1
package/lib/mobile-patch.mjs
CHANGED
|
@@ -145,20 +145,33 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
145
145
|
return matches[matches.length - 1]
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
/** 从点击目标向上找图片文件名;菜单/侧栏里的点击不处理。
|
|
148
|
+
/** 从点击目标向上找图片文件名;菜单/侧栏里的点击不处理。
|
|
149
|
+
* 返回 { name, node }:node 是真正带文件名的那个祖先容器(用于判断点击是不是落在卡片内的操作按钮上)。 */
|
|
149
150
|
const findClickImageName = (target) => {
|
|
150
151
|
let node = target
|
|
151
152
|
for (let depth = 0; depth < 10 && node !== null && node !== undefined; depth += 1) {
|
|
152
153
|
if (typeof node.closest === 'function') {
|
|
153
154
|
for (const selector of CLICK_IGNORE_SELECTORS) {
|
|
154
|
-
if (node.closest(selector) !== null) return ''
|
|
155
|
+
if (node.closest(selector) !== null) return { name: '', node: null }
|
|
155
156
|
}
|
|
156
157
|
}
|
|
157
158
|
const name = pickImageFileName(node.textContent || '')
|
|
158
|
-
if (name !== '') return name
|
|
159
|
+
if (name !== '') return { name, node }
|
|
159
160
|
node = node.parentElement
|
|
160
161
|
}
|
|
161
|
-
return ''
|
|
162
|
+
return { name: '', node: null }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 点击目标与带文件名的容器之间是否夹着按钮类控件(卡片右侧的下拉箭头、更多按钮等)。
|
|
166
|
+
* 这类控件的文字往往只有图标、不含文件名,但祖先卡片文字里有 —— 不能把它们算作"点卡片"。 */
|
|
167
|
+
const CONTROL_SELECTOR = 'button, [role="button"], [aria-haspopup], [aria-expanded], [tabindex], [data-state]'
|
|
168
|
+
const findNestedControl = (target, stopAt) => {
|
|
169
|
+
let node = target
|
|
170
|
+
while (node !== null && node !== undefined && node !== stopAt) {
|
|
171
|
+
if (typeof node.matches === 'function' && node.matches(CONTROL_SELECTOR)) return node
|
|
172
|
+
node = node.parentElement
|
|
173
|
+
}
|
|
174
|
+
return null
|
|
162
175
|
}
|
|
163
176
|
|
|
164
177
|
/** 打开某文件的预览页:先让服务端按文件名/相对路径在工作区里解析。 */
|
|
@@ -175,8 +188,11 @@ export const MOBILE_JS = String.raw`(() => {
|
|
|
175
188
|
try {
|
|
176
189
|
const target = event.target
|
|
177
190
|
if (target === null || target === undefined) return
|
|
178
|
-
const
|
|
191
|
+
const found = findClickImageName(target)
|
|
192
|
+
const name = found.name
|
|
179
193
|
if (name === '') return
|
|
194
|
+
// 卡片内的下拉箭头/更多按钮:应该弹出它自己的菜单,不能被我们拐去预览页
|
|
195
|
+
if (findNestedControl(target, found.node) !== null) return
|
|
180
196
|
// 已经是我们自己的文件链接(比如文件页里的图片名),不要二次拦截
|
|
181
197
|
const anchor = typeof target.closest === 'function' ? target.closest('a[href]') : null
|
|
182
198
|
if (anchor !== null && /^\/files\//u.test(String(anchor.getAttribute('href') ?? ''))) return
|