-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraft.js
37 lines (30 loc) · 1.05 KB
/
draft.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
// This script requires the `@logseq/plugins` library
logseq.beforeRenderBlock(({ block, uuid }) => {
// Check if the block is selected
if (!block.isSelected) return;
// Add a custom right-click menu item
logseq.addBlockContextMenu(
{
title: "Move to Page & Embed Reference",
fn: async () => {
// Get the selected page URL
const currentPageUrl = await logseq.getCurrentPage().url;
// Prompt for target page URL
const targetPageUrl = await logseq.ui.openInputPrompt({
label: "Enter target page URL:",
});
if (!targetPageUrl) return;
// Move the block to the target page
await logseq.Editor.moveBlockToPage(uuid, targetPageUrl);
// Create a transclusion back to the original block
const transclusion = await logseq.Editor.createBlock({
content: `[[${uuid}]]`,
parent: currentPageUrl,
});
// Select the newly created transclusion block
logseq.Editor.setSelection(transclusion.uuid);
},
},
block
);
});