| 
									
										
										
										
											2024-07-29 10:14:27 +08:00
										 |  |  | import { t } from "../../services/i18n.js"; | 
					
						
							| 
									
										
										
										
											2021-05-22 12:35:41 +02:00
										 |  |  | import NoteContextAwareWidget from "../note_context_aware_widget.js"; | 
					
						
							| 
									
										
										
										
											2020-11-26 23:00:27 +01:00
										 |  |  | import noteAutocompleteService from "../../services/note_autocomplete.js"; | 
					
						
							|  |  |  | import server from "../../services/server.js"; | 
					
						
							| 
									
										
										
										
											2022-08-05 16:44:26 +02:00
										 |  |  | import contextMenuService from "../../menus/context_menu.js"; | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | import attributeParser, { Attribute } from "../../services/attribute_parser.js"; | 
					
						
							| 
									
										
										
										
											2020-11-26 23:00:27 +01:00
										 |  |  | import libraryLoader from "../../services/library_loader.js"; | 
					
						
							| 
									
										
										
										
											2021-04-16 23:01:56 +02:00
										 |  |  | import froca from "../../services/froca.js"; | 
					
						
							| 
									
										
										
										
											2020-11-26 23:00:27 +01:00
										 |  |  | import attributeRenderer from "../../services/attribute_renderer.js"; | 
					
						
							|  |  |  | import noteCreateService from "../../services/note_create.js"; | 
					
						
							| 
									
										
										
										
											2021-08-25 22:49:24 +02:00
										 |  |  | import attributeService from "../../services/attributes.js"; | 
					
						
							| 
									
										
										
										
											2023-05-29 00:19:54 +02:00
										 |  |  | import linkService from "../../services/link.js"; | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | import AttributeDetailWidget from "./attribute_detail.js"; | 
					
						
							|  |  |  | import { CommandData, EventData, EventListener, FilteredCommandNames } from "../../components/app_context.js"; | 
					
						
							|  |  |  | import FAttribute, { AttributeType } from "../../entities/fattribute.js"; | 
					
						
							|  |  |  | import FNote from "../../entities/fnote.js"; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  | const HELP_TEXT = `
 | 
					
						
							| 
									
										
										
										
											2024-07-29 10:14:27 +08:00
										 |  |  | <p>${t("attribute_editor.help_text_body1")}</p> | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-29 10:14:27 +08:00
										 |  |  | <p>${t("attribute_editor.help_text_body2")}</p> | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-29 10:14:27 +08:00
										 |  |  | <p>${t("attribute_editor.help_text_body3")}</p>`;
 | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | const TPL = `
 | 
					
						
							| 
									
										
										
										
											2020-10-31 22:47:15 +01:00
										 |  |  | <div style="position: relative; padding-top: 10px; padding-bottom: 10px"> | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     <style> | 
					
						
							|  |  |  |     .attribute-list-editor { | 
					
						
							|  |  |  |         border: 0 !important; | 
					
						
							|  |  |  |         outline: 0 !important; | 
					
						
							|  |  |  |         box-shadow: none !important; | 
					
						
							|  |  |  |         padding: 0 0 0 5px !important; | 
					
						
							|  |  |  |         margin: 0 !important; | 
					
						
							| 
									
										
										
										
											2020-07-23 00:19:50 +02:00
										 |  |  |         max-height: 100px; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         overflow: auto; | 
					
						
							| 
									
										
										
										
											2020-09-14 21:07:00 +02:00
										 |  |  |         transition: opacity .1s linear; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-29 23:29:14 +02:00
										 |  |  |     .attribute-list-editor.ck-content .mention { | 
					
						
							|  |  |  |         color: var(--muted-text-color) !important; | 
					
						
							|  |  |  |         background: transparent !important; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     .save-attributes-button { | 
					
						
							|  |  |  |         color: var(--muted-text-color); | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         position: absolute; | 
					
						
							| 
									
										
										
										
											2020-11-19 23:02:25 +01:00
										 |  |  |         bottom: 14px; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         right: 25px; | 
					
						
							|  |  |  |         cursor: pointer; | 
					
						
							|  |  |  |         border: 1px solid transparent; | 
					
						
							|  |  |  |         font-size: 130%; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     .add-new-attribute-button { | 
					
						
							|  |  |  |         color: var(--muted-text-color); | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         position: absolute; | 
					
						
							| 
									
										
										
										
											2020-11-19 23:02:25 +01:00
										 |  |  |         bottom: 13px; | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         right: 0; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         cursor: pointer; | 
					
						
							|  |  |  |         border: 1px solid transparent; | 
					
						
							|  |  |  |         font-size: 130%; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     .add-new-attribute-button:hover, .save-attributes-button:hover { | 
					
						
							| 
									
										
										
										
											2022-09-18 13:52:19 +02:00
										 |  |  |         border: 1px solid var(--button-border-color); | 
					
						
							|  |  |  |         border-radius: var(--button-border-radius); | 
					
						
							|  |  |  |         background: var(--button-background-color); | 
					
						
							|  |  |  |         color: var(--button-text-color); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |     .attribute-errors { | 
					
						
							|  |  |  |         color: red; | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  |         padding: 5px 50px 0px 5px; /* large right padding to avoid buttons */ | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     </style> | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     <div class="attribute-list-editor" tabindex="200"></div> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-29 10:14:27 +08:00
										 |  |  |     <div class="bx bx-save save-attributes-button" title="${t("attribute_editor.save_attributes")}"></div> | 
					
						
							|  |  |  |     <div class="bx bx-plus add-new-attribute-button" title="${t("attribute_editor.add_a_new_attribute")}"></div> | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |     <div class="attribute-errors" style="display: none;"></div> | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | </div> | 
					
						
							|  |  |  | `;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | const mentionSetup: MentionConfig = { | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     feeds: [ | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             marker: "@", | 
					
						
							|  |  |  |             feed: (queryText) => noteAutocompleteService.autocompleteSourceForCKEditor(queryText), | 
					
						
							|  |  |  |             itemRenderer: (item) => { | 
					
						
							|  |  |  |                 const itemElement = document.createElement("button"); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 itemElement.innerHTML = `${item.highlightedNotePathTitle} `; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 return itemElement; | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             minimumCharacters: 0 | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             marker: "#", | 
					
						
							|  |  |  |             feed: async (queryText) => { | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |                 const names = await server.get<string[]>(`attribute-names/?type=label&query=${encodeURIComponent(queryText)}`); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                 return names.map((name) => { | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |                     return { | 
					
						
							| 
									
										
										
										
											2022-12-21 15:19:05 +01:00
										 |  |  |                         id: `#${name}`, | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |                         name: name | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                     }; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |                 }); | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-06-29 11:44:28 +02:00
										 |  |  |             minimumCharacters: 0 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         }, | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             marker: "~", | 
					
						
							|  |  |  |             feed: async (queryText) => { | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |                 const names = await server.get<string[]>(`attribute-names/?type=relation&query=${encodeURIComponent(queryText)}`); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                 return names.map((name) => { | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |                     return { | 
					
						
							| 
									
										
										
										
											2022-12-21 15:19:05 +01:00
										 |  |  |                         id: `~${name}`, | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |                         name: name | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                     }; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |                 }); | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2023-06-29 11:44:28 +02:00
										 |  |  |             minimumCharacters: 0 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const editorConfig = { | 
					
						
							|  |  |  |     removePlugins: [ | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         "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" | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     ], | 
					
						
							|  |  |  |     toolbar: { | 
					
						
							|  |  |  |         items: [] | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2024-09-14 14:44:32 +03:00
										 |  |  |     placeholder: t("attribute_editor.placeholder"), | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     mention: mentionSetup | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  | type AttributeCommandNames = FilteredCommandNames<CommandData>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  | export default class AttributeEditorWidget extends NoteContextAwareWidget implements EventListener<"entitiesReloaded">, EventListener<"addNewLabel">, EventListener<"addNewRelation"> { | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     private attributeDetailWidget: AttributeDetailWidget; | 
					
						
							|  |  |  |     private $editor!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $addNewAttributeButton!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $saveAttributesButton!: JQuery<HTMLElement>; | 
					
						
							|  |  |  |     private $errors!: JQuery<HTMLElement>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private textEditor!: TextEditor; | 
					
						
							|  |  |  |     private lastUpdatedNoteId!: string | undefined; | 
					
						
							|  |  |  |     private lastSavedContent!: string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     constructor(attributeDetailWidget: AttributeDetailWidget) { | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |         super(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.attributeDetailWidget = attributeDetailWidget; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     doRender() { | 
					
						
							|  |  |  |         this.$widget = $(TPL); | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$editor = this.$widget.find(".attribute-list-editor"); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.initialized = this.initEditor(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$editor.on("keydown", async (e) => { | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  |             if (e.which === 13) { | 
					
						
							| 
									
										
										
										
											2021-10-30 15:22:20 +02:00
										 |  |  |                 // allow autocomplete to fill the result textarea
 | 
					
						
							|  |  |  |                 setTimeout(() => this.save(), 100); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             this.attributeDetailWidget.hide(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$editor.on("blur", () => setTimeout(() => this.save(), 100)); // Timeout to fix https://github.com/zadam/trilium/issues/4160
 | 
					
						
							| 
									
										
										
										
											2020-07-18 00:20:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$addNewAttributeButton = this.$widget.find(".add-new-attribute-button"); | 
					
						
							|  |  |  |         this.$addNewAttributeButton.on("click", (e) => this.addNewAttribute(e)); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$saveAttributesButton = this.$widget.find(".save-attributes-button"); | 
					
						
							|  |  |  |         this.$saveAttributesButton.on("click", () => this.save()); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$errors = this.$widget.find(".attribute-errors"); | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     addNewAttribute(e: JQuery.ClickEvent) { | 
					
						
							|  |  |  |         contextMenuService.show<AttributeCommandNames>({ | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |             x: e.pageX, | 
					
						
							|  |  |  |             y: e.pageY, | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             orientation: "left", | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |             items: [ | 
					
						
							| 
									
										
										
										
											2024-07-29 10:14:27 +08:00
										 |  |  |                 { 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" }, | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                 { title: t("attribute_editor.add_new_relation_definition"), command: "addNewRelationDefinition", uiIcon: "bx bx-empty" } | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |             ], | 
					
						
							| 
									
										
										
										
											2024-07-29 10:14:27 +08:00
										 |  |  |             selectMenuItemHandler: ({ command }) => this.handleAddNewAttributeCommand(command) | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-01 23:18:28 +02:00
										 |  |  |     // triggered from keyboard shortcut
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     async addNewLabelEvent({ ntxId }: EventData<"addNewLabel">) { | 
					
						
							| 
									
										
										
										
											2021-05-22 12:42:34 +02:00
										 |  |  |         if (this.isNoteContext(ntxId)) { | 
					
						
							| 
									
										
										
										
											2023-07-17 22:41:37 +02:00
										 |  |  |             await this.refresh(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             this.handleAddNewAttributeCommand("addNewLabel"); | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-01 23:18:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // triggered from keyboard shortcut
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     async addNewRelationEvent({ ntxId }: EventData<"addNewRelation">) { | 
					
						
							| 
									
										
										
										
											2021-05-22 12:42:34 +02:00
										 |  |  |         if (this.isNoteContext(ntxId)) { | 
					
						
							| 
									
										
										
										
											2023-07-17 22:41:37 +02:00
										 |  |  |             await this.refresh(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             this.handleAddNewAttributeCommand("addNewRelation"); | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-01 23:18:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     async handleAddNewAttributeCommand(command: AttributeCommandNames | undefined) { | 
					
						
							|  |  |  |         // TODO: Not sure what the relation between FAttribute[] and Attribute[] is.
 | 
					
						
							|  |  |  |         const attrs = this.parseAttributes() as FAttribute[]; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |         if (!attrs) { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         let type: AttributeType; | 
					
						
							|  |  |  |         let name; | 
					
						
							|  |  |  |         let value; | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         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"; | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         // TODO: Incomplete type
 | 
					
						
							|  |  |  |         //@ts-ignore
 | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |         attrs.push({ | 
					
						
							|  |  |  |             type, | 
					
						
							|  |  |  |             name, | 
					
						
							| 
									
										
										
										
											2020-07-18 23:45:28 +02:00
										 |  |  |             value, | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |             isInheritable: false | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 00:20:24 +02:00
										 |  |  |         await this.renderOwnedAttributes(attrs, false); | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.$editor.scrollTop(this.$editor[0].scrollHeight); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const rect = this.$editor[0].getBoundingClientRect(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         setTimeout(() => { | 
					
						
							|  |  |  |             // showing a little bit later because there's a conflict with outside click closing the attr detail
 | 
					
						
							|  |  |  |             this.attributeDetailWidget.showAttributeDetail({ | 
					
						
							|  |  |  |                 allAttributes: attrs, | 
					
						
							|  |  |  |                 attribute: attrs[attrs.length - 1], | 
					
						
							|  |  |  |                 isOwned: true, | 
					
						
							|  |  |  |                 x: (rect.left + rect.right) / 2, | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  |                 y: rect.bottom, | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                 focus: "name" | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |             }); | 
					
						
							|  |  |  |         }, 100); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     async save() { | 
					
						
							| 
									
										
										
										
											2022-08-26 22:02:40 +02:00
										 |  |  |         if (this.lastUpdatedNoteId !== this.noteId) { | 
					
						
							|  |  |  |             // https://github.com/zadam/trilium/issues/3090
 | 
					
						
							|  |  |  |             console.warn("Ignoring blur event because a different note is loaded."); | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         const attributes = this.parseAttributes(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (attributes) { | 
					
						
							|  |  |  |             await server.put(`notes/${this.noteId}/attributes`, attributes, this.componentId); | 
					
						
							| 
									
										
										
										
											2020-07-23 00:19:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             this.$saveAttributesButton.fadeOut(); | 
					
						
							| 
									
										
										
										
											2020-09-14 21:07:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-30 11:18:34 +02:00
										 |  |  |             // blink the attribute text to give a visual hint that save has been executed
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             this.$editor.css("opacity", 0); | 
					
						
							| 
									
										
										
										
											2020-09-14 21:07:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             // revert back
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             setTimeout(() => this.$editor.css("opacity", 1), 100); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     parseAttributes() { | 
					
						
							|  |  |  |         try { | 
					
						
							| 
									
										
										
										
											2023-05-29 00:19:54 +02:00
										 |  |  |             return attributeParser.lexAndParse(this.getPreprocessedData()); | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         } catch (e: any) { | 
					
						
							| 
									
										
										
										
											2020-08-17 23:54:18 +02:00
										 |  |  |             this.$errors.text(e.message).slideDown(); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 23:54:18 +02:00
										 |  |  |     getPreprocessedData() { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         const str = this.textEditor | 
					
						
							|  |  |  |             .getData() | 
					
						
							| 
									
										
										
										
											2022-11-28 23:39:23 +01:00
										 |  |  |             .replace(/<a[^>]+href="(#[A-Za-z0-9_/]*)"[^>]*>[^<]*<\/a>/g, "$1") | 
					
						
							| 
									
										
										
										
											2020-08-28 16:00:30 +02:00
										 |  |  |             .replace(/ /g, " "); // otherwise .text() below outputs non-breaking space in unicode
 | 
					
						
							| 
									
										
										
										
											2020-08-17 23:54:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return $("<div>").html(str).text(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     async initEditor() { | 
					
						
							| 
									
										
										
										
											2024-11-09 18:09:05 +02:00
										 |  |  |         await libraryLoader.requireLibrary(libraryLoader.CKEDITOR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$widget.show(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$editor.on("click", (e) => this.handleEditorClick(e)); | 
					
						
							| 
									
										
										
										
											2024-11-09 18:09:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         this.textEditor = await CKEditor.BalloonEditor.create(this.$editor[0], editorConfig); | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         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" } | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2024-11-09 18:09:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // disable spellcheck for attribute editor
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.textEditor.editing.view.change((writer) => writer.setAttribute("spellcheck", "false", this.textEditor.editing.view.document.getRoot())); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dataChanged() { | 
					
						
							| 
									
										
										
										
											2022-08-26 22:02:40 +02:00
										 |  |  |         this.lastUpdatedNoteId = this.noteId; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |         if (this.lastSavedContent === this.textEditor.getData()) { | 
					
						
							|  |  |  |             this.$saveAttributesButton.fadeOut(); | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |             this.$saveAttributesButton.fadeIn(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this.$errors.is(":visible")) { | 
					
						
							| 
									
										
										
										
											2020-09-01 23:43:09 +02:00
										 |  |  |             // using .hide() instead of .slideUp() since this will also hide the error after confirming
 | 
					
						
							|  |  |  |             // mention for relation name which suits up. When using.slideUp() error will appear and the slideUp which is weird
 | 
					
						
							|  |  |  |             this.$errors.hide(); | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     async handleEditorClick(e: JQuery.ClickEvent) { | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         const pos = this.textEditor.model.document.selection.getFirstPosition(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  |         if (pos && pos.textNode && pos.textNode.data) { | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |             const clickIndex = this.getClickIndex(pos); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |             let parsedAttrs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             try { | 
					
						
							| 
									
										
										
										
											2023-05-29 00:19:54 +02:00
										 |  |  |                 parsedAttrs = attributeParser.lexAndParse(this.getPreprocessedData(), true); | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             } catch (e) { | 
					
						
							| 
									
										
										
										
											2023-06-30 11:18:34 +02:00
										 |  |  |                 // the input is incorrect because the user messed up with it and now needs to fix it manually
 | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  |                 return null; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             let matchedAttr = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (const attr of parsedAttrs) { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                 if (attr.startIndex && clickIndex > attr.startIndex && attr.endIndex && clickIndex <= attr.endIndex) { | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |                     matchedAttr = attr; | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-17 23:54:18 +02:00
										 |  |  |             setTimeout(() => { | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  |                 if (matchedAttr) { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                     this.$editor.tooltip("hide"); | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     this.attributeDetailWidget.showAttributeDetail({ | 
					
						
							|  |  |  |                         allAttributes: parsedAttrs, | 
					
						
							|  |  |  |                         attribute: matchedAttr, | 
					
						
							|  |  |  |                         isOwned: true, | 
					
						
							|  |  |  |                         x: e.pageX, | 
					
						
							|  |  |  |                         y: e.pageY | 
					
						
							|  |  |  |                     }); | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |                 } else { | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  |                     this.showHelpTooltip(); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-17 23:54:18 +02:00
										 |  |  |             }, 100); | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  |             this.showHelpTooltip(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-28 22:52:57 +02:00
										 |  |  |     showHelpTooltip() { | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  |         this.attributeDetailWidget.hide(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.$editor.tooltip({ | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             trigger: "focus", | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  |             html: true, | 
					
						
							|  |  |  |             title: HELP_TEXT, | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             placement: "bottom", | 
					
						
							| 
									
										
										
										
											2020-09-01 22:47:36 +02:00
										 |  |  |             offset: "0,30" | 
					
						
							| 
									
										
										
										
											2020-08-21 23:08:53 +02:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-09-01 23:47:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$editor.tooltip("show"); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     getClickIndex(pos: TextPosition) { | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |         let clickIndex = pos.offset - pos.textNode.startOffset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         let curNode = pos.textNode; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         while (curNode.previousSibling) { | 
					
						
							|  |  |  |             curNode = curNode.previousSibling; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |             if (curNode.name === "reference") { | 
					
						
							|  |  |  |                 clickIndex += curNode._attrs.get("notePath").length + 1; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |             } else { | 
					
						
							|  |  |  |                 clickIndex += curNode.data.length; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return clickIndex; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     async loadReferenceLinkTitle($el: JQuery<HTMLElement>, href: string) { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         const { noteId } = linkService.parseNavigationStateFromUrl(href); | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         const note = noteId ? await froca.getNote(noteId, true) : null; | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         const title = note ? note.title : "[missing]"; | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         $el.text(title); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     async refreshWithNote(note: FNote) { | 
					
						
							| 
									
										
										
										
											2020-07-18 00:20:24 +02:00
										 |  |  |         await this.renderOwnedAttributes(note.getOwnedAttributes(), true); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     async renderOwnedAttributes(ownedAttributes: FAttribute[], saved: boolean) { | 
					
						
							| 
									
										
										
										
											2023-06-29 12:19:01 +02:00
										 |  |  |         // attrs are not resorted if position changes after the initial load
 | 
					
						
							| 
									
										
										
										
											2023-11-03 01:11:47 +01:00
										 |  |  |         ownedAttributes.sort((a, b) => a.position - b.position); | 
					
						
							| 
									
										
										
										
											2020-09-04 23:35:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-08 21:45:07 +02:00
										 |  |  |         let htmlAttrs = (await attributeRenderer.renderAttributes(ownedAttributes, true)).html(); | 
					
						
							| 
									
										
										
										
											2020-09-03 22:37:51 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (htmlAttrs.length > 0) { | 
					
						
							|  |  |  |             htmlAttrs += " "; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         this.textEditor.setData(htmlAttrs); | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 00:20:24 +02:00
										 |  |  |         if (saved) { | 
					
						
							|  |  |  |             this.lastSavedContent = this.textEditor.getData(); | 
					
						
							| 
									
										
										
										
											2020-07-17 23:55:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-18 00:20:24 +02:00
										 |  |  |             this.$saveAttributesButton.fadeOut(0); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     async createNoteForReferenceLink(title: string) { | 
					
						
							|  |  |  |         let result; | 
					
						
							|  |  |  |         if (this.notePath) { | 
					
						
							|  |  |  |             result = await noteCreateService.createNoteWithTypePrompt(this.notePath, { | 
					
						
							|  |  |  |                 activate: false, | 
					
						
							|  |  |  |                 title: title | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-21 22:08:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |         return result?.note?.getBestNotePathString(); | 
					
						
							| 
									
										
										
										
											2020-09-21 22:08:54 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-22 21:59:08 +02:00
										 |  |  |     async updateAttributeList(attributes: FAttribute[]) { | 
					
						
							| 
									
										
										
										
											2020-09-21 23:08:39 +02:00
										 |  |  |         await this.renderOwnedAttributes(attributes, false); | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-12 00:02:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 20:24:58 +01:00
										 |  |  |     focus() { | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.$editor.trigger("focus"); | 
					
						
							| 
									
										
										
										
											2022-02-01 20:24:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         this.textEditor.model.change((writer) => { | 
					
						
							|  |  |  |             const positionAt = writer.createPositionAt(this.textEditor.model.document.getRoot(), "end"); | 
					
						
							| 
									
										
										
										
											2022-02-01 20:24:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             writer.setSelection(positionAt); | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2022-02-01 20:24:58 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-09 18:07:02 +02:00
										 |  |  |     entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { | 
					
						
							|  |  |  |         if (loadResults.getAttributeRows(this.componentId).find((attr) => attributeService.isAffecting(attr, this.note))) { | 
					
						
							| 
									
										
										
										
											2020-08-12 00:02:19 +02:00
										 |  |  |             this.refresh(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-17 00:08:28 +02:00
										 |  |  | } |