@amplifyup/sdk 0.1.11 → 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/index.mjs CHANGED
@@ -1154,6 +1154,24 @@ Available Console Commands:
1154
1154
  }
1155
1155
  return;
1156
1156
  }
1157
+ if (event.data?.type === "COMPOSER_DRAG_AT_POINT") {
1158
+ const { x, y } = event.data;
1159
+ if (typeof x === "number" && typeof y === "number") {
1160
+ this.handleComposerDragAtPoint(x, y);
1161
+ }
1162
+ return;
1163
+ }
1164
+ if (event.data?.type === "COMPOSER_DROP_AT_POINT") {
1165
+ const { x, y } = event.data;
1166
+ if (typeof x === "number" && typeof y === "number") {
1167
+ this.handleComposerDropAtPoint(x, y);
1168
+ }
1169
+ return;
1170
+ }
1171
+ if (event.data?.type === "COMPOSER_DRAG_END") {
1172
+ this.clearComposerDragHighlight();
1173
+ return;
1174
+ }
1157
1175
  if (event.data?.type === "GET_ELEMENT_POSITION") {
1158
1176
  const { componentId, slotName } = event.data;
1159
1177
  const selector = slotName ? `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
@@ -1287,6 +1305,46 @@ Available Console Commands:
1287
1305
  }
1288
1306
  return el.tagName.toLowerCase();
1289
1307
  }
1308
+ /** Clear drag-over highlight state (Composer overlay path or native drag end). */
1309
+ clearComposerDragHighlight() {
1310
+ if (typeof document === "undefined") return;
1311
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1312
+ document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
1313
+ el.classList.remove("amplifyup-drag-over-slot");
1314
+ });
1315
+ document.body.classList.remove("amplifyup-drag-no-drop");
1316
+ }
1317
+ /**
1318
+ * Hit-test a slot at iframe-local coordinates (Composer overlay drag path).
1319
+ * Required for cross-origin drags: the browser blocks native drop inside the iframe.
1320
+ */
1321
+ handleComposerDragAtPoint(x, y) {
1322
+ if (typeof document === "undefined") return;
1323
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1324
+ this.clearComposerDragHighlight();
1325
+ const el = document.elementFromPoint(x, y)?.closest?.(slotSelector);
1326
+ if (el) {
1327
+ el.classList.add("amplifyup-drag-over-slot");
1328
+ } else {
1329
+ document.body.classList.add("amplifyup-drag-no-drop");
1330
+ }
1331
+ }
1332
+ handleComposerDropAtPoint(x, y) {
1333
+ if (typeof document === "undefined") return;
1334
+ const win = window;
1335
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1336
+ this.clearComposerDragHighlight();
1337
+ const htmlEl = document.elementFromPoint(x, y)?.closest?.(slotSelector);
1338
+ if (!htmlEl || !win.parent || win.parent === win) return;
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
+ }, "*");
1347
+ }
1290
1348
  /**
1291
1349
  * Enable component highlighting
1292
1350
  */