Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/update2svelte5 #1122

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
blank_issues_enabled: false
blank_issues_enabled: false
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
</p>

## Kickstart a new project

Are you eager to dive into coding? **[Follow these steps to kickstart a new project with Storyblok and Svelte](https://www.storyblok.com/technologies#sveltekit?utm_source=github.com&utm_medium=readme&utm_campaign=storyblok-svelte)**, and get started in just a few minutes!

## Ultimate Tutorial

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.

## Compatibility
Expand Down Expand Up @@ -226,8 +228,9 @@ You can easily render rich text by using the `renderRichText` function that come
```html
<script>
import { renderRichText } from "@storyblok/svelte";

export let blok;
$: articleHTML = renderRichText(blok.article);
articleHTML = renderRichText(blok.article);
</script>

<div class="prose">{@html articleHTML}</div>
Expand Down
42 changes: 42 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import prettier from "eslint-config-prettier";
import js from "@eslint/js";
import { includeIgnoreFile } from "@eslint/compat";
import svelte from "eslint-plugin-svelte";
import globals from "globals";
import { fileURLToPath } from "node:url";
import ts from "typescript-eslint";
const gitignorePath = fileURLToPath(new URL("./.gitignore", import.meta.url));

export default ts.config(
includeIgnoreFile(gitignorePath),
js.configs.recommended,
...ts.configs.recommended,
...svelte.configs["flat/recommended"],
prettier,
...svelte.configs["flat/prettier"],
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
},
},
{
files: ["**/*.svelte"],

languageOptions: {
parserOptions: {
parser: ts.parser,
},
},
},
{
ignores: ["lib/__tests__/*"],
},
{
rules: {
"svelte/no-at-html-tags": "off",
},
}
);
10 changes: 6 additions & 4 deletions lib/Testing.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
StoryblokComponent,
} from "./pkg";

export let accessToken;
export let bridge;
export let components;
export let blok;
let {
accessToken,
bridge,
components,
blok
} = $props();

storyblokInit({
accessToken,
Expand Down
19 changes: 11 additions & 8 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storyblok/svelte",
"version": "1.0.0",
"version": "2.0.0",
"type": "module",
"description": "Storyblok SDK to connect Storyblok with Svelte",
"main": "./dist/index.js",
Expand All @@ -22,27 +22,27 @@
"scripts": {
"dev": "svelte-package -i pkg --watch",
"build": "svelte-package -i pkg",
"test": "npm run test:unit && npm run test:e2e",
"test": "npm run test:unit",
"test:unit": "jest __tests__",
"prepublishOnly": "npm run build && cp ../README.md ."
},
"dependencies": {
"@storyblok/js": "^3.1.1"
"@storyblok/js": "^3.1.9"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@sveltejs/package": "^2.3.4",
"@sveltejs/package": "^2.3.7",
"@tsconfig/svelte": "^5.0.4",
"babel-jest": "^29",
"eslint-plugin-jest": "^28.8.0",
"jest": "^29.7.0",
"svelte": "^4.2.16",
"svelte-preprocess": "^5.1.4",
"svelte": "^5.0.0",
"svelte-preprocess": "^6.0.0",
"typescript": "^5.5.4",
"vite": "^5.4.2"
"vite": "^5.4.4"
},
"peerDependencies": {
"svelte": "^3.0.0 || ^4.0.0"
"svelte": "^5.0.0"
},
"eslintConfig": {
"env": {
Expand All @@ -67,6 +67,9 @@
"storyblok"
],
"author": "Josefine Schaefer",
"contributors": [
"Amar Tupo<[email protected]>"
],
"bugs": {
"url": "https://github.com/storyblok/storyblok-svelte/issues"
},
Expand Down
10 changes: 6 additions & 4 deletions lib/pkg/StoryblokComponent.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script>
import { getComponent } from "./index";

let component;
export let blok;
let component = $state();
let { blok, ...rest } = $props();

if (blok) {
component = getComponent(blok.component);
} else {
console.error("Please provide a 'blok' property to the StoryblokComponent");
}
const SvelteComponent = $derived(component);
</script>
{#if component}
<SvelteComponent {blok} {...rest} />
{/if}

<!-- svelte-ignore missing-declaration -->
<svelte:component this={component} {blok} {...$$restProps} />
2 changes: 1 addition & 1 deletion lib/pkg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const getComponent = (componentName: string) => {
storyblokInit({
accessToken: "<your-token>",
components: {
"teaser": Teaser
"${componentName.toLowerCase()}": ${componentName}
}
})
`);
Expand Down
5 changes: 2 additions & 3 deletions lib/pkg/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { SbSDKOptions } from "@storyblok/js";
import type { SvelteComponent } from "svelte";
import type { Component } from "svelte";

export interface SbSvelteComponentsMap {
// @ts-ignore
[name: string]: typeof SvelteComponent<any>;
[name: string]: Component;
}

export interface SbSvelteSDKOptions extends SbSDKOptions {
Expand Down
Loading