mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
added require() method for commonJS compliancy
This commit is contained in:
@@ -1,8 +1,22 @@
|
||||
function ScriptContext(startNote, allNotes) {
|
||||
const modules = {};
|
||||
|
||||
return {
|
||||
modules: {},
|
||||
modules: modules,
|
||||
notes: toObject(allNotes, note => [note.noteId, note]),
|
||||
apis: 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;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user