@storyblok/react 2.0.14 → 2.0.16
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-react.js +2 -2
- package/dist/storyblok-react.mjs +494 -379
- package/package.json +6 -6
package/dist/storyblok-react.mjs
CHANGED
|
@@ -5,18 +5,18 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a,
|
|
9
|
-
for (var prop in
|
|
10
|
-
if (__hasOwnProp.call(
|
|
11
|
-
__defNormalProp(a, prop,
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
12
|
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(
|
|
14
|
-
if (__propIsEnum.call(
|
|
15
|
-
__defNormalProp(a, prop,
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
16
|
}
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
|
-
var __spreadProps = (a,
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
var __objRest = (source, exclude) => {
|
|
21
21
|
var target = {};
|
|
22
22
|
for (var prop in source)
|
|
@@ -30,388 +30,491 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
import React, { forwardRef, useState, useEffect } from "react";
|
|
33
|
-
let
|
|
34
|
-
const
|
|
33
|
+
let T = false;
|
|
34
|
+
const R = [], j = (n) => new Promise((e, t) => {
|
|
35
35
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
|
36
36
|
if (window.location === window.parent.location) {
|
|
37
37
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
T ? r() : R.push(r);
|
|
41
41
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
42
42
|
return;
|
|
43
43
|
const s = document.createElement("script");
|
|
44
|
-
s.async = true, s.src =
|
|
45
|
-
|
|
44
|
+
s.async = true, s.src = n, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
|
45
|
+
R.forEach((i) => i()), T = true, e(r);
|
|
46
46
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
47
47
|
});
|
|
48
|
-
var
|
|
49
|
-
function
|
|
50
|
-
return !(
|
|
48
|
+
var P = Object.defineProperty, I = (n, e, t) => e in n ? P(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t, h = (n, e, t) => (I(n, typeof e != "symbol" ? e + "" : e, t), t);
|
|
49
|
+
function _(n) {
|
|
50
|
+
return !(n !== n || n === 1 / 0 || n === -1 / 0);
|
|
51
51
|
}
|
|
52
|
-
function
|
|
53
|
-
if (!
|
|
52
|
+
function S(n, e, t) {
|
|
53
|
+
if (!_(e))
|
|
54
54
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
55
|
-
if (!
|
|
55
|
+
if (!_(t))
|
|
56
56
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
57
57
|
const s = [];
|
|
58
|
-
let r = [],
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
return u !==
|
|
58
|
+
let r = [], i = 0;
|
|
59
|
+
const o = function() {
|
|
60
|
+
i++;
|
|
61
|
+
const a = setTimeout(function() {
|
|
62
|
+
i--, s.length > 0 && o(), r = r.filter(function(u) {
|
|
63
|
+
return u !== a;
|
|
64
64
|
});
|
|
65
|
-
},
|
|
66
|
-
r.indexOf(
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
const
|
|
65
|
+
}, t);
|
|
66
|
+
r.indexOf(a) < 0 && r.push(a);
|
|
67
|
+
const l = s.shift();
|
|
68
|
+
l.resolve(n.apply(l.self, l.args));
|
|
69
|
+
}, c = function(...a) {
|
|
70
|
+
const l = this;
|
|
71
71
|
return new Promise(function(u, d) {
|
|
72
72
|
s.push({
|
|
73
73
|
resolve: u,
|
|
74
74
|
reject: d,
|
|
75
|
-
args:
|
|
76
|
-
self:
|
|
77
|
-
}),
|
|
75
|
+
args: a,
|
|
76
|
+
self: l
|
|
77
|
+
}), i < e && o();
|
|
78
78
|
});
|
|
79
79
|
};
|
|
80
|
-
return
|
|
81
|
-
r.forEach(clearTimeout), r = [], s.forEach(function(
|
|
82
|
-
|
|
80
|
+
return c.abort = function() {
|
|
81
|
+
r.forEach(clearTimeout), r = [], s.forEach(function(a) {
|
|
82
|
+
a.reject(function() {
|
|
83
83
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
84
84
|
});
|
|
85
85
|
}), s.length = 0;
|
|
86
|
-
},
|
|
86
|
+
}, c;
|
|
87
87
|
}
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
for (const s in
|
|
91
|
-
const r =
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
return
|
|
95
|
-
},
|
|
88
|
+
const C = function(n, e) {
|
|
89
|
+
const t = {};
|
|
90
|
+
for (const s in n) {
|
|
91
|
+
const r = n[s];
|
|
92
|
+
e.indexOf(s) > -1 && r !== null && (t[s] = r);
|
|
93
|
+
}
|
|
94
|
+
return t;
|
|
95
|
+
}, O = (n) => n === "email", A = () => ({
|
|
96
96
|
singleTag: "hr"
|
|
97
|
-
}),
|
|
97
|
+
}), N = () => ({
|
|
98
98
|
tag: "blockquote"
|
|
99
|
-
}),
|
|
99
|
+
}), M = () => ({
|
|
100
100
|
tag: "ul"
|
|
101
|
-
}),
|
|
101
|
+
}), L = (n) => ({
|
|
102
102
|
tag: [
|
|
103
103
|
"pre",
|
|
104
104
|
{
|
|
105
105
|
tag: "code",
|
|
106
|
-
attrs:
|
|
106
|
+
attrs: n.attrs
|
|
107
107
|
}
|
|
108
108
|
]
|
|
109
|
-
}),
|
|
109
|
+
}), z = () => ({
|
|
110
110
|
singleTag: "br"
|
|
111
|
-
}),
|
|
112
|
-
tag: `h${
|
|
113
|
-
}),
|
|
111
|
+
}), U = (n) => ({
|
|
112
|
+
tag: `h${n.attrs.level}`
|
|
113
|
+
}), q = (n) => ({
|
|
114
114
|
singleTag: [
|
|
115
115
|
{
|
|
116
116
|
tag: "img",
|
|
117
|
-
attrs:
|
|
117
|
+
attrs: C(n.attrs, ["src", "alt", "title"])
|
|
118
118
|
}
|
|
119
119
|
]
|
|
120
|
-
}),
|
|
120
|
+
}), H = () => ({
|
|
121
121
|
tag: "li"
|
|
122
|
-
}),
|
|
122
|
+
}), B = () => ({
|
|
123
123
|
tag: "ol"
|
|
124
|
-
}),
|
|
124
|
+
}), D = () => ({
|
|
125
125
|
tag: "p"
|
|
126
|
-
}),
|
|
126
|
+
}), F = (n) => ({
|
|
127
|
+
tag: [
|
|
128
|
+
{
|
|
129
|
+
tag: "span",
|
|
130
|
+
attrs: {
|
|
131
|
+
["data-type"]: "emoji",
|
|
132
|
+
["data-name"]: n.attrs.name,
|
|
133
|
+
emoji: n.attrs.emoji
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}), J = () => ({
|
|
127
138
|
tag: "b"
|
|
128
|
-
}),
|
|
139
|
+
}), V = () => ({
|
|
129
140
|
tag: "strike"
|
|
130
|
-
}),
|
|
141
|
+
}), Y = () => ({
|
|
131
142
|
tag: "u"
|
|
132
|
-
}),
|
|
143
|
+
}), K = () => ({
|
|
133
144
|
tag: "strong"
|
|
134
|
-
}),
|
|
145
|
+
}), G = () => ({
|
|
135
146
|
tag: "code"
|
|
136
|
-
}),
|
|
147
|
+
}), Q = () => ({
|
|
137
148
|
tag: "i"
|
|
138
|
-
}),
|
|
139
|
-
const
|
|
140
|
-
|
|
149
|
+
}), W = (n) => {
|
|
150
|
+
const e = __spreadValues({}, n.attrs), { linktype: t = "url" } = n.attrs;
|
|
151
|
+
if (O(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), e.custom) {
|
|
152
|
+
for (const s in e.custom)
|
|
153
|
+
e[s] = e.custom[s];
|
|
154
|
+
delete e.custom;
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
141
157
|
tag: [
|
|
142
158
|
{
|
|
143
159
|
tag: "a",
|
|
144
|
-
attrs:
|
|
160
|
+
attrs: e
|
|
145
161
|
}
|
|
146
162
|
]
|
|
147
163
|
};
|
|
148
|
-
},
|
|
164
|
+
}, X = (n) => ({
|
|
165
|
+
tag: [
|
|
166
|
+
{
|
|
167
|
+
tag: "span",
|
|
168
|
+
attrs: n.attrs
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
}), Z = () => ({
|
|
172
|
+
tag: "sub"
|
|
173
|
+
}), ee = () => ({
|
|
174
|
+
tag: "sup"
|
|
175
|
+
}), te = (n) => ({
|
|
176
|
+
tag: [
|
|
177
|
+
{
|
|
178
|
+
tag: "span",
|
|
179
|
+
attrs: n.attrs
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
}), se = (n) => ({
|
|
149
183
|
tag: [
|
|
150
184
|
{
|
|
151
185
|
tag: "span",
|
|
152
|
-
attrs:
|
|
186
|
+
attrs: {
|
|
187
|
+
style: `background-color:${n.attrs.color};`
|
|
188
|
+
}
|
|
153
189
|
}
|
|
154
190
|
]
|
|
155
|
-
}),
|
|
191
|
+
}), re = (n) => ({
|
|
192
|
+
tag: [
|
|
193
|
+
{
|
|
194
|
+
tag: "span",
|
|
195
|
+
attrs: {
|
|
196
|
+
style: `background-color:${n.attrs.color}`
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
}), ie = {
|
|
156
201
|
nodes: {
|
|
157
|
-
horizontal_rule:
|
|
158
|
-
blockquote:
|
|
159
|
-
bullet_list:
|
|
160
|
-
code_block:
|
|
161
|
-
hard_break:
|
|
162
|
-
heading:
|
|
163
|
-
image:
|
|
164
|
-
list_item:
|
|
165
|
-
ordered_list:
|
|
166
|
-
paragraph:
|
|
202
|
+
horizontal_rule: A,
|
|
203
|
+
blockquote: N,
|
|
204
|
+
bullet_list: M,
|
|
205
|
+
code_block: L,
|
|
206
|
+
hard_break: z,
|
|
207
|
+
heading: U,
|
|
208
|
+
image: q,
|
|
209
|
+
list_item: H,
|
|
210
|
+
ordered_list: B,
|
|
211
|
+
paragraph: D,
|
|
212
|
+
emoji: F
|
|
167
213
|
},
|
|
168
214
|
marks: {
|
|
169
|
-
bold:
|
|
170
|
-
strike:
|
|
171
|
-
underline:
|
|
172
|
-
strong:
|
|
173
|
-
code:
|
|
174
|
-
italic:
|
|
175
|
-
link:
|
|
176
|
-
styled:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
215
|
+
bold: J,
|
|
216
|
+
strike: V,
|
|
217
|
+
underline: Y,
|
|
218
|
+
strong: K,
|
|
219
|
+
code: G,
|
|
220
|
+
italic: Q,
|
|
221
|
+
link: W,
|
|
222
|
+
styled: X,
|
|
223
|
+
subscript: Z,
|
|
224
|
+
superscript: ee,
|
|
225
|
+
anchor: te,
|
|
226
|
+
highlight: se,
|
|
227
|
+
textStyle: re
|
|
228
|
+
}
|
|
229
|
+
}, oe = function(n) {
|
|
230
|
+
const e = {
|
|
180
231
|
"&": "&",
|
|
181
232
|
"<": "<",
|
|
182
233
|
">": ">",
|
|
183
234
|
'"': """,
|
|
184
235
|
"'": "'"
|
|
185
|
-
},
|
|
186
|
-
return
|
|
236
|
+
}, t = /[&<>"']/g, s = RegExp(t.source);
|
|
237
|
+
return n && s.test(n) ? n.replace(t, (r) => e[r]) : n;
|
|
187
238
|
};
|
|
188
|
-
class
|
|
189
|
-
constructor(
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
addNode(
|
|
193
|
-
this.nodes[
|
|
194
|
-
}
|
|
195
|
-
addMark(
|
|
196
|
-
this.marks[
|
|
197
|
-
}
|
|
198
|
-
render(t) {
|
|
199
|
-
if (
|
|
200
|
-
let
|
|
201
|
-
return
|
|
202
|
-
|
|
203
|
-
}),
|
|
239
|
+
class y {
|
|
240
|
+
constructor(e) {
|
|
241
|
+
h(this, "marks"), h(this, "nodes"), e || (e = ie), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
242
|
+
}
|
|
243
|
+
addNode(e, t) {
|
|
244
|
+
this.nodes[e] = t;
|
|
245
|
+
}
|
|
246
|
+
addMark(e, t) {
|
|
247
|
+
this.marks[e] = t;
|
|
248
|
+
}
|
|
249
|
+
render(e, t = { optimizeImages: false }) {
|
|
250
|
+
if (e && e.content && Array.isArray(e.content)) {
|
|
251
|
+
let s = "";
|
|
252
|
+
return e.content.forEach((r) => {
|
|
253
|
+
s += this.renderNode(r);
|
|
254
|
+
}), t.optimizeImages ? this.optimizeImages(s, t.optimizeImages) : s;
|
|
204
255
|
}
|
|
205
256
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
206
257
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
t.
|
|
210
|
-
|
|
211
|
-
|
|
258
|
+
optimizeImages(e, t) {
|
|
259
|
+
let s = 0, r = 0, i = "", o = "";
|
|
260
|
+
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 && (o += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (o += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (o += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (o += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (o += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (o += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (o += `:rotate(${t.filters.rotate})`), o.length > 0 && (o = "/filters" + o))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
|
|
261
|
+
const c = s > 0 || r > 0 || o.length > 0 ? `${s}x${r}${o}` : "";
|
|
262
|
+
return e = e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g, `a.storyblok.com/f/$1/$2.$3/m/${c}`), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
|
263
|
+
var l, u;
|
|
264
|
+
const d = a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);
|
|
265
|
+
if (d && d.length > 0) {
|
|
266
|
+
const g = {
|
|
267
|
+
srcset: (l = t.srcset) == null ? void 0 : l.map((p) => {
|
|
268
|
+
if (typeof p == "number")
|
|
269
|
+
return `//${d}/m/${p}x0${o} ${p}w`;
|
|
270
|
+
if (typeof p == "object" && p.length === 2) {
|
|
271
|
+
let k = 0, $ = 0;
|
|
272
|
+
return typeof p[0] == "number" && (k = p[0]), typeof p[1] == "number" && ($ = p[1]), `//${d}/m/${k}x${$}${o} ${k}w`;
|
|
273
|
+
}
|
|
274
|
+
}).join(", "),
|
|
275
|
+
sizes: (u = t.sizes) == null ? void 0 : u.map((p) => p).join(", ")
|
|
276
|
+
};
|
|
277
|
+
let b = "";
|
|
278
|
+
return g.srcset && (b += `srcset="${g.srcset}" `), g.sizes && (b += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${b.trim()}`);
|
|
279
|
+
}
|
|
280
|
+
return a;
|
|
281
|
+
})), e;
|
|
282
|
+
}
|
|
283
|
+
renderNode(e) {
|
|
284
|
+
const t = [];
|
|
285
|
+
e.marks && e.marks.forEach((r) => {
|
|
286
|
+
const i = this.getMatchingMark(r);
|
|
287
|
+
i && t.push(this.renderOpeningTag(i.tag));
|
|
212
288
|
});
|
|
213
|
-
const s = this.getMatchingNode(
|
|
214
|
-
return s && s.tag &&
|
|
215
|
-
|
|
216
|
-
}) :
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
}),
|
|
220
|
-
}
|
|
221
|
-
renderTag(
|
|
222
|
-
return
|
|
289
|
+
const s = this.getMatchingNode(e);
|
|
290
|
+
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
291
|
+
t.push(this.renderNode(r));
|
|
292
|
+
}) : e.text ? t.push(oe(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) => {
|
|
293
|
+
const i = this.getMatchingMark(r);
|
|
294
|
+
i && t.push(this.renderClosingTag(i.tag));
|
|
295
|
+
}), t.join("");
|
|
296
|
+
}
|
|
297
|
+
renderTag(e, t) {
|
|
298
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((s) => {
|
|
223
299
|
if (s.constructor === String)
|
|
224
|
-
return `<${s}${
|
|
300
|
+
return `<${s}${t}>`;
|
|
225
301
|
{
|
|
226
302
|
let r = `<${s.tag}`;
|
|
227
303
|
if (s.attrs)
|
|
228
|
-
for (const
|
|
229
|
-
const
|
|
230
|
-
|
|
304
|
+
for (const i in s.attrs) {
|
|
305
|
+
const o = s.attrs[i];
|
|
306
|
+
o !== null && (r += ` ${i}="${o}"`);
|
|
231
307
|
}
|
|
232
|
-
return `${r}${
|
|
308
|
+
return `${r}${t}>`;
|
|
233
309
|
}
|
|
234
310
|
}).join("");
|
|
235
311
|
}
|
|
236
|
-
renderOpeningTag(
|
|
237
|
-
return this.renderTag(
|
|
312
|
+
renderOpeningTag(e) {
|
|
313
|
+
return this.renderTag(e, "");
|
|
238
314
|
}
|
|
239
|
-
renderClosingTag(
|
|
240
|
-
return
|
|
315
|
+
renderClosingTag(e) {
|
|
316
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
|
|
241
317
|
}
|
|
242
|
-
getMatchingNode(
|
|
243
|
-
const
|
|
244
|
-
if (typeof
|
|
245
|
-
return e
|
|
318
|
+
getMatchingNode(e) {
|
|
319
|
+
const t = this.nodes[e.type];
|
|
320
|
+
if (typeof t == "function")
|
|
321
|
+
return t(e);
|
|
246
322
|
}
|
|
247
|
-
getMatchingMark(
|
|
248
|
-
const
|
|
249
|
-
if (typeof
|
|
250
|
-
return e
|
|
323
|
+
getMatchingMark(e) {
|
|
324
|
+
const t = this.marks[e.type];
|
|
325
|
+
if (typeof t == "function")
|
|
326
|
+
return t(e);
|
|
327
|
+
}
|
|
328
|
+
renderEmoji(e) {
|
|
329
|
+
if (e.attrs.emoji)
|
|
330
|
+
return e.attrs.emoji;
|
|
331
|
+
const t = [
|
|
332
|
+
{
|
|
333
|
+
tag: "img",
|
|
334
|
+
attrs: {
|
|
335
|
+
src: e.attrs.fallbackImage,
|
|
336
|
+
draggable: "false",
|
|
337
|
+
loading: "lazy",
|
|
338
|
+
align: "absmiddle"
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
];
|
|
342
|
+
return this.renderTag(t, " /");
|
|
251
343
|
}
|
|
252
344
|
}
|
|
253
|
-
class
|
|
345
|
+
class v {
|
|
254
346
|
constructor() {
|
|
255
|
-
|
|
256
|
-
per_page:
|
|
347
|
+
h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25, s = 1) => __spreadProps(__spreadValues({}, e), {
|
|
348
|
+
per_page: t,
|
|
257
349
|
page: s
|
|
258
|
-
})),
|
|
259
|
-
const s = Math.abs(
|
|
260
|
-
return this.arrayFrom(s, (
|
|
261
|
-
}),
|
|
350
|
+
})), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
|
|
351
|
+
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
|
352
|
+
return this.arrayFrom(s, (i, o) => o * r + e);
|
|
353
|
+
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []));
|
|
262
354
|
}
|
|
263
|
-
stringify(
|
|
355
|
+
stringify(e, t, s) {
|
|
264
356
|
const r = [];
|
|
265
|
-
for (const
|
|
266
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
357
|
+
for (const i in e) {
|
|
358
|
+
if (!Object.prototype.hasOwnProperty.call(e, i))
|
|
267
359
|
continue;
|
|
268
|
-
const
|
|
269
|
-
let
|
|
270
|
-
typeof
|
|
360
|
+
const o = e[i], c = s ? "" : encodeURIComponent(i);
|
|
361
|
+
let a;
|
|
362
|
+
typeof o == "object" ? a = this.stringify(o, t ? t + encodeURIComponent("[" + c + "]") : c, Array.isArray(o)) : a = (t ? t + encodeURIComponent("[" + c + "]") : c) + "=" + encodeURIComponent(o), r.push(a);
|
|
271
363
|
}
|
|
272
364
|
return r.join("&");
|
|
273
365
|
}
|
|
366
|
+
getRegionURL(e) {
|
|
367
|
+
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn";
|
|
368
|
+
switch (e) {
|
|
369
|
+
case "us":
|
|
370
|
+
return s;
|
|
371
|
+
case "cn":
|
|
372
|
+
return r;
|
|
373
|
+
default:
|
|
374
|
+
return t;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
274
377
|
}
|
|
275
|
-
class
|
|
276
|
-
constructor(
|
|
277
|
-
|
|
378
|
+
class ne {
|
|
379
|
+
constructor(e) {
|
|
380
|
+
h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), 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 = false, this.url = "", this.parameters = {};
|
|
278
381
|
}
|
|
279
|
-
get(
|
|
280
|
-
return this.url =
|
|
382
|
+
get(e, t) {
|
|
383
|
+
return this.url = e, this.parameters = t, this._methodHandler("get");
|
|
281
384
|
}
|
|
282
|
-
post(
|
|
283
|
-
return this.url =
|
|
385
|
+
post(e, t) {
|
|
386
|
+
return this.url = e, this.parameters = t, this._methodHandler("post");
|
|
284
387
|
}
|
|
285
|
-
put(
|
|
286
|
-
return this.url =
|
|
388
|
+
put(e, t) {
|
|
389
|
+
return this.url = e, this.parameters = t, this._methodHandler("put");
|
|
287
390
|
}
|
|
288
|
-
delete(
|
|
289
|
-
return this.url =
|
|
391
|
+
delete(e, t) {
|
|
392
|
+
return this.url = e, this.parameters = t, this._methodHandler("delete");
|
|
290
393
|
}
|
|
291
|
-
async _responseHandler(
|
|
292
|
-
const
|
|
394
|
+
async _responseHandler(e) {
|
|
395
|
+
const t = /* @__PURE__ */ new Map(), s = {
|
|
293
396
|
data: {},
|
|
294
397
|
headers: {},
|
|
295
398
|
status: 0,
|
|
296
399
|
statusText: ""
|
|
297
400
|
};
|
|
298
|
-
|
|
401
|
+
e.status !== 204 && await e.json().then((r) => {
|
|
299
402
|
s.data = r;
|
|
300
403
|
});
|
|
301
|
-
for (const r of
|
|
302
|
-
|
|
303
|
-
return s.headers = __spreadValues({},
|
|
304
|
-
}
|
|
305
|
-
async _methodHandler(
|
|
306
|
-
let
|
|
307
|
-
if (
|
|
308
|
-
const
|
|
309
|
-
|
|
404
|
+
for (const [r, i] of e.headers.entries())
|
|
405
|
+
t.set(r, i);
|
|
406
|
+
return s.headers = __spreadValues({}, t), s.status = e.status, s.statusText = e.statusText, s;
|
|
407
|
+
}
|
|
408
|
+
async _methodHandler(e) {
|
|
409
|
+
let t = `${this.baseURL}${this.url}`, s = null;
|
|
410
|
+
if (e === "get") {
|
|
411
|
+
const a = new v();
|
|
412
|
+
t = `${this.baseURL}${this.url}?${a.stringify(this.parameters)}`;
|
|
310
413
|
} else
|
|
311
414
|
s = JSON.stringify(this.parameters);
|
|
312
|
-
const r = new URL(
|
|
313
|
-
let
|
|
314
|
-
this.timeout && (
|
|
415
|
+
const r = new URL(t), i = new AbortController(), { signal: o } = i;
|
|
416
|
+
let c;
|
|
417
|
+
this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
|
|
315
418
|
try {
|
|
316
|
-
const
|
|
317
|
-
method:
|
|
419
|
+
const a = await this.fetch(`${r}`, {
|
|
420
|
+
method: e,
|
|
318
421
|
headers: this.headers,
|
|
319
422
|
body: s,
|
|
320
|
-
signal:
|
|
423
|
+
signal: o
|
|
321
424
|
});
|
|
322
|
-
this.timeout && clearTimeout(
|
|
323
|
-
const
|
|
324
|
-
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(
|
|
325
|
-
} catch (
|
|
425
|
+
this.timeout && clearTimeout(c);
|
|
426
|
+
const l = await this._responseHandler(a);
|
|
427
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
|
|
428
|
+
} catch (a) {
|
|
326
429
|
return {
|
|
327
|
-
message:
|
|
430
|
+
message: a
|
|
328
431
|
};
|
|
329
432
|
}
|
|
330
433
|
}
|
|
331
434
|
eject() {
|
|
332
435
|
this.ejectInterceptor = true;
|
|
333
436
|
}
|
|
334
|
-
_statusHandler(
|
|
335
|
-
const
|
|
437
|
+
_statusHandler(e) {
|
|
438
|
+
const t = /20[0-6]/g;
|
|
336
439
|
return new Promise((s, r) => {
|
|
337
|
-
if (
|
|
338
|
-
return s(
|
|
339
|
-
const
|
|
340
|
-
message: new Error(
|
|
341
|
-
status:
|
|
342
|
-
response:
|
|
440
|
+
if (t.test(`${e.status}`))
|
|
441
|
+
return s(e);
|
|
442
|
+
const i = {
|
|
443
|
+
message: new Error(e.statusText),
|
|
444
|
+
status: e.status,
|
|
445
|
+
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
|
343
446
|
};
|
|
344
|
-
r(
|
|
447
|
+
r(i);
|
|
345
448
|
});
|
|
346
449
|
}
|
|
347
450
|
}
|
|
348
|
-
let
|
|
349
|
-
const
|
|
350
|
-
class
|
|
351
|
-
constructor(
|
|
352
|
-
if (
|
|
353
|
-
const
|
|
354
|
-
|
|
451
|
+
let m = {};
|
|
452
|
+
const f = {};
|
|
453
|
+
class ae {
|
|
454
|
+
constructor(e, t) {
|
|
455
|
+
if (h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), !t) {
|
|
456
|
+
const i = new v().getRegionURL, o = e.https === false ? "http" : "https";
|
|
457
|
+
e.oauthToken ? t = `${o}://${i(e.region)}/v1` : t = `${o}://${i(e.region)}/v2`;
|
|
355
458
|
}
|
|
356
459
|
const s = new Headers();
|
|
357
|
-
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((
|
|
358
|
-
|
|
460
|
+
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((i, o) => {
|
|
461
|
+
e.headers && e.headers[o] && s.set(o, e.headers[o]);
|
|
359
462
|
});
|
|
360
463
|
let r = 5;
|
|
361
|
-
|
|
362
|
-
baseURL:
|
|
363
|
-
timeout:
|
|
464
|
+
e.oauthToken && (s.set("Authorization", e.oauthToken), r = 3), e.rateLimit && (r = e.rateLimit), e.richTextSchema ? this.richTextResolver = new y(e.richTextSchema) : this.richTextResolver = new y(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries, this.throttle = S(this.throttledRequest, r, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new v(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || true, this.client = new ne({
|
|
465
|
+
baseURL: t,
|
|
466
|
+
timeout: e.timeout || 0,
|
|
364
467
|
headers: s,
|
|
365
|
-
responseInterceptor:
|
|
366
|
-
fetch:
|
|
468
|
+
responseInterceptor: e.responseInterceptor,
|
|
469
|
+
fetch: e.fetch
|
|
367
470
|
});
|
|
368
471
|
}
|
|
369
|
-
setComponentResolver(
|
|
370
|
-
this.richTextResolver.addNode("blok", (
|
|
472
|
+
setComponentResolver(e) {
|
|
473
|
+
this.richTextResolver.addNode("blok", (t) => {
|
|
371
474
|
let s = "";
|
|
372
|
-
return
|
|
373
|
-
s +=
|
|
475
|
+
return t.attrs.body.forEach((r) => {
|
|
476
|
+
s += e(r.component, r);
|
|
374
477
|
}), {
|
|
375
478
|
html: s
|
|
376
479
|
};
|
|
377
480
|
});
|
|
378
481
|
}
|
|
379
|
-
parseParams(
|
|
380
|
-
return
|
|
482
|
+
parseParams(e) {
|
|
483
|
+
return e.version || (e.version = "published"), 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(",")), e;
|
|
381
484
|
}
|
|
382
|
-
factoryParamOptions(
|
|
383
|
-
return this.helpers.isCDNUrl(
|
|
485
|
+
factoryParamOptions(e, t) {
|
|
486
|
+
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
384
487
|
}
|
|
385
|
-
makeRequest(
|
|
386
|
-
const
|
|
387
|
-
return this.cacheResponse(
|
|
488
|
+
makeRequest(e, t, s, r) {
|
|
489
|
+
const i = this.factoryParamOptions(e, this.helpers.getOptionsPage(t, s, r));
|
|
490
|
+
return this.cacheResponse(e, i);
|
|
388
491
|
}
|
|
389
|
-
get(
|
|
390
|
-
|
|
391
|
-
const s = `/${
|
|
492
|
+
get(e, t) {
|
|
493
|
+
t || (t = {});
|
|
494
|
+
const s = `/${e}`, r = this.factoryParamOptions(s, t);
|
|
392
495
|
return this.cacheResponse(s, r);
|
|
393
496
|
}
|
|
394
|
-
async getAll(
|
|
395
|
-
const r = (
|
|
396
|
-
return this.helpers.flatMap([
|
|
497
|
+
async getAll(e, t, s) {
|
|
498
|
+
const r = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`, o = i.split("/"), c = s || o[o.length - 1], a = 1, l = await this.makeRequest(i, t, r, a), u = l.total ? Math.ceil(l.total / r) : 1, d = await this.helpers.asyncMap(this.helpers.range(a, u), (g) => this.makeRequest(i, t, r, g + 1));
|
|
499
|
+
return this.helpers.flatMap([l, ...d], (g) => Object.values(g.data[c]));
|
|
397
500
|
}
|
|
398
|
-
post(
|
|
399
|
-
const s = `/${
|
|
400
|
-
return Promise.resolve(this.throttle("post", s,
|
|
501
|
+
post(e, t) {
|
|
502
|
+
const s = `/${e}`;
|
|
503
|
+
return Promise.resolve(this.throttle("post", s, t));
|
|
401
504
|
}
|
|
402
|
-
put(
|
|
403
|
-
const s = `/${
|
|
404
|
-
return Promise.resolve(this.throttle("put", s,
|
|
505
|
+
put(e, t) {
|
|
506
|
+
const s = `/${e}`;
|
|
507
|
+
return Promise.resolve(this.throttle("put", s, t));
|
|
405
508
|
}
|
|
406
|
-
delete(
|
|
407
|
-
const s = `/${
|
|
408
|
-
return Promise.resolve(this.throttle("delete", s,
|
|
509
|
+
delete(e, t) {
|
|
510
|
+
const s = `/${e}`;
|
|
511
|
+
return Promise.resolve(this.throttle("delete", s, t));
|
|
409
512
|
}
|
|
410
|
-
getStories(
|
|
411
|
-
return this.get("cdn/stories",
|
|
513
|
+
getStories(e) {
|
|
514
|
+
return this.get("cdn/stories", e);
|
|
412
515
|
}
|
|
413
|
-
getStory(
|
|
414
|
-
return this.get(`cdn/stories/${
|
|
516
|
+
getStory(e, t) {
|
|
517
|
+
return this.get(`cdn/stories/${e}`, t);
|
|
415
518
|
}
|
|
416
519
|
getToken() {
|
|
417
520
|
return this.accessToken;
|
|
@@ -419,150 +522,160 @@ class W {
|
|
|
419
522
|
ejectInterceptor() {
|
|
420
523
|
this.client.eject();
|
|
421
524
|
}
|
|
422
|
-
_cleanCopy(
|
|
423
|
-
return JSON.parse(JSON.stringify(
|
|
424
|
-
}
|
|
425
|
-
_insertLinks(t,
|
|
426
|
-
const
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
_insertRelations(t,
|
|
430
|
-
if (s.indexOf(`${
|
|
431
|
-
if (typeof t
|
|
432
|
-
this.relations[
|
|
433
|
-
else if (t
|
|
434
|
-
const
|
|
435
|
-
t
|
|
436
|
-
this.relations[
|
|
437
|
-
}), t
|
|
525
|
+
_cleanCopy(e) {
|
|
526
|
+
return JSON.parse(JSON.stringify(e));
|
|
527
|
+
}
|
|
528
|
+
_insertLinks(e, t, s) {
|
|
529
|
+
const r = e[t];
|
|
530
|
+
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]));
|
|
531
|
+
}
|
|
532
|
+
_insertRelations(e, t, s, r) {
|
|
533
|
+
if (s.indexOf(`${e.component}.${t}`) > -1) {
|
|
534
|
+
if (typeof e[t] == "string")
|
|
535
|
+
this.relations[r][e[t]] && (e[t] = this._cleanCopy(this.relations[r][e[t]]));
|
|
536
|
+
else if (e[t] && e[t].constructor === Array) {
|
|
537
|
+
const i = [];
|
|
538
|
+
e[t].forEach((o) => {
|
|
539
|
+
this.relations[r][o] && i.push(this._cleanCopy(this.relations[r][o]));
|
|
540
|
+
}), e[t] = i;
|
|
438
541
|
}
|
|
439
542
|
}
|
|
440
543
|
}
|
|
441
|
-
iterateTree(t,
|
|
442
|
-
const
|
|
443
|
-
if (
|
|
444
|
-
if (
|
|
445
|
-
for (let
|
|
446
|
-
|
|
447
|
-
else if (
|
|
448
|
-
if (
|
|
544
|
+
iterateTree(e, t, s) {
|
|
545
|
+
const r = (i) => {
|
|
546
|
+
if (i != null) {
|
|
547
|
+
if (i.constructor === Array)
|
|
548
|
+
for (let o = 0; o < i.length; o++)
|
|
549
|
+
r(i[o]);
|
|
550
|
+
else if (i.constructor === Object) {
|
|
551
|
+
if (i._stopResolving)
|
|
449
552
|
return;
|
|
450
|
-
for (const
|
|
451
|
-
(
|
|
553
|
+
for (const o in i)
|
|
554
|
+
(i.component && i._uid || i.type === "link") && (this._insertRelations(i, o, t, s), this._insertLinks(i, o, s)), r(i[o]);
|
|
452
555
|
}
|
|
453
556
|
}
|
|
454
557
|
};
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
async resolveLinks(t,
|
|
458
|
-
let
|
|
459
|
-
if (
|
|
460
|
-
const
|
|
461
|
-
for (let a = 0; a <
|
|
462
|
-
const
|
|
463
|
-
|
|
558
|
+
r(e.content);
|
|
559
|
+
}
|
|
560
|
+
async resolveLinks(e, t, s) {
|
|
561
|
+
let r = [];
|
|
562
|
+
if (e.link_uuids) {
|
|
563
|
+
const i = e.link_uuids.length, o = [], c = 50;
|
|
564
|
+
for (let a = 0; a < i; a += c) {
|
|
565
|
+
const l = Math.min(i, a + c);
|
|
566
|
+
o.push(e.link_uuids.slice(a, l));
|
|
464
567
|
}
|
|
465
|
-
for (let a = 0; a <
|
|
568
|
+
for (let a = 0; a < o.length; a++)
|
|
466
569
|
(await this.getStories({
|
|
467
|
-
per_page:
|
|
468
|
-
language:
|
|
469
|
-
version:
|
|
470
|
-
by_uuids:
|
|
471
|
-
})).data.stories.forEach((
|
|
472
|
-
|
|
570
|
+
per_page: c,
|
|
571
|
+
language: t.language,
|
|
572
|
+
version: t.version,
|
|
573
|
+
by_uuids: o[a].join(",")
|
|
574
|
+
})).data.stories.forEach((l) => {
|
|
575
|
+
r.push(l);
|
|
473
576
|
});
|
|
474
577
|
} else
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
this.links[
|
|
578
|
+
r = e.links;
|
|
579
|
+
r.forEach((i) => {
|
|
580
|
+
this.links[s][i.uuid] = __spreadProps(__spreadValues({}, i), {
|
|
581
|
+
_stopResolving: true
|
|
582
|
+
});
|
|
478
583
|
});
|
|
479
584
|
}
|
|
480
|
-
async resolveRelations(t,
|
|
481
|
-
let
|
|
482
|
-
if (
|
|
483
|
-
const
|
|
484
|
-
for (let a = 0; a <
|
|
485
|
-
const
|
|
486
|
-
|
|
585
|
+
async resolveRelations(e, t, s) {
|
|
586
|
+
let r = [];
|
|
587
|
+
if (e.rel_uuids) {
|
|
588
|
+
const i = e.rel_uuids.length, o = [], c = 50;
|
|
589
|
+
for (let a = 0; a < i; a += c) {
|
|
590
|
+
const l = Math.min(i, a + c);
|
|
591
|
+
o.push(e.rel_uuids.slice(a, l));
|
|
487
592
|
}
|
|
488
|
-
for (let a = 0; a <
|
|
593
|
+
for (let a = 0; a < o.length; a++)
|
|
489
594
|
(await this.getStories({
|
|
490
|
-
per_page:
|
|
491
|
-
language:
|
|
492
|
-
version:
|
|
493
|
-
by_uuids:
|
|
494
|
-
})).data.stories.forEach((
|
|
495
|
-
|
|
595
|
+
per_page: c,
|
|
596
|
+
language: t.language,
|
|
597
|
+
version: t.version,
|
|
598
|
+
by_uuids: o[a].join(",")
|
|
599
|
+
})).data.stories.forEach((l) => {
|
|
600
|
+
r.push(l);
|
|
496
601
|
});
|
|
497
602
|
} else
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
this.relations[
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
async resolveStories(t, e) {
|
|
504
|
-
var s, r;
|
|
505
|
-
let n = [];
|
|
506
|
-
if (typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (n = e.resolve_relations.split(",")), await this.resolveRelations(t, e)), e.resolve_links && ["1", "story", "url"].indexOf(e.resolve_links) > -1 && ((s = t.links) != null && s.length || (r = t.link_uuids) != null && r.length) && await this.resolveLinks(t, e), this.resolveNestedRelations)
|
|
507
|
-
for (const i in this.relations)
|
|
508
|
-
this.iterateTree(this.relations[i], n);
|
|
509
|
-
t.story ? this.iterateTree(t.story, n) : t.stories.forEach((i) => {
|
|
510
|
-
this.iterateTree(i, n);
|
|
603
|
+
r = e.rels;
|
|
604
|
+
r && r.length > 0 && r.forEach((i) => {
|
|
605
|
+
this.relations[s][i.uuid] = __spreadProps(__spreadValues({}, i), {
|
|
606
|
+
_stopResolving: true
|
|
607
|
+
});
|
|
511
608
|
});
|
|
512
609
|
}
|
|
513
|
-
async
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
610
|
+
async resolveStories(e, t, s) {
|
|
611
|
+
var r, i;
|
|
612
|
+
let o = [];
|
|
613
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
|
614
|
+
for (const c in this.relations[s])
|
|
615
|
+
this.iterateTree(this.relations[s][c], o, s);
|
|
616
|
+
e.story ? this.iterateTree(e.story, o, s) : e.stories.forEach((c) => {
|
|
617
|
+
this.iterateTree(c, o, s);
|
|
618
|
+
}), delete this.links[s], delete this.relations[s];
|
|
619
|
+
}
|
|
620
|
+
async cacheResponse(e, t, s) {
|
|
621
|
+
const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
|
|
622
|
+
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
623
|
+
const o = await i.get(r);
|
|
624
|
+
if (o)
|
|
625
|
+
return Promise.resolve(o);
|
|
519
626
|
}
|
|
520
|
-
return new Promise((
|
|
627
|
+
return new Promise((o, c) => {
|
|
521
628
|
try {
|
|
522
629
|
(async () => {
|
|
523
|
-
var
|
|
630
|
+
var a;
|
|
524
631
|
try {
|
|
525
|
-
const
|
|
526
|
-
let u = { data:
|
|
527
|
-
|
|
528
|
-
perPage:
|
|
529
|
-
total:
|
|
530
|
-
})),
|
|
531
|
-
|
|
532
|
-
|
|
632
|
+
const l = await this.throttle("get", e, t);
|
|
633
|
+
let u = { data: l.data, headers: l.headers };
|
|
634
|
+
if ((a = l.headers) != null && a["per-page"] && (u = Object.assign({}, u, {
|
|
635
|
+
perPage: l.headers["per-page"] ? parseInt(l.headers["per-page"]) : 0,
|
|
636
|
+
total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
|
|
637
|
+
})), l.status != 200)
|
|
638
|
+
return c(l);
|
|
639
|
+
if (u.data.story || u.data.stories) {
|
|
640
|
+
const d = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
641
|
+
await this.resolveStories(u.data, t, `${d}`);
|
|
642
|
+
}
|
|
643
|
+
return t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && t.token && (t.version == "draft" && f[t.token] != u.data.cv && await this.flushCache(), f[t.token] = u.data.cv), o(u);
|
|
644
|
+
} catch (l) {
|
|
645
|
+
return c(l);
|
|
533
646
|
}
|
|
534
647
|
})();
|
|
535
648
|
} catch {
|
|
536
649
|
}
|
|
537
650
|
});
|
|
538
651
|
}
|
|
539
|
-
throttledRequest(
|
|
540
|
-
return this.client[
|
|
652
|
+
throttledRequest(e, t, s) {
|
|
653
|
+
return this.client[e](t, s);
|
|
541
654
|
}
|
|
542
655
|
cacheVersions() {
|
|
543
|
-
return
|
|
656
|
+
return f;
|
|
544
657
|
}
|
|
545
658
|
cacheVersion() {
|
|
546
|
-
return
|
|
659
|
+
return f[this.accessToken];
|
|
547
660
|
}
|
|
548
|
-
setCacheVersion(
|
|
549
|
-
this.accessToken && (
|
|
661
|
+
setCacheVersion(e) {
|
|
662
|
+
this.accessToken && (f[this.accessToken] = e);
|
|
550
663
|
}
|
|
551
664
|
cacheProvider() {
|
|
552
665
|
switch (this.cache.type) {
|
|
553
666
|
case "memory":
|
|
554
667
|
return {
|
|
555
|
-
get(
|
|
556
|
-
return Promise.resolve(
|
|
668
|
+
get(e) {
|
|
669
|
+
return Promise.resolve(m[e]);
|
|
557
670
|
},
|
|
558
671
|
getAll() {
|
|
559
|
-
return Promise.resolve(
|
|
672
|
+
return Promise.resolve(m);
|
|
560
673
|
},
|
|
561
|
-
set(
|
|
562
|
-
return
|
|
674
|
+
set(e, t) {
|
|
675
|
+
return m[e] = t, Promise.resolve(void 0);
|
|
563
676
|
},
|
|
564
677
|
flush() {
|
|
565
|
-
return
|
|
678
|
+
return m = {}, Promise.resolve(void 0);
|
|
566
679
|
}
|
|
567
680
|
};
|
|
568
681
|
case "custom":
|
|
@@ -589,68 +702,70 @@ class W {
|
|
|
589
702
|
return await this.cacheProvider().flush(), this;
|
|
590
703
|
}
|
|
591
704
|
}
|
|
592
|
-
const
|
|
593
|
-
const { apiOptions:
|
|
594
|
-
if (!
|
|
705
|
+
const le = (n = {}) => {
|
|
706
|
+
const { apiOptions: e } = n;
|
|
707
|
+
if (!e.accessToken) {
|
|
595
708
|
console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");
|
|
596
709
|
return;
|
|
597
710
|
}
|
|
598
|
-
return { storyblokApi: new
|
|
599
|
-
},
|
|
600
|
-
if (typeof
|
|
711
|
+
return { storyblokApi: new ae(e) };
|
|
712
|
+
}, ce = (n) => {
|
|
713
|
+
if (typeof n != "object" || typeof n._editable > "u")
|
|
601
714
|
return {};
|
|
602
|
-
const
|
|
715
|
+
const e = JSON.parse(n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
|
|
603
716
|
return {
|
|
604
|
-
"data-blok-c": JSON.stringify(
|
|
605
|
-
"data-blok-uid":
|
|
717
|
+
"data-blok-c": JSON.stringify(e),
|
|
718
|
+
"data-blok-uid": e.id + "-" + e.uid
|
|
606
719
|
};
|
|
607
720
|
};
|
|
608
|
-
let
|
|
609
|
-
const
|
|
610
|
-
|
|
611
|
-
|
|
721
|
+
let w;
|
|
722
|
+
const x = "https://app.storyblok.com/f/storyblok-v2-latest.js", he = (n, e, t = {}) => {
|
|
723
|
+
var c;
|
|
724
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((c = window.location) == null ? void 0 : c.href).searchParams.get("_storyblok") === n;
|
|
725
|
+
if (!(!r || !o)) {
|
|
726
|
+
if (!n) {
|
|
612
727
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
613
728
|
return;
|
|
614
729
|
}
|
|
615
730
|
window.storyblokRegisterEvent(() => {
|
|
616
|
-
new window.StoryblokBridge(
|
|
617
|
-
|
|
731
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (l) => {
|
|
732
|
+
l.action === "input" && l.story.id === n ? e(l.story) : (l.action === "change" || l.action === "published") && l.storyId === n && window.location.reload();
|
|
618
733
|
});
|
|
619
734
|
});
|
|
620
735
|
}
|
|
621
|
-
},
|
|
736
|
+
}, ue = (n = {}) => {
|
|
622
737
|
var u, d;
|
|
623
738
|
const {
|
|
624
|
-
bridge:
|
|
625
|
-
accessToken:
|
|
739
|
+
bridge: e,
|
|
740
|
+
accessToken: t,
|
|
626
741
|
use: s = [],
|
|
627
742
|
apiOptions: r = {},
|
|
628
|
-
richText:
|
|
629
|
-
} =
|
|
630
|
-
r.accessToken = r.accessToken ||
|
|
631
|
-
const
|
|
632
|
-
let
|
|
743
|
+
richText: i = {}
|
|
744
|
+
} = n;
|
|
745
|
+
r.accessToken = r.accessToken || t;
|
|
746
|
+
const o = { bridge: e, apiOptions: r };
|
|
747
|
+
let c = {};
|
|
633
748
|
s.forEach((g) => {
|
|
634
|
-
|
|
749
|
+
c = __spreadValues(__spreadValues({}, c), g(o));
|
|
635
750
|
});
|
|
636
|
-
const
|
|
637
|
-
return
|
|
638
|
-
},
|
|
639
|
-
|
|
751
|
+
const l = !(typeof window > "u") && ((d = (u = window.location) == null ? void 0 : u.search) == null ? void 0 : d.includes("_storyblok_tk"));
|
|
752
|
+
return e !== false && l && j(x), w = new y(i.schema), i.resolver && E(w, i.resolver), c;
|
|
753
|
+
}, E = (n, e) => {
|
|
754
|
+
n.addNode("blok", (t) => {
|
|
640
755
|
let s = "";
|
|
641
|
-
return
|
|
642
|
-
s +=
|
|
756
|
+
return t.attrs.body.forEach((r) => {
|
|
757
|
+
s += e(r.component, r);
|
|
643
758
|
}), {
|
|
644
759
|
html: s
|
|
645
760
|
};
|
|
646
761
|
});
|
|
647
|
-
},
|
|
648
|
-
let s =
|
|
762
|
+
}, de = (n, e, t) => {
|
|
763
|
+
let s = t || w;
|
|
649
764
|
if (!s) {
|
|
650
765
|
console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
|
|
651
766
|
return;
|
|
652
767
|
}
|
|
653
|
-
return
|
|
768
|
+
return n === "" ? "" : n ? (e && (s = new y(e.schema), e.resolver && E(s, e.resolver)), s.render(n)) : (console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
654
769
|
|
|
655
770
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
|
|
656
771
|
};
|
|
@@ -682,7 +797,7 @@ const useStoryblok = (slug, apiOptions = {}, bridgeOptions = {}) => {
|
|
|
682
797
|
const { data } = await storyblokApiInstance.get(`cdn/stories/${slug}`, apiOptions);
|
|
683
798
|
setStory(data.story);
|
|
684
799
|
if (isBridgeEnable && data.story.id) {
|
|
685
|
-
|
|
800
|
+
he(data.story.id, (story2) => setStory(story2), bridgeOptions);
|
|
686
801
|
}
|
|
687
802
|
}
|
|
688
803
|
initStory();
|
|
@@ -697,7 +812,7 @@ const useStoryblokState = (initialStory = null, bridgeOptions = {}) => {
|
|
|
697
812
|
}
|
|
698
813
|
useEffect(() => {
|
|
699
814
|
setStory(initialStory);
|
|
700
|
-
|
|
815
|
+
he(story.id, (newStory) => setStory(newStory), bridgeOptions);
|
|
701
816
|
}, [initialStory]);
|
|
702
817
|
return story;
|
|
703
818
|
};
|
|
@@ -717,8 +832,8 @@ const getComponent = (componentKey) => {
|
|
|
717
832
|
return componentsMap[componentKey];
|
|
718
833
|
};
|
|
719
834
|
const storyblokInit = (pluginOptions = {}) => {
|
|
720
|
-
const { storyblokApi } =
|
|
835
|
+
const { storyblokApi } = ue(pluginOptions);
|
|
721
836
|
storyblokApiInstance = storyblokApi;
|
|
722
837
|
componentsMap = pluginOptions.components;
|
|
723
838
|
};
|
|
724
|
-
export {
|
|
839
|
+
export { y as RichTextResolver, ie as RichTextSchema, StoryblokComponent, le as apiPlugin, getComponent, useStoryblokApi as getStoryblokApi, he as registerStoryblokBridge, de as renderRichText, ce as storyblokEditable, storyblokInit, useStoryblok, useStoryblokApi, he as useStoryblokBridge, useStoryblokState };
|