@storyblok/js 4.4.1 → 4.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/storyblok-js.js +1 -1
- package/dist/storyblok-js.mjs +499 -413
- package/package.json +3 -3
package/dist/storyblok-js.mjs
CHANGED
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using JavaScript.
|
|
5
5
|
* author: undefined
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var m = (e, t,
|
|
10
|
-
let
|
|
7
|
+
var ce = Object.defineProperty;
|
|
8
|
+
var ue = (e, t, r) => t in e ? ce(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
9
|
+
var m = (e, t, r) => ue(e, typeof t != "symbol" ? t + "" : t, r);
|
|
10
|
+
let v = /* @__PURE__ */ function(e) {
|
|
11
11
|
return e.DOCUMENT = "doc", e.HEADING = "heading", e.PARAGRAPH = "paragraph", e.QUOTE = "blockquote", e.OL_LIST = "ordered_list", e.UL_LIST = "bullet_list", e.LIST_ITEM = "list_item", e.CODE_BLOCK = "code_block", e.HR = "horizontal_rule", e.BR = "hard_break", e.IMAGE = "image", e.EMOJI = "emoji", e.COMPONENT = "blok", e.TABLE = "table", e.TABLE_ROW = "tableRow", e.TABLE_CELL = "tableCell", e.TABLE_HEADER = "tableHeader", e;
|
|
12
|
-
}({}),
|
|
12
|
+
}({}), w = /* @__PURE__ */ function(e) {
|
|
13
13
|
return e.BOLD = "bold", e.STRONG = "strong", e.STRIKE = "strike", e.UNDERLINE = "underline", e.ITALIC = "italic", e.CODE = "code", e.LINK = "link", e.ANCHOR = "anchor", e.STYLED = "styled", e.SUPERSCRIPT = "superscript", e.SUBSCRIPT = "subscript", e.TEXT_STYLE = "textStyle", e.HIGHLIGHT = "highlight", e;
|
|
14
|
-
}({}),
|
|
14
|
+
}({}), he = /* @__PURE__ */ function(e) {
|
|
15
15
|
return e.TEXT = "text", e;
|
|
16
|
-
}({}),
|
|
16
|
+
}({}), x = /* @__PURE__ */ function(e) {
|
|
17
17
|
return e.URL = "url", e.STORY = "story", e.ASSET = "asset", e.EMAIL = "email", e;
|
|
18
18
|
}({});
|
|
19
|
-
const
|
|
19
|
+
const de = [
|
|
20
20
|
"area",
|
|
21
21
|
"base",
|
|
22
22
|
"br",
|
|
@@ -31,251 +31,251 @@ const oe = [
|
|
|
31
31
|
"source",
|
|
32
32
|
"track",
|
|
33
33
|
"wbr"
|
|
34
|
-
],
|
|
35
|
-
const { custom: t, ...
|
|
36
|
-
...
|
|
34
|
+
], fe = (e = {}) => {
|
|
35
|
+
const { custom: t, ...r } = e, s = {
|
|
36
|
+
...r,
|
|
37
37
|
...t
|
|
38
38
|
};
|
|
39
|
-
return Object.keys(
|
|
40
|
-
},
|
|
41
|
-
function
|
|
39
|
+
return Object.keys(s).map((i) => `${i}="${s[i]}"`).join(" ");
|
|
40
|
+
}, ge = (e = {}) => Object.keys(e).map((t) => `${t}: ${e[t]}`).join("; ");
|
|
41
|
+
function ye(e) {
|
|
42
42
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
43
43
|
}
|
|
44
|
-
const
|
|
45
|
-
function
|
|
44
|
+
const O = (e) => Object.fromEntries(Object.entries(e).filter(([t, r]) => r !== void 0));
|
|
45
|
+
function be(e, t) {
|
|
46
46
|
if (!t) return {
|
|
47
47
|
src: e,
|
|
48
48
|
attrs: {}
|
|
49
49
|
};
|
|
50
|
-
let
|
|
50
|
+
let r = 0, s = 0;
|
|
51
51
|
const i = {}, n = [];
|
|
52
|
-
function
|
|
53
|
-
typeof u != "number" || u <=
|
|
52
|
+
function l(u, c, f, y, A) {
|
|
53
|
+
typeof u != "number" || u <= c || u >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${c} and ${f} (inclusive)`) : A.push(`${y}(${u})`);
|
|
54
54
|
}
|
|
55
55
|
if (typeof t == "object") {
|
|
56
|
-
if (t.width !== void 0 && (typeof t.width == "number" && t.width >= 0 ? (i.width = t.width,
|
|
57
|
-
const { filters: u } = t || {}, { blur:
|
|
58
|
-
|
|
56
|
+
if (t.width !== void 0 && (typeof t.width == "number" && t.width >= 0 ? (i.width = t.width, r = t.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")), t.height !== void 0 && (typeof t.height == "number" && t.height >= 0 ? (i.height = t.height, s = t.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")), t.height === 0 && t.width === 0 && (delete i.width, delete i.height, console.warn("[StoryblokRichText] - Width and height values cannot both be 0")), t.loading && ["lazy", "eager"].includes(t.loading) && (i.loading = t.loading), t.class && (i.class = t.class), t.filters) {
|
|
57
|
+
const { filters: u } = t || {}, { blur: c, brightness: f, fill: y, format: A, grayscale: S, quality: E, rotate: T } = u || {};
|
|
58
|
+
c && l(c, 0, 100, "blur", n), E && l(E, 0, 100, "quality", n), f && l(f, 0, 100, "brightness", n), y && n.push(`fill(${y})`), S && n.push("grayscale()"), T && [
|
|
59
59
|
0,
|
|
60
60
|
90,
|
|
61
61
|
180,
|
|
62
62
|
270
|
|
63
|
-
].includes(t.filters.rotate || 0) && n.push(`rotate(${T})`),
|
|
63
|
+
].includes(t.filters.rotate || 0) && n.push(`rotate(${T})`), A && [
|
|
64
64
|
"webp",
|
|
65
65
|
"png",
|
|
66
66
|
"jpeg"
|
|
67
|
-
].includes(
|
|
67
|
+
].includes(A) && n.push(`format(${A})`);
|
|
68
68
|
}
|
|
69
69
|
t.srcset && (i.srcset = t.srcset.map((u) => {
|
|
70
70
|
if (typeof u == "number") return `${e}/m/${u}x0/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${u}w`;
|
|
71
71
|
if (Array.isArray(u) && u.length === 2) {
|
|
72
|
-
const [
|
|
73
|
-
return `${e}/m/${
|
|
72
|
+
const [c, f] = u;
|
|
73
|
+
return `${e}/m/${c}x${f}/${n.length > 0 ? `filters:${n.join(":")}` : ""} ${c}w`;
|
|
74
74
|
} else {
|
|
75
75
|
console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
78
|
}).join(", ")), t.sizes && (i.sizes = t.sizes.join(", "));
|
|
79
79
|
}
|
|
80
|
-
let
|
|
81
|
-
return (
|
|
82
|
-
src:
|
|
80
|
+
let a = `${e}/m/`;
|
|
81
|
+
return (r > 0 || s > 0) && (a = `${a}${r}x${s}/`), n.length > 0 && (a = `${a}filters:${n.join(":")}`), {
|
|
82
|
+
src: a,
|
|
83
83
|
attrs: i
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
const
|
|
86
|
+
function V(e, t = {}, r) {
|
|
87
|
+
const s = fe(t), i = s ? `${e} ${s}` : e, n = Array.isArray(r) ? r.join("") : r || "";
|
|
88
88
|
if (e) {
|
|
89
|
-
if (
|
|
89
|
+
if (de.includes(e)) return `<${i}>`;
|
|
90
90
|
} else return n;
|
|
91
91
|
return `<${i}>${n}</${e}>`;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
const t = /* @__PURE__ */ new Map(), { renderFn:
|
|
95
|
-
const { textAlign: h, class: d, id:
|
|
96
|
-
return
|
|
97
|
-
...
|
|
93
|
+
function me(e = {}) {
|
|
94
|
+
const t = /* @__PURE__ */ new Map(), { renderFn: r = V, textFn: s = ye, resolvers: i = {}, optimizeImages: n = !1, keyedResolvers: l = !1 } = e, a = r !== V, u = (o = {}) => {
|
|
95
|
+
const { textAlign: h, class: d, id: g, style: b, ...R } = o, p = [];
|
|
96
|
+
return b && p.push(b.endsWith(";") ? b : `${b};`), h && p.push(`text-align: ${h};`), O({
|
|
97
|
+
...R,
|
|
98
98
|
class: d,
|
|
99
|
-
id:
|
|
100
|
-
...
|
|
99
|
+
id: g,
|
|
100
|
+
...p.length > 0 ? { style: p.join(" ") } : {}
|
|
101
101
|
});
|
|
102
|
-
},
|
|
103
|
-
const
|
|
104
|
-
return d.render(o,
|
|
105
|
-
},
|
|
106
|
-
const { src: d, alt:
|
|
107
|
-
let
|
|
102
|
+
}, c = (o) => (h, d) => {
|
|
103
|
+
const g = u(h.attrs);
|
|
104
|
+
return d.render(o, g, h.children || null);
|
|
105
|
+
}, f = (o, h) => {
|
|
106
|
+
const { src: d, alt: g, title: b, srcset: R, sizes: p } = o.attrs || {};
|
|
107
|
+
let k = d, _ = {};
|
|
108
108
|
if (n) {
|
|
109
|
-
const { src:
|
|
110
|
-
|
|
109
|
+
const { src: ae, attrs: le } = be(d, n);
|
|
110
|
+
k = ae, _ = le;
|
|
111
111
|
}
|
|
112
|
-
const
|
|
113
|
-
src:
|
|
114
|
-
alt:
|
|
115
|
-
title:
|
|
116
|
-
srcset:
|
|
117
|
-
sizes:
|
|
118
|
-
...
|
|
112
|
+
const C = {
|
|
113
|
+
src: k,
|
|
114
|
+
alt: g,
|
|
115
|
+
title: b,
|
|
116
|
+
srcset: R,
|
|
117
|
+
sizes: p,
|
|
118
|
+
..._
|
|
119
119
|
};
|
|
120
|
-
return h.render("img", C
|
|
121
|
-
},
|
|
122
|
-
const { level: d, ...
|
|
123
|
-
return h.render(`h${d}`,
|
|
124
|
-
},
|
|
125
|
-
var
|
|
120
|
+
return h.render("img", O(C));
|
|
121
|
+
}, y = (o, h) => {
|
|
122
|
+
const { level: d, ...g } = o.attrs || {}, b = u(g);
|
|
123
|
+
return h.render(`h${d}`, b, o.children);
|
|
124
|
+
}, A = (o, h) => {
|
|
125
|
+
var g, b, R, p;
|
|
126
126
|
const d = h.render("img", {
|
|
127
|
-
src: (
|
|
128
|
-
alt: (
|
|
127
|
+
src: (g = o.attrs) == null ? void 0 : g.fallbackImage,
|
|
128
|
+
alt: (b = o.attrs) == null ? void 0 : b.alt,
|
|
129
129
|
style: "width: 1.25em; height: 1.25em; vertical-align: text-top",
|
|
130
130
|
draggable: "false",
|
|
131
131
|
loading: "lazy"
|
|
132
132
|
});
|
|
133
133
|
return h.render("span", {
|
|
134
134
|
"data-type": "emoji",
|
|
135
|
-
"data-name": (
|
|
136
|
-
"data-emoji": (
|
|
135
|
+
"data-name": (R = o.attrs) == null ? void 0 : R.name,
|
|
136
|
+
"data-emoji": (p = o.attrs) == null ? void 0 : p.emoji
|
|
137
137
|
}, d);
|
|
138
|
-
},
|
|
139
|
-
const { class:
|
|
140
|
-
class:
|
|
141
|
-
id:
|
|
142
|
-
style:
|
|
143
|
-
} :
|
|
144
|
-
return
|
|
145
|
-
}, T = (o) =>
|
|
138
|
+
}, S = (o, h) => h.render("pre", o.attrs || {}, h.render("code", {}, o.children || "")), E = (o, h = !1) => ({ text: d, attrs: g }, b) => {
|
|
139
|
+
const { class: R, id: p, ...k } = g || {}, _ = h ? {
|
|
140
|
+
class: R,
|
|
141
|
+
id: p,
|
|
142
|
+
style: ge(k) || void 0
|
|
143
|
+
} : g || {};
|
|
144
|
+
return b.render(o, O(_), d);
|
|
145
|
+
}, T = (o) => U(o), ee = (o) => {
|
|
146
146
|
const { marks: h, ...d } = o;
|
|
147
147
|
if ("text" in o) {
|
|
148
|
-
if (h) return h.reduce((
|
|
149
|
-
...
|
|
150
|
-
text:
|
|
148
|
+
if (h) return h.reduce((b, R) => T({
|
|
149
|
+
...R,
|
|
150
|
+
text: b
|
|
151
151
|
}), T({
|
|
152
152
|
...d,
|
|
153
153
|
children: d.children
|
|
154
154
|
}));
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
const
|
|
158
|
-
t.set("txt",
|
|
155
|
+
const g = o.attrs || {};
|
|
156
|
+
if (l) {
|
|
157
|
+
const b = t.get("txt") || 0;
|
|
158
|
+
t.set("txt", b + 1), g.key = `txt-${b}`;
|
|
159
159
|
}
|
|
160
|
-
return
|
|
160
|
+
return s(d.text, g);
|
|
161
161
|
}
|
|
162
162
|
return "";
|
|
163
|
-
},
|
|
164
|
-
const { linktype: d, href:
|
|
165
|
-
let
|
|
163
|
+
}, D = (o, h) => {
|
|
164
|
+
const { linktype: d, href: g, anchor: b, ...R } = o.attrs || {};
|
|
165
|
+
let p = "";
|
|
166
166
|
switch (d) {
|
|
167
|
-
case
|
|
168
|
-
case
|
|
169
|
-
|
|
167
|
+
case x.ASSET:
|
|
168
|
+
case x.URL:
|
|
169
|
+
p = g;
|
|
170
170
|
break;
|
|
171
|
-
case
|
|
172
|
-
|
|
171
|
+
case x.EMAIL:
|
|
172
|
+
p = `mailto:${g}`;
|
|
173
173
|
break;
|
|
174
|
-
case
|
|
175
|
-
|
|
174
|
+
case x.STORY:
|
|
175
|
+
p = g, b && (p = `${p}#${b}`);
|
|
176
176
|
break;
|
|
177
177
|
default:
|
|
178
|
-
|
|
178
|
+
p = g;
|
|
179
179
|
break;
|
|
180
180
|
}
|
|
181
|
-
const
|
|
182
|
-
return
|
|
183
|
-
},
|
|
184
|
-
var d,
|
|
181
|
+
const k = { ...R };
|
|
182
|
+
return p && (k.href = p), h.render("a", k, o.text);
|
|
183
|
+
}, te = (o, h) => {
|
|
184
|
+
var d, g;
|
|
185
185
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), h.render("span", {
|
|
186
186
|
blok: (d = o == null ? void 0 : o.attrs) == null ? void 0 : d.body[0],
|
|
187
|
-
id: (
|
|
187
|
+
id: (g = o.attrs) == null ? void 0 : g.id,
|
|
188
188
|
style: "display: none"
|
|
189
189
|
});
|
|
190
|
-
},
|
|
191
|
-
const d = u(o.attrs),
|
|
192
|
-
return h.render("table", d, h.render("tbody", {},
|
|
193
|
-
},
|
|
190
|
+
}, re = (o, h) => {
|
|
191
|
+
const d = u(o.attrs), g = o.children || null;
|
|
192
|
+
return h.render("table", d, h.render("tbody", {}, g));
|
|
193
|
+
}, se = (o, h) => {
|
|
194
194
|
const d = u(o.attrs);
|
|
195
195
|
return h.render("tr", d, o.children);
|
|
196
|
-
},
|
|
197
|
-
const { colspan: d, rowspan:
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
...
|
|
196
|
+
}, ie = (o, h) => {
|
|
197
|
+
const { colspan: d, rowspan: g, colwidth: b, backgroundColor: R, textAlign: p, ...k } = o.attrs || {}, _ = [];
|
|
198
|
+
b && _.push(`width: ${b}px;`), R && _.push(`background-color: ${R};`), p && _.push(`text-align: ${p};`);
|
|
199
|
+
const C = {
|
|
200
|
+
...k,
|
|
201
201
|
...d > 1 ? { colspan: d } : {},
|
|
202
|
-
...
|
|
203
|
-
...
|
|
202
|
+
...g > 1 ? { rowspan: g } : {},
|
|
203
|
+
..._.length > 0 ? { style: _.join(" ") } : {}
|
|
204
204
|
};
|
|
205
|
-
return h.render("td", C
|
|
206
|
-
},
|
|
207
|
-
const { colspan: d, rowspan:
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
...
|
|
205
|
+
return h.render("td", O(C), o.children);
|
|
206
|
+
}, ne = (o, h) => {
|
|
207
|
+
const { colspan: d, rowspan: g, colwidth: b, backgroundColor: R, textAlign: p, ...k } = o.attrs || {}, _ = [];
|
|
208
|
+
b && _.push(`width: ${b}px;`), R && _.push(`background-color: ${R};`), p && _.push(`text-align: ${p};`);
|
|
209
|
+
const C = {
|
|
210
|
+
...k,
|
|
211
211
|
...d > 1 ? { colspan: d } : {},
|
|
212
|
-
...
|
|
213
|
-
...
|
|
212
|
+
...g > 1 ? { rowspan: g } : {},
|
|
213
|
+
..._.length > 0 ? { style: _.join(" ") } : {}
|
|
214
214
|
};
|
|
215
|
-
return h.render("th", C
|
|
215
|
+
return h.render("th", O(C), o.children);
|
|
216
216
|
}, B = /* @__PURE__ */ new Map([
|
|
217
|
-
[
|
|
218
|
-
[
|
|
219
|
-
[
|
|
220
|
-
[
|
|
221
|
-
[
|
|
222
|
-
[
|
|
223
|
-
[
|
|
224
|
-
[
|
|
225
|
-
[
|
|
226
|
-
[
|
|
227
|
-
[
|
|
228
|
-
[
|
|
229
|
-
[
|
|
230
|
-
[
|
|
231
|
-
[
|
|
232
|
-
[
|
|
233
|
-
[
|
|
234
|
-
[
|
|
235
|
-
[
|
|
236
|
-
[
|
|
237
|
-
[
|
|
238
|
-
[
|
|
239
|
-
[
|
|
240
|
-
[
|
|
241
|
-
[
|
|
242
|
-
[
|
|
243
|
-
[
|
|
244
|
-
[
|
|
245
|
-
[
|
|
246
|
-
[
|
|
247
|
-
]), z = new Map([...B, ...Object.entries(i).map(([o, h]) => [o, h])]),
|
|
248
|
-
render: (d,
|
|
249
|
-
if (
|
|
250
|
-
const
|
|
251
|
-
t.set(d,
|
|
217
|
+
[v.DOCUMENT, c("")],
|
|
218
|
+
[v.HEADING, y],
|
|
219
|
+
[v.PARAGRAPH, c("p")],
|
|
220
|
+
[v.UL_LIST, c("ul")],
|
|
221
|
+
[v.OL_LIST, c("ol")],
|
|
222
|
+
[v.LIST_ITEM, c("li")],
|
|
223
|
+
[v.IMAGE, f],
|
|
224
|
+
[v.EMOJI, A],
|
|
225
|
+
[v.CODE_BLOCK, S],
|
|
226
|
+
[v.HR, c("hr")],
|
|
227
|
+
[v.BR, c("br")],
|
|
228
|
+
[v.QUOTE, c("blockquote")],
|
|
229
|
+
[v.COMPONENT, te],
|
|
230
|
+
[he.TEXT, ee],
|
|
231
|
+
[w.LINK, D],
|
|
232
|
+
[w.ANCHOR, D],
|
|
233
|
+
[w.STYLED, E("span", !0)],
|
|
234
|
+
[w.BOLD, E("strong")],
|
|
235
|
+
[w.TEXT_STYLE, E("span", !0)],
|
|
236
|
+
[w.ITALIC, E("em")],
|
|
237
|
+
[w.UNDERLINE, E("u")],
|
|
238
|
+
[w.STRIKE, E("s")],
|
|
239
|
+
[w.CODE, E("code")],
|
|
240
|
+
[w.SUPERSCRIPT, E("sup")],
|
|
241
|
+
[w.SUBSCRIPT, E("sub")],
|
|
242
|
+
[w.HIGHLIGHT, E("mark")],
|
|
243
|
+
[v.TABLE, re],
|
|
244
|
+
[v.TABLE_ROW, se],
|
|
245
|
+
[v.TABLE_CELL, ie],
|
|
246
|
+
[v.TABLE_HEADER, ne]
|
|
247
|
+
]), z = new Map([...B, ...Object.entries(i).map(([o, h]) => [o, h])]), oe = () => ({
|
|
248
|
+
render: (d, g = {}, b) => {
|
|
249
|
+
if (l && d) {
|
|
250
|
+
const R = t.get(d) || 0;
|
|
251
|
+
t.set(d, R + 1), g.key = `${d}-${R}`;
|
|
252
252
|
}
|
|
253
|
-
return
|
|
253
|
+
return r(d, g, b);
|
|
254
254
|
},
|
|
255
255
|
originalResolvers: B,
|
|
256
256
|
mergedResolvers: z
|
|
257
257
|
});
|
|
258
|
-
function
|
|
258
|
+
function P(o) {
|
|
259
259
|
const h = z.get(o.type);
|
|
260
260
|
if (!h)
|
|
261
261
|
return console.error("<Storyblok>", `No resolver found for node type ${o.type}`), "";
|
|
262
|
-
const d =
|
|
262
|
+
const d = oe();
|
|
263
263
|
if (o.type === "text") return h(o, d);
|
|
264
|
-
const
|
|
264
|
+
const g = o.content ? o.content.map(U) : void 0;
|
|
265
265
|
return h({
|
|
266
266
|
...o,
|
|
267
|
-
children:
|
|
267
|
+
children: g
|
|
268
268
|
}, d);
|
|
269
269
|
}
|
|
270
|
-
function
|
|
271
|
-
return o.type === "doc" ?
|
|
270
|
+
function U(o) {
|
|
271
|
+
return o.type === "doc" ? a ? o.content.map(P) : o.content.map(P).join("") : Array.isArray(o) ? o.map(P) : P(o);
|
|
272
272
|
}
|
|
273
|
-
return { render:
|
|
273
|
+
return { render: U };
|
|
274
274
|
}
|
|
275
|
-
let
|
|
276
|
-
const
|
|
275
|
+
let Y = !1;
|
|
276
|
+
const J = [], X = (e) => new Promise((t, r) => {
|
|
277
277
|
if (typeof window > "u") {
|
|
278
|
-
|
|
278
|
+
r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
|
|
279
279
|
return;
|
|
280
280
|
}
|
|
281
281
|
if (window.storyblokRegisterEvent = (i) => {
|
|
@@ -283,70 +283,34 @@ const q = [], J = (e) => new Promise((t, s) => {
|
|
|
283
283
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
284
284
|
return;
|
|
285
285
|
}
|
|
286
|
-
|
|
286
|
+
Y ? i() : J.push(i);
|
|
287
287
|
}, document.getElementById("storyblok-javascript-bridge")) {
|
|
288
288
|
t(void 0);
|
|
289
289
|
return;
|
|
290
290
|
}
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}, document.getElementsByTagName("head")[0].appendChild(
|
|
295
|
-
})
|
|
296
|
-
var de = class extends Error {
|
|
297
|
-
constructor(e) {
|
|
298
|
-
super(e), this.name = "AbortError";
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
function fe(e, t, s) {
|
|
302
|
-
if (!Number.isFinite(t)) throw new TypeError("Expected `limit` to be a finite number");
|
|
303
|
-
if (!Number.isFinite(s)) throw new TypeError("Expected `interval` to be a finite number");
|
|
304
|
-
const r = [];
|
|
305
|
-
let i = [], n = 0, c = !1;
|
|
306
|
-
const l = async () => {
|
|
307
|
-
n++;
|
|
308
|
-
const a = r.shift();
|
|
309
|
-
if (a) try {
|
|
310
|
-
const p = await e(...a.args);
|
|
311
|
-
a.resolve(p);
|
|
312
|
-
} catch (p) {
|
|
313
|
-
a.reject(p);
|
|
314
|
-
}
|
|
315
|
-
const g = setTimeout(() => {
|
|
316
|
-
n--, r.length > 0 && l(), i = i.filter((p) => p !== g);
|
|
317
|
-
}, s);
|
|
318
|
-
i.includes(g) || i.push(g);
|
|
319
|
-
}, u = (...a) => c ? Promise.reject(/* @__PURE__ */ new Error("Throttled function is already aborted and not accepting new promises")) : new Promise((g, p) => {
|
|
320
|
-
r.push({
|
|
321
|
-
resolve: g,
|
|
322
|
-
reject: p,
|
|
323
|
-
args: a
|
|
324
|
-
}), n < t && l();
|
|
325
|
-
});
|
|
326
|
-
return u.abort = () => {
|
|
327
|
-
c = !0, i.forEach(clearTimeout), i = [], r.forEach((a) => a.reject(() => new de("Throttle function aborted"))), r.length = 0;
|
|
328
|
-
}, u;
|
|
329
|
-
}
|
|
330
|
-
var ge = fe;
|
|
331
|
-
const V = (e = "") => e.includes("/cdn/"), ye = (e, t = 25, s = 1) => ({
|
|
291
|
+
const s = document.createElement("script");
|
|
292
|
+
s.async = !0, s.src = e, s.id = "storyblok-javascript-bridge", s.onerror = (i) => r(i), s.onload = (i) => {
|
|
293
|
+
J.forEach((n) => n()), Y = !0, t(i);
|
|
294
|
+
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
295
|
+
}), K = (e = "") => e.includes("/cdn/"), pe = (e, t = 25, r = 1) => ({
|
|
332
296
|
...e,
|
|
333
297
|
per_page: t,
|
|
334
|
-
page:
|
|
335
|
-
}),
|
|
336
|
-
const
|
|
337
|
-
return
|
|
338
|
-
},
|
|
339
|
-
const
|
|
298
|
+
page: r
|
|
299
|
+
}), Re = (e) => new Promise((t) => setTimeout(t, e)), ve = (e = 0, t) => Array.from({ length: e }, t), _e = (e = 0, t = e) => {
|
|
300
|
+
const r = Math.abs(t - e) || 0, s = e < t ? 1 : -1;
|
|
301
|
+
return ve(r, (i, n) => n * s + e);
|
|
302
|
+
}, Ee = async (e, t) => Promise.all(e.map(t)), Ae = (e = [], t) => e.map(t).reduce((r, s) => [...r, ...s], []), F = (e, t, r) => {
|
|
303
|
+
const s = [];
|
|
340
304
|
for (const i in e) {
|
|
341
305
|
if (!Object.prototype.hasOwnProperty.call(e, i)) continue;
|
|
342
306
|
const n = e[i];
|
|
343
307
|
if (n == null) continue;
|
|
344
|
-
const
|
|
345
|
-
let
|
|
346
|
-
typeof n == "object" ?
|
|
308
|
+
const l = r ? "" : encodeURIComponent(i);
|
|
309
|
+
let a;
|
|
310
|
+
typeof n == "object" ? a = F(n, t ? t + encodeURIComponent(`[${l}]`) : l, Array.isArray(n)) : a = `${t ? t + encodeURIComponent(`[${l}]`) : l}=${encodeURIComponent(n)}`, s.push(a);
|
|
347
311
|
}
|
|
348
|
-
return
|
|
349
|
-
},
|
|
312
|
+
return s.join("&");
|
|
313
|
+
}, W = (e) => {
|
|
350
314
|
const t = {
|
|
351
315
|
eu: "api.storyblok.com",
|
|
352
316
|
us: "api-us.storyblok.com",
|
|
@@ -388,37 +352,37 @@ var we = class {
|
|
|
388
352
|
return this.url = e, this.parameters = t ?? {}, this._methodHandler("delete");
|
|
389
353
|
}
|
|
390
354
|
async _responseHandler(e) {
|
|
391
|
-
const t = [],
|
|
355
|
+
const t = [], r = {
|
|
392
356
|
data: {},
|
|
393
357
|
headers: {},
|
|
394
358
|
status: 0,
|
|
395
359
|
statusText: ""
|
|
396
360
|
};
|
|
397
|
-
e.status !== 204 && await e.json().then((
|
|
398
|
-
|
|
361
|
+
e.status !== 204 && await e.json().then((s) => {
|
|
362
|
+
r.data = s;
|
|
399
363
|
});
|
|
400
|
-
for (const
|
|
401
|
-
return
|
|
364
|
+
for (const s of e.headers.entries()) t[s[0]] = s[1];
|
|
365
|
+
return r.headers = { ...t }, r.status = e.status, r.statusText = e.statusText, r;
|
|
402
366
|
}
|
|
403
367
|
async _methodHandler(e) {
|
|
404
|
-
let t = `${this.baseURL}${this.url}`,
|
|
405
|
-
e === "get" ? t = `${this.baseURL}${this.url}?${
|
|
406
|
-
const
|
|
407
|
-
let
|
|
408
|
-
this.timeout && (
|
|
368
|
+
let t = `${this.baseURL}${this.url}`, r = null;
|
|
369
|
+
e === "get" ? t = `${this.baseURL}${this.url}?${F(this.parameters)}` : r = JSON.stringify(this.parameters);
|
|
370
|
+
const s = new URL(t), i = new AbortController(), { signal: n } = i;
|
|
371
|
+
let l = null;
|
|
372
|
+
this.timeout && (l = setTimeout(() => i.abort(), this.timeout));
|
|
409
373
|
try {
|
|
410
|
-
const
|
|
374
|
+
const a = await this.fetch(`${s}`, {
|
|
411
375
|
method: e,
|
|
412
376
|
headers: this.headers,
|
|
413
|
-
body:
|
|
377
|
+
body: r,
|
|
414
378
|
signal: n,
|
|
415
379
|
...this.fetchOptions
|
|
416
380
|
});
|
|
417
|
-
this.timeout &&
|
|
418
|
-
const u = await this._responseHandler(
|
|
381
|
+
this.timeout && l && clearTimeout(l);
|
|
382
|
+
const u = await this._responseHandler(a);
|
|
419
383
|
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(u)) : this._statusHandler(u);
|
|
420
|
-
} catch (
|
|
421
|
-
return { message:
|
|
384
|
+
} catch (a) {
|
|
385
|
+
return { message: a };
|
|
422
386
|
}
|
|
423
387
|
}
|
|
424
388
|
setFetchOptions(e = {}) {
|
|
@@ -446,27 +410,148 @@ var we = class {
|
|
|
446
410
|
}
|
|
447
411
|
_statusHandler(e) {
|
|
448
412
|
const t = /20[0-6]/g;
|
|
449
|
-
return new Promise((
|
|
450
|
-
if (t.test(`${e.status}`)) return
|
|
413
|
+
return new Promise((r, s) => {
|
|
414
|
+
if (t.test(`${e.status}`)) return r(e);
|
|
451
415
|
const i = {
|
|
452
416
|
message: this._normalizeErrorMessage(e.data),
|
|
453
417
|
status: e.status,
|
|
454
418
|
response: e
|
|
455
419
|
};
|
|
456
|
-
|
|
420
|
+
s(i);
|
|
457
421
|
});
|
|
458
422
|
}
|
|
459
423
|
}, ke = we;
|
|
460
|
-
const
|
|
424
|
+
const Q = "SB-Agent", $ = {
|
|
461
425
|
defaultAgentName: "SB-JS-CLIENT",
|
|
462
426
|
defaultAgentVersion: "SB-Agent-Version",
|
|
463
427
|
packageVersion: "7.0.0"
|
|
464
|
-
},
|
|
428
|
+
}, Z = {
|
|
429
|
+
DRAFT: "draft",
|
|
465
430
|
PUBLISHED: "published"
|
|
431
|
+
}, Le = 25, M = {
|
|
432
|
+
SMALL: 25,
|
|
433
|
+
MEDIUM: 50,
|
|
434
|
+
LARGE: 75
|
|
435
|
+
}, I = {
|
|
436
|
+
SINGLE_OR_SMALL: 50,
|
|
437
|
+
MEDIUM: 15,
|
|
438
|
+
LARGE: 10,
|
|
439
|
+
VERY_LARGE: 6
|
|
440
|
+
}, j = 1e3, G = 3;
|
|
441
|
+
function Se(e) {
|
|
442
|
+
return e.version === Z.DRAFT;
|
|
443
|
+
}
|
|
444
|
+
function Te(e, t) {
|
|
445
|
+
const r = e.includes("/cdn/stories/"), s = e.split("/").length > 3 && !e.endsWith("/cdn/stories"), i = "find_by" in t;
|
|
446
|
+
return r && s || i;
|
|
447
|
+
}
|
|
448
|
+
function Ce(e) {
|
|
449
|
+
return e <= M.SMALL ? I.SINGLE_OR_SMALL : e <= M.MEDIUM ? I.MEDIUM : e <= M.LARGE ? I.LARGE : I.VERY_LARGE;
|
|
450
|
+
}
|
|
451
|
+
function N(e, t, r = {}, s) {
|
|
452
|
+
if (r.userRateLimit !== void 0) return Math.min(r.userRateLimit, j);
|
|
453
|
+
if (r.serverHeadersRateLimit !== void 0) return Math.min(r.serverHeadersRateLimit, j);
|
|
454
|
+
if (t && !Se(t)) return j;
|
|
455
|
+
if (s !== void 0) return s;
|
|
456
|
+
if (Te(e, t)) return I.SINGLE_OR_SMALL;
|
|
457
|
+
const i = t.per_page || Le;
|
|
458
|
+
return Ce(i);
|
|
459
|
+
}
|
|
460
|
+
function Oe(e) {
|
|
461
|
+
if (!e) return null;
|
|
462
|
+
const t = e["x-ratelimit"] || e["X-RateLimit"], r = e["x-ratelimit-policy"] || e["X-RateLimit-Policy"];
|
|
463
|
+
if (!t && !r) return null;
|
|
464
|
+
const s = {};
|
|
465
|
+
if (t) {
|
|
466
|
+
const i = t.match(/r=(\d+)/);
|
|
467
|
+
i && (s.remaining = Number.parseInt(i[1], 10));
|
|
468
|
+
}
|
|
469
|
+
if (r) {
|
|
470
|
+
const i = r.match(/q=(\d+)/);
|
|
471
|
+
i && (s.max = Number.parseInt(i[1], 10));
|
|
472
|
+
}
|
|
473
|
+
return Object.keys(s).length > 0 ? s : null;
|
|
474
|
+
}
|
|
475
|
+
function Ie(e, t = !1) {
|
|
476
|
+
return {
|
|
477
|
+
userRateLimit: e,
|
|
478
|
+
serverHeadersRateLimit: void 0,
|
|
479
|
+
isManagementApi: t
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
var Pe = class extends Error {
|
|
483
|
+
constructor(e) {
|
|
484
|
+
super(e), this.name = "AbortError";
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
function xe(e, t, r) {
|
|
488
|
+
if (!Number.isFinite(t)) throw new TypeError("Expected `limit` to be a finite number");
|
|
489
|
+
if (!Number.isFinite(r)) throw new TypeError("Expected `interval` to be a finite number");
|
|
490
|
+
const s = [];
|
|
491
|
+
let i = [], n = 0, l = !1;
|
|
492
|
+
const a = async () => {
|
|
493
|
+
n++;
|
|
494
|
+
const c = s.shift();
|
|
495
|
+
if (c) try {
|
|
496
|
+
const y = await e(...c.args);
|
|
497
|
+
c.resolve(y);
|
|
498
|
+
} catch (y) {
|
|
499
|
+
c.reject(y);
|
|
500
|
+
}
|
|
501
|
+
const f = setTimeout(() => {
|
|
502
|
+
n--, s.length > 0 && a(), i = i.filter((y) => y !== f);
|
|
503
|
+
}, r);
|
|
504
|
+
i.includes(f) || i.push(f);
|
|
505
|
+
}, u = (...c) => l ? Promise.reject(/* @__PURE__ */ new Error("Throttled function is already aborted and not accepting new promises")) : new Promise((f, y) => {
|
|
506
|
+
s.push({
|
|
507
|
+
resolve: f,
|
|
508
|
+
reject: y,
|
|
509
|
+
args: c
|
|
510
|
+
}), n < t && a();
|
|
511
|
+
});
|
|
512
|
+
return u.abort = () => {
|
|
513
|
+
l = !0, i.forEach(clearTimeout), i = [], s.forEach((c) => c.reject(() => new Pe("Throttle function aborted"))), s.length = 0;
|
|
514
|
+
}, u;
|
|
515
|
+
}
|
|
516
|
+
var Ne = xe, He = class {
|
|
517
|
+
constructor(e, t = 1e3) {
|
|
518
|
+
m(this, "queues");
|
|
519
|
+
m(this, "interval");
|
|
520
|
+
m(this, "throttledRequestFn");
|
|
521
|
+
this.queues = /* @__PURE__ */ new Map(), this.interval = t, this.throttledRequestFn = e;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Gets or creates a throttle queue for the specified rate limit
|
|
525
|
+
*/
|
|
526
|
+
getQueue(e) {
|
|
527
|
+
let t = this.queues.get(e);
|
|
528
|
+
return t || (t = Ne(this.throttledRequestFn, e, this.interval), this.queues.set(e, t)), t;
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Executes a request through the appropriate throttle queue based on rate limit
|
|
532
|
+
*/
|
|
533
|
+
execute(e, ...t) {
|
|
534
|
+
return this.getQueue(e)(...t);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Aborts all throttle queues
|
|
538
|
+
*/
|
|
539
|
+
abortAll() {
|
|
540
|
+
this.queues.forEach((e) => {
|
|
541
|
+
var t;
|
|
542
|
+
(t = e.abort) == null || t.call(e);
|
|
543
|
+
}), this.queues.clear();
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Gets the number of active queues
|
|
547
|
+
*/
|
|
548
|
+
getQueueCount() {
|
|
549
|
+
return this.queues.size;
|
|
550
|
+
}
|
|
466
551
|
};
|
|
467
|
-
let
|
|
468
|
-
const
|
|
469
|
-
var
|
|
552
|
+
let H = {};
|
|
553
|
+
const L = {};
|
|
554
|
+
var Ue = class {
|
|
470
555
|
/**
|
|
471
556
|
*
|
|
472
557
|
* @param config ISbConfig interface
|
|
@@ -476,13 +561,14 @@ var Se = class {
|
|
|
476
561
|
m(this, "client");
|
|
477
562
|
m(this, "maxRetries");
|
|
478
563
|
m(this, "retriesDelay");
|
|
479
|
-
m(this, "
|
|
564
|
+
m(this, "throttleManager");
|
|
480
565
|
m(this, "accessToken");
|
|
481
566
|
m(this, "cache");
|
|
482
567
|
m(this, "resolveCounter");
|
|
483
568
|
m(this, "relations");
|
|
484
569
|
m(this, "links");
|
|
485
570
|
m(this, "version");
|
|
571
|
+
m(this, "rateLimitConfig");
|
|
486
572
|
/**
|
|
487
573
|
* @deprecated This property is deprecated. Use the standalone `richTextResolver` from `@storyblok/richtext` instead.
|
|
488
574
|
* @see https://github.com/storyblok/richtext
|
|
@@ -491,65 +577,63 @@ var Se = class {
|
|
|
491
577
|
m(this, "resolveNestedRelations");
|
|
492
578
|
m(this, "stringifiedStoriesCache");
|
|
493
579
|
m(this, "inlineAssets");
|
|
494
|
-
let
|
|
495
|
-
if (!
|
|
496
|
-
const
|
|
497
|
-
e.oauthToken ?
|
|
580
|
+
let r = e.endpoint || t;
|
|
581
|
+
if (!r) {
|
|
582
|
+
const i = e.https === !1 ? "http" : "https";
|
|
583
|
+
e.oauthToken ? r = `${i}://${W(e.region)}/v1` : r = `${i}://${W(e.region)}/v2`;
|
|
498
584
|
}
|
|
499
|
-
const
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}),
|
|
503
|
-
|
|
504
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = ge(this.throttledRequest.bind(this), i, 1e3), 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 || _e.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new ke({
|
|
505
|
-
baseURL: s,
|
|
585
|
+
const s = new Headers();
|
|
586
|
+
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(([n, l]) => {
|
|
587
|
+
s.set(n, l);
|
|
588
|
+
}), s.has(Q) || (s.set(Q, $.defaultAgentName), s.set($.defaultAgentVersion, $.packageVersion)), e.oauthToken && s.set("Authorization", e.oauthToken), this.rateLimitConfig = Ie(e.rateLimit, !!e.oauthToken), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttleManager = new He(this.throttledRequest.bind(this), 1e3), 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 || Z.PUBLISHED, this.inlineAssets = e.inlineAssets || !1, this.client = new ke({
|
|
589
|
+
baseURL: r,
|
|
506
590
|
timeout: e.timeout || 0,
|
|
507
|
-
headers:
|
|
591
|
+
headers: s,
|
|
508
592
|
responseInterceptor: e.responseInterceptor,
|
|
509
593
|
fetch: e.fetch
|
|
510
594
|
});
|
|
511
595
|
}
|
|
512
596
|
parseParams(e) {
|
|
513
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
|
597
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = L[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
514
598
|
}
|
|
515
599
|
factoryParamOptions(e, t) {
|
|
516
|
-
return
|
|
600
|
+
return K(e) ? this.parseParams(t) : t;
|
|
517
601
|
}
|
|
518
|
-
makeRequest(e, t,
|
|
519
|
-
const n = this.factoryParamOptions(e,
|
|
602
|
+
makeRequest(e, t, r, s, i) {
|
|
603
|
+
const n = this.factoryParamOptions(e, pe(t, r, s));
|
|
520
604
|
return this.cacheResponse(e, n, void 0, i);
|
|
521
605
|
}
|
|
522
|
-
get(e, t = {},
|
|
606
|
+
get(e, t = {}, r) {
|
|
523
607
|
t || (t = {});
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
const i = this.factoryParamOptions(
|
|
527
|
-
return this.cacheResponse(
|
|
608
|
+
const s = `/${e}`;
|
|
609
|
+
K(s) && (t.version = t.version || this.version);
|
|
610
|
+
const i = this.factoryParamOptions(s, t);
|
|
611
|
+
return this.cacheResponse(s, i, void 0, r);
|
|
528
612
|
}
|
|
529
|
-
async getAll(e, t = {},
|
|
530
|
-
const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""),
|
|
613
|
+
async getAll(e, t = {}, r, s) {
|
|
614
|
+
const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), l = r ?? n.substring(n.lastIndexOf("/") + 1);
|
|
531
615
|
t.version = t.version || this.version;
|
|
532
|
-
const
|
|
533
|
-
return
|
|
616
|
+
const a = 1, u = await this.makeRequest(n, t, i, a, s), c = u.total ? Math.ceil(u.total / (u.perPage || i)) : 1, f = await Ee(_e(a, c), (y) => this.makeRequest(n, t, i, y + 1, s));
|
|
617
|
+
return Ae([u, ...f], (y) => Object.values(y.data[l]));
|
|
534
618
|
}
|
|
535
|
-
post(e, t = {},
|
|
536
|
-
const
|
|
537
|
-
return this.
|
|
619
|
+
post(e, t = {}, r) {
|
|
620
|
+
const s = `/${e}`, i = N(void 0, void 0, this.rateLimitConfig, G);
|
|
621
|
+
return this.throttleManager.execute(i, "post", s, t, r);
|
|
538
622
|
}
|
|
539
|
-
put(e, t = {},
|
|
540
|
-
const
|
|
541
|
-
return this.
|
|
623
|
+
put(e, t = {}, r) {
|
|
624
|
+
const s = `/${e}`, i = N(void 0, void 0, this.rateLimitConfig, G);
|
|
625
|
+
return this.throttleManager.execute(i, "put", s, t, r);
|
|
542
626
|
}
|
|
543
|
-
delete(e, t = {},
|
|
627
|
+
delete(e, t = {}, r) {
|
|
544
628
|
t || (t = {});
|
|
545
|
-
const
|
|
546
|
-
return this.
|
|
629
|
+
const s = `/${e}`, i = N(void 0, void 0, this.rateLimitConfig, G);
|
|
630
|
+
return this.throttleManager.execute(i, "delete", s, t, r);
|
|
547
631
|
}
|
|
548
632
|
getStories(e = {}, t) {
|
|
549
633
|
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
|
550
634
|
}
|
|
551
|
-
getStory(e, t = {},
|
|
552
|
-
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t,
|
|
635
|
+
getStory(e, t = {}, r) {
|
|
636
|
+
return this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t, r);
|
|
553
637
|
}
|
|
554
638
|
getToken() {
|
|
555
639
|
return this.accessToken;
|
|
@@ -563,9 +647,9 @@ var Se = class {
|
|
|
563
647
|
_cleanCopy(e) {
|
|
564
648
|
return JSON.parse(JSON.stringify(e));
|
|
565
649
|
}
|
|
566
|
-
_insertLinks(e, t,
|
|
567
|
-
const
|
|
568
|
-
|
|
650
|
+
_insertLinks(e, t, r) {
|
|
651
|
+
const s = e[t];
|
|
652
|
+
s && s.fieldtype === "multilink" && s.linktype === "story" && typeof s.id == "string" && this.links[r][s.id] ? s.story = this._cleanCopy(this.links[r][s.id]) : s && s.linktype === "story" && typeof s.uuid == "string" && this.links[r][s.uuid] && (s.story = this._cleanCopy(this.links[r][s.uuid]));
|
|
569
653
|
}
|
|
570
654
|
/**
|
|
571
655
|
*
|
|
@@ -586,9 +670,9 @@ var Se = class {
|
|
|
586
670
|
* - For single strings: directly replaces the UUID with the story reference
|
|
587
671
|
* - For arrays: maps through each UUID and replaces with corresponding story references
|
|
588
672
|
*/
|
|
589
|
-
_resolveField(e, t,
|
|
590
|
-
const
|
|
591
|
-
typeof
|
|
673
|
+
_resolveField(e, t, r) {
|
|
674
|
+
const s = e[t];
|
|
675
|
+
typeof s == "string" ? e[t] = this.getStoryReference(r, s) : Array.isArray(s) && (e[t] = s.map((i) => this.getStoryReference(r, i)).filter(Boolean));
|
|
592
676
|
}
|
|
593
677
|
/**
|
|
594
678
|
* Inserts relations into the JSON tree by resolving references
|
|
@@ -607,13 +691,13 @@ var Se = class {
|
|
|
607
691
|
* The method supports both string and array formats for the fields parameter,
|
|
608
692
|
* allowing flexible specification of relation patterns.
|
|
609
693
|
*/
|
|
610
|
-
_insertRelations(e, t,
|
|
611
|
-
if (Array.isArray(
|
|
612
|
-
this._resolveField(e, t,
|
|
694
|
+
_insertRelations(e, t, r, s) {
|
|
695
|
+
if (Array.isArray(r) ? r.find((l) => l.endsWith(`.${t}`)) : r.endsWith(`.${t}`)) {
|
|
696
|
+
this._resolveField(e, t, s);
|
|
613
697
|
return;
|
|
614
698
|
}
|
|
615
699
|
const n = e.component ? `${e.component}.${t}` : t;
|
|
616
|
-
(Array.isArray(
|
|
700
|
+
(Array.isArray(r) ? r.includes(n) : r === n) && this._resolveField(e, t, s);
|
|
617
701
|
}
|
|
618
702
|
/**
|
|
619
703
|
* Recursively traverses and resolves relations in the story content tree
|
|
@@ -621,67 +705,67 @@ var Se = class {
|
|
|
621
705
|
* @param fields - The relation patterns to resolve
|
|
622
706
|
* @param resolveId - The unique identifier for the current resolution context
|
|
623
707
|
*/
|
|
624
|
-
iterateTree(e, t,
|
|
625
|
-
const
|
|
708
|
+
iterateTree(e, t, r) {
|
|
709
|
+
const s = (i, n = "") => {
|
|
626
710
|
if (!(!i || i._stopResolving)) {
|
|
627
|
-
if (Array.isArray(i)) i.forEach((
|
|
628
|
-
else if (typeof i == "object") for (const
|
|
629
|
-
const
|
|
630
|
-
(i.component && i._uid || i.type === "link") && (this._insertRelations(i,
|
|
711
|
+
if (Array.isArray(i)) i.forEach((l, a) => s(l, `${n}[${a}]`));
|
|
712
|
+
else if (typeof i == "object") for (const l in i) {
|
|
713
|
+
const a = n ? `${n}.${l}` : l;
|
|
714
|
+
(i.component && i._uid || i.type === "link") && (this._insertRelations(i, l, t, r), this._insertLinks(i, l, r)), s(i[l], a);
|
|
631
715
|
}
|
|
632
716
|
}
|
|
633
717
|
};
|
|
634
|
-
|
|
718
|
+
s(e.content);
|
|
635
719
|
}
|
|
636
|
-
async resolveLinks(e, t,
|
|
637
|
-
let
|
|
720
|
+
async resolveLinks(e, t, r) {
|
|
721
|
+
let s = [];
|
|
638
722
|
if (e.link_uuids) {
|
|
639
|
-
const i = e.link_uuids.length, n = [],
|
|
640
|
-
for (let
|
|
641
|
-
const u = Math.min(i,
|
|
642
|
-
n.push(e.link_uuids.slice(
|
|
723
|
+
const i = e.link_uuids.length, n = [], l = 50;
|
|
724
|
+
for (let a = 0; a < i; a += l) {
|
|
725
|
+
const u = Math.min(i, a + l);
|
|
726
|
+
n.push(e.link_uuids.slice(a, u));
|
|
643
727
|
}
|
|
644
|
-
for (let
|
|
728
|
+
for (let a = 0; a < n.length; a++)
|
|
645
729
|
(await this.getStories({
|
|
646
|
-
per_page:
|
|
730
|
+
per_page: l,
|
|
647
731
|
language: t.language,
|
|
648
732
|
version: t.version,
|
|
649
733
|
starts_with: t.starts_with,
|
|
650
|
-
by_uuids: n[
|
|
651
|
-
})).data.stories.forEach((
|
|
652
|
-
|
|
734
|
+
by_uuids: n[a].join(",")
|
|
735
|
+
})).data.stories.forEach((c) => {
|
|
736
|
+
s.push(c);
|
|
653
737
|
});
|
|
654
|
-
} else
|
|
655
|
-
|
|
656
|
-
this.links[
|
|
738
|
+
} else s = e.links;
|
|
739
|
+
s.forEach((i) => {
|
|
740
|
+
this.links[r][i.uuid] = {
|
|
657
741
|
...i,
|
|
658
742
|
_stopResolving: !0
|
|
659
743
|
};
|
|
660
744
|
});
|
|
661
745
|
}
|
|
662
|
-
async resolveRelations(e, t,
|
|
663
|
-
let
|
|
746
|
+
async resolveRelations(e, t, r) {
|
|
747
|
+
let s = [];
|
|
664
748
|
if (e.rel_uuids) {
|
|
665
|
-
const i = e.rel_uuids.length, n = [],
|
|
666
|
-
for (let
|
|
667
|
-
const u = Math.min(i,
|
|
668
|
-
n.push(e.rel_uuids.slice(
|
|
749
|
+
const i = e.rel_uuids.length, n = [], l = 50;
|
|
750
|
+
for (let a = 0; a < i; a += l) {
|
|
751
|
+
const u = Math.min(i, a + l);
|
|
752
|
+
n.push(e.rel_uuids.slice(a, u));
|
|
669
753
|
}
|
|
670
|
-
for (let
|
|
754
|
+
for (let a = 0; a < n.length; a++)
|
|
671
755
|
(await this.getStories({
|
|
672
|
-
per_page:
|
|
756
|
+
per_page: l,
|
|
673
757
|
language: t.language,
|
|
674
758
|
version: t.version,
|
|
675
759
|
starts_with: t.starts_with,
|
|
676
|
-
by_uuids: n[
|
|
760
|
+
by_uuids: n[a].join(","),
|
|
677
761
|
excluding_fields: t.excluding_fields
|
|
678
|
-
})).data.stories.forEach((
|
|
679
|
-
|
|
762
|
+
})).data.stories.forEach((c) => {
|
|
763
|
+
s.push(c);
|
|
680
764
|
});
|
|
681
|
-
|
|
682
|
-
} else
|
|
683
|
-
|
|
684
|
-
this.relations[
|
|
765
|
+
s.length > 0 && (e.rels = s, delete e.rel_uuids);
|
|
766
|
+
} else s = e.rels;
|
|
767
|
+
s && s.length > 0 && s.forEach((i) => {
|
|
768
|
+
this.relations[r][i.uuid] = {
|
|
685
769
|
...i,
|
|
686
770
|
_stopResolving: !0
|
|
687
771
|
};
|
|
@@ -696,84 +780,86 @@ var Se = class {
|
|
|
696
780
|
* @returns Promise<void>
|
|
697
781
|
*
|
|
698
782
|
*/
|
|
699
|
-
async resolveStories(e, t,
|
|
783
|
+
async resolveStories(e, t, r) {
|
|
700
784
|
var i, n;
|
|
701
|
-
let
|
|
702
|
-
if (this.links[
|
|
785
|
+
let s = [];
|
|
786
|
+
if (this.links[r] = {}, this.relations[r] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (s = t.resolve_relations.split(",")), await this.resolveRelations(e, t, r)), t.resolve_links && [
|
|
703
787
|
"1",
|
|
704
788
|
"story",
|
|
705
789
|
"url",
|
|
706
790
|
"link"
|
|
707
|
-
].includes(t.resolve_links) && ((i = e.links) != null && i.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t,
|
|
708
|
-
e.story ? this.iterateTree(e.story,
|
|
709
|
-
this.iterateTree(
|
|
710
|
-
}), this.stringifiedStoriesCache = {}, delete this.links[
|
|
791
|
+
].includes(t.resolve_links) && ((i = e.links) != null && i.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, r), this.resolveNestedRelations) for (const l in this.relations[r]) this.iterateTree(this.relations[r][l], s, r);
|
|
792
|
+
e.story ? this.iterateTree(e.story, s, r) : e.stories.forEach((l) => {
|
|
793
|
+
this.iterateTree(l, s, r);
|
|
794
|
+
}), this.stringifiedStoriesCache = {}, delete this.links[r], delete this.relations[r];
|
|
711
795
|
}
|
|
712
|
-
async cacheResponse(e, t,
|
|
713
|
-
const i =
|
|
796
|
+
async cacheResponse(e, t, r, s) {
|
|
797
|
+
const i = F({
|
|
714
798
|
url: e,
|
|
715
799
|
params: t
|
|
716
800
|
}), n = this.cacheProvider();
|
|
717
801
|
if (t.version === "published" && e !== "/cdn/spaces/me") {
|
|
718
|
-
const
|
|
719
|
-
if (
|
|
802
|
+
const a = await n.get(i);
|
|
803
|
+
if (a) return Promise.resolve(a);
|
|
720
804
|
}
|
|
721
|
-
|
|
722
|
-
|
|
805
|
+
const l = N(e, t, this.rateLimitConfig);
|
|
806
|
+
return new Promise(async (a, u) => {
|
|
807
|
+
var c;
|
|
723
808
|
try {
|
|
724
|
-
const
|
|
725
|
-
if (
|
|
726
|
-
let
|
|
727
|
-
data:
|
|
728
|
-
headers:
|
|
809
|
+
const f = await this.throttleManager.execute(l, "get", e, t, s);
|
|
810
|
+
if (f.status !== 200) return u(f);
|
|
811
|
+
let y = {
|
|
812
|
+
data: f.data,
|
|
813
|
+
headers: f.headers
|
|
729
814
|
};
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
815
|
+
const A = Oe(f.headers);
|
|
816
|
+
if ((A == null ? void 0 : A.max) !== void 0 && (this.rateLimitConfig.serverHeadersRateLimit = A.max), (c = f.headers) != null && c["per-page"] && (y = Object.assign({}, y, {
|
|
817
|
+
perPage: f.headers["per-page"] ? Number.parseInt(f.headers["per-page"]) : 0,
|
|
818
|
+
total: f.headers["per-page"] ? Number.parseInt(f.headers.total) : 0
|
|
819
|
+
})), y.data.story || y.data.stories) {
|
|
820
|
+
const E = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
821
|
+
await this.resolveStories(y.data, t, `${E}`), y = await this.processInlineAssets(y);
|
|
736
822
|
}
|
|
737
|
-
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i,
|
|
738
|
-
const
|
|
739
|
-
return t.token &&
|
|
740
|
-
} catch (
|
|
741
|
-
if (
|
|
742
|
-
return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await
|
|
743
|
-
|
|
823
|
+
t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, y);
|
|
824
|
+
const S = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
825
|
+
return t.token && y.data.cv && (S && L[t.token] && L[t.token] !== y.data.cv && await this.flushCache(), L[t.token] = y.data.cv), a(y);
|
|
826
|
+
} catch (f) {
|
|
827
|
+
if (f.response && f.status === 429 && (r = typeof r > "u" ? 0 : r + 1, r < this.maxRetries))
|
|
828
|
+
return console.log(`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`), await Re(this.retriesDelay), this.cacheResponse(e, t, r).then(a).catch(u);
|
|
829
|
+
u(f);
|
|
744
830
|
}
|
|
745
831
|
});
|
|
746
832
|
}
|
|
747
|
-
throttledRequest(e, t,
|
|
748
|
-
return this.client.setFetchOptions(
|
|
833
|
+
throttledRequest(e, t, r, s) {
|
|
834
|
+
return this.client.setFetchOptions(s), this.client[e](t, r);
|
|
749
835
|
}
|
|
750
836
|
cacheVersions() {
|
|
751
|
-
return
|
|
837
|
+
return L;
|
|
752
838
|
}
|
|
753
839
|
cacheVersion() {
|
|
754
|
-
return
|
|
840
|
+
return L[this.accessToken];
|
|
755
841
|
}
|
|
756
842
|
setCacheVersion(e) {
|
|
757
|
-
this.accessToken && (
|
|
843
|
+
this.accessToken && (L[this.accessToken] = e);
|
|
758
844
|
}
|
|
759
845
|
clearCacheVersion() {
|
|
760
|
-
this.accessToken && (
|
|
846
|
+
this.accessToken && (L[this.accessToken] = 0);
|
|
761
847
|
}
|
|
762
848
|
cacheProvider() {
|
|
763
849
|
switch (this.cache.type) {
|
|
764
850
|
case "memory":
|
|
765
851
|
return {
|
|
766
852
|
get(e) {
|
|
767
|
-
return Promise.resolve(
|
|
853
|
+
return Promise.resolve(H[e]);
|
|
768
854
|
},
|
|
769
855
|
getAll() {
|
|
770
|
-
return Promise.resolve(
|
|
856
|
+
return Promise.resolve(H);
|
|
771
857
|
},
|
|
772
858
|
set(e, t) {
|
|
773
|
-
return
|
|
859
|
+
return H[e] = t, Promise.resolve(void 0);
|
|
774
860
|
},
|
|
775
861
|
flush() {
|
|
776
|
-
return
|
|
862
|
+
return H = {}, Promise.resolve(void 0);
|
|
777
863
|
}
|
|
778
864
|
};
|
|
779
865
|
case "custom":
|
|
@@ -800,21 +886,21 @@ var Se = class {
|
|
|
800
886
|
}
|
|
801
887
|
async processInlineAssets(e) {
|
|
802
888
|
if (!this.inlineAssets) return e;
|
|
803
|
-
const t = (
|
|
804
|
-
if (!
|
|
805
|
-
if (Array.isArray(
|
|
806
|
-
let
|
|
807
|
-
|
|
808
|
-
...e.data.assets.find((i) => i.id ===
|
|
809
|
-
...
|
|
889
|
+
const t = (r) => {
|
|
890
|
+
if (!r || typeof r != "object") return r;
|
|
891
|
+
if (Array.isArray(r)) return r.map((i) => t(i));
|
|
892
|
+
let s = { ...r };
|
|
893
|
+
s.fieldtype === "asset" && Array.isArray(e.data.assets) && (s = {
|
|
894
|
+
...e.data.assets.find((i) => i.id === s.id),
|
|
895
|
+
...s
|
|
810
896
|
});
|
|
811
|
-
for (const i in
|
|
812
|
-
return
|
|
897
|
+
for (const i in s) typeof s[i] == "object" && (s[i] = t(s[i]));
|
|
898
|
+
return s;
|
|
813
899
|
};
|
|
814
|
-
return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((
|
|
900
|
+
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;
|
|
815
901
|
}
|
|
816
|
-
},
|
|
817
|
-
const
|
|
902
|
+
}, $e = Ue;
|
|
903
|
+
const je = (e = {}) => {
|
|
818
904
|
const { apiOptions: t } = e;
|
|
819
905
|
if (!t || !t.accessToken) {
|
|
820
906
|
console.error(
|
|
@@ -822,8 +908,8 @@ const Te = (e = {}) => {
|
|
|
822
908
|
);
|
|
823
909
|
return;
|
|
824
910
|
}
|
|
825
|
-
return { storyblokApi: new
|
|
826
|
-
},
|
|
911
|
+
return { storyblokApi: new $e(t) };
|
|
912
|
+
}, Ge = (e) => {
|
|
827
913
|
if (typeof e != "object" || typeof e._editable > "u")
|
|
828
914
|
return {};
|
|
829
915
|
try {
|
|
@@ -838,57 +924,57 @@ const Te = (e = {}) => {
|
|
|
838
924
|
return {};
|
|
839
925
|
}
|
|
840
926
|
};
|
|
841
|
-
let
|
|
842
|
-
const
|
|
843
|
-
var
|
|
844
|
-
const i = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((
|
|
927
|
+
let q = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
928
|
+
const qe = (e, t, r = {}) => {
|
|
929
|
+
var a;
|
|
930
|
+
const i = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = new URL((a = window.location) == null ? void 0 : a.href).searchParams.get(
|
|
845
931
|
"_storyblok"
|
|
846
|
-
),
|
|
847
|
-
if (!(!i || !
|
|
932
|
+
), l = n !== null && +n === e;
|
|
933
|
+
if (!(!i || !l)) {
|
|
848
934
|
if (!e) {
|
|
849
935
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
850
936
|
return;
|
|
851
937
|
}
|
|
852
938
|
window.storyblokRegisterEvent(() => {
|
|
853
|
-
new window.StoryblokBridge(
|
|
854
|
-
var
|
|
855
|
-
|
|
939
|
+
new window.StoryblokBridge(r).on(["input", "published", "change"], (c) => {
|
|
940
|
+
var f;
|
|
941
|
+
c && (c.action === "input" && ((f = c.story) == null ? void 0 : f.id) === e ? t(c.story) : (c.action === "change" || c.action === "published") && c.storyId === e && window.location.reload());
|
|
856
942
|
});
|
|
857
943
|
});
|
|
858
944
|
}
|
|
859
|
-
},
|
|
860
|
-
var
|
|
945
|
+
}, Fe = (e = {}) => {
|
|
946
|
+
var f, y;
|
|
861
947
|
const {
|
|
862
948
|
bridge: t,
|
|
863
|
-
accessToken:
|
|
864
|
-
use:
|
|
949
|
+
accessToken: r,
|
|
950
|
+
use: s = [],
|
|
865
951
|
apiOptions: i = {},
|
|
866
952
|
bridgeUrl: n
|
|
867
953
|
} = e;
|
|
868
|
-
i.accessToken = i.accessToken ||
|
|
869
|
-
const
|
|
870
|
-
let
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
}), n && (
|
|
874
|
-
const
|
|
875
|
-
return t !== !1 &&
|
|
954
|
+
i.accessToken = i.accessToken || r;
|
|
955
|
+
const l = { bridge: t, apiOptions: i };
|
|
956
|
+
let a = {};
|
|
957
|
+
s.forEach((A) => {
|
|
958
|
+
a = { ...a, ...A(l) };
|
|
959
|
+
}), n && (q = n);
|
|
960
|
+
const c = !(typeof window > "u") && ((y = (f = window.location) == null ? void 0 : f.search) == null ? void 0 : y.includes("_storyblok_tk"));
|
|
961
|
+
return t !== !1 && c && X(q), a;
|
|
876
962
|
};
|
|
877
|
-
function
|
|
878
|
-
return
|
|
963
|
+
function De(e, t) {
|
|
964
|
+
return me(t).render(e);
|
|
879
965
|
}
|
|
880
|
-
const
|
|
966
|
+
const Be = () => X(q);
|
|
881
967
|
export {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
968
|
+
v as BlockTypes,
|
|
969
|
+
w as MarkTypes,
|
|
970
|
+
$e as StoryblokClient,
|
|
971
|
+
he as TextTypes,
|
|
972
|
+
je as apiPlugin,
|
|
973
|
+
Be as loadStoryblokBridge,
|
|
974
|
+
qe as registerStoryblokBridge,
|
|
975
|
+
De as renderRichText,
|
|
976
|
+
me as richTextResolver,
|
|
977
|
+
Ge as storyblokEditable,
|
|
978
|
+
Fe as storyblokInit,
|
|
979
|
+
qe as useStoryblokBridge
|
|
894
980
|
};
|