@storyblok/vue 6.2.0 → 6.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.
@@ -1,86 +1,38 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a2, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a2, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a2, prop, b[prop]);
14
- }
15
- return a2;
16
- };
17
- import { defineComponent, openBlock, createBlock, resolveDynamicComponent, normalizeProps, guardReactiveProps, ref, onMounted } from "vue";
18
- import e from "axios";
19
- var __defProp2 = Object.defineProperty;
20
- var __defProps = Object.defineProperties;
21
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
22
- var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
23
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
24
- var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
25
- var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
26
- var __spreadValues2 = (a2, b) => {
27
- for (var prop in b || (b = {}))
28
- if (__hasOwnProp2.call(b, prop))
29
- __defNormalProp2(a2, prop, b[prop]);
30
- if (__getOwnPropSymbols2)
31
- for (var prop of __getOwnPropSymbols2(b)) {
32
- if (__propIsEnum2.call(b, prop))
33
- __defNormalProp2(a2, prop, b[prop]);
34
- }
35
- return a2;
36
- };
37
- var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
38
- let loaded = false;
39
- const callbacks = [];
40
- const loadBridge = (src) => {
41
- return new Promise((resolve, reject) => {
42
- if (typeof window === "undefined")
43
- return;
44
- window.storyblokRegisterEvent = (cb) => {
45
- if (window.location === window.parent.location) {
46
- console.warn("You are not in Draft Mode or in the Visual Editor.");
47
- return;
48
- }
49
- if (!loaded)
50
- callbacks.push(cb);
51
- else
52
- cb();
53
- };
54
- if (document.getElementById("storyblok-javascript-bridge"))
1
+ import { defineComponent as E, openBlock as O, createBlock as S, resolveDynamicComponent as P, normalizeProps as j, guardReactiveProps as A, ref as C, onMounted as M } from "vue";
2
+ import x from "axios";
3
+ var N = Object.defineProperty, I = Object.defineProperties, q = Object.getOwnPropertyDescriptors, k = Object.getOwnPropertySymbols, L = Object.prototype.hasOwnProperty, B = Object.prototype.propertyIsEnumerable, b = (n, t, e) => t in n ? N(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, h = (n, t) => {
4
+ for (var e in t || (t = {}))
5
+ L.call(t, e) && b(n, e, t[e]);
6
+ if (k)
7
+ for (var e of k(t))
8
+ B.call(t, e) && b(n, e, t[e]);
9
+ return n;
10
+ }, y = (n, t) => I(n, q(t));
11
+ let v = !1;
12
+ const _ = [], z = (n) => new Promise((t, e) => {
13
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
14
+ if (window.location === window.parent.location) {
15
+ console.warn("You are not in Draft Mode or in the Visual Editor.");
55
16
  return;
56
- const script = document.createElement("script");
57
- script.async = true;
58
- script.src = src;
59
- script.id = "storyblok-javascript-bridge";
60
- script.onerror = (error) => reject(error);
61
- script.onload = (ev) => {
62
- callbacks.forEach((cb) => cb());
63
- loaded = true;
64
- resolve(ev);
65
- };
66
- document.getElementsByTagName("head")[0].appendChild(script);
67
- });
68
- };
69
- const pick = function(attrs, allowed) {
70
- if (!attrs) {
71
- return null;
72
- }
73
- let h2 = {};
74
- for (let key in attrs) {
75
- let value = attrs[key];
76
- if (allowed.indexOf(key) > -1 && value !== null) {
77
- h2[key] = value;
78
17
  }
79
- }
80
- return h2;
81
- };
82
- const isEmailLinkType = (type) => type === "email";
83
- var defaultHtmlSerializer = {
18
+ v ? s() : _.push(s);
19
+ }, document.getElementById("storyblok-javascript-bridge")))
20
+ return;
21
+ const r = document.createElement("script");
22
+ r.async = !0, r.src = n, r.id = "storyblok-javascript-bridge", r.onerror = (s) => e(s), r.onload = (s) => {
23
+ _.forEach((o) => o()), v = !0, t(s);
24
+ }, document.getElementsByTagName("head")[0].appendChild(r);
25
+ }), D = function(n, t) {
26
+ if (!n)
27
+ return null;
28
+ let e = {};
29
+ for (let r in n) {
30
+ let s = n[r];
31
+ t.indexOf(r) > -1 && s !== null && (e[r] = s);
32
+ }
33
+ return e;
34
+ }, U = (n) => n === "email";
35
+ var V = {
84
36
  nodes: {
85
37
  horizontal_rule() {
86
38
  return {
@@ -97,13 +49,13 @@ var defaultHtmlSerializer = {
97
49
  tag: "ul"
98
50
  };
99
51
  },
100
- code_block(node) {
52
+ code_block(n) {
101
53
  return {
102
54
  tag: [
103
55
  "pre",
104
56
  {
105
57
  tag: "code",
106
- attrs: node.attrs
58
+ attrs: n.attrs
107
59
  }
108
60
  ]
109
61
  };
@@ -113,17 +65,17 @@ var defaultHtmlSerializer = {
113
65
  singleTag: "br"
114
66
  };
115
67
  },
116
- heading(node) {
68
+ heading(n) {
117
69
  return {
118
- tag: `h${node.attrs.level}`
70
+ tag: `h${n.attrs.level}`
119
71
  };
120
72
  },
121
- image(node) {
73
+ image(n) {
122
74
  return {
123
75
  singleTag: [
124
76
  {
125
77
  tag: "img",
126
- attrs: pick(node.attrs, ["src", "alt", "title"])
78
+ attrs: D(n.attrs, ["src", "alt", "title"])
127
79
  }
128
80
  ]
129
81
  };
@@ -175,161 +127,100 @@ var defaultHtmlSerializer = {
175
127
  tag: "i"
176
128
  };
177
129
  },
178
- link(node) {
179
- const attrs = __spreadValues2({}, node.attrs);
180
- const { linktype = "url" } = node.attrs;
181
- if (isEmailLinkType(linktype)) {
182
- attrs.href = `mailto:${attrs.href}`;
183
- }
184
- if (attrs.anchor) {
185
- attrs.href = `${attrs.href}#${attrs.anchor}`;
186
- delete attrs.anchor;
187
- }
188
- return {
130
+ link(n) {
131
+ const t = h({}, n.attrs), { linktype: e = "url" } = n.attrs;
132
+ return U(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
189
133
  tag: [
190
134
  {
191
135
  tag: "a",
192
- attrs
136
+ attrs: t
193
137
  }
194
138
  ]
195
139
  };
196
140
  },
197
- styled(node) {
141
+ styled(n) {
198
142
  return {
199
143
  tag: [
200
144
  {
201
145
  tag: "span",
202
- attrs: node.attrs
146
+ attrs: n.attrs
203
147
  }
204
148
  ]
205
149
  };
206
150
  }
207
151
  }
208
152
  };
209
- const escapeHTML = function(string) {
210
- const htmlEscapes = {
153
+ const H = function(n) {
154
+ const t = {
211
155
  "&": "&",
212
156
  "<": "&lt;",
213
157
  ">": "&gt;",
214
158
  '"': "&quot;",
215
159
  "'": "&#39;"
216
- };
217
- const reUnescapedHtml = /[&<>"']/g;
218
- const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
219
- return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr]) : string;
160
+ }, e = /[&<>"']/g, r = RegExp(e.source);
161
+ return n && r.test(n) ? n.replace(e, (s) => t[s]) : n;
220
162
  };
221
- class RichTextResolver {
222
- constructor(schema) {
223
- if (!schema) {
224
- schema = defaultHtmlSerializer;
163
+ class J {
164
+ constructor(t) {
165
+ t || (t = V), this.marks = t.marks || [], this.nodes = t.nodes || [];
166
+ }
167
+ addNode(t, e) {
168
+ this.nodes[t] = e;
169
+ }
170
+ addMark(t, e) {
171
+ this.marks[t] = e;
172
+ }
173
+ render(t = {}) {
174
+ if (t.content && Array.isArray(t.content)) {
175
+ let e = "";
176
+ return t.content.forEach((r) => {
177
+ e += this.renderNode(r);
178
+ }), e;
225
179
  }
226
- this.marks = schema.marks || [];
227
- this.nodes = schema.nodes || [];
228
- }
229
- addNode(key, schema) {
230
- this.nodes[key] = schema;
231
- }
232
- addMark(key, schema) {
233
- this.marks[key] = schema;
234
- }
235
- render(data = {}) {
236
- if (data.content && Array.isArray(data.content)) {
237
- let html = "";
238
- data.content.forEach((node) => {
239
- html += this.renderNode(node);
240
- });
241
- return html;
242
- }
243
- console.warn("The render method must receive an object with a content field, which is an array");
244
- return "";
245
- }
246
- renderNode(item) {
247
- let html = [];
248
- if (item.marks) {
249
- item.marks.forEach((m) => {
250
- const mark = this.getMatchingMark(m);
251
- if (mark) {
252
- html.push(this.renderOpeningTag(mark.tag));
253
- }
254
- });
255
- }
256
- const node = this.getMatchingNode(item);
257
- if (node && node.tag) {
258
- html.push(this.renderOpeningTag(node.tag));
259
- }
260
- if (item.content) {
261
- item.content.forEach((content) => {
262
- html.push(this.renderNode(content));
263
- });
264
- } else if (item.text) {
265
- html.push(escapeHTML(item.text));
266
- } else if (node && node.singleTag) {
267
- html.push(this.renderTag(node.singleTag, " /"));
268
- } else if (node && node.html) {
269
- html.push(node.html);
270
- }
271
- if (node && node.tag) {
272
- html.push(this.renderClosingTag(node.tag));
273
- }
274
- if (item.marks) {
275
- item.marks.slice(0).reverse().forEach((m) => {
276
- const mark = this.getMatchingMark(m);
277
- if (mark) {
278
- html.push(this.renderClosingTag(mark.tag));
279
- }
280
- });
281
- }
282
- return html.join("");
180
+ return console.warn("The render method must receive an object with a content field, which is an array"), "";
283
181
  }
284
- renderTag(tags, ending) {
285
- if (tags.constructor === String) {
286
- return `<${tags}${ending}>`;
287
- }
288
- const all = tags.map((tag) => {
289
- if (tag.constructor === String) {
290
- return `<${tag}${ending}>`;
291
- } else {
292
- let h2 = `<${tag.tag}`;
293
- if (tag.attrs) {
294
- for (let key in tag.attrs) {
295
- let value = tag.attrs[key];
296
- if (value !== null) {
297
- h2 += ` ${key}="${value}"`;
298
- }
182
+ renderNode(t) {
183
+ let e = [];
184
+ t.marks && t.marks.forEach((s) => {
185
+ const o = this.getMatchingMark(s);
186
+ o && e.push(this.renderOpeningTag(o.tag));
187
+ });
188
+ const r = this.getMatchingNode(t);
189
+ return r && r.tag && e.push(this.renderOpeningTag(r.tag)), t.content ? t.content.forEach((s) => {
190
+ e.push(this.renderNode(s));
191
+ }) : t.text ? e.push(H(t.text)) : r && r.singleTag ? e.push(this.renderTag(r.singleTag, " /")) : r && r.html && e.push(r.html), r && r.tag && e.push(this.renderClosingTag(r.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
192
+ const o = this.getMatchingMark(s);
193
+ o && e.push(this.renderClosingTag(o.tag));
194
+ }), e.join("");
195
+ }
196
+ renderTag(t, e) {
197
+ return t.constructor === String ? `<${t}${e}>` : t.map((s) => {
198
+ if (s.constructor === String)
199
+ return `<${s}${e}>`;
200
+ {
201
+ let o = `<${s.tag}`;
202
+ if (s.attrs)
203
+ for (let i in s.attrs) {
204
+ let a = s.attrs[i];
205
+ a !== null && (o += ` ${i}="${a}"`);
299
206
  }
300
- }
301
- return `${h2}${ending}>`;
207
+ return `${o}${e}>`;
302
208
  }
303
- });
304
- return all.join("");
209
+ }).join("");
305
210
  }
306
- renderOpeningTag(tags) {
307
- return this.renderTag(tags, "");
211
+ renderOpeningTag(t) {
212
+ return this.renderTag(t, "");
308
213
  }
309
- renderClosingTag(tags) {
310
- if (tags.constructor === String) {
311
- return `</${tags}>`;
312
- }
313
- const all = tags.slice(0).reverse().map((tag) => {
314
- if (tag.constructor === String) {
315
- return `</${tag}>`;
316
- } else {
317
- return `</${tag.tag}>`;
318
- }
319
- });
320
- return all.join("");
214
+ renderClosingTag(t) {
215
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((r) => r.constructor === String ? `</${r}>` : `</${r.tag}>`).join("");
321
216
  }
322
- getMatchingNode(item) {
323
- if (typeof this.nodes[item.type] !== "function") {
324
- return;
325
- }
326
- return this.nodes[item.type](item);
217
+ getMatchingNode(t) {
218
+ if (typeof this.nodes[t.type] == "function")
219
+ return this.nodes[t.type](t);
327
220
  }
328
- getMatchingMark(item) {
329
- if (typeof this.marks[item.type] !== "function") {
330
- return;
331
- }
332
- return this.marks[item.type](item);
221
+ getMatchingMark(t) {
222
+ if (typeof this.marks[t.type] == "function")
223
+ return this.marks[t.type](t);
333
224
  }
334
225
  }
335
226
  /*!
@@ -337,340 +228,334 @@ class RichTextResolver {
337
228
  * Universal JavaScript SDK for Storyblok's API
338
229
  * (c) 2020-2022 Stobylok Team
339
230
  */
340
- function t(e2) {
341
- return typeof e2 == "number" && (e2 == e2 && e2 !== 1 / 0 && e2 !== -1 / 0);
231
+ function T(n) {
232
+ return typeof n == "number" && n == n && n !== 1 / 0 && n !== -1 / 0;
342
233
  }
343
- function s(e2, s2, r2) {
344
- if (!t(s2))
234
+ function w(n, t, e) {
235
+ if (!T(t))
345
236
  throw new TypeError("Expected `limit` to be a finite number");
346
- if (!t(r2))
237
+ if (!T(e))
347
238
  throw new TypeError("Expected `interval` to be a finite number");
348
- var i2 = [], n2 = [], o2 = 0, a2 = function() {
349
- o2++;
350
- var t2 = setTimeout(function() {
351
- o2--, i2.length > 0 && a2(), n2 = n2.filter(function(e3) {
352
- return e3 !== t2;
239
+ var r = [], s = [], o = 0, i = function() {
240
+ o++;
241
+ var c = setTimeout(function() {
242
+ o--, r.length > 0 && i(), s = s.filter(function(u) {
243
+ return u !== c;
353
244
  });
354
- }, r2);
355
- n2.indexOf(t2) < 0 && n2.push(t2);
356
- var s3 = i2.shift();
357
- s3.resolve(e2.apply(s3.self, s3.args));
358
- }, l2 = function() {
359
- var e3 = arguments, t2 = this;
360
- return new Promise(function(r3, n3) {
361
- i2.push({ resolve: r3, reject: n3, args: e3, self: t2 }), o2 < s2 && a2();
245
+ }, e);
246
+ s.indexOf(c) < 0 && s.push(c);
247
+ var l = r.shift();
248
+ l.resolve(n.apply(l.self, l.args));
249
+ }, a = function() {
250
+ var c = arguments, l = this;
251
+ return new Promise(function(u, p) {
252
+ r.push({ resolve: u, reject: p, args: c, self: l }), o < t && i();
362
253
  });
363
254
  };
364
- return l2.abort = function() {
365
- n2.forEach(clearTimeout), n2 = [], i2.forEach(function(e3) {
366
- e3.reject(new throttle.AbortError());
367
- }), i2.length = 0;
368
- }, l2;
255
+ return a.abort = function() {
256
+ s.forEach(clearTimeout), s = [], r.forEach(function(c) {
257
+ c.reject(new throttle.AbortError());
258
+ }), r.length = 0;
259
+ }, a;
369
260
  }
370
- s.AbortError = function() {
261
+ w.AbortError = function() {
371
262
  Error.call(this, "Throttled function aborted"), this.name = "AbortError";
372
263
  };
373
- const r = function(e2, t2) {
374
- if (!e2)
264
+ const Y = function(n, t) {
265
+ if (!n)
375
266
  return null;
376
- let s2 = {};
377
- for (let r2 in e2) {
378
- let i2 = e2[r2];
379
- t2.indexOf(r2) > -1 && i2 !== null && (s2[r2] = i2);
267
+ let e = {};
268
+ for (let r in n) {
269
+ let s = n[r];
270
+ t.indexOf(r) > -1 && s !== null && (e[r] = s);
380
271
  }
381
- return s2;
272
+ return e;
382
273
  };
383
- var i = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (e2) => ({ tag: ["pre", { tag: "code", attrs: e2.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (e2) => ({ tag: `h${e2.attrs.level}` }), image: (e2) => ({ singleTag: [{ tag: "img", attrs: r(e2.attrs, ["src", "alt", "title"]) }] }), list_item: () => ({ tag: "li" }), ordered_list: () => ({ tag: "ol" }), paragraph: () => ({ tag: "p" }) }, marks: { bold: () => ({ tag: "b" }), strike: () => ({ tag: "strike" }), underline: () => ({ tag: "u" }), strong: () => ({ tag: "strong" }), code: () => ({ tag: "code" }), italic: () => ({ tag: "i" }), link(e2) {
384
- const t2 = __spreadValues2({}, e2.attrs), { linktype: s2 = "url" } = e2.attrs;
385
- return s2 === "email" && (t2.href = `mailto:${t2.href}`), t2.anchor && (t2.href = `${t2.href}#${t2.anchor}`, delete t2.anchor), { tag: [{ tag: "a", attrs: t2 }] };
386
- }, styled: (e2) => ({ tag: [{ tag: "span", attrs: e2.attrs }] }) } };
387
- class n {
388
- constructor(e2) {
389
- e2 || (e2 = i), this.marks = e2.marks || [], this.nodes = e2.nodes || [];
390
- }
391
- addNode(e2, t2) {
392
- this.nodes[e2] = t2;
393
- }
394
- addMark(e2, t2) {
395
- this.marks[e2] = t2;
396
- }
397
- render(e2 = {}) {
398
- if (e2.content && Array.isArray(e2.content)) {
399
- let t2 = "";
400
- return e2.content.forEach((e3) => {
401
- t2 += this.renderNode(e3);
402
- }), t2;
274
+ var F = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (n) => ({ tag: ["pre", { tag: "code", attrs: n.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (n) => ({ tag: `h${n.attrs.level}` }), image: (n) => ({ singleTag: [{ tag: "img", attrs: Y(n.attrs, ["src", "alt", "title"]) }] }), list_item: () => ({ tag: "li" }), ordered_list: () => ({ tag: "ol" }), paragraph: () => ({ tag: "p" }) }, marks: { bold: () => ({ tag: "b" }), strike: () => ({ tag: "strike" }), underline: () => ({ tag: "u" }), strong: () => ({ tag: "strong" }), code: () => ({ tag: "code" }), italic: () => ({ tag: "i" }), link(n) {
275
+ const t = h({}, n.attrs), { linktype: e = "url" } = n.attrs;
276
+ return e === "email" && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), { tag: [{ tag: "a", attrs: t }] };
277
+ }, styled: (n) => ({ tag: [{ tag: "span", attrs: n.attrs }] }) } };
278
+ class G {
279
+ constructor(t) {
280
+ t || (t = F), this.marks = t.marks || [], this.nodes = t.nodes || [];
281
+ }
282
+ addNode(t, e) {
283
+ this.nodes[t] = e;
284
+ }
285
+ addMark(t, e) {
286
+ this.marks[t] = e;
287
+ }
288
+ render(t = {}) {
289
+ if (t.content && Array.isArray(t.content)) {
290
+ let e = "";
291
+ return t.content.forEach((r) => {
292
+ e += this.renderNode(r);
293
+ }), e;
403
294
  }
404
295
  return console.warn("The render method must receive an object with a content field, which is an array"), "";
405
296
  }
406
- renderNode(e2) {
407
- let t2 = [];
408
- e2.marks && e2.marks.forEach((e3) => {
409
- const s3 = this.getMatchingMark(e3);
410
- s3 && t2.push(this.renderOpeningTag(s3.tag));
297
+ renderNode(t) {
298
+ let e = [];
299
+ t.marks && t.marks.forEach((s) => {
300
+ const o = this.getMatchingMark(s);
301
+ o && e.push(this.renderOpeningTag(o.tag));
411
302
  });
412
- const s2 = this.getMatchingNode(e2);
413
- return s2 && s2.tag && t2.push(this.renderOpeningTag(s2.tag)), e2.content ? e2.content.forEach((e3) => {
414
- t2.push(this.renderNode(e3));
415
- }) : e2.text ? t2.push(function(e3) {
416
- const t3 = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, s3 = /[&<>"']/g, r2 = RegExp(s3.source);
417
- return e3 && r2.test(e3) ? e3.replace(s3, (e4) => t3[e4]) : e3;
418
- }(e2.text)) : s2 && s2.singleTag ? t2.push(this.renderTag(s2.singleTag, " /")) : s2 && s2.html && t2.push(s2.html), s2 && s2.tag && t2.push(this.renderClosingTag(s2.tag)), e2.marks && e2.marks.slice(0).reverse().forEach((e3) => {
419
- const s3 = this.getMatchingMark(e3);
420
- s3 && t2.push(this.renderClosingTag(s3.tag));
421
- }), t2.join("");
422
- }
423
- renderTag(e2, t2) {
424
- if (e2.constructor === String)
425
- return `<${e2}${t2}>`;
426
- return e2.map((e3) => {
427
- if (e3.constructor === String)
428
- return `<${e3}${t2}>`;
303
+ const r = this.getMatchingNode(t);
304
+ return r && r.tag && e.push(this.renderOpeningTag(r.tag)), t.content ? t.content.forEach((s) => {
305
+ e.push(this.renderNode(s));
306
+ }) : t.text ? e.push(function(s) {
307
+ const o = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, i = /[&<>"']/g, a = RegExp(i.source);
308
+ return s && a.test(s) ? s.replace(i, (c) => o[c]) : s;
309
+ }(t.text)) : r && r.singleTag ? e.push(this.renderTag(r.singleTag, " /")) : r && r.html && e.push(r.html), r && r.tag && e.push(this.renderClosingTag(r.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
310
+ const o = this.getMatchingMark(s);
311
+ o && e.push(this.renderClosingTag(o.tag));
312
+ }), e.join("");
313
+ }
314
+ renderTag(t, e) {
315
+ return t.constructor === String ? `<${t}${e}>` : t.map((r) => {
316
+ if (r.constructor === String)
317
+ return `<${r}${e}>`;
429
318
  {
430
- let s2 = `<${e3.tag}`;
431
- if (e3.attrs)
432
- for (let t3 in e3.attrs) {
433
- let r2 = e3.attrs[t3];
434
- r2 !== null && (s2 += ` ${t3}="${r2}"`);
319
+ let s = `<${r.tag}`;
320
+ if (r.attrs)
321
+ for (let o in r.attrs) {
322
+ let i = r.attrs[o];
323
+ i !== null && (s += ` ${o}="${i}"`);
435
324
  }
436
- return `${s2}${t2}>`;
325
+ return `${s}${e}>`;
437
326
  }
438
327
  }).join("");
439
328
  }
440
- renderOpeningTag(e2) {
441
- return this.renderTag(e2, "");
329
+ renderOpeningTag(t) {
330
+ return this.renderTag(t, "");
442
331
  }
443
- renderClosingTag(e2) {
444
- if (e2.constructor === String)
445
- return `</${e2}>`;
446
- return e2.slice(0).reverse().map((e3) => e3.constructor === String ? `</${e3}>` : `</${e3.tag}>`).join("");
332
+ renderClosingTag(t) {
333
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
447
334
  }
448
- getMatchingNode(e2) {
449
- if (typeof this.nodes[e2.type] == "function")
450
- return this.nodes[e2.type](e2);
335
+ getMatchingNode(t) {
336
+ if (typeof this.nodes[t.type] == "function")
337
+ return this.nodes[t.type](t);
451
338
  }
452
- getMatchingMark(e2) {
453
- if (typeof this.marks[e2.type] == "function")
454
- return this.marks[e2.type](e2);
339
+ getMatchingMark(t) {
340
+ if (typeof this.marks[t.type] == "function")
341
+ return this.marks[t.type](t);
455
342
  }
456
343
  }
457
- const o = (e2 = 0, t2 = e2) => {
458
- const s2 = Math.abs(t2 - e2) || 0, r2 = e2 < t2 ? 1 : -1;
459
- return ((e3 = 0, t3) => [...Array(e3)].map(t3))(s2, (t3, s3) => s3 * r2 + e2);
460
- }, a = (e2, t2, s2) => {
461
- const r2 = [];
462
- for (const i2 in e2) {
463
- if (!Object.prototype.hasOwnProperty.call(e2, i2))
344
+ const K = (n = 0, t = n) => {
345
+ const e = Math.abs(t - n) || 0, r = n < t ? 1 : -1;
346
+ return ((s = 0, o) => [...Array(s)].map(o))(e, (s, o) => o * r + n);
347
+ }, m = (n, t, e) => {
348
+ const r = [];
349
+ for (const s in n) {
350
+ if (!Object.prototype.hasOwnProperty.call(n, s))
464
351
  continue;
465
- const n2 = e2[i2], o2 = s2 ? "" : encodeURIComponent(i2);
466
- let l2;
467
- l2 = typeof n2 == "object" ? a(n2, t2 ? t2 + encodeURIComponent("[" + o2 + "]") : o2, Array.isArray(n2)) : (t2 ? t2 + encodeURIComponent("[" + o2 + "]") : o2) + "=" + encodeURIComponent(n2), r2.push(l2);
352
+ const o = n[s], i = e ? "" : encodeURIComponent(s);
353
+ let a;
354
+ a = typeof o == "object" ? m(o, t ? t + encodeURIComponent("[" + i + "]") : i, Array.isArray(o)) : (t ? t + encodeURIComponent("[" + i + "]") : i) + "=" + encodeURIComponent(o), r.push(a);
468
355
  }
469
- return r2.join("&");
356
+ return r.join("&");
470
357
  };
471
- let l = {}, c = {};
472
- class h {
473
- constructor(t2, r2) {
474
- if (!r2) {
475
- let e2 = t2.region ? `-${t2.region}` : "", s2 = t2.https === false ? "http" : "https";
476
- r2 = t2.oauthToken === void 0 ? `${s2}://api${e2}.storyblok.com/v2` : `${s2}://api${e2}.storyblok.com/v1`;
358
+ let f = {}, d = {};
359
+ class Q {
360
+ constructor(t, e) {
361
+ if (!e) {
362
+ let o = t.region ? `-${t.region}` : "", i = t.https === !1 ? "http" : "https";
363
+ e = t.oauthToken === void 0 ? `${i}://api${o}.storyblok.com/v2` : `${i}://api${o}.storyblok.com/v1`;
477
364
  }
478
- let i2 = Object.assign({}, t2.headers), o2 = 5;
479
- t2.oauthToken !== void 0 && (i2.Authorization = t2.oauthToken, o2 = 3), t2.rateLimit !== void 0 && (o2 = t2.rateLimit), this.richTextResolver = new n(t2.richTextSchema), typeof t2.componentResolver == "function" && this.setComponentResolver(t2.componentResolver), this.maxRetries = t2.maxRetries || 5, this.throttle = s(this.throttledRequest, o2, 1e3), this.accessToken = t2.accessToken, this.relations = {}, this.links = {}, this.cache = t2.cache || { clear: "manual" }, this.client = e.create({ baseURL: r2, timeout: t2.timeout || 0, headers: i2, proxy: t2.proxy || false }), t2.responseInterceptor && this.client.interceptors.response.use((e2) => t2.responseInterceptor(e2)), this.resolveNestedRelations = t2.resolveNestedRelations || true;
480
- }
481
- setComponentResolver(e2) {
482
- this.richTextResolver.addNode("blok", (t2) => {
483
- let s2 = "";
484
- return t2.attrs.body.forEach((t3) => {
485
- s2 += e2(t3.component, t3);
486
- }), { html: s2 };
365
+ let r = Object.assign({}, t.headers), s = 5;
366
+ t.oauthToken !== void 0 && (r.Authorization = t.oauthToken, s = 3), t.rateLimit !== void 0 && (s = t.rateLimit), this.richTextResolver = new G(t.richTextSchema), typeof t.componentResolver == "function" && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries || 5, this.throttle = w(this.throttledRequest, s, 1e3), this.accessToken = t.accessToken, this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.client = x.create({ baseURL: e, timeout: t.timeout || 0, headers: r, proxy: t.proxy || !1 }), t.responseInterceptor && this.client.interceptors.response.use((o) => t.responseInterceptor(o)), this.resolveNestedRelations = t.resolveNestedRelations || !0;
367
+ }
368
+ setComponentResolver(t) {
369
+ this.richTextResolver.addNode("blok", (e) => {
370
+ let r = "";
371
+ return e.attrs.body.forEach((s) => {
372
+ r += t(s.component, s);
373
+ }), { html: r };
487
374
  });
488
375
  }
489
- parseParams(e2 = {}) {
490
- return e2.version || (e2.version = "published"), e2.token || (e2.token = this.getToken()), e2.cv || (e2.cv = c[e2.token]), Array.isArray(e2.resolve_relations) && (e2.resolve_relations = e2.resolve_relations.join(",")), e2;
376
+ parseParams(t = {}) {
377
+ return t.version || (t.version = "published"), t.token || (t.token = this.getToken()), t.cv || (t.cv = d[t.token]), Array.isArray(t.resolve_relations) && (t.resolve_relations = t.resolve_relations.join(",")), t;
491
378
  }
492
- factoryParamOptions(e2, t2 = {}) {
493
- return ((e3 = "") => e3.indexOf("/cdn/") > -1)(e2) ? this.parseParams(t2) : t2;
379
+ factoryParamOptions(t, e = {}) {
380
+ return ((r = "") => r.indexOf("/cdn/") > -1)(t) ? this.parseParams(e) : e;
494
381
  }
495
- makeRequest(e2, t2, s2, r2) {
496
- const i2 = this.factoryParamOptions(e2, ((e3 = {}, t3 = 25, s3 = 1) => __spreadProps(__spreadValues2({}, e3), { per_page: t3, page: s3 }))(t2, s2, r2));
497
- return this.cacheResponse(e2, i2);
382
+ makeRequest(t, e, r, s) {
383
+ const o = this.factoryParamOptions(t, ((i = {}, a = 25, c = 1) => y(h({}, i), { per_page: a, page: c }))(e, r, s));
384
+ return this.cacheResponse(t, o);
498
385
  }
499
- get(e2, t2) {
500
- let s2 = `/${e2}`;
501
- const r2 = this.factoryParamOptions(s2, t2);
502
- return this.cacheResponse(s2, r2);
386
+ get(t, e) {
387
+ let r = `/${t}`;
388
+ const s = this.factoryParamOptions(r, e);
389
+ return this.cacheResponse(r, s);
503
390
  }
504
- async getAll(e2, t2 = {}, s2) {
505
- const r2 = t2.per_page || 25, i2 = `/${e2}`, n2 = i2.split("/");
506
- s2 = s2 || n2[n2.length - 1];
507
- const a2 = await this.makeRequest(i2, t2, r2, 1), l2 = Math.ceil(a2.total / r2);
508
- return ((e3 = [], t3) => e3.map(t3).reduce((e4, t4) => [...e4, ...t4], []))([a2, ...await (async (e3 = [], t3) => Promise.all(e3.map(t3)))(o(1, l2), async (e3) => this.makeRequest(i2, t2, r2, e3 + 1))], (e3) => Object.values(e3.data[s2]));
391
+ async getAll(t, e = {}, r) {
392
+ const s = e.per_page || 25, o = `/${t}`, i = o.split("/");
393
+ r = r || i[i.length - 1];
394
+ const a = await this.makeRequest(o, e, s, 1), c = Math.ceil(a.total / s);
395
+ return ((l = [], u) => l.map(u).reduce((p, $) => [...p, ...$], []))([a, ...await (async (l = [], u) => Promise.all(l.map(u)))(K(1, c), async (l) => this.makeRequest(o, e, s, l + 1))], (l) => Object.values(l.data[r]));
509
396
  }
510
- post(e2, t2) {
511
- let s2 = `/${e2}`;
512
- return this.throttle("post", s2, t2);
397
+ post(t, e) {
398
+ let r = `/${t}`;
399
+ return this.throttle("post", r, e);
513
400
  }
514
- put(e2, t2) {
515
- let s2 = `/${e2}`;
516
- return this.throttle("put", s2, t2);
401
+ put(t, e) {
402
+ let r = `/${t}`;
403
+ return this.throttle("put", r, e);
517
404
  }
518
- delete(e2, t2) {
519
- let s2 = `/${e2}`;
520
- return this.throttle("delete", s2, t2);
405
+ delete(t, e) {
406
+ let r = `/${t}`;
407
+ return this.throttle("delete", r, e);
521
408
  }
522
- getStories(e2) {
523
- return this.get("cdn/stories", e2);
409
+ getStories(t) {
410
+ return this.get("cdn/stories", t);
524
411
  }
525
- getStory(e2, t2) {
526
- return this.get(`cdn/stories/${e2}`, t2);
412
+ getStory(t, e) {
413
+ return this.get(`cdn/stories/${t}`, e);
527
414
  }
528
- setToken(e2) {
529
- this.accessToken = e2;
415
+ setToken(t) {
416
+ this.accessToken = t;
530
417
  }
531
418
  getToken() {
532
419
  return this.accessToken;
533
420
  }
534
- _cleanCopy(e2) {
535
- return JSON.parse(JSON.stringify(e2));
536
- }
537
- _insertLinks(e2, t2) {
538
- const s2 = e2[t2];
539
- s2 && s2.fieldtype == "multilink" && s2.linktype == "story" && typeof s2.id == "string" && this.links[s2.id] ? s2.story = this._cleanCopy(this.links[s2.id]) : s2 && s2.linktype === "story" && typeof s2.uuid == "string" && this.links[s2.uuid] && (s2.story = this._cleanCopy(this.links[s2.uuid]));
540
- }
541
- _insertRelations(e2, t2, s2) {
542
- if (s2.indexOf(e2.component + "." + t2) > -1) {
543
- if (typeof e2[t2] == "string")
544
- this.relations[e2[t2]] && (e2[t2] = this._cleanCopy(this.relations[e2[t2]]));
545
- else if (e2[t2].constructor === Array) {
546
- let s3 = [];
547
- e2[t2].forEach((e3) => {
548
- this.relations[e3] && s3.push(this._cleanCopy(this.relations[e3]));
549
- }), e2[t2] = s3;
421
+ _cleanCopy(t) {
422
+ return JSON.parse(JSON.stringify(t));
423
+ }
424
+ _insertLinks(t, e) {
425
+ const r = t[e];
426
+ r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[r.id] ? r.story = this._cleanCopy(this.links[r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[r.uuid] && (r.story = this._cleanCopy(this.links[r.uuid]));
427
+ }
428
+ _insertRelations(t, e, r) {
429
+ if (r.indexOf(t.component + "." + e) > -1) {
430
+ if (typeof t[e] == "string")
431
+ this.relations[t[e]] && (t[e] = this._cleanCopy(this.relations[t[e]]));
432
+ else if (t[e].constructor === Array) {
433
+ let s = [];
434
+ t[e].forEach((o) => {
435
+ this.relations[o] && s.push(this._cleanCopy(this.relations[o]));
436
+ }), t[e] = s;
550
437
  }
551
438
  }
552
439
  }
553
- _insertAssetsRelations(e2, t2) {
554
- t2.forEach((t3) => {
555
- e2.id === t3.id && (e2.original = t3, e2.original.filename = e2.filename, e2.original.filename = e2.original.filename.includes("https://s3.amazonaws.com/") ? e2.original.filename : e2.original.filename.replace("https://", "https://s3.amazonaws.com/"), delete e2.original.s3_filename);
440
+ _insertAssetsRelations(t, e) {
441
+ e.forEach((r) => {
442
+ t.id === r.id && (t.original = r, t.original.filename = t.filename, t.original.filename = t.original.filename.includes("https://s3.amazonaws.com/") ? t.original.filename : t.original.filename.replace("https://", "https://s3.amazonaws.com/"), delete t.original.s3_filename);
556
443
  });
557
444
  }
558
- iterateTree(e2, t2) {
559
- let s2 = (e3) => {
560
- if (e3 != null) {
561
- if (e3.constructor === Array)
562
- for (let t3 = 0; t3 < e3.length; t3++)
563
- s2(e3[t3]);
564
- else if (e3.constructor === Object) {
565
- if (e3._stopResolving)
445
+ iterateTree(t, e) {
446
+ let r = (s) => {
447
+ if (s != null) {
448
+ if (s.constructor === Array)
449
+ for (let o = 0; o < s.length; o++)
450
+ r(s[o]);
451
+ else if (s.constructor === Object) {
452
+ if (s._stopResolving)
566
453
  return;
567
- for (let r2 in e3)
568
- e3.component && e3._uid || e3.type === "link" ? (this._insertRelations(e3, r2, t2), this._insertLinks(e3, r2)) : "id" in e3 && e3.fieldtype === "asset" && this._insertAssetsRelations(e3, t2), s2(e3[r2]);
454
+ for (let o in s)
455
+ s.component && s._uid || s.type === "link" ? (this._insertRelations(s, o, e), this._insertLinks(s, o)) : "id" in s && s.fieldtype === "asset" && this._insertAssetsRelations(s, e), r(s[o]);
569
456
  }
570
457
  }
571
458
  };
572
- s2(e2.content);
573
- }
574
- async resolveLinks(e2, t2) {
575
- let s2 = [];
576
- if (e2.link_uuids) {
577
- const r2 = e2.link_uuids.length;
578
- let i2 = [];
579
- const n2 = 50;
580
- for (let t3 = 0; t3 < r2; t3 += n2) {
581
- const s3 = Math.min(r2, t3 + n2);
582
- i2.push(e2.link_uuids.slice(t3, s3));
459
+ r(t.content);
460
+ }
461
+ async resolveLinks(t, e) {
462
+ let r = [];
463
+ if (t.link_uuids) {
464
+ const s = t.link_uuids.length;
465
+ let o = [];
466
+ const i = 50;
467
+ for (let a = 0; a < s; a += i) {
468
+ const c = Math.min(s, a + i);
469
+ o.push(t.link_uuids.slice(a, c));
583
470
  }
584
- for (let e3 = 0; e3 < i2.length; e3++) {
585
- (await this.getStories({ per_page: n2, language: t2.language, version: t2.version, by_uuids: i2[e3].join(",") })).data.stories.forEach((e4) => {
586
- s2.push(e4);
471
+ for (let a = 0; a < o.length; a++)
472
+ (await this.getStories({ per_page: i, language: e.language, version: e.version, by_uuids: o[a].join(",") })).data.stories.forEach((c) => {
473
+ r.push(c);
587
474
  });
588
- }
589
475
  } else
590
- s2 = e2.links;
591
- s2.forEach((e3) => {
592
- this.links[e3.uuid] = __spreadProps(__spreadValues2({}, e3), { _stopResolving: true });
476
+ r = t.links;
477
+ r.forEach((s) => {
478
+ this.links[s.uuid] = y(h({}, s), { _stopResolving: !0 });
593
479
  });
594
480
  }
595
- async resolveRelations(e2, t2) {
596
- let s2 = [];
597
- if (e2.rel_uuids) {
598
- const r2 = e2.rel_uuids.length;
599
- let i2 = [];
600
- const n2 = 50;
601
- for (let t3 = 0; t3 < r2; t3 += n2) {
602
- const s3 = Math.min(r2, t3 + n2);
603
- i2.push(e2.rel_uuids.slice(t3, s3));
481
+ async resolveRelations(t, e) {
482
+ let r = [];
483
+ if (t.rel_uuids) {
484
+ const s = t.rel_uuids.length;
485
+ let o = [];
486
+ const i = 50;
487
+ for (let a = 0; a < s; a += i) {
488
+ const c = Math.min(s, a + i);
489
+ o.push(t.rel_uuids.slice(a, c));
604
490
  }
605
- for (let e3 = 0; e3 < i2.length; e3++) {
606
- (await this.getStories({ per_page: n2, language: t2.language, version: t2.version, by_uuids: i2[e3].join(",") })).data.stories.forEach((e4) => {
607
- s2.push(e4);
491
+ for (let a = 0; a < o.length; a++)
492
+ (await this.getStories({ per_page: i, language: e.language, version: e.version, by_uuids: o[a].join(",") })).data.stories.forEach((c) => {
493
+ r.push(c);
608
494
  });
609
- }
610
495
  } else
611
- s2 = e2.rels;
612
- s2.forEach((e3) => {
613
- this.relations[e3.uuid] = __spreadProps(__spreadValues2({}, e3), { _stopResolving: true });
496
+ r = t.rels;
497
+ r.forEach((s) => {
498
+ this.relations[s.uuid] = y(h({}, s), { _stopResolving: !0 });
614
499
  });
615
500
  }
616
- async resolveStories(e2, t2) {
617
- let s2 = [];
618
- if (t2.resolve_relations !== void 0 && t2.resolve_relations.length > 0 && (e2.rels || e2.rel_uuids) && (s2 = t2.resolve_relations.split(","), await this.resolveRelations(e2, t2)), ["1", "story", "url"].indexOf(t2.resolve_links) > -1 && (e2.links || e2.link_uuids) && await this.resolveLinks(e2, t2), this.resolveNestedRelations)
619
- for (const e3 in this.relations)
620
- this.iterateTree(this.relations[e3], s2);
621
- e2.story ? this.iterateTree(e2.story, s2) : e2.stories.forEach((e3) => {
622
- this.iterateTree(e3, s2);
501
+ async resolveStories(t, e) {
502
+ let r = [];
503
+ if (e.resolve_relations !== void 0 && e.resolve_relations.length > 0 && (t.rels || t.rel_uuids) && (r = e.resolve_relations.split(","), await this.resolveRelations(t, e)), ["1", "story", "url"].indexOf(e.resolve_links) > -1 && (t.links || t.link_uuids) && await this.resolveLinks(t, e), this.resolveNestedRelations)
504
+ for (const s in this.relations)
505
+ this.iterateTree(this.relations[s], r);
506
+ t.story ? this.iterateTree(t.story, r) : t.stories.forEach((s) => {
507
+ this.iterateTree(s, r);
623
508
  });
624
509
  }
625
- resolveAssetsRelations(e2) {
626
- const { assets: t2, stories: s2, story: r2 } = e2;
627
- if (s2)
628
- for (const e3 of s2)
629
- this.iterateTree(e3, t2);
510
+ resolveAssetsRelations(t) {
511
+ const { assets: e, stories: r, story: s } = t;
512
+ if (r)
513
+ for (const o of r)
514
+ this.iterateTree(o, e);
630
515
  else {
631
- if (!r2)
632
- return e2;
633
- this.iterateTree(r2, t2);
516
+ if (!s)
517
+ return t;
518
+ this.iterateTree(s, e);
634
519
  }
635
520
  }
636
- cacheResponse(e2, t2, s2) {
637
- return s2 === void 0 && (s2 = 0), new Promise(async (r2, i2) => {
638
- let n2 = a({ url: e2, params: t2 }), o2 = this.cacheProvider();
639
- if (this.cache.clear === "auto" && t2.version === "draft" && await this.flushCache(), t2.version === "published" && e2 != "/cdn/spaces/me") {
640
- const e3 = await o2.get(n2);
641
- if (e3)
642
- return r2(e3);
521
+ cacheResponse(t, e, r) {
522
+ return r === void 0 && (r = 0), new Promise(async (s, o) => {
523
+ let i = m({ url: t, params: e }), a = this.cacheProvider();
524
+ if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
525
+ const l = await a.get(i);
526
+ if (l)
527
+ return s(l);
643
528
  }
644
529
  try {
645
- let s3 = await this.throttle("get", e2, { params: t2, paramsSerializer: (e3) => a(e3) }), l3 = { data: s3.data, headers: s3.headers };
646
- if (l3.data.assets && l3.data.assets.length && this.resolveAssetsRelations(l3.data), s3.headers["per-page"] && (l3 = Object.assign({}, l3, { perPage: parseInt(s3.headers["per-page"]), total: parseInt(s3.headers.total) })), s3.status != 200)
647
- return i2(s3);
648
- (l3.data.story || l3.data.stories) && await this.resolveStories(l3.data, t2), t2.version === "published" && e2 != "/cdn/spaces/me" && o2.set(n2, l3), l3.data.cv && (t2.version == "draft" && c[t2.token] != l3.data.cv && this.flushCache(), c[t2.token] = l3.data.cv), r2(l3);
649
- } catch (n3) {
650
- if (n3.response && n3.response.status === 429 && (s2 += 1) < this.maxRetries)
651
- return console.log(`Hit rate limit. Retrying in ${s2} seconds.`), await (l2 = 1e3 * s2, new Promise((e3) => setTimeout(e3, l2))), this.cacheResponse(e2, t2, s2).then(r2).catch(i2);
652
- i2(n3);
530
+ let l = await this.throttle("get", t, { params: e, paramsSerializer: (p) => m(p) }), u = { data: l.data, headers: l.headers };
531
+ if (u.data.assets && u.data.assets.length && this.resolveAssetsRelations(u.data), l.headers["per-page"] && (u = Object.assign({}, u, { perPage: parseInt(l.headers["per-page"]), total: parseInt(l.headers.total) })), l.status != 200)
532
+ return o(l);
533
+ (u.data.story || u.data.stories) && await this.resolveStories(u.data, e), e.version === "published" && t != "/cdn/spaces/me" && a.set(i, u), u.data.cv && (e.version == "draft" && d[e.token] != u.data.cv && this.flushCache(), d[e.token] = u.data.cv), s(u);
534
+ } catch (l) {
535
+ if (l.response && l.response.status === 429 && (r += 1) < this.maxRetries)
536
+ return console.log(`Hit rate limit. Retrying in ${r} seconds.`), await (c = 1e3 * r, new Promise((u) => setTimeout(u, c))), this.cacheResponse(t, e, r).then(s).catch(o);
537
+ o(l);
653
538
  }
654
- var l2;
539
+ var c;
655
540
  });
656
541
  }
657
- throttledRequest(e2, t2, s2) {
658
- return this.client[e2](t2, s2);
542
+ throttledRequest(t, e, r) {
543
+ return this.client[t](e, r);
659
544
  }
660
545
  cacheVersions() {
661
- return c;
546
+ return d;
662
547
  }
663
548
  cacheVersion() {
664
- return c[this.accessToken];
549
+ return d[this.accessToken];
665
550
  }
666
- setCacheVersion(e2) {
667
- this.accessToken && (c[this.accessToken] = e2);
551
+ setCacheVersion(t) {
552
+ this.accessToken && (d[this.accessToken] = t);
668
553
  }
669
554
  cacheProvider() {
670
- return this.cache.type === "memory" ? { get: (e2) => l[e2], getAll: () => l, set(e2, t2) {
671
- l[e2] = t2;
555
+ return this.cache.type === "memory" ? { get: (t) => f[t], getAll: () => f, set(t, e) {
556
+ f[t] = e;
672
557
  }, flush() {
673
- l = {};
558
+ f = {};
674
559
  } } : { get() {
675
560
  }, getAll() {
676
561
  }, set() {
@@ -681,125 +566,99 @@ class h {
681
566
  return await this.cacheProvider().flush(), this;
682
567
  }
683
568
  }
684
- const apiFactory = (options = {}) => {
685
- const { apiOptions } = options;
686
- if (!apiOptions.accessToken) {
569
+ const it = (n = {}) => {
570
+ const { apiOptions: t } = n;
571
+ if (!t.accessToken) {
687
572
  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");
688
573
  return;
689
574
  }
690
- const storyblokApi = new h(apiOptions);
691
- return { storyblokApi };
575
+ return { storyblokApi: new Q(t) };
692
576
  };
693
- var editable = (blok) => {
694
- if (typeof blok !== "object" || typeof blok._editable === "undefined") {
577
+ var W = (n) => {
578
+ if (typeof n != "object" || typeof n._editable > "u")
695
579
  return {};
696
- }
697
- const options = JSON.parse(blok._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
580
+ const t = JSON.parse(n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
698
581
  return {
699
- "data-blok-c": JSON.stringify(options),
700
- "data-blok-uid": options.id + "-" + options.uid
582
+ "data-blok-c": JSON.stringify(t),
583
+ "data-blok-uid": t.id + "-" + t.uid
701
584
  };
702
585
  };
703
- const resolver = new RichTextResolver();
704
- const bridgeLatest = "https://app.storyblok.com/f/storyblok-v2-latest.js";
705
- const useStoryblokBridge = (id, cb, options = {}) => {
706
- if (typeof window === "undefined") {
707
- return;
708
- }
709
- if (typeof window.storyblokRegisterEvent === "undefined") {
710
- console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");
711
- return;
712
- }
713
- if (!id) {
714
- console.warn("Story ID is not defined. Please provide a valid ID.");
715
- return;
716
- }
717
- window.storyblokRegisterEvent(() => {
718
- const sbBridge = new window.StoryblokBridge(options);
719
- sbBridge.on(["input", "published", "change"], (event) => {
720
- if (event.action == "input" && event.story.id === id) {
721
- cb(event.story);
722
- } else {
723
- window.location.reload();
724
- }
586
+ const X = new J(), Z = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt = (n, t, e = {}) => {
587
+ if (!(typeof window > "u")) {
588
+ if (typeof window.storyblokRegisterEvent > "u") {
589
+ console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");
590
+ return;
591
+ }
592
+ if (!n) {
593
+ console.warn("Story ID is not defined. Please provide a valid ID.");
594
+ return;
595
+ }
596
+ window.storyblokRegisterEvent(() => {
597
+ new window.StoryblokBridge(e).on(["input", "published", "change"], (s) => {
598
+ s.story.id === n && (s.action === "input" ? t(s.story) : window.location.reload());
599
+ });
725
600
  });
726
- });
727
- };
728
- const storyblokInit = (pluginOptions = {}) => {
729
- const { bridge, accessToken, use = [], apiOptions = {} } = pluginOptions;
730
- apiOptions.accessToken = apiOptions.accessToken || accessToken;
731
- const options = { bridge, apiOptions };
732
- let result = {};
733
- use.forEach((pluginFactory) => {
734
- result = __spreadValues2(__spreadValues2({}, result), pluginFactory(options));
735
- });
736
- if (bridge !== false) {
737
- loadBridge(bridgeLatest);
738
- }
739
- return result;
740
- };
741
- const renderRichText = (text) => {
742
- if (text === "") {
743
- return "";
744
- } else if (!text) {
745
- console.warn(`${text} is not a valid Richtext object. This might be because the value of the richtext field is empty.
746
-
747
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`);
748
- return "";
749
601
  }
750
- return resolver.render(text);
751
- };
752
- const _sfc_main = /* @__PURE__ */ defineComponent({
602
+ }, et = (n = {}) => {
603
+ const { bridge: t, accessToken: e, use: r = [], apiOptions: s = {} } = n;
604
+ s.accessToken = s.accessToken || e;
605
+ const o = { bridge: t, apiOptions: s };
606
+ let i = {};
607
+ return r.forEach((a) => {
608
+ i = h(h({}, i), a(o));
609
+ }), t !== !1 && z(Z), i;
610
+ }, at = (n) => n === "" ? "" : n ? X.render(n) : (console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
611
+
612
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), ""), rt = /* @__PURE__ */ E({
753
613
  __name: "StoryblokComponent",
754
614
  props: {
755
615
  blok: null
756
616
  },
757
- setup(__props) {
758
- return (_ctx, _cache) => {
759
- return openBlock(), createBlock(resolveDynamicComponent(__props.blok.component), normalizeProps(guardReactiveProps(__spreadValues(__spreadValues({}, _ctx.$props), _ctx.$attrs))), null, 16);
760
- };
761
- }
762
- });
763
- const vEditableDirective = {
764
- beforeMount(el, binding) {
765
- if (binding.value) {
766
- const options = editable(binding.value);
767
- el.setAttribute("data-blok-c", options["data-blok-c"]);
768
- el.setAttribute("data-blok-uid", options["data-blok-uid"]);
769
- el.classList.add("storyblok__outline");
617
+ setup(n) {
618
+ return (t, e) => (O(), S(P(n.blok.component), j(A({ ...t.$props, ...t.$attrs })), null, 16));
619
+ }
620
+ }), st = {
621
+ beforeMount(n, t) {
622
+ if (t.value) {
623
+ const e = W(t.value);
624
+ n.setAttribute("data-blok-c", e["data-blok-c"]), n.setAttribute("data-blok-uid", e["data-blok-uid"]), n.classList.add("storyblok__outline");
770
625
  }
771
626
  }
772
- };
773
- const printError = (fnName) => {
774
- console.error(`You can't use ${fnName} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
627
+ }, R = (n) => {
628
+ console.error(`You can't use ${n} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
775
629
  `);
776
630
  };
777
- let storyblokApiInstance = null;
778
- const useStoryblokApi = () => {
779
- if (!storyblokApiInstance)
780
- printError("useStoryblokApi");
781
- return storyblokApiInstance;
782
- };
783
- const useStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
784
- const story = ref(null);
785
- onMounted(() => {
786
- if (story.value && story.value.id) {
787
- useStoryblokBridge(story.value.id, (evStory) => story.value = evStory, bridgeOptions);
788
- }
789
- });
790
- if (storyblokApiInstance) {
791
- const { data } = await storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions);
792
- story.value = data.story;
631
+ let g = null;
632
+ const lt = () => (g || R("useStoryblokApi"), g), ct = async (n, t = {}, e = {}) => {
633
+ const r = C(null);
634
+ if (M(() => {
635
+ r.value && r.value.id && tt(
636
+ r.value.id,
637
+ (s) => r.value = s,
638
+ e
639
+ );
640
+ }), g) {
641
+ const { data: s } = await g.get(
642
+ `cdn/stories/${n}`,
643
+ t
644
+ );
645
+ r.value = s.story;
793
646
  } else
794
- printError("useStoryblok");
795
- return story;
796
- };
797
- const StoryblokVue = {
798
- install(app, pluginOptions = {}) {
799
- app.directive("editable", vEditableDirective);
800
- app.component("StoryblokComponent", _sfc_main);
801
- const { storyblokApi } = storyblokInit(pluginOptions);
802
- storyblokApiInstance = storyblokApi;
647
+ R("useStoryblok");
648
+ return r;
649
+ }, ut = {
650
+ install(n, t = {}) {
651
+ n.directive("editable", st), n.component("StoryblokComponent", rt);
652
+ const { storyblokApi: e } = et(t);
653
+ g = e;
803
654
  }
804
655
  };
805
- export { _sfc_main as StoryblokComponent, StoryblokVue, apiFactory as apiPlugin, renderRichText, useStoryblok, useStoryblokApi, useStoryblokBridge };
656
+ export {
657
+ rt as StoryblokComponent,
658
+ ut as StoryblokVue,
659
+ it as apiPlugin,
660
+ at as renderRichText,
661
+ ct as useStoryblok,
662
+ lt as useStoryblokApi,
663
+ tt as useStoryblokBridge
664
+ };