@b10cks/client 1.4.0 → 1.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/README.md +90 -0
- package/dist/index.d.ts +138 -4
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +283 -131
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.mjs
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (!
|
|
3
|
-
if (
|
|
1
|
+
function _(i) {
|
|
2
|
+
if (!i) return;
|
|
3
|
+
if (i.type === "email") {
|
|
4
4
|
const n = new URLSearchParams();
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
return { href: `mailto:${
|
|
5
|
+
i.subject && n.set("subject", i.subject), i.body && n.set("body", i.body), i.cc && n.set("cc", i.cc), i.bcc && n.set("bcc", i.bcc);
|
|
6
|
+
const s = n.toString();
|
|
7
|
+
return { href: `mailto:${i.email}${s ? `?${s}` : ""}`, target: "_self" };
|
|
8
8
|
}
|
|
9
|
-
if (
|
|
9
|
+
if (i.type === "asset")
|
|
10
10
|
return;
|
|
11
|
-
const t =
|
|
12
|
-
let e =
|
|
13
|
-
return "anchor" in
|
|
11
|
+
const t = i.target ?? "_self";
|
|
12
|
+
let e = i.url ?? "";
|
|
13
|
+
return "anchor" in i && i.anchor && (e = `${e.trimEnd()}#${i.anchor}`), { href: e, target: t };
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
if (
|
|
17
|
-
if (typeof
|
|
18
|
-
if (typeof
|
|
19
|
-
if (typeof
|
|
20
|
-
const t =
|
|
15
|
+
function A(i) {
|
|
16
|
+
if (i != null) {
|
|
17
|
+
if (typeof i == "boolean" || typeof i == "number") return String(i);
|
|
18
|
+
if (typeof i == "string") return i;
|
|
19
|
+
if (typeof i == "object" && !Array.isArray(i)) {
|
|
20
|
+
const t = i;
|
|
21
21
|
if ("null" in t) return "null:";
|
|
22
22
|
if ("!null" in t) return "!null:";
|
|
23
23
|
if ("between" in t) {
|
|
24
|
-
const [n,
|
|
25
|
-
return `${n}...${
|
|
24
|
+
const [n, s] = t.between;
|
|
25
|
+
return `${n}...${s}`;
|
|
26
26
|
}
|
|
27
27
|
const e = [
|
|
28
28
|
"eq",
|
|
@@ -42,25 +42,25 @@ function v(s) {
|
|
|
42
42
|
];
|
|
43
43
|
for (const n of e)
|
|
44
44
|
if (n in t) {
|
|
45
|
-
const
|
|
46
|
-
return Array.isArray(
|
|
45
|
+
const s = t[n];
|
|
46
|
+
return Array.isArray(s) ? `${n}:${s.join(",")}` : `${n}:${String(s)}`;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function S(i) {
|
|
52
52
|
const t = {};
|
|
53
|
-
for (const [e, n] of Object.entries(
|
|
54
|
-
const
|
|
55
|
-
|
|
53
|
+
for (const [e, n] of Object.entries(i)) {
|
|
54
|
+
const s = A(n);
|
|
55
|
+
s !== void 0 && (t[e] = s);
|
|
56
56
|
}
|
|
57
57
|
return t;
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
const n = t && typeof t == "object" ?
|
|
61
|
-
return { ...
|
|
59
|
+
function g(i, t, e) {
|
|
60
|
+
const n = t && typeof t == "object" ? S(t) : {}, s = Array.isArray(e) ? { sort: e.join(",") } : e != null ? { sort: e } : {};
|
|
61
|
+
return { ...i, ...n, ...s };
|
|
62
62
|
}
|
|
63
|
-
class
|
|
63
|
+
class P {
|
|
64
64
|
constructor(t) {
|
|
65
65
|
this.client = t;
|
|
66
66
|
}
|
|
@@ -73,17 +73,17 @@ class C {
|
|
|
73
73
|
async getCollection(t, e = {}, n = {}) {
|
|
74
74
|
if (n.allPages)
|
|
75
75
|
return this.client.getAll(t, e);
|
|
76
|
-
const
|
|
77
|
-
return this.unwrapCollection(
|
|
76
|
+
const s = await this.client.get(t, e);
|
|
77
|
+
return this.unwrapCollection(s);
|
|
78
78
|
}
|
|
79
79
|
async getContent(t, e = {}) {
|
|
80
80
|
return this.getResource(`contents/${t}`, e);
|
|
81
81
|
}
|
|
82
82
|
async getContents(t = {}, e = {}) {
|
|
83
|
-
const { filter: n, sort:
|
|
83
|
+
const { filter: n, sort: s, ...r } = t;
|
|
84
84
|
return this.getCollection(
|
|
85
85
|
"contents",
|
|
86
|
-
|
|
86
|
+
g(r, n, s),
|
|
87
87
|
e
|
|
88
88
|
);
|
|
89
89
|
}
|
|
@@ -91,10 +91,10 @@ class C {
|
|
|
91
91
|
return this.getResource(`blocks/${t}`, e);
|
|
92
92
|
}
|
|
93
93
|
async getBlocks(t = {}, e = {}) {
|
|
94
|
-
const { filter: n, ...
|
|
94
|
+
const { filter: n, ...s } = t;
|
|
95
95
|
return this.getCollection(
|
|
96
96
|
"blocks",
|
|
97
|
-
|
|
97
|
+
g(s, n, void 0),
|
|
98
98
|
e
|
|
99
99
|
);
|
|
100
100
|
}
|
|
@@ -132,29 +132,29 @@ class C {
|
|
|
132
132
|
return this.client.post("redirects/lookup", { source: t });
|
|
133
133
|
}
|
|
134
134
|
async getRedirects(t = {}, e = !1) {
|
|
135
|
-
const { allPages: n = !1, forceRefresh:
|
|
136
|
-
if (n && this.redirectsCache && !
|
|
135
|
+
const { allPages: n = !1, forceRefresh: s = !1 } = typeof e == "boolean" ? { allPages: !0, forceRefresh: e } : e;
|
|
136
|
+
if (n && this.redirectsCache && !s)
|
|
137
137
|
return this.redirectsCache;
|
|
138
|
-
const { filter: r, ...
|
|
139
|
-
|
|
138
|
+
const { filter: r, ...o } = t, a = g(o, r, void 0), c = await this.getCollection("redirects", a, { allPages: n }), d = Object.fromEntries(
|
|
139
|
+
c.map(({ source: p, target: u, status_code: f }) => [p, { target: u, status_code: f }])
|
|
140
140
|
);
|
|
141
|
-
return n && (this.redirectsCache =
|
|
141
|
+
return n && (this.redirectsCache = d), d;
|
|
142
142
|
}
|
|
143
143
|
async getConfig({
|
|
144
144
|
slug: t = "_config",
|
|
145
145
|
language_iso: e,
|
|
146
146
|
language: n,
|
|
147
|
-
bypassCache:
|
|
147
|
+
bypassCache: s = !1,
|
|
148
148
|
...r
|
|
149
149
|
} = {}) {
|
|
150
|
-
const
|
|
151
|
-
if (!
|
|
152
|
-
return this.configCache.get(
|
|
153
|
-
const
|
|
150
|
+
const o = e ?? n, a = JSON.stringify({ slug: t, language_iso: o, ...r });
|
|
151
|
+
if (!s && this.configCache.has(a))
|
|
152
|
+
return this.configCache.get(a);
|
|
153
|
+
const d = (await this.getContent(t, {
|
|
154
154
|
...r,
|
|
155
|
-
language_iso:
|
|
155
|
+
language_iso: o
|
|
156
156
|
})).content ?? {};
|
|
157
|
-
return
|
|
157
|
+
return s || this.configCache.set(a, d), d;
|
|
158
158
|
}
|
|
159
159
|
async syncRevision(t = 426713400) {
|
|
160
160
|
const n = (await this.getSpace()).rv || t;
|
|
@@ -178,23 +178,34 @@ class C {
|
|
|
178
178
|
return [];
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
|
-
function
|
|
182
|
-
return new
|
|
181
|
+
function L(i) {
|
|
182
|
+
return new P(i);
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
const T = /* @__PURE__ */ new Set([
|
|
185
|
+
"CONTENT_UPDATE",
|
|
186
|
+
"CONTENT_PATCH",
|
|
187
|
+
"SELECT_UPDATE",
|
|
188
|
+
"HOVER_UPDATE",
|
|
189
|
+
"FIELD_UPDATE",
|
|
190
|
+
"FIELD_SELECT"
|
|
191
|
+
]), j = "B10CKS_BRIDGE_READY";
|
|
192
|
+
class h {
|
|
185
193
|
static instance;
|
|
186
194
|
listeners = {};
|
|
187
195
|
initialized = !1;
|
|
196
|
+
allowedOrigins = null;
|
|
197
|
+
/** Origin of the editor, captured from the first trusted message. */
|
|
198
|
+
parentOrigin = null;
|
|
188
199
|
constructor() {
|
|
189
200
|
}
|
|
190
201
|
static getInstance() {
|
|
191
|
-
return
|
|
202
|
+
return h.instance || (h.instance = new h()), h.instance;
|
|
192
203
|
}
|
|
193
|
-
init() {
|
|
194
|
-
!this.isInPreviewMode() || this.initialized || (window.addEventListener("message", this.handleMessage), this.initialized = !0);
|
|
204
|
+
init(t = {}) {
|
|
205
|
+
!this.isInPreviewMode() || this.initialized || (this.allowedOrigins = t.allowedOrigins ?? null, window.addEventListener("message", this.handleMessage), this.initialized = !0, window.parent.postMessage({ type: j }, "*"));
|
|
195
206
|
}
|
|
196
207
|
destroy() {
|
|
197
|
-
this.initialized && typeof window < "u" && window.removeEventListener("message", this.handleMessage), this.initialized = !1;
|
|
208
|
+
this.initialized && typeof window < "u" && window.removeEventListener("message", this.handleMessage), this.initialized = !1, this.parentOrigin = null;
|
|
198
209
|
for (const t of Object.keys(this.listeners))
|
|
199
210
|
this.listeners[t]?.clear();
|
|
200
211
|
}
|
|
@@ -211,77 +222,204 @@ class c {
|
|
|
211
222
|
};
|
|
212
223
|
}
|
|
213
224
|
selectItem(t) {
|
|
214
|
-
this.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
"*"
|
|
220
|
-
);
|
|
225
|
+
this.post("SELECT_UPDATE", { selectedItem: t });
|
|
226
|
+
}
|
|
227
|
+
/** Deep-select a nested field (e.g. a rich text field) in the editor. */
|
|
228
|
+
selectField(t, e) {
|
|
229
|
+
this.post("FIELD_SELECT", { itemId: t, path: e });
|
|
221
230
|
}
|
|
231
|
+
/** @deprecated Prefer {@link updateFieldAt} with a path. */
|
|
222
232
|
updateField(t, e, n) {
|
|
223
|
-
this.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
233
|
+
this.post("FIELD_UPDATE", { itemId: t, field: e, value: n });
|
|
234
|
+
}
|
|
235
|
+
/** Stream an inline edit back to the editor, addressed by path. */
|
|
236
|
+
updateFieldAt(t, e, n) {
|
|
237
|
+
this.post("FIELD_UPDATE", { itemId: t, path: e, value: n });
|
|
238
|
+
}
|
|
239
|
+
post(t, e) {
|
|
240
|
+
this.isInPreviewMode() && window.parent.postMessage({ type: t, payload: e }, this.parentOrigin ?? "*");
|
|
230
241
|
}
|
|
231
242
|
handleMessage = (t) => {
|
|
232
|
-
if (!t.data || typeof t.data != "object")
|
|
243
|
+
if (!this.isOriginTrusted(t.origin) || !t.data || typeof t.data != "object")
|
|
233
244
|
return;
|
|
234
245
|
const { type: e, payload: n } = t.data;
|
|
235
|
-
!e || !n || this.notify(e, n);
|
|
246
|
+
!e || !T.has(e) || !n || (!this.parentOrigin && t.origin && t.origin !== "null" && (this.parentOrigin = t.origin), this.notify(e, n));
|
|
236
247
|
};
|
|
248
|
+
isOriginTrusted(t) {
|
|
249
|
+
return this.parentOrigin ? t === this.parentOrigin : this.allowedOrigins ? this.allowedOrigins.includes(t) : !0;
|
|
250
|
+
}
|
|
237
251
|
notify(t, e) {
|
|
238
252
|
const n = this.listeners[t];
|
|
239
253
|
if (n)
|
|
240
|
-
for (const
|
|
241
|
-
|
|
254
|
+
for (const s of n)
|
|
255
|
+
s(e);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const l = h.getInstance(), v = "b10cks-preview-style", C = "--b10cks-scroll-offset";
|
|
259
|
+
function E() {
|
|
260
|
+
if (typeof document > "u" || document.getElementById(v))
|
|
261
|
+
return;
|
|
262
|
+
const i = document.createElement("style");
|
|
263
|
+
i.id = v, i.textContent = `
|
|
264
|
+
.b10cks-preview { scroll-margin-top: var(${C}, 0px); }
|
|
265
|
+
.b10cks-hover,
|
|
266
|
+
.b10cks-preview:hover {
|
|
267
|
+
outline: 2px dashed rgba(59, 130, 246, 0.5);
|
|
268
|
+
outline-offset: 2px;
|
|
269
|
+
}
|
|
270
|
+
.b10cks-selected {
|
|
271
|
+
outline: 2px solid rgb(59, 130, 246) !important;
|
|
272
|
+
outline-offset: 2px;
|
|
273
|
+
}
|
|
274
|
+
`, document.head.appendChild(i);
|
|
275
|
+
}
|
|
276
|
+
function F(i) {
|
|
277
|
+
if (typeof document > "u")
|
|
278
|
+
return;
|
|
279
|
+
const t = typeof i == "number" ? `${i}px` : i;
|
|
280
|
+
document.documentElement.style.setProperty(C, t);
|
|
281
|
+
}
|
|
282
|
+
function O(i, t) {
|
|
283
|
+
if (!l.isInPreviewMode() || !t.id)
|
|
284
|
+
return () => {
|
|
285
|
+
};
|
|
286
|
+
E();
|
|
287
|
+
const { id: e, onSelectChange: n, onHoverChange: s, scrollOnSelect: r = !0 } = t;
|
|
288
|
+
i.classList.add("b10cks-preview");
|
|
289
|
+
const o = (u) => {
|
|
290
|
+
u.preventDefault(), u.stopPropagation(), l.selectItem(e);
|
|
291
|
+
}, a = ({ selectedItem: u }) => {
|
|
292
|
+
const f = u === e;
|
|
293
|
+
i.classList.toggle("b10cks-selected", f), f && r && k(i), n?.(f);
|
|
294
|
+
}, c = ({ selectedItem: u }) => {
|
|
295
|
+
const f = u === e;
|
|
296
|
+
i.classList.toggle("b10cks-hover", f), s?.(f);
|
|
297
|
+
};
|
|
298
|
+
i.addEventListener("click", o);
|
|
299
|
+
const d = l.on("SELECT_UPDATE", a), p = l.on("HOVER_UPDATE", c);
|
|
300
|
+
return () => {
|
|
301
|
+
i.removeEventListener("click", o), d(), p(), i.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function $(i, t) {
|
|
305
|
+
if (!l.isInPreviewMode() || !t.id)
|
|
306
|
+
return () => {
|
|
307
|
+
};
|
|
308
|
+
const { id: e, field: n, path: s, mode: r = "inline" } = t;
|
|
309
|
+
if (r === "select") {
|
|
310
|
+
E(), i.classList.add("b10cks-preview");
|
|
311
|
+
const a = (c) => {
|
|
312
|
+
c.preventDefault(), c.stopPropagation(), s ? l.selectField(e, s) : l.selectItem(e);
|
|
313
|
+
};
|
|
314
|
+
return i.addEventListener("click", a), () => {
|
|
315
|
+
i.removeEventListener("click", a), i.classList.remove("b10cks-preview");
|
|
316
|
+
};
|
|
242
317
|
}
|
|
318
|
+
i.setAttribute("contenteditable", "true");
|
|
319
|
+
const o = (a) => {
|
|
320
|
+
const c = a.target.innerText;
|
|
321
|
+
s ? l.updateFieldAt(e, s, c) : l.updateField(e, n ?? "", c);
|
|
322
|
+
};
|
|
323
|
+
return i.addEventListener("input", o), () => {
|
|
324
|
+
i.removeEventListener("input", o), i.removeAttribute("contenteditable");
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
function k(i) {
|
|
328
|
+
typeof i.scrollIntoView == "function" && i.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
329
|
+
}
|
|
330
|
+
function D(i, t) {
|
|
331
|
+
let e = i;
|
|
332
|
+
for (const n of t) {
|
|
333
|
+
if (e == null || typeof e != "object")
|
|
334
|
+
return;
|
|
335
|
+
e = e[n];
|
|
336
|
+
}
|
|
337
|
+
return e;
|
|
338
|
+
}
|
|
339
|
+
function m(i, t, e) {
|
|
340
|
+
if (t.length === 0)
|
|
341
|
+
return e;
|
|
342
|
+
const [n, ...s] = t;
|
|
343
|
+
if (n === void 0)
|
|
344
|
+
return e;
|
|
345
|
+
if (typeof n == "number") {
|
|
346
|
+
const o = Array.isArray(i) ? i.slice() : [];
|
|
347
|
+
return o[n] = m(o[n], s, e), o;
|
|
348
|
+
}
|
|
349
|
+
const r = i && typeof i == "object" && !Array.isArray(i) ? { ...i } : {};
|
|
350
|
+
return r[n] = m(r[n], s, e), r;
|
|
351
|
+
}
|
|
352
|
+
class I {
|
|
353
|
+
content;
|
|
354
|
+
listeners = /* @__PURE__ */ new Set();
|
|
355
|
+
constructor(t) {
|
|
356
|
+
this.content = t;
|
|
357
|
+
}
|
|
358
|
+
subscribe = (t) => (this.listeners.add(t), () => {
|
|
359
|
+
this.listeners.delete(t);
|
|
360
|
+
});
|
|
361
|
+
getSnapshot = () => this.content;
|
|
362
|
+
setContent(t) {
|
|
363
|
+
this.content = t, this.emit();
|
|
364
|
+
}
|
|
365
|
+
patch(t, e) {
|
|
366
|
+
this.content = m(this.content, t, e), this.emit();
|
|
367
|
+
}
|
|
368
|
+
emit() {
|
|
369
|
+
for (const t of this.listeners)
|
|
370
|
+
t();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
function U(i) {
|
|
374
|
+
const t = l.on("CONTENT_UPDATE", ({ content: n }) => {
|
|
375
|
+
i.setContent(n);
|
|
376
|
+
}), e = l.on("CONTENT_PATCH", ({ path: n, value: s }) => {
|
|
377
|
+
i.patch(n, s);
|
|
378
|
+
});
|
|
379
|
+
return () => {
|
|
380
|
+
t(), e();
|
|
381
|
+
};
|
|
243
382
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return (s ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
383
|
+
function w(i) {
|
|
384
|
+
return (i ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
247
385
|
}
|
|
248
|
-
function
|
|
249
|
-
const e =
|
|
386
|
+
function R(i, t) {
|
|
387
|
+
const e = w(i), n = w(t);
|
|
250
388
|
if (!n)
|
|
251
389
|
return e && e !== "home" ? `/${e}` : "/";
|
|
252
390
|
if (!e || e === "home")
|
|
253
391
|
return `/${n}`;
|
|
254
|
-
const
|
|
255
|
-
return e === n || e.startsWith(
|
|
392
|
+
const s = `${n}/`;
|
|
393
|
+
return e === n || e.startsWith(s) ? `/${e}` : `/${n}/${e}`;
|
|
256
394
|
}
|
|
257
|
-
function
|
|
395
|
+
function b(i, t) {
|
|
258
396
|
if (!t) return null;
|
|
259
397
|
try {
|
|
260
|
-
return new URL(
|
|
398
|
+
return new URL(i, t).toString();
|
|
261
399
|
} catch {
|
|
262
400
|
return null;
|
|
263
401
|
}
|
|
264
402
|
}
|
|
265
|
-
function
|
|
266
|
-
return
|
|
403
|
+
function y(i) {
|
|
404
|
+
return i.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
267
405
|
}
|
|
268
|
-
function
|
|
269
|
-
const { siteUrl: e, locale: n } = t,
|
|
270
|
-
return
|
|
406
|
+
function x(i, t = {}) {
|
|
407
|
+
const { siteUrl: e, locale: n } = t, s = /* @__PURE__ */ new Set();
|
|
408
|
+
return i.filter((r) => {
|
|
271
409
|
if (n && r.language_iso !== n || r.meta?.robots?.toLowerCase().includes("noindex")) return !1;
|
|
272
|
-
const
|
|
273
|
-
return
|
|
410
|
+
const o = R(r.full_slug, r.language_iso), a = e ? b(o, e) ?? o : o;
|
|
411
|
+
return s.has(a) ? !1 : (s.add(a), !0);
|
|
274
412
|
});
|
|
275
413
|
}
|
|
276
|
-
function
|
|
414
|
+
function z(i, t) {
|
|
277
415
|
return [
|
|
278
416
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
279
417
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
280
|
-
|
|
281
|
-
const
|
|
418
|
+
i.map((n) => {
|
|
419
|
+
const s = R(n.full_slug, n.language_iso), r = t ? b(s, t) : s;
|
|
282
420
|
if (!r) return "";
|
|
283
|
-
const
|
|
284
|
-
return n.published_at &&
|
|
421
|
+
const o = [" <url>", ` <loc>${y(r)}</loc>`];
|
|
422
|
+
return n.published_at && o.push(` <lastmod>${y(n.published_at)}</lastmod>`), o.push(" </url>"), o.join(`
|
|
285
423
|
`);
|
|
286
424
|
}).filter(Boolean).join(`
|
|
287
425
|
`),
|
|
@@ -289,13 +427,13 @@ function P(s, t) {
|
|
|
289
427
|
].join(`
|
|
290
428
|
`);
|
|
291
429
|
}
|
|
292
|
-
function
|
|
430
|
+
function M(i, t) {
|
|
293
431
|
return [
|
|
294
432
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
295
433
|
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
return
|
|
434
|
+
i.map((n) => {
|
|
435
|
+
const s = t ? b(n, t) : n;
|
|
436
|
+
return s ? [" <sitemap>", ` <loc>${y(s)}</loc>`, " </sitemap>"].join(`
|
|
299
437
|
`) : "";
|
|
300
438
|
}).filter(Boolean).join(`
|
|
301
439
|
`),
|
|
@@ -303,17 +441,23 @@ function F(s, t) {
|
|
|
303
441
|
].join(`
|
|
304
442
|
`);
|
|
305
443
|
}
|
|
306
|
-
const
|
|
444
|
+
const N = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
307
445
|
__proto__: null
|
|
308
446
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
309
|
-
|
|
310
|
-
class E {
|
|
447
|
+
class V {
|
|
311
448
|
baseUrl;
|
|
312
449
|
token;
|
|
313
450
|
vid;
|
|
314
451
|
fetchClient;
|
|
315
452
|
getRvFn;
|
|
316
453
|
setRvFn;
|
|
454
|
+
/**
|
|
455
|
+
* Per-instance revision store, used when no `getRv`/`setRv` callbacks are
|
|
456
|
+
* supplied. Kept on the instance (not module scope) so concurrent requests
|
|
457
|
+
* in a server runtime cannot leak revisions into one another. Server callers
|
|
458
|
+
* that need request-scoped persistence should pass `getRv`/`setRv`.
|
|
459
|
+
*/
|
|
460
|
+
rvValue = 0;
|
|
317
461
|
constructor(t, e) {
|
|
318
462
|
this.baseUrl = t.baseUrl.endsWith("/") ? t.baseUrl.slice(0, -1) : t.baseUrl, this.token = t.token;
|
|
319
463
|
const n = typeof globalThis.fetch == "function" ? globalThis.fetch.bind(globalThis) : null;
|
|
@@ -326,8 +470,8 @@ class E {
|
|
|
326
470
|
"No fetch implementation available. Provide `fetchClient` in ApiClient options."
|
|
327
471
|
);
|
|
328
472
|
this.getRvFn = t.getRv, this.setRvFn = t.setRv;
|
|
329
|
-
const
|
|
330
|
-
this.vid = t.version || "published", this.setRv(
|
|
473
|
+
const s = this.resolveRequestUrl(e);
|
|
474
|
+
this.vid = t.version || "published", this.setRv(s?.searchParams.get("b10cks_rv") || t.rv || 0);
|
|
331
475
|
}
|
|
332
476
|
async get(t, e = {}) {
|
|
333
477
|
const n = this.buildUrl(t, {
|
|
@@ -335,16 +479,16 @@ class E {
|
|
|
335
479
|
rv: this.getRv(),
|
|
336
480
|
...e,
|
|
337
481
|
token: this.token
|
|
338
|
-
}),
|
|
482
|
+
}), s = await this.fetchClient(n), r = await this.parseResponse(s);
|
|
339
483
|
return this.hasRevision(r) && this.setRv(r.rv), r;
|
|
340
484
|
}
|
|
341
485
|
async post(t, e, n = {}) {
|
|
342
|
-
const
|
|
486
|
+
const s = this.buildUrl(t, {
|
|
343
487
|
vid: this.vid,
|
|
344
488
|
rv: this.getRv(),
|
|
345
489
|
...n,
|
|
346
490
|
token: this.token
|
|
347
|
-
}), r = await this.fetchClient(
|
|
491
|
+
}), r = await this.fetchClient(s, {
|
|
348
492
|
method: "POST",
|
|
349
493
|
headers: { "Content-Type": "application/json" },
|
|
350
494
|
body: e !== void 0 ? JSON.stringify(e) : void 0
|
|
@@ -355,22 +499,22 @@ class E {
|
|
|
355
499
|
const n = await this.get(t, {
|
|
356
500
|
...e,
|
|
357
501
|
page: 1
|
|
358
|
-
}),
|
|
359
|
-
if (
|
|
360
|
-
return
|
|
502
|
+
}), s = this.normalizeCollectionResponse(n);
|
|
503
|
+
if (s.rv && this.setRv(s.rv), !s.meta || s.meta.last_page <= 1)
|
|
504
|
+
return s.data;
|
|
361
505
|
const r = Array.from(
|
|
362
|
-
{ length:
|
|
363
|
-
(
|
|
364
|
-
),
|
|
365
|
-
return
|
|
366
|
-
|
|
506
|
+
{ length: s.meta.last_page - 1 },
|
|
507
|
+
(a, c) => this.get(t, { ...e, page: c + 2 })
|
|
508
|
+
), o = await Promise.all(r);
|
|
509
|
+
return s.data.concat(
|
|
510
|
+
o.flatMap((a) => this.normalizeCollectionResponse(a).data)
|
|
367
511
|
);
|
|
368
512
|
}
|
|
369
513
|
setRv(t) {
|
|
370
|
-
this.setRvFn ? this.setRvFn(t) :
|
|
514
|
+
this.setRvFn ? this.setRvFn(t) : this.rvValue = t;
|
|
371
515
|
}
|
|
372
516
|
getRv() {
|
|
373
|
-
return this.getRvFn ? this.getRvFn() :
|
|
517
|
+
return this.getRvFn ? this.getRvFn() : this.rvValue;
|
|
374
518
|
}
|
|
375
519
|
async parseResponse(t) {
|
|
376
520
|
if (this.isFetchResponse(t)) {
|
|
@@ -395,16 +539,16 @@ class E {
|
|
|
395
539
|
const {
|
|
396
540
|
data: e,
|
|
397
541
|
meta: n,
|
|
398
|
-
rv:
|
|
542
|
+
rv: s
|
|
399
543
|
} = t;
|
|
400
|
-
return { data: e, meta: n, rv:
|
|
544
|
+
return { data: e, meta: n, rv: s };
|
|
401
545
|
}
|
|
402
546
|
return { data: [], meta: void 0, rv: void 0 };
|
|
403
547
|
}
|
|
404
548
|
buildUrl(t, e) {
|
|
405
549
|
const n = new URL(`${this.baseUrl}/v1/${t}`);
|
|
406
|
-
return Object.entries(e).forEach(([
|
|
407
|
-
r != null && n.searchParams.append(
|
|
550
|
+
return Object.entries(e).forEach(([s, r]) => {
|
|
551
|
+
r != null && n.searchParams.append(s, String(r));
|
|
408
552
|
}), n.toString();
|
|
409
553
|
}
|
|
410
554
|
resolveRequestUrl(t) {
|
|
@@ -421,18 +565,26 @@ class E {
|
|
|
421
565
|
}
|
|
422
566
|
}
|
|
423
567
|
export {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
568
|
+
V as ApiClient,
|
|
569
|
+
P as B10cksDataApi,
|
|
570
|
+
h as PreviewBridge,
|
|
571
|
+
I as PreviewStore,
|
|
572
|
+
O as attachEditable,
|
|
573
|
+
$ as attachEditableField,
|
|
574
|
+
U as bindPreviewStore,
|
|
575
|
+
R as buildLocalizedPath,
|
|
576
|
+
L as createB10cksDataApi,
|
|
577
|
+
E as ensurePreviewStyles,
|
|
578
|
+
x as filterSitemapEntries,
|
|
579
|
+
D as getAtPath,
|
|
580
|
+
w as normalizePathSegment,
|
|
581
|
+
l as previewBridge,
|
|
582
|
+
M as renderSitemapIndex,
|
|
583
|
+
z as renderSitemapXml,
|
|
584
|
+
_ as resolveB10cksLink,
|
|
585
|
+
S as serializeFilter,
|
|
586
|
+
m as setAtPath,
|
|
587
|
+
F as setPreviewScrollOffset,
|
|
588
|
+
N as types
|
|
437
589
|
};
|
|
438
590
|
//# sourceMappingURL=index.mjs.map
|