@storyblok/vue 9.0.1 → 9.0.3
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/index.d.ts +2 -2
- package/dist/storyblok-vue.js +1 -1
- package/dist/storyblok-vue.mjs +9 -2
- package/package.json +30 -53
package/dist/index.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ export * from './composables/useStoryblokRichText';
|
|
|
6
6
|
export * from './types';
|
|
7
7
|
export { apiPlugin, BlockTypes, MarkTypes, renderRichText, richTextResolver, type StoryblokRichTextDocumentNode, type StoryblokRichTextImageOptimizationOptions, type StoryblokRichTextNode, type StoryblokRichTextNodeResolver, type StoryblokRichTextNodeTypes, type StoryblokRichTextOptions, type StoryblokRichTextResolvers, TextTypes, useStoryblokBridge, } from '@storyblok/js';
|
|
8
8
|
export declare const useStoryblokApi: () => StoryblokClient;
|
|
9
|
-
export declare const useStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<Ref<ISbStoryData<import('
|
|
9
|
+
export declare const useStoryblok: (url: string, apiOptions?: ISbStoriesParams, bridgeOptions?: StoryblokBridgeConfigV2) => Promise<Ref<ISbStoryData<import('storyblok-js-client').ISbComponentType<string> & {
|
|
10
10
|
[index: string]: any;
|
|
11
|
-
}> | null, ISbStoryData<import('
|
|
11
|
+
}> | null, ISbStoryData<import('storyblok-js-client').ISbComponentType<string> & {
|
|
12
12
|
[index: string]: any;
|
|
13
13
|
}> | null>>;
|
|
14
14
|
export declare const StoryblokVue: Plugin;
|
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,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(v=typeof globalThis<"u"?globalThis:v||self,f(v.storyblokVue={},v.Vue))})(this,function(v,f){"use strict";function te(s,e){if(!e)return{src:s,attrs:{}};let t=0,o=0;const r={},n=[];function a(i,u,m,y,E){typeof i!="number"||i<=u||i>=m?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${u} and ${m} (inclusive)`):E.push(`${y}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(r.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(r.height=e.height,o=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(r.loading=e.loading),e.class&&(r.class=e.class),e.filters){const{filters:i}=e||{},{blur:u,brightness:m,fill:y,format:E,grayscale:$,quality:L,rotate:P}=i||{};u&&a(u,0,100,"blur",n),L&&a(L,0,100,"quality",n),m&&a(m,0,100,"brightness",n),y&&n.push(`fill(${y})`),$&&n.push("grayscale()"),P&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${P})`),E&&["webp","png","jpeg"].includes(E)&&n.push(`format(${E})`)}e.srcset&&(r.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${s}/m/${i}x0/${n.length>0?`filters:${n.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[u,m]=i;return`${s}/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(", ")),e.sizes&&(r.sizes=e.sizes.join(", "))}let c=`${s}/m/`;return t>0&&o>0&&(c=`${c}${t}x${o}/`),n.length>0&&(c=`${c}filters:${n.join(":")}`),{src:c,attrs:r}}var k=(s=>(s.DOCUMENT="doc",s.HEADING="heading",s.PARAGRAPH="paragraph",s.QUOTE="blockquote",s.OL_LIST="ordered_list",s.UL_LIST="bullet_list",s.LIST_ITEM="list_item",s.CODE_BLOCK="code_block",s.HR="horizontal_rule",s.BR="hard_break",s.IMAGE="image",s.EMOJI="emoji",s.COMPONENT="blok",s.TABLE="table",s.TABLE_ROW="tableRow",s.TABLE_CELL="tableCell",s.TABLE_HEADER="tableHeader",s))(k||{}),R=(s=>(s.BOLD="bold",s.STRONG="strong",s.STRIKE="strike",s.UNDERLINE="underline",s.ITALIC="italic",s.CODE="code",s.LINK="link",s.ANCHOR="anchor",s.STYLED="styled",s.SUPERSCRIPT="superscript",s.SUBSCRIPT="subscript",s.TEXT_STYLE="textStyle",s.HIGHLIGHT="highlight",s))(R||{}),x=(s=>(s.TEXT="text",s))(x||{}),C=(s=>(s.URL="url",s.STORY="story",s.ASSET="asset",s.EMAIL="email",s))(C||{});const se=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],re=(s={})=>Object.keys(s).map(e=>`${e}="${s[e]}"`).join(" "),oe=(s={})=>Object.keys(s).map(e=>`${e}: ${s[e]}`).join("; ");function ne(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=s=>Object.fromEntries(Object.entries(s).filter(([e,t])=>t!==void 0));function F(s,e={},t){const o=re(e),r=o?`${s} ${o}`:s,n=Array.isArray(t)?t.join(""):t||"";if(s){if(se.includes(s))return`<${r}>`}else return n;return`<${r}>${n}</${s}>`}function D(s={}){const e=new Map,{renderFn:t=F,textFn:o=ne,resolvers:r={},optimizeImages:n=!1,keyedResolvers:a=!1}=s,c=t!==F,i=l=>(h,d)=>{const p=h.attrs||{};return d.render(l,p,h.children||null)},u=(l,h)=>{const{src:d,alt:p,title:g,srcset:T,sizes:_}=l.attrs||{};let w=d,A={};if(n){const{src:Ue,attrs:Me}=te(d,n);w=Ue,A=Me}const He={src:w,alt:p,title:g,srcset:T,sizes:_,...A};return h.render("img",O(He))},m=(l,h)=>{const{level:d,...p}=l.attrs||{};return h.render(`h${d}`,p,l.children)},y=(l,h)=>{var d,p,g,T;const _=h.render("img",{src:(d=l.attrs)==null?void 0:d.fallbackImage,alt:(p=l.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=l.attrs)==null?void 0:g.name,"data-emoji":(T=l.attrs)==null?void 0:T.emoji},_)},E=(l,h)=>h.render("pre",l.attrs||{},h.render("code",{},l.children||"")),$=(l,h=!1)=>({text:d,attrs:p},g)=>{const{class:T,id:_,...w}=p||{},A=h?{class:T,id:_,style:oe(w)||void 0}:p||{};return g.render(l,O(A),d)},L=l=>M(l),P=l=>{const{marks:h,...d}=l;if("text"in l){if(h)return h.reduce((g,T)=>L({...T,text:g}),L({...d,children:d.children}));const p=l.attrs||{};if(a){const g=e.get("txt")||0;e.set("txt",g+1),p.key=`txt-${g}`}return o(d.text,p)}return""},Q=(l,h)=>{const{linktype:d,href:p,anchor:g,...T}=l.attrs||{};let _="";switch(d){case C.ASSET:case C.URL:_=p;break;case C.EMAIL:_=`mailto:${p}`;break;case C.STORY:_=p,g&&(_=`${_}#${g}`);break;default:_=p;break}const w={...T};return _&&(w.href=_),h.render("a",w,l.text)},je=(l,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=l==null?void 0:l.attrs)==null?void 0:d.body[0],id:(p=l.attrs)==null?void 0:p.id,style:"display: none"})},Pe=(l,h)=>{const d={},p=h.render("tbody",{},l.children);return h.render("table",d,p)},Ne=(l,h)=>{const d={};return h.render("tr",d,l.children)},xe=(l,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:T,..._}=l.attrs||{},w={..._};d>1&&(w.colspan=d),p>1&&(w.rowspan=p);const A=[];return g&&A.push(`width: ${g}px;`),T&&A.push(`background-color: ${T};`),A.length>0&&(w.style=A.join(" ")),h.render("td",O(w),l.children)},De=(l,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:T,..._}=l.attrs||{},w={..._};d>1&&(w.colspan=d),p>1&&(w.rowspan=p);const A=[];return g&&A.push(`width: ${g}px;`),T&&A.push(`background-color: ${T};`),A.length>0&&(w.style=A.join(" ")),h.render("th",O(w),l.children)},Z=new Map([[k.DOCUMENT,i("")],[k.HEADING,m],[k.PARAGRAPH,i("p")],[k.UL_LIST,i("ul")],[k.OL_LIST,i("ol")],[k.LIST_ITEM,i("li")],[k.IMAGE,u],[k.EMOJI,y],[k.CODE_BLOCK,E],[k.HR,i("hr")],[k.BR,i("br")],[k.QUOTE,i("blockquote")],[k.COMPONENT,je],[x.TEXT,P],[R.LINK,Q],[R.ANCHOR,Q],[R.STYLED,$("span",!0)],[R.BOLD,$("strong")],[R.TEXT_STYLE,$("span",!0)],[R.ITALIC,$("em")],[R.UNDERLINE,$("u")],[R.STRIKE,$("s")],[R.CODE,$("code")],[R.SUPERSCRIPT,$("sup")],[R.SUBSCRIPT,$("sub")],[R.HIGHLIGHT,$("mark")],[k.TABLE,Pe],[k.TABLE_ROW,Ne],[k.TABLE_CELL,xe],[k.TABLE_HEADER,De]]),ee=new Map([...Z,...Object.entries(r).map(([l,h])=>[l,h])]),Be=()=>({render:(l,h={},d)=>{if(a&&l){const p=e.get(l)||0;e.set(l,p+1),h.key=`${l}-${p}`}return t(l,h,d)},originalResolvers:Z,mergedResolvers:ee});function N(l){const h=ee.get(l.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${l.type}`),"";const d=Be();if(l.type==="text")return h(l,d);const p=l.content?l.content.map(M):void 0;return h({...l,children:p},d)}function M(l){return l.type==="doc"?c?l.content.map(N):l.content.map(N).join(""):Array.isArray(l)?l.map(N):N(l)}return{render:M}}let V=!1;const z=[],ie=s=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}V?r():z.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=s,o.id="storyblok-javascript-bridge",o.onerror=r=>t(r),o.onload=r=>{z.forEach(n=>n()),V=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(o)});var ae=Object.defineProperty,le=(s,e,t)=>e in s?ae(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,b=(s,e,t)=>le(s,typeof e!="symbol"?e+"":e,t);class ce extends Error{constructor(e){super(e),this.name="AbortError"}}function ue(s,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const o=[];let r=[],n=0,a=!1;const c=async()=>{n++;const u=o.shift();if(u)try{const y=await s(...u.args);u.resolve(y)}catch(y){u.reject(y)}const m=setTimeout(()=>{n--,o.length>0&&c(),r=r.filter(y=>y!==m)},t);r.includes(m)||r.push(m)},i=(...u)=>a?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((m,y)=>{o.push({resolve:m,reject:y,args:u}),n<e&&c()});return i.abort=()=>{a=!0,r.forEach(clearTimeout),r=[],o.forEach(u=>u.reject(()=>new ce("Throttle function aborted"))),o.length=0},i}const he=(s="")=>s.includes("/cdn/"),de=(s,e=25,t=1)=>({...s,per_page:e,page:t}),pe=s=>new Promise(e=>setTimeout(e,s)),fe=(s=0,e)=>Array.from({length:s},e),me=(s=0,e=s)=>{const t=Math.abs(e-s)||0,o=s<e?1:-1;return fe(t,(r,n)=>n*o+s)},ye=async(s,e)=>Promise.all(s.map(e)),be=(s=[],e)=>s.map(e).reduce((t,o)=>[...t,...o],[]),B=(s,e,t)=>{const o=[];for(const r in s){if(!Object.prototype.hasOwnProperty.call(s,r))continue;const n=s[r];if(n==null)continue;const a=t?"":encodeURIComponent(r);let c;typeof n=="object"?c=B(n,e?e+encodeURIComponent(`[${a}]`):a,Array.isArray(n)):c=`${e?e+encodeURIComponent(`[${a}]`):a}=${encodeURIComponent(n)}`,o.push(c)}return o.join("&")},q=s=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[s]??e.eu};class ke{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=[],o={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{o.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return o.headers={...t},o.status=e.status,o.statusText=e.statusText,o}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,o=null;e==="get"?t=`${this.baseURL}${this.url}?${B(this.parameters)}`:o=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:a}=n;let c;this.timeout&&(c=setTimeout(()=>n.abort(),this.timeout));try{const i=await this.fetch(`${r}`,{method:e,headers:this.headers,body:o,signal:a,...this.fetchOptions});this.timeout&&clearTimeout(c);const u=await this._responseHandler(i);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(i){return{message:i}}}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((o,r)=>{if(t.test(`${e.status}`))return o(e);const n={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};r(n)})}}const G="SB-Agent",H={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"},ge={DRAFT:"draft"};let j={};const S={};class ve{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 o=e.endpoint||t;if(!o){const a=e.https===!1?"http":"https";e.oauthToken?o=`${a}://${q(e.region)}/v1`:o=`${a}://${q(e.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([a,c])=>{r.set(a,c)}),r.has(G)||(r.set(G,H.defaultAgentName),r.set(H.defaultAgentVersion,H.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ue(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||ge.DRAFT,this.inlineAssets=e.inlineAssets||!1,this.client=new ke({baseURL:o,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=S[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 he(e)?this.parseParams(t):t}makeRequest(e,t,o,r,n){const a=this.factoryParamOptions(e,de(t,o,r));return this.cacheResponse(e,a,void 0,n)}get(e,t={},o){t||(t={});const r=`/${e}`;t.version=t.version||this.version;const n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n,void 0,o)}async getAll(e,t={},o,r){const n=(t==null?void 0:t.per_page)||25,a=`/${e}`.replace(/\/$/,""),c=o??a.substring(a.lastIndexOf("/")+1);t.version=t.version||this.version;const i=1,u=await this.makeRequest(a,t,n,i,r),m=u.total?Math.ceil(u.total/n):1,y=await ye(me(i,m),E=>this.makeRequest(a,t,n,E+1,r));return be([u,...y],E=>Object.values(E.data[c]))}post(e,t={},o){const r=`/${e}`;return this.throttle("post",r,t,o)}put(e,t={},o){const r=`/${e}`;return this.throttle("put",r,t,o)}delete(e,t={},o){t||(t={});const r=`/${e}`;return this.throttle("delete",r,t,o)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},o){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,o)}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,o){const r=e[t];r&&r.fieldtype==="multilink"&&r.linktype==="story"&&typeof r.id=="string"&&this.links[o][r.id]?r.story=this._cleanCopy(this.links[o][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[o][r.uuid]&&(r.story=this._cleanCopy(this.links[o][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,o){const r=e[t];typeof r=="string"?e[t]=this.getStoryReference(o,r):Array.isArray(r)&&(e[t]=r.map(n=>this.getStoryReference(o,n)).filter(Boolean))}_insertRelations(e,t,o,r){if(Array.isArray(o)?o.find(a=>a.endsWith(`.${t}`)):o.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(o)?o.includes(n):o===n)&&this._resolveField(e,t,r)}iterateTree(e,t,o){const r=(n,a="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((c,i)=>r(c,`${a}[${i}]`));else if(typeof n=="object")for(const c in n){const i=a?`${a}.${c}`:c;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,c,t,o),this._insertLinks(n,c,o)),r(n[c],i)}}};r(e.content)}async resolveLinks(e,t,o){let r=[];if(e.link_uuids){const n=e.link_uuids.length,a=[],c=50;for(let i=0;i<n;i+=c){const u=Math.min(n,i+c);a.push(e.link_uuids.slice(i,u))}for(let i=0;i<a.length;i++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:a[i].join(",")})).data.stories.forEach(u=>{r.push(u)})}else r=e.links;r.forEach(n=>{this.links[o][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,o){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,a=[],c=50;for(let i=0;i<n;i+=c){const u=Math.min(n,i+c);a.push(e.rel_uuids.slice(i,u))}for(let i=0;i<a.length;i++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:a[i].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(u=>{r.push(u)});r.length>0&&(e.rels=r,delete e.rel_uuids)}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[o][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,o){var r,n;let a=[];if(this.links[o]={},this.relations[o]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(a=t.resolve_relations.split(",")),await this.resolveRelations(e,t,o)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((r=e.links)!=null&&r.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,o),this.resolveNestedRelations)for(const c in this.relations[o])this.iterateTree(this.relations[o][c],a,o);e.story?this.iterateTree(e.story,a,o):e.stories.forEach(c=>{this.iterateTree(c,a,o)}),this.stringifiedStoriesCache={},delete this.links[o],delete this.relations[o]}async cacheResponse(e,t,o,r){const n=B({url:e,params:t}),a=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await a.get(n);if(c)return Promise.resolve(c)}return new Promise(async(c,i)=>{var u;try{const m=await this.throttle("get",e,t,r);if(m.status!==200)return i(m);let y={data:m.data,headers:m.headers};if((u=m.headers)!=null&&u["per-page"]&&(y=Object.assign({},y,{perPage:m.headers["per-page"]?Number.parseInt(m.headers["per-page"]):0,total:m.headers["per-page"]?Number.parseInt(m.headers.total):0})),y.data.story||y.data.stories){const $=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${$}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await a.set(n,y);const E=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(E&&S[t.token]&&S[t.token]!==y.data.cv&&await this.flushCache(),S[t.token]=y.data.cv),c(y)}catch(m){if(m.response&&m.status===429&&(o=typeof o>"u"?0:o+1,o<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await pe(this.retriesDelay),this.cacheResponse(e,t,o).then(c).catch(i);i(m)}})}throttledRequest(e,t,o,r){return this.client.setFetchOptions(r),this.client[e](t,o)}cacheVersions(){return S}cacheVersion(){return S[this.accessToken]}setCacheVersion(e){this.accessToken&&(S[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(S[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=o=>{if(!o||typeof o!="object")return o;if(Array.isArray(o))return o.map(n=>t(n));let r={...o};r.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(r={...r,...e.data.assets.find(n=>n.id===r.id)});for(const n in r)typeof r[n]=="object"&&(r[n]=t(r[n]));return r};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(o=>(o.content=t(o.content),o))),e}}const _e=(s={})=>{const{apiOptions:e}=s;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ve(e)}},we=s=>{if(typeof s!="object"||typeof s._editable>"u")return{};try{const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let J="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(s,e,t={})=>{var o;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((o=window.location)==null?void 0:o.href).searchParams.get("_storyblok"),a=n!==null&&+n===s;if(!(!r||!a)){if(!s){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],c=>{var i;c&&(c.action==="input"&&((i=c.story)==null?void 0:i.id)===s?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===s&&window.location.reload())})})}},Te=(s={})=>{var e,t;const{bridge:o,accessToken:r,use:n=[],apiOptions:a={},bridgeUrl:c}=s;a.accessToken=a.accessToken||r;const i={bridge:o,apiOptions:a};let u={};n.forEach(y=>{u={...u,...y(i)}}),c&&(J=c);const m=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return o!==!1&&m&&ie(J),u};function Re(s,e){return D(e).render(s)}const U=f.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(s,{expose:e}){const t=s,o=f.ref();e({value:o});const r=typeof f.resolveDynamicComponent(t.blok.component)!="string",n=f.inject("VueSDKOptions"),a=f.ref(t.blok.component);return!r&&n&&(n.enableFallbackComponent?(a.value=n.customFallbackComponent??"FallbackComponent",typeof f.resolveDynamicComponent(a.value)=="string"&&console.error(`Is the Fallback component "${a.value}" registered properly?`)):console.error(`Component could not be found for blok "${t.blok.component}"! Is it defined in main.ts as "app.component("${t.blok.component}", ${t.blok.component});"?`)),(c,i)=>(f.openBlock(),f.createBlock(f.resolveDynamicComponent(a.value),f.mergeProps({ref_key:"blokRef",ref:o},{...c.$props,...c.$attrs}),null,16))}}),$e=s=>{var e,t;return f.h(U,{blok:(e=s==null?void 0:s.attrs)==null?void 0:e.body[0],id:(t=s.attrs)==null?void 0:t.id},s.children)};function Y(s){const e={renderFn:f.h,textFn:f.createTextVNode,keyedResolvers:!0,resolvers:{[k.COMPONENT]:$e,...s.resolvers}};return D(e)}const W=f.defineComponent({__name:"StoryblokRichText",props:{doc:{},resolvers:{}},setup(s){const e=s,t=f.ref(),o=()=>t.value;return f.watch([()=>e.doc,()=>e.resolvers],([r,n])=>{const{render:a}=Y({resolvers:n??{}});t.value=a(r)},{immediate:!0,deep:!0}),(r,n)=>(f.openBlock(),f.createBlock(o))}}),Ae={beforeMount(s,e){if(e.value){const t=we(e.value);Object.keys(t).length>0&&(s.setAttribute("data-blok-c",t["data-blok-c"]),s.setAttribute("data-blok-uid",t["data-blok-uid"]),s.classList.add("storyblok__outline"))}}},X=s=>{console.error(`You can't use ${s} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
7
|
+
(function(v,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],f):(v=typeof globalThis<"u"?globalThis:v||self,f(v.storyblokVue={},v.Vue))})(this,function(v,f){"use strict";function te(s,e){if(!e)return{src:s,attrs:{}};let t=0,o=0;const r={},n=[];function a(i,u,m,y,E){typeof i!="number"||i<=u||i>=m?console.warn(`[StoryblokRichText] - ${y.charAt(0).toUpperCase()+y.slice(1)} value must be a number between ${u} and ${m} (inclusive)`):E.push(`${y}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(r.width=e.width,t=e.width):console.warn("[StoryblokRichText] - Width value must be a number greater than 0"),e.height&&typeof e.height=="number"&&e.height>0?(r.height=e.height,o=e.height):console.warn("[StoryblokRichText] - Height value must be a number greater than 0"),e.loading&&["lazy","eager"].includes(e.loading)&&(r.loading=e.loading),e.class&&(r.class=e.class),e.filters){const{filters:i}=e||{},{blur:u,brightness:m,fill:y,format:E,grayscale:$,quality:L,rotate:P}=i||{};u&&a(u,0,100,"blur",n),L&&a(L,0,100,"quality",n),m&&a(m,0,100,"brightness",n),y&&n.push(`fill(${y})`),$&&n.push("grayscale()"),P&&[0,90,180,270].includes(e.filters.rotate||0)&&n.push(`rotate(${P})`),E&&["webp","png","jpeg"].includes(E)&&n.push(`format(${E})`)}e.srcset&&(r.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${s}/m/${i}x0/${n.length>0?`filters:${n.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[u,m]=i;return`${s}/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(", ")),e.sizes&&(r.sizes=e.sizes.join(", "))}let c=`${s}/m/`;return t>0&&o>0&&(c=`${c}${t}x${o}/`),n.length>0&&(c=`${c}filters:${n.join(":")}`),{src:c,attrs:r}}var k=(s=>(s.DOCUMENT="doc",s.HEADING="heading",s.PARAGRAPH="paragraph",s.QUOTE="blockquote",s.OL_LIST="ordered_list",s.UL_LIST="bullet_list",s.LIST_ITEM="list_item",s.CODE_BLOCK="code_block",s.HR="horizontal_rule",s.BR="hard_break",s.IMAGE="image",s.EMOJI="emoji",s.COMPONENT="blok",s.TABLE="table",s.TABLE_ROW="tableRow",s.TABLE_CELL="tableCell",s.TABLE_HEADER="tableHeader",s))(k||{}),R=(s=>(s.BOLD="bold",s.STRONG="strong",s.STRIKE="strike",s.UNDERLINE="underline",s.ITALIC="italic",s.CODE="code",s.LINK="link",s.ANCHOR="anchor",s.STYLED="styled",s.SUPERSCRIPT="superscript",s.SUBSCRIPT="subscript",s.TEXT_STYLE="textStyle",s.HIGHLIGHT="highlight",s))(R||{}),x=(s=>(s.TEXT="text",s))(x||{}),C=(s=>(s.URL="url",s.STORY="story",s.ASSET="asset",s.EMAIL="email",s))(C||{});const se=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],re=(s={})=>Object.keys(s).map(e=>`${e}="${s[e]}"`).join(" "),oe=(s={})=>Object.keys(s).map(e=>`${e}: ${s[e]}`).join("; ");function ne(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const O=s=>Object.fromEntries(Object.entries(s).filter(([e,t])=>t!==void 0));function F(s,e={},t){const o=re(e),r=o?`${s} ${o}`:s,n=Array.isArray(t)?t.join(""):t||"";if(s){if(se.includes(s))return`<${r}>`}else return n;return`<${r}>${n}</${s}>`}function D(s={}){const e=new Map,{renderFn:t=F,textFn:o=ne,resolvers:r={},optimizeImages:n=!1,keyedResolvers:a=!1}=s,c=t!==F,i=l=>(h,d)=>{const p=h.attrs||{};return d.render(l,p,h.children||null)},u=(l,h)=>{const{src:d,alt:p,title:g,srcset:T,sizes:_}=l.attrs||{};let w=d,A={};if(n){const{src:Ue,attrs:Me}=te(d,n);w=Ue,A=Me}const He={src:w,alt:p,title:g,srcset:T,sizes:_,...A};return h.render("img",O(He))},m=(l,h)=>{const{level:d,...p}=l.attrs||{};return h.render(`h${d}`,p,l.children)},y=(l,h)=>{var d,p,g,T;const _=h.render("img",{src:(d=l.attrs)==null?void 0:d.fallbackImage,alt:(p=l.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=l.attrs)==null?void 0:g.name,"data-emoji":(T=l.attrs)==null?void 0:T.emoji},_)},E=(l,h)=>h.render("pre",l.attrs||{},h.render("code",{},l.children||"")),$=(l,h=!1)=>({text:d,attrs:p},g)=>{const{class:T,id:_,...w}=p||{},A=h?{class:T,id:_,style:oe(w)||void 0}:p||{};return g.render(l,O(A),d)},L=l=>M(l),P=l=>{const{marks:h,...d}=l;if("text"in l){if(h)return h.reduce((g,T)=>L({...T,text:g}),L({...d,children:d.children}));const p=l.attrs||{};if(a){const g=e.get("txt")||0;e.set("txt",g+1),p.key=`txt-${g}`}return o(d.text,p)}return""},Q=(l,h)=>{const{linktype:d,href:p,anchor:g,...T}=l.attrs||{};let _="";switch(d){case C.ASSET:case C.URL:_=p;break;case C.EMAIL:_=`mailto:${p}`;break;case C.STORY:_=p,g&&(_=`${_}#${g}`);break;default:_=p;break}const w={...T};return _&&(w.href=_),h.render("a",w,l.text)},je=(l,h)=>{var d,p;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),h.render("span",{blok:(d=l==null?void 0:l.attrs)==null?void 0:d.body[0],id:(p=l.attrs)==null?void 0:p.id,style:"display: none"})},Pe=(l,h)=>{const d={},p=h.render("tbody",{},l.children);return h.render("table",d,p)},Ne=(l,h)=>{const d={};return h.render("tr",d,l.children)},xe=(l,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:T,..._}=l.attrs||{},w={..._};d>1&&(w.colspan=d),p>1&&(w.rowspan=p);const A=[];return g&&A.push(`width: ${g}px;`),T&&A.push(`background-color: ${T};`),A.length>0&&(w.style=A.join(" ")),h.render("td",O(w),l.children)},De=(l,h)=>{const{colspan:d,rowspan:p,colwidth:g,backgroundColor:T,..._}=l.attrs||{},w={..._};d>1&&(w.colspan=d),p>1&&(w.rowspan=p);const A=[];return g&&A.push(`width: ${g}px;`),T&&A.push(`background-color: ${T};`),A.length>0&&(w.style=A.join(" ")),h.render("th",O(w),l.children)},Z=new Map([[k.DOCUMENT,i("")],[k.HEADING,m],[k.PARAGRAPH,i("p")],[k.UL_LIST,i("ul")],[k.OL_LIST,i("ol")],[k.LIST_ITEM,i("li")],[k.IMAGE,u],[k.EMOJI,y],[k.CODE_BLOCK,E],[k.HR,i("hr")],[k.BR,i("br")],[k.QUOTE,i("blockquote")],[k.COMPONENT,je],[x.TEXT,P],[R.LINK,Q],[R.ANCHOR,Q],[R.STYLED,$("span",!0)],[R.BOLD,$("strong")],[R.TEXT_STYLE,$("span",!0)],[R.ITALIC,$("em")],[R.UNDERLINE,$("u")],[R.STRIKE,$("s")],[R.CODE,$("code")],[R.SUPERSCRIPT,$("sup")],[R.SUBSCRIPT,$("sub")],[R.HIGHLIGHT,$("mark")],[k.TABLE,Pe],[k.TABLE_ROW,Ne],[k.TABLE_CELL,xe],[k.TABLE_HEADER,De]]),ee=new Map([...Z,...Object.entries(r).map(([l,h])=>[l,h])]),Be=()=>({render:(l,h={},d)=>{if(a&&l){const p=e.get(l)||0;e.set(l,p+1),h.key=`${l}-${p}`}return t(l,h,d)},originalResolvers:Z,mergedResolvers:ee});function N(l){const h=ee.get(l.type);if(!h)return console.error("<Storyblok>",`No resolver found for node type ${l.type}`),"";const d=Be();if(l.type==="text")return h(l,d);const p=l.content?l.content.map(M):void 0;return h({...l,children:p},d)}function M(l){return l.type==="doc"?c?l.content.map(N):l.content.map(N).join(""):Array.isArray(l)?l.map(N):N(l)}return{render:M}}let V=!1;const z=[],ie=s=>new Promise((e,t)=>{if(typeof window>"u"){t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));return}if(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}V?r():z.push(r)},document.getElementById("storyblok-javascript-bridge")){e(void 0);return}const o=document.createElement("script");o.async=!0,o.src=s,o.id="storyblok-javascript-bridge",o.onerror=r=>t(r),o.onload=r=>{z.forEach(n=>n()),V=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(o)});var ae=Object.defineProperty,le=(s,e,t)=>e in s?ae(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,b=(s,e,t)=>le(s,typeof e!="symbol"?e+"":e,t);class ce extends Error{constructor(e){super(e),this.name="AbortError"}}function ue(s,e,t){if(!Number.isFinite(e))throw new TypeError("Expected `limit` to be a finite number");if(!Number.isFinite(t))throw new TypeError("Expected `interval` to be a finite number");const o=[];let r=[],n=0,a=!1;const c=async()=>{n++;const u=o.shift();if(u)try{const y=await s(...u.args);u.resolve(y)}catch(y){u.reject(y)}const m=setTimeout(()=>{n--,o.length>0&&c(),r=r.filter(y=>y!==m)},t);r.includes(m)||r.push(m)},i=(...u)=>a?Promise.reject(new Error("Throttled function is already aborted and not accepting new promises")):new Promise((m,y)=>{o.push({resolve:m,reject:y,args:u}),n<e&&c()});return i.abort=()=>{a=!0,r.forEach(clearTimeout),r=[],o.forEach(u=>u.reject(()=>new ce("Throttle function aborted"))),o.length=0},i}const he=(s="")=>s.includes("/cdn/"),de=(s,e=25,t=1)=>({...s,per_page:e,page:t}),pe=s=>new Promise(e=>setTimeout(e,s)),fe=(s=0,e)=>Array.from({length:s},e),me=(s=0,e=s)=>{const t=Math.abs(e-s)||0,o=s<e?1:-1;return fe(t,(r,n)=>n*o+s)},ye=async(s,e)=>Promise.all(s.map(e)),be=(s=[],e)=>s.map(e).reduce((t,o)=>[...t,...o],[]),B=(s,e,t)=>{const o=[];for(const r in s){if(!Object.prototype.hasOwnProperty.call(s,r))continue;const n=s[r];if(n==null)continue;const a=t?"":encodeURIComponent(r);let c;typeof n=="object"?c=B(n,e?e+encodeURIComponent(`[${a}]`):a,Array.isArray(n)):c=`${e?e+encodeURIComponent(`[${a}]`):a}=${encodeURIComponent(n)}`,o.push(c)}return o.join("&")},q=s=>{const e={eu:"api.storyblok.com",us:"api-us.storyblok.com",cn:"app.storyblokchina.cn",ap:"api-ap.storyblok.com",ca:"api-ca.storyblok.com"};return e[s]??e.eu};class ke{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=[],o={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{o.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return o.headers={...t},o.status=e.status,o.statusText=e.statusText,o}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,o=null;e==="get"?t=`${this.baseURL}${this.url}?${B(this.parameters)}`:o=JSON.stringify(this.parameters);const r=new URL(t),n=new AbortController,{signal:a}=n;let c;this.timeout&&(c=setTimeout(()=>n.abort(),this.timeout));try{const i=await this.fetch(`${r}`,{method:e,headers:this.headers,body:o,signal:a,...this.fetchOptions});this.timeout&&clearTimeout(c);const u=await this._responseHandler(i);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(u)):this._statusHandler(u)}catch(i){return{message:i}}}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((o,r)=>{if(t.test(`${e.status}`))return o(e);const n={message:this._normalizeErrorMessage(e.data),status:e.status,response:e};r(n)})}}const G="SB-Agent",H={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"},ge={DRAFT:"draft"};let j={};const S={};class ve{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 o=e.endpoint||t;if(!o){const a=e.https===!1?"http":"https";e.oauthToken?o=`${a}://${q(e.region)}/v1`:o=`${a}://${q(e.region)}/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([a,c])=>{r.set(a,c)}),r.has(G)||(r.set(G,H.defaultAgentName),r.set(H.defaultAgentVersion,H.packageVersion));let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ue(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||ge.DRAFT,this.inlineAssets=e.inlineAssets||!1,this.client=new ke({baseURL:o,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=S[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 he(e)?this.parseParams(t):t}makeRequest(e,t,o,r,n){const a=this.factoryParamOptions(e,de(t,o,r));return this.cacheResponse(e,a,void 0,n)}get(e,t={},o){t||(t={});const r=`/${e}`;t.version=t.version||this.version;const n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n,void 0,o)}async getAll(e,t={},o,r){const n=(t==null?void 0:t.per_page)||25,a=`/${e}`.replace(/\/$/,""),c=o??a.substring(a.lastIndexOf("/")+1);t.version=t.version||this.version;const i=1,u=await this.makeRequest(a,t,n,i,r),m=u.total?Math.ceil(u.total/n):1,y=await ye(me(i,m),E=>this.makeRequest(a,t,n,E+1,r));return be([u,...y],E=>Object.values(E.data[c]))}post(e,t={},o){const r=`/${e}`;return this.throttle("post",r,t,o)}put(e,t={},o){const r=`/${e}`;return this.throttle("put",r,t,o)}delete(e,t={},o){t||(t={});const r=`/${e}`;return this.throttle("delete",r,t,o)}getStories(e={},t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t={},o){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,o)}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,o){const r=e[t];r&&r.fieldtype==="multilink"&&r.linktype==="story"&&typeof r.id=="string"&&this.links[o][r.id]?r.story=this._cleanCopy(this.links[o][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[o][r.uuid]&&(r.story=this._cleanCopy(this.links[o][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,o){const r=e[t];typeof r=="string"?e[t]=this.getStoryReference(o,r):Array.isArray(r)&&(e[t]=r.map(n=>this.getStoryReference(o,n)).filter(Boolean))}_insertRelations(e,t,o,r){if(Array.isArray(o)?o.find(a=>a.endsWith(`.${t}`)):o.endsWith(`.${t}`)){this._resolveField(e,t,r);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(o)?o.includes(n):o===n)&&this._resolveField(e,t,r)}iterateTree(e,t,o){const r=(n,a="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((c,i)=>r(c,`${a}[${i}]`));else if(typeof n=="object")for(const c in n){const i=a?`${a}.${c}`:c;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,c,t,o),this._insertLinks(n,c,o)),r(n[c],i)}}};r(e.content)}async resolveLinks(e,t,o){let r=[];if(e.link_uuids){const n=e.link_uuids.length,a=[],c=50;for(let i=0;i<n;i+=c){const u=Math.min(n,i+c);a.push(e.link_uuids.slice(i,u))}for(let i=0;i<a.length;i++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:a[i].join(",")})).data.stories.forEach(u=>{r.push(u)})}else r=e.links;r.forEach(n=>{this.links[o][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,o){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,a=[],c=50;for(let i=0;i<n;i+=c){const u=Math.min(n,i+c);a.push(e.rel_uuids.slice(i,u))}for(let i=0;i<a.length;i++)(await this.getStories({per_page:c,language:t.language,version:t.version,starts_with:t.starts_with,by_uuids:a[i].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(u=>{r.push(u)});r.length>0&&(e.rels=r,delete e.rel_uuids)}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[o][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,o){var r,n;let a=[];if(this.links[o]={},this.relations[o]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(a=t.resolve_relations.split(",")),await this.resolveRelations(e,t,o)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((r=e.links)!=null&&r.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,o),this.resolveNestedRelations)for(const c in this.relations[o])this.iterateTree(this.relations[o][c],a,o);e.story?this.iterateTree(e.story,a,o):e.stories.forEach(c=>{this.iterateTree(c,a,o)}),this.stringifiedStoriesCache={},delete this.links[o],delete this.relations[o]}async cacheResponse(e,t,o,r){const n=B({url:e,params:t}),a=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const c=await a.get(n);if(c)return Promise.resolve(c)}return new Promise(async(c,i)=>{var u;try{const m=await this.throttle("get",e,t,r);if(m.status!==200)return i(m);let y={data:m.data,headers:m.headers};if((u=m.headers)!=null&&u["per-page"]&&(y=Object.assign({},y,{perPage:m.headers["per-page"]?Number.parseInt(m.headers["per-page"]):0,total:m.headers["per-page"]?Number.parseInt(m.headers.total):0})),y.data.story||y.data.stories){const $=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(y.data,t,`${$}`),y=await this.processInlineAssets(y)}t.version==="published"&&e!=="/cdn/spaces/me"&&await a.set(n,y);const E=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&y.data.cv&&(E&&S[t.token]&&S[t.token]!==y.data.cv&&await this.flushCache(),S[t.token]=y.data.cv),c(y)}catch(m){if(m.response&&m.status===429&&(o=typeof o>"u"?0:o+1,o<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await pe(this.retriesDelay),this.cacheResponse(e,t,o).then(c).catch(i);i(m)}})}throttledRequest(e,t,o,r){return this.client.setFetchOptions(r),this.client[e](t,o)}cacheVersions(){return S}cacheVersion(){return S[this.accessToken]}setCacheVersion(e){this.accessToken&&(S[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(S[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=o=>{if(!o||typeof o!="object")return o;if(Array.isArray(o))return o.map(n=>t(n));let r={...o};r.fieldtype==="asset"&&Array.isArray(e.data.assets)&&(r={...r,...e.data.assets.find(n=>n.id===r.id)});for(const n in r)typeof r[n]=="object"&&(r[n]=t(r[n]));return r};return e.data.story&&(e.data.story.content=t(e.data.story.content)),e.data.stories&&(e.data.stories=e.data.stories.map(o=>(o.content=t(o.content),o))),e}}const _e=(s={})=>{const{apiOptions:e}=s;if(!e||!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ve(e)}},we=s=>{if(typeof s!="object"||typeof s._editable>"u")return{};try{const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let J="https://app.storyblok.com/f/storyblok-v2-latest.js";const K=(s,e,t={})=>{var o;const r=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",n=new URL((o=window.location)==null?void 0:o.href).searchParams.get("_storyblok"),a=n!==null&&+n===s;if(!(!r||!a)){if(!s){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],c=>{var i;c&&(c.action==="input"&&((i=c.story)==null?void 0:i.id)===s?e(c.story):(c.action==="change"||c.action==="published")&&c.storyId===s&&window.location.reload())})})}},Te=(s={})=>{var e,t;const{bridge:o,accessToken:r,use:n=[],apiOptions:a={},bridgeUrl:c}=s;a.accessToken=a.accessToken||r;const i={bridge:o,apiOptions:a};let u={};n.forEach(y=>{u={...u,...y(i)}}),c&&(J=c);const m=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return o!==!1&&m&&ie(J),u};function Re(s,e){return D(e).render(s)}const U=f.defineComponent({__name:"StoryblokComponent",props:{blok:{}},setup(s,{expose:e}){const t=s,o=f.ref();e({value:o});const r=typeof f.resolveDynamicComponent(t.blok.component)!="string",n=f.inject("VueSDKOptions"),a=f.ref(t.blok.component);return!r&&n&&(n.enableFallbackComponent?(a.value=n.customFallbackComponent??"FallbackComponent",typeof f.resolveDynamicComponent(a.value)=="string"&&console.error(`Is the Fallback component "${a.value}" registered properly?`)):console.error(`Component could not be found for blok "${t.blok.component}"! Is it defined in main.ts as "app.component("${t.blok.component}", ${t.blok.component});"?`)),(c,i)=>(f.openBlock(),f.createBlock(f.resolveDynamicComponent(a.value),f.mergeProps({ref_key:"blokRef",ref:o},{...c.$props,...c.$attrs}),null,16))}}),$e=s=>{var e,t;return f.h(U,{blok:(e=s==null?void 0:s.attrs)==null?void 0:e.body[0],id:(t=s.attrs)==null?void 0:t.id},s.children)};function Y(s){const e={renderFn:f.h,textFn:f.createTextVNode,keyedResolvers:!0,resolvers:{[k.COMPONENT]:$e,...s.resolvers}};return D(e)}const W=f.defineComponent({__name:"StoryblokRichText",props:{doc:{},resolvers:{}},setup(s){const e=s,t=f.ref(),o=()=>t.value;return f.watch([()=>e.doc,()=>e.resolvers],([r,n])=>{const{render:a}=Y({resolvers:n??{}});t.value=a(r)},{immediate:!0,deep:!0}),(r,n)=>(f.openBlock(),f.createBlock(o))}}),Ae={beforeMount(s,e){if(e.value){const t=we(e.value);Object.keys(t).length>0&&(s.setAttribute("data-blok-c",t["data-blok-c"]),s.setAttribute("data-blok-uid",t["data-blok-uid"]),s.classList.add("storyblok__outline"))}}},X=s=>{console.error(`You can't use ${s} if you're not loading apiPlugin. Please provide it on StoryblokVue initialization.
|
|
8
8
|
`)};let I=null;const Ee=()=>(I||X("useStoryblokApi"),I),Se=async(s,e={},t={})=>{const o=f.ref(null);if(t.resolveRelations=t.resolveRelations??e.resolve_relations,t.resolveLinks=t.resolveLinks??e.resolve_links,f.onMounted(()=>{o.value&&o.value.id&&K(o.value.id,r=>o.value=r,t)}),I){const{data:r}=await I.get(`cdn/stories/${s}`,e);o.value=r.story}else X("useStoryblok");return o},Ce={install(s,e={}){s.directive("editable",Ae),s.component("StoryblokComponent",U),s.component("StoryblokRichText",W),e.enableFallbackComponent&&!e.customFallbackComponent&&s.component("FallbackComponent",f.defineAsyncComponent(()=>Promise.resolve().then(()=>Oe)));const{storyblokApi:t}=Te(e);I=t||null,s.provide("VueSDKOptions",e)}},Ie={class:"fallback-component"},Le={class:"component"},Oe=Object.freeze(Object.defineProperty({__proto__:null,default:((s,e)=>{const t=s.__vccOpts||s;for(const[o,r]of e)t[o]=r;return t})(f.defineComponent({__name:"FallbackComponent",props:{blok:{}},setup(s){return(e,t)=>(f.openBlock(),f.createElementBlock("div",Ie,[f.createElementVNode("p",null,[t[0]||(t[0]=f.createTextVNode(" Component could not be found for blok ")),f.createElementVNode("span",Le,f.toDisplayString(e.blok.component),1),t[1]||(t[1]=f.createTextVNode("! Is it configured correctly? "))])]))}}),[["__scopeId","data-v-9abcd1f2"]])},Symbol.toStringTag,{value:"Module"}));v.BlockTypes=k,v.MarkTypes=R,v.StoryblokComponent=U,v.StoryblokRichText=W,v.StoryblokVue=Ce,v.TextTypes=x,v.apiPlugin=_e,v.renderRichText=Re,v.richTextResolver=D,v.useStoryblok=Se,v.useStoryblokApi=Ee,v.useStoryblokBridge=K,v.useStoryblokRichText=Y,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/dist/storyblok-vue.mjs
CHANGED
|
@@ -249,14 +249,20 @@ function Z(s = {}) {
|
|
|
249
249
|
}
|
|
250
250
|
let V = !1;
|
|
251
251
|
const z = [], Te = (s) => new Promise((e, t) => {
|
|
252
|
-
if (typeof window > "u"
|
|
252
|
+
if (typeof window > "u") {
|
|
253
|
+
t(new Error("Cannot load Storyblok bridge: window is undefined (server-side environment)"));
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (window.storyblokRegisterEvent = (r) => {
|
|
253
257
|
if (window.location === window.parent.location) {
|
|
254
258
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
255
259
|
return;
|
|
256
260
|
}
|
|
257
261
|
V ? r() : z.push(r);
|
|
258
|
-
}, document.getElementById("storyblok-javascript-bridge"))
|
|
262
|
+
}, document.getElementById("storyblok-javascript-bridge")) {
|
|
263
|
+
e(void 0);
|
|
259
264
|
return;
|
|
265
|
+
}
|
|
260
266
|
const o = document.createElement("script");
|
|
261
267
|
o.async = !0, o.src = s, o.id = "storyblok-javascript-bridge", o.onerror = (r) => t(r), o.onload = (r) => {
|
|
262
268
|
z.forEach((n) => n()), V = !0, e(r);
|
|
@@ -779,6 +785,7 @@ class Ne {
|
|
|
779
785
|
case "custom":
|
|
780
786
|
if (this.cache.custom)
|
|
781
787
|
return this.cache.custom;
|
|
788
|
+
// eslint-disable-next-line no-fallthrough
|
|
782
789
|
default:
|
|
783
790
|
return {
|
|
784
791
|
get() {
|
package/package.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "9.0.
|
|
5
|
-
"packageManager": "pnpm@10.2.0",
|
|
4
|
+
"version": "9.0.3",
|
|
6
5
|
"description": "SDK to integrate Storyblok into your project using Vue.",
|
|
7
6
|
"author": "Storyblok",
|
|
8
7
|
"license": "MIT",
|
|
@@ -26,70 +25,32 @@
|
|
|
26
25
|
"files": [
|
|
27
26
|
"dist"
|
|
28
27
|
],
|
|
29
|
-
"scripts": {
|
|
30
|
-
"dev": "vite build --watch",
|
|
31
|
-
"playground": "pnpm run --filter ./playground/vue dev",
|
|
32
|
-
"test": "pnpm run test:unit:ci && pnpm run test:e2e",
|
|
33
|
-
"test:unit": "vitest",
|
|
34
|
-
"test:unit:ci": "vitest run",
|
|
35
|
-
"test:unit:ui": "vitest --ui",
|
|
36
|
-
"test:e2e": "pnpm run cy:components",
|
|
37
|
-
"build": "vite build",
|
|
38
|
-
"lint": "eslint .",
|
|
39
|
-
"lint:fix": "eslint . --fix",
|
|
40
|
-
"cy:run": "cypress run",
|
|
41
|
-
"cy:open": "cypress open",
|
|
42
|
-
"cy:components": "cypress run-ct",
|
|
43
|
-
"prepublishOnly": "pnpm build",
|
|
44
|
-
"check-licenses": "node scripts/license-checker.mjs"
|
|
45
|
-
},
|
|
46
28
|
"peerDependencies": {
|
|
47
29
|
"vue": ">=3.4"
|
|
48
30
|
},
|
|
49
31
|
"dependencies": {
|
|
50
|
-
"@storyblok/js": "4.0.
|
|
32
|
+
"@storyblok/js": "4.0.3"
|
|
51
33
|
},
|
|
52
34
|
"devDependencies": {
|
|
53
|
-
"@commitlint/cli": "^19.7.1",
|
|
54
|
-
"@commitlint/config-conventional": "^19.7.1",
|
|
55
35
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
56
36
|
"@storyblok/eslint-config": "^0.3.0",
|
|
57
|
-
"@types/node": "^22.
|
|
37
|
+
"@types/node": "^22.15.1",
|
|
58
38
|
"@typescript-eslint/parser": "^8.23.0",
|
|
59
39
|
"@vitejs/plugin-vue": "^5.2.1",
|
|
60
|
-
"cypress": "^
|
|
61
|
-
"eslint": "^9.
|
|
40
|
+
"cypress": "^14.3.3",
|
|
41
|
+
"eslint": "^9.26.0",
|
|
62
42
|
"eslint-plugin-vue": "^9.32.0",
|
|
63
43
|
"kolorist": "^1.8.0",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"typescript": "^5.7.3",
|
|
68
|
-
"vite": "^6.1.0",
|
|
44
|
+
"pathe": "^2.0.3",
|
|
45
|
+
"typescript": "5.8.3",
|
|
46
|
+
"vite": "^6.3.5",
|
|
69
47
|
"vite-plugin-banner": "^0.8.0",
|
|
70
|
-
"vite-plugin-dts": "^4.5.
|
|
71
|
-
"vitest": "^3.
|
|
48
|
+
"vite-plugin-dts": "^4.5.3",
|
|
49
|
+
"vitest": "^3.1.3",
|
|
72
50
|
"vue": "^3.5.13",
|
|
73
51
|
"vue-router": "^4.5.0",
|
|
74
52
|
"vue-tsc": "^2.2.0"
|
|
75
53
|
},
|
|
76
|
-
"pnpm": {
|
|
77
|
-
"onlyBuiltDependencies": [
|
|
78
|
-
"cypress"
|
|
79
|
-
]
|
|
80
|
-
},
|
|
81
|
-
"commitlint": {
|
|
82
|
-
"extends": [
|
|
83
|
-
"@commitlint/config-conventional"
|
|
84
|
-
],
|
|
85
|
-
"rules": {
|
|
86
|
-
"body-max-line-length": [
|
|
87
|
-
2,
|
|
88
|
-
"always",
|
|
89
|
-
200
|
|
90
|
-
]
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
54
|
"release": {
|
|
94
55
|
"branches": [
|
|
95
56
|
"main"
|
|
@@ -98,8 +59,24 @@
|
|
|
98
59
|
"publishConfig": {
|
|
99
60
|
"access": "public"
|
|
100
61
|
},
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
|
|
62
|
+
"nx": {
|
|
63
|
+
"implicitDependencies": [
|
|
64
|
+
"!@storyblok/playground-*"
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
"scripts": {
|
|
68
|
+
"dev": "vite build --watch",
|
|
69
|
+
"playground": "pnpm run --filter ./playground/vue dev",
|
|
70
|
+
"test": "pnpm run test:unit:ci && pnpm run test:e2e",
|
|
71
|
+
"test:unit": "vitest",
|
|
72
|
+
"test:unit:ci": "vitest run",
|
|
73
|
+
"test:unit:ui": "vitest --ui",
|
|
74
|
+
"test:e2e": "pnpm run cy:components",
|
|
75
|
+
"build": "vite build",
|
|
76
|
+
"lint": "eslint .",
|
|
77
|
+
"lint:fix": "eslint . --fix",
|
|
78
|
+
"cy:run": "cypress run",
|
|
79
|
+
"cy:open": "cypress open",
|
|
80
|
+
"cy:components": "cypress run --component"
|
|
104
81
|
}
|
|
105
|
-
}
|
|
82
|
+
}
|