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