@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.
@@ -4,10 +4,15 @@
4
4
  */
5
5
  /** True when `preview=true` (or legacy visualEditor) is in request search params. */
6
6
  declare function isPreviewRequest(searchParams: Record<string, string | string[] | undefined> | URLSearchParams): boolean;
7
+ /**
8
+ * Composer Edit (not Preview toggle): overlay unpublished CMS docs.
9
+ * Live visitors and Composer Preview omit this.
10
+ */
11
+ declare function isWorkingContentRequest(searchParams: Record<string, string | string[] | undefined> | URLSearchParams): boolean;
7
12
  /**
8
13
  * Client-only: true when the page is loaded inside AmplifyUp Composer.
9
14
  * Does NOT treat every iframe as preview — only Composer referrers / query flags.
10
15
  */
11
16
  declare function isComposerPreview(): boolean;
12
17
 
13
- export { isPreviewRequest as a, isComposerPreview as i };
18
+ export { isPreviewRequest as a, isWorkingContentRequest as b, isComposerPreview as i };
@@ -4,10 +4,15 @@
4
4
  */
5
5
  /** True when `preview=true` (or legacy visualEditor) is in request search params. */
6
6
  declare function isPreviewRequest(searchParams: Record<string, string | string[] | undefined> | URLSearchParams): boolean;
7
+ /**
8
+ * Composer Edit (not Preview toggle): overlay unpublished CMS docs.
9
+ * Live visitors and Composer Preview omit this.
10
+ */
11
+ declare function isWorkingContentRequest(searchParams: Record<string, string | string[] | undefined> | URLSearchParams): boolean;
7
12
  /**
8
13
  * Client-only: true when the page is loaded inside AmplifyUp Composer.
9
14
  * Does NOT treat every iframe as preview — only Composer referrers / query flags.
10
15
  */
11
16
  declare function isComposerPreview(): boolean;
12
17
 
13
- export { isPreviewRequest as a, isComposerPreview as i };
18
+ export { isPreviewRequest as a, isWorkingContentRequest as b, isComposerPreview as i };
package/dist/react.d.mts CHANGED
@@ -3,7 +3,7 @@ import React, { ReactNode } from 'react';
3
3
  import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-npF_lNoq.mjs';
4
4
  export { Z as ZoneConfig } from './types-npF_lNoq.mjs';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.mjs';
6
- export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.mjs';
6
+ export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.mjs';
7
7
  export { fetchPageConfigServer } from './server.mjs';
8
8
 
