ZDDC/browse/js/init.js
ZDDC 582db6d86d feat(browse): vendored JSZip, SVG home icon, auto-filter rows
- Vendor JSZip locally (shared/vendor/jszip.min.js) and bundle into
  the browse build instead of CDN-loading. Eliminates the failure
  mode where ZIP rows can't expand because the CDN script doesn't
  load (CSP, network, etc.). Tool now works fully offline.
- Replace the toolbar filter input + ext multi-select with two
  spreadsheet-style auto-filter rows in <thead>:
    - 📄 row: file-name filter + extension filter
    - 📁 row: folder-name filter
  Each input uses shared/zddc-filter syntax (substring/!negate/
  ^startsWith/$endsWith/regex/| or/space and).
- New visibility model with ancestor-of-match awareness:
    - file matches keep their ancestor folders visible (path-to-hit)
    - folder match keeps its descendants visible
    - filters compose (file ∧ folder ∧ ext) so combinations narrow
  Computed model-side; render walks only visible nodes.
- Replace 🏠 emoji breadcrumb-root with an inline outline-stroke SVG
  that tints with currentColor.
2026-05-03 21:35:15 -05:00

57 lines
2.3 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 },
// Auto-filter row state. Each is a raw string from the input,
// plus a parsed AST (zddc.filter.parse) cached on every keystroke.
// Empty raw → AST empty → matches everything.
filters: {
file: { raw: '', ast: null }, // matches against file basename
folder: { raw: '', ast: null }, // matches against folder basename
ext: { raw: '', ast: null } // matches against file extension
},
// The tree's in-memory representation. Each node:
// { id, name, isDir, size, modTime, ext, url, depth,
// parentId, expanded, loaded, childIds, isZip, zipFile,
// zipPath }
// - isZip: set when the node IS a .zip file we know how to
// expand inline (server file or FS handle).
// - zipFile: cached JSZip instance for this archive (set
// after first expand).
// - zipPath: relative path WITHIN a zip (set on virtual
// children of an expanded zip; null otherwise).
// 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
};
})();