Skip to content

Commit 3f3d3d4

Browse files
committed
feat: add edit button to image right top
1 parent 28c06a3 commit 3f3d3d4

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ The label of a draw.io image block can be configured in the plugin settings.
8181

8282
## Changelog
8383

84+
+ v0.6.4
85+
+ Feature: Add edit button to image right top
8486
+ v0.6.3
8587
+ Add QQ group
8688
+ v0.6.2

README_zh_CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272

7373
## 更新日志
7474

75+
+ v0.6.4
76+
+ 新增功能:图片右上角编辑按钮
7577
+ v0.6.3
7678
+ 增加QQ交流群
7779
+ v0.6.2

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.6.3",
3+
"version": "0.6.4",
44
"type": "module",
55
"description": "This is a plugin for siyuan",
66
"author": "",

plugin.json

Lines changed: 3 additions & 3 deletions
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.6.3",
5+
"version": "0.6.4",
66
"minAppVersion": "3.0.0",
77
"disabledInPublish": true,
88
"backends": [
@@ -16,8 +16,8 @@
1616
"zh_CN": "「嵌入式系列」draw.io"
1717
},
1818
"description": {
19-
"default": "「Embed Series」Create editable SVG/PNG Image with draw.io",
20-
"zh_CN": "「嵌入式系列」使用draw.io创建可编辑的SVG/PNG图像"
19+
"default": "Create editable SVG/PNG Image with draw.io",
20+
"zh_CN": "使用draw.io创建可编辑的SVG/PNG图像"
2121
},
2222
"readme": {
2323
"default": "README.md",

src/index.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,35 @@ export default class DrawioPlugin extends Plugin {
7373
if (imageElement) {
7474
const imageURL = imageElement.getAttribute("data-src");
7575
this.getDrawioImageInfo(imageURL, false).then((imageInfo) => {
76-
this.updateAttrLabel(imageInfo, blockElement);
76+
if (imageInfo) {
77+
this.updateAttrLabel(imageInfo, blockElement);
78+
const actionElement = blockElement.querySelector(".protyle-action") as HTMLElement;
79+
if (actionElement) {
80+
const editBtnElement = HTMLToElement(`<span aria-label="${this.i18n.editDrawio}" data-position="4north" class="ariaLabel protyle-icon"><svg><use xlink:href="#iconEdit"></use></svg></span>`);
81+
editBtnElement.addEventListener("click", (event: PointerEvent) => {
82+
event.preventDefault();
83+
event.stopPropagation();
84+
if (!this.isMobile && this.data[STORAGE_NAME].editWindow === 'tab') {
85+
this.openEditTab(imageInfo);
86+
} else {
87+
this.openEditDialog(imageInfo);
88+
}
89+
});
90+
actionElement.insertAdjacentElement('afterbegin', editBtnElement);
91+
for (const child of actionElement.children) {
92+
child.classList.toggle('protyle-icon--only', false);
93+
child.classList.toggle('protyle-icon--first', false);
94+
child.classList.toggle('protyle-icon--last', false);
95+
}
96+
if (actionElement.children.length == 1) {
97+
actionElement.firstElementChild.classList.toggle('protyle-icon--only', true);
98+
}
99+
else if (actionElement.children.length > 1) {
100+
actionElement.firstElementChild.classList.toggle('protyle-icon--first', true);
101+
actionElement.lastElementChild.classList.toggle('protyle-icon--last', true);
102+
}
103+
}
104+
}
77105
});
78106
}
79107
});

0 commit comments

Comments
 (0)