@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.js CHANGED
@@ -414,7 +414,7 @@ function isComposerPreview() {
414
414
  if (window.self !== window.top && document.referrer) {
415
415
  try {
416
416
  const refUrl = new URL(document.referrer);
417
- 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/")) {
417
+ if (refUrl.hostname === "amplifyup.ai" || refUrl.hostname.endsWith(".amplifyup.ai") || refUrl.hostname === "localhost" && refUrl.port === "5001" || refUrl.pathname.includes("/dashboard/composer")) {
418
418
  return true;
419
419
  }
420
420
  } catch {
@@ -893,7 +893,8 @@ function layoutProviderCacheKey(opts) {
893
893
  opts.preview ? "1" : "0",
894
894
  opts.working ? "1" : "0",
895
895
  opts.zoneId || "",
896
- opts.compositionId || ""
896
+ opts.compositionId || "",
897
+ opts.layoutId || ""
897
898
  ].join("|");
898
899
  }
899
900
  function getSettledLayoutProvider(key) {
@@ -1412,7 +1413,7 @@ var AmplifyUpSDK = class {
1412
1413
  if (document.referrer) {
1413
1414
  try {
1414
1415
  const referrerUrl = new URL(document.referrer);
1415
- if (referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer") || referrerUrl.pathname.includes("/dashboard/routes/")) {
1416
+ if (referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer")) {
1416
1417
  return true;
1417
1418
  }
1418
1419
  } catch {
@@ -1689,11 +1690,7 @@ var AmplifyUpSDK = class {
1689
1690
  this.page(resumePath, { resumed: true });
1690
1691
  this.lastTrackedPath = resumePath;
1691
1692
  if (this.config?.debug) {
1692
- console.log(
1693
- "[AmplifyUp SDK] Idle resume page view",
1694
- resumePath,
1695
- `(hidden ${Math.round(idleMs / 6e4)}m)`
1696
- );
1693
+ console.log("[AmplifyUp SDK] Idle resume page view", resumePath, `(hidden ${Math.round(idleMs / 6e4)}m)`);
1697
1694
  }
1698
1695
  }
1699
1696
  noteActivity();
@@ -1713,12 +1710,7 @@ var AmplifyUpSDK = class {
1713
1710
  }
1714
1711
  state.visibleSince = null;
1715
1712
  };
1716
- const activityEvents = [
1717
- "pointerdown",
1718
- "keydown",
1719
- "scroll",
1720
- "touchstart"
1721
- ];
1713
+ const activityEvents = ["pointerdown", "keydown", "scroll", "touchstart"];
1722
1714
  const onActivity = () => noteActivity();
1723
1715
  window.addEventListener("scroll", onScroll, { passive: true });
1724
1716
  document.addEventListener("visibilitychange", onVisibility);
@@ -1866,11 +1858,7 @@ var AmplifyUpSDK = class {
1866
1858
  hosts.forEach((host) => observer.observe(host));
1867
1859
  this.componentViewObservers.push(observer);
1868
1860
  if (this.config?.debug) {
1869
- console.log(
1870
- "[AmplifyUp SDK] Component View tracking enabled for",
1871
- hosts.length,
1872
- "hosts"
1873
- );
1861
+ console.log("[AmplifyUp SDK] Component View tracking enabled for", hosts.length, "hosts");
1874
1862
  }
1875
1863
  }
1876
1864
  cleanupComponentViewTracking() {
@@ -2341,6 +2329,8 @@ Available Console Commands:
2341
2329
  const compositionId = pageSearch.get("compositionId");
2342
2330
  if (zoneId) params.set("zoneId", zoneId);
2343
2331
  if (compositionId) params.set("compositionId", compositionId);
2332
+ const layoutId = pageSearch.get("layoutId");
2333
+ if (layoutId) params.set("layoutId", layoutId);
2344
2334
  }
2345
2335
  }
2346
2336
  if (isOnOrchestratorOrigin) {
@@ -2361,7 +2351,8 @@ Available Console Commands:
2361
2351
  preview,
2362
2352
  working: pageSearch ? isWorkingContentRequest(pageSearch) : false,
2363
2353
  zoneId: pageSearch?.get("zoneId"),
2364
- compositionId: pageSearch?.get("compositionId")
2354
+ compositionId: pageSearch?.get("compositionId"),
2355
+ layoutId: pageSearch?.get("layoutId")
2365
2356
  });
2366
2357
  return dedupeLayoutProviderFetch(cacheKey, async () => {
2367
2358
  const startedAt = Date.now();
@@ -2443,15 +2434,11 @@ Available Console Commands:
2443
2434
  ) : document;
2444
2435
  if (!scopeRoot) {
2445
2436
  if (this.config?.debug) {
2446
- console.log(
2447
- `[AmplifyUp SDK] Component host not found for ${eventConfig.componentId}`
2448
- );
2437
+ console.log(`[AmplifyUp SDK] Component host not found for ${eventConfig.componentId}`);
2449
2438
  }
2450
2439
  return;
2451
2440
  }
2452
- targetElements = Array.from(
2453
- scopeRoot.querySelectorAll(eventConfig.selector)
2454
- );
2441
+ targetElements = Array.from(scopeRoot.querySelectorAll(eventConfig.selector));
2455
2442
  if (scopeRoot instanceof Element && scopeRoot !== document.documentElement && scopeRoot.matches?.(eventConfig.selector)) {
2456
2443
  targetElements.unshift(scopeRoot);
2457
2444
  }
@@ -2484,7 +2471,9 @@ Available Console Commands:
2484
2471
  });
2485
2472
  }
2486
2473
  if (this.config?.debug) {
2487
- console.log(`[AmplifyUp SDK] Attached ${eventConfig.eventType} listener for ${eventConfig.eventName} on selector: ${eventConfig.selector}`);
2474
+ console.log(
2475
+ `[AmplifyUp SDK] Attached ${eventConfig.eventType} listener for ${eventConfig.eventName} on selector: ${eventConfig.selector}`
2476
+ );
2488
2477
  }
2489
2478
  });
