Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Merge branch 'master' into next61
zadam93addac8bb23
diff --cc src/becca/entities/bnote.jsindex 64599cc139,09dd7e6792..3771f0f05f--- a/src/becca/entities/bnote.js+++ b/src/becca/entities/bnote.js@@@ -5,13 -5,14 +5,13 @@@ const log = require('../../services/logconst sql = require('../../services/sql');const utils = require('../../services/utils');const dateUtils = require('../../services/date_utils');-const entityChangesService = require('../../services/entity_changes');const AbstractBeccaEntity = require("./abstract_becca_entity");- const BRevision = require("./brevision.js");-const BNoteRevision = require("./bnote_revision");++const BRevision = require("./brevision");+const BAttachment = require("./battachment");const TaskContext = require("../../services/task_context");const dayjs = require("dayjs");const utc = require('dayjs/plugin/utc');- const eventService = require("../../services/events.js");+ const eventService = require("../../services/events");-const cls = require("../../services/cls.js");dayjs.extend(utc);const LABEL = 'label';@@@ -1042,14 -1089,9 +1024,14 @@@ class BNote extends AbstractBeccaEntit}}- return this.ancestorCache;+ return this.__ancestorCache;}+ /** @returns {string[]} */+ getAncestorNoteIds() {+ return this.getAncestors().map(note => note.noteId);+ }+/** @returns {boolean} */hasAncestor(ancestorNoteId) {for (const ancestorNote of this.getAncestors()) {diff --cc src/public/app/components/note_context.jsindex 42b1608a77,c22a87ac60..9e0716cb34--- a/src/public/app/components/note_context.js+++ b/src/public/app/components/note_context.js@@@ -170,10 -175,13 +170,13 @@@ class NoteContext extends Componentreturn appContext.tabManager.activeNtxId === this.ntxId;}- getTabState() {+ getPojoState() {- if (!this.notePath && this.hoistedNoteId === 'root') {- // keeping empty hoisted tab is esp. important for mobile (e.g., opened launcher config)- return null;+ if (this.hoistedNoteId !== 'root') {+ // keeping empty hoisted tab is esp. important for mobile (e.g. opened launcher config)++ if (!this.notePath && this.getSubContexts().length === 0) {+ return null;+ }}return {diff --cc src/public/app/layouts/desktop_layout.jsindex 927a83bd34,cd5bb19128..76a05b7e2d--- a/src/public/app/layouts/desktop_layout.js+++ b/src/public/app/layouts/desktop_layout.js@@@ -75,7 -76,7 +76,8 @@@ import CodeButtonsWidget from "../widgeimport ApiLogWidget from "../widgets/api_log.js";import HideFloatingButtonsButton from "../widgets/floating_buttons/hide_floating_buttons_button.js";import ScriptExecutorWidget from "../widgets/ribbon_widgets/script_executor.js";+ import MovePaneButton from "../widgets/buttons/move_pane_button.js";+import UploadAttachmentsDialog from "../widgets/dialogs/upload_attachments.js";export default class DesktopLayout {constructor(customWidgets) {diff --cc src/public/app/services/note_content_renderer.jsindex 0000000000,6bb47d9f3a..e69de29bb2mode 000000,100644..100644--- a/src/public/app/services/note_content_renderer.js+++ b/src/public/app/services/note_content_renderer.jsdiff --cc src/public/app/services/utils.jsindex 5d66435073,bf468c5788..ddf7e9fbb9--- a/src/public/app/services/utils.js+++ b/src/public/app/services/utils.js@@@ -398,130 -354,17 +398,141 @@@ function escapeRegExp(str)return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");}+function areObjectsEqual () {+ let i, l, leftChain, rightChain;++ function compare2Objects (x, y) {+ let p;++ // remember that NaN === NaN returns false+ // and isNaN(undefined) returns true+ if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') {+ return true;+ }++ // Compare primitives and functions.+ // Check if both arguments link to the same object.+ // Especially useful on the step where we compare prototypes+ if (x === y) {+ return true;+ }++ // Works in case when functions are created in constructor.+ // Comparing dates is a common scenario. Another built-ins?+ // We can even handle functions passed across iframes+ if ((typeof x === 'function' && typeof y === 'function') ||+ (x instanceof Date && y instanceof Date) ||+ (x instanceof RegExp && y instanceof RegExp) ||+ (x instanceof String && y instanceof String) ||+ (x instanceof Number && y instanceof Number)) {+ return x.toString() === y.toString();+ }++ // At last checking prototypes as good as we can+ if (!(x instanceof Object && y instanceof Object)) {+ return false;+ }++ if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) {+ return false;+ }++ if (x.constructor !== y.constructor) {+ return false;+ }++ if (x.prototype !== y.prototype) {+ return false;+ }++ // Check for infinitive linking loops+ if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {+ return false;+ }++ // Quick checking of one object being a subset of another.+ // todo: cache the structure of arguments[0] for performance+ for (p in y) {+ if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {+ return false;+ }+ else if (typeof y[p] !== typeof x[p]) {+ return false;+ }+ }++ for (p in x) {+ if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {+ return false;+ }+ else if (typeof y[p] !== typeof x[p]) {+ return false;+ }++ switch (typeof (x[p])) {+ case 'object':+ case 'function':++ leftChain.push(x);+ rightChain.push(y);++ if (!compare2Objects (x[p], y[p])) {+ return false;+ }++ leftChain.pop();+ rightChain.pop();+ break;++ default:+ if (x[p] !== y[p]) {+ return false;+ }+ break;+ }+ }++ return true;+ }++ if (arguments.length < 1) {+ return true; //Die silently? Don't know how to handle such case, please help...+ // throw "Need two or more arguments to compare";+ }++ for (i = 1, l = arguments.length; i < l; i++) {++ leftChain = []; //Todo: this can be cached+ rightChain = [];++ if (!compare2Objects(arguments[0], arguments[i])) {+ return false;+ }+ }++ return true;+}++function copyHtmlToClipboard(content) {+ const clipboardItem = new ClipboardItem({+ 'text/html': new Blob([content], {type: 'text/html'}),+ 'text/plain': new Blob([content], {type: 'text/plain'})+ });++ navigator.clipboard.write([clipboardItem]);+}++ function formatNoteSize(size) {+ size = Math.max(Math.round(size / 1024), 1);++ if (size < 1024) {+ return `${size} KiB`;+ }+ else {+ return `${Math.round(size / 102.4) / 10} MiB`;+ }+ }+export default {reloadFrontendApp,parseDate,@@@ -567,6 -408,5 +578,8 @@@isValidAttributeName,sleep,escapeRegExp,- formatNoteSize++ formatNoteSize,++ escapeRegExp,+ areObjectsEqual,+ copyHtmlToClipboard};diff --cc src/public/app/widgets/ribbon_widgets/file_properties.jsindex 2080e71a42,afa0511684..633a3a60d4--- a/src/public/app/widgets/ribbon_widgets/file_properties.js+++ b/src/public/app/widgets/ribbon_widgets/file_properties.js@@@ -134,11 -134,11 +134,11 @@@ export default class FilePropertiesWidgthis.$fileName.text(attributeMap.originalFileName || "?");this.$fileType.text(note.mime);- const noteComplement = await this.noteContext.getNoteComplement();+ const blob = await this.note.getBlob();- this.$fileSize.text(`${blob.contentLength} bytes`);- this.$fileSize.text(utils.formatNoteSize(noteComplement.contentLength));++ this.$fileSize.text(utils.formatNoteSize(blob.contentLength));- // open doesn't work for protected notes since it works through browser which isn't in protected session+ // open doesn't work for protected notes since it works through a browser which isn't in protected sessionthis.$openButton.toggle(!note.isProtected);this.$downloadButton.toggle(!note.isProtected || protectedSessionHolder.isProtectedSessionAvailable())this.$uploadNewRevisionButton.toggle(!note.isProtected || protectedSessionHolder.isProtectedSessionAvailable())diff --cc src/routes/api/options.jsindex ae72275df6,4d9ee77a2b..ce40d6e3e5--- a/src/routes/api/options.js+++ b/src/routes/api/options.js@@@ -60,10 -60,9 +60,11 @@@ const ALLOWED_OPTIONS = new Set('compressImages','downloadImagesAutomatically','minTocHeadings',+ 'highlightedText','checkForUpdates','disableTray',+ 'eraseUnusedAttachmentsAfterSeconds',+ 'disableTray','customSearchEngineName','customSearchEngineUrl',]);diff --cc src/services/notes.jsindex 39c313399f,c9343bc4e9..a4062ac5e9--- a/src/services/notes.js+++ b/src/services/notes.js@@@ -55,13 -53,7 +55,11 @@@ function deriveMime(type, mime)return noteTypesService.getDefaultMimeForNoteType(type);}+/**+ * @param {BNote} parentNote+ * @param {BNote} childNote+ */function copyChildAttributes(parentNote, childNote) {- const hasAlreadyTemplate = childNote.hasRelation('template');-for (const attr of parentNote.getAttributes()) {if (attr.name.startsWith("child:")) {const name = attr.name.substr(6);@@@ -222,22 -214,14 +221,14 @@@ function createNewNote(params)copyChildAttributes(parentNote, note);+ eventService.emit(eventService.ENTITY_CREATED, { entityName: 'notes', entity: note });+ eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'notes', entity: note });triggerNoteTitleChanged(note);-- eventService.emit(eventService.ENTITY_CREATED, {- entityName: 'notes',- entity: note- });-- eventService.emit(eventService.ENTITY_CREATED, {- entityName: 'branches',- entity: branch- });-- eventService.emit(eventService.CHILD_NOTE_CREATED, {- childNote: note,- parentNote: parentNote- });- // note_contents doesn't use "created" event- eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'note_contents', entity: note });++ // blobs doesn't use "created" event++ eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'blobs', entity: note });+ eventService.emit(eventService.ENTITY_CREATED, { entityName: 'branches', entity: branch });+ eventService.emit(eventService.ENTITY_CHANGED, { entityName: 'branches', entity: branch });+ eventService.emit(eventService.CHILD_NOTE_CREATED, { childNote: note, parentNote: parentNote });log.info(`Created new note '${note.noteId}', branch '${branch.branchId}' of type '${note.type}', mime '${note.mime}'`);diff --cc src/services/options_init.jsindex 0ef3e2ff0e,358403214a..c08ec59921--- a/src/services/options_init.js+++ b/src/services/options_init.js@@@ -86,11 -87,11 +86,12 @@@ const defaultOptions ={ name: 'compressImages', value: 'true', isSynced: true },{ name: 'downloadImagesAutomatically', value: 'true', isSynced: true },{ name: 'minTocHeadings', value: '5', isSynced: true },+ { name: 'highlightedText', value: '["bold","italic","underline","color","bgColor"]', isSynced: true },{ name: 'checkForUpdates', value: 'true', isSynced: true },{ name: 'disableTray', value: 'false', isSynced: false },- { name: 'customSearchEngineName', value: 'Duckduckgo', isSynced: false },- { name: 'customSearchEngineUrl', value: 'https://duckduckgo.com/?q={keyword}', isSynced: false },+ { name: 'eraseUnusedAttachmentsAfterSeconds', value: '2592000', isSynced: true },+ { name: 'customSearchEngineName', value: 'DuckDuckGo', isSynced: true },+ { name: 'customSearchEngineUrl', value: 'https://duckduckgo.com/?q={keyword}', isSynced: true },];function initStartupOptions() {