mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
render notes should now return elements to append instead of modifying DOM directly
This commit is contained in:
parent
f59f08fa0e
commit
aead6a44de
@ -8,8 +8,8 @@ async function getAndExecuteBundle(noteId, originEntity = null) {
|
||||
await executeBundle(bundle, originEntity);
|
||||
}
|
||||
|
||||
async function executeBundle(bundle, originEntity) {
|
||||
const apiContext = await ScriptContext(bundle.noteId, bundle.allNoteIds, originEntity);
|
||||
async function executeBundle(bundle, originEntity, tabContext) {
|
||||
const apiContext = await ScriptContext(bundle.noteId, bundle.allNoteIds, originEntity, tabContext);
|
||||
|
||||
try {
|
||||
return await (function () {
|
||||
|
@ -16,7 +16,7 @@ import dateNotesService from'./date_notes.js';
|
||||
* @constructor
|
||||
* @hideconstructor
|
||||
*/
|
||||
function FrontendScriptApi(startNote, currentNote, originEntity = null) {
|
||||
function FrontendScriptApi(startNote, currentNote, originEntity = null, tabContext = null) {
|
||||
const $pluginButtons = $("#plugin-buttons");
|
||||
|
||||
/** @property {object} note where script started executing */
|
||||
@ -29,6 +29,9 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
|
||||
// to keep consistency with backend API
|
||||
this.dayjs = dayjs;
|
||||
|
||||
/** @property {TabContext|null} - experimental! */
|
||||
this.tabContext = tabContext;
|
||||
|
||||
/**
|
||||
* Activates note in the tree and in the note detail.
|
||||
*
|
||||
|
@ -1,7 +1,5 @@
|
||||
import bundleService from "./bundle.js";
|
||||
import server from "./server.js";
|
||||
import noteDetailService from "./note_detail.js";
|
||||
import attributeService from "./attributes.js";
|
||||
|
||||
class NoteDetailRender {
|
||||
/**
|
||||
@ -14,7 +12,7 @@ class NoteDetailRender {
|
||||
this.$noteDetailRenderContent = ctx.$tabContent.find('.note-detail-render-content');
|
||||
this.$renderButton = ctx.$tabContent.find('.render-button');
|
||||
|
||||
this.$renderButton.click(this.render);
|
||||
this.$renderButton.click(() => this.render()); // long form!
|
||||
}
|
||||
|
||||
async render() {
|
||||
@ -35,7 +33,11 @@ class NoteDetailRender {
|
||||
|
||||
this.$noteDetailRenderContent.append(bundle.html);
|
||||
|
||||
await bundleService.executeBundle(bundle, noteDetailService.getActiveNote());
|
||||
const $result = await bundleService.executeBundle(bundle, this.ctx.note, this.ctx);
|
||||
|
||||
if ($result) {
|
||||
this.$noteDetailRenderContent.append($result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ 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) {
|
||||
async function ScriptContext(startNoteId, allNoteIds, originEntity = null, tabContext = null) {
|
||||
const modules = {};
|
||||
|
||||
const startNote = await treeCache.getNote(startNoteId);
|
||||
@ -11,7 +11,7 @@ async function ScriptContext(startNoteId, allNoteIds, originEntity = null) {
|
||||
return {
|
||||
modules: modules,
|
||||
notes: utils.toObject(allNotes, note => [note.noteId, note]),
|
||||
apis: utils.toObject(allNotes, note => [note.noteId, new FrontendScriptApi(startNote, note, originEntity)]),
|
||||
apis: utils.toObject(allNotes, note => [note.noteId, new FrontendScriptApi(startNote, note, originEntity, tabContext)]),
|
||||
require: moduleNoteIds => {
|
||||
return moduleName => {
|
||||
const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));
|
||||
|
@ -18,7 +18,6 @@ import noteDetailRelationMap from "./note_detail_relation_map.js";
|
||||
import noteDetailProtectedSession from "./note_detail_protected_session.js";
|
||||
import protectedSessionService from "./protected_session.js";
|
||||
import linkService from "./link.js";
|
||||
import treeCache from "./tree_cache.js";
|
||||
|
||||
const $tabContentsContainer = $("#note-tab-container");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user