mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added note.executeScript()
This commit is contained in:
parent
f22c76d9fb
commit
fddab59265
10762
package-lock.json
generated
10762
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -58,7 +58,7 @@
|
|||||||
"mime-types": "2.1.30",
|
"mime-types": "2.1.30",
|
||||||
"multer": "1.4.2",
|
"multer": "1.4.2",
|
||||||
"node-abi": "2.26.0",
|
"node-abi": "2.26.0",
|
||||||
"open": "8.0.6",
|
"open": "8.0.8",
|
||||||
"portscanner": "2.2.0",
|
"portscanner": "2.2.0",
|
||||||
"rand-token": "1.0.1",
|
"rand-token": "1.0.1",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
@ -80,8 +80,8 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"cross-env": "7.0.3",
|
"cross-env": "7.0.3",
|
||||||
"electron": "13.0.0-beta.18",
|
"electron": "13.0.0-beta.23",
|
||||||
"electron-builder": "22.10.5",
|
"electron-builder": "22.11.1",
|
||||||
"electron-packager": "15.2.0",
|
"electron-packager": "15.2.0",
|
||||||
"electron-rebuild": "2.3.5",
|
"electron-rebuild": "2.3.5",
|
||||||
"esm": "3.2.25",
|
"esm": "3.2.25",
|
||||||
@ -89,8 +89,8 @@
|
|||||||
"jsdoc": "3.6.6",
|
"jsdoc": "3.6.6",
|
||||||
"lorem-ipsum": "2.0.3",
|
"lorem-ipsum": "2.0.3",
|
||||||
"rcedit": "3.0.0",
|
"rcedit": "3.0.0",
|
||||||
"webpack": "5.35.1",
|
"webpack": "5.36.2",
|
||||||
"webpack-cli": "4.6.0"
|
"webpack-cli": "4.7.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"electron-installer-debian": "3.1.0"
|
"electron-installer-debian": "3.1.0"
|
||||||
|
@ -3,6 +3,7 @@ import noteAttributeCache from "../services/note_attribute_cache.js";
|
|||||||
import ws from "../services/ws.js";
|
import ws from "../services/ws.js";
|
||||||
import options from "../services/options.js";
|
import options from "../services/options.js";
|
||||||
import treeCache from "../services/tree_cache.js";
|
import treeCache from "../services/tree_cache.js";
|
||||||
|
import bundle from "../services/bundle.js";
|
||||||
|
|
||||||
const LABEL = 'label';
|
const LABEL = 'label';
|
||||||
const RELATION = 'relation';
|
const RELATION = 'relation';
|
||||||
@ -701,6 +702,55 @@ class NoteShort {
|
|||||||
const labels = this.getLabels('workspaceTabBackgroundColor');
|
const labels = this.getLabels('workspaceTabBackgroundColor');
|
||||||
return labels.length > 0 ? labels[0].value : "";
|
return labels.length > 0 ? labels[0].value : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @returns {boolean} true if this note is JavaScript (code or attachment) */
|
||||||
|
isJavaScript() {
|
||||||
|
return (this.type === "code" || this.type === "file")
|
||||||
|
&& (this.mime.startsWith("application/javascript")
|
||||||
|
|| this.mime === "application/x-javascript"
|
||||||
|
|| this.mime === "text/javascript");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @returns {boolean} true if this note is HTML */
|
||||||
|
isHtml() {
|
||||||
|
return (this.type === "code" || this.type === "file" || this.type === "render") && this.mime === "text/html";
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @returns {string|null} JS script environment - either "frontend" or "backend" */
|
||||||
|
getScriptEnv() {
|
||||||
|
if (this.isHtml() || (this.isJavaScript() && this.mime.endsWith('env=frontend'))) {
|
||||||
|
return "frontend";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.type === 'render') {
|
||||||
|
return "frontend";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isJavaScript() && this.mime.endsWith('env=backend')) {
|
||||||
|
return "backend";
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async executeScript() {
|
||||||
|
if (!this.isJavaScript()) {
|
||||||
|
throw new Error(`Note ${this.noteId} is of type ${this.type} and mime ${this.mime} and thus cannot be executed`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const env = this.getScriptEnv();
|
||||||
|
|
||||||
|
if (env === "frontend") {
|
||||||
|
const bundleService = (await import("../services/bundle.js")).default;
|
||||||
|
await bundleService.getAndExecuteBundle(this.noteId);
|
||||||
|
}
|
||||||
|
else if (env === "backend") {
|
||||||
|
await server.post('script/run/' + this.noteId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error(`Unrecognized env type ${env} for note ${this.noteId}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NoteShort;
|
export default NoteShort;
|
||||||
|
@ -216,6 +216,7 @@ export default class Entrypoints extends Component {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: use note.executeScript()
|
||||||
if (note.mime.endsWith("env=frontend")) {
|
if (note.mime.endsWith("env=frontend")) {
|
||||||
await bundleService.getAndExecuteBundle(note.noteId);
|
await bundleService.getAndExecuteBundle(note.noteId);
|
||||||
} else if (note.mime.endsWith("env=backend")) {
|
} else if (note.mime.endsWith("env=backend")) {
|
||||||
|
@ -8,7 +8,7 @@ import treeService from "../../services/tree.js";
|
|||||||
import noteCreateService from "../../services/note_create.js";
|
import noteCreateService from "../../services/note_create.js";
|
||||||
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
|
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
|
||||||
|
|
||||||
const ENABLE_INSPECTOR = false;
|
const ENABLE_INSPECTOR = true;
|
||||||
|
|
||||||
const mentionSetup = {
|
const mentionSetup = {
|
||||||
feeds: [
|
feeds: [
|
||||||
@ -121,7 +121,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.textEditor.model.document.on('change:data', () => this.spacedUpdate.scheduleUpdate());
|
this.textEditor.model.document.on('change:data', () => this.spacedUpdate.scheduleUpdate());
|
||||||
|
console.log('glob.isDev', glob.isDev);
|
||||||
if (glob.isDev && ENABLE_INSPECTOR) {
|
if (glob.isDev && ENABLE_INSPECTOR) {
|
||||||
await import(/* webpackIgnore: true */'../../../libraries/ckeditor/inspector.js');
|
await import(/* webpackIgnore: true */'../../../libraries/ckeditor/inspector.js');
|
||||||
CKEditorInspector.attach(this.textEditor);
|
CKEditorInspector.attach(this.textEditor);
|
||||||
|
@ -14,6 +14,10 @@ button.btn, button.btn-sm {
|
|||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-micro {
|
||||||
|
padding: 0 10px 0 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.input-group-text {
|
.input-group-text {
|
||||||
background-color: var(--accented-background-color) !important;
|
background-color: var(--accented-background-color) !important;
|
||||||
color: var(--muted-text-color) !important;
|
color: var(--muted-text-color) !important;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user