@amplifyup/sdk 0.2.1 → 0.2.3

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
@@ -410,7 +410,7 @@ function isComposerPreview() {
410
410
  if (window.self !== window.top && document.referrer) {
411
411
  try {
412
412
  const refUrl = new URL(document.referrer);
413
- if (refUrl.hostname === "amplifyup.ai" || refUrl.hostname.endsWith(".amplifyup.ai") || refUrl.hostname === "localhost" && refUrl.port === "5001" || refUrl.pathname.includes("/dashboard/composer") || refUrl.pathname.includes("/dashboard/routes/")) {
413
+ if (refUrl.hostname === "amplifyup.ai" || refUrl.hostname.endsWith(".amplifyup.ai") || refUrl.hostname === "localhost" && refUrl.port === "5001" || refUrl.pathname.includes("/dashboard/composer")) {
414
414
  return true;
415
415
  }
416
416
  } catch {
@@ -889,7 +889,8 @@ function layoutProviderCacheKey(opts) {
889
889
  opts.preview ? "1" : "0",
890
890
  opts.working ? "1" : "0",
891
891
  opts.zoneId || "",
892
- opts.compositionId || ""
892
+ opts.compositionId || "",
893
+ opts.layoutId || ""
893
894
  ].join("|");
894
895
  }
895
896
  function getSettledLayoutProvider(key) {
@@ -1408,7 +1409,7 @@ var AmplifyUpSDK = class {
1408
1409
  if (document.referrer) {
1409
1410
  try {
1410
1411
  const referrerUrl = new URL(document.referrer);
1411
- if (referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer") || referrerUrl.pathname.includes("/dashboard/routes/")) {
1412
+ if (referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer")) {
1412
1413
  return true;
1413
1414
  }
1414
1415
  } catch {
@@ -1685,11 +1686,7 @@ var AmplifyUpSDK = class {
1685
1686
  this.page(resumePath, { resumed: true });
1686
1687
  this.lastTrackedPath = resumePath;
1687
1688
  if (this.config?.debug) {
1688
- console.log(
1689
- "[AmplifyUp SDK] Idle resume page view",
1690
- resumePath,
1691
- `(hidden ${Math.round(idleMs / 6e4)}m)`
1692
- );
1689
+ console.log("[AmplifyUp SDK] Idle resume page view", resumePath, `(hidden ${Math.round(idleMs / 6e4)}m)`);
1693
1690
  }
1694
1691
  }
1695
1692
  noteActivity();
@@ -1709,12 +1706,7 @@ var AmplifyUpSDK = class {
1709
1706
  }
1710
1707
  state.visibleSince = null;
1711
1708
  };
1712
- const activityEvents = [
1713
- "pointerdown",
1714
- "keydown",
1715
- "scroll",
1716
- "touchstart"
1717
- ];
1709
+ const activityEvents = ["pointerdown", "keydown", "scroll", "touchstart"];
1718
1710
  const onActivity = () => noteActivity();
1719
1711
  window.addEventListener("scroll", onScroll, { passive: true });
1720
1712
  document.addEventListener("visibilitychange", onVisibility);
@@ -1862,11 +1854,7 @@ var AmplifyUpSDK = class {
1862
1854
  hosts.forEach((host) => observer.observe(host));
1863
1855
  this.componentViewObservers.push(observer);
1864
1856
  if (this.config?.debug) {
1865
- console.log(
1866
- "[AmplifyUp SDK] Component View tracking enabled for",
1867
- hosts.length,
1868
- "hosts"
1869
- );
1857
+ console.log("[AmplifyUp SDK] Component View tracking enabled for", hosts.length, "hosts");
1870
1858
  }
1871
1859
  }
1872
1860
  cleanupComponentViewTracking() {
@@ -2337,6 +2325,8 @@ Available Console Commands:
2337
2325
  const compositionId = pageSearch.get("compositionId");
2338
2326
  if (zoneId) params.set("zoneId", zoneId);
2339
2327
  if (compositionId) params.set("compositionId", compositionId);
2328
+ const layoutId = pageSearch.get("layoutId");
2329
+ if (layoutId) params.set("layoutId", layoutId);
2340
2330
  }
2341
2331
  }
2342
2332
  if (isOnOrchestratorOrigin) {
@@ -2357,7 +2347,8 @@ Available Console Commands:
2357
2347
  preview,
2358
2348
  working: pageSearch ? isWorkingContentRequest(pageSearch) : false,
2359
2349
  zoneId: pageSearch?.get("zoneId"),
2360
- compositionId: pageSearch?.get("compositionId")
2350
+ compositionId: pageSearch?.get("compositionId"),
2351
+ layoutId: pageSearch?.get("layoutId")
2361
2352
  });
2362
2353
  return dedupeLayoutProviderFetch(cacheKey, async () => {
2363
2354
  const startedAt = Date.now();
@@ -2439,15 +2430,11 @@ Available Console Commands:
2439
2430
  ) : document;
2440
2431
  if (!scopeRoot) {
2441
2432
  if (this.config?.debug) {
2442
- console.log(
2443
- `[AmplifyUp SDK] Component host not found for ${eventConfig.componentId}`
2444
- );
2433
+ console.log(`[AmplifyUp SDK] Component host not found for ${eventConfig.componentId}`);
2445
2434
  }
2446
2435
  return;
2447
2436
  }
2448
- targetElements = Array.from(
2449
- scopeRoot.querySelectorAll(eventConfig.selector)
2450
- );
2437
+ targetElements = Array.from(scopeRoot.querySelectorAll(eventConfig.selector));
2451
2438
  if (scopeRoot instanceof Element && scopeRoot !== document.documentElement && scopeRoot.matches?.(eventConfig.selector)) {
2452
2439
  targetElements.unshift(scopeRoot);
2453
2440
  }
@@ -2480,7 +2467,9 @@ Available Console Commands:
2480
2467
  });
2481
2468
  }
2482
2469
  if (this.config?.debug) {
2483
- console.log(`[AmplifyUp SDK] Attached ${eventConfig.eventType} listener for ${eventConfig.eventName} on selector: ${eventConfig.selector}`);
2470
+ console.log(
2471
+ `[AmplifyUp SDK] Attached ${eventConfig.eventType} listener for ${eventConfig.eventName} on selector: ${eventConfig.selector}`
2472
+ );
2484
2473
  }
2485
2474
  });
2486
2475
  });
