@storyblok/vue 9.3.0 → 9.3.2
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 +1 -1
- package/dist/storyblok-vue.mjs +55 -55
- package/package.json +2 -2
package/dist/storyblok-vue.js
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using Vue.
|
|
5
5
|
* author: Storyblok
|
|
6
6
|
*/
|
|
7
|
-
(function(v,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],d):(v=typeof globalThis<"u"?globalThis:v||self,d(v.storyblokVue={},v.Vue))})(this,function(v,d){"use strict";var se=Object.defineProperty,ne=(e,t,r)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,k=(e,t,r)=>ne(e,typeof t!="symbol"?t+"":t,r);let _=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),$=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),V=function(e){return e.TEXT="text",e}({}),j=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const oe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ie=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),ae=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function le(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const C=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function ce(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const n={},o=[];function l(c,u,y,m,A){typeof c!="number"||c<=u||c>=y?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${u} and ${y} (inclusive)`):A.push(`${m}(${c})`)}if(typeof t=="object"){if(typeof t.width=="number"&&t.width>0?(n.width=t.width,r=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),t.height&&typeof t.height=="number"&&t.height>0?(n.height=t.height,s=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),t.loading&&["lazy","eager"].includes(t.loading)&&(n.loading=t.loading),t.class&&(n.class=t.class),t.filters){const{filters:c}=t||{},{blur:u,brightness:y,fill:m,format:A,grayscale:U,quality:R,rotate:L}=c||{};u&&l(u,0,100,"blur",o),R&&l(R,0,100,"quality",o),y&&l(y,0,100,"brightness",o),m&&o.push(`fill(${m})`),U&&o.push("grayscale()"),L&&[0,90,180,270].includes(t.filters.rotate||0)&&o.push(`rotate(${L})`),A&&["webp","png","jpeg"].includes(A)&&o.push(`format(${A})`)}t.srcset&&(n.srcset=t.srcset.map(c=>{if(typeof c=="number")return`${e}/m/${c}x0/${o.length>0?`filters:${o.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,y]=c;return`${e}/m/${u}x${y}/${o.length>0?`filters:${o.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(n.sizes=t.sizes.join(", "))}let a=`${e}/m/`;return r>0&&s>0&&(a=`${a}${r}x${s}/`),o.length>0&&(a=`${a}filters:${o.join(":")}`),{src:a,attrs:n}}function F(e,t={},r){const s=ie(t),n=s?`${e} ${s}`:e,o=Array.isArray(r)?r.join(""):r||"";if(e){if(oe.includes(e))return`<${n}>`}else return o;return`<${n}>${o}</${e}>`}function N(e={}){const t=new Map,{renderFn:r=F,textFn:s=le,resolvers:n={},optimizeImages:o=!1,keyedResolvers:l=!1}=e,a=r!==F,c=(i={})=>{const{textAlign:h,class:p,id:f,style:b,...w}=i,g=[];return b&&g.push(b.endsWith(";")?b:`${b};`),h&&g.push(`text-align: ${h};`),C({...w,class:p,id:f,...g.length>0?{style:g.join(" ")}:{}})},u=i=>(h,p)=>{const f=c(h.attrs);return p.render(i,f,h.children||null)},y=(i,h)=>{const{src:p,alt:f,title:b,srcset:w,sizes:g}=i.attrs||{};let S=p,T={};if(o){const{src:ze,attrs:qe}=ce(p,o);S=ze,T=qe}const O={src:S,alt:f,title:b,srcset:w,sizes:g,...T};return h.render("img",C(O))},m=(i,h)=>{const{level:p,...f}=i.attrs||{},b=c(f);return h.render(`h${p}`,b,i.children)},A=(i,h)=>{var p,f,b,w;const g=h.render("img",{src:(p=i.attrs)==null?void 0:p.fallbackImage,alt:(f=i.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return h.render("span",{"data-type":"emoji","data-name":(b=i.attrs)==null?void 0:b.name,"data-emoji":(w=i.attrs)==null?void 0:w.emoji},g)},U=(i,h)=>h.render("pre",i.attrs||{},h.render("code",{},i.children||"")),R=(i,h=!1)=>({text:p,attrs:f},b)=>{const{class:w,id:g,...S}=f||{},T=h?{class:w,id:g,style:ae(S)||void 0}:f||{};return b.render(i,C(T),p)},L=i=>M(i),Be=i=>{const{marks:h,...p}=i;if("text"in i){if(h)return h.reduce((b,w)=>L({...w,text:b}),L({...p,children:p.children}));const f=i.attrs||{};if(l){const b=t.get("txt")||0;t.set("txt",b+1),f.key=`txt-${b}`}return s(p.text,f)}return""},ee=(i,h)=>{const{linktype:p,href:f,anchor:b,...w}=i.attrs||{};let g="";switch(p){case j.ASSET:case j.URL:g=f;break;case j.EMAIL:g=`mailto:${f}`;break;case j.STORY:g=f,b&&(g=`${g}#${b}`);break;default:g=f;break}const S={...w};return g&&(S.href=g),h.render("a",S,i.text)},De=(i,h)=>{var p,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(p=i==null?void 0:i.attrs)==null?void 0:p.body[0],id:(f=i.attrs)==null?void 0:f.id,style:"display: none"})},He=(i,h)=>{const p=c(i.attrs),f=i.children||null;return h.render("table",p,h.render("tbody",{},f))},Ue=(i,h)=>{const p=c(i.attrs);return h.render("tr",p,i.children)},Me=(i,h)=>{const{colspan:p,rowspan:f,colwidth:b,backgroundColor:w,textAlign:g,...S}=i.attrs||{},T=[];b&&T.push(`width: ${b}px;`),w&&T.push(`background-color: ${w};`),g&&T.push(`text-align: ${g};`);const O={...S,...p>1?{colspan:p}:{},...f>1?{rowspan:f}:{},...T.length>0?{style:T.join(" ")}:{}};return h.render("td",C(O),i.children)},Ve=(i,h)=>{const{colspan:p,rowspan:f,colwidth:b,backgroundColor:w,textAlign:g,...S}=i.attrs||{},T=[];b&&T.push(`width: ${b}px;`),w&&T.push(`background-color: ${w};`),g&&T.push(`text-align: ${g};`);const O={...S,...p>1?{colspan:p}:{},...f>1?{rowspan:f}:{},...T.length>0?{style:T.join(" ")}:{}};return h.render("th",C(O),i.children)},te=new Map([[_.DOCUMENT,u("")],[_.HEADING,m],[_.PARAGRAPH,u("p")],[_.UL_LIST,u("ul")],[_.OL_LIST,u("ol")],[_.LIST_ITEM,u("li")],[_.IMAGE,y],[_.EMOJI,A],[_.CODE_BLOCK,U],[_.HR,u("hr")],[_.BR,u("br")],[_.QUOTE,u("blockquote")],[_.COMPONENT,De],[V.TEXT,Be],[$.LINK,ee],[$.ANCHOR,ee],[$.STYLED,R("span",!0)],[$.BOLD,R("strong")],[$.TEXT_STYLE,R("span",!0)],[$.ITALIC,R("em")],[$.UNDERLINE,R("u")],[$.STRIKE,R("s")],[$.CODE,R("code")],[$.SUPERSCRIPT,R("sup")],[$.SUBSCRIPT,R("sub")],[$.HIGHLIGHT,R("mark")],[_.TABLE,He],[_.TABLE_ROW,Ue],[_.TABLE_CELL,Me],[_.TABLE_HEADER,Ve]]),re=new Map([...te,...Object.entries(n).map(([i,h])=>[i,h])]),Fe=()=>({render:(i,h={},p)=>{if(l&&i){const f=t.get(i)||0;t.set(i,f+1),h.key=`${i}-${f}`}return r(i,h,p)},originalResolvers:te,mergedResolvers:re});function x(i){const h=re.get(i.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${i.type}`),"";const p=Fe();if(i.type==="text")return h(i,p);const f=i.content?i.content.map(M):void 0;return h({...i,children:f},p)}function M(i){return i.type==="doc"?a?i.content.map(x):i.content.map(x).join(""):Array.isArray(i)?i.map(x):x(i)}return{render:M}}let z=!1;const q=[],ue=e=>new Promise((t,r)=>{if(typeof window>"u"){r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=n=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?n():q.push(n)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const s=document.createElement("script");s.async=!0,s.src=e,s.id="storyblok-javascript-bridge",s.onerror=n=>r(n),s.onload=n=>{q.forEach(o=>o()),z=!0,t(n)},document.getElementsByTagName("head")[0].appendChild(s)});var he=class extends Error{constructor(e){super(e),this.name="AbortError"}};function de(e,t,r){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(r))throw new TypeError("Expected `interval` to be a finite number");const s=[];let n=[],o=0,l=!1;const a=async()=>{o++;const u=s.shift();if(u)try{const m=await e(...u.args);u.resolve(m)}catch(m){u.reject(m)}const y=setTimeout(()=>{o--,s.length>0&&a(),n=n.filter(m=>m!==y)},r);n.includes(y)||n.push(y)},c=(...u)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((y,m)=>{s.push({resolve:y,reject:m,args:u}),o<t&&a()});return c.abort=()=>{l=!0,n.forEach(clearTimeout),n=[],s.forEach(u=>u.reject(()=>new he("Throttle function aborted"))),s.length=0},c}var pe=de;const G=(e="")=>e.includes("/cdn/"),fe=(e,t=25,r=1)=>({...e,per_page:t,page:r}),ye=e=>new Promise(t=>setTimeout(t,e)),me=(e=0,t)=>Array.from({length:e},t),be=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return me(r,(n,o)=>o*s+e)},ge=async(e,t)=>Promise.all(e.map(t)),ke=(e=[],t)=>e.map(t).reduce((r,s)=>[...r,...s],[]),B=(e,t,r)=>{const s=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const o=e[n];if(o==null)continue;const l=r?"":encodeURIComponent(n);let a;typeof o=="object"?a=B(o,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(o)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(o)}`,s.push(a)}return s.join("&")},J=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var ve=class{constructor(e){k(this,"baseURL"),k(this,"timeout"),k(this,"headers"),k(this,"responseInterceptor"),k(this,"fetch"),k(this,"ejectInterceptor"),k(this,"url"),k(this,"parameters"),k(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}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=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${B(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),n=new AbortController,{signal:o}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:o,...this.fetchOptions});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const n={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(n)})}},_e=ve;const K="SB-Agent",D={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},we={PUBLISHED:"published"};let P={};const E={};var Te=class{constructor(e,t){k(this,"client"),k(this,"maxRetries"),k(this,"retriesDelay"),k(this,"throttle"),k(this,"accessToken"),k(this,"cache"),k(this,"resolveCounter"),k(this,"relations"),k(this,"links"),k(this,"version"),k(this,"richTextResolver"),k(this,"resolveNestedRelations"),k(this,"stringifiedStoriesCache"),k(this,"inlineAssets");let r=e.endpoint||t;if(!r){const o=e.https===!1?"http":"https";e.oauthToken?r=`${o}://${J(e.region)}/v1`:r=`${o}://${J(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([o,l])=>{s.set(o,l)}),s.has(K)||(s.set(K,D.defaultAgentName),s.set(D.defaultAgentVersion,D.packageVersion));let n=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=pe(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||we.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new _e({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=E[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return G(e)?this.parseParams(t):t}makeRequest(e,t,r,s,n){const o=this.factoryParamOptions(e,fe(t,r,s));return this.cacheResponse(e,o,void 0,n)}get(e,t={},r){t||(t={});const s=`/${e}`;G(s)&&(t.version=t.version||this.version);const n=this.factoryParamOptions(s,t);return this.cacheResponse(s,n,void 0,r)}async getAll(e,t={},r,s){const n=(t==null?void 0:t.per_page)||25,o=`/${e}`.replace(/\/$/,""),l=r??o.substring(o.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,c=await this.makeRequest(o,t,n,a,s),u=c.total?Math.ceil(c.total/(c.perPage||n)):1,y=await ge(be(a,u),m=>this.makeRequest(o,t,n,m+1,s));return ke([c,...y],m=>Object.values(m.data[l]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(n=>this.getStoryReference(r,n)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(o=>o.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(n):r===n)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(n,o="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((l,a)=>s(l,`${o}[${a}]`));else if(typeof n=="object")for(const l in n){const a=o?`${o}.${l}`:l;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,l,t,r),this._insertLinks(n,l,r)),s(n[l],a)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const n=e.link_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);o.push(e.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(n=>{this.links[r][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const n=e.rel_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);o.push(e.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:o[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{s.push(c)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(n=>{this.relations[r][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,r){var s,n;let o=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const l in this.relations[r])this.iterateTree(this.relations[r][l],o,r);e.story?this.iterateTree(e.story,o,r):e.stories.forEach(l=>{this.iterateTree(l,o,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const n=B({url:e,params:t}),o=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await o.get(n);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var c;try{const u=await this.throttle("get",e,t,s);if(u.status!==200)return a(u);let y={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(y=Object.assign({},y,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),y.data.story||y.data.stories){const A=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${A}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await o.set(n,y);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(m&&E[t.token]&&E[t.token]!==y.data.cv&&await this.flushCache(),E[t.token]=y.data.cv),l(y)}catch(u){if(u.response&&u.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await ye(this.retriesDelay),this.cacheResponse(e,t,r).then(l).catch(a);a(u)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return E}cacheVersion(){return E[this.accessToken]}setCacheVersion(e){this.accessToken&&(E[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(E[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(P[e])},getAll(){return Promise.resolve(P)},set(e,t){return P[e]=t,Promise.resolve(void 0)},flush(){return P={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},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.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(n=>t(n));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(n=>n.id===s.id)});for(const n in s)typeof s[n]=="object"&&(s[n]=t(s[n]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}},$e=Te;const Re=(e={})=>{const{apiOptions:t}=e;if(!t||!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 $e(t)}},Ae=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let Y="https://app.storyblok.com/f/storyblok-v2-latest.js";const W=(e,t,r={})=>{var s;const n=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok"),l=o!==null&&+o===e;if(!(!n||!l)){if(!e){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(r).on(["input","published","change"],a=>{var c;a&&(a.action==="input"&&((c=a.story)==null?void 0:c.id)===e?t(a.story):(a.action==="change"||a.action==="published")&&a.storyId===e&&window.location.reload())})})}},Se=(e={})=>{var t,r;const{bridge:s,accessToken:n,use:o=[],apiOptions:l={},bridgeUrl:a}=e;l.accessToken=l.accessToken||n;const c={bridge:s,apiOptions:l};let u={};o.forEach(m=>{u={...u,...m(c)}}),a&&(Y=a);const y=!(typeof window>"u")&&((r=(t=window.location)==null?void 0:t.search)==null?void 0:r.includes("_storyblok_tk"));return s!==!1&&y&&ue(Y),u};function Ee(e,t){return N(t).render(e)}const H=d.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(e,{expose:t}){var a;const r=e,s=d.ref();t({value:s});const n=typeof d.resolveDynamicComponent(r.blok.component)!="string",o=d.inject("VueSDKOptions"),l=d.ref((a=r.blok.component)==null?void 0:a.replace(/_/g,"-"));return!n&&o&&(o.enableFallbackComponent?(l.value=o.customFallbackComponent??"FallbackComponent",typeof d.resolveDynamicComponent(l.value)=="string"&&console.error(`Is the Fallback component "${l.value}" registered properly?`)):console.error(`Component could not be found for blok "${r.blok.component}"! Is it defined in main.ts as "app.component("${r.blok.component}", ${r.blok.component});"?`)),(c,u)=>(d.openBlock(),d.createBlock(d.resolveDynamicComponent(l.value),d.mergeProps({ref_key:"blokRef",ref:s},{...c.$props,...c.$attrs}),d.createSlots({_:2},[d.renderList(c.$slots,(y,m)=>({name:m,fn:d.withCtx(A=>[d.renderSlot(c.$slots,m,d.normalizeProps(d.guardReactiveProps(A)))])}))]),1040))}}),Ce=e=>{var r;const t=(r=e==null?void 0:e.attrs)==null?void 0:r.body;return!Array.isArray(t)||t.length===0?[]:t.map(s=>{var n;return d.h(H,{blok:s,id:(n=e==null?void 0:e.attrs)==null?void 0:n.id},e.children)})};function X(e){const t={renderFn:d.h,textFn:d.createTextVNode,keyedResolvers:!0,resolvers:{[_.COMPONENT]:Ce,...e.resolvers}};return N(t)}const Q=d.defineComponent({__name:"StoryblokRichText",props:{doc:{},resolvers:{}},setup(e){const t=e,r=d.ref(),s=()=>r.value;return d.watch([()=>t.doc,()=>t.resolvers],([n,o])=>{const{render:l}=X({resolvers:o??{}});r.value=l(n)},{immediate:!0,deep:!0}),(n,o)=>(d.openBlock(),d.createBlock(s))}}),Ie={beforeMount(e,t){if(t.value){const r=Ae(t.value);Object.keys(r).length>0&&(e.setAttribute("data-blok-c",r["data-blok-c"]),e.setAttribute("data-blok-uid",r["data-blok-uid"]),e.classList.add("storyblok__outline"))}}},Z=e=>{console.error(`You can't use ${e} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
7
|
+
(function(v,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],d):(v=typeof globalThis<"u"?globalThis:v||self,d(v.storyblokVue={},v.Vue))})(this,function(v,d){"use strict";var se=Object.defineProperty,ne=(e,t,r)=>t in e?se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,k=(e,t,r)=>ne(e,typeof t!="symbol"?t+"":t,r);let _=function(e){return e.DOCUMENT="doc",e.HEADING="heading",e.PARAGRAPH="paragraph",e.QUOTE="blockquote",e.OL_LIST="ordered_list",e.UL_LIST="bullet_list",e.LIST_ITEM="list_item",e.CODE_BLOCK="code_block",e.HR="horizontal_rule",e.BR="hard_break",e.IMAGE="image",e.EMOJI="emoji",e.COMPONENT="blok",e.TABLE="table",e.TABLE_ROW="tableRow",e.TABLE_CELL="tableCell",e.TABLE_HEADER="tableHeader",e}({}),$=function(e){return e.BOLD="bold",e.STRONG="strong",e.STRIKE="strike",e.UNDERLINE="underline",e.ITALIC="italic",e.CODE="code",e.LINK="link",e.ANCHOR="anchor",e.STYLED="styled",e.SUPERSCRIPT="superscript",e.SUBSCRIPT="subscript",e.TEXT_STYLE="textStyle",e.HIGHLIGHT="highlight",e}({}),V=function(e){return e.TEXT="text",e}({}),j=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const oe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],ie=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),ae=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function le(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const C=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function ce(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const n={},o=[];function l(c,u,y,m,A){typeof c!="number"||c<=u||c>=y?console.warn(`[StoryblokRichText] - ${m.charAt(0).toUpperCase()+m.slice(1)} value must be a number between ${u} and ${y} (inclusive)`):A.push(`${m}(${c})`)}if(typeof t=="object"){if(t.width!==void 0&&(typeof t.width=="number"&&t.width>=0?(n.width=t.width,r=t.width):console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")),t.height!==void 0&&(typeof t.height=="number"&&t.height>=0?(n.height=t.height,s=t.height):console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")),t.height===0&&t.width===0&&(delete n.width,delete n.height,console.warn("[StoryblokRichText] - Width and height values cannot both be 0")),t.loading&&["lazy","eager"].includes(t.loading)&&(n.loading=t.loading),t.class&&(n.class=t.class),t.filters){const{filters:c}=t||{},{blur:u,brightness:y,fill:m,format:A,grayscale:U,quality:R,rotate:L}=c||{};u&&l(u,0,100,"blur",o),R&&l(R,0,100,"quality",o),y&&l(y,0,100,"brightness",o),m&&o.push(`fill(${m})`),U&&o.push("grayscale()"),L&&[0,90,180,270].includes(t.filters.rotate||0)&&o.push(`rotate(${L})`),A&&["webp","png","jpeg"].includes(A)&&o.push(`format(${A})`)}t.srcset&&(n.srcset=t.srcset.map(c=>{if(typeof c=="number")return`${e}/m/${c}x0/${o.length>0?`filters:${o.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,y]=c;return`${e}/m/${u}x${y}/${o.length>0?`filters:${o.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(n.sizes=t.sizes.join(", "))}let a=`${e}/m/`;return(r>0||s>0)&&(a=`${a}${r}x${s}/`),o.length>0&&(a=`${a}filters:${o.join(":")}`),{src:a,attrs:n}}function F(e,t={},r){const s=ie(t),n=s?`${e} ${s}`:e,o=Array.isArray(r)?r.join(""):r||"";if(e){if(oe.includes(e))return`<${n}>`}else return o;return`<${n}>${o}</${e}>`}function N(e={}){const t=new Map,{renderFn:r=F,textFn:s=le,resolvers:n={},optimizeImages:o=!1,keyedResolvers:l=!1}=e,a=r!==F,c=(i={})=>{const{textAlign:h,class:p,id:f,style:b,...w}=i,g=[];return b&&g.push(b.endsWith(";")?b:`${b};`),h&&g.push(`text-align: ${h};`),C({...w,class:p,id:f,...g.length>0?{style:g.join(" ")}:{}})},u=i=>(h,p)=>{const f=c(h.attrs);return p.render(i,f,h.children||null)},y=(i,h)=>{const{src:p,alt:f,title:b,srcset:w,sizes:g}=i.attrs||{};let S=p,T={};if(o){const{src:ze,attrs:qe}=ce(p,o);S=ze,T=qe}const O={src:S,alt:f,title:b,srcset:w,sizes:g,...T};return h.render("img",C(O))},m=(i,h)=>{const{level:p,...f}=i.attrs||{},b=c(f);return h.render(`h${p}`,b,i.children)},A=(i,h)=>{var p,f,b,w;const g=h.render("img",{src:(p=i.attrs)==null?void 0:p.fallbackImage,alt:(f=i.attrs)==null?void 0:f.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"});return h.render("span",{"data-type":"emoji","data-name":(b=i.attrs)==null?void 0:b.name,"data-emoji":(w=i.attrs)==null?void 0:w.emoji},g)},U=(i,h)=>h.render("pre",i.attrs||{},h.render("code",{},i.children||"")),R=(i,h=!1)=>({text:p,attrs:f},b)=>{const{class:w,id:g,...S}=f||{},T=h?{class:w,id:g,style:ae(S)||void 0}:f||{};return b.render(i,C(T),p)},L=i=>M(i),Be=i=>{const{marks:h,...p}=i;if("text"in i){if(h)return h.reduce((b,w)=>L({...w,text:b}),L({...p,children:p.children}));const f=i.attrs||{};if(l){const b=t.get("txt")||0;t.set("txt",b+1),f.key=`txt-${b}`}return s(p.text,f)}return""},ee=(i,h)=>{const{linktype:p,href:f,anchor:b,...w}=i.attrs||{};let g="";switch(p){case j.ASSET:case j.URL:g=f;break;case j.EMAIL:g=`mailto:${f}`;break;case j.STORY:g=f,b&&(g=`${g}#${b}`);break;default:g=f;break}const S={...w};return g&&(S.href=g),h.render("a",S,i.text)},De=(i,h)=>{var p,f;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(p=i==null?void 0:i.attrs)==null?void 0:p.body[0],id:(f=i.attrs)==null?void 0:f.id,style:"display: none"})},He=(i,h)=>{const p=c(i.attrs),f=i.children||null;return h.render("table",p,h.render("tbody",{},f))},Ue=(i,h)=>{const p=c(i.attrs);return h.render("tr",p,i.children)},Me=(i,h)=>{const{colspan:p,rowspan:f,colwidth:b,backgroundColor:w,textAlign:g,...S}=i.attrs||{},T=[];b&&T.push(`width: ${b}px;`),w&&T.push(`background-color: ${w};`),g&&T.push(`text-align: ${g};`);const O={...S,...p>1?{colspan:p}:{},...f>1?{rowspan:f}:{},...T.length>0?{style:T.join(" ")}:{}};return h.render("td",C(O),i.children)},Ve=(i,h)=>{const{colspan:p,rowspan:f,colwidth:b,backgroundColor:w,textAlign:g,...S}=i.attrs||{},T=[];b&&T.push(`width: ${b}px;`),w&&T.push(`background-color: ${w};`),g&&T.push(`text-align: ${g};`);const O={...S,...p>1?{colspan:p}:{},...f>1?{rowspan:f}:{},...T.length>0?{style:T.join(" ")}:{}};return h.render("th",C(O),i.children)},te=new Map([[_.DOCUMENT,u("")],[_.HEADING,m],[_.PARAGRAPH,u("p")],[_.UL_LIST,u("ul")],[_.OL_LIST,u("ol")],[_.LIST_ITEM,u("li")],[_.IMAGE,y],[_.EMOJI,A],[_.CODE_BLOCK,U],[_.HR,u("hr")],[_.BR,u("br")],[_.QUOTE,u("blockquote")],[_.COMPONENT,De],[V.TEXT,Be],[$.LINK,ee],[$.ANCHOR,ee],[$.STYLED,R("span",!0)],[$.BOLD,R("strong")],[$.TEXT_STYLE,R("span",!0)],[$.ITALIC,R("em")],[$.UNDERLINE,R("u")],[$.STRIKE,R("s")],[$.CODE,R("code")],[$.SUPERSCRIPT,R("sup")],[$.SUBSCRIPT,R("sub")],[$.HIGHLIGHT,R("mark")],[_.TABLE,He],[_.TABLE_ROW,Ue],[_.TABLE_CELL,Me],[_.TABLE_HEADER,Ve]]),re=new Map([...te,...Object.entries(n).map(([i,h])=>[i,h])]),Fe=()=>({render:(i,h={},p)=>{if(l&&i){const f=t.get(i)||0;t.set(i,f+1),h.key=`${i}-${f}`}return r(i,h,p)},originalResolvers:te,mergedResolvers:re});function x(i){const h=re.get(i.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${i.type}`),"";const p=Fe();if(i.type==="text")return h(i,p);const f=i.content?i.content.map(M):void 0;return h({...i,children:f},p)}function M(i){return i.type==="doc"?a?i.content.map(x):i.content.map(x).join(""):Array.isArray(i)?i.map(x):x(i)}return{render:M}}let z=!1;const q=[],ue=e=>new Promise((t,r)=>{if(typeof window>"u"){r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=n=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?n():q.push(n)},document.getElementById("storyblok-javascript-bridge")){t(void 0);return}const s=document.createElement("script");s.async=!0,s.src=e,s.id="storyblok-javascript-bridge",s.onerror=n=>r(n),s.onload=n=>{q.forEach(o=>o()),z=!0,t(n)},document.getElementsByTagName("head")[0].appendChild(s)});var he=class extends Error{constructor(e){super(e),this.name="AbortError"}};function de(e,t,r){if(!Number.isFinite(t))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(r))throw new TypeError("Expected `interval` to be a finite number");const s=[];let n=[],o=0,l=!1;const a=async()=>{o++;const u=s.shift();if(u)try{const m=await e(...u.args);u.resolve(m)}catch(m){u.reject(m)}const y=setTimeout(()=>{o--,s.length>0&&a(),n=n.filter(m=>m!==y)},r);n.includes(y)||n.push(y)},c=(...u)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((y,m)=>{s.push({resolve:y,reject:m,args:u}),o<t&&a()});return c.abort=()=>{l=!0,n.forEach(clearTimeout),n=[],s.forEach(u=>u.reject(()=>new he("Throttle function aborted"))),s.length=0},c}var pe=de;const G=(e="")=>e.includes("/cdn/"),fe=(e,t=25,r=1)=>({...e,per_page:t,page:r}),ye=e=>new Promise(t=>setTimeout(t,e)),me=(e=0,t)=>Array.from({length:e},t),be=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return me(r,(n,o)=>o*s+e)},ge=async(e,t)=>Promise.all(e.map(t)),ke=(e=[],t)=>e.map(t).reduce((r,s)=>[...r,...s],[]),B=(e,t,r)=>{const s=[];for(const n in e){if(!Object.prototype.hasOwnProperty.call(e,n))continue;const o=e[n];if(o==null)continue;const l=r?"":encodeURIComponent(n);let a;typeof o=="object"?a=B(o,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(o)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(o)}`,s.push(a)}return s.join("&")},J=e=>{const t={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return t[e]??t.eu};var ve=class{constructor(e){k(this,"baseURL"),k(this,"timeout"),k(this,"headers"),k(this,"responseInterceptor"),k(this,"fetch"),k(this,"ejectInterceptor"),k(this,"url"),k(this,"parameters"),k(this,"fetchOptions"),this.baseURL=e.baseURL,this.headers=e.headers||new Headers,this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={},this.fetchOptions={}}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=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(s=>{r.data=s});for(const s of e.headers.entries())t[s[0]]=s[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;e==="get"?t=`${this.baseURL}${this.url}?${B(this.parameters)}`:r=JSON.stringify(this.parameters);const s=new URL(t),n=new AbortController,{signal:o}=n;let l;this.timeout&&(l=setTimeout(()=>n.abort(),this.timeout));try{const a=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:o,...this.fetchOptions});this.timeout&&clearTimeout(l);const c=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(a){return{message:a}}}setFetchOptions(e={}){Object.keys(e).length>0&&"method"in e&&delete e.method,this.fetchOptions={...e}}eject(){this.ejectInterceptor=!0}_normalizeErrorMessage(e){if(Array.isArray(e))return e[0]||"Unknown error";if(e&&typeof e=="object"){if(e.error)return e.error;for(const t in e){if(Array.isArray(e[t]))return`${t}: ${e[t][0]}`;if(typeof e[t]=="string")return`${t}: ${e[t]}`}if(e.slug)return e.slug}return"Unknown error"}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,s)=>{if(t.test(`${e.status}`))return r(e);const n={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(n)})}},_e=ve;const K="SB-Agent",D={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},we={PUBLISHED:"published"};let P={};const E={};var Te=class{constructor(e,t){k(this,"client"),k(this,"maxRetries"),k(this,"retriesDelay"),k(this,"throttle"),k(this,"accessToken"),k(this,"cache"),k(this,"resolveCounter"),k(this,"relations"),k(this,"links"),k(this,"version"),k(this,"richTextResolver"),k(this,"resolveNestedRelations"),k(this,"stringifiedStoriesCache"),k(this,"inlineAssets");let r=e.endpoint||t;if(!r){const o=e.https===!1?"http":"https";e.oauthToken?r=`${o}://${J(e.region)}/v1`:r=`${o}://${J(e.region)}/v2`}const s=new Headers;s.set("Content-Type","application/json"),s.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([o,l])=>{s.set(o,l)}),s.has(K)||(s.set(K,D.defaultAgentName),s.set(D.defaultAgentVersion,D.packageVersion));let n=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=pe(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.version=e.version||we.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new _e({baseURL:r,timeout:e.timeout||0,headers:s,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=E[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),typeof e.resolve_relations<"u"&&(e.resolve_level=2),e}factoryParamOptions(e,t){return G(e)?this.parseParams(t):t}makeRequest(e,t,r,s,n){const o=this.factoryParamOptions(e,fe(t,r,s));return this.cacheResponse(e,o,void 0,n)}get(e,t={},r){t||(t={});const s=`/${e}`;G(s)&&(t.version=t.version||this.version);const n=this.factoryParamOptions(s,t);return this.cacheResponse(s,n,void 0,r)}async getAll(e,t={},r,s){const n=(t==null?void 0:t.per_page)||25,o=`/${e}`.replace(/\/$/,""),l=r??o.substring(o.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,c=await this.makeRequest(o,t,n,a,s),u=c.total?Math.ceil(c.total/(c.perPage||n)):1,y=await ge(be(a,u),m=>this.makeRequest(o,t,n,m+1,s));return ke([c,...y],m=>Object.values(m.data[l]))}post(e,t={},r){const s=`/${e}`;return this.throttle("post",s,t,r)}put(e,t={},r){const s=`/${e}`;return this.throttle("put",s,t,r)}delete(e,t={},r){t||(t={});const s=`/${e}`;return this.throttle("delete",s,t,r)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},r){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,r)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_addResolveLevel(e){typeof e.resolve_relations<"u"&&(e.resolve_level=2)}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,r){const s=e[t];s&&s.fieldtype==="multilink"&&s.linktype==="story"&&typeof s.id=="string"&&this.links[r][s.id]?s.story=this._cleanCopy(this.links[r][s.id]):s&&s.linktype==="story"&&typeof s.uuid=="string"&&this.links[r][s.uuid]&&(s.story=this._cleanCopy(this.links[r][s.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,r){const s=e[t];typeof s=="string"?e[t]=this.getStoryReference(r,s):Array.isArray(s)&&(e[t]=s.map(n=>this.getStoryReference(r,n)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(o=>o.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(n):r===n)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(n,o="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((l,a)=>s(l,`${o}[${a}]`));else if(typeof n=="object")for(const l in n){const a=o?`${o}.${l}`:l;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,l,t,r),this._insertLinks(n,l,r)),s(n[l],a)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const n=e.link_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);o.push(e.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(n=>{this.links[r][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const n=e.rel_uuids.length,o=[],l=50;for(let a=0;a<n;a+=l){const c=Math.min(n,a+l);o.push(e.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:o[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{s.push(c)});s.length>0&&(e.rels=s,delete e.rel_uuids)}else s=e.rels;s&&s.length>0&&s.forEach(n=>{this.relations[r][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,r){var s,n;let o=[];if(this.links[r]={},this.relations[r]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const l in this.relations[r])this.iterateTree(this.relations[r][l],o,r);e.story?this.iterateTree(e.story,o,r):e.stories.forEach(l=>{this.iterateTree(l,o,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const n=B({url:e,params:t}),o=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await o.get(n);if(l)return Promise.resolve(l)}return new Promise(async(l,a)=>{var c;try{const u=await this.throttle("get",e,t,s);if(u.status!==200)return a(u);let y={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(y=Object.assign({},y,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),y.data.story||y.data.stories){const A=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${A}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await o.set(n,y);const m=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(m&&E[t.token]&&E[t.token]!==y.data.cv&&await this.flushCache(),E[t.token]=y.data.cv),l(y)}catch(u){if(u.response&&u.status===429&&(r=typeof r>"u"?0:r+1,r<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await ye(this.retriesDelay),this.cacheResponse(e,t,r).then(l).catch(a);a(u)}})}throttledRequest(e,t,r,s){return this.client.setFetchOptions(s),this.client[e](t,r)}cacheVersions(){return E}cacheVersion(){return E[this.accessToken]}setCacheVersion(e){this.accessToken&&(E[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(E[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(P[e])},getAll(){return Promise.resolve(P)},set(e,t){return P[e]=t,Promise.resolve(void 0)},flush(){return P={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve()},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.clearCacheVersion(),this}async processInlineAssets(e){if(!this.inlineAssets)return e;const t=r=>{if(!r||typeof r!="object")return r;if(Array.isArray(r))return r.map(n=>t(n));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...e.data.assets.find(n=>n.id===s.id),...s});for(const n in s)typeof s[n]=="object"&&(s[n]=t(s[n]));return s};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(r=>(r.content=t(r.content),r))),e}},$e=Te;const Re=(e={})=>{const{apiOptions:t}=e;if(!t||!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 $e(t)}},Ae=e=>{if(typeof e!="object"||typeof e._editable>"u")return{};try{const t=JSON.parse(e._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return t?{"data-blok-c":JSON.stringify(t),"data-blok-uid":`${t.id}-${t.uid}`}:{}}catch{return{}}};let Y="https://app.storyblok.com/f/storyblok-v2-latest.js";const W=(e,t,r={})=>{var s;const n=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok"),l=o!==null&&+o===e;if(!(!n||!l)){if(!e){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(r).on(["input","published","change"],a=>{var c;a&&(a.action==="input"&&((c=a.story)==null?void 0:c.id)===e?t(a.story):(a.action==="change"||a.action==="published")&&a.storyId===e&&window.location.reload())})})}},Se=(e={})=>{var t,r;const{bridge:s,accessToken:n,use:o=[],apiOptions:l={},bridgeUrl:a}=e;l.accessToken=l.accessToken||n;const c={bridge:s,apiOptions:l};let u={};o.forEach(m=>{u={...u,...m(c)}}),a&&(Y=a);const y=!(typeof window>"u")&&((r=(t=window.location)==null?void 0:t.search)==null?void 0:r.includes("_storyblok_tk"));return s!==!1&&y&&ue(Y),u};function Ee(e,t){return N(t).render(e)}const H=d.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(e,{expose:t}){var a;const r=e,s=d.ref();t({value:s});const n=typeof d.resolveDynamicComponent(r.blok.component)!="string",o=d.inject("VueSDKOptions"),l=d.ref((a=r.blok.component)==null?void 0:a.replace(/_/g,"-"));return!n&&o&&(o.enableFallbackComponent?(l.value=o.customFallbackComponent??"FallbackComponent",typeof d.resolveDynamicComponent(l.value)=="string"&&console.error(`Is the Fallback component "${l.value}" registered properly?`)):console.error(`Component could not be found for blok "${r.blok.component}"! Is it defined in main.ts as "app.component("${r.blok.component}", ${r.blok.component});"?`)),(c,u)=>(d.openBlock(),d.createBlock(d.resolveDynamicComponent(l.value),d.mergeProps({ref_key:"blokRef",ref:s},{...c.$props,...c.$attrs}),d.createSlots({_:2},[d.renderList(c.$slots,(y,m)=>({name:m,fn:d.withCtx(A=>[d.renderSlot(c.$slots,m,d.normalizeProps(d.guardReactiveProps(A)))])}))]),1040))}}),Ce=e=>{var r;const t=(r=e==null?void 0:e.attrs)==null?void 0:r.body;return!Array.isArray(t)||t.length===0?[]:t.map(s=>{var n;return d.h(H,{blok:s,id:(n=e==null?void 0:e.attrs)==null?void 0:n.id},e.children)})};function X(e){const t={renderFn:d.h,textFn:d.createTextVNode,keyedResolvers:!0,resolvers:{[_.COMPONENT]:Ce,...e.resolvers}};return N(t)}const Q=d.defineComponent({__name:"StoryblokRichText",props:{doc:{},resolvers:{}},setup(e){const t=e,r=d.ref(),s=()=>r.value;return d.watch([()=>t.doc,()=>t.resolvers],([n,o])=>{const{render:l}=X({resolvers:o??{}});r.value=l(n)},{immediate:!0,deep:!0}),(n,o)=>(d.openBlock(),d.createBlock(s))}}),Ie={beforeMount(e,t){if(t.value){const r=Ae(t.value);Object.keys(r).length>0&&(e.setAttribute("data-blok-c",r["data-blok-c"]),e.setAttribute("data-blok-uid",r["data-blok-uid"]),e.classList.add("storyblok__outline"))}}},Z=e=>{console.error(`You can't use ${e} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
8
8
|
`)};let I=null;const Le=()=>(I||Z("useStoryblokApi"),I),Oe=async(e,t={},r={})=>{const s=d.ref(null);if(r.resolveRelations=r.resolveRelations??t.resolve_relations,r.resolveLinks=r.resolveLinks??t.resolve_links,d.onMounted(()=>{s.value&&s.value.id&&W(s.value.id,n=>s.value=n,r)}),I){const{data:n}=await I.get(`cdn/stories/${e}`,t);s.value=n.story}else Z("useStoryblok");return s},je={install(e,t={}){e.directive("editable",Ie),e.component("StoryblokComponent",H),e.component("StoryblokRichText",Q),t.enableFallbackComponent&&!t.customFallbackComponent&&e.component("FallbackComponent",d.defineAsyncComponent(()=>Promise.resolve().then(()=>Ne)));const{storyblokApi:r}=Se(t);I=r||null,e.provide("VueSDKOptions",t)}},Pe={class:"fallback-component"},xe={class:"component"},Ne=Object.freeze(Object.defineProperty({__proto__:null,default:((e,t)=>{const r=e.__vccOpts||e;for(const[s,n]of t)r[s]=n;return r})(d.defineComponent({__name:"FallbackComponent",props:{blok:{}},setup(e){return(t,r)=>(d.openBlock(),d.createElementBlock("div",Pe,[d.createElementVNode("p",null,[r[0]||(r[0]=d.createTextVNode(" Component could not be found for blok ",-1)),d.createElementVNode("span",xe,d.toDisplayString(t.blok.component),1),r[1]||(r[1]=d.createTextVNode("! Is it configured correctly? ",-1))])]))}}),[["__scopeId","data-v-9abcd1f2"]])},Symbol.toStringTag,{value:"Module"}));v.BlockTypes=_,v.MarkTypes=$,v.StoryblokComponent=H,v.StoryblokRichText=Q,v.StoryblokVue=je,v.TextTypes=V,v.apiPlugin=Re,v.renderRichText=Ee,v.richTextResolver=N,v.useStoryblok=Oe,v.useStoryblokApi=Le,v.useStoryblokBridge=W,v.useStoryblokRichText=X,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* description: SDK to integrate Storyblok into your project using Vue.
|
|
5
5
|
* author: Storyblok
|
|
6
6
|
*/
|
|
7
|
-
import { defineComponent as W, ref as x, resolveDynamicComponent as H, inject as de, createBlock as X, openBlock as Q, mergeProps as pe, createSlots as fe, renderList as ye, withCtx as me, renderSlot as ge, normalizeProps as be, guardReactiveProps as ve, h as Z, createTextVNode as ke, watch as we, onMounted as
|
|
8
|
-
var
|
|
7
|
+
import { defineComponent as W, ref as x, resolveDynamicComponent as H, inject as de, createBlock as X, openBlock as Q, mergeProps as pe, createSlots as fe, renderList as ye, withCtx as me, renderSlot as ge, normalizeProps as be, guardReactiveProps as ve, h as Z, createTextVNode as ke, watch as we, onMounted as Te, defineAsyncComponent as _e } from "vue";
|
|
8
|
+
var Re = Object.defineProperty, $e = (e, t, r) => t in e ? Re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, b = (e, t, r) => $e(e, typeof t != "symbol" ? t + "" : t, r);
|
|
9
9
|
let k = /* @__PURE__ */ function(e) {
|
|
10
10
|
return e.DOCUMENT = "doc", e.HEADING = "heading", e.PARAGRAPH = "paragraph", e.QUOTE = "blockquote", e.OL_LIST = "ordered_list", e.UL_LIST = "bullet_list", e.LIST_ITEM = "list_item", e.CODE_BLOCK = "code_block", e.HR = "horizontal_rule", e.BR = "hard_break", e.IMAGE = "image", e.EMOJI = "emoji", e.COMPONENT = "blok", e.TABLE = "table", e.TABLE_ROW = "tableRow", e.TABLE_CELL = "tableCell", e.TABLE_HEADER = "tableHeader", e;
|
|
11
|
-
}({}),
|
|
11
|
+
}({}), _ = /* @__PURE__ */ function(e) {
|
|
12
12
|
return e.BOLD = "bold", e.STRONG = "strong", e.STRIKE = "strike", e.UNDERLINE = "underline", e.ITALIC = "italic", e.CODE = "code", e.LINK = "link", e.ANCHOR = "anchor", e.STYLED = "styled", e.SUPERSCRIPT = "superscript", e.SUBSCRIPT = "subscript", e.TEXT_STYLE = "textStyle", e.HIGHLIGHT = "highlight", e;
|
|
13
13
|
}({}), Ae = /* @__PURE__ */ function(e) {
|
|
14
14
|
return e.TEXT = "text", e;
|
|
@@ -42,22 +42,22 @@ function Ce(e, t) {
|
|
|
42
42
|
};
|
|
43
43
|
let r = 0, s = 0;
|
|
44
44
|
const n = {}, o = [];
|
|
45
|
-
function l(c, u, f, y,
|
|
46
|
-
typeof c != "number" || c <= u || c >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${u} and ${f} (inclusive)`) :
|
|
45
|
+
function l(c, u, f, y, R) {
|
|
46
|
+
typeof c != "number" || c <= u || c >= f ? console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase() + y.slice(1)} value must be a number between ${u} and ${f} (inclusive)`) : R.push(`${y}(${c})`);
|
|
47
47
|
}
|
|
48
48
|
if (typeof t == "object") {
|
|
49
|
-
if (typeof t.width == "number" && t.width
|
|
50
|
-
const { filters: c } = t || {}, { blur: u, brightness: f, fill: y, format:
|
|
51
|
-
u && l(u, 0, 100, "blur", o),
|
|
49
|
+
if (t.width !== void 0 && (typeof t.width == "number" && t.width >= 0 ? (n.width = t.width, r = t.width) : console.warn("[StoryblokRichText] - Width value must be a number greater than or equal to 0")), t.height !== void 0 && (typeof t.height == "number" && t.height >= 0 ? (n.height = t.height, s = t.height) : console.warn("[StoryblokRichText] - Height value must be a number greater than or equal to 0")), t.height === 0 && t.width === 0 && (delete n.width, delete n.height, console.warn("[StoryblokRichText] - Width and height values cannot both be 0")), t.loading && ["lazy", "eager"].includes(t.loading) && (n.loading = t.loading), t.class && (n.class = t.class), t.filters) {
|
|
50
|
+
const { filters: c } = t || {}, { blur: u, brightness: f, fill: y, format: R, grayscale: P, quality: T, rotate: E } = c || {};
|
|
51
|
+
u && l(u, 0, 100, "blur", o), T && l(T, 0, 100, "quality", o), f && l(f, 0, 100, "brightness", o), y && o.push(`fill(${y})`), P && o.push("grayscale()"), E && [
|
|
52
52
|
0,
|
|
53
53
|
90,
|
|
54
54
|
180,
|
|
55
55
|
270
|
|
56
|
-
].includes(t.filters.rotate || 0) && o.push(`rotate(${E})`),
|
|
56
|
+
].includes(t.filters.rotate || 0) && o.push(`rotate(${E})`), R && [
|
|
57
57
|
"webp",
|
|
58
58
|
"png",
|
|
59
59
|
"jpeg"
|
|
60
|
-
].includes(
|
|
60
|
+
].includes(R) && o.push(`format(${R})`);
|
|
61
61
|
}
|
|
62
62
|
t.srcset && (n.srcset = t.srcset.map((c) => {
|
|
63
63
|
if (typeof c == "number") return `${e}/m/${c}x0/${o.length > 0 ? `filters:${o.join(":")}` : ""} ${c}w`;
|
|
@@ -71,7 +71,7 @@ function Ce(e, t) {
|
|
|
71
71
|
}).join(", ")), t.sizes && (n.sizes = t.sizes.join(", "));
|
|
72
72
|
}
|
|
73
73
|
let a = `${e}/m/`;
|
|
74
|
-
return r > 0
|
|
74
|
+
return (r > 0 || s > 0) && (a = `${a}${r}x${s}/`), o.length > 0 && (a = `${a}filters:${o.join(":")}`), {
|
|
75
75
|
src: a,
|
|
76
76
|
attrs: n
|
|
77
77
|
};
|
|
@@ -97,13 +97,13 @@ function ee(e = {}) {
|
|
|
97
97
|
return d.render(i, p, h.children || null);
|
|
98
98
|
}, f = (i, h) => {
|
|
99
99
|
const { src: d, alt: p, title: m, srcset: v, sizes: g } = i.attrs || {};
|
|
100
|
-
let
|
|
100
|
+
let $ = d, w = {};
|
|
101
101
|
if (o) {
|
|
102
102
|
const { src: ue, attrs: he } = Ce(d, o);
|
|
103
|
-
|
|
103
|
+
$ = ue, w = he;
|
|
104
104
|
}
|
|
105
105
|
const S = {
|
|
106
|
-
src:
|
|
106
|
+
src: $,
|
|
107
107
|
alt: p,
|
|
108
108
|
title: m,
|
|
109
109
|
srcset: v,
|
|
@@ -114,7 +114,7 @@ function ee(e = {}) {
|
|
|
114
114
|
}, y = (i, h) => {
|
|
115
115
|
const { level: d, ...p } = i.attrs || {}, m = c(p);
|
|
116
116
|
return h.render(`h${d}`, m, i.children);
|
|
117
|
-
},
|
|
117
|
+
}, R = (i, h) => {
|
|
118
118
|
var d, p, m, v;
|
|
119
119
|
const g = h.render("img", {
|
|
120
120
|
src: (d = i.attrs) == null ? void 0 : d.fallbackImage,
|
|
@@ -128,11 +128,11 @@ function ee(e = {}) {
|
|
|
128
128
|
"data-name": (m = i.attrs) == null ? void 0 : m.name,
|
|
129
129
|
"data-emoji": (v = i.attrs) == null ? void 0 : v.emoji
|
|
130
130
|
}, g);
|
|
131
|
-
}, P = (i, h) => h.render("pre", i.attrs || {}, h.render("code", {}, i.children || "")),
|
|
132
|
-
const { class: v, id: g,
|
|
131
|
+
}, P = (i, h) => h.render("pre", i.attrs || {}, h.render("code", {}, i.children || "")), T = (i, h = !1) => ({ text: d, attrs: p }, m) => {
|
|
132
|
+
const { class: v, id: g, ...$ } = p || {}, w = h ? {
|
|
133
133
|
class: v,
|
|
134
134
|
id: g,
|
|
135
|
-
style: Le(
|
|
135
|
+
style: Le($) || void 0
|
|
136
136
|
} : p || {};
|
|
137
137
|
return m.render(i, L(w), d);
|
|
138
138
|
}, E = (i) => N(i), se = (i) => {
|
|
@@ -171,8 +171,8 @@ function ee(e = {}) {
|
|
|
171
171
|
g = p;
|
|
172
172
|
break;
|
|
173
173
|
}
|
|
174
|
-
const
|
|
175
|
-
return g && (
|
|
174
|
+
const $ = { ...v };
|
|
175
|
+
return g && ($.href = g), h.render("a", $, i.text);
|
|
176
176
|
}, ne = (i, h) => {
|
|
177
177
|
var d, p;
|
|
178
178
|
return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"), h.render("span", {
|
|
@@ -187,20 +187,20 @@ function ee(e = {}) {
|
|
|
187
187
|
const d = c(i.attrs);
|
|
188
188
|
return h.render("tr", d, i.children);
|
|
189
189
|
}, ae = (i, h) => {
|
|
190
|
-
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: v, textAlign: g,
|
|
190
|
+
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: v, textAlign: g, ...$ } = i.attrs || {}, w = [];
|
|
191
191
|
m && w.push(`width: ${m}px;`), v && w.push(`background-color: ${v};`), g && w.push(`text-align: ${g};`);
|
|
192
192
|
const S = {
|
|
193
|
-
|
|
193
|
+
...$,
|
|
194
194
|
...d > 1 ? { colspan: d } : {},
|
|
195
195
|
...p > 1 ? { rowspan: p } : {},
|
|
196
196
|
...w.length > 0 ? { style: w.join(" ") } : {}
|
|
197
197
|
};
|
|
198
198
|
return h.render("td", L(S), i.children);
|
|
199
199
|
}, le = (i, h) => {
|
|
200
|
-
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: v, textAlign: g,
|
|
200
|
+
const { colspan: d, rowspan: p, colwidth: m, backgroundColor: v, textAlign: g, ...$ } = i.attrs || {}, w = [];
|
|
201
201
|
m && w.push(`width: ${m}px;`), v && w.push(`background-color: ${v};`), g && w.push(`text-align: ${g};`);
|
|
202
202
|
const S = {
|
|
203
|
-
|
|
203
|
+
...$,
|
|
204
204
|
...d > 1 ? { colspan: d } : {},
|
|
205
205
|
...p > 1 ? { rowspan: p } : {},
|
|
206
206
|
...w.length > 0 ? { style: w.join(" ") } : {}
|
|
@@ -214,25 +214,25 @@ function ee(e = {}) {
|
|
|
214
214
|
[k.OL_LIST, u("ol")],
|
|
215
215
|
[k.LIST_ITEM, u("li")],
|
|
216
216
|
[k.IMAGE, f],
|
|
217
|
-
[k.EMOJI,
|
|
217
|
+
[k.EMOJI, R],
|
|
218
218
|
[k.CODE_BLOCK, P],
|
|
219
219
|
[k.HR, u("hr")],
|
|
220
220
|
[k.BR, u("br")],
|
|
221
221
|
[k.QUOTE, u("blockquote")],
|
|
222
222
|
[k.COMPONENT, ne],
|
|
223
223
|
[Ae.TEXT, se],
|
|
224
|
-
[
|
|
225
|
-
[
|
|
226
|
-
[
|
|
227
|
-
[
|
|
228
|
-
[
|
|
229
|
-
[
|
|
230
|
-
[
|
|
231
|
-
[
|
|
232
|
-
[
|
|
233
|
-
[
|
|
234
|
-
[
|
|
235
|
-
[
|
|
224
|
+
[_.LINK, B],
|
|
225
|
+
[_.ANCHOR, B],
|
|
226
|
+
[_.STYLED, T("span", !0)],
|
|
227
|
+
[_.BOLD, T("strong")],
|
|
228
|
+
[_.TEXT_STYLE, T("span", !0)],
|
|
229
|
+
[_.ITALIC, T("em")],
|
|
230
|
+
[_.UNDERLINE, T("u")],
|
|
231
|
+
[_.STRIKE, T("s")],
|
|
232
|
+
[_.CODE, T("code")],
|
|
233
|
+
[_.SUPERSCRIPT, T("sup")],
|
|
234
|
+
[_.SUBSCRIPT, T("sub")],
|
|
235
|
+
[_.HIGHLIGHT, T("mark")],
|
|
236
236
|
[k.TABLE, oe],
|
|
237
237
|
[k.TABLE_ROW, ie],
|
|
238
238
|
[k.TABLE_CELL, ae],
|
|
@@ -266,7 +266,7 @@ function ee(e = {}) {
|
|
|
266
266
|
return { render: N };
|
|
267
267
|
}
|
|
268
268
|
let z = !1;
|
|
269
|
-
const
|
|
269
|
+
const q = [], Oe = (e) => new Promise((t, r) => {
|
|
270
270
|
if (typeof window > "u") {
|
|
271
271
|
r(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
|
|
272
272
|
return;
|
|
@@ -276,14 +276,14 @@ const G = [], Oe = (e) => new Promise((t, r) => {
|
|
|
276
276
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
277
277
|
return;
|
|
278
278
|
}
|
|
279
|
-
z ? n() :
|
|
279
|
+
z ? n() : q.push(n);
|
|
280
280
|
}, document.getElementById("storyblok-javascript-bridge")) {
|
|
281
281
|
t(void 0);
|
|
282
282
|
return;
|
|
283
283
|
}
|
|
284
284
|
const s = document.createElement("script");
|
|
285
285
|
s.async = !0, s.src = e, s.id = "storyblok-javascript-bridge", s.onerror = (n) => r(n), s.onload = (n) => {
|
|
286
|
-
|
|
286
|
+
q.forEach((o) => o()), z = !0, t(n);
|
|
287
287
|
}, document.getElementsByTagName("head")[0].appendChild(s);
|
|
288
288
|
});
|
|
289
289
|
var je = class extends Error {
|
|
@@ -321,7 +321,7 @@ function xe(e, t, r) {
|
|
|
321
321
|
}, c;
|
|
322
322
|
}
|
|
323
323
|
var Pe = xe;
|
|
324
|
-
const
|
|
324
|
+
const G = (e = "") => e.includes("/cdn/"), Ne = (e, t = 25, r = 1) => ({
|
|
325
325
|
...e,
|
|
326
326
|
per_page: t,
|
|
327
327
|
page: r
|
|
@@ -450,7 +450,7 @@ const K = "SB-Agent", U = {
|
|
|
450
450
|
};
|
|
451
451
|
let j = {};
|
|
452
452
|
const A = {};
|
|
453
|
-
var
|
|
453
|
+
var qe = class {
|
|
454
454
|
/**
|
|
455
455
|
*
|
|
456
456
|
* @param config ISbConfig interface
|
|
@@ -480,7 +480,7 @@ var Ge = class {
|
|
|
480
480
|
return e.token || (e.token = this.getToken()), e.cv || (e.cv = A[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
481
481
|
}
|
|
482
482
|
factoryParamOptions(e, t) {
|
|
483
|
-
return
|
|
483
|
+
return G(e) ? this.parseParams(t) : t;
|
|
484
484
|
}
|
|
485
485
|
makeRequest(e, t, r, s, n) {
|
|
486
486
|
const o = this.factoryParamOptions(e, Ne(t, r, s));
|
|
@@ -489,7 +489,7 @@ var Ge = class {
|
|
|
489
489
|
get(e, t = {}, r) {
|
|
490
490
|
t || (t = {});
|
|
491
491
|
const s = `/${e}`;
|
|
492
|
-
|
|
492
|
+
G(s) && (t.version = t.version || this.version);
|
|
493
493
|
const n = this.factoryParamOptions(s, t);
|
|
494
494
|
return this.cacheResponse(s, n, void 0, r);
|
|
495
495
|
}
|
|
@@ -698,8 +698,8 @@ var Ge = class {
|
|
|
698
698
|
perPage: u.headers["per-page"] ? Number.parseInt(u.headers["per-page"]) : 0,
|
|
699
699
|
total: u.headers["per-page"] ? Number.parseInt(u.headers.total) : 0
|
|
700
700
|
})), f.data.story || f.data.stories) {
|
|
701
|
-
const
|
|
702
|
-
await this.resolveStories(f.data, t, `${
|
|
701
|
+
const R = this.resolveCounter = ++this.resolveCounter % 1e3;
|
|
702
|
+
await this.resolveStories(f.data, t, `${R}`), f = await this.processInlineAssets(f);
|
|
703
703
|
}
|
|
704
704
|
t.version === "published" && e !== "/cdn/spaces/me" && await o.set(n, f);
|
|
705
705
|
const y = this.cache.clear === "onpreview" && t.version === "draft" || this.cache.clear === "auto";
|
|
@@ -772,15 +772,15 @@ var Ge = class {
|
|
|
772
772
|
if (Array.isArray(r)) return r.map((n) => t(n));
|
|
773
773
|
let s = { ...r };
|
|
774
774
|
s.fieldtype === "asset" && Array.isArray(e.data.assets) && (s = {
|
|
775
|
-
...s,
|
|
776
|
-
...
|
|
775
|
+
...e.data.assets.find((n) => n.id === s.id),
|
|
776
|
+
...s
|
|
777
777
|
});
|
|
778
778
|
for (const n in s) typeof s[n] == "object" && (s[n] = t(s[n]));
|
|
779
779
|
return s;
|
|
780
780
|
};
|
|
781
781
|
return e.data.story && (e.data.story.content = t(e.data.story.content)), e.data.stories && (e.data.stories = e.data.stories.map((r) => (r.content = t(r.content), r))), e;
|
|
782
782
|
}
|
|
783
|
-
},
|
|
783
|
+
}, Ge = qe;
|
|
784
784
|
const tt = (e = {}) => {
|
|
785
785
|
const { apiOptions: t } = e;
|
|
786
786
|
if (!t || !t.accessToken) {
|
|
@@ -789,7 +789,7 @@ const tt = (e = {}) => {
|
|
|
789
789
|
);
|
|
790
790
|
return;
|
|
791
791
|
}
|
|
792
|
-
return { storyblokApi: new
|
|
792
|
+
return { storyblokApi: new Ge(t) };
|
|
793
793
|
}, Je = (e) => {
|
|
794
794
|
if (typeof e != "object" || typeof e._editable > "u")
|
|
795
795
|
return {};
|
|
@@ -866,8 +866,8 @@ const te = /* @__PURE__ */ W({
|
|
|
866
866
|
}, { ...c.$props, ...c.$attrs }), fe({ _: 2 }, [
|
|
867
867
|
ye(c.$slots, (f, y) => ({
|
|
868
868
|
name: y,
|
|
869
|
-
fn: me((
|
|
870
|
-
ge(c.$slots, y, be(ve(
|
|
869
|
+
fn: me((R) => [
|
|
870
|
+
ge(c.$slots, y, be(ve(R)))
|
|
871
871
|
])
|
|
872
872
|
}))
|
|
873
873
|
]), 1040));
|
|
@@ -931,7 +931,7 @@ const Qe = /* @__PURE__ */ W({
|
|
|
931
931
|
let I = null;
|
|
932
932
|
const st = () => (I || re("useStoryblokApi"), I), nt = async (e, t = {}, r = {}) => {
|
|
933
933
|
const s = x(null);
|
|
934
|
-
if (r.resolveRelations = r.resolveRelations ?? t.resolve_relations, r.resolveLinks = r.resolveLinks ?? t.resolve_links,
|
|
934
|
+
if (r.resolveRelations = r.resolveRelations ?? t.resolve_relations, r.resolveLinks = r.resolveLinks ?? t.resolve_links, Te(() => {
|
|
935
935
|
s.value && s.value.id && Ke(
|
|
936
936
|
s.value.id,
|
|
937
937
|
(n) => s.value = n,
|
|
@@ -950,7 +950,7 @@ const st = () => (I || re("useStoryblokApi"), I), nt = async (e, t = {}, r = {})
|
|
|
950
950
|
install(e, t = {}) {
|
|
951
951
|
e.directive("editable", Ze), e.component("StoryblokComponent", te), e.component("StoryblokRichText", Qe), t.enableFallbackComponent && !t.customFallbackComponent && e.component(
|
|
952
952
|
"FallbackComponent",
|
|
953
|
-
|
|
953
|
+
_e(() => import("./FallbackComponent-vpkAikkq.js"))
|
|
954
954
|
);
|
|
955
955
|
const { storyblokApi: r } = Ye(t);
|
|
956
956
|
I = r || null, e.provide("VueSDKOptions", t);
|
|
@@ -958,7 +958,7 @@ const st = () => (I || re("useStoryblokApi"), I), nt = async (e, t = {}, r = {})
|
|
|
958
958
|
};
|
|
959
959
|
export {
|
|
960
960
|
k as BlockTypes,
|
|
961
|
-
|
|
961
|
+
_ as MarkTypes,
|
|
962
962
|
te as StoryblokComponent,
|
|
963
963
|
Qe as StoryblokRichText,
|
|
964
964
|
ot as StoryblokVue,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "9.3.
|
|
4
|
+
"version": "9.3.2",
|
|
5
5
|
"description": "SDK to integrate Storyblok into your project using Vue.",
|
|
6
6
|
"author": "Storyblok",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"vue": ">=3.4"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@storyblok/js": "4.
|
|
34
|
+
"@storyblok/js": "4.3.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@rollup/plugin-typescript": "^12.1.2",
|