render notes should now return elements to append instead of modifying DOM directly

This commit is contained in:
zadam 2019-05-19 21:52:28 +02:00
parent f59f08fa0e
commit aead6a44de
5 changed files with 14 additions and 10 deletions

View File

@ -8,8 +8,8 @@ async function getAndExecuteBundle(noteId, originEntity = null) {
await executeBundle(bundle, originEntity); await executeBundle(bundle, originEntity);
} }
async function executeBundle(bundle, originEntity) { async function executeBundle(bundle, originEntity, tabContext) {
const apiContext = await ScriptContext(bundle.noteId, bundle.allNoteIds, originEntity); const apiContext = await ScriptContext(bundle.noteId, bundle.allNoteIds, originEntity, tabContext);
try { try {
return await (function () { return await (function () {

View File

@ -16,7 +16,7 @@ import dateNotesService from'./date_notes.js';
* @constructor * @constructor
* @hideconstructor * @hideconstructor
*/ */
function FrontendScriptApi(startNote, currentNote, originEntity = null) { function FrontendScriptApi(startNote, currentNote, originEntity = null, tabContext = null) {
const $pluginButtons = $("#plugin-buttons"); const $pluginButtons = $("#plugin-buttons");
/** @property {object} note where script started executing */ /** @property {object} note where script started executing */
@ -29,6 +29,9 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {
// to keep consistency with backend API // to keep consistency with backend API
this.dayjs = dayjs; this.dayjs = dayjs;
/** @property {TabContext|null} - experimental! */
this.tabContext = tabContext;
/** /**
* Activates note in the tree and in the note detail. * Activates note in the tree and in the note detail.
* *

View File

@ -1,7 +1,5 @@
import bundleService from "./bundle.js"; import bundleService from "./bundle.js";
import server from "./server.js"; import server from "./server.js";
import noteDetailService from "./note_detail.js";
import attributeService from "./attributes.js";
class NoteDetailRender { class NoteDetailRender {
/** /**
@ -14,7 +12,7 @@ class NoteDetailRender {
this.$noteDetailRenderContent = ctx.$tabContent.find('.note-detail-render-content'); this.$noteDetailRenderContent = ctx.$tabContent.find('.note-detail-render-content');
this.$renderButton = ctx.$tabContent.find('.render-button'); this.$renderButton = ctx.$tabContent.find('.render-button');
this.$renderButton.click(this.render); this.$renderButton.click(() => this.render()); // long form!
} }
async render() { async render() {
@ -35,7 +33,11 @@ class NoteDetailRender {
this.$noteDetailRenderContent.append(bundle.html); 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);
}
} }
} }

View File

@ -2,7 +2,7 @@ import FrontendScriptApi from './frontend_script_api.js';
import utils from './utils.js'; import utils from './utils.js';
import treeCache from './tree_cache.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 modules = {};
const startNote = await treeCache.getNote(startNoteId); const startNote = await treeCache.getNote(startNoteId);
@ -11,7 +11,7 @@ async function ScriptContext(startNoteId, allNoteIds, originEntity = null) {
return { return {
modules: modules, modules: modules,
notes: utils.toObject(allNotes, note => [note.noteId, note]), 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 => { require: moduleNoteIds => {
return moduleName => { return moduleName => {
const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId)); const candidates = allNotes.filter(note => moduleNoteIds.includes(note.noteId));

View File

@ -18,7 +18,6 @@ import noteDetailRelationMap from "./note_detail_relation_map.js";
import noteDetailProtectedSession from "./note_detail_protected_session.js"; import noteDetailProtectedSession from "./note_detail_protected_session.js";
import protectedSessionService from "./protected_session.js"; import protectedSessionService from "./protected_session.js";
import linkService from "./link.js"; import linkService from "./link.js";
import treeCache from "./tree_cache.js";
const $tabContentsContainer = $("#note-tab-container"); const $tabContentsContainer = $("#note-tab-container");