Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
feat: redesigned templates browser and view (#3304)
Kyle Mendellb3eb2992aaa8
diff --git a/frontend/messages/en.json b/frontend/messages/en.jsonindex 1d45d5212..e7ddc090f 100644--- a/frontend/messages/en.json+++ b/frontend/messages/en.json@@ -1920,6 +1920,8 @@"templates_sort_name_asc": "Name (A-Z)","templates_sort_name_desc": "Name (Z-A)","templates_no_templates": "No templates available",+ "templates_search_placeholder": "Search templates...",+ "templates_no_description": "No description provided","templates_add_registry_prompt_part1": "Add a template registry in ","templates_add_registry_prompt_part2": " to access community templates.","templates_template_settings": "Template Settings",diff --git a/frontend/src/lib/components/ComposeTemplateEditor.svelte b/frontend/src/lib/components/ComposeTemplateEditor.svelteindex 39bdb2057..8aa8221b5 100644--- a/frontend/src/lib/components/ComposeTemplateEditor.svelte+++ b/frontend/src/lib/components/ComposeTemplateEditor.svelte@@ -53,7 +53,7 @@envClass="contents">{#snippet compose()}- <Card.Root class="flex min-h-0 min-w-0 flex-1 flex-col lg:col-span-3">+ <Card.Root class="flex min-h-[360px] min-w-0 flex-1 flex-col lg:col-span-3 lg:min-h-0"><Card.Header icon={CodeIcon} class="shrink-0"><div class="flex flex-col space-y-1.5"><Card.Title>@@ -91,7 +91,7 @@{/snippet}{#snippet env()}- <Card.Root class="flex min-h-0 min-w-0 flex-1 flex-col lg:col-span-2">+ <Card.Root class="flex min-h-[360px] min-w-0 flex-1 flex-col lg:col-span-2 lg:min-h-0"><Card.Header icon={VariableIcon} class="shrink-0"><div class="flex flex-col space-y-1.5"><Card.Title>diff --git a/frontend/src/routes/(app)/customize/templates/+page.svelte b/frontend/src/routes/(app)/customize/templates/+page.svelteindex 9ce82b8f2..127ecbfb0 100644--- a/frontend/src/routes/(app)/customize/templates/+page.svelte+++ b/frontend/src/routes/(app)/customize/templates/+page.svelte@@ -7,7 +7,7 @@import { ResourcePageLayout, type ActionButton, type StatCardConfig } from '$lib/layouts';import { TabBar, type TabItem } from '$lib/components/tab-bar';import * as Tabs from '$lib/components/ui/tabs';- import TemplatesBrowser from './components/TemplatesBrowser.svelte';+ import TemplateGallery from './components/template-gallery.svelte';import RegistryManager from './components/RegistryManager.svelte';import type { TemplateRegistry } from '$lib/types/swarm';import { untrack } from 'svelte';@@ -200,7 +200,7 @@</div><Tabs.Content value="browse">- <TemplatesBrowser bind:templates bind:requestOptions />+ <TemplateGallery bind:templates bind:requestOptions /></Tabs.Content><Tabs.Content value="registries">diff --git a/frontend/src/routes/(app)/customize/templates/+page.ts b/frontend/src/routes/(app)/customize/templates/+page.tsindex 489590003..0cce75ab5 100644--- a/frontend/src/routes/(app)/customize/templates/+page.ts+++ b/frontend/src/routes/(app)/customize/templates/+page.ts@@ -14,7 +14,7 @@ export const load: PageLoad = async ({}> => {const { queryClient } = await parent();- const templateRequestOptions = resolveInitialTableRequest('arcane-template-table', {+ const templateRequestOptions = resolveInitialTableRequest('arcane-template-gallery', {pagination: { page: 1, limit: 20 },sort: { column: 'name', direction: 'asc' }} satisfies SearchPaginationSortRequest);diff --git a/frontend/src/routes/(app)/customize/templates/[id]/+page.svelte b/frontend/src/routes/(app)/customize/templates/[id]/+page.svelteindex 839fde476..1ba61762e 100644--- a/frontend/src/routes/(app)/customize/templates/[id]/+page.svelte+++ b/frontend/src/routes/(app)/customize/templates/[id]/+page.svelte@@ -1,10 +1,12 @@<script lang="ts">- import { ArcaneButton } from '$lib/components/arcane-button/index.js';- import * as Card from '$lib/components/ui/card';import { Badge } from '$lib/components/ui/badge';+ import { Spinner } from '$lib/components/ui/spinner/index.js';+ import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';import CodeEditor from '$lib/components/code-editor/editor.svelte';- import FormInput from '$lib/components/form/form-input.svelte';- import IconImage from '$lib/components/icon-image.svelte';+ import TemplateEditorWorkspace from '../components/template-editor-workspace.svelte';+ import { ResourceDetailLayout, type DetailAction } from '$lib/layouts';+ import IfPermitted from '$lib/components/if-permitted.svelte';import { goto, refreshAll } from '$app/navigation';import { m } from '$lib/paraglide/messages.js';import { templateService } from '$lib/services/template-service';@@ -12,7 +14,7 @@import { untrack } from 'svelte';import { toast } from 'svelte-sonner';import { createForm } from '$lib/utils/settings';- import ComposeTemplateEditor from '$lib/components/ComposeTemplateEditor.svelte';+ import { formatDateTimeShort } from '$lib/utils/formatting';import { globalVariablesToMap } from '$lib/utils/template-load';import {createNamedTemplateSchema,@@ -21,16 +23,15 @@runTemplateEditorSave} from '$lib/utils/template-editor';import {- ArrowLeftIcon,- ProjectsIcon,+ EllipsisIcon,CodeIcon,- TemplateIcon,- DownloadIcon,GlobeIcon,- ContainersIcon,BoxIcon,- VariableIcon,- FileTextIcon+ FileTextIcon,+ RegistryIcon,+ ExternalLinkIcon,+ MoveToFolderIcon,+ TrashIcon} from '$lib/icons';let { data } = $props();@@ -181,277 +182,246 @@}});}-</script>--<div class="mx-auto flex h-full min-h-0 w-full max-w-full flex-col gap-6 overflow-hidden p-2 pb-10 sm:p-6 sm:pb-10">- <!-- Header -->- <!-- fallow-ignore-next-line code-duplication page header/back chrome differs per template page (editable vs static header) -->- <div class="flex-shrink-0 space-y-3 sm:space-y-4">- <ArcaneButton action="base" tone="ghost" onclick={() => goto('/customize/templates')} class="w-fit gap-2">- <ArrowLeftIcon class="size-4" />- <span>{m.common_back_to({ resource: m.templates_title() })}</span>- </ArcaneButton>- {#if !template.isRemote}- <!-- Editable header for custom templates -->- <div class="flex flex-col justify-between gap-4 sm:flex-row sm:items-start">- <div class="min-w-0 flex-1 space-y-3">- <FormInput- input={$inputs.name}- label={m.templates_template_name_label()}- placeholder={m.templates_template_name_placeholder()}- disabled={status.saving}- />- <FormInput- input={$inputs.description}- label={m.templates_template_description_label()}- placeholder={m.templates_template_description_placeholder()}- disabled={status.saving}- />- </div>- <div class="flex flex-col gap-2 sm:flex-row sm:items-start">- <ArcaneButton- action="create"- onclick={() => goto(`/projects/new?templateId=${template.id}`)}- customLabel={m.compose_create_project()}- class="w-full gap-2 sm:w-auto"- />- <ArcaneButton action="cancel" onclick={handleReset} disabled={!hasChanges || status.saving}>- {m.common_reset()}- </ArcaneButton>- <ArcaneButton- action="save"- onclick={handleSave}- disabled={!canSave}- loading={status.saving}- loadingLabel={m.common_action_saving()}- />- <ArcaneButton- action="remove"- onclick={handleDelete}- disabled={status.isDeleting}- loading={status.isDeleting}- loadingLabel={m.common_action_deleting()}- customLabel={m.templates_delete_template()}- class="w-full gap-2 sm:w-auto"- />- </div>- </div>+ const remoteActions = $derived.by(() => {+ const actions: DetailAction[] = [+ {+ id: 'create-project',+ action: 'create',+ label: m.compose_create_project(),+ onclick: () => goto(`/projects/new?templateId=${template.id}`)+ }+ ];+ if (canDownload) {+ actions.push({+ id: 'download',+ action: 'base',+ label: m.templates_download(),+ loadingLabel: m.common_action_downloading(),+ loading: status.isDownloading,+ disabled: status.isDownloading,+ onclick: handleDownload+ });+ } else if (localVersionOfRemote) {+ actions.push({+ id: 'view-local',+ action: 'base',+ label: m.templates_view_local_version(),+ onclick: () => goto(`/customize/templates/${localVersionOfRemote?.id}`)+ });+ }+ return actions;+ });- <div class="flex flex-wrap items-center gap-2">- <Badge variant="secondary" class="gap-1">- <TemplateIcon class="size-3" />- {m.templates_local()}- </Badge>- </div>- {:else}- <!-- Read-only header for remote templates -->- <div class="flex min-w-0 items-start gap-3">- <IconImage- src={template.metadata?.iconUrl}- alt={template.name}- fallback={GlobeIcon}- class="size-6"- containerClass="size-9 bg-transparent ring-0"- />- <div class="min-w-0 flex-1">- <h1 class="text-xl font-semibold break-words sm:text-2xl">{template.name}</h1>- {#if template.description}- <p class="mt-1.5 text-sm break-words text-muted-foreground sm:text-base">{template.description}</p>- {/if}- </div>- </div>+ const documentationHost = $derived.by(() => {+ const url = template.metadata?.documentationUrl;+ if (!url) return null;+ try {+ return new URL(url).hostname;+ } catch {+ return url;+ }+ });+</script>- <div class="flex flex-wrap items-center gap-2">- <Badge variant="secondary" class="gap-1">- <GlobeIcon class="size-3" />- {m.templates_remote()}+{#if !template.isRemote}+ <!-- Editor workspace for custom templates (same chrome as the create page) -->+ <TemplateEditorWorkspace+ {inputs}+ bind:validation+ {originalName}+ {originalCompose}+ {originalEnv}+ fileIdPrefix="templates:custom:{template.id}"+ {globalVariableMap}+ saving={status.saving}+ onSubmit={handleSave}+ >+ {#snippet toolbarActions()}+ <ArcaneButton action="cancel" onclick={handleReset} disabled={!hasChanges || status.saving}>+ {m.common_reset()}+ </ArcaneButton>+ <ArcaneButton+ action="save"+ onclick={handleSave}+ disabled={!canSave}+ loading={status.saving}+ loadingLabel={m.common_action_saving()}+ />+ <DropdownMenu.Root>+ <DropdownMenu.Trigger>+ {#snippet child({ props })}+ <ArcaneButton {...props} action="base" tone="ghost" size="icon" class="size-9">+ <span class="sr-only">{m.common_open_menu()}</span>+ <EllipsisIcon class="size-4" />+ </ArcaneButton>+ {/snippet}+ </DropdownMenu.Trigger>+ <DropdownMenu.Content align="end">+ <IfPermitted perm="projects:create">+ <DropdownMenu.Item onclick={() => goto(`/projects/new?templateId=${template.id}`)}>+ <MoveToFolderIcon class="size-4" />+ {m.compose_create_project()}+ </DropdownMenu.Item>+ <DropdownMenu.Separator />+ </IfPermitted>+ <DropdownMenu.Item variant="destructive" onclick={handleDelete} disabled={status.isDeleting}>+ {#if status.isDeleting}+ <Spinner class="size-4" />+ {:else}+ <TrashIcon class="size-4" />+ {/if}+ {m.templates_delete_template()}+ </DropdownMenu.Item>+ </DropdownMenu.Content>+ </DropdownMenu.Root>+ {/snippet}+ </TemplateEditorWorkspace>+{:else}+ <!-- Marketplace-style read-only view for remote templates -->+ <ResourceDetailLayout+ backUrl="/customize/templates"+ backLabel={m.templates_title()}+ title={template.name}+ subtitle={template.description}+ actions={remoteActions}+ >+ {#snippet badges()}+ <Badge variant="secondary" class="gap-1">+ <GlobeIcon class="size-3" />+ {m.templates_remote()}+ </Badge>+ {#if template.registry?.name}+ <Badge variant="outline" class="gap-1">+ <RegistryIcon class="size-3" />+ {template.registry.name}</Badge>- {#if template.metadata?.tags && template.metadata.tags.length > 0}- {#each template.metadata.tags as tag (tag)}- <Badge variant="outline">{tag}</Badge>- {/each}- {/if}- </div>-- <div class="flex flex-col gap-2 sm:flex-row">- <ArcaneButton- action="create"- onclick={() => goto(`/projects/new?templateId=${template.id}`)}- customLabel={m.compose_create_project()}- class="w-full gap-2 sm:w-auto"- />- {#if canDownload}- <ArcaneButton- action="base"- onclick={handleDownload}- disabled={status.isDownloading}- loading={status.isDownloading}- loadingLabel={m.common_action_downloading()}- class="w-full gap-2 sm:w-auto"- >- <DownloadIcon class="size-4" />- {m.templates_download()}- </ArcaneButton>- {:else if template.isRemote && localVersionOfRemote}- <ArcaneButton- action="base"- onclick={() => goto(`/customize/templates/${localVersionOfRemote?.id}`)}- class="w-full gap-2 sm:w-auto"- >- <ProjectsIcon class="size-4" />- {m.templates_view_local_version()}- </ArcaneButton>- {/if}- </div>- {/if}- </div>+ {/if}+ {/snippet}- {#if !template.isRemote}- <!-- Edit layout: compose editor + env editor side by side -->- <ComposeTemplateEditor- bind:composeValue={$inputs.composeContent.value}- bind:envValue={$inputs.envContent.value}- {originalCompose}- {originalEnv}- bind:validation- {globalVariableMap}- fileIdPrefix="templates:custom:{template.id}"- readOnly={status.saving}- composeError={$inputs.composeContent.error}- envError={$inputs.envContent.error}- />- {:else}- <!-- Read-only view for remote templates -->- <div class="grid flex-shrink-0 gap-4 sm:grid-cols-2">- <Card.Root variant="subtle">- <Card.Content class="flex items-center gap-4 p-4">- <div class="flex size-12 shrink-0 items-center justify-center rounded-lg bg-blue-500/10">- <ContainersIcon class="size-6 text-blue-500" />+ <div class="flex flex-col gap-8 lg:flex-row">+ <div class="min-w-0 flex-1 space-y-8">+ <section class="space-y-2">+ <div class="flex items-center gap-2">+ <CodeIcon class="size-4 text-muted-foreground" />+ <h2 class="font-mono text-sm font-medium">compose.yaml</h2></div>- <div class="min-w-0 flex-1">- <div class="text-xs font-semibold tracking-wide text-muted-foreground uppercase">{m.compose_services()}</div>- <div class="mt-1">- <div class="text-2xl font-semibold">{services?.length ?? 0}</div>+ <div class="relative h-[480px] overflow-hidden rounded-lg border border-border/50 sm:h-[560px]">+ <div class="absolute inset-0">+ <CodeEditor bind:value={data.templateData.content} language="yaml" readOnly={true} fontSize="13px" /></div></div>- </Card.Content>- </Card.Root>+ </section>- <Card.Root variant="subtle">- <Card.Content class="flex items-center gap-4 p-4">- <div class="flex size-12 shrink-0 items-center justify-center rounded-lg bg-purple-500/10">- <VariableIcon class="size-6 text-purple-500" />- </div>- <div class="min-w-0 flex-1">- <div class="text-xs font-semibold tracking-wide text-muted-foreground uppercase">- {m.common_environment_variables()}+ {#if data.templateData.envContent}+ <section class="space-y-2">+ <div class="flex items-center gap-2">+ <FileTextIcon class="size-4 text-muted-foreground" />+ <h2 class="font-mono text-sm font-medium">.env</h2></div>- <div class="mt-1 flex flex-wrap items-baseline gap-2">- <div class="text-2xl font-semibold">{envVars?.length ?? 0}</div>- {#if envVars?.length}- <div class="text-sm text-muted-foreground">{m.templates_configurable_settings()}</div>- {/if}+ <div class="relative h-[280px] overflow-hidden rounded-lg border border-border/50">+ <div class="absolute inset-0">+ <CodeEditor bind:value={data.templateData.envContent} language="env" readOnly={true} fontSize="13px" />+ </div></div>- </div>- </Card.Content>- </Card.Root>- </div>+ </section>+ {/if}+ </div>- <div class="min-h-0 flex-1">- <div class="grid h-full min-h-0 gap-6 lg:grid-cols-2 xl:grid-cols-3">- <Card.Root class="flex h-full min-h-0 min-w-0 flex-col lg:col-span-1 xl:col-span-2">- <Card.Header icon={CodeIcon} class="flex-shrink-0">- <div class="flex flex-col space-y-1.5">- <Card.Title>- <h2>{m.common_docker_compose()}</h2>- </Card.Title>- <Card.Description>{m.templates_service_definitions()}</Card.Description>- </div>- </Card.Header>- <Card.Content class="relative z-[var(--arcane-z-content)] flex min-h-0 min-w-0 flex-1 flex-col overflow-visible p-0">- <div class="absolute inset-0 min-h-0 w-full min-w-0 rounded-t-none rounded-b-xl">- <CodeEditor bind:value={data.templateData.content} language="yaml" readOnly={true} fontSize="13px" />- </div>- </Card.Content>- </Card.Root>+ <aside class="w-full shrink-0 space-y-6 lg:w-72 lg:border-l lg:border-border/50 lg:pl-8 xl:w-80">+ <div class="space-y-3">+ <h3 class="text-xs font-semibold tracking-wide text-muted-foreground uppercase">{m.common_overview()}</h3>+ <dl class="space-y-2 text-sm">+ {#if template.registry?.name}+ <div class="flex items-center justify-between gap-4">+ <dt class="shrink-0 text-muted-foreground">{m.resource_registry_cap()}</dt>+ <dd class="min-w-0 text-right font-medium break-words">{template.registry.name}</dd>+ </div>+ {/if}+ {#if template.metadata?.version}+ <div class="flex items-center justify-between gap-4">+ <dt class="shrink-0 text-muted-foreground">{m.common_version()}</dt>+ <dd class="min-w-0 text-right font-medium break-words">{template.metadata.version}</dd>+ </div>+ {/if}+ {#if template.metadata?.author}+ <div class="flex items-center justify-between gap-4">+ <dt class="shrink-0 text-muted-foreground">{m.common_author()}</dt>+ <dd class="min-w-0 text-right font-medium break-words">{template.metadata.author}</dd>+ </div>+ {/if}+ {#if template.metadata?.updatedAt}+ <div class="flex items-center justify-between gap-4">+ <dt class="shrink-0 text-muted-foreground">{m.common_updated()}</dt>+ <dd class="min-w-0 text-right font-medium break-words">{formatDateTimeShort(template.metadata.updatedAt)}</dd>+ </div>+ {/if}+ {#if template.metadata?.documentationUrl}+ <div class="flex items-center justify-between gap-4">+ <dt class="shrink-0 text-muted-foreground">{m.common_documentation()}</dt>+ <dd class="min-w-0 text-right">+ <a+ href={template.metadata.documentationUrl}+ target="_blank"+ rel="noopener noreferrer"+ class="inline-flex items-center gap-1 font-medium break-all text-primary hover:underline"+ >+ {documentationHost}+ <ExternalLinkIcon class="size-3.5 shrink-0" />+ </a>+ </dd>+ </div>+ {/if}+ </dl>+ </div>- <div class="flex h-full min-h-0 min-w-0 flex-1 flex-col gap-6 lg:col-span-1">- {#if services?.length}- <Card.Root class="min-w-0 flex-shrink-0">- <Card.Header icon={ContainersIcon}>- <div class="flex flex-col space-y-1.5">- <Card.Title>- <h2>{m.services()}</h2>- </Card.Title>- <Card.Description>{m.templates_containers_to_create()}</Card.Description>- </div>- </Card.Header>- <Card.Content class="grid grid-cols-1 gap-2 p-4">- {#each services as service (service)}- <Card.Root variant="subtle" class="min-w-0">- <Card.Content class="flex min-w-0 items-center gap-3 p-3">- <div class="flex size-8 shrink-0 items-center justify-center rounded-lg bg-blue-500/10">- <BoxIcon class="size-4 text-blue-500" />- </div>- <div class="min-w-0 flex-1 truncate font-mono text-sm font-semibold">{service}</div>- </Card.Content>- </Card.Root>- {/each}- </Card.Content>- </Card.Root>- {/if}+ {#if services?.length}+ <div class="space-y-3 border-t border-border/50 pt-6">+ <h3 class="text-xs font-semibold tracking-wide text-muted-foreground uppercase">+ {m.services()} ({services.length})+ </h3>+ <ul class="space-y-1.5">+ {#each services as service (service)}+ <li class="flex min-w-0 items-center gap-2 text-sm">+ <BoxIcon class="size-4 shrink-0 text-muted-foreground" />+ <span class="min-w-0 truncate font-mono">{service}</span>+ </li>+ {/each}+ </ul>+ </div>+ {/if}- {#if envVars?.length}- <Card.Root class="min-w-0 flex-shrink-0">- <Card.Header icon={VariableIcon}>- <div class="flex flex-col space-y-1.5">- <Card.Title>- <h2>{m.common_environment_variables()}</h2>- </Card.Title>- <Card.Description>{m.templates_default_config_values()}</Card.Description>+ {#if envVars?.length}+ <div class="space-y-3 border-t border-border/50 pt-6">+ <h3 class="text-xs font-semibold tracking-wide text-muted-foreground uppercase">+ {m.common_environment_variables()} ({envVars.length})+ </h3>+ <div class="space-y-2.5">+ {#each envVars as envVar (envVar.key)}+ <div class="min-w-0">+ <div class="font-mono text-xs font-medium break-words select-all">{envVar.key}</div>+ {#if envVar.value}+ <div class="font-mono text-xs break-words text-muted-foreground select-all">{envVar.value}</div>+ {:else}+ <div class="text-xs text-muted-foreground italic">{m.common_no_default_value()}</div>+ {/if}</div>- </Card.Header>- <Card.Content class="grid grid-cols-1 gap-2 p-4">- {#each envVars as envVar (envVar.key)}- <Card.Root variant="subtle" class="min-w-0">- <Card.Content class="flex min-w-0 flex-col gap-2 p-3">- <div class="text-xs font-semibold tracking-wide break-words text-muted-foreground uppercase select-all">- {envVar.key}- </div>- {#if envVar.value}- <div class="min-w-0 font-mono text-sm break-words text-foreground select-all">{envVar.value}</div>- {:else}- <div class="text-xs text-muted-foreground italic">{m.common_no_default_value()}</div>- {/if}- </Card.Content>- </Card.Root>- {/each}- </Card.Content>- </Card.Root>- {/if}+ {/each}+ </div>+ </div>+ {/if}- {#if data.templateData.envContent}- <Card.Root class="flex h-full min-h-0 min-w-0 flex-1 flex-col">- <Card.Header icon={FileTextIcon} class="flex-shrink-0">- <div class="flex flex-col space-y-1.5">- <Card.Title>- <h2>{m.environment_file()}</h2>- </Card.Title>- <Card.Description>{m.templates_raw_env_config()}</Card.Description>- </div>- </Card.Header>- <Card.Content- class="relative z-[var(--arcane-z-content)] flex min-h-0 min-w-0 flex-1 flex-col overflow-visible p-0"- >- <div class="absolute inset-0 min-h-0 w-full min-w-0 rounded-b-xl">- <CodeEditor bind:value={data.templateData.envContent} language="env" readOnly={true} fontSize="13px" />- </div>- </Card.Content>- </Card.Root>- {/if}- </div>- </div>+ {#if template.metadata?.tags && template.metadata.tags.length > 0}+ <div class="space-y-3 border-t border-border/50 pt-6">+ <h3 class="text-xs font-semibold tracking-wide text-muted-foreground uppercase">{m.common_tags()}</h3>+ <div class="flex flex-wrap gap-1">+ {#each template.metadata.tags as tag (tag)}+ <Badge variant="outline" class="text-xs">{tag}</Badge>+ {/each}+ </div>+ </div>+ {/if}+ </aside></div>- {/if}-</div>+ </ResourceDetailLayout>+{/if}diff --git a/frontend/src/routes/(app)/customize/templates/components/RegistryManager.svelte b/frontend/src/routes/(app)/customize/templates/components/RegistryManager.svelteindex 10c2ab313..bb39fa065 100644--- a/frontend/src/routes/(app)/customize/templates/components/RegistryManager.svelte+++ b/frontend/src/routes/(app)/customize/templates/components/RegistryManager.svelte@@ -1,6 +1,5 @@<script lang="ts">import { ArcaneButton } from '$lib/components/arcane-button/index.js';- import * as Card from '$lib/components/ui/card';import { Badge } from '$lib/components/ui/badge';import * as Alert from '$lib/components/ui/alert';import { Switch } from '$lib/components/ui/switch';@@ -62,8 +61,8 @@</div>{:else}<div class="space-y-3">- {#each registries as registry}- <Card.Root class="p-4">+ {#each registries as registry (registry.id)}+ <div class="rounded-xl border border-border/50 p-4"><div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between"><div class="min-w-0 flex-1"><div class="mb-1 flex flex-wrap items-center gap-2">@@ -107,7 +106,7 @@/></div></div>- </Card.Root>+ </div>{/each}</div>{/if}diff --git a/frontend/src/routes/(app)/customize/templates/components/TemplatesBrowser.svelte b/frontend/src/routes/(app)/customize/templates/components/TemplatesBrowser.sveltedeleted file mode 100644index 86b0c9a47..000000000--- a/frontend/src/routes/(app)/customize/templates/components/TemplatesBrowser.svelte+++ /dev/null@@ -1,17 +0,0 @@-<script lang="ts">- import TemplateTable from '../template-table.svelte';- import type { Paginated, SearchPaginationSortRequest } from '$lib/types/shared';- import type { Template } from '$lib/types/swarm';-- let {- templates = $bindable(),- requestOptions = $bindable()- }: {- templates: Paginated<Template>;- requestOptions: SearchPaginationSortRequest;- } = $props();-- let selectedIds = $state<string[]>([]);-</script>--<TemplateTable bind:templates bind:selectedIds bind:requestOptions />diff --git a/frontend/src/routes/(app)/customize/templates/components/template-card.svelte b/frontend/src/routes/(app)/customize/templates/components/template-card.sveltenew file mode 100644index 000000000..4e11b9a39--- /dev/null+++ b/frontend/src/routes/(app)/customize/templates/components/template-card.svelte@@ -0,0 +1,117 @@+<script lang="ts">+ import { Badge } from '$lib/components/ui/badge';+ import { Spinner } from '$lib/components/ui/spinner/index.js';+ import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';+ import RowActionsMenu from '$lib/components/arcane-table/row-actions-menu.svelte';+ import IconImage from '$lib/components/icon-image.svelte';+ import IfPermitted from '$lib/components/if-permitted.svelte';+ import { goto } from '$app/navigation';+ import { m } from '$lib/paraglide/messages';+ import { hasPermission } from '$lib/utils/auth';+ import type { Template } from '$lib/types/swarm';+ import { InspectIcon, FolderOpenIcon, GlobeIcon, TrashIcon, DownloadIcon, MoveToFolderIcon } from '$lib/icons';++ let {+ template,+ downloading = false,+ deleting = false,+ onDownload,+ onDelete+ }: {+ template: Template;+ downloading?: boolean;+ deleting?: boolean;+ onDownload: (template: Template) => void;+ onDelete: (template: Template) => void;+ } = $props();++ const MAX_TAGS = 4;++ const canReadTemplate = $derived(hasPermission('templates:read'));+ const canDeleteTemplate = $derived(hasPermission('templates:delete'));+ const registryName = $derived(+ template.registry?.name ?? (template.isRemote ? m.templates_unknown_registry() : m.templates_local_templates())+ );+ const tags = $derived(template.metadata?.tags ?? []);+</script>++<div+ class="group relative flex h-full flex-col gap-3 rounded-xl border border-border/50 bg-card/30 p-4 transition-colors hover:bg-muted/40"+>+ <div class="flex items-start gap-3">+ <IconImage+ src={template.metadata?.iconUrl}+ alt={template.name}+ fallback={template.isRemote ? GlobeIcon : FolderOpenIcon}+ class="size-5"+ containerClass="size-9"+ />+ <div class="min-w-0 flex-1">+ <a+ href="/customize/templates/{template.id}"+ class="block truncate font-medium after:absolute after:inset-0 hover:underline"+ >+ {template.name}+ </a>+ <p class="truncate text-xs text-muted-foreground">+ {template.isRemote ? m.templates_remote() : m.templates_local()} · {registryName}+ </p>+ </div>+ <div class="relative z-10 -mt-1 -mr-1 shrink-0">+ <RowActionsMenu>+ <DropdownMenu.Item onclick={() => goto(`/customize/templates/${template.id}`)}>+ <InspectIcon class="size-4" />+ {m.common_view_details()}+ </DropdownMenu.Item>++ <IfPermitted perm="projects:create">+ <DropdownMenu.Item onclick={() => goto(`/projects/new?templateId=${template.id}`)}>+ <MoveToFolderIcon class="size-4" />+ {m.compose_create_project()}+ </DropdownMenu.Item>+ </IfPermitted>++ {#if (template.isRemote && canReadTemplate) || (!template.isRemote && canDeleteTemplate)}+ <DropdownMenu.Separator />+ {/if}++ {#if template.isRemote && canReadTemplate}+ <DropdownMenu.Item onclick={() => onDownload(template)} disabled={downloading}>+ {#if downloading}+ <Spinner class="size-4" />+ {:else}+ <DownloadIcon class="size-4" />+ {/if}+ {m.templates_download()}+ </DropdownMenu.Item>+ {:else if !template.isRemote && canDeleteTemplate}+ <DropdownMenu.Item variant="destructive" onclick={() => onDelete(template)} disabled={deleting}>+ {#if deleting}+ <Spinner class="size-4" />+ {:else}+ <TrashIcon class="size-4" />+ {/if}+ {m.templates_delete_template()}+ </DropdownMenu.Item>+ {/if}+ </RowActionsMenu>+ </div>+ </div>++ {#if template.description}+ <p class="line-clamp-3 text-sm text-muted-foreground">{template.description}</p>+ {:else}+ <p class="text-sm text-muted-foreground italic">{m.templates_no_description()}</p>+ {/if}++ {#if tags.length > 0}+ <div class="mt-auto flex flex-wrap gap-1">+ {#each tags.slice(0, MAX_TAGS) as tag (tag)}+ <Badge variant="outline" class="text-xs">{tag}</Badge>+ {/each}+ {#if tags.length > MAX_TAGS}+ <Badge variant="outline" class="text-xs">+{tags.length - MAX_TAGS}</Badge>+ {/if}+ </div>+ {/if}+</div>diff --git a/frontend/src/routes/(app)/customize/templates/components/template-editor-workspace.svelte b/frontend/src/routes/(app)/customize/templates/components/template-editor-workspace.sveltenew file mode 100644index 000000000..be9d8d9cf--- /dev/null+++ b/frontend/src/routes/(app)/customize/templates/components/template-editor-workspace.svelte@@ -0,0 +1,160 @@+<script lang="ts">+ import { ArcaneButton } from '$lib/components/arcane-button/index.js';+ import FormInput from '$lib/components/form/form-input.svelte';+ import CodePanel from '../../../projects/components/CodePanel.svelte';+ import EditableName from '../../../projects/components/EditableName.svelte';+ import { ComposeEditorSplit } from '$lib/components/compose';+ import { goto } from '$app/navigation';+ import { m } from '$lib/paraglide/messages';+ import { preventDefault, type FormInputs } from '$lib/utils/settings';+ import { ArrowLeftIcon } from '$lib/icons';+ import type { Writable } from 'svelte/store';+ import type { Snippet } from 'svelte';++ interface ValidationState {+ composeHasErrors: boolean;+ envHasErrors: boolean;+ composeValidationReady: boolean;+ envValidationReady: boolean;+ }++ type NamedTemplateValues = {+ name: string;+ description: string;+ composeContent: string;+ envContent: string;+ };++ let {+ inputs,+ validation = $bindable(),+ originalName = '',+ originalCompose,+ originalEnv,+ fileIdPrefix,+ globalVariableMap,+ saving = false,+ onSubmit,+ toolbarActions+ }: {+ inputs: Writable<FormInputs<NamedTemplateValues>>;+ validation: ValidationState;+ originalName?: string;+ originalCompose?: string;+ originalEnv?: string;+ fileIdPrefix: string;+ globalVariableMap: Record<string, string>;+ saving?: boolean;+ onSubmit: () => void;+ toolbarActions: Snippet;+ } = $props();++ let nameInputRef = $state<HTMLInputElement | null>(null);+ const enableDiff = $derived(originalCompose !== undefined);+</script>++<div class="flex h-full min-h-0 flex-col bg-background">+ <div class="sticky top-0 mb-2 border-b">+ <div class="mx-auto flex h-16 max-w-full items-center justify-between gap-4 px-6">+ <div class="flex min-w-0 items-center gap-4">+ <ArcaneButton+ action="base"+ tone="ghost"+ size="sm"+ class="gap-2 bg-transparent"+ icon={ArrowLeftIcon}+ customLabel={m.common_back()}+ onclick={() => goto('/customize/templates')}+ />+ <div class="hidden h-4 w-px bg-border sm:block"></div>+ <div class="hidden min-w-0 items-center gap-3 sm:flex">+ <EditableName+ bind:value={$inputs.name.value}+ bind:ref={nameInputRef}+ variant="inline"+ error={$inputs.name.error ?? undefined}+ originalValue={originalName}+ placeholder={m.templates_template_name_placeholder()}+ canEdit={!saving}+ class="hidden sm:block"+ />+ </div>+ </div>++ <div class="flex items-center gap-2">+ {@render toolbarActions()}+ </div>+ </div>+ </div>++ <div class="flex min-h-0 flex-1 overflow-hidden">+ <div class="mx-auto flex h-full w-full max-w-full min-w-0 flex-col px-2 pb-6 sm:px-6 sm:pb-6">+ <form class="flex min-h-0 flex-1 flex-col gap-4" onsubmit={preventDefault(onSubmit)}>+ <div class="block flex-shrink-0 py-4 sm:hidden">+ <EditableName+ bind:value={$inputs.name.value}+ bind:ref={nameInputRef}+ variant="block"+ error={$inputs.name.error ?? undefined}+ originalValue={originalName}+ placeholder={m.templates_template_name_placeholder()}+ canEdit={!saving}+ />+ </div>++ <div class="flex-shrink-0 px-1 pt-1">+ <div class="max-w-2xl">+ <FormInput+ input={$inputs.description}+ label={m.templates_template_description_label()}+ placeholder={m.templates_template_description_placeholder()}+ disabled={saving}+ />+ </div>+ </div>++ <ComposeEditorSplit>+ {#snippet compose()}+ <CodePanel+ title="compose.yaml"+ language="yaml"+ bind:value={$inputs.composeContent.value}+ error={$inputs.composeContent.error ?? undefined}+ readOnly={saving}+ bind:hasErrors={validation.composeHasErrors}+ bind:validationReady={validation.composeValidationReady}+ fileId="{fileIdPrefix}:compose"+ originalValue={originalCompose}+ {enableDiff}+ editorContext={{+ envContent: $inputs.envContent.value,+ composeContents: [$inputs.composeContent.value],+ globalVariables: globalVariableMap+ }}+ />+ {/snippet}++ {#snippet env()}+ <CodePanel+ title=".env"+ language="env"+ bind:value={$inputs.envContent.value}+ error={$inputs.envContent.error ?? undefined}+ readOnly={saving}+ bind:hasErrors={validation.envHasErrors}+ bind:validationReady={validation.envValidationReady}+ fileId="{fileIdPrefix}:env"+ originalValue={originalEnv}+ {enableDiff}+ editorContext={{+ envContent: $inputs.envContent.value,+ composeContents: [$inputs.composeContent.value],+ globalVariables: globalVariableMap+ }}+ />+ {/snippet}+ </ComposeEditorSplit>+ </form>+ </div>+ </div>+</div>diff --git a/frontend/src/routes/(app)/customize/templates/components/template-gallery.svelte b/frontend/src/routes/(app)/customize/templates/components/template-gallery.sveltenew file mode 100644index 000000000..d340b1234--- /dev/null+++ b/frontend/src/routes/(app)/customize/templates/components/template-gallery.svelte@@ -0,0 +1,213 @@+<script lang="ts">+ import { Input } from '$lib/components/ui/input/index.js';+ import * as Select from '$lib/components/ui/select/index.js';+ import ArcaneTablePagination from '$lib/components/arcane-table/arcane-table-pagination.svelte';+ import EmptyState from '$lib/components/states/empty-state.svelte';+ import TemplateCard from './template-card.svelte';+ import { toast } from 'svelte-sonner';+ import { openConfirmDialog } from '$lib/components/confirm-dialog';+ import { handleApiResultWithCallbacks, tryCatch } from '$lib/utils/api';+ import { templateService } from '$lib/services/template-service';+ import { templateTypeFilters } from '$lib/components/arcane-table/data';+ import { debounced } from '$lib/utils/ws';+ import { hasPermission } from '$lib/utils/auth';+ import { m } from '$lib/paraglide/messages';+ import { PersistedState } from 'runed';+ import { onMount, untrack } from 'svelte';+ import type { CompactTablePrefs } from '$lib/components/arcane-table/arcane-table.types.svelte';+ import type { Paginated, SearchPaginationSortRequest } from '$lib/types/shared';+ import type { Template } from '$lib/types/swarm';+ import { SearchIcon, TemplateIcon } from '$lib/icons';++ let {+ templates = $bindable(),+ requestOptions = $bindable()+ }: {+ templates: Paginated<Template>;+ requestOptions: SearchPaginationSortRequest;+ } = $props();++ let deletingId = $state<string | null>(null);+ let downloadingId = $state<string | null>(null);+ let searchValue = $state(untrack(() => requestOptions.search ?? ''));+ let typeFilter = $state(untrack(() => (requestOptions.filters?.['type'] as string) ?? 'all'));++ let prefs = $state<PersistedState<CompactTablePrefs> | null>(null);++ const currentPage = $derived(templates.pagination?.currentPage ?? requestOptions.pagination?.page ?? 1);+ const totalPages = $derived(templates.pagination?.totalPages ?? 1);+ const totalItems = $derived(templates.pagination?.totalItems ?? 0);+ const pageSize = $derived(requestOptions.pagination?.limit ?? templates.pagination?.itemsPerPage ?? 20);+ const hasActiveQuery = $derived(!!requestOptions.search || requestOptions.filters?.['type'] !== undefined);+ const canCreateTemplate = $derived(hasPermission('templates:create'));++ const typeFilterLabel = $derived(templateTypeFilters.find((f) => f.value === typeFilter)?.label ?? m.common_all());++ onMount(() => {+ prefs = new PersistedState<CompactTablePrefs>(+ 'arcane-template-gallery',+ { v: [], f: [], g: '', l: pageSize },+ { syncTabs: false }+ );+ });++ async function refetch() {+ templates = await templateService.getTemplates(requestOptions);+ }++ function applySearch(value: string) {+ const search = value.trim();+ requestOptions = {+ ...requestOptions,+ search: search || undefined,+ pagination: { page: 1, limit: pageSize }+ };+ if (prefs) prefs.current = { ...prefs.current, g: search };+ refetch();+ }++ const debouncedSearch = debounced(applySearch, 300);++ function applyTypeFilter(value: string) {+ typeFilter = value;+ const filters = { ...requestOptions.filters };+ if (value === 'all') {+ delete filters['type'];+ } else {+ filters['type'] = value;+ }+ requestOptions = {+ ...requestOptions,+ filters,+ pagination: { page: 1, limit: pageSize }+ };+ if (prefs) prefs.current = { ...prefs.current, f: value === 'all' ? [] : [['type', value]] };+ refetch();+ }++ function setPage(page: number) {+ if (page < 1) page = 1;+ if (totalPages > 0 && page > totalPages) page = totalPages;+ requestOptions = { ...requestOptions, pagination: { page, limit: pageSize } };+ refetch();+ }++ function setPageSize(limit: number) {+ if (prefs) prefs.current = { ...prefs.current, l: limit };+ requestOptions = { ...requestOptions, pagination: { page: 1, limit } };+ refetch();+ }++ async function handleDeleteTemplate(template: Template) {+ openConfirmDialog({+ title: m.common_delete_title({ resource: m.resource_template() }),+ message: m.common_delete_confirm({ resource: `${m.resource_template()} "${template.name}"` }),+ confirm: {+ label: m.templates_delete_template(),+ destructive: true,+ action: async () => {+ deletingId = template.id;++ const result = await tryCatch(templateService.deleteTemplate(template.id));+ handleApiResultWithCallbacks({+ result,+ message: m.common_delete_failed({ resource: `${m.resource_template()} "${template.name}"` }),+ setLoadingState: (value) => (value ? null : (deletingId = null)),+ onSuccess: async () => {+ toast.success(m.common_delete_success({ resource: `${m.resource_template()} "${template.name}"` }));+ await refetch();+ deletingId = null;+ }+ });+ }+ }+ });+ }++ async function handleDownloadTemplate(template: Template) {+ downloadingId = template.id;++ const result = await tryCatch(templateService.download(template.id));+ handleApiResultWithCallbacks({+ result,+ message: m.templates_download_failed(),+ setLoadingState: (value) => (value ? null : (downloadingId = null)),+ onSuccess: async () => {+ toast.success(m.templates_downloaded_success({ name: template.name }));+ await refetch();+ downloadingId = null;+ }+ });+ }+</script>++<div class="space-y-4">+ <div class="flex flex-wrap items-center gap-2">+ <div class="relative min-w-0 flex-1 md:w-64 md:flex-none">+ <SearchIcon class="pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />+ <Input+ placeholder={m.templates_search_placeholder()}+ bind:value={searchValue}+ oninput={(e) => debouncedSearch(e.currentTarget.value)}+ onchange={(e) => applySearch(e.currentTarget.value)}+ onkeydown={(e) => {+ if (e.key === 'Enter') applySearch((e.currentTarget as HTMLInputElement).value);+ }}+ class="h-9 w-full pl-8"+ />+ </div>++ <Select.Root allowDeselect={false} type="single" value={typeFilter} onValueChange={applyTypeFilter}>+ <Select.Trigger class="h-9 w-[140px]">+ {typeFilterLabel}+ </Select.Trigger>+ <Select.Content>+ <Select.Item value="all">{m.common_all()}</Select.Item>+ {#each templateTypeFilters as option (String(option.value))}+ <Select.Item value={String(option.value)}>{option.label}</Select.Item>+ {/each}+ </Select.Content>+ </Select.Root>+ </div>++ {#if templates.data.length > 0}+ <div class="grid grid-cols-1 gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">+ {#each templates.data as template (template.id)}+ <TemplateCard+ {template}+ downloading={downloadingId === template.id}+ deleting={deletingId === template.id}+ onDownload={handleDownloadTemplate}+ onDelete={handleDeleteTemplate}+ />+ {/each}+ </div>++ <ArcaneTablePagination+ items={templates}+ {currentPage}+ {totalPages}+ {totalItems}+ {pageSize}+ canPrev={currentPage > 1}+ canNext={currentPage < totalPages}+ {setPage}+ {setPageSize}+ />+ {:else if hasActiveQuery}+ <EmptyState+ icon={SearchIcon}+ title={m.common_no_results_found()}+ description={m.common_no_results_hint()}+ class="rounded-xl border border-border/50 py-12"+ />+ {:else}+ <EmptyState+ icon={TemplateIcon}+ title={m.templates_no_templates()}+ actionLabel={canCreateTemplate ? m.templates_create_template() : undefined}+ actionHref={canCreateTemplate ? '/customize/templates/create' : undefined}+ class="rounded-xl border border-border/50 py-12"+ />+ {/if}+</div>diff --git a/frontend/src/routes/(app)/customize/templates/create/+page.svelte b/frontend/src/routes/(app)/customize/templates/create/+page.svelteindex 2e0ea6837..12571f7b6 100644--- a/frontend/src/routes/(app)/customize/templates/create/+page.svelte+++ b/frontend/src/routes/(app)/customize/templates/create/+page.svelte@@ -1,17 +1,13 @@<script lang="ts">import { goto } from '$app/navigation';import { ArcaneButton } from '$lib/components/arcane-button/index.js';- import FormInput from '$lib/components/form/form-input.svelte';- import { ArrowLeftIcon } from '$lib/icons';import { m } from '$lib/paraglide/messages';import { templateService } from '$lib/services/template-service';import { handleApiResultWithCallbacks } from '$lib/utils/api';- import { createForm, preventDefault } from '$lib/utils/settings';+ import { createForm } from '$lib/utils/settings';import { tryCatch } from '$lib/utils/api';import { toast } from 'svelte-sonner';- import CodePanel from '../../../projects/components/CodePanel.svelte';- import EditableName from '../../../projects/components/EditableName.svelte';- import { ComposeEditorSplit } from '$lib/components/compose';+ import TemplateEditorWorkspace from '../components/template-editor-workspace.svelte';import { globalVariablesToMap } from '$lib/utils/template-load';import {createNamedTemplateSchema,@@ -23,11 +19,12 @@let { data } = $props();let saving = $state(false);- let composeHasErrors = $state(false);- let envHasErrors = $state(false);- let composeValidationReady = $state(false);- let envValidationReady = $state(false);- let nameInputRef = $state<HTMLInputElement | null>(null);+ let validation = $state({+ composeHasErrors: false,+ envHasErrors: false,+ composeValidationReady: false,+ envValidationReady: false+ });const globalVariableMap = $derived(globalVariablesToMap(data.globalVariables));@@ -44,14 +41,24 @@const hasEditorErrors = $derived(hasTemplateEditorErrors(- getTemplateEditorValidationState(composeValidationReady, envValidationReady, composeHasErrors, envHasErrors)+ getTemplateEditorValidationState(+ validation.composeValidationReady,+ validation.envValidationReady,+ validation.composeHasErrors,+ validation.envHasErrors+ )));const canCreate = $derived(!!$inputs.name.value && !!$inputs.composeContent.value && !hasEditorErrors && !saving);async function handleCreate() {const validated = validateTemplateEditorForm(- getTemplateEditorValidationState(composeValidationReady, envValidationReady, composeHasErrors, envHasErrors),+ getTemplateEditorValidationState(+ validation.composeValidationReady,+ validation.envValidationReady,+ validation.composeHasErrors,+ validation.envHasErrors+ ),form.validate);if (!validated) return;@@ -75,114 +82,23 @@}</script>-<div class="flex h-full min-h-0 flex-col bg-background">- <div- class="sticky top-0 z-[var(--arcane-z-sticky)] mb-2 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80"- >- <div class="mx-auto flex h-16 max-w-full items-center justify-between gap-4 px-6">- <div class="flex min-w-0 items-center gap-4">- <ArcaneButton- action="base"- tone="ghost"- size="sm"- class="gap-2 bg-transparent"- icon={ArrowLeftIcon}- customLabel={m.common_back()}- onclick={() => goto('/customize/templates')}- />- <div class="hidden h-4 w-px bg-border sm:block"></div>- <div class="hidden min-w-0 items-center gap-3 sm:flex">- <EditableName- bind:value={$inputs.name.value}- bind:ref={nameInputRef}- variant="inline"- error={$inputs.name.error ?? undefined}- originalValue=""- placeholder={m.templates_template_name_placeholder()}- canEdit={!saving}- class="hidden sm:block"- />- </div>- </div>-- <div class="flex items-center gap-2">- <ArcaneButton action="cancel" onclick={() => goto('/customize/templates')} disabled={saving} />- <ArcaneButton- action="create"- customLabel={m.templates_create_template()}- onclick={handleCreate}- disabled={!canCreate}- loading={saving}- loadingLabel={m.common_action_creating()}- />- </div>- </div>- </div>-- <div class="flex min-h-0 flex-1 overflow-hidden">- <div class="mx-auto flex h-full w-full max-w-full min-w-0 flex-col px-2 pb-6 sm:px-6 sm:pb-6">- <form class="flex min-h-0 flex-1 flex-col gap-4" onsubmit={preventDefault(handleCreate)}>- <div class="block flex-shrink-0 py-4 sm:hidden">- <EditableName- bind:value={$inputs.name.value}- bind:ref={nameInputRef}- variant="block"- error={$inputs.name.error ?? undefined}- originalValue=""- placeholder={m.templates_template_name_placeholder()}- canEdit={!saving}- />- </div>-- <div class="flex-shrink-0 px-1 pt-1">- <div class="max-w-2xl">- <FormInput- input={$inputs.description}- label={m.templates_template_description_label()}- placeholder={m.templates_template_description_placeholder()}- disabled={saving}- />- </div>- </div>-- <ComposeEditorSplit>- {#snippet compose()}- <CodePanel- title="compose.yaml"- language="yaml"- bind:value={$inputs.composeContent.value}- error={$inputs.composeContent.error ?? undefined}- readOnly={saving}- bind:hasErrors={composeHasErrors}- bind:validationReady={composeValidationReady}- fileId="templates:create:compose"- editorContext={{- envContent: $inputs.envContent.value,- composeContents: [$inputs.composeContent.value],- globalVariables: globalVariableMap- }}- />- {/snippet}-- {#snippet env()}- <CodePanel- title=".env"- language="env"- bind:value={$inputs.envContent.value}- error={$inputs.envContent.error ?? undefined}- readOnly={saving}- bind:hasErrors={envHasErrors}- bind:validationReady={envValidationReady}- fileId="templates:create:env"- editorContext={{- envContent: $inputs.envContent.value,- composeContents: [$inputs.composeContent.value],- globalVariables: globalVariableMap- }}- />- {/snippet}- </ComposeEditorSplit>- </form>- </div>- </div>-</div>+<TemplateEditorWorkspace+ {inputs}+ bind:validation+ fileIdPrefix="templates:create"+ {globalVariableMap}+ {saving}+ onSubmit={handleCreate}+>+ {#snippet toolbarActions()}+ <ArcaneButton action="cancel" onclick={() => goto('/customize/templates')} disabled={saving} />+ <ArcaneButton+ action="create"+ customLabel={m.templates_create_template()}+ onclick={handleCreate}+ disabled={!canCreate}+ loading={saving}+ loadingLabel={m.common_action_creating()}+ />+ {/snippet}+</TemplateEditorWorkspace>diff --git a/frontend/src/routes/(app)/customize/templates/template-table.svelte b/frontend/src/routes/(app)/customize/templates/template-table.sveltedeleted file mode 100644index 91265ed5b..000000000--- a/frontend/src/routes/(app)/customize/templates/template-table.svelte+++ /dev/null@@ -1,345 +0,0 @@-<script lang="ts">- import ArcaneTable from '$lib/components/arcane-table/arcane-table.svelte';- import { Badge } from '$lib/components/ui/badge';- import { Spinner } from '$lib/components/ui/spinner/index.js';- import * as DropdownMenu from '$lib/components/ui/dropdown-menu/index.js';- import RowActionsMenu from '$lib/components/arcane-table/row-actions-menu.svelte';- import { goto } from '$app/navigation';- import { toast } from 'svelte-sonner';- import { openConfirmDialog } from '$lib/components/confirm-dialog';- import { handleApiResultWithCallbacks } from '$lib/utils/api';- import { tryCatch } from '$lib/utils/api';- import UniversalMobileCard from '$lib/components/arcane-table/cards/universal-mobile-card.svelte';- import type { Paginated, SearchPaginationSortRequest } from '$lib/types/shared';- import type { Template } from '$lib/types/swarm';- import type { ColumnSpec, MobileFieldVisibility } from '$lib/components/arcane-table';- import { m } from '$lib/paraglide/messages';- import { templateTypeFilters } from '$lib/components/arcane-table/data';- import { templateService } from '$lib/services/template-service';- import { truncateString } from '$lib/utils/formatting';- import { hasPermission } from '$lib/utils/auth';- import IfPermitted from '$lib/components/if-permitted.svelte';- import { PersistedState } from 'runed';- import { onMount } from 'svelte';- import IconImage from '$lib/components/icon-image.svelte';- import {- InspectIcon,- FolderOpenIcon,- GlobeIcon,- TrashIcon,- DownloadIcon,- TagIcon,- MoveToFolderIcon,- RegistryIcon- } from '$lib/icons';-- let {- templates = $bindable(),- selectedIds = $bindable(),- requestOptions = $bindable()- }: {- templates: Paginated<Template>;- selectedIds: string[];- requestOptions: SearchPaginationSortRequest;- } = $props();-- let deletingId = $state<string | null>(null);- let downloadingId = $state<string | null>(null);-- const canReadTemplate = $derived(hasPermission('templates:read'));- const canDeleteTemplate = $derived(hasPermission('templates:delete'));-- async function handleDeleteTemplate(id: string, name: string) {- openConfirmDialog({- title: m.common_delete_title({ resource: m.resource_template() }),- message: m.common_delete_confirm({ resource: `${m.resource_template()} "${name}"` }),- confirm: {- label: m.templates_delete_template(),- destructive: true,- action: async () => {- deletingId = id;-- const result = await tryCatch(templateService.deleteTemplate(id));- handleApiResultWithCallbacks({- result,- message: m.common_delete_failed({ resource: `${m.resource_template()} "${name}"` }),- setLoadingState: (value) => (value ? null : (deletingId = null)),- onSuccess: async () => {- toast.success(m.common_delete_success({ resource: `${m.resource_template()} "${name}"` }));- templates = await templateService.getTemplates(requestOptions);- deletingId = null;- }- });- }- }- });- }-- async function handleDownloadTemplate(id: string, name: string) {- downloadingId = id;-- const result = await tryCatch(templateService.download(id));- handleApiResultWithCallbacks({- result,- message: m.templates_download_failed(),- setLoadingState: (value) => (value ? null : (downloadingId = null)),- onSuccess: async () => {- toast.success(m.templates_downloaded_success({ name }));- templates = await templateService.getTemplates(requestOptions);- downloadingId = null;- }- });- }-- const columns = [- {- accessorKey: 'name',- title: m.common_name(),- sortable: true,- cell: NameCell- },- {- accessorKey: 'description',- title: m.common_description(),- cell: DescriptionCell- },- {- id: 'type',- accessorFn: (row) => row.isRemote,- title: m.common_type(),- sortable: true,- filterOptions: templateTypeFilters,- cell: TypeCell- },- {- accessorKey: 'metadata',- title: m.common_tags(),- cell: TagsCell- }- ] satisfies ColumnSpec<Template>[];-- const mobileFields = [- { id: 'description', label: m.common_description(), defaultVisible: true },- { id: 'type', label: m.common_type(), defaultVisible: true },- { id: 'tags', label: m.common_tags(), defaultVisible: true }- ];-- let mobileFieldVisibility = $state<Record<string, boolean>>({});- let customSettings = $state<Record<string, unknown>>({});- let collapsedGroupsState = $state<PersistedState<Record<string, boolean>> | null>(null);- let collapsedGroups = $derived(collapsedGroupsState?.current ?? {});-- onMount(() => {- collapsedGroupsState = new PersistedState<Record<string, boolean>>('template-groups-collapsed', {});- });-- let groupByRegistry = $derived((customSettings['groupByRegistry'] as boolean) ?? false);-- function toggleGroup(groupName: string) {- if (!collapsedGroupsState) return;- collapsedGroupsState.current = {- ...collapsedGroupsState.current,- // Groups with no recorded state render collapsed, so toggle from that default- [groupName]: !(collapsedGroupsState.current[groupName] ?? true)- };- }-- function getRegistryName(template: Template): string {- if (template.registry?.name) {- return template.registry.name;- }- if (template.isRemote) {- return m.templates_unknown_registry();- }- return m.templates_local_templates();- }-- // Group by function for templates- function groupTemplateByRegistry(template: Template): string {- return getRegistryName(template);- }-- // Icon for each group- function getGroupIcon(groupName: string) {- if (groupName === m.templates_local_templates()) {- return FolderOpenIcon;- }- return RegistryIcon;- }-</script>--{#snippet NameCell({ item }: { item: Template })}- <div class="flex items-center gap-2">- <IconImage- src={item.metadata?.iconUrl}- alt={item.name}- fallback={item.isRemote ? GlobeIcon : FolderOpenIcon}- class="size-6"- containerClass="size-8"- />- <a class="font-medium hover:underline" href="/customize/templates/{item.id}">- {item.name}- </a>- </div>-{/snippet}--{#snippet DescriptionCell({ item }: { item: Template })}- <span class="line-clamp-2 text-sm text-muted-foreground">- {truncateString(item.description, 80)}- </span>-{/snippet}--{#snippet TypeCell({ item }: { item: Template })}- {#if item.isRemote}- <Badge variant="secondary" class="gap-1">- <GlobeIcon class="size-3" />- {m.templates_remote()}- </Badge>- {:else}- <Badge variant="secondary" class="gap-1">- <FolderOpenIcon class="size-3" />- {m.templates_local()}- </Badge>- {/if}-{/snippet}--{#snippet TagsCell({ item }: { item: Template })}- {#if item.metadata?.tags && item.metadata.tags.length > 0}- <div class="flex flex-wrap gap-1">- {#each item.metadata.tags.slice(0, 2) as tag (tag)}- <Badge variant="outline" class="text-xs">{tag}</Badge>- {/each}- {#if item.metadata.tags.length > 2}- <Badge variant="outline" class="text-xs">+{item.metadata.tags.length - 2}</Badge>- {/if}- </div>- {/if}-{/snippet}--{#snippet TemplateMobileCardSnippet({- item,- mobileFieldVisibility-}: {- item: Template;- mobileFieldVisibility: MobileFieldVisibility;-})}- <UniversalMobileCard- {item}- icon={(item) => ({- component: item.isRemote ? GlobeIcon : FolderOpenIcon,- variant: item.isRemote ? 'emerald' : 'blue',- imageUrl: item.metadata?.iconUrl,- alt: item.name- })}- title={(item) => item.name}- subtitle={(item) => ((mobileFieldVisibility['description'] ?? true) ? item.description : null)}- badges={[- (item) =>- (mobileFieldVisibility['type'] ?? true)- ? {- variant: item.isRemote ? 'green' : 'blue',- text: item.isRemote ? m.templates_remote() : m.templates_local()- }- : null- ]}- fields={[]}- rowActions={RowActions}- onclick={(item: Template) => goto(`/customize/templates/${item.id}`)}- >- {#snippet children()}- {#if (mobileFieldVisibility['tags'] ?? true) && item.metadata?.tags && item.metadata.tags.length > 0}- <div class="flex items-start gap-2.5 border-t pt-3">- <div class="flex size-7 shrink-0 items-center justify-center rounded-lg bg-purple-500/10">- <TagIcon class="size-3.5 text-purple-500" />- </div>- <div class="min-w-0 flex-1">- <div class="text-[10px] font-medium tracking-wide text-muted-foreground uppercase">- {m.common_tags()}- </div>- <div class="mt-1 flex flex-wrap gap-1">- {#each item.metadata.tags.slice(0, 3) as tag (tag)}- <Badge variant="outline" class="text-xs">{tag}</Badge>- {/each}- {#if item.metadata.tags.length > 3}- <Badge variant="outline" class="text-xs">+{item.metadata.tags.length - 3}</Badge>- {/if}- </div>- </div>- </div>- {/if}- {/snippet}- </UniversalMobileCard>-{/snippet}--{#snippet RowActions({ item }: { item: Template })}- <RowActionsMenu>- <DropdownMenu.Item onclick={() => goto(`/customize/templates/${item.id}`)}>- <InspectIcon class="size-4" />- {m.common_view_details()}- </DropdownMenu.Item>-- <IfPermitted perm="projects:create">- <DropdownMenu.Item onclick={() => goto(`/projects/new?templateId=${item.id}`)}>- <MoveToFolderIcon class="size-4" />- {m.compose_create_project()}- </DropdownMenu.Item>- </IfPermitted>-- {#if (item.isRemote && canReadTemplate) || (!item.isRemote && canDeleteTemplate)}- <DropdownMenu.Separator />- {/if}-- {#if item.isRemote && canReadTemplate}- <DropdownMenu.Item onclick={() => handleDownloadTemplate(item.id, item.name)} disabled={downloadingId === item.id}>- {#if downloadingId === item.id}- <Spinner class="size-4" />- {:else}- <DownloadIcon class="size-4" />- {/if}- {m.templates_download()}- </DropdownMenu.Item>- {:else if !item.isRemote && canDeleteTemplate}- <DropdownMenu.Item- variant="destructive"- onclick={() => handleDeleteTemplate(item.id, item.name)}- disabled={deletingId === item.id}- >- {#if deletingId === item.id}- <Spinner class="size-4" />- {:else}- <TrashIcon class="size-4" />- {/if}- {m.templates_delete_template()}- </DropdownMenu.Item>- {/if}- </RowActionsMenu>-{/snippet}--<ArcaneTable- persistKey="arcane-template-table"- items={templates}- bind:requestOptions- bind:selectedIds- bind:mobileFieldVisibility- bind:customSettings- onRefresh={async (options) => (templates = await templateService.getTemplates(options))}- {columns}- {mobileFields}- rowActions={RowActions}- mobileCard={TemplateMobileCardSnippet}- selectionDisabled- customViewOptions={CustomViewOptions}- groupBy={groupByRegistry ? groupTemplateByRegistry : undefined}- groupIcon={groupByRegistry ? getGroupIcon : undefined}- groupCollapsedState={collapsedGroups}- onGroupToggle={toggleGroup}-/>--{#snippet CustomViewOptions()}- <DropdownMenu.CheckboxItem- checked={groupByRegistry}- onCheckedChange={(v) => (customSettings = { ...customSettings, groupByRegistry: !!v })}- >- {m.templates_group_by_registry()}- </DropdownMenu.CheckboxItem>-{/snippet}