@storyblok/vue 9.2.5 → 9.2.8
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.
|
@@ -13,9 +13,9 @@ const m = { class: "fallback-component" }, _ = { class: "component" }, f = /* @_
|
|
|
13
13
|
setup(t) {
|
|
14
14
|
return (e, o) => (a(), p("div", m, [
|
|
15
15
|
n("p", null, [
|
|
16
|
-
o[0] || (o[0] = c(" Component could not be found for blok ")),
|
|
16
|
+
o[0] || (o[0] = c(" Component could not be found for blok ", -1)),
|
|
17
17
|
n("span", _, d(e.blok.component), 1),
|
|
18
|
-
o[1] || (o[1] = c("! Is it configured correctly? "))
|
|
18
|
+
o[1] || (o[1] = c("! Is it configured correctly? ", -1))
|
|
19
19
|
])
|
|
20
20
|
]));
|
|
21
21
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { VNode } from 'vue';
|
|
2
2
|
import { StoryblokRichTextNode, StoryblokRichTextOptions } from '@storyblok/js';
|
|
3
|
-
export declare function useStoryblokRichText(options: StoryblokRichTextOptions<VNode>): {
|
|
3
|
+
export declare function useStoryblokRichText(options: StoryblokRichTextOptions<VNode | VNode[]>): {
|
|
4
4
|
render: (node: StoryblokRichTextNode<VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
5
5
|
[key: string]: any;
|
|
6
|
-
}
|
|
6
|
+
}> | VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
7
7
|
[key: string]: any;
|
|
8
|
-
}
|
|
8
|
+
}>[]>) => VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}> | VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}>[];
|
|
9
13
|
};
|
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(k,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(k=typeof globalThis<"u"?globalThis:k||self,f(k.storyblokVue={},k.Vue))})(this,function(k,f){"use strict";var re=Object.defineProperty,se=(e,t,r)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t,r)=>se(e,typeof t!="symbol"?t+"":t,r);let v=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}({}),M=function(e){return e.TEXT="text",e}({}),L=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"],ne=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),ie=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function ae(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function le(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const o={},n=[];function l(c,u,m,y,S){typeof c!="number"||c<=u||c>=m?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${u} and ${m} (inclusive)`):S.push(`${y}(${c})`)}if(typeof t=="object"){if(typeof t.width=="number"&&t.width>0?(o.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?(o.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)&&(o.loading=t.loading),t.class&&(o.class=t.class),t.filters){const{filters:c}=t||{},{blur:u,brightness:m,fill:y,format:S,grayscale:E,quality:I,rotate:P}=c||{};u&&l(u,0,100,"blur",n),I&&l(I,0,100,"quality",n),m&&l(m,0,100,"brightness",n),y&&n.push(`fill(${y})`),E&&n.push("grayscale()"),P&&[0,90,180,270].includes(t.filters.rotate||0)&&n.push(`rotate(${P})`),S&&["webp","png","jpeg"].includes(S)&&n.push(`format(${S})`)}t.srcset&&(o.srcset=t.srcset.map(c=>{if(typeof c=="number")return`${e}/m/${c}x0/${n.length>0?`filters:${n.join(":")}`:""} ${c}w`;if(Array.isArray(c)&&c.length===2){const[u,m]=c;return`${e}/m/${u}x${m}/${n.length>0?`filters:${n.join(":")}`:""} ${u}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),t.sizes&&(o.sizes=t.sizes.join(", "))}let a=`${e}/m/`;return r>0&&s>0&&(a=`${a}${r}x${s}/`),n.length>0&&(a=`${a}filters:${n.join(":")}`),{src:a,attrs:o}}function V(e,t={},r){const s=ne(t),o=s?`${e} ${s}`:e,n=Array.isArray(r)?r.join(""):r||"";if(e){if(oe.includes(e))return`<${o}>`}else return n;return`<${o}>${n}</${e}>`}function x(e={}){const t=new Map,{renderFn:r=V,textFn:s=ae,resolvers:o={},optimizeImages:n=!1,keyedResolvers:l=!1}=e,a=r!==V,c=i=>(h,d)=>{const p=h.attrs||{};return d.render(i,p,h.children||null)},u=(i,h)=>{const{src:d,alt:p,title:g,srcset:w,sizes:_}=i.attrs||{};let T=d,R={};if(n){const{src:Fe,attrs:ze}=le(d,n);T=Fe,R=ze}const Ve={src:T,alt:p,title:g,srcset:w,sizes:_,...R};return h.render("img",O(Ve))},m=(i,h)=>{const{level:d,...p}=i.attrs||{};return h.render(`h${d}`,p,i.children)},y=(i,h)=>{var d,p,g,w;const _=h.render("img",{src:(d=i.attrs)==null?void 0:d.fallbackImage,alt:(p=i.attrs)==null?void 0:p.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":(g=i.attrs)==null?void 0:g.name,"data-emoji":(w=i.attrs)==null?void 0:w.emoji},_)},S=(i,h)=>h.render("pre",i.attrs||{},h.render("code",{},i.children||"")),E=(i,h=!1)=>({text:d,attrs:p},g)=>{const{class:w,id:_,...T}=p||{},R=h?{class:w,id:_,style:ie(T)||void 0}:p||{};return g.render(i,O(R),d)},I=i=>U(i),P=i=>{const{marks:h,...d}=i;if("text"in i){if(h)return h.reduce((g,w)=>I({...w,text:g}),I({...d,children:d.children}));const p=i.attrs||{};if(l){const g=t.get("txt")||0;t.set("txt",g+1),p.key=`txt-${g}`}return s(d.text,p)}return""},Z=(i,h)=>{const{linktype:d,href:p,anchor:g,...w}=i.attrs||{};let _="";switch(d){case L.ASSET:case L.URL:_=p;break;case L.EMAIL:_=`mailto:${p}`;break;case L.STORY:_=p,g&&(_=`${_}#${g}`);break;default:_=p;break}const T={...w};return _&&(T.href=_),h.render("a",T,i.text)},xe=(i,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=i==null?void 0:i.attrs)==null?void 0:d.body[0],id:(p=i.attrs)==null?void 0:p.id,style:"display: none"})},Be=(i,h)=>{const d={},p=h.render("tbody",{},i.children);return h.render("table",d,p)},De=(i,h)=>{const d={};return h.render("tr",d,i.children)},He=(i,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:w,..._}=i.attrs||{},T={..._};d>1&&(T.colspan=d),p>1&&(T.rowspan=p);const R=[];return g&&R.push(`width: ${g}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(T.style=R.join(" ")),h.render("td",O(T),i.children)},Ue=(i,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:w,..._}=i.attrs||{},T={..._};d>1&&(T.colspan=d),p>1&&(T.rowspan=p);const R=[];return g&&R.push(`width: ${g}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(T.style=R.join(" ")),h.render("th",O(T),i.children)},ee=new Map([[v.DOCUMENT,c("")],[v.HEADING,m],[v.PARAGRAPH,c("p")],[v.UL_LIST,c("ul")],[v.OL_LIST,c("ol")],[v.LIST_ITEM,c("li")],[v.IMAGE,u],[v.EMOJI,y],[v.CODE_BLOCK,S],[v.HR,c("hr")],[v.BR,c("br")],[v.QUOTE,c("blockquote")],[v.COMPONENT,xe],[M.TEXT,P],[$.LINK,Z],[$.ANCHOR,Z],[$.STYLED,E("span",!0)],[$.BOLD,E("strong")],[$.TEXT_STYLE,E("span",!0)],[$.ITALIC,E("em")],[$.UNDERLINE,E("u")],[$.STRIKE,E("s")],[$.CODE,E("code")],[$.SUPERSCRIPT,E("sup")],[$.SUBSCRIPT,E("sub")],[$.HIGHLIGHT,E("mark")],[v.TABLE,Be],[v.TABLE_ROW,De],[v.TABLE_CELL,He],[v.TABLE_HEADER,Ue]]),te=new Map([...ee,...Object.entries(o).map(([i,h])=>[i,h])]),Me=()=>({render:(i,h={},d)=>{if(l&&i){const p=t.get(i)||0;t.set(i,p+1),h.key=`${i}-${p}`}return r(i,h,d)},originalResolvers:ee,mergedResolvers:te});function N(i){const h=te.get(i.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${i.type}`),"";const d=Me();if(i.type==="text")return h(i,d);const p=i.content?i.content.map(U):void 0;return h({...i,children:p},d)}function U(i){return i.type==="doc"?a?i.content.map(N):i.content.map(N).join(""):Array.isArray(i)?i.map(N):N(i)}return{render:U}}let F=!1;const z=[],ce=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=o=>{if(!window.location.search.includes("_storyblok")){console.warn("You are not in Draft Mode or in the Visual Editor.");return}F?o():z.push(o)},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=o=>r(o),s.onload=o=>{z.forEach(n=>n()),F=!0,t(o)},document.getElementsByTagName("head")[0].appendChild(s)});var ue=class extends Error{constructor(e){super(e),this.name="AbortError"}};function he(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 o=[],n=0,l=!1;const a=async()=>{n++;const u=s.shift();if(u)try{const y=await e(...u.args);u.resolve(y)}catch(y){u.reject(y)}const m=setTimeout(()=>{n--,s.length>0&&a(),o=o.filter(y=>y!==m)},r);o.includes(m)||o.push(m)},c=(...u)=>l?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((m,y)=>{s.push({resolve:m,reject:y,args:u}),n<t&&a()});return c.abort=()=>{l=!0,o.forEach(clearTimeout),o=[],s.forEach(u=>u.reject(()=>new ue("Throttle function aborted"))),s.length=0},c}var de=he;const q=(e="")=>e.includes("/cdn/"),pe=(e,t=25,r=1)=>({...e,per_page:t,page:r}),fe=e=>new Promise(t=>setTimeout(t,e)),me=(e=0,t)=>Array.from({length:e},t),ye=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return me(r,(o,n)=>n*s+e)},be=async(e,t)=>Promise.all(e.map(t)),ge=(e=[],t)=>e.map(t).reduce((r,s)=>[...r,...s],[]),B=(e,t,r)=>{const s=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const n=e[o];if(n==null)continue;const l=r?"":encodeURIComponent(o);let a;typeof n=="object"?a=B(n,t?t+encodeURIComponent(`[${l}]`):l,Array.isArray(n)):a=`${t?t+encodeURIComponent(`[${l}]`):l}=${encodeURIComponent(n)}`,s.push(a)}return s.join("&")},G=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 ke=class{constructor(e){b(this,"baseURL"),b(this,"timeout"),b(this,"headers"),b(this,"responseInterceptor"),b(this,"fetch"),b(this,"ejectInterceptor"),b(this,"url"),b(this,"parameters"),b(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),o=new AbortController,{signal:n}=o;let l;this.timeout&&(l=setTimeout(()=>o.abort(),this.timeout));try{const a=await this.fetch(`${s}`,{method:e,headers:this.headers,body:r,signal:n,...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 o={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};s(o)})}},ve=ke;const J="SB-Agent",D={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},_e={PUBLISHED:"published"};let j={};const A={};var Te=class{constructor(e,t){b(this,"client"),b(this,"maxRetries"),b(this,"retriesDelay"),b(this,"throttle"),b(this,"accessToken"),b(this,"cache"),b(this,"resolveCounter"),b(this,"relations"),b(this,"links"),b(this,"version"),b(this,"richTextResolver"),b(this,"resolveNestedRelations"),b(this,"stringifiedStoriesCache"),b(this,"inlineAssets");let r=e.endpoint||t;if(!r){const n=e.https===!1?"http":"https";e.oauthToken?r=`${n}://${G(e.region)}/v1`:r=`${n}://${G(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(([n,l])=>{s.set(n,l)}),s.has(J)||(s.set(J,D.defaultAgentName),s.set(D.defaultAgentVersion,D.packageVersion));let o=5;e.oauthToken&&(s.set("Authorization",e.oauthToken),o=3),e.rateLimit&&(o=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=de(this.throttledRequest.bind(this),o,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||_e.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new ve({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=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}factoryParamOptions(e,t){return q(e)?this.parseParams(t):t}makeRequest(e,t,r,s,o){const n=this.factoryParamOptions(e,pe(t,r,s));return this.cacheResponse(e,n,void 0,o)}get(e,t={},r){t||(t={});const s=`/${e}`;q(s)&&(t.version=t.version||this.version);const o=this.factoryParamOptions(s,t);return this.cacheResponse(s,o,void 0,r)}async getAll(e,t={},r,s){const o=(t==null?void 0:t.per_page)||25,n=`/${e}`.replace(/\/$/,""),l=r??n.substring(n.lastIndexOf("/")+1);t.version=t.version||this.version;const a=1,c=await this.makeRequest(n,t,o,a,s),u=c.total?Math.ceil(c.total/(c.perPage||o)):1,m=await be(ye(a,u),y=>this.makeRequest(n,t,o,y+1,s));return ge([c,...m],y=>Object.values(y.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(o=>this.getStoryReference(r,o)).filter(Boolean))}_insertRelations(e,t,r,s){if(Array.isArray(r)?r.find(n=>n.endsWith(`.${t}`)):r.endsWith(`.${t}`)){this._resolveField(e,t,s);return}const o=e.component?`${e.component}.${t}`:t;(Array.isArray(r)?r.includes(o):r===o)&&this._resolveField(e,t,s)}iterateTree(e,t,r){const s=(o,n="")=>{if(!(!o||o._stopResolving)){if(Array.isArray(o))o.forEach((l,a)=>s(l,`${n}[${a}]`));else if(typeof o=="object")for(const l in o){const a=n?`${n}.${l}`:l;(o.component&&o._uid||o.type==="link")&&(this._insertRelations(o,l,t,r),this._insertLinks(o,l,r)),s(o[l],a)}}};s(e.content)}async resolveLinks(e,t,r){let s=[];if(e.link_uuids){const o=e.link_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{s.push(c)})}else s=e.links;s.forEach(o=>{this.links[r][o.uuid]={...o,_stopResolving:!0}})}async resolveRelations(e,t,r){let s=[];if(e.rel_uuids){const o=e.rel_uuids.length,n=[],l=50;for(let a=0;a<o;a+=l){const c=Math.min(o,a+l);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:l,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:n[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(o=>{this.relations[r][o.uuid]={...o,_stopResolving:!0}})}async resolveStories(e,t,r){var s,o;let n=[];if(this.links[r]={},this.relations[r]={},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,r)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((s=e.links)!=null&&s.length||(o=e.link_uuids)!=null&&o.length)&&await this.resolveLinks(e,t,r),this.resolveNestedRelations)for(const l in this.relations[r])this.iterateTree(this.relations[r][l],n,r);e.story?this.iterateTree(e.story,n,r):e.stories.forEach(l=>{this.iterateTree(l,n,r)}),this.stringifiedStoriesCache={},delete this.links[r],delete this.relations[r]}async cacheResponse(e,t,r,s){const o=B({url:e,params:t}),n=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const l=await n.get(o);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 m={data:u.data,headers:u.headers};if((c=u.headers)!=null&&c["per-page"]&&(m=Object.assign({},m,{perPage:u.headers["per-page"]?Number.parseInt(u.headers["per-page"]):0,total:u.headers["per-page"]?Number.parseInt(u.headers.total):0})),m.data.story||m.data.stories){const S=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(m.data,t,`${S}`),m=await this.processInlineAssets(m)}t.version==="published"&&e!=="/cdn/spaces/me"&&await n.set(o,m);const y=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&m.data.cv&&(y&&A[t.token]&&A[t.token]!==m.data.cv&&await this.flushCache(),A[t.token]=m.data.cv),l(m)}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 fe(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 A}cacheVersion(){return A[this.accessToken]}setCacheVersion(e){this.accessToken&&(A[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(A[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},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(o=>t(o));let s={...r};s.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(s={...s,...e.data.assets.find(o=>o.id===s.id)});for(const o in s)typeof s[o]=="object"&&(s[o]=t(s[o]));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}},we=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 we(t)}},$e=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 K="https://app.storyblok.com/f/storyblok-v2-latest.js";const Y=(e,t,r={})=>{var s;const o=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((s=window.location)==null?void 0:s.href).searchParams.get("_storyblok"),l=n!==null&&+n===e;if(!(!o||!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())})})}},Ee=(e={})=>{var t,r;const{bridge:s,accessToken:o,use:n=[],apiOptions:l={},bridgeUrl:a}=e;l.accessToken=l.accessToken||o;const c={bridge:s,apiOptions:l};let u={};n.forEach(y=>{u={...u,...y(c)}}),a&&(K=a);const m=!(typeof window>"u")&&((r=(t=window.location)==null?void 0:t.search)==null?void 0:r.includes("_storyblok_tk"));return s!==!1&&m&&ce(K),u};function Se(e,t){return x(t).render(e)}const H=f.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(e,{expose:t}){var a;const r=e,s=f.ref();t({value:s});const o=typeof f.resolveDynamicComponent(r.blok.component)!="string",n=f.inject("VueSDKOptions"),l=f.ref((a=r.blok.component)==null?void 0:a.replace(/_/g,"-"));return!o&&n&&(n.enableFallbackComponent?(l.value=n.customFallbackComponent??"FallbackComponent",typeof f.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)=>(f.openBlock(),f.createBlock(f.resolveDynamicComponent(l.value),f.mergeProps({ref_key:"blokRef",ref:s},{...c.$props,...c.$attrs}),null,16))}}),Ae=e=>{var t,r;return f.h(H,{blok:(t=e==null?void 0:e.attrs)==null?void 0:t.body[0],id:(r=e.attrs)==null?void 0:r.id},e.children)};function W(e){const t={renderFn:f.h,textFn:f.createTextVNode,keyedResolvers:!0,resolvers:{[v.COMPONENT]:Ae,...e.resolvers}};return x(t)}const X=f.defineComponent({__name:"StoryblokRichText",props:{doc:{},resolvers:{}},setup(e){const t=e,r=f.ref(),s=()=>r.value;return f.watch([()=>t.doc,()=>t.resolvers],([o,n])=>{const{render:l}=W({resolvers:n??{}});r.value=l(o)},{immediate:!0,deep:!0}),(o,n)=>(f.openBlock(),f.createBlock(s))}}),Ce={beforeMount(e,t){if(t.value){const r=$e(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"))}}},Q=e=>{console.error(`You can't use ${e} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
8
|
-
`)};let C=null;const Ie=()=>(C||Q("useStoryblokApi"),C),Le=async(e,t={},r={})=>{const s=f.ref(null);if(r.resolveRelations=r.resolveRelations??t.resolve_relations,r.resolveLinks=r.resolveLinks??t.resolve_links,f.onMounted(()=>{s.value&&s.value.id&&Y(s.value.id,
|
|
7
|
+
(function(k,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(k=typeof globalThis<"u"?globalThis:k||self,f(k.storyblokVue={},k.Vue))})(this,function(k,f){"use strict";var re=Object.defineProperty,se=(e,t,r)=>t in e?re(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,b=(e,t,r)=>se(e,typeof t!="symbol"?t+"":t,r);let v=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}({}),M=function(e){return e.TEXT="text",e}({}),L=function(e){return e.URL="url",e.STORY="story",e.ASSET="asset",e.EMAIL="email",e}({});const ne=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],oe=(e={})=>Object.keys(e).map(t=>`${t}="${e[t]}"`).join(" "),ie=(e={})=>Object.keys(e).map(t=>`${t}: ${e[t]}`).join("; ");function ae(e){return e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=e=>Object.fromEntries(Object.entries(e).filter(([t,r])=>r!==void 0));function le(e,t){if(!t)return{src:e,attrs:{}};let r=0,s=0;const n={},o=[];function l(c,u,y,m,S){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)`):S.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:S,grayscale:E,quality:I,rotate:P}=c||{};u&&l(u,0,100,"blur",o),I&&l(I,0,100,"quality",o),y&&l(y,0,100,"brightness",o),m&&o.push(`fill(${m})`),E&&o.push("grayscale()"),P&&[0,90,180,270].includes(t.filters.rotate||0)&&o.push(`rotate(${P})`),S&&["webp","png","jpeg"].includes(S)&&o.push(`format(${S})`)}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 V(e,t={},r){const s=oe(t),n=s?`${e} ${s}`:e,o=Array.isArray(r)?r.join(""):r||"";if(e){if(ne.includes(e))return`<${n}>`}else return o;return`<${n}>${o}</${e}>`}function x(e={}){const t=new Map,{renderFn:r=V,textFn:s=ae,resolvers:n={},optimizeImages:o=!1,keyedResolvers:l=!1}=e,a=r!==V,c=i=>(h,d)=>{const p=h.attrs||{};return d.render(i,p,h.children||null)},u=(i,h)=>{const{src:d,alt:p,title:g,srcset:w,sizes:_}=i.attrs||{};let T=d,R={};if(o){const{src:Fe,attrs:ze}=le(d,o);T=Fe,R=ze}const Ve={src:T,alt:p,title:g,srcset:w,sizes:_,...R};return h.render("img",O(Ve))},y=(i,h)=>{const{level:d,...p}=i.attrs||{};return h.render(`h${d}`,p,i.children)},m=(i,h)=>{var d,p,g,w;const _=h.render("img",{src:(d=i.attrs)==null?void 0:d.fallbackImage,alt:(p=i.attrs)==null?void 0:p.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":(g=i.attrs)==null?void 0:g.name,"data-emoji":(w=i.attrs)==null?void 0:w.emoji},_)},S=(i,h)=>h.render("pre",i.attrs||{},h.render("code",{},i.children||"")),E=(i,h=!1)=>({text:d,attrs:p},g)=>{const{class:w,id:_,...T}=p||{},R=h?{class:w,id:_,style:ie(T)||void 0}:p||{};return g.render(i,O(R),d)},I=i=>U(i),P=i=>{const{marks:h,...d}=i;if("text"in i){if(h)return h.reduce((g,w)=>I({...w,text:g}),I({...d,children:d.children}));const p=i.attrs||{};if(l){const g=t.get("txt")||0;t.set("txt",g+1),p.key=`txt-${g}`}return s(d.text,p)}return""},Z=(i,h)=>{const{linktype:d,href:p,anchor:g,...w}=i.attrs||{};let _="";switch(d){case L.ASSET:case L.URL:_=p;break;case L.EMAIL:_=`mailto:${p}`;break;case L.STORY:_=p,g&&(_=`${_}#${g}`);break;default:_=p;break}const T={...w};return _&&(T.href=_),h.render("a",T,i.text)},xe=(i,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=i==null?void 0:i.attrs)==null?void 0:d.body[0],id:(p=i.attrs)==null?void 0:p.id,style:"display: none"})},Be=(i,h)=>{const d={},p=h.render("tbody",{},i.children);return h.render("table",d,p)},De=(i,h)=>{const d={};return h.render("tr",d,i.children)},He=(i,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:w,..._}=i.attrs||{},T={..._};d>1&&(T.colspan=d),p>1&&(T.rowspan=p);const R=[];return g&&R.push(`width: ${g}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(T.style=R.join(" ")),h.render("td",O(T),i.children)},Ue=(i,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:w,..._}=i.attrs||{},T={..._};d>1&&(T.colspan=d),p>1&&(T.rowspan=p);const R=[];return g&&R.push(`width: ${g}px;`),w&&R.push(`background-color: ${w};`),R.length>0&&(T.style=R.join(" ")),h.render("th",O(T),i.children)},ee=new Map([[v.DOCUMENT,c("")],[v.HEADING,y],[v.PARAGRAPH,c("p")],[v.UL_LIST,c("ul")],[v.OL_LIST,c("ol")],[v.LIST_ITEM,c("li")],[v.IMAGE,u],[v.EMOJI,m],[v.CODE_BLOCK,S],[v.HR,c("hr")],[v.BR,c("br")],[v.QUOTE,c("blockquote")],[v.COMPONENT,xe],[M.TEXT,P],[$.LINK,Z],[$.ANCHOR,Z],[$.STYLED,E("span",!0)],[$.BOLD,E("strong")],[$.TEXT_STYLE,E("span",!0)],[$.ITALIC,E("em")],[$.UNDERLINE,E("u")],[$.STRIKE,E("s")],[$.CODE,E("code")],[$.SUPERSCRIPT,E("sup")],[$.SUBSCRIPT,E("sub")],[$.HIGHLIGHT,E("mark")],[v.TABLE,Be],[v.TABLE_ROW,De],[v.TABLE_CELL,He],[v.TABLE_HEADER,Ue]]),te=new Map([...ee,...Object.entries(n).map(([i,h])=>[i,h])]),Me=()=>({render:(i,h={},d)=>{if(l&&i){const p=t.get(i)||0;t.set(i,p+1),h.key=`${i}-${p}`}return r(i,h,d)},originalResolvers:ee,mergedResolvers:te});function N(i){const h=te.get(i.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${i.type}`),"";const d=Me();if(i.type==="text")return h(i,d);const p=i.content?i.content.map(U):void 0;return h({...i,children:p},d)}function U(i){return i.type==="doc"?a?i.content.map(N):i.content.map(N).join(""):Array.isArray(i)?i.map(N):N(i)}return{render:U}}let F=!1;const z=[],ce=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}F?n():z.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=>{z.forEach(o=>o()),F=!0,t(n)},document.getElementsByTagName("head")[0].appendChild(s)});var ue=class extends Error{constructor(e){super(e),this.name="AbortError"}};function he(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 ue("Throttle function aborted"))),s.length=0},c}var de=he;const q=(e="")=>e.includes("/cdn/"),pe=(e,t=25,r=1)=>({...e,per_page:t,page:r}),fe=e=>new Promise(t=>setTimeout(t,e)),ye=(e=0,t)=>Array.from({length:e},t),me=(e=0,t=e)=>{const r=Math.abs(t-e)||0,s=e<t?1:-1;return ye(r,(n,o)=>o*s+e)},be=async(e,t)=>Promise.all(e.map(t)),ge=(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("&")},G=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 ke=class{constructor(e){b(this,"baseURL"),b(this,"timeout"),b(this,"headers"),b(this,"responseInterceptor"),b(this,"fetch"),b(this,"ejectInterceptor"),b(this,"url"),b(this,"parameters"),b(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)})}},ve=ke;const J="SB-Agent",D={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"7.0.0"},_e={PUBLISHED:"published"};let j={};const A={};var Te=class{constructor(e,t){b(this,"client"),b(this,"maxRetries"),b(this,"retriesDelay"),b(this,"throttle"),b(this,"accessToken"),b(this,"cache"),b(this,"resolveCounter"),b(this,"relations"),b(this,"links"),b(this,"version"),b(this,"richTextResolver"),b(this,"resolveNestedRelations"),b(this,"stringifiedStoriesCache"),b(this,"inlineAssets");let r=e.endpoint||t;if(!r){const o=e.https===!1?"http":"https";e.oauthToken?r=`${o}://${G(e.region)}/v1`:r=`${o}://${G(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(J)||(s.set(J,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=de(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||_e.PUBLISHED,this.inlineAssets=e.inlineAssets||!1,this.client=new ve({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=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}factoryParamOptions(e,t){return q(e)?this.parseParams(t):t}makeRequest(e,t,r,s,n){const o=this.factoryParamOptions(e,pe(t,r,s));return this.cacheResponse(e,o,void 0,n)}get(e,t={},r){t||(t={});const s=`/${e}`;q(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 be(me(a,u),m=>this.makeRequest(o,t,n,m+1,s));return ge([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 S=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${S}`),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&&A[t.token]&&A[t.token]!==y.data.cv&&await this.flushCache(),A[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 fe(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 A}cacheVersion(){return A[this.accessToken]}setCacheVersion(e){this.accessToken&&(A[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(A[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(j[e])},getAll(){return Promise.resolve(j)},set(e,t){return j[e]=t,Promise.resolve(void 0)},flush(){return j={},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}},we=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 we(t)}},$e=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 K="https://app.storyblok.com/f/storyblok-v2-latest.js";const Y=(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())})})}},Ee=(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&&(K=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&&ce(K),u};function Se(e,t){return x(t).render(e)}const H=f.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(e,{expose:t}){var a;const r=e,s=f.ref();t({value:s});const n=typeof f.resolveDynamicComponent(r.blok.component)!="string",o=f.inject("VueSDKOptions"),l=f.ref((a=r.blok.component)==null?void 0:a.replace(/_/g,"-"));return!n&&o&&(o.enableFallbackComponent?(l.value=o.customFallbackComponent??"FallbackComponent",typeof f.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)=>(f.openBlock(),f.createBlock(f.resolveDynamicComponent(l.value),f.mergeProps({ref_key:"blokRef",ref:s},{...c.$props,...c.$attrs}),null,16))}}),Ae=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 f.h(H,{blok:s,id:(n=e==null?void 0:e.attrs)==null?void 0:n.id},e.children)})};function W(e){const t={renderFn:f.h,textFn:f.createTextVNode,keyedResolvers:!0,resolvers:{[v.COMPONENT]:Ae,...e.resolvers}};return x(t)}const X=f.defineComponent({__name:"StoryblokRichText",props:{doc:{},resolvers:{}},setup(e){const t=e,r=f.ref(),s=()=>r.value;return f.watch([()=>t.doc,()=>t.resolvers],([n,o])=>{const{render:l}=W({resolvers:o??{}});r.value=l(n)},{immediate:!0,deep:!0}),(n,o)=>(f.openBlock(),f.createBlock(s))}}),Ce={beforeMount(e,t){if(t.value){const r=$e(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"))}}},Q=e=>{console.error(`You can't use ${e} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
8
|
+
`)};let C=null;const Ie=()=>(C||Q("useStoryblokApi"),C),Le=async(e,t={},r={})=>{const s=f.ref(null);if(r.resolveRelations=r.resolveRelations??t.resolve_relations,r.resolveLinks=r.resolveLinks??t.resolve_links,f.onMounted(()=>{s.value&&s.value.id&&Y(s.value.id,n=>s.value=n,r)}),C){const{data:n}=await C.get(`cdn/stories/${e}`,t);s.value=n.story}else Q("useStoryblok");return s},Oe={install(e,t={}){e.directive("editable",Ce),e.component("StoryblokComponent",H),e.component("StoryblokRichText",X),t.enableFallbackComponent&&!t.customFallbackComponent&&e.component("FallbackComponent",f.defineAsyncComponent(()=>Promise.resolve().then(()=>Ne)));const{storyblokApi:r}=Ee(t);C=r||null,e.provide("VueSDKOptions",t)}},je={class:"fallback-component"},Pe={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})(f.defineComponent({__name:"FallbackComponent",props:{blok:{}},setup(e){return(t,r)=>(f.openBlock(),f.createElementBlock("div",je,[f.createElementVNode("p",null,[r[0]||(r[0]=f.createTextVNode(" Component could not be found for blok ",-1)),f.createElementVNode("span",Pe,f.toDisplayString(t.blok.component),1),r[1]||(r[1]=f.createTextVNode("! Is it configured correctly? ",-1))])]))}}),[["__scopeId","data-v-9abcd1f2"]])},Symbol.toStringTag,{value:"Module"}));k.BlockTypes=v,k.MarkTypes=$,k.StoryblokComponent=H,k.StoryblokRichText=X,k.StoryblokVue=Oe,k.TextTypes=M,k.apiPlugin=Re,k.renderRichText=Se,k.richTextResolver=x,k.useStoryblok=Le,k.useStoryblokApi=Ie,k.useStoryblokBridge=Y,k.useStoryblokRichText=W,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -848,14 +848,16 @@ const ee = /* @__PURE__ */ Y({
|
|
|
848
848
|
}, { ...c.$props, ...c.$attrs }), null, 16));
|
|
849
849
|
}
|
|
850
850
|
}), Ve = (e) => {
|
|
851
|
-
var
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
{
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
851
|
+
var r;
|
|
852
|
+
const t = (r = e == null ? void 0 : e.attrs) == null ? void 0 : r.body;
|
|
853
|
+
return !Array.isArray(t) || t.length === 0 ? [] : t.map(
|
|
854
|
+
(s) => {
|
|
855
|
+
var n;
|
|
856
|
+
return Q(ee, {
|
|
857
|
+
blok: s,
|
|
858
|
+
id: (n = e == null ? void 0 : e.attrs) == null ? void 0 : n.id
|
|
859
|
+
}, e.children);
|
|
860
|
+
}
|
|
859
861
|
);
|
|
860
862
|
};
|
|
861
863
|
function ze(e) {
|
|
@@ -923,7 +925,7 @@ const We = () => (S || te("useStoryblokApi"), S), Xe = async (e, t = {}, r = {})
|
|
|
923
925
|
install(e, t = {}) {
|
|
924
926
|
e.directive("editable", qe), e.component("StoryblokComponent", ee), e.component("StoryblokRichText", Ge), t.enableFallbackComponent && !t.customFallbackComponent && e.component(
|
|
925
927
|
"FallbackComponent",
|
|
926
|
-
me(() => import("./FallbackComponent-
|
|
928
|
+
me(() => import("./FallbackComponent-vpkAikkq.js"))
|
|
927
929
|
);
|
|
928
930
|
const { storyblokApi: r } = Fe(t);
|
|
929
931
|
S = r || null, e.provide("VueSDKOptions", t);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "9.2.
|
|
4
|
+
"version": "9.2.8",
|
|
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.2.
|
|
34
|
+
"@storyblok/js": "4.2.7"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@rollup/plugin-typescript": "^12.1.2",
|