autoblogger 0.1.10 → 0.1.11
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/ui.js +30 -10
- package/dist/ui.js.map +1 -1
- package/dist/ui.mjs +30 -10
- package/dist/ui.mjs.map +1 -1
- package/package.json +1 -1
package/dist/ui.js
CHANGED
|
@@ -6896,6 +6896,9 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
|
|
|
6896
6896
|
navigate(`/editor/${data.data.slug}`);
|
|
6897
6897
|
}
|
|
6898
6898
|
}
|
|
6899
|
+
} catch (err) {
|
|
6900
|
+
console.error("Save failed:", err);
|
|
6901
|
+
throw err;
|
|
6899
6902
|
} finally {
|
|
6900
6903
|
if (!silent) {
|
|
6901
6904
|
setSaving(false);
|
|
@@ -6910,14 +6913,19 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
|
|
|
6910
6913
|
try {
|
|
6911
6914
|
const method = post.id ? "PATCH" : "POST";
|
|
6912
6915
|
const url = post.id ? `${apiBasePath}/posts/${post.id}` : `${apiBasePath}/posts`;
|
|
6916
|
+
let currentPost;
|
|
6917
|
+
setPost((p) => {
|
|
6918
|
+
currentPost = p;
|
|
6919
|
+
return p;
|
|
6920
|
+
});
|
|
6913
6921
|
const res = await fetch(url, {
|
|
6914
6922
|
method,
|
|
6915
6923
|
headers: { "Content-Type": "application/json" },
|
|
6916
6924
|
body: JSON.stringify({
|
|
6917
|
-
...
|
|
6918
|
-
title:
|
|
6925
|
+
...currentPost,
|
|
6926
|
+
title: currentPost.title || "Untitled",
|
|
6919
6927
|
status: "published",
|
|
6920
|
-
...Object.fromEntries(fields.map((f) => [f.name,
|
|
6928
|
+
...Object.fromEntries(fields.map((f) => [f.name, currentPost[f.name]]))
|
|
6921
6929
|
})
|
|
6922
6930
|
});
|
|
6923
6931
|
if (res.ok) {
|
|
@@ -6927,7 +6935,7 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
|
|
|
6927
6935
|
setSaving(false);
|
|
6928
6936
|
setSavingAs(null);
|
|
6929
6937
|
}
|
|
6930
|
-
}, [post, apiBasePath, fields, navigate]);
|
|
6938
|
+
}, [post.id, apiBasePath, fields, navigate]);
|
|
6931
6939
|
const comments = useComments({
|
|
6932
6940
|
postId: post.id || null,
|
|
6933
6941
|
editor,
|
|
@@ -6976,23 +6984,35 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
|
|
|
6976
6984
|
const current = JSON.stringify({ title: post.title, subtitle: post.subtitle, markdown: post.markdown });
|
|
6977
6985
|
setHasUnsavedChanges(current !== savedContent.current && savedContent.current !== "");
|
|
6978
6986
|
}, [post.title, post.subtitle, post.markdown]);
|
|
6987
|
+
const savePostRef = (0, import_react16.useRef)(savePost);
|
|
6988
|
+
const handlePublishRef = (0, import_react16.useRef)(handlePublish);
|
|
6989
|
+
const onEditorStateChangeRef = (0, import_react16.useRef)(onEditorStateChange);
|
|
6990
|
+
(0, import_react16.useEffect)(() => {
|
|
6991
|
+
savePostRef.current = savePost;
|
|
6992
|
+
}, [savePost]);
|
|
6993
|
+
(0, import_react16.useEffect)(() => {
|
|
6994
|
+
handlePublishRef.current = handlePublish;
|
|
6995
|
+
}, [handlePublish]);
|
|
6996
|
+
(0, import_react16.useEffect)(() => {
|
|
6997
|
+
onEditorStateChangeRef.current = onEditorStateChange;
|
|
6998
|
+
}, [onEditorStateChange]);
|
|
6979
6999
|
(0, import_react16.useEffect)(() => {
|
|
6980
|
-
if (!
|
|
7000
|
+
if (!onEditorStateChangeRef.current) return;
|
|
6981
7001
|
const confirmLeave = () => {
|
|
6982
7002
|
if (hasUnsavedChanges) {
|
|
6983
7003
|
return confirm("You have unsaved changes. Leave anyway?");
|
|
6984
7004
|
}
|
|
6985
7005
|
return true;
|
|
6986
7006
|
};
|
|
6987
|
-
|
|
7007
|
+
onEditorStateChangeRef.current({
|
|
6988
7008
|
hasUnsavedChanges,
|
|
6989
7009
|
status: post.status,
|
|
6990
7010
|
savingAs,
|
|
6991
7011
|
onSave: (status) => {
|
|
6992
7012
|
if (status === "draft") {
|
|
6993
|
-
|
|
7013
|
+
savePostRef.current();
|
|
6994
7014
|
} else {
|
|
6995
|
-
|
|
7015
|
+
handlePublishRef.current();
|
|
6996
7016
|
}
|
|
6997
7017
|
},
|
|
6998
7018
|
confirmLeave,
|
|
@@ -7004,9 +7024,9 @@ function EditorPage({ slug, onEditorStateChange: onEditorStateChangeProp }) {
|
|
|
7004
7024
|
}
|
|
7005
7025
|
});
|
|
7006
7026
|
return () => {
|
|
7007
|
-
|
|
7027
|
+
onEditorStateChangeRef.current?.(null);
|
|
7008
7028
|
};
|
|
7009
|
-
}, [hasUnsavedChanges, post.status, savingAs, post.title, post.subtitle, post.markdown
|
|
7029
|
+
}, [hasUnsavedChanges, post.status, savingAs, post.title, post.subtitle, post.markdown]);
|
|
7010
7030
|
(0, import_react16.useEffect)(() => {
|
|
7011
7031
|
if (!onRegisterEditHandler) return;
|
|
7012
7032
|
const handleEdit = (edit) => {
|