@storyblok/astro 1.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 ADDED
@@ -0,0 +1,252 @@
1
+ <div align="center">
2
+ <a href="https://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro" align="center">
3
+ <img src="https://a.storyblok.com/f/88751/600x200/cc68aca8ea/storyblok-astro.jpg" width="300" height="100" alt="Storyblok + Astro">
4
+ </a>
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 />
7
+ </div>
8
+
9
+ <p align="center">
10
+ <a href="https://npmjs.com/package/@storyblok/astro">
11
+ <img src="https://img.shields.io/npm/v/@storyblok/astro/latest.svg?style=flat-square" alt="Storyblok Astro" />
12
+ </a>
13
+ <a href="https://npmjs.com/package/@storyblok/astro" rel="nofollow">
14
+ <img src="https://img.shields.io/npm/dt/@storyblok/astro.svg?style=flat-square" alt="npm">
15
+ </a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://discord.gg/jKrbAMz">
20
+ <img src="https://img.shields.io/discord/700316478792138842?label=Join%20Our%20Discord%20Community&style=appveyor&logo=discord&color=09b3af">
21
+ </a>
22
+ <a href="https://twitter.com/intent/follow?screen_name=storyblok">
23
+ <img src="https://img.shields.io/badge/Follow-%40storyblok-09b3af?style=appveyor&logo=twitter" alt="Follow @Storyblok" />
24
+ </a><br/>
25
+ <a href="https://app.storyblok.com/#!/signup?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-nuxt">
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
+ </a>
28
+ </p>
29
+
30
+ ## Live Demo
31
+
32
+ If you are in a hurry, check out our official **[live demo](https://stackblitz.com/edit/astro-sdk-demo)** on StackBlitz.
33
+
34
+ ## 🚀 Usage
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.
37
+
38
+ ## Installation
39
+
40
+ Install `@storyblok/astro`:
41
+
42
+ ```bash
43
+ npm install @storyblok/astro
44
+ # yarn add @storyblok/astro
45
+ ```
46
+
47
+ Add the following code to `astro.config.mjs` and replace the `accessToken` with the preview API token of your Storyblok space.
48
+
49
+ ```js
50
+ import { defineConfig } from "astro/config";
51
+ import storyblok from "@storyblok/astro";
52
+
53
+ export default defineConfig({
54
+ integrations: [
55
+ storyblok({
56
+ accessToken: "<your-access-token>",
57
+ }),
58
+ ],
59
+ });
60
+ ```
61
+
62
+ ### Options
63
+
64
+ When you initialize the module, you can pass all [_@storyblok/js_ options](https://github.com/storyblok/storyblok-js#features-and-api)
65
+
66
+ ```js
67
+ // Defaults
68
+ storyblok({
69
+ accessToken: "<your-access-token>",
70
+ bridge: true,
71
+ apiOptions: {}, // storyblok-js-client options
72
+ use: [apiPlugin],
73
+ });
74
+ ```
75
+
76
+ > Note: if you don't use `apiPlugin`, you can use your preferred method or function to fetch your data.
77
+
78
+ ## Getting started
79
+
80
+ ### 1. Creating and linking your components to the Storyblok Visual Editor
81
+
82
+ In order to link your Astro components to their equivalents you created in Storyblok:
83
+
84
+ First, you need to load them globally by specifying their name and their path in `astro.config.mjs`:
85
+
86
+ ```javascript
87
+ components: {
88
+ page: "storyblok/Page",
89
+ feature: "storyblok/Feature",
90
+ grid: "storyblok/Grid",
91
+ teaser: "storyblok/Teaser",
92
+ },
93
+ ```
94
+
95
+ > Note: The `src` folder is automatically added to the beginning of the path, so in this example your Astro components should be located here:
96
+ >
97
+ > - `src/storyblok/Page.astro`
98
+ > - `src/storyblok/Feature.astro`
99
+ > - `src/storyblok/Grid.astro`
100
+ > - `src/storyblok/Teaser.astro`
101
+ > You can choose any other folder in the `src` directory for your Astro components.
102
+
103
+ For each component, use the `storyblokEditable()` function on its root element, passing the `blok` property that they receive:
104
+
105
+ ```html
106
+ ---
107
+ import { storyblokEditable } from '@storyblok/astro';
108
+
109
+ const { blok } = Astro.props
110
+ ---
111
+
112
+ <div {...storyblokEditable(blok)}>
113
+ <h2>{blok.headline}</h2>
114
+ </div>
115
+ ```
116
+
117
+ Finally, you can use the provided `<StoryblokComponent>` for nested components; it will automatically render them (if they have been registered globally beforehand):
118
+
119
+ ```html
120
+ ---
121
+ import { storyblokEditable } from '@storyblok/astro';
122
+ import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro';
123
+
124
+ const { blok } = Astro.props
125
+ ---
126
+
127
+ <main {...storyblokEditable(blok)}>
128
+ {blok.body?.map(blok => {return <StoryblokComponent blok="{blok}" />})}
129
+ </main>
130
+ ```
131
+
132
+ > Note: The `blok` is the actual blok data coming from [Storblok's Content Delivery API](https://www.storyblok.com/docs/api/content-delivery/v2?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro).
133
+
134
+ #### Using partial hydration
135
+
136
+ If you want to use partial hydration with any of the [frameworks supported by Astro](https://docs.astro.build/en/guides/integrations-guide/#article), follow these steps:
137
+
138
+ 1. [Install the official Astro integration for your desired framework](https://docs.astro.build/en/guides/integrations-guide/#automatic-integration-setup)
139
+ 2. Create an Astro component that serves as a wrapper and utilizes the most suitable [client directive](https://docs.astro.build/en/reference/directives-reference/#client-directives)
140
+ 3. Create the actual component in Vue, Svelte, React or any other supported framework
141
+
142
+ For working examples, please refer to the [Live Demo on Stackblitz](https://stackblitz.com/edit/astro-sdk-demo).
143
+
144
+ ### 2. Getting Storyblok Stories and using the Storyblok Bridge
145
+
146
+ ### Fetching one Story
147
+
148
+ Use the `useStoryblokApi` function to have access to an instance of `storyblok-js-client`:
149
+
150
+ ```html
151
+ ---
152
+ import { useStoryblokApi } from "@storyblok/astro";
153
+ import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
154
+
155
+ const storyblokApi = useStoryblokApi();
156
+ const { data } = await storyblokApi.get("cdn/stories/home", {
157
+ version: "draft",
158
+ });
159
+
160
+ const story = data.story;
161
+ ---
162
+
163
+ <StoryblokComponent blok="{story.content}" />
164
+ ```
165
+
166
+ > Note: The available methods are described in the [storyblok-js-client] repository(https://github.com/storyblok/storyblok-js-client#method-storyblokget)
167
+
168
+ ### Dynamic Routing
169
+
170
+ In order to dynamically generate Astro pages based on the Stories in your Storyblok Space, you can use the [Storyblok Links API](https://www.storyblok.com/docs/api/content-delivery/v2#core-resources/links/links) and the Astro [`getStaticPaths()` function](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) similar to this example:
171
+
172
+ ```html
173
+ ---
174
+ import { useStoryblokApi } from "@storyblok/astro";
175
+ import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
176
+
177
+ const storyblokApi = useStoryblokApi();
178
+
179
+ export async function getStaticPaths() {
180
+ const { data } = await storyblokApi.get("cdn/links", {
181
+ version: "draft",
182
+ });
183
+ let links = data.links;
184
+ links = Object.values(links);
185
+
186
+ return links.map((link) => {
187
+ return {
188
+ params: { slug: link.slug },
189
+ };
190
+ });
191
+ }
192
+
193
+ const { slug } = Astro.params;
194
+
195
+ const { data } = await storyblokApi.get(`cdn/stories/${slug}`, {
196
+ version: "draft",
197
+ });
198
+
199
+ const story = data.story;
200
+ ---
201
+
202
+ <StoryblokComponent blok="{story.content}" />
203
+ ```
204
+
205
+ ### Using the Storyblok Bridge
206
+
207
+ 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`:
208
+
209
+ > 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.
210
+
211
+ #### Rendering Rich Text
212
+
213
+ 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):
214
+
215
+ ```html
216
+ ---
217
+ import { renderRichText } from '@storyblok/astro';
218
+
219
+ const { blok } = Astro.props
220
+
221
+ const renderedRichText = renderRichText(blok.text)
222
+ ---
223
+
224
+ <div set:html="{renderedRichText}"></div>
225
+ ```
226
+
227
+ ## API
228
+
229
+ ### useStoryblokApi()
230
+
231
+ Returns the instance of the `storyblok-js-client`.
232
+
233
+ ## Acknowledgements
234
+
235
+ 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.
236
+
237
+ ## 🔗 Related Links
238
+
239
+ - **[Live Demo on Stackblitz](https://stackblitz.com/edit/astro-sdk-demo)**
240
+ - **[Storyblok CLI](https://github.com/storyblok/storyblok)**: A simple CLI for scaffolding Storyblok projects and fieldtypes.
241
+
242
+ ## ℹ️ More Resources
243
+
244
+ ### Support
245
+
246
+ - Bugs or Feature Requests? [Submit an issue](/../../issues/new);
247
+ - Do you have questions about Storyblok or you need help? [Join our Discord Community](https://discord.gg/jKrbAMz).
248
+
249
+ ### Contributing
250
+
251
+ 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).
252
+ 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.
@@ -0,0 +1,8 @@
1
+ ---
2
+ import components from 'virtual:storyblok-components';
3
+ const { blok } = Astro.props;
4
+
5
+ const Component = components[blok.component];
6
+ ---
7
+
8
+ {<Component blok={blok} />}
@@ -0,0 +1,19 @@
1
+ (function(h,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],g):(h=typeof globalThis<"u"?globalThis:h||self,g(h.storyblokAstro={},h.axios))})(this,function(h,g){"use strict";const E=(n=>n&&typeof n=="object"&&"default"in n?n:{default:n})(g);function j(n){const t="virtual:storyblok-components",e="\0"+t;return{name:"vite-plugin-storyblok",async resolveId(r){if(r===t)return e},async load(r){if(r===e){const s=[];for await(const[o,i]of Object.entries(n)){const{id:a}=await this.resolve("/src/"+i+".astro");s.push(`import ${o} from "${a}"`)}return`${s.join(";")};export default {${Object.keys(n).join(",")}}`}}}}var S=Object.defineProperty,A=Object.defineProperties,P=Object.getOwnPropertyDescriptors,b=Object.getOwnPropertySymbols,x=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable,v=(n,t,e)=>t in n?S(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e,d=(n,t)=>{for(var e in t||(t={}))x.call(t,e)&&v(n,e,t[e]);if(b)for(var e of b(t))M.call(t,e)&&v(n,e,t[e]);return n},k=(n,t)=>A(n,P(t));let T=!1;const _=[],w=n=>new Promise((t,e)=>{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}T?s():_.push(s)},document.getElementById("storyblok-javascript-bridge")))return;const r=document.createElement("script");r.async=!0,r.src=n,r.id="storyblok-javascript-bridge",r.onerror=s=>e(s),r.onload=s=>{_.forEach(o=>o()),T=!0,t(s)},document.getElementsByTagName("head")[0].appendChild(r)}),C=function(n,t){if(!n)return null;let e={};for(let r in n){let s=n[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e},I=n=>n==="email";var N={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(n){return{tag:["pre",{tag:"code",attrs:n.attrs}]}},hard_break(){return{singleTag:"br"}},heading(n){return{tag:`h${n.attrs.level}`}},image(n){return{singleTag:[{tag:"img",attrs:C(n.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(n){const t=d({},n.attrs),{linktype:e="url"}=n.attrs;return I(e)&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled(n){return{tag:[{tag:"span",attrs:n.attrs}]}}}};const q=function(n){const t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},e=/[&<>"']/g,r=RegExp(e.source);return n&&r.test(n)?n.replace(e,s=>t[s]):n};class L{constructor(t){t||(t=N),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(r=>{e+=this.renderNode(r)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(t);return r&&r.tag&&e.push(this.renderOpeningTag(r.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(q(t.text)):r&&r.singleTag?e.push(this.renderTag(r.singleTag," /")):r&&r.html&&e.push(r.html),r&&r.tag&&e.push(this.renderClosingTag(r.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderClosingTag(o.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(s=>{if(s.constructor===String)return`<${s}${e}>`;{let o=`<${s.tag}`;if(s.attrs)for(let i in s.attrs){let a=s.attrs[i];a!==null&&(o+=` ${i}="${a}"`)}return`${o}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(r=>r.constructor===String?`</${r}>`:`</${r.tag}>`).join("")}getMatchingNode(t){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}/*!
2
+ * storyblok-js-client v4.5.2
3
+ * Universal JavaScript SDK for Storyblok's API
4
+ * (c) 2020-2022 Stobylok Team
5
+ */function $(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function R(n,t,e){if(!$(t))throw new TypeError("Expected `limit` to be a finite number");if(!$(e))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],o=0,i=function(){o++;var c=setTimeout(function(){o--,r.length>0&&i(),s=s.filter(function(u){return u!==c})},e);s.indexOf(c)<0&&s.push(c);var l=r.shift();l.resolve(n.apply(l.self,l.args))},a=function(){var c=arguments,l=this;return new Promise(function(u,f){r.push({resolve:u,reject:f,args:c,self:l}),o<t&&i()})};return a.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},a}R.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const B=function(n,t){if(!n)return null;let e={};for(let r in n){let s=n[r];t.indexOf(r)>-1&&s!==null&&(e[r]=s)}return e};var z={nodes:{horizontal_rule:()=>({singleTag:"hr"}),blockquote:()=>({tag:"blockquote"}),bullet_list:()=>({tag:"ul"}),code_block:n=>({tag:["pre",{tag:"code",attrs:n.attrs}]}),hard_break:()=>({singleTag:"br"}),heading:n=>({tag:`h${n.attrs.level}`}),image:n=>({singleTag:[{tag:"img",attrs:B(n.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(n){const t=d({},n.attrs),{linktype:e="url"}=n.attrs;return e==="email"&&(t.href=`mailto:${t.href}`),t.anchor&&(t.href=`${t.href}#${t.anchor}`,delete t.anchor),{tag:[{tag:"a",attrs:t}]}},styled:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class U{constructor(t){t||(t=z),this.marks=t.marks||[],this.nodes=t.nodes||[]}addNode(t,e){this.nodes[t]=e}addMark(t,e){this.marks[t]=e}render(t={}){if(t.content&&Array.isArray(t.content)){let e="";return t.content.forEach(r=>{e+=this.renderNode(r)}),e}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(t){let e=[];t.marks&&t.marks.forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(t);return r&&r.tag&&e.push(this.renderOpeningTag(r.tag)),t.content?t.content.forEach(s=>{e.push(this.renderNode(s))}):t.text?e.push(function(s){const o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},i=/[&<>"']/g,a=RegExp(i.source);return s&&a.test(s)?s.replace(i,c=>o[c]):s}(t.text)):r&&r.singleTag?e.push(this.renderTag(r.singleTag," /")):r&&r.html&&e.push(r.html),r&&r.tag&&e.push(this.renderClosingTag(r.tag)),t.marks&&t.marks.slice(0).reverse().forEach(s=>{const o=this.getMatchingMark(s);o&&e.push(this.renderClosingTag(o.tag))}),e.join("")}renderTag(t,e){return t.constructor===String?`<${t}${e}>`:t.map(r=>{if(r.constructor===String)return`<${r}${e}>`;{let s=`<${r.tag}`;if(r.attrs)for(let o in r.attrs){let i=r.attrs[o];i!==null&&(s+=` ${o}="${i}"`)}return`${s}${e}>`}}).join("")}renderOpeningTag(t){return this.renderTag(t,"")}renderClosingTag(t){return t.constructor===String?`</${t}>`:t.slice(0).reverse().map(e=>e.constructor===String?`</${e}>`:`</${e.tag}>`).join("")}getMatchingNode(t){if(typeof this.nodes[t.type]=="function")return this.nodes[t.type](t)}getMatchingMark(t){if(typeof this.marks[t.type]=="function")return this.marks[t.type](t)}}const H=(n=0,t=n)=>{const e=Math.abs(t-n)||0,r=n<t?1:-1;return((s=0,o)=>[...Array(s)].map(o))(e,(s,o)=>o*r+n)},m=(n,t,e)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],i=e?"":encodeURIComponent(s);let a;a=typeof o=="object"?m(o,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(o)):(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(o),r.push(a)}return r.join("&")};let y={},p={};class V{constructor(t,e){if(!e){let o=t.region?`-${t.region}`:"",i=t.https===!1?"http":"https";e=t.oauthToken===void 0?`${i}://api${o}.storyblok.com/v2`:`${i}://api${o}.storyblok.com/v1`}let r=Object.assign({},t.headers),s=5;t.oauthToken!==void 0&&(r.Authorization=t.oauthToken,s=3),t.rateLimit!==void 0&&(s=t.rateLimit),this.richTextResolver=new U(t.richTextSchema),typeof t.componentResolver=="function"&&this.setComponentResolver(t.componentResolver),this.maxRetries=t.maxRetries||5,this.throttle=R(this.throttledRequest,s,1e3),this.accessToken=t.accessToken,this.relations={},this.links={},this.cache=t.cache||{clear:"manual"},this.client=E.default.create({baseURL:e,timeout:t.timeout||0,headers:r,proxy:t.proxy||!1}),t.responseInterceptor&&this.client.interceptors.response.use(o=>t.responseInterceptor(o)),this.resolveNestedRelations=t.resolveNestedRelations||!0}setComponentResolver(t){this.richTextResolver.addNode("blok",e=>{let r="";return e.attrs.body.forEach(s=>{r+=t(s.component,s)}),{html:r}})}parseParams(t={}){return t.version||(t.version="published"),t.token||(t.token=this.getToken()),t.cv||(t.cv=p[t.token]),Array.isArray(t.resolve_relations)&&(t.resolve_relations=t.resolve_relations.join(",")),t}factoryParamOptions(t,e={}){return((r="")=>r.indexOf("/cdn/")>-1)(t)?this.parseParams(e):e}makeRequest(t,e,r,s){const o=this.factoryParamOptions(t,((i={},a=25,c=1)=>k(d({},i),{per_page:a,page:c}))(e,r,s));return this.cacheResponse(t,o)}get(t,e){let r=`/${t}`;const s=this.factoryParamOptions(r,e);return this.cacheResponse(r,s)}async getAll(t,e={},r){const s=e.per_page||25,o=`/${t}`,i=o.split("/");r=r||i[i.length-1];const a=await this.makeRequest(o,e,s,1),c=Math.ceil(a.total/s);return((l=[],u)=>l.map(u).reduce((f,Z)=>[...f,...Z],[]))([a,...await(async(l=[],u)=>Promise.all(l.map(u)))(H(1,c),async l=>this.makeRequest(o,e,s,l+1))],l=>Object.values(l.data[r]))}post(t,e){let r=`/${t}`;return this.throttle("post",r,e)}put(t,e){let r=`/${t}`;return this.throttle("put",r,e)}delete(t,e){let r=`/${t}`;return this.throttle("delete",r,e)}getStories(t){return this.get("cdn/stories",t)}getStory(t,e){return this.get(`cdn/stories/${t}`,e)}setToken(t){this.accessToken=t}getToken(){return this.accessToken}_cleanCopy(t){return JSON.parse(JSON.stringify(t))}_insertLinks(t,e){const r=t[e];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(t,e,r){if(r.indexOf(t.component+"."+e)>-1){if(typeof t[e]=="string")this.relations[t[e]]&&(t[e]=this._cleanCopy(this.relations[t[e]]));else if(t[e].constructor===Array){let s=[];t[e].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),t[e]=s}}}_insertAssetsRelations(t,e){e.forEach(r=>{t.id===r.id&&(t.original=r,t.original.filename=t.filename,t.original.filename=t.original.filename.includes("https://s3.amazonaws.com/")?t.original.filename:t.original.filename.replace("https://","https://s3.amazonaws.com/"),delete t.original.s3_filename)})}iterateTree(t,e){let r=s=>{if(s!=null){if(s.constructor===Array)for(let o=0;o<s.length;o++)r(s[o]);else if(s.constructor===Object){if(s._stopResolving)return;for(let o in s)s.component&&s._uid||s.type==="link"?(this._insertRelations(s,o,e),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,e),r(s[o])}}};r(t.content)}async resolveLinks(t,e){let r=[];if(t.link_uuids){const s=t.link_uuids.length;let o=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);o.push(t.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=t.links;r.forEach(s=>{this.links[s.uuid]=k(d({},s),{_stopResolving:!0})})}async resolveRelations(t,e){let r=[];if(t.rel_uuids){const s=t.rel_uuids.length;let o=[];const i=50;for(let a=0;a<s;a+=i){const c=Math.min(s,a+i);o.push(t.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:e.language,version:e.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=t.rels;r.forEach(s=>{this.relations[s.uuid]=k(d({},s),{_stopResolving:!0})})}async resolveStories(t,e){let r=[];if(e.resolve_relations!==void 0&&e.resolve_relations.length>0&&(t.rels||t.rel_uuids)&&(r=e.resolve_relations.split(","),await this.resolveRelations(t,e)),["1","story","url"].indexOf(e.resolve_links)>-1&&(t.links||t.link_uuids)&&await this.resolveLinks(t,e),this.resolveNestedRelations)for(const s in this.relations)this.iterateTree(this.relations[s],r);t.story?this.iterateTree(t.story,r):t.stories.forEach(s=>{this.iterateTree(s,r)})}resolveAssetsRelations(t){const{assets:e,stories:r,story:s}=t;if(r)for(const o of r)this.iterateTree(o,e);else{if(!s)return t;this.iterateTree(s,e)}}cacheResponse(t,e,r){return r===void 0&&(r=0),new Promise(async(s,o)=>{let i=m({url:t,params:e}),a=this.cacheProvider();if(this.cache.clear==="auto"&&e.version==="draft"&&await this.flushCache(),e.version==="published"&&t!="/cdn/spaces/me"){const l=await a.get(i);if(l)return s(l)}try{let l=await this.throttle("get",t,{params:e,paramsSerializer:f=>m(f)}),u={data:l.data,headers:l.headers};if(u.data.assets&&u.data.assets.length&&this.resolveAssetsRelations(u.data),l.headers["per-page"]&&(u=Object.assign({},u,{perPage:parseInt(l.headers["per-page"]),total:parseInt(l.headers.total)})),l.status!=200)return o(l);(u.data.story||u.data.stories)&&await this.resolveStories(u.data,e),e.version==="published"&&t!="/cdn/spaces/me"&&a.set(i,u),u.data.cv&&(e.version=="draft"&&p[e.token]!=u.data.cv&&this.flushCache(),p[e.token]=u.data.cv),s(u)}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(u=>setTimeout(u,c))),this.cacheResponse(t,e,r).then(s).catch(o);o(l)}var c})}throttledRequest(t,e,r){return this.client[t](e,r)}cacheVersions(){return p}cacheVersion(){return p[this.accessToken]}setCacheVersion(t){this.accessToken&&(p[this.accessToken]=t)}cacheProvider(){return this.cache.type==="memory"?{get:t=>y[t],getAll:()=>y,set(t,e){y[t]=e},flush(){y={}}}:{get(){},getAll(){},set(){},flush(){}}}async flushCache(){return await this.cacheProvider().flush(),this}}const D=(n={})=>{const{apiOptions:t}=n;if(!t.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 V(t)}};var J=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const t=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(t),"data-blok-uid":t.id+"-"+t.uid}};const F=new L,O="https://app.storyblok.com/f/storyblok-v2-latest.js",Y=(n={})=>{const{bridge:t,accessToken:e,use:r=[],apiOptions:s={}}=n;s.accessToken=s.accessToken||e;const o={bridge:t,apiOptions:s};let i={};return r.forEach(a=>{i=d(d({},i),a(o))}),t!==!1&&w(O),i},G=n=>n===""?"":n?F.render(n):(console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
6
+
7
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),""),K=()=>w(O);function Q(n,t,e){const{storyblokApi:r}=Y({accessToken:n,use:t||[D],apiOptions:{...e}});globalThis.storyblokApiInstance=r}function W(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),globalThis.storyblokApiInstance}function X(n){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:t,updateConfig:e})=>{e({vite:{plugins:[j(n.components)]}}),Q(n.accessToken,n.use,n.apiOptions),(n.bridge||!0)&&t("page",`
8
+ import { loadStoryblokBridge } from "@storyblok/astro";
9
+ loadStoryblokBridge().then(() => {
10
+ const { StoryblokBridge, location } = window;
11
+ const storyblokInstance = new StoryblokBridge();
12
+
13
+ storyblokInstance.on(["published", "change"], (event) => {
14
+ if (!event.slugChanged) {
15
+ location.reload(true);
16
+ }
17
+ });
18
+ });
19
+ `)}}}}h.default=X,h.loadStoryblokBridge=K,h.renderRichText=G,h.storyblokEditable=J,h.useStoryblokApi=W,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,659 @@
1
+ import O from "axios";
2
+ function E(n) {
3
+ const t = "virtual:storyblok-components", e = "\0" + t;
4
+ return {
5
+ name: "vite-plugin-storyblok",
6
+ async resolveId(r) {
7
+ if (r === t)
8
+ return e;
9
+ },
10
+ async load(r) {
11
+ if (r === e) {
12
+ const s = [];
13
+ for await (const [o, i] of Object.entries(n)) {
14
+ const { id: a } = await this.resolve("/src/" + i + ".astro");
15
+ s.push(`import ${o} from "${a}"`);
16
+ }
17
+ return `${s.join(";")};export default {${Object.keys(n).join(",")}}`;
18
+ }
19
+ }
20
+ };
21
+ }
22
+ var j = Object.defineProperty, S = Object.defineProperties, A = Object.getOwnPropertyDescriptors, k = Object.getOwnPropertySymbols, P = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable, m = (n, t, e) => t in n ? j(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e, u = (n, t) => {
23
+ for (var e in t || (t = {}))
24
+ P.call(t, e) && m(n, e, t[e]);
25
+ if (k)
26
+ for (var e of k(t))
27
+ x.call(t, e) && m(n, e, t[e]);
28
+ return n;
29
+ }, f = (n, t) => S(n, A(t));
30
+ let b = !1;
31
+ const v = [], _ = (n) => new Promise((t, e) => {
32
+ if (typeof window > "u" || (window.storyblokRegisterEvent = (s) => {
33
+ if (window.location === window.parent.location) {
34
+ console.warn("You are not in Draft Mode or in the Visual Editor.");
35
+ return;
36
+ }
37
+ b ? s() : v.push(s);
38
+ }, document.getElementById("storyblok-javascript-bridge")))
39
+ return;
40
+ const r = document.createElement("script");
41
+ r.async = !0, r.src = n, r.id = "storyblok-javascript-bridge", r.onerror = (s) => e(s), r.onload = (s) => {
42
+ v.forEach((o) => o()), b = !0, t(s);
43
+ }, document.getElementsByTagName("head")[0].appendChild(r);
44
+ }), M = function(n, t) {
45
+ if (!n)
46
+ return null;
47
+ let e = {};
48
+ for (let r in n) {
49
+ let s = n[r];
50
+ t.indexOf(r) > -1 && s !== null && (e[r] = s);
51
+ }
52
+ return e;
53
+ }, C = (n) => n === "email";
54
+ var I = {
55
+ nodes: {
56
+ horizontal_rule() {
57
+ return {
58
+ singleTag: "hr"
59
+ };
60
+ },
61
+ blockquote() {
62
+ return {
63
+ tag: "blockquote"
64
+ };
65
+ },
66
+ bullet_list() {
67
+ return {
68
+ tag: "ul"
69
+ };
70
+ },
71
+ code_block(n) {
72
+ return {
73
+ tag: [
74
+ "pre",
75
+ {
76
+ tag: "code",
77
+ attrs: n.attrs
78
+ }
79
+ ]
80
+ };
81
+ },
82
+ hard_break() {
83
+ return {
84
+ singleTag: "br"
85
+ };
86
+ },
87
+ heading(n) {
88
+ return {
89
+ tag: `h${n.attrs.level}`
90
+ };
91
+ },
92
+ image(n) {
93
+ return {
94
+ singleTag: [
95
+ {
96
+ tag: "img",
97
+ attrs: M(n.attrs, ["src", "alt", "title"])
98
+ }
99
+ ]
100
+ };
101
+ },
102
+ list_item() {
103
+ return {
104
+ tag: "li"
105
+ };
106
+ },
107
+ ordered_list() {
108
+ return {
109
+ tag: "ol"
110
+ };
111
+ },
112
+ paragraph() {
113
+ return {
114
+ tag: "p"
115
+ };
116
+ }
117
+ },
118
+ marks: {
119
+ bold() {
120
+ return {
121
+ tag: "b"
122
+ };
123
+ },
124
+ strike() {
125
+ return {
126
+ tag: "strike"
127
+ };
128
+ },
129
+ underline() {
130
+ return {
131
+ tag: "u"
132
+ };
133
+ },
134
+ strong() {
135
+ return {
136
+ tag: "strong"
137
+ };
138
+ },
139
+ code() {
140
+ return {
141
+ tag: "code"
142
+ };
143
+ },
144
+ italic() {
145
+ return {
146
+ tag: "i"
147
+ };
148
+ },
149
+ link(n) {
150
+ const t = u({}, n.attrs), { linktype: e = "url" } = n.attrs;
151
+ return C(e) && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), {
152
+ tag: [
153
+ {
154
+ tag: "a",
155
+ attrs: t
156
+ }
157
+ ]
158
+ };
159
+ },
160
+ styled(n) {
161
+ return {
162
+ tag: [
163
+ {
164
+ tag: "span",
165
+ attrs: n.attrs
166
+ }
167
+ ]
168
+ };
169
+ }
170
+ }
171
+ };
172
+ const N = function(n) {
173
+ const t = {
174
+ "&": "&amp;",
175
+ "<": "&lt;",
176
+ ">": "&gt;",
177
+ '"': "&quot;",
178
+ "'": "&#39;"
179
+ }, e = /[&<>"']/g, r = RegExp(e.source);
180
+ return n && r.test(n) ? n.replace(e, (s) => t[s]) : n;
181
+ };
182
+ class q {
183
+ constructor(t) {
184
+ t || (t = I), this.marks = t.marks || [], this.nodes = t.nodes || [];
185
+ }
186
+ addNode(t, e) {
187
+ this.nodes[t] = e;
188
+ }
189
+ addMark(t, e) {
190
+ this.marks[t] = e;
191
+ }
192
+ render(t = {}) {
193
+ if (t.content && Array.isArray(t.content)) {
194
+ let e = "";
195
+ return t.content.forEach((r) => {
196
+ e += this.renderNode(r);
197
+ }), e;
198
+ }
199
+ return console.warn("The render method must receive an object with a content field, which is an array"), "";
200
+ }
201
+ renderNode(t) {
202
+ let e = [];
203
+ t.marks && t.marks.forEach((s) => {
204
+ const o = this.getMatchingMark(s);
205
+ o && e.push(this.renderOpeningTag(o.tag));
206
+ });
207
+ const r = this.getMatchingNode(t);
208
+ return r && r.tag && e.push(this.renderOpeningTag(r.tag)), t.content ? t.content.forEach((s) => {
209
+ e.push(this.renderNode(s));
210
+ }) : t.text ? e.push(N(t.text)) : r && r.singleTag ? e.push(this.renderTag(r.singleTag, " /")) : r && r.html && e.push(r.html), r && r.tag && e.push(this.renderClosingTag(r.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
211
+ const o = this.getMatchingMark(s);
212
+ o && e.push(this.renderClosingTag(o.tag));
213
+ }), e.join("");
214
+ }
215
+ renderTag(t, e) {
216
+ return t.constructor === String ? `<${t}${e}>` : t.map((s) => {
217
+ if (s.constructor === String)
218
+ return `<${s}${e}>`;
219
+ {
220
+ let o = `<${s.tag}`;
221
+ if (s.attrs)
222
+ for (let i in s.attrs) {
223
+ let a = s.attrs[i];
224
+ a !== null && (o += ` ${i}="${a}"`);
225
+ }
226
+ return `${o}${e}>`;
227
+ }
228
+ }).join("");
229
+ }
230
+ renderOpeningTag(t) {
231
+ return this.renderTag(t, "");
232
+ }
233
+ renderClosingTag(t) {
234
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((r) => r.constructor === String ? `</${r}>` : `</${r.tag}>`).join("");
235
+ }
236
+ getMatchingNode(t) {
237
+ if (typeof this.nodes[t.type] == "function")
238
+ return this.nodes[t.type](t);
239
+ }
240
+ getMatchingMark(t) {
241
+ if (typeof this.marks[t.type] == "function")
242
+ return this.marks[t.type](t);
243
+ }
244
+ }
245
+ /*!
246
+ * storyblok-js-client v4.5.2
247
+ * Universal JavaScript SDK for Storyblok's API
248
+ * (c) 2020-2022 Stobylok Team
249
+ */
250
+ function T(n) {
251
+ return typeof n == "number" && n == n && n !== 1 / 0 && n !== -1 / 0;
252
+ }
253
+ function w(n, t, e) {
254
+ if (!T(t))
255
+ throw new TypeError("Expected `limit` to be a finite number");
256
+ if (!T(e))
257
+ throw new TypeError("Expected `interval` to be a finite number");
258
+ var r = [], s = [], o = 0, i = function() {
259
+ o++;
260
+ var c = setTimeout(function() {
261
+ o--, r.length > 0 && i(), s = s.filter(function(h) {
262
+ return h !== c;
263
+ });
264
+ }, e);
265
+ s.indexOf(c) < 0 && s.push(c);
266
+ var l = r.shift();
267
+ l.resolve(n.apply(l.self, l.args));
268
+ }, a = function() {
269
+ var c = arguments, l = this;
270
+ return new Promise(function(h, p) {
271
+ r.push({ resolve: h, reject: p, args: c, self: l }), o < t && i();
272
+ });
273
+ };
274
+ return a.abort = function() {
275
+ s.forEach(clearTimeout), s = [], r.forEach(function(c) {
276
+ c.reject(new throttle.AbortError());
277
+ }), r.length = 0;
278
+ }, a;
279
+ }
280
+ w.AbortError = function() {
281
+ Error.call(this, "Throttled function aborted"), this.name = "AbortError";
282
+ };
283
+ const B = function(n, t) {
284
+ if (!n)
285
+ return null;
286
+ let e = {};
287
+ for (let r in n) {
288
+ let s = n[r];
289
+ t.indexOf(r) > -1 && s !== null && (e[r] = s);
290
+ }
291
+ return e;
292
+ };
293
+ var L = { nodes: { horizontal_rule: () => ({ singleTag: "hr" }), blockquote: () => ({ tag: "blockquote" }), bullet_list: () => ({ tag: "ul" }), code_block: (n) => ({ tag: ["pre", { tag: "code", attrs: n.attrs }] }), hard_break: () => ({ singleTag: "br" }), heading: (n) => ({ tag: `h${n.attrs.level}` }), image: (n) => ({ singleTag: [{ tag: "img", attrs: B(n.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(n) {
294
+ const t = u({}, n.attrs), { linktype: e = "url" } = n.attrs;
295
+ return e === "email" && (t.href = `mailto:${t.href}`), t.anchor && (t.href = `${t.href}#${t.anchor}`, delete t.anchor), { tag: [{ tag: "a", attrs: t }] };
296
+ }, styled: (n) => ({ tag: [{ tag: "span", attrs: n.attrs }] }) } };
297
+ class z {
298
+ constructor(t) {
299
+ t || (t = L), this.marks = t.marks || [], this.nodes = t.nodes || [];
300
+ }
301
+ addNode(t, e) {
302
+ this.nodes[t] = e;
303
+ }
304
+ addMark(t, e) {
305
+ this.marks[t] = e;
306
+ }
307
+ render(t = {}) {
308
+ if (t.content && Array.isArray(t.content)) {
309
+ let e = "";
310
+ return t.content.forEach((r) => {
311
+ e += this.renderNode(r);
312
+ }), e;
313
+ }
314
+ return console.warn("The render method must receive an object with a content field, which is an array"), "";
315
+ }
316
+ renderNode(t) {
317
+ let e = [];
318
+ t.marks && t.marks.forEach((s) => {
319
+ const o = this.getMatchingMark(s);
320
+ o && e.push(this.renderOpeningTag(o.tag));
321
+ });
322
+ const r = this.getMatchingNode(t);
323
+ return r && r.tag && e.push(this.renderOpeningTag(r.tag)), t.content ? t.content.forEach((s) => {
324
+ e.push(this.renderNode(s));
325
+ }) : t.text ? e.push(function(s) {
326
+ const o = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }, i = /[&<>"']/g, a = RegExp(i.source);
327
+ return s && a.test(s) ? s.replace(i, (c) => o[c]) : s;
328
+ }(t.text)) : r && r.singleTag ? e.push(this.renderTag(r.singleTag, " /")) : r && r.html && e.push(r.html), r && r.tag && e.push(this.renderClosingTag(r.tag)), t.marks && t.marks.slice(0).reverse().forEach((s) => {
329
+ const o = this.getMatchingMark(s);
330
+ o && e.push(this.renderClosingTag(o.tag));
331
+ }), e.join("");
332
+ }
333
+ renderTag(t, e) {
334
+ return t.constructor === String ? `<${t}${e}>` : t.map((r) => {
335
+ if (r.constructor === String)
336
+ return `<${r}${e}>`;
337
+ {
338
+ let s = `<${r.tag}`;
339
+ if (r.attrs)
340
+ for (let o in r.attrs) {
341
+ let i = r.attrs[o];
342
+ i !== null && (s += ` ${o}="${i}"`);
343
+ }
344
+ return `${s}${e}>`;
345
+ }
346
+ }).join("");
347
+ }
348
+ renderOpeningTag(t) {
349
+ return this.renderTag(t, "");
350
+ }
351
+ renderClosingTag(t) {
352
+ return t.constructor === String ? `</${t}>` : t.slice(0).reverse().map((e) => e.constructor === String ? `</${e}>` : `</${e.tag}>`).join("");
353
+ }
354
+ getMatchingNode(t) {
355
+ if (typeof this.nodes[t.type] == "function")
356
+ return this.nodes[t.type](t);
357
+ }
358
+ getMatchingMark(t) {
359
+ if (typeof this.marks[t.type] == "function")
360
+ return this.marks[t.type](t);
361
+ }
362
+ }
363
+ const U = (n = 0, t = n) => {
364
+ const e = Math.abs(t - n) || 0, r = n < t ? 1 : -1;
365
+ return ((s = 0, o) => [...Array(s)].map(o))(e, (s, o) => o * r + n);
366
+ }, y = (n, t, e) => {
367
+ const r = [];
368
+ for (const s in n) {
369
+ if (!Object.prototype.hasOwnProperty.call(n, s))
370
+ continue;
371
+ const o = n[s], i = e ? "" : encodeURIComponent(s);
372
+ let a;
373
+ a = typeof o == "object" ? y(o, t ? t + encodeURIComponent("[" + i + "]") : i, Array.isArray(o)) : (t ? t + encodeURIComponent("[" + i + "]") : i) + "=" + encodeURIComponent(o), r.push(a);
374
+ }
375
+ return r.join("&");
376
+ };
377
+ let g = {}, d = {};
378
+ class H {
379
+ constructor(t, e) {
380
+ if (!e) {
381
+ let o = t.region ? `-${t.region}` : "", i = t.https === !1 ? "http" : "https";
382
+ e = t.oauthToken === void 0 ? `${i}://api${o}.storyblok.com/v2` : `${i}://api${o}.storyblok.com/v1`;
383
+ }
384
+ let r = Object.assign({}, t.headers), s = 5;
385
+ t.oauthToken !== void 0 && (r.Authorization = t.oauthToken, s = 3), t.rateLimit !== void 0 && (s = t.rateLimit), this.richTextResolver = new z(t.richTextSchema), typeof t.componentResolver == "function" && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries || 5, this.throttle = w(this.throttledRequest, s, 1e3), this.accessToken = t.accessToken, this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.client = O.create({ baseURL: e, timeout: t.timeout || 0, headers: r, proxy: t.proxy || !1 }), t.responseInterceptor && this.client.interceptors.response.use((o) => t.responseInterceptor(o)), this.resolveNestedRelations = t.resolveNestedRelations || !0;
386
+ }
387
+ setComponentResolver(t) {
388
+ this.richTextResolver.addNode("blok", (e) => {
389
+ let r = "";
390
+ return e.attrs.body.forEach((s) => {
391
+ r += t(s.component, s);
392
+ }), { html: r };
393
+ });
394
+ }
395
+ parseParams(t = {}) {
396
+ return t.version || (t.version = "published"), t.token || (t.token = this.getToken()), t.cv || (t.cv = d[t.token]), Array.isArray(t.resolve_relations) && (t.resolve_relations = t.resolve_relations.join(",")), t;
397
+ }
398
+ factoryParamOptions(t, e = {}) {
399
+ return ((r = "") => r.indexOf("/cdn/") > -1)(t) ? this.parseParams(e) : e;
400
+ }
401
+ makeRequest(t, e, r, s) {
402
+ const o = this.factoryParamOptions(t, ((i = {}, a = 25, c = 1) => f(u({}, i), { per_page: a, page: c }))(e, r, s));
403
+ return this.cacheResponse(t, o);
404
+ }
405
+ get(t, e) {
406
+ let r = `/${t}`;
407
+ const s = this.factoryParamOptions(r, e);
408
+ return this.cacheResponse(r, s);
409
+ }
410
+ async getAll(t, e = {}, r) {
411
+ const s = e.per_page || 25, o = `/${t}`, i = o.split("/");
412
+ r = r || i[i.length - 1];
413
+ const a = await this.makeRequest(o, e, s, 1), c = Math.ceil(a.total / s);
414
+ return ((l = [], h) => l.map(h).reduce((p, R) => [...p, ...R], []))([a, ...await (async (l = [], h) => Promise.all(l.map(h)))(U(1, c), async (l) => this.makeRequest(o, e, s, l + 1))], (l) => Object.values(l.data[r]));
415
+ }
416
+ post(t, e) {
417
+ let r = `/${t}`;
418
+ return this.throttle("post", r, e);
419
+ }
420
+ put(t, e) {
421
+ let r = `/${t}`;
422
+ return this.throttle("put", r, e);
423
+ }
424
+ delete(t, e) {
425
+ let r = `/${t}`;
426
+ return this.throttle("delete", r, e);
427
+ }
428
+ getStories(t) {
429
+ return this.get("cdn/stories", t);
430
+ }
431
+ getStory(t, e) {
432
+ return this.get(`cdn/stories/${t}`, e);
433
+ }
434
+ setToken(t) {
435
+ this.accessToken = t;
436
+ }
437
+ getToken() {
438
+ return this.accessToken;
439
+ }
440
+ _cleanCopy(t) {
441
+ return JSON.parse(JSON.stringify(t));
442
+ }
443
+ _insertLinks(t, e) {
444
+ const r = t[e];
445
+ 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]));
446
+ }
447
+ _insertRelations(t, e, r) {
448
+ if (r.indexOf(t.component + "." + e) > -1) {
449
+ if (typeof t[e] == "string")
450
+ this.relations[t[e]] && (t[e] = this._cleanCopy(this.relations[t[e]]));
451
+ else if (t[e].constructor === Array) {
452
+ let s = [];
453
+ t[e].forEach((o) => {
454
+ this.relations[o] && s.push(this._cleanCopy(this.relations[o]));
455
+ }), t[e] = s;
456
+ }
457
+ }
458
+ }
459
+ _insertAssetsRelations(t, e) {
460
+ e.forEach((r) => {
461
+ t.id === r.id && (t.original = r, t.original.filename = t.filename, t.original.filename = t.original.filename.includes("https://s3.amazonaws.com/") ? t.original.filename : t.original.filename.replace("https://", "https://s3.amazonaws.com/"), delete t.original.s3_filename);
462
+ });
463
+ }
464
+ iterateTree(t, e) {
465
+ let r = (s) => {
466
+ if (s != null) {
467
+ if (s.constructor === Array)
468
+ for (let o = 0; o < s.length; o++)
469
+ r(s[o]);
470
+ else if (s.constructor === Object) {
471
+ if (s._stopResolving)
472
+ return;
473
+ for (let o in s)
474
+ s.component && s._uid || s.type === "link" ? (this._insertRelations(s, o, e), this._insertLinks(s, o)) : "id" in s && s.fieldtype === "asset" && this._insertAssetsRelations(s, e), r(s[o]);
475
+ }
476
+ }
477
+ };
478
+ r(t.content);
479
+ }
480
+ async resolveLinks(t, e) {
481
+ let r = [];
482
+ if (t.link_uuids) {
483
+ const s = t.link_uuids.length;
484
+ let o = [];
485
+ const i = 50;
486
+ for (let a = 0; a < s; a += i) {
487
+ const c = Math.min(s, a + i);
488
+ o.push(t.link_uuids.slice(a, c));
489
+ }
490
+ for (let a = 0; a < o.length; a++)
491
+ (await this.getStories({ per_page: i, language: e.language, version: e.version, by_uuids: o[a].join(",") })).data.stories.forEach((c) => {
492
+ r.push(c);
493
+ });
494
+ } else
495
+ r = t.links;
496
+ r.forEach((s) => {
497
+ this.links[s.uuid] = f(u({}, s), { _stopResolving: !0 });
498
+ });
499
+ }
500
+ async resolveRelations(t, e) {
501
+ let r = [];
502
+ if (t.rel_uuids) {
503
+ const s = t.rel_uuids.length;
504
+ let o = [];
505
+ const i = 50;
506
+ for (let a = 0; a < s; a += i) {
507
+ const c = Math.min(s, a + i);
508
+ o.push(t.rel_uuids.slice(a, c));
509
+ }
510
+ for (let a = 0; a < o.length; a++)
511
+ (await this.getStories({ per_page: i, language: e.language, version: e.version, by_uuids: o[a].join(",") })).data.stories.forEach((c) => {
512
+ r.push(c);
513
+ });
514
+ } else
515
+ r = t.rels;
516
+ r.forEach((s) => {
517
+ this.relations[s.uuid] = f(u({}, s), { _stopResolving: !0 });
518
+ });
519
+ }
520
+ async resolveStories(t, e) {
521
+ let r = [];
522
+ if (e.resolve_relations !== void 0 && e.resolve_relations.length > 0 && (t.rels || t.rel_uuids) && (r = e.resolve_relations.split(","), await this.resolveRelations(t, e)), ["1", "story", "url"].indexOf(e.resolve_links) > -1 && (t.links || t.link_uuids) && await this.resolveLinks(t, e), this.resolveNestedRelations)
523
+ for (const s in this.relations)
524
+ this.iterateTree(this.relations[s], r);
525
+ t.story ? this.iterateTree(t.story, r) : t.stories.forEach((s) => {
526
+ this.iterateTree(s, r);
527
+ });
528
+ }
529
+ resolveAssetsRelations(t) {
530
+ const { assets: e, stories: r, story: s } = t;
531
+ if (r)
532
+ for (const o of r)
533
+ this.iterateTree(o, e);
534
+ else {
535
+ if (!s)
536
+ return t;
537
+ this.iterateTree(s, e);
538
+ }
539
+ }
540
+ cacheResponse(t, e, r) {
541
+ return r === void 0 && (r = 0), new Promise(async (s, o) => {
542
+ let i = y({ url: t, params: e }), a = this.cacheProvider();
543
+ if (this.cache.clear === "auto" && e.version === "draft" && await this.flushCache(), e.version === "published" && t != "/cdn/spaces/me") {
544
+ const l = await a.get(i);
545
+ if (l)
546
+ return s(l);
547
+ }
548
+ try {
549
+ let l = await this.throttle("get", t, { params: e, paramsSerializer: (p) => y(p) }), h = { data: l.data, headers: l.headers };
550
+ 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)
551
+ return o(l);
552
+ (h.data.story || h.data.stories) && await this.resolveStories(h.data, e), e.version === "published" && t != "/cdn/spaces/me" && a.set(i, h), h.data.cv && (e.version == "draft" && d[e.token] != h.data.cv && this.flushCache(), d[e.token] = h.data.cv), s(h);
553
+ } catch (l) {
554
+ if (l.response && l.response.status === 429 && (r += 1) < this.maxRetries)
555
+ return console.log(`Hit rate limit. Retrying in ${r} seconds.`), await (c = 1e3 * r, new Promise((h) => setTimeout(h, c))), this.cacheResponse(t, e, r).then(s).catch(o);
556
+ o(l);
557
+ }
558
+ var c;
559
+ });
560
+ }
561
+ throttledRequest(t, e, r) {
562
+ return this.client[t](e, r);
563
+ }
564
+ cacheVersions() {
565
+ return d;
566
+ }
567
+ cacheVersion() {
568
+ return d[this.accessToken];
569
+ }
570
+ setCacheVersion(t) {
571
+ this.accessToken && (d[this.accessToken] = t);
572
+ }
573
+ cacheProvider() {
574
+ return this.cache.type === "memory" ? { get: (t) => g[t], getAll: () => g, set(t, e) {
575
+ g[t] = e;
576
+ }, flush() {
577
+ g = {};
578
+ } } : { get() {
579
+ }, getAll() {
580
+ }, set() {
581
+ }, flush() {
582
+ } };
583
+ }
584
+ async flushCache() {
585
+ return await this.cacheProvider().flush(), this;
586
+ }
587
+ }
588
+ const V = (n = {}) => {
589
+ const { apiOptions: t } = n;
590
+ if (!t.accessToken) {
591
+ 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");
592
+ return;
593
+ }
594
+ return { storyblokApi: new H(t) };
595
+ };
596
+ var G = (n) => {
597
+ if (typeof n != "object" || typeof n._editable > "u")
598
+ return {};
599
+ const t = JSON.parse(n._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
600
+ return {
601
+ "data-blok-c": JSON.stringify(t),
602
+ "data-blok-uid": t.id + "-" + t.uid
603
+ };
604
+ };
605
+ const J = new q(), $ = "https://app.storyblok.com/f/storyblok-v2-latest.js", D = (n = {}) => {
606
+ const { bridge: t, accessToken: e, use: r = [], apiOptions: s = {} } = n;
607
+ s.accessToken = s.accessToken || e;
608
+ const o = { bridge: t, apiOptions: s };
609
+ let i = {};
610
+ return r.forEach((a) => {
611
+ i = u(u({}, i), a(o));
612
+ }), t !== !1 && _($), i;
613
+ }, K = (n) => n === "" ? "" : n ? J.render(n) : (console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
614
+
615
+ For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), ""), Q = () => _($);
616
+ function F(n, t, e) {
617
+ const { storyblokApi: r } = D({
618
+ accessToken: n,
619
+ use: t || [V],
620
+ apiOptions: { ...e }
621
+ });
622
+ globalThis.storyblokApiInstance = r;
623
+ }
624
+ function W() {
625
+ return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), globalThis.storyblokApiInstance;
626
+ }
627
+ function X(n) {
628
+ return {
629
+ name: "@storyblok/astro",
630
+ hooks: {
631
+ "astro:config:setup": ({ injectScript: t, updateConfig: e }) => {
632
+ e({
633
+ vite: {
634
+ plugins: [E(n.components)]
635
+ }
636
+ }), F(n.accessToken, n.use, n.apiOptions), (n.bridge || !0) && t("page", `
637
+ import { loadStoryblokBridge } from "@storyblok/astro";
638
+ loadStoryblokBridge().then(() => {
639
+ const { StoryblokBridge, location } = window;
640
+ const storyblokInstance = new StoryblokBridge();
641
+
642
+ storyblokInstance.on(["published", "change"], (event) => {
643
+ if (!event.slugChanged) {
644
+ location.reload(true);
645
+ }
646
+ });
647
+ });
648
+ `);
649
+ }
650
+ }
651
+ };
652
+ }
653
+ export {
654
+ X as default,
655
+ Q as loadStoryblokBridge,
656
+ K as renderRichText,
657
+ G as storyblokEditable,
658
+ W as useStoryblokApi
659
+ };
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "@storyblok/astro",
3
+ "version": "1.0.0",
4
+ "description": "UPDATE DESCRIPTION",
5
+ "main": "./dist/storyblok-astro.js",
6
+ "module": "./dist/storyblok-astro.mjs",
7
+ "files": [
8
+ "dist",
9
+ "StoryblokComponent.astro"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/storyblok-astro.mjs",
14
+ "require": "./dist/storyblok-astro.js"
15
+ },
16
+ "./StoryblokComponent.astro": "./StoryblokComponent.astro"
17
+ },
18
+ "scripts": {
19
+ "dev": "vite build --watch",
20
+ "build": "vite build",
21
+ "test": "npm run test:e2e",
22
+ "test:e2e": "start-server-and-test cy:playground http-get://localhost:3000/ cy:run",
23
+ "test:e2e-watch": "start-server-and-test cy:playground http-get://localhost:3000/ cy:open",
24
+ "cy:playground": "npm run dev --prefix ../playground-test",
25
+ "cy:run": "cypress run",
26
+ "cy:open": "cypress open",
27
+ "prepublishOnly": "npm run build && cp ../README.md ./"
28
+ },
29
+ "dependencies": {
30
+ "@storyblok/js": "^1.7.2"
31
+ },
32
+ "devDependencies": {
33
+ "@babel/core": "^7.15.0",
34
+ "@cypress/vite-dev-server": "^2.0.7",
35
+ "@rollup/plugin-dynamic-import-vars": "^1.4.3",
36
+ "@vue/babel-preset-app": "^4.5.13",
37
+ "@vue/test-utils": "next",
38
+ "axios": "^0.27.2",
39
+ "babel-jest": "^26.6.3",
40
+ "cypress": "^10.6.0",
41
+ "eslint-plugin-cypress": "^2.12.1",
42
+ "eslint-plugin-jest": "^25.2.4",
43
+ "jest": "^26.6.3",
44
+ "start-server-and-test": "^1.14.0",
45
+ "vite": "^3.0.8"
46
+ },
47
+ "babel": {
48
+ "presets": [
49
+ "@vue/babel-preset-app"
50
+ ]
51
+ },
52
+ "jest": {
53
+ "moduleFileExtensions": [
54
+ "js",
55
+ "json",
56
+ "vue"
57
+ ],
58
+ "transform": {
59
+ "^.+\\.js$": "babel-jest"
60
+ }
61
+ },
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "https://github.com/storyblok/storyblok-astro"
65
+ },
66
+ "keywords": [
67
+ "astro",
68
+ "storyblok"
69
+ ],
70
+ "author": "Alexander Feiglstorfer",
71
+ "bugs": {
72
+ "url": "https://github.com/storyblok/storyblok-astro/issues"
73
+ },
74
+ "homepage": "https://github.com/storyblok/storyblok-astro",
75
+ "release": {
76
+ "branches": [
77
+ "main"
78
+ ]
79
+ },
80
+ "publishConfig": {
81
+ "access": "public"
82
+ }
83
+ }