UNPKG

@scalar/api-client

Version:

the open source API testing client

126 lines 5.53 kB
import type { ScalarListboxOption, WorkspaceGroup } from '@scalar/components'; import type { HttpMethod } from '@scalar/helpers/http/http-methods'; import type { LoaderPlugin } from '@scalar/json-magic/bundle'; import { createSidebarState } from '@scalar/sidebar'; import { type WorkspaceStore } from '@scalar/workspace-store/client'; import { type WorkspaceEventBus } from '@scalar/workspace-store/events'; import type { WorkspaceDocument } from '@scalar/workspace-store/schemas'; import type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'; import type { Tab } from '@scalar/workspace-store/schemas/extensions/workspace/x-scalar-tabs'; import type { TraversedEntry } from '@scalar/workspace-store/schemas/navigation'; import { type ComputedRef, type Ref, type ShallowRef } from 'vue'; import type { RouteLocationNormalizedGeneric, Router } from 'vue-router'; export type GetEntryByLocation = (location: { document: string; path?: string; method?: HttpMethod; example?: string; }) => (TraversedEntry & { parent?: TraversedEntry | undefined; }) | undefined; type WorkspaceOption = ScalarListboxOption & { teamUid: string; namespace: string; slug: string; }; /** Defines the overall application state structure and its main feature modules */ export type AppState = { /** The workspace store */ store: ShallowRef<WorkspaceStore | null>; /** The sidebar management */ sidebar: { /** The sidebar state */ state: ReturnType<typeof createSidebarState<TraversedEntry>>; /** The width of the sidebar */ width: ComputedRef<number>; /** Whether the sidebar is open */ isOpen: Ref<boolean>; /** Handles the selection of an item in the sidebar */ handleSelectItem: (id: string) => void; /** Handles the width update of the sidebar */ handleSidebarWidthUpdate: (width: number) => void; /** Gets the entry by location */ getEntryByLocation: GetEntryByLocation; }; /** The tabs management */ tabs: { /** The tabs state */ state: Ref<Tab[]>; /** The active tab index */ activeTabIndex: Ref<number>; /** Copies the URL of the tab at the given index to the clipboard */ copyTabUrl: (index: number) => Promise<void>; }; /** The workspace management */ workspace: { /** Creates a new workspace and navigates to it */ create: (payload: { teamUid?: string; namespace?: string; slug?: string; name: string; }) => Promise<{ name: string; namespace: string; slug: string; teamUid: string; } | undefined>; /** All workspace list */ workspaceList: Ref<WorkspaceOption[]>; /** Filtered workspace list, based on the current teamUid */ filteredWorkspaceList: ComputedRef<WorkspaceOption[]>; /** * Groups workspaces into team and local categories for display in the workspace picker. * Team workspaces are shown first (when not on local team), followed by local workspaces. */ workspaceGroups: ComputedRef<WorkspaceGroup[]>; /** The currently active workspace */ activeWorkspace: ShallowRef<{ id: string; label: string; } | null>; /** Navigates to the specified workspace */ navigateToWorkspace: (namespace?: string, slug?: string) => Promise<void>; /** Whether the workspace page is open */ isOpen: ComputedRef<boolean>; }; /** The workspace event bus for handling workspace-level events */ eventBus: WorkspaceEventBus; /** The router instance */ router: Router; /** The current route derived from the router */ currentRoute: Ref<RouteLocationNormalizedGeneric | null>; /** Whether the workspace is currently syncing */ loading: Ref<boolean>; /** The currently active entities */ activeEntities: { /** The namespace of the current entity, e.g. "default" or a custom namespace */ namespace: Ref<string | undefined>; /** The slug identifying the current workspace */ workspaceSlug: Ref<string | undefined>; /** The slug of the currently selected document in the workspace */ documentSlug: Ref<string | undefined>; /** The API path currently selected (e.g. "/users/{id}") */ path: Ref<string | undefined>; /** The HTTP method for the currently selected API path (e.g. GET, POST) */ method: Ref<HttpMethod | undefined>; /** The name of the currently selected example (for examples within an endpoint) */ exampleName: Ref<string | undefined>; /** The unique identifier for the selected team context (read-only; use setTeamUid to change) */ teamUid: Readonly<Ref<string>>; /** Sets the current team context by team UID */ setTeamUid: (value: string) => void; }; /** The currently active environment */ environment: ComputedRef<XScalarEnvironment>; /** The currently active document */ document: ComputedRef<WorkspaceDocument | null>; /** Whether the current color mode is dark */ isDarkMode: ComputedRef<boolean>; }; export declare const createAppState: ({ router, fileLoader, }: { router: Router; fileLoader?: LoaderPlugin; }) => Promise<AppState>; export {}; //# sourceMappingURL=app-state.d.ts.map