gradio-pr-bot commited on
Commit
c2bbf5c
·
verified ·
1 Parent(s): 1cae904

Upload folder using huggingface_hub

Browse files
6.4.0/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.4.0/markdown/Index.svelte ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ rtl={gradio.props.rtl}
30
+ >
31
+ <StatusTracker
32
+ autoscroll={gradio.shared.autoscroll}
33
+ i18n={gradio.i18n}
34
+ {...gradio.shared.loading_status}
35
+ variant="center"
36
+ on_clear_status={() =>
37
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
38
+ />
39
+ <div
40
+ class:padding={gradio.props.padding}
41
+ class:pending={gradio.shared.loading_status?.status === "pending"}
42
+ >
43
+ <Markdown
44
+ value={gradio.props.value}
45
+ elem_classes={gradio.shared.elem_classes}
46
+ visible={gradio.shared.visible}
47
+ rtl={gradio.props.rtl}
48
+ onchange={() => gradio.dispatch("change")}
49
+ oncopy={(e) => gradio.dispatch("copy", e.detail)}
50
+ latex_delimiters={gradio.props.latex_delimiters}
51
+ sanitize_html={gradio.props.sanitize_html}
52
+ line_breaks={gradio.props.line_breaks}
53
+ header_links={gradio.props.header_links}
54
+ show_copy_button={gradio.props.buttons?.includes("copy")}
55
+ loading_status={gradio.shared.loading_status}
56
+ theme_mode={gradio.shared.theme_mode}
57
+ />
58
+ </div>
59
+ </Block>
60
+
61
+ <style>
62
+ div {
63
+ transition: 150ms;
64
+ }
65
+
66
+ .pending {
67
+ opacity: 0.2;
68
+ }
69
+
70
+ .padding {
71
+ padding: var(--block-padding);
72
+ }
73
+ </style>
6.4.0/markdown/package.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/markdown",
3
+ "version": "0.13.26",
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.4.0/markdown/shared/Markdown.svelte ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { copy, css_units } from "@gradio/utils";
3
+ import { Copy, Check } from "@gradio/icons";
4
+ import type { LoadingStatus } from "@gradio/statustracker";
5
+ import { IconButton, IconButtonWrapper } from "@gradio/atoms";
6
+ import type { ThemeMode } from "@gradio/core";
7
+
8
+ import { MarkdownCode } from "@gradio/markdown-code";
9
+
10
+ let {
11
+ elem_classes = [],
12
+ visible = true,
13
+ value,
14
+ min_height = undefined,
15
+ rtl = false,
16
+ sanitize_html = true,
17
+ line_breaks = false,
18
+ latex_delimiters = [],
19
+ header_links = false,
20
+ height = undefined,
21
+ show_copy_button = false,
22
+ loading_status = undefined,
23
+ theme_mode,
24
+ onchange = () => {},
25
+ oncopy = (val) => {}
26
+ }: {
27
+ elem_classes: string[];
28
+ visible: boolean | "hidden";
29
+ value: string;
30
+ min_height: number | string | undefined;
31
+ rtl: boolean;
32
+ sanitize_html: boolean;
33
+ line_breaks: boolean;
34
+ latex_delimiters: {
35
+ left: string;
36
+ right: string;
37
+ display: boolean;
38
+ }[];
39
+ header_links: boolean;
40
+ height: number | string | undefined;
41
+ show_copy_button: boolean | undefined;
42
+ loading_status: LoadingStatus | undefined;
43
+ theme_mode: ThemeMode;
44
+ onchange: () => void;
45
+ oncopy: (val: any) => void;
46
+ } = $props();
47
+
48
+ let copied = $state(false);
49
+ let timer: NodeJS.Timeout;
50
+
51
+ $effect(() => {
52
+ if (value) {
53
+ onchange();
54
+ }
55
+ });
56
+
57
+ async function handle_copy(): Promise<void> {
58
+ if ("clipboard" in navigator) {
59
+ await navigator.clipboard.writeText(value);
60
+ oncopy({ value: value });
61
+ copy_feedback();
62
+ }
63
+ }
64
+
65
+ function copy_feedback(): void {
66
+ copied = true;
67
+ if (timer) clearTimeout(timer);
68
+ timer = setTimeout(() => {
69
+ copied = false;
70
+ }, 1000);
71
+ }
72
+ </script>
73
+
74
+ <div
75
+ class="prose {elem_classes?.join(' ') || ''}"
76
+ class:hide={!visible}
77
+ data-testid="markdown"
78
+ dir={rtl ? "rtl" : "ltr"}
79
+ use:copy
80
+ style={height ? `max-height: ${css_units(height)}; overflow-y: auto;` : ""}
81
+ style:min-height={min_height && loading_status?.status !== "pending"
82
+ ? css_units(min_height)
83
+ : undefined}
84
+ >
85
+ {#if show_copy_button}
86
+ <IconButtonWrapper>
87
+ <IconButton
88
+ Icon={copied ? Check : Copy}
89
+ on:click={handle_copy}
90
+ label={copied ? "Copied conversation" : "Copy conversation"}
91
+ ></IconButton>
92
+ </IconButtonWrapper>
93
+ {/if}
94
+ <MarkdownCode
95
+ message={value}
96
+ {latex_delimiters}
97
+ {sanitize_html}
98
+ {line_breaks}
99
+ chatbot={false}
100
+ {header_links}
101
+ {theme_mode}
102
+ />
103
+ </div>
104
+
105
+ <style>
106
+ div :global(.math.inline) {
107
+ fill: var(--body-text-color);
108
+ display: inline-block;
109
+ vertical-align: middle;
110
+ padding: var(--size-1-5) -var(--size-1);
111
+ color: var(--body-text-color);
112
+ }
113
+
114
+ div :global(.math.inline svg) {
115
+ display: inline;
116
+ margin-bottom: 0.22em;
117
+ }
118
+
119
+ div {
120
+ max-width: 100%;
121
+ }
122
+
123
+ .hide {
124
+ display: none;
125
+ }
126
+ </style>
6.4.0/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
+ }