@storyblok/astro 4.0.4-next.6 → 4.0.5-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/storyblok-astro.js
CHANGED
|
@@ -21,16 +21,16 @@
|
|
|
21
21
|
}
|
|
22
22
|
],
|
|
23
23
|
type: 'doc'
|
|
24
|
-
}`),""}optimizeImages(e,t){let s=0,r=0,i="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(i+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(i+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(i+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(i+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),i.length>0&&(e=e.replace(/<img/g,`<img ${i.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,h;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const g={srcset:(l=t.srcset)==null?void 0:l.map(f=>{if(typeof f=="number")return`//${p}/m/${f}x0${n} ${f}w`;if(typeof f=="object"&&f.length===2){let _=0,U=0;return typeof f[0]=="number"&&(_=f[0]),typeof f[1]=="number"&&(U=f[1]),`//${p}/m/${_}x${U}${n} ${_}w`}}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(f=>f).join(", ")};let m="";return g.srcset&&(m+=`srcset="${g.srcset}" `),g.sizes&&(m+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${m.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderOpeningTag(i.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ge(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderClosingTag(i.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const i in s.attrs){const n=s.attrs[i];n!==null&&(r+=` ${i}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class fe{constructor(e){u(this,"baseURL"),u(this,"timeout"),u(this,"headers"),u(this,"responseInterceptor"),u(this,"fetch"),u(this,"ejectInterceptor"),u(this,"url"),u(this,"parameters"),u(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=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const a=await fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}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}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(i)})}}var me={npm_package_version:"6.6.3"};const x="SB-Agent",T={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:me.npm_package_version};let w={};const b={};class ye{constructor(e,t){u(this,"client"),u(this,"maxRetries"),u(this,"throttle"),u(this,"accessToken"),u(this,"cache"),u(this,"helpers"),u(this,"resolveCounter"),u(this,"relations"),u(this,"links"),u(this,"richTextResolver"),u(this,"resolveNestedRelations"),u(this,"stringifiedStoriesCache");let s=e.endpoint||t;const r=new v().getRegionURL,i=e.https===!1?"http":"https";e.oauthToken?s=`${i}://${r(e.region)}/v1`:s=`${i}://${r(e.region)}/v2`;const n=new Headers;if(n.set("Content-Type","application/json"),n.set("Accept","application/json"),e.headers)for(const a in e.headers)n.set(a,e.headers[a]);n.has(x)||(n.set(x,T.defaultAgentName),n.set(T.defaultAgentVersion,T.packageVersion));let c=5;e.oauthToken&&(n.set("Authorization",e.oauthToken),c=3),e.rateLimit&&(c=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=H(this.throttledRequest,c,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new fe({baseURL:s,timeout:e.timeout||0,headers:n,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=b[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,i)}get(e,t,s){t||(t={});const r=`/${e}`,i=this.factoryParamOptions(r,t);return this.client.setFetchOptions(s),this.cacheResponse(r,i)}async getAll(e,t,s,r){const i=(t==null?void 0:t.per_page)||25,n=`/${e}`,c=n.split("/"),a=s||c[c.length-1],l=1,h=await this.makeRequest(n,t,i,l),p=h.total?Math.ceil(h.total/i):1;this.client.setFetchOptions(r);const g=await this.helpers.asyncMap(this.helpers.range(l,p),m=>this.makeRequest(n,t,i,m+1));return this.helpers.flatMap([h,...g],m=>Object.values(m.data[a]))}post(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("post",r,t))}put(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("put",r,t))}delete(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("delete",r,t))}getStories(e,t){return this.client.setFetchOptions(t),this.get("cdn/stories",e)}getStory(e,t,s){return this.client.setFetchOptions(s),this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(i=>this.getStoryReference(r,i)).filter(Boolean)))}iterateTree(e,t,s){const r=i=>{if(i!=null){if(i.constructor===Array)for(let n=0;n<i.length;n++)r(i[n]);else if(i.constructor===Object){if(i._stopResolving)return;for(const n in i)(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,n,t,s),this._insertLinks(i,n,s)),r(i[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,n=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var r,i;let n=[];if(this.links[s]={},this.relations[s]={},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,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(i=e.link_uuids)!=null&&i.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const n=await i.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let h={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(h=Object.assign({},h,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),h.data.story||h.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(h.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await i.set(r,h),h.data.cv&&t.token&&(t.version==="draft"&&b[t.token]!=h.data.cv&&await this.flushCache(),b[t.token]=t.cv?t.cv:h.data.cv),n(h)}catch(l){if(l.response&&l.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return b}cacheVersion(){return b[this.accessToken]}setCacheVersion(e){this.accessToken&&(b[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(w[e])},getAll(){return Promise.resolve(w)},set(e,t){return w[e]=t,Promise.resolve(void 0)},flush(){return w={},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}}const be=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new ye(e)}},ke=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};try{const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}}catch{return{}}};let $,R="https://app.storyblok.com/f/storyblok-v2-latest.js";const ve=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:i=[],apiOptions:n={},richText:c={},bridgeUrl:a}=o;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let h={};i.forEach(g=>{h={...h,...g(l)}}),a&&(R=a);const p=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&p&&A(R),$=new k(c.schema),c.resolver&&j($,c.resolver),h},j=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},we=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),Te=(o,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return we(o)?"":(e&&(s=new k(e.schema),e.resolver&&j(s,e.resolver)),s.render(o))},$e=()=>A(R);function Re(o,e,t){const s="virtual:storyblok-init",r="\0"+s;return globalThis.apiPlugin=be,globalThis.storyblokInit=ve,{name:"vite-plugin-storyblok-init",async resolveId(i){if(i===s)return r},async load(i){if(i===r)return`
|
|
24
|
+
}`),""}optimizeImages(e,t){let s=0,r=0,i="",n="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(i+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(i+=`height="${t.height}" `,r=t.height),(t.loading==="lazy"||t.loading==="eager")&&(i+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(i+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(n+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(n+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-Fa-f]{6}/g)||t.filters.fill==="transparent")&&(n+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(n+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(n+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(n+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(n+=`:rotate(${t.filters.rotate})`),n.length>0&&(n="/filters"+n))),i.length>0&&(e=e.replace(/<img/g,`<img ${i.trim()}`));const c=s>0||r>0||n.length>0?`${s}x${r}${n}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${c}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,a=>{var l,h;const p=a.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g);if(p&&p.length>0){const g={srcset:(l=t.srcset)==null?void 0:l.map(f=>{if(typeof f=="number")return`//${p}/m/${f}x0${n} ${f}w`;if(typeof f=="object"&&f.length===2){let I=0,U=0;return typeof f[0]=="number"&&(I=f[0]),typeof f[1]=="number"&&(U=f[1]),`//${p}/m/${I}x${U}${n} ${I}w`}}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(f=>f).join(", ")};let m="";return g.srcset&&(m+=`srcset="${g.srcset}" `),g.sizes&&(m+=`sizes="${g.sizes}" `),a.replace(/<img/g,`<img ${m.trim()}`)}return a})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderOpeningTag(i.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(ge(e.text)):s&&s.singleTag?t.push(this.renderTag(s.singleTag," /")):s&&s.html?t.push(s.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),s&&s.tag&&t.push(this.renderClosingTag(s.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const i=this.getMatchingMark(r);i&&i.tag!==""&&t.push(this.renderClosingTag(i.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let r=`<${s.tag}`;if(s.attrs)for(const i in s.attrs){const n=s.attrs[i];n!==null&&(r+=` ${i}="${n}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}renderEmoji(e){if(e.attrs.emoji)return e.attrs.emoji;const t=[{tag:"img",attrs:{src:e.attrs.fallbackImage,draggable:"false",loading:"lazy",align:"absmiddle"}}];return this.renderTag(t," /")}}class fe{constructor(e){u(this,"baseURL"),u(this,"timeout"),u(this,"headers"),u(this,"responseInterceptor"),u(this,"fetch"),u(this,"ejectInterceptor"),u(this,"url"),u(this,"parameters"),u(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=[],s={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{s.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const a=new v;t=`${this.baseURL}${this.url}?${a.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const r=new URL(t),i=new AbortController,{signal:n}=i;let c;this.timeout&&(c=setTimeout(()=>i.abort(),this.timeout));try{const a=await this.fetch(`${r}`,{method:e,headers:this.headers,body:s,signal:n,...this.fetchOptions});this.timeout&&clearTimeout(c);const l=await this._responseHandler(a);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}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}_statusHandler(e){const t=/20[0-6]/g;return new Promise((s,r)=>{if(t.test(`${e.status}`))return s(e);const i={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};r(i)})}}const x="SB-Agent",T={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let w={};const b={};class me{constructor(e,t){u(this,"client"),u(this,"maxRetries"),u(this,"throttle"),u(this,"accessToken"),u(this,"cache"),u(this,"helpers"),u(this,"resolveCounter"),u(this,"relations"),u(this,"links"),u(this,"richTextResolver"),u(this,"resolveNestedRelations"),u(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const n=new v().getRegionURL,c=e.https===!1?"http":"https";e.oauthToken?s=`${c}://${n(e.region)}/v1`:s=`${c}://${n(e.region)}/v2`}const r=new Headers;if(r.set("Content-Type","application/json"),r.set("Accept","application/json"),e.headers)for(const n in e.headers)r.set(n,e.headers[n]);r.has(x)||(r.set(x,T.defaultAgentName),r.set(T.defaultAgentVersion,T.packageVersion));let i=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),i=3),e.rateLimit&&(i=e.rateLimit),e.richTextSchema?this.richTextResolver=new k(e.richTextSchema):this.richTextResolver=new k,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=H(this.throttledRequest,i,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new v,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new fe({baseURL:s,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})}parseParams(e){return e.token||(e.token=this.getToken()),e.cv||(e.cv=b[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 this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,r){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,r));return this.cacheResponse(e,i)}get(e,t,s){t||(t={});const r=`/${e}`,i=this.factoryParamOptions(r,t);return this.client.setFetchOptions(s),this.cacheResponse(r,i)}async getAll(e,t,s,r){const i=(t==null?void 0:t.per_page)||25,n=`/${e}`,c=n.split("/"),a=s||c[c.length-1],l=1,h=await this.makeRequest(n,t,i,l),p=h.total?Math.ceil(h.total/i):1;this.client.setFetchOptions(r);const g=await this.helpers.asyncMap(this.helpers.range(l,p),m=>this.makeRequest(n,t,i,m+1));return this.helpers.flatMap([h,...g],m=>Object.values(m.data[a]))}post(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("post",r,t))}put(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("put",r,t))}delete(e,t,s){const r=`/${e}`;return this.client.setFetchOptions(s),Promise.resolve(this.throttle("delete",r,t))}getStories(e,t){return this.client.setFetchOptions(t),this._addResolveLevel(e),this.get("cdn/stories",e)}getStory(e,t,s){return this.client.setFetchOptions(s),this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t)}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,s){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[s][r.id]?r.story=this._cleanCopy(this.links[s][r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[s][r.uuid]&&(r.story=this._cleanCopy(this.links[s][r.uuid]))}getStoryReference(e,t){return this.relations[e][t]?(this.stringifiedStoriesCache[t]||(this.stringifiedStoriesCache[t]=JSON.stringify(this.relations[e][t])),JSON.parse(this.stringifiedStoriesCache[t])):t}_insertRelations(e,t,s,r){s.indexOf(`${e.component}.${t}`)>-1&&(typeof e[t]=="string"?e[t]=this.getStoryReference(r,e[t]):Array.isArray(e[t])&&(e[t]=e[t].map(i=>this.getStoryReference(r,i)).filter(Boolean)))}iterateTree(e,t,s){const r=i=>{if(i!=null){if(i.constructor===Array)for(let n=0;n<i.length;n++)r(i[n]);else if(i.constructor===Object){if(i._stopResolving)return;for(const n in i)(i.component&&i._uid||i.type==="link")&&(this._insertRelations(i,n,t,s),this._insertLinks(i,n,s)),r(i[n])}}};r(e.content)}async resolveLinks(e,t,s){let r=[];if(e.link_uuids){const i=e.link_uuids.length,n=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);n.push(e.link_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(l=>{r.push(l)})}else r=e.links;r.forEach(i=>{this.links[s][i.uuid]={...i,_stopResolving:!0}})}async resolveRelations(e,t,s){let r=[];if(e.rel_uuids){const i=e.rel_uuids.length,n=[],c=50;for(let a=0;a<i;a+=c){const l=Math.min(i,a+c);n.push(e.rel_uuids.slice(a,l))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:c,language:t.language,version:t.version,by_uuids:n[a].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(l=>{r.push(l)})}else r=e.rels;r&&r.length>0&&r.forEach(i=>{this.relations[s][i.uuid]={...i,_stopResolving:!0}})}async resolveStories(e,t,s){var r,i;let n=[];if(this.links[s]={},this.relations[s]={},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,s)),t.resolve_links&&["1","story","url","link"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(i=e.link_uuids)!=null&&i.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const c in this.relations[s])this.iterateTree(this.relations[s][c],n,s);e.story?this.iterateTree(e.story,n,s):e.stories.forEach(c=>{this.iterateTree(c,n,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s){(typeof s>"u"||!s)&&(s=0);const r=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const n=await i.get(r);if(n)return Promise.resolve(n)}return new Promise(async(n,c)=>{var a;try{const l=await this.throttle("get",e,t);if(l.status!==200)return c(l);let h={data:l.data,headers:l.headers};if((a=l.headers)!=null&&a["per-page"]&&(h=Object.assign({},h,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),h.data.story||h.data.stories){const p=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(h.data,t,`${p}`)}return t.version==="published"&&e!="/cdn/spaces/me"&&await i.set(r,h),h.data.cv&&t.token&&(t.version==="draft"&&b[t.token]!=h.data.cv&&await this.flushCache(),b[t.token]=t.cv?t.cv:h.data.cv),n(h)}catch(l){if(l.response&&l.status===429&&(s=s?s+1:0,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${s} seconds.`),await this.helpers.delay(1e3*s),this.cacheResponse(e,t,s).then(n).catch(c);c(l)}})}throttledRequest(e,t,s){return this.client[e](t,s)}cacheVersions(){return b}cacheVersion(){return b[this.accessToken]}setCacheVersion(e){this.accessToken&&(b[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(w[e])},getAll(){return Promise.resolve(w)},set(e,t){return w[e]=t,Promise.resolve(void 0)},flush(){return w={},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}}const ye=(o={})=>{const{apiOptions:e}=o;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new me(e)}},be=o=>{if(typeof o!="object"||typeof o._editable>"u")return{};try{const e=JSON.parse(o._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}:{}}catch{return{}}};let $,R="https://app.storyblok.com/f/storyblok-v2-latest.js";const ke=(o={})=>{var e,t;const{bridge:s,accessToken:r,use:i=[],apiOptions:n={},richText:c={},bridgeUrl:a}=o;n.accessToken=n.accessToken||r;const l={bridge:s,apiOptions:n};let h={};i.forEach(g=>{h={...h,...g(l)}}),a&&(R=a);const p=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&p&&A(R),$=new k(c.schema),c.resolver&&j($,c.resolver),h},j=(o,e)=>{o.addNode("blok",t=>{let s="";return t.attrs.body.forEach(r=>{s+=e(r.component,r)}),{html:s}})},ve=o=>!o||!(o!=null&&o.content.some(e=>e.content||e.type==="blok"||e.type==="horizontal_rule")),we=(o,e,t)=>{let s=t||$;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ve(o)?"":(e&&(s=new k(e.schema),e.resolver&&j(s,e.resolver)),s.render(o))},Te=()=>A(R);function $e(o,e,t){const s="virtual:storyblok-init",r="\0"+s;return globalThis.apiPlugin=ye,globalThis.storyblokInit=ke,{name:"vite-plugin-storyblok-init",async resolveId(i){if(i===s)return r},async load(i){if(i===r)return`
|
|
25
25
|
const { storyblokApi } = globalThis.storyblokInit({
|
|
26
26
|
accessToken: "${o}",
|
|
27
27
|
use: ${e?"[]":"[globalThis.apiPlugin]"},
|
|
28
28
|
apiOptions: ${JSON.stringify(t)},
|
|
29
29
|
});
|
|
30
30
|
export const storyblokApiInstance = storyblokApi;
|
|
31
|
-
`}}}const
|
|
31
|
+
`}}}const Re=/[\p{Lu}]/u,_e=/[\p{Ll}]/u,E=/^[\p{Lu}](?![\p{Lu}])/gu,P=/([\p{Alpha}\p{N}_]|$)/u,_=/[_.\- ]+/,Ie=new RegExp("^"+_.source),L=new RegExp(_.source+P.source,"gu"),N=new RegExp("\\d+"+P.source,"gu"),Se=(o,e,t,s)=>{let r=!1,i=!1,n=!1,c=!1;for(let a=0;a<o.length;a++){const l=o[a];c=a>2?o[a-3]==="-":!0,r&&Re.test(l)?(o=o.slice(0,a)+"-"+o.slice(a),r=!1,n=i,i=!0,a++):i&&n&&_e.test(l)&&(!c||s)?(o=o.slice(0,a-1)+"-"+o.slice(a-1),n=i,i=!1,r=!0):(r=e(l)===l&&t(l)!==l,n=i,i=t(l)===l&&e(l)!==l)}return o},Ae=(o,e)=>(E.lastIndex=0,o.replaceAll(E,t=>e(t))),Ce=(o,e)=>(L.lastIndex=0,N.lastIndex=0,o.replaceAll(N,(t,s,r)=>["_","-"].includes(o.charAt(r+t.length))?t:e(t)).replaceAll(L,(t,s)=>e(s)));function M(o,e){if(!(typeof o=="string"||Array.isArray(o)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(o)?o=o.map(i=>i.trim()).filter(i=>i.length).join("-"):o=o.trim(),o.length===0)return"";const t=e.locale===!1?i=>i.toLowerCase():i=>i.toLocaleLowerCase(e.locale),s=e.locale===!1?i=>i.toUpperCase():i=>i.toLocaleUpperCase(e.locale);return o.length===1?_.test(o)?"":e.pascalCase?s(o):t(o):(o!==t(o)&&(o=Se(o,t,s,e.preserveConsecutiveUppercase)),o=o.replace(Ie,""),o=e.preserveConsecutiveUppercase?Ae(o,t):t(o),e.pascalCase&&(o=s(o.charAt(0))+o.slice(1)),Ce(o,s))}function Oe(o,e,t,s){const r="virtual:storyblok-components",i="\0"+r;return{name:"vite-plugin-storyblok-components",async resolveId(n){if(n===r)return i},async load(n){if(n===i){const c=[],a=[];for await(const[h,p]of Object.entries(e)){const g=await this.resolve("/"+o+"/"+p+".astro");if(g)c.push(`import ${M(h)} from "${g.id}"`);else if(t)a.push(h);else throw new Error(`Component could not be found for blok "${h}"! Does "${"/"+o+"/"+p}.astro" exist?`)}let l="";if(t)if(l=",FallbackComponent",s){const h=await this.resolve("/"+o+"/"+s+".astro");if(!h)throw new Error(`Custom fallback component could not be found. Does "${"/"+o+"/"+s}.astro" exist?`);c.push(`import FallbackComponent from "${h.id}"`)}else c.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(e).length)return`${c.join(";")};export default {${Object.keys(e).filter(h=>!a.includes(h)).map(h=>M(h)).join(",")}${l}}`;if(t)return`${c[0]}; export default {${l.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
32
32
|
Please register your components or enable the fallback component.
|
|
33
|
-
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function
|
|
33
|
+
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function xe(o){const e="virtual:storyblok-options",t="\0"+e;return{name:"vite-plugin-storyblok-options",async resolveId(s){if(s===e)return t},async load(s){if(s===t)return`export default ${JSON.stringify(o)}`}}}function je(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function Ee(o,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return we(o,e,t)}function Pe(o){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,...o};return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:s,addDevToolbarApp:r})=>{if(s({vite:{plugins:[$e(e.accessToken,e.useCustomApi,e.apiOptions),Oe(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),xe(e)]}}),t("page-ssr",`
|
|
34
34
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
35
35
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
36
36
|
`),e.bridge){let i="";if(typeof e.bridge=="object"){const n={...e.bridge};i=`const storyblokInstance = new StoryblokBridge(${JSON.stringify(n)});`}else i="const storyblokInstance = new StoryblokBridge()";t("page",`
|
|
@@ -45,4 +45,4 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
|
-
`)}r("@storyblok/astro/toolbar-app-storyblok.ts")}}}}d.RichTextResolver=k,d.RichTextSchema=O,d.default=
|
|
48
|
+
`)}r("@storyblok/astro/toolbar-app-storyblok.ts")}}}}d.RichTextResolver=k,d.RichTextSchema=O,d.default=Pe,d.loadStoryblokBridge=Te,d.renderRichText=Ee,d.storyblokEditable=be,d.useStoryblokApi=je,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-astro.mjs
CHANGED
|
@@ -271,7 +271,7 @@ const F = function(o, e) {
|
|
|
271
271
|
highlight: he,
|
|
272
272
|
textStyle: ue
|
|
273
273
|
}
|
|
274
|
-
},
|
|
274
|
+
}, de = function(o) {
|
|
275
275
|
const e = {
|
|
276
276
|
"&": "&",
|
|
277
277
|
"<": "<",
|
|
@@ -338,19 +338,19 @@ class k {
|
|
|
338
338
|
/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|tiff|bmp)/g
|
|
339
339
|
);
|
|
340
340
|
if (p && p.length > 0) {
|
|
341
|
-
const
|
|
342
|
-
srcset: (l = t.srcset) == null ? void 0 : l.map((
|
|
343
|
-
if (typeof
|
|
344
|
-
return `//${p}/m/${
|
|
345
|
-
if (typeof
|
|
341
|
+
const d = {
|
|
342
|
+
srcset: (l = t.srcset) == null ? void 0 : l.map((g) => {
|
|
343
|
+
if (typeof g == "number")
|
|
344
|
+
return `//${p}/m/${g}x0${n} ${g}w`;
|
|
345
|
+
if (typeof g == "object" && g.length === 2) {
|
|
346
346
|
let v = 0, I = 0;
|
|
347
|
-
return typeof
|
|
347
|
+
return typeof g[0] == "number" && (v = g[0]), typeof g[1] == "number" && (I = g[1]), `//${p}/m/${v}x${I}${n} ${v}w`;
|
|
348
348
|
}
|
|
349
349
|
}).join(", "),
|
|
350
|
-
sizes: (h = t.sizes) == null ? void 0 : h.map((
|
|
350
|
+
sizes: (h = t.sizes) == null ? void 0 : h.map((g) => g).join(", ")
|
|
351
351
|
};
|
|
352
352
|
let f = "";
|
|
353
|
-
return
|
|
353
|
+
return d.srcset && (f += `srcset="${d.srcset}" `), d.sizes && (f += `sizes="${d.sizes}" `), a.replace(/<img/g, `<img ${f.trim()}`);
|
|
354
354
|
}
|
|
355
355
|
return a;
|
|
356
356
|
})), e;
|
|
@@ -364,7 +364,7 @@ class k {
|
|
|
364
364
|
const s = this.getMatchingNode(e);
|
|
365
365
|
return s && s.tag && t.push(this.renderOpeningTag(s.tag)), e.content ? e.content.forEach((r) => {
|
|
366
366
|
t.push(this.renderNode(r));
|
|
367
|
-
}) : e.text ? t.push(
|
|
367
|
+
}) : e.text ? t.push(de(e.text)) : s && s.singleTag ? t.push(this.renderTag(s.singleTag, " /")) : s && s.html ? t.push(s.html) : e.type === "emoji" && t.push(this.renderEmoji(e)), s && s.tag && t.push(this.renderClosingTag(s.tag)), e.marks && e.marks.slice(0).reverse().forEach((r) => {
|
|
368
368
|
const i = this.getMatchingMark(r);
|
|
369
369
|
i && i.tag !== "" && t.push(this.renderClosingTag(i.tag));
|
|
370
370
|
}), t.join("");
|
|
@@ -417,7 +417,7 @@ class k {
|
|
|
417
417
|
return this.renderTag(t, " /");
|
|
418
418
|
}
|
|
419
419
|
}
|
|
420
|
-
class
|
|
420
|
+
class ge {
|
|
421
421
|
constructor(e) {
|
|
422
422
|
u(this, "baseURL"), u(this, "timeout"), u(this, "headers"), u(this, "responseInterceptor"), u(this, "fetch"), u(this, "ejectInterceptor"), u(this, "url"), u(this, "parameters"), u(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 = {};
|
|
423
423
|
}
|
|
@@ -466,7 +466,7 @@ class de {
|
|
|
466
466
|
let c;
|
|
467
467
|
this.timeout && (c = setTimeout(() => i.abort(), this.timeout));
|
|
468
468
|
try {
|
|
469
|
-
const a = await fetch(`${r}`, {
|
|
469
|
+
const a = await this.fetch(`${r}`, {
|
|
470
470
|
method: e,
|
|
471
471
|
headers: this.headers,
|
|
472
472
|
body: s,
|
|
@@ -504,15 +504,14 @@ class de {
|
|
|
504
504
|
});
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
|
-
var fe = { npm_package_version: "6.6.3" };
|
|
508
507
|
const S = "SB-Agent", w = {
|
|
509
508
|
defaultAgentName: "SB-JS-CLIENT",
|
|
510
509
|
defaultAgentVersion: "SB-Agent-Version",
|
|
511
|
-
packageVersion:
|
|
510
|
+
packageVersion: "6.0.0"
|
|
512
511
|
};
|
|
513
512
|
let y = {};
|
|
514
513
|
const m = {};
|
|
515
|
-
class
|
|
514
|
+
class fe {
|
|
516
515
|
/**
|
|
517
516
|
*
|
|
518
517
|
* @param config ISbConfig interface
|
|
@@ -521,21 +520,23 @@ class me {
|
|
|
521
520
|
constructor(e, t) {
|
|
522
521
|
u(this, "client"), u(this, "maxRetries"), u(this, "throttle"), u(this, "accessToken"), u(this, "cache"), u(this, "helpers"), u(this, "resolveCounter"), u(this, "relations"), u(this, "links"), u(this, "richTextResolver"), u(this, "resolveNestedRelations"), u(this, "stringifiedStoriesCache");
|
|
523
522
|
let s = e.endpoint || t;
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
523
|
+
if (!s) {
|
|
524
|
+
const n = new b().getRegionURL, c = e.https === !1 ? "http" : "https";
|
|
525
|
+
e.oauthToken ? s = `${c}://${n(e.region)}/v1` : s = `${c}://${n(e.region)}/v2`;
|
|
526
|
+
}
|
|
527
|
+
const r = new Headers();
|
|
528
|
+
if (r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), e.headers)
|
|
529
|
+
for (const n in e.headers)
|
|
530
|
+
r.set(n, e.headers[n]);
|
|
531
|
+
r.has(S) || (r.set(S, w.defaultAgentName), r.set(
|
|
531
532
|
w.defaultAgentVersion,
|
|
532
533
|
w.packageVersion
|
|
533
534
|
));
|
|
534
|
-
let
|
|
535
|
-
e.oauthToken && (
|
|
535
|
+
let i = 5;
|
|
536
|
+
e.oauthToken && (r.set("Authorization", e.oauthToken), i = 3), e.rateLimit && (i = e.rateLimit), e.richTextSchema ? this.richTextResolver = new k(e.richTextSchema) : this.richTextResolver = new k(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = z(this.throttledRequest, i, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new b(), this.resolveCounter = 0, this.resolveNestedRelations = e.resolveNestedRelations || !0, this.stringifiedStoriesCache = {}, this.client = new ge({
|
|
536
537
|
baseURL: s,
|
|
537
538
|
timeout: e.timeout || 0,
|
|
538
|
-
headers:
|
|
539
|
+
headers: r,
|
|
539
540
|
responseInterceptor: e.responseInterceptor,
|
|
540
541
|
fetch: e.fetch
|
|
541
542
|
});
|
|
@@ -551,7 +552,7 @@ class me {
|
|
|
551
552
|
});
|
|
552
553
|
}
|
|
553
554
|
parseParams(e) {
|
|
554
|
-
return e.token || (e.token = this.getToken()), e.cv || (e.cv = m[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
|
|
555
|
+
return e.token || (e.token = this.getToken()), e.cv || (e.cv = m[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), typeof e.resolve_relations < "u" && (e.resolve_level = 2), e;
|
|
555
556
|
}
|
|
556
557
|
factoryParamOptions(e, t) {
|
|
557
558
|
return this.helpers.isCDNUrl(e) ? this.parseParams(t) : t;
|
|
@@ -571,12 +572,12 @@ class me {
|
|
|
571
572
|
async getAll(e, t, s, r) {
|
|
572
573
|
const i = (t == null ? void 0 : t.per_page) || 25, n = `/${e}`, c = n.split("/"), a = s || c[c.length - 1], l = 1, h = await this.makeRequest(n, t, i, l), p = h.total ? Math.ceil(h.total / i) : 1;
|
|
573
574
|
this.client.setFetchOptions(r);
|
|
574
|
-
const
|
|
575
|
+
const d = await this.helpers.asyncMap(
|
|
575
576
|
this.helpers.range(l, p),
|
|
576
577
|
(f) => this.makeRequest(n, t, i, f + 1)
|
|
577
578
|
);
|
|
578
579
|
return this.helpers.flatMap(
|
|
579
|
-
[h, ...
|
|
580
|
+
[h, ...d],
|
|
580
581
|
(f) => Object.values(f.data[a])
|
|
581
582
|
);
|
|
582
583
|
}
|
|
@@ -593,10 +594,10 @@ class me {
|
|
|
593
594
|
return this.client.setFetchOptions(s), Promise.resolve(this.throttle("delete", r, t));
|
|
594
595
|
}
|
|
595
596
|
getStories(e, t) {
|
|
596
|
-
return this.client.setFetchOptions(t), this.get("cdn/stories", e);
|
|
597
|
+
return this.client.setFetchOptions(t), this._addResolveLevel(e), this.get("cdn/stories", e);
|
|
597
598
|
}
|
|
598
599
|
getStory(e, t, s) {
|
|
599
|
-
return this.client.setFetchOptions(s), this.get(`cdn/stories/${e}`, t);
|
|
600
|
+
return this.client.setFetchOptions(s), this._addResolveLevel(t), this.get(`cdn/stories/${e}`, t);
|
|
600
601
|
}
|
|
601
602
|
getToken() {
|
|
602
603
|
return this.accessToken;
|
|
@@ -604,6 +605,9 @@ class me {
|
|
|
604
605
|
ejectInterceptor() {
|
|
605
606
|
this.client.eject();
|
|
606
607
|
}
|
|
608
|
+
_addResolveLevel(e) {
|
|
609
|
+
typeof e.resolve_relations < "u" && (e.resolve_level = 2);
|
|
610
|
+
}
|
|
607
611
|
_cleanCopy(e) {
|
|
608
612
|
return JSON.parse(JSON.stringify(e));
|
|
609
613
|
}
|
|
@@ -811,7 +815,7 @@ class me {
|
|
|
811
815
|
return await this.cacheProvider().flush(), this;
|
|
812
816
|
}
|
|
813
817
|
}
|
|
814
|
-
const
|
|
818
|
+
const me = (o = {}) => {
|
|
815
819
|
const { apiOptions: e } = o;
|
|
816
820
|
if (!e.accessToken) {
|
|
817
821
|
console.error(
|
|
@@ -819,8 +823,8 @@ const ye = (o = {}) => {
|
|
|
819
823
|
);
|
|
820
824
|
return;
|
|
821
825
|
}
|
|
822
|
-
return { storyblokApi: new
|
|
823
|
-
},
|
|
826
|
+
return { storyblokApi: new fe(e) };
|
|
827
|
+
}, Se = (o) => {
|
|
824
828
|
if (typeof o != "object" || typeof o._editable > "u")
|
|
825
829
|
return {};
|
|
826
830
|
try {
|
|
@@ -835,8 +839,8 @@ const ye = (o = {}) => {
|
|
|
835
839
|
return {};
|
|
836
840
|
}
|
|
837
841
|
};
|
|
838
|
-
let $,
|
|
839
|
-
const
|
|
842
|
+
let $, R = "https://app.storyblok.com/f/storyblok-v2-latest.js";
|
|
843
|
+
const ye = (o = {}) => {
|
|
840
844
|
var e, t;
|
|
841
845
|
const {
|
|
842
846
|
bridge: s,
|
|
@@ -849,11 +853,11 @@ const be = (o = {}) => {
|
|
|
849
853
|
n.accessToken = n.accessToken || r;
|
|
850
854
|
const l = { bridge: s, apiOptions: n };
|
|
851
855
|
let h = {};
|
|
852
|
-
i.forEach((
|
|
853
|
-
h = { ...h, ...
|
|
854
|
-
}), a && (
|
|
856
|
+
i.forEach((d) => {
|
|
857
|
+
h = { ...h, ...d(l) };
|
|
858
|
+
}), a && (R = a);
|
|
855
859
|
const p = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
856
|
-
return s !== !1 && p && P(
|
|
860
|
+
return s !== !1 && p && P(R), $ = new k(c.schema), c.resolver && L($, c.resolver), h;
|
|
857
861
|
}, L = (o, e) => {
|
|
858
862
|
o.addNode("blok", (t) => {
|
|
859
863
|
let s = "";
|
|
@@ -863,7 +867,7 @@ const be = (o = {}) => {
|
|
|
863
867
|
html: s
|
|
864
868
|
};
|
|
865
869
|
});
|
|
866
|
-
},
|
|
870
|
+
}, be = (o) => !o || !(o != null && o.content.some((e) => e.content || e.type === "blok" || e.type === "horizontal_rule")), ke = (o, e, t) => {
|
|
867
871
|
let s = t || $;
|
|
868
872
|
if (!s) {
|
|
869
873
|
console.error(
|
|
@@ -871,11 +875,11 @@ const be = (o = {}) => {
|
|
|
871
875
|
);
|
|
872
876
|
return;
|
|
873
877
|
}
|
|
874
|
-
return
|
|
875
|
-
},
|
|
876
|
-
function
|
|
878
|
+
return be(o) ? "" : (e && (s = new k(e.schema), e.resolver && L(s, e.resolver)), s.render(o));
|
|
879
|
+
}, xe = () => P(R);
|
|
880
|
+
function ve(o, e, t) {
|
|
877
881
|
const s = "virtual:storyblok-init", r = "\0" + s;
|
|
878
|
-
return globalThis.apiPlugin =
|
|
882
|
+
return globalThis.apiPlugin = me, globalThis.storyblokInit = ye, {
|
|
879
883
|
name: "vite-plugin-storyblok-init",
|
|
880
884
|
async resolveId(i) {
|
|
881
885
|
if (i === s)
|
|
@@ -894,14 +898,14 @@ function we(o, e, t) {
|
|
|
894
898
|
}
|
|
895
899
|
};
|
|
896
900
|
}
|
|
897
|
-
const
|
|
901
|
+
const we = /[\p{Lu}]/u, $e = /[\p{Ll}]/u, x = /^[\p{Lu}](?![\p{Lu}])/gu, N = /([\p{Alpha}\p{N}_]|$)/u, T = /[_.\- ]+/, Re = new RegExp("^" + T.source), O = new RegExp(T.source + N.source, "gu"), E = new RegExp("\\d+" + N.source, "gu"), Te = (o, e, t, s) => {
|
|
898
902
|
let r = !1, i = !1, n = !1, c = !1;
|
|
899
903
|
for (let a = 0; a < o.length; a++) {
|
|
900
904
|
const l = o[a];
|
|
901
|
-
c = a > 2 ? o[a - 3] === "-" : !0, r &&
|
|
905
|
+
c = a > 2 ? o[a - 3] === "-" : !0, r && we.test(l) ? (o = o.slice(0, a) + "-" + o.slice(a), r = !1, n = i, i = !0, a++) : i && n && $e.test(l) && (!c || s) ? (o = o.slice(0, a - 1) + "-" + o.slice(a - 1), n = i, i = !1, r = !0) : (r = e(l) === l && t(l) !== l, n = i, i = t(l) === l && e(l) !== l);
|
|
902
906
|
}
|
|
903
907
|
return o;
|
|
904
|
-
},
|
|
908
|
+
}, Ie = (o, e) => (x.lastIndex = 0, o.replaceAll(x, (t) => e(t))), _e = (o, e) => (O.lastIndex = 0, E.lastIndex = 0, o.replaceAll(E, (t, s, r) => ["_", "-"].includes(o.charAt(r + t.length)) ? t : e(t)).replaceAll(O, (t, s) => e(s)));
|
|
905
909
|
function j(o, e) {
|
|
906
910
|
if (!(typeof o == "string" || Array.isArray(o)))
|
|
907
911
|
throw new TypeError("Expected the input to be `string | string[]`");
|
|
@@ -912,9 +916,9 @@ function j(o, e) {
|
|
|
912
916
|
}, Array.isArray(o) ? o = o.map((i) => i.trim()).filter((i) => i.length).join("-") : o = o.trim(), o.length === 0)
|
|
913
917
|
return "";
|
|
914
918
|
const t = e.locale === !1 ? (i) => i.toLowerCase() : (i) => i.toLocaleLowerCase(e.locale), s = e.locale === !1 ? (i) => i.toUpperCase() : (i) => i.toLocaleUpperCase(e.locale);
|
|
915
|
-
return o.length === 1 ?
|
|
919
|
+
return o.length === 1 ? T.test(o) ? "" : e.pascalCase ? s(o) : t(o) : (o !== t(o) && (o = Te(o, t, s, e.preserveConsecutiveUppercase)), o = o.replace(Re, ""), o = e.preserveConsecutiveUppercase ? Ie(o, t) : t(o), e.pascalCase && (o = s(o.charAt(0)) + o.slice(1)), _e(o, s));
|
|
916
920
|
}
|
|
917
|
-
function
|
|
921
|
+
function Ce(o, e, t, s) {
|
|
918
922
|
const r = "virtual:storyblok-components", i = "\0" + r;
|
|
919
923
|
return {
|
|
920
924
|
name: "vite-plugin-storyblok-components",
|
|
@@ -926,11 +930,11 @@ function Ae(o, e, t, s) {
|
|
|
926
930
|
if (n === i) {
|
|
927
931
|
const c = [], a = [];
|
|
928
932
|
for await (const [h, p] of Object.entries(e)) {
|
|
929
|
-
const
|
|
933
|
+
const d = await this.resolve(
|
|
930
934
|
"/" + o + "/" + p + ".astro"
|
|
931
935
|
);
|
|
932
|
-
if (
|
|
933
|
-
c.push(`import ${j(h)} from "${
|
|
936
|
+
if (d)
|
|
937
|
+
c.push(`import ${j(h)} from "${d.id}"`);
|
|
934
938
|
else if (t)
|
|
935
939
|
a.push(h);
|
|
936
940
|
else
|
|
@@ -968,7 +972,7 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
968
972
|
}
|
|
969
973
|
};
|
|
970
974
|
}
|
|
971
|
-
function
|
|
975
|
+
function Ae(o) {
|
|
972
976
|
const e = "virtual:storyblok-options", t = "\0" + e;
|
|
973
977
|
return {
|
|
974
978
|
name: "vite-plugin-storyblok-options",
|
|
@@ -982,10 +986,10 @@ function Se(o) {
|
|
|
982
986
|
}
|
|
983
987
|
};
|
|
984
988
|
}
|
|
985
|
-
function
|
|
989
|
+
function Oe() {
|
|
986
990
|
return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
|
|
987
991
|
}
|
|
988
|
-
function
|
|
992
|
+
function Ee(o, e) {
|
|
989
993
|
const t = globalThis.storyblokApiInstance.richTextResolver;
|
|
990
994
|
if (!t) {
|
|
991
995
|
console.error(
|
|
@@ -993,9 +997,9 @@ function je(o, e) {
|
|
|
993
997
|
);
|
|
994
998
|
return;
|
|
995
999
|
}
|
|
996
|
-
return
|
|
1000
|
+
return ke(o, e, t);
|
|
997
1001
|
}
|
|
998
|
-
function
|
|
1002
|
+
function je(o) {
|
|
999
1003
|
const e = {
|
|
1000
1004
|
useCustomApi: !1,
|
|
1001
1005
|
bridge: !0,
|
|
@@ -1014,18 +1018,18 @@ function Pe(o) {
|
|
|
1014
1018
|
if (s({
|
|
1015
1019
|
vite: {
|
|
1016
1020
|
plugins: [
|
|
1017
|
-
|
|
1021
|
+
ve(
|
|
1018
1022
|
e.accessToken,
|
|
1019
1023
|
e.useCustomApi,
|
|
1020
1024
|
e.apiOptions
|
|
1021
1025
|
),
|
|
1022
|
-
|
|
1026
|
+
Ce(
|
|
1023
1027
|
e.componentsDir,
|
|
1024
1028
|
e.components,
|
|
1025
1029
|
e.enableFallbackComponent,
|
|
1026
1030
|
e.customFallbackComponent
|
|
1027
1031
|
),
|
|
1028
|
-
|
|
1032
|
+
Ae(e)
|
|
1029
1033
|
]
|
|
1030
1034
|
}
|
|
1031
1035
|
}), t(
|
|
@@ -1068,9 +1072,9 @@ function Pe(o) {
|
|
|
1068
1072
|
export {
|
|
1069
1073
|
k as RichTextResolver,
|
|
1070
1074
|
pe as RichTextSchema,
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1075
|
+
je as default,
|
|
1076
|
+
xe as loadStoryblokBridge,
|
|
1077
|
+
Ee as renderRichText,
|
|
1078
|
+
Se as storyblokEditable,
|
|
1079
|
+
Oe as useStoryblokApi
|
|
1076
1080
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _exports: any
|
|
1
|
+
declare const _exports: Cypress.ConfigOptions<any>;
|
|
2
2
|
export = _exports;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.5-next.1",
|
|
4
4
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
5
5
|
"main": "./dist/storyblok-astro.js",
|
|
6
6
|
"module": "./dist/storyblok-astro.mjs",
|
|
@@ -49,19 +49,19 @@
|
|
|
49
49
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@storyblok/js": "^3.0.
|
|
52
|
+
"@storyblok/js": "^3.0.7",
|
|
53
53
|
"camelcase": "^8.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@cypress/vite-dev-server": "^5.0.7",
|
|
57
57
|
"@rollup/plugin-dynamic-import-vars": "^2.1.2",
|
|
58
|
-
"@types/node": "20.11.
|
|
59
|
-
"astro": "^4.
|
|
58
|
+
"@types/node": "20.11.26",
|
|
59
|
+
"astro": "^4.5.2",
|
|
60
60
|
"cypress": "^13.6.6",
|
|
61
61
|
"eslint-plugin-cypress": "^2.15.1",
|
|
62
62
|
"start-server-and-test": "^2.0.3",
|
|
63
|
-
"typescript": "5.
|
|
64
|
-
"vite": "^5.1.
|
|
63
|
+
"typescript": "5.4.2",
|
|
64
|
+
"vite": "^5.1.6",
|
|
65
65
|
"vite-plugin-dts": "^3.7.3"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|