-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
98 lines (71 loc) · 3.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const { onShortcut, onDispatch, getCurrentPage, getBlockUuid } = await import('logseq');
// onShortcut('your-shortcut-key', async () => {
// const currentPage = await getCurrentPage();
// const selectedBlock = await logseq.getSelection();
// if (!selectedBlock || selectedBlock.length === 0) {
// return console.warn('Please select a block to move');
// }
// const blockUuid = await getBlockUuid(selectedBlock[0].ref); // Get the UUID of the selected block
// const targetPage = await logseq.getPageTitle('Target Page Name'); // Replace with logic to get the target page title
// if (!targetPage) {
// return console.warn('Target page not found');
// }
// await logseq.appendBlock(targetPage, `[[${blockUuid}]]`); // Append reference to target page
// // Remove the block from the current page (optional)
// // await logseq.deleteBlock(selectedBlock[0].ref);
// console.log('Block moved and reference added successfully');
// });
// logseq.ready(() => {
// logseq.App.showMsg("Hello World Logseq!");
// }).catch(console.error);
// logseq.provide('swap-transclude', async (e) => {
// const { blockId, content } = e.detail;
// const block = await logseq.Editor.getBlock(blockId);
// const newContent = content.replace(/!\[\[([^\]]+)\]\]/g, (match, p1) => {
// return `[[${p1}]]`;
// });
// await logseq.Editor.updateBlock(blockId, newContent);
// });
function handleSwapTranscludeClick(blockId) {
// Code to handle the menu item click
console.log("Menu item clicked for block:", blockId);
// You can perform any action you want here
}
logseq.provideCommand("Swap-Transclude", {
// This function will be called when the menu item is clicked
handler: (ctx) => {
handleSwapTranscludeClick(ctx.block.id);
},
});
logseq.ready(() => {
logseq.App.showMsg("Hello World Logseq!");
// logseq.Editor.registerBlockContextMenu("Journal-Swap", [
// {
// label: "Swap-Transclude",
// action: "Swap-Transclude",
// },
// ]);
});
// onDispatch('block-context-menu-open', async (payload) => {
// // Add the option to the block context menu (optional)
// payload.push({
// label: 'Move with Reference',
// onClick: async () => {
// // Move block logic here using the above code
// const currentPage = await getCurrentPage();
// const selectedBlock = await logseq.getSelection();
// if (!selectedBlock || selectedBlock.length === 0) {
// return console.warn('Please select a block to move');
// }
// const blockUuid = await getBlockUuid(selectedBlock[0].ref); // Get the UUID of the selected block
// const targetPage = await logseq.getPageTitle('Target Page Name'); // Replace with logic to get the target page title
// if (!targetPage) {
// return console.warn('Target page not found');
// }
// await logseq.appendBlock(targetPage, `[[${blockUuid}]]`); // Append reference to target page
// // Remove the block from the current page (optional)
// // await logseq.deleteBlock(selectedBlock[0].ref);
// console.log('Block moved and reference added successfully');
// },
// });
// });