Skip to content

Commit

Permalink
Generalize obsidian-private.ts to private.ts
Browse files Browse the repository at this point in the history
Signed-off-by: William So <polyipseity@gmail.com>
  • Loading branch information
polyipseity committed May 3, 2023
1 parent a990638 commit df2c79e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 46 deletions.
38 changes: 38 additions & 0 deletions sources/@types/obsidian.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import "obsidian"
import type { Private } from "sources/utils/private"

declare module "obsidian" {
interface DataAdapter extends Private<$DataAdapter> { }
interface ViewStateResult extends Private<$ViewStateResult> { }
interface WorkspaceLeaf extends Private<$WorkspaceLeaf> { }
interface WorkspaceRibbon extends Private<$WorkspaceRibbon> { }
}

interface $DataAdapter {
readonly fs: {
readonly open: <T extends Platform.Current>(
path: T extends Platform.Mobile ? string : never,
) => T extends Platform.Mobile ? PromiseLike<void> : never
}
}

interface $ViewStateResult {
history: boolean
}

interface $WorkspaceLeaf {
readonly tabHeaderEl: HTMLElement
readonly tabHeaderInnerIconEl: HTMLElement
readonly tabHeaderInnerTitleEl: HTMLElement
}

interface $WorkspaceRibbon {
readonly addRibbonItemButton: (
id: string,
icon: string,
title: string,
callback: (event: MouseEvent) => unknown,
) => HTMLElement
readonly removeRibbonAction: (title: string) => void
}
2 changes: 1 addition & 1 deletion sources/terminal/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import { XtermTerminalEmulator } from "./emulator"
import { cloneDeep } from "lodash-es"
import { dynamicRequireLazy } from "sources/imports"
import { launderUnchecked } from "sources/utils/types"
import { revealPrivate } from "sources/utils/obsidian-private"
import { revealPrivate } from "sources/utils/private"
import { writePromise } from "./util"

const
Expand Down
2 changes: 1 addition & 1 deletion sources/utils/obsidian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
typedStructuredClone,
} from "./util"
import { constant, isUndefined } from "lodash-es"
import { revealPrivate, revealPrivateAsync } from "./obsidian-private"
import { revealPrivate, revealPrivateAsync } from "./private"
import { DEFAULT_LANGUAGE } from "assets/locales"
import { Platform } from "./platforms"
import type { TerminalPlugin } from "sources/main"
Expand Down
49 changes: 5 additions & 44 deletions sources/utils/obsidian-private.ts → sources/utils/private.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* eslint-disable @typescript-eslint/no-empty-interface */
import type { Platform } from "./platforms"
import type { TerminalPlugin } from "sources/main"

declare const PRIVATE: unique symbol
export interface Private<T> { readonly [PRIVATE]: T }
export type RevealPrivate<T extends Private<unknown>> =
Omit<T, typeof PRIVATE> & T[typeof PRIVATE]

export function revealPrivate<const As extends readonly Private<unknown>[], R>(
plugin: TerminalPlugin,
args: As,
Expand Down Expand Up @@ -43,45 +46,3 @@ export async function revealPrivateAsync<
return await fallback(error, ...args)
}
}

declare const PRIVATE: unique symbol
interface Private<T> {
readonly [PRIVATE]: T
}
export type RevealPrivate<T extends {
readonly [PRIVATE]: unknown
}> = Omit<T, typeof PRIVATE> & T[typeof PRIVATE]
declare module "obsidian" {
interface DataAdapter extends Private<$DataAdapter> { }
interface ViewStateResult extends Private<$ViewStateResult> { }
interface WorkspaceLeaf extends Private<$WorkspaceLeaf> { }
interface WorkspaceRibbon extends Private<$WorkspaceRibbon> { }
}

interface $DataAdapter {
readonly fs: {
readonly open: <T extends Platform.Current>(
path: T extends Platform.Mobile ? string : never,
) => T extends Platform.Mobile ? PromiseLike<void> : never
}
}

interface $ViewStateResult {
history: boolean
}

interface $WorkspaceLeaf {
readonly tabHeaderEl: HTMLElement
readonly tabHeaderInnerIconEl: HTMLElement
readonly tabHeaderInnerTitleEl: HTMLElement
}

interface $WorkspaceRibbon {
readonly addRibbonItemButton: (
id: string,
icon: string,
title: string,
callback: (event: MouseEvent) => unknown,
) => HTMLElement
readonly removeRibbonAction: (title: string) => void
}

0 comments on commit df2c79e

Please sign in to comment.