@amplifyup/sdk 0.1.12 → 0.1.13
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 +3 -1
- package/dist/AmplifyRenderer.d.ts +3 -1
- package/dist/AmplifyRenderer.js +291 -131
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +291 -131
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +247 -123
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +247 -123
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +8 -2
- package/dist/react.d.ts +8 -2
- package/dist/react.js +313 -155
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +313 -155
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -340,6 +340,15 @@ var AmplifyUpSDK = class {
|
|
|
340
340
|
this.messageListener = null;
|
|
341
341
|
this.mutationObserver = null;
|
|
342
342
|
this.composerDragHandlers = null;
|
|
343
|
+
/** Last slot highlighted during Composer drag — avoid clear/re-add flicker. */
|
|
344
|
+
this.lastComposerDragSlot = null;
|
|
345
|
+
/** Consecutive miss frames before clearing highlight (anti-jitter). */
|
|
346
|
+
this.composerDragMissFrames = 0;
|
|
347
|
+
/**
|
|
348
|
+
* Parent overlay is driving drag via postMessage. Native iframe dragleave must
|
|
349
|
+
* not clear highlight — overlay takeover fires a spurious document dragleave.
|
|
350
|
+
*/
|
|
351
|
+
this.composerOverlayDragActive = false;
|
|
343
352
|
this.isVisualEditorMode = false;
|
|
344
353
|
this.eventSelectionMode = false;
|
|
345
354
|
this.eventSelectionClickHandler = null;
|
|
@@ -870,6 +879,12 @@ Available Console Commands:
|
|
|
870
879
|
}
|
|
871
880
|
throw new Error(`Failed to fetch page: ${response.statusText}`);
|
|
872
881
|
}
|
|
882
|
+
const contentType = response.headers.get("content-type") || "";
|
|
883
|
+
if (!contentType.includes("application/json")) {
|
|
884
|
+
throw new Error(
|
|
885
|
+
`Layout provider returned non-JSON (${contentType || "unknown"}). Check Composer preview routing.`
|
|
886
|
+
);
|
|
887
|
+
}
|
|
873
888
|
const data = await response.json();
|
|
874
889
|
const pageConfig = data.page;
|
|
875
890
|
if (pageConfig?.eventTracking) {
|
|
@@ -1154,6 +1169,13 @@ Available Console Commands:
|
|
|
1154
1169
|
}
|
|
1155
1170
|
return;
|
|
1156
1171
|
}
|
|
1172
|
+
if (event.data?.type === "COMPOSER_DRAG_START") {
|
|
1173
|
+
this.composerOverlayDragActive = true;
|
|
1174
|
+
if (typeof document !== "undefined") {
|
|
1175
|
+
document.body.classList.add("amplifyup-composer-dragging");
|
|
1176
|
+
}
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1157
1179
|
if (event.data?.type === "COMPOSER_DRAG_AT_POINT") {
|
|
1158
1180
|
const { x, y } = event.data;
|
|
1159
1181
|
if (typeof x === "number" && typeof y === "number") {
|
|
@@ -1169,36 +1191,72 @@ Available Console Commands:
|
|
|
1169
1191
|
return;
|
|
1170
1192
|
}
|
|
1171
1193
|
if (event.data?.type === "COMPOSER_DRAG_END") {
|
|
1194
|
+
this.composerOverlayDragActive = false;
|
|
1172
1195
|
this.clearComposerDragHighlight();
|
|
1173
1196
|
return;
|
|
1174
1197
|
}
|
|
1175
1198
|
if (event.data?.type === "GET_ELEMENT_POSITION") {
|
|
1176
|
-
const { componentId, slotName } = event.data;
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1199
|
+
const { componentId, slotName, nodeId, isPageSlot } = event.data;
|
|
1200
|
+
let element = null;
|
|
1201
|
+
if (isPageSlot || slotName === "main" && !nodeId && !componentId) {
|
|
1202
|
+
element = document.querySelector(
|
|
1203
|
+
'[data-slot-source="page"]'
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
if (!element && nodeId && slotName) {
|
|
1207
|
+
element = document.querySelector(
|
|
1208
|
+
`[data-parent-node-id="${nodeId}"][data-slot-id="${slotName}"], [data-parent-node-id="${nodeId}"][data-amplifyup-slot="${slotName}"]`
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
1211
|
+
if (!element && nodeId && !slotName) {
|
|
1212
|
+
element = document.querySelector(
|
|
1213
|
+
`[data-node-id="${nodeId}"]`
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
if (!element && slotName) {
|
|
1217
|
+
element = document.querySelector(
|
|
1218
|
+
`[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]`
|
|
1219
|
+
);
|
|
1220
|
+
}
|
|
1221
|
+
if (!element && componentId) {
|
|
1222
|
+
element = document.querySelector(
|
|
1223
|
+
`[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`
|
|
1224
|
+
);
|
|
1225
|
+
}
|
|
1226
|
+
console.log("[AmplifyUp SDK] Finding element position:", {
|
|
1227
|
+
componentId,
|
|
1228
|
+
slotName,
|
|
1229
|
+
nodeId,
|
|
1230
|
+
isPageSlot,
|
|
1231
|
+
found: !!element
|
|
1232
|
+
});
|
|
1180
1233
|
if (element) {
|
|
1181
1234
|
const rect = element.getBoundingClientRect();
|
|
1182
1235
|
const position = {
|
|
1183
1236
|
x: rect.left + rect.width / 2,
|
|
1184
|
-
// Center of element
|
|
1185
1237
|
y: rect.top - 50,
|
|
1186
|
-
// Position above element
|
|
1187
1238
|
width: rect.width,
|
|
1188
1239
|
height: rect.height
|
|
1189
1240
|
};
|
|
1190
|
-
|
|
1241
|
+
const bounds = {
|
|
1242
|
+
top: rect.top,
|
|
1243
|
+
left: rect.left,
|
|
1244
|
+
width: rect.width,
|
|
1245
|
+
height: rect.height
|
|
1246
|
+
};
|
|
1191
1247
|
if (window.parent && window.parent !== window) {
|
|
1192
1248
|
window.parent.postMessage({
|
|
1193
1249
|
type: "ELEMENT_POSITION",
|
|
1194
|
-
componentId,
|
|
1195
|
-
slotName,
|
|
1196
|
-
|
|
1250
|
+
componentId: componentId || null,
|
|
1251
|
+
slotName: slotName || null,
|
|
1252
|
+
nodeId: nodeId || null,
|
|
1253
|
+
isPageSlot: !!isPageSlot,
|
|
1254
|
+
position,
|
|
1255
|
+
bounds
|
|
1197
1256
|
}, "*");
|
|
1198
|
-
console.log("[AmplifyUp SDK] Sent ELEMENT_POSITION message");
|
|
1199
1257
|
}
|
|
1200
1258
|
} else {
|
|
1201
|
-
console.warn("[AmplifyUp SDK] Element not found for
|
|
1259
|
+
console.warn("[AmplifyUp SDK] Element not found for position request");
|
|
1202
1260
|
}
|
|
1203
1261
|
return;
|
|
1204
1262
|
}
|
|
@@ -1313,37 +1371,148 @@ Available Console Commands:
|
|
|
1313
1371
|
el.classList.remove("amplifyup-drag-over-slot");
|
|
1314
1372
|
});
|
|
1315
1373
|
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1374
|
+
document.body.classList.remove("amplifyup-composer-dragging");
|
|
1375
|
+
this.lastComposerDragSlot = null;
|
|
1376
|
+
this.composerDragMissFrames = 0;
|
|
1377
|
+
}
|
|
1378
|
+
/** Re-apply drag-over class only if missing (avoids classList churn / flicker). */
|
|
1379
|
+
ensureDragOverClass(slot) {
|
|
1380
|
+
if (!slot.classList.contains("amplifyup-drag-over-slot")) {
|
|
1381
|
+
slot.classList.add("amplifyup-drag-over-slot");
|
|
1382
|
+
}
|
|
1383
|
+
if (document.body.classList.contains("amplifyup-drag-no-drop")) {
|
|
1384
|
+
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1385
|
+
}
|
|
1316
1386
|
}
|
|
1317
1387
|
/**
|
|
1318
|
-
*
|
|
1319
|
-
*
|
|
1388
|
+
* Composer drag targets the innermost (most specific) slot under the cursor.
|
|
1389
|
+
* e.g. FullWidthGrid's main wins over a page-level main that wraps it.
|
|
1320
1390
|
*/
|
|
1321
|
-
|
|
1322
|
-
if (typeof document === "undefined") return;
|
|
1391
|
+
resolveSlotAtPoint(x, y) {
|
|
1392
|
+
if (typeof document === "undefined") return null;
|
|
1323
1393
|
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
el.
|
|
1328
|
-
|
|
1394
|
+
const containing = [];
|
|
1395
|
+
document.querySelectorAll(slotSelector).forEach((node) => {
|
|
1396
|
+
const el = node;
|
|
1397
|
+
const r = el.getBoundingClientRect();
|
|
1398
|
+
if (x >= r.left && x <= r.right && y >= r.top && y <= r.bottom) {
|
|
1399
|
+
containing.push(el);
|
|
1400
|
+
}
|
|
1401
|
+
});
|
|
1402
|
+
if (containing.length === 0) return null;
|
|
1403
|
+
const innermost = containing.filter(
|
|
1404
|
+
(el) => !containing.some((other) => other !== el && el.contains(other))
|
|
1405
|
+
);
|
|
1406
|
+
if (innermost.length === 1) return innermost[0];
|
|
1407
|
+
let best = innermost[0];
|
|
1408
|
+
let bestArea = Infinity;
|
|
1409
|
+
for (const el of innermost) {
|
|
1410
|
+
const r = el.getBoundingClientRect();
|
|
1411
|
+
const area = Math.max(1, r.width) * Math.max(1, r.height);
|
|
1412
|
+
if (area < bestArea) {
|
|
1413
|
+
bestArea = area;
|
|
1414
|
+
best = el;
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
return best;
|
|
1418
|
+
}
|
|
1419
|
+
/** Parent layout node that owns this slot (null for page-level code main). */
|
|
1420
|
+
parentComponentForSlot(slotEl) {
|
|
1421
|
+
let componentId = slotEl.getAttribute("data-parent-component-id");
|
|
1422
|
+
let nodeId = slotEl.getAttribute("data-parent-node-id");
|
|
1423
|
+
let el = slotEl.parentElement;
|
|
1424
|
+
while (el && (!nodeId || !componentId)) {
|
|
1425
|
+
if (!nodeId && el.hasAttribute("data-node-id")) {
|
|
1426
|
+
nodeId = el.getAttribute("data-node-id");
|
|
1427
|
+
}
|
|
1428
|
+
if (!componentId) {
|
|
1429
|
+
componentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
|
|
1430
|
+
}
|
|
1431
|
+
if (nodeId) break;
|
|
1432
|
+
el = el.parentElement;
|
|
1433
|
+
}
|
|
1434
|
+
return { componentId, nodeId };
|
|
1435
|
+
}
|
|
1436
|
+
pointInRect(x, y, el, pad = 8) {
|
|
1437
|
+
const r = el.getBoundingClientRect();
|
|
1438
|
+
return x >= r.left - pad && x <= r.right + pad && y >= r.top - pad && y <= r.bottom + pad;
|
|
1439
|
+
}
|
|
1440
|
+
setComposerDragHighlight(slot, x, y) {
|
|
1441
|
+
if (slot && slot === this.lastComposerDragSlot) {
|
|
1442
|
+
this.composerDragMissFrames = 0;
|
|
1443
|
+
this.ensureDragOverClass(slot);
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
if (slot && this.lastComposerDragSlot && this.lastComposerDragSlot.contains(slot) && slot !== this.lastComposerDragSlot) {
|
|
1447
|
+
this.composerDragMissFrames = 0;
|
|
1448
|
+
this.lastComposerDragSlot.classList.remove("amplifyup-drag-over-slot");
|
|
1449
|
+
this.lastComposerDragSlot = slot;
|
|
1450
|
+
this.ensureDragOverClass(slot);
|
|
1451
|
+
return;
|
|
1452
|
+
}
|
|
1453
|
+
if (this.lastComposerDragSlot && typeof x === "number" && typeof y === "number" && this.pointInRect(x, y, this.lastComposerDragSlot)) {
|
|
1454
|
+
if (!slot || slot.contains(this.lastComposerDragSlot) || slot === this.lastComposerDragSlot) {
|
|
1455
|
+
this.composerDragMissFrames = 0;
|
|
1456
|
+
this.ensureDragOverClass(this.lastComposerDragSlot);
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
if (slot) {
|
|
1461
|
+
this.composerDragMissFrames = 0;
|
|
1462
|
+
if (this.lastComposerDragSlot && this.lastComposerDragSlot !== slot) {
|
|
1463
|
+
this.lastComposerDragSlot.classList.remove("amplifyup-drag-over-slot");
|
|
1464
|
+
}
|
|
1465
|
+
this.lastComposerDragSlot = slot;
|
|
1466
|
+
this.ensureDragOverClass(slot);
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
this.composerDragMissFrames += 1;
|
|
1470
|
+
if (this.lastComposerDragSlot && this.composerDragMissFrames < 8) {
|
|
1471
|
+
this.ensureDragOverClass(this.lastComposerDragSlot);
|
|
1472
|
+
return;
|
|
1473
|
+
}
|
|
1474
|
+
if (this.lastComposerDragSlot) {
|
|
1475
|
+
this.lastComposerDragSlot.classList.remove("amplifyup-drag-over-slot");
|
|
1476
|
+
this.lastComposerDragSlot = null;
|
|
1477
|
+
}
|
|
1478
|
+
if (!document.body.classList.contains("amplifyup-drag-no-drop")) {
|
|
1329
1479
|
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1330
1480
|
}
|
|
1331
1481
|
}
|
|
1482
|
+
handleComposerDragAtPoint(x, y) {
|
|
1483
|
+
this.composerOverlayDragActive = true;
|
|
1484
|
+
if (!document.body.classList.contains("amplifyup-composer-dragging")) {
|
|
1485
|
+
document.body.classList.add("amplifyup-composer-dragging");
|
|
1486
|
+
}
|
|
1487
|
+
this.setComposerDragHighlight(this.resolveSlotAtPoint(x, y), x, y);
|
|
1488
|
+
}
|
|
1489
|
+
postDropOnSlot(slotEl) {
|
|
1490
|
+
const win = window;
|
|
1491
|
+
if (!win.parent || win.parent === win) return;
|
|
1492
|
+
const slotName = slotEl.getAttribute("data-amplifyup-slot") || slotEl.getAttribute("data-slot-id");
|
|
1493
|
+
if (!slotName) return;
|
|
1494
|
+
const { componentId, nodeId } = this.parentComponentForSlot(slotEl);
|
|
1495
|
+
const isEmpty = slotEl.getAttribute("data-slot-empty") === "true";
|
|
1496
|
+
win.parent.postMessage(
|
|
1497
|
+
{
|
|
1498
|
+
type: "DROP_ON_SLOT",
|
|
1499
|
+
slotName,
|
|
1500
|
+
slotElement: {
|
|
1501
|
+
path: slotEl.getAttribute("data-slot-path"),
|
|
1502
|
+
isEmpty,
|
|
1503
|
+
parentComponentId: componentId,
|
|
1504
|
+
parentNodeId: nodeId
|
|
1505
|
+
}
|
|
1506
|
+
},
|
|
1507
|
+
"*"
|
|
1508
|
+
);
|
|
1509
|
+
}
|
|
1332
1510
|
handleComposerDropAtPoint(x, y) {
|
|
1333
1511
|
if (typeof document === "undefined") return;
|
|
1334
|
-
const
|
|
1335
|
-
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1512
|
+
const htmlEl = this.resolveSlotAtPoint(x, y);
|
|
1336
1513
|
this.clearComposerDragHighlight();
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
const slotName = htmlEl.getAttribute("data-amplifyup-slot") || htmlEl.getAttribute("data-slot-id");
|
|
1340
|
-
if (!slotName) return;
|
|
1341
|
-
const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
|
|
1342
|
-
win.parent.postMessage({
|
|
1343
|
-
type: "DROP_ON_SLOT",
|
|
1344
|
-
slotName,
|
|
1345
|
-
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1346
|
-
}, "*");
|
|
1514
|
+
if (!htmlEl) return;
|
|
1515
|
+
this.postDropOnSlot(htmlEl);
|
|
1347
1516
|
}
|
|
1348
1517
|
/**
|
|
1349
1518
|
* Enable component highlighting
|
|
@@ -1371,35 +1540,25 @@ Available Console Commands:
|
|
|
1371
1540
|
this.teardownComposerDragDrop();
|
|
1372
1541
|
const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
|
|
1373
1542
|
const clearDragOverState = () => {
|
|
1374
|
-
|
|
1375
|
-
el.classList.remove("amplifyup-drag-over-slot");
|
|
1376
|
-
});
|
|
1377
|
-
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1543
|
+
this.clearComposerDragHighlight();
|
|
1378
1544
|
};
|
|
1379
1545
|
const dragenter = (e) => {
|
|
1380
1546
|
e.preventDefault();
|
|
1381
|
-
if (e.dataTransfer?.types?.length) {
|
|
1382
|
-
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1383
|
-
}
|
|
1384
1547
|
};
|
|
1385
1548
|
const dragover = (e) => {
|
|
1386
1549
|
e.preventDefault();
|
|
1387
|
-
|
|
1388
|
-
|
|
1550
|
+
if (this.composerOverlayDragActive) {
|
|
1551
|
+
if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";
|
|
1552
|
+
return;
|
|
1553
|
+
}
|
|
1554
|
+
const slot = this.resolveSlotAtPoint(e.clientX, e.clientY);
|
|
1389
1555
|
if (e.dataTransfer) {
|
|
1390
1556
|
e.dataTransfer.dropEffect = slot ? "copy" : "none";
|
|
1391
1557
|
}
|
|
1392
|
-
|
|
1393
|
-
el.classList.remove("amplifyup-drag-over-slot");
|
|
1394
|
-
});
|
|
1395
|
-
if (slot) {
|
|
1396
|
-
slot.classList.add("amplifyup-drag-over-slot");
|
|
1397
|
-
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1398
|
-
} else {
|
|
1399
|
-
document.body.classList.add("amplifyup-drag-no-drop");
|
|
1400
|
-
}
|
|
1558
|
+
this.setComposerDragHighlight(slot, e.clientX, e.clientY);
|
|
1401
1559
|
};
|
|
1402
1560
|
const dragleave = (e) => {
|
|
1561
|
+
if (this.composerOverlayDragActive) return;
|
|
1403
1562
|
const related = e.relatedTarget;
|
|
1404
1563
|
if (!related || !document.body.contains(related)) {
|
|
1405
1564
|
clearDragOverState();
|
|
@@ -1407,20 +1566,10 @@ Available Console Commands:
|
|
|
1407
1566
|
};
|
|
1408
1567
|
const drop = (e) => {
|
|
1409
1568
|
e.preventDefault();
|
|
1410
|
-
const
|
|
1411
|
-
const slot = target?.closest?.(slotSelector);
|
|
1569
|
+
const slot = this.resolveSlotAtPoint(e.clientX, e.clientY);
|
|
1412
1570
|
clearDragOverState();
|
|
1413
1571
|
if (!slot || !this.isVisualEditorMode) return;
|
|
1414
|
-
|
|
1415
|
-
const isEmpty = slot.getAttribute("data-slot-empty") === "true";
|
|
1416
|
-
const win = window;
|
|
1417
|
-
if (slotName && win.parent && win.parent !== win) {
|
|
1418
|
-
win.parent.postMessage({
|
|
1419
|
-
type: "DROP_ON_SLOT",
|
|
1420
|
-
slotName,
|
|
1421
|
-
slotElement: { path: slot.getAttribute("data-slot-path"), isEmpty }
|
|
1422
|
-
}, "*");
|
|
1423
|
-
}
|
|
1572
|
+
this.postDropOnSlot(slot);
|
|
1424
1573
|
};
|
|
1425
1574
|
const mouseover = (e) => {
|
|
1426
1575
|
if (!this.showZonesEnabled) return;
|
|
@@ -1459,7 +1608,11 @@ Available Console Commands:
|
|
|
1459
1608
|
document.removeEventListener("mouseover", h.mouseover, true);
|
|
1460
1609
|
document.removeEventListener("mouseout", h.mouseout, true);
|
|
1461
1610
|
this.composerDragHandlers = null;
|
|
1611
|
+
this.composerOverlayDragActive = false;
|
|
1612
|
+
this.lastComposerDragSlot = null;
|
|
1613
|
+
this.composerDragMissFrames = 0;
|
|
1462
1614
|
document.body.classList.remove("amplifyup-drag-no-drop");
|
|
1615
|
+
document.body.classList.remove("amplifyup-composer-dragging");
|
|
1463
1616
|
document.querySelectorAll("[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot").forEach((el) => {
|
|
1464
1617
|
el.classList.remove("amplifyup-drag-over-slot");
|
|
1465
1618
|
});
|
|
@@ -1500,21 +1653,32 @@ Available Console Commands:
|
|
|
1500
1653
|
'[data-slot-id="main"], [data-amplifyup-slot="main"] {',
|
|
1501
1654
|
" min-height: 50vh !important;",
|
|
1502
1655
|
"}",
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
"
|
|
1507
|
-
"
|
|
1508
|
-
"
|
|
1509
|
-
"
|
|
1510
|
-
"
|
|
1656
|
+
/* Single empty-state hint — Slot React label uses .amplifyup-slot-placeholder */
|
|
1657
|
+
".amplifyup-slot-placeholder {",
|
|
1658
|
+
" display: flex !important;",
|
|
1659
|
+
" align-items: center !important;",
|
|
1660
|
+
" justify-content: center !important;",
|
|
1661
|
+
" min-height: inherit !important;",
|
|
1662
|
+
" color: rgba(34, 197, 94, 0.75) !important;",
|
|
1663
|
+
" font-size: 14px !important;",
|
|
1664
|
+
" font-weight: 500 !important;",
|
|
1511
1665
|
" pointer-events: none !important;",
|
|
1512
|
-
"
|
|
1666
|
+
" text-align: center !important;",
|
|
1513
1667
|
"}",
|
|
1514
1668
|
"[data-slot-id].amplifyup-slot-hover, [data-amplifyup-slot].amplifyup-slot-hover {",
|
|
1515
1669
|
" outline-color: rgba(34, 197, 94, 1) !important;",
|
|
1516
1670
|
" background: rgba(34, 197, 94, 0.06) !important;",
|
|
1517
1671
|
"}",
|
|
1672
|
+
/* During any Composer drag, hide idle slot labels so they don't flash
|
|
1673
|
+
when the active drag-over class briefly changes */
|
|
1674
|
+
"body.amplifyup-composer-dragging .amplifyup-slot-placeholder {",
|
|
1675
|
+
" visibility: hidden !important;",
|
|
1676
|
+
" opacity: 0 !important;",
|
|
1677
|
+
"}",
|
|
1678
|
+
"body.amplifyup-composer-dragging [data-slot-id]::before,",
|
|
1679
|
+
"body.amplifyup-composer-dragging [data-amplifyup-slot]::before {",
|
|
1680
|
+
" content: none !important;",
|
|
1681
|
+
"}",
|
|
1518
1682
|
"[data-slot-id].amplifyup-drag-over-slot, [data-amplifyup-slot].amplifyup-drag-over-slot {",
|
|
1519
1683
|
" outline: 2px solid rgba(34, 197, 94, 1) !important;",
|
|
1520
1684
|
" background: rgba(34, 197, 94, 0.18) !important;",
|
|
@@ -1530,7 +1694,7 @@ Available Console Commands:
|
|
|
1530
1694
|
" color: rgb(22, 163, 74) !important;",
|
|
1531
1695
|
" pointer-events: none !important;",
|
|
1532
1696
|
" white-space: nowrap !important;",
|
|
1533
|
-
" z-index:
|
|
1697
|
+
" z-index: 2 !important;",
|
|
1534
1698
|
"}",
|
|
1535
1699
|
"body.amplifyup-drag-no-drop { cursor: no-drop !important; }",
|
|
1536
1700
|
"body.amplifyup-drag-no-drop::before {",
|
|
@@ -1657,18 +1821,23 @@ Available Console Commands:
|
|
|
1657
1821
|
sendSelectionMessage(element, hierarchy, isEmpty) {
|
|
1658
1822
|
if (!this.isVisualEditorMode) return;
|
|
1659
1823
|
const componentId = element.getAttribute("data-amplifyup-component") || element.getAttribute("data-component-id");
|
|
1660
|
-
const slotName = element.getAttribute("data-amplifyup-slot") || element.getAttribute("data-slot-id");
|
|
1824
|
+
const slotName = componentId ? null : element.getAttribute("data-amplifyup-slot") || element.getAttribute("data-slot-id");
|
|
1661
1825
|
const componentName = element.getAttribute("data-component-name");
|
|
1662
1826
|
const hierarchyInfo = hierarchy.map((el, index) => {
|
|
1663
1827
|
const elComponentId = el.getAttribute("data-amplifyup-component") || el.getAttribute("data-component-id");
|
|
1664
1828
|
const elSlotName = el.getAttribute("data-amplifyup-slot") || el.getAttribute("data-slot-id");
|
|
1665
1829
|
const elComponentName = el.getAttribute("data-component-name");
|
|
1830
|
+
const isSlot = !elComponentId && !!elSlotName;
|
|
1831
|
+
const isPageSlot = isSlot && el.getAttribute("data-slot-source") === "page";
|
|
1832
|
+
const nodeId = el.getAttribute("data-node-id") || (isSlot ? el.getAttribute("data-parent-node-id") : null);
|
|
1666
1833
|
return {
|
|
1667
1834
|
index,
|
|
1668
1835
|
componentId: elComponentId,
|
|
1669
|
-
componentName: elComponentName,
|
|
1670
|
-
slotName: elSlotName,
|
|
1671
|
-
isSlot
|
|
1836
|
+
componentName: isPageSlot ? "Page" : elComponentName,
|
|
1837
|
+
slotName: isSlot ? elSlotName : null,
|
|
1838
|
+
isSlot,
|
|
1839
|
+
isPageSlot,
|
|
1840
|
+
nodeId
|
|
1672
1841
|
};
|
|
1673
1842
|
});
|
|
1674
1843
|
const rect = element.getBoundingClientRect ? element.getBoundingClientRect() : null;
|
|
@@ -1705,7 +1874,6 @@ Available Console Commands:
|
|
|
1705
1874
|
return;
|
|
1706
1875
|
}
|
|
1707
1876
|
const doc = document;
|
|
1708
|
-
const win = window;
|
|
1709
1877
|
if (highlightComponents) {
|
|
1710
1878
|
const componentElements = doc.querySelectorAll("[data-amplifyup-component], [data-component-id]");
|
|
1711
1879
|
console.log("[AmplifyUp SDK] Found", componentElements.length, "components to highlight");
|
|
@@ -1766,52 +1934,8 @@ Available Console Commands:
|
|
|
1766
1934
|
e.stopPropagation();
|
|
1767
1935
|
this.sendSelectionMessage(htmlEl, hierarchy, isEmpty);
|
|
1768
1936
|
};
|
|
1769
|
-
const handleDrop = (e) => {
|
|
1770
|
-
e.preventDefault();
|
|
1771
|
-
e.stopPropagation();
|
|
1772
|
-
htmlEl.classList.remove("amplifyup-drag-over-slot");
|
|
1773
|
-
if (!win.parent || win.parent === win) return;
|
|
1774
|
-
win.parent.postMessage({
|
|
1775
|
-
type: "DROP_ON_SLOT",
|
|
1776
|
-
slotName,
|
|
1777
|
-
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1778
|
-
}, "*");
|
|
1779
|
-
try {
|
|
1780
|
-
const data = JSON.parse(e.dataTransfer.getData("application/json"));
|
|
1781
|
-
if (data.type === "component") {
|
|
1782
|
-
win.parent.postMessage({
|
|
1783
|
-
type: "COMPONENT_DROPPED",
|
|
1784
|
-
componentId: data.componentId,
|
|
1785
|
-
componentName: data.componentName,
|
|
1786
|
-
slotName,
|
|
1787
|
-
slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
|
|
1788
|
-
}, "*");
|
|
1789
|
-
}
|
|
1790
|
-
} catch (_err) {
|
|
1791
|
-
}
|
|
1792
|
-
};
|
|
1793
|
-
const handleDragOver = (e) => {
|
|
1794
|
-
e.preventDefault();
|
|
1795
|
-
e.stopPropagation();
|
|
1796
|
-
e.dataTransfer.dropEffect = "copy";
|
|
1797
|
-
htmlEl.classList.add("amplifyup-drag-over-slot");
|
|
1798
|
-
};
|
|
1799
|
-
const handleDragLeave = (e) => {
|
|
1800
|
-
const related = e.relatedTarget;
|
|
1801
|
-
if (!related || !htmlEl.contains(related)) {
|
|
1802
|
-
htmlEl.classList.remove("amplifyup-drag-over-slot");
|
|
1803
|
-
}
|
|
1804
|
-
};
|
|
1805
1937
|
htmlEl.addEventListener("click", handleClick);
|
|
1806
|
-
htmlEl.
|
|
1807
|
-
htmlEl.addEventListener("dragleave", handleDragLeave);
|
|
1808
|
-
htmlEl.addEventListener("drop", handleDrop);
|
|
1809
|
-
htmlEl._amplifyupSlotHandlers = {
|
|
1810
|
-
handleClick,
|
|
1811
|
-
handleDragOver,
|
|
1812
|
-
handleDragLeave,
|
|
1813
|
-
handleDrop
|
|
1814
|
-
};
|
|
1938
|
+
htmlEl._amplifyupSlotHandlers = { handleClick };
|
|
1815
1939
|
});
|
|
1816
1940
|
}
|
|
1817
1941
|
}
|