This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement main command palette UI
- Loading branch information
1 parent
fa60ace
commit 53b457b
Showing
29 changed files
with
623 additions
and
403 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +0,0 @@ | ||
# Tauri + SvelteKit + TypeScript | ||
|
||
This template should help get you started developing with Tauri, SvelteKit and TypeScript in Vite. | ||
|
||
## Recommended IDE Setup | ||
|
||
[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer). | ||
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
apps/desktop-svelte/src/lib/components/context/AppConfigContext.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script lang="ts"> | ||
import { setAppConfigContext } from "@/context" | ||
import type { AppConfig } from "@/types/appConfig" | ||
import type { Snippet } from "svelte" | ||
import type { Writable } from "svelte/store" | ||
const { appConfig, children }: { appConfig: Writable<AppConfig>; children: Snippet<[]> } = | ||
$props() | ||
setAppConfigContext(appConfig) | ||
</script> | ||
|
||
{@render children?.()} |
4 changes: 4 additions & 0 deletions
4
apps/desktop-svelte/src/lib/components/main/CmdItemExt.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<!-- This file is for rendering an extension command list item --> | ||
<script lang="ts"> | ||
import IconMultiplexer from "@/components/common/IconMultiplexer.svelte" | ||
</script> |
45 changes: 45 additions & 0 deletions
45
apps/desktop-svelte/src/lib/components/main/CommandPalette.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!-- This file renders the main command palette, a list of commands --> | ||
<script lang="ts"> | ||
import { getAppConfigContext } from "@/context" | ||
import { cn } from "@/utils" | ||
import type { ExtPackageJsonExtra } from "@kksh/api/models" | ||
import { isExtPathInDev } from "@kksh/extensions" | ||
import * as Command from "$lib/components/ui/command/index.js" | ||
import ExtCmdsGroup from "./ExtCmdsGroup.svelte" | ||
const { extensions, class: className }: { extensions: ExtPackageJsonExtra[]; class?: string } = | ||
$props() | ||
const appConfig = getAppConfigContext() | ||
</script> | ||
|
||
<Command.Root class={cn("rounded-lg border shadow-md", className)}> | ||
<Command.Input placeholder="Type a command or search..." /> | ||
<Command.List class="h-full max-h-fit"> | ||
<Command.Empty>No results found.</Command.Empty> | ||
{#if $appConfig.extensionPath} | ||
<ExtCmdsGroup | ||
extensions={extensions.filter((ext) => | ||
isExtPathInDev($appConfig.extensionPath!, ext.extPath) | ||
)} | ||
heading="Dev Extensions" | ||
isDev={true} | ||
hmr={$appConfig.hmr} | ||
/> | ||
{/if} | ||
{#if $appConfig.extensionPath} | ||
<ExtCmdsGroup | ||
extensions={extensions.filter( | ||
(ext) => !isExtPathInDev($appConfig.extensionPath!, ext.extPath) | ||
)} | ||
heading="Extensions" | ||
isDev={false} | ||
hmr={false} | ||
/> | ||
{/if} | ||
<Command.Separator /> | ||
</Command.List> | ||
<footer | ||
data-tauri-drag-region | ||
class="absolute bottom-0 left-0 right-0 h-10 bg-slate-500/40" | ||
></footer> | ||
</Command.Root> |
54 changes: 54 additions & 0 deletions
54
apps/desktop-svelte/src/lib/components/main/ExtCmdsGroup.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!-- This file renders a group of extension commands --> | ||
<!-- Input props to this component is an array of ExtPackageJsonExtra[] --> | ||
<script lang="ts"> | ||
import Icon from "@iconify/svelte" | ||
import { | ||
CustomUiCmd, | ||
ExtPackageJsonExtra, | ||
IconEnum, | ||
IconType, | ||
TemplateUiCmd | ||
} from "@kksh/api/models" | ||
import { Badge } from "@kksh/svelte" | ||
import * as Command from "$lib/components/ui/command/index.js" | ||
import IconMultiplexer from "../common/IconMultiplexer.svelte" | ||
const { | ||
extensions, | ||
heading, | ||
isDev, | ||
hmr | ||
}: { extensions: ExtPackageJsonExtra[]; heading: string; isDev: boolean; hmr: boolean } = $props() | ||
</script> | ||
|
||
{#snippet cmd(ext: ExtPackageJsonExtra, cmd: CustomUiCmd | TemplateUiCmd)} | ||
<Command.Item class="flex justify-between"> | ||
<span class="flex gap-2"> | ||
<IconMultiplexer icon={cmd.icon ?? ext.kunkun.icon} class="!h-5 !w-5 shrink-0" /> | ||
<span>{cmd.name}</span> | ||
</span> | ||
<span class="flex gap-2"> | ||
{#if isDev} | ||
<Badge class="rounded-sm bg-green-500 px-1">Dev</Badge> | ||
{/if} | ||
{#if hmr} | ||
<Badge class="rounded-sm px-1">HMR</Badge> | ||
{/if} | ||
</span> | ||
</Command.Item> | ||
{/snippet} | ||
|
||
{#snippet ext(ext: ExtPackageJsonExtra)} | ||
{#each ext.kunkun.customUiCmds as _cmd} | ||
{@render cmd(ext, _cmd)} | ||
{/each} | ||
{#each ext.kunkun.templateUiCmds as _cmd} | ||
{@render cmd(ext, _cmd)} | ||
{/each} | ||
{/snippet} | ||
|
||
<Command.Group {heading}> | ||
{#each extensions as _ext} | ||
{@render ext(_ext)} | ||
{/each} | ||
</Command.Group> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { appDataDir, join } from "@tauri-apps/api/path" | ||
import { PUBLIC_SUPABASE_ANON_KEY, PUBLIC_SUPABASE_PROJECT_ID } from "$env/static/public" | ||
|
||
export const SUPABASE_ANON_KEY = PUBLIC_SUPABASE_ANON_KEY | ||
export const SUPABASE_URL = `https://${PUBLIC_SUPABASE_PROJECT_ID}.supabase.co` | ||
export const SUPABASE_GRAPHQL_ENDPOINT = `${SUPABASE_URL}/graphql/v1` | ||
export function getExtensionsFolder() { | ||
return appDataDir().then((appDataDirPath) => join(appDataDirPath, "extensions")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* This is app state context. | ||
* It's designed to allow all components to access a shared state. | ||
* With context, we can avoid prop drilling, and avoid using stores which makes components hard to encapsulate. | ||
*/ | ||
import type { AppConfig } from '@/types/appConfig'; | ||
import { getContext, setContext } from 'svelte' | ||
import type { Writable } from 'svelte/store'; | ||
|
||
export const APP_CONFIG_CONTEXT_KEY = Symbol('appConfig') | ||
|
||
export function getAppConfigContext(): Writable<AppConfig> { | ||
return getContext(APP_CONFIG_CONTEXT_KEY) | ||
} | ||
|
||
export function setAppConfigContext(appConfig: Writable<AppConfig>) { | ||
setContext(APP_CONFIG_CONTEXT_KEY, appConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './appConfig' |
Oops, something went wrong.