@hanzo/app 0.2.20 → 0.2.21
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/dist/Drive.js +95 -16
- package/dist/lib/local-fs.d.ts +6 -0
- package/dist/lib/local-fs.js +36 -0
- package/package.json +1 -1
package/dist/Drive.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import { ArrowRight, ChevronDown, ChevronRight, Clock, Cloud, Download, File as FileIcon, FileArchive, FileAudio, FileCode, FileImage, FilePlus, FileText, FileVideo, Folder, FolderInput, FolderPlus, HardDrive, Laptop, ListTree, MessageSquare, LayoutGrid, List, MoreHorizontal, PanelLeft, Plus, Search, Trash2, Upload, } from 'lucide-react';
|
|
4
|
+
import { ArrowRight, ChevronDown, ChevronRight, Clock, Cloud, Download, File as FileIcon, FileArchive, FileAudio, FileCode, FileImage, FilePlus, FileText, FileVideo, Folder, FolderGit2, FolderInput, FolderPlus, HardDrive, Laptop, ListTree, MessageSquare, LayoutGrid, List, MoreHorizontal, PanelLeft, Plus, Search, Trash2, Upload, } from 'lucide-react';
|
|
5
5
|
import { Box, Button, Text, View, XStack, YStack } from '@hanzo/ui';
|
|
6
6
|
import { useIam, useOrganizations } from '@hanzo/iam/react';
|
|
7
7
|
import { useAi } from './lib/ai.js';
|
|
@@ -11,7 +11,7 @@ import { useRooms } from './host.js';
|
|
|
11
11
|
import { org } from './lib/session.js';
|
|
12
12
|
import { Badge, Contents, Hits } from './Contents.js';
|
|
13
13
|
import { Editor } from './Editor.js';
|
|
14
|
-
import { createLocalDir, createLocalFile, deleteLocalPath, getActiveWorkspace, getLocalWorkspaces, listLocalEntries, pickLocalFolder, removeLocalWorkspace, setActiveWorkspace, subscribeLocalFs, } from './lib/local-fs.js';
|
|
14
|
+
import { cloneRemoteRepo, createLocalDir, createLocalFile, deleteLocalPath, getActiveWorkspace, getLocalWorkspaces, importLocalFile, listLocalEntries, pickLocalFile, pickLocalFolder, removeLocalWorkspace, setActiveWorkspace, subscribeLocalFs, } from './lib/local-fs.js';
|
|
15
15
|
import { weigh as size } from './lib/attach.js';
|
|
16
16
|
import { dropped, filesIn, forget, pool, register, search, settled, slug, upload, } from './lib/files.js';
|
|
17
17
|
import { checkoutUrl } from './lib/pay.js';
|
|
@@ -420,8 +420,55 @@ export function Drive() {
|
|
|
420
420
|
setEditingFile({ path: filePath, name: clean });
|
|
421
421
|
})
|
|
422
422
|
.catch((e) => setFailed(blame(e)));
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (!client || !activeBucket)
|
|
426
|
+
return;
|
|
427
|
+
void run(`Creating ${clean}`, () => putBytes(client, activeBucket, `${prefix}${clean}`, new Blob([''])));
|
|
428
|
+
setNaming(null);
|
|
429
|
+
}, [client, activeBucket, prefix, run, navSection, activeWs, localPrefix, loadLocalEntries]);
|
|
430
|
+
const handleCloneRepo = useCallback((repoUrl) => {
|
|
431
|
+
const clean = repoUrl.trim();
|
|
432
|
+
if (!clean)
|
|
433
|
+
return;
|
|
434
|
+
setNaming(null);
|
|
435
|
+
void run(`Cloning ${clean}`, async () => {
|
|
436
|
+
const ws = await cloneRemoteRepo(clean);
|
|
437
|
+
setNavSection('local');
|
|
438
|
+
setActiveWorkspace(ws);
|
|
439
|
+
setLocalPrefix('');
|
|
440
|
+
loadLocalEntries();
|
|
441
|
+
});
|
|
442
|
+
}, [run, loadLocalEntries]);
|
|
443
|
+
const handleOpenLocalFile = useCallback(async () => {
|
|
444
|
+
try {
|
|
445
|
+
const selected = await pickLocalFile();
|
|
446
|
+
if (selected) {
|
|
447
|
+
const fileName = selected.split(/[/\\]/).pop() || 'file';
|
|
448
|
+
setEditingFile({ path: selected, name: fileName });
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
catch (e) {
|
|
452
|
+
setFailed(blame(e));
|
|
453
|
+
}
|
|
454
|
+
}, []);
|
|
455
|
+
const handleImportLocalFile = useCallback(async () => {
|
|
456
|
+
if (!activeWs)
|
|
457
|
+
return;
|
|
458
|
+
try {
|
|
459
|
+
const selected = await pickLocalFile();
|
|
460
|
+
if (selected) {
|
|
461
|
+
const targetDir = localPrefix
|
|
462
|
+
? `${activeWs.path}/${localPrefix}`.replace(/\/+/g, '/')
|
|
463
|
+
: activeWs.path;
|
|
464
|
+
await importLocalFile(selected, targetDir);
|
|
465
|
+
loadLocalEntries();
|
|
466
|
+
}
|
|
423
467
|
}
|
|
424
|
-
|
|
468
|
+
catch (e) {
|
|
469
|
+
setFailed(blame(e));
|
|
470
|
+
}
|
|
471
|
+
}, [activeWs, localPrefix, loadLocalEntries]);
|
|
425
472
|
const handleRename = useCallback((entry, to) => {
|
|
426
473
|
const clean = to.trim().replace(/^\/+|\/+$/g, '');
|
|
427
474
|
if (!clean || !client || !activeBucket || entry.isDir)
|
|
@@ -571,7 +618,23 @@ export function Drive() {
|
|
|
571
618
|
setLocalPrefix('');
|
|
572
619
|
}
|
|
573
620
|
});
|
|
574
|
-
}, children: [_jsx(FolderInput, { size: 14 }), "Open local folder\u2026"] })
|
|
621
|
+
}, children: [_jsx(FolderInput, { size: 14 }), "Open local folder\u2026"] }), _jsxs(Button, { ...ITEM, onClick: () => {
|
|
622
|
+
setNewMenuOpen(false);
|
|
623
|
+
setMenu(false);
|
|
624
|
+
void handleOpenLocalFile();
|
|
625
|
+
}, children: [_jsx(FileText, { size: 14 }), "Open local file\u2026"] }), _jsxs(Button, { ...ITEM, onClick: () => {
|
|
626
|
+
setNewMenuOpen(false);
|
|
627
|
+
setMenu(false);
|
|
628
|
+
void handleImportLocalFile();
|
|
629
|
+
}, children: [_jsx(Upload, { size: 14 }), "Import local file\u2026"] }), _jsxs(Button, { ...ITEM, onClick: () => {
|
|
630
|
+
setNewMenuOpen(false);
|
|
631
|
+
setMenu(false);
|
|
632
|
+
setNaming({ kind: 'clone', value: '' });
|
|
633
|
+
}, children: [_jsx(FolderGit2, { size: 14 }), "Clone remote repo\u2026"] })] })) : (_jsxs(_Fragment, { children: [_jsxs(Button, { ...ITEM, onClick: () => {
|
|
634
|
+
setNewMenuOpen(false);
|
|
635
|
+
setMenu(false);
|
|
636
|
+
setNaming({ kind: 'file', value: '' });
|
|
637
|
+
}, children: [_jsx(FilePlus, { size: 14 }), "New file"] }), _jsxs(Button, { ...ITEM, onClick: () => {
|
|
575
638
|
setNewMenuOpen(false);
|
|
576
639
|
setMenu(false);
|
|
577
640
|
setNaming({ kind: 'folder', value: '' });
|
|
@@ -583,7 +646,11 @@ export function Drive() {
|
|
|
583
646
|
setNewMenuOpen(false);
|
|
584
647
|
setMenu(false);
|
|
585
648
|
folderInputRef.current?.click();
|
|
586
|
-
}, children: [_jsx(FolderInput, { size: 14 }), "Folder upload"] })
|
|
649
|
+
}, children: [_jsx(FolderInput, { size: 14 }), "Folder upload"] }), _jsx(View, { height: 1, bg: "$borderColor", my: 4 }), _jsxs(Button, { ...ITEM, onClick: () => {
|
|
650
|
+
setNewMenuOpen(false);
|
|
651
|
+
setMenu(false);
|
|
652
|
+
setNaming({ kind: 'clone', value: '' });
|
|
653
|
+
}, children: [_jsx(FolderGit2, { size: 14 }), "Clone remote repo\u2026"] })] })) })) : null] }), _jsx(YStack, { gap: "$1", children: [
|
|
587
654
|
{ id: 'my-drive', label: 'My Drive', icon: HardDrive },
|
|
588
655
|
{ id: 'local', label: 'Local Folders', icon: Laptop },
|
|
589
656
|
{ id: 'recent', label: 'Recent', icon: Clock },
|
|
@@ -628,34 +695,46 @@ export function Drive() {
|
|
|
628
695
|
['list', 'List View', List],
|
|
629
696
|
['grid', 'Grid View', LayoutGrid],
|
|
630
697
|
['details', 'Details View', MoreHorizontal],
|
|
631
|
-
].map(([mode, label, Icon]) => (_jsx(Button, { variant: viewMode === mode ? 'secondary' : 'ghost', size: "icon-sm", color: viewMode === mode ? '$ink' : '$soft', onClick: () => setViewMode(mode), "aria-label": label, "aria-pressed": viewMode === mode, title: label, children: _jsx(Icon, { size: 14 }) }, mode))) })] }), naming ? (_jsxs(XStack, { items: "center", gap: "$3", py: 10, px: 14, rounded: 8, borderWidth: 1, borderColor: "var(--border-control)", bg: "$panel", children: [naming.kind === 'file' ? (_jsx(FileCode, { size: 16, color: "var(--primary)" })) : (_jsx(Folder, { size: 16, color: "var(--foreground)" })), _jsx(Text, { render: _jsx("input", { autoFocus: true, value: naming.value, onChange: (e) => setNaming({ ...naming, value: e.target.value }), onKeyDown: (e) => {
|
|
698
|
+
].map(([mode, label, Icon]) => (_jsx(Button, { variant: viewMode === mode ? 'secondary' : 'ghost', size: "icon-sm", color: viewMode === mode ? '$ink' : '$soft', onClick: () => setViewMode(mode), "aria-label": label, "aria-pressed": viewMode === mode, title: label, children: _jsx(Icon, { size: 14 }) }, mode))) })] }), naming ? (_jsxs(XStack, { items: "center", gap: "$3", py: 10, px: 14, rounded: 8, borderWidth: 1, borderColor: "var(--border-control)", bg: "$panel", children: [naming.kind === 'file' ? (_jsx(FileCode, { size: 16, color: "var(--primary)" })) : naming.kind === 'clone' ? (_jsx(FolderGit2, { size: 16, color: "var(--primary)" })) : (_jsx(Folder, { size: 16, color: "var(--foreground)" })), _jsx(Text, { render: _jsx("input", { autoFocus: true, value: naming.value, onChange: (e) => setNaming({ ...naming, value: e.target.value }), onKeyDown: (e) => {
|
|
632
699
|
if (e.key === 'Escape')
|
|
633
700
|
setNaming(null);
|
|
634
701
|
if (e.key === 'Enter') {
|
|
635
702
|
if (naming.kind === 'file')
|
|
636
703
|
handleCreateFile(naming.value);
|
|
704
|
+
else if (naming.kind === 'clone')
|
|
705
|
+
handleCloneRepo(naming.value);
|
|
637
706
|
else
|
|
638
707
|
handleCreateFolder(naming.value);
|
|
639
708
|
}
|
|
640
|
-
}, placeholder: naming.kind === 'file'
|
|
709
|
+
}, placeholder: naming.kind === 'file'
|
|
710
|
+
? 'File name (e.g. index.ts)'
|
|
711
|
+
: naming.kind === 'clone'
|
|
712
|
+
? 'owner/repo or Git URL (e.g. hanzoai/desktop)'
|
|
713
|
+
: 'Folder name', "aria-label": naming.kind === 'file'
|
|
714
|
+
? 'File name'
|
|
715
|
+
: naming.kind === 'clone'
|
|
716
|
+
? 'Clone remote repository'
|
|
717
|
+
: 'Folder name' }), ...BARE }), _jsx(Button, { variant: "primary", size: "sm", onClick: () => {
|
|
641
718
|
if (naming.kind === 'file')
|
|
642
719
|
handleCreateFile(naming.value);
|
|
720
|
+
else if (naming.kind === 'clone')
|
|
721
|
+
handleCloneRepo(naming.value);
|
|
643
722
|
else
|
|
644
723
|
handleCreateFolder(naming.value);
|
|
645
|
-
}, children:
|
|
724
|
+
}, children: naming.kind === 'clone' ? 'Clone' : 'Create' }), _jsx(Button, { variant: "ghost", size: "sm", color: "$soft", onClick: () => setNaming(null), children: "Cancel" })] })) : null, editingFile ? (_jsx(Editor, { filePath: editingFile.path, fileName: editingFile.name, onClose: () => {
|
|
646
725
|
setEditingFile(null);
|
|
647
726
|
loadLocalEntries();
|
|
648
727
|
}, onAskInChat: () => {
|
|
649
728
|
setEditingFile(null);
|
|
650
729
|
router.push('/chat');
|
|
651
|
-
} })) : null, busy ? (_jsxs(Text, { fontSize: "$2", color: "$soft", "data-slot": "drive-busy", children: [busy, "\u2026"] })) : null, hits && hits.length ? _jsx(Hits, { hits: hits, onOpen: (p) => showContents(p.file.id, p.section.id) }) : null, navSection === 'local' ? (!activeWs ? (_jsxs(YStack, { py: 60, px: 24, items: "center", justify: "center", gap: "$4", borderWidth: 1, borderStyle: "dashed", borderColor: "$borderColor", rounded: 12, bg: "$panel", children: [_jsx(Laptop, { size: 40, color: "var(--primary)" }), _jsxs(YStack, { items: "center", gap: "$1", maxW: 460, children: [_jsx(Text, { fontSize: 18, fontWeight: "600", color: "$ink", text: "center", children: "No local folder opened" }), _jsx(Text, { fontSize: 13, color: "$soft", text: "center", children: "Open a local folder on your computer to browse, create, edit, and save files directly in Hanzo Desktop." })] }), _jsxs(Button, { onClick: () => {
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
730
|
+
} })) : null, busy ? (_jsxs(Text, { fontSize: "$2", color: "$soft", "data-slot": "drive-busy", children: [busy, "\u2026"] })) : null, hits && hits.length ? _jsx(Hits, { hits: hits, onOpen: (p) => showContents(p.file.id, p.section.id) }) : null, navSection === 'local' ? (!activeWs ? (_jsxs(YStack, { py: 60, px: 24, items: "center", justify: "center", gap: "$4", borderWidth: 1, borderStyle: "dashed", borderColor: "$borderColor", rounded: 12, bg: "$panel", children: [_jsx(Laptop, { size: 40, color: "var(--primary)" }), _jsxs(YStack, { items: "center", gap: "$1", maxW: 460, children: [_jsx(Text, { fontSize: 18, fontWeight: "600", color: "$ink", text: "center", children: "No local folder opened" }), _jsx(Text, { fontSize: 13, color: "$soft", text: "center", children: "Open a local folder on your computer to browse, create, edit, and save files directly in Hanzo Desktop." })] }), _jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(Button, { onClick: () => {
|
|
731
|
+
void pickLocalFolder().then((ws) => {
|
|
732
|
+
if (ws) {
|
|
733
|
+
setNavSection('local');
|
|
734
|
+
setLocalPrefix('');
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}, children: [_jsx(FolderPlus, { size: 16 }), "Open Local Folder\u2026"] }), _jsxs(Button, { variant: "outline", onClick: () => setNaming({ kind: 'clone', value: '' }), children: [_jsx(FolderGit2, { size: 16 }), "Clone Remote Repo\u2026"] })] })] })) : (_jsxs(YStack, { gap: "$2", children: [_jsxs(XStack, { items: "center", justify: "space-between", pb: "$1", children: [_jsx(Text, { fontSize: 12, fontWeight: "600", color: "$soft", children: localPrefix ? `Folder: ${localPrefix}` : 'Root Files & Directories' }), _jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(Button, { variant: "outline", size: "sm", onClick: () => setNaming({ kind: 'file', value: '' }), children: [_jsx(FilePlus, { size: 13 }), "New file"] }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => setNaming({ kind: 'folder', value: '' }), children: [_jsx(FolderPlus, { size: 13 }), "New folder"] }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => void handleImportLocalFile(), children: [_jsx(Upload, { size: 13 }), "Import file"] }), _jsxs(Button, { variant: "outline", size: "sm", onClick: () => setNaming({ kind: 'clone', value: '' }), children: [_jsx(FolderGit2, { size: 13 }), "Clone repo"] })] })] }), _jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: 8, overflowX: "auto", overflowY: "hidden", children: [_jsxs(View, { display: "grid", gridTemplateColumns: FILES, minW: "min-content", px: 16, py: 10, borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsx(Text, { ...HEAD, children: "Name" }), _jsx(Text, { ...HEAD, children: "Type" }), _jsx(Text, { ...HEAD, children: "Updated" }), _jsx(Text, { ...HEAD, children: "Size" }), _jsx(View, {})] }), !localEntries || localEntries.length === 0 ? (_jsx(Text, { py: 36, px: 16, text: "center", fontSize: "$2", color: "$faint", children: "Empty folder" })) : (localEntries.map((e) => {
|
|
659
738
|
const ext = e.name.split('.').pop() || '';
|
|
660
739
|
return (_jsxs(View, { display: "grid", gridTemplateColumns: FILES, minW: "min-content", px: 16, py: 11, items: "center", cursor: "pointer", borderBottomWidth: 1, borderColor: "$borderColor", transition: "100ms", hoverStyle: { bg: '$hover' }, onClick: () => {
|
|
661
740
|
if (e.isDir) {
|
package/dist/lib/local-fs.d.ts
CHANGED
|
@@ -37,6 +37,12 @@ export declare function addLocalWorkspace(path: string, name?: string): LocalWor
|
|
|
37
37
|
export declare function removeLocalWorkspace(idOrPath: string): void;
|
|
38
38
|
/** Open native dialog to pick a local folder */
|
|
39
39
|
export declare function pickLocalFolder(): Promise<LocalWorkspace | null>;
|
|
40
|
+
/** Open native dialog to pick a local file to view or edit */
|
|
41
|
+
export declare function pickLocalFile(): Promise<string | null>;
|
|
42
|
+
/** Clone a remote repository to local machine and register as a workspace */
|
|
43
|
+
export declare function cloneRemoteRepo(repo: string, targetDir?: string): Promise<LocalWorkspace>;
|
|
44
|
+
/** Import an existing local file into the active workspace directory */
|
|
45
|
+
export declare function importLocalFile(sourcePath: string, targetDir: string): Promise<LocalEntry>;
|
|
40
46
|
/** List entries in a local directory */
|
|
41
47
|
export declare function listLocalEntries(dirPath: string): Promise<LocalEntry[]>;
|
|
42
48
|
/** Read text content of a local file */
|
package/dist/lib/local-fs.js
CHANGED
|
@@ -152,6 +152,42 @@ export async function pickLocalFolder() {
|
|
|
152
152
|
}
|
|
153
153
|
return null;
|
|
154
154
|
}
|
|
155
|
+
/** Open native dialog to pick a local file to view or edit */
|
|
156
|
+
export async function pickLocalFile() {
|
|
157
|
+
if (isTauri()) {
|
|
158
|
+
try {
|
|
159
|
+
const selected = await tauriInvoke('local_workspace_open_file_dialog');
|
|
160
|
+
if (selected && typeof selected === 'string') {
|
|
161
|
+
return selected;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
console.warn('local_workspace_open_file_dialog failed:', e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
/** Clone a remote repository to local machine and register as a workspace */
|
|
171
|
+
export async function cloneRemoteRepo(repo, targetDir) {
|
|
172
|
+
if (isTauri()) {
|
|
173
|
+
const res = await tauriInvoke('local_workspace_clone_repo', {
|
|
174
|
+
repo,
|
|
175
|
+
targetDir,
|
|
176
|
+
});
|
|
177
|
+
return addLocalWorkspace(res.path, res.name);
|
|
178
|
+
}
|
|
179
|
+
throw new Error('Cloning remote repositories locally requires Hanzo Desktop');
|
|
180
|
+
}
|
|
181
|
+
/** Import an existing local file into the active workspace directory */
|
|
182
|
+
export async function importLocalFile(sourcePath, targetDir) {
|
|
183
|
+
if (isTauri()) {
|
|
184
|
+
return await tauriInvoke('local_workspace_import_file', {
|
|
185
|
+
sourcePath,
|
|
186
|
+
targetDir,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
throw new Error('Importing files requires Hanzo Desktop');
|
|
190
|
+
}
|
|
155
191
|
/** List entries in a local directory */
|
|
156
192
|
export async function listLocalEntries(dirPath) {
|
|
157
193
|
if (isTauri()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.21",
|
|
4
4
|
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|