@websline/cms-view-utils 0.2.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
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[data-drop-zone] {
|
|
2
|
+
transition: all 0.2s ease-in-out;
|
|
3
|
+
height: 0px;
|
|
4
|
+
}
|
|
5
|
+
[data-drop-zone].highlight {
|
|
6
|
+
border: 1.5px dashed var(--cms-drop-zone-border, #00f);
|
|
7
|
+
height: 60px;
|
|
8
|
+
margin: 24px 0;
|
|
9
|
+
}
|
|
10
|
+
[data-drop-zone].highlight:hover {
|
|
11
|
+
background-color: var(--cms-drop-zone-background, rgba(0, 0, 255, 0.5));
|
|
12
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const insertDropZones = (blockAreaSelector = "[data-block-area]") => {
|
|
2
|
+
const blockArea = document.querySelector(blockAreaSelector);
|
|
3
|
+
if (!blockArea) return;
|
|
4
|
+
|
|
5
|
+
const children = Array.from(blockArea.children);
|
|
6
|
+
let lastIndex = 0;
|
|
7
|
+
|
|
8
|
+
children.forEach((child, index) => {
|
|
9
|
+
const dropZone = document.createElement("div");
|
|
10
|
+
dropZone.setAttribute("data-drop-zone", "");
|
|
11
|
+
dropZone.setAttribute("data-drop-zone-index", lastIndex.toString());
|
|
12
|
+
blockArea.insertBefore(dropZone, child);
|
|
13
|
+
|
|
14
|
+
lastIndex++;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const finalDropZone = document.createElement("div");
|
|
18
|
+
finalDropZone.setAttribute("data-drop-zone", "");
|
|
19
|
+
finalDropZone.setAttribute("data-drop-zone-index", lastIndex.toString());
|
|
20
|
+
blockArea.appendChild(finalDropZone);
|
|
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,8 +163,35 @@ 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
|
-
const dropzones = document.querySelectorAll("
|
|
194
|
+
const dropzones = document.querySelectorAll("[data-drop-zone]");
|
|
166
195
|
|
|
167
196
|
dropzones.forEach((dropzone) => {
|
|
168
197
|
dropzone.classList.add("highlight");
|
|
@@ -170,7 +199,7 @@ class IframeDragHandler {
|
|
|
170
199
|
}
|
|
171
200
|
|
|
172
201
|
unhighlightDropzone() {
|
|
173
|
-
const dropzones = document.querySelectorAll("
|
|
202
|
+
const dropzones = document.querySelectorAll("[data-drop-zone]");
|
|
174
203
|
|
|
175
204
|
dropzones.forEach((dropzone) => {
|
|
176
205
|
dropzone.classList.remove("highlight");
|
package/src/utils/index.js
CHANGED