@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.
@@ -1138,6 +1138,24 @@ Available Console Commands:
1138
1138
  }
1139
1139
  return;
1140
1140
  }
1141
+ if (event.data?.type === "COMPOSER_DRAG_AT_POINT") {
1142
+ const { x, y } = event.data;
1143
+ if (typeof x === "number" && typeof y === "number") {
1144
+ this.handleComposerDragAtPoint(x, y);
1145
+ }
1146
+ return;
1147
+ }
1148
+ if (event.data?.type === "COMPOSER_DROP_AT_POINT") {
1149
+ const { x, y } = event.data;
1150
+ if (typeof x === "number" && typeof y === "number") {
1151
+ this.handleComposerDropAtPoint(x, y);
1152
+ }
1153
+ return;
1154
+ }
1155
+ if (event.data?.type === "COMPOSER_DRAG_END") {
1156
+ this.clearComposerDragHighlight();
1157
+ return;
1158
+ }
1141
1159
  if (event.data?.type === "GET_ELEMENT_POSITION") {
1142
1160
  const { componentId, slotName } = event.data;
1143
1161
  const selector = slotName ? `[data-amplifyup-slot="${slotName}"], [data-slot-id="${slotName}"]` : `[data-amplifyup-component="${componentId}"], [data-component-id="${componentId}"]`;
@@ -1271,6 +1289,46 @@ Available Console Commands:
1271
1289
  }
1272
1290
  return el.tagName.toLowerCase();
1273
1291
  }
1292
+ /** Clear drag-over highlight state (Composer overlay path or native drag end). */
1293
+ clearComposerDragHighlight() {
1294
+ if (typeof document === "undefined") return;
1295
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1296
+ document.querySelectorAll(`${slotSelector}.amplifyup-drag-over-slot`).forEach((el) => {
1297
+ el.classList.remove("amplifyup-drag-over-slot");
1298
+ });
1299
+ document.body.classList.remove("amplifyup-drag-no-drop");
1300
+ }
1301
+ /**
1302
+ * Hit-test a slot at iframe-local coordinates (Composer overlay drag path).
1303
+ * Required for cross-origin drags: the browser blocks native drop inside the iframe.
1304
+ */
1305
+ handleComposerDragAtPoint(x, y) {
1306
+ if (typeof document === "undefined") return;
1307
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1308
+ this.clearComposerDragHighlight();
1309
+ const el = document.elementFromPoint(x, y)?.closest?.(slotSelector);
1310
+ if (el) {
1311
+ el.classList.add("amplifyup-drag-over-slot");
1312
+ } else {
1313
+ document.body.classList.add("amplifyup-drag-no-drop");
1314
+ }
1315
+ }
1316
+ handleComposerDropAtPoint(x, y) {
1317
+ if (typeof document === "undefined") return;
1318
+ const win = window;
1319
+ const slotSelector = "[data-slot-id], [data-amplifyup-slot]";
1320
+ this.clearComposerDragHighlight();
1321
+ const htmlEl = document.elementFromPoint(x, y)?.closest?.(slotSelector);
1322
+ if (!htmlEl || !win.parent || win.parent === win) return;
1323
+ const slotName = htmlEl.getAttribute("data-amplifyup-slot") || htmlEl.getAttribute("data-slot-id");
1324
+ if (!slotName) return;
1325
+ const isEmpty = htmlEl.getAttribute("data-slot-empty") === "true";
1326
+ win.parent.postMessage({
1327
+ type: "DROP_ON_SLOT",
1328
+ slotName,
1329
+ slotElement: { path: htmlEl.getAttribute("data-slot-path"), isEmpty }
1330
+ }, "*");
1331
+ }
1274
1332
  /**
1275
1333
  * Enable component highlighting
1276
1334
  */