@storyblok/react 4.0.0 → 4.2.1
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/LICENSE +21 -0
- package/README.md +26 -2
- package/dist/client.js +1 -1
- package/dist/common/client.d.ts +3 -0
- package/dist/common/client.d.ts.map +1 -0
- package/dist/{types/common → common}/index.d.ts +2 -1
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/storyblok-component.d.ts +7 -0
- package/dist/common/storyblok-component.d.ts.map +1 -0
- package/dist/common.mjs +2 -2
- package/dist/{types/index.d.ts → index.d.ts} +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +4 -4
- package/dist/live-editing.js +1 -1
- package/dist/{types/rsc → rsc}/common.d.ts +2 -1
- package/dist/rsc/common.d.ts.map +1 -0
- package/dist/{types/rsc → rsc}/index.d.ts +1 -0
- package/dist/rsc/index.d.ts.map +1 -0
- package/dist/{types/rsc → rsc}/live-edit-update-action.d.ts +1 -0
- package/dist/rsc/live-edit-update-action.d.ts.map +1 -0
- package/dist/{types/rsc → rsc}/live-editing.d.ts +1 -0
- package/dist/rsc/live-editing.d.ts.map +1 -0
- package/dist/rsc/server-component.d.ts +7 -0
- package/dist/rsc/server-component.d.ts.map +1 -0
- package/dist/rsc/story.d.ts +8 -0
- package/dist/rsc/story.d.ts.map +1 -0
- package/dist/server-component.js +1 -1
- package/dist/server-component.mjs +21 -15
- package/dist/story.js +1 -1
- package/dist/story.mjs +17 -13
- package/dist/storyblok-component.js +1 -1
- package/dist/storyblok-component.mjs +20 -14
- package/dist/storyblok-js.js +24 -24
- package/dist/storyblok-js.mjs +373 -354
- package/dist/{types/types.d.ts → types.d.ts} +2 -1
- package/dist/types.d.ts.map +1 -0
- package/package.json +52 -45
- package/dist/types/common/client.d.ts +0 -2
- package/dist/types/common/storyblok-component.d.ts +0 -8
- package/dist/types/rsc/server-component.d.ts +0 -8
- package/dist/types/rsc/story.d.ts +0 -9
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let _ = !1;
|
|
2
|
-
const j = [],
|
|
2
|
+
const j = [], E = (o) => new Promise((e, t) => {
|
|
3
3
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
|
4
4
|
if (window.location === window.parent.location) {
|
|
5
5
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
@@ -8,165 +8,169 @@ const j = [], O = (n) => new Promise((e, t) => {
|
|
|
8
8
|
_ ? r() : j.push(r);
|
|
9
9
|
}, document.getElementById("storyblok-javascript-bridge"))) return;
|
|
10
10
|
const s = document.createElement("script");
|
|
11
|
-
s.async = !0, s.src =
|
|
12
|
-
j.forEach((
|
|
11
|
+
s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
|
12
|
+
j.forEach((i) => i()), _ = !0, e(r);
|
|
13
13
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
14
14
|
});
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
var O = Object.defineProperty, I = (o, e, t) => e in o ? O(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, c = (o, e, t) => I(o, typeof e != "symbol" ? e + "" : e, t);
|
|
16
|
+
class C extends Error {
|
|
17
|
+
constructor(e) {
|
|
18
|
+
super(e), this.name = "AbortError";
|
|
19
|
+
}
|
|
18
20
|
}
|
|
19
|
-
function
|
|
20
|
-
if (!
|
|
21
|
+
function N(o, e, t) {
|
|
22
|
+
if (!Number.isFinite(e))
|
|
21
23
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
22
|
-
if (!
|
|
24
|
+
if (!Number.isFinite(t))
|
|
23
25
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
24
26
|
const s = [];
|
|
25
|
-
let r = [],
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
let r = [], i = 0, n = !1;
|
|
28
|
+
const a = async () => {
|
|
29
|
+
i++;
|
|
30
|
+
const h = s.shift();
|
|
31
|
+
if (h)
|
|
32
|
+
try {
|
|
33
|
+
const d = await o(...h.args);
|
|
34
|
+
h.resolve(d);
|
|
35
|
+
} catch (d) {
|
|
36
|
+
h.reject(d);
|
|
37
|
+
}
|
|
38
|
+
const u = setTimeout(() => {
|
|
39
|
+
i--, s.length > 0 && a(), r = r.filter((d) => d !== u);
|
|
32
40
|
}, t);
|
|
33
|
-
r.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
a.reject(function() {
|
|
50
|
-
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
51
|
-
});
|
|
52
|
-
}), s.length = 0;
|
|
41
|
+
r.includes(u) || r.push(u);
|
|
42
|
+
}, l = (...h) => n ? Promise.reject(
|
|
43
|
+
new Error(
|
|
44
|
+
"Throttled function is already aborted and not accepting new promises"
|
|
45
|
+
)
|
|
46
|
+
) : new Promise((u, d) => {
|
|
47
|
+
s.push({
|
|
48
|
+
resolve: u,
|
|
49
|
+
reject: d,
|
|
50
|
+
args: h
|
|
51
|
+
}), i < e && a();
|
|
52
|
+
});
|
|
53
|
+
return l.abort = () => {
|
|
54
|
+
n = !0, r.forEach(clearTimeout), r = [], s.forEach(
|
|
55
|
+
(h) => h.reject(() => new C("Throttle function aborted"))
|
|
56
|
+
), s.length = 0;
|
|
53
57
|
}, l;
|
|
54
58
|
}
|
|
55
|
-
class
|
|
59
|
+
let y = class {
|
|
56
60
|
constructor() {
|
|
57
|
-
c(this, "isCDNUrl", (
|
|
58
|
-
...
|
|
59
|
-
per_page:
|
|
60
|
-
page:
|
|
61
|
-
})), c(this, "delay", (
|
|
62
|
-
const
|
|
63
|
-
return this.arrayFrom(
|
|
64
|
-
}), c(this, "asyncMap", async (
|
|
65
|
-
const
|
|
61
|
+
c(this, "isCDNUrl", (o = "") => o.includes("/cdn/")), c(this, "getOptionsPage", (o, e = 25, t = 1) => ({
|
|
62
|
+
...o,
|
|
63
|
+
per_page: e,
|
|
64
|
+
page: t
|
|
65
|
+
})), c(this, "delay", (o) => new Promise((e) => setTimeout(e, o))), c(this, "arrayFrom", (o = 0, e) => Array.from({ length: o }, e)), c(this, "range", (o = 0, e = o) => {
|
|
66
|
+
const t = Math.abs(e - o) || 0, s = o < e ? 1 : -1;
|
|
67
|
+
return this.arrayFrom(t, (r, i) => i * s + o);
|
|
68
|
+
}), c(this, "asyncMap", async (o, e) => Promise.all(o.map(e))), c(this, "flatMap", (o = [], e) => o.map(e).reduce((t, s) => [...t, ...s], [])), c(this, "escapeHTML", function(o) {
|
|
69
|
+
const e = {
|
|
66
70
|
"&": "&",
|
|
67
71
|
"<": "<",
|
|
68
72
|
">": ">",
|
|
69
73
|
'"': """,
|
|
70
74
|
"'": "'"
|
|
71
|
-
},
|
|
72
|
-
return
|
|
75
|
+
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
|
76
|
+
return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
|
|
73
77
|
});
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
80
|
* @method stringify
|
|
77
|
-
* @param {
|
|
78
|
-
* @param {
|
|
79
|
-
* @param {
|
|
80
|
-
* @return {
|
|
81
|
+
* @param {object} params
|
|
82
|
+
* @param {string} prefix
|
|
83
|
+
* @param {boolean} isArray
|
|
84
|
+
* @return {string} Stringified object
|
|
81
85
|
*/
|
|
82
|
-
stringify(e, t
|
|
83
|
-
const
|
|
84
|
-
for (const
|
|
85
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
86
|
+
stringify(o, e, t) {
|
|
87
|
+
const s = [];
|
|
88
|
+
for (const r in o) {
|
|
89
|
+
if (!Object.prototype.hasOwnProperty.call(o, r))
|
|
86
90
|
continue;
|
|
87
|
-
const i =
|
|
91
|
+
const i = o[r], n = t ? "" : encodeURIComponent(r);
|
|
88
92
|
let a;
|
|
89
93
|
typeof i == "object" ? a = this.stringify(
|
|
90
94
|
i,
|
|
91
|
-
|
|
95
|
+
e ? e + encodeURIComponent(`[${n}]`) : n,
|
|
92
96
|
Array.isArray(i)
|
|
93
|
-
) : a =
|
|
97
|
+
) : a = `${e ? e + encodeURIComponent(`[${n}]`) : n}=${encodeURIComponent(i)}`, s.push(a);
|
|
94
98
|
}
|
|
95
|
-
return
|
|
99
|
+
return s.join("&");
|
|
96
100
|
}
|
|
97
101
|
/**
|
|
98
102
|
* @method getRegionURL
|
|
99
|
-
* @param {
|
|
100
|
-
* @return {
|
|
103
|
+
* @param {string} regionCode region code, could be eu, us, cn, ap or ca
|
|
104
|
+
* @return {string} The base URL of the region
|
|
101
105
|
*/
|
|
102
|
-
getRegionURL(
|
|
103
|
-
const
|
|
104
|
-
switch (
|
|
106
|
+
getRegionURL(o) {
|
|
107
|
+
const e = "api.storyblok.com", t = "api-us.storyblok.com", s = "app.storyblokchina.cn", r = "api-ap.storyblok.com", i = "api-ca.storyblok.com";
|
|
108
|
+
switch (o) {
|
|
105
109
|
case "us":
|
|
106
|
-
return
|
|
110
|
+
return t;
|
|
107
111
|
case "cn":
|
|
108
|
-
return
|
|
112
|
+
return s;
|
|
109
113
|
case "ap":
|
|
110
|
-
return
|
|
114
|
+
return r;
|
|
111
115
|
case "ca":
|
|
112
116
|
return i;
|
|
113
117
|
default:
|
|
114
|
-
return
|
|
118
|
+
return e;
|
|
115
119
|
}
|
|
116
120
|
}
|
|
117
|
-
}
|
|
118
|
-
const A = function(
|
|
121
|
+
};
|
|
122
|
+
const A = function(o, e) {
|
|
119
123
|
const t = {};
|
|
120
|
-
for (const s in
|
|
121
|
-
const r =
|
|
122
|
-
e.
|
|
124
|
+
for (const s in o) {
|
|
125
|
+
const r = o[s];
|
|
126
|
+
e.includes(s) && r !== null && (t[s] = r);
|
|
123
127
|
}
|
|
124
128
|
return t;
|
|
125
|
-
},
|
|
129
|
+
}, L = (o) => o === "email", M = () => ({
|
|
126
130
|
singleTag: "hr"
|
|
127
|
-
}),
|
|
131
|
+
}), z = () => ({
|
|
128
132
|
tag: "blockquote"
|
|
129
133
|
}), H = () => ({
|
|
130
134
|
tag: "ul"
|
|
131
|
-
}), U = (
|
|
135
|
+
}), U = (o) => ({
|
|
132
136
|
tag: [
|
|
133
137
|
"pre",
|
|
134
138
|
{
|
|
135
139
|
tag: "code",
|
|
136
|
-
attrs:
|
|
140
|
+
attrs: o.attrs
|
|
137
141
|
}
|
|
138
142
|
]
|
|
139
|
-
}),
|
|
143
|
+
}), q = () => ({
|
|
140
144
|
singleTag: "br"
|
|
141
|
-
}),
|
|
142
|
-
tag: `h${
|
|
143
|
-
}),
|
|
145
|
+
}), B = (o) => ({
|
|
146
|
+
tag: `h${o.attrs.level}`
|
|
147
|
+
}), V = (o) => ({
|
|
144
148
|
singleTag: [
|
|
145
149
|
{
|
|
146
150
|
tag: "img",
|
|
147
|
-
attrs: A(
|
|
151
|
+
attrs: A(o.attrs, ["src", "alt", "title"])
|
|
148
152
|
}
|
|
149
153
|
]
|
|
150
154
|
}), D = () => ({
|
|
151
155
|
tag: "li"
|
|
152
|
-
}),
|
|
156
|
+
}), F = () => ({
|
|
153
157
|
tag: "ol"
|
|
154
158
|
}), J = () => ({
|
|
155
159
|
tag: "p"
|
|
156
|
-
}),
|
|
160
|
+
}), W = (o) => ({
|
|
157
161
|
tag: [
|
|
158
162
|
{
|
|
159
163
|
tag: "span",
|
|
160
164
|
attrs: {
|
|
161
165
|
"data-type": "emoji",
|
|
162
|
-
"data-name":
|
|
163
|
-
emoji:
|
|
166
|
+
"data-name": o.attrs.name,
|
|
167
|
+
emoji: o.attrs.emoji
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
]
|
|
167
|
-
}), W = () => ({
|
|
168
|
-
tag: "b"
|
|
169
171
|
}), Y = () => ({
|
|
172
|
+
tag: "b"
|
|
173
|
+
}), G = () => ({
|
|
170
174
|
tag: "s"
|
|
171
175
|
}), K = () => ({
|
|
172
176
|
tag: "u"
|
|
@@ -176,13 +180,13 @@ const A = function(n, e) {
|
|
|
176
180
|
tag: "code"
|
|
177
181
|
}), Z = () => ({
|
|
178
182
|
tag: "i"
|
|
179
|
-
}),
|
|
180
|
-
if (!
|
|
183
|
+
}), ee = (o) => {
|
|
184
|
+
if (!o.attrs)
|
|
181
185
|
return {
|
|
182
186
|
tag: ""
|
|
183
187
|
};
|
|
184
|
-
const e = new
|
|
185
|
-
if (delete t.linktype, t.href && (t.href = e(
|
|
188
|
+
const e = new y().escapeHTML, t = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
|
|
189
|
+
if (delete t.linktype, t.href && (t.href = e(o.attrs.href || "")), L(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
186
190
|
for (const r in t.custom)
|
|
187
191
|
t[r] = t.custom[r];
|
|
188
192
|
delete t.custom;
|
|
@@ -195,94 +199,95 @@ const A = function(n, e) {
|
|
|
195
199
|
}
|
|
196
200
|
]
|
|
197
201
|
};
|
|
198
|
-
},
|
|
202
|
+
}, te = (o) => ({
|
|
199
203
|
tag: [
|
|
200
204
|
{
|
|
201
205
|
tag: "span",
|
|
202
|
-
attrs:
|
|
206
|
+
attrs: o.attrs
|
|
203
207
|
}
|
|
204
208
|
]
|
|
205
|
-
}), te = () => ({
|
|
206
|
-
tag: "sub"
|
|
207
209
|
}), se = () => ({
|
|
210
|
+
tag: "sub"
|
|
211
|
+
}), re = () => ({
|
|
208
212
|
tag: "sup"
|
|
209
|
-
}),
|
|
213
|
+
}), oe = (o) => ({
|
|
210
214
|
tag: [
|
|
211
215
|
{
|
|
212
216
|
tag: "span",
|
|
213
|
-
attrs:
|
|
217
|
+
attrs: o.attrs
|
|
214
218
|
}
|
|
215
219
|
]
|
|
216
|
-
}),
|
|
220
|
+
}), ie = (o) => {
|
|
217
221
|
var e;
|
|
218
|
-
return (e =
|
|
222
|
+
return (e = o.attrs) != null && e.color ? {
|
|
219
223
|
tag: [
|
|
220
224
|
{
|
|
221
225
|
tag: "span",
|
|
222
226
|
attrs: {
|
|
223
|
-
style: `background-color:${
|
|
227
|
+
style: `background-color:${o.attrs.color};`
|
|
224
228
|
}
|
|
225
229
|
}
|
|
226
230
|
]
|
|
227
231
|
} : {
|
|
228
232
|
tag: ""
|
|
229
233
|
};
|
|
230
|
-
},
|
|
234
|
+
}, ne = (o) => {
|
|
231
235
|
var e;
|
|
232
|
-
return (e =
|
|
236
|
+
return (e = o.attrs) != null && e.color ? {
|
|
233
237
|
tag: [
|
|
234
238
|
{
|
|
235
239
|
tag: "span",
|
|
236
240
|
attrs: {
|
|
237
|
-
style: `color:${
|
|
241
|
+
style: `color:${o.attrs.color}`
|
|
238
242
|
}
|
|
239
243
|
}
|
|
240
244
|
]
|
|
241
245
|
} : {
|
|
242
246
|
tag: ""
|
|
243
247
|
};
|
|
244
|
-
},
|
|
248
|
+
}, ae = {
|
|
245
249
|
nodes: {
|
|
246
|
-
horizontal_rule:
|
|
247
|
-
blockquote:
|
|
250
|
+
horizontal_rule: M,
|
|
251
|
+
blockquote: z,
|
|
248
252
|
bullet_list: H,
|
|
249
253
|
code_block: U,
|
|
250
|
-
hard_break:
|
|
251
|
-
heading:
|
|
252
|
-
image:
|
|
254
|
+
hard_break: q,
|
|
255
|
+
heading: B,
|
|
256
|
+
image: V,
|
|
253
257
|
list_item: D,
|
|
254
|
-
ordered_list:
|
|
258
|
+
ordered_list: F,
|
|
255
259
|
paragraph: J,
|
|
256
|
-
emoji:
|
|
260
|
+
emoji: W
|
|
257
261
|
},
|
|
258
262
|
marks: {
|
|
259
|
-
bold:
|
|
260
|
-
strike:
|
|
263
|
+
bold: Y,
|
|
264
|
+
strike: G,
|
|
261
265
|
underline: K,
|
|
262
266
|
strong: Q,
|
|
263
267
|
code: X,
|
|
264
268
|
italic: Z,
|
|
265
|
-
link:
|
|
266
|
-
styled:
|
|
267
|
-
subscript:
|
|
268
|
-
superscript:
|
|
269
|
-
anchor:
|
|
270
|
-
highlight:
|
|
271
|
-
textStyle:
|
|
272
|
-
}
|
|
273
|
-
},
|
|
269
|
+
link: ee,
|
|
270
|
+
styled: te,
|
|
271
|
+
subscript: se,
|
|
272
|
+
superscript: re,
|
|
273
|
+
anchor: oe,
|
|
274
|
+
highlight: ie,
|
|
275
|
+
textStyle: ne
|
|
276
|
+
}
|
|
277
|
+
}, le = function(o) {
|
|
274
278
|
const e = {
|
|
275
279
|
"&": "&",
|
|
276
280
|
"<": "<",
|
|
277
281
|
">": ">",
|
|
278
282
|
'"': """,
|
|
279
283
|
"'": "'"
|
|
280
|
-
}, t = /[&<>"']/g, s = RegExp(t.source);
|
|
281
|
-
return
|
|
284
|
+
}, t = /[&<>"']/g, s = new RegExp(t.source);
|
|
285
|
+
return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
|
|
282
286
|
};
|
|
283
|
-
|
|
287
|
+
let x = !1;
|
|
288
|
+
class ce {
|
|
284
289
|
constructor(e) {
|
|
285
|
-
c(this, "marks"), c(this, "nodes"), e || (e =
|
|
290
|
+
c(this, "marks"), c(this, "nodes"), e || (e = ae), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
286
291
|
}
|
|
287
292
|
addNode(e, t) {
|
|
288
293
|
this.nodes[e] = t;
|
|
@@ -290,84 +295,85 @@ class le {
|
|
|
290
295
|
addMark(e, t) {
|
|
291
296
|
this.marks[e] = t;
|
|
292
297
|
}
|
|
293
|
-
render(e, t = { optimizeImages: !1 }) {
|
|
294
|
-
if (console.warn(
|
|
298
|
+
render(e, t = { optimizeImages: !1 }, s = !0) {
|
|
299
|
+
if (!x && s && (console.warn(
|
|
295
300
|
"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/"
|
|
296
|
-
), e && e.content && Array.isArray(e.content)) {
|
|
297
|
-
let
|
|
298
|
-
return e.content.forEach((
|
|
299
|
-
|
|
300
|
-
}), t.optimizeImages ? this.optimizeImages(
|
|
301
|
+
), x = !0), e && e.content && Array.isArray(e.content)) {
|
|
302
|
+
let r = "";
|
|
303
|
+
return e.content.forEach((i) => {
|
|
304
|
+
r += this.renderNode(i);
|
|
305
|
+
}), t.optimizeImages ? this.optimizeImages(r, t.optimizeImages) : r;
|
|
301
306
|
}
|
|
302
307
|
return console.warn(
|
|
303
308
|
`The render method must receive an Object with a "content" field.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
309
|
+
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
310
|
+
ISbRichtext:
|
|
311
|
+
content?: ISbRichtext[]
|
|
312
|
+
marks?: ISbRichtext[]
|
|
313
|
+
attrs?: any
|
|
314
|
+
text?: string
|
|
315
|
+
type: string
|
|
316
|
+
|
|
317
|
+
Example:
|
|
318
|
+
{
|
|
319
|
+
content: [
|
|
320
|
+
{
|
|
321
|
+
content: [
|
|
322
|
+
{
|
|
323
|
+
text: 'Hello World',
|
|
324
|
+
type: 'text'
|
|
325
|
+
}
|
|
326
|
+
],
|
|
327
|
+
type: 'paragraph'
|
|
328
|
+
}
|
|
329
|
+
],
|
|
330
|
+
type: 'doc'
|
|
331
|
+
}`
|
|
327
332
|
), "";
|
|
328
333
|
}
|
|
329
334
|
optimizeImages(e, t) {
|
|
330
|
-
let s = 0, r = 0,
|
|
331
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
|
332
|
-
const
|
|
335
|
+
let s = 0, r = 0, i = "", n = "";
|
|
336
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (i += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (i += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (i += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (i += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-F]{6}/gi) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = `/filters${n}`))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
|
|
337
|
+
const a = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
|
|
333
338
|
return e = e.replace(
|
|
334
|
-
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|
|
|
335
|
-
`a.storyblok.com/f/$1/$2.$3/m/${
|
|
336
|
-
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (
|
|
337
|
-
var
|
|
338
|
-
const d =
|
|
339
|
-
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|
|
|
339
|
+
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,
|
|
340
|
+
`a.storyblok.com/f/$1/$2.$3/m/${a}`
|
|
341
|
+
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (l) => {
|
|
342
|
+
var h, u;
|
|
343
|
+
const d = l.match(
|
|
344
|
+
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g
|
|
340
345
|
);
|
|
341
346
|
if (d && d.length > 0) {
|
|
342
|
-
const
|
|
343
|
-
srcset: (
|
|
344
|
-
if (typeof
|
|
345
|
-
return `//${d}/m/${
|
|
346
|
-
if (typeof
|
|
347
|
-
let k = 0,
|
|
348
|
-
return typeof
|
|
347
|
+
const p = {
|
|
348
|
+
srcset: (h = t.srcset) == null ? void 0 : h.map((g) => {
|
|
349
|
+
if (typeof g == "number")
|
|
350
|
+
return `//${d}/m/${g}x0${n} ${g}w`;
|
|
351
|
+
if (typeof g == "object" && g.length === 2) {
|
|
352
|
+
let k = 0, T = 0;
|
|
353
|
+
return typeof g[0] == "number" && (k = g[0]), typeof g[1] == "number" && (T = g[1]), `//${d}/m/${k}x${T}${n} ${k}w`;
|
|
349
354
|
}
|
|
355
|
+
return "";
|
|
350
356
|
}).join(", "),
|
|
351
|
-
sizes: (
|
|
357
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((g) => g).join(", ")
|
|
352
358
|
};
|
|
353
|
-
let
|
|
354
|
-
return
|
|
359
|
+
let v = "";
|
|
360
|
+
return p.srcset && (v += `srcset="${p.srcset}" `), p.sizes && (v += `sizes="${p.sizes}" `), l.replace(/<img/g, `<img ${v.trim()}`);
|
|
355
361
|
}
|
|
356
|
-
return
|
|
362
|
+
return l;
|
|
357
363
|
})), e;
|
|
358
364
|
}
|
|
359
365
|
renderNode(e) {
|
|
360
366
|
const t = [];
|
|
361
367
|
e.marks && e.marks.forEach((r) => {
|
|
362
|
-
const
|
|
363
|
-
|
|
368
|
+
const i = this.getMatchingMark(r);
|
|
369
|
+
i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
|
|
364
370
|
});
|
|
365
371
|
const s = this.getMatchingNode(e);
|
|
366
372
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
367
373
|
t.push(this.renderNode(r));
|
|
368
|
-
}) : e.text ? t.push(
|
|
369
|
-
const
|
|
370
|
-
|
|
374
|
+
}) : e.text ? t.push(le(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) => {
|
|
375
|
+
const i = this.getMatchingMark(r);
|
|
376
|
+
i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
|
|
371
377
|
}), t.join("");
|
|
372
378
|
}
|
|
373
379
|
renderTag(e, t) {
|
|
@@ -377,10 +383,10 @@ class le {
|
|
|
377
383
|
{
|
|
378
384
|
let r = `<${s.tag}`;
|
|
379
385
|
if (s.attrs) {
|
|
380
|
-
for (const
|
|
381
|
-
if (Object.prototype.hasOwnProperty.call(s.attrs,
|
|
382
|
-
const
|
|
383
|
-
|
|
386
|
+
for (const i in s.attrs)
|
|
387
|
+
if (Object.prototype.hasOwnProperty.call(s.attrs, i)) {
|
|
388
|
+
const n = s.attrs[i];
|
|
389
|
+
n !== null && (r += ` ${i}="${n}"`);
|
|
384
390
|
}
|
|
385
391
|
}
|
|
386
392
|
return `${r}${t}>`;
|
|
@@ -420,8 +426,8 @@ class le {
|
|
|
420
426
|
return this.renderTag(t, " /");
|
|
421
427
|
}
|
|
422
428
|
}
|
|
423
|
-
const
|
|
424
|
-
class
|
|
429
|
+
const b = ce;
|
|
430
|
+
class he {
|
|
425
431
|
constructor(e) {
|
|
426
432
|
c(this, "baseURL"), c(this, "timeout"), c(this, "headers"), c(this, "responseInterceptor"), c(this, "fetch"), c(this, "ejectInterceptor"), c(this, "url"), c(this, "parameters"), c(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 = {};
|
|
427
433
|
}
|
|
@@ -460,31 +466,31 @@ class ce {
|
|
|
460
466
|
async _methodHandler(e) {
|
|
461
467
|
let t = `${this.baseURL}${this.url}`, s = null;
|
|
462
468
|
if (e === "get") {
|
|
463
|
-
const
|
|
464
|
-
t = `${this.baseURL}${this.url}?${
|
|
469
|
+
const l = new y();
|
|
470
|
+
t = `${this.baseURL}${this.url}?${l.stringify(
|
|
465
471
|
this.parameters
|
|
466
472
|
)}`;
|
|
467
473
|
} else
|
|
468
474
|
s = JSON.stringify(this.parameters);
|
|
469
|
-
const r = new URL(t),
|
|
470
|
-
let
|
|
471
|
-
this.timeout && (
|
|
475
|
+
const r = new URL(t), i = new AbortController(), { signal: n } = i;
|
|
476
|
+
let a;
|
|
477
|
+
this.timeout && (a = setTimeout(() => i.abort(), this.timeout));
|
|
472
478
|
try {
|
|
473
|
-
const
|
|
479
|
+
const l = await this.fetch(`${r}`, {
|
|
474
480
|
method: e,
|
|
475
481
|
headers: this.headers,
|
|
476
482
|
body: s,
|
|
477
|
-
signal:
|
|
483
|
+
signal: n,
|
|
478
484
|
...this.fetchOptions
|
|
479
485
|
});
|
|
480
|
-
this.timeout && clearTimeout(
|
|
481
|
-
const
|
|
482
|
-
|
|
486
|
+
this.timeout && clearTimeout(a);
|
|
487
|
+
const h = await this._responseHandler(
|
|
488
|
+
l
|
|
483
489
|
);
|
|
484
|
-
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(
|
|
485
|
-
} catch (
|
|
490
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
|
|
491
|
+
} catch (l) {
|
|
486
492
|
return {
|
|
487
|
-
message:
|
|
493
|
+
message: l
|
|
488
494
|
};
|
|
489
495
|
}
|
|
490
496
|
}
|
|
@@ -499,44 +505,48 @@ class ce {
|
|
|
499
505
|
return new Promise((s, r) => {
|
|
500
506
|
if (t.test(`${e.status}`))
|
|
501
507
|
return s(e);
|
|
502
|
-
const
|
|
508
|
+
const i = {
|
|
503
509
|
message: e.statusText,
|
|
504
510
|
status: e.status,
|
|
505
511
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
|
506
512
|
};
|
|
507
|
-
r(
|
|
513
|
+
r(i);
|
|
508
514
|
});
|
|
509
515
|
}
|
|
510
516
|
}
|
|
511
|
-
const
|
|
517
|
+
const ue = he, S = "SB-Agent", w = {
|
|
512
518
|
defaultAgentName: "SB-JS-CLIENT",
|
|
513
519
|
defaultAgentVersion: "SB-Agent-Version",
|
|
514
520
|
packageVersion: "6.0.0"
|
|
515
521
|
};
|
|
516
|
-
let
|
|
517
|
-
const
|
|
518
|
-
class
|
|
522
|
+
let m = {};
|
|
523
|
+
const f = {};
|
|
524
|
+
class de {
|
|
519
525
|
/**
|
|
520
526
|
*
|
|
521
527
|
* @param config ISbConfig interface
|
|
522
|
-
* @param
|
|
528
|
+
* @param pEndpoint string, optional
|
|
523
529
|
*/
|
|
524
530
|
constructor(e, t) {
|
|
525
531
|
c(this, "client"), c(this, "maxRetries"), c(this, "retriesDelay"), c(this, "throttle"), c(this, "accessToken"), c(this, "cache"), c(this, "helpers"), c(this, "resolveCounter"), c(this, "relations"), c(this, "links"), c(this, "richTextResolver"), c(this, "resolveNestedRelations"), c(this, "stringifiedStoriesCache");
|
|
526
532
|
let s = e.endpoint || t;
|
|
527
533
|
if (!s) {
|
|
528
|
-
const
|
|
529
|
-
e.oauthToken ? s = `${
|
|
534
|
+
const n = new y().getRegionURL, a = e.https === !1 ? "http" : "https";
|
|
535
|
+
e.oauthToken ? s = `${a}://${n(e.region)}/v1` : s = `${a}://${n(e.region)}/v2`;
|
|
530
536
|
}
|
|
531
537
|
const r = new Headers();
|
|
532
|
-
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([
|
|
533
|
-
r.set(
|
|
538
|
+
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers && (e.headers.constructor.name === "Headers" ? e.headers.entries().toArray() : Object.entries(e.headers)).forEach(([n, a]) => {
|
|
539
|
+
r.set(n, a);
|
|
534
540
|
}), r.has(S) || (r.set(S, w.defaultAgentName), r.set(
|
|
535
541
|
w.defaultAgentVersion,
|
|
536
542
|
w.packageVersion
|
|
537
543
|
));
|
|
538
|
-
let
|
|
539
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken),
|
|
544
|
+
let i = 5;
|
|
545
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), e.richTextSchema ? this.richTextResolver = new b(e.richTextSchema) : this.richTextResolver = new b(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 10, this.retriesDelay = 300, this.throttle = N(
|
|
546
|
+
this.throttledRequest.bind(this),
|
|
547
|
+
i,
|
|
548
|
+
1e3
|
|
549
|
+
), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new y(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new ue({
|
|
540
550
|
baseURL: s,
|
|
541
551
|
timeout: e.timeout || 0,
|
|
542
552
|
headers: r,
|
|
@@ -555,50 +565,53 @@ class ue {
|
|
|
555
565
|
});
|
|
556
566
|
}
|
|
557
567
|
parseParams(e) {
|
|
558
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv =
|
|
568
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = f[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
559
569
|
}
|
|
560
570
|
factoryParamOptions(e, t) {
|
|
561
571
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
562
572
|
}
|
|
563
|
-
makeRequest(e, t, s, r,
|
|
564
|
-
const
|
|
573
|
+
makeRequest(e, t, s, r, i) {
|
|
574
|
+
const n = this.factoryParamOptions(
|
|
565
575
|
e,
|
|
566
576
|
this.helpers.getOptionsPage(t, s, r)
|
|
567
577
|
);
|
|
568
|
-
return this.cacheResponse(e,
|
|
578
|
+
return this.cacheResponse(e, n, void 0, i);
|
|
569
579
|
}
|
|
570
580
|
get(e, t, s) {
|
|
571
581
|
t || (t = {});
|
|
572
|
-
const r = `/${e}`,
|
|
573
|
-
return this.cacheResponse(r,
|
|
582
|
+
const r = `/${e}`, i = this.factoryParamOptions(r, t);
|
|
583
|
+
return this.cacheResponse(r, i, void 0, s);
|
|
574
584
|
}
|
|
575
585
|
async getAll(e, t, s, r) {
|
|
576
|
-
const
|
|
577
|
-
|
|
586
|
+
const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`.replace(/\/$/, ""), a = s ?? n.substring(n.lastIndexOf("/") + 1), l = 1, h = await this.makeRequest(
|
|
587
|
+
n,
|
|
578
588
|
t,
|
|
579
|
-
|
|
580
|
-
|
|
589
|
+
i,
|
|
590
|
+
l,
|
|
581
591
|
r
|
|
582
|
-
),
|
|
583
|
-
this.helpers.range(
|
|
584
|
-
(
|
|
585
|
-
);
|
|
586
|
-
return this.helpers.flatMap(
|
|
587
|
-
[h, ...g],
|
|
588
|
-
(f) => Object.values(f.data[a])
|
|
592
|
+
), u = h.total ? Math.ceil(h.total / i) : 1, d = await this.helpers.asyncMap(
|
|
593
|
+
this.helpers.range(l, u),
|
|
594
|
+
(p) => this.makeRequest(n, t, i, p + 1, r)
|
|
589
595
|
);
|
|
596
|
+
return this.helpers.flatMap([h, ...d], (p) => Object.values(p.data[a]));
|
|
590
597
|
}
|
|
591
598
|
post(e, t, s) {
|
|
592
599
|
const r = `/${e}`;
|
|
593
|
-
return Promise.resolve(
|
|
600
|
+
return Promise.resolve(
|
|
601
|
+
this.throttle("post", r, t, s)
|
|
602
|
+
);
|
|
594
603
|
}
|
|
595
604
|
put(e, t, s) {
|
|
596
605
|
const r = `/${e}`;
|
|
597
|
-
return Promise.resolve(
|
|
606
|
+
return Promise.resolve(
|
|
607
|
+
this.throttle("put", r, t, s)
|
|
608
|
+
);
|
|
598
609
|
}
|
|
599
610
|
delete(e, t, s) {
|
|
600
611
|
const r = `/${e}`;
|
|
601
|
-
return Promise.resolve(
|
|
612
|
+
return Promise.resolve(
|
|
613
|
+
this.throttle("delete", r, t, s)
|
|
614
|
+
);
|
|
602
615
|
}
|
|
603
616
|
getStories(e, t) {
|
|
604
617
|
return this._addResolveLevel(e), this.get("cdn/stories", e, t);
|
|
@@ -620,7 +633,7 @@ class ue {
|
|
|
620
633
|
}
|
|
621
634
|
_insertLinks(e, t, s) {
|
|
622
635
|
const r = e[t];
|
|
623
|
-
r && r.fieldtype
|
|
636
|
+
r && r.fieldtype === "multilink" && r.linktype === "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
|
|
624
637
|
}
|
|
625
638
|
/**
|
|
626
639
|
*
|
|
@@ -634,28 +647,28 @@ class ue {
|
|
|
634
647
|
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
|
635
648
|
}
|
|
636
649
|
_insertRelations(e, t, s, r) {
|
|
637
|
-
s.
|
|
650
|
+
s.includes(`${e.component}.${t}`) && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((i) => this.getStoryReference(r, i)).filter(Boolean)));
|
|
638
651
|
}
|
|
639
652
|
iterateTree(e, t, s) {
|
|
640
|
-
const r = (
|
|
641
|
-
if (
|
|
642
|
-
if (
|
|
643
|
-
for (let
|
|
644
|
-
r(
|
|
645
|
-
else if (
|
|
646
|
-
if (
|
|
653
|
+
const r = (i) => {
|
|
654
|
+
if (i != null) {
|
|
655
|
+
if (i.constructor === Array)
|
|
656
|
+
for (let n = 0; n < i.length; n++)
|
|
657
|
+
r(i[n]);
|
|
658
|
+
else if (i.constructor === Object) {
|
|
659
|
+
if (i._stopResolving)
|
|
647
660
|
return;
|
|
648
|
-
for (const
|
|
649
|
-
(
|
|
650
|
-
o,
|
|
661
|
+
for (const n in i)
|
|
662
|
+
(i.component && i._uid || i.type === "link") && (this._insertRelations(
|
|
651
663
|
i,
|
|
664
|
+
n,
|
|
652
665
|
t,
|
|
653
666
|
s
|
|
654
667
|
), this._insertLinks(
|
|
655
|
-
o,
|
|
656
668
|
i,
|
|
669
|
+
n,
|
|
657
670
|
s
|
|
658
|
-
)), r(
|
|
671
|
+
)), r(i[n]);
|
|
659
672
|
}
|
|
660
673
|
}
|
|
661
674
|
};
|
|
@@ -664,27 +677,27 @@ class ue {
|
|
|
664
677
|
async resolveLinks(e, t, s) {
|
|
665
678
|
let r = [];
|
|
666
679
|
if (e.link_uuids) {
|
|
667
|
-
const
|
|
668
|
-
for (let
|
|
669
|
-
const
|
|
670
|
-
|
|
680
|
+
const i = e.link_uuids.length, n = [], a = 50;
|
|
681
|
+
for (let l = 0; l < i; l += a) {
|
|
682
|
+
const h = Math.min(i, l + a);
|
|
683
|
+
n.push(e.link_uuids.slice(l, h));
|
|
671
684
|
}
|
|
672
|
-
for (let
|
|
685
|
+
for (let l = 0; l < n.length; l++)
|
|
673
686
|
(await this.getStories({
|
|
674
|
-
per_page:
|
|
687
|
+
per_page: a,
|
|
675
688
|
language: t.language,
|
|
676
689
|
version: t.version,
|
|
677
|
-
by_uuids:
|
|
690
|
+
by_uuids: n[l].join(",")
|
|
678
691
|
})).data.stories.forEach(
|
|
679
|
-
(
|
|
680
|
-
r.push(
|
|
692
|
+
(h) => {
|
|
693
|
+
r.push(h);
|
|
681
694
|
}
|
|
682
695
|
);
|
|
683
696
|
} else
|
|
684
697
|
r = e.links;
|
|
685
|
-
r.forEach((
|
|
686
|
-
this.links[s][
|
|
687
|
-
...
|
|
698
|
+
r.forEach((i) => {
|
|
699
|
+
this.links[s][i.uuid] = {
|
|
700
|
+
...i,
|
|
688
701
|
_stopResolving: !0
|
|
689
702
|
};
|
|
690
703
|
});
|
|
@@ -692,26 +705,26 @@ class ue {
|
|
|
692
705
|
async resolveRelations(e, t, s) {
|
|
693
706
|
let r = [];
|
|
694
707
|
if (e.rel_uuids) {
|
|
695
|
-
const
|
|
696
|
-
for (let
|
|
697
|
-
const
|
|
698
|
-
|
|
708
|
+
const i = e.rel_uuids.length, n = [], a = 50;
|
|
709
|
+
for (let l = 0; l < i; l += a) {
|
|
710
|
+
const h = Math.min(i, l + a);
|
|
711
|
+
n.push(e.rel_uuids.slice(l, h));
|
|
699
712
|
}
|
|
700
|
-
for (let
|
|
713
|
+
for (let l = 0; l < n.length; l++)
|
|
701
714
|
(await this.getStories({
|
|
702
|
-
per_page:
|
|
715
|
+
per_page: a,
|
|
703
716
|
language: t.language,
|
|
704
717
|
version: t.version,
|
|
705
|
-
by_uuids:
|
|
718
|
+
by_uuids: n[l].join(","),
|
|
706
719
|
excluding_fields: t.excluding_fields
|
|
707
|
-
})).data.stories.forEach((
|
|
708
|
-
r.push(
|
|
720
|
+
})).data.stories.forEach((h) => {
|
|
721
|
+
r.push(h);
|
|
709
722
|
});
|
|
710
723
|
} else
|
|
711
724
|
r = e.rels;
|
|
712
|
-
r && r.length > 0 && r.forEach((
|
|
713
|
-
this.relations[s][
|
|
714
|
-
...
|
|
725
|
+
r && r.length > 0 && r.forEach((i) => {
|
|
726
|
+
this.relations[s][i.uuid] = {
|
|
727
|
+
...i,
|
|
715
728
|
_stopResolving: !0
|
|
716
729
|
};
|
|
717
730
|
});
|
|
@@ -726,47 +739,52 @@ class ue {
|
|
|
726
739
|
*
|
|
727
740
|
*/
|
|
728
741
|
async resolveStories(e, t, s) {
|
|
729
|
-
var r,
|
|
730
|
-
let
|
|
731
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (
|
|
732
|
-
for (const
|
|
742
|
+
var r, i;
|
|
743
|
+
let n = [];
|
|
744
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].includes(t.resolve_links) && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
|
745
|
+
for (const a in this.relations[s])
|
|
733
746
|
this.iterateTree(
|
|
734
|
-
this.relations[s][
|
|
735
|
-
|
|
747
|
+
this.relations[s][a],
|
|
748
|
+
n,
|
|
736
749
|
s
|
|
737
750
|
);
|
|
738
|
-
e.story ? this.iterateTree(e.story,
|
|
739
|
-
this.iterateTree(
|
|
751
|
+
e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((a) => {
|
|
752
|
+
this.iterateTree(a, n, s);
|
|
740
753
|
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
741
754
|
}
|
|
742
755
|
async cacheResponse(e, t, s, r) {
|
|
743
|
-
const
|
|
744
|
-
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e
|
|
745
|
-
const
|
|
746
|
-
if (
|
|
747
|
-
return Promise.resolve(
|
|
756
|
+
const i = this.helpers.stringify({ url: e, params: t }), n = this.cacheProvider();
|
|
757
|
+
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e !== "/cdn/spaces/me") {
|
|
758
|
+
const a = await n.get(i);
|
|
759
|
+
if (a)
|
|
760
|
+
return Promise.resolve(a);
|
|
748
761
|
}
|
|
749
|
-
return new Promise(async (
|
|
750
|
-
var
|
|
762
|
+
return new Promise(async (a, l) => {
|
|
763
|
+
var h;
|
|
751
764
|
try {
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
765
|
+
const u = await this.throttle(
|
|
766
|
+
"get",
|
|
767
|
+
e,
|
|
768
|
+
t,
|
|
769
|
+
r
|
|
770
|
+
);
|
|
771
|
+
if (u.status !== 200)
|
|
772
|
+
return l(u);
|
|
773
|
+
let d = { data: u.data, headers: u.headers };
|
|
774
|
+
if ((h = u.headers) != null && h["per-page"] && (d = Object.assign({}, d, {
|
|
775
|
+
perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
|
|
776
|
+
total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
|
|
759
777
|
})), d.data.story || d.data.stories) {
|
|
760
|
-
const
|
|
761
|
-
await this.resolveStories(d.data, t, `${
|
|
778
|
+
const p = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
779
|
+
await this.resolveStories(d.data, t, `${p}`);
|
|
762
780
|
}
|
|
763
|
-
return t.version === "published" && e
|
|
764
|
-
} catch (
|
|
765
|
-
if (
|
|
781
|
+
return t.version === "published" && e !== "/cdn/spaces/me" && await n.set(i, d), d.data.cv && t.token && f[t.token] !== d.data.cv && (await this.flushCache(), f[t.token] = d.data.cv), a(d);
|
|
782
|
+
} catch (u) {
|
|
783
|
+
if (u.response && u.status === 429 && (s = typeof s > "u" ? 0 : s + 1, s < this.maxRetries))
|
|
766
784
|
return console.log(
|
|
767
785
|
`Hit rate limit. Retrying in ${this.retriesDelay / 1e3} seconds.`
|
|
768
|
-
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(
|
|
769
|
-
|
|
786
|
+
), await this.helpers.delay(this.retriesDelay), this.cacheResponse(e, t, s).then(a).catch(l);
|
|
787
|
+
l(u);
|
|
770
788
|
}
|
|
771
789
|
});
|
|
772
790
|
}
|
|
@@ -774,36 +792,37 @@ class ue {
|
|
|
774
792
|
return this.client.setFetchOptions(r), this.client[e](t, s);
|
|
775
793
|
}
|
|
776
794
|
cacheVersions() {
|
|
777
|
-
return
|
|
795
|
+
return f;
|
|
778
796
|
}
|
|
779
797
|
cacheVersion() {
|
|
780
|
-
return
|
|
798
|
+
return f[this.accessToken];
|
|
781
799
|
}
|
|
782
800
|
setCacheVersion(e) {
|
|
783
|
-
this.accessToken && (
|
|
801
|
+
this.accessToken && (f[this.accessToken] = e);
|
|
784
802
|
}
|
|
785
803
|
clearCacheVersion() {
|
|
786
|
-
this.accessToken && (
|
|
804
|
+
this.accessToken && (f[this.accessToken] = 0);
|
|
787
805
|
}
|
|
788
806
|
cacheProvider() {
|
|
789
807
|
switch (this.cache.type) {
|
|
790
808
|
case "memory":
|
|
791
809
|
return {
|
|
792
810
|
get(e) {
|
|
793
|
-
return Promise.resolve(
|
|
811
|
+
return Promise.resolve(m[e]);
|
|
794
812
|
},
|
|
795
813
|
getAll() {
|
|
796
|
-
return Promise.resolve(
|
|
814
|
+
return Promise.resolve(m);
|
|
797
815
|
},
|
|
798
816
|
set(e, t) {
|
|
799
|
-
return
|
|
817
|
+
return m[e] = t, Promise.resolve(void 0);
|
|
800
818
|
},
|
|
801
819
|
flush() {
|
|
802
|
-
return
|
|
820
|
+
return m = {}, Promise.resolve(void 0);
|
|
803
821
|
}
|
|
804
822
|
};
|
|
805
823
|
case "custom":
|
|
806
|
-
if (this.cache.custom)
|
|
824
|
+
if (this.cache.custom)
|
|
825
|
+
return this.cache.custom;
|
|
807
826
|
default:
|
|
808
827
|
return {
|
|
809
828
|
get() {
|
|
@@ -825,21 +844,21 @@ class ue {
|
|
|
825
844
|
return await this.cacheProvider().flush(), this.clearCacheVersion(), this;
|
|
826
845
|
}
|
|
827
846
|
}
|
|
828
|
-
const
|
|
829
|
-
const { apiOptions: e } =
|
|
847
|
+
const ge = (o = {}) => {
|
|
848
|
+
const { apiOptions: e } = o;
|
|
830
849
|
if (!e.accessToken) {
|
|
831
850
|
console.error(
|
|
832
851
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
|
833
852
|
);
|
|
834
853
|
return;
|
|
835
854
|
}
|
|
836
|
-
return { storyblokApi: new
|
|
837
|
-
},
|
|
838
|
-
if (typeof
|
|
855
|
+
return { storyblokApi: new de(e) };
|
|
856
|
+
}, fe = (o) => {
|
|
857
|
+
if (typeof o != "object" || typeof o._editable > "u")
|
|
839
858
|
return {};
|
|
840
859
|
try {
|
|
841
860
|
const e = JSON.parse(
|
|
842
|
-
|
|
861
|
+
o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
843
862
|
);
|
|
844
863
|
return e ? {
|
|
845
864
|
"data-blok-c": JSON.stringify(e),
|
|
@@ -849,43 +868,43 @@ const pe = (n = {}) => {
|
|
|
849
868
|
return {};
|
|
850
869
|
}
|
|
851
870
|
};
|
|
852
|
-
let R
|
|
853
|
-
const
|
|
871
|
+
let $, R = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
872
|
+
const me = (o, e, t = {}) => {
|
|
854
873
|
var s;
|
|
855
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u",
|
|
874
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", i = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
856
875
|
"_storyblok"
|
|
857
|
-
) ===
|
|
858
|
-
if (!(!r || !
|
|
859
|
-
if (!
|
|
876
|
+
) === o;
|
|
877
|
+
if (!(!r || !i)) {
|
|
878
|
+
if (!o) {
|
|
860
879
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
861
880
|
return;
|
|
862
881
|
}
|
|
863
882
|
window.storyblokRegisterEvent(() => {
|
|
864
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
|
865
|
-
|
|
883
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (n) => {
|
|
884
|
+
n.action === "input" && n.story.id === o ? e(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
|
|
866
885
|
});
|
|
867
886
|
});
|
|
868
887
|
}
|
|
869
|
-
},
|
|
888
|
+
}, ye = (o = {}) => {
|
|
870
889
|
var e, t;
|
|
871
890
|
const {
|
|
872
891
|
bridge: s,
|
|
873
892
|
accessToken: r,
|
|
874
|
-
use:
|
|
875
|
-
apiOptions:
|
|
876
|
-
richText:
|
|
877
|
-
bridgeUrl:
|
|
878
|
-
} =
|
|
879
|
-
|
|
880
|
-
const
|
|
881
|
-
let
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
}),
|
|
893
|
+
use: i = [],
|
|
894
|
+
apiOptions: n = {},
|
|
895
|
+
richText: a = {},
|
|
896
|
+
bridgeUrl: l
|
|
897
|
+
} = o;
|
|
898
|
+
n.accessToken = n.accessToken || r;
|
|
899
|
+
const h = { bridge: s, apiOptions: n };
|
|
900
|
+
let u = {};
|
|
901
|
+
i.forEach((p) => {
|
|
902
|
+
u = { ...u, ...p(h) };
|
|
903
|
+
}), l && (R = l);
|
|
885
904
|
const d = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
886
|
-
return s !== !1 && d &&
|
|
887
|
-
},
|
|
888
|
-
|
|
905
|
+
return s !== !1 && d && E(R), $ = new b(a.schema), a.resolver && P($, a.resolver), u;
|
|
906
|
+
}, P = (o, e) => {
|
|
907
|
+
o.addNode("blok", (t) => {
|
|
889
908
|
let s = "";
|
|
890
909
|
return t.attrs.body.forEach((r) => {
|
|
891
910
|
s += e(r.component, r);
|
|
@@ -893,25 +912,25 @@ const fe = (n, e, t = {}) => {
|
|
|
893
912
|
html: s
|
|
894
913
|
};
|
|
895
914
|
});
|
|
896
|
-
},
|
|
897
|
-
let s = t ||
|
|
915
|
+
}, pe = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), be = (o, e, t) => {
|
|
916
|
+
let s = t || $;
|
|
898
917
|
if (!s) {
|
|
899
918
|
console.error(
|
|
900
919
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
901
920
|
);
|
|
902
921
|
return;
|
|
903
922
|
}
|
|
904
|
-
return
|
|
905
|
-
},
|
|
923
|
+
return pe(o) ? "" : (e && (s = new b(e.schema), e.resolver && P(s, e.resolver)), s.render(o, {}, !1));
|
|
924
|
+
}, ve = () => E(R);
|
|
906
925
|
export {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
926
|
+
b as RichTextResolver,
|
|
927
|
+
ae as RichTextSchema,
|
|
928
|
+
ge as apiPlugin,
|
|
929
|
+
pe as isRichTextEmpty,
|
|
930
|
+
ve as loadStoryblokBridge,
|
|
931
|
+
me as registerStoryblokBridge,
|
|
932
|
+
be as renderRichText,
|
|
933
|
+
fe as storyblokEditable,
|
|
934
|
+
ye as storyblokInit,
|
|
935
|
+
me as useStoryblokBridge
|
|
917
936
|
};
|