@gradio/code 0.17.1 → 0.17.2
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/CHANGELOG.md +12 -0
- package/Example.svelte +7 -3
- package/Index.svelte +3 -3
- package/dist/Example.svelte +7 -3
- package/dist/Example.svelte.d.ts +4 -18
- package/dist/Index.svelte +3 -3
- package/dist/shared/Code.svelte +64 -33
- package/dist/shared/Code.svelte.d.ts +8 -23
- package/dist/shared/Copy.svelte +7 -2
- package/dist/shared/Copy.svelte.d.ts +4 -18
- package/dist/shared/Download.svelte +10 -6
- package/dist/shared/Download.svelte.d.ts +4 -18
- package/dist/shared/Widgets.svelte +13 -4
- package/dist/shared/Widgets.svelte.d.ts +4 -18
- package/package.json +6 -6
- package/shared/Code.svelte +64 -33
- package/shared/Copy.svelte +7 -2
- package/shared/Download.svelte +10 -6
- package/shared/Widgets.svelte +13 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @gradio/code
|
|
2
2
|
|
|
3
|
+
## 0.17.2
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- [#12809](https://github.com/gradio-app/gradio/pull/12809) [`8409b7a`](https://github.com/gradio-app/gradio/commit/8409b7ab51fb36d8973d2a3f1bc3557489f7e1c5) - Migrate js/code. Thanks @aliabid94!
|
|
8
|
+
|
|
9
|
+
### Dependency updates
|
|
10
|
+
|
|
11
|
+
- @gradio/atoms@0.21.0
|
|
12
|
+
- @gradio/statustracker@0.12.3
|
|
13
|
+
- @gradio/upload@0.17.5
|
|
14
|
+
|
|
3
15
|
## 0.17.1
|
|
4
16
|
|
|
5
17
|
### Fixes
|
package/Example.svelte
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
interface Props {
|
|
3
|
+
value: string | null;
|
|
4
|
+
type: "gallery" | "table";
|
|
5
|
+
selected?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let { value, type, selected = false }: Props = $props();
|
|
5
9
|
|
|
6
10
|
function truncate_text(text: string | null, max_length = 60): string {
|
|
7
11
|
if (!text) return "";
|
package/Index.svelte
CHANGED
|
@@ -88,9 +88,9 @@
|
|
|
88
88
|
show_line_numbers={gradio.props.show_line_numbers}
|
|
89
89
|
autocomplete={gradio.props.autocomplete}
|
|
90
90
|
readonly={!gradio.shared.interactive}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
onblur={() => gradio.dispatch("blur")}
|
|
92
|
+
onfocus={() => gradio.dispatch("focus")}
|
|
93
|
+
oninput={() => gradio.dispatch("input")}
|
|
94
94
|
/>
|
|
95
95
|
{/if}
|
|
96
96
|
</Block>
|
package/dist/Example.svelte
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
interface Props {
|
|
3
|
+
value: string | null;
|
|
4
|
+
type: "gallery" | "table";
|
|
5
|
+
selected?: boolean;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let { value, type, selected = false }: Props = $props();
|
|
5
9
|
|
|
6
10
|
function truncate_text(text: string | null, max_length = 60): string {
|
|
7
11
|
if (!text) return "";
|
package/dist/Example.svelte.d.ts
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
interface
|
|
2
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
-
$$bindings?: Bindings;
|
|
4
|
-
} & Exports;
|
|
5
|
-
(internal: unknown, props: Props & {
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
declare const Example: $$__sveltets_2_IsomorphicComponent<{
|
|
1
|
+
interface Props {
|
|
15
2
|
value: string | null;
|
|
16
3
|
type: "gallery" | "table";
|
|
17
4
|
selected?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type Example = InstanceType<typeof Example>;
|
|
5
|
+
}
|
|
6
|
+
declare const Example: import("svelte").Component<Props, {}, "">;
|
|
7
|
+
type Example = ReturnType<typeof Example>;
|
|
22
8
|
export default Example;
|
package/dist/Index.svelte
CHANGED
|
@@ -88,9 +88,9 @@
|
|
|
88
88
|
show_line_numbers={gradio.props.show_line_numbers}
|
|
89
89
|
autocomplete={gradio.props.autocomplete}
|
|
90
90
|
readonly={!gradio.shared.interactive}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
onblur={() => gradio.dispatch("blur")}
|
|
92
|
+
onfocus={() => gradio.dispatch("focus")}
|
|
93
|
+
oninput={() => gradio.dispatch("input")}
|
|
94
94
|
/>
|
|
95
95
|
{/if}
|
|
96
96
|
</Block>
|
package/dist/shared/Code.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
3
|
import {
|
|
4
4
|
EditorView,
|
|
5
5
|
ViewUpdate,
|
|
@@ -16,41 +16,72 @@
|
|
|
16
16
|
import { basicSetup } from "./extensions";
|
|
17
17
|
import { getLanguageExtension } from "./language";
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let
|
|
19
|
+
interface Props {
|
|
20
|
+
class_names?: string;
|
|
21
|
+
value?: string;
|
|
22
|
+
dark_mode: boolean;
|
|
23
|
+
basic?: boolean;
|
|
24
|
+
language: string;
|
|
25
|
+
lines?: number;
|
|
26
|
+
max_lines?: number | null;
|
|
27
|
+
extensions?: Extension[];
|
|
28
|
+
use_tab?: boolean;
|
|
29
|
+
readonly?: boolean;
|
|
30
|
+
placeholder?: string | HTMLElement | null | undefined;
|
|
31
|
+
wrap_lines?: boolean;
|
|
32
|
+
show_line_numbers?: boolean;
|
|
33
|
+
autocomplete?: boolean;
|
|
34
|
+
onchange?: (value: string) => void;
|
|
35
|
+
onblur?: () => void;
|
|
36
|
+
onfocus?: () => void;
|
|
37
|
+
oninput?: () => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
class_names = "",
|
|
42
|
+
value = $bindable(),
|
|
43
|
+
dark_mode,
|
|
44
|
+
basic = true,
|
|
45
|
+
language,
|
|
46
|
+
lines = 5,
|
|
47
|
+
max_lines = null,
|
|
48
|
+
extensions = [],
|
|
49
|
+
use_tab = true,
|
|
50
|
+
readonly = false,
|
|
51
|
+
placeholder = undefined,
|
|
52
|
+
wrap_lines = false,
|
|
53
|
+
show_line_numbers = true,
|
|
54
|
+
autocomplete = false,
|
|
55
|
+
onchange,
|
|
56
|
+
onblur,
|
|
57
|
+
onfocus,
|
|
58
|
+
oninput
|
|
59
|
+
}: Props = $props();
|
|
60
|
+
|
|
61
|
+
let lang_extension: Extension | undefined = $state();
|
|
41
62
|
let element: HTMLDivElement;
|
|
42
63
|
let view: EditorView;
|
|
43
64
|
|
|
44
|
-
$: get_lang(language);
|
|
45
|
-
|
|
46
65
|
async function get_lang(val: string): Promise<void> {
|
|
47
66
|
const ext = await getLanguageExtension(val);
|
|
48
67
|
lang_extension = ext;
|
|
49
68
|
}
|
|
50
69
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
$effect(() => {
|
|
71
|
+
get_lang(language);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
$effect(() => {
|
|
75
|
+
lang_extension;
|
|
76
|
+
readonly;
|
|
77
|
+
reconfigure();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
$effect(() => {
|
|
81
|
+
set_doc(value);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
update_lines();
|
|
54
85
|
|
|
55
86
|
function set_doc(new_doc: string): void {
|
|
56
87
|
if (view && new_doc !== view.state.doc.toString()) {
|
|
@@ -81,11 +112,11 @@
|
|
|
81
112
|
}
|
|
82
113
|
|
|
83
114
|
function handle_focus(): void {
|
|
84
|
-
|
|
115
|
+
onfocus?.();
|
|
85
116
|
}
|
|
86
117
|
|
|
87
118
|
function handle_blur(): void {
|
|
88
|
-
|
|
119
|
+
onblur?.();
|
|
89
120
|
}
|
|
90
121
|
|
|
91
122
|
function getGutterLineHeight(_view: EditorView): string | null {
|
|
@@ -136,10 +167,10 @@
|
|
|
136
167
|
|
|
137
168
|
const user_change = is_user_input(vu);
|
|
138
169
|
if (user_change) {
|
|
139
|
-
|
|
140
|
-
|
|
170
|
+
onchange?.(text);
|
|
171
|
+
oninput?.();
|
|
141
172
|
} else {
|
|
142
|
-
|
|
173
|
+
onchange?.(text);
|
|
143
174
|
}
|
|
144
175
|
|
|
145
176
|
view.requestMeasure({ read: resize });
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import { type Extension } from "@codemirror/state";
|
|
2
|
-
interface
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports & {
|
|
10
|
-
$set?: any;
|
|
11
|
-
$on?: any;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
declare const Code: $$__sveltets_2_IsomorphicComponent<{
|
|
2
|
+
interface Props {
|
|
16
3
|
class_names?: string;
|
|
17
4
|
value?: string;
|
|
18
5
|
dark_mode: boolean;
|
|
@@ -27,13 +14,11 @@ declare const Code: $$__sveltets_2_IsomorphicComponent<{
|
|
|
27
14
|
wrap_lines?: boolean;
|
|
28
15
|
show_line_numbers?: boolean;
|
|
29
16
|
autocomplete?: boolean;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}, {}, {}, string>;
|
|
38
|
-
type Code = InstanceType<typeof Code>;
|
|
17
|
+
onchange?: (value: string) => void;
|
|
18
|
+
onblur?: () => void;
|
|
19
|
+
onfocus?: () => void;
|
|
20
|
+
oninput?: () => void;
|
|
21
|
+
}
|
|
22
|
+
declare const Code: import("svelte").Component<Props, {}, "value">;
|
|
23
|
+
type Code = ReturnType<typeof Code>;
|
|
39
24
|
export default Code;
|
package/dist/shared/Copy.svelte
CHANGED
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
import { Copy, Check } from "@gradio/icons";
|
|
4
4
|
import { IconButton } from "@gradio/atoms";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
interface Props {
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let { value }: Props = $props();
|
|
11
|
+
|
|
12
|
+
let copied = $state(false);
|
|
8
13
|
let timer: NodeJS.Timeout;
|
|
9
14
|
|
|
10
15
|
function copy_feedback(): void {
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
import { Copy } from "@gradio/icons";
|
|
2
|
-
interface
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports & {
|
|
10
|
-
$set?: any;
|
|
11
|
-
$on?: any;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
declare const Copy: $$__sveltets_2_IsomorphicComponent<{
|
|
2
|
+
interface Props {
|
|
16
3
|
value: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
type Copy = InstanceType<typeof Copy>;
|
|
4
|
+
}
|
|
5
|
+
declare const Copy: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type Copy = ReturnType<typeof Copy>;
|
|
21
7
|
export default Copy;
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
import { DownloadLink } from "@gradio/atoms";
|
|
5
5
|
import { IconButton } from "@gradio/atoms";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
interface Props {
|
|
8
|
+
value: string;
|
|
9
|
+
language: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { value, language }: Props = $props();
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
let ext = $derived(get_ext_for_type(language));
|
|
11
15
|
|
|
12
16
|
function get_ext_for_type(type: string): string {
|
|
13
17
|
const exts: Record<string, string> = {
|
|
@@ -36,7 +40,7 @@
|
|
|
36
40
|
return exts[type] || "txt";
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
let copied = false;
|
|
43
|
+
let copied = $state(false);
|
|
40
44
|
let timer: NodeJS.Timeout;
|
|
41
45
|
|
|
42
46
|
function copy_feedback(): void {
|
|
@@ -47,7 +51,7 @@
|
|
|
47
51
|
}, 2000);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
let download_value = $derived(URL.createObjectURL(new Blob([value])));
|
|
51
55
|
|
|
52
56
|
onDestroy(() => {
|
|
53
57
|
if (timer) clearTimeout(timer);
|
|
@@ -57,7 +61,7 @@
|
|
|
57
61
|
<DownloadLink
|
|
58
62
|
download="file.{ext}"
|
|
59
63
|
href={download_value}
|
|
60
|
-
|
|
64
|
+
onclick={copy_feedback}
|
|
61
65
|
>
|
|
62
66
|
<IconButton Icon={copied ? Check : Download} />
|
|
63
67
|
</DownloadLink>
|
|
@@ -1,22 +1,8 @@
|
|
|
1
1
|
import { Download } from "@gradio/icons";
|
|
2
|
-
interface
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports & {
|
|
10
|
-
$set?: any;
|
|
11
|
-
$on?: any;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
declare const Download: $$__sveltets_2_IsomorphicComponent<{
|
|
2
|
+
interface Props {
|
|
16
3
|
value: string;
|
|
17
4
|
language: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type Download = InstanceType<typeof Download>;
|
|
5
|
+
}
|
|
6
|
+
declare const Download: import("svelte").Component<Props, {}, "">;
|
|
7
|
+
type Download = ReturnType<typeof Download>;
|
|
22
8
|
export default Download;
|
|
@@ -4,10 +4,19 @@
|
|
|
4
4
|
import { IconButtonWrapper } from "@gradio/atoms";
|
|
5
5
|
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
interface Props {
|
|
8
|
+
value: string;
|
|
9
|
+
language: string;
|
|
10
|
+
buttons?: (string | CustomButtonType)[] | null;
|
|
11
|
+
on_custom_button_click?: ((id: number) => void) | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
value,
|
|
16
|
+
language,
|
|
17
|
+
buttons = null,
|
|
18
|
+
on_custom_button_click = null
|
|
19
|
+
}: Props = $props();
|
|
11
20
|
</script>
|
|
12
21
|
|
|
13
22
|
<IconButtonWrapper {buttons} {on_custom_button_click}>
|
|
@@ -1,24 +1,10 @@
|
|
|
1
1
|
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
|
2
|
-
interface
|
|
3
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
-
$$bindings?: Bindings;
|
|
5
|
-
} & Exports;
|
|
6
|
-
(internal: unknown, props: Props & {
|
|
7
|
-
$$events?: Events;
|
|
8
|
-
$$slots?: Slots;
|
|
9
|
-
}): Exports & {
|
|
10
|
-
$set?: any;
|
|
11
|
-
$on?: any;
|
|
12
|
-
};
|
|
13
|
-
z_$$bindings?: Bindings;
|
|
14
|
-
}
|
|
15
|
-
declare const Widgets: $$__sveltets_2_IsomorphicComponent<{
|
|
2
|
+
interface Props {
|
|
16
3
|
value: string;
|
|
17
4
|
language: string;
|
|
18
5
|
buttons?: (string | CustomButtonType)[] | null;
|
|
19
6
|
on_custom_button_click?: ((id: number) => void) | null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type Widgets = InstanceType<typeof Widgets>;
|
|
7
|
+
}
|
|
8
|
+
declare const Widgets: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type Widgets = ReturnType<typeof Widgets>;
|
|
24
10
|
export default Widgets;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradio/code",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.2",
|
|
4
4
|
"description": "Gradio UI packages",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"cm6-theme-basic-dark": "^0.2.0",
|
|
28
28
|
"cm6-theme-basic-light": "^0.2.0",
|
|
29
29
|
"codemirror": "^6.0.2",
|
|
30
|
-
"@gradio/atoms": "^0.
|
|
31
|
-
"@gradio/statustracker": "^0.12.
|
|
32
|
-
"@gradio/
|
|
33
|
-
"@gradio/
|
|
34
|
-
"@gradio/
|
|
30
|
+
"@gradio/atoms": "^0.21.0",
|
|
31
|
+
"@gradio/statustracker": "^0.12.3",
|
|
32
|
+
"@gradio/upload": "^0.17.5",
|
|
33
|
+
"@gradio/utils": "^0.11.2",
|
|
34
|
+
"@gradio/icons": "^0.15.1"
|
|
35
35
|
},
|
|
36
36
|
"main_changeset": true,
|
|
37
37
|
"main": "./Index.svelte",
|
package/shared/Code.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
3
|
import {
|
|
4
4
|
EditorView,
|
|
5
5
|
ViewUpdate,
|
|
@@ -16,41 +16,72 @@
|
|
|
16
16
|
import { basicSetup } from "./extensions";
|
|
17
17
|
import { getLanguageExtension } from "./language";
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
let
|
|
19
|
+
interface Props {
|
|
20
|
+
class_names?: string;
|
|
21
|
+
value?: string;
|
|
22
|
+
dark_mode: boolean;
|
|
23
|
+
basic?: boolean;
|
|
24
|
+
language: string;
|
|
25
|
+
lines?: number;
|
|
26
|
+
max_lines?: number | null;
|
|
27
|
+
extensions?: Extension[];
|
|
28
|
+
use_tab?: boolean;
|
|
29
|
+
readonly?: boolean;
|
|
30
|
+
placeholder?: string | HTMLElement | null | undefined;
|
|
31
|
+
wrap_lines?: boolean;
|
|
32
|
+
show_line_numbers?: boolean;
|
|
33
|
+
autocomplete?: boolean;
|
|
34
|
+
onchange?: (value: string) => void;
|
|
35
|
+
onblur?: () => void;
|
|
36
|
+
onfocus?: () => void;
|
|
37
|
+
oninput?: () => void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
class_names = "",
|
|
42
|
+
value = $bindable(),
|
|
43
|
+
dark_mode,
|
|
44
|
+
basic = true,
|
|
45
|
+
language,
|
|
46
|
+
lines = 5,
|
|
47
|
+
max_lines = null,
|
|
48
|
+
extensions = [],
|
|
49
|
+
use_tab = true,
|
|
50
|
+
readonly = false,
|
|
51
|
+
placeholder = undefined,
|
|
52
|
+
wrap_lines = false,
|
|
53
|
+
show_line_numbers = true,
|
|
54
|
+
autocomplete = false,
|
|
55
|
+
onchange,
|
|
56
|
+
onblur,
|
|
57
|
+
onfocus,
|
|
58
|
+
oninput
|
|
59
|
+
}: Props = $props();
|
|
60
|
+
|
|
61
|
+
let lang_extension: Extension | undefined = $state();
|
|
41
62
|
let element: HTMLDivElement;
|
|
42
63
|
let view: EditorView;
|
|
43
64
|
|
|
44
|
-
$: get_lang(language);
|
|
45
|
-
|
|
46
65
|
async function get_lang(val: string): Promise<void> {
|
|
47
66
|
const ext = await getLanguageExtension(val);
|
|
48
67
|
lang_extension = ext;
|
|
49
68
|
}
|
|
50
69
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
$effect(() => {
|
|
71
|
+
get_lang(language);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
$effect(() => {
|
|
75
|
+
lang_extension;
|
|
76
|
+
readonly;
|
|
77
|
+
reconfigure();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
$effect(() => {
|
|
81
|
+
set_doc(value);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
update_lines();
|
|
54
85
|
|
|
55
86
|
function set_doc(new_doc: string): void {
|
|
56
87
|
if (view && new_doc !== view.state.doc.toString()) {
|
|
@@ -81,11 +112,11 @@
|
|
|
81
112
|
}
|
|
82
113
|
|
|
83
114
|
function handle_focus(): void {
|
|
84
|
-
|
|
115
|
+
onfocus?.();
|
|
85
116
|
}
|
|
86
117
|
|
|
87
118
|
function handle_blur(): void {
|
|
88
|
-
|
|
119
|
+
onblur?.();
|
|
89
120
|
}
|
|
90
121
|
|
|
91
122
|
function getGutterLineHeight(_view: EditorView): string | null {
|
|
@@ -136,10 +167,10 @@
|
|
|
136
167
|
|
|
137
168
|
const user_change = is_user_input(vu);
|
|
138
169
|
if (user_change) {
|
|
139
|
-
|
|
140
|
-
|
|
170
|
+
onchange?.(text);
|
|
171
|
+
oninput?.();
|
|
141
172
|
} else {
|
|
142
|
-
|
|
173
|
+
onchange?.(text);
|
|
143
174
|
}
|
|
144
175
|
|
|
145
176
|
view.requestMeasure({ read: resize });
|
package/shared/Copy.svelte
CHANGED
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
import { Copy, Check } from "@gradio/icons";
|
|
4
4
|
import { IconButton } from "@gradio/atoms";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
interface Props {
|
|
7
|
+
value: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let { value }: Props = $props();
|
|
11
|
+
|
|
12
|
+
let copied = $state(false);
|
|
8
13
|
let timer: NodeJS.Timeout;
|
|
9
14
|
|
|
10
15
|
function copy_feedback(): void {
|
package/shared/Download.svelte
CHANGED
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
import { DownloadLink } from "@gradio/atoms";
|
|
5
5
|
import { IconButton } from "@gradio/atoms";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
interface Props {
|
|
8
|
+
value: string;
|
|
9
|
+
language: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let { value, language }: Props = $props();
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
let ext = $derived(get_ext_for_type(language));
|
|
11
15
|
|
|
12
16
|
function get_ext_for_type(type: string): string {
|
|
13
17
|
const exts: Record<string, string> = {
|
|
@@ -36,7 +40,7 @@
|
|
|
36
40
|
return exts[type] || "txt";
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
let copied = false;
|
|
43
|
+
let copied = $state(false);
|
|
40
44
|
let timer: NodeJS.Timeout;
|
|
41
45
|
|
|
42
46
|
function copy_feedback(): void {
|
|
@@ -47,7 +51,7 @@
|
|
|
47
51
|
}, 2000);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
|
|
54
|
+
let download_value = $derived(URL.createObjectURL(new Blob([value])));
|
|
51
55
|
|
|
52
56
|
onDestroy(() => {
|
|
53
57
|
if (timer) clearTimeout(timer);
|
|
@@ -57,7 +61,7 @@
|
|
|
57
61
|
<DownloadLink
|
|
58
62
|
download="file.{ext}"
|
|
59
63
|
href={download_value}
|
|
60
|
-
|
|
64
|
+
onclick={copy_feedback}
|
|
61
65
|
>
|
|
62
66
|
<IconButton Icon={copied ? Check : Download} />
|
|
63
67
|
</DownloadLink>
|
package/shared/Widgets.svelte
CHANGED
|
@@ -4,10 +4,19 @@
|
|
|
4
4
|
import { IconButtonWrapper } from "@gradio/atoms";
|
|
5
5
|
import type { CustomButton as CustomButtonType } from "@gradio/utils";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
interface Props {
|
|
8
|
+
value: string;
|
|
9
|
+
language: string;
|
|
10
|
+
buttons?: (string | CustomButtonType)[] | null;
|
|
11
|
+
on_custom_button_click?: ((id: number) => void) | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let {
|
|
15
|
+
value,
|
|
16
|
+
language,
|
|
17
|
+
buttons = null,
|
|
18
|
+
on_custom_button_click = null
|
|
19
|
+
}: Props = $props();
|
|
11
20
|
</script>
|
|
12
21
|
|
|
13
22
|
<IconButtonWrapper {buttons} {on_custom_button_click}>
|