New shared/zip-source.js: a ZipDirectoryHandle / ZipFileHandle pair that exposes a JSZip instance behind the File-System-Access surface (values/entries/keys, getDirectoryHandle/getFileHandle, getFile) — read-only, with a zip-slip guard. Mirrors shared/zddc-source.js's HTTP polyfill. Wired into archive's and browse's build.sh (both already bundle JSZip). archive: a .zip whose name minus ".zip" parses as a transmittal-folder name is now scanned as that transmittal folder. Offline, the zip is opened in the browser (ZipDirectoryHandle) and its members enumerated exactly like an uncompressed folder's files — table/export/hash paths are unchanged (they go through file.handle.getFile()). Online, the scanner recurses into the server's "<…>.zip/" virtual-directory listing, so members come back as "<…>.zip/<member>" URLs the server extracts on demand — no whole-zip download. browse: the offline (file://) zip path is migrated onto the shared adapter — expanding a .zip now opens it as a ZipDirectoryHandle and its members become ordinary dir/file nodes handled by the normal fetchFsChildren path (nested zips fall out by recursion). The bespoke flat-entry walker (loadZipChildren / setZipDirChildren / zipEntries / zipParentId / zipPath / _zipSyntheticDir) is gone — one zip implementation repo-wide. Markdown members inside a zip are flagged read-only (the ZipFileHandle refuses createWritable; server "<…>.zip/" URLs 405 on PUT). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
66 lines
2.7 KiB
JavaScript
66 lines
2.7 KiB
JavaScript
// Bootstrap window.app for the browse tool. Mirrors the convention
|
|
// used by every other ZDDC tool — ./build's CSS/JS concat order means
|
|
// this file runs FIRST inside the IIFE-of-IIFEs.
|
|
(function () {
|
|
'use strict';
|
|
|
|
if (!window.app) {
|
|
window.app = { modules: {}, state: {} };
|
|
}
|
|
|
|
window.app.state = {
|
|
// Source: 'server' | 'fs' | null. Determines how the loader
|
|
// resolves entries.
|
|
source: null,
|
|
|
|
// For server-source: the URL path of the directory currently
|
|
// being viewed. Always starts with '/' and ends with '/'.
|
|
// For fs-source: the displayed path string (no semantic
|
|
// meaning — just for the toolbar).
|
|
currentPath: '/',
|
|
|
|
// FileSystemAccessAPI root handle (null in server mode).
|
|
rootHandle: null,
|
|
|
|
// Sort state. key: 'name' | 'size' | 'ext' | 'date'. dir: 1 or -1.
|
|
sort: { key: 'name', dir: 1 },
|
|
|
|
// Currently-selected tree node id (for highlight + pop-out).
|
|
selectedId: null,
|
|
lastPreviewedNodeId: null,
|
|
|
|
// View mode: 'browse' (tree + preview, default) | 'grid' (classifier).
|
|
viewMode: 'browse',
|
|
|
|
// The tree's in-memory representation. Each node:
|
|
// { id, name, isDir, size, modTime, ext, url, handle, depth,
|
|
// parentId, expanded, loaded, childIds, isZip,
|
|
// _zipDirHandle, virtual }
|
|
// - isZip: the node IS a .zip file; expanding it lists
|
|
// the zip's members (server "<…>.zip/" listing
|
|
// online, JSZip behind a ZipDirectoryHandle
|
|
// offline). Members are ordinary dir/file nodes.
|
|
// - _zipDirHandle: cached ZipDirectoryHandle for an opened zip
|
|
// (offline / nested-in-zip path only).
|
|
// - handle: a FileSystemFileHandle/DirectoryHandle (fs
|
|
// mode) — or, inside an opened zip, a
|
|
// ZipFileHandle/ZipDirectoryHandle.
|
|
// Stored flat in a Map keyed by id; render order derived
|
|
// from a depth-first walk.
|
|
nodes: new Map(),
|
|
rootIds: [],
|
|
nextId: 1,
|
|
|
|
// Single shared popup window for file preview (across
|
|
// multiple file clicks). Same pattern as archive's preview.
|
|
previewWindow: null,
|
|
|
|
// Cascade-resolved scope flags, refreshed on each listing
|
|
// fetch from response headers.
|
|
// scopeDropTarget: cascade's drop_target at currentPath
|
|
// scopeDefaultTool: cascade's default_tool at currentPath
|
|
// (empty when no default declared)
|
|
scopeDropTarget: false,
|
|
scopeDefaultTool: ''
|
|
};
|
|
})();
|