mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
split out library loader
This commit is contained in:
parent
9bb188b519
commit
b10b0048f3
@ -1,4 +1,3 @@
|
|||||||
import treeService from '../services/tree.js';
|
|
||||||
import cloningService from '../services/cloning.js';
|
import cloningService from '../services/cloning.js';
|
||||||
import linkService from '../services/link.js';
|
import linkService from '../services/link.js';
|
||||||
import noteDetailService from '../services/note_detail.js';
|
import noteDetailService from '../services/note_detail.js';
|
||||||
|
@ -30,14 +30,18 @@ async function showDialog() {
|
|||||||
$noteTitle.html(noteTitle);
|
$noteTitle.html(noteTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
$form.submit(() => {
|
async function savePrefix() {
|
||||||
const prefix = $treePrefixInput.val();
|
const prefix = $treePrefixInput.val();
|
||||||
|
|
||||||
server.put('tree/' + branchId + '/set-prefix', {
|
await server.put('tree/' + branchId + '/set-prefix', { prefix: prefix });
|
||||||
prefix: prefix
|
|
||||||
}).then(() => treeService.setPrefix(branchId, prefix));
|
await treeService.setPrefix(branchId, prefix);
|
||||||
|
|
||||||
$dialog.dialog("close");
|
$dialog.dialog("close");
|
||||||
|
}
|
||||||
|
|
||||||
|
$form.submit(() => {
|
||||||
|
savePrefix();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
@ -29,7 +29,7 @@ function formatNode(node, level) {
|
|||||||
const indentAfter = new Array(level - 1).join(' ');
|
const indentAfter = new Array(level - 1).join(' ');
|
||||||
let textNode;
|
let textNode;
|
||||||
|
|
||||||
for (let i = 0; i < node.children.length; i++) {
|
for (const i = 0; i < node.children.length; i++) {
|
||||||
textNode = document.createTextNode('\n' + indentBefore);
|
textNode = document.createTextNode('\n' + indentBefore);
|
||||||
node.insertBefore(textNode, node.children[i]);
|
node.insertBefore(textNode, node.children[i]);
|
||||||
|
|
||||||
|
@ -27,6 +27,21 @@ function addRecentNote(branchId, notePath) {
|
|||||||
}, 1500);
|
}, 1500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getNoteTitle(notePath) {
|
||||||
|
let noteTitle;
|
||||||
|
|
||||||
|
try {
|
||||||
|
noteTitle = await treeUtils.getNotePathTitle(notePath);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
noteTitle = "[error - can't find note title]";
|
||||||
|
|
||||||
|
messagingService.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
return noteTitle;
|
||||||
|
}
|
||||||
|
|
||||||
async function showDialog() {
|
async function showDialog() {
|
||||||
glob.activeDialog = $dialog;
|
glob.activeDialog = $dialog;
|
||||||
|
|
||||||
@ -44,19 +59,8 @@ async function showDialog() {
|
|||||||
const items = [];
|
const items = [];
|
||||||
|
|
||||||
for (const notePath of recNotes) {
|
for (const notePath of recNotes) {
|
||||||
let noteTitle;
|
|
||||||
|
|
||||||
try {
|
|
||||||
noteTitle = await treeUtils.getNotePathTitle(notePath);
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
noteTitle = "[error - can't find note title]";
|
|
||||||
|
|
||||||
messagingService.logError("Could not find title for notePath=" + notePath + ", stack=" + e.stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
items.push({
|
items.push({
|
||||||
label: noteTitle,
|
label: await getNoteTitle(notePath),
|
||||||
value: notePath
|
value: notePath
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ import infoService from "../services/info.js";
|
|||||||
const $dialog = $("#settings-dialog");
|
const $dialog = $("#settings-dialog");
|
||||||
const $tabs = $("#settings-tabs");
|
const $tabs = $("#settings-tabs");
|
||||||
|
|
||||||
const settingModules = [];
|
const tabHandlers = [];
|
||||||
|
|
||||||
function addModule(module) {
|
function addTabHandler(handler) {
|
||||||
settingModules.push(module);
|
tabHandlers.push(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function showDialog() {
|
async function showDialog() {
|
||||||
@ -26,9 +26,9 @@ async function showDialog() {
|
|||||||
|
|
||||||
$tabs.tabs();
|
$tabs.tabs();
|
||||||
|
|
||||||
for (const module of settingModules) {
|
for (const handler of tabHandlers) {
|
||||||
if (module.settingsLoaded) {
|
if (handler.settingsLoaded) {
|
||||||
module.settingsLoaded(settings);
|
handler.settingsLoaded(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ export default {
|
|||||||
saveSettings
|
saveSettings
|
||||||
};
|
};
|
||||||
|
|
||||||
addModule((function() {
|
addTabHandler((function() {
|
||||||
const $form = $("#change-password-form");
|
const $form = $("#change-password-form");
|
||||||
const $oldPassword = $("#old-password");
|
const $oldPassword = $("#old-password");
|
||||||
const $newPassword1 = $("#new-password1");
|
const $newPassword1 = $("#new-password1");
|
||||||
@ -93,7 +93,7 @@ addModule((function() {
|
|||||||
};
|
};
|
||||||
})());
|
})());
|
||||||
|
|
||||||
addModule((function() {
|
addTabHandler((function() {
|
||||||
const $form = $("#protected-session-timeout-form");
|
const $form = $("#protected-session-timeout-form");
|
||||||
const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds");
|
const $protectedSessionTimeout = $("#protected-session-timeout-in-seconds");
|
||||||
const settingName = 'protected_session_timeout';
|
const settingName = 'protected_session_timeout';
|
||||||
@ -117,7 +117,7 @@ addModule((function() {
|
|||||||
};
|
};
|
||||||
})());
|
})());
|
||||||
|
|
||||||
addModule((function () {
|
addTabHandler((function () {
|
||||||
const $form = $("#note-revision-snapshot-time-interval-form");
|
const $form = $("#note-revision-snapshot-time-interval-form");
|
||||||
const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds");
|
const $timeInterval = $("#note-revision-snapshot-time-interval-in-seconds");
|
||||||
const settingName = 'note_revision_snapshot_time_interval';
|
const settingName = 'note_revision_snapshot_time_interval';
|
||||||
@ -137,7 +137,7 @@ addModule((function () {
|
|||||||
};
|
};
|
||||||
})());
|
})());
|
||||||
|
|
||||||
addModule((async function () {
|
addTabHandler((async function () {
|
||||||
const $appVersion = $("#app-version");
|
const $appVersion = $("#app-version");
|
||||||
const $dbVersion = $("#db-version");
|
const $dbVersion = $("#db-version");
|
||||||
const $buildDate = $("#build-date");
|
const $buildDate = $("#build-date");
|
||||||
@ -154,7 +154,7 @@ addModule((async function () {
|
|||||||
return {};
|
return {};
|
||||||
})());
|
})());
|
||||||
|
|
||||||
addModule((async function () {
|
addTabHandler((async function () {
|
||||||
const $forceFullSyncButton = $("#force-full-sync-button");
|
const $forceFullSyncButton = $("#force-full-sync-button");
|
||||||
const $fillSyncRowsButton = $("#fill-sync-rows-button");
|
const $fillSyncRowsButton = $("#fill-sync-rows-button");
|
||||||
const $anonymizeButton = $("#anonymize-button");
|
const $anonymizeButton = $("#anonymize-button");
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import utils from '../services/utils.js';
|
import utils from '../services/utils.js';
|
||||||
|
import libraryLoader from '../services/library_loader.js';
|
||||||
import server from '../services/server.js';
|
import server from '../services/server.js';
|
||||||
import infoService from "../services/info.js";
|
import infoService from "../services/info.js";
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ function showDialog() {
|
|||||||
|
|
||||||
async function initEditor() {
|
async function initEditor() {
|
||||||
if (!codeEditor) {
|
if (!codeEditor) {
|
||||||
await utils.requireLibrary(utils.CODE_MIRROR);
|
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
||||||
|
|
||||||
CodeMirror.keyMap.default["Shift-Tab"] = "indentLess";
|
CodeMirror.keyMap.default["Shift-Tab"] = "indentLess";
|
||||||
CodeMirror.keyMap.default["Tab"] = "indentMore";
|
CodeMirror.keyMap.default["Tab"] = "indentMore";
|
||||||
|
5
src/public/javascripts/services/bootstrap.js
vendored
5
src/public/javascripts/services/bootstrap.js
vendored
@ -30,6 +30,7 @@ import entrypoints from './entrypoints.js';
|
|||||||
import tooltip from './tooltip.js';
|
import tooltip from './tooltip.js';
|
||||||
import bundle from "./bundle.js";
|
import bundle from "./bundle.js";
|
||||||
import treeCache from "./tree_cache.js";
|
import treeCache from "./tree_cache.js";
|
||||||
|
import libraryLoader from "./library_loader.js";
|
||||||
|
|
||||||
// required for CKEditor image upload plugin
|
// required for CKEditor image upload plugin
|
||||||
window.glob.getCurrentNode = treeService.getCurrentNode;
|
window.glob.getCurrentNode = treeService.getCurrentNode;
|
||||||
@ -37,8 +38,8 @@ window.glob.getHeaders = server.getHeaders;
|
|||||||
|
|
||||||
// required for ESLint plugin
|
// required for ESLint plugin
|
||||||
window.glob.getCurrentNote = noteDetailService.getCurrentNote;
|
window.glob.getCurrentNote = noteDetailService.getCurrentNote;
|
||||||
window.glob.requireLibrary = utils.requireLibrary;
|
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
||||||
window.glob.ESLINT = utils.ESLINT;
|
window.glob.ESLINT = libraryLoader.ESLINT;
|
||||||
|
|
||||||
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
||||||
const string = msg.toLowerCase();
|
const string = msg.toLowerCase();
|
||||||
|
64
src/public/javascripts/services/library_loader.js
Normal file
64
src/public/javascripts/services/library_loader.js
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
const CKEDITOR = {"js": ["libraries/ckeditor/ckeditor.js"]};
|
||||||
|
|
||||||
|
const CODE_MIRROR = {
|
||||||
|
js: [
|
||||||
|
"libraries/codemirror/codemirror.js",
|
||||||
|
"libraries/codemirror/addon/mode/loadmode.js",
|
||||||
|
"libraries/codemirror/addon/fold/xml-fold.js",
|
||||||
|
"libraries/codemirror/addon/edit/matchbrackets.js",
|
||||||
|
"libraries/codemirror/addon/edit/matchtags.js",
|
||||||
|
"libraries/codemirror/addon/search/match-highlighter.js",
|
||||||
|
"libraries/codemirror/mode/meta.js",
|
||||||
|
"libraries/codemirror/addon/lint/lint.js",
|
||||||
|
"libraries/codemirror/addon/lint/eslint.js"
|
||||||
|
],
|
||||||
|
css: [
|
||||||
|
"libraries/codemirror/codemirror.css",
|
||||||
|
"libraries/codemirror/addon/lint/lint.css"
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const ESLINT = {js: ["libraries/eslint.js"]};
|
||||||
|
|
||||||
|
async function requireLibrary(library) {
|
||||||
|
if (library.css) {
|
||||||
|
library.css.map(cssUrl => requireCss(cssUrl));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (library.js) {
|
||||||
|
for (const scriptUrl of library.js) {
|
||||||
|
await requireScript(scriptUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const dynamicallyLoadedScripts = [];
|
||||||
|
|
||||||
|
async function requireScript(url) {
|
||||||
|
if (!dynamicallyLoadedScripts.includes(url)) {
|
||||||
|
dynamicallyLoadedScripts.push(url);
|
||||||
|
|
||||||
|
return await $.ajax({
|
||||||
|
url: url,
|
||||||
|
dataType: "script",
|
||||||
|
cache: true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function requireCss(url) {
|
||||||
|
const css = Array
|
||||||
|
.from(document.querySelectorAll('link'))
|
||||||
|
.map(scr => scr.href);
|
||||||
|
|
||||||
|
if (!css.includes(url)) {
|
||||||
|
$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
requireLibrary,
|
||||||
|
CKEDITOR,
|
||||||
|
CODE_MIRROR,
|
||||||
|
ESLINT
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import utils from "./utils.js";
|
import utils from "./utils.js";
|
||||||
|
import libraryLoader from "./library_loader.js";
|
||||||
import bundleService from "./bundle.js";
|
import bundleService from "./bundle.js";
|
||||||
import infoService from "./info.js";
|
import infoService from "./info.js";
|
||||||
import server from "./server.js";
|
import server from "./server.js";
|
||||||
@ -11,7 +12,7 @@ const $executeScriptButton = $("#execute-script-button");
|
|||||||
|
|
||||||
async function show() {
|
async function show() {
|
||||||
if (!codeEditor) {
|
if (!codeEditor) {
|
||||||
await utils.requireLibrary(utils.CODE_MIRROR);
|
await libraryLoader.requireLibrary(libraryLoader.CODE_MIRROR);
|
||||||
|
|
||||||
CodeMirror.keyMap.default["Shift-Tab"] = "indentLess";
|
CodeMirror.keyMap.default["Shift-Tab"] = "indentLess";
|
||||||
CodeMirror.keyMap.default["Tab"] = "indentMore";
|
CodeMirror.keyMap.default["Tab"] = "indentMore";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import utils from "./utils.js";
|
import libraryLoader from "./library_loader.js";
|
||||||
import noteDetailService from './note_detail.js';
|
import noteDetailService from './note_detail.js';
|
||||||
|
|
||||||
const $noteDetailText = $('#note-detail-text');
|
const $noteDetailText = $('#note-detail-text');
|
||||||
@ -7,7 +7,7 @@ let textEditor = null;
|
|||||||
|
|
||||||
async function show() {
|
async function show() {
|
||||||
if (!textEditor) {
|
if (!textEditor) {
|
||||||
await utils.requireLibrary(utils.CKEDITOR);
|
await libraryLoader.requireLibrary(libraryLoader.CKEDITOR);
|
||||||
|
|
||||||
textEditor = await BalloonEditor.create($noteDetailText[0], {});
|
textEditor = await BalloonEditor.create($noteDetailText[0], {});
|
||||||
|
|
||||||
|
@ -89,64 +89,6 @@ function formatLabel(attr) {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CKEDITOR = {"js": ["libraries/ckeditor/ckeditor.js"]};
|
|
||||||
|
|
||||||
const CODE_MIRROR = {
|
|
||||||
js: [
|
|
||||||
"libraries/codemirror/codemirror.js",
|
|
||||||
"libraries/codemirror/addon/mode/loadmode.js",
|
|
||||||
"libraries/codemirror/addon/fold/xml-fold.js",
|
|
||||||
"libraries/codemirror/addon/edit/matchbrackets.js",
|
|
||||||
"libraries/codemirror/addon/edit/matchtags.js",
|
|
||||||
"libraries/codemirror/addon/search/match-highlighter.js",
|
|
||||||
"libraries/codemirror/mode/meta.js",
|
|
||||||
"libraries/codemirror/addon/lint/lint.js",
|
|
||||||
"libraries/codemirror/addon/lint/eslint.js"
|
|
||||||
],
|
|
||||||
css: [
|
|
||||||
"libraries/codemirror/codemirror.css",
|
|
||||||
"libraries/codemirror/addon/lint/lint.css"
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
const ESLINT = {js: ["libraries/eslint.js"]};
|
|
||||||
|
|
||||||
async function requireLibrary(library) {
|
|
||||||
if (library.css) {
|
|
||||||
library.css.map(cssUrl => requireCss(cssUrl));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (library.js) {
|
|
||||||
for (const scriptUrl of library.js) {
|
|
||||||
await requireScript(scriptUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const dynamicallyLoadedScripts = [];
|
|
||||||
|
|
||||||
async function requireScript(url) {
|
|
||||||
if (!dynamicallyLoadedScripts.includes(url)) {
|
|
||||||
dynamicallyLoadedScripts.push(url);
|
|
||||||
|
|
||||||
return await $.ajax({
|
|
||||||
url: url,
|
|
||||||
dataType: "script",
|
|
||||||
cache: true
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function requireCss(url) {
|
|
||||||
const css = Array
|
|
||||||
.from(document.querySelectorAll('link'))
|
|
||||||
.map(scr => scr.href);
|
|
||||||
|
|
||||||
if (!css.includes(url)) {
|
|
||||||
$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getHost() {
|
function getHost() {
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
return url.protocol + "//" + url.hostname + ":" + url.port;
|
return url.protocol + "//" + url.hostname + ":" + url.port;
|
||||||
@ -212,10 +154,6 @@ export default {
|
|||||||
stopWatch,
|
stopWatch,
|
||||||
formatValueWithWhitespace,
|
formatValueWithWhitespace,
|
||||||
formatLabel,
|
formatLabel,
|
||||||
requireLibrary,
|
|
||||||
CKEDITOR,
|
|
||||||
CODE_MIRROR,
|
|
||||||
ESLINT,
|
|
||||||
getHost,
|
getHost,
|
||||||
download,
|
download,
|
||||||
toObject,
|
toObject,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user