@paulpaulstudio/strapi-render 0.4.1 → 0.5.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/index.cjs +55 -162
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -24
- package/dist/index.d.ts +39 -24
- package/dist/index.js +55 -164
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -53,30 +53,56 @@ interface MsgEditMediaPicked {
|
|
|
53
53
|
}
|
|
54
54
|
type StrapiEditMessage = MsgEditReady | MsgEditChange | MsgEditCommitRequest | MsgEditOpenMediaPicker | MsgEditReload | MsgEditCommitResult | MsgEditMediaPicked;
|
|
55
55
|
|
|
56
|
-
interface PendingChange {
|
|
57
|
-
path: string;
|
|
58
|
-
fieldType: StrapiFieldType;
|
|
59
|
-
value: unknown;
|
|
60
|
-
}
|
|
61
56
|
interface EditModeState {
|
|
62
57
|
enabled: boolean;
|
|
63
58
|
token: string | null;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
setChange: (path: string, fieldType: StrapiFieldType, value: unknown) => void;
|
|
69
|
-
clearChange: (path: string) => void;
|
|
70
|
-
commit: () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Wert/Path-Update an Parent (mit Content-Type-Kontext aus dem nächsten StrapiContent).
|
|
61
|
+
*/
|
|
62
|
+
publishChange: (path: string, fieldType: StrapiFieldType, value: unknown) => void;
|
|
71
63
|
openMediaPicker: (path: string, multiple: boolean, allowedTypes: string[] | undefined, currentValue: unknown) => void;
|
|
72
64
|
onMediaPicked: (path: string, listener: (value: unknown) => void) => () => void;
|
|
73
65
|
}
|
|
66
|
+
interface ContentScope {
|
|
67
|
+
uid: string;
|
|
68
|
+
kind: "singleType" | "collectionType";
|
|
69
|
+
documentId?: string;
|
|
70
|
+
}
|
|
74
71
|
declare function useStrapiEditMode(): EditModeState;
|
|
72
|
+
declare function useContentScope(): ContentScope | null;
|
|
75
73
|
interface ProviderProps {
|
|
76
74
|
children: React.ReactNode;
|
|
77
75
|
enabled?: boolean;
|
|
78
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Edit-Mode wird aktiv wenn:
|
|
79
|
+
* - `?__pp_edit=1` in der URL, ODER
|
|
80
|
+
* - sessionStorage `__pp_edit_session=1` gesetzt (für Navigation innerhalb der
|
|
81
|
+
* Customer-Site — beim ersten Aufruf via URL wird der Flag gesetzt, danach
|
|
82
|
+
* bleibt der Mode aktiv auch wenn die URL-Params bei Folge-Links fehlen).
|
|
83
|
+
*/
|
|
79
84
|
declare function StrapiEditModeProvider({ children, enabled: enabledOverride }: ProviderProps): react_jsx_runtime.JSX.Element;
|
|
85
|
+
interface StrapiContentProps {
|
|
86
|
+
/** Strapi-API-ID (z.B. "impressum", "home", "event"). */
|
|
87
|
+
uid: string;
|
|
88
|
+
/** "singleType" oder "collectionType". */
|
|
89
|
+
kind: "singleType" | "collectionType";
|
|
90
|
+
/** Bei collectionType erforderlich; bei singleType weglassen. */
|
|
91
|
+
documentId?: string;
|
|
92
|
+
children: React.ReactNode;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Marker, der allen inneren `<StrapiField>`s die Content-Type-Identität
|
|
96
|
+
* mitgibt. Ohne `<StrapiContent>` rund um Felder weiß der Parent-Editor
|
|
97
|
+
* nicht, wohin er die Änderung saven soll — Felder bleiben dann inert.
|
|
98
|
+
*
|
|
99
|
+
* Beispiel:
|
|
100
|
+
* <StrapiContent uid="impressum" kind="singleType">
|
|
101
|
+
* <StrapiText path="titel" value={data.titel} as="h1" />
|
|
102
|
+
* <StrapiMarkdownField path="content" value={data.content} render={...} />
|
|
103
|
+
* </StrapiContent>
|
|
104
|
+
*/
|
|
105
|
+
declare function StrapiContent({ uid, kind, documentId, children }: StrapiContentProps): react_jsx_runtime.JSX.Element;
|
|
80
106
|
|
|
81
107
|
interface StrapiFieldProps {
|
|
82
108
|
path: string;
|
|
@@ -85,17 +111,6 @@ interface StrapiFieldProps {
|
|
|
85
111
|
children: ReactNode;
|
|
86
112
|
className?: string;
|
|
87
113
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Universeller Wrapper. Im Normal-Mode: rendert children unverändert.
|
|
90
|
-
*
|
|
91
|
-
* Im Edit-Mode:
|
|
92
|
-
* - Für text/textarea/richText/email/number: macht das Top-Level-Child
|
|
93
|
-
* `contenteditable`, mit dünnem orange Hover-Outline, sammelt Wert-Änderungen
|
|
94
|
-
* in den globalen Edit-Context, der dann beim Klick auf "Speichern" alle
|
|
95
|
-
* Änderungen in einem Roundtrip ans Parent schickt.
|
|
96
|
-
* - Für andere Typen (media/select/checkbox): trägt ein Click-Handler bzw.
|
|
97
|
-
* ein Overlay (Implementierung in jeweiligen Sugar-Komponenten).
|
|
98
|
-
*/
|
|
99
114
|
declare function StrapiField({ path, type, value, children, className }: StrapiFieldProps): react_jsx_runtime.JSX.Element;
|
|
100
115
|
|
|
101
116
|
interface StrapiTextProps {
|
|
@@ -194,4 +209,4 @@ interface Props {
|
|
|
194
209
|
*/
|
|
195
210
|
declare function StrapiMarkdownField({ path, value, render, className, minRows }: Props): react_jsx_runtime.JSX.Element;
|
|
196
211
|
|
|
197
|
-
export { type MsgEditChange, type MsgEditCommitRequest, type MsgEditCommitResult, type MsgEditMediaPicked, type MsgEditOpenMediaPicker, type MsgEditReady, type MsgEditReload, StrapiBlocks, type StrapiEditMessage, StrapiEditModeProvider, StrapiField, type StrapiFieldType, StrapiImage, StrapiList, StrapiMarkdownField, type StrapiMediaValue, StrapiText, useStrapiEditMode };
|
|
212
|
+
export { type MsgEditChange, type MsgEditCommitRequest, type MsgEditCommitResult, type MsgEditMediaPicked, type MsgEditOpenMediaPicker, type MsgEditReady, type MsgEditReload, StrapiBlocks, StrapiContent, type StrapiEditMessage, StrapiEditModeProvider, StrapiField, type StrapiFieldType, StrapiImage, StrapiList, StrapiMarkdownField, type StrapiMediaValue, StrapiText, useContentScope, useStrapiEditMode };
|
package/dist/index.d.ts
CHANGED
|
@@ -53,30 +53,56 @@ interface MsgEditMediaPicked {
|
|
|
53
53
|
}
|
|
54
54
|
type StrapiEditMessage = MsgEditReady | MsgEditChange | MsgEditCommitRequest | MsgEditOpenMediaPicker | MsgEditReload | MsgEditCommitResult | MsgEditMediaPicked;
|
|
55
55
|
|
|
56
|
-
interface PendingChange {
|
|
57
|
-
path: string;
|
|
58
|
-
fieldType: StrapiFieldType;
|
|
59
|
-
value: unknown;
|
|
60
|
-
}
|
|
61
56
|
interface EditModeState {
|
|
62
57
|
enabled: boolean;
|
|
63
58
|
token: string | null;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
setChange: (path: string, fieldType: StrapiFieldType, value: unknown) => void;
|
|
69
|
-
clearChange: (path: string) => void;
|
|
70
|
-
commit: () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Wert/Path-Update an Parent (mit Content-Type-Kontext aus dem nächsten StrapiContent).
|
|
61
|
+
*/
|
|
62
|
+
publishChange: (path: string, fieldType: StrapiFieldType, value: unknown) => void;
|
|
71
63
|
openMediaPicker: (path: string, multiple: boolean, allowedTypes: string[] | undefined, currentValue: unknown) => void;
|
|
72
64
|
onMediaPicked: (path: string, listener: (value: unknown) => void) => () => void;
|
|
73
65
|
}
|
|
66
|
+
interface ContentScope {
|
|
67
|
+
uid: string;
|
|
68
|
+
kind: "singleType" | "collectionType";
|
|
69
|
+
documentId?: string;
|
|
70
|
+
}
|
|
74
71
|
declare function useStrapiEditMode(): EditModeState;
|
|
72
|
+
declare function useContentScope(): ContentScope | null;
|
|
75
73
|
interface ProviderProps {
|
|
76
74
|
children: React.ReactNode;
|
|
77
75
|
enabled?: boolean;
|
|
78
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Edit-Mode wird aktiv wenn:
|
|
79
|
+
* - `?__pp_edit=1` in der URL, ODER
|
|
80
|
+
* - sessionStorage `__pp_edit_session=1` gesetzt (für Navigation innerhalb der
|
|
81
|
+
* Customer-Site — beim ersten Aufruf via URL wird der Flag gesetzt, danach
|
|
82
|
+
* bleibt der Mode aktiv auch wenn die URL-Params bei Folge-Links fehlen).
|
|
83
|
+
*/
|
|
79
84
|
declare function StrapiEditModeProvider({ children, enabled: enabledOverride }: ProviderProps): react_jsx_runtime.JSX.Element;
|
|
85
|
+
interface StrapiContentProps {
|
|
86
|
+
/** Strapi-API-ID (z.B. "impressum", "home", "event"). */
|
|
87
|
+
uid: string;
|
|
88
|
+
/** "singleType" oder "collectionType". */
|
|
89
|
+
kind: "singleType" | "collectionType";
|
|
90
|
+
/** Bei collectionType erforderlich; bei singleType weglassen. */
|
|
91
|
+
documentId?: string;
|
|
92
|
+
children: React.ReactNode;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Marker, der allen inneren `<StrapiField>`s die Content-Type-Identität
|
|
96
|
+
* mitgibt. Ohne `<StrapiContent>` rund um Felder weiß der Parent-Editor
|
|
97
|
+
* nicht, wohin er die Änderung saven soll — Felder bleiben dann inert.
|
|
98
|
+
*
|
|
99
|
+
* Beispiel:
|
|
100
|
+
* <StrapiContent uid="impressum" kind="singleType">
|
|
101
|
+
* <StrapiText path="titel" value={data.titel} as="h1" />
|
|
102
|
+
* <StrapiMarkdownField path="content" value={data.content} render={...} />
|
|
103
|
+
* </StrapiContent>
|
|
104
|
+
*/
|
|
105
|
+
declare function StrapiContent({ uid, kind, documentId, children }: StrapiContentProps): react_jsx_runtime.JSX.Element;
|
|
80
106
|
|
|
81
107
|
interface StrapiFieldProps {
|
|
82
108
|
path: string;
|
|
@@ -85,17 +111,6 @@ interface StrapiFieldProps {
|
|
|
85
111
|
children: ReactNode;
|
|
86
112
|
className?: string;
|
|
87
113
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Universeller Wrapper. Im Normal-Mode: rendert children unverändert.
|
|
90
|
-
*
|
|
91
|
-
* Im Edit-Mode:
|
|
92
|
-
* - Für text/textarea/richText/email/number: macht das Top-Level-Child
|
|
93
|
-
* `contenteditable`, mit dünnem orange Hover-Outline, sammelt Wert-Änderungen
|
|
94
|
-
* in den globalen Edit-Context, der dann beim Klick auf "Speichern" alle
|
|
95
|
-
* Änderungen in einem Roundtrip ans Parent schickt.
|
|
96
|
-
* - Für andere Typen (media/select/checkbox): trägt ein Click-Handler bzw.
|
|
97
|
-
* ein Overlay (Implementierung in jeweiligen Sugar-Komponenten).
|
|
98
|
-
*/
|
|
99
114
|
declare function StrapiField({ path, type, value, children, className }: StrapiFieldProps): react_jsx_runtime.JSX.Element;
|
|
100
115
|
|
|
101
116
|
interface StrapiTextProps {
|
|
@@ -194,4 +209,4 @@ interface Props {
|
|
|
194
209
|
*/
|
|
195
210
|
declare function StrapiMarkdownField({ path, value, render, className, minRows }: Props): react_jsx_runtime.JSX.Element;
|
|
196
211
|
|
|
197
|
-
export { type MsgEditChange, type MsgEditCommitRequest, type MsgEditCommitResult, type MsgEditMediaPicked, type MsgEditOpenMediaPicker, type MsgEditReady, type MsgEditReload, StrapiBlocks, type StrapiEditMessage, StrapiEditModeProvider, StrapiField, type StrapiFieldType, StrapiImage, StrapiList, StrapiMarkdownField, type StrapiMediaValue, StrapiText, useStrapiEditMode };
|
|
212
|
+
export { type MsgEditChange, type MsgEditCommitRequest, type MsgEditCommitResult, type MsgEditMediaPicked, type MsgEditOpenMediaPicker, type MsgEditReady, type MsgEditReload, StrapiBlocks, StrapiContent, type StrapiEditMessage, StrapiEditModeProvider, StrapiField, type StrapiFieldType, StrapiImage, StrapiList, StrapiMarkdownField, type StrapiMediaValue, StrapiText, useContentScope, useStrapiEditMode };
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { createContext, useContext, useState, useRef, useEffect, useCallback, useMemo, Children, isValidElement, cloneElement, createElement, Fragment as Fragment$1 } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
|
+
var EDIT_SESSION_KEY = "__pp_edit_session";
|
|
5
6
|
var noop = () => {
|
|
6
7
|
};
|
|
7
8
|
var EditModeContext = createContext({
|
|
8
9
|
enabled: false,
|
|
9
10
|
token: null,
|
|
10
|
-
|
|
11
|
-
isDirty: false,
|
|
12
|
-
isCommitting: false,
|
|
13
|
-
lastCommitError: null,
|
|
14
|
-
setChange: noop,
|
|
15
|
-
clearChange: noop,
|
|
16
|
-
commit: noop,
|
|
11
|
+
publishChange: noop,
|
|
17
12
|
openMediaPicker: noop,
|
|
18
13
|
onMediaPicked: () => noop
|
|
19
14
|
});
|
|
15
|
+
var ContentScopeContext = createContext(null);
|
|
20
16
|
function useStrapiEditMode() {
|
|
21
17
|
return useContext(EditModeContext);
|
|
22
18
|
}
|
|
19
|
+
function useContentScope() {
|
|
20
|
+
return useContext(ContentScopeContext);
|
|
21
|
+
}
|
|
23
22
|
function StrapiEditModeProvider({ children, enabled: enabledOverride }) {
|
|
24
23
|
const [urlState, setUrlState] = useState({ enabled: false, token: null });
|
|
25
|
-
const [changes, setChanges] = useState(/* @__PURE__ */ new Map());
|
|
26
|
-
const [isCommitting, setIsCommitting] = useState(false);
|
|
27
|
-
const [lastCommitError, setLastCommitError] = useState(null);
|
|
28
24
|
const mediaPickListeners = useRef(/* @__PURE__ */ new Map());
|
|
29
25
|
useEffect(() => {
|
|
30
26
|
if (typeof window === "undefined") return;
|
|
@@ -34,9 +30,15 @@ function StrapiEditModeProvider({ children, enabled: enabledOverride }) {
|
|
|
34
30
|
}
|
|
35
31
|
try {
|
|
36
32
|
const params = new URLSearchParams(window.location.search);
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
33
|
+
const urlEdit = params.get("__pp_edit") === "1";
|
|
34
|
+
const sessionFlag = window.sessionStorage.getItem(EDIT_SESSION_KEY) === "1";
|
|
35
|
+
const enabled = urlEdit || sessionFlag;
|
|
36
|
+
if (urlEdit) {
|
|
37
|
+
window.sessionStorage.setItem(EDIT_SESSION_KEY, "1");
|
|
38
|
+
}
|
|
39
|
+
const token = params.get("__pp_token") ?? window.sessionStorage.getItem("__pp_edit_token");
|
|
40
|
+
if (token) window.sessionStorage.setItem("__pp_edit_token", token);
|
|
41
|
+
setUrlState({ enabled, token });
|
|
40
42
|
} catch {
|
|
41
43
|
}
|
|
42
44
|
}, [enabledOverride]);
|
|
@@ -63,14 +65,9 @@ function StrapiEditModeProvider({ children, enabled: enabledOverride }) {
|
|
|
63
65
|
window.location.reload();
|
|
64
66
|
return;
|
|
65
67
|
}
|
|
66
|
-
if (d.type === "pp:edit:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
setChanges(/* @__PURE__ */ new Map());
|
|
70
|
-
setLastCommitError(null);
|
|
71
|
-
} else {
|
|
72
|
-
setLastCommitError(d.error || "Speichern fehlgeschlagen");
|
|
73
|
-
}
|
|
68
|
+
if (d.type === "pp:edit:exit") {
|
|
69
|
+
window.sessionStorage.removeItem(EDIT_SESSION_KEY);
|
|
70
|
+
window.location.reload();
|
|
74
71
|
return;
|
|
75
72
|
}
|
|
76
73
|
if (d.type === "pp:edit:media-picked") {
|
|
@@ -85,58 +82,12 @@ function StrapiEditModeProvider({ children, enabled: enabledOverride }) {
|
|
|
85
82
|
window.addEventListener("message", onMsg);
|
|
86
83
|
return () => window.removeEventListener("message", onMsg);
|
|
87
84
|
}, [urlState.enabled]);
|
|
88
|
-
const
|
|
89
|
-
setChanges((prev) => {
|
|
90
|
-
const next = new Map(prev);
|
|
91
|
-
next.set(path, { path, fieldType, value: value2 });
|
|
92
|
-
return next;
|
|
93
|
-
});
|
|
94
|
-
setLastCommitError(null);
|
|
95
|
-
if (typeof window !== "undefined" && window.parent !== window) {
|
|
96
|
-
try {
|
|
97
|
-
window.parent.postMessage({ type: "pp:edit:change", path, fieldType, value: value2 }, "*");
|
|
98
|
-
} catch {
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}, []);
|
|
102
|
-
const clearChange = useCallback((path) => {
|
|
103
|
-
setChanges((prev) => {
|
|
104
|
-
const next = new Map(prev);
|
|
105
|
-
next.delete(path);
|
|
106
|
-
return next;
|
|
107
|
-
});
|
|
85
|
+
const publishChange = useCallback((_path, _fieldType, _value) => {
|
|
108
86
|
}, []);
|
|
109
|
-
const commit = useCallback(() => {
|
|
110
|
-
if (changes.size === 0) return;
|
|
111
|
-
if (typeof window === "undefined" || window.parent === window) return;
|
|
112
|
-
setIsCommitting(true);
|
|
113
|
-
setLastCommitError(null);
|
|
114
|
-
try {
|
|
115
|
-
window.parent.postMessage(
|
|
116
|
-
{
|
|
117
|
-
type: "pp:edit:commit-request",
|
|
118
|
-
changes: Array.from(changes.values())
|
|
119
|
-
},
|
|
120
|
-
"*"
|
|
121
|
-
);
|
|
122
|
-
} catch (err) {
|
|
123
|
-
setIsCommitting(false);
|
|
124
|
-
setLastCommitError(err instanceof Error ? err.message : String(err));
|
|
125
|
-
}
|
|
126
|
-
}, [changes]);
|
|
127
87
|
const openMediaPicker = useCallback((path, multiple, allowedTypes, currentValue) => {
|
|
128
88
|
if (typeof window === "undefined" || window.parent === window) return;
|
|
129
89
|
try {
|
|
130
|
-
window.parent.postMessage(
|
|
131
|
-
{
|
|
132
|
-
type: "pp:edit:open-media-picker",
|
|
133
|
-
path,
|
|
134
|
-
multiple,
|
|
135
|
-
allowedTypes,
|
|
136
|
-
currentValue
|
|
137
|
-
},
|
|
138
|
-
"*"
|
|
139
|
-
);
|
|
90
|
+
window.parent.postMessage({ type: "pp:edit:open-media-picker", path, multiple, allowedTypes, currentValue }, "*");
|
|
140
91
|
} catch {
|
|
141
92
|
}
|
|
142
93
|
}, []);
|
|
@@ -149,98 +100,34 @@ function StrapiEditModeProvider({ children, enabled: enabledOverride }) {
|
|
|
149
100
|
const value = useMemo(() => ({
|
|
150
101
|
enabled: urlState.enabled,
|
|
151
102
|
token: urlState.token,
|
|
152
|
-
|
|
153
|
-
isDirty: changes.size > 0,
|
|
154
|
-
isCommitting,
|
|
155
|
-
lastCommitError,
|
|
156
|
-
setChange,
|
|
157
|
-
clearChange,
|
|
158
|
-
commit,
|
|
103
|
+
publishChange,
|
|
159
104
|
openMediaPicker,
|
|
160
105
|
onMediaPicked
|
|
161
|
-
}), [urlState,
|
|
162
|
-
return /* @__PURE__ */
|
|
163
|
-
children,
|
|
164
|
-
urlState.enabled && /* @__PURE__ */ jsx(SaveBar, {})
|
|
165
|
-
] });
|
|
106
|
+
}), [urlState, publishChange, openMediaPicker, onMediaPicked]);
|
|
107
|
+
return /* @__PURE__ */ jsx(EditModeContext.Provider, { value, children });
|
|
166
108
|
}
|
|
167
|
-
function
|
|
168
|
-
const {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}, children: lastCommitError }),
|
|
190
|
-
/* @__PURE__ */ jsx(
|
|
191
|
-
"button",
|
|
192
|
-
{
|
|
193
|
-
type: "button",
|
|
194
|
-
onClick: commit,
|
|
195
|
-
disabled: isCommitting || !isDirty,
|
|
196
|
-
style: {
|
|
197
|
-
background: isCommitting ? "#666" : "#000",
|
|
198
|
-
color: "#EBC6DF",
|
|
199
|
-
border: "2px solid #000",
|
|
200
|
-
padding: "14px 22px",
|
|
201
|
-
fontSize: 13,
|
|
202
|
-
fontWeight: 700,
|
|
203
|
-
textTransform: "uppercase",
|
|
204
|
-
letterSpacing: "0.2em",
|
|
205
|
-
cursor: isCommitting ? "wait" : "pointer",
|
|
206
|
-
display: "flex",
|
|
207
|
-
alignItems: "center",
|
|
208
|
-
gap: 10,
|
|
209
|
-
boxShadow: "0 4px 12px rgba(0,0,0,0.3)",
|
|
210
|
-
transition: "background 0.15s ease"
|
|
211
|
-
},
|
|
212
|
-
onMouseEnter: (e) => {
|
|
213
|
-
if (!isCommitting && isDirty) {
|
|
214
|
-
e.currentTarget.style.background = "#FA501E";
|
|
215
|
-
e.currentTarget.style.color = "#000";
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
onMouseLeave: (e) => {
|
|
219
|
-
if (!isCommitting && isDirty) {
|
|
220
|
-
e.currentTarget.style.background = "#000";
|
|
221
|
-
e.currentTarget.style.color = "#EBC6DF";
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
children: isCommitting ? /* @__PURE__ */ jsx("span", { children: "Speichere\u2026" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
225
|
-
/* @__PURE__ */ jsx("span", { style: {
|
|
226
|
-
background: "#FA501E",
|
|
227
|
-
color: "#000",
|
|
228
|
-
width: 22,
|
|
229
|
-
height: 22,
|
|
230
|
-
borderRadius: "50%",
|
|
231
|
-
display: "inline-flex",
|
|
232
|
-
alignItems: "center",
|
|
233
|
-
justifyContent: "center",
|
|
234
|
-
fontSize: 11,
|
|
235
|
-
fontWeight: 700
|
|
236
|
-
}, children: changes.size }),
|
|
237
|
-
/* @__PURE__ */ jsx("span", { children: "Speichern" })
|
|
238
|
-
] })
|
|
239
|
-
}
|
|
240
|
-
)
|
|
241
|
-
]
|
|
242
|
-
}
|
|
243
|
-
);
|
|
109
|
+
function StrapiContent({ uid, kind, documentId, children }) {
|
|
110
|
+
const scope = useMemo(() => ({ uid, kind, documentId }), [uid, kind, documentId]);
|
|
111
|
+
return /* @__PURE__ */ jsx(ContentScopeContext.Provider, { value: scope, children });
|
|
112
|
+
}
|
|
113
|
+
function postEditChange(scope, path, fieldType, value) {
|
|
114
|
+
if (typeof window === "undefined" || window.parent === window) return;
|
|
115
|
+
if (!scope) {
|
|
116
|
+
console.warn("[strapi-render] Feld ohne <StrapiContent>-Scope \u2014 Save wird nicht funktionieren. Wickle deine Seite mit <StrapiContent uid='...' kind='...'> ein.");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
window.parent.postMessage({
|
|
121
|
+
type: "pp:edit:change",
|
|
122
|
+
uid: scope.uid,
|
|
123
|
+
kind: scope.kind,
|
|
124
|
+
documentId: scope.documentId,
|
|
125
|
+
path,
|
|
126
|
+
fieldType,
|
|
127
|
+
value
|
|
128
|
+
}, "*");
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
244
131
|
}
|
|
245
132
|
var EDITABLE_TYPES = /* @__PURE__ */ new Set([
|
|
246
133
|
"text",
|
|
@@ -252,6 +139,7 @@ var EDITABLE_TYPES = /* @__PURE__ */ new Set([
|
|
|
252
139
|
var HOVER_OUTLINE_COLOR = "#FA501E";
|
|
253
140
|
function StrapiField({ path, type, value, children, className }) {
|
|
254
141
|
const ctx = useStrapiEditMode();
|
|
142
|
+
const scope = useContentScope();
|
|
255
143
|
const ref = useRef(null);
|
|
256
144
|
const initialText = useRef(void 0);
|
|
257
145
|
useEffect(() => {
|
|
@@ -307,7 +195,7 @@ function StrapiField({ path, type, value, children, className }) {
|
|
|
307
195
|
const original = typeof value === "string" ? value : initialText.current ?? "";
|
|
308
196
|
if (newText !== original) {
|
|
309
197
|
const newValue = type === "number" ? newText === "" ? null : Number(newText) : newText;
|
|
310
|
-
|
|
198
|
+
postEditChange(scope, path, type, newValue);
|
|
311
199
|
}
|
|
312
200
|
};
|
|
313
201
|
props.onKeyDown = (e) => {
|
|
@@ -347,6 +235,7 @@ function resolveUrl(value, baseUrl) {
|
|
|
347
235
|
var HOVER_OUTLINE_COLOR2 = "#FA501E";
|
|
348
236
|
function StrapiImage({ path, value, baseUrl, alt, className, style, loading = "lazy", fallback, allowedTypes, multiple = false, width, height, draggable }) {
|
|
349
237
|
const ctx = useStrapiEditMode();
|
|
238
|
+
const scope = useContentScope();
|
|
350
239
|
const containerRef = useRef(null);
|
|
351
240
|
const imgRef = useRef(null);
|
|
352
241
|
const handleClick = (e) => {
|
|
@@ -354,7 +243,7 @@ function StrapiImage({ path, value, baseUrl, alt, className, style, loading = "l
|
|
|
354
243
|
e.preventDefault();
|
|
355
244
|
e.stopPropagation();
|
|
356
245
|
const unsubscribe = ctx.onMediaPicked(path, (picked) => {
|
|
357
|
-
|
|
246
|
+
postEditChange(scope, path, "media", picked);
|
|
358
247
|
unsubscribe();
|
|
359
248
|
if (imgRef.current && picked && typeof picked === "object" && !Array.isArray(picked) && "url" in picked) {
|
|
360
249
|
imgRef.current.src = resolveUrl(picked, baseUrl);
|
|
@@ -576,6 +465,7 @@ function parseBlocksFromDOM(root) {
|
|
|
576
465
|
}
|
|
577
466
|
function StrapiBlocks({ path, value, className }) {
|
|
578
467
|
const ctx = useStrapiEditMode();
|
|
468
|
+
const scope = useContentScope();
|
|
579
469
|
const containerRef = useRef(null);
|
|
580
470
|
const initialValue = useRef(null);
|
|
581
471
|
const blocks = Array.isArray(value) ? value : [];
|
|
@@ -616,7 +506,7 @@ function StrapiBlocks({ path, value, className }) {
|
|
|
616
506
|
const before = JSON.stringify(initialValue.current);
|
|
617
507
|
const after = JSON.stringify(parsed);
|
|
618
508
|
if (before !== after) {
|
|
619
|
-
|
|
509
|
+
postEditChange(scope, path, "blocks", parsed);
|
|
620
510
|
}
|
|
621
511
|
e.currentTarget.style.outlineColor = "transparent";
|
|
622
512
|
e.currentTarget.style.outlineStyle = "dashed";
|
|
@@ -628,6 +518,7 @@ function StrapiBlocks({ path, value, className }) {
|
|
|
628
518
|
var HOVER_OUTLINE2 = "#FA501E";
|
|
629
519
|
function StrapiMarkdownField({ path, value, render, className, minRows = 12 }) {
|
|
630
520
|
const ctx = useStrapiEditMode();
|
|
521
|
+
const scope = useContentScope();
|
|
631
522
|
const [draft, setDraft] = useState(value ?? "");
|
|
632
523
|
const initial = useRef(value ?? "");
|
|
633
524
|
useEffect(() => {
|
|
@@ -645,7 +536,7 @@ function StrapiMarkdownField({ path, value, render, className, minRows = 12 }) {
|
|
|
645
536
|
onChange: (e) => setDraft(e.target.value),
|
|
646
537
|
onBlur: () => {
|
|
647
538
|
if (draft !== initial.current) {
|
|
648
|
-
|
|
539
|
+
postEditChange(scope, path, "richText", draft);
|
|
649
540
|
}
|
|
650
541
|
},
|
|
651
542
|
onFocus: (e) => {
|
|
@@ -693,6 +584,6 @@ function StrapiMarkdownField({ path, value, render, className, minRows = 12 }) {
|
|
|
693
584
|
] });
|
|
694
585
|
}
|
|
695
586
|
|
|
696
|
-
export { StrapiBlocks, StrapiEditModeProvider, StrapiField, StrapiImage, StrapiList, StrapiMarkdownField, StrapiText, useStrapiEditMode };
|
|
587
|
+
export { StrapiBlocks, StrapiContent, StrapiEditModeProvider, StrapiField, StrapiImage, StrapiList, StrapiMarkdownField, StrapiText, useContentScope, useStrapiEditMode };
|
|
697
588
|
//# sourceMappingURL=index.js.map
|
|
698
589
|
//# sourceMappingURL=index.js.map
|