@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/AmplifyRenderer.mjs
CHANGED
|
@@ -323,6 +323,7 @@ var AmplifyUpSDK = class {
|
|
|
323
323
|
this.componentRegistry = [];
|
|
324
324
|
this.messageListener = null;
|
|
325
325
|
this.mutationObserver = null;
|
|
326
|
+
this.composerDragHandlers = null;
|
|
326
327
|
this.isVisualEditorMode = false;
|
|
327
328
|
this.eventSelectionMode = false;
|
|
328
329
|
this.eventSelectionClickHandler = null;
|
|
@@ -1055,6 +1056,39 @@ Available Console Commands:
|
|
|
1055
1056
|
this.attachEventListeners();
|
|
1056
1057
|
}
|
|
1057
1058
|
}
|
|
1059
|
+
/** Origins allowed to send Composer postMessage commands to the SDK. */
|
|
1060
|
+
isAllowedComposerOrigin(origin) {
|
|
1061
|
+
if (typeof window === "undefined") return false;
|
|
1062
|
+
if (origin === window.location.origin) return true;
|
|
1063
|
+
const staticAllowed = [
|
|
1064
|
+
"http://localhost:5001",
|
|
1065
|
+
"http://localhost:3001",
|
|
1066
|
+
"https://amplifyup.ai",
|
|
1067
|
+
"https://orchestrator.amplifyup.com"
|
|
1068
|
+
];
|
|
1069
|
+
if (staticAllowed.includes(origin)) return true;
|
|
1070
|
+
try {
|
|
1071
|
+
const host = new URL(origin).hostname;
|
|
1072
|
+
if (host === "amplifyup.ai" || host.endsWith(".amplifyup.ai")) return true;
|
|
1073
|
+
} catch {
|
|
1074
|
+
}
|
|
1075
|
+
const orchestratorFromQuery = (() => {
|
|
1076
|
+
try {
|
|
1077
|
+
const value = new URLSearchParams(window.location.search).get("orchestratorUrl");
|
|
1078
|
+
return value ? new URL(value).origin : null;
|
|
1079
|
+
} catch {
|
|
1080
|
+
return null;
|
|
1081
|
+
}
|
|
1082
|
+
})();
|
|
1083
|
+
if (orchestratorFromQuery && origin === orchestratorFromQuery) return true;
|
|
1084
|
+
if (this.orchestratorUrl) {
|
|
1085
|
+
try {
|
|
1086
|
+
if (new URL(this.orchestratorUrl).origin === origin) return true;
|
|
1087
|
+
} catch {
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
return false;
|
|
1091
|
+
}
|
|
1058
1092
|
/**
|
|
1059
1093
|
* Set up postMessage listener for highlighting commands from orchestrator
|
|
1060
1094
|
*/
|
|
@@ -1070,18 +1104,10 @@ Available Console Commands:
|
|
|
1070
1104
|
currentOrigin: window.location.origin,
|
|
1071
1105
|
data: event.data
|
|
1072
1106
|
});
|
|
1073
|
-
|
|
1074
|
-
"http://localhost:5001",
|
|
1075
|
-
"http://localhost:3001",
|
|
1076
|
-
"https://orchestrator.amplifyup.com"
|
|
1077
|
-
];
|
|
1078
|
-
const isSameOrigin = event.origin === window.location.origin;
|
|
1079
|
-
const isAllowedOrigin = allowedOrigins.some((origin) => event.origin.startsWith(origin));
|
|
1080
|
-
if (!isSameOrigin && !isAllowedOrigin) {
|
|
1107
|
+
if (!this.isAllowedComposerOrigin(event.origin)) {
|
|
1081
1108
|
console.warn("[AmplifyUp SDK] Rejected message from unauthorized origin:", {
|
|
1082
1109
|
eventOrigin: event.origin,
|
|
1083
|
-
currentOrigin: window.location.origin
|
|
1084
|
-
allowedOrigins
|
|
1110
|
+
currentOrigin: window.location.origin
|
|
1085
1111
|
});
|
|
1086
1112
|
return;
|
|
1087
1113
|
}
|
|
@@ -1261,6 +1287,111 @@ Available Console Commands:
|
|
|
1261
1287
|
this.applyComponentHighlights(highlightComponents, showZones);
|
|
1262
1288
|
this.setupMutationObserver();
|
|
1263
1289
|
}
|
|
1290
|
+
if (showZones) {
|
|
1291
|
+
this.setupComposerDragDrop();
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
/** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
|
|
1295
|
+
setupComposerDragDrop() {
|
|
1296
|
+
if (typeof document === "undefined") return;
|
|
1297
|
+
this.teardownComposerDragDrop();
|
|
1298
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1299
|
+
const clearDragOverState = () => {
|
|
1300
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1301
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1302
|
+
});
|
|
1303
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1304
|
+
};
|
|
1305
|
+
const dragenter = (e) => {
|
|
1306
|
+
e.preventDefault();
|
|
1307
|
+
if (e.dataTransfer?.types?.length) {
|
|
1308
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1309
|
+
}
|
|
1310
|
+
};
|
|
1311
|
+
const dragover = (e) => {
|
|
1312
|
+
e.preventDefault();
|
|
1313
|
+
const target = e.target;
|
|
1314
|
+
const slot = target?.closest?.(slotSelector);
|
|
1315
|
+
if (e.dataTransfer) {
|
|
1316
|
+
e.dataTransfer.dropEffect = slot ? "copy" : "none";
|
|
1317
|
+
}
|
|
1318
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1319
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1320
|
+
});
|
|
1321
|
+
if (slot) {
|
|
1322
|
+
slot.classList.add("amplifyup-drag-over-slot");
|
|
1323
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1324
|
+
} else {
|
|
1325
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
const dragleave = (e) => {
|
|
1329
|
+
const related = e.relatedTarget;
|
|
1330
|
+
if (!related || !document.body.contains(related)) {
|
|
1331
|
+
clearDragOverState();
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
const drop = (e) => {
|
|
1335
|
+
e.preventDefault();
|
|
1336
|
+
const target = e.target;
|
|
1337
|
+
const slot = target?.closest?.(slotSelector);
|
|
1338
|
+
clearDragOverState();
|
|
1339
|
+
if (!slot || !this.isVisualEditorMode) return;
|
|
1340
|
+
const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
|
|
1341
|
+
const isEmpty = slot.getAttribute("data-slot-empty") === "true";
|
|
1342
|
+
const win = window;
|
|
1343
|
+
if (slotName && win.parent && win.parent !== win) {
|
|
1344
|
+
win.parent.postMessage({
|
|
1345
|
+
type: "DROP_ON_SLOT",
|
|
1346
|
+
slotName,
|
|
1347
|
+
slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
|
|
1348
|
+
}, "*");
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
const mouseover = (e) => {
|
|
1352
|
+
if (!this.showZonesEnabled) return;
|
|
1353
|
+
const target = e.target;
|
|
1354
|
+
const slot = target?.closest?.(slotSelector);
|
|
1355
|
+
if (!slot) return;
|
|
1356
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1357
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1358
|
+
});
|
|
1359
|
+
slot.classList.add("amplifyup-slot-hover");
|
|
1360
|
+
};
|
|
1361
|
+
const mouseout = (e) => {
|
|
1362
|
+
if (!this.showZonesEnabled) return;
|
|
1363
|
+
const related = e.relatedTarget;
|
|
1364
|
+
if (!related?.closest?.(slotSelector)) {
|
|
1365
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1366
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
};
|
|
1370
|
+
document.addEventListener("dragenter", dragenter, false);
|
|
1371
|
+
document.addEventListener("dragover", dragover, false);
|
|
1372
|
+
document.addEventListener("dragleave", dragleave, false);
|
|
1373
|
+
document.addEventListener("drop", drop, false);
|
|
1374
|
+
document.addEventListener("mouseover", mouseover, true);
|
|
1375
|
+
document.addEventListener("mouseout", mouseout, true);
|
|
1376
|
+
this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
|
|
1377
|
+
}
|
|
1378
|
+
teardownComposerDragDrop() {
|
|
1379
|
+
if (!this.composerDragHandlers || typeof document === "undefined") return;
|
|
1380
|
+
const h = this.composerDragHandlers;
|
|
1381
|
+
document.removeEventListener("dragenter", h.dragenter, false);
|
|
1382
|
+
document.removeEventListener("dragover", h.dragover, false);
|
|
1383
|
+
document.removeEventListener("dragleave", h.dragleave, false);
|
|
1384
|
+
document.removeEventListener("drop", h.drop, false);
|
|
1385
|
+
document.removeEventListener("mouseover", h.mouseover, true);
|
|
1386
|
+
document.removeEventListener("mouseout", h.mouseout, true);
|
|
1387
|
+
this.composerDragHandlers = null;
|
|
1388
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1389
|
+
document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
|
|
1390
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1391
|
+
});
|
|
1392
|
+
document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
|
|
1393
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1394
|
+
});
|
|
1264
1395
|
}
|
|
1265
1396
|
/** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
|
|
1266
1397
|
injectComposerHighlightStyles(highlightComponents, showZones) {
|
|
@@ -1287,19 +1418,64 @@ Available Console Commands:
|
|
|
1287
1418
|
" outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
|
|
1288
1419
|
" outline-offset: 4px !important;",
|
|
1289
1420
|
" min-height: 3rem !important;",
|
|
1421
|
+
" padding: 20px !important;",
|
|
1290
1422
|
" box-sizing: border-box !important;",
|
|
1291
1423
|
" cursor: pointer !important;",
|
|
1424
|
+
" position: relative !important;",
|
|
1292
1425
|
"}",
|
|
1293
1426
|
'[data-slot-id="main"], [data-amplifyup-slot="main"] {',
|
|
1294
1427
|
" min-height: 50vh !important;",
|
|
1295
1428
|
"}",
|
|
1429
|
+
'[data-slot-id="main"][data-slot-empty="true"]::before,',
|
|
1430
|
+
'[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
|
|
1431
|
+
' content: "Drop components here" !important;',
|
|
1432
|
+
" position: absolute !important;",
|
|
1433
|
+
" top: 50% !important; left: 50% !important;",
|
|
1434
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1435
|
+
" font-size: 14px !important; font-weight: 500 !important;",
|
|
1436
|
+
" color: rgba(34, 197, 94, 0.65) !important;",
|
|
1437
|
+
" pointer-events: none !important;",
|
|
1438
|
+
" white-space: nowrap !important;",
|
|
1439
|
+
"}",
|
|
1296
1440
|
"[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
|
|
1297
1441
|
" outline-color: rgba(34, 197, 94, 1) !important;",
|
|
1298
1442
|
" background: rgba(34, 197, 94, 0.06) !important;",
|
|
1299
1443
|
"}",
|
|
1300
1444
|
"[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
|
|
1301
1445
|
" outline: 2px solid rgba(34, 197, 94, 1) !important;",
|
|
1302
|
-
" background: rgba(34, 197, 94, 0.
|
|
1446
|
+
" background: rgba(34, 197, 94, 0.18) !important;",
|
|
1447
|
+
" position: relative !important;",
|
|
1448
|
+
"}",
|
|
1449
|
+
"[data-slot-id].amplifyup-drag-over-slot::after,",
|
|
1450
|
+
"[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
|
|
1451
|
+
' content: "\\2713 Drop here" !important;',
|
|
1452
|
+
" position: absolute !important;",
|
|
1453
|
+
" top: 50% !important; left: 50% !important;",
|
|
1454
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1455
|
+
" font-size: 14px !important; font-weight: 600 !important;",
|
|
1456
|
+
" color: rgb(22, 163, 74) !important;",
|
|
1457
|
+
" pointer-events: none !important;",
|
|
1458
|
+
" white-space: nowrap !important;",
|
|
1459
|
+
" z-index: 1 !important;",
|
|
1460
|
+
"}",
|
|
1461
|
+
"body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
|
|
1462
|
+
"body.amplifyup-drag-no-drop::before {",
|
|
1463
|
+
' content: "" !important;',
|
|
1464
|
+
" position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
|
|
1465
|
+
" background: rgba(239, 68, 68, 0.06) !important;",
|
|
1466
|
+
" pointer-events: none !important;",
|
|
1467
|
+
" z-index: 2147483646 !important;",
|
|
1468
|
+
"}",
|
|
1469
|
+
"body.amplifyup-drag-no-drop::after {",
|
|
1470
|
+
' content: "\\2717 Not a drop zone" !important;',
|
|
1471
|
+
" position: fixed !important; bottom: 12px !important; right: 12px !important;",
|
|
1472
|
+
" font-size: 12px !important; font-weight: 600 !important;",
|
|
1473
|
+
" color: rgb(185, 28, 28) !important;",
|
|
1474
|
+
" background: rgba(254, 226, 226, 0.95) !important;",
|
|
1475
|
+
" padding: 6px 10px !important; border-radius: 6px !important;",
|
|
1476
|
+
" pointer-events: none !important;",
|
|
1477
|
+
" z-index: 2147483647 !important;",
|
|
1478
|
+
" box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
|
|
1303
1479
|
"}"
|
|
1304
1480
|
);
|
|
1305
1481
|
}
|
|
@@ -1359,6 +1535,7 @@ Available Console Commands:
|
|
|
1359
1535
|
disableHighlighting() {
|
|
1360
1536
|
if (typeof document === "undefined") return;
|
|
1361
1537
|
this.highlightingEnabled = false;
|
|
1538
|
+
this.teardownComposerDragDrop();
|
|
1362
1539
|
if (this.mutationObserver) {
|
|
1363
1540
|
this.mutationObserver.disconnect();
|
|
1364
1541
|
this.mutationObserver = null;
|
|
@@ -1519,9 +1696,15 @@ Available Console Commands:
|
|
|
1519
1696
|
e.preventDefault();
|
|
1520
1697
|
e.stopPropagation();
|
|
1521
1698
|
htmlEl.classList.remove("amplifyup-drag-over-slot");
|
|
1699
|
+
if (!win.parent || win.parent === win) return;
|
|
1700
|
+
win.parent.postMessage({
|
|
1701
|
+
type: "DROP_ON_SLOT",
|
|
1702
|
+
slotName,
|
|
1703
|
+
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1704
|
+
}, "*");
|
|
1522
1705
|
try {
|
|
1523
1706
|
const data = JSON.parse(e.dataTransfer.getData("application/json"));
|
|
1524
|
-
if (data.type === "component"
|
|
1707
|
+
if (data.type === "component") {
|
|
1525
1708
|
win.parent.postMessage({
|
|
1526
1709
|
type: "COMPONENT_DROPPED",
|
|
1527
1710
|
componentId: data.componentId,
|
|
@@ -1529,7 +1712,6 @@ Available Console Commands:
|
|
|
1529
1712
|
slotName,
|
|
1530
1713
|
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1531
1714
|
}, "*");
|
|
1532
|
-
win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
|
|
1533
1715
|
}
|
|
1534
1716
|
} catch (_err) {
|
|
1535
1717
|
}
|