@amplifyup/sdk 0.1.31 → 0.1.33

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
@@ -312,12 +312,17 @@ function resolveAmplifyUpUrls(target) {
312
312
 
313
313
  // src/preview.ts
314
314
  function isPreviewRequest(searchParams) {
315
+ return paramIsTrue(searchParams, "preview") || paramIsTrue(searchParams, "visualEditor");
316
+ }
317
+ function isWorkingContentRequest(searchParams) {
318
+ return paramIsTrue(searchParams, "working");
319
+ }
320
+ function paramIsTrue(searchParams, key) {
315
321
  if (searchParams instanceof URLSearchParams) {
316
- return searchParams.get("preview") === "true" || searchParams.get("visualEditor") === "true";
322
+ return searchParams.get(key) === "true";
317
323
  }
318
- const preview = searchParams.preview;
319
- const visualEditor = searchParams.visualEditor;
320
- return preview === "true" || visualEditor === "true";
324
+ const value = searchParams[key];
325
+ return value === "true" || Array.isArray(value) && value[0] === "true";
321
326
  }
322
327
  function isComposerPreview() {
323
328
  if (typeof window === "undefined") return false;
@@ -552,6 +557,8 @@ var AmplifyUpSDK = class {
552
557
  this.showZonesEnabled = false;
553
558
  this.componentRegistry = [];
554
559
  this.messageListener = null;
560
+ this.composerBoundsRaf = 0;
561
+ this.composerBoundsScrollListener = null;
555
562
  this.mutationObserver = null;
556
563
  this.composerDragHandlers = null;
557
564
  /** Last slot highlighted during Composer drag — avoid clear/re-add flicker. */
@@ -1451,6 +1458,9 @@ Available Console Commands:
1451
1458
  });
1452
1459
  if (preview) {
1453
1460
  params.set("preview", "true");
1461
+ if (typeof window !== "undefined" && isWorkingContentRequest(new URLSearchParams(window.location.search))) {
1462
+ params.set("working", "true");
1463
+ }
1454
1464
  }
1455
1465
  if (isOnOrchestratorOrigin) {
1456
1466
  return `/api/layout/provider?${params.toString()}`;
@@ -2210,6 +2220,7 @@ Available Console Commands:
2210
2220
  this.applyComponentHighlights(highlightComponents, showZones);
2211
2221
  this.setupMutationObserver();
2212
2222
  this.setupComposerDragDrop();
2223
+ this.setupComposerBoundsTracking();
2213
2224
  }
2214
2225
  previouslySelected.forEach((el) => {
2215
2226
  if (document.contains(el)) {
@@ -2364,6 +2375,52 @@ Available Console Commands:
2364
2375
  this.clearComposerSelection();
2365
2376
  element.classList.add("amplifyup-selected");
2366
2377
  }
2378
+ postComposerSelectionBounds() {
2379
+ if (typeof document === "undefined") return;
2380
+ if (!window.parent || window.parent === window) return;
2381
+ const el = document.querySelector(".amplifyup-selected");
2382
+ if (!el) return;
2383
+ const rect = el.getBoundingClientRect();
2384
+ window.parent.postMessage(
2385
+ {
2386
+ type: "SELECTION_BOUNDS",
2387
+ bounds: {
2388
+ top: rect.top,
2389
+ left: rect.left,
2390
+ width: rect.width,
2391
+ height: rect.height
2392
+ }
2393
+ },
2394
+ "*"
2395
+ );
2396
+ }
2397
+ setupComposerBoundsTracking() {
2398
+ if (typeof document === "undefined") return;
2399
+ this.teardownComposerBoundsTracking();
2400
+ const onScroll = () => {
2401
+ if (this.composerBoundsRaf) return;
2402
+ this.composerBoundsRaf = requestAnimationFrame(() => {
2403
+ this.composerBoundsRaf = 0;
2404
+ this.postComposerSelectionBounds();
2405
+ });
2406
+ };
2407
+ this.composerBoundsScrollListener = onScroll;
2408
+ document.addEventListener("scroll", onScroll, { capture: true, passive: true });
2409
+ window.addEventListener("scroll", onScroll, { capture: true, passive: true });
2410
+ window.addEventListener("resize", onScroll);
2411
+ }
2412
+ teardownComposerBoundsTracking() {
2413
+ const onScroll = this.composerBoundsScrollListener;
2414
+ this.composerBoundsScrollListener = null;
2415
+ if (this.composerBoundsRaf) {
2416
+ cancelAnimationFrame(this.composerBoundsRaf);
2417
+ this.composerBoundsRaf = 0;
2418
+ }
2419
+ if (!onScroll || typeof document === "undefined") return;
2420
+ document.removeEventListener("scroll", onScroll, true);
2421
+ window.removeEventListener("scroll", onScroll, true);
2422
+ window.removeEventListener("resize", onScroll);
2423
+ }
2367
2424
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
2368
2425
  injectComposerHighlightStyles(highlightComponents, showZones) {
2369
2426
  if (typeof document === "undefined") return;
@@ -2531,6 +2588,7 @@ Available Console Commands:
2531
2588
  if (typeof document === "undefined") return;
2532
2589
  const clearSelection = opts?.clearSelection !== false;
2533
2590
  this.highlightingEnabled = false;
2591
+ this.teardownComposerBoundsTracking();
2534
2592
  this.teardownComposerDragDrop();
2535
2593
  if (opts?.clearSelection !== false && typeof window !== "undefined") {
2536
2594
  window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
@@ -2782,6 +2840,6 @@ var verifyAWSConnection = () => {
2782
2840
  };
2783
2841
  var index_default = getSDK();
2784
2842
 
2785
- export { AmplifyUpSDK, DWELL_ACTIVITY_IDLE_MS, EdgeResolveError, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, index_default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId2 as getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId2 as getUserId, identify, init, isAmplifyUpTarget, isComposerPreview, isPreviewRequest, mapResolvedToPageConfig, normalizeAmplifyUpTarget, normalizeRoute, page, refreshEventTracking, reset, resolveAmplifyUpTarget, resolveAmplifyUpUrls, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
2843
+ export { AmplifyUpSDK, DWELL_ACTIVITY_IDLE_MS, EdgeResolveError, SESSION_IDLE_GAP_MS, buildLayoutProviderUrl, buildPageRenderUrl, cleanupEventTracking, index_default as default, fetchContent, fetchEdgeResolve, fetchPageConfig, getDiagnostics, getInstanceId2 as getInstanceId, getOrchestratorUrl, getSDK, getStatus, getTarget, getTrackingId, getUserId2 as getUserId, identify, init, isAmplifyUpTarget, isComposerPreview, isPreviewRequest, isWorkingContentRequest, mapResolvedToPageConfig, normalizeAmplifyUpTarget, normalizeRoute, page, refreshEventTracking, reset, resolveAmplifyUpTarget, resolveAmplifyUpUrls, routeChange, setProfileFields, setupComponentViewTracking, setupEventTracking, testTracking, track, trackClick, trackContentEngagement, trackContentView, trackFormFieldInteraction, trackFormSubmit, verifyAWSConnection };
2786
2844
  //# sourceMappingURL=index.mjs.map
2787
2845
  //# sourceMappingURL=index.mjs.map