2490
2479
  });
@@ -2494,16 +2483,16 @@ Available Console Commands:
2494
2483
  */
2495
2484
  mapEventType(eventType) {
2496
2485
  const eventMap = {
2497
- "click": "click",
2498
- "submit": "submit",
2499
- "focus": "focus",
2500
- "blur": "blur",
2501
- "hover": "mouseenter",
2502
- "change": "change",
2503
- "scroll": "scroll",
2504
- "view": "view",
2486
+ click: "click",
2487
+ submit: "submit",
2488
+ focus: "focus",
2489
+ blur: "blur",
2490
+ hover: "mouseenter",
2491
+ change: "change",
2492
+ scroll: "scroll",
2493
+ view: "view",
2505
2494
  // Handled separately with IntersectionObserver
2506
- "custom": "custom"
2495
+ custom: "custom"
2507
2496
  };
2508
2497
  return eventMap[eventType] || eventType;
2509
2498
  }
@@ -2579,11 +2568,7 @@ Available Console Commands:
2579
2568
  (entries) => {
2580
2569
  entries.forEach((entry) => {
2581
2570
  if (entry.isIntersecting) {
2582
- this.handleTrackedEvent(
2583
- new CustomEvent("view"),
2584
- config,
2585
- element
2586
- );
2571
+ this.handleTrackedEvent(new CustomEvent("view"), config, element);
2587
2572
  observer.unobserve(element);
2588
2573
  }
2589
2574
  });
@@ -2726,21 +2711,15 @@ Available Console Commands:
2726
2711
  return;
2727
2712
  }
2728
2713
  if (event.data?.type === "AMPLIFYUP_FIELD_PATCH") {
2729
- window.dispatchEvent(
2730
- new CustomEvent("amplifyup:field-patch", { detail: event.data })
2731
- );
2714
+ window.dispatchEvent(new CustomEvent("amplifyup:field-patch", { detail: event.data }));
2732
2715
  return;
2733
2716
  }
2734
2717
  if (event.data?.type === "AMPLIFYUP_PROPS_PATCH") {
2735
- window.dispatchEvent(
2736
- new CustomEvent("amplifyup:props-patch", { detail: event.data })
2737
- );
2718
+ window.dispatchEvent(new CustomEvent("amplifyup:props-patch", { detail: event.data }));
2738
2719
  return;
2739
2720
  }
2740
2721
  if (event.data?.type === "AMPLIFYUP_LAYOUT_PATCH") {
2741
- window.dispatchEvent(
2742
- new CustomEvent("amplifyup:layout-patch", { detail: event.data })
2743
- );
2722
+ window.dispatchEvent(new CustomEvent("amplifyup:layout-patch", { detail: event.data }));
2744
2723
  return;
2745
2724
  }
