@storyblok/vue 7.1.0 → 7.1.1
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 +2 -2
- package/dist/storyblok-vue.mjs +88 -84
- package/package.json +5 -5
package/dist/storyblok-vue.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(d,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],p):(d=typeof globalThis<"u"?globalThis:d||self,p(d.storyblokVue={},d.Vue))})(this,function(d,p){"use strict";let w=!1;const T=[],C=o=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}w?r():T.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=o,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{T.forEach(n=>n()),w=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var O=Object.defineProperty,x=(o,e,t)=>e in o?O(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e,t)=>(x(o,typeof e!="symbol"?e+"":e,t),t);function _(o){return!(o!==o||o===1/0||o===-1/0)}function A(o,e,t){if(!_(e))throw new TypeError("Expected `limit` to be a finite number");if(!_(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],n=0;const i=function(){n++;const l=setTimeout(function(){n--,s.length>0&&i(),r=r.filter(function(u){return u!==l})},t);r.indexOf(l)<0&&r.push(l);const c=s.shift();c.resolve(o.apply(c.self,c.args))},a=function(...l){const c=this;return new Promise(function(u,y){s.push({resolve:u,reject:y,args:l,self:c}),n<e&&i()})};return a.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(l){l.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},a}const I=function(o,e){const t={};for(const s in o){const r=o[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},M=o=>o==="email",N=()=>({singleTag:"hr"}),L=()=>({tag:"blockquote"}),U=()=>({tag:"ul"}),H=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),q=()=>({singleTag:"br"}),V=o=>({tag:`h${o.attrs.level}`}),D=o=>({singleTag:[{tag:"img",attrs:I(o.attrs,["src","alt","title"])}]}),B=()=>({tag:"li"}),z=()=>({tag:"ol"}),J=()=>({tag:"p"}),F=()=>({tag:"b"}),Y=()=>({tag:"strike"}),K=()=>({tag:"u"}),G=()=>({tag:"strong"}),Q=()=>({tag:"code"}),W=()=>({tag:"i"}),X=o=>{const e={...o.attrs},{linktype:t="url"}=o.attrs;return M(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},Z=o=>({tag:[{tag:"span",attrs:o.attrs}]}),R={nodes:{horizontal_rule:N,blockquote:L,bullet_list:U,code_block:H,hard_break:q,heading:V,image:D,list_item:B,ordered_list:z,paragraph:J},marks:{bold:F,strike:Y,underline:K,strong:G,code:Q,italic:W,link:X,styled:Z}},ee=function(o){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class f{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=R),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&&e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(s=>{t+=this.renderNode(s)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const n=this.getMatchingMark(r);n&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ee(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const n=this.getMatchingMark(r);n&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const n in s.attrs){const i=s.attrs[n];i!==null&&(r+=` ${n}="${i}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}}class ${constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(n,i)=>i*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]))}stringify(e,t,s){const r=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const i=e[n],a=s?"":encodeURIComponent(n);let l;typeof i=="object"?l=this.stringify(i,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(i)):l=(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(i),r.push(l)}return r.join("&")}}class te{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||[],this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const l=new $;t=`${this.baseURL}${this.url}?${l.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:i}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const l=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:i});this.timeout&&clearTimeout(a);const c=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(l){return{message:l}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const n={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};r(n)})}}let k={};const g={};class se{constructor(e,t){if(h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),!t){const n=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${n}.storyblok.com/v1`:t=`${i}://api${n}.storyblok.com/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach((n,i)=>{e.headers&&e.headers[i]&&s.set(i,e.headers[i])});let r=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new f(e.richTextSchema):this.richTextResolver=new f,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=A(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new $,this.resolveNestedRelations=!1,this.client=new te({baseURL:t,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=g[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const n=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,n)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,n=`/${e}`,i=n.split("/"),a=s||i[i.length-1],l=1,c=await this.makeRequest(n,t,r,l),u=c.total?Math.ceil(c.total/r):1,y=await this.helpers.asyncMap(this.helpers.range(l,u),v=>this.makeRequest(n,t,r,v+1));return this.helpers.flatMap([c,...y],v=>Object.values(v.data[a]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const s=e[t];s&&s.fieldtype=="multilink"&&s.linktype=="story"&&typeof s.id=="string"&&this.links[s.id]?s.story=this._cleanCopy(this.links[s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[s.uuid]&&(s.story=this._cleanCopy(this.links[s.uuid]))}_insertRelations(e,t,s){if(s.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]&&e[t].constructor===Array){const r=[];e[t].forEach(n=>{this.relations[n]&&r.push(this._cleanCopy(this.relations[n]))}),e[t]=r}}}iterateTree(e,t){const s=r=>{if(r!=null){if(r.constructor===Array)for(let n=0;n<r.length;n++)s(r[n]);else if(r.constructor===Object){if(r._stopResolving)return;for(const n in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,n,t),this._insertLinks(r,n)),s(r[n])}}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const l=Math.min(r,a+i);n.push(e.link_uuids.slice(a,l))}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(l=>{s.push(l)})}else s=e.links;s.forEach(r=>{this.links[r.uuid]={...r,_stopResolving:!0}})}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length,n=[],i=50;for(let a=0;a<r;a+=i){const l=Math.min(r,a+i);n.push(e.rel_uuids.slice(a,l))}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(l=>{s.push(l)})}else s=e.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]={...r,_stopResolving:!0}})}async resolveStories(e,t){var s,r;let n=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(n=t.resolve_relations.split(",")),await this.resolveRelations(e,t)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((s=e.links)!=null&&s.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const i in this.relations)this.iterateTree(this.relations[i],n);e.story?this.iterateTree(e.story,n):e.stories.forEach(i=>{this.iterateTree(i,n)})}async cacheResponse(e,t,s){const r=this.helpers.stringify({url:e,params:t}),n=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await n.get(r);if(i)return Promise.resolve(i)}return new Promise((i,a)=>{try{(async()=>{var l;try{const c=await this.throttle("get",e,t);let u={data:c.data,headers:c.headers};return(l=c.headers)!=null&&l["per-page"]&&(u=Object.assign({},u,{perPage:c.headers["per-page"]?parseInt(c.headers["per-page"]):0,total:c.headers["per-page"]?parseInt(c.headers.total):0})),c.status!=200?a(c):((u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await n.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&g[t.token]!=u.data.cv&&await this.flushCache(),g[t.token]=u.data.cv),i(u))}catch(c){return a(c)}})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}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){return Promise.resolve(k[e])},getAll(){return Promise.resolve(k)},set(e,t){return k[e]=t,Promise.resolve(void 0)},flush(){return k={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const re=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new se(e)}},oe=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let b;const ne="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(o,e,t={})=>{if(!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u"){if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],s=>{s.action==="input"&&s.story.id===o?e(s.story):(s.action==="change"||s.action==="published")&&s.storyId===o&&window.location.reload()})})}},ie=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:n=[],apiOptions:i={},richText:a={}}=o;i.accessToken=i.accessToken||r;const l={bridge:s,apiOptions:i};let c={};n.forEach(y=>{c={...c,...y(l)}});const u=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&u&&C(ne),b=new f(a.schema),a.resolver&&S(b,a.resolver),c},S=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ae=(o,e,t)=>{let s=t||b;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return o===""?"":o?(e&&(s=new f(e.schema),e.resolver&&S(s,e.resolver)),s.render(o)):(console.warn(`${o} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
1
|
+
(function(d,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],p):(d=typeof globalThis<"u"?globalThis:d||self,p(d.storyblokVue={},d.Vue))})(this,function(d,p){"use strict";let w=!1;const T=[],C=o=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}w?r():T.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const s=document.createElement("script");s.async=!0,s.src=o,s.id="storyblok-javascript-bridge",s.onerror=r=>t(r),s.onload=r=>{T.forEach(i=>i()),w=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(s)});var O=Object.defineProperty,x=(o,e,t)=>e in o?O(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,h=(o,e,t)=>(x(o,typeof e!="symbol"?e+"":e,t),t);function _(o){return!(o!==o||o===1/0||o===-1/0)}function A(o,e,t){if(!_(e))throw new TypeError("Expected `limit` to be a finite number");if(!_(t))throw new TypeError("Expected `interval` to be a finite number");const s=[];let r=[],i=0;const n=function(){i++;const l=setTimeout(function(){i--,s.length>0&&n(),r=r.filter(function(u){return u!==l})},t);r.indexOf(l)<0&&r.push(l);const c=s.shift();c.resolve(o.apply(c.self,c.args))},a=function(...l){const c=this;return new Promise(function(u,y){s.push({resolve:u,reject:y,args:l,self:c}),i<e&&n()})};return a.abort=function(){r.forEach(clearTimeout),r=[],s.forEach(function(l){l.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),s.length=0},a}const I=function(o,e){const t={};for(const s in o){const r=o[s];e.indexOf(s)>-1&&r!==null&&(t[s]=r)}return t},M=o=>o==="email",N=()=>({singleTag:"hr"}),L=()=>({tag:"blockquote"}),U=()=>({tag:"ul"}),H=o=>({tag:["pre",{tag:"code",attrs:o.attrs}]}),q=()=>({singleTag:"br"}),V=o=>({tag:`h${o.attrs.level}`}),D=o=>({singleTag:[{tag:"img",attrs:I(o.attrs,["src","alt","title"])}]}),B=()=>({tag:"li"}),z=()=>({tag:"ol"}),J=()=>({tag:"p"}),F=()=>({tag:"b"}),Y=()=>({tag:"strike"}),K=()=>({tag:"u"}),G=()=>({tag:"strong"}),Q=()=>({tag:"code"}),W=()=>({tag:"i"}),X=o=>{const e={...o.attrs},{linktype:t="url"}=o.attrs;return M(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},Z=o=>({tag:[{tag:"span",attrs:o.attrs}]}),R={nodes:{horizontal_rule:N,blockquote:L,bullet_list:U,code_block:H,hard_break:q,heading:V,image:D,list_item:B,ordered_list:z,paragraph:J},marks:{bold:F,strike:Y,underline:K,strong:G,code:Q,italic:W,link:X,styled:Z}},ee=function(o){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,s=RegExp(t.source);return o&&s.test(o)?o.replace(t,r=>e[r]):o};class f{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=R),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&&e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(s=>{t+=this.renderNode(s)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const i=this.getMatchingMark(r);i&&t.push(this.renderOpeningTag(i.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ee(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html&&t.push(s.html),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const i=this.getMatchingMark(r);i&&t.push(this.renderClosingTag(i.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const i in s.attrs){const n=s.attrs[i];n!==null&&(r+=` ${i}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}}class ${constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,s=1)=>({...e,per_page:t,page:s})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const s=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(s,(i,n)=>n*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((s,r)=>[...s,...r],[]))}stringify(e,t,s){const r=[];for(const i in e){if(!Object.prototype.hasOwnProperty.call(e,i))continue;const n=e[i],a=s?"":encodeURIComponent(i);let l;typeof n=="object"?l=this.stringify(n,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(n)):l=(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(n),r.push(l)}return r.join("&")}}class te{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||[],this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const l=new $;t=`${this.baseURL}${this.url}?${l.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let a;this.timeout&&(a=setTimeout(()=>i.abort(),this.timeout));try{const l=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n});this.timeout&&clearTimeout(a);const c=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(l){return{message:l}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};r(i)})}}let k={};const g={};class se{constructor(e,t){if(h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),!t){const i=e.region?`-${e.region}`:"",n=e.https===!1?"http":"https";e.oauthToken?t=`${n}://api${i}.storyblok.com/v1`:t=`${n}://api${i}.storyblok.com/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),s.forEach((i,n)=>{e.headers&&e.headers[n]&&s.set(n,e.headers[n])});let r=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new f(e.richTextSchema):this.richTextResolver=new f,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=A(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new $,this.resolveNestedRelations=!1,this.client=new te({baseURL:t,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=g[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,i)}get(e,t){t||(t={});const s=`/${e}`,r=this.factoryParamOptions(s,t);return this.cacheResponse(s,r)}async getAll(e,t,s){const r=(t==null?void 0:t.per_page)||25,i=`/${e}`,n=i.split("/"),a=s||n[n.length-1],l=1,c=await this.makeRequest(i,t,r,l),u=c.total?Math.ceil(c.total/r):1,y=await this.helpers.asyncMap(this.helpers.range(l,u),v=>this.makeRequest(i,t,r,v+1));return this.helpers.flatMap([c,...y],v=>Object.values(v.data[a]))}post(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("post",s,t))}put(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("put",s,t))}delete(e,t){const s=`/${e}`;return Promise.resolve(this.throttle("delete",s,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const s=e[t];s&&s.fieldtype=="multilink"&&s.linktype=="story"&&typeof s.id=="string"&&this.links[s.id]?s.story=this._cleanCopy(this.links[s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[s.uuid]&&(s.story=this._cleanCopy(this.links[s.uuid]))}_insertRelations(e,t,s){if(s.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]&&e[t].constructor===Array){const r=[];e[t].forEach(i=>{this.relations[i]&&r.push(this._cleanCopy(this.relations[i]))}),e[t]=r}}}iterateTree(e,t){const s=r=>{if(r!=null){if(r.constructor===Array)for(let i=0;i<r.length;i++)s(r[i]);else if(r.constructor===Object){if(r._stopResolving)return;for(const i in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,i,t),this._insertLinks(r,i)),s(r[i])}}};s(e.content)}async resolveLinks(e,t){let s=[];if(e.link_uuids){const r=e.link_uuids.length,i=[],n=50;for(let a=0;a<r;a+=n){const l=Math.min(r,a+n);i.push(e.link_uuids.slice(a,l))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(l=>{s.push(l)})}else s=e.links;s.forEach(r=>{this.links[r.uuid]={...r,_stopResolving:!0}})}async resolveRelations(e,t){let s=[];if(e.rel_uuids){const r=e.rel_uuids.length,i=[],n=50;for(let a=0;a<r;a+=n){const l=Math.min(r,a+n);i.push(e.rel_uuids.slice(a,l))}for(let a=0;a<i.length;a++)(await this.getStories({per_page:n,language:t.language,version:t.version,by_uuids:i[a].join(",")})).data.stories.forEach(l=>{s.push(l)})}else s=e.rels;s&&s.length>0&&s.forEach(r=>{this.relations[r.uuid]={...r,_stopResolving:!0}})}async resolveStories(e,t){var s,r;let i=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=t.resolve_relations.split(",")),await this.resolveRelations(e,t)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((s=e.links)!=null&&s.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const n in this.relations)this.iterateTree(this.relations[n],i);e.story?this.iterateTree(e.story,i):e.stories.forEach(n=>{this.iterateTree(n,i)})}async cacheResponse(e,t,s){const r=this.helpers.stringify({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 n=await i.get(r);if(n)return Promise.resolve(n)}return new Promise((n,a)=>{try{(async()=>{var l;try{const c=await this.throttle("get",e,t);let u={data:c.data,headers:c.headers};return(l=c.headers)!=null&&l["per-page"]&&(u=Object.assign({},u,{perPage:c.headers["per-page"]?parseInt(c.headers["per-page"]):0,total:c.headers["per-page"]?parseInt(c.headers.total):0})),c.status!=200?a(c):((u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await i.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&g[t.token]!=u.data.cv&&await this.flushCache(),g[t.token]=u.data.cv),n(u))}catch(c){return a(c)}})()}catch{}})}throttledRequest(e,t,s){return this.client[e](t,s)}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){return Promise.resolve(k[e])},getAll(){return Promise.resolve(k)},set(e,t){return k[e]=t,Promise.resolve(void 0)},flush(){return k={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const re=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new se(e)}},oe=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let b;const ie="https://app.storyblok.com/f/storyblok-v2-latest.js",P=(o,e,t={})=>{var s;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",i=+new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok")===o;if(!(!r||!i)){if(!o){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],n=>{n.action==="input"&&n.story.id===o?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===o&&window.location.reload()})})}},ne=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:i=[],apiOptions:n={},richText:a={}}=o;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let c={};i.forEach(y=>{c={...c,...y(l)}});const u=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&u&&C(ie),b=new f(a.schema),a.resolver&&S(b,a.resolver),c},S=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ae=(o,e,t)=>{let s=t||b;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return o===""?"":o?(e&&(s=new f(e.schema),e.resolver&&S(s,e.resolver)),s.render(o)):(console.warn(`${o} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
2
2
|
|
|
3
3
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},j=p.defineComponent({__name:"StoryblokComponent",props:{blok:null},setup(o){return(e,t)=>(p.openBlock(),p.createBlock(p.resolveDynamicComponent(o.blok.component),p.normalizeProps(p.guardReactiveProps({...e.$props,...e.$attrs})),null,16))}}),le={beforeMount(o,e){if(e.value){const t=oe(e.value);o.setAttribute("data-blok-c",t["data-blok-c"]),o.setAttribute("data-blok-uid",t["data-blok-uid"]),o.classList.add("storyblok__outline")}}},E=o=>{console.error(`You can't use ${o} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
4
|
-
`)};let m=null;const ce=()=>(m||E("useStoryblokApi"),m),he=async(o,e={},t={})=>{const s=p.ref(null);if(p.onMounted(()=>{s.value&&s.value.id&&P(s.value.id,r=>s.value=r,t)}),m){const{data:r}=await m.get(`cdn/stories/${o}`,e);s.value=r.story}else E("useStoryblok");return s},ue={install(o,e={}){o.directive("editable",le),o.component("StoryblokComponent",j);const{storyblokApi:t}=
|
|
4
|
+
`)};let m=null;const ce=()=>(m||E("useStoryblokApi"),m),he=async(o,e={},t={})=>{const s=p.ref(null);if(p.onMounted(()=>{s.value&&s.value.id&&P(s.value.id,r=>s.value=r,t)}),m){const{data:r}=await m.get(`cdn/stories/${o}`,e);s.value=r.story}else E("useStoryblok");return s},ue={install(o,e={}){o.directive("editable",le),o.component("StoryblokComponent",j);const{storyblokApi:t}=ne(e);m=t}};d.RichTextResolver=f,d.RichTextSchema=R,d.StoryblokComponent=j,d.StoryblokVue=ue,d.apiPlugin=re,d.renderRichText=ae,d.useStoryblok=he,d.useStoryblokApi=ce,d.useStoryblokBridge=P,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const b = [], A = (o) => new Promise((e, t) => {
|
|
|
11
11
|
return;
|
|
12
12
|
const s = document.createElement("script");
|
|
13
13
|
s.async = !0, s.src = o, s.id = "storyblok-javascript-bridge", s.onerror = (r) => t(r), s.onload = (r) => {
|
|
14
|
-
b.forEach((
|
|
14
|
+
b.forEach((i) => i()), v = !0, e(r);
|
|
15
15
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
16
16
|
});
|
|
17
17
|
var I = Object.defineProperty, M = (o, e, t) => e in o ? I(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t, h = (o, e, t) => (M(o, typeof e != "symbol" ? e + "" : e, t), t);
|
|
@@ -24,11 +24,11 @@ function N(o, e, t) {
|
|
|
24
24
|
if (!w(t))
|
|
25
25
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
26
26
|
const s = [];
|
|
27
|
-
let r = [],
|
|
28
|
-
const
|
|
29
|
-
|
|
27
|
+
let r = [], i = 0;
|
|
28
|
+
const n = function() {
|
|
29
|
+
i++;
|
|
30
30
|
const l = setTimeout(function() {
|
|
31
|
-
|
|
31
|
+
i--, s.length > 0 && n(), r = r.filter(function(u) {
|
|
32
32
|
return u !== l;
|
|
33
33
|
});
|
|
34
34
|
}, t);
|
|
@@ -43,7 +43,7 @@ function N(o, e, t) {
|
|
|
43
43
|
reject: p,
|
|
44
44
|
args: l,
|
|
45
45
|
self: c
|
|
46
|
-
}),
|
|
46
|
+
}), i < e && n();
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
49
|
return a.abort = function() {
|
|
@@ -178,15 +178,15 @@ class m {
|
|
|
178
178
|
renderNode(e) {
|
|
179
179
|
const t = [];
|
|
180
180
|
e.marks && e.marks.forEach((r) => {
|
|
181
|
-
const
|
|
182
|
-
|
|
181
|
+
const i = this.getMatchingMark(r);
|
|
182
|
+
i && t.push(this.renderOpeningTag(i.tag));
|
|
183
183
|
});
|
|
184
184
|
const s = this.getMatchingNode(e);
|
|
185
185
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
186
186
|
t.push(this.renderNode(r));
|
|
187
187
|
}) : e.text ? t.push(oe(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html && t.push(s.html), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
|
|
188
|
-
const
|
|
189
|
-
|
|
188
|
+
const i = this.getMatchingMark(r);
|
|
189
|
+
i && t.push(this.renderClosingTag(i.tag));
|
|
190
190
|
}), t.join("");
|
|
191
191
|
}
|
|
192
192
|
renderTag(e, t) {
|
|
@@ -196,9 +196,9 @@ class m {
|
|
|
196
196
|
{
|
|
197
197
|
let r = `<${s.tag}`;
|
|
198
198
|
if (s.attrs)
|
|
199
|
-
for (const
|
|
200
|
-
const
|
|
201
|
-
|
|
199
|
+
for (const i in s.attrs) {
|
|
200
|
+
const n = s.attrs[i];
|
|
201
|
+
n !== null && (r += ` ${i}="${n}"`);
|
|
202
202
|
}
|
|
203
203
|
return `${r}${t}>`;
|
|
204
204
|
}
|
|
@@ -221,7 +221,7 @@ class m {
|
|
|
221
221
|
return t(e);
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
-
class
|
|
224
|
+
class _ {
|
|
225
225
|
constructor() {
|
|
226
226
|
h(this, "isCDNUrl", (e = "") => e.indexOf("/cdn/") > -1), h(this, "getOptionsPage", (e, t = 25, s = 1) => ({
|
|
227
227
|
...e,
|
|
@@ -229,26 +229,26 @@ class T {
|
|
|
229
229
|
page: s
|
|
230
230
|
})), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
|
|
231
231
|
const s = Math.abs(t - e) || 0, r = e < t ? 1 : -1;
|
|
232
|
-
return this.arrayFrom(s, (
|
|
232
|
+
return this.arrayFrom(s, (i, n) => n * r + e);
|
|
233
233
|
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((s, r) => [...s, ...r], []));
|
|
234
234
|
}
|
|
235
235
|
stringify(e, t, s) {
|
|
236
236
|
const r = [];
|
|
237
|
-
for (const
|
|
238
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
|
237
|
+
for (const i in e) {
|
|
238
|
+
if (!Object.prototype.hasOwnProperty.call(e, i))
|
|
239
239
|
continue;
|
|
240
|
-
const
|
|
240
|
+
const n = e[i], a = s ? "" : encodeURIComponent(i);
|
|
241
241
|
let l;
|
|
242
|
-
typeof
|
|
243
|
-
|
|
242
|
+
typeof n == "object" ? l = this.stringify(
|
|
243
|
+
n,
|
|
244
244
|
t ? t + encodeURIComponent("[" + a + "]") : a,
|
|
245
|
-
Array.isArray(
|
|
246
|
-
) : l = (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(
|
|
245
|
+
Array.isArray(n)
|
|
246
|
+
) : l = (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(n), r.push(l);
|
|
247
247
|
}
|
|
248
248
|
return r.join("&");
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
class
|
|
251
|
+
class ie {
|
|
252
252
|
constructor(e) {
|
|
253
253
|
h(this, "baseURL"), h(this, "timeout"), h(this, "headers"), h(this, "responseInterceptor"), h(this, "fetch"), h(this, "ejectInterceptor"), h(this, "url"), h(this, "parameters"), this.baseURL = e.baseURL, this.headers = e.headers || [], this.timeout = e != null && e.timeout ? e.timeout * 1e3 : 0, this.responseInterceptor = e.responseInterceptor, this.fetch = (...t) => e.fetch ? e.fetch(...t) : fetch(...t), this.ejectInterceptor = !1, this.url = "", this.parameters = {};
|
|
254
254
|
}
|
|
@@ -281,21 +281,21 @@ class ne {
|
|
|
281
281
|
async _methodHandler(e) {
|
|
282
282
|
let t = `${this.baseURL}${this.url}`, s = null;
|
|
283
283
|
if (e === "get") {
|
|
284
|
-
const l = new
|
|
284
|
+
const l = new _();
|
|
285
285
|
t = `${this.baseURL}${this.url}?${l.stringify(
|
|
286
286
|
this.parameters
|
|
287
287
|
)}`;
|
|
288
288
|
} else
|
|
289
289
|
s = JSON.stringify(this.parameters);
|
|
290
|
-
const r = new URL(t),
|
|
290
|
+
const r = new URL(t), i = new AbortController(), { signal: n } = i;
|
|
291
291
|
let a;
|
|
292
|
-
this.timeout && (a = setTimeout(() =>
|
|
292
|
+
this.timeout && (a = setTimeout(() => i.abort(), this.timeout));
|
|
293
293
|
try {
|
|
294
294
|
const l = await this.fetch(`${r}`, {
|
|
295
295
|
method: e,
|
|
296
296
|
headers: this.headers,
|
|
297
297
|
body: s,
|
|
298
|
-
signal:
|
|
298
|
+
signal: n
|
|
299
299
|
});
|
|
300
300
|
this.timeout && clearTimeout(a);
|
|
301
301
|
const c = await this._responseHandler(l);
|
|
@@ -314,29 +314,29 @@ class ne {
|
|
|
314
314
|
return new Promise((s, r) => {
|
|
315
315
|
if (t.test(`${e.status}`))
|
|
316
316
|
return s(e);
|
|
317
|
-
const
|
|
317
|
+
const i = {
|
|
318
318
|
message: new Error(e.statusText),
|
|
319
319
|
status: e.status,
|
|
320
320
|
response: e.data.error || e.data.slug
|
|
321
321
|
};
|
|
322
|
-
r(
|
|
322
|
+
r(i);
|
|
323
323
|
});
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
326
|
let f = {};
|
|
327
327
|
const d = {};
|
|
328
|
-
class
|
|
328
|
+
class ne {
|
|
329
329
|
constructor(e, t) {
|
|
330
330
|
if (h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), !t) {
|
|
331
|
-
const
|
|
332
|
-
e.oauthToken ? t = `${
|
|
331
|
+
const i = e.region ? `-${e.region}` : "", n = e.https === !1 ? "http" : "https";
|
|
332
|
+
e.oauthToken ? t = `${n}://api${i}.storyblok.com/v1` : t = `${n}://api${i}.storyblok.com/v2`;
|
|
333
333
|
}
|
|
334
334
|
const s = new Headers();
|
|
335
|
-
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((
|
|
336
|
-
e.headers && e.headers[
|
|
335
|
+
s.set("Content-Type", "application/json"), s.set("Accept", "application/json"), s.forEach((i, n) => {
|
|
336
|
+
e.headers && e.headers[n] && s.set(n, e.headers[n]);
|
|
337
337
|
});
|
|
338
338
|
let r = 5;
|
|
339
|
-
e.oauthToken && (s.set("Authorization", e.oauthToken), r = 3), e.rateLimit && (r = e.rateLimit), e.richTextSchema ? this.richTextResolver = new m(e.richTextSchema) : this.richTextResolver = new m(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries, this.throttle = N(this.throttledRequest, r, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new
|
|
339
|
+
e.oauthToken && (s.set("Authorization", e.oauthToken), r = 3), e.rateLimit && (r = e.rateLimit), e.richTextSchema ? this.richTextResolver = new m(e.richTextSchema) : this.richTextResolver = new m(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries, this.throttle = N(this.throttledRequest, r, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new _(), this.resolveNestedRelations = !1, this.client = new ie({
|
|
340
340
|
baseURL: t,
|
|
341
341
|
timeout: e.timeout || 0,
|
|
342
342
|
headers: s,
|
|
@@ -361,11 +361,11 @@ class ie {
|
|
|
361
361
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
362
362
|
}
|
|
363
363
|
makeRequest(e, t, s, r) {
|
|
364
|
-
const
|
|
364
|
+
const i = this.factoryParamOptions(
|
|
365
365
|
e,
|
|
366
366
|
this.helpers.getOptionsPage(t, s, r)
|
|
367
367
|
);
|
|
368
|
-
return this.cacheResponse(e,
|
|
368
|
+
return this.cacheResponse(e, i);
|
|
369
369
|
}
|
|
370
370
|
get(e, t) {
|
|
371
371
|
t || (t = {});
|
|
@@ -373,9 +373,9 @@ class ie {
|
|
|
373
373
|
return this.cacheResponse(s, r);
|
|
374
374
|
}
|
|
375
375
|
async getAll(e, t, s) {
|
|
376
|
-
const r = (t == null ? void 0 : t.per_page) || 25,
|
|
376
|
+
const r = (t == null ? void 0 : t.per_page) || 25, i = `/${e}`, n = i.split("/"), a = s || n[n.length - 1], l = 1, c = await this.makeRequest(i, t, r, l), u = c.total ? Math.ceil(c.total / r) : 1, p = await this.helpers.asyncMap(
|
|
377
377
|
this.helpers.range(l, u),
|
|
378
|
-
(y) => this.makeRequest(
|
|
378
|
+
(y) => this.makeRequest(i, t, r, y + 1)
|
|
379
379
|
);
|
|
380
380
|
return this.helpers.flatMap(
|
|
381
381
|
[c, ...p],
|
|
@@ -419,8 +419,8 @@ class ie {
|
|
|
419
419
|
this.relations[e[t]] && (e[t] = this._cleanCopy(this.relations[e[t]]));
|
|
420
420
|
else if (e[t] && e[t].constructor === Array) {
|
|
421
421
|
const r = [];
|
|
422
|
-
e[t].forEach((
|
|
423
|
-
this.relations[
|
|
422
|
+
e[t].forEach((i) => {
|
|
423
|
+
this.relations[i] && r.push(this._cleanCopy(this.relations[i]));
|
|
424
424
|
}), e[t] = r;
|
|
425
425
|
}
|
|
426
426
|
}
|
|
@@ -429,17 +429,17 @@ class ie {
|
|
|
429
429
|
const s = (r) => {
|
|
430
430
|
if (r != null) {
|
|
431
431
|
if (r.constructor === Array)
|
|
432
|
-
for (let
|
|
433
|
-
s(r[
|
|
432
|
+
for (let i = 0; i < r.length; i++)
|
|
433
|
+
s(r[i]);
|
|
434
434
|
else if (r.constructor === Object) {
|
|
435
435
|
if (r._stopResolving)
|
|
436
436
|
return;
|
|
437
|
-
for (const
|
|
437
|
+
for (const i in r)
|
|
438
438
|
(r.component && r._uid || r.type === "link") && (this._insertRelations(
|
|
439
439
|
r,
|
|
440
|
-
|
|
440
|
+
i,
|
|
441
441
|
t
|
|
442
|
-
), this._insertLinks(r,
|
|
442
|
+
), this._insertLinks(r, i)), s(r[i]);
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
445
|
};
|
|
@@ -448,17 +448,17 @@ class ie {
|
|
|
448
448
|
async resolveLinks(e, t) {
|
|
449
449
|
let s = [];
|
|
450
450
|
if (e.link_uuids) {
|
|
451
|
-
const r = e.link_uuids.length,
|
|
452
|
-
for (let a = 0; a < r; a +=
|
|
453
|
-
const l = Math.min(r, a +
|
|
454
|
-
|
|
451
|
+
const r = e.link_uuids.length, i = [], n = 50;
|
|
452
|
+
for (let a = 0; a < r; a += n) {
|
|
453
|
+
const l = Math.min(r, a + n);
|
|
454
|
+
i.push(e.link_uuids.slice(a, l));
|
|
455
455
|
}
|
|
456
|
-
for (let a = 0; a <
|
|
456
|
+
for (let a = 0; a < i.length; a++)
|
|
457
457
|
(await this.getStories({
|
|
458
|
-
per_page:
|
|
458
|
+
per_page: n,
|
|
459
459
|
language: t.language,
|
|
460
460
|
version: t.version,
|
|
461
|
-
by_uuids:
|
|
461
|
+
by_uuids: i[a].join(",")
|
|
462
462
|
})).data.stories.forEach(
|
|
463
463
|
(l) => {
|
|
464
464
|
s.push(l);
|
|
@@ -473,17 +473,17 @@ class ie {
|
|
|
473
473
|
async resolveRelations(e, t) {
|
|
474
474
|
let s = [];
|
|
475
475
|
if (e.rel_uuids) {
|
|
476
|
-
const r = e.rel_uuids.length,
|
|
477
|
-
for (let a = 0; a < r; a +=
|
|
478
|
-
const l = Math.min(r, a +
|
|
479
|
-
|
|
476
|
+
const r = e.rel_uuids.length, i = [], n = 50;
|
|
477
|
+
for (let a = 0; a < r; a += n) {
|
|
478
|
+
const l = Math.min(r, a + n);
|
|
479
|
+
i.push(e.rel_uuids.slice(a, l));
|
|
480
480
|
}
|
|
481
|
-
for (let a = 0; a <
|
|
481
|
+
for (let a = 0; a < i.length; a++)
|
|
482
482
|
(await this.getStories({
|
|
483
|
-
per_page:
|
|
483
|
+
per_page: n,
|
|
484
484
|
language: t.language,
|
|
485
485
|
version: t.version,
|
|
486
|
-
by_uuids:
|
|
486
|
+
by_uuids: i[a].join(",")
|
|
487
487
|
})).data.stories.forEach((l) => {
|
|
488
488
|
s.push(l);
|
|
489
489
|
});
|
|
@@ -495,22 +495,22 @@ class ie {
|
|
|
495
495
|
}
|
|
496
496
|
async resolveStories(e, t) {
|
|
497
497
|
var s, r;
|
|
498
|
-
let
|
|
499
|
-
if (typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (
|
|
500
|
-
for (const
|
|
501
|
-
this.iterateTree(this.relations[
|
|
502
|
-
e.story ? this.iterateTree(e.story,
|
|
503
|
-
this.iterateTree(
|
|
498
|
+
let i = [];
|
|
499
|
+
if (typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (i = t.resolve_relations.split(",")), await this.resolveRelations(e, t)), t.resolve_links && ["1", "story", "url"].indexOf(t.resolve_links) > -1 && ((s = e.links) != null && s.length || (r = e.link_uuids) != null && r.length) && await this.resolveLinks(e, t), this.resolveNestedRelations)
|
|
500
|
+
for (const n in this.relations)
|
|
501
|
+
this.iterateTree(this.relations[n], i);
|
|
502
|
+
e.story ? this.iterateTree(e.story, i) : e.stories.forEach((n) => {
|
|
503
|
+
this.iterateTree(n, i);
|
|
504
504
|
});
|
|
505
505
|
}
|
|
506
506
|
async cacheResponse(e, t, s) {
|
|
507
|
-
const r = this.helpers.stringify({ url: e, params: t }),
|
|
507
|
+
const r = this.helpers.stringify({ url: e, params: t }), i = this.cacheProvider();
|
|
508
508
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
509
|
-
const
|
|
510
|
-
if (
|
|
511
|
-
return Promise.resolve(
|
|
509
|
+
const n = await i.get(r);
|
|
510
|
+
if (n)
|
|
511
|
+
return Promise.resolve(n);
|
|
512
512
|
}
|
|
513
|
-
return new Promise((
|
|
513
|
+
return new Promise((n, a) => {
|
|
514
514
|
try {
|
|
515
515
|
(async () => {
|
|
516
516
|
var l;
|
|
@@ -520,7 +520,7 @@ class ie {
|
|
|
520
520
|
return (l = c.headers) != null && l["per-page"] && (u = Object.assign({}, u, {
|
|
521
521
|
perPage: c.headers["per-page"] ? parseInt(c.headers["per-page"]) : 0,
|
|
522
522
|
total: c.headers["per-page"] ? parseInt(c.headers.total) : 0
|
|
523
|
-
})), c.status != 200 ? a(c) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, t), t.version === "published" && e != "/cdn/spaces/me" && await
|
|
523
|
+
})), c.status != 200 ? a(c) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, t), t.version === "published" && e != "/cdn/spaces/me" && await i.set(r, u), u.data.cv && t.token && (t.version == "draft" && d[t.token] != u.data.cv && await this.flushCache(), d[t.token] = u.data.cv), n(u));
|
|
524
524
|
} catch (c) {
|
|
525
525
|
return a(c);
|
|
526
526
|
}
|
|
@@ -590,7 +590,7 @@ const ge = (o = {}) => {
|
|
|
590
590
|
);
|
|
591
591
|
return;
|
|
592
592
|
}
|
|
593
|
-
return { storyblokApi: new
|
|
593
|
+
return { storyblokApi: new ne(e) };
|
|
594
594
|
}, ae = (o) => {
|
|
595
595
|
if (typeof o != "object" || typeof o._editable > "u")
|
|
596
596
|
return {};
|
|
@@ -604,14 +604,18 @@ const ge = (o = {}) => {
|
|
|
604
604
|
};
|
|
605
605
|
let k;
|
|
606
606
|
const le = "https://app.storyblok.com/f/storyblok-v2-latest.js", ce = (o, e, t = {}) => {
|
|
607
|
-
|
|
607
|
+
var s;
|
|
608
|
+
const r = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", i = +new URL((s = window.location) == null ? void 0 : s.href).searchParams.get(
|
|
609
|
+
"_storyblok"
|
|
610
|
+
) === o;
|
|
611
|
+
if (!(!r || !i)) {
|
|
608
612
|
if (!o) {
|
|
609
613
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
610
614
|
return;
|
|
611
615
|
}
|
|
612
616
|
window.storyblokRegisterEvent(() => {
|
|
613
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
|
614
|
-
|
|
617
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (n) => {
|
|
618
|
+
n.action === "input" && n.story.id === o ? e(n.story) : (n.action === "change" || n.action === "published") && n.storyId === o && window.location.reload();
|
|
615
619
|
});
|
|
616
620
|
});
|
|
617
621
|
}
|
|
@@ -620,19 +624,19 @@ const le = "https://app.storyblok.com/f/storyblok-v2-latest.js", ce = (o, e, t =
|
|
|
620
624
|
const {
|
|
621
625
|
bridge: s,
|
|
622
626
|
accessToken: r,
|
|
623
|
-
use:
|
|
624
|
-
apiOptions:
|
|
627
|
+
use: i = [],
|
|
628
|
+
apiOptions: n = {},
|
|
625
629
|
richText: a = {}
|
|
626
630
|
} = o;
|
|
627
|
-
|
|
628
|
-
const l = { bridge: s, apiOptions:
|
|
631
|
+
n.accessToken = n.accessToken || r;
|
|
632
|
+
const l = { bridge: s, apiOptions: n };
|
|
629
633
|
let c = {};
|
|
630
|
-
|
|
634
|
+
i.forEach((p) => {
|
|
631
635
|
c = { ...c, ...p(l) };
|
|
632
636
|
});
|
|
633
637
|
const u = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
634
|
-
return s !== !1 && u && A(le), k = new m(a.schema), a.resolver &&
|
|
635
|
-
},
|
|
638
|
+
return s !== !1 && u && A(le), k = new m(a.schema), a.resolver && T(k, a.resolver), c;
|
|
639
|
+
}, T = (o, e) => {
|
|
636
640
|
o.addNode("blok", (t) => {
|
|
637
641
|
let s = "";
|
|
638
642
|
return t.attrs.body.forEach((r) => {
|
|
@@ -649,7 +653,7 @@ const le = "https://app.storyblok.com/f/storyblok-v2-latest.js", ce = (o, e, t =
|
|
|
649
653
|
);
|
|
650
654
|
return;
|
|
651
655
|
}
|
|
652
|
-
return o === "" ? "" : o ? (e && (s = new m(e.schema), e.resolver &&
|
|
656
|
+
return o === "" ? "" : o ? (e && (s = new m(e.schema), e.resolver && T(s, e.resolver)), s.render(o)) : (console.warn(`${o} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
653
657
|
|
|
654
658
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
|
|
655
659
|
}, ue = /* @__PURE__ */ $({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"description": "Storyblok directive for get editable elements.",
|
|
5
5
|
"main": "./dist/storyblok-vue.js",
|
|
6
6
|
"module": "./dist/storyblok-vue.mjs",
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@storyblok/js": "^2.1.
|
|
27
|
+
"@storyblok/js": "^2.1.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@babel/core": "^7.21.
|
|
30
|
+
"@babel/core": "^7.21.3",
|
|
31
31
|
"@cypress/vite-dev-server": "^5.0.4",
|
|
32
32
|
"@cypress/vue": "^5.0.4",
|
|
33
33
|
"@vitejs/plugin-vue": "^4.0.0",
|
|
34
34
|
"@vue/babel-preset-app": "^5.0.8",
|
|
35
|
-
"@vue/test-utils": "2.3.
|
|
35
|
+
"@vue/test-utils": "2.3.1",
|
|
36
36
|
"@vue/tsconfig": "^0.1.3",
|
|
37
37
|
"@vue/vue3-jest": "^29.2.3",
|
|
38
38
|
"babel-jest": "^29.4.3",
|
|
39
|
-
"cypress": "^12.
|
|
39
|
+
"cypress": "^12.8.1",
|
|
40
40
|
"eslint-plugin-cypress": "^2.12.1",
|
|
41
41
|
"eslint-plugin-jest": "^27.2.1",
|
|
42
42
|
"jest": "^29.4.3",
|