@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/AmplifyRenderer.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).
|
|
@@ -2000,7 +2032,8 @@ function AmplifyRenderer({
|
|
|
2000
2032
|
pageConfig: serverPageConfig,
|
|
2001
2033
|
loadingComponent,
|
|
2002
2034
|
errorComponent,
|
|
2003
|
-
emptyComponent
|
|
2035
|
+
emptyComponent,
|
|
2036
|
+
composerPreview
|
|
2004
2037
|
}) {
|
|
2005
2038
|
const clientHook = useAmplifyUp();
|
|
2006
2039
|
const pageConfig = serverPageConfig || clientHook.pageConfig || null;
|
|
@@ -2059,7 +2092,9 @@ function AmplifyRenderer({
|
|
|
2059
2092
|
if (!pageConfig) {
|
|
2060
2093
|
return;
|
|
2061
2094
|
}
|
|
2062
|
-
|
|
2095
|
+
const rawTree2 = pageConfig.layoutTree;
|
|
2096
|
+
const normalizedTree = Array.isArray(rawTree2) ? rawTree2 : rawTree2 && typeof rawTree2 === "object" && rawTree2.componentId ? [rawTree2] : [];
|
|
2097
|
+
if (normalizedTree.length === 0) {
|
|
2063
2098
|
if (typeof window !== "undefined" && window.parent && window.parent !== window) {
|
|
2064
2099
|
window.parent.postMessage({
|
|
2065
2100
|
type: "COMPONENT_TREE",
|
|
@@ -2071,6 +2106,7 @@ function AmplifyRenderer({
|
|
|
2071
2106
|
const convertLayoutTreeToComponentTree = (nodes, parentId = null) => {
|
|
2072
2107
|
const result = [];
|
|
2073
2108
|
nodes.forEach((node) => {
|
|
2109
|
+
if (!node) return;
|
|
2074
2110
|
const treeNode = {
|
|
2075
2111
|
id: node.id,
|
|
2076
2112
|
componentId: node.componentId,
|
|
@@ -2081,8 +2117,9 @@ function AmplifyRenderer({
|
|
|
2081
2117
|
};
|
|
2082
2118
|
if (node.slots && node.slots.length > 0) {
|
|
2083
2119
|
node.slots.forEach((slot) => {
|
|
2084
|
-
|
|
2085
|
-
|
|
2120
|
+
const kids = Array.isArray(slot?.children) ? slot.children : [];
|
|
2121
|
+
if (kids.length > 0) {
|
|
2122
|
+
const slotChildren = convertLayoutTreeToComponentTree(kids, node.id);
|
|
2086
2123
|
treeNode.children.push(...slotChildren);
|
|
2087
2124
|
}
|
|
2088
2125
|
});
|
|
@@ -2091,7 +2128,7 @@ function AmplifyRenderer({
|
|
|
2091
2128
|
});
|
|
2092
2129
|
return result;
|
|
2093
2130
|
};
|
|
2094
|
-
const layoutTree2 =
|
|
2131
|
+
const layoutTree2 = normalizedTree;
|
|
2095
2132
|
const componentTree = convertLayoutTreeToComponentTree(layoutTree2);
|
|
2096
2133
|
const describeLayoutTree = (nodes, depth = 0) => {
|
|
2097
2134
|
if (!nodes?.length) return "";
|
|
@@ -2264,11 +2301,12 @@ function AmplifyRenderer({
|
|
|
2264
2301
|
childrenCount: childrenToRender.length
|
|
2265
2302
|
});
|
|
2266
2303
|
} else {
|
|
2267
|
-
childrenToRender = slot.children;
|
|
2304
|
+
childrenToRender = Array.isArray(slot.children) ? slot.children : [];
|
|
2268
2305
|
console.log(`[AmplifyRenderer] Using direct children for slot ${slot.slotId}`, {
|
|
2269
2306
|
childrenCount: childrenToRender.length
|
|
2270
2307
|
});
|
|
2271
2308
|
}
|
|
2309
|
+
const safeChildren = Array.isArray(childrenToRender) ? childrenToRender : [];
|
|
2272
2310
|
slotChildren[slot.slotId] = /* @__PURE__ */ jsx(
|
|
2273
2311
|
"div",
|
|
2274
2312
|
{
|
|
@@ -2277,7 +2315,7 @@ function AmplifyRenderer({
|
|
|
2277
2315
|
"data-zone-id": slot.zoneId || void 0,
|
|
2278
2316
|
"data-parent-node-id": node.id,
|
|
2279
2317
|
"data-parent-component-id": node.componentId,
|
|
2280
|
-
children:
|
|
2318
|
+
children: safeChildren.filter(Boolean).map((child) => renderNode(child))
|
|
2281
2319
|
},
|
|
2282
2320
|
slot.slotId
|
|
2283
2321
|
);
|
|
@@ -2301,7 +2339,7 @@ function AmplifyRenderer({
|
|
|
2301
2339
|
if (layoutTree.length === 0) {
|
|
2302
2340
|
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." }) }) });
|
|
2303
2341
|
}
|
|
2304
|
-
return /* @__PURE__ */ jsx("main", { children: isComposerPreview() ? /* @__PURE__ */ jsx(
|
|
2342
|
+
return /* @__PURE__ */ jsx("main", { children: composerPreview || isComposerPreview() ? /* @__PURE__ */ jsx(
|
|
2305
2343
|
"div",
|
|
2306
2344
|
{
|
|
2307
2345
|
"data-slot-id": "main",
|