mirror of
https://github.com/multipleof4/octopus-file-browser.git
synced 2026-09-25 12:35:25 +00:00
Add an opt-in context menu for files and directories
Apps set browser.contextMenu to a list of { label, action, when?, danger? }
items; when(entry, path) scopes an item to directories, files, or any
other match. Right-click, the Menu key, or a touch long press opens it.
The demo adds sample items, including a .json-only one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { fileKindLabel, formatFileSize, formatRelativeDate, isRecent, sortEntries } from '../src/file-browser-utils.js';
|
||||
import { fileKindLabel, formatFileSize, formatRelativeDate, isRecent, menuItemsFor, sortEntries } from '../src/file-browser-utils.js';
|
||||
|
||||
test('sortEntries keeps folders first and names natural', () => {
|
||||
const sorted = sortEntries([
|
||||
@@ -36,3 +36,15 @@ test('fileKindLabel identifies special and common files', () => {
|
||||
assert.equal(fileKindLabel('app.js'), 'JavaScript');
|
||||
assert.equal(fileKindLabel('Dockerfile'), 'File');
|
||||
});
|
||||
|
||||
test('menuItemsFor keeps items whose when() matches the entry', () => {
|
||||
const items = [
|
||||
{ label: 'All' },
|
||||
{ label: 'Folders', when: (entry) => entry.type === 'directory' },
|
||||
{ label: 'JSON', when: (entry, path) => entry.name.endsWith('.json') && path.length === 2 },
|
||||
];
|
||||
const labels = (entry, path) => menuItemsFor(items, entry, path).map(({ label }) => label);
|
||||
assert.deepEqual(labels({ name: 'src', type: 'directory' }, ['src']), ['All', 'Folders']);
|
||||
assert.deepEqual(labels({ name: 'a.json', type: 'file' }, ['src', 'a.json']), ['All', 'JSON']);
|
||||
assert.deepEqual(menuItemsFor(undefined, { name: 'a', type: 'file' }, ['a']), []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user