@storyblok/svelte 2.4.7 → 2.4.9
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 +261 -12
- package/dist/storyblok-svelte.js +3 -3
- package/dist/storyblok-svelte.mjs +170 -156
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
</a>
|
|
5
5
|
<h1 align="center"><strong>@storyblok/svelte</strong></h1>
|
|
6
6
|
<p align="center">
|
|
7
|
-
The Svelte SDK you need to interact with <a href="http://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte" target="_blank">Storyblok API</a> and enable the <a href="https://www.storyblok.com/docs/guide/essentials/visual-editor?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte" target="_blank">Real-time Visual Editing Experience</a>.
|
|
7
|
+
The Svelte SDK you need to interact with <a href="http://www.storyblok.com?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte" target="_blank">Storyblok API</a> and enable the <a href="https://www.storyblok.com/docs/guide/essentials/visual-editor?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte" target="_blank">Real-time Visual Editing Experience</a>.
|
|
8
8
|
</p>
|
|
9
9
|
<br />
|
|
10
10
|
</div>
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
<a href="https://www.npmjs.com/package/@storyblok/svelte">
|
|
14
14
|
<img src="https://img.shields.io/npm/v/@storyblok/svelte/latest.svg?style=flat-square" alt="npm package" />
|
|
15
15
|
</a>
|
|
16
|
-
<a href="https://www.npmjs.com/package/@storyblok/svelte" rel="nofollow">
|
|
17
|
-
<img src="https://img.shields.io/npm/v/@storyblok/svelte/latest.svg?style=flat-square" alt="download storyblok svelte">
|
|
18
|
-
</a>
|
|
19
16
|
</p>
|
|
20
17
|
|
|
21
18
|
<p align="center">
|
|
@@ -36,9 +33,9 @@
|
|
|
36
33
|
|
|
37
34
|
`@storyblok/svelte` helps you connect your Svelte project to Storyblok by:
|
|
38
35
|
|
|
39
|
-
- Providing the `getStoryblokApi` function to interact with the Storyblok APIs, using the [storyblok-js-client](https://github.com/storyblok/storyblok-js-client)
|
|
40
|
-
- Enabling real
|
|
41
|
-
- Providing the `StoryblokComponent
|
|
36
|
+
- Providing the `getStoryblokApi` function to interact with the Storyblok APIs, using the [storyblok-js-client](https://github.com/storyblok/storyblok-js-client);
|
|
37
|
+
- Enabling real-time editing through the [Storyblok Bridge](https://www.storyblok.com/docs/Guides/storyblok-latest-js?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte);
|
|
38
|
+
- Providing the `StoryblokComponent`, which allows you to connect your components to the [Storyblok Visual Editor](https://www.storyblok.com/docs/editor-guides/visual-editor?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte).
|
|
42
39
|
|
|
43
40
|
### Installation
|
|
44
41
|
|
|
@@ -48,7 +45,7 @@ Install `@storyblok/svelte`
|
|
|
48
45
|
npm install @storyblok/svelte
|
|
49
46
|
```
|
|
50
47
|
|
|
51
|
-
Please note that you have to use npm - unfortunately we are currently not supporting yarn or pnpm for this SDK.
|
|
48
|
+
Please note that you have to use `npm` - unfortunately, we are currently not supporting `yarn` or `pnpm` for this SDK.
|
|
52
49
|
|
|
53
50
|
Initialize the library in your application by adding the `apiPlugin` and the [access token](https://www.storyblok.com/docs/api/content-delivery/v2?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte) of your Storyblok space:
|
|
54
51
|
|
|
@@ -74,13 +71,265 @@ storyblokInit({
|
|
|
74
71
|
});
|
|
75
72
|
```
|
|
76
73
|
|
|
77
|
-
|
|
74
|
+
The best place to initialize the Stroyblok library is in the `main.ts.` or `main.js` file if you are using `svelte` or in the `load()` function in the `src/routes/+layout.js` file if you are using `SvelteKit`.
|
|
75
|
+
|
|
76
|
+
List all your components to the components object in the storyblokInit function. You can load all of them by adding them to the list.
|
|
77
|
+
|
|
78
|
+
## Getting started
|
|
79
|
+
|
|
80
|
+
### 1. Fetching Content
|
|
81
|
+
|
|
82
|
+
Use the `getStoryblokApi`()` to get your stories from the Storyblok CDN API:
|
|
83
|
+
|
|
84
|
+
```html
|
|
85
|
+
<script>
|
|
86
|
+
import { onMount } from "svelte";
|
|
87
|
+
import { getStoryblokApi } from "@storyblok/svelte";
|
|
88
|
+
onMount(async () => {
|
|
89
|
+
const storyblokApi = getStoryblokApi();
|
|
90
|
+
const { data } = await storyblokApi.get("cdn/stories/home", {
|
|
91
|
+
version: "draft",
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
</script>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
> Note: you can skip using `storyblokApi` if you prefer your own method or function to fetch your data.
|
|
98
|
+
|
|
99
|
+
### 2. Listen to Storyblok Visual Editor events
|
|
100
|
+
|
|
101
|
+
Use `useStoryBridge` to get the updated story every time a change event is triggered from the Visual Editor. You need to pass the story id as the first param, and a callback function as the second param to update the new story:
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<script>
|
|
105
|
+
import { onMount } from "svelte";
|
|
106
|
+
import { getStoryblokApi, useStoryblokBridge } from "@storyblok/svelte";
|
|
107
|
+
let story = null;
|
|
108
|
+
onMount(async () => {
|
|
109
|
+
const storyblokApi = getStoryblokApi();
|
|
110
|
+
const { data } = await storyblokApi.get("cdn/stories/home", {
|
|
111
|
+
version: "draft",
|
|
112
|
+
});
|
|
113
|
+
story = data.story;
|
|
114
|
+
useStoryblokBridge(story.id, (newStory) => (story = newStory));
|
|
115
|
+
});
|
|
116
|
+
</script>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
You can pass [Bridge options](https://www.storyblok.com/docs/Guides/storyblok-latest-js?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte) as a third parameter as well:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
useStoryblokBridge(story.id, (newStory) => (story = newStory), {
|
|
123
|
+
resolveRelations: ["Article.author"],
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 3. Link your components to Storyblok Visual Editor
|
|
128
|
+
|
|
129
|
+
To link the Storyblok components, you have to
|
|
130
|
+
|
|
131
|
+
- Load them in components when calling `storyblokInit`
|
|
132
|
+
|
|
133
|
+
- Use the `storyblokEditable` action on the root element of each component
|
|
134
|
+
|
|
135
|
+
```html
|
|
136
|
+
<div use:storyblokEditable={blok} / >
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- Use the `StoryblokComponent` to load them by passing the `blok` property
|
|
140
|
+
|
|
141
|
+
```html
|
|
142
|
+
<StoryblokComponent {blok} />
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
> 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-svelte).
|
|
146
|
+
|
|
147
|
+
### Features and API
|
|
148
|
+
|
|
149
|
+
You can **choose the features to use** when you initialize the plugin. In that way, you can improve web performance by optimizing your page load and saving some bytes.
|
|
150
|
+
|
|
151
|
+
#### Storyblok API
|
|
152
|
+
|
|
153
|
+
You can use an `apiOptions` object. This is passed down to the [storyblok-js-client config object](https://github.com/storyblok/storyblok-js-client#class-storyblok):
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
storyblokInit({
|
|
157
|
+
accessToken: "<your-token>",
|
|
158
|
+
apiOptions: {
|
|
159
|
+
//storyblok-js-client config object
|
|
160
|
+
cache: { type: "memory" },
|
|
161
|
+
},
|
|
162
|
+
use: [apiPlugin],
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
If you prefer to use your own fetch method, just remove the `apiPlugin` and `storyblok-js-client` won't be added to your application. You can find out more about our [Content Delivery API](https://www.storyblok.com/docs/api/content-delivery?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte) in the documentation.
|
|
167
|
+
|
|
168
|
+
#### Storyblok Bridge
|
|
169
|
+
|
|
170
|
+
You can conditionally load it by using the `bridge` option. Very useful if you want to disable it in production:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
storyblokInit({
|
|
174
|
+
bridge: process.env.NODE_ENV !== "production",
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Keep in mind you have still access to the raw `window.StoryblokBridge`:
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
const sbBridge = new window.StoryblokBridge(options);
|
|
182
|
+
sbBridge.on(["input", "published", "change"], (event) => {
|
|
183
|
+
// ...
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
For background information on the [Storyblok JS Bridge](https://www.storyblok.com/docs/Guides/storyblok-latest-js?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte), please check out the documentation.
|
|
188
|
+
|
|
189
|
+
### Rendering Rich Text
|
|
190
|
+
|
|
191
|
+
You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/svelte` and Svelte `{@html htmlstring}` directive.
|
|
192
|
+
|
|
193
|
+
```html
|
|
194
|
+
<script>
|
|
195
|
+
import { renderRichText } from "@storyblok/svelte";
|
|
196
|
+
export let blok;
|
|
197
|
+
$: articleHTML = renderRichText(blok.article);
|
|
198
|
+
</script>
|
|
199
|
+
|
|
200
|
+
<div class="prose">{@html articleHTML}</div>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
If you are allowing the content editors to add Blok (components like teaser, hero etc) into the rich text editor, you can also implement a specific logic for rendering correctly the components added to the rich text editor.
|
|
204
|
+
To achieve this, you have to obtain the schema definition from the RichTextSchema via cloning object. For cloning schema you can use the clone-deep library for example:
|
|
205
|
+
|
|
206
|
+
```
|
|
207
|
+
npm i clone-deep
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
You can set a **custom Schema and component resolver globally** at init time by using the `richText` init option:
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
import { RichTextSchema, storyblokInit } from "@storyblok/svelte";
|
|
214
|
+
import cloneDeep from "clone-deep";
|
|
215
|
+
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
|
|
216
|
+
// ... and edit the nodes and marks, or add your own.
|
|
217
|
+
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js
|
|
218
|
+
storyblokInit({
|
|
219
|
+
accessToken: "<your-token>",
|
|
220
|
+
richText: {
|
|
221
|
+
schema: mySchema,
|
|
222
|
+
resolver: (component, blok) => {
|
|
223
|
+
switch (component) {
|
|
224
|
+
case "my-custom-component":
|
|
225
|
+
return `<div class="my-component-class">${blok.text}</div>`;
|
|
226
|
+
default:
|
|
227
|
+
return "Resolver not defined";
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
You can also set a **custom Schema and component resolver only once** by passing the options as the second parameter to `renderRichText` function:
|
|
235
|
+
|
|
236
|
+
```js
|
|
237
|
+
<script>
|
|
238
|
+
import {
|
|
239
|
+
RichTextSchema,
|
|
240
|
+
storyblokEditable,
|
|
241
|
+
StoryblokComponent,
|
|
242
|
+
renderRichText,
|
|
243
|
+
} from "@storyblok/svelte";
|
|
244
|
+
import cloneDeep from "clone-deep";
|
|
245
|
+
const mySchema = cloneDeep(RichTextSchema);
|
|
246
|
+
export let blok;
|
|
247
|
+
$: resolvedRichText = renderRichText(blok.richText, {
|
|
248
|
+
schema: mySchema,
|
|
249
|
+
resolver: (component, blok) => {
|
|
250
|
+
switch (component) {
|
|
251
|
+
case "teaser":
|
|
252
|
+
console.log(blok); // for learning purpose
|
|
253
|
+
return `<div class="my-component-class">${blok.headline}</div>`;
|
|
254
|
+
break;
|
|
255
|
+
default:
|
|
256
|
+
return `Component ${component} not found`;
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
</script>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Enabling SSL
|
|
264
|
+
|
|
265
|
+
For security reasons the Storyblok UI loads and embeds the frontend project that you are building with Svelte, via HTTPS protocol into Storyblok Visual Editor.
|
|
266
|
+
|
|
267
|
+
To enable the HTTPS protocol when you run `npm run dev`, you can install the `basicSsl` Vite plugin.
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
npm i @vitejs/plugin-basic-ssl
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
and, in the `vite.config.js` file be sure to load correctly the plugin, importing the plugin:
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
import basicSsl from '@vitejs/plugin-basic-ssl'
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
and then, activating the plugin in `plugins` configuration array:
|
|
280
|
+
|
|
281
|
+
```
|
|
282
|
+
plugins: [sveltekit(), basicSsl()],
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Compatibility
|
|
286
|
+
|
|
287
|
+
This plugin is for Svelte. Thus, it supports the [same browsers as Svelte 3](https://github.com/sveltejs/svelte/issues/558). In short: all modern browsers and IE10+.
|
|
288
|
+
|
|
289
|
+
## Troubleshooting
|
|
290
|
+
|
|
291
|
+
### Working with a Component Library
|
|
292
|
+
|
|
293
|
+
When working with a component library, create an alias pointing '@storyblok/svelte' to './node_modules/@storyblok/svelte'. This will ensure the imported module will use the local version of Storyblok SDK. In your `vite.config.js`, include:
|
|
294
|
+
|
|
295
|
+
```js
|
|
296
|
+
import { sveltekit } from "@sveltejs/kit/vite";
|
|
297
|
+
import basicSsl from "@vitejs/plugin-basic-ssl";
|
|
298
|
+
import path from "path";
|
|
299
|
+
import { fileURLToPath } from "url";
|
|
300
|
+
|
|
301
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
302
|
+
|
|
303
|
+
const __dirname = path.dirname(__filename);
|
|
304
|
+
|
|
305
|
+
/** @type {import('vite').UserConfig} */
|
|
306
|
+
const config = {
|
|
307
|
+
plugins: [sveltekit(), basicSsl()],
|
|
308
|
+
server: {
|
|
309
|
+
https: true,
|
|
310
|
+
},
|
|
311
|
+
resolve: {
|
|
312
|
+
alias: {
|
|
313
|
+
"@storyblok/svelte": path.resolve(
|
|
314
|
+
__dirname,
|
|
315
|
+
"./node_modules/@storyblok/svelte"
|
|
316
|
+
),
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export default config;
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Another option might also be using npm / yarn workspaces.
|
|
325
|
+
|
|
326
|
+
## A note about Fetch API
|
|
78
327
|
|
|
79
328
|
⚠️ This SDK uses the Fetch API under the hood. If your environment doesn't support it, you need to install a polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch). More info on [storyblok-js-client docs](https://github.com/storyblok/storyblok-js-client#fetch-use-polyfill-if-needed---version-5).
|
|
80
329
|
|
|
81
330
|
## ℹ️ More Resources
|
|
82
331
|
|
|
83
|
-
Please follow the step
|
|
332
|
+
Please follow the step-by-step instructions available in [Ultimate Tutorial Series](https://www.storyblok.com/tp/the-storyblok-sveltekit-ultimate-tutorial). You can find all the different parts on this overview page and take it from here.
|
|
84
333
|
The parts are:
|
|
85
334
|
|
|
86
335
|
- Part 1: [Add a headless CMS to SvelteKit in 5 minutes](https://www.storyblok.com/tp/add-a-headless-cms-to-svelte-in-5-minutes) - [Source Code](https://github.com/storyblok/sveltekit-ultimate-tutorial-series/tree/part-1-sveltekit-ut)
|
|
@@ -92,9 +341,9 @@ The parts are:
|
|
|
92
341
|
### Support
|
|
93
342
|
|
|
94
343
|
- Bugs or Feature Requests? [Submit an issue](/../../issues/new).
|
|
95
|
-
- Do you have questions about Storyblok or you need help? [Join our Discord Community](https://discord.gg/jKrbAMz).
|
|
344
|
+
- Do you have questions about Storyblok or do you need help? [Join our Discord Community](https://discord.gg/jKrbAMz).
|
|
96
345
|
|
|
97
346
|
### Contributing
|
|
98
347
|
|
|
99
348
|
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-svelte).
|
|
100
|
-
This project uses [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for
|
|
349
|
+
This project uses [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for generating new versions by using commit messages and we use the [Angular Convention](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#) to name 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.
|
package/dist/storyblok-svelte.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(d,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(d=typeof globalThis<"u"?globalThis:d||self,g(d.storyblokSvelte={}))})(this,function(d){"use strict";let g=!1;const U=[],re=s=>new Promise((e,t)=>{if(typeof window>"u"||(window.storyblokRegisterEvent=r=>{if(window.location===window.parent.location){console.warn("You are not in Draft Mode or in the Visual Editor.");return}g?r():U.push(r)},document.getElementById("storyblok-javascript-bridge")))return;const n=document.createElement("script");n.async=!0,n.src=s,n.id="storyblok-javascript-bridge",n.onerror=r=>t(r),n.onload=r=>{U.forEach(o=>o()),g=!0,e(r)},document.getElementsByTagName("head")[0].appendChild(n)});var oe=Object.defineProperty,ie=(s,e,t)=>e in s?oe(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,h=(s,e,t)=>(ie(s,typeof e!="symbol"?e+"":e,t),t);function H(s){return!(s!==s||s===1/0||s===-1/0)}function ae(s,e,t){if(!H(e))throw new TypeError("Expected `limit` to be a finite number");if(!H(t))throw new TypeError("Expected `interval` to be a finite number");const n=[];let r=[],o=0;const a=function(){o++;const c=setTimeout(function(){o--,n.length>0&&a(),r=r.filter(function(u){return u!==c})},t);r.indexOf(c)<0&&r.push(c);const l=n.shift();l.resolve(s.apply(l.self,l.args))},i=function(...c){const l=this;return new Promise(function(u,f){n.push({resolve:u,reject:f,args:c,self:l}),o<e&&a()})};return i.abort=function(){r.forEach(clearTimeout),r=[],n.forEach(function(c){c.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),n.length=0},i}const ce=function(s,e){const t={};for(const n in s){const r=s[n];e.indexOf(n)>-1&&r!==null&&(t[n]=r)}return t},le=s=>s==="email",he=()=>({singleTag:"hr"}),ue=()=>({tag:"blockquote"}),de=()=>({tag:"ul"}),fe=s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),pe=()=>({singleTag:"br"}),ge=s=>({tag:`h${s.attrs.level}`}),me=s=>({singleTag:[{tag:"img",attrs:ce(s.attrs,["src","alt","title"])}]}),ye=()=>({tag:"li"}),ke=()=>({tag:"ol"}),be=()=>({tag:"p"}),_e=()=>({tag:"b"}),ve=()=>({tag:"strike"}),we=()=>({tag:"u"}),$e=()=>({tag:"strong"}),Te=()=>({tag:"code"}),Re=()=>({tag:"i"}),je=s=>{const e={...s.attrs},{linktype:t="url"}=s.attrs;return le(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},Pe=s=>({tag:[{tag:"span",attrs:s.attrs}]}),q={nodes:{horizontal_rule:he,blockquote:ue,bullet_list:de,code_block:fe,hard_break:pe,heading:ge,image:me,list_item:ye,ordered_list:ke,paragraph:be},marks:{bold:_e,strike:ve,underline:we,strong:$e,code:Te,italic:Re,link:je,styled:Pe}},xe=function(s){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,n=RegExp(t.source);return s&&n.test(s)?s.replace(t,r=>e[r]):s};class w{constructor(e){h(this,"marks"),h(this,"nodes"),e||(e=q),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&&e.content&&Array.isArray(e.content)){let t="";return e.content.forEach(n=>{t+=this.renderNode(n)}),t}return console.warn("The render method must receive an object with a content field, which is an array"),""}renderNode(e){const t=[];e.marks&&e.marks.forEach(r=>{const o=this.getMatchingMark(r);o&&t.push(this.renderOpeningTag(o.tag))});const n=this.getMatchingNode(e);return n&&n.tag&&t.push(this.renderOpeningTag(n.tag)),e.content?e.content.forEach(r=>{t.push(this.renderNode(r))}):e.text?t.push(xe(e.text)):n&&n.singleTag?t.push(this.renderTag(n.singleTag," /")):n&&n.html&&t.push(n.html),n&&n.tag&&t.push(this.renderClosingTag(n.tag)),e.marks&&e.marks.slice(0).reverse().forEach(r=>{const o=this.getMatchingMark(r);o&&t.push(this.renderClosingTag(o.tag))}),t.join("")}renderTag(e,t){return e.constructor===String?`<${e}${t}>`:e.map(n=>{if(n.constructor===String)return`<${n}${t}>`;{let r=`<${n.tag}`;if(n.attrs)for(const o in n.attrs){const a=n.attrs[o];a!==null&&(r+=` ${o}="${a}"`)}return`${r}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}}class D{constructor(){h(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),h(this,"getOptionsPage",(e,t=25,n=1)=>({...e,per_page:t,page:n})),h(this,"delay",e=>new Promise(t=>setTimeout(t,e))),h(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),h(this,"range",(e=0,t=e)=>{const n=Math.abs(t-e)||0,r=e<t?1:-1;return this.arrayFrom(n,(o,a)=>a*r+e)}),h(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),h(this,"flatMap",(e=[],t)=>e.map(t).reduce((n,r)=>[...n,...r],[]))}stringify(e,t,n){const r=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const a=e[o],i=n?"":encodeURIComponent(o);let c;typeof a=="object"?c=this.stringify(a,t?t+encodeURIComponent("["+i+"]"):i,Array.isArray(a)):c=(t?t+encodeURIComponent("["+i+"]"):i)+"="+encodeURIComponent(a),r.push(c)}return r.join("&")}}class Ee{constructor(e){h(this,"baseURL"),h(this,"timeout"),h(this,"headers"),h(this,"responseInterceptor"),h(this,"fetch"),h(this,"ejectInterceptor"),h(this,"url"),h(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||[],this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],n={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(r=>{n.data=r});for(const r of e.headers.entries())t[r[0]]=r[1];return n.headers={...t},n.status=e.status,n.statusText=e.statusText,n}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,n=null;if(e==="get"){const c=new D;t=`${this.baseURL}${this.url}?${c.stringify(this.parameters)}`}else n=JSON.stringify(this.parameters);const r=new URL(t),o=new AbortController,{signal:a}=o;let i;this.timeout&&(i=setTimeout(()=>o.abort(),this.timeout));try{const c=await this.fetch(`${r}`,{method:e,headers:this.headers,body:n,signal:a});this.timeout&&clearTimeout(i);const l=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(c){return{message:c}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((n,r)=>{if(t.test(`${e.status}`))return n(e);const o={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};r(o)})}}let $={};const m={};class Se{constructor(e,t){if(h(this,"client"),h(this,"maxRetries"),h(this,"throttle"),h(this,"accessToken"),h(this,"cache"),h(this,"helpers"),h(this,"relations"),h(this,"links"),h(this,"richTextResolver"),h(this,"resolveNestedRelations"),!t){const o=e.region?`-${e.region}`:"",a=e.https===!1?"http":"https";e.oauthToken?t=`${a}://api${o}.storyblok.com/v1`:t=`${a}://api${o}.storyblok.com/v2`}const n=new Headers;n.set("Content-Type","application/json"),n.set("Accept","application/json"),n.forEach((o,a)=>{e.headers&&e.headers[a]&&n.set(a,e.headers[a])});let r=5;e.oauthToken&&(n.set("Authorization",e.oauthToken),r=3),e.rateLimit&&(r=e.rateLimit),e.richTextSchema?this.richTextResolver=new w(e.richTextSchema):this.richTextResolver=new w,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=ae(this.throttledRequest,r,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new D,this.resolveNestedRelations=!1,this.client=new Ee({baseURL:t,timeout:e.timeout||0,headers:n,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let n="";return t.attrs.body.forEach(r=>{n+=e(r.component,r)}),{html:n}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=m[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,n,r){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,n,r));return this.cacheResponse(e,o)}get(e,t){t||(t={});const n=`/${e}`,r=this.factoryParamOptions(n,t);return this.cacheResponse(n,r)}async getAll(e,t,n){const r=(t==null?void 0:t.per_page)||25,o=`/${e}`,a=o.split("/"),i=n||a[a.length-1],c=1,l=await this.makeRequest(o,t,r,c),u=l.total?Math.ceil(l.total/r):1,f=await this.helpers.asyncMap(this.helpers.range(c,u),b=>this.makeRequest(o,t,r,b+1));return this.helpers.flatMap([l,...f],b=>Object.values(b.data[i]))}post(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("post",n,t))}put(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("put",n,t))}delete(e,t){const n=`/${e}`;return Promise.resolve(this.throttle("delete",n,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_cleanCopy(e){return JSON.parse(JSON.stringify(e))}_insertLinks(e,t){const n=e[t];n&&n.fieldtype=="multilink"&&n.linktype=="story"&&typeof n.id=="string"&&this.links[n.id]?n.story=this._cleanCopy(this.links[n.id]):n&&n.linktype==="story"&&typeof n.uuid=="string"&&this.links[n.uuid]&&(n.story=this._cleanCopy(this.links[n.uuid]))}_insertRelations(e,t,n){if(n.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]&&e[t].constructor===Array){const r=[];e[t].forEach(o=>{this.relations[o]&&r.push(this._cleanCopy(this.relations[o]))}),e[t]=r}}}iterateTree(e,t){const n=r=>{if(r!=null){if(r.constructor===Array)for(let o=0;o<r.length;o++)n(r[o]);else if(r.constructor===Object){if(r._stopResolving)return;for(const o in r)(r.component&&r._uid||r.type==="link")&&(this._insertRelations(r,o,t),this._insertLinks(r,o)),n(r[o])}}};n(e.content)}async resolveLinks(e,t){let n=[];if(e.link_uuids){const r=e.link_uuids.length,o=[],a=50;for(let i=0;i<r;i+=a){const c=Math.min(r,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=>{n.push(c)})}else n=e.links;n.forEach(r=>{this.links[r.uuid]={...r,_stopResolving:!0}})}async resolveRelations(e,t){let n=[];if(e.rel_uuids){const r=e.rel_uuids.length,o=[],a=50;for(let i=0;i<r;i+=a){const c=Math.min(r,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=>{n.push(c)})}else n=e.rels;n&&n.length>0&&n.forEach(r=>{this.relations[r.uuid]={...r,_stopResolving:!0}})}async resolveStories(e,t){var n,r;let o=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((n=e.links)!=null&&n.length||(r=e.link_uuids)!=null&&r.length)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const a in this.relations)this.iterateTree(this.relations[a],o);e.story?this.iterateTree(e.story,o):e.stories.forEach(a=>{this.iterateTree(a,o)})}async cacheResponse(e,t,n){const r=this.helpers.stringify({url:e,params:t}),o=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const a=await o.get(r);if(a)return Promise.resolve(a)}return new Promise((a,i)=>{try{(async()=>{var c;try{const l=await this.throttle("get",e,t);let u={data:l.data,headers:l.headers};return(c=l.headers)!=null&&c["per-page"]&&(u=Object.assign({},u,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),l.status!=200?i(l):((u.data.story||u.data.stories)&&await this.resolveStories(u.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(r,u),u.data.cv&&t.token&&(t.version=="draft"&&m[t.token]!=u.data.cv&&await this.flushCache(),m[t.token]=u.data.cv),a(u))}catch(l){return i(l)}})()}catch{}})}throttledRequest(e,t,n){return this.client[e](t,n)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve($[e])},getAll(){return Promise.resolve($)},set(e,t){return $[e]=t,Promise.resolve(void 0)},flush(){return $={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const Oe=(s={})=>{const{apiOptions:e}=s;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Se(e)}},Ce=s=>{if(typeof s!="object"||typeof s._editable>"u")return{};const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let P;const Ie="https://app.storyblok.com/f/storyblok-v2-latest.js",Ae=(s,e,t={})=>{if(!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u"){if(!s){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],n=>{n.action==="input"&&n.story.id===s?e(n.story):(n.action==="change"||n.action==="published")&&n.storyId===s&&window.location.reload()})})}},Ne=(s={})=>{const{bridge:e,accessToken:t,use:n=[],apiOptions:r={},richText:o={}}=s;r.accessToken=r.accessToken||t;const a={bridge:e,apiOptions:r};let i={};return n.forEach(c=>{i={...i,...c(a)}}),e!==!1&&re(Ie),P=new w(o.schema),o.resolver&&B(P,o.resolver),i},B=(s,e)=>{s.addNode("blok",t=>{let n="";return t.attrs.body.forEach(r=>{n+=e(r.component,r)}),{html:n}})},Me=(s,e,t)=>{let n=t||P;if(!n){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return s===""?"":s?(e&&(n=new w(e.schema),e.resolver&&B(n,e.resolver)),n.render(s)):(console.warn(`${s} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
1
|
+
(function(d,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(d=typeof globalThis<"u"?globalThis:d||self,g(d.storyblokSvelte={}))})(this,function(d){"use strict";let g=!1;const U=[],ne=s=>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}g?n():U.push(n)},document.getElementById("storyblok-javascript-bridge")))return;const r=document.createElement("script");r.async=!0,r.src=s,r.id="storyblok-javascript-bridge",r.onerror=n=>t(n),r.onload=n=>{U.forEach(o=>o()),g=!0,e(n)},document.getElementsByTagName("head")[0].appendChild(r)});var oe=Object.defineProperty,ie=(s,e,t)=>e in s?oe(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,u=(s,e,t)=>(ie(s,typeof e!="symbol"?e+"":e,t),t);function H(s){return!(s!==s||s===1/0||s===-1/0)}function ae(s,e,t){if(!H(e))throw new TypeError("Expected `limit` to be a finite number");if(!H(t))throw new TypeError("Expected `interval` to be a finite number");const r=[];let n=[],o=0;const i=function(){o++;const c=setTimeout(function(){o--,r.length>0&&i(),n=n.filter(function(h){return h!==c})},t);n.indexOf(c)<0&&n.push(c);const l=r.shift();l.resolve(s.apply(l.self,l.args))},a=function(...c){const l=this;return new Promise(function(h,f){r.push({resolve:h,reject:f,args:c,self:l}),o<e&&i()})};return a.abort=function(){n.forEach(clearTimeout),n=[],r.forEach(function(c){c.reject(function(){Error.call(this,"Throttled function aborted"),this.name="AbortError"})}),r.length=0},a}const ce=function(s,e){const t={};for(const r in s){const n=s[r];e.indexOf(r)>-1&&n!==null&&(t[r]=n)}return t},le=s=>s==="email",ue=()=>({singleTag:"hr"}),he=()=>({tag:"blockquote"}),de=()=>({tag:"ul"}),fe=s=>({tag:["pre",{tag:"code",attrs:s.attrs}]}),pe=()=>({singleTag:"br"}),ge=s=>({tag:`h${s.attrs.level}`}),me=s=>({singleTag:[{tag:"img",attrs:ce(s.attrs,["src","alt","title"])}]}),ye=()=>({tag:"li"}),ke=()=>({tag:"ol"}),_e=()=>({tag:"p"}),be=()=>({tag:"b"}),ve=()=>({tag:"strike"}),we=()=>({tag:"u"}),$e=()=>({tag:"strong"}),Te=()=>({tag:"code"}),Re=()=>({tag:"i"}),Pe=s=>{const e={...s.attrs},{linktype:t="url"}=s.attrs;return le(t)&&(e.href=`mailto:${e.href}`),e.anchor&&(e.href=`${e.href}#${e.anchor}`,delete e.anchor),{tag:[{tag:"a",attrs:e}]}},je=s=>({tag:[{tag:"span",attrs:s.attrs}]}),q={nodes:{horizontal_rule:ue,blockquote:he,bullet_list:de,code_block:fe,hard_break:pe,heading:ge,image:me,list_item:ye,ordered_list:ke,paragraph:_e},marks:{bold:be,strike:ve,underline:we,strong:$e,code:Te,italic:Re,link:Pe,styled:je}},xe=function(s){const e={"&":"&","<":"<",">":">",'"':""","'":"'"},t=/[&<>"']/g,r=RegExp(t.source);return s&&r.test(s)?s.replace(t,n=>e[n]):s};class ${constructor(e){u(this,"marks"),u(this,"nodes"),e||(e=q),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&&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){const t=[];e.marks&&e.marks.forEach(n=>{const o=this.getMatchingMark(n);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(n=>{t.push(this.renderNode(n))}):e.text?t.push(xe(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(n=>{const o=this.getMatchingMark(n);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 n=`<${r.tag}`;if(r.attrs)for(const o in r.attrs){const i=r.attrs[o];i!==null&&(n+=` ${o}="${i}"`)}return`${n}${t}>`}}).join("")}renderOpeningTag(e){return this.renderTag(e,"")}renderClosingTag(e){return e.constructor===String?`</${e}>`:e.slice(0).reverse().map(t=>t.constructor===String?`</${t}>`:`</${t.tag}>`).join("")}getMatchingNode(e){const t=this.nodes[e.type];if(typeof t=="function")return t(e)}getMatchingMark(e){const t=this.marks[e.type];if(typeof t=="function")return t(e)}}class D{constructor(){u(this,"isCDNUrl",(e="")=>e.indexOf("/cdn/")>-1),u(this,"getOptionsPage",(e,t=25,r=1)=>({...e,per_page:t,page:r})),u(this,"delay",e=>new Promise(t=>setTimeout(t,e))),u(this,"arrayFrom",(e=0,t)=>[...Array(e)].map(t)),u(this,"range",(e=0,t=e)=>{const r=Math.abs(t-e)||0,n=e<t?1:-1;return this.arrayFrom(r,(o,i)=>i*n+e)}),u(this,"asyncMap",async(e,t)=>Promise.all(e.map(t))),u(this,"flatMap",(e=[],t)=>e.map(t).reduce((r,n)=>[...r,...n],[]))}stringify(e,t,r){const n=[];for(const o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const i=e[o],a=r?"":encodeURIComponent(o);let c;typeof i=="object"?c=this.stringify(i,t?t+encodeURIComponent("["+a+"]"):a,Array.isArray(i)):c=(t?t+encodeURIComponent("["+a+"]"):a)+"="+encodeURIComponent(i),n.push(c)}return n.join("&")}}class Ee{constructor(e){u(this,"baseURL"),u(this,"timeout"),u(this,"headers"),u(this,"responseInterceptor"),u(this,"fetch"),u(this,"ejectInterceptor"),u(this,"url"),u(this,"parameters"),this.baseURL=e.baseURL,this.headers=e.headers||[],this.timeout=e!=null&&e.timeout?e.timeout*1e3:0,this.responseInterceptor=e.responseInterceptor,this.fetch=(...t)=>e.fetch?e.fetch(...t):fetch(...t),this.ejectInterceptor=!1,this.url="",this.parameters={}}get(e,t){return this.url=e,this.parameters=t,this._methodHandler("get")}post(e,t){return this.url=e,this.parameters=t,this._methodHandler("post")}put(e,t){return this.url=e,this.parameters=t,this._methodHandler("put")}delete(e,t){return this.url=e,this.parameters=t,this._methodHandler("delete")}async _responseHandler(e){const t=[],r={data:{},headers:{},status:0,statusText:""};e.status!==204&&await e.json().then(n=>{r.data=n});for(const n of e.headers.entries())t[n[0]]=n[1];return r.headers={...t},r.status=e.status,r.statusText=e.statusText,r}async _methodHandler(e){let t=`${this.baseURL}${this.url}`,r=null;if(e==="get"){const c=new D;t=`${this.baseURL}${this.url}?${c.stringify(this.parameters)}`}else r=JSON.stringify(this.parameters);const n=new URL(t),o=new AbortController,{signal:i}=o;let a;this.timeout&&(a=setTimeout(()=>o.abort(),this.timeout));try{const c=await this.fetch(`${n}`,{method:e,headers:this.headers,body:r,signal:i});this.timeout&&clearTimeout(a);const l=await this._responseHandler(c);return this.responseInterceptor&&!this.ejectInterceptor?this._statusHandler(this.responseInterceptor(l)):this._statusHandler(l)}catch(c){return{message:c}}}eject(){this.ejectInterceptor=!0}_statusHandler(e){const t=/20[0-6]/g;return new Promise((r,n)=>{if(t.test(`${e.status}`))return r(e);const o={message:new Error(e.statusText),status:e.status,response:e.data.error||e.data.slug};n(o)})}}let T={};const m={};class Se{constructor(e,t){if(u(this,"client"),u(this,"maxRetries"),u(this,"throttle"),u(this,"accessToken"),u(this,"cache"),u(this,"helpers"),u(this,"relations"),u(this,"links"),u(this,"richTextResolver"),u(this,"resolveNestedRelations"),!t){const o=e.region?`-${e.region}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${o}.storyblok.com/v1`:t=`${i}://api${o}.storyblok.com/v2`}const r=new Headers;r.set("Content-Type","application/json"),r.set("Accept","application/json"),r.forEach((o,i)=>{e.headers&&e.headers[i]&&r.set(i,e.headers[i])});let n=5;e.oauthToken&&(r.set("Authorization",e.oauthToken),n=3),e.rateLimit&&(n=e.rateLimit),e.richTextSchema?this.richTextResolver=new $(e.richTextSchema):this.richTextResolver=new $,e.componentResolver&&this.setComponentResolver(e.componentResolver),this.maxRetries=e.maxRetries,this.throttle=ae(this.throttledRequest,n,1e3),this.accessToken=e.accessToken||"",this.relations={},this.links={},this.cache=e.cache||{clear:"manual"},this.helpers=new D,this.resolveNestedRelations=!1,this.client=new Ee({baseURL:t,timeout:e.timeout||0,headers:r,responseInterceptor:e.responseInterceptor,fetch:e.fetch})}setComponentResolver(e){this.richTextResolver.addNode("blok",t=>{let r="";return t.attrs.body.forEach(n=>{r+=e(n.component,n)}),{html:r}})}parseParams(e){return e.version||(e.version="published"),e.token||(e.token=this.getToken()),e.cv||(e.cv=m[e.token]),Array.isArray(e.resolve_relations)&&(e.resolve_relations=e.resolve_relations.join(",")),e}factoryParamOptions(e,t){return this.helpers.isCDNUrl(e)?this.parseParams(t):t}makeRequest(e,t,r,n){const o=this.factoryParamOptions(e,this.helpers.getOptionsPage(t,r,n));return this.cacheResponse(e,o)}get(e,t){t||(t={});const r=`/${e}`,n=this.factoryParamOptions(r,t);return this.cacheResponse(r,n)}async getAll(e,t,r){const n=(t==null?void 0:t.per_page)||25,o=`/${e}`,i=o.split("/"),a=r||i[i.length-1],c=1,l=await this.makeRequest(o,t,n,c),h=l.total?Math.ceil(l.total/n):1,f=await this.helpers.asyncMap(this.helpers.range(c,h),b=>this.makeRequest(o,t,n,b+1));return this.helpers.flatMap([l,...f],b=>Object.values(b.data[a]))}post(e,t){const r=`/${e}`;return Promise.resolve(this.throttle("post",r,t))}put(e,t){const r=`/${e}`;return Promise.resolve(this.throttle("put",r,t))}delete(e,t){const r=`/${e}`;return Promise.resolve(this.throttle("delete",r,t))}getStories(e){return this.get("cdn/stories",e)}getStory(e,t){return this.get(`cdn/stories/${e}`,t)}getToken(){return this.accessToken}ejectInterceptor(){this.client.eject()}_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]&&e[t].constructor===Array){const n=[];e[t].forEach(o=>{this.relations[o]&&n.push(this._cleanCopy(this.relations[o]))}),e[t]=n}}}iterateTree(e,t){const r=n=>{if(n!=null){if(n.constructor===Array)for(let o=0;o<n.length;o++)r(n[o]);else if(n.constructor===Object){if(n._stopResolving)return;for(const o in n)(n.component&&n._uid||n.type==="link")&&(this._insertRelations(n,o,t),this._insertLinks(n,o)),r(n[o])}}};r(e.content)}async resolveLinks(e,t){let r=[];if(e.link_uuids){const n=e.link_uuids.length,o=[],i=50;for(let a=0;a<n;a+=i){const c=Math.min(n,a+i);o.push(e.link_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.links;r.forEach(n=>{this.links[n.uuid]={...n,_stopResolving:!0}})}async resolveRelations(e,t){let r=[];if(e.rel_uuids){const n=e.rel_uuids.length,o=[],i=50;for(let a=0;a<n;a+=i){const c=Math.min(n,a+i);o.push(e.rel_uuids.slice(a,c))}for(let a=0;a<o.length;a++)(await this.getStories({per_page:i,language:t.language,version:t.version,by_uuids:o[a].join(",")})).data.stories.forEach(c=>{r.push(c)})}else r=e.rels;r&&r.length>0&&r.forEach(n=>{this.relations[n.uuid]={...n,_stopResolving:!0}})}async resolveStories(e,t){var r,n;let o=[];if(typeof t.resolve_relations<"u"&&t.resolve_relations.length>0&&(typeof t.resolve_relations=="string"&&(o=t.resolve_relations.split(",")),await this.resolveRelations(e,t)),t.resolve_links&&["1","story","url"].indexOf(t.resolve_links)>-1&&((r=e.links)!=null&&r.length||(n=e.link_uuids)!=null&&n.length)&&await this.resolveLinks(e,t),this.resolveNestedRelations)for(const i in this.relations)this.iterateTree(this.relations[i],o);e.story?this.iterateTree(e.story,o):e.stories.forEach(i=>{this.iterateTree(i,o)})}async cacheResponse(e,t,r){const n=this.helpers.stringify({url:e,params:t}),o=this.cacheProvider();if(this.cache.clear==="auto"&&t.version==="draft"&&await this.flushCache(),t.version==="published"&&e!="/cdn/spaces/me"){const i=await o.get(n);if(i)return Promise.resolve(i)}return new Promise((i,a)=>{try{(async()=>{var c;try{const l=await this.throttle("get",e,t);let h={data:l.data,headers:l.headers};return(c=l.headers)!=null&&c["per-page"]&&(h=Object.assign({},h,{perPage:l.headers["per-page"]?parseInt(l.headers["per-page"]):0,total:l.headers["per-page"]?parseInt(l.headers.total):0})),l.status!=200?a(l):((h.data.story||h.data.stories)&&await this.resolveStories(h.data,t),t.version==="published"&&e!="/cdn/spaces/me"&&await o.set(n,h),h.data.cv&&t.token&&(t.version=="draft"&&m[t.token]!=h.data.cv&&await this.flushCache(),m[t.token]=h.data.cv),i(h))}catch(l){return a(l)}})()}catch{}})}throttledRequest(e,t,r){return this.client[e](t,r)}cacheVersions(){return m}cacheVersion(){return m[this.accessToken]}setCacheVersion(e){this.accessToken&&(m[this.accessToken]=e)}cacheProvider(){switch(this.cache.type){case"memory":return{get(e){return Promise.resolve(T[e])},getAll(){return Promise.resolve(T)},set(e,t){return T[e]=t,Promise.resolve(void 0)},flush(){return T={},Promise.resolve(void 0)}};case"custom":if(this.cache.custom)return this.cache.custom;default:return{get(){return Promise.resolve(void 0)},getAll(){return Promise.resolve(void 0)},set(){return Promise.resolve(void 0)},flush(){return Promise.resolve(void 0)}}}}async flushCache(){return await this.cacheProvider().flush(),this}}const Oe=(s={})=>{const{apiOptions:e}=s;if(!e.accessToken){console.error("You need to provide an access token to interact with Storyblok API. Read https://www.storyblok.com/docs/api/content-delivery#topics/authentication");return}return{storyblokApi:new Se(e)}},Ce=s=>{if(typeof s!="object"||typeof s._editable>"u")return{};const e=JSON.parse(s._editable.replace(/^<!--#storyblok#/,"").replace(/-->$/,""));return{"data-blok-c":JSON.stringify(e),"data-blok-uid":e.id+"-"+e.uid}};let j;const Ie="https://app.storyblok.com/f/storyblok-v2-latest.js",Ae=(s,e,t={})=>{var r;const n=!(typeof window>"u")&&typeof window.storyblokRegisterEvent<"u",o=+new URL((r=window.location)==null?void 0:r.href).searchParams.get("_storyblok")===s;if(!(!n||!o)){if(!s){console.warn("Story ID is not defined. Please provide a valid ID.");return}window.storyblokRegisterEvent(()=>{new window.StoryblokBridge(t).on(["input","published","change"],i=>{i.action==="input"&&i.story.id===s?e(i.story):(i.action==="change"||i.action==="published")&&i.storyId===s&&window.location.reload()})})}},Ne=(s={})=>{var e,t;const{bridge:r,accessToken:n,use:o=[],apiOptions:i={},richText:a={}}=s;i.accessToken=i.accessToken||n;const c={bridge:r,apiOptions:i};let l={};o.forEach(f=>{l={...l,...f(c)}});const h=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return r!==!1&&h&&ne(Ie),j=new $(a.schema),a.resolver&&B(j,a.resolver),l},B=(s,e)=>{s.addNode("blok",t=>{let r="";return t.attrs.body.forEach(n=>{r+=e(n.component,n)}),{html:r}})},Me=(s,e,t)=>{let r=t||j;if(!r){console.error("Please initialize the Storyblok SDK before calling the renderRichText function");return}return s===""?"":s?(e&&(r=new $(e.schema),e.resolver&&B(r,e.resolver)),r.render(s)):(console.warn(`${s} is not a valid Richtext object. This might be because the value of the richtext field is empty.
|
|
2
2
|
|
|
3
|
-
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")};function x(){}function E(s,e){for(const t in e)s[t]=e[t];return s}function J(s){return s()}function F(){return Object.create(null)}function
|
|
3
|
+
For more info about the richtext object check https://github.com/storyblok/storyblok-js#rendering-rich-text`),"")};function x(){}function E(s,e){for(const t in e)s[t]=e[t];return s}function J(s){return s()}function F(){return Object.create(null)}function v(s){s.forEach(J)}function V(s){return typeof s=="function"}function Le(s,e){return s!=s?e==e:s!==e||s&&typeof s=="object"||typeof s=="function"}function Ue(s){return Object.keys(s).length===0}function He(s){const e={};for(const t in s)t[0]!=="$"&&(e[t]=s[t]);return e}function Y(s,e){const t={};e=new Set(e);for(const r in s)!e.has(r)&&r[0]!=="$"&&(t[r]=s[r]);return t}function qe(s,e,t){s.insertBefore(e,t||null)}function z(s){s.parentNode&&s.parentNode.removeChild(s)}function De(s){return document.createTextNode(s)}function Be(){return De("")}function Je(s){return Array.from(s.childNodes)}function K(s,e){return new s(e)}let S;function w(s){S=s}const y=[],G=[];let k=[];const Q=[],Fe=Promise.resolve();let O=!1;function Ve(){O||(O=!0,Fe.then(W))}function C(s){k.push(s)}const I=new Set;let _=0;function W(){if(_!==0)return;const s=S;do{try{for(;_<y.length;){const e=y[_];_++,w(e),Ye(e.$$)}}catch(e){throw y.length=0,_=0,e}for(w(null),y.length=0,_=0;G.length;)G.pop()();for(let e=0;e<k.length;e+=1){const t=k[e];I.has(t)||(I.add(t),t())}k.length=0}while(y.length);for(;Q.length;)Q.pop()();O=!1,I.clear(),w(s)}function Ye(s){if(s.fragment!==null){s.update(),v(s.before_update);const e=s.dirty;s.dirty=[-1],s.fragment&&s.fragment.p(s.ctx,e),s.after_update.forEach(C)}}function ze(s){const e=[],t=[];k.forEach(r=>s.indexOf(r)===-1?e.push(r):t.push(r)),t.forEach(r=>r()),k=e}const R=new Set;let p;function Ke(){p={r:0,c:[],p}}function Ge(){p.r||v(p.c),p=p.p}function A(s,e){s&&s.i&&(R.delete(s),s.i(e))}function X(s,e,t,r){if(s&&s.o){if(R.has(s))return;R.add(s),p.c.push(()=>{R.delete(s),r&&(t&&s.d(1),r())}),s.o(e)}else r&&r()}function Qe(s,e){const t={},r={},n={$$scope:1};let o=s.length;for(;o--;){const i=s[o],a=e[o];if(a){for(const c in i)c in a||(r[c]=1);for(const c in a)n[c]||(t[c]=a[c],n[c]=1);s[o]=a}else for(const c in i)n[c]=1}for(const i in r)i in t||(t[i]=void 0);return t}function We(s){return typeof s=="object"&&s!==null?s:{}}function Z(s){s&&s.c()}function N(s,e,t,r){const{fragment:n,after_update:o}=s.$$;n&&n.m(e,t),r||C(()=>{const i=s.$$.on_mount.map(J).filter(V);s.$$.on_destroy?s.$$.on_destroy.push(...i):v(i),s.$$.on_mount=[]}),o.forEach(C)}function M(s,e){const t=s.$$;t.fragment!==null&&(ze(t.after_update),v(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function Xe(s,e){s.$$.dirty[0]===-1&&(y.push(s),Ve(),s.$$.dirty.fill(0)),s.$$.dirty[e/31|0]|=1<<e%31}function Ze(s,e,t,r,n,o,i,a=[-1]){const c=S;w(s);const l=s.$$={fragment:null,ctx:[],props:o,update:x,not_equal:n,bound:F(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(c?c.$$.context:[])),callbacks:F(),dirty:a,skip_bound:!1,root:e.target||c.$$.root};i&&i(l.root);let h=!1;if(l.ctx=t?t(s,e.props||{},(f,b,...se)=>{const re=se.length?se[0]:b;return l.ctx&&n(l.ctx[f],l.ctx[f]=re)&&(!l.skip_bound&&l.bound[f]&&l.bound[f](re),h&&Xe(s,f)),b}):[],l.update(),h=!0,v(l.before_update),l.fragment=r?r(l.ctx):!1,e.target){if(e.hydrate){const f=Je(e.target);l.fragment&&l.fragment.l(f),f.forEach(z)}else l.fragment&&l.fragment.c();e.intro&&A(s.$$.fragment),N(s,e.target,e.anchor,e.customElement),W()}w(c)}class et{$destroy(){M(this,1),this.$destroy=x}$on(e,t){if(!V(t))return x;const r=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return r.push(t),()=>{const n=r.indexOf(t);n!==-1&&r.splice(n,1)}}$set(e){this.$$set&&!Ue(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}function tt(s){let e,t,r;const n=[{blok:s[0]},s[2]];var o=s[1];function i(a){let c={};for(let l=0;l<n.length;l+=1)c=E(c,n[l]);return{props:c}}return o&&(e=K(o,i())),{c(){e&&Z(e.$$.fragment),t=Be()},m(a,c){e&&N(e,a,c),qe(a,t,c),r=!0},p(a,[c]){const l=c&5?Qe(n,[c&1&&{blok:a[0]},c&4&&We(a[2])]):{};if(c&2&&o!==(o=a[1])){if(e){Ke();const h=e;X(h.$$.fragment,1,0,()=>{M(h,1)}),Ge()}o?(e=K(o,i()),Z(e.$$.fragment),A(e.$$.fragment,1),N(e,t.parentNode,t)):e=null}else o&&e.$set(l)},i(a){r||(e&&A(e.$$.fragment,a),r=!0)},o(a){e&&X(e.$$.fragment,a),r=!1},d(a){a&&z(t),e&&M(e,a)}}}function st(s,e,t){const r=["blok"];let n=Y(e,r),o,{blok:i}=e;return i?o=te(i.component):console.error("Please provide a 'blok' property to the StoryblokComponent"),s.$$set=a=>{e=E(E({},e),He(a)),t(2,n=Y(e,r)),"blok"in a&&t(0,i=a.blok)},[i,o,n]}class rt extends et{constructor(e){super(),Ze(this,e,st,tt,Le,{blok:0})}}const nt=(s,e)=>{const t=r=>{const n=Ce(r);n["data-blok-c"]&&(s.setAttribute("data-blok-c",n["data-blok-c"]),s.setAttribute("data-blok-uid",n["data-blok-uid"]),s.classList.add("storyblok__outline"))};return t(e),{update(r){t(r)}}};let L=null;const ee=()=>(L||console.log("You can't use getStoryblokApi if you're not loading apiPlugin."),L);let P=null;const ot=s=>{const{storyblokApi:e}=Ne(s);L=e,P=s.components||{}},te=s=>{let e=null;return e=typeof P=="function"?P()[s]:P[s],e||console.error(`You didn't load the ${s} component. Please load it in storyblokInit. For example:
|
|
4
4
|
storyblokInit({
|
|
5
5
|
accessToken: "<your-token>",
|
|
6
6
|
components: {
|
|
7
7
|
"teaser": Teaser
|
|
8
8
|
}
|
|
9
9
|
})
|
|
10
|
-
`),e};d.RichTextSchema=q,d.StoryblokComponent=
|
|
10
|
+
`),e};d.RichTextSchema=q,d.StoryblokComponent=rt,d.apiPlugin=Oe,d.getComponent=te,d.getStoryblokApi=ee,d.renderRichText=Me,d.storyblokEditable=nt,d.storyblokInit=ot,d.useStoryblokApi=ee,d.useStoryblokBridge=Ae,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -24,17 +24,17 @@ function re(s, e, t) {
|
|
|
24
24
|
throw new TypeError("Expected `interval` to be a finite number");
|
|
25
25
|
const r = [];
|
|
26
26
|
let n = [], o = 0;
|
|
27
|
-
const
|
|
27
|
+
const i = function() {
|
|
28
28
|
o++;
|
|
29
29
|
const c = setTimeout(function() {
|
|
30
|
-
o--, r.length > 0 &&
|
|
30
|
+
o--, r.length > 0 && i(), n = n.filter(function(u) {
|
|
31
31
|
return u !== c;
|
|
32
32
|
});
|
|
33
33
|
}, t);
|
|
34
34
|
n.indexOf(c) < 0 && n.push(c);
|
|
35
35
|
const l = r.shift();
|
|
36
36
|
l.resolve(s.apply(l.self, l.args));
|
|
37
|
-
},
|
|
37
|
+
}, a = function(...c) {
|
|
38
38
|
const l = this;
|
|
39
39
|
return new Promise(function(u, d) {
|
|
40
40
|
r.push({
|
|
@@ -42,16 +42,16 @@ function re(s, e, t) {
|
|
|
42
42
|
reject: d,
|
|
43
43
|
args: c,
|
|
44
44
|
self: l
|
|
45
|
-
}), o < e &&
|
|
45
|
+
}), o < e && i();
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
|
-
return
|
|
48
|
+
return a.abort = function() {
|
|
49
49
|
n.forEach(clearTimeout), n = [], r.forEach(function(c) {
|
|
50
50
|
c.reject(function() {
|
|
51
51
|
Error.call(this, "Throttled function aborted"), this.name = "AbortError";
|
|
52
52
|
});
|
|
53
53
|
}), r.length = 0;
|
|
54
|
-
},
|
|
54
|
+
}, a;
|
|
55
55
|
}
|
|
56
56
|
const ne = function(s, e) {
|
|
57
57
|
const t = {};
|
|
@@ -196,8 +196,8 @@ class T {
|
|
|
196
196
|
let n = `<${r.tag}`;
|
|
197
197
|
if (r.attrs)
|
|
198
198
|
for (const o in r.attrs) {
|
|
199
|
-
const
|
|
200
|
-
|
|
199
|
+
const i = r.attrs[o];
|
|
200
|
+
i !== null && (n += ` ${o}="${i}"`);
|
|
201
201
|
}
|
|
202
202
|
return `${n}${t}>`;
|
|
203
203
|
}
|
|
@@ -228,7 +228,7 @@ class K {
|
|
|
228
228
|
page: r
|
|
229
229
|
})), h(this, "delay", (e) => new Promise((t) => setTimeout(t, e))), h(this, "arrayFrom", (e = 0, t) => [...Array(e)].map(t)), h(this, "range", (e = 0, t = e) => {
|
|
230
230
|
const r = Math.abs(t - e) || 0, n = e < t ? 1 : -1;
|
|
231
|
-
return this.arrayFrom(r, (o,
|
|
231
|
+
return this.arrayFrom(r, (o, i) => i * n + e);
|
|
232
232
|
}), h(this, "asyncMap", async (e, t) => Promise.all(e.map(t))), h(this, "flatMap", (e = [], t) => e.map(t).reduce((r, n) => [...r, ...n], []));
|
|
233
233
|
}
|
|
234
234
|
stringify(e, t, r) {
|
|
@@ -236,13 +236,13 @@ class K {
|
|
|
236
236
|
for (const o in e) {
|
|
237
237
|
if (!Object.prototype.hasOwnProperty.call(e, o))
|
|
238
238
|
continue;
|
|
239
|
-
const
|
|
239
|
+
const i = e[o], a = r ? "" : encodeURIComponent(o);
|
|
240
240
|
let c;
|
|
241
|
-
typeof
|
|
242
|
-
|
|
243
|
-
t ? t + encodeURIComponent("[" +
|
|
244
|
-
Array.isArray(
|
|
245
|
-
) : c = (t ? t + encodeURIComponent("[" +
|
|
241
|
+
typeof i == "object" ? c = this.stringify(
|
|
242
|
+
i,
|
|
243
|
+
t ? t + encodeURIComponent("[" + a + "]") : a,
|
|
244
|
+
Array.isArray(i)
|
|
245
|
+
) : c = (t ? t + encodeURIComponent("[" + a + "]") : a) + "=" + encodeURIComponent(i), n.push(c);
|
|
246
246
|
}
|
|
247
247
|
return n.join("&");
|
|
248
248
|
}
|
|
@@ -286,17 +286,17 @@ class xe {
|
|
|
286
286
|
)}`;
|
|
287
287
|
} else
|
|
288
288
|
r = JSON.stringify(this.parameters);
|
|
289
|
-
const n = new URL(t), o = new AbortController(), { signal:
|
|
290
|
-
let
|
|
291
|
-
this.timeout && (
|
|
289
|
+
const n = new URL(t), o = new AbortController(), { signal: i } = o;
|
|
290
|
+
let a;
|
|
291
|
+
this.timeout && (a = setTimeout(() => o.abort(), this.timeout));
|
|
292
292
|
try {
|
|
293
293
|
const c = await this.fetch(`${n}`, {
|
|
294
294
|
method: e,
|
|
295
295
|
headers: this.headers,
|
|
296
296
|
body: r,
|
|
297
|
-
signal:
|
|
297
|
+
signal: i
|
|
298
298
|
});
|
|
299
|
-
this.timeout && clearTimeout(
|
|
299
|
+
this.timeout && clearTimeout(a);
|
|
300
300
|
const l = await this._responseHandler(c);
|
|
301
301
|
return this.responseInterceptor && !this.ejectInterceptor ? this._statusHandler(this.responseInterceptor(l)) : this._statusHandler(l);
|
|
302
302
|
} catch (c) {
|
|
@@ -322,17 +322,17 @@ class xe {
|
|
|
322
322
|
});
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
|
-
let
|
|
325
|
+
let v = {};
|
|
326
326
|
const g = {};
|
|
327
327
|
class Pe {
|
|
328
328
|
constructor(e, t) {
|
|
329
329
|
if (h(this, "client"), h(this, "maxRetries"), h(this, "throttle"), h(this, "accessToken"), h(this, "cache"), h(this, "helpers"), h(this, "relations"), h(this, "links"), h(this, "richTextResolver"), h(this, "resolveNestedRelations"), !t) {
|
|
330
|
-
const o = e.region ? `-${e.region}` : "",
|
|
331
|
-
e.oauthToken ? t = `${
|
|
330
|
+
const o = e.region ? `-${e.region}` : "", i = e.https === !1 ? "http" : "https";
|
|
331
|
+
e.oauthToken ? t = `${i}://api${o}.storyblok.com/v1` : t = `${i}://api${o}.storyblok.com/v2`;
|
|
332
332
|
}
|
|
333
333
|
const r = new Headers();
|
|
334
|
-
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), r.forEach((o,
|
|
335
|
-
e.headers && e.headers[
|
|
334
|
+
r.set("Content-Type", "application/json"), r.set("Accept", "application/json"), r.forEach((o, i) => {
|
|
335
|
+
e.headers && e.headers[i] && r.set(i, e.headers[i]);
|
|
336
336
|
});
|
|
337
337
|
let n = 5;
|
|
338
338
|
e.oauthToken && (r.set("Authorization", e.oauthToken), n = 3), e.rateLimit && (n = e.rateLimit), e.richTextSchema ? this.richTextResolver = new T(e.richTextSchema) : this.richTextResolver = new T(), e.componentResolver && this.setComponentResolver(e.componentResolver), this.maxRetries = e.maxRetries, this.throttle = re(this.throttledRequest, n, 1e3), this.accessToken = e.accessToken || "", this.relations = {}, this.links = {}, this.cache = e.cache || { clear: "manual" }, this.helpers = new K(), this.resolveNestedRelations = !1, this.client = new xe({
|
|
@@ -372,13 +372,13 @@ class Pe {
|
|
|
372
372
|
return this.cacheResponse(r, n);
|
|
373
373
|
}
|
|
374
374
|
async getAll(e, t, r) {
|
|
375
|
-
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`,
|
|
375
|
+
const n = (t == null ? void 0 : t.per_page) || 25, o = `/${e}`, i = o.split("/"), a = r || i[i.length - 1], c = 1, l = await this.makeRequest(o, t, n, c), u = l.total ? Math.ceil(l.total / n) : 1, d = await this.helpers.asyncMap(
|
|
376
376
|
this.helpers.range(c, u),
|
|
377
377
|
(p) => this.makeRequest(o, t, n, p + 1)
|
|
378
378
|
);
|
|
379
379
|
return this.helpers.flatMap(
|
|
380
380
|
[l, ...d],
|
|
381
|
-
(p) => Object.values(p.data[
|
|
381
|
+
(p) => Object.values(p.data[a])
|
|
382
382
|
);
|
|
383
383
|
}
|
|
384
384
|
post(e, t) {
|
|
@@ -447,17 +447,17 @@ class Pe {
|
|
|
447
447
|
async resolveLinks(e, t) {
|
|
448
448
|
let r = [];
|
|
449
449
|
if (e.link_uuids) {
|
|
450
|
-
const n = e.link_uuids.length, o = [],
|
|
451
|
-
for (let
|
|
452
|
-
const c = Math.min(n,
|
|
453
|
-
o.push(e.link_uuids.slice(
|
|
450
|
+
const n = e.link_uuids.length, o = [], i = 50;
|
|
451
|
+
for (let a = 0; a < n; a += i) {
|
|
452
|
+
const c = Math.min(n, a + i);
|
|
453
|
+
o.push(e.link_uuids.slice(a, c));
|
|
454
454
|
}
|
|
455
|
-
for (let
|
|
455
|
+
for (let a = 0; a < o.length; a++)
|
|
456
456
|
(await this.getStories({
|
|
457
|
-
per_page:
|
|
457
|
+
per_page: i,
|
|
458
458
|
language: t.language,
|
|
459
459
|
version: t.version,
|
|
460
|
-
by_uuids: o[
|
|
460
|
+
by_uuids: o[a].join(",")
|
|
461
461
|
})).data.stories.forEach(
|
|
462
462
|
(c) => {
|
|
463
463
|
r.push(c);
|
|
@@ -472,17 +472,17 @@ class Pe {
|
|
|
472
472
|
async resolveRelations(e, t) {
|
|
473
473
|
let r = [];
|
|
474
474
|
if (e.rel_uuids) {
|
|
475
|
-
const n = e.rel_uuids.length, o = [],
|
|
476
|
-
for (let
|
|
477
|
-
const c = Math.min(n,
|
|
478
|
-
o.push(e.rel_uuids.slice(
|
|
475
|
+
const n = e.rel_uuids.length, o = [], i = 50;
|
|
476
|
+
for (let a = 0; a < n; a += i) {
|
|
477
|
+
const c = Math.min(n, a + i);
|
|
478
|
+
o.push(e.rel_uuids.slice(a, c));
|
|
479
479
|
}
|
|
480
|
-
for (let
|
|
480
|
+
for (let a = 0; a < o.length; a++)
|
|
481
481
|
(await this.getStories({
|
|
482
|
-
per_page:
|
|
482
|
+
per_page: i,
|
|
483
483
|
language: t.language,
|
|
484
484
|
version: t.version,
|
|
485
|
-
by_uuids: o[
|
|
485
|
+
by_uuids: o[a].join(",")
|
|
486
486
|
})).data.stories.forEach((c) => {
|
|
487
487
|
r.push(c);
|
|
488
488
|
});
|
|
@@ -496,20 +496,20 @@ class Pe {
|
|
|
496
496
|
var r, n;
|
|
497
497
|
let o = [];
|
|
498
498
|
if (typeof t.resolve_relations < "u" && t.resolve_relations.length > 0 && (typeof t.resolve_relations == "string" && (o = t.resolve_relations.split(",")), await this.resolveRelations(e, t)), t.resolve_links && ["1", "story", "url"].indexOf(t.resolve_links) > -1 && ((r = e.links) != null && r.length || (n = e.link_uuids) != null && n.length) && await this.resolveLinks(e, t), this.resolveNestedRelations)
|
|
499
|
-
for (const
|
|
500
|
-
this.iterateTree(this.relations[
|
|
501
|
-
e.story ? this.iterateTree(e.story, o) : e.stories.forEach((
|
|
502
|
-
this.iterateTree(
|
|
499
|
+
for (const i in this.relations)
|
|
500
|
+
this.iterateTree(this.relations[i], o);
|
|
501
|
+
e.story ? this.iterateTree(e.story, o) : e.stories.forEach((i) => {
|
|
502
|
+
this.iterateTree(i, o);
|
|
503
503
|
});
|
|
504
504
|
}
|
|
505
505
|
async cacheResponse(e, t, r) {
|
|
506
506
|
const n = this.helpers.stringify({ url: e, params: t }), o = this.cacheProvider();
|
|
507
507
|
if (this.cache.clear === "auto" && t.version === "draft" && await this.flushCache(), t.version === "published" && e != "/cdn/spaces/me") {
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
510
|
-
return Promise.resolve(
|
|
508
|
+
const i = await o.get(n);
|
|
509
|
+
if (i)
|
|
510
|
+
return Promise.resolve(i);
|
|
511
511
|
}
|
|
512
|
-
return new Promise((
|
|
512
|
+
return new Promise((i, a) => {
|
|
513
513
|
try {
|
|
514
514
|
(async () => {
|
|
515
515
|
var c;
|
|
@@ -519,9 +519,9 @@ class Pe {
|
|
|
519
519
|
return (c = l.headers) != null && c["per-page"] && (u = Object.assign({}, u, {
|
|
520
520
|
perPage: l.headers["per-page"] ? parseInt(l.headers["per-page"]) : 0,
|
|
521
521
|
total: l.headers["per-page"] ? parseInt(l.headers.total) : 0
|
|
522
|
-
})), l.status != 200 ?
|
|
522
|
+
})), l.status != 200 ? a(l) : ((u.data.story || u.data.stories) && await this.resolveStories(u.data, t), t.version === "published" && e != "/cdn/spaces/me" && await o.set(n, u), u.data.cv && t.token && (t.version == "draft" && g[t.token] != u.data.cv && await this.flushCache(), g[t.token] = u.data.cv), i(u));
|
|
523
523
|
} catch (l) {
|
|
524
|
-
return
|
|
524
|
+
return a(l);
|
|
525
525
|
}
|
|
526
526
|
})();
|
|
527
527
|
} catch {
|
|
@@ -545,16 +545,16 @@ class Pe {
|
|
|
545
545
|
case "memory":
|
|
546
546
|
return {
|
|
547
547
|
get(e) {
|
|
548
|
-
return Promise.resolve(
|
|
548
|
+
return Promise.resolve(v[e]);
|
|
549
549
|
},
|
|
550
550
|
getAll() {
|
|
551
|
-
return Promise.resolve(
|
|
551
|
+
return Promise.resolve(v);
|
|
552
552
|
},
|
|
553
553
|
set(e, t) {
|
|
554
|
-
return
|
|
554
|
+
return v[e] = t, Promise.resolve(void 0);
|
|
555
555
|
},
|
|
556
556
|
flush() {
|
|
557
|
-
return
|
|
557
|
+
return v = {}, Promise.resolve(void 0);
|
|
558
558
|
}
|
|
559
559
|
};
|
|
560
560
|
case "custom":
|
|
@@ -581,7 +581,7 @@ class Pe {
|
|
|
581
581
|
return await this.cacheProvider().flush(), this;
|
|
582
582
|
}
|
|
583
583
|
}
|
|
584
|
-
const
|
|
584
|
+
const Xe = (s = {}) => {
|
|
585
585
|
const { apiOptions: e } = s;
|
|
586
586
|
if (!e.accessToken) {
|
|
587
587
|
console.error(
|
|
@@ -590,7 +590,7 @@ const We = (s = {}) => {
|
|
|
590
590
|
return;
|
|
591
591
|
}
|
|
592
592
|
return { storyblokApi: new Pe(e) };
|
|
593
|
-
},
|
|
593
|
+
}, Ee = (s) => {
|
|
594
594
|
if (typeof s != "object" || typeof s._editable > "u")
|
|
595
595
|
return {};
|
|
596
596
|
const e = JSON.parse(
|
|
@@ -602,32 +602,39 @@ const We = (s = {}) => {
|
|
|
602
602
|
};
|
|
603
603
|
};
|
|
604
604
|
let x;
|
|
605
|
-
const
|
|
606
|
-
|
|
605
|
+
const je = "https://app.storyblok.com/f/storyblok-v2-latest.js", Ze = (s, e, t = {}) => {
|
|
606
|
+
var r;
|
|
607
|
+
const n = !(typeof window > "u") && typeof window.storyblokRegisterEvent < "u", o = +new URL((r = window.location) == null ? void 0 : r.href).searchParams.get(
|
|
608
|
+
"_storyblok"
|
|
609
|
+
) === s;
|
|
610
|
+
if (!(!n || !o)) {
|
|
607
611
|
if (!s) {
|
|
608
612
|
console.warn("Story ID is not defined. Please provide a valid ID.");
|
|
609
613
|
return;
|
|
610
614
|
}
|
|
611
615
|
window.storyblokRegisterEvent(() => {
|
|
612
|
-
new window.StoryblokBridge(t).on(["input", "published", "change"], (
|
|
613
|
-
|
|
616
|
+
new window.StoryblokBridge(t).on(["input", "published", "change"], (i) => {
|
|
617
|
+
i.action === "input" && i.story.id === s ? e(i.story) : (i.action === "change" || i.action === "published") && i.storyId === s && window.location.reload();
|
|
614
618
|
});
|
|
615
619
|
});
|
|
616
620
|
}
|
|
617
621
|
}, Se = (s = {}) => {
|
|
622
|
+
var e, t;
|
|
618
623
|
const {
|
|
619
|
-
bridge:
|
|
620
|
-
accessToken:
|
|
621
|
-
use:
|
|
622
|
-
apiOptions:
|
|
623
|
-
richText:
|
|
624
|
+
bridge: r,
|
|
625
|
+
accessToken: n,
|
|
626
|
+
use: o = [],
|
|
627
|
+
apiOptions: i = {},
|
|
628
|
+
richText: a = {}
|
|
624
629
|
} = s;
|
|
625
|
-
|
|
626
|
-
const
|
|
627
|
-
let
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
})
|
|
630
|
+
i.accessToken = i.accessToken || n;
|
|
631
|
+
const c = { bridge: r, apiOptions: i };
|
|
632
|
+
let l = {};
|
|
633
|
+
o.forEach((d) => {
|
|
634
|
+
l = { ...l, ...d(c) };
|
|
635
|
+
});
|
|
636
|
+
const u = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
637
|
+
return r !== !1 && u && ee(je), x = new T(a.schema), a.resolver && G(x, a.resolver), l;
|
|
631
638
|
}, G = (s, e) => {
|
|
632
639
|
s.addNode("blok", (t) => {
|
|
633
640
|
let r = "";
|
|
@@ -637,7 +644,7 @@ const Ee = "https://app.storyblok.com/f/storyblok-v2-latest.js", Xe = (s, e, t =
|
|
|
637
644
|
html: r
|
|
638
645
|
};
|
|
639
646
|
});
|
|
640
|
-
},
|
|
647
|
+
}, et = (s, e, t) => {
|
|
641
648
|
let r = t || x;
|
|
642
649
|
if (!r) {
|
|
643
650
|
console.error(
|
|
@@ -651,7 +658,7 @@ const Ee = "https://app.storyblok.com/f/storyblok-v2-latest.js", Xe = (s, e, t =
|
|
|
651
658
|
};
|
|
652
659
|
function P() {
|
|
653
660
|
}
|
|
654
|
-
function
|
|
661
|
+
function E(s, e) {
|
|
655
662
|
for (const t in e)
|
|
656
663
|
s[t] = e[t];
|
|
657
664
|
return s;
|
|
@@ -662,7 +669,7 @@ function Q(s) {
|
|
|
662
669
|
function D() {
|
|
663
670
|
return /* @__PURE__ */ Object.create(null);
|
|
664
671
|
}
|
|
665
|
-
function
|
|
672
|
+
function b(s) {
|
|
666
673
|
s.forEach(Q);
|
|
667
674
|
}
|
|
668
675
|
function W(s) {
|
|
@@ -706,16 +713,18 @@ function J(s, e) {
|
|
|
706
713
|
return new s(e);
|
|
707
714
|
}
|
|
708
715
|
let N;
|
|
709
|
-
function
|
|
716
|
+
function _(s) {
|
|
710
717
|
N = s;
|
|
711
718
|
}
|
|
712
|
-
const y = [], F = []
|
|
713
|
-
let
|
|
719
|
+
const y = [], F = [];
|
|
720
|
+
let k = [];
|
|
721
|
+
const V = [], Ue = /* @__PURE__ */ Promise.resolve();
|
|
722
|
+
let j = !1;
|
|
714
723
|
function He() {
|
|
715
|
-
|
|
724
|
+
j || (j = !0, Ue.then(Z));
|
|
716
725
|
}
|
|
717
726
|
function S(s) {
|
|
718
|
-
|
|
727
|
+
k.push(s);
|
|
719
728
|
}
|
|
720
729
|
const R = /* @__PURE__ */ new Set();
|
|
721
730
|
let m = 0;
|
|
@@ -727,33 +736,37 @@ function Z() {
|
|
|
727
736
|
try {
|
|
728
737
|
for (; m < y.length; ) {
|
|
729
738
|
const e = y[m];
|
|
730
|
-
m++,
|
|
739
|
+
m++, _(e), qe(e.$$);
|
|
731
740
|
}
|
|
732
741
|
} catch (e) {
|
|
733
742
|
throw y.length = 0, m = 0, e;
|
|
734
743
|
}
|
|
735
|
-
for (
|
|
744
|
+
for (_(null), y.length = 0, m = 0; F.length; )
|
|
736
745
|
F.pop()();
|
|
737
|
-
for (let e = 0; e <
|
|
738
|
-
const t =
|
|
746
|
+
for (let e = 0; e < k.length; e += 1) {
|
|
747
|
+
const t = k[e];
|
|
739
748
|
R.has(t) || (R.add(t), t());
|
|
740
749
|
}
|
|
741
|
-
|
|
750
|
+
k.length = 0;
|
|
742
751
|
} while (y.length);
|
|
743
752
|
for (; V.length; )
|
|
744
753
|
V.pop()();
|
|
745
|
-
|
|
754
|
+
j = !1, R.clear(), _(s);
|
|
746
755
|
}
|
|
747
756
|
function qe(s) {
|
|
748
757
|
if (s.fragment !== null) {
|
|
749
|
-
s.update(),
|
|
758
|
+
s.update(), b(s.before_update);
|
|
750
759
|
const e = s.dirty;
|
|
751
760
|
s.dirty = [-1], s.fragment && s.fragment.p(s.ctx, e), s.after_update.forEach(S);
|
|
752
761
|
}
|
|
753
762
|
}
|
|
763
|
+
function De(s) {
|
|
764
|
+
const e = [], t = [];
|
|
765
|
+
k.forEach((r) => s.indexOf(r) === -1 ? e.push(r) : t.push(r)), t.forEach((r) => r()), k = e;
|
|
766
|
+
}
|
|
754
767
|
const w = /* @__PURE__ */ new Set();
|
|
755
768
|
let f;
|
|
756
|
-
function
|
|
769
|
+
function Be() {
|
|
757
770
|
f = {
|
|
758
771
|
r: 0,
|
|
759
772
|
c: [],
|
|
@@ -761,8 +774,8 @@ function De() {
|
|
|
761
774
|
// parent group
|
|
762
775
|
};
|
|
763
776
|
}
|
|
764
|
-
function
|
|
765
|
-
f.r ||
|
|
777
|
+
function Je() {
|
|
778
|
+
f.r || b(f.c), f = f.p;
|
|
766
779
|
}
|
|
767
780
|
function O(s, e) {
|
|
768
781
|
s && s.i && (w.delete(s), s.i(e));
|
|
@@ -777,26 +790,26 @@ function Y(s, e, t, r) {
|
|
|
777
790
|
} else
|
|
778
791
|
r && r();
|
|
779
792
|
}
|
|
780
|
-
function
|
|
793
|
+
function Fe(s, e) {
|
|
781
794
|
const t = {}, r = {}, n = { $$scope: 1 };
|
|
782
795
|
let o = s.length;
|
|
783
796
|
for (; o--; ) {
|
|
784
|
-
const
|
|
785
|
-
if (
|
|
786
|
-
for (const c in a)
|
|
787
|
-
c in i || (r[c] = 1);
|
|
797
|
+
const i = s[o], a = e[o];
|
|
798
|
+
if (a) {
|
|
788
799
|
for (const c in i)
|
|
789
|
-
|
|
790
|
-
s[o] = i;
|
|
791
|
-
} else
|
|
800
|
+
c in a || (r[c] = 1);
|
|
792
801
|
for (const c in a)
|
|
802
|
+
n[c] || (t[c] = a[c], n[c] = 1);
|
|
803
|
+
s[o] = a;
|
|
804
|
+
} else
|
|
805
|
+
for (const c in i)
|
|
793
806
|
n[c] = 1;
|
|
794
807
|
}
|
|
795
|
-
for (const
|
|
796
|
-
|
|
808
|
+
for (const i in r)
|
|
809
|
+
i in t || (t[i] = void 0);
|
|
797
810
|
return t;
|
|
798
811
|
}
|
|
799
|
-
function
|
|
812
|
+
function Ve(s) {
|
|
800
813
|
return typeof s == "object" && s !== null ? s : {};
|
|
801
814
|
}
|
|
802
815
|
function z(s) {
|
|
@@ -805,20 +818,20 @@ function z(s) {
|
|
|
805
818
|
function C(s, e, t, r) {
|
|
806
819
|
const { fragment: n, after_update: o } = s.$$;
|
|
807
820
|
n && n.m(e, t), r || S(() => {
|
|
808
|
-
const
|
|
809
|
-
s.$$.on_destroy ? s.$$.on_destroy.push(...
|
|
821
|
+
const i = s.$$.on_mount.map(Q).filter(W);
|
|
822
|
+
s.$$.on_destroy ? s.$$.on_destroy.push(...i) : b(i), s.$$.on_mount = [];
|
|
810
823
|
}), o.forEach(S);
|
|
811
824
|
}
|
|
812
825
|
function I(s, e) {
|
|
813
826
|
const t = s.$$;
|
|
814
|
-
t.fragment !== null && (
|
|
827
|
+
t.fragment !== null && (De(t.after_update), b(t.on_destroy), t.fragment && t.fragment.d(e), t.on_destroy = t.fragment = null, t.ctx = []);
|
|
815
828
|
}
|
|
816
|
-
function
|
|
829
|
+
function Ye(s, e) {
|
|
817
830
|
s.$$.dirty[0] === -1 && (y.push(s), He(), s.$$.dirty.fill(0)), s.$$.dirty[e / 31 | 0] |= 1 << e % 31;
|
|
818
831
|
}
|
|
819
|
-
function
|
|
832
|
+
function ze(s, e, t, r, n, o, i, a = [-1]) {
|
|
820
833
|
const c = N;
|
|
821
|
-
|
|
834
|
+
_(s);
|
|
822
835
|
const l = s.$$ = {
|
|
823
836
|
fragment: null,
|
|
824
837
|
ctx: [],
|
|
@@ -836,16 +849,16 @@ function Ye(s, e, t, r, n, o, a, i = [-1]) {
|
|
|
836
849
|
context: new Map(e.context || (c ? c.$$.context : [])),
|
|
837
850
|
// everything else
|
|
838
851
|
callbacks: D(),
|
|
839
|
-
dirty:
|
|
852
|
+
dirty: a,
|
|
840
853
|
skip_bound: !1,
|
|
841
854
|
root: e.target || c.$$.root
|
|
842
855
|
};
|
|
843
|
-
|
|
856
|
+
i && i(l.root);
|
|
844
857
|
let u = !1;
|
|
845
858
|
if (l.ctx = t ? t(s, e.props || {}, (d, p, ...M) => {
|
|
846
859
|
const L = M.length ? M[0] : p;
|
|
847
|
-
return l.ctx && n(l.ctx[d], l.ctx[d] = L) && (!l.skip_bound && l.bound[d] && l.bound[d](L), u &&
|
|
848
|
-
}) : [], l.update(), u = !0,
|
|
860
|
+
return l.ctx && n(l.ctx[d], l.ctx[d] = L) && (!l.skip_bound && l.bound[d] && l.bound[d](L), u && Ye(s, d)), p;
|
|
861
|
+
}) : [], l.update(), u = !0, b(l.before_update), l.fragment = r ? r(l.ctx) : !1, e.target) {
|
|
849
862
|
if (e.hydrate) {
|
|
850
863
|
const d = Le(e.target);
|
|
851
864
|
l.fragment && l.fragment.l(d), d.forEach(X);
|
|
@@ -853,9 +866,9 @@ function Ye(s, e, t, r, n, o, a, i = [-1]) {
|
|
|
853
866
|
l.fragment && l.fragment.c();
|
|
854
867
|
e.intro && O(s.$$.fragment), C(s, e.target, e.anchor, e.customElement), Z();
|
|
855
868
|
}
|
|
856
|
-
|
|
869
|
+
_(c);
|
|
857
870
|
}
|
|
858
|
-
class
|
|
871
|
+
class Ke {
|
|
859
872
|
$destroy() {
|
|
860
873
|
I(this, 1), this.$destroy = P;
|
|
861
874
|
}
|
|
@@ -872,7 +885,7 @@ class ze {
|
|
|
872
885
|
this.$$set && !Ce(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1);
|
|
873
886
|
}
|
|
874
887
|
}
|
|
875
|
-
function
|
|
888
|
+
function Ge(s) {
|
|
876
889
|
let e, t, r;
|
|
877
890
|
const n = [
|
|
878
891
|
{ blok: (
|
|
@@ -886,72 +899,73 @@ function Ke(s) {
|
|
|
886
899
|
/*component*/
|
|
887
900
|
s[1]
|
|
888
901
|
);
|
|
889
|
-
function a
|
|
902
|
+
function i(a) {
|
|
890
903
|
let c = {};
|
|
891
904
|
for (let l = 0; l < n.length; l += 1)
|
|
892
|
-
c =
|
|
905
|
+
c = E(c, n[l]);
|
|
893
906
|
return { props: c };
|
|
894
907
|
}
|
|
895
|
-
return o && (e = J(o,
|
|
908
|
+
return o && (e = J(o, i())), {
|
|
896
909
|
c() {
|
|
897
910
|
e && z(e.$$.fragment), t = Me();
|
|
898
911
|
},
|
|
899
|
-
m(
|
|
900
|
-
e && C(e,
|
|
912
|
+
m(a, c) {
|
|
913
|
+
e && C(e, a, c), Ae(a, t, c), r = !0;
|
|
901
914
|
},
|
|
902
|
-
p(
|
|
915
|
+
p(a, [c]) {
|
|
903
916
|
const l = c & /*blok, $$restProps*/
|
|
904
|
-
5 ?
|
|
917
|
+
5 ? Fe(n, [
|
|
905
918
|
c & /*blok*/
|
|
906
919
|
1 && { blok: (
|
|
907
920
|
/*blok*/
|
|
908
|
-
|
|
921
|
+
a[0]
|
|
909
922
|
) },
|
|
910
923
|
c & /*$$restProps*/
|
|
911
|
-
4 &&
|
|
924
|
+
4 && Ve(
|
|
912
925
|
/*$$restProps*/
|
|
913
|
-
|
|
926
|
+
a[2]
|
|
914
927
|
)
|
|
915
928
|
]) : {};
|
|
916
|
-
if (
|
|
917
|
-
|
|
929
|
+
if (c & /*component*/
|
|
930
|
+
2 && o !== (o = /*component*/
|
|
931
|
+
a[1])) {
|
|
918
932
|
if (e) {
|
|
919
|
-
|
|
933
|
+
Be();
|
|
920
934
|
const u = e;
|
|
921
935
|
Y(u.$$.fragment, 1, 0, () => {
|
|
922
936
|
I(u, 1);
|
|
923
|
-
}),
|
|
937
|
+
}), Je();
|
|
924
938
|
}
|
|
925
|
-
o ? (e = J(o,
|
|
939
|
+
o ? (e = J(o, i()), z(e.$$.fragment), O(e.$$.fragment, 1), C(e, t.parentNode, t)) : e = null;
|
|
926
940
|
} else
|
|
927
941
|
o && e.$set(l);
|
|
928
942
|
},
|
|
929
|
-
i(
|
|
930
|
-
r || (e && O(e.$$.fragment,
|
|
943
|
+
i(a) {
|
|
944
|
+
r || (e && O(e.$$.fragment, a), r = !0);
|
|
931
945
|
},
|
|
932
|
-
o(
|
|
933
|
-
e && Y(e.$$.fragment,
|
|
946
|
+
o(a) {
|
|
947
|
+
e && Y(e.$$.fragment, a), r = !1;
|
|
934
948
|
},
|
|
935
|
-
d(
|
|
936
|
-
|
|
949
|
+
d(a) {
|
|
950
|
+
a && X(t), e && I(e, a);
|
|
937
951
|
}
|
|
938
952
|
};
|
|
939
953
|
}
|
|
940
|
-
function
|
|
954
|
+
function Qe(s, e, t) {
|
|
941
955
|
const r = ["blok"];
|
|
942
|
-
let n = B(e, r), o, { blok:
|
|
943
|
-
return
|
|
944
|
-
e =
|
|
945
|
-
}, [
|
|
956
|
+
let n = B(e, r), o, { blok: i } = e;
|
|
957
|
+
return i ? o = We(i.component) : console.error("Please provide a 'blok' property to the StoryblokComponent"), s.$$set = (a) => {
|
|
958
|
+
e = E(E({}, e), Ie(a)), t(2, n = B(e, r)), "blok" in a && t(0, i = a.blok);
|
|
959
|
+
}, [i, o, n];
|
|
946
960
|
}
|
|
947
|
-
class
|
|
961
|
+
class tt extends Ke {
|
|
948
962
|
constructor(e) {
|
|
949
|
-
super(),
|
|
963
|
+
super(), ze(this, e, Qe, Ge, Oe, { blok: 0 });
|
|
950
964
|
}
|
|
951
965
|
}
|
|
952
|
-
const
|
|
966
|
+
const st = (s, e) => {
|
|
953
967
|
const t = (r) => {
|
|
954
|
-
const n =
|
|
968
|
+
const n = Ee(r);
|
|
955
969
|
n["data-blok-c"] && (s.setAttribute("data-blok-c", n["data-blok-c"]), s.setAttribute("data-blok-uid", n["data-blok-uid"]), s.classList.add("storyblok__outline"));
|
|
956
970
|
};
|
|
957
971
|
return t(e), {
|
|
@@ -961,14 +975,14 @@ const tt = (s, e) => {
|
|
|
961
975
|
};
|
|
962
976
|
};
|
|
963
977
|
let A = null;
|
|
964
|
-
const
|
|
978
|
+
const rt = () => (A || console.log(
|
|
965
979
|
"You can't use getStoryblokApi if you're not loading apiPlugin."
|
|
966
980
|
), A);
|
|
967
981
|
let $ = null;
|
|
968
|
-
const
|
|
982
|
+
const nt = (s) => {
|
|
969
983
|
const { storyblokApi: e } = Se(s);
|
|
970
984
|
A = e, $ = s.components || {};
|
|
971
|
-
},
|
|
985
|
+
}, We = (s) => {
|
|
972
986
|
let e = null;
|
|
973
987
|
return e = typeof $ == "function" ? $()[s] : $[s], e || console.error(`You didn't load the ${s} component. Please load it in storyblokInit. For example:
|
|
974
988
|
storyblokInit({
|
|
@@ -981,13 +995,13 @@ storyblokInit({
|
|
|
981
995
|
};
|
|
982
996
|
export {
|
|
983
997
|
Te as RichTextSchema,
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
998
|
+
tt as StoryblokComponent,
|
|
999
|
+
Xe as apiPlugin,
|
|
1000
|
+
We as getComponent,
|
|
1001
|
+
rt as getStoryblokApi,
|
|
1002
|
+
et as renderRichText,
|
|
1003
|
+
st as storyblokEditable,
|
|
1004
|
+
nt as storyblokInit,
|
|
1005
|
+
rt as useStoryblokApi,
|
|
1006
|
+
Ze as useStoryblokBridge
|
|
993
1007
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/svelte",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Storyblok SDK to connect Storyblok with Svelte",
|
|
6
6
|
"main": "./dist/storyblok-svelte.js",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@storyblok/js": "^2.
|
|
30
|
+
"@storyblok/js": "^2.1.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/core": "^7.21.
|
|
33
|
+
"@babel/core": "^7.21.3",
|
|
34
34
|
"@tsconfig/svelte": "^3.0.0",
|
|
35
35
|
"babel-jest": "^28.1.3",
|
|
36
36
|
"eslint-plugin-jest": "^27.2.0",
|
|
37
|
-
"jest": "^29.
|
|
38
|
-
"svelte-preprocess": "^5.0.
|
|
37
|
+
"jest": "^29.5.0",
|
|
38
|
+
"svelte-preprocess": "^5.0.2",
|
|
39
39
|
"typescript": "^4.9.5",
|
|
40
|
-
"vite": "^4.1.
|
|
40
|
+
"vite": "^4.1.4"
|
|
41
41
|
},
|
|
42
42
|
"eslintConfig": {
|
|
43
43
|
"env": {
|