@storyblok/react 4.7.0 → 5.0.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 +0 -59
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common.js +1 -1
- package/dist/common.mjs +12 -14
- package/dist/index.js +1 -1
- package/dist/index.mjs +37 -39
- package/dist/index2.js +1 -1
- package/dist/index2.mjs +18 -20
- package/dist/richtext.mjs +5 -5
- package/dist/rsc/common.d.ts +1 -1
- package/dist/rsc/common.d.ts.map +1 -1
- package/dist/rsc.js +1 -1
- package/dist/rsc.mjs +17 -19
- package/dist/storyblok-js.js +1 -24
- package/dist/storyblok-js.mjs +484 -819
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,438 +1,335 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
function te(n, e) {
|
|
2
|
+
if (!e)
|
|
3
|
+
return { src: n, attrs: {} };
|
|
4
|
+
let t = 0, r = 0;
|
|
5
|
+
const s = {}, o = [];
|
|
6
|
+
function l(c, h, f, y, _) {
|
|
7
|
+
typeof c != "number" || c <= h || c >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${h} and ${f} (inclusive)`) : _.push(`${y}(${c})`);
|
|
8
|
+
}
|
|
9
|
+
if (typeof e == "object") {
|
|
10
|
+
if (typeof e.width == "number" && e.width > 0 ? (s.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (s.height = e.height, r = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (s.loading = e.loading), e.class && (s.class = e.class), e.filters) {
|
|
11
|
+
const { filters: c } = e || {}, { blur: h, brightness: f, fill: y, format: _, grayscale: A, quality: $, rotate: S } = c || {};
|
|
12
|
+
h && l(h, 0, 100, "blur", o), $ && l($, 0, 100, "quality", o), f && l(f, 0, 100, "brightness", o), y && o.push(`fill(${y})`), A && o.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${S})`), _ && ["webp", "png", "jpeg"].includes(_) && o.push(`format(${_})`);
|
|
13
|
+
}
|
|
14
|
+
e.srcset && (s.srcset = e.srcset.map((c) => {
|
|
15
|
+
if (typeof c == "number")
|
|
16
|
+
return `${n}/m/${c}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${c}w`;
|
|
17
|
+
if (Array.isArray(c) && c.length === 2) {
|
|
18
|
+
const [h, f] = c;
|
|
19
|
+
return `${n}/m/${h}x${f}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${h}w`;
|
|
20
|
+
} else {
|
|
21
|
+
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}).join(", ")), e.sizes && (s.sizes = e.sizes.join(", "));
|
|
25
|
+
}
|
|
26
|
+
let a = `${n}/m/`;
|
|
27
|
+
return t > 0 && r > 0 && (a = `${a}${t}x${r}/`), o.length > 0 && (a = `${a}filters:${o.join(":")}`), {
|
|
28
|
+
src: a,
|
|
29
|
+
attrs: s
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
var v = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n.TABLE = "table", n.TABLE_ROW = "tableRow", n.TABLE_CELL = "tableCell", n.TABLE_HEADER = "tableHeader", n))(v || {}), R = /* @__PURE__ */ ((n) => (n.BOLD = "bold", n.STRONG = "strong", n.STRIKE = "strike", n.UNDERLINE = "underline", n.ITALIC = "italic", n.CODE = "code", n.LINK = "link", n.ANCHOR = "anchor", n.STYLED = "styled", n.SUPERSCRIPT = "superscript", n.SUBSCRIPT = "subscript", n.TEXT_STYLE = "textStyle", n.HIGHLIGHT = "highlight", n))(R || {}), F = /* @__PURE__ */ ((n) => (n.TEXT = "text", n))(F || {}), I = /* @__PURE__ */ ((n) => (n.URL = "url", n.STORY = "story", n.ASSET = "asset", n.EMAIL = "email", n))(I || {});
|
|
33
|
+
const se = [
|
|
34
|
+
"area",
|
|
35
|
+
"base",
|
|
36
|
+
"br",
|
|
37
|
+
"col",
|
|
38
|
+
"embed",
|
|
39
|
+
"hr",
|
|
40
|
+
"img",
|
|
41
|
+
"input",
|
|
42
|
+
"link",
|
|
43
|
+
"meta",
|
|
44
|
+
"param",
|
|
45
|
+
"source",
|
|
46
|
+
"track",
|
|
47
|
+
"wbr"
|
|
48
|
+
], re = (n = {}) => Object.keys(n).map((e) => `${e}="${n[e]}"`).join(" "), ne = (n = {}) => Object.keys(n).map((e) => `${e}: ${n[e]}`).join("; ");
|
|
49
|
+
function oe(n) {
|
|
50
|
+
return n.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
51
|
+
}
|
|
52
|
+
const O = (n) => Object.fromEntries(Object.entries(n).filter(([e, t]) => t !== void 0));
|
|
53
|
+
function U(n, e = {}, t) {
|
|
54
|
+
const r = re(e), s = r ? `${n} ${r}` : n, o = Array.isArray(t) ? t.join("") : t || "";
|
|
55
|
+
if (n) {
|
|
56
|
+
if (se.includes(n))
|
|
57
|
+
return `<${s}>`;
|
|
58
|
+
} else return o;
|
|
59
|
+
return `<${s}>${o}</${n}>`;
|
|
60
|
+
}
|
|
61
|
+
function ie(n = {}) {
|
|
62
|
+
const e = /* @__PURE__ */ new Map(), {
|
|
63
|
+
renderFn: t = U,
|
|
64
|
+
textFn: r = oe,
|
|
65
|
+
resolvers: s = {},
|
|
66
|
+
optimizeImages: o = !1,
|
|
67
|
+
keyedResolvers: l = !1
|
|
68
|
+
} = n, a = t !== U, c = () => ({ render: (i, u = {}, d) => {
|
|
69
|
+
if (l && i) {
|
|
70
|
+
const p = e.get(i) || 0;
|
|
71
|
+
e.set(i, p + 1), u.key = `${i}-${p}`;
|
|
72
|
+
}
|
|
73
|
+
return t(i, u, d);
|
|
74
|
+
} }), h = (i) => (u, d) => {
|
|
75
|
+
const p = u.attrs || {};
|
|
76
|
+
return d.render(i, p, u.children || null);
|
|
77
|
+
}, f = (i, u) => {
|
|
78
|
+
const { src: d, alt: p, title: m, srcset: w, sizes: b } = i.attrs || {};
|
|
79
|
+
let k = d, T = {};
|
|
80
|
+
if (o) {
|
|
81
|
+
const { src: Z, attrs: ee } = te(d, o);
|
|
82
|
+
k = Z, T = ee;
|
|
83
|
+
}
|
|
84
|
+
const Q = {
|
|
85
|
+
src: k,
|
|
86
|
+
alt: p,
|
|
87
|
+
title: m,
|
|
88
|
+
srcset: w,
|
|
89
|
+
sizes: b,
|
|
90
|
+
...T
|
|
91
|
+
};
|
|
92
|
+
return u.render("img", O(Q));
|
|
93
|
+
}, y = (i, u) => {
|
|
94
|
+
const { level: d, ...p } = i.attrs || {};
|
|
95
|
+
return u.render(`h${d}`, p, i.children);
|
|
96
|
+
}, _ = (i, u) => {
|
|
97
|
+
var d, p, m, w;
|
|
98
|
+
const b = u.render("img", {
|
|
99
|
+
src: (d = i.attrs) == null ? void 0 : d.fallbackImage,
|
|
100
|
+
alt: (p = i.attrs) == null ? void 0 : p.alt,
|
|
101
|
+
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
|
102
|
+
draggable: "false",
|
|
103
|
+
loading: "lazy"
|
|
104
|
+
});
|
|
105
|
+
return u.render("span", {
|
|
106
|
+
"data-type": "emoji",
|
|
107
|
+
"data-name": (m = i.attrs) == null ? void 0 : m.name,
|
|
108
|
+
"data-emoji": (w = i.attrs) == null ? void 0 : w.emoji
|
|
109
|
+
}, b);
|
|
110
|
+
}, A = (i, u) => u.render(
|
|
111
|
+
"pre",
|
|
112
|
+
i.attrs || {},
|
|
113
|
+
u.render("code", {}, i.children || "")
|
|
114
|
+
), $ = (i, u = !1) => ({ text: d, attrs: p }, m) => {
|
|
115
|
+
const { class: w, id: b, ...k } = p || {}, T = u ? {
|
|
116
|
+
class: w,
|
|
117
|
+
id: b,
|
|
118
|
+
style: ne(k) || void 0
|
|
119
|
+
} : p || {};
|
|
120
|
+
return m.render(i, O(T), d);
|
|
121
|
+
}, S = (i) => C(i), V = (i) => {
|
|
122
|
+
const { marks: u, ...d } = i;
|
|
123
|
+
if ("text" in i) {
|
|
124
|
+
if (u)
|
|
125
|
+
return u.reduce(
|
|
126
|
+
(m, w) => S({ ...w, text: m }),
|
|
127
|
+
S({ ...d, children: d.children })
|
|
128
|
+
);
|
|
129
|
+
const p = i.attrs || {};
|
|
130
|
+
if (l) {
|
|
131
|
+
const m = e.get("txt") || 0;
|
|
132
|
+
e.set("txt", m + 1), p.key = `txt-${m}`;
|
|
133
|
+
}
|
|
134
|
+
return r(d.text, p);
|
|
135
|
+
}
|
|
136
|
+
return "";
|
|
137
|
+
}, H = (i, u) => {
|
|
138
|
+
const { linktype: d, href: p, anchor: m, ...w } = i.attrs || {};
|
|
139
|
+
let b = "";
|
|
140
|
+
switch (d) {
|
|
141
|
+
case I.ASSET:
|
|
142
|
+
case I.URL:
|
|
143
|
+
b = p;
|
|
144
|
+
break;
|
|
145
|
+
case I.EMAIL:
|
|
146
|
+
b = `mailto:${p}`;
|
|
147
|
+
break;
|
|
148
|
+
case I.STORY:
|
|
149
|
+
b = p, m && (b = `${b}#${m}`);
|
|
150
|
+
break;
|
|
151
|
+
default:
|
|
152
|
+
b = p;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
const k = { ...w };
|
|
156
|
+
return b && (k.href = b), u.render("a", k, i.text);
|
|
157
|
+
}, q = (i, u) => {
|
|
158
|
+
var d, p;
|
|
159
|
+
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), u.render("span", {
|
|
160
|
+
blok: (d = i == null ? void 0 : i.attrs) == null ? void 0 : d.body[0],
|
|
161
|
+
id: (p = i.attrs) == null ? void 0 : p.id,
|
|
162
|
+
style: "display: none"
|
|
163
|
+
});
|
|
164
|
+
}, J = (i, u) => {
|
|
165
|
+
const d = {}, p = u.render("tbody", {}, i.children);
|
|
166
|
+
return u.render("table", d, p);
|
|
167
|
+
}, Y = (i, u) => {
|
|
168
|
+
const d = {};
|
|
169
|
+
return u.render("tr", d, i.children);
|
|
170
|
+
}, K = (i, u) => {
|
|
171
|
+
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = i.attrs || {}, k = {
|
|
172
|
+
...b
|
|
173
|
+
};
|
|
174
|
+
d > 1 && (k.colspan = d), p > 1 && (k.rowspan = p);
|
|
175
|
+
const T = [];
|
|
176
|
+
return m && T.push(`width: ${m}px;`), w && T.push(`background-color: ${w};`), T.length > 0 && (k.style = T.join(" ")), u.render("td", O(k), i.children);
|
|
177
|
+
}, W = (i, u) => {
|
|
178
|
+
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: w, ...b } = i.attrs || {}, k = {
|
|
179
|
+
...b
|
|
180
|
+
};
|
|
181
|
+
d > 1 && (k.colspan = d), p > 1 && (k.rowspan = p);
|
|
182
|
+
const T = [];
|
|
183
|
+
return m && T.push(`width: ${m}px;`), w && T.push(`background-color: ${w};`), T.length > 0 && (k.style = T.join(" ")), u.render("th", O(k), i.children);
|
|
184
|
+
}, X = new Map([
|
|
185
|
+
[v.DOCUMENT, h("")],
|
|
186
|
+
[v.HEADING, y],
|
|
187
|
+
[v.PARAGRAPH, h("p")],
|
|
188
|
+
[v.UL_LIST, h("ul")],
|
|
189
|
+
[v.OL_LIST, h("ol")],
|
|
190
|
+
[v.LIST_ITEM, h("li")],
|
|
191
|
+
[v.IMAGE, f],
|
|
192
|
+
[v.EMOJI, _],
|
|
193
|
+
[v.CODE_BLOCK, A],
|
|
194
|
+
[v.HR, h("hr")],
|
|
195
|
+
[v.BR, h("br")],
|
|
196
|
+
[v.QUOTE, h("blockquote")],
|
|
197
|
+
[v.COMPONENT, q],
|
|
198
|
+
[F.TEXT, V],
|
|
199
|
+
[R.LINK, H],
|
|
200
|
+
[R.ANCHOR, H],
|
|
201
|
+
[R.STYLED, $("span", !0)],
|
|
202
|
+
[R.BOLD, $("strong")],
|
|
203
|
+
[R.TEXT_STYLE, $("span", !0)],
|
|
204
|
+
[R.ITALIC, $("em")],
|
|
205
|
+
[R.UNDERLINE, $("u")],
|
|
206
|
+
[R.STRIKE, $("s")],
|
|
207
|
+
[R.CODE, $("code")],
|
|
208
|
+
[R.SUPERSCRIPT, $("sup")],
|
|
209
|
+
[R.SUBSCRIPT, $("sub")],
|
|
210
|
+
[R.HIGHLIGHT, $("mark")],
|
|
211
|
+
[v.TABLE, J],
|
|
212
|
+
[v.TABLE_ROW, Y],
|
|
213
|
+
[v.TABLE_CELL, K],
|
|
214
|
+
[v.TABLE_HEADER, W],
|
|
215
|
+
...Object.entries(s).map(([i, u]) => [i, u])
|
|
216
|
+
]);
|
|
217
|
+
function L(i) {
|
|
218
|
+
const u = X.get(i.type);
|
|
219
|
+
if (!u)
|
|
220
|
+
return console.error("<Storyblok>", `No resolver found for node type ${i.type}`), "";
|
|
221
|
+
const d = c();
|
|
222
|
+
if (i.type === "text")
|
|
223
|
+
return u(i, d);
|
|
224
|
+
const p = i.content ? i.content.map(C) : void 0;
|
|
225
|
+
return u({
|
|
226
|
+
...i,
|
|
227
|
+
children: p
|
|
228
|
+
}, d);
|
|
229
|
+
}
|
|
230
|
+
function C(i) {
|
|
231
|
+
return i.type === "doc" ? a ? i.content.map(L) : i.content.map(L).join("") : Array.isArray(i) ? i.map(L) : L(i);
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
render: C
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
let B = !1;
|
|
238
|
+
const D = [], G = (n) => new Promise((e, t) => {
|
|
3
239
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
|
|
4
240
|
if (window.location === window.parent.location) {
|
|
5
241
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
6
242
|
return;
|
|
7
243
|
}
|
|
8
|
-
|
|
244
|
+
B ? s() : D.push(s);
|
|
9
245
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
10
246
|
return;
|
|
11
247
|
const r = document.createElement("script");
|
|
12
248
|
r.async = !0, r.src = n, r.id = "storyblok-javascript-bridge", r.onerror = (s) => t(s), r.onload = (s) => {
|
|
13
|
-
D.forEach((o) => o()),
|
|
249
|
+
D.forEach((o) => o()), B = !0, e(s);
|
|
14
250
|
}, document.getElementsByTagName("head")[0].appendChild(r);
|
|
15
251
|
});
|
|
16
|
-
var
|
|
17
|
-
class
|
|
252
|
+
var ae = Object.defineProperty, le = (n, e, t) => e in n ? ae(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, g = (n, e, t) => le(n, typeof e != "symbol" ? e + "" : e, t);
|
|
253
|
+
class ce extends Error {
|
|
18
254
|
constructor(e) {
|
|
19
255
|
super(e), this.name = "AbortError";
|
|
20
256
|
}
|
|
21
257
|
}
|
|
22
|
-
function
|
|
258
|
+
function he(n, e, t) {
|
|
23
259
|
if (!Number.isFinite(e))
|
|
24
260
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
25
261
|
if (!Number.isFinite(t))
|
|
26
262
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
27
263
|
const r = [];
|
|
28
|
-
let s = [], o = 0,
|
|
29
|
-
const
|
|
264
|
+
let s = [], o = 0, l = !1;
|
|
265
|
+
const a = async () => {
|
|
30
266
|
o++;
|
|
31
267
|
const h = r.shift();
|
|
32
268
|
if (h)
|
|
33
269
|
try {
|
|
34
|
-
const
|
|
35
|
-
h.resolve(
|
|
36
|
-
} catch (
|
|
37
|
-
h.reject(
|
|
270
|
+
const y = await n(...h.args);
|
|
271
|
+
h.resolve(y);
|
|
272
|
+
} catch (y) {
|
|
273
|
+
h.reject(y);
|
|
38
274
|
}
|
|
39
|
-
const
|
|
40
|
-
o--, r.length > 0 &&
|
|
275
|
+
const f = setTimeout(() => {
|
|
276
|
+
o--, r.length > 0 && a(), s = s.filter((y) => y !== f);
|
|
41
277
|
}, t);
|
|
42
|
-
s.includes(
|
|
43
|
-
},
|
|
278
|
+
s.includes(f) || s.push(f);
|
|
279
|
+
}, c = (...h) => l ? Promise.reject(
|
|
44
280
|
new Error(
|
|
45
281
|
"Throttled function is already aborted and not accepting new promises"
|
|
46
282
|
)
|
|
47
|
-
) : new Promise((
|
|
283
|
+
) : new Promise((f, y) => {
|
|
48
284
|
r.push({
|
|
49
|
-
resolve:
|
|
50
|
-
reject:
|
|
285
|
+
resolve: f,
|
|
286
|
+
reject: y,
|
|
51
287
|
args: h
|
|
52
|
-
}), o < e &&
|
|
288
|
+
}), o < e && a();
|
|
53
289
|
});
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
(h) => h.reject(() => new
|
|
290
|
+
return c.abort = () => {
|
|
291
|
+
l = !0, s.forEach(clearTimeout), s = [], r.forEach(
|
|
292
|
+
(h) => h.reject(() => new ce("Throttle function aborted"))
|
|
57
293
|
), r.length = 0;
|
|
58
|
-
},
|
|
59
|
-
}
|
|
60
|
-
class C {
|
|
61
|
-
constructor() {
|
|
62
|
-
m(this, "isCDNUrl", (e = "") => e.includes("/cdn/")), m(this, "getOptionsPage", (e, t = 25, r = 1) => ({
|
|
63
|
-
...e,
|
|
64
|
-
per_page: t,
|
|
65
|
-
page: r
|
|
66
|
-
})), m(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), m(this, "arrayFrom", (e = 0, t) => Array.from({ length: e }, t)), m(this, "range", (e = 0, t = e) => {
|
|
67
|
-
const r = Math.abs(t - e) || 0, s = e < t ? 1 : -1;
|
|
68
|
-
return this.arrayFrom(r, (o, a) => a * s + e);
|
|
69
|
-
}), m(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), m(this, "flatMap", (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], [])), m(this, "escapeHTML", function(e) {
|
|
70
|
-
const t = {
|
|
71
|
-
"&": "&",
|
|
72
|
-
"<": "<",
|
|
73
|
-
">": ">",
|
|
74
|
-
'"': """,
|
|
75
|
-
"'": "'"
|
|
76
|
-
}, r = /[&<>"']/g, s = new RegExp(r.source);
|
|
77
|
-
return e && s.test(e) ? e.replace(r, (o) => t[o]) : e;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* @method stringify
|
|
82
|
-
* @param {object} params
|
|
83
|
-
* @param {string} prefix
|
|
84
|
-
* @param {boolean} isArray
|
|
85
|
-
* @return {string} Stringified object
|
|
86
|
-
*/
|
|
87
|
-
stringify(e, t, r) {
|
|
88
|
-
const s = [];
|
|
89
|
-
for (const o in e) {
|
|
90
|
-
if (!Object.prototype.hasOwnProperty.call(e, o))
|
|
91
|
-
continue;
|
|
92
|
-
const a = e[o];
|
|
93
|
-
if (a == null)
|
|
94
|
-
continue;
|
|
95
|
-
const l = r ? "" : encodeURIComponent(o);
|
|
96
|
-
let i;
|
|
97
|
-
typeof a == "object" ? i = this.stringify(
|
|
98
|
-
a,
|
|
99
|
-
t ? t + encodeURIComponent(`[${l}]`) : l,
|
|
100
|
-
Array.isArray(a)
|
|
101
|
-
) : i = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(a)}`, s.push(i);
|
|
102
|
-
}
|
|
103
|
-
return s.join("&");
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* @method getRegionURL
|
|
107
|
-
* @param {string} regionCode region code, could be eu, us, cn, ap or ca
|
|
108
|
-
* @return {string} The base URL of the region
|
|
109
|
-
*/
|
|
110
|
-
getRegionURL(e) {
|
|
111
|
-
const t = "api.storyblok.com", r = "api-us.storyblok.com", s = "app.storyblokchina.cn", o = "api-ap.storyblok.com", a = "api-ca.storyblok.com";
|
|
112
|
-
switch (e) {
|
|
113
|
-
case "us":
|
|
114
|
-
return r;
|
|
115
|
-
case "cn":
|
|
116
|
-
return s;
|
|
117
|
-
case "ap":
|
|
118
|
-
return o;
|
|
119
|
-
case "ca":
|
|
120
|
-
return a;
|
|
121
|
-
default:
|
|
122
|
-
return t;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
294
|
+
}, c;
|
|
125
295
|
}
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return t;
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
"
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
singleTag: "br"
|
|
149
|
-
}), fe = (n) => ({
|
|
150
|
-
tag: `h${n.attrs.level}`
|
|
151
|
-
}), me = (n) => ({
|
|
152
|
-
singleTag: [
|
|
153
|
-
{
|
|
154
|
-
tag: "img",
|
|
155
|
-
attrs: le(n.attrs, ["src", "alt", "title"])
|
|
156
|
-
}
|
|
157
|
-
]
|
|
158
|
-
}), ye = () => ({
|
|
159
|
-
tag: "li"
|
|
160
|
-
}), be = () => ({
|
|
161
|
-
tag: "ol"
|
|
162
|
-
}), ve = () => ({
|
|
163
|
-
tag: "p"
|
|
164
|
-
}), ke = (n) => ({
|
|
165
|
-
tag: [
|
|
166
|
-
{
|
|
167
|
-
tag: "span",
|
|
168
|
-
attrs: {
|
|
169
|
-
"data-type": "emoji",
|
|
170
|
-
"data-name": n.attrs.name,
|
|
171
|
-
emoji: n.attrs.emoji
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
}), Te = () => ({
|
|
176
|
-
tag: "b"
|
|
177
|
-
}), we = () => ({
|
|
178
|
-
tag: "s"
|
|
179
|
-
}), $e = () => ({
|
|
180
|
-
tag: "u"
|
|
181
|
-
}), Re = () => ({
|
|
182
|
-
tag: "strong"
|
|
183
|
-
}), _e = () => ({
|
|
184
|
-
tag: "code"
|
|
185
|
-
}), Ee = () => ({
|
|
186
|
-
tag: "i"
|
|
187
|
-
}), Se = (n) => {
|
|
188
|
-
if (!n.attrs)
|
|
189
|
-
return {
|
|
190
|
-
tag: ""
|
|
191
|
-
};
|
|
192
|
-
const e = new C().escapeHTML, t = { ...n.attrs }, { linktype: r = "url" } = n.attrs;
|
|
193
|
-
if (delete t.linktype, t.href && (t.href = e(n.attrs.href || "")), ce(r) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
194
|
-
for (const s in t.custom)
|
|
195
|
-
t[s] = t.custom[s];
|
|
196
|
-
delete t.custom;
|
|
197
|
-
}
|
|
198
|
-
return {
|
|
199
|
-
tag: [
|
|
200
|
-
{
|
|
201
|
-
tag: "a",
|
|
202
|
-
attrs: t
|
|
203
|
-
}
|
|
204
|
-
]
|
|
205
|
-
};
|
|
206
|
-
}, je = (n) => ({
|
|
207
|
-
tag: [
|
|
208
|
-
{
|
|
209
|
-
tag: "span",
|
|
210
|
-
attrs: n.attrs
|
|
211
|
-
}
|
|
212
|
-
]
|
|
213
|
-
}), xe = () => ({
|
|
214
|
-
tag: "sub"
|
|
215
|
-
}), Ie = () => ({
|
|
216
|
-
tag: "sup"
|
|
217
|
-
}), Ae = (n) => ({
|
|
218
|
-
tag: [
|
|
219
|
-
{
|
|
220
|
-
tag: "span",
|
|
221
|
-
attrs: n.attrs
|
|
222
|
-
}
|
|
223
|
-
]
|
|
224
|
-
}), Oe = (n) => {
|
|
225
|
-
var e;
|
|
226
|
-
return (e = n.attrs) != null && e.color ? {
|
|
227
|
-
tag: [
|
|
228
|
-
{
|
|
229
|
-
tag: "span",
|
|
230
|
-
attrs: {
|
|
231
|
-
style: `background-color:${n.attrs.color};`
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
]
|
|
235
|
-
} : {
|
|
236
|
-
tag: ""
|
|
237
|
-
};
|
|
238
|
-
}, Le = (n) => {
|
|
239
|
-
var e;
|
|
240
|
-
return (e = n.attrs) != null && e.color ? {
|
|
241
|
-
tag: [
|
|
242
|
-
{
|
|
243
|
-
tag: "span",
|
|
244
|
-
attrs: {
|
|
245
|
-
style: `color:${n.attrs.color}`
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
]
|
|
249
|
-
} : {
|
|
250
|
-
tag: ""
|
|
251
|
-
};
|
|
252
|
-
}, Ce = {
|
|
253
|
-
nodes: {
|
|
254
|
-
horizontal_rule: he,
|
|
255
|
-
blockquote: ue,
|
|
256
|
-
bullet_list: de,
|
|
257
|
-
code_block: pe,
|
|
258
|
-
hard_break: ge,
|
|
259
|
-
heading: fe,
|
|
260
|
-
image: me,
|
|
261
|
-
list_item: ye,
|
|
262
|
-
ordered_list: be,
|
|
263
|
-
paragraph: ve,
|
|
264
|
-
emoji: ke
|
|
265
|
-
},
|
|
266
|
-
marks: {
|
|
267
|
-
bold: Te,
|
|
268
|
-
strike: we,
|
|
269
|
-
underline: $e,
|
|
270
|
-
strong: Re,
|
|
271
|
-
code: _e,
|
|
272
|
-
italic: Ee,
|
|
273
|
-
link: Se,
|
|
274
|
-
styled: je,
|
|
275
|
-
subscript: xe,
|
|
276
|
-
superscript: Ie,
|
|
277
|
-
anchor: Ae,
|
|
278
|
-
highlight: Oe,
|
|
279
|
-
textStyle: Le
|
|
296
|
+
const ue = (n = "") => n.includes("/cdn/"), de = (n, e = 25, t = 1) => ({
|
|
297
|
+
...n,
|
|
298
|
+
per_page: e,
|
|
299
|
+
page: t
|
|
300
|
+
}), pe = (n) => new Promise((e) => setTimeout(e, n)), fe = (n = 0, e) => Array.from({ length: n }, e), ye = (n = 0, e = n) => {
|
|
301
|
+
const t = Math.abs(e - n) || 0, r = n < e ? 1 : -1;
|
|
302
|
+
return fe(t, (s, o) => o * r + n);
|
|
303
|
+
}, ge = async (n, e) => Promise.all(n.map(e)), me = (n = [], e) => n.map(e).reduce((t, r) => [...t, ...r], []), N = (n, e, t) => {
|
|
304
|
+
const r = [];
|
|
305
|
+
for (const s in n) {
|
|
306
|
+
if (!Object.prototype.hasOwnProperty.call(n, s))
|
|
307
|
+
continue;
|
|
308
|
+
const o = n[s];
|
|
309
|
+
if (o == null)
|
|
310
|
+
continue;
|
|
311
|
+
const l = t ? "" : encodeURIComponent(s);
|
|
312
|
+
let a;
|
|
313
|
+
typeof o == "object" ? a = N(
|
|
314
|
+
o,
|
|
315
|
+
e ? e + encodeURIComponent(`[${l}]`) : l,
|
|
316
|
+
Array.isArray(o)
|
|
317
|
+
) : a = `${e ? e + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(o)}`, r.push(a);
|
|
280
318
|
}
|
|
281
|
-
|
|
319
|
+
return r.join("&");
|
|
320
|
+
}, M = (n) => {
|
|
282
321
|
const e = {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
return
|
|
322
|
+
eu: "api.storyblok.com",
|
|
323
|
+
us: "api-us.storyblok.com",
|
|
324
|
+
cn: "app.storyblokchina.cn",
|
|
325
|
+
ap: "api-ap.storyblok.com",
|
|
326
|
+
ca: "api-ca.storyblok.com"
|
|
327
|
+
};
|
|
328
|
+
return e[n] ?? e.eu;
|
|
290
329
|
};
|
|
291
|
-
|
|
292
|
-
class P {
|
|
330
|
+
class be {
|
|
293
331
|
constructor(e) {
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
addNode(e, t) {
|
|
297
|
-
this.nodes[e] = t;
|
|
298
|
-
}
|
|
299
|
-
addMark(e, t) {
|
|
300
|
-
this.marks[e] = t;
|
|
301
|
-
}
|
|
302
|
-
render(e, t = { optimizeImages: !1 }, r = !0) {
|
|
303
|
-
if (!q && r && (console.warn(
|
|
304
|
-
"Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"
|
|
305
|
-
), q = !0), e && e.content && Array.isArray(e.content)) {
|
|
306
|
-
let s = "";
|
|
307
|
-
return e.content.forEach((o) => {
|
|
308
|
-
s += this.renderNode(o);
|
|
309
|
-
}), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
|
|
310
|
-
}
|
|
311
|
-
return console.warn(
|
|
312
|
-
`The render method must receive an Object with a "content" field.
|
|
313
|
-
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
314
|
-
ISbRichtext:
|
|
315
|
-
content?: ISbRichtext[]
|
|
316
|
-
marks?: ISbRichtext[]
|
|
317
|
-
attrs?: any
|
|
318
|
-
text?: string
|
|
319
|
-
type: string
|
|
320
|
-
|
|
321
|
-
Example:
|
|
322
|
-
{
|
|
323
|
-
content: [
|
|
324
|
-
{
|
|
325
|
-
content: [
|
|
326
|
-
{
|
|
327
|
-
text: 'Hello World',
|
|
328
|
-
type: 'text'
|
|
329
|
-
}
|
|
330
|
-
],
|
|
331
|
-
type: 'paragraph'
|
|
332
|
-
}
|
|
333
|
-
],
|
|
334
|
-
type: 'doc'
|
|
335
|
-
}`
|
|
336
|
-
), "";
|
|
337
|
-
}
|
|
338
|
-
optimizeImages(e, t) {
|
|
339
|
-
let r = 0, s = 0, o = "", a = "";
|
|
340
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (o += `width="${t.width}" `, r = t.width), typeof t.height == "number" && t.height > 0 && (o += `height="${t.height}" `, s = t.height), (t.loading === "lazy" || t.loading === "eager") && (o += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (o += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (a += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (a += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (a += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (a += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (a += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (a += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (a += `:rotate(${t.filters.rotate})`), a.length > 0 && (a = `/filters${a}`))), o.length > 0 && (e = e.replace(/<img/g, `<img ${o.trim()}`));
|
|
341
|
-
const l = r > 0 || s > 0 || a.length > 0 ? `${r}x${s}${a}` : "";
|
|
342
|
-
return e = e.replace(
|
|
343
|
-
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
|
344
|
-
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
|
345
|
-
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (i) => {
|
|
346
|
-
var h, d;
|
|
347
|
-
const p = i.match(
|
|
348
|
-
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
|
349
|
-
);
|
|
350
|
-
if (p && p.length > 0) {
|
|
351
|
-
const b = {
|
|
352
|
-
srcset: (h = t.srcset) == null ? void 0 : h.map((y) => {
|
|
353
|
-
if (typeof y == "number")
|
|
354
|
-
return `//${p}/m/${y}x0${a} ${y}w`;
|
|
355
|
-
if (typeof y == "object" && y.length === 2) {
|
|
356
|
-
let S = 0, I = 0;
|
|
357
|
-
return typeof y[0] == "number" && (S = y[0]), typeof y[1] == "number" && (I = y[1]), `//${p}/m/${S}x${I}${a} ${S}w`;
|
|
358
|
-
}
|
|
359
|
-
return "";
|
|
360
|
-
}).join(", "),
|
|
361
|
-
sizes: (d = t.sizes) == null ? void 0 : d.map((y) => y).join(", ")
|
|
362
|
-
};
|
|
363
|
-
let E = "";
|
|
364
|
-
return b.srcset && (E += `srcset="${b.srcset}" `), b.sizes && (E += `sizes="${b.sizes}" `), i.replace(/<img/g, `<img ${E.trim()}`);
|
|
365
|
-
}
|
|
366
|
-
return i;
|
|
367
|
-
})), e;
|
|
368
|
-
}
|
|
369
|
-
renderNode(e) {
|
|
370
|
-
const t = [];
|
|
371
|
-
e.marks && e.marks.forEach((s) => {
|
|
372
|
-
const o = this.getMatchingMark(s);
|
|
373
|
-
o && o.tag !== "" && t.push(this.renderOpeningTag(o.tag));
|
|
374
|
-
});
|
|
375
|
-
const r = this.getMatchingNode(e);
|
|
376
|
-
return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((s) => {
|
|
377
|
-
t.push(this.renderNode(s));
|
|
378
|
-
}) : e.text ? t.push(Pe(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html ? t.push(r.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((s) => {
|
|
379
|
-
const o = this.getMatchingMark(s);
|
|
380
|
-
o && o.tag !== "" && t.push(this.renderClosingTag(o.tag));
|
|
381
|
-
}), t.join("");
|
|
382
|
-
}
|
|
383
|
-
renderTag(e, t) {
|
|
384
|
-
return e.constructor === String ? `<${e}${t}>` : e.map((r) => {
|
|
385
|
-
if (r.constructor === String)
|
|
386
|
-
return `<${r}${t}>`;
|
|
387
|
-
{
|
|
388
|
-
let s = `<${r.tag}`;
|
|
389
|
-
if (r.attrs) {
|
|
390
|
-
for (const o in r.attrs)
|
|
391
|
-
if (Object.prototype.hasOwnProperty.call(r.attrs, o)) {
|
|
392
|
-
const a = r.attrs[o];
|
|
393
|
-
a !== null && (s += ` ${o}="${a}"`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return `${s}${t}>`;
|
|
397
|
-
}
|
|
398
|
-
}).join("");
|
|
399
|
-
}
|
|
400
|
-
renderOpeningTag(e) {
|
|
401
|
-
return this.renderTag(e, "");
|
|
402
|
-
}
|
|
403
|
-
renderClosingTag(e) {
|
|
404
|
-
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
|
|
405
|
-
}
|
|
406
|
-
getMatchingNode(e) {
|
|
407
|
-
const t = this.nodes[e.type];
|
|
408
|
-
if (typeof t == "function")
|
|
409
|
-
return t(e);
|
|
410
|
-
}
|
|
411
|
-
getMatchingMark(e) {
|
|
412
|
-
const t = this.marks[e.type];
|
|
413
|
-
if (typeof t == "function")
|
|
414
|
-
return t(e);
|
|
415
|
-
}
|
|
416
|
-
renderEmoji(e) {
|
|
417
|
-
if (e.attrs.emoji)
|
|
418
|
-
return e.attrs.emoji;
|
|
419
|
-
const t = [
|
|
420
|
-
{
|
|
421
|
-
tag: "img",
|
|
422
|
-
attrs: {
|
|
423
|
-
src: e.attrs.fallbackImage,
|
|
424
|
-
draggable: "false",
|
|
425
|
-
loading: "lazy",
|
|
426
|
-
align: "absmiddle"
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
];
|
|
430
|
-
return this.renderTag(t, " /");
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
class Ne {
|
|
434
|
-
constructor(e) {
|
|
435
|
-
m(this, "baseURL"), m(this, "timeout"), m(this, "headers"), m(this, "responseInterceptor"), m(this, "fetch"), m(this, "ejectInterceptor"), m(this, "url"), m(this, "parameters"), m(this, "fetchOptions"), this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {}, this.fetchOptions = {};
|
|
332
|
+
g(this, "baseURL"), g(this, "timeout"), g(this, "headers"), g(this, "responseInterceptor"), g(this, "fetch"), g(this, "ejectInterceptor"), g(this, "url"), g(this, "parameters"), g(this, "fetchOptions"), this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {}, this.fetchOptions = {};
|
|
436
333
|
}
|
|
437
334
|
/**
|
|
438
335
|
*
|
|
@@ -468,32 +365,26 @@ class Ne {
|
|
|
468
365
|
}
|
|
469
366
|
async _methodHandler(e) {
|
|
470
367
|
let t = `${this.baseURL}${this.url}`, r = null;
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
)}`;
|
|
476
|
-
} else
|
|
477
|
-
r = JSON.stringify(this.parameters);
|
|
478
|
-
const s = new URL(t), o = new AbortController(), { signal: a } = o;
|
|
479
|
-
let l;
|
|
480
|
-
this.timeout && (l = setTimeout(() => o.abort(), this.timeout));
|
|
368
|
+
e === "get" ? t = `${this.baseURL}${this.url}?${N(this.parameters)}` : r = JSON.stringify(this.parameters);
|
|
369
|
+
const s = new URL(t), o = new AbortController(), { signal: l } = o;
|
|
370
|
+
let a;
|
|
371
|
+
this.timeout && (a = setTimeout(() => o.abort(), this.timeout));
|
|
481
372
|
try {
|
|
482
|
-
const
|
|
373
|
+
const c = await this.fetch(`${s}`, {
|
|
483
374
|
method: e,
|
|
484
375
|
headers: this.headers,
|
|
485
376
|
body: r,
|
|
486
|
-
signal:
|
|
377
|
+
signal: l,
|
|
487
378
|
...this.fetchOptions
|
|
488
379
|
});
|
|
489
|
-
this.timeout && clearTimeout(
|
|
380
|
+
this.timeout && clearTimeout(a);
|
|
490
381
|
const h = await this._responseHandler(
|
|
491
|
-
|
|
382
|
+
c
|
|
492
383
|
);
|
|
493
384
|
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
|
|
494
|
-
} catch (
|
|
385
|
+
} catch (c) {
|
|
495
386
|
return {
|
|
496
|
-
message:
|
|
387
|
+
message: c
|
|
497
388
|
};
|
|
498
389
|
}
|
|
499
390
|
}
|
|
@@ -503,53 +394,77 @@ class Ne {
|
|
|
503
394
|
eject() {
|
|
504
395
|
this.ejectInterceptor = !0;
|
|
505
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* Normalizes error messages from different response structures
|
|
399
|
+
* @param data The response data that might contain error information
|
|
400
|
+
* @returns A normalized error message string
|
|
401
|
+
*/
|
|
402
|
+
_normalizeErrorMessage(e) {
|
|
403
|
+
if (Array.isArray(e))
|
|
404
|
+
return e[0] || "Unknown error";
|
|
405
|
+
if (e && typeof e == "object") {
|
|
406
|
+
if (e.error)
|
|
407
|
+
return e.error;
|
|
408
|
+
for (const t in e) {
|
|
409
|
+
if (Array.isArray(e[t]))
|
|
410
|
+
return `${t}: ${e[t][0]}`;
|
|
411
|
+
if (typeof e[t] == "string")
|
|
412
|
+
return `${t}: ${e[t]}`;
|
|
413
|
+
}
|
|
414
|
+
if (e.slug)
|
|
415
|
+
return e.slug;
|
|
416
|
+
}
|
|
417
|
+
return "Unknown error";
|
|
418
|
+
}
|
|
506
419
|
_statusHandler(e) {
|
|
507
420
|
const t = /20[0-6]/g;
|
|
508
421
|
return new Promise((r, s) => {
|
|
509
422
|
if (t.test(`${e.status}`))
|
|
510
423
|
return r(e);
|
|
511
424
|
const o = {
|
|
512
|
-
message: e.
|
|
425
|
+
message: this._normalizeErrorMessage(e.data),
|
|
513
426
|
status: e.status,
|
|
514
|
-
response:
|
|
427
|
+
response: e
|
|
515
428
|
};
|
|
516
429
|
s(o);
|
|
517
430
|
});
|
|
518
431
|
}
|
|
519
432
|
}
|
|
520
|
-
const
|
|
433
|
+
const z = "SB-Agent", P = {
|
|
521
434
|
defaultAgentName: "SB-JS-CLIENT",
|
|
522
435
|
defaultAgentVersion: "SB-Agent-Version",
|
|
523
436
|
packageVersion: "6.0.0"
|
|
437
|
+
}, ve = {
|
|
438
|
+
DRAFT: "draft"
|
|
524
439
|
};
|
|
525
|
-
let
|
|
526
|
-
const
|
|
527
|
-
class
|
|
440
|
+
let j = {};
|
|
441
|
+
const E = {};
|
|
442
|
+
class ke {
|
|
528
443
|
/**
|
|
529
444
|
*
|
|
530
445
|
* @param config ISbConfig interface
|
|
531
446
|
* @param pEndpoint string, optional
|
|
532
447
|
*/
|
|
533
448
|
constructor(e, t) {
|
|
534
|
-
|
|
449
|
+
g(this, "client"), g(this, "maxRetries"), g(this, "retriesDelay"), g(this, "throttle"), g(this, "accessToken"), g(this, "cache"), g(this, "resolveCounter"), g(this, "relations"), g(this, "links"), g(this, "version"), g(this, "richTextResolver"), g(this, "resolveNestedRelations"), g(this, "stringifiedStoriesCache"), g(this, "inlineAssets");
|
|
535
450
|
let r = e.endpoint || t;
|
|
536
451
|
if (!r) {
|
|
537
|
-
const
|
|
538
|
-
e.oauthToken ? r = `${l}://${
|
|
452
|
+
const l = e.https === !1 ? "http" : "https";
|
|
453
|
+
e.oauthToken ? r = `${l}://${M(e.region)}/v1` : r = `${l}://${M(e.region)}/v2`;
|
|
539
454
|
}
|
|
540
455
|
const s = new Headers();
|
|
541
|
-
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([
|
|
542
|
-
s.set(
|
|
543
|
-
}), s.has(
|
|
544
|
-
|
|
545
|
-
|
|
456
|
+
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([l, a]) => {
|
|
457
|
+
s.set(l, a);
|
|
458
|
+
}), s.has(z) || (s.set(z, P.defaultAgentName), s.set(
|
|
459
|
+
P.defaultAgentVersion,
|
|
460
|
+
P.packageVersion
|
|
546
461
|
));
|
|
547
462
|
let o = 5;
|
|
548
|
-
e.oauthToken && (s.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit),
|
|
463
|
+
e.oauthToken && (s.set("Authorization", e.oauthToken), o = 3), e.rateLimit && (o = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = he(
|
|
549
464
|
this.throttledRequest.bind(this),
|
|
550
465
|
o,
|
|
551
466
|
1e3
|
|
552
|
-
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.
|
|
467
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.version = e.version || ve.DRAFT, this.inlineAssets = e.inlineAssets || !1, this.client = new be({
|
|
553
468
|
baseURL: r,
|
|
554
469
|
timeout: e.timeout || 0,
|
|
555
470
|
headers: s,
|
|
@@ -557,70 +472,58 @@ class He {
|
|
|
557
472
|
fetch: e.fetch
|
|
558
473
|
});
|
|
559
474
|
}
|
|
560
|
-
setComponentResolver(e) {
|
|
561
|
-
this.richTextResolver.addNode("blok", (t) => {
|
|
562
|
-
let r = "";
|
|
563
|
-
return t.attrs.body && t.attrs.body.forEach((s) => {
|
|
564
|
-
r += e(s.component, s);
|
|
565
|
-
}), {
|
|
566
|
-
html: r
|
|
567
|
-
};
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
475
|
parseParams(e) {
|
|
571
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
|
476
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = E[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
572
477
|
}
|
|
573
478
|
factoryParamOptions(e, t) {
|
|
574
|
-
return
|
|
479
|
+
return ue(e) ? this.parseParams(t) : t;
|
|
575
480
|
}
|
|
576
481
|
makeRequest(e, t, r, s, o) {
|
|
577
|
-
const
|
|
482
|
+
const l = this.factoryParamOptions(
|
|
578
483
|
e,
|
|
579
|
-
|
|
484
|
+
de(t, r, s)
|
|
580
485
|
);
|
|
581
|
-
return this.cacheResponse(e,
|
|
486
|
+
return this.cacheResponse(e, l, void 0, o);
|
|
582
487
|
}
|
|
583
|
-
get(e, t, r) {
|
|
488
|
+
get(e, t = {}, r) {
|
|
584
489
|
t || (t = {});
|
|
585
|
-
const s = `/${e}
|
|
490
|
+
const s = `/${e}`;
|
|
491
|
+
t.version = t.version || this.version;
|
|
492
|
+
const o = this.factoryParamOptions(s, t);
|
|
586
493
|
return this.cacheResponse(s, o, void 0, r);
|
|
587
494
|
}
|
|
588
|
-
async getAll(e, t, r, s) {
|
|
589
|
-
const o = (t == null ? void 0 : t.per_page) || 25,
|
|
590
|
-
|
|
495
|
+
async getAll(e, t = {}, r, s) {
|
|
496
|
+
const o = (t == null ? void 0 : t.per_page) || 25, l = `/${e}`.replace(/\/$/, ""), a = r ?? l.substring(l.lastIndexOf("/") + 1);
|
|
497
|
+
t.version = t.version || this.version;
|
|
498
|
+
const c = 1, h = await this.makeRequest(
|
|
499
|
+
l,
|
|
591
500
|
t,
|
|
592
501
|
o,
|
|
593
|
-
|
|
502
|
+
c,
|
|
594
503
|
s
|
|
595
|
-
),
|
|
596
|
-
|
|
597
|
-
(
|
|
504
|
+
), f = h.total ? Math.ceil(h.total / o) : 1, y = await ge(
|
|
505
|
+
ye(c, f),
|
|
506
|
+
(_) => this.makeRequest(l, t, o, _ + 1, s)
|
|
598
507
|
);
|
|
599
|
-
return
|
|
508
|
+
return me([h, ...y], (_) => Object.values(_.data[a]));
|
|
600
509
|
}
|
|
601
|
-
post(e, t, r) {
|
|
510
|
+
post(e, t = {}, r) {
|
|
602
511
|
const s = `/${e}`;
|
|
603
|
-
return
|
|
604
|
-
this.throttle("post", s, t, r)
|
|
605
|
-
);
|
|
512
|
+
return this.throttle("post", s, t, r);
|
|
606
513
|
}
|
|
607
|
-
put(e, t, r) {
|
|
514
|
+
put(e, t = {}, r) {
|
|
608
515
|
const s = `/${e}`;
|
|
609
|
-
return
|
|
610
|
-
this.throttle("put", s, t, r)
|
|
611
|
-
);
|
|
516
|
+
return this.throttle("put", s, t, r);
|
|
612
517
|
}
|
|
613
|
-
delete(e, t, r) {
|
|
518
|
+
delete(e, t = {}, r) {
|
|
614
519
|
t || (t = {});
|
|
615
520
|
const s = `/${e}`;
|
|
616
|
-
return
|
|
617
|
-
this.throttle("delete", s, t, r)
|
|
618
|
-
);
|
|
521
|
+
return this.throttle("delete", s, t, r);
|
|
619
522
|
}
|
|
620
|
-
getStories(e, t) {
|
|
523
|
+
getStories(e = {}, t) {
|
|
621
524
|
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
|
622
525
|
}
|
|
623
|
-
getStory(e, t, r) {
|
|
526
|
+
getStory(e, t = {}, r) {
|
|
624
527
|
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, r);
|
|
625
528
|
}
|
|
626
529
|
getToken() {
|
|
@@ -682,7 +585,7 @@ class He {
|
|
|
682
585
|
* allowing flexible specification of relation patterns.
|
|
683
586
|
*/
|
|
684
587
|
_insertRelations(e, t, r, s) {
|
|
685
|
-
if (Array.isArray(r) ? r.find((
|
|
588
|
+
if (Array.isArray(r) ? r.find((l) => l.endsWith(`.${t}`)) : r.endsWith(`.${t}`)) {
|
|
686
589
|
this._resolveField(e, t, s);
|
|
687
590
|
return;
|
|
688
591
|
}
|
|
@@ -696,14 +599,14 @@ class He {
|
|
|
696
599
|
* @param resolveId - The unique identifier for the current resolution context
|
|
697
600
|
*/
|
|
698
601
|
iterateTree(e, t, r) {
|
|
699
|
-
const s = (o,
|
|
602
|
+
const s = (o, l = "") => {
|
|
700
603
|
if (!(!o || o._stopResolving)) {
|
|
701
604
|
if (Array.isArray(o))
|
|
702
|
-
o.forEach((
|
|
605
|
+
o.forEach((a, c) => s(a, `${l}[${c}]`));
|
|
703
606
|
else if (typeof o == "object")
|
|
704
|
-
for (const
|
|
705
|
-
const
|
|
706
|
-
(o.component && o._uid || o.type === "link") && (this._insertRelations(o,
|
|
607
|
+
for (const a in o) {
|
|
608
|
+
const c = l ? `${l}.${a}` : a;
|
|
609
|
+
(o.component && o._uid || o.type === "link") && (this._insertRelations(o, a, t, r), this._insertLinks(o, a, r)), s(o[a], c);
|
|
707
610
|
}
|
|
708
611
|
}
|
|
709
612
|
};
|
|
@@ -712,18 +615,18 @@ class He {
|
|
|
712
615
|
async resolveLinks(e, t, r) {
|
|
713
616
|
let s = [];
|
|
714
617
|
if (e.link_uuids) {
|
|
715
|
-
const o = e.link_uuids.length,
|
|
716
|
-
for (let
|
|
717
|
-
const h = Math.min(o,
|
|
718
|
-
|
|
618
|
+
const o = e.link_uuids.length, l = [], a = 50;
|
|
619
|
+
for (let c = 0; c < o; c += a) {
|
|
620
|
+
const h = Math.min(o, c + a);
|
|
621
|
+
l.push(e.link_uuids.slice(c, h));
|
|
719
622
|
}
|
|
720
|
-
for (let
|
|
623
|
+
for (let c = 0; c < l.length; c++)
|
|
721
624
|
(await this.getStories({
|
|
722
|
-
per_page:
|
|
625
|
+
per_page: a,
|
|
723
626
|
language: t.language,
|
|
724
627
|
version: t.version,
|
|
725
628
|
starts_with: t.starts_with,
|
|
726
|
-
by_uuids:
|
|
629
|
+
by_uuids: l[c].join(",")
|
|
727
630
|
})).data.stories.forEach(
|
|
728
631
|
(h) => {
|
|
729
632
|
s.push(h);
|
|
@@ -741,18 +644,18 @@ class He {
|
|
|
741
644
|
async resolveRelations(e, t, r) {
|
|
742
645
|
let s = [];
|
|
743
646
|
if (e.rel_uuids) {
|
|
744
|
-
const o = e.rel_uuids.length,
|
|
745
|
-
for (let
|
|
746
|
-
const h = Math.min(o,
|
|
747
|
-
|
|
647
|
+
const o = e.rel_uuids.length, l = [], a = 50;
|
|
648
|
+
for (let c = 0; c < o; c += a) {
|
|
649
|
+
const h = Math.min(o, c + a);
|
|
650
|
+
l.push(e.rel_uuids.slice(c, h));
|
|
748
651
|
}
|
|
749
|
-
for (let
|
|
652
|
+
for (let c = 0; c < l.length; c++)
|
|
750
653
|
(await this.getStories({
|
|
751
|
-
per_page:
|
|
654
|
+
per_page: a,
|
|
752
655
|
language: t.language,
|
|
753
656
|
version: t.version,
|
|
754
657
|
starts_with: t.starts_with,
|
|
755
|
-
by_uuids:
|
|
658
|
+
by_uuids: l[c].join(","),
|
|
756
659
|
excluding_fields: t.excluding_fields
|
|
757
660
|
})).data.stories.forEach((h) => {
|
|
758
661
|
s.push(h);
|
|
@@ -778,53 +681,53 @@ class He {
|
|
|
778
681
|
*/
|
|
779
682
|
async resolveStories(e, t, r) {
|
|
780
683
|
var s, o;
|
|
781
|
-
let
|
|
782
|
-
if (this.links[r] = {}, this.relations[r] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (
|
|
783
|
-
for (const
|
|
684
|
+
let l = [];
|
|
685
|
+
if (this.links[r] = {}, this.relations[r] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (l = t.resolve_relations.split(",")), await this.resolveRelations(e, t, r)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((s = e.links) != null && s.length || (o = e.link_uuids) != null && o.length) && await this.resolveLinks(e, t, r), this.resolveNestedRelations)
|
|
686
|
+
for (const a in this.relations[r])
|
|
784
687
|
this.iterateTree(
|
|
785
|
-
this.relations[r][
|
|
786
|
-
|
|
688
|
+
this.relations[r][a],
|
|
689
|
+
l,
|
|
787
690
|
r
|
|
788
691
|
);
|
|
789
|
-
e.story ? this.iterateTree(e.story,
|
|
790
|
-
this.iterateTree(
|
|
692
|
+
e.story ? this.iterateTree(e.story, l, r) : e.stories.forEach((a) => {
|
|
693
|
+
this.iterateTree(a, l, r);
|
|
791
694
|
}), this.stringifiedStoriesCache = {}, delete this.links[r], delete this.relations[r];
|
|
792
695
|
}
|
|
793
696
|
async cacheResponse(e, t, r, s) {
|
|
794
|
-
const o =
|
|
697
|
+
const o = N({ url: e, params: t }), l = this.cacheProvider();
|
|
795
698
|
if (t.version === "published" && e !== "/cdn/spaces/me") {
|
|
796
|
-
const
|
|
797
|
-
if (
|
|
798
|
-
return Promise.resolve(
|
|
699
|
+
const a = await l.get(o);
|
|
700
|
+
if (a)
|
|
701
|
+
return Promise.resolve(a);
|
|
799
702
|
}
|
|
800
|
-
return new Promise(async (
|
|
703
|
+
return new Promise(async (a, c) => {
|
|
801
704
|
var h;
|
|
802
705
|
try {
|
|
803
|
-
const
|
|
706
|
+
const f = await this.throttle(
|
|
804
707
|
"get",
|
|
805
708
|
e,
|
|
806
709
|
t,
|
|
807
710
|
s
|
|
808
711
|
);
|
|
809
|
-
if (
|
|
810
|
-
return
|
|
811
|
-
let
|
|
812
|
-
if ((h =
|
|
813
|
-
perPage:
|
|
814
|
-
total:
|
|
815
|
-
})),
|
|
816
|
-
const
|
|
817
|
-
await this.resolveStories(
|
|
712
|
+
if (f.status !== 200)
|
|
713
|
+
return c(f);
|
|
714
|
+
let y = { data: f.data, headers: f.headers };
|
|
715
|
+
if ((h = f.headers) != null && h["per-page"] && (y = Object.assign({}, y, {
|
|
716
|
+
perPage: f.headers["per-page"] ? Number.parseInt(f.headers["per-page"]) : 0,
|
|
717
|
+
total: f.headers["per-page"] ? Number.parseInt(f.headers.total) : 0
|
|
718
|
+
})), y.data.story || y.data.stories) {
|
|
719
|
+
const A = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
720
|
+
await this.resolveStories(y.data, t, `${A}`), y = await this.processInlineAssets(y);
|
|
818
721
|
}
|
|
819
|
-
t.version === "published" && e !== "/cdn/spaces/me" && await
|
|
820
|
-
const
|
|
821
|
-
return t.token &&
|
|
822
|
-
} catch (
|
|
823
|
-
if (
|
|
722
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await l.set(o, y);
|
|
723
|
+
const _ = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
724
|
+
return t.token && y.data.cv && (_ && E[t.token] && E[t.token] !== y.data.cv && await this.flushCache(), E[t.token] = y.data.cv), a(y);
|
|
725
|
+
} catch (f) {
|
|
726
|
+
if (f.response && f.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
|
|
824
727
|
return console.log(
|
|
825
728
|
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
|
826
|
-
), await
|
|
827
|
-
|
|
729
|
+
), await pe(this.retriesDelay), this.cacheResponse(e, t, r).then(a).catch(c);
|
|
730
|
+
c(f);
|
|
828
731
|
}
|
|
829
732
|
});
|
|
830
733
|
}
|
|
@@ -832,32 +735,32 @@ class He {
|
|
|
832
735
|
return this.client.setFetchOptions(s), this.client[e](t, r);
|
|
833
736
|
}
|
|
834
737
|
cacheVersions() {
|
|
835
|
-
return
|
|
738
|
+
return E;
|
|
836
739
|
}
|
|
837
740
|
cacheVersion() {
|
|
838
|
-
return
|
|
741
|
+
return E[this.accessToken];
|
|
839
742
|
}
|
|
840
743
|
setCacheVersion(e) {
|
|
841
|
-
this.accessToken && (
|
|
744
|
+
this.accessToken && (E[this.accessToken] = e);
|
|
842
745
|
}
|
|
843
746
|
clearCacheVersion() {
|
|
844
|
-
this.accessToken && (
|
|
747
|
+
this.accessToken && (E[this.accessToken] = 0);
|
|
845
748
|
}
|
|
846
749
|
cacheProvider() {
|
|
847
750
|
switch (this.cache.type) {
|
|
848
751
|
case "memory":
|
|
849
752
|
return {
|
|
850
753
|
get(e) {
|
|
851
|
-
return Promise.resolve(
|
|
754
|
+
return Promise.resolve(j[e]);
|
|
852
755
|
},
|
|
853
756
|
getAll() {
|
|
854
|
-
return Promise.resolve(
|
|
757
|
+
return Promise.resolve(j);
|
|
855
758
|
},
|
|
856
759
|
set(e, t) {
|
|
857
|
-
return
|
|
760
|
+
return j[e] = t, Promise.resolve(void 0);
|
|
858
761
|
},
|
|
859
762
|
flush() {
|
|
860
|
-
return
|
|
763
|
+
return j = {}, Promise.resolve(void 0);
|
|
861
764
|
}
|
|
862
765
|
};
|
|
863
766
|
case "custom":
|
|
@@ -883,8 +786,27 @@ class He {
|
|
|
883
786
|
async flushCache() {
|
|
884
787
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
885
788
|
}
|
|
789
|
+
async processInlineAssets(e) {
|
|
790
|
+
if (!this.inlineAssets)
|
|
791
|
+
return e;
|
|
792
|
+
const t = (r) => {
|
|
793
|
+
if (!r || typeof r != "object")
|
|
794
|
+
return r;
|
|
795
|
+
if (Array.isArray(r))
|
|
796
|
+
return r.map((o) => t(o));
|
|
797
|
+
let s = { ...r };
|
|
798
|
+
s.fieldtype === "asset" && Array.isArray(e.data.assets) && (s = {
|
|
799
|
+
...s,
|
|
800
|
+
...e.data.assets.find((o) => o.id === s.id)
|
|
801
|
+
});
|
|
802
|
+
for (const o in s)
|
|
803
|
+
typeof s[o] == "object" && (s[o] = t(s[o]));
|
|
804
|
+
return s;
|
|
805
|
+
};
|
|
806
|
+
return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((r) => (r.content = t(r.content), r))), e;
|
|
807
|
+
}
|
|
886
808
|
}
|
|
887
|
-
const
|
|
809
|
+
const we = (n = {}) => {
|
|
888
810
|
const { apiOptions: e } = n;
|
|
889
811
|
if (!e || !e.accessToken) {
|
|
890
812
|
console.error(
|
|
@@ -892,8 +814,8 @@ const Fe = (n = {}) => {
|
|
|
892
814
|
);
|
|
893
815
|
return;
|
|
894
816
|
}
|
|
895
|
-
return { storyblokApi: new
|
|
896
|
-
},
|
|
817
|
+
return { storyblokApi: new ke(e) };
|
|
818
|
+
}, Te = (n) => {
|
|
897
819
|
if (typeof n != "object" || typeof n._editable > "u")
|
|
898
820
|
return {};
|
|
899
821
|
try {
|
|
@@ -908,313 +830,56 @@ const Fe = (n = {}) => {
|
|
|
908
830
|
return {};
|
|
909
831
|
}
|
|
910
832
|
};
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
return { src: n, attrs: {} };
|
|
914
|
-
let t = 0, r = 0;
|
|
915
|
-
const s = {}, o = [];
|
|
916
|
-
function a(i, h, d, p, b) {
|
|
917
|
-
typeof i != "number" || i <= h || i >= d ? console.warn(`[StoryblokRichText] - ${p.charAt(0).toUpperCase() + p.slice(1)} value must be a number between ${h} and ${d} (inclusive)`) : b.push(`${p}(${i})`);
|
|
918
|
-
}
|
|
919
|
-
if (typeof e == "object") {
|
|
920
|
-
if (typeof e.width == "number" && e.width > 0 ? (s.width = e.width, t = e.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than 0"), e.height && typeof e.height == "number" && e.height > 0 ? (s.height = e.height, r = e.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than 0"), e.loading && ["lazy", "eager"].includes(e.loading) && (s.loading = e.loading), e.class && (s.class = e.class), e.filters) {
|
|
921
|
-
const { filters: i } = e || {}, { blur: h, brightness: d, fill: p, format: b, grayscale: E, quality: y, rotate: S } = i || {};
|
|
922
|
-
h && a(h, 0, 100, "blur", o), y && a(y, 0, 100, "quality", o), d && a(d, 0, 100, "brightness", o), p && o.push(`fill(${p})`), E && o.push("grayscale()"), S && [0, 90, 180, 270].includes(e.filters.rotate || 0) && o.push(`rotate(${S})`), b && ["webp", "png", "jpeg"].includes(b) && o.push(`format(${b})`);
|
|
923
|
-
}
|
|
924
|
-
e.srcset && (s.srcset = e.srcset.map((i) => {
|
|
925
|
-
if (typeof i == "number")
|
|
926
|
-
return `${n}/m/${i}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${i}w`;
|
|
927
|
-
if (Array.isArray(i) && i.length === 2) {
|
|
928
|
-
const [h, d] = i;
|
|
929
|
-
return `${n}/m/${h}x${d}/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${h}w`;
|
|
930
|
-
} else {
|
|
931
|
-
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
932
|
-
return;
|
|
933
|
-
}
|
|
934
|
-
}).join(", ")), e.sizes && (s.sizes = e.sizes.join(", "));
|
|
935
|
-
}
|
|
936
|
-
let l = `${n}/m/`;
|
|
937
|
-
return t > 0 && r > 0 && (l = `${l}${t}x${r}/`), o.length > 0 && (l = `${l}filters:${o.join(":")}`), {
|
|
938
|
-
src: l,
|
|
939
|
-
attrs: s
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
var T = /* @__PURE__ */ ((n) => (n.DOCUMENT = "doc", n.HEADING = "heading", n.PARAGRAPH = "paragraph", n.QUOTE = "blockquote", n.OL_LIST = "ordered_list", n.UL_LIST = "bullet_list", n.LIST_ITEM = "list_item", n.CODE_BLOCK = "code_block", n.HR = "horizontal_rule", n.BR = "hard_break", n.IMAGE = "image", n.EMOJI = "emoji", n.COMPONENT = "blok", n.TABLE = "table", n.TABLE_ROW = "tableRow", n.TABLE_CELL = "tableCell", n.TABLE_HEADER = "tableHeader", n))(T || {}), _ = /* @__PURE__ */ ((n) => (n.BOLD = "bold", n.STRONG = "strong", n.STRIKE = "strike", n.UNDERLINE = "underline", n.ITALIC = "italic", n.CODE = "code", n.LINK = "link", n.ANCHOR = "anchor", n.STYLED = "styled", n.SUPERSCRIPT = "superscript", n.SUBSCRIPT = "subscript", n.TEXT_STYLE = "textStyle", n.HIGHLIGHT = "highlight", n))(_ || {}), J = /* @__PURE__ */ ((n) => (n.TEXT = "text", n))(J || {}), x = /* @__PURE__ */ ((n) => (n.URL = "url", n.STORY = "story", n.ASSET = "asset", n.EMAIL = "email", n))(x || {});
|
|
943
|
-
const Ue = [
|
|
944
|
-
"area",
|
|
945
|
-
"base",
|
|
946
|
-
"br",
|
|
947
|
-
"col",
|
|
948
|
-
"embed",
|
|
949
|
-
"hr",
|
|
950
|
-
"img",
|
|
951
|
-
"input",
|
|
952
|
-
"link",
|
|
953
|
-
"meta",
|
|
954
|
-
"param",
|
|
955
|
-
"source",
|
|
956
|
-
"track",
|
|
957
|
-
"wbr"
|
|
958
|
-
], Be = (n = {}) => Object.keys(n).map((e) => `${e}="${n[e]}"`).join(" "), ze = (n = {}) => Object.keys(n).map((e) => `${e}: ${n[e]}`).join("; ");
|
|
959
|
-
function De(n) {
|
|
960
|
-
return n.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
961
|
-
}
|
|
962
|
-
const L = (n) => Object.fromEntries(Object.entries(n).filter(([e, t]) => t !== void 0));
|
|
963
|
-
function G(n, e = {}, t) {
|
|
964
|
-
const r = Be(e), s = r ? `${n} ${r}` : n, o = Array.isArray(t) ? t.join("") : t || "";
|
|
965
|
-
if (n) {
|
|
966
|
-
if (Ue.includes(n))
|
|
967
|
-
return `<${s}>`;
|
|
968
|
-
} else return o;
|
|
969
|
-
return `<${s}>${o}</${n}>`;
|
|
970
|
-
}
|
|
971
|
-
function Ve(n = {}) {
|
|
972
|
-
const e = /* @__PURE__ */ new Map(), {
|
|
973
|
-
renderFn: t = G,
|
|
974
|
-
textFn: r = De,
|
|
975
|
-
resolvers: s = {},
|
|
976
|
-
optimizeImages: o = !1,
|
|
977
|
-
keyedResolvers: a = !1
|
|
978
|
-
} = n, l = t !== G, i = () => ({ render: (c, u = {}, g) => {
|
|
979
|
-
if (a && c) {
|
|
980
|
-
const f = e.get(c) || 0;
|
|
981
|
-
e.set(c, f + 1), u.key = `${c}-${f}`;
|
|
982
|
-
}
|
|
983
|
-
return t(c, u, g);
|
|
984
|
-
} }), h = (c) => (u, g) => {
|
|
985
|
-
const f = u.attrs || {};
|
|
986
|
-
return g.render(c, f, u.children || null);
|
|
987
|
-
}, d = (c, u) => {
|
|
988
|
-
const { src: g, alt: f, title: v, srcset: $, sizes: k } = c.attrs || {};
|
|
989
|
-
let w = g, R = {};
|
|
990
|
-
if (o) {
|
|
991
|
-
const { src: re, attrs: se } = Me(g, o);
|
|
992
|
-
w = re, R = se;
|
|
993
|
-
}
|
|
994
|
-
const te = {
|
|
995
|
-
src: w,
|
|
996
|
-
alt: f,
|
|
997
|
-
title: v,
|
|
998
|
-
srcset: $,
|
|
999
|
-
sizes: k,
|
|
1000
|
-
...R
|
|
1001
|
-
};
|
|
1002
|
-
return u.render("img", L(te));
|
|
1003
|
-
}, p = (c, u) => {
|
|
1004
|
-
const { level: g, ...f } = c.attrs || {};
|
|
1005
|
-
return u.render(`h${g}`, f, c.children);
|
|
1006
|
-
}, b = (c, u) => {
|
|
1007
|
-
var g, f, v, $;
|
|
1008
|
-
const k = u.render("img", {
|
|
1009
|
-
src: (g = c.attrs) == null ? void 0 : g.fallbackImage,
|
|
1010
|
-
alt: (f = c.attrs) == null ? void 0 : f.alt,
|
|
1011
|
-
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
|
1012
|
-
draggable: "false",
|
|
1013
|
-
loading: "lazy"
|
|
1014
|
-
});
|
|
1015
|
-
return u.render("span", {
|
|
1016
|
-
"data-type": "emoji",
|
|
1017
|
-
"data-name": (v = c.attrs) == null ? void 0 : v.name,
|
|
1018
|
-
"data-emoji": ($ = c.attrs) == null ? void 0 : $.emoji
|
|
1019
|
-
}, k);
|
|
1020
|
-
}, E = (c, u) => u.render(
|
|
1021
|
-
"pre",
|
|
1022
|
-
c.attrs || {},
|
|
1023
|
-
u.render("code", {}, c.children || "")
|
|
1024
|
-
), y = (c, u = !1) => ({ text: g, attrs: f }, v) => {
|
|
1025
|
-
const { class: $, id: k, ...w } = f || {}, R = u ? {
|
|
1026
|
-
class: $,
|
|
1027
|
-
id: k,
|
|
1028
|
-
style: ze(w) || void 0
|
|
1029
|
-
} : f || {};
|
|
1030
|
-
return v.render(c, L(R), g);
|
|
1031
|
-
}, S = (c) => N(c), I = (c) => {
|
|
1032
|
-
const { marks: u, ...g } = c;
|
|
1033
|
-
if ("text" in c) {
|
|
1034
|
-
if (u)
|
|
1035
|
-
return u.reduce(
|
|
1036
|
-
(v, $) => S({ ...$, text: v }),
|
|
1037
|
-
S({ ...g, children: g.children })
|
|
1038
|
-
);
|
|
1039
|
-
const f = c.attrs || {};
|
|
1040
|
-
if (a) {
|
|
1041
|
-
const v = e.get("txt") || 0;
|
|
1042
|
-
e.set("txt", v + 1), f.key = `txt-${v}`;
|
|
1043
|
-
}
|
|
1044
|
-
return r(g.text, f);
|
|
1045
|
-
}
|
|
1046
|
-
return "";
|
|
1047
|
-
}, B = (c, u) => {
|
|
1048
|
-
const { linktype: g, href: f, anchor: v, ...$ } = c.attrs || {};
|
|
1049
|
-
let k = "";
|
|
1050
|
-
switch (g) {
|
|
1051
|
-
case x.ASSET:
|
|
1052
|
-
case x.URL:
|
|
1053
|
-
k = f;
|
|
1054
|
-
break;
|
|
1055
|
-
case x.EMAIL:
|
|
1056
|
-
k = `mailto:${f}`;
|
|
1057
|
-
break;
|
|
1058
|
-
case x.STORY:
|
|
1059
|
-
k = f, v && (k = `${k}#${v}`);
|
|
1060
|
-
break;
|
|
1061
|
-
default:
|
|
1062
|
-
k = f;
|
|
1063
|
-
break;
|
|
1064
|
-
}
|
|
1065
|
-
const w = { ...$ };
|
|
1066
|
-
return k && (w.href = k), u.render("a", w, c.text);
|
|
1067
|
-
}, Y = (c, u) => {
|
|
1068
|
-
var g, f;
|
|
1069
|
-
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), u.render("span", {
|
|
1070
|
-
blok: (g = c == null ? void 0 : c.attrs) == null ? void 0 : g.body[0],
|
|
1071
|
-
id: (f = c.attrs) == null ? void 0 : f.id,
|
|
1072
|
-
style: "display: none"
|
|
1073
|
-
});
|
|
1074
|
-
}, W = (c, u) => {
|
|
1075
|
-
const g = {}, f = u.render("tbody", {}, c.children);
|
|
1076
|
-
return u.render("table", g, f);
|
|
1077
|
-
}, X = (c, u) => {
|
|
1078
|
-
const g = {};
|
|
1079
|
-
return u.render("tr", g, c.children);
|
|
1080
|
-
}, Q = (c, u) => {
|
|
1081
|
-
const { colspan: g, rowspan: f, colwidth: v, backgroundColor: $, ...k } = c.attrs || {}, w = {
|
|
1082
|
-
...k
|
|
1083
|
-
};
|
|
1084
|
-
g > 1 && (w.colspan = g), f > 1 && (w.rowspan = f);
|
|
1085
|
-
const R = [];
|
|
1086
|
-
return v && R.push(`width: ${v}px;`), $ && R.push(`background-color: ${$};`), R.length > 0 && (w.style = R.join(" ")), u.render("td", L(w), c.children);
|
|
1087
|
-
}, Z = (c, u) => {
|
|
1088
|
-
const { colspan: g, rowspan: f, colwidth: v, backgroundColor: $, ...k } = c.attrs || {}, w = {
|
|
1089
|
-
...k
|
|
1090
|
-
};
|
|
1091
|
-
g > 1 && (w.colspan = g), f > 1 && (w.rowspan = f);
|
|
1092
|
-
const R = [];
|
|
1093
|
-
return v && R.push(`width: ${v}px;`), $ && R.push(`background-color: ${$};`), R.length > 0 && (w.style = R.join(" ")), u.render("th", L(w), c.children);
|
|
1094
|
-
}, ee = new Map([
|
|
1095
|
-
[T.DOCUMENT, h("")],
|
|
1096
|
-
[T.HEADING, p],
|
|
1097
|
-
[T.PARAGRAPH, h("p")],
|
|
1098
|
-
[T.UL_LIST, h("ul")],
|
|
1099
|
-
[T.OL_LIST, h("ol")],
|
|
1100
|
-
[T.LIST_ITEM, h("li")],
|
|
1101
|
-
[T.IMAGE, d],
|
|
1102
|
-
[T.EMOJI, b],
|
|
1103
|
-
[T.CODE_BLOCK, E],
|
|
1104
|
-
[T.HR, h("hr")],
|
|
1105
|
-
[T.BR, h("br")],
|
|
1106
|
-
[T.QUOTE, h("blockquote")],
|
|
1107
|
-
[T.COMPONENT, Y],
|
|
1108
|
-
[J.TEXT, I],
|
|
1109
|
-
[_.LINK, B],
|
|
1110
|
-
[_.ANCHOR, B],
|
|
1111
|
-
[_.STYLED, y("span", !0)],
|
|
1112
|
-
[_.BOLD, y("strong")],
|
|
1113
|
-
[_.TEXT_STYLE, y("span", !0)],
|
|
1114
|
-
[_.ITALIC, y("em")],
|
|
1115
|
-
[_.UNDERLINE, y("u")],
|
|
1116
|
-
[_.STRIKE, y("s")],
|
|
1117
|
-
[_.CODE, y("code")],
|
|
1118
|
-
[_.SUPERSCRIPT, y("sup")],
|
|
1119
|
-
[_.SUBSCRIPT, y("sub")],
|
|
1120
|
-
[_.HIGHLIGHT, y("mark")],
|
|
1121
|
-
[T.TABLE, W],
|
|
1122
|
-
[T.TABLE_ROW, X],
|
|
1123
|
-
[T.TABLE_CELL, Q],
|
|
1124
|
-
[T.TABLE_HEADER, Z],
|
|
1125
|
-
...Object.entries(s).map(([c, u]) => [c, u])
|
|
1126
|
-
]);
|
|
1127
|
-
function A(c) {
|
|
1128
|
-
const u = ee.get(c.type);
|
|
1129
|
-
if (!u)
|
|
1130
|
-
return console.error("<Storyblok>", `No resolver found for node type ${c.type}`), "";
|
|
1131
|
-
const g = i();
|
|
1132
|
-
if (c.type === "text")
|
|
1133
|
-
return u(c, g);
|
|
1134
|
-
const f = c.content ? c.content.map(N) : void 0;
|
|
1135
|
-
return u({
|
|
1136
|
-
...c,
|
|
1137
|
-
children: f
|
|
1138
|
-
}, g);
|
|
1139
|
-
}
|
|
1140
|
-
function N(c) {
|
|
1141
|
-
return c.type === "doc" ? l ? c.content.map(A) : c.content.map(A).join("") : Array.isArray(c) ? c.map(A) : A(c);
|
|
1142
|
-
}
|
|
1143
|
-
return {
|
|
1144
|
-
render: N
|
|
1145
|
-
};
|
|
1146
|
-
}
|
|
1147
|
-
let M, U = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
1148
|
-
const Je = (n, e, t = {}) => {
|
|
833
|
+
let x = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
834
|
+
const _e = (n, e, t = {}) => {
|
|
1149
835
|
var r;
|
|
1150
836
|
const s = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = new URL((r = window.location) == null ? void 0 : r.href).searchParams.get(
|
|
1151
837
|
"_storyblok"
|
|
1152
|
-
),
|
|
1153
|
-
if (!(!s || !
|
|
838
|
+
), l = o !== null && +o === n;
|
|
839
|
+
if (!(!s || !l)) {
|
|
1154
840
|
if (!n) {
|
|
1155
841
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
1156
842
|
return;
|
|
1157
843
|
}
|
|
1158
844
|
window.storyblokRegisterEvent(() => {
|
|
1159
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
|
1160
|
-
var
|
|
1161
|
-
|
|
845
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (a) => {
|
|
846
|
+
var c;
|
|
847
|
+
a && (a.action === "input" && ((c = a.story) == null ? void 0 : c.id) === n ? e(a.story) : (a.action === "change" || a.action === "published") && a.storyId === n && window.location.reload());
|
|
1162
848
|
});
|
|
1163
849
|
});
|
|
1164
850
|
}
|
|
1165
|
-
},
|
|
1166
|
-
n.addNode("blok", (t) => {
|
|
1167
|
-
let r = "";
|
|
1168
|
-
return t.attrs.body.forEach((s) => {
|
|
1169
|
-
r += e(s.component, s);
|
|
1170
|
-
}), {
|
|
1171
|
-
html: r
|
|
1172
|
-
};
|
|
1173
|
-
});
|
|
1174
|
-
}, Ke = (n = {}) => {
|
|
851
|
+
}, $e = (n = {}) => {
|
|
1175
852
|
var e, t;
|
|
1176
853
|
const {
|
|
1177
854
|
bridge: r,
|
|
1178
855
|
accessToken: s,
|
|
1179
856
|
use: o = [],
|
|
1180
|
-
apiOptions:
|
|
1181
|
-
|
|
1182
|
-
bridgeUrl: i
|
|
857
|
+
apiOptions: l = {},
|
|
858
|
+
bridgeUrl: a
|
|
1183
859
|
} = n;
|
|
1184
|
-
|
|
1185
|
-
const
|
|
1186
|
-
let
|
|
1187
|
-
o.forEach((
|
|
1188
|
-
|
|
1189
|
-
}),
|
|
1190
|
-
const
|
|
1191
|
-
return r !== !1 &&
|
|
1192
|
-
}
|
|
1193
|
-
|
|
1194
|
-
return
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
if (!r) {
|
|
1198
|
-
console.error(
|
|
1199
|
-
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
1200
|
-
);
|
|
1201
|
-
return;
|
|
1202
|
-
}
|
|
1203
|
-
return qe(n) ? "" : (e && (r = new P(e.schema), e.resolver && K(r, e.resolver)), r.render(n, {}, !1));
|
|
1204
|
-
}, We = () => V(U);
|
|
860
|
+
l.accessToken = l.accessToken || s;
|
|
861
|
+
const c = { bridge: r, apiOptions: l };
|
|
862
|
+
let h = {};
|
|
863
|
+
o.forEach((y) => {
|
|
864
|
+
h = { ...h, ...y(c) };
|
|
865
|
+
}), a && (x = a);
|
|
866
|
+
const f = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
867
|
+
return r !== !1 && f && G(x), h;
|
|
868
|
+
};
|
|
869
|
+
function Re(n, e) {
|
|
870
|
+
return ie(e).render(n);
|
|
871
|
+
}
|
|
872
|
+
const Ee = () => G(x);
|
|
1205
873
|
export {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
Ge as storyblokEditable,
|
|
1218
|
-
Ke as storyblokInit,
|
|
1219
|
-
Je as useStoryblokBridge
|
|
874
|
+
v as BlockTypes,
|
|
875
|
+
R as MarkTypes,
|
|
876
|
+
F as TextTypes,
|
|
877
|
+
we as apiPlugin,
|
|
878
|
+
Ee as loadStoryblokBridge,
|
|
879
|
+
_e as registerStoryblokBridge,
|
|
880
|
+
Re as renderRichText,
|
|
881
|
+
ie as richTextResolver,
|
|
882
|
+
Te as storyblokEditable,
|
|
883
|
+
$e as storyblokInit,
|
|
884
|
+
_e as useStoryblokBridge
|
|
1220
885
|
};
|