cursedbelt 5.34.0 → 5.35.0
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/react/file-tree/FileTree.d.ts +27 -1
- package/dist/react/file-tree/FileTree.d.ts.map +1 -1
- package/dist/react/file-tree/FileTree.js +183 -9
- package/dist/react/file-tree/FileTree.js.map +1 -1
- package/dist/react/file-tree/FolderViewMenus.d.ts +88 -0
- package/dist/react/file-tree/FolderViewMenus.d.ts.map +1 -0
- package/dist/react/file-tree/FolderViewMenus.js +121 -0
- package/dist/react/file-tree/FolderViewMenus.js.map +1 -0
- package/dist/react/file-tree/FolderViewPanels.d.ts +78 -0
- package/dist/react/file-tree/FolderViewPanels.d.ts.map +1 -0
- package/dist/react/file-tree/FolderViewPanels.js +155 -0
- package/dist/react/file-tree/FolderViewPanels.js.map +1 -0
- package/dist/react/file-tree/fileTree.css +146 -0
- package/dist/react/file-tree/folderView.d.ts +117 -0
- package/dist/react/file-tree/folderView.d.ts.map +1 -0
- package/dist/react/file-tree/folderView.js +230 -0
- package/dist/react/file-tree/folderView.js.map +1 -0
- package/dist/react/file-tree/folderViewPanels.css +217 -0
- package/dist/react/file-tree/index.d.ts +2 -0
- package/dist/react/file-tree/index.d.ts.map +1 -1
- package/dist/react/file-tree/index.js +9 -0
- package/dist/react/file-tree/index.js.map +1 -1
- package/dist/react/file-tree/useFolderView.d.ts +56 -0
- package/dist/react/file-tree/useFolderView.d.ts.map +1 -0
- package/dist/react/file-tree/useFolderView.js +79 -0
- package/dist/react/file-tree/useFolderView.js.map +1 -0
- package/dist/react/filter-rail/FilterRail.d.ts +7 -0
- package/dist/react/filter-rail/FilterRail.d.ts.map +1 -1
- package/dist/react/filter-rail/FilterRail.js +8 -1
- package/dist/react/filter-rail/FilterRail.js.map +1 -1
- package/dist/react/filter-rail/RailSection.d.ts +7 -1
- package/dist/react/filter-rail/RailSection.d.ts.map +1 -1
- package/dist/react/filter-rail/RailSection.js +5 -3
- package/dist/react/filter-rail/RailSection.js.map +1 -1
- package/dist/react/filter-rail/headerContextMenu.d.ts +8 -0
- package/dist/react/filter-rail/headerContextMenu.d.ts.map +1 -0
- package/dist/react/filter-rail/headerContextMenu.js +31 -0
- package/dist/react/filter-rail/headerContextMenu.js.map +1 -0
- package/dist/react/media/denseGallery.css +46 -0
- package/dist/react/media-gallery/rememberedPreference.d.ts +10 -1
- package/dist/react/media-gallery/rememberedPreference.d.ts.map +1 -1
- package/dist/react/media-gallery/rememberedPreference.js +12 -3
- package/dist/react/media-gallery/rememberedPreference.js.map +1 -1
- package/package.json +1 -1
- package/scripts/guardrails-baseline.json +1 -1
- package/src/react/file-tree/FileTree.tsx +323 -4
- package/src/react/file-tree/FolderViewMenus.tsx +242 -0
- package/src/react/file-tree/FolderViewPanels.tsx +402 -0
- package/src/react/file-tree/fileTree.css +146 -0
- package/src/react/file-tree/folderView.spec.ts +174 -0
- package/src/react/file-tree/folderView.ts +316 -0
- package/src/react/file-tree/folderViewPanels.css +217 -0
- package/src/react/file-tree/folderViewTree.spec.tsx +252 -0
- package/src/react/file-tree/index.ts +14 -0
- package/src/react/file-tree/useFolderView.ts +152 -0
- package/src/react/filter-rail/FilterRail.tsx +35 -6
- package/src/react/filter-rail/RailSection.tsx +10 -2
- package/src/react/filter-rail/headerContextMenu.spec.tsx +62 -0
- package/src/react/filter-rail/headerContextMenu.ts +37 -0
- package/src/react/media/denseGallery.css +46 -0
- package/src/react/media-gallery/rememberedPreference.ts +10 -2
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The file tree's right-click panels — the menus' own pieces, the tag filter and the tag editor.
|
|
3
|
+
*
|
|
4
|
+
* Its own stylesheet because its own CHUNK: `FolderViewPanels.tsx` is loaded on demand (see its
|
|
5
|
+
* header), and a bundler ships a lazily imported module's CSS with it. Plain `cbft-` CSS for the
|
|
6
|
+
* reason `fileTree.css` gives in its header.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* ── The menus' own pieces (the panel and its items are the belt's `Popover` and `Menu`) ── */
|
|
10
|
+
|
|
11
|
+
.cbft-menu-panel {
|
|
12
|
+
min-inline-size: 12rem;
|
|
13
|
+
max-inline-size: min(20rem, calc(100vw - 16px));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.cbft-fv-head {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: baseline;
|
|
19
|
+
justify-content: space-between;
|
|
20
|
+
gap: 0.5rem;
|
|
21
|
+
padding-inline-end: 0.5rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.cbft-fv-scope {
|
|
25
|
+
font-size: 0.75rem;
|
|
26
|
+
color: var(--muted-foreground);
|
|
27
|
+
cursor: help;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.cbft-fv-empty {
|
|
31
|
+
margin: 0;
|
|
32
|
+
padding: 0.25rem 0.5rem 0.5rem;
|
|
33
|
+
font-size: 0.75rem;
|
|
34
|
+
line-height: 1.4;
|
|
35
|
+
color: var(--muted-foreground);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* The belt's ScrollArea does the scrolling (and fades the cut edge); this only bounds it. */
|
|
39
|
+
.cbft-fv-scroll {
|
|
40
|
+
max-block-size: 15rem;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.cbft-fv-list {
|
|
44
|
+
list-style: none;
|
|
45
|
+
margin: 0;
|
|
46
|
+
padding: 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.cbft-fv-row {
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: 0.5rem;
|
|
53
|
+
min-block-size: 2rem;
|
|
54
|
+
padding: 0.125rem 0.25rem 0.125rem 0.5rem;
|
|
55
|
+
border-radius: var(--radius-sm, 0.375rem);
|
|
56
|
+
font-size: 0.875rem;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.cbft-fv-row:hover {
|
|
60
|
+
background: color-mix(in srgb, var(--muted-foreground) 8%, transparent);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.cbft-fv-name {
|
|
64
|
+
flex: 1 1 auto;
|
|
65
|
+
min-inline-size: 0;
|
|
66
|
+
overflow: hidden;
|
|
67
|
+
text-overflow: ellipsis;
|
|
68
|
+
white-space: nowrap;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.cbft-fv-count {
|
|
72
|
+
flex: none;
|
|
73
|
+
font-size: 0.75rem;
|
|
74
|
+
color: var(--muted-foreground);
|
|
75
|
+
font-variant-numeric: tabular-nums;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Two toggles, joined — a segmented control in miniature. Off is quiet; on is the accent. */
|
|
79
|
+
.cbft-fv-seg {
|
|
80
|
+
flex: none;
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
/* A <fieldset>, so the browser's own frame comes off first. */
|
|
83
|
+
margin: 0;
|
|
84
|
+
padding: 0;
|
|
85
|
+
min-inline-size: 0;
|
|
86
|
+
border: 1px solid var(--border);
|
|
87
|
+
border-radius: var(--radius-sm, 0.375rem);
|
|
88
|
+
overflow: hidden;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.cbft-fv-seg button {
|
|
92
|
+
border: 0;
|
|
93
|
+
background: transparent;
|
|
94
|
+
color: var(--muted-foreground);
|
|
95
|
+
font: inherit;
|
|
96
|
+
font-size: 0.75rem;
|
|
97
|
+
padding: 0.1875rem 0.5rem;
|
|
98
|
+
min-block-size: 1.5rem;
|
|
99
|
+
cursor: pointer;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.cbft-fv-seg button + button {
|
|
103
|
+
border-inline-start: 1px solid var(--border);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.cbft-fv-seg button:hover {
|
|
107
|
+
background: color-mix(in srgb, var(--muted-foreground) 12%, transparent);
|
|
108
|
+
color: var(--foreground);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.cbft-fv-seg button:focus-visible {
|
|
112
|
+
outline: 2px solid var(--ring, var(--accent-solid));
|
|
113
|
+
outline-offset: -2px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.cbft-fv-seg button[aria-pressed='true'] {
|
|
117
|
+
background: var(--accent-solid);
|
|
118
|
+
color: var(--accent-solid-foreground);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.cbft-fv-row[data-mode='hide'] .cbft-fv-name {
|
|
122
|
+
text-decoration: line-through;
|
|
123
|
+
color: var(--muted-foreground);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.cbft-fv-clear {
|
|
127
|
+
display: block;
|
|
128
|
+
inline-size: 100%;
|
|
129
|
+
margin-block-start: 0.25rem;
|
|
130
|
+
padding: 0.375rem 0.5rem;
|
|
131
|
+
border: 0;
|
|
132
|
+
border-radius: var(--radius-sm, 0.375rem);
|
|
133
|
+
background: transparent;
|
|
134
|
+
color: var(--accent);
|
|
135
|
+
font: inherit;
|
|
136
|
+
font-size: 0.8125rem;
|
|
137
|
+
text-align: start;
|
|
138
|
+
cursor: pointer;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.cbft-fv-clear:hover,
|
|
142
|
+
.cbft-fv-clear:focus-visible {
|
|
143
|
+
background: color-mix(in srgb, var(--muted-foreground) 10%, transparent);
|
|
144
|
+
outline: none;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* ── The tag editor — Gmail's "Label as" ─────────────────────────────────────────────── */
|
|
148
|
+
|
|
149
|
+
.cbft-te {
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
gap: 0.25rem;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.cbft-te-head {
|
|
156
|
+
padding: 0.25rem 0.5rem 0;
|
|
157
|
+
font-size: 0.8125rem;
|
|
158
|
+
font-weight: 600;
|
|
159
|
+
color: var(--foreground);
|
|
160
|
+
overflow: hidden;
|
|
161
|
+
text-overflow: ellipsis;
|
|
162
|
+
white-space: nowrap;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.cbft-te-input {
|
|
166
|
+
/* The belt's Input draws itself; this only spaces it inside the panel. */
|
|
167
|
+
margin: 0.25rem;
|
|
168
|
+
inline-size: auto;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.cbft-te-scroll {
|
|
172
|
+
max-block-size: 14rem;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.cbft-te-option {
|
|
176
|
+
display: flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
gap: 0.5rem;
|
|
179
|
+
min-block-size: 2rem;
|
|
180
|
+
padding: 0.25rem 0.5rem;
|
|
181
|
+
border-radius: var(--radius-sm, 0.375rem);
|
|
182
|
+
font-size: 0.875rem;
|
|
183
|
+
cursor: pointer;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.cbft-te-option[data-active] {
|
|
187
|
+
background: color-mix(in srgb, var(--muted-foreground) 14%, transparent);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.cbft-te-check {
|
|
191
|
+
flex: none;
|
|
192
|
+
inline-size: 1rem;
|
|
193
|
+
text-align: center;
|
|
194
|
+
color: var(--accent);
|
|
195
|
+
font-weight: 700;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.cbft-te-foot {
|
|
199
|
+
margin: 0;
|
|
200
|
+
padding: 0.25rem 0.5rem 0.375rem;
|
|
201
|
+
border-block-start: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
|
|
202
|
+
font-size: 0.75rem;
|
|
203
|
+
color: var(--muted-foreground);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* A coarse pointer gets the 44px hit targets every other control in this tree gets. */
|
|
207
|
+
@media (pointer: coarse) {
|
|
208
|
+
.cbft-fv-row,
|
|
209
|
+
.cbft-te-option {
|
|
210
|
+
min-block-size: 44px;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.cbft-fv-seg button {
|
|
214
|
+
min-block-size: 36px;
|
|
215
|
+
padding-inline: 0.75rem;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import type { FileTreeNode } from 'cursedbelt-core/file-tree/file-tree-model';
|
|
4
|
+
import { onPreferenceWrite } from '../media-gallery/preferenceBus.js';
|
|
5
|
+
import { FileTree, type FileTreeProps, preloadFileTreePanels } from './FileTree.js';
|
|
6
|
+
import { useFolderView } from './useFolderView.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hidden folders and folder tags, through the gestures the owner named: right-click a folder,
|
|
10
|
+
* right-click the blank space, right-click the app's header, ⇧⌘. — with the hook an app uses.
|
|
11
|
+
* The rules themselves are `folderView.spec.ts`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const KEY = 'test:folder-marks';
|
|
15
|
+
|
|
16
|
+
const folder = (id: string, name: string, children: FileTreeNode[] = []): FileTreeNode => ({
|
|
17
|
+
id,
|
|
18
|
+
name,
|
|
19
|
+
kind: 'folder',
|
|
20
|
+
children,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const TREE: FileTreeNode[] = [
|
|
24
|
+
folder('home', 'Home', [folder('photos', 'Photos')]),
|
|
25
|
+
folder('work', 'Work', [folder('dynatrace', 'Dynatrace')]),
|
|
26
|
+
{ id: 'readme', name: 'readme.md', kind: 'file' },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
function Harness(props: Partial<FileTreeProps>) {
|
|
30
|
+
const folderView = useFolderView({ key: KEY });
|
|
31
|
+
return (
|
|
32
|
+
<div>
|
|
33
|
+
{/* biome-ignore lint/a11y/noStaticElementInteractions: stands in for an app's header bar, whose right-click is exactly what is under test. */}
|
|
34
|
+
<div data-testid='header' onContextMenu={folderView.onContextMenu}>
|
|
35
|
+
Files
|
|
36
|
+
</div>
|
|
37
|
+
<FileTree
|
|
38
|
+
nodes={TREE}
|
|
39
|
+
selectedId={null}
|
|
40
|
+
onSelect={() => undefined}
|
|
41
|
+
folderView={folderView}
|
|
42
|
+
{...props}
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const row = (name: string) => screen.getByText(name).closest('[role="treeitem"]') as HTMLElement;
|
|
49
|
+
const blank = () => document.querySelector('.cbft-scroll') as HTMLElement;
|
|
50
|
+
const items = () =>
|
|
51
|
+
[...document.querySelectorAll<HTMLElement>('[role="menuitem"],[role="menuitemradio"]')];
|
|
52
|
+
/** The menu item whose text is `name` (or matches it) — a command or a toggle alike. */
|
|
53
|
+
const item = (name: RegExp | string): HTMLElement => {
|
|
54
|
+
const label = (el: HTMLElement) => el.querySelector('.truncate')?.textContent ?? el.textContent ?? '';
|
|
55
|
+
const found = items().find((el) =>
|
|
56
|
+
typeof name === 'string' ? label(el) === name : name.test(label(el)),
|
|
57
|
+
);
|
|
58
|
+
if (!found) throw new Error(`no menu item ${String(name)} — have: ${items().map(label).join(' | ')}`);
|
|
59
|
+
return found;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// The panels are a lazy chunk (`FolderViewPanels.tsx`); loaded, a new mount draws them at once.
|
|
63
|
+
beforeAll(() => preloadFileTreePanels());
|
|
64
|
+
beforeEach(() => globalThis.localStorage.clear());
|
|
65
|
+
afterEach(cleanup);
|
|
66
|
+
|
|
67
|
+
describe('hiding a folder', () => {
|
|
68
|
+
test('🔴 right-click a folder → Hide folder → it and its contents leave the tree', () => {
|
|
69
|
+
render(<Harness />);
|
|
70
|
+
fireEvent.contextMenu(row('Work'), { clientX: 10, clientY: 10 });
|
|
71
|
+
fireEvent.click(item('Hide folder'));
|
|
72
|
+
expect(screen.queryByText('Work')).toBeNull();
|
|
73
|
+
expect(screen.queryByText('Dynatrace')).toBeNull();
|
|
74
|
+
expect(screen.getByText('Home')).toBeDefined();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('🔴 "Show hidden folders" draws them back — the hidden one italic-marked, its contents faded-marked', () => {
|
|
78
|
+
render(<Harness />);
|
|
79
|
+
fireEvent.contextMenu(row('Work'));
|
|
80
|
+
fireEvent.click(item('Hide folder'));
|
|
81
|
+
fireEvent.contextMenu(blank(), { clientX: 5, clientY: 300 });
|
|
82
|
+
fireEvent.click(item(/Show hidden folders \(1\)/));
|
|
83
|
+
expect(row('Work').getAttribute('data-hidden')).toBe('self');
|
|
84
|
+
expect(row('Work').querySelector('.cbft-hidden-mark')).not.toBeNull();
|
|
85
|
+
expect(row('Dynatrace').getAttribute('data-hidden')).toBe('inherited');
|
|
86
|
+
expect(row('Dynatrace').querySelector('.cbft-hidden-mark')).toBeNull();
|
|
87
|
+
expect(row('Home').getAttribute('data-hidden')).toBeNull();
|
|
88
|
+
// Still hideable — the owner's "showing hidden folders still keeps them hideable": its own
|
|
89
|
+
// menu now offers the way back.
|
|
90
|
+
fireEvent.contextMenu(row('Work'));
|
|
91
|
+
fireEvent.click(item('Unhide folder'));
|
|
92
|
+
expect(row('Work').getAttribute('data-hidden')).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('the strip says hidden folders are showing, and its button leaves them out again', () => {
|
|
96
|
+
render(<Harness />);
|
|
97
|
+
fireEvent.contextMenu(row('Work'));
|
|
98
|
+
fireEvent.click(item('Hide folder'));
|
|
99
|
+
fireEvent.contextMenu(blank());
|
|
100
|
+
fireEvent.click(item(/Show hidden folders/));
|
|
101
|
+
expect(screen.getByText('Showing hidden')).toBeDefined();
|
|
102
|
+
fireEvent.click(screen.getByRole('button', { name: 'Hide' }));
|
|
103
|
+
expect(screen.queryByText('Work')).toBeNull();
|
|
104
|
+
expect(screen.queryByText('Showing hidden')).toBeNull();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('⇧⌘. on a row toggles hidden folders — Finder\'s chord', () => {
|
|
108
|
+
render(<Harness />);
|
|
109
|
+
fireEvent.contextMenu(row('Work'));
|
|
110
|
+
fireEvent.click(item('Hide folder'));
|
|
111
|
+
fireEvent.keyDown(row('Home'), { key: '>', code: 'Period', shiftKey: true, metaKey: true });
|
|
112
|
+
expect(row('Work').getAttribute('data-hidden')).toBe('self');
|
|
113
|
+
fireEvent.keyDown(row('Home'), { key: '>', code: 'Period', shiftKey: true, metaKey: true });
|
|
114
|
+
expect(screen.queryByText('Work')).toBeNull();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe('the view menu', () => {
|
|
119
|
+
test('🔴 right-click (⌃-click) on the APP\'s header opens the same menu as the blank space', () => {
|
|
120
|
+
render(<Harness />);
|
|
121
|
+
const event = fireEvent.contextMenu(screen.getByTestId('header'), { clientX: 4, clientY: 4 });
|
|
122
|
+
expect(event).toBe(false); // the browser's menu was refused
|
|
123
|
+
expect(item(/Show hidden folders/)).toBeDefined();
|
|
124
|
+
expect(item('Collapse all folders')).toBeDefined();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('"Collapse all folders" shuts every folder', () => {
|
|
128
|
+
render(<Harness />);
|
|
129
|
+
expect(screen.getByText('Photos')).toBeDefined();
|
|
130
|
+
fireEvent.contextMenu(blank());
|
|
131
|
+
fireEvent.click(item('Collapse all folders'));
|
|
132
|
+
expect(screen.queryByText('Photos')).toBeNull();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('an app\'s own background items come first', () => {
|
|
136
|
+
let made = 0;
|
|
137
|
+
render(<Harness backgroundMenu={() => [{ key: 'new', label: 'New folder', onClick: () => made++ }]} />);
|
|
138
|
+
fireEvent.contextMenu(blank());
|
|
139
|
+
fireEvent.click(item('New folder'));
|
|
140
|
+
expect(made).toBe(1);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('tags', () => {
|
|
145
|
+
const tag = (folderName: string, word: string) => {
|
|
146
|
+
fireEvent.contextMenu(row(folderName));
|
|
147
|
+
fireEvent.click(item('Tags…'));
|
|
148
|
+
const field = screen.getByRole('combobox', { name: 'Find or create a tag' });
|
|
149
|
+
fireEvent.change(field, { target: { value: word } });
|
|
150
|
+
fireEvent.keyDown(field, { key: 'Enter' });
|
|
151
|
+
fireEvent.keyDown(field, { key: 'Escape' });
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
test('🔴 Tags… creates a tag by typing it, and the row wears its dot', () => {
|
|
155
|
+
render(<Harness />);
|
|
156
|
+
tag('Home', 'Home');
|
|
157
|
+
expect(row('Home').querySelector('.cbft-tagdot')).not.toBeNull();
|
|
158
|
+
expect(row('Home').querySelector('[aria-label="Tags: home"]')).not.toBeNull();
|
|
159
|
+
expect(row('Work').querySelector('.cbft-tagdot')).toBeNull();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('🔴 "Only" a tag narrows this device\'s tree; the strip says so; Clear brings everything back', () => {
|
|
163
|
+
render(<Harness />);
|
|
164
|
+
tag('Home', 'home');
|
|
165
|
+
tag('Work', 'work');
|
|
166
|
+
fireEvent.contextMenu(blank());
|
|
167
|
+
const only = screen.getByRole('group', { name: 'Filter by home' }).querySelector('button') as HTMLElement;
|
|
168
|
+
fireEvent.click(only);
|
|
169
|
+
expect(only.getAttribute('aria-pressed')).toBe('true');
|
|
170
|
+
expect(screen.queryByText('Work')).toBeNull();
|
|
171
|
+
expect(screen.getByText('Photos')).toBeDefined(); // a tagged folder keeps what is in it
|
|
172
|
+
expect(screen.getByText('readme.md')).toBeDefined(); // a top-level file is in no folder
|
|
173
|
+
fireEvent.keyDown(document.activeElement ?? document.body, { key: 'Escape' });
|
|
174
|
+
fireEvent.click(screen.getByRole('button', { name: 'Clear' }));
|
|
175
|
+
expect(screen.getByText('Work')).toBeDefined();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('a FILE has no Hide or Tags — the feature is about folders', () => {
|
|
179
|
+
render(<Harness />);
|
|
180
|
+
const event = fireEvent.contextMenu(row('readme.md'));
|
|
181
|
+
expect(event).toBe(true); // nothing to offer, so the browser keeps its own menu
|
|
182
|
+
expect(items()).toHaveLength(0);
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
describe('🔴 what reaches other devices, and what does not', () => {
|
|
187
|
+
test('hiding and tagging are ANNOUNCED (an app syncs them); the tag filter and show-hidden are not', () => {
|
|
188
|
+
const heard: string[] = [];
|
|
189
|
+
const stop = onPreferenceWrite((key) => heard.push(key));
|
|
190
|
+
try {
|
|
191
|
+
render(<Harness />);
|
|
192
|
+
fireEvent.contextMenu(row('Work'));
|
|
193
|
+
fireEvent.click(item('Hide folder'));
|
|
194
|
+
expect(heard).toEqual([KEY]);
|
|
195
|
+
fireEvent.contextMenu(blank());
|
|
196
|
+
fireEvent.click(item(/Show hidden folders/));
|
|
197
|
+
expect(heard).toEqual([KEY]);
|
|
198
|
+
expect(globalThis.localStorage.getItem(`${KEY}:device`)).toContain('"showHidden":true');
|
|
199
|
+
} finally {
|
|
200
|
+
stop();
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe('a row menu of the app\'s own', () => {
|
|
206
|
+
test('rowMenu items open on right-click, with Hide and Tags… after them on a folder', () => {
|
|
207
|
+
let renamed = '';
|
|
208
|
+
render(
|
|
209
|
+
<Harness
|
|
210
|
+
rowMenu={(node) => [{ key: 'rename', label: 'Rename', onClick: () => (renamed = node.id) }]}
|
|
211
|
+
/>,
|
|
212
|
+
);
|
|
213
|
+
fireEvent.contextMenu(row('Home'));
|
|
214
|
+
const labels = items().map((el) => el.textContent);
|
|
215
|
+
expect(labels[0]).toBe('Rename');
|
|
216
|
+
expect(labels.some((l) => l?.startsWith('Hide folder'))).toBe(true);
|
|
217
|
+
fireEvent.click(item('Rename'));
|
|
218
|
+
expect(renamed).toBe('home');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('Hide and Tags… go ABOVE a trailing Delete — Delete stays last, under its rule', () => {
|
|
222
|
+
render(
|
|
223
|
+
<Harness
|
|
224
|
+
rowMenu={() => [
|
|
225
|
+
{ key: 'rename', label: 'Rename' },
|
|
226
|
+
{ key: 'sep', divider: true },
|
|
227
|
+
{ key: 'delete', label: 'Delete folder', destructive: true },
|
|
228
|
+
]}
|
|
229
|
+
/>,
|
|
230
|
+
);
|
|
231
|
+
fireEvent.contextMenu(row('Home'));
|
|
232
|
+
expect(items().map((el) => el.querySelector('.truncate')?.textContent)).toEqual([
|
|
233
|
+
'Rename',
|
|
234
|
+
'Hide folder',
|
|
235
|
+
'Tags…',
|
|
236
|
+
'Delete folder',
|
|
237
|
+
]);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('Shift+F10 opens the same menu from the keyboard', () => {
|
|
241
|
+
render(<Harness />);
|
|
242
|
+
act(() => row('Home').focus());
|
|
243
|
+
fireEvent.keyDown(row('Home'), { key: 'F10', shiftKey: true });
|
|
244
|
+
expect(item('Hide folder')).toBeDefined();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('a tree with neither rowMenu nor folderView leaves right-click to the browser', () => {
|
|
248
|
+
render(<FileTree nodes={TREE} selectedId={null} onSelect={() => undefined} />);
|
|
249
|
+
expect(fireEvent.contextMenu(row('Home'))).toBe(true);
|
|
250
|
+
expect(fireEvent.contextMenu(blank())).toBe(true);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
@@ -52,3 +52,17 @@ export {
|
|
|
52
52
|
type WrapPlan,
|
|
53
53
|
wrapFolderName,
|
|
54
54
|
} from './fileTreeSelection.js';
|
|
55
|
+
/*
|
|
56
|
+
* Hidden folders and folder tags (owner, 2026-09-30) — `useFolderView({ key })` handed to the
|
|
57
|
+
* tree's `folderView` prop, and its `onContextMenu` on the app's header over the tree. The rules
|
|
58
|
+
* are DOM-free in `folderView.ts`; the menus, tag editor and strip are `FolderViewMenus.tsx`.
|
|
59
|
+
* `folderViewMenuItems` is for an app's own ⋯ menu, so it offers exactly what the right-click
|
|
60
|
+
* does; `FileTreeMenuItem` is `DropdownMenuItem`'s shape, for `rowMenu`/`backgroundMenu`.
|
|
61
|
+
*/
|
|
62
|
+
export {
|
|
63
|
+
type FileTreeMenuItem,
|
|
64
|
+
folderTargets,
|
|
65
|
+
folderViewMenuItems,
|
|
66
|
+
withFolderItems,
|
|
67
|
+
} from './FolderViewMenus.js';
|
|
68
|
+
export { type FolderView, type UseFolderViewOptions, useFolderView } from './useFolderView.js';
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useFolderView` — hidden folders and folder tags for one {@link FileTree}, remembered.
|
|
3
|
+
*
|
|
4
|
+
* const folderView = useFolderView({ key: 'collections:folder-marks' });
|
|
5
|
+
* <FileTree folderView={folderView} … />
|
|
6
|
+
* <header onContextMenu={folderView.onContextMenu}>Files</header>
|
|
7
|
+
*
|
|
8
|
+
* The arithmetic is `folderView.ts`; this is where the two halves are KEPT, and the reason it
|
|
9
|
+
* is a hook rather than two more controlled props on the tree:
|
|
10
|
+
*
|
|
11
|
+
* · the MARKS (hidden, tags) are stored under `key` and announced on the preference bus, the
|
|
12
|
+
* seam every synced setting in this package uses (`preferenceSync.ts`). An app that keeps
|
|
13
|
+
* preferences on its server lists `key` once and the marks follow the person to every
|
|
14
|
+
* device — *"The general hiding is persisted for all machines."* An app that does not still
|
|
15
|
+
* remembers them in this browser, so the feature works before anyone wires a server.
|
|
16
|
+
* · the VIEW (show hidden, the tag filter) is stored under `${key}:device` and is NEVER
|
|
17
|
+
* announced — *"Hiding or showing by tag can be stored per machine, so viewing the 'home'
|
|
18
|
+
* tag at home doesn't change my work computer."*
|
|
19
|
+
*
|
|
20
|
+
* And because the tree's header belongs to the APP (collections' `FilterRail` section, desk's
|
|
21
|
+
* explorer bar), the view menu has to be openable from outside the tree: the hook holds which
|
|
22
|
+
* menu is open, and the tree draws it. `onContextMenu` is the one handler an app puts on its
|
|
23
|
+
* header so right-click and ⌃-click there open the same menu as the tree's blank space.
|
|
24
|
+
*/
|
|
25
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
26
|
+
import { useRememberedPreference } from '../media-gallery/rememberedPreference.js';
|
|
27
|
+
import {
|
|
28
|
+
type FolderMarks,
|
|
29
|
+
type FolderViewLocal,
|
|
30
|
+
normalizeTag,
|
|
31
|
+
parseFolderMarks,
|
|
32
|
+
parseFolderViewLocal,
|
|
33
|
+
serializeFolderMarks,
|
|
34
|
+
setFolderTags,
|
|
35
|
+
setHidden,
|
|
36
|
+
setTagFilter,
|
|
37
|
+
type TagCount,
|
|
38
|
+
tagCounts,
|
|
39
|
+
toggleFolderTag,
|
|
40
|
+
} from './folderView.js';
|
|
41
|
+
|
|
42
|
+
/** A point in viewport coordinates — what a context menu anchors to. */
|
|
43
|
+
export interface FolderViewPoint {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Which of the tree's folder-view panels is open, if one is. */
|
|
49
|
+
export type FolderViewPanel =
|
|
50
|
+
| { kind: 'view'; at: FolderViewPoint }
|
|
51
|
+
| { kind: 'tags'; at: FolderViewPoint | null; ids: readonly string[] };
|
|
52
|
+
|
|
53
|
+
export interface FolderView {
|
|
54
|
+
marks: FolderMarks;
|
|
55
|
+
local: FolderViewLocal;
|
|
56
|
+
/** Every tag in use, most-used first. */
|
|
57
|
+
tags: readonly TagCount[];
|
|
58
|
+
|
|
59
|
+
hide: (ids: readonly string[]) => void;
|
|
60
|
+
unhide: (ids: readonly string[]) => void;
|
|
61
|
+
/** Add or take away one tag on each folder named. */
|
|
62
|
+
toggleTag: (ids: readonly string[], tag: string) => void;
|
|
63
|
+
/** Replace one folder's tags. */
|
|
64
|
+
setTags: (id: string, tags: readonly string[]) => void;
|
|
65
|
+
|
|
66
|
+
setShowHidden: (show: boolean) => void;
|
|
67
|
+
/** Put one tag in this device's filter: only folders carrying it, none carrying it, or neither. */
|
|
68
|
+
filterTag: (tag: string, mode: 'only' | 'hide' | null) => void;
|
|
69
|
+
clearTagFilter: () => void;
|
|
70
|
+
|
|
71
|
+
/** The open panel — read by the tree, which draws it. */
|
|
72
|
+
panel: FolderViewPanel | null;
|
|
73
|
+
openViewMenu: (at: FolderViewPoint) => void;
|
|
74
|
+
/** Open the tag editor for these folders; `at` omitted anchors it to the first one's row. */
|
|
75
|
+
openTagEditor: (ids: readonly string[], at?: FolderViewPoint) => void;
|
|
76
|
+
closePanel: () => void;
|
|
77
|
+
/**
|
|
78
|
+
* For the APP's header over the tree: right-click (and ⌃-click, which macOS turns into a
|
|
79
|
+
* `contextmenu` by itself) opens the view menu at the pointer instead of the browser's.
|
|
80
|
+
*/
|
|
81
|
+
onContextMenu: (event: { clientX: number; clientY: number; preventDefault: () => void }) => void;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface UseFolderViewOptions {
|
|
85
|
+
/**
|
|
86
|
+
* Where the marks are remembered, and the name they are announced under. Name it per tree
|
|
87
|
+
* (`'collections:folder-marks'`) for the reason `FilterRail.resizeKey` is: two trees on one
|
|
88
|
+
* origin must not hide each other's folders.
|
|
89
|
+
*/
|
|
90
|
+
key: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function useFolderView({ key }: UseFolderViewOptions): FolderView {
|
|
94
|
+
const [rawMarks, writeMarks] = useRememberedPreference(key);
|
|
95
|
+
const [rawLocal, writeLocal] = useRememberedPreference(`${key}:device`, { announce: false });
|
|
96
|
+
const marks = useMemo(() => parseFolderMarks(rawMarks), [rawMarks]);
|
|
97
|
+
const local = useMemo(() => parseFolderViewLocal(rawLocal), [rawLocal]);
|
|
98
|
+
const tags = useMemo(() => tagCounts(marks), [marks]);
|
|
99
|
+
const [panel, setPanel] = useState<FolderViewPanel | null>(null);
|
|
100
|
+
|
|
101
|
+
const saveMarks = useCallback(
|
|
102
|
+
(next: FolderMarks) => {
|
|
103
|
+
if (next !== marks) writeMarks(serializeFolderMarks(next));
|
|
104
|
+
},
|
|
105
|
+
[marks, writeMarks],
|
|
106
|
+
);
|
|
107
|
+
const saveLocal = useCallback(
|
|
108
|
+
(next: FolderViewLocal) => {
|
|
109
|
+
const empty = !next.showHidden && next.only.length === 0 && next.hide.length === 0;
|
|
110
|
+
writeLocal(empty ? null : JSON.stringify(next));
|
|
111
|
+
},
|
|
112
|
+
[writeLocal],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const onContextMenu = useCallback((event: { clientX: number; clientY: number; preventDefault: () => void }) => {
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
setPanel({ kind: 'view', at: { x: event.clientX, y: event.clientY } });
|
|
118
|
+
}, []);
|
|
119
|
+
|
|
120
|
+
return useMemo<FolderView>(
|
|
121
|
+
() => ({
|
|
122
|
+
marks,
|
|
123
|
+
local,
|
|
124
|
+
tags,
|
|
125
|
+
hide: (ids) => saveMarks(setHidden(marks, ids, true)),
|
|
126
|
+
unhide: (ids) => saveMarks(setHidden(marks, ids, false)),
|
|
127
|
+
toggleTag: (ids, raw) => {
|
|
128
|
+
const tag = normalizeTag(raw);
|
|
129
|
+
if (!tag || ids.length === 0) return;
|
|
130
|
+
// Several folders take the tag together: if every one already has it, it comes off
|
|
131
|
+
// all of them; otherwise it goes on the ones missing it — Finder's mixed-state rule.
|
|
132
|
+
const all = ids.every((id) => (marks.tags[id] ?? []).includes(tag));
|
|
133
|
+
let next = marks;
|
|
134
|
+
for (const id of ids) {
|
|
135
|
+
const has = (next.tags[id] ?? []).includes(tag);
|
|
136
|
+
if (all || !has) next = toggleFolderTag(next, id, tag);
|
|
137
|
+
}
|
|
138
|
+
saveMarks(next);
|
|
139
|
+
},
|
|
140
|
+
setTags: (id, list) => saveMarks(setFolderTags(marks, id, list)),
|
|
141
|
+
setShowHidden: (show) => saveLocal({ ...local, showHidden: show }),
|
|
142
|
+
filterTag: (tag, mode) => saveLocal(setTagFilter(local, tag, mode)),
|
|
143
|
+
clearTagFilter: () => saveLocal({ ...local, only: [], hide: [] }),
|
|
144
|
+
panel,
|
|
145
|
+
openViewMenu: (at) => setPanel({ kind: 'view', at }),
|
|
146
|
+
openTagEditor: (ids, at) => setPanel({ kind: 'tags', at: at ?? null, ids }),
|
|
147
|
+
closePanel: () => setPanel(null),
|
|
148
|
+
onContextMenu,
|
|
149
|
+
}),
|
|
150
|
+
[marks, local, tags, panel, saveMarks, saveLocal, onContextMenu],
|
|
151
|
+
);
|
|
152
|
+
}
|