@storyblok/astro 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -22
- package/StoryblokComponent.astro +18 -1
- package/dist/storyblok-astro.js +24 -17
- package/dist/storyblok-astro.mjs +212 -525
- package/package.json +8 -6
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
|
|
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-
|
|
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
|
-
##
|
|
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-
|
|
36
|
+
> If you are first-time user of Storyblok, read the [Getting Started](https://www.storyblok.com/docs/guide/getting-started?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro) guide to get a project ready in less than 5 minutes.
|
|
37
37
|
|
|
38
38
|
## Installation
|
|
39
39
|
|
|
@@ -61,7 +61,7 @@ export default defineConfig({
|
|
|
61
61
|
|
|
62
62
|
### Options
|
|
63
63
|
|
|
64
|
-
When you initialize the
|
|
64
|
+
When you initialize the integration, you can pass all [_@storyblok/js_ options](https://github.com/storyblok/storyblok-js#features-and-api). For spaces created in the United States, you have to set the `region` parameter accordingly `{ apiOptions: { region: 'us' } }`.
|
|
65
65
|
|
|
66
66
|
```js
|
|
67
67
|
// Defaults
|
|
@@ -69,11 +69,11 @@ storyblok({
|
|
|
69
69
|
accessToken: "<your-access-token>",
|
|
70
70
|
bridge: true,
|
|
71
71
|
apiOptions: {}, // storyblok-js-client options
|
|
72
|
-
|
|
72
|
+
useCustomApi: false,
|
|
73
73
|
});
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
> Note:
|
|
76
|
+
> Note: By default, the apiPlugin from `@storyblok/js` is loaded. If you want to use your own method to fetch data from Storyblok, you can disable this behavior by setting `useCustomApi` to `true`, resulting in an optimized final bundle.
|
|
77
77
|
|
|
78
78
|
## Getting started
|
|
79
79
|
|
|
@@ -125,7 +125,7 @@ const { blok } = Astro.props
|
|
|
125
125
|
---
|
|
126
126
|
|
|
127
127
|
<main {...storyblokEditable(blok)}>
|
|
128
|
-
{blok.body?.map(blok => {return <StoryblokComponent blok={blok} />})}
|
|
128
|
+
{blok.body?.map(blok => {return <StoryblokComponent blok="{blok}" />})}
|
|
129
129
|
</main>
|
|
130
130
|
```
|
|
131
131
|
|
|
@@ -143,7 +143,7 @@ For working examples, please refer to the [Live Demo on Stackblitz](https://stac
|
|
|
143
143
|
|
|
144
144
|
### 2. Getting Storyblok Stories and using the Storyblok Bridge
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
#### Fetching one Story
|
|
147
147
|
|
|
148
148
|
Use the `useStoryblokApi` function to have access to an instance of `storyblok-js-client`:
|
|
149
149
|
|
|
@@ -160,12 +160,12 @@ const { data } = await storyblokApi.get("cdn/stories/home", {
|
|
|
160
160
|
const story = data.story;
|
|
161
161
|
---
|
|
162
162
|
|
|
163
|
-
<StoryblokComponent blok={story.content} />
|
|
163
|
+
<StoryblokComponent blok="{story.content}" />
|
|
164
164
|
```
|
|
165
165
|
|
|
166
166
|
> Note: The available methods are described in the [storyblok-js-client] repository(https://github.com/storyblok/storyblok-js-client#method-storyblokget)
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
#### Dynamic Routing
|
|
169
169
|
|
|
170
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
171
|
|
|
@@ -201,16 +201,18 @@ const { data } = await storyblokApi.get(`cdn/stories/${slug}`, {
|
|
|
201
201
|
const story = data.story;
|
|
202
202
|
---
|
|
203
203
|
|
|
204
|
-
<StoryblokComponent blok={story.content} />
|
|
204
|
+
<StoryblokComponent blok="{story.content}" />
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
### Using the Storyblok Bridge
|
|
208
208
|
|
|
209
|
-
The Storyblok Bridge is
|
|
209
|
+
The Storyblok Bridge is enabled by default. If you would like to disable it or enable it conditionally (e.g. depending on the environment) you can set the `bridge` parameter to `true` or `false` in `astro.config.mjs`:
|
|
210
210
|
|
|
211
211
|
> Note: Since Astro is not a reactive JavaScript framework and renders everything as HTML, the Storyblok Bridge will not provide real-time editing as you may know it from other frameworks. However, it automatically refreshes the site for you whenever you save or publish a story.
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
If you want to deploy a dedicated preview environment with the Bridge enabled, allowing users of the Storyblok CMS to see their changes being reflected on the frontend directly without having to rebuild the static site, you can enable Server Side Rendering for that particular use case. More information can be found in the [Astro Docs](https://docs.astro.build/en/guides/server-side-rendering/).
|
|
214
|
+
|
|
215
|
+
### Rendering Rich Text
|
|
214
216
|
|
|
215
217
|
You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/astro`. Then you can use the [`set:html` directive](https://docs.astro.build/en/reference/directives-reference/#sethtml):
|
|
216
218
|
|
|
@@ -223,7 +225,7 @@ const { blok } = Astro.props
|
|
|
223
225
|
const renderedRichText = renderRichText(blok.text)
|
|
224
226
|
---
|
|
225
227
|
|
|
226
|
-
<div set:html={renderedRichText}></div>
|
|
228
|
+
<div set:html="{renderedRichText}"></div>
|
|
227
229
|
```
|
|
228
230
|
|
|
229
231
|
You can also set a **custom Schema and component resolver** by passing the options as the second parameter of the `renderRichText` function:
|
|
@@ -234,9 +236,9 @@ import cloneDeep from "clone-deep";
|
|
|
234
236
|
|
|
235
237
|
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
|
|
236
238
|
// ... and edit the nodes and marks, or add your own.
|
|
237
|
-
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/
|
|
239
|
+
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/v4/source/schema.js
|
|
238
240
|
|
|
239
|
-
const { blok } = Astro.props
|
|
241
|
+
const { blok } = Astro.props;
|
|
240
242
|
|
|
241
243
|
const renderedRichText = renderRichText(blok.text, {
|
|
242
244
|
schema: mySchema,
|
|
@@ -260,21 +262,22 @@ Returns the instance of the `storyblok-js-client`.
|
|
|
260
262
|
|
|
261
263
|
## Acknowledgements
|
|
262
264
|
|
|
263
|
-
A huge thank you goes to the Astro Team. In particular to [Tony
|
|
265
|
+
A huge thank you goes to the Astro Team. In particular to [Tony Sullivan](https://github.com/tony-sull), who has provided extraordinary support and made _automagically_ rendering Storyblok components a reality.
|
|
264
266
|
|
|
265
|
-
##
|
|
267
|
+
## Related Links
|
|
266
268
|
|
|
267
269
|
- **[Live Demo on Stackblitz](https://stackblitz.com/edit/astro-sdk-demo)**
|
|
268
270
|
- **[Storyblok CLI](https://github.com/storyblok/storyblok)**: A simple CLI for scaffolding Storyblok projects and fieldtypes.
|
|
269
271
|
|
|
270
|
-
##
|
|
272
|
+
## More Resources
|
|
271
273
|
|
|
272
274
|
### Support
|
|
273
275
|
|
|
274
276
|
- Bugs or Feature Requests? [Submit an issue](/../../issues/new);
|
|
275
|
-
- Do you have questions about
|
|
277
|
+
- Do you have questions about this SDK? Or would you like to join the growing community of `@storyblok/astro` users? [Join the Astro Discord Community](https://discord.com/channels/830184174198718474/1002802280267001858)
|
|
278
|
+
- Do you have questions about Storyblok or you need help? [Join the Storyblok Discord Community](https://discord.gg/jKrbAMz).
|
|
276
279
|
|
|
277
280
|
### Contributing
|
|
278
281
|
|
|
279
282
|
Please see our [contributing guidelines](https://github.com/storyblok/.github/blob/master/contributing.md) and our [code of conduct](https://www.storyblok.com/trust-center#code-of-conduct?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro).
|
|
280
|
-
This project
|
|
283
|
+
This project uses [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for generating new versions by using commit messages. We use the Angular Convention to name the commits.
|
package/StoryblokComponent.astro
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
---
|
|
2
2
|
import components from "virtual:storyblok-components";
|
|
3
|
+
import camelcase from "camelcase";
|
|
4
|
+
|
|
3
5
|
const { blok, ...props } = Astro.props;
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* convert blok components to camel case to match vite-plugin-storyblok
|
|
9
|
+
*/
|
|
10
|
+
const key = camelcase(blok.component);
|
|
11
|
+
|
|
12
|
+
if (!(key in components)) {
|
|
13
|
+
/**
|
|
14
|
+
* Component not found! Log an error with details on the blok name that could not be found
|
|
15
|
+
* TODO: Add support for a placeholder component as a fallback?
|
|
16
|
+
*/
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Component could not be found for blok "${blok.component}"! Is it defined in astro.config.mjs?`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const Component = components[key];
|
|
6
23
|
---
|
|
7
24
|
|
|
8
25
|
<Component blok={blok} {...props} />
|
package/dist/storyblok-astro.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/function E(n){return typeof n=="number"&&n==n&&n!==1/0&&n!==-1/0}function S(n,e,t){if(!E(e))throw new TypeError("Expected `limit` to be a finite number");if(!E(t))throw new TypeError("Expected `interval` to be a finite number");var r=[],s=[],o=0,a=function(){o++;var c=setTimeout(function(){o--,r.length>0&&a(),s=s.filter(function(u){return u!==c})},t);s.indexOf(c)<0&&s.push(c);var l=r.shift();l.resolve(n.apply(l.self,l.args))},i=function(){var c=arguments,l=this;return new Promise(function(u,f){r.push({resolve:u,reject:f,args:c,self:l}),o<e&&a()})};return i.abort=function(){s.forEach(clearTimeout),s=[],r.forEach(function(c){c.reject(new throttle.AbortError)}),r.length=0},i}S.AbortError=function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"};const D=function(n,e){if(!n)return null;let t={};for(let r in n){let s=n[r];e.indexOf(r)>-1&&s!==null&&(t[r]=s)}return t};var U={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:D(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 e=d({},n.attrs),{linktype:t="url"}=n.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:n=>({tag:[{tag:"span",attrs:n.attrs}]})}};class H{constructor(e){e||(e=U),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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderOpeningTag(o.tag))});const r=this.getMatchingNode(e);return r&&r.tag&&t.push(this.renderOpeningTag(r.tag)),e.content?e.content.forEach(s=>{t.push(this.renderNode(s))}):e.text?t.push(function(s){const o={"&":"&","<":"<",">":">",'"':""","'":"'"},a=/[&<>"']/g,i=RegExp(a.source);return s&&i.test(s)?s.replace(a,c=>o[c]):s}(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(s=>{const o=this.getMatchingMark(s);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(r=>{if(r.constructor===String)return`<${r}${t}>`;{let s=`<${r.tag}`;if(r.attrs)for(let o in r.attrs){let a=r.attrs[o];a!==null&&(s+=` ${o}="${a}"`)}return`${s}${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 V=(n=0,e=n)=>{const t=Math.abs(e-n)||0,r=n<e?1:-1;return((s=0,o)=>[...Array(s)].map(o))(t,(s,o)=>o*r+n)},m=(n,e,t)=>{const r=[];for(const s in n){if(!Object.prototype.hasOwnProperty.call(n,s))continue;const o=n[s],a=t?"":encodeURIComponent(s);let i;i=typeof o=="object"?m(o,e?e+encodeURIComponent("["+a+"]"):a,Array.isArray(o)):(e?e+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(o),r.push(i)}return r.join("&")};let y={},p={};class J{constructor(e,t){if(!t){let o=e.region?`-${e.region}`:"",a=e.https===!1?"http":"https";t=e.oauthToken===void 0?`${a}://api${o}.storyblok.com/v2`:`${a}://api${o}.storyblok.com/v1`}let r=Object.assign({},e.headers),s=5;e.oauthToken!==void 0&&(r.Authorization=e.oauthToken,s=3),e.rateLimit!==void 0&&(s=e.rateLimit),this.richTextResolver=new H(e.richTextSchema),typeof e.componentResolver=="function"&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries||5,this.throttle=S(this.throttledRequest,s,1e3),this.accessToken=e.accessToken,this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.client=A.default.create({baseURL:t,timeout:e.timeout||0,headers:r,proxy:e.proxy||!1}),e.responseInterceptor&&this.client.interceptors.response.use(o=>e.responseInterceptor(o)),this.resolveNestedRelations=e.resolveNestedRelations||!0}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})}parseParams(e={}){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=p[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,s){const o=this.factoryParamOptions(e,((a={},i=25,c=1)=>k(d({},a),{per_page:i,page:c}))(t,r,s));return this.cacheResponse(e,o)}get(e,t){let r=`/${e}`;const s=this.factoryParamOptions(r,t);return this.cacheResponse(r,s)}async getAll(e,t={},r){const s=t.per_page||25,o=`/${e}`,a=o.split("/");r=r||a[a.length-1];const i=await this.makeRequest(o,t,s,1),c=Math.ceil(i.total/s);return((l=[],u)=>l.map(u).reduce((f,te)=>[...f,...te],[]))([i,...await(async(l=[],u)=>Promise.all(l.map(u)))(V(1,c),async l=>this.makeRequest(o,t,s,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 s=[];e[t].forEach(o=>{this.relations[o]&&s.push(this._cleanCopy(this.relations[o]))}),e[t]=s}}}_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=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,t),this._insertLinks(s,o)):"id"in s&&s.fieldtype==="asset"&&this._insertAssetsRelations(s,t),r(s[o])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const s=e.link_uuids.length;let o=[];const a=50;for(let i=0;i<s;i+=a){const c=Math.min(s,i+a);o.push(e.link_uuids.slice(i,c))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(s=>{this.links[s.uuid]=k(d({},s),{_stopResolving:!0})})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const s=e.rel_uuids.length;let o=[];const a=50;for(let i=0;i<s;i+=a){const c=Math.min(s,i+a);o.push(e.rel_uuids.slice(i,c))}for(let i=0;i<o.length;i++)(await this.getStories({per_page:a,language:t.language,version:t.version,by_uuids:o[i].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r.forEach(s=>{this.relations[s.uuid]=k(d({},s),{_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 s in this.relations)this.iterateTree(this.relations[s],r);e.story?this.iterateTree(e.story,r):e.stories.forEach(s=>{this.iterateTree(s,r)})}resolveAssetsRelations(e){const{assets:t,stories:r,story:s}=e;if(r)for(const o of r)this.iterateTree(o,t);else{if(!s)return e;this.iterateTree(s,t)}}cacheResponse(e,t,r){return r===void 0&&(r=0),new Promise(async(s,o)=>{let a=m({url:e,params:t}),i=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const l=await i.get(a);if(l)return s(l)}try{let l=await this.throttle("get",e,{params:t,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,t),t.version==="published"&&e!="/cdn/spaces/me"&&i.set(a,u),u.data.cv&&(t.version=="draft"&&p[t.token]!=u.data.cv&&this.flushCache(),p[t.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(e,t,r).then(s).catch(o);o(l)}var c})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return p}cacheVersion(){return p[this.accessToken]}setCacheVersion(e){this.accessToken&&(p[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 F=(n={})=>{const{apiOptions:e}=n;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 J(e)}};var K=n=>{if(typeof n!="object"||typeof n._editable>"u")return{};const e=JSON.parse(n._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let b;const j="https://app.storyblok.com/f/storyblok-v2-latest.js",Y=(n={})=>{const{bridge:e,accessToken:t,use:r=[],apiOptions:s={},richText:o={}}=n;s.accessToken=s.accessToken||t;const a={bridge:e,apiOptions:s};let i={};return r.forEach(c=>{i=d(d({},i),c(a))}),e!==!1&&R(j),b=new O(o.schema),o.resolver&&x(b,o.resolver),i},x=(n,e)=>{n.addNode("blok",t=>{let r="";return t.attrs.body.forEach(s=>{r+=e(s.component,s)}),{html:r}})},G=(n,e,t)=>{let r=t||b;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return n===""?"":n?(e&&(r=new O(e.schema),e.resolver&&x(r,e.resolver)),r.render(n)):(console.warn(`${n} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
1
|
+
(function(i,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("axios")):typeof define=="function"&&define.amd?define(["exports","axios"],c):(i=typeof globalThis<"u"?globalThis:i||self,c(i.storyblokAstro={}))})(this,function(i){"use strict";function c(r,e,t){const o="virtual:storyblok-init",n="\0"+o;return{name:"vite-plugin-storyblok-init",async resolveId(s){if(s===o)return n},async load(s){if(s===n)return`
|
|
2
|
+
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
3
|
+
const { storyblokApi } = storyblokInit({
|
|
4
|
+
accessToken: "${r}",
|
|
5
|
+
use: ${e?"[]":"[apiPlugin]"},
|
|
6
|
+
apiOptions: ${JSON.stringify(t)},
|
|
7
|
+
});
|
|
8
|
+
export const storyblokApiInstance = storyblokApi;
|
|
9
|
+
`}}}const T=/[\p{Lu}]/u,I=/[\p{Ll}]/u,d=/^[\p{Lu}](?![\p{Lu}])/gu,f=/([\p{Alpha}\p{N}_]|$)/u,u=/[_.\- ]+/,E=new RegExp("^"+u.source),h=new RegExp(u.source+f.source,"gu"),p=new RegExp("\\d+"+f.source,"gu"),A=(r,e,t)=>{let o=!1,n=!1,s=!1;for(let l=0;l<r.length;l++){const a=r[l];o&&T.test(a)?(r=r.slice(0,l)+"-"+r.slice(l),o=!1,s=n,n=!0,l++):n&&s&&I.test(a)?(r=r.slice(0,l-1)+"-"+r.slice(l-1),s=n,n=!1,o=!0):(o=e(a)===a&&t(a)!==a,s=n,n=t(a)===a&&e(a)!==a)}return r},S=(r,e)=>(d.lastIndex=0,r.replace(d,t=>e(t))),w=(r,e)=>(h.lastIndex=0,p.lastIndex=0,r.replace(h,(t,o)=>e(o)).replace(p,t=>e(t)));function g(r,e){if(!(typeof r=="string"||Array.isArray(r)))throw new TypeError("Expected the input to be `string | string[]`");if(e={pascalCase:!1,preserveConsecutiveUppercase:!1,...e},Array.isArray(r)?r=r.map(s=>s.trim()).filter(s=>s.length).join("-"):r=r.trim(),r.length===0)return"";const t=e.locale===!1?s=>s.toLowerCase():s=>s.toLocaleLowerCase(e.locale),o=e.locale===!1?s=>s.toUpperCase():s=>s.toLocaleUpperCase(e.locale);return r.length===1?u.test(r)?"":e.pascalCase?o(r):t(r):(r!==t(r)&&(r=A(r,t,o)),r=r.replace(E,""),r=e.preserveConsecutiveUppercase?S(r,t):t(r),e.pascalCase&&(r=o(r.charAt(0))+r.slice(1)),w(r,o))}function _(r){const e="virtual:storyblok-components",t="\0"+e;return{name:"vite-plugin-storyblok-components",async resolveId(o){if(o===e)return t},async load(o){if(o===t){const n=[];for await(const[s,l]of Object.entries(r)){const{id:a}=await this.resolve("/src/"+l+".astro");n.push(`import ${g(s)} from "${a}"`)}return`${n.join(";")};export default {${Object.keys(r).map(s=>g(s)).join(",")}}`}}}}var R=Object.defineProperty,y=Object.getOwnPropertySymbols,C=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable,b=(r,e,t)=>e in r?R(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,x=(r,e)=>{for(var t in e||(e={}))C.call(e,t)&&b(r,t,e[t]);if(y)for(var t of y(e))$.call(e,t)&&b(r,t,e[t]);return r};let k=!1;const m=[],O=r=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=n=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}k?n():m.push(n)},document.getElementById("storyblok-javascript-bridge")))return;const o=document.createElement("script");o.async=!0,o.src=r,o.id="storyblok-javascript-bridge",o.onerror=n=>t(n),o.onload=n=>{m.forEach(s=>s()),k=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(o)}),P=function(r,e){if(!r)return null;let t={};for(let o in r){let n=r[o];e.indexOf(o)>-1&&n!==null&&(t[o]=n)}return t},N=r=>r==="email";var v={nodes:{horizontal_rule(){return{singleTag:"hr"}},blockquote(){return{tag:"blockquote"}},bullet_list(){return{tag:"ul"}},code_block(r){return{tag:["pre",{tag:"code",attrs:r.attrs}]}},hard_break(){return{singleTag:"br"}},heading(r){return{tag:`h${r.attrs.level}`}},image(r){return{singleTag:[{tag:"img",attrs:P(r.attrs,["src","alt","title"])}]}},list_item(){return{tag:"li"}},ordered_list(){return{tag:"ol"}},paragraph(){return{tag:"p"}}},marks:{bold(){return{tag:"b"}},strike(){return{tag:"strike"}},underline(){return{tag:"u"}},strong(){return{tag:"strong"}},code(){return{tag:"code"}},italic(){return{tag:"i"}},link(r){const e=x({},r.attrs),{linktype:t="url"}=r.attrs;return N(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},styled(r){return{tag:[{tag:"span",attrs:r.attrs}]}}}};const j=function(r){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,o=RegExp(t.source);return r&&o.test(r)?r.replace(t,n=>e[n]):r};class L{constructor(e){e||(e=v),this.marks=e.marks||[],this.nodes=e.nodes||[]}addNode(e,t){this.nodes[e]=t}addMark(e,t){this.marks[e]=t}render(e={}){if(e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(o=>{t+=this.renderNode(o)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){let t=[];e.marks&&e.marks.forEach(n=>{const s=this.getMatchingMark(n);s&&t.push(this.renderOpeningTag(s.tag))});const o=this.getMatchingNode(e);return o&&o.tag&&t.push(this.renderOpeningTag(o.tag)),e.content?e.content.forEach(n=>{t.push(this.renderNode(n))}):e.text?t.push(j(e.text)):o&&o.singleTag?t.push(this.renderTag(o.singleTag," /")):o&&o.html&&t.push(o.html),o&&o.tag&&t.push(this.renderClosingTag(o.tag)),e.marks&&e.marks.slice(0).reverse().forEach(n=>{const s=this.getMatchingMark(n);s&&t.push(this.renderClosingTag(s.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(n=>{if(n.constructor===String)return`<${n}${t}>`;{let s=`<${n.tag}`;if(n.attrs)for(let l in n.attrs){let a=n.attrs[l];a!==null&&(s+=` ${l}="${a}"`)}return`${s}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(o=>o.constructor===String?`</${o}>`:`</${o.tag}>`).join("")}getMatchingNode(e){if(typeof this.nodes[e.type]=="function")return this.nodes[e.type](e)}getMatchingMark(e){if(typeof this.marks[e.type]=="function")return this.marks[e.type](e)}}var M=r=>{if(typeof r!="object"||typeof r._editable>"u")return{};const e=JSON.parse(r._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let B;const U="https://app.storyblok.com/f/storyblok-v2-latest.js",D=(r,e)=>{r.addNode("blok",t=>{let o="";return t.attrs.body.forEach(n=>{o+=e(n.component,n)}),{html:o}})},z=(r,e,t)=>{let o=t||B;if(!o){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return r===""?"":r?(e&&(o=new L(e.schema),e.resolver&&D(o,e.resolver)),o.render(r)):(console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
6
10
|
|
|
7
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")},H=()=>O(U);function q(){return globalThis.storyblokApiInstance||console.error("storyblokApiInstance has not been initialized correctly"),storyblokApiInstance}function F(r,e){const t=globalThis.storyblokApiInstance.richTextResolver;if(!t){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return z(r,e,t)}function V(r){return{name:"@storyblok/astro",hooks:{"astro:config:setup":({injectScript:e,updateConfig:t})=>{var n;t({vite:{plugins:[c(r.accessToken,r.useCustomApi,r.apiOptions),_(r.components)]}}),e("page-ssr",`
|
|
12
|
+
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
13
|
+
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
14
|
+
`),((n=r.bridge)!=null?n:!0)&&e("page",`
|
|
15
|
+
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
16
|
+
loadStoryblokBridge().then(() => {
|
|
17
|
+
const { StoryblokBridge, location } = window;
|
|
18
|
+
const storyblokInstance = new StoryblokBridge();
|
|
12
19
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
storyblokInstance.on(["published", "change"], (event) => {
|
|
21
|
+
if (!event.slugChanged) {
|
|
22
|
+
location.reload(true);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
`)}}}}i.RichTextSchema=v,i.default=V,i.loadStoryblokBridge=H,i.renderRichText=F,i.storyblokEditable=M,i.useStoryblokApi=q,Object.defineProperties(i,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/storyblok-astro.mjs
CHANGED
|
@@ -1,57 +1,99 @@
|
|
|
1
|
-
import
|
|
2
|
-
function
|
|
3
|
-
const
|
|
1
|
+
import "axios";
|
|
2
|
+
function k(r, e, t) {
|
|
3
|
+
const o = "virtual:storyblok-init", n = "\0" + o;
|
|
4
4
|
return {
|
|
5
|
-
name: "vite-plugin-storyblok",
|
|
6
|
-
async resolveId(
|
|
7
|
-
if (
|
|
8
|
-
return
|
|
5
|
+
name: "vite-plugin-storyblok-init",
|
|
6
|
+
async resolveId(s) {
|
|
7
|
+
if (s === o)
|
|
8
|
+
return n;
|
|
9
9
|
},
|
|
10
|
-
async load(
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
|
|
10
|
+
async load(s) {
|
|
11
|
+
if (s === n)
|
|
12
|
+
return `
|
|
13
|
+
import { storyblokInit, apiPlugin } from "@storyblok/js";
|
|
14
|
+
const { storyblokApi } = storyblokInit({
|
|
15
|
+
accessToken: "${r}",
|
|
16
|
+
use: ${e ? "[]" : "[apiPlugin]"},
|
|
17
|
+
apiOptions: ${JSON.stringify(t)},
|
|
18
|
+
});
|
|
19
|
+
export const storyblokApiInstance = storyblokApi;
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const m = /[\p{Lu}]/u, v = /[\p{Ll}]/u, c = /^[\p{Lu}](?![\p{Lu}])/gu, b = /([\p{Alpha}\p{N}_]|$)/u, i = /[_.\- ]+/, T = new RegExp("^" + i.source), u = new RegExp(i.source + b.source, "gu"), d = new RegExp("\\d+" + b.source, "gu"), I = (r, e, t) => {
|
|
25
|
+
let o = !1, n = !1, s = !1;
|
|
26
|
+
for (let l = 0; l < r.length; l++) {
|
|
27
|
+
const a = r[l];
|
|
28
|
+
o && m.test(a) ? (r = r.slice(0, l) + "-" + r.slice(l), o = !1, s = n, n = !0, l++) : n && s && v.test(a) ? (r = r.slice(0, l - 1) + "-" + r.slice(l - 1), s = n, n = !1, o = !0) : (o = e(a) === a && t(a) !== a, s = n, n = t(a) === a && e(a) !== a);
|
|
29
|
+
}
|
|
30
|
+
return r;
|
|
31
|
+
}, E = (r, e) => (c.lastIndex = 0, r.replace(c, (t) => e(t))), A = (r, e) => (u.lastIndex = 0, d.lastIndex = 0, r.replace(u, (t, o) => e(o)).replace(d, (t) => e(t)));
|
|
32
|
+
function f(r, e) {
|
|
33
|
+
if (!(typeof r == "string" || Array.isArray(r)))
|
|
34
|
+
throw new TypeError("Expected the input to be `string | string[]`");
|
|
35
|
+
if (e = {
|
|
36
|
+
pascalCase: !1,
|
|
37
|
+
preserveConsecutiveUppercase: !1,
|
|
38
|
+
...e
|
|
39
|
+
}, Array.isArray(r) ? r = r.map((s) => s.trim()).filter((s) => s.length).join("-") : r = r.trim(), r.length === 0)
|
|
40
|
+
return "";
|
|
41
|
+
const t = e.locale === !1 ? (s) => s.toLowerCase() : (s) => s.toLocaleLowerCase(e.locale), o = e.locale === !1 ? (s) => s.toUpperCase() : (s) => s.toLocaleUpperCase(e.locale);
|
|
42
|
+
return r.length === 1 ? i.test(r) ? "" : e.pascalCase ? o(r) : t(r) : (r !== t(r) && (r = I(r, t, o)), r = r.replace(T, ""), r = e.preserveConsecutiveUppercase ? E(r, t) : t(r), e.pascalCase && (r = o(r.charAt(0)) + r.slice(1)), A(r, o));
|
|
43
|
+
}
|
|
44
|
+
function w(r) {
|
|
45
|
+
const e = "virtual:storyblok-components", t = "\0" + e;
|
|
46
|
+
return {
|
|
47
|
+
name: "vite-plugin-storyblok-components",
|
|
48
|
+
async resolveId(o) {
|
|
49
|
+
if (o === e)
|
|
50
|
+
return t;
|
|
51
|
+
},
|
|
52
|
+
async load(o) {
|
|
53
|
+
if (o === t) {
|
|
54
|
+
const n = [];
|
|
55
|
+
for await (const [s, l] of Object.entries(r)) {
|
|
56
|
+
const { id: a } = await this.resolve("/src/" + l + ".astro");
|
|
57
|
+
n.push(`import ${f(s)} from "${a}"`);
|
|
16
58
|
}
|
|
17
|
-
return `${
|
|
59
|
+
return `${n.join(";")};export default {${Object.keys(r).map((s) => f(s)).join(",")}}`;
|
|
18
60
|
}
|
|
19
61
|
}
|
|
20
62
|
};
|
|
21
63
|
}
|
|
22
|
-
var
|
|
23
|
-
for (var
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
for (var
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
}
|
|
30
|
-
let
|
|
31
|
-
const
|
|
32
|
-
if (typeof window > "u" || (window.storyblokRegisterEvent = (
|
|
64
|
+
var S = Object.defineProperty, h = Object.getOwnPropertySymbols, R = Object.prototype.hasOwnProperty, _ = Object.prototype.propertyIsEnumerable, p = (r, e, t) => e in r ? S(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, C = (r, e) => {
|
|
65
|
+
for (var t in e || (e = {}))
|
|
66
|
+
R.call(e, t) && p(r, t, e[t]);
|
|
67
|
+
if (h)
|
|
68
|
+
for (var t of h(e))
|
|
69
|
+
_.call(e, t) && p(r, t, e[t]);
|
|
70
|
+
return r;
|
|
71
|
+
};
|
|
72
|
+
let g = !1;
|
|
73
|
+
const y = [], x = (r) => new Promise((e, t) => {
|
|
74
|
+
if (typeof window > "u" || (window.storyblokRegisterEvent = (n) => {
|
|
33
75
|
if (window.location === window.parent.location) {
|
|
34
76
|
console.warn("You are not in Draft Mode or in the Visual Editor.");
|
|
35
77
|
return;
|
|
36
78
|
}
|
|
37
|
-
|
|
79
|
+
g ? n() : y.push(n);
|
|
38
80
|
}, document.getElementById("storyblok-javascript-bridge")))
|
|
39
81
|
return;
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}, document.getElementsByTagName("head")[0].appendChild(
|
|
44
|
-
}),
|
|
45
|
-
if (!
|
|
82
|
+
const o = document.createElement("script");
|
|
83
|
+
o.async = !0, o.src = r, o.id = "storyblok-javascript-bridge", o.onerror = (n) => t(n), o.onload = (n) => {
|
|
84
|
+
y.forEach((s) => s()), g = !0, e(n);
|
|
85
|
+
}, document.getElementsByTagName("head")[0].appendChild(o);
|
|
86
|
+
}), $ = function(r, e) {
|
|
87
|
+
if (!r)
|
|
46
88
|
return null;
|
|
47
|
-
let
|
|
48
|
-
for (let
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
return
|
|
53
|
-
},
|
|
54
|
-
var
|
|
89
|
+
let t = {};
|
|
90
|
+
for (let o in r) {
|
|
91
|
+
let n = r[o];
|
|
92
|
+
e.indexOf(o) > -1 && n !== null && (t[o] = n);
|
|
93
|
+
}
|
|
94
|
+
return t;
|
|
95
|
+
}, O = (r) => r === "email";
|
|
96
|
+
var N = {
|
|
55
97
|
nodes: {
|
|
56
98
|
horizontal_rule() {
|
|
57
99
|
return {
|
|
@@ -68,13 +110,13 @@ var z = {
|
|
|
68
110
|
tag: "ul"
|
|
69
111
|
};
|
|
70
112
|
},
|
|
71
|
-
code_block(
|
|
113
|
+
code_block(r) {
|
|
72
114
|
return {
|
|
73
115
|
tag: [
|
|
74
116
|
"pre",
|
|
75
117
|
{
|
|
76
118
|
tag: "code",
|
|
77
|
-
attrs:
|
|
119
|
+
attrs: r.attrs
|
|
78
120
|
}
|
|
79
121
|
]
|
|
80
122
|
};
|
|
@@ -84,17 +126,17 @@ var z = {
|
|
|
84
126
|
singleTag: "br"
|
|
85
127
|
};
|
|
86
128
|
},
|
|
87
|
-
heading(
|
|
129
|
+
heading(r) {
|
|
88
130
|
return {
|
|
89
|
-
tag: `h${
|
|
131
|
+
tag: `h${r.attrs.level}`
|
|
90
132
|
};
|
|
91
133
|
},
|
|
92
|
-
image(
|
|
134
|
+
image(r) {
|
|
93
135
|
return {
|
|
94
136
|
singleTag: [
|
|
95
137
|
{
|
|
96
138
|
tag: "img",
|
|
97
|
-
attrs:
|
|
139
|
+
attrs: $(r.attrs, ["src", "alt", "title"])
|
|
98
140
|
}
|
|
99
141
|
]
|
|
100
142
|
};
|
|
@@ -146,547 +188,192 @@ var z = {
|
|
|
146
188
|
tag: "i"
|
|
147
189
|
};
|
|
148
190
|
},
|
|
149
|
-
link(
|
|
150
|
-
const
|
|
151
|
-
return
|
|
191
|
+
link(r) {
|
|
192
|
+
const e = C({}, r.attrs), { linktype: t = "url" } = r.attrs;
|
|
193
|
+
return O(t) && (e.href = `mailto:${e.href}`), e.anchor && (e.href = `${e.href}#${e.anchor}`, delete e.anchor), {
|
|
152
194
|
tag: [
|
|
153
195
|
{
|
|
154
196
|
tag: "a",
|
|
155
|
-
attrs:
|
|
197
|
+
attrs: e
|
|
156
198
|
}
|
|
157
199
|
]
|
|
158
200
|
};
|
|
159
201
|
},
|
|
160
|
-
styled(
|
|
202
|
+
styled(r) {
|
|
161
203
|
return {
|
|
162
204
|
tag: [
|
|
163
205
|
{
|
|
164
206
|
tag: "span",
|
|
165
|
-
attrs:
|
|
207
|
+
attrs: r.attrs
|
|
166
208
|
}
|
|
167
209
|
]
|
|
168
210
|
};
|
|
169
211
|
}
|
|
170
212
|
}
|
|
171
213
|
};
|
|
172
|
-
const
|
|
173
|
-
const
|
|
214
|
+
const P = function(r) {
|
|
215
|
+
const e = {
|
|
174
216
|
"&": "&",
|
|
175
217
|
"<": "<",
|
|
176
218
|
">": ">",
|
|
177
219
|
'"': """,
|
|
178
220
|
"'": "'"
|
|
179
|
-
},
|
|
180
|
-
return
|
|
221
|
+
}, t = /[&<>"']/g, o = RegExp(t.source);
|
|
222
|
+
return r && o.test(r) ? r.replace(t, (n) => e[n]) : r;
|
|
181
223
|
};
|
|
182
|
-
class
|
|
183
|
-
constructor(
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
addNode(
|
|
187
|
-
this.nodes[
|
|
188
|
-
}
|
|
189
|
-
addMark(
|
|
190
|
-
this.marks[
|
|
191
|
-
}
|
|
192
|
-
render(
|
|
193
|
-
if (
|
|
194
|
-
let
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
}),
|
|
224
|
+
class L {
|
|
225
|
+
constructor(e) {
|
|
226
|
+
e || (e = N), this.marks = e.marks || [], this.nodes = e.nodes || [];
|
|
227
|
+
}
|
|
228
|
+
addNode(e, t) {
|
|
229
|
+
this.nodes[e] = t;
|
|
230
|
+
}
|
|
231
|
+
addMark(e, t) {
|
|
232
|
+
this.marks[e] = t;
|
|
233
|
+
}
|
|
234
|
+
render(e = {}) {
|
|
235
|
+
if (e.content && Array.isArray(e.content)) {
|
|
236
|
+
let t = "";
|
|
237
|
+
return e.content.forEach((o) => {
|
|
238
|
+
t += this.renderNode(o);
|
|
239
|
+
}), t;
|
|
198
240
|
}
|
|
199
241
|
return console.warn("The render method must receive an object with a content field, which is an array"), "";
|
|
200
242
|
}
|
|
201
|
-
renderNode(
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
243
|
+
renderNode(e) {
|
|
244
|
+
let t = [];
|
|
245
|
+
e.marks && e.marks.forEach((n) => {
|
|
246
|
+
const s = this.getMatchingMark(n);
|
|
247
|
+
s && t.push(this.renderOpeningTag(s.tag));
|
|
206
248
|
});
|
|
207
|
-
const
|
|
208
|
-
return
|
|
209
|
-
|
|
210
|
-
}) :
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
}),
|
|
214
|
-
}
|
|
215
|
-
renderTag(
|
|
216
|
-
return
|
|
217
|
-
if (
|
|
218
|
-
return `<${
|
|
249
|
+
const o = this.getMatchingNode(e);
|
|
250
|
+
return o && o.tag && t.push(this.renderOpeningTag(o.tag)), e.content ? e.content.forEach((n) => {
|
|
251
|
+
t.push(this.renderNode(n));
|
|
252
|
+
}) : e.text ? t.push(P(e.text)) : o && o.singleTag ? t.push(this.renderTag(o.singleTag, " /")) : o && o.html && t.push(o.html), o && o.tag && t.push(this.renderClosingTag(o.tag)), e.marks && e.marks.slice(0).reverse().forEach((n) => {
|
|
253
|
+
const s = this.getMatchingMark(n);
|
|
254
|
+
s && t.push(this.renderClosingTag(s.tag));
|
|
255
|
+
}), t.join("");
|
|
256
|
+
}
|
|
257
|
+
renderTag(e, t) {
|
|
258
|
+
return e.constructor === String ? `<${e}${t}>` : e.map((n) => {
|
|
259
|
+
if (n.constructor === String)
|
|
260
|
+
return `<${n}${t}>`;
|
|
219
261
|
{
|
|
220
|
-
let
|
|
221
|
-
if (
|
|
222
|
-
for (let
|
|
223
|
-
let
|
|
224
|
-
|
|
262
|
+
let s = `<${n.tag}`;
|
|
263
|
+
if (n.attrs)
|
|
264
|
+
for (let l in n.attrs) {
|
|
265
|
+
let a = n.attrs[l];
|
|
266
|
+
a !== null && (s += ` ${l}="${a}"`);
|
|
225
267
|
}
|
|
226
|
-
return `${
|
|
268
|
+
return `${s}${t}>`;
|
|
227
269
|
}
|
|
228
270
|
}).join("");
|
|
229
271
|
}
|
|
230
|
-
renderOpeningTag(
|
|
231
|
-
return this.renderTag(
|
|
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 _(n) {
|
|
251
|
-
return typeof n == "number" && n == n && n !== 1 / 0 && n !== -1 / 0;
|
|
252
|
-
}
|
|
253
|
-
function $(n, t, e) {
|
|
254
|
-
if (!_(t))
|
|
255
|
-
throw new TypeError("Expected `limit` to be a finite number");
|
|
256
|
-
if (!_(e))
|
|
257
|
-
throw new TypeError("Expected `interval` to be a finite number");
|
|
258
|
-
var r = [], s = [], o = 0, a = function() {
|
|
259
|
-
o++;
|
|
260
|
-
var c = setTimeout(function() {
|
|
261
|
-
o--, r.length > 0 && a(), 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
|
-
}, i = 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 && a();
|
|
272
|
-
});
|
|
273
|
-
};
|
|
274
|
-
return i.abort = function() {
|
|
275
|
-
s.forEach(clearTimeout), s = [], r.forEach(function(c) {
|
|
276
|
-
c.reject(new throttle.AbortError());
|
|
277
|
-
}), r.length = 0;
|
|
278
|
-
}, i;
|
|
279
|
-
}
|
|
280
|
-
$.AbortError = function() {
|
|
281
|
-
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
282
|
-
};
|
|
283
|
-
const L = 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 U = { 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: L(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 H {
|
|
298
|
-
constructor(t) {
|
|
299
|
-
t || (t = U), 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 = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }, a = /[&<>"']/g, i = RegExp(a.source);
|
|
327
|
-
return s && i.test(s) ? s.replace(a, (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 a = r.attrs[o];
|
|
342
|
-
a !== null && (s += ` ${o}="${a}"`);
|
|
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 V = (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], a = e ? "" : encodeURIComponent(s);
|
|
372
|
-
let i;
|
|
373
|
-
i = typeof o == "object" ? y(o, t ? t + encodeURIComponent("[" + a + "]") : a, Array.isArray(o)) : (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(o), r.push(i);
|
|
374
|
-
}
|
|
375
|
-
return r.join("&");
|
|
376
|
-
};
|
|
377
|
-
let g = {}, d = {};
|
|
378
|
-
class D {
|
|
379
|
-
constructor(t, e) {
|
|
380
|
-
if (!e) {
|
|
381
|
-
let o = t.region ? `-${t.region}` : "", a = t.https === !1 ? "http" : "https";
|
|
382
|
-
e = t.oauthToken === void 0 ? `${a}://api${o}.storyblok.com/v2` : `${a}://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 H(t.richTextSchema), typeof t.componentResolver == "function" && this.setComponentResolver(t.componentResolver), this.maxRetries = t.maxRetries || 5, this.throttle = $(this.throttledRequest, s, 1e3), this.accessToken = t.accessToken, this.relations = {}, this.links = {}, this.cache = t.cache || { clear: "manual" }, this.client = S.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, ((a = {}, i = 25, c = 1) => f(u({}, a), { per_page: i, 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}`, a = o.split("/");
|
|
412
|
-
r = r || a[a.length - 1];
|
|
413
|
-
const i = await this.makeRequest(o, e, s, 1), c = Math.ceil(i.total / s);
|
|
414
|
-
return ((l = [], h) => l.map(h).reduce((p, x) => [...p, ...x], []))([i, ...await (async (l = [], h) => Promise.all(l.map(h)))(V(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);
|
|
272
|
+
renderOpeningTag(e) {
|
|
273
|
+
return this.renderTag(e, "");
|
|
419
274
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
return this.throttle("put", r, e);
|
|
275
|
+
renderClosingTag(e) {
|
|
276
|
+
return e.constructor === String ? `</${e}>` : e.slice(0).reverse().map((o) => o.constructor === String ? `</${o}>` : `</${o.tag}>`).join("");
|
|
423
277
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
278
|
+
getMatchingNode(e) {
|
|
279
|
+
if (typeof this.nodes[e.type] == "function")
|
|
280
|
+
return this.nodes[e.type](e);
|
|
427
281
|
}
|
|
428
|
-
|
|
429
|
-
|
|
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 a = 50;
|
|
486
|
-
for (let i = 0; i < s; i += a) {
|
|
487
|
-
const c = Math.min(s, i + a);
|
|
488
|
-
o.push(t.link_uuids.slice(i, c));
|
|
489
|
-
}
|
|
490
|
-
for (let i = 0; i < o.length; i++)
|
|
491
|
-
(await this.getStories({ per_page: a, language: e.language, version: e.version, by_uuids: o[i].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 a = 50;
|
|
506
|
-
for (let i = 0; i < s; i += a) {
|
|
507
|
-
const c = Math.min(s, i + a);
|
|
508
|
-
o.push(t.rel_uuids.slice(i, c));
|
|
509
|
-
}
|
|
510
|
-
for (let i = 0; i < o.length; i++)
|
|
511
|
-
(await this.getStories({ per_page: a, language: e.language, version: e.version, by_uuids: o[i].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 a = y({ url: t, params: e }), i = 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 i.get(a);
|
|
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" && i.set(a, 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;
|
|
282
|
+
getMatchingMark(e) {
|
|
283
|
+
if (typeof this.marks[e.type] == "function")
|
|
284
|
+
return this.marks[e.type](e);
|
|
586
285
|
}
|
|
587
286
|
}
|
|
588
|
-
|
|
589
|
-
|
|
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 D(t) };
|
|
595
|
-
};
|
|
596
|
-
var Q = (n) => {
|
|
597
|
-
if (typeof n != "object" || typeof n._editable > "u")
|
|
287
|
+
var z = (r) => {
|
|
288
|
+
if (typeof r != "object" || typeof r._editable > "u")
|
|
598
289
|
return {};
|
|
599
|
-
const
|
|
290
|
+
const e = JSON.parse(r._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, ""));
|
|
600
291
|
return {
|
|
601
|
-
"data-blok-c": JSON.stringify(
|
|
602
|
-
"data-blok-uid":
|
|
292
|
+
"data-blok-c": JSON.stringify(e),
|
|
293
|
+
"data-blok-uid": e.id + "-" + e.uid
|
|
603
294
|
};
|
|
604
295
|
};
|
|
605
|
-
let
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
apiOptions: s = {},
|
|
612
|
-
richText: o = {}
|
|
613
|
-
} = n;
|
|
614
|
-
s.accessToken = s.accessToken || e;
|
|
615
|
-
const a = { bridge: t, apiOptions: s };
|
|
616
|
-
let i = {};
|
|
617
|
-
return r.forEach((c) => {
|
|
618
|
-
i = u(u({}, i), c(a));
|
|
619
|
-
}), t !== !1 && w(O), m = new R(o.schema), o.resolver && E(m, o.resolver), i;
|
|
620
|
-
}, E = (n, t) => {
|
|
621
|
-
n.addNode("blok", (e) => {
|
|
622
|
-
let r = "";
|
|
623
|
-
return e.attrs.body.forEach((s) => {
|
|
624
|
-
r += t(s.component, s);
|
|
296
|
+
let j;
|
|
297
|
+
const M = "https://app.storyblok.com/f/storyblok-v2-latest.js", U = (r, e) => {
|
|
298
|
+
r.addNode("blok", (t) => {
|
|
299
|
+
let o = "";
|
|
300
|
+
return t.attrs.body.forEach((n) => {
|
|
301
|
+
o += e(n.component, n);
|
|
625
302
|
}), {
|
|
626
|
-
html:
|
|
303
|
+
html: o
|
|
627
304
|
};
|
|
628
305
|
});
|
|
629
|
-
},
|
|
630
|
-
let
|
|
631
|
-
if (!
|
|
306
|
+
}, B = (r, e, t) => {
|
|
307
|
+
let o = t || j;
|
|
308
|
+
if (!o) {
|
|
632
309
|
console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
|
|
633
310
|
return;
|
|
634
311
|
}
|
|
635
|
-
return
|
|
312
|
+
return r === "" ? "" : r ? (e && (o = new L(e.schema), e.resolver && U(o, e.resolver)), o.render(r)) : (console.warn(`${r} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
636
313
|
|
|
637
314
|
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`), "");
|
|
638
|
-
},
|
|
639
|
-
function
|
|
640
|
-
|
|
641
|
-
accessToken: n,
|
|
642
|
-
use: t || [J],
|
|
643
|
-
apiOptions: { ...e }
|
|
644
|
-
});
|
|
645
|
-
globalThis.storyblokApiInstance = r;
|
|
315
|
+
}, H = () => x(M);
|
|
316
|
+
function F() {
|
|
317
|
+
return globalThis.storyblokApiInstance || console.error("storyblokApiInstance has not been initialized correctly"), storyblokApiInstance;
|
|
646
318
|
}
|
|
647
|
-
function
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
console.error("Please initialize the Storyblok SDK before calling the renderRichText function");
|
|
319
|
+
function V(r, e) {
|
|
320
|
+
const t = globalThis.storyblokApiInstance.richTextResolver;
|
|
321
|
+
if (!t) {
|
|
322
|
+
console.error(
|
|
323
|
+
"Please initialize the Storyblok SDK before calling the renderRichText function"
|
|
324
|
+
);
|
|
654
325
|
return;
|
|
655
326
|
}
|
|
656
|
-
return
|
|
327
|
+
return B(r, e, t);
|
|
657
328
|
}
|
|
658
|
-
function
|
|
329
|
+
function q(r) {
|
|
659
330
|
return {
|
|
660
331
|
name: "@storyblok/astro",
|
|
661
332
|
hooks: {
|
|
662
|
-
"astro:config:setup": ({ injectScript:
|
|
663
|
-
var
|
|
664
|
-
|
|
333
|
+
"astro:config:setup": ({ injectScript: e, updateConfig: t }) => {
|
|
334
|
+
var n;
|
|
335
|
+
t({
|
|
665
336
|
vite: {
|
|
666
|
-
plugins: [
|
|
337
|
+
plugins: [
|
|
338
|
+
k(
|
|
339
|
+
r.accessToken,
|
|
340
|
+
r.useCustomApi,
|
|
341
|
+
r.apiOptions
|
|
342
|
+
),
|
|
343
|
+
w(r.components)
|
|
344
|
+
]
|
|
667
345
|
}
|
|
668
|
-
}),
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
346
|
+
}), e(
|
|
347
|
+
"page-ssr",
|
|
348
|
+
`
|
|
349
|
+
import { storyblokApiInstance } from "virtual:storyblok-init";
|
|
350
|
+
globalThis.storyblokApiInstance = storyblokApiInstance;
|
|
351
|
+
`
|
|
352
|
+
), ((n = r.bridge) != null ? n : !0) && e(
|
|
353
|
+
"page",
|
|
354
|
+
`
|
|
355
|
+
import { loadStoryblokBridge } from "@storyblok/astro";
|
|
356
|
+
loadStoryblokBridge().then(() => {
|
|
357
|
+
const { StoryblokBridge, location } = window;
|
|
358
|
+
const storyblokInstance = new StoryblokBridge();
|
|
673
359
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
360
|
+
storyblokInstance.on(["published", "change"], (event) => {
|
|
361
|
+
if (!event.slugChanged) {
|
|
362
|
+
location.reload(true);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
`
|
|
367
|
+
);
|
|
681
368
|
}
|
|
682
369
|
}
|
|
683
370
|
};
|
|
684
371
|
}
|
|
685
372
|
export {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
373
|
+
N as RichTextSchema,
|
|
374
|
+
q as default,
|
|
375
|
+
H as loadStoryblokBridge,
|
|
376
|
+
V as renderRichText,
|
|
377
|
+
z as storyblokEditable,
|
|
378
|
+
F as useStoryblokApi
|
|
692
379
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/astro",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "Official Astro integration for the Storyblok Headless CMS",
|
|
5
5
|
"main": "./dist/storyblok-astro.js",
|
|
6
6
|
"module": "./dist/storyblok-astro.mjs",
|
|
7
7
|
"files": [
|
|
@@ -27,16 +27,17 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@storyblok/js": "^1.8.
|
|
30
|
+
"@storyblok/js": "^1.8.6",
|
|
31
|
+
"camelcase": "^7.0.0"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@cypress/vite-dev-server": "^2.0.7",
|
|
34
35
|
"@rollup/plugin-dynamic-import-vars": "^1.4.4",
|
|
35
36
|
"axios": "^0.27.2",
|
|
36
|
-
"cypress": "^10.
|
|
37
|
+
"cypress": "^10.9.0",
|
|
37
38
|
"eslint-plugin-cypress": "^2.12.1",
|
|
38
39
|
"start-server-and-test": "^1.14.0",
|
|
39
|
-
"vite": "^3.
|
|
40
|
+
"vite": "^3.2.4"
|
|
40
41
|
},
|
|
41
42
|
"repository": {
|
|
42
43
|
"type": "git",
|
|
@@ -44,7 +45,8 @@
|
|
|
44
45
|
},
|
|
45
46
|
"keywords": [
|
|
46
47
|
"astro",
|
|
47
|
-
"storyblok"
|
|
48
|
+
"storyblok",
|
|
49
|
+
"astro-component"
|
|
48
50
|
],
|
|
49
51
|
"author": "Alexander Feiglstorfer",
|
|
50
52
|
"bugs": {
|