Merge branch 'master' into next53

This commit is contained in:
zadam 2022-06-05 22:25:14 +02:00
commit 4211d0feda
17 changed files with 76 additions and 24 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
"name": "trilium", "name": "trilium",
"productName": "Trilium Notes", "productName": "Trilium Notes",
"description": "Trilium Notes", "description": "Trilium Notes",
"version": "0.52.0-beta", "version": "0.52.1-beta",
"license": "AGPL-3.0-only", "license": "AGPL-3.0-only",
"main": "electron.js", "main": "electron.js",
"bin": { "bin": {

View File

@ -5,9 +5,9 @@ const AbstractEntity = require("./abstract_entity");
const sql = require("../../services/sql"); const sql = require("../../services/sql");
const dateUtils = require("../../services/date_utils"); const dateUtils = require("../../services/date_utils");
const utils = require("../../services/utils.js"); const utils = require("../../services/utils.js");
const TaskContext = require("../../services/task_context.js"); const TaskContext = require("../../services/task_context");
const cls = require("../../services/cls.js"); const cls = require("../../services/cls");
const log = require("../../services/log.js"); const log = require("../../services/log");
/** /**
* Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple * Branch represents a relationship between a child note and its parent note. Trilium allows a note to have multiple
@ -137,6 +137,18 @@ class Branch extends AbstractEntity {
taskContext.increaseProgressCount(); taskContext.increaseProgressCount();
const note = this.getNote();
if (!taskContext.noteDeletionHandlerTriggered) {
const parentBranches = note.getParentBranches();
if (parentBranches.length === 1 && parentBranches[0] === this) {
// needs to be run before branches and attributes are deleted and thus attached relations disappear
const handlers = require("../../services/handlers");
handlers.runAttachedRelations(note, 'runOnNoteDeletion', note);
}
}
if (this.branchId === 'root' if (this.branchId === 'root'
|| this.noteId === 'root' || this.noteId === 'root'
|| this.noteId === cls.getHoistedNoteId()) { || this.noteId === cls.getHoistedNoteId()) {
@ -146,7 +158,6 @@ class Branch extends AbstractEntity {
this.markAsDeleted(deleteId); this.markAsDeleted(deleteId);
const note = this.getNote();
const notDeletedBranches = note.getParentBranches(); const notDeletedBranches = note.getParentBranches();
if (notDeletedBranches.length === 0) { if (notDeletedBranches.length === 0) {

View File

@ -8,9 +8,8 @@ const dateUtils = require('../../services/date_utils');
const entityChangesService = require('../../services/entity_changes'); const entityChangesService = require('../../services/entity_changes');
const AbstractEntity = require("./abstract_entity"); const AbstractEntity = require("./abstract_entity");
const NoteRevision = require("./note_revision"); const NoteRevision = require("./note_revision");
const TaskContext = require("../../services/task_context.js"); const TaskContext = require("../../services/task_context");
const optionService = require("../../services/options.js"); const handlers = require("../../services/handlers");
const noteRevisionService = require("../../services/note_revisions.js");
const LABEL = 'label'; const LABEL = 'label';
const RELATION = 'relation'; const RELATION = 'relation';
@ -1143,6 +1142,10 @@ class Note extends AbstractEntity {
taskContext = new TaskContext('no-progress-reporting'); taskContext = new TaskContext('no-progress-reporting');
} }
// needs to be run before branches and attributes are deleted and thus attached relations disappear
handlers.runAttachedRelations(this, 'runOnNoteDeletion', this);
taskContext.noteDeletionHandlerTriggered = true;
for (const branch of this.getParentBranches()) { for (const branch of this.getParentBranches()) {
branch.deleteBranch(deleteId, taskContext); branch.deleteBranch(deleteId, taskContext);
} }

View File

@ -248,6 +248,13 @@ class NoteContext extends Component {
ntxId: this.ntxId ntxId: this.ntxId
})); }));
} }
async getTypeWidget() {
return new Promise(resolve => appContext.triggerCommand('executeWithTypeWidget', {
resolve,
ntxId: this.ntxId
}));
}
} }
export default NoteContext; export default NoteContext;

View File

@ -24,8 +24,8 @@ async function createNote(parentNotePath, options = {}) {
options.saveSelection = false; options.saveSelection = false;
} }
if (options.saveSelection && utils.isCKEditorInitialized()) { if (options.saveSelection) {
[options.title, options.content] = parseSelectedHtml(window.cutToNote.getSelectedHtml()); [options.title, options.content] = parseSelectedHtml(options.textEditor.getSelectedHtml());
} }
const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath); const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath);
@ -47,9 +47,9 @@ async function createNote(parentNotePath, options = {}) {
templateNoteId: options.templateNoteId templateNoteId: options.templateNoteId
}); });
if (options.saveSelection && utils.isCKEditorInitialized()) { if (options.saveSelection) {
// we remove the selection only after it was saved to server to make sure we don't lose anything // we remove the selection only after it was saved to server to make sure we don't lose anything
window.cutToNote.removeSelection(); options.textEditor.removeSelection();
} }
await ws.waitForMaxKnownEntityChangeId(); await ws.waitForMaxKnownEntityChangeId();

View File

@ -292,10 +292,6 @@ function copySelectionToClipboard() {
} }
} }
function isCKEditorInitialized() {
return !!(window && window.cutToNote);
}
function dynamicRequire(moduleName) { function dynamicRequire(moduleName) {
if (typeof __non_webpack_require__ !== 'undefined') { if (typeof __non_webpack_require__ !== 'undefined') {
return __non_webpack_require__(moduleName); return __non_webpack_require__(moduleName);
@ -405,7 +401,6 @@ export default {
clearBrowserCache, clearBrowserCache,
normalizeShortcut, normalizeShortcut,
copySelectionToClipboard, copySelectionToClipboard,
isCKEditorInitialized,
dynamicRequire, dynamicRequire,
timeLimit, timeLimit,
initHelpDropdown, initHelpDropdown,

View File

@ -233,6 +233,9 @@ const ATTR_HELP = {
"runOnNoteCreation": "executes when note is created on backend", "runOnNoteCreation": "executes when note is created on backend",
"runOnNoteTitleChange": "executes when note title is changed (includes note creation as well)", "runOnNoteTitleChange": "executes when note title is changed (includes note creation as well)",
"runOnNoteChange": "executes when note is changed (includes note creation as well)", "runOnNoteChange": "executes when note is changed (includes note creation as well)",
"runOnNoteDeletion": "executes when note is being deleted",
"runOnBranchCreation": "executes when a branch is created. Branch is a link between parent note and child note and is created e.g. when cloning or moving note.",
"runOnBranchDeletion": "executes when a branch is deleted. Branch is a link between parent note and child note and is deleted e.g. when moving note (old branch/link is deleted).",
"runOnChildNoteCreation": "executes when new note is created under this note", "runOnChildNoteCreation": "executes when new note is created under this note",
"runOnAttributeCreation": "executes when new attribute is created under this note", "runOnAttributeCreation": "executes when new attribute is created under this note",
"runOnAttributeChange": "executes when attribute is changed under this note", "runOnAttributeChange": "executes when attribute is changed under this note",

View File

@ -330,7 +330,8 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
// without await as this otherwise causes deadlock through component mutex // without await as this otherwise causes deadlock through component mutex
noteCreateService.createNote(appContext.tabManager.getActiveContextNotePath(), { noteCreateService.createNote(appContext.tabManager.getActiveContextNotePath(), {
isProtected: note.isProtected, isProtected: note.isProtected,
saveSelection: true saveSelection: true,
textEditor: await this.noteContext.getTextEditor()
}); });
} }
@ -344,4 +345,16 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
this.refresh(); this.refresh();
} }
} }
async executeWithTypeWidgetEvent({resolve, ntxId}) {
if (!this.isNoteContext(ntxId)) {
return;
}
await this.initialized;
await this.getWidgetType();
resolve(this.getTypeWidget());
}
} }

View File

@ -363,7 +363,9 @@ pre:not(.CodeMirror-line) {
.go-to-selected-note-button.disabled, .go-to-selected-note-button.disabled:hover { .go-to-selected-note-button.disabled, .go-to-selected-note-button.disabled:hover {
cursor: inherit; cursor: inherit;
color: var(--button-disabled-background-color) !important; color: var(--button-disabled-text-color) !important;
background-color: var(--button-disabled-background-color) !important;
text-decoration: none;
} }
.note-autocomplete-input { .note-autocomplete-input {

View File

@ -21,10 +21,11 @@
--more-accented-background-color: #777; --more-accented-background-color: #777;
--button-background-color: transparent; --button-background-color: transparent;
--button-disabled-background-color: #222;
--button-border-color: #ccc; --button-border-color: #ccc;
--button-text-color: currentColor; --button-text-color: currentColor;
--button-border-radius: 5px; --button-border-radius: 5px;
--button-disabled-background-color: transparent;
--button-disabled-text-color: #999;
--primary-button-background-color: #888; --primary-button-background-color: #888;
--primary-button-text-color: white; --primary-button-text-color: white;

View File

@ -25,10 +25,11 @@ html {
--more-accented-background-color: #ddd; --more-accented-background-color: #ddd;
--button-background-color: transparent; --button-background-color: transparent;
--button-disabled-background-color: #ddd;
--button-border-color: #ddd; --button-border-color: #ddd;
--button-text-color: black; --button-text-color: black;
--button-border-radius: 5px; --button-border-radius: 5px;
--button-disabled-background-color: #ddd;
--button-disabled-text-color: black;
--primary-button-background-color: #6c757d; --primary-button-background-color: #6c757d;
--primary-button-text-color: white; --primary-button-text-color: white;

View File

@ -1 +1 @@
module.exports = { buildDate:"2022-05-27T22:13:24+02:00", buildRevision: "388dcadef3e23c25ee256c63cd627d18691a687a" }; module.exports = { buildDate:"2022-06-05T15:00:25+02:00", buildRevision: "f587e0dfd9177462faef8ad7c39a855c25d03c91" };

View File

@ -61,6 +61,9 @@ module.exports = [
{ type: 'relation', name: 'runOnNoteCreation', isDangerous: true }, { type: 'relation', name: 'runOnNoteCreation', isDangerous: true },
{ type: 'relation', name: 'runOnNoteTitleChange', isDangerous: true }, { type: 'relation', name: 'runOnNoteTitleChange', isDangerous: true },
{ type: 'relation', name: 'runOnNoteChange', isDangerous: true }, { type: 'relation', name: 'runOnNoteChange', isDangerous: true },
{ type: 'relation', name: 'runOnNoteDeletion', isDangerous: true },
{ type: 'relation', name: 'runOnBranchCreation', isDangerous: true },
{ type: 'relation', name: 'runOnBranchDeletion', isDangerous: true },
{ type: 'relation', name: 'runOnChildNoteCreation', isDangerous: true }, { type: 'relation', name: 'runOnChildNoteCreation', isDangerous: true },
{ type: 'relation', name: 'runOnAttributeCreation', isDangerous: true }, { type: 'relation', name: 'runOnAttributeCreation', isDangerous: true },
{ type: 'relation', name: 'runOnAttributeChange', isDangerous: true }, { type: 'relation', name: 'runOnAttributeChange', isDangerous: true },

View File

@ -49,6 +49,7 @@ eventService.subscribe([ eventService.ENTITY_CHANGED, eventService.ENTITY_DELETE
} }
} }
else if (entityName === 'notes') { else if (entityName === 'notes') {
// ENTITY_DELETED won't trigger anything since all branches/attributes are already deleted at this point
runAttachedRelations(entity, 'runOnNoteChange', entity); runAttachedRelations(entity, 'runOnNoteChange', entity);
} }
}); });
@ -94,6 +95,9 @@ eventService.subscribe(eventService.ENTITY_CREATED, ({ entityName, entity }) =>
handleSortedAttribute(entity); handleSortedAttribute(entity);
} }
} }
else if (entityName === 'branches') {
runAttachedRelations(entity.getNote(), 'runOnBranchCreation', entity);
}
else if (entityName === 'notes') { else if (entityName === 'notes') {
runAttachedRelations(entity, 'runOnNoteCreation', entity); runAttachedRelations(entity, 'runOnNoteCreation', entity);
} }
@ -167,4 +171,12 @@ eventService.subscribe(eventService.ENTITY_DELETED, ({ entityName, entity }) =>
} }
} }
}); });
if (entityName === 'branches') {
runAttachedRelations(entity.getNote(), 'runOnBranchDeletion', entity);
}
}); });
module.exports = {
runAttachedRelations
};

View File

@ -10,6 +10,7 @@ class TaskContext {
this.taskId = taskId; this.taskId = taskId;
this.taskType = taskType; this.taskType = taskType;
this.data = data; this.data = data;
this.noteDeletionHandlerTriggered = false;
// progressCount is meant to represent just some progress - to indicate the task is not stuck // progressCount is meant to represent just some progress - to indicate the task is not stuck
this.progressCount = -1; // we're incrementing immediatelly this.progressCount = -1; // we're incrementing immediatelly