reimplementation of frontend's api.addButtonToToolbar() to smoothen the upgrade

This commit is contained in:
zadam
2022-12-17 21:46:51 +01:00
parent 967919b400
commit 5af506e268
14 changed files with 382 additions and 161 deletions

View File

@@ -382,6 +382,8 @@ class NoteShort {
return a.isSearch ? 1 : -1;
} else if (a.isArchived !== b.isArchived) {
return a.isArchived ? 1 : -1;
} else if (a.isHidden !== b.isHidden) {
return a.isHidden ? 1 : -1;
} else {
return a.notePath.length - b.notePath.length;
}
@@ -391,6 +393,8 @@ class NoteShort {
}
__filterAttrs(attributes, type, name) {
this.__validateTypeName(type, name);
if (!type && !name) {
return attributes;
} else if (type && name) {
@@ -408,6 +412,19 @@ class NoteShort {
return attrs.filter(attr => attr.isInheritable);
}
__validateTypeName(type, name) {
if (type && type !== 'label' && type !== 'relation') {
throw new Error(`Unrecognized attribute type '${type}'. Only 'label' and 'relation' are possible values.`);
}
if (name) {
const firstLetter = name.charAt(0);
if (firstLetter === '#' || firstLetter === '~') {
throw new Error(`Detect '#' or '~' in the attribute's name. In the API, attribute names should be set without these characters.`);
}
}
}
/**
* @param {string} [name] - label name to filter
* @returns {Attribute[]} all note's labels (attributes with type label), including inherited ones
@@ -784,7 +801,7 @@ class NoteShort {
/** @returns {boolean} true if this note is JavaScript (code or attachment) */
isJavaScript() {
return (this.type === "code" || this.type === "file")
return (this.type === "code" || this.type === "file" || this.type === 'launcher')
&& (this.mime.startsWith("application/javascript")
|| this.mime === "application/x-javascript"
|| this.mime === "text/javascript");