refactor(browse): remove auto-filter rows from header
The two filter rows (📄 file/ext + 📁 folder) didn't really earn their header real estate. Browse is for navigating directory structure; ad-hoc filters across a tree of mixed file types and depths weren't the right affordance, and the visual weight competed with the column headers and the breadcrumb. Removed entirely: - template.html: dropped both <tr class="filter-row"> rows in <thead>, the related "Filter rows" help section, and the empty-state copy that mentioned the 📄/📁 rows. - init.js: dropped state.filters (file/folder/ext slots). - events.js: dropped the .column-filter[data-filter] input wiring. - tree.js: dropped recomputeVisibility() and the n.visible plumbing in visibleIds() and updateCount(). Render is now a straight depth- first walk over expanded subtrees; the count is just total rows. setFilter is removed from the public API. - css/tree.css: dropped .filter-row*, .filter-row__icon, and the browse-local .column-filter rules (.column-filter is also defined in shared/base.css for tools that still use it; that stays). No test changes — tests/browse.spec.js never exercised filters. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
13e929b029
commit
53eb58b90b
5 changed files with 5 additions and 263 deletions
|
|
@ -90,58 +90,6 @@
|
|||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Auto-filter rows in <thead>. Two rows — one targets file rows
|
||||
(📄 icon, with file-name + ext inputs), one targets folder rows
|
||||
(📁 icon, with folder-name input). The icons make it visually
|
||||
obvious which row controls which kind of filter. The rows are
|
||||
non-sticky (only the sortable header row sticks) — keeps the
|
||||
stack-positioning math out of the picture and accepts that
|
||||
filters scroll out of view on long lists. */
|
||||
.browse-table thead .filter-row th {
|
||||
position: static;
|
||||
padding: 0.25rem 0.6rem;
|
||||
background: var(--bg-secondary);
|
||||
border-bottom: 1px solid var(--border);
|
||||
cursor: default;
|
||||
font-weight: normal;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
.browse-table thead .filter-row th:hover {
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.filter-row__icon {
|
||||
display: inline-block;
|
||||
width: 1.2rem;
|
||||
text-align: center;
|
||||
margin-right: 0.3rem;
|
||||
vertical-align: middle;
|
||||
font-size: 0.95rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.column-filter {
|
||||
width: calc(100% - 1.5rem);
|
||||
padding: 0.2rem 0.4rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 3px;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-size: 0.8rem;
|
||||
font-family: Consolas, Monaco, monospace;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.filter-row th.col-name .column-filter {
|
||||
width: calc(100% - 1.7rem); /* leave space for the icon */
|
||||
}
|
||||
|
||||
.column-filter:focus {
|
||||
outline: 1px solid var(--primary);
|
||||
outline-offset: -1px;
|
||||
}
|
||||
|
||||
/* Table — folders + files in a tree */
|
||||
|
||||
.browse-table {
|
||||
|
|
|
|||
|
|
@ -122,19 +122,6 @@
|
|||
var refresh = document.getElementById('refreshHeaderBtn');
|
||||
if (refresh) refresh.addEventListener('click', refreshListing);
|
||||
|
||||
// Auto-filter row inputs. There are three of them (file, folder,
|
||||
// ext) — wire each by its `data-filter` attribute. Idempotent
|
||||
// re: re-init.
|
||||
var filterInputs = document.querySelectorAll('input.column-filter[data-filter]');
|
||||
for (var fi = 0; fi < filterInputs.length; fi++) {
|
||||
(function (input) {
|
||||
var which = input.dataset.filter;
|
||||
input.addEventListener('input', function () {
|
||||
tree.setFilter(which, input.value);
|
||||
});
|
||||
})(filterInputs[fi]);
|
||||
}
|
||||
|
||||
// Sort headers
|
||||
var ths = document.querySelectorAll('#browseTable thead th.sortable');
|
||||
for (var i = 0; i < ths.length; i++) {
|
||||
|
|
|
|||
|
|
@ -25,15 +25,6 @@
|
|||
// 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,
|
||||
|
|
|
|||
|
|
@ -102,17 +102,14 @@
|
|||
parent.loaded = true;
|
||||
}
|
||||
|
||||
// Walk visible nodes in render order. Excludes nodes whose
|
||||
// node.visible is false (filter-hidden) and skips the children of
|
||||
// a collapsed expandable. Filter visibility is computed by
|
||||
// recomputeVisibility() before this is called from render().
|
||||
// Walk nodes in render order. Skips the children of a collapsed
|
||||
// expandable.
|
||||
function visibleIds() {
|
||||
var out = [];
|
||||
function walk(ids) {
|
||||
for (var i = 0; i < ids.length; i++) {
|
||||
var n = state.nodes.get(ids[i]);
|
||||
if (!n) continue;
|
||||
if (n.visible === false) continue;
|
||||
out.push(ids[i]);
|
||||
if ((n.isDir || n.isZip) && n.expanded) walk(n.childIds);
|
||||
}
|
||||
|
|
@ -192,7 +189,6 @@
|
|||
function render() {
|
||||
var tbody = document.getElementById('browseTbody');
|
||||
if (!tbody) return;
|
||||
recomputeVisibility();
|
||||
var ids = visibleIds();
|
||||
var html = '';
|
||||
for (var i = 0; i < ids.length; i++) {
|
||||
|
|
@ -204,111 +200,7 @@
|
|||
renderBreadcrumbs();
|
||||
}
|
||||
|
||||
// Compute model-level visibility per node based on the three
|
||||
// filter ASTs:
|
||||
// - fileFilter → matches a file's basename
|
||||
// - folderFilter→ matches a folder's basename
|
||||
// - extFilter → matches a file's extension (no leading dot)
|
||||
//
|
||||
// Visibility rules:
|
||||
// 1. A FILE is "self-matched" when it passes both file+ext filter.
|
||||
// 2. A FOLDER is "self-matched" when it passes the folder filter.
|
||||
// 3. A file is "in-scope" when either no folder filter is active,
|
||||
// OR at least one ancestor folder is folder-self-matched.
|
||||
// 4. A file is VISIBLE when self-matched AND in-scope.
|
||||
// 5. A folder is VISIBLE when:
|
||||
// - any descendant is visible (so the path to a hit is
|
||||
// always shown), OR
|
||||
// - the folder itself is folder-self-matched AND no file
|
||||
// filter is active (when a file filter is set, we hide
|
||||
// folders that have no matching files inside — keeps
|
||||
// the result list focused).
|
||||
//
|
||||
// Pure model walk; the renderer just consumes node.visible. Hidden
|
||||
// expandable nodes get their `expanded` flag respected even though
|
||||
// they're not in the DOM, so toggling filters preserves the user's
|
||||
// expand state.
|
||||
function recomputeVisibility() {
|
||||
var fileAst = state.filters.file.ast;
|
||||
var folderAst = state.filters.folder.ast;
|
||||
var extAst = state.filters.ext.ast;
|
||||
var hasFile = !!(state.filters.file.raw);
|
||||
var hasFolder = !!(state.filters.folder.raw);
|
||||
var hasExt = !!(state.filters.ext.raw);
|
||||
var anyActive = hasFile || hasFolder || hasExt;
|
||||
|
||||
// Fast path: nothing filtered → everything visible.
|
||||
if (!anyActive) {
|
||||
state.nodes.forEach(function (n) { n.visible = true; });
|
||||
return;
|
||||
}
|
||||
|
||||
var f = window.zddc && window.zddc.filter;
|
||||
|
||||
// Walk top-down to propagate folder scope, then bottom-up to
|
||||
// propagate descendant visibility. Done in one DFS recursion.
|
||||
// ZIPs are hybrids — they match FILE filter (their name is a
|
||||
// filename) AND can be matched by FOLDER filter (they're
|
||||
// container-like — clicking expands them like a folder).
|
||||
function visit(nodeId, ancestorMatchesFolder) {
|
||||
var n = state.nodes.get(nodeId);
|
||||
if (!n) return false;
|
||||
|
||||
if (!(n.isDir || n.isZip)) {
|
||||
// Plain file. Visible iff its name+ext pass file/ext
|
||||
// filters AND it's inside the folder-filter scope.
|
||||
var nameOk = f.matches(n.name, fileAst);
|
||||
var extOk = f.matches(n.ext || '', extAst);
|
||||
n.visible = nameOk && extOk && ancestorMatchesFolder;
|
||||
return n.visible;
|
||||
}
|
||||
|
||||
// Folder or zip — has childIds and contributes to scope.
|
||||
// Folder self-match: the folder/zip name passes folder
|
||||
// filter. A folder match also opens the file-filter scope
|
||||
// for descendants.
|
||||
var asFolderMatch = f.matches(n.name, folderAst);
|
||||
// A zip can also match the FILE filter (it's a file too).
|
||||
// Typing a zip name into file filter surfaces the zip.
|
||||
// Gate on hasFile||hasExt — when neither is active, the
|
||||
// empty filter matches every name and would falsely
|
||||
// surface every zip regardless of the active folder filter.
|
||||
var asFileMatch = n.isZip
|
||||
&& (hasFile || hasExt)
|
||||
&& f.matches(n.name, fileAst)
|
||||
&& f.matches(n.ext || '', extAst);
|
||||
|
||||
var nextAncestorScope = ancestorMatchesFolder
|
||||
|| asFolderMatch || asFileMatch;
|
||||
|
||||
var anyChildVisible = false;
|
||||
for (var i = 0; i < n.childIds.length; i++) {
|
||||
if (visit(n.childIds[i], nextAncestorScope)) anyChildVisible = true;
|
||||
}
|
||||
|
||||
// Visible if:
|
||||
// - any descendant is visible (path-to-hit visibility), or
|
||||
// - self-folder-match with no file/ext filter active
|
||||
// (let the folder surface even if it's empty/unloaded), or
|
||||
// - self-file-match (for zips, where the user is searching
|
||||
// for the archive by name in the file filter).
|
||||
n.visible = anyChildVisible
|
||||
|| (asFolderMatch && !hasFile && !hasExt)
|
||||
|| asFileMatch;
|
||||
return n.visible;
|
||||
}
|
||||
|
||||
// Initial ancestor scope = folder filter empty (so files don't
|
||||
// require ancestor matches when there's no folder filter).
|
||||
var initialScope = !hasFolder;
|
||||
for (var i = 0; i < state.rootIds.length; i++) {
|
||||
visit(state.rootIds[i], initialScope);
|
||||
}
|
||||
}
|
||||
|
||||
// Count nodes that would render if no filter were active
|
||||
// (i.e. anything at the root, or under an expanded ancestor).
|
||||
// Used to express "<visible> of <total> shown" while a filter is on.
|
||||
// Count nodes that render at the root + every expanded subtree.
|
||||
function expandedSetSize() {
|
||||
var n = 0;
|
||||
function walk(ids) {
|
||||
|
|
@ -327,14 +219,8 @@
|
|||
function updateCount() {
|
||||
var el = document.getElementById('entryCount');
|
||||
if (!el) return;
|
||||
var visible = visibleIds().length;
|
||||
var total = expandedSetSize();
|
||||
var anyFilter = state.filters.file.raw
|
||||
|| state.filters.folder.raw
|
||||
|| state.filters.ext.raw;
|
||||
el.textContent = anyFilter
|
||||
? visible + ' of ' + total + ' shown'
|
||||
: total + ' item' + (total === 1 ? '' : 's');
|
||||
el.textContent = total + ' item' + (total === 1 ? '' : 's');
|
||||
}
|
||||
|
||||
// ── Breadcrumbs ──────────────────────────────────────────────────────
|
||||
|
|
@ -647,17 +533,6 @@
|
|||
}
|
||||
render();
|
||||
},
|
||||
// Update one of the three column filters and re-render. `which`
|
||||
// is 'file' | 'folder' | 'ext'. Empty raw → AST cleared.
|
||||
setFilter: function (which, raw) {
|
||||
var slot = state.filters[which];
|
||||
if (!slot) return;
|
||||
slot.raw = raw || '';
|
||||
slot.ast = slot.raw && window.zddc && window.zddc.filter
|
||||
? window.zddc.filter.parse(slot.raw)
|
||||
: null;
|
||||
render();
|
||||
},
|
||||
pathFor: pathFor
|
||||
};
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -47,10 +47,7 @@
|
|||
</ul>
|
||||
<p>Once loaded: click a folder to expand it, <b>shift-click</b>
|
||||
to expand its entire subtree (or collapse it again),
|
||||
click column headers to sort. Use the 📄 row to filter files
|
||||
(and the 📁 row to scope to matching folders) — file matches
|
||||
stay visible together with their containing folders.
|
||||
Click any file to open it.</p>
|
||||
click column headers to sort. Click any file to open it.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -68,32 +65,6 @@
|
|||
<th data-sort="ext" class="col-ext sortable">Type <span class="sort-arrow"></span></th>
|
||||
<th data-sort="date" class="col-date sortable">Modified <span class="sort-arrow"></span></th>
|
||||
</tr>
|
||||
<tr class="filter-row filter-row--file" title="Filter files">
|
||||
<th class="col-name">
|
||||
<span class="filter-row__icon" aria-hidden="true">📄</span>
|
||||
<input type="text" class="column-filter" data-filter="file"
|
||||
placeholder="filter files…" spellcheck="false"
|
||||
aria-label="Filter by file name">
|
||||
</th>
|
||||
<th class="col-size"></th>
|
||||
<th class="col-ext">
|
||||
<input type="text" class="column-filter" data-filter="ext"
|
||||
placeholder="ext…" spellcheck="false"
|
||||
aria-label="Filter by extension">
|
||||
</th>
|
||||
<th class="col-date"></th>
|
||||
</tr>
|
||||
<tr class="filter-row filter-row--folder" title="Filter folders">
|
||||
<th class="col-name">
|
||||
<span class="filter-row__icon" aria-hidden="true">📁</span>
|
||||
<input type="text" class="column-filter" data-filter="folder"
|
||||
placeholder="filter folders…" spellcheck="false"
|
||||
aria-label="Filter by folder name">
|
||||
</th>
|
||||
<th class="col-size"></th>
|
||||
<th class="col-ext"></th>
|
||||
<th class="col-date"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="browseTbody"></tbody>
|
||||
</table>
|
||||
|
|
@ -145,36 +116,6 @@
|
|||
local (re-enumerates the FS handle) and online (re-fetches the JSON).</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Filter rows</h3>
|
||||
<p>Two filter rows live in the table header:</p>
|
||||
<dl>
|
||||
<dt>📄 file row</dt>
|
||||
<dd>Filter by file name (left input) and/or extension (Type input).
|
||||
File matches stay visible together with their ancestor folders, so
|
||||
the path to each hit is always shown.</dd>
|
||||
<dt>📁 folder row</dt>
|
||||
<dd>Filter by folder name. Matching folders show with their entire
|
||||
subtree. Combined with file filter: file must also be inside a
|
||||
matching folder's subtree (intersection).</dd>
|
||||
</dl>
|
||||
<p>Filter syntax (shared across all ZDDC tools):</p>
|
||||
<dl>
|
||||
<dt><code>term</code></dt>
|
||||
<dd>Contains "term" (case-insensitive)</dd>
|
||||
<dt><code>!term</code></dt>
|
||||
<dd>Does not contain</dd>
|
||||
<dt><code>^term</code></dt>
|
||||
<dd>Starts with</dd>
|
||||
<dt><code>term$</code></dt>
|
||||
<dd>Ends with</dd>
|
||||
<dt><code>a b</code></dt>
|
||||
<dd>Both (AND)</dd>
|
||||
<dt><code>a | b</code></dt>
|
||||
<dd>Either (OR)</dd>
|
||||
<dt><code>el.*spc</code></dt>
|
||||
<dd>Regex — any-char + any-sequence</dd>
|
||||
</dl>
|
||||
|
||||
<h3>Header buttons</h3>
|
||||
<dl>
|
||||
<dt>Add Local Directory</dt>
|
||||
|
|
|
|||
Loading…
Reference in a new issue