Skip to content

Commit 60df7d2

Browse files
committed
feat: lightbox
1 parent bc8b880 commit 60df7d2

File tree

8 files changed

+135
-9
lines changed

8 files changed

+135
-9
lines changed

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,53 @@ This plugin serves as the third plugin in the **Embed Series**, aiming to provid
3030
- [x] Support export to PDF
3131
- [x] Support for mobile devices
3232
- [x] Support dark mode
33+
- [x] Lightbox
3334

3435
> If you have additional feature requests or suggestions, feel free to [open an issue on GitHub](https://github.com/YuxinZhaozyx/siyuan-embed-drawio/issues) or [post in the SiYuan community](https://ld246.com/article/1762744532030) to request support for additional packages.
3536
3637
## Effects
3738

39+
Edit:
40+
3841
![image.png](https://b3logfile.com/file/2025/11/image-r5KMPJt.png)
3942

43+
Lightbox:
44+
45+
![image.png](https://b3logfile.com/file/2025/11/image-HcmEJ0P.png)
46+
4047
## Usage Guide
4148

42-
**Create a draw.io Image:**
49+
**Create a draw.io Image:**
50+
4351
Type `/drawio` in the editor to create a new draw.io image.
4452

45-
**Edit a draw.io Image:**
53+
**Edit a draw.io Image:**
54+
4655
Click the menu button in the top-right corner of the image. If the block is recognized as a valid draw.io image, an `Edit draw.io` option will appear. Click it to open the editor.
4756

57+
**Open draw.io Lightbox:**
58+
59+
Click the menu button in the top-right corner of the image. If the block is recognized as a valid draw.io image, an `draw.io lightbox` option will appear. Click it to open the lightbox.
60+
4861
**Migrating from other sources:**
62+
4963
+ Method 1: Simply export your diagram as an SVG from any draw.io platform with the "Include a copy of my diagram" option enabled, then drag the resulting SVG file into SiYuan.
5064
+ Method 2: Copy all content from any draw.io platform, type `/drawio` in the editor, and paste the copied content into the pop-up draw.io window.
5165

66+
**Disable draw.io label:**
67+
68+
Add CSS Snippet:
69+
70+
```css
71+
.protyle-attr .label--embed-drawio {
72+
display: none !important;
73+
}
74+
```
75+
5276
## Changelog
5377

78+
+ v0.2.1
79+
+ Feature: lightbox
5480
+ v0.2.0
5581
+ Feature: show draw.io image label and page counts
5682
+ v0.1.6

README_zh_CN.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@
2424

2525
## 使用效果
2626

27+
编辑:
28+
2729
![image.png](https://b3logfile.com/file/2025/11/image-r5KMPJt.png)
2830

31+
灯箱:
32+
33+
![image.png](https://b3logfile.com/file/2025/11/image-HcmEJ0P.png)
34+
2935
## 功能
3036

3137
- [x] 无网络离线使用
@@ -34,22 +40,35 @@
3440
- [x] 支持导出PDF
3541
- [x] 支持移动端编辑
3642
- [x] 图像支持暗黑模式
43+
- [x] 灯箱
3744

3845
> 如有更多需求/建议欢迎[在GitHub仓库中提issue](https://github.com/YuxinZhaozyx/siyuan-embed-drawio/issues)[在思源笔记社区中发帖](https://ld246.com/article/1762744532030)
3946
4047
## 使用指南
4148

4249
**创建draw.io图像:** 在编辑器中输入 `/drawio` 命令即可创建新draw.io图像。
4350

44-
**编辑draw.io图像:** 点击图像右上角的菜单按钮,当图像被识别为合法的draw.io图像时,菜单中会显示 `编辑draw.io` 的选项,点击即可打开编辑窗口。
51+
**编辑draw.io图像:** 右键/点击图像右上角的菜单按钮,当图像被识别为合法的draw.io图像时,菜单中会显示 `编辑draw.io` 的选项,点击即可打开编辑窗口。
52+
53+
**查看draw.io灯箱:** 右键/点击图像右上角的菜单按钮,当图像被识别为合法的draw.io图像时,菜单中会显示 `draw.io 灯箱` 的选项,点击即可打开灯箱窗口。
4554

4655
**从其他来源迁移:**
4756

4857
+ 方案1:只需要在任意draw.io平台导出SVG图像时勾选 `包含绘图副本` 选项,再把SVG图像拖入思源笔记中即可,不用担心以后没法再迁移,这个SVG图像也是可以导入到任意draw.io再次编辑的。
4958
+ 方案2:在任意draw.io平台内复制全部内容,在思源笔记中输入 `/drawio` 命令创建新draw.io图像,然后将复制的内容粘贴进弹出的draw.io窗口中即可。
5059

60+
**移除draw.io标签:** 添加下列代码片段:
61+
62+
```css
63+
.protyle-attr .label--embed-drawio {
64+
display: none !important;
65+
}
66+
```
67+
5168
## 更新日志
5269

70+
+ v0.2.1
71+
+ 新增功能:灯箱
5372
+ v0.2.0
5473
+ 新增功能:draw.io图像右上侧显示标签和页数
5574
+ v0.1.6

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "siyuan-embed-drawio",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"type": "module",
55
"description": "This is a plugin for siyuan",
66
"author": "",

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "siyuan-embed-drawio",
33
"author": "Yuxin Zhao",
44
"url": "https://github.com/YuxinZhaozyx/siyuan-embed-drawio",
5-
"version": "0.2.0",
5+
"version": "0.2.1",
66
"minAppVersion": "3.3.0",
77
"disabledInPublish": true,
88
"backends": [

src/i18n/en_US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"editDrawio": "Edit draw.io"
2+
"editDrawio": "Edit draw.io",
3+
"drawioLightbox": "draw.io Lightbox"
34
}

src/i18n/zh_CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"editDrawio": "编辑 draw.io"
2+
"editDrawio": "编辑 draw.io",
3+
"drawioLightbox": "draw.io 灯箱"
34
}

src/index.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
.drawio-edit-dialog {
1+
.drawio-edit-dialog,
2+
.drawio-lightbox-dialog {
23
flex: 1;
34
display: flex;
45
flex-direction: column;

src/index.ts

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,16 @@ export default class DrawioPlugin extends Plugin {
228228
click: () => {
229229
this.openEditDialog(imageInfo);
230230
}
231-
})
231+
});
232+
window.siyuan.menus.menu.addItem({
233+
id: "drawio-lightbox",
234+
icon: 'iconImage',
235+
label: `${this.i18n.drawioLightbox}`,
236+
index: 1,
237+
click: () => {
238+
this.openLightboxDialog(imageInfo);
239+
}
240+
});
232241
}
233242
})
234243
}
@@ -358,4 +367,73 @@ export default class DrawioPlugin extends Plugin {
358367
});
359368
}
360369

