Skip to content

Commit

Permalink
Merge branch 'main' into zh-cn
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed Sep 5, 2024
2 parents 938d41e + b12449b commit ed0d4cb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 27 deletions.
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
"dependencies": {
"@ethercorps/sveltekit-og": "^3.0.0",
"@fontsource-variable/fira-code": "^5.0.19",
"@iconify/json": "^2.2.243",
"@fontsource-variable/inter": "^5.0.20",
"@iconify/json": "^2.2.244",
"@neodrag/svelte": "^2.0.6",
"@shikijs/monaco": "^1.16.1",
"@shikijs/rehype": "^1.16.1",
"@shikijs/monaco": "^1.16.2",
"@shikijs/rehype": "^1.16.2",
"@sveltejs/adapter-netlify": "^4.3.3",
"@sveltejs/kit": "^2.5.25",
"@sveltejs/kit": "^2.5.26",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@unocss/extractor-svelte": "^0.62.3",
"@unocss/reset": "^0.62.3",
Expand All @@ -33,7 +34,7 @@
"htmlparser2": "^9.1.0",
"misans-vf": "^1.0.0",
"monaco-editor-core": "^0.51.0",
"openai": "^4.57.0",
"openai": "^4.57.3",
"paneforge": "^0.0.5",
"pyodide": "0.26.2",
"rehype-parse": "^9.0.0",
Expand All @@ -44,7 +45,7 @@
"remark-rehype": "^11.1.0",
"remark-stringify": "^11.0.0",
"rollup-plugin-flatten-dir": "^1.0.1",
"shiki": "^1.16.1",
"shiki": "^1.16.2",
"svelte": "^4.2.19",
"svelte-portal": "^2.2.1",
"svelte-sonner": "0.3.27",
Expand All @@ -53,16 +54,16 @@
"unified": "^11.0.5",
"unocss": "^0.62.3",
"unzipit": "^1.4.3",
"vite": "^5.4.2"
"vite": "^5.4.3"
},
"devDependencies": {
"@antfu/eslint-config": "^3.0.0",
"@antfu/eslint-config": "^3.2.0",
"@types/mdast": "^4.0.4",
"@types/turndown": "^5.0.5",
"@unocss/eslint-config": "^0.62.3",
"eslint": "^9.9.1",
"eslint-plugin-format": "^0.1.2",
"eslint-plugin-svelte": "^2.43.0",
"svelte-check": "^4.0.0"
"svelte-check": "^4.0.1"
}
}
16 changes: 11 additions & 5 deletions src/lib/components/Tooltip.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@
$: top = `${position.top}px`;
$: left = `${position.left}px`;
let doShow = show;
$: show && (doShow = true);
const maybeHide = () => !show && (doShow = false);
</script>

<Portal>
<div class:op-0={!show} class:pointer-events-none={!show} class="fixed transition-opacity" style:top style:left bind:this={div}>
<slot />
</div>
</Portal>
{#if doShow}
<Portal>
<div on:transitioncancel={maybeHide} on:transitionend={maybeHide} class:op-0={!show} class:pointer-events-none={!show} class="fixed animate-(fade-in duration-150 ease) transition-opacity" style:top style:left bind:this={div}>
<slot />
</div>
</Portal>
{/if}
22 changes: 13 additions & 9 deletions src/lib/components/markdown/InlineCode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@
}
</script>

<Tooltip target={ref} show={show && inspection !== undefined}>
<div class="{outerColor} max-w-lg flex flex-row items-center gap-1.5 overflow-x-hidden ws-nowrap rounded bg-neutral-8/80 p-1.5 pr-2 text-sm text-xs font-mono ring-(1.5 inset) backdrop-blur -translate-y-0.4em <lg:(text-2.75 ring-1.3) <sm:(text-2.5 ring-1.1)">
<div class="{classColor} rounded-sm px-1 py-0.5 font-bold <lg:(px-0.75 py-0.25) <sm:(px-0.5 py-0)">{inspection?.class}</div>
<div class="{valueColor} overflow-x-hidden text-ellipsis">{inspection?.value}</div>
</div>
</Tooltip>

