@gradio/code 0.15.1-dev.0 → 0.16.0-dev.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/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # @gradio/code
2
2
 
3
+ ## 0.16.0-dev.3
4
+
5
+ ### Dependency updates
6
+
7
+ - @gradio/atoms@0.19.0-dev.1
8
+ - @gradio/statustracker@0.12.0-dev.1
9
+ - @gradio/upload@0.17.2-dev.2
10
+
11
+ ## 0.16.0-dev.2
12
+
13
+ ### Features
14
+
15
+ - [#12357](https://github.com/gradio-app/gradio/pull/12357) [`c9cf634`](https://github.com/gradio-app/gradio/commit/c9cf634a9cd34b4adadde1a6a98d60faf732639a) - Fix various event issues. Thanks @pngwn!
16
+
17
+ ## 0.15.1-dev.1
18
+
19
+ ### Dependency updates
20
+
21
+ - @gradio/atoms@0.18.2-dev.0
22
+ - @gradio/upload@0.17.2-dev.1
23
+ - @gradio/utils@0.10.3-dev.0
24
+ - @gradio/statustracker@0.12.0-dev.0
25
+ - @gradio/icons@0.15.0-dev.0
26
+
3
27
  ## 0.15.1-dev.0
4
28
 
5
29
  ### Dependency updates
package/Index.svelte CHANGED
@@ -7,97 +7,83 @@
7
7
  </script>
8
8
 
9
9
  <script lang="ts">
10
- import type { Gradio } from "@gradio/utils";
11
- import { afterUpdate } from "svelte";
12
-
13
- import type { LoadingStatus } from "@gradio/statustracker";
10
+ import { Gradio } from "@gradio/utils";
11
+ import type { CodeProps, CodeEvents } from "./types";
12
+ import { StatusTracker } from "@gradio/statustracker";
14
13
 
15
14
  import Code from "./shared/Code.svelte";
16
15
  import Widget from "./shared/Widgets.svelte";
17
- import { StatusTracker } from "@gradio/statustracker";
18
16
  import { Block, BlockLabel, Empty } from "@gradio/atoms";
19
17
  import { Code as CodeIcon } from "@gradio/icons";
20
18
 
21
- export let gradio: Gradio<{
22
- change: typeof value;
23
- input: never;
24
- blur: never;
25
- focus: never;
26
- clear_status: LoadingStatus;
27
- }>;
28
- export let value = "";
29
- export let value_is_output = false;
30
- export let language = "";
31
- export let lines = 5;
32
- export let max_lines: number | undefined = undefined;
33
- export let elem_id = "";
34
- export let elem_classes: string[] = [];
35
- export let visible: boolean | "hidden" = true;
36
- export let label = gradio.i18n("code.code");
37
- export let show_label = true;
38
- export let loading_status: LoadingStatus;
39
- export let scale: number | null = null;
40
- export let min_width: number | undefined = undefined;
41
- export let wrap_lines = false;
42
- export let show_line_numbers = true;
43
- export let autocomplete = false;
19
+ const props = $props();
20
+ const gradio = new Gradio<CodeEvents, CodeProps>(props);
44
21
 
45
- export let interactive: boolean;
22
+ let dark_mode = gradio.shared.theme === "dark";
46
23
 
47
- let dark_mode = gradio.theme === "dark";
24
+ let label = $derived(gradio.shared.label || gradio.i18n("code.code"));
25
+ let old_value = $state(gradio.props.value);
26
+ let first_change = true;
48
27
 
49
- function handle_change(): void {
50
- gradio.dispatch("change", value);
51
- if (!value_is_output) {
52
- gradio.dispatch("input");
28
+ $effect(() => {
29
+ if (first_change) {
30
+ first_change = false;
31
+ return;
32
+ }
33
+ if (old_value != gradio.props.value) {
34
+ old_value = gradio.props.value;
35
+ gradio.dispatch("change");
53
36
  }
54
- }
55
- afterUpdate(() => {
56
- value_is_output = false;
57
37
  });
58
- $: value, handle_change();
59
38
  </script>
60
39
 
61
40
  <Block
62
- height={max_lines && "fit-content"}
41
+ height={gradio.props.max_lines && "fit-content"}
63
42
  variant={"solid"}
64
43
  padding={false}
65
- {elem_id}
66
- {elem_classes}
67
- {visible}
68
- {scale}
69
- {min_width}
44
+ elem_id={gradio.shared.elem_id}
45
+ elem_classes={gradio.shared.elem_classes}
46
+ visible={gradio.shared.visible}
47
+ scale={gradio.shared.scale}
48
+ min_width={gradio.shared.min_width}
70
49
  >
71
50
  <StatusTracker
72
- autoscroll={gradio.autoscroll}
51
+ autoscroll={gradio.shared.autoscroll}
73
52
  i18n={gradio.i18n}
74
- {...loading_status}
75
- on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
53
+ {...gradio.shared.loading_status}
54
+ on:clear_status={() =>
55
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
76
56
  />
77
57
 
78
- {#if show_label}
79
- <BlockLabel Icon={CodeIcon} {show_label} {label} float={false} />
58
+ {#if gradio.shared.show_label}
59
+ <BlockLabel
60
+ Icon={CodeIcon}
61
+ show_label={gradio.shared.show_label}
62
+ {label}
63
+ float={false}
64
+ />
80
65
  {/if}
81
66
 
82
- {#if !value && !interactive}
67
+ {#if !gradio.props.value && !gradio.shared.interactive}
83
68
  <Empty unpadded_box={true} size="large">
84
69
  <CodeIcon />
85
70
  </Empty>
86
71
  {:else}
87
- <Widget {language} {value} />
72
+ <Widget language={gradio.props.language} value={gradio.props.value} />
88
73
 
89
74
  <Code
90
- bind:value
91
- {language}
92
- {lines}
93
- {max_lines}
75
+ bind:value={gradio.props.value}
76
+ language={gradio.props.language}
77
+ lines={gradio.props.lines}
78
+ max_lines={gradio.props.max_lines}
94
79
  {dark_mode}
95
- {wrap_lines}
96
- {show_line_numbers}
97
- {autocomplete}
98
- readonly={!interactive}
80
+ wrap_lines={gradio.props.wrap_lines}
81
+ show_line_numbers={gradio.props.show_line_numbers}
82
+ autocomplete={gradio.props.autocomplete}
83
+ readonly={!gradio.shared.interactive}
99
84
  on:blur={() => gradio.dispatch("blur")}
100
85
  on:focus={() => gradio.dispatch("focus")}
86
+ on:input={() => gradio.dispatch("input")}
101
87
  />
102
88
  {/if}
103
89
  </Block>
@@ -1,12 +1,14 @@
1
- <script>export let value;
2
- export let type;
3
- export let selected = false;
4
- function truncate_text(text, max_length = 60) {
5
- if (!text) return "";
6
- const str = String(text);
7
- if (str.length <= max_length) return str;
8
- return str.slice(0, max_length) + "...";
9
- }
1
+ <script lang="ts">
2
+ export let value: string | null;
3
+ export let type: "gallery" | "table";
4
+ export let selected = false;
5
+
6
+ function truncate_text(text: string | null, max_length = 60): string {
7
+ if (!text) return "";
8
+ const str = String(text);
9
+ if (str.length <= max_length) return str;
10
+ return str.slice(0, max_length) + "...";
11
+ }
10
12
  </script>
11
13
 
12
14
  <pre
@@ -1,20 +1,22 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- value: string | null;
5
- type: "gallery" | "table";
6
- selected?: boolean;
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
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;
7
11
  };
8
- events: {
9
- [evt: string]: CustomEvent<any>;
10
- };
11
- slots: {};
12
- exports?: {} | undefined;
13
- bindings?: string | undefined;
14
- };
15
- export type ExampleProps = typeof __propDef.props;
16
- export type ExampleEvents = typeof __propDef.events;
17
- export type ExampleSlots = typeof __propDef.slots;
18
- export default class Example extends SvelteComponent<ExampleProps, ExampleEvents, ExampleSlots> {
12
+ z_$$bindings?: Bindings;
19
13
  }
20
- export {};
14
+ declare const Example: $$__sveltets_2_IsomorphicComponent<{
15
+ value: string | null;
16
+ type: "gallery" | "table";
17
+ selected?: boolean;
18
+ }, {
19
+ [evt: string]: CustomEvent<any>;
20
+ }, {}, {}, string>;
21
+ type Example = InstanceType<typeof Example>;
22
+ export default Example;
package/dist/Index.svelte CHANGED
@@ -1,87 +1,89 @@
1
- <script context="module">export { default as BaseCode } from "./shared/Code.svelte";
2
- export { default as BaseCopy } from "./shared/Copy.svelte";
3
- export { default as BaseDownload } from "./shared/Download.svelte";
4
- export { default as BaseWidget } from "./shared/Widgets.svelte";
5
- export { default as BaseExample } from "./Example.svelte";
1
+ <script context="module" lang="ts">
2
+ export { default as BaseCode } from "./shared/Code.svelte";
3
+ export { default as BaseCopy } from "./shared/Copy.svelte";
4
+ export { default as BaseDownload } from "./shared/Download.svelte";
5
+ export { default as BaseWidget } from "./shared/Widgets.svelte";
6
+ export { default as BaseExample } from "./Example.svelte";
6
7
  </script>
7
8
 
8
- <script>import { afterUpdate } from "svelte";
9
- import Code from "./shared/Code.svelte";
10
- import Widget from "./shared/Widgets.svelte";
11
- import { StatusTracker } from "@gradio/statustracker";
12
- import { Block, BlockLabel, Empty } from "@gradio/atoms";
13
- import { Code as CodeIcon } from "@gradio/icons";
14
- export let gradio;
15
- export let value = "";
16
- export let value_is_output = false;
17
- export let language = "";
18
- export let lines = 5;
19
- export let max_lines = void 0;
20
- export let elem_id = "";
21
- export let elem_classes = [];
22
- export let visible = true;
23
- export let label = gradio.i18n("code.code");
24
- export let show_label = true;
25
- export let loading_status;
26
- export let scale = null;
27
- export let min_width = void 0;
28
- export let wrap_lines = false;
29
- export let show_line_numbers = true;
30
- export let autocomplete = false;
31
- export let interactive;
32
- let dark_mode = gradio.theme === "dark";
33
- function handle_change() {
34
- gradio.dispatch("change", value);
35
- if (!value_is_output) {
36
- gradio.dispatch("input");
37
- }
38
- }
39
- afterUpdate(() => {
40
- value_is_output = false;
41
- });
42
- $: value, handle_change();
9
+ <script lang="ts">
10
+ import { Gradio } from "@gradio/utils";
11
+ import type { CodeProps, CodeEvents } from "./types";
12
+ import { StatusTracker } from "@gradio/statustracker";
13
+
14
+ import Code from "./shared/Code.svelte";
15
+ import Widget from "./shared/Widgets.svelte";
16
+ import { Block, BlockLabel, Empty } from "@gradio/atoms";
17
+ import { Code as CodeIcon } from "@gradio/icons";
18
+
19
+ const props = $props();
20
+ const gradio = new Gradio<CodeEvents, CodeProps>(props);
21
+
22
+ let dark_mode = gradio.shared.theme === "dark";
23
+
24
+ let label = $derived(gradio.shared.label || gradio.i18n("code.code"));
25
+ let old_value = $state(gradio.props.value);
26
+ let first_change = true;
27
+
28
+ $effect(() => {
29
+ if (first_change) {
30
+ first_change = false;
31
+ return;
32
+ }
33
+ if (old_value != gradio.props.value) {
34
+ old_value = gradio.props.value;
35
+ gradio.dispatch("change");
36
+ }
37
+ });
43
38
  </script>
44
39
 
45
40
  <Block
46
- height={max_lines && "fit-content"}
41
+ height={gradio.props.max_lines && "fit-content"}
47
42
  variant={"solid"}
48
43
  padding={false}
49
- {elem_id}
50
- {elem_classes}
51
- {visible}
52
- {scale}
53
- {min_width}
44
+ elem_id={gradio.shared.elem_id}
45
+ elem_classes={gradio.shared.elem_classes}
46
+ visible={gradio.shared.visible}
47
+ scale={gradio.shared.scale}
48
+ min_width={gradio.shared.min_width}
54
49
  >
55
50
  <StatusTracker
56
- autoscroll={gradio.autoscroll}
51
+ autoscroll={gradio.shared.autoscroll}
57
52
  i18n={gradio.i18n}
58
- {...loading_status}
59
- on:clear_status={() => gradio.dispatch("clear_status", loading_status)}
53
+ {...gradio.shared.loading_status}
54
+ on:clear_status={() =>
55
+ gradio.dispatch("clear_status", gradio.shared.loading_status)}
60
56
  />
61
57
 
62
- {#if show_label}
63
- <BlockLabel Icon={CodeIcon} {show_label} {label} float={false} />
58
+ {#if gradio.shared.show_label}
59
+ <BlockLabel
60
+ Icon={CodeIcon}
61
+ show_label={gradio.shared.show_label}
62
+ {label}
63
+ float={false}
64
+ />
64
65
  {/if}
65
66
 
66
- {#if !value && !interactive}
67
+ {#if !gradio.props.value && !gradio.shared.interactive}
67
68
  <Empty unpadded_box={true} size="large">
68
69
  <CodeIcon />
69
70
  </Empty>
70
71
  {:else}
71
- <Widget {language} {value} />
72
+ <Widget language={gradio.props.language} value={gradio.props.value} />
72
73
 
73
74
  <Code
74
- bind:value
75
- {language}
76
- {lines}
77
- {max_lines}
75
+ bind:value={gradio.props.value}
76
+ language={gradio.props.language}
77
+ lines={gradio.props.lines}
78
+ max_lines={gradio.props.max_lines}
78
79
  {dark_mode}
79
- {wrap_lines}
80
- {show_line_numbers}
81
- {autocomplete}
82
- readonly={!interactive}
80
+ wrap_lines={gradio.props.wrap_lines}
81
+ show_line_numbers={gradio.props.show_line_numbers}
82
+ autocomplete={gradio.props.autocomplete}
83
+ readonly={!gradio.shared.interactive}
83
84
  on:blur={() => gradio.dispatch("blur")}
84
85
  on:focus={() => gradio.dispatch("focus")}
86
+ on:input={() => gradio.dispatch("input")}
85
87
  />
86
88
  {/if}
87
89
  </Block>
@@ -1,47 +1,8 @@
1
- import { SvelteComponent } from "svelte";
2
1
  export { default as BaseCode } from "./shared/Code.svelte";
3
2
  export { default as BaseCopy } from "./shared/Copy.svelte";
4
3
  export { default as BaseDownload } from "./shared/Download.svelte";
5
4
  export { default as BaseWidget } from "./shared/Widgets.svelte";
6
5
  export { default as BaseExample } from "./Example.svelte";
7
- import type { Gradio } from "@gradio/utils";
8
- import type { LoadingStatus } from "@gradio/statustracker";
9
- declare const __propDef: {
10
- props: {
11
- gradio: Gradio<{
12
- change: string;
13
- input: never;
14
- blur: never;
15
- focus: never;
16
- clear_status: LoadingStatus;
17
- }>;
18
- value?: string;
19
- value_is_output?: boolean;
20
- language?: string;
21
- lines?: number;
22
- max_lines?: number | undefined;
23
- elem_id?: string;
24
- elem_classes?: string[];
25
- visible?: boolean | "hidden";
26
- label?: any;
27
- show_label?: boolean;
28
- loading_status: LoadingStatus;
29
- scale?: number | null;
30
- min_width?: number | undefined;
31
- wrap_lines?: boolean;
32
- show_line_numbers?: boolean;
33
- autocomplete?: boolean;
34
- interactive: boolean;
35
- };
36
- events: {
37
- [evt: string]: CustomEvent<any>;
38
- };
39
- slots: {};
40
- exports?: {} | undefined;
41
- bindings?: string | undefined;
42
- };
43
- export type IndexProps = typeof __propDef.props;
44
- export type IndexEvents = typeof __propDef.events;
45
- export type IndexSlots = typeof __propDef.slots;
46
- export default class Index extends SvelteComponent<IndexProps, IndexEvents, IndexSlots> {
47
- }
6
+ declare const Index: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type Index = ReturnType<typeof Index>;
8
+ export default Index;