@inspecto-dev/core 0.3.6 → 0.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/dist/index.cjs CHANGED
@@ -2206,9 +2206,29 @@ function parseAttrValue(value) {
2206
2206
  if (isNaN(line) || isNaN(col) || !file) return null;
2207
2207
  return { file, line, column: col };
2208
2208
  }
2209
+ function parseAstroAttrValue(file, loc) {
2210
+ const parts = loc.split(":");
2211
+ if (parts.length !== 2) return null;
2212
+ const line = parseInt(parts[0], 10);
2213
+ const column = parseInt(parts[1], 10);
2214
+ if (isNaN(line) || isNaN(column) || !file) return null;
2215
+ return { file, line, column };
2216
+ }
2217
+ function getInspectableLocation(el) {
2218
+ const attrValue = el.getAttribute(ATTR_NAME);
2219
+ if (attrValue) {
2220
+ return parseAttrValue(attrValue);
2221
+ }
2222
+ const astroFile = el.getAttribute(ASTRO_FILE_ATTR_NAME);
2223
+ const astroLoc = el.getAttribute(ASTRO_LOC_ATTR_NAME);
2224
+ if (astroFile && astroLoc) {
2225
+ return parseAstroAttrValue(astroFile, astroLoc);
2226
+ }
2227
+ return null;
2228
+ }
2209
2229
  function findInspectable(el) {
2210
2230
  while (el) {
2211
- if (el.hasAttribute(ATTR_NAME)) return el;
2231
+ if (getInspectableLocation(el)) return el;
2212
2232
  el = el.parentElement;
2213
2233
  }
2214
2234
  return null;
@@ -2258,11 +2278,13 @@ function createElementSelector(element) {
2258
2278
  }
2259
2279
  return segments.join(" > ");
2260
2280
  }
2261
- var ATTR_NAME;
2281
+ var ATTR_NAME, ASTRO_FILE_ATTR_NAME, ASTRO_LOC_ATTR_NAME;
2262
2282
  var init_component_utils = __esm({
2263
2283
  "src/component-utils.ts"() {
2264
2284
  "use strict";
2265
2285
  ATTR_NAME = "data-inspecto";
2286
+ ASTRO_FILE_ATTR_NAME = "data-astro-source-file";
2287
+ ASTRO_LOC_ATTR_NAME = "data-astro-source-loc";
2266
2288
  }
2267
2289
  });
2268
2290
 
@@ -2424,7 +2446,16 @@ function findElementForLocation(_ctx, location, selector) {
2424
2446
  const byLocation = Array.from(document.querySelectorAll(`[${ATTR_NAME}]`)).find(
2425
2447
  (candidate) => candidate.getAttribute(ATTR_NAME) === locationAttr
2426
2448
  );
2427
- return byLocation instanceof Element ? byLocation : null;
2449
+ if (byLocation instanceof Element) {
2450
+ return byLocation;
2451
+ }
2452
+ const byAstroLocation = Array.from(
2453
+ document.querySelectorAll("[data-astro-source-file][data-astro-source-loc]")
2454
+ ).find((candidate) => {
2455
+ const candidateLocation = getInspectableLocation(candidate);
2456
+ return (candidateLocation == null ? void 0 : candidateLocation.file) === location.file && candidateLocation.line === location.line && candidateLocation.column === location.column;
2457
+ });
2458
+ return byAstroLocation instanceof Element ? byAstroLocation : null;
2428
2459
  }
2429
2460
  function rebindCurrentAnnotationElements(ctx) {
2430
2461
  const state = asAnnotateContext(ctx);
@@ -4174,7 +4205,61 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
4174
4205
  };
4175
4206
  updatePosition();
4176
4207
  menu.style.visibility = "visible";
