mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	chore(client/ts): port services/clipboard
This commit is contained in:
		
							parent
							
								
									c0e9684f73
								
							
						
					
					
						commit
						911323c099
					
				@ -255,7 +255,7 @@ ws.subscribeToMessages(async message => {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function cloneNoteToBranch(childNoteId: string, parentBranchId: string, prefix: string) {
 | 
					async function cloneNoteToBranch(childNoteId: string, parentBranchId: string, prefix?: string) {
 | 
				
			||||||
    const resp = await server.put<Response>(`notes/${childNoteId}/clone-to-branch/${parentBranchId}`, {
 | 
					    const resp = await server.put<Response>(`notes/${childNoteId}/clone-to-branch/${parentBranchId}`, {
 | 
				
			||||||
        prefix: prefix
 | 
					        prefix: prefix
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
				
			|||||||
@ -5,10 +5,10 @@ import linkService from "./link.js";
 | 
				
			|||||||
import utils from "./utils.js";
 | 
					import utils from "./utils.js";
 | 
				
			||||||
import { t } from "./i18n.js";
 | 
					import { t } from "./i18n.js";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let clipboardBranchIds = [];
 | 
					let clipboardBranchIds: string[] = [];
 | 
				
			||||||
let clipboardMode = null;
 | 
					let clipboardMode: string | null = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function pasteAfter(afterBranchId) {
 | 
					async function pasteAfter(afterBranchId: string) {
 | 
				
			||||||
    if (isClipboardEmpty()) {
 | 
					    if (isClipboardEmpty()) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -23,7 +23,14 @@ async function pasteAfter(afterBranchId) {
 | 
				
			|||||||
        const clipboardBranches = clipboardBranchIds.map(branchId => froca.getBranch(branchId));
 | 
					        const clipboardBranches = clipboardBranchIds.map(branchId => froca.getBranch(branchId));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const clipboardBranch of clipboardBranches) {
 | 
					        for (const clipboardBranch of clipboardBranches) {
 | 
				
			||||||
 | 
					            if (!clipboardBranch) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const clipboardNote = await clipboardBranch.getNote();
 | 
					            const clipboardNote = await clipboardBranch.getNote();
 | 
				
			||||||
 | 
					            if (!clipboardNote) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await branchService.cloneNoteAfter(clipboardNote.noteId, afterBranchId);
 | 
					            await branchService.cloneNoteAfter(clipboardNote.noteId, afterBranchId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -35,7 +42,7 @@ async function pasteAfter(afterBranchId) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function pasteInto(parentBranchId) {
 | 
					async function pasteInto(parentBranchId: string) {
 | 
				
			||||||
    if (isClipboardEmpty()) {
 | 
					    if (isClipboardEmpty()) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -50,7 +57,14 @@ async function pasteInto(parentBranchId) {
 | 
				
			|||||||
        const clipboardBranches = clipboardBranchIds.map(branchId => froca.getBranch(branchId));
 | 
					        const clipboardBranches = clipboardBranchIds.map(branchId => froca.getBranch(branchId));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (const clipboardBranch of clipboardBranches) {
 | 
					        for (const clipboardBranch of clipboardBranches) {
 | 
				
			||||||
 | 
					            if (!clipboardBranch) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const clipboardNote = await clipboardBranch.getNote();
 | 
					            const clipboardNote = await clipboardBranch.getNote();
 | 
				
			||||||
 | 
					            if (!clipboardNote) {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            await branchService.cloneNoteToBranch(clipboardNote.noteId, parentBranchId);
 | 
					            await branchService.cloneNoteToBranch(clipboardNote.noteId, parentBranchId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -62,7 +76,7 @@ async function pasteInto(parentBranchId) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function copy(branchIds) {
 | 
					async function copy(branchIds: string[]) {
 | 
				
			||||||
    clipboardBranchIds = branchIds;
 | 
					    clipboardBranchIds = branchIds;
 | 
				
			||||||
    clipboardMode = 'copy';
 | 
					    clipboardMode = 'copy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -82,7 +96,7 @@ async function copy(branchIds) {
 | 
				
			|||||||
    toastService.showMessage(t("clipboard.copied"));
 | 
					    toastService.showMessage(t("clipboard.copied"));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function cut(branchIds) {
 | 
					function cut(branchIds: string[]) {
 | 
				
			||||||
    clipboardBranchIds = branchIds;
 | 
					    clipboardBranchIds = branchIds;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (clipboardBranchIds.length > 0) {
 | 
					    if (clipboardBranchIds.length > 0) {
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user