@storyblok/svelte 4.0.11 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +55 -40
- 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
|
@@ -29,8 +29,15 @@
|
|
|
29
29
|
</a>
|
|
30
30
|
</p>
|
|
31
31
|
|
|
32
|
+
<p align="center">
|
|
33
|
+
<a href="https://www.npmjs.com/package/@storyblok/svelte">
|
|
34
|
+
<img src="https://img.shields.io/npm/v/@storyblok/svelte/latest.svg?style=flat-square" alt="npm package" />
|
|
35
|
+
</a>
|
|
36
|
+
<img src="https://img.shields.io/badge/Svelte-5.x%20Ready-FF3E00?style=flat-square&logo=svelte" alt="Svelte 5 Ready" />
|
|
37
|
+
</p>
|
|
38
|
+
|
|
32
39
|
## 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
|
|
40
|
+
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
41
|
|
|
35
42
|
## Ultimate Tutorial
|
|
36
43
|
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 +46,16 @@ Are you looking for a hands-on, step-by-step tutorial? The **[SvelteKit Ultimate
|
|
|
39
46
|
|
|
40
47
|
| Version to install | Support |
|
|
41
48
|
| --------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
|
|
42
|
-
| Latest (from v3) `@storyblok/svelte` | Modern browsers + Node 18+
|
|
49
|
+
| Latest (from v3) `@storyblok/svelte` | Modern browsers + Node 18+ (Compatible with Svelte 5)|
|
|
43
50
|
| 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
51
|
| [Version 2](https://github.com/storyblok/@storyblok/svelte/tree/v2.5.0) `@storyblok/svelte@2` | Internet Explorer support |
|
|
45
52
|
|
|
53
|
+
### Upgrading to Svelte 5
|
|
54
|
+
|
|
55
|
+
We recommend upgrading to Svelte 5 for the latest features and improvements. The latest version of `@storyblok/svelte` is fully compatible with Svelte 5.
|
|
56
|
+
|
|
57
|
+
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`.
|
|
58
|
+
|
|
46
59
|
## Usage
|
|
47
60
|
|
|
48
61
|
`@storyblok/svelte` helps you connect your Svelte project to Storyblok by:
|
|
@@ -59,16 +72,14 @@ Install `@storyblok/svelte`
|
|
|
59
72
|
npm install @storyblok/svelte
|
|
60
73
|
```
|
|
61
74
|
|
|
62
|
-
Please note that you have to use `npm` - unfortunately, we are currently not supporting `yarn` or `pnpm` for this SDK.
|
|
63
|
-
|
|
64
75
|
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
76
|
|
|
66
77
|
```js
|
|
67
|
-
import App from
|
|
68
|
-
import {
|
|
78
|
+
import App from './App.svelte';
|
|
79
|
+
import { apiPlugin, storyblokInit } from '@storyblok/svelte';
|
|
69
80
|
|
|
70
81
|
storyblokInit({
|
|
71
|
-
accessToken:
|
|
82
|
+
accessToken: '<your-token>',
|
|
72
83
|
// bridge: false,
|
|
73
84
|
use: [apiPlugin],
|
|
74
85
|
|
|
@@ -78,7 +89,9 @@ storyblokInit({
|
|
|
78
89
|
});
|
|
79
90
|
```
|
|
80
91
|
|
|
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`.
|
|
92
|
+
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`.
|
|
93
|
+
|
|
94
|
+
You can find a good example with SvelteKit in the `playground` folder.
|
|
82
95
|
|
|
83
96
|
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
97
|
|
|
@@ -114,12 +127,12 @@ Use the `getStoryblokApi`()` to get your stories from the Storyblok CDN API:
|
|
|
114
127
|
|
|
115
128
|
```html
|
|
116
129
|
<script>
|
|
117
|
-
import { onMount } from
|
|
118
|
-
import { getStoryblokApi } from
|
|
130
|
+
import { onMount } from 'svelte';
|
|
131
|
+
import { getStoryblokApi } from '@storyblok/svelte';
|
|
119
132
|
onMount(async () => {
|
|
120
133
|
const storyblokApi = getStoryblokApi();
|
|
121
|
-
const { data } = await storyblokApi.get(
|
|
122
|
-
version:
|
|
134
|
+
const { data } = await storyblokApi.get('cdn/stories/home', {
|
|
135
|
+
version: 'draft',
|
|
123
136
|
});
|
|
124
137
|
});
|
|
125
138
|
</script>
|
|
@@ -134,13 +147,13 @@ Use `useStoryBridge` to get the updated story every time a change event is trigg
|
|
|
134
147
|
|
|
135
148
|
```html
|
|
136
149
|
<script>
|
|
137
|
-
import { onMount } from
|
|
138
|
-
import { getStoryblokApi, useStoryblokBridge } from
|
|
150
|
+
import { onMount } from 'svelte';
|
|
151
|
+
import { getStoryblokApi, useStoryblokBridge } from '@storyblok/svelte';
|
|
139
152
|
let story = null;
|
|
140
153
|
onMount(async () => {
|
|
141
154
|
const storyblokApi = getStoryblokApi();
|
|
142
|
-
const { data } = await storyblokApi.get(
|
|
143
|
-
version:
|
|
155
|
+
const { data } = await storyblokApi.get('cdn/stories/home', {
|
|
156
|
+
version: 'draft',
|
|
144
157
|
});
|
|
145
158
|
story = data.story;
|
|
146
159
|
useStoryblokBridge(story.id, (newStory) => (story = newStory));
|
|
@@ -151,9 +164,9 @@ Use `useStoryBridge` to get the updated story every time a change event is trigg
|
|
|
151
164
|
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
165
|
|
|
153
166
|
```js
|
|
154
|
-
useStoryblokBridge(story.id,
|
|
155
|
-
resolveRelations: [
|
|
156
|
-
resolveLinks:
|
|
167
|
+
useStoryblokBridge(story.id, newStory => (story = newStory), {
|
|
168
|
+
resolveRelations: ['Article.author'],
|
|
169
|
+
resolveLinks: 'url',
|
|
157
170
|
});
|
|
158
171
|
```
|
|
159
172
|
|
|
@@ -172,7 +185,7 @@ To link the Storyblok components, you have to
|
|
|
172
185
|
- Use the `StoryblokComponent` to load them by passing the `blok` property
|
|
173
186
|
|
|
174
187
|
```html
|
|
175
|
-
<StoryblokComponent {blok} />
|
|
188
|
+
<StoryblokComponent blok={blok} />
|
|
176
189
|
```
|
|
177
190
|
|
|
178
191
|
> 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 +200,10 @@ You can use an `apiOptions` object. This is passed down to the [storyblok-js-cli
|
|
|
187
200
|
|
|
188
201
|
```js
|
|
189
202
|
storyblokInit({
|
|
190
|
-
accessToken:
|
|
203
|
+
accessToken: '<your-token>',
|
|
191
204
|
apiOptions: {
|
|
192
|
-
//storyblok-js-client config object
|
|
193
|
-
cache: { type:
|
|
205
|
+
// storyblok-js-client config object
|
|
206
|
+
cache: { type: 'memory' },
|
|
194
207
|
},
|
|
195
208
|
use: [apiPlugin],
|
|
196
209
|
});
|
|
@@ -204,7 +217,7 @@ You can conditionally load it by using the `bridge` option. Very useful if you w
|
|
|
204
217
|
|
|
205
218
|
```js
|
|
206
219
|
storyblokInit({
|
|
207
|
-
bridge: process.env.NODE_ENV !==
|
|
220
|
+
bridge: process.env.NODE_ENV !== 'production',
|
|
208
221
|
});
|
|
209
222
|
```
|
|
210
223
|
|
|
@@ -212,7 +225,7 @@ Keep in mind you have still access to the raw `window.StoryblokBridge`:
|
|
|
212
225
|
|
|
213
226
|
```js
|
|
214
227
|
const sbBridge = new window.StoryblokBridge(options);
|
|
215
|
-
sbBridge.on([
|
|
228
|
+
sbBridge.on(['input', 'published', 'change'], (event) => {
|
|
216
229
|
// ...
|
|
217
230
|
});
|
|
218
231
|
```
|
|
@@ -225,9 +238,11 @@ You can easily render rich text by using the `renderRichText` function that come
|
|
|
225
238
|
|
|
226
239
|
```html
|
|
227
240
|
<script>
|
|
228
|
-
import { renderRichText } from
|
|
241
|
+
import { renderRichText } from '@storyblok/svelte';
|
|
242
|
+
|
|
243
|
+
let articleHTML = $derived(renderRichText(blok.article));
|
|
244
|
+
|
|
229
245
|
export let blok;
|
|
230
|
-
$: articleHTML = renderRichText(blok.article);
|
|
231
246
|
</script>
|
|
232
247
|
|
|
233
248
|
<div class="prose">{@html articleHTML}</div>
|
|
@@ -243,21 +258,21 @@ npm i clone-deep
|
|
|
243
258
|
You can set a **custom Schema and component resolver globally** at init time by using the `richText` init option:
|
|
244
259
|
|
|
245
260
|
```js
|
|
246
|
-
import { RichTextSchema, storyblokInit } from
|
|
247
|
-
import cloneDeep from
|
|
261
|
+
import { RichTextSchema, storyblokInit } from '@storyblok/svelte';
|
|
262
|
+
import cloneDeep from 'clone-deep';
|
|
248
263
|
const mySchema = cloneDeep(RichTextSchema); // you can make a copy of the default RichTextSchema
|
|
249
264
|
// ... and edit the nodes and marks, or add your own.
|
|
250
265
|
// Check the base RichTextSchema source here https://github.com/storyblok/storyblok-js-client/blob/master/source/schema.js
|
|
251
266
|
storyblokInit({
|
|
252
|
-
accessToken:
|
|
267
|
+
accessToken: '<your-token>',
|
|
253
268
|
richText: {
|
|
254
269
|
schema: mySchema,
|
|
255
270
|
resolver: (component, blok) => {
|
|
256
271
|
switch (component) {
|
|
257
|
-
case
|
|
272
|
+
case 'my-custom-component':
|
|
258
273
|
return `<div class="my-component-class">${blok.text}</div>`;
|
|
259
274
|
default:
|
|
260
|
-
return
|
|
275
|
+
return 'Resolver not defined';
|
|
261
276
|
}
|
|
262
277
|
},
|
|
263
278
|
},
|
|
@@ -317,7 +332,7 @@ and then, activating the plugin in `plugins` configuration array:
|
|
|
317
332
|
|
|
318
333
|
### Compatibility
|
|
319
334
|
|
|
320
|
-
This plugin
|
|
335
|
+
This plugin was made and tested with Svelte 5.
|
|
321
336
|
|
|
322
337
|
## Troubleshooting
|
|
323
338
|
|
|
@@ -326,10 +341,10 @@ This plugin is for Svelte. Thus, it supports the [same browsers as Svelte 3](htt
|
|
|
326
341
|
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
342
|
|
|
328
343
|
```js
|
|
329
|
-
import { sveltekit } from
|
|
330
|
-
import basicSsl from
|
|
331
|
-
import path from
|
|
332
|
-
import { fileURLToPath } from
|
|
344
|
+
import { sveltekit } from '@sveltejs/kit/vite';
|
|
345
|
+
import basicSsl from '@vitejs/plugin-basic-ssl';
|
|
346
|
+
import path from 'node:path';
|
|
347
|
+
import { fileURLToPath } from 'node:url';
|
|
333
348
|
|
|
334
349
|
const __filename = fileURLToPath(import.meta.url);
|
|
335
350
|
|
|
@@ -343,9 +358,9 @@ const config = {
|
|
|
343
358
|
},
|
|
344
359
|
resolve: {
|
|
345
360
|
alias: {
|
|
346
|
-
|
|
361
|
+
'@storyblok/svelte': path.resolve(
|
|
347
362
|
__dirname,
|
|
348
|
-
|
|
363
|
+
'./node_modules/@storyblok/svelte'
|
|
349
364
|
),
|
|
350
365
|
},
|
|
351
366
|
},
|
|
@@ -379,5 +394,5 @@ Another option might also be using npm / yarn workspaces.
|
|
|
379
394
|
|
|
380
395
|
## Contributing
|
|
381
396
|
|
|
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
|
|
397
|
+
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
398
|
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.0",
|
|
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.0"
|
|
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
|
+
2,
|
|
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
|
}
|