2746
2725
  if (event.data?.type === "COMPONENT_DELETABLE_STATUS") {
@@ -2803,9 +2782,7 @@ Available Console Commands:
2803
2782
  const { componentId, slotName, nodeId, isPageSlot } = event.data;
2804
2783
  let element = null;
2805
2784
  if (isPageSlot || slotName === "main" && !nodeId && !componentId) {
2806
- element = document.querySelector(
2807
- '[data-slot-source="page"]'
2808
- );
2785
+ element = document.querySelector('[data-slot-source="page"]');
2809
2786
  }
2810
2787
  if (!element && nodeId && slotName) {
2811
2788
  element = document.querySelector(
@@ -2813,9 +2790,7 @@ Available Console Commands:
2813
2790
  );
2814
2791
  }
2815
2792
  if (!element && nodeId && !slotName) {
2816
- element = document.querySelector(
2817
- `[data-node-id="${nodeId}"]`
2818
- );
2793
+ element = document.querySelector(`[data-node-id="${nodeId}"]`);
2819
2794
  }
2820
2795
  if (!element && slotName) {
2821
2796
  element = document.querySelector(
@@ -2856,30 +2831,33 @@ Available Console Commands:
2856
2831
  };
2857
2832
  if (window.parent && window.parent !== window) {
2858
2833
  const hierarchyEls = this.buildComponentHierarchy(element);
2859
- window.parent.postMessage({
2860
- type: "ELEMENT_POSITION",
2861
- componentId: componentId || null,
2862
- slotName: slotName || null,
2863
- nodeId: nodeId || null,
2864
- isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
2865
- hierarchy: hierarchyEls.map((el, index) => {
2866
- const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
2867
- const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
2868
- const isSlot = !elComponentId && !!elSlotName;
2869
- const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
2870
- return {
2871
- index,
2872
- componentId: elComponentId,
2873
- componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
2874
- slotName: isSlot ? elSlotName : null,
2875
- isSlot,
2876
- isPageSlot: pageSlot,
2877
- nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
2878
- };
2879
- }),
2880
- position,
2881
- bounds
2882
- }, "*");
2834
+ window.parent.postMessage(
2835
+ {
2836
+ type: "ELEMENT_POSITION",
2837
+ componentId: componentId || null,
2838
+ slotName: slotName || null,
2839
+ nodeId: nodeId || null,
2840
+ isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
2841
+ hierarchy: hierarchyEls.map((el, index) => {
2842
+ const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
2843
+ const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
2844
+ const isSlot = !elComponentId && !!elSlotName;
2845
+ const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
2846
+ return {
2847
+ index,
2848
+ componentId: elComponentId,
2849
+ componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
2850
+ slotName: isSlot ? elSlotName : null,
2851
+ isSlot,
2852
+ isPageSlot: pageSlot,
2853
+ nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
2854
+ };
2855
+ }),
2856
+ position,
2857
+ bounds
2858
+ },
2859
+ "*"
2860
+ );
2883
2861
  }
2884
2862
  } else {
2885
2863
  console.warn("[AmplifyUp SDK] Element not found for position request");
@@ -2895,7 +2873,11 @@ Available Console Commands:
2895
2873
  switch (message.type) {
2896
2874
  case "ENABLE_HIGHLIGHTING":
2897
2875
  case "UPDATE_HIGHLIGHTING":
2898
- console.log("[AmplifyUp SDK] Enabling highlighting with registry:", message.componentRegistry?.length || 0, "components");
2876
+ console.log(
2877
+ "[AmplifyUp SDK] Enabling highlighting with registry:",
2878
+ message.componentRegistry?.length || 0,
2879
+ "components"
2880
+ );
2899
2881
  this.enableHighlighting(
2900
2882
  message.componentRegistry || [],
2901
2883
  message.highlightComponents ?? true,
@@ -2955,12 +2937,15 @@ Available Console Commands:
2955
2937
  const tagName = target.tagName.toLowerCase();
2956
2938
  const text = (target.textContent || "").replace(/\s+/g, " ").trim().substring(0, 80);
2957
2939
  if (window.parent && window.parent !== window) {
2958
- window.parent.postMessage({
2959
- type: "ELEMENT_CLICKED_FOR_EVENT",
2960
- selector,
2961
- tagName,
2962
- text
2963
- }, "*");
2940
+ window.parent.postMessage(
2941
+ {
2942
+ type: "ELEMENT_CLICKED_FOR_EVENT",
2943
+ selector,
2944
+ tagName,
2945
+ text
2946
+ },
2947
+ "*"
2948
+ );
2964
2949
  }
2965
2950
  };
2966
2951
  document.addEventListener("click", this.eventSelectionClickHandler, true);
@@ -2986,9 +2971,7 @@ Available Console Commands:
2986
2971
  return "[" + attr.name + '="' + attr.value + '"]';
2987
2972
  }
2988
2973
  if (el.className && typeof el.className === "string") {
2989
- const classes = el.className.split(" ").filter(
2990
- (c) => c && !c.startsWith("has-") && !c.includes("selectable") && !c.includes("selected")
2991
- );
2974
+ const classes = el.className.split(" ").filter((c) => c && !c.startsWith("has-") && !c.includes("selectable") && !c.includes("selected"));
2992
2975
  if (classes.length > 0) {
2993
2976
  return el.tagName.toLowerCase() + "." + classes[0];
2994
2977
  }
@@ -3038,9 +3021,7 @@ Available Console Commands:
3038
3021
  }
3039
3022
  });
