@refrakt-md/svelte 0.3.0 → 0.5.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/package.json +3 -2
- package/src/ThemeShell.svelte +43 -11
- package/src/types.ts +2 -9
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refrakt-md/svelte",
|
|
3
3
|
"description": "Svelte renderer for refrakt.md content",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@markdoc/markdoc": "0.4.0",
|
|
30
|
-
"@refrakt-md/
|
|
30
|
+
"@refrakt-md/behaviors": "0.5.0",
|
|
31
|
+
"@refrakt-md/types": "0.5.0"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
34
|
"svelte": "^5.0.0"
|
package/src/ThemeShell.svelte
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { SvelteTheme } from './theme.js';
|
|
3
3
|
import { setRegistry, setElementOverrides } from './context.js';
|
|
4
|
-
import { setContext } from 'svelte';
|
|
4
|
+
import { setContext, tick } from 'svelte';
|
|
5
5
|
import { matchRouteRule } from './route-rules.js';
|
|
6
|
+
import { initRuneBehaviors } from '@refrakt-md/behaviors';
|
|
6
7
|
|
|
7
8
|
interface OgMeta {
|
|
8
9
|
title?: string;
|
|
@@ -20,9 +21,19 @@
|
|
|
20
21
|
interface PageData {
|
|
21
22
|
title: string;
|
|
22
23
|
description: string;
|
|
24
|
+
frontmatter?: Record<string, unknown>;
|
|
23
25
|
regions: Record<string, { name: string; mode: string; content: any[] }>;
|
|
24
26
|
renderable: any;
|
|
25
|
-
pages: Array<{
|
|
27
|
+
pages: Array<{
|
|
28
|
+
url: string;
|
|
29
|
+
title: string;
|
|
30
|
+
draft: boolean;
|
|
31
|
+
description?: string;
|
|
32
|
+
date?: string;
|
|
33
|
+
author?: string;
|
|
34
|
+
tags?: string[];
|
|
35
|
+
image?: string;
|
|
36
|
+
}>;
|
|
26
37
|
url: string;
|
|
27
38
|
seo?: PageSeo;
|
|
28
39
|
}
|
|
@@ -40,6 +51,23 @@
|
|
|
40
51
|
// Pick layout via route rules (reactive so layout updates on client-side navigation)
|
|
41
52
|
const layoutName = $derived(matchRouteRule(page.url, theme.manifest.routeRules));
|
|
42
53
|
const Layout = $derived(theme.layouts[layoutName] ?? theme.layouts['default']);
|
|
54
|
+
|
|
55
|
+
// Initialize rune behaviors after render, re-run on navigation.
|
|
56
|
+
// The {#key page.url} block in the template ensures full DOM recreation on
|
|
57
|
+
// navigation, so behaviors always run on fresh DOM and old behavior-modified
|
|
58
|
+
// elements are simply discarded (no cleanup/restore conflicts with Svelte).
|
|
59
|
+
$effect(() => {
|
|
60
|
+
void page.url; // re-run when page changes
|
|
61
|
+
let cleanup: (() => void) | undefined;
|
|
62
|
+
let active = true;
|
|
63
|
+
tick().then(() => {
|
|
64
|
+
if (active) cleanup = initRuneBehaviors();
|
|
65
|
+
});
|
|
66
|
+
return () => {
|
|
67
|
+
active = false;
|
|
68
|
+
cleanup?.();
|
|
69
|
+
};
|
|
70
|
+
});
|
|
43
71
|
</script>
|
|
44
72
|
|
|
45
73
|
<svelte:head>
|
|
@@ -72,12 +100,16 @@
|
|
|
72
100
|
{/if}
|
|
73
101
|
</svelte:head>
|
|
74
102
|
|
|
75
|
-
{#
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
{
|
|
103
|
+
{#key page.url}
|
|
104
|
+
{#if Layout}
|
|
105
|
+
<Layout
|
|
106
|
+
title={page.title}
|
|
107
|
+
description={page.description}
|
|
108
|
+
frontmatter={page.frontmatter}
|
|
109
|
+
regions={page.regions}
|
|
110
|
+
renderable={page.renderable}
|
|
111
|
+
pages={page.pages}
|
|
112
|
+
url={page.url}
|
|
113
|
+
/>
|
|
114
|
+
{/if}
|
|
115
|
+
{/key}
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
$$mdtype: 'Tag';
|
|
4
|
-
name: string;
|
|
5
|
-
attributes: Record<string, any>;
|
|
6
|
-
children: RendererNode[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type RendererNode = SerializedTag | string | number | null | undefined | RendererNode[];
|
|
1
|
+
// Canonical types live in @refrakt-md/types; re-exported here for backward compat
|
|
2
|
+
export type { SerializedTag, RendererNode } from '@refrakt-md/types';
|