update typescript
This commit is contained in:
parent
c2d3812e19
commit
8be20e023c
1 changed files with 56 additions and 13 deletions
69
src/index.ts
69
src/index.ts
|
@ -11,7 +11,7 @@ import {
|
||||||
IModel,
|
IModel,
|
||||||
Setting,
|
Setting,
|
||||||
fetchPost,
|
fetchPost,
|
||||||
Protyle, openWindow
|
Protyle, openWindow, IOperation
|
||||||
} from "siyuan";
|
} from "siyuan";
|
||||||
import "@/index.scss";
|
import "@/index.scss";
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ export default class PluginSample extends Plugin {
|
||||||
});
|
});
|
||||||
|
|
||||||
const statusIconTemp = document.createElement("template");
|
const statusIconTemp = document.createElement("template");
|
||||||
statusIconTemp.innerHTML = `<div class="toolbar__item b3-tooltips b3-tooltips__w" aria-label="Remove plugin-sample Data">
|
statusIconTemp.innerHTML = `<div class="toolbar__item ariaLabel" aria-label="Remove plugin-sample Data">
|
||||||
<svg>
|
<svg>
|
||||||
<use xlink:href="#iconTrashcan"></use>
|
<use xlink:href="#iconTrashcan"></use>
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -272,19 +272,38 @@ export default class PluginSample extends Plugin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private eventBusPaste(event: any) {
|
||||||
|
// 如果需异步处理请调用 preventDefault, 否则会进行默认处理
|
||||||
|
event.preventDefault();
|
||||||
|
// 如果使用了 preventDefault,必须调用 resolve,否则程序会卡死
|
||||||
|
event.detail.resolve({
|
||||||
|
textPlain: event.detail.textPlain.trim(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private eventBusLog({ detail }: any) {
|
private eventBusLog({ detail }: any) {
|
||||||
console.log(detail);
|
console.log(detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
private blockIconEvent({ detail }: any) {
|
private blockIconEvent({ detail }: any) {
|
||||||
const ids: string[] = [];
|
|
||||||
detail.blockElements.forEach((item: HTMLElement) => {
|
|
||||||
ids.push(item.getAttribute("data-node-id"));
|
|
||||||
});
|
|
||||||
detail.menu.addItem({
|
detail.menu.addItem({
|
||||||
iconHTML: "",
|
iconHTML: "",
|
||||||
type: "readonly",
|
label: this.i18n.removeSpace,
|
||||||
label: "IDs<br>" + ids.join("<br>"),
|
click: () => {
|
||||||
|
const doOperations: IOperation[] = [];
|
||||||
|
detail.blockElements.forEach((item: HTMLElement) => {
|
||||||
|
const editElement = item.querySelector('[contenteditable="true"]');
|
||||||
|
if (editElement) {
|
||||||
|
editElement.textContent = editElement.textContent.replace(/ /g, "");
|
||||||
|
doOperations.push({
|
||||||
|
id: item.dataset.nodeId,
|
||||||
|
data: item.outerHTML,
|
||||||
|
action: "update"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
detail.protyle.getInstance().transaction(doOperations);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -488,9 +507,15 @@ export default class PluginSample extends Plugin {
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
icon: "iconSelect",
|
icon: "iconSelect",
|
||||||
label: "On loaded-protyle",
|
label: "On loaded-protyle-static",
|
||||||
click: () => {
|
click: () => {
|
||||||
this.eventBus.on("loaded-protyle", this.eventBusLog);
|
this.eventBus.on("loaded-protyle-static", this.eventBusLog);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconClose",
|
||||||
|
label: "Off loaded-protyle-static",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.off("loaded-protyle-static", this.eventBusLog);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
icon: "iconSelect",
|
icon: "iconSelect",
|
||||||
|
@ -517,10 +542,16 @@ export default class PluginSample extends Plugin {
|
||||||
this.eventBus.off("destroy-protyle", this.eventBusLog);
|
this.eventBus.off("destroy-protyle", this.eventBusLog);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
icon: "iconClose",
|
icon: "iconSelect",
|
||||||
label: "Off loaded-protyle",
|
label: "On open-menu-doctree",
|
||||||
click: () => {
|
click: () => {
|
||||||
this.eventBus.off("loaded-protyle", this.eventBusLog);
|
this.eventBus.on("open-menu-doctree", this.eventBusLog);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconClose",
|
||||||
|
label: "Off open-menu-doctree",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.off("open-menu-doctree", this.eventBusLog);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
icon: "iconSelect",
|
icon: "iconSelect",
|
||||||
|
@ -630,6 +661,18 @@ export default class PluginSample extends Plugin {
|
||||||
click: () => {
|
click: () => {
|
||||||
this.eventBus.off("input-search", this.eventBusLog);
|
this.eventBus.off("input-search", this.eventBusLog);
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconSelect",
|
||||||
|
label: "On paste",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.on("paste", this.eventBusPaste);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconClose",
|
||||||
|
label: "Off paste",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.off("paste", this.eventBusPaste);
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
icon: "iconSelect",
|
icon: "iconSelect",
|
||||||
label: "On open-siyuan-url-plugin",
|
label: "On open-siyuan-url-plugin",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue