mirror of
https://github.com/zadam/trilium.git
synced 2024-11-18 05:35:56 +08:00
30 lines
No EOL
1.1 KiB
JavaScript
30 lines
No EOL
1.1 KiB
JavaScript
import FrontendScriptApi from './frontend_script_api.js';
|
|
import utils from './utils.js';
|
|
import treeCache from './tree_cache.js';
|
|
|
|
async function ScriptContext(startNoteId, allNoteIds, originEntity = null, tabContext = null, $container = null) {
|
|
const modules = {};
|
|
|
|
const startNote = await treeCache.getNote(startNoteId);
|
|
const allNotes = await treeCache.getNotes(allNoteIds);
|
|
|
|
return {
|
|
modules: modules,
|
|
notes: utils.toObject(allNotes, note => [note.noteId, note]),
|
|
apis: utils.toObject(allNotes, note => [note.noteId, new FrontendScriptApi(startNote, note, originEntity, tabContext, $container)]),
|
|
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;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
export default ScriptContext; |