@storyblok/vue 7.2.0 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/StoryblokComponent.vue.d.ts +3 -1
- package/dist/storyblok-vue.js +2 -2
- package/dist/storyblok-vue.mjs +171 -164
- package/package.json +7 -7
|
@@ -7,7 +7,9 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
7
7
|
type: import("vue").PropType<SbBlokData>;
|
|
8
8
|
required: true;
|
|
9
9
|
};
|
|
10
|
-
}, {
|
|
10
|
+
}, {
|
|
11
|
+
value: import("vue").Ref<any>;
|
|
12
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
11
13
|
blok: {
|
|
12
14
|
type: import("vue").PropType<SbBlokData>;
|
|
13
15
|
required: true;
|
package/dist/storyblok-vue.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d.storyblokVue={},d.Vue))})(this,function(d,u){"use strict";let S=!1;const j=[],L=o=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}S?r():j.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=o,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{j.forEach(n=>n()),S=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var V=Object.defineProperty,z=(o,e,t)=>e in o?V(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e,t)=>(z(o,typeof e!="symbol"?e+"":e,t),t);function C(o){return!(o!==o||o===1/0||o===-1/0)}function U(o,e,t){if(!C(e))throw new TypeError("Expected `limit` to be a finite number");if(!C(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const a=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(p){return p!==a})},t);r.indexOf(a)<0&&r.push(a);const
|
|
1
|
+
(function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d.storyblokVue={},d.Vue))})(this,function(d,u){"use strict";let S=!1;const j=[],L=o=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}S?r():j.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=o,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{j.forEach(n=>n()),S=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var V=Object.defineProperty,z=(o,e,t)=>e in o?V(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e,t)=>(z(o,typeof e!="symbol"?e+"":e,t),t);function C(o){return!(o!==o||o===1/0||o===-1/0)}function U(o,e,t){if(!C(e))throw new TypeError("Expected `limit` to be a finite number");if(!C(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const a=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(p){return p!==a})},t);r.indexOf(a)<0&&r.push(a);const c=s.shift();c.resolve(o.apply(c.self,c.args))},l=function(...a){const c=this;return new Promise(function(p,f){s.push({resolve:p,reject:f,args:a,self:c}),n<e&&i()})};return l.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},l}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,(n,i)=>i*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[])),h(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},s=/[&<>"']/g,r=RegExp(s.source);return e&&r.test(e)?e.replace(s,n=>t[n]):e})}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const i=e[n],l=s?"":encodeURIComponent(n);let a;typeof i=="object"?a=this.stringify(i,t?t+encodeURIComponent("["+l+"]"):l,Array.isArray(i)):a=(t?t+encodeURIComponent("["+l+"]"):l)+"="+encodeURIComponent(i),r.push(a)}return r.join("&")}getRegionURL(e){const t="api.storyblok.com",s="api-us.storyblok.com",r="app.storyblokchina.cn";switch(e){case"us":return s;case"cn":return r;default:return t}}}const F=function(o,e){const t={};for(const s in o){const r=o[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},H=o=>o==="email",q=()=>({singleTag:"hr"}),D=()=>({tag:"blockquote"}),B=()=>({tag:"ul"}),J=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),K=()=>({singleTag:"br"}),Y=o=>({tag:`h${o.attrs.level}`}),W=o=>({singleTag:[{tag:"img",attrs:F(o.attrs,["src","alt","title"])}]}),G=()=>({tag:"li"}),Q=()=>({tag:"ol"}),X=()=>({tag:"p"}),Z=o=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":o.attrs.name,emoji:o.attrs.emoji}}]}),ee=()=>({tag:"b"}),te=()=>({tag:"strike"}),se=()=>({tag:"u"}),re=()=>({tag:"strong"}),oe=()=>({tag:"code"}),ne=()=>({tag:"i"}),ie=o=>{const e=new v().escapeHTML,t={...o.attrs},{linktype:s="url"}=o.attrs;if(t.href&&(t.href=e(o.attrs.href||"")),H(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}]}},ae=o=>({tag:[{tag:"span",attrs:o.attrs}]}),le=()=>({tag:"sub"}),ce=()=>({tag:"sup"}),he=o=>({tag:[{tag:"span",attrs:o.attrs}]}),ue=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${o.attrs.color};`}}]}:{tag:""}},pe=o=>{var e;return(e=o.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${o.attrs.color}`}}]}:{tag:""}},P={nodes:{horizontal_rule:q,blockquote:D,bullet_list:B,code_block:J,hard_break:K,heading:Y,image:W,list_item:G,ordered_list:Q,paragraph:X,emoji:Z},marks:{bold:ee,strike:te,underline:se,strong:re,code:oe,italic:ne,link:ie,styled:ae,subscript:le,superscript:ce,anchor:he,highlight:ue,textStyle:pe}},de=function(o){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class b{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=P),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1}){if(e&&e.content&&Array.isArray(e.content)){let s="";return e.content.forEach(r=>{s+=this.renderNode(r)}),t.optimizeImages?this.optimizeImages(s,t.optimizeImages):s}return console.warn(`The render method must receive an Object with a "content" field.
|
|
2
2
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
3
3
|
ISbRichtext:
|
|
4
4
|
content?: ISbRichtext[]
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
23
|
type: 'doc'
|
|
24
|
-
}`),""}optimizeImages(e,t){let s=0,r=0,n="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const c=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";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,p;const f=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(f&&f.length>0){const m={srcset:(l=t.srcset)==null?void 0:l.map(g=>{if(typeof g=="number")return`//${f}/m/${g}x0${i} ${g}w`;if(typeof g=="object"&&g.length===2){let R=0,M=0;return typeof g[0]=="number"&&(R=g[0]),typeof g[1]=="number"&&(M=g[1]),`//${f}/m/${R}x${M}${i} ${R}w`}}).join(", "),sizes:(p=t.sizes)==null?void 0:p.map(g=>g).join(", ")};let T="";return m.srcset&&(T+=`srcset="${m.srcset}" `),m.sizes&&(T+=`sizes="${m.sizes}" `),a.replace(/<img/g,`<img ${T.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(de(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 n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}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 fe{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:i}=n;let c;this.timeout&&(c=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise(s=>{if(t.test(`${e.status}`))return s(e);const r={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};throw new Error(JSON.stringify(r))})}}const E="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"5.14.2"};let _={};const y={};class ge{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const i=new v().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${i(e.region)}/v1`:s=`${c}://${i(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const i in e.headers)r.set(i,e.headers[i]);r.has(E)||(r.set(E,w.defaultAgentName),r.set(w.defaultAgentVersion,w.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new b(e.richTextSchema):this.richTextResolver=new b,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=U(this.throttledRequest,n,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.client=new fe({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=y[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,n=`/${e}`,i=n.split("/"),c=s||i[i.length-1],a=1,l=await this.makeRequest(n,t,r,a),p=l.total?Math.ceil(l.total/r):1,f=await this.helpers.asyncMap(this.helpers.range(a,p),m=>this.makeRequest(n,t,r,m+1));return this.helpers.flatMap([l,...f],m=>Object.values(m.data[c]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}_insertRelations(e,t,s,r){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[r][e[t]]&&(e[t]=this._cleanCopy(this.relations[r][e[t]]));else if(e[t]&&e[t].constructor===Array){const n=[];e[t].forEach(i=>{this.relations[r][i]&&n.push(this._cleanCopy(this.relations[r][i]))}),e[t]=n}}}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let i=0;i<n.length;i++)r(n[i]);else if(n.constructor===Object){if(n._stopResolving)return;for(const i in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,i,t,s),this._insertLinks(n,i,s)),r(n[i])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,i=[],c=50;for(let a=0;a<n;a+=c){const l=Math.min(n,a+c);i.push(e.link_uuids.slice(a,l))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,i=[],c=50;for(let a=0;a<n;a+=c){const l=Math.min(n,a+c);i.push(e.rel_uuids.slice(a,l))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var r,n;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=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||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(c=>{this.iterateTree(c,i,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise(async(i,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let p={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(p=Object.assign({},p,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),p.data.story||p.data.stories){const f=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(p.data,t,`${f}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,p),p.data.cv&&t.token&&(t.version=="draft"&&y[t.token]!=p.data.cv&&await this.flushCache(),y[t.token]=p.data.cv),i(p)}catch(l){if(l.response&&l.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(i).catch(c);c(l.message)}})}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)}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 me=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ge(e)}},ye=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}};let $,x="https://app.storyblok.com/f/storyblok-v2-latest.js";const I=(o,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===o;if(!(!r||!n)){if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],i=>{i.action==="input"&&i.story.id===o?e(i.story):(i.action==="change"||i.action==="published")&&i.storyId===o&&window.location.reload()})})}},be=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:n=[],apiOptions:i={},richText:c={},bridgeUrl:a}=o;i.accessToken=i.accessToken||r;const l={bridge:s,apiOptions:i};let p={};n.forEach(m=>{p={...p,...m(l)}}),a&&(x=a);const f=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&f&&L(x),$=new b(c.schema),c.resolver&&A($,c.resolver),p},A=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ke=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),ve=(o,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ke(o)?"":(e&&(s=new b(e.schema),e.resolver&&A(s,e.resolver)),s.render(o))},N=u.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(o){const e=o,t=typeof u.resolveDynamicComponent(e.blok.component)!="string",s=u.inject("VueSDKOptions"),r=u.ref(e.blok.component);return t||(s.enableFallbackComponent?(r.value=s.customFallbackComponent??"FallbackComponent",typeof u.resolveDynamicComponent(r.value)=="string"&&console.error(`Is the Fallback component "${r.value}" registered properly?`)):console.error(`Component could not be found for blok "${e.blok.component}"! Is it defined in main.ts as "app.component("${e.blok.component}", ${e.blok.component});"?`)),(n,i)=>(u.openBlock(),u.createBlock(u.resolveDynamicComponent(r.value),u.normalizeProps(u.guardReactiveProps({...n.$props,...n.$attrs})),null,16))}}),_e={beforeMount(o,e){if(e.value){const t=ye(e.value);Object.keys(t).length>0&&(o.setAttribute("data-blok-c",t["data-blok-c"]),o.setAttribute("data-blok-uid",t["data-blok-uid"]),o.classList.add("storyblok__outline"))}}},O=o=>{console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
24
|
+
}`),""}optimizeImages(e,t){let s=0,r=0,n="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i="/filters"+i))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const l=s>0||r>0||i.length>0?`${s}x${r}${i}`:"";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/${l}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var c,p;const f=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(f&&f.length>0){const m={srcset:(c=t.srcset)==null?void 0:c.map(g=>{if(typeof g=="number")return`//${f}/m/${g}x0${i} ${g}w`;if(typeof g=="object"&&g.length===2){let R=0,M=0;return typeof g[0]=="number"&&(R=g[0]),typeof g[1]=="number"&&(M=g[1]),`//${f}/m/${R}x${M}${i} ${R}w`}}).join(", "),sizes:(p=t.sizes)==null?void 0:p.map(g=>g).join(", ")};let T="";return m.srcset&&(T+=`srcset="${m.srcset}" `),m.sizes&&(T+=`sizes="${m.sizes}" `),a.replace(/<img/g,`<img ${T.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(de(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 n=this.getMatchingMark(r);n&&n.tag!==""&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}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 fe{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:i}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return{message:a}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise(s=>{if(t.test(`${e.status}`))return s(e);const r={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};throw new Error(JSON.stringify(r))})}}const x="SB-Agent",w={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"5.14.2"};let _={};const y={};class ge{constructor(e,t){h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"resolveCounter"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations");let s=e.endpoint||t;if(!s){const i=new v().getRegionURL,l=e.https===!1?"http":"https";e.oauthToken?s=`${l}://${i(e.region)}/v1`:s=`${l}://${i(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const i in e.headers)r.set(i,e.headers[i]);r.has(x)||(r.set(x,w.defaultAgentName),r.set(w.defaultAgentVersion,w.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new b(e.richTextSchema):this.richTextResolver=new b,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=U(this.throttledRequest,n,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.client=new fe({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=y[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,n=`/${e}`,i=n.split("/"),l=s||i[i.length-1],a=1,c=await this.makeRequest(n,t,r,a),p=c.total?Math.ceil(c.total/r):1,f=await this.helpers.asyncMap(this.helpers.range(a,p),m=>this.makeRequest(n,t,r,m+1));return this.helpers.flatMap([c,...f],m=>Object.values(m.data[l]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}_insertRelations(e,t,s,r){if(s.indexOf(`${e.component}.${t}`)>-1){if(typeof e[t]=="string")this.relations[r][e[t]]&&(e[t]=this._cleanCopy(this.relations[r][e[t]]));else if(e[t]&&e[t].constructor===Array){const n=[];e[t].forEach(i=>{this.relations[r][i]&&n.push(this._cleanCopy(this.relations[r][i]))}),e[t]=n}}}iterateTree(e,t,s){const r=n=>{if(n!=null){if(n.constructor===Array)for(let i=0;i<n.length;i++)r(n[i]);else if(n.constructor===Object){if(n._stopResolving)return;for(const i in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,i,t,s),this._insertLinks(n,i,s)),r(n[i])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const n=e.link_uuids.length,i=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);i.push(e.link_uuids.slice(a,c))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,i=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);i.push(e.rel_uuids.slice(a,c))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var r,n;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=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||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const l in this.relations[s])this.iterateTree(this.relations[s][l],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(l=>{this.iterateTree(l,i,s)}),delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise(async(i,l)=>{var a;try{const c=await this.throttle("get",e,t);if(c.status!==200)return l(c);let p={data:c.data,headers:c.headers};if((a=c.headers)!=null&&a["per-page"]&&(p=Object.assign({},p,{perPage:c.headers["per-page"]?parseInt(c.headers["per-page"]):0,total:c.headers["per-page"]?parseInt(c.headers.total):0})),p.data.story||p.data.stories){const f=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(p.data,t,`${f}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,p),p.data.cv&&t.token&&(t.version=="draft"&&y[t.token]!=p.data.cv&&await this.flushCache(),y[t.token]=p.data.cv),i(p)}catch(c){if(c.response&&c.response.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(i).catch(l);l(c.message)}})}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)}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 me=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ge(e)}},ye=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}};let $,E="https://app.storyblok.com/f/storyblok-v2-latest.js";const I=(o,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===o;if(!(!r||!n)){if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],i=>{i.action==="input"&&i.story.id===o?e(i.story):(i.action==="change"||i.action==="published")&&i.storyId===o&&window.location.reload()})})}},be=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:n=[],apiOptions:i={},richText:l={},bridgeUrl:a}=o;i.accessToken=i.accessToken||r;const c={bridge:s,apiOptions:i};let p={};n.forEach(m=>{p={...p,...m(c)}}),a&&(E=a);const f=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&f&&L(E),$=new b(l.schema),l.resolver&&A($,l.resolver),p},A=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ke=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),ve=(o,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ke(o)?"":(e&&(s=new b(e.schema),e.resolver&&A(s,e.resolver)),s.render(o))},N=u.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(o,{expose:e}){const t=o,s=u.ref();e({value:s});const r=typeof u.resolveDynamicComponent(t.blok.component)!="string",n=u.inject("VueSDKOptions"),i=u.ref(t.blok.component);return r||(n.enableFallbackComponent?(i.value=n.customFallbackComponent??"FallbackComponent",typeof u.resolveDynamicComponent(i.value)=="string"&&console.error(`Is the Fallback component "${i.value}" registered properly?`)):console.error(`Component could not be found for blok "${t.blok.component}"! Is it defined in main.ts as "app.component("${t.blok.component}", ${t.blok.component});"?`)),(l,a)=>(u.openBlock(),u.createBlock(u.resolveDynamicComponent(i.value),u.mergeProps({ref_key:"blokRef",ref:s},{...l.$props,...l.$attrs}),null,16))}}),_e={beforeMount(o,e){if(e.value){const t=ye(e.value);Object.keys(t).length>0&&(o.setAttribute("data-blok-c",t["data-blok-c"]),o.setAttribute("data-blok-uid",t["data-blok-uid"]),o.classList.add("storyblok__outline"))}}},O=o=>{console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
25
25
|
`)};let k=null;const we=()=>(k||O("useStoryblokApi"),k),$e=async(o,e={},t={})=>{const s=u.ref(null);if(t.resolveRelations=t.resolveRelations??e.resolve_relations,t.resolveLinks=t.resolveLinks??e.resolve_links,u.onMounted(()=>{s.value&&s.value.id&&I(s.value.id,r=>s.value=r,t)}),k){const{data:r}=await k.get(`cdn/stories/${o}`,e);s.value=r.story}else O("useStoryblok");return s},Te={install(o,e={}){o.directive("editable",_e),o.component("StoryblokComponent",N),e.enableFallbackComponent&&!e.customFallbackComponent&&o.component("FallbackComponent",u.defineAsyncComponent(()=>Promise.resolve().then(()=>Ce)));const{storyblokApi:t}=be(e);k=t,o.provide("VueSDKOptions",e)}},Re={class:"fallback-component"},Se={class:"component"},je=u.defineComponent({__name:"FallbackComponent",props:{blok:{}},setup(o){return(e,t)=>(u.openBlock(),u.createElementBlock("div",Re,[u.createElementVNode("p",null,[u.createTextVNode(" Component could not be found for blok "),u.createElementVNode("span",Se,u.toDisplayString(e.blok.component),1),u.createTextVNode("! Is it configured correctly? ")])]))}}),Pe="",Ce=Object.freeze(Object.defineProperty({__proto__:null,default:((o,e)=>{const t=o.__vccOpts||o;for(const[s,r]of e)t[s]=r;return t})(je,[["__scopeId","data-v-93c770c0"]])},Symbol.toStringTag,{value:"Module"}));d.RichTextResolver=b,d.RichTextSchema=P,d.StoryblokComponent=N,d.StoryblokVue=Te,d.apiPlugin=me,d.renderRichText=ve,d.useStoryblok=$e,d.useStoryblokApi=we,d.useStoryblokBridge=I,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { defineComponent as N, resolveDynamicComponent as $, inject as O,
|
|
2
|
-
let
|
|
3
|
-
const
|
|
1
|
+
import { defineComponent as N, ref as _, resolveDynamicComponent as $, inject as O, openBlock as L, createBlock as M, mergeProps as z, onMounted as U, defineAsyncComponent as H } from "vue";
|
|
2
|
+
let S = !1;
|
|
3
|
+
const x = [], q = (o) => new Promise((e, t) => {
|
|
4
4
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (r) => {
|
|
5
5
|
if (window.location === window.parent.location) {
|
|
6
6
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
S ? r() : x.push(r);
|
|
10
10
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
11
11
|
return;
|
|
12
12
|
const s = document.createElement("script");
|
|
13
13
|
s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
|
14
|
-
|
|
14
|
+
x.forEach((n) => n()), S = !0, e(r);
|
|
15
15
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
16
16
|
});
|
|
17
|
-
var
|
|
18
|
-
function
|
|
17
|
+
var V = Object.defineProperty, D = (o, e, t) => e in o ? V(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, h = (o, e, t) => (D(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
18
|
+
function C(o) {
|
|
19
19
|
return !(o !== o || o === 1 / 0 || o === -1 / 0);
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
if (!
|
|
21
|
+
function F(o, e, t) {
|
|
22
|
+
if (!C(e))
|
|
23
23
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
24
|
-
if (!
|
|
24
|
+
if (!C(t))
|
|
25
25
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
26
26
|
const s = [];
|
|
27
27
|
let r = [], n = 0;
|
|
@@ -33,26 +33,26 @@ function B(o, e, t) {
|
|
|
33
33
|
});
|
|
34
34
|
}, t);
|
|
35
35
|
r.indexOf(a) < 0 && r.push(a);
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
const
|
|
36
|
+
const c = s.shift();
|
|
37
|
+
c.resolve(o.apply(c.self, c.args));
|
|
38
|
+
}, l = function(...a) {
|
|
39
|
+
const c = this;
|
|
40
40
|
return new Promise(function(u, p) {
|
|
41
41
|
s.push({
|
|
42
42
|
resolve: u,
|
|
43
43
|
reject: p,
|
|
44
44
|
args: a,
|
|
45
|
-
self:
|
|
45
|
+
self: c
|
|
46
46
|
}), n < e && i();
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
|
-
return
|
|
49
|
+
return l.abort = function() {
|
|
50
50
|
r.forEach(clearTimeout), r = [], s.forEach(function(a) {
|
|
51
51
|
a.reject(function() {
|
|
52
52
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
53
53
|
});
|
|
54
54
|
}), s.length = 0;
|
|
55
|
-
},
|
|
55
|
+
}, l;
|
|
56
56
|
}
|
|
57
57
|
class b {
|
|
58
58
|
constructor() {
|
|
@@ -86,13 +86,13 @@ class b {
|
|
|
86
86
|
for (const n in e) {
|
|
87
87
|
if (!Object.prototype.hasOwnProperty.call(e, n))
|
|
88
88
|
continue;
|
|
89
|
-
const i = e[n],
|
|
89
|
+
const i = e[n], l = s ? "" : encodeURIComponent(n);
|
|
90
90
|
let a;
|
|
91
91
|
typeof i == "object" ? a = this.stringify(
|
|
92
92
|
i,
|
|
93
|
-
t ? t + encodeURIComponent("[" +
|
|
93
|
+
t ? t + encodeURIComponent("[" + l + "]") : l,
|
|
94
94
|
Array.isArray(i)
|
|
95
|
-
) : a = (t ? t + encodeURIComponent("[" +
|
|
95
|
+
) : a = (t ? t + encodeURIComponent("[" + l + "]") : l) + "=" + encodeURIComponent(i), r.push(a);
|
|
96
96
|
}
|
|
97
97
|
return r.join("&");
|
|
98
98
|
}
|
|
@@ -113,20 +113,20 @@ class b {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
|
-
const
|
|
116
|
+
const B = function(o, e) {
|
|
117
117
|
const t = {};
|
|
118
118
|
for (const s in o) {
|
|
119
119
|
const r = o[s];
|
|
120
120
|
e.indexOf(s) > -1 && r !== null && (t[s] = r);
|
|
121
121
|
}
|
|
122
122
|
return t;
|
|
123
|
-
},
|
|
123
|
+
}, J = (o) => o === "email", K = () => ({
|
|
124
124
|
singleTag: "hr"
|
|
125
|
-
}),
|
|
125
|
+
}), Y = () => ({
|
|
126
126
|
tag: "blockquote"
|
|
127
|
-
}),
|
|
127
|
+
}), W = () => ({
|
|
128
128
|
tag: "ul"
|
|
129
|
-
}),
|
|
129
|
+
}), G = (o) => ({
|
|
130
130
|
tag: [
|
|
131
131
|
"pre",
|
|
132
132
|
{
|
|
@@ -134,24 +134,24 @@ const J = function(o, e) {
|
|
|
134
134
|
attrs: o.attrs
|
|
135
135
|
}
|
|
136
136
|
]
|
|
137
|
-
}),
|
|
137
|
+
}), Q = () => ({
|
|
138
138
|
singleTag: "br"
|
|
139
|
-
}),
|
|
139
|
+
}), X = (o) => ({
|
|
140
140
|
tag: `h${o.attrs.level}`
|
|
141
|
-
}),
|
|
141
|
+
}), Z = (o) => ({
|
|
142
142
|
singleTag: [
|
|
143
143
|
{
|
|
144
144
|
tag: "img",
|
|
145
|
-
attrs:
|
|
145
|
+
attrs: B(o.attrs, ["src", "alt", "title"])
|
|
146
146
|
}
|
|
147
147
|
]
|
|
148
|
-
}),
|
|
148
|
+
}), ee = () => ({
|
|
149
149
|
tag: "li"
|
|
150
|
-
}),
|
|
150
|
+
}), te = () => ({
|
|
151
151
|
tag: "ol"
|
|
152
|
-
}),
|
|
152
|
+
}), se = () => ({
|
|
153
153
|
tag: "p"
|
|
154
|
-
}),
|
|
154
|
+
}), re = (o) => ({
|
|
155
155
|
tag: [
|
|
156
156
|
{
|
|
157
157
|
tag: "span",
|
|
@@ -162,21 +162,21 @@ const J = function(o, e) {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
]
|
|
165
|
-
}),
|
|
165
|
+
}), oe = () => ({
|
|
166
166
|
tag: "b"
|
|
167
|
-
}),
|
|
167
|
+
}), ne = () => ({
|
|
168
168
|
tag: "strike"
|
|
169
|
-
}),
|
|
169
|
+
}), ie = () => ({
|
|
170
170
|
tag: "u"
|
|
171
|
-
}),
|
|
171
|
+
}), ae = () => ({
|
|
172
172
|
tag: "strong"
|
|
173
|
-
}),
|
|
173
|
+
}), le = () => ({
|
|
174
174
|
tag: "code"
|
|
175
|
-
}),
|
|
175
|
+
}), ce = () => ({
|
|
176
176
|
tag: "i"
|
|
177
|
-
}),
|
|
177
|
+
}), he = (o) => {
|
|
178
178
|
const e = new b().escapeHTML, t = { ...o.attrs }, { linktype: s = "url" } = o.attrs;
|
|
179
|
-
if (t.href && (t.href = e(o.attrs.href || "")),
|
|
179
|
+
if (t.href && (t.href = e(o.attrs.href || "")), J(s) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), t.custom) {
|
|
180
180
|
for (const r in t.custom)
|
|
181
181
|
t[r] = t.custom[r];
|
|
182
182
|
delete t.custom;
|
|
@@ -189,25 +189,25 @@ const J = function(o, e) {
|
|
|
189
189
|
}
|
|
190
190
|
]
|
|
191
191
|
};
|
|
192
|
-
},
|
|
192
|
+
}, ue = (o) => ({
|
|
193
193
|
tag: [
|
|
194
194
|
{
|
|
195
195
|
tag: "span",
|
|
196
196
|
attrs: o.attrs
|
|
197
197
|
}
|
|
198
198
|
]
|
|
199
|
-
}),
|
|
199
|
+
}), pe = () => ({
|
|
200
200
|
tag: "sub"
|
|
201
|
-
}),
|
|
201
|
+
}), de = () => ({
|
|
202
202
|
tag: "sup"
|
|
203
|
-
}),
|
|
203
|
+
}), ge = (o) => ({
|
|
204
204
|
tag: [
|
|
205
205
|
{
|
|
206
206
|
tag: "span",
|
|
207
207
|
attrs: o.attrs
|
|
208
208
|
}
|
|
209
209
|
]
|
|
210
|
-
}),
|
|
210
|
+
}), fe = (o) => {
|
|
211
211
|
var e;
|
|
212
212
|
return (e = o.attrs) != null && e.color ? {
|
|
213
213
|
tag: [
|
|
@@ -221,7 +221,7 @@ const J = function(o, e) {
|
|
|
221
221
|
} : {
|
|
222
222
|
tag: ""
|
|
223
223
|
};
|
|
224
|
-
},
|
|
224
|
+
}, me = (o) => {
|
|
225
225
|
var e;
|
|
226
226
|
return (e = o.attrs) != null && e.color ? {
|
|
227
227
|
tag: [
|
|
@@ -235,36 +235,36 @@ const J = function(o, e) {
|
|
|
235
235
|
} : {
|
|
236
236
|
tag: ""
|
|
237
237
|
};
|
|
238
|
-
},
|
|
238
|
+
}, ye = {
|
|
239
239
|
nodes: {
|
|
240
|
-
horizontal_rule:
|
|
241
|
-
blockquote:
|
|
242
|
-
bullet_list:
|
|
243
|
-
code_block:
|
|
244
|
-
hard_break:
|
|
245
|
-
heading:
|
|
246
|
-
image:
|
|
247
|
-
list_item:
|
|
248
|
-
ordered_list:
|
|
249
|
-
paragraph:
|
|
250
|
-
emoji:
|
|
240
|
+
horizontal_rule: K,
|
|
241
|
+
blockquote: Y,
|
|
242
|
+
bullet_list: W,
|
|
243
|
+
code_block: G,
|
|
244
|
+
hard_break: Q,
|
|
245
|
+
heading: X,
|
|
246
|
+
image: Z,
|
|
247
|
+
list_item: ee,
|
|
248
|
+
ordered_list: te,
|
|
249
|
+
paragraph: se,
|
|
250
|
+
emoji: re
|
|
251
251
|
},
|
|
252
252
|
marks: {
|
|
253
|
-
bold:
|
|
254
|
-
strike:
|
|
255
|
-
underline:
|
|
256
|
-
strong:
|
|
257
|
-
code:
|
|
258
|
-
italic:
|
|
259
|
-
link:
|
|
260
|
-
styled:
|
|
261
|
-
subscript:
|
|
262
|
-
superscript:
|
|
263
|
-
anchor:
|
|
264
|
-
highlight:
|
|
265
|
-
textStyle:
|
|
266
|
-
}
|
|
267
|
-
},
|
|
253
|
+
bold: oe,
|
|
254
|
+
strike: ne,
|
|
255
|
+
underline: ie,
|
|
256
|
+
strong: ae,
|
|
257
|
+
code: le,
|
|
258
|
+
italic: ce,
|
|
259
|
+
link: he,
|
|
260
|
+
styled: ue,
|
|
261
|
+
subscript: pe,
|
|
262
|
+
superscript: de,
|
|
263
|
+
anchor: ge,
|
|
264
|
+
highlight: fe,
|
|
265
|
+
textStyle: me
|
|
266
|
+
}
|
|
267
|
+
}, be = function(o) {
|
|
268
268
|
const e = {
|
|
269
269
|
"&": "&",
|
|
270
270
|
"<": "<",
|
|
@@ -276,7 +276,7 @@ const J = function(o, e) {
|
|
|
276
276
|
};
|
|
277
277
|
class k {
|
|
278
278
|
constructor(e) {
|
|
279
|
-
h(this, "marks"), h(this, "nodes"), e || (e =
|
|
279
|
+
h(this, "marks"), h(this, "nodes"), e || (e = ye), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
280
280
|
}
|
|
281
281
|
addNode(e, t) {
|
|
282
282
|
this.nodes[e] = t;
|
|
@@ -321,23 +321,23 @@ class k {
|
|
|
321
321
|
optimizeImages(e, t) {
|
|
322
322
|
let s = 0, r = 0, n = "", i = "";
|
|
323
323
|
typeof t != "boolean" && (typeof t.width == "number" && t.width > 0 && (n += `width="${t.width}" `, s = t.width), typeof t.height == "number" && t.height > 0 && (n += `height="${t.height}" `, r = t.height), (t.loading === "lazy" || t.loading === "eager") && (n += `loading="${t.loading}" `), typeof t.class == "string" && t.class.length > 0 && (n += `class="${t.class}" `), t.filters && (typeof t.filters.blur == "number" && t.filters.blur >= 0 && t.filters.blur <= 100 && (i += `:blur(${t.filters.blur})`), typeof t.filters.brightness == "number" && t.filters.brightness >= -100 && t.filters.brightness <= 100 && (i += `:brightness(${t.filters.brightness})`), t.filters.fill && (t.filters.fill.match(/[0-9A-Fa-f]{6}/g) || t.filters.fill === "transparent") && (i += `:fill(${t.filters.fill})`), t.filters.format && ["webp", "png", "jpeg"].includes(t.filters.format) && (i += `:format(${t.filters.format})`), typeof t.filters.grayscale == "boolean" && t.filters.grayscale && (i += ":grayscale()"), typeof t.filters.quality == "number" && t.filters.quality >= 0 && t.filters.quality <= 100 && (i += `:quality(${t.filters.quality})`), t.filters.rotate && [90, 180, 270].includes(t.filters.rotate) && (i += `:rotate(${t.filters.rotate})`), i.length > 0 && (i = "/filters" + i))), n.length > 0 && (e = e.replace(/<img/g, `<img ${n.trim()}`));
|
|
324
|
-
const
|
|
324
|
+
const l = s > 0 || r > 0 || i.length > 0 ? `${s}x${r}${i}` : "";
|
|
325
325
|
return e = e.replace(
|
|
326
326
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,
|
|
327
|
-
`a.storyblok.com/f/$1/$2.$3/m/${
|
|
327
|
+
`a.storyblok.com/f/$1/$2.$3/m/${l}`
|
|
328
328
|
), typeof t != "boolean" && (t.sizes || t.srcset) && (e = e.replace(/<img.*?src=["|'](.*?)["|']/g, (a) => {
|
|
329
|
-
var
|
|
329
|
+
var c, u;
|
|
330
330
|
const p = a.match(
|
|
331
331
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
332
332
|
);
|
|
333
333
|
if (p && p.length > 0) {
|
|
334
334
|
const g = {
|
|
335
|
-
srcset: (
|
|
335
|
+
srcset: (c = t.srcset) == null ? void 0 : c.map((d) => {
|
|
336
336
|
if (typeof d == "number")
|
|
337
337
|
return `//${p}/m/${d}x0${i} ${d}w`;
|
|
338
338
|
if (typeof d == "object" && d.length === 2) {
|
|
339
|
-
let w = 0,
|
|
340
|
-
return typeof d[0] == "number" && (w = d[0]), typeof d[1] == "number" && (
|
|
339
|
+
let w = 0, j = 0;
|
|
340
|
+
return typeof d[0] == "number" && (w = d[0]), typeof d[1] == "number" && (j = d[1]), `//${p}/m/${w}x${j}${i} ${w}w`;
|
|
341
341
|
}
|
|
342
342
|
}).join(", "),
|
|
343
343
|
sizes: (u = t.sizes) == null ? void 0 : u.map((d) => d).join(", ")
|
|
@@ -357,7 +357,7 @@ class k {
|
|
|
357
357
|
const s = this.getMatchingNode(e);
|
|
358
358
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
359
359
|
t.push(this.renderNode(r));
|
|
360
|
-
}) : e.text ? t.push(
|
|
360
|
+
}) : e.text ? t.push(be(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) => {
|
|
361
361
|
const n = this.getMatchingMark(r);
|
|
362
362
|
n && n.tag !== "" && t.push(this.renderClosingTag(n.tag));
|
|
363
363
|
}), t.join("");
|
|
@@ -410,7 +410,7 @@ class k {
|
|
|
410
410
|
return this.renderTag(t, " /");
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
|
-
class
|
|
413
|
+
class ke {
|
|
414
414
|
constructor(e) {
|
|
415
415
|
h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), this.baseURL = e.baseURL, this.headers = e.headers || new Headers(), this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
|
|
416
416
|
}
|
|
@@ -456,8 +456,8 @@ class ve {
|
|
|
456
456
|
} else
|
|
457
457
|
s = JSON.stringify(this.parameters);
|
|
458
458
|
const r = new URL(t), n = new AbortController(), { signal: i } = n;
|
|
459
|
-
let
|
|
460
|
-
this.timeout && (
|
|
459
|
+
let l;
|
|
460
|
+
this.timeout && (l = setTimeout(() => n.abort(), this.timeout));
|
|
461
461
|
try {
|
|
462
462
|
const a = await this.fetch(`${r}`, {
|
|
463
463
|
method: e,
|
|
@@ -465,9 +465,9 @@ class ve {
|
|
|
465
465
|
body: s,
|
|
466
466
|
signal: i
|
|
467
467
|
});
|
|
468
|
-
this.timeout && clearTimeout(
|
|
469
|
-
const
|
|
470
|
-
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(
|
|
468
|
+
this.timeout && clearTimeout(l);
|
|
469
|
+
const c = await this._responseHandler(a);
|
|
470
|
+
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(c)) : this._statusHandler(c);
|
|
471
471
|
} catch (a) {
|
|
472
472
|
return {
|
|
473
473
|
message: a
|
|
@@ -491,14 +491,14 @@ class ve {
|
|
|
491
491
|
});
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
|
-
const
|
|
494
|
+
const P = "SB-Agent", R = {
|
|
495
495
|
defaultAgentName: "SB-JS-CLIENT",
|
|
496
496
|
defaultAgentVersion: "SB-Agent-Version",
|
|
497
497
|
packageVersion: "5.14.2"
|
|
498
498
|
};
|
|
499
499
|
let y = {};
|
|
500
500
|
const f = {};
|
|
501
|
-
class
|
|
501
|
+
class ve {
|
|
502
502
|
/**
|
|
503
503
|
*
|
|
504
504
|
* @param config ISbConfig interface
|
|
@@ -508,19 +508,19 @@ class we {
|
|
|
508
508
|
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");
|
|
509
509
|
let s = e.endpoint || t;
|
|
510
510
|
if (!s) {
|
|
511
|
-
const i = new b().getRegionURL,
|
|
512
|
-
e.oauthToken ? s = `${
|
|
511
|
+
const i = new b().getRegionURL, l = e.https === !1 ? "http" : "https";
|
|
512
|
+
e.oauthToken ? s = `${l}://${i(e.region)}/v1` : s = `${l}://${i(e.region)}/v2`;
|
|
513
513
|
}
|
|
514
514
|
const r = new Headers();
|
|
515
515
|
if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers)
|
|
516
516
|
for (const i in e.headers)
|
|
517
517
|
r.set(i, e.headers[i]);
|
|
518
|
-
r.has(
|
|
518
|
+
r.has(P) || (r.set(P, R.defaultAgentName), r.set(
|
|
519
519
|
R.defaultAgentVersion,
|
|
520
520
|
R.packageVersion
|
|
521
521
|
));
|
|
522
522
|
let n = 5;
|
|
523
|
-
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = 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 =
|
|
523
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = 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 = F(this.throttledRequest, n, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.client = new ke({
|
|
524
524
|
baseURL: s,
|
|
525
525
|
timeout: e.timeout || 0,
|
|
526
526
|
headers: r,
|
|
@@ -557,13 +557,13 @@ class we {
|
|
|
557
557
|
return this.cacheResponse(s, r);
|
|
558
558
|
}
|
|
559
559
|
async getAll(e, t, s) {
|
|
560
|
-
const r = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`, i = n.split("/"),
|
|
560
|
+
const r = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`, i = n.split("/"), l = s || i[i.length - 1], a = 1, c = await this.makeRequest(n, t, r, a), u = c.total ? Math.ceil(c.total / r) : 1, p = await this.helpers.asyncMap(
|
|
561
561
|
this.helpers.range(a, u),
|
|
562
562
|
(g) => this.makeRequest(n, t, r, g + 1)
|
|
563
563
|
);
|
|
564
564
|
return this.helpers.flatMap(
|
|
565
|
-
[
|
|
566
|
-
(g) => Object.values(g.data[
|
|
565
|
+
[c, ...p],
|
|
566
|
+
(g) => Object.values(g.data[l])
|
|
567
567
|
);
|
|
568
568
|
}
|
|
569
569
|
post(e, t) {
|
|
@@ -639,20 +639,20 @@ class we {
|
|
|
639
639
|
async resolveLinks(e, t, s) {
|
|
640
640
|
let r = [];
|
|
641
641
|
if (e.link_uuids) {
|
|
642
|
-
const n = e.link_uuids.length, i = [],
|
|
643
|
-
for (let a = 0; a < n; a +=
|
|
644
|
-
const
|
|
645
|
-
i.push(e.link_uuids.slice(a,
|
|
642
|
+
const n = e.link_uuids.length, i = [], l = 50;
|
|
643
|
+
for (let a = 0; a < n; a += l) {
|
|
644
|
+
const c = Math.min(n, a + l);
|
|
645
|
+
i.push(e.link_uuids.slice(a, c));
|
|
646
646
|
}
|
|
647
647
|
for (let a = 0; a < i.length; a++)
|
|
648
648
|
(await this.getStories({
|
|
649
|
-
per_page:
|
|
649
|
+
per_page: l,
|
|
650
650
|
language: t.language,
|
|
651
651
|
version: t.version,
|
|
652
652
|
by_uuids: i[a].join(",")
|
|
653
653
|
})).data.stories.forEach(
|
|
654
|
-
(
|
|
655
|
-
r.push(
|
|
654
|
+
(c) => {
|
|
655
|
+
r.push(c);
|
|
656
656
|
}
|
|
657
657
|
);
|
|
658
658
|
} else
|
|
@@ -667,19 +667,19 @@ class we {
|
|
|
667
667
|
async resolveRelations(e, t, s) {
|
|
668
668
|
let r = [];
|
|
669
669
|
if (e.rel_uuids) {
|
|
670
|
-
const n = e.rel_uuids.length, i = [],
|
|
671
|
-
for (let a = 0; a < n; a +=
|
|
672
|
-
const
|
|
673
|
-
i.push(e.rel_uuids.slice(a,
|
|
670
|
+
const n = e.rel_uuids.length, i = [], l = 50;
|
|
671
|
+
for (let a = 0; a < n; a += l) {
|
|
672
|
+
const c = Math.min(n, a + l);
|
|
673
|
+
i.push(e.rel_uuids.slice(a, c));
|
|
674
674
|
}
|
|
675
675
|
for (let a = 0; a < i.length; a++)
|
|
676
676
|
(await this.getStories({
|
|
677
|
-
per_page:
|
|
677
|
+
per_page: l,
|
|
678
678
|
language: t.language,
|
|
679
679
|
version: t.version,
|
|
680
680
|
by_uuids: i[a].join(",")
|
|
681
|
-
})).data.stories.forEach((
|
|
682
|
-
r.push(
|
|
681
|
+
})).data.stories.forEach((c) => {
|
|
682
|
+
r.push(c);
|
|
683
683
|
});
|
|
684
684
|
} else
|
|
685
685
|
r = e.rels;
|
|
@@ -694,14 +694,14 @@ class we {
|
|
|
694
694
|
var r, n;
|
|
695
695
|
let i = [];
|
|
696
696
|
if (this.links[s] = {}, this.relations[s] = {}, typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (i = 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 || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t, s), this.resolveNestedRelations)
|
|
697
|
-
for (const
|
|
697
|
+
for (const l in this.relations[s])
|
|
698
698
|
this.iterateTree(
|
|
699
|
-
this.relations[s][
|
|
699
|
+
this.relations[s][l],
|
|
700
700
|
i,
|
|
701
701
|
s
|
|
702
702
|
);
|
|
703
|
-
e.story ? this.iterateTree(e.story, i, s) : e.stories.forEach((
|
|
704
|
-
this.iterateTree(
|
|
703
|
+
e.story ? this.iterateTree(e.story, i, s) : e.stories.forEach((l) => {
|
|
704
|
+
this.iterateTree(l, i, s);
|
|
705
705
|
}), delete this.links[s], delete this.relations[s];
|
|
706
706
|
}
|
|
707
707
|
async cacheResponse(e, t, s) {
|
|
@@ -712,25 +712,25 @@ class we {
|
|
|
712
712
|
if (i)
|
|
713
713
|
return Promise.resolve(i);
|
|
714
714
|
}
|
|
715
|
-
return new Promise(async (i,
|
|
715
|
+
return new Promise(async (i, l) => {
|
|
716
716
|
var a;
|
|
717
717
|
try {
|
|
718
|
-
const
|
|
719
|
-
if (
|
|
720
|
-
return c
|
|
721
|
-
let u = { data:
|
|
722
|
-
if ((a =
|
|
723
|
-
perPage:
|
|
724
|
-
total:
|
|
718
|
+
const c = await this.throttle("get", e, t);
|
|
719
|
+
if (c.status !== 200)
|
|
720
|
+
return l(c);
|
|
721
|
+
let u = { data: c.data, headers: c.headers };
|
|
722
|
+
if ((a = c.headers) != null && a["per-page"] && (u = Object.assign({}, u, {
|
|
723
|
+
perPage: c.headers["per-page"] ? parseInt(c.headers["per-page"]) : 0,
|
|
724
|
+
total: c.headers["per-page"] ? parseInt(c.headers.total) : 0
|
|
725
725
|
})), u.data.story || u.data.stories) {
|
|
726
726
|
const p = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
727
727
|
await this.resolveStories(u.data, t, `${p}`);
|
|
728
728
|
}
|
|
729
729
|
return t.version === "published" && e != "/cdn/spaces/me" && await n.set(r, u), u.data.cv && t.token && (t.version == "draft" && f[t.token] != u.data.cv && await this.flushCache(), f[t.token] = u.data.cv), i(u);
|
|
730
|
-
} catch (
|
|
731
|
-
if (
|
|
732
|
-
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(i).catch(
|
|
733
|
-
c
|
|
730
|
+
} catch (c) {
|
|
731
|
+
if (c.response && c.response.status === 429 && (s = s ? s + 1 : 0, s < this.maxRetries))
|
|
732
|
+
return console.log(`Hit rate limit. Retrying in ${s} seconds.`), await this.helpers.delay(1e3 * s), this.cacheResponse(e, t, s).then(i).catch(l);
|
|
733
|
+
l(c.message);
|
|
734
734
|
}
|
|
735
735
|
});
|
|
736
736
|
}
|
|
@@ -787,7 +787,7 @@ class we {
|
|
|
787
787
|
return await this.cacheProvider().flush(), this;
|
|
788
788
|
}
|
|
789
789
|
}
|
|
790
|
-
const
|
|
790
|
+
const xe = (o = {}) => {
|
|
791
791
|
const { apiOptions: e } = o;
|
|
792
792
|
if (!e.accessToken) {
|
|
793
793
|
console.error(
|
|
@@ -795,8 +795,8 @@ const Ce = (o = {}) => {
|
|
|
795
795
|
);
|
|
796
796
|
return;
|
|
797
797
|
}
|
|
798
|
-
return { storyblokApi: new
|
|
799
|
-
},
|
|
798
|
+
return { storyblokApi: new ve(e) };
|
|
799
|
+
}, we = (o) => {
|
|
800
800
|
if (typeof o != "object" || typeof o._editable > "u")
|
|
801
801
|
return {};
|
|
802
802
|
const e = JSON.parse(
|
|
@@ -807,8 +807,8 @@ const Ce = (o = {}) => {
|
|
|
807
807
|
"data-blok-uid": e.id + "-" + e.uid
|
|
808
808
|
} : {};
|
|
809
809
|
};
|
|
810
|
-
let T,
|
|
811
|
-
const
|
|
810
|
+
let T, E = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
811
|
+
const $e = (o, e, t = {}) => {
|
|
812
812
|
var s;
|
|
813
813
|
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", n = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
814
814
|
"_storyblok"
|
|
@@ -824,24 +824,24 @@ const Re = (o, e, t = {}) => {
|
|
|
824
824
|
});
|
|
825
825
|
});
|
|
826
826
|
}
|
|
827
|
-
},
|
|
827
|
+
}, Re = (o = {}) => {
|
|
828
828
|
var e, t;
|
|
829
829
|
const {
|
|
830
830
|
bridge: s,
|
|
831
831
|
accessToken: r,
|
|
832
832
|
use: n = [],
|
|
833
833
|
apiOptions: i = {},
|
|
834
|
-
richText:
|
|
834
|
+
richText: l = {},
|
|
835
835
|
bridgeUrl: a
|
|
836
836
|
} = o;
|
|
837
837
|
i.accessToken = i.accessToken || r;
|
|
838
|
-
const
|
|
838
|
+
const c = { bridge: s, apiOptions: i };
|
|
839
839
|
let u = {};
|
|
840
840
|
n.forEach((g) => {
|
|
841
|
-
u = { ...u, ...g(
|
|
842
|
-
}), a && (
|
|
841
|
+
u = { ...u, ...g(c) };
|
|
842
|
+
}), a && (E = a);
|
|
843
843
|
const p = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
844
|
-
return s !== !1 && p &&
|
|
844
|
+
return s !== !1 && p && q(E), T = new k(l.schema), l.resolver && I(T, l.resolver), u;
|
|
845
845
|
}, I = (o, e) => {
|
|
846
846
|
o.addNode("blok", (t) => {
|
|
847
847
|
let s = "";
|
|
@@ -851,7 +851,7 @@ const Re = (o, e, t = {}) => {
|
|
|
851
851
|
html: s
|
|
852
852
|
};
|
|
853
853
|
});
|
|
854
|
-
}, _e = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")),
|
|
854
|
+
}, _e = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), Ce = (o, e, t) => {
|
|
855
855
|
let s = t || T;
|
|
856
856
|
if (!s) {
|
|
857
857
|
console.error(
|
|
@@ -860,23 +860,30 @@ const Re = (o, e, t = {}) => {
|
|
|
860
860
|
return;
|
|
861
861
|
}
|
|
862
862
|
return _e(o) ? "" : (e && (s = new k(e.schema), e.resolver && I(s, e.resolver)), s.render(o));
|
|
863
|
-
},
|
|
863
|
+
}, Te = /* @__PURE__ */ N({
|
|
864
864
|
__name: "StoryblokComponent",
|
|
865
865
|
props: {
|
|
866
866
|
blok: {}
|
|
867
867
|
},
|
|
868
|
-
setup(o) {
|
|
869
|
-
const
|
|
870
|
-
|
|
871
|
-
|
|
868
|
+
setup(o, { expose: e }) {
|
|
869
|
+
const t = o, s = _();
|
|
870
|
+
e({
|
|
871
|
+
value: s
|
|
872
|
+
});
|
|
873
|
+
const r = typeof $(t.blok.component) != "string", n = O("VueSDKOptions"), i = _(t.blok.component);
|
|
874
|
+
return r || (n.enableFallbackComponent ? (i.value = n.customFallbackComponent ?? "FallbackComponent", typeof $(i.value) == "string" && console.error(
|
|
875
|
+
`Is the Fallback component "${i.value}" registered properly?`
|
|
872
876
|
)) : console.error(
|
|
873
|
-
`Component could not be found for blok "${
|
|
874
|
-
)), (
|
|
877
|
+
`Component could not be found for blok "${t.blok.component}"! Is it defined in main.ts as "app.component("${t.blok.component}", ${t.blok.component});"?`
|
|
878
|
+
)), (l, a) => (L(), M($(i.value), z({
|
|
879
|
+
ref_key: "blokRef",
|
|
880
|
+
ref: s
|
|
881
|
+
}, { ...l.$props, ...l.$attrs }), null, 16));
|
|
875
882
|
}
|
|
876
|
-
}),
|
|
883
|
+
}), je = {
|
|
877
884
|
beforeMount(o, e) {
|
|
878
885
|
if (e.value) {
|
|
879
|
-
const t =
|
|
886
|
+
const t = we(e.value);
|
|
880
887
|
Object.keys(t).length > 0 && (o.setAttribute("data-blok-c", t["data-blok-c"]), o.setAttribute("data-blok-uid", t["data-blok-uid"]), o.classList.add("storyblok__outline"));
|
|
881
888
|
}
|
|
882
889
|
}
|
|
@@ -885,10 +892,10 @@ const Re = (o, e, t = {}) => {
|
|
|
885
892
|
`);
|
|
886
893
|
};
|
|
887
894
|
let m = null;
|
|
888
|
-
const
|
|
889
|
-
const s =
|
|
890
|
-
if (t.resolveRelations = t.resolveRelations ?? e.resolve_relations, t.resolveLinks = t.resolveLinks ?? e.resolve_links,
|
|
891
|
-
s.value && s.value.id &&
|
|
895
|
+
const Pe = () => (m || A("useStoryblokApi"), m), Ee = async (o, e = {}, t = {}) => {
|
|
896
|
+
const s = _(null);
|
|
897
|
+
if (t.resolveRelations = t.resolveRelations ?? e.resolve_relations, t.resolveLinks = t.resolveLinks ?? e.resolve_links, U(() => {
|
|
898
|
+
s.value && s.value.id && $e(
|
|
892
899
|
s.value.id,
|
|
893
900
|
(r) => s.value = r,
|
|
894
901
|
t
|
|
@@ -902,24 +909,24 @@ const Ee = () => (m || A("useStoryblokApi"), m), Ie = async (o, e = {}, t = {})
|
|
|
902
909
|
} else
|
|
903
910
|
A("useStoryblok");
|
|
904
911
|
return s;
|
|
905
|
-
},
|
|
912
|
+
}, Ie = {
|
|
906
913
|
install(o, e = {}) {
|
|
907
|
-
o.directive("editable",
|
|
914
|
+
o.directive("editable", je), o.component("StoryblokComponent", Te), e.enableFallbackComponent && !e.customFallbackComponent && o.component(
|
|
908
915
|
"FallbackComponent",
|
|
909
|
-
|
|
916
|
+
H(() => import("./FallbackComponent-ddf2f161.mjs"))
|
|
910
917
|
);
|
|
911
|
-
const { storyblokApi: t } =
|
|
918
|
+
const { storyblokApi: t } = Re(e);
|
|
912
919
|
m = t, o.provide("VueSDKOptions", e);
|
|
913
920
|
}
|
|
914
921
|
};
|
|
915
922
|
export {
|
|
916
923
|
k as RichTextResolver,
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
924
|
+
ye as RichTextSchema,
|
|
925
|
+
Te as StoryblokComponent,
|
|
926
|
+
Ie as StoryblokVue,
|
|
927
|
+
xe as apiPlugin,
|
|
928
|
+
Ce as renderRichText,
|
|
929
|
+
Ee as useStoryblok,
|
|
930
|
+
Pe as useStoryblokApi,
|
|
931
|
+
$e as useStoryblokBridge
|
|
925
932
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "Storyblok directive for get editable elements.",
|
|
5
5
|
"main": "./dist/storyblok-vue.js",
|
|
6
6
|
"module": "./dist/storyblok-vue.mjs",
|
|
@@ -28,23 +28,23 @@
|
|
|
28
28
|
"@storyblok/js": "^2.3.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "^7.
|
|
31
|
+
"@babel/core": "^7.23.0",
|
|
32
32
|
"@cypress/vite-dev-server": "^5.0.6",
|
|
33
33
|
"@cypress/vue": "^6.0.0",
|
|
34
34
|
"@vitejs/plugin-vue": "^4.3.4",
|
|
35
35
|
"@vue/babel-preset-app": "^5.0.8",
|
|
36
36
|
"@vue/test-utils": "2.4.1",
|
|
37
37
|
"@vue/tsconfig": "^0.1.3",
|
|
38
|
-
"@vue/vue3-jest": "^29.2.
|
|
38
|
+
"@vue/vue3-jest": "^29.2.6",
|
|
39
39
|
"babel-jest": "^29.4.3",
|
|
40
|
-
"cypress": "^13.
|
|
41
|
-
"eslint-plugin-cypress": "^2.
|
|
42
|
-
"eslint-plugin-jest": "^27.
|
|
40
|
+
"cypress": "^13.3.0",
|
|
41
|
+
"eslint-plugin-cypress": "^2.15.1",
|
|
42
|
+
"eslint-plugin-jest": "^27.4.0",
|
|
43
43
|
"jest": "^29.6.4",
|
|
44
44
|
"typescript": "^4.9.5",
|
|
45
45
|
"vite": "^4.4.9",
|
|
46
46
|
"vue": "^3.3.4",
|
|
47
|
-
"vue-tsc": "^1.8.
|
|
47
|
+
"vue-tsc": "^1.8.15"
|
|
48
48
|
},
|
|
49
49
|
"babel": {
|
|
50
50
|
"presets": [
|