@b10cks/client 1.5.0 → 1.6.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 +23 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +46 -1
- package/dist/index.mjs +613 -560
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -7
- package/dist/index.js +0 -19
- package/dist/index.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,267 +1,295 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var e = Object.defineProperty, t = (t, n) => {
|
|
3
|
+
let r = {};
|
|
4
|
+
for (var i in t) e(r, i, {
|
|
5
|
+
get: t[i],
|
|
6
|
+
enumerable: !0
|
|
7
|
+
});
|
|
8
|
+
return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/content.ts
|
|
12
|
+
function n(e) {
|
|
13
|
+
if (!e) return;
|
|
14
|
+
if (e.type === "email") {
|
|
15
|
+
let t = new URLSearchParams();
|
|
16
|
+
e.subject && t.set("subject", e.subject), e.body && t.set("body", e.body), e.cc && t.set("cc", e.cc), e.bcc && t.set("bcc", e.bcc);
|
|
17
|
+
let n = t.toString();
|
|
18
|
+
return {
|
|
19
|
+
href: `mailto:${e.email}${n ? `?${n}` : ""}`,
|
|
20
|
+
target: "_self"
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (e.type === "asset") return;
|
|
24
|
+
let t = e.target ?? "_self", n = e.url ?? "";
|
|
25
|
+
return "anchor" in e && e.anchor && (n = `${n.trimEnd()}#${e.anchor}`), {
|
|
26
|
+
href: n,
|
|
27
|
+
target: t
|
|
28
|
+
};
|
|
14
29
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/data-api.ts
|
|
32
|
+
function r(e) {
|
|
33
|
+
if (e != null) {
|
|
34
|
+
if (typeof e == "boolean" || typeof e == "number") return String(e);
|
|
35
|
+
if (typeof e == "string") return e;
|
|
36
|
+
if (typeof e == "object" && !Array.isArray(e)) {
|
|
37
|
+
let t = e;
|
|
38
|
+
if ("null" in t) return "null:";
|
|
39
|
+
if ("!null" in t) return "!null:";
|
|
40
|
+
if ("between" in t) {
|
|
41
|
+
let e = t.between;
|
|
42
|
+
if (!Array.isArray(e) || e.length !== 2) return;
|
|
43
|
+
let [n, r] = e;
|
|
44
|
+
return `${n}...${r}`;
|
|
45
|
+
}
|
|
46
|
+
for (let e of [
|
|
47
|
+
"eq",
|
|
48
|
+
"neq",
|
|
49
|
+
"like",
|
|
50
|
+
"!like",
|
|
51
|
+
"^like",
|
|
52
|
+
"like$",
|
|
53
|
+
"lt",
|
|
54
|
+
"gt",
|
|
55
|
+
"lte",
|
|
56
|
+
"gte",
|
|
57
|
+
"in",
|
|
58
|
+
"!in",
|
|
59
|
+
"empty",
|
|
60
|
+
"!empty"
|
|
61
|
+
]) if (e in t) {
|
|
62
|
+
let n = t[e];
|
|
63
|
+
return Array.isArray(n) ? `${e}:${n.join(",")}` : `${e}:${String(n)}`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
50
67
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
68
|
+
function i(e) {
|
|
69
|
+
let t = {};
|
|
70
|
+
for (let [n, i] of Object.entries(e)) {
|
|
71
|
+
let e = r(i);
|
|
72
|
+
e !== void 0 && (t[n] = e);
|
|
73
|
+
}
|
|
74
|
+
return t;
|
|
58
75
|
}
|
|
59
|
-
function
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
function a(e, t, n) {
|
|
77
|
+
let r = t && typeof t == "object" ? i(t) : {}, a = Array.isArray(n) ? { sort: n.join(",") } : n == null ? {} : { sort: n };
|
|
78
|
+
return {
|
|
79
|
+
...e,
|
|
80
|
+
...r,
|
|
81
|
+
...a
|
|
82
|
+
};
|
|
62
83
|
}
|
|
63
|
-
class
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
"HOVER_UPDATE",
|
|
189
|
-
"FIELD_UPDATE",
|
|
190
|
-
"FIELD_SELECT"
|
|
191
|
-
]), j = "B10CKS_BRIDGE_READY";
|
|
192
|
-
class h {
|
|
193
|
-
static instance;
|
|
194
|
-
listeners = {};
|
|
195
|
-
initialized = !1;
|
|
196
|
-
allowedOrigins = null;
|
|
197
|
-
/** Origin of the editor, captured from the first trusted message. */
|
|
198
|
-
parentOrigin = null;
|
|
199
|
-
constructor() {
|
|
200
|
-
}
|
|
201
|
-
static getInstance() {
|
|
202
|
-
return h.instance || (h.instance = new h()), h.instance;
|
|
203
|
-
}
|
|
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 }, "*"));
|
|
206
|
-
}
|
|
207
|
-
destroy() {
|
|
208
|
-
this.initialized && typeof window < "u" && window.removeEventListener("message", this.handleMessage), this.initialized = !1, this.parentOrigin = null;
|
|
209
|
-
for (const t of Object.keys(this.listeners))
|
|
210
|
-
this.listeners[t]?.clear();
|
|
211
|
-
}
|
|
212
|
-
isInPreviewMode() {
|
|
213
|
-
return typeof window < "u" && window.self !== window.top;
|
|
214
|
-
}
|
|
215
|
-
on(t, e) {
|
|
216
|
-
if (!this.isInPreviewMode())
|
|
217
|
-
return () => {
|
|
218
|
-
};
|
|
219
|
-
const n = this.listeners[t] || /* @__PURE__ */ new Set();
|
|
220
|
-
return this.listeners[t] = n, n.add(e), () => {
|
|
221
|
-
n.delete(e);
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
selectItem(t) {
|
|
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 });
|
|
230
|
-
}
|
|
231
|
-
/** @deprecated Prefer {@link updateFieldAt} with a path. */
|
|
232
|
-
updateField(t, e, n) {
|
|
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 ?? "*");
|
|
241
|
-
}
|
|
242
|
-
handleMessage = (t) => {
|
|
243
|
-
if (!this.isOriginTrusted(t.origin) || !t.data || typeof t.data != "object")
|
|
244
|
-
return;
|
|
245
|
-
const { type: e, payload: n } = t.data;
|
|
246
|
-
!e || !T.has(e) || !n || (!this.parentOrigin && t.origin && t.origin !== "null" && (this.parentOrigin = t.origin), this.notify(e, n));
|
|
247
|
-
};
|
|
248
|
-
isOriginTrusted(t) {
|
|
249
|
-
return this.parentOrigin ? t === this.parentOrigin : this.allowedOrigins ? this.allowedOrigins.includes(t) : !0;
|
|
250
|
-
}
|
|
251
|
-
notify(t, e) {
|
|
252
|
-
const n = this.listeners[t];
|
|
253
|
-
if (n)
|
|
254
|
-
for (const s of n)
|
|
255
|
-
s(e);
|
|
256
|
-
}
|
|
84
|
+
var o = 128, s = class {
|
|
85
|
+
client;
|
|
86
|
+
redirectsCache = /* @__PURE__ */ new Map();
|
|
87
|
+
configCache = /* @__PURE__ */ new Map();
|
|
88
|
+
configInflight = /* @__PURE__ */ new Map();
|
|
89
|
+
constructor(e) {
|
|
90
|
+
this.client = e;
|
|
91
|
+
}
|
|
92
|
+
async getResource(e, t = {}) {
|
|
93
|
+
let n = await this.client.get(e, t);
|
|
94
|
+
return this.unwrapResource(n);
|
|
95
|
+
}
|
|
96
|
+
async getCollection(e, t = {}, n = {}) {
|
|
97
|
+
if (n.allPages) return this.client.getAll(e, t);
|
|
98
|
+
let r = await this.client.get(e, t);
|
|
99
|
+
return this.unwrapCollection(r);
|
|
100
|
+
}
|
|
101
|
+
async getContent(e, t = {}) {
|
|
102
|
+
return this.getResource(`contents/${e}`, t);
|
|
103
|
+
}
|
|
104
|
+
async getContents(e = {}, t = {}) {
|
|
105
|
+
let { filter: n, sort: r, ...i } = e;
|
|
106
|
+
return this.getCollection("contents", a(i, n, r), t);
|
|
107
|
+
}
|
|
108
|
+
async getBlock(e, t = {}) {
|
|
109
|
+
return this.getResource(`blocks/${e}`, t);
|
|
110
|
+
}
|
|
111
|
+
async getBlocks(e = {}, t = {}) {
|
|
112
|
+
let { filter: n, ...r } = e;
|
|
113
|
+
return this.getCollection("blocks", a(r, n, void 0), t);
|
|
114
|
+
}
|
|
115
|
+
async search(e) {
|
|
116
|
+
let t = await this.client.get("search", e);
|
|
117
|
+
if (typeof t == "object" && t && "data" in t && "meta" in t) return t;
|
|
118
|
+
if (typeof t == "object" && t && "data" in t) {
|
|
119
|
+
let e = t.data;
|
|
120
|
+
if (typeof e == "object" && e && "meta" in e && "data" in e) return e;
|
|
121
|
+
}
|
|
122
|
+
return t;
|
|
123
|
+
}
|
|
124
|
+
async getSitemap(e = {}, t = {}) {
|
|
125
|
+
return this.getCollection("sitemap", e, t);
|
|
126
|
+
}
|
|
127
|
+
async getDataEntries(e, t = {}, n = {}) {
|
|
128
|
+
return this.getCollection(`datasources/${e}/entries`, t, n);
|
|
129
|
+
}
|
|
130
|
+
async getDataSources(e = {}, t = {}) {
|
|
131
|
+
return this.getCollection("datasources", e, t);
|
|
132
|
+
}
|
|
133
|
+
async getSpace(e = {}) {
|
|
134
|
+
return this.getResource("spaces/me", e);
|
|
135
|
+
}
|
|
136
|
+
async lookupRedirect(e) {
|
|
137
|
+
if (!this.client.post) throw Error("lookupRedirect requires a client that supports POST. Use ApiClient from @b10cks/client.");
|
|
138
|
+
return this.client.post("redirects/lookup", { source: e });
|
|
139
|
+
}
|
|
140
|
+
async getRedirects(e = {}, t = !1) {
|
|
141
|
+
let { allPages: n = !1, forceRefresh: r = !1 } = typeof t == "boolean" ? {
|
|
142
|
+
allPages: !0,
|
|
143
|
+
forceRefresh: t
|
|
144
|
+
} : t, i = JSON.stringify({
|
|
145
|
+
params: e,
|
|
146
|
+
rv: this.currentRv()
|
|
147
|
+
});
|
|
148
|
+
if (n && !r) {
|
|
149
|
+
let e = this.redirectsCache.get(i);
|
|
150
|
+
if (e) return e;
|
|
151
|
+
}
|
|
152
|
+
let { filter: o, ...s } = e, c = a(s, o, void 0), l = await this.getCollection("redirects", c, { allPages: n }), u = Object.fromEntries(l.map(({ source: e, target: t, status_code: n }) => [e, {
|
|
153
|
+
target: t,
|
|
154
|
+
status_code: n
|
|
155
|
+
}]));
|
|
156
|
+
return n && this.redirectsCache.set(i, u), u;
|
|
157
|
+
}
|
|
158
|
+
currentRv() {
|
|
159
|
+
return typeof this.client.getRv == "function" ? this.client.getRv() : "";
|
|
160
|
+
}
|
|
161
|
+
async getConfig({ slug: e = "_config", language_iso: t, language: n, bypassCache: r = !1, ...i } = {}) {
|
|
162
|
+
let a = t ?? n, o = JSON.stringify({
|
|
163
|
+
slug: e,
|
|
164
|
+
language_iso: a,
|
|
165
|
+
rv: this.currentRv(),
|
|
166
|
+
...i
|
|
167
|
+
});
|
|
168
|
+
if (!r && this.configCache.has(o)) return this.configCache.get(o);
|
|
169
|
+
let s = this.configInflight.get(o);
|
|
170
|
+
if (!r && s) return s;
|
|
171
|
+
let c = this.getContent(e, {
|
|
172
|
+
...i,
|
|
173
|
+
language_iso: a
|
|
174
|
+
}).then((e) => {
|
|
175
|
+
let t = e.content ?? {};
|
|
176
|
+
return r || this.setConfigCache(o, t), t;
|
|
177
|
+
}).finally(() => {
|
|
178
|
+
this.configInflight.delete(o);
|
|
179
|
+
});
|
|
180
|
+
return r || this.configInflight.set(o, c), c;
|
|
181
|
+
}
|
|
182
|
+
setConfigCache(e, t) {
|
|
183
|
+
if (this.configCache.delete(e), this.configCache.set(e, t), this.configCache.size > o) {
|
|
184
|
+
let e = this.configCache.keys().next().value;
|
|
185
|
+
e !== void 0 && this.configCache.delete(e);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async syncRevision(e = 426713400) {
|
|
189
|
+
let t = (await this.getSpace()).rv || e;
|
|
190
|
+
return this.client.setRv(t), t;
|
|
191
|
+
}
|
|
192
|
+
clearCache() {
|
|
193
|
+
this.redirectsCache.clear(), this.configCache.clear(), this.configInflight.clear();
|
|
194
|
+
}
|
|
195
|
+
unwrapResource(e) {
|
|
196
|
+
return typeof e == "object" && e && "data" in e ? e.data : e;
|
|
197
|
+
}
|
|
198
|
+
unwrapCollection(e) {
|
|
199
|
+
if (Array.isArray(e)) return e;
|
|
200
|
+
if (typeof e == "object" && e && "data" in e) {
|
|
201
|
+
if (Array.isArray(e.data)) return e.data;
|
|
202
|
+
if (typeof e.data == "object" && e.data !== null && "data" in e.data && Array.isArray(e.data.data)) return e.data.data;
|
|
203
|
+
}
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
function c(e) {
|
|
208
|
+
return new s(e);
|
|
257
209
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
210
|
+
//#endregion
|
|
211
|
+
//#region src/preview-bridge.ts
|
|
212
|
+
var l = /* @__PURE__ */ new Set([
|
|
213
|
+
"CONTENT_UPDATE",
|
|
214
|
+
"CONTENT_PATCH",
|
|
215
|
+
"SELECT_UPDATE",
|
|
216
|
+
"HOVER_UPDATE",
|
|
217
|
+
"FIELD_UPDATE",
|
|
218
|
+
"FIELD_SELECT"
|
|
219
|
+
]), u = "B10CKS_BRIDGE_READY", d = class e {
|
|
220
|
+
static instance;
|
|
221
|
+
listeners = {};
|
|
222
|
+
initialized = !1;
|
|
223
|
+
allowedOrigins = null;
|
|
224
|
+
parentOrigin = null;
|
|
225
|
+
constructor() {}
|
|
226
|
+
static getInstance() {
|
|
227
|
+
return e.instance ||= new e(), e.instance;
|
|
228
|
+
}
|
|
229
|
+
init(e = {}) {
|
|
230
|
+
!this.isInPreviewMode() || this.initialized || (this.allowedOrigins = e.allowedOrigins ?? null, window.addEventListener("message", this.handleMessage), this.initialized = !0, window.parent.postMessage({ type: u }, "*"));
|
|
231
|
+
}
|
|
232
|
+
destroy() {
|
|
233
|
+
this.initialized && typeof window < "u" && window.removeEventListener("message", this.handleMessage), this.initialized = !1, this.parentOrigin = null;
|
|
234
|
+
for (let e of Object.keys(this.listeners)) this.listeners[e]?.clear();
|
|
235
|
+
}
|
|
236
|
+
isInPreviewMode() {
|
|
237
|
+
return typeof window < "u" && window.self !== window.top;
|
|
238
|
+
}
|
|
239
|
+
on(e, t) {
|
|
240
|
+
if (!this.isInPreviewMode()) return () => {};
|
|
241
|
+
let n = this.listeners[e] || /* @__PURE__ */ new Set();
|
|
242
|
+
return this.listeners[e] = n, n.add(t), () => {
|
|
243
|
+
n.delete(t);
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
selectItem(e) {
|
|
247
|
+
this.post("SELECT_UPDATE", { selectedItem: e });
|
|
248
|
+
}
|
|
249
|
+
selectField(e, t) {
|
|
250
|
+
this.post("FIELD_SELECT", {
|
|
251
|
+
itemId: e,
|
|
252
|
+
path: t
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
updateField(e, t, n) {
|
|
256
|
+
this.post("FIELD_UPDATE", {
|
|
257
|
+
itemId: e,
|
|
258
|
+
field: t,
|
|
259
|
+
value: n
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
updateFieldAt(e, t, n) {
|
|
263
|
+
this.post("FIELD_UPDATE", {
|
|
264
|
+
itemId: e,
|
|
265
|
+
path: t,
|
|
266
|
+
value: n
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
post(e, t) {
|
|
270
|
+
this.isInPreviewMode() && window.parent.postMessage({
|
|
271
|
+
type: e,
|
|
272
|
+
payload: t
|
|
273
|
+
}, this.parentOrigin ?? "*");
|
|
274
|
+
}
|
|
275
|
+
handleMessage = (e) => {
|
|
276
|
+
if (!this.isOriginTrusted(e.origin) || !e.data || typeof e.data != "object") return;
|
|
277
|
+
let { type: t, payload: n } = e.data;
|
|
278
|
+
!t || !l.has(t) || !n || (!this.parentOrigin && e.origin && e.origin !== "null" && (this.parentOrigin = e.origin), this.notify(t, n));
|
|
279
|
+
};
|
|
280
|
+
isOriginTrusted(e) {
|
|
281
|
+
return this.parentOrigin ? e === this.parentOrigin : this.allowedOrigins ? this.allowedOrigins.includes(e) : !0;
|
|
282
|
+
}
|
|
283
|
+
notify(e, t) {
|
|
284
|
+
let n = this.listeners[e];
|
|
285
|
+
if (n) for (let e of n) e(t);
|
|
286
|
+
}
|
|
287
|
+
}, f = d.getInstance(), p = "b10cks-preview-style", m = "--b10cks-scroll-offset";
|
|
288
|
+
function h() {
|
|
289
|
+
if (typeof document > "u" || document.getElementById(p)) return;
|
|
290
|
+
let e = document.createElement("style");
|
|
291
|
+
e.id = p, e.textContent = `
|
|
292
|
+
.b10cks-preview { scroll-margin-top: var(${m}, 0px); }
|
|
265
293
|
.b10cks-hover,
|
|
266
294
|
.b10cks-preview:hover {
|
|
267
295
|
outline: 2px dashed rgba(59, 130, 246, 0.5);
|
|
@@ -271,320 +299,345 @@ function E() {
|
|
|
271
299
|
outline: 2px solid rgb(59, 130, 246) !important;
|
|
272
300
|
outline-offset: 2px;
|
|
273
301
|
}
|
|
274
|
-
`, document.head.appendChild(
|
|
302
|
+
`, document.head.appendChild(e);
|
|
275
303
|
}
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
document.documentElement.style.setProperty(C, t);
|
|
304
|
+
function g(e) {
|
|
305
|
+
if (typeof document > "u") return;
|
|
306
|
+
let t = typeof e == "number" ? `${e}px` : e;
|
|
307
|
+
document.documentElement.style.setProperty(m, t);
|
|
281
308
|
}
|
|
282
|
-
function
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
i.removeEventListener("click", o), d(), p(), i.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
302
|
-
};
|
|
309
|
+
function _(e, t) {
|
|
310
|
+
if (!f.isInPreviewMode() || !t.id) return () => {};
|
|
311
|
+
h();
|
|
312
|
+
let { id: n, onSelectChange: r, onHoverChange: i, scrollOnSelect: a = !0 } = t;
|
|
313
|
+
e.classList.add("b10cks-preview");
|
|
314
|
+
let o = (e) => {
|
|
315
|
+
e.preventDefault(), e.stopPropagation(), f.selectItem(n);
|
|
316
|
+
}, s = ({ selectedItem: t }) => {
|
|
317
|
+
let i = t === n;
|
|
318
|
+
e.classList.toggle("b10cks-selected", i), i && a && y(e), r?.(i);
|
|
319
|
+
}, c = ({ selectedItem: t }) => {
|
|
320
|
+
let r = t === n;
|
|
321
|
+
e.classList.toggle("b10cks-hover", r), i?.(r);
|
|
322
|
+
};
|
|
323
|
+
e.addEventListener("click", o);
|
|
324
|
+
let l = f.on("SELECT_UPDATE", s), u = f.on("HOVER_UPDATE", c);
|
|
325
|
+
return () => {
|
|
326
|
+
e.removeEventListener("click", o), l(), u(), e.classList.remove("b10cks-preview", "b10cks-selected", "b10cks-hover");
|
|
327
|
+
};
|
|
303
328
|
}
|
|
304
|
-
function
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
i.removeEventListener("input", o), i.removeAttribute("contenteditable");
|
|
325
|
-
};
|
|
329
|
+
function v(e, t) {
|
|
330
|
+
if (!f.isInPreviewMode() || !t.id) return () => {};
|
|
331
|
+
let { id: n, field: r, path: i, mode: a = "inline" } = t;
|
|
332
|
+
if (a === "select") {
|
|
333
|
+
h(), e.classList.add("b10cks-preview");
|
|
334
|
+
let t = (e) => {
|
|
335
|
+
e.preventDefault(), e.stopPropagation(), i ? f.selectField(n, i) : f.selectItem(n);
|
|
336
|
+
};
|
|
337
|
+
return e.addEventListener("click", t), () => {
|
|
338
|
+
e.removeEventListener("click", t), e.classList.remove("b10cks-preview");
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
e.setAttribute("contenteditable", "true");
|
|
342
|
+
let o = (e) => {
|
|
343
|
+
let t = e.target.innerText;
|
|
344
|
+
i ? f.updateFieldAt(n, i, t) : f.updateField(n, r ?? "", t);
|
|
345
|
+
};
|
|
346
|
+
return e.addEventListener("input", o), () => {
|
|
347
|
+
e.removeEventListener("input", o), e.removeAttribute("contenteditable");
|
|
348
|
+
};
|
|
326
349
|
}
|
|
327
|
-
function
|
|
328
|
-
|
|
350
|
+
function y(e) {
|
|
351
|
+
typeof e.scrollIntoView == "function" && e.scrollIntoView({
|
|
352
|
+
block: "nearest",
|
|
353
|
+
behavior: "smooth"
|
|
354
|
+
});
|
|
329
355
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/preview-store.ts
|
|
358
|
+
function b(e, t) {
|
|
359
|
+
let n = e;
|
|
360
|
+
for (let e of t) {
|
|
361
|
+
if (typeof n != "object" || !n) return;
|
|
362
|
+
n = n[e];
|
|
363
|
+
}
|
|
364
|
+
return n;
|
|
338
365
|
}
|
|
339
|
-
function
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const r = i && typeof i == "object" && !Array.isArray(i) ? { ...i } : {};
|
|
350
|
-
return r[n] = m(r[n], s, e), r;
|
|
366
|
+
function x(e, t, n) {
|
|
367
|
+
if (t.length === 0) return n;
|
|
368
|
+
let [r, ...i] = t;
|
|
369
|
+
if (r === void 0) return n;
|
|
370
|
+
if (typeof r == "number") {
|
|
371
|
+
let t = Array.isArray(e) ? e.slice() : [];
|
|
372
|
+
return t[r] = x(t[r], i, n), t;
|
|
373
|
+
}
|
|
374
|
+
let a = e && typeof e == "object" && !Array.isArray(e) ? { ...e } : {};
|
|
375
|
+
return a[r] = x(a[r], i, n), a;
|
|
351
376
|
}
|
|
352
|
-
class
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
function w(i) {
|
|
384
|
-
return (i ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
377
|
+
var S = class {
|
|
378
|
+
content;
|
|
379
|
+
listeners = /* @__PURE__ */ new Set();
|
|
380
|
+
constructor(e) {
|
|
381
|
+
this.content = e;
|
|
382
|
+
}
|
|
383
|
+
subscribe = (e) => (this.listeners.add(e), () => {
|
|
384
|
+
this.listeners.delete(e);
|
|
385
|
+
});
|
|
386
|
+
getSnapshot = () => this.content;
|
|
387
|
+
setContent(e) {
|
|
388
|
+
this.content = e, this.emit();
|
|
389
|
+
}
|
|
390
|
+
patch(e, t) {
|
|
391
|
+
this.content = x(this.content, e, t), this.emit();
|
|
392
|
+
}
|
|
393
|
+
emit() {
|
|
394
|
+
for (let e of this.listeners) e();
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
function C(e) {
|
|
398
|
+
let t = f.on("CONTENT_UPDATE", ({ content: t }) => {
|
|
399
|
+
e.setContent(t);
|
|
400
|
+
}), n = f.on("CONTENT_PATCH", ({ path: t, value: n }) => {
|
|
401
|
+
e.patch(t, n);
|
|
402
|
+
});
|
|
403
|
+
return () => {
|
|
404
|
+
t(), n();
|
|
405
|
+
};
|
|
385
406
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
if (!e || e === "home")
|
|
391
|
-
return `/${n}`;
|
|
392
|
-
const s = `${n}/`;
|
|
393
|
-
return e === n || e.startsWith(s) ? `/${e}` : `/${n}/${e}`;
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/sitemap.ts
|
|
409
|
+
function w(e) {
|
|
410
|
+
return (e ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
394
411
|
}
|
|
395
|
-
function
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
412
|
+
function T(e, t) {
|
|
413
|
+
let n = w(e), r = w(t);
|
|
414
|
+
if (!r) return n && n !== "home" ? `/${n}` : "/";
|
|
415
|
+
if (!n || n === "home") return `/${r}`;
|
|
416
|
+
let i = `${r}/`;
|
|
417
|
+
return n === r || n.startsWith(i) ? `/${n}` : `/${r}/${n}`;
|
|
402
418
|
}
|
|
403
|
-
function
|
|
404
|
-
|
|
419
|
+
function E(e, t) {
|
|
420
|
+
if (!t) return null;
|
|
421
|
+
try {
|
|
422
|
+
return new URL(e, t).toString();
|
|
423
|
+
} catch {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
405
426
|
}
|
|
406
|
-
function
|
|
407
|
-
|
|
408
|
-
return i.filter((r) => {
|
|
409
|
-
if (n && r.language_iso !== n || r.meta?.robots?.toLowerCase().includes("noindex")) return !1;
|
|
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);
|
|
412
|
-
});
|
|
427
|
+
function D(e) {
|
|
428
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
413
429
|
}
|
|
414
|
-
function
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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(`
|
|
423
|
-
`);
|
|
424
|
-
}).filter(Boolean).join(`
|
|
425
|
-
`),
|
|
426
|
-
"</urlset>"
|
|
427
|
-
].join(`
|
|
428
|
-
`);
|
|
430
|
+
function O(e, t = {}) {
|
|
431
|
+
let { siteUrl: n, locale: r } = t, i = /* @__PURE__ */ new Set();
|
|
432
|
+
return e.filter((e) => {
|
|
433
|
+
if (r && e.language_iso !== r || e.meta?.robots?.toLowerCase().includes("noindex")) return !1;
|
|
434
|
+
let t = T(e.full_slug, e.language_iso), a = n ? E(t, n) ?? t : t;
|
|
435
|
+
return i.has(a) ? !1 : (i.add(a), !0);
|
|
436
|
+
});
|
|
429
437
|
}
|
|
430
|
-
function
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}).
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
`);
|
|
438
|
+
function k(e, t) {
|
|
439
|
+
return [
|
|
440
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
441
|
+
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
442
|
+
e.map((e) => {
|
|
443
|
+
let n = T(e.full_slug, e.language_iso), r = t ? E(n, t) : n;
|
|
444
|
+
if (!r) return "";
|
|
445
|
+
let i = [" <url>", ` <loc>${D(r)}</loc>`];
|
|
446
|
+
return e.published_at && i.push(` <lastmod>${D(e.published_at)}</lastmod>`), i.push(" </url>"), i.join("\n");
|
|
447
|
+
}).filter(Boolean).join("\n"),
|
|
448
|
+
"</urlset>"
|
|
449
|
+
].join("\n");
|
|
443
450
|
}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
* that need request-scoped persistence should pass `getRv`/`setRv`.
|
|
459
|
-
*/
|
|
460
|
-
rvValue = 0;
|
|
461
|
-
constructor(t, e) {
|
|
462
|
-
this.baseUrl = t.baseUrl.endsWith("/") ? t.baseUrl.slice(0, -1) : t.baseUrl, this.token = t.token;
|
|
463
|
-
const n = typeof globalThis.fetch == "function" ? globalThis.fetch.bind(globalThis) : null;
|
|
464
|
-
if (t.fetchClient)
|
|
465
|
-
this.fetchClient = t.fetchClient;
|
|
466
|
-
else if (n)
|
|
467
|
-
this.fetchClient = n;
|
|
468
|
-
else
|
|
469
|
-
throw new Error(
|
|
470
|
-
"No fetch implementation available. Provide `fetchClient` in ApiClient options."
|
|
471
|
-
);
|
|
472
|
-
this.getRvFn = t.getRv, this.setRvFn = t.setRv;
|
|
473
|
-
const s = this.resolveRequestUrl(e);
|
|
474
|
-
this.vid = t.version || "published", this.setRv(s?.searchParams.get("b10cks_rv") || t.rv || 0);
|
|
475
|
-
}
|
|
476
|
-
async get(t, e = {}) {
|
|
477
|
-
const n = this.buildUrl(t, {
|
|
478
|
-
vid: this.vid,
|
|
479
|
-
rv: this.getRv(),
|
|
480
|
-
...e,
|
|
481
|
-
token: this.token
|
|
482
|
-
}), s = await this.fetchClient(n), r = await this.parseResponse(s);
|
|
483
|
-
return this.hasRevision(r) && this.setRv(r.rv), r;
|
|
484
|
-
}
|
|
485
|
-
async post(t, e, n = {}) {
|
|
486
|
-
const s = this.buildUrl(t, {
|
|
487
|
-
vid: this.vid,
|
|
488
|
-
rv: this.getRv(),
|
|
489
|
-
...n,
|
|
490
|
-
token: this.token
|
|
491
|
-
}), r = await this.fetchClient(s, {
|
|
492
|
-
method: "POST",
|
|
493
|
-
headers: { "Content-Type": "application/json" },
|
|
494
|
-
body: e !== void 0 ? JSON.stringify(e) : void 0
|
|
495
|
-
});
|
|
496
|
-
return this.parseResponse(r);
|
|
497
|
-
}
|
|
498
|
-
async getAll(t, e = {}) {
|
|
499
|
-
const n = await this.get(t, {
|
|
500
|
-
...e,
|
|
501
|
-
page: 1
|
|
502
|
-
}), s = this.normalizeCollectionResponse(n);
|
|
503
|
-
if (s.rv && this.setRv(s.rv), !s.meta || s.meta.last_page <= 1)
|
|
504
|
-
return s.data;
|
|
505
|
-
const r = Array.from(
|
|
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)
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
setRv(t) {
|
|
514
|
-
this.setRvFn ? this.setRvFn(t) : this.rvValue = t;
|
|
515
|
-
}
|
|
516
|
-
getRv() {
|
|
517
|
-
return this.getRvFn ? this.getRvFn() : this.rvValue;
|
|
518
|
-
}
|
|
519
|
-
async parseResponse(t) {
|
|
520
|
-
if (this.isFetchResponse(t)) {
|
|
521
|
-
if (!t.ok)
|
|
522
|
-
throw new Error(`Request failed with status ${t.status}`);
|
|
523
|
-
return await t.json();
|
|
524
|
-
}
|
|
525
|
-
return t;
|
|
526
|
-
}
|
|
527
|
-
normalizeCollectionResponse(t) {
|
|
528
|
-
if (this.isCollectionResponseEnvelope(t)) {
|
|
529
|
-
const e = t.data;
|
|
530
|
-
return {
|
|
531
|
-
data: e.data,
|
|
532
|
-
meta: e.meta,
|
|
533
|
-
rv: t.rv || e.rv
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
if (Array.isArray(t))
|
|
537
|
-
return { data: t, meta: void 0, rv: void 0 };
|
|
538
|
-
if (typeof t == "object" && t !== null && "data" in t) {
|
|
539
|
-
const {
|
|
540
|
-
data: e,
|
|
541
|
-
meta: n,
|
|
542
|
-
rv: s
|
|
543
|
-
} = t;
|
|
544
|
-
return { data: e, meta: n, rv: s };
|
|
545
|
-
}
|
|
546
|
-
return { data: [], meta: void 0, rv: void 0 };
|
|
547
|
-
}
|
|
548
|
-
buildUrl(t, e) {
|
|
549
|
-
const n = new URL(`${this.baseUrl}/v1/${t}`);
|
|
550
|
-
return Object.entries(e).forEach(([s, r]) => {
|
|
551
|
-
r != null && n.searchParams.append(s, String(r));
|
|
552
|
-
}), n.toString();
|
|
553
|
-
}
|
|
554
|
-
resolveRequestUrl(t) {
|
|
555
|
-
return t ? t instanceof URL ? t : new URL(t, "http://localhost") : null;
|
|
556
|
-
}
|
|
557
|
-
isFetchResponse(t) {
|
|
558
|
-
return typeof t == "object" && t !== null && "json" in t && typeof t.json == "function" && "ok" in t;
|
|
559
|
-
}
|
|
560
|
-
hasRevision(t) {
|
|
561
|
-
return typeof t == "object" && t !== null && "rv" in t;
|
|
562
|
-
}
|
|
563
|
-
isCollectionResponseEnvelope(t) {
|
|
564
|
-
return typeof t == "object" && t !== null && "data" in t && typeof t.data == "object" && t.data !== null && "data" in t.data && Array.isArray(t.data.data);
|
|
565
|
-
}
|
|
451
|
+
function A(e, t) {
|
|
452
|
+
return [
|
|
453
|
+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
|
|
454
|
+
"<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">",
|
|
455
|
+
e.map((e) => {
|
|
456
|
+
let n = t ? E(e, t) : e;
|
|
457
|
+
return n ? [
|
|
458
|
+
" <sitemap>",
|
|
459
|
+
` <loc>${D(n)}</loc>`,
|
|
460
|
+
" </sitemap>"
|
|
461
|
+
].join("\n") : "";
|
|
462
|
+
}).filter(Boolean).join("\n"),
|
|
463
|
+
"</sitemapindex>"
|
|
464
|
+
].join("\n");
|
|
566
465
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/types.ts
|
|
468
|
+
var j = /* @__PURE__ */ t({}), M = class extends Error {
|
|
469
|
+
status;
|
|
470
|
+
endpoint;
|
|
471
|
+
body;
|
|
472
|
+
constructor(e, t, n, r) {
|
|
473
|
+
super(e), this.status = t, this.endpoint = n, this.body = r, this.name = "ApiError";
|
|
474
|
+
}
|
|
475
|
+
}, N = (e) => e === 429 || e >= 500 && e <= 599, P = (e) => new Promise((t) => setTimeout(t, e)), F = class {
|
|
476
|
+
baseUrl;
|
|
477
|
+
token;
|
|
478
|
+
vid;
|
|
479
|
+
fetchClient;
|
|
480
|
+
getRvFn;
|
|
481
|
+
setRvFn;
|
|
482
|
+
timeoutMs;
|
|
483
|
+
retries;
|
|
484
|
+
maxConcurrency;
|
|
485
|
+
rvValue = 0;
|
|
486
|
+
constructor(e, t) {
|
|
487
|
+
this.baseUrl = e.baseUrl.endsWith("/") ? e.baseUrl.slice(0, -1) : e.baseUrl, this.token = e.token;
|
|
488
|
+
let n = typeof globalThis.fetch == "function" ? globalThis.fetch.bind(globalThis) : null;
|
|
489
|
+
if (e.fetchClient) this.fetchClient = e.fetchClient;
|
|
490
|
+
else if (n) this.fetchClient = n;
|
|
491
|
+
else throw Error("No fetch implementation available. Provide `fetchClient` in ApiClient options.");
|
|
492
|
+
this.getRvFn = e.getRv, this.setRvFn = e.setRv, this.timeoutMs = e.timeoutMs, this.retries = Math.max(0, e.retries ?? 0), this.maxConcurrency = Math.max(1, e.maxConcurrency ?? 6);
|
|
493
|
+
let r = this.resolveRequestUrl(t);
|
|
494
|
+
this.vid = e.version || "published", this.setRv(r?.searchParams.get("b10cks_rv") || e.rv || 0);
|
|
495
|
+
}
|
|
496
|
+
async get(e, t = {}) {
|
|
497
|
+
let n = this.buildUrl(e, {
|
|
498
|
+
vid: this.vid,
|
|
499
|
+
rv: this.getRv(),
|
|
500
|
+
...t,
|
|
501
|
+
token: this.token
|
|
502
|
+
}), r = await this.requestWithRetry(n, e);
|
|
503
|
+
return this.hasRevision(r) && this.setRv(r.rv), r;
|
|
504
|
+
}
|
|
505
|
+
async post(e, t, n = {}) {
|
|
506
|
+
let r = this.buildUrl(e, {
|
|
507
|
+
vid: this.vid,
|
|
508
|
+
rv: this.getRv(),
|
|
509
|
+
...n,
|
|
510
|
+
token: this.token
|
|
511
|
+
}), i = await this.fetchWithTimeout(r, {
|
|
512
|
+
method: "POST",
|
|
513
|
+
headers: { "Content-Type": "application/json" },
|
|
514
|
+
body: t === void 0 ? void 0 : JSON.stringify(t)
|
|
515
|
+
});
|
|
516
|
+
return this.parseResponse(i, e);
|
|
517
|
+
}
|
|
518
|
+
async fetchWithTimeout(e, t) {
|
|
519
|
+
if (!this.timeoutMs) return this.fetchClient(e, t);
|
|
520
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), this.timeoutMs);
|
|
521
|
+
try {
|
|
522
|
+
return await this.fetchClient(e, {
|
|
523
|
+
...t,
|
|
524
|
+
signal: n.signal
|
|
525
|
+
});
|
|
526
|
+
} catch (t) {
|
|
527
|
+
throw t instanceof Error && t.name === "AbortError" ? new M(`Request timed out after ${this.timeoutMs}ms`, 0, e) : t;
|
|
528
|
+
} finally {
|
|
529
|
+
clearTimeout(r);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
async requestWithRetry(e, t) {
|
|
533
|
+
let n;
|
|
534
|
+
for (let r = 0; r <= this.retries; r++) try {
|
|
535
|
+
let n = await this.fetchWithTimeout(e);
|
|
536
|
+
return await this.parseResponse(n, t);
|
|
537
|
+
} catch (e) {
|
|
538
|
+
if (n = e, !(r < this.retries && (!(e instanceof M) || e.status === 0 || N(e.status)))) throw e;
|
|
539
|
+
await P(200 * 2 ** r);
|
|
540
|
+
}
|
|
541
|
+
throw n;
|
|
542
|
+
}
|
|
543
|
+
async getAll(e, t = {}) {
|
|
544
|
+
let n = await this.get(e, {
|
|
545
|
+
...t,
|
|
546
|
+
page: 1
|
|
547
|
+
}), r = this.normalizeCollectionResponse(n);
|
|
548
|
+
if (r.rv && this.setRv(r.rv), !r.meta || r.meta.last_page <= 1) return r.data;
|
|
549
|
+
let i = Array.from({ length: r.meta.last_page - 1 }, (e, t) => t + 2), a = await this.mapWithConcurrency(i, (n) => this.get(e, {
|
|
550
|
+
...t,
|
|
551
|
+
page: n
|
|
552
|
+
}));
|
|
553
|
+
return r.data.concat(a.flatMap((e) => this.normalizeCollectionResponse(e).data));
|
|
554
|
+
}
|
|
555
|
+
async mapWithConcurrency(e, t) {
|
|
556
|
+
let n = Array.from({ length: e.length }), r = 0, i = async () => {
|
|
557
|
+
for (; r < e.length;) {
|
|
558
|
+
let i = r++;
|
|
559
|
+
n[i] = await t(e[i]);
|
|
560
|
+
}
|
|
561
|
+
}, a = Array.from({ length: Math.min(this.maxConcurrency, e.length) }, () => i());
|
|
562
|
+
return await Promise.all(a), n;
|
|
563
|
+
}
|
|
564
|
+
setRv(e) {
|
|
565
|
+
this.setRvFn ? this.setRvFn(e) : this.rvValue = e;
|
|
566
|
+
}
|
|
567
|
+
getRv() {
|
|
568
|
+
return this.getRvFn ? this.getRvFn() : this.rvValue;
|
|
569
|
+
}
|
|
570
|
+
async parseResponse(e, t) {
|
|
571
|
+
if (this.isFetchResponse(e)) {
|
|
572
|
+
if (!e.ok) {
|
|
573
|
+
let n = await this.readErrorBody(e);
|
|
574
|
+
throw new M(`Request to "${t}" failed with status ${e.status}`, e.status, t, n);
|
|
575
|
+
}
|
|
576
|
+
return await e.json();
|
|
577
|
+
}
|
|
578
|
+
return e;
|
|
579
|
+
}
|
|
580
|
+
async readErrorBody(e) {
|
|
581
|
+
try {
|
|
582
|
+
let t = await e.text();
|
|
583
|
+
if (!t) return;
|
|
584
|
+
try {
|
|
585
|
+
return JSON.parse(t);
|
|
586
|
+
} catch {
|
|
587
|
+
return t;
|
|
588
|
+
}
|
|
589
|
+
} catch {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
normalizeCollectionResponse(e) {
|
|
594
|
+
if (this.isCollectionResponseEnvelope(e)) {
|
|
595
|
+
let t = e.data;
|
|
596
|
+
return {
|
|
597
|
+
data: t.data,
|
|
598
|
+
meta: t.meta,
|
|
599
|
+
rv: e.rv || t.rv
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
if (Array.isArray(e)) return {
|
|
603
|
+
data: e,
|
|
604
|
+
meta: void 0,
|
|
605
|
+
rv: void 0
|
|
606
|
+
};
|
|
607
|
+
if (typeof e == "object" && e && "data" in e) {
|
|
608
|
+
let { data: t, meta: n, rv: r } = e;
|
|
609
|
+
return {
|
|
610
|
+
data: t,
|
|
611
|
+
meta: n,
|
|
612
|
+
rv: r
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
return {
|
|
616
|
+
data: [],
|
|
617
|
+
meta: void 0,
|
|
618
|
+
rv: void 0
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
buildUrl(e, t) {
|
|
622
|
+
let n = new URL(`${this.baseUrl}/v1/${e}`);
|
|
623
|
+
return Object.entries(t).forEach(([e, t]) => {
|
|
624
|
+
t != null && n.searchParams.append(e, String(t));
|
|
625
|
+
}), n.toString();
|
|
626
|
+
}
|
|
627
|
+
resolveRequestUrl(e) {
|
|
628
|
+
return e ? e instanceof URL ? e : new URL(e, "http://localhost") : null;
|
|
629
|
+
}
|
|
630
|
+
isFetchResponse(e) {
|
|
631
|
+
return typeof e == "object" && !!e && "json" in e && typeof e.json == "function" && "ok" in e;
|
|
632
|
+
}
|
|
633
|
+
hasRevision(e) {
|
|
634
|
+
return typeof e == "object" && !!e && "rv" in e && e.rv != null;
|
|
635
|
+
}
|
|
636
|
+
isCollectionResponseEnvelope(e) {
|
|
637
|
+
return typeof e == "object" && !!e && "data" in e && typeof e.data == "object" && e.data !== null && "data" in e.data && Array.isArray(e.data.data);
|
|
638
|
+
}
|
|
589
639
|
};
|
|
590
|
-
//#
|
|
640
|
+
//#endregion
|
|
641
|
+
export { F as ApiClient, M as ApiError, s as B10cksDataApi, d as PreviewBridge, S as PreviewStore, _ as attachEditable, v as attachEditableField, C as bindPreviewStore, T as buildLocalizedPath, c as createB10cksDataApi, h as ensurePreviewStyles, O as filterSitemapEntries, b as getAtPath, w as normalizePathSegment, f as previewBridge, A as renderSitemapIndex, k as renderSitemapXml, n as resolveB10cksLink, i as serializeFilter, x as setAtPath, g as setPreviewScrollOffset, j as types };
|
|
642
|
+
|
|
643
|
+
//# sourceMappingURL=index.mjs.map
|