@storyblok/vue 6.0.3 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/storyblok-vue.js +3 -3
- package/dist/storyblok-vue.mjs +250 -242
- package/package.json +11 -11
package/dist/storyblok-vue.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
1
|
+
(function(h,d){typeof exports=="object"&&typeof module!="undefined"?d(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],d):(h=typeof globalThis!="undefined"?globalThis:h||self,d(h.storyblokVue={},h.Vue,h.e))})(this,function(h,d,p){"use strict";var et=Object.defineProperty;var j=Object.getOwnPropertySymbols;var rt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var C=(h,d,p)=>d in h?et(h,d,{enumerable:!0,configurable:!0,writable:!0,value:p}):h[d]=p,_=(h,d)=>{for(var p in d||(d={}))rt.call(d,p)&&C(h,p,d[p]);if(j)for(var p of j(d))st.call(d,p)&&C(h,p,d[p]);return h};function M(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var I=M(p),N=Object.defineProperty,x=Object.defineProperties,B=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,T=(o,t,e)=>t in o?N(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,f=(o,t)=>{for(var e in t||(t={}))q.call(t,e)&&T(o,e,t[e]);if(w)for(var e of w(t))L.call(t,e)&&T(o,e,t[e]);return o},b=(o,t)=>x(o,B(t));let R=!1;const O=[],V=o=>new Promise((t,e)=>{if(typeof window=="undefined"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}R?s():O.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const r=document.createElement("script");r.async=!0,r.src=o,r.id="storyblok-javascript-bridge",r.onerror=s=>e(s),r.onload=s=>{O.forEach(n=>n()),R=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(r)});/*!
|
|
2
2
|
* storyblok-js-client v0.0.0-development
|
|
3
3
|
* Universal JavaScript SDK for Storyblok's API
|
|
4
4
|
* (c) 2020-2022 Stobylok Team
|
|
5
|
-
*/function O(s){return typeof s=="number"&&s==s&&s!==1/0&&s!==-1/0}function P(s,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");var r=[],o=[],n=0,i=function(){n++;var c=setTimeout(function(){n--,r.length>0&&i(),o=o.filter(function(d){return d!==c})},t);o.indexOf(c)<0&&o.push(c);var l=r.shift();l.resolve(s.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(d,k){r.push({resolve:d,reject:k,args:c,self:l}),n<e&&i()})};return a.abort=function(){o.forEach(clearTimeout),o=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}P.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const D=function(s,e){if(!s)return null;let t={};for(let r in s){let o=s[r];e.indexOf(r)>-1&&o!==null&&(t[r]=o)}return t};var z={nodes:{horizontal_rule:s=>({singleTag:"hr"}),blockquote:s=>({tag:"blockquote"}),bullet_list:s=>({tag:"ul"}),code_block:s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),hard_break:s=>({singleTag:"br"}),heading:s=>({tag:"h"+s.attrs.level}),image:s=>({singleTag:[{tag:"img",attrs:D(s.attrs,["src","alt","title"])}]}),list_item:s=>({tag:"li"}),ordered_list:s=>({tag:"ol"}),paragraph:s=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(s){const e=f({},s.attrs),{linktype:t="url"}=s.attrs;return t==="email"&&(e.href="mailto:"+e.href),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled:s=>({tag:[{tag:"span",attrs:s.attrs}]})}};class U{constructor(e){e||(e=z),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(r=>{t+=this.renderNode(r)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderOpeningTag(n.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(function(o){const n={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return o&&a.test(o)?o.replace(i,c=>n[c]):o}(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let o="<"+r.tag;if(r.attrs)for(let n in r.attrs){let i=r.attrs[n];i!==null&&(o+=` ${n}="${i}"`)}return`${o}${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){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}const J=(s=0,e=s)=>{const t=Math.abs(e-s)||0,r=s<e?1:-1;return((o=0,n)=>[...Array(o)].map(n))(t,(o,n)=>n*r+s)},v=(s,e,t)=>{const r=[];for(const o in s){if(!Object.prototype.hasOwnProperty.call(s,o))continue;const n=s[o],i=t?"":encodeURIComponent(o);let a;a=typeof n=="object"?v(n,e?e+encodeURIComponent("["+i+"]"):i,Array.isArray(n)):(e?e+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let m={},g={};class Y{constructor(e,t){if(!t){let n=e.region?"-"+e.region:"",i=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${i}://api${n}.storyblok.com/v2`:`${i}://api${n}.storyblok.com/v1`}let r=Object.assign({},e.headers),o=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,o=3),e.rateLimit!==void 0&&(o=e.rateLimit),this.richTextResolver=new U(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=P(this.throttledRequest,o,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=I.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(n=>e.responseInterceptor(n))}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(o=>{r+=e(o.component,o)}),{html:r}})}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=g[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((r="")=>r.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,r,o){const n=this.factoryParamOptions(e,((i={},a=25,c=1)=>b(f({},i),{per_page:a,page:c}))(t,r,o));return this.cacheResponse(e,n)}get(e,t){let r="/"+e;const o=this.factoryParamOptions(r,t);return this.cacheResponse(r,o)}async getAll(e,t={},r){const o=t.per_page||25,n="/"+e,i=n.split("/");r=r||i[i.length-1];const a=await this.makeRequest(n,t,o,1),c=Math.ceil(a.total/o);return((l=[],d)=>l.map(d).reduce((k,ee)=>[...k,...ee],[]))([a,...await(async(l=[],d)=>Promise.all(l.map(d)))(J(1,c),async l=>this.makeRequest(n,t,o,l+1))],l=>Object.values(l.data[r]))}post(e,t){let r="/"+e;return this.throttle("post",r,t)}put(e,t){let r="/"+e;return this.throttle("put",r,t)}delete(e,t){let r="/"+e;return this.throttle("delete",r,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get("cdn/stories/"+e,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(e,t,r){if(r.indexOf(e.component+"."+t)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let o=[];e[t].forEach(n=>{this.relations[n]&&o.push(this._cleanCopy(this.relations[n]))}),e[t]=o}}}iterateTree(e,t){let 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(let n in o)(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,n,t),this._insertLinks(o,n)),r(o[n])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const o=e.link_uuids.length;let n=[];const i=50;for(let a=0;a<o;a+=i){const c=Math.min(o,a+i);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(o=>{this.links[o.uuid]=b(f({},o),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length;let n=[];const i=50;for(let a=0;a<o;a+=i){const c=Math.min(o,a+i);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r.forEach(o=>{this.relations[o.uuid]=b(f({},o),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&await this.resolveLinks(e,t);for(const o in this.relations)this.iterateTree(this.relations[o],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(o=>{this.iterateTree(o,r)})}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(o,n)=>{let i=v({url:e,params:t}),a=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await a.get(i);if(l)return o(l)}try{let l=await this.throttle("get",e,{params:t,paramsSerializer:k=>v(k)}),d={data:l.data,headers:l.headers};if(l.headers["per-page"]&&(d=Object.assign({},d,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return n(l);(d.data.story||d.data.stories)&&await this.resolveStories(d.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&a.set(i,d),d.data.cv&&(t.version=="draft"&&g[t.token]!=d.data.cv&&this.flushCache(),g[t.token]=d.data.cv),o(d)}catch(l){if(l.response&&l.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(c=1e3*r,new Promise(d=>setTimeout(d,c))),this.cacheResponse(e,t,r).then(o).catch(n);n(l)}var c})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(e){this.accessToken&&(g[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get:e=>m[e],getAll:()=>m,set(e,t){m[e]=t},flush(){m={}}};default:return{get(){},getAll(){},set(){},flush(){}}}}async flushCache(){return await this.cacheProvider().flush(),this}}var H=(s={})=>{const{apiOptions:e}=s;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Y(e)}},F=s=>{if(typeof s!="object"||typeof s._editable=="undefined")return{};const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};const G="https://app.storyblok.com/f/storyblok-v2-latest.js",E=(s,e,t={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!s){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],o=>{o.action=="input"&&o.story.id===s?e(o.story):window.location.reload()})})}},K=(s={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:o={}}=s;o.accessToken=o.accessToken||t;const n={bridge:e,apiOptions:o};let i={};return r.forEach(a=>{i=f(f({},i),a(n))}),e!==!1&&V(G),i},j={props:{blok:Object},setup(s){return(e,t)=>(h.openBlock(),h.createBlock(h.resolveDynamicComponent(s.blok.component),h.normalizeProps(h.guardReactiveProps(_(_({},e.$props),e.$attrs))),null,16))}},Q={beforeMount(s,e){if(e.value){const t=F(e.value);s.setAttribute("data-blok-c",t["data-blok-c"]),s.setAttribute("data-blok-uid",t["data-blok-uid"]),s.classList.add("storyblok__outline")}}},A=s=>{console.error(`You can't use ${s} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
6
|
-
`)};let y=null;const W=()=>(y||A("useStoryblokApi"),y),X=async(
|
|
5
|
+
*/function S(o){return typeof o=="number"&&o==o&&o!==1/0&&o!==-1/0}function E(o,t,e){if(!S(t))throw new TypeError("Expected `limit` to be a finite number");if(!S(e))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],n=0,i=function(){n++;var c=setTimeout(function(){n--,r.length>0&&i(),s=s.filter(function(u){return u!==c})},e);s.indexOf(c)<0&&s.push(c);var l=r.shift();l.resolve(o.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(u,m){r.push({resolve:u,reject:m,args:c,self:l}),n<t&&i()})};return a.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}E.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const D=function(o,t){if(!o)return null;let e={};for(let r in o){let s=o[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e};var z={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:o=>({tag:`h${o.attrs.level}`}),image:o=>({singleTag:[{tag:"img",attrs:D(o.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(o){const t=f({},o.attrs),{linktype:e="url"}=o.attrs;return e==="email"&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:o=>({tag:[{tag:"span",attrs:o.attrs}]})}};class U{constructor(t){t||(t=z),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(r=>{e+=this.renderNode(r)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&e.push(this.renderOpeningTag(n.tag))});const r=this.getMatchingNode(t);return r&&r.tag&&e.push(this.renderOpeningTag(r.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(function(s){const n={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return s&&a.test(s)?s.replace(i,c=>n[c]):s}(t.text)):r&&r.singleTag?e.push(this.renderTag(r.singleTag," /")):r&&r.html&&e.push(r.html),r&&r.tag&&e.push(this.renderClosingTag(r.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&e.push(this.renderClosingTag(n.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(r=>{if(r.constructor===String)return`<${r}${e}>`;{let s=`<${r.tag}`;if(r.attrs)for(let n in r.attrs){let i=r.attrs[n];i!==null&&(s+=` ${n}="${i}"`)}return`${s}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}const J=(o=0,t=o)=>{const e=Math.abs(t-o)||0,r=o<t?1:-1;return((s=0,n)=>[...Array(s)].map(n))(e,(s,n)=>n*r+o)},v=(o,t,e)=>{const r=[];for(const s in o){if(!Object.prototype.hasOwnProperty.call(o,s))continue;const n=o[s],i=e?"":encodeURIComponent(s);let a;a=typeof n=="object"?v(n,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(n)):(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let k={},g={};class Y{constructor(t,e){if(!e){let n=t.region?`-${t.region}`:"",i=t.https===!1?"http":"https";e=t.oauthToken===void 0?`${i}://api${n}.storyblok.com/v2`:`${i}://api${n}.storyblok.com/v1`}let r=Object.assign({},t.headers),s=5;t.oauthToken!==void 0&&(r.Authorization=t.oauthToken,s=3),t.rateLimit!==void 0&&(s=t.rateLimit),this.richTextResolver=new U(t.richTextSchema),typeof t.componentResolver=="function"&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=E(this.throttledRequest,s,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=I.default.create({baseURL:e,timeout:t.timeout||0,headers:r,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use(n=>t.responseInterceptor(n)),this.resolveNestedRelations=t.resolveNestedRelations||!0}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let r="";return e.attrs.body.forEach(s=>{r+=t(s.component,s)}),{html:r}})}parseParams(t={}){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=g[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e={}){return((r="")=>r.indexOf("/cdn/")>-1)(t)?this.parseParams(e):e}makeRequest(t,e,r,s){const n=this.factoryParamOptions(t,((i={},a=25,c=1)=>b(f({},i),{per_page:a,page:c}))(e,r,s));return this.cacheResponse(t,n)}get(t,e){let r=`/${t}`;const s=this.factoryParamOptions(r,e);return this.cacheResponse(r,s)}async getAll(t,e={},r){const s=e.per_page||25,n=`/${t}`,i=n.split("/");r=r||i[i.length-1];const a=await this.makeRequest(n,e,s,1),c=Math.ceil(a.total/s);return((l=[],u)=>l.map(u).reduce((m,tt)=>[...m,...tt],[]))([a,...await(async(l=[],u)=>Promise.all(l.map(u)))(J(1,c),async l=>this.makeRequest(n,e,s,l+1))],l=>Object.values(l.data[r]))}post(t,e){let r=`/${t}`;return this.throttle("post",r,e)}put(t,e){let r=`/${t}`;return this.throttle("put",r,e)}delete(t,e){let r=`/${t}`;return this.throttle("delete",r,e)}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}setToken(t){this.accessToken=t}getToken(){return this.accessToken}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e){const r=t[e];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(t,e,r){if(r.indexOf(t.component+"."+e)>-1){if(typeof t[e]=="string")this.relations[t[e]]&&(t[e]=this._cleanCopy(this.relations[t[e]]));else if(t[e].constructor===Array){let s=[];t[e].forEach(n=>{this.relations[n]&&s.push(this._cleanCopy(this.relations[n]))}),t[e]=s}}}_insertAssetsRelations(t,e){e.forEach(r=>{t.id===r.id&&(t.original=r,t.original.filename=t.filename,t.original.filename=t.original.filename.includes("https://s3.amazonaws.com/")?t.original.filename:t.original.filename.replace("https://","https://s3.amazonaws.com/"),delete t.original.s3_filename)})}iterateTree(t,e){let r=s=>{if(s!=null){if(s.constructor===Array)for(let n=0;n<s.length;n++)r(s[n]);else if(s.constructor===Object){if(s._stopResolving)return;for(let n in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,n,e),this._insertLinks(s,n)):s.fieldtype==="asset"&&this._insertAssetsRelations(s,e),r(s[n])}}};r(t.content)}async resolveLinks(t,e){let r=[];if(t.link_uuids){const s=t.link_uuids.length;let n=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);n.push(t.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=t.links;r.forEach(s=>{this.links[s.uuid]=b(f({},s),{_stopResolving:!0})})}async resolveRelations(t,e){let r=[];if(t.rel_uuids){const s=t.rel_uuids.length;let n=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);n.push(t.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=t.rels;r.forEach(s=>{this.relations[s.uuid]=b(f({},s),{_stopResolving:!0})})}async resolveStories(t,e){let r=[];if(e.resolve_relations!==void 0&&e.resolve_relations.length>0&&(r=e.resolve_relations.split(","),await this.resolveRelations(t,e)),["1","story","url"].indexOf(e.resolve_links)>-1&&await this.resolveLinks(t,e),this.resolveNestedRelations)for(const s in this.relations)this.iterateTree(this.relations[s],r);t.story?this.iterateTree(t.story,r):t.stories.forEach(s=>{this.iterateTree(s,r)})}resolveAssetsRelations(t){const{assets:e,stories:r,story:s}=t;if(r)for(const n of r)this.iterateTree(n,e);else this.iterateTree(s,e)}cacheResponse(t,e,r){return r===void 0&&(r=0),new Promise(async(s,n)=>{let i=v({url:t,params:e}),a=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const l=await a.get(i);if(l)return s(l)}try{let l=await this.throttle("get",t,{params:e,paramsSerializer:m=>v(m)}),u={data:l.data,headers:l.headers};if(u.data.assets&&u.data.assets.length&&this.resolveAssetsRelations(u.data),l.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return n(l);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&a.set(i,u),u.data.cv&&(e.version=="draft"&&g[e.token]!=u.data.cv&&this.flushCache(),g[e.token]=u.data.cv),s(u)}catch(l){if(l.response&&l.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(c=1e3*r,new Promise(u=>setTimeout(u,c))),this.cacheResponse(t,e,r).then(s).catch(n);n(l)}var c})}throttledRequest(t,e,r){return this.client[t](e,r)}cacheVersions(){return g}cacheVersion(){return g[this.accessToken]}setCacheVersion(t){this.accessToken&&(g[this.accessToken]=t)}cacheProvider(){return this.cache.type==="memory"?{get:t=>k[t],getAll:()=>k,set(t,e){k[t]=e},flush(){k={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}var H=(o={})=>{const{apiOptions:t}=o;if(!t.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 Y(t)}},F=o=>{if(typeof o!="object"||typeof o._editable=="undefined")return{};const t=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};const G="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(o,t,e={})=>{if(typeof window!="undefined"){if(typeof window.storyblokRegisterEvent=="undefined"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(e).on(["input","published","change"],s=>{s.action=="input"&&s.story.id===o?t(s.story):window.location.reload()})})}},K=(o={})=>{const{bridge:t,accessToken:e,use:r=[],apiOptions:s={}}=o;s.accessToken=s.accessToken||e;const n={bridge:t,apiOptions:s};let i={};return r.forEach(a=>{i=f(f({},i),a(n))}),t!==!1&&V(G),i},$={props:{blok:Object},setup(o){return(t,e)=>(d.openBlock(),d.createBlock(d.resolveDynamicComponent(o.blok.component),d.normalizeProps(d.guardReactiveProps(_(_({},t.$props),t.$attrs))),null,16))}},Q={beforeMount(o,t){if(t.value){const e=F(t.value);o.setAttribute("data-blok-c",e["data-blok-c"]),o.setAttribute("data-blok-uid",e["data-blok-uid"]),o.classList.add("storyblok__outline")}}},A=o=>{console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
6
|
+
`)};let y=null;const W=()=>(y||A("useStoryblokApi"),y),X=async(o,t={},e={})=>{const r=d.ref(null);if(d.onMounted(()=>{r.value&&r.value.id&&P(r.value.id,s=>r.value=s,e)}),y){const{data:s}=await y.get(`cdn/stories/${o}`,t);r.value=s.story}else A("useStoryblok");return r},Z={install(o,t={}){o.directive("editable",Q),o.component("StoryblokComponent",$);const{storyblokApi:e}=K(t);y=e}};h.StoryblokComponent=$,h.StoryblokVue=Z,h.apiPlugin=H,h.useStoryblok=X,h.useStoryblokApi=W,h.useStoryblokBridge=P,Object.defineProperty(h,"__esModule",{value:!0}),h[Symbol.toStringTag]="Module"});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -15,7 +15,7 @@ var __spreadValues = (a2, b) => {
|
|
|
15
15
|
return a2;
|
|
16
16
|
};
|
|
17
17
|
import { openBlock, createBlock, resolveDynamicComponent, normalizeProps, guardReactiveProps, ref, onMounted } from "vue";
|
|
18
|
-
import
|
|
18
|
+
import e from "axios";
|
|
19
19
|
var __defProp2 = Object.defineProperty;
|
|
20
20
|
var __defProps = Object.defineProperties;
|
|
21
21
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -71,309 +71,322 @@ const loadBridge = (src) => {
|
|
|
71
71
|
* Universal JavaScript SDK for Storyblok's API
|
|
72
72
|
* (c) 2020-2022 Stobylok Team
|
|
73
73
|
*/
|
|
74
|
-
function
|
|
75
|
-
return typeof
|
|
74
|
+
function t(e2) {
|
|
75
|
+
return typeof e2 == "number" && (e2 == e2 && e2 !== 1 / 0 && e2 !== -1 / 0);
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
if (!
|
|
77
|
+
function s(e2, s2, r2) {
|
|
78
|
+
if (!t(s2))
|
|
79
79
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
80
|
-
if (!
|
|
80
|
+
if (!t(r2))
|
|
81
81
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
82
|
-
var
|
|
82
|
+
var i2 = [], n2 = [], o2 = 0, a2 = function() {
|
|
83
83
|
o2++;
|
|
84
|
-
var
|
|
85
|
-
o2--,
|
|
86
|
-
return
|
|
84
|
+
var t2 = setTimeout(function() {
|
|
85
|
+
o2--, i2.length > 0 && a2(), n2 = n2.filter(function(e3) {
|
|
86
|
+
return e3 !== t2;
|
|
87
87
|
});
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
var
|
|
91
|
-
|
|
88
|
+
}, r2);
|
|
89
|
+
n2.indexOf(t2) < 0 && n2.push(t2);
|
|
90
|
+
var s3 = i2.shift();
|
|
91
|
+
s3.resolve(e2.apply(s3.self, s3.args));
|
|
92
92
|
}, l2 = function() {
|
|
93
|
-
var
|
|
94
|
-
return new Promise(function(
|
|
95
|
-
|
|
93
|
+
var e3 = arguments, t2 = this;
|
|
94
|
+
return new Promise(function(r3, n3) {
|
|
95
|
+
i2.push({ resolve: r3, reject: n3, args: e3, self: t2 }), o2 < s2 && a2();
|
|
96
96
|
});
|
|
97
97
|
};
|
|
98
98
|
return l2.abort = function() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}),
|
|
99
|
+
n2.forEach(clearTimeout), n2 = [], i2.forEach(function(e3) {
|
|
100
|
+
e3.reject(new throttle.AbortError());
|
|
101
|
+
}), i2.length = 0;
|
|
102
102
|
}, l2;
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
s.AbortError = function() {
|
|
105
105
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
106
106
|
};
|
|
107
|
-
const
|
|
108
|
-
if (!
|
|
107
|
+
const r = function(e2, t2) {
|
|
108
|
+
if (!e2)
|
|
109
109
|
return null;
|
|
110
|
-
let
|
|
111
|
-
for (let
|
|
112
|
-
let
|
|
113
|
-
|
|
110
|
+
let s2 = {};
|
|
111
|
+
for (let r2 in e2) {
|
|
112
|
+
let i2 = e2[r2];
|
|
113
|
+
t2.indexOf(r2) > -1 && i2 !== null && (s2[r2] = i2);
|
|
114
114
|
}
|
|
115
|
-
return
|
|
115
|
+
return s2;
|
|
116
116
|
};
|
|
117
|
-
var
|
|
118
|
-
const
|
|
119
|
-
return
|
|
120
|
-
}, styled: (
|
|
121
|
-
class
|
|
122
|
-
constructor(
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
addNode(
|
|
126
|
-
this.nodes[
|
|
127
|
-
}
|
|
128
|
-
addMark(
|
|
129
|
-
this.marks[
|
|
130
|
-
}
|
|
131
|
-
render(
|
|
132
|
-
if (
|
|
133
|
-
let
|
|
134
|
-
return
|
|
135
|
-
|
|
136
|
-
}),
|
|
117
|
+
var i = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (e2) => ({ tag: ["pre", { tag: "code", attrs: e2.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (e2) => ({ tag: `h${e2.attrs.level}` }), image: (e2) => ({ singleTag: [{ tag: "img", attrs: r(e2.attrs, ["src", "alt", "title"]) }] }), list_item: () => ({ tag: "li" }), ordered_list: () => ({ tag: "ol" }), paragraph: () => ({ tag: "p" }) }, marks: { bold: () => ({ tag: "b" }), strike: () => ({ tag: "strike" }), underline: () => ({ tag: "u" }), strong: () => ({ tag: "strong" }), code: () => ({ tag: "code" }), italic: () => ({ tag: "i" }), link(e2) {
|
|
118
|
+
const t2 = __spreadValues2({}, e2.attrs), { linktype: s2 = "url" } = e2.attrs;
|
|
119
|
+
return s2 === "email" && (t2.href = `mailto:${t2.href}`), t2.anchor && (t2.href = `${t2.href}#${t2.anchor}`, delete t2.anchor), { tag: [{ tag: "a", attrs: t2 }] };
|
|
120
|
+
}, styled: (e2) => ({ tag: [{ tag: "span", attrs: e2.attrs }] }) } };
|
|
121
|
+
class n {
|
|
122
|
+
constructor(e2) {
|
|
123
|
+
e2 || (e2 = i), this.marks = e2.marks || [], this.nodes = e2.nodes || [];
|
|
124
|
+
}
|
|
125
|
+
addNode(e2, t2) {
|
|
126
|
+
this.nodes[e2] = t2;
|
|
127
|
+
}
|
|
128
|
+
addMark(e2, t2) {
|
|
129
|
+
this.marks[e2] = t2;
|
|
130
|
+
}
|
|
131
|
+
render(e2 = {}) {
|
|
132
|
+
if (e2.content && Array.isArray(e2.content)) {
|
|
133
|
+
let t2 = "";
|
|
134
|
+
return e2.content.forEach((e3) => {
|
|
135
|
+
t2 += this.renderNode(e3);
|
|
136
|
+
}), t2;
|
|
137
137
|
}
|
|
138
138
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
139
139
|
}
|
|
140
|
-
renderNode(
|
|
141
|
-
let
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
140
|
+
renderNode(e2) {
|
|
141
|
+
let t2 = [];
|
|
142
|
+
e2.marks && e2.marks.forEach((e3) => {
|
|
143
|
+
const s3 = this.getMatchingMark(e3);
|
|
144
|
+
s3 && t2.push(this.renderOpeningTag(s3.tag));
|
|
145
145
|
});
|
|
146
|
-
const
|
|
147
|
-
return
|
|
148
|
-
|
|
149
|
-
}) :
|
|
150
|
-
const
|
|
151
|
-
return
|
|
152
|
-
}(
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
}),
|
|
156
|
-
}
|
|
157
|
-
renderTag(
|
|
158
|
-
if (
|
|
159
|
-
return `<${
|
|
160
|
-
return
|
|
161
|
-
if (
|
|
162
|
-
return `<${
|
|
146
|
+
const s2 = this.getMatchingNode(e2);
|
|
147
|
+
return s2 && s2.tag && t2.push(this.renderOpeningTag(s2.tag)), e2.content ? e2.content.forEach((e3) => {
|
|
148
|
+
t2.push(this.renderNode(e3));
|
|
149
|
+
}) : e2.text ? t2.push(function(e3) {
|
|
150
|
+
const t3 = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }, s3 = /[&<>"']/g, r2 = RegExp(s3.source);
|
|
151
|
+
return e3 && r2.test(e3) ? e3.replace(s3, (e4) => t3[e4]) : e3;
|
|
152
|
+
}(e2.text)) : s2 && s2.singleTag ? t2.push(this.renderTag(s2.singleTag, " /")) : s2 && s2.html && t2.push(s2.html), s2 && s2.tag && t2.push(this.renderClosingTag(s2.tag)), e2.marks && e2.marks.slice(0).reverse().forEach((e3) => {
|
|
153
|
+
const s3 = this.getMatchingMark(e3);
|
|
154
|
+
s3 && t2.push(this.renderClosingTag(s3.tag));
|
|
155
|
+
}), t2.join("");
|
|
156
|
+
}
|
|
157
|
+
renderTag(e2, t2) {
|
|
158
|
+
if (e2.constructor === String)
|
|
159
|
+
return `<${e2}${t2}>`;
|
|
160
|
+
return e2.map((e3) => {
|
|
161
|
+
if (e3.constructor === String)
|
|
162
|
+
return `<${e3}${t2}>`;
|
|
163
163
|
{
|
|
164
|
-
let
|
|
165
|
-
if (
|
|
166
|
-
for (let
|
|
167
|
-
let
|
|
168
|
-
|
|
164
|
+
let s2 = `<${e3.tag}`;
|
|
165
|
+
if (e3.attrs)
|
|
166
|
+
for (let t3 in e3.attrs) {
|
|
167
|
+
let r2 = e3.attrs[t3];
|
|
168
|
+
r2 !== null && (s2 += ` ${t3}="${r2}"`);
|
|
169
169
|
}
|
|
170
|
-
return `${
|
|
170
|
+
return `${s2}${t2}>`;
|
|
171
171
|
}
|
|
172
172
|
}).join("");
|
|
173
173
|
}
|
|
174
|
-
renderOpeningTag(
|
|
175
|
-
return this.renderTag(
|
|
174
|
+
renderOpeningTag(e2) {
|
|
175
|
+
return this.renderTag(e2, "");
|
|
176
176
|
}
|
|
177
|
-
renderClosingTag(
|
|
178
|
-
if (
|
|
179
|
-
return `</${
|
|
180
|
-
return
|
|
177
|
+
renderClosingTag(e2) {
|
|
178
|
+
if (e2.constructor === String)
|
|
179
|
+
return `</${e2}>`;
|
|
180
|
+
return e2.slice(0).reverse().map((e3) => e3.constructor === String ? `</${e3}>` : `</${e3.tag}>`).join("");
|
|
181
181
|
}
|
|
182
|
-
getMatchingNode(
|
|
183
|
-
if (typeof this.nodes[
|
|
184
|
-
return this.nodes[
|
|
182
|
+
getMatchingNode(e2) {
|
|
183
|
+
if (typeof this.nodes[e2.type] == "function")
|
|
184
|
+
return this.nodes[e2.type](e2);
|
|
185
185
|
}
|
|
186
|
-
getMatchingMark(
|
|
187
|
-
if (typeof this.marks[
|
|
188
|
-
return this.marks[
|
|
186
|
+
getMatchingMark(e2) {
|
|
187
|
+
if (typeof this.marks[e2.type] == "function")
|
|
188
|
+
return this.marks[e2.type](e2);
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
|
-
const o = (
|
|
192
|
-
const
|
|
193
|
-
return ((
|
|
194
|
-
}, a = (
|
|
195
|
-
const
|
|
196
|
-
for (const
|
|
197
|
-
if (!Object.prototype.hasOwnProperty.call(
|
|
191
|
+
const o = (e2 = 0, t2 = e2) => {
|
|
192
|
+
const s2 = Math.abs(t2 - e2) || 0, r2 = e2 < t2 ? 1 : -1;
|
|
193
|
+
return ((e3 = 0, t3) => [...Array(e3)].map(t3))(s2, (t3, s3) => s3 * r2 + e2);
|
|
194
|
+
}, a = (e2, t2, s2) => {
|
|
195
|
+
const r2 = [];
|
|
196
|
+
for (const i2 in e2) {
|
|
197
|
+
if (!Object.prototype.hasOwnProperty.call(e2, i2))
|
|
198
198
|
continue;
|
|
199
|
-
const
|
|
199
|
+
const n2 = e2[i2], o2 = s2 ? "" : encodeURIComponent(i2);
|
|
200
200
|
let l2;
|
|
201
|
-
l2 = typeof
|
|
201
|
+
l2 = typeof n2 == "object" ? a(n2, t2 ? t2 + encodeURIComponent("[" + o2 + "]") : o2, Array.isArray(n2)) : (t2 ? t2 + encodeURIComponent("[" + o2 + "]") : o2) + "=" + encodeURIComponent(n2), r2.push(l2);
|
|
202
202
|
}
|
|
203
|
-
return
|
|
203
|
+
return r2.join("&");
|
|
204
204
|
};
|
|
205
205
|
let l = {}, c = {};
|
|
206
|
-
class
|
|
207
|
-
constructor(
|
|
208
|
-
if (!
|
|
209
|
-
let
|
|
210
|
-
|
|
206
|
+
class h {
|
|
207
|
+
constructor(t2, r2) {
|
|
208
|
+
if (!r2) {
|
|
209
|
+
let e2 = t2.region ? `-${t2.region}` : "", s2 = t2.https === false ? "http" : "https";
|
|
210
|
+
r2 = t2.oauthToken === void 0 ? `${s2}://api${e2}.storyblok.com/v2` : `${s2}://api${e2}.storyblok.com/v1`;
|
|
211
211
|
}
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
setComponentResolver(
|
|
216
|
-
this.richTextResolver.addNode("blok", (
|
|
217
|
-
let
|
|
218
|
-
return
|
|
219
|
-
|
|
220
|
-
}), { html:
|
|
212
|
+
let i2 = Object.assign({}, t2.headers), o2 = 5;
|
|
213
|
+
t2.oauthToken !== void 0 && (i2.Authorization = t2.oauthToken, o2 = 3), t2.rateLimit !== void 0 && (o2 = t2.rateLimit), this.richTextResolver = new n(t2.richTextSchema), typeof t2.componentResolver == "function" && this.setComponentResolver(t2.componentResolver), this.maxRetries = t2.maxRetries || 5, this.throttle = s(this.throttledRequest, o2, 1e3), this.accessToken = t2.accessToken, this.relations = {}, this.links = {}, this.cache = t2.cache || { clear: "manual" }, this.client = e.create({ baseURL: r2, timeout: t2.timeout || 0, headers: i2, proxy: t2.proxy || false }), t2.responseInterceptor && this.client.interceptors.response.use((e2) => t2.responseInterceptor(e2)), this.resolveNestedRelations = t2.resolveNestedRelations || true;
|
|
214
|
+
}
|
|
215
|
+
setComponentResolver(e2) {
|
|
216
|
+
this.richTextResolver.addNode("blok", (t2) => {
|
|
217
|
+
let s2 = "";
|
|
218
|
+
return t2.attrs.body.forEach((t3) => {
|
|
219
|
+
s2 += e2(t3.component, t3);
|
|
220
|
+
}), { html: s2 };
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
|
-
parseParams(
|
|
224
|
-
return
|
|
223
|
+
parseParams(e2 = {}) {
|
|
224
|
+
return e2.version || (e2.version = "published"), e2.token || (e2.token = this.getToken()), e2.cv || (e2.cv = c[e2.token]), Array.isArray(e2.resolve_relations) && (e2.resolve_relations = e2.resolve_relations.join(",")), e2;
|
|
225
225
|
}
|
|
226
|
-
factoryParamOptions(
|
|
227
|
-
return ((
|
|
226
|
+
factoryParamOptions(e2, t2 = {}) {
|
|
227
|
+
return ((e3 = "") => e3.indexOf("/cdn/") > -1)(e2) ? this.parseParams(t2) : t2;
|
|
228
228
|
}
|
|
229
|
-
makeRequest(t2,
|
|
230
|
-
const
|
|
231
|
-
return this.cacheResponse(
|
|
229
|
+
makeRequest(e2, t2, s2, r2) {
|
|
230
|
+
const i2 = this.factoryParamOptions(e2, ((e3 = {}, t3 = 25, s3 = 1) => __spreadProps(__spreadValues2({}, e3), { per_page: t3, page: s3 }))(t2, s2, r2));
|
|
231
|
+
return this.cacheResponse(e2, i2);
|
|
232
232
|
}
|
|
233
|
-
get(
|
|
234
|
-
let
|
|
235
|
-
const
|
|
236
|
-
return this.cacheResponse(
|
|
233
|
+
get(e2, t2) {
|
|
234
|
+
let s2 = `/${e2}`;
|
|
235
|
+
const r2 = this.factoryParamOptions(s2, t2);
|
|
236
|
+
return this.cacheResponse(s2, r2);
|
|
237
237
|
}
|
|
238
|
-
async getAll(
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
const a2 = await this.makeRequest(
|
|
242
|
-
return ((
|
|
238
|
+
async getAll(e2, t2 = {}, s2) {
|
|
239
|
+
const r2 = t2.per_page || 25, i2 = `/${e2}`, n2 = i2.split("/");
|
|
240
|
+
s2 = s2 || n2[n2.length - 1];
|
|
241
|
+
const a2 = await this.makeRequest(i2, t2, r2, 1), l2 = Math.ceil(a2.total / r2);
|
|
242
|
+
return ((e3 = [], t3) => e3.map(t3).reduce((e4, t4) => [...e4, ...t4], []))([a2, ...await (async (e3 = [], t3) => Promise.all(e3.map(t3)))(o(1, l2), async (e3) => this.makeRequest(i2, t2, r2, e3 + 1))], (e3) => Object.values(e3.data[s2]));
|
|
243
243
|
}
|
|
244
|
-
post(
|
|
245
|
-
let
|
|
246
|
-
return this.throttle("post",
|
|
244
|
+
post(e2, t2) {
|
|
245
|
+
let s2 = `/${e2}`;
|
|
246
|
+
return this.throttle("post", s2, t2);
|
|
247
247
|
}
|
|
248
|
-
put(
|
|
249
|
-
let
|
|
250
|
-
return this.throttle("put",
|
|
248
|
+
put(e2, t2) {
|
|
249
|
+
let s2 = `/${e2}`;
|
|
250
|
+
return this.throttle("put", s2, t2);
|
|
251
251
|
}
|
|
252
|
-
delete(
|
|
253
|
-
let
|
|
254
|
-
return this.throttle("delete",
|
|
252
|
+
delete(e2, t2) {
|
|
253
|
+
let s2 = `/${e2}`;
|
|
254
|
+
return this.throttle("delete", s2, t2);
|
|
255
255
|
}
|
|
256
|
-
getStories(
|
|
257
|
-
return this.get("cdn/stories",
|
|
256
|
+
getStories(e2) {
|
|
257
|
+
return this.get("cdn/stories", e2);
|
|
258
258
|
}
|
|
259
|
-
getStory(
|
|
260
|
-
return this.get(
|
|
259
|
+
getStory(e2, t2) {
|
|
260
|
+
return this.get(`cdn/stories/${e2}`, t2);
|
|
261
261
|
}
|
|
262
|
-
setToken(
|
|
263
|
-
this.accessToken =
|
|
262
|
+
setToken(e2) {
|
|
263
|
+
this.accessToken = e2;
|
|
264
264
|
}
|
|
265
265
|
getToken() {
|
|
266
266
|
return this.accessToken;
|
|
267
267
|
}
|
|
268
|
-
_cleanCopy(
|
|
269
|
-
return JSON.parse(JSON.stringify(
|
|
270
|
-
}
|
|
271
|
-
_insertLinks(
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
_insertRelations(
|
|
276
|
-
if (
|
|
277
|
-
if (typeof t2
|
|
278
|
-
this.relations[t2
|
|
279
|
-
else if (t2
|
|
280
|
-
let
|
|
281
|
-
t2
|
|
282
|
-
this.relations[
|
|
283
|
-
}), t2
|
|
268
|
+
_cleanCopy(e2) {
|
|
269
|
+
return JSON.parse(JSON.stringify(e2));
|
|
270
|
+
}
|
|
271
|
+
_insertLinks(e2, t2) {
|
|
272
|
+
const s2 = e2[t2];
|
|
273
|
+
s2 && s2.fieldtype == "multilink" && s2.linktype == "story" && typeof s2.id == "string" && this.links[s2.id] ? s2.story = this._cleanCopy(this.links[s2.id]) : s2 && s2.linktype === "story" && typeof s2.uuid == "string" && this.links[s2.uuid] && (s2.story = this._cleanCopy(this.links[s2.uuid]));
|
|
274
|
+
}
|
|
275
|
+
_insertRelations(e2, t2, s2) {
|
|
276
|
+
if (s2.indexOf(e2.component + "." + t2) > -1) {
|
|
277
|
+
if (typeof e2[t2] == "string")
|
|
278
|
+
this.relations[e2[t2]] && (e2[t2] = this._cleanCopy(this.relations[e2[t2]]));
|
|
279
|
+
else if (e2[t2].constructor === Array) {
|
|
280
|
+
let s3 = [];
|
|
281
|
+
e2[t2].forEach((e3) => {
|
|
282
|
+
this.relations[e3] && s3.push(this._cleanCopy(this.relations[e3]));
|
|
283
|
+
}), e2[t2] = s3;
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
287
|
+
_insertAssetsRelations(e2, t2) {
|
|
288
|
+
t2.forEach((t3) => {
|
|
289
|
+
e2.id === t3.id && (e2.original = t3, e2.original.filename = e2.filename, e2.original.filename = e2.original.filename.includes("https://s3.amazonaws.com/") ? e2.original.filename : e2.original.filename.replace("https://", "https://s3.amazonaws.com/"), delete e2.original.s3_filename);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
iterateTree(e2, t2) {
|
|
293
|
+
let s2 = (e3) => {
|
|
294
|
+
if (e3 != null) {
|
|
295
|
+
if (e3.constructor === Array)
|
|
296
|
+
for (let t3 = 0; t3 < e3.length; t3++)
|
|
297
|
+
s2(e3[t3]);
|
|
298
|
+
else if (e3.constructor === Object) {
|
|
299
|
+
if (e3._stopResolving)
|
|
295
300
|
return;
|
|
296
|
-
for (let
|
|
297
|
-
|
|
301
|
+
for (let r2 in e3)
|
|
302
|
+
e3.component && e3._uid || e3.type === "link" ? (this._insertRelations(e3, r2, t2), this._insertLinks(e3, r2)) : e3.fieldtype === "asset" && this._insertAssetsRelations(e3, t2), s2(e3[r2]);
|
|
298
303
|
}
|
|
299
304
|
}
|
|
300
305
|
};
|
|
301
|
-
|
|
302
|
-
}
|
|
303
|
-
async resolveLinks(
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
const
|
|
307
|
-
let
|
|
308
|
-
const
|
|
309
|
-
for (let
|
|
310
|
-
const
|
|
311
|
-
|
|
306
|
+
s2(e2.content);
|
|
307
|
+
}
|
|
308
|
+
async resolveLinks(e2, t2) {
|
|
309
|
+
let s2 = [];
|
|
310
|
+
if (e2.link_uuids) {
|
|
311
|
+
const r2 = e2.link_uuids.length;
|
|
312
|
+
let i2 = [];
|
|
313
|
+
const n2 = 50;
|
|
314
|
+
for (let t3 = 0; t3 < r2; t3 += n2) {
|
|
315
|
+
const s3 = Math.min(r2, t3 + n2);
|
|
316
|
+
i2.push(e2.link_uuids.slice(t3, s3));
|
|
312
317
|
}
|
|
313
|
-
for (let
|
|
314
|
-
(await this.getStories({ per_page:
|
|
315
|
-
|
|
318
|
+
for (let e3 = 0; e3 < i2.length; e3++) {
|
|
319
|
+
(await this.getStories({ per_page: n2, language: t2.language, version: t2.version, by_uuids: i2[e3].join(",") })).data.stories.forEach((e4) => {
|
|
320
|
+
s2.push(e4);
|
|
316
321
|
});
|
|
317
322
|
}
|
|
318
323
|
} else
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
this.links[
|
|
324
|
+
s2 = e2.links;
|
|
325
|
+
s2.forEach((e3) => {
|
|
326
|
+
this.links[e3.uuid] = __spreadProps(__spreadValues2({}, e3), { _stopResolving: true });
|
|
322
327
|
});
|
|
323
328
|
}
|
|
324
|
-
async resolveRelations(
|
|
325
|
-
let
|
|
326
|
-
if (
|
|
327
|
-
const
|
|
328
|
-
let
|
|
329
|
-
const
|
|
330
|
-
for (let
|
|
331
|
-
const
|
|
332
|
-
|
|
329
|
+
async resolveRelations(e2, t2) {
|
|
330
|
+
let s2 = [];
|
|
331
|
+
if (e2.rel_uuids) {
|
|
332
|
+
const r2 = e2.rel_uuids.length;
|
|
333
|
+
let i2 = [];
|
|
334
|
+
const n2 = 50;
|
|
335
|
+
for (let t3 = 0; t3 < r2; t3 += n2) {
|
|
336
|
+
const s3 = Math.min(r2, t3 + n2);
|
|
337
|
+
i2.push(e2.rel_uuids.slice(t3, s3));
|
|
333
338
|
}
|
|
334
|
-
for (let
|
|
335
|
-
(await this.getStories({ per_page:
|
|
336
|
-
|
|
339
|
+
for (let e3 = 0; e3 < i2.length; e3++) {
|
|
340
|
+
(await this.getStories({ per_page: n2, language: t2.language, version: t2.version, by_uuids: i2[e3].join(",") })).data.stories.forEach((e4) => {
|
|
341
|
+
s2.push(e4);
|
|
337
342
|
});
|
|
338
343
|
}
|
|
339
344
|
} else
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
this.relations[
|
|
345
|
+
s2 = e2.rels;
|
|
346
|
+
s2.forEach((e3) => {
|
|
347
|
+
this.relations[e3.uuid] = __spreadProps(__spreadValues2({}, e3), { _stopResolving: true });
|
|
343
348
|
});
|
|
344
349
|
}
|
|
345
|
-
async resolveStories(
|
|
346
|
-
let
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
this.iterateTree(
|
|
350
|
+
async resolveStories(e2, t2) {
|
|
351
|
+
let s2 = [];
|
|
352
|
+
if (t2.resolve_relations !== void 0 && t2.resolve_relations.length > 0 && (s2 = t2.resolve_relations.split(","), await this.resolveRelations(e2, t2)), ["1", "story", "url"].indexOf(t2.resolve_links) > -1 && await this.resolveLinks(e2, t2), this.resolveNestedRelations)
|
|
353
|
+
for (const e3 in this.relations)
|
|
354
|
+
this.iterateTree(this.relations[e3], s2);
|
|
355
|
+
e2.story ? this.iterateTree(e2.story, s2) : e2.stories.forEach((e3) => {
|
|
356
|
+
this.iterateTree(e3, s2);
|
|
352
357
|
});
|
|
353
358
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
359
|
+
resolveAssetsRelations(e2) {
|
|
360
|
+
const { assets: t2, stories: s2, story: r2 } = e2;
|
|
361
|
+
if (s2)
|
|
362
|
+
for (const e3 of s2)
|
|
363
|
+
this.iterateTree(e3, t2);
|
|
364
|
+
else
|
|
365
|
+
this.iterateTree(r2, t2);
|
|
366
|
+
}
|
|
367
|
+
cacheResponse(e2, t2, s2) {
|
|
368
|
+
return s2 === void 0 && (s2 = 0), new Promise(async (r2, i2) => {
|
|
369
|
+
let n2 = a({ url: e2, params: t2 }), o2 = this.cacheProvider();
|
|
370
|
+
if (this.cache.clear === "auto" && t2.version === "draft" && await this.flushCache(), t2.version === "published" && e2 != "/cdn/spaces/me") {
|
|
371
|
+
const e3 = await o2.get(n2);
|
|
372
|
+
if (e3)
|
|
373
|
+
return r2(e3);
|
|
361
374
|
}
|
|
362
375
|
try {
|
|
363
|
-
let
|
|
364
|
-
if (
|
|
365
|
-
return
|
|
366
|
-
(l3.data.story || l3.data.stories) && await this.resolveStories(l3.data,
|
|
367
|
-
} catch (
|
|
368
|
-
if (
|
|
369
|
-
return console.log(`Hit rate limit. Retrying in ${
|
|
370
|
-
|
|
376
|
+
let s3 = await this.throttle("get", e2, { params: t2, paramsSerializer: (e3) => a(e3) }), l3 = { data: s3.data, headers: s3.headers };
|
|
377
|
+
if (l3.data.assets && l3.data.assets.length && this.resolveAssetsRelations(l3.data), s3.headers["per-page"] && (l3 = Object.assign({}, l3, { perPage: parseInt(s3.headers["per-page"]), total: parseInt(s3.headers.total) })), s3.status != 200)
|
|
378
|
+
return i2(s3);
|
|
379
|
+
(l3.data.story || l3.data.stories) && await this.resolveStories(l3.data, t2), t2.version === "published" && e2 != "/cdn/spaces/me" && o2.set(n2, l3), l3.data.cv && (t2.version == "draft" && c[t2.token] != l3.data.cv && this.flushCache(), c[t2.token] = l3.data.cv), r2(l3);
|
|
380
|
+
} catch (n3) {
|
|
381
|
+
if (n3.response && n3.response.status === 429 && (s2 += 1) < this.maxRetries)
|
|
382
|
+
return console.log(`Hit rate limit. Retrying in ${s2} seconds.`), await (l2 = 1e3 * s2, new Promise((e3) => setTimeout(e3, l2))), this.cacheResponse(e2, t2, s2).then(r2).catch(i2);
|
|
383
|
+
i2(n3);
|
|
371
384
|
}
|
|
372
385
|
var l2;
|
|
373
386
|
});
|
|
374
387
|
}
|
|
375
|
-
throttledRequest(
|
|
376
|
-
return this.client[
|
|
388
|
+
throttledRequest(e2, t2, s2) {
|
|
389
|
+
return this.client[e2](t2, s2);
|
|
377
390
|
}
|
|
378
391
|
cacheVersions() {
|
|
379
392
|
return c;
|
|
@@ -381,24 +394,19 @@ class StoryblokClient {
|
|
|
381
394
|
cacheVersion() {
|
|
382
395
|
return c[this.accessToken];
|
|
383
396
|
}
|
|
384
|
-
setCacheVersion(
|
|
385
|
-
this.accessToken && (c[this.accessToken] =
|
|
397
|
+
setCacheVersion(e2) {
|
|
398
|
+
this.accessToken && (c[this.accessToken] = e2);
|
|
386
399
|
}
|
|
387
400
|
cacheProvider() {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
}, getAll() {
|
|
398
|
-
}, set() {
|
|
399
|
-
}, flush() {
|
|
400
|
-
} };
|
|
401
|
-
}
|
|
401
|
+
return this.cache.type === "memory" ? { get: (e2) => l[e2], getAll: () => l, set(e2, t2) {
|
|
402
|
+
l[e2] = t2;
|
|
403
|
+
}, flush() {
|
|
404
|
+
l = {};
|
|
405
|
+
} } : { get() {
|
|
406
|
+
}, getAll() {
|
|
407
|
+
}, set() {
|
|
408
|
+
}, flush() {
|
|
409
|
+
} };
|
|
402
410
|
}
|
|
403
411
|
async flushCache() {
|
|
404
412
|
return await this.cacheProvider().flush(), this;
|
|
@@ -410,7 +418,7 @@ var api = (options = {}) => {
|
|
|
410
418
|
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");
|
|
411
419
|
return;
|
|
412
420
|
}
|
|
413
|
-
const storyblokApi = new
|
|
421
|
+
const storyblokApi = new h(apiOptions);
|
|
414
422
|
return { storyblokApi };
|
|
415
423
|
};
|
|
416
424
|
var editable = (blok) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4",
|
|
4
4
|
"description": "Storyblok directive for get editable elements.",
|
|
5
5
|
"main": "./dist/storyblok-vue.js",
|
|
6
6
|
"module": "./dist/storyblok-vue.mjs",
|
|
@@ -23,22 +23,22 @@
|
|
|
23
23
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@storyblok/js": "^1.
|
|
26
|
+
"@storyblok/js": "^1.2.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@babel/core": "^7.
|
|
29
|
+
"@babel/core": "^7.18.5",
|
|
30
30
|
"@cypress/vite-dev-server": "^2.0.7",
|
|
31
|
-
"@cypress/vue": "^3.
|
|
32
|
-
"@vitejs/plugin-vue": "^2.3.
|
|
31
|
+
"@cypress/vue": "^3.1.2",
|
|
32
|
+
"@vitejs/plugin-vue": "^2.3.3",
|
|
33
33
|
"@vue/babel-preset-app": "^5.0.4",
|
|
34
34
|
"@vue/test-utils": "next",
|
|
35
|
-
"babel-jest": "^
|
|
36
|
-
"cypress": "^9.
|
|
35
|
+
"babel-jest": "^28.1.0",
|
|
36
|
+
"cypress": "^9.6.0",
|
|
37
37
|
"eslint-plugin-cypress": "^2.12.1",
|
|
38
|
-
"eslint-plugin-jest": "^26.1.
|
|
39
|
-
"jest": "^
|
|
40
|
-
"vite": "^2.
|
|
41
|
-
"vue": "^3.2.
|
|
38
|
+
"eslint-plugin-jest": "^26.1.5",
|
|
39
|
+
"jest": "^28.1.0",
|
|
40
|
+
"vite": "^2.9.9",
|
|
41
|
+
"vue": "^3.2.33",
|
|
42
42
|
"vue-jest": "next"
|
|
43
43
|
},
|
|
44
44
|
"babel": {
|