@storyblok/astro 1.1.1 → 1.2.0

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  <img src="https://a.storyblok.com/f/88751/1500x500/7974d6bc34/storyblok-astro.png" width="300" height="100" alt="Storyblok + Astro">
4
4
  </a>
5
5
  <h1 align="center">@storyblok/astro</h1>
6
- <p align="center">Astro module for the <a href="http://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro" target="_blank">Storyblok</a> Headless CMS.</p> <br />
6
+ <p align="center">Astro integration for the <a href="http://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro" target="_blank">Storyblok</a> Headless CMS.</p> <br />
7
7
  </div>
8
8
 
9
9
  <p align="center">
@@ -22,7 +22,7 @@
22
22
  <a href="https://twitter.com/intent/follow?screen_name=storyblok">
23
23
  <img src="https://img.shields.io/badge/Follow-%40storyblok-09b3af?style=appveyor&logo=twitter" alt="Follow @Storyblok" />
24
24
  </a><br/>
25
- <a href="https://app.storyblok.com/#!/signup?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-nuxt">
25
+ <a href="https://app.storyblok.com/#!/signup?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro">
26
26
  <img src="https://img.shields.io/badge/Try%20Storyblok-Free-09b3af?style=appveyor&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAAHqADAAQAAAABAAAAHgAAAADpiRU/AAACRElEQVRIDWNgGGmAEd3D3Js3LPrP8D8WXZwSPiMjw6qvPoHhyGYwIXNAbGpbCjbzP0MYuj0YFqMroBV/wCxmIeSju64eDNzMBJUxvP/9i2Hnq5cM1devMnz984eQsQwETeRhYWHgIcJiXqC6VHlFBjUeXgav40cIWkz1oLYXFmGwFBImaDFBHyObcOzdW4aSq5eRhRiE2dgYlpuYoYSKJi8vw3GgWnyAJIs/AuPu4scPGObd/fqVQZ+PHy7+6udPOBsXgySLDfn5GRYYmaKYJcXBgWLpsx8/GPa8foWiBhuHJIsl2DkYQqWksZkDFgP5PObcKYYff//iVAOTIDlx/QPqRMb/YSYBaWlOToZIaVkGZmAZSQiQ5OPtwHwacuo4iplMQEu6tXUZMhSUGDiYmBjylFQYvv/7x9B04xqKOnQOyT5GN+Df//8M59ASXKyMHLoyDD5JPtbj42OYrm+EYgg70JfuYuIoYmLs7AwMjIzA+uY/zjAnyWJpDk6GOFnCvrn86SOwmsNtKciVFAc1ileBHFDC67lzG10Yg0+SjzF0ownsf/OaofvOLYaDQJoQIGix94ljv1gIZI8Pv38zPvj2lQWYf3HGKbpDCFp85v07NnRN1OBTPY6JdRSGxcCw2k6sZuLVMZ5AV4s1TozPnGGFKbz+/PE7IJsHmC//MDMyhXBw8e6FyRFLv3Z0/IKuFqvFyIqAzd1PwBzJw8jAGPfVx38JshwlbIygxmYY43/GQmpais0ODDHuzevLMARHBcgIAQAbOJHZW0/EyQAAAABJRU5ErkJggg==" alt="Follow @Storyblok" />
27
27
  </a>
28
28
  </p>
@@ -31,9 +31,9 @@
31
31
 
