@storyblok/react 1.3.5 → 2.0.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.
@@ -3,16 +3,16 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
3
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
4
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
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]);
6
+ var __spreadValues = (a, b2) => {
7
+ for (var prop in b2 || (b2 = {}))
8
+ if (__hasOwnProp.call(b2, prop))
9
+ __defNormalProp(a, prop, b2[prop]);
10
10
  if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a2, prop, b[prop]);
11
+ for (var prop of __getOwnPropSymbols(b2)) {
12
+ if (__propIsEnum.call(b2, prop))
13
+ __defNormalProp(a, prop, b2[prop]);
14
14
  }
15
- return a2;
15
+ return a;
16
16
  };
17
17
  var __objRest = (source, exclude) => {
18
18
  var target = {};
@@ -27,7 +27,6 @@ var __objRest = (source, exclude) => {
27
27
  return target;
28
28
  };
29
29
  import React, { forwardRef, useState, useEffect } from "react";
30
- import e from "axios";
31
30
  var __defProp2 = Object.defineProperty;
32
31
  var __defProps = Object.defineProperties;
33
32
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -35,18 +34,18 @@ var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
35
34
  var __hasOwnProp2 = Object.prototype.hasOwnProperty;
36
35
  var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
37
36
  var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
38
- var __spreadValues2 = (a2, b) => {
39
- for (var prop in b || (b = {}))
40
- if (__hasOwnProp2.call(b, prop))
41
- __defNormalProp2(a2, prop, b[prop]);
37
+ var __spreadValues2 = (a, b2) => {
38
+ for (var prop in b2 || (b2 = {}))
39
+ if (__hasOwnProp2.call(b2, prop))
40
+ __defNormalProp2(a, prop, b2[prop]);
42
41
  if (__getOwnPropSymbols2)
43
- for (var prop of __getOwnPropSymbols2(b)) {
44
- if (__propIsEnum2.call(b, prop))
45
- __defNormalProp2(a2, prop, b[prop]);
42
+ for (var prop of __getOwnPropSymbols2(b2)) {
43
+ if (__propIsEnum2.call(b2, prop))
44
+ __defNormalProp2(a, prop, b2[prop]);
46
45
  }
47
- return a2;
46
+ return a;
48
47
  };
49
- var __spreadProps = (a2, b) => __defProps(a2, __getOwnPropDescs(b));
48
+ var __spreadProps = (a, b2) => __defProps(a, __getOwnPropDescs(b2));
50
49
  let loaded = false;
51
50
  const callbacks = [];
52
51
  const loadBridge = (src) => {
@@ -78,619 +77,555 @@ const loadBridge = (src) => {
78
77
  document.getElementsByTagName("head")[0].appendChild(script);
79
78
  });
80
79
  };
81
- const pick = function(attrs, allowed) {
82
- if (!attrs) {
83
- return null;
84
- }
85
- let h2 = {};
86
- for (let key in attrs) {
87
- let value = attrs[key];
88
- if (allowed.indexOf(key) > -1 && value !== null) {
89
- h2[key] = value;
80
+ var m = Object.defineProperty;
81
+ var R = (i, t, e) => t in i ? m(i, t, { enumerable: true, configurable: true, writable: true, value: e }) : i[t] = e;
82
+ var l = (i, t, e) => (R(i, typeof t != "symbol" ? t + "" : t, e), e);
83
+ function y(i) {
84
+ return !(i !== i || i === 1 / 0 || i === -1 / 0);
85
+ }
86
+ function _(i, t, e) {
87
+ if (!y(t))
88
+ throw new TypeError("Expected `limit` to be a finite number");
89
+ if (!y(e))
90
+ throw new TypeError("Expected `interval` to be a finite number");
91
+ const s = [];
92
+ let r = [], n = 0;
93
+ const c = function() {
94
+ n++;
95
+ const a = setTimeout(function() {
96
+ n--, s.length > 0 && c(), r = r.filter(function(u) {
97
+ return u !== a;
98
+ });
99
+ }, e);
100
+ r.indexOf(a) < 0 && r.push(a);
101
+ const h = s.shift();
102
+ h.resolve(i.apply(h.self, h.args));
103
+ }, o = function(...a) {
104
+ const h = this;
105
+ return new Promise(function(u, g) {
106
+ s.push({
107
+ resolve: u,
108
+ reject: g,
109
+ args: a,
110
+ self: h
111
+ }), n < t && c();
112
+ });
113
+ };
114
+ return o.abort = function() {
115
+ r.forEach(clearTimeout), r = [], s.forEach(function(a) {
116
+ a.reject(function() {
117
+ Error.call(this, "Throttled function aborted"), this.name = "AbortError";
118
+ });
119
+ }), s.length = 0;
120
+ }, o;
121
+ }
122
+ const b = function(i, t) {
123
+ const e = {};
124
+ for (const s in i) {
125
+ const r = i[s];
126
+ t.indexOf(s) > -1 && r !== null && (e[s] = r);
127
+ }
128
+ return e;
129
+ }, $ = (i) => i === "email", w = () => ({
130
+ singleTag: "hr"
131
+ }), E = () => ({
132
+ tag: "blockquote"
133
+ }), x = () => ({
134
+ tag: "ul"
135
+ }), P = (i) => ({
136
+ tag: [
137
+ "pre",
138
+ {
139
+ tag: "code",
140
+ attrs: i.attrs
90
141
  }
91
- }
92
- return h2;
93
- };
94
- const isEmailLinkType = (type) => type === "email";
95
- var defaultHtmlSerializer = {
96
- nodes: {
97
- horizontal_rule() {
98
- return {
99
- singleTag: "hr"
100
- };
101
- },
102
- blockquote() {
103
- return {
104
- tag: "blockquote"
105
- };
106
- },
107
- bullet_list() {
108
- return {
109
- tag: "ul"
110
- };
111
- },
112
- code_block(node) {
113
- return {
114
- tag: [
115
- "pre",
116
- {
117
- tag: "code",
118
- attrs: node.attrs
119
- }
120
- ]
121
- };
122
- },
123
- hard_break() {
124
- return {
125
- singleTag: "br"
126
- };
127
- },
128
- heading(node) {
129
- return {
130
- tag: `h${node.attrs.level}`
131
- };
132
- },
133
- image(node) {
134
- return {
135
- singleTag: [
136
- {
137
- tag: "img",
138
- attrs: pick(node.attrs, ["src", "alt", "title"])
139
- }
140
- ]
141
- };
142
- },
143
- list_item() {
144
- return {
145
- tag: "li"
146
- };
147
- },
148
- ordered_list() {
149
- return {
150
- tag: "ol"
151
- };
152
- },
153
- paragraph() {
154
- return {
155
- tag: "p"
156
- };
142
+ ]
143
+ }), O = () => ({
144
+ singleTag: "br"
145
+ }), S = (i) => ({
146
+ tag: `h${i.attrs.level}`
147
+ }), C = (i) => ({
148
+ singleTag: [
149
+ {
150
+ tag: "img",
151
+ attrs: b(i.attrs, ["src", "alt", "title"])
157
152
  }
158
- },
159
- marks: {
160
- bold() {
161
- return {
162
- tag: "b"
163
- };
164
- },
165
- strike() {
166
- return {
167
- tag: "strike"
168
- };
169
- },
170
- underline() {
171
- return {
172
- tag: "u"
173
- };
174
- },
175
- strong() {
176
- return {
177
- tag: "strong"
178
- };
179
- },
180
- code() {
181
- return {
182
- tag: "code"
183
- };
184
- },
185
- italic() {
186
- return {
187
- tag: "i"
188
- };
189
- },
190
- link(node) {
191
- const attrs = __spreadValues2({}, node.attrs);
192
- const { linktype = "url" } = node.attrs;
193
- if (isEmailLinkType(linktype)) {
194
- attrs.href = `mailto:${attrs.href}`;
195
- }
196
- if (attrs.anchor) {
197
- attrs.href = `${attrs.href}#${attrs.anchor}`;
198
- delete attrs.anchor;
153
+ ]
154
+ }), L = () => ({
155
+ tag: "li"
156
+ }), U = () => ({
157
+ tag: "ol"
158
+ }), H = () => ({
159
+ tag: "p"
160
+ }), A = () => ({
161
+ tag: "b"
162
+ }), I = () => ({
163
+ tag: "strike"
164
+ }), M = () => ({
165
+ tag: "u"
166
+ }), N = () => ({
167
+ tag: "strong"
168
+ }), q = () => ({
169
+ tag: "code"
170
+ }), z = () => ({
171
+ tag: "i"
172
+ }), F = (i) => {
173
+ const t = __spreadValues2({}, i.attrs), { linktype: e = "url" } = i.attrs;
174
+ return $(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
175
+ tag: [
176
+ {
177
+ tag: "a",
178
+ attrs: t
199
179
  }
200
- return {
201
- tag: [
202
- {
203
- tag: "a",
204
- attrs
205
- }
206
- ]
207
- };
208
- },
209
- styled(node) {
210
- return {
211
- tag: [
212
- {
213
- tag: "span",
214
- attrs: node.attrs
215
- }
216
- ]
217
- };
180
+ ]
181
+ };
182
+ }, V = (i) => ({
183
+ tag: [
184
+ {
185
+ tag: "span",
186
+ attrs: i.attrs
218
187
  }
219
- }
220
- };
221
- const escapeHTML = function(string) {
222
- const htmlEscapes = {
188
+ ]
189
+ }), j = {
190
+ nodes: {
191
+ horizontal_rule: w,
192
+ blockquote: E,
193
+ bullet_list: x,
194
+ code_block: P,
195
+ hard_break: O,
196
+ heading: S,
197
+ image: C,
198
+ list_item: L,
199
+ ordered_list: U,
200
+ paragraph: H
201
+ },
202
+ marks: {
203
+ bold: A,
204
+ strike: I,
205
+ underline: M,
206
+ strong: N,
207
+ code: q,
208
+ italic: z,
209
+ link: F,
210
+ styled: V
211
+ }
212
+ }, J = function(i) {
213
+ const t = {
223
214
  "&": "&amp;",
224
215
  "<": "&lt;",
225
216
  ">": "&gt;",
226
217
  '"': "&quot;",
227
218
  "'": "&#39;"
228
- };
229
- const reUnescapedHtml = /[&<>"']/g;
230
- const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
231
- return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr]) : string;
219
+ }, e = /[&<>"']/g, s = RegExp(e.source);
220
+ return i && s.test(i) ? i.replace(e, (r) => t[r]) : i;
232
221
  };
233
- class RichTextResolver {
234
- constructor(schema) {
235
- if (!schema) {
236
- schema = defaultHtmlSerializer;
237
- }
238
- this.marks = schema.marks || [];
239
- this.nodes = schema.nodes || [];
240
- }
241
- addNode(key, schema) {
242
- this.nodes[key] = schema;
243
- }
244
- addMark(key, schema) {
245
- this.marks[key] = schema;
246
- }
247
- render(data = {}) {
248
- if (data.content && Array.isArray(data.content)) {
249
- let html = "";
250
- data.content.forEach((node) => {
251
- html += this.renderNode(node);
252
- });
253
- return html;
254
- }
255
- console.warn("The render method must receive an object with a content field, which is an array");
256
- return "";
257
- }
258
- renderNode(item) {
259
- let html = [];
260
- if (item.marks) {
261
- item.marks.forEach((m) => {
262
- const mark = this.getMatchingMark(m);
263
- if (mark) {
264
- html.push(this.renderOpeningTag(mark.tag));
265
- }
266
- });
267
- }
268
- const node = this.getMatchingNode(item);
269
- if (node && node.tag) {
270
- html.push(this.renderOpeningTag(node.tag));
271
- }
272
- if (item.content) {
273
- item.content.forEach((content) => {
274
- html.push(this.renderNode(content));
275
- });
276
- } else if (item.text) {
277
- html.push(escapeHTML(item.text));
278
- } else if (node && node.singleTag) {
279
- html.push(this.renderTag(node.singleTag, " /"));
280
- } else if (node && node.html) {
281
- html.push(node.html);
282
- }
283
- if (node && node.tag) {
284
- html.push(this.renderClosingTag(node.tag));
285
- }
286
- if (item.marks) {
287
- item.marks.slice(0).reverse().forEach((m) => {
288
- const mark = this.getMatchingMark(m);
289
- if (mark) {
290
- html.push(this.renderClosingTag(mark.tag));
291
- }
292
- });
222
+ class v {
223
+ constructor(t) {
224
+ l(this, "marks");
225
+ l(this, "nodes");
226
+ t || (t = j), this.marks = t.marks || [], this.nodes = t.nodes || [];
227
+ }
228
+ addNode(t, e) {
229
+ this.nodes[t] = e;
230
+ }
231
+ addMark(t, e) {
232
+ this.marks[t] = e;
233
+ }
234
+ render(t) {
235
+ if (t && t.content && Array.isArray(t.content)) {
236
+ let e = "";
237
+ return t.content.forEach((s) => {
238
+ e += this.renderNode(s);
239
+ }), e;
293
240
  }
294
- return html.join("");
241
+ return console.warn("The render method must receive an object with a content field, which is an array"), "";
295
242
  }
296
- renderTag(tags, ending) {
297
- if (tags.constructor === String) {
298
- return `<${tags}${ending}>`;
299
- }
300
- const all = tags.map((tag) => {
301
- if (tag.constructor === String) {
302
- return `<${tag}${ending}>`;
303
- } else {
304
- let h2 = `<${tag.tag}`;
305
- if (tag.attrs) {
306
- for (let key in tag.attrs) {
307
- let value = tag.attrs[key];
308
- if (value !== null) {
309
- h2 += ` ${key}="${value}"`;
310
- }
243
+ renderNode(t) {
244
+ const e = [];
245
+ t.marks && t.marks.forEach((r) => {
246
+ const n = this.getMatchingMark(r);
247
+ n && e.push(this.renderOpeningTag(n.tag));
248
+ });
249
+ const s = this.getMatchingNode(t);
250
+ return s && s.tag && e.push(this.renderOpeningTag(s.tag)), t.content ? t.content.forEach((r) => {
251
+ e.push(this.renderNode(r));
252
+ }) : t.text ? e.push(J(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) => {
253
+ const n = this.getMatchingMark(r);
254
+ n && e.push(this.renderClosingTag(n.tag));
255
+ }), e.join("");
256
+ }
257
+ renderTag(t, e) {
258
+ return t.constructor === String ? `<${t}${e}>` : t.map((r) => {
259
+ if (r.constructor === String)
260
+ return `<${r}${e}>`;
261
+ {
262
+ let n = `<${r.tag}`;
263
+ if (r.attrs)
264
+ for (const c in r.attrs) {
265
+ const o = r.attrs[c];
266
+ o !== null && (n += ` ${c}="${o}"`);
311
267
  }
312
- }
313
- return `${h2}${ending}>`;
268
+ return `${n}${e}>`;
314
269
  }
315
- });
316
- return all.join("");
270
+ }).join("");
317
271
  }
318
- renderOpeningTag(tags) {
319
- return this.renderTag(tags, "");
272
+ renderOpeningTag(t) {
273
+ return this.renderTag(t, "");
320
274
  }
321
- renderClosingTag(tags) {
322
- if (tags.constructor === String) {
323
- return `</${tags}>`;
324
- }
325
- const all = tags.slice(0).reverse().map((tag) => {
326
- if (tag.constructor === String) {
327
- return `</${tag}>`;
328
- } else {
329
- return `</${tag.tag}>`;
330
- }
331
- });
332
- return all.join("");
275
+ renderClosingTag(t) {
276
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((s) => s.constructor === String ? `</${s}>` : `</${s.tag}>`).join("");
333
277
  }
334
- getMatchingNode(item) {
335
- if (typeof this.nodes[item.type] !== "function") {
336
- return;
337
- }
338
- return this.nodes[item.type](item);
278
+ getMatchingNode(t) {
279
+ const e = this.nodes[t.type];
280
+ if (typeof e == "function")
281
+ return e(t);
339
282
  }
340
- getMatchingMark(item) {
341
- if (typeof this.marks[item.type] !== "function") {
342
- return;
343
- }
344
- return this.marks[item.type](item);
283
+ getMatchingMark(t) {
284
+ const e = this.marks[t.type];
285
+ if (typeof e == "function")
286
+ return e(t);
345
287
  }
346
288
  }
347
- /*!
348
- * storyblok-js-client v4.5.2
349
- * Universal JavaScript SDK for Storyblok's API
350
- * (c) 2020-2022 Stobylok Team
351
- */
352
- function t(e2) {
353
- return typeof e2 == "number" && (e2 == e2 && e2 !== 1 / 0 && e2 !== -1 / 0);
354
- }
355
- function s(e2, s2, r2) {
356
- if (!t(s2))
357
- throw new TypeError("Expected `limit` to be a finite number");
358
- if (!t(r2))
359
- throw new TypeError("Expected `interval` to be a finite number");
360
- var i2 = [], n2 = [], o2 = 0, a2 = function() {
361
- o2++;
362
- var t2 = setTimeout(function() {
363
- o2--, i2.length > 0 && a2(), n2 = n2.filter(function(e3) {
364
- return e3 !== t2;
365
- });
366
- }, r2);
367
- n2.indexOf(t2) < 0 && n2.push(t2);
368
- var s3 = i2.shift();
369
- s3.resolve(e2.apply(s3.self, s3.args));
370
- }, l2 = function() {
371
- var e3 = arguments, t2 = this;
372
- return new Promise(function(r3, n3) {
373
- i2.push({ resolve: r3, reject: n3, args: e3, self: t2 }), o2 < s2 && a2();
289
+ class T {
290
+ constructor() {
291
+ l(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1);
292
+ l(this, "getOptionsPage", (t, e = 25, s = 1) => __spreadProps(__spreadValues2({}, t), {
293
+ per_page: e,
294
+ page: s
295
+ }));
296
+ l(this, "delay", (t) => new Promise((e) => setTimeout(e, t)));
297
+ l(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e));
298
+ l(this, "range", (t = 0, e = t) => {
299
+ const s = Math.abs(e - t) || 0, r = t < e ? 1 : -1;
300
+ return this.arrayFrom(s, (n, c) => c * r + t);
374
301
  });
375
- };
376
- return l2.abort = function() {
377
- n2.forEach(clearTimeout), n2 = [], i2.forEach(function(e3) {
378
- e3.reject(new throttle.AbortError());
379
- }), i2.length = 0;
380
- }, l2;
381
- }
382
- s.AbortError = function() {
383
- Error.call(this, "Throttled function aborted"), this.name = "AbortError";
384
- };
385
- const r = function(e2, t2) {
386
- if (!e2)
387
- return null;
388
- let s2 = {};
389
- for (let r2 in e2) {
390
- let i2 = e2[r2];
391
- t2.indexOf(r2) > -1 && i2 !== null && (s2[r2] = i2);
392
- }
393
- return s2;
394
- };
395
- 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) {
396
- const t2 = __spreadValues2({}, e2.attrs), { linktype: s2 = "url" } = e2.attrs;
397
- return s2 === "email" && (t2.href = `mailto:${t2.href}`), t2.anchor && (t2.href = `${t2.href}#${t2.anchor}`, delete t2.anchor), { tag: [{ tag: "a", attrs: t2 }] };
398
- }, styled: (e2) => ({ tag: [{ tag: "span", attrs: e2.attrs }] }) } };
399
- class n {
400
- constructor(e2) {
401
- e2 || (e2 = i), this.marks = e2.marks || [], this.nodes = e2.nodes || [];
402
- }
403
- addNode(e2, t2) {
404
- this.nodes[e2] = t2;
405
- }
406
- addMark(e2, t2) {
407
- this.marks[e2] = t2;
408
- }
409
- render(e2 = {}) {
410
- if (e2.content && Array.isArray(e2.content)) {
411
- let t2 = "";
412
- return e2.content.forEach((e3) => {
413
- t2 += this.renderNode(e3);
414
- }), t2;
302
+ l(this, "asyncMap", async (t, e) => Promise.all(t.map(e)));
303
+ l(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], []));
304
+ }
305
+ stringify(t, e, s) {
306
+ const r = [];
307
+ for (const n in t) {
308
+ if (!Object.prototype.hasOwnProperty.call(t, n))
309
+ continue;
310
+ const c = t[n], o = s ? "" : encodeURIComponent(n);
311
+ let a;
312
+ typeof c == "object" ? a = this.stringify(c, e ? e + encodeURIComponent("[" + o + "]") : o, Array.isArray(c)) : a = (e ? e + encodeURIComponent("[" + o + "]") : o) + "=" + encodeURIComponent(c), r.push(a);
415
313
  }
416
- return console.warn("The render method must receive an object with a content field, which is an array"), "";
314
+ return r.join("&");
417
315
  }
418
- renderNode(e2) {
419
- let t2 = [];
420
- e2.marks && e2.marks.forEach((e3) => {
421
- const s3 = this.getMatchingMark(e3);
422
- s3 && t2.push(this.renderOpeningTag(s3.tag));
316
+ }
317
+ var f = /* @__PURE__ */ ((i) => (i.GET = "get", i.DELETE = "delete", i.POST = "post", i.PUT = "put", i))(f || {});
318
+ class G {
319
+ constructor(t) {
320
+ l(this, "baseURL");
321
+ l(this, "timeout");
322
+ l(this, "headers");
323
+ l(this, "responseInterceptor");
324
+ l(this, "ejectInterceptor");
325
+ l(this, "url");
326
+ l(this, "parameters");
327
+ this.baseURL = t.baseURL, this.timeout = t.timeout ? t.timeout * 1e3 : 1e3, this.headers = t.headers || [], this.responseInterceptor = t.responseInterceptor, this.ejectInterceptor = false, this.url = "", this.parameters = {};
328
+ }
329
+ get(t, e) {
330
+ return this.url = t, this.parameters = e, this._methodHandler(f.GET);
331
+ }
332
+ post(t, e) {
333
+ return this.url = t, this.parameters = e, this._methodHandler(f.POST);
334
+ }
335
+ put(t, e) {
336
+ return this.url = t, this.parameters = e, this._methodHandler(f.PUT);
337
+ }
338
+ delete(t, e) {
339
+ return this.url = t, this.parameters = e, this._methodHandler(f.DELETE);
340
+ }
341
+ async _responseHandler(t) {
342
+ const e = [], s = {
343
+ data: {},
344
+ headers: {},
345
+ status: 0,
346
+ statusText: ""
347
+ };
348
+ await t.json().then((r) => {
349
+ s.data = r;
423
350
  });
424
- const s2 = this.getMatchingNode(e2);
425
- return s2 && s2.tag && t2.push(this.renderOpeningTag(s2.tag)), e2.content ? e2.content.forEach((e3) => {
426
- t2.push(this.renderNode(e3));
427
- }) : e2.text ? t2.push(function(e3) {
428
- const t3 = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, s3 = /[&<>"']/g, r2 = RegExp(s3.source);
429
- return e3 && r2.test(e3) ? e3.replace(s3, (e4) => t3[e4]) : e3;
430
- }(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) => {
431
- const s3 = this.getMatchingMark(e3);
432
- s3 && t2.push(this.renderClosingTag(s3.tag));
433
- }), t2.join("");
434
- }
435
- renderTag(e2, t2) {
436
- if (e2.constructor === String)
437
- return `<${e2}${t2}>`;
438
- return e2.map((e3) => {
439
- if (e3.constructor === String)
440
- return `<${e3}${t2}>`;
441
- {
442
- let s2 = `<${e3.tag}`;
443
- if (e3.attrs)
444
- for (let t3 in e3.attrs) {
445
- let r2 = e3.attrs[t3];
446
- r2 !== null && (s2 += ` ${t3}="${r2}"`);
447
- }
448
- return `${s2}${t2}>`;
449
- }
450
- }).join("");
451
- }
452
- renderOpeningTag(e2) {
453
- return this.renderTag(e2, "");
454
- }
455
- renderClosingTag(e2) {
456
- if (e2.constructor === String)
457
- return `</${e2}>`;
458
- return e2.slice(0).reverse().map((e3) => e3.constructor === String ? `</${e3}>` : `</${e3.tag}>`).join("");
351
+ for (const r of t.headers.entries())
352
+ e[r[0]] = r[1];
353
+ return s.headers = __spreadValues2({}, e), s.status = t.status, s.statusText = t.statusText, s;
354
+ }
355
+ async _methodHandler(t) {
356
+ const e = new URL(`${this.baseURL}${this.url}`);
357
+ let s = null;
358
+ if (t === "get") {
359
+ const o = new T();
360
+ e.search = o.stringify(this.parameters);
361
+ } else
362
+ s = JSON.stringify(this.parameters);
363
+ const r = new AbortController(), { signal: n } = r, c = setTimeout(() => r.abort(), this.timeout);
364
+ try {
365
+ const o = await fetch(`${e}`, {
366
+ method: t,
367
+ headers: this.headers,
368
+ body: s,
369
+ signal: n
370
+ });
371
+ clearTimeout(c);
372
+ const a = await this._responseHandler(o);
373
+ return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(a)) : this._statusHandler(a);
374
+ } catch (o) {
375
+ return o;
376
+ }
459
377
  }
460
- getMatchingNode(e2) {
461
- if (typeof this.nodes[e2.type] == "function")
462
- return this.nodes[e2.type](e2);
378
+ eject() {
379
+ this.ejectInterceptor = true;
463
380
  }
464
- getMatchingMark(e2) {
465
- if (typeof this.marks[e2.type] == "function")
466
- return this.marks[e2.type](e2);
381
+ _statusHandler(t) {
382
+ if (/20[01]/g.test(`${t.status}`))
383
+ return t;
384
+ throw {
385
+ message: new Error(t.statusText || `status: ${t.status}`),
386
+ response: t
387
+ };
467
388
  }
468
389
  }
469
- const o = (e2 = 0, t2 = e2) => {
470
- const s2 = Math.abs(t2 - e2) || 0, r2 = e2 < t2 ? 1 : -1;
471
- return ((e3 = 0, t3) => [...Array(e3)].map(t3))(s2, (t3, s3) => s3 * r2 + e2);
472
- }, a = (e2, t2, s2) => {
473
- const r2 = [];
474
- for (const i2 in e2) {
475
- if (!Object.prototype.hasOwnProperty.call(e2, i2))
476
- continue;
477
- const n2 = e2[i2], o2 = s2 ? "" : encodeURIComponent(i2);
478
- let l2;
479
- l2 = typeof n2 == "object" ? a(n2, t2 ? t2 + encodeURIComponent("[" + o2 + "]") : o2, Array.isArray(n2)) : (t2 ? t2 + encodeURIComponent("[" + o2 + "]") : o2) + "=" + encodeURIComponent(n2), r2.push(l2);
480
- }
481
- return r2.join("&");
482
- };
483
- let l = {}, c = {};
484
- class h {
485
- constructor(t2, r2) {
486
- if (!r2) {
487
- let e2 = t2.region ? `-${t2.region}` : "", s2 = t2.https === false ? "http" : "https";
488
- r2 = t2.oauthToken === void 0 ? `${s2}://api${e2}.storyblok.com/v2` : `${s2}://api${e2}.storyblok.com/v1`;
390
+ let p = {};
391
+ const d = {};
392
+ class Q {
393
+ constructor(t, e) {
394
+ l(this, "client");
395
+ l(this, "maxRetries");
396
+ l(this, "throttle");
397
+ l(this, "accessToken");
398
+ l(this, "cache");
399
+ l(this, "helpers");
400
+ l(this, "relations");
401
+ l(this, "links");
402
+ l(this, "richTextResolver");
403
+ l(this, "resolveNestedRelations");
404
+ if (!e) {
405
+ const n = t.region ? `-${t.region}` : "", c = t.https === false ? "http" : "https";
406
+ t.oauthToken ? e = `${c}://api${n}.storyblok.com/v1` : e = `${c}://api${n}.storyblok.com/v2`;
489
407
  }
490
- let i2 = Object.assign({}, t2.headers), o2 = 5;
491
- 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;
492
- }
493
- setComponentResolver(e2) {
494
- this.richTextResolver.addNode("blok", (t2) => {
495
- let s2 = "";
496
- return t2.attrs.body.forEach((t3) => {
497
- s2 += e2(t3.component, t3);
498
- }), { html: s2 };
408
+ const s = Object.assign({}, t.headers);
409
+ let r = 5;
410
+ t.oauthToken && (s.Authorization = t.oauthToken, r = 3), t.rateLimit && (r = t.rateLimit), t.richTextSchema ? this.richTextResolver = new v(t.richTextSchema) : this.richTextResolver = new v(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries, this.throttle = _(this.throttledRequest, r, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new T(), this.resolveNestedRelations = false, this.client = new G({
411
+ baseURL: e,
412
+ timeout: t.timeout || 0,
413
+ headers: s,
414
+ responseInterceptor: t.responseInterceptor
499
415
  });
500
416
  }
501
- parseParams(e2 = {}) {
502
- 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;
417
+ setComponentResolver(t) {
418
+ this.richTextResolver.addNode("blok", (e) => {
419
+ let s = "";
420
+ return e.attrs.body.forEach((r) => {
421
+ s += t(r.component, r);
422
+ }), {
423
+ html: s
424
+ };
425
+ });
503
426
  }
504
- factoryParamOptions(e2, t2 = {}) {
505
- return ((e3 = "") => e3.indexOf("/cdn/") > -1)(e2) ? this.parseParams(t2) : t2;
427
+ parseParams(t) {
428
+ 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;
506
429
  }
507
- makeRequest(e2, t2, s2, r2) {
508
- const i2 = this.factoryParamOptions(e2, ((e3 = {}, t3 = 25, s3 = 1) => __spreadProps(__spreadValues2({}, e3), { per_page: t3, page: s3 }))(t2, s2, r2));
509
- return this.cacheResponse(e2, i2);
430
+ factoryParamOptions(t, e) {
431
+ return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
510
432
  }
511
- get(e2, t2) {
512
- let s2 = `/${e2}`;
513
- const r2 = this.factoryParamOptions(s2, t2);
514
- return this.cacheResponse(s2, r2);
433
+ makeRequest(t, e, s, r) {
434
+ const n = this.factoryParamOptions(t, this.helpers.getOptionsPage(e, s, r));
435
+ return this.cacheResponse(t, n);
515
436
  }
516
- async getAll(e2, t2 = {}, s2) {
517
- const r2 = t2.per_page || 25, i2 = `/${e2}`, n2 = i2.split("/");
518
- s2 = s2 || n2[n2.length - 1];
519
- const a2 = await this.makeRequest(i2, t2, r2, 1), l2 = a2.total ? Math.ceil(a2.total / r2) : 1;
520
- 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]));
437
+ get(t, e) {
438
+ e || (e = {});
439
+ const s = `/${t}`, r = this.factoryParamOptions(s, e);
440
+ return this.cacheResponse(s, r);
521
441
  }
522
- post(e2, t2) {
523
- let s2 = `/${e2}`;
524
- return this.throttle("post", s2, t2);
442
+ async getAll(t, e, s) {
443
+ const r = (e == null ? void 0 : e.per_page) || 25, n = `/${t}`, c = n.split("/"), o = s || c[c.length - 1], a = 1, h = await this.makeRequest(n, e, r, a), u = h.total ? Math.ceil(h.total / r) : 1, g = await this.helpers.asyncMap(this.helpers.range(a, u), (k) => this.makeRequest(n, e, r, k + 1));
444
+ return this.helpers.flatMap([h, ...g], (k) => Object.values(k.data[o]));
525
445
  }
526
- put(e2, t2) {
527
- let s2 = `/${e2}`;
528
- return this.throttle("put", s2, t2);
446
+ post(t, e) {
447
+ const s = `/${t}`;
448
+ return Promise.resolve(this.throttle("post", s, e));
529
449
  }
530
- delete(e2, t2) {
531
- let s2 = `/${e2}`;
532
- return this.throttle("delete", s2, t2);
450
+ put(t, e) {
451
+ const s = `/${t}`;
452
+ return Promise.resolve(this.throttle("put", s, e));
533
453
  }
534
- getStories(e2) {
535
- return this.get("cdn/stories", e2);
454
+ delete(t, e) {
455
+ const s = `/${t}`;
456
+ return Promise.resolve(this.throttle("delete", s, e));
536
457
  }
537
- getStory(e2, t2) {
538
- return this.get(`cdn/stories/${e2}`, t2);
458
+ getStories(t) {
459
+ return this.get("cdn/stories", t);
539
460
  }
540
- setToken(e2) {
541
- this.accessToken = e2;
461
+ getStory(t, e) {
462
+ return this.get(`cdn/stories/${t}`, e);
542
463
  }
543
464
  getToken() {
544
465
  return this.accessToken;
545
466
  }
546
- _cleanCopy(e2) {
547
- return JSON.parse(JSON.stringify(e2));
548
- }
549
- _insertLinks(e2, t2) {
550
- const s2 = e2[t2];
551
- 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]));
552
- }
553
- _insertRelations(e2, t2, s2) {
554
- if (s2.indexOf(e2.component + "." + t2) > -1) {
555
- if (typeof e2[t2] == "string")
556
- this.relations[e2[t2]] && (e2[t2] = this._cleanCopy(this.relations[e2[t2]]));
557
- else if (e2[t2].constructor === Array) {
558
- let s3 = [];
559
- e2[t2].forEach((e3) => {
560
- this.relations[e3] && s3.push(this._cleanCopy(this.relations[e3]));
561
- }), e2[t2] = s3;
467
+ ejectInterceptor() {
468
+ this.client.eject();
469
+ }
470
+ _cleanCopy(t) {
471
+ return JSON.parse(JSON.stringify(t));
472
+ }
473
+ _insertLinks(t, e) {
474
+ const s = t[e];
475
+ 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]));
476
+ }
477
+ _insertRelations(t, e, s) {
478
+ if (s.indexOf(`${t.component}.${e}`) > -1) {
479
+ if (typeof t[e] == "string")
480
+ this.relations[t[e]] && (t[e] = this._cleanCopy(this.relations[t[e]]));
481
+ else if (t[e] && t[e].constructor === Array) {
482
+ const r = [];
483
+ t[e].forEach((n) => {
484
+ this.relations[n] && r.push(this._cleanCopy(this.relations[n]));
485
+ }), t[e] = r;
562
486
  }
563
487
  }
564
488
  }
565
- _insertAssetsRelations(e2, t2) {
566
- t2.forEach((t3) => {
567
- 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);
568
- });
569
- }
570
- iterateTree(e2, t2) {
571
- let s2 = (e3) => {
572
- if (e3 != null) {
573
- if (e3.constructor === Array)
574
- for (let t3 = 0; t3 < e3.length; t3++)
575
- s2(e3[t3]);
576
- else if (e3.constructor === Object) {
577
- if (e3._stopResolving)
489
+ iterateTree(t, e) {
490
+ const s = (r) => {
491
+ if (r != null) {
492
+ if (r.constructor === Array)
493
+ for (let n = 0; n < r.length; n++)
494
+ s(r[n]);
495
+ else if (r.constructor === Object) {
496
+ if (r._stopResolving)
578
497
  return;
579
- for (let r2 in e3)
580
- 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]);
498
+ for (const n in r)
499
+ (r.component && r._uid || r.type === "link") && (this._insertRelations(r, n, e), this._insertLinks(r, n)), s(r[n]);
581
500
  }
582
501
  }
583
502
  };
584
- s2(e2.content);
585
- }
586
- async resolveLinks(e2, t2) {
587
- let s2 = [];
588
- if (e2.link_uuids) {
589
- const r2 = e2.link_uuids.length;
590
- let i2 = [];
591
- const n2 = 50;
592
- for (let t3 = 0; t3 < r2; t3 += n2) {
593
- const s3 = Math.min(r2, t3 + n2);
594
- i2.push(e2.link_uuids.slice(t3, s3));
503
+ s(t.content);
504
+ }
505
+ async resolveLinks(t, e) {
506
+ let s = [];
507
+ if (t.link_uuids) {
508
+ const r = t.link_uuids.length, n = [], c = 50;
509
+ for (let o = 0; o < r; o += c) {
510
+ const a = Math.min(r, o + c);
511
+ n.push(t.link_uuids.slice(o, a));
595
512
  }
596
- for (let e3 = 0; e3 < i2.length; e3++) {
597
- (await this.getStories({ per_page: n2, language: t2.language, version: t2.version, by_uuids: i2[e3].join(",") })).data.stories.forEach((e4) => {
598
- s2.push(e4);
513
+ for (let o = 0; o < n.length; o++)
514
+ (await this.getStories({
515
+ per_page: c,
516
+ language: e.language,
517
+ version: e.version,
518
+ by_uuids: n[o].join(",")
519
+ })).data.stories.forEach((h) => {
520
+ s.push(h);
599
521
  });
600
- }
601
522
  } else
602
- s2 = e2.links;
603
- s2.forEach((e3) => {
604
- this.links[e3.uuid] = __spreadProps(__spreadValues2({}, e3), { _stopResolving: true });
523
+ s = t.links;
524
+ s.forEach((r) => {
525
+ this.links[r.uuid] = __spreadProps(__spreadValues2({}, r), { _stopResolving: true });
605
526
  });
606
527
  }
607
- async resolveRelations(e2, t2) {
608
- let s2 = [];
609
- if (e2.rel_uuids) {
610
- const r2 = e2.rel_uuids.length;
611
- let i2 = [];
612
- const n2 = 50;
613
- for (let t3 = 0; t3 < r2; t3 += n2) {
614
- const s3 = Math.min(r2, t3 + n2);
615
- i2.push(e2.rel_uuids.slice(t3, s3));
528
+ async resolveRelations(t, e) {
529
+ let s = [];
530
+ if (t.rel_uuids) {
531
+ const r = t.rel_uuids.length, n = [], c = 50;
532
+ for (let o = 0; o < r; o += c) {
533
+ const a = Math.min(r, o + c);
534
+ n.push(t.rel_uuids.slice(o, a));
616
535
  }
617
- for (let e3 = 0; e3 < i2.length; e3++) {
618
- (await this.getStories({ per_page: n2, language: t2.language, version: t2.version, by_uuids: i2[e3].join(",") })).data.stories.forEach((e4) => {
619
- s2.push(e4);
536
+ for (let o = 0; o < n.length; o++)
537
+ (await this.getStories({
538
+ per_page: c,
539
+ language: e.language,
540
+ version: e.version,
541
+ by_uuids: n[o].join(",")
542
+ })).data.stories.forEach((h) => {
543
+ s.push(h);
620
544
  });
621
- }
622
545
  } else
623
- s2 = e2.rels;
624
- s2.forEach((e3) => {
625
- this.relations[e3.uuid] = __spreadProps(__spreadValues2({}, e3), { _stopResolving: true });
546
+ s = t.rels;
547
+ s && s.length > 0 && s.forEach((r) => {
548
+ this.relations[r.uuid] = __spreadProps(__spreadValues2({}, r), { _stopResolving: true });
626
549
  });
627
550
  }
628
- async resolveStories(e2, t2) {
629
- let s2 = [];
630
- 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)
631
- for (const e3 in this.relations)
632
- this.iterateTree(this.relations[e3], s2);
633
- e2.story ? this.iterateTree(e2.story, s2) : e2.stories.forEach((e3) => {
634
- this.iterateTree(e3, s2);
551
+ async resolveStories(t, e) {
552
+ var r, n;
553
+ let s = [];
554
+ if (typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (s = e.resolve_relations.split(","), await this.resolveRelations(t, e)), e.resolve_links && ["1", "story", "url"].indexOf(e.resolve_links) > -1 && (((r = t.links) == null ? void 0 : r.length) || ((n = t.link_uuids) == null ? void 0 : n.length)) && await this.resolveLinks(t, e), this.resolveNestedRelations)
555
+ for (const c in this.relations)
556
+ this.iterateTree(this.relations[c], s);
557
+ t.story ? this.iterateTree(t.story, s) : t.stories.forEach((c) => {
558
+ this.iterateTree(c, s);
635
559
  });
636
560
  }
637
- resolveAssetsRelations(e2) {
638
- const { assets: t2, stories: s2, story: r2 } = e2;
639
- if (s2)
640
- for (const e3 of s2)
641
- this.iterateTree(e3, t2);
642
- else {
643
- if (!r2)
644
- return e2;
645
- this.iterateTree(r2, t2);
646
- }
647
- }
648
- cacheResponse(e2, t2, s2) {
649
- return s2 === void 0 && (s2 = 0), new Promise(async (r2, i2) => {
650
- let n2 = a({ url: e2, params: t2 }), o2 = this.cacheProvider();
651
- if (this.cache.clear === "auto" && t2.version === "draft" && await this.flushCache(), t2.version === "published" && e2 != "/cdn/spaces/me") {
652
- const e3 = await o2.get(n2);
653
- if (e3)
654
- return r2(e3);
561
+ cacheResponse(t, e, s) {
562
+ return new Promise((r, n) => {
563
+ const c = this.helpers.stringify({ url: t, params: e }), o = this.cacheProvider();
564
+ if (this.cache.clear === "auto" && e.version === "draft" && this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
565
+ const a = o.get(c);
566
+ if (a)
567
+ return r(a);
655
568
  }
656
569
  try {
657
- let s3 = await this.throttle("get", e2, { params: t2, paramsSerializer: (e3) => a(e3) }), l3 = { data: s3.data, headers: s3.headers };
658
- if (l3.data.assets && l3.data.assets.length && this.resolveAssetsRelations(l3.data), l3 = Object.assign({}, l3, { perPage: s3.headers["per-page"] ? parseInt(s3.headers["per-page"]) : 0, total: s3.headers["per-page"] ? parseInt(s3.headers.total) : 0 }), s3.status != 200)
659
- return i2(s3);
660
- (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);
661
- } catch (n3) {
662
- if (n3.response && n3.response.status === 429 && (s2 += 1) < this.maxRetries)
663
- 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);
664
- i2(n3);
570
+ (async () => {
571
+ var u;
572
+ const a = await this.throttle("get", t, e);
573
+ let h = { data: a.data, headers: a.headers };
574
+ if ((u = a.headers) != null && u["per-page"] && (h = Object.assign({}, h, {
575
+ perPage: a.headers["per-page"] ? parseInt(a.headers["per-page"]) : 0,
576
+ total: a.headers["per-page"] ? parseInt(a.headers.total) : 0
577
+ })), a.status != 200)
578
+ return n(a);
579
+ (h.data.story || h.data.stories) && await this.resolveStories(h.data, e), e.version === "published" && t != "/cdn/spaces/me" && o.set(c, h), h.data.cv && e.token && (e.version == "draft" && d[e.token] != h.data.cv && this.flushCache(), d[e.token] = h.data.cv), r(h);
580
+ })();
581
+ } catch {
665
582
  }
666
- var l2;
667
583
  });
668
584
  }
669
- throttledRequest(e2, t2, s2) {
670
- return this.client[e2](t2, s2);
585
+ throttledRequest(t, e, s) {
586
+ return this.client[t](e, s);
671
587
  }
672
588
  cacheVersions() {
673
- return c;
589
+ return d;
674
590
  }
675
591
  cacheVersion() {
676
- return c[this.accessToken];
592
+ return d[this.accessToken];
677
593
  }
678
- setCacheVersion(e2) {
679
- this.accessToken && (c[this.accessToken] = e2);
594
+ setCacheVersion(t) {
595
+ this.accessToken && (d[this.accessToken] = t);
680
596
  }
681
597
  cacheProvider() {
682
- return this.cache.type === "memory" ? { get: (e2) => l[e2], getAll: () => l, set(e2, t2) {
683
- l[e2] = t2;
684
- }, flush() {
685
- l = {};
686
- } } : { get() {
687
- }, getAll() {
688
- }, set() {
689
- }, flush() {
690
- } };
691
- }
692
- async flushCache() {
693
- return await this.cacheProvider().flush(), this;
598
+ switch (this.cache.type) {
599
+ case "memory":
600
+ return {
601
+ get(t) {
602
+ return p[t];
603
+ },
604
+ getAll() {
605
+ return p;
606
+ },
607
+ set(t, e) {
608
+ p[t] = e;
609
+ },
610
+ flush() {
611
+ p = {};
612
+ }
613
+ };
614
+ default:
615
+ return {
616
+ get() {
617
+ },
618
+ getAll() {
619
+ },
620
+ set() {
621
+ },
622
+ flush() {
623
+ }
624
+ };
625
+ }
626
+ }
627
+ flushCache() {
628
+ return this.cacheProvider().flush(), this;
694
629
  }
695
630
  }
696
631
  const apiFactory = (options = {}) => {
@@ -699,7 +634,7 @@ const apiFactory = (options = {}) => {
699
634
  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");
700
635
  return;
701
636
  }
702
- const storyblokApi = new h(apiOptions);
637
+ const storyblokApi = new Q(apiOptions);
703
638
  return { storyblokApi };
704
639
  };
705
640
  var editable = (blok) => {
@@ -754,7 +689,7 @@ const storyblokInit$1 = (pluginOptions = {}) => {
754
689
  if (bridge !== false) {
755
690
  loadBridge(bridgeLatest);
756
691
  }
757
- richTextResolver = new RichTextResolver(richText.schema);
692
+ richTextResolver = new v(richText.schema);
758
693
  if (richText.resolver) {
759
694
  setComponentResolver(richTextResolver, richText.resolver);
760
695
  }
@@ -786,7 +721,7 @@ const renderRichText = (data, options, resolverInstance) => {
786
721
  return "";
787
722
  }
788
723
  if (options) {
789
- localResolver = new RichTextResolver(options.schema);
724
+ localResolver = new v(options.schema);
790
725
  if (options.resolver) {
791
726
  setComponentResolver(localResolver, options.resolver);
792
727
  }
@@ -815,24 +750,28 @@ const useStoryblok = (slug, apiOptions = {}, bridgeOptions = {}) => {
815
750
  console.error("You can't use useStoryblok if you're not loading apiPlugin.");
816
751
  return null;
817
752
  }
818
- useStoryblokBridge(story.id, (story2) => setStory(story2), bridgeOptions);
753
+ const isBridgeEnable = typeof window !== "undefined" && typeof window.storyblokRegisterEvent !== "undefined";
819
754
  useEffect(() => {
820
- async function fetchData() {
755
+ async function initStory() {
821
756
  const { data } = await storyblokApiInstance.get(`cdn/stories/${slug}`, apiOptions);
822
757
  setStory(data.story);
758
+ if (isBridgeEnable && data.story.id) {
759
+ useStoryblokBridge(data.story.id, (story2) => setStory(story2), bridgeOptions);
760
+ }
823
761
  }
824
- fetchData();
762
+ initStory();
825
763
  }, [slug]);
826
764
  return story;
827
765
  };
828
- const useStoryblokState = (initialStory = {}, bridgeOptions = {}, preview = true) => {
766
+ const useStoryblokState = (initialStory = null, bridgeOptions = {}) => {
829
767
  let [story, setStory] = useState(initialStory);
830
- if (!preview) {
768
+ const isBridgeEnable = typeof window !== "undefined" && typeof window.storyblokRegisterEvent !== "undefined";
769
+ if (!isBridgeEnable || !initialStory) {
831
770
  return initialStory;
832
771
  }
833
772
  useEffect(() => {
834
- useStoryblokBridge(story.id, (newStory) => setStory(newStory), bridgeOptions);
835
773
  setStory(initialStory);
774
+ useStoryblokBridge(story.id, (newStory) => setStory(newStory), bridgeOptions);
836
775
  }, [initialStory]);
837
776
  return story;
838
777
  };
@@ -856,4 +795,4 @@ const storyblokInit = (pluginOptions = {}) => {
856
795
  storyblokApiInstance = storyblokApi;
857
796
  componentsMap = pluginOptions.components;
858
797
  };
859
- export { defaultHtmlSerializer as RichTextSchema, StoryblokComponent, apiFactory as apiPlugin, getComponent, useStoryblokApi as getStoryblokApi, useStoryblokBridge as registerStoryblokBridge, renderRichText, editable as storyblokEditable, storyblokInit, useStoryblok, useStoryblokApi, useStoryblokBridge, useStoryblokState };
798
+ export { v as RichTextResolver, j as RichTextSchema, StoryblokComponent, apiFactory as apiPlugin, getComponent, useStoryblokApi as getStoryblokApi, useStoryblokBridge as registerStoryblokBridge, renderRichText, editable as storyblokEditable, storyblokInit, useStoryblok, useStoryblokApi, useStoryblokBridge, useStoryblokState };