@storyblok/svelte 2.4.7 → 2.4.8
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-svelte.js +2 -2
- package/dist/storyblok-svelte.mjs +97 -94
- package/package.json +3 -3
package/dist/storyblok-svelte.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(d,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(d=typeof globalThis<"u"?globalThis:d||self,g(d.storyblokSvelte={}))})(this,function(d){"use strict";let g=!1;const U=[],re=s=>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}g?r():U.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const n=document.createElement("script");n.async=!0,n.src=s,n.id="storyblok-javascript-bridge",n.onerror=r=>t(r),n.onload=r=>{U.forEach(o=>o()),g=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(n)});var oe=Object.defineProperty,ie=(s,e,t)=>e in s?oe(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,h=(s,e,t)=>(ie(s,typeof e!="symbol"?e+"":e,t),t);function H(s){return!(s!==s||s===1/0||s===-1/0)}function ae(s,e,t){if(!H(e))throw new TypeError("Expected `limit` to be a finite number");if(!H(t))throw new TypeError("Expected `interval` to be a finite number");const n=[];let r=[],o=0;const a=function(){o++;const c=setTimeout(function(){o--,n.length>0&&a(),r=r.filter(function(u){return u!==c})},t);r.indexOf(c)<0&&r.push(c);const l=n.shift();l.resolve(s.apply(l.self,l.args))},i=function(...c){const l=this;return new Promise(function(u,f){n.push({resolve:u,reject:f,args:c,self:l}),o<e&&a()})};return i.abort=function(){r.forEach(clearTimeout),r=[],n.forEach(function(c){c.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),n.length=0},i}const ce=function(s,e){const t={};for(const n in s){const r=s[n];e.indexOf(n)>-1&&r!==null&&(t[n]=r)}return t},le=s=>s==="email",he=()=>({singleTag:"hr"}),ue=()=>({tag:"blockquote"}),de=()=>({tag:"ul"}),fe=s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),pe=()=>({singleTag:"br"}),ge=s=>({tag:`h${s.attrs.level}`}),me=s=>({singleTag:[{tag:"img",attrs:ce(s.attrs,["src","alt","title"])}]}),ye=()=>({tag:"li"}),ke=()=>({tag:"ol"}),be=()=>({tag:"p"}),_e=()=>({tag:"b"}),ve=()=>({tag:"strike"}),we=()=>({tag:"u"}),$e=()=>({tag:"strong"}),Te=()=>({tag:"code"}),Re=()=>({tag:"i"}),je=s=>{const e={...s.attrs},{linktype:t="url"}=s.attrs;return le(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},Pe=s=>({tag:[{tag:"span",attrs:s.attrs}]}),q={nodes:{horizontal_rule:he,blockquote:ue,bullet_list:de,code_block:fe,hard_break:pe,heading:ge,image:me,list_item:ye,ordered_list:ke,paragraph:be},marks:{bold:_e,strike:ve,underline:we,strong:$e,code:Te,italic:Re,link:je,styled:Pe}},xe=function(s){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,n=RegExp(t.source);return s&&n.test(s)?s.replace(t,r=>e[r]):s};class w{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=q),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(n=>{t+=this.renderNode(n)}),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 o=this.getMatchingMark(r);o&&t.push(this.renderOpeningTag(o.tag))});const n=this.getMatchingNode(e);return n&&n.tag&&t.push(this.renderOpeningTag(n.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(xe(e.text)):n&&n.singleTag?t.push(this.renderTag(n.singleTag," /")):n&&n.html&&t.push(n.html),n&&n.tag&&t.push(this.renderClosingTag(n.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(n=>{if(n.constructor===String)return`<${n}${t}>`;{let r=`<${n.tag}`;if(n.attrs)for(const o in n.attrs){const a=n.attrs[o];a!==null&&(r+=` ${o}="${a}"`)}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 D{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,n=1)=>({...e,per_page:t,page:n})),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 n=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(n,(o,a)=>a*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((n,r)=>[...n,...r],[]))}stringify(e,t,n){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const a=e[o],i=n?"":encodeURIComponent(o);let c;typeof a=="object"?c=this.stringify(a,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(a)):c=(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(a),r.push(c)}return r.join("&")}}class Ee{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=[],n={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{n.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return n.headers={...t},n.status=e.status,n.statusText=e.statusText,n}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,n=null;if(e==="get"){const c=new D;t=`${this.baseURL}${this.url}?${c.stringify(this.parameters)}`}else n=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:a}=o;let i;this.timeout&&(i=setTimeout(()=>o.abort(),this.timeout));try{const c=await this.fetch(`${r}`,{method:e,headers:this.headers,body:n,signal:a});this.timeout&&clearTimeout(i);const l=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(c){return{message:c}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((n,r)=>{if(t.test(`${e.status}`))return n(e);const o={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};r(o)})}}let $={};const m={};class Se{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 o=e.region?`-${e.region}`:"",a=e.https===!1?"http":"https";e.oauthToken?t=`${a}://api${o}.storyblok.com/v1`:t=`${a}://api${o}.storyblok.com/v2`}const n=new Headers;n.set("Content-Type","application/json"),n.set("Accept","application/json"),n.forEach((o,a)=>{e.headers&&e.headers[a]&&n.set(a,e.headers[a])});let r=5;e.oauthToken&&(n.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new w(e.richTextSchema):this.richTextResolver=new w,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=ae(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new D,this.resolveNestedRelations=!1,this.client=new Ee({baseURL:t,timeout:e.timeout||0,headers:n,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let n="";return t.attrs.body.forEach(r=>{n+=e(r.component,r)}),{html:n}})}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,n,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,n,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const n=`/${e}`,r=this.factoryParamOptions(n,t);return this.cacheResponse(n,r)}async getAll(e,t,n){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,a=o.split("/"),i=n||a[a.length-1],c=1,l=await this.makeRequest(o,t,r,c),u=l.total?Math.ceil(l.total/r):1,f=await this.helpers.asyncMap(this.helpers.range(c,u),b=>this.makeRequest(o,t,r,b+1));return this.helpers.flatMap([l,...f],b=>Object.values(b.data[i]))}post(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("post",n,t))}put(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("put",n,t))}delete(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("delete",n,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 n=e[t];n&&n.fieldtype=="multilink"&&n.linktype=="story"&&typeof n.id=="string"&&this.links[n.id]?n.story=this._cleanCopy(this.links[n.id]):n&&n.linktype==="story"&&typeof n.uuid=="string"&&this.links[n.uuid]&&(n.story=this._cleanCopy(this.links[n.uuid]))}_insertRelations(e,t,n){if(n.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(o=>{this.relations[o]&&r.push(this._cleanCopy(this.relations[o]))}),e[t]=r}}}iterateTree(e,t){const n=r=>{if(r!=null){if(r.constructor===Array)for(let o=0;o<r.length;o++)n(r[o]);else if(r.constructor===Object){if(r._stopResolving)return;for(const o in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,o,t),this._insertLinks(r,o)),n(r[o])}}};n(e.content)}async resolveLinks(e,t){let n=[];if(e.link_uuids){const r=e.link_uuids.length,o=[],a=50;for(let i=0;i<r;i+=a){const c=Math.min(r,i+a);o.push(e.link_uuids.slice(i,c))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(c=>{n.push(c)})}else n=e.links;n.forEach(r=>{this.links[r.uuid]={...r,_stopResolving:!0}})}async resolveRelations(e,t){let n=[];if(e.rel_uuids){const r=e.rel_uuids.length,o=[],a=50;for(let i=0;i<r;i+=a){const c=Math.min(r,i+a);o.push(e.rel_uuids.slice(i,c))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(c=>{n.push(c)})}else n=e.rels;n&&n.length>0&&n.forEach(r=>{this.relations[r.uuid]={...r,_stopResolving:!0}})}async resolveStories(e,t){var n,r;let o=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((n=e.links)!=null&&n.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const a in this.relations)this.iterateTree(this.relations[a],o);e.story?this.iterateTree(e.story,o):e.stories.forEach(a=>{this.iterateTree(a,o)})}async cacheResponse(e,t,n){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 a=await o.get(r);if(a)return Promise.resolve(a)}return new Promise((a,i)=>{try{(async()=>{var c;try{const l=await this.throttle("get",e,t);let u={data:l.data,headers:l.headers};return(c=l.headers)!=null&&c["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})),l.status!=200?i(l):((u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&m[t.token]!=u.data.cv&&await this.flushCache(),m[t.token]=u.data.cv),a(u))}catch(l){return i(l)}})()}catch{}})}throttledRequest(e,t,n){return this.client[e](t,n)}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($[e])},getAll(){return Promise.resolve($)},set(e,t){return $[e]=t,Promise.resolve(void 0)},flush(){return $={},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 Oe=(s={})=>{const{apiOptions:e}=s;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 Se(e)}},Ce=s=>{if(typeof s!="object"||typeof s._editable>"u")return{};const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let P;const Ie="https://app.storyblok.com/f/storyblok-v2-latest.js",Ae=(s,e,t={})=>{if(!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u"){if(!s){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===s?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===s&&window.location.reload()})})}},Ne=(s={})=>{const{bridge:e,accessToken:t,use:n=[],apiOptions:r={},richText:o={}}=s;r.accessToken=r.accessToken||t;const a={bridge:e,apiOptions:r};let i={};return n.forEach(c=>{i={...i,...c(a)}}),e!==!1&&re(Ie),P=new w(o.schema),o.resolver&&B(P,o.resolver),i},B=(s,e)=>{s.addNode("blok",t=>{let n="";return t.attrs.body.forEach(r=>{n+=e(r.component,r)}),{html:n}})},Me=(s,e,t)=>{let n=t||P;if(!n){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return s===""?"":s?(e&&(n=new w(e.schema),e.resolver&&B(n,e.resolver)),n.render(s)):(console.warn(`${s} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
1
|
+
(function(d,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(d=typeof globalThis<"u"?globalThis:d||self,g(d.storyblokSvelte={}))})(this,function(d){"use strict";let g=!1;const U=[],re=s=>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}g?r():U.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const n=document.createElement("script");n.async=!0,n.src=s,n.id="storyblok-javascript-bridge",n.onerror=r=>t(r),n.onload=r=>{U.forEach(o=>o()),g=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(n)});var oe=Object.defineProperty,ie=(s,e,t)=>e in s?oe(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,h=(s,e,t)=>(ie(s,typeof e!="symbol"?e+"":e,t),t);function H(s){return!(s!==s||s===1/0||s===-1/0)}function ae(s,e,t){if(!H(e))throw new TypeError("Expected `limit` to be a finite number");if(!H(t))throw new TypeError("Expected `interval` to be a finite number");const n=[];let r=[],o=0;const i=function(){o++;const c=setTimeout(function(){o--,n.length>0&&i(),r=r.filter(function(u){return u!==c})},t);r.indexOf(c)<0&&r.push(c);const l=n.shift();l.resolve(s.apply(l.self,l.args))},a=function(...c){const l=this;return new Promise(function(u,f){n.push({resolve:u,reject:f,args:c,self:l}),o<e&&i()})};return a.abort=function(){r.forEach(clearTimeout),r=[],n.forEach(function(c){c.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),n.length=0},a}const ce=function(s,e){const t={};for(const n in s){const r=s[n];e.indexOf(n)>-1&&r!==null&&(t[n]=r)}return t},le=s=>s==="email",he=()=>({singleTag:"hr"}),ue=()=>({tag:"blockquote"}),de=()=>({tag:"ul"}),fe=s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),pe=()=>({singleTag:"br"}),ge=s=>({tag:`h${s.attrs.level}`}),me=s=>({singleTag:[{tag:"img",attrs:ce(s.attrs,["src","alt","title"])}]}),ye=()=>({tag:"li"}),ke=()=>({tag:"ol"}),be=()=>({tag:"p"}),_e=()=>({tag:"b"}),ve=()=>({tag:"strike"}),we=()=>({tag:"u"}),$e=()=>({tag:"strong"}),Te=()=>({tag:"code"}),Re=()=>({tag:"i"}),je=s=>{const e={...s.attrs},{linktype:t="url"}=s.attrs;return le(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},Pe=s=>({tag:[{tag:"span",attrs:s.attrs}]}),q={nodes:{horizontal_rule:he,blockquote:ue,bullet_list:de,code_block:fe,hard_break:pe,heading:ge,image:me,list_item:ye,ordered_list:ke,paragraph:be},marks:{bold:_e,strike:ve,underline:we,strong:$e,code:Te,italic:Re,link:je,styled:Pe}},xe=function(s){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,n=RegExp(t.source);return s&&n.test(s)?s.replace(t,r=>e[r]):s};class w{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=q),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(n=>{t+=this.renderNode(n)}),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 o=this.getMatchingMark(r);o&&t.push(this.renderOpeningTag(o.tag))});const n=this.getMatchingNode(e);return n&&n.tag&&t.push(this.renderOpeningTag(n.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(xe(e.text)):n&&n.singleTag?t.push(this.renderTag(n.singleTag," /")):n&&n.html&&t.push(n.html),n&&n.tag&&t.push(this.renderClosingTag(n.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(n=>{if(n.constructor===String)return`<${n}${t}>`;{let r=`<${n.tag}`;if(n.attrs)for(const o in n.attrs){const i=n.attrs[o];i!==null&&(r+=` ${o}="${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 D{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,n=1)=>({...e,per_page:t,page:n})),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 n=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(n,(o,i)=>i*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((n,r)=>[...n,...r],[]))}stringify(e,t,n){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],a=n?"":encodeURIComponent(o);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 Ee{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=[],n={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{n.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return n.headers={...t},n.status=e.status,n.statusText=e.statusText,n}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,n=null;if(e==="get"){const c=new D;t=`${this.baseURL}${this.url}?${c.stringify(this.parameters)}`}else n=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:i}=o;let a;this.timeout&&(a=setTimeout(()=>o.abort(),this.timeout));try{const c=await this.fetch(`${r}`,{method:e,headers:this.headers,body:n,signal:i});this.timeout&&clearTimeout(a);const l=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(c){return{message:c}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((n,r)=>{if(t.test(`${e.status}`))return n(e);const o={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};r(o)})}}let $={};const m={};class Se{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 o=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${o}.storyblok.com/v1`:t=`${i}://api${o}.storyblok.com/v2`}const n=new Headers;n.set("Content-Type","application/json"),n.set("Accept","application/json"),n.forEach((o,i)=>{e.headers&&e.headers[i]&&n.set(i,e.headers[i])});let r=5;e.oauthToken&&(n.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new w(e.richTextSchema):this.richTextResolver=new w,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=ae(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new D,this.resolveNestedRelations=!1,this.client=new Ee({baseURL:t,timeout:e.timeout||0,headers:n,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let n="";return t.attrs.body.forEach(r=>{n+=e(r.component,r)}),{html:n}})}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,n,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,n,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const n=`/${e}`,r=this.factoryParamOptions(n,t);return this.cacheResponse(n,r)}async getAll(e,t,n){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,i=o.split("/"),a=n||i[i.length-1],c=1,l=await this.makeRequest(o,t,r,c),u=l.total?Math.ceil(l.total/r):1,f=await this.helpers.asyncMap(this.helpers.range(c,u),b=>this.makeRequest(o,t,r,b+1));return this.helpers.flatMap([l,...f],b=>Object.values(b.data[a]))}post(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("post",n,t))}put(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("put",n,t))}delete(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("delete",n,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 n=e[t];n&&n.fieldtype=="multilink"&&n.linktype=="story"&&typeof n.id=="string"&&this.links[n.id]?n.story=this._cleanCopy(this.links[n.id]):n&&n.linktype==="story"&&typeof n.uuid=="string"&&this.links[n.uuid]&&(n.story=this._cleanCopy(this.links[n.uuid]))}_insertRelations(e,t,n){if(n.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(o=>{this.relations[o]&&r.push(this._cleanCopy(this.relations[o]))}),e[t]=r}}}iterateTree(e,t){const n=r=>{if(r!=null){if(r.constructor===Array)for(let o=0;o<r.length;o++)n(r[o]);else if(r.constructor===Object){if(r._stopResolving)return;for(const o in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,o,t),this._insertLinks(r,o)),n(r[o])}}};n(e.content)}async resolveLinks(e,t){let n=[];if(e.link_uuids){const r=e.link_uuids.length,o=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);o.push(e.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{n.push(c)})}else n=e.links;n.forEach(r=>{this.links[r.uuid]={...r,_stopResolving:!0}})}async resolveRelations(e,t){let n=[];if(e.rel_uuids){const r=e.rel_uuids.length,o=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,a+i);o.push(e.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{n.push(c)})}else n=e.rels;n&&n.length>0&&n.forEach(r=>{this.relations[r.uuid]={...r,_stopResolving:!0}})}async resolveStories(e,t){var n,r;let o=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((n=e.links)!=null&&n.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],o);e.story?this.iterateTree(e.story,o):e.stories.forEach(i=>{this.iterateTree(i,o)})}async cacheResponse(e,t,n){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 i=await o.get(r);if(i)return Promise.resolve(i)}return new Promise((i,a)=>{try{(async()=>{var c;try{const l=await this.throttle("get",e,t);let u={data:l.data,headers:l.headers};return(c=l.headers)!=null&&c["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})),l.status!=200?a(l):((u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&m[t.token]!=u.data.cv&&await this.flushCache(),m[t.token]=u.data.cv),i(u))}catch(l){return a(l)}})()}catch{}})}throttledRequest(e,t,n){return this.client[e](t,n)}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($[e])},getAll(){return Promise.resolve($)},set(e,t){return $[e]=t,Promise.resolve(void 0)},flush(){return $={},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 Oe=(s={})=>{const{apiOptions:e}=s;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 Se(e)}},Ce=s=>{if(typeof s!="object"||typeof s._editable>"u")return{};const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let P;const Ie="https://app.storyblok.com/f/storyblok-v2-latest.js",Ae=(s,e,t={})=>{if(!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u"){if(!s){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===s?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===s&&window.location.reload()})})}},Ne=(s={})=>{var e,t;const{bridge:n,accessToken:r,use:o=[],apiOptions:i={},richText:a={}}=s;i.accessToken=i.accessToken||r;const c={bridge:n,apiOptions:i};let l={};o.forEach(f=>{l={...l,...f(c)}});const u=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return n!==!1&&u&&re(Ie),P=new w(a.schema),a.resolver&&B(P,a.resolver),l},B=(s,e)=>{s.addNode("blok",t=>{let n="";return t.attrs.body.forEach(r=>{n+=e(r.component,r)}),{html:n}})},Me=(s,e,t)=>{let n=t||P;if(!n){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return s===""?"":s?(e&&(n=new w(e.schema),e.resolver&&B(n,e.resolver)),n.render(s)):(console.warn(`${s} 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`),"")};function x(){}function E(s,e){for(const t in e)s[t]=e[t];return s}function J(s){return s()}function F(){return Object.create(null)}function _(s){s.forEach(J)}function V(s){return typeof s=="function"}function Le(s,e){return s!=s?e==e:s!==e||s&&typeof s=="object"||typeof s=="function"}function Ue(s){return Object.keys(s).length===0}function He(s){const e={};for(const t in s)t[0]!=="$"&&(e[t]=s[t]);return e}function Y(s,e){const t={};e=new Set(e);for(const n in s)!e.has(n)&&n[0]!=="$"&&(t[n]=s[n]);return t}function qe(s,e,t){s.insertBefore(e,t||null)}function z(s){s.parentNode&&s.parentNode.removeChild(s)}function De(s){return document.createTextNode(s)}function Be(){return De("")}function Je(s){return Array.from(s.childNodes)}function K(s,e){return new s(e)}let S;function v(s){S=s}const y=[],G=[],T=[],Q=[],Fe=Promise.resolve();let O=!1;function Ve(){O||(O=!0,Fe.then(W))}function C(s){T.push(s)}const I=new Set;let k=0;function W(){if(k!==0)return;const s=S;do{try{for(;k<y.length;){const e=y[k];k++,v(e),Ye(e.$$)}}catch(e){throw y.length=0,k=0,e}for(v(null),y.length=0,k=0;G.length;)G.pop()();for(let e=0;e<T.length;e+=1){const t=T[e];I.has(t)||(I.add(t),t())}T.length=0}while(y.length);for(;Q.length;)Q.pop()();O=!1,I.clear(),v(s)}function Ye(s){if(s.fragment!==null){s.update(),_(s.before_update);const e=s.dirty;s.dirty=[-1],s.fragment&&s.fragment.p(s.ctx,e),s.after_update.forEach(C)}}const R=new Set;let p;function ze(){p={r:0,c:[],p}}function Ke(){p.r||_(p.c),p=p.p}function A(s,e){s&&s.i&&(R.delete(s),s.i(e))}function X(s,e,t,n){if(s&&s.o){if(R.has(s))return;R.add(s),p.c.push(()=>{R.delete(s),n&&(t&&s.d(1),n())}),s.o(e)}else n&&n()}function Ge(s,e){const t={},n={},r={$$scope:1};let o=s.length;for(;o--;){const
|
|
3
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")};function x(){}function E(s,e){for(const t in e)s[t]=e[t];return s}function J(s){return s()}function F(){return Object.create(null)}function _(s){s.forEach(J)}function V(s){return typeof s=="function"}function Le(s,e){return s!=s?e==e:s!==e||s&&typeof s=="object"||typeof s=="function"}function Ue(s){return Object.keys(s).length===0}function He(s){const e={};for(const t in s)t[0]!=="$"&&(e[t]=s[t]);return e}function Y(s,e){const t={};e=new Set(e);for(const n in s)!e.has(n)&&n[0]!=="$"&&(t[n]=s[n]);return t}function qe(s,e,t){s.insertBefore(e,t||null)}function z(s){s.parentNode&&s.parentNode.removeChild(s)}function De(s){return document.createTextNode(s)}function Be(){return De("")}function Je(s){return Array.from(s.childNodes)}function K(s,e){return new s(e)}let S;function v(s){S=s}const y=[],G=[],T=[],Q=[],Fe=Promise.resolve();let O=!1;function Ve(){O||(O=!0,Fe.then(W))}function C(s){T.push(s)}const I=new Set;let k=0;function W(){if(k!==0)return;const s=S;do{try{for(;k<y.length;){const e=y[k];k++,v(e),Ye(e.$$)}}catch(e){throw y.length=0,k=0,e}for(v(null),y.length=0,k=0;G.length;)G.pop()();for(let e=0;e<T.length;e+=1){const t=T[e];I.has(t)||(I.add(t),t())}T.length=0}while(y.length);for(;Q.length;)Q.pop()();O=!1,I.clear(),v(s)}function Ye(s){if(s.fragment!==null){s.update(),_(s.before_update);const e=s.dirty;s.dirty=[-1],s.fragment&&s.fragment.p(s.ctx,e),s.after_update.forEach(C)}}const R=new Set;let p;function ze(){p={r:0,c:[],p}}function Ke(){p.r||_(p.c),p=p.p}function A(s,e){s&&s.i&&(R.delete(s),s.i(e))}function X(s,e,t,n){if(s&&s.o){if(R.has(s))return;R.add(s),p.c.push(()=>{R.delete(s),n&&(t&&s.d(1),n())}),s.o(e)}else n&&n()}function Ge(s,e){const t={},n={},r={$$scope:1};let o=s.length;for(;o--;){const i=s[o],a=e[o];if(a){for(const c in i)c in a||(n[c]=1);for(const c in a)r[c]||(t[c]=a[c],r[c]=1);s[o]=a}else for(const c in i)r[c]=1}for(const i in n)i in t||(t[i]=void 0);return t}function Qe(s){return typeof s=="object"&&s!==null?s:{}}function Z(s){s&&s.c()}function N(s,e,t,n){const{fragment:r,after_update:o}=s.$$;r&&r.m(e,t),n||C(()=>{const i=s.$$.on_mount.map(J).filter(V);s.$$.on_destroy?s.$$.on_destroy.push(...i):_(i),s.$$.on_mount=[]}),o.forEach(C)}function M(s,e){const t=s.$$;t.fragment!==null&&(_(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function We(s,e){s.$$.dirty[0]===-1&&(y.push(s),Ve(),s.$$.dirty.fill(0)),s.$$.dirty[e/31|0]|=1<<e%31}function Xe(s,e,t,n,r,o,i,a=[-1]){const c=S;v(s);const l=s.$$={fragment:null,ctx:[],props:o,update:x,not_equal:r,bound:F(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(c?c.$$.context:[])),callbacks:F(),dirty:a,skip_bound:!1,root:e.target||c.$$.root};i&&i(l.root);let u=!1;if(l.ctx=t?t(s,e.props||{},(f,b,...se)=>{const ne=se.length?se[0]:b;return l.ctx&&r(l.ctx[f],l.ctx[f]=ne)&&(!l.skip_bound&&l.bound[f]&&l.bound[f](ne),u&&We(s,f)),b}):[],l.update(),u=!0,_(l.before_update),l.fragment=n?n(l.ctx):!1,e.target){if(e.hydrate){const f=Je(e.target);l.fragment&&l.fragment.l(f),f.forEach(z)}else l.fragment&&l.fragment.c();e.intro&&A(s.$$.fragment),N(s,e.target,e.anchor,e.customElement),W()}v(c)}class Ze{$destroy(){M(this,1),this.$destroy=x}$on(e,t){if(!V(t))return x;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(t),()=>{const r=n.indexOf(t);r!==-1&&n.splice(r,1)}}$set(e){this.$$set&&!Ue(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}function et(s){let e,t,n;const r=[{blok:s[0]},s[2]];var o=s[1];function i(a){let c={};for(let l=0;l<r.length;l+=1)c=E(c,r[l]);return{props:c}}return o&&(e=K(o,i())),{c(){e&&Z(e.$$.fragment),t=Be()},m(a,c){e&&N(e,a,c),qe(a,t,c),n=!0},p(a,[c]){const l=c&5?Ge(r,[c&1&&{blok:a[0]},c&4&&Qe(a[2])]):{};if(o!==(o=a[1])){if(e){ze();const u=e;X(u.$$.fragment,1,0,()=>{M(u,1)}),Ke()}o?(e=K(o,i()),Z(e.$$.fragment),A(e.$$.fragment,1),N(e,t.parentNode,t)):e=null}else o&&e.$set(l)},i(a){n||(e&&A(e.$$.fragment,a),n=!0)},o(a){e&&X(e.$$.fragment,a),n=!1},d(a){a&&z(t),e&&M(e,a)}}}function tt(s,e,t){const n=["blok"];let r=Y(e,n),o,{blok:i}=e;return i?o=te(i.component):console.error("Please provide a 'blok' property to the StoryblokComponent"),s.$$set=a=>{e=E(E({},e),He(a)),t(2,r=Y(e,n)),"blok"in a&&t(0,i=a.blok)},[i,o,r]}class st extends Ze{constructor(e){super(),Xe(this,e,tt,et,Le,{blok:0})}}const nt=(s,e)=>{const t=n=>{const r=Ce(n);r["data-blok-c"]&&(s.setAttribute("data-blok-c",r["data-blok-c"]),s.setAttribute("data-blok-uid",r["data-blok-uid"]),s.classList.add("storyblok__outline"))};return t(e),{update(n){t(n)}}};let L=null;const ee=()=>(L||console.log("You can't use getStoryblokApi if you're not loading apiPlugin."),L);let j=null;const rt=s=>{const{storyblokApi:e}=Ne(s);L=e,j=s.components||{}},te=s=>{let e=null;return e=typeof j=="function"?j()[s]:j[s],e||console.error(`You didn't load the ${s} component. Please load it in storyblokInit. For example:
|
|
4
4
|
storyblokInit({
|
|
5
5
|
accessToken: "<your-token>",
|
|
6
6
|
components: {
|
|
@@ -24,17 +24,17 @@ function re(s, e, t) {
|
|
|
24
24
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
25
25
|
const r = [];
|
|
26
26
|
let n = [], o = 0;
|
|
27
|
-
const
|
|
27
|
+
const i = function() {
|
|
28
28
|
o++;
|
|
29
29
|
const c = setTimeout(function() {
|
|
30
|
-
o--, r.length > 0 &&
|
|
30
|
+
o--, r.length > 0 && i(), n = n.filter(function(u) {
|
|
31
31
|
return u !== c;
|
|
32
32
|
});
|
|
33
33
|
}, t);
|
|
34
34
|
n.indexOf(c) < 0 && n.push(c);
|
|
35
35
|
const l = r.shift();
|
|
36
36
|
l.resolve(s.apply(l.self, l.args));
|
|
37
|
-
},
|
|
37
|
+
}, a = function(...c) {
|
|
38
38
|
const l = this;
|
|
39
39
|
return new Promise(function(u, d) {
|
|
40
40
|
r.push({
|
|
@@ -42,16 +42,16 @@ function re(s, e, t) {
|
|
|
42
42
|
reject: d,
|
|
43
43
|
args: c,
|
|
44
44
|
self: l
|
|
45
|
-
}), o < e &&
|
|
45
|
+
}), o < e && i();
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
-
return
|
|
48
|
+
return a.abort = function() {
|
|
49
49
|
n.forEach(clearTimeout), n = [], r.forEach(function(c) {
|
|
50
50
|
c.reject(function() {
|
|
51
51
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
52
52
|
});
|
|
53
53
|
}), r.length = 0;
|
|
54
|
-
},
|
|
54
|
+
}, a;
|
|
55
55
|
}
|
|
56
56
|
const ne = function(s, e) {
|
|
57
57
|
const t = {};
|
|
@@ -196,8 +196,8 @@ class T {
|
|
|
196
196
|
let n = `<${r.tag}`;
|
|
197
197
|
if (r.attrs)
|
|
198
198
|
for (const o in r.attrs) {
|
|
199
|
-
const
|
|
200
|
-
|
|
199
|
+
const i = r.attrs[o];
|
|
200
|
+
i !== null && (n += ` ${o}="${i}"`);
|
|
201
201
|
}
|
|
202
202
|
return `${n}${t}>`;
|
|
203
203
|
}
|
|
@@ -228,7 +228,7 @@ class K {
|
|
|
228
228
|
page: r
|
|
229
229
|
})), 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) => {
|
|
230
230
|
const r = Math.abs(t - e) || 0, n = e < t ? 1 : -1;
|
|
231
|
-
return this.arrayFrom(r, (o,
|
|
231
|
+
return this.arrayFrom(r, (o, i) => i * n + e);
|
|
232
232
|
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((r, n) => [...r, ...n], []));
|
|
233
233
|
}
|
|
234
234
|
stringify(e, t, r) {
|
|
@@ -236,13 +236,13 @@ class K {
|
|
|
236
236
|
for (const o in e) {
|
|
237
237
|
if (!Object.prototype.hasOwnProperty.call(e, o))
|
|
238
238
|
continue;
|
|
239
|
-
const
|
|
239
|
+
const i = e[o], a = r ? "" : encodeURIComponent(o);
|
|
240
240
|
let c;
|
|
241
|
-
typeof
|
|
242
|
-
|
|
243
|
-
t ? t + encodeURIComponent("[" +
|
|
244
|
-
Array.isArray(
|
|
245
|
-
) : c = (t ? t + encodeURIComponent("[" +
|
|
241
|
+
typeof i == "object" ? c = this.stringify(
|
|
242
|
+
i,
|
|
243
|
+
t ? t + encodeURIComponent("[" + a + "]") : a,
|
|
244
|
+
Array.isArray(i)
|
|
245
|
+
) : c = (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(i), n.push(c);
|
|
246
246
|
}
|
|
247
247
|
return n.join("&");
|
|
248
248
|
}
|
|
@@ -286,17 +286,17 @@ class xe {
|
|
|
286
286
|
)}`;
|
|
287
287
|
} else
|
|
288
288
|
r = JSON.stringify(this.parameters);
|
|
289
|
-
const n = new URL(t), o = new AbortController(), { signal:
|
|
290
|
-
let
|
|
291
|
-
this.timeout && (
|
|
289
|
+
const n = new URL(t), o = new AbortController(), { signal: i } = o;
|
|
290
|
+
let a;
|
|
291
|
+
this.timeout && (a = setTimeout(() => o.abort(), this.timeout));
|
|
292
292
|
try {
|
|
293
293
|
const c = await this.fetch(`${n}`, {
|
|
294
294
|
method: e,
|
|
295
295
|
headers: this.headers,
|
|
296
296
|
body: r,
|
|
297
|
-
signal:
|
|
297
|
+
signal: i
|
|
298
298
|
});
|
|
299
|
-
this.timeout && clearTimeout(
|
|
299
|
+
this.timeout && clearTimeout(a);
|
|
300
300
|
const l = await this._responseHandler(c);
|
|
301
301
|
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
|
|
302
302
|
} catch (c) {
|
|
@@ -327,12 +327,12 @@ const g = {};
|
|
|
327
327
|
class Pe {
|
|
328
328
|
constructor(e, t) {
|
|
329
329
|
if (h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), !t) {
|
|
330
|
-
const o = e.region ? `-${e.region}` : "",
|
|
331
|
-
e.oauthToken ? t = `${
|
|
330
|
+
const o = e.region ? `-${e.region}` : "", i = e.https === !1 ? "http" : "https";
|
|
331
|
+
e.oauthToken ? t = `${i}://api${o}.storyblok.com/v1` : t = `${i}://api${o}.storyblok.com/v2`;
|
|
332
332
|
}
|
|
333
333
|
const r = new Headers();
|
|
334
|
-
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), r.forEach((o,
|
|
335
|
-
e.headers && e.headers[
|
|
334
|
+
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), r.forEach((o, i) => {
|
|
335
|
+
e.headers && e.headers[i] && r.set(i, e.headers[i]);
|
|
336
336
|
});
|
|
337
337
|
let n = 5;
|
|
338
338
|
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new T(e.richTextSchema) : this.richTextResolver = new T(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries, this.throttle = re(this.throttledRequest, n, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new K(), this.resolveNestedRelations = !1, this.client = new xe({
|
|
@@ -372,13 +372,13 @@ class Pe {
|
|
|
372
372
|
return this.cacheResponse(r, n);
|
|
373
373
|
}
|
|
374
374
|
async getAll(e, t, r) {
|
|
375
|
-
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`,
|
|
375
|
+
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, i = o.split("/"), a = r || i[i.length - 1], c = 1, l = await this.makeRequest(o, t, n, c), u = l.total ? Math.ceil(l.total / n) : 1, d = await this.helpers.asyncMap(
|
|
376
376
|
this.helpers.range(c, u),
|
|
377
377
|
(p) => this.makeRequest(o, t, n, p + 1)
|
|
378
378
|
);
|
|
379
379
|
return this.helpers.flatMap(
|
|
380
380
|
[l, ...d],
|
|
381
|
-
(p) => Object.values(p.data[
|
|
381
|
+
(p) => Object.values(p.data[a])
|
|
382
382
|
);
|
|
383
383
|
}
|
|
384
384
|
post(e, t) {
|
|
@@ -447,17 +447,17 @@ class Pe {
|
|
|
447
447
|
async resolveLinks(e, t) {
|
|
448
448
|
let r = [];
|
|
449
449
|
if (e.link_uuids) {
|
|
450
|
-
const n = e.link_uuids.length, o = [],
|
|
451
|
-
for (let
|
|
452
|
-
const c = Math.min(n,
|
|
453
|
-
o.push(e.link_uuids.slice(
|
|
450
|
+
const n = e.link_uuids.length, o = [], i = 50;
|
|
451
|
+
for (let a = 0; a < n; a += i) {
|
|
452
|
+
const c = Math.min(n, a + i);
|
|
453
|
+
o.push(e.link_uuids.slice(a, c));
|
|
454
454
|
}
|
|
455
|
-
for (let
|
|
455
|
+
for (let a = 0; a < o.length; a++)
|
|
456
456
|
(await this.getStories({
|
|
457
|
-
per_page:
|
|
457
|
+
per_page: i,
|
|
458
458
|
language: t.language,
|
|
459
459
|
version: t.version,
|
|
460
|
-
by_uuids: o[
|
|
460
|
+
by_uuids: o[a].join(",")
|
|
461
461
|
})).data.stories.forEach(
|
|
462
462
|
(c) => {
|
|
463
463
|
r.push(c);
|
|
@@ -472,17 +472,17 @@ class Pe {
|
|
|
472
472
|
async resolveRelations(e, t) {
|
|
473
473
|
let r = [];
|
|
474
474
|
if (e.rel_uuids) {
|
|
475
|
-
const n = e.rel_uuids.length, o = [],
|
|
476
|
-
for (let
|
|
477
|
-
const c = Math.min(n,
|
|
478
|
-
o.push(e.rel_uuids.slice(
|
|
475
|
+
const n = e.rel_uuids.length, o = [], i = 50;
|
|
476
|
+
for (let a = 0; a < n; a += i) {
|
|
477
|
+
const c = Math.min(n, a + i);
|
|
478
|
+
o.push(e.rel_uuids.slice(a, c));
|
|
479
479
|
}
|
|
480
|
-
for (let
|
|
480
|
+
for (let a = 0; a < o.length; a++)
|
|
481
481
|
(await this.getStories({
|
|
482
|
-
per_page:
|
|
482
|
+
per_page: i,
|
|
483
483
|
language: t.language,
|
|
484
484
|
version: t.version,
|
|
485
|
-
by_uuids: o[
|
|
485
|
+
by_uuids: o[a].join(",")
|
|
486
486
|
})).data.stories.forEach((c) => {
|
|
487
487
|
r.push(c);
|
|
488
488
|
});
|
|
@@ -496,20 +496,20 @@ class Pe {
|
|
|
496
496
|
var r, n;
|
|
497
497
|
let o = [];
|
|
498
498
|
if (typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t)), t.resolve_links && ["1", "story", "url"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t), this.resolveNestedRelations)
|
|
499
|
-
for (const
|
|
500
|
-
this.iterateTree(this.relations[
|
|
501
|
-
e.story ? this.iterateTree(e.story, o) : e.stories.forEach((
|
|
502
|
-
this.iterateTree(
|
|
499
|
+
for (const i in this.relations)
|
|
500
|
+
this.iterateTree(this.relations[i], o);
|
|
501
|
+
e.story ? this.iterateTree(e.story, o) : e.stories.forEach((i) => {
|
|
502
|
+
this.iterateTree(i, o);
|
|
503
503
|
});
|
|
504
504
|
}
|
|
505
505
|
async cacheResponse(e, t, r) {
|
|
506
506
|
const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
|
|
507
507
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
510
|
-
return Promise.resolve(
|
|
508
|
+
const i = await o.get(n);
|
|
509
|
+
if (i)
|
|
510
|
+
return Promise.resolve(i);
|
|
511
511
|
}
|
|
512
|
-
return new Promise((
|
|
512
|
+
return new Promise((i, a) => {
|
|
513
513
|
try {
|
|
514
514
|
(async () => {
|
|
515
515
|
var c;
|
|
@@ -519,9 +519,9 @@ class Pe {
|
|
|
519
519
|
return (c = l.headers) != null && c["per-page"] && (u = Object.assign({}, u, {
|
|
520
520
|
perPage: l.headers["per-page"] ? parseInt(l.headers["per-page"]) : 0,
|
|
521
521
|
total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
|
|
522
|
-
})), l.status != 200 ?
|
|
522
|
+
})), l.status != 200 ? a(l) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, t), t.version === "published" && e != "/cdn/spaces/me" && await o.set(n, u), u.data.cv && t.token && (t.version == "draft" && g[t.token] != u.data.cv && await this.flushCache(), g[t.token] = u.data.cv), i(u));
|
|
523
523
|
} catch (l) {
|
|
524
|
-
return
|
|
524
|
+
return a(l);
|
|
525
525
|
}
|
|
526
526
|
})();
|
|
527
527
|
} catch {
|
|
@@ -615,19 +615,22 @@ const Ee = "https://app.storyblok.com/f/storyblok-v2-latest.js", Xe = (s, e, t =
|
|
|
615
615
|
});
|
|
616
616
|
}
|
|
617
617
|
}, Se = (s = {}) => {
|
|
618
|
+
var e, t;
|
|
618
619
|
const {
|
|
619
|
-
bridge:
|
|
620
|
-
accessToken:
|
|
621
|
-
use:
|
|
622
|
-
apiOptions:
|
|
623
|
-
richText:
|
|
620
|
+
bridge: r,
|
|
621
|
+
accessToken: n,
|
|
622
|
+
use: o = [],
|
|
623
|
+
apiOptions: i = {},
|
|
624
|
+
richText: a = {}
|
|
624
625
|
} = s;
|
|
625
|
-
|
|
626
|
-
const
|
|
627
|
-
let
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
})
|
|
626
|
+
i.accessToken = i.accessToken || n;
|
|
627
|
+
const c = { bridge: r, apiOptions: i };
|
|
628
|
+
let l = {};
|
|
629
|
+
o.forEach((d) => {
|
|
630
|
+
l = { ...l, ...d(c) };
|
|
631
|
+
});
|
|
632
|
+
const u = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
633
|
+
return r !== !1 && u && ee(Ee), x = new T(a.schema), a.resolver && G(x, a.resolver), l;
|
|
631
634
|
}, G = (s, e) => {
|
|
632
635
|
s.addNode("blok", (t) => {
|
|
633
636
|
let r = "";
|
|
@@ -781,19 +784,19 @@ function Je(s, e) {
|
|
|
781
784
|
const t = {}, r = {}, n = { $$scope: 1 };
|
|
782
785
|
let o = s.length;
|
|
783
786
|
for (; o--; ) {
|
|
784
|
-
const
|
|
785
|
-
if (
|
|
786
|
-
for (const c in a)
|
|
787
|
-
c in i || (r[c] = 1);
|
|
787
|
+
const i = s[o], a = e[o];
|
|
788
|
+
if (a) {
|
|
788
789
|
for (const c in i)
|
|
789
|
-
|
|
790
|
-
s[o] = i;
|
|
791
|
-
} else
|
|
790
|
+
c in a || (r[c] = 1);
|
|
792
791
|
for (const c in a)
|
|
792
|
+
n[c] || (t[c] = a[c], n[c] = 1);
|
|
793
|
+
s[o] = a;
|
|
794
|
+
} else
|
|
795
|
+
for (const c in i)
|
|
793
796
|
n[c] = 1;
|
|
794
797
|
}
|
|
795
|
-
for (const
|
|
796
|
-
|
|
798
|
+
for (const i in r)
|
|
799
|
+
i in t || (t[i] = void 0);
|
|
797
800
|
return t;
|
|
798
801
|
}
|
|
799
802
|
function Fe(s) {
|
|
@@ -805,8 +808,8 @@ function z(s) {
|
|
|
805
808
|
function C(s, e, t, r) {
|
|
806
809
|
const { fragment: n, after_update: o } = s.$$;
|
|
807
810
|
n && n.m(e, t), r || S(() => {
|
|
808
|
-
const
|
|
809
|
-
s.$$.on_destroy ? s.$$.on_destroy.push(...
|
|
811
|
+
const i = s.$$.on_mount.map(Q).filter(W);
|
|
812
|
+
s.$$.on_destroy ? s.$$.on_destroy.push(...i) : _(i), s.$$.on_mount = [];
|
|
810
813
|
}), o.forEach(S);
|
|
811
814
|
}
|
|
812
815
|
function I(s, e) {
|
|
@@ -816,7 +819,7 @@ function I(s, e) {
|
|
|
816
819
|
function Ve(s, e) {
|
|
817
820
|
s.$$.dirty[0] === -1 && (y.push(s), He(), s.$$.dirty.fill(0)), s.$$.dirty[e / 31 | 0] |= 1 << e % 31;
|
|
818
821
|
}
|
|
819
|
-
function Ye(s, e, t, r, n, o,
|
|
822
|
+
function Ye(s, e, t, r, n, o, i, a = [-1]) {
|
|
820
823
|
const c = N;
|
|
821
824
|
k(s);
|
|
822
825
|
const l = s.$$ = {
|
|
@@ -836,11 +839,11 @@ function Ye(s, e, t, r, n, o, a, i = [-1]) {
|
|
|
836
839
|
context: new Map(e.context || (c ? c.$$.context : [])),
|
|
837
840
|
// everything else
|
|
838
841
|
callbacks: D(),
|
|
839
|
-
dirty:
|
|
842
|
+
dirty: a,
|
|
840
843
|
skip_bound: !1,
|
|
841
844
|
root: e.target || c.$$.root
|
|
842
845
|
};
|
|
843
|
-
|
|
846
|
+
i && i(l.root);
|
|
844
847
|
let u = !1;
|
|
845
848
|
if (l.ctx = t ? t(s, e.props || {}, (d, p, ...M) => {
|
|
846
849
|
const L = M.length ? M[0] : p;
|
|
@@ -886,35 +889,35 @@ function Ke(s) {
|
|
|
886
889
|
/*component*/
|
|
887
890
|
s[1]
|
|
888
891
|
);
|
|
889
|
-
function a
|
|
892
|
+
function i(a) {
|
|
890
893
|
let c = {};
|
|
891
894
|
for (let l = 0; l < n.length; l += 1)
|
|
892
895
|
c = j(c, n[l]);
|
|
893
896
|
return { props: c };
|
|
894
897
|
}
|
|
895
|
-
return o && (e = J(o,
|
|
898
|
+
return o && (e = J(o, i())), {
|
|
896
899
|
c() {
|
|
897
900
|
e && z(e.$$.fragment), t = Me();
|
|
898
901
|
},
|
|
899
|
-
m(
|
|
900
|
-
e && C(e,
|
|
902
|
+
m(a, c) {
|
|
903
|
+
e && C(e, a, c), Ae(a, t, c), r = !0;
|
|
901
904
|
},
|
|
902
|
-
p(
|
|
905
|
+
p(a, [c]) {
|
|
903
906
|
const l = c & /*blok, $$restProps*/
|
|
904
907
|
5 ? Je(n, [
|
|
905
908
|
c & /*blok*/
|
|
906
909
|
1 && { blok: (
|
|
907
910
|
/*blok*/
|
|
908
|
-
|
|
911
|
+
a[0]
|
|
909
912
|
) },
|
|
910
913
|
c & /*$$restProps*/
|
|
911
914
|
4 && Fe(
|
|
912
915
|
/*$$restProps*/
|
|
913
|
-
|
|
916
|
+
a[2]
|
|
914
917
|
)
|
|
915
918
|
]) : {};
|
|
916
919
|
if (o !== (o = /*component*/
|
|
917
|
-
|
|
920
|
+
a[1])) {
|
|
918
921
|
if (e) {
|
|
919
922
|
De();
|
|
920
923
|
const u = e;
|
|
@@ -922,27 +925,27 @@ function Ke(s) {
|
|
|
922
925
|
I(u, 1);
|
|
923
926
|
}), Be();
|
|
924
927
|
}
|
|
925
|
-
o ? (e = J(o,
|
|
928
|
+
o ? (e = J(o, i()), z(e.$$.fragment), O(e.$$.fragment, 1), C(e, t.parentNode, t)) : e = null;
|
|
926
929
|
} else
|
|
927
930
|
o && e.$set(l);
|
|
928
931
|
},
|
|
929
|
-
i(
|
|
930
|
-
r || (e && O(e.$$.fragment,
|
|
932
|
+
i(a) {
|
|
933
|
+
r || (e && O(e.$$.fragment, a), r = !0);
|
|
931
934
|
},
|
|
932
|
-
o(
|
|
933
|
-
e && Y(e.$$.fragment,
|
|
935
|
+
o(a) {
|
|
936
|
+
e && Y(e.$$.fragment, a), r = !1;
|
|
934
937
|
},
|
|
935
|
-
d(
|
|
936
|
-
|
|
938
|
+
d(a) {
|
|
939
|
+
a && X(t), e && I(e, a);
|
|
937
940
|
}
|
|
938
941
|
};
|
|
939
942
|
}
|
|
940
943
|
function Ge(s, e, t) {
|
|
941
944
|
const r = ["blok"];
|
|
942
|
-
let n = B(e, r), o, { blok:
|
|
943
|
-
return
|
|
944
|
-
e = j(j({}, e), Ie(
|
|
945
|
-
}, [
|
|
945
|
+
let n = B(e, r), o, { blok: i } = e;
|
|
946
|
+
return i ? o = Qe(i.component) : console.error("Please provide a 'blok' property to the StoryblokComponent"), s.$$set = (a) => {
|
|
947
|
+
e = j(j({}, e), Ie(a)), t(2, n = B(e, r)), "blok" in a && t(0, i = a.blok);
|
|
948
|
+
}, [i, o, n];
|
|
946
949
|
}
|
|
947
950
|
class et extends ze {
|
|
948
951
|
constructor(e) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/svelte",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Storyblok SDK to connect Storyblok with Svelte",
|
|
6
6
|
"main": "./dist/storyblok-svelte.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@storyblok/js": "^2.0
|
|
30
|
+
"@storyblok/js": "^2.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@babel/core": "^7.21.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"jest": "^29.4.3",
|
|
38
38
|
"svelte-preprocess": "^5.0.1",
|
|
39
39
|
"typescript": "^4.9.5",
|
|
40
|
-
"vite": "^4.1.
|
|
40
|
+
"vite": "^4.1.4"
|
|
41
41
|
},
|
|
42
42
|
"eslintConfig": {
|
|
43
43
|
"env": {
|