@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.
@@ -421,7 +421,7 @@ function isComposerPreview() {
421
421
  if (window.self !== window.top && document.referrer) {
422
422
  try {
423
423
  const refUrl = new URL(document.referrer);
424
- 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/")) {
424
+ if (refUrl.hostname === "amplifyup.ai" || refUrl.hostname.endsWith(".amplifyup.ai") || refUrl.hostname === "localhost" && refUrl.port === "5001" || refUrl.pathname.includes("/dashboard/composer")) {
425
425
  return true;
426
426
  }
427
427
  } catch {
@@ -1032,7 +1032,8 @@ function layoutProviderCacheKey(opts) {
1032
1032
  opts.preview ? "1" : "0",
1033
1033
  opts.working ? "1" : "0",
1034
1034
  opts.zoneId || "",
1035
- opts.compositionId || ""
1035
+ opts.compositionId || "",
1036
+ opts.layoutId || ""
1036
1037
  ].join("|");
1037
1038
  }
1038
1039
  function getSettledLayoutProvider(key) {
@@ -1192,7 +1193,7 @@ var AmplifyUpSDK = class {
1192
1193
  if (document.referrer) {
1193
1194
  try {
1194
1195
  const referrerUrl = new URL(document.referrer);
1195
- if (referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer") || referrerUrl.pathname.includes("/dashboard/routes/")) {
1196
+ if (referrerUrl.hostname === "localhost" && referrerUrl.port === "5001" || referrerUrl.pathname.includes("/dashboard/composer")) {
1196
1197
  return true;
1197
1198
  }
1198
1199
  } catch {
@@ -1469,11 +1470,7 @@ var AmplifyUpSDK = class {
1469
1470
  this.page(resumePath, { resumed: true });
1470
1471
  this.lastTrackedPath = resumePath;
1471
1472
  if (this.config?.debug) {
1472
- console.log(
1473
- "[AmplifyUp SDK] Idle resume page view",
1474
- resumePath,
1475
- `(hidden ${Math.round(idleMs / 6e4)}m)`
1476
- );
1473
+ console.log("[AmplifyUp SDK] Idle resume page view", resumePath, `(hidden ${Math.round(idleMs / 6e4)}m)`);
1477
1474
  }
1478
1475
  }
1479
1476
  noteActivity();
@@ -1493,12 +1490,7 @@ var AmplifyUpSDK = class {
1493
1490
  }
1494
1491
  state.visibleSince = null;
1495
1492
  };
1496
- const activityEvents = [
1497
- "pointerdown",
1498
- "keydown",
1499
- "scroll",
1500
- "touchstart"
1501
- ];
1493
+ const activityEvents = ["pointerdown", "keydown", "scroll", "touchstart"];
1502
1494
  const onActivity = () => noteActivity();
1503
1495
  window.addEventListener("scroll", onScroll, { passive: true });
1504
1496
  document.addEventListener("visibilitychange", onVisibility);
@@ -1646,11 +1638,7 @@ var AmplifyUpSDK = class {
1646
1638
  hosts.forEach((host) => observer.observe(host));
1647
1639
  this.componentViewObservers.push(observer);
1648
1640
  if (this.config?.debug) {
1649
- console.log(
1650
- "[AmplifyUp SDK] Component View tracking enabled for",
1651
- hosts.length,
1652
- "hosts"
1653
- );
1641
+ console.log("[AmplifyUp SDK] Component View tracking enabled for", hosts.length, "hosts");
1654
1642
  }
1655
1643
  }
1656
1644
  cleanupComponentViewTracking() {
@@ -2122,6 +2110,8 @@ Available Console Commands:
2122
2110
  const compositionId = pageSearch.get("compositionId");
2123
2111
  if (zoneId) params.set("zoneId", zoneId);
2124
2112
  if (compositionId) params.set("compositionId", compositionId);
2113
+ const layoutId = pageSearch.get("layoutId");
2114
+ if (layoutId) params.set("layoutId", layoutId);
2125
2115
  }
2126
2116
  }
2127
2117
  if (isOnOrchestratorOrigin) {
@@ -2142,7 +2132,8 @@ Available Console Commands:
2142
2132
  preview,
2143
2133
  working: pageSearch ? isWorkingContentRequest(pageSearch) : false,
2144
2134
  zoneId: pageSearch?.get("zoneId"),
2145
- compositionId: pageSearch?.get("compositionId")
2135
+ compositionId: pageSearch?.get("compositionId"),
2136
+ layoutId: pageSearch?.get("layoutId")
2146
2137
  });
2147
2138
  return dedupeLayoutProviderFetch(cacheKey, async () => {
2148
2139
  const startedAt = Date.now();
@@ -2224,15 +2215,11 @@ Available Console Commands:
2224
2215
  ) : document;
2225
2216
  if (!scopeRoot) {
2226
2217
  if (this.config?.debug) {
2227
- console.log(
2228
- `[AmplifyUp SDK] Component host not found for ${eventConfig.componentId}`
2229
- );
2218
+ console.log(`[AmplifyUp SDK] Component host not found for ${eventConfig.componentId}`);
2230
2219
  }
2231
2220
  return;
2232
2221
  }
2233
- targetElements = Array.from(
2234
- scopeRoot.querySelectorAll(eventConfig.selector)
2235
- );
2222
+ targetElements = Array.from(scopeRoot.querySelectorAll(eventConfig.selector));
2236
2223
  if (scopeRoot instanceof Element && scopeRoot !== document.documentElement && scopeRoot.matches?.(eventConfig.selector)) {
2237
2224
  targetElements.unshift(scopeRoot);
2238
2225
  }
@@ -2265,7 +2252,9 @@ Available Console Commands:
2265
2252
  });
2266
2253
  }
2267
2254
  if (this.config?.debug) {
2268
- console.log(`[AmplifyUp SDK] Attached ${eventConfig.eventType} listener for ${eventConfig.eventName} on selector: ${eventConfig.selector}`);
2255
+ console.log(
2256
+ `[AmplifyUp SDK] Attached ${eventConfig.eventType} listener for ${eventConfig.eventName} on selector: ${eventConfig.selector}`
2257
+ );
2269
2258
  }
2270
2259
  });