<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<code on:mouseover={() => show = true} on:mouseout={() => show = false} bind:this={ref}>{inlineCode.value}</code>
{#if inspect}
<Tooltip target={ref} show={show && inspection !== undefined}>
<div class="{outerColor} max-w-lg flex flex-row items-center gap-1.5 overflow-x-hidden ws-nowrap rounded bg-neutral-8/80 p-1.5 pr-2 text-sm text-xs font-mono ring-(1.5 inset) backdrop-blur -translate-y-0.4em <lg:(text-2.75 ring-1.3) <sm:(text-2.5 ring-1.1)">
<div class="{classColor} rounded-sm px-1 py-0.5 font-bold <lg:(px-0.75 py-0.25) <sm:(px-0.5 py-0)">{inspection?.class}</div>
<div class="{valueColor} overflow-x-hidden text-ellipsis">{inspection?.value}</div>
</div>
</Tooltip>

<!-- svelte-ignore a11y-mouse-events-have-key-events -->
<code on:mouseover={() => show = true} on:mouseout={() => show = false} bind:this={ref}>{inlineCode.value}</code>
{:else}
<code>{inlineCode.value}</code>
{/if}
36 changes: 36 additions & 0 deletions src/python/common/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import micropip
from js import window
from pyodide.ffi import can_run_sync, run_sync

from .package import get_package_name
from .toast import loading
Expand Down Expand Up @@ -63,6 +64,40 @@ def input(prompt=""):
builtins.input = input


@cache
def patch_sync():
if not can_run_sync():
return

import asyncio
import time
from asyncio import get_running_loop

@wraps(_ := asyncio.run)
def run(future, **kwargs):
if can_run_sync():
return run_sync(future)
return _(future, **kwargs)

asyncio.run = run

@wraps(_ := get_running_loop().run_until_complete)
def run_until_complete(future):
if can_run_sync():
return run_sync(future)
return _(future)

get_running_loop().run_until_complete = run_until_complete

@wraps(_ := time.sleep)
def sleep(duration):
if can_run_sync():
return run_sync(asyncio.sleep(duration))
return _(duration)

time.sleep = sleep


@cache
def patch_exit():
window.close.__signature__ = Signature() # type: ignore
Expand All @@ -73,4 +108,5 @@ def patch_exit():
patch_linecache()
patch_console()
patch_input()
patch_sync()
patch_exit()
10 changes: 10 additions & 0 deletions src/python/common/sync.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from collections.abc import Awaitable, Callable

from pyodide.ffi import run_sync


def syncify[**P, T](func: Callable[P, Awaitable[T]]) -> Callable[P, T]:
def wrapper(*args: P.args, **kwargs: P.kwargs):
return run_sync(func(*args, **kwargs))

return wrapper
8 changes: 4 additions & 4 deletions src/routes/(workspace)/github/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@

{#await Promise.resolve() then}
<Intro title="打开一个 GitHub 仓库为工作区">
<a href="github/promplate/pyth-on-line" in:fly|global={{ duration: 500, x: -5, delay: 100 }}>
<a href="/github/promplate/pyth-on-line" in:fly|global={{ duration: 500, x: -5, delay: 100 }}>
<div class="i-tabler-inner-shadow-bottom-right text-lg text-rose" />
本项目
</a>
<a href="github/promplate/core" in:fly|global={{ duration: 500, x: 5, delay: 150 }}>
<a href="/github/promplate/core" in:fly|global={{ duration: 500, x: 5, delay: 150 }}>
<div class="i-tabler-building-lighthouse text-lg text-yellow" />
我们的提示工程框架
</a>
<a href="github/pyodide/micropip" in:fly|global={{ duration: 500, x: -5, delay: 300 }}>
<a href="/github/pyodide/micropip" in:fly|global={{ duration: 500, x: -5, delay: 300 }}>
<div class="i-tabler-brand-python text-lg text-blue" />
pyodide/micropip
</a>
<a href="github/{input}" class="w-fit" class:cursor-text={!valid} on:click={e => !valid && ([e.preventDefault(), ref.focus()])} in:fly|global={{ duration: 500, x: 5, delay: 500 }}>
<a href="/github/{input}" class="w-fit" class:cursor-text={!valid} on:click={e => !valid && ([e.preventDefault(), ref.focus()])} in:fly|global={{ duration: 500, x: 5, delay: 500 }}>
<div class="i-tabler-brand-github text-lg text-gray-4 transition-color" class:text-gray-1={valid} />
<input class="w-50 bg-transparent outline-none placeholder:(text-inherit op-30)" class:animate-pulse={!input} placeholder="你的 GitHub 仓库" bind:this={ref} on:click|preventDefault={() => { ref.focus(); }} bind:value={input} on:keydown={e => e.key === "Enter" && ref.parentElement?.click()}>
</a>
Expand Down

0 comments on commit ed0d4cb

Please sign in to comment.