Upload folder using huggingface_hub
Browse files- 6.2.0/html/shared/HTML.svelte +20 -10
6.2.0/html/shared/HTML.svelte
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
component_class_name = "HTML"
|
| 15 |
} = $props();
|
| 16 |
|
| 17 |
-
let old_props = $state(props);
|
| 18 |
|
| 19 |
const dispatch = createEventDispatcher<{
|
| 20 |
event: { type: "click" | "submit"; data: any };
|
|
@@ -37,7 +37,8 @@
|
|
| 37 |
let currentCss = $state("");
|
| 38 |
let renderScheduled = $state(false);
|
| 39 |
let mounted = $state(false);
|
| 40 |
-
let
|
|
|
|
| 41 |
|
| 42 |
function get_scrollable_parent(element: HTMLElement): HTMLElement | null {
|
| 43 |
let parent = element.parentElement;
|
|
@@ -92,7 +93,8 @@
|
|
| 92 |
|
| 93 |
function render_template(
|
| 94 |
template: string,
|
| 95 |
-
props: Record<string, any
|
|
|
|
| 96 |
): string {
|
| 97 |
try {
|
| 98 |
const handlebarsTemplate = Handlebars.compile(template);
|
|
@@ -104,11 +106,19 @@
|
|
| 104 |
...propKeys,
|
| 105 |
`return \`${handlebarsRendered}\`;`
|
| 106 |
);
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
return templateFunc(...propValues);
|
| 109 |
} catch (e) {
|
| 110 |
console.error("Error evaluating template:", e);
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
return "";
|
| 113 |
}
|
| 114 |
}
|
|
@@ -119,7 +129,7 @@
|
|
| 119 |
style_element = document.createElement("style");
|
| 120 |
document.head.appendChild(style_element);
|
| 121 |
}
|
| 122 |
-
currentCss = render_template(css_template, reactiveProps);
|
| 123 |
if (currentCss) {
|
| 124 |
style_element.textContent = `#${random_id} { ${currentCss} }`;
|
| 125 |
} else {
|
|
@@ -227,7 +237,7 @@
|
|
| 227 |
}
|
| 228 |
|
| 229 |
function renderHTML(): void {
|
| 230 |
-
const newHtml = render_template(html_template, reactiveProps);
|
| 231 |
if (element) {
|
| 232 |
updateDOM(currentHtml, newHtml);
|
| 233 |
}
|
|
@@ -278,7 +288,7 @@
|
|
| 278 |
}
|
| 279 |
);
|
| 280 |
|
| 281 |
-
currentHtml = render_template(html_template, reactiveProps);
|
| 282 |
element.innerHTML = currentHtml;
|
| 283 |
update_css();
|
| 284 |
|
|
@@ -314,14 +324,14 @@
|
|
| 314 |
});
|
| 315 |
</script>
|
| 316 |
|
| 317 |
-
{#if
|
| 318 |
<div class="error-container">
|
| 319 |
<strong class="error-title"
|
| 320 |
>Error rendering <code class="error-component-name"
|
| 321 |
>{component_class_name}</code
|
| 322 |
>:</strong
|
| 323 |
>
|
| 324 |
-
<code class="error-message">{
|
| 325 |
</div>
|
| 326 |
{:else}
|
| 327 |
<div
|
|
|
|
| 14 |
component_class_name = "HTML"
|
| 15 |
} = $props();
|
| 16 |
|
| 17 |
+
let old_props = $state(JSON.parse(JSON.stringify(props)));
|
| 18 |
|
| 19 |
const dispatch = createEventDispatcher<{
|
| 20 |
event: { type: "click" | "submit"; data: any };
|
|
|
|
| 37 |
let currentCss = $state("");
|
| 38 |
let renderScheduled = $state(false);
|
| 39 |
let mounted = $state(false);
|
| 40 |
+
let html_error_message: string | null = $state(null);
|
| 41 |
+
let css_error_message: string | null = $state(null);
|
| 42 |
|
| 43 |
function get_scrollable_parent(element: HTMLElement): HTMLElement | null {
|
| 44 |
let parent = element.parentElement;
|
|
|
|
| 93 |
|
| 94 |
function render_template(
|
| 95 |
template: string,
|
| 96 |
+
props: Record<string, any>,
|
| 97 |
+
language: "html" | "css" = "html"
|
| 98 |
): string {
|
| 99 |
try {
|
| 100 |
const handlebarsTemplate = Handlebars.compile(template);
|
|
|
|
| 106 |
...propKeys,
|
| 107 |
`return \`${handlebarsRendered}\`;`
|
| 108 |
);
|
| 109 |
+
if (language === "html") {
|
| 110 |
+
html_error_message = null;
|
| 111 |
+
} else if (language === "css") {
|
| 112 |
+
css_error_message = null;
|
| 113 |
+
}
|
| 114 |
return templateFunc(...propValues);
|
| 115 |
} catch (e) {
|
| 116 |
console.error("Error evaluating template:", e);
|
| 117 |
+
if (language === "html") {
|
| 118 |
+
html_error_message = e instanceof Error ? e.message : String(e);
|
| 119 |
+
} else if (language === "css") {
|
| 120 |
+
css_error_message = e instanceof Error ? e.message : String(e);
|
| 121 |
+
}
|
| 122 |
return "";
|
| 123 |
}
|
| 124 |
}
|
|
|
|
| 129 |
style_element = document.createElement("style");
|
| 130 |
document.head.appendChild(style_element);
|
| 131 |
}
|
| 132 |
+
currentCss = render_template(css_template, reactiveProps, "css");
|
| 133 |
if (currentCss) {
|
| 134 |
style_element.textContent = `#${random_id} { ${currentCss} }`;
|
| 135 |
} else {
|
|
|
|
| 237 |
}
|
| 238 |
|
| 239 |
function renderHTML(): void {
|
| 240 |
+
const newHtml = render_template(html_template, reactiveProps, "html");
|
| 241 |
if (element) {
|
| 242 |
updateDOM(currentHtml, newHtml);
|
| 243 |
}
|
|
|
|
| 288 |
}
|
| 289 |
);
|
| 290 |
|
| 291 |
+
currentHtml = render_template(html_template, reactiveProps, "html");
|
| 292 |
element.innerHTML = currentHtml;
|
| 293 |
update_css();
|
| 294 |
|
|
|
|
| 324 |
});
|
| 325 |
</script>
|
| 326 |
|
| 327 |
+
{#if html_error_message || css_error_message}
|
| 328 |
<div class="error-container">
|
| 329 |
<strong class="error-title"
|
| 330 |
>Error rendering <code class="error-component-name"
|
| 331 |
>{component_class_name}</code
|
| 332 |
>:</strong
|
| 333 |
>
|
| 334 |
+
<code class="error-message">{html_error_message || css_error_message}</code>
|
| 335 |
</div>
|
| 336 |
{:else}
|
| 337 |
<div
|