@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.
@@ -3925,7 +3925,61 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
3925
3925
  };
3926
3926
  updatePosition();
3927
3927
  menu.style.visibility = "visible";
3928
- setTimeout(() => input.focus(), 0);
3928
+ const teardownDocFocusGuards = () => {
3929
+ document.removeEventListener("focusin", onDocFocusIn, true);
3930
+ document.removeEventListener("focusout", onDocFocusOut, true);
3931
+ };
3932
+ const onDocFocusIn = (e) => {
3933
+ var _a3, _b2;
3934
+ if (!menu.isConnected) {
3935
+ teardownDocFocusGuards();
3936
+ return;
3937
+ }
3938
+ const path = (_b2 = (_a3 = e.composedPath) == null ? void 0 : _a3.call(e)) != null ? _b2 : [];
3939
+ if (path.includes(menu)) {
3940
+ e.stopImmediatePropagation();
3941
+ }
3942
+ };
3943
+ const onDocFocusOut = (e) => {
3944
+ if (!menu.isConnected) {
3945
+ teardownDocFocusGuards();
3946
+ return;
3947
+ }
3948
+ const related = e.relatedTarget;
3949
+ if (!related) return;
3950
+ if (related === shadowRoot.host) {
3951
+ e.stopImmediatePropagation();
3952
+ return;
3953
+ }
3954
+ if (related instanceof Node && menu.contains(related)) {
3955
+ e.stopImmediatePropagation();
3956
+ }
3957
+ };
3958
+ document.addEventListener("focusin", onDocFocusIn, true);
3959
+ document.addEventListener("focusout", onDocFocusOut, true);
3960
+ const focusAskInput = () => {
3961
+ try {
3962
+ input.focus({ preventScroll: true });
3963
+ } catch (e) {
3964
+ input.focus();
3965
+ }
3966
+ };
3967
+ const isAskInputFocused = () => {
3968
+ try {
3969
+ return shadowRoot.activeElement === input;
3970
+ } catch (e) {
3971
+ return false;
3972
+ }
3973
+ };
3974
+ focusAskInput();
3975
+ const rafId = requestAnimationFrame(() => {
3976
+ if (!menu.isConnected) return;
3977
+ if (!isAskInputFocused()) focusAskInput();
3978
+ });
3979
+ const focusTimeoutId = setTimeout(() => {
3980
+ if (!menu.isConnected) return;
3981
+ if (!isAskInputFocused()) focusAskInput();
3982
+ }, 50);
3929
3983
  const onDocClick = (e) => {
3930
3984
  const eventTarget = e.target;
3931
3985
  if (eventTarget) {
@@ -3942,6 +3996,9 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
3942
3996
  setTimeout(() => document.addEventListener("click", onDocClick, { capture: true }), 0);
3943
3997
  function cleanup() {
3944
3998
  document.removeEventListener("click", onDocClick, { capture: true });
3999
+ teardownDocFocusGuards();
4000
+ cancelAnimationFrame(rafId);
4001
+ clearTimeout(focusTimeoutId);
3945
4002
  menu.remove();
3946
4003
  onClose();
3947
4004
  }
@@ -6499,4 +6556,4 @@ if (typeof customElements !== "undefined" && !customElements.get("inspecto-overl
6499
6556
  export {
6500
6557
  InspectoElement
6501
6558
  };
6502
- //# sourceMappingURL=component-YOUXVPMF.js.map
6559
+ //# sourceMappingURL=component-PVWVSPVZ.js.map