@tecof/theme-editor 0.0.18 → 0.0.19
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.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -58,7 +58,7 @@ var TecofApiClient = class {
|
|
|
58
58
|
/**
|
|
59
59
|
* Save a page by ID
|
|
60
60
|
*/
|
|
61
|
-
async savePage(pageId,
|
|
61
|
+
async savePage(pageId, draftData, title, accessToken) {
|
|
62
62
|
try {
|
|
63
63
|
const res2 = await fetch(`${this.apiUrl}/api/store/editor/${pageId}`, {
|
|
64
64
|
method: "PUT",
|
|
@@ -66,7 +66,7 @@ var TecofApiClient = class {
|
|
|
66
66
|
...this.headers,
|
|
67
67
|
...accessToken && { Authorization: accessToken }
|
|
68
68
|
},
|
|
69
|
-
body: JSON.stringify({
|
|
69
|
+
body: JSON.stringify({ draftData, ...title && { title } })
|
|
70
70
|
});
|
|
71
71
|
return await res2.json();
|
|
72
72
|
} catch (error2) {
|
|
@@ -231,7 +231,7 @@ var TecofEditor = ({
|
|
|
231
231
|
const [loading, setLoading] = useState(true);
|
|
232
232
|
const [saving, setSaving] = useState(false);
|
|
233
233
|
const [saveStatus, setSaveStatus] = useState("idle");
|
|
234
|
-
const
|
|
234
|
+
const draftDataRef = useRef(null);
|
|
235
235
|
const isEmbedded = typeof window !== "undefined" && window.parent !== window;
|
|
236
236
|
useEffect(() => {
|
|
237
237
|
let cancelled = false;
|
|
@@ -239,9 +239,9 @@ var TecofEditor = ({
|
|
|
239
239
|
setLoading(true);
|
|
240
240
|
const res2 = await apiClient.getPage(pageId);
|
|
241
241
|
if (cancelled) return;
|
|
242
|
-
const data3 = res2.success && res2.data?.
|
|
242
|
+
const data3 = res2.success && res2.data?.draftData ? res2.data.draftData : EMPTY_PAGE;
|
|
243
243
|
setInitialData(data3);
|
|
244
|
-
|
|
244
|
+
draftDataRef.current = data3;
|
|
245
245
|
setLoading(false);
|
|
246
246
|
};
|
|
247
247
|
load();
|
|
@@ -251,16 +251,16 @@ var TecofEditor = ({
|
|
|
251
251
|
}, [pageId, apiClient]);
|
|
252
252
|
const handleSaveDraft = useCallback(
|
|
253
253
|
async (data3) => {
|
|
254
|
-
const currentData = data3 ||
|
|
254
|
+
const currentData = data3 || draftDataRef.current;
|
|
255
255
|
if (!currentData) return;
|
|
256
|
-
const
|
|
256
|
+
const draftData = currentData;
|
|
257
257
|
setSaving(true);
|
|
258
258
|
setSaveStatus("idle");
|
|
259
|
-
const res2 = await apiClient.savePage(pageId,
|
|
259
|
+
const res2 = await apiClient.savePage(pageId, draftData, void 0, accessToken);
|
|
260
260
|
if (res2.success) {
|
|
261
261
|
setSaveStatus("success");
|
|
262
262
|
setTimeout(() => setSaveStatus("idle"), 3e3);
|
|
263
|
-
onSave?.(
|
|
263
|
+
onSave?.(draftData);
|
|
264
264
|
if (isEmbedded) window.parent.postMessage({ type: "puck:saved" }, "*");
|
|
265
265
|
} else {
|
|
266
266
|
setSaveStatus("error");
|
|
@@ -272,9 +272,9 @@ var TecofEditor = ({
|
|
|
272
272
|
);
|
|
273
273
|
const handleChange = useCallback(
|
|
274
274
|
(data3) => {
|
|
275
|
-
|
|
276
|
-
const
|
|
277
|
-
onChange?.(
|
|
275
|
+
draftDataRef.current = data3;
|
|
276
|
+
const draftData = data3;
|
|
277
|
+
onChange?.(draftData);
|
|
278
278
|
if (isEmbedded) window.parent.postMessage({ type: "puck:changed" }, "*");
|
|
279
279
|
},
|
|
280
280
|
[onChange, isEmbedded]
|