@brftech/filex-core 0.1.56
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/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/ArchiveViewer-CJdaw5x3.js +99 -0
- package/dist/ArchiveViewer-CJdaw5x3.js.map +1 -0
- package/dist/CsvViewer-QYx_tePQ.js +132 -0
- package/dist/CsvViewer-QYx_tePQ.js.map +1 -0
- package/dist/DrawioViewer-GWt0TyB7.js +141 -0
- package/dist/DrawioViewer-GWt0TyB7.js.map +1 -0
- package/dist/EpubViewer-Je0ywklQ.js +146 -0
- package/dist/EpubViewer-Je0ywklQ.js.map +1 -0
- package/dist/IpynbViewer-TsB4gqP-.js +175 -0
- package/dist/IpynbViewer-TsB4gqP-.js.map +1 -0
- package/dist/MermaidViewer-CXfeDS-7.js +128 -0
- package/dist/MermaidViewer-CXfeDS-7.js.map +1 -0
- package/dist/PsdViewer-VtPpxKVe.js +113 -0
- package/dist/PsdViewer-VtPpxKVe.js.map +1 -0
- package/dist/TiffViewer-OINn9bbb.js +133 -0
- package/dist/TiffViewer-OINn9bbb.js.map +1 -0
- package/dist/UTIF-Cjsrlm0l.js +3104 -0
- package/dist/UTIF-Cjsrlm0l.js.map +1 -0
- package/dist/Viewer3D-xvvyiWHd.js +61 -0
- package/dist/Viewer3D-xvvyiWHd.js.map +1 -0
- package/dist/_commonjsHelpers-DaMA6jEr.js +9 -0
- package/dist/_commonjsHelpers-DaMA6jEr.js.map +1 -0
- package/dist/filex-core.js +26 -0
- package/dist/filex-core.js.map +1 -0
- package/dist/filex-core.umd.cjs +285 -0
- package/dist/filex-core.umd.cjs.map +1 -0
- package/dist/index-CmSYzt6L.js +5404 -0
- package/dist/index-CmSYzt6L.js.map +1 -0
- package/dist/index-UFULWo35.js +10736 -0
- package/dist/index-UFULWo35.js.map +1 -0
- package/dist/index.d.ts +1089 -0
- package/dist/katex-yuB6V-q6.js +11616 -0
- package/dist/katex-yuB6V-q6.js.map +1 -0
- package/dist/papaparse.min-VB1HBwYX.js +441 -0
- package/dist/papaparse.min-VB1HBwYX.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/useViewerFetch-czqbd2Lj.js +25 -0
- package/dist/useViewerFetch-czqbd2Lj.js.map +1 -0
- package/package.json +113 -0
- package/src/FileExplorer.vue +1872 -0
- package/src/components/Breadcrumb.vue +282 -0
- package/src/components/ContextMenu.vue +152 -0
- package/src/components/GridView.vue +166 -0
- package/src/components/ListView.vue +212 -0
- package/src/components/PendingOpsTray.vue +91 -0
- package/src/components/RecentlyOpened.vue +155 -0
- package/src/components/StarButton.vue +101 -0
- package/src/components/TagPicker.vue +184 -0
- package/src/components/Toolbar.vue +220 -0
- package/src/components/UploadProgress.vue +78 -0
- package/src/composables/useFileApi.ts +692 -0
- package/src/composables/useKeyboardShortcuts.ts +144 -0
- package/src/composables/useLocale.ts +60 -0
- package/src/composables/useMonacoLoader.ts +98 -0
- package/src/composables/usePendingOps.ts +200 -0
- package/src/composables/useSelection.ts +81 -0
- package/src/composables/useUploadChunked.ts +250 -0
- package/src/composables/useViewerFetch.ts +58 -0
- package/src/index.ts +80 -0
- package/src/locales/en.ts +122 -0
- package/src/locales/index.ts +12 -0
- package/src/locales/tr.ts +122 -0
- package/src/modals/ConvertModal.vue +254 -0
- package/src/modals/DeleteConfirmModal.vue +32 -0
- package/src/modals/Modal.vue +104 -0
- package/src/modals/NewFolderModal.vue +64 -0
- package/src/modals/PermissionsModal.vue +815 -0
- package/src/modals/PreviewModal.vue +1070 -0
- package/src/modals/RenameModal.vue +58 -0
- package/src/modals/ShareModal.vue +135 -0
- package/src/styles/base.css +1224 -0
- package/src/styles/variables.css +90 -0
- package/src/types/ExplorerConfig.ts +282 -0
- package/src/types/FileNode.ts +136 -0
- package/src/types/index.ts +27 -0
- package/src/types/peers.d.ts +45 -0
- package/src/viewers/ArchiveViewer.vue +186 -0
- package/src/viewers/CsvViewer.vue +319 -0
- package/src/viewers/DrawioViewer.vue +243 -0
- package/src/viewers/EpubViewer.vue +307 -0
- package/src/viewers/IpynbViewer.vue +365 -0
- package/src/viewers/MermaidViewer.vue +259 -0
- package/src/viewers/PdfViewer.vue +562 -0
- package/src/viewers/PsdViewer.vue +264 -0
- package/src/viewers/TiffViewer.vue +273 -0
- package/src/viewers/Viewer3D.vue +120 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* ListView — tabular layout (name / size / modified).
|
|
4
|
+
*
|
|
5
|
+
* Selection + context menu + double-click open are caller-owned — we
|
|
6
|
+
* just emit the events and let FileExplorer.vue handle them uniformly
|
|
7
|
+
* across List and Grid.
|
|
8
|
+
*/
|
|
9
|
+
import { computed } from 'vue';
|
|
10
|
+
import type { FileNode } from '../types/FileNode';
|
|
11
|
+
import type { LocaleCode } from '../types/ExplorerConfig';
|
|
12
|
+
import { useLocale } from '../composables/useLocale';
|
|
13
|
+
import StarButton from './StarButton.vue';
|
|
14
|
+
|
|
15
|
+
const props = defineProps<{
|
|
16
|
+
files: FileNode[];
|
|
17
|
+
selected: Set<string>;
|
|
18
|
+
/** Paths that were cut → dim them so the user sees the pending move. */
|
|
19
|
+
clipped?: Set<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Show each row's parent directory under the basename. Caller flips
|
|
22
|
+
* this on while a search filter is active so the user can tell
|
|
23
|
+
* `invoice.pdf` (in 2024/) apart from `invoice.pdf` (in 2025/) when
|
|
24
|
+
* both match the same query.
|
|
25
|
+
*/
|
|
26
|
+
showParentPath?: boolean;
|
|
27
|
+
locale: LocaleCode;
|
|
28
|
+
loading?: boolean;
|
|
29
|
+
/** Set of node IDs flagged starred by the user — render an inline
|
|
30
|
+
* filled star indicator and let the user toggle it from the row. */
|
|
31
|
+
starredIds?: Set<number>;
|
|
32
|
+
/** Backend base URL + auth header builder forwarded to StarButton
|
|
33
|
+
* so it can POST /api/files/manager/star on click. Optional —
|
|
34
|
+
* embedders without auth wire-up pass nothing and the star column
|
|
35
|
+
* hides itself. */
|
|
36
|
+
apiBase?: string;
|
|
37
|
+
authHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
38
|
+
}>();
|
|
39
|
+
|
|
40
|
+
const emit = defineEmits<{
|
|
41
|
+
(e: 'click-row', node: FileNode, mod: { ctrl: boolean; shift: boolean }): void;
|
|
42
|
+
(e: 'dbl-row', node: FileNode): void;
|
|
43
|
+
(e: 'context-row', node: FileNode, ev: MouseEvent): void;
|
|
44
|
+
(e: 'item-drag-start', node: FileNode, ev: DragEvent): void;
|
|
45
|
+
(e: 'item-drop-into', target: FileNode, ev: DragEvent): void;
|
|
46
|
+
(e: 'star-change', node: FileNode, value: boolean): void;
|
|
47
|
+
}>();
|
|
48
|
+
|
|
49
|
+
const { t, formatSize, nodeDisplayName } = useLocale(() => props.locale);
|
|
50
|
+
|
|
51
|
+
function isSelected(n: FileNode): boolean {
|
|
52
|
+
return props.selected.has(n.path);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function onRowClick(n: FileNode, ev: MouseEvent) {
|
|
56
|
+
emit('click-row', n, { ctrl: ev.ctrlKey || ev.metaKey, shift: ev.shiftKey });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function onRowDbl(n: FileNode) {
|
|
60
|
+
emit('dbl-row', n);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function onRowCtx(n: FileNode, ev: MouseEvent) {
|
|
64
|
+
// Stop bubbling so the root `@contextmenu` handler doesn't fire and
|
|
65
|
+
// clear the selection we just set.
|
|
66
|
+
ev.preventDefault();
|
|
67
|
+
ev.stopPropagation();
|
|
68
|
+
emit('context-row', n, ev);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function onItemDragStart(n: FileNode, ev: DragEvent) {
|
|
72
|
+
emit('item-drag-start', n, ev);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function onItemDragOver(n: FileNode, ev: DragEvent) {
|
|
76
|
+
if (n.type !== 'dir') return;
|
|
77
|
+
if (!ev.dataTransfer?.types.includes('application/x-brf-files')) return;
|
|
78
|
+
ev.preventDefault();
|
|
79
|
+
ev.stopPropagation();
|
|
80
|
+
if (ev.dataTransfer) ev.dataTransfer.dropEffect = 'move';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function onItemDrop(n: FileNode, ev: DragEvent) {
|
|
84
|
+
if (n.type !== 'dir') return;
|
|
85
|
+
if (!ev.dataTransfer?.types.includes('application/x-brf-files')) return;
|
|
86
|
+
ev.preventDefault();
|
|
87
|
+
ev.stopPropagation();
|
|
88
|
+
emit('item-drop-into', n, ev);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let pressTimer: ReturnType<typeof setTimeout> | undefined;
|
|
92
|
+
let pressTarget: FileNode | null = null;
|
|
93
|
+
|
|
94
|
+
function onTouchStart(n: FileNode, ev: TouchEvent) {
|
|
95
|
+
pressTarget = n;
|
|
96
|
+
if (pressTimer) clearTimeout(pressTimer);
|
|
97
|
+
pressTimer = setTimeout(() => {
|
|
98
|
+
if (pressTarget) {
|
|
99
|
+
const t0 = ev.touches[0];
|
|
100
|
+
emit('context-row', pressTarget, {
|
|
101
|
+
clientX: t0.clientX,
|
|
102
|
+
clientY: t0.clientY,
|
|
103
|
+
preventDefault: () => {},
|
|
104
|
+
} as unknown as MouseEvent);
|
|
105
|
+
}
|
|
106
|
+
}, 500);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function cancelPress() {
|
|
110
|
+
if (pressTimer) clearTimeout(pressTimer);
|
|
111
|
+
pressTarget = null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function iconFor(n: FileNode): string {
|
|
115
|
+
if (n.mime_type === 'inode/storage') return '💾';
|
|
116
|
+
if (n.type === 'dir') return '📁';
|
|
117
|
+
const e = (n.extension || '').toLowerCase();
|
|
118
|
+
if (['jpg', 'jpeg', 'png', 'webp', 'gif', 'bmp', 'avif', 'heic', 'svg'].includes(e)) return '🖼';
|
|
119
|
+
if (['mp4', 'webm', 'mov', 'mkv', 'avi', 'ogv', 'm4v'].includes(e)) return '🎞';
|
|
120
|
+
if (['mp3', 'wav', 'flac', 'ogg', 'm4a', 'aac', 'opus'].includes(e)) return '🎵';
|
|
121
|
+
if (e === 'pdf') return '📕';
|
|
122
|
+
if (['doc', 'docx', 'odt', 'rtf'].includes(e)) return '📄';
|
|
123
|
+
if (['xls', 'xlsx', 'ods', 'csv'].includes(e)) return '📊';
|
|
124
|
+
if (['ppt', 'pptx', 'odp'].includes(e)) return '📽';
|
|
125
|
+
if (['zip', 'tar', 'gz', 'bz2', '7z', 'rar'].includes(e)) return '🗜';
|
|
126
|
+
if (['txt', 'md', 'log', 'json', 'yml', 'yaml', 'xml'].includes(e)) return '📝';
|
|
127
|
+
return '📎';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function displayDate(ms: number | undefined): string {
|
|
131
|
+
if (!ms) return '—';
|
|
132
|
+
const d = new Date(ms * (ms < 1e12 ? 1000 : 1));
|
|
133
|
+
return d.toLocaleString();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function parentDir(path: string): string {
|
|
137
|
+
const stripped = path.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '');
|
|
138
|
+
const idx = stripped.lastIndexOf('/');
|
|
139
|
+
if (idx === -1) return '';
|
|
140
|
+
return stripped.slice(0, idx);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const rows = computed(() => props.files);
|
|
144
|
+
</script>
|
|
145
|
+
|
|
146
|
+
<template>
|
|
147
|
+
<div class="fe-list" :class="{ 'is-loading': loading, 'has-star-col': !!apiBase || apiBase === '' }">
|
|
148
|
+
<div class="fe-list__head" role="row">
|
|
149
|
+
<div class="fe-list__col fe-list__col--star" role="columnheader" aria-label="Star"></div>
|
|
150
|
+
<div class="fe-list__col fe-list__col--name" role="columnheader">{{ t('col.name') }}</div>
|
|
151
|
+
<div class="fe-list__col fe-list__col--size" role="columnheader">{{ t('col.size') }}</div>
|
|
152
|
+
<div class="fe-list__col fe-list__col--mod" role="columnheader">{{ t('col.modified') }}</div>
|
|
153
|
+
</div>
|
|
154
|
+
<div class="fe-list__body" role="rowgroup">
|
|
155
|
+
<div
|
|
156
|
+
v-for="n in rows"
|
|
157
|
+
:key="n.path"
|
|
158
|
+
class="fe-list__row"
|
|
159
|
+
:class="{
|
|
160
|
+
'is-selected': isSelected(n),
|
|
161
|
+
'is-dir': n.type === 'dir',
|
|
162
|
+
'is-trash': n.trashed,
|
|
163
|
+
'is-clipped': clipped?.has(n.path),
|
|
164
|
+
}"
|
|
165
|
+
role="row"
|
|
166
|
+
tabindex="0"
|
|
167
|
+
draggable="true"
|
|
168
|
+
@click="onRowClick(n, $event)"
|
|
169
|
+
@dblclick="onRowDbl(n)"
|
|
170
|
+
@contextmenu="onRowCtx(n, $event)"
|
|
171
|
+
@dragstart="onItemDragStart(n, $event)"
|
|
172
|
+
@dragover="onItemDragOver(n, $event)"
|
|
173
|
+
@drop="onItemDrop(n, $event)"
|
|
174
|
+
@touchstart.passive="onTouchStart(n, $event)"
|
|
175
|
+
@touchend="cancelPress"
|
|
176
|
+
@touchmove="cancelPress"
|
|
177
|
+
>
|
|
178
|
+
<div class="fe-list__col fe-list__col--star" @click.stop>
|
|
179
|
+
<StarButton
|
|
180
|
+
v-if="typeof n.id === 'number' && n.type === 'file'"
|
|
181
|
+
:starred="!!starredIds?.has(n.id)"
|
|
182
|
+
:node-id="n.id"
|
|
183
|
+
:api-base="apiBase"
|
|
184
|
+
:auth-headers="authHeaders"
|
|
185
|
+
compact
|
|
186
|
+
@change="(val: boolean) => emit('star-change', n, val)"
|
|
187
|
+
/>
|
|
188
|
+
</div>
|
|
189
|
+
<div class="fe-list__col fe-list__col--name">
|
|
190
|
+
<span class="fe-list__icon" aria-hidden="true">{{ iconFor(n) }}</span>
|
|
191
|
+
<div class="fe-list__name-wrap">
|
|
192
|
+
<span class="fe-list__name" :title="n.basename">{{ nodeDisplayName(n) }}</span>
|
|
193
|
+
<span
|
|
194
|
+
v-if="showParentPath"
|
|
195
|
+
class="fe-list__parent"
|
|
196
|
+
:title="parentDir(n.path)"
|
|
197
|
+
>{{ parentDir(n.path) || '—' }}</span>
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
<div class="fe-list__col fe-list__col--size">
|
|
201
|
+
{{ n.type === 'dir' ? '—' : formatSize(n.size) }}
|
|
202
|
+
</div>
|
|
203
|
+
<div class="fe-list__col fe-list__col--mod">
|
|
204
|
+
{{ displayDate(n.last_modified) }}
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
<div v-if="!loading && rows.length === 0" class="fe-list__empty">
|
|
208
|
+
{{ t('empty.folder') }}
|
|
209
|
+
</div>
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
212
|
+
</template>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* PendingOpsTray — bottom-left toast list for queued copy/move/delete.
|
|
4
|
+
*
|
|
5
|
+
* Sits next to UploadProgress visually (offset to its left when both
|
|
6
|
+
* are open). Each row shows op type + a progress bar driven by
|
|
7
|
+
* `progress_done / progress_total`. Terminal rows linger for a moment
|
|
8
|
+
* (RETAIN_MS in usePendingOps) so the final state is visible before
|
|
9
|
+
* they fade out.
|
|
10
|
+
*/
|
|
11
|
+
import { computed } from 'vue';
|
|
12
|
+
import type { LocaleCode } from '../types/ExplorerConfig';
|
|
13
|
+
import type { PendingOp } from '../composables/usePendingOps';
|
|
14
|
+
import { useLocale } from '../composables/useLocale';
|
|
15
|
+
|
|
16
|
+
const props = defineProps<{
|
|
17
|
+
ops: PendingOp[];
|
|
18
|
+
locale: LocaleCode;
|
|
19
|
+
}>();
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits<{
|
|
22
|
+
(e: 'dismiss', id: number): void;
|
|
23
|
+
}>();
|
|
24
|
+
|
|
25
|
+
const { t } = useLocale(() => props.locale);
|
|
26
|
+
|
|
27
|
+
const sorted = computed(() => [...props.ops].sort((a, b) => b.id - a.id));
|
|
28
|
+
|
|
29
|
+
function percent(op: PendingOp): number {
|
|
30
|
+
if (op.status === 'done') return 100;
|
|
31
|
+
if (op.progress_total <= 0) return 0;
|
|
32
|
+
return Math.min(100, Math.round((op.progress_done / op.progress_total) * 100));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function statusClass(op: PendingOp): string {
|
|
36
|
+
if (op.status === 'done') return 'is-done';
|
|
37
|
+
if (op.status === 'error') return 'is-error';
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function summary(op: PendingOp): string {
|
|
42
|
+
const verb =
|
|
43
|
+
op.op_type === 'copy'
|
|
44
|
+
? t('ops.copy')
|
|
45
|
+
: op.op_type === 'move'
|
|
46
|
+
? t('ops.move')
|
|
47
|
+
: t('ops.delete');
|
|
48
|
+
if (op.status === 'pending') return `${verb} (${t('ops.queued')})`;
|
|
49
|
+
if (op.status === 'running') return `${verb} ${op.progress_done}/${op.progress_total}`;
|
|
50
|
+
if (op.status === 'done') return `${verb} ${t('ops.done')} (${op.progress_total})`;
|
|
51
|
+
if (op.status === 'error') return `${verb} ${t('ops.error')}`;
|
|
52
|
+
return verb;
|
|
53
|
+
}
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<template>
|
|
57
|
+
<transition-group
|
|
58
|
+
v-if="sorted.length > 0"
|
|
59
|
+
name="fe-ops-slide"
|
|
60
|
+
tag="div"
|
|
61
|
+
class="fe-ops"
|
|
62
|
+
role="status"
|
|
63
|
+
aria-live="polite"
|
|
64
|
+
>
|
|
65
|
+
<div
|
|
66
|
+
v-for="op in sorted"
|
|
67
|
+
:key="op.id"
|
|
68
|
+
class="fe-ops__item"
|
|
69
|
+
:class="statusClass(op)"
|
|
70
|
+
>
|
|
71
|
+
<div class="fe-ops__row">
|
|
72
|
+
<span class="fe-ops__title" :title="op.target_path || op.source_dir || ''">
|
|
73
|
+
{{ summary(op) }}
|
|
74
|
+
</span>
|
|
75
|
+
<button
|
|
76
|
+
v-if="op.status === 'done' || op.status === 'error'"
|
|
77
|
+
type="button"
|
|
78
|
+
class="fe-ops__dismiss"
|
|
79
|
+
aria-label="Dismiss"
|
|
80
|
+
@click="emit('dismiss', op.id)"
|
|
81
|
+
>×</button>
|
|
82
|
+
</div>
|
|
83
|
+
<div class="fe-ops__bar">
|
|
84
|
+
<div class="fe-ops__bar-fill" :style="{ width: percent(op) + '%' }" />
|
|
85
|
+
</div>
|
|
86
|
+
<div v-if="op.status === 'error' && op.error_message" class="fe-ops__error">
|
|
87
|
+
{{ op.error_message }}
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
</transition-group>
|
|
91
|
+
</template>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* RecentlyOpened — drop-down/sidebar tray of the user's recently-opened
|
|
4
|
+
* files. Backed by `GET /api/files/manager/recent?limit=20`.
|
|
5
|
+
*/
|
|
6
|
+
import { ref, onMounted, watch } from 'vue';
|
|
7
|
+
|
|
8
|
+
interface RecentNode {
|
|
9
|
+
id: number;
|
|
10
|
+
storage_id: number;
|
|
11
|
+
path: string;
|
|
12
|
+
name: string;
|
|
13
|
+
mime?: string;
|
|
14
|
+
last_opened?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const props = defineProps<{
|
|
18
|
+
apiBase?: string;
|
|
19
|
+
authHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
20
|
+
limit?: number;
|
|
21
|
+
/** Optional refresh trigger — incrementing this re-fetches. */
|
|
22
|
+
refreshKey?: number | string;
|
|
23
|
+
}>();
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits<{
|
|
26
|
+
(e: 'open', node: RecentNode): void;
|
|
27
|
+
(e: 'error', message: string): void;
|
|
28
|
+
}>();
|
|
29
|
+
|
|
30
|
+
const items = ref<RecentNode[]>([]);
|
|
31
|
+
const loading = ref(false);
|
|
32
|
+
|
|
33
|
+
async function load() {
|
|
34
|
+
loading.value = true;
|
|
35
|
+
try {
|
|
36
|
+
const headers = await (props.authHeaders ?? (() => ({})))();
|
|
37
|
+
const base = props.apiBase ?? '';
|
|
38
|
+
const limit = props.limit ?? 20;
|
|
39
|
+
const res = await fetch(`${base}/api/files/manager/recent?limit=${limit}`, {
|
|
40
|
+
headers,
|
|
41
|
+
credentials: 'include',
|
|
42
|
+
});
|
|
43
|
+
if (res.ok) {
|
|
44
|
+
const body = await res.json();
|
|
45
|
+
items.value = Array.isArray(body.entries) ? body.entries : (Array.isArray(body) ? body : []);
|
|
46
|
+
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
emit('error', err instanceof Error ? err.message : String(err));
|
|
49
|
+
} finally {
|
|
50
|
+
loading.value = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function fmtTime(s?: string): string {
|
|
55
|
+
if (!s) return '';
|
|
56
|
+
const t = new Date(s).getTime();
|
|
57
|
+
if (Number.isNaN(t)) return '';
|
|
58
|
+
const diff = Date.now() - t;
|
|
59
|
+
if (diff < 60_000) return 'just now';
|
|
60
|
+
if (diff < 3_600_000) return `${Math.floor(diff / 60_000)}m ago`;
|
|
61
|
+
if (diff < 86_400_000) return `${Math.floor(diff / 3_600_000)}h ago`;
|
|
62
|
+
return `${Math.floor(diff / 86_400_000)}d ago`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
onMounted(load);
|
|
66
|
+
watch(() => props.refreshKey, load);
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<div class="filex-recent">
|
|
71
|
+
<header>
|
|
72
|
+
<h3>Recently opened</h3>
|
|
73
|
+
<button class="filex-recent-refresh" type="button" @click="load" :disabled="loading">
|
|
74
|
+
↻
|
|
75
|
+
</button>
|
|
76
|
+
</header>
|
|
77
|
+
|
|
78
|
+
<ul v-if="items.length">
|
|
79
|
+
<li v-for="n in items" :key="n.id">
|
|
80
|
+
<button type="button" @click="emit('open', n)" class="filex-recent-item">
|
|
81
|
+
<span class="filex-recent-name">{{ n.name }}</span>
|
|
82
|
+
<span class="filex-recent-meta">{{ fmtTime(n.last_opened) }}</span>
|
|
83
|
+
</button>
|
|
84
|
+
</li>
|
|
85
|
+
</ul>
|
|
86
|
+
<p v-else-if="!loading" class="filex-recent-empty">Nothing here yet.</p>
|
|
87
|
+
<p v-else class="filex-recent-empty">Loading…</p>
|
|
88
|
+
</div>
|
|
89
|
+
</template>
|
|
90
|
+
|
|
91
|
+
<style scoped>
|
|
92
|
+
.filex-recent {
|
|
93
|
+
background: var(--fe-bg-elev, var(--filex-bg-card, #ffffff));
|
|
94
|
+
border: 1px solid var(--fe-border, var(--filex-border, #e5e7eb));
|
|
95
|
+
border-radius: 8px;
|
|
96
|
+
padding: 12px;
|
|
97
|
+
font-size: 13px;
|
|
98
|
+
}
|
|
99
|
+
.filex-recent header {
|
|
100
|
+
display: flex;
|
|
101
|
+
justify-content: space-between;
|
|
102
|
+
align-items: center;
|
|
103
|
+
margin-bottom: 8px;
|
|
104
|
+
}
|
|
105
|
+
.filex-recent h3 {
|
|
106
|
+
margin: 0;
|
|
107
|
+
font-size: 13px;
|
|
108
|
+
font-weight: 600;
|
|
109
|
+
color: var(--fe-text, var(--filex-text, #111827));
|
|
110
|
+
}
|
|
111
|
+
.filex-recent-refresh {
|
|
112
|
+
background: transparent;
|
|
113
|
+
border: none;
|
|
114
|
+
color: var(--fe-text-muted, var(--filex-text-muted, #9ca3af));
|
|
115
|
+
cursor: pointer;
|
|
116
|
+
font-size: 14px;
|
|
117
|
+
padding: 2px 6px;
|
|
118
|
+
}
|
|
119
|
+
.filex-recent ul {
|
|
120
|
+
list-style: none;
|
|
121
|
+
margin: 0;
|
|
122
|
+
padding: 0;
|
|
123
|
+
}
|
|
124
|
+
.filex-recent-item {
|
|
125
|
+
display: flex;
|
|
126
|
+
justify-content: space-between;
|
|
127
|
+
align-items: center;
|
|
128
|
+
width: 100%;
|
|
129
|
+
background: transparent;
|
|
130
|
+
border: none;
|
|
131
|
+
padding: 6px 8px;
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
border-radius: 4px;
|
|
134
|
+
text-align: left;
|
|
135
|
+
}
|
|
136
|
+
.filex-recent-item:hover {
|
|
137
|
+
background: var(--fe-bg-hover, var(--filex-bg-soft, #f3f4f6));
|
|
138
|
+
}
|
|
139
|
+
.filex-recent-name {
|
|
140
|
+
color: var(--fe-text, var(--filex-text, #111827));
|
|
141
|
+
overflow: hidden;
|
|
142
|
+
text-overflow: ellipsis;
|
|
143
|
+
white-space: nowrap;
|
|
144
|
+
}
|
|
145
|
+
.filex-recent-meta {
|
|
146
|
+
color: var(--fe-text-muted, var(--filex-text-muted, #9ca3af));
|
|
147
|
+
font-size: 11px;
|
|
148
|
+
margin-left: 8px;
|
|
149
|
+
flex-shrink: 0;
|
|
150
|
+
}
|
|
151
|
+
.filex-recent-empty {
|
|
152
|
+
color: var(--fe-text-muted, var(--filex-text-muted, #9ca3af));
|
|
153
|
+
margin: 4px 0 0;
|
|
154
|
+
}
|
|
155
|
+
</style>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* StarButton — toggleable star indicator for a node.
|
|
4
|
+
*
|
|
5
|
+
* Backed by the `node_meta key="starred"` server-side row (see
|
|
6
|
+
* `POST /api/files/manager/star`). Optimistic update — flips the local
|
|
7
|
+
* state immediately and rolls back on API error.
|
|
8
|
+
*/
|
|
9
|
+
import { ref, watch } from 'vue';
|
|
10
|
+
|
|
11
|
+
const props = defineProps<{
|
|
12
|
+
starred: boolean;
|
|
13
|
+
nodeId: number;
|
|
14
|
+
apiBase?: string;
|
|
15
|
+
/** Auth header builder injected by the parent file explorer. */
|
|
16
|
+
authHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
17
|
+
/** Compact mode for grid view (no label, just the icon). */
|
|
18
|
+
compact?: boolean;
|
|
19
|
+
}>();
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits<{
|
|
22
|
+
(e: 'change', value: boolean): void;
|
|
23
|
+
(e: 'error', message: string): void;
|
|
24
|
+
}>();
|
|
25
|
+
|
|
26
|
+
const local = ref(props.starred);
|
|
27
|
+
watch(() => props.starred, (v) => { local.value = v; });
|
|
28
|
+
|
|
29
|
+
async function toggle() {
|
|
30
|
+
const next = !local.value;
|
|
31
|
+
local.value = next; // optimistic
|
|
32
|
+
try {
|
|
33
|
+
const headers = {
|
|
34
|
+
'Content-Type': 'application/json',
|
|
35
|
+
...(await (props.authHeaders ?? (() => ({})))()),
|
|
36
|
+
};
|
|
37
|
+
const base = props.apiBase ?? '';
|
|
38
|
+
const res = await fetch(`${base}/api/files/manager/star`, {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers,
|
|
41
|
+
credentials: 'include',
|
|
42
|
+
body: JSON.stringify({ node_id: props.nodeId, starred: next }),
|
|
43
|
+
});
|
|
44
|
+
if (!res.ok) throw new Error(`star toggle failed: ${res.status}`);
|
|
45
|
+
emit('change', next);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
local.value = !next; // rollback
|
|
48
|
+
emit('error', err instanceof Error ? err.message : String(err));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<template>
|
|
54
|
+
<button
|
|
55
|
+
type="button"
|
|
56
|
+
class="filex-star-btn"
|
|
57
|
+
:class="{ 'is-starred': local, 'is-compact': compact }"
|
|
58
|
+
:aria-pressed="local"
|
|
59
|
+
:title="local ? 'Unstar' : 'Star'"
|
|
60
|
+
@click.stop="toggle"
|
|
61
|
+
>
|
|
62
|
+
<svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true">
|
|
63
|
+
<path
|
|
64
|
+
:fill="local ? 'currentColor' : 'none'"
|
|
65
|
+
stroke="currentColor"
|
|
66
|
+
stroke-width="2"
|
|
67
|
+
stroke-linejoin="round"
|
|
68
|
+
d="M12 2.5l3.09 6.26 6.91 1-5 4.87 1.18 6.87L12 18.27l-6.18 3.23L7 14.63 2 9.76l6.91-1z"
|
|
69
|
+
/>
|
|
70
|
+
</svg>
|
|
71
|
+
<span v-if="!compact" class="filex-star-label">{{ local ? 'Starred' : 'Star' }}</span>
|
|
72
|
+
</button>
|
|
73
|
+
</template>
|
|
74
|
+
|
|
75
|
+
<style scoped>
|
|
76
|
+
.filex-star-btn {
|
|
77
|
+
display: inline-flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
gap: 6px;
|
|
80
|
+
background: transparent;
|
|
81
|
+
border: 1px solid transparent;
|
|
82
|
+
border-radius: 6px;
|
|
83
|
+
padding: 4px 8px;
|
|
84
|
+
color: var(--filex-text-muted, #9ca3af);
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
transition: color 120ms, background 120ms;
|
|
87
|
+
}
|
|
88
|
+
.filex-star-btn:hover {
|
|
89
|
+
color: var(--filex-accent-amber, #f59e0b);
|
|
90
|
+
background: var(--filex-bg-soft, rgba(0, 0, 0, 0.04));
|
|
91
|
+
}
|
|
92
|
+
.filex-star-btn.is-starred {
|
|
93
|
+
color: var(--filex-accent-amber, #f59e0b);
|
|
94
|
+
}
|
|
95
|
+
.filex-star-btn.is-compact {
|
|
96
|
+
padding: 4px;
|
|
97
|
+
}
|
|
98
|
+
.filex-star-label {
|
|
99
|
+
font-size: 13px;
|
|
100
|
+
}
|
|
101
|
+
</style>
|