File size: 3,873 Bytes
8d9d326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<svelte:options accessors={true} />

<script context="module" lang="ts">
	export { default as BaseDataFrame } from "./shared/Table.svelte";
	export { default as BaseExample } from "./Example.svelte";
</script>

<script lang="ts">
	import type { SharedProps } from "@gradio/utils";
	import { Gradio } from "@gradio/utils";

	import type { DataframeProps, DataframeEvents } from "./types";
	import { dequal } from "dequal";
	import { onMount } from "svelte";
	import DF from "@gradio/dataframe-interim";
	import "@gradio/dataframe-interim/css";

	let prev_data: any = null;

	let changed = false;

	class DataframeGradio extends Gradio<DataframeEvents, DataframeProps> {
		async set_data(data: Partial<DataframeProps & SharedProps>): Promise<void> {
			console.log("DataframeGradio set_data called", data);
			if (data.value) {
				changed = true;
			}

			super.set_data(data);
			if (data.value && dequal(data.value, JSON.parse(prev_data)) === false) {
				// this.dispatch("change");
				prev_data = JSON.stringify(data.value);
			}
		}
	}

	let props = $props();

	let gradio = new DataframeGradio(props);
	let el: HTMLDivElement;
	let Component: typeof DF | null = null;
	onMount(() => {
		Component = new DF({
			target: el,
			props: {
				elem_id: gradio.shared.elem_id,
				elem_classes: gradio.shared.elem_classes,
				visible: gradio.shared.visible,
				value: gradio.props.value,

				col_count: gradio.props.col_count,
				row_count: gradio.props.row_count,
				label: gradio.shared.label,
				show_label: gradio.shared.show_label,
				wrap: gradio.props.wrap,
				datatype: gradio.props.datatype,
				scale: gradio.shared.scale,
				min_width: gradio.shared.min_width,
				root: gradio.shared.root,
				line_breaks: gradio.props.line_breaks,
				column_widths: gradio.props.column_widths,
				gradio: compat_gradio,
				latex_delimiters: gradio.props.latex_delimiters,
				max_height: gradio.props.max_height,
				loading_status: gradio.shared.loading_status,
				interactive: gradio.shared.interactive,
				buttons: gradio.props.buttons,
				max_chars: gradio.props.max_chars,
				show_row_numbers: gradio.props.show_row_numbers,
				show_search: gradio.props.show_search,
				pinned_columns: gradio.props.pinned_columns,
				static_columns: gradio.props.static_columns,
				fullscreen: gradio.props.fullscreen
			}
		});
	});

	const compat_gradio = {
		i18n: gradio.i18n,
		client: gradio.shared.client,
		dispatch(name: keyof DataframeEvents, detail?: any) {
			if (name === "input" && changed) {
				console.log("Skipping duplicate input event");
				changed = false;
				return;
			}
			gradio.dispatch(name, detail);
		},
		autoscroll: gradio.shared.autoscroll
	};
	$effect(() => {
		if (Component) {
			Component.$set({
				elem_id: gradio.shared.elem_id,
				elem_classes: gradio.shared.elem_classes,
				visible: gradio.shared.visible,
				value: gradio.props.value,

				col_count: gradio.props.col_count,
				row_count: gradio.props.row_count,
				label: gradio.shared.label,
				show_label: gradio.shared.show_label,
				wrap: gradio.props.wrap,
				datatype: gradio.props.datatype,
				scale: gradio.shared.scale,
				min_width: gradio.shared.min_width,
				root: gradio.shared.root,
				line_breaks: gradio.props.line_breaks,
				column_widths: gradio.props.column_widths,
				gradio: compat_gradio,
				latex_delimiters: gradio.props.latex_delimiters,
				max_height: gradio.props.max_height,
				loading_status: gradio.shared.loading_status,
				interactive: gradio.shared.interactive,
				buttons: gradio.props.buttons,
				max_chars: gradio.props.max_chars,
				show_row_numbers: gradio.props.show_row_numbers,
				show_search: gradio.props.show_search,
				pinned_columns: gradio.props.pinned_columns,
				static_columns: gradio.props.static_columns,
				fullscreen: gradio.props.fullscreen
			});
		}
	});
</script>

<div bind:this={el} />