@websline/cms-view-utils 0.22.0 → 0.23.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.22.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.js"
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "sideEffects": false,
12
12
  "peerDependencies": {
13
- "astro": "^5.8.1",
14
- "svelte": "^5.33.10"
13
+ "astro": "^5.9.0",
14
+ "svelte": "^5.33.14"
15
15
  },
16
16
  "scripts": {
17
17
  "bump:minor": "pnpm version minor --no-git-tag-version",
@@ -1,10 +1,11 @@
1
1
  ---
2
2
  import { fetchPageData } from "../data/pageData";
3
3
 
4
- const { lang, slug } = Astro.params;
5
- const isPreviewMode = Astro.url.searchParams.get("editable") === "true";
4
+ const { locale, slug } = Astro.params;
5
+ const editToken = Astro.url.searchParams.get("edit_token") || null;
6
+ const isPreviewMode = editToken !== null && editToken !== "";
6
7
 
7
- await fetchPageData(Astro.locals, lang, slug);
8
+ await fetchPageData({ editToken, locals: Astro.locals, locale, slug });
8
9
  ---
9
10
 
10
11
  <slot />
@@ -35,4 +36,4 @@ await fetchPageData(Astro.locals, lang, slug);
35
36
  insertDropZones();
36
37
  disableLinks();
37
38
  enableEditBlocks();
38
- </script>}
39
+ </script>}
@@ -1,11 +1,15 @@
1
- export async function fetchPageData(locals, lang, slug) {
1
+ const fetchPageData = async ({ editToken, locals, locale, slug }) => {
2
2
  const API_BASE = import.meta.env.PUBLIC_API_URL?.replace(/\/+$/, ""); // Remove trailing slashes
3
3
  if (!API_BASE) throw new Error("PUBLIC_API_URL ist nicht gesetzt.");
4
4
 
5
- const key = `__pageData__${lang}__${slug}`;
5
+ const key = `__pageData__${locale}__${slug}`;
6
6
 
7
7
  if (!locals[key]) {
8
- const url = `${API_BASE}/${lang}/pages/${slug}`;
8
+ let url = `${API_BASE}/${locale}/pages/${slug}`;
9
+
10
+ if (editToken) {
11
+ url += `?edit_token=${editToken}`;
12
+ }
9
13
  const res = await fetch(url);
10
14
 
11
15
  if (!res.ok) {
@@ -19,10 +23,14 @@ export async function fetchPageData(locals, lang, slug) {
19
23
 
20
24
  locals.__currentPageKey = key;
21
25
  return locals[key];
22
- }
26
+ };
23
27
 
24
- export function getPageData(locals) {
25
- const key = locals.__currentPageKey;
28
+ const getPageData = (locals) => {
29
+ const key = locals?.__currentPageKey;
30
+
31
+ if (!key) {
32
+ throw new Error("locals fehlt");
33
+ }
26
34
 
27
35
  if (!key || !locals[key]) {
28
36
  throw new Error(
@@ -31,4 +39,6 @@ export function getPageData(locals) {
31
39
  }
32
40
 
33
41
  return locals[key];
34
- }
42
+ };
43
+
44
+ export { fetchPageData, getPageData };