@storyblok/astro 1.1.1 → 2.0.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
 
@@ -59,9 +59,11 @@ export default defineConfig({
59
59
  });
60
60
  ```
61
61
 
62
+ > ⚠️ This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch). More info on [storyblok-js-client docs](https://github.com/storyblok/storyblok-js-client#fetch-use-polyfill-if-needed---version-5).
63
+
62
64
  ### Options
63
65
 
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' } }`.
66
+ 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
67
 
66
68
  ```js
67
69
  // Defaults
@@ -69,11 +71,11 @@ storyblok({
69
71
  accessToken: "<your-access-token>",
70
72
  bridge: true,
71
73
  apiOptions: {}, // storyblok-js-client options
72
- use: [apiPlugin],
74
+ useCustomApi: false,
73
75
  });
74
76
  ```
75
77
 
76
- > Note: if you don't use `apiPlugin`, you can use your preferred method or function to fetch your data.
78
+ > 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
79
 
78
80
  ## Getting started
79
81
 
@@ -125,7 +127,7 @@ const { blok } = Astro.props
125
127
  ---
126
128
 
127
129
  <main {...storyblokEditable(blok)}>
128
- {blok.body?.map(blok => {return <StoryblokComponent blok={blok} />})}
130
+ {blok.body?.map(blok => {return <StoryblokComponent blok="{blok}" />})}
129
131
  </main>
130
132
  ```
131
133
 
@@ -160,7 +162,7 @@ const { data } = await storyblokApi.get("cdn/stories/home", {
160
162
  const story = data.story;
161
163
  ---
162
164
 
163
- <StoryblokComponent blok={story.content} />
165
+ <StoryblokComponent blok="{story.content}" />
164
166
  ```
165
167
 