@@ -2490,16 +2479,16 @@ Available Console Commands:
2490
2479
  */
2491
2480
  mapEventType(eventType) {
2492
2481
  const eventMap = {
2493
- "click": "click",
2494
- "submit": "submit",
2495
- "focus": "focus",
2496
- "blur": "blur",
2497
- "hover": "mouseenter",
2498
- "change": "change",
2499
- "scroll": "scroll",
2500
- "view": "view",
2482
+ click: "click",
2483
+ submit: "submit",
2484
+ focus: "focus",
2485
+ blur: "blur",
2486
+ hover: "mouseenter",
2487
+ change: "change",
2488
+ scroll: "scroll",
2489
+ view: "view",
2501
2490
  // Handled separately with IntersectionObserver
2502
- "custom": "custom"
2491
+ custom: "custom"
2503
2492
  };
2504
2493
  return eventMap[eventType] || eventType;
2505
2494
  }
@@ -2575,11 +2564,7 @@ Available Console Commands:
2575
2564
  (entries) => {
2576
2565
  entries.forEach((entry) => {
2577
2566
  if (entry.isIntersecting) {
2578
- this.handleTrackedEvent(
2579
- new CustomEvent("view"),
2580
- config,
2581
- element
2582
- );
2567
+ this.handleTrackedEvent(new CustomEvent("view"), config, element);
2583
2568
  observer.unobserve(element);
2584
2569
  }
2585
2570
  });
@@ -2722,21 +2707,15 @@ Available Console Commands:
2722
2707
  return;
2723
2708
  }
2724
2709
  if (event.data?.type === "AMPLIFYUP_FIELD_PATCH") {
2725
- window.dispatchEvent(
2726
- new CustomEvent("amplifyup:field-patch", { detail: event.data })
2727
- );
2710
+ window.dispatchEvent(new CustomEvent("amplifyup:field-patch", { detail: event.data }));
2728
2711
  return;
2729
2712
  }
2730
2713
  if (event.data?.type === "AMPLIFYUP_PROPS_PATCH") {
2731
- window.dispatchEvent(
2732
- new CustomEvent("amplifyup:props-patch", { detail: event.data })
2733
- );
2714
+ window.dispatchEvent(new CustomEvent("amplifyup:props-patch", { detail: event.data }));
2734
2715
  return;
2735
2716
  }
2736
2717
  if (event.data?.type === "AMPLIFYUP_LAYOUT_PATCH") {
2737
- window.dispatchEvent(
2738
- new CustomEvent("amplifyup:layout-patch", { detail: event.data })
2739
- );
2718
+ window.dispatchEvent(new CustomEvent("amplifyup:layout-patch", { detail: event.data }));
2740
2719
  return;
2741
2720
  }