2271
2260
  });
@@ -2275,16 +2264,16 @@ Available Console Commands:
2275
2264
  */
2276
2265
  mapEventType(eventType) {
2277
2266
  const eventMap = {
2278
- "click": "click",
2279
- "submit": "submit",
2280
- "focus": "focus",
2281
- "blur": "blur",
2282
- "hover": "mouseenter",
2283
- "change": "change",
2284
- "scroll": "scroll",
2285
- "view": "view",
2267
+ click: "click",
2268
+ submit: "submit",
2269
+ focus: "focus",
2270
+ blur: "blur",
2271
+ hover: "mouseenter",
2272
+ change: "change",
2273
+ scroll: "scroll",
2274
+ view: "view",
2286
2275
  // Handled separately with IntersectionObserver
2287
- "custom": "custom"
2276
+ custom: "custom"
2288
2277
  };
2289
2278
  return eventMap[eventType] || eventType;
2290
2279
  }
@@ -2360,11 +2349,7 @@ Available Console Commands:
2360
2349
  (entries) => {
2361
2350
  entries.forEach((entry) => {
2362
2351
  if (entry.isIntersecting) {
2363
- this.handleTrackedEvent(
2364
- new CustomEvent("view"),
2365
- config,
2366
- element
2367
- );
2352
+ this.handleTrackedEvent(new CustomEvent("view"), config, element);
2368
2353
  observer.unobserve(element);
2369
2354
  }
2370
2355
  });
@@ -2507,21 +2492,15 @@ Available Console Commands:
2507
2492
  return;
2508
2493
  }
2509
2494
  if (event.data?.type === "AMPLIFYUP_FIELD_PATCH") {
2510
- window.dispatchEvent(
2511
- new CustomEvent("amplifyup:field-patch", { detail: event.data })
2512
- );
2495
+ window.dispatchEvent(new CustomEvent("amplifyup:field-patch", { detail: event.data }));
2513
2496
  return;
2514
2497
  }
2515
2498
  if (event.data?.type === "AMPLIFYUP_PROPS_PATCH") {
2516
- window.dispatchEvent(
2517
- new CustomEvent("amplifyup:props-patch", { detail: event.data })
2518
- );
2499
+ window.dispatchEvent(new CustomEvent("amplifyup:props-patch", { detail: event.data }));
2519
2500
  return;
2520
2501
  }
2521
2502
  if (event.data?.type === "AMPLIFYUP_LAYOUT_PATCH") {
2522
- window.dispatchEvent(
2523
- new CustomEvent("amplifyup:layout-patch", { detail: event.data })
2524
- );
2503
+ window.dispatchEvent(new CustomEvent("amplifyup:layout-patch", { detail: event.data }));
2525
2504
  return;
2526
2505
  }
