@amplifyup/sdk 0.1.10 → 0.1.12
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 +218 -3
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +218 -3
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +218 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +218 -3
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +219 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +219 -4
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/AmplifyRenderer.js
CHANGED
|
@@ -325,6 +325,7 @@ var AmplifyUpSDK = class {
|
|
|
325
325
|
this.componentRegistry = [];
|
|
326
326
|
this.messageListener = null;
|
|
327
327
|
this.mutationObserver = null;
|
|
328
|
+
this.composerDragHandlers = null;
|
|
328
329
|
this.isVisualEditorMode = false;
|
|
329
330
|
this.eventSelectionMode = false;
|
|
330
331
|
this.eventSelectionClickHandler = null;
|
|
@@ -1139,6 +1140,24 @@ Available Console Commands:
|
|
|
1139
1140
|
}
|
|
1140
1141
|
return;
|
|
1141
1142
|
}
|
|
1143
|
+
if (event.data?.type === "COMPOSER_DRAG_AT_POINT") {
|
|
1144
|
+
const { x, y } = event.data;
|
|
1145
|
+
if (typeof x === "number" && typeof y === "number") {
|
|
1146
|
+
this.handleComposerDragAtPoint(x, y);
|
|
1147
|
+
}
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
if (event.data?.type === "COMPOSER_DROP_AT_POINT") {
|
|
1151
|
+
const { x, y } = event.data;
|
|
1152
|
+
if (typeof x === "number" && typeof y === "number") {
|
|
1153
|
+
this.handleComposerDropAtPoint(x, y);
|
|
1154
|
+
}
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
if (event.data?.type === "COMPOSER_DRAG_END") {
|
|
1158
|
+
this.clearComposerDragHighlight();
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1142
1161
|
if (event.data?.type === "GET_ELEMENT_POSITION") {
|
|
1143
1162
|
const { componentId, slotName } = event.data;
|
|
1144
1163
|
const selector = slotName ? `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
|
|
@@ -1272,6 +1291,46 @@ Available Console Commands:
|
|
|
1272
1291
|
}
|
|
1273
1292
|
return el.tagName.toLowerCase();
|
|
1274
1293
|
}
|
|
1294
|
+
/** Clear drag-over highlight state (Composer overlay path or native drag end). */
|
|
1295
|
+
clearComposerDragHighlight() {
|
|
1296
|
+
if (typeof document === "undefined") return;
|
|
1297
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1298
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1299
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1300
|
+
});
|
|
1301
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Hit-test a slot at iframe-local coordinates (Composer overlay drag path).
|
|
1305
|
+
* Required for cross-origin drags: the browser blocks native drop inside the iframe.
|
|
1306
|
+
*/
|
|
1307
|
+
handleComposerDragAtPoint(x, y) {
|
|
1308
|
+
if (typeof document === "undefined") return;
|
|
1309
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1310
|
+
this.clearComposerDragHighlight();
|
|
1311
|
+
const el = document.elementFromPoint(x, y)?.closest?.(slotSelector);
|
|
1312
|
+
if (el) {
|
|
1313
|
+
el.classList.add("amplifyup-drag-over-slot");
|
|
1314
|
+
} else {
|
|
1315
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
handleComposerDropAtPoint(x, y) {
|
|
1319
|
+
if (typeof document === "undefined") return;
|
|
1320
|
+
const win = window;
|
|
1321
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1322
|
+
this.clearComposerDragHighlight();
|
|
1323
|
+
const htmlEl = document.elementFromPoint(x, y)?.closest?.(slotSelector);
|
|
1324
|
+
if (!htmlEl || !win.parent || win.parent === win) return;
|
|
1325
|
+
const slotName = htmlEl.getAttribute("data-amplifyup-slot") || htmlEl.getAttribute("data-slot-id");
|
|
1326
|
+
if (!slotName) return;
|
|
1327
|
+
const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
|
|
1328
|
+
win.parent.postMessage({
|
|
1329
|
+
type: "DROP_ON_SLOT",
|
|
1330
|
+
slotName,
|
|
1331
|
+
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1332
|
+
}, "*");
|
|
1333
|
+
}
|
|
1275
1334
|
/**
|
|
1276
1335
|
* Enable component highlighting
|
|
1277
1336
|
*/
|
|
@@ -1288,6 +1347,111 @@ Available Console Commands:
|
|
|
1288
1347
|
this.applyComponentHighlights(highlightComponents, showZones);
|
|
1289
1348
|
this.setupMutationObserver();
|
|
1290
1349
|
}
|
|
1350
|
+
if (showZones) {
|
|
1351
|
+
this.setupComposerDragDrop();
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
/** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
|
|
1355
|
+
setupComposerDragDrop() {
|
|
1356
|
+
if (typeof document === "undefined") return;
|
|
1357
|
+
this.teardownComposerDragDrop();
|
|
1358
|
+
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1359
|
+
const clearDragOverState = () => {
|
|
1360
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1361
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1362
|
+
});
|
|
1363
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1364
|
+
};
|
|
1365
|
+
const dragenter = (e) => {
|
|
1366
|
+
e.preventDefault();
|
|
1367
|
+
if (e.dataTransfer?.types?.length) {
|
|
1368
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1369
|
+
}
|
|
1370
|
+
};
|
|
1371
|
+
const dragover = (e) => {
|
|
1372
|
+
e.preventDefault();
|
|
1373
|
+
const target = e.target;
|
|
1374
|
+
const slot = target?.closest?.(slotSelector);
|
|
1375
|
+
if (e.dataTransfer) {
|
|
1376
|
+
e.dataTransfer.dropEffect = slot ? "copy" : "none";
|
|
1377
|
+
}
|
|
1378
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
|
|
1379
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1380
|
+
});
|
|
1381
|
+
if (slot) {
|
|
1382
|
+
slot.classList.add("amplifyup-drag-over-slot");
|
|
1383
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1384
|
+
} else {
|
|
1385
|
+
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1386
|
+
}
|
|
1387
|
+
};
|
|
1388
|
+
const dragleave = (e) => {
|
|
1389
|
+
const related = e.relatedTarget;
|
|
1390
|
+
if (!related || !document.body.contains(related)) {
|
|
1391
|
+
clearDragOverState();
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
const drop = (e) => {
|
|
1395
|
+
e.preventDefault();
|
|
1396
|
+
const target = e.target;
|
|
1397
|
+
const slot = target?.closest?.(slotSelector);
|
|
1398
|
+
clearDragOverState();
|
|
1399
|
+
if (!slot || !this.isVisualEditorMode) return;
|
|
1400
|
+
const slotName = slot.getAttribute("data-amplifyup-slot") || slot.getAttribute("data-slot-id");
|
|
1401
|
+
const isEmpty = slot.getAttribute("data-slot-empty") === "true";
|
|
1402
|
+
const win = window;
|
|
1403
|
+
if (slotName && win.parent && win.parent !== win) {
|
|
1404
|
+
win.parent.postMessage({
|
|
1405
|
+
type: "DROP_ON_SLOT",
|
|
1406
|
+
slotName,
|
|
1407
|
+
slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
|
|
1408
|
+
}, "*");
|
|
1409
|
+
}
|
|
1410
|
+
};
|
|
1411
|
+
const mouseover = (e) => {
|
|
1412
|
+
if (!this.showZonesEnabled) return;
|
|
1413
|
+
const target = e.target;
|
|
1414
|
+
const slot = target?.closest?.(slotSelector);
|
|
1415
|
+
if (!slot) return;
|
|
1416
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1417
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1418
|
+
});
|
|
1419
|
+
slot.classList.add("amplifyup-slot-hover");
|
|
1420
|
+
};
|
|
1421
|
+
const mouseout = (e) => {
|
|
1422
|
+
if (!this.showZonesEnabled) return;
|
|
1423
|
+
const related = e.relatedTarget;
|
|
1424
|
+
if (!related?.closest?.(slotSelector)) {
|
|
1425
|
+
document.querySelectorAll(`${slotSelector}.amplifyup-slot-hover`).forEach((el) => {
|
|
1426
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
};
|
|
1430
|
+
document.addEventListener("dragenter", dragenter, false);
|
|
1431
|
+
document.addEventListener("dragover", dragover, false);
|
|
1432
|
+
document.addEventListener("dragleave", dragleave, false);
|
|
1433
|
+
document.addEventListener("drop", drop, false);
|
|
1434
|
+
document.addEventListener("mouseover", mouseover, true);
|
|
1435
|
+
document.addEventListener("mouseout", mouseout, true);
|
|
1436
|
+
this.composerDragHandlers = { dragenter, dragover, dragleave, drop, mouseover, mouseout };
|
|
1437
|
+
}
|
|
1438
|
+
teardownComposerDragDrop() {
|
|
1439
|
+
if (!this.composerDragHandlers || typeof document === "undefined") return;
|
|
1440
|
+
const h = this.composerDragHandlers;
|
|
1441
|
+
document.removeEventListener("dragenter", h.dragenter, false);
|
|
1442
|
+
document.removeEventListener("dragover", h.dragover, false);
|
|
1443
|
+
document.removeEventListener("dragleave", h.dragleave, false);
|
|
1444
|
+
document.removeEventListener("drop", h.drop, false);
|
|
1445
|
+
document.removeEventListener("mouseover", h.mouseover, true);
|
|
1446
|
+
document.removeEventListener("mouseout", h.mouseout, true);
|
|
1447
|
+
this.composerDragHandlers = null;
|
|
1448
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1449
|
+
document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
|
|
1450
|
+
el.classList.remove("amplifyup-drag-over-slot");
|
|
1451
|
+
});
|
|
1452
|
+
document.querySelectorAll("[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover").forEach((el) => {
|
|
1453
|
+
el.classList.remove("amplifyup-slot-hover");
|
|
1454
|
+
});
|
|
1291
1455
|
}
|
|
1292
1456
|
/** Visual outlines for Composer (direct iframe path — no preview-frame proxy). */
|
|
1293
1457
|
injectComposerHighlightStyles(highlightComponents, showZones) {
|
|
@@ -1314,19 +1478,64 @@ Available Console Commands:
|
|
|
1314
1478
|
" outline: 2px dotted rgba(34, 197, 94, 0.75) !important;",
|
|
1315
1479
|
" outline-offset: 4px !important;",
|
|
1316
1480
|
" min-height: 3rem !important;",
|
|
1481
|
+
" padding: 20px !important;",
|
|
1317
1482
|
" box-sizing: border-box !important;",
|
|
1318
1483
|
" cursor: pointer !important;",
|
|
1484
|
+
" position: relative !important;",
|
|
1319
1485
|
"}",
|
|
1320
1486
|
'[data-slot-id="main"], [data-amplifyup-slot="main"] {',
|
|
1321
1487
|
" min-height: 50vh !important;",
|
|
1322
1488
|
"}",
|
|
1489
|
+
'[data-slot-id="main"][data-slot-empty="true"]::before,',
|
|
1490
|
+
'[data-amplifyup-slot="main"][data-slot-empty="true"]::before {',
|
|
1491
|
+
' content: "Drop components here" !important;',
|
|
1492
|
+
" position: absolute !important;",
|
|
1493
|
+
" top: 50% !important; left: 50% !important;",
|
|
1494
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1495
|
+
" font-size: 14px !important; font-weight: 500 !important;",
|
|
1496
|
+
" color: rgba(34, 197, 94, 0.65) !important;",
|
|
1497
|
+
" pointer-events: none !important;",
|
|
1498
|
+
" white-space: nowrap !important;",
|
|
1499
|
+
"}",
|
|
1323
1500
|
"[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
|
|
1324
1501
|
" outline-color: rgba(34, 197, 94, 1) !important;",
|
|
1325
1502
|
" background: rgba(34, 197, 94, 0.06) !important;",
|
|
1326
1503
|
"}",
|
|
1327
1504
|
"[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
|
|
1328
1505
|
" outline: 2px solid rgba(34, 197, 94, 1) !important;",
|
|
1329
|
-
" background: rgba(34, 197, 94, 0.
|
|
1506
|
+
" background: rgba(34, 197, 94, 0.18) !important;",
|
|
1507
|
+
" position: relative !important;",
|
|
1508
|
+
"}",
|
|
1509
|
+
"[data-slot-id].amplifyup-drag-over-slot::after,",
|
|
1510
|
+
"[data-amplifyup-slot].amplifyup-drag-over-slot::after {",
|
|
1511
|
+
' content: "\\2713 Drop here" !important;',
|
|
1512
|
+
" position: absolute !important;",
|
|
1513
|
+
" top: 50% !important; left: 50% !important;",
|
|
1514
|
+
" transform: translate(-50%, -50%) !important;",
|
|
1515
|
+
" font-size: 14px !important; font-weight: 600 !important;",
|
|
1516
|
+
" color: rgb(22, 163, 74) !important;",
|
|
1517
|
+
" pointer-events: none !important;",
|
|
1518
|
+
" white-space: nowrap !important;",
|
|
1519
|
+
" z-index: 1 !important;",
|
|
1520
|
+
"}",
|
|
1521
|
+
"body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
|
|
1522
|
+
"body.amplifyup-drag-no-drop::before {",
|
|
1523
|
+
' content: "" !important;',
|
|
1524
|
+
" position: fixed !important; top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;",
|
|
1525
|
+
" background: rgba(239, 68, 68, 0.06) !important;",
|
|
1526
|
+
" pointer-events: none !important;",
|
|
1527
|
+
" z-index: 2147483646 !important;",
|
|
1528
|
+
"}",
|
|
1529
|
+
"body.amplifyup-drag-no-drop::after {",
|
|
1530
|
+
' content: "\\2717 Not a drop zone" !important;',
|
|
1531
|
+
" position: fixed !important; bottom: 12px !important; right: 12px !important;",
|
|
1532
|
+
" font-size: 12px !important; font-weight: 600 !important;",
|
|
1533
|
+
" color: rgb(185, 28, 28) !important;",
|
|
1534
|
+
" background: rgba(254, 226, 226, 0.95) !important;",
|
|
1535
|
+
" padding: 6px 10px !important; border-radius: 6px !important;",
|
|
1536
|
+
" pointer-events: none !important;",
|
|
1537
|
+
" z-index: 2147483647 !important;",
|
|
1538
|
+
" box-shadow: 0 1px 3px rgba(0,0,0,0.1) !important;",
|
|
1330
1539
|
"}"
|
|
1331
1540
|
);
|
|
1332
1541
|
}
|
|
@@ -1386,6 +1595,7 @@ Available Console Commands:
|
|
|
1386
1595
|
disableHighlighting() {
|
|
1387
1596
|
if (typeof document === "undefined") return;
|
|
1388
1597
|
this.highlightingEnabled = false;
|
|
1598
|
+
this.teardownComposerDragDrop();
|
|
1389
1599
|
if (this.mutationObserver) {
|
|
1390
1600
|
this.mutationObserver.disconnect();
|
|
1391
1601
|
this.mutationObserver = null;
|
|
@@ -1546,9 +1756,15 @@ Available Console Commands:
|
|
|
1546
1756
|
e.preventDefault();
|
|
1547
1757
|
e.stopPropagation();
|
|
1548
1758
|
htmlEl.classList.remove("amplifyup-drag-over-slot");
|
|
1759
|
+
if (!win.parent || win.parent === win) return;
|
|
1760
|
+
win.parent.postMessage({
|
|
1761
|
+
type: "DROP_ON_SLOT",
|
|
1762
|
+
slotName,
|
|
1763
|
+
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1764
|
+
}, "*");
|
|
1549
1765
|
try {
|
|
1550
1766
|
const data = JSON.parse(e.dataTransfer.getData("application/json"));
|
|
1551
|
-
if (data.type === "component"
|
|
1767
|
+
if (data.type === "component") {
|
|
1552
1768
|
win.parent.postMessage({
|
|
1553
1769
|
type: "COMPONENT_DROPPED",
|
|
1554
1770
|
componentId: data.componentId,
|
|
@@ -1556,7 +1772,6 @@ Available Console Commands:
|
|
|
1556
1772
|
slotName,
|
|
1557
1773
|
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1558
1774
|
}, "*");
|
|
1559
|
-
win.parent.postMessage({ type: "DROP_ON_SLOT", slotName }, "*");
|
|
1560
1775
|
}
|
|
1561
1776
|
} catch (_err) {
|
|
1562
1777
|
}
|