@bendyline/docblocks-react 2.0.0 → 2.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/README.md +6 -0
- package/dist/{ExportDialog-MEUISWZX.js → ExportDialog-7LDIXJZ3.js} +3 -2
- package/dist/{ExportToolbarControls-D2YDWOXW.js → ExportToolbarControls-GHAOJMH6.js} +147 -12
- package/dist/ExportToolbarControls-GHAOJMH6.js.map +1 -0
- package/dist/{GitToolbarControl-LMIR4R7I.js → GitToolbarControl-GNMRVKWQ.js} +62 -43
- package/dist/GitToolbarControl-GNMRVKWQ.js.map +1 -0
- package/dist/{GitUI-KGF5MSNV.js → GitUI-VHOBQY43.js} +225 -140
- package/dist/GitUI-VHOBQY43.js.map +1 -0
- package/dist/ShareDialog-63ENBEDZ.js +213 -0
- package/dist/ShareDialog-63ENBEDZ.js.map +1 -0
- package/dist/chunk-57ZJJOC5.js +89 -0
- package/dist/chunk-57ZJJOC5.js.map +1 -0
- package/dist/chunk-FEWQUQML.js +256 -0
- package/dist/chunk-FEWQUQML.js.map +1 -0
- package/dist/chunk-FMGTHSTX.js +110 -0
- package/dist/chunk-FMGTHSTX.js.map +1 -0
- package/dist/chunk-UNYZQXWR.js +324 -0
- package/dist/chunk-UNYZQXWR.js.map +1 -0
- package/dist/editor.d.ts +5 -4
- package/dist/editor.js +8 -69
- package/dist/editor.js.map +1 -1
- package/dist/export/index.d.ts +7 -1
- package/dist/export/index.js +2 -1
- package/dist/index.d.ts +346 -21
- package/dist/index.js +6169 -20
- package/dist/index.js.map +1 -1
- package/dist/settings/index.d.ts +9 -1
- package/dist/settings/index.js +6 -4
- package/package.json +18 -13
- package/src/styles/docblocks.css +537 -26
- package/dist/AppMenu/AppMenu.d.ts +0 -53
- package/dist/AppMenu/AppMenu.d.ts.map +0 -1
- package/dist/AppMenu/AppMenu.js +0 -67
- package/dist/AppMenu/AppMenu.js.map +0 -1
- package/dist/AppMenu/index.d.ts +0 -3
- package/dist/AppMenu/index.d.ts.map +0 -1
- package/dist/AppMenu/index.js +0 -2
- package/dist/AppMenu/index.js.map +0 -1
- package/dist/DocBlocksShell/DocBlocksShell.d.ts +0 -49
- package/dist/DocBlocksShell/DocBlocksShell.d.ts.map +0 -1
- package/dist/DocBlocksShell/DocBlocksShell.js +0 -2730
- package/dist/DocBlocksShell/DocBlocksShell.js.map +0 -1
- package/dist/DocBlocksShell/LazyEditorShell.d.ts +0 -3
- package/dist/DocBlocksShell/LazyEditorShell.d.ts.map +0 -1
- package/dist/DocBlocksShell/LazyEditorShell.js +0 -3
- package/dist/DocBlocksShell/LazyEditorShell.js.map +0 -1
- package/dist/DocBlocksShell/UpdateAvailableNotice.d.ts +0 -13
- package/dist/DocBlocksShell/UpdateAvailableNotice.d.ts.map +0 -1
- package/dist/DocBlocksShell/UpdateAvailableNotice.js +0 -16
- package/dist/DocBlocksShell/UpdateAvailableNotice.js.map +0 -1
- package/dist/DocBlocksShell/document-title.d.ts +0 -3
- package/dist/DocBlocksShell/document-title.d.ts.map +0 -1
- package/dist/DocBlocksShell/document-title.js +0 -17
- package/dist/DocBlocksShell/document-title.js.map +0 -1
- package/dist/DocBlocksShell/index.d.ts +0 -3
- package/dist/DocBlocksShell/index.d.ts.map +0 -1
- package/dist/DocBlocksShell/index.js +0 -2
- package/dist/DocBlocksShell/index.js.map +0 -1
- package/dist/DocBlocksShell/workspace-authority-barrier.d.ts +0 -14
- package/dist/DocBlocksShell/workspace-authority-barrier.d.ts.map +0 -1
- package/dist/DocBlocksShell/workspace-authority-barrier.js +0 -23
- package/dist/DocBlocksShell/workspace-authority-barrier.js.map +0 -1
- package/dist/Export/DeferredExportToolbarControls.d.ts +0 -5
- package/dist/Export/DeferredExportToolbarControls.d.ts.map +0 -1
- package/dist/Export/DeferredExportToolbarControls.js +0 -10
- package/dist/Export/DeferredExportToolbarControls.js.map +0 -1
- package/dist/Export/ExportDialog.d.ts +0 -25
- package/dist/Export/ExportDialog.d.ts.map +0 -1
- package/dist/Export/ExportDialog.js +0 -160
- package/dist/Export/ExportDialog.js.map +0 -1
- package/dist/Export/ExportToolbarControls.d.ts +0 -37
- package/dist/Export/ExportToolbarControls.d.ts.map +0 -1
- package/dist/Export/ExportToolbarControls.js +0 -285
- package/dist/Export/ExportToolbarControls.js.map +0 -1
- package/dist/Export/export-destination.d.ts +0 -3
- package/dist/Export/export-destination.d.ts.map +0 -1
- package/dist/Export/export-destination.js +0 -32
- package/dist/Export/export-destination.js.map +0 -1
- package/dist/Export/export-options.d.ts +0 -53
- package/dist/Export/export-options.d.ts.map +0 -1
- package/dist/Export/export-options.js +0 -49
- package/dist/Export/export-options.js.map +0 -1
- package/dist/Export/index.d.ts +0 -10
- package/dist/Export/index.d.ts.map +0 -1
- package/dist/Export/index.js +0 -6
- package/dist/Export/index.js.map +0 -1
- package/dist/Export/public-api.d.ts +0 -12
- package/dist/Export/public-api.d.ts.map +0 -1
- package/dist/Export/public-api.js +0 -9
- package/dist/Export/public-api.js.map +0 -1
- package/dist/Export/run-export.d.ts +0 -10
- package/dist/Export/run-export.d.ts.map +0 -1
- package/dist/Export/run-export.js +0 -313
- package/dist/Export/run-export.js.map +0 -1
- package/dist/Export/transform-summaries.d.ts +0 -7
- package/dist/Export/transform-summaries.d.ts.map +0 -1
- package/dist/Export/transform-summaries.js +0 -6
- package/dist/Export/transform-summaries.js.map +0 -1
- package/dist/ExportToolbarControls-D2YDWOXW.js.map +0 -1
- package/dist/FileExplorer/FileExplorer.d.ts +0 -43
- package/dist/FileExplorer/FileExplorer.d.ts.map +0 -1
- package/dist/FileExplorer/FileExplorer.js +0 -315
- package/dist/FileExplorer/FileExplorer.js.map +0 -1
- package/dist/FileExplorer/FileTreeNode.d.ts +0 -39
- package/dist/FileExplorer/FileTreeNode.d.ts.map +0 -1
- package/dist/FileExplorer/FileTreeNode.js +0 -131
- package/dist/FileExplorer/FileTreeNode.js.map +0 -1
- package/dist/FileExplorer/index.d.ts +0 -6
- package/dist/FileExplorer/index.d.ts.map +0 -1
- package/dist/FileExplorer/index.js +0 -4
- package/dist/FileExplorer/index.js.map +0 -1
- package/dist/FileExplorer/useFileTree.d.ts +0 -37
- package/dist/FileExplorer/useFileTree.d.ts.map +0 -1
- package/dist/FileExplorer/useFileTree.js +0 -284
- package/dist/FileExplorer/useFileTree.js.map +0 -1
- package/dist/Git/GitAuthGuidanceDialog.d.ts +0 -18
- package/dist/Git/GitAuthGuidanceDialog.d.ts.map +0 -1
- package/dist/Git/GitAuthGuidanceDialog.js +0 -27
- package/dist/Git/GitAuthGuidanceDialog.js.map +0 -1
- package/dist/Git/GitBranchesDialog.d.ts +0 -13
- package/dist/Git/GitBranchesDialog.d.ts.map +0 -1
- package/dist/Git/GitBranchesDialog.js +0 -59
- package/dist/Git/GitBranchesDialog.js.map +0 -1
- package/dist/Git/GitCloneDialog.d.ts +0 -14
- package/dist/Git/GitCloneDialog.d.ts.map +0 -1
- package/dist/Git/GitCloneDialog.js +0 -79
- package/dist/Git/GitCloneDialog.js.map +0 -1
- package/dist/Git/GitCommitDialog.d.ts +0 -12
- package/dist/Git/GitCommitDialog.d.ts.map +0 -1
- package/dist/Git/GitCommitDialog.js +0 -38
- package/dist/Git/GitCommitDialog.js.map +0 -1
- package/dist/Git/GitConflictsDialog.d.ts +0 -12
- package/dist/Git/GitConflictsDialog.d.ts.map +0 -1
- package/dist/Git/GitConflictsDialog.js +0 -17
- package/dist/Git/GitConflictsDialog.js.map +0 -1
- package/dist/Git/GitContext.d.ts +0 -89
- package/dist/Git/GitContext.d.ts.map +0 -1
- package/dist/Git/GitContext.js +0 -15
- package/dist/Git/GitContext.js.map +0 -1
- package/dist/Git/GitDiffDialog.d.ts +0 -20
- package/dist/Git/GitDiffDialog.d.ts.map +0 -1
- package/dist/Git/GitDiffDialog.js +0 -100
- package/dist/Git/GitDiffDialog.js.map +0 -1
- package/dist/Git/GitDiffView.d.ts +0 -23
- package/dist/Git/GitDiffView.d.ts.map +0 -1
- package/dist/Git/GitDiffView.js +0 -77
- package/dist/Git/GitDiffView.js.map +0 -1
- package/dist/Git/GitHistoryDialog.d.ts +0 -15
- package/dist/Git/GitHistoryDialog.d.ts.map +0 -1
- package/dist/Git/GitHistoryDialog.js +0 -107
- package/dist/Git/GitHistoryDialog.js.map +0 -1
- package/dist/Git/GitStatusBar.d.ts +0 -8
- package/dist/Git/GitStatusBar.d.ts.map +0 -1
- package/dist/Git/GitStatusBar.js +0 -49
- package/dist/Git/GitStatusBar.js.map +0 -1
- package/dist/Git/GitToolbarControl.d.ts +0 -15
- package/dist/Git/GitToolbarControl.d.ts.map +0 -1
- package/dist/Git/GitToolbarControl.js +0 -51
- package/dist/Git/GitToolbarControl.js.map +0 -1
- package/dist/Git/GitUI.d.ts +0 -14
- package/dist/Git/GitUI.d.ts.map +0 -1
- package/dist/Git/GitUI.js +0 -21
- package/dist/Git/GitUI.js.map +0 -1
- package/dist/Git/commit-selection.d.ts +0 -22
- package/dist/Git/commit-selection.d.ts.map +0 -1
- package/dist/Git/commit-selection.js +0 -47
- package/dist/Git/commit-selection.js.map +0 -1
- package/dist/Git/git-clone-utils.d.ts +0 -8
- package/dist/Git/git-clone-utils.d.ts.map +0 -1
- package/dist/Git/git-clone-utils.js +0 -26
- package/dist/Git/git-clone-utils.js.map +0 -1
- package/dist/Git/git-status.d.ts +0 -24
- package/dist/Git/git-status.d.ts.map +0 -1
- package/dist/Git/git-status.js +0 -105
- package/dist/Git/git-status.js.map +0 -1
- package/dist/Git/useGit.d.ts +0 -15
- package/dist/Git/useGit.d.ts.map +0 -1
- package/dist/Git/useGit.js +0 -206
- package/dist/Git/useGit.js.map +0 -1
- package/dist/Git/useGitStatus.d.ts +0 -17
- package/dist/Git/useGitStatus.d.ts.map +0 -1
- package/dist/Git/useGitStatus.js +0 -63
- package/dist/Git/useGitStatus.js.map +0 -1
- package/dist/GitToolbarControl-LMIR4R7I.js.map +0 -1
- package/dist/GitUI-KGF5MSNV.js.map +0 -1
- package/dist/Settings/Settings.d.ts +0 -23
- package/dist/Settings/Settings.d.ts.map +0 -1
- package/dist/Settings/Settings.js +0 -22
- package/dist/Settings/Settings.js.map +0 -1
- package/dist/Settings/public-api.d.ts +0 -3
- package/dist/Settings/public-api.d.ts.map +0 -1
- package/dist/Settings/public-api.js +0 -2
- package/dist/Settings/public-api.js.map +0 -1
- package/dist/WorkspacePicker/WorkspacePicker.d.ts +0 -22
- package/dist/WorkspacePicker/WorkspacePicker.d.ts.map +0 -1
- package/dist/WorkspacePicker/WorkspacePicker.js +0 -74
- package/dist/WorkspacePicker/WorkspacePicker.js.map +0 -1
- package/dist/WorkspacePicker/WorkspaceSettingsButton.d.ts +0 -11
- package/dist/WorkspacePicker/WorkspaceSettingsButton.d.ts.map +0 -1
- package/dist/WorkspacePicker/WorkspaceSettingsButton.js +0 -27
- package/dist/WorkspacePicker/WorkspaceSettingsButton.js.map +0 -1
- package/dist/WorkspacePicker/WorkspaceSettingsDialog.d.ts +0 -20
- package/dist/WorkspacePicker/WorkspaceSettingsDialog.d.ts.map +0 -1
- package/dist/WorkspacePicker/WorkspaceSettingsDialog.js +0 -36
- package/dist/WorkspacePicker/WorkspaceSettingsDialog.js.map +0 -1
- package/dist/WorkspacePicker/index.d.ts +0 -3
- package/dist/WorkspacePicker/index.d.ts.map +0 -1
- package/dist/WorkspacePicker/index.js +0 -2
- package/dist/WorkspacePicker/index.js.map +0 -1
- package/dist/chunk-3SAXDU2U.js +0 -157
- package/dist/chunk-3SAXDU2U.js.map +0 -1
- package/dist/chunk-AOVTHZU7.js +0 -321
- package/dist/chunk-AOVTHZU7.js.map +0 -1
- package/dist/chunk-GSNZSCIK.js +0 -55
- package/dist/chunk-GSNZSCIK.js.map +0 -1
- package/dist/components/Dialog.d.ts +0 -22
- package/dist/components/Dialog.d.ts.map +0 -1
- package/dist/components/Dialog.js +0 -33
- package/dist/components/Dialog.js.map +0 -1
- package/dist/editor.d.ts.map +0 -1
- package/dist/hooks/index.d.ts +0 -3
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -2
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useDocumentSession.d.ts +0 -16
- package/dist/hooks/useDocumentSession.d.ts.map +0 -1
- package/dist/hooks/useDocumentSession.js +0 -18
- package/dist/hooks/useDocumentSession.js.map +0 -1
- package/dist/icons.d.ts +0 -12
- package/dist/icons.d.ts.map +0 -1
- package/dist/icons.js +0 -28
- package/dist/icons.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/preferences/theme.d.ts +0 -18
- package/dist/preferences/theme.d.ts.map +0 -1
- package/dist/preferences/theme.js +0 -63
- package/dist/preferences/theme.js.map +0 -1
- package/dist/preferences/versioning.d.ts +0 -27
- package/dist/preferences/versioning.d.ts.map +0 -1
- package/dist/preferences/versioning.js +0 -62
- package/dist/preferences/versioning.js.map +0 -1
- package/dist/provider-lease.d.ts +0 -10
- package/dist/provider-lease.d.ts.map +0 -1
- package/dist/provider-lease.js +0 -42
- package/dist/provider-lease.js.map +0 -1
- package/src/AppMenu/AppMenu.tsx +0 -334
- package/src/AppMenu/index.ts +0 -2
- package/src/DocBlocksShell/DocBlocksShell.tsx +0 -3398
- package/src/DocBlocksShell/LazyEditorShell.ts +0 -2
- package/src/DocBlocksShell/UpdateAvailableNotice.tsx +0 -60
- package/src/DocBlocksShell/document-title.ts +0 -19
- package/src/DocBlocksShell/index.ts +0 -2
- package/src/DocBlocksShell/workspace-authority-barrier.ts +0 -26
- package/src/Export/DeferredExportToolbarControls.tsx +0 -23
- package/src/Export/ExportDialog.tsx +0 -437
- package/src/Export/ExportToolbarControls.tsx +0 -511
- package/src/Export/export-destination.ts +0 -30
- package/src/Export/export-options.ts +0 -99
- package/src/Export/index.ts +0 -19
- package/src/Export/public-api.ts +0 -17
- package/src/Export/run-export.ts +0 -374
- package/src/Export/transform-summaries.ts +0 -14
- package/src/FileExplorer/FileExplorer.tsx +0 -528
- package/src/FileExplorer/FileTreeNode.tsx +0 -306
- package/src/FileExplorer/index.ts +0 -5
- package/src/FileExplorer/useFileTree.ts +0 -352
- package/src/Git/GitAuthGuidanceDialog.tsx +0 -84
- package/src/Git/GitBranchesDialog.tsx +0 -144
- package/src/Git/GitCloneDialog.tsx +0 -200
- package/src/Git/GitCommitDialog.tsx +0 -119
- package/src/Git/GitConflictsDialog.tsx +0 -62
- package/src/Git/GitContext.tsx +0 -88
- package/src/Git/GitDiffDialog.tsx +0 -147
- package/src/Git/GitDiffView.tsx +0 -105
- package/src/Git/GitHistoryDialog.tsx +0 -195
- package/src/Git/GitStatusBar.tsx +0 -157
- package/src/Git/GitToolbarControl.tsx +0 -123
- package/src/Git/GitUI.tsx +0 -68
- package/src/Git/commit-selection.ts +0 -63
- package/src/Git/git-clone-utils.ts +0 -23
- package/src/Git/git-status.ts +0 -113
- package/src/Git/useGit.ts +0 -279
- package/src/Git/useGitStatus.ts +0 -78
- package/src/Settings/Settings.tsx +0 -118
- package/src/Settings/public-api.ts +0 -8
- package/src/WorkspacePicker/WorkspacePicker.tsx +0 -191
- package/src/WorkspacePicker/WorkspaceSettingsButton.tsx +0 -88
- package/src/WorkspacePicker/WorkspaceSettingsDialog.tsx +0 -121
- package/src/WorkspacePicker/index.ts +0 -2
- package/src/components/Dialog.tsx +0 -81
- package/src/editor.ts +0 -72
- package/src/hooks/index.ts +0 -2
- package/src/hooks/useDocumentSession.ts +0 -37
- package/src/icons.tsx +0 -48
- package/src/index.ts +0 -61
- package/src/preferences/theme.ts +0 -67
- package/src/preferences/versioning.ts +0 -69
- package/src/provider-lease.ts +0 -52
- package/src/types/pwa-dom.d.ts +0 -31
- /package/dist/{ExportDialog-MEUISWZX.js.map → ExportDialog-7LDIXJZ3.js.map} +0 -0
|
@@ -1,528 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FileExplorer — tree component rendering FileSystemProvider contents.
|
|
3
|
-
*
|
|
4
|
-
* Shows a file/folder tree with expand/collapse, selection, and a toolbar
|
|
5
|
-
* for creating new files/folders.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
9
|
-
import {
|
|
10
|
-
isFileSystemMoveStateError,
|
|
11
|
-
parseWorkspacePath,
|
|
12
|
-
type FileSystemProvider,
|
|
13
|
-
type FileSystemEntry,
|
|
14
|
-
} from '@bendyline/docblocks/filesystem';
|
|
15
|
-
import { useFileTree } from './useFileTree.js';
|
|
16
|
-
import {
|
|
17
|
-
FileTreeNode,
|
|
18
|
-
type FileTreeNodeBadge,
|
|
19
|
-
type FileTreeNodeGitActions,
|
|
20
|
-
} from './FileTreeNode.js';
|
|
21
|
-
import { NewFileIcon, NewFolderIcon } from '../icons.js';
|
|
22
|
-
import { useGitContext } from '../Git/GitContext.js';
|
|
23
|
-
import { BADGE_GLYPHS, BADGE_LABELS, isFileDirty } from '../Git/git-status.js';
|
|
24
|
-
|
|
25
|
-
const SUPPORTED_EXTENSIONS = new Set(['.txt', '.md', '.docx', '.pdf', '.dbk', '.zip']);
|
|
26
|
-
const INTERNAL_DRAG_TYPE = 'application/x-docblocks-entry';
|
|
27
|
-
|
|
28
|
-
export type FileTreeChange =
|
|
29
|
-
| { type: 'create'; path: string; kind?: 'file' | 'directory' }
|
|
30
|
-
| { type: 'delete'; path: string; kind: 'file' | 'directory' }
|
|
31
|
-
| {
|
|
32
|
-
type: 'move';
|
|
33
|
-
oldPath: string;
|
|
34
|
-
newPath: string;
|
|
35
|
-
kind: 'file' | 'directory';
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type FileTreeMutationHandler = (
|
|
39
|
-
change: FileTreeChange,
|
|
40
|
-
mutate: () => Promise<void>,
|
|
41
|
-
) => Promise<void>;
|
|
42
|
-
|
|
43
|
-
function normalisePath(path: string): string {
|
|
44
|
-
return parseWorkspacePath(path);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function hasEquivalentPath(paths: ReadonlySet<string>, path: string): boolean {
|
|
48
|
-
const canonical = normalisePath(path);
|
|
49
|
-
return (
|
|
50
|
-
paths.has(path) || paths.has(canonical) || (canonical !== '' && paths.has(`/${canonical}`))
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getEquivalentPathValue<T>(values: ReadonlyMap<string, T>, path: string): T | undefined {
|
|
55
|
-
const canonical = normalisePath(path);
|
|
56
|
-
return values.get(path) ?? values.get(canonical) ?? values.get(`/${canonical}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function parentPath(path: string): string {
|
|
60
|
-
const clean = normalisePath(path);
|
|
61
|
-
const slash = clean.lastIndexOf('/');
|
|
62
|
-
return slash < 0 ? '' : clean.slice(0, slash);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function pathInDirectory(entry: FileSystemEntry, directoryPath: string): string {
|
|
66
|
-
const prefix = directoryPath.replace(/\/+$/, '');
|
|
67
|
-
if (prefix) return `${prefix}/${entry.name}`;
|
|
68
|
-
return entry.path.startsWith('/') ? `/${entry.name}` : entry.name;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function canMoveTo(entry: FileSystemEntry, directoryPath: string): boolean {
|
|
72
|
-
const source = normalisePath(entry.path);
|
|
73
|
-
const target = normalisePath(directoryPath);
|
|
74
|
-
if (parentPath(source) === target) return false;
|
|
75
|
-
if (entry.kind === 'directory' && (target === source || target.startsWith(`${source}/`))) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function isInternalDrag(dataTransfer: DataTransfer): boolean {
|
|
82
|
-
return Array.from(dataTransfer.types).includes(INTERNAL_DRAG_TYPE);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Hide dot-entries (`.git`, `.gitignore`, `.DS_Store`, …) — never user
|
|
87
|
-
* documents — and auto-generated `<basename>_files/` companion folders,
|
|
88
|
-
* which hold per-document images and version snapshots (useful to the
|
|
89
|
-
* editor, noisy in the user-facing file list). Everything still exists on
|
|
90
|
-
* disk; we just don't surface it in the explorer.
|
|
91
|
-
*/
|
|
92
|
-
function isHiddenEntry(entry: FileSystemEntry): boolean {
|
|
93
|
-
const name = entry.path.replace(/^\/+/, '').split('/').pop() ?? '';
|
|
94
|
-
if (name.startsWith('.')) return true;
|
|
95
|
-
return entry.kind === 'directory' && name.endsWith('_files');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function filterVisible(entries: FileSystemEntry[]): FileSystemEntry[] {
|
|
99
|
-
return entries.filter((e) => !isHiddenEntry(e));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface FileExplorerProps {
|
|
103
|
-
/** The filesystem to display. */
|
|
104
|
-
provider: FileSystemProvider | null;
|
|
105
|
-
/** Active document to select and reveal by expanding all ancestor folders. */
|
|
106
|
-
activeFilePath?: string | null;
|
|
107
|
-
/** Called when any entry is selected (file or directory). */
|
|
108
|
-
onSelect?: (path: string, kind: 'file' | 'directory') => void;
|
|
109
|
-
/**
|
|
110
|
-
* Wraps destructive tree mutations so the active document session can
|
|
111
|
-
* flush, cancel, or retarget itself before storage changes.
|
|
112
|
-
*/
|
|
113
|
-
onTreeMutation?: FileTreeMutationHandler;
|
|
114
|
-
/** Called after any mutation, with move details when paths change. */
|
|
115
|
-
onTreeChange?: (change?: FileTreeChange) => void;
|
|
116
|
-
/** Called when supported files are dropped onto the explorer. */
|
|
117
|
-
onImportFiles?: (files: File[]) => void;
|
|
118
|
-
/** Optional className for the root element. */
|
|
119
|
-
className?: string;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function FileExplorer({
|
|
123
|
-
provider,
|
|
124
|
-
activeFilePath,
|
|
125
|
-
onSelect,
|
|
126
|
-
onTreeMutation,
|
|
127
|
-
onTreeChange,
|
|
128
|
-
onImportFiles,
|
|
129
|
-
className,
|
|
130
|
-
}: FileExplorerProps) {
|
|
131
|
-
const tree = useFileTree(provider);
|
|
132
|
-
const { childEntries } = tree as typeof tree & {
|
|
133
|
-
childEntries: Map<string, FileSystemEntry[]>;
|
|
134
|
-
};
|
|
135
|
-
const { reveal } = tree;
|
|
136
|
-
// Null on surfaces without git (site, tests) — everything degrades.
|
|
137
|
-
const git = useGitContext();
|
|
138
|
-
|
|
139
|
-
const [newItemName, setNewItemName] = useState('');
|
|
140
|
-
const [newItemType, setNewItemType] = useState<'file' | 'directory' | null>(null);
|
|
141
|
-
const [dragOver, setDragOver] = useState(false);
|
|
142
|
-
const [draggedEntry, setDraggedEntry] = useState<FileSystemEntry | null>(null);
|
|
143
|
-
const [dropTarget, setDropTarget] = useState<string | null>(null);
|
|
144
|
-
const [moveError, setMoveError] = useState<string | null>(null);
|
|
145
|
-
const dragCounter = useRef(0);
|
|
146
|
-
|
|
147
|
-
useEffect(() => {
|
|
148
|
-
if (activeFilePath) reveal(activeFilePath, 'file');
|
|
149
|
-
}, [activeFilePath, provider, reveal]);
|
|
150
|
-
|
|
151
|
-
const hasSupported = useCallback((dt: DataTransfer): boolean => {
|
|
152
|
-
for (const item of Array.from(dt.items)) {
|
|
153
|
-
if (item.kind !== 'file') continue;
|
|
154
|
-
const name = (item as DataTransferItem & { getAsFile(): File | null }).getAsFile?.()?.name;
|
|
155
|
-
// During dragover the filename may not be available, so accept broadly
|
|
156
|
-
if (!name) return true;
|
|
157
|
-
const ext = name.slice(name.lastIndexOf('.')).toLowerCase();
|
|
158
|
-
if (SUPPORTED_EXTENSIONS.has(ext)) return true;
|
|
159
|
-
}
|
|
160
|
-
return dt.items.length > 0;
|
|
161
|
-
}, []);
|
|
162
|
-
|
|
163
|
-
const handleDragEnter = useCallback(
|
|
164
|
-
(e: React.DragEvent) => {
|
|
165
|
-
if (isInternalDrag(e.dataTransfer)) return;
|
|
166
|
-
e.preventDefault();
|
|
167
|
-
dragCounter.current += 1;
|
|
168
|
-
if (hasSupported(e.dataTransfer)) setDragOver(true);
|
|
169
|
-
},
|
|
170
|
-
[hasSupported, dragCounter],
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
const handleDragOver = useCallback((e: React.DragEvent) => {
|
|
174
|
-
if (isInternalDrag(e.dataTransfer)) return;
|
|
175
|
-
e.preventDefault();
|
|
176
|
-
e.dataTransfer.dropEffect = 'copy';
|
|
177
|
-
}, []);
|
|
178
|
-
|
|
179
|
-
const handleDragLeave = useCallback(
|
|
180
|
-
(e: React.DragEvent) => {
|
|
181
|
-
if (isInternalDrag(e.dataTransfer)) return;
|
|
182
|
-
e.preventDefault();
|
|
183
|
-
dragCounter.current -= 1;
|
|
184
|
-
if (dragCounter.current <= 0) {
|
|
185
|
-
dragCounter.current = 0;
|
|
186
|
-
setDragOver(false);
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
[dragCounter],
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const handleDrop = useCallback(
|
|
193
|
-
(e: React.DragEvent) => {
|
|
194
|
-
if (isInternalDrag(e.dataTransfer)) return;
|
|
195
|
-
e.preventDefault();
|
|
196
|
-
dragCounter.current = 0;
|
|
197
|
-
setDragOver(false);
|
|
198
|
-
const supported = Array.from(e.dataTransfer.files).filter((f) => {
|
|
199
|
-
const ext = f.name.slice(f.name.lastIndexOf('.')).toLowerCase();
|
|
200
|
-
return SUPPORTED_EXTENSIONS.has(ext);
|
|
201
|
-
});
|
|
202
|
-
if (supported.length > 0) onImportFiles?.(supported);
|
|
203
|
-
},
|
|
204
|
-
[onImportFiles],
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
const handleSelect = useCallback(
|
|
208
|
-
(path: string) => {
|
|
209
|
-
// Determine kind from entries (root + children)
|
|
210
|
-
const findKind = (p: string): 'file' | 'directory' => {
|
|
211
|
-
for (const e of tree.entries) {
|
|
212
|
-
if (e.path === p) return e.kind;
|
|
213
|
-
}
|
|
214
|
-
for (const children of childEntries.values()) {
|
|
215
|
-
for (const e of children) {
|
|
216
|
-
if (e.path === p) return e.kind;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return 'file';
|
|
220
|
-
};
|
|
221
|
-
const kind = findKind(path);
|
|
222
|
-
tree.select(path, kind);
|
|
223
|
-
onSelect?.(path, kind);
|
|
224
|
-
},
|
|
225
|
-
[tree, onSelect, childEntries],
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
const handleNewItemSubmit = useCallback(async () => {
|
|
229
|
-
if (!newItemName.trim()) {
|
|
230
|
-
setNewItemType(null);
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
const name = newItemName.trim();
|
|
234
|
-
// Scope to currently selected folder (or root)
|
|
235
|
-
const prefix =
|
|
236
|
-
tree.selectedKind === 'directory' && tree.selectedPath ? `${tree.selectedPath}/` : '';
|
|
237
|
-
let createdPath = `${prefix}${name}`;
|
|
238
|
-
if (newItemType === 'file') {
|
|
239
|
-
const filename = name.endsWith('.md') ? name : `${name}.md`;
|
|
240
|
-
createdPath = `${prefix}${filename}`;
|
|
241
|
-
await tree.createFile(createdPath, '');
|
|
242
|
-
} else if (newItemType === 'directory') {
|
|
243
|
-
await tree.createDirectory(createdPath);
|
|
244
|
-
}
|
|
245
|
-
setNewItemName('');
|
|
246
|
-
setNewItemType(null);
|
|
247
|
-
onTreeChange?.({ type: 'create', path: createdPath });
|
|
248
|
-
}, [newItemName, newItemType, tree, onTreeChange]);
|
|
249
|
-
|
|
250
|
-
const runTreeMutation = useCallback(
|
|
251
|
-
async (change: FileTreeChange, mutate: () => Promise<void>) => {
|
|
252
|
-
if (onTreeMutation) await onTreeMutation(change, mutate);
|
|
253
|
-
else await mutate();
|
|
254
|
-
onTreeChange?.(change);
|
|
255
|
-
},
|
|
256
|
-
[onTreeMutation, onTreeChange],
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
const handleDelete = useCallback(
|
|
260
|
-
async (path: string, kind: 'file' | 'directory') => {
|
|
261
|
-
const change: FileTreeChange = { type: 'delete', path, kind };
|
|
262
|
-
await runTreeMutation(change, () => tree.deleteEntry(path));
|
|
263
|
-
},
|
|
264
|
-
[tree, runTreeMutation],
|
|
265
|
-
);
|
|
266
|
-
|
|
267
|
-
const handleRename = useCallback(
|
|
268
|
-
async (oldPath: string, newPath: string, kind: 'file' | 'directory') => {
|
|
269
|
-
setMoveError(null);
|
|
270
|
-
const change: FileTreeChange = { type: 'move', oldPath, newPath, kind };
|
|
271
|
-
try {
|
|
272
|
-
await runTreeMutation(change, () => tree.renameEntry(oldPath, newPath, kind));
|
|
273
|
-
} catch (error: unknown) {
|
|
274
|
-
await tree.refresh();
|
|
275
|
-
if (isFileSystemMoveStateError(error) && error.documentLocation === 'destination') {
|
|
276
|
-
onTreeChange?.(change);
|
|
277
|
-
}
|
|
278
|
-
setMoveError(error instanceof Error ? error.message : 'Unable to move this entry.');
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
[tree, runTreeMutation, onTreeChange],
|
|
282
|
-
);
|
|
283
|
-
|
|
284
|
-
const handleMove = useCallback(
|
|
285
|
-
async (entry: FileSystemEntry, directoryPath: string) => {
|
|
286
|
-
if (!canMoveTo(entry, directoryPath)) return;
|
|
287
|
-
const newPath = pathInDirectory(entry, directoryPath);
|
|
288
|
-
await handleRename(entry.path, newPath, entry.kind);
|
|
289
|
-
if (directoryPath && !tree.expanded.has(directoryPath)) {
|
|
290
|
-
tree.toggleExpand(directoryPath);
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
[handleRename, tree],
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
const handleInternalDragStart = useCallback((e: React.DragEvent, entry: FileSystemEntry) => {
|
|
297
|
-
e.dataTransfer.effectAllowed = 'move';
|
|
298
|
-
e.dataTransfer.setData(INTERNAL_DRAG_TYPE, entry.path);
|
|
299
|
-
e.dataTransfer.setData('text/plain', entry.path);
|
|
300
|
-
setDraggedEntry(entry);
|
|
301
|
-
setMoveError(null);
|
|
302
|
-
}, []);
|
|
303
|
-
|
|
304
|
-
const handleInternalDragEnd = useCallback(() => {
|
|
305
|
-
setDraggedEntry(null);
|
|
306
|
-
setDropTarget(null);
|
|
307
|
-
}, []);
|
|
308
|
-
|
|
309
|
-
const handleEntryDragOver = useCallback(
|
|
310
|
-
(e: React.DragEvent, entry: FileSystemEntry) => {
|
|
311
|
-
if (!isInternalDrag(e.dataTransfer)) return;
|
|
312
|
-
e.stopPropagation();
|
|
313
|
-
const canDrop =
|
|
314
|
-
entry.kind === 'directory' && draggedEntry && canMoveTo(draggedEntry, entry.path);
|
|
315
|
-
e.dataTransfer.dropEffect = canDrop ? 'move' : 'none';
|
|
316
|
-
if (canDrop) {
|
|
317
|
-
e.preventDefault();
|
|
318
|
-
setDropTarget(entry.path);
|
|
319
|
-
} else {
|
|
320
|
-
setDropTarget(null);
|
|
321
|
-
}
|
|
322
|
-
},
|
|
323
|
-
[draggedEntry],
|
|
324
|
-
);
|
|
325
|
-
|
|
326
|
-
const handleEntryDrop = useCallback(
|
|
327
|
-
(e: React.DragEvent, entry: FileSystemEntry) => {
|
|
328
|
-
if (!isInternalDrag(e.dataTransfer)) return;
|
|
329
|
-
e.preventDefault();
|
|
330
|
-
e.stopPropagation();
|
|
331
|
-
setDropTarget(null);
|
|
332
|
-
if (entry.kind === 'directory' && draggedEntry) {
|
|
333
|
-
void handleMove(draggedEntry, entry.path);
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
[draggedEntry, handleMove],
|
|
337
|
-
);
|
|
338
|
-
|
|
339
|
-
const handleRootDragOver = useCallback(
|
|
340
|
-
(e: React.DragEvent) => {
|
|
341
|
-
if (!isInternalDrag(e.dataTransfer) || !draggedEntry) return;
|
|
342
|
-
e.preventDefault();
|
|
343
|
-
e.stopPropagation();
|
|
344
|
-
const canDrop = canMoveTo(draggedEntry, '');
|
|
345
|
-
e.dataTransfer.dropEffect = canDrop ? 'move' : 'none';
|
|
346
|
-
setDropTarget(canDrop ? '' : null);
|
|
347
|
-
},
|
|
348
|
-
[draggedEntry],
|
|
349
|
-
);
|
|
350
|
-
|
|
351
|
-
const handleRootDrop = useCallback(
|
|
352
|
-
(e: React.DragEvent) => {
|
|
353
|
-
if (!isInternalDrag(e.dataTransfer)) return;
|
|
354
|
-
e.preventDefault();
|
|
355
|
-
e.stopPropagation();
|
|
356
|
-
setDropTarget(null);
|
|
357
|
-
if (draggedEntry) void handleMove(draggedEntry, '');
|
|
358
|
-
},
|
|
359
|
-
[draggedEntry, handleMove],
|
|
360
|
-
);
|
|
361
|
-
|
|
362
|
-
const badgeFor = useCallback(
|
|
363
|
-
(entry: FileSystemEntry): FileTreeNodeBadge | undefined => {
|
|
364
|
-
if (!git?.repo) return undefined;
|
|
365
|
-
const key = entry.path.startsWith('/') ? entry.path : `/${entry.path}`;
|
|
366
|
-
const kind = git.badges.get(key);
|
|
367
|
-
if (!kind) return undefined;
|
|
368
|
-
return { kind, glyph: BADGE_GLYPHS[kind], label: BADGE_LABELS[kind] };
|
|
369
|
-
},
|
|
370
|
-
[git],
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
const gitActionsFor = useCallback(
|
|
374
|
-
(entry: FileSystemEntry): FileTreeNodeGitActions | undefined => {
|
|
375
|
-
if (!git?.repo || entry.kind !== 'file') return undefined;
|
|
376
|
-
const path = entry.path.startsWith('/') ? entry.path : `/${entry.path}`;
|
|
377
|
-
return {
|
|
378
|
-
viewChanges: isFileDirty(git.status, path)
|
|
379
|
-
? () => git.openDialog({ kind: 'diff', path })
|
|
380
|
-
: undefined,
|
|
381
|
-
fileHistory: () => git.openDialog({ kind: 'history', path }),
|
|
382
|
-
openOnRemote: git.remoteWeb ? () => git.openOnRemote(path) : undefined,
|
|
383
|
-
};
|
|
384
|
-
},
|
|
385
|
-
[git],
|
|
386
|
-
);
|
|
387
|
-
|
|
388
|
-
const renderEntries = useCallback(
|
|
389
|
-
(entries: FileSystemEntry[], depth: number): React.ReactNode => {
|
|
390
|
-
return filterVisible(entries).map((entry) => (
|
|
391
|
-
<FileTreeNode
|
|
392
|
-
key={entry.path}
|
|
393
|
-
entry={entry}
|
|
394
|
-
depth={depth}
|
|
395
|
-
expanded={hasEquivalentPath(tree.expanded, entry.path)}
|
|
396
|
-
selected={
|
|
397
|
-
tree.selectedPath !== null &&
|
|
398
|
-
normalisePath(tree.selectedPath) === normalisePath(entry.path)
|
|
399
|
-
}
|
|
400
|
-
badge={badgeFor(entry)}
|
|
401
|
-
gitActions={gitActionsFor(entry)}
|
|
402
|
-
onToggle={tree.toggleExpand}
|
|
403
|
-
onSelect={handleSelect}
|
|
404
|
-
onDelete={handleDelete}
|
|
405
|
-
onRename={handleRename}
|
|
406
|
-
draggable
|
|
407
|
-
dragging={draggedEntry?.path === entry.path}
|
|
408
|
-
dropTarget={dropTarget === entry.path}
|
|
409
|
-
onDragStart={handleInternalDragStart}
|
|
410
|
-
onDragEnd={handleInternalDragEnd}
|
|
411
|
-
onDragOverEntry={handleEntryDragOver}
|
|
412
|
-
onDropEntry={handleEntryDrop}
|
|
413
|
-
renderChildren={(dirPath: string) => {
|
|
414
|
-
const children = getEquivalentPathValue(childEntries, dirPath) ?? [];
|
|
415
|
-
return renderEntries(children, depth + 1);
|
|
416
|
-
}}
|
|
417
|
-
/>
|
|
418
|
-
));
|
|
419
|
-
},
|
|
420
|
-
[
|
|
421
|
-
tree,
|
|
422
|
-
handleSelect,
|
|
423
|
-
handleDelete,
|
|
424
|
-
handleRename,
|
|
425
|
-
childEntries,
|
|
426
|
-
badgeFor,
|
|
427
|
-
gitActionsFor,
|
|
428
|
-
draggedEntry,
|
|
429
|
-
dropTarget,
|
|
430
|
-
handleInternalDragStart,
|
|
431
|
-
handleInternalDragEnd,
|
|
432
|
-
handleEntryDragOver,
|
|
433
|
-
handleEntryDrop,
|
|
434
|
-
],
|
|
435
|
-
);
|
|
436
|
-
|
|
437
|
-
return (
|
|
438
|
-
<div
|
|
439
|
-
className={`db-file-explorer ${dragOver ? 'db-file-explorer--drop-active' : ''} ${className ?? ''}`}
|
|
440
|
-
onDragEnter={handleDragEnter}
|
|
441
|
-
onDragOver={handleDragOver}
|
|
442
|
-
onDragLeave={handleDragLeave}
|
|
443
|
-
onDrop={handleDrop}
|
|
444
|
-
>
|
|
445
|
-
{/* Toolbar */}
|
|
446
|
-
<div className="db-explorer-toolbar">
|
|
447
|
-
<span className="db-explorer-title">Files</span>
|
|
448
|
-
<div className="db-explorer-actions">
|
|
449
|
-
<button
|
|
450
|
-
className="db-explorer-btn"
|
|
451
|
-
onClick={() => setNewItemType('file')}
|
|
452
|
-
title="New File"
|
|
453
|
-
aria-label="New File"
|
|
454
|
-
>
|
|
455
|
-
<NewFileIcon />
|
|
456
|
-
</button>
|
|
457
|
-
<button
|
|
458
|
-
className="db-explorer-btn"
|
|
459
|
-
onClick={() => setNewItemType('directory')}
|
|
460
|
-
title="New Folder"
|
|
461
|
-
aria-label="New Folder"
|
|
462
|
-
>
|
|
463
|
-
<NewFolderIcon />
|
|
464
|
-
</button>
|
|
465
|
-
</div>
|
|
466
|
-
</div>
|
|
467
|
-
|
|
468
|
-
{/* New item input */}
|
|
469
|
-
{newItemType && (
|
|
470
|
-
<div className="db-new-item">
|
|
471
|
-
<form
|
|
472
|
-
className="db-new-item-row"
|
|
473
|
-
onSubmit={(e) => {
|
|
474
|
-
e.preventDefault();
|
|
475
|
-
handleNewItemSubmit();
|
|
476
|
-
}}
|
|
477
|
-
>
|
|
478
|
-
<input
|
|
479
|
-
className="db-new-item-input"
|
|
480
|
-
placeholder={newItemType === 'file' ? 'filename' : 'folder-name'}
|
|
481
|
-
value={newItemName}
|
|
482
|
-
onChange={(e) => setNewItemName(e.target.value)}
|
|
483
|
-
onKeyDown={(e) => {
|
|
484
|
-
if (e.key === 'Escape') {
|
|
485
|
-
setNewItemType(null);
|
|
486
|
-
setNewItemName('');
|
|
487
|
-
}
|
|
488
|
-
}}
|
|
489
|
-
autoFocus
|
|
490
|
-
/>
|
|
491
|
-
{newItemType === 'file' && <span className="db-new-item-suffix">.md</span>}
|
|
492
|
-
<button type="submit" className="db-new-item-add">
|
|
493
|
-
Add
|
|
494
|
-
</button>
|
|
495
|
-
</form>
|
|
496
|
-
</div>
|
|
497
|
-
)}
|
|
498
|
-
|
|
499
|
-
{moveError && (
|
|
500
|
-
<div className="db-tree-error" role="alert">
|
|
501
|
-
{moveError}
|
|
502
|
-
</div>
|
|
503
|
-
)}
|
|
504
|
-
|
|
505
|
-
{/* Tree — role="tree" only when there are real treeitem children; the
|
|
506
|
-
loading/empty states get a status role so axe doesn't flag the
|
|
507
|
-
tree as missing required children. */}
|
|
508
|
-
{tree.loading ? (
|
|
509
|
-
<div className="db-tree" role="status" aria-live="polite">
|
|
510
|
-
<div className="db-tree-loading">Loading...</div>
|
|
511
|
-
</div>
|
|
512
|
-
) : filterVisible(tree.entries).length === 0 ? (
|
|
513
|
-
<div className="db-tree">
|
|
514
|
-
<div className="db-tree-empty">No files yet</div>
|
|
515
|
-
</div>
|
|
516
|
-
) : (
|
|
517
|
-
<div
|
|
518
|
-
className={`db-tree ${dropTarget === '' ? 'db-tree--drop-target' : ''}`}
|
|
519
|
-
role="tree"
|
|
520
|
-
onDragOver={handleRootDragOver}
|
|
521
|
-
onDrop={handleRootDrop}
|
|
522
|
-
>
|
|
523
|
-
{renderEntries(tree.entries, 0)}
|
|
524
|
-
</div>
|
|
525
|
-
)}
|
|
526
|
-
</div>
|
|
527
|
-
);
|
|
528
|
-
}
|