mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
ScriptApi separated from ScriptContext, preparation for modularisation
This commit is contained in:
parent
c8e456cdb1
commit
001a5107dd
@ -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) {
|
function ScriptApi(startNote, currentNote) {
|
||||||
const $pluginButtons = $("#plugin-buttons");
|
const $pluginButtons = $("#plugin-buttons");
|
||||||
|
|
21
src/public/javascripts/script_context.js
Normal file
21
src/public/javascripts/script_context.js
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -555,7 +555,8 @@
|
|||||||
<script src="/javascripts/link.js"></script>
|
<script src="/javascripts/link.js"></script>
|
||||||
<script src="/javascripts/sync.js"></script>
|
<script src="/javascripts/sync.js"></script>
|
||||||
<script src="/javascripts/messaging.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">
|
<script type="text/javascript">
|
||||||
// we hide container initally because otherwise it is rendered first without CSS and then flickers into
|
// we hide container initally because otherwise it is rendered first without CSS and then flickers into
|
||||||
|
Loading…
x
Reference in New Issue
Block a user