import treeService from './tree.js'; import server from './server.js'; import utils from './utils.js'; import infoService from './info.js'; import linkService from './link.js'; import treeCache from './tree_cache.js'; /** * @constructor * @hideconstructor */ function FrontendScriptApi(startNote, currentNote, originEntity = null) { const $pluginButtons = $("#plugin-buttons"); /** @property {object} note where script started executing */ this.startNote = startNote; /** @property {object} note where script is currently executing */ this.currentNote = currentNote; /** @property {object|null} entity whose event triggered this execution */ this.originEntity = originEntity; /** * Activates note in the tree and in the note detail. * * @method * @param {string} notePath (or noteId) * @returns {Promise} */ this.activateNote = treeService.activateNote; /** * Activates newly created note. Compared to this.activateNote() also refreshes tree. * * @param {string} notePath (or noteId) * @return {Promise} */ this.activateNewNote = async notePath => { await treeService.reload(); await treeService.activateNote(notePath, true); }; /** * Adds new button the the plugin area. * * @param {object} options */ this.addButtonToToolbar = opts => { const buttonId = "toolbar-button-" + opts.title.replace(/[^a-zA-Z0-9]/g, "-"); $("#" + buttonId).remove(); const icon = $("") .addClass("ui-icon ui-icon-" + opts.icon); const button = $('