mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
refactorings for add link and include note
This commit is contained in:
parent
7e41a2750c
commit
e06f3ef97e
@ -1,4 +1,4 @@
|
|||||||
FROM node:12.14.1-alpine
|
FROM node:12.16.0-alpine
|
||||||
|
|
||||||
# Create app directory
|
# Create app directory
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
PKG_DIR=dist/trilium-linux-x64-server
|
PKG_DIR=dist/trilium-linux-x64-server
|
||||||
NODE_VERSION=12.14.1
|
NODE_VERSION=12.16.0
|
||||||
|
|
||||||
if [ "$1" != "DONTCOPY" ]
|
if [ "$1" != "DONTCOPY" ]
|
||||||
then
|
then
|
||||||
|
2
libraries/ckeditor/ckeditor.js
vendored
2
libraries/ckeditor/ckeditor.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
6
package-lock.json
generated
6
package-lock.json
generated
@ -2669,9 +2669,9 @@
|
|||||||
"integrity": "sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA=="
|
"integrity": "sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA=="
|
||||||
},
|
},
|
||||||
"electron": {
|
"electron": {
|
||||||
"version": "9.0.0-beta.1",
|
"version": "9.0.0-beta.2",
|
||||||
"resolved": "https://registry.npmjs.org/electron/-/electron-9.0.0-beta.1.tgz",
|
"resolved": "https://registry.npmjs.org/electron/-/electron-9.0.0-beta.2.tgz",
|
||||||
"integrity": "sha512-OUqCC/aGYjFb2cA2ta1eBcjBW9yembcwtOQ9jKu75Lk3zTIVPavKLQxkC0LDy1FqTL9/Et8VtBI86EDvnFm3xw==",
|
"integrity": "sha512-WkRkUh5gE5B+b9XdTDvC67VvG118J0+wURcBpcXlBZJ9k+oqn0qcX+D3NG1WitXjcrAdV18cx5taUOat8zxAeA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@electron/get": "^1.0.1",
|
"@electron/get": "^1.0.1",
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
"ws": "7.2.1"
|
"ws": "7.2.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"electron": "9.0.0-beta.1",
|
"electron": "9.0.0-beta.2",
|
||||||
"electron-builder": "22.3.2",
|
"electron-builder": "22.3.2",
|
||||||
"electron-packager": "14.2.1",
|
"electron-packager": "14.2.1",
|
||||||
"electron-rebuild": "1.10.0",
|
"electron-rebuild": "1.10.0",
|
||||||
|
@ -36,36 +36,10 @@ window.glob.PROFILING_LOG = false;
|
|||||||
window.glob.isDesktop = utils.isDesktop;
|
window.glob.isDesktop = utils.isDesktop;
|
||||||
window.glob.isMobile = utils.isMobile;
|
window.glob.isMobile = utils.isMobile;
|
||||||
|
|
||||||
// required for CKEditor image upload plugin
|
window.glob.getComponentByEl = el => appContext.getComponentByEl(el);
|
||||||
// FIXME
|
|
||||||
window.glob.getActiveNode = () => appContext.getMainNoteTree().getActiveNode();
|
|
||||||
window.glob.getHeaders = server.getHeaders;
|
window.glob.getHeaders = server.getHeaders;
|
||||||
window.glob.showAddLinkDialog = () => import('./dialogs/add_link.js').then(d => d.showDialog());
|
|
||||||
window.glob.showIncludeNoteDialog = cb => import('./dialogs/include_note.js').then(d => d.showDialog(cb));
|
|
||||||
window.glob.loadIncludedNote = async (noteId, el) => {
|
|
||||||
const note = await treeCache.getNote(noteId);
|
|
||||||
|
|
||||||
if (note) {
|
// required for ESLint plugin and CKEditor
|
||||||
$(el).empty().append($("<h3>").append(await linkService.createNoteLink(note.noteId, {
|
|
||||||
showTooltip: false
|
|
||||||
})));
|
|
||||||
|
|
||||||
const {renderedContent} = await noteContentRenderer.getRenderedContent(note);
|
|
||||||
|
|
||||||
$(el).append(renderedContent);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// this is required by CKEditor when uploading images
|
|
||||||
window.glob.noteChanged = () => {
|
|
||||||
const activeTabContext = appContext.tabManager.getActiveTabContext();
|
|
||||||
|
|
||||||
if (activeTabContext) {
|
|
||||||
activeTabContext.noteChanged();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
window.glob.refreshTree = treeService.reload;
|
|
||||||
|
|
||||||
// required for ESLint plugin
|
|
||||||
window.glob.getActiveTabNote = () => appContext.tabManager.getActiveTabNote();
|
window.glob.getActiveTabNote = () => appContext.tabManager.getActiveTabNote();
|
||||||
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
window.glob.requireLibrary = libraryLoader.requireLibrary;
|
||||||
window.glob.ESLINT = libraryLoader.ESLINT;
|
window.glob.ESLINT = libraryLoader.ESLINT;
|
||||||
|
@ -5,10 +5,12 @@ import utils from "../services/utils.js";
|
|||||||
const $dialog = $("#include-note-dialog");
|
const $dialog = $("#include-note-dialog");
|
||||||
const $form = $("#include-note-form");
|
const $form = $("#include-note-form");
|
||||||
const $autoComplete = $("#include-note-autocomplete");
|
const $autoComplete = $("#include-note-autocomplete");
|
||||||
let callback = null;
|
|
||||||
|
|
||||||
export async function showDialog(cb) {
|
/** @var TextTypeWidget */
|
||||||
callback = cb;
|
let textTypeWidget;
|
||||||
|
|
||||||
|
export async function showDialog(widget) {
|
||||||
|
textTypeWidget = widget;
|
||||||
|
|
||||||
$autoComplete.val('');
|
$autoComplete.val('');
|
||||||
|
|
||||||
@ -24,9 +26,9 @@ $form.on('submit', () => {
|
|||||||
if (notePath) {
|
if (notePath) {
|
||||||
$dialog.modal('hide');
|
$dialog.modal('hide');
|
||||||
|
|
||||||
if (callback) {
|
const includedNoteId = treeService.getNoteIdFromNotePath(notePath);
|
||||||
callback(treeService.getNoteIdFromNotePath(notePath));
|
|
||||||
}
|
textTypeWidget.addIncludeNote(includedNoteId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error("No noteId to include.");
|
console.error("No noteId to include.");
|
||||||
|
@ -16,6 +16,7 @@ class AppContext {
|
|||||||
this.tabManager = new TabManager(this);
|
this.tabManager = new TabManager(this);
|
||||||
this.components = [];
|
this.components = [];
|
||||||
this.executors = [];
|
this.executors = [];
|
||||||
|
this.idToComponent = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
async start() {
|
async start() {
|
||||||
@ -59,6 +60,18 @@ class AppContext {
|
|||||||
this.trigger('initialRenderComplete');
|
this.trigger('initialRenderComplete');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerComponent(componentId, component) {
|
||||||
|
this.idToComponent[componentId] = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
findComponentById(componentId) {
|
||||||
|
return this.idToComponent[componentId];
|
||||||
|
}
|
||||||
|
|
||||||
|
getComponentByEl(el) {
|
||||||
|
return $(el).closest(".component").prop('component');
|
||||||
|
}
|
||||||
|
|
||||||
async trigger(name, data) {
|
async trigger(name, data) {
|
||||||
this.eventReceived(name, data);
|
this.eventReceived(name, data);
|
||||||
|
|
||||||
|
@ -5,6 +5,9 @@ class BasicWidget extends Component {
|
|||||||
render() {
|
render() {
|
||||||
const $widget = this.doRender();
|
const $widget = this.doRender();
|
||||||
|
|
||||||
|
$widget.addClass('component')
|
||||||
|
.prop('component', this);
|
||||||
|
|
||||||
keyboardActionsService.updateDisplayedShortcuts($widget);
|
keyboardActionsService.updateDisplayedShortcuts($widget);
|
||||||
|
|
||||||
this.toggle(this.isEnabled());
|
this.toggle(this.isEnabled());
|
||||||
|
@ -5,6 +5,9 @@ import TypeWidget from "./type_widget.js";
|
|||||||
import utils from "../../services/utils.js";
|
import utils from "../../services/utils.js";
|
||||||
import appContext from "../../services/app_context.js";
|
import appContext from "../../services/app_context.js";
|
||||||
import keyboardActionService from "../../services/keyboard_actions.js";
|
import keyboardActionService from "../../services/keyboard_actions.js";
|
||||||
|
import treeCache from "../../services/tree_cache.js";
|
||||||
|
import linkService from "../../services/link.js";
|
||||||
|
import noteContentRenderer from "../../services/note_content_renderer.js";
|
||||||
|
|
||||||
const ENABLE_INSPECTOR = false;
|
const ENABLE_INSPECTOR = false;
|
||||||
|
|
||||||
@ -254,4 +257,32 @@ export default class TextTypeWidget extends TypeWidget {
|
|||||||
addLinkToTextCommand() {
|
addLinkToTextCommand() {
|
||||||
import("../../dialogs/add_link.js").then(d => d.showDialog(this));
|
import("../../dialogs/add_link.js").then(d => d.showDialog(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addIncludeNoteToTextCommand() {
|
||||||
|
import("../../dialogs/include_note.js").then(d => d.showDialog(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadIncludedNote(noteId, el) {
|
||||||
|
const note = await treeCache.getNote(noteId);
|
||||||
|
|
||||||
|
if (note) {
|
||||||
|
$(el).empty().append($("<h3>").append(await linkService.createNoteLink(note.noteId, {
|
||||||
|
showTooltip: false
|
||||||
|
})));
|
||||||
|
|
||||||
|
const {renderedContent} = await noteContentRenderer.getRenderedContent(note);
|
||||||
|
|
||||||
|
$(el).append(renderedContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addIncludeNote(noteId) {
|
||||||
|
this.textEditor.model.change( writer => {
|
||||||
|
// Insert <includeNote>*</includeNote> at the current selection position
|
||||||
|
// in a way that will result in creating a valid model structure
|
||||||
|
this.textEditor.model.insertContent(writer.createElement('includeNote', {
|
||||||
|
noteId: noteId
|
||||||
|
}));
|
||||||
|
} );
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user