2527
2506
  if (event.data?.type === "COMPONENT_DELETABLE_STATUS") {
@@ -2584,9 +2563,7 @@ Available Console Commands:
2584
2563
  const { componentId, slotName, nodeId, isPageSlot } = event.data;
2585
2564
  let element = null;
2586
2565
  if (isPageSlot || slotName === "main" && !nodeId && !componentId) {
2587
- element = document.querySelector(
2588
- '[data-slot-source="page"]'
2589
- );
2566
+ element = document.querySelector('[data-slot-source="page"]');
2590
2567
  }
2591
2568
  if (!element && nodeId && slotName) {
2592
2569
  element = document.querySelector(
@@ -2594,9 +2571,7 @@ Available Console Commands:
2594
2571
  );
2595
2572
  }
2596
2573
  if (!element && nodeId && !slotName) {
2597
- element = document.querySelector(
2598
- `[data-node-id="${nodeId}"]`
2599
- );
2574
+ element = document.querySelector(`[data-node-id="${nodeId}"]`);
2600
2575
  }
2601
2576
  if (!element && slotName) {
2602
2577
  element = document.querySelector(
@@ -2637,30 +2612,33 @@ Available Console Commands:
2637
2612
  };
2638
2613
  if (window.parent && window.parent !== window) {
2639
2614
  const hierarchyEls = this.buildComponentHierarchy(element);
2640
- window.parent.postMessage({
2641
- type: "ELEMENT_POSITION",
2642
- componentId: componentId || null,
2643
- slotName: slotName || null,
2644
- nodeId: nodeId || null,
2645
- isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
2646
- hierarchy: hierarchyEls.map((el, index) => {
2647
- const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
2648
- const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
2649
- const isSlot = !elComponentId && !!elSlotName;
2650
- const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
2651
- return {
2652
- index,
2653
- componentId: elComponentId,
2654
- componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
2655
- slotName: isSlot ? elSlotName : null,
2656
- isSlot,
2657
- isPageSlot: pageSlot,
2658
- nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
2659
- };
2660
- }),
2661
- position,
2662
- bounds
2663
- }, "*");
2615
+ window.parent.postMessage(
2616
+ {
2617
+ type: "ELEMENT_POSITION",
2618
+ componentId: componentId || null,
2619
+ slotName: slotName || null,
2620
+ nodeId: nodeId || null,
2621
+ isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
2622
+ hierarchy: hierarchyEls.map((el, index) => {
2623
+ const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
2624
+ const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
2625
+ const isSlot = !elComponentId && !!elSlotName;
2626
+ const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
2627
+ return {
2628
+ index,
2629
+ componentId: elComponentId,
2630
+ componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
2631
+ slotName: isSlot ? elSlotName : null,
2632
+ isSlot,
2633
+ isPageSlot: pageSlot,
2634
+ nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
2635
+ };
2636
+ }),
2637
+ position,
2638
+ bounds
2639
+ },
2640
+ "*"
2641
+ );
2664
2642
  }
2665
2643
  } else {
2666
2644
  console.warn("[AmplifyUp SDK] Element not found for position request");
@@ -2676,7 +2654,11 @@ Available Console Commands:
2676
2654
  switch (message.type) {
2677
2655
  case "ENABLE_HIGHLIGHTING":
2678
2656
  case "UPDATE_HIGHLIGHTING":
2679
- console.log("[AmplifyUp SDK] Enabling highlighting with registry:", message.componentRegistry?.length || 0, "components");
2657
+ console.log(
2658
+ "[AmplifyUp SDK] Enabling highlighting with registry:",
2659
+ message.componentRegistry?.length || 0,
2660
+ "components"
2661
+ );
2680
2662
  this.enableHighlighting(
2681
2663
  message.componentRegistry || [],
2682
2664
  message.highlightComponents ?? true,
@@ -2736,12 +2718,15 @@ Available Console Commands:
2736
2718
  const tagName = target.tagName.toLowerCase();
2737
2719
  const text = (target.textContent || "").replace(/\s+/g, " ").trim().substring(0, 80);
2738
2720
  if (window.parent && window.parent !== window) {
2739
- window.parent.postMessage({
2740
- type: "ELEMENT_CLICKED_FOR_EVENT",
2741
- selector,
2742
- tagName,
2743
- text
2744
- }, "*");
2721
+ window.parent.postMessage(
2722
+ {
2723
+ type: "ELEMENT_CLICKED_FOR_EVENT",
2724
+ selector,
2725
+ tagName,
2726
+ text
2727
+ },
2728
+ "*"
2729
+ );
2745
2730
  }
2746
2731
  };
2747
2732
  document.addEventListener("click", this.eventSelectionClickHandler, true);
@@ -2767,9 +2752,7 @@ Available Console Commands:
2767
2752
  return "[" + attr.name + '="' + attr.value + '"]';
2768
2753
  }
2769
2754
  if (el.className && typeof el.className === "string") {
2770
- const classes = el.className.split(" ").filter(
2771
- (c) => c && !c.startsWith("has-") && !c.includes("selectable") && !c.includes("selected")
2772
- );
2755
+ const classes = el.className.split(" ").filter((c) => c && !c.startsWith("has-") && !c.includes("selectable") && !c.includes("selected"));
2773
2756
  if (classes.length > 0) {
2774
2757
  return el.tagName.toLowerCase() + "." + classes[0];
2775
2758
  }
@@ -2819,9 +2802,7 @@ Available Console Commands:
2819
2802
  }
2820
2803
  });
