feat: drag onto file bookmark creates parent note + fix calendar layout
Drag-and-drop: - Dropping a bookmark onto a file bookmark (middle zone) creates a new parent note group containing both items - Dropping onto a group still moves into the group as before - All file/group bookmarks now accept drops (3-zone behavior) Calendar: - Fixed broken table layout caused by display:flex on td elements - Uses vertical-align:middle instead for cell content centering - Calendar cells still have configurable height via CSS variable
This commit is contained in:
@@ -604,7 +604,7 @@ export class WaypointView extends ItemView {
|
||||
rowEl.addClass('waypoint-bm-dragging');
|
||||
});
|
||||
|
||||
const canAcceptChildren = isGroup || (item.children && item.children.length > 0);
|
||||
const canAcceptChildren = true; // all file/group bookmarks can accept drops
|
||||
|
||||
rowEl.addEventListener('dragend', () => {
|
||||
this.dragId = null;
|
||||
@@ -646,7 +646,11 @@ export class WaypointView extends ItemView {
|
||||
|
||||
const dropInto = (rowEl as any).__dropInto;
|
||||
if (dropInto && canAcceptChildren) {
|
||||
if (isGroup) {
|
||||
this.moveBookmarkToGroup(draggedId, item.id);
|
||||
} else {
|
||||
this.createParentNoteAndMove(draggedId, item.id);
|
||||
}
|
||||
} else {
|
||||
const dropAbove = (rowEl as any).__dropAbove;
|
||||
this.moveBookmarkToPosition(draggedId, item.id, dropAbove);
|
||||
@@ -1001,6 +1005,64 @@ export class WaypointView extends ItemView {
|
||||
this.redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new parent note group at the target's position,
|
||||
* containing both the target and the dragged item.
|
||||
*/
|
||||
private createParentNoteAndMove(draggedId: string, targetId: string): void {
|
||||
const removeById = (items: BookmarkItem[]): BookmarkItem | null => {
|
||||
const idx = items.findIndex(i => i.id === draggedId);
|
||||
if (idx >= 0) {
|
||||
const [removed] = items.splice(idx, 1);
|
||||
return removed;
|
||||
}
|
||||
for (const child of items) {
|
||||
if (child.children) {
|
||||
const found = removeById(child.children);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const dragged = removeById(this.plugin.waypointData.bookmarks);
|
||||
if (!dragged) return;
|
||||
|
||||
// Find the target in its parent array
|
||||
const findTarget = (items: BookmarkItem[]): { parent: BookmarkItem[]; idx: number } | null => {
|
||||
const idx = items.findIndex(i => i.id === targetId);
|
||||
if (idx >= 0) return { parent: items, idx };
|
||||
for (const child of items) {
|
||||
if (child.children) {
|
||||
const result = findTarget(child.children);
|
||||
if (result) return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const targetInfo = findTarget(this.plugin.waypointData.bookmarks);
|
||||
if (!targetInfo) return;
|
||||
|
||||
const target = targetInfo.parent[targetInfo.idx];
|
||||
const newGroup: BookmarkItem = {
|
||||
id: `bm-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`,
|
||||
type: 'group',
|
||||
label: target.label,
|
||||
filePath: target.filePath || '',
|
||||
icon: '',
|
||||
children: [{ ...target, indent: 1 }, { ...dragged, indent: 1 }],
|
||||
collapsed: false,
|
||||
indent: target.indent,
|
||||
};
|
||||
|
||||
// Replace target with the new group
|
||||
targetInfo.parent.splice(targetInfo.idx, 1, newGroup);
|
||||
|
||||
this.plugin.saveWaypointData();
|
||||
this.redraw();
|
||||
}
|
||||
|
||||
private moveBookmarkToPosition(draggedId: string, targetId: string, before: boolean): void {
|
||||
// Find and remove the dragged item from wherever it is
|
||||
const removeById = (items: BookmarkItem[]): { item: BookmarkItem | null; parent: BookmarkItem[] } => {
|
||||
|
||||
+1
-3
@@ -159,9 +159,7 @@
|
||||
border-radius: 6px;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.waypoint-calendar .waypoint-day:hover {
|
||||
|
||||
Reference in New Issue
Block a user