gradio-pr-bot commited on
Commit
35c4b86
·
verified ·
1 Parent(s): 4036f32

Upload folder using huggingface_hub

Browse files
6.0.0-dev.6/markdown/Example.svelte ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { MarkdownCode } from "@gradio/markdown-code";
3
+
4
+ export let value: string | null;
5
+ export let type: "gallery" | "table";
6
+ export let selected = false;
7
+ export let sanitize_html: boolean;
8
+ export let line_breaks: boolean;
9
+ export let latex_delimiters: {
10
+ left: string;
11
+ right: string;
12
+ display: boolean;
13
+ }[];
14
+
15
+ function truncate_text(text: string | null, max_length = 60): string {
16
+ if (!text) return "";
17
+ const str = String(text);
18
+ if (str.length <= max_length) return str;
19
+ return str.slice(0, max_length) + "...";
20
+ }
21
+ </script>
22
+
23
+ <div
24
+ class:table={type === "table"}
25
+ class:gallery={type === "gallery"}
26
+ class:selected
27
+ class="prose"
28
+ >
29
+ <MarkdownCode
30
+ message={truncate_text(value)}
31
+ {latex_delimiters}
32
+ {sanitize_html}
33
+ {line_breaks}
34
+ chatbot={false}
35
+ />
36
+ </div>
37
+
38
+ <style>
39
+ .gallery {
40
+ padding: var(--size-1) var(--size-2);
41
+ }
42
+ </style>
6.0.0-dev.6/markdown/Index.svelte ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as BaseMarkdown } from "./shared/Markdown.svelte";
3
+ export { default as BaseExample } from "./Example.svelte";
4
+ </script>
5
+
6
+ <script lang="ts">
7
+ import { Gradio } from "@gradio/utils";
8
+ import Markdown from "./shared/Markdown.svelte";
9
+
10
+ import { StatusTracker } from "@gradio/statustracker";
11
+ import { Block } from "@gradio/atoms";
12
+
13
+ import type { MarkdownProps, MarkdownEvents } from "./types";
14
+
15
+ let props = $props();
16
+ const gradio = new Gradio<MarkdownEvents, MarkdownProps>(props);
17
+ </script>
18
+
19
+ <Block
20
+ visible={gradio.shared.visible}
21
+ elem_id={gradio.shared.elem_id}
22
+ elem_classes={gradio.shared.elem_classes}
23
+ container={gradio.shared.container}
24
+ allow_overflow={true}
25
+ overflow_behavior="auto"
26
+ height={gradio.props.height}
27
+ min_height={gradio.props.min_height}
28
+ max_height={gradio.props.max_height}
29
+ >
30
+ <StatusTracker
31
+ autoscroll={gradio.shared.autoscroll}
32
+ i18n={gradio.i18n}
33
+ {...gradio.shared.loading_status}
34
+ variant="center"
35
+ on:clear_status={() =>
36
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
37
+ />
38
+ <div
39
+ class:padding={gradio.props.padding}
40
+ class:pending={gradio.shared.loading_status?.status === "pending"}
41
+ >
42
+ <Markdown
43
+ value={gradio.props.value}
44
+ elem_classes={gradio.shared.elem_classes}
45
+ visible={gradio.shared.visible}
46
+ rtl={gradio.props.rtl}
47
+ on:change={() => gradio.dispatch("change")}
48
+ on:copy={(e) => gradio.dispatch("copy", e.detail)}
49
+ latex_delimiters={gradio.props.latex_delimiters}
50
+ sanitize_html={gradio.props.sanitize_html}
51
+ line_breaks={gradio.props.line_breaks}
52
+ header_links={gradio.props.header_links}
53
+ show_copy_button={gradio.props.buttons?.includes("copy")}
54
+ loading_status={gradio.shared.loading_status}
55
+ theme_mode={gradio.shared.theme_mode}
56
+ />
57
+ </div>
58
+ </Block>
59
+
60
+ <style>
61
+ div {
62
+ transition: 150ms;
63
+ }
64
+
65
+ .pending {
66
+ opacity: 0.2;
67
+ }
68
+
69
+ .padding {
70
+ padding: var(--block-padding);
71
+ }
72
+ </style>
6.0.0-dev.6/markdown/package.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/markdown",
3
+ "version": "0.13.23-dev.1",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "main_changeset": true,
10
+ "main": "Index.svelte",
11
+ "exports": {
12
+ ".": {
13
+ "gradio": "./Index.svelte",
14
+ "svelte": "./dist/Index.svelte",
15
+ "types": "./dist/Index.svelte.d.ts"
16
+ },
17
+ "./example": {
18
+ "gradio": "./Example.svelte",
19
+ "svelte": "./dist/Example.svelte",
20
+ "types": "./dist/Example.svelte.d.ts"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "dependencies": {
25
+ "@gradio/atoms": "workspace:^",
26
+ "@gradio/icons": "workspace:^",
27
+ "@gradio/statustracker": "workspace:^",
28
+ "@gradio/utils": "workspace:^",
29
+ "@gradio/markdown-code": "workspace:^"
30
+ },
31
+ "devDependencies": {
32
+ "@gradio/preview": "workspace:^"
33
+ },
34
+ "peerDependencies": {
35
+ "svelte": "^5.43.4"
36
+ },
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/gradio-app/gradio.git",
40
+ "directory": "js/markdown"
41
+ }
42
+ }
6.0.0-dev.6/markdown/shared/Markdown.svelte ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { createEventDispatcher } from "svelte";
3
+ import { copy, css_units } from "@gradio/utils";
4
+ import type { CopyData } from "@gradio/utils";
5
+ import { Copy, Check } from "@gradio/icons";
6
+ import type { LoadingStatus } from "@gradio/statustracker";
7
+ import { IconButton, IconButtonWrapper } from "@gradio/atoms";
8
+ import type { ThemeMode } from "@gradio/core";
9
+
10
+ import { MarkdownCode } from "@gradio/markdown-code";
11
+
12
+ export let elem_classes: string[] = [];
13
+ export let visible: boolean | "hidden" = true;
14
+ export let value: string;
15
+ export let min_height: number | string | undefined = undefined;
16
+ export let rtl = false;
17
+ export let sanitize_html = true;
18
+ export let line_breaks = false;
19
+ export let latex_delimiters: {
20
+ left: string;
21
+ right: string;
22
+ display: boolean;
23
+ }[];
24
+ export let header_links = false;
25
+ export let height: number | string | undefined = undefined;
26
+ export let show_copy_button = false;
27
+ export let loading_status: LoadingStatus | undefined = undefined;
28
+ export let theme_mode: ThemeMode;
29
+ let copied = false;
30
+ let timer: NodeJS.Timeout;
31
+
32
+ const dispatch = createEventDispatcher<{
33
+ change: undefined;
34
+ copy: CopyData;
35
+ }>();
36
+
37
+ $: (value, dispatch("change"));
38
+
39
+ async function handle_copy(): Promise<void> {
40
+ if ("clipboard" in navigator) {
41
+ await navigator.clipboard.writeText(value);
42
+ dispatch("copy", { value: value });
43
+ copy_feedback();
44
+ }
45
+ }
46
+
47
+ function copy_feedback(): void {
48
+ copied = true;
49
+ if (timer) clearTimeout(timer);
50
+ timer = setTimeout(() => {
51
+ copied = false;
52
+ }, 1000);
53
+ }
54
+ </script>
55
+
56
+ <div
57
+ class="prose {elem_classes?.join(' ') || ''}"
58
+ class:hide={!visible}
59
+ data-testid="markdown"
60
+ dir={rtl ? "rtl" : "ltr"}
61
+ use:copy
62
+ style={height ? `max-height: ${css_units(height)}; overflow-y: auto;` : ""}
63
+ style:min-height={min_height && loading_status?.status !== "pending"
64
+ ? css_units(min_height)
65
+ : undefined}
66
+ >
67
+ {#if show_copy_button}
68
+ <IconButtonWrapper>
69
+ <IconButton
70
+ Icon={copied ? Check : Copy}
71
+ on:click={handle_copy}
72
+ label={copied ? "Copied conversation" : "Copy conversation"}
73
+ ></IconButton>
74
+ </IconButtonWrapper>
75
+ {/if}
76
+ <MarkdownCode
77
+ message={value}
78
+ {latex_delimiters}
79
+ {sanitize_html}
80
+ {line_breaks}
81
+ chatbot={false}
82
+ {header_links}
83
+ {theme_mode}
84
+ />
85
+ </div>
86
+
87
+ <style>
88
+ div :global(.math.inline) {
89
+ fill: var(--body-text-color);
90
+ display: inline-block;
91
+ vertical-align: middle;
92
+ padding: var(--size-1-5) -var(--size-1);
93
+ color: var(--body-text-color);
94
+ }
95
+
96
+ div :global(.math.inline svg) {
97
+ display: inline;
98
+ margin-bottom: 0.22em;
99
+ }
100
+
101
+ div {
102
+ max-width: 100%;
103
+ }
104
+
105
+ .hide {
106
+ display: none;
107
+ }
108
+ </style>
6.0.0-dev.6/markdown/types.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { LoadingStatus } from "js/statustracker";
2
+
3
+ export interface MarkdownProps {
4
+ value: string;
5
+ sanitize_html: boolean;
6
+ header_links: boolean;
7
+ latex_delimiters: { left: string; right: string; display: boolean }[];
8
+ rtl: boolean;
9
+ line_breaks: boolean;
10
+ padding: boolean;
11
+ buttons: string[] | null;
12
+ height: number | null;
13
+ min_height: number | null;
14
+ max_height: number | null;
15
+ }
16
+
17
+ export interface MarkdownEvents {
18
+ change: string;
19
+ copy: any;
20
+ clear_status: LoadingStatus;
21
+ }