@refrakt-md/svelte 0.6.0 → 0.7.1
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 +4 -4
- package/src/ThemeShell.svelte +10 -3
- package/src/behaviors.ts +15 -0
- package/src/elements/Pre.svelte +77 -0
- package/src/elements/Table.svelte +40 -0
- package/src/elements.ts +9 -0
- package/src/index.ts +3 -0
- package/src/registry.ts +22 -0
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.7.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@markdoc/markdoc": "0.4.0",
|
|
30
|
-
"@refrakt-md/behaviors": "0.
|
|
31
|
-
"@refrakt-md/transform": "0.
|
|
32
|
-
"@refrakt-md/types": "0.
|
|
30
|
+
"@refrakt-md/behaviors": "0.7.1",
|
|
31
|
+
"@refrakt-md/transform": "0.7.1",
|
|
32
|
+
"@refrakt-md/types": "0.7.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"svelte": "^5.0.0"
|
package/src/ThemeShell.svelte
CHANGED
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
author?: string;
|
|
37
37
|
tags?: string[];
|
|
38
38
|
image?: string;
|
|
39
|
+
version?: string;
|
|
40
|
+
versionGroup?: string;
|
|
39
41
|
}>;
|
|
40
42
|
url: string;
|
|
41
43
|
seo?: PageSeo;
|
|
@@ -65,15 +67,20 @@
|
|
|
65
67
|
const layoutName = $derived(matchRouteRule(page.url, theme.manifest.routeRules ?? []));
|
|
66
68
|
const layoutEntry = $derived(theme.layouts[layoutName] ?? theme.layouts['default']);
|
|
67
69
|
|
|
70
|
+
// Keep RfContext in sync for web components BEFORE DOM updates.
|
|
71
|
+
// $effect.pre runs before {#key page.url} recreates the DOM, so
|
|
72
|
+
// RfNav.connectedCallback sees the new URL when it fires.
|
|
73
|
+
$effect.pre(() => {
|
|
74
|
+
RfContext.pages = page.pages;
|
|
75
|
+
RfContext.currentUrl = page.url;
|
|
76
|
+
});
|
|
77
|
+
|
|
68
78
|
// Initialize rune + layout behaviors after render, re-run on navigation.
|
|
69
79
|
// The {#key page.url} block in the template ensures full DOM recreation on
|
|
70
80
|
// navigation, so behaviors always run on fresh DOM and old behavior-modified
|
|
71
81
|
// elements are simply discarded (no cleanup/restore conflicts with Svelte).
|
|
72
82
|
$effect(() => {
|
|
73
83
|
void page.url; // re-run when page changes
|
|
74
|
-
// Keep RfContext in sync for web components on client-side navigation
|
|
75
|
-
RfContext.pages = page.pages;
|
|
76
|
-
RfContext.currentUrl = page.url;
|
|
77
84
|
let cleanupRunes: (() => void) | undefined;
|
|
78
85
|
let cleanupLayout: (() => void) | undefined;
|
|
79
86
|
let active = true;
|
package/src/behaviors.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { initRuneBehaviors } from '@refrakt-md/behaviors';
|
|
2
|
+
|
|
3
|
+
/** Svelte action that initializes rune behaviors on mounted content. */
|
|
4
|
+
export function behaviors(node: HTMLElement) {
|
|
5
|
+
let cleanup = initRuneBehaviors(node);
|
|
6
|
+
return {
|
|
7
|
+
update() {
|
|
8
|
+
cleanup();
|
|
9
|
+
cleanup = initRuneBehaviors(node);
|
|
10
|
+
},
|
|
11
|
+
destroy() {
|
|
12
|
+
cleanup();
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { SerializedTag } from '../types.js';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
|
|
5
|
+
let { tag, children }: { tag: SerializedTag; children: Snippet } = $props();
|
|
6
|
+
|
|
7
|
+
const isCodeBlock = 'data-language' in (tag.attributes || {});
|
|
8
|
+
|
|
9
|
+
let preEl: HTMLPreElement;
|
|
10
|
+
let copied = $state(false);
|
|
11
|
+
let timer: ReturnType<typeof setTimeout>;
|
|
12
|
+
|
|
13
|
+
function copy() {
|
|
14
|
+
const text = preEl.textContent ?? '';
|
|
15
|
+
navigator.clipboard.writeText(text);
|
|
16
|
+
copied = true;
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
timer = setTimeout(() => copied = false, 2000);
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
{#if isCodeBlock}
|
|
23
|
+
<div class="rf-codeblock">
|
|
24
|
+
<pre bind:this={preEl} {...tag.attributes}>{@render children()}</pre>
|
|
25
|
+
<button class="rf-codeblock__copy" class:rf-codeblock__copy--copied={copied} onclick={copy} aria-label="Copy code">
|
|
26
|
+
{#if copied}
|
|
27
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
28
|
+
<polyline points="20 6 9 17 4 12" />
|
|
29
|
+
</svg>
|
|
30
|
+
{:else}
|
|
31
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
32
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
|
|
33
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
|
|
34
|
+
</svg>
|
|
35
|
+
{/if}
|
|
36
|
+
</button>
|
|
37
|
+
</div>
|
|
38
|
+
{:else}
|
|
39
|
+
<pre {...tag.attributes}>{@render children()}</pre>
|
|
40
|
+
{/if}
|
|
41
|
+
|
|
42
|
+
<style>
|
|
43
|
+
.rf-codeblock {
|
|
44
|
+
position: relative;
|
|
45
|
+
}
|
|
46
|
+
.rf-codeblock :global(pre) {
|
|
47
|
+
margin: 0;
|
|
48
|
+
}
|
|
49
|
+
.rf-codeblock__copy {
|
|
50
|
+
position: absolute;
|
|
51
|
+
top: 0.5rem;
|
|
52
|
+
right: 0.5rem;
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
justify-content: center;
|
|
56
|
+
width: 2rem;
|
|
57
|
+
height: 2rem;
|
|
58
|
+
border: none;
|
|
59
|
+
border-radius: var(--rf-radius-sm);
|
|
60
|
+
background: transparent;
|
|
61
|
+
color: var(--rf-color-code-text, #e2e8f0);
|
|
62
|
+
cursor: pointer;
|
|
63
|
+
opacity: 0;
|
|
64
|
+
transition: opacity 150ms ease, background-color 150ms ease;
|
|
65
|
+
}
|
|
66
|
+
.rf-codeblock:hover .rf-codeblock__copy {
|
|
67
|
+
opacity: 0.6;
|
|
68
|
+
}
|
|
69
|
+
.rf-codeblock__copy:hover {
|
|
70
|
+
opacity: 1 !important;
|
|
71
|
+
background: rgba(255, 255, 255, 0.1);
|
|
72
|
+
}
|
|
73
|
+
.rf-codeblock__copy--copied {
|
|
74
|
+
opacity: 1 !important;
|
|
75
|
+
color: var(--rf-color-success, #4ade80);
|
|
76
|
+
}
|
|
77
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { SerializedTag } from '../types.js';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
|
|
5
|
+
let { tag, children }: { tag: SerializedTag; children: Snippet } = $props();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<div class="table-wrapper">
|
|
9
|
+
<table {...tag.attributes}>
|
|
10
|
+
{@render children()}
|
|
11
|
+
</table>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<style>
|
|
15
|
+
.table-wrapper {
|
|
16
|
+
overflow-x: auto;
|
|
17
|
+
-webkit-overflow-scrolling: touch;
|
|
18
|
+
margin: 1.5rem 0;
|
|
19
|
+
border: 1px solid var(--rf-color-border);
|
|
20
|
+
border-radius: var(--rf-radius-md);
|
|
21
|
+
}
|
|
22
|
+
.table-wrapper :global(table) {
|
|
23
|
+
margin: 0;
|
|
24
|
+
border-collapse: collapse;
|
|
25
|
+
width: 100%;
|
|
26
|
+
min-width: 100%;
|
|
27
|
+
}
|
|
28
|
+
.table-wrapper :global(th) {
|
|
29
|
+
background: var(--rf-color-surface);
|
|
30
|
+
}
|
|
31
|
+
.table-wrapper :global(th:first-child) {
|
|
32
|
+
border-top-left-radius: var(--rf-radius-md);
|
|
33
|
+
}
|
|
34
|
+
.table-wrapper :global(th:last-child) {
|
|
35
|
+
border-top-right-radius: var(--rf-radius-md);
|
|
36
|
+
}
|
|
37
|
+
.table-wrapper :global(tr:last-child td) {
|
|
38
|
+
border-bottom: none;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
package/src/elements.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ElementOverrides } from './context.js';
|
|
2
|
+
import Table from './elements/Table.svelte';
|
|
3
|
+
import Pre from './elements/Pre.svelte';
|
|
4
|
+
|
|
5
|
+
/** Base element overrides — functional enhancements for HTML elements */
|
|
6
|
+
export const elements: ElementOverrides = {
|
|
7
|
+
'table': Table,
|
|
8
|
+
'pre': Pre,
|
|
9
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -7,3 +7,6 @@ export type { ComponentRegistry, ElementOverrides } from './context.js';
|
|
|
7
7
|
export type { SvelteTheme } from './theme.js';
|
|
8
8
|
export { isLayoutConfig } from './theme.js';
|
|
9
9
|
export { matchRouteRule } from './route-rules.js';
|
|
10
|
+
export { registry } from './registry.js';
|
|
11
|
+
export { elements } from './elements.js';
|
|
12
|
+
export { behaviors } from './behaviors.js';
|
package/src/registry.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ComponentRegistry } from './context.js';
|
|
2
|
+
|
|
3
|
+
/** Maps typeof attribute values to base theme Svelte components.
|
|
4
|
+
*
|
|
5
|
+
* All runes are now rendered purely through the identity transform engine:
|
|
6
|
+
*
|
|
7
|
+
* - Interactive runes requiring client-side lifecycle (Diagram, Map, Nav, Sandbox)
|
|
8
|
+
* are framework-neutral web components in @refrakt-md/behaviors, initialized
|
|
9
|
+
* via custom elements. Their postTransform hooks produce custom element tags.
|
|
10
|
+
*
|
|
11
|
+
* - Data rendering runes (Chart, Comparison, Embed, Testimonial, DesignContext)
|
|
12
|
+
* use postTransform hooks to generate their complete HTML structure.
|
|
13
|
+
*
|
|
14
|
+
* - Behavior-driven runes (tabs, accordion, datatable, form, reveal, preview, details)
|
|
15
|
+
* use BEM classes from the identity transform + @refrakt-md/behaviors.
|
|
16
|
+
*
|
|
17
|
+
* - Layout runes (grid, bento, storyboard, pricing) are fully handled by
|
|
18
|
+
* identity transform + CSS attribute selectors / custom properties.
|
|
19
|
+
*
|
|
20
|
+
* The registry is empty but preserved for user-defined component overrides.
|
|
21
|
+
*/
|
|
22
|
+
export const registry: ComponentRegistry = {};
|