@websline/cms-view-utils 0.25.0 → 1.0.0-alpha.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/dist/editScroll.global.js +1 -0
- package/dist/previewBridge.global.js +1 -0
- package/package.json +15 -9
- package/src/components/AddBlockPlaceholder.svelte +49 -0
- package/src/components/BlockWrapper.svelte +51 -0
- package/src/components/EditableBlock.svelte +284 -0
- package/src/components/Picture.svelte +87 -0
- package/src/components/skeleton/Grid.svelte +34 -0
- package/src/components/skeleton/Image.svelte +26 -0
- package/src/components/skeleton/ImageText.svelte +50 -0
- package/src/components/skeleton/Text.svelte +38 -0
- package/src/utils/blockValidation.js +9 -0
- package/src/utils/cmsActions.js +12 -0
- package/src/utils/editScroll.js +55 -0
- package/src/utils/editorToken.js +24 -0
- package/src/utils/errors.js +10 -0
- package/src/utils/fetchPage.js +51 -0
- package/src/utils/headers.js +9 -0
- package/src/utils/notify.js +27 -0
- package/src/utils/previewBridge.js +71 -0
- package/src/utils/urlResolver.js +13 -0
- package/src/components/Block.astro +0 -26
- package/src/components/PageRenderer.astro +0 -39
- package/src/data/index.js +0 -1
- package/src/data/pageData.js +0 -44
- package/src/index.js +0 -4
- package/src/styles/drag-drop-blocks.css +0 -64
- package/src/utils/dragDropUtils.js +0 -67
- package/src/utils/iframeDragHandler.js +0 -222
- package/src/utils/index.js +0 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
if (typeof window === "undefined") return;
|
|
3
|
+
|
|
4
|
+
const DEBOUNCE_MS = 150;
|
|
5
|
+
const RESTORE_DELAY = 60;
|
|
6
|
+
|
|
7
|
+
const script =
|
|
8
|
+
document.currentScript ||
|
|
9
|
+
[...document.querySelectorAll("script[data-slug]")].pop();
|
|
10
|
+
|
|
11
|
+
const slug = script?.dataset?.slug;
|
|
12
|
+
|
|
13
|
+
if (!slug) {
|
|
14
|
+
console.warn("[editScroll] Missing data-slug");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const storageKey = `preview-scroll:${slug}`;
|
|
19
|
+
|
|
20
|
+
let timeout = null;
|
|
21
|
+
let lastY = 0;
|
|
22
|
+
|
|
23
|
+
const saveScroll = () => {
|
|
24
|
+
const y = window.scrollY;
|
|
25
|
+
if (y === lastY) return;
|
|
26
|
+
|
|
27
|
+
lastY = y;
|
|
28
|
+
sessionStorage.setItem(storageKey, String(y));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const onScroll = () => {
|
|
32
|
+
clearTimeout(timeout);
|
|
33
|
+
timeout = setTimeout(saveScroll, DEBOUNCE_MS);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const restoreScroll = () => {
|
|
37
|
+
const raw = sessionStorage.getItem(storageKey);
|
|
38
|
+
if (!raw) return;
|
|
39
|
+
|
|
40
|
+
const y = Number(raw);
|
|
41
|
+
if (Number.isNaN(y)) return;
|
|
42
|
+
|
|
43
|
+
requestAnimationFrame(() => {
|
|
44
|
+
window.scrollTo(0, y);
|
|
45
|
+
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
window.scrollTo(0, y);
|
|
48
|
+
}, RESTORE_DELAY);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
53
|
+
window.addEventListener("beforeunload", saveScroll);
|
|
54
|
+
window.addEventListener("load", restoreScroll);
|
|
55
|
+
})();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import jwt from "jsonwebtoken";
|
|
2
|
+
import { HttpError } from "./errors.js";
|
|
3
|
+
|
|
4
|
+
const resolveDraftUuidFromToken = (editorToken) => {
|
|
5
|
+
if (!editorToken) return undefined;
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
const payload = jwt.verify(editorToken, import.meta.env.CMS_EDITOR_JWT_SECRET);
|
|
9
|
+
|
|
10
|
+
if (payload.type !== "editor") {
|
|
11
|
+
throw new HttpError(401, "Invalid token type");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!payload.draftUuid) {
|
|
15
|
+
throw new HttpError(401, "Draft UUID missing in token");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return payload.draftUuid;
|
|
19
|
+
} catch {
|
|
20
|
+
throw new HttpError(401, "Invalid or expired editor token");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { resolveDraftUuidFromToken };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { resolveDraftUuidFromToken } from "./editorToken.js";
|
|
2
|
+
import { buildCmsPageUrl } from "./urlResolver.js";
|
|
3
|
+
import { buildCmsHeaders } from "./headers.js";
|
|
4
|
+
import { HttpError } from "./errors.js";
|
|
5
|
+
|
|
6
|
+
const fetchPage = async (context) => {
|
|
7
|
+
let { slug = "" } = context.params;
|
|
8
|
+
const request = context.request;
|
|
9
|
+
const url = new URL(request.url);
|
|
10
|
+
const isCMSPreviewRoute = url.pathname.startsWith("/preview_");
|
|
11
|
+
|
|
12
|
+
if (isCMSPreviewRoute) {
|
|
13
|
+
slug = slug.replace(/^preview_/, "");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const editorToken = url.searchParams.get("editorToken");
|
|
17
|
+
const draftUuid = resolveDraftUuidFromToken(editorToken);
|
|
18
|
+
const isCMSEditRoute = editorToken && draftUuid;
|
|
19
|
+
|
|
20
|
+
const cmsUrl = buildCmsPageUrl({ slug, draftUuid });
|
|
21
|
+
|
|
22
|
+
const response = await fetch(cmsUrl, {
|
|
23
|
+
method: "GET",
|
|
24
|
+
headers: buildCmsHeaders(request),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
if (response.status === 404) {
|
|
28
|
+
throw new HttpError(404, "Not Found");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
throw new HttpError(response.status, "CMS Error");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const data = await response.json();
|
|
36
|
+
|
|
37
|
+
context.locals.content = data?.content ?? [];
|
|
38
|
+
context.locals.navigation = data?.navigation ?? {};
|
|
39
|
+
context.locals.page = data?.page ?? {};
|
|
40
|
+
context.locals.seo = data?.seo ?? {};
|
|
41
|
+
context.locals._cmsRaw = data;
|
|
42
|
+
|
|
43
|
+
if (isCMSPreviewRoute) {
|
|
44
|
+
context.locals._preview = true;
|
|
45
|
+
}
|
|
46
|
+
if (isCMSEditRoute) {
|
|
47
|
+
context.locals._edit = true;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { fetchPage };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const buildCmsHeaders = (request) => ({
|
|
2
|
+
"accept-language": request.headers.get("accept-language") ?? "",
|
|
3
|
+
"cms-tenant": import.meta.env.CMS_TENANT,
|
|
4
|
+
"cms-token": import.meta.env.CMS_TOKEN,
|
|
5
|
+
"user-agent": request.headers.get("user-agent") ?? "",
|
|
6
|
+
referer: request.headers.get("referer") ?? "",
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
export { buildCmsHeaders };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const EVENTS = {
|
|
2
|
+
BLOCK_ADD: "BLOCK_ADD",
|
|
3
|
+
BLOCK_DELETE: "BLOCK_DELETE",
|
|
4
|
+
BLOCK_EDIT: "BLOCK_EDIT",
|
|
5
|
+
BLOCK_SHOW: "BLOCK_SHOW",
|
|
6
|
+
BLOCK_HIDE: "BLOCK_HIDE",
|
|
7
|
+
SLUG_CHANGED: "SLUG_CHANGED",
|
|
8
|
+
SLUG_ON_LOAD: "SLUG_ON_LOAD",
|
|
9
|
+
IFRAME_DOM_LOADED: "IFRAME_DOM_LOADED",
|
|
10
|
+
CURRENT_BLOCK_EDIT: "CURRENT_BLOCK_EDIT",
|
|
11
|
+
SCROLL_TO_BLOCK: "SCROLL_TO_BLOCK",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const notifyCMS = (type, payload = {}) => {
|
|
15
|
+
if (!type) return;
|
|
16
|
+
if (window.parent === window) return;
|
|
17
|
+
|
|
18
|
+
window.parent.postMessage(
|
|
19
|
+
{
|
|
20
|
+
type,
|
|
21
|
+
payload,
|
|
22
|
+
},
|
|
23
|
+
"*",
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { EVENTS, notifyCMS };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { EVENTS, notifyCMS } from "./notify.js";
|
|
2
|
+
|
|
3
|
+
(function () {
|
|
4
|
+
if (window.parent === window) return;
|
|
5
|
+
if (window.__PREVIEW_BRIDGE_INITIALIZED__) return;
|
|
6
|
+
|
|
7
|
+
window.__PREVIEW_BRIDGE_INITIALIZED__ = true;
|
|
8
|
+
|
|
9
|
+
const isModifiedClick = (event) => event.metaKey || event.ctrlKey || event.shiftKey;
|
|
10
|
+
|
|
11
|
+
const handleClick = (event) => {
|
|
12
|
+
const link = event.target.closest("a[href]");
|
|
13
|
+
|
|
14
|
+
if (!link) return;
|
|
15
|
+
if (link.target === "_blank") return;
|
|
16
|
+
if (isModifiedClick(event)) return;
|
|
17
|
+
|
|
18
|
+
const url = new URL(link.href, window.location.origin);
|
|
19
|
+
if (url.origin !== window.location.origin) return;
|
|
20
|
+
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
event.stopPropagation();
|
|
23
|
+
|
|
24
|
+
notifyCMS(EVENTS.SLUG_CHANGED, {
|
|
25
|
+
slug: url.pathname,
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
document.addEventListener("click", handleClick, true);
|
|
30
|
+
|
|
31
|
+
notifyCMS(EVENTS.SLUG_ON_LOAD, {
|
|
32
|
+
slug: window.location.pathname,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
window.addEventListener("load", () => {
|
|
36
|
+
notifyCMS(EVENTS.IFRAME_DOM_LOADED);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const scrollToId = (id) => {
|
|
40
|
+
const selector = `[data-cms-block-id="${id}"]`;
|
|
41
|
+
|
|
42
|
+
let tries = 0;
|
|
43
|
+
const max = 10;
|
|
44
|
+
|
|
45
|
+
const interval = setInterval(() => {
|
|
46
|
+
const el = document.querySelector(selector);
|
|
47
|
+
|
|
48
|
+
if (el) {
|
|
49
|
+
el.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
50
|
+
clearInterval(interval);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (++tries >= max) {
|
|
54
|
+
clearInterval(interval);
|
|
55
|
+
}
|
|
56
|
+
}, 100);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
window.addEventListener("message", (event) => {
|
|
60
|
+
const { type, payload } = event.data || {};
|
|
61
|
+
|
|
62
|
+
if (!type) return;
|
|
63
|
+
|
|
64
|
+
if (type === EVENTS.SCROLL_TO_BLOCK) {
|
|
65
|
+
const { draftBlockUuid } = payload || {};
|
|
66
|
+
if (!draftBlockUuid) return;
|
|
67
|
+
|
|
68
|
+
scrollToId(draftBlockUuid);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
})();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const buildCmsPageUrl = ({ slug, draftUuid }) => {
|
|
2
|
+
const base = import.meta.env.CMS_URL;
|
|
3
|
+
|
|
4
|
+
if (draftUuid) {
|
|
5
|
+
return `${base}/api/public/pages/preview/${draftUuid}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const normalizedSlug = slug.startsWith("/") ? slug : `/${slug}`;
|
|
9
|
+
|
|
10
|
+
return `${base}/api/public/pages${normalizedSlug}`;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { buildCmsPageUrl };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
const editToken = Astro.url.searchParams.get("edit_token") || null;
|
|
3
|
-
const isPreviewMode = editToken !== null && editToken !== "";
|
|
4
|
-
|
|
5
|
-
const { class: classes, style } = Astro.props;
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
{
|
|
9
|
-
isPreviewMode ? (
|
|
10
|
-
<div class={classes} data-edit-block {style}>
|
|
11
|
-
<div data-edit-block-menu>
|
|
12
|
-
<div data-edit-block-item data-edit-block-item-edit>
|
|
13
|
-
Bearbeiten...
|
|
14
|
-
</div>
|
|
15
|
-
<div data-edit-block-item data-edit-block-item-delete>
|
|
16
|
-
Löschen...
|
|
17
|
-
</div>
|
|
18
|
-
</div>
|
|
19
|
-
<slot />
|
|
20
|
-
</div>
|
|
21
|
-
) : (
|
|
22
|
-
<div class={classes} {style}>
|
|
23
|
-
<slot />
|
|
24
|
-
</div>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import { fetchPageData } from "../data/pageData";
|
|
3
|
-
|
|
4
|
-
const { locale, slug } = Astro.params;
|
|
5
|
-
const editToken = Astro.url.searchParams.get("edit_token") || null;
|
|
6
|
-
const isPreviewMode = editToken !== null && editToken !== "";
|
|
7
|
-
|
|
8
|
-
await fetchPageData({ editToken, locals: Astro.locals, locale, slug });
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
<slot />
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
isPreviewMode && (
|
|
15
|
-
<>
|
|
16
|
-
<link
|
|
17
|
-
href="https://fonts.googleapis.com/css2?family=Ancizar+Sans:ital,wght@0,100..1000;1,100..1000&display=swap"
|
|
18
|
-
rel="stylesheet"
|
|
19
|
-
/>
|
|
20
|
-
<link
|
|
21
|
-
rel="stylesheet"
|
|
22
|
-
href="https://unpkg.com/@websline/cms-view-utils@latest/src/styles/drag-drop-blocks.css"
|
|
23
|
-
/>
|
|
24
|
-
</>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
{isPreviewMode && <script type="module">
|
|
28
|
-
import IframeDragHandler from "https://unpkg.com/@websline/cms-view-utils@latest/src/utils/iframeDragHandler.js";
|
|
29
|
-
import {
|
|
30
|
-
disableLinks,
|
|
31
|
-
enableEditBlocks,
|
|
32
|
-
insertDropZones,
|
|
33
|
-
} from "https://unpkg.com/@websline/cms-view-utils@latest/src/utils/dragDropUtils.js";
|
|
34
|
-
|
|
35
|
-
new IframeDragHandler();
|
|
36
|
-
insertDropZones();
|
|
37
|
-
disableLinks();
|
|
38
|
-
enableEditBlocks();
|
|
39
|
-
</script>}
|
package/src/data/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./pageData";
|
package/src/data/pageData.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const fetchPageData = async ({ editToken, locals, locale, slug }) => {
|
|
2
|
-
const API_BASE = import.meta.env.PUBLIC_API_URL?.replace(/\/+$/, ""); // Remove trailing slashes
|
|
3
|
-
if (!API_BASE) throw new Error("PUBLIC_API_URL ist nicht gesetzt.");
|
|
4
|
-
|
|
5
|
-
const key = `__pageData__${locale}__${slug}`;
|
|
6
|
-
|
|
7
|
-
if (!locals[key]) {
|
|
8
|
-
let url = `${API_BASE}/${locale}/pages/${slug}`;
|
|
9
|
-
|
|
10
|
-
if (editToken) {
|
|
11
|
-
url += `?edit_token=${editToken}`;
|
|
12
|
-
}
|
|
13
|
-
const res = await fetch(url);
|
|
14
|
-
|
|
15
|
-
if (!res.ok) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
`Fehler beim Abrufen der Seite: ${res.status} ${res.statusText}`
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
locals[key] = await res.json();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
locals.__currentPageKey = key;
|
|
25
|
-
return locals[key];
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const getPageData = (locals) => {
|
|
29
|
-
const key = locals?.__currentPageKey;
|
|
30
|
-
|
|
31
|
-
if (!key) {
|
|
32
|
-
throw new Error("locals fehlt");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (!key || !locals[key]) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
"getPageData() wurde aufgerufen, bevor fetchPageData() ausgeführt wurde."
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return locals[key];
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export { fetchPageData, getPageData };
|
package/src/index.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
[data-drop-zone] {
|
|
2
|
-
height: 0px;
|
|
3
|
-
margin-left: auto;
|
|
4
|
-
margin-right: auto;
|
|
5
|
-
max-width: min(1440px, calc(100% - 48px));
|
|
6
|
-
transition: all 0.2s ease-in-out;
|
|
7
|
-
width: 100%;
|
|
8
|
-
}
|
|
9
|
-
[data-drop-zone].highlight {
|
|
10
|
-
border: 1.5px dashed var(--cms-drop-zone-border, #1168af);
|
|
11
|
-
height: 60px;
|
|
12
|
-
margin-top: 24px;
|
|
13
|
-
margin-bottom: 24px;
|
|
14
|
-
}
|
|
15
|
-
[data-drop-zone].highlight:hover {
|
|
16
|
-
background-color: var(--cms-drop-zone-background, rgba(17, 104, 175, 0.5));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
[data-edit-block] {
|
|
20
|
-
min-height: 40px;
|
|
21
|
-
position: relative;
|
|
22
|
-
user-select: none;
|
|
23
|
-
}
|
|
24
|
-
[data-edit-block-hover] {
|
|
25
|
-
&:after {
|
|
26
|
-
background: var(--cms-edit-block-background, #5aaff48c);
|
|
27
|
-
border-radius: 8px;
|
|
28
|
-
bottom: 0;
|
|
29
|
-
content: "";
|
|
30
|
-
display: block;
|
|
31
|
-
left: 0;
|
|
32
|
-
pointer-events: none;
|
|
33
|
-
position: absolute;
|
|
34
|
-
right: 0;
|
|
35
|
-
top: 0;
|
|
36
|
-
z-index: 1;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
[data-edit-block-hover] > [data-edit-block-menu] {
|
|
40
|
-
display: flex;
|
|
41
|
-
}
|
|
42
|
-
[data-edit-block-menu] {
|
|
43
|
-
background: var(--cms-edit-block-menu-bg, #1168af);
|
|
44
|
-
border-radius: 4px;
|
|
45
|
-
display: none;
|
|
46
|
-
left: 0;
|
|
47
|
-
overflow: hidden;
|
|
48
|
-
position: absolute;
|
|
49
|
-
top: -5px;
|
|
50
|
-
transform: translate(0, -100%);
|
|
51
|
-
}
|
|
52
|
-
[data-edit-block-item] {
|
|
53
|
-
color: var(--cms-edit-block-menu-color, #fff);
|
|
54
|
-
cursor: pointer;
|
|
55
|
-
font-family: "Ancizar Sans", sans-serif;
|
|
56
|
-
font-size: 14px;
|
|
57
|
-
font-weight: 400;
|
|
58
|
-
padding: 8px;
|
|
59
|
-
|
|
60
|
-
&:hover {
|
|
61
|
-
background: var(--cms-edit-block-menu-bg-hover, #0d5d9e);
|
|
62
|
-
color: var(--cms-edit-block-menu-color-hover, #fff);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
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) => {
|
|
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
|
-
const disableLinks = () => {
|
|
24
|
-
const hrefs = document.querySelectorAll("a");
|
|
25
|
-
|
|
26
|
-
hrefs.forEach((a) => {
|
|
27
|
-
a.addEventListener("click", (e) => {
|
|
28
|
-
alert("Vorschau-Modus: Links sind deaktiviert.");
|
|
29
|
-
e.preventDefault();
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const enableEditBlocks = () => {
|
|
35
|
-
const editBlocks = document.querySelectorAll("[data-edit-block]");
|
|
36
|
-
let activeBlock = null;
|
|
37
|
-
let timeoutId;
|
|
38
|
-
|
|
39
|
-
editBlocks.forEach((el) => {
|
|
40
|
-
el.addEventListener("mouseover", () => {
|
|
41
|
-
if (document.body.classList.contains("cms-editor-is-dragging")) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
clearTimeout(timeoutId);
|
|
46
|
-
|
|
47
|
-
if (activeBlock && activeBlock !== el) {
|
|
48
|
-
activeBlock.removeAttribute("data-edit-block-hover");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
activeBlock = el;
|
|
52
|
-
el.setAttribute("data-edit-block-hover", "");
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
el.addEventListener("mouseout", () => {
|
|
56
|
-
timeoutId = setTimeout(() => {
|
|
57
|
-
el.removeAttribute("data-edit-block-hover");
|
|
58
|
-
|
|
59
|
-
if (activeBlock === el) {
|
|
60
|
-
activeBlock = null;
|
|
61
|
-
}
|
|
62
|
-
}, 150);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export { disableLinks, enableEditBlocks, insertDropZones };
|