@dotdirfm/extension-api 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,119 @@
1
+ export interface ViewerProps {
2
+ filePath: string;
3
+ fileName: string;
4
+ fileSize: number;
5
+ inline?: boolean;
6
+ extensionScriptBaseUrl?: string;
7
+ }
8
+ export interface EditorGrammarPayload {
9
+ contribution: {
10
+ language: string;
11
+ scopeName: string;
12
+ path: string;
13
+ embeddedLanguages?: Record<string, string>;
14
+ };
15
+ path?: string;
16
+ content?: object;
17
+ }
18
+ export interface EditorLanguagePayload {
19
+ id: string;
20
+ aliases?: string[];
21
+ extensions?: string[];
22
+ filenames?: string[];
23
+ }
24
+ export interface EditorProps {
25
+ filePath: string;
26
+ fileName: string;
27
+ langId: string;
28
+ extensionDirPath?: string;
29
+ languages?: EditorLanguagePayload[];
30
+ grammars?: EditorGrammarPayload[];
31
+ inline?: boolean;
32
+ extensionScriptBaseUrl?: string;
33
+ }
34
+ export interface ColorThemeData {
35
+ kind: "dark" | "light";
36
+ colors?: Record<string, string>;
37
+ tokenColors?: unknown[];
38
+ }
39
+ export interface HostApi {
40
+ readFile(path: string): Promise<ArrayBuffer>;
41
+ readFileText(path: string): Promise<string>;
42
+ readFileRange?(path: string, offset: number, length: number): Promise<ArrayBuffer>;
43
+ statFile?(path: string): Promise<{
44
+ size: number;
45
+ mtimeMs: number;
46
+ }>;
47
+ onFileChange?(callback: () => void): () => void;
48
+ writeFile(path: string, content: string): Promise<void>;
49
+ getTheme(): Promise<string>;
50
+ getColorTheme?(): ColorThemeData | null;
51
+ onThemeChange?(callback: (theme: ColorThemeData) => void): () => void;
52
+ onClose(): void;
53
+ executeCommand?<T = unknown>(command: string, args?: unknown): Promise<T>;
54
+ registerCommand?(commandId: string, handler: (...args: unknown[]) => void | Promise<void>): () => void;
55
+ registerKeybinding?(binding: {
56
+ command: string;
57
+ key: string;
58
+ mac?: string;
59
+ when?: string;
60
+ }): () => void;
61
+ getOnigurumaWasm?(): Promise<ArrayBuffer>;
62
+ getExtensionResourceUrl?(relativePath: string): Promise<string>;
63
+ }
64
+ export interface ViewerExtensionApi {
65
+ mount(root: HTMLElement, props: ViewerProps): Promise<void>;
66
+ unmount(): Promise<void>;
67
+ }
68
+ export interface EditorExtensionApi {
69
+ mount(root: HTMLElement, props: EditorProps): Promise<void>;
70
+ unmount(): Promise<void>;
71
+ setDirty?(dirty: boolean): void;
72
+ setLanguage?(langId: string): void | Promise<void>;
73
+ }
74
+ export interface FsProviderEntry {
75
+ name: string;
76
+ type: "file" | "directory";
77
+ size?: number;
78
+ mtimeMs?: number;
79
+ }
80
+ export interface FsProviderHostApi {
81
+ readFile(realPath: string): Promise<ArrayBuffer>;
82
+ readFileRange(realPath: string, offset: number, length: number): Promise<ArrayBuffer>;
83
+ }
84
+ export interface FsProviderExtensionApi {
85
+ listEntries(containerPath: string, innerPath: string): Promise<FsProviderEntry[]>;
86
+ readFileRange?(containerPath: string, innerPath: string, offset: number, length: number): Promise<ArrayBuffer>;
87
+ }
88
+ export type DotDirHostReadyCallback = (api: ViewerExtensionApi | EditorExtensionApi) => void;
89
+ export type FsProviderFactory = (hostApi: FsProviderHostApi) => FsProviderExtensionApi;
90
+ export interface DotDirCommandsApi {
91
+ registerCommand: (commandId: string, handler: (...args: unknown[]) => void | Promise<void>, options?: {
92
+ title?: string;
93
+ category?: string;
94
+ icon?: string;
95
+ when?: string;
96
+ }) => {
97
+ dispose: () => void;
98
+ };
99
+ registerKeybinding: (binding: {
100
+ command: string;
101
+ key: string;
102
+ mac?: string;
103
+ when?: string;
104
+ }) => {
105
+ dispose: () => void;
106
+ };
107
+ }
108
+ export type DotDirGlobalApi = HostApi & {
109
+ commands?: DotDirCommandsApi;
110
+ };
111
+ declare global {
112
+ interface Window {
113
+ __dotdirHostReady?: DotDirHostReadyCallback;
114
+ __dotdirProviderReady?: FsProviderFactory;
115
+ dotdir?: DotDirGlobalApi;
116
+ }
117
+ var dotdir: DotDirGlobalApi;
118
+ }
119
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@dotdirfm/extension-api",
3
+ "version": "0.1.0",
4
+ "description": "Shared host and extension API types for DotDir viewer/editor/fs provider extensions.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "keywords": [
19
+ "dotdir",
20
+ "extensions",
21
+ "api",
22
+ "types"
23
+ ],
24
+ "author": "Mikhail Isupov",
25
+ "license": "ISC",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/dotdirfm/dotdir.git"
29
+ },
30
+ "homepage": "https://github.com/dotdirfm/dotdir#readme",
31
+ "bugs": {
32
+ "url": "https://github.com/dotdirfm/dotdir/issues"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.json"
39
+ }
40
+ }