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