4177
- setTimeout(() => input.focus(), 0);
4208
+ const teardownDocFocusGuards = () => {
4209
+ document.removeEventListener("focusin", onDocFocusIn, true);
4210
+ document.removeEventListener("focusout", onDocFocusOut, true);
4211
+ };
4212
+ const onDocFocusIn = (e) => {
4213
+ var _a3, _b2;
4214
+ if (!menu.isConnected) {
4215
+ teardownDocFocusGuards();
4216
+ return;
4217
+ }
4218
+ const path = (_b2 = (_a3 = e.composedPath) == null ? void 0 : _a3.call(e)) != null ? _b2 : [];
4219
+ if (path.includes(menu)) {
4220
+ e.stopImmediatePropagation();
4221
+ }
4222
+ };
4223
+ const onDocFocusOut = (e) => {
4224
+ if (!menu.isConnected) {
4225
+ teardownDocFocusGuards();
4226
+ return;
4227
+ }
4228
+ const related = e.relatedTarget;
4229
+ if (!related) return;
4230
+ if (related === shadowRoot.host) {
4231
+ e.stopImmediatePropagation();
4232
+ return;
4233
+ }
4234
+ if (related instanceof Node && menu.contains(related)) {
4235
+ e.stopImmediatePropagation();
4236
+ }
4237
+ };
4238
+ document.addEventListener("focusin", onDocFocusIn, true);
4239
+ document.addEventListener("focusout", onDocFocusOut, true);
4240
+ const focusAskInput = () => {
4241
+ try {
4242
+ input.focus({ preventScroll: true });
4243
+ } catch (e) {
4244
+ input.focus();
4245
+ }
4246
+ };
4247
+ const isAskInputFocused = () => {
4248
+ try {
4249
+ return shadowRoot.activeElement === input;
4250
+ } catch (e) {
4251
+ return false;
4252
+ }
4253
+ };
4254
+ focusAskInput();
4255
+ const rafId = requestAnimationFrame(() => {
4256
+ if (!menu.isConnected) return;
4257
+ if (!isAskInputFocused()) focusAskInput();
4258
+ });
4259
+ const focusTimeoutId = setTimeout(() => {
4260
+ if (!menu.isConnected) return;
4261
+ if (!isAskInputFocused()) focusAskInput();
4262
+ }, 50);
4178
4263
  const onDocClick = (e) => {
4179
4264
  const eventTarget = e.target;
4180
4265
  if (eventTarget) {
@@ -4191,6 +4276,9 @@ function showIntentMenu(shadowRoot, location, clickX, clickY, options, onClose,
4191
4276
  setTimeout(() => document.addEventListener("click", onDocClick, { capture: true }), 0);
4192
4277
  function cleanup() {
4193
4278
  document.removeEventListener("click", onDocClick, { capture: true });
4279
+ teardownDocFocusGuards();
4280
+ cancelAnimationFrame(rafId);
4281
+ clearTimeout(focusTimeoutId);
4194
4282
  menu.remove();
4195
4283
  onClose();
4196
4284
  }
@@ -5067,9 +5155,8 @@ function handleMouseMove(ctx, event) {
5067
5155
  state.overlay.hide();
5068
5156
  return;
5069
5157
  }
5070
- const attrValue = target.getAttribute(ATTR_NAME);
5071
- const loc = parseAttrValue(attrValue);
5072
- const label = loc ? `${(_a2 = loc.file.split("/").pop()) != null ? _a2 : ""}:${loc.line}` : attrValue;
5158
+ const loc = getInspectableLocation(target);
5159
+ const label = loc ? `${(_a2 = loc.file.split("/").pop()) != null ? _a2 : ""}:${loc.line}` : "";
5073
5160
  if (state.mode === "annotate" && state.annotateCapturePaused) {
5074
5161
  state.overlay.hide();
5075
5162
  return;
@@ -5096,8 +5183,7 @@ function handleTrigger(ctx, event) {
5096
5183
  if (state.mode === "annotate" && state.annotateCapturePaused) return;
5097
5184
  event.preventDefault();
5098
5185
  event.stopPropagation();
5099
- const attrValue = target.getAttribute(ATTR_NAME);
5100
- const loc = parseAttrValue(attrValue);
5186
+ const loc = getInspectableLocation(target);
5101
5187
  if (!loc) return;
5102
5188
  if (state.mode === "annotate") {
5103
5189
  if (state.annotateQuickCaptureEnabled) {
@@ -5117,10 +5203,13 @@ function handleTrigger(ctx, event) {
5117
5203
  state.openInspectMenu(loc, event.clientX, event.clientY, target);
5118
5204
  }
5119
5205
  function handleKeyDown(ctx, event) {
5120
- var _a2;
5121
5206
  const state = asInteractionContext(ctx);
5122
5207
  if (event.key === "Escape") {
5123
- (_a2 = state.cleanupMenu) == null ? void 0 : _a2.call(state);
5208
+ if (state.cleanupMenu !== null) {
5209
+ state.cleanupMenu();
5210
+ } else if (!state.disabled) {
5211
+ state.pause();
5212
+ }
5124
5213
  state.overlay.hide();
5125
5214
  }
5126
5215
  state.updateLauncherEye();
@@ -6722,6 +6811,9 @@ var init_component = __esm({
6722
6811
  updateLauncherEye() {
6723
6812
  updateLauncherEye(this);
6724
6813
  }
6814
+ pause() {
6815
+ this.setPaused(true);
6816
+ }
6725
6817
  openInspectMenu(loc, clientX, clientY, targetElement) {
6726
6818
  openInspectMenu(this, loc, clientX, clientY, targetElement);
6727
6819
  }
@@ -6893,7 +6985,7 @@ var TAG_NAME = "inspecto-overlay";
6893
6985
  function mountInspector() {
6894
6986
  return __async(this, arguments, function* (options = {}) {
6895
6987
  if (typeof document === "undefined") return null;
6896
- const { InspectoElement: InspectoElement2 } = yield Promise.resolve().then(() => (init_component(), component_exports));
6988
+ const { InspectoElement: _InspectoElement } = yield Promise.resolve().then(() => (init_component(), component_exports));
6897
6989
  const existing = document.querySelector(TAG_NAME);
6898
6990
  if (existing) {
6899
6991
  ;