@svadmin/ui 0.25.1 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/ui",
3
- "version": "0.25.1",
3
+ "version": "0.25.3",
4
4
  "description": "Pre-built admin UI components — AdminApp, AutoTable, AutoForm, Sidebar, Layout",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -16,7 +16,10 @@
16
16
  "types": "./src/index.ts",
17
17
  "default": "./src/index.ts"
18
18
  },
19
- "./app.css": "./src/app.css",
19
+ "./app.css": {
20
+ "style": "./src/app.css",
21
+ "default": "./src/app.css"
22
+ },
20
23
  "./components/*": "./src/components/*"
21
24
  },
22
25
  "peerDependencies": {
@@ -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
- <AutoTable resourceName={params.resource} />
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
- <AutoForm resourceName={params.resource} mode="create" />
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
- <AutoForm resourceName={params.resource} mode="edit" id={params.id} />
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
- <ShowPage resourceName={params.resource} id={params.id} />
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 { Marked } from "marked";
3
- import { markedHighlight } from "marked-highlight";
4
- import * as hljsModule from "highlight.js";
5
- const hljs = "default" in hljsModule ? hljsModule.default : hljsModule;
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
- // Configure marked with syntax highlighting
23
- const marked = new Marked(
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 = hljs.getLanguage(lang) ? lang : "plaintext";
28
- return hljs.highlight(code, { language }).value;
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
- DOMPurify.sanitize(marked.parse(content || "") as string),
45
+ hasMarkdownDeps
46
+ ? DOMPurify.sanitize(markedObj.parse(content || "") as string)
47
+ : `<div style="white-space: pre-wrap">${String(content || "").replace(/</g, "&lt;").replace(/>/g, "&gt;")}</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}></div>
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}></div>
9
+ <div class={cn("flex flex-col space-y-2 text-center sm:text-left", className)} {...restProps}>
10
+ {@render children?.()}
11
+ </div>