@storyblok/vue-2
Advanced tools
Comparing version 4.0.7 to 4.0.8
@@ -1,2 +0,2 @@ | ||
(function(f,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],y):(f=typeof globalThis<"u"?globalThis:f||self,y(f.storyblokVue={},f.Vue))})(this,function(f,y){"use strict";let S=!1;const j=[],U=i=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}S?r():j.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=i,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{j.forEach(o=>o()),S=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var V=Object.defineProperty,H=(i,e,t)=>e in i?V(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,h=(i,e,t)=>(H(i,typeof e!="symbol"?e+"":e,t),t);function O(i){return!(i!==i||i===1/0||i===-1/0)}function q(i,e,t){if(!O(e))throw new TypeError("Expected `limit` to be a finite number");if(!O(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0;const n=function(){o++;const a=setTimeout(function(){o--,s.length>0&&n(),r=r.filter(function(u){return u!==a})},t);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(i.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(u,d){s.push({resolve:u,reject:d,args:a,self:l}),o<e&&n()})};return c.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},c}class v{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,n)=>n*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),h(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,o=>t[o]):e})}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o],c=s?"":encodeURIComponent(o);let a;typeof n=="object"?a=this.stringify(n,t?t+encodeURIComponent("["+c+"]"):c,Array.isArray(n)):a=(t?t+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",o="api-ap.storyblok.com",n="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return o;case"ca":return n;default:return t}}}const F=function(i,e){const t={};for(const s in i){const r=i[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},B=i=>i==="email",J=()=>({singleTag:"hr"}),D=()=>({tag:"blockquote"}),Y=()=>({tag:"ul"}),W=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),X=()=>({singleTag:"br"}),K=i=>({tag:`h${i.attrs.level}`}),G=i=>({singleTag:[{tag:"img",attrs:F(i.attrs,["src","alt","title"])}]}),Q=()=>({tag:"li"}),Z=()=>({tag:"ol"}),ee=()=>({tag:"p"}),te=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),se=()=>({tag:"b"}),re=()=>({tag:"s"}),oe=()=>({tag:"u"}),ie=()=>({tag:"strong"}),ne=()=>({tag:"code"}),ae=()=>({tag:"i"}),le=i=>{if(!i.attrs)return{tag:""};const e=new v().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),B(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},ce=i=>({tag:[{tag:"span",attrs:i.attrs}]}),he=()=>({tag:"sub"}),ue=()=>({tag:"sup"}),pe=i=>({tag:[{tag:"span",attrs:i.attrs}]}),de=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},fe=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},C={nodes:{horizontal_rule:J,blockquote:D,bullet_list:Y,code_block:W,hard_break:X,heading:K,image:G,list_item:Q,ordered_list:Z,paragraph:ee,emoji:te},marks:{bold:se,strike:re,underline:oe,strong:ie,code:ne,italic:ae,link:le,styled:ce,subscript:he,superscript:ue,anchor:pe,highlight:de,textStyle:fe}},ge=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};class k{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=C),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field. | ||
(function(f,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],b):(f=typeof globalThis<"u"?globalThis:f||self,b(f.storyblokVue={},f.Vue))})(this,function(f,b){"use strict";let S=!1;const j=[],z=i=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}S?r():j.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=i,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{j.forEach(o=>o()),S=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var U=Object.defineProperty,H=(i,e,t)=>e in i?U(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t,h=(i,e,t)=>(H(i,typeof e!="symbol"?e+"":e,t),t);function O(i){return!(i!==i||i===1/0||i===-1/0)}function q(i,e,t){if(!O(e))throw new TypeError("Expected `limit` to be a finite number");if(!O(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],o=0;const n=function(){o++;const a=setTimeout(function(){o--,s.length>0&&n(),r=r.filter(function(u){return u!==a})},t);r.indexOf(a)<0&&r.push(a);const l=s.shift();l.resolve(i.apply(l.self,l.args))},c=function(...a){const l=this;return new Promise(function(u,d){s.push({resolve:u,reject:d,args:a,self:l}),o<e&&n()})};return c.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(a){a.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},c}class v{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(o,n)=>n*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),h(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,o=>t[o]):e})}stringify(e,t,s){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o],c=s?"":encodeURIComponent(o);let a;typeof n=="object"?a=this.stringify(n,t?t+encodeURIComponent("["+c+"]"):c,Array.isArray(n)):a=(t?t+encodeURIComponent("["+c+"]"):c)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn",o="api-ap.storyblok.com",n="api-ca.storyblok.com";switch(e){case"us":return s;case"cn":return r;case"ap":return o;case"ca":return n;default:return t}}}const F=function(i,e){const t={};for(const s in i){const r=i[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},B=i=>i==="email",J=()=>({singleTag:"hr"}),D=()=>({tag:"blockquote"}),Y=()=>({tag:"ul"}),W=i=>({tag:["pre",{tag:"code",attrs:i.attrs}]}),X=()=>({singleTag:"br"}),K=i=>({tag:`h${i.attrs.level}`}),G=i=>({singleTag:[{tag:"img",attrs:F(i.attrs,["src","alt","title"])}]}),Q=()=>({tag:"li"}),Z=()=>({tag:"ol"}),ee=()=>({tag:"p"}),te=i=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":i.attrs.name,emoji:i.attrs.emoji}}]}),se=()=>({tag:"b"}),re=()=>({tag:"s"}),oe=()=>({tag:"u"}),ie=()=>({tag:"strong"}),ne=()=>({tag:"code"}),ae=()=>({tag:"i"}),le=i=>{if(!i.attrs)return{tag:""};const e=new v().escapeHTML,t={...i.attrs},{linktype:s="url"}=i.attrs;if(delete t.linktype,t.href&&(t.href=e(i.attrs.href||"")),B(s)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const r in t.custom)t[r]=t.custom[r];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},ce=i=>({tag:[{tag:"span",attrs:i.attrs}]}),he=()=>({tag:"sub"}),ue=()=>({tag:"sup"}),pe=i=>({tag:[{tag:"span",attrs:i.attrs}]}),de=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${i.attrs.color};`}}]}:{tag:""}},fe=i=>{var e;return(e=i.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${i.attrs.color}`}}]}:{tag:""}},C={nodes:{horizontal_rule:J,blockquote:D,bullet_list:Y,code_block:W,hard_break:X,heading:K,image:G,list_item:Q,ordered_list:Z,paragraph:ee,emoji:te},marks:{bold:se,strike:re,underline:oe,strong:ie,code:ne,italic:ae,link:le,styled:ce,subscript:he,superscript:ue,anchor:pe,highlight:de,textStyle:fe}},ge=function(i){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return i&&s.test(i)?i.replace(t,r=>e[r]):i};class k{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=C),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field. | ||
The "content" field must be an array of nodes as the type ISbRichtext. | ||
@@ -24,3 +24,3 @@ ISbRichtext: | ||
type: 'doc' | ||
}`),""}optimizeImages(e,t){let s=0,r=0,o="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const p={srcset:(l=t.srcset)==null?void 0:l.map(g=>{if(typeof g=="number")return`//${d}/m/${g}x0${n} ${g}w`;if(typeof g=="object"&&g.length===2){let T=0,z=0;return typeof g[0]=="number"&&(T=g[0]),typeof g[1]=="number"&&(z=g[1]),`//${d}/m/${T}x${z}${n} ${T}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(g=>g).join(", ")};let m="";return p.srcset&&(m+=`srcset="${p.srcset}" `),p.sizes&&(m+=`sizes="${p.sizes}" `),a.replace(/<img/g,`<img ${m.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ge(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const o in s.attrs){const n=s.attrs[o];n!==null&&(r+=` ${o}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class me{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"),h(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:n}=o;let c;this.timeout&&(c=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}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 o={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(o)})}}const P="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let _={};const b={};class ye{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),h(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new v().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const n in e.headers)r.set(n,e.headers[n]);r.has(P)||(r.set(P,w.defaultAgentName),r.set(w.defaultAgentVersion,w.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=q(this.throttledRequest,o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new me({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=b[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t,s){t||(t={});const r=`/${e}`,o=this.factoryParamOptions(r,t);return this.client.setFetchOptions(s),this.cacheResponse(r,o)}async getAll(e,t,s,r){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`,c=n.split("/"),a=s||c[c.length-1],l=1,u=await this.makeRequest(n,t,o,l),d=u.total?Math.ceil(u.total/o):1;this.client.setFetchOptions(r);const p=await this.helpers.asyncMap(this.helpers.range(l,d),m=>this.makeRequest(n,t,o,m+1));return this.helpers.flatMap([u,...p],m=>Object.values(m.data[a]))}post(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("post",r,t))}put(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("put",r,t))}delete(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("delete",r,t))}getStories(e,t){return this.client.setFetchOptions(t),this._addResolveLevel(e),this.get("cdn/stories",e)}getStory(e,t,s){return this.client.setFetchOptions(s),this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(o=>this.getStoryReference(r,o)).filter(Boolean)))}iterateTree(e,t,s){const r=o=>{if(o!=null){if(o.constructor===Array)for(let n=0;n<o.length;n++)r(o[n]);else if(o.constructor===Object){if(o._stopResolving)return;for(const n in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,n,t,s),this._insertLinks(o,n,s)),r(o[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let n=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),o=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const n=await o.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),u.data.story||u.data.stories){const d=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${d}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version==="draft"&&b[t.token]!=u.data.cv&&await this.flushCache(),b[t.token]=t.cv?t.cv:u.data.cv),n(u)}catch(l){if(l.response&&l.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return b}cacheVersion(){return b[this.accessToken]}setCacheVersion(e){this.accessToken&&(b[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()},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 be=(i={})=>{const{apiOptions:e}=i;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ye(e)}},ve=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};try{const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}}catch{return{}}};let $,A="https://app.storyblok.com/f/storyblok-v2-latest.js";const E=(i,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===i;if(!(!r||!o)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],n=>{n.action==="input"&&n.story.id===i?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===i&&window.location.reload()})})}},ke=(i={})=>{var e,t;const{bridge:s,accessToken:r,use:o=[],apiOptions:n={},richText:c={},bridgeUrl:a}=i;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let u={};o.forEach(p=>{u={...u,...p(l)}}),a&&(A=a);const d=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&d&&U(A),$=new k(c.schema),c.resolver&&I($,c.resolver),u},I=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},_e=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),we=(i,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return _e(i)?"":(e&&(s=new k(e.schema),e.resolver&&I(s,e.resolver)),s.render(i))};function $e(i,e,t,s,r,o,n,c){var a=typeof i=="function"?i.options:i;e&&(a.render=e,a.staticRenderFns=t,a._compiled=!0),s&&(a.functional=!0),o&&(a._scopeId="data-v-"+o);var l;if(n?(l=function(p){p=p||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!p&&typeof __VUE_SSR_CONTEXT__<"u"&&(p=__VUE_SSR_CONTEXT__),r&&r.call(this,p),p&&p._registeredComponents&&p._registeredComponents.add(n)},a._ssrRegister=l):r&&(l=c?function(){r.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:r),l)if(a.functional){a._injectStyles=l;var u=a.render;a.render=function(m,g){return l.call(g),u(m,g)}}else{var d=a.beforeCreate;a.beforeCreate=d?[].concat(d,l):[l]}return{exports:i,options:a}}const Re={props:{blok:{type:Object}}};var Te=function(){var e=this,t=e._self._c;return t(e.blok.component,e._g(e._b({tag:"component"},"component",{...e.$props,...e.$attrs},!1),e.$listeners))},Se=[],je=$e(Re,Te,Se,!1,null,null,null,null);const x=je.exports,N=i=>{console.error(`You can't use ${i} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization. | ||
`)},Oe=(i,e={},t={})=>{const s=y.ref(null),r=L();return y.onMounted(async()=>{if(r){const{data:o}=await r.get(`cdn/stories/${i}`,e);s.value=o.story}else N("useStoryblok");s.value&&s.value.id&&E(s.value.id,o=>s.value=o,t)}),s},Ce={bind:(i,e)=>{if(e.value){const t=ve(e.value);i.setAttribute("data-blok-c",t["data-blok-c"]),i.setAttribute("data-blok-uid",t["data-blok-uid"]),i.classList.add("storyblok__outline")}}};let R=null;const L=()=>(R||N("useStoryblokApi"),R),M={install(i,e={}){i.directive("editable",Ce),i.component("StoryblokComponent",x);const{storyblokApi:t}=ke(e);R=t,i.prototype.$storyblokApi=t}};typeof window<"u"&&window.Vue&&window.Vue.use(M),f.RichTextSchema=C,f.StoryblokComponent=x,f.StoryblokVue=M,f.apiPlugin=be,f.renderRichText=we,f.useStoryblok=Oe,f.useStoryblokApi=L,f.useStoryblokBridge=E,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
}`),""}optimizeImages(e,t){let s=0,r=0,o="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(o+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(o+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(o+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(o+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),o.length>0&&(e=e.replace(/<img/g,`<img ${o.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,u;const d=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(d&&d.length>0){const p={srcset:(l=t.srcset)==null?void 0:l.map(g=>{if(typeof g=="number")return`//${d}/m/${g}x0${n} ${g}w`;if(typeof g=="object"&&g.length===2){let T=0,V=0;return typeof g[0]=="number"&&(T=g[0]),typeof g[1]=="number"&&(V=g[1]),`//${d}/m/${T}x${V}${n} ${T}w`}}).join(", "),sizes:(u=t.sizes)==null?void 0:u.map(g=>g).join(", ")};let m="";return p.srcset&&(m+=`srcset="${p.srcset}" `),p.sizes&&(m+=`sizes="${p.sizes}" `),a.replace(/<img/g,`<img ${m.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderOpeningTag(o.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ge(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&o.tag!==""&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const o in s.attrs){const n=s.attrs[o];n!==null&&(r+=` ${o}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class me{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"),h(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:n}=o;let c;this.timeout&&(c=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}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 o={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(o)})}}const P="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let _={};const y={};class ye{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),h(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new v().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const n in e.headers)r.set(n,e.headers[n]);r.has(P)||(r.set(P,w.defaultAgentName),r.set(w.defaultAgentVersion,w.packageVersion));let o=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=q(this.throttledRequest,o,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new me({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=y[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,o)}get(e,t,s){t||(t={});const r=`/${e}`,o=this.factoryParamOptions(r,t);return this.client.setFetchOptions(s),this.cacheResponse(r,o)}async getAll(e,t,s,r){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`,c=n.split("/"),a=s||c[c.length-1],l=1,u=await this.makeRequest(n,t,o,l),d=u.total?Math.ceil(u.total/o):1;this.client.setFetchOptions(r);const p=await this.helpers.asyncMap(this.helpers.range(l,d),m=>this.makeRequest(n,t,o,m+1));return this.helpers.flatMap([u,...p],m=>Object.values(m.data[a]))}post(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("post",r,t))}put(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("put",r,t))}delete(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("delete",r,t))}getStories(e,t){return this.client.setFetchOptions(t),this._addResolveLevel(e),this.get("cdn/stories",e)}getStory(e,t,s){return this.client.setFetchOptions(s),this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(o=>this.getStoryReference(r,o)).filter(Boolean)))}iterateTree(e,t,s){const r=o=>{if(o!=null){if(o.constructor===Array)for(let n=0;n<o.length;n++)r(o[n]);else if(o.constructor===Object){if(o._stopResolving)return;for(const n in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,n,t,s),this._insertLinks(o,n,s)),r(o[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(o=>{this.links[s][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],c=50;for(let a=0;a<o;a+=c){const l=Math.min(o,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(o=>{this.relations[s][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,s){var r,o;let n=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),o=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const n=await o.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let u={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),u.data.story||u.data.stories){const d=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${d}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version==="draft"&&y[t.token]!=u.data.cv&&await this.flushCache(),y[t.token]=t.cv?t.cv:u.data.cv),n(u)}catch(l){if(l.response&&l.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return y}cacheVersion(){return y[this.accessToken]}setCacheVersion(e){this.accessToken&&(y[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(y[this.accessToken]=0)}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()},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.clearCacheVersion(),this}}const be=(i={})=>{const{apiOptions:e}=i;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ye(e)}},ve=i=>{if(typeof i!="object"||typeof i._editable>"u")return{};try{const e=JSON.parse(i._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}}catch{return{}}};let $,A="https://app.storyblok.com/f/storyblok-v2-latest.js";const E=(i,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===i;if(!(!r||!o)){if(!i){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],n=>{n.action==="input"&&n.story.id===i?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===i&&window.location.reload()})})}},ke=(i={})=>{var e,t;const{bridge:s,accessToken:r,use:o=[],apiOptions:n={},richText:c={},bridgeUrl:a}=i;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let u={};o.forEach(p=>{u={...u,...p(l)}}),a&&(A=a);const d=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&d&&z(A),$=new k(c.schema),c.resolver&&I($,c.resolver),u},I=(i,e)=>{i.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},_e=i=>!i||!(i!=null&&i.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),we=(i,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return _e(i)?"":(e&&(s=new k(e.schema),e.resolver&&I(s,e.resolver)),s.render(i))};function $e(i,e,t,s,r,o,n,c){var a=typeof i=="function"?i.options:i;e&&(a.render=e,a.staticRenderFns=t,a._compiled=!0),s&&(a.functional=!0),o&&(a._scopeId="data-v-"+o);var l;if(n?(l=function(p){p=p||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!p&&typeof __VUE_SSR_CONTEXT__<"u"&&(p=__VUE_SSR_CONTEXT__),r&&r.call(this,p),p&&p._registeredComponents&&p._registeredComponents.add(n)},a._ssrRegister=l):r&&(l=c?function(){r.call(this,(a.functional?this.parent:this).$root.$options.shadowRoot)}:r),l)if(a.functional){a._injectStyles=l;var u=a.render;a.render=function(m,g){return l.call(g),u(m,g)}}else{var d=a.beforeCreate;a.beforeCreate=d?[].concat(d,l):[l]}return{exports:i,options:a}}const Re={props:{blok:{type:Object}}};var Te=function(){var e=this,t=e._self._c;return t(e.blok.component,e._g(e._b({tag:"component"},"component",{...e.$props,...e.$attrs},!1),e.$listeners))},Se=[],je=$e(Re,Te,Se,!1,null,null,null,null);const x=je.exports,N=i=>{console.error(`You can't use ${i} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization. | ||
`)},Oe=(i,e={},t={})=>{const s=b.ref(null),r=L();return b.onMounted(async()=>{if(r){const{data:o}=await r.get(`cdn/stories/${i}`,e);s.value=o.story}else N("useStoryblok");s.value&&s.value.id&&E(s.value.id,o=>s.value=o,t)}),s},Ce={bind:(i,e)=>{if(e.value){const t=ve(e.value);i.setAttribute("data-blok-c",t["data-blok-c"]),i.setAttribute("data-blok-uid",t["data-blok-uid"]),i.classList.add("storyblok__outline")}}};let R=null;const L=()=>(R||N("useStoryblokApi"),R),M={install(i,e={}){i.directive("editable",Ce),i.component("StoryblokComponent",x);const{storyblokApi:t}=ke(e);R=t,i.prototype.$storyblokApi=t}};typeof window<"u"&&window.Vue&&window.Vue.use(M),f.RichTextSchema=C,f.StoryblokComponent=x,f.StoryblokVue=M,f.apiPlugin=be,f.renderRichText=we,f.useStoryblok=Oe,f.useStoryblokApi=L,f.useStoryblokBridge=E,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "@storyblok/vue-2", | ||
"version": "4.0.7", | ||
"version": "4.0.8", | ||
"description": "Storyblok SDK for Vue 2 to interact with Storyblok API and connect to Storyblok Visual Editor", | ||
@@ -29,9 +29,9 @@ "main": "./dist/storyblok-vue-2.js", | ||
"dependencies": { | ||
"@storyblok/js": "^3.0.7" | ||
"@storyblok/js": "^3.0.8" | ||
}, | ||
"devDependencies": { | ||
"@cypress/vite-dev-server": "^5.0.7", | ||
"@cypress/vue2": "^2.0.1", | ||
"@cypress/vue2": "^2.1.0", | ||
"@vitejs/plugin-vue2": "^2.3.1", | ||
"@vue/test-utils": "^1.3.4", | ||
"@vue/test-utils": "^2.4.5", | ||
"@vue/tsconfig": "^0.1.3", | ||
@@ -41,3 +41,3 @@ "cypress": "^10.0.0", | ||
"vite": "^3.2.7", | ||
"vitest": "^1.3.1", | ||
"vitest": "^1.5.0", | ||
"vue": "^2.7.16", | ||
@@ -44,0 +44,0 @@ "vue-tsc": "1.8.27" |
@@ -33,3 +33,3 @@ <div align="center"> | ||
> ⚠️ **Storyblok Vue 2 SDK is reaching its End of Life on August 1st 2024.** | ||
> ⚠️ **Storyblok Vue 2 SDK is reaching its End of Life on August 31st 2024.** | ||
> The repository for the latest version of Vue is [storyblok-vue](https://github.com/storyblok/storyblok-vue). | ||
@@ -36,0 +36,0 @@ > |
Sorry, the diff of this file is not supported yet
76168
1094
Updated@storyblok/js@^3.0.8