@amplifyup/sdk 0.1.14 → 0.1.16

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.d.mts CHANGED
@@ -21,6 +21,11 @@ interface AmplifyPageContentProps {
21
21
  renderComponent: RenderComponentFn;
22
22
  /** Optional pre-fetched layout (e.g. from server in preview mode). */
23
23
  pageConfig?: PageConfig | null;
24
+ /**
25
+ * Force Composer mode (e.g. from SSR `?preview=true`). Ensures the page slot
26
+ * wrapper exists even before client-side preview detection runs.
27
+ */
28
+ forceComposerPreview?: boolean;
24
29
  /** Shown while layout loads in Composer (default: empty main canvas). */
25
30
  previewLoadingComponent?: ReactNode;
26
31
  /** Shown when no layout components exist yet in Composer (default: empty main canvas). */
@@ -33,7 +38,7 @@ interface AmplifyPageContentProps {
33
38
  * Hybrid page wrapper: Composer shows only the AmplifyUp layout canvas;
34
39
  * normal visits show the configured layout or your native `fallback`.
35
40
  */
36
- declare function AmplifyPageContent({ fallback, renderComponent, pageConfig: pageConfigProp, previewLoadingComponent, previewEmptyComponent, loadingComponent, emptyComponent, errorComponent, }: AmplifyPageContentProps): react_jsx_runtime.JSX.Element | null;
41
+ declare function AmplifyPageContent({ fallback, renderComponent, pageConfig: pageConfigProp, forceComposerPreview, previewLoadingComponent, previewEmptyComponent, loadingComponent, emptyComponent, errorComponent, }: AmplifyPageContentProps): react_jsx_runtime.JSX.Element | null;
37
42
 
38
43
  /**
39
44
  * ComponentContextProvider - Provides slots and props to child components
package/dist/react.d.ts CHANGED
@@ -21,6 +21,11 @@ interface AmplifyPageContentProps {
21
21
  renderComponent: RenderComponentFn;
22
22
  /** Optional pre-fetched layout (e.g. from server in preview mode). */
23
23
  pageConfig?: PageConfig | null;
24
+ /**
25
+ * Force Composer mode (e.g. from SSR `?preview=true`). Ensures the page slot
26
+ * wrapper exists even before client-side preview detection runs.
27
+ */
28
+ forceComposerPreview?: boolean;
24
29
  /** Shown while layout loads in Composer (default: empty main canvas). */
25
30
  previewLoadingComponent?: ReactNode;
26
31
  /** Shown when no layout components exist yet in Composer (default: empty main canvas). */
@@ -33,7 +38,7 @@ interface AmplifyPageContentProps {
33
38
  * Hybrid page wrapper: Composer shows only the AmplifyUp layout canvas;
34
39
  * normal visits show the configured layout or your native `fallback`.
35
40
  */
36
- declare function AmplifyPageContent({ fallback, renderComponent, pageConfig: pageConfigProp, previewLoadingComponent, previewEmptyComponent, loadingComponent, emptyComponent, errorComponent, }: AmplifyPageContentProps): react_jsx_runtime.JSX.Element | null;
41
+ declare function AmplifyPageContent({ fallback, renderComponent, pageConfig: pageConfigProp, forceComposerPreview, previewLoadingComponent, previewEmptyComponent, loadingComponent, emptyComponent, errorComponent, }: AmplifyPageContentProps): react_jsx_runtime.JSX.Element | null;
37
42
 
38
43
  /**
39
44
  * ComponentContextProvider - Provides slots and props to child components
package/dist/react.js CHANGED
@@ -1225,6 +1225,11 @@ Available Console Commands:
1225
1225
  `[data-node-id="${nodeId}"]`
1226
1226
  );
1227
1227
  }
1228
+ if (!element && slotName) {
1229
+ element = document.querySelector(
1230
+ `[data-slot-source="page"][data-slot-id="${slotName}"], [data-slot-source="page"][data-amplifyup-slot="${slotName}"]`
1231
+ );
1232
+ }
1228
1233
  if (!element && slotName) {
1229
1234
  element = document.querySelector(
1230
1235
  `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]`
@@ -1257,12 +1262,28 @@ Available Console Commands:
1257
1262
  height: rect.height
1258
1263
  };
1259
1264
  if (window.parent && window.parent !== window) {
1265
+ const hierarchyEls = this.buildComponentHierarchy(element);
1260
1266
  window.parent.postMessage({
1261
1267
  type: "ELEMENT_POSITION",
1262
1268
  componentId: componentId || null,
1263
1269
  slotName: slotName || null,
1264
1270
  nodeId: nodeId || null,
1265
- isPageSlot: !!isPageSlot,
1271
+ isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
1272
+ hierarchy: hierarchyEls.map((el, index) => {
1273
+ const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
1274
+ const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
1275
+ const isSlot = !elComponentId && !!elSlotName;
1276
+ const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
1277
+ return {
1278
+ index,
1279
+ componentId: elComponentId,
1280
+ componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
1281
+ slotName: isSlot ? elSlotName : null,
1282
+ isSlot,
1283
+ isPageSlot: pageSlot,
1284
+ nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
1285
+ };
1286
+ }),
1266
1287
  position,
1267
1288
  bounds
1268
1289
  }, "*");
@@ -1819,13 +1840,24 @@ Available Console Commands:
1819
1840
  buildComponentHierarchy(element) {
1820
1841
  const hierarchy = [];
1821
1842
  let current = element;
1843
+ let sawPageSlot = false;
1822
1844
  while (current) {
1823
1845
  if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id")) {
1824
1846
  hierarchy.push(current);
1847
+ if (current.getAttribute("data-slot-source") === "page") {
1848
+ sawPageSlot = true;
1849
+ }
1825
1850
  }
1826
1851
  current = current.parentElement;
1827
1852
  }
1828
- return hierarchy.reverse();
1853
+ const ordered = hierarchy.reverse();
1854
+ if (!sawPageSlot) {
1855
+ const pageSlot = element.closest('[data-slot-source="page"]');
1856
+ if (pageSlot && !ordered.includes(pageSlot)) {
1857
+ ordered.unshift(pageSlot);
1858
+ }
1859
+ }
1860
+ return ordered;
1829
1861
  }
1830
1862
  /**
1831
1863
  * Send selection message to orchestrator (includes element bounds for overlay positioning).
@@ -1983,7 +2015,8 @@ function AmplifyRenderer({
1983
2015
  pageConfig: serverPageConfig,
1984
2016
  loadingComponent,
1985
2017
  errorComponent,
1986
- emptyComponent
2018
+ emptyComponent,
2019
+ composerPreview
1987
2020
  }) {
1988
2021
  const clientHook = useAmplifyUp();
1989
2022
  const pageConfig = serverPageConfig || clientHook.pageConfig || null;
@@ -2265,7 +2298,7 @@ function AmplifyRenderer({
2265
2298
  "data-zone-id": slot.zoneId || void 0,
2266
2299
  "data-parent-node-id": node.id,
2267
2300
  "data-parent-component-id": node.componentId,
2268
- children: safeChildren.filter(Boolean).map((child) => renderNode(child))
2301
+ children: safeChildren.filter(Boolean).map((child) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderNode(child) }, child.id))
2269
2302
  },
2270
2303
  slot.slotId
2271
2304
  );
@@ -2289,7 +2322,7 @@ function AmplifyRenderer({
2289
2322
  if (layoutTree.length === 0) {
2290
2323
  return /* @__PURE__ */ jsxRuntime.jsx("main", { children: emptyComponent || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground", children: "No content configured for this page." }) }) });
2291
2324
  }
2292
- return /* @__PURE__ */ jsxRuntime.jsx("main", { children: isComposerPreview() ? /* @__PURE__ */ jsxRuntime.jsx(
2325
+ return /* @__PURE__ */ jsxRuntime.jsx("main", { children: composerPreview || isComposerPreview() ? /* @__PURE__ */ jsxRuntime.jsx(
2293
2326
  "div",
2294
2327
  {
2295
2328
  "data-slot-id": "main",
@@ -2320,6 +2353,7 @@ function AmplifyPageContent({
2320
2353
  fallback,
2321
2354
  renderComponent,
2322
2355
  pageConfig: pageConfigProp,
2356
+ forceComposerPreview = false,
2323
2357
  previewLoadingComponent,
2324
2358
  previewEmptyComponent,
2325
2359
  loadingComponent,
@@ -2327,7 +2361,7 @@ function AmplifyPageContent({
2327
2361
  errorComponent
2328
2362
  }) {
2329
2363
  const client = useAmplifyUp();
2330
- const preview = isComposerPreview();
2364
+ const preview = forceComposerPreview || isComposerPreview();
2331
2365
  const pageConfig = pageConfigProp ?? client.pageConfig;
2332
2366
  const loading = pageConfigProp ? false : client.loading;
2333
2367
  const error = pageConfigProp ? null : client.error;
@@ -2339,6 +2373,7 @@ function AmplifyPageContent({
2339
2373
  {
2340
2374
  pageConfig: pageConfig ?? void 0,
2341
2375
  renderComponent,
2376
+ composerPreview: true,
2342
2377
  loadingComponent: loadingComponent ?? previewLoading,
2343
2378
  emptyComponent: emptyComponent ?? previewCanvas,
2344
2379
  errorComponent: errorComponent ?? (() => previewCanvas)