@dotdirfm/ui 0.1.4 → 0.1.5
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.
|
@@ -1,196 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Shared types for the host ↔ extension iframe communication (postMessage RPC).
|
|
3
|
-
*
|
|
4
|
-
* Host exposes HostApi to the iframe.
|
|
5
|
-
* Viewer extensions expose ViewerExtensionApi; editor extensions expose EditorExtensionApi.
|
|
6
|
-
*/
|
|
7
|
-
export interface ViewerProps {
|
|
8
|
-
filePath: string;
|
|
9
|
-
fileName: string;
|
|
10
|
-
fileSize: number;
|
|
11
|
-
inline?: boolean;
|
|
12
|
-
/** When set (e.g. Web VFS), extension can load scripts/workers from this base URL. */
|
|
13
|
-
extensionScriptBaseUrl?: string;
|
|
14
|
-
}
|
|
15
|
-
/** Grammar contribution + loaded content (from host, for custom syntax highlighting). */
|
|
16
|
-
export interface EditorGrammarPayload {
|
|
17
|
-
contribution: {
|
|
18
|
-
language: string;
|
|
19
|
-
scopeName: string;
|
|
20
|
-
path: string;
|
|
21
|
-
embeddedLanguages?: Record<string, string>;
|
|
22
|
-
};
|
|
23
|
-
/** Absolute path to grammar JSON file (used for lazy loading). */
|
|
24
|
-
path?: string;
|
|
25
|
-
/** Parsed TextMate grammar JSON (optional; host may lazy-load and fill it). */
|
|
26
|
-
content?: object;
|
|
27
|
-
}
|
|
28
|
-
export interface EditorLanguagePayload {
|
|
29
|
-
id: string;
|
|
30
|
-
aliases?: string[];
|
|
31
|
-
extensions?: string[];
|
|
32
|
-
filenames?: string[];
|
|
33
|
-
}
|
|
34
|
-
export interface EditorProps {
|
|
35
|
-
filePath: string;
|
|
36
|
-
fileName: string;
|
|
37
|
-
langId: string;
|
|
38
|
-
/** Extension root path (for reading package.json / grammars). */
|
|
39
|
-
extensionDirPath?: string;
|
|
40
|
-
/** All languages from loaded extensions (for Monaco registration). */
|
|
41
|
-
languages?: EditorLanguagePayload[];
|
|
42
|
-
/** All grammars with content from loaded extensions (for TextMate tokenization). */
|
|
43
|
-
grammars?: EditorGrammarPayload[];
|
|
44
|
-
/** True when shown inline (e.g. preview tab). Extensions should not steal focus when inline. */
|
|
45
|
-
inline?: boolean;
|
|
46
|
-
/** When set (e.g. Web VFS), extension can load scripts/workers from this base URL for lazy loading. */
|
|
47
|
-
extensionScriptBaseUrl?: string;
|
|
48
|
-
}
|
|
49
|
-
export interface ColorThemeData {
|
|
50
|
-
/** Theme kind: 'dark' or 'light'. */
|
|
51
|
-
kind: "dark" | "light";
|
|
52
|
-
/** VS Code color theme colors (e.g. 'editor.background' → '#1e1e2e'). Undefined when no VS Code theme active. */
|
|
53
|
-
colors?: Record<string, string>;
|
|
54
|
-
/** VS Code tokenColors for syntax highlighting. Undefined when no VS Code theme active. */
|
|
55
|
-
tokenColors?: unknown[];
|
|
56
|
-
}
|
|
57
|
-
export interface HostApi {
|
|
58
|
-
readFile(path: string): Promise<ArrayBuffer>;
|
|
59
|
-
readFileText(path: string): Promise<string>;
|
|
60
|
-
/** Read a byte range (for chunked viewing). */
|
|
61
|
-
readFileRange?(path: string, offset: number, length: number): Promise<ArrayBuffer>;
|
|
62
|
-
/** Lightweight stat for the currently viewed file. */
|
|
63
|
-
statFile?(path: string): Promise<{
|
|
64
|
-
size: number;
|
|
65
|
-
mtimeMs: number;
|
|
66
|
-
}>;
|
|
67
|
-
/** Subscribe to external changes of the currently viewed file. */
|
|
68
|
-
onFileChange?(callback: () => void): () => void;
|
|
69
|
-
writeFile(path: string, content: string): Promise<void>;
|
|
70
|
-
getTheme(): Promise<string>;
|
|
71
|
-
/** Get the active color theme data (colors + tokenColors). Returns null if no VS Code theme is active. */
|
|
72
|
-
getColorTheme?(): ColorThemeData | null;
|
|
73
|
-
/** Subscribe to theme changes. Callback fires when the color theme changes. Returns unsubscribe function. */
|
|
74
|
-
onThemeChange?(callback: (theme: ColorThemeData) => void): () => void;
|
|
75
|
-
onClose(): void;
|
|
76
|
-
/** Execute a host command (e.g. navigatePrev, navigateNext, getFileIndex). */
|
|
77
|
-
executeCommand?<T = unknown>(command: string, args?: unknown): Promise<T>;
|
|
78
|
-
/**
|
|
79
|
-
* Commands API exposed to extensions running inside the iframe.
|
|
80
|
-
* Implemented to mimic VS Code: `registerCommand(id, callback) -> Disposable`.
|
|
81
|
-
*/
|
|
82
|
-
registerCommand?(commandId: string, handler: (...args: unknown[]) => void | Promise<void>): () => void;
|
|
83
|
-
/** Contribute a keybinding (extension layer). */
|
|
84
|
-
registerKeybinding?(binding: {
|
|
85
|
-
command: string;
|
|
86
|
-
key: string;
|
|
87
|
-
mac?: string;
|
|
88
|
-
when?: string;
|
|
89
|
-
}): () => void;
|
|
90
|
-
/** Oniguruma WASM binary for TextMate grammars (optional). */
|
|
91
|
-
getOnigurumaWasm?(): Promise<ArrayBuffer>;
|
|
92
|
-
/** URL to a file inside the extension dir (for lazy-loading workers). Returns blob URL. */
|
|
93
|
-
getExtensionResourceUrl?(relativePath: string): Promise<string>;
|
|
94
|
-
}
|
|
95
|
-
export interface ViewerExtensionApi {
|
|
96
|
-
/** Render viewer UI into the provided root. */
|
|
97
|
-
mount(root: HTMLElement, props: ViewerProps): Promise<void>;
|
|
98
|
-
unmount(): Promise<void>;
|
|
99
|
-
}
|
|
100
|
-
export interface EditorExtensionApi {
|
|
101
|
-
/** Render editor UI into the provided root. */
|
|
102
|
-
mount(root: HTMLElement, props: EditorProps): Promise<void>;
|
|
103
|
-
unmount(): Promise<void>;
|
|
104
|
-
setDirty?(dirty: boolean): void;
|
|
105
|
-
/** Change the editor language (e.g. for syntax highlighting). */
|
|
106
|
-
setLanguage?(langId: string): void | Promise<void>;
|
|
107
|
-
}
|
|
108
|
-
/** A single entry returned by an fsProvider. */
|
|
109
|
-
export interface FsProviderEntry {
|
|
110
|
-
name: string;
|
|
111
|
-
type: "file" | "directory";
|
|
112
|
-
size?: number;
|
|
113
|
-
mtimeMs?: number;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Host API available to fsProvider extensions (injected as `window.__dotdirProviderHostApi`
|
|
117
|
-
* before the provider bundle is evaluated).
|
|
118
|
-
*/
|
|
119
|
-
export interface FsProviderHostApi {
|
|
120
|
-
/** Read the entire container file from the real filesystem. */
|
|
121
|
-
readFile(realPath: string): Promise<ArrayBuffer>;
|
|
122
|
-
/** Read a byte range from the real filesystem. */
|
|
123
|
-
readFileRange(realPath: string, offset: number, length: number): Promise<ArrayBuffer>;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* API that an fsProvider extension bundle must expose.
|
|
127
|
-
*
|
|
128
|
-
* Protocol: the bundle assigns a factory to `window.__dotdirProviderReady`.
|
|
129
|
-
* The host evaluates the bundle, then calls `window.__dotdirProviderReady(hostApi)`
|
|
130
|
-
* and stores the returned object.
|
|
131
|
-
*
|
|
132
|
-
* Example bundle (CommonJS):
|
|
133
|
-
* ```js
|
|
134
|
-
* window.__dotdirProviderReady = function(hostApi) {
|
|
135
|
-
* return {
|
|
136
|
-
* async listEntries(containerPath, innerPath) {
|
|
137
|
-
* const bytes = await hostApi.readFile(containerPath);
|
|
138
|
-
* // ... parse format, return entries
|
|
139
|
-
* return [{ name: 'README.md', type: 'file', size: 1234 }];
|
|
140
|
-
* }
|
|
141
|
-
* };
|
|
142
|
-
* };
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
export interface FsProviderExtensionApi {
|
|
146
|
-
/**
|
|
147
|
-
* List the entries at `innerPath` inside the container at `containerPath`.
|
|
148
|
-
* `containerPath` is always a real filesystem path.
|
|
149
|
-
* `innerPath` is always absolute, e.g. '/' for the root.
|
|
150
|
-
*/
|
|
151
|
-
listEntries(containerPath: string, innerPath: string): Promise<FsProviderEntry[]>;
|
|
152
|
-
/**
|
|
153
|
-
* Read a byte range of a file inside the container.
|
|
154
|
-
* Optional — only needed if the host should be able to open files inside containers.
|
|
155
|
-
*/
|
|
156
|
-
readFileRange?(containerPath: string, innerPath: string, offset: number, length: number): Promise<ArrayBuffer>;
|
|
157
|
-
}
|
|
158
|
-
/** Extension calls this when loaded; host sets it before injecting the script. */
|
|
159
|
-
export type DotDirHostReadyCallback = (api: ViewerExtensionApi | EditorExtensionApi) => void;
|
|
160
|
-
/** Factory signature for fsProvider bundles. */
|
|
161
|
-
export type FsProviderFactory = (hostApi: FsProviderHostApi) => FsProviderExtensionApi;
|
|
162
|
-
declare global {
|
|
163
|
-
interface Window {
|
|
164
|
-
__dotdirHostReady?: DotDirHostReadyCallback;
|
|
165
|
-
/**
|
|
166
|
-
* Set by the fsProvider bundle. The host calls it after the bundle loads,
|
|
167
|
-
* passing the HostApi, and stores the returned FsProviderExtensionApi.
|
|
168
|
-
*/
|
|
169
|
-
__dotdirProviderReady?: FsProviderFactory;
|
|
170
|
-
/**
|
|
171
|
-
* Host API exposed to isolated extensions (iframe) as a global.
|
|
172
|
-
* Extensions can call `window.dotdir.readFile(...)`, etc.
|
|
173
|
-
*
|
|
174
|
-
* We'll later publish these typings via an npm package (`dotdir`).
|
|
175
|
-
*/
|
|
176
|
-
dotdir?: HostApi & {
|
|
177
|
-
commands?: {
|
|
178
|
-
registerCommand: (commandId: string, handler: (...args: unknown[]) => void | Promise<void>, options?: {
|
|
179
|
-
title?: string;
|
|
180
|
-
category?: string;
|
|
181
|
-
icon?: string;
|
|
182
|
-
}) => {
|
|
183
|
-
dispose: () => void;
|
|
184
|
-
};
|
|
185
|
-
registerKeybinding: (binding: {
|
|
186
|
-
command: string;
|
|
187
|
-
key: string;
|
|
188
|
-
mac?: string;
|
|
189
|
-
when?: string;
|
|
190
|
-
}) => {
|
|
191
|
-
dispose: () => void;
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}
|
|
1
|
+
export type { ColorThemeData, DotDirCommandsApi, DotDirGlobalApi, DotDirHostReadyCallback, EditorExtensionApi, EditorGrammarPayload, EditorLanguagePayload, EditorProps, FsProviderEntry, FsProviderExtensionApi, FsProviderFactory, FsProviderHostApi, HostApi, ViewerExtensionApi, ViewerProps, } from '../../../../../extension-api/dist/index.d.ts';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dotdirfm/ui",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Reusable DotDir file manager UI component for React apps.",
|
|
5
5
|
"main": "./dist/dotdir.js",
|
|
6
6
|
"module": "./dist/dotdir.mjs",
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"fss-lang": "^0.0.5",
|
|
52
52
|
"jotai": "^2.19.0",
|
|
53
53
|
"jsonc-parser": "^3.3.1",
|
|
54
|
-
"marked": "^17.0.5"
|
|
54
|
+
"marked": "^17.0.5",
|
|
55
|
+
"@dotdirfm/extension-api": "0.1.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"vite": "^8.0.0",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"scripts": {
|
|
61
62
|
"dev": "vite",
|
|
62
63
|
"watch": "vite build --watch",
|
|
63
|
-
"build": "tsc && vite build",
|
|
64
|
+
"build": "pnpm --filter @dotdirfm/extension-api build && tsc && vite build",
|
|
64
65
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
65
66
|
}
|
|
66
67
|
}
|