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