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