Fix preview restore and add breadcrumb/parent/sidebar move targets
@@ -43,6 +43,7 @@
43
43
- fileAccentColor(name) - Returns canonical file-type accent color used by icon strokes and preview sheet outline.
44
44
- animatePreviewOpen(sourceSvgEl, sheetEl) - Animates a cloned file icon from its tile position into the full preview sheet.
45
45
- openFolderSidebar() - Persistent sidebar fallback view that shows current folder/root overview when no item is selected.
46
- renderBreadcrumb() - Builds clickable breadcrumb path and marks each folder segment as a drag-drop move target via .crumb-drop-target and data-path.
46
47
- fetchFileBlob(item) - Downloads a file as Blob with auth headers for preview/download flows.
47
48
- downloadOrView(item, sourceSvgEl) - Opens preview; prefers in-place expanded tile preview when invoked from a file icon, falls back to overlay when no source tile is available.
48
49
- renderPreviewBody(item, blob, objectUrl, targetEl) - Renders preview content (image/video/audio/pdf/text) or unsupported message into a target container.
@@ -50,22 +51,29 @@
50
51
- openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents the real file tile to body, expands it to viewport preview, injects close/download controls.
51
52
- closeExpandedTilePreview() - Collapses expanded tile preview back to original grid position and restores original icon markup.
52
53
- closePreview() - Closes either expanded-tile preview or overlay preview, then revokes active preview object URL.
54
- openMovePicker(item) - Opens Move To selector modal with expandable folder tree across all writable roots and executes /api/files/move.
55
- ensureMoveModal() - Lazily creates and wires Move To modal UI (tree, selection state, confirm/cancel handlers).
56
- createMoveNode(folderPath, label) - Builds an expandable/selectable folder node for the Move To tree.
57
- loadMoveChildren(containerEl, dirPath) - Lazy-loads subfolders for a tree node via /api/files/list.
53
58
- isInlinePreviewableBlob(blob, name) - Determines if a blob can be previewed inline by MIME/extension.
54
59
- makeFileItem(item) - Builds a .file-item element; sets data-isdir attribute on folders and calls makeDraggable(el, item) from drag-move.js.
55
60
56
61
## public/drag-move.js
57
62
- makeDraggable(el, item) - Attaches pointerdown to a .file-item; starts drag after threshold movement. Depends on: api(), canWrite(), navigateTo(), STATE, closeSidebar(), toast() from app.js.
58
- (internal) _beginDrag(e, el, item) - Lifts and re-parents the real .file-item to body, inserts hidden placeholder, records drag state.
59
- (internal) _moveDrag(e) - Moves the real dragged item, hit-tests .file-item[data-isdir] targets, toggles drop-target class.
63
- (internal) _beginDrag(e, el, item) - Lifts and re-parents the real .file-item to body, inserts hidden placeholder, and shows parent-folder drag target when applicable.
64
- (internal) _moveDrag(e) - Moves the real dragged item, hit-tests folder tiles, breadcrumb segments, and parent-folder target, toggles target highlight state.
60
65
- (internal) _endDrag() - On valid target: runs drop animation on real tile then calls POST /api/files/move, refreshes dir. Otherwise snap-back.
61
- (internal) _cleanupDrag(reinsert) - Restores tile styles; reinserts into grid on failure/abort or removes before refresh on success.
66
- (internal) _cleanupDrag(reinsert) - Restores tile styles; reinserts into grid on failure/abort or removes before refresh on success, hides drag helper targets.
62
67
63
68
## public/drag-move.css
64
69
- .file-item.dragging - Lifted style for real dragged tile.
65
70
- .file-item.drop-target - Glows folder icon when drag hovers over it.
71
- .drag-parent-target - Temporary top-left "move to parent" drop target shown while dragging in nested folders.
72
- .crumb-drop-target.active - Highlight style for breadcrumb drop destinations during drag.
66
73
- @keyframes drag-rise-spin-fall - Real tile rises, spins, falls/scales into folder on drop.
67
74
- @keyframes folder-bounce - Target folder bounces down then back on accept.
68
- .preview-backdrop/.file-item--preview/.preview-expand-* - In-place expanded tile preview styling (no separate overlay window).
75
- .preview-backdrop/.file-item--preview/.preview-expand-* - In-place expanded tile preview styling (no separate overlay window), including preserved icon-outline layer.
76
- .move-modal/.move-tree/.move-node* - Move To tree picker styles with expandable/collapsible folder hierarchy.
69
77
70
78
## tests/auth.routes.test.js
71
79
- session lifecycle / POST /api/auth/logout revokes active session - Verifies explicit logout invalidates token immediately.
@@ -43,6 +43,7 @@43
- fileAccentColor(name) - Returns canonical file-type accent color used by icon strokes and preview sheet outline.43
- fileAccentColor(name) - Returns canonical file-type accent color used by icon strokes and preview sheet outline.44
- animatePreviewOpen(sourceSvgEl, sheetEl) - Animates a cloned file icon from its tile position into the full preview sheet.44
- animatePreviewOpen(sourceSvgEl, sheetEl) - Animates a cloned file icon from its tile position into the full preview sheet.45
- openFolderSidebar() - Persistent sidebar fallback view that shows current folder/root overview when no item is selected.45
- openFolderSidebar() - Persistent sidebar fallback view that shows current folder/root overview when no item is selected.46
- renderBreadcrumb() - Builds clickable breadcrumb path and marks each folder segment as a drag-drop move target via .crumb-drop-target and data-path.46
- fetchFileBlob(item) - Downloads a file as Blob with auth headers for preview/download flows.47
- fetchFileBlob(item) - Downloads a file as Blob with auth headers for preview/download flows.47
- downloadOrView(item, sourceSvgEl) - Opens preview; prefers in-place expanded tile preview when invoked from a file icon, falls back to overlay when no source tile is available.48
- downloadOrView(item, sourceSvgEl) - Opens preview; prefers in-place expanded tile preview when invoked from a file icon, falls back to overlay when no source tile is available.48
- renderPreviewBody(item, blob, objectUrl, targetEl) - Renders preview content (image/video/audio/pdf/text) or unsupported message into a target container.49
- renderPreviewBody(item, blob, objectUrl, targetEl) - Renders preview content (image/video/audio/pdf/text) or unsupported message into a target container.@@ -50,22 +51,29 @@50
- openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents the real file tile to body, expands it to viewport preview, injects close/download controls.51
- openExpandedTilePreview(item, tileEl, sourceSvgEl, blob, objectUrl) - Reparents the real file tile to body, expands it to viewport preview, injects close/download controls.51
- closeExpandedTilePreview() - Collapses expanded tile preview back to original grid position and restores original icon markup.52
- closeExpandedTilePreview() - Collapses expanded tile preview back to original grid position and restores original icon markup.52
- closePreview() - Closes either expanded-tile preview or overlay preview, then revokes active preview object URL.53
- closePreview() - Closes either expanded-tile preview or overlay preview, then revokes active preview object URL.54
- openMovePicker(item) - Opens Move To selector modal with expandable folder tree across all writable roots and executes /api/files/move.55
- ensureMoveModal() - Lazily creates and wires Move To modal UI (tree, selection state, confirm/cancel handlers).56
- createMoveNode(folderPath, label) - Builds an expandable/selectable folder node for the Move To tree.57
- loadMoveChildren(containerEl, dirPath) - Lazy-loads subfolders for a tree node via /api/files/list.53
- isInlinePreviewableBlob(blob, name) - Determines if a blob can be previewed inline by MIME/extension.58
- isInlinePreviewableBlob(blob, name) - Determines if a blob can be previewed inline by MIME/extension.54
- makeFileItem(item) - Builds a .file-item element; sets data-isdir attribute on folders and calls makeDraggable(el, item) from drag-move.js.59
- makeFileItem(item) - Builds a .file-item element; sets data-isdir attribute on folders and calls makeDraggable(el, item) from drag-move.js.55
60
56
## public/drag-move.js61
## public/drag-move.js57
- makeDraggable(el, item) - Attaches pointerdown to a .file-item; starts drag after threshold movement. Depends on: api(), canWrite(), navigateTo(), STATE, closeSidebar(), toast() from app.js.62
- makeDraggable(el, item) - Attaches pointerdown to a .file-item; starts drag after threshold movement. Depends on: api(), canWrite(), navigateTo(), STATE, closeSidebar(), toast() from app.js.58
- (internal) _beginDrag(e, el, item) - Lifts and re-parents the real .file-item to body, inserts hidden placeholder, records drag state.63
- (internal) _beginDrag(e, el, item) - Lifts and re-parents the real .file-item to body, inserts hidden placeholder, and shows parent-folder drag target when applicable.59
- (internal) _moveDrag(e) - Moves the real dragged item, hit-tests .file-item[data-isdir] targets, toggles drop-target class.64
- (internal) _moveDrag(e) - Moves the real dragged item, hit-tests folder tiles, breadcrumb segments, and parent-folder target, toggles target highlight state.60
- (internal) _endDrag() - On valid target: runs drop animation on real tile then calls POST /api/files/move, refreshes dir. Otherwise snap-back.65
- (internal) _endDrag() - On valid target: runs drop animation on real tile then calls POST /api/files/move, refreshes dir. Otherwise snap-back.61
- (internal) _cleanupDrag(reinsert) - Restores tile styles; reinserts into grid on failure/abort or removes before refresh on success.66
- (internal) _cleanupDrag(reinsert) - Restores tile styles; reinserts into grid on failure/abort or removes before refresh on success, hides drag helper targets.62
67
63
## public/drag-move.css68
## public/drag-move.css64
- .file-item.dragging - Lifted style for real dragged tile.69
- .file-item.dragging - Lifted style for real dragged tile.65
- .file-item.drop-target - Glows folder icon when drag hovers over it.70
- .file-item.drop-target - Glows folder icon when drag hovers over it.71
- .drag-parent-target - Temporary top-left "move to parent" drop target shown while dragging in nested folders.72
- .crumb-drop-target.active - Highlight style for breadcrumb drop destinations during drag.66
- @keyframes drag-rise-spin-fall - Real tile rises, spins, falls/scales into folder on drop.73
- @keyframes drag-rise-spin-fall - Real tile rises, spins, falls/scales into folder on drop.67
- @keyframes folder-bounce - Target folder bounces down then back on accept.74
- @keyframes folder-bounce - Target folder bounces down then back on accept.68
- .preview-backdrop/.file-item--preview/.preview-expand-* - In-place expanded tile preview styling (no separate overlay window).75
- .preview-backdrop/.file-item--preview/.preview-expand-* - In-place expanded tile preview styling (no separate overlay window), including preserved icon-outline layer.76
- .move-modal/.move-tree/.move-node* - Move To tree picker styles with expandable/collapsible folder hierarchy.69
77
70
## tests/auth.routes.test.js78
## tests/auth.routes.test.js71
- session lifecycle / POST /api/auth/logout revokes active session - Verifies explicit logout invalidates token immediately.79
- session lifecycle / POST /api/auth/logout revokes active session - Verifies explicit logout invalidates token immediately.@@ -49,6 +49,7 @@ const STATE = {
49
49
previewSourceEl: null, // SVG element that triggered the preview
50
50
previewClosing: false, // guard to prevent double-close during animation
51
51
previewExpandState: null, // in-place expanded tile preview state
52
movePicker: null,
52
53
};
53
54
54
55
const SESSION_KEY = 'filemanager.session.v1';
@@ -762,6 +763,8 @@ function renderBreadcrumb ()
762
763
763
764
// Capture the path for this crumb
764
765
const capturedPath = i === 0 ? rootPath : accumulated;
766
crumb.classList.add('crumb-drop-target');
767
crumb.dataset.path = capturedPath;
765
768
if (i < parts.length - 1)
766
769
{
767
770
crumb.addEventListener('click', () => navigateTo(capturedPath, STATE.currentRoot));
@@ -811,6 +814,7 @@ function itemsSignature (items)
811
814
812
815
async function incrementalRefreshCurrentDir ()
813
816
{
817
if (STATE.previewExpandState) return;
814
818
if (!STATE.currentDir || STATE.uploadInProgress) return;
815
819
816
820
const data = await api('GET', `/files/list?dir=${encodeURIComponent(STATE.currentDir)}`).catch(() => null);
@@ -1003,6 +1007,11 @@ async function openSidebar (item)
1003
1007
// Rename button (write access required)
1004
1008
if (canWrite())
1005
1009
{
1010
const btnMove = document.createElement('button');
1011
btnMove.textContent = 'Move to';
1012
btnMove.addEventListener('click', () => openMovePicker(item));
1013
actions.appendChild(btnMove);
1014
1006
1015
const btnRen = document.createElement('button');
1007
1016
btnRen.textContent = 'Rename';
1008
1017
btnRen.addEventListener('click', () => openRenameModal(item));
@@ -1059,6 +1068,199 @@ function closeSidebar ()
1059
1068
openFolderSidebar();
1060
1069
}
1061
1070
1071
function basenameOfPath (p)
1072
{
1073
const parts = String(p || '').split(/[\\/]/).filter(Boolean);
1074
return parts.length ? parts[parts.length - 1] : String(p || '');
1075
}
1076
1077
function writableRoots ()
1078
{
1079
if (STATE.isAdmin) return STATE.roots.slice();
1080
return STATE.roots.filter((r) =>
1081
{
1082
const perm = STATE.permissions[r.label];
1083
return !!(perm && perm.write);
1084
});
1085
}
1086
1087
function ensureMoveModal ()
1088
{
1089
let overlay = document.getElementById('move-modal');
1090
if (overlay) return overlay;
1091
1092
overlay = document.createElement('div');
1093
overlay.id = 'move-modal';
1094
overlay.className = 'modal-overlay hidden';
1095
overlay.innerHTML = `
1096
<div class="modal move-modal">
1097
<button class="modal-close" id="move-modal-close" aria-label="Close">✕</button>
1098
<h2>Move To</h2>
1099
<p id="move-modal-caption" class="muted"></p>
1100
<div id="move-tree" class="move-tree"></div>
1101
<p id="move-selected" class="muted"></p>
1102
<div class="dialog-actions">
1103
<button id="move-modal-cancel">Cancel</button>
1104
<button id="move-modal-confirm" class="primary">Move</button>
1105
</div>
1106
</div>
1107
`;
1108
document.body.appendChild(overlay);
1109
1110
const closeBtn = overlay.querySelector('#move-modal-close');
1111
const cancelBtn = overlay.querySelector('#move-modal-cancel');
1112
const confirmBtn = overlay.querySelector('#move-modal-confirm');
1113
1114
function hide ()
1115
{
1116
overlay.classList.add('hidden');
1117
STATE.movePicker = null;
1118
}
1119
1120
closeBtn.addEventListener('click', hide);
1121
cancelBtn.addEventListener('click', hide);
1122
overlay.addEventListener('click', (e) =>
1123
{
1124
if (e.target === overlay) hide();
1125
});
1126
1127
confirmBtn.addEventListener('click', async () =>
1128
{
1129
const st = STATE.movePicker;
1130
if (!st || !st.item || !st.selectedPath)
1131
{
1132
toast('Select a destination folder first.', 'err');
1133
return;
1134
}
1135
1136
try
1137
{
1138
await api('POST', '/files/move', { from: st.item.path, toDir: st.selectedPath });
1139
}
1140
catch (err)
1141
{
1142
toast('Move failed: ' + err.message, 'err');
1143
return;
1144
}
1145
1146
hide();
1147
if (STATE.selectedItem && STATE.selectedItem.path === st.item.path) closeSidebar();
1148
navigateTo(STATE.currentDir, STATE.currentRoot);
1149
});
1150
1151
return overlay;
1152
}
1153
1154
function setMoveSelection (path, buttonEl)
1155
{
1156
if (!STATE.movePicker) return;
1157
STATE.movePicker.selectedPath = path;
1158
1159
document.querySelectorAll('.move-node-label.selected').forEach((el) => el.classList.remove('selected'));
1160
if (buttonEl) buttonEl.classList.add('selected');
1161
1162
const selectedEl = document.getElementById('move-selected');
1163
selectedEl.textContent = path ? `Destination: ${path}` : 'Destination: none';
1164
}
1165
1166
async function loadMoveChildren (containerEl, dirPath)
1167
{
1168
if (containerEl.dataset.loaded === '1') return;
1169
containerEl.dataset.loaded = '1';
1170
1171
const data = await api('GET', `/files/list?dir=${encodeURIComponent(dirPath)}`).catch(() => null);
1172
const folders = data ? data.items.filter((it) => it.isDir).sort((a, b) => a.name.localeCompare(b.name)) : [];
1173
1174
if (!folders.length)
1175
{
1176
const empty = document.createElement('div');
1177
empty.className = 'move-empty';
1178
empty.textContent = 'No subfolders';
1179
containerEl.appendChild(empty);
1180
return;
1181
}
1182
1183
for (const child of folders)
1184
{
1185
containerEl.appendChild(createMoveNode(child.path, child.name));
1186
}
1187
}
1188
1189
function createMoveNode (folderPath, label)
1190
{
1191
const node = document.createElement('div');
1192
node.className = 'move-node';
1193
1194
const row = document.createElement('div');
1195
row.className = 'move-node-row';
1196
1197
const toggle = document.createElement('button');
1198
toggle.type = 'button';
1199
toggle.className = 'move-toggle';
1200
toggle.textContent = '▸';
1201
1202
const selectBtn = document.createElement('button');
1203
selectBtn.type = 'button';
1204
selectBtn.className = 'move-node-label';
1205
selectBtn.textContent = label;
1206
selectBtn.addEventListener('click', () => setMoveSelection(folderPath, selectBtn));
1207
1208
const children = document.createElement('div');
1209
children.className = 'move-children hidden';
1210
1211
toggle.addEventListener('click', async () =>
1212
{
1213
if (children.classList.contains('hidden'))
1214
{
1215
await loadMoveChildren(children, folderPath);
1216
children.classList.remove('hidden');
1217
toggle.textContent = '▾';
1218
} else
1219
{
1220
children.classList.add('hidden');
1221
toggle.textContent = '▸';
1222
}
1223
});
1224
1225
row.appendChild(toggle);
1226
row.appendChild(selectBtn);
1227
node.appendChild(row);
1228
node.appendChild(children);
1229
return node;
1230
}
1231
1232
function openMovePicker (item)
1233
{
1234
if (!canWrite())
1235
{
1236
toast('No write access.', 'err');
1237
return;
1238
}
1239
1240
const roots = writableRoots();
1241
if (!roots.length)
1242
{
1243
toast('No writable destination roots available.', 'err');
1244
return;
1245
}
1246
1247
const overlay = ensureMoveModal();
1248
const tree = overlay.querySelector('#move-tree');
1249
const caption = overlay.querySelector('#move-modal-caption');
1250
1251
STATE.movePicker = { item, selectedPath: null };
1252
caption.textContent = `Select destination folder for: ${item.name}`;
1253
tree.innerHTML = '';
1254
1255
for (const root of roots)
1256
{
1257
tree.appendChild(createMoveNode(root.path, root.label));
1258
}
1259
1260
setMoveSelection(null, null);
1261
overlay.classList.remove('hidden');
1262
}
1263
1062
1264
// ───────────────────────────────────────────────────────────────────────────
1063
1265
// DOWNLOAD / VIEW
1064
1266
// ───────────────────────────────────────────────────────────────────────────
@@ -1399,28 +1601,42 @@ function animatePreviewClose (sourceSvgEl, sheetEl)
1399
1601
function animateRect (el, fromRect, toRect, opts = {})
1400
1602
{
1401
1603
const duration = opts.duration == null ? 260 : opts.duration;
1402
const easing = opts.easing || 'cubic-bezier(0.22, 0.8, 0.2, 1)';
1604
const easeOut = (t) => 1 - Math.pow(1 - t, 3);
1605
1606
el.style.left = `${fromRect.left}px`;
1607
el.style.top = `${fromRect.top}px`;
1608
el.style.width = `${fromRect.width}px`;
1609
el.style.height = `${fromRect.height}px`;
1610
1403
1611
return new Promise((resolve) =>
1404
1612
{
1405
const a = el.animate(
1406
[
1407
{
1408
left: `${fromRect.left}px`,
1409
top: `${fromRect.top}px`,
1410
width: `${fromRect.width}px`,
1411
height: `${fromRect.height}px`,
1412
},
1413
{
1414
left: `${toRect.left}px`,
1415
top: `${toRect.top}px`,
1416
width: `${toRect.width}px`,
1417
height: `${toRect.height}px`,
1418
},
1419
],
1420
{ duration, easing, fill: 'forwards' }
1421
);
1422
a.onfinish = resolve;
1423
a.oncancel = resolve;
1613
const t0 = performance.now();
1614
1615
function frame (now)
1616
{
1617
const raw = Math.min((now - t0) / duration, 1);
1618
const t = easeOut(raw);
1619
1620
const left = fromRect.left + (toRect.left - fromRect.left) * t;
1621
const top = fromRect.top + (toRect.top - fromRect.top) * t;
1622
const width = fromRect.width + (toRect.width - fromRect.width) * t;
1623
const height = fromRect.height + (toRect.height - fromRect.height) * t;
1624
1625
el.style.left = `${left}px`;
1626
el.style.top = `${top}px`;
1627
el.style.width = `${width}px`;
1628
el.style.height = `${height}px`;
1629
1630
if (raw < 1)
1631
{
1632
requestAnimationFrame(frame);
1633
} else
1634
{
1635
resolve();
1636
}
1637
}
1638
1639
requestAnimationFrame(frame);
1424
1640
});
1425
1641
}
1426
1642
@@ -1454,6 +1670,7 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU
1454
1670
const parent = tileEl.parentNode;
1455
1671
const nextSibling = tileEl.nextSibling;
1456
1672
const iconHtml = iconEl.innerHTML;
1673
const originalIconSvg = iconEl.querySelector('svg');
1457
1674
1458
1675
tileEl.remove();
1459
1676
document.body.appendChild(tileEl);
@@ -1489,7 +1706,19 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU
1489
1706
});
1490
1707
1491
1708
iconEl.innerHTML = '';
1492
await renderPreviewBody(item, blob, objectUrl, iconEl);
1709
1710
if (originalIconSvg)
1711
{
1712
const outline = originalIconSvg.cloneNode(true);
1713
outline.classList.add('preview-expand-outline');
1714
iconEl.appendChild(outline);
1715
}
1716
1717
const previewMount = document.createElement('div');
1718
previewMount.className = 'preview-expand-content';
1719
iconEl.appendChild(previewMount);
1720
1721
await renderPreviewBody(item, blob, objectUrl, previewMount);
1493
1722
1494
1723
tileEl.insertBefore(titleEl, tileEl.firstChild);
1495
1724
tileEl.appendChild(closeBtn);
@@ -1508,6 +1737,7 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU
1508
1737
closeBtn,
1509
1738
dlBtn,
1510
1739
titleEl,
1740
previewMount,
1511
1741
startRect,
1512
1742
};
1513
1743
@@ -49,6 +49,7 @@ const STATE = {49
previewSourceEl: null, // SVG element that triggered the preview49
previewSourceEl: null, // SVG element that triggered the preview50
previewClosing: false, // guard to prevent double-close during animation50
previewClosing: false, // guard to prevent double-close during animation51
previewExpandState: null, // in-place expanded tile preview state51
previewExpandState: null, // in-place expanded tile preview state52
movePicker: null,52
};53
};53
54
54
const SESSION_KEY = 'filemanager.session.v1';55
const SESSION_KEY = 'filemanager.session.v1';@@ -762,6 +763,8 @@ function renderBreadcrumb ()762
763
763
// Capture the path for this crumb764
// Capture the path for this crumb764
const capturedPath = i === 0 ? rootPath : accumulated;765
const capturedPath = i === 0 ? rootPath : accumulated;766
crumb.classList.add('crumb-drop-target');767
crumb.dataset.path = capturedPath;765
if (i < parts.length - 1)768
if (i < parts.length - 1)766
{769
{767
crumb.addEventListener('click', () => navigateTo(capturedPath, STATE.currentRoot));770
crumb.addEventListener('click', () => navigateTo(capturedPath, STATE.currentRoot));@@ -811,6 +814,7 @@ function itemsSignature (items)811
814
812
async function incrementalRefreshCurrentDir ()815
async function incrementalRefreshCurrentDir ()813
{816
{817
if (STATE.previewExpandState) return;814
if (!STATE.currentDir || STATE.uploadInProgress) return;818
if (!STATE.currentDir || STATE.uploadInProgress) return;815
819
816
const data = await api('GET', `/files/list?dir=${encodeURIComponent(STATE.currentDir)}`).catch(() => null);820
const data = await api('GET', `/files/list?dir=${encodeURIComponent(STATE.currentDir)}`).catch(() => null);@@ -1003,6 +1007,11 @@ async function openSidebar (item)1003
// Rename button (write access required)1007
// Rename button (write access required)1004
if (canWrite())1008
if (canWrite())1005
{1009
{1010
const btnMove = document.createElement('button');1011
btnMove.textContent = 'Move to';1012
btnMove.addEventListener('click', () => openMovePicker(item));1013
actions.appendChild(btnMove);1014
1006
const btnRen = document.createElement('button');1015
const btnRen = document.createElement('button');1007
btnRen.textContent = 'Rename';1016
btnRen.textContent = 'Rename';1008
btnRen.addEventListener('click', () => openRenameModal(item));1017
btnRen.addEventListener('click', () => openRenameModal(item));@@ -1059,6 +1068,199 @@ function closeSidebar ()1059
openFolderSidebar();1068
openFolderSidebar();1060
}1069
}1061
1070
1071
function basenameOfPath (p)1072
{1073
const parts = String(p || '').split(/[\\/]/).filter(Boolean);1074
return parts.length ? parts[parts.length - 1] : String(p || '');1075
}1076
1077
function writableRoots ()1078
{1079
if (STATE.isAdmin) return STATE.roots.slice();1080
return STATE.roots.filter((r) =>1081
{1082
const perm = STATE.permissions[r.label];1083
return !!(perm && perm.write);1084
});1085
}1086
1087
function ensureMoveModal ()1088
{1089
let overlay = document.getElementById('move-modal');1090
if (overlay) return overlay;1091
1092
overlay = document.createElement('div');1093
overlay.id = 'move-modal';1094
overlay.className = 'modal-overlay hidden';1095
overlay.innerHTML = `1096
<div class="modal move-modal">1097
<button class="modal-close" id="move-modal-close" aria-label="Close">✕</button>1098
<h2>Move To</h2>1099
<p id="move-modal-caption" class="muted"></p>1100
<div id="move-tree" class="move-tree"></div>1101
<p id="move-selected" class="muted"></p>1102
<div class="dialog-actions">1103
<button id="move-modal-cancel">Cancel</button>1104
<button id="move-modal-confirm" class="primary">Move</button>1105
</div>1106
</div>1107
`;1108
document.body.appendChild(overlay);1109
1110
const closeBtn = overlay.querySelector('#move-modal-close');1111
const cancelBtn = overlay.querySelector('#move-modal-cancel');1112
const confirmBtn = overlay.querySelector('#move-modal-confirm');1113
1114
function hide ()1115
{1116
overlay.classList.add('hidden');1117
STATE.movePicker = null;1118
}1119
1120
closeBtn.addEventListener('click', hide);1121
cancelBtn.addEventListener('click', hide);1122
overlay.addEventListener('click', (e) =>1123
{1124
if (e.target === overlay) hide();1125
});1126
1127
confirmBtn.addEventListener('click', async () =>1128
{1129
const st = STATE.movePicker;1130
if (!st || !st.item || !st.selectedPath)1131
{1132
toast('Select a destination folder first.', 'err');1133
return;1134
}1135
1136
try1137
{1138
await api('POST', '/files/move', { from: st.item.path, toDir: st.selectedPath });1139
}1140
catch (err)1141
{1142
toast('Move failed: ' + err.message, 'err');1143
return;1144
}1145
1146
hide();1147
if (STATE.selectedItem && STATE.selectedItem.path === st.item.path) closeSidebar();1148
navigateTo(STATE.currentDir, STATE.currentRoot);1149
});1150
1151
return overlay;1152
}1153
1154
function setMoveSelection (path, buttonEl)1155
{1156
if (!STATE.movePicker) return;1157
STATE.movePicker.selectedPath = path;1158
1159
document.querySelectorAll('.move-node-label.selected').forEach((el) => el.classList.remove('selected'));1160
if (buttonEl) buttonEl.classList.add('selected');1161
1162
const selectedEl = document.getElementById('move-selected');1163
selectedEl.textContent = path ? `Destination: ${path}` : 'Destination: none';1164
}1165
1166
async function loadMoveChildren (containerEl, dirPath)1167
{1168
if (containerEl.dataset.loaded === '1') return;1169
containerEl.dataset.loaded = '1';1170
1171
const data = await api('GET', `/files/list?dir=${encodeURIComponent(dirPath)}`).catch(() => null);1172
const folders = data ? data.items.filter((it) => it.isDir).sort((a, b) => a.name.localeCompare(b.name)) : [];1173
1174
if (!folders.length)1175
{1176
const empty = document.createElement('div');1177
empty.className = 'move-empty';1178
empty.textContent = 'No subfolders';1179
containerEl.appendChild(empty);1180
return;1181
}1182
1183
for (const child of folders)1184
{1185
containerEl.appendChild(createMoveNode(child.path, child.name));1186
}1187
}1188
1189
function createMoveNode (folderPath, label)1190
{1191
const node = document.createElement('div');1192
node.className = 'move-node';1193
1194
const row = document.createElement('div');1195
row.className = 'move-node-row';1196
1197
const toggle = document.createElement('button');1198
toggle.type = 'button';1199
toggle.className = 'move-toggle';1200
toggle.textContent = '▸';1201
1202
const selectBtn = document.createElement('button');1203
selectBtn.type = 'button';1204
selectBtn.className = 'move-node-label';1205
selectBtn.textContent = label;1206
selectBtn.addEventListener('click', () => setMoveSelection(folderPath, selectBtn));1207
1208
const children = document.createElement('div');1209
children.className = 'move-children hidden';1210
1211
toggle.addEventListener('click', async () =>1212
{1213
if (children.classList.contains('hidden'))1214
{1215
await loadMoveChildren(children, folderPath);1216
children.classList.remove('hidden');1217
toggle.textContent = '▾';1218
} else1219
{1220
children.classList.add('hidden');1221
toggle.textContent = '▸';1222
}1223
});1224
1225
row.appendChild(toggle);1226
row.appendChild(selectBtn);1227
node.appendChild(row);1228
node.appendChild(children);1229
return node;1230
}1231
1232
function openMovePicker (item)1233
{1234
if (!canWrite())1235
{1236
toast('No write access.', 'err');1237
return;1238
}1239
1240
const roots = writableRoots();1241
if (!roots.length)1242
{1243
toast('No writable destination roots available.', 'err');1244
return;1245
}1246
1247
const overlay = ensureMoveModal();1248
const tree = overlay.querySelector('#move-tree');1249
const caption = overlay.querySelector('#move-modal-caption');1250
1251
STATE.movePicker = { item, selectedPath: null };1252
caption.textContent = `Select destination folder for: ${item.name}`;1253
tree.innerHTML = '';1254
1255
for (const root of roots)1256
{1257
tree.appendChild(createMoveNode(root.path, root.label));1258
}1259
1260
setMoveSelection(null, null);1261
overlay.classList.remove('hidden');1262
}1263
1062
// ───────────────────────────────────────────────────────────────────────────1264
// ───────────────────────────────────────────────────────────────────────────1063
// DOWNLOAD / VIEW1265
// DOWNLOAD / VIEW1064
// ───────────────────────────────────────────────────────────────────────────1266
// ───────────────────────────────────────────────────────────────────────────@@ -1399,28 +1601,42 @@ function animatePreviewClose (sourceSvgEl, sheetEl)1399
function animateRect (el, fromRect, toRect, opts = {})1601
function animateRect (el, fromRect, toRect, opts = {})1400
{1602
{1401
const duration = opts.duration == null ? 260 : opts.duration;1603
const duration = opts.duration == null ? 260 : opts.duration;1402
const easing = opts.easing || 'cubic-bezier(0.22, 0.8, 0.2, 1)';1604
const easeOut = (t) => 1 - Math.pow(1 - t, 3);1605
1606
el.style.left = `${fromRect.left}px`;1607
el.style.top = `${fromRect.top}px`;1608
el.style.width = `${fromRect.width}px`;1609
el.style.height = `${fromRect.height}px`;1610
1403
return new Promise((resolve) =>1611
return new Promise((resolve) =>1404
{1612
{1405
const a = el.animate(1613
const t0 = performance.now();1406
[1614
1407
{1615
function frame (now)1408
left: `${fromRect.left}px`,1616
{1409
top: `${fromRect.top}px`,1617
const raw = Math.min((now - t0) / duration, 1);1410
width: `${fromRect.width}px`,1618
const t = easeOut(raw);1411
height: `${fromRect.height}px`,1619
1412
},1620
const left = fromRect.left + (toRect.left - fromRect.left) * t;1413
{1621
const top = fromRect.top + (toRect.top - fromRect.top) * t;1414
left: `${toRect.left}px`,1622
const width = fromRect.width + (toRect.width - fromRect.width) * t;1415
top: `${toRect.top}px`,1623
const height = fromRect.height + (toRect.height - fromRect.height) * t;1416
width: `${toRect.width}px`,1624
1417
height: `${toRect.height}px`,1625
el.style.left = `${left}px`;1418
},1626
el.style.top = `${top}px`;1419
],1627
el.style.width = `${width}px`;1420
{ duration, easing, fill: 'forwards' }1628
el.style.height = `${height}px`;1421
);1629
1422
a.onfinish = resolve;1630
if (raw < 1)1423
a.oncancel = resolve;1631
{1632
requestAnimationFrame(frame);1633
} else1634
{1635
resolve();1636
}1637
}1638
1639
requestAnimationFrame(frame);1424
});1640
});1425
}1641
}1426
1642
@@ -1454,6 +1670,7 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU1454
const parent = tileEl.parentNode;1670
const parent = tileEl.parentNode;1455
const nextSibling = tileEl.nextSibling;1671
const nextSibling = tileEl.nextSibling;1456
const iconHtml = iconEl.innerHTML;1672
const iconHtml = iconEl.innerHTML;1673
const originalIconSvg = iconEl.querySelector('svg');1457
1674
1458
tileEl.remove();1675
tileEl.remove();1459
document.body.appendChild(tileEl);1676
document.body.appendChild(tileEl);@@ -1489,7 +1706,19 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU1489
});1706
});1490
1707
1491
iconEl.innerHTML = '';1708
iconEl.innerHTML = '';1492
await renderPreviewBody(item, blob, objectUrl, iconEl);1709
1710
if (originalIconSvg)1711
{1712
const outline = originalIconSvg.cloneNode(true);1713
outline.classList.add('preview-expand-outline');1714
iconEl.appendChild(outline);1715
}1716
1717
const previewMount = document.createElement('div');1718
previewMount.className = 'preview-expand-content';1719
iconEl.appendChild(previewMount);1720
1721
await renderPreviewBody(item, blob, objectUrl, previewMount);1493
1722
1494
tileEl.insertBefore(titleEl, tileEl.firstChild);1723
tileEl.insertBefore(titleEl, tileEl.firstChild);1495
tileEl.appendChild(closeBtn);1724
tileEl.appendChild(closeBtn);@@ -1508,6 +1737,7 @@ async function openExpandedTilePreview (item, tileEl, sourceSvgEl, blob, objectU1508
closeBtn,1737
closeBtn,1509
dlBtn,1738
dlBtn,1510
titleEl,1739
titleEl,1740
previewMount,1511
startRect,1741
startRect,1512
};1742
};1513
1743
@@ -15,6 +15,44 @@
15
15
filter: drop-shadow(0 0 6px var(--accent, #5b7fff)) brightness(1.25);
16
16
}
17
17
18
.drag-parent-target {
19
position: fixed;
20
left: 16px;
21
top: 68px;
22
z-index: 10002;
23
display: inline-flex;
24
align-items: center;
25
gap: 0.45rem;
26
padding: 0.45rem 0.65rem;
27
border: 1px solid var(--border, #2e3247);
28
border-radius: 8px;
29
background: var(--surface, #1a1d27);
30
color: var(--text, #e8eaf0);
31
pointer-events: auto;
32
user-select: none;
33
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
34
}
35
36
.drag-parent-target .up {
37
color: var(--accent, #5b7fff);
38
font-weight: 700;
39
}
40
41
.drag-parent-target .label {
42
font-size: 0.82rem;
43
}
44
45
.drag-parent-target.active {
46
border-color: var(--accent, #5b7fff);
47
box-shadow: 0 0 0 2px rgba(91, 127, 255, 0.22), 0 8px 20px rgba(0, 0, 0, 0.5);
48
}
49
50
.crumb-drop-target.active {
51
color: var(--accent, #5b7fff) !important;
52
text-decoration: underline;
53
text-underline-offset: 0.2rem;
54
}
55
18
56
/* ---- drop animation: rises, spins, falls into folder ---- */
19
57
/* --dx / --dy : current viewport X/Y of the item when released */
20
58
/* --fall-x / --fall-y : viewport position of the target folder */
@@ -83,6 +121,7 @@
83
121
.file-item.file-item--preview .icon {
84
122
width: 100% !important;
85
123
height: auto !important;
124
position: relative;
86
125
flex: 1;
87
126
min-height: 0;
88
127
display: flex !important;
@@ -93,6 +132,28 @@
93
132
box-sizing: border-box;
94
133
}
95
134
135
.file-item.file-item--preview .icon .preview-expand-outline {
136
position: absolute;
137
left: 50%;
138
top: 50%;
139
width: min(72%, 640px);
140
height: min(72%, 640px);
141
transform: translate(-50%, -50%);
142
opacity: 0.22;
143
pointer-events: none;
144
z-index: 1;
145
}
146
147
.file-item.file-item--preview .icon .preview-expand-content {
148
position: relative;
149
z-index: 2;
150
width: 100%;
151
height: 100%;
152
display: flex;
153
align-items: center;
154
justify-content: center;
155
}
156
96
157
/* Keep preview media constrained within the expanded icon */
97
158
.file-item.file-item--preview .icon .preview-media {
98
159
max-width: 100%;
@@ -187,3 +248,75 @@
187
248
.preview-expand-download:hover {
188
249
opacity: 0.85;
189
250
}
251
252
.move-modal {
253
width: min(92vw, 760px);
254
max-height: min(86vh, 760px);
255
display: flex;
256
flex-direction: column;
257
gap: 0.6rem;
258
}
259
260
.move-tree {
261
border: 1px solid var(--border, #2e3247);
262
border-radius: 10px;
263
padding: 0.55rem;
264
max-height: min(58vh, 480px);
265
overflow: auto;
266
background: var(--bg, #0f1117);
267
}
268
269
.move-node {
270
margin-left: 0.25rem;
271
}
272
273
.move-node-row {
274
display: flex;
275
align-items: center;
276
gap: 0.35rem;
277
margin: 0.14rem 0;
278
}
279
280
.move-toggle {
281
width: 26px;
282
min-width: 26px;
283
height: 26px;
284
padding: 0;
285
display: inline-flex;
286
align-items: center;
287
justify-content: center;
288
}
289
290
.move-node-label {
291
display: inline-flex;
292
align-items: center;
293
justify-content: flex-start;
294
min-height: 28px;
295
width: auto;
296
padding: 0.2rem 0.5rem;
297
background: transparent;
298
border: 1px solid transparent;
299
color: var(--text, #e8eaf0);
300
}
301
302
.move-node-label:hover {
303
border-color: var(--border, #2e3247);
304
background: rgba(255, 255, 255, 0.03);
305
}
306
307
.move-node-label.selected {
308
border-color: var(--accent, #5b7fff);
309
background: rgba(91, 127, 255, 0.12);
310
}
311
312
.move-children {
313
margin-left: 1.2rem;
314
border-left: 1px dashed var(--border, #2e3247);
315
padding-left: 0.5rem;
316
}
317
318
.move-empty {
319
color: var(--text-muted, #7880a0);
320
font-size: 0.85rem;
321
margin: 0.2rem 0 0.4rem 0.2rem;
322
}
@@ -15,6 +15,44 @@15
filter: drop-shadow(0 0 6px var(--accent, #5b7fff)) brightness(1.25);15
filter: drop-shadow(0 0 6px var(--accent, #5b7fff)) brightness(1.25);16
}16
}17
17
18
.drag-parent-target {19
position: fixed;20
left: 16px;21
top: 68px;22
z-index: 10002;23
display: inline-flex;24
align-items: center;25
gap: 0.45rem;26
padding: 0.45rem 0.65rem;27
border: 1px solid var(--border, #2e3247);28
border-radius: 8px;29
background: var(--surface, #1a1d27);30
color: var(--text, #e8eaf0);31
pointer-events: auto;32
user-select: none;33
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.42);34
}35
36
.drag-parent-target .up {37
color: var(--accent, #5b7fff);38
font-weight: 700;39
}40
41
.drag-parent-target .label {42
font-size: 0.82rem;43
}44
45
.drag-parent-target.active {46
border-color: var(--accent, #5b7fff);47
box-shadow: 0 0 0 2px rgba(91, 127, 255, 0.22), 0 8px 20px rgba(0, 0, 0, 0.5);48
}49
50
.crumb-drop-target.active {51
color: var(--accent, #5b7fff) !important;52
text-decoration: underline;53
text-underline-offset: 0.2rem;54
}55
18
/* ---- drop animation: rises, spins, falls into folder ---- */56
/* ---- drop animation: rises, spins, falls into folder ---- */19
/* --dx / --dy : current viewport X/Y of the item when released */57
/* --dx / --dy : current viewport X/Y of the item when released */20
/* --fall-x / --fall-y : viewport position of the target folder */58
/* --fall-x / --fall-y : viewport position of the target folder */@@ -83,6 +121,7 @@83
.file-item.file-item--preview .icon {121
.file-item.file-item--preview .icon {84
width: 100% !important;122
width: 100% !important;85
height: auto !important;123
height: auto !important;124
position: relative;86
flex: 1;125
flex: 1;87
min-height: 0;126
min-height: 0;88
display: flex !important;127
display: flex !important;@@ -93,6 +132,28 @@93
box-sizing: border-box;132
box-sizing: border-box;94
}133
}95
134
135
.file-item.file-item--preview .icon .preview-expand-outline {136
position: absolute;137
left: 50%;138
top: 50%;139
width: min(72%, 640px);140
height: min(72%, 640px);141
transform: translate(-50%, -50%);142
opacity: 0.22;143
pointer-events: none;144
z-index: 1;145
}146
147
.file-item.file-item--preview .icon .preview-expand-content {148
position: relative;149
z-index: 2;150
width: 100%;151
height: 100%;152
display: flex;153
align-items: center;154
justify-content: center;155
}156
96
/* Keep preview media constrained within the expanded icon */157
/* Keep preview media constrained within the expanded icon */97
.file-item.file-item--preview .icon .preview-media {158
.file-item.file-item--preview .icon .preview-media {98
max-width: 100%;159
max-width: 100%;@@ -187,3 +248,75 @@187
.preview-expand-download:hover {248
.preview-expand-download:hover {188
opacity: 0.85;249
opacity: 0.85;189
}250
}251
252
.move-modal {253
width: min(92vw, 760px);254
max-height: min(86vh, 760px);255
display: flex;256
flex-direction: column;257
gap: 0.6rem;258
}259
260
.move-tree {261
border: 1px solid var(--border, #2e3247);262
border-radius: 10px;263
padding: 0.55rem;264
max-height: min(58vh, 480px);265
overflow: auto;266
background: var(--bg, #0f1117);267
}268
269
.move-node {270
margin-left: 0.25rem;271
}272
273
.move-node-row {274
display: flex;275
align-items: center;276
gap: 0.35rem;277
margin: 0.14rem 0;278
}279
280
.move-toggle {281
width: 26px;282
min-width: 26px;283
height: 26px;284
padding: 0;285
display: inline-flex;286
align-items: center;287
justify-content: center;288
}289
290
.move-node-label {291
display: inline-flex;292
align-items: center;293
justify-content: flex-start;294
min-height: 28px;295
width: auto;296
padding: 0.2rem 0.5rem;297
background: transparent;298
border: 1px solid transparent;299
color: var(--text, #e8eaf0);300
}301
302
.move-node-label:hover {303
border-color: var(--border, #2e3247);304
background: rgba(255, 255, 255, 0.03);305
}306
307
.move-node-label.selected {308
border-color: var(--accent, #5b7fff);309
background: rgba(91, 127, 255, 0.12);310
}311
312
.move-children {313
margin-left: 1.2rem;314
border-left: 1px dashed var(--border, #2e3247);315
padding-left: 0.5rem;316
}317
318
.move-empty {319
color: var(--text-muted, #7880a0);320
font-size: 0.85rem;321
margin: 0.2rem 0 0.4rem 0.2rem;322
}@@ -25,6 +25,7 @@ const _drag = {
25
25
sourceEl: null,
26
26
sourceItem: null,
27
27
placeholder: null,
28
parentTarget: null,
28
29
originRect: null,
29
30
offsetX: 0,
30
31
offsetY: 0,
@@ -98,9 +99,60 @@ function _beginDrag (e, el, item)
98
99
_drag.offsetY = e.clientY - rect.top;
99
100
_drag.currentTarget = null;
100
101
102
const parentPath = _parentDirPathForCurrentDir();
103
if (parentPath)
104
{
105
const parentTarget = _ensureParentDropTarget();
106
parentTarget.dataset.path = parentPath;
107
parentTarget.classList.remove('hidden');
108
_drag.parentTarget = parentTarget;
109
}
110
101
111
document.body.style.userSelect = 'none';
102
112
}
103
113
114
function _parentDirPathForCurrentDir ()
115
{
116
if (!STATE.currentDir || !STATE.currentRoot) return null;
117
const root = STATE.currentRoot.path;
118
const dir = STATE.currentDir;
119
if (samePath(dir, root)) return null;
120
121
const relative = String(dir).replace(String(root), '').replace(/^[\\/]/, '');
122
const parts = relative.split(/[\\/]/).filter(Boolean);
123
if (!parts.length) return null;
124
parts.pop();
125
if (!parts.length) return root;
126
127
let out = root;
128
for (const p of parts) out = joinServerPath(out, p);
129
return out;
130
}
131
132
function _ensureParentDropTarget ()
133
{
134
let el = document.getElementById('drag-parent-target');
135
if (el) return el;
136
137
el = document.createElement('div');
138
el.id = 'drag-parent-target';
139
el.className = 'drag-parent-target hidden';
140
el.innerHTML = '<span class="folder">📁</span><span class="up">↑</span><span class="label">Parent folder</span>';
141
document.body.appendChild(el);
142
return el;
143
}
144
145
function _setTargetVisual (el, active)
146
{
147
if (!el) return;
148
if (el.classList.contains('file-item'))
149
{
150
el.classList.toggle('drop-target', !!active);
151
return;
152
}
153
el.classList.toggle('active', !!active);
154
}
155
104
156
function _moveDrag (e)
105
157
{
106
158
const x = e.clientX - _drag.offsetX;
@@ -108,17 +160,18 @@ function _moveDrag (e)
108
160
_drag.sourceEl.style.transform = `translate(${x}px, ${y}px)`;
109
161
110
162
const under = document.elementFromPoint(e.clientX, e.clientY);
111
const targetEl = under && under.closest('.file-item[data-isdir]');
112
const isValidTarget = targetEl && targetEl !== _drag.placeholder;
163
const targetEl = under && under.closest('.file-item[data-isdir], .drag-parent-target, .crumb-drop-target');
164
const targetPath = targetEl ? targetEl.dataset.path : null;
165
const isValidTarget = !!(targetEl && targetPath && targetEl !== _drag.placeholder);
113
166
114
167
if (_drag.currentTarget && _drag.currentTarget !== targetEl)
115
168
{
116
_drag.currentTarget.classList.remove('drop-target');
169
_setTargetVisual(_drag.currentTarget, false);
117
170
}
118
171
119
172
if (isValidTarget)
120
173
{
121
targetEl.classList.add('drop-target');
174
_setTargetVisual(targetEl, true);
122
175
_drag.currentTarget = targetEl;
123
176
} else
124
177
{
@@ -129,7 +182,7 @@ function _moveDrag (e)
129
182
function _endDrag ()
130
183
{
131
184
const target = _drag.currentTarget;
132
if (target) target.classList.remove('drop-target');
185
if (target) _setTargetVisual(target, false);
133
186
document.body.style.userSelect = '';
134
187
135
188
if (!target)
@@ -143,16 +196,16 @@ function _endDrag ()
143
196
const curX = match ? parseFloat(match[1]) : _drag.originRect.left;
144
197
const curY = match ? parseFloat(match[2]) : _drag.originRect.top;
145
198
146
const folderRect = target.getBoundingClientRect();
147
const fallX = folderRect.left + folderRect.width / 2 - _drag.originRect.width / 2;
148
const fallY = folderRect.top;
199
const targetRect = target.getBoundingClientRect();
200
const fallX = targetRect.left + targetRect.width / 2 - _drag.originRect.width / 2;
201
const fallY = targetRect.top;
149
202
150
203
el.style.setProperty('--dx', curX + 'px');
151
204
el.style.setProperty('--dy', curY + 'px');
152
205
el.style.setProperty('--fall-x', fallX + 'px');
153
206
el.style.setProperty('--fall-y', fallY + 'px');
154
207
el.classList.add('dropping');
155
target.classList.add('folder-bounce');
208
if (target.classList.contains('file-item')) target.classList.add('folder-bounce');
156
209
157
210
const sourceItem = _drag.sourceItem;
158
211
@@ -220,7 +273,12 @@ function _cleanupDrag (reinsert)
220
273
const el = _drag.sourceEl;
221
274
const placeholder = _drag.placeholder;
222
275
223
if (_drag.currentTarget) _drag.currentTarget.classList.remove('drop-target');
276
if (_drag.currentTarget) _setTargetVisual(_drag.currentTarget, false);
277
if (_drag.parentTarget)
278
{
279
_drag.parentTarget.classList.remove('active');
280
_drag.parentTarget.classList.add('hidden');
281
}
224
282
225
283
if (el)
226
284
{
@@ -255,6 +313,7 @@ function _cleanupDrag (reinsert)
255
313
_drag.sourceEl = null;
256
314
_drag.sourceItem = null;
257
315
_drag.placeholder = null;
316
_drag.parentTarget = null;
258
317
_drag.originRect = null;
259
318
_drag.currentTarget = null;
260
319
}
@@ -25,6 +25,7 @@ const _drag = {25
sourceEl: null,25
sourceEl: null,26
sourceItem: null,26
sourceItem: null,27
placeholder: null,27
placeholder: null,28
parentTarget: null,28
originRect: null,29
originRect: null,29
offsetX: 0,30
offsetX: 0,30
offsetY: 0,31
offsetY: 0,@@ -98,9 +99,60 @@ function _beginDrag (e, el, item)98
_drag.offsetY = e.clientY - rect.top;99
_drag.offsetY = e.clientY - rect.top;99
_drag.currentTarget = null;100
_drag.currentTarget = null;100
101
102
const parentPath = _parentDirPathForCurrentDir();103
if (parentPath)104
{105
const parentTarget = _ensureParentDropTarget();106
parentTarget.dataset.path = parentPath;107
parentTarget.classList.remove('hidden');108
_drag.parentTarget = parentTarget;109
}110
101
document.body.style.userSelect = 'none';111
document.body.style.userSelect = 'none';102
}112
}103
113
114
function _parentDirPathForCurrentDir ()115
{116
if (!STATE.currentDir || !STATE.currentRoot) return null;117
const root = STATE.currentRoot.path;118
const dir = STATE.currentDir;119
if (samePath(dir, root)) return null;120
121
const relative = String(dir).replace(String(root), '').replace(/^[\\/]/, '');122
const parts = relative.split(/[\\/]/).filter(Boolean);123
if (!parts.length) return null;124
parts.pop();125
if (!parts.length) return root;126
127
let out = root;128
for (const p of parts) out = joinServerPath(out, p);129
return out;130
}131
132
function _ensureParentDropTarget ()133
{134
let el = document.getElementById('drag-parent-target');135
if (el) return el;136
137
el = document.createElement('div');138
el.id = 'drag-parent-target';139
el.className = 'drag-parent-target hidden';140
el.innerHTML = '<span class="folder">📁</span><span class="up">↑</span><span class="label">Parent folder</span>';141
document.body.appendChild(el);142
return el;143
}144
145
function _setTargetVisual (el, active)146
{147
if (!el) return;148
if (el.classList.contains('file-item'))149
{150
el.classList.toggle('drop-target', !!active);151
return;152
}153
el.classList.toggle('active', !!active);154
}155
104
function _moveDrag (e)156
function _moveDrag (e)105
{157
{106
const x = e.clientX - _drag.offsetX;158
const x = e.clientX - _drag.offsetX;@@ -108,17 +160,18 @@ function _moveDrag (e)108
_drag.sourceEl.style.transform = `translate(${x}px, ${y}px)`;160
_drag.sourceEl.style.transform = `translate(${x}px, ${y}px)`;109
161
110
const under = document.elementFromPoint(e.clientX, e.clientY);162
const under = document.elementFromPoint(e.clientX, e.clientY);111
const targetEl = under && under.closest('.file-item[data-isdir]');163
const targetEl = under && under.closest('.file-item[data-isdir], .drag-parent-target, .crumb-drop-target');112
const isValidTarget = targetEl && targetEl !== _drag.placeholder;164
const targetPath = targetEl ? targetEl.dataset.path : null;165
const isValidTarget = !!(targetEl && targetPath && targetEl !== _drag.placeholder);113
166
114
if (_drag.currentTarget && _drag.currentTarget !== targetEl)167
if (_drag.currentTarget && _drag.currentTarget !== targetEl)115
{168
{116
_drag.currentTarget.classList.remove('drop-target');169
_setTargetVisual(_drag.currentTarget, false);117
}170
}118
171
119
if (isValidTarget)172
if (isValidTarget)120
{173
{121
targetEl.classList.add('drop-target');174
_setTargetVisual(targetEl, true);122
_drag.currentTarget = targetEl;175
_drag.currentTarget = targetEl;123
} else176
} else124
{177
{@@ -129,7 +182,7 @@ function _moveDrag (e)129
function _endDrag ()182
function _endDrag ()130
{183
{131
const target = _drag.currentTarget;184
const target = _drag.currentTarget;132
if (target) target.classList.remove('drop-target');185
if (target) _setTargetVisual(target, false);133
document.body.style.userSelect = '';186
document.body.style.userSelect = '';134
187
135
if (!target)188
if (!target)@@ -143,16 +196,16 @@ function _endDrag ()143
const curX = match ? parseFloat(match[1]) : _drag.originRect.left;196
const curX = match ? parseFloat(match[1]) : _drag.originRect.left;144
const curY = match ? parseFloat(match[2]) : _drag.originRect.top;197
const curY = match ? parseFloat(match[2]) : _drag.originRect.top;145
198
146
const folderRect = target.getBoundingClientRect();199
const targetRect = target.getBoundingClientRect();147
const fallX = folderRect.left + folderRect.width / 2 - _drag.originRect.width / 2;200
const fallX = targetRect.left + targetRect.width / 2 - _drag.originRect.width / 2;148
const fallY = folderRect.top;201
const fallY = targetRect.top;149
202
150
el.style.setProperty('--dx', curX + 'px');203
el.style.setProperty('--dx', curX + 'px');151
el.style.setProperty('--dy', curY + 'px');204
el.style.setProperty('--dy', curY + 'px');152
el.style.setProperty('--fall-x', fallX + 'px');205
el.style.setProperty('--fall-x', fallX + 'px');153
el.style.setProperty('--fall-y', fallY + 'px');206
el.style.setProperty('--fall-y', fallY + 'px');154
el.classList.add('dropping');207
el.classList.add('dropping');155
target.classList.add('folder-bounce');208
if (target.classList.contains('file-item')) target.classList.add('folder-bounce');156
209
157
const sourceItem = _drag.sourceItem;210
const sourceItem = _drag.sourceItem;158
211
@@ -220,7 +273,12 @@ function _cleanupDrag (reinsert)220
const el = _drag.sourceEl;273
const el = _drag.sourceEl;221
const placeholder = _drag.placeholder;274
const placeholder = _drag.placeholder;222
275
223
if (_drag.currentTarget) _drag.currentTarget.classList.remove('drop-target');276
if (_drag.currentTarget) _setTargetVisual(_drag.currentTarget, false);277
if (_drag.parentTarget)278
{279
_drag.parentTarget.classList.remove('active');280
_drag.parentTarget.classList.add('hidden');281
}224
282
225
if (el)283
if (el)226
{284
{@@ -255,6 +313,7 @@ function _cleanupDrag (reinsert)255
_drag.sourceEl = null;313
_drag.sourceEl = null;256
_drag.sourceItem = null;314
_drag.sourceItem = null;257
_drag.placeholder = null;315
_drag.placeholder = null;316
_drag.parentTarget = null;258
_drag.originRect = null;317
_drag.originRect = null;259
_drag.currentTarget = null;318
_drag.currentTarget = null;260
}319
}