Upload folder using huggingface_hub
Browse files- 6.7.0/html/Index.svelte +5 -1
- 6.7.0/html/package.json +1 -1
- 6.7.0/html/shared/HTML.svelte +96 -17
6.7.0/html/Index.svelte
CHANGED
|
@@ -11,8 +11,10 @@
|
|
| 11 |
import { Code as CodeIcon } from "@gradio/icons";
|
| 12 |
import { css_units } from "@gradio/utils";
|
| 13 |
import type { HTMLProps, HTMLEvents } from "./types.ts";
|
|
|
|
| 14 |
|
| 15 |
let props = $props();
|
|
|
|
| 16 |
const gradio = new Gradio<HTMLEvents, HTMLProps>(props);
|
| 17 |
|
| 18 |
let _props = $derived({
|
|
@@ -99,7 +101,9 @@
|
|
| 99 |
gradio.shared.visible = e.detail.data;
|
| 100 |
}
|
| 101 |
}}
|
| 102 |
-
|
|
|
|
|
|
|
| 103 |
</div>
|
| 104 |
</Block>
|
| 105 |
|
|
|
|
| 11 |
import { Code as CodeIcon } from "@gradio/icons";
|
| 12 |
import { css_units } from "@gradio/utils";
|
| 13 |
import type { HTMLProps, HTMLEvents } from "./types.ts";
|
| 14 |
+
import type { Snippet } from "svelte";
|
| 15 |
|
| 16 |
let props = $props();
|
| 17 |
+
let children: Snippet | undefined = props.children;
|
| 18 |
const gradio = new Gradio<HTMLEvents, HTMLProps>(props);
|
| 19 |
|
| 20 |
let _props = $derived({
|
|
|
|
| 101 |
gradio.shared.visible = e.detail.data;
|
| 102 |
}
|
| 103 |
}}
|
| 104 |
+
>
|
| 105 |
+
{@render children?.()}
|
| 106 |
+
</HTML>
|
| 107 |
</div>
|
| 108 |
</Block>
|
| 109 |
|
6.7.0/html/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/html",
|
| 3 |
-
"version": "0.
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
|
|
|
| 1 |
{
|
| 2 |
"name": "@gradio/html",
|
| 3 |
+
"version": "0.10.0",
|
| 4 |
"description": "Gradio UI packages",
|
| 5 |
"type": "module",
|
| 6 |
"author": "",
|
6.7.0/html/shared/HTML.svelte
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { createEventDispatcher, tick } from "svelte";
|
| 3 |
import Handlebars from "handlebars";
|
|
|
|
| 4 |
|
| 5 |
let {
|
| 6 |
elem_classes = [],
|
|
@@ -11,9 +12,31 @@
|
|
| 11 |
visible = true,
|
| 12 |
autoscroll = false,
|
| 13 |
apply_default_css = true,
|
| 14 |
-
component_class_name = "HTML"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
} = $props();
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
let old_props = $state(JSON.parse(JSON.stringify(props)));
|
| 18 |
|
| 19 |
const dispatch = createEventDispatcher<{
|
|
@@ -29,11 +52,15 @@
|
|
| 29 |
};
|
| 30 |
|
| 31 |
let element: HTMLDivElement;
|
|
|
|
|
|
|
| 32 |
let scrollable_parent: HTMLElement | null = null;
|
| 33 |
let random_id = `html-${Math.random().toString(36).substring(2, 11)}`;
|
| 34 |
let style_element: HTMLStyleElement | null = null;
|
| 35 |
let reactiveProps: Record<string, any> = {};
|
| 36 |
let currentHtml = $state("");
|
|
|
|
|
|
|
| 37 |
let currentCss = $state("");
|
| 38 |
let renderScheduled = $state(false);
|
| 39 |
let mounted = $state(false);
|
|
@@ -137,13 +164,17 @@
|
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
| 140 |
-
function updateDOM(
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
const tempContainer = document.createElement("div");
|
| 144 |
tempContainer.innerHTML = newHtml;
|
| 145 |
|
| 146 |
-
const oldNodes = Array.from(
|
| 147 |
const newNodes = Array.from(tempContainer.childNodes);
|
| 148 |
|
| 149 |
const maxLength = Math.max(oldNodes.length, newNodes.length);
|
|
@@ -153,9 +184,9 @@
|
|
| 153 |
const newNode = newNodes[i];
|
| 154 |
|
| 155 |
if (!oldNode && newNode) {
|
| 156 |
-
|
| 157 |
} else if (oldNode && !newNode) {
|
| 158 |
-
|
| 159 |
} else if (oldNode && newNode) {
|
| 160 |
updateNode(oldNode, newNode);
|
| 161 |
}
|
|
@@ -237,11 +268,26 @@
|
|
| 237 |
}
|
| 238 |
|
| 239 |
function renderHTML(): void {
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
}
|
| 244 |
-
currentHtml = newHtml;
|
| 245 |
if (autoscroll) {
|
| 246 |
scroll_on_html_update();
|
| 247 |
}
|
|
@@ -258,7 +304,6 @@
|
|
| 258 |
}
|
| 259 |
}
|
| 260 |
|
| 261 |
-
// Mount effect
|
| 262 |
$effect(() => {
|
| 263 |
if (!element || mounted) return;
|
| 264 |
mounted = true;
|
|
@@ -288,8 +333,23 @@
|
|
| 288 |
}
|
| 289 |
);
|
| 290 |
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
update_css();
|
| 294 |
|
| 295 |
if (autoscroll) {
|
|
@@ -337,11 +397,24 @@
|
|
| 337 |
<div
|
| 338 |
bind:this={element}
|
| 339 |
id={random_id}
|
| 340 |
-
class="{apply_default_css
|
| 341 |
-
' '
|
| 342 |
-
|
| 343 |
class:hide={!visible}
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
{/if}
|
| 346 |
|
| 347 |
<style>
|
|
@@ -349,6 +422,12 @@
|
|
| 349 |
display: none;
|
| 350 |
}
|
| 351 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
.error-container {
|
| 353 |
padding: 12px;
|
| 354 |
background-color: #fee;
|
|
|
|
| 1 |
<script lang="ts">
|
| 2 |
import { createEventDispatcher, tick } from "svelte";
|
| 3 |
import Handlebars from "handlebars";
|
| 4 |
+
import type { Snippet } from "svelte";
|
| 5 |
|
| 6 |
let {
|
| 7 |
elem_classes = [],
|
|
|
|
| 12 |
visible = true,
|
| 13 |
autoscroll = false,
|
| 14 |
apply_default_css = true,
|
| 15 |
+
component_class_name = "HTML",
|
| 16 |
+
children
|
| 17 |
+
}: {
|
| 18 |
+
elem_classes: string[];
|
| 19 |
+
props: Record<string, any>;
|
| 20 |
+
html_template: string;
|
| 21 |
+
css_template: string;
|
| 22 |
+
js_on_load: string | null;
|
| 23 |
+
visible: boolean;
|
| 24 |
+
autoscroll: boolean;
|
| 25 |
+
apply_default_css: boolean;
|
| 26 |
+
component_class_name: string;
|
| 27 |
+
children?: Snippet;
|
| 28 |
} = $props();
|
| 29 |
|
| 30 |
+
let [has_children, pre_html_template, post_html_template] = $derived.by(
|
| 31 |
+
() => {
|
| 32 |
+
if (html_template.includes("@children") && children) {
|
| 33 |
+
const parts = html_template.split("@children");
|
| 34 |
+
return [true, parts[0] || "", parts.slice(1).join("@children") || ""];
|
| 35 |
+
}
|
| 36 |
+
return [false, html_template, ""];
|
| 37 |
+
}
|
| 38 |
+
);
|
| 39 |
+
|
| 40 |
let old_props = $state(JSON.parse(JSON.stringify(props)));
|
| 41 |
|
| 42 |
const dispatch = createEventDispatcher<{
|
|
|
|
| 52 |
};
|
| 53 |
|
| 54 |
let element: HTMLDivElement;
|
| 55 |
+
let pre_element: HTMLDivElement;
|
| 56 |
+
let post_element: HTMLDivElement;
|
| 57 |
let scrollable_parent: HTMLElement | null = null;
|
| 58 |
let random_id = `html-${Math.random().toString(36).substring(2, 11)}`;
|
| 59 |
let style_element: HTMLStyleElement | null = null;
|
| 60 |
let reactiveProps: Record<string, any> = {};
|
| 61 |
let currentHtml = $state("");
|
| 62 |
+
let currentPreHtml = $state("");
|
| 63 |
+
let currentPostHtml = $state("");
|
| 64 |
let currentCss = $state("");
|
| 65 |
let renderScheduled = $state(false);
|
| 66 |
let mounted = $state(false);
|
|
|
|
| 164 |
}
|
| 165 |
}
|
| 166 |
|
| 167 |
+
function updateDOM(
|
| 168 |
+
_element: HTMLElement | undefined,
|
| 169 |
+
oldHtml: string,
|
| 170 |
+
newHtml: string
|
| 171 |
+
): void {
|
| 172 |
+
if (!_element || oldHtml === newHtml) return;
|
| 173 |
|
| 174 |
const tempContainer = document.createElement("div");
|
| 175 |
tempContainer.innerHTML = newHtml;
|
| 176 |
|
| 177 |
+
const oldNodes = Array.from(_element.childNodes);
|
| 178 |
const newNodes = Array.from(tempContainer.childNodes);
|
| 179 |
|
| 180 |
const maxLength = Math.max(oldNodes.length, newNodes.length);
|
|
|
|
| 184 |
const newNode = newNodes[i];
|
| 185 |
|
| 186 |
if (!oldNode && newNode) {
|
| 187 |
+
_element.appendChild(newNode.cloneNode(true));
|
| 188 |
} else if (oldNode && !newNode) {
|
| 189 |
+
_element.removeChild(oldNode);
|
| 190 |
} else if (oldNode && newNode) {
|
| 191 |
updateNode(oldNode, newNode);
|
| 192 |
}
|
|
|
|
| 268 |
}
|
| 269 |
|
| 270 |
function renderHTML(): void {
|
| 271 |
+
if (has_children) {
|
| 272 |
+
const newPreHtml = render_template(
|
| 273 |
+
pre_html_template,
|
| 274 |
+
reactiveProps,
|
| 275 |
+
"html"
|
| 276 |
+
);
|
| 277 |
+
updateDOM(pre_element, currentPreHtml, newPreHtml);
|
| 278 |
+
currentPreHtml = newPreHtml;
|
| 279 |
+
const newPostHtml = render_template(
|
| 280 |
+
post_html_template,
|
| 281 |
+
reactiveProps,
|
| 282 |
+
"html"
|
| 283 |
+
);
|
| 284 |
+
updateDOM(post_element, currentPostHtml, newPostHtml);
|
| 285 |
+
currentPostHtml = newPostHtml;
|
| 286 |
+
} else {
|
| 287 |
+
const newHtml = render_template(html_template, reactiveProps, "html");
|
| 288 |
+
updateDOM(element, currentHtml, newHtml);
|
| 289 |
+
currentHtml = newHtml;
|
| 290 |
}
|
|
|
|
| 291 |
if (autoscroll) {
|
| 292 |
scroll_on_html_update();
|
| 293 |
}
|
|
|
|
| 304 |
}
|
| 305 |
}
|
| 306 |
|
|
|
|
| 307 |
$effect(() => {
|
| 308 |
if (!element || mounted) return;
|
| 309 |
mounted = true;
|
|
|
|
| 333 |
}
|
| 334 |
);
|
| 335 |
|
| 336 |
+
if (has_children) {
|
| 337 |
+
currentPreHtml = render_template(
|
| 338 |
+
pre_html_template,
|
| 339 |
+
reactiveProps,
|
| 340 |
+
"html"
|
| 341 |
+
);
|
| 342 |
+
pre_element.innerHTML = currentPreHtml;
|
| 343 |
+
currentPostHtml = render_template(
|
| 344 |
+
post_html_template,
|
| 345 |
+
reactiveProps,
|
| 346 |
+
"html"
|
| 347 |
+
);
|
| 348 |
+
post_element.innerHTML = currentPostHtml;
|
| 349 |
+
} else {
|
| 350 |
+
currentHtml = render_template(html_template, reactiveProps, "html");
|
| 351 |
+
element.innerHTML = currentHtml;
|
| 352 |
+
}
|
| 353 |
update_css();
|
| 354 |
|
| 355 |
if (autoscroll) {
|
|
|
|
| 397 |
<div
|
| 398 |
bind:this={element}
|
| 399 |
id={random_id}
|
| 400 |
+
class="{apply_default_css && !has_children
|
| 401 |
+
? 'prose gradio-style'
|
| 402 |
+
: ''} {elem_classes.join(' ')}"
|
| 403 |
class:hide={!visible}
|
| 404 |
+
class:has_children
|
| 405 |
+
>
|
| 406 |
+
{#if has_children}
|
| 407 |
+
<div
|
| 408 |
+
class={apply_default_css ? "prose gradio-style" : ""}
|
| 409 |
+
bind:this={pre_element}
|
| 410 |
+
></div>
|
| 411 |
+
{@render children?.()}
|
| 412 |
+
<div
|
| 413 |
+
class={apply_default_css ? "prose gradio-style" : ""}
|
| 414 |
+
bind:this={post_element}
|
| 415 |
+
></div>
|
| 416 |
+
{/if}
|
| 417 |
+
</div>
|
| 418 |
{/if}
|
| 419 |
|
| 420 |
<style>
|
|
|
|
| 422 |
display: none;
|
| 423 |
}
|
| 424 |
|
| 425 |
+
.has_children {
|
| 426 |
+
display: flex;
|
| 427 |
+
flex-direction: column;
|
| 428 |
+
gap: var(--layout-gap);
|
| 429 |
+
}
|
| 430 |
+
|
| 431 |
.error-container {
|
| 432 |
padding: 12px;
|
| 433 |
background-color: #fee;
|