diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f62cdf11..48414ee2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,6 +70,8 @@ jobs: run: bun install --frozen-lockfile - name: Run build with lint run: bun run build-with-lint + - name: Svelte check + run: bun run check dependency-review: name: Dependency Review diff --git a/package.json b/package.json index 08d6631b..1941240a 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "lint": "eslint .", "build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production", "build-with-lint": "tsc -noEmit -skipLibCheck && bun lint && node esbuild.config.mjs production", + "check": "svelte-check --threshold error", "test": "vitest run --config vitest.config.mts --passWithNoTests", "test:e2e": "vitest run --config vitest.e2e.config.mts" }, diff --git a/src/gui/GlobalVariables/GlobalVariablesView.svelte b/src/gui/GlobalVariables/GlobalVariablesView.svelte index b9c01bc8..9a43f5f3 100644 --- a/src/gui/GlobalVariables/GlobalVariablesView.svelte +++ b/src/gui/GlobalVariables/GlobalVariablesView.svelte @@ -39,7 +39,7 @@ function addVariable() { const names = new Set(items.map((i) => i.name)); const name = uniqueName("NewVar", names); - items = [...items, { id: name, name, value: "" }]; + items = [...items, { name, value: "" }]; persistToSettings(); } diff --git a/src/gui/MacroGUIs/CommandList.svelte b/src/gui/MacroGUIs/CommandList.svelte index 91fd0129..cbbdc6c5 100644 --- a/src/gui/MacroGUIs/CommandList.svelte +++ b/src/gui/MacroGUIs/CommandList.svelte @@ -31,6 +31,8 @@ import { createEventDispatcher } from "svelte"; import { OpenFileCommandSettingsModal } from "./OpenFileCommandSettingsModal"; import ConditionalCommand from "./Components/ConditionalCommand.svelte"; import type { IConditionalCommand } from "../../types/macros/Conditional/IConditionalCommand"; +import type { IWaitCommand } from "../../types/macros/QuickCommands/IWaitCommand"; +import type { INestedChoiceCommand } from "../../types/macros/QuickCommands/INestedChoiceCommand"; export let commands: ICommand[]; export let deleteCommand: (commandId: string) => Promise; @@ -40,6 +42,16 @@ export let plugin: QuickAdd; let dragDisabled: boolean = true; const dispatch = createEventDispatcher(); +// Narrowing helpers: the {#each} discriminates on command.type, so each child +// receives the matching subtype. Passed one-way — children report edits via the +// on:updateCommand event, not via two-way bind:command. +const asWait = (c: ICommand) => c as IWaitCommand; +const asNested = (c: ICommand) => c as INestedChoiceCommand; +const asUserScript = (c: ICommand) => c as IUserScript; +const asAI = (c: ICommand) => c as IAIAssistantCommand; +const asOpenFile = (c: ICommand) => c as IOpenFileCommand; +const asConditional = (c: ICommand) => c as IConditionalCommand; + export const updateCommandList: (newCommands: ICommand[]) => void = ( newCommands: ICommand[] ) => { @@ -66,7 +78,7 @@ const dispatch = createEventDispatcher(); saveCommands(commands); } - let startDrag = (e: CustomEvent) => { + let startDrag = (e: MouseEvent | TouchEvent) => { e.preventDefault(); dragDisabled = false; }; @@ -135,23 +147,13 @@ function editConditionalElse(e: CustomEvent) { return; } + const scriptSettings = + (userScript as { settings?: { [key: string]: unknown } }).settings ?? {}; + new UserScriptSettingsModal( app, command, - (userScript.settings ?? {}) as { - [key: string]: unknown; - options?: { - [key: string]: { - description?: string; - type: string; - value: string | boolean; - placeholder?: string; - secret?: boolean; - defaultValue: string | boolean; - options?: string[]; - }; - }; - }, + scriptSettings as ConstructorParameters[2], () => saveCommands([...commands]), ).open(); } @@ -197,7 +199,7 @@ function editConditionalElse(e: CustomEvent) { {#each commands.filter((c) => c.id !== SHADOW_PLACEHOLDER_ITEM_ID) as command (command.id)} {#if command.type === CommandType.Wait} await deleteCommand(e.detail)} @@ -205,7 +207,7 @@ function editConditionalElse(e: CustomEvent) { /> {:else if command.type === CommandType.NestedChoice} await deleteCommand(e.detail)} @@ -214,7 +216,7 @@ function editConditionalElse(e: CustomEvent) { /> {:else if command.type === CommandType.UserScript} await deleteCommand(e.detail)} @@ -223,7 +225,7 @@ function editConditionalElse(e: CustomEvent) { /> {:else if command.type === CommandType.AIAssistant} await deleteCommand(e.detail)} @@ -232,7 +234,7 @@ function editConditionalElse(e: CustomEvent) { /> {:else if command.type === CommandType.OpenFile} await deleteCommand(e.detail)} @@ -241,7 +243,7 @@ function editConditionalElse(e: CustomEvent) { /> {:else if command.type === CommandType.Conditional} await deleteCommand(e.detail)} diff --git a/src/gui/MacroGUIs/Components/AIAssistantCommand.svelte b/src/gui/MacroGUIs/Components/AIAssistantCommand.svelte index 518a7716..ae51fa1f 100644 --- a/src/gui/MacroGUIs/Components/AIAssistantCommand.svelte +++ b/src/gui/MacroGUIs/Components/AIAssistantCommand.svelte @@ -1,11 +1,10 @@