mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	Compare commits
	
		
			4 Commits
		
	
	
		
			v0.9.1-bet
			...
			v0.9.2
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 840af15dae | ||
|  | 0fdb6af98a | ||
|  | f6c7f6a0f2 | ||
|  | 354999f37a | 
| @@ -1,7 +1,7 @@ | ||||
| { | ||||
|   "name": "trilium", | ||||
|   "description": "Trilium Notes", | ||||
|   "version": "0.9.1-beta", | ||||
|   "version": "0.9.2", | ||||
|   "license": "AGPL-3.0-only", | ||||
|   "main": "electron.js", | ||||
|   "repository": { | ||||
|   | ||||
| @@ -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; | ||||
|             } | ||||
|         } | ||||
|     }; | ||||
| } | ||||
|  | ||||
|   | ||||
										
											Binary file not shown.
										
									
								
							| @@ -111,13 +111,15 @@ async function getScriptBundle(note, root = true, scriptEnv = null, includedNote | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     const moduleNoteIds = modules.map(mod => mod.noteId); | ||||
|  | ||||
|     if (note.isJavaScript()) { | ||||
|         bundle.script += ` | ||||
| apiContext.modules['${note.noteId}'] = {}; | ||||
| ${root ? 'return ' : ''}await (async function(exports, module, api` + (modules.length > 0 ? ', ' : '') + | ||||
| ${root ? 'return ' : ''}await (async function(exports, module, require, api` + (modules.length > 0 ? ', ' : '') + | ||||
|             modules.map(child => sanitizeVariableName(child.title)).join(', ') + `) { | ||||
| ${note.content} | ||||
| })({}, apiContext.modules['${note.noteId}'], apiContext.apis['${note.noteId}']` + (modules.length > 0 ? ', ' : '') + | ||||
| })({}, apiContext.modules['${note.noteId}'], apiContext.require(${JSON.stringify(moduleNoteIds)}), apiContext.apis['${note.noteId}']` + (modules.length > 0 ? ', ' : '') + | ||||
|             modules.map(mod => `apiContext.modules['${mod.noteId}'].exports`).join(', ') + `); | ||||
| `; | ||||
|     } | ||||
|   | ||||
| @@ -15,6 +15,18 @@ function ScriptContext(dataKey, startNote, allNotes) { | ||||
|     this.modules = {}; | ||||
|     this.notes = utils.toObject(allNotes, note => [note.noteId, note]); | ||||
|     this.apis = utils.toObject(allNotes, note => [note.noteId, new ScriptApi(dataKey, startNote, note)]); | ||||
|     this.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 this.modules[note.noteId].exports; | ||||
|         } | ||||
|     }; | ||||
| } | ||||
|  | ||||
| function ScriptApi(dataKey, startNote, currentNote) { | ||||
| @@ -26,7 +38,8 @@ function ScriptApi(dataKey, startNote, currentNote) { | ||||
|  | ||||
|     this.utils = { | ||||
|         unescapeHtml: utils.unescapeHtml, | ||||
|         isoDateTimeStr: utils.dateStr | ||||
|         isoDateTimeStr: utils.dateStr, | ||||
|         isoDateStr: date => utils.dateStr(date).substr(0, 10) | ||||
|     }; | ||||
|  | ||||
|     this.getInstanceName = () => config.General ? config.General.instanceName : null; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user