9
9
  type RenderComponentContext = {
package/dist/react.d.ts CHANGED
@@ -3,7 +3,7 @@ import React, { ReactNode } from 'react';
3
3
  import { P as PageConfig, b as AmplifyUpConfig, C as ContentSource, A as AmplifyContentMeta } from './types-npF_lNoq.js';
4
4
  export { Z as ZoneConfig } from './types-npF_lNoq.js';
5
5
  export { AmplifyRenderer } from './AmplifyRenderer.js';
6
- export { i as isComposerPreview, a as isPreviewRequest } from './preview-BMrIgUvp.js';
6
+ export { i as isComposerPreview, a as isPreviewRequest, b as isWorkingContentRequest } from './preview-_vHmzRen.js';
7
7
  export { fetchPageConfigServer } from './server.js';
8
8
 
9
9
  type RenderComponentContext = {
package/dist/react.js CHANGED
@@ -325,12 +325,17 @@ function resolveAmplifyUpUrls(target) {
325
325
 
326
326
  // src/preview.ts
327
327
  function isPreviewRequest(searchParams) {
328
+ return paramIsTrue(searchParams, "preview") || paramIsTrue(searchParams, "visualEditor");
329
+ }
330
+ function isWorkingContentRequest(searchParams) {
331
+ return paramIsTrue(searchParams, "working");
332
+ }
333
+ function paramIsTrue(searchParams, key) {
328
334
  if (searchParams instanceof URLSearchParams) {
329
- return searchParams.get("preview") === "true" || searchParams.get("visualEditor") === "true";
335
+ return searchParams.get(key) === "true";
330
336
  }
331
- const preview = searchParams.preview;
332
- const visualEditor = searchParams.visualEditor;
333
- return preview === "true" || visualEditor === "true";
337
+ const value = searchParams[key];
338
+ return value === "true" || Array.isArray(value) && value[0] === "true";
334
339
  }
335
340
  function isComposerPreview() {
336
341
  if (typeof window === "undefined") return false;
@@ -565,6 +570,8 @@ var AmplifyUpSDK = class {
565
570
  this.showZonesEnabled = false;
566
571
  this.componentRegistry = [];
567
572
  this.messageListener = null;
573
+ this.composerBoundsRaf = 0;
574
+ this.composerBoundsScrollListener = null;
568
575
  this.mutationObserver = null;
569
576
  this.composerDragHandlers = null;
570
577
  /** Last slot highlighted during Composer drag — avoid clear/re-add flicker. */
@@ -1464,6 +1471,9 @@ Available Console Commands:
1464
1471
  });
1465
1472
  if (preview) {
1466
1473
  params.set("preview", "true");
1474
+ if (typeof window !== "undefined" && isWorkingContentRequest(new URLSearchParams(window.location.search))) {
1475
+ params.set("working", "true");
1476
+ }
1467
1477
  }
1468
1478
  if (isOnOrchestratorOrigin) {
1469
1479
  return `/api/layout/provider?${params.toString()}`;
@@ -2223,6 +2233,7 @@ Available Console Commands:
2223
2233
  this.applyComponentHighlights(highlightComponents, showZones);
2224
2234
  this.setupMutationObserver();
2225
2235
  this.setupComposerDragDrop();
2236
+ this.setupComposerBoundsTracking();
2226
2237
  }
2227
2238
  previouslySelected.forEach((el) => {
2228
2239
  if (document.contains(el)) {
@@ -2377,6 +2388,52 @@ Available Console Commands:
2377
2388
  this.clearComposerSelection();
2378
2389
  element.classList.add("amplifyup-selected");
2379
2390
  }
2391
+ postComposerSelectionBounds() {
2392
+ if (typeof document === "undefined") return;
2393
+ if (!window.parent || window.parent === window) return;
2394
+ const el = document.querySelector(".amplifyup-selected");
2395
+ if (!el) return;
2396
+ const rect = el.getBoundingClientRect();
2397
+ window.parent.postMessage(
2398
+ {
2399
+ type: "SELECTION_BOUNDS",
2400
+ bounds: {
2401
+ top: rect.top,
2402
+ left: rect.left,
2403
+ width: rect.width,
2404
+ height: rect.height
2405
+ }
2406
+ },
2407
+ "*"
2408
+ );
2409
+ }
2410
+ setupComposerBoundsTracking() {
2411
+ if (typeof document === "undefined") return;
2412
+ this.teardownComposerBoundsTracking();
2413
+ const onScroll = () => {
2414
+ if (this.composerBoundsRaf) return;
2415
+ this.composerBoundsRaf = requestAnimationFrame(() => {
2416
+ this.composerBoundsRaf = 0;
2417
+ this.postComposerSelectionBounds();
2418
+ });
2419
+ };
2420
+ this.composerBoundsScrollListener = onScroll;
2421
+ document.addEventListener("scroll", onScroll, { capture: true, passive: true });
2422
+ window.addEventListener("scroll", onScroll, { capture: true, passive: true });
2423
+ window.addEventListener("resize", onScroll);
2424
+ }
2425
+ teardownComposerBoundsTracking() {
2426
+ const onScroll = this.composerBoundsScrollListener;
2427
+ this.composerBoundsScrollListener = null;
2428
+ if (this.composerBoundsRaf) {
2429
+ cancelAnimationFrame(this.composerBoundsRaf);
2430
+ this.composerBoundsRaf = 0;
2431
+ }
2432
+ if (!onScroll || typeof document === "undefined") return;
2433
+ document.removeEventListener("scroll", onScroll, true);
2434
+ window.removeEventListener("scroll", onScroll, true);
2435
+ window.removeEventListener("resize", onScroll);
2436
+ }
2380
2437
  /** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
2381
2438
  injectComposerHighlightStyles(highlightComponents, showZones) {
2382
2439
  if (typeof document === "undefined") return;
@@ -2544,6 +2601,7 @@ Available Console Commands:
2544
2601
  if (typeof document === "undefined") return;
2545
2602
  const clearSelection = opts?.clearSelection !== false;
2546
2603
  this.highlightingEnabled = false;
2604
+ this.teardownComposerBoundsTracking();
2547
2605
  this.teardownComposerDragDrop();
2548
2606
  if (opts?.clearSelection !== false && typeof window !== "undefined") {
2549
2607
  window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
@@ -3778,12 +3836,14 @@ async function fetchPageConfigServer(route, trackingId, preview = false, options
3778
3836
  });
3779
3837
  const { orchestratorUrl, edgeUrl } = resolveAmplifyUpUrls(target);
3780
3838
  const previewFlag = preview || (options?.searchParams ? isPreviewRequest(options.searchParams) : false);
3839
+ const workingFlag = options?.searchParams ? isWorkingContentRequest(options.searchParams) : false;
3781
3840
  const fetchOrchestratorPage = async (pageRoute, isPreview) => {
3782
3841
  const params = new URLSearchParams({
3783
3842
  route: pageRoute,
3784
3843
  trackingId
3785
3844
  });
3786
3845
  if (isPreview) params.set("preview", "true");
3846
+ if (workingFlag) params.set("working", "true");
3787
3847
  const url = `${orchestratorUrl}/api/layout/provider?${params.toString()}`;
3788
3848
  try {
3789
3849
  const res = await fetch(url, {
@@ -3977,6 +4037,7 @@ exports.Slot = Slot;
3977
4037
  exports.fetchPageConfigServer = fetchPageConfigServer;
3978
4038
  exports.isComposerPreview = isComposerPreview;
3979
4039
  exports.isPreviewRequest = isPreviewRequest;
4040
+ exports.isWorkingContentRequest = isWorkingContentRequest;
3980
4041
  exports.useAmplifyUp = useAmplifyUp;
3981
4042
  exports.useComponentProps = useComponentProps;
3982
4043
  exports.useLiveComposerProps = useLiveComposerProps;