@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/index.mjs
CHANGED
|
@@ -339,6 +339,7 @@ var AmplifyUpSDK = class {
|
|
|
339
339
|
this.componentRegistry = [];
|
|
340
340
|
this.messageListener = null;
|
|
341
341
|
this.mutationObserver = null;
|
|
342
|
+
this.composerDragHandlers = null;
|
|
342
343
|
this.isVisualEditorMode = false;
|
|
343
344
|
this.eventSelectionMode = false;
|
|
344
345
|
this.eventSelectionClickHandler = null;
|
|
@@ -1071,6 +1072,39 @@ Available Console Commands:
|
|
|
1071
1072
|
this.attachEventListeners();
|
|
1072
1073
|
}
|
|
1073
1074
|
}
|
|
1075
|
+
/** Origins allowed to send Composer postMessage commands to the SDK. */
|
|
1076
|
+
isAllowedComposerOrigin(origin) {
|
|
1077
|
+
if (typeof window === "undefined") return false;
|
|
1078
|
+
if (origin === window.location.origin) return true;
|
|
1079
|
+
const staticAllowed = [
|
|
1080
|
+
"http://localhost:5001",
|
|
1081
|
+
"http://localhost:3001",
|
|
1082
|
+
"https://amplifyup.ai",
|
|
1083
|
+
"https://orchestrator.amplifyup.com"
|
|
1084
|
+
];
|
|
1085
|
+
if (staticAllowed.includes(origin)) return true;
|
|
1086
|
+
try {
|
|
1087
|
+
const host = new URL(origin).hostname;
|
|
1088
|
+
if (host === "amplifyup.ai" || host.endsWith(".amplifyup.ai")) return true;
|
|
1089
|
+
} catch {
|
|
1090
|
+
}
|
|
1091
|
+
const orchestratorFromQuery = (() => {
|
|
1092
|
+
try {
|
|
1093
|
+
const value = new URLSearchParams(window.location.search).get("orchestratorUrl");
|
|
1094
|
+
return value ? new URL(value).origin : null;
|
|
1095
|
+
} catch {
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
})();
|
|
1099
|
+
if (orchestratorFromQuery && origin === orchestratorFromQuery) return true;
|
|
1100
|
+
if (this.orchestratorUrl) {
|
|
1101
|
+
try {
|
|
1102
|
+
if (new URL(this.orchestratorUrl).origin === origin) return true;
|
|
1103
|
+
} catch {
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
return false;
|
|
1107
|
+
}
|
|
1074
1108
|
/**
|
|
1075
1109
|
* Set up postMessage listener for highlighting commands from orchestrator
|
|
1076
1110
|
*/
|
|
@@ -1086,18 +1120,10 @@ Available Console Commands:
|
|
|
1086
1120
|
currentOrigin: window.location.origin,
|
|
1087
1121
|
data: event.data
|
|
1088
1122
|
});
|
|
1089
|
-
|
|
1090
|
-
"http://localhost:5001",
|
|
1091
|
-
"http://localhost:3001",
|
|
1092
|
-
"https://orchestrator.amplifyup.com"
|
|
1093
|
-
];
|
|
1094
|
-
const isSameOrigin = event.origin === window.location.origin;
|
|
1095
|
-
const isAllowedOrigin = allowedOrigins.some((origin) => event.origin.startsWith(origin));
|
|
1096
|
-
if (!isSameOrigin && !isAllowedOrigin) {
|
|
1123
|
+
if (!this.isAllowedComposerOrigin(event.origin)) {
|
|
1097
1124
|
console.warn("[AmplifyUp SDK] Rejected message from unauthorized origin:", {
|
|
1098
1125
|
eventOrigin: event.origin,
|
|
1099
|
-
currentOrigin: window.location.origin
|
|
1100
|
-
allowedOrigins
|
|
1126
|
+
currentOrigin: window.location.origin
|
|
1101
1127
|
});
|
|
1102
1128
|
return;
|
|
1103
1129
|
}
|
|
@@ -1277,6 +1303,111 @@ Available Console Commands:
|
|
|
1277
1303
|
this.applyComponentHighlights(highlightComponents, showZones);
|
|
1278
1304
|
this.setupMutationObserver();
|
|
1279
1305
|
}
|
|
1306
|
+
if (showZones) {
|
|
1307
|
+
this.setupComposerDragDrop();
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
/** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
|
|
1311
|
+
setupComposerDragDrop() {
|
|
1312
|
+
if (typeof document === "undefined") return;
|
|
1313
|
+
this.teardownComposerDragDrop();
|
|
1314
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1315
|
+
const clearDragOverState = () => {
|
|
1316
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1317
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1318
|
+
});
|
|
1319
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1320
|
+
};
|
|
1321
|
+
const dragenter = (e) => {
|
|
1322
|
+
e.preventDefault();
|
|
1323
|
+
if (e.dataTransfer?.types?.length) {
|
|
1324
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
const dragover = (e) => {
|
|
1328
|
+
e.preventDefault();
|
|
1329
|
+
const target = e.target;
|
|
1330
|
+
const slot = target?.closest?.(slotSelector);
|
|
1331
|
+
if (e.dataTransfer) {
|
|
1332
|
+
e.dataTransfer.dropEffect = slot ? "copy" : "none";
|
|
1333
|
+
}
|
|
1334
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1335
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1336
|
+
});
|
|
1337
|
+
if (slot) {
|
|
1338
|
+
slot.classList.add("amplifyup-drag-over-slot");
|
|
1339
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1340
|
+
} else {
|
|
1341
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
const dragleave = (e) => {
|
|
1345
|
+
const related = e.relatedTarget;
|
|
1346
|
+
if (!related || !document.body.contains(related)) {
|
|
1347
|
+
clearDragOverState();
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
const drop = (e) => {
|
|
1351
|
+
e.preventDefault();
|
|
1352
|
+
const target = e.target;
|
|
1353
|
+
const slot = target?.closest?.(slotSelector);
|
|
1354
|
+
clearDragOverState();
|
|
1355
|
+
if (!slot || !this.isVisualEditorMode) return;
|
|
1356
|
+
const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
|
|
1357
|
+
const isEmpty = slot.getAttribute("data-slot-empty") === "true";
|
|
1358
|
+
const win = window;
|
|
1359
|
+
if (slotName && win.parent && win.parent !== win) {
|
|
1360
|
+
win.parent.postMessage({
|
|
1361
|
+
type: "DROP_ON_SLOT",
|
|
1362
|
+
slotName,
|
|
1363
|
+
slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
|
|
1364
|
+
}, "*");
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
const mouseover = (e) => {
|
|
1368
|
+
if (!this.showZonesEnabled) return;
|
|
1369
|
+
const target = e.target;
|
|
1370
|
+
const slot = target?.closest?.(slotSelector);
|
|
1371
|
+
if (!slot) return;
|
|
1372
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1373
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1374
|
+
});
|
|
1375
|
+
slot.classList.add("amplifyup-slot-hover");
|
|
1376
|
+
};
|
|
1377
|
+
const mouseout = (e) => {
|
|
1378
|
+
if (!this.showZonesEnabled) return;
|
|
1379
|
+
const related = e.relatedTarget;
|
|
1380
|
+
if (!related?.closest?.(slotSelector)) {
|
|
1381
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1382
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
document.addEventListener("dragenter", dragenter, false);
|
|
1387
|
+
document.addEventListener("dragover", dragover, false);
|
|
1388
|
+
document.addEventListener("dragleave", dragleave, false);
|
|
1389
|
+
document.addEventListener("drop", drop, false);
|
|
1390
|
+
document.addEventListener("mouseover", mouseover, true);
|
|
1391
|
+
document.addEventListener("mouseout", mouseout, true);
|
|
1392
|
+
this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
|
|
1393
|
+
}
|
|
1394
|
+
teardownComposerDragDrop() {
|
|
1395
|
+
if (!this.composerDragHandlers || typeof document === "undefined") return;
|
|
1396
|
+
const h = this.composerDragHandlers;
|
|
1397
|
+
document.removeEventListener("dragenter", h.dragenter, false);
|
|
1398
|
+
document.removeEventListener("dragover", h.dragover, false);
|
|
1399
|
+
document.removeEventListener("dragleave", h.dragleave, false);
|
|
1400
|
+
document.removeEventListener("drop", h.drop, false);
|
|
1401
|
+
document.removeEventListener("mouseover", h.mouseover, true);
|
|
1402
|
+
document.removeEventListener("mouseout", h.mouseout, true);
|
|
1403
|
+
this.composerDragHandlers = null;
|
|
1404
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1405
|
+
document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
|
|
1406
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1407
|
+
});
|
|
1408
|
+
document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
|
|
1409
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1410
|
+
});
|
|
1280
1411
|
}
|
|
1281
1412
|
/** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
|
|
1282
1413
|
injectComposerHighlightStyles(highlightComponents, showZones) {
|
|
@@ -1303,19 +1434,64 @@ Available Console Commands:
|
|
|
1303
1434
|
" outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
|
|
1304
1435
|
" outline-offset: 4px !important;",
|
|
1305
1436
|
" min-height: 3rem !important;",
|
|
1437
|
+
" padding: 20px !important;",
|
|
1306
1438
|
" box-sizing: border-box !important;",
|
|
1307
1439
|
" cursor: pointer !important;",
|
|
1440
|
+
" position: relative !important;",
|
|
1308
1441
|
"}",
|
|
1309
1442
|
'[data-slot-id="main"], [data-amplifyup-slot="main"] {',
|
|
1310
1443
|
" min-height: 50vh !important;",
|
|
1311
1444
|
"}",
|
|
1445
|
+
'[data-slot-id="main"][data-slot-empty="true"]::before,',
|
|
1446
|
+
'[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
|
|
1447
|
+
' content: "Drop components here" !important;',
|
|
1448
|
+
" position: absolute !important;",
|
|
1449
|
+
" top: 50% !important; left: 50% !important;",
|
|
1450
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1451
|
+
" font-size: 14px !important; font-weight: 500 !important;",
|
|
1452
|
+
" color: rgba(34, 197, 94, 0.65) !important;",
|
|
1453
|
+
" pointer-events: none !important;",
|
|
1454
|
+
" white-space: nowrap !important;",
|
|
1455
|
+
"}",
|
|
1312
1456
|
"[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
|
|
1313
1457
|
" outline-color: rgba(34, 197, 94, 1) !important;",
|
|
1314
1458
|
" background: rgba(34, 197, 94, 0.06) !important;",
|
|
1315
1459
|
"}",
|
|
1316
1460
|
"[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
|
|
1317
1461
|
" outline: 2px solid rgba(34, 197, 94, 1) !important;",
|
|
1318
|
-
" background: rgba(34, 197, 94, 0.
|
|
1462
|
+
" background: rgba(34, 197, 94, 0.18) !important;",
|
|
1463
|
+
" position: relative !important;",
|
|
1464
|
+
"}",
|
|
1465
|
+
"[data-slot-id].amplifyup-drag-over-slot::after,",
|
|
1466
|
+
"[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
|
|
1467
|
+
' content: "\\2713 Drop here" !important;',
|
|
1468
|
+
" position: absolute !important;",
|
|
1469
|
+
" top: 50% !important; left: 50% !important;",
|
|
1470
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1471
|
+
" font-size: 14px !important; font-weight: 600 !important;",
|
|
1472
|
+
" color: rgb(22, 163, 74) !important;",
|
|
1473
|
+
" pointer-events: none !important;",
|
|
1474
|
+
" white-space: nowrap !important;",
|
|
1475
|
+
" z-index: 1 !important;",
|
|
1476
|
+
"}",
|
|
1477
|
+
"body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
|
|
1478
|
+
"body.amplifyup-drag-no-drop::before {",
|
|
1479
|
+
' content: "" !important;',
|
|
1480
|
+
" position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
|
|
1481
|
+
" background: rgba(239, 68, 68, 0.06) !important;",
|
|
1482
|
+
" pointer-events: none !important;",
|
|
1483
|
+
" z-index: 2147483646 !important;",
|
|
1484
|
+
"}",
|
|
1485
|
+
"body.amplifyup-drag-no-drop::after {",
|
|
1486
|
+
' content: "\\2717 Not a drop zone" !important;',
|
|
1487
|
+
" position: fixed !important; bottom: 12px !important; right: 12px !important;",
|
|
1488
|
+
" font-size: 12px !important; font-weight: 600 !important;",
|
|
1489
|
+
" color: rgb(185, 28, 28) !important;",
|
|
1490
|
+
" background: rgba(254, 226, 226, 0.95) !important;",
|
|
1491
|
+
" padding: 6px 10px !important; border-radius: 6px !important;",
|
|
1492
|
+
" pointer-events: none !important;",
|
|
1493
|
+
" z-index: 2147483647 !important;",
|
|
1494
|
+
" box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
|
|
1319
1495
|
"}"
|
|
1320
1496
|
);
|
|
1321
1497
|
}
|
|
@@ -1375,6 +1551,7 @@ Available Console Commands:
|
|
|
1375
1551
|
disableHighlighting() {
|
|
1376
1552
|
if (typeof document === "undefined") return;
|
|
1377
1553
|
this.highlightingEnabled = false;
|
|
1554
|
+
this.teardownComposerDragDrop();
|
|
1378
1555
|
if (this.mutationObserver) {
|
|
1379
1556
|
this.mutationObserver.disconnect();
|
|
1380
1557
|
this.mutationObserver = null;
|
|
@@ -1535,9 +1712,15 @@ Available Console Commands:
|
|
|
1535
1712
|
e.preventDefault();
|
|
1536
1713
|
e.stopPropagation();
|
|
1537
1714
|
htmlEl.classList.remove("amplifyup-drag-over-slot");
|
|
1715
|
+
if (!win.parent || win.parent === win) return;
|
|
1716
|
+
win.parent.postMessage({
|
|
1717
|
+
type: "DROP_ON_SLOT",
|
|
1718
|
+
slotName,
|
|
1719
|
+
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1720
|
+
}, "*");
|
|
1538
1721
|
try {
|
|
1539
1722
|
const data = JSON.parse(e.dataTransfer.getData("application/json"));
|
|
1540
|
-
if (data.type === "component"
|
|
1723
|
+
if (data.type === "component") {
|
|
1541
1724
|
win.parent.postMessage({
|
|
1542
1725
|
type: "COMPONENT_DROPPED",
|
|
1543
1726
|
componentId: data.componentId,
|
|
@@ -1545,7 +1728,6 @@ Available Console Commands:
|
|
|
1545
1728
|
slotName,
|
|
1546
1729
|
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1547
1730
|
}, "*");
|
|
1548
|
-
win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
|
|
1549
1731
|
}
|
|
1550
1732
|
} catch (_err) {
|
|
1551
1733
|
}
|