2821
2804
  if (containing.length === 0) return null;
2822
- const innermost = containing.filter(
2823
- (el) => !containing.some((other) => other !== el && el.contains(other))
2824
- );
2805
+ const innermost = containing.filter((el) => !containing.some((other) => other !== el && el.contains(other)));
2825
2806
  if (innermost.length === 1) return innermost[0];
2826
2807
  let best = innermost[0];
2827
2808
  let bestArea = Infinity;
@@ -2938,9 +2919,7 @@ Available Console Commands:
2938
2919
  */
2939
2920
  enableHighlighting(componentRegistry, highlightComponents, showZones) {
2940
2921
  if (typeof document === "undefined") return;
2941
- const previouslySelected = Array.from(
2942
- document.querySelectorAll(".amplifyup-selected")
2943
- );
2922
+ const previouslySelected = Array.from(document.querySelectorAll(".amplifyup-selected"));
2944
2923
  this.componentRegistry = componentRegistry;
2945
2924
  this.highlightingEnabled = true;
2946
2925
  this.highlightComponentsEnabled = highlightComponents;
@@ -3313,10 +3292,7 @@ Available Console Commands:
3313
3292
  if (shouldReapply && this.highlightingEnabled) {
3314
3293
  setTimeout(() => {
3315
3294
  if (this.highlightingEnabled) {
3316
- this.applyComponentHighlights(
3317
- this.highlightComponentsEnabled,
3318
- this.showZonesEnabled
3319
- );
3295
+ this.applyComponentHighlights(this.highlightComponentsEnabled, this.showZonesEnabled);
3320
3296
  }
3321
3297
  }, 100);
3322
3298
  }
@@ -3325,7 +3301,13 @@ Available Console Commands:
3325
3301
  childList: true,
3326
3302
  subtree: true,
3327
3303
  attributes: true,
3328
- attributeFilter: ["data-amplifyup-component", "data-component-id", "data-amplifyup-slot", "data-slot-id", "data-slot-empty"]
3304
+ attributeFilter: [
3305
+ "data-amplifyup-component",
3306
+ "data-component-id",
3307
+ "data-amplifyup-slot",
3308
+ "data-slot-id",
3309
+ "data-slot-empty"
3310
+ ]
3329
3311
  });
3330
3312
  }
3331
3313
  /**
@@ -3339,9 +3321,7 @@ Available Console Commands:
3339
3321
  this.teardownComposerDragDrop();
3340
3322
  if (opts?.clearSelection !== false && typeof window !== "undefined") {
3341
3323
  window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
3342
- window.dispatchEvent(
3343
- new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } })
3344
- );
3324
+ window.dispatchEvent(new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } }));
3345
3325
  }
3346
3326
  if (this.mutationObserver) {
3347
3327
  this.mutationObserver.disconnect();
@@ -3499,7 +3479,10 @@ Available Console Commands:
3499
3479
  e.stopPropagation();
3500
3480
  this.sendSelectionMessage(htmlEl, hierarchy);
3501
3481
  if (window.parent && window.parent !== window) {
3502
- window.parent.postMessage({ type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id }, "*");
3482
+ window.parent.postMessage(
3483
+ { type: "CHECK_COMPONENT_DELETABLE", componentId: component.component_id },
3484
+ "*"
3485
+ );
3503
3486
  }
3504
3487
  };
3505
3488
  htmlEl.addEventListener("click", handleClick);
@@ -3719,13 +3702,7 @@ function ComponentContextProvider({
3719
3702
  componentId
3720
3703
  }) {
3721
3704
  const next = hydratePageResourceProps(props || {}, getPageResourceFields());
3722
- return /* @__PURE__ */ jsx(
3723
- ComponentContext.Provider,
3724
- {
3725
- value: { slots, props: next, layoutNodeId, componentId },
3726
- children
3727
- }
3728
- );
3705
+ return /* @__PURE__ */ jsx(ComponentContext.Provider, { value: { slots, props: next, layoutNodeId, componentId }, children });
3729
3706
  }
3730
3707
  var REGISTRY_BRAND = Symbol.for("amplifyup.componentRegistry");
3731
3708
  var isComponentRegistry = (value) => !!value && typeof value === "object" && value[REGISTRY_BRAND] === true;