@storyblok/astro 5.1.0-alpha.4 → 5.1.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.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -114
  3. package/{components → dist/components}/FallbackComponent.astro +1 -1
  4. package/dist/components/FallbackComponent.d.ts +6 -0
  5. package/{components → dist/components}/StoryblokComponent.astro +3 -3
  6. package/dist/components/StoryblokComponent.d.ts +6 -0
  7. package/dist/{types/dev-toolbar → dev-toolbar}/toolbarApp.d.ts +1 -1
  8. package/{dev-toolbar → dist/dev-toolbar}/toolbarApp.ts +143 -146
  9. package/dist/{types/index.d.ts → index.d.ts} +12 -17
  10. package/dist/{types/live-preview → live-preview}/handleStoryblokMessage.d.ts +1 -1
  11. package/dist/live-preview/middleware.d.ts +1 -0
  12. package/dist/live-preview/middleware.ts +25 -0
  13. package/dist/storyblok-astro.es.js +1324 -0
  14. package/dist/storyblok-astro.umd.js +69 -0
  15. package/dist/types.d.ts +12 -0
  16. package/dist/utils/generateFinalBridgeObject.d.ts +3 -0
  17. package/dist/utils/parseAstCode.d.ts +7 -0
  18. package/dist/utils/toCamelCase.d.ts +1 -0
  19. package/dist/vite-plugins/vite-plugin-storyblok-bridge.d.ts +12 -0
  20. package/dist/vite-plugins/vite-plugin-storyblok-components.d.ts +2 -0
  21. package/dist/vite-plugins/vite-plugin-storyblok-init.d.ts +3 -0
  22. package/dist/{types/vite-plugins → vite-plugins}/vite-plugin-storyblok-options.d.ts +1 -1
  23. package/package.json +123 -62
  24. package/components/FallbackComponent.ts +0 -2
  25. package/components/StoryblokComponent.ts +0 -2
  26. package/dist/storyblok-astro.js +0 -72
  27. package/dist/storyblok-astro.mjs +0 -1259
  28. package/dist/types/components/FallbackComponent.d.ts +0 -2
  29. package/dist/types/components/StoryblokComponent.d.ts +0 -2
  30. package/dist/types/content-layer/storyblokLoader.d.ts +0 -9
  31. package/dist/types/content-layer/syncContentUpdate.d.ts +0 -4
  32. package/dist/types/cypress/e2e/index.cy.d.ts +0 -0
  33. package/dist/types/cypress/plugins/index.d.ts +0 -2
  34. package/dist/types/cypress/support/commands.d.ts +0 -0
  35. package/dist/types/cypress/support/e2e.d.ts +0 -1
  36. package/dist/types/cypress.config.d.ts +0 -2
  37. package/dist/types/live-preview/middleware.d.ts +0 -1
  38. package/dist/types/node_modules/astro/dist/runtime/client/dev-toolbar/ui-library/icons.d.ts +0 -35
  39. package/dist/types/node_modules/astro/dist/toolbar/index.d.ts +0 -2
  40. package/dist/types/node_modules/camelcase/index.d.ts +0 -102
  41. package/dist/types/types.d.ts +0 -12
  42. package/dist/types/utils/initStoryblokBridge.d.ts +0 -2
  43. package/dist/types/vite-plugins/vite-plugin-storyblok-components.d.ts +0 -2
  44. package/dist/types/vite-plugins/vite-plugin-storyblok-init.d.ts +0 -3
  45. package/live-preview/handleStoryblokMessage.ts +0 -78
  46. package/live-preview/middleware.ts +0 -24
  47. package/utils/initStoryblokBridge.ts +0 -11
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,7 +29,7 @@
29
29
 
30
30
  ## Kickstart a new project
31
31
 
