Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
expose note hoisting to frontend API, closes #663
zadam132360b46bfd
diff --git a/docs/backend_api/entities_branch.js.html b/docs/backend_api/entities_branch.js.htmlindex e76ded267b..7a4d69a8fe 100644--- a/docs/backend_api/entities_branch.js.html+++ b/docs/backend_api/entities_branch.js.html@@ -70,7 +70,7 @@ class Branch extends Entity {async beforeSaving() {if (this.notePosition === undefined) {const maxNotePos = await sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [this.parentNoteId]);- this.notePosition = maxNotePos === null ? 0 : maxNotePos + 1;+ this.notePosition = maxNotePos === null ? 0 : maxNotePos + 10;}if (!this.isDeleted) {diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.htmlindex f654b2fb87..6f60a7867e 100644--- a/docs/frontend_api/FrontendScriptApi.html+++ b/docs/frontend_api/FrontendScriptApi.html@@ -81,7 +81,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line19">line 19</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line21">line 21</a></li></ul></dd>@@ -223,7 +223,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line23">line 23</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line25">line 25</a></li></ul></dd>@@ -333,7 +333,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line28">line 28</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line30">line 30</a></li></ul></dd>@@ -446,7 +446,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line30">line 30</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line32">line 32</a></li></ul></dd>@@ -552,7 +552,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line39">line 39</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line41">line 41</a></li></ul></dd>@@ -662,7 +662,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line26">line 26</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line28">line 28</a></li></ul></dd>@@ -771,7 +771,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line36">line 36</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line38">line 38</a></li></ul></dd>@@ -900,7 +900,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line64">line 64</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line66">line 66</a></li></ul></dd>@@ -1055,7 +1055,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line48">line 48</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line50">line 50</a></li></ul></dd>@@ -1210,7 +1210,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line83">line 83</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line85">line 85</a></li></ul></dd>@@ -1390,7 +1390,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line272">line 272</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line279">line 279</a></li></ul></dd>@@ -1523,7 +1523,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line232">line 232</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line239">line 239</a></li></ul></dd>@@ -1629,7 +1629,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line278">line 278</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line285">line 285</a></li></ul></dd>@@ -1735,7 +1735,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line284">line 284</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line291">line 291</a></li></ul></dd>@@ -1894,7 +1894,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line335">line 335</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line338">line 338</a></li></ul></dd>@@ -2001,7 +2001,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line225">line 225</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line232">line 232</a></li></ul></dd>@@ -2156,7 +2156,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line344">line 344</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line347">line 347</a></li></ul></dd>@@ -2312,7 +2312,7 @@ if some action needs to happen on only one specific instance.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line193">line 193</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line200">line 200</a></li></ul></dd>@@ -2513,7 +2513,7 @@ otherwise (by e.g. createNoteLink())<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line205">line 205</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line212">line 212</a></li></ul></dd>@@ -2619,7 +2619,7 @@ otherwise (by e.g. createNoteLink())<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line326">line 326</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line329">line 329</a></li></ul></dd>@@ -2774,7 +2774,7 @@ otherwise (by e.g. createNoteLink())<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line353">line 353</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line356">line 356</a></li></ul></dd>@@ -2883,7 +2883,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line299">line 299</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line302">line 302</a></li></ul></dd>@@ -3038,7 +3038,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line307">line 307</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line310">line 310</a></li></ul></dd>@@ -3171,7 +3171,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line239">line 239</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line246">line 246</a></li></ul></dd>@@ -3277,7 +3277,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line318">line 318</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line321">line 321</a></li></ul></dd>@@ -3365,7 +3365,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line263">line 263</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line270">line 270</a></li></ul></dd>@@ -3419,7 +3419,7 @@ note.- <h4 class="name" id="reloadChildren"><span class="type-signature"></span>reloadChildren<span class="signature">(noteId)</span><span class="type-signature"></span></h4>+ <h4 class="name" id="reloadNotesAndTheirChildren"><span class="type-signature"></span>reloadNotesAndTheirChildren<span class="signature">(noteId)</span><span class="type-signature"></span></h4>@@ -3516,7 +3516,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line211">line 211</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line218">line 218</a></li></ul></dd>@@ -3649,7 +3649,7 @@ note.<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line217">line 217</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line224">line 224</a></li></ul></dd>@@ -3810,7 +3810,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line133">line 133</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line135">line 135</a></li></ul></dd>@@ -3970,7 +3970,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line181">line 181</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line188">line 188</a></li></ul></dd>@@ -4126,7 +4126,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line163">line 163</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line170">line 170</a></li></ul></dd>@@ -4180,6 +4180,161 @@ Internally this serializes the anonymous function into string and sends it to ba+ <h4 class="name" id="setHoistedNoteId"><span class="type-signature"></span>setHoistedNoteId<span class="signature">(noteId)</span><span class="type-signature"> → {Promise}</span></h4>+++++++<div class="description">+ Hoist note. See https://github.com/zadam/trilium/wiki/Note-hoisting+</div>++++++++++ <h5>Parameters:</h5>+++<table class="params">+ <thead>+ <tr>++ <th>Name</th>+++ <th>Type</th>++++++ <th class="last">Description</th>+ </tr>+ </thead>++ <tbody>+++ <tr>++ <td class="name"><code>noteId</code></td>+++ <td class="type">+++<span class="param-type">string</span>++++ </td>++++++ <td class="description last">set hoisted note. 'root' will effectively unhoist</td>+ </tr>+++ </tbody>+</table>+++++++<dl class="details">+++++++++++++++++++++++++++ <dt class="tag-source">Source:</dt>+ <dd class="tag-source"><ul class="dummy"><li>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line365">line 365</a>+ </li></ul></dd>++++++++</dl>++++++++++++++++<h5>Returns:</h5>+++++<dl>+ <dt>+ Type+ </dt>+ <dd>++<span class="param-type">Promise</span>+++ </dd>+</dl>+++++++++++++<h4 class="name" id="setupElementTooltip"><span class="type-signature"></span>setupElementTooltip<span class="signature">($el)</span><span class="type-signature"></span></h4>@@ -4277,7 +4432,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line313">line 313</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line316">line 316</a></li></ul></dd>@@ -4414,7 +4569,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line255">line 255</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line262">line 262</a></li></ul></dd>@@ -4551,7 +4706,7 @@ Internally this serializes the anonymous function into string and sends it to ba<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line247">line 247</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line254">line 254</a></li></ul></dd>diff --git a/docs/frontend_api/global.html b/docs/frontend_api/global.htmlindex 6e4c07a95f..22f49fed05 100644--- a/docs/frontend_api/global.html+++ b/docs/frontend_api/global.html@@ -303,7 +303,7 @@<dt class="tag-source">Source:</dt><dd class="tag-source"><ul class="dummy"><li>- <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line70">line 70</a>+ <a href="services_frontend_script_api.js.html">services/frontend_script_api.js</a>, <a href="services_frontend_script_api.js.html#line72">line 72</a></li></ul></dd>diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.htmlindex 4d684ad796..9d0d2c6004 100644--- a/docs/frontend_api/services_frontend_script_api.js.html+++ b/docs/frontend_api/services_frontend_script_api.js.html@@ -37,6 +37,8 @@ import noteTooltipService from './note_tooltip.js';import protectedSessionService from './protected_session.js';import dateNotesService from './date_notes.js';import StandardWidget from '../widgets/standard_widget.js';+import ws from "./ws.js";+import hoistedNoteService from "./hoisted_note.js";/*** This is the main frontend API interface for scripts. It's published in the local "api" object.@@ -170,9 +172,14 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabContecurrentNoteId: currentNote.noteId,originEntityName: "notes", // currently there's no other entity on frontend which can trigger eventoriginEntityId: originEntity ? originEntity.noteId : null+ }, {+ 'trilium-source-id': "script"});if (ret.success) {+ // wait until all the changes done in the script has been synced to frontend before continuing+ await ws.waitForSyncId(ret.maxSyncId);+return ret.executionResult;}else {@@ -236,7 +243,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte* @param {string} noteId* @method*/- this.reloadChildren = async noteId => await treeCache.reloadNotesAndTheirChildren(noteId);+ this.reloadNotesAndTheirChildren = async noteId => await treeCache.reloadNotesAndTheirChildren(noteId);/*** @param {string} noteId@@ -309,11 +316,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte* @method* @returns {Promise<string|null>} returns note path of active note or null if there isn't active note*/- this.getActiveTabNotePath = () => {- const activeTabContext = noteDetailService.getActiveTabContext();-- return activeTabContext ? activeTabContext.notePath : null;- };+ this.getActiveTabNotePath = noteDetailService.getActiveTabNotePath;/*** This method checks whether user navigated away from the note from which the scripts has been started.@@ -379,6 +382,15 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte* @return {Promise<NoteShort>}*/this.getYearNote = dateNotesService.getYearNote;++ /**+ * Hoist note. See https://github.com/zadam/trilium/wiki/Note-hoisting+ *+ * @method+ * @param {string} noteId - set hoisted note. 'root' will effectively unhoist+ * @return {Promise}+ */+ this.setHoistedNoteId = hoistedNoteService.setHoistedNoteId;}export default FrontendScriptApi;</code></pre>diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.jsindex 74de2c6cdd..edb3dc1999 100644--- a/src/public/javascripts/services/frontend_script_api.js+++ b/src/public/javascripts/services/frontend_script_api.js@@ -10,6 +10,7 @@ import protectedSessionService from './protected_session.js';import dateNotesService from './date_notes.js';import StandardWidget from '../widgets/standard_widget.js';import ws from "./ws.js";+import hoistedNoteService from "./hoisted_note.js";/*** This is the main frontend API interface for scripts. It's published in the local "api" object.@@ -353,6 +354,15 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte* @return {Promise<NoteShort>}*/this.getYearNote = dateNotesService.getYearNote;++ /**+ * Hoist note. See https://github.com/zadam/trilium/wiki/Note-hoisting+ *+ * @method+ * @param {string} noteId - set hoisted note. 'root' will effectively unhoist+ * @return {Promise}+ */+ this.setHoistedNoteId = hoistedNoteService.setHoistedNoteId;}export default FrontendScriptApi;\ No newline at end of filediff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.jsindex c4e4d0da56..3c444d1d92 100644--- a/src/public/javascripts/services/tab_context.js+++ b/src/public/javascripts/services/tab_context.js@@ -411,11 +411,13 @@ class TabContext {}async remove() {- // sometimes there are orphan autocompletes after closing the tab- this.cleanup();+ if (this.$tabContent) {+ // sometimes there are orphan autocompletes after closing the tab+ this.cleanup();- await this.saveNoteIfChanged();- this.$tabContent.remove();+ await this.saveNoteIfChanged();+ this.$tabContent.remove();+ }}cleanup() {