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

chore(docs): update svelte to v5 #691

Merged
merged 1 commit into from
Oct 23, 2024
Merged
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
8 changes: 4 additions & 4 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
},
"devDependencies": {
"@sveltejs/adapter-static": "^3.0.5",
"@sveltejs/kit": "^2.5.24",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
"@sveltejs/kit": "^2.7.2",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.7",
"rimraf": "^6.0.1",
"sass": "^1.79.4",
"svelte": "^4.2.19",
"svelte-check": "^4.0.4",
"svelte": "^5.0.3",
"svelte-check": "^4.0.5",
"svelte-preprocess-import-assets": "^1.1.0",
"typescript": "^5.6.2",
"vite": "^5.4.8"
Expand Down
6 changes: 3 additions & 3 deletions docs/src/lib/BreadcrumbNav.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
<script lang="ts">
import { base } from "$app/paths";
import { page } from "$app/stores";
import { getBreadcrumbs } from "$lib/breadcrumbs.js";
import { getBreadcrumbs } from "$lib/breadcrumbs";
import NavLink from "./NavLink.svelte";
$: breadcrumbs = getBreadcrumbs($page.route.id, $page.data.breadcrumbNames);
let breadcrumbs = $derived(getBreadcrumbs($page.route.id, $page.data.breadcrumbNames));
thomastilkema marked this conversation as resolved.
Show resolved Hide resolved
</script>

{#if breadcrumbs.length > 1}
Expand Down
18 changes: 9 additions & 9 deletions docs/src/lib/Code.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script context="module">
<script module lang="ts">
import hljs from "highlight.js/lib/core";
import xml from "highlight.js/lib/languages/xml";
import css from "highlight.js/lib/languages/css";
Expand All @@ -11,17 +11,17 @@
hljs.registerLanguage("plaintext", plaintext);
</script>

<script>
<script lang="ts">
import "highlight.js/styles/github.css";

/** @param {string} markup */
const trim = (markup) => markup.replace(/^(\s*\n)+/, "").replace(/\n\s*$/, "");
interface Props {
language?: "html" | "css" | "scss" | "plaintext";
code?: string;
}

/** @type {'html' | 'css' | 'scss' | 'plaintext'} */
export let language = "plaintext";
export let code = "";
$: trimmed = trim(code);
$: highlighted = hljs.highlight(trimmed, { language }).value;
let { language = "plaintext", code = "" }: Props = $props();
thomastilkema marked this conversation as resolved.
Show resolved Hide resolved
let trimmed = $derived(code.replace(/^(\s*\n)+/, "").replace(/\n\s*$/, ""));
let highlighted = $derived(hljs.highlight(trimmed, { language }).value);
</script>

<pre><code>{@html highlighted}</code></pre>
2 changes: 1 addition & 1 deletion docs/src/lib/DefaultFooter.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>
<script lang="ts">
import SiteNavLinks from "$lib/SiteNavLinks.svelte";
</script>

Expand Down
7 changes: 5 additions & 2 deletions docs/src/lib/DefaultHeader.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script>
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import SiteNav from "$lib/SiteNav.svelte";
import BreadcrumbNav from "$lib/BreadcrumbNav.svelte";

let props: HTMLAttributes<HTMLElement> = $props();
</script>

<header {...$$props}>
<header {...props}>
<div>
<a href="#main-content" class="button focus-only skip-to-content">Ga direct naar inhoud</a>
<SiteNav />
Expand Down
17 changes: 11 additions & 6 deletions docs/src/lib/NavLink.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<script>
<script lang="ts">
import type { Snippet } from "svelte";
import type { HTMLAnchorAttributes } from "svelte/elements";
import { page } from "$app/stores";

export let href = "";
interface Props {
children: Snippet;
href: string;
}

/** @type {"page"|undefined} */
$: ariaCurrent = $page.url.pathname === href ? "page" : undefined;
let { href = "", children, ...rest }: Props & HTMLAnchorAttributes = $props();
let ariaCurrent = $derived($page.url.pathname === href ? ("page" as const) : undefined);
</script>

<a {href} aria-current={ariaCurrent} {...$$restProps}>
<slot />
<a {href} aria-current={ariaCurrent} {...rest}>
{@render children?.()}
thomastilkema marked this conversation as resolved.
Show resolved Hide resolved
</a>
12 changes: 7 additions & 5 deletions docs/src/lib/SideMenu.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<script>
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import { onMount } from "svelte";
import { browser } from "$app/environment";
import { initSidemenus } from "$lib/manon.js";
import { initSidemenus } from "$lib/manon";

let props: HTMLAttributes<HTMLElement> = $props();
onMount(initSidemenus);
</script>

<nav
data-open-label="Zijbalknavigatie"
data-close-label="Sluit zijbalknavigatie"
aria-label="Document-navigatie"
{...$$props}
{...props}
>
<slot />
{@render props.children?.()}
</nav>
4 changes: 2 additions & 2 deletions docs/src/lib/SiteNav.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script>
<script lang="ts">
import { base } from "$app/paths";
import { onMount } from "svelte";
import SiteNavLinks from "$lib/SiteNavLinks.svelte";
import { initCollapsible } from "$lib/manon.js";
import { initCollapsible } from "$lib/manon";
onMount(initCollapsible);
</script>

Expand Down
7 changes: 5 additions & 2 deletions docs/src/lib/SiteNavLinks.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<script>
<script lang="ts">
import type { HTMLAttributes } from "svelte/elements";
import { base } from "$app/paths";
import NavLink from "$lib/NavLink.svelte";

let props: HTMLAttributes<HTMLElement> = $props();
</script>

<ul {...$$props}>
<ul {...props}>
<li><NavLink href="{base}/">Home</NavLink></li>
<li><NavLink href="{base}/components">Componenten</NavLink></li>
<li><NavLink href="{base}/documentation">Documentatie</NavLink></li>
Expand Down
40 changes: 13 additions & 27 deletions docs/src/lib/breadcrumbs.js → docs/src/lib/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @param {string | null} routeId
* @param {import('./types').BreadcrumbNames} breadcrumbNames
* @return {Array<import('./types').Breadcrumb>}
*/
export function getBreadcrumbs(routeId, breadcrumbNames) {
import type { Breadcrumb, BreadcrumbNames } from "./types";

export function getBreadcrumbs(
routeId: string | null,
breadcrumbNames: BreadcrumbNames,
): Array<Breadcrumb> {
if (!routeId || !breadcrumbNames) return [];
const breadcrumbs = [];
let route = "";
Expand All @@ -17,19 +17,15 @@ export function getBreadcrumbs(routeId, breadcrumbNames) {
return breadcrumbs;
}

/**
* @return {Promise<import('./types').BreadcrumbNames>}
*/
export async function loadBreadcrumbNames() {
export async function loadBreadcrumbNames(): Promise<BreadcrumbNames> {
const modules = import.meta.glob("../routes/**/+page.svelte");
/** @type import('./types').BreadcrumbNames */
const names = {};
const names: BreadcrumbNames = {};
await Promise.all(
Object.entries(modules).map(async ([key, value]) => {
key = routeFromModulePath(key);
if (!key) return;
const name = (await nameFromModule(value)) || nameFromKey(key);
names[/** @type {import('./types').Route} */ (key)] = name;
names[key] = name;
}),
);
return names;
Expand All @@ -40,10 +36,8 @@ const routeSegmentPattern = /\/[^+.(\/]+/g;
/**
* Strip the "../routes/" prefix, "/+page.svelte" suffix, and any route
* "(group)/"s from the module path.
* @param {string} path
* @return {string}
*/
function routeFromModulePath(path) {
function routeFromModulePath(path: string): string {
routeSegmentPattern.lastIndex = 0;
let route = "";
let match;
Expand All @@ -54,20 +48,12 @@ function routeFromModulePath(path) {
return route;
}

/**
* @param {() => Promise<any>} mod
* @return {Promise<string>}
*/
async function nameFromModule(mod) {
const name = /** @type {any} */ (await mod()).breadcrumb;
async function nameFromModule(mod: () => Promise<any>): Promise<string> {
const name = (await mod()).breadcrumb;
return typeof name === "string" ? name : "";
}

/**
* @param {string} key
* @return {string}
*/
function nameFromKey(key) {
function nameFromKey(key: string): string {
const parts = key.split("/");
if (parts.length < 3) return "";
const name = parts[parts.length - 2];
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion docs/src/redirects.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/**
* Record mapping old URLs to new URLs. The root +layout.js uses this to
* Record mapping old URLs to new URLs. The root +layout.ts uses this to
* generate redirect pages for the old URLs during a build. The keys (old URLs)
* are added to the kit.prerender.entries array in svelte.config.js to ensure
* they are included in the build.
*
* NB: this needs to be a .js file because it's imported from svelte.config.js.
*
* @type {Record<string, string>}
*/
export const redirects = {
Expand Down
6 changes: 4 additions & 2 deletions docs/src/routes/(docs)/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<script>
<script lang="ts">
import DefaultHeader from "$lib/DefaultHeader.svelte";
import DefaultFooter from "$lib/DefaultFooter.svelte";

let { children } = $props();
</script>

<DefaultHeader />

<slot />
{@render children?.()}

<DefaultFooter />
4 changes: 2 additions & 2 deletions docs/src/routes/(docs)/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Manon";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
</script>

Expand Down
4 changes: 2 additions & 2 deletions docs/src/routes/(docs)/components/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Componenten";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import NavLink from "$lib/NavLink.svelte";
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Accordeon testpagina";
</script>

<script>
<script lang="ts">
import Code from "$lib/Code.svelte";
</script>

Expand Down
4 changes: 2 additions & 2 deletions docs/src/routes/(docs)/components/accordion/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Accordeon";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import Code from "$lib/Code.svelte";
import SideMenu from "$lib/SideMenu.svelte";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Stijlkeuzes op applicatie-niveau";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import Code from "$lib/Code.svelte";
import SideMenu from "$lib/SideMenu.svelte";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Main testpagina";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import Code from "$lib/Code.svelte";
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Article content wrapper";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import Code from "$lib/Code.svelte";
import SideMenu from "$lib/SideMenu.svelte";
Expand Down
4 changes: 2 additions & 2 deletions docs/src/routes/(docs)/components/article-test/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Article testpagina";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import Code from "$lib/Code.svelte";
</script>
Expand Down
4 changes: 2 additions & 2 deletions docs/src/routes/(docs)/components/article/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Artikel";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import Code from "$lib/Code.svelte";
import SideMenu from "$lib/SideMenu.svelte";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Body text set";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import Code from "$lib/Code.svelte";
import SideMenu from "$lib/SideMenu.svelte";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Kleuren";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import SideMenu from "$lib/SideMenu.svelte";
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script context="module">
<script module>
export const breadcrumb = "Kruimelpad voorbeeld";
</script>

<script>
<script lang="ts">
import { base } from "$app/paths";
import Code from "$lib/Code.svelte";
import SideMenu from "$lib/SideMenu.svelte";
Expand Down
Loading