32
- Are you eager to dive into coding? **[Follow these steps to kickstart a new project with Storyblok and Astro](https://www.storyblok.com/technologies#astro?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro)**, and get started in just a few minutes!
32
+ Are you eager to dive into coding? **[Follow these steps to kickstart a new project with Storyblok and Astro](https://www.storyblok.com/technologies?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro#astro)**, and get started in just a few minutes!
33
33
 
34
34
  ## Ultimate Tutorial
35
35
 
@@ -360,7 +360,7 @@ The Astro SDK now provides a live preview feature, designed to offer real-time e
360
360
 
361
361
  To activate the experimental live preview feature, follow these steps:
362
362
 
363
- 1. Set `livePreview` to `true` in your astro.config.mjs file. You can also add your `bridge` configuration here, which will be applied to your bridge.
363
+ 1. Set `livePreview` to `true` within your `astro.config.mjs` file.
364
364
 
365
365
  ```js
366
366
  //astro.config.mjs
@@ -369,133 +369,37 @@ export default defineConfig({
369
369
  storyblok({
370
370
  accessToken: "OsvN..",
371
371
  livePreview: true,
372
- bridge: {
373
- resolveRelations: ["featured.posts"],//Your bridge config
374
- }
375
372
  }),
376
373
  ],
377
374
  output: "server", // Astro must be configured to run in SSR mode
378
375
  });
379
376
  ```
380
377
 
381
- 2. Additionally, please use `getLiveStory` on your Astro pages for getting live story.
378
+ 2. Additionally, please use `useStoryblok` on your Astro pages for story fetching. This replaces the previously used `useStoryblokApi` method.
382
379
 
383
380
  ```jsx
384
381
  //pages/[...slug].astro
385
382
  ---
386
- import { getLiveStory, useStoryblokApi, type ISbStoryData } from "@storyblok/astro";
383
+ import { useStoryblok } from "@storyblok/astro";
387
384
  import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
388
385
 
389
386
  const { slug } = Astro.params;
390
387
 
391
- let story: ISbStoryData = null;
392
-
393
- const liveStory = await getLiveStory(Astro);
394
-
395
- if (liveStory) {
396
- story = liveStory;
397
- } else {
398
- const sbApi = useStoryblokApi();
399
- const { data } = await sbApi.get(
400
- `cdn/stories/${slug === undefined ? "home" : slug}`,
401
- {
402
- version: "draft",
403
- resolve_relations: ["featured-articles.posts"],
404
- }
405
- );
406
- story = data?.story;
407
- }
408
- ---
409
-
410
- <StoryblokComponent blok={story.content} />
411
- ```
412
- 3. You can also listen to when the live preview is updated.
413
-
414
- ```js
415
- <script>
416
- document.addEventListener("storyblok-live-preview-updated", () => {
417
- // console.log("Live preview: body updated");
418
- // initUnoCssRuntime(); regenerate all the css
419
- });
420
- </script>
421
- ```
422
-
423
- ## Enabling Storyblok Loader
424
-
425
- > [!WARNING]
426
- > This feature is currently experimental and optional. You may encounters bugs or performance issues.
427
-
428
- The Astro SDK now provides Storyblok Loader feature, It is designed to scale efficiently and handle large sites with thousands of pages highly performantly.
429
-
430
- To activate the experimental Storyblok Loader feature, follow these steps:
431
-
432
- 1. Set `contentLayer` to `true` in your `astro.config.mjs` file.
433
-
434
- ```js
435
- //astro.config.mjs
436
- export default defineConfig({
437
- integrations: [
438
- storyblok({
439
- accessToken: "OsvN..",
440
- contentLayer: true,
441
- }),
442
- ],
443
- });
444
- ```
445
-
446
- 2. Additionally, in your `src/content/config.ts` file define your collection.
447
-
448
- ```jsx
449
- //src/content/config.ts
450
- import { storyblokLoader } from "@storyblok/astro";
451
- import { defineCollection } from "astro:content";
452
-
453
- const storyblokCollection = defineCollection({
454
- loader: storyblokLoader({
455
- accessToken: "fV...",
456
- apiOptions: {
457
- region: "us",
458
- },
388
+ const story = await useStoryblok(
389
+ // The slug to fetch
390
+ `cdn/stories/${slug === undefined ? "home" : slug}`,
391
+ // The API options
392
+ {
459
393
  version: "draft",
460
- }),
461
- });
462
-
463
- export const collections = {
464
- storyblok: storyblokCollection,
465
- };
466
-
467
- ```
468
- 3. You can now use the storyblokCollection in your pages.
469
-
470
- ```jsx
471
- //src/pages/[...slug].astro
472
- ---
473
- import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
474
- import BaseLayout from "~/layouts/BaseLayout.astro";
475
- import { getCollection } from "astro:content";
476
- import { type ISbStoryData } from "@storyblok/astro";
477
-
478
- export async function getStaticPaths() {
479
- const stories = await getCollection("storyblok");
480
-
481
- return stories.map(({ data }: { data: ISbStoryData }) => {
482
- return {
483
- params: { slug: data.full_slug },
484
- props: { story: data },
485
- };
486
- });
487
- }
488
-
489
- interface Props {
490
- story: ISbStoryData;
491
- }
492
-
493
- const { story } = Astro.props;
394
+ },
395
+ // The Bridge options (optional, if an empty object, null, or false are set, the API options will be considered automatically as far as applicable)
396
+ {},
397
+ // The Astro object (essential for the live preview functionality)
398
+ Astro
399
+ );
494
400
  ---
495
401
 
496
- <BaseLayout>
497
- <StoryblokComponent blok={story.content} />
498
- </BaseLayout>
402
+ <StoryblokComponent blok={story.content} />
499
403
  ```
500
404
 
501
405
  ## The Storyblok JavaScript SDK Ecosystem
@@ -528,5 +432,8 @@ Our heartfelt thanks go to [Virtual Identity](https://www.virtual-identity.com/)
528
432
 
529
433
  ## Contributing
530
434
 
531
- 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-astro).
532
- This project uses [semantic-release](https://semantic-release.gitbook.io/semantic-release/) for generating new versions by using commit messages. We use the Angular Convention to name the commits.
435
+ Please review our [Contributing Guidelines](https://github.com/storyblok/.github/blob/master/contributing.md) and [Code of Conduct](https://www.storyblok.com/trust-center?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-astro#code-of-conduct) before contributing.
436
+
437
+ This project employs [semantic-release](https://semantic-release.gitbook.io/semantic-release/) to generate new versions based on commit messages, following the Angular Commit Message Convention.
438
+
439
+ When using playgrounds during development, ensure the build is running in watch mode for an efficient workflow.
@@ -1,5 +1,5 @@
1
1
  ---
2
- import type { SbBlokData } from "../dist/types";
2
+ import type { SbBlokData } from "@storyblok/js";
3
3
 
4
4
  export interface Props {
5
5
  blok: SbBlokData;
@@ -0,0 +1,6 @@
1
+ import { SbBlokData } from '@storyblok/js';
2
+ declare const FallbackComponent: (_props: {
3
+ blok: SbBlokData;
4
+ [prop: string]: unknown;
5
+ }) => any;
6
+ export default FallbackComponent;
@@ -1,8 +1,8 @@
1
1
  ---
2
2
  import components from "virtual:storyblok-components";
3
3
  import options from "virtual:storyblok-options";
4
- import camelcase from "camelcase";
5
- import type { SbBlokData } from "../dist/types";
4
+ import { toCamelCase } from "@storyblok/astro";
5
+ import type { SbBlokData } from "@storyblok/js";
6
6
  import type { AstroComponentFactory } from "astro/runtime/server/index.js";
7
7
 
8
8
  export interface Props {
@@ -21,7 +21,7 @@ if (!blok) {
21
21
  /**
22
22
  * convert blok components to camel case to match vite-plugin-storyblok-components
23
23
  */
24
- let key = camelcase(blok.component);
24
+ let key = toCamelCase(blok.component as string);
25
25
 
26
26
  const componentFound: boolean = key in components;
27
27
 
@@ -0,0 +1,6 @@
1
+ import { SbBlokData } from '@storyblok/js';
2
+ declare const StoryblokComponent: (_props: {
3
+ blok: SbBlokData;
4
+ [prop: string]: unknown;
5
+ }) => any;
6
+ export default StoryblokComponent;
@@ -1,3 +1,3 @@
1
1
  export declare const storyblokLogo = "<svg width=\"45px\" height=\"53px\" viewBox=\"0 0 45 53\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <g id=\"storyblok-logo-kit\" stroke=\"none\" stroke-width=\"1\" fill=\"none\" fill-rule=\"evenodd\">\n <g id=\"storyblok-partner-logo\" transform=\"translate(-59.000000, -169.000000)\" fill-rule=\"nonzero\">\n <g id=\"storyblok-symbol\" transform=\"translate(59.000000, 169.000000)\">\n <path d=\"M2.32662261,0 C1.03405449,0 0,1.0331384 0,2.27290448 L0,42.8752437 C0,44.1150097 1.03405449,44.8898635 2.27491989,44.8898635 L8.27243596,44.8898635 L8.27243596,53 L15.7176283,44.9415205 L42.9132615,44.9415205 C44.1541269,44.9415205 44.9296678,44.1666667 44.9296678,42.8752437 L44.9296678,2.3245614 C44.9296678,1.08479532 44.2058296,0 42.9132615,0 L2.32662261,0 Z\" id=\"Shape-path-Copy\" fill=\"#0AB3AF\"></path>\n <path d=\"M29.1016723,8.11483254 C30.1351059,8.11483254 31.0135245,8.32132604 31.8402713,8.78593643 C32.6153465,9.19892344 33.33875,9.76678059 33.9071385,10.4378845 C35.0647615,11.8482391 35.6869248,13.6215753 35.6639755,15.445352 C35.6639755,16.7875598 35.3022738,18.0781442 34.630542,19.3171053 C33.9341248,20.5632996 32.8438147,21.5436614 31.5302412,22.1047676 C33.183735,22.569378 34.4755269,23.395352 35.4572888,24.5826897 C36.387379,25.8216507 36.8524241,27.4219754 36.8524241,29.4352871 C36.8524241,30.7258715 36.6168825,31.8756998 36.1290206,32.7391832 C35.6123039,33.668404 34.8372287,34.4427546 33.9071385,35.0106118 C32.9253766,35.6300923 31.8402713,36.1979494 30.600151,36.4560663 C29.3600307,36.7658066 28.0165671,37.0239234 26.6214318,37.0239234 L8.32965751,37.0239234 L8.32965751,8.11483254 L29.1016723,8.11483254 Z M26.1340815,24.271851 L15.77813,24.271851 L15.77813,29.1552028 L25.8851404,29.1552028 C26.4825991,29.1552028 27.0302696,28.9110352 27.4783637,28.5203671 C27.8766695,28.1296989 28.1256107,27.5436967 28.1256107,26.811194 C28.140051,26.1827412 27.948041,25.5663945 27.5779401,25.0531873 C27.1796343,24.5648522 26.7315403,24.271851 26.1340815,24.271851 Z M25.2876816,14.5051475 L15.77813,14.5051475 L15.77813,18.9001641 L25.0885287,18.9001641 C25.586411,18.9001641 26.0842933,18.6559965 26.4825991,18.3629954 C26.9306932,18.0699943 27.1298461,17.4351586 27.1298461,16.6049888 C27.1298461,15.872486 26.9306932,15.3353173 26.5821756,14.9934827 C26.233658,14.7004816 25.7855639,14.5051475 25.2876816,14.5051475 Z\" id=\"Combined-Shape-Copy-3\" fill=\"#FFFFFF\"></path>\n </g>\n </g>\n </g>\n</svg>";
2
- declare const _default: import("astro").DevToolbarApp;
2
+ declare const _default: import('astro').DevToolbarApp;
3
3
  export default _default;
@@ -1,9 +1,8 @@
1
- import { defineToolbarApp } from "astro/toolbar";
2
-
3
1
  import {
4
- isDefinedIcon,
5
2
  type Icon,
6
- } from "astro/runtime/client/dev-toolbar/ui-library/icons.js";
3
+ isDefinedIcon,
4
+ } from 'astro/runtime/client/dev-toolbar/ui-library/icons.js';
5
+ import { defineToolbarApp } from 'astro/toolbar';
7
6
 
8
7
  export const storyblokLogo = `<svg width="45px" height="53px" viewBox="0 0 45 53" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
9
8
  <g id="storyblok-logo-kit" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
@@ -31,153 +30,151 @@ const storyblokLogoFull = `<svg width="180px" height="38px" viewBox="0 0 251 53"
31
30
  </svg>`;
32
31
 
33
32
  function createWindowElement(content: string) {
34
- const windowElement = document.createElement("astro-dev-toolbar-window");
33
+ const windowElement = document.createElement('astro-dev-toolbar-window');
35
34
  windowElement.innerHTML = content;
36
35
  return windowElement;
37
36
  }
38
37
 
38
+ interface LinkItem {
39
+ icon: Icon;
40
+ name: string;
41
+ description: string;
42
+ link: string;
43
+ }
44
+ const links: LinkItem[] = [
45
+ {
46
+ icon: 'star',
47
+ name: 'Ultimate Tutorial',
48
+ description: 'Practical step-by-step guide.',
49
+ link: 'https://www.storyblok.com/tp/the-storyblok-astro-ultimate-tutorial',
50
+ },
51
+ {
52
+ icon: 'lightbulb',
53
+ name: 'Further Tutorials',
54
+ description: 'Browse our other tutorials.',
55
+ link: 'https://www.storyblok.com/tutorials?technologies=astro',
56
+ },
57
+ {
58
+ icon: 'file-search',
59
+ name: 'API Docs',
60
+ description: 'Storyblok\'s Content Delivery and Management APIs.',
61
+ link: 'https://www.storyblok.com/docs#api-documentations',
62
+ },
63
+ {
64
+ icon: 'astro:logo',
65
+ name: 'Astro Docs',
66
+ description: 'Astro\'s official Storyblok docs.',
67
+ link: 'https://docs.astro.build/en/guides/cms/storyblok/',
68
+ },
69
+ {
70
+ icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17 14"><path fill="currentColor" d="M14.3451 1.9072c-1.0375-.47613-2.1323-.81595-3.257-1.010998-.0102-.001716-.0207-.000234-.03.004243s-.017.011728-.022.020757c-.141.249998-.297.576998-.406.832998-1.2124-.18399-2.44561-.18399-3.658 0-.12159-.28518-.25914-.56328-.412-.832998-.00513-.00893-.01285-.016098-.02213-.02056-.00928-.004462-.0197-.00601-.02987-.00444-1.125.193998-2.22.533998-3.257 1.010998-.00888.00339-.0163.00975-.021.018-2.074 3.099-2.643004 6.122-2.364004 9.107.001.014.01.028.021.037 1.207724.8946 2.558594 1.5777 3.995004 2.02.01014.0032.02103.0031.03111-.0003.01007-.0034.01878-.01.02489-.0187.308-.42.582-.863.818-1.329.00491-.0096.0066-.0205.0048-.0312-.00181-.0106-.007-.0204-.0148-.0278-.00517-.0049-.0113-.0086-.018-.011-.43084-.1656-.84811-.3645-1.248-.595-.01117-.0063-.01948-.0167-.0232-.029-.00373-.0123-.00258-.0255.0032-.037.0034-.0074.00854-.014.015-.019.084-.063.168-.129.248-.195.00706-.0057.01554-.0093.02453-.0106.00898-.0012.01813 0 .02647.0036 2.619 1.196 5.454 1.196 8.041 0 .0086-.0037.0181-.0051.0275-.0038.0093.0012.0181.0049.0255.0108.08.066.164.132.248.195.0068.005.0123.0116.0159.0192.0036.0076.0053.016.0049.0244-.0003.0084-.0028.0166-.0072.0238-.0043.0072-.0104.0133-.0176.0176-.399.2326-.8168.4313-1.249.594-.0069.0025-.0132.0065-.0183.0117-.0052.0051-.0092.0114-.0117.0183-.0023.0067-.0032.0138-.0027.0208.0005.0071.0024.0139.0057.0202.24.465.515.909.817 1.329.0061.0087.0148.0153.0249.0187.0101.0034.021.0035.0311.0003 1.4388-.441 2.7919-1.1241 4.001-2.02.0061-.0042.0111-.0097.0147-.0161.0037-.0064.0058-.0135.0063-.0209.334-3.451-.559-6.449-2.366-9.106-.0018-.00439-.0045-.00834-.008-.01162-.0034-.00327-.0075-.00578-.012-.00738Zm-8.198 7.307c-.789 0-1.438-.724-1.438-1.612 0-.889.637-1.613 1.438-1.613.807 0 1.45.73 1.438 1.613 0 .888-.637 1.612-1.438 1.612Zm5.316 0c-.788 0-1.438-.724-1.438-1.612 0-.889.637-1.613 1.438-1.613.807 0 1.451.73 1.438 1.613 0 .888-.631 1.612-1.438 1.612Z"/></svg>`,
71
+ name: 'Community',
72
+ description: 'Engage with our Discord community.',
73
+ link: 'https://discord.com/channels/830184174198718474/1002802280267001858',
74
+ },
75
+ {
76
+ icon: 'bug',
77
+ name: 'Report a Bug',
78
+ description: 'Help us make @storyblok/astro even better.',
79
+ link: 'https://github.com/withastro/astro/issues/new/choose',
80
+ },
81
+ ];
82
+ function createCanvas() {
83
+ return createWindowElement(
84
+ `
85
+ <style>
86
+ p {
87
+ margin-top: 0;
88
+ }
89
+
90
+ header {
91
+ display: flex;
92
+ justify-content: space-between;
93
+ align-items: center;
94
+ }
95
+
96
+ a {
97
+ color: rgba(224, 204, 250, 1);
98
+ text-decoration: none;
99
+ }
100
+
101
+ a:hover {
102
+ color: #f4ecfd;
103
+ }
104
+
105
+ #links {
106
+ margin: auto 0;
107
+ display: grid;
108
+ grid-template-columns: repeat(3, minmax(0, 1fr));
109
+ gap: 16px;
110
+ }
111
+
112
+ #links astro-dev-toolbar-card {
113
+ color: white;
114
+ }
115
+
116
+ #links astro-dev-toolbar-card h3 {
117
+ margin: 0.5em 0;
118
+ color: white;
119
+ }
120
+
121
+ #links astro-dev-toolbar-card p {
122
+ margin: 0;
123
+ }
124
+
125
+ #links astro-dev-toolbar-card:hover {
126
+ color: rgba(145, 152, 173, 1);
127
+ }
128
+
129
+ #links astro-dev-toolbar-icon {
130
+ width: 1.5em;
131
+ height: 1.5em;
132
+ display: block;
133
+ color: white;
134
+ }
135
+
136
+ @media (forced-colors: active) {
137
+ svg path[fill='#fff'] {
138
+ fill: black;
139
+ }
140
+ }
141
+ </style>
142
+
143
+ <header>
144
+ <a href="https://storyblok.com" target="_blank" id="logo">
145
+ ${storyblokLogoFull}
146
+ </a>
147
+ <a href="https://github.com/storyblok/storyblok-astro" target="_blank">
148
+ <img
149
+ src="https://img.shields.io/npm/v/@storyblok/astro?color=40C6C4&label=Astro&labelColor=1B243F&logo=storyblok"
150
+ alt="Storyblok Astro Version v.3.0.1."
151
+ />
152
+ </a>
153
+ </header>
154
+ <hr />
155
+ <div id="main-container">
156
+ <section id="links">
157
+ ${links
158
+ .map(
159
+ link =>
160
+ `<astro-dev-toolbar-card link="${
161
+ link.link
162
+ }"><astro-dev-toolbar-icon ${
163
+ isDefinedIcon(link.icon)
164
+ ? `icon="${link.icon}">`
165
+ : `>${link.icon}`
166
+ }</astro-dev-toolbar-icon><h3>${link.name}</h3><p>${
167
+ link.description
168
+ }</p></astro-dev-toolbar-card>`,
169
+ )
170
+ .join('')}
171
+ </section>
172
+ </div>`,
173
+ );
174
+ }
39
175
  export default defineToolbarApp({
40
176
  init(canvas) {
41
- createCanvas();
42
-
43
- document.addEventListener("astro:after-swap", createCanvas);
44
-
45
- function createCanvas() {
46
- const links: {
47
- icon: Icon;
48
- name: string;
49
- description: string;
50
- link: string;
51
- }[] = [
52
- {
53
- icon: "star",
54
- name: "Ultimate Tutorial",
55
- description: "Practical step-by-step guide.",
56
- link: "https://www.storyblok.com/tp/the-storyblok-astro-ultimate-tutorial",
57
- },
58
- {
59
- icon: "lightbulb",
60
- name: "Further Tutorials",
61
- description: "Browse our other tutorials.",
62
- link: "https://www.storyblok.com/tutorials?technologies=astro",
63
- },
64
- {
65
- icon: "file-search",
66
- name: "API Docs",
67
- description: "Storyblok's Content Delivery and Management APIs.",
68
- link: "https://www.storyblok.com/docs#api-documentations",
69
- },
70
- {
71
- icon: "astro:logo",
72
- name: "Astro Docs",
73
- description: "Astro's official Storyblok docs.",
74
- link: "https://docs.astro.build/en/guides/cms/storyblok/",
75
- },
76
- {
77
- icon: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17 14"><path fill="currentColor" d="M14.3451 1.9072c-1.0375-.47613-2.1323-.81595-3.257-1.010998-.0102-.001716-.0207-.000234-.03.004243s-.017.011728-.022.020757c-.141.249998-.297.576998-.406.832998-1.2124-.18399-2.44561-.18399-3.658 0-.12159-.28518-.25914-.56328-.412-.832998-.00513-.00893-.01285-.016098-.02213-.02056-.00928-.004462-.0197-.00601-.02987-.00444-1.125.193998-2.22.533998-3.257 1.010998-.00888.00339-.0163.00975-.021.018-2.074 3.099-2.643004 6.122-2.364004 9.107.001.014.01.028.021.037 1.207724.8946 2.558594 1.5777 3.995004 2.02.01014.0032.02103.0031.03111-.0003.01007-.0034.01878-.01.02489-.0187.308-.42.582-.863.818-1.329.00491-.0096.0066-.0205.0048-.0312-.00181-.0106-.007-.0204-.0148-.0278-.00517-.0049-.0113-.0086-.018-.011-.43084-.1656-.84811-.3645-1.248-.595-.01117-.0063-.01948-.0167-.0232-.029-.00373-.0123-.00258-.0255.0032-.037.0034-.0074.00854-.014.015-.019.084-.063.168-.129.248-.195.00706-.0057.01554-.0093.02453-.0106.00898-.0012.01813 0 .02647.0036 2.619 1.196 5.454 1.196 8.041 0 .0086-.0037.0181-.0051.0275-.0038.0093.0012.0181.0049.0255.0108.08.066.164.132.248.195.0068.005.0123.0116.0159.0192.0036.0076.0053.016.0049.0244-.0003.0084-.0028.0166-.0072.0238-.0043.0072-.0104.0133-.0176.0176-.399.2326-.8168.4313-1.249.594-.0069.0025-.0132.0065-.0183.0117-.0052.0051-.0092.0114-.0117.0183-.0023.0067-.0032.0138-.0027.0208.0005.0071.0024.0139.0057.0202.24.465.515.909.817 1.329.0061.0087.0148.0153.0249.0187.0101.0034.021.0035.0311.0003 1.4388-.441 2.7919-1.1241 4.001-2.02.0061-.0042.0111-.0097.0147-.0161.0037-.0064.0058-.0135.0063-.0209.334-3.451-.559-6.449-2.366-9.106-.0018-.00439-.0045-.00834-.008-.01162-.0034-.00327-.0075-.00578-.012-.00738Zm-8.198 7.307c-.789 0-1.438-.724-1.438-1.612 0-.889.637-1.613 1.438-1.613.807 0 1.45.73 1.438 1.613 0 .888-.637 1.612-1.438 1.612Zm5.316 0c-.788 0-1.438-.724-1.438-1.612 0-.889.637-1.613 1.438-1.613.807 0 1.451.73 1.438 1.613 0 .888-.631 1.612-1.438 1.612Z"/></svg>`,
78
- name: "Community",
79
- description: "Engage with our Discord community.",
80
- link: "https://discord.com/channels/830184174198718474/1002802280267001858",
81
- },
82
- {
83
- icon: "bug",
84
- name: "Report a Bug",
85
- description: "Help us make @storyblok/astro even better.",
86
- link: "https://github.com/withastro/astro/issues/new/choose",
87
- },
88
- ];
89
-
90
- const windowComponent = createWindowElement(
91
- `
92
- <style>
93
- p {
94
- margin-top: 0;
95
- }
96
-
97
- header {
98
- display: flex;
99
- justify-content: space-between;
100
- align-items: center;
101
- }
102
-
103
- a {
104
- color: rgba(224, 204, 250, 1);
105
- text-decoration: none;
106
- }
107
-
108
- a:hover {
109
- color: #f4ecfd;
110
- }
111
-
112
- #links {
113
- margin: auto 0;
114
- display: grid;
115
- grid-template-columns: repeat(3, minmax(0, 1fr));
116
- gap: 16px;
117
- }
118
-
119
- #links astro-dev-toolbar-card {
120
- color: white;
121
- }
122
-
123
- #links astro-dev-toolbar-card h3 {
124
- margin: 0.5em 0;
125
- color: white;
126
- }
127
-
128
- #links astro-dev-toolbar-card p {
129
- margin: 0;
130
- }
131
-
132
- #links astro-dev-toolbar-card:hover {
133
- color: rgba(145, 152, 173, 1);
134
- }
135
-
136
- #links astro-dev-toolbar-icon {
137
- width: 1.5em;
138
- height: 1.5em;
139
- display: block;
140
- color: white;
141
- }
142
-
143
- @media (forced-colors: active) {
144
- svg path[fill="#fff"] {
145
- fill: black;
146
- }
147
- }
148
- </style>
149
-
150
- <header>
151
- <a href="https://storyblok.com" target="_blank" id="logo">
152
- ${storyblokLogoFull}
153
- </a>
154
- <a href="https://github.com/storyblok/storyblok-astro" target="_blank">
155
- <img src="https://img.shields.io/npm/v/@storyblok/astro?color=40C6C4&label=Astro&labelColor=1B243F&logo=storyblok" alt="Storyblok Astro Version v.3.0.1."/>
156
- </a>
157
- </header>
158
- <hr />
159
- <div id="main-container">
160
- <section id="links">
161
- ${links
162
- .map(
163
- (link) =>
164
- `<astro-dev-toolbar-card link="${
165
- link.link
166
- }"><astro-dev-toolbar-icon ${
167
- isDefinedIcon(link.icon)
168
- ? `icon="${link.icon}">`
169
- : `>${link.icon}`
170
- }</astro-dev-toolbar-icon><h3>${link.name}</h3><p>${
171
- link.description
172
- }</p></astro-dev-toolbar-card>`
173
- )
174
- .join("")}
175
- </section>
176
- </div>
177
- `
178
- );
179
-
180
- canvas.append(windowComponent);
181
- }
177
+ const text = createCanvas();
178
+ canvas.appendChild(text);
182
179
  },
183
180
  });
@@ -1,15 +1,15 @@
1
- import type { AstroGlobal, AstroIntegration } from "astro";
2
- import type { ISbConfig, ISbRichtext, ISbStoryData, SbRichTextOptions, StoryblokBridgeConfigV2, StoryblokClient } from "./types";
3
- export { handleStoryblokMessage } from "./live-preview/handleStoryblokMessage";
4
- export { syncContentUpdate } from "./content-layer/syncContentUpdate";
5
- export { storyblokLoader } from "./content-layer/storyblokLoader";
6
- export { storyblokEditable, loadStoryblokBridge, RichTextResolver, RichTextSchema, } from "@storyblok/js";
1
+ import { AstroGlobal, AstroIntegration } from 'astro';
2
+ import { ISbConfig, ISbRichtext, ISbStoriesParams, ISbStoryData, SbRichTextOptions, StoryblokBridgeConfigV2, StoryblokClient } from './types';
3
+ export { handleStoryblokMessage } from './live-preview/handleStoryblokMessage';
4
+ export * from './types';
5
+ export { toCamelCase } from './utils/toCamelCase';
6
+ export { loadStoryblokBridge, RichTextResolver, RichTextSchema, storyblokEditable, } from '@storyblok/js';
7
7
  export declare function useStoryblokApi(): StoryblokClient;
8
- export declare function getLiveStory(Astro: AstroGlobal): Promise<ISbStoryData<import("@storyblok/js").StoryblokComponentType<string> & {
8
+ export declare function useStoryblok(slug: string, apiOptions: ISbStoriesParams | undefined, _: StoryblokBridgeConfigV2 | undefined, Astro: AstroGlobal): Promise<ISbStoryData<import('@storyblok/js').StoryblokComponentType<string> & {
9
9
  [index: string]: any;
10
- }>>;
10
+ }> | null>;
11
11
  export declare function renderRichText(data?: ISbRichtext, options?: SbRichTextOptions): string;
12
- export type IntegrationOptions = {
12
+ export interface IntegrationOptions {
13
13
  /**
14
14
  * The access token from your space.
15
15
  */
@@ -38,7 +38,7 @@ export type IntegrationOptions = {
38
38
  * },
39
39
  * ```
40
40
  */
41
- components?: object;
41
+ components?: Record<string, string>;
42
42
  /**
43
43
  * The directory containing your Astro components are. Defaults to "src".
44
44
  */
@@ -56,10 +56,5 @@ export type IntegrationOptions = {
56
56
  * A boolean to enable/disable the Experimental Live Preview feature. Disabled by default.
57
57
  */
58
58
  livePreview?: boolean;
59
- /**
60
- * A boolean to enable/disable storyblok content layer.
61
- */
62
- contentLayer?: boolean;
63
- };
64
- export default function storyblokIntegration({ useCustomApi, bridge, componentsDir, enableFallbackComponent, livePreview, contentLayer, ...restOptions }: IntegrationOptions): AstroIntegration;
65
- export * from "./types";
59
+ }
60
+ export default function storyblokIntegration(options: IntegrationOptions): AstroIntegration;
@@ -1,4 +1,4 @@
1
- import type { ISbStoryData } from "@storyblok/js";
1
+ import { ISbStoryData } from '@storyblok/js';
2
2
  /**
3
3
  * Our current tests indicate that the post request section
4
4
  * is the bottleneck in terms of time consumption.
@@ -0,0 +1 @@
1
+ export declare const onRequest: import('astro').MiddlewareHandler;
@@ -0,0 +1,25 @@
1
+ import { defineMiddleware } from 'astro/middleware';
2
+
3
+ export const onRequest = defineMiddleware(async ({ locals, request }, next) => {
4
+ if (request.method === 'POST') {
5
+ const url = new URL(request.url);
6
+ // First do a basic check if its coming from within storyblok
7
+ const isStoryblokRequest
8
+ = url.searchParams.has('_storyblok')
9
+ && url.searchParams.has('_storyblok_c');
10
+
11
+ if (isStoryblokRequest) {
12
+ try {
13
+ // Create a copy of the request
14
+ const requestBody = await request.clone().json();
15
+ if (requestBody && requestBody.is_storyblok_preview) {
16
+ locals._storyblok_preview_data = requestBody;
17
+ }
18
+ }
19
+ catch (error) {
20
+ console.error('Error reading request body:', error);
21
+ }
22
+ }
23
+ }
24
+ return next();
25
+ });