166
168
  > Note: The available methods are described in the [storyblok-js-client] repository(https://github.com/storyblok/storyblok-js-client#method-storyblokget)
@@ -201,15 +203,17 @@ const { data } = await storyblokApi.get(`cdn/stories/${slug}`, {
201
203
  const story = data.story;
202
204
  ---
203
205
 
204
- <StoryblokComponent blok={story.content} />
206
+ <StoryblokComponent blok="{story.content}" />
205
207
  ```
206
208
 
207
209
  ### Using the Storyblok Bridge
208
210
 
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`:
211
+ 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
212
 
211
213
  > 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
214
 
215
+ 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/).
216
+
213
217
  ### Rendering Rich Text
214
218
 
215
219
  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 +227,7 @@ const { blok } = Astro.props
223
227
  const renderedRichText = renderRichText(blok.text)
224
228
  ---
225
229
 
226
- <div set:html={renderedRichText}></div>
230
+ <div set:html="{renderedRichText}"></div>
227
231
  ```
228
232
 
229
233
  You can also set a **custom Schema and component resolver** by passing the options as the second parameter of the `renderRichText` function:
@@ -234,9 +238,9 @@ import cloneDeep from "clone-deep";
234
238
 
235
239
  const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
236
240
  // ... 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
241
+ // Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/v4/source/schema.js
238
242
 
239
- const { blok } = Astro.props
243
+ const { blok } = Astro.props;
240
244
 
241
245
  const renderedRichText = renderRichText(blok.text, {
242
246
  schema: mySchema,
@@ -260,21 +264,22 @@ Returns the instance of the `storyblok-js-client`.
260
264
 
261
265
  ## Acknowledgements
262
266
 
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.
267
+ 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
268
 
265
- ## 🔗 Related Links
269
+ ## Related Links
266
270
 
267
271
  - **[Live Demo on Stackblitz](https://stackblitz.com/edit/astro-sdk-demo)**
268
272
  - **[Storyblok CLI](https://github.com/storyblok/storyblok)**: A simple CLI for scaffolding Storyblok projects and fieldtypes.
269
273
 
270
- ## ℹ️ More Resources
274
+ ## More Resources
271
275
 
272
276
  ### Support
273
277
 
274
278
  - 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).
279
+ - 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)
280
+ - Do you have questions about Storyblok or you need help? [Join the Storyblok Discord Community](https://discord.gg/jKrbAMz).
276
281
 
277
282
  ### Contributing
278
283
 
279
284
  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.
285
+ 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,6 +1,12 @@
1
1
  ---
2
2
  import components from "virtual:storyblok-components";
3
3
  import camelcase from "camelcase";
4
+ import type { SbBlokData } from "./types";
5
+
6
+ interface Props {
7
+ blok: SbBlokData;
8
+ props: object;
9
+ }
4
10
 
5
11
  const { blok, ...props } = Astro.props;
6
12
 
@@ -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(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l.storyblokAstro={}))})(this,function(l){"use strict";function c(t,e,r){const o="virtual:storyblok-init",s="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(n){if(n===o)return s},async load(n){if(n===s)return`
2
+ import { storyblokInit, apiPlugin } from "@storyblok/js";
3
+ const { storyblokApi } = storyblokInit({
4
+ accessToken: "${t}",
5
+ use: ${e?"[]":"[apiPlugin]"},
6
+ apiOptions: ${JSON.stringify(r)},
7
+ });
8
+ export const storyblokApiInstance = storyblokApi;
9
+ `}}}const A=/[\p{Lu}]/u,E=/[\p{Ll}]/u,d=/^[\p{Lu}](?![\p{Lu}])/gu,g=/([\p{Alpha}\p{N}_]|$)/u,u=/[_.\- ]+/,w=new RegExp("^"+u.source),f=new RegExp(u.source+g.source,"gu"),h=new RegExp("\\d+"+g.source,"gu"),S=(t,e,r)=>{let o=!1,s=!1,n=!1;for(let a=0;a<t.length;a++){const i=t[a];o&&A.test(i)?(t=t.slice(0,a)+"-"+t.slice(a),o=!1,n=s,s=!0,a++):s&&n&&E.test(i)?(t=t.slice(0,a-1)+"-"+t.slice(a-1),n=s,s=!1,o=!0):(o=e(i)===i&&r(i)!==i,n=s,s=r(i)===i&&e(i)!==i)}return t},R=(t,e)=>(d.lastIndex=0,t.replace(d,r=>e(r))),_=(t,e)=>(f.lastIndex=0,h.lastIndex=0,t.replace(f,(r,o)=>e(o)).replace(h,r=>e(r)));function p(t,e){if(!(typeof t=="string"||Array.isArray(t)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(t)?t=t.map(n=>n.trim()).filter(n=>n.length).join("-"):t=t.trim(),t.length===0)return"";const r=e.locale===!1?n=>n.toLowerCase():n=>n.toLocaleLowerCase(e.locale),o=e.locale===!1?n=>n.toUpperCase():n=>n.toLocaleUpperCase(e.locale);return t.length===1?u.test(t)?"":e.pascalCase?o(t):r(t):(t!==r(t)&&(t=S(t,r,o)),t=t.replace(w,""),t=e.preserveConsecutiveUppercase?R(t,r):r(t),e.pascalCase&&(t=o(t.charAt(0))+t.slice(1)),_(t,o))}function C(t){const e="virtual:storyblok-components",r="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return r},async load(o){if(o===r){const s=[];for await(const[n,a]of Object.entries(t)){const{id:i}=await this.resolve("/src/"+a+".astro");s.push(`import ${p(n)} from "${i}"`)}return`${s.join(";")};export default {${Object.keys(t).map(n=>p(n)).join(",")}}`}}}}var $=Object.defineProperty,b=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,y=(t,e,r)=>e in t?$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,P=(t,e)=>{for(var r in e||(e={}))O.call(e,r)&&y(t,r,e[r]);if(b)for(var r of b(e))x.call(e,r)&&y(t,r,e[r]);return t};let m=!1;const k=[],j=t=>new Promise((e,r)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=s=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}m?s():k.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=t,o.id="storyblok-javascript-bridge",o.onerror=s=>r(s),o.onload=s=>{k.forEach(n=>n()),m=!0,e(s)},document.getElementsByTagName("head")[0].appendChild(o)});var N=Object.defineProperty,L=(t,e,r)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e,r)=>(L(t,typeof e!="symbol"?e+"":e,r),r);const M=function(t,e){const r={};for(const o in t){const s=t[o];e.indexOf(o)>-1&&s!==null&&(r[o]=s)}return r},U=t=>t==="email",B=()=>({singleTag:"hr"}),D=()=>({tag:"blockquote"}),z=()=>({tag:"ul"}),F=t=>({tag:["pre",{tag:"code",attrs:t.attrs}]}),V=()=>({singleTag:"br"}),q=t=>({tag:`h${t.attrs.level}`}),J=t=>({singleTag:[{tag:"img",attrs:M(t.attrs,["src","alt","title"])}]}),G=()=>({tag:"li"}),K=()=>({tag:"ol"}),H=()=>({tag:"p"}),W=()=>({tag:"b"}),Y=()=>({tag:"strike"}),Q=()=>({tag:"u"}),X=()=>({tag:"strong"}),Z=()=>({tag:"code"}),ee=()=>({tag:"i"}),te=t=>{const e=P({},t.attrs),{linktype:r="url"}=t.attrs;return U(r)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},re=t=>({tag:[{tag:"span",attrs:t.attrs}]}),T={nodes:{horizontal_rule:B,blockquote:D,bullet_list:z,code_block:F,hard_break:V,heading:q,image:J,list_item:G,ordered_list:K,paragraph:H},marks:{bold:W,strike:Y,underline:Q,strong:X,code:Z,italic:ee,link:te,styled:re}},oe=function(t){const e={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},r=/[&<>"']/g,o=RegExp(r.source);return t&&o.test(t)?t.replace(r,s=>e[s]):t};class I{constructor(e){v(this,"marks"),v(this,"nodes"),e||(e=T),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,r){this.nodes[e]=r}addMark(e,r){this.marks[e]=r}render(e){if(e&&e.content&&Array.isArray(e.content)){let r="";return e.content.forEach(o=>{r+=this.renderNode(o)}),r}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const r=[];e.marks&&e.marks.forEach(s=>{const n=this.getMatchingMark(s);n&&r.push(this.renderOpeningTag(n.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&r.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(s=>{r.push(this.renderNode(s))}):e.text?r.push(oe(e.text)):o&&o.singleTag?r.push(this.renderTag(o.singleTag," /")):o&&o.html&&r.push(o.html),o&&o.tag&&r.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(s=>{const n=this.getMatchingMark(s);n&&r.push(this.renderClosingTag(n.tag))}),r.join("")}renderTag(e,r){return e.constructor===String?`<${e}${r}>`:e.map(o=>{if(o.constructor===String)return`<${o}${r}>`;{let s=`<${o.tag}`;if(o.attrs)for(const n in o.attrs){const a=o.attrs[n];a!==null&&(s+=` ${n}="${a}"`)}return`${s}${r}>`}}).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){const r=this.nodes[e.type];if(typeof r=="function")return r(e)}getMatchingMark(e){const r=this.marks[e.type];if(typeof r=="function")return r(e)}}var se=t=>{if(typeof t!="object"||typeof t._editable>"u")return{};const e=JSON.parse(t._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let ne;const ae="https://app.storyblok.com/f/storyblok-v2-latest.js",le=(t,e)=>{t.addNode("blok",r=>{let o="";return r.attrs.body.forEach(s=>{o+=e(s.component,s)}),{html:o}})},ie=(t,e,r)=>{let o=r||ne;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return t===""?"":t?(e&&(o=new I(e.schema),e.resolver&&le(o,e.resolver)),o.render(t)):(console.warn(`${t} 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`),"")},ce=()=>j(ae);function ue(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function de(t,e){const r=globalThis.storyblokApiInstance.richTextResolver;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return ie(t,e,r)}function ge(t={accessToken:"",useCustomApi:!1,apiOptions:{},bridge:!0,components:{}}){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:r})=>{r({vite:{plugins:[c(t.accessToken,t.useCustomApi,t.apiOptions),C(t.components)]}}),e("page-ssr",`
12
+ import { storyblokApiInstance } from "virtual:storyblok-init";
13
+ globalThis.storyblokApiInstance = storyblokApiInstance;
14
+ `),t.bridge&&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
+ `)}}}}l.RichTextResolver=I,l.RichTextSchema=T,l.default=ge,l.loadStoryblokBridge=ce,l.renderRichText=de,l.storyblokEditable=se,l.useStoryblokApi=ue,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,249 +1,234 @@
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);
1
+ function k(t, e, r) {
2
+ const o = "virtual:storyblok-init", s = "\0" + o;
3
+ return {
4
+ name: "vite-plugin-storyblok-init",
5
+ async resolveId(n) {
6
+ if (n === o)
7
+ return s;
8
+ },
9
+ async load(n) {
10
+ if (n === s)
11
+ return `
12
+ import { storyblokInit, apiPlugin } from "@storyblok/js";
13
+ const { storyblokApi } = storyblokInit({
14
+ accessToken: "${t}",
15
+ use: ${e ? "[]" : "[apiPlugin]"},
16
+ apiOptions: ${JSON.stringify(r)},
17
+ });
18
+ export const storyblokApiInstance = storyblokApi;
19
+ `;
20
+ }
21
+ };
22
+ }
23
+ const v = /[\p{Lu}]/u, I = /[\p{Ll}]/u, c = /^[\p{Lu}](?![\p{Lu}])/gu, m = /([\p{Alpha}\p{N}_]|$)/u, i = /[_.\- ]+/, T = new RegExp("^" + i.source), u = new RegExp(i.source + m.source, "gu"), d = new RegExp("\\d+" + m.source, "gu"), E = (t, e, r) => {
24
+ let o = !1, s = !1, n = !1;
25
+ for (let a = 0; a < t.length; a++) {
26
+ const l = t[a];
27
+ o && v.test(l) ? (t = t.slice(0, a) + "-" + t.slice(a), o = !1, n = s, s = !0, a++) : s && n && I.test(l) ? (t = t.slice(0, a - 1) + "-" + t.slice(a - 1), n = s, s = !1, o = !0) : (o = e(l) === l && r(l) !== l, n = s, s = r(l) === l && e(l) !== l);
7
28
  }
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)))
29
+ return t;
30
+ }, A = (t, e) => (c.lastIndex = 0, t.replace(c, (r) => e(r))), w = (t, e) => (u.lastIndex = 0, d.lastIndex = 0, t.replace(u, (r, o) => e(o)).replace(d, (r) => e(r)));
31
+ function g(t, e) {
32
+ if (!(typeof t == "string" || Array.isArray(t)))
12
33
  throw new TypeError("Expected the input to be `string | string[]`");
13
34
  if (e = {
14
35
  pascalCase: !1,
15
36
  preserveConsecutiveUppercase: !1,
16
37
  ...e
17
- }, Array.isArray(s) ? s = s.map((n) => n.trim()).filter((n) => n.length).join("-") : s = s.trim(), s.length === 0)
38
+ }, Array.isArray(t) ? t = t.map((n) => n.trim()).filter((n) => n.length).join("-") : t = t.trim(), t.length === 0)
18
39
  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));
