@storyblok/react 2.4.7 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/bridge-loader.mjs +4 -4
- package/dist/client.js +1 -1
- package/dist/client.mjs +15 -14
- package/dist/index.js +1 -1
- package/dist/index.mjs +18 -18
- package/dist/index2.mjs +6 -6
- package/dist/storyblok-js.js +2 -2
- package/dist/storyblok-js.mjs +209 -202
- package/dist/types/common/index.d.ts +2 -2
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -94,6 +94,8 @@ Possible values:
|
|
|
94
94
|
|
|
95
95
|
- `eu` (default): For spaces created in the EU
|
|
96
96
|
- `us`: For spaces created in the US
|
|
97
|
+
- `ap`: For spaces created in Australia
|
|
98
|
+
- `ca`: For spaces created in Canada
|
|
97
99
|
- `cn`: For spaces created in China
|
|
98
100
|
|
|
99
101
|
Full example for a space created in the US:
|
|
@@ -280,7 +282,7 @@ export async function fetchData() {
|
|
|
280
282
|
```js
|
|
281
283
|
const bridgeOptions = { resolveRelations: ["article.author"] };
|
|
282
284
|
|
|
283
|
-
<StoryblokStory story={data.story} bridgeOptions={bridgeOptions}
|
|
285
|
+
<StoryblokStory story={data.story} bridgeOptions={bridgeOptions} />;
|
|
284
286
|
```
|
|
285
287
|
|
|
286
288
|
> Note: To use this approach (with `getStoryblokApi`), you need to include the `apiPlugin` module when calling `storyblokInit` function. If you don't use `apiPlugin`, you can use your preferred method or function to fetch your data.
|
|
@@ -560,7 +562,7 @@ import cloneDeep from "clone-deep";
|
|
|
560
562
|
|
|
561
563
|
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
|
|
562
564
|
// ... and edit the nodes and marks, or add your own.
|
|
563
|
-
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/
|
|
565
|
+
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/main/src/schema.ts
|
|
564
566
|
|
|
565
567
|
storyblokInit({
|
|
566
568
|
accessToken: "<your-token>",
|
|
@@ -625,5 +627,5 @@ By default, `@storyblok/react` returns an empty `<div>` if a component is not im
|
|
|
625
627
|
|
|
626
628
|
### Contributing
|
|
627
629
|
|
|
628
|
-
Please see our [contributing guidelines](https://github.com/storyblok/.github/blob/
|
|
630
|
+
Please see our [contributing guidelines](https://github.com/storyblok/.github/blob/master/contributing.md) and our [code of conduct](https://www.storyblok.com/trust-center#code-of-conduct?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-react).
|
|
629
631
|
This project use [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for generate new versions by using commit messages and we use the Angular Convention to naming the commits. Check [this question](https://semantic-release.gitbook.io/semantic-release/support/faq#how-can-i-change-the-type-of-commits-that-trigger-a-release) about it in semantic-release FAQ.
|
package/dist/bridge-loader.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import
|
|
2
|
+
import o from "react";
|
|
3
3
|
import { loadStoryblokBridge as r } from "./storyblok-js.mjs";
|
|
4
|
-
const t = async (
|
|
5
|
-
await r(), new window.StoryblokBridge(
|
|
4
|
+
const t = async (e) => {
|
|
5
|
+
await r(), new window.StoryblokBridge(e).on(["published", "change"], () => {
|
|
6
6
|
window.location.reload();
|
|
7
7
|
});
|
|
8
|
-
}, i = ({ options:
|
|
8
|
+
}, i = ({ options: e }) => (t(e), /* @__PURE__ */ o.createElement(o.Fragment, null));
|
|
9
9
|
export {
|
|
10
10
|
i as default
|
|
11
11
|
};
|
package/dist/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),c=require("./storyblok-js.js"),f=(e=null,n={})=>{let[t,o]=s.useState(e);const r=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u";return s.useEffect(()=>{if(!r||!e)return;const u=t.internalId||t.id;o(e),c.registerStoryblokBridge(u,d=>o(d),n)},[e,r,t]),!r||!e?e:t};exports.useStoryblokState=f;
|
package/dist/client.mjs
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { registerStoryblokBridge as
|
|
3
|
-
const
|
|
4
|
-
let [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
r
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
o
|
|
1
|
+
import { useState as f, useEffect as u } from "react";
|
|
2
|
+
import { registerStoryblokBridge as g } from "./storyblok-js.mjs";
|
|
3
|
+
const c = (e = null, s = {}) => {
|
|
4
|
+
let [r, o] = f(e);
|
|
5
|
+
const t = typeof window < "u" && typeof window.storyblokRegisterEvent < "u";
|
|
6
|
+
return u(() => {
|
|
7
|
+
if (!t || !e)
|
|
8
|
+
return;
|
|
9
|
+
const n = r.internalId || r.id;
|
|
10
|
+
o(e), g(
|
|
11
|
+
n,
|
|
12
|
+
(d) => o(d),
|
|
13
|
+
s
|
|
13
14
|
);
|
|
14
|
-
}, [e]), t;
|
|
15
|
+
}, [e, t, r]), !t || !e ? e : r;
|
|
15
16
|
};
|
|
16
17
|
export {
|
|
17
|
-
|
|
18
|
+
c as useStoryblokState
|
|
18
19
|
};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),c=require("./client.js"),S=require("./storyblok-component.js"),d=(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),e=require("./storyblok-js.js"),o=require("./index2.js"),c=require("./client.js"),S=require("./storyblok-component.js"),d=(s,r={},t={})=>{let[a,i]=y.useState({});const u=typeof window<"u"&&typeof window.storyblokRegisterEvent<"u",n=o.useStoryblokApi();return y.useEffect(()=>{if(!n){console.error("You can't use useStoryblok if you're not loading apiPlugin.");return}async function b(){const{data:l}=await n.get(`cdn/stories/${s}`,r);i(l.story),u&&l.story.id&&e.registerStoryblokBridge(l.story.id,k=>i(k),t)}b()},[s,JSON.stringify(r),n]),n?(t.resolveRelations=t.resolveRelations??r.resolve_relations,t.resolveLinks=t.resolveLinks??r.resolve_links,a):null};exports.RichTextResolver=e.RichTextResolver;exports.RichTextSchema=e.RichTextSchema;exports.apiPlugin=e.apiPlugin;exports.loadStoryblokBridge=e.loadStoryblokBridge;exports.registerStoryblokBridge=e.registerStoryblokBridge;exports.renderRichText=e.renderRichText;exports.storyblokEditable=e.storyblokEditable;exports.useStoryblokBridge=e.registerStoryblokBridge;exports.getComponent=o.getComponent;exports.getCustomFallbackComponent=o.getCustomFallbackComponent;exports.getEnableFallbackComponent=o.getEnableFallbackComponent;exports.getStoryblokApi=o.useStoryblokApi;exports.setComponents=o.setComponents;exports.storyblokInit=o.storyblokInit;exports.useStoryblokApi=o.useStoryblokApi;exports.useStoryblokState=c.useStoryblokState;exports.StoryblokComponent=S;exports.useStoryblok=d;
|
package/dist/index.mjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { useState as f, useEffect as
|
|
2
|
-
import { registerStoryblokBridge as
|
|
1
|
+
import { useState as f, useEffect as u } from "react";
|
|
2
|
+
import { registerStoryblokBridge as k } from "./storyblok-js.mjs";
|
|
3
3
|
import { RichTextResolver as v, RichTextSchema as x, apiPlugin as R, loadStoryblokBridge as C, renderRichText as w, storyblokEditable as B } from "./storyblok-js.mjs";
|
|
4
4
|
import { useStoryblokApi as c } from "./index2.mjs";
|
|
5
5
|
import { getComponent as h, getCustomFallbackComponent as A, getEnableFallbackComponent as T, setComponents as F, storyblokInit as I } from "./index2.mjs";
|
|
6
6
|
import { useStoryblokState as P } from "./client.mjs";
|
|
7
7
|
import { default as J } from "./storyblok-component.mjs";
|
|
8
|
-
const b = (
|
|
9
|
-
const s = c();
|
|
10
|
-
if (!s)
|
|
11
|
-
return console.error(
|
|
12
|
-
"You can't use useStoryblok if you're not loading apiPlugin."
|
|
13
|
-
), null;
|
|
8
|
+
const b = (s, e = {}, o = {}) => {
|
|
14
9
|
let [l, n] = f({});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
const i = typeof window < "u" && typeof window.storyblokRegisterEvent < "u", t = c();
|
|
11
|
+
return u(() => {
|
|
12
|
+
if (!t) {
|
|
13
|
+
console.error(
|
|
14
|
+
"You can't use useStoryblok if you're not loading apiPlugin."
|
|
15
|
+
);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
18
|
async function a() {
|
|
19
|
-
const { data:
|
|
20
|
-
`cdn/stories/${
|
|
19
|
+
const { data: r } = await t.get(
|
|
20
|
+
`cdn/stories/${s}`,
|
|
21
21
|
e
|
|
22
22
|
);
|
|
23
|
-
n(
|
|
24
|
-
|
|
23
|
+
n(r.story), i && r.story.id && k(
|
|
24
|
+
r.story.id,
|
|
25
25
|
(y) => n(y),
|
|
26
26
|
o
|
|
27
27
|
);
|
|
28
28
|
}
|
|
29
29
|
a();
|
|
30
|
-
}, [
|
|
30
|
+
}, [s, JSON.stringify(e), t]), t ? (o.resolveRelations = o.resolveRelations ?? e.resolve_relations, o.resolveLinks = o.resolveLinks ?? e.resolve_links, l) : null;
|
|
31
31
|
};
|
|
32
32
|
export {
|
|
33
33
|
v as RichTextResolver,
|
|
@@ -39,13 +39,13 @@ export {
|
|
|
39
39
|
T as getEnableFallbackComponent,
|
|
40
40
|
c as getStoryblokApi,
|
|
41
41
|
C as loadStoryblokBridge,
|
|
42
|
-
|
|
42
|
+
k as registerStoryblokBridge,
|
|
43
43
|
w as renderRichText,
|
|
44
44
|
F as setComponents,
|
|
45
45
|
B as storyblokEditable,
|
|
46
46
|
I as storyblokInit,
|
|
47
47
|
b as useStoryblok,
|
|
48
48
|
c as useStoryblokApi,
|
|
49
|
-
|
|
49
|
+
k as useStoryblokBridge,
|
|
50
50
|
P as useStoryblokState
|
|
51
51
|
};
|
package/dist/index2.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { storyblokInit as s } from "./storyblok-js.mjs";
|
|
2
|
-
import { RichTextResolver as
|
|
2
|
+
import { RichTextResolver as g, RichTextSchema as C, apiPlugin as d, loadStoryblokBridge as f, registerStoryblokBridge as S, renderRichText as x, storyblokEditable as F, registerStoryblokBridge as A } from "./storyblok-js.mjs";
|
|
3
3
|
import { default as B } from "./storyblok-component.mjs";
|
|
4
|
-
let
|
|
5
|
-
const b = () => (
|
|
4
|
+
let t = null, e = {}, r = !1, l = null;
|
|
5
|
+
const b = () => (t || console.error(
|
|
6
6
|
"You can't use getStoryblokApi if you're not loading apiPlugin."
|
|
7
|
-
),
|
|
7
|
+
), t), c = (o) => (e = o, e), i = (o) => e[o] ? e[o] : (console.error(`Component ${o} doesn't exist.`), !1), k = () => r, m = () => l, p = (o = {}) => {
|
|
8
8
|
const { storyblokApi: n } = s(o);
|
|
9
|
-
|
|
9
|
+
t = n, e = o.components, r = o.enableFallbackComponent, l = o.customFallbackComponent;
|
|
10
10
|
};
|
|
11
11
|
export {
|
|
12
|
-
|
|
12
|
+
g as RichTextResolver,
|
|
13
13
|
C as RichTextSchema,
|
|
14
14
|
B as StoryblokComponent,
|
|
15
15
|
d as apiPlugin,
|
package/dist/storyblok-js.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let S=!1;const E=[],C=o=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}S?r():E.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=o,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{E.forEach(i=>i()),S=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var N=Object.defineProperty,P=(o,e,t)=>e in o?N(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e,t)=>(P(o,typeof e!="symbol"?e+"":e,t),t);function x(o){return!(o!==o||o===1/0||o===-1/0)}function A(o,e,t){if(!x(e))throw new TypeError("Expected `limit` to be a finite number");if(!x(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],i=0;const n=function(){i++;const a=setTimeout(function(){i--,s.length>0&&n(),r=r.filter(function(u){return u!==a})},t);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(o.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(u,d){s.push({resolve:u,reject:d,args:a,self:l}),i<e&&n()})};return c.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},c}class b{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(i,n)=>n*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),h(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,i=>t[i]):e})}stringify(e,t,s){const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i],c=s?"":encodeURIComponent(i);let a;typeof n=="object"?a=this.stringify(n,t?t+encodeURIComponent("["+c+"]"):c,Array.isArray(n)):a=(t?t+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",i="api-ap.storyblok.com",n="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return i;case"ca":return n;default:return t}}}const L=function(o,e){const t={};for(const s in o){const r=o[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},M=o=>o==="email",D=()=>({singleTag:"hr"}),B=()=>({tag:"blockquote"}),H=()=>({tag:"ul"}),z=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),F=()=>({singleTag:"br"}),q=o=>({tag:`h${o.attrs.level}`}),V=o=>({singleTag:[{tag:"img",attrs:L(o.attrs,["src","alt","title"])}]}),G=()=>({tag:"li"}),J=()=>({tag:"ol"}),Y=()=>({tag:"p"}),K=o=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":o.attrs.name,emoji:o.attrs.emoji}}]}),W=()=>({tag:"b"}),X=()=>({tag:"s"}),Z=()=>({tag:"u"}),Q=()=>({tag:"strong"}),ee=()=>({tag:"code"}),te=()=>({tag:"i"}),se=o=>{if(!o.attrs)return{tag:""};const e=new b().escapeHTML,t={...o.attrs},{linktype:s="url"}=o.attrs;if(delete t.linktype,t.href&&(t.href=e(o.attrs.href||"")),M(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},re=o=>({tag:[{tag:"span",attrs:o.attrs}]}),ie=()=>({tag:"sub"}),ne=()=>({tag:"sup"}),oe=o=>({tag:[{tag:"span",attrs:o.attrs}]}),ae=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${o.attrs.color};`}}]}:{tag:""}},le=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${o.attrs.color}`}}]}:{tag:""}},j={nodes:{horizontal_rule:D,blockquote:B,bullet_list:H,code_block:z,hard_break:F,heading:q,image:V,list_item:G,ordered_list:J,paragraph:Y,emoji:K},marks:{bold:W,strike:X,underline:Z,strong:Q,code:ee,italic:te,link:se,styled:re,subscript:ie,superscript:ne,anchor:oe,highlight:ae,textStyle:le}},ce=function(o){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class f{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=j),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
|
|
2
2
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
3
3
|
ISbRichtext:
|
|
4
4
|
content?: ISbRichtext[]
|
|
@@ -21,4 +21,4 @@
|
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
23
|
type: 'doc'
|
|
24
|
-
}`),""}optimizeImages(e,t){let s=0,r=0,o="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const g={srcset:(l=t.srcset)==null?void 0:l.map(d=>{if(typeof d=="number")return`//${p}/m/${d}x0${n} ${d}w`;if(typeof d=="object"&&d.length===2){let v=0,R=0;return typeof d[0]=="number"&&(v=d[0]),typeof d[1]=="number"&&(R=d[1]),`//${p}/m/${v}x${R}${n} ${v}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(d=>d).join(", ")};let k="";return g.srcset&&(k+=`srcset="${g.srcset}" `),g.sizes&&(k+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${k.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ce(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const o in s.attrs){const n=s.attrs[o];n!==null&&(r+=` ${o}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class he{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new b;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:n}=o;let c;this.timeout&&(c=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise(s=>{if(t.test(`${e.status}`))return s(e);const r={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};throw new Error(JSON.stringify(r))})}}const E="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"5.14.2"};let y={};const f={};class ue{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const n=new b().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const n in e.headers)r.set(n,e.headers[n]);r.has(E)||(r.set(E,w.defaultAgentName),r.set(w.defaultAgentVersion,w.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new m(e.richTextSchema):this.richTextResolver=new m,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=M(this.throttledRequest,o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new b,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.client=new he({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=f[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,n=o.split("/"),c=s||n[n.length-1],a=1,l=await this.makeRequest(o,t,r,a),u=l.total?Math.ceil(l.total/r):1,p=await this.helpers.asyncMap(this.helpers.range(a,u),g=>this.makeRequest(o,t,r,g+1));return this.helpers.flatMap([l,...p],g=>Object.values(g.data[c]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}_insertRelations(e,t,s,r){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[r][e[t]]&&(e[t]=this._cleanCopy(this.relations[r][e[t]]));else if(e[t]&&e[t].constructor===Array){const o=[];e[t].forEach(n=>{this.relations[r][n]&&o.push(this._cleanCopy(this.relations[r][n]))}),e[t]=o}}}iterateTree(e,t,s){const r=o=>{if(o!=null){if(o.constructor===Array)for(let n=0;n<o.length;n++)r(o[n]);else if(o.constructor===Object){if(o._stopResolving)return;for(const n in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,n,t,s),this._insertLinks(o,n,s)),r(o[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let n=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),o=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const n=await o.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),u.data.story||u.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&f[t.token]!=u.data.cv&&await this.flushCache(),f[t.token]=u.data.cv),n(u)}catch(l){if(l.response&&l.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l.message)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(e){this.accessToken&&(f[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(y[e])},getAll(){return Promise.resolve(y)},set(e,t){return y[e]=t,Promise.resolve(void 0)},flush(){return y={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const pe=(i={})=>{const{apiOptions:e}=i;if(!e.accessToken){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");return}return{storyblokApi:new ue(e)}},de=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}};let $,T="https://app.storyblok.com/f/storyblok-v2-latest.js";const I=(i,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===i;if(!(!r||!o)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],n=>{n.action==="input"&&n.story.id===i?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===i&&window.location.reload()})})}},ge=(i={})=>{var e,t;const{bridge:s,accessToken:r,use:o=[],apiOptions:n={},richText:c={},bridgeUrl:a}=i;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let u={};o.forEach(g=>{u={...u,...g(l)}}),a&&(T=a);const p=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&p&&S(T),$=new m(c.schema),c.resolver&&O($,c.resolver),u},O=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},C=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),fe=(i,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return C(i)?"":(e&&(s=new m(e.schema),e.resolver&&O(s,e.resolver)),s.render(i))},me=()=>S(T);exports.RichTextResolver=m;exports.RichTextSchema=P;exports.apiPlugin=pe;exports.isRichTextEmpty=C;exports.loadStoryblokBridge=me;exports.registerStoryblokBridge=I;exports.renderRichText=fe;exports.storyblokEditable=de;exports.storyblokInit=ge;exports.useStoryblokBridge=I;
|
|
24
|
+
}`),""}optimizeImages(e,t){let s=0,r=0,i="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(i+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(i+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(i+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(i+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),i.length>0&&(e=e.replace(/<img/g,`<img ${i.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const g={srcset:(l=t.srcset)==null?void 0:l.map(p=>{if(typeof p=="number")return`//${d}/m/${p}x0${n} ${p}w`;if(typeof p=="object"&&p.length===2){let _=0,T=0;return typeof p[0]=="number"&&(_=p[0]),typeof p[1]=="number"&&(T=p[1]),`//${d}/m/${_}x${T}${n} ${_}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(p=>p).join(", ")};let v="";return g.srcset&&(v+=`srcset="${g.srcset}" `),g.sizes&&(v+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${v.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderOpeningTag(i.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ce(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderClosingTag(i.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const i in s.attrs){const n=s.attrs[i];n!==null&&(r+=` ${i}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class he{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new b;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const a=await fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(i)})}}var ue={NVM_INC:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/include/node",TERM_PROGRAM:"iTerm.app",NODE:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node",NVM_CD_FLAGS:"-q",INIT_CWD:"/Users/lisilinhart/Code/storyblok-js-client",SHELL:"/bin/zsh",TERM:"xterm-256color",TMPDIR:"/var/folders/9v/t3hq3s9n2rj6_x9jlsjjq95w0000gn/T/",npm_config_metrics_registry:"https://registry.npmjs.org/",npm_config_global_prefix:"/Users/lisilinhart/.nvm/versions/node/v18.16.0",TERM_PROGRAM_VERSION:"3.4.20",TERM_SESSION_ID:"w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF",COLOR:"0",npm_config_noproxy:"",ZSH:"/Users/lisilinhart/.oh-my-zsh",npm_config_local_prefix:"/Users/lisilinhart/Code/storyblok-js-client",USER:"lisilinhart",NVM_DIR:"/Users/lisilinhart/.nvm",COMMAND_MODE:"unix2003",npm_config_globalconfig:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/etc/npmrc",SSH_AUTH_SOCK:"/private/tmp/com.apple.launchd.oUounWp9qr/Listeners",__CF_USER_TEXT_ENCODING:"0x1F5:0x0:0x5C",npm_execpath:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/bin/npm-cli.js",PAGER:"less",npm_package_integrity:"null",LSCOLORS:"Gxfxcxdxbxegedabagacad",PATH:"/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/sbin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.yarn/bin:/Users/lisilinhart/.config/yarn/global/node_modules/.bin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin:/Users/lisilinhart/bin:/usr/local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/lisilinhart/.cargo/bin",RUBY_CONFIGURE_OPTS:"--with-openssl-dir=/usr/local/opt/openssl@1.1",LaunchInstanceID:"9D2A03D3-35CC-4CDD-810D-0D5C25991BBB",_:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node",npm_package_json:"/Users/lisilinhart/Code/storyblok-js-client/package.json",__CFBundleIdentifier:"com.googlecode.iterm2",npm_config_init_module:"/Users/lisilinhart/.npm-init.js",npm_config_userconfig:"/Users/lisilinhart/.npmrc",PWD:"/Users/lisilinhart/Code/storyblok-js-client",npm_command:"run-script",P9K_SSH:"0",EDITOR:"vi",npm_lifecycle_event:"build",LANG:"de_AT.UTF-8",P9K_TTY:"old",npm_package_name:"storyblok-js-client",ITERM_PROFILE:"Default",XPC_FLAGS:"0x0",RBENV_SHELL:"zsh",npm_config_node_gyp:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js",XPC_SERVICE_NAME:"0",npm_package_version:"6.4.1",COLORFGBG:"7;0",HOME:"/Users/lisilinhart",SHLVL:"3",npm_package_resolved:"/Users/lisilinhart/Code/storyblok-js-client",LC_TERMINAL_VERSION:"3.4.20",ITERM_SESSION_ID:"w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF",LOGNAME:"lisilinhart",LESS:"-R",npm_config_cache:"/Users/lisilinhart/.npm",npm_lifecycle_script:"node vite.build.mjs && tsc",NVM_BIN:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin",npm_config_user_agent:"npm/9.5.1 node/v18.16.0 darwin x64 workspaces/false",LC_TERMINAL:"iTerm2",SECURITYSESSIONID:"186a1",COLORTERM:"truecolor",npm_config_prefix:"/Users/lisilinhart/.nvm/versions/node/v18.16.0",npm_node_execpath:"/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node",NODE_ENV:"production"};const $="SB-Agent",k={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:ue.npm_package_version};let y={};const m={};class de{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),h(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new b().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const n in e.headers)r.set(n,e.headers[n]);r.has($)||(r.set($,k.defaultAgentName),r.set(k.defaultAgentVersion,k.packageVersion));let i=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),i=3),e.rateLimit&&(i=e.rateLimit),e.richTextSchema?this.richTextResolver=new f(e.richTextSchema):this.richTextResolver=new f,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=A(this.throttledRequest,i,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new b,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new he({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=m[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,i)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,i=`/${e}`,n=i.split("/"),c=s||n[n.length-1],a=1,l=await this.makeRequest(i,t,r,a),u=l.total?Math.ceil(l.total/r):1,d=await this.helpers.asyncMap(this.helpers.range(a,u),g=>this.makeRequest(i,t,r,g+1));return this.helpers.flatMap([l,...d],g=>Object.values(g.data[c]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(i=>this.getStoryReference(r,i)).filter(Boolean)))}iterateTree(e,t,s){const r=i=>{if(i!=null){if(i.constructor===Array)for(let n=0;n<i.length;n++)r(i[n]);else if(i.constructor===Object){if(i._stopResolving)return;for(const n in i)(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,n,t,s),this._insertLinks(i,n,s)),r(i[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,n=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var r,i;let n=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(i=e.link_uuids)!=null&&i.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const n=await i.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),u.data.story||u.data.stories){const d=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${d}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await i.set(r,u),u.data.cv&&t.token&&(t.version==="draft"&&m[t.token]!=u.data.cv&&await this.flushCache(),m[t.token]=t.cv?t.cv:u.data.cv),n(u)}catch(l){if(l.response&&l.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(y[e])},getAll(){return Promise.resolve(y)},set(e,t){return y[e]=t,Promise.resolve(void 0)},flush(){return y={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const pe=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){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");return}return{storyblokApi:new de(e)}},ge=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}};let R,w="https://app.storyblok.com/f/storyblok-v2-latest.js";const U=(o,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",i=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===o;if(!(!r||!i)){if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],n=>{n.action==="input"&&n.story.id===o?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===o&&window.location.reload()})})}},me=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:i=[],apiOptions:n={},richText:c={},bridgeUrl:a}=o;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let u={};i.forEach(g=>{u={...u,...g(l)}}),a&&(w=a);const d=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&d&&C(w),R=new f(c.schema),c.resolver&&I(R,c.resolver),u},I=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},O=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),fe=(o,e,t)=>{let s=t||R;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return O(o)?"":(e&&(s=new f(e.schema),e.resolver&&I(s,e.resolver)),s.render(o))},ye=()=>C(w);exports.RichTextResolver=f;exports.RichTextSchema=j;exports.apiPlugin=pe;exports.isRichTextEmpty=O;exports.loadStoryblokBridge=ye;exports.registerStoryblokBridge=U;exports.renderRichText=fe;exports.storyblokEditable=ge;exports.storyblokInit=me;exports.useStoryblokBridge=U;
|
package/dist/storyblok-js.mjs
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
let
|
|
2
|
-
const
|
|
1
|
+
let S = !1;
|
|
2
|
+
const E = [], C = (o) => new Promise((e, t) => {
|
|
3
3
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
|
4
4
|
if (window.location === window.parent.location) {
|
|
5
5
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
S ? r() : E.push(r);
|
|
9
9
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
10
10
|
return;
|
|
11
11
|
const s = document.createElement("script");
|
|
12
|
-
s.async = !0, s.src =
|
|
13
|
-
|
|
12
|
+
s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
|
13
|
+
E.forEach((i) => i()), S = !0, e(r);
|
|
14
14
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
15
15
|
});
|
|
16
|
-
var
|
|
17
|
-
function x(
|
|
18
|
-
return !(
|
|
16
|
+
var U = Object.defineProperty, I = (o, e, t) => e in o ? U(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, h = (o, e, t) => (I(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
17
|
+
function x(o) {
|
|
18
|
+
return !(o !== o || o === 1 / 0 || o === -1 / 0);
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function O(o, e, t) {
|
|
21
21
|
if (!x(e))
|
|
22
22
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
23
23
|
if (!x(t))
|
|
24
24
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
25
25
|
const s = [];
|
|
26
|
-
let r = [],
|
|
26
|
+
let r = [], i = 0;
|
|
27
27
|
const n = function() {
|
|
28
|
-
|
|
28
|
+
i++;
|
|
29
29
|
const a = setTimeout(function() {
|
|
30
|
-
|
|
30
|
+
i--, s.length > 0 && n(), r = r.filter(function(u) {
|
|
31
31
|
return u !== a;
|
|
32
32
|
});
|
|
33
33
|
}, t);
|
|
34
34
|
r.indexOf(a) < 0 && r.push(a);
|
|
35
35
|
const l = s.shift();
|
|
36
|
-
l.resolve(
|
|
36
|
+
l.resolve(o.apply(l.self, l.args));
|
|
37
37
|
}, c = function(...a) {
|
|
38
38
|
const l = this;
|
|
39
39
|
return new Promise(function(u, p) {
|
|
@@ -42,7 +42,7 @@ function C(i, e, t) {
|
|
|
42
42
|
reject: p,
|
|
43
43
|
args: a,
|
|
44
44
|
self: l
|
|
45
|
-
}),
|
|
45
|
+
}), i < e && n();
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
return c.abort = function() {
|
|
@@ -61,7 +61,7 @@ class y {
|
|
|
61
61
|
page: s
|
|
62
62
|
})), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
|
|
63
63
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
|
64
|
-
return this.arrayFrom(s, (
|
|
64
|
+
return this.arrayFrom(s, (i, n) => n * r + e);
|
|
65
65
|
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], [])), h(this, "escapeHTML", function(e) {
|
|
66
66
|
const t = {
|
|
67
67
|
"&": "&",
|
|
@@ -70,7 +70,7 @@ class y {
|
|
|
70
70
|
'"': """,
|
|
71
71
|
"'": "'"
|
|
72
72
|
}, s = /[&<>"']/g, r = RegExp(s.source);
|
|
73
|
-
return e && r.test(e) ? e.replace(s, (
|
|
73
|
+
return e && r.test(e) ? e.replace(s, (i) => t[i]) : e;
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
@@ -82,10 +82,10 @@ class y {
|
|
|
82
82
|
*/
|
|
83
83
|
stringify(e, t, s) {
|
|
84
84
|
const r = [];
|
|
85
|
-
for (const
|
|
86
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
|
85
|
+
for (const i in e) {
|
|
86
|
+
if (!Object.prototype.hasOwnProperty.call(e, i))
|
|
87
87
|
continue;
|
|
88
|
-
const n = e[
|
|
88
|
+
const n = e[i], c = s ? "" : encodeURIComponent(i);
|
|
89
89
|
let a;
|
|
90
90
|
typeof n == "object" ? a = this.stringify(
|
|
91
91
|
n,
|
|
@@ -97,85 +97,93 @@ class y {
|
|
|
97
97
|
}
|
|
98
98
|
/**
|
|
99
99
|
* @method getRegionURL
|
|
100
|
-
* @param {String} regionCode region code, could be eu, us or
|
|
100
|
+
* @param {String} regionCode region code, could be eu, us, cn, ap or ca
|
|
101
101
|
* @return {String} The base URL of the region
|
|
102
102
|
*/
|
|
103
103
|
getRegionURL(e) {
|
|
104
|
-
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn";
|
|
104
|
+
const t = "api.storyblok.com", s = "api-us.storyblok.com", r = "app.storyblokchina.cn", i = "api-ap.storyblok.com", n = "api-ca.storyblok.com";
|
|
105
105
|
switch (e) {
|
|
106
106
|
case "us":
|
|
107
107
|
return s;
|
|
108
108
|
case "cn":
|
|
109
109
|
return r;
|
|
110
|
+
case "ap":
|
|
111
|
+
return i;
|
|
112
|
+
case "ca":
|
|
113
|
+
return n;
|
|
110
114
|
default:
|
|
111
115
|
return t;
|
|
112
116
|
}
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
|
-
const
|
|
119
|
+
const N = function(o, e) {
|
|
116
120
|
const t = {};
|
|
117
|
-
for (const s in
|
|
118
|
-
const r =
|
|
121
|
+
for (const s in o) {
|
|
122
|
+
const r = o[s];
|
|
119
123
|
e.indexOf(s) > -1 && r !== null && (t[s] = r);
|
|
120
124
|
}
|
|
121
125
|
return t;
|
|
122
|
-
},
|
|
126
|
+
}, P = (o) => o === "email", A = () => ({
|
|
123
127
|
singleTag: "hr"
|
|
124
128
|
}), L = () => ({
|
|
125
129
|
tag: "blockquote"
|
|
126
|
-
}),
|
|
130
|
+
}), M = () => ({
|
|
127
131
|
tag: "ul"
|
|
128
|
-
}),
|
|
132
|
+
}), D = (o) => ({
|
|
129
133
|
tag: [
|
|
130
134
|
"pre",
|
|
131
135
|
{
|
|
132
136
|
tag: "code",
|
|
133
|
-
attrs:
|
|
137
|
+
attrs: o.attrs
|
|
134
138
|
}
|
|
135
139
|
]
|
|
136
|
-
}),
|
|
140
|
+
}), B = () => ({
|
|
137
141
|
singleTag: "br"
|
|
138
|
-
}),
|
|
139
|
-
tag: `h${
|
|
140
|
-
}),
|
|
142
|
+
}), H = (o) => ({
|
|
143
|
+
tag: `h${o.attrs.level}`
|
|
144
|
+
}), z = (o) => ({
|
|
141
145
|
singleTag: [
|
|
142
146
|
{
|
|
143
147
|
tag: "img",
|
|
144
|
-
attrs:
|
|
148
|
+
attrs: N(o.attrs, ["src", "alt", "title"])
|
|
145
149
|
}
|
|
146
150
|
]
|
|
147
|
-
}),
|
|
151
|
+
}), F = () => ({
|
|
148
152
|
tag: "li"
|
|
149
|
-
}),
|
|
153
|
+
}), q = () => ({
|
|
150
154
|
tag: "ol"
|
|
151
|
-
}),
|
|
155
|
+
}), V = () => ({
|
|
152
156
|
tag: "p"
|
|
153
|
-
}),
|
|
157
|
+
}), G = (o) => ({
|
|
154
158
|
tag: [
|
|
155
159
|
{
|
|
156
160
|
tag: "span",
|
|
157
161
|
attrs: {
|
|
158
162
|
"data-type": "emoji",
|
|
159
|
-
"data-name":
|
|
160
|
-
emoji:
|
|
163
|
+
"data-name": o.attrs.name,
|
|
164
|
+
emoji: o.attrs.emoji
|
|
161
165
|
}
|
|
162
166
|
}
|
|
163
167
|
]
|
|
164
|
-
}),
|
|
168
|
+
}), J = () => ({
|
|
165
169
|
tag: "b"
|
|
170
|
+
}), Y = () => ({
|
|
171
|
+
tag: "s"
|
|
166
172
|
}), K = () => ({
|
|
167
|
-
tag: "strike"
|
|
168
|
-
}), W = () => ({
|
|
169
173
|
tag: "u"
|
|
170
|
-
}),
|
|
174
|
+
}), W = () => ({
|
|
171
175
|
tag: "strong"
|
|
172
|
-
}), Q = () => ({
|
|
173
|
-
tag: "code"
|
|
174
176
|
}), X = () => ({
|
|
177
|
+
tag: "code"
|
|
178
|
+
}), Z = () => ({
|
|
175
179
|
tag: "i"
|
|
176
|
-
}),
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
}), Q = (o) => {
|
|
181
|
+
if (!o.attrs)
|
|
182
|
+
return {
|
|
183
|
+
tag: ""
|
|
184
|
+
};
|
|
185
|
+
const e = new y().escapeHTML, t = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
|
|
186
|
+
if (delete t.linktype, t.href && (t.href = e(o.attrs.href || "")), P(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
179
187
|
for (const r in t.custom)
|
|
180
188
|
t[r] = t.custom[r];
|
|
181
189
|
delete t.custom;
|
|
@@ -188,82 +196,82 @@ const A = function(i, e) {
|
|
|
188
196
|
}
|
|
189
197
|
]
|
|
190
198
|
};
|
|
191
|
-
}, ee = (
|
|
199
|
+
}, ee = (o) => ({
|
|
192
200
|
tag: [
|
|
193
201
|
{
|
|
194
202
|
tag: "span",
|
|
195
|
-
attrs:
|
|
203
|
+
attrs: o.attrs
|
|
196
204
|
}
|
|
197
205
|
]
|
|
198
206
|
}), te = () => ({
|
|
199
207
|
tag: "sub"
|
|
200
208
|
}), se = () => ({
|
|
201
209
|
tag: "sup"
|
|
202
|
-
}), re = (
|
|
210
|
+
}), re = (o) => ({
|
|
203
211
|
tag: [
|
|
204
212
|
{
|
|
205
213
|
tag: "span",
|
|
206
|
-
attrs:
|
|
214
|
+
attrs: o.attrs
|
|
207
215
|
}
|
|
208
216
|
]
|
|
209
|
-
}),
|
|
217
|
+
}), ie = (o) => {
|
|
210
218
|
var e;
|
|
211
|
-
return (e =
|
|
219
|
+
return (e = o.attrs) != null && e.color ? {
|
|
212
220
|
tag: [
|
|
213
221
|
{
|
|
214
222
|
tag: "span",
|
|
215
223
|
attrs: {
|
|
216
|
-
style: `background-color:${
|
|
224
|
+
style: `background-color:${o.attrs.color};`
|
|
217
225
|
}
|
|
218
226
|
}
|
|
219
227
|
]
|
|
220
228
|
} : {
|
|
221
229
|
tag: ""
|
|
222
230
|
};
|
|
223
|
-
}, ne = (
|
|
231
|
+
}, ne = (o) => {
|
|
224
232
|
var e;
|
|
225
|
-
return (e =
|
|
233
|
+
return (e = o.attrs) != null && e.color ? {
|
|
226
234
|
tag: [
|
|
227
235
|
{
|
|
228
236
|
tag: "span",
|
|
229
237
|
attrs: {
|
|
230
|
-
style: `color:${
|
|
238
|
+
style: `color:${o.attrs.color}`
|
|
231
239
|
}
|
|
232
240
|
}
|
|
233
241
|
]
|
|
234
242
|
} : {
|
|
235
243
|
tag: ""
|
|
236
244
|
};
|
|
237
|
-
},
|
|
245
|
+
}, oe = {
|
|
238
246
|
nodes: {
|
|
239
|
-
horizontal_rule:
|
|
247
|
+
horizontal_rule: A,
|
|
240
248
|
blockquote: L,
|
|
241
|
-
bullet_list:
|
|
242
|
-
code_block:
|
|
243
|
-
hard_break:
|
|
244
|
-
heading:
|
|
245
|
-
image:
|
|
246
|
-
list_item:
|
|
247
|
-
ordered_list:
|
|
248
|
-
paragraph:
|
|
249
|
-
emoji:
|
|
249
|
+
bullet_list: M,
|
|
250
|
+
code_block: D,
|
|
251
|
+
hard_break: B,
|
|
252
|
+
heading: H,
|
|
253
|
+
image: z,
|
|
254
|
+
list_item: F,
|
|
255
|
+
ordered_list: q,
|
|
256
|
+
paragraph: V,
|
|
257
|
+
emoji: G
|
|
250
258
|
},
|
|
251
259
|
marks: {
|
|
252
|
-
bold:
|
|
253
|
-
strike:
|
|
254
|
-
underline:
|
|
255
|
-
strong:
|
|
256
|
-
code:
|
|
257
|
-
italic:
|
|
258
|
-
link:
|
|
260
|
+
bold: J,
|
|
261
|
+
strike: Y,
|
|
262
|
+
underline: K,
|
|
263
|
+
strong: W,
|
|
264
|
+
code: X,
|
|
265
|
+
italic: Z,
|
|
266
|
+
link: Q,
|
|
259
267
|
styled: ee,
|
|
260
268
|
subscript: te,
|
|
261
269
|
superscript: se,
|
|
262
270
|
anchor: re,
|
|
263
|
-
highlight:
|
|
271
|
+
highlight: ie,
|
|
264
272
|
textStyle: ne
|
|
265
273
|
}
|
|
266
|
-
}, ae = function(
|
|
274
|
+
}, ae = function(o) {
|
|
267
275
|
const e = {
|
|
268
276
|
"&": "&",
|
|
269
277
|
"<": "<",
|
|
@@ -271,11 +279,11 @@ const A = function(i, e) {
|
|
|
271
279
|
'"': """,
|
|
272
280
|
"'": "'"
|
|
273
281
|
}, t = /[&<>"']/g, s = RegExp(t.source);
|
|
274
|
-
return
|
|
282
|
+
return o && s.test(o) ? o.replace(t, (r) => e[r]) : o;
|
|
275
283
|
};
|
|
276
284
|
class b {
|
|
277
285
|
constructor(e) {
|
|
278
|
-
h(this, "marks"), h(this, "nodes"), e || (e =
|
|
286
|
+
h(this, "marks"), h(this, "nodes"), e || (e = oe), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
279
287
|
}
|
|
280
288
|
addNode(e, t) {
|
|
281
289
|
this.nodes[e] = t;
|
|
@@ -318,8 +326,8 @@ class b {
|
|
|
318
326
|
), "";
|
|
319
327
|
}
|
|
320
328
|
optimizeImages(e, t) {
|
|
321
|
-
let s = 0, r = 0,
|
|
322
|
-
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (
|
|
329
|
+
let s = 0, r = 0, i = "", n = "";
|
|
330
|
+
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (i += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (i += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (i += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (i += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (n += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (n += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (n += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (n += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (n += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (n += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (n += `:rotate(${t.filters.rotate})`), n.length > 0 && (n = "/filters" + n))), i.length > 0 && (e = e.replace(/<img/g, `<img ${i.trim()}`));
|
|
323
331
|
const c = s > 0 || r > 0 || n.length > 0 ? `${s}x${r}${n}` : "";
|
|
324
332
|
return e = e.replace(
|
|
325
333
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
|
@@ -335,14 +343,14 @@ class b {
|
|
|
335
343
|
if (typeof d == "number")
|
|
336
344
|
return `//${p}/m/${d}x0${n} ${d}w`;
|
|
337
345
|
if (typeof d == "object" && d.length === 2) {
|
|
338
|
-
let
|
|
339
|
-
return typeof d[0] == "number" && (
|
|
346
|
+
let _ = 0, T = 0;
|
|
347
|
+
return typeof d[0] == "number" && (_ = d[0]), typeof d[1] == "number" && (T = d[1]), `//${p}/m/${_}x${T}${n} ${_}w`;
|
|
340
348
|
}
|
|
341
349
|
}).join(", "),
|
|
342
350
|
sizes: (u = t.sizes) == null ? void 0 : u.map((d) => d).join(", ")
|
|
343
351
|
};
|
|
344
|
-
let
|
|
345
|
-
return g.srcset && (
|
|
352
|
+
let v = "";
|
|
353
|
+
return g.srcset && (v += `srcset="${g.srcset}" `), g.sizes && (v += `sizes="${g.sizes}" `), a.replace(/<img/g, `<img ${v.trim()}`);
|
|
346
354
|
}
|
|
347
355
|
return a;
|
|
348
356
|
})), e;
|
|
@@ -350,15 +358,15 @@ class b {
|
|
|
350
358
|
renderNode(e) {
|
|
351
359
|
const t = [];
|
|
352
360
|
e.marks && e.marks.forEach((r) => {
|
|
353
|
-
const
|
|
354
|
-
|
|
361
|
+
const i = this.getMatchingMark(r);
|
|
362
|
+
i && i.tag !== "" && t.push(this.renderOpeningTag(i.tag));
|
|
355
363
|
});
|
|
356
364
|
const s = this.getMatchingNode(e);
|
|
357
365
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
358
366
|
t.push(this.renderNode(r));
|
|
359
367
|
}) : e.text ? t.push(ae(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
|
|
360
|
-
const
|
|
361
|
-
|
|
368
|
+
const i = this.getMatchingMark(r);
|
|
369
|
+
i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
|
|
362
370
|
}), t.join("");
|
|
363
371
|
}
|
|
364
372
|
renderTag(e, t) {
|
|
@@ -368,9 +376,9 @@ class b {
|
|
|
368
376
|
{
|
|
369
377
|
let r = `<${s.tag}`;
|
|
370
378
|
if (s.attrs)
|
|
371
|
-
for (const
|
|
372
|
-
const n = s.attrs[
|
|
373
|
-
n !== null && (r += ` ${
|
|
379
|
+
for (const i in s.attrs) {
|
|
380
|
+
const n = s.attrs[i];
|
|
381
|
+
n !== null && (r += ` ${i}="${n}"`);
|
|
374
382
|
}
|
|
375
383
|
return `${r}${t}>`;
|
|
376
384
|
}
|
|
@@ -454,11 +462,11 @@ class le {
|
|
|
454
462
|
)}`;
|
|
455
463
|
} else
|
|
456
464
|
s = JSON.stringify(this.parameters);
|
|
457
|
-
const r = new URL(t),
|
|
465
|
+
const r = new URL(t), i = new AbortController(), { signal: n } = i;
|
|
458
466
|
let c;
|
|
459
|
-
this.timeout && (c = setTimeout(() =>
|
|
467
|
+
this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
|
|
460
468
|
try {
|
|
461
|
-
const a = await
|
|
469
|
+
const a = await fetch(`${r}`, {
|
|
462
470
|
method: e,
|
|
463
471
|
headers: this.headers,
|
|
464
472
|
body: s,
|
|
@@ -478,33 +486,34 @@ class le {
|
|
|
478
486
|
}
|
|
479
487
|
_statusHandler(e) {
|
|
480
488
|
const t = /20[0-6]/g;
|
|
481
|
-
return new Promise((s) => {
|
|
489
|
+
return new Promise((s, r) => {
|
|
482
490
|
if (t.test(`${e.status}`))
|
|
483
491
|
return s(e);
|
|
484
|
-
const
|
|
492
|
+
const i = {
|
|
485
493
|
message: e.statusText,
|
|
486
494
|
status: e.status,
|
|
487
495
|
response: Array.isArray(e.data) ? e.data[0] : e.data.error || e.data.slug
|
|
488
496
|
};
|
|
489
|
-
|
|
497
|
+
r(i);
|
|
490
498
|
});
|
|
491
499
|
}
|
|
492
500
|
}
|
|
493
|
-
|
|
501
|
+
var ce = { NVM_INC: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/include/node", TERM_PROGRAM: "iTerm.app", NODE: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", NVM_CD_FLAGS: "-q", INIT_CWD: "/Users/lisilinhart/Code/storyblok-js-client", SHELL: "/bin/zsh", TERM: "xterm-256color", TMPDIR: "/var/folders/9v/t3hq3s9n2rj6_x9jlsjjq95w0000gn/T/", npm_config_metrics_registry: "https://registry.npmjs.org/", npm_config_global_prefix: "/Users/lisilinhart/.nvm/versions/node/v18.16.0", TERM_PROGRAM_VERSION: "3.4.20", TERM_SESSION_ID: "w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF", COLOR: "0", npm_config_noproxy: "", ZSH: "/Users/lisilinhart/.oh-my-zsh", npm_config_local_prefix: "/Users/lisilinhart/Code/storyblok-js-client", USER: "lisilinhart", NVM_DIR: "/Users/lisilinhart/.nvm", COMMAND_MODE: "unix2003", npm_config_globalconfig: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/etc/npmrc", SSH_AUTH_SOCK: "/private/tmp/com.apple.launchd.oUounWp9qr/Listeners", __CF_USER_TEXT_ENCODING: "0x1F5:0x0:0x5C", npm_execpath: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/bin/npm-cli.js", PAGER: "less", npm_package_integrity: "null", LSCOLORS: "Gxfxcxdxbxegedabagacad", PATH: "/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/Users/lisilinhart/Code/storyblok-js-client/node_modules/.bin:/Users/lisilinhart/Code/node_modules/.bin:/Users/lisilinhart/node_modules/.bin:/Users/node_modules/.bin:/node_modules/.bin:/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/@npmcli/run-script/lib/node-gyp-bin:/usr/local/sbin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.yarn/bin:/Users/lisilinhart/.config/yarn/global/node_modules/.bin:/Users/lisilinhart/.rbenv/shims:/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin:/Users/lisilinhart/bin:/usr/local/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Users/lisilinhart/.cargo/bin", RUBY_CONFIGURE_OPTS: "--with-openssl-dir=/usr/local/opt/openssl@1.1", LaunchInstanceID: "9D2A03D3-35CC-4CDD-810D-0D5C25991BBB", _: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", npm_package_json: "/Users/lisilinhart/Code/storyblok-js-client/package.json", __CFBundleIdentifier: "com.googlecode.iterm2", npm_config_init_module: "/Users/lisilinhart/.npm-init.js", npm_config_userconfig: "/Users/lisilinhart/.npmrc", PWD: "/Users/lisilinhart/Code/storyblok-js-client", npm_command: "run-script", P9K_SSH: "0", EDITOR: "vi", npm_lifecycle_event: "build", LANG: "de_AT.UTF-8", P9K_TTY: "old", npm_package_name: "storyblok-js-client", ITERM_PROFILE: "Default", XPC_FLAGS: "0x0", RBENV_SHELL: "zsh", npm_config_node_gyp: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js", XPC_SERVICE_NAME: "0", npm_package_version: "6.4.1", COLORFGBG: "7;0", HOME: "/Users/lisilinhart", SHLVL: "3", npm_package_resolved: "/Users/lisilinhart/Code/storyblok-js-client", LC_TERMINAL_VERSION: "3.4.20", ITERM_SESSION_ID: "w0t0p1:12B7CE01-010D-40B5-B6DA-DFE3CF20B8FF", LOGNAME: "lisilinhart", LESS: "-R", npm_config_cache: "/Users/lisilinhart/.npm", npm_lifecycle_script: "node vite.build.mjs && tsc", NVM_BIN: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin", npm_config_user_agent: "npm/9.5.1 node/v18.16.0 darwin x64 workspaces/false", LC_TERMINAL: "iTerm2", SECURITYSESSIONID: "186a1", COLORTERM: "truecolor", npm_config_prefix: "/Users/lisilinhart/.nvm/versions/node/v18.16.0", npm_node_execpath: "/Users/lisilinhart/.nvm/versions/node/v18.16.0/bin/node", NODE_ENV: "production" };
|
|
502
|
+
const $ = "SB-Agent", k = {
|
|
494
503
|
defaultAgentName: "SB-JS-CLIENT",
|
|
495
504
|
defaultAgentVersion: "SB-Agent-Version",
|
|
496
|
-
packageVersion:
|
|
505
|
+
packageVersion: ce.npm_package_version
|
|
497
506
|
};
|
|
498
|
-
let
|
|
499
|
-
const
|
|
500
|
-
class
|
|
507
|
+
let f = {};
|
|
508
|
+
const m = {};
|
|
509
|
+
class he {
|
|
501
510
|
/**
|
|
502
511
|
*
|
|
503
512
|
* @param config ISbConfig interface
|
|
504
513
|
* @param endpoint string, optional
|
|
505
514
|
*/
|
|
506
515
|
constructor(e, t) {
|
|
507
|
-
h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations");
|
|
516
|
+
h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "resolveCounter"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), h(this, "stringifiedStoriesCache");
|
|
508
517
|
let s = e.endpoint || t;
|
|
509
518
|
if (!s) {
|
|
510
519
|
const n = new y().getRegionURL, c = e.https === !1 ? "http" : "https";
|
|
@@ -514,12 +523,12 @@ class ce {
|
|
|
514
523
|
if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers)
|
|
515
524
|
for (const n in e.headers)
|
|
516
525
|
r.set(n, e.headers[n]);
|
|
517
|
-
r.has(
|
|
518
|
-
|
|
519
|
-
|
|
526
|
+
r.has($) || (r.set($, k.defaultAgentName), r.set(
|
|
527
|
+
k.defaultAgentVersion,
|
|
528
|
+
k.packageVersion
|
|
520
529
|
));
|
|
521
|
-
let
|
|
522
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken),
|
|
530
|
+
let i = 5;
|
|
531
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), e.richTextSchema ? this.richTextResolver = new b(e.richTextSchema) : this.richTextResolver = new b(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = O(this.throttledRequest, i, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new y(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new le({
|
|
523
532
|
baseURL: s,
|
|
524
533
|
timeout: e.timeout || 0,
|
|
525
534
|
headers: r,
|
|
@@ -538,17 +547,17 @@ class ce {
|
|
|
538
547
|
});
|
|
539
548
|
}
|
|
540
549
|
parseParams(e) {
|
|
541
|
-
return e.
|
|
550
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = m[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
|
|
542
551
|
}
|
|
543
552
|
factoryParamOptions(e, t) {
|
|
544
553
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
545
554
|
}
|
|
546
555
|
makeRequest(e, t, s, r) {
|
|
547
|
-
const
|
|
556
|
+
const i = this.factoryParamOptions(
|
|
548
557
|
e,
|
|
549
558
|
this.helpers.getOptionsPage(t, s, r)
|
|
550
559
|
);
|
|
551
|
-
return this.cacheResponse(e,
|
|
560
|
+
return this.cacheResponse(e, i);
|
|
552
561
|
}
|
|
553
562
|
get(e, t) {
|
|
554
563
|
t || (t = {});
|
|
@@ -556,9 +565,9 @@ class ce {
|
|
|
556
565
|
return this.cacheResponse(s, r);
|
|
557
566
|
}
|
|
558
567
|
async getAll(e, t, s) {
|
|
559
|
-
const r = (t == null ? void 0 : t.per_page) || 25,
|
|
568
|
+
const r = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`, n = i.split("/"), c = s || n[n.length - 1], a = 1, l = await this.makeRequest(i, t, r, a), u = l.total ? Math.ceil(l.total / r) : 1, p = await this.helpers.asyncMap(
|
|
560
569
|
this.helpers.range(a, u),
|
|
561
|
-
(g) => this.makeRequest(
|
|
570
|
+
(g) => this.makeRequest(i, t, r, g + 1)
|
|
562
571
|
);
|
|
563
572
|
return this.helpers.flatMap(
|
|
564
573
|
[l, ...p],
|
|
@@ -596,40 +605,40 @@ class ce {
|
|
|
596
605
|
const r = e[t];
|
|
597
606
|
r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[s][r.id] ? r.story = this._cleanCopy(this.links[s][r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[s][r.uuid] && (r.story = this._cleanCopy(this.links[s][r.uuid]));
|
|
598
607
|
}
|
|
608
|
+
/**
|
|
609
|
+
*
|
|
610
|
+
* @param resolveId A counter number as a string
|
|
611
|
+
* @param uuid The uuid of the story
|
|
612
|
+
* @returns string | object
|
|
613
|
+
*/
|
|
614
|
+
getStoryReference(e, t) {
|
|
615
|
+
return this.relations[e][t] ? (this.stringifiedStoriesCache[t] || (this.stringifiedStoriesCache[t] = JSON.stringify(
|
|
616
|
+
this.relations[e][t]
|
|
617
|
+
)), JSON.parse(this.stringifiedStoriesCache[t])) : t;
|
|
618
|
+
}
|
|
599
619
|
_insertRelations(e, t, s, r) {
|
|
600
|
-
|
|
601
|
-
if (typeof e[t] == "string")
|
|
602
|
-
this.relations[r][e[t]] && (e[t] = this._cleanCopy(
|
|
603
|
-
this.relations[r][e[t]]
|
|
604
|
-
));
|
|
605
|
-
else if (e[t] && e[t].constructor === Array) {
|
|
606
|
-
const o = [];
|
|
607
|
-
e[t].forEach((n) => {
|
|
608
|
-
this.relations[r][n] && o.push(this._cleanCopy(this.relations[r][n]));
|
|
609
|
-
}), e[t] = o;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
620
|
+
s.indexOf(`${e.component}.${t}`) > -1 && (typeof e[t] == "string" ? e[t] = this.getStoryReference(r, e[t]) : Array.isArray(e[t]) && (e[t] = e[t].map((i) => this.getStoryReference(r, i)).filter(Boolean)));
|
|
612
621
|
}
|
|
613
622
|
iterateTree(e, t, s) {
|
|
614
|
-
const r = (
|
|
615
|
-
if (
|
|
616
|
-
if (
|
|
617
|
-
for (let n = 0; n <
|
|
618
|
-
r(
|
|
619
|
-
else if (
|
|
620
|
-
if (
|
|
623
|
+
const r = (i) => {
|
|
624
|
+
if (i != null) {
|
|
625
|
+
if (i.constructor === Array)
|
|
626
|
+
for (let n = 0; n < i.length; n++)
|
|
627
|
+
r(i[n]);
|
|
628
|
+
else if (i.constructor === Object) {
|
|
629
|
+
if (i._stopResolving)
|
|
621
630
|
return;
|
|
622
|
-
for (const n in
|
|
623
|
-
(
|
|
624
|
-
|
|
631
|
+
for (const n in i)
|
|
632
|
+
(i.component && i._uid || i.type === "link") && (this._insertRelations(
|
|
633
|
+
i,
|
|
625
634
|
n,
|
|
626
635
|
t,
|
|
627
636
|
s
|
|
628
637
|
), this._insertLinks(
|
|
629
|
-
|
|
638
|
+
i,
|
|
630
639
|
n,
|
|
631
640
|
s
|
|
632
|
-
)), r(
|
|
641
|
+
)), r(i[n]);
|
|
633
642
|
}
|
|
634
643
|
}
|
|
635
644
|
};
|
|
@@ -638,9 +647,9 @@ class ce {
|
|
|
638
647
|
async resolveLinks(e, t, s) {
|
|
639
648
|
let r = [];
|
|
640
649
|
if (e.link_uuids) {
|
|
641
|
-
const
|
|
642
|
-
for (let a = 0; a <
|
|
643
|
-
const l = Math.min(
|
|
650
|
+
const i = e.link_uuids.length, n = [], c = 50;
|
|
651
|
+
for (let a = 0; a < i; a += c) {
|
|
652
|
+
const l = Math.min(i, a + c);
|
|
644
653
|
n.push(e.link_uuids.slice(a, l));
|
|
645
654
|
}
|
|
646
655
|
for (let a = 0; a < n.length; a++)
|
|
@@ -656,9 +665,9 @@ class ce {
|
|
|
656
665
|
);
|
|
657
666
|
} else
|
|
658
667
|
r = e.links;
|
|
659
|
-
r.forEach((
|
|
660
|
-
this.links[s][
|
|
661
|
-
...
|
|
668
|
+
r.forEach((i) => {
|
|
669
|
+
this.links[s][i.uuid] = {
|
|
670
|
+
...i,
|
|
662
671
|
_stopResolving: !0
|
|
663
672
|
};
|
|
664
673
|
});
|
|
@@ -666,9 +675,9 @@ class ce {
|
|
|
666
675
|
async resolveRelations(e, t, s) {
|
|
667
676
|
let r = [];
|
|
668
677
|
if (e.rel_uuids) {
|
|
669
|
-
const
|
|
670
|
-
for (let a = 0; a <
|
|
671
|
-
const l = Math.min(
|
|
678
|
+
const i = e.rel_uuids.length, n = [], c = 50;
|
|
679
|
+
for (let a = 0; a < i; a += c) {
|
|
680
|
+
const l = Math.min(i, a + c);
|
|
672
681
|
n.push(e.rel_uuids.slice(a, l));
|
|
673
682
|
}
|
|
674
683
|
for (let a = 0; a < n.length; a++)
|
|
@@ -676,23 +685,24 @@ class ce {
|
|
|
676
685
|
per_page: c,
|
|
677
686
|
language: t.language,
|
|
678
687
|
version: t.version,
|
|
679
|
-
by_uuids: n[a].join(",")
|
|
688
|
+
by_uuids: n[a].join(","),
|
|
689
|
+
excluding_fields: t.excluding_fields
|
|
680
690
|
})).data.stories.forEach((l) => {
|
|
681
691
|
r.push(l);
|
|
682
692
|
});
|
|
683
693
|
} else
|
|
684
694
|
r = e.rels;
|
|
685
|
-
r && r.length > 0 && r.forEach((
|
|
686
|
-
this.relations[s][
|
|
687
|
-
...
|
|
695
|
+
r && r.length > 0 && r.forEach((i) => {
|
|
696
|
+
this.relations[s][i.uuid] = {
|
|
697
|
+
...i,
|
|
688
698
|
_stopResolving: !0
|
|
689
699
|
};
|
|
690
700
|
});
|
|
691
701
|
}
|
|
692
702
|
async resolveStories(e, t, s) {
|
|
693
|
-
var r,
|
|
703
|
+
var r, i;
|
|
694
704
|
let n = [];
|
|
695
|
-
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (
|
|
705
|
+
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (n = t.resolve_relations.split(",")), await this.resolveRelations(e, t, s)), t.resolve_links && ["1", "story", "url", "link"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (i = e.link_uuids) != null && i.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
|
696
706
|
for (const c in this.relations[s])
|
|
697
707
|
this.iterateTree(
|
|
698
708
|
this.relations[s][c],
|
|
@@ -701,13 +711,13 @@ class ce {
|
|
|
701
711
|
);
|
|
702
712
|
e.story ? this.iterateTree(e.story, n, s) : e.stories.forEach((c) => {
|
|
703
713
|
this.iterateTree(c, n, s);
|
|
704
|
-
}), delete this.links[s], delete this.relations[s];
|
|
714
|
+
}), this.stringifiedStoriesCache = {}, delete this.links[s], delete this.relations[s];
|
|
705
715
|
}
|
|
706
716
|
async cacheResponse(e, t, s) {
|
|
707
717
|
(typeof s > "u" || !s) && (s = 0);
|
|
708
|
-
const r = this.helpers.stringify({ url: e, params: t }),
|
|
718
|
+
const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
|
|
709
719
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
710
|
-
const n = await
|
|
720
|
+
const n = await i.get(r);
|
|
711
721
|
if (n)
|
|
712
722
|
return Promise.resolve(n);
|
|
713
723
|
}
|
|
@@ -725,11 +735,11 @@ class ce {
|
|
|
725
735
|
const p = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
726
736
|
await this.resolveStories(u.data, t, `${p}`);
|
|
727
737
|
}
|
|
728
|
-
return t.version === "published" && e != "/cdn/spaces/me" && await
|
|
738
|
+
return t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && t.token && (t.version === "draft" && m[t.token] != u.data.cv && await this.flushCache(), m[t.token] = t.cv ? t.cv : u.data.cv), n(u);
|
|
729
739
|
} catch (l) {
|
|
730
740
|
if (l.response && l.response.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
|
|
731
741
|
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(n).catch(c);
|
|
732
|
-
c(l
|
|
742
|
+
c(l);
|
|
733
743
|
}
|
|
734
744
|
});
|
|
735
745
|
}
|
|
@@ -737,29 +747,26 @@ class ce {
|
|
|
737
747
|
return this.client[e](t, s);
|
|
738
748
|
}
|
|
739
749
|
cacheVersions() {
|
|
740
|
-
return
|
|
750
|
+
return m;
|
|
741
751
|
}
|
|
742
752
|
cacheVersion() {
|
|
743
|
-
return
|
|
744
|
-
}
|
|
745
|
-
setCacheVersion(e) {
|
|
746
|
-
this.accessToken && (f[this.accessToken] = e);
|
|
753
|
+
return m[this.accessToken];
|
|
747
754
|
}
|
|
748
755
|
cacheProvider() {
|
|
749
756
|
switch (this.cache.type) {
|
|
750
757
|
case "memory":
|
|
751
758
|
return {
|
|
752
759
|
get(e) {
|
|
753
|
-
return Promise.resolve(
|
|
760
|
+
return Promise.resolve(f[e]);
|
|
754
761
|
},
|
|
755
762
|
getAll() {
|
|
756
|
-
return Promise.resolve(
|
|
763
|
+
return Promise.resolve(f);
|
|
757
764
|
},
|
|
758
765
|
set(e, t) {
|
|
759
|
-
return
|
|
766
|
+
return f[e] = t, Promise.resolve(void 0);
|
|
760
767
|
},
|
|
761
768
|
flush() {
|
|
762
|
-
return
|
|
769
|
+
return f = {}, Promise.resolve(void 0);
|
|
763
770
|
}
|
|
764
771
|
};
|
|
765
772
|
case "custom":
|
|
@@ -768,7 +775,7 @@ class ce {
|
|
|
768
775
|
default:
|
|
769
776
|
return {
|
|
770
777
|
get() {
|
|
771
|
-
return Promise.resolve(
|
|
778
|
+
return Promise.resolve();
|
|
772
779
|
},
|
|
773
780
|
getAll() {
|
|
774
781
|
return Promise.resolve(void 0);
|
|
@@ -786,63 +793,63 @@ class ce {
|
|
|
786
793
|
return await this.cacheProvider().flush(), this;
|
|
787
794
|
}
|
|
788
795
|
}
|
|
789
|
-
const
|
|
790
|
-
const { apiOptions: e } =
|
|
796
|
+
const pe = (o = {}) => {
|
|
797
|
+
const { apiOptions: e } = o;
|
|
791
798
|
if (!e.accessToken) {
|
|
792
799
|
console.error(
|
|
793
800
|
"You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication"
|
|
794
801
|
);
|
|
795
802
|
return;
|
|
796
803
|
}
|
|
797
|
-
return { storyblokApi: new
|
|
798
|
-
},
|
|
799
|
-
if (typeof
|
|
804
|
+
return { storyblokApi: new he(e) };
|
|
805
|
+
}, de = (o) => {
|
|
806
|
+
if (typeof o != "object" || typeof o._editable > "u")
|
|
800
807
|
return {};
|
|
801
808
|
const e = JSON.parse(
|
|
802
|
-
|
|
809
|
+
o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
|
|
803
810
|
);
|
|
804
811
|
return e ? {
|
|
805
812
|
"data-blok-c": JSON.stringify(e),
|
|
806
813
|
"data-blok-uid": e.id + "-" + e.uid
|
|
807
814
|
} : {};
|
|
808
815
|
};
|
|
809
|
-
let
|
|
810
|
-
const
|
|
816
|
+
let R, w = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
817
|
+
const ge = (o, e, t = {}) => {
|
|
811
818
|
var s;
|
|
812
|
-
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u",
|
|
819
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", i = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
813
820
|
"_storyblok"
|
|
814
|
-
) ===
|
|
815
|
-
if (!(!r || !
|
|
816
|
-
if (!
|
|
821
|
+
) === o;
|
|
822
|
+
if (!(!r || !i)) {
|
|
823
|
+
if (!o) {
|
|
817
824
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
818
825
|
return;
|
|
819
826
|
}
|
|
820
827
|
window.storyblokRegisterEvent(() => {
|
|
821
828
|
new window.StoryblokBridge(t).on(["input", "published", "change"], (n) => {
|
|
822
|
-
n.action === "input" && n.story.id ===
|
|
829
|
+
n.action === "input" && n.story.id === o ? e(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
|
|
823
830
|
});
|
|
824
831
|
});
|
|
825
832
|
}
|
|
826
|
-
},
|
|
833
|
+
}, me = (o = {}) => {
|
|
827
834
|
var e, t;
|
|
828
835
|
const {
|
|
829
836
|
bridge: s,
|
|
830
837
|
accessToken: r,
|
|
831
|
-
use:
|
|
838
|
+
use: i = [],
|
|
832
839
|
apiOptions: n = {},
|
|
833
840
|
richText: c = {},
|
|
834
841
|
bridgeUrl: a
|
|
835
|
-
} =
|
|
842
|
+
} = o;
|
|
836
843
|
n.accessToken = n.accessToken || r;
|
|
837
844
|
const l = { bridge: s, apiOptions: n };
|
|
838
845
|
let u = {};
|
|
839
|
-
|
|
846
|
+
i.forEach((g) => {
|
|
840
847
|
u = { ...u, ...g(l) };
|
|
841
|
-
}), a && (
|
|
848
|
+
}), a && (w = a);
|
|
842
849
|
const p = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
843
|
-
return s !== !1 && p &&
|
|
844
|
-
},
|
|
845
|
-
|
|
850
|
+
return s !== !1 && p && C(w), R = new b(c.schema), c.resolver && j(R, c.resolver), u;
|
|
851
|
+
}, j = (o, e) => {
|
|
852
|
+
o.addNode("blok", (t) => {
|
|
846
853
|
let s = "";
|
|
847
854
|
return t.attrs.body.forEach((r) => {
|
|
848
855
|
s += e(r.component, r);
|
|
@@ -850,25 +857,25 @@ const de = (i, e, t = {}) => {
|
|
|
850
857
|
html: s
|
|
851
858
|
};
|
|
852
859
|
});
|
|
853
|
-
},
|
|
854
|
-
let s = t ||
|
|
860
|
+
}, ue = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), fe = (o, e, t) => {
|
|
861
|
+
let s = t || R;
|
|
855
862
|
if (!s) {
|
|
856
863
|
console.error(
|
|
857
864
|
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
858
865
|
);
|
|
859
866
|
return;
|
|
860
867
|
}
|
|
861
|
-
return
|
|
862
|
-
},
|
|
868
|
+
return ue(o) ? "" : (e && (s = new b(e.schema), e.resolver && j(s, e.resolver)), s.render(o));
|
|
869
|
+
}, ye = () => C(w);
|
|
863
870
|
export {
|
|
864
871
|
b as RichTextResolver,
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
872
|
+
oe as RichTextSchema,
|
|
873
|
+
pe as apiPlugin,
|
|
874
|
+
ue as isRichTextEmpty,
|
|
875
|
+
ye as loadStoryblokBridge,
|
|
876
|
+
ge as registerStoryblokBridge,
|
|
870
877
|
fe as renderRichText,
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
878
|
+
de as storyblokEditable,
|
|
879
|
+
me as storyblokInit,
|
|
880
|
+
ge as useStoryblokBridge
|
|
874
881
|
};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { SbReactComponentsMap, SbReactSDKOptions, StoryblokClient } from "../types";
|
|
3
3
|
export declare const useStoryblokApi: () => StoryblokClient;
|
|
4
4
|
export declare const setComponents: (newComponentsMap: SbReactComponentsMap) => SbReactComponentsMap;
|
|
5
|
-
export declare const getComponent: (componentKey: string) => false | import("react").ElementType<any>;
|
|
5
|
+
export declare const getComponent: (componentKey: string) => false | import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>;
|
|
6
6
|
export declare const getEnableFallbackComponent: () => boolean;
|
|
7
|
-
export declare const getCustomFallbackComponent: () => import("react").ElementType<any>;
|
|
7
|
+
export declare const getCustomFallbackComponent: () => import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements>;
|
|
8
8
|
export declare const storyblokInit: (pluginOptions?: SbReactSDKOptions) => void;
|
|
9
9
|
export { default as StoryblokComponent } from "./storyblok-component";
|
|
10
10
|
export { useStoryblokApi as getStoryblokApi };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "SDK to integrate Storyblok into your project using React.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -44,26 +44,26 @@
|
|
|
44
44
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@storyblok/js": "^
|
|
47
|
+
"@storyblok/js": "^3.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@babel/core": "^7.
|
|
51
|
-
"@babel/preset-env": "^7.
|
|
52
|
-
"@cypress/react": "^
|
|
53
|
-
"@cypress/vite-dev-server": "^
|
|
54
|
-
"@tsconfig/recommended": "^1.0.
|
|
55
|
-
"@types/react": "18.2.
|
|
56
|
-
"@vitejs/plugin-react": "^4.
|
|
57
|
-
"babel-jest": "^29.
|
|
58
|
-
"cypress": "^
|
|
59
|
-
"eslint-plugin-cypress": "^2.
|
|
60
|
-
"eslint-plugin-jest": "^27.
|
|
61
|
-
"jest": "^29.
|
|
50
|
+
"@babel/core": "^7.23.6",
|
|
51
|
+
"@babel/preset-env": "^7.23.6",
|
|
52
|
+
"@cypress/react": "^8.0.0",
|
|
53
|
+
"@cypress/vite-dev-server": "^5.0.6",
|
|
54
|
+
"@tsconfig/recommended": "^1.0.3",
|
|
55
|
+
"@types/react": "18.2.45",
|
|
56
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
57
|
+
"babel-jest": "^29.7.0",
|
|
58
|
+
"cypress": "^13.6.1",
|
|
59
|
+
"eslint-plugin-cypress": "^2.15.1",
|
|
60
|
+
"eslint-plugin-jest": "^27.6.0",
|
|
61
|
+
"jest": "^29.7.0",
|
|
62
62
|
"react": "^18.2.0",
|
|
63
63
|
"react-dom": "^18.2.0",
|
|
64
64
|
"rollup-plugin-preserve-directives": "^0.2.0",
|
|
65
|
-
"start-server-and-test": "^2.0.
|
|
66
|
-
"vite": "^
|
|
65
|
+
"start-server-and-test": "^2.0.3",
|
|
66
|
+
"vite": "^5.0.9"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react": "^17.0.0 || ^18.0.0",
|