Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions kit/src/lib/Added.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<script lang="ts">
import Tip from "./Tip.svelte";

export let version: string;
interface Props {
version: string;
children?: import("svelte").Snippet;
}

let { version, children }: Props = $props();
</script>

<Tip>
<p class="font-medium">Added in {version}</p>
<slot />
{@render children?.()}
</Tip>
9 changes: 7 additions & 2 deletions kit/src/lib/Changed.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<script lang="ts">
import Tip from "./Tip.svelte";

export let version: string;
interface Props {
version: string;
children?: import("svelte").Snippet;
}

let { version, children }: Props = $props();
</script>

<Tip>
<p class="font-medium">Changed in {version}</p>
<slot />
{@render children?.()}
</Tip>
26 changes: 15 additions & 11 deletions kit/src/lib/CodeBlock.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<script>
<script lang="ts">
import CopyButton from "./CopyButton.svelte";
let hideCopyButton = true;
export let code = "";
export let highlighted = "";
export let lang = "";
export let wrap = false;
export let classNames = "";
let hideCopyButton = $state(true);
interface Props {
code?: string;
highlighted?: string;
lang?: string;
wrap?: boolean;
classNames?: string;
}

let { code = "", highlighted = "", lang = "", wrap = false, classNames = "" }: Props = $props();