40
+ const r = e.locale === !1 ? (n) => n.toLowerCase() : (n) => n.toLocaleLowerCase(e.locale), o = e.locale === !1 ? (n) => n.toUpperCase() : (n) => n.toLocaleUpperCase(e.locale);
41
+ return t.length === 1 ? i.test(t) ? "" : e.pascalCase ? o(t) : r(t) : (t !== r(t) && (t = E(t, r, o)), t = t.replace(T, ""), t = e.preserveConsecutiveUppercase ? A(t, r) : r(t), e.pascalCase && (t = o(t.charAt(0)) + t.slice(1)), w(t, o));
21
42
  }
22
- function z(s) {
23
- const e = "virtual:storyblok-components", t = "\0" + e;
43
+ function S(t) {
44
+ const e = "virtual:storyblok-components", r = "\0" + e;
24
45
  return {
25
- name: "vite-plugin-storyblok",
26
- async resolveId(r) {
27
- if (r === e)
28
- return t;
46
+ name: "vite-plugin-storyblok-components",
47
+ async resolveId(o) {
48
+ if (o === e)
49
+ return r;
29
50
  },
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}"`);
51
+ async load(o) {
52
+ if (o === r) {
53
+ const s = [];
54
+ for await (const [n, a] of Object.entries(t)) {
55
+ const { id: l } = await this.resolve("/src/" + a + ".astro");
56
+ s.push(`import ${g(n)} from "${l}"`);
36
57
  }
37
- return `${o.join(";")};export default {${Object.keys(s).map((n) => _(n)).join(",")}}`;
58
+ return `${s.join(";")};export default {${Object.keys(t).map((n) => g(n)).join(",")}}`;
38
59
  }
39
60
  }
40
61
  };
41
62
  }
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) => {
43
- 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) => {
63
+ var C = Object.defineProperty, h = Object.getOwnPropertySymbols, R = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable, f = (t, e, r) => e in t ? C(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, x = (t, e) => {
64
+ for (var r in e || (e = {}))
65
+ R.call(e, r) && f(t, r, e[r]);
66
+ if (h)
67
+ for (var r of h(e))
68
+ _.call(e, r) && f(t, r, e[r]);
69
+ return t;
70
+ };
71
+ let p = !1;
72
+ const b = [], $ = (t) => new Promise((e, r) => {
73
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
53
74
  if (window.location === window.parent.location) {
54
75
  console.warn("You are not in Draft Mode or in the Visual Editor.");
55
76
  return;
56
77
  }
57
- E ? o() : A.push(o);
78
+ p ? s() : b.push(s);
58
79
  }, document.getElementById("storyblok-javascript-bridge")))
59
80
  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)
