@cancia/toolbar 0.1.0 → 0.4.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/cancia.d.ts +6 -2
- package/dist/cancia.iife.js +59 -59
- package/dist/cancia.js +16 -8
- package/dist/cancia.js.map +1 -1
- package/package.json +2 -2
package/dist/cancia.js
CHANGED
|
@@ -68,6 +68,13 @@ function headers() {
|
|
|
68
68
|
if (state.sessionToken) h["Authorization"] = `Bearer ${state.sessionToken}`;
|
|
69
69
|
return h;
|
|
70
70
|
}
|
|
71
|
+
function currentRoute() {
|
|
72
|
+
return typeof location !== "undefined" ? location.pathname : "";
|
|
73
|
+
}
|
|
74
|
+
function routeParam() {
|
|
75
|
+
const r = currentRoute();
|
|
76
|
+
return r ? `&route=${encodeURIComponent(r)}` : "";
|
|
77
|
+
}
|
|
71
78
|
async function fetchContent() {
|
|
72
79
|
const { apiUrl, site } = state.config;
|
|
73
80
|
const res = await fetch(`${apiUrl}/api/cancia/content?site=${encodeURIComponent(site)}`, {
|
|
@@ -81,7 +88,8 @@ async function saveEntry(key, lang, value) {
|
|
|
81
88
|
const res = await fetch(`${apiUrl}/api/cancia/save`, {
|
|
82
89
|
method: "POST",
|
|
83
90
|
headers: headers(),
|
|
84
|
-
|
|
91
|
+
// `route` lets the server invalidate this page's cache tag (034, invalidate mode).
|
|
92
|
+
body: JSON.stringify({ key, lang, value, site, route: currentRoute() })
|
|
85
93
|
});
|
|
86
94
|
if (!res.ok) throw new Error(`Cancia: failed to save (${res.status})`);
|
|
87
95
|
}
|
|
@@ -157,7 +165,7 @@ async function fetchTranslations(listName) {
|
|
|
157
165
|
async function createListEntry(listName, data, locale, id) {
|
|
158
166
|
const { apiUrl, site } = state.config;
|
|
159
167
|
const res = await fetch(
|
|
160
|
-
`${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}?site=${encodeURIComponent(site)}${localeParam(locale)}`,
|
|
168
|
+
`${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}?site=${encodeURIComponent(site)}${localeParam(locale)}${routeParam()}`,
|
|
161
169
|
{ method: "POST", headers: headers(), body: JSON.stringify({ data, id }) }
|
|
162
170
|
);
|
|
163
171
|
if (!res.ok) {
|
|
@@ -170,7 +178,7 @@ async function createListEntry(listName, data, locale, id) {
|
|
|
170
178
|
async function updateListEntry(listName, id, data, rev, locale) {
|
|
171
179
|
const { apiUrl, site } = state.config;
|
|
172
180
|
const res = await fetch(
|
|
173
|
-
`${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/${encodeURIComponent(id)}?site=${encodeURIComponent(site)}${localeParam(locale)}`,
|
|
181
|
+
`${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/${encodeURIComponent(id)}?site=${encodeURIComponent(site)}${localeParam(locale)}${routeParam()}`,
|
|
174
182
|
{ method: "PATCH", headers: headers(), body: JSON.stringify({ data, _rev: rev }) }
|
|
175
183
|
);
|
|
176
184
|
if (!res.ok) {
|
|
@@ -184,7 +192,7 @@ async function updateListEntry(listName, id, data, rev, locale) {
|
|
|
184
192
|
async function deleteListEntry(listName, id, locale) {
|
|
185
193
|
const { apiUrl, site } = state.config;
|
|
186
194
|
const res = await fetch(
|
|
187
|
-
`${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/${encodeURIComponent(id)}?site=${encodeURIComponent(site)}${localeParam(locale)}`,
|
|
195
|
+
`${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/${encodeURIComponent(id)}?site=${encodeURIComponent(site)}${localeParam(locale)}${routeParam()}`,
|
|
188
196
|
{ method: "DELETE", headers: headers() }
|
|
189
197
|
);
|
|
190
198
|
if (!res.ok) throw new Error(`Cancia: failed to delete entry (${res.status})`);
|
|
@@ -192,7 +200,7 @@ async function deleteListEntry(listName, id, locale) {
|
|
|
192
200
|
async function reorderList(listName, ids) {
|
|
193
201
|
const { apiUrl, site } = state.config;
|
|
194
202
|
const res = await fetch(
|
|
195
|
-
`${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/reorder?site=${encodeURIComponent(site)}`,
|
|
203
|
+
`${apiUrl}/api/cancia/lists/${encodeURIComponent(listName)}/reorder?site=${encodeURIComponent(site)}${routeParam()}`,
|
|
196
204
|
{ method: "POST", headers: headers(), body: JSON.stringify({ ids }) }
|
|
197
205
|
);
|
|
198
206
|
if (!res.ok) throw new Error(`Cancia: failed to reorder list (${res.status})`);
|
|
@@ -2807,16 +2815,16 @@ function buildToolbar() {
|
|
|
2807
2815
|
() => toggleEditMode()
|
|
2808
2816
|
);
|
|
2809
2817
|
controls.appendChild(editBtn);
|
|
2810
|
-
const
|
|
2818
|
+
const canPublish = state.config?.canPublish ?? true;
|
|
2811
2819
|
const publishBtn = makeIconButton(
|
|
2812
2820
|
`<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
2813
2821
|
<path d="M22 2L11 13"/>
|
|
2814
2822
|
<path d="M22 2L15 22l-4-9-9-4 20-7z"/>
|
|
2815
2823
|
</svg>`,
|
|
2816
|
-
|
|
2824
|
+
canPublish ? "Publish" : "Publish (no publish method configured)",
|
|
2817
2825
|
() => handlePublish(publishBtn)
|
|
2818
2826
|
);
|
|
2819
|
-
if (!
|
|
2827
|
+
if (!canPublish) {
|
|
2820
2828
|
publishBtn.disabled = true;
|
|
2821
2829
|
publishBtn.style.opacity = "0.3";
|
|
2822
2830
|
publishBtn.style.cursor = "not-allowed";
|