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
ScriptApi separated from ScriptContext, preparation for modularisation
azivner001a5107dde7
diff --git a/src/public/javascripts/api.js b/src/public/javascripts/script_api.jssimilarity index 64%rename from src/public/javascripts/api.jsrename to src/public/javascripts/script_api.jsindex 247586f9fe..8038e795c9 100644--- a/src/public/javascripts/api.js+++ b/src/public/javascripts/script_api.js@@ -1,25 +1,3 @@-function ScriptContext(startNote, allNotes) {- const modules = {};-- return {- modules: modules,- notes: utils.toObject(allNotes, note => [note.noteId, note]),- apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note)]),- require: moduleNoteIds => {- return moduleName => {- const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));- const note = candidates.find(c => c.title === moduleName);-- if (!note) {- throw new Error("Could not find module note " + moduleName);- }-- return modules[note.noteId].exports;- }- }- };-}-function ScriptApi(startNote, currentNote) {const $pluginButtons = $("#plugin-buttons");diff --git a/src/public/javascripts/script_context.js b/src/public/javascripts/script_context.jsnew file mode 100644index 0000000000..bf8ee68efa--- /dev/null+++ b/src/public/javascripts/script_context.js@@ -0,0 +1,21 @@+function ScriptContext(startNote, allNotes) {+ const modules = {};++ return {+ modules: modules,+ notes: utils.toObject(allNotes, note => [note.noteId, note]),+ apis: utils.toObject(allNotes, note => [note.noteId, ScriptApi(startNote, note)]),+ require: moduleNoteIds => {+ return moduleName => {+ const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));+ const note = candidates.find(c => c.title === moduleName);++ if (!note) {+ throw new Error("Could not find module note " + moduleName);+ }++ return modules[note.noteId].exports;+ }+ }+ };+}\ No newline at end of filediff --git a/src/views/index.ejs b/src/views/index.ejsindex cedc2ed118..f07375e320 100644--- a/src/views/index.ejs+++ b/src/views/index.ejs@@ -555,7 +555,8 @@<script src="/javascripts/link.js"></script><script src="/javascripts/sync.js"></script><script src="/javascripts/messaging.js"></script>- <script src="/javascripts/api.js"></script>+ <script src="/javascripts/script_context.js"></script>+ <script src="/javascripts/script_api.js"></script><script type="text/javascript">// we hide container initally because otherwise it is rendered first without CSS and then flickers into