@websline/cms-view-utils 0.3.0 → 0.4.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@websline/cms-view-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.js"
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
"sideEffects": false,
|
|
12
12
|
"peerDependencies": {
|
|
13
13
|
"astro": "^5.8.0",
|
|
14
|
-
"svelte": "^5.33.
|
|
15
|
-
}
|
|
16
|
-
"scripts": {}
|
|
14
|
+
"svelte": "^5.33.2"
|
|
15
|
+
}
|
|
17
16
|
}
|
|
@@ -14,10 +14,18 @@ await fetchPageData(Astro.locals, lang, slug);
|
|
|
14
14
|
|
|
15
15
|
{
|
|
16
16
|
isPreviewMode && (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
<>
|
|
18
|
+
<link
|
|
19
|
+
rel="stylesheet"
|
|
20
|
+
href="https://unpkg.com/@websline/cms-view-utils@0.3.0/src/styles/dropZone.css"
|
|
21
|
+
/>
|
|
22
|
+
<script type="module">
|
|
23
|
+
import IframeDragHandler from
|
|
24
|
+
"https://unpkg.com/@websline/cms-view-utils@latest/src/utils/iframeDragHandler.js";
|
|
25
|
+
import {insertDropZones} from
|
|
26
|
+
"https://unpkg.com/@websline/cms-view-utils@latest/src/utils/dropZoneUtils.js";
|
|
27
|
+
new IframeDragHandler(); insertDropZones();
|
|
28
|
+
</script>
|
|
29
|
+
</>
|
|
22
30
|
)
|
|
23
31
|
}
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
const insertDropZones = (blockAreaSelector = "[data-block-area]") => {
|
|
2
2
|
const blockArea = document.querySelector(blockAreaSelector);
|
|
3
3
|
if (!blockArea) return;
|
|
4
4
|
|
|
5
5
|
const children = Array.from(blockArea.children);
|
|
6
|
+
let lastIndex = 0;
|
|
6
7
|
|
|
7
|
-
children.forEach((child) => {
|
|
8
|
+
children.forEach((child, index) => {
|
|
8
9
|
const dropZone = document.createElement("div");
|
|
9
10
|
dropZone.setAttribute("data-drop-zone", "");
|
|
11
|
+
dropZone.setAttribute("data-drop-zone-index", lastIndex.toString());
|
|
10
12
|
blockArea.insertBefore(dropZone, child);
|
|
13
|
+
|
|
14
|
+
lastIndex++;
|
|
11
15
|
});
|
|
12
16
|
|
|
13
17
|
const finalDropZone = document.createElement("div");
|
|
14
18
|
finalDropZone.setAttribute("data-drop-zone", "");
|
|
19
|
+
finalDropZone.setAttribute("data-drop-zone-index", lastIndex.toString());
|
|
15
20
|
blockArea.appendChild(finalDropZone);
|
|
16
|
-
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { insertDropZones };
|
|
@@ -42,6 +42,7 @@ class IframeDragHandler {
|
|
|
42
42
|
this.addMouseFollowerToDOM();
|
|
43
43
|
this.addMouseFollowerHandler();
|
|
44
44
|
this.highlightDropzone();
|
|
45
|
+
this.addDropListeners();
|
|
45
46
|
window.addEventListener("scroll", this.handleScroll, true);
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -50,6 +51,7 @@ class IframeDragHandler {
|
|
|
50
51
|
this.removeMouseFollowerFromDOM();
|
|
51
52
|
this.removeMouseFollowerHandler();
|
|
52
53
|
this.unhighlightDropzone();
|
|
54
|
+
this.removeDropListeners();
|
|
53
55
|
window.removeEventListener("scroll", this.handleScroll, true);
|
|
54
56
|
this.lastMouseEvent = null;
|
|
55
57
|
}
|
|
@@ -161,6 +163,33 @@ class IframeDragHandler {
|
|
|
161
163
|
window.parent.postMessage(message, "*");
|
|
162
164
|
}
|
|
163
165
|
|
|
166
|
+
addDropListeners() {
|
|
167
|
+
const dropzones = document.querySelectorAll("[data-drop-zone]");
|
|
168
|
+
|
|
169
|
+
dropzones.forEach((dropzone) => {
|
|
170
|
+
dropzone.addEventListener("mouseup", this.commitDrop);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
removeDropListeners() {
|
|
175
|
+
const dropzones = document.querySelectorAll("[data-drop-zone]");
|
|
176
|
+
|
|
177
|
+
dropzones.forEach((dropzone) => {
|
|
178
|
+
dropzone.removeEventListener("mouseup", this.commitDrop);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
commitDrop = (event) => {
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
const dropPosition = event.target.getAttribute("data-drop-zone-index");
|
|
185
|
+
|
|
186
|
+
this.sendParentMessage({
|
|
187
|
+
owner: "iframe",
|
|
188
|
+
position: dropPosition,
|
|
189
|
+
type: "commitDrop",
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
164
193
|
highlightDropzone() {
|
|
165
194
|
const dropzones = document.querySelectorAll("[data-drop-zone]");
|
|
166
195
|
|