@storyblok/svelte 2.4.8 → 2.4.10
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/{StoryblokComponent.svelte → dist/StoryblokComponent.svelte} +3 -2
- package/dist/StoryblokComponent.svelte.d.ts +18 -0
- package/dist/index.js +53 -0
- package/dist/types.js +1 -0
- package/package.json +17 -17
- package/dist/main.d.ts +0 -11
- package/dist/storyblok-svelte.js +0 -10
- package/dist/storyblok-svelte.mjs +0 -996
- package/dist/vite.config.d.ts +0 -2
- package/index.ts +0 -81
- package/types.ts +0 -35
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.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { SbBlokData } from "@storyblok/js";
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
blok: SbBlokData;
|
|
7
|
+
};
|
|
8
|
+
events: {
|
|
9
|
+
[evt: string]: CustomEvent<any>;
|
|
10
|
+
};
|
|
11
|
+
slots: {};
|
|
12
|
+
};
|
|
13
|
+
export type StoryblokComponentProps = typeof __propDef.props;
|
|
14
|
+
export type StoryblokComponentEvents = typeof __propDef.events;
|
|
15
|
+
export type StoryblokComponentSlots = typeof __propDef.slots;
|
|
16
|
+
export default class StoryblokComponent extends SvelteComponentTyped<StoryblokComponentProps, StoryblokComponentEvents, StoryblokComponentSlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { storyblokEditable as sbEdit, storyblokInit as sbInit, } from "@storyblok/js";
|
|
2
|
+
export { useStoryblokBridge, apiPlugin, renderRichText, RichTextSchema, } from "@storyblok/js";
|
|
3
|
+
export const storyblokEditable = (node, value) => {
|
|
4
|
+
const updateDom = (value) => {
|
|
5
|
+
const options = sbEdit(value);
|
|
6
|
+
if (options["data-blok-c"]) {
|
|
7
|
+
node.setAttribute("data-blok-c", options["data-blok-c"]);
|
|
8
|
+
node.setAttribute("data-blok-uid", options["data-blok-uid"]);
|
|
9
|
+
node.classList.add("storyblok__outline");
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
updateDom(value); // when is mounted
|
|
13
|
+
return {
|
|
14
|
+
update(newValue) {
|
|
15
|
+
// when value changes
|
|
16
|
+
updateDom(newValue);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
let storyblokApiInstance = null;
|
|
21
|
+
export const useStoryblokApi = () => {
|
|
22
|
+
if (!storyblokApiInstance) {
|
|
23
|
+
console.log(`You can't use getStoryblokApi if you're not loading apiPlugin.`);
|
|
24
|
+
}
|
|
25
|
+
return storyblokApiInstance;
|
|
26
|
+
};
|
|
27
|
+
export { useStoryblokApi as getStoryblokApi };
|
|
28
|
+
let componentsMap = null;
|
|
29
|
+
export const storyblokInit = (options) => {
|
|
30
|
+
const { storyblokApi } = sbInit(options);
|
|
31
|
+
storyblokApiInstance = storyblokApi;
|
|
32
|
+
componentsMap = options.components || {};
|
|
33
|
+
};
|
|
34
|
+
export const getComponent = (componentName) => {
|
|
35
|
+
let component = null;
|
|
36
|
+
component =
|
|
37
|
+
typeof componentsMap === "function"
|
|
38
|
+
? componentsMap()[componentName]
|
|
39
|
+
: componentsMap[componentName];
|
|
40
|
+
if (!component) {
|
|
41
|
+
console.error(`You didn't load the ${componentName} component. Please load it in storyblokInit. For example:
|
|
42
|
+
storyblokInit({
|
|
43
|
+
accessToken: "<your-token>",
|
|
44
|
+
components: {
|
|
45
|
+
"teaser": Teaser
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
`);
|
|
49
|
+
}
|
|
50
|
+
return component;
|
|
51
|
+
};
|
|
52
|
+
export * from "./types";
|
|
53
|
+
export { default as StoryblokComponent } from "./StoryblokComponent.svelte";
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { apiPlugin } from "@storyblok/js";
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/svelte",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Storyblok SDK to connect Storyblok with Svelte",
|
|
6
|
-
"main": "./dist/
|
|
7
|
-
"module": "./dist/
|
|
8
|
-
"svelte": "index.
|
|
9
|
-
"types": "./dist/
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"svelte": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
|
-
"
|
|
13
|
-
"types.ts",
|
|
14
|
-
"StoryblokComponent.svelte"
|
|
12
|
+
"README.md"
|
|
15
13
|
],
|
|
16
14
|
"exports": {
|
|
17
15
|
".": {
|
|
18
|
-
"import": "./dist/
|
|
19
|
-
"require": "./dist/
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.js"
|
|
20
18
|
}
|
|
21
19
|
},
|
|
22
20
|
"scripts": {
|
|
23
|
-
"dev": "
|
|
24
|
-
"build": "
|
|
21
|
+
"dev": "svelte-package -i pkg --watch",
|
|
22
|
+
"build": "svelte-package -i pkg",
|
|
25
23
|
"test": "npm run test:unit && npm run test:e2e",
|
|
26
24
|
"test:unit": "jest __tests__",
|
|
27
|
-
"prepublishOnly": "npm run build && cp ../README.md
|
|
25
|
+
"prepublishOnly": "npm run build && cp ../README.md ."
|
|
28
26
|
},
|
|
29
27
|
"dependencies": {
|
|
30
|
-
"@storyblok/js": "^2.1.0"
|
|
28
|
+
"@storyblok/js": "^2.1.0",
|
|
29
|
+
"svelte": "^3.0.0"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
32
|
"@babel/core": "^7.21.0",
|
|
33
|
+
"@sveltejs/package": "^2.0.2",
|
|
34
34
|
"@tsconfig/svelte": "^3.0.0",
|
|
35
|
-
"babel-jest": "^
|
|
35
|
+
"babel-jest": "^29",
|
|
36
36
|
"eslint-plugin-jest": "^27.2.0",
|
|
37
|
-
"jest": "^29.
|
|
37
|
+
"jest": "^29.5.0",
|
|
38
38
|
"svelte-preprocess": "^5.0.1",
|
|
39
|
-
"typescript": "^
|
|
39
|
+
"typescript": "^5.0.0",
|
|
40
40
|
"vite": "^4.1.4"
|
|
41
41
|
},
|
|
42
42
|
"eslintConfig": {
|
package/dist/main.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { SbBlokData } from './index'
|
|
2
|
-
import { SvelteComponentTyped} from 'svelte'
|
|
3
|
-
|
|
4
|
-
export * from "./index"
|
|
5
|
-
|
|
6
|
-
interface StoryblokComponentProps {
|
|
7
|
-
blok: SbBlokData;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export declare class StoryblokComponent extends SvelteComponentTyped<StoryblokComponentProps> {
|
|
11
|
-
}
|
package/dist/storyblok-svelte.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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.
|
|
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 _(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 n in s)!e.has(n)&&n[0]!=="$"&&(t[n]=s[n]);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 v(s){S=s}const y=[],G=[],T=[],Q=[],Fe=Promise.resolve();let O=!1;function Ve(){O||(O=!0,Fe.then(W))}function C(s){T.push(s)}const I=new Set;let k=0;function W(){if(k!==0)return;const s=S;do{try{for(;k<y.length;){const e=y[k];k++,v(e),Ye(e.$$)}}catch(e){throw y.length=0,k=0,e}for(v(null),y.length=0,k=0;G.length;)G.pop()();for(let e=0;e<T.length;e+=1){const t=T[e];I.has(t)||(I.add(t),t())}T.length=0}while(y.length);for(;Q.length;)Q.pop()();O=!1,I.clear(),v(s)}function Ye(s){if(s.fragment!==null){s.update(),_(s.before_update);const e=s.dirty;s.dirty=[-1],s.fragment&&s.fragment.p(s.ctx,e),s.after_update.forEach(C)}}const R=new Set;let p;function ze(){p={r:0,c:[],p}}function Ke(){p.r||_(p.c),p=p.p}function A(s,e){s&&s.i&&(R.delete(s),s.i(e))}function X(s,e,t,n){if(s&&s.o){if(R.has(s))return;R.add(s),p.c.push(()=>{R.delete(s),n&&(t&&s.d(1),n())}),s.o(e)}else n&&n()}function Ge(s,e){const t={},n={},r={$$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||(n[c]=1);for(const c in a)r[c]||(t[c]=a[c],r[c]=1);s[o]=a}else for(const c in i)r[c]=1}for(const i in n)i in t||(t[i]=void 0);return t}function Qe(s){return typeof s=="object"&&s!==null?s:{}}function Z(s){s&&s.c()}function N(s,e,t,n){const{fragment:r,after_update:o}=s.$$;r&&r.m(e,t),n||C(()=>{const i=s.$$.on_mount.map(J).filter(V);s.$$.on_destroy?s.$$.on_destroy.push(...i):_(i),s.$$.on_mount=[]}),o.forEach(C)}function M(s,e){const t=s.$$;t.fragment!==null&&(_(t.on_destroy),t.fragment&&t.fragment.d(e),t.on_destroy=t.fragment=null,t.ctx=[])}function We(s,e){s.$$.dirty[0]===-1&&(y.push(s),Ve(),s.$$.dirty.fill(0)),s.$$.dirty[e/31|0]|=1<<e%31}function Xe(s,e,t,n,r,o,i,a=[-1]){const c=S;v(s);const l=s.$$={fragment:null,ctx:[],props:o,update:x,not_equal:r,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 u=!1;if(l.ctx=t?t(s,e.props||{},(f,b,...se)=>{const ne=se.length?se[0]:b;return l.ctx&&r(l.ctx[f],l.ctx[f]=ne)&&(!l.skip_bound&&l.bound[f]&&l.bound[f](ne),u&&We(s,f)),b}):[],l.update(),u=!0,_(l.before_update),l.fragment=n?n(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()}v(c)}class Ze{$destroy(){M(this,1),this.$destroy=x}$on(e,t){if(!V(t))return x;const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(t),()=>{const r=n.indexOf(t);r!==-1&&n.splice(r,1)}}$set(e){this.$$set&&!Ue(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}function et(s){let e,t,n;const r=[{blok:s[0]},s[2]];var o=s[1];function i(a){let c={};for(let l=0;l<r.length;l+=1)c=E(c,r[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),n=!0},p(a,[c]){const l=c&5?Ge(r,[c&1&&{blok:a[0]},c&4&&Qe(a[2])]):{};if(o!==(o=a[1])){if(e){ze();const u=e;X(u.$$.fragment,1,0,()=>{M(u,1)}),Ke()}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){n||(e&&A(e.$$.fragment,a),n=!0)},o(a){e&&X(e.$$.fragment,a),n=!1},d(a){a&&z(t),e&&M(e,a)}}}function tt(s,e,t){const n=["blok"];let r=Y(e,n),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,r=Y(e,n)),"blok"in a&&t(0,i=a.blok)},[i,o,r]}class st extends Ze{constructor(e){super(),Xe(this,e,tt,et,Le,{blok:0})}}const nt=(s,e)=>{const t=n=>{const r=Ce(n);r["data-blok-c"]&&(s.setAttribute("data-blok-c",r["data-blok-c"]),s.setAttribute("data-blok-uid",r["data-blok-uid"]),s.classList.add("storyblok__outline"))};return t(e),{update(n){t(n)}}};let L=null;const ee=()=>(L||console.log("You can't use getStoryblokApi if you're not loading apiPlugin."),L);let j=null;const rt=s=>{const{storyblokApi:e}=Ne(s);L=e,j=s.components||{}},te=s=>{let e=null;return e=typeof j=="function"?j()[s]:j[s],e||console.error(`You didn't load the ${s} component. Please load it in storyblokInit. For example:
|
|
4
|
-
storyblokInit({
|
|
5
|
-
accessToken: "<your-token>",
|
|
6
|
-
components: {
|
|
7
|
-
"teaser": Teaser
|
|
8
|
-
}
|
|
9
|
-
})
|
|
10
|
-
`),e};d.RichTextSchema=q,d.StoryblokComponent=st,d.apiPlugin=Oe,d.getComponent=te,d.getStoryblokApi=ee,d.renderRichText=Me,d.storyblokEditable=nt,d.storyblokInit=rt,d.useStoryblokApi=ee,d.useStoryblokBridge=Ae,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|