@cardinali-studio/adminkit 2.2.1 → 2.2.2
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/app/lib/settings.js +26 -3
- package/dist/app/site.d.ts +6 -0
- package/package.json +1 -1
package/dist/app/lib/settings.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { useCallback, useEffect, useState } from "react";
|
|
8
8
|
import { ApiError } from "../../index.js";
|
|
9
|
+
import { api } from "../../api.js";
|
|
10
|
+
import { contentPersistenceMode, site } from "../site.js";
|
|
9
11
|
const empty = {
|
|
10
12
|
siteTitle: "",
|
|
11
13
|
shortDescription: "",
|
|
@@ -34,10 +36,22 @@ export function useSiteSettings(active) {
|
|
|
34
36
|
const [dirty, setDirty] = useState(false);
|
|
35
37
|
const [saving, setSaving] = useState(false);
|
|
36
38
|
const [notice, setNotice] = useState(null);
|
|
39
|
+
const [revision, setRevision] = useState(null);
|
|
37
40
|
const load = useCallback(async () => {
|
|
38
41
|
try {
|
|
39
|
-
const
|
|
40
|
-
|
|
42
|
+
const mapped = site().siteSettingsDocument;
|
|
43
|
+
if (contentPersistenceMode() === "d1" && mapped) {
|
|
44
|
+
const { document } = await api.contentDocument(mapped.documentId);
|
|
45
|
+
const payload = document.draftPayload ?? document.publishedPayload;
|
|
46
|
+
if (!payload || (document.draftPayload !== null ? document.draftTombstone : document.publishedTombstone))
|
|
47
|
+
throw new Error("content_unavailable");
|
|
48
|
+
setData({ ...empty, ...JSON.parse(payload), password: "" });
|
|
49
|
+
setRevision({ base: document.draftRevisionId ?? document.publishedRevisionId, expected: document.draftRevisionId });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
const result = await call("/admin/api/settings");
|
|
53
|
+
setData({ ...empty, ...result.settings, password: "" });
|
|
54
|
+
}
|
|
41
55
|
setError(null);
|
|
42
56
|
setDirty(false);
|
|
43
57
|
}
|
|
@@ -55,6 +69,15 @@ export function useSiteSettings(active) {
|
|
|
55
69
|
setSaving(true);
|
|
56
70
|
setNotice(null);
|
|
57
71
|
try {
|
|
72
|
+
const mapped = site().siteSettingsDocument;
|
|
73
|
+
if (contentPersistenceMode() === "d1" && mapped && revision) {
|
|
74
|
+
const revisionId = crypto.randomUUID();
|
|
75
|
+
await api.saveContent({ revisionId, documentId: mapped.documentId, baseRevisionId: revision.base, expectedDraftRevisionId: revision.expected, kind: mapped.kind, locale: mapped.locale, schemaVersion: mapped.schemaVersion, payload: data, tombstone: false });
|
|
76
|
+
setRevision({ base: revisionId, expected: revisionId });
|
|
77
|
+
setDirty(false);
|
|
78
|
+
setNotice("Bozza D1 salvata");
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
58
81
|
const result = await call("/admin/api/settings", {
|
|
59
82
|
method: "POST",
|
|
60
83
|
headers: { "Content-Type": "application/json" },
|
|
@@ -73,7 +96,7 @@ export function useSiteSettings(active) {
|
|
|
73
96
|
finally {
|
|
74
97
|
setSaving(false);
|
|
75
98
|
}
|
|
76
|
-
}, [data]);
|
|
99
|
+
}, [data, revision]);
|
|
77
100
|
const change = useCallback((next) => {
|
|
78
101
|
setData(next);
|
|
79
102
|
setDirty(true);
|
package/dist/app/site.d.ts
CHANGED
|
@@ -56,6 +56,12 @@ export interface SiteAdminConfig {
|
|
|
56
56
|
locale: string;
|
|
57
57
|
schemaVersion: number;
|
|
58
58
|
};
|
|
59
|
+
siteSettingsDocument?: {
|
|
60
|
+
documentId: string;
|
|
61
|
+
kind: string;
|
|
62
|
+
locale: string;
|
|
63
|
+
schemaVersion: number;
|
|
64
|
+
};
|
|
59
65
|
}
|
|
60
66
|
/** Chiamata da `mountAdmin` prima del primo render. */
|
|
61
67
|
export declare function setSiteConfig(config: SiteAdminConfig): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardinali-studio/adminkit",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Motore riusabile di un pannello di amministrazione per siti Hugo su Cloudflare Pages: codec del front matter guidato dallo schema, form React, libreria media su R2. NIENTE di specifico di un sito qui dentro.",
|
|
6
6
|
"license": "UNLICENSED",
|