@gradio/core 0.0.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 +32 -0
- package/LICENSE +201 -0
- package/blocks.ts +1 -0
- package/index.ts +4 -0
- package/login.ts +1 -0
- package/package.json +83 -0
- package/public/favicon.png +0 -0
- package/public/static/img/Bunny.obj +7474 -0
- package/public/static/img/Duck.glb +0 -0
- package/public/static/img/api-logo.svg +4 -0
- package/public/static/img/camera.svg +1 -0
- package/public/static/img/clear.svg +67 -0
- package/public/static/img/edit.svg +39 -0
- package/public/static/img/javascript.svg +16 -0
- package/public/static/img/logo.svg +19 -0
- package/public/static/img/logo_error.svg +134 -0
- package/public/static/img/python.svg +20 -0
- package/public/static/img/undo-solid.svg +1 -0
- package/src/Blocks.svelte +792 -0
- package/src/Embed.svelte +197 -0
- package/src/Login.stories.svelte +33 -0
- package/src/Login.svelte +111 -0
- package/src/MountComponents.svelte +30 -0
- package/src/Render.svelte +103 -0
- package/src/RenderComponent.svelte +67 -0
- package/src/api_docs/ApiBanner.svelte +118 -0
- package/src/api_docs/ApiDocs.svelte +418 -0
- package/src/api_docs/ApiRecorder.svelte +75 -0
- package/src/api_docs/CodeSnippet.svelte +198 -0
- package/src/api_docs/CopyButton.svelte +17 -0
- package/src/api_docs/EndpointDetail.svelte +37 -0
- package/src/api_docs/InputPayload.svelte +155 -0
- package/src/api_docs/InstallSnippet.svelte +59 -0
- package/src/api_docs/NoApi.svelte +74 -0
- package/src/api_docs/ParametersSnippet.svelte +106 -0
- package/src/api_docs/RecordingSnippet.svelte +224 -0
- package/src/api_docs/ResponseSnippet.svelte +97 -0
- package/src/api_docs/TryButton.svelte +19 -0
- package/src/api_docs/img/api-logo.svg +4 -0
- package/src/api_docs/img/bash.svg +8 -0
- package/src/api_docs/img/clear.svelte +19 -0
- package/src/api_docs/img/javascript.svg +16 -0
- package/src/api_docs/img/python.svg +20 -0
- package/src/api_docs/index.ts +2 -0
- package/src/api_docs/utils.ts +143 -0
- package/src/css.ts +116 -0
- package/src/gradio_helper.ts +7 -0
- package/src/i18n.test.ts +27 -0
- package/src/i18n.ts +36 -0
- package/src/images/lightning.svg +2 -0
- package/src/images/logo.svg +19 -0
- package/src/images/play.svg +2 -0
- package/src/images/spaces.svg +7 -0
- package/src/init.test.ts +521 -0
- package/src/init.ts +590 -0
- package/src/lang/BCP47_codes.js +58 -0
- package/src/lang/README.md +11 -0
- package/src/lang/ar.json +16 -0
- package/src/lang/ca.json +19 -0
- package/src/lang/ckb.json +108 -0
- package/src/lang/de.json +16 -0
- package/src/lang/en.json +118 -0
- package/src/lang/es.json +17 -0
- package/src/lang/eu.json +16 -0
- package/src/lang/fa.json +16 -0
- package/src/lang/fr.json +30 -0
- package/src/lang/he.json +16 -0
- package/src/lang/hi.json +16 -0
- package/src/lang/ja.json +16 -0
- package/src/lang/ko.json +16 -0
- package/src/lang/lt.json +16 -0
- package/src/lang/nl.json +16 -0
- package/src/lang/pl.json +16 -0
- package/src/lang/pt-BR.json +19 -0
- package/src/lang/ru.json +118 -0
- package/src/lang/ta.json +16 -0
- package/src/lang/tr.json +16 -0
- package/src/lang/uk.json +16 -0
- package/src/lang/ur.json +16 -0
- package/src/lang/uz.json +15 -0
- package/src/lang/zh-CN.json +115 -0
- package/src/lang/zh-TW.json +16 -0
- package/src/s-blocks.ts +1 -0
- package/src/s-login.ts +1 -0
- package/src/stores.ts +165 -0
- package/src/types.ts +106 -0
- package/src/vite-env-override.d.ts +20 -0
package/src/Embed.svelte
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import space_logo from "./images/spaces.svg";
|
|
3
|
+
import { _ } from "svelte-i18n";
|
|
4
|
+
export let wrapper: HTMLDivElement;
|
|
5
|
+
export let version: string;
|
|
6
|
+
export let initial_height: string;
|
|
7
|
+
export let fill_width: boolean;
|
|
8
|
+
export let is_embed: boolean;
|
|
9
|
+
|
|
10
|
+
export let space: string | null;
|
|
11
|
+
export let display: boolean;
|
|
12
|
+
export let info: boolean;
|
|
13
|
+
export let loaded: boolean;
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<div
|
|
17
|
+
bind:this={wrapper}
|
|
18
|
+
class:app={!display && !is_embed}
|
|
19
|
+
class:fill_width
|
|
20
|
+
class:embed-container={display}
|
|
21
|
+
class:with-info={info}
|
|
22
|
+
class="gradio-container gradio-container-{version}"
|
|
23
|
+
style:min-height={loaded ? "initial" : initial_height}
|
|
24
|
+
style:flex-grow={!display ? "1" : "auto"}
|
|
25
|
+
data-iframe-height
|
|
26
|
+
>
|
|
27
|
+
<div class="main">
|
|
28
|
+
<slot />
|
|
29
|
+
</div>
|
|
30
|
+
{#if display && space && info}
|
|
31
|
+
<div class="info">
|
|
32
|
+
<span>
|
|
33
|
+
<a href="https://huggingface.co/spaces/{space}" class="title">{space}</a
|
|
34
|
+
>
|
|
35
|
+
</span>
|
|
36
|
+
<span>
|
|
37
|
+
{$_("common.built_with")}
|
|
38
|
+
<a class="gradio" href="https://gradio.app">Gradio</a>.
|
|
39
|
+
</span>
|
|
40
|
+
<span>
|
|
41
|
+
{$_("common.hosted_on")}
|
|
42
|
+
<a class="hf" href="https://huggingface.co/spaces"
|
|
43
|
+
><span class="space-logo">
|
|
44
|
+
<img src={space_logo} alt="Hugging Face Space" />
|
|
45
|
+
</span> Spaces</a
|
|
46
|
+
>
|
|
47
|
+
</span>
|
|
48
|
+
</div>
|
|
49
|
+
{/if}
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
<style>
|
|
53
|
+
.gradio-container {
|
|
54
|
+
display: flex;
|
|
55
|
+
position: relative;
|
|
56
|
+
flex-direction: column;
|
|
57
|
+
padding: 0;
|
|
58
|
+
min-height: 1px;
|
|
59
|
+
overflow: hidden;
|
|
60
|
+
color: var(--button-secondary-text-color);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.embed-container {
|
|
64
|
+
margin: var(--size-4) 0px;
|
|
65
|
+
border: 1px solid var(--button-secondary-border-color);
|
|
66
|
+
border-radius: var(--embed-radius);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.with-info {
|
|
70
|
+
padding-bottom: var(--size-7);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.embed-container > .main {
|
|
74
|
+
padding: var(--size-4);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.app > .main {
|
|
78
|
+
display: flex;
|
|
79
|
+
flex-grow: 1;
|
|
80
|
+
flex-direction: column;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.app {
|
|
84
|
+
position: relative;
|
|
85
|
+
margin: auto;
|
|
86
|
+
padding: var(--size-4) var(--size-8);
|
|
87
|
+
width: 100%;
|
|
88
|
+
height: 100%;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@media (--screen-sm) {
|
|
92
|
+
.app:not(.fill_width) {
|
|
93
|
+
max-width: 640px;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
@media (--screen-md) {
|
|
97
|
+
.app:not(.fill_width) {
|
|
98
|
+
max-width: 768px;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
@media (--screen-lg) {
|
|
102
|
+
.app:not(.fill_width) {
|
|
103
|
+
max-width: 1024px;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
@media (--screen-xl) {
|
|
107
|
+
.app:not(.fill_width) {
|
|
108
|
+
max-width: 1280px;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
@media (--screen-xxl) {
|
|
112
|
+
.app:not(.fill_width) {
|
|
113
|
+
max-width: 1536px;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.info {
|
|
118
|
+
display: flex;
|
|
119
|
+
position: absolute;
|
|
120
|
+
bottom: 0;
|
|
121
|
+
justify-content: flex-start;
|
|
122
|
+
border-top: 1px solid var(--button-secondary-border-color);
|
|
123
|
+
padding: var(--size-1) var(--size-5);
|
|
124
|
+
width: 100%;
|
|
125
|
+
color: var(--body-text-color-subdued);
|
|
126
|
+
font-size: var(--text-md);
|
|
127
|
+
white-space: nowrap;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.info > span {
|
|
131
|
+
word-wrap: break-word;
|
|
132
|
+
-break: keep-all;
|
|
133
|
+
display: block;
|
|
134
|
+
word-break: keep-all;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.info > span:nth-child(1) {
|
|
138
|
+
margin-right: 4px;
|
|
139
|
+
min-width: 0px;
|
|
140
|
+
max-width: max-content;
|
|
141
|
+
overflow: hidden;
|
|
142
|
+
color: var(--body-text-color);
|
|
143
|
+
text-overflow: ellipsis;
|
|
144
|
+
white-space: nowrap;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.info > span:nth-child(2) {
|
|
148
|
+
margin-right: 3px;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.info > span:nth-child(2),
|
|
152
|
+
.info > span:nth-child(3) {
|
|
153
|
+
width: max-content;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.info > span:nth-child(3) {
|
|
157
|
+
align-self: flex-end;
|
|
158
|
+
justify-self: flex-end;
|
|
159
|
+
margin-left: auto;
|
|
160
|
+
text-align: right;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.info > span:nth-child(1) {
|
|
164
|
+
flex-shrink: 9;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.hidden-title {
|
|
168
|
+
position: absolute;
|
|
169
|
+
left: var(--size-5);
|
|
170
|
+
opacity: 0;
|
|
171
|
+
background: var(--button-secondary-background-fill);
|
|
172
|
+
padding-right: 4px;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.info a {
|
|
176
|
+
color: var(--body-text-color);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.title {
|
|
180
|
+
font-size: var(--text-sm);
|
|
181
|
+
font-family: var(--font-mono);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.hf {
|
|
185
|
+
margin-left: 5px;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.space-logo img {
|
|
189
|
+
display: inline-block;
|
|
190
|
+
margin-bottom: 4px;
|
|
191
|
+
height: 12px;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
a:hover {
|
|
195
|
+
text-decoration: underline;
|
|
196
|
+
}
|
|
197
|
+
</style>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Meta, Template, Story } from "@storybook/addon-svelte-csf";
|
|
3
|
+
import Login from "./Login.svelte";
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<Meta
|
|
7
|
+
title="Components/Login Page"
|
|
8
|
+
component={Login}
|
|
9
|
+
argTypes={{
|
|
10
|
+
auth_message: {
|
|
11
|
+
control: "text",
|
|
12
|
+
description: "The optional auth message to display",
|
|
13
|
+
name: "label",
|
|
14
|
+
value: "Gradio Button"
|
|
15
|
+
}
|
|
16
|
+
}}
|
|
17
|
+
/>
|
|
18
|
+
|
|
19
|
+
<Template let:args>
|
|
20
|
+
<Login {...args} />
|
|
21
|
+
</Template>
|
|
22
|
+
|
|
23
|
+
<Story name="Login page without auth message" args={{ auth_message: null }} />
|
|
24
|
+
<Story
|
|
25
|
+
name="Login page with auth message"
|
|
26
|
+
args={{ auth_message: "Log in to this great gradio app" }}
|
|
27
|
+
/>
|
|
28
|
+
<Story
|
|
29
|
+
name="Login page with HTML auth message"
|
|
30
|
+
args={{
|
|
31
|
+
auth_message: "<em>Log in to this <strong>great</strong> gradio app</em>"
|
|
32
|
+
}}
|
|
33
|
+
/>
|
package/src/Login.svelte
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Form from "@gradio/form";
|
|
3
|
+
import { BaseTextbox as Textbox } from "@gradio/textbox";
|
|
4
|
+
import { BaseButton } from "@gradio/button";
|
|
5
|
+
import Column from "@gradio/column";
|
|
6
|
+
import { Block } from "@gradio/atoms";
|
|
7
|
+
import { _ } from "svelte-i18n";
|
|
8
|
+
export let root: string;
|
|
9
|
+
export let auth_message: string | null;
|
|
10
|
+
export let app_mode: boolean;
|
|
11
|
+
export let space_id: string | null;
|
|
12
|
+
|
|
13
|
+
let username = "";
|
|
14
|
+
let password = "";
|
|
15
|
+
let incorrect_credentials = false;
|
|
16
|
+
|
|
17
|
+
const submit = async (): Promise<void> => {
|
|
18
|
+
const formData = new FormData();
|
|
19
|
+
formData.append("username", username);
|
|
20
|
+
formData.append("password", password);
|
|
21
|
+
|
|
22
|
+
let response = await fetch(root + "/login", {
|
|
23
|
+
method: "POST",
|
|
24
|
+
body: formData
|
|
25
|
+
});
|
|
26
|
+
if (response.status === 400) {
|
|
27
|
+
incorrect_credentials = true;
|
|
28
|
+
username = "";
|
|
29
|
+
password = "";
|
|
30
|
+
} else if (response.status == 200) {
|
|
31
|
+
location.reload();
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<div class="wrap" class:min-h-screen={app_mode}>
|
|
37
|
+
<Column variant="panel" min_width={480}>
|
|
38
|
+
<h2>{$_("login.login")}</h2>
|
|
39
|
+
{#if auth_message}
|
|
40
|
+
<p class="auth">{@html auth_message}</p>
|
|
41
|
+
{/if}
|
|
42
|
+
{#if space_id}
|
|
43
|
+
<p class="auth">
|
|
44
|
+
{$_("login.enable_cookies")}
|
|
45
|
+
</p>
|
|
46
|
+
{/if}
|
|
47
|
+
{#if incorrect_credentials}
|
|
48
|
+
<p class="creds">{$_("login.incorrect_credentials")}</p>
|
|
49
|
+
{/if}
|
|
50
|
+
<Form>
|
|
51
|
+
<Block>
|
|
52
|
+
<Textbox
|
|
53
|
+
label="username"
|
|
54
|
+
lines={1}
|
|
55
|
+
show_label={true}
|
|
56
|
+
max_lines={1}
|
|
57
|
+
on:submit={submit}
|
|
58
|
+
bind:value={username}
|
|
59
|
+
/>
|
|
60
|
+
</Block>
|
|
61
|
+
|
|
62
|
+
<Block>
|
|
63
|
+
<Textbox
|
|
64
|
+
label="password"
|
|
65
|
+
lines={1}
|
|
66
|
+
show_label={true}
|
|
67
|
+
max_lines={1}
|
|
68
|
+
type="password"
|
|
69
|
+
on:submit={submit}
|
|
70
|
+
bind:value={password}
|
|
71
|
+
/>
|
|
72
|
+
</Block>
|
|
73
|
+
</Form>
|
|
74
|
+
|
|
75
|
+
<BaseButton size="lg" variant="primary" on:click={submit}
|
|
76
|
+
>{$_("login.login")}</BaseButton
|
|
77
|
+
>
|
|
78
|
+
</Column>
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
<style>
|
|
82
|
+
.wrap {
|
|
83
|
+
display: flex;
|
|
84
|
+
flex-direction: column;
|
|
85
|
+
justify-content: center;
|
|
86
|
+
align-items: center;
|
|
87
|
+
margin-top: var(--size-3);
|
|
88
|
+
background: var(--background-fill-primary);
|
|
89
|
+
width: var(--size-full);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
h2 {
|
|
93
|
+
margin-bottom: var(--size-3);
|
|
94
|
+
color: var(--body-text-color);
|
|
95
|
+
font-weight: var(--section-header-text-weight);
|
|
96
|
+
font-size: var(--text-xl);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.auth {
|
|
100
|
+
margin-top: var(--size-1);
|
|
101
|
+
margin-bottom: var(--size-1);
|
|
102
|
+
color: var(--body-text-color);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.creds {
|
|
106
|
+
margin-top: var(--size-4);
|
|
107
|
+
margin-bottom: var(--size-4);
|
|
108
|
+
color: var(--error-text-color);
|
|
109
|
+
font-weight: var(--weight-semibold);
|
|
110
|
+
}
|
|
111
|
+
</style>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, createEventDispatcher } from "svelte";
|
|
3
|
+
import type { Client } from "@gradio/client";
|
|
4
|
+
import Render from "./Render.svelte";
|
|
5
|
+
|
|
6
|
+
export let rootNode: any;
|
|
7
|
+
export let root: any;
|
|
8
|
+
export let target: any;
|
|
9
|
+
export let theme_mode: any;
|
|
10
|
+
export let version: any;
|
|
11
|
+
export let autoscroll: boolean;
|
|
12
|
+
export let max_file_size: number | null = null;
|
|
13
|
+
export let client: Client;
|
|
14
|
+
|
|
15
|
+
const dispatch = createEventDispatcher<{ mount?: never }>();
|
|
16
|
+
onMount(() => {
|
|
17
|
+
dispatch("mount");
|
|
18
|
+
});
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<Render
|
|
22
|
+
node={rootNode}
|
|
23
|
+
{root}
|
|
24
|
+
{target}
|
|
25
|
+
{theme_mode}
|
|
26
|
+
{version}
|
|
27
|
+
{autoscroll}
|
|
28
|
+
{max_file_size}
|
|
29
|
+
{client}
|
|
30
|
+
/>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Gradio, formatter } from "./gradio_helper";
|
|
3
|
+
import { onMount, createEventDispatcher, setContext } from "svelte";
|
|
4
|
+
import type { ComponentMeta, ThemeMode } from "./types";
|
|
5
|
+
import type { Client } from "@gradio/client";
|
|
6
|
+
import RenderComponent from "./RenderComponent.svelte";
|
|
7
|
+
|
|
8
|
+
export let root: string;
|
|
9
|
+
|
|
10
|
+
export let node: ComponentMeta;
|
|
11
|
+
export let parent: string | null = null;
|
|
12
|
+
export let target: HTMLElement;
|
|
13
|
+
export let theme_mode: ThemeMode;
|
|
14
|
+
export let version: string;
|
|
15
|
+
export let autoscroll: boolean;
|
|
16
|
+
export let max_file_size: number | null;
|
|
17
|
+
export let client: Client;
|
|
18
|
+
|
|
19
|
+
const dispatch = createEventDispatcher<{ mount: number; destroy: number }>();
|
|
20
|
+
let filtered_children: ComponentMeta[] = [];
|
|
21
|
+
|
|
22
|
+
onMount(() => {
|
|
23
|
+
dispatch("mount", node.id);
|
|
24
|
+
|
|
25
|
+
for (const child of filtered_children) {
|
|
26
|
+
dispatch("mount", child.id);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return () => {
|
|
30
|
+
dispatch("destroy", node.id);
|
|
31
|
+
|
|
32
|
+
for (const child of filtered_children) {
|
|
33
|
+
dispatch("mount", child.id);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
$: node.children =
|
|
39
|
+
node.children &&
|
|
40
|
+
node.children.filter((v) => {
|
|
41
|
+
const valid_node = node.type !== "statustracker";
|
|
42
|
+
if (!valid_node) {
|
|
43
|
+
filtered_children.push(v);
|
|
44
|
+
}
|
|
45
|
+
return valid_node;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
setContext("BLOCK_KEY", parent);
|
|
49
|
+
|
|
50
|
+
$: {
|
|
51
|
+
if (node.type === "form") {
|
|
52
|
+
if (node.children?.every((c) => !c.props.visible)) {
|
|
53
|
+
node.props.visible = false;
|
|
54
|
+
} else {
|
|
55
|
+
node.props.visible = true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
$: gradio_class = new Gradio<Record<string, any>>(
|
|
61
|
+
node.id,
|
|
62
|
+
target,
|
|
63
|
+
theme_mode,
|
|
64
|
+
version,
|
|
65
|
+
root,
|
|
66
|
+
autoscroll,
|
|
67
|
+
max_file_size,
|
|
68
|
+
formatter,
|
|
69
|
+
client
|
|
70
|
+
);
|
|
71
|
+
</script>
|
|
72
|
+
|
|
73
|
+
<RenderComponent
|
|
74
|
+
_id={node.id}
|
|
75
|
+
component={node.component}
|
|
76
|
+
bind:instance={node.instance}
|
|
77
|
+
bind:value={node.props.value}
|
|
78
|
+
elem_id={("elem_id" in node.props && node.props.elem_id) ||
|
|
79
|
+
`component-${node.id}`}
|
|
80
|
+
elem_classes={("elem_classes" in node.props && node.props.elem_classes) || []}
|
|
81
|
+
{target}
|
|
82
|
+
{...node.props}
|
|
83
|
+
{theme_mode}
|
|
84
|
+
{root}
|
|
85
|
+
gradio={gradio_class}
|
|
86
|
+
>
|
|
87
|
+
{#if node.children && node.children.length}
|
|
88
|
+
{#each node.children as _node (_node.id)}
|
|
89
|
+
<svelte:self
|
|
90
|
+
node={_node}
|
|
91
|
+
component={_node.component}
|
|
92
|
+
{target}
|
|
93
|
+
id={_node.id}
|
|
94
|
+
{root}
|
|
95
|
+
{theme_mode}
|
|
96
|
+
on:destroy
|
|
97
|
+
on:mount
|
|
98
|
+
{max_file_size}
|
|
99
|
+
{client}
|
|
100
|
+
/>
|
|
101
|
+
{/each}
|
|
102
|
+
{/if}
|
|
103
|
+
</RenderComponent>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<svelte:options immutable={true} />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { Gradio } from "./gradio_helper";
|
|
5
|
+
import type { ComponentMeta, ThemeMode } from "./types";
|
|
6
|
+
import type { SvelteComponent, ComponentType } from "svelte";
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
import { bind, binding_callbacks } from "svelte/internal";
|
|
9
|
+
|
|
10
|
+
export let root: string;
|
|
11
|
+
export let component: ComponentMeta["component"];
|
|
12
|
+
export let target: HTMLElement;
|
|
13
|
+
export let theme_mode: ThemeMode;
|
|
14
|
+
export let instance: ComponentMeta["instance"];
|
|
15
|
+
export let value: any;
|
|
16
|
+
export let gradio: Gradio;
|
|
17
|
+
export let elem_id: string;
|
|
18
|
+
export let elem_classes: string[];
|
|
19
|
+
export let _id: number;
|
|
20
|
+
|
|
21
|
+
const s = (id: number, p: string, v: any): CustomEvent =>
|
|
22
|
+
new CustomEvent("prop_change", { detail: { id, prop: p, value: v } });
|
|
23
|
+
|
|
24
|
+
function wrap(
|
|
25
|
+
component: ComponentType<SvelteComponent>
|
|
26
|
+
): ComponentType<SvelteComponent> {
|
|
27
|
+
const ProxiedMyClass = new Proxy(component, {
|
|
28
|
+
construct(_target, args: Record<string, any>[]) {
|
|
29
|
+
//@ts-ignore
|
|
30
|
+
const instance = new _target(...args);
|
|
31
|
+
const props = Object.keys(instance.$$.props);
|
|
32
|
+
|
|
33
|
+
function report(props: string) {
|
|
34
|
+
return function (propargs: any) {
|
|
35
|
+
const ev = s(_id, props, propargs);
|
|
36
|
+
target.dispatchEvent(ev);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
props.forEach((v) => {
|
|
40
|
+
binding_callbacks.push(() => bind(instance, v, report(v)));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return instance;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return ProxiedMyClass;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const _component = wrap(component);
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<svelte:component
|
|
54
|
+
this={_component}
|
|
55
|
+
bind:this={instance}
|
|
56
|
+
bind:value
|
|
57
|
+
on:prop_change
|
|
58
|
+
{elem_id}
|
|
59
|
+
{elem_classes}
|
|
60
|
+
{target}
|
|
61
|
+
{...$$restProps}
|
|
62
|
+
{theme_mode}
|
|
63
|
+
{root}
|
|
64
|
+
{gradio}
|
|
65
|
+
>
|
|
66
|
+
<slot />
|
|
67
|
+
</svelte:component>
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createEventDispatcher } from "svelte";
|
|
3
|
+
import api_logo from "./img/api-logo.svg";
|
|
4
|
+
import Clear from "./img/clear.svelte";
|
|
5
|
+
import { BaseButton } from "@gradio/button";
|
|
6
|
+
|
|
7
|
+
export let root: string;
|
|
8
|
+
export let api_count: number;
|
|
9
|
+
|
|
10
|
+
const dispatch = createEventDispatcher();
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<h2>
|
|
14
|
+
<img src={api_logo} alt="" />
|
|
15
|
+
<div class="title">
|
|
16
|
+
API documentation
|
|
17
|
+
<div class="url">
|
|
18
|
+
{root}
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
<span class="counts">
|
|
22
|
+
<BaseButton
|
|
23
|
+
size="sm"
|
|
24
|
+
variant="secondary"
|
|
25
|
+
elem_id="start-api-recorder"
|
|
26
|
+
on:click={() => dispatch("close", { api_recorder_visible: true })}
|
|
27
|
+
>
|
|
28
|
+
<div class="loading-dot self-baseline"></div>
|
|
29
|
+
<p class="self-baseline btn-text">API Recorder</p>
|
|
30
|
+
</BaseButton>
|
|
31
|
+
<p>
|
|
32
|
+
<span class="url">{api_count}</span> API endpoint{#if api_count > 1}s{/if}<br
|
|
33
|
+
/>
|
|
34
|
+
</p>
|
|
35
|
+
</span>
|
|
36
|
+
</h2>
|
|
37
|
+
|
|
38
|
+
<button on:click={() => dispatch("close")}>
|
|
39
|
+
<Clear />
|
|
40
|
+
</button>
|
|
41
|
+
|
|
42
|
+
<style>
|
|
43
|
+
h2 {
|
|
44
|
+
display: flex;
|
|
45
|
+
color: var(--body-text-color);
|
|
46
|
+
font-weight: var(--weight-semibold);
|
|
47
|
+
gap: var(--size-4);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
h2 img {
|
|
51
|
+
margin-right: var(--size-2);
|
|
52
|
+
width: var(--size-4);
|
|
53
|
+
display: inline-block;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.url {
|
|
57
|
+
color: var(--color-accent);
|
|
58
|
+
font-weight: normal;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
button {
|
|
62
|
+
position: absolute;
|
|
63
|
+
top: var(--size-5);
|
|
64
|
+
right: var(--size-6);
|
|
65
|
+
width: var(--size-4);
|
|
66
|
+
color: var(--body-text-color);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
button:hover {
|
|
70
|
+
color: var(--color-accent);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@media (--screen-md) {
|
|
74
|
+
button {
|
|
75
|
+
top: var(--size-6);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
h2 img {
|
|
79
|
+
width: var(--size-5);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.counts {
|
|
84
|
+
margin-top: auto;
|
|
85
|
+
margin-right: var(--size-8);
|
|
86
|
+
margin-bottom: auto;
|
|
87
|
+
margin-left: auto;
|
|
88
|
+
color: var(--body-text-color);
|
|
89
|
+
font-weight: var(--weight-light);
|
|
90
|
+
display: flex;
|
|
91
|
+
flex-direction: row;
|
|
92
|
+
gap: 0.5rem;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.loading-dot {
|
|
96
|
+
position: relative;
|
|
97
|
+
left: -9999px;
|
|
98
|
+
width: 12px;
|
|
99
|
+
height: 12px;
|
|
100
|
+
border-radius: 6px;
|
|
101
|
+
background-color: #fd7b00;
|
|
102
|
+
color: #fd7b00;
|
|
103
|
+
box-shadow: 9999px 0 0 -1px;
|
|
104
|
+
margin-right: 0.3rem;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.self-baseline {
|
|
108
|
+
align-self: baseline;
|
|
109
|
+
}
|
|
110
|
+
.title {
|
|
111
|
+
display: flex;
|
|
112
|
+
flex-direction: row;
|
|
113
|
+
gap: 0.5rem;
|
|
114
|
+
}
|
|
115
|
+
.btn-text {
|
|
116
|
+
font-size: var(--text-lg);
|
|
117
|
+
}
|
|
118
|
+
</style>
|