Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@storyblok/vue

Package Overview
Dependencies
Maintainers
5
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storyblok/vue - npm Package Compare versions

Comparing version 6.0.4 to 6.1.0

dist/index.d.ts

8

dist/storyblok-vue.js

@@ -1,6 +0,6 @@

(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)});/*!
* storyblok-js-client v0.0.0-development
(function(d,u){typeof exports=="object"&&typeof module!="undefined"?u(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],u):(d=typeof globalThis!="undefined"?globalThis:d||self,u(d.storyblokVue={},d.Vue,d.e))})(this,function(d,u,p){"use strict";var et=Object.defineProperty;var j=Object.getOwnPropertySymbols;var rt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable;var C=(d,u,p)=>u in d?et(d,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):d[u]=p,_=(d,u)=>{for(var p in u||(u={}))rt.call(u,p)&&C(d,p,u[p]);if(j)for(var p of j(u))st.call(u,p)&&C(d,p,u[p]);return d};function M(o){return o&&typeof o=="object"&&"default"in o?o:{default:o}}var x=M(p),I=Object.defineProperty,N=Object.defineProperties,B=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,T=(o,t,e)=>t in o?I(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)=>N(o,B(t));let R=!1;const S=[],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():S.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=>{S.forEach(n=>n()),R=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(r)});/*!
* storyblok-js-client v4.5.2
* Universal JavaScript SDK for Storyblok's API
* (c) 2020-2022 Stobylok Team
*/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={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},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.
`)};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"});
*/function E(o){return typeof o=="number"&&o==o&&o!==1/0&&o!==-1/0}function O(o,t,e){if(!E(t))throw new TypeError("Expected `limit` to be a finite number");if(!E(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(h){return h!==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(h,m){r.push({resolve:h,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}O.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={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},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=O(this.throttledRequest,s,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=x.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=[],h)=>l.map(h).reduce((m,tt)=>[...m,...tt],[]))([a,...await(async(l=[],h)=>Promise.all(l.map(h)))(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)}),h={data:l.data,headers:l.headers};if(h.data.assets&&h.data.assets.length&&this.resolveAssetsRelations(h.data),l.headers["per-page"]&&(h=Object.assign({},h,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return n(l);(h.data.story||h.data.stories)&&await this.resolveStories(h.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&a.set(i,h),h.data.cv&&(e.version=="draft"&&g[e.token]!=h.data.cv&&this.flushCache(),g[e.token]=h.data.cv),s(h)}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(h=>setTimeout(h,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}}const F=(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)}};var H=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},$=u.defineComponent({__name:"StoryblokComponent",props:{blok:null},setup(o){return(t,e)=>(u.openBlock(),u.createBlock(u.resolveDynamicComponent(o.blok.component),u.normalizeProps(u.guardReactiveProps(_(_({},t.$props),t.$attrs))),null,16))}}),Q={beforeMount(o,t){if(t.value){const e=H(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.
`)};let y=null;const W=()=>(y||A("useStoryblokApi"),y),X=async(o,t={},e={})=>{const r=u.ref(null);if(u.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}};d.StoryblokComponent=$,d.StoryblokVue=Z,d.apiPlugin=F,d.useStoryblok=X,d.useStoryblokApi=W,d.useStoryblokBridge=P,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
{
"name": "@storyblok/vue",
"version": "6.0.4",
"version": "6.1.0",
"description": "Storyblok directive for get editable elements.",
"main": "./dist/storyblok-vue.js",
"module": "./dist/storyblok-vue.mjs",
"types": "./dist/index.d.ts",
"files": [

@@ -18,3 +19,3 @@ "dist"

"dev": "vite build --watch",
"build": "vite build",
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly",
"test": "npm run test:unit && npm run test:e2e",

@@ -27,3 +28,3 @@ "test:unit": "jest __tests__",

"dependencies": {
"@storyblok/js": "^1.2.0"
"@storyblok/js": "^1.6.1"
},

@@ -37,10 +38,13 @@ "devDependencies": {

"@vue/test-utils": "next",
"babel-jest": "^28.1.0",
"@vue/tsconfig": "^0.1.3",
"babel-jest": "^26.0.0",
"cypress": "^9.6.0",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-jest": "^26.1.5",
"jest": "^28.1.0",
"jest": "^26.1.0",
"typescript": "^4.7.3",
"vite": "^2.9.9",
"vue": "^3.2.33",
"vue-jest": "next"
"vue-jest": "next",
"vue-tsc": "^0.37.9"
},

@@ -47,0 +51,0 @@ "babel": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc