@storyblok/vue 6.2.1 → 6.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/storyblok-vue.js +4 -4
- package/dist/storyblok-vue.mjs +131 -104
- package/package.json +4 -4
package/dist/storyblok-vue.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(h,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],d):(h=typeof globalThis<"u"?globalThis:h||self,d(h.storyblokVue={},h.Vue,h.e))})(this,function(h,d,
|
|
1
|
+
(function(h,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("vue"),require("axios")):typeof define=="function"&&define.amd?define(["exports","vue","axios"],d):(h=typeof globalThis<"u"?globalThis:h||self,d(h.storyblokVue={},h.Vue,h.e))})(this,function(h,d,x){"use strict";const C=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(x);var M=Object.defineProperty,N=Object.defineProperties,I=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,q=Object.prototype.hasOwnProperty,L=Object.prototype.propertyIsEnumerable,T=(n,e,t)=>e in n?M(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,p=(n,e)=>{for(var t in e||(e={}))q.call(e,t)&&T(n,t,e[t]);if(_)for(var t of _(e))L.call(e,t)&&T(n,t,e[t]);return n},b=(n,e)=>N(n,I(e));let w=!1;const R=[],B=n=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}w?s():R.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const r=document.createElement("script");r.async=!0,r.src=n,r.id="storyblok-javascript-bridge",r.onerror=s=>t(s),r.onload=s=>{R.forEach(o=>o()),w=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(r)}),z=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t},D=n=>n==="email";var V={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(n){return{tag:["pre",{tag:"code",attrs:n.attrs}]}},hard_break(){return{singleTag:"br"}},heading(n){return{tag:`h${n.attrs.level}`}},image(n){return{singleTag:[{tag:"img",attrs:z(n.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(n){const e=p({},n.attrs),{linktype:t="url"}=n.attrs;return D(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled(n){return{tag:[{tag:"span",attrs:n.attrs}]}}}};const U=function(n){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,r=RegExp(t.source);return n&&r.test(n)?n.replace(t,s=>e[s]):n};class ${constructor(e){e||(e=V),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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(U(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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let o=`<${s.tag}`;if(s.attrs)for(let a in s.attrs){let i=s.attrs[a];i!==null&&(o+=` ${a}="${i}"`)}return`${o}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.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)}}/*!
|
|
2
2
|
* storyblok-js-client v4.5.2
|
|
3
3
|
* Universal JavaScript SDK for Storyblok's API
|
|
4
4
|
* (c) 2020-2022 Stobylok Team
|
|
5
|
-
*/function R(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function $(n,t,e){if(!R(t))throw new TypeError("Expected `limit` to be a finite number");if(!R(e))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],o=0,i=function(){o++;var c=setTimeout(function(){o--,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(n.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(u,y){r.push({resolve:u,reject:y,args:c,self:l}),o<t&&i()})};return a.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}$.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const D=function(n,t){if(!n)return null;let e={};for(let r in n){let s=n[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e};var U={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:n=>({tag:`h${n.attrs.level}`}),image:n=>({singleTag:[{tag:"img",attrs:D(n.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(n){const t=p({},n.attrs),{linktype:e="url"}=n.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:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class H{constructor(t){t||(t=U),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 o=this.getMatchingMark(s);o&&e.push(this.renderOpeningTag(o.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 o={"&":"&","<":"<",">":">",'"':""","'":"'"},i=/[&<>"']/g,a=RegExp(i.source);return s&&a.test(s)?s.replace(i,c=>o[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 o=this.getMatchingMark(s);o&&e.push(this.renderClosingTag(o.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 o in r.attrs){let i=r.attrs[o];i!==null&&(s+=` ${o}="${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=(n=0,t=n)=>{const e=Math.abs(t-n)||0,r=n<t?1:-1;return((s=0,o)=>[...Array(s)].map(o))(e,(s,o)=>o*r+n)},b=(n,t,e)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],i=e?"":encodeURIComponent(s);let a;a=typeof o=="object"?b(o,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(o)):(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(o),r.push(a)}return r.join("&")};let k={},f={};class Y{constructor(t,e){if(!e){let o=t.region?`-${t.region}`:"",i=t.https===!1?"http":"https";e=t.oauthToken===void 0?`${i}://api${o}.storyblok.com/v2`:`${i}://api${o}.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 H(t.richTextSchema),typeof t.componentResolver=="function"&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=$(this.throttledRequest,s,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=j.default.create({baseURL:e,timeout:t.timeout||0,headers:r,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use(o=>t.responseInterceptor(o)),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=f[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 o=this.factoryParamOptions(t,((i={},a=25,c=1)=>m(p({},i),{per_page:a,page:c}))(e,r,s));return this.cacheResponse(t,o)}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,o=`/${t}`,i=o.split("/");r=r||i[i.length-1];const a=await this.makeRequest(o,e,s,1),c=Math.ceil(a.total/s);return((l=[],u)=>l.map(u).reduce((y,st)=>[...y,...st],[]))([a,...await(async(l=[],u)=>Promise.all(l.map(u)))(J(1,c),async l=>this.makeRequest(o,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(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),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 o=0;o<s.length;o++)r(s[o]);else if(s.constructor===Object){if(s._stopResolving)return;for(let o in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,o,e),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,e),r(s[o])}}};r(t.content)}async resolveLinks(t,e){let r=[];if(t.link_uuids){const s=t.link_uuids.length;let o=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);o.push(t.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=t.links;r.forEach(s=>{this.links[s.uuid]=m(p({},s),{_stopResolving:!0})})}async resolveRelations(t,e){let r=[];if(t.rel_uuids){const s=t.rel_uuids.length;let o=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);o.push(t.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=t.rels;r.forEach(s=>{this.relations[s.uuid]=m(p({},s),{_stopResolving:!0})})}async resolveStories(t,e){let r=[];if(e.resolve_relations!==void 0&&e.resolve_relations.length>0&&(t.rels||t.rel_uuids)&&(r=e.resolve_relations.split(","),await this.resolveRelations(t,e)),["1","story","url"].indexOf(e.resolve_links)>-1&&(t.links||t.link_uuids)&&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 o of r)this.iterateTree(o,e);else{if(!s)return t;this.iterateTree(s,e)}}cacheResponse(t,e,r){return r===void 0&&(r=0),new Promise(async(s,o)=>{let i=b({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:y=>b(y)}),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 o(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"&&f[e.token]!=u.data.cv&&this.flushCache(),f[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(o);o(l)}var c})}throttledRequest(t,e,r){return this.client[t](e,r)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(t){this.accessToken&&(f[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=(n={})=>{const{apiOptions:t}=n;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 G=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const t=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};const K=new z,Q="https://app.storyblok.com/f/storyblok-v2-latest.js",E=(n,t,e={})=>{if(!(typeof window>"u")){if(typeof window.storyblokRegisterEvent>"u"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!n){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.story.id===n&&(s.action==="input"?t(s.story):window.location.reload())})})}},W=(n={})=>{const{bridge:t,accessToken:e,use:r=[],apiOptions:s={}}=n;s.accessToken=s.accessToken||e;const o={bridge:t,apiOptions:s};let i={};return r.forEach(a=>{i=p(p({},i),a(o))}),t!==!1&&I(Q),i},X=n=>n===""?"":n?K.render(n):(console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
5
|
+
*/function S(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function E(n,e,t){if(!S(e))throw new TypeError("Expected `limit` to be a finite number");if(!S(t))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],o=0,a=function(){o++;var c=setTimeout(function(){o--,r.length>0&&a(),s=s.filter(function(u){return u!==c})},t);s.indexOf(c)<0&&s.push(c);var l=r.shift();l.resolve(n.apply(l.self,l.args))},i=function(){var c=arguments,l=this;return new Promise(function(u,y){r.push({resolve:u,reject:y,args:c,self:l}),o<e&&a()})};return i.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},i}E.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const H=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t};var J={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:n=>({tag:`h${n.attrs.level}`}),image:n=>({singleTag:[{tag:"img",attrs:H(n.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(n){const e=p({},n.attrs),{linktype:t="url"}=n.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:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class Y{constructor(e){e||(e=J),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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(function(s){const o={"&":"&","<":"<",">":">",'"':""","'":"'"},a=/[&<>"']/g,i=RegExp(a.source);return s&&i.test(s)?s.replace(a,c=>o[c]):s}(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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let s=`<${r.tag}`;if(r.attrs)for(let o in r.attrs){let a=r.attrs[o];a!==null&&(s+=` ${o}="${a}"`)}return`${s}${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 F=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return((s=0,o)=>[...Array(s)].map(o))(t,(s,o)=>o*r+n)},v=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],a=t?"":encodeURIComponent(s);let i;i=typeof o=="object"?v(o,e?e+encodeURIComponent("["+a+"]"):a,Array.isArray(o)):(e?e+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(o),r.push(i)}return r.join("&")};let m={},f={};class K{constructor(e,t){if(!t){let o=e.region?`-${e.region}`:"",a=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${a}://api${o}.storyblok.com/v2`:`${a}://api${o}.storyblok.com/v1`}let r=Object.assign({},e.headers),s=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,s=3),e.rateLimit!==void 0&&(s=e.rateLimit),this.richTextResolver=new Y(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=E(this.throttledRequest,s,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=C.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(o=>e.responseInterceptor(o)),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=f[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,s){const o=this.factoryParamOptions(e,((a={},i=25,c=1)=>b(p({},a),{per_page:i,page:c}))(t,r,s));return this.cacheResponse(e,o)}get(e,t){let r=`/${e}`;const s=this.factoryParamOptions(r,t);return this.cacheResponse(r,s)}async getAll(e,t={},r){const s=t.per_page||25,o=`/${e}`,a=o.split("/");r=r||a[a.length-1];const i=await this.makeRequest(o,t,s,1),c=Math.ceil(i.total/s);return((l=[],u)=>l.map(u).reduce((y,ne)=>[...y,...ne],[]))([i,...await(async(l=[],u)=>Promise.all(l.map(u)))(F(1,c),async l=>this.makeRequest(o,t,s,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 s=[];e[t].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),e[t]=s}}}_insertAssetsRelations(e,t){t.forEach(r=>{e.id===r.id&&(e.original=r,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)})}iterateTree(e,t){let r=s=>{if(s!=null){if(s.constructor===Array)for(let o=0;o<s.length;o++)r(s[o]);else if(s.constructor===Object){if(s._stopResolving)return;for(let o in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,o,t),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,t),r(s[o])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const s=e.link_uuids.length;let o=[];const a=50;for(let i=0;i<s;i+=a){const c=Math.min(s,i+a);o.push(e.link_uuids.slice(i,c))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(s=>{this.links[s.uuid]=b(p({},s),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const s=e.rel_uuids.length;let o=[];const a=50;for(let i=0;i<s;i+=a){const c=Math.min(s,i+a);o.push(e.rel_uuids.slice(i,c))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r.forEach(s=>{this.relations[s.uuid]=b(p({},s),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];if(t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const s in this.relations)this.iterateTree(this.relations[s],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(s=>{this.iterateTree(s,r)})}resolveAssetsRelations(e){const{assets:t,stories:r,story:s}=e;if(r)for(const o of r)this.iterateTree(o,t);else{if(!s)return e;this.iterateTree(s,t)}}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(s,o)=>{let a=v({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await i.get(a);if(l)return s(l)}try{let l=await this.throttle("get",e,{params:t,paramsSerializer:y=>v(y)}),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 o(l);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&i.set(a,u),u.data.cv&&(t.version=="draft"&&f[t.token]!=u.data.cv&&this.flushCache(),f[t.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(e,t,r).then(s).catch(o);o(l)}var c})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(e){this.accessToken&&(f[this.accessToken]=e)}cacheProvider(){return this.cache.type==="memory"?{get:e=>m[e],getAll:()=>m,set(e,t){m[e]=t},flush(){m={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const G=(n={})=>{const{apiOptions:e}=n;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 K(e)}};var Q=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let k;const W="https://app.storyblok.com/f/storyblok-v2-latest.js",O=(n,e,t={})=>{if(!(typeof window>"u")){if(typeof window.storyblokRegisterEvent>"u"){console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");return}if(!n){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],s=>{s.story.id===n&&(s.action==="input"?e(s.story):window.location.reload())})})}},X=(n={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:s={},richText:o={}}=n;s.accessToken=s.accessToken||t;const a={bridge:e,apiOptions:s};let i={};return r.forEach(c=>{i=p(p({},i),c(a))}),e!==!1&&B(W),k=new $(o.schema),o.resolver&&P(k,o.resolver),i},P=(n,e)=>{n.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})},Z=(n,e)=>{if(!k){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}if(n==="")return"";if(!n)return console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
6
6
|
|
|
7
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),""),
|
|
8
|
-
`)};let g=null;const
|
|
7
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"";let t=k;return e&&(t=new $(e.schema),e.resolver&&P(t,e.resolver)),t.render(n)},j=d.defineComponent({__name:"StoryblokComponent",props:{blok:null},setup(n){return(e,t)=>(d.openBlock(),d.createBlock(d.resolveDynamicComponent(n.blok.component),d.normalizeProps(d.guardReactiveProps({...e.$props,...e.$attrs})),null,16))}}),ee={beforeMount(n,e){if(e.value){const t=Q(e.value);n.setAttribute("data-blok-c",t["data-blok-c"]),n.setAttribute("data-blok-uid",t["data-blok-uid"]),n.classList.add("storyblok__outline")}}},A=n=>{console.error(`You can't use ${n} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
8
|
+
`)};let g=null;const te=()=>(g||A("useStoryblokApi"),g),re=async(n,e={},t={})=>{const r=d.ref(null);if(d.onMounted(()=>{r.value&&r.value.id&&O(r.value.id,s=>r.value=s,t)}),g){const{data:s}=await g.get(`cdn/stories/${n}`,e);r.value=s.story}else A("useStoryblok");return r},se={install(n,e={}){n.directive("editable",ee),n.component("StoryblokComponent",j);const{storyblokApi:t}=X(e);g=t}};h.StoryblokComponent=j,h.StoryblokVue=se,h.apiPlugin=G,h.renderRichText=Z,h.useStoryblok=re,h.useStoryblokApi=te,h.useStoryblokBridge=O,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import
|
|
3
|
-
var
|
|
1
|
+
import { defineComponent as P, openBlock as j, createBlock as x, resolveDynamicComponent as A, normalizeProps as C, guardReactiveProps as M, ref as N, onMounted as I } from "vue";
|
|
2
|
+
import q from "axios";
|
|
3
|
+
var L = Object.defineProperty, z = Object.defineProperties, B = Object.getOwnPropertyDescriptors, v = Object.getOwnPropertySymbols, D = Object.prototype.hasOwnProperty, U = Object.prototype.propertyIsEnumerable, b = (n, t, e) => t in n ? L(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, h = (n, t) => {
|
|
4
4
|
for (var e in t || (t = {}))
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
for (var e of
|
|
8
|
-
|
|
5
|
+
D.call(t, e) && b(n, e, t[e]);
|
|
6
|
+
if (v)
|
|
7
|
+
for (var e of v(t))
|
|
8
|
+
U.call(t, e) && b(n, e, t[e]);
|
|
9
9
|
return n;
|
|
10
|
-
}, y = (n, t) =>
|
|
11
|
-
let
|
|
12
|
-
const
|
|
10
|
+
}, y = (n, t) => z(n, B(t));
|
|
11
|
+
let _ = !1;
|
|
12
|
+
const T = [], V = (n) => new Promise((t, e) => {
|
|
13
13
|
if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
|
|
14
14
|
if (window.location === window.parent.location) {
|
|
15
15
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
_ ? s() : T.push(s);
|
|
19
19
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
20
20
|
return;
|
|
21
21
|
const r = document.createElement("script");
|
|
22
22
|
r.async = !0, r.src = n, r.id = "storyblok-javascript-bridge", r.onerror = (s) => e(s), r.onload = (s) => {
|
|
23
|
-
|
|
23
|
+
T.forEach((o) => o()), _ = !0, t(s);
|
|
24
24
|
}, document.getElementsByTagName("head")[0].appendChild(r);
|
|
25
|
-
}),
|
|
25
|
+
}), H = function(n, t) {
|
|
26
26
|
if (!n)
|
|
27
27
|
return null;
|
|
28
28
|
let e = {};
|
|
@@ -31,8 +31,8 @@ const _ = [], z = (n) => new Promise((t, e) => {
|
|
|
31
31
|
t.indexOf(r) > -1 && s !== null && (e[r] = s);
|
|
32
32
|
}
|
|
33
33
|
return e;
|
|
34
|
-
},
|
|
35
|
-
var
|
|
34
|
+
}, J = (n) => n === "email";
|
|
35
|
+
var Y = {
|
|
36
36
|
nodes: {
|
|
37
37
|
horizontal_rule() {
|
|
38
38
|
return {
|
|
@@ -75,7 +75,7 @@ var V = {
|
|
|
75
75
|
singleTag: [
|
|
76
76
|
{
|
|
77
77
|
tag: "img",
|
|
78
|
-
attrs:
|
|
78
|
+
attrs: H(n.attrs, ["src", "alt", "title"])
|
|
79
79
|
}
|
|
80
80
|
]
|
|
81
81
|
};
|
|
@@ -129,7 +129,7 @@ var V = {
|
|
|
129
129
|
},
|
|
130
130
|
link(n) {
|
|
131
131
|
const t = h({}, n.attrs), { linktype: e = "url" } = n.attrs;
|
|
132
|
-
return
|
|
132
|
+
return J(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
|
|
133
133
|
tag: [
|
|
134
134
|
{
|
|
135
135
|
tag: "a",
|
|
@@ -150,7 +150,7 @@ var V = {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
-
const
|
|
153
|
+
const F = function(n) {
|
|
154
154
|
const t = {
|
|
155
155
|
"&": "&",
|
|
156
156
|
"<": "<",
|
|
@@ -160,9 +160,9 @@ const H = function(n) {
|
|
|
160
160
|
}, e = /[&<>"']/g, r = RegExp(e.source);
|
|
161
161
|
return n && r.test(n) ? n.replace(e, (s) => t[s]) : n;
|
|
162
162
|
};
|
|
163
|
-
class
|
|
163
|
+
class R {
|
|
164
164
|
constructor(t) {
|
|
165
|
-
t || (t =
|
|
165
|
+
t || (t = Y), this.marks = t.marks || [], this.nodes = t.nodes || [];
|
|
166
166
|
}
|
|
167
167
|
addNode(t, e) {
|
|
168
168
|
this.nodes[t] = e;
|
|
@@ -188,7 +188,7 @@ class J {
|
|
|
188
188
|
const r = this.getMatchingNode(t);
|
|
189
189
|
return r && r.tag && e.push(this.renderOpeningTag(r.tag)), t.content ? t.content.forEach((s) => {
|
|
190
190
|
e.push(this.renderNode(s));
|
|
191
|
-
}) : t.text ? e.push(
|
|
191
|
+
}) : t.text ? e.push(F(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) => {
|
|
192
192
|
const o = this.getMatchingMark(s);
|
|
193
193
|
o && e.push(this.renderClosingTag(o.tag));
|
|
194
194
|
}), e.join("");
|
|
@@ -200,9 +200,9 @@ class J {
|
|
|
200
200
|
{
|
|
201
201
|
let o = `<${s.tag}`;
|
|
202
202
|
if (s.attrs)
|
|
203
|
-
for (let
|
|
204
|
-
let
|
|
205
|
-
|
|
203
|
+
for (let a in s.attrs) {
|
|
204
|
+
let i = s.attrs[a];
|
|
205
|
+
i !== null && (o += ` ${a}="${i}"`);
|
|
206
206
|
}
|
|
207
207
|
return `${o}${e}>`;
|
|
208
208
|
}
|
|
@@ -228,40 +228,40 @@ class J {
|
|
|
228
228
|
* Universal JavaScript SDK for Storyblok's API
|
|
229
229
|
* (c) 2020-2022 Stobylok Team
|
|
230
230
|
*/
|
|
231
|
-
function
|
|
231
|
+
function w(n) {
|
|
232
232
|
return typeof n == "number" && n == n && n !== 1 / 0 && n !== -1 / 0;
|
|
233
233
|
}
|
|
234
|
-
function
|
|
235
|
-
if (!
|
|
234
|
+
function $(n, t, e) {
|
|
235
|
+
if (!w(t))
|
|
236
236
|
throw new TypeError("Expected `limit` to be a finite number");
|
|
237
|
-
if (!
|
|
237
|
+
if (!w(e))
|
|
238
238
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
239
|
-
var r = [], s = [], o = 0,
|
|
239
|
+
var r = [], s = [], o = 0, a = function() {
|
|
240
240
|
o++;
|
|
241
241
|
var c = setTimeout(function() {
|
|
242
|
-
o--, r.length > 0 &&
|
|
242
|
+
o--, r.length > 0 && a(), s = s.filter(function(u) {
|
|
243
243
|
return u !== c;
|
|
244
244
|
});
|
|
245
245
|
}, e);
|
|
246
246
|
s.indexOf(c) < 0 && s.push(c);
|
|
247
247
|
var l = r.shift();
|
|
248
248
|
l.resolve(n.apply(l.self, l.args));
|
|
249
|
-
},
|
|
249
|
+
}, i = function() {
|
|
250
250
|
var c = arguments, l = this;
|
|
251
251
|
return new Promise(function(u, p) {
|
|
252
|
-
r.push({ resolve: u, reject: p, args: c, self: l }), o < t &&
|
|
252
|
+
r.push({ resolve: u, reject: p, args: c, self: l }), o < t && a();
|
|
253
253
|
});
|
|
254
254
|
};
|
|
255
|
-
return
|
|
255
|
+
return i.abort = function() {
|
|
256
256
|
s.forEach(clearTimeout), s = [], r.forEach(function(c) {
|
|
257
257
|
c.reject(new throttle.AbortError());
|
|
258
258
|
}), r.length = 0;
|
|
259
|
-
},
|
|
259
|
+
}, i;
|
|
260
260
|
}
|
|
261
|
-
|
|
261
|
+
$.AbortError = function() {
|
|
262
262
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
263
263
|
};
|
|
264
|
-
const
|
|
264
|
+
const K = function(n, t) {
|
|
265
265
|
if (!n)
|
|
266
266
|
return null;
|
|
267
267
|
let e = {};
|
|
@@ -271,13 +271,13 @@ const Y = function(n, t) {
|
|
|
271
271
|
}
|
|
272
272
|
return e;
|
|
273
273
|
};
|
|
274
|
-
var
|
|
274
|
+
var G = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (n) => ({ tag: ["pre", { tag: "code", attrs: n.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (n) => ({ tag: `h${n.attrs.level}` }), image: (n) => ({ singleTag: [{ tag: "img", attrs: K(n.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(n) {
|
|
275
275
|
const t = h({}, n.attrs), { linktype: e = "url" } = n.attrs;
|
|
276
276
|
return e === "email" && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), { tag: [{ tag: "a", attrs: t }] };
|
|
277
277
|
}, styled: (n) => ({ tag: [{ tag: "span", attrs: n.attrs }] }) } };
|
|
278
|
-
class
|
|
278
|
+
class Q {
|
|
279
279
|
constructor(t) {
|
|
280
|
-
t || (t =
|
|
280
|
+
t || (t = G), this.marks = t.marks || [], this.nodes = t.nodes || [];
|
|
281
281
|
}
|
|
282
282
|
addNode(t, e) {
|
|
283
283
|
this.nodes[t] = e;
|
|
@@ -304,8 +304,8 @@ class G {
|
|
|
304
304
|
return r && r.tag && e.push(this.renderOpeningTag(r.tag)), t.content ? t.content.forEach((s) => {
|
|
305
305
|
e.push(this.renderNode(s));
|
|
306
306
|
}) : t.text ? e.push(function(s) {
|
|
307
|
-
const o = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" },
|
|
308
|
-
return s &&
|
|
307
|
+
const o = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }, a = /[&<>"']/g, i = RegExp(a.source);
|
|
308
|
+
return s && i.test(s) ? s.replace(a, (c) => o[c]) : s;
|
|
309
309
|
}(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) => {
|
|
310
310
|
const o = this.getMatchingMark(s);
|
|
311
311
|
o && e.push(this.renderClosingTag(o.tag));
|
|
@@ -319,8 +319,8 @@ class G {
|
|
|
319
319
|
let s = `<${r.tag}`;
|
|
320
320
|
if (r.attrs)
|
|
321
321
|
for (let o in r.attrs) {
|
|
322
|
-
let
|
|
323
|
-
|
|
322
|
+
let a = r.attrs[o];
|
|
323
|
+
a !== null && (s += ` ${o}="${a}"`);
|
|
324
324
|
}
|
|
325
325
|
return `${s}${e}>`;
|
|
326
326
|
}
|
|
@@ -341,29 +341,29 @@ class G {
|
|
|
341
341
|
return this.marks[t.type](t);
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
|
-
const
|
|
344
|
+
const W = (n = 0, t = n) => {
|
|
345
345
|
const e = Math.abs(t - n) || 0, r = n < t ? 1 : -1;
|
|
346
346
|
return ((s = 0, o) => [...Array(s)].map(o))(e, (s, o) => o * r + n);
|
|
347
|
-
},
|
|
347
|
+
}, k = (n, t, e) => {
|
|
348
348
|
const r = [];
|
|
349
349
|
for (const s in n) {
|
|
350
350
|
if (!Object.prototype.hasOwnProperty.call(n, s))
|
|
351
351
|
continue;
|
|
352
|
-
const o = n[s],
|
|
353
|
-
let
|
|
354
|
-
|
|
352
|
+
const o = n[s], a = e ? "" : encodeURIComponent(s);
|
|
353
|
+
let i;
|
|
354
|
+
i = typeof o == "object" ? k(o, t ? t + encodeURIComponent("[" + a + "]") : a, Array.isArray(o)) : (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(o), r.push(i);
|
|
355
355
|
}
|
|
356
356
|
return r.join("&");
|
|
357
357
|
};
|
|
358
358
|
let f = {}, d = {};
|
|
359
|
-
class
|
|
359
|
+
class X {
|
|
360
360
|
constructor(t, e) {
|
|
361
361
|
if (!e) {
|
|
362
|
-
let o = t.region ? `-${t.region}` : "",
|
|
363
|
-
e = t.oauthToken === void 0 ? `${
|
|
362
|
+
let o = t.region ? `-${t.region}` : "", a = t.https === !1 ? "http" : "https";
|
|
363
|
+
e = t.oauthToken === void 0 ? `${a}://api${o}.storyblok.com/v2` : `${a}://api${o}.storyblok.com/v1`;
|
|
364
364
|
}
|
|
365
365
|
let r = Object.assign({}, t.headers), s = 5;
|
|
366
|
-
t.oauthToken !== void 0 && (r.Authorization = t.oauthToken, s = 3), t.rateLimit !== void 0 && (s = t.rateLimit), this.richTextResolver = new
|
|
366
|
+
t.oauthToken !== void 0 && (r.Authorization = t.oauthToken, s = 3), t.rateLimit !== void 0 && (s = t.rateLimit), this.richTextResolver = new Q(t.richTextSchema), typeof t.componentResolver == "function" && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries || 5, this.throttle = $(this.throttledRequest, s, 1e3), this.accessToken = t.accessToken, this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.client = q.create({ baseURL: e, timeout: t.timeout || 0, headers: r, proxy: t.proxy || !1 }), t.responseInterceptor && this.client.interceptors.response.use((o) => t.responseInterceptor(o)), this.resolveNestedRelations = t.resolveNestedRelations || !0;
|
|
367
367
|
}
|
|
368
368
|
setComponentResolver(t) {
|
|
369
369
|
this.richTextResolver.addNode("blok", (e) => {
|
|
@@ -380,7 +380,7 @@ class Q {
|
|
|
380
380
|
return ((r = "") => r.indexOf("/cdn/") > -1)(t) ? this.parseParams(e) : e;
|
|
381
381
|
}
|
|
382
382
|
makeRequest(t, e, r, s) {
|
|
383
|
-
const o = this.factoryParamOptions(t, ((
|
|
383
|
+
const o = this.factoryParamOptions(t, ((a = {}, i = 25, c = 1) => y(h({}, a), { per_page: i, page: c }))(e, r, s));
|
|
384
384
|
return this.cacheResponse(t, o);
|
|
385
385
|
}
|
|
386
386
|
get(t, e) {
|
|
@@ -389,10 +389,10 @@ class Q {
|
|
|
389
389
|
return this.cacheResponse(r, s);
|
|
390
390
|
}
|
|
391
391
|
async getAll(t, e = {}, r) {
|
|
392
|
-
const s = e.per_page || 25, o = `/${t}`,
|
|
393
|
-
r = r ||
|
|
394
|
-
const
|
|
395
|
-
return ((l = [], u) => l.map(u).reduce((p,
|
|
392
|
+
const s = e.per_page || 25, o = `/${t}`, a = o.split("/");
|
|
393
|
+
r = r || a[a.length - 1];
|
|
394
|
+
const i = await this.makeRequest(o, e, s, 1), c = Math.ceil(i.total / s);
|
|
395
|
+
return ((l = [], u) => l.map(u).reduce((p, S) => [...p, ...S], []))([i, ...await (async (l = [], u) => Promise.all(l.map(u)))(W(1, c), async (l) => this.makeRequest(o, e, s, l + 1))], (l) => Object.values(l.data[r]));
|
|
396
396
|
}
|
|
397
397
|
post(t, e) {
|
|
398
398
|
let r = `/${t}`;
|
|
@@ -463,13 +463,13 @@ class Q {
|
|
|
463
463
|
if (t.link_uuids) {
|
|
464
464
|
const s = t.link_uuids.length;
|
|
465
465
|
let o = [];
|
|
466
|
-
const
|
|
467
|
-
for (let
|
|
468
|
-
const c = Math.min(s,
|
|
469
|
-
o.push(t.link_uuids.slice(
|
|
466
|
+
const a = 50;
|
|
467
|
+
for (let i = 0; i < s; i += a) {
|
|
468
|
+
const c = Math.min(s, i + a);
|
|
469
|
+
o.push(t.link_uuids.slice(i, c));
|
|
470
470
|
}
|
|
471
|
-
for (let
|
|
472
|
-
(await this.getStories({ per_page:
|
|
471
|
+
for (let i = 0; i < o.length; i++)
|
|
472
|
+
(await this.getStories({ per_page: a, language: e.language, version: e.version, by_uuids: o[i].join(",") })).data.stories.forEach((c) => {
|
|
473
473
|
r.push(c);
|
|
474
474
|
});
|
|
475
475
|
} else
|
|
@@ -483,13 +483,13 @@ class Q {
|
|
|
483
483
|
if (t.rel_uuids) {
|
|
484
484
|
const s = t.rel_uuids.length;
|
|
485
485
|
let o = [];
|
|
486
|
-
const
|
|
487
|
-
for (let
|
|
488
|
-
const c = Math.min(s,
|
|
489
|
-
o.push(t.rel_uuids.slice(
|
|
486
|
+
const a = 50;
|
|
487
|
+
for (let i = 0; i < s; i += a) {
|
|
488
|
+
const c = Math.min(s, i + a);
|
|
489
|
+
o.push(t.rel_uuids.slice(i, c));
|
|
490
490
|
}
|
|
491
|
-
for (let
|
|
492
|
-
(await this.getStories({ per_page:
|
|
491
|
+
for (let i = 0; i < o.length; i++)
|
|
492
|
+
(await this.getStories({ per_page: a, language: e.language, version: e.version, by_uuids: o[i].join(",") })).data.stories.forEach((c) => {
|
|
493
493
|
r.push(c);
|
|
494
494
|
});
|
|
495
495
|
} else
|
|
@@ -520,17 +520,17 @@ class Q {
|
|
|
520
520
|
}
|
|
521
521
|
cacheResponse(t, e, r) {
|
|
522
522
|
return r === void 0 && (r = 0), new Promise(async (s, o) => {
|
|
523
|
-
let
|
|
523
|
+
let a = k({ url: t, params: e }), i = this.cacheProvider();
|
|
524
524
|
if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
|
|
525
|
-
const l = await
|
|
525
|
+
const l = await i.get(a);
|
|
526
526
|
if (l)
|
|
527
527
|
return s(l);
|
|
528
528
|
}
|
|
529
529
|
try {
|
|
530
|
-
let l = await this.throttle("get", t, { params: e, paramsSerializer: (p) =>
|
|
530
|
+
let l = await this.throttle("get", t, { params: e, paramsSerializer: (p) => k(p) }), u = { data: l.data, headers: l.headers };
|
|
531
531
|
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)
|
|
532
532
|
return o(l);
|
|
533
|
-
(u.data.story || u.data.stories) && await this.resolveStories(u.data, e), e.version === "published" && t != "/cdn/spaces/me" &&
|
|
533
|
+
(u.data.story || u.data.stories) && await this.resolveStories(u.data, e), e.version === "published" && t != "/cdn/spaces/me" && i.set(a, u), u.data.cv && (e.version == "draft" && d[e.token] != u.data.cv && this.flushCache(), d[e.token] = u.data.cv), s(u);
|
|
534
534
|
} catch (l) {
|
|
535
535
|
if (l.response && l.response.status === 429 && (r += 1) < this.maxRetries)
|
|
536
536
|
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(o);
|
|
@@ -566,15 +566,15 @@ class Q {
|
|
|
566
566
|
return await this.cacheProvider().flush(), this;
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
|
-
const
|
|
569
|
+
const at = (n = {}) => {
|
|
570
570
|
const { apiOptions: t } = n;
|
|
571
571
|
if (!t.accessToken) {
|
|
572
572
|
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");
|
|
573
573
|
return;
|
|
574
574
|
}
|
|
575
|
-
return { storyblokApi: new
|
|
575
|
+
return { storyblokApi: new X(t) };
|
|
576
576
|
};
|
|
577
|
-
var
|
|
577
|
+
var Z = (n) => {
|
|
578
578
|
if (typeof n != "object" || typeof n._editable > "u")
|
|
579
579
|
return {};
|
|
580
580
|
const t = JSON.parse(n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
|
|
@@ -583,7 +583,8 @@ var W = (n) => {
|
|
|
583
583
|
"data-blok-uid": t.id + "-" + t.uid
|
|
584
584
|
};
|
|
585
585
|
};
|
|
586
|
-
|
|
586
|
+
let m;
|
|
587
|
+
const tt = "https://app.storyblok.com/f/storyblok-v2-latest.js", et = (n, t, e = {}) => {
|
|
587
588
|
if (!(typeof window > "u")) {
|
|
588
589
|
if (typeof window.storyblokRegisterEvent > "u") {
|
|
589
590
|
console.error("Storyblok Bridge is disabled. Please enable it to use it. Read https://github.com/storyblok/storyblok-js");
|
|
@@ -599,40 +600,66 @@ const X = new J(), Z = "https://app.storyblok.com/f/storyblok-v2-latest.js", tt
|
|
|
599
600
|
});
|
|
600
601
|
});
|
|
601
602
|
}
|
|
602
|
-
},
|
|
603
|
-
const {
|
|
603
|
+
}, rt = (n = {}) => {
|
|
604
|
+
const {
|
|
605
|
+
bridge: t,
|
|
606
|
+
accessToken: e,
|
|
607
|
+
use: r = [],
|
|
608
|
+
apiOptions: s = {},
|
|
609
|
+
richText: o = {}
|
|
610
|
+
} = n;
|
|
604
611
|
s.accessToken = s.accessToken || e;
|
|
605
|
-
const
|
|
612
|
+
const a = { bridge: t, apiOptions: s };
|
|
606
613
|
let i = {};
|
|
607
|
-
return r.forEach((
|
|
608
|
-
i = h(h({}, i), a
|
|
609
|
-
}), t !== !1 &&
|
|
610
|
-
},
|
|
614
|
+
return r.forEach((c) => {
|
|
615
|
+
i = h(h({}, i), c(a));
|
|
616
|
+
}), t !== !1 && V(tt), m = new R(o.schema), o.resolver && E(m, o.resolver), i;
|
|
617
|
+
}, E = (n, t) => {
|
|
618
|
+
n.addNode("blok", (e) => {
|
|
619
|
+
let r = "";
|
|
620
|
+
return e.attrs.body.forEach((s) => {
|
|
621
|
+
r += t(s.component, s);
|
|
622
|
+
}), {
|
|
623
|
+
html: r
|
|
624
|
+
};
|
|
625
|
+
});
|
|
626
|
+
}, lt = (n, t) => {
|
|
627
|
+
if (!m) {
|
|
628
|
+
console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
if (n === "")
|
|
632
|
+
return "";
|
|
633
|
+
if (!n)
|
|
634
|
+
return console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
611
635
|
|
|
612
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), ""
|
|
636
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "";
|
|
637
|
+
let e = m;
|
|
638
|
+
return t && (e = new R(t.schema), t.resolver && E(e, t.resolver)), e.render(n);
|
|
639
|
+
}, st = /* @__PURE__ */ P({
|
|
613
640
|
__name: "StoryblokComponent",
|
|
614
641
|
props: {
|
|
615
642
|
blok: null
|
|
616
643
|
},
|
|
617
644
|
setup(n) {
|
|
618
|
-
return (t, e) => (
|
|
645
|
+
return (t, e) => (j(), x(A(n.blok.component), C(M({ ...t.$props, ...t.$attrs })), null, 16));
|
|
619
646
|
}
|
|
620
|
-
}),
|
|
647
|
+
}), nt = {
|
|
621
648
|
beforeMount(n, t) {
|
|
622
649
|
if (t.value) {
|
|
623
|
-
const e =
|
|
650
|
+
const e = Z(t.value);
|
|
624
651
|
n.setAttribute("data-blok-c", e["data-blok-c"]), n.setAttribute("data-blok-uid", e["data-blok-uid"]), n.classList.add("storyblok__outline");
|
|
625
652
|
}
|
|
626
653
|
}
|
|
627
|
-
},
|
|
654
|
+
}, O = (n) => {
|
|
628
655
|
console.error(`You can't use ${n} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
629
656
|
`);
|
|
630
657
|
};
|
|
631
658
|
let g = null;
|
|
632
|
-
const
|
|
633
|
-
const r =
|
|
634
|
-
if (
|
|
635
|
-
r.value && r.value.id &&
|
|
659
|
+
const ct = () => (g || O("useStoryblokApi"), g), ut = async (n, t = {}, e = {}) => {
|
|
660
|
+
const r = N(null);
|
|
661
|
+
if (I(() => {
|
|
662
|
+
r.value && r.value.id && et(
|
|
636
663
|
r.value.id,
|
|
637
664
|
(s) => r.value = s,
|
|
638
665
|
e
|
|
@@ -644,21 +671,21 @@ const lt = () => (g || R("useStoryblokApi"), g), ct = async (n, t = {}, e = {})
|
|
|
644
671
|
);
|
|
645
672
|
r.value = s.story;
|
|
646
673
|
} else
|
|
647
|
-
|
|
674
|
+
O("useStoryblok");
|
|
648
675
|
return r;
|
|
649
|
-
},
|
|
676
|
+
}, ht = {
|
|
650
677
|
install(n, t = {}) {
|
|
651
|
-
n.directive("editable",
|
|
652
|
-
const { storyblokApi: e } =
|
|
678
|
+
n.directive("editable", nt), n.component("StoryblokComponent", st);
|
|
679
|
+
const { storyblokApi: e } = rt(t);
|
|
653
680
|
g = e;
|
|
654
681
|
}
|
|
655
682
|
};
|
|
656
683
|
export {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
684
|
+
st as StoryblokComponent,
|
|
685
|
+
ht as StoryblokVue,
|
|
686
|
+
at as apiPlugin,
|
|
687
|
+
lt as renderRichText,
|
|
688
|
+
ut as useStoryblok,
|
|
689
|
+
ct as useStoryblokApi,
|
|
690
|
+
et as useStoryblokBridge
|
|
664
691
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.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",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@storyblok/js": "^1.
|
|
27
|
+
"@storyblok/js": "^1.8.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@babel/core": "^7.18.10",
|
|
31
31
|
"@cypress/vite-dev-server": "^2.0.7",
|
|
32
32
|
"@cypress/vue": "^3.1.2",
|
|
33
33
|
"@vitejs/plugin-vue": "^2.3.3",
|
|
34
|
-
"@vue/babel-preset-app": "^5.0.
|
|
34
|
+
"@vue/babel-preset-app": "^5.0.8",
|
|
35
35
|
"@vue/test-utils": "next",
|
|
36
36
|
"@vue/tsconfig": "^0.1.3",
|
|
37
37
|
"babel-jest": "^26.0.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"eslint-plugin-cypress": "^2.12.1",
|
|
40
40
|
"eslint-plugin-jest": "^26.8.2",
|
|
41
41
|
"jest": "^28.1.3",
|
|
42
|
-
"typescript": "^4.7.
|
|
42
|
+
"typescript": "^4.7.4",
|
|
43
43
|
"vite": "^3.0.5",
|
|
44
44
|
"vue": "^3.2.33",
|
|
45
45
|
"vue-jest": "next",
|