@bendyline/docblocks 0.1.0 → 1.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.
- package/LICENSE +21 -21
- package/dist/chunk-AOBPNSU6.js +23 -0
- package/dist/chunk-AOBPNSU6.js.map +1 -0
- package/dist/{chunk-NSVTXALR.js → chunk-OGJN2J4P.js} +218 -2
- package/dist/chunk-OGJN2J4P.js.map +1 -0
- package/dist/filesystem/electron-provider.d.ts +32 -0
- package/dist/filesystem/electron-provider.d.ts.map +1 -0
- package/dist/filesystem/electron-provider.js +64 -0
- package/dist/filesystem/electron-provider.js.map +1 -0
- package/dist/filesystem/file-media-provider.d.ts +23 -0
- package/dist/filesystem/file-media-provider.d.ts.map +1 -0
- package/dist/filesystem/file-media-provider.js +85 -0
- package/dist/filesystem/file-media-provider.js.map +1 -0
- package/dist/filesystem/filesystem-content-container.d.ts +24 -0
- package/dist/filesystem/filesystem-content-container.d.ts.map +1 -0
- package/dist/filesystem/filesystem-content-container.js +103 -0
- package/dist/filesystem/filesystem-content-container.js.map +1 -0
- package/dist/filesystem/index.d.ts +3 -0
- package/dist/filesystem/index.d.ts.map +1 -1
- package/dist/filesystem/index.js +3 -0
- package/dist/filesystem/index.js.map +1 -1
- package/dist/host/index.d.ts +14 -0
- package/dist/host/index.d.ts.map +1 -0
- package/dist/host/index.js +28 -0
- package/dist/host/index.js.map +1 -0
- package/dist/host/types.d.ts +149 -0
- package/dist/host/types.d.ts.map +1 -0
- package/dist/host/types.js +10 -0
- package/dist/host/types.js.map +1 -0
- package/dist/index-TtDaQ3vS.d.ts +213 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/workspace/types.d.ts +9 -2
- package/dist/workspace/types.d.ts.map +1 -1
- package/package.json +12 -7
- package/src/filesystem/electron-provider.ts +88 -0
- package/src/filesystem/file-media-provider.ts +103 -0
- package/src/filesystem/filesystem-content-container.ts +115 -0
- package/src/filesystem/index.ts +4 -0
- package/src/host/index.ts +47 -0
- package/src/host/types.ts +153 -0
- package/src/index.ts +2 -1
- package/src/workspace/types.ts +9 -2
- package/dist/chunk-NSVTXALR.js.map +0 -1
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileSystemProvider — abstract interface for a virtual filesystem.
|
|
3
|
+
*
|
|
4
|
+
* Implementations back onto IndexedDB (for browser-local storage) or
|
|
5
|
+
* the File System Access API (for native folder access).
|
|
6
|
+
*/
|
|
7
|
+
interface FileEntry {
|
|
8
|
+
kind: 'file';
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
}
|
|
12
|
+
interface FolderEntry {
|
|
13
|
+
kind: 'directory';
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
}
|
|
17
|
+
type FileSystemEntry = FileEntry | FolderEntry;
|
|
18
|
+
interface FileMeta {
|
|
19
|
+
name: string;
|
|
20
|
+
path: string;
|
|
21
|
+
size: number;
|
|
22
|
+
lastModified: string;
|
|
23
|
+
}
|
|
24
|
+
interface FileSystemProvider {
|
|
25
|
+
/** Unique identifier for this provider instance. */
|
|
26
|
+
readonly id: string;
|
|
27
|
+
/** Human-readable label (e.g., folder name or "Browser Storage"). */
|
|
28
|
+
readonly label: string;
|
|
29
|
+
/** Read the text content of a file. Returns null if the file doesn't exist. */
|
|
30
|
+
readFile(path: string): Promise<string | null>;
|
|
31
|
+
/** Write text content to a file, creating it (and parent dirs) if needed. */
|
|
32
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
33
|
+
/** Delete a file or empty directory. */
|
|
34
|
+
delete(path: string): Promise<void>;
|
|
35
|
+
/** Rename or move an entry. */
|
|
36
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
37
|
+
/** List immediate children of a directory. */
|
|
38
|
+
readDirectory(path: string): Promise<FileSystemEntry[]>;
|
|
39
|
+
/** Check whether a path exists. */
|
|
40
|
+
exists(path: string): Promise<boolean>;
|
|
41
|
+
/** Create a directory (and parents if needed). */
|
|
42
|
+
createDirectory(path: string): Promise<void>;
|
|
43
|
+
/** Get metadata for a file. Returns null if not found. */
|
|
44
|
+
stat(path: string): Promise<FileMeta | null>;
|
|
45
|
+
/** Read raw binary content. Returns null if not found. */
|
|
46
|
+
readBinary(path: string): Promise<ArrayBuffer | null>;
|
|
47
|
+
/** Write raw binary content. */
|
|
48
|
+
writeBinary(path: string, data: ArrayBuffer | Uint8Array): Promise<void>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* DocblocksHostAPI — the contract exposed by the Electron desktop shell
|
|
53
|
+
* to its renderer process via contextBridge.
|
|
54
|
+
*
|
|
55
|
+
* This file is the single source of truth for the host ↔ renderer
|
|
56
|
+
* bridge. The Electron preload script exposes an implementation matching
|
|
57
|
+
* this shape; the React renderer calls it through `window.docblocksHost`.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/** Filesystem operations scoped to a registered absolute root path. */
|
|
61
|
+
interface DocblocksHostFsAPI {
|
|
62
|
+
readFile(rootPath: string, path: string): Promise<string | null>;
|
|
63
|
+
writeFile(rootPath: string, path: string, content: string): Promise<void>;
|
|
64
|
+
delete(rootPath: string, path: string): Promise<void>;
|
|
65
|
+
rename(rootPath: string, oldPath: string, newPath: string): Promise<void>;
|
|
66
|
+
readDirectory(rootPath: string, path: string): Promise<FileSystemEntry[]>;
|
|
67
|
+
exists(rootPath: string, path: string): Promise<boolean>;
|
|
68
|
+
createDirectory(rootPath: string, path: string): Promise<void>;
|
|
69
|
+
stat(rootPath: string, path: string): Promise<FileMeta | null>;
|
|
70
|
+
readBinary(rootPath: string, path: string): Promise<ArrayBuffer | null>;
|
|
71
|
+
writeBinary(rootPath: string, path: string, data: ArrayBuffer | Uint8Array): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Subscribe to change notifications for a watched root. Returns an
|
|
74
|
+
* unsubscribe function. The main process uses chokidar under the hood.
|
|
75
|
+
*/
|
|
76
|
+
watch(rootPath: string, onChange: (path: string) => void): () => void;
|
|
77
|
+
}
|
|
78
|
+
/** Descriptor returned for an Electron-managed workspace (backed by a folder). */
|
|
79
|
+
interface ElectronWorkspaceInfo {
|
|
80
|
+
id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
rootPath: string;
|
|
83
|
+
}
|
|
84
|
+
/** Workspace-management operations exposed to the renderer. */
|
|
85
|
+
interface DocblocksHostWorkspacesAPI {
|
|
86
|
+
/**
|
|
87
|
+
* Return the default workspace (creating ~/Documents/DocBlocks on first
|
|
88
|
+
* call, or the user's configured default).
|
|
89
|
+
*/
|
|
90
|
+
getDefault(): Promise<ElectronWorkspaceInfo>;
|
|
91
|
+
/**
|
|
92
|
+
* Open the native folder picker. Returns null if the user cancels.
|
|
93
|
+
* The selected folder is registered in the main process whitelist.
|
|
94
|
+
*/
|
|
95
|
+
pickFolder(): Promise<ElectronWorkspaceInfo | null>;
|
|
96
|
+
/**
|
|
97
|
+
* Re-register a previously known workspace so its rootPath is trusted
|
|
98
|
+
* for subsequent fs calls. Called on app startup for persisted
|
|
99
|
+
* electron-native workspaces before any fs operation.
|
|
100
|
+
*/
|
|
101
|
+
register(info: ElectronWorkspaceInfo): Promise<void>;
|
|
102
|
+
/** Remove a workspace from the trusted whitelist. */
|
|
103
|
+
unregister(id: string): Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
/** Shell operations — reveal in Finder/Explorer, open external URLs. */
|
|
106
|
+
interface DocblocksHostShellAPI {
|
|
107
|
+
/** Reveal a file (by absolute path) in the OS file manager. */
|
|
108
|
+
revealInFolder(absolutePath: string): Promise<void>;
|
|
109
|
+
/** Open a URL in the default browser. */
|
|
110
|
+
openExternal(url: string): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
/** System ffmpeg detection and invocation. */
|
|
113
|
+
interface DocblocksHostFfmpegAPI {
|
|
114
|
+
/** True if `ffmpeg` is available on PATH (or bundled). */
|
|
115
|
+
available(): Promise<boolean>;
|
|
116
|
+
/** Version string from `ffmpeg -version`, or null if unavailable. */
|
|
117
|
+
version(): Promise<string | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Render a markdown file at the given absolute path to MP4 using the
|
|
120
|
+
* existing squisq-video CLI pipeline. Returns the absolute path to the
|
|
121
|
+
* produced MP4 file, or throws on failure.
|
|
122
|
+
*/
|
|
123
|
+
renderVideo(markdownAbsolutePath: string, options: {
|
|
124
|
+
fps?: number;
|
|
125
|
+
quality?: 'draft' | 'normal' | 'high';
|
|
126
|
+
}): Promise<string>;
|
|
127
|
+
}
|
|
128
|
+
/** Auto-updater control. */
|
|
129
|
+
interface DocblocksHostUpdaterAPI {
|
|
130
|
+
/** Kick off a check; resolves to true if an update is available. */
|
|
131
|
+
checkForUpdates(): Promise<boolean>;
|
|
132
|
+
/** Current app version string. */
|
|
133
|
+
getVersion(): Promise<string>;
|
|
134
|
+
/**
|
|
135
|
+
* Quit the app and apply a downloaded update. Should only be called
|
|
136
|
+
* after an `UpdaterStatus` of kind `'downloaded'` has been observed.
|
|
137
|
+
*/
|
|
138
|
+
quitAndInstall(): Promise<void>;
|
|
139
|
+
/**
|
|
140
|
+
* Subscribe to updater status events. Returns an unsubscribe function.
|
|
141
|
+
*/
|
|
142
|
+
onStatus(listener: (status: UpdaterStatus) => void): () => void;
|
|
143
|
+
}
|
|
144
|
+
type UpdaterStatus = {
|
|
145
|
+
kind: 'checking';
|
|
146
|
+
} | {
|
|
147
|
+
kind: 'available';
|
|
148
|
+
version: string;
|
|
149
|
+
releaseNotes?: string;
|
|
150
|
+
releaseUrl?: string;
|
|
151
|
+
} | {
|
|
152
|
+
kind: 'not-available';
|
|
153
|
+
} | {
|
|
154
|
+
kind: 'downloading';
|
|
155
|
+
percent: number;
|
|
156
|
+
} | {
|
|
157
|
+
kind: 'downloaded';
|
|
158
|
+
version: string;
|
|
159
|
+
releaseNotes?: string;
|
|
160
|
+
releaseUrl?: string;
|
|
161
|
+
} | {
|
|
162
|
+
kind: 'error';
|
|
163
|
+
message: string;
|
|
164
|
+
};
|
|
165
|
+
/** Menu-command events pushed from the main process to the renderer. */
|
|
166
|
+
type MenuCommand = 'file:new' | 'file:openFolder' | 'file:revealWorkspace' | 'file:settings' | 'help:about' | 'help:checkForUpdates' | 'help:viewOnGitHub';
|
|
167
|
+
/** Deep-link event: the user opened a docblocks:// URL or dropped a file. */
|
|
168
|
+
interface OpenRequest {
|
|
169
|
+
/** For docblocks:// URLs — the full URL string. */
|
|
170
|
+
url?: string;
|
|
171
|
+
/** For file drops / open-with — absolute path to the file. */
|
|
172
|
+
filePath?: string;
|
|
173
|
+
}
|
|
174
|
+
/** Environment metadata provided by the host. */
|
|
175
|
+
interface HostEnvironment {
|
|
176
|
+
platform: 'darwin' | 'win32' | 'linux';
|
|
177
|
+
appVersion: string;
|
|
178
|
+
isDev: boolean;
|
|
179
|
+
}
|
|
180
|
+
/** The full DocBlocks desktop host API. */
|
|
181
|
+
interface DocblocksHostAPI {
|
|
182
|
+
env: HostEnvironment;
|
|
183
|
+
fs: DocblocksHostFsAPI;
|
|
184
|
+
workspaces: DocblocksHostWorkspacesAPI;
|
|
185
|
+
shell: DocblocksHostShellAPI;
|
|
186
|
+
ffmpeg: DocblocksHostFfmpegAPI;
|
|
187
|
+
updater: DocblocksHostUpdaterAPI;
|
|
188
|
+
/**
|
|
189
|
+
* Subscribe to menu commands dispatched by the native menu.
|
|
190
|
+
* Returns an unsubscribe function.
|
|
191
|
+
*/
|
|
192
|
+
onMenuCommand(listener: (cmd: MenuCommand) => void): () => void;
|
|
193
|
+
/**
|
|
194
|
+
* Subscribe to open-file / open-url requests from the OS.
|
|
195
|
+
* Returns an unsubscribe function.
|
|
196
|
+
*/
|
|
197
|
+
onOpenRequest(listener: (request: OpenRequest) => void): () => void;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Host bridge — shared types + runtime access for the Electron desktop
|
|
202
|
+
* host. The renderer calls `getDocblocksHost()` to reach the preload
|
|
203
|
+
* contextBridge; `isElectronHost()` gates desktop-only UI branches.
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
/** True when running inside the Electron desktop shell. */
|
|
207
|
+
declare function isElectronHost(): boolean;
|
|
208
|
+
/** Return the host API, or throw if not running under Electron. */
|
|
209
|
+
declare function getDocblocksHost(): DocblocksHostAPI;
|
|
210
|
+
/** Return the host API, or null if not running under Electron. */
|
|
211
|
+
declare function maybeGetDocblocksHost(): DocblocksHostAPI | null;
|
|
212
|
+
|
|
213
|
+
export { type DocblocksHostAPI as D, type ElectronWorkspaceInfo as E, type FileEntry as F, type HostEnvironment as H, type MenuCommand as M, type OpenRequest as O, type UpdaterStatus as U, type DocblocksHostFfmpegAPI as a, type DocblocksHostFsAPI as b, type DocblocksHostShellAPI as c, type DocblocksHostUpdaterAPI as d, type DocblocksHostWorkspacesAPI as e, type FileMeta as f, type FileSystemEntry as g, type FileSystemProvider as h, type FolderEntry as i, getDocblocksHost as j, isElectronHost as k, maybeGetDocblocksHost as m };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @bendyline/docblocks — Core package
|
|
3
3
|
*
|
|
4
|
-
* Re-exports filesystem and
|
|
4
|
+
* Re-exports filesystem, workspace, and host modules for convenience.
|
|
5
5
|
*/
|
|
6
6
|
export * from './filesystem/index.js';
|
|
7
7
|
export * from './workspace/index.js';
|
|
8
|
+
export * from './host/index.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @bendyline/docblocks — Core package
|
|
3
3
|
*
|
|
4
|
-
* Re-exports filesystem and
|
|
4
|
+
* Re-exports filesystem, workspace, and host modules for convenience.
|
|
5
5
|
*/
|
|
6
6
|
export * from './filesystem/index.js';
|
|
7
7
|
export * from './workspace/index.js';
|
|
8
|
+
export * from './host/index.js';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC"}
|
|
@@ -7,9 +7,16 @@ export interface WorkspaceDescriptor {
|
|
|
7
7
|
id: string;
|
|
8
8
|
/** User-visible label. */
|
|
9
9
|
name: string;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Provider kind:
|
|
12
|
+
* - 'indexeddb' — browser-local storage (web only)
|
|
13
|
+
* - 'native' — File System Access API (web Chrome/Edge only)
|
|
14
|
+
* - 'electron-native' — Electron main-process native filesystem
|
|
15
|
+
*/
|
|
16
|
+
type: 'indexeddb' | 'native' | 'electron-native';
|
|
12
17
|
/** ISO timestamp of last access. */
|
|
13
18
|
lastOpened: string;
|
|
19
|
+
/** Absolute filesystem path for 'electron-native' workspaces. */
|
|
20
|
+
rootPath?: string;
|
|
14
21
|
}
|
|
15
22
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workspace/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workspace/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,IAAI,EAAE,WAAW,GAAG,QAAQ,GAAG,iBAAiB,CAAC;IACjD,oCAAoC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bendyline/docblocks",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Core data structures and filesystem abstractions for DocBlocks",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Bendyline",
|
|
@@ -42,6 +42,11 @@
|
|
|
42
42
|
"types": "./dist/workspace/index.d.ts",
|
|
43
43
|
"import": "./dist/workspace/index.js",
|
|
44
44
|
"default": "./dist/workspace/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./host": {
|
|
47
|
+
"types": "./dist/host/index.d.ts",
|
|
48
|
+
"import": "./dist/host/index.js",
|
|
49
|
+
"default": "./dist/host/index.js"
|
|
45
50
|
}
|
|
46
51
|
},
|
|
47
52
|
"scripts": {
|
|
@@ -49,11 +54,11 @@
|
|
|
49
54
|
"typecheck": "tsc --noEmit"
|
|
50
55
|
},
|
|
51
56
|
"dependencies": {
|
|
52
|
-
"@bendyline/squisq": "1.
|
|
53
|
-
"@bendyline/squisq-editor-react": "1.
|
|
54
|
-
"@bendyline/squisq-formats": "1.2.
|
|
55
|
-
"@bendyline/squisq-react": "1.
|
|
56
|
-
"@bendyline/squisq-video": "1.0.
|
|
57
|
-
"@bendyline/squisq-video-react": "1.0.
|
|
57
|
+
"@bendyline/squisq": "1.3.0",
|
|
58
|
+
"@bendyline/squisq-editor-react": "1.4.0",
|
|
59
|
+
"@bendyline/squisq-formats": "1.2.3",
|
|
60
|
+
"@bendyline/squisq-react": "1.2.0",
|
|
61
|
+
"@bendyline/squisq-video": "1.0.5",
|
|
62
|
+
"@bendyline/squisq-video-react": "1.0.5"
|
|
58
63
|
}
|
|
59
64
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ElectronFileSystemProvider — implements FileSystemProvider by delegating
|
|
3
|
+
* to the Electron desktop host's fs IPC bridge. Every operation is scoped
|
|
4
|
+
* to an absolute root path that the main process validates against a
|
|
5
|
+
* whitelist of registered workspace roots.
|
|
6
|
+
*
|
|
7
|
+
* This file has no Electron dependency — it is a pure IPC client that
|
|
8
|
+
* relies on the `docblocksHost` global installed by the preload script.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { FileSystemProvider, FileSystemEntry, FileMeta } from './types.js';
|
|
12
|
+
import { maybeGetDocblocksHost } from '../host/index.js';
|
|
13
|
+
import type { DocblocksHostFsAPI } from '../host/types.js';
|
|
14
|
+
|
|
15
|
+
export { isElectronHost } from '../host/index.js';
|
|
16
|
+
|
|
17
|
+
function getHostFs(): DocblocksHostFsAPI {
|
|
18
|
+
const host = maybeGetDocblocksHost();
|
|
19
|
+
if (!host) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
'ElectronFileSystemProvider: docblocksHost is not available — not running under Electron?',
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return host.fs;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class ElectronFileSystemProvider implements FileSystemProvider {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly label: string;
|
|
30
|
+
|
|
31
|
+
private readonly rootPath: string;
|
|
32
|
+
|
|
33
|
+
constructor(id: string, label: string, rootPath: string) {
|
|
34
|
+
this.id = id;
|
|
35
|
+
this.label = label;
|
|
36
|
+
this.rootPath = rootPath;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Absolute path this provider is rooted at. */
|
|
40
|
+
getRootPath(): string {
|
|
41
|
+
return this.rootPath;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
readFile(path: string): Promise<string | null> {
|
|
45
|
+
return getHostFs().readFile(this.rootPath, path);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
writeFile(path: string, content: string): Promise<void> {
|
|
49
|
+
return getHostFs().writeFile(this.rootPath, path, content);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
delete(path: string): Promise<void> {
|
|
53
|
+
return getHostFs().delete(this.rootPath, path);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
rename(oldPath: string, newPath: string): Promise<void> {
|
|
57
|
+
return getHostFs().rename(this.rootPath, oldPath, newPath);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
readDirectory(path: string): Promise<FileSystemEntry[]> {
|
|
61
|
+
return getHostFs().readDirectory(this.rootPath, path);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exists(path: string): Promise<boolean> {
|
|
65
|
+
return getHostFs().exists(this.rootPath, path);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
createDirectory(path: string): Promise<void> {
|
|
69
|
+
return getHostFs().createDirectory(this.rootPath, path);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
stat(path: string): Promise<FileMeta | null> {
|
|
73
|
+
return getHostFs().stat(this.rootPath, path);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
readBinary(path: string): Promise<ArrayBuffer | null> {
|
|
77
|
+
return getHostFs().readBinary(this.rootPath, path);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
writeBinary(path: string, data: ArrayBuffer | Uint8Array): Promise<void> {
|
|
81
|
+
return getHostFs().writeBinary(this.rootPath, path, data);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Subscribe to external change notifications under this root. */
|
|
85
|
+
watch(onChange: (changedPath: string) => void): () => void {
|
|
86
|
+
return getHostFs().watch(this.rootPath, onChange);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createFileMediaProvider — per-file media storage following the pandoc /
|
|
3
|
+
* Word convention: a markdown file `notes.md` gets a sibling folder
|
|
4
|
+
* `notes_files/` that holds its images, audio, and video.
|
|
5
|
+
*
|
|
6
|
+
* Given:
|
|
7
|
+
* • `container` — a ContentContainer scoped to the markdown file's
|
|
8
|
+
* parent directory (so `readFile('notes_files/image.png')` maps to the
|
|
9
|
+
* parent-relative path)
|
|
10
|
+
* • `markdownBasename` — e.g. `"notes.md"`
|
|
11
|
+
*
|
|
12
|
+
* Returns a MediaProvider that:
|
|
13
|
+
* • Writes new media under `{basename}_files/{name}` in the parent dir
|
|
14
|
+
* • Returns the folder-qualified path (`notes_files/image.png`) from
|
|
15
|
+
* addMedia so the markdown stays portable outside DocBlocks
|
|
16
|
+
* • Resolves both bare (`image.png`) and folder-qualified
|
|
17
|
+
* (`notes_files/image.png`) references — so legacy markdown and
|
|
18
|
+
* exports from other tools both work
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import type { MediaProvider, MediaEntry } from '@bendyline/squisq/schemas';
|
|
22
|
+
import type { ContentContainer } from '@bendyline/squisq/storage';
|
|
23
|
+
|
|
24
|
+
function stripExt(name: string): string {
|
|
25
|
+
return name.replace(/\.[^.]+$/, '');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createFileMediaProvider(
|
|
29
|
+
container: ContentContainer,
|
|
30
|
+
markdownBasename: string,
|
|
31
|
+
): MediaProvider {
|
|
32
|
+
const folder = stripExt(markdownBasename) + '_files';
|
|
33
|
+
const prefix = folder + '/';
|
|
34
|
+
const blobUrlCache = new Map<string, string>();
|
|
35
|
+
|
|
36
|
+
function toKey(ref: string): string {
|
|
37
|
+
const clean = ref.replace(/^\/+/, '');
|
|
38
|
+
return clean.startsWith(prefix) ? clean : prefix + clean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
async resolveUrl(ref: string): Promise<string> {
|
|
43
|
+
const key = toKey(ref);
|
|
44
|
+
const cached = blobUrlCache.get(key);
|
|
45
|
+
if (cached) return cached;
|
|
46
|
+
|
|
47
|
+
const data = await container.readFile(key);
|
|
48
|
+
if (!data) return ref;
|
|
49
|
+
|
|
50
|
+
const entries = await container.listFiles();
|
|
51
|
+
const entry = entries.find((e) => e.path === key);
|
|
52
|
+
const mimeType = entry?.mimeType ?? 'application/octet-stream';
|
|
53
|
+
|
|
54
|
+
const url = URL.createObjectURL(new Blob([data], { type: mimeType }));
|
|
55
|
+
blobUrlCache.set(key, url);
|
|
56
|
+
return url;
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
async listMedia(): Promise<MediaEntry[]> {
|
|
60
|
+
const entries = await container.listFiles(prefix);
|
|
61
|
+
return entries
|
|
62
|
+
.filter((e) => !e.path.toLowerCase().endsWith('.md'))
|
|
63
|
+
.map((e) => ({
|
|
64
|
+
name: e.path,
|
|
65
|
+
mimeType: e.mimeType,
|
|
66
|
+
size: e.size,
|
|
67
|
+
}));
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
async addMedia(
|
|
71
|
+
name: string,
|
|
72
|
+
data: ArrayBuffer | Blob | Uint8Array,
|
|
73
|
+
mimeType: string,
|
|
74
|
+
): Promise<string> {
|
|
75
|
+
const key = toKey(name);
|
|
76
|
+
const cached = blobUrlCache.get(key);
|
|
77
|
+
if (cached) {
|
|
78
|
+
URL.revokeObjectURL(cached);
|
|
79
|
+
blobUrlCache.delete(key);
|
|
80
|
+
}
|
|
81
|
+
const buffer = data instanceof Blob ? new Uint8Array(await data.arrayBuffer()) : data;
|
|
82
|
+
await container.writeFile(key, buffer, mimeType);
|
|
83
|
+
return key;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
async removeMedia(ref: string): Promise<void> {
|
|
87
|
+
const key = toKey(ref);
|
|
88
|
+
const cached = blobUrlCache.get(key);
|
|
89
|
+
if (cached) {
|
|
90
|
+
URL.revokeObjectURL(cached);
|
|
91
|
+
blobUrlCache.delete(key);
|
|
92
|
+
}
|
|
93
|
+
await container.removeFile(key);
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
dispose(): void {
|
|
97
|
+
for (const url of blobUrlCache.values()) {
|
|
98
|
+
URL.revokeObjectURL(url);
|
|
99
|
+
}
|
|
100
|
+
blobUrlCache.clear();
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileSystemContentContainer — a ContentContainer backed by any
|
|
3
|
+
* FileSystemProvider, scoped to a sub-path (e.g., ".docblocks/media/").
|
|
4
|
+
*
|
|
5
|
+
* Used by the Electron desktop app so media lives inside the workspace
|
|
6
|
+
* folder (visible as regular files) rather than in a separate IndexedDB
|
|
7
|
+
* origin that only the app can see.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { ContentContainer, ContentEntry } from '@bendyline/squisq/storage';
|
|
11
|
+
import { findDocumentPath } from '@bendyline/squisq/storage';
|
|
12
|
+
import type { FileSystemProvider } from './types.js';
|
|
13
|
+
|
|
14
|
+
const EXTENSION_MIME_MAP: Record<string, string> = {
|
|
15
|
+
'.md': 'text/markdown',
|
|
16
|
+
'.txt': 'text/plain',
|
|
17
|
+
'.json': 'application/json',
|
|
18
|
+
'.jpg': 'image/jpeg',
|
|
19
|
+
'.jpeg': 'image/jpeg',
|
|
20
|
+
'.png': 'image/png',
|
|
21
|
+
'.gif': 'image/gif',
|
|
22
|
+
'.svg': 'image/svg+xml',
|
|
23
|
+
'.webp': 'image/webp',
|
|
24
|
+
'.avif': 'image/avif',
|
|
25
|
+
'.mp4': 'video/mp4',
|
|
26
|
+
'.webm': 'video/webm',
|
|
27
|
+
'.mp3': 'audio/mpeg',
|
|
28
|
+
'.wav': 'audio/wav',
|
|
29
|
+
'.ogg': 'audio/ogg',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function guessMimeType(path: string): string {
|
|
33
|
+
const dot = path.lastIndexOf('.');
|
|
34
|
+
if (dot === -1) return 'application/octet-stream';
|
|
35
|
+
const ext = path.slice(dot).toLowerCase();
|
|
36
|
+
return EXTENSION_MIME_MAP[ext] ?? 'application/octet-stream';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function joinPrefix(prefix: string, p: string): string {
|
|
40
|
+
const clean = p.replace(/^\/+/, '');
|
|
41
|
+
return prefix.replace(/\/+$/, '') + '/' + clean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class FileSystemContentContainer implements ContentContainer {
|
|
45
|
+
private readonly prefix: string;
|
|
46
|
+
|
|
47
|
+
constructor(
|
|
48
|
+
private readonly provider: FileSystemProvider,
|
|
49
|
+
prefix = '.docblocks/media',
|
|
50
|
+
) {
|
|
51
|
+
this.prefix = prefix.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async readFile(path: string): Promise<ArrayBuffer | null> {
|
|
55
|
+
return this.provider.readBinary(joinPrefix(this.prefix, path));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async writeFile(path: string, data: ArrayBuffer | Uint8Array, _mimeType?: string): Promise<void> {
|
|
59
|
+
await this.provider.writeBinary(joinPrefix(this.prefix, path), data);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async removeFile(path: string): Promise<void> {
|
|
63
|
+
await this.provider.delete(joinPrefix(this.prefix, path));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async listFiles(prefix?: string): Promise<ContentEntry[]> {
|
|
67
|
+
const entries: ContentEntry[] = [];
|
|
68
|
+
const walk = async (dir: string) => {
|
|
69
|
+
let children;
|
|
70
|
+
try {
|
|
71
|
+
children = await this.provider.readDirectory(dir);
|
|
72
|
+
} catch {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
for (const child of children) {
|
|
76
|
+
if (child.kind === 'directory') {
|
|
77
|
+
await walk(child.path);
|
|
78
|
+
} else {
|
|
79
|
+
const rel = child.path.replace(new RegExp('^/?' + this.prefix + '/?'), '');
|
|
80
|
+
if (prefix && !rel.startsWith(prefix)) continue;
|
|
81
|
+
const meta = await this.provider.stat(child.path);
|
|
82
|
+
entries.push({
|
|
83
|
+
path: rel,
|
|
84
|
+
mimeType: guessMimeType(rel),
|
|
85
|
+
size: meta?.size ?? 0,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
await walk('/' + this.prefix);
|
|
91
|
+
return entries;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async exists(path: string): Promise<boolean> {
|
|
95
|
+
return this.provider.exists(joinPrefix(this.prefix, path));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async getDocumentPath(): Promise<string | null> {
|
|
99
|
+
return findDocumentPath(await this.listFiles());
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async readDocument(): Promise<string | null> {
|
|
103
|
+
const docPath = await this.getDocumentPath();
|
|
104
|
+
if (!docPath) return null;
|
|
105
|
+
const data = await this.readFile(docPath);
|
|
106
|
+
if (!data) return null;
|
|
107
|
+
return new TextDecoder().decode(data);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async writeDocument(markdown: string, filename?: string): Promise<void> {
|
|
111
|
+
const name = filename ?? 'index.md';
|
|
112
|
+
const data = new TextEncoder().encode(markdown);
|
|
113
|
+
await this.writeFile(name, data, 'text/markdown');
|
|
114
|
+
}
|
|
115
|
+
}
|
package/src/filesystem/index.ts
CHANGED
|
@@ -8,6 +8,8 @@ export type {
|
|
|
8
8
|
|
|
9
9
|
export { IndexedDBFileSystemProvider } from './indexeddb-provider.js';
|
|
10
10
|
export { IndexedDBContentContainer } from './indexeddb-content-container.js';
|
|
11
|
+
export { FileSystemContentContainer } from './filesystem-content-container.js';
|
|
12
|
+
export { createFileMediaProvider } from './file-media-provider.js';
|
|
11
13
|
|
|
12
14
|
export {
|
|
13
15
|
NativeFileSystemProvider,
|
|
@@ -18,3 +20,5 @@ export {
|
|
|
18
20
|
loadDirectoryHandle,
|
|
19
21
|
removeDirectoryHandle,
|
|
20
22
|
} from './native-provider.js';
|
|
23
|
+
|
|
24
|
+
export { ElectronFileSystemProvider, isElectronHost } from './electron-provider.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host bridge — shared types + runtime access for the Electron desktop
|
|
3
|
+
* host. The renderer calls `getDocblocksHost()` to reach the preload
|
|
4
|
+
* contextBridge; `isElectronHost()` gates desktop-only UI branches.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type {
|
|
8
|
+
DocblocksHostAPI,
|
|
9
|
+
DocblocksHostFsAPI,
|
|
10
|
+
DocblocksHostWorkspacesAPI,
|
|
11
|
+
DocblocksHostShellAPI,
|
|
12
|
+
DocblocksHostFfmpegAPI,
|
|
13
|
+
DocblocksHostUpdaterAPI,
|
|
14
|
+
ElectronWorkspaceInfo,
|
|
15
|
+
HostEnvironment,
|
|
16
|
+
MenuCommand,
|
|
17
|
+
OpenRequest,
|
|
18
|
+
UpdaterStatus,
|
|
19
|
+
} from './types.js';
|
|
20
|
+
|
|
21
|
+
import type { DocblocksHostAPI } from './types.js';
|
|
22
|
+
|
|
23
|
+
/** True when running inside the Electron desktop shell. */
|
|
24
|
+
export function isElectronHost(): boolean {
|
|
25
|
+
if (typeof globalThis === 'undefined') return false;
|
|
26
|
+
const host = (globalThis as { docblocksHost?: unknown }).docblocksHost;
|
|
27
|
+
return (
|
|
28
|
+
typeof host === 'object' &&
|
|
29
|
+
host !== null &&
|
|
30
|
+
typeof (host as { fs?: unknown }).fs === 'object' &&
|
|
31
|
+
(host as { fs?: unknown }).fs !== null
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Return the host API, or throw if not running under Electron. */
|
|
36
|
+
export function getDocblocksHost(): DocblocksHostAPI {
|
|
37
|
+
const host = (globalThis as { docblocksHost?: DocblocksHostAPI }).docblocksHost;
|
|
38
|
+
if (!host) {
|
|
39
|
+
throw new Error('docblocksHost is not available — not running under Electron?');
|
|
40
|
+
}
|
|
41
|
+
return host;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Return the host API, or null if not running under Electron. */
|
|
45
|
+
export function maybeGetDocblocksHost(): DocblocksHostAPI | null {
|
|
46
|
+
return (globalThis as { docblocksHost?: DocblocksHostAPI }).docblocksHost ?? null;
|
|
47
|
+
}
|