文本类型选择 JS Frontend 属性添加 #widget
内容
let TPL = `
<style>
.scratchpad-widget {
border: 1px solid var(--main-border-color);
min-height: 10em;
resize: vertical;
width: 100%;
font-family:var(--font-code);
}
</style>
<textarea class="scratchpad scratchpad-widget">
</textarea>
`
class ScratchpadWidget extends api.RightPanelWidget {
get contentLabelName () {
return "scratchpadContent"
}
get contentLabel () {
return this.note.getLabel(this.contentLabelName)
}
get hasContentLabel () {
return this.note.hasLabel(this.contentLabelName)
}
isEnabled() {
return super.isEnabled() && !this.note.hasLabel("scratchpadWidgetDisabled")
}
get widgetTitle() {
return "草稿板"
}
get parentWidget() {
return "right-pane"
}
async setContent(content = "") {
let result = await api.runOnBackend((noteId, value) => {
api.getNote(noteId).setLabel("scratchpadContent", value)
}, [this.note.noteId, content])
}
async doRenderBody() {
this.$body.html(TPL);
this.$scratchpad = this.$body.find(".scratchpad")
this.$scratchpad.on("input", event => {
// TODO debounce
this.setContent(this.$scratchpad.prop("value"))
})
}
async refreshWithNote(note) {
if (this.hasContentLabel) {
this.$scratchpad.text(this.contentLabel.value)
this.$scratchpad.prop("value", this.contentLabel.value)
} else {
this.$scratchpad.text("")
this.$scratchpad.prop("value", "")
}
}
entitiesReloadedEvent({loadResults}) {
if (loadResults.isNoteReloaded(this.noteId) || loadResults.isNoteContentReloaded(this.noteId)) {
this.refresh();
}
}
}
module.exports = new ScratchpadWidget()
