@storyblok/astro 6.1.0-alpha.2 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -1
- package/dist/components/StoryblokComponent.astro +9 -6
- package/dist/index.d.ts +1 -3
- package/dist/storyblok-astro.es.js +494 -825
- package/dist/storyblok-astro.umd.js +8 -8
- package/dist/vite-plugins/vite-plugin-storyblok-options.d.ts +1 -2
- package/package.json +5 -3
- package/dist/content-loader/storyblokLoader.d.ts +0 -11
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(m,L){typeof exports=="object"&&typeof module<"u"?L(exports):typeof define=="function"&&define.amd?define(["exports"],L):(m=typeof globalThis<"u"?globalThis:m||self,L(m.storyblokAstro={}))})(this,function(m){"use strict";const L=`<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
2
2
|
<g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
|
3
3
|
<g id="storyblok-partner-logo" transform="translate(-59.000000, -169.000000)" fill-rule="nonzero">
|
|
4
4
|
<g id="storyblok-symbol" transform="translate(59.000000, 169.000000)">
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
</g>
|
|
8
8
|
</g>
|
|
9
9
|
</g>
|
|
10
|
-
</svg>`,
|
|
10
|
+
</svg>`,W=/[\p{Lu}]/u,Y=/[\p{Ll}]/u,P=/^[\p{Lu}](?![\p{Lu}])/gu,B=/([\p{Alpha}\p{N}_]|$)/u,x=/[_.\- ]+/,V=new RegExp("^"+x.source),D=new RegExp(x.source+B.source,"gu"),U=new RegExp("\\d+"+B.source,"gu"),X=(r,e,t,o)=>{let n=!1,s=!1,l=!1,d=!1;for(let i=0;i<r.length;i++){const p=r[i];d=i>2?r[i-3]==="-":!0,n&&W.test(p)?(r=r.slice(0,i)+"-"+r.slice(i),n=!1,l=s,s=!0,i++):s&&l&&Y.test(p)&&(!d||o)?(r=r.slice(0,i-1)+"-"+r.slice(i-1),l=s,s=!1,n=!0):(n=e(p)===p&&t(p)!==p,l=s,s=t(p)===p&&e(p)!==p)}return r},Z=(r,e)=>(P.lastIndex=0,r.replaceAll(P,t=>e(t))),Q=(r,e)=>(D.lastIndex=0,U.lastIndex=0,r.replaceAll(U,(t,o,n)=>["_","-"].includes(r.charAt(n+t.length))?t:e(t)).replaceAll(D,(t,o)=>e(o)));function ee(r,e){if(!(typeof r=="string"||Array.isArray(r)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(r)?r=r.map(s=>s.trim()).filter(s=>s.length).join("-"):r=r.trim(),r.length===0)return"";const t=e.locale===!1?s=>s.toLowerCase():s=>s.toLocaleLowerCase(e.locale),o=e.locale===!1?s=>s.toUpperCase():s=>s.toLocaleUpperCase(e.locale);return r.length===1?x.test(r)?"":e.pascalCase?o(r):t(r):(r!==t(r)&&(r=X(r,t,o,e.preserveConsecutiveUppercase)),r=r.replace(V,""),r=e.preserveConsecutiveUppercase?Z(r,t):t(r),e.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),Q(r,o))}function _(r){return ee(r)}function te(r,e={},t,o){const n="virtual:storyblok-components",s=`\0${n}`;return{name:"vite-plugin-storyblok-components",async resolveId(l){if(l===n)return s},async load(l){if(l===s){const d=[],i=[];for await(const[g,w]of Object.entries(e)){const C=await this.resolve(`/${r}/${w}.astro`);if(C)d.push(`import ${_(g)} from "${C.id}"`);else if(t)i.push(g);else throw new Error(`Component could not be found for blok "${g}"! Does "${`/${r}/${w}`}.astro" exist?`)}let p="";if(t)if(p=",FallbackComponent",o){const g=await this.resolve(`/${r}/${o}.astro`);if(!g)throw new Error(`Custom fallback component could not be found. Does "${`/${r}/${o}`}.astro" exist?`);d.push(`import FallbackComponent from "${g.id}"`)}else d.push("import FallbackComponent from '@storyblok/astro/FallbackComponent.astro'");if(Object.values(e).length)return`${d.join(";")};export default {${Object.keys(e).filter(g=>!i.includes(g)).map(g=>_(g)).join(",")}${p}}`;if(t)return`${d[0]}; export default {${p.replace(",","")}}`;throw new Error(`Currently, no Storyblok components are registered in astro.config.mjs.
|
|
11
11
|
Please register your components or enable the fallback component.
|
|
12
|
-
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function
|
|
12
|
+
Detailed information can be found here: https://github.com/storyblok/storyblok-astro`)}}}}function re(r,e,t){const o="virtual:storyblok-init",n=`\0${o}`;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return n},async load(s){if(s===n)return`
|
|
13
13
|
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
14
14
|
const { storyblokApi } = storyblokInit({
|
|
15
15
|
accessToken: "${r}",
|
|
@@ -17,7 +17,7 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
17
17
|
apiOptions: ${JSON.stringify(t)},
|
|
18
18
|
});
|
|
19
19
|
export const storyblokApiInstance = storyblokApi;
|
|
20
|
-
`}}}function
|
|
20
|
+
`}}}function oe(r){const e="virtual:storyblok-options",t=`\0${e}`;return{name:"vite-plugin-storyblok-options",async resolveId(o){if(o===e)return t},async load(o){if(o===t)return`export default ${JSON.stringify(r)}`}}}let z=!1;const H=[],se=r=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=n=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}z?n():H.push(n)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=n=>t(n),o.onload=n=>{H.forEach(s=>s()),z=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)});var ne=Object.defineProperty,ae=(r,e,t)=>e in r?ne(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,S=(r,e,t)=>ae(r,typeof e!="symbol"?e+"":e,t);class le{constructor(){S(this,"isCDNUrl",(e="")=>e.includes("/cdn/")),S(this,"getOptionsPage",(e,t=25,o=1)=>({...e,per_page:t,page:o})),S(this,"delay",e=>new Promise(t=>setTimeout(t,e))),S(this,"arrayFrom",(e=0,t)=>Array.from({length:e},t)),S(this,"range",(e=0,t=e)=>{const o=Math.abs(t-e)||0,n=e<t?1:-1;return this.arrayFrom(o,(s,l)=>l*n+e)}),S(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),S(this,"flatMap",(e=[],t)=>e.map(t).reduce((o,n)=>[...o,...n],[])),S(this,"escapeHTML",function(e){const t={"&":"&","<":"<",">":">",'"':""","'":"'"},o=/[&<>"']/g,n=new RegExp(o.source);return e&&n.test(e)?e.replace(o,s=>t[s]):e})}stringify(e,t,o){const n=[];for(const s in e){if(!Object.prototype.hasOwnProperty.call(e,s))continue;const l=e[s],d=o?"":encodeURIComponent(s);let i;typeof l=="object"?i=this.stringify(l,t?t+encodeURIComponent(`[${d}]`):d,Array.isArray(l)):i=`${t?t+encodeURIComponent(`[${d}]`):d}=${encodeURIComponent(l)}`,n.push(i)}return n.join("&")}getRegionURL(e){const t="api.storyblok.com",o="api-us.storyblok.com",n="app.storyblokchina.cn",s="api-ap.storyblok.com",l="api-ca.storyblok.com";switch(e){case"us":return o;case"cn":return n;case"ap":return s;case"ca":return l;default:return t}}}const ie=function(r,e){const t={};for(const o in r){const n=r[o];e.includes(o)&&n!==null&&(t[o]=n)}return t},ce=r=>r==="email",ue=()=>({singleTag:"hr"}),de=()=>({tag:"blockquote"}),pe=()=>({tag:"ul"}),ge=r=>({tag:["pre",{tag:"code",attrs:r.attrs}]}),he=()=>({singleTag:"br"}),fe=r=>({tag:`h${r.attrs.level}`}),be=r=>({singleTag:[{tag:"img",attrs:ie(r.attrs,["src","alt","title"])}]}),ye=()=>({tag:"li"}),me=()=>({tag:"ol"}),ke=()=>({tag:"p"}),$e=r=>({tag:[{tag:"span",attrs:{"data-type":"emoji","data-name":r.attrs.name,emoji:r.attrs.emoji}}]}),we=()=>({tag:"b"}),Te=()=>({tag:"s"}),Ee=()=>({tag:"u"}),Ce=()=>({tag:"strong"}),ve=()=>({tag:"code"}),Se=()=>({tag:"i"}),Ie=r=>{if(!r.attrs)return{tag:""};const e=new le().escapeHTML,t={...r.attrs},{linktype:o="url"}=r.attrs;if(delete t.linktype,t.href&&(t.href=e(r.attrs.href||"")),ce(o)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),t.custom){for(const n in t.custom)t[n]=t.custom[n];delete t.custom}return{tag:[{tag:"a",attrs:t}]}},Le=r=>({tag:[{tag:"span",attrs:r.attrs}]}),Ae=()=>({tag:"sub"}),Re=()=>({tag:"sup"}),je=r=>({tag:[{tag:"span",attrs:r.attrs}]}),Oe=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`background-color:${r.attrs.color};`}}]}:{tag:""}},xe=r=>{var e;return(e=r.attrs)!=null&&e.color?{tag:[{tag:"span",attrs:{style:`color:${r.attrs.color}`}}]}:{tag:""}},F={nodes:{horizontal_rule:ue,blockquote:de,bullet_list:pe,code_block:ge,hard_break:he,heading:fe,image:be,list_item:ye,ordered_list:me,paragraph:ke,emoji:$e},marks:{bold:we,strike:Te,underline:Ee,strong:Ce,code:ve,italic:Se,link:Ie,styled:Le,subscript:Ae,superscript:Re,anchor:je,highlight:Oe,textStyle:xe}},_e=function(r){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,o=new RegExp(t.source);return r&&o.test(r)?r.replace(t,n=>e[n]):r};let q=!1;class G{constructor(e){S(this,"marks"),S(this,"nodes"),e||(e=F),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e,t={optimizeImages:!1},o=!0){if(!q&&o&&(console.warn("Warning ⚠️: The RichTextResolver class is deprecated and will be removed in the next major release. Please use the `@storyblok/richtext` package instead. https://github.com/storyblok/richtext/"),q=!0),e&&e.content&&Array.isArray(e.content)){let n="";return e.content.forEach(s=>{n+=this.renderNode(s)}),t.optimizeImages?this.optimizeImages(n,t.optimizeImages):n}return console.warn(`The render method must receive an Object with a "content" field.
|
|
21
21
|
The "content" field must be an array of nodes as the type ISbRichtext.
|
|
22
22
|
ISbRichtext:
|
|
23
23
|
content?: ISbRichtext[]
|
|
@@ -40,10 +40,10 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
40
40
|
}
|
|
41
41
|
],
|
|
42
42
|
type: 'doc'
|
|
43
|
-
}`),""}optimizeImages(e,t){let s=0,o=0,n="",i="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(n+=`width="${t.width}" `,s=t.width),typeof t.height=="number"&&t.height>0&&(n+=`height="${t.height}" `,o=t.height),(t.loading==="lazy"||t.loading==="eager")&&(n+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(n+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(i+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(i+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-F]{6}/gi)||t.filters.fill==="transparent")&&(i+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(i+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(i+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(i+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(i+=`:rotate(${t.filters.rotate})`),i.length>0&&(i=`/filters${i}`))),n.length>0&&(e=e.replace(/<img/g,`<img ${n.trim()}`));const a=s>0||o>0||i.length>0?`${s}x${o}${i}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${a}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,l=>{var c,h;const u=l.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(u&&u.length>0){const p={srcset:(c=t.srcset)==null?void 0:c.map(g=>{if(typeof g=="number")return`//${u}/m/${g}x0${i} ${g}w`;if(typeof g=="object"&&g.length===2){let v=0,k=0;return typeof g[0]=="number"&&(v=g[0]),typeof g[1]=="number"&&(k=g[1]),`//${u}/m/${v}x${k}${i} ${v}w`}return""}).join(", "),sizes:(h=t.sizes)==null?void 0:h.map(g=>g).join(", ")};let b="";return p.srcset&&(b+=`srcset="${p.srcset}" `),p.sizes&&(b+=`sizes="${p.sizes}" `),l.replace(/<img/g,`<img ${b.trim()}`)}return l})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&n.tag!==""&&t.push(this.renderOpeningTag(n.tag))});const s=this.getMatchingNode(e);return s&&s.tag&&t.push(this.renderOpeningTag(s.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(Pe(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(o=>{const n=this.getMatchingMark(o);n&&n.tag!==""&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(s=>{if(s.constructor===String)return`<${s}${t}>`;{let o=`<${s.tag}`;if(s.attrs){for(const n in s.attrs)if(Object.prototype.hasOwnProperty.call(s.attrs,n)){const i=s.attrs[n];i!==null&&(o+=` ${n}="${i}"`)}}return`${o}${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 je{constructor(e){d(this,"baseURL"),d(this,"timeout"),d(this,"headers"),d(this,"responseInterceptor"),d(this,"fetch"),d(this,"ejectInterceptor"),d(this,"url"),d(this,"parameters"),d(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(o=>{s.data=o});for(const o of e.headers.entries())t[o[0]]=o[1];return s.headers={...t},s.status=e.status,s.statusText=e.statusText,s}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,s=null;if(e==="get"){const l=new C;t=`${this.baseURL}${this.url}?${l.stringify(this.parameters)}`}else s=JSON.stringify(this.parameters);const o=new URL(t),n=new AbortController,{signal:i}=n;let a;this.timeout&&(a=setTimeout(()=>n.abort(),this.timeout));try{const l=await this.fetch(`${o}`,{method:e,headers:this.headers,body:s,signal:i,...this.fetchOptions});this.timeout&&clearTimeout(a);const c=await this._responseHandler(l);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(c)):this._statusHandler(c)}catch(l){return{message:l}}}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,o)=>{if(t.test(`${e.status}`))return s(e);const n={message:e.statusText,status:e.status,response:Array.isArray(e.data)?e.data[0]:e.data.error||e.data.slug};o(n)})}}const H="SB-Agent",I={defaultAgentName:"SB-JS-CLIENT",defaultAgentVersion:"SB-Agent-Version",packageVersion:"6.0.0"};let A={};const m={};class xe{constructor(e,t){d(this,"client"),d(this,"maxRetries"),d(this,"retriesDelay"),d(this,"throttle"),d(this,"accessToken"),d(this,"cache"),d(this,"helpers"),d(this,"resolveCounter"),d(this,"relations"),d(this,"links"),d(this,"richTextResolver"),d(this,"resolveNestedRelations"),d(this,"stringifiedStoriesCache");let s=e.endpoint||t;if(!s){const i=new C().getRegionURL,a=e.https===!1?"http":"https";e.oauthToken?s=`${a}://${i(e.region)}/v1`:s=`${a}://${i(e.region)}/v2`}const o=new Headers;o.set("Content-Type","application/json"),o.set("Accept","application/json"),e.headers&&(e.headers.constructor.name==="Headers"?e.headers.entries().toArray():Object.entries(e.headers)).forEach(([i,a])=>{o.set(i,a)}),o.has(H)||(o.set(H,I.defaultAgentName),o.set(I.defaultAgentVersion,I.packageVersion));let n=5;e.oauthToken&&(o.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new $(e.richTextSchema):this.richTextResolver=new $,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||10,this.retriesDelay=300,this.throttle=ne(this.throttledRequest.bind(this),n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new C,this.resolveCounter=0,this.resolveNestedRelations=e.resolveNestedRelations||!0,this.stringifiedStoriesCache={},this.client=new je({baseURL:s,timeout:e.timeout||0,headers:o,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let s="";return t.attrs.body&&t.attrs.body.forEach(o=>{s+=e(o.component,o)}),{html:s}})}parseParams(e){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}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,s,o,n){const i=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,s,o));return this.cacheResponse(e,i,void 0,n)}get(e,t,s){t||(t={});const o=`/${e}`,n=this.factoryParamOptions(o,t);return this.cacheResponse(o,n,void 0,s)}async getAll(e,t,s,o){const n=(t==null?void 0:t.per_page)||25,i=`/${e}`.replace(/\/$/,""),a=s??i.substring(i.lastIndexOf("/")+1),l=1,c=await this.makeRequest(i,t,n,l,o),h=c.total?Math.ceil(c.total/n):1,u=await this.helpers.asyncMap(this.helpers.range(l,h),p=>this.makeRequest(i,t,n,p+1,o));return this.helpers.flatMap([c,...u],p=>Object.values(p.data[a]))}post(e,t,s){const o=`/${e}`;return Promise.resolve(this.throttle("post",o,t,s))}put(e,t,s){const o=`/${e}`;return Promise.resolve(this.throttle("put",o,t,s))}delete(e,t,s){t||(t={});const o=`/${e}`;return Promise.resolve(this.throttle("delete",o,t,s))}getStories(e,t){return this._addResolveLevel(e),this.get("cdn/stories",e,t)}getStory(e,t,s){return this._addResolveLevel(t),this.get(`cdn/stories/${e}`,t,s)}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 o=e[t];o&&o.fieldtype==="multilink"&&o.linktype==="story"&&typeof o.id=="string"&&this.links[s][o.id]?o.story=this._cleanCopy(this.links[s][o.id]):o&&o.linktype==="story"&&typeof o.uuid=="string"&&this.links[s][o.uuid]&&(o.story=this._cleanCopy(this.links[s][o.uuid]))}getStoryReference(e,t){return this.relations[e][t]?JSON.parse(this.stringifiedStoriesCache[t]||JSON.stringify(this.relations[e][t])):t}_resolveField(e,t,s){const o=e[t];typeof o=="string"?e[t]=this.getStoryReference(s,o):Array.isArray(o)&&(e[t]=o.map(n=>this.getStoryReference(s,n)).filter(Boolean))}_insertRelations(e,t,s,o){if(Array.isArray(s)?s.find(i=>i.endsWith(`.${t}`)):s.endsWith(`.${t}`)){this._resolveField(e,t,o);return}const n=e.component?`${e.component}.${t}`:t;(Array.isArray(s)?s.includes(n):s===n)&&this._resolveField(e,t,o)}iterateTree(e,t,s){const o=(n,i="")=>{if(!(!n||n._stopResolving)){if(Array.isArray(n))n.forEach((a,l)=>o(a,`${i}[${l}]`));else if(typeof n=="object")for(const a in n){const l=i?`${i}.${a}`:a;(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,a,t,s),this._insertLinks(n,a,s)),o(n[a],l)}}};o(e.content)}async resolveLinks(e,t,s){let o=[];if(e.link_uuids){const n=e.link_uuids.length,i=[],a=50;for(let l=0;l<n;l+=a){const c=Math.min(n,l+a);i.push(e.link_uuids.slice(l,c))}for(let l=0;l<i.length;l++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:i[l].join(",")})).data.stories.forEach(c=>{o.push(c)})}else o=e.links;o.forEach(n=>{this.links[s][n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t,s){let o=[];if(e.rel_uuids){const n=e.rel_uuids.length,i=[],a=50;for(let l=0;l<n;l+=a){const c=Math.min(n,l+a);i.push(e.rel_uuids.slice(l,c))}for(let l=0;l<i.length;l++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:i[l].join(","),excluding_fields:t.excluding_fields})).data.stories.forEach(c=>{o.push(c)})}else o=e.rels;o&&o.length>0&&o.forEach(n=>{this.relations[s][n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t,s){var o,n;let i=[];if(this.links[s]={},this.relations[s]={},typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(i=t.resolve_relations.split(",")),await this.resolveRelations(e,t,s)),t.resolve_links&&["1","story","url","link"].includes(t.resolve_links)&&((o=e.links)!=null&&o.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t,s),this.resolveNestedRelations)for(const a in this.relations[s])this.iterateTree(this.relations[s][a],i,s);e.story?this.iterateTree(e.story,i,s):e.stories.forEach(a=>{this.iterateTree(a,i,s)}),this.stringifiedStoriesCache={},delete this.links[s],delete this.relations[s]}async cacheResponse(e,t,s,o){const n=this.helpers.stringify({url:e,params:t}),i=this.cacheProvider();if(t.version==="published"&&e!=="/cdn/spaces/me"){const a=await i.get(n);if(a)return Promise.resolve(a)}return new Promise(async(a,l)=>{var c;try{const h=await this.throttle("get",e,t,o);if(h.status!==200)return l(h);let u={data:h.data,headers:h.headers};if((c=h.headers)!=null&&c["per-page"]&&(u=Object.assign({},u,{perPage:h.headers["per-page"]?Number.parseInt(h.headers["per-page"]):0,total:h.headers["per-page"]?Number.parseInt(h.headers.total):0})),u.data.story||u.data.stories){const b=this.resolveCounter=++this.resolveCounter%1e3;await this.resolveStories(u.data,t,`${b}`)}t.version==="published"&&e!=="/cdn/spaces/me"&&await i.set(n,u);const p=this.cache.clear==="onpreview"&&t.version==="draft"||this.cache.clear==="auto";return t.token&&u.data.cv&&(p&&m[t.token]&&m[t.token]!==u.data.cv&&await this.flushCache(),m[t.token]=u.data.cv),a(u)}catch(h){if(h.response&&h.status===429&&(s=typeof s>"u"?0:s+1,s<this.maxRetries))return console.log(`Hit rate limit. Retrying in ${this.retriesDelay/1e3} seconds.`),await this.helpers.delay(this.retriesDelay),this.cacheResponse(e,t,s).then(a).catch(l);l(h)}})}throttledRequest(e,t,s,o){return this.client.setFetchOptions(o),this.client[e](t,s)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}clearCacheVersion(){this.accessToken&&(m[this.accessToken]=0)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(A[e])},getAll(){return Promise.resolve(A)},set(e,t){return A[e]=t,Promise.resolve(void 0)},flush(){return A={},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}}const Oe=(r={})=>{const{apiOptions:e}=r;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 xe(e)}},Ne=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};let L,E="https://app.storyblok.com/f/storyblok-v2-latest.js";const q=(r,e)=>{r.addNode("blok",t=>{let s="";return t.attrs.body.forEach(o=>{s+=e(o.component,o)}),{html:s}})},Me=(r={})=>{var e,t;const{bridge:s,accessToken:o,use:n=[],apiOptions:i={},richText:a={},bridgeUrl:l}=r;i.accessToken=i.accessToken||o;const c={bridge:s,apiOptions:i};let h={};n.forEach(p=>{h={...h,...p(c)}}),l&&(E=l);const u=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return s!==!1&&u&&B(E),L=new $(a.schema),a.resolver&&q(L,a.resolver),h},Ue=r=>{var e;return!r||!((e=r==null?void 0:r.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},Fe=(r,e,t)=>{let s=t||L;if(!s){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ue(r)?"":(e&&(s=new $(e.schema),e.resolver&&q(s,e.resolver)),s.render(r,{},!1))},Be=()=>B(E);function De(){if(!globalThis.storyblokApiInstance)throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function ze(r){let e=null;return r&&r.locals._storyblok_preview_data&&(e=r.locals._storyblok_preview_data),e}function He(r,e){var s;const t=(s=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:s.richTextResolver;if(!t)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Fe(r,e,t)}function qe(r){return typeof r=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});`:"const storyblokInstance = new StoryblokBridge();"}function Ve(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...r},t=qe(e.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:s,updateConfig:o,addDevToolbarApp:n,addMiddleware:i,config:a})=>{if(o({vite:{plugins:[ee(e.accessToken,e.useCustomApi,e.apiOptions),X(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),te(e)]}}),e.livePreview&&(a==null?void 0:a.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode.");s("page-ssr",`
|
|
43
|
+
}`),""}optimizeImages(e,t){let o=0,n=0,s="",l="";typeof t!="boolean"&&(typeof t.width=="number"&&t.width>0&&(s+=`width="${t.width}" `,o=t.width),typeof t.height=="number"&&t.height>0&&(s+=`height="${t.height}" `,n=t.height),(t.loading==="lazy"||t.loading==="eager")&&(s+=`loading="${t.loading}" `),typeof t.class=="string"&&t.class.length>0&&(s+=`class="${t.class}" `),t.filters&&(typeof t.filters.blur=="number"&&t.filters.blur>=0&&t.filters.blur<=100&&(l+=`:blur(${t.filters.blur})`),typeof t.filters.brightness=="number"&&t.filters.brightness>=-100&&t.filters.brightness<=100&&(l+=`:brightness(${t.filters.brightness})`),t.filters.fill&&(t.filters.fill.match(/[0-9A-F]{6}/gi)||t.filters.fill==="transparent")&&(l+=`:fill(${t.filters.fill})`),t.filters.format&&["webp","png","jpeg"].includes(t.filters.format)&&(l+=`:format(${t.filters.format})`),typeof t.filters.grayscale=="boolean"&&t.filters.grayscale&&(l+=":grayscale()"),typeof t.filters.quality=="number"&&t.filters.quality>=0&&t.filters.quality<=100&&(l+=`:quality(${t.filters.quality})`),t.filters.rotate&&[90,180,270].includes(t.filters.rotate)&&(l+=`:rotate(${t.filters.rotate})`),l.length>0&&(l=`/filters${l}`))),s.length>0&&(e=e.replace(/<img/g,`<img ${s.trim()}`));const d=o>0||n>0||l.length>0?`${o}x${n}${l}`:"";return e=e.replace(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g,`a.storyblok.com/f/$1/$2.$3/m/${d}`),typeof t!="boolean"&&(t.sizes||t.srcset)&&(e=e.replace(/<img.*?src=["|'](.*?)["|']/g,i=>{var p,g;const w=i.match(/a.storyblok.com\/f\/(\d+)\/([^.]+)\.(gif|jpg|jpeg|png|tif|bmp)/g);if(w&&w.length>0){const C={srcset:(p=t.srcset)==null?void 0:p.map(k=>{if(typeof k=="number")return`//${w}/m/${k}x0${l} ${k}w`;if(typeof k=="object"&&k.length===2){let I=0,R=0;return typeof k[0]=="number"&&(I=k[0]),typeof k[1]=="number"&&(R=k[1]),`//${w}/m/${I}x${R}${l} ${I}w`}return""}).join(", "),sizes:(g=t.sizes)==null?void 0:g.map(k=>k).join(", ")};let T="";return C.srcset&&(T+=`srcset="${C.srcset}" `),C.sizes&&(T+=`sizes="${C.sizes}" `),i.replace(/<img/g,`<img ${T.trim()}`)}return i})),e}renderNode(e){const t=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&s.tag!==""&&t.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&t.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(n=>{t.push(this.renderNode(n))}):e.text?t.push(_e(e.text)):o&&o.singleTag?t.push(this.renderTag(o.singleTag," /")):o&&o.html?t.push(o.html):e.type==="emoji"&&t.push(this.renderEmoji(e)),o&&o.tag&&t.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&s.tag!==""&&t.push(this.renderClosingTag(s.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(o=>{if(o.constructor===String)return`<${o}${t}>`;{let n=`<${o.tag}`;if(o.attrs){for(const s in o.attrs)if(Object.prototype.hasOwnProperty.call(o.attrs,s)){const l=o.attrs[s];l!==null&&(n+=` ${s}="${l}"`)}}return`${n}${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," /")}}const Me=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};try{const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return e?{"data-blok-c":JSON.stringify(e),"data-blok-uid":`${e.id}-${e.uid}`}:{}}catch{return{}}};function Ne(r,e){if(!e)return{src:r,attrs:{}};let t=0,o=0;const n={},s=[];function l(i,p,g,w,C){typeof i!="number"||i<=p||i>=g?console.warn(`[StoryblokRichText] - ${w.charAt(0).toUpperCase()+w.slice(1)} value must be a number between ${p} and ${g} (inclusive)`):C.push(`${w}(${i})`)}if(typeof e=="object"){if(typeof e.width=="number"&&e.width>0?(n.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?(n.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)&&(n.loading=e.loading),e.class&&(n.class=e.class),e.filters){const{filters:i}=e||{},{blur:p,brightness:g,fill:w,format:C,grayscale:T,quality:k,rotate:I}=i||{};p&&l(p,0,100,"blur",s),k&&l(k,0,100,"quality",s),g&&l(g,0,100,"brightness",s),w&&s.push(`fill(${w})`),T&&s.push("grayscale()"),I&&[0,90,180,270].includes(e.filters.rotate||0)&&s.push(`rotate(${I})`),C&&["webp","png","jpeg"].includes(C)&&s.push(`format(${C})`)}e.srcset&&(n.srcset=e.srcset.map(i=>{if(typeof i=="number")return`${r}/m/${i}x0/${s.length>0?`filters:${s.join(":")}`:""} ${i}w`;if(Array.isArray(i)&&i.length===2){const[p,g]=i;return`${r}/m/${p}x${g}/${s.length>0?`filters:${s.join(":")}`:""} ${p}w`}else{console.warn("[StoryblokRichText] - srcset entry must be a number or a tuple of two numbers");return}}).join(", ")),e.sizes&&(n.sizes=e.sizes.join(", "))}let d=`${r}/m/`;return t>0&&o>0&&(d=`${d}${t}x${o}/`),s.length>0&&(d=`${d}filters:${s.join(":")}`),{src:d,attrs:n}}var b=(r=>(r.DOCUMENT="doc",r.HEADING="heading",r.PARAGRAPH="paragraph",r.QUOTE="blockquote",r.OL_LIST="ordered_list",r.UL_LIST="bullet_list",r.LIST_ITEM="list_item",r.CODE_BLOCK="code_block",r.HR="horizontal_rule",r.BR="hard_break",r.IMAGE="image",r.EMOJI="emoji",r.COMPONENT="blok",r.TABLE="table",r.TABLE_ROW="tableRow",r.TABLE_CELL="tableCell",r.TABLE_HEADER="tableHeader",r))(b||{}),v=(r=>(r.BOLD="bold",r.STRONG="strong",r.STRIKE="strike",r.UNDERLINE="underline",r.ITALIC="italic",r.CODE="code",r.LINK="link",r.ANCHOR="anchor",r.STYLED="styled",r.SUPERSCRIPT="superscript",r.SUBSCRIPT="subscript",r.TEXT_STYLE="textStyle",r.HIGHLIGHT="highlight",r))(v||{}),M=(r=>(r.TEXT="text",r))(M||{}),A=(r=>(r.URL="url",r.STORY="story",r.ASSET="asset",r.EMAIL="email",r))(A||{});const Pe=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],Be=(r={})=>Object.keys(r).map(e=>`${e}="${r[e]}"`).join(" "),De=(r={})=>Object.keys(r).map(e=>`${e}: ${r[e]}`).join("; ");function Ue(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}const j=r=>Object.fromEntries(Object.entries(r).filter(([e,t])=>t!==void 0));function K(r,e={},t){const o=Be(e),n=o?`${r} ${o}`:r,s=Array.isArray(t)?t.join(""):t||"";if(r){if(Pe.includes(r))return`<${n}>`}else return s;return`<${n}>${s}</${r}>`}function ze(r={}){let e=0;const{renderFn:t=K,textFn:o=Ue,resolvers:n={},optimizeImages:s=!1,keyedResolvers:l=!1}=r,d=t!==K,i=a=>c=>{const u=c.attrs||{};return l&&(u.key=`${a}-${e}`),t(a,u,c.children||null)},p=a=>{const{src:c,alt:u,title:f,srcset:E,sizes:y}=a.attrs||{};let h=c,$={};if(s){const{src:ct,attrs:ut}=Ne(c,s);h=ct,$=ut}l&&($={...$,key:`img-${e}`});const it={src:h,alt:u,title:f,srcset:E,sizes:y,...$};return t("img",j(it))},g=a=>{const{level:c,...u}=a.attrs||{},f={...u};return l&&(f.key=`h${c}-${e}`),t(`h${c}`,f,a.children)},w=a=>{var c,u,f,E;const y=t("img",{src:(c=a.attrs)==null?void 0:c.fallbackImage,alt:(u=a.attrs)==null?void 0:u.alt,style:"width: 1.25em; height: 1.25em; vertical-align: text-top",draggable:"false",loading:"lazy"}),h={"data-type":"emoji","data-name":(f=a.attrs)==null?void 0:f.name,"data-emoji":(E=a.attrs)==null?void 0:E.emoji};return l&&(h.key=`emoji-${e}`),t("span",h,y)},C=a=>t("pre",{...a.attrs,key:`code-${e}`},t("code",{key:`code-${e}`},a.children||"")),T=(a,c=!1)=>({text:u,attrs:f})=>{const{class:E,id:y,...h}=f||{},$=c?{class:E,id:y,style:De(h)||void 0}:f||{};return l&&($.key=`${a}-${e}`),t(a,j($),u)},k=a=>N(a),I=a=>{const{marks:c,...u}=a;return"text"in a?c?c.reduce((f,E)=>k({...E,text:f}),k({...u,children:u.children})):o(u.text):""},R=a=>{const{linktype:c,href:u,anchor:f,...E}=a.attrs||{};let y="";switch(c){case A.ASSET:case A.URL:y=u;break;case A.EMAIL:y=`mailto:${u}`;break;case A.STORY:y=u,f&&(y=`${y}#${f}`);break;default:y=u;break}const h={...E};return y&&(h.href=y),l&&(h.key=`a-${e}`),t("a",h,a.text)},rt=a=>{var c,u;return console.warn("[StoryblokRichtText] - BLOK resolver is not available for vanilla usage"),t("span",{blok:(c=a==null?void 0:a.attrs)==null?void 0:c.body[0],id:(u=a.attrs)==null?void 0:u.id,key:`component-${e}`,style:"display: none"})},ot=a=>{const c={};return l&&(c.key=`table-${e}`),t("table",c,a.children)},st=a=>{const c={};return l&&(c.key=`tr-${e}`),t("tr",c,a.children)},nt=a=>{const{colspan:c,rowspan:u,colwidth:f,backgroundColor:E,...y}=a.attrs||{},h={...y};c>1&&(h.colspan=c),u>1&&(h.rowspan=u);const $=[];return f&&$.push(`width: ${f}px;`),E&&$.push(`background-color: ${E};`),$.length>0&&(h.style=$.join(" ")),l&&(h.key=`td-${e}`),t("td",j(h),a.children)},at=a=>{const{colspan:c,rowspan:u,colwidth:f,backgroundColor:E,...y}=a.attrs||{},h={...y};c>1&&(h.colspan=c),u>1&&(h.rowspan=u);const $=[];return f&&$.push(`width: ${f}px;`),E&&$.push(`background-color: ${E};`),$.length>0&&(h.style=$.join(" ")),l&&(h.key=`th-${e}`),t("th",j(h),a.children)},lt=new Map([[b.DOCUMENT,i("")],[b.HEADING,g],[b.PARAGRAPH,i("p")],[b.UL_LIST,i("ul")],[b.OL_LIST,i("ol")],[b.LIST_ITEM,i("li")],[b.IMAGE,p],[b.EMOJI,w],[b.CODE_BLOCK,C],[b.HR,i("hr")],[b.BR,i("br")],[b.QUOTE,i("blockquote")],[b.COMPONENT,rt],[M.TEXT,I],[v.LINK,R],[v.ANCHOR,R],[v.STYLED,T("span",!0)],[v.BOLD,T("strong")],[v.TEXT_STYLE,T("span",!0)],[v.ITALIC,T("em")],[v.UNDERLINE,T("u")],[v.STRIKE,T("s")],[v.CODE,T("code")],[v.SUPERSCRIPT,T("sup")],[v.SUBSCRIPT,T("sub")],[v.HIGHLIGHT,T("mark")],[b.TABLE,ot],[b.TABLE_ROW,st],[b.TABLE_CELL,nt],[b.TABLE_HEADER,at],...Object.entries(n).map(([a,c])=>[a,c])]);function O(a){e+=1;const c=lt.get(a.type);if(!c)return console.error("<Storyblok>",`No resolver found for node type ${a.type}`),"";if(a.type==="text")return c(a);const u=a.content?a.content.map(N):void 0;return c({...a,children:u})}function N(a){return a.type==="doc"?d?a.content.map(O):a.content.map(O).join(""):Array.isArray(a)?a.map(O):O(a)}return{render:N}}let He,Fe="https://app.storyblok.com/f/storyblok-v2-latest.js";const qe=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},Ge=r=>{var e;return!r||!((e=r==null?void 0:r.content)!=null&&e.some(t=>t.content||t.type==="blok"||t.type==="horizontal_rule"))},Ke=(r,e,t)=>{let o=t||He;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return Ge(r)?"":(e&&(o=new G(e.schema),e.resolver&&qe(o,e.resolver)),o.render(r,{},!1))},Je=()=>se(Fe);function We(){if(!(globalThis!=null&&globalThis.storyblokApiInstance))throw new Error("storyblokApiInstance has not been initialized correctly");return globalThis.storyblokApiInstance}async function Ye(r){let e=null;return r&&r.locals._storyblok_preview_data&&(e=r.locals._storyblok_preview_data),e}function Ve(r,e){var o;const t=(o=globalThis==null?void 0:globalThis.storyblokApiInstance)==null?void 0:o.richTextResolver;if(!t)throw new Error("Please initialize the Storyblok SDK before calling the renderRichText function");return Ke(r,e,t)}function Xe(r){return typeof r=="object"?`const storyblokInstance = new StoryblokBridge(${JSON.stringify(r)});`:"const storyblokInstance = new StoryblokBridge();"}function Ze(r){const e={useCustomApi:!1,bridge:!0,componentsDir:"src",enableFallbackComponent:!1,livePreview:!1,...r},t=Xe(e.bridge);return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:o,updateConfig:n,addDevToolbarApp:s,addMiddleware:l,config:d})=>{if(n({vite:{plugins:[re(e.accessToken,e.useCustomApi,e.apiOptions),te(e.componentsDir,e.components,e.enableFallbackComponent,e.customFallbackComponent),oe(e)]}}),e.livePreview&&(d==null?void 0:d.output)!=="server")throw new Error("To utilize the Astro Storyblok Live feature, Astro must be configured to run in SSR mode. Please disable this feature or switch Astro to SSR mode.");o("page-ssr",`
|
|
44
44
|
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
45
45
|
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
46
|
-
`),e.bridge&&!e.livePreview&&
|
|
46
|
+
`),e.bridge&&!e.livePreview&&o("page",`import { loadStoryblokBridge } from "@storyblok/astro";
|
|
47
47
|
loadStoryblokBridge().then(() => {
|
|
48
48
|
const { StoryblokBridge, location } = window;
|
|
49
49
|
${t}
|
|
@@ -53,10 +53,10 @@ Detailed information can be found here: https://github.com/storyblok/storyblok-a
|
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
|
-
`),e.livePreview&&(
|
|
56
|
+
`),e.livePreview&&(o("page",`import { loadStoryblokBridge, handleStoryblokMessage } from "@storyblok/astro";
|
|
57
57
|
loadStoryblokBridge().then(() => {
|
|
58
58
|
const { StoryblokBridge, location } = window;
|
|
59
59
|
${t}
|
|
60
60
|
storyblokInstance.on(["published", "change", "input"], handleStoryblokMessage);
|
|
61
61
|
});
|
|
62
|
-
`),
|
|
62
|
+
`),l({entrypoint:"@storyblok/astro/middleware.ts",order:"pre"})),s({id:"storyblok",name:"Storyblok",icon:L,entrypoint:"@storyblok/astro/toolbarApp.ts"})}}}}let J;async function Qe(r){const{action:e,story:t}=r||{};if(e==="input"&&t){const o=async()=>{const s=await tt(t),l=document.body;if(s.outerHTML===l.outerHTML)return;const d=document.querySelector('[data-blok-focused="true"]');et(l,s,d),document.dispatchEvent(new Event("storyblok-live-preview-updated"))};clearTimeout(J),J=setTimeout(o,500)}["published","change"].includes(r==null?void 0:r.action)&&location.reload()}function et(r,e,t){if(t){const o=t.getAttribute("data-blok-uid"),n=e.querySelector(`[data-blok-uid="${o}"]`);n&&(n.setAttribute("data-blok-focused","true"),t.replaceWith(n))}else r.replaceWith(e)}async function tt(r){const t=await(await fetch(location.href,{method:"POST",body:JSON.stringify({...r,is_storyblok_preview:!0}),headers:{"Content-Type":"application/json"}})).text();return new DOMParser().parseFromString(t,"text/html").body}m.RichTextResolver=G,m.RichTextSchema=F,m.TextTypes=M,m.getLiveStory=Ye,m.handleStoryblokMessage=Qe,m.loadStoryblokBridge=Je,m.renderRichText=Ve,m.richTextResolver=ze,m.storyblok=Ze,m.storyblokEditable=Me,m.toCamelCase=_,m.useStoryblokApi=We,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.1.
|
|
4
|
+
"version": "6.1.1",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@9.13.2",
|
|
7
7
|
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
@@ -66,13 +66,14 @@
|
|
|
66
66
|
"test:e2e": "start-server-and-test playground:test http://localhost:4321/ cy:run",
|
|
67
67
|
"test:e2e-watch": "start-server-and-test playground:test http://localhost:4321/ cy:open",
|
|
68
68
|
"cy:run": "cypress run",
|
|
69
|
-
"cy:open": "cypress open"
|
|
69
|
+
"cy:open": "cypress open",
|
|
70
|
+
"check-licenses": "node scripts/license-checker.mjs"
|
|
70
71
|
},
|
|
71
72
|
"peerDependencies": {
|
|
72
73
|
"astro": "^3.0.0 || ^4.0.0 || ^5.0.0"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
75
|
-
"@storyblok/js": "3.
|
|
76
|
+
"@storyblok/js": "3.3.0",
|
|
76
77
|
"camelcase": "^8.0.0"
|
|
77
78
|
},
|
|
78
79
|
"devDependencies": {
|
|
@@ -89,6 +90,7 @@
|
|
|
89
90
|
"eslint-config-prettier": "^9.1.0",
|
|
90
91
|
"eslint-plugin-astro": "^1.3.1",
|
|
91
92
|
"eslint-plugin-cypress": "^4.1.0",
|
|
93
|
+
"license-checker": "^25.0.1",
|
|
92
94
|
"lint-staged": "^15.2.10",
|
|
93
95
|
"prettier": "^3.3.3",
|
|
94
96
|
"prettier-plugin-astro": "^0.13.0",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Loader } from 'astro/loaders';
|
|
2
|
-
import { ISbConfig, ISbStoriesParams } from '@storyblok/js';
|
|
3
|
-
interface StoryblokLoaderConfig {
|
|
4
|
-
accessToken: string;
|
|
5
|
-
version: 'draft' | 'published';
|
|
6
|
-
useCustomApi?: boolean;
|
|
7
|
-
apiOptions?: ISbConfig;
|
|
8
|
-
storiesParams?: ISbStoriesParams;
|
|
9
|
-
}
|
|
10
|
-
export declare function storyblokLoader(config: StoryblokLoaderConfig): Loader;
|
|
11
|
-
export {};
|