@svadmin/ui 0.25.2 → 0.25.3
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
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { navigate } from '@svadmin/core/router';
|
|
9
9
|
import { currentPath } from '@svadmin/core/router';
|
|
10
10
|
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query';
|
|
11
|
-
import { setComponentRegistry, type ComponentRegistry } from '../component-registry.svelte.js';
|
|
11
|
+
import { setComponentRegistry, getComponentRegistry, type ComponentRegistry } from '../component-registry.svelte.js';
|
|
12
12
|
import Layout from './Layout.svelte';
|
|
13
13
|
import AutoTable from './AutoTable.svelte';
|
|
14
14
|
import AutoForm from './AutoForm.svelte';
|
|
@@ -164,19 +164,23 @@
|
|
|
164
164
|
{/if}
|
|
165
165
|
{:else if route === '/:resource'}
|
|
166
166
|
{#key params.resource}
|
|
167
|
-
|
|
167
|
+
{@const Comp = getComponentRegistry().AutoTable}
|
|
168
|
+
<Comp resourceName={params.resource} />
|
|
168
169
|
{/key}
|
|
169
170
|
{:else if route === '/:resource/create'}
|
|
170
171
|
{#key params.resource}
|
|
171
|
-
|
|
172
|
+
{@const Comp = getComponentRegistry().AutoForm}
|
|
173
|
+
<Comp resourceName={params.resource} mode="create" />
|
|
172
174
|
{/key}
|
|
173
175
|
{:else if route === '/:resource/edit/:id'}
|
|
174
176
|
{#key `${params.resource}-${params.id}`}
|
|
175
|
-
|
|
177
|
+
{@const Comp = getComponentRegistry().AutoForm}
|
|
178
|
+
<Comp resourceName={params.resource} mode="edit" id={params.id} />
|
|
176
179
|
{/key}
|
|
177
180
|
{:else if route === '/:resource/show/:id'}
|
|
178
181
|
{#key `${params.resource}-${params.id}`}
|
|
179
|
-
|
|
182
|
+
{@const Comp = getComponentRegistry().ShowPage}
|
|
183
|
+
<Comp resourceName={params.resource} id={params.id} />
|
|
180
184
|
{/key}
|
|
181
185
|
{/if}
|
|
182
186
|
</div>
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import * as
|
|
5
|
-
|
|
6
|
-
import "highlight.js/styles/github-dark.css"; // or your preferred theme
|
|
7
|
-
import DOMPurify from "isomorphic-dompurify";
|
|
2
|
+
import * as markedPkg from "marked";
|
|
3
|
+
import * as markedHighlightPkg from "marked-highlight";
|
|
4
|
+
import * as hljsPkg from "highlight.js";
|
|
5
|
+
import * as DOMPurifyPkg from "isomorphic-dompurify";
|
|
8
6
|
import { Check, Copy } from "lucide-svelte";
|
|
9
7
|
import { Button } from "./ui/button/index.js";
|
|
10
8
|
|
|
9
|
+
const Marked = markedPkg.Marked;
|
|
10
|
+
const markedHighlight = markedHighlightPkg.markedHighlight;
|
|
11
|
+
const hljsModule = hljsPkg.default || hljsPkg;
|
|
12
|
+
const DOMPurify = 'default' in DOMPurifyPkg ? DOMPurifyPkg.default : DOMPurifyPkg;
|
|
13
|
+
|
|
14
|
+
// Only safely import css if hljs exists
|
|
15
|
+
if (hljsModule && Object.keys(hljsModule).length > 0) {
|
|
16
|
+
import("highlight.js/styles/github-dark.css").catch(() => {});
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
interface Props {
|
|
12
20
|
/** The raw markdown string to render */
|
|
13
21
|
content: string;
|
|
@@ -19,20 +27,24 @@
|
|
|
19
27
|
|
|
20
28
|
let { content, streaming = false, class: className = "" }: Props = $props();
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
const hasMarkdownDeps = !!(Marked && markedHighlight && DOMPurify && Object.keys(DOMPurify).length > 0);
|
|
31
|
+
|
|
32
|
+
// Configure marked with syntax highlighting if available
|
|
33
|
+
const markedObj = hasMarkdownDeps ? new Marked(
|
|
24
34
|
markedHighlight({
|
|
25
35
|
langPrefix: "hljs language-",
|
|
26
36
|
highlight(code: string, lang: string) {
|
|
27
|
-
const language =
|
|
28
|
-
return
|
|
37
|
+
const language = hljsModule.getLanguage && hljsModule.getLanguage(lang) ? lang : "plaintext";
|
|
38
|
+
return hljsModule.highlight ? hljsModule.highlight(code, { language }).value : code;
|
|
29
39
|
},
|
|
30
40
|
}),
|
|
31
|
-
);
|
|
41
|
+
) : null;
|
|
32
42
|
|
|
33
43
|
// Render HTML safely
|
|
34
44
|
const html = $derived(
|
|
35
|
-
|
|
45
|
+
hasMarkdownDeps
|
|
46
|
+
? DOMPurify.sanitize(markedObj.parse(content || "") as string)
|
|
47
|
+
: `<div style="white-space: pre-wrap">${String(content || "").replace(/</g, "<").replace(/>/g, ">")}</div>`
|
|
36
48
|
);
|
|
37
49
|
|
|
38
50
|
// Handle copy code blocks
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
2
3
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
4
|
import { cn } from "../../../utils.js";
|
|
4
5
|
|
|
5
|
-
let { class: className, ...restProps }: HTMLAttributes<HTMLDivElement> = $props();
|
|
6
|
+
let { class: className, children, ...restProps }: HTMLAttributes<HTMLDivElement> & { children?: Snippet } = $props();
|
|
6
7
|
</script>
|
|
7
8
|
|
|
8
|
-
<div class={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...restProps}
|
|
9
|
+
<div class={cn("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2", className)} {...restProps}>
|
|
10
|
+
{@render children?.()}
|
|
11
|
+
</div>
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
2
3
|
import type { HTMLAttributes } from "svelte/elements";
|
|
3
4
|
import { cn } from "../../../utils.js";
|
|
4
5
|
|
|
5
|
-
let { class: className, ...restProps }: HTMLAttributes<HTMLDivElement> = $props();
|
|
6
|
+
let { class: className, children, ...restProps }: HTMLAttributes<HTMLDivElement> & { children?: Snippet } = $props();
|
|
6
7
|
</script>
|
|
7
8
|
|
|
8
|
-
<div class={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...restProps}
|
|
9
|
+
<div class={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...restProps}>
|
|
10
|
+
{@render children?.()}
|
|
11
|
+
</div>
|