@storyblok/svelte 4.0.11 → 5.0.1
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/LICENSE +21 -0
- package/README.md +51 -46
- package/dist/StoryblokComponent.svelte +10 -9
- package/dist/StoryblokComponent.svelte.d.ts +10 -24
- package/dist/index.d.ts +4 -11
- package/dist/index.js +4 -53
- package/dist/storyblok-store.d.ts +2 -0
- package/dist/storyblok-store.js +52 -0
- package/dist/storyblok.d.ts +12 -0
- package/dist/storyblok.js +45 -0
- package/dist/types.d.ts +4 -5
- package/dist/types.js +1 -1
- package/package.json +92 -61
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Storyblok GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -10,15 +10,12 @@
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
12
|
<p align="center">
|
|
13
|
-
<a href="https://www.npmjs.com/package/@storyblok/svelte">
|
|
14
|
-
|
|
15
|
-
</a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@storyblok/svelte"><img src="https://img.shields.io/npm/v/@storyblok/svelte/latest.svg?style=flat-square" alt="npm package" /></a>
|
|
14
|
+
<img src="https://img.shields.io/badge/Svelte-5.x%20Ready-FF3E00?style=flat-square&logo=svelte" alt="Svelte 5 Ready" />
|
|
16
15
|
</p>
|
|
17
16
|
|
|
18
17
|
<p align="center">
|
|
19
|
-
<a href="https://discord.gg/jKrbAMz">
|
|
20
|
-
<img src="https://img.shields.io/discord/700316478792138842?label=Join%20Our%20Discord%20Community&style=appveyor&logo=discord&color=09b3af">
|
|
21
|
-
</a>
|
|
18
|
+
<a href="https://discord.gg/jKrbAMz"><img src="https://img.shields.io/discord/700316478792138842?label=Join%20Our%20Discord%20Community&style=appveyor&logo=discord&color=09b3af"></a>
|
|
22
19
|
<a href="https://twitter.com/intent/follow?screen_name=storyblok">
|
|
23
20
|
<img src="https://img.shields.io/badge/Follow-%40storyblok-09b3af?style=appveyor&logo=twitter" alt="Follow @Storyblok" />
|
|
24
21
|
</a>
|
|
@@ -30,7 +27,7 @@
|
|
|
30
27
|
</p>
|
|
31
28
|
|
|
32
29
|
## Kickstart a new project
|
|
33
|
-
Are you eager to dive into coding? **[Follow these steps to kickstart a new project with Storyblok and Svelte](https://www.storyblok.com/technologies
|
|
30
|
+
Are you eager to dive into coding? **[Follow these steps to kickstart a new project with Storyblok and Svelte](https://www.storyblok.com/technologies?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte#sveltekit)**, and get started in just a few minutes!
|
|
34
31
|
|
|
35
32
|
## Ultimate Tutorial
|
|
36
33
|
Are you looking for a hands-on, step-by-step tutorial? The **[SvelteKit Ultimate Tutorial](https://www.storyblok.com/tp/the-storyblok-sveltekit-ultimate-tutorial?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte)** has you covered! It provides comprehensive instructions on building a complete, multilingual website using Storyblok and SvelteKit from start to finish.
|
|
@@ -39,10 +36,16 @@ Are you looking for a hands-on, step-by-step tutorial? The **[SvelteKit Ultimate
|
|
|
39
36
|
|
|
40
37
|
| Version to install | Support |
|
|
41
38
|
| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
|
|
42
|
-
| Latest (from v3) `@storyblok/svelte` | Modern browsers + Node 18+
|
|
39
|
+
| Latest (from v3) `@storyblok/svelte` | Modern browsers + Node 18+ (Compatible with Svelte 5)|
|
|
43
40
|
| Latest (from v3) `@storyblok/svelte` <br> + Fetch polyfill like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch) | Browsers and Node versions with no Fetch API support |
|
|
44
41
|
| [Version 2](https://github.com/storyblok/@storyblok/svelte/tree/v2.5.0) `@storyblok/svelte@2` | Internet Explorer support |
|
|
45
42
|
|
|
43
|
+
### Upgrading to Svelte 5
|
|
44
|
+
|
|
45
|
+
We recommend upgrading to Svelte 5 for the latest features and improvements. The latest version of `@storyblok/svelte` is fully compatible with Svelte 5.
|
|
46
|
+
|
|
47
|
+
If you're migrating from Svelte 3/4 to Svelte 5, please follow the [official Svelte migration guide](https://svelte.dev/docs/svelte/v5-migration-guide) and then ensure you're using the latest version of `@storyblok/svelte`.
|
|
48
|
+
|
|
46
49
|
## Usage
|
|
47
50
|
|
|
48
51
|
`@storyblok/svelte` helps you connect your Svelte project to Storyblok by:
|
|
@@ -59,16 +62,14 @@ Install `@storyblok/svelte`
|
|
|
59
62
|
npm install @storyblok/svelte
|
|
60
63
|
```
|
|
61
64
|
|
|
62
|
-
Please note that you have to use `npm` - unfortunately, we are currently not supporting `yarn` or `pnpm` for this SDK.
|
|
63
|
-
|
|
64
65
|
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:
|
|
65
66
|
|
|
66
67
|
```js
|
|
67
|
-
import App from
|
|
68
|
-
import {
|
|
68
|
+
import App from './App.svelte';
|
|
69
|
+
import { apiPlugin, storyblokInit } from '@storyblok/svelte';
|
|
69
70
|
|
|
70
71
|
storyblokInit({
|
|
71
|
-
accessToken:
|
|
72
|
+
accessToken: '<your-token>',
|
|
72
73
|
// bridge: false,
|
|
73
74
|
use: [apiPlugin],
|
|
74
75
|
|
|
@@ -78,7 +79,9 @@ storyblokInit({
|
|
|
78
79
|
});
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
The best place to initialize the Storyblok 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`.
|
|
82
|
+
The best place to initialize the Storyblok library is in the `main.(ts|js).` or `main.(ts|js)` file if you are using `svelte` or in the `load()` function in the `src/routes/+layout.(ts|js)` file if you are using `SvelteKit`.
|
|
83
|
+
|
|
84
|
+
You can find a good example with SvelteKit in the `playground` folder.
|
|
82
85
|
|
|
83
86
|
List all your components to the components object in the storyblokInit function. You can load all of them by adding them to the list.
|
|
84
87
|
|
|
@@ -114,12 +117,12 @@ Use the `getStoryblokApi`()` to get your stories from the Storyblok CDN API:
|
|
|
114
117
|
|
|
115
118
|
```html
|
|
116
119
|
<script>
|
|
117
|
-
import { onMount } from
|
|
118
|
-
import { getStoryblokApi } from
|
|
120
|
+
import { onMount } from 'svelte';
|
|
121
|
+
import { getStoryblokApi } from '@storyblok/svelte';
|
|
119
122
|
onMount(async () => {
|
|
120
123
|
const storyblokApi = getStoryblokApi();
|
|
121
|
-
const { data } = await storyblokApi.get(
|
|
122
|
-
version:
|
|
124
|
+
const { data } = await storyblokApi.get('cdn/stories/home', {
|
|
125
|
+
version: 'draft',
|
|
123
126
|
});
|
|
124
127
|
});
|
|
125
128
|
</script>
|
|
@@ -134,13 +137,13 @@ Use `useStoryBridge` to get the updated story every time a change event is trigg
|
|
|
134
137
|
|
|
135
138
|
```html
|
|
136
139
|
<script>
|
|
137
|
-
import { onMount } from
|
|
138
|
-
import { getStoryblokApi, useStoryblokBridge } from
|
|
140
|
+
import { onMount } from 'svelte';
|
|
141
|
+
import { getStoryblokApi, useStoryblokBridge } from '@storyblok/svelte';
|
|
139
142
|
let story = null;
|
|
140
143
|
onMount(async () => {
|
|
141
144
|
const storyblokApi = getStoryblokApi();
|
|
142
|
-
const { data } = await storyblokApi.get(
|
|
143
|
-
version:
|
|
145
|
+
const { data } = await storyblokApi.get('cdn/stories/home', {
|
|
146
|
+
version: 'draft',
|
|
144
147
|
});
|
|
145
148
|
story = data.story;
|
|
146
149
|
useStoryblokBridge(story.id, (newStory) => (story = newStory));
|
|
@@ -151,9 +154,9 @@ Use `useStoryBridge` to get the updated story every time a change event is trigg
|
|
|
151
154
|
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:
|
|
152
155
|
|
|
153
156
|
```js
|
|
154
|
-
useStoryblokBridge(story.id,
|
|
155
|
-
resolveRelations: [
|
|
156
|
-
resolveLinks:
|
|
157
|
+
useStoryblokBridge(story.id, newStory => (story = newStory), {
|
|
158
|
+
resolveRelations: ['Article.author'],
|
|
159
|
+
resolveLinks: 'url',
|
|
157
160
|
});
|
|
158
161
|
```
|
|
159
162
|
|
|
@@ -172,7 +175,7 @@ To link the Storyblok components, you have to
|
|
|
172
175
|
- Use the `StoryblokComponent` to load them by passing the `blok` property
|
|
173
176
|
|
|
174
177
|
```html
|
|
175
|
-
<StoryblokComponent {blok} />
|
|
178
|
+
<StoryblokComponent blok={blok} />
|
|
176
179
|
```
|
|
177
180
|
|
|
178
181
|
> The `blok` is the actual blok data coming from [Storyblok's Content Delivery API](https://www.storyblok.com/docs/api/content-delivery/v2?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte).
|
|
@@ -187,10 +190,10 @@ You can use an `apiOptions` object. This is passed down to the [storyblok-js-cli
|
|
|
187
190
|
|
|
188
191
|
```js
|
|
189
192
|
storyblokInit({
|
|
190
|
-
accessToken:
|
|
193
|
+
accessToken: '<your-token>',
|
|
191
194
|
apiOptions: {
|
|
192
|
-
//storyblok-js-client config object
|
|
193
|
-
cache: { type:
|
|
195
|
+
// storyblok-js-client config object
|
|
196
|
+
cache: { type: 'memory' },
|
|
194
197
|
},
|
|
195
198
|
use: [apiPlugin],
|
|
196
199
|
});
|
|
@@ -204,7 +207,7 @@ You can conditionally load it by using the `bridge` option. Very useful if you w
|
|
|
204
207
|
|
|
205
208
|
```js
|
|
206
209
|
storyblokInit({
|
|
207
|
-
bridge: process.env.NODE_ENV !==
|
|
210
|
+
bridge: process.env.NODE_ENV !== 'production',
|
|
208
211
|
});
|
|
209
212
|
```
|
|
210
213
|
|
|
@@ -212,7 +215,7 @@ Keep in mind you have still access to the raw `window.StoryblokBridge`:
|
|
|
212
215
|
|
|
213
216
|
```js
|
|
214
217
|
const sbBridge = new window.StoryblokBridge(options);
|
|
215
|
-
sbBridge.on([
|
|
218
|
+
sbBridge.on(['input', 'published', 'change'], (event) => {
|
|
216
219
|
// ...
|
|
217
220
|
});
|
|
218
221
|
```
|
|
@@ -225,9 +228,11 @@ You can easily render rich text by using the `renderRichText` function that come
|
|
|
225
228
|
|
|
226
229
|
```html
|
|
227
230
|
<script>
|
|
228
|
-
import { renderRichText } from
|
|
231
|
+
import { renderRichText } from '@storyblok/svelte';
|
|
232
|
+
|
|
233
|
+
let articleHTML = $derived(renderRichText(blok.article));
|
|
234
|
+
|
|
229
235
|
export let blok;
|
|
230
|
-
$: articleHTML = renderRichText(blok.article);
|
|
231
236
|
</script>
|
|
232
237
|
|
|
233
238
|
<div class="prose">{@html articleHTML}</div>
|
|
@@ -243,21 +248,21 @@ npm i clone-deep
|
|
|
243
248
|
You can set a **custom Schema and component resolver globally** at init time by using the `richText` init option:
|
|
244
249
|
|
|
245
250
|
```js
|
|
246
|
-
import { RichTextSchema, storyblokInit } from
|
|
247
|
-
import cloneDeep from
|
|
251
|
+
import { RichTextSchema, storyblokInit } from '@storyblok/svelte';
|
|
252
|
+
import cloneDeep from 'clone-deep';
|
|
248
253
|
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
|
|
249
254
|
// ... and edit the nodes and marks, or add your own.
|
|
250
255
|
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js
|
|
251
256
|
storyblokInit({
|
|
252
|
-
accessToken:
|
|
257
|
+
accessToken: '<your-token>',
|
|
253
258
|
richText: {
|
|
254
259
|
schema: mySchema,
|
|
255
260
|
resolver: (component, blok) => {
|
|
256
261
|
switch (component) {
|
|
257
|
-
case
|
|
262
|
+
case 'my-custom-component':
|
|
258
263
|
return `<div class="my-component-class">${blok.text}</div>`;
|
|
259
264
|
default:
|
|
260
|
-
return
|
|
265
|
+
return 'Resolver not defined';
|
|
261
266
|
}
|
|
262
267
|
},
|
|
263
268
|
},
|
|
@@ -317,7 +322,7 @@ and then, activating the plugin in `plugins` configuration array:
|
|
|
317
322
|
|
|
318
323
|
### Compatibility
|
|
319
324
|
|
|
320
|
-
This plugin
|
|
325
|
+
This plugin was made and tested with Svelte 5.
|
|
321
326
|
|
|
322
327
|
## Troubleshooting
|
|
323
328
|
|
|
@@ -326,10 +331,10 @@ This plugin is for Svelte. Thus, it supports the [same browsers as Svelte 3](htt
|
|
|
326
331
|
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:
|
|
327
332
|
|
|
328
333
|
```js
|
|
329
|
-
import { sveltekit } from
|
|
330
|
-
import basicSsl from
|
|
331
|
-
import path from
|
|
332
|
-
import { fileURLToPath } from
|
|
334
|
+
import { sveltekit } from '@sveltejs/kit/vite';
|
|
335
|
+
import basicSsl from '@vitejs/plugin-basic-ssl';
|
|
336
|
+
import path from 'node:path';
|
|
337
|
+
import { fileURLToPath } from 'node:url';
|
|
333
338
|
|
|
334
339
|
const __filename = fileURLToPath(import.meta.url);
|
|
335
340
|
|
|
@@ -343,9 +348,9 @@ const config = {
|
|
|
343
348
|
},
|
|
344
349
|
resolve: {
|
|
345
350
|
alias: {
|
|
346
|
-
|
|
351
|
+
'@storyblok/svelte': path.resolve(
|
|
347
352
|
__dirname,
|
|
348
|
-
|
|
353
|
+
'./node_modules/@storyblok/svelte'
|
|
349
354
|
),
|
|
350
355
|
},
|
|
351
356
|
},
|
|
@@ -379,5 +384,5 @@ Another option might also be using npm / yarn workspaces.
|
|
|
379
384
|
|
|
380
385
|
## Contributing
|
|
381
386
|
|
|
382
|
-
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
|
|
387
|
+
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?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte#code-of-conduct).
|
|
383
388
|
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.
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
import { getComponent } from
|
|
2
|
+
import { getComponent } from './index';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
export let blok;
|
|
4
|
+
const { blok = null, ...rest } = $props();
|
|
6
5
|
|
|
7
|
-
if (blok) {
|
|
8
|
-
|
|
9
|
-
} else {
|
|
10
|
-
console.error("Please provide a 'blok' property to the StoryblokComponent");
|
|
6
|
+
if (!blok) {
|
|
7
|
+
console.error('Please provide a \'blok\' property to the StoryblokComponent');
|
|
11
8
|
}
|
|
9
|
+
|
|
10
|
+
const component = $state(blok ? getComponent(blok.component) : null);
|
|
11
|
+
const SvelteComponent = $derived(component);
|
|
12
12
|
</script>
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
<
|
|
14
|
+
{#if SvelteComponent}
|
|
15
|
+
<SvelteComponent {blok} {...rest} />
|
|
16
|
+
{/if}
|
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
[x: string]: any;
|
|
6
|
-
blok: any;
|
|
7
|
-
}, {
|
|
8
|
-
[evt: string]: CustomEvent<any>;
|
|
9
|
-
}, {}> {
|
|
10
|
-
}
|
|
11
|
-
export type StoryblokComponentProps = typeof __propDef.props;
|
|
12
|
-
export type StoryblokComponentEvents = typeof __propDef.events;
|
|
13
|
-
export type StoryblokComponentSlots = typeof __propDef.slots;
|
|
14
|
-
import { SvelteComponentTyped } from "svelte";
|
|
15
|
-
declare const __propDef: {
|
|
16
|
-
props: {
|
|
17
|
-
[x: string]: any;
|
|
18
|
-
blok: any;
|
|
19
|
-
};
|
|
20
|
-
events: {
|
|
21
|
-
[evt: string]: CustomEvent<any>;
|
|
22
|
-
};
|
|
23
|
-
slots: {};
|
|
1
|
+
export default StoryblokComponent;
|
|
2
|
+
type StoryblokComponent = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
24
5
|
};
|
|
25
|
-
|
|
6
|
+
declare const StoryblokComponent: import("svelte").Component<{
|
|
7
|
+
blok?: any;
|
|
8
|
+
} & Record<string, any>, {}, "">;
|
|
9
|
+
type $$ComponentProps = {
|
|
10
|
+
blok?: any;
|
|
11
|
+
} & Record<string, any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
export declare const useStoryblokApi: () => StoryblokClient;
|
|
7
|
-
export { useStoryblokApi as getStoryblokApi };
|
|
8
|
-
export declare const storyblokInit: (options: SbSvelteSDKOptions) => void;
|
|
9
|
-
export declare const getComponent: (componentName: string) => any;
|
|
10
|
-
export * from "./types";
|
|
11
|
-
export { default as StoryblokComponent } from "./StoryblokComponent.svelte";
|
|
1
|
+
export * from './storyblok';
|
|
2
|
+
export { default as StoryblokComponent } from './StoryblokComponent.svelte';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { apiPlugin, renderRichText, RichTextSchema, useStoryblokBridge, } from '@storyblok/js';
|
package/dist/index.js
CHANGED
|
@@ -1,53 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
|
|
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";
|
|
1
|
+
export * from './storyblok';
|
|
2
|
+
export { default as StoryblokComponent } from './StoryblokComponent.svelte';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export { apiPlugin, renderRichText, RichTextSchema, useStoryblokBridge, } from '@storyblok/js';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { storyblokInit as sbInit } from '@storyblok/js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a singleton store for managing Storyblok state
|
|
4
|
+
*/
|
|
5
|
+
const createStoryblokStore = () => {
|
|
6
|
+
let api = null;
|
|
7
|
+
let components = {};
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the Storyblok API instance
|
|
10
|
+
*/
|
|
11
|
+
const getApi = () => {
|
|
12
|
+
if (!api) {
|
|
13
|
+
console.error('Storyblok API not initialized. Make sure to load apiPlugin.');
|
|
14
|
+
}
|
|
15
|
+
return api;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Initializes the Storyblok SDK with provided options
|
|
19
|
+
*/
|
|
20
|
+
const init = (options) => {
|
|
21
|
+
const { storyblokApi } = sbInit(options);
|
|
22
|
+
api = storyblokApi ?? api;
|
|
23
|
+
components = options.components ?? {};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves a component from the registered components map
|
|
27
|
+
*/
|
|
28
|
+
const getComponent = (componentName) => {
|
|
29
|
+
const resolvedComponent = typeof components === 'function'
|
|
30
|
+
? components()[componentName]
|
|
31
|
+
: components[componentName];
|
|
32
|
+
if (!resolvedComponent) {
|
|
33
|
+
console.error(`Component "${componentName}" not found. Please register it in storyblokInit:\n`
|
|
34
|
+
+ `storyblokInit({
|
|
35
|
+
accessToken: "<your-token>",
|
|
36
|
+
components: {
|
|
37
|
+
"${componentName}": YourComponent
|
|
38
|
+
}
|
|
39
|
+
})`);
|
|
40
|
+
}
|
|
41
|
+
return resolvedComponent;
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
init,
|
|
45
|
+
getApi,
|
|
46
|
+
getComponent,
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
// Create singleton instance
|
|
50
|
+
const storyblokStore = createStoryblokStore();
|
|
51
|
+
// Export store methods
|
|
52
|
+
export const { init: storyblokInit, getApi: getStoryblokApi, getComponent, } = storyblokStore;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SbBlokData } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Svelte action to make a component editable in Storyblok
|
|
4
|
+
*/
|
|
5
|
+
export declare const storyblokEditable: (node: HTMLElement, value: SbBlokData) => {
|
|
6
|
+
update: (value: SbBlokData) => void;
|
|
7
|
+
};
|
|
8
|
+
export { getComponent, getStoryblokApi, storyblokInit, } from './storyblok-store';
|
|
9
|
+
/**
|
|
10
|
+
* @deprecated Use getStoryblokApi() instead. This will be removed in a next major version.
|
|
11
|
+
*/
|
|
12
|
+
export { getStoryblokApi as useStoryblokApi } from './storyblok-store';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { storyblokEditable as sbEdit, } from '@storyblok/js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates options object for Storyblok editable elements
|
|
4
|
+
*/
|
|
5
|
+
const createEditableOptions = (value) => {
|
|
6
|
+
const options = sbEdit(value);
|
|
7
|
+
return options['data-blok-c']
|
|
8
|
+
? {
|
|
9
|
+
'data-blok-c': options['data-blok-c'],
|
|
10
|
+
'data-blok-uid': options['data-blok-uid'],
|
|
11
|
+
'className': 'storyblok__outline',
|
|
12
|
+
}
|
|
13
|
+
: null;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Applies Storyblok editable attributes to a DOM node
|
|
17
|
+
*/
|
|
18
|
+
const applyEditableOptions = (node, options) => {
|
|
19
|
+
if (!options) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
node.setAttribute('data-blok-c', options['data-blok-c']);
|
|
23
|
+
node.setAttribute('data-blok-uid', options['data-blok-uid']);
|
|
24
|
+
node.classList.add(options.className);
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Svelte action to make a component editable in Storyblok
|
|
28
|
+
*/
|
|
29
|
+
export const storyblokEditable = (node, value) => {
|
|
30
|
+
const updateDom = (value) => {
|
|
31
|
+
const options = createEditableOptions(value);
|
|
32
|
+
if (options) {
|
|
33
|
+
applyEditableOptions(node, options);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
updateDom(value);
|
|
37
|
+
return {
|
|
38
|
+
update: updateDom,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export { getComponent, getStoryblokApi, storyblokInit, } from './storyblok-store';
|
|
42
|
+
/**
|
|
43
|
+
* @deprecated Use getStoryblokApi() instead. This will be removed in a next major version.
|
|
44
|
+
*/
|
|
45
|
+
export { getStoryblokApi as useStoryblokApi } from './storyblok-store';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type { SbSDKOptions } from
|
|
2
|
-
import type {
|
|
1
|
+
import type { SbSDKOptions } from '@storyblok/js';
|
|
2
|
+
import type { Component } from 'svelte';
|
|
3
3
|
export interface SbSvelteComponentsMap {
|
|
4
|
-
[name: string]:
|
|
4
|
+
[name: string]: Component;
|
|
5
5
|
}
|
|
6
6
|
export interface SbSvelteSDKOptions extends SbSDKOptions {
|
|
7
7
|
components?: SbSvelteComponentsMap | CallableFunction;
|
|
8
8
|
}
|
|
9
|
-
export {
|
|
10
|
-
export type { ISbAlternateObject, ISbRichtext, RichTextResolver, SbBlokData, SbBlokKeyDataTypes, SbSDKOptions, ISbStories, ISbStoriesParams, ISbStory, ISbStoryData, ISbStoryParams, StoryblokBridgeConfigV2, StoryblokBridgeV2, ISbCache, StoryblokClient, StoryblokComponentType, ISbConfig, ISbManagmentApiResult, ISbResult, useStoryblokBridge, } from "@storyblok/js";
|
|
9
|
+
export type { ISbAlternateObject, ISbCache, ISbConfig, ISbManagmentApiResult, ISbResult, ISbRichtext, ISbStories, ISbStoriesParams, ISbStory, ISbStoryData, ISbStoryParams, RichTextResolver, SbBlokData, SbBlokKeyDataTypes, SbSDKOptions, StoryblokBridgeConfigV2, StoryblokBridgeV2, StoryblokClient, StoryblokComponentType, useStoryblokBridge, } from '@storyblok/js';
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,89 +1,120 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyblok/svelte",
|
|
3
|
-
"version": "4.0.11",
|
|
4
3
|
"type": "module",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
4
|
+
"version": "5.0.1",
|
|
5
|
+
"private": false,
|
|
6
|
+
"packageManager": "pnpm@9.15.9",
|
|
7
|
+
"description": "SDK to integrate Storyblok into your project using Svelte.",
|
|
8
|
+
"author": "Storyblok",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/storyblok/storyblok-svelte.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/storyblok/storyblok-svelte/issues"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": [
|
|
18
|
+
"**/*.css"
|
|
13
19
|
],
|
|
14
20
|
"exports": {
|
|
15
21
|
".": {
|
|
16
|
-
"svelte": "./dist/index.js",
|
|
17
22
|
"types": "./dist/index.d.ts",
|
|
23
|
+
"svelte": "./dist/index.js",
|
|
18
24
|
"import": "./dist/index.js",
|
|
19
25
|
"require": "./dist/index.js"
|
|
20
26
|
}
|
|
21
27
|
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"module": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"!dist/**/*.spec.*",
|
|
33
|
+
"!dist/**/*.test.*",
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"svelte": "./dist/index.js",
|
|
22
37
|
"scripts": {
|
|
23
|
-
"dev": "
|
|
24
|
-
"build": "
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
38
|
+
"dev": "vite dev",
|
|
39
|
+
"build": "pnpm package",
|
|
40
|
+
"preview": "vite preview",
|
|
41
|
+
"package": "svelte-kit sync && svelte-package && publint",
|
|
42
|
+
"test": "pnpm run test:unit:ci && pnpm run test:e2e",
|
|
43
|
+
"test:unit": "vitest",
|
|
44
|
+
"test:unit:ci": "vitest run",
|
|
45
|
+
"test:unit:ui": "vitest --ui",
|
|
46
|
+
"playground": "pnpm run --filter ./playground/sveltekit dev",
|
|
47
|
+
"test:e2e": "START_SERVER_AND_TEST_INSECURE=1 start-server-and-test playground https://localhost:5173/ cy:run",
|
|
48
|
+
"test:e2e-watch": "START_SERVER_AND_TEST_INSECURE=1 start-server-and-test playground https://localhost:5173/ cy:open",
|
|
49
|
+
"cy:run": "cypress run",
|
|
50
|
+
"cy:open": "cypress open",
|
|
51
|
+
"lint": "eslint .",
|
|
52
|
+
"lint:fix": "eslint . --fix",
|
|
53
|
+
"prepublishOnly": "pnpm package",
|
|
54
|
+
"prepare": "simple-git-hooks",
|
|
55
|
+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
56
|
+
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"svelte": "^5.0.0"
|
|
28
60
|
},
|
|
29
61
|
"dependencies": {
|
|
30
|
-
"@storyblok/js": "3.
|
|
62
|
+
"@storyblok/js": "3.3.1"
|
|
31
63
|
},
|
|
32
64
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"vite": "^5.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"svelte": "^3.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
65
|
+
"@commitlint/cli": "^19.8.0",
|
|
66
|
+
"@commitlint/config-conventional": "^19.8.0",
|
|
67
|
+
"@cypress/svelte": "^3.0.0",
|
|
68
|
+
"@eslint/compat": "^1.2.7",
|
|
69
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
70
|
+
"@storyblok/eslint-config": "^0.3.0",
|
|
71
|
+
"@sveltejs/adapter-auto": "^5.0.0",
|
|
72
|
+
"@sveltejs/kit": "^2.20.2",
|
|
73
|
+
"@sveltejs/package": "^2.3.10",
|
|
74
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
75
|
+
"cypress": "^14.2.0",
|
|
76
|
+
"eslint": "^9.23.0",
|
|
77
|
+
"eslint-plugin-svelte": "^3.3.3",
|
|
78
|
+
"jsdom": "^26.0.0",
|
|
79
|
+
"pathe": "^2.0.3",
|
|
80
|
+
"publint": "^0.3.9",
|
|
81
|
+
"simple-git-hooks": "^2.12.1",
|
|
82
|
+
"start-server-and-test": "^2.0.11",
|
|
83
|
+
"svelte": "^5.25.3",
|
|
84
|
+
"svelte-check": "^4.1.5",
|
|
85
|
+
"typescript": "^5.8.2",
|
|
86
|
+
"typescript-eslint": "^8.28.0",
|
|
87
|
+
"vite": "^6.2.3",
|
|
88
|
+
"vite-plugin-dts": "^4.5.3",
|
|
89
|
+
"vitest": "^3.0.9"
|
|
51
90
|
},
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"json"
|
|
91
|
+
"commitlint": {
|
|
92
|
+
"extends": [
|
|
93
|
+
"@commitlint/config-conventional"
|
|
56
94
|
],
|
|
57
|
-
"
|
|
58
|
-
"
|
|
95
|
+
"rules": {
|
|
96
|
+
"body-max-line-length": [
|
|
97
|
+
2,
|
|
98
|
+
"always",
|
|
99
|
+
200
|
|
100
|
+
],
|
|
101
|
+
"footer-max-line-length": [
|
|
102
|
+
0,
|
|
103
|
+
"always",
|
|
104
|
+
"Infinity"
|
|
105
|
+
]
|
|
59
106
|
}
|
|
60
107
|
},
|
|
61
|
-
"repository": {
|
|
62
|
-
"type": "git",
|
|
63
|
-
"url": "https://github.com/storyblok/storyblok-svelte"
|
|
64
|
-
},
|
|
65
|
-
"keywords": [
|
|
66
|
-
"svelte",
|
|
67
|
-
"storyblok"
|
|
68
|
-
],
|
|
69
|
-
"author": "Josefine Schaefer",
|
|
70
|
-
"bugs": {
|
|
71
|
-
"url": "https://github.com/storyblok/storyblok-svelte/issues"
|
|
72
|
-
},
|
|
73
|
-
"homepage": "https://github.com/storyblok/storyblok-svelte",
|
|
74
108
|
"release": {
|
|
75
109
|
"branches": [
|
|
76
|
-
|
|
77
|
-
"name": "v2",
|
|
78
|
-
"range": "2.x",
|
|
79
|
-
"channel": "v2"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
"name": "main"
|
|
83
|
-
}
|
|
110
|
+
"main"
|
|
84
111
|
]
|
|
85
112
|
},
|
|
86
113
|
"publishConfig": {
|
|
87
114
|
"access": "public"
|
|
115
|
+
},
|
|
116
|
+
"simple-git-hooks": {
|
|
117
|
+
"pre-commit": "pnpm lint",
|
|
118
|
+
"pre-push": "pnpm commitlint --last --verbose"
|
|
88
119
|
}
|
|
89
120
|
}
|