2742
2721
  if (event.data?.type === "COMPONENT_DELETABLE_STATUS") {
@@ -2799,9 +2778,7 @@ Available Console Commands:
2799
2778
  const { componentId, slotName, nodeId, isPageSlot } = event.data;
2800
2779
  let element = null;
2801
2780
  if (isPageSlot || slotName === "main" && !nodeId && !componentId) {
2802
- element = document.querySelector(
2803
- '[data-slot-source="page"]'
2804
- );
2781
+ element = document.querySelector('[data-slot-source="page"]');
2805
2782
  }
2806
2783
  if (!element && nodeId && slotName) {
2807
2784
  element = document.querySelector(
@@ -2809,9 +2786,7 @@ Available Console Commands:
2809
2786
  );
2810
2787
  }
2811
2788
  if (!element && nodeId && !slotName) {
2812
- element = document.querySelector(
2813
- `[data-node-id="${nodeId}"]`
2814
- );
2789
+ element = document.querySelector(`[data-node-id="${nodeId}"]`);
2815
2790
  }
2816
2791
  if (!element && slotName) {
2817
2792
  element = document.querySelector(
@@ -2852,30 +2827,33 @@ Available Console Commands:
2852
2827
  };
2853
2828
  if (window.parent && window.parent !== window) {
2854
2829
  const hierarchyEls = this.buildComponentHierarchy(element);
2855
- window.parent.postMessage({
2856
- type: "ELEMENT_POSITION",
2857
- componentId: componentId || null,
2858
- slotName: slotName || null,
2859
- nodeId: nodeId || null,
2860
- isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
2861
- hierarchy: hierarchyEls.map((el, index) => {
2862
- const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
2863
- const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
2864
- const isSlot = !elComponentId && !!elSlotName;
2865
- const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
2866
- return {
2867
- index,
2868
- componentId: elComponentId,
2869
- componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
2870
- slotName: isSlot ? elSlotName : null,
2871
- isSlot,
2872
- isPageSlot: pageSlot,
2873
- nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
2874
- };
2875
- }),
2876
- position,
2877
- bounds
2878
- }, "*");
2830
+ window.parent.postMessage(
2831
+ {
2832
+ type: "ELEMENT_POSITION",
2833
+ componentId: componentId || null,
2834
+ slotName: slotName || null,
2835
+ nodeId: nodeId || null,
2836
+ isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
2837
+ hierarchy: hierarchyEls.map((el, index) => {
2838
+ const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
2839
+ const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
2840
+ const isSlot = !elComponentId && !!elSlotName;
2841
+ const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
2842
+ return {
2843
+ index,
2844
+ componentId: elComponentId,
2845
+ componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
2846
+ slotName: isSlot ? elSlotName : null,
2847
+ isSlot,
2848
+ isPageSlot: pageSlot,
2849
+ nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
2850
+ };
2851
+ }),
2852
+ position,
2853
+ bounds
2854
+ },
2855
+ "*"
2856
+ );
2879
2857
  }
2880
2858
  } else {
2881
2859
  console.warn("[AmplifyUp SDK] Element not found for position request");
@@ -2891,7 +2869,11 @@ Available Console Commands:
2891
2869
  switch (message.type) {
2892
2870
  case "ENABLE_HIGHLIGHTING":
2893
2871
  case "UPDATE_HIGHLIGHTING":
2894
- console.log("[AmplifyUp SDK] Enabling highlighting with registry:", message.componentRegistry?.length || 0, "components");
2872
+ console.log(
2873
+ "[AmplifyUp SDK] Enabling highlighting with registry:",
2874
+ message.componentRegistry?.length || 0,
2875
+ "components"
2876
+ );
2895
2877
  this.enableHighlighting(
2896
2878
  message.componentRegistry || [],
2897
2879
  message.highlightComponents ?? true,
@@ -2951,12 +2933,15 @@ Available Console Commands:
2951
2933
  const tagName = target.tagName.toLowerCase();
2952
2934
  const text = (target.textContent || "").replace(/\s+/g, " ").trim().substring(0, 80);
2953
2935
  if (window.parent && window.parent !== window) {
2954
- window.parent.postMessage({
2955
- type: "ELEMENT_CLICKED_FOR_EVENT",
2956
- selector,
2957
- tagName,
2958
- text
2959
- }, "*");
2936
+ window.parent.postMessage(
2937
+ {
2938
+ type: "ELEMENT_CLICKED_FOR_EVENT",
2939
+ selector,
2940
+ tagName,
2941
+ text
2942
+ },
2943
+ "*"
2944
+ );
2960
2945
  }
2961
2946
  };
2962
2947
  document.addEventListener("click", this.eventSelectionClickHandler, true);
@@ -2982,9 +2967,7 @@ Available Console Commands:
2982
2967
  return "[" + attr.name + '="' + attr.value + '"]';
2983
2968
  }
2984
2969
  if (el.className && typeof el.className === "string") {
2985
- const classes = el.className.split(" ").filter(
2986
- (c) => c && !c.startsWith("has-") && !c.includes("selectable") && !c.includes("selected")
2987
- );
2970
+ const classes = el.className.split(" ").filter((c) => c && !c.startsWith("has-") && !c.includes("selectable") && !c.includes("selected"));
2988
2971
  if (classes.length > 0) {
2989
2972
  return el.tagName.toLowerCase() + "." + classes[0];
2990
2973
  }
@@ -3034,9 +3017,7 @@ Available Console Commands:
3034
3017
  }
3035
3018
  });