function handleMouseOver() {
hideCopyButton = false;
Expand All @@ -17,10 +21,10 @@

<div
class="code-block relative {classNames}"
on:mouseover={handleMouseOver}
on:focus={handleMouseOver}
on:mouseout={handleMouseOut}
on:blur={handleMouseOut}
onmouseover={handleMouseOver}
onfocus={handleMouseOver}
onmouseout={handleMouseOut}
onblur={handleMouseOut}
>
<div class="absolute top-2.5 right-4">
<CopyButton
Expand Down
25 changes: 16 additions & 9 deletions kit/src/lib/CodeBlockFw.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
import CopyButton from "./CopyButton.svelte";
import FrameworkSwitch from "./FrameworkSwitch.svelte";

export let group1: { id: string; code: string; highlighted: string };
export let group2: { id: string; code: string; highlighted: string };
export let lang = "";
export let wrap = false;
interface Props {
group1: { id: string; code: string; highlighted: string };
group2: { id: string; code: string; highlighted: string };
lang?: string;
wrap?: boolean;
}

let { group1, group2, lang = "", wrap = false }: Props = $props();

const ids = [group1.id, group2.id];
const storeKey = ids.join("-");
const group = getGroupStore(storeKey);

let hideCopyButton = true;
let hideCopyButton = $state(true);

function handleMouseOver() {
hideCopyButton = false;
Expand All @@ -24,10 +28,13 @@

<div
class="code-block relative"
on:mouseover={handleMouseOver}
on:focus={handleMouseOver}
on:mouseout={handleMouseOut}
on:focus={handleMouseOut}
onmouseover={handleMouseOver}
onfocus={() => {
// preserved from the svelte 4 version, which bound focus to both handlers
handleMouseOver();
handleMouseOut();
}}
onmouseout={handleMouseOut}
>
{#if $group === "group1"}
<div class="absolute top-2.5 right-4">
Expand Down
47 changes: 28 additions & 19 deletions kit/src/lib/ColabDropdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
import Dropdown from "./Dropdown.svelte";
import DropdownEntry from "./DropdownEntry.svelte";

export let options: { label: string; value: string }[] = [];
export let classNames = "";
interface Props {
options?: { label: string; value: string }[];
classNames?: string;
children?: import("svelte").Snippet;
}

let { options = [], classNames = "", children }: Props = $props();

function onClick(url: string) {
window.open(url);
Expand All @@ -12,23 +17,27 @@

<div class={classNames}>
<Dropdown btnLabel="" classNames="colab-dropdown" noBtnClass useDeprecatedJS={false}>
<slot slot="button">
<img
alt="Open In Colab"
class="!m-0"
src="https://colab.research.google.com/assets/colab-badge.svg"
/>
</slot>
<slot slot="menu">
{#each options as { label, value }}
<DropdownEntry
classNames="text-sm !no-underline"
iconClassNames="text-gray-500"
{label}
onClick={() => onClick(value)}
useDeprecatedJS={false}
{#snippet button()}
{#if children}{@render children()}{:else}
<img
alt="Open In Colab"
class="!m-0"
src="https://colab.research.google.com/assets/colab-badge.svg"
/>
{/each}
</slot>
{/if}
{/snippet}
{#snippet menu()}
{#if children}{@render children()}{:else}
{#each options as { label, value }}
<DropdownEntry
classNames="text-sm !no-underline"
iconClassNames="text-gray-500"
{label}
onClick={() => onClick(value)}
useDeprecatedJS={false}
/>
{/each}
{/if}
{/snippet}
</Dropdown>
</div>
18 changes: 11 additions & 7 deletions kit/src/lib/CopyButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
import IconCopy from "./IconCopy.svelte";
import Tooltip from "./Tooltip.svelte";

export let classNames = "";
export let label = "";
export let style: "button" | "button-clear" | "text" = "text";
export let title = "";
export let value: string;
interface Props {
classNames?: string;
label?: string;
style?: "button" | "button-clear" | "text";
title?: string;
value: string;
}

let { classNames = "", label = "", style = "text", title = "", value }: Props = $props();

let isSuccess = false;
let isSuccess = $state(false);
let timeout: any;

onDestroy(() => {
Expand Down Expand Up @@ -41,7 +45,7 @@
{!isSuccess && ['button-clear', 'text'].includes(style) ? 'text-gray-600' : ''}
{isSuccess ? 'text-green-500' : ''}
"
on:click={handleClick}
onclick={handleClick}
title={title || label || "Copy to clipboard"}
type="button"
>
Expand Down
47 changes: 28 additions & 19 deletions kit/src/lib/CopyLLMTxtMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
import IconMCP from "./IconMCP.svelte";
import IconHuggingChat from "./IconHuggingChat.svelte";

export let label = "Copy page";
export let markdownDescription = "Copy page as Markdown for LLMs";
export let containerClass = "";
export let containerStyle = "";
interface Props {
label?: string;
markdownDescription?: string;
containerClass?: string;
containerStyle?: string;
}

let {
label = "Copy page",
markdownDescription = "Copy page as Markdown for LLMs",
containerClass = "",
containerStyle = "",
}: Props = $props();

const isClient = typeof window !== "undefined";
const hasDocument = typeof document !== "undefined";
Expand All @@ -28,11 +37,11 @@
const SOURCE_URL_MD = SOURCE_URL.endsWith(".md") ? SOURCE_URL : SOURCE_URL + ".md";
let encodedPrompt: string | null = null;

let open = false;
let copied = false;
let triggerEl: HTMLDivElement | null = null;
let menuEl: HTMLDivElement | null = null;
let menuStyle = "";
let open = $state(false);
let copied = $state(false);
let triggerEl: HTMLDivElement | null = $state(null);
let menuEl: HTMLDivElement | null = $state(null);
let menuStyle = $state("");
let closeTimeout: ReturnType<typeof setTimeout> | null = null;
let sourceMarkdown: string | null = null;
let sourceFetchPromise: Promise<string> | null = null;
Expand Down Expand Up @@ -204,10 +213,10 @@
</script>

<svelte:window
on:mousedown={handleWindowPointer}
on:keydown={handleWindowKeydown}
on:resize={handleWindowResize}
on:scroll={handleWindowScroll}
onmousedown={handleWindowPointer}
onkeydown={handleWindowKeydown}
onresize={handleWindowResize}
onscroll={handleWindowScroll}
/>

<div
Expand All @@ -218,7 +227,7 @@
>
<div bind:this={triggerEl} class="inline-flex rounded-md max-sm:rounded-sm">
<button
on:click={copyMarkdown}
onclick={copyMarkdown}
class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800"
aria-live="polite"
>
Expand All @@ -230,7 +239,7 @@
<span>{copied ? "Copied" : label}</span>
</button>
<button
on:click={toggleMenu}
onclick={toggleMenu}
class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800"
aria-haspopup="menu"
aria-expanded={open}
Expand All @@ -249,7 +258,7 @@
class="fixed inset-0 z-40"
aria-hidden="true"
style="background: transparent;"
on:click={closeMenu}
onclick={closeMenu}
></div>
<div
bind:this={menuEl}
Expand All @@ -260,7 +269,7 @@
>
<button
role="menuitem"
on:click={() => {
onclick={() => {
copyMarkdown();
closeMenu();
}}
Expand All @@ -284,7 +293,7 @@
href={SOURCE_URL_MD}
target="_blank"
rel="noopener noreferrer"
on:click={closeMenu}
onclick={closeMenu}
class="{baseMenuItemClass} no-underline!"
>
<div class="border border-gray-200 dark:border-gray-850 rounded-lg p-1.5">
Expand All @@ -305,7 +314,7 @@
href={option.buildUrl()}
target="_blank"
rel="noopener noreferrer"
on:click={closeMenu}
onclick={closeMenu}
class="{baseMenuItemClass} no-underline!"
>
<div class="border border-gray-200 dark:border-gray-850 rounded-lg p-1.5">
Expand Down
21 changes: 15 additions & 6 deletions kit/src/lib/CourseFloatingBanner.svelte
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
<script lang="ts">
import DocNotebookDropdown from "./DocNotebookDropdown.svelte";

export let chapter: number;
export let notebooks: { label: string; value: string }[] = [];
export let classNames = "";
export let askForHelpUrl = `https://discuss.huggingface.co/t/chapter-${chapter}-questions`;
interface Props {
chapter: number;
notebooks?: { label: string; value: string }[];
classNames?: string;
askForHelpUrl?: any;
}

let {
chapter,
notebooks = [],
classNames = "",
askForHelpUrl = `https://discuss.huggingface.co/t/chapter-${chapter}-questions`,
}: Props = $props();
</script>

<DocNotebookDropdown options={notebooks} {classNames}>
<svelte:fragment slot="alwaysVisible">
{#snippet alwaysVisible()}
<a href={askForHelpUrl} target="_blank">
<img
alt="Ask a Question"
class="!m-0"
src="https://img.shields.io/badge/Ask%20a%20question-ffcb4c.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgLTEgMTA0IDEwNiI+PGRlZnM+PHN0eWxlPi5jbHMtMXtmaWxsOiMyMzFmMjA7fS5jbHMtMntmaWxsOiNmZmY5YWU7fS5jbHMtM3tmaWxsOiMwMGFlZWY7fS5jbHMtNHtmaWxsOiMwMGE5NGY7fS5jbHMtNXtmaWxsOiNmMTVkMjI7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z48L3N2Zz4="
/>
</a>
</svelte:fragment>
{/snippet}
</DocNotebookDropdown>
9 changes: 7 additions & 2 deletions kit/src/lib/Deprecated.svelte
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<script lang="ts">
import Tip from "./Tip.svelte";

export let version: string;
interface Props {
version: string;
children?: import("svelte").Snippet;
}

let { version, children }: Props = $props();
</script>

<Tip warning>
<p class="font-medium">Deprecated in {version}</p>
<slot />
{@render children?.()}
</Tip>
Loading