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

@@ -86,10 +86,10 @@ const TPL = `
const mentionSetup: MentionConfig = {
feeds: [
{
marker: '@',
feed: queryText => noteAutocompleteService.autocompleteSourceForCKEditor(queryText),
itemRenderer: item => {
const itemElement = document.createElement('button');
marker: "@",
feed: (queryText) => noteAutocompleteService.autocompleteSourceForCKEditor(queryText),
itemRenderer: (item) => {
const itemElement = document.createElement("button");
itemElement.innerHTML = `${item.highlightedNotePathTitle} `;
@@ -98,29 +98,29 @@ const mentionSetup: MentionConfig = {
minimumCharacters: 0
},
{
marker: '#',
feed: async queryText => {
marker: "#",
feed: async (queryText) => {
const names = await server.get<string[]>(`attribute-names/?type=label&query=${encodeURIComponent(queryText)}`);
return names.map(name => {
return names.map((name) => {
return {
id: `#${name}`,
name: name
}
};
});
},
minimumCharacters: 0
},
{
marker: '~',
feed: async queryText => {
marker: "~",
feed: async (queryText) => {
const names = await server.get<string[]>(`attribute-names/?type=relation&query=${encodeURIComponent(queryText)}`);
return names.map(name => {
return names.map((name) => {
return {
id: `~${name}`,
name: name
}
};
});
},
minimumCharacters: 0
@@ -130,53 +130,53 @@ const mentionSetup: MentionConfig = {
const editorConfig = {
removePlugins: [
'Heading',
'Link',
'Autoformat',
'Bold',
'Italic',
'Underline',
'Strikethrough',
'Code',
'Superscript',
'Subscript',
'BlockQuote',
'Image',
'ImageCaption',
'ImageStyle',
'ImageToolbar',
'ImageUpload',
'ImageResize',
'List',
'TodoList',
'PasteFromOffice',
'Table',
'TableToolbar',
'TableProperties',
'TableCellProperties',
'Indent',
'IndentBlock',
'BlockToolbar',
'ParagraphButtonUI',
'HeadingButtonsUI',
'UploadimagePlugin',
'InternalLinkPlugin',
'MarkdownImportPlugin',
'CuttonotePlugin',
'TextTransformation',
'Font',
'FontColor',
'FontBackgroundColor',
'CodeBlock',
'SelectAll',
'IncludeNote',
'CutToNote',
'Mathematics',
'AutoformatMath',
'indentBlockShortcutPlugin',
'removeFormatLinksPlugin',
'Footnotes',
'Mermaid'
"Heading",
"Link",
"Autoformat",
"Bold",
"Italic",
"Underline",
"Strikethrough",
"Code",
"Superscript",
"Subscript",
"BlockQuote",
"Image",
"ImageCaption",
"ImageStyle",
"ImageToolbar",
"ImageUpload",
"ImageResize",
"List",
"TodoList",
"PasteFromOffice",
"Table",
"TableToolbar",
"TableProperties",
"TableCellProperties",
"Indent",
"IndentBlock",
"BlockToolbar",
"ParagraphButtonUI",
"HeadingButtonsUI",
"UploadimagePlugin",
"InternalLinkPlugin",
"MarkdownImportPlugin",
"CuttonotePlugin",
"TextTransformation",
"Font",
"FontColor",
"FontBackgroundColor",
"CodeBlock",
"SelectAll",
"IncludeNote",
"CutToNote",
"Mathematics",
"AutoformatMath",
"indentBlockShortcutPlugin",
"removeFormatLinksPlugin",
"Footnotes",
"Mermaid"
],
toolbar: {
items: []
@@ -187,11 +187,7 @@ const editorConfig = {
type AttributeCommandNames = FilteredCommandNames<CommandData>;
export default class AttributeEditorWidget extends NoteContextAwareWidget implements
EventListener<"entitiesReloaded">,
EventListener<"addNewLabel">,
EventListener<"addNewRelation"> {
export default class AttributeEditorWidget extends NoteContextAwareWidget implements EventListener<"entitiesReloaded">, EventListener<"addNewLabel">, EventListener<"addNewRelation"> {
private attributeDetailWidget: AttributeDetailWidget;
private $editor!: JQuery<HTMLElement>;
private $addNewAttributeButton!: JQuery<HTMLElement>;
@@ -210,11 +206,11 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
doRender() {
this.$widget = $(TPL);
this.$editor = this.$widget.find('.attribute-list-editor');
this.$editor = this.$widget.find(".attribute-list-editor");
this.initialized = this.initEditor();
this.$editor.on('keydown', async e => {
this.$editor.on("keydown", async (e) => {
if (e.which === 13) {
// allow autocomplete to fill the result textarea
setTimeout(() => this.save(), 100);
@@ -223,48 +219,48 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
this.attributeDetailWidget.hide();
});
this.$editor.on('blur', () => setTimeout(() => this.save(), 100)); // Timeout to fix https://github.com/zadam/trilium/issues/4160
this.$editor.on("blur", () => setTimeout(() => this.save(), 100)); // Timeout to fix https://github.com/zadam/trilium/issues/4160
this.$addNewAttributeButton = this.$widget.find('.add-new-attribute-button');
this.$addNewAttributeButton.on('click', e => this.addNewAttribute(e));
this.$addNewAttributeButton = this.$widget.find(".add-new-attribute-button");
this.$addNewAttributeButton.on("click", (e) => this.addNewAttribute(e));
this.$saveAttributesButton = this.$widget.find('.save-attributes-button');
this.$saveAttributesButton.on('click', () => this.save());
this.$saveAttributesButton = this.$widget.find(".save-attributes-button");
this.$saveAttributesButton.on("click", () => this.save());
this.$errors = this.$widget.find('.attribute-errors');
this.$errors = this.$widget.find(".attribute-errors");
}
addNewAttribute(e: JQuery.ClickEvent) {
contextMenuService.show<AttributeCommandNames>({
x: e.pageX,
y: e.pageY,
orientation: 'left',
orientation: "left",
items: [
{ title: t("attribute_editor.add_new_label"), command: "addNewLabel", uiIcon: "bx bx-hash" },
{ title: t("attribute_editor.add_new_relation"), command: "addNewRelation", uiIcon: "bx bx-transfer" },
{ title: "----" },
{ title: t("attribute_editor.add_new_label_definition"), command: "addNewLabelDefinition", uiIcon: "bx bx-empty" },
{ title: t("attribute_editor.add_new_relation_definition"), command: "addNewRelationDefinition", uiIcon: "bx bx-empty" },
{ title: t("attribute_editor.add_new_relation_definition"), command: "addNewRelationDefinition", uiIcon: "bx bx-empty" }
],
selectMenuItemHandler: ({ command }) => this.handleAddNewAttributeCommand(command)
});
}
// triggered from keyboard shortcut
async addNewLabelEvent({ntxId}: EventData<"addNewLabel">) {
async addNewLabelEvent({ ntxId }: EventData<"addNewLabel">) {
if (this.isNoteContext(ntxId)) {
await this.refresh();
this.handleAddNewAttributeCommand('addNewLabel');
this.handleAddNewAttributeCommand("addNewLabel");
}
}
// triggered from keyboard shortcut
async addNewRelationEvent({ntxId}: EventData<"addNewRelation">) {
async addNewRelationEvent({ ntxId }: EventData<"addNewRelation">) {
if (this.isNoteContext(ntxId)) {
await this.refresh();
this.handleAddNewAttributeCommand('addNewRelation');
this.handleAddNewAttributeCommand("addNewRelation");
}
}
@@ -280,22 +276,22 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
let name;
let value;
if (command === 'addNewLabel') {
type = 'label';
name = 'myLabel';
value = '';
} else if (command === 'addNewRelation') {
type = 'relation';
name = 'myRelation';
value = '';
} else if (command === 'addNewLabelDefinition') {
type = 'label';
name = 'label:myLabel';
value = 'promoted,single,text';
} else if (command === 'addNewRelationDefinition') {
type = 'label';
name = 'relation:myRelation';
value = 'promoted,single';
if (command === "addNewLabel") {
type = "label";
name = "myLabel";
value = "";
} else if (command === "addNewRelation") {
type = "relation";
name = "myRelation";
value = "";
} else if (command === "addNewLabelDefinition") {
type = "label";
name = "label:myLabel";
value = "promoted,single,text";
} else if (command === "addNewRelationDefinition") {
type = "label";
name = "relation:myRelation";
value = "promoted,single";
} else {
return;
}
@@ -323,7 +319,7 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
isOwned: true,
x: (rect.left + rect.right) / 2,
y: rect.bottom,
focus: 'name'
focus: "name"
});
}, 100);
}
@@ -343,10 +339,10 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
this.$saveAttributesButton.fadeOut();
// blink the attribute text to give a visual hint that save has been executed
this.$editor.css('opacity', 0);
this.$editor.css("opacity", 0);
// revert back
setTimeout(() => this.$editor.css('opacity', 1), 100);
setTimeout(() => this.$editor.css("opacity", 1), 100);
}
}
@@ -359,7 +355,8 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
}
getPreprocessedData() {
const str = this.textEditor.getData()
const str = this.textEditor
.getData()
.replace(/<a[^>]+href="(#[A-Za-z0-9_/]*)"[^>]*>[^<]*<\/a>/g, "$1")
.replace(/&nbsp;/g, " "); // otherwise .text() below outputs non-breaking space in unicode
@@ -371,18 +368,22 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
this.$widget.show();
this.$editor.on("click", e => this.handleEditorClick(e));
this.$editor.on("click", (e) => this.handleEditorClick(e));
this.textEditor = await CKEditor.BalloonEditor.create(this.$editor[0], editorConfig);
this.textEditor.model.document.on('change:data', () => this.dataChanged());
this.textEditor.editing.view.document.on('enter', (event, data) => {
// disable entering new line - see https://github.com/ckeditor/ckeditor5/issues/9422
data.preventDefault();
event.stop();
}, {priority: 'high'});
this.textEditor.model.document.on("change:data", () => this.dataChanged());
this.textEditor.editing.view.document.on(
"enter",
(event, data) => {
// disable entering new line - see https://github.com/ckeditor/ckeditor5/issues/9422
data.preventDefault();
event.stop();
},
{ priority: "high" }
);
// disable spellcheck for attribute editor
this.textEditor.editing.view.change(writer => writer.setAttribute('spellcheck', 'false', this.textEditor.editing.view.document.getRoot()));
this.textEditor.editing.view.change((writer) => writer.setAttribute("spellcheck", "false", this.textEditor.editing.view.document.getRoot()));
}
dataChanged() {
@@ -390,8 +391,7 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
if (this.lastSavedContent === this.textEditor.getData()) {
this.$saveAttributesButton.fadeOut();
}
else {
} else {
this.$saveAttributesButton.fadeIn();
}
@@ -412,8 +412,7 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
try {
parsedAttrs = attributeParser.lexAndParse(this.getPreprocessedData(), true);
}
catch (e) {
} catch (e) {
// the input is incorrect because the user messed up with it and now needs to fix it manually
return null;
}
@@ -421,8 +420,7 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
let matchedAttr = null;
for (const attr of parsedAttrs) {
if (attr.startIndex && clickIndex > attr.startIndex &&
attr.endIndex && clickIndex <= attr.endIndex) {
if (attr.startIndex && clickIndex > attr.startIndex && attr.endIndex && clickIndex <= attr.endIndex) {
matchedAttr = attr;
break;
}
@@ -430,7 +428,7 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
setTimeout(() => {
if (matchedAttr) {
this.$editor.tooltip('hide');
this.$editor.tooltip("hide");
this.attributeDetailWidget.showAttributeDetail({
allAttributes: parsedAttrs,
@@ -439,13 +437,11 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
x: e.pageX,
y: e.pageY
});
}
else {
} else {
this.showHelpTooltip();
}
}, 100);
}
else {
} else {
this.showHelpTooltip();
}
}
@@ -454,14 +450,14 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
this.attributeDetailWidget.hide();
this.$editor.tooltip({
trigger: 'focus',
trigger: "focus",
html: true,
title: HELP_TEXT,
placement: 'bottom',
placement: "bottom",
offset: "0,30"
});
this.$editor.tooltip('show');
this.$editor.tooltip("show");
}
getClickIndex(pos: TextPosition) {
@@ -472,8 +468,8 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
while (curNode.previousSibling) {
curNode = curNode.previousSibling;
if (curNode.name === 'reference') {
clickIndex += curNode._attrs.get('notePath').length + 1;
if (curNode.name === "reference") {
clickIndex += curNode._attrs.get("notePath").length + 1;
} else {
clickIndex += curNode.data.length;
}
@@ -483,9 +479,9 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
}
async loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string) {
const {noteId} = linkService.parseNavigationStateFromUrl(href);
const { noteId } = linkService.parseNavigationStateFromUrl(href);
const note = noteId ? await froca.getNote(noteId, true) : null;
const title = note ? note.title : '[missing]';
const title = note ? note.title : "[missing]";
$el.text(title);
}
@@ -530,19 +526,18 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
}
focus() {
this.$editor.trigger('focus');
this.$editor.trigger("focus");
this.textEditor.model.change( writer => {
const positionAt = writer.createPositionAt(this.textEditor.model.document.getRoot(), 'end');
this.textEditor.model.change((writer) => {
const positionAt = writer.createPositionAt(this.textEditor.model.document.getRoot(), "end");
writer.setSelection(positionAt);
} );
});
}
entitiesReloadedEvent({loadResults}: EventData<"entitiesReloaded">) {
if (loadResults.getAttributeRows(this.componentId).find(attr => attributeService.isAffecting(attr, this.note))) {
entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) {
if (loadResults.getAttributeRows(this.componentId).find((attr) => attributeService.isAffecting(attr, this.note))) {
this.refresh();
}
}
}