gradio-pr-bot commited on
Commit
9dc4cf7
·
verified ·
1 Parent(s): 1815c64

Upload folder using huggingface_hub

Browse files
6.6.0/json/Example.svelte ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import JSON from "./shared/JSON.svelte";
3
+
4
+ let {
5
+ value,
6
+ theme_mode = "system" as "system" | "light" | "dark",
7
+ type,
8
+ selected = false
9
+ }: {
10
+ value: any;
11
+ theme_mode?: "system" | "light" | "dark";
12
+ type: "gallery" | "table";
13
+ selected?: boolean;
14
+ } = $props();
15
+
16
+ let show_indices = $state(false);
17
+ let label_height = $state(0);
18
+ </script>
19
+
20
+ <div
21
+ class="container"
22
+ class:table={type === "table"}
23
+ class:gallery={type === "gallery"}
24
+ class:selected
25
+ class:border={value}
26
+ >
27
+ {#if value}
28
+ <JSON
29
+ {value}
30
+ open={true}
31
+ {theme_mode}
32
+ {show_indices}
33
+ {label_height}
34
+ interactive={false}
35
+ show_copy_button={false}
36
+ />
37
+ {/if}
38
+ </div>
39
+
40
+ <style>
41
+ .container :global(img) {
42
+ width: 100%;
43
+ height: 100%;
44
+ }
45
+
46
+ .container.selected {
47
+ border-color: var(--border-color-accent);
48
+ }
49
+ .border.table {
50
+ border: 1px solid var(--border-color-primary);
51
+ }
52
+
53
+ .container.table {
54
+ margin: 0 auto;
55
+ border-radius: var(--radius-lg);
56
+ overflow: hidden;
57
+ width: 100%;
58
+ height: 100%;
59
+ max-width: var(--size-40);
60
+ max-height: var(--size-20);
61
+ object-fit: cover;
62
+ }
63
+
64
+ .container.gallery {
65
+ width: 100%;
66
+ max-width: 100%;
67
+ object-fit: cover;
68
+ max-width: var(--size-40);
69
+ max-height: var(--size-20);
70
+ overflow: hidden;
71
+ }
72
+ </style>
6.6.0/json/Index.svelte ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script context="module" lang="ts">
2
+ export { default as BaseJSON } from "./shared/JSON.svelte";
3
+ </script>
4
+
5
+ <script lang="ts">
6
+ import { Gradio } from "@gradio/utils";
7
+ import JSON from "./shared/JSON.svelte";
8
+ import { Block, BlockLabel } from "@gradio/atoms";
9
+ import { JSON as JSONIcon } from "@gradio/icons";
10
+
11
+ import { StatusTracker } from "@gradio/statustracker";
12
+ import type { JSONProps, JSONEvents } from "./types";
13
+
14
+ const props = $props();
15
+ const gradio = new Gradio<JSONEvents, JSONProps>(props);
16
+
17
+ let old_value = $state(gradio.props.value);
18
+
19
+ $effect(() => {
20
+ if (old_value !== gradio.props.value) {
21
+ old_value = gradio.props.value;
22
+ gradio.dispatch("change");
23
+ }
24
+ });
25
+
26
+ let label_height = $state(0);
27
+ </script>
28
+
29
+ <Block
30
+ visible={gradio.shared.visible}
31
+ test_id="json"
32
+ elem_id={gradio.shared.elem_id}
33
+ elem_classes={gradio.shared.elem_classes}
34
+ container={gradio.shared.container}
35
+ scale={gradio.shared.scale}
36
+ min_width={gradio.shared.min_width}
37
+ padding={false}
38
+ allow_overflow={true}
39
+ overflow_behavior="auto"
40
+ height={gradio.props.height}
41
+ min_height={gradio.props.min_height}
42
+ max_height={gradio.props.max_height}
43
+ >
44
+ <div bind:clientHeight={label_height}>
45
+ {#if gradio.shared.label}
46
+ <BlockLabel
47
+ Icon={JSONIcon}
48
+ show_label={gradio.shared.show_label}
49
+ label={gradio.shared.label}
50
+ float={false}
51
+ disable={gradio.shared.container === false}
52
+ />
53
+ {/if}
54
+ </div>
55
+
56
+ <StatusTracker
57
+ autoscroll={gradio.shared.autoscroll}
58
+ i18n={gradio.i18n}
59
+ {...gradio.shared.loading_status}
60
+ on_clear_status={() =>
61
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
62
+ />
63
+
64
+ <JSON
65
+ value={gradio.props.value}
66
+ open={gradio.props.open}
67
+ theme_mode={gradio.props.theme_mode}
68
+ show_indices={gradio.props.show_indices}
69
+ show_copy_button={gradio.props.buttons == null
70
+ ? true
71
+ : gradio.props.buttons.some(
72
+ (btn) => typeof btn === "string" && btn === "copy"
73
+ )}
74
+ buttons={gradio.props.buttons}
75
+ on_custom_button_click={(id) => {
76
+ gradio.dispatch("custom_button_click", { id });
77
+ }}
78
+ {label_height}
79
+ />
80
+ </Block>
6.6.0/json/package.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "@gradio/json",
3
+ "version": "0.7.2",
4
+ "description": "Gradio UI packages",
5
+ "type": "module",
6
+ "author": "",
7
+ "license": "ISC",
8
+ "private": false,
9
+ "dependencies": {
10
+ "@gradio/atoms": "workspace:^",
11
+ "@gradio/icons": "workspace:^",
12
+ "@gradio/statustracker": "workspace:^",
13
+ "@gradio/utils": "workspace:^"
14
+ },
15
+ "devDependencies": {
16
+ "@gradio/preview": "workspace:^"
17
+ },
18
+ "main": "./Index.svelte",
19
+ "main_changeset": true,
20
+ "exports": {
21
+ ".": {
22
+ "gradio": "./Index.svelte",
23
+ "svelte": "./dist/Index.svelte",
24
+ "types": "./dist/Index.svelte.d.ts"
25
+ },
26
+ "./example": {
27
+ "gradio": "./Example.svelte",
28
+ "svelte": "./dist/Example.svelte",
29
+ "types": "./dist/Example.svelte.d.ts"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "peerDependencies": {
34
+ "svelte": "^5.48.0"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/gradio-app/gradio.git",
39
+ "directory": "js/json"
40
+ }
41
+ }
6.6.0/json/shared/JSON.svelte ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { JSON as JSONIcon } from "@gradio/icons";
3
+ import { Empty, IconButtonWrapper, IconButton } from "@gradio/atoms";
4
+ import JSONNode from "./JSONNode.svelte";
5
+ import { Copy, Check } from "@gradio/icons";
6
+ import type { CustomButton as CustomButtonType } from "@gradio/utils";
7
+
8
+ let {
9
+ value = {},
10
+ open = false,
11
+ theme_mode = "system" as "system" | "light" | "dark",
12
+ show_indices = false,
13
+ label_height,
14
+ interactive = true,
15
+ show_copy_button = true,
16
+ buttons = null,
17
+ on_custom_button_click = null
18
+ }: {
19
+ value?: any;
20
+ open?: boolean;
21
+ theme_mode?: "system" | "light" | "dark";
22
+ show_indices?: boolean;
23
+ label_height: number;
24
+ interactive?: boolean;
25
+ show_copy_button?: boolean;
26
+ buttons?: (string | CustomButtonType)[] | null;
27
+ on_custom_button_click?: ((id: number) => void) | null;
28
+ } = $props();
29
+
30
+ let json_max_height = $derived(`calc(100% - ${label_height}px)`);
31
+
32
+ let copied = $state(false);
33
+ let timer = $state<NodeJS.Timeout>();
34
+
35
+ function copy_feedback(): void {
36
+ copied = true;
37
+ if (timer) clearTimeout(timer);
38
+ timer = setTimeout(() => {
39
+ copied = false;
40
+ }, 1000);
41
+ }
42
+
43
+ async function handle_copy(): Promise<void> {
44
+ if ("clipboard" in navigator) {
45
+ await navigator.clipboard.writeText(JSON.stringify(value, null, 2));
46
+ copy_feedback();
47
+ }
48
+ }
49
+
50
+ function is_empty(obj: object): boolean {
51
+ return (
52
+ obj &&
53
+ Object.keys(obj).length === 0 &&
54
+ Object.getPrototypeOf(obj) === Object.prototype &&
55
+ JSON.stringify(obj) === JSON.stringify({})
56
+ );
57
+ }
58
+
59
+ $effect(() => {
60
+ return () => {
61
+ if (timer) clearTimeout(timer);
62
+ };
63
+ });
64
+ </script>
65
+
66
+ {#if value && value !== '""' && !is_empty(value)}
67
+ {#if show_copy_button || (buttons && buttons.some((btn) => typeof btn !== "string"))}
68
+ <IconButtonWrapper {buttons} {on_custom_button_click}>
69
+ {#if show_copy_button}
70
+ <IconButton
71
+ show_label={false}
72
+ label={copied ? "Copied" : "Copy"}
73
+ Icon={copied ? Check : Copy}
74
+ onclick={() => handle_copy()}
75
+ />
76
+ {/if}
77
+ </IconButtonWrapper>
78
+ {/if}
79
+ <div class="json-holder" style:max-height={json_max_height}>
80
+ <JSONNode
81
+ {value}
82
+ depth={0}
83
+ is_root={true}
84
+ {open}
85
+ {theme_mode}
86
+ {show_indices}
87
+ {interactive}
88
+ />
89
+ </div>
90
+ {:else}
91
+ <div class="empty-wrapper">
92
+ <Empty>
93
+ <JSONIcon />
94
+ </Empty>
95
+ </div>
96
+ {/if}
97
+
98
+ <style>
99
+ :global(.copied svg) {
100
+ animation: fade ease 300ms;
101
+ animation-fill-mode: forwards;
102
+ }
103
+
104
+ @keyframes fade {
105
+ 0% {
106
+ opacity: 0;
107
+ }
108
+ 100% {
109
+ opacity: 1;
110
+ }
111
+ }
112
+
113
+ .json-holder {
114
+ padding: var(--size-2);
115
+ overflow-y: auto;
116
+ }
117
+
118
+ .empty-wrapper {
119
+ min-height: calc(var(--size-32) - 20px);
120
+ height: 100%;
121
+ }
122
+ </style>
6.6.0/json/shared/JSONNode.svelte ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <script lang="ts">
2
+ import { tick } from "svelte";
3
+ import Self from "./JSONNode.svelte";
4
+
5
+ let {
6
+ value,
7
+ depth = 0,
8
+ is_root = false,
9
+ is_last_item = true,
10
+ key = null,
11
+ open = false,
12
+ theme_mode = "system" as "system" | "light" | "dark",
13
+ show_indices = false,
14
+ interactive = true
15
+ }: {
16
+ value: any;
17
+ depth?: number;
18
+ is_root?: boolean;
19
+ is_last_item?: boolean;
20
+ key?: string | number | null;
21
+ open?: boolean;
22
+ theme_mode?: "system" | "light" | "dark";
23
+ show_indices?: boolean;
24
+ interactive?: boolean;
25
+ } = $props();
26
+
27
+ let root_element = $state<HTMLElement>();
28
+ let collapsed = $state(open ? false : depth >= 3);
29
+ let child_nodes = $state<any[]>([]);
30
+
31
+ function is_collapsible(val: any): boolean {
32
+ return val !== null && (typeof val === "object" || Array.isArray(val));
33
+ }
34
+
35
+ async function toggle_collapse(): Promise<void> {
36
+ collapsed = !collapsed;
37
+ await tick();
38
+ }
39
+
40
+ function get_collapsed_preview(val: any): string {
41
+ if (Array.isArray(val)) return `Array(${val.length})`;
42
+ if (typeof val === "object" && val !== null)
43
+ return `Object(${Object.keys(val).length})`;
44
+ return String(val);
45
+ }
46
+
47
+ $effect(() => {
48
+ if (is_collapsible(value)) {
49
+ child_nodes = Object.entries(value);
50
+ } else {
51
+ child_nodes = [];
52
+ }
53
+ });
54
+
55
+ function updateLineNumbers(): void {
56
+ if (!root_element) return;
57
+ const lines = root_element.querySelectorAll(".line");
58
+ lines.forEach((line, index) => {
59
+ const line_number = line.querySelector(".line-number");
60
+ if (line_number) {
61
+ line_number.setAttribute("data-pseudo-content", (index + 1).toString());
62
+ line_number?.setAttribute(
63
+ "aria-roledescription",
64
+ `Line number ${index + 1}`
65
+ );
66
+ line_number?.setAttribute("title", `Line number ${index + 1}`);
67
+ }
68
+ });
69
+ }
70
+
71
+ $effect(() => {
72
+ value;
73
+ collapsed;
74
+
75
+ if (is_root && root_element) {
76
+ tick().then(() => {
77
+ updateLineNumbers();
78
+ });
79
+ }
80
+ });
81
+ </script>
82
+
83
+ <div
84
+ class="json-node"
85
+ class:root={is_root}
86
+ class:dark-mode={theme_mode === "dark"}
87
+ bind:this={root_element}
88
+ style="--depth: {depth};"
89
+ >
90
+ <div class="line" class:collapsed>
91
+ <span class="line-number"></span>
92
+ <span class="content">
93
+ {#if is_collapsible(value)}
94
+ <button
95
+ data-pseudo-content={interactive ? (collapsed ? "▶" : "▼") : ""}
96
+ aria-label={collapsed ? "Expand" : "Collapse"}
97
+ class="toggle"
98
+ disabled={!interactive}
99
+ onclick={toggle_collapse}
100
+ />
101
+ {/if}
102
+ {#if key !== null}
103
+ <span class="key">"{key}"</span><span class="punctuation colon"
104
+ >:
105
+ </span>
106
+ {/if}
107
+ {#if is_collapsible(value)}
108
+ <span
109
+ class="punctuation bracket"
110
+ class:square-bracket={Array.isArray(value)}
111
+ >{Array.isArray(value) ? "[" : "{"}</span
112
+ >
113
+ {#if collapsed}
114
+ <button onclick={toggle_collapse} class="preview">
115
+ {get_collapsed_preview(value)}
116
+ </button>
117
+ <span
118
+ class="punctuation bracket"
119
+ class:square-bracket={Array.isArray(value)}
120
+ >{Array.isArray(value) ? "]" : "}"}</span
121
+ >
122
+ {/if}
123
+ {:else if typeof value === "string"}
124
+ <span class="value string">"{value}"</span>
125
+ {:else if typeof value === "number"}
126
+ <span class="value number">{value}</span>
127
+ {:else if typeof value === "boolean"}
128
+ <span class="value bool">{value.toString()}</span>
129
+ {:else if value === null}
130
+ <span class="value null">null</span>
131
+ {:else}
132
+ <span>{value}</span>
133
+ {/if}
134
+ {#if !is_last_item && (!is_collapsible(value) || collapsed)}
135
+ <span class="punctuation">,</span>
136
+ {/if}
137
+ </span>
138
+ </div>
139
+
140
+ {#if is_collapsible(value)}
141
+ <div class="children" class:hidden={collapsed}>
142
+ {#each child_nodes as [subKey, subVal], i}
143
+ <Self
144
+ value={subVal}
145
+ depth={depth + 1}
146
+ is_last_item={i === child_nodes.length - 1}
147
+ key={Array.isArray(value) && !show_indices ? null : subKey}
148
+ {open}
149
+ {theme_mode}
150
+ {show_indices}
151
+ {interactive}
152
+ />
153
+ {/each}
154
+ <div class="line">
155
+ <span class="line-number"></span>
156
+ <span class="content">
157
+ <span
158
+ class="punctuation bracket"
159
+ class:square-bracket={Array.isArray(value)}
160
+ >{Array.isArray(value) ? "]" : "}"}</span
161
+ >
162
+ {#if !is_last_item}<span class="punctuation">,</span>{/if}
163
+ </span>
164
+ </div>
165
+ </div>
166
+ {/if}
167
+ </div>
168
+
169
+ <style>
170
+ .json-node {
171
+ font-family: var(--font-mono);
172
+ --text-color: #d18770;
173
+ --key-color: var(--text-color);
174
+ --string-color: #ce9178;
175
+ --number-color: #719fad;
176
+
177
+ --bracket-color: #5d8585;
178
+ --square-bracket-color: #be6069;
179
+ --punctuation-color: #8fbcbb;
180
+ --line-number-color: #6a737d;
181
+ --separator-color: var(--line-number-color);
182
+ }
183
+ .json-node.dark-mode {
184
+ --bracket-color: #7eb4b3;
185
+ --number-color: #638d9a;
186
+ }
187
+ .json-node.root {
188
+ position: relative;
189
+ padding-left: var(--size-14);
190
+ }
191
+ .json-node.root::before {
192
+ content: "";
193
+ position: absolute;
194
+ top: 0;
195
+ bottom: 0;
196
+ left: var(--size-11);
197
+ width: 1px;
198
+ background-color: var(--separator-color);
199
+ }
200
+ .line {
201
+ display: flex;
202
+ align-items: flex-start;
203
+ padding: 0;
204
+ margin: 0;
205
+ line-height: var(--line-md);
206
+ }
207
+ .line-number {
208
+ position: absolute;
209
+ left: 0;
210
+ width: calc(var(--size-7));
211
+ text-align: right;
212
+ color: var(--line-number-color);
213
+ user-select: none;
214
+ text-overflow: ellipsis;
215
+ text-overflow: ellipsis;
216
+ direction: rtl;
217
+ overflow: hidden;
218
+ }
219
+ .content {
220
+ flex: 1;
221
+ display: flex;
222
+ align-items: center;
223
+ padding-left: calc(var(--depth) * var(--size-2));
224
+ flex-wrap: wrap;
225
+ }
226
+ .children {
227
+ padding-left: var(--size-4);
228
+ }
229
+ .children.hidden {
230
+ display: none;
231
+ }
232
+ .key {
233
+ color: var(--key-color);
234
+ }
235
+ .string {
236
+ color: var(--string-color);
237
+ }
238
+ .number {
239
+ color: var(--number-color);
240
+ }
241
+ .bool {
242
+ color: var(--text-color);
243
+ }
244
+ .null {
245
+ color: var(--text-color);
246
+ }
247
+ .value {
248
+ margin-left: var(--spacing-md);
249
+ }
250
+ .punctuation {
251
+ color: var(--punctuation-color);
252
+ }
253
+ .bracket {
254
+ margin-left: var(--spacing-sm);
255
+ color: var(--bracket-color);
256
+ }
257
+ .square-bracket {
258
+ margin-left: var(--spacing-sm);
259
+ color: var(--square-bracket-color);
260
+ }
261
+ .toggle,
262
+ .preview {
263
+ background: none;
264
+ border: none;
265
+ color: inherit;
266
+ cursor: pointer;
267
+ padding: 0;
268
+ margin: 0;
269
+ }
270
+ .toggle {
271
+ user-select: none;
272
+ margin-right: var(--spacing-md);
273
+ }
274
+ .preview {
275
+ margin: 0 var(--spacing-sm) 0 var(--spacing-lg);
276
+ }
277
+ .preview:hover {
278
+ text-decoration: underline;
279
+ }
280
+
281
+ :global([data-pseudo-content])::before {
282
+ content: attr(data-pseudo-content);
283
+ }
284
+ </style>
6.6.0/json/types.ts ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { LoadingStatus } from "js/statustracker";
2
+ import type { CustomButton } from "@gradio/utils";
3
+
4
+ export interface JSONProps {
5
+ value: any;
6
+ open: boolean;
7
+ show_indices: boolean;
8
+ height: number | string | undefined;
9
+ min_height: number | string | undefined;
10
+ max_height: number | string | undefined;
11
+ theme_mode: "system" | "light" | "dark";
12
+ buttons: (string | CustomButton)[];
13
+ }
14
+
15
+ export interface JSONEvents {
16
+ change: never;
17
+ clear_status: LoadingStatus;
18
+ custom_button_click: { id: number };
19
+ }