Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
chore: cleanup logic
Kyle Mendell017d41aedb09
diff --git a/frontend/src/lib/components/arcane-button/arcane-button.svelte b/frontend/src/lib/components/arcane-button/arcane-button.svelteindex 8cf360361..20e6786f3 100644--- a/frontend/src/lib/components/arcane-button/arcane-button.svelte+++ b/frontend/src/lib/components/arcane-button/arcane-button.svelte@@ -3,6 +3,7 @@import type { HTMLAnchorAttributes, HTMLButtonAttributes } from 'svelte/elements';import type { IconType } from '#lib/icons/index.js';+ import type { ShortcutKey } from '#lib/utils/navigation.js';import type { ArcaneButtonSize, Action, ArcaneButtonHoverEffect, ActionConfig, ArcaneButtonTone } from './variants';@@ -17,6 +18,7 @@customLabel?: string;loadingLabel?: string;icon?: IconType | null;+ shortcut?: ShortcutKey[];onClickPromise?: (e: MouseEvent & {currentTarget: EventTarget & HTMLButtonElement;@@ -42,9 +44,14 @@</script><script lang="ts">+ import type { Attachment } from 'svelte/attachments';+ import { on } from 'svelte/events';+import { Spinner } from '#lib/components/ui/spinner/index.js';import { m } from '#lib/paraglide/messages.js';+ import userStore from '#lib/stores/user-store.svelte.js';import { cn } from '#lib/utils.js';+ import { matchesShortcutEvent } from '#lib/utils/navigation.js';import { arcaneButtonVariants, actionConfigs } from './variants';@@ -64,6 +71,7 @@customLabel = undefined,loadingLabel = undefined,icon = undefined,+ shortcut = undefined,tabindex = 0,onclick,onClickPromise,@@ -80,6 +88,17 @@let isIconOnlyButton = $derived(size === 'icon' || !showLabel);let IconComponent = $derived(icon === null ? null : (icon ?? config.IconComponent));++ // The shortcut clicks the button, so disabled and loading block it and hidden buttons (inactive tabs) ignore it.+ function clickOnShortcut(keys: ShortcutKey[]): Attachment<HTMLElement> {+ return (node) =>+ on(window, 'keydown', (event) => {+ if (event.defaultPrevented || userStore.current?.preferences?.keyboardShortcutsEnabled === false) return;+ if (!matchesShortcutEvent(keys, event) || !node.checkVisibility()) return;+ event.preventDefault();+ node.click();+ });+ }</script><svelte:element@@ -96,6 +115,7 @@class={cn('relative', arcaneButtonVariants({ tone: tone ?? config.tone, size, hoverEffect }), className)}aria-label={ariaLabel ?? (children ? undefined : isIconOnlyButton ? displayLabel : undefined)}bind:this={ref}+ {@attach shortcut && clickOnShortcut(shortcut)}onclick={async (e: any) => {onclick?.(e);if (type === undefined) return;diff --git a/frontend/src/lib/components/compose-create-menu.svelte b/frontend/src/lib/components/compose-create-menu.svelteindex d80a881d4..cddefafbf 100644--- a/frontend/src/lib/components/compose-create-menu.svelte+++ b/frontend/src/lib/components/compose-create-menu.svelte@@ -18,6 +18,7 @@import { Spinner } from '#lib/components/ui/spinner/index.js';import { TerminalIcon, TemplateIcon, AddIcon, ArrowDownIcon as ChevronDown, GitBranchIcon } from '#lib/icons/index.js';import { templateBtnClass } from '#lib/utils/compose-flow.js';+ import type { ShortcutKey } from '#lib/utils/navigation.js';interface Props {// Tooltip shows when the tooltipOpen prop is truthy-undefined (bits-ui@@ -35,6 +36,7 @@createLoading: boolean;createLabel: string;createLoadingLabel: string;+ createShortcut?: ShortcutKey[];onCreate: () => void;// Dropdown items.@@ -70,6 +72,7 @@createLoading,createLabel,createLoadingLabel,+ createShortcut,onCreate,itemsDisabled,showUseTemplate = true,@@ -113,6 +116,7 @@loading={createLoading}customLabel={createLabel}loadingLabel={createLoadingLabel}+ shortcut={createShortcut}/>{/snippet}</ArcaneTooltip.Trigger>diff --git a/frontend/src/lib/components/editor-tab-strip.svelte b/frontend/src/lib/components/editor-tab-strip.svelteindex d933f35d0..4cc0c6ed0 100644--- a/frontend/src/lib/components/editor-tab-strip.svelte+++ b/frontend/src/lib/components/editor-tab-strip.svelte@@ -23,7 +23,7 @@let { tabs, activeKey, onSelect, onClose, actions }: Props = $props();- // Middle-click closes like browser and IDE tabs; preventing mousedown stops Windows auto-scroll.+ // Middle-click anywhere on a tab closes it like browser and IDE tabs; preventing mousedown stops Windows auto-scroll.function preventMiddleMouseDown(event: MouseEvent) {if (event.button === 1) event.preventDefault();}@@ -39,6 +39,7 @@<div class="scrollbar-hide flex h-full min-w-0 flex-1 items-center overflow-x-auto">{#each tabs as tab (tab.key)}{@const isActive = activeKey === tab.key}+ <!-- svelte-ignore a11y_no_static_element_interactions --><divclass={cn('group relative flex h-full shrink-0 items-center border-r border-border',@@ -46,6 +47,8 @@)}data-tab-key={tab.key}data-active={isActive}+ onmousedown={preventMiddleMouseDown}+ onauxclick={(event) => closeOnMiddleClick(event, tab.key)}>{#if isActive}<span class="absolute inset-x-0 top-0 h-0.5 bg-primary"></span>@@ -58,8 +61,6 @@)}title={tab.title}onclick={() => onSelect(tab.key)}- onmousedown={preventMiddleMouseDown}- onauxclick={(event) => closeOnMiddleClick(event, tab.key)}><FileTextIcon class={cn('size-3.5 shrink-0', tab.iconClass)} /><span class="max-w-40 truncate">{tab.label}</span>@@ -80,8 +81,6 @@)}aria-label={m.common_close()}onclick={() => onClose(tab.key)}- onmousedown={preventMiddleMouseDown}- onauxclick={(event) => closeOnMiddleClick(event, tab.key)}><CloseIcon class="size-3" /></button>diff --git a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte b/frontend/src/routes/(app)/projects/[projectId]/+page.svelteindex c69409688..2aa696239 100644--- a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte+++ b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte@@ -72,7 +72,7 @@import { getStatusVariant, getThemedIconUrl } from '#lib/utils/docker.js';import { capitalizeFirstLetter } from '#lib/utils/formatting.js';import { gitOpsComposeEditUrl, gitOpsFileEditUrl, gitOpsProjectUrl } from '#lib/utils/gitops.js';- import { matchesShortcutEvent, toGitRouteUrl, toSafeHref } from '#lib/utils/navigation.js';+ import { toGitRouteUrl, toSafeHref } from '#lib/utils/navigation.js';import { createForm } from '#lib/utils/settings.svelte.js';import { globalVariablesToMap } from '#lib/utils/template-load.js';import { tryCatch } from '#lib/utils/try-catch.js';@@ -814,13 +814,6 @@}}- // Always swallow Ctrl/Cmd+S here so the browser's "save page" dialog never opens.- function handleSaveShortcut(event: KeyboardEvent) {- if (!matchesShortcutEvent(['mod', 's'], event)) return;- event.preventDefault();- if (canSave && !isLoading.saving) handleSaveChanges();- }-function saveNameIfChanged() {if (project?.isArchived) return;if (effectiveName === serverName) return;@@ -1478,8 +1471,6 @@});</script>-<svelte:window onkeydown={handleSaveShortcut} />-{#snippet projectComposeTab(project: Project)}<Tabs.Content value="compose" class="h-full min-h-0"><div class="flex h-full min-h-0 flex-col">@@ -1541,6 +1532,7 @@disabled={!canSave}loading={isLoading.saving}loadingLabel={m.common_saving()}+ shortcut={['mod', 's']}onclick={handleSaveChanges}/></div>diff --git a/frontend/src/routes/(app)/projects/new/+page.svelte b/frontend/src/routes/(app)/projects/new/+page.svelteindex b5663ebb3..564cd223e 100644--- a/frontend/src/routes/(app)/projects/new/+page.svelte+++ b/frontend/src/routes/(app)/projects/new/+page.svelte@@ -40,7 +40,6 @@templateNameSlug,type ProjectEditorLayoutMode} from '#lib/utils/compose-flow.js';- import { matchesShortcutEvent } from '#lib/utils/navigation.js';import { preventDefault, createForm } from '#lib/utils/settings.svelte.js';import {getTemplateEditorValidationState,@@ -180,14 +179,6 @@// effective name without writing to form state reactively.const effectiveName = $derived(composeYamlName ?? inputs.name.value);const createMenuBusy = $derived(ui.saving || ui.converting || ui.isLoadingTemplateContent);- const createDisabled = $derived(!effectiveName || !inputs.composeContent.value || hasEditorErrors || createMenuBusy);-- // Always swallow Ctrl/Cmd+S here so the browser's "save page" dialog never opens.- function handleCreateShortcut(event: KeyboardEvent) {- if (!matchesShortcutEvent(['mod', 's'], event)) return;- event.preventDefault();- if (canCreateProject && !createDisabled) handleSubmit();- }async function handleSubmit() {if (sourceContainerIds.length > 0 && canDeleteContainers) {@@ -270,8 +261,6 @@}</script>-<svelte:window onkeydown={handleCreateShortcut} />-{#snippet newProjectWorkspaceEditor()}{#key activeProjectTab}{#if activeProjectTab === 'compose'}@@ -370,10 +359,11 @@tooltipDescription={m.compose_project_name_tooltip_description()}tooltipExample={m.compose_project_name_tooltip_example()}showCreateButton={!hasEditorErrors && canCreateProject}- {createDisabled}+ createDisabled={!effectiveName || !inputs.composeContent.value || hasEditorErrors || createMenuBusy}createLoading={ui.saving}createLabel={m.compose_create_project()}createLoadingLabel={m.common_action_creating()}+ createShortcut={['mod', 's']}onCreate={() => handleSubmit()}itemsDisabled={createMenuBusy}showUseTemplate={canUseTemplates}