@amplifyup/sdk 0.1.9 → 0.1.11
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.js +195 -13
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +195 -13
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +195 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +195 -13
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +196 -14
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +196 -14
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -349,6 +349,7 @@ var AmplifyUpSDK = class {
|
|
|
349
349
|
this.componentRegistry = [];
|
|
350
350
|
this.messageListener = null;
|
|
351
351
|
this.mutationObserver = null;
|
|
352
|
+
this.composerDragHandlers = null;
|
|
352
353
|
this.isVisualEditorMode = false;
|
|
353
354
|
this.eventSelectionMode = false;
|
|
354
355
|
this.eventSelectionClickHandler = null;
|
|
@@ -1081,6 +1082,39 @@ Available Console Commands:
|
|
|
1081
1082
|
this.attachEventListeners();
|
|
1082
1083
|
}
|
|
1083
1084
|
}
|
|
1085
|
+
/** Origins allowed to send Composer postMessage commands to the SDK. */
|
|
1086
|
+
isAllowedComposerOrigin(origin) {
|
|
1087
|
+
if (typeof window === "undefined") return false;
|
|
1088
|
+
if (origin === window.location.origin) return true;
|
|
1089
|
+
const staticAllowed = [
|
|
1090
|
+
"http://localhost:5001",
|
|
1091
|
+
"http://localhost:3001",
|
|
1092
|
+
"https://amplifyup.ai",
|
|
1093
|
+
"https://orchestrator.amplifyup.com"
|
|
1094
|
+
];
|
|
1095
|
+
if (staticAllowed.includes(origin)) return true;
|
|
1096
|
+
try {
|
|
1097
|
+
const host = new URL(origin).hostname;
|
|
1098
|
+
if (host === "amplifyup.ai" || host.endsWith(".amplifyup.ai")) return true;
|
|
1099
|
+
} catch {
|
|
1100
|
+
}
|
|
1101
|
+
const orchestratorFromQuery = (() => {
|
|
1102
|
+
try {
|
|
1103
|
+
const value = new URLSearchParams(window.location.search).get("orchestratorUrl");
|
|
1104
|
+
return value ? new URL(value).origin : null;
|
|
1105
|
+
} catch {
|
|
1106
|
+
return null;
|
|
1107
|
+
}
|
|
1108
|
+
})();
|
|
1109
|
+
if (orchestratorFromQuery && origin === orchestratorFromQuery) return true;
|
|
1110
|
+
if (this.orchestratorUrl) {
|
|
1111
|
+
try {
|
|
1112
|
+
if (new URL(this.orchestratorUrl).origin === origin) return true;
|
|
1113
|
+
} catch {
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return false;
|
|
1117
|
+
}
|
|
1084
1118
|
/**
|
|
1085
1119
|
* Set up postMessage listener for highlighting commands from orchestrator
|
|
1086
1120
|
*/
|
|
@@ -1096,18 +1130,10 @@ Available Console Commands:
|
|
|
1096
1130
|
currentOrigin: window.location.origin,
|
|
1097
1131
|
data: event.data
|
|
1098
1132
|
});
|
|
1099
|
-
|
|
1100
|
-
"http://localhost:5001",
|
|
1101
|
-
"http://localhost:3001",
|
|
1102
|
-
"https://orchestrator.amplifyup.com"
|
|
1103
|
-
];
|
|
1104
|
-
const isSameOrigin = event.origin === window.location.origin;
|
|
1105
|
-
const isAllowedOrigin = allowedOrigins.some((origin) => event.origin.startsWith(origin));
|
|
1106
|
-
if (!isSameOrigin && !isAllowedOrigin) {
|
|
1133
|
+
if (!this.isAllowedComposerOrigin(event.origin)) {
|
|
1107
1134
|
console.warn("[AmplifyUp SDK] Rejected message from unauthorized origin:", {
|
|
1108
1135
|
eventOrigin: event.origin,
|
|
1109
|
-
currentOrigin: window.location.origin
|
|
1110
|
-
allowedOrigins
|
|
1136
|
+
currentOrigin: window.location.origin
|
|
1111
1137
|
});
|
|
1112
1138
|
return;
|
|
1113
1139
|
}
|
|
@@ -1287,6 +1313,111 @@ Available Console Commands:
|
|
|
1287
1313
|
this.applyComponentHighlights(highlightComponents, showZones);
|
|
1288
1314
|
this.setupMutationObserver();
|
|
1289
1315
|
}
|
|
1316
|
+
if (showZones) {
|
|
1317
|
+
this.setupComposerDragDrop();
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
/** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
|
|
1321
|
+
setupComposerDragDrop() {
|
|
1322
|
+
if (typeof document === "undefined") return;
|
|
1323
|
+
this.teardownComposerDragDrop();
|
|
1324
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1325
|
+
const clearDragOverState = () => {
|
|
1326
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1327
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1328
|
+
});
|
|
1329
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1330
|
+
};
|
|
1331
|
+
const dragenter = (e) => {
|
|
1332
|
+
e.preventDefault();
|
|
1333
|
+
if (e.dataTransfer?.types?.length) {
|
|
1334
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1335
|
+
}
|
|
1336
|
+
};
|
|
1337
|
+
const dragover = (e) => {
|
|
1338
|
+
e.preventDefault();
|
|
1339
|
+
const target = e.target;
|
|
1340
|
+
const slot = target?.closest?.(slotSelector);
|
|
1341
|
+
if (e.dataTransfer) {
|
|
1342
|
+
e.dataTransfer.dropEffect = slot ? "copy" : "none";
|
|
1343
|
+
}
|
|
1344
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1345
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1346
|
+
});
|
|
1347
|
+
if (slot) {
|
|
1348
|
+
slot.classList.add("amplifyup-drag-over-slot");
|
|
1349
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1350
|
+
} else {
|
|
1351
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1352
|
+
}
|
|
1353
|
+
};
|
|
1354
|
+
const dragleave = (e) => {
|
|
1355
|
+
const related = e.relatedTarget;
|
|
1356
|
+
if (!related || !document.body.contains(related)) {
|
|
1357
|
+
clearDragOverState();
|
|
1358
|
+
}
|
|
1359
|
+
};
|
|
1360
|
+
const drop = (e) => {
|
|
1361
|
+
e.preventDefault();
|
|
1362
|
+
const target = e.target;
|
|
1363
|
+
const slot = target?.closest?.(slotSelector);
|
|
1364
|
+
clearDragOverState();
|
|
1365
|
+
if (!slot || !this.isVisualEditorMode) return;
|
|
1366
|
+
const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
|
|
1367
|
+
const isEmpty = slot.getAttribute("data-slot-empty") === "true";
|
|
1368
|
+
const win = window;
|
|
1369
|
+
if (slotName && win.parent && win.parent !== win) {
|
|
1370
|
+
win.parent.postMessage({
|
|
1371
|
+
type: "DROP_ON_SLOT",
|
|
1372
|
+
slotName,
|
|
1373
|
+
slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
|
|
1374
|
+
}, "*");
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
const mouseover = (e) => {
|
|
1378
|
+
if (!this.showZonesEnabled) return;
|
|
1379
|
+
const target = e.target;
|
|
1380
|
+
const slot = target?.closest?.(slotSelector);
|
|
1381
|
+
if (!slot) return;
|
|
1382
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1383
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1384
|
+
});
|
|
1385
|
+
slot.classList.add("amplifyup-slot-hover");
|
|
1386
|
+
};
|
|
1387
|
+
const mouseout = (e) => {
|
|
1388
|
+
if (!this.showZonesEnabled) return;
|
|
1389
|
+
const related = e.relatedTarget;
|
|
1390
|
+
if (!related?.closest?.(slotSelector)) {
|
|
1391
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1392
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
document.addEventListener("dragenter", dragenter, false);
|
|
1397
|
+
document.addEventListener("dragover", dragover, false);
|
|
1398
|
+
document.addEventListener("dragleave", dragleave, false);
|
|
1399
|
+
document.addEventListener("drop", drop, false);
|
|
1400
|
+
document.addEventListener("mouseover", mouseover, true);
|
|
1401
|
+
document.addEventListener("mouseout", mouseout, true);
|
|
1402
|
+
this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
|
|
1403
|
+
}
|
|
1404
|
+
teardownComposerDragDrop() {
|
|
1405
|
+
if (!this.composerDragHandlers || typeof document === "undefined") return;
|
|
1406
|
+
const h = this.composerDragHandlers;
|
|
1407
|
+
document.removeEventListener("dragenter", h.dragenter, false);
|
|
1408
|
+
document.removeEventListener("dragover", h.dragover, false);
|
|
1409
|
+
document.removeEventListener("dragleave", h.dragleave, false);
|
|
1410
|
+
document.removeEventListener("drop", h.drop, false);
|
|
1411
|
+
document.removeEventListener("mouseover", h.mouseover, true);
|
|
1412
|
+
document.removeEventListener("mouseout", h.mouseout, true);
|
|
1413
|
+
this.composerDragHandlers = null;
|
|
1414
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1415
|
+
document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
|
|
1416
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1417
|
+
});
|
|
1418
|
+
document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
|
|
1419
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1420
|
+
});
|
|
1290
1421
|
}
|
|
1291
1422
|
/** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
|
|
1292
1423
|
injectComposerHighlightStyles(highlightComponents, showZones) {
|
|
@@ -1313,19 +1444,64 @@ Available Console Commands:
|
|
|
1313
1444
|
" outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
|
|
1314
1445
|
" outline-offset: 4px !important;",
|
|
1315
1446
|
" min-height: 3rem !important;",
|
|
1447
|
+
" padding: 20px !important;",
|
|
1316
1448
|
" box-sizing: border-box !important;",
|
|
1317
1449
|
" cursor: pointer !important;",
|
|
1450
|
+
" position: relative !important;",
|
|
1318
1451
|
"}",
|
|
1319
1452
|
'[data-slot-id="main"], [data-amplifyup-slot="main"] {',
|
|
1320
1453
|
" min-height: 50vh !important;",
|
|
1321
1454
|
"}",
|
|
1455
|
+
'[data-slot-id="main"][data-slot-empty="true"]::before,',
|
|
1456
|
+
'[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
|
|
1457
|
+
' content: "Drop components here" !important;',
|
|
1458
|
+
" position: absolute !important;",
|
|
1459
|
+
" top: 50% !important; left: 50% !important;",
|
|
1460
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1461
|
+
" font-size: 14px !important; font-weight: 500 !important;",
|
|
1462
|
+
" color: rgba(34, 197, 94, 0.65) !important;",
|
|
1463
|
+
" pointer-events: none !important;",
|
|
1464
|
+
" white-space: nowrap !important;",
|
|
1465
|
+
"}",
|
|
1322
1466
|
"[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
|
|
1323
1467
|
" outline-color: rgba(34, 197, 94, 1) !important;",
|
|
1324
1468
|
" background: rgba(34, 197, 94, 0.06) !important;",
|
|
1325
1469
|
"}",
|
|
1326
1470
|
"[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
|
|
1327
1471
|
" outline: 2px solid rgba(34, 197, 94, 1) !important;",
|
|
1328
|
-
" background: rgba(34, 197, 94, 0.
|
|
1472
|
+
" background: rgba(34, 197, 94, 0.18) !important;",
|
|
1473
|
+
" position: relative !important;",
|
|
1474
|
+
"}",
|
|
1475
|
+
"[data-slot-id].amplifyup-drag-over-slot::after,",
|
|
1476
|
+
"[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
|
|
1477
|
+
' content: "\\2713 Drop here" !important;',
|
|
1478
|
+
" position: absolute !important;",
|
|
1479
|
+
" top: 50% !important; left: 50% !important;",
|
|
1480
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1481
|
+
" font-size: 14px !important; font-weight: 600 !important;",
|
|
1482
|
+
" color: rgb(22, 163, 74) !important;",
|
|
1483
|
+
" pointer-events: none !important;",
|
|
1484
|
+
" white-space: nowrap !important;",
|
|
1485
|
+
" z-index: 1 !important;",
|
|
1486
|
+
"}",
|
|
1487
|
+
"body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
|
|
1488
|
+
"body.amplifyup-drag-no-drop::before {",
|
|
1489
|
+
' content: "" !important;',
|
|
1490
|
+
" position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
|
|
1491
|
+
" background: rgba(239, 68, 68, 0.06) !important;",
|
|
1492
|
+
" pointer-events: none !important;",
|
|
1493
|
+
" z-index: 2147483646 !important;",
|
|
1494
|
+
"}",
|
|
1495
|
+
"body.amplifyup-drag-no-drop::after {",
|
|
1496
|
+
' content: "\\2717 Not a drop zone" !important;',
|
|
1497
|
+
" position: fixed !important; bottom: 12px !important; right: 12px !important;",
|
|
1498
|
+
" font-size: 12px !important; font-weight: 600 !important;",
|
|
1499
|
+
" color: rgb(185, 28, 28) !important;",
|
|
1500
|
+
" background: rgba(254, 226, 226, 0.95) !important;",
|
|
1501
|
+
" padding: 6px 10px !important; border-radius: 6px !important;",
|
|
1502
|
+
" pointer-events: none !important;",
|
|
1503
|
+
" z-index: 2147483647 !important;",
|
|
1504
|
+
" box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
|
|
1329
1505
|
"}"
|
|
1330
1506
|
);
|
|
1331
1507
|
}
|
|
@@ -1385,6 +1561,7 @@ Available Console Commands:
|
|
|
1385
1561
|
disableHighlighting() {
|
|
1386
1562
|
if (typeof document === "undefined") return;
|
|
1387
1563
|
this.highlightingEnabled = false;
|
|
1564
|
+
this.teardownComposerDragDrop();
|
|
1388
1565
|
if (this.mutationObserver) {
|
|
1389
1566
|
this.mutationObserver.disconnect();
|
|
1390
1567
|
this.mutationObserver = null;
|
|
@@ -1545,9 +1722,15 @@ Available Console Commands:
|
|
|
1545
1722
|
e.preventDefault();
|
|
1546
1723
|
e.stopPropagation();
|
|
1547
1724
|
htmlEl.classList.remove("amplifyup-drag-over-slot");
|
|
1725
|
+
if (!win.parent || win.parent === win) return;
|
|
1726
|
+
win.parent.postMessage({
|
|
1727
|
+
type: "DROP_ON_SLOT",
|
|
1728
|
+
slotName,
|
|
1729
|
+
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1730
|
+
}, "*");
|
|
1548
1731
|
try {
|
|
1549
1732
|
const data = JSON.parse(e.dataTransfer.getData("application/json"));
|
|
1550
|
-
if (data.type === "component"
|
|
1733
|
+
if (data.type === "component") {
|
|
1551
1734
|
win.parent.postMessage({
|
|
1552
1735
|
type: "COMPONENT_DROPPED",
|
|
1553
1736
|
componentId: data.componentId,
|
|
@@ -1555,7 +1738,6 @@ Available Console Commands:
|
|
|
1555
1738
|
slotName,
|
|
1556
1739
|
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1557
1740
|
}, "*");
|
|
1558
|
-
win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
|
|
1559
1741
|
}
|
|
1560
1742
|
} catch (_err) {
|
|
1561
1743
|
}
|
|
@@ -1926,7 +2108,7 @@ function defaultPreviewCanvas() {
|
|
|
1926
2108
|
"data-slot-id": "main",
|
|
1927
2109
|
"data-amplifyup-slot": "main",
|
|
1928
2110
|
"data-slot-empty": "true",
|
|
1929
|
-
|
|
2111
|
+
style: { minHeight: "50vh", width: "100%", display: "block" }
|
|
1930
2112
|
}
|
|
1931
2113
|
);
|
|
1932
2114
|
}
|