2018-03-27 22:42:46 -04:00
|
|
|
const CKEDITOR = {"js": ["libraries/ckeditor/ckeditor.js"]};
|
|
|
|
|
|
|
|
const CODE_MIRROR = {
|
|
|
|
js: [
|
|
|
|
"libraries/codemirror/codemirror.js",
|
2022-01-07 19:33:59 +01:00
|
|
|
"libraries/codemirror/addon/display/placeholder.js",
|
2018-03-27 22:42:46 -04:00
|
|
|
"libraries/codemirror/addon/edit/matchbrackets.js",
|
|
|
|
"libraries/codemirror/addon/edit/matchtags.js",
|
2022-01-07 19:33:59 +01:00
|
|
|
"libraries/codemirror/addon/fold/xml-fold.js",
|
|
|
|
"libraries/codemirror/addon/lint/lint.js",
|
|
|
|
"libraries/codemirror/addon/lint/eslint.js",
|
|
|
|
"libraries/codemirror/addon/mode/loadmode.js",
|
|
|
|
"libraries/codemirror/addon/mode/simple.js",
|
2018-03-27 22:42:46 -04:00
|
|
|
"libraries/codemirror/addon/search/match-highlighter.js",
|
|
|
|
"libraries/codemirror/mode/meta.js",
|
2022-01-07 19:33:59 +01:00
|
|
|
"libraries/codemirror/keymap/vim.js"
|
2018-03-27 22:42:46 -04:00
|
|
|
],
|
|
|
|
css: [
|
|
|
|
"libraries/codemirror/codemirror.css",
|
|
|
|
"libraries/codemirror/addon/lint/lint.css"
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
const ESLINT = {js: ["libraries/eslint.js"]};
|
|
|
|
|
2018-09-02 23:02:01 +02:00
|
|
|
const COMMONMARK = {js: ["libraries/commonmark.min.js"]};
|
|
|
|
|
2018-10-18 11:46:07 +02:00
|
|
|
const RELATION_MAP = {
|
|
|
|
js: [
|
|
|
|
"libraries/jsplumb.js",
|
|
|
|
"libraries/panzoom.js"
|
|
|
|
],
|
|
|
|
css: [
|
2018-11-13 19:00:01 +01:00
|
|
|
"stylesheets/relation_map.css"
|
2018-10-18 11:46:07 +02:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-06-29 22:57:47 +02:00
|
|
|
const PRINT_THIS = {js: ["libraries/printThis.js"]};
|
|
|
|
|
2019-09-08 16:06:42 +02:00
|
|
|
const CALENDAR_WIDGET = {css: ["stylesheets/calendar.css"]};
|
|
|
|
|
2020-09-21 22:57:22 +02:00
|
|
|
const KATEX = {
|
2021-05-06 16:38:56 -04:00
|
|
|
js: [ "libraries/katex/katex.min.js", "libraries/katex/mhchem.min.js", "libraries/katex/auto-render.min.js" ],
|
2020-09-21 22:57:22 +02:00
|
|
|
css: [ "libraries/katex/katex.min.css" ]
|
|
|
|
};
|
|
|
|
|
2021-03-15 22:24:56 +01:00
|
|
|
const WHEEL_ZOOM = {
|
|
|
|
js: [ "libraries/wheel-zoom.min.js"]
|
|
|
|
};
|
|
|
|
|
2021-05-29 22:52:32 +02:00
|
|
|
const FORCE_GRAPH = {
|
|
|
|
js: [ "libraries/force-graph.min.js"]
|
|
|
|
};
|
|
|
|
|
2021-09-29 21:54:56 +02:00
|
|
|
const MERMAID = {
|
|
|
|
js: [ "libraries/mermaid.min.js" ]
|
|
|
|
}
|
|
|
|
|
2022-04-05 15:35:15 +02:00
|
|
|
const EXCALIDRAW = {
|
2021-11-25 13:45:58 +01:00
|
|
|
js: [
|
2022-05-09 15:16:12 +02:00
|
|
|
"node_modules/react/umd/react.production.min.js",
|
|
|
|
"node_modules/react-dom/umd/react-dom.production.min.js",
|
|
|
|
"node_modules/@excalidraw/excalidraw/dist/excalidraw.production.min.js",
|
2021-11-25 13:45:58 +01:00
|
|
|
],
|
|
|
|
// css: [
|
|
|
|
// "stylesheets/somestyle.css"
|
|
|
|
// ]
|
|
|
|
};
|
|
|
|
|
2018-03-27 22:42:46 -04:00
|
|
|
async function requireLibrary(library) {
|
|
|
|
if (library.css) {
|
2020-02-17 19:42:52 +01:00
|
|
|
library.css.map(cssUrl => requireCss(cssUrl));
|
2018-03-27 22:42:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (library.js) {
|
|
|
|
for (const scriptUrl of library.js) {
|
|
|
|
await requireScript(scriptUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 15:56:46 -04:00
|
|
|
// we save the promises in case of the same script being required concurrently multiple times
|
|
|
|
const loadedScriptPromises = {};
|
2018-03-27 22:42:46 -04:00
|
|
|
|
|
|
|
async function requireScript(url) {
|
2018-04-07 15:56:46 -04:00
|
|
|
if (!loadedScriptPromises[url]) {
|
|
|
|
loadedScriptPromises[url] = $.ajax({
|
2018-03-27 22:42:46 -04:00
|
|
|
url: url,
|
|
|
|
dataType: "script",
|
|
|
|
cache: true
|
2018-04-07 15:56:46 -04:00
|
|
|
});
|
2018-03-27 22:42:46 -04:00
|
|
|
}
|
2018-04-07 15:56:46 -04:00
|
|
|
|
|
|
|
await loadedScriptPromises[url];
|
2018-03-27 22:42:46 -04:00
|
|
|
}
|
|
|
|
|
2020-02-17 19:42:52 +01:00
|
|
|
async function requireCss(url) {
|
|
|
|
const cssLinks = Array
|
|
|
|
.from(document.querySelectorAll('link'))
|
|
|
|
.map(el => el.href);
|
|
|
|
|
|
|
|
if (!cssLinks.some(l => l.endsWith(url))) {
|
|
|
|
$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', url));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-27 22:42:46 -04:00
|
|
|
export default {
|
2020-02-17 19:42:52 +01:00
|
|
|
requireCss,
|
2018-03-27 22:42:46 -04:00
|
|
|
requireLibrary,
|
|
|
|
CKEDITOR,
|
|
|
|
CODE_MIRROR,
|
2018-09-02 23:02:01 +02:00
|
|
|
ESLINT,
|
2018-10-18 11:46:07 +02:00
|
|
|
COMMONMARK,
|
2019-06-03 22:55:59 +02:00
|
|
|
RELATION_MAP,
|
2019-08-20 23:30:19 +02:00
|
|
|
PRINT_THIS,
|
2020-09-21 22:57:22 +02:00
|
|
|
CALENDAR_WIDGET,
|
2021-03-15 22:24:56 +01:00
|
|
|
KATEX,
|
2021-05-29 22:52:32 +02:00
|
|
|
WHEEL_ZOOM,
|
2021-09-29 21:54:56 +02:00
|
|
|
FORCE_GRAPH,
|
2021-11-25 13:45:58 +01:00
|
|
|
MERMAID,
|
missing path2d support for freedawings, remove node-side rendering, allow async getContent()
* ## Excalidraw and SVG
* 2022-04-16 - @thfrei
*
* Known issues:
* - excalidraw-to-svg (node.js) does not render any hand drawn (freedraw) paths. There is an issue with
* Path2D object not present in node-canvas library used by jsdom. (See Trilium PR for samples and other issues
* in respective library. Link will be added later). Related links:
* - https://github.com/Automattic/node-canvas/pull/2013
* - https://github.com/google/canvas-5-polyfill
* - https://github.com/Automattic/node-canvas/issues/1116
* - https://www.npmjs.com/package/path2d-polyfill
* - excalidraw-to-svg (node.js) takes quite some time to load an image (1-2s)
* - excalidraw-utils (browser) does render freedraw, however NOT freedraw with background
*
* Due to this issues, we opt to use **only excalidraw in the frontend**. Upon saving, we will also get the SVG
* output from the live excalidraw instance. We will save this **SVG side by side the native excalidraw format
* in the trilium note**.
*
* Pro: we will combat bit-rot. Showing the SVG will be very fast, since it is already rendered.
* Con: The note will get bigger (maybe +30%?), we will generate more bandwith.
* (However, using trilium desktop instance, does not care too much about bandwidth. Size increase is probably
* acceptable, as a trade off.)
2022-04-19 00:21:20 +02:00
|
|
|
EXCALIDRAW
|
2020-07-04 10:18:01 +02:00
|
|
|
}
|