@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.
@@ -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;
@@ -391,6 +396,8 @@ var AmplifyUpSDK = class {
391
396
  this.showZonesEnabled = false;
392
397
  this.componentRegistry = [];
393
398
  this.messageListener = null;
399
+ this.composerBoundsRaf = 0;
400
+ this.composerBoundsScrollListener = null;
394
401
  this.mutationObserver = null;
395
402
  this.composerDragHandlers = null;
396
403
  /** Last slot highlighted during Composer drag — avoid clear/re-add flicker. */
@@ -1290,6 +1297,9 @@ Available Console Commands:
1290
1297
  });
1291
1298
  if (preview) {
1292
1299
  params.set("preview", "true");
1300
+ if (typeof window !== "undefined" && isWorkingContentRequest(new URLSearchParams(window.location.search))) {
1301
+ params.set("working", "true");
1302
+ }
1293
1303
  }
1294
1304
  if (isOnOrchestratorOrigin) {
1295
1305
  return `/api/layout/provider?${params.toString()}`;
@@ -2049,6 +2059,7 @@ Available Console Commands:
2049
2059
  this.applyComponentHighlights(highlightComponents, showZones);
2050
2060
  this.setupMutationObserver();
2051
2061
  this.setupComposerDragDrop();
2062
+ this.setupComposerBoundsTracking();
2052
2063
  }
2053
2064
  previouslySelected.forEach((el) => {
2054
2065
  if (document.contains(el)) {
@@ -2203,6 +2214,52 @@ Available Console Commands:
2203
2214
  this.clearComposerSelection();
2204
2215
  element.classList.add("amplifyup-selected");
2205
2216
  }
2217
+ postComposerSelectionBounds() {
2218
+ if (typeof document === "undefined") return;
2219
+ if (!window.parent || window.parent === window) return;
2220
+ const el = document.querySelector(".amplifyup-selected");
2221
+ if (!el) return;
2222
+ const rect = el.getBoundingClientRect();
2223
+ window.parent.postMessage(
2224
+ {
2225
+ type: "SELECTION_BOUNDS",
2226
+ bounds: {
2227
+ top: rect.top,
2228
+ left: rect.left,
2229
+ width: rect.width,
2230
+ height: rect.height
2231
+ }
2232
+ },
2233
+ "*"
2234
+ );
2235
+ }
2236
+ setupComposerBoundsTracking() {
2237
+ if (typeof document === "undefined") return;
2238
+ this.teardownComposerBoundsTracking();
2239
+ const onScroll = () => {
2240
+ if (this.composerBoundsRaf) return;
2241
+ this.composerBoundsRaf = requestAnimationFrame(() => {
2242
+ this.composerBoundsRaf = 0;
2243
+ this.postComposerSelectionBounds();
2244
+ });
2245
+ };
2246
+ this.composerBoundsScrollListener = onScroll;
2247
+ document.addEventListener("scroll", onScroll, { capture: true, passive: true });
2248
+ window.addEventListener("scroll", onScroll, { capture: true, passive: true });
2249
+ window.addEventListener("resize", onScroll);
2250
+ }
2251
+ teardownComposerBoundsTracking() {
2252
+ const onScroll = this.composerBoundsScrollListener;
2253
+ this.composerBoundsScrollListener = null;
2254
+ if (this.composerBoundsRaf) {
2255
+ cancelAnimationFrame(this.composerBoundsRaf);
2256
+ this.composerBoundsRaf = 0;
2257
+ }
2258
+ if (!onScroll || typeof document === "undefined") return;
2259
+ document.removeEventListener("scroll", onScroll, true);
2260
+ window.removeEventListener("scroll", onScroll, true);
2261
+ window.removeEventListener("resize", onScroll);
2262
+ }
2206
2263
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
2207
2264
  injectComposerHighlightStyles(highlightComponents, showZones) {
2208
2265
  if (typeof document === "undefined") return;
@@ -2370,6 +2427,7 @@ Available Console Commands:
2370
2427
  if (typeof document === "undefined") return;
2371
2428
  const clearSelection = opts?.clearSelection !== false;
2372
2429
  this.highlightingEnabled = false;
2430
+ this.teardownComposerBoundsTracking();
2373
2431
  this.teardownComposerDragDrop();
2374
2432
  if (opts?.clearSelection !== false && typeof window !== "undefined") {
2375
2433
  window.__AMPLIFYUP_COMPOSER_EDIT__ = false;