@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/react.mjs CHANGED
@@ -323,12 +323,17 @@ function resolveAmplifyUpUrls(target) {
323
323
 
324
324
  // src/preview.ts
325
325
  function isPreviewRequest(searchParams) {
326
+ return paramIsTrue(searchParams, "preview") || paramIsTrue(searchParams, "visualEditor");
327
+ }
328
+ function isWorkingContentRequest(searchParams) {
329
+ return paramIsTrue(searchParams, "working");
330
+ }
331
+ function paramIsTrue(searchParams, key) {
326
332
  if (searchParams instanceof URLSearchParams) {
327
- return searchParams.get("preview") === "true" || searchParams.get("visualEditor") === "true";
333
+ return searchParams.get(key) === "true";
328
334
  }
329
- const preview = searchParams.preview;
330
- const visualEditor = searchParams.visualEditor;
331
- return preview === "true" || visualEditor === "true";
335
+ const value = searchParams[key];
336
+ return value === "true" || Array.isArray(value) && value[0] === "true";
332
337
  }
333
338
  function isComposerPreview() {
334
339
  if (typeof window === "undefined") return false;
@@ -563,6 +568,8 @@ var AmplifyUpSDK = class {
563
568
  this.showZonesEnabled = false;
564
569
  this.componentRegistry = [];
565
570
  this.messageListener = null;
571
+ this.composerBoundsRaf = 0;
572
+ this.composerBoundsScrollListener = null;
566
573
  this.mutationObserver = null;
567
574
  this.composerDragHandlers = null;
568
575
  /** Last slot highlighted during Composer drag — avoid clear/re-add flicker. */
@@ -1462,6 +1469,9 @@ Available Console Commands:
1462
1469
  });
1463
1470
  if (preview) {
1464
1471
  params.set("preview", "true");
1472
+ if (typeof window !== "undefined" && isWorkingContentRequest(new URLSearchParams(window.location.search))) {
1473
+ params.set("working", "true");
1474
+ }
1465
1475
  }
1466
1476
  if (isOnOrchestratorOrigin) {
1467
1477
  return `/api/layout/provider?${params.toString()}`;
@@ -2221,6 +2231,7 @@ Available Console Commands:
2221
2231
  this.applyComponentHighlights(highlightComponents, showZones);
2222
2232
  this.setupMutationObserver();
2223
2233
  this.setupComposerDragDrop();
2234
+ this.setupComposerBoundsTracking();
2224
2235
  }
2225
2236
  previouslySelected.forEach((el) => {
2226
2237
  if (document.contains(el)) {
@@ -2375,6 +2386,52 @@ Available Console Commands:
2375
2386
  this.clearComposerSelection();
2376
2387
  element.classList.add("amplifyup-selected");
2377
2388
  }
2389
+ postComposerSelectionBounds() {
2390
+ if (typeof document === "undefined") return;
2391
+ if (!window.parent || window.parent === window) return;
2392
+ const el = document.querySelector(".amplifyup-selected");
2393
+ if (!el) return;
2394
+ const rect = el.getBoundingClientRect();
2395
+ window.parent.postMessage(
2396
+ {
2397
+ type: "SELECTION_BOUNDS",
2398
+ bounds: {
2399
+ top: rect.top,
2400
+ left: rect.left,
2401
+ width: rect.width,
2402
+ height: rect.height
2403
+ }
2404
+ },
2405
+ "*"
2406
+ );
2407
+ }
2408
+ setupComposerBoundsTracking() {
2409
+ if (typeof document === "undefined") return;
2410
+ this.teardownComposerBoundsTracking();
2411
+ const onScroll = () => {
2412
+ if (this.composerBoundsRaf) return;
2413
+ this.composerBoundsRaf = requestAnimationFrame(() => {
2414
+ this.composerBoundsRaf = 0;
2415
+ this.postComposerSelectionBounds();
2416
+ });
2417
+ };
2418
+ this.composerBoundsScrollListener = onScroll;
2419
+ document.addEventListener("scroll", onScroll, { capture: true, passive: true });
2420
+ window.addEventListener("scroll", onScroll, { capture: true, passive: true });
2421
+ window.addEventListener("resize", onScroll);
2422
+ }
2423
+ teardownComposerBoundsTracking() {
2424
+ const onScroll = this.composerBoundsScrollListener;
2425
+ this.composerBoundsScrollListener = null;
2426
+ if (this.composerBoundsRaf) {
2427
+ cancelAnimationFrame(this.composerBoundsRaf);
2428
+ this.composerBoundsRaf = 0;
2429
+ }
2430
+ if (!onScroll || typeof document === "undefined") return;
2431
+ document.removeEventListener("scroll", onScroll, true);
2432
+ window.removeEventListener("scroll", onScroll, true);
2433
+ window.removeEventListener("resize", onScroll);
2434
+ }
2378
2435
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
2379
2436
  injectComposerHighlightStyles(highlightComponents, showZones) {
2380
2437
  if (typeof document === "undefined") return;
@@ -2542,6 +2599,7 @@ Available Console Commands:
2542
2599
  if (typeof document === "undefined") return;
2543
2600
  const clearSelection = opts?.clearSelection !== false;
2544
2601
  this.highlightingEnabled = false;
2602
+ this.teardownComposerBoundsTracking();
2545
2603
  this.teardownComposerDragDrop();
2546
2604
  if (opts?.clearSelection !== false && typeof window !== "undefined") {
2547
2605
  window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
@@ -3776,12 +3834,14 @@ async function fetchPageConfigServer(route, trackingId, preview = false, options
3776
3834
  });
3777
3835
  const { orchestratorUrl, edgeUrl } = resolveAmplifyUpUrls(target);
3778
3836
  const previewFlag = preview || (options?.searchParams ? isPreviewRequest(options.searchParams) : false);
3837
+ const workingFlag = options?.searchParams ? isWorkingContentRequest(options.searchParams) : false;
3779
3838
  const fetchOrchestratorPage = async (pageRoute, isPreview) => {
3780
3839
  const params = new URLSearchParams({
3781
3840
  route: pageRoute,
3782
3841
  trackingId
3783
3842
  });
3784
3843
  if (isPreview) params.set("preview", "true");
3844
+ if (workingFlag) params.set("working", "true");
3785
3845
  const url = `${orchestratorUrl}/api/layout/provider?${params.toString()}`;
3786
3846
  try {
3787
3847
  const res = await fetch(url, {
@@ -3964,6 +4024,6 @@ function useAmplifyUp() {
3964
4024
  return context;
3965
4025
  }
3966
4026
 
3967
- export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, Field, Image, RichText, Slot, fetchPageConfigServer, isComposerPreview, isPreviewRequest, useAmplifyUp, useComponentProps, useLiveComposerProps };
4027
+ export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, Field, Image, RichText, Slot, fetchPageConfigServer, isComposerPreview, isPreviewRequest, isWorkingContentRequest, useAmplifyUp, useComponentProps, useLiveComposerProps };
3968
4028
  //# sourceMappingURL=react.mjs.map
3969
4029
  //# sourceMappingURL=react.mjs.map