refactor(web): keep app utilities private and remove dead helpers (#10227)
This commit is contained in:
1 parent
226abe5f91
commit
1200f530bd
22 files changed
+27
-52
No files matched your search
@@ -4,7 +4,7 @@ type BrowserViewportHandler = (setting: PreviewViewportSetting) => Promise<void>
|
||||
|
||||
export const BROWSER_VIEWPORT_COMMIT_TIMEOUT_MS = 15_000;
|
||||
|
||||
export class BrowserViewportCommitTimeoutError extends Error {
|
||||
class BrowserViewportCommitTimeoutError extends Error {
|
||||
override readonly name = "BrowserViewportCommitTimeoutError";
|
||||
|
||||
constructor(readonly tabId: string) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const WEBVIEW_CRASH_RECOVERY_WINDOW_MS = 30_000;
|
||||
export const WEBVIEW_CRASH_RECOVERY_MAX_ATTEMPTS = 3;
|
||||
export const WEBVIEW_CRASH_RECOVERY_BASE_DELAY_MS = 250;
|
||||
const WEBVIEW_CRASH_RECOVERY_MAX_ATTEMPTS = 3;
|
||||
const WEBVIEW_CRASH_RECOVERY_BASE_DELAY_MS = 250;
|
||||
|
||||
export interface WebviewCrashRecoveryState {
|
||||
readonly attempts: number;
|
||||
|
||||
@@ -9,7 +9,7 @@ export type BrowserFaviconEntry = {
|
||||
};
|
||||
|
||||
export const BROWSER_FAVICON_MAX_ENTRIES = 40;
|
||||
export const BROWSER_FAVICON_MAX_KEY_LENGTH = 4_096;
|
||||
const BROWSER_FAVICON_MAX_KEY_LENGTH = 4_096;
|
||||
const BROWSER_FAVICON_MAX_FUTURE_SKEW_MS = 5 * 60 * 1_000;
|
||||
export const BROWSER_FAVICON_MAX_ALIASES_PER_ENTRY = 4;
|
||||
const BROWSER_FAVICON_MAX_ALIAS_LENGTH = 255;
|
||||
|
||||
@@ -14,7 +14,7 @@ export type BrowserHistoryEntry = { url: string; lastVisitedAt: number; title?:
|
||||
|
||||
export const BROWSER_HISTORY_MAX_ENTRIES_PER_PROJECT = 50;
|
||||
export const BROWSER_HISTORY_MAX_PROJECTS = 20;
|
||||
export const BROWSER_HISTORY_MAX_URL_LENGTH = 2048;
|
||||
const BROWSER_HISTORY_MAX_URL_LENGTH = 2048;
|
||||
export const BROWSER_HISTORY_MAX_TITLE_LENGTH = 512;
|
||||
const MAX_VALID_DATE_MS = 8_640_000_000_000_000;
|
||||
|
||||
@@ -35,7 +35,7 @@ export function normalizeHistoryUrl(raw: string): string | null {
|
||||
return parsed.href.length > BROWSER_HISTORY_MAX_URL_LENGTH ? null : parsed.href;
|
||||
}
|
||||
|
||||
export function titleLookupKey(normalized: string, environmentHostname?: string | null): string {
|
||||
function titleLookupKey(normalized: string, environmentHostname?: string | null): string {
|
||||
const parsed = new URL(visitLookupKey(normalized, environmentHostname));
|
||||
if (parsed.pathname !== "/" && parsed.pathname.endsWith("/"))
|
||||
parsed.pathname = parsed.pathname.slice(0, -1);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ClientSettingsSchema, type ClientSettings } from "@t3tools/contracts";
|
||||
|
||||
import { getLocalStorageItem, setLocalStorageItem } from "./hooks/useLocalStorage";
|
||||
|
||||
export const CLIENT_SETTINGS_STORAGE_KEY = "t3code:client-settings:v1";
|
||||
const CLIENT_SETTINGS_STORAGE_KEY = "t3code:client-settings:v1";
|
||||
|
||||
function hasWindow(): boolean {
|
||||
return typeof window !== "undefined";
|
||||
|
||||
@@ -769,7 +769,7 @@ const EMPTY_THREAD_DRAFT = Object.freeze<ComposerThreadDraftState>({
|
||||
* slice — adding a new field to the interface (e.g. `elementContexts`) only
|
||||
* has to be reflected here, not in every stub.
|
||||
*/
|
||||
export function createEmptyThreadDraft(): ComposerThreadDraftState {
|
||||
function createEmptyThreadDraft(): ComposerThreadDraftState {
|
||||
return {
|
||||
prompt: "",
|
||||
images: [],
|
||||
@@ -4050,9 +4050,7 @@ export function useThreadHasUnsentDraft(threadRef: ScopedThreadRef): boolean {
|
||||
);
|
||||
}
|
||||
|
||||
export function useComposerDraftModelState(
|
||||
threadRef: ComposerThreadTarget,
|
||||
): ComposerDraftModelState {
|
||||
function useComposerDraftModelState(threadRef: ComposerThreadTarget): ComposerDraftModelState {
|
||||
return useComposerDraftStore(
|
||||
useShallow((state) => {
|
||||
const draft = getComposerDraftState(state, threadRef);
|
||||
|
||||
@@ -44,7 +44,7 @@ function failure(
|
||||
return { version: 1, requestId, ok: false, code, message };
|
||||
}
|
||||
|
||||
export function desktopPlatformToEnvironmentOs(
|
||||
function desktopPlatformToEnvironmentOs(
|
||||
platform: DesktopAppActivationRequest["platform"],
|
||||
): ExecutionEnvironmentPlatformOs {
|
||||
return platform === "win32" ? "windows" : platform;
|
||||
|
||||
@@ -377,14 +377,6 @@ export function isDiffToggleShortcut(
|
||||
return matchesCommandShortcut(event, keybindings, "diff.toggle", options);
|
||||
}
|
||||
|
||||
export function isPreviewRefreshShortcut(
|
||||
event: ShortcutEventLike,
|
||||
keybindings: ResolvedKeybindingsConfig,
|
||||
options?: ShortcutMatchOptions,
|
||||
): boolean {
|
||||
return matchesCommandShortcut(event, keybindings, "preview.refresh", options);
|
||||
}
|
||||
|
||||
export function isOpenFavoriteEditorShortcut(
|
||||
event: ShortcutEventLike,
|
||||
keybindings: ResolvedKeybindingsConfig,
|
||||
|
||||
@@ -445,7 +445,7 @@ export function startAttachmentUpload(input: {
|
||||
* persisted draft upload survives cancellation (an environment switch cancels
|
||||
* the old job, and the draft still references that server copy).
|
||||
*/
|
||||
export function cancelAttachmentUpload(imageId: string): void {
|
||||
function cancelAttachmentUpload(imageId: string): void {
|
||||
const job = jobsByImageId.get(imageId);
|
||||
if (!job) {
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles";
|
||||
import type { FileDiffMetadata } from "@pierre/diffs/types";
|
||||
|
||||
export const DIFF_THEME_NAMES = {
|
||||
const DIFF_THEME_NAMES = {
|
||||
light: "pierre-light",
|
||||
dark: "pierre-dark",
|
||||
} as const;
|
||||
@@ -81,7 +81,7 @@ interface RenderablePatchOptions {
|
||||
compactPartialHunkOffsets?: boolean;
|
||||
}
|
||||
|
||||
export function compactPartialHunkOffsets(file: FileDiffMetadata): FileDiffMetadata {
|
||||
function compactPartialHunkOffsets(file: FileDiffMetadata): FileDiffMetadata {
|
||||
if (!file.isPartial) return file;
|
||||
|
||||
let splitLineStart = 0;
|
||||
|
||||
@@ -111,7 +111,7 @@ async function previewAnnotationScreenshotFile(
|
||||
}
|
||||
|
||||
/** Upper bound on turning a picked element's crop into a composer attachment. */
|
||||
export const PREVIEW_ANNOTATION_CAPTURE_TIMEOUT_MS = 5_000;
|
||||
const PREVIEW_ANNOTATION_CAPTURE_TIMEOUT_MS = 5_000;
|
||||
|
||||
export type PreviewAnnotationCapture =
|
||||
/** The crop is ready to attach. */
|
||||
|
||||
@@ -26,7 +26,7 @@ export function createMemoryStorage(): StateStorage {
|
||||
};
|
||||
}
|
||||
|
||||
export function isStateStorage(
|
||||
function isStateStorage(
|
||||
storage: Partial<StateStorage> | null | undefined,
|
||||
): storage is StateStorage {
|
||||
return (
|
||||
|
||||
@@ -65,7 +65,7 @@ export function filterTerminalContextsWithText<T extends { text: string }>(
|
||||
return contexts.filter((context) => hasTerminalContextText(context));
|
||||
}
|
||||
|
||||
export function normalizeTerminalContextSelection(
|
||||
function normalizeTerminalContextSelection(
|
||||
selection: TerminalContextSelection,
|
||||
): TerminalContextSelection | null {
|
||||
const text = normalizeTerminalContextText(selection.text);
|
||||
@@ -85,10 +85,7 @@ export function normalizeTerminalContextSelection(
|
||||
};
|
||||
}
|
||||
|
||||
export function formatTerminalContextRange(selection: {
|
||||
lineStart: number;
|
||||
lineEnd: number;
|
||||
}): string {
|
||||
function formatTerminalContextRange(selection: { lineStart: number; lineEnd: number }): string {
|
||||
return selection.lineStart === selection.lineEnd
|
||||
? `line ${selection.lineStart}`
|
||||
: `lines ${selection.lineStart}-${selection.lineEnd}`;
|
||||
|
||||
@@ -43,7 +43,7 @@ export function syncDocumentWindowControlsOverlayClass(): () => void {
|
||||
};
|
||||
}
|
||||
|
||||
export function getElectronPlatformClassNames(
|
||||
function getElectronPlatformClassNames(
|
||||
platform: string,
|
||||
):
|
||||
| readonly [typeof ELECTRON_CLASS_NAME]
|
||||
|
||||
@@ -4,7 +4,6 @@ export {
|
||||
deriveLogicalProjectKeyFromSettings,
|
||||
derivePhysicalProjectKey,
|
||||
derivePhysicalProjectKeyFromPath,
|
||||
deriveProjectGroupLabel,
|
||||
deriveProjectGroupingOverrideKey,
|
||||
getProjectOrderKey,
|
||||
resolveProjectGroupingMode,
|
||||
|
||||
@@ -43,7 +43,7 @@ export function boundConfiguredLocalServerUrls(
|
||||
return bounded;
|
||||
}
|
||||
|
||||
export function useDiscoveredPorts(
|
||||
function useDiscoveredPorts(
|
||||
environmentId: EnvironmentId | null,
|
||||
configuredUrls?: ReadonlyArray<string>,
|
||||
): ReadonlyArray<DiscoveredLocalServer> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { iconNames, type IconName } from "lucide-react/dynamic";
|
||||
export { PROJECT_ICON_COLORS, projectIconColorClassName } from "./projectIconColors";
|
||||
|
||||
export const POPULAR_PROJECT_ICONS = [
|
||||
const POPULAR_PROJECT_ICONS = [
|
||||
"folder-code",
|
||||
"code-2",
|
||||
"terminal",
|
||||
|
||||
@@ -180,12 +180,6 @@ export function parseReviewCommentMessageSegments(
|
||||
return segments;
|
||||
}
|
||||
|
||||
export function hasReviewCommentMessageSegments(value: string): boolean {
|
||||
return parseReviewCommentMessageSegments(value).some(
|
||||
(segment) => segment.kind === "review-comment",
|
||||
);
|
||||
}
|
||||
|
||||
export function formatReviewCommentFence(language: string, contents: string): string {
|
||||
const longestBacktickRun = Math.max(
|
||||
0,
|
||||
|
||||
@@ -14,7 +14,7 @@ import { createJSONStorage, persist } from "zustand/middleware";
|
||||
|
||||
import { resolveStorage } from "./lib/storage";
|
||||
|
||||
export const RIGHT_PANEL_KINDS = [
|
||||
const RIGHT_PANEL_KINDS = [
|
||||
"diff",
|
||||
"files",
|
||||
"file",
|
||||
@@ -193,7 +193,7 @@ export function pullRequestSurfaceId(target: {
|
||||
return `pull-request:${scope}${encodeURIComponent(target.projectId)}:${encodeURIComponent(target.repository)}:${target.number}`;
|
||||
}
|
||||
|
||||
export function pullRequestSurface(target: {
|
||||
function pullRequestSurface(target: {
|
||||
environmentId?: string;
|
||||
projectId: string;
|
||||
repository: string;
|
||||
|
||||
@@ -34,7 +34,7 @@ import type { Dispatch, SetStateAction } from "react";
|
||||
* Call `beginRender()` before each component invocation and `reset()` in
|
||||
* `beforeEach` to drop persisted state between tests.
|
||||
*/
|
||||
export function createReactHookHarness() {
|
||||
function createReactHookHarness() {
|
||||
let cursor = 0;
|
||||
let slots: unknown[] = [];
|
||||
const nextIndex = () => cursor++;
|
||||
|
||||
@@ -22,15 +22,10 @@ export { EMBER_THEME, GROVE_THEME, IRIS_THEME, OCEAN_THEME, T3_CHAT_THEME, THEME
|
||||
export type { ThemeAppearance, ThemeColorRole, ThemeColors, ThemeDefinition, ThemeVariants };
|
||||
|
||||
export const T3_CHAT_THEME_ID = "t3-chat" as const;
|
||||
export const T3_CHAT_THEME_LABEL = "T3 Chat";
|
||||
export const GROVE_THEME_ID = "grove" as const;
|
||||
export const GROVE_THEME_LABEL = "Grove";
|
||||
const GROVE_THEME_ID = "grove" as const;
|
||||
export const OCEAN_THEME_ID = "ocean" as const;
|
||||
export const OCEAN_THEME_LABEL = "Ocean";
|
||||
export const EMBER_THEME_ID = "ember" as const;
|
||||
export const EMBER_THEME_LABEL = "Ember";
|
||||
export const IRIS_THEME_ID = "iris" as const;
|
||||
export const IRIS_THEME_LABEL = "Iris";
|
||||
const EMBER_THEME_ID = "ember" as const;
|
||||
const IRIS_THEME_ID = "iris" as const;
|
||||
export const THEME_FILE_VERSION = 1 as const;
|
||||
export const CUSTOM_THEMES_STORAGE_KEY = "t3code:themes:v1";
|
||||
export const THEME_FOLLOW_SYSTEM_STORAGE_KEY = "t3code:theme-follow-system";
|
||||
|
||||
@@ -12,7 +12,7 @@ export interface VersionMismatch {
|
||||
readonly hint: string;
|
||||
}
|
||||
|
||||
export const VERSION_MISMATCH_DISMISSALS_STORAGE_KEY = "t3code:version-mismatch-dismissals:v1";
|
||||
const VERSION_MISMATCH_DISMISSALS_STORAGE_KEY = "t3code:version-mismatch-dismissals:v1";
|
||||
|
||||
// Runtime failures retain their identity until the next attempt. Dismiss only
|
||||
// that attempt, across chat remounts, without clearing the error in Settings.
|
||||
|
||||
Reference in new issue
Block a user