kunkun/packages/ui/src/components/main/ExtCmdsGroup.svelte
Huakun Shen f89cf8fe6a
Some checks are pending
CI / build-test (macos-14) (push) Waiting to run
CI / build-test (ubuntu-24.04) (push) Waiting to run
CI / build-test (windows-latest) (push) Waiting to run
Feature: Headless Command (#44)
* chore: add check-types

* refactor: api package file structure update

* feat: add headless worker extension API

* feat: add HeadlessCmd to manifest schema

* feat: make each type of cmds optional in manifest

There may be more types of cmds in the future, this makes backward compatibility easier.

* feat: implement headless extension command in app

A demo cmd implemented as well.

* refactor: move api package's API server files

* refactor: reformat all
2025-01-05 21:12:56 -05:00

74 lines
1.8 KiB
Svelte

<!-- This file renders a group of extension commands -->
<!-- Input props to this component is an array of ExtPackageJsonExtra[] -->
<script lang="ts">
import {
CmdTypeEnum,
CustomUiCmd,
ExtPackageJsonExtra,
HeadlessCmd,
TemplateUiCmd
} from "@kksh/api/models"
import { Badge, Command } from "@kksh/svelte5"
import { IconMultiplexer } from "@kksh/ui"
import { DraggableCommandGroup } from "../custom"
import type { CmdValue, OnExtCmdSelect } from "./types"
const {
extensions,
heading,
isDev,
hmr,
onExtCmdSelect
}: {
extensions: ExtPackageJsonExtra[]
heading: string
isDev: boolean
hmr: boolean
onExtCmdSelect: OnExtCmdSelect
} = $props()
</script>
{#snippet cmd(ext: ExtPackageJsonExtra, cmd: CustomUiCmd | TemplateUiCmd | HeadlessCmd)}
<Command.Item
class="flex justify-between"
onSelect={() => {
onExtCmdSelect(ext, cmd, { isDev, hmr })
}}
value={JSON.stringify({
cmdName: cmd.name,
cmdType: cmd.type,
data: { isDev: heading === "Dev Extensions" }
} satisfies CmdValue)}
>
<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-1">
{#if isDev}
<Badge class="scale-75 rounded-sm bg-green-500 px-1">Dev</Badge>
{/if}
{#if hmr}
<Badge class="scale-75 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}
{#each ext.kunkun.headlessCmds ?? [] as _cmd}
{@render cmd(ext, _cmd)}
{/each}
{/snippet}
<DraggableCommandGroup {heading}>
{#each extensions as _ext}
{@render ext(_ext)}
{/each}
</DraggableCommandGroup>