@storyblok/svelte 2.4.8 → 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 +78 -67
- package/package.json +5 -5
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 i=function(){o++;const c=setTimeout(function(){o--,n.length>0&&i(),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))},a=function(...c){const l=this;return new Promise(function(u,f){n.push({resolve:u,reject:f,args:c,self:l}),o<e&&i()})};return a.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},a}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 i=n.attrs[o];i!==null&&(r+=` ${o}="${i}"`)}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,i)=>i*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 i=e[o],a=n?"":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),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:i}=o;let a;this.timeout&&(a=setTimeout(()=>o.abort(),this.timeout));try{const c=await this.fetch(`${r}`,{method:e,headers:this.headers,body:n,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((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}`:"",i=e.https===!1?"http":"https";e.oauthToken?t=`${i}://api${o}.storyblok.com/v1`:t=`${i}://api${o}.storyblok.com/v2`}const n=new Headers;n.set("Content-Type","application/json"),n.set("Accept","application/json"),n.forEach((o,i)=>{e.headers&&e.headers[i]&&n.set(i,e.headers[i])});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}`,i=o.split("/"),a=n||i[i.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[a]))}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=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,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=>{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=[],i=50;for(let a=0;a<r;a+=i){const c=Math.min(r,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=>{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 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,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 i=await o.get(r);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 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?a(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),i(u))}catch(l){return a(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={})=>{var e,t;const{bridge:n,accessToken:r,use:o=[],apiOptions:i={},richText:a={}}=s;i.accessToken=i.accessToken||r;const c={bridge:n,apiOptions:i};let l={};o.forEach(f=>{l={...l,...f(c)}});const u=!(typeof window>"u")&&((t=(e=window.location)==null?void 0:e.search)==null?void 0:t.includes("_storyblok_tk"));return n!==!1&&u&&re(Ie),P=new w(a.schema),a.resolver&&B(P,a.resolver),l},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"})});
|
|
@@ -322,7 +322,7 @@ 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) {
|
|
@@ -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,15 +602,19 @@ 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
|
}
|
|
@@ -630,7 +634,7 @@ const Ee = "https://app.storyblok.com/f/storyblok-v2-latest.js", Xe = (s, e, t =
|
|
|
630
634
|
l = { ...l, ...d(c) };
|
|
631
635
|
});
|
|
632
636
|
const u = !(typeof window > "u") && ((t = (e = window.location) == null ? void 0 : e.search) == null ? void 0 : t.includes("_storyblok_tk"));
|
|
633
|
-
return r !== !1 && u && ee(
|
|
637
|
+
return r !== !1 && u && ee(je), x = new T(a.schema), a.resolver && G(x, a.resolver), l;
|
|
634
638
|
}, G = (s, e) => {
|
|
635
639
|
s.addNode("blok", (t) => {
|
|
636
640
|
let r = "";
|
|
@@ -640,7 +644,7 @@ const Ee = "https://app.storyblok.com/f/storyblok-v2-latest.js", Xe = (s, e, t =
|
|
|
640
644
|
html: r
|
|
641
645
|
};
|
|
642
646
|
});
|
|
643
|
-
},
|
|
647
|
+
}, et = (s, e, t) => {
|
|
644
648
|
let r = t || x;
|
|
645
649
|
if (!r) {
|
|
646
650
|
console.error(
|
|
@@ -654,7 +658,7 @@ const Ee = "https://app.storyblok.com/f/storyblok-v2-latest.js", Xe = (s, e, t =
|
|
|
654
658
|
};
|
|
655
659
|
function P() {
|
|
656
660
|
}
|
|
657
|
-
function
|
|
661
|
+
function E(s, e) {
|
|
658
662
|
for (const t in e)
|
|
659
663
|
s[t] = e[t];
|
|
660
664
|
return s;
|
|
@@ -665,7 +669,7 @@ function Q(s) {
|
|
|
665
669
|
function D() {
|
|
666
670
|
return /* @__PURE__ */ Object.create(null);
|
|
667
671
|
}
|
|
668
|
-
function
|
|
672
|
+
function b(s) {
|
|
669
673
|
s.forEach(Q);
|
|
670
674
|
}
|
|
671
675
|
function W(s) {
|
|
@@ -709,16 +713,18 @@ function J(s, e) {
|
|
|
709
713
|
return new s(e);
|
|
710
714
|
}
|
|
711
715
|
let N;
|
|
712
|
-
function
|
|
716
|
+
function _(s) {
|
|
713
717
|
N = s;
|
|
714
718
|
}
|
|
715
|
-
const y = [], F = []
|
|
716
|
-
let
|
|
719
|
+
const y = [], F = [];
|
|
720
|
+
let k = [];
|
|
721
|
+
const V = [], Ue = /* @__PURE__ */ Promise.resolve();
|
|
722
|
+
let j = !1;
|
|
717
723
|
function He() {
|
|
718
|
-
|
|
724
|
+
j || (j = !0, Ue.then(Z));
|
|
719
725
|
}
|
|
720
726
|
function S(s) {
|
|
721
|
-
|
|
727
|
+
k.push(s);
|
|
722
728
|
}
|
|
723
729
|
const R = /* @__PURE__ */ new Set();
|
|
724
730
|
let m = 0;
|
|
@@ -730,33 +736,37 @@ function Z() {
|
|
|
730
736
|
try {
|
|
731
737
|
for (; m < y.length; ) {
|
|
732
738
|
const e = y[m];
|
|
733
|
-
m++,
|
|
739
|
+
m++, _(e), qe(e.$$);
|
|
734
740
|
}
|
|
735
741
|
} catch (e) {
|
|
736
742
|
throw y.length = 0, m = 0, e;
|
|
737
743
|
}
|
|
738
|
-
for (
|
|
744
|
+
for (_(null), y.length = 0, m = 0; F.length; )
|
|
739
745
|
F.pop()();
|
|
740
|
-
for (let e = 0; e <
|
|
741
|
-
const t =
|
|
746
|
+
for (let e = 0; e < k.length; e += 1) {
|
|
747
|
+
const t = k[e];
|
|
742
748
|
R.has(t) || (R.add(t), t());
|
|
743
749
|
}
|
|
744
|
-
|
|
750
|
+
k.length = 0;
|
|
745
751
|
} while (y.length);
|
|
746
752
|
for (; V.length; )
|
|
747
753
|
V.pop()();
|
|
748
|
-
|
|
754
|
+
j = !1, R.clear(), _(s);
|
|
749
755
|
}
|
|
750
756
|
function qe(s) {
|
|
751
757
|
if (s.fragment !== null) {
|
|
752
|
-
s.update(),
|
|
758
|
+
s.update(), b(s.before_update);
|
|
753
759
|
const e = s.dirty;
|
|
754
760
|
s.dirty = [-1], s.fragment && s.fragment.p(s.ctx, e), s.after_update.forEach(S);
|
|
755
761
|
}
|
|
756
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
|
+
}
|
|
757
767
|
const w = /* @__PURE__ */ new Set();
|
|
758
768
|
let f;
|
|
759
|
-
function
|
|
769
|
+
function Be() {
|
|
760
770
|
f = {
|
|
761
771
|
r: 0,
|
|
762
772
|
c: [],
|
|
@@ -764,8 +774,8 @@ function De() {
|
|
|
764
774
|
// parent group
|
|
765
775
|
};
|
|
766
776
|
}
|
|
767
|
-
function
|
|
768
|
-
f.r ||
|
|
777
|
+
function Je() {
|
|
778
|
+
f.r || b(f.c), f = f.p;
|
|
769
779
|
}
|
|
770
780
|
function O(s, e) {
|
|
771
781
|
s && s.i && (w.delete(s), s.i(e));
|
|
@@ -780,7 +790,7 @@ function Y(s, e, t, r) {
|
|
|
780
790
|
} else
|
|
781
791
|
r && r();
|
|
782
792
|
}
|
|
783
|
-
function
|
|
793
|
+
function Fe(s, e) {
|
|
784
794
|
const t = {}, r = {}, n = { $$scope: 1 };
|
|
785
795
|
let o = s.length;
|
|
786
796
|
for (; o--; ) {
|
|
@@ -799,7 +809,7 @@ function Je(s, e) {
|
|
|
799
809
|
i in t || (t[i] = void 0);
|
|
800
810
|
return t;
|
|
801
811
|
}
|
|
802
|
-
function
|
|
812
|
+
function Ve(s) {
|
|
803
813
|
return typeof s == "object" && s !== null ? s : {};
|
|
804
814
|
}
|
|
805
815
|
function z(s) {
|
|
@@ -809,19 +819,19 @@ function C(s, e, t, r) {
|
|
|
809
819
|
const { fragment: n, after_update: o } = s.$$;
|
|
810
820
|
n && n.m(e, t), r || S(() => {
|
|
811
821
|
const i = s.$$.on_mount.map(Q).filter(W);
|
|
812
|
-
s.$$.on_destroy ? s.$$.on_destroy.push(...i) :
|
|
822
|
+
s.$$.on_destroy ? s.$$.on_destroy.push(...i) : b(i), s.$$.on_mount = [];
|
|
813
823
|
}), o.forEach(S);
|
|
814
824
|
}
|
|
815
825
|
function I(s, e) {
|
|
816
826
|
const t = s.$$;
|
|
817
|
-
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 = []);
|
|
818
828
|
}
|
|
819
|
-
function
|
|
829
|
+
function Ye(s, e) {
|
|
820
830
|
s.$$.dirty[0] === -1 && (y.push(s), He(), s.$$.dirty.fill(0)), s.$$.dirty[e / 31 | 0] |= 1 << e % 31;
|
|
821
831
|
}
|
|
822
|
-
function
|
|
832
|
+
function ze(s, e, t, r, n, o, i, a = [-1]) {
|
|
823
833
|
const c = N;
|
|
824
|
-
|
|
834
|
+
_(s);
|
|
825
835
|
const l = s.$$ = {
|
|
826
836
|
fragment: null,
|
|
827
837
|
ctx: [],
|
|
@@ -847,8 +857,8 @@ function Ye(s, e, t, r, n, o, i, a = [-1]) {
|
|
|
847
857
|
let u = !1;
|
|
848
858
|
if (l.ctx = t ? t(s, e.props || {}, (d, p, ...M) => {
|
|
849
859
|
const L = M.length ? M[0] : p;
|
|
850
|
-
return l.ctx && n(l.ctx[d], l.ctx[d] = L) && (!l.skip_bound && l.bound[d] && l.bound[d](L), u &&
|
|
851
|
-
}) : [], 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) {
|
|
852
862
|
if (e.hydrate) {
|
|
853
863
|
const d = Le(e.target);
|
|
854
864
|
l.fragment && l.fragment.l(d), d.forEach(X);
|
|
@@ -856,9 +866,9 @@ function Ye(s, e, t, r, n, o, i, a = [-1]) {
|
|
|
856
866
|
l.fragment && l.fragment.c();
|
|
857
867
|
e.intro && O(s.$$.fragment), C(s, e.target, e.anchor, e.customElement), Z();
|
|
858
868
|
}
|
|
859
|
-
|
|
869
|
+
_(c);
|
|
860
870
|
}
|
|
861
|
-
class
|
|
871
|
+
class Ke {
|
|
862
872
|
$destroy() {
|
|
863
873
|
I(this, 1), this.$destroy = P;
|
|
864
874
|
}
|
|
@@ -875,7 +885,7 @@ class ze {
|
|
|
875
885
|
this.$$set && !Ce(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1);
|
|
876
886
|
}
|
|
877
887
|
}
|
|
878
|
-
function
|
|
888
|
+
function Ge(s) {
|
|
879
889
|
let e, t, r;
|
|
880
890
|
const n = [
|
|
881
891
|
{ blok: (
|
|
@@ -892,7 +902,7 @@ function Ke(s) {
|
|
|
892
902
|
function i(a) {
|
|
893
903
|
let c = {};
|
|
894
904
|
for (let l = 0; l < n.length; l += 1)
|
|
895
|
-
c =
|
|
905
|
+
c = E(c, n[l]);
|
|
896
906
|
return { props: c };
|
|
897
907
|
}
|
|
898
908
|
return o && (e = J(o, i())), {
|
|
@@ -904,26 +914,27 @@ function Ke(s) {
|
|
|
904
914
|
},
|
|
905
915
|
p(a, [c]) {
|
|
906
916
|
const l = c & /*blok, $$restProps*/
|
|
907
|
-
5 ?
|
|
917
|
+
5 ? Fe(n, [
|
|
908
918
|
c & /*blok*/
|
|
909
919
|
1 && { blok: (
|
|
910
920
|
/*blok*/
|
|
911
921
|
a[0]
|
|
912
922
|
) },
|
|
913
923
|
c & /*$$restProps*/
|
|
914
|
-
4 &&
|
|
924
|
+
4 && Ve(
|
|
915
925
|
/*$$restProps*/
|
|
916
926
|
a[2]
|
|
917
927
|
)
|
|
918
928
|
]) : {};
|
|
919
|
-
if (
|
|
929
|
+
if (c & /*component*/
|
|
930
|
+
2 && o !== (o = /*component*/
|
|
920
931
|
a[1])) {
|
|
921
932
|
if (e) {
|
|
922
|
-
|
|
933
|
+
Be();
|
|
923
934
|
const u = e;
|
|
924
935
|
Y(u.$$.fragment, 1, 0, () => {
|
|
925
936
|
I(u, 1);
|
|
926
|
-
}),
|
|
937
|
+
}), Je();
|
|
927
938
|
}
|
|
928
939
|
o ? (e = J(o, i()), z(e.$$.fragment), O(e.$$.fragment, 1), C(e, t.parentNode, t)) : e = null;
|
|
929
940
|
} else
|
|
@@ -940,21 +951,21 @@ function Ke(s) {
|
|
|
940
951
|
}
|
|
941
952
|
};
|
|
942
953
|
}
|
|
943
|
-
function
|
|
954
|
+
function Qe(s, e, t) {
|
|
944
955
|
const r = ["blok"];
|
|
945
956
|
let n = B(e, r), o, { blok: i } = e;
|
|
946
|
-
return i ? o =
|
|
947
|
-
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);
|
|
948
959
|
}, [i, o, n];
|
|
949
960
|
}
|
|
950
|
-
class
|
|
961
|
+
class tt extends Ke {
|
|
951
962
|
constructor(e) {
|
|
952
|
-
super(),
|
|
963
|
+
super(), ze(this, e, Qe, Ge, Oe, { blok: 0 });
|
|
953
964
|
}
|
|
954
965
|
}
|
|
955
|
-
const
|
|
966
|
+
const st = (s, e) => {
|
|
956
967
|
const t = (r) => {
|
|
957
|
-
const n =
|
|
968
|
+
const n = Ee(r);
|
|
958
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"));
|
|
959
970
|
};
|
|
960
971
|
return t(e), {
|
|
@@ -964,14 +975,14 @@ const tt = (s, e) => {
|
|
|
964
975
|
};
|
|
965
976
|
};
|
|
966
977
|
let A = null;
|
|
967
|
-
const
|
|
978
|
+
const rt = () => (A || console.log(
|
|
968
979
|
"You can't use getStoryblokApi if you're not loading apiPlugin."
|
|
969
980
|
), A);
|
|
970
981
|
let $ = null;
|
|
971
|
-
const
|
|
982
|
+
const nt = (s) => {
|
|
972
983
|
const { storyblokApi: e } = Se(s);
|
|
973
984
|
A = e, $ = s.components || {};
|
|
974
|
-
},
|
|
985
|
+
}, We = (s) => {
|
|
975
986
|
let e = null;
|
|
976
987
|
return e = typeof $ == "function" ? $()[s] : $[s], e || console.error(`You didn't load the ${s} component. Please load it in storyblokInit. For example:
|
|
977
988
|
storyblokInit({
|
|
@@ -984,13 +995,13 @@ storyblokInit({
|
|
|
984
995
|
};
|
|
985
996
|
export {
|
|
986
997
|
Te as RichTextSchema,
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
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
|
|
996
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,15 +27,15 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build && cp ../README.md ./"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@storyblok/js": "^2.1.
|
|
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
40
|
"vite": "^4.1.4"
|
|
41
41
|
},
|