| author | |
| committer | |
| log | 674720c6cd233ca8c9a7b357eb954e26cae3466d |
| tree | 3370feadf8746aac1751108f45f62e92a1127231 |
| parent | 58c9e4b96d811c120c7434549656c19058751713 |
Re-export ContextMenuItem and replace the inlined
{ id: T; label: string; destructive?: boolean } definitions in
wsNativeApi, contextMenuFallback, and the test file.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>4 files changed, 8 insertions(+), 4 deletions(-)
apps/web/src/contextMenuFallback.ts+3-1| ... | @@ -1,10 +1,12 @@ | ... | @@ -1,10 +1,12 @@ |
| 1 | import type { ContextMenuItem } from "@t3tools/contracts"; | ||
| 2 | |||
| 1 | /** | 3 | /** |
| 2 | * Imperative DOM-based context menu for non-Electron environments. | 4 | * Imperative DOM-based context menu for non-Electron environments. |
| 3 | * Shows a positioned dropdown and returns a promise that resolves | 5 | * Shows a positioned dropdown and returns a promise that resolves |
| 4 | * with the clicked item id, or null if dismissed. | 6 | * with the clicked item id, or null if dismissed. |
| 5 | */ | 7 | */ |
| 6 | export function showContextMenuFallback<T extends string>( | 8 | export function showContextMenuFallback<T extends string>( |
| 7 | items: readonly { id: T; label: string; destructive?: boolean }[], | 9 | items: readonly ContextMenuItem<T>[], |
| 8 | position?: { x: number; y: number }, | 10 | position?: { x: number; y: number }, |
| 9 | ): Promise<T | null> { | 11 | ): Promise<T | null> { |
| 10 | return new Promise<T | null>((resolve) => { | 12 | return new Promise<T | null>((resolve) => { |
apps/web/src/wsNativeApi.test.ts+2-1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | import { | 1 | import { |
| 2 | CommandId, | 2 | CommandId, |
| 3 | type ContextMenuItem, | ||
| 3 | ORCHESTRATION_WS_CHANNELS, | 4 | ORCHESTRATION_WS_CHANNELS, |
| 4 | ORCHESTRATION_WS_METHODS, | 5 | ORCHESTRATION_WS_METHODS, |
| 5 | ProjectId, | 6 | ProjectId, |
| ... | @@ -11,7 +12,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ... | @@ -11,7 +12,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 11 | const requestMock = vi.fn<(...args: Array<unknown>) => Promise<unknown>>(); | 12 | const requestMock = vi.fn<(...args: Array<unknown>) => Promise<unknown>>(); |
| 12 | const showContextMenuFallbackMock = vi.fn< | 13 | const showContextMenuFallbackMock = vi.fn< |
| 13 | <T extends string>( | 14 | <T extends string>( |
| 14 | items: readonly { id: T; label: string; destructive?: boolean }[], | 15 | items: readonly ContextMenuItem<T>[], |
| 15 | position?: { x: number; y: number }, | 16 | position?: { x: number; y: number }, |
| 16 | ) => Promise<T | null> | 17 | ) => Promise<T | null> |
| 17 | >(); | 18 | >(); |
apps/web/src/wsNativeApi.ts+2-1| ... | @@ -2,6 +2,7 @@ import { | ... | @@ -2,6 +2,7 @@ import { |
| 2 | OrchestrationEvent, | 2 | OrchestrationEvent, |
| 3 | ORCHESTRATION_WS_CHANNELS, | 3 | ORCHESTRATION_WS_CHANNELS, |
| 4 | ORCHESTRATION_WS_METHODS, | 4 | ORCHESTRATION_WS_METHODS, |
| 5 | type ContextMenuItem, | ||
| 5 | type NativeApi, | 6 | type NativeApi, |
| 6 | ServerConfigUpdatedPayload, | 7 | ServerConfigUpdatedPayload, |
| 7 | TerminalEvent, | 8 | TerminalEvent, |
| ... | @@ -171,7 +172,7 @@ export function createWsNativeApi(): NativeApi { | ... | @@ -171,7 +172,7 @@ export function createWsNativeApi(): NativeApi { |
| 171 | }, | 172 | }, |
| 172 | contextMenu: { | 173 | contextMenu: { |
| 173 | show: async <T extends string>( | 174 | show: async <T extends string>( |
| 174 | items: readonly { id: T; label: string; destructive?: boolean }[], | 175 | items: readonly ContextMenuItem<T>[], |
| 175 | position?: { x: number; y: number }, | 176 | position?: { x: number; y: number }, |
| 176 | ): Promise<T | null> => { | 177 | ): Promise<T | null> => { |
| 177 | if (window.desktopBridge) { | 178 | if (window.desktopBridge) { |
packages/contracts/src/ipc.ts+1-1| ... | @@ -37,7 +37,7 @@ import type { | ... | @@ -37,7 +37,7 @@ import type { |
| 37 | } from "./orchestration"; | 37 | } from "./orchestration"; |
| 38 | import { EditorId } from "./editor"; | 38 | import { EditorId } from "./editor"; |
| 39 | 39 | ||
| 40 | interface ContextMenuItem<T extends string = string> { | 40 | export interface ContextMenuItem<T extends string = string> { |
| 41 | id: T; | 41 | id: T; |
| 42 | label: string; | 42 | label: string; |
| 43 | destructive?: boolean; | 43 | destructive?: boolean; |