chore(prettier): fix all files

This commit is contained in:
Elian Doran
2025-01-09 18:07:02 +02:00
parent 19ee861699
commit 4cbb529fd4
571 changed files with 23226 additions and 23940 deletions

View File

@@ -17,10 +17,7 @@ interface SetNoteOpts {
export type GetTextEditorCallback = () => void;
class NoteContext extends Component
implements EventListener<"entitiesReloaded">
{
class NoteContext extends Component implements EventListener<"entitiesReloaded"> {
ntxId: string | null;
hoistedNoteId: string;
private mainNtxId: string | null;
@@ -30,7 +27,7 @@ class NoteContext extends Component
private parentNoteId?: string | null;
viewScope?: ViewScope;
constructor(ntxId: string | null = null, hoistedNoteId: string = 'root', mainNtxId: string | null = null) {
constructor(ntxId: string | null = null, hoistedNoteId: string = "root", mainNtxId: string | null = null) {
super();
this.ntxId = ntxId || NoteContext.generateNtxId();
@@ -50,7 +47,7 @@ class NoteContext extends Component
this.parentNoteId = null;
// hoisted note is kept intentionally
this.triggerEvent('noteSwitched', {
this.triggerEvent("noteSwitched", {
noteContext: this,
notePath: this.notePath
});
@@ -81,20 +78,20 @@ class NoteContext extends Component
return;
}
await this.triggerEvent('beforeNoteSwitch', {noteContext: this});
await this.triggerEvent("beforeNoteSwitch", { noteContext: this });
utils.closeActiveDialog();
this.notePath = resolvedNotePath;
this.viewScope = opts.viewScope;
({noteId: this.noteId, parentNoteId: this.parentNoteId} = treeService.getNoteIdAndParentIdFromUrl(resolvedNotePath));
({ noteId: this.noteId, parentNoteId: this.parentNoteId } = treeService.getNoteIdAndParentIdFromUrl(resolvedNotePath));
this.saveToRecentNotes(resolvedNotePath);
protectedSessionHolder.touchProtectedSessionIfNecessary(this.note);
if (opts.triggerSwitchEvent) {
await this.triggerEvent('noteSwitched', {
await this.triggerEvent("noteSwitched", {
noteContext: this,
notePath: this.notePath
});
@@ -103,23 +100,20 @@ class NoteContext extends Component
await this.setHoistedNoteIfNeeded();
if (utils.isMobile()) {
this.triggerCommand('setActiveScreen', {screen: 'detail'});
this.triggerCommand("setActiveScreen", { screen: "detail" });
}
}
async setHoistedNoteIfNeeded() {
if (this.hoistedNoteId === 'root'
&& this.notePath?.startsWith("root/_hidden")
&& !this.note?.isLabelTruthy("keepCurrentHoisting")
) {
if (this.hoistedNoteId === "root" && this.notePath?.startsWith("root/_hidden") && !this.note?.isLabelTruthy("keepCurrentHoisting")) {
// hidden subtree displays only when hoisted, so it doesn't make sense to keep root as hoisted note
let hoistedNoteId = '_hidden';
let hoistedNoteId = "_hidden";
if (this.note?.isLaunchBarConfig()) {
hoistedNoteId = '_lbRoot';
hoistedNoteId = "_lbRoot";
} else if (this.note?.isOptions()) {
hoistedNoteId = '_options';
hoistedNoteId = "_options";
}
await this.setHoistedNoteId(hoistedNoteId);
@@ -127,7 +121,7 @@ class NoteContext extends Component
}
getSubContexts() {
return appContext.tabManager.noteContexts.filter(nc => nc.ntxId === this.ntxId || nc.mainNtxId === this.ntxId);
return appContext.tabManager.noteContexts.filter((nc) => nc.ntxId === this.ntxId || nc.mainNtxId === this.ntxId);
}
/**
@@ -152,13 +146,11 @@ class NoteContext extends Component
if (this.mainNtxId) {
try {
return appContext.tabManager.getNoteContextById(this.mainNtxId);
}
catch (e) {
} catch (e) {
this.mainNtxId = null;
return this;
}
}
else {
} else {
return this;
}
}
@@ -167,7 +159,7 @@ class NoteContext extends Component
setTimeout(async () => {
// we include the note in the recent list only if the user stayed on the note at least 5 seconds
if (resolvedNotePath && resolvedNotePath === this.notePath) {
await server.post('recent-notes', {
await server.post("recent-notes", {
noteId: this.note?.noteId,
notePath: this.notePath
});
@@ -183,7 +175,7 @@ class NoteContext extends Component
return;
}
if (await hoistedNoteService.checkNoteAccess(resolvedNotePath, this) === false) {
if ((await hoistedNoteService.checkNoteAccess(resolvedNotePath, this)) === false) {
return; // note is outside of hoisted subtree and user chose not to unhoist
}
@@ -200,7 +192,7 @@ class NoteContext extends Component
/** @returns {string[]} */
get notePathArray() {
return this.notePath ? this.notePath.split('/') : [];
return this.notePath ? this.notePath.split("/") : [];
}
isActive() {
@@ -208,7 +200,7 @@ class NoteContext extends Component
}
getPojoState() {
if (this.hoistedNoteId !== 'root') {
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) {
@@ -223,11 +215,11 @@ class NoteContext extends Component
hoistedNoteId: this.hoistedNoteId,
active: this.isActive(),
viewScope: this.viewScope
}
};
}
async unhoist() {
await this.setHoistedNoteId('root');
await this.setHoistedNoteId("root");
}
async setHoistedNoteId(noteIdToHoist: string) {
@@ -241,7 +233,7 @@ class NoteContext extends Component
await this.setNote(noteIdToHoist);
}
await this.triggerEvent('hoistedNoteChanged', {
await this.triggerEvent("hoistedNoteChanged", {
noteId: noteIdToHoist,
ntxId: this.ntxId
});
@@ -254,15 +246,15 @@ class NoteContext extends Component
}
// "readOnly" is a state valid only for text/code notes
if (!this.note || (this.note.type !== 'text' && this.note.type !== 'code')) {
if (!this.note || (this.note.type !== "text" && this.note.type !== "code")) {
return false;
}
if (this.note.isLabelTruthy('readOnly')) {
if (this.note.isLabelTruthy("readOnly")) {
return true;
}
if (this.viewScope?.viewMode === 'source') {
if (this.viewScope?.viewMode === "source") {
return true;
}
@@ -271,24 +263,20 @@ class NoteContext extends Component
return false;
}
const sizeLimit = this.note.type === 'text'
? options.getInt('autoReadonlySizeText')
: options.getInt('autoReadonlySizeCode');
const sizeLimit = this.note.type === "text" ? options.getInt("autoReadonlySizeText") : options.getInt("autoReadonlySizeCode");
return sizeLimit
&& blob.contentLength > sizeLimit
&& !this.note.isLabelTruthy('autoReadOnlyDisabled');
return sizeLimit && blob.contentLength > sizeLimit && !this.note.isLabelTruthy("autoReadOnlyDisabled");
}
async entitiesReloadedEvent({loadResults}: EventData<"entitiesReloaded">) {
async entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
if (this.noteId && loadResults.isNoteReloaded(this.noteId)) {
const noteRow = loadResults.getEntityRow('notes', this.noteId);
const noteRow = loadResults.getEntityRow("notes", this.noteId);
if (noteRow.isDeleted) {
this.noteId = null;
this.notePath = null;
this.triggerEvent('noteSwitched', {
this.triggerEvent("noteSwitched", {
noteContext: this,
notePath: this.notePath
});
@@ -297,48 +285,63 @@ class NoteContext extends Component
}
hasNoteList() {
return this.note
&& this.viewScope?.viewMode === 'default'
&& this.note.hasChildren()
&& ['book', 'text', 'code'].includes(this.note.type)
&& this.note.mime !== 'text/x-sqlite;schema=trilium'
&& !this.note.isLabelTruthy('hideChildrenOverview');
return (
this.note &&
this.viewScope?.viewMode === "default" &&
this.note.hasChildren() &&
["book", "text", "code"].includes(this.note.type) &&
this.note.mime !== "text/x-sqlite;schema=trilium" &&
!this.note.isLabelTruthy("hideChildrenOverview")
);
}
async getTextEditor(callback?: GetTextEditorCallback) {
return this.timeout<TextEditor>(new Promise(resolve => appContext.triggerCommand('executeWithTextEditor', {
callback,
resolve,
ntxId: this.ntxId
})));
return this.timeout<TextEditor>(
new Promise((resolve) =>
appContext.triggerCommand("executeWithTextEditor", {
callback,
resolve,
ntxId: this.ntxId
})
)
);
}
async getCodeEditor() {
return this.timeout(new Promise(resolve => appContext.triggerCommand('executeWithCodeEditor', {
resolve,
ntxId: this.ntxId
})));
return this.timeout(
new Promise((resolve) =>
appContext.triggerCommand("executeWithCodeEditor", {
resolve,
ntxId: this.ntxId
})
)
);
}
async getContentElement() {
return this.timeout<JQuery<HTMLElement>>(new Promise(resolve => appContext.triggerCommand('executeWithContentElement', {
resolve,
ntxId: this.ntxId
})));
return this.timeout<JQuery<HTMLElement>>(
new Promise((resolve) =>
appContext.triggerCommand("executeWithContentElement", {
resolve,
ntxId: this.ntxId
})
)
);
}
async getTypeWidget() {
return this.timeout(new Promise(resolve => appContext.triggerCommand('executeWithTypeWidget', {
resolve,
ntxId: this.ntxId
})));
return this.timeout(
new Promise((resolve) =>
appContext.triggerCommand("executeWithTypeWidget", {
resolve,
ntxId: this.ntxId
})
)
);
}
timeout<T>(promise: Promise<T | null>) {
return Promise.race([
promise,
new Promise(res => setTimeout(() => res(null), 200))
]) as Promise<T>;
return Promise.race([promise, new Promise((res) => setTimeout(() => res(null), 200))]) as Promise<T>;
}
resetViewScope() {
@@ -355,9 +358,7 @@ class NoteContext extends Component
const { note, viewScope } = this;
let title = viewScope?.viewMode === 'default'
? note.title
: `${note.title}: ${viewScope?.viewMode}`;
let title = viewScope?.viewMode === "default" ? note.title : `${note.title}: ${viewScope?.viewMode}`;
if (viewScope?.attachmentId) {
// assuming the attachment has been already loaded