File size: 1,894 Bytes
2e58857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<script context="module" lang="ts">
	export { default as BaseJSON } from "./shared/JSON.svelte";
</script>

<script lang="ts">
	import { Gradio } from "@gradio/utils";
	import JSON from "./shared/JSON.svelte";
	import { Block, BlockLabel } from "@gradio/atoms";
	import { JSON as JSONIcon } from "@gradio/icons";

	import { StatusTracker } from "@gradio/statustracker";
	import type { JSONProps, JSONEvents } from "./types";

	const props = $props();
	const gradio = new Gradio<JSONEvents, JSONProps>(props);

	let old_value = $state(gradio.props.value);

	$effect(() => {
		if (old_value !== gradio.props.value) {
			old_value = gradio.props.value;
			gradio.dispatch("change");
		}
	});

	let label_height = $state(0);
</script>

<Block
	visible={gradio.shared.visible}
	test_id="json"
	elem_id={gradio.shared.elem_id}
	elem_classes={gradio.shared.elem_classes}
	container={gradio.shared.container}
	scale={gradio.shared.scale}
	min_width={gradio.shared.min_width}
	padding={false}
	allow_overflow={true}
	overflow_behavior="auto"
	height={gradio.props.height}
	min_height={gradio.props.min_height}
	max_height={gradio.props.max_height}
>
	<div bind:clientHeight={label_height}>
		{#if gradio.shared.label}
			<BlockLabel
				Icon={JSONIcon}
				show_label={gradio.shared.show_label}
				label={gradio.shared.label}
				float={false}
				disable={gradio.shared.container === false}
			/>
		{/if}
	</div>

	<StatusTracker
		autoscroll={gradio.shared.autoscroll}
		i18n={gradio.i18n}
		{...gradio.shared.loading_status}
		on_clear_status={() =>
			gradio.dispatch("clear_status", gradio.shared.loading_status)}
	/>

	<JSON
		value={gradio.props.value}
		open={gradio.props.open}
		theme_mode={gradio.props.theme_mode}
		show_indices={gradio.props.show_indices}
		show_copy_button={gradio.props.buttons == null
			? true
			: gradio.props.buttons.includes("copy")}
		{label_height}
	/>
</Block>