@amplifyup/sdk 0.1.30 → 0.1.32

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.mjs CHANGED
@@ -552,6 +552,8 @@ var AmplifyUpSDK = class {
552
552
  this.showZonesEnabled = false;
553
553
  this.componentRegistry = [];
554
554
  this.messageListener = null;
555
+ this.composerBoundsRaf = 0;
556
+ this.composerBoundsScrollListener = null;
555
557
  this.mutationObserver = null;
556
558
  this.composerDragHandlers = null;
557
559
  /** Last slot highlighted during Composer drag — avoid clear/re-add flicker. */
@@ -1605,6 +1607,11 @@ Available Console Commands:
1605
1607
  if (config.componentName) {
1606
1608
  properties.componentName = config.componentName;
1607
1609
  }
1610
+ if (config.staticProperties) {
1611
+ for (const [key, value] of Object.entries(config.staticProperties)) {
1612
+ if (key) properties[key] = value;
1613
+ }
1614
+ }
1608
1615
  if (config.properties && config.properties.length > 0) {
1609
1616
  config.properties.forEach((prop) => {
1610
1617
  const dataAttrValue = element.getAttribute(`data-${prop}`);
@@ -1971,13 +1978,23 @@ Available Console Commands:
1971
1978
  document.removeEventListener("click", this.eventSelectionClickHandler, true);
1972
1979
  this.eventSelectionClickHandler = null;
1973
1980
  }
1981
+ if (enabled && typeof window !== "undefined" && window.__AMPLIFYUP_PREVIEW_MODE__) {
1982
+ return;
1983
+ }
1974
1984
  if (enabled) {
1975
1985
  this.eventSelectionClickHandler = (e) => {
1976
- const target = e.target;
1977
- if (!target) return;
1986
+ const raw = e.target;
1987
+ if (!raw) return;
1988
+ const interactive = raw.closest(
1989
+ 'a, button, [role="button"], input, select, textarea, [data-el], [data-amplifyup-component], [data-component-id]'
1990
+ );
1991
+ const target = interactive instanceof HTMLElement ? interactive : raw;
1992
+ e.preventDefault();
1993
+ e.stopPropagation();
1994
+ e.stopImmediatePropagation();
1978
1995
  const selector = this.generateSelectorForElement(target);
1979
1996
  const tagName = target.tagName.toLowerCase();
1980
- const text = target.textContent?.trim().substring(0, 50) || "";
1997
+ const text = (target.textContent || "").replace(/\s+/g, " ").trim().substring(0, 80);
1981
1998
  if (window.parent && window.parent !== window) {
1982
1999
  window.parent.postMessage({
1983
2000
  type: "ELEMENT_CLICKED_FOR_EVENT",
@@ -1986,9 +2003,6 @@ Available Console Commands:
1986
2003
  text
1987
2004
  }, "*");
1988
2005
  }
1989
- if (tagName === "a") {
1990
- e.preventDefault();
1991
- }
1992
2006
  };
1993
2007
  document.addEventListener("click", this.eventSelectionClickHandler, true);
1994
2008
  if (this.config?.debug) {
@@ -2198,6 +2212,7 @@ Available Console Commands:
2198
2212
  this.applyComponentHighlights(highlightComponents, showZones);
2199
2213
  this.setupMutationObserver();
2200
2214
  this.setupComposerDragDrop();
2215
+ this.setupComposerBoundsTracking();
2201
2216
  }
2202
2217
  previouslySelected.forEach((el) => {
2203
2218
  if (document.contains(el)) {
@@ -2352,6 +2367,52 @@ Available Console Commands:
2352
2367
  this.clearComposerSelection();
2353
2368
  element.classList.add("amplifyup-selected");
2354
2369
  }
2370
+ postComposerSelectionBounds() {
2371
+ if (typeof document === "undefined") return;
2372
+ if (!window.parent || window.parent === window) return;
2373
+ const el = document.querySelector(".amplifyup-selected");
2374
+ if (!el) return;
2375
+ const rect = el.getBoundingClientRect();
2376
+ window.parent.postMessage(
2377
+ {
2378
+ type: "SELECTION_BOUNDS",
2379
+ bounds: {
2380
+ top: rect.top,
2381
+ left: rect.left,
2382
+ width: rect.width,
2383
+ height: rect.height
2384
+ }
2385
+ },
2386
+ "*"
2387
+ );
2388
+ }
2389
+ setupComposerBoundsTracking() {
2390
+ if (typeof document === "undefined") return;
2391
+ this.teardownComposerBoundsTracking();
2392
+ const onScroll = () => {
2393
+ if (this.composerBoundsRaf) return;
2394
+ this.composerBoundsRaf = requestAnimationFrame(() => {
2395
+ this.composerBoundsRaf = 0;
2396
+ this.postComposerSelectionBounds();
2397
+ });
2398
+ };
2399
+ this.composerBoundsScrollListener = onScroll;
2400
+ document.addEventListener("scroll", onScroll, { capture: true, passive: true });
2401
+ window.addEventListener("scroll", onScroll, { capture: true, passive: true });
2402
+ window.addEventListener("resize", onScroll);
2403
+ }
2404
+ teardownComposerBoundsTracking() {
2405
+ const onScroll = this.composerBoundsScrollListener;
2406
+ this.composerBoundsScrollListener = null;
2407
+ if (this.composerBoundsRaf) {
2408
+ cancelAnimationFrame(this.composerBoundsRaf);
2409
+ this.composerBoundsRaf = 0;
2410
+ }
2411
+ if (!onScroll || typeof document === "undefined") return;
2412
+ document.removeEventListener("scroll", onScroll, true);
2413
+ window.removeEventListener("scroll", onScroll, true);
2414
+ window.removeEventListener("resize", onScroll);
2415
+ }
2355
2416
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
2356
2417
  injectComposerHighlightStyles(highlightComponents, showZones) {
2357
2418
  if (typeof document === "undefined") return;
@@ -2519,6 +2580,7 @@ Available Console Commands:
2519
2580
  if (typeof document === "undefined") return;
2520
2581
  const clearSelection = opts?.clearSelection !== false;
2521
2582
  this.highlightingEnabled = false;
2583
+ this.teardownComposerBoundsTracking();
2522
2584
  this.teardownComposerDragDrop();
2523
2585
  if (opts?.clearSelection !== false && typeof window !== "undefined") {
2524
2586
  window.__AMPLIFYUP_COMPOSER_EDIT__ = false;