@storyblok/react 2.0.12 → 2.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/storyblok-react.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(l,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],u):(l=typeof globalThis!="undefined"?globalThis:l||self,u(l.storyblokReact={},l.React))})(this,function(l,u){"use strict";var Te=Object.defineProperty,_e=Object.defineProperties;var Re=Object.getOwnPropertyDescriptors;var T=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var L=(l,u,p)=>u in l?Te(l,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):l[u]=p,y=(l,u)=>{for(var p in u||(u={}))U.call(u,p)&&L(l,p,u[p]);if(T)for(var p of T(u))H.call(u,p)&&L(l,p,u[p]);return l},_=(l,u)=>_e(l,Re(u));var q=(l,u)=>{var p={};for(var f in l)U.call(l,f)&&u.indexOf(f)<0&&(p[f]=l[f]);if(l!=null&&T)for(var f of T(l))u.indexOf(f)<0&&H.call(l,f)&&(p[f]=l[f]);return p};function p(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var f=p(u);let $=!1;const j=[],B=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}$?r():j.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=>{j.forEach(n=>n()),$=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var D=Object.defineProperty,J=(o,e,t)=>e in o?D(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e,t)=>(J(o,typeof e!="symbol"?e+"":e,t),t);function C(o){return!(o!==o||o===1/0||o===-1/0)}function V(o,e,t){if(!C(e))throw new TypeError("Expected `limit` to be a finite number");if(!C(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const c=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(g){return g!==c})},t);r.indexOf(c)<0&&r.push(c);const d=s.shift();d.resolve(o.apply(d.self,d.args))},a=function(...c){const d=this;return new Promise(function(g,E){s.push({resolve:g,reject:E,args:c,self:d}),n<e&&i()})};return a.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(c){c.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},a}const Y=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},z=o=>o==="email",F=()=>({singleTag:"hr"}),G=()=>({tag:"blockquote"}),Q=()=>({tag:"ul"}),W=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),X=()=>({singleTag:"br"}),Z=o=>({tag:`h${o.attrs.level}`}),K=o=>({singleTag:[{tag:"img",attrs:Y(o.attrs,["src","alt","title"])}]}),ee=()=>({tag:"li"}),te=()=>({tag:"ol"}),se=()=>({tag:"p"}),re=()=>({tag:"b"}),oe=()=>({tag:"strike"}),ne=()=>({tag:"u"}),ie=()=>({tag:"strong"}),ae=()=>({tag:"code"}),le=()=>({tag:"i"}),ce=o=>{const e=y({},o.attrs),{linktype:t="url"}=o.attrs;return z(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},he=o=>({tag:[{tag:"span",attrs:o.attrs}]}),O={nodes:{horizontal_rule:F,blockquote:G,bullet_list:Q,code_block:W,hard_break:X,heading:Z,image:K,list_item:ee,ordered_list:te,paragraph:se},marks:{bold:re,strike:oe,underline:ne,strong:ie,code:ae,italic:le,link:ce,styled:he}},ue=function(o){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class k{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=O),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e){if(e&&e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(s=>{t+=this.renderNode(s)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&t.push(this.renderOpeningTag(n.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(ue(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const n=this.getMatchingMark(r);n&&t.push(this.renderClosingTag(n.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 n in s.attrs){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}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)}}class I{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>_(y({},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,(n,i)=>i*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],[]))}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const i=e[n],a=s?"":encodeURIComponent(n);let c;typeof i=="object"?c=this.stringify(i,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(i)):c=(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(i),r.push(c)}return r.join("&")}}class de{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||[],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=y({},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 c=new I;t=`${this.baseURL}${this.url}?${c.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:i}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const c=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(a);const d=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(d)):this._statusHandler(d)}catch(c){return{message:c}}}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 n={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};r(n)})}}let v={};const m={};class pe{constructor(e,t){if(h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),!t){const n=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${n}.storyblok.com/v1`:t=`${i}://api${n}.storyblok.com/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach((n,i)=>{e.headers&&e.headers[i]&&s.set(i,e.headers[i])});let r=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=V(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new I,this.resolveNestedRelations=!1,this.client=new de({baseURL:t,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return 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=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 n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}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,n=`/${e}`,i=n.split("/"),a=s||i[i.length-1],c=1,d=await this.makeRequest(n,t,r,c),g=d.total?Math.ceil(d.total/r):1,E=await this.helpers.asyncMap(this.helpers.range(c,g),P=>this.makeRequest(n,t,r,P+1));return this.helpers.flatMap([d,...E],P=>Object.values(P.data[a]))}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){const s=e[t];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]))}_insertRelations(e,t,s){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t]&&e[t].constructor===Array){const r=[];e[t].forEach(n=>{this.relations[n]&&r.push(this._cleanCopy(this.relations[n]))}),e[t]=r}}}iterateTree(e,t){const s=r=>{if(r!=null){if(r.constructor===Array)for(let n=0;n<r.length;n++)s(r[n]);else if(r.constructor===Object){if(r._stopResolving)return;for(const n in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,n,t),this._insertLinks(r,n)),s(r[n])}}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(r=>{this.links[r.uuid]=_(y({},r),{_stopResolving:!0})})}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]=_(y({},r),{_stopResolving:!0})})}async resolveStories(e,t){var s,r;let n=[];if(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)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((s=e.links)!=null&&s.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const i in this.relations)this.iterateTree(this.relations[i],n);e.story?this.iterateTree(e.story,n):e.stories.forEach(i=>{this.iterateTree(i,n)})}async cacheResponse(e,t,s){const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise((i,a)=>{try{(async()=>{var c;try{const d=await this.throttle("get",e,t);let g={data:d.data,headers:d.headers};return(c=d.headers)!=null&&c["per-page"]&&(g=Object.assign({},g,{perPage:d.headers["per-page"]?parseInt(d.headers["per-page"]):0,total:d.headers["per-page"]?parseInt(d.headers.total):0})),d.status!=200?a(d):((g.data.story||g.data.stories)&&await this.resolveStories(g.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,g),g.data.cv&&t.token&&(t.version=="draft"&&m[t.token]!=g.data.cv&&await this.flushCache(),m[t.token]=g.data.cv),i(g))}catch(d){return a(d)}})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(v[e])},getAll(){return Promise.resolve(v)},set(e,t){return v[e]=t,Promise.resolve(void 0)},flush(){return v={},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 ge=(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 pe(e)}},fe=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let R;const ye="https://app.storyblok.com/f/storyblok-v2-latest.js",w=(o,e,t={})=>{if(!(typeof window>"u")){if(typeof window.storyblokRegisterEvent>"u"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}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"],s=>{s.action==="input"&&s.story.id===o?e(s.story):(s.action==="change"||s.action==="published")&&s.storyId===o&&window.location.reload()})})}},me=(o={})=>{const{bridge:e,accessToken:t,use:s=[],apiOptions:r={},richText:n={}}=o;r.accessToken=r.accessToken||t;const i={bridge:e,apiOptions:r};let a={};return s.forEach(c=>{a=y(y({},a),c(i))}),e!==!1&&B(ye),R=new k(n.schema),n.resolver&&A(R,n.resolver),a},A=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ke=(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 k(e.schema),e.resolver&&A(s,e.resolver)),s.render(o)):(console.warn(`${o} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
1
|
+
(function(l,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],d):(l=typeof globalThis!="undefined"?globalThis:l||self,d(l.storyblokReact={},l.React))})(this,function(l,d){"use strict";var Te=Object.defineProperty,_e=Object.defineProperties;var Re=Object.getOwnPropertyDescriptors;var _=Object.getOwnPropertySymbols;var U=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var L=(l,d,f)=>d in l?Te(l,d,{enumerable:!0,configurable:!0,writable:!0,value:f}):l[d]=f,y=(l,d)=>{for(var f in d||(d={}))U.call(d,f)&&L(l,f,d[f]);if(_)for(var f of _(d))H.call(d,f)&&L(l,f,d[f]);return l},R=(l,d)=>_e(l,Re(d));var q=(l,d)=>{var f={};for(var g in l)U.call(l,g)&&d.indexOf(g)<0&&(f[g]=l[g]);if(l!=null&&_)for(var g of _(l))d.indexOf(g)<0&&H.call(l,g)&&(f[g]=l[g]);return f};function f(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var g=f(d);let $=!1;const j=[],B=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}$?r():j.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=>{j.forEach(n=>n()),$=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var D=Object.defineProperty,J=(o,e,t)=>e in o?D(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,u=(o,e,t)=>(J(o,typeof e!="symbol"?e+"":e,t),t);function C(o){return!(o!==o||o===1/0||o===-1/0)}function V(o,e,t){if(!C(e))throw new TypeError("Expected `limit` to be a finite number");if(!C(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const c=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(p){return p!==c})},t);r.indexOf(c)<0&&r.push(c);const h=s.shift();h.resolve(o.apply(h.self,h.args))},a=function(...c){const h=this;return new Promise(function(p,v){s.push({resolve:p,reject:v,args:c,self:h}),n<e&&i()})};return a.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(c){c.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},a}const Y=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},z=o=>o==="email",F=()=>({singleTag:"hr"}),G=()=>({tag:"blockquote"}),Q=()=>({tag:"ul"}),W=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),X=()=>({singleTag:"br"}),Z=o=>({tag:`h${o.attrs.level}`}),K=o=>({singleTag:[{tag:"img",attrs:Y(o.attrs,["src","alt","title"])}]}),ee=()=>({tag:"li"}),te=()=>({tag:"ol"}),se=()=>({tag:"p"}),re=()=>({tag:"b"}),oe=()=>({tag:"strike"}),ne=()=>({tag:"u"}),ie=()=>({tag:"strong"}),ae=()=>({tag:"code"}),le=()=>({tag:"i"}),ce=o=>{const e=y({},o.attrs),{linktype:t="url"}=o.attrs;return z(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},he=o=>({tag:[{tag:"span",attrs:o.attrs}]}),O={nodes:{horizontal_rule:F,blockquote:G,bullet_list:Q,code_block:W,hard_break:X,heading:Z,image:K,list_item:ee,ordered_list:te,paragraph:se},marks:{bold:re,strike:oe,underline:ne,strong:ie,code:ae,italic:le,link:ce,styled:he}},ue=function(o){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class k{constructor(e){u(this,"marks"),u(this,"nodes"),e||(e=O),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e){if(e&&e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(s=>{t+=this.renderNode(s)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&t.push(this.renderOpeningTag(n.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(ue(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const n=this.getMatchingMark(r);n&&t.push(this.renderClosingTag(n.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 n in s.attrs){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}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)}}class I{constructor(){u(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),u(this,"getOptionsPage",(e,t=25,s=1)=>R(y({},e),{per_page:t,page:s})),u(this,"delay",e=>new Promise(t=>setTimeout(t,e))),u(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),u(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(n,i)=>i*r+e)}),u(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),u(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]))}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const i=e[n],a=s?"":encodeURIComponent(n);let c;typeof i=="object"?c=this.stringify(i,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(i)):c=(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(i),r.push(c)}return r.join("&")}}class de{constructor(e){u(this,"baseURL"),u(this,"timeout"),u(this,"headers"),u(this,"responseInterceptor"),u(this,"fetch"),u(this,"ejectInterceptor"),u(this,"url"),u(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.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=y({},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 c=new I;t=`${this.baseURL}${this.url}?${c.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:i}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const c=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(a);const h=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(h)):this._statusHandler(h)}catch(c){return{message:c}}}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 n={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};r(n)})}}let w={};const m={};class pe{constructor(e,t){if(u(this,"client"),u(this,"maxRetries"),u(this,"throttle"),u(this,"accessToken"),u(this,"cache"),u(this,"helpers"),u(this,"relations"),u(this,"links"),u(this,"richTextResolver"),u(this,"resolveNestedRelations"),!t){const n=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${n}.storyblok.com/v1`:t=`${i}://api${n}.storyblok.com/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach((n,i)=>{e.headers&&e.headers[i]&&s.set(i,e.headers[i])});let r=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=V(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new I,this.resolveNestedRelations=!1,this.client=new de({baseURL:t,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return 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=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 n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}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,n=`/${e}`,i=n.split("/"),a=s||i[i.length-1],c=1,h=await this.makeRequest(n,t,r,c),p=h.total?Math.ceil(h.total/r):1,v=await this.helpers.asyncMap(this.helpers.range(c,p),P=>this.makeRequest(n,t,r,P+1));return this.helpers.flatMap([h,...v],P=>Object.values(P.data[a]))}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){const s=e[t];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]))}_insertRelations(e,t,s){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t]&&e[t].constructor===Array){const r=[];e[t].forEach(n=>{this.relations[n]&&r.push(this._cleanCopy(this.relations[n]))}),e[t]=r}}}iterateTree(e,t){const s=r=>{if(r!=null){if(r.constructor===Array)for(let n=0;n<r.length;n++)s(r[n]);else if(r.constructor===Object){if(r._stopResolving)return;for(const n in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,n,t),this._insertLinks(r,n)),s(r[n])}}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(r=>{this.links[r.uuid]=R(y({},r),{_stopResolving:!0})})}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]=R(y({},r),{_stopResolving:!0})})}async resolveStories(e,t){var s,r;let n=[];if(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)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((s=e.links)!=null&&s.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const i in this.relations)this.iterateTree(this.relations[i],n);e.story?this.iterateTree(e.story,n):e.stories.forEach(i=>{this.iterateTree(i,n)})}async cacheResponse(e,t,s){const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise((i,a)=>{try{(async()=>{var c;try{const h=await this.throttle("get",e,t);let p={data:h.data,headers:h.headers};return(c=h.headers)!=null&&c["per-page"]&&(p=Object.assign({},p,{perPage:h.headers["per-page"]?parseInt(h.headers["per-page"]):0,total:h.headers["per-page"]?parseInt(h.headers.total):0})),h.status!=200?a(h):((p.data.story||p.data.stories)&&await this.resolveStories(p.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,p),p.data.cv&&t.token&&(t.version=="draft"&&m[t.token]!=p.data.cv&&await this.flushCache(),m[t.token]=p.data.cv),i(p))}catch(h){return a(h)}})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(w[e])},getAll(){return Promise.resolve(w)},set(e,t){return w[e]=t,Promise.resolve(void 0)},flush(){return w={},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 fe=(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 pe(e)}},ge=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let S;const ye="https://app.storyblok.com/f/storyblok-v2-latest.js",T=(o,e,t={})=>{if(!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u"){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"],s=>{s.action==="input"&&s.story.id===o?e(s.story):(s.action==="change"||s.action==="published")&&s.storyId===o&&window.location.reload()})})}},me=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:n=[],apiOptions:i={},richText:a={}}=o;i.accessToken=i.accessToken||r;const c={bridge:s,apiOptions:i};let h={};n.forEach(v=>{h=y(y({},h),v(c))});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&&B(ye),S=new k(a.schema),a.resolver&&A(S,a.resolver),h},A=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ke=(o,e,t)=>{let s=t||S;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return o===""?"":o?(e&&(s=new k(e.schema),e.resolver&&A(s,e.resolver)),s.render(o)):(console.warn(`${o} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
2
2
|
|
|
3
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},x=
|
|
3
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},x=d.forwardRef((s,t)=>{var r=s,{blok:o}=r,e=q(r,["blok"]);if(!o)return console.error("Please provide a 'blok' property to the StoryblokComponent"),g.default.createElement("div",null,"Please provide a blok property to the StoryblokComponent");const n=N(o.component);return n?g.default.createElement(n,y({ref:t,blok:o},e)):g.default.createElement("div",null)});x.displayName="StoryblokComponent";const be=(o,e={},t={})=>{let[s,r]=d.useState({});if(!b)return console.error("You can't use useStoryblok if you're not loading apiPlugin."),null;const n=typeof window!="undefined"&&typeof window.storyblokRegisterEvent!="undefined";return d.useEffect(()=>{async function i(){const{data:a}=await b.get(`cdn/stories/${o}`,e);r(a.story),n&&a.story.id&&T(a.story.id,c=>r(c),t)}i()},[o]),s},ve=(o=null,e={})=>{let[t,s]=d.useState(o);return!(typeof window!="undefined"&&typeof window.storyblokRegisterEvent!="undefined")||!o?o:(d.useEffect(()=>{s(o),T(t.id,n=>s(n),e)},[o]),t)};let b=null;const M=()=>(b||console.error("You can't use getStoryblokApi if you're not loading apiPlugin."),b);let E={};const N=o=>E[o]?E[o]:(console.error(`Component ${o} doesn't exist.`),!1),we=(o={})=>{const{storyblokApi:e}=me(o);b=e,E=o.components};l.RichTextResolver=k,l.RichTextSchema=O,l.StoryblokComponent=x,l.apiPlugin=fe,l.getComponent=N,l.getStoryblokApi=M,l.registerStoryblokBridge=T,l.renderRichText=ke,l.storyblokEditable=ge,l.storyblokInit=we,l.useStoryblok=be,l.useStoryblokApi=M,l.useStoryblokBridge=T,l.useStoryblokState=ve,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-react.mjs
CHANGED
|
@@ -30,91 +30,91 @@ var __objRest = (source, exclude) => {
|
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
32
|
import React, { forwardRef, useState, useEffect } from "react";
|
|
33
|
-
let
|
|
34
|
-
const
|
|
33
|
+
let v = false;
|
|
34
|
+
const k = [], w = (o) => new Promise((t, e) => {
|
|
35
35
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
|
36
36
|
if (window.location === window.parent.location) {
|
|
37
37
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
v ? r() : k.push(r);
|
|
41
41
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
42
42
|
return;
|
|
43
43
|
const s = document.createElement("script");
|
|
44
|
-
s.async = true, s.src =
|
|
45
|
-
|
|
44
|
+
s.async = true, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => e(r), s.onload = (r) => {
|
|
45
|
+
k.forEach((n) => n()), v = true, t(r);
|
|
46
46
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
47
47
|
});
|
|
48
|
-
var $ = Object.defineProperty, P = (
|
|
49
|
-
function b(
|
|
50
|
-
return !(
|
|
48
|
+
var $ = Object.defineProperty, P = (o, t, e) => t in o ? $(o, t, { enumerable: true, configurable: true, writable: true, value: e }) : o[t] = e, l = (o, t, e) => (P(o, typeof t != "symbol" ? t + "" : t, e), e);
|
|
49
|
+
function b(o) {
|
|
50
|
+
return !(o !== o || o === 1 / 0 || o === -1 / 0);
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function x(o, t, e) {
|
|
53
53
|
if (!b(t))
|
|
54
54
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
55
55
|
if (!b(e))
|
|
56
56
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
57
57
|
const s = [];
|
|
58
|
-
let r = [],
|
|
58
|
+
let r = [], n = 0;
|
|
59
59
|
const i = function() {
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
return u !==
|
|
60
|
+
n++;
|
|
61
|
+
const c = setTimeout(function() {
|
|
62
|
+
n--, s.length > 0 && i(), r = r.filter(function(u) {
|
|
63
|
+
return u !== c;
|
|
64
64
|
});
|
|
65
65
|
}, e);
|
|
66
|
-
r.indexOf(
|
|
66
|
+
r.indexOf(c) < 0 && r.push(c);
|
|
67
67
|
const h = s.shift();
|
|
68
|
-
h.resolve(
|
|
69
|
-
}, a = function(...
|
|
68
|
+
h.resolve(o.apply(h.self, h.args));
|
|
69
|
+
}, a = function(...c) {
|
|
70
70
|
const h = this;
|
|
71
|
-
return new Promise(function(u,
|
|
71
|
+
return new Promise(function(u, d) {
|
|
72
72
|
s.push({
|
|
73
73
|
resolve: u,
|
|
74
|
-
reject:
|
|
75
|
-
args:
|
|
74
|
+
reject: d,
|
|
75
|
+
args: c,
|
|
76
76
|
self: h
|
|
77
|
-
}),
|
|
77
|
+
}), n < t && i();
|
|
78
78
|
});
|
|
79
79
|
};
|
|
80
80
|
return a.abort = function() {
|
|
81
|
-
r.forEach(clearTimeout), r = [], s.forEach(function(
|
|
82
|
-
|
|
81
|
+
r.forEach(clearTimeout), r = [], s.forEach(function(c) {
|
|
82
|
+
c.reject(function() {
|
|
83
83
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
84
84
|
});
|
|
85
85
|
}), s.length = 0;
|
|
86
86
|
}, a;
|
|
87
87
|
}
|
|
88
|
-
const
|
|
88
|
+
const E = function(o, t) {
|
|
89
89
|
const e = {};
|
|
90
|
-
for (const s in
|
|
91
|
-
const r =
|
|
90
|
+
for (const s in o) {
|
|
91
|
+
const r = o[s];
|
|
92
92
|
t.indexOf(s) > -1 && r !== null && (e[s] = r);
|
|
93
93
|
}
|
|
94
94
|
return e;
|
|
95
|
-
},
|
|
95
|
+
}, j = (o) => o === "email", S = () => ({
|
|
96
96
|
singleTag: "hr"
|
|
97
97
|
}), O = () => ({
|
|
98
98
|
tag: "blockquote"
|
|
99
99
|
}), C = () => ({
|
|
100
100
|
tag: "ul"
|
|
101
|
-
}), I = (
|
|
101
|
+
}), I = (o) => ({
|
|
102
102
|
tag: [
|
|
103
103
|
"pre",
|
|
104
104
|
{
|
|
105
105
|
tag: "code",
|
|
106
|
-
attrs:
|
|
106
|
+
attrs: o.attrs
|
|
107
107
|
}
|
|
108
108
|
]
|
|
109
109
|
}), A = () => ({
|
|
110
110
|
singleTag: "br"
|
|
111
|
-
}), N = (
|
|
112
|
-
tag: `h${
|
|
113
|
-
}), M = (
|
|
111
|
+
}), N = (o) => ({
|
|
112
|
+
tag: `h${o.attrs.level}`
|
|
113
|
+
}), M = (o) => ({
|
|
114
114
|
singleTag: [
|
|
115
115
|
{
|
|
116
116
|
tag: "img",
|
|
117
|
-
attrs:
|
|
117
|
+
attrs: E(o.attrs, ["src", "alt", "title"])
|
|
118
118
|
}
|
|
119
119
|
]
|
|
120
120
|
}), L = () => ({
|
|
@@ -135,9 +135,9 @@ const x = function(n, t) {
|
|
|
135
135
|
tag: "code"
|
|
136
136
|
}), V = () => ({
|
|
137
137
|
tag: "i"
|
|
138
|
-
}), z = (
|
|
139
|
-
const t = __spreadValues({},
|
|
140
|
-
return
|
|
138
|
+
}), z = (o) => {
|
|
139
|
+
const t = __spreadValues({}, o.attrs), { linktype: e = "url" } = o.attrs;
|
|
140
|
+
return j(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
|
|
141
141
|
tag: [
|
|
142
142
|
{
|
|
143
143
|
tag: "a",
|
|
@@ -145,11 +145,11 @@ const x = function(n, t) {
|
|
|
145
145
|
}
|
|
146
146
|
]
|
|
147
147
|
};
|
|
148
|
-
}, Y = (
|
|
148
|
+
}, Y = (o) => ({
|
|
149
149
|
tag: [
|
|
150
150
|
{
|
|
151
151
|
tag: "span",
|
|
152
|
-
attrs:
|
|
152
|
+
attrs: o.attrs
|
|
153
153
|
}
|
|
154
154
|
]
|
|
155
155
|
}), K = {
|
|
@@ -175,7 +175,7 @@ const x = function(n, t) {
|
|
|
175
175
|
link: z,
|
|
176
176
|
styled: Y
|
|
177
177
|
}
|
|
178
|
-
}, Q = function(
|
|
178
|
+
}, Q = function(o) {
|
|
179
179
|
const t = {
|
|
180
180
|
"&": "&",
|
|
181
181
|
"<": "<",
|
|
@@ -183,11 +183,11 @@ const x = function(n, t) {
|
|
|
183
183
|
'"': """,
|
|
184
184
|
"'": "'"
|
|
185
185
|
}, e = /[&<>"']/g, s = RegExp(e.source);
|
|
186
|
-
return
|
|
186
|
+
return o && s.test(o) ? o.replace(e, (r) => t[r]) : o;
|
|
187
187
|
};
|
|
188
|
-
class
|
|
188
|
+
class m {
|
|
189
189
|
constructor(t) {
|
|
190
|
-
|
|
190
|
+
l(this, "marks"), l(this, "nodes"), t || (t = K), this.marks = t.marks || [], this.nodes = t.nodes || [];
|
|
191
191
|
}
|
|
192
192
|
addNode(t, e) {
|
|
193
193
|
this.nodes[t] = e;
|
|
@@ -207,15 +207,15 @@ class g {
|
|
|
207
207
|
renderNode(t) {
|
|
208
208
|
const e = [];
|
|
209
209
|
t.marks && t.marks.forEach((r) => {
|
|
210
|
-
const
|
|
211
|
-
|
|
210
|
+
const n = this.getMatchingMark(r);
|
|
211
|
+
n && e.push(this.renderOpeningTag(n.tag));
|
|
212
212
|
});
|
|
213
213
|
const s = this.getMatchingNode(t);
|
|
214
214
|
return s && s.tag && e.push(this.renderOpeningTag(s.tag)), t.content ? t.content.forEach((r) => {
|
|
215
215
|
e.push(this.renderNode(r));
|
|
216
216
|
}) : t.text ? e.push(Q(t.text)) : s && s.singleTag ? e.push(this.renderTag(s.singleTag, " /")) : s && s.html && e.push(s.html), s && s.tag && e.push(this.renderClosingTag(s.tag)), t.marks && t.marks.slice(0).reverse().forEach((r) => {
|
|
217
|
-
const
|
|
218
|
-
|
|
217
|
+
const n = this.getMatchingMark(r);
|
|
218
|
+
n && e.push(this.renderClosingTag(n.tag));
|
|
219
219
|
}), e.join("");
|
|
220
220
|
}
|
|
221
221
|
renderTag(t, e) {
|
|
@@ -225,9 +225,9 @@ class g {
|
|
|
225
225
|
{
|
|
226
226
|
let r = `<${s.tag}`;
|
|
227
227
|
if (s.attrs)
|
|
228
|
-
for (const
|
|
229
|
-
const i = s.attrs[
|
|
230
|
-
i !== null && (r += ` ${
|
|
228
|
+
for (const n in s.attrs) {
|
|
229
|
+
const i = s.attrs[n];
|
|
230
|
+
i !== null && (r += ` ${n}="${i}"`);
|
|
231
231
|
}
|
|
232
232
|
return `${r}${e}>`;
|
|
233
233
|
}
|
|
@@ -252,29 +252,29 @@ class g {
|
|
|
252
252
|
}
|
|
253
253
|
class T {
|
|
254
254
|
constructor() {
|
|
255
|
-
|
|
255
|
+
l(this, "isCDNUrl", (t = "") => t.indexOf("/cdn/") > -1), l(this, "getOptionsPage", (t, e = 25, s = 1) => __spreadProps(__spreadValues({}, t), {
|
|
256
256
|
per_page: e,
|
|
257
257
|
page: s
|
|
258
|
-
})),
|
|
258
|
+
})), l(this, "delay", (t) => new Promise((e) => setTimeout(e, t))), l(this, "arrayFrom", (t = 0, e) => [...Array(t)].map(e)), l(this, "range", (t = 0, e = t) => {
|
|
259
259
|
const s = Math.abs(e - t) || 0, r = t < e ? 1 : -1;
|
|
260
|
-
return this.arrayFrom(s, (
|
|
261
|
-
}),
|
|
260
|
+
return this.arrayFrom(s, (n, i) => i * r + t);
|
|
261
|
+
}), l(this, "asyncMap", async (t, e) => Promise.all(t.map(e))), l(this, "flatMap", (t = [], e) => t.map(e).reduce((s, r) => [...s, ...r], []));
|
|
262
262
|
}
|
|
263
263
|
stringify(t, e, s) {
|
|
264
264
|
const r = [];
|
|
265
|
-
for (const
|
|
266
|
-
if (!Object.prototype.hasOwnProperty.call(t,
|
|
265
|
+
for (const n in t) {
|
|
266
|
+
if (!Object.prototype.hasOwnProperty.call(t, n))
|
|
267
267
|
continue;
|
|
268
|
-
const i = t[
|
|
269
|
-
let
|
|
270
|
-
typeof i == "object" ?
|
|
268
|
+
const i = t[n], a = s ? "" : encodeURIComponent(n);
|
|
269
|
+
let c;
|
|
270
|
+
typeof i == "object" ? c = this.stringify(i, e ? e + encodeURIComponent("[" + a + "]") : a, Array.isArray(i)) : c = (e ? e + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(i), r.push(c);
|
|
271
271
|
}
|
|
272
272
|
return r.join("&");
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
class G {
|
|
276
276
|
constructor(t) {
|
|
277
|
-
|
|
277
|
+
l(this, "baseURL"), l(this, "timeout"), l(this, "headers"), l(this, "responseInterceptor"), l(this, "fetch"), l(this, "ejectInterceptor"), l(this, "url"), l(this, "parameters"), this.baseURL = t.baseURL, this.headers = t.headers || [], this.timeout = t != null && t.timeout ? t.timeout * 1e3 : 0, this.responseInterceptor = t.responseInterceptor, this.fetch = (...e) => t.fetch ? t.fetch(...e) : fetch(...e), this.ejectInterceptor = false, this.url = "", this.parameters = {};
|
|
278
278
|
}
|
|
279
279
|
get(t, e) {
|
|
280
280
|
return this.url = t, this.parameters = e, this._methodHandler("get");
|
|
@@ -305,26 +305,26 @@ class G {
|
|
|
305
305
|
async _methodHandler(t) {
|
|
306
306
|
let e = `${this.baseURL}${this.url}`, s = null;
|
|
307
307
|
if (t === "get") {
|
|
308
|
-
const
|
|
309
|
-
e = `${this.baseURL}${this.url}?${
|
|
308
|
+
const c = new T();
|
|
309
|
+
e = `${this.baseURL}${this.url}?${c.stringify(this.parameters)}`;
|
|
310
310
|
} else
|
|
311
311
|
s = JSON.stringify(this.parameters);
|
|
312
|
-
const r = new URL(e),
|
|
312
|
+
const r = new URL(e), n = new AbortController(), { signal: i } = n;
|
|
313
313
|
let a;
|
|
314
|
-
this.timeout && (a = setTimeout(() =>
|
|
314
|
+
this.timeout && (a = setTimeout(() => n.abort(), this.timeout));
|
|
315
315
|
try {
|
|
316
|
-
const
|
|
316
|
+
const c = await this.fetch(`${r}`, {
|
|
317
317
|
method: t,
|
|
318
318
|
headers: this.headers,
|
|
319
319
|
body: s,
|
|
320
320
|
signal: i
|
|
321
321
|
});
|
|
322
322
|
this.timeout && clearTimeout(a);
|
|
323
|
-
const h = await this._responseHandler(
|
|
323
|
+
const h = await this._responseHandler(c);
|
|
324
324
|
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(h)) : this._statusHandler(h);
|
|
325
|
-
} catch (
|
|
325
|
+
} catch (c) {
|
|
326
326
|
return {
|
|
327
|
-
message:
|
|
327
|
+
message: c
|
|
328
328
|
};
|
|
329
329
|
}
|
|
330
330
|
}
|
|
@@ -336,29 +336,29 @@ class G {
|
|
|
336
336
|
return new Promise((s, r) => {
|
|
337
337
|
if (e.test(`${t.status}`))
|
|
338
338
|
return s(t);
|
|
339
|
-
const
|
|
339
|
+
const n = {
|
|
340
340
|
message: new Error(t.statusText),
|
|
341
341
|
status: t.status,
|
|
342
342
|
response: t.data.error || t.data.slug
|
|
343
343
|
};
|
|
344
|
-
r(
|
|
344
|
+
r(n);
|
|
345
345
|
});
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
|
-
let
|
|
349
|
-
const
|
|
348
|
+
let f = {};
|
|
349
|
+
const p = {};
|
|
350
350
|
class W {
|
|
351
351
|
constructor(t, e) {
|
|
352
|
-
if (
|
|
353
|
-
const
|
|
354
|
-
t.oauthToken ? e = `${i}://api${
|
|
352
|
+
if (l(this, "client"), l(this, "maxRetries"), l(this, "throttle"), l(this, "accessToken"), l(this, "cache"), l(this, "helpers"), l(this, "relations"), l(this, "links"), l(this, "richTextResolver"), l(this, "resolveNestedRelations"), !e) {
|
|
353
|
+
const n = t.region ? `-${t.region}` : "", i = t.https === false ? "http" : "https";
|
|
354
|
+
t.oauthToken ? e = `${i}://api${n}.storyblok.com/v1` : e = `${i}://api${n}.storyblok.com/v2`;
|
|
355
355
|
}
|
|
356
356
|
const s = new Headers();
|
|
357
|
-
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((
|
|
357
|
+
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((n, i) => {
|
|
358
358
|
t.headers && t.headers[i] && s.set(i, t.headers[i]);
|
|
359
359
|
});
|
|
360
360
|
let r = 5;
|
|
361
|
-
t.oauthToken && (s.set("Authorization", t.oauthToken), r = 3), t.rateLimit && (r = t.rateLimit), t.richTextSchema ? this.richTextResolver = new
|
|
361
|
+
t.oauthToken && (s.set("Authorization", t.oauthToken), r = 3), t.rateLimit && (r = t.rateLimit), t.richTextSchema ? this.richTextResolver = new m(t.richTextSchema) : this.richTextResolver = new m(), t.componentResolver && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries, this.throttle = x(this.throttledRequest, r, 1e3), this.accessToken = t.accessToken || "", this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.helpers = new T(), this.resolveNestedRelations = false, this.client = new G({
|
|
362
362
|
baseURL: e,
|
|
363
363
|
timeout: t.timeout || 0,
|
|
364
364
|
headers: s,
|
|
@@ -377,14 +377,14 @@ class W {
|
|
|
377
377
|
});
|
|
378
378
|
}
|
|
379
379
|
parseParams(t) {
|
|
380
|
-
return t.version || (t.version = "published"), t.token || (t.token = this.getToken()), t.cv || (t.cv =
|
|
380
|
+
return t.version || (t.version = "published"), t.token || (t.token = this.getToken()), t.cv || (t.cv = p[t.token]), Array.isArray(t.resolve_relations) && (t.resolve_relations = t.resolve_relations.join(",")), t;
|
|
381
381
|
}
|
|
382
382
|
factoryParamOptions(t, e) {
|
|
383
383
|
return this.helpers.isCDNUrl(t) ? this.parseParams(e) : e;
|
|
384
384
|
}
|
|
385
385
|
makeRequest(t, e, s, r) {
|
|
386
|
-
const
|
|
387
|
-
return this.cacheResponse(t,
|
|
386
|
+
const n = this.factoryParamOptions(t, this.helpers.getOptionsPage(e, s, r));
|
|
387
|
+
return this.cacheResponse(t, n);
|
|
388
388
|
}
|
|
389
389
|
get(t, e) {
|
|
390
390
|
e || (e = {});
|
|
@@ -392,8 +392,8 @@ class W {
|
|
|
392
392
|
return this.cacheResponse(s, r);
|
|
393
393
|
}
|
|
394
394
|
async getAll(t, e, s) {
|
|
395
|
-
const r = (e == null ? void 0 : e.per_page) || 25,
|
|
396
|
-
return this.helpers.flatMap([h, ...
|
|
395
|
+
const r = (e == null ? void 0 : e.per_page) || 25, n = `/${t}`, i = n.split("/"), a = s || i[i.length - 1], c = 1, h = await this.makeRequest(n, e, r, c), u = h.total ? Math.ceil(h.total / r) : 1, d = await this.helpers.asyncMap(this.helpers.range(c, u), (g) => this.makeRequest(n, e, r, g + 1));
|
|
396
|
+
return this.helpers.flatMap([h, ...d], (g) => Object.values(g.data[a]));
|
|
397
397
|
}
|
|
398
398
|
post(t, e) {
|
|
399
399
|
const s = `/${t}`;
|
|
@@ -432,8 +432,8 @@ class W {
|
|
|
432
432
|
this.relations[t[e]] && (t[e] = this._cleanCopy(this.relations[t[e]]));
|
|
433
433
|
else if (t[e] && t[e].constructor === Array) {
|
|
434
434
|
const r = [];
|
|
435
|
-
t[e].forEach((
|
|
436
|
-
this.relations[
|
|
435
|
+
t[e].forEach((n) => {
|
|
436
|
+
this.relations[n] && r.push(this._cleanCopy(this.relations[n]));
|
|
437
437
|
}), t[e] = r;
|
|
438
438
|
}
|
|
439
439
|
}
|
|
@@ -442,13 +442,13 @@ class W {
|
|
|
442
442
|
const s = (r) => {
|
|
443
443
|
if (r != null) {
|
|
444
444
|
if (r.constructor === Array)
|
|
445
|
-
for (let
|
|
446
|
-
s(r[
|
|
445
|
+
for (let n = 0; n < r.length; n++)
|
|
446
|
+
s(r[n]);
|
|
447
447
|
else if (r.constructor === Object) {
|
|
448
448
|
if (r._stopResolving)
|
|
449
449
|
return;
|
|
450
|
-
for (const
|
|
451
|
-
(r.component && r._uid || r.type === "link") && (this._insertRelations(r,
|
|
450
|
+
for (const n in r)
|
|
451
|
+
(r.component && r._uid || r.type === "link") && (this._insertRelations(r, n, e), this._insertLinks(r, n)), s(r[n]);
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
454
|
};
|
|
@@ -457,19 +457,19 @@ class W {
|
|
|
457
457
|
async resolveLinks(t, e) {
|
|
458
458
|
let s = [];
|
|
459
459
|
if (t.link_uuids) {
|
|
460
|
-
const r = t.link_uuids.length,
|
|
460
|
+
const r = t.link_uuids.length, n = [], i = 50;
|
|
461
461
|
for (let a = 0; a < r; a += i) {
|
|
462
|
-
const
|
|
463
|
-
|
|
462
|
+
const c = Math.min(r, a + i);
|
|
463
|
+
n.push(t.link_uuids.slice(a, c));
|
|
464
464
|
}
|
|
465
|
-
for (let a = 0; a <
|
|
465
|
+
for (let a = 0; a < n.length; a++)
|
|
466
466
|
(await this.getStories({
|
|
467
467
|
per_page: i,
|
|
468
468
|
language: e.language,
|
|
469
469
|
version: e.version,
|
|
470
|
-
by_uuids:
|
|
471
|
-
})).data.stories.forEach((
|
|
472
|
-
s.push(
|
|
470
|
+
by_uuids: n[a].join(",")
|
|
471
|
+
})).data.stories.forEach((c) => {
|
|
472
|
+
s.push(c);
|
|
473
473
|
});
|
|
474
474
|
} else
|
|
475
475
|
s = t.links;
|
|
@@ -480,19 +480,19 @@ class W {
|
|
|
480
480
|
async resolveRelations(t, e) {
|
|
481
481
|
let s = [];
|
|
482
482
|
if (t.rel_uuids) {
|
|
483
|
-
const r = t.rel_uuids.length,
|
|
483
|
+
const r = t.rel_uuids.length, n = [], i = 50;
|
|
484
484
|
for (let a = 0; a < r; a += i) {
|
|
485
|
-
const
|
|
486
|
-
|
|
485
|
+
const c = Math.min(r, a + i);
|
|
486
|
+
n.push(t.rel_uuids.slice(a, c));
|
|
487
487
|
}
|
|
488
|
-
for (let a = 0; a <
|
|
488
|
+
for (let a = 0; a < n.length; a++)
|
|
489
489
|
(await this.getStories({
|
|
490
490
|
per_page: i,
|
|
491
491
|
language: e.language,
|
|
492
492
|
version: e.version,
|
|
493
|
-
by_uuids:
|
|
494
|
-
})).data.stories.forEach((
|
|
495
|
-
s.push(
|
|
493
|
+
by_uuids: n[a].join(",")
|
|
494
|
+
})).data.stories.forEach((c) => {
|
|
495
|
+
s.push(c);
|
|
496
496
|
});
|
|
497
497
|
} else
|
|
498
498
|
s = t.rels;
|
|
@@ -502,32 +502,32 @@ class W {
|
|
|
502
502
|
}
|
|
503
503
|
async resolveStories(t, e) {
|
|
504
504
|
var s, r;
|
|
505
|
-
let
|
|
506
|
-
if (typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (
|
|
505
|
+
let n = [];
|
|
506
|
+
if (typeof e.resolve_relations < "u" && e.resolve_relations.length > 0 && (typeof e.resolve_relations == "string" && (n = e.resolve_relations.split(",")), await this.resolveRelations(t, e)), e.resolve_links && ["1", "story", "url"].indexOf(e.resolve_links) > -1 && ((s = t.links) != null && s.length || (r = t.link_uuids) != null && r.length) && await this.resolveLinks(t, e), this.resolveNestedRelations)
|
|
507
507
|
for (const i in this.relations)
|
|
508
|
-
this.iterateTree(this.relations[i],
|
|
509
|
-
t.story ? this.iterateTree(t.story,
|
|
510
|
-
this.iterateTree(i,
|
|
508
|
+
this.iterateTree(this.relations[i], n);
|
|
509
|
+
t.story ? this.iterateTree(t.story, n) : t.stories.forEach((i) => {
|
|
510
|
+
this.iterateTree(i, n);
|
|
511
511
|
});
|
|
512
512
|
}
|
|
513
513
|
async cacheResponse(t, e, s) {
|
|
514
|
-
const r = this.helpers.stringify({ url: t, params: e }),
|
|
514
|
+
const r = this.helpers.stringify({ url: t, params: e }), n = this.cacheProvider();
|
|
515
515
|
if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
|
|
516
|
-
const i = await
|
|
516
|
+
const i = await n.get(r);
|
|
517
517
|
if (i)
|
|
518
518
|
return Promise.resolve(i);
|
|
519
519
|
}
|
|
520
520
|
return new Promise((i, a) => {
|
|
521
521
|
try {
|
|
522
522
|
(async () => {
|
|
523
|
-
var
|
|
523
|
+
var c;
|
|
524
524
|
try {
|
|
525
525
|
const h = await this.throttle("get", t, e);
|
|
526
526
|
let u = { data: h.data, headers: h.headers };
|
|
527
|
-
return (
|
|
527
|
+
return (c = h.headers) != null && c["per-page"] && (u = Object.assign({}, u, {
|
|
528
528
|
perPage: h.headers["per-page"] ? parseInt(h.headers["per-page"]) : 0,
|
|
529
529
|
total: h.headers["per-page"] ? parseInt(h.headers.total) : 0
|
|
530
|
-
})), h.status != 200 ? a(h) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, e), e.version === "published" && t != "/cdn/spaces/me" && await
|
|
530
|
+
})), h.status != 200 ? a(h) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, e), e.version === "published" && t != "/cdn/spaces/me" && await n.set(r, u), u.data.cv && e.token && (e.version == "draft" && p[e.token] != u.data.cv && await this.flushCache(), p[e.token] = u.data.cv), i(u));
|
|
531
531
|
} catch (h) {
|
|
532
532
|
return a(h);
|
|
533
533
|
}
|
|
@@ -540,29 +540,29 @@ class W {
|
|
|
540
540
|
return this.client[t](e, s);
|
|
541
541
|
}
|
|
542
542
|
cacheVersions() {
|
|
543
|
-
return
|
|
543
|
+
return p;
|
|
544
544
|
}
|
|
545
545
|
cacheVersion() {
|
|
546
|
-
return
|
|
546
|
+
return p[this.accessToken];
|
|
547
547
|
}
|
|
548
548
|
setCacheVersion(t) {
|
|
549
|
-
this.accessToken && (
|
|
549
|
+
this.accessToken && (p[this.accessToken] = t);
|
|
550
550
|
}
|
|
551
551
|
cacheProvider() {
|
|
552
552
|
switch (this.cache.type) {
|
|
553
553
|
case "memory":
|
|
554
554
|
return {
|
|
555
555
|
get(t) {
|
|
556
|
-
return Promise.resolve(
|
|
556
|
+
return Promise.resolve(f[t]);
|
|
557
557
|
},
|
|
558
558
|
getAll() {
|
|
559
|
-
return Promise.resolve(
|
|
559
|
+
return Promise.resolve(f);
|
|
560
560
|
},
|
|
561
561
|
set(t, e) {
|
|
562
|
-
return
|
|
562
|
+
return f[t] = e, Promise.resolve(void 0);
|
|
563
563
|
},
|
|
564
564
|
flush() {
|
|
565
|
-
return
|
|
565
|
+
return f = {}, Promise.resolve(void 0);
|
|
566
566
|
}
|
|
567
567
|
};
|
|
568
568
|
case "custom":
|
|
@@ -589,55 +589,54 @@ class W {
|
|
|
589
589
|
return await this.cacheProvider().flush(), this;
|
|
590
590
|
}
|
|
591
591
|
}
|
|
592
|
-
const X = (
|
|
593
|
-
const { apiOptions: t } =
|
|
592
|
+
const X = (o = {}) => {
|
|
593
|
+
const { apiOptions: t } = o;
|
|
594
594
|
if (!t.accessToken) {
|
|
595
595
|
console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");
|
|
596
596
|
return;
|
|
597
597
|
}
|
|
598
598
|
return { storyblokApi: new W(t) };
|
|
599
|
-
}, Z = (
|
|
600
|
-
if (typeof
|
|
599
|
+
}, Z = (o) => {
|
|
600
|
+
if (typeof o != "object" || typeof o._editable > "u")
|
|
601
601
|
return {};
|
|
602
|
-
const t = JSON.parse(
|
|
602
|
+
const t = JSON.parse(o._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
|
|
603
603
|
return {
|
|
604
604
|
"data-blok-c": JSON.stringify(t),
|
|
605
605
|
"data-blok-uid": t.id + "-" + t.uid
|
|
606
606
|
};
|
|
607
607
|
};
|
|
608
608
|
let y;
|
|
609
|
-
const
|
|
610
|
-
if (!(typeof window > "u")) {
|
|
611
|
-
if (
|
|
612
|
-
console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
if (!n) {
|
|
609
|
+
const _ = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt = (o, t, e = {}) => {
|
|
610
|
+
if (!(typeof window > "u") && typeof window.storyblokRegisterEvent < "u") {
|
|
611
|
+
if (!o) {
|
|
616
612
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
617
613
|
return;
|
|
618
614
|
}
|
|
619
615
|
window.storyblokRegisterEvent(() => {
|
|
620
|
-
new window.StoryblokBridge(e).on(["input", "published", "change"], (
|
|
621
|
-
|
|
616
|
+
new window.StoryblokBridge(e).on(["input", "published", "change"], (i) => {
|
|
617
|
+
i.action === "input" && i.story.id === o ? t(i.story) : (i.action === "change" || i.action === "published") && i.storyId === o && window.location.reload();
|
|
622
618
|
});
|
|
623
619
|
});
|
|
624
620
|
}
|
|
625
|
-
}, et = (
|
|
621
|
+
}, et = (o = {}) => {
|
|
622
|
+
var u, d;
|
|
626
623
|
const {
|
|
627
624
|
bridge: t,
|
|
628
625
|
accessToken: e,
|
|
629
626
|
use: s = [],
|
|
630
627
|
apiOptions: r = {},
|
|
631
|
-
richText:
|
|
632
|
-
} =
|
|
628
|
+
richText: n = {}
|
|
629
|
+
} = o;
|
|
633
630
|
r.accessToken = r.accessToken || e;
|
|
634
631
|
const i = { bridge: t, apiOptions: r };
|
|
635
632
|
let a = {};
|
|
636
|
-
|
|
637
|
-
a = __spreadValues(__spreadValues({}, a),
|
|
638
|
-
})
|
|
639
|
-
|
|
640
|
-
n.
|
|
633
|
+
s.forEach((g) => {
|
|
634
|
+
a = __spreadValues(__spreadValues({}, a), g(i));
|
|
635
|
+
});
|
|
636
|
+
const h = !(typeof window > "u") && ((d = (u = window.location) == null ? void 0 : u.search) == null ? void 0 : d.includes("_storyblok_tk"));
|
|
637
|
+
return t !== false && h && w(_), y = new m(n.schema), n.resolver && R(y, n.resolver), a;
|
|
638
|
+
}, R = (o, t) => {
|
|
639
|
+
o.addNode("blok", (e) => {
|
|
641
640
|
let s = "";
|
|
642
641
|
return e.attrs.body.forEach((r) => {
|
|
643
642
|
s += t(r.component, r);
|
|
@@ -645,13 +644,13 @@ const R = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt = (n, t, e =
|
|
|
645
644
|
html: s
|
|
646
645
|
};
|
|
647
646
|
});
|
|
648
|
-
}, st = (
|
|
647
|
+
}, st = (o, t, e) => {
|
|
649
648
|
let s = e || y;
|
|
650
649
|
if (!s) {
|
|
651
650
|
console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
|
|
652
651
|
return;
|
|
653
652
|
}
|
|
654
|
-
return
|
|
653
|
+
return o === "" ? "" : o ? (t && (s = new m(t.schema), t.resolver && R(s, t.resolver)), s.render(o)) : (console.warn(`${o} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
655
654
|
|
|
656
655
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
|
|
657
656
|
};
|
|
@@ -722,4 +721,4 @@ const storyblokInit = (pluginOptions = {}) => {
|
|
|
722
721
|
storyblokApiInstance = storyblokApi;
|
|
723
722
|
componentsMap = pluginOptions.components;
|
|
724
723
|
};
|
|
725
|
-
export {
|
|
724
|
+
export { m as RichTextResolver, K as RichTextSchema, StoryblokComponent, X as apiPlugin, getComponent, useStoryblokApi as getStoryblokApi, tt as registerStoryblokBridge, st as renderRichText, Z as storyblokEditable, storyblokInit, useStoryblok, useStoryblokApi, tt as useStoryblokBridge, useStoryblokState };
|
|
@@ -4,5 +4,5 @@ interface StoryblokComponentProps {
|
|
|
4
4
|
blok: SbBlokData;
|
|
5
5
|
[key: string]: unknown;
|
|
6
6
|
}
|
|
7
|
-
declare const StoryblokComponent: React.ForwardRefExoticComponent<
|
|
7
|
+
declare const StoryblokComponent: React.ForwardRefExoticComponent<Omit<StoryblokComponentProps, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
8
8
|
export default StoryblokComponent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/react",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.14",
|
|
4
4
|
"description": "SDK to integrate Storyblok into your project using React.",
|
|
5
5
|
"main": "./dist/storyblok-react.js",
|
|
6
6
|
"module": "./dist/storyblok-react.mjs",
|
|
@@ -24,21 +24,21 @@
|
|
|
24
24
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@storyblok/js": "^2.0
|
|
27
|
+
"@storyblok/js": "^2.1.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@babel/core": "^7.
|
|
30
|
+
"@babel/core": "^7.21.0",
|
|
31
31
|
"@babel/preset-env": "^7.20.2",
|
|
32
32
|
"@cypress/react": "^5.12.5",
|
|
33
33
|
"@cypress/vite-dev-server": "^2.2.3",
|
|
34
34
|
"@tsconfig/recommended": "^1.0.2",
|
|
35
|
-
"@types/react": "18.0.
|
|
35
|
+
"@types/react": "18.0.28",
|
|
36
36
|
"@vitejs/plugin-react": "^1.3.2",
|
|
37
|
-
"babel-jest": "^29.4.
|
|
37
|
+
"babel-jest": "^29.4.3",
|
|
38
38
|
"cypress": "^9.7.0",
|
|
39
39
|
"eslint-plugin-cypress": "^2.12.1",
|
|
40
40
|
"eslint-plugin-jest": "^27.2.1",
|
|
41
|
-
"jest": "^29.4.
|
|
41
|
+
"jest": "^29.4.3",
|
|
42
42
|
"react": "^18.2.0",
|
|
43
43
|
"react-dom": "^18.2.0",
|
|
44
44
|
"vite": "^2.9.15"
|