@inspecto-dev/core 0.3.6 → 0.3.7
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/dist/index.cjs
CHANGED
|
@@ -4174,7 +4174,61 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
|
|
|
4174
4174
|
};
|
|
4175
4175
|
updatePosition();
|
|
4176
4176
|
menu.style.visibility = "visible";
|
|
4177
|
-
|
|
4177
|
+
const teardownDocFocusGuards = () => {
|
|
4178
|
+
document.removeEventListener("focusin", onDocFocusIn, true);
|
|
4179
|
+
document.removeEventListener("focusout", onDocFocusOut, true);
|
|
4180
|
+
};
|
|
4181
|
+
const onDocFocusIn = (e) => {
|
|
4182
|
+
var _a3, _b2;
|
|
4183
|
+
if (!menu.isConnected) {
|
|
4184
|
+
teardownDocFocusGuards();
|
|
4185
|
+
return;
|
|
4186
|
+
}
|
|
4187
|
+
const path = (_b2 = (_a3 = e.composedPath) == null ? void 0 : _a3.call(e)) != null ? _b2 : [];
|
|
4188
|
+
if (path.includes(menu)) {
|
|
4189
|
+
e.stopImmediatePropagation();
|
|
4190
|
+
}
|
|
4191
|
+
};
|
|
4192
|
+
const onDocFocusOut = (e) => {
|
|
4193
|
+
if (!menu.isConnected) {
|
|
4194
|
+
teardownDocFocusGuards();
|
|
4195
|
+
return;
|
|
4196
|
+
}
|
|
4197
|
+
const related = e.relatedTarget;
|
|
4198
|
+
if (!related) return;
|
|
4199
|
+
if (related === shadowRoot.host) {
|
|
4200
|
+
e.stopImmediatePropagation();
|
|
4201
|
+
return;
|
|
4202
|
+
}
|
|
4203
|
+
if (related instanceof Node && menu.contains(related)) {
|
|
4204
|
+
e.stopImmediatePropagation();
|
|
4205
|
+
}
|
|
4206
|
+
};
|
|
4207
|
+
document.addEventListener("focusin", onDocFocusIn, true);
|
|
4208
|
+
document.addEventListener("focusout", onDocFocusOut, true);
|
|
4209
|
+
const focusAskInput = () => {
|
|
4210
|
+
try {
|
|
4211
|
+
input.focus({ preventScroll: true });
|
|
4212
|
+
} catch (e) {
|
|
4213
|
+
input.focus();
|
|
4214
|
+
}
|
|
4215
|
+
};
|
|
4216
|
+
const isAskInputFocused = () => {
|
|
4217
|
+
try {
|
|
4218
|
+
return shadowRoot.activeElement === input;
|
|
4219
|
+
} catch (e) {
|
|
4220
|
+
return false;
|
|
4221
|
+
}
|
|
4222
|
+
};
|
|
4223
|
+
focusAskInput();
|
|
4224
|
+
const rafId = requestAnimationFrame(() => {
|
|
4225
|
+
if (!menu.isConnected) return;
|
|
4226
|
+
if (!isAskInputFocused()) focusAskInput();
|
|
4227
|
+
});
|
|
4228
|
+
const focusTimeoutId = setTimeout(() => {
|
|
4229
|
+
if (!menu.isConnected) return;
|
|
4230
|
+
if (!isAskInputFocused()) focusAskInput();
|
|
4231
|
+
}, 50);
|
|
4178
4232
|
const onDocClick = (e) => {
|
|
4179
4233
|
const eventTarget = e.target;
|
|
4180
4234
|
if (eventTarget) {
|
|
@@ -4191,6 +4245,9 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
|
|
|
4191
4245
|
setTimeout(() => document.addEventListener("click", onDocClick, { capture: true }), 0);
|
|
4192
4246
|
function cleanup() {
|
|
4193
4247
|
document.removeEventListener("click", onDocClick, { capture: true });
|
|
4248
|
+
teardownDocFocusGuards();
|
|
4249
|
+
cancelAnimationFrame(rafId);
|
|
4250
|
+
clearTimeout(focusTimeoutId);
|
|
4194
4251
|
menu.remove();
|
|
4195
4252
|
onClose();
|
|
4196
4253
|
}
|