@amplifyup/sdk 0.1.13 → 0.1.15
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/AmplifyRenderer.d.mts +6 -1
- package/dist/AmplifyRenderer.d.ts +6 -1
- package/dist/AmplifyRenderer.js +48 -10
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +48 -10
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.js +34 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -2
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +6 -1
- package/dist/react.d.ts +6 -1
- package/dist/react.js +51 -11
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +51 -11
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -1223,6 +1223,11 @@ Available Console Commands:
|
|
|
1223
1223
|
`[data-node-id="${nodeId}"]`
|
|
1224
1224
|
);
|
|
1225
1225
|
}
|
|
1226
|
+
if (!element && slotName) {
|
|
1227
|
+
element = document.querySelector(
|
|
1228
|
+
`[data-slot-source="page"][data-slot-id="${slotName}"], [data-slot-source="page"][data-amplifyup-slot="${slotName}"]`
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1226
1231
|
if (!element && slotName) {
|
|
1227
1232
|
element = document.querySelector(
|
|
1228
1233
|
`[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]`
|
|
@@ -1255,12 +1260,28 @@ Available Console Commands:
|
|
|
1255
1260
|
height: rect.height
|
|
1256
1261
|
};
|
|
1257
1262
|
if (window.parent && window.parent !== window) {
|
|
1263
|
+
const hierarchyEls = this.buildComponentHierarchy(element);
|
|
1258
1264
|
window.parent.postMessage({
|
|
1259
1265
|
type: "ELEMENT_POSITION",
|
|
1260
1266
|
componentId: componentId || null,
|
|
1261
1267
|
slotName: slotName || null,
|
|
1262
1268
|
nodeId: nodeId || null,
|
|
1263
|
-
isPageSlot: !!isPageSlot,
|
|
1269
|
+
isPageSlot: !!isPageSlot || element.getAttribute("data-slot-source") === "page",
|
|
1270
|
+
hierarchy: hierarchyEls.map((el, index) => {
|
|
1271
|
+
const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
|
|
1272
|
+
const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
|
|
1273
|
+
const isSlot = !elComponentId && !!elSlotName;
|
|
1274
|
+
const pageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
|
|
1275
|
+
return {
|
|
1276
|
+
index,
|
|
1277
|
+
componentId: elComponentId,
|
|
1278
|
+
componentName: pageSlot ? "Page" : el.getAttribute("data-component-name"),
|
|
1279
|
+
slotName: isSlot ? elSlotName : null,
|
|
1280
|
+
isSlot,
|
|
1281
|
+
isPageSlot: pageSlot,
|
|
1282
|
+
nodeId: el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null)
|
|
1283
|
+
};
|
|
1284
|
+
}),
|
|
1264
1285
|
position,
|
|
1265
1286
|
bounds
|
|
1266
1287
|
}, "*");
|
|
@@ -1817,13 +1838,24 @@ Available Console Commands:
|
|
|
1817
1838
|
buildComponentHierarchy(element) {
|
|
1818
1839
|
const hierarchy = [];
|
|
1819
1840
|
let current = element;
|
|
1841
|
+
let sawPageSlot = false;
|
|
1820
1842
|
while (current) {
|
|
1821
1843
|
if (current.hasAttribute("data-amplifyup-component") || current.hasAttribute("data-component-id") || current.hasAttribute("data-amplifyup-slot") || current.hasAttribute("data-slot-id")) {
|
|
1822
1844
|
hierarchy.push(current);
|
|
1845
|
+
if (current.getAttribute("data-slot-source") === "page") {
|
|
1846
|
+
sawPageSlot = true;
|
|
1847
|
+
}
|
|
1823
1848
|
}
|
|
1824
1849
|
current = current.parentElement;
|
|
1825
1850
|
}
|
|
1826
|
-
|
|
1851
|
+
const ordered = hierarchy.reverse();
|
|
1852
|
+
if (!sawPageSlot) {
|
|
1853
|
+
const pageSlot = element.closest('[data-slot-source="page"]');
|
|
1854
|
+
if (pageSlot && !ordered.includes(pageSlot)) {
|
|
1855
|
+
ordered.unshift(pageSlot);
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
return ordered;
|
|
1827
1859
|
}
|
|
1828
1860
|
/**
|
|
1829
1861
|
* Send selection message to orchestrator (includes element bounds for overlay positioning).
|
|
@@ -1981,7 +2013,8 @@ function AmplifyRenderer({
|
|
|
1981
2013
|
pageConfig: serverPageConfig,
|
|
1982
2014
|
loadingComponent,
|
|
1983
2015
|
errorComponent,
|
|
1984
|
-
emptyComponent
|
|
2016
|
+
emptyComponent,
|
|
2017
|
+
composerPreview
|
|
1985
2018
|
}) {
|
|
1986
2019
|
const clientHook = useAmplifyUp();
|
|
1987
2020
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
@@ -2040,7 +2073,9 @@ function AmplifyRenderer({
|
|
|
2040
2073
|
if (!pageConfig) {
|
|
2041
2074
|
return;
|
|
2042
2075
|
}
|
|
2043
|
-
|
|
2076
|
+
const rawTree2 = pageConfig.layoutTree;
|
|
2077
|
+
const normalizedTree = Array.isArray(rawTree2) ? rawTree2 : rawTree2 && typeof rawTree2 === "object" && rawTree2.componentId ? [rawTree2] : [];
|
|
2078
|
+
if (normalizedTree.length === 0) {
|
|
2044
2079
|
if (typeof window !== "undefined" && window.parent && window.parent !== window) {
|
|
2045
2080
|
window.parent.postMessage({
|
|
2046
2081
|
type: "COMPONENT_TREE",
|
|
@@ -2052,6 +2087,7 @@ function AmplifyRenderer({
|
|
|
2052
2087
|
const convertLayoutTreeToComponentTree = (nodes, parentId = null) => {
|
|
2053
2088
|
const result = [];
|
|
2054
2089
|
nodes.forEach((node) => {
|
|
2090
|
+
if (!node) return;
|
|
2055
2091
|
const treeNode = {
|
|
2056
2092
|
id: node.id,
|
|
2057
2093
|
componentId: node.componentId,
|
|
@@ -2062,8 +2098,9 @@ function AmplifyRenderer({
|
|
|
2062
2098
|
};
|
|
2063
2099
|
if (node.slots && node.slots.length > 0) {
|
|
2064
2100
|
node.slots.forEach((slot) => {
|
|
2065
|
-
|
|
2066
|
-
|
|
2101
|
+
const kids = Array.isArray(slot?.children) ? slot.children : [];
|
|
2102
|
+
if (kids.length > 0) {
|
|
2103
|
+
const slotChildren = convertLayoutTreeToComponentTree(kids, node.id);
|
|
2067
2104
|
treeNode.children.push(...slotChildren);
|
|
2068
2105
|
}
|
|
2069
2106
|
});
|
|
@@ -2072,7 +2109,7 @@ function AmplifyRenderer({
|
|
|
2072
2109
|
});
|
|
2073
2110
|
return result;
|
|
2074
2111
|
};
|
|
2075
|
-
const layoutTree2 =
|
|
2112
|
+
const layoutTree2 = normalizedTree;
|
|
2076
2113
|
const componentTree = convertLayoutTreeToComponentTree(layoutTree2);
|
|
2077
2114
|
const describeLayoutTree = (nodes, depth = 0) => {
|
|
2078
2115
|
if (!nodes?.length) return "";
|
|
@@ -2245,11 +2282,12 @@ function AmplifyRenderer({
|
|
|
2245
2282
|
childrenCount: childrenToRender.length
|
|
2246
2283
|
});
|
|
2247
2284
|
} else {
|
|
2248
|
-
childrenToRender = slot.children;
|
|
2285
|
+
childrenToRender = Array.isArray(slot.children) ? slot.children : [];
|
|
2249
2286
|
console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
|
|
2250
2287
|
childrenCount: childrenToRender.length
|
|
2251
2288
|
});
|
|
2252
2289
|
}
|
|
2290
|
+
const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
|
|
2253
2291
|
slotChildren[slot.slotId] = /* @__PURE__ */ jsx(
|
|
2254
2292
|
"div",
|
|
2255
2293
|
{
|
|
@@ -2258,7 +2296,7 @@ function AmplifyRenderer({
|
|
|
2258
2296
|
"data-zone-id": slot.zoneId || void 0,
|
|
2259
2297
|
"data-parent-node-id": node.id,
|
|
2260
2298
|
"data-parent-component-id": node.componentId,
|
|
2261
|
-
children:
|
|
2299
|
+
children: safeChildren.filter(Boolean).map((child) => renderNode(child))
|
|
2262
2300
|
},
|
|
2263
2301
|
slot.slotId
|
|
2264
2302
|
);
|
|
@@ -2282,7 +2320,7 @@ function AmplifyRenderer({
|
|
|
2282
2320
|
if (layoutTree.length === 0) {
|
|
2283
2321
|
return /* @__PURE__ */ jsx("main", { children: emptyComponent || /* @__PURE__ */ jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: "No content configured for this page." }) }) });
|
|
2284
2322
|
}
|
|
2285
|
-
return /* @__PURE__ */ jsx("main", { children: isComposerPreview() ? /* @__PURE__ */ jsx(
|
|
2323
|
+
return /* @__PURE__ */ jsx("main", { children: composerPreview || isComposerPreview() ? /* @__PURE__ */ jsx(
|
|
2286
2324
|
"div",
|
|
2287
2325
|
{
|
|
2288
2326
|
"data-slot-id": "main",
|
|
@@ -2313,6 +2351,7 @@ function AmplifyPageContent({
|
|
|
2313
2351
|
fallback,
|
|
2314
2352
|
renderComponent,
|
|
2315
2353
|
pageConfig: pageConfigProp,
|
|
2354
|
+
forceComposerPreview = false,
|
|
2316
2355
|
previewLoadingComponent,
|
|
2317
2356
|
previewEmptyComponent,
|
|
2318
2357
|
loadingComponent,
|
|
@@ -2320,7 +2359,7 @@ function AmplifyPageContent({
|
|
|
2320
2359
|
errorComponent
|
|
2321
2360
|
}) {
|
|
2322
2361
|
const client = useAmplifyUp();
|
|
2323
|
-
const preview = isComposerPreview();
|
|
2362
|
+
const preview = forceComposerPreview || isComposerPreview();
|
|
2324
2363
|
const pageConfig = pageConfigProp ?? client.pageConfig;
|
|
2325
2364
|
const loading = pageConfigProp ? false : client.loading;
|
|
2326
2365
|
const error = pageConfigProp ? null : client.error;
|
|
@@ -2332,6 +2371,7 @@ function AmplifyPageContent({
|
|
|
2332
2371
|
{
|
|
2333
2372
|
pageConfig: pageConfig ?? void 0,
|
|
2334
2373
|
renderComponent,
|
|
2374
|
+
composerPreview: true,
|
|
2335
2375
|
loadingComponent: loadingComponent ?? previewLoading,
|
|
2336
2376
|
emptyComponent: emptyComponent ?? previewCanvas,
|
|
2337
2377
|
errorComponent: errorComponent ?? (() => previewCanvas)
|