3036
3019
  if (containing.length === 0) return null;
3037
- const innermost = containing.filter(
3038
- (el) => !containing.some((other) => other !== el && el.contains(other))
3039
- );
3020
+ const innermost = containing.filter((el) => !containing.some((other) => other !== el && el.contains(other)));
3040
3021
  if (innermost.length === 1) return innermost[0];
3041
3022
  let best = innermost[0];
3042
3023
  let bestArea = Infinity;
@@ -3153,9 +3134,7 @@ Available Console Commands:
3153
3134
  */
3154
3135
  enableHighlighting(componentRegistry, highlightComponents, showZones) {
3155
3136
  if (typeof document === "undefined") return;
3156
- const previouslySelected = Array.from(
3157
- document.querySelectorAll(".amplifyup-selected")
3158
- );
3137
+ const previouslySelected = Array.from(document.querySelectorAll(".amplifyup-selected"));
3159
3138
  this.componentRegistry = componentRegistry;
3160
3139
  this.highlightingEnabled = true;
3161
3140
  this.highlightComponentsEnabled = highlightComponents;
@@ -3528,10 +3507,7 @@ Available Console Commands:
3528
3507
  if (shouldReapply && this.highlightingEnabled) {
3529
3508
  setTimeout(() => {
3530
3509
  if (this.highlightingEnabled) {
3531
- this.applyComponentHighlights(
3532
- this.highlightComponentsEnabled,
3533
- this.showZonesEnabled
3534
- );
3510
+ this.applyComponentHighlights(this.highlightComponentsEnabled, this.showZonesEnabled);
3535
3511
  }
3536
3512
  }, 100);
3537
3513
  }
@@ -3540,7 +3516,13 @@ Available Console Commands:
3540
3516
  childList: true,
3541
3517
  subtree: true,
3542
3518
  attributes: true,
3543
- attributeFilter: ["data-amplifyup-component", "data-component-id", "data-amplifyup-slot", "data-slot-id", "data-slot-empty"]
3519
+ attributeFilter: [
3520
+ "data-amplifyup-component",
3521
+ "data-component-id",
3522
+ "data-amplifyup-slot",
3523
+ "data-slot-id",
3524
+ "data-slot-empty"
3525
+ ]
3544
3526
  });
3545
3527
  }
3546
3528
  /**
@@ -3554,9 +3536,7 @@ Available Console Commands:
3554
3536
  this.teardownComposerDragDrop();
3555
3537
  if (opts?.clearSelection !== false && typeof window !== "undefined") {
3556
3538
  window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
3557
- window.dispatchEvent(
3558
- new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } })
3559
- );
3539
+ window.dispatchEvent(new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } }));
3560
3540
  }
3561
3541
  if (this.mutationObserver) {
3562
3542
  this.mutationObserver.disconnect();
@@ -3714,7 +3694,10 @@ Available Console Commands:
3714
3694
  e.stopPropagation();
3715
3695
  this.sendSelectionMessage(htmlEl, hierarchy);
3716
3696
  if (window.parent && window.parent !== window) {
3717
- window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id }, "*");
3697
+ window.parent.postMessage(
3698
+ { type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id },
3699
+ "*"
3700
+ );
3718
3701
  }
3719
3702
  };
3720
3703
  htmlEl.addEventListener("click", handleClick);