32
32
  If you are in a hurry, check out our official **[live demo](https://stackblitz.com/edit/astro-sdk-demo)** on StackBlitz.
33
33
 
34
- ## 🚀 Usage
34
+ ## Usage
35
35
 
36
- > If you are first-time user of Storyblok, read the [Getting Started](https://www.storyblok.com/docs/guide/getting-started?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-nuxt) guide to get a project ready in less than 5 minutes.
36
+ > If you are first-time user of Storyblok, read the [Getting Started](https://www.storyblok.com/docs/guide/getting-started?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro) guide to get a project ready in less than 5 minutes.
37
37
 
38
38
  ## Installation
39
39
 
@@ -61,7 +61,7 @@ export default defineConfig({
61
61
 
62
62
  ### Options
63
63
 
64
- When you initialize the module, you can pass all [_@storyblok/js_ options](https://github.com/storyblok/storyblok-js#features-and-api). For Spaces created in the United States, you have to set the `region` parameter accordingly `{ apiOptions: { region: 'us' } }`.
64
+ When you initialize the integration, you can pass all [_@storyblok/js_ options](https://github.com/storyblok/storyblok-js#features-and-api). For spaces created in the United States, you have to set the `region` parameter accordingly `{ apiOptions: { region: 'us' } }`.
65
65
 
66
66
  ```js
67
67
  // Defaults
@@ -69,11 +69,11 @@ storyblok({
69
69
  accessToken: "<your-access-token>",
70
70
  bridge: true,
71
71
  apiOptions: {}, // storyblok-js-client options
72
- use: [apiPlugin],
72
+ useCustomApi: false,
73
73
  });
74
74
  ```
75
75
 
76
- > Note: if you don't use `apiPlugin`, you can use your preferred method or function to fetch your data.
76
+ > Note: By default, the apiPlugin from `@storyblok/js` is loaded. If you want to use your own method to fetch data from Storyblok, you can disable this behavior by setting `useCustomApi` to `true`, resulting in an optimized final bundle.
77
77
 
78
78
  ## Getting started
79
79
 
@@ -125,7 +125,7 @@ const { blok } = Astro.props
125
125
  ---
126
126
 
127
127
  <main {...storyblokEditable(blok)}>
128
- {blok.body?.map(blok => {return <StoryblokComponent blok={blok} />})}
128
+ {blok.body?.map(blok => {return <StoryblokComponent blok="{blok}" />})}
129
129
  </main>
130
130
  ```
131
131
 
@@ -160,7 +160,7 @@ const { data } = await storyblokApi.get("cdn/stories/home", {
160
160
  const story = data.story;
161
161
  ---
162
162
 
163
- <StoryblokComponent blok={story.content} />
163
+ <StoryblokComponent blok="{story.content}" />
164
164
  ```
165
165
 
166
166
  > Note: The available methods are described in the [storyblok-js-client] repository(https://github.com/storyblok/storyblok-js-client#method-storyblokget)
@@ -201,15 +201,17 @@ const { data } = await storyblokApi.get(`cdn/stories/${slug}`, {
201
201
  const story = data.story;
202
202
  ---
203
203
 
204
- <StoryblokComponent blok={story.content} />
204
+ <StoryblokComponent blok="{story.content}" />
205
205
  ```
206
206
 
207
207
  ### Using the Storyblok Bridge
208
208
 
209
- The Storyblok Bridge is automatically activated by default. If you would like to disable it or enable it conditionally (e.g. depending on the environment) you can set the `bridge` parameter to `false` in `astro.config.mjs`:
209
+ The Storyblok Bridge is enabled by default. If you would like to disable it or enable it conditionally (e.g. depending on the environment) you can set the `bridge` parameter to `true` or `false` in `astro.config.mjs`:
210
210
 
211
211
  > Note: Since Astro is not a reactive JavaScript framework and renders everything as HTML, the Storyblok Bridge will not provide real-time editing as you may know it from other frameworks. However, it automatically refreshes the site for you whenever you save or publish a story.
212
212
 
213
+ If you want to deploy a dedicated preview environment with the Bridge enabled, allowing users of the Storyblok CMS to see their changes being reflected on the frontend directly without having to rebuild the static site, you can enable Server Side Rendering for that particular use case. More information can be found in the [Astro Docs](https://docs.astro.build/en/guides/server-side-rendering/).
214
+
213
215
  ### Rendering Rich Text
214
216
 
215
217
  You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/astro`. Then you can use the [`set:html` directive](https://docs.astro.build/en/reference/directives-reference/#sethtml):
@@ -223,7 +225,7 @@ const { blok } = Astro.props
223
225
  const renderedRichText = renderRichText(blok.text)
224
226
  ---
225
227
 
226
- <div set:html={renderedRichText}></div>
228
+ <div set:html="{renderedRichText}"></div>
227
229
  ```
228
230
 
229
231
  You can also set a **custom Schema and component resolver** by passing the options as the second parameter of the `renderRichText` function:
@@ -234,9 +236,9 @@ import cloneDeep from "clone-deep";
234
236
 
235
237
  const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
236
238
  // ... and edit the nodes and marks, or add your own.
237
- // Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js
239
+ // Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/v4/source/schema.js
238
240
 
239
- const { blok } = Astro.props
241
+ const { blok } = Astro.props;
240
242
 
241
243
  const renderedRichText = renderRichText(blok.text, {
242
244
  schema: mySchema,
@@ -260,21 +262,22 @@ Returns the instance of the `storyblok-js-client`.
260
262
 
261
263
  ## Acknowledgements
262
264
 
263
- A huge thank you goes to the Astro Team. In particular to [Tony Sull](https://github.com/tony-sull), who has provided extraordinary support and made automagically rendering Storyblok components a reality.
265
+ A huge thank you goes to the Astro Team. In particular to [Tony Sullivan](https://github.com/tony-sull), who has provided extraordinary support and made _automagically_ rendering Storyblok components a reality.
264
266
 
265
- ## 🔗 Related Links
267
+ ## Related Links
266
268
 
267
269
  - **[Live Demo on Stackblitz](https://stackblitz.com/edit/astro-sdk-demo)**
268
270
  - **[Storyblok CLI](https://github.com/storyblok/storyblok)**: A simple CLI for scaffolding Storyblok projects and fieldtypes.
269
271
 
270
- ## â„šī¸ More Resources
272
+ ## More Resources
271
273
 
272
274
  ### Support
273
275
 
274
276
  - Bugs or Feature Requests? [Submit an issue](/../../issues/new);
275
- - Do you have questions about Storyblok or you need help? [Join our Discord Community](https://discord.gg/jKrbAMz).
277
+ - Do you have questions about this SDK? Or would you like to join the growing community of `@storyblok/astro` users? [Join the Astro Discord Community](https://discord.com/channels/830184174198718474/1002802280267001858)
278
+ - Do you have questions about Storyblok or you need help? [Join the Storyblok Discord Community](https://discord.gg/jKrbAMz).
276
279
 
277
280
  ### Contributing
278
281
 
279
282
  Please see our [contributing guidelines](https://github.com/storyblok/.github/blob/master/contributing.md) and our [code of conduct](https://www.storyblok.com/trust-center#code-of-conduct?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro).
280
- This project use [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for generate new versions by using commit messages and we use the Angular Convention to naming the commits. Check [this question](https://semantic-release.gitbook.io/semantic-release/support/faq#how-can-i-change-the-type-of-commits-that-trigger-a-release) about it in semantic-release FAQ.
283
+ This project uses [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for generating new versions by using commit messages. We use the Angular Convention to name the commits.
@@ -1,19 +1,26 @@
1
- (function(u,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],p):(u=typeof globalThis<"u"?globalThis:u||self,p(u.storyblokAstro={},u.axios))})(this,function(u,p){"use strict";const M=(s=>s&&typeof s=="object"&&"default"in s?s:{default:s})(p),U=/[\p{Lu}]/u,D=/[\p{Ll}]/u,T=/^[\p{Lu}](?![\p{Lu}])/gu,_=/([\p{Alpha}\p{N}_]|$)/u,m=/[_.\- ]+/,q=new RegExp("^"+m.source),R=new RegExp(m.source+_.source,"gu"),w=new RegExp("\\d+"+_.source,"gu"),B=(s,e,t)=>{let r=!1,o=!1,n=!1;for(let i=0;i<s.length;i++){const a=s[i];r&&U.test(a)?(s=s.slice(0,i)+"-"+s.slice(i),r=!1,n=o,o=!0,i++):o&&n&&D.test(a)?(s=s.slice(0,i-1)+"-"+s.slice(i-1),n=o,o=!1,r=!0):(r=e(a)===a&&t(a)!==a,n=o,o=t(a)===a&&e(a)!==a)}return s},z=(s,e)=>(T.lastIndex=0,s.replace(T,t=>e(t))),H=(s,e)=>(R.lastIndex=0,w.lastIndex=0,s.replace(R,(t,r)=>e(r)).replace(w,t=>e(t)));function E(s,e){if(!(typeof s=="string"||Array.isArray(s)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(s)?s=s.map(n=>n.trim()).filter(n=>n.length).join("-"):s=s.trim(),s.length===0)return"";const t=e.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(e.locale),r=e.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(e.locale);return s.length===1?m.test(s)?"":e.pascalCase?r(s):t(s):(s!==t(s)&&(s=B(s,t,r)),s=s.replace(q,""),s=e.preserveConsecutiveUppercase?z(s,t):t(s),e.pascalCase&&(s=r(s.charAt(0))+s.slice(1)),H(s,r))}function V(s){const e="virtual:storyblok-components",t="\0"+e;return{name:"vite-plugin-storyblok",async resolveId(r){if(r===e)return t},async load(r){if(r===t){const o=[];for await(const[n,i]of Object.entries(s)){const{id:a}=await this.resolve("/src/"+i+".astro");o.push(`import ${E(n)} from "${a}"`)}return`${o.join(";")};export default {${Object.keys(s).map(n=>E(n)).join(",")}}`}}}}var F=Object.defineProperty,J=Object.defineProperties,G=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,Y=Object.prototype.propertyIsEnumerable,$=(s,e,t)=>e in s?F(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,d=(s,e)=>{for(var t in e||(e={}))K.call(e,t)&&$(s,t,e[t]);if(A)for(var t of A(e))Y.call(e,t)&&$(s,t,e[t]);return s},k=(s,e)=>J(s,G(e));let S=!1;const O=[],x=s=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=o=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}S?o():O.push(o)},document.getElementById("storyblok-javascript-bridge")))return;const r=document.createElement("script");r.async=!0,r.src=s,r.id="storyblok-javascript-bridge",r.onerror=o=>t(o),r.onload=o=>{O.forEach(n=>n()),S=!0,e(o)},document.getElementsByTagName("head")[0].appendChild(r)}),W=function(s,e){if(!s)return null;let t={};for(let r in s){let o=s[r];e.indexOf(r)>-1&&o!==null&&(t[r]=o)}return t},Q=s=>s==="email";var C={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(s){return{tag:["pre",{tag:"code",attrs:s.attrs}]}},hard_break(){return{singleTag:"br"}},heading(s){return{tag:`h${s.attrs.level}`}},image(s){return{singleTag:[{tag:"img",attrs:W(s.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(s){const e=d({},s.attrs),{linktype:t="url"}=s.attrs;return Q(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled(s){return{tag:[{tag:"span",attrs:s.attrs}]}}}};const X=function(s){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,r=RegExp(t.source);return s&&r.test(s)?s.replace(t,o=>e[o]):s};class I{constructor(e){e||(e=C),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(r=>{t+=this.renderNode(r)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderOpeningTag(n.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(X(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderClosingTag(n.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(let i in o.attrs){let a=o.attrs[i];a!==null&&(n+=` ${i}="${a}"`)}return`${n}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}/*!
2
- * storyblok-js-client v4.5.2
3
- * Universal JavaScript SDK for Storyblok's API
4
- * (c) 2020-2022 Stobylok Team
5
- */function j(s){return typeof s=="number"&&s==s&&s!==1/0&&s!==-1/0}function P(s,e,t){if(!j(e))throw new TypeError("Expected `limit` to be a finite number");if(!j(t))throw new TypeError("Expected `interval` to be a finite number");var r=[],o=[],n=0,i=function(){n++;var c=setTimeout(function(){n--,r.length>0&&i(),o=o.filter(function(h){return h!==c})},t);o.indexOf(c)<0&&o.push(c);var l=r.shift();l.resolve(s.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(h,g){r.push({resolve:h,reject:g,args:c,self:l}),n<e&&i()})};return a.abort=function(){o.forEach(clearTimeout),o=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}P.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const Z=function(s,e){if(!s)return null;let t={};for(let r in s){let o=s[r];e.indexOf(r)>-1&&o!==null&&(t[r]=o)}return t};var ee={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:s=>({tag:`h${s.attrs.level}`}),image:s=>({singleTag:[{tag:"img",attrs:Z(s.attrs,["src","alt","title"])}]}),list_item:()=>({tag:"li"}),ordered_list:()=>({tag:"ol"}),paragraph:()=>({tag:"p"})},marks:{bold:()=>({tag:"b"}),strike:()=>({tag:"strike"}),underline:()=>({tag:"u"}),strong:()=>({tag:"strong"}),code:()=>({tag:"code"}),italic:()=>({tag:"i"}),link(s){const e=d({},s.attrs),{linktype:t="url"}=s.attrs;return t==="email"&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled:s=>({tag:[{tag:"span",attrs:s.attrs}]})}};class te{constructor(e){e||(e=ee),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(r=>{t+=this.renderNode(r)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderOpeningTag(n.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(o=>{t.push(this.renderNode(o))}):e.text?t.push(function(o){const n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},i=/[&<>"']/g,a=RegExp(i.source);return o&&a.test(o)?o.replace(i,c=>n[c]):o}(e.text)):r&&r.singleTag?t.push(this.renderTag(r.singleTag," /")):r&&r.html&&t.push(r.html),r&&r.tag&&t.push(this.renderClosingTag(r.tag)),e.marks&&e.marks.slice(0).reverse().forEach(o=>{const n=this.getMatchingMark(o);n&&t.push(this.renderClosingTag(n.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let o=`<${r.tag}`;if(r.attrs)for(let n in r.attrs){let i=r.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){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}const re=(s=0,e=s)=>{const t=Math.abs(e-s)||0,r=s<e?1:-1;return((o=0,n)=>[...Array(o)].map(n))(t,(o,n)=>n*r+s)},b=(s,e,t)=>{const r=[];for(const o in s){if(!Object.prototype.hasOwnProperty.call(s,o))continue;const n=s[o],i=t?"":encodeURIComponent(o);let a;a=typeof n=="object"?b(n,e?e+encodeURIComponent("["+i+"]"):i,Array.isArray(n)):(e?e+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(n),r.push(a)}return r.join("&")};let y={},f={};class se{constructor(e,t){if(!t){let n=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${i}://api${n}.storyblok.com/v2`:`${i}://api${n}.storyblok.com/v1`}let r=Object.assign({},e.headers),o=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,o=3),e.rateLimit!==void 0&&(o=e.rateLimit),this.richTextResolver=new te(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=P(this.throttledRequest,o,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=M.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(n=>e.responseInterceptor(n)),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(o=>{r+=e(o.component,o)}),{html:r}})}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=f[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t={}){return((r="")=>r.indexOf("/cdn/")>-1)(e)?this.parseParams(t):t}makeRequest(e,t,r,o){const n=this.factoryParamOptions(e,((i={},a=25,c=1)=>k(d({},i),{per_page:a,page:c}))(t,r,o));return this.cacheResponse(e,n)}get(e,t){let r=`/${e}`;const o=this.factoryParamOptions(r,t);return this.cacheResponse(r,o)}async getAll(e,t={},r){const o=t.per_page||25,n=`/${e}`,i=n.split("/");r=r||i[i.length-1];const a=await this.makeRequest(n,t,o,1),c=Math.ceil(a.total/o);return((l=[],h)=>l.map(h).reduce((g,fe)=>[...g,...fe],[]))([a,...await(async(l=[],h)=>Promise.all(l.map(h)))(re(1,c),async l=>this.makeRequest(n,t,o,l+1))],l=>Object.values(l.data[r]))}post(e,t){let r=`/${e}`;return this.throttle("post",r,t)}put(e,t){let r=`/${e}`;return this.throttle("put",r,t)}delete(e,t){let r=`/${e}`;return this.throttle("delete",r,t)}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}setToken(e){this.accessToken=e}getToken(){return this.accessToken}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const r=e[t];r&&r.fieldtype=="multilink"&&r.linktype=="story"&&typeof r.id=="string"&&this.links[r.id]?r.story=this._cleanCopy(this.links[r.id]):r&&r.linktype==="story"&&typeof r.uuid=="string"&&this.links[r.uuid]&&(r.story=this._cleanCopy(this.links[r.uuid]))}_insertRelations(e,t,r){if(r.indexOf(e.component+"."+t)>-1){if(typeof e[t]=="string")this.relations[e[t]]&&(e[t]=this._cleanCopy(this.relations[e[t]]));else if(e[t].constructor===Array){let o=[];e[t].forEach(n=>{this.relations[n]&&o.push(this._cleanCopy(this.relations[n]))}),e[t]=o}}}_insertAssetsRelations(e,t){t.forEach(r=>{e.id===r.id&&(e.original=r,e.original.filename=e.filename,e.original.filename=e.original.filename.includes("https://s3.amazonaws.com/")?e.original.filename:e.original.filename.replace("https://","https://s3.amazonaws.com/"),delete e.original.s3_filename)})}iterateTree(e,t){let r=o=>{if(o!=null){if(o.constructor===Array)for(let n=0;n<o.length;n++)r(o[n]);else if(o.constructor===Object){if(o._stopResolving)return;for(let n in o)o.component&&o._uid||o.type==="link"?(this._insertRelations(o,n,t),this._insertLinks(o,n)):"id"in o&&o.fieldtype==="asset"&&this._insertAssetsRelations(o,t),r(o[n])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const o=e.link_uuids.length;let n=[];const i=50;for(let a=0;a<o;a+=i){const c=Math.min(o,a+i);n.push(e.link_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(o=>{this.links[o.uuid]=k(d({},o),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const o=e.rel_uuids.length;let n=[];const i=50;for(let a=0;a<o;a+=i){const c=Math.min(o,a+i);n.push(e.rel_uuids.slice(a,c))}for(let a=0;a<n.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:n[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r.forEach(o=>{this.relations[o.uuid]=k(d({},o),{_stopResolving:!0})})}async resolveStories(e,t){let r=[];if(t.resolve_relations!==void 0&&t.resolve_relations.length>0&&(e.rels||e.rel_uuids)&&(r=t.resolve_relations.split(","),await this.resolveRelations(e,t)),["1","story","url"].indexOf(t.resolve_links)>-1&&(e.links||e.link_uuids)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const o in this.relations)this.iterateTree(this.relations[o],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(o=>{this.iterateTree(o,r)})}resolveAssetsRelations(e){const{assets:t,stories:r,story:o}=e;if(r)for(const n of r)this.iterateTree(n,t);else{if(!o)return e;this.iterateTree(o,t)}}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(o,n)=>{let i=b({url:e,params:t}),a=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await a.get(i);if(l)return o(l)}try{let l=await this.throttle("get",e,{params:t,paramsSerializer:g=>b(g)}),h={data:l.data,headers:l.headers};if(h.data.assets&&h.data.assets.length&&this.resolveAssetsRelations(h.data),l.headers["per-page"]&&(h=Object.assign({},h,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return n(l);(h.data.story||h.data.stories)&&await this.resolveStories(h.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&a.set(i,h),h.data.cv&&(t.version=="draft"&&f[t.token]!=h.data.cv&&this.flushCache(),f[t.token]=h.data.cv),o(h)}catch(l){if(l.response&&l.response.status===429&&(r+=1)<this.maxRetries)return console.log(`Hit rate limit. Retrying in ${r} seconds.`),await(c=1e3*r,new Promise(h=>setTimeout(h,c))),this.cacheResponse(e,t,r).then(o).catch(n);n(l)}var c})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return f}cacheVersion(){return f[this.accessToken]}setCacheVersion(e){this.accessToken&&(f[this.accessToken]=e)}cacheProvider(){return this.cache.type==="memory"?{get:e=>y[e],getAll:()=>y,set(e,t){y[e]=t},flush(){y={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const oe=(s={})=>{const{apiOptions:e}=s;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 se(e)}};var ne=s=>{if(typeof s!="object"||typeof s._editable>"u")return{};const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let v;const N="https://app.storyblok.com/f/storyblok-v2-latest.js",ae=(s={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:o={},richText:n={}}=s;o.accessToken=o.accessToken||t;const i={bridge:e,apiOptions:o};let a={};return r.forEach(c=>{a=d(d({},a),c(i))}),e!==!1&&x(N),v=new I(n.schema),n.resolver&&L(v,n.resolver),a},L=(s,e)=>{s.addNode("blok",t=>{let r="";return t.attrs.body.forEach(o=>{r+=e(o.component,o)}),{html:r}})},ie=(s,e,t)=>{let r=t||v;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return s===""?"":s?(e&&(r=new I(e.schema),e.resolver&&L(r,e.resolver)),r.render(s)):(console.warn(`${s} is not a valid Richtext object. This might be because the value of the richtext field is empty.
1
+ (function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.storyblokAstro={}))})(this,function(i){"use strict";function c(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`
2
+ import { storyblokInit, apiPlugin } from "@storyblok/js";
3
+ const { storyblokApi } = storyblokInit({
4
+ accessToken: "${r}",
5
+ use: ${e?"[]":"[apiPlugin]"},
6
+ apiOptions: ${JSON.stringify(t)},
7
+ });
8
+ export const storyblokApiInstance = storyblokApi;
9
+ `}}}const T=/[\p{Lu}]/u,I=/[\p{Ll}]/u,d=/^[\p{Lu}](?![\p{Lu}])/gu,f=/([\p{Alpha}\p{N}_]|$)/u,u=/[_.\- ]+/,E=new RegExp("^"+u.source),h=new RegExp(u.source+f.source,"gu"),p=new RegExp("\\d+"+f.source,"gu"),A=(r,e,t)=>{let o=!1,n=!1,s=!1;for(let l=0;l<r.length;l++){const a=r[l];o&&T.test(a)?(r=r.slice(0,l)+"-"+r.slice(l),o=!1,s=n,n=!0,l++):n&&s&&I.test(a)?(r=r.slice(0,l-1)+"-"+r.slice(l-1),s=n,n=!1,o=!0):(o=e(a)===a&&t(a)!==a,s=n,n=t(a)===a&&e(a)!==a)}return r},S=(r,e)=>(d.lastIndex=0,r.replace(d,t=>e(t))),w=(r,e)=>(h.lastIndex=0,p.lastIndex=0,r.replace(h,(t,o)=>e(o)).replace(p,t=>e(t)));function g(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?u.test(r)?"":e.pascalCase?o(r):t(r):(r!==t(r)&&(r=A(r,t,o)),r=r.replace(E,""),r=e.preserveConsecutiveUppercase?S(r,t):t(r),e.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),w(r,o))}function _(r){const e="virtual:storyblok-components",t="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return t},async load(o){if(o===t){const n=[];for await(const[s,l]of Object.entries(r)){const{id:a}=await this.resolve("/src/"+l+".astro");n.push(`import ${g(s)} from "${a}"`)}return`${n.join(";")};export default {${Object.keys(r).map(s=>g(s)).join(",")}}`}}}}var R=Object.defineProperty,y=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,b=(r,e,t)=>e in r?R(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,x=(r,e)=>{for(var t in e||(e={}))C.call(e,t)&&b(r,t,e[t]);if(y)for(var t of y(e))$.call(e,t)&&b(r,t,e[t]);return r};let k=!1;const m=[],O=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}k?n():m.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=>{m.forEach(s=>s()),k=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)}),P=function(r,e){if(!r)return null;let t={};for(let o in r){let n=r[o];e.indexOf(o)>-1&&n!==null&&(t[o]=n)}return t},N=r=>r==="email";var v={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(r){return{tag:["pre",{tag:"code",attrs:r.attrs}]}},hard_break(){return{singleTag:"br"}},heading(r){return{tag:`h${r.attrs.level}`}},image(r){return{singleTag:[{tag:"img",attrs:P(r.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(r){const e=x({},r.attrs),{linktype:t="url"}=r.attrs;return N(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled(r){return{tag:[{tag:"span",attrs:r.attrs}]}}}};const j=function(r){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},t=/[&<>"']/g,o=RegExp(t.source);return r&&o.test(r)?r.replace(t,n=>e[n]):r};class L{constructor(e){e||(e=v),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(o=>{t+=this.renderNode(o)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&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(j(e.text)):o&&o.singleTag?t.push(this.renderTag(o.singleTag," /")):o&&o.html&&t.push(o.html),o&&o.tag&&t.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&t.push(this.renderClosingTag(s.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(n=>{if(n.constructor===String)return`<${n}${t}>`;{let s=`<${n.tag}`;if(n.attrs)for(let l in n.attrs){let a=n.attrs[l];a!==null&&(s+=` ${l}="${a}"`)}return`${s}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(o=>o.constructor===String?`</${o}>`:`</${o.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}var M=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let B;const U="https://app.storyblok.com/f/storyblok-v2-latest.js",D=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},z=(r,e,t)=>{let o=t||B;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return r===""?"":r?(e&&(o=new L(e.schema),e.resolver&&D(o,e.resolver)),o.render(r)):(console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty.
6
10
 
7
- For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},le=()=>x(N);function ce(s,e,t){const{storyblokApi:r}=ae({accessToken:s,use:e||[oe],apiOptions:{...t}});globalThis.storyblokApiInstance=r}function he(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function ue(s,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ie(s,e,t)}function de(s){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:t})=>{var o;t({vite:{plugins:[V(s.components)]}}),ce(s.accessToken,s.use,s.apiOptions),((o=s.bridge)!=null?o:!0)&&e("page",`
8
- import { loadStoryblokBridge } from "@storyblok/astro";
9
- loadStoryblokBridge().then(() => {
10
- const { StoryblokBridge, location } = window;
11
- const storyblokInstance = new StoryblokBridge();
11
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},H=()=>O(U);function q(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),storyblokApiInstance}function F(r,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return z(r,e,t)}function V(r){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:t})=>{var n;t({vite:{plugins:[c(r.accessToken,r.useCustomApi,r.apiOptions),_(r.components)]}}),e("page-ssr",`
12
+ import { storyblokApiInstance } from "virtual:storyblok-init";
13
+ globalThis.storyblokApiInstance = storyblokApiInstance;
14
+ `),((n=r.bridge)!=null?n:!0)&&e("page",`
15
+ import { loadStoryblokBridge } from "@storyblok/astro";
16
+ loadStoryblokBridge().then(() => {
17
+ const { StoryblokBridge, location } = window;
18
+ const storyblokInstance = new StoryblokBridge();
12
19
 
13
- storyblokInstance.on(["published", "change"], (event) => {
14
- if (!event.slugChanged) {
15
- location.reload(true);
16
- }
17
- });
18
- });
19
- `)}}}}u.RichTextSchema=C,u.default=de,u.loadStoryblokBridge=le,u.renderRichText=ue,u.storyblokEditable=ne,u.useStoryblokApi=he,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
20
+ storyblokInstance.on(["published", "change"], (event) => {
21
+ if (!event.slugChanged) {
22
+ location.reload(true);
23
+ }
24
+ });
25
+ });
26
+ `)}}}}i.RichTextSchema=v,i.default=V,i.loadStoryblokBridge=H,i.renderRichText=F,i.storyblokEditable=M,i.useStoryblokApi=q,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,77 +1,99 @@
1
- import N from "axios";
2
- const L = /[\p{Lu}]/u, M = /[\p{Ll}]/u, v = /^[\p{Lu}](?![\p{Lu}])/gu, O = /([\p{Alpha}\p{N}_]|$)/u, k = /[_.\- ]+/, U = new RegExp("^" + k.source), b = new RegExp(k.source + O.source, "gu"), T = new RegExp("\\d+" + O.source, "gu"), D = (s, e, t) => {
3
- let r = !1, o = !1, n = !1;
4
- for (let i = 0; i < s.length; i++) {
5
- const a = s[i];
6
- r && L.test(a) ? (s = s.slice(0, i) + "-" + s.slice(i), r = !1, n = o, o = !0, i++) : o && n && M.test(a) ? (s = s.slice(0, i - 1) + "-" + s.slice(i - 1), n = o, o = !1, r = !0) : (r = e(a) === a && t(a) !== a, n = o, o = t(a) === a && e(a) !== a);
7
- }
8
- return s;
9
- }, q = (s, e) => (v.lastIndex = 0, s.replace(v, (t) => e(t))), B = (s, e) => (b.lastIndex = 0, T.lastIndex = 0, s.replace(b, (t, r) => e(r)).replace(T, (t) => e(t)));
10
- function _(s, e) {
11
- if (!(typeof s == "string" || Array.isArray(s)))
1
+ import "axios";
2
+ function k(r, e, t) {
3
+ const o = "virtual:storyblok-init", n = "\0" + o;
4
+ return {
5
+ name: "vite-plugin-storyblok-init",
6
+ async resolveId(s) {
7
+ if (s === o)
8
+ return n;
9
+ },
10
+ async load(s) {
11
+ if (s === n)
12
+ return `
13
+ import { storyblokInit, apiPlugin } from "@storyblok/js";
14
+ const { storyblokApi } = storyblokInit({
15
+ accessToken: "${r}",
16
+ use: ${e ? "[]" : "[apiPlugin]"},
17
+ apiOptions: ${JSON.stringify(t)},
18
+ });
19
+ export const storyblokApiInstance = storyblokApi;
20
+ `;
21
+ }
22
+ };
23
+ }
24
+ const m = /[\p{Lu}]/u, v = /[\p{Ll}]/u, c = /^[\p{Lu}](?![\p{Lu}])/gu, b = /([\p{Alpha}\p{N}_]|$)/u, i = /[_.\- ]+/, T = new RegExp("^" + i.source), u = new RegExp(i.source + b.source, "gu"), d = new RegExp("\\d+" + b.source, "gu"), I = (r, e, t) => {
25
+ let o = !1, n = !1, s = !1;
26
+ for (let l = 0; l < r.length; l++) {
27
+ const a = r[l];
28
+ o && m.test(a) ? (r = r.slice(0, l) + "-" + r.slice(l), o = !1, s = n, n = !0, l++) : n && s && v.test(a) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), s = n, n = !1, o = !0) : (o = e(a) === a && t(a) !== a, s = n, n = t(a) === a && e(a) !== a);
29
+ }
30
+ return r;
31
+ }, E = (r, e) => (c.lastIndex = 0, r.replace(c, (t) => e(t))), A = (r, e) => (u.lastIndex = 0, d.lastIndex = 0, r.replace(u, (t, o) => e(o)).replace(d, (t) => e(t)));
32
+ function f(r, e) {
33
+ if (!(typeof r == "string" || Array.isArray(r)))
12
34
  throw new TypeError("Expected the input to be `string | string[]`");
13
35
  if (e = {
14
36
  pascalCase: !1,
15
37
  preserveConsecutiveUppercase: !1,
16
38
  ...e
17
- }, Array.isArray(s) ? s = s.map((n) => n.trim()).filter((n) => n.length).join("-") : s = s.trim(), s.length === 0)
39
+ }, Array.isArray(r) ? r = r.map((s) => s.trim()).filter((s) => s.length).join("-") : r = r.trim(), r.length === 0)
18
40
  return "";
19
- const t = e.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(e.locale), r = e.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(e.locale);
20
- return s.length === 1 ? k.test(s) ? "" : e.pascalCase ? r(s) : t(s) : (s !== t(s) && (s = D(s, t, r)), s = s.replace(U, ""), s = e.preserveConsecutiveUppercase ? q(s, t) : t(s), e.pascalCase && (s = r(s.charAt(0)) + s.slice(1)), B(s, r));
41
+ 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);
42
+ return r.length === 1 ? i.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = I(r, t, o)), r = r.replace(T, ""), r = e.preserveConsecutiveUppercase ? E(r, t) : t(r), e.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), A(r, o));
21
43
  }
22
- function z(s) {
44
+ function w(r) {
23
45
  const e = "virtual:storyblok-components", t = "\0" + e;
24
46
  return {
25
- name: "vite-plugin-storyblok",
26
- async resolveId(r) {
27
- if (r === e)
47
+ name: "vite-plugin-storyblok-components",
48
+ async resolveId(o) {
49
+ if (o === e)
28
50
  return t;
29
51
  },
30
- async load(r) {
31
- if (r === t) {
32
- const o = [];
33
- for await (const [n, i] of Object.entries(s)) {
34
- const { id: a } = await this.resolve("/src/" + i + ".astro");
35
- o.push(`import ${_(n)} from "${a}"`);
52
+ async load(o) {
53
+ if (o === t) {
54
+ const n = [];
55
+ for await (const [s, l] of Object.entries(r)) {
56
+ const { id: a } = await this.resolve("/src/" + l + ".astro");
57
+ n.push(`import ${f(s)} from "${a}"`);
36
58
  }
37
- return `${o.join(";")};export default {${Object.keys(s).map((n) => _(n)).join(",")}}`;
59
+ return `${n.join(";")};export default {${Object.keys(r).map((s) => f(s)).join(",")}}`;
38
60
  }
39
61
  }
40
62
  };
41
63
  }
42
- var H = Object.defineProperty, V = Object.defineProperties, F = Object.getOwnPropertyDescriptors, R = Object.getOwnPropertySymbols, J = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable, w = (s, e, t) => e in s ? H(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, u = (s, e) => {
64
+ var S = Object.defineProperty, h = Object.getOwnPropertySymbols, R = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable, p = (r, e, t) => e in r ? S(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, C = (r, e) => {
43
65
  for (var t in e || (e = {}))
44
- J.call(e, t) && w(s, t, e[t]);
45
- if (R)
46
- for (var t of R(e))
47
- G.call(e, t) && w(s, t, e[t]);
48
- return s;
49
- }, g = (s, e) => V(s, F(e));
50
- let E = !1;
51
- const A = [], S = (s) => new Promise((e, t) => {
52
- if (typeof window > "u" || (window.storyblokRegisterEvent = (o) => {
66
+ R.call(e, t) && p(r, t, e[t]);
67
+ if (h)
68
+ for (var t of h(e))
69
+ _.call(e, t) && p(r, t, e[t]);
70
+ return r;
71
+ };
72
+ let g = !1;
73
+ const y = [], x = (r) => new Promise((e, t) => {
74
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (n) => {
53
75
  if (window.location === window.parent.location) {
54
76
  console.warn("You are not in Draft Mode or in the Visual Editor.");
55
77
  return;
56
78
  }
57
- E ? o() : A.push(o);
79
+ g ? n() : y.push(n);
58
80
  }, document.getElementById("storyblok-javascript-bridge")))
59
81
  return;
60
- const r = document.createElement("script");
61
- r.async = !0, r.src = s, r.id = "storyblok-javascript-bridge", r.onerror = (o) => t(o), r.onload = (o) => {
62
- A.forEach((n) => n()), E = !0, e(o);
63
- }, document.getElementsByTagName("head")[0].appendChild(r);
64
- }), K = function(s, e) {
65
- if (!s)
82
+ const o = document.createElement("script");
83
+ o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (n) => t(n), o.onload = (n) => {
84
+ y.forEach((s) => s()), g = !0, e(n);
85
+ }, document.getElementsByTagName("head")[0].appendChild(o);
86
+ }), $ = function(r, e) {
87
+ if (!r)
66
88
  return null;
67
89
  let t = {};
68
- for (let r in s) {
69
- let o = s[r];
70
- e.indexOf(r) > -1 && o !== null && (t[r] = o);
90
+ for (let o in r) {
91
+ let n = r[o];
92
+ e.indexOf(o) > -1 && n !== null && (t[o] = n);
71
93
  }
72
94
  return t;
73
- }, Y = (s) => s === "email";
74
- var W = {
95
+ }, O = (r) => r === "email";
96
+ var N = {
75
97
  nodes: {
76
98
  horizontal_rule() {
77
99
  return {
@@ -88,13 +110,13 @@ var W = {
88
110
  tag: "ul"
89
111
  };
90
112
  },
91
- code_block(s) {
113
+ code_block(r) {
92
114
  return {
93
115
  tag: [
94
116
  "pre",
95
117
  {
96
118
  tag: "code",
97
- attrs: s.attrs
119
+ attrs: r.attrs
98
120
  }
99
121
  ]
100
122
  };
@@ -104,17 +126,17 @@ var W = {
104
126
  singleTag: "br"
105
127
  };
106
128
  },
107
- heading(s) {
129
+ heading(r) {
108
130
  return {
109
- tag: `h${s.attrs.level}`
131
+ tag: `h${r.attrs.level}`
110
132
  };
111
133
  },
112
- image(s) {
134
+ image(r) {
113
135
  return {
114
136
  singleTag: [
115
137
  {
116
138
  tag: "img",
117
- attrs: K(s.attrs, ["src", "alt", "title"])
139
+ attrs: $(r.attrs, ["src", "alt", "title"])
118
140
  }
119
141
  ]
120
142
  };
@@ -166,9 +188,9 @@ var W = {
166
188
  tag: "i"
167
189
  };
168
190
  },
169
- link(s) {
170
- const e = u({}, s.attrs), { linktype: t = "url" } = s.attrs;
171
- return Y(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
191
+ link(r) {
192
+ const e = C({}, r.attrs), { linktype: t = "url" } = r.attrs;
193
+ return O(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
172
194
  tag: [
173
195
  {
174
196
  tag: "a",
@@ -177,31 +199,31 @@ var W = {
177
199
  ]
178
200
  };
179
201
  },
180
- styled(s) {
202
+ styled(r) {
181
203
  return {
182
204
  tag: [
183
205
  {
184
206
  tag: "span",
185
- attrs: s.attrs
207
+ attrs: r.attrs
186
208
  }
187
209
  ]
188
210
  };
189
211
  }
190
212
  }
191
213
  };
192
- const Q = function(s) {
214
+ const P = function(r) {
193
215
  const e = {
194
216
  "&": "&amp;",
195
217
  "<": "&lt;",
196
218
  ">": "&gt;",
197
219
  '"': "&quot;",
198
220
  "'": "&#39;"
199
- }, t = /[&<>"']/g, r = RegExp(t.source);
200
- return s && r.test(s) ? s.replace(t, (o) => e[o]) : s;
221
+ }, t = /[&<>"']/g, o = RegExp(t.source);
222
+ return r && o.test(r) ? r.replace(t, (n) => e[n]) : r;
201
223
  };
202
- class x {
224
+ class L {
203
225
  constructor(e) {
204
- e || (e = W), this.marks = e.marks || [], this.nodes = e.nodes || [];
226
+ e || (e = N), this.marks = e.marks || [], this.nodes = e.nodes || [];
205
227
  }
206
228
  addNode(e, t) {
207
229
  this.nodes[e] = t;
@@ -212,38 +234,38 @@ class x {
212
234
  render(e = {}) {
213
235
  if (e.content && Array.isArray(e.content)) {
214
236
  let t = "";
215
- return e.content.forEach((r) => {
216
- t += this.renderNode(r);
237
+ return e.content.forEach((o) => {
238
+ t += this.renderNode(o);
217
239
  }), t;
218
240
  }
219
241
  return console.warn("The render method must receive an object with a content field, which is an array"), "";
220
242
  }
221
243
  renderNode(e) {
222
244
  let t = [];
223
- e.marks && e.marks.forEach((o) => {
224
- const n = this.getMatchingMark(o);
225
- n && t.push(this.renderOpeningTag(n.tag));
245
+ e.marks && e.marks.forEach((n) => {
246
+ const s = this.getMatchingMark(n);
247
+ s && t.push(this.renderOpeningTag(s.tag));
226
248
  });
227
- const r = this.getMatchingNode(e);
228
- return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((o) => {
229
- t.push(this.renderNode(o));
230
- }) : e.text ? t.push(Q(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html && t.push(r.html), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((o) => {
231
- const n = this.getMatchingMark(o);
232
- n && t.push(this.renderClosingTag(n.tag));
249
+ const o = this.getMatchingNode(e);
250
+ return o && o.tag && t.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((n) => {
251
+ t.push(this.renderNode(n));
252
+ }) : e.text ? t.push(P(e.text)) : o && o.singleTag ? t.push(this.renderTag(o.singleTag, " /")) : o && o.html && t.push(o.html), o && o.tag && t.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((n) => {
253
+ const s = this.getMatchingMark(n);
254
+ s && t.push(this.renderClosingTag(s.tag));
233
255
  }), t.join("");
234
256
  }
235
257
  renderTag(e, t) {
236
- return e.constructor === String ? `<${e}${t}>` : e.map((o) => {
237
- if (o.constructor === String)
238
- return `<${o}${t}>`;
258
+ return e.constructor === String ? `<${e}${t}>` : e.map((n) => {
259
+ if (n.constructor === String)
260
+ return `<${n}${t}>`;
239
261
  {
240
- let n = `<${o.tag}`;
241
- if (o.attrs)
242
- for (let i in o.attrs) {
243
- let a = o.attrs[i];
244
- a !== null && (n += ` ${i}="${a}"`);
262
+ let s = `<${n.tag}`;
263
+ if (n.attrs)
264
+ for (let l in n.attrs) {
265
+ let a = n.attrs[l];
266
+ a !== null && (s += ` ${l}="${a}"`);
245
267
  }
246
- return `${n}${t}>`;
268
+ return `${s}${t}>`;
247
269
  }
248
270
  }).join("");
249
271
  }
@@ -251,7 +273,7 @@ class x {
251
273
  return this.renderTag(e, "");
252
274
  }
253
275
  renderClosingTag(e) {
254
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((r) => r.constructor === String ? `</${r}>` : `</${r.tag}>`).join("");
276
+ return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((o) => o.constructor === String ? `</${o}>` : `</${o.tag}>`).join("");
255
277
  }
256
278
  getMatchingNode(e) {
257
279
  if (typeof this.nodes[e.type] == "function")
@@ -262,412 +284,39 @@ class x {
262
284
  return this.marks[e.type](e);
263
285
  }
264
286
  }
265
- /*!
266
- * storyblok-js-client v4.5.2
267
- * Universal JavaScript SDK for Storyblok's API
268
- * (c) 2020-2022 Stobylok Team
269
- */
270
- function $(s) {
271
- return typeof s == "number" && s == s && s !== 1 / 0 && s !== -1 / 0;
272
- }
273
- function C(s, e, t) {
274
- if (!$(e))
275
- throw new TypeError("Expected `limit` to be a finite number");
276
- if (!$(t))
277
- throw new TypeError("Expected `interval` to be a finite number");
278
- var r = [], o = [], n = 0, i = function() {
279
- n++;
280
- var c = setTimeout(function() {
281
- n--, r.length > 0 && i(), o = o.filter(function(h) {
282
- return h !== c;
283
- });
284
- }, t);
285
- o.indexOf(c) < 0 && o.push(c);
286
- var l = r.shift();
287
- l.resolve(s.apply(l.self, l.args));
288
- }, a = function() {
289
- var c = arguments, l = this;
290
- return new Promise(function(h, p) {
291
- r.push({ resolve: h, reject: p, args: c, self: l }), n < e && i();
292
- });
293
- };
294
- return a.abort = function() {
295
- o.forEach(clearTimeout), o = [], r.forEach(function(c) {
296
- c.reject(new throttle.AbortError());
297
- }), r.length = 0;
298
- }, a;
299
- }
300
- C.AbortError = function() {
301
- Error.call(this, "Throttled function aborted"), this.name = "AbortError";
302
- };
303
- const X = function(s, e) {
304
- if (!s)
305
- return null;
306
- let t = {};
307
- for (let r in s) {
308
- let o = s[r];
309
- e.indexOf(r) > -1 && o !== null && (t[r] = o);
310
- }
311
- return t;
312
- };
313
- var Z = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (s) => ({ tag: ["pre", { tag: "code", attrs: s.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (s) => ({ tag: `h${s.attrs.level}` }), image: (s) => ({ singleTag: [{ tag: "img", attrs: X(s.attrs, ["src", "alt", "title"]) }] }), list_item: () => ({ tag: "li" }), ordered_list: () => ({ tag: "ol" }), paragraph: () => ({ tag: "p" }) }, marks: { bold: () => ({ tag: "b" }), strike: () => ({ tag: "strike" }), underline: () => ({ tag: "u" }), strong: () => ({ tag: "strong" }), code: () => ({ tag: "code" }), italic: () => ({ tag: "i" }), link(s) {
314
- const e = u({}, s.attrs), { linktype: t = "url" } = s.attrs;
315
- return t === "email" && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), { tag: [{ tag: "a", attrs: e }] };
316
- }, styled: (s) => ({ tag: [{ tag: "span", attrs: s.attrs }] }) } };
317
- class ee {
318
- constructor(e) {
319
- e || (e = Z), this.marks = e.marks || [], this.nodes = e.nodes || [];
320
- }
321
- addNode(e, t) {
322
- this.nodes[e] = t;
323
- }
324
- addMark(e, t) {
325
- this.marks[e] = t;
326
- }
327
- render(e = {}) {
328
- if (e.content && Array.isArray(e.content)) {
329
- let t = "";
330
- return e.content.forEach((r) => {
331
- t += this.renderNode(r);
332
- }), t;
333
- }
334
- return console.warn("The render method must receive an object with a content field, which is an array"), "";
335
- }
336
- renderNode(e) {
337
- let t = [];
338
- e.marks && e.marks.forEach((o) => {
339
- const n = this.getMatchingMark(o);
340
- n && t.push(this.renderOpeningTag(n.tag));
341
- });
342
- const r = this.getMatchingNode(e);
343
- return r && r.tag && t.push(this.renderOpeningTag(r.tag)), e.content ? e.content.forEach((o) => {
344
- t.push(this.renderNode(o));
345
- }) : e.text ? t.push(function(o) {
346
- const n = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, i = /[&<>"']/g, a = RegExp(i.source);
347
- return o && a.test(o) ? o.replace(i, (c) => n[c]) : o;
348
- }(e.text)) : r && r.singleTag ? t.push(this.renderTag(r.singleTag, " /")) : r && r.html && t.push(r.html), r && r.tag && t.push(this.renderClosingTag(r.tag)), e.marks && e.marks.slice(0).reverse().forEach((o) => {
349
- const n = this.getMatchingMark(o);
350
- n && t.push(this.renderClosingTag(n.tag));
351
- }), t.join("");
352
- }
353
- renderTag(e, t) {
354
- return e.constructor === String ? `<${e}${t}>` : e.map((r) => {
355
- if (r.constructor === String)
356
- return `<${r}${t}>`;
357
- {
358
- let o = `<${r.tag}`;
359
- if (r.attrs)
360
- for (let n in r.attrs) {
361
- let i = r.attrs[n];
362
- i !== null && (o += ` ${n}="${i}"`);
363
- }
364
- return `${o}${t}>`;
365
- }
366
- }).join("");
367
- }
368
- renderOpeningTag(e) {
369
- return this.renderTag(e, "");
370
- }
371
- renderClosingTag(e) {
372
- return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((t) => t.constructor === String ? `</${t}>` : `</${t.tag}>`).join("");
373
- }
374
- getMatchingNode(e) {
375
- if (typeof this.nodes[e.type] == "function")
376
- return this.nodes[e.type](e);
377
- }
378
- getMatchingMark(e) {
379
- if (typeof this.marks[e.type] == "function")
380
- return this.marks[e.type](e);
381
- }
382
- }
383
- const te = (s = 0, e = s) => {
384
- const t = Math.abs(e - s) || 0, r = s < e ? 1 : -1;
385
- return ((o = 0, n) => [...Array(o)].map(n))(t, (o, n) => n * r + s);
386
- }, y = (s, e, t) => {
387
- const r = [];
388
- for (const o in s) {
389
- if (!Object.prototype.hasOwnProperty.call(s, o))
390
- continue;
391
- const n = s[o], i = t ? "" : encodeURIComponent(o);
392
- let a;
393
- a = typeof n == "object" ? y(n, e ? e + encodeURIComponent("[" + i + "]") : i, Array.isArray(n)) : (e ? e + encodeURIComponent("[" + i + "]") : i) + "=" + encodeURIComponent(n), r.push(a);
394
- }
395
- return r.join("&");
396
- };
397
- let f = {}, d = {};
398
- class re {
399
- constructor(e, t) {
400
- if (!t) {
401
- let n = e.region ? `-${e.region}` : "", i = e.https === !1 ? "http" : "https";
402
- t = e.oauthToken === void 0 ? `${i}://api${n}.storyblok.com/v2` : `${i}://api${n}.storyblok.com/v1`;
403
- }
404
- let r = Object.assign({}, e.headers), o = 5;
405
- e.oauthToken !== void 0 && (r.Authorization = e.oauthToken, o = 3), e.rateLimit !== void 0 && (o = e.rateLimit), this.richTextResolver = new ee(e.richTextSchema), typeof e.componentResolver == "function" && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries || 5, this.throttle = C(this.throttledRequest, o, 1e3), this.accessToken = e.accessToken, this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.client = N.create({ baseURL: t, timeout: e.timeout || 0, headers: r, proxy: e.proxy || !1 }), e.responseInterceptor && this.client.interceptors.response.use((n) => e.responseInterceptor(n)), this.resolveNestedRelations = e.resolveNestedRelations || !0;
406
- }
407
- setComponentResolver(e) {
408
- this.richTextResolver.addNode("blok", (t) => {
409
- let r = "";
410
- return t.attrs.body.forEach((o) => {
411
- r += e(o.component, o);
412
- }), { html: r };
413
- });
414
- }
415
- parseParams(e = {}) {
416
- return e.version || (e.version = "published"), e.token || (e.token = this.getToken()), e.cv || (e.cv = d[e.token]), Array.isArray(e.resolve_relations) && (e.resolve_relations = e.resolve_relations.join(",")), e;
417
- }
418
- factoryParamOptions(e, t = {}) {
419
- return ((r = "") => r.indexOf("/cdn/") > -1)(e) ? this.parseParams(t) : t;
420
- }
421
- makeRequest(e, t, r, o) {
422
- const n = this.factoryParamOptions(e, ((i = {}, a = 25, c = 1) => g(u({}, i), { per_page: a, page: c }))(t, r, o));
423
- return this.cacheResponse(e, n);
424
- }
425
- get(e, t) {
426
- let r = `/${e}`;
427
- const o = this.factoryParamOptions(r, t);
428
- return this.cacheResponse(r, o);
429
- }
430
- async getAll(e, t = {}, r) {
431
- const o = t.per_page || 25, n = `/${e}`, i = n.split("/");
432
- r = r || i[i.length - 1];
433
- const a = await this.makeRequest(n, t, o, 1), c = Math.ceil(a.total / o);
434
- return ((l = [], h) => l.map(h).reduce((p, j) => [...p, ...j], []))([a, ...await (async (l = [], h) => Promise.all(l.map(h)))(te(1, c), async (l) => this.makeRequest(n, t, o, l + 1))], (l) => Object.values(l.data[r]));
435
- }
436
- post(e, t) {
437
- let r = `/${e}`;
438
- return this.throttle("post", r, t);
439
- }
440
- put(e, t) {
441
- let r = `/${e}`;
442
- return this.throttle("put", r, t);
443
- }
444
- delete(e, t) {
445
- let r = `/${e}`;
446
- return this.throttle("delete", r, t);
447
- }
448
- getStories(e) {
449
- return this.get("cdn/stories", e);
450
- }
451
- getStory(e, t) {
452
- return this.get(`cdn/stories/${e}`, t);
453
- }
454
- setToken(e) {
455
- this.accessToken = e;
456
- }
457
- getToken() {
458
- return this.accessToken;
459
- }
460
- _cleanCopy(e) {
461
- return JSON.parse(JSON.stringify(e));
462
- }
463
- _insertLinks(e, t) {
464
- const r = e[t];
465
- r && r.fieldtype == "multilink" && r.linktype == "story" && typeof r.id == "string" && this.links[r.id] ? r.story = this._cleanCopy(this.links[r.id]) : r && r.linktype === "story" && typeof r.uuid == "string" && this.links[r.uuid] && (r.story = this._cleanCopy(this.links[r.uuid]));
466
- }
467
- _insertRelations(e, t, r) {
468
- if (r.indexOf(e.component + "." + t) > -1) {
469
- if (typeof e[t] == "string")
470
- this.relations[e[t]] && (e[t] = this._cleanCopy(this.relations[e[t]]));
471
- else if (e[t].constructor === Array) {
472
- let o = [];
473
- e[t].forEach((n) => {
474
- this.relations[n] && o.push(this._cleanCopy(this.relations[n]));
475
- }), e[t] = o;
476
- }
477
- }
478
- }
479
- _insertAssetsRelations(e, t) {
480
- t.forEach((r) => {
481
- e.id === r.id && (e.original = r, e.original.filename = e.filename, e.original.filename = e.original.filename.includes("https://s3.amazonaws.com/") ? e.original.filename : e.original.filename.replace("https://", "https://s3.amazonaws.com/"), delete e.original.s3_filename);
482
- });
483
- }
484
- iterateTree(e, t) {
485
- let r = (o) => {
486
- if (o != null) {
487
- if (o.constructor === Array)
488
- for (let n = 0; n < o.length; n++)
489
- r(o[n]);
490
- else if (o.constructor === Object) {
491
- if (o._stopResolving)
492
- return;
493
- for (let n in o)
494
- o.component && o._uid || o.type === "link" ? (this._insertRelations(o, n, t), this._insertLinks(o, n)) : "id" in o && o.fieldtype === "asset" && this._insertAssetsRelations(o, t), r(o[n]);
495
- }
496
- }
497
- };
498
- r(e.content);
499
- }
500
- async resolveLinks(e, t) {
501
- let r = [];
502
- if (e.link_uuids) {
503
- const o = e.link_uuids.length;
504
- let n = [];
505
- const i = 50;
506
- for (let a = 0; a < o; a += i) {
507
- const c = Math.min(o, a + i);
508
- n.push(e.link_uuids.slice(a, c));
509
- }
510
- for (let a = 0; a < n.length; a++)
511
- (await this.getStories({ per_page: i, language: t.language, version: t.version, by_uuids: n[a].join(",") })).data.stories.forEach((c) => {
512
- r.push(c);
513
- });
514
- } else
515
- r = e.links;
516
- r.forEach((o) => {
517
- this.links[o.uuid] = g(u({}, o), { _stopResolving: !0 });
518
- });
519
- }
520
- async resolveRelations(e, t) {
521
- let r = [];
522
- if (e.rel_uuids) {
523
- const o = e.rel_uuids.length;
524
- let n = [];
525
- const i = 50;
526
- for (let a = 0; a < o; a += i) {
527
- const c = Math.min(o, a + i);
528
- n.push(e.rel_uuids.slice(a, c));
529
- }
530
- for (let a = 0; a < n.length; a++)
531
- (await this.getStories({ per_page: i, language: t.language, version: t.version, by_uuids: n[a].join(",") })).data.stories.forEach((c) => {
532
- r.push(c);
533
- });
534
- } else
535
- r = e.rels;
536
- r.forEach((o) => {
537
- this.relations[o.uuid] = g(u({}, o), { _stopResolving: !0 });
538
- });
539
- }
540
- async resolveStories(e, t) {
541
- let r = [];
542
- if (t.resolve_relations !== void 0 && t.resolve_relations.length > 0 && (e.rels || e.rel_uuids) && (r = t.resolve_relations.split(","), await this.resolveRelations(e, t)), ["1", "story", "url"].indexOf(t.resolve_links) > -1 && (e.links || e.link_uuids) && await this.resolveLinks(e, t), this.resolveNestedRelations)
543
- for (const o in this.relations)
544
- this.iterateTree(this.relations[o], r);
545
- e.story ? this.iterateTree(e.story, r) : e.stories.forEach((o) => {
546
- this.iterateTree(o, r);
547
- });
548
- }
549
- resolveAssetsRelations(e) {
550
- const { assets: t, stories: r, story: o } = e;
551
- if (r)
552
- for (const n of r)
553
- this.iterateTree(n, t);
554
- else {
555
- if (!o)
556
- return e;
557
- this.iterateTree(o, t);
558
- }
559
- }
560
- cacheResponse(e, t, r) {
561
- return r === void 0 && (r = 0), new Promise(async (o, n) => {
562
- let i = y({ url: e, params: t }), a = this.cacheProvider();
563
- if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
564
- const l = await a.get(i);
565
- if (l)
566
- return o(l);
567
- }
568
- try {
569
- let l = await this.throttle("get", e, { params: t, paramsSerializer: (p) => y(p) }), h = { data: l.data, headers: l.headers };
570
- if (h.data.assets && h.data.assets.length && this.resolveAssetsRelations(h.data), l.headers["per-page"] && (h = Object.assign({}, h, { perPage: parseInt(l.headers["per-page"]), total: parseInt(l.headers.total) })), l.status != 200)
571
- return n(l);
572
- (h.data.story || h.data.stories) && await this.resolveStories(h.data, t), t.version === "published" && e != "/cdn/spaces/me" && a.set(i, h), h.data.cv && (t.version == "draft" && d[t.token] != h.data.cv && this.flushCache(), d[t.token] = h.data.cv), o(h);
573
- } catch (l) {
574
- if (l.response && l.response.status === 429 && (r += 1) < this.maxRetries)
575
- return console.log(`Hit rate limit. Retrying in ${r} seconds.`), await (c = 1e3 * r, new Promise((h) => setTimeout(h, c))), this.cacheResponse(e, t, r).then(o).catch(n);
576
- n(l);
577
- }
578
- var c;
579
- });
580
- }
581
- throttledRequest(e, t, r) {
582
- return this.client[e](t, r);
583
- }
584
- cacheVersions() {
585
- return d;
586
- }
587
- cacheVersion() {
588
- return d[this.accessToken];
589
- }
590
- setCacheVersion(e) {
591
- this.accessToken && (d[this.accessToken] = e);
592
- }
593
- cacheProvider() {
594
- return this.cache.type === "memory" ? { get: (e) => f[e], getAll: () => f, set(e, t) {
595
- f[e] = t;
596
- }, flush() {
597
- f = {};
598
- } } : { get() {
599
- }, getAll() {
600
- }, set() {
601
- }, flush() {
602
- } };
603
- }
604
- async flushCache() {
605
- return await this.cacheProvider().flush(), this;
606
- }
607
- }
608
- const se = (s = {}) => {
609
- const { apiOptions: e } = s;
610
- if (!e.accessToken) {
611
- 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");
612
- return;
613
- }
614
- return { storyblokApi: new re(e) };
615
- };
616
- var le = (s) => {
617
- if (typeof s != "object" || typeof s._editable > "u")
287
+ var z = (r) => {
288
+ if (typeof r != "object" || typeof r._editable > "u")
618
289
  return {};
619
- const e = JSON.parse(s._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
290
+ const e = JSON.parse(r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
620
291
  return {
621
292
  "data-blok-c": JSON.stringify(e),
622
293
  "data-blok-uid": e.id + "-" + e.uid
623
294
  };
624
295
  };
625
- let m;
626
- const I = "https://app.storyblok.com/f/storyblok-v2-latest.js", oe = (s = {}) => {
627
- const {
628
- bridge: e,
629
- accessToken: t,
630
- use: r = [],
631
- apiOptions: o = {},
632
- richText: n = {}
633
- } = s;
634
- o.accessToken = o.accessToken || t;
635
- const i = { bridge: e, apiOptions: o };
636
- let a = {};
637
- return r.forEach((c) => {
638
- a = u(u({}, a), c(i));
639
- }), e !== !1 && S(I), m = new x(n.schema), n.resolver && P(m, n.resolver), a;
640
- }, P = (s, e) => {
641
- s.addNode("blok", (t) => {
642
- let r = "";
643
- return t.attrs.body.forEach((o) => {
644
- r += e(o.component, o);
296
+ let j;
297
+ const M = "https://app.storyblok.com/f/storyblok-v2-latest.js", U = (r, e) => {
298
+ r.addNode("blok", (t) => {
299
+ let o = "";
300
+ return t.attrs.body.forEach((n) => {
301
+ o += e(n.component, n);
645
302
  }), {
646
- html: r
303
+ html: o
647
304
  };
648
305
  });
649
- }, ne = (s, e, t) => {
650
- let r = t || m;
651
- if (!r) {
306
+ }, B = (r, e, t) => {
307
+ let o = t || j;
308
+ if (!o) {
652
309
  console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
653
310
  return;
654
311
  }
655
- return s === "" ? "" : s ? (e && (r = new x(e.schema), e.resolver && P(r, e.resolver)), r.render(s)) : (console.warn(`${s} is not a valid Richtext object. This might be because the value of the richtext field is empty.
312
+ return r === "" ? "" : r ? (e && (o = new L(e.schema), e.resolver && U(o, e.resolver)), o.render(r)) : (console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty.
656
313
 
657
314
  For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
658
- }, ce = () => S(I);
659
- function ae(s, e, t) {
660
- const { storyblokApi: r } = oe({
661
- accessToken: s,
662
- use: e || [se],
663
- apiOptions: { ...t }
664
- });
665
- globalThis.storyblokApiInstance = r;
315
+ }, H = () => x(M);
316
+ function F() {
317
+ return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), storyblokApiInstance;
666
318
  }
667
- function he() {
668
- return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
669
- }
670
- function ue(s, e) {
319
+ function V(r, e) {
671
320
  const t = globalThis.storyblokApiInstance.richTextResolver;
672
321
  if (!t) {
673
322
  console.error(
@@ -675,43 +324,56 @@ function ue(s, e) {
675
324
  );
676
325
  return;
677
326
  }
678
- return ne(s, e, t);
327
+ return B(r, e, t);
679
328
  }
680
- function de(s) {
329
+ function q(r) {
681
330
  return {
682
331
  name: "@storyblok/astro",
683
332
  hooks: {
684
333
  "astro:config:setup": ({ injectScript: e, updateConfig: t }) => {
685
- var o;
334
+ var n;
686
335
  t({
687
336
  vite: {
688
- plugins: [z(s.components)]
337
+ plugins: [
338
+ k(
339
+ r.accessToken,
340
+ r.useCustomApi,
341
+ r.apiOptions
342
+ ),
343
+ w(r.components)
344
+ ]
689
345
  }
690
- }), ae(s.accessToken, s.use, s.apiOptions), ((o = s.bridge) != null ? o : !0) && e(
346
+ }), e(
347
+ "page-ssr",
348
+ `
349
+ import { storyblokApiInstance } from "virtual:storyblok-init";
350
+ globalThis.storyblokApiInstance = storyblokApiInstance;
351
+ `
352
+ ), ((n = r.bridge) != null ? n : !0) && e(
691
353
  "page",
692
354
  `
693
- import { loadStoryblokBridge } from "@storyblok/astro";
694
- loadStoryblokBridge().then(() => {
695
- const { StoryblokBridge, location } = window;
696
- const storyblokInstance = new StoryblokBridge();
355
+ import { loadStoryblokBridge } from "@storyblok/astro";
356
+ loadStoryblokBridge().then(() => {
357
+ const { StoryblokBridge, location } = window;
358
+ const storyblokInstance = new StoryblokBridge();
697
359
 
698
- storyblokInstance.on(["published", "change"], (event) => {
699
- if (!event.slugChanged) {
700
- location.reload(true);
701
- }
702
- });
703
- });
704
- `
360
+ storyblokInstance.on(["published", "change"], (event) => {
361
+ if (!event.slugChanged) {
362
+ location.reload(true);
363
+ }
364
+ });
365
+ });
366
+ `
705
367
  );
706
368
  }
707
369
  }
708
370
  };
709
371
  }
710
372
  export {
711
- W as RichTextSchema,
712
- de as default,
713
- ce as loadStoryblokBridge,
714
- ue as renderRichText,
715
- le as storyblokEditable,
716
- he as useStoryblokApi
373
+ N as RichTextSchema,
374
+ q as default,
375
+ H as loadStoryblokBridge,
376
+ V as renderRichText,
377
+ z as storyblokEditable,
378
+ F as useStoryblokApi
717
379
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@storyblok/astro",
3
- "version": "1.1.1",
4
- "description": "SDK to integrate Storyblok into your project using Astro.",
3
+ "version": "1.2.0",
4
+ "description": "Official Astro integration for the Storyblok Headless CMS",
5
5
  "main": "./dist/storyblok-astro.js",
6
6
  "module": "./dist/storyblok-astro.mjs",
7
7
  "files": [
@@ -27,7 +27,7 @@
27
27
  "prepublishOnly": "npm run build && cp ../README.md ./"
28
28
  },
29
29
  "dependencies": {
30
- "@storyblok/js": "^1.8.5",
30
+ "@storyblok/js": "^1.8.6",
31
31
  "camelcase": "^7.0.0"
32
32
  },
33
33
  "devDependencies": {
@@ -37,7 +37,7 @@
37
37
  "cypress": "^10.9.0",
38
38
  "eslint-plugin-cypress": "^2.12.1",
39
39
  "start-server-and-test": "^1.14.0",
40
- "vite": "^3.1.3"
40
+ "vite": "^3.2.4"
41
41
  },
42
42
  "repository": {
43
43
  "type": "git",
@@ -45,7 +45,8 @@
45
45
  },
46
46
  "keywords": [
47
47
  "astro",
48
- "storyblok"
48
+ "storyblok",
49
+ "astro-component"
49
50
  ],
50
51
  "author": "Alexander Feiglstorfer",
51
52
  "bugs": {