66
- return null;
67
- let t = {};
68
- for (let r in s) {
69
- let o = s[r];
70
- e.indexOf(r) > -1 && o !== null && (t[r] = o);
71
- }
72
- return t;
73
- }, Y = (s) => s === "email";
74
- var W = {
75
- nodes: {
76
- horizontal_rule() {
77
- return {
78
- singleTag: "hr"
79
- };
80
- },
81
- blockquote() {
82
- return {
83
- tag: "blockquote"
84
- };
85
- },
86
- bullet_list() {
87
- return {
88
- tag: "ul"
89
- };
90
- },
91
- code_block(s) {
92
- return {
93
- tag: [
94
- "pre",
95
- {
96
- tag: "code",
97
- attrs: s.attrs
98
- }
99
- ]
100
- };
101
- },
102
- hard_break() {
103
- return {
104
- singleTag: "br"
105
- };
106
- },
107
- heading(s) {
108
- return {
109
- tag: `h${s.attrs.level}`
110
- };
111
- },
112
- image(s) {
113
- return {
114
- singleTag: [
115
- {
116
- tag: "img",
117
- attrs: K(s.attrs, ["src", "alt", "title"])
118
- }
119
- ]
120
- };
121
- },
122
- list_item() {
123
- return {
124
- tag: "li"
125
- };
126
- },
127
- ordered_list() {
128
- return {
129
- tag: "ol"
130
- };
131
- },
132
- paragraph() {
133
- return {
134
- tag: "p"
135
- };
81
+ const o = document.createElement("script");
82
+ o.async = !0, o.src = t, o.id = "storyblok-javascript-bridge", o.onerror = (s) => r(s), o.onload = (s) => {
83
+ b.forEach((n) => n()), p = !0, e(s);
84
+ }, document.getElementsByTagName("head")[0].appendChild(o);
85
+ });
86
+ var O = Object.defineProperty, P = (t, e, r) => e in t ? O(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, y = (t, e, r) => (P(t, typeof e != "symbol" ? e + "" : e, r), r);
87
+ const N = function(t, e) {
88
+ const r = {};
89
+ for (const o in t) {
90
+ const s = t[o];
91
+ e.indexOf(o) > -1 && s !== null && (r[o] = s);
92
+ }
93
+ return r;
94
+ }, j = (t) => t === "email", L = () => ({
95
+ singleTag: "hr"
96
+ }), M = () => ({
97
+ tag: "blockquote"
98
+ }), U = () => ({
99
+ tag: "ul"
100
+ }), D = (t) => ({
101
+ tag: [
102
+ "pre",
103
+ {
104
+ tag: "code",
105
+ attrs: t.attrs
136
106
  }
107
+ ]
108
+ }), B = () => ({
109
+ singleTag: "br"
110
+ }), z = (t) => ({
111
+ tag: `h${t.attrs.level}`
112
+ }), F = (t) => ({
113
+ singleTag: [
114
+ {
115
+ tag: "img",
116
+ attrs: N(t.attrs, ["src", "alt", "title"])
117
+ }
118
+ ]
119
+ }), V = () => ({
120
+ tag: "li"
121
+ }), q = () => ({
122
+ tag: "ol"
123
+ }), J = () => ({
124
+ tag: "p"
125
+ }), G = () => ({
126
+ tag: "b"
127
+ }), K = () => ({
128
+ tag: "strike"
129
+ }), H = () => ({
130
+ tag: "u"
131
+ }), W = () => ({
132
+ tag: "strong"
133
+ }), Y = () => ({
134
+ tag: "code"
135
+ }), Q = () => ({
136
+ tag: "i"
137
+ }), X = (t) => {
138
+ const e = x({}, t.attrs), { linktype: r = "url" } = t.attrs;
139
+ return j(r) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
140
+ tag: [
141
+ {
142
+ tag: "a",
143
+ attrs: e
144
+ }
145
+ ]
146
+ };
147
+ }, Z = (t) => ({
148
+ tag: [
149
+ {
150
+ tag: "span",
151
+ attrs: t.attrs
152
+ }
153
+ ]
154
+ }), ee = {
155
+ nodes: {
156
+ horizontal_rule: L,
157
+ blockquote: M,
158
+ bullet_list: U,
159
+ code_block: D,
160
+ hard_break: B,
161
+ heading: z,
162
+ image: F,
163
+ list_item: V,
164
+ ordered_list: q,
165
+ paragraph: J
137
166
  },
138
167
  marks: {
139
- bold() {
140
- return {
141
- tag: "b"
142
- };
143
- },
144
- strike() {
145
- return {
146
- tag: "strike"
147
- };
148
- },
149
- underline() {
150
- return {
151
- tag: "u"
152
- };
153
- },
154
- strong() {
155
- return {
156
- tag: "strong"
157
- };
158
- },
159
- code() {
160
- return {
161
- tag: "code"
162
- };
163
- },
164
- italic() {
165
- return {
166
- tag: "i"
167
- };
168
- },
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), {
172
- tag: [
173
- {
174
- tag: "a",
175
- attrs: e
176
- }
177
- ]
178
- };
179
- },
180
- styled(s) {
181
- return {
182
- tag: [
183
- {
184
- tag: "span",
185
- attrs: s.attrs
186
- }
187
- ]
188
- };
189
- }
190
- }
191
- };
192
- const Q = function(s) {
168
+ bold: G,
169
+ strike: K,
170
+ underline: H,
171
+ strong: W,
172
+ code: Y,
173
+ italic: Q,
174
+ link: X,
175
+ styled: Z
176
+ }
177
+ }, te = function(t) {
193
178
  const e = {
194
179
  "&": "&amp;",
195
180
  "<": "&lt;",
196
181
  ">": "&gt;",
197
182
  '"': "&quot;",
198
183
  "'": "&#39;"
199
- }, t = /[&<>"']/g, r = RegExp(t.source);
200
- return s && r.test(s) ? s.replace(t, (o) => e[o]) : s;
184
+ }, r = /[&<>"']/g, o = RegExp(r.source);
185
+ return t && o.test(t) ? t.replace(r, (s) => e[s]) : t;
201
186
  };
202
- class x {
187
+ class re {
203
188
  constructor(e) {
204
- e || (e = W), this.marks = e.marks || [], this.nodes = e.nodes || [];
189
+ y(this, "marks"), y(this, "nodes"), e || (e = ee), this.marks = e.marks || [], this.nodes = e.nodes || [];
205
190
  }
206
- addNode(e, t) {
207
- this.nodes[e] = t;
191
+ addNode(e, r) {
192
+ this.nodes[e] = r;
208
193
  }
209
- addMark(e, t) {
210
- this.marks[e] = t;
194
+ addMark(e, r) {
195
+ this.marks[e] = r;
211
196
  }
212
- render(e = {}) {
213
- if (e.content && Array.isArray(e.content)) {
214
- let t = "";
215
- return e.content.forEach((r) => {
216
- t += this.renderNode(r);
217
- }), t;
197
+ render(e) {
198
+ if (e && e.content && Array.isArray(e.content)) {
199
+ let r = "";
200
+ return e.content.forEach((o) => {
201
+ r += this.renderNode(o);
202
+ }), r;
218
203
  }
219
204
  return console.warn("The render method must receive an object with a content field, which is an array"), "";
220
205
  }
221
206
  renderNode(e) {
222
- let t = [];
223
- e.marks && e.marks.forEach((o) => {
224
- const n = this.getMatchingMark(o);
225
- n && t.push(this.renderOpeningTag(n.tag));
207
+ const r = [];
208
+ e.marks && e.marks.forEach((s) => {
209
+ const n = this.getMatchingMark(s);
210
+ n && r.push(this.renderOpeningTag(n.tag));
226
211
  });
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));
233
- }), t.join("");
234
- }
235
- renderTag(e, t) {
236
- return e.constructor === String ? `<${e}${t}>` : e.map((o) => {
212
+ const o = this.getMatchingNode(e);
213
+ return o && o.tag && r.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((s) => {
214
+ r.push(this.renderNode(s));
215
+ }) : e.text ? r.push(te(e.text)) : o && o.singleTag ? r.push(this.renderTag(o.singleTag, " /")) : o && o.html && r.push(o.html), o && o.tag && r.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((s) => {
216
+ const n = this.getMatchingMark(s);
217
+ n && r.push(this.renderClosingTag(n.tag));
218
+ }), r.join("");
219
+ }
220
+ renderTag(e, r) {
221
+ return e.constructor === String ? `<${e}${r}>` : e.map((o) => {
237
222
  if (o.constructor === String)
238
- return `<${o}${t}>`;
223
+ return `<${o}${r}>`;
239
224
  {
240
- let n = `<${o.tag}`;
225
+ let s = `<${o.tag}`;
241
226
  if (o.attrs)
242
- for (let i in o.attrs) {
243
- let a = o.attrs[i];
244
- a !== null && (n += ` ${i}="${a}"`);
227
+ for (const n in o.attrs) {
228
+ const a = o.attrs[n];
229
+ a !== null && (s += ` ${n}="${a}"`);
245
230
  }
246
- return `${n}${t}>`;
231
+ return `${s}${r}>`;
247
232
  }
248
233
  }).join("");
249
234
  }
@@ -254,464 +239,112 @@ class x {
254
239
  return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((r) => r.constructor === String ? `</${r}>` : `</${r.tag}>`).join("");
255
240
  }
256
241
  getMatchingNode(e) {
257
- if (typeof this.nodes[e.type] == "function")
258
- return this.nodes[e.type](e);
259
- }
260
- getMatchingMark(e) {
261
- if (typeof this.marks[e.type] == "function")
262
- return this.marks[e.type](e);
263
- }
264
- }
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);
242
+ const r = this.nodes[e.type];
243
+ if (typeof r == "function")
244
+ return r(e);
377
245
  }
378
246
  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;
247
+ const r = this.marks[e.type];
248
+ if (typeof r == "function")
249
+ return r(e);
606
250
  }
607
251
  }
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")
252
+ var le = (t) => {
253
+ if (typeof t != "object" || typeof t._editable > "u")
618
254
  return {};
619
- const e = JSON.parse(s._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
255
+ const e = JSON.parse(t._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
620
256
  return {
621
257
  "data-blok-c": JSON.stringify(e),
622
258
  "data-blok-uid": e.id + "-" + e.uid
623
259
  };
624
260
  };
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);
261
+ let oe;
262
+ const se = "https://app.storyblok.com/f/storyblok-v2-latest.js", ne = (t, e) => {
263
+ t.addNode("blok", (r) => {
264
+ let o = "";
265
+ return r.attrs.body.forEach((s) => {
266
+ o += e(s.component, s);
645
267
  }), {
646
- html: r
268
+ html: o
647
269
  };
648
270
  });
649
- }, ne = (s, e, t) => {
650
- let r = t || m;
651
- if (!r) {
271
+ }, ae = (t, e, r) => {
272
+ let o = r || oe;
273
+ if (!o) {
652
274
  console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
653
275
  return;
654
276
  }
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.
277
+ return t === "" ? "" : t ? (e && (o = new re(e.schema), e.resolver && ne(o, e.resolver)), o.render(t)) : (console.warn(`${t} is not a valid Richtext object. This might be because the value of the richtext field is empty.
656
278
 
657
279
  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;
666
- }
667
- function he() {
280
+ }, ie = () => $(se);
281
+ function ce() {
668
282
  return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
669
283
  }
670
- function ue(s, e) {
671
- const t = globalThis.storyblokApiInstance.richTextResolver;
672
- if (!t) {
284
+ function ue(t, e) {
285
+ const r = globalThis.storyblokApiInstance.richTextResolver;
286
+ if (!r) {
673
287
  console.error(
674
288
  "Please initialize the Storyblok SDK before calling the renderRichText function"
675
289
  );
676
290
  return;
677
291
  }
678
- return ne(s, e, t);
292
+ return ae(t, e, r);
679
293
  }
680
- function de(s) {
294
+ function de(t = {
295
+ accessToken: "",
296
+ useCustomApi: !1,
297
+ apiOptions: {},
298
+ bridge: !0,
299
+ components: {}
300
+ }) {
681
301
  return {
682
302
  name: "@storyblok/astro",
683
303
  hooks: {
684
- "astro:config:setup": ({ injectScript: e, updateConfig: t }) => {
685
- var o;
686
- t({
304
+ "astro:config:setup": ({ injectScript: e, updateConfig: r }) => {
305
+ r({
687
306
  vite: {
688
- plugins: [z(s.components)]
307
+ plugins: [
308
+ k(
309
+ t.accessToken,
310
+ t.useCustomApi,
311
+ t.apiOptions
312
+ ),
313
+ S(t.components)
314
+ ]
689
315
  }
690
- }), ae(s.accessToken, s.use, s.apiOptions), ((o = s.bridge) != null ? o : !0) && e(
316
+ }), e(
317
+ "page-ssr",
318
+ `
319
+ import { storyblokApiInstance } from "virtual:storyblok-init";
320
+ globalThis.storyblokApiInstance = storyblokApiInstance;
321
+ `
322
+ ), t.bridge && e(
691
323
  "page",
692
324
  `
693
- import { loadStoryblokBridge } from "@storyblok/astro";
694
- loadStoryblokBridge().then(() => {
695
- const { StoryblokBridge, location } = window;
696
- const storyblokInstance = new StoryblokBridge();
325
+ import { loadStoryblokBridge } from "@storyblok/astro";
326
+ loadStoryblokBridge().then(() => {
327
+ const { StoryblokBridge, location } = window;
328
+ const storyblokInstance = new StoryblokBridge();
697
329
 
698
- storyblokInstance.on(["published", "change"], (event) => {
699
- if (!event.slugChanged) {
700
- location.reload(true);
701
- }
702
- });
703
- });
704
- `
330
+ storyblokInstance.on(["published", "change"], (event) => {
331
+ if (!event.slugChanged) {
332
+ location.reload(true);
333
+ }
334
+ });
335
+ });
336
+ `
705
337
  );
706
338
  }
707
339
  }
708
340
  };
709
341
  }
710
342
  export {
711
- W as RichTextSchema,
343
+ re as RichTextResolver,
344
+ ee as RichTextSchema,
712
345
  de as default,
713
- ce as loadStoryblokBridge,
346
+ ie as loadStoryblokBridge,
714
347
  ue as renderRichText,
715
348
  le as storyblokEditable,
716
- he as useStoryblokApi
349
+ ce as useStoryblokApi
717
350
  };
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": "2.0.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": [
@@ -15,9 +15,10 @@
15
15
  },
16
16
  "./StoryblokComponent.astro": "./StoryblokComponent.astro"
17
17
  },
18
+ "types": "./dist/index.d.ts",
18
19
  "scripts": {
19
20
  "dev": "vite build --watch",
20
- "build": "vite build",
21
+ "build": "vite build && tsc",
21
22
  "test": "npm run test:e2e",
22
23
  "test:e2e": "start-server-and-test cy:playground http-get://localhost:3000/ cy:run",
23
24
  "test:e2e-watch": "start-server-and-test cy:playground http-get://localhost:3000/ cy:open",
@@ -27,17 +28,19 @@
27
28
  "prepublishOnly": "npm run build && cp ../README.md ./"
28
29
  },
29
30
  "dependencies": {
30
- "@storyblok/js": "^1.8.5",
31
+ "@storyblok/js": "^2.0.4",
31
32
  "camelcase": "^7.0.0"
32
33
  },
33
34
  "devDependencies": {
34
- "@cypress/vite-dev-server": "^2.0.7",
35
- "@rollup/plugin-dynamic-import-vars": "^1.4.4",
36
- "axios": "^0.27.2",
37
- "cypress": "^10.9.0",
35
+ "@cypress/vite-dev-server": "^5.0.2",
36
+ "@rollup/plugin-dynamic-import-vars": "^2.0.1",
37
+ "cypress": "^12.1.0",
38
38
  "eslint-plugin-cypress": "^2.12.1",
39
- "start-server-and-test": "^1.14.0",
40
- "vite": "^3.1.3"
39
+ "start-server-and-test": "^1.15.2",
40
+ "vite": "^4.0.1",
41
+ "typescript": "4.9.4",
42
+ "@types/node": "18.11.10",
43
+ "astro": "1.6.15"
41
44
  },
42
45
  "repository": {
43
46
  "type": "git",
@@ -45,7 +48,8 @@
45
48
  },
46
49
  "keywords": [
47
50
  "astro",
48
- "storyblok"
51
+ "storyblok",
52
+ "astro-component"
49
53
  ],
50
54
  "author": "Alexander Feiglstorfer",
51
55
  "bugs": {