370+
public openLightboxDialog(imageInfo: DrawioImageInfo) {
371+
const lightboxDialogHTML = `
372+
<div class="drawio-lightbox-dialog">
373+
<div class="edit-dialog-header resize__move"></div>
374+
<div class="edit-dialog-container">
375+
<div class="edit-dialog-editor">
376+
<iframe src="/plugins/siyuan-embed-drawio/draw/index.html?proto=json&embed=1${this.isMobile?"&ui=min":""}&lang=${window.siyuan.config.lang.split('_')[0]}&lightbox=1"></iframe>
377+
</div>
378+
<div class="fn__hr--b"></div>
379+
</div>
380+
</div>
381+
`;
382+
383+
const dialogDestroyCallbacks = [];
384+
385+
const dialog = new Dialog({
386+
content: lightboxDialogHTML,
387+
width: this.isMobile ? "92vw" : "90vw",
388+
height: "80vh",
389+
hideCloseIcon: this.isMobile,
390+
destroyCallback: () => {
391+
dialogDestroyCallbacks.forEach(callback => callback());
392+
},
393+
});
394+
395+
const iframe = dialog.element.querySelector("iframe");
396+
iframe.focus();
397+
398+
const postMessage = (message: any) => {
399+
if (!iframe.contentWindow) return;
400+
iframe.contentWindow.postMessage(JSON.stringify(message), '*');
401+
};
402+
403+
const onInit = (message: any) => {
404+
postMessage({
405+
action: "load",
406+
autosave: 0,
407+
modified: 'unsavedChanges',
408+
title: this.isMobile ? '' : imageInfo.imageURL,
409+
xml: imageInfo.data,
410+
});
411+
}
412+
413+
const messageEventHandler = (event) => {
414+
if (event.data && event.data.length > 0)
415+
{
416+
try
417+
{
418+
var message = JSON.parse(event.data);
419+
if (message != null)
420+
{
421+
// console.log(message.event);
422+
if (message.event == "init") {
423+
onInit(message);
424+
}
425+
}
426+
}
427+
catch (err)
428+
{
429+
console.error(err);
430+
}
431+
}
432+
};
433+
434+
window.addEventListener("message", messageEventHandler);
435+
dialogDestroyCallbacks.push(() => {
436+
window.removeEventListener("message", messageEventHandler);
437+
});
438+
}
361439
}

0 commit comments

Comments
 (0)