3040
3023
  if (containing.length === 0) return null;
3041
- const innermost = containing.filter(
3042
- (el) => !containing.some((other) => other !== el && el.contains(other))
3043
- );
3024
+ const innermost = containing.filter((el) => !containing.some((other) => other !== el && el.contains(other)));
3044
3025
  if (innermost.length === 1) return innermost[0];
3045
3026
  let best = innermost[0];
3046
3027
  let bestArea = Infinity;
@@ -3157,9 +3138,7 @@ Available Console Commands:
3157
3138
  */
3158
3139
  enableHighlighting(componentRegistry, highlightComponents, showZones) {
3159
3140
  if (typeof document === "undefined") return;
3160
- const previouslySelected = Array.from(
3161
- document.querySelectorAll(".amplifyup-selected")
3162
- );
3141
+ const previouslySelected = Array.from(document.querySelectorAll(".amplifyup-selected"));
3163
3142
  this.componentRegistry = componentRegistry;
3164
3143
  this.highlightingEnabled = true;
3165
3144
  this.highlightComponentsEnabled = highlightComponents;
@@ -3532,10 +3511,7 @@ Available Console Commands:
3532
3511
  if (shouldReapply && this.highlightingEnabled) {
3533
3512
  setTimeout(() => {
3534
3513
  if (this.highlightingEnabled) {
3535
- this.applyComponentHighlights(
3536
- this.highlightComponentsEnabled,
3537
- this.showZonesEnabled
3538
- );
3514
+ this.applyComponentHighlights(this.highlightComponentsEnabled, this.showZonesEnabled);
3539
3515
  }
3540
3516
  }, 100);
3541
3517
  }
@@ -3544,7 +3520,13 @@ Available Console Commands:
3544
3520
  childList: true,
3545
3521
  subtree: true,
3546
3522
  attributes: true,
3547
- attributeFilter: ["data-amplifyup-component", "data-component-id", "data-amplifyup-slot", "data-slot-id", "data-slot-empty"]
3523
+ attributeFilter: [
3524
+ "data-amplifyup-component",
3525
+ "data-component-id",
3526
+ "data-amplifyup-slot",
3527
+ "data-slot-id",
3528
+ "data-slot-empty"
3529
+ ]
3548
3530
  });
3549
3531
  }
3550
3532
  /**
@@ -3558,9 +3540,7 @@ Available Console Commands:
3558
3540
  this.teardownComposerDragDrop();
3559
3541
  if (opts?.clearSelection !== false && typeof window !== "undefined") {
3560
3542
  window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
3561
- window.dispatchEvent(
3562
- new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } })
3563
- );
3543
+ window.dispatchEvent(new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } }));
3564
3544
  }
3565
3545
  if (this.mutationObserver) {
3566
3546
  this.mutationObserver.disconnect();
@@ -3718,7 +3698,10 @@ Available Console Commands:
3718
3698
  e.stopPropagation();
3719
3699
  this.sendSelectionMessage(htmlEl, hierarchy);
3720
3700
  if (window.parent && window.parent !== window) {
3721
- window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id }, "*");
3701
+ window.parent.postMessage(
3702
+ { type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id },
3703
+ "*"
3704
+ );
3722
3705
  }
3723
3706
  };
3724
3707
  htmlEl.addEventListener("click", handleClick);