mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	removed note detail service
This commit is contained in:
		
							parent
							
								
									96e2b9bc18
								
							
						
					
					
						commit
						3cd4be4e48
					
				| @ -2,7 +2,6 @@ import cloning from './services/cloning.js'; | |||||||
| import contextMenu from './services/tree_context_menu.js'; | import contextMenu from './services/tree_context_menu.js'; | ||||||
| import link from './services/link.js'; | import link from './services/link.js'; | ||||||
| import ws from './services/ws.js'; | import ws from './services/ws.js'; | ||||||
| import noteDetailService from './services/note_detail.js'; |  | ||||||
| import noteType from './widgets/note_type.js'; | import noteType from './widgets/note_type.js'; | ||||||
| import protectedSessionService from './services/protected_session.js'; | import protectedSessionService from './services/protected_session.js'; | ||||||
| import protectedSessionHolder from './services/protected_session_holder.js'; | import protectedSessionHolder from './services/protected_session_holder.js'; | ||||||
| @ -55,7 +54,13 @@ window.glob.loadIncludedNote = async (noteId, el) => { | |||||||
|     } |     } | ||||||
| }; | }; | ||||||
| // this is required by CKEditor when uploading images
 | // this is required by CKEditor when uploading images
 | ||||||
| window.glob.noteChanged = noteDetailService.noteChanged; | window.glob.noteChanged = () => { | ||||||
|  |     const activeTabContext = appContext.getActiveTabContext(); | ||||||
|  | 
 | ||||||
|  |     if (activeTabContext) { | ||||||
|  |         activeTabContext.noteChanged(); | ||||||
|  |     } | ||||||
|  | }; | ||||||
| window.glob.refreshTree = treeService.reload; | window.glob.refreshTree = treeService.reload; | ||||||
| 
 | 
 | ||||||
| // required for ESLint plugin
 | // required for ESLint plugin
 | ||||||
|  | |||||||
| @ -1,5 +1,3 @@ | |||||||
| import linkService from '../services/link.js'; |  | ||||||
| import noteDetailService from '../services/note_detail.js'; |  | ||||||
| import treeService from '../services/tree.js'; | import treeService from '../services/tree.js'; | ||||||
| import noteAutocompleteService from "../services/note_autocomplete.js"; | import noteAutocompleteService from "../services/note_autocomplete.js"; | ||||||
| import utils from "../services/utils.js"; | import utils from "../services/utils.js"; | ||||||
| @ -55,21 +53,12 @@ $form.on('submit', () => { | |||||||
|     const notePath = $autoComplete.getSelectedPath(); |     const notePath = $autoComplete.getSelectedPath(); | ||||||
| 
 | 
 | ||||||
|     if (notePath) { |     if (notePath) { | ||||||
|         const linkTitle = $linkTitle.val(); |  | ||||||
| 
 |  | ||||||
|         $dialog.modal('hide'); |         $dialog.modal('hide'); | ||||||
| 
 | 
 | ||||||
|         const linkHref = '#' + notePath; |         appContext.trigger(`addLinkToActiveEditor`, { | ||||||
|         const editor = noteDetailService.getActiveEditor(); |             linkTitle: $linkTitle.val(), | ||||||
| 
 |             linkHref: '#' + notePath | ||||||
|         if (hasSelection()) { |         }); | ||||||
|             editor.execute('link', linkHref); |  | ||||||
|         } |  | ||||||
|         else { |  | ||||||
|             linkService.addLinkToEditor(linkTitle, linkHref); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         editor.editing.view.focus(); |  | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         console.error("No path to add link."); |         console.error("No path to add link."); | ||||||
| @ -77,11 +66,3 @@ $form.on('submit', () => { | |||||||
| 
 | 
 | ||||||
|     return false; |     return false; | ||||||
| }); | }); | ||||||
| 
 |  | ||||||
| // returns true if user selected some text, false if there's no selection
 |  | ||||||
| function hasSelection() { |  | ||||||
|     const model = noteDetailService.getActiveEditor().model; |  | ||||||
|     const selection = model.document.selection; |  | ||||||
| 
 |  | ||||||
|     return !selection.isCollapsed; |  | ||||||
| } |  | ||||||
| @ -1,7 +1,6 @@ | |||||||
| import libraryLoader from "../services/library_loader.js"; | import libraryLoader from "../services/library_loader.js"; | ||||||
| import toastService from "../services/toast.js"; | import toastService from "../services/toast.js"; | ||||||
| import utils from "../services/utils.js"; | import utils from "../services/utils.js"; | ||||||
| import noteDetailService from "../services/note_detail.js"; |  | ||||||
| import appContext from "../services/app_context.js"; | import appContext from "../services/app_context.js"; | ||||||
| 
 | 
 | ||||||
| const $dialog = $('#markdown-import-dialog'); | const $dialog = $('#markdown-import-dialog'); | ||||||
| @ -17,13 +16,16 @@ async function convertMarkdownToHtml(text) { | |||||||
| 
 | 
 | ||||||
|     const result = writer.render(parsed); |     const result = writer.render(parsed); | ||||||
| 
 | 
 | ||||||
|     const textEditor = noteDetailService.getActiveEditor(); |     appContext.trigger('executeInActiveEditor', { | ||||||
|     const viewFragment = textEditor.data.processor.toView(result); |         callback: textEditor => { | ||||||
|     const modelFragment = textEditor.data.toModel(viewFragment); |             const viewFragment = textEditor.data.processor.toView(result); | ||||||
|  |             const modelFragment = textEditor.data.toModel(viewFragment); | ||||||
| 
 | 
 | ||||||
|     textEditor.model.insertContent(modelFragment, textEditor.model.document.selection); |             textEditor.model.insertContent(modelFragment, textEditor.model.document.selection); | ||||||
| 
 | 
 | ||||||
|     toastService.showMessage("Markdown content has been imported into the document."); |             toastService.showMessage("Markdown content has been imported into the document."); | ||||||
|  |         } | ||||||
|  |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export async function importMarkdownInline() { | export async function importMarkdownInline() { | ||||||
|  | |||||||
| @ -401,4 +401,9 @@ class AppContext { | |||||||
| 
 | 
 | ||||||
| const appContext = new AppContext(); | const appContext = new AppContext(); | ||||||
| 
 | 
 | ||||||
|  | // we should save all outstanding changes before the page/app is closed
 | ||||||
|  | $(window).on('beforeunload', () => { | ||||||
|  |     appContext.trigger('beforeUnload'); | ||||||
|  | }); | ||||||
|  | 
 | ||||||
| export default appContext; | export default appContext; | ||||||
| @ -4,7 +4,6 @@ import server from './server.js'; | |||||||
| import toastService from "./toast.js"; | import toastService from "./toast.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| import hoistedNoteService from "./hoisted_note.js"; | import hoistedNoteService from "./hoisted_note.js"; | ||||||
| import noteDetailService from "./note_detail.js"; |  | ||||||
| import ws from "./ws.js"; | import ws from "./ws.js"; | ||||||
| import appContext from "./app_context.js"; | import appContext from "./app_context.js"; | ||||||
| 
 | 
 | ||||||
| @ -134,12 +133,14 @@ async function deleteNodes(branchIdsToDelete) { | |||||||
|         if (deleteClones) { |         if (deleteClones) { | ||||||
|             await server.remove(`notes/${branch.noteId}` + query); |             await server.remove(`notes/${branch.noteId}` + query); | ||||||
| 
 | 
 | ||||||
|  |             // FIXME
 | ||||||
|             noteDetailService.noteDeleted(branch.noteId); |             noteDetailService.noteDeleted(branch.noteId); | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|             const {noteDeleted} = await server.remove(`branches/${branchIdToDelete}` + query); |             const {noteDeleted} = await server.remove(`branches/${branchIdToDelete}` + query); | ||||||
| 
 | 
 | ||||||
|             if (noteDeleted) { |             if (noteDeleted) { | ||||||
|  |                 // FIXME
 | ||||||
|                 noteDetailService.noteDeleted(branch.noteId); |                 noteDetailService.noteDeleted(branch.noteId); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ import utils from "./utils.js"; | |||||||
| import zoomService from "./zoom.js"; | import zoomService from "./zoom.js"; | ||||||
| import treeService from "./tree.js"; | import treeService from "./tree.js"; | ||||||
| import dateNoteService from "./date_notes.js"; | import dateNoteService from "./date_notes.js"; | ||||||
| import noteDetailService from "./note_detail.js"; |  | ||||||
| import hoistedNoteService from "./hoisted_note.js"; | import hoistedNoteService from "./hoisted_note.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
| @ -82,7 +81,7 @@ export default class Entrypoints extends Component { | |||||||
|         appContext.activateTab(tabContext.tabId); |         appContext.activateTab(tabContext.tabId); | ||||||
|         await tabContext.setNote(note.noteId); |         await tabContext.setNote(note.noteId); | ||||||
| 
 | 
 | ||||||
|         noteDetailService.focusAndSelectTitle(); |         appContext.trigger('focusAndSelectTitle'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     toggleNoteHoistingListener() { |     toggleNoteHoistingListener() { | ||||||
|  | |||||||
| @ -4,7 +4,6 @@ import utils from './utils.js'; | |||||||
| import toastService from './toast.js'; | import toastService from './toast.js'; | ||||||
| import linkService from './link.js'; | import linkService from './link.js'; | ||||||
| import treeCache from './tree_cache.js'; | import treeCache from './tree_cache.js'; | ||||||
| import noteDetailService from './note_detail.js'; |  | ||||||
| import noteTooltipService from './note_tooltip.js'; | import noteTooltipService from './note_tooltip.js'; | ||||||
| import protectedSessionService from './protected_session.js'; | import protectedSessionService from './protected_session.js'; | ||||||
| import dateNotesService from './date_notes.js'; | import dateNotesService from './date_notes.js'; | ||||||
| @ -67,7 +66,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte | |||||||
|     this.activateNewNote = async notePath => { |     this.activateNewNote = async notePath => { | ||||||
|         await ws.waitForMaxKnownSyncId(); |         await ws.waitForMaxKnownSyncId(); | ||||||
| 
 | 
 | ||||||
|         await treeService.activateNote(notePath, noteDetailService.focusAndSelectTitle); |         await treeService.activateNote(notePath, () => appContext.trigger('focusAndSelectTitle')); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
| @ -285,7 +284,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte | |||||||
|      * @param {string} text - this must be clear text, HTML is not supported. |      * @param {string} text - this must be clear text, HTML is not supported. | ||||||
|      * @method |      * @method | ||||||
|      */ |      */ | ||||||
|     this.addTextToActiveTabEditor = linkService.addTextToEditor; |     this.addTextToActiveTabEditor = text => appContext.trigger('addTextToActiveEditor', {text}); | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * @method |      * @method | ||||||
| @ -297,9 +296,9 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte | |||||||
|      * See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
 |      * See https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html for a documentation on the returned instance.
 | ||||||
|      * |      * | ||||||
|      * @method |      * @method | ||||||
|      * @returns {Editor|null} CKEditor instance or null (e.g. if active note is not a text note) |      * @param callback - method receiving "textEditor" instance | ||||||
|      */ |      */ | ||||||
|     this.getActiveTabTextEditor = noteDetailService.getActiveEditor; |     this.getActiveTabTextEditor = callback => appContext.trigger('executeInActiveEditor', {callback}); | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * @method |      * @method | ||||||
| @ -320,12 +319,6 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte | |||||||
|         return tabContext.note && this.originEntity.noteId === tabContext.note.noteId; |         return tabContext.note && this.originEntity.noteId === tabContext.note.noteId; | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * @method |  | ||||||
|      * @param {function} func - callback called on note change as user is typing (not necessarily tied to save event) |  | ||||||
|      */ |  | ||||||
|     this.onNoteChange = noteDetailService.onNoteChange; |  | ||||||
| 
 |  | ||||||
|     /** |     /** | ||||||
|      * @method |      * @method | ||||||
|      * @param {object} $el - jquery object on which to setup the tooltip |      * @param {object} $el - jquery object on which to setup the tooltip | ||||||
|  | |||||||
| @ -1,7 +1,5 @@ | |||||||
| import optionsService from './options.js'; | import optionsService from './options.js'; | ||||||
| import server from "./server.js"; | import server from "./server.js"; | ||||||
| import tree from "./tree.js"; |  | ||||||
| import noteDetailService from "./note_detail.js"; |  | ||||||
| import appContext from "./app_context.js"; | import appContext from "./app_context.js"; | ||||||
| 
 | 
 | ||||||
| let hoistedNoteId = 'root'; | let hoistedNoteId = 'root'; | ||||||
|  | |||||||
| @ -11,32 +11,6 @@ function getActiveEditor() { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function focusOnTitle() { |  | ||||||
|     appContext.trigger('focusOnTitle'); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function focusAndSelectTitle() { |  | ||||||
|     appContext.trigger('focusAndSelectTitle'); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function noteChanged() { |  | ||||||
|     const activeTabContext = appContext.getActiveTabContext(); |  | ||||||
| 
 |  | ||||||
|     if (activeTabContext) { |  | ||||||
|         activeTabContext.noteChanged(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
 |  | ||||||
| // this sends the request asynchronously and doesn't wait for result
 |  | ||||||
| // FIXME
 |  | ||||||
| $(window).on('beforeunload', () => { |  | ||||||
|     //saveNotesIfChanged();
 |  | ||||||
|  }); |  | ||||||
| 
 |  | ||||||
| export default { | export default { | ||||||
|     focusOnTitle, |     getActiveEditor | ||||||
|     focusAndSelectTitle, |  | ||||||
|     getActiveEditor, |  | ||||||
|     noteChanged |  | ||||||
| }; | }; | ||||||
| @ -1,7 +1,5 @@ | |||||||
| import noteDetailService from "./note_detail.js"; |  | ||||||
| import treeService from "./tree.js"; | import treeService from "./tree.js"; | ||||||
| import linkService from "./link.js"; | import linkService from "./link.js"; | ||||||
| import server from "./server.js"; |  | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| 
 | 
 | ||||||
| function setupGlobalTooltip() { | function setupGlobalTooltip() { | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| import treeService from './tree.js'; | import treeService from './tree.js'; | ||||||
| import noteDetailService from './note_detail.js'; |  | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
| import protectedSessionHolder from './protected_session_holder.js'; | import protectedSessionHolder from './protected_session_holder.js'; | ||||||
| @ -82,8 +81,6 @@ async function protectNoteAndSendToServer() { | |||||||
|     await appContext.getActiveTabContext().saveNote(); |     await appContext.getActiveTabContext().saveNote(); | ||||||
| 
 | 
 | ||||||
|     treeService.setProtected(note.noteId, note.isProtected); |     treeService.setProtected(note.noteId, note.isProtected); | ||||||
| 
 |  | ||||||
|     await noteDetailService.reload(); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async function unprotectNoteAndSendToServer() { | async function unprotectNoteAndSendToServer() { | ||||||
|  | |||||||
| @ -5,7 +5,6 @@ import utils from "./utils.js"; | |||||||
| import optionsService from "./options.js"; | import optionsService from "./options.js"; | ||||||
| import appContext from "./app_context.js"; | import appContext from "./app_context.js"; | ||||||
| import treeService from "./tree.js"; | import treeService from "./tree.js"; | ||||||
| import noteDetailService from "./note_detail.js"; |  | ||||||
| import Component from "../widgets/component.js"; | import Component from "../widgets/component.js"; | ||||||
| import treeCache from "./tree_cache.js"; | import treeCache from "./tree_cache.js"; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| import ws from './ws.js'; | import ws from './ws.js'; | ||||||
| import noteDetailService from './note_detail.js'; |  | ||||||
| import protectedSessionHolder from './protected_session_holder.js'; | import protectedSessionHolder from './protected_session_holder.js'; | ||||||
| import utils from './utils.js'; | import utils from './utils.js'; | ||||||
| import server from './server.js'; | import server from './server.js'; | ||||||
| @ -69,6 +68,7 @@ async function activateNote(notePath, noteLoadedListener) { | |||||||
|     const node = await appContext.getMainNoteTree().expandToNote(notePath); |     const node = await appContext.getMainNoteTree().expandToNote(notePath); | ||||||
| 
 | 
 | ||||||
|     if (noteLoadedListener) { |     if (noteLoadedListener) { | ||||||
|  |         // FIXME
 | ||||||
|         noteDetailService.addDetailLoadedListener(node.data.noteId, noteLoadedListener); |         noteDetailService.addDetailLoadedListener(node.data.noteId, noteLoadedListener); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -340,7 +340,7 @@ async function createNote(node, parentNoteId, target, extraOptions = {}) { | |||||||
|         window.cutToNote.removeSelection(); |         window.cutToNote.removeSelection(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     noteDetailService.addDetailLoadedListener(note.noteId, noteDetailService.focusAndSelectTitle); |     noteDetailService.addDetailLoadedListener(note.noteId, () => appContext.trigger('focusAndSelectTitle')); | ||||||
| 
 | 
 | ||||||
|     const noteEntity = await treeCache.getNote(note.noteId); |     const noteEntity = await treeCache.getNote(note.noteId); | ||||||
|     const branchEntity = treeCache.getBranch(branch.branchId); |     const branchEntity = treeCache.getBranch(branch.branchId); | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| import noteDetailService from "./note_detail.js"; |  | ||||||
| import treeChangesService from "./branches.js"; | import treeChangesService from "./branches.js"; | ||||||
| import treeService from "./tree.js"; | import treeService from "./tree.js"; | ||||||
| import hoistedNoteService from "./hoisted_note.js"; | import hoistedNoteService from "./hoisted_note.js"; | ||||||
| import clipboard from "./clipboard.js"; | import clipboard from "./clipboard.js"; | ||||||
| import utils from "./utils.js"; | import utils from "./utils.js"; | ||||||
| import keyboardActionService from "./keyboard_actions.js"; | import keyboardActionService from "./keyboard_actions.js"; | ||||||
|  | import appContext from "./app_context.js"; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * @param {NoteTreeWidget} treeWidget |  * @param {NoteTreeWidget} treeWidget | ||||||
| @ -167,7 +167,7 @@ function getTemplates(treeWidget) { | |||||||
|             return false; |             return false; | ||||||
|         }, |         }, | ||||||
|         "EditNoteTitle": node => { |         "EditNoteTitle": node => { | ||||||
|             noteDetailService.focusOnTitle(); |             appContext.trigger('focusOnTitle'); | ||||||
| 
 | 
 | ||||||
|             return false; |             return false; | ||||||
|         }, |         }, | ||||||
|  | |||||||
| @ -4,7 +4,6 @@ import protectedSessionHolder from "../services/protected_session_holder.js"; | |||||||
| import SpacedUpdate from "../services/spaced_update.js"; | import SpacedUpdate from "../services/spaced_update.js"; | ||||||
| import server from "../services/server.js"; | import server from "../services/server.js"; | ||||||
| import libraryLoader from "../services/library_loader.js"; | import libraryLoader from "../services/library_loader.js"; | ||||||
| import noteDetailService from "../services/note_detail.js"; |  | ||||||
| 
 | 
 | ||||||
| const TPL = ` | const TPL = ` | ||||||
| <div class="note-detail"> | <div class="note-detail"> | ||||||
| @ -221,4 +220,8 @@ export default class NoteDetailWidget extends TabAwareWidget { | |||||||
|             this.refreshWithNote(this.note, this.notePath); |             this.refreshWithNote(this.note, this.notePath); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     beforeUnloadListener() { | ||||||
|  |         this.spacedUpdate.updateNowIfNecessary(); | ||||||
|  |     } | ||||||
| } | } | ||||||
| @ -102,4 +102,8 @@ export default class NoteTitleWidget extends TabAwareWidget { | |||||||
|                 .trigger('select'); |                 .trigger('select'); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     beforeUnloadListener() { | ||||||
|  |         this.spacedUpdate.updateNowIfNecessary(); | ||||||
|  |     } | ||||||
| } | } | ||||||
| @ -1,5 +1,3 @@ | |||||||
| import treeService from '../services/tree.js'; |  | ||||||
| import noteDetailService from '../services/note_detail.js'; |  | ||||||
| import server from '../services/server.js'; | import server from '../services/server.js'; | ||||||
| import mimeTypesService from '../services/mime_types.js'; | import mimeTypesService from '../services/mime_types.js'; | ||||||
| import TabAwareWidget from "./tab_aware_widget.js"; | import TabAwareWidget from "./tab_aware_widget.js"; | ||||||
| @ -128,8 +126,6 @@ export default class NoteTypeWidget extends TabAwareWidget { | |||||||
|             + '/type/' + encodeURIComponent(type) |             + '/type/' + encodeURIComponent(type) | ||||||
|             + '/mime/' + encodeURIComponent(mime)); |             + '/mime/' + encodeURIComponent(mime)); | ||||||
| 
 | 
 | ||||||
|         await noteDetailService.reload(); |  | ||||||
| 
 |  | ||||||
|         this.update(); |         this.update(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -2,7 +2,6 @@ import libraryLoader from "../../services/library_loader.js"; | |||||||
| import bundleService from "../../services/bundle.js"; | import bundleService from "../../services/bundle.js"; | ||||||
| import toastService from "../../services/toast.js"; | import toastService from "../../services/toast.js"; | ||||||
| import server from "../../services/server.js"; | import server from "../../services/server.js"; | ||||||
| import noteDetailService from "../../services/note_detail.js"; |  | ||||||
| import keyboardActionService from "../../services/keyboard_actions.js"; | import keyboardActionService from "../../services/keyboard_actions.js"; | ||||||
| import TypeWidget from "./type_widget.js"; | import TypeWidget from "./type_widget.js"; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| import utils from "../../services/utils.js"; | import utils from "../../services/utils.js"; | ||||||
| import server from "../../services/server.js"; | import server from "../../services/server.js"; | ||||||
| import toastService from "../../services/toast.js"; | import toastService from "../../services/toast.js"; | ||||||
| import noteDetailService from "../../services/note_detail.js"; |  | ||||||
| import TypeWidget from "./type_widget.js"; | import TypeWidget from "./type_widget.js"; | ||||||
| 
 | 
 | ||||||
| const TPL = ` | const TPL = ` | ||||||
| @ -107,7 +106,7 @@ export default class FileTypeWidget extends TypeWidget { | |||||||
|             if (result.uploaded) { |             if (result.uploaded) { | ||||||
|                 toastService.showMessage("New file revision has been uploaded."); |                 toastService.showMessage("New file revision has been uploaded."); | ||||||
| 
 | 
 | ||||||
|                 await noteDetailService.reload(); |                 // FIXME reload
 | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 toastService.showError("Upload of a new file revision failed."); |                 toastService.showError("Upload of a new file revision failed."); | ||||||
|  | |||||||
| @ -1,7 +1,6 @@ | |||||||
| import utils from "../../services/utils.js"; | import utils from "../../services/utils.js"; | ||||||
| import toastService from "../../services/toast.js"; | import toastService from "../../services/toast.js"; | ||||||
| import server from "../../services/server.js"; | import server from "../../services/server.js"; | ||||||
| import noteDetailService from "../../services/note_detail.js"; |  | ||||||
| import TypeWidget from "./type_widget.js"; | import TypeWidget from "./type_widget.js"; | ||||||
| 
 | 
 | ||||||
| const TPL = ` | const TPL = ` | ||||||
| @ -48,7 +47,7 @@ const TPL = ` | |||||||
|     <input type="file" class="image-upload-new-revision-input" style="display: none"> |     <input type="file" class="image-upload-new-revision-input" style="display: none"> | ||||||
| </div>`; | </div>`; | ||||||
| 
 | 
 | ||||||
| class NoteDetailImage extends TypeWidget { | class ImageTypeWidget extends TypeWidget { | ||||||
|     static getType() { return "image"; } |     static getType() { return "image"; } | ||||||
| 
 | 
 | ||||||
|     doRender() { |     doRender() { | ||||||
| @ -112,6 +111,7 @@ class NoteDetailImage extends TypeWidget { | |||||||
| 
 | 
 | ||||||
|                 await utils.clearBrowserCache(); |                 await utils.clearBrowserCache(); | ||||||
| 
 | 
 | ||||||
|  |                 // FIXME
 | ||||||
|                 await noteDetailService.reload(); |                 await noteDetailService.reload(); | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
| @ -160,4 +160,4 @@ class NoteDetailImage extends TypeWidget { | |||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default NoteDetailImage | export default ImageTypeWidget | ||||||
| @ -1,4 +1,3 @@ | |||||||
| import noteDetailService from "../../services/note_detail.js"; |  | ||||||
| import searchNotesService from "../../services/search_notes.js"; | import searchNotesService from "../../services/search_notes.js"; | ||||||
| import TypeWidget from "./type_widget.js"; | import TypeWidget from "./type_widget.js"; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -185,6 +185,10 @@ export default class TextTypeWidget extends TypeWidget { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     insertDateTimeToTextListener() { |     insertDateTimeToTextListener() { | ||||||
|  |         if (!this.isActive()) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         const date = new Date(); |         const date = new Date(); | ||||||
|         const dateString = utils.formatDateTime(date); |         const dateString = utils.formatDateTime(date); | ||||||
| 
 | 
 | ||||||
| @ -208,4 +212,47 @@ export default class TextTypeWidget extends TypeWidget { | |||||||
|             writer.insertText(text, insertPosition); |             writer.insertText(text, insertPosition); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     addTextToActiveEditorListener(text) { | ||||||
|  |         if (!this.isActive()) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         this.addTextToEditor(text); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async addLinkToActiveEditorListener({linkTitle, linkHref}) { | ||||||
|  |         if (!this.isActive()) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         await this.initialized; | ||||||
|  | 
 | ||||||
|  |         if (this.hasSelection()) { | ||||||
|  |             this.textEditor.execute('link', linkHref); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             await this.addLinkToEditor(linkTitle, linkHref); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         this.textEditor.editing.view.focus(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // returns true if user selected some text, false if there's no selection
 | ||||||
|  |     hasSelection() { | ||||||
|  |         const model = this.textEditor.model; | ||||||
|  |         const selection = model.document.selection; | ||||||
|  | 
 | ||||||
|  |         return !selection.isCollapsed; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async executeInActiveEditorListener({callback}) { | ||||||
|  |         if (!this.isActive()) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         await this.initialized; | ||||||
|  | 
 | ||||||
|  |         callback(this.textEditor); | ||||||
|  |     } | ||||||
| } | } | ||||||
| @ -24,4 +24,8 @@ export default class TypeWidget extends TabAwareWidget { | |||||||
| 
 | 
 | ||||||
|         this.doRefresh(note); |         this.doRefresh(note); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     isActive() { | ||||||
|  |         return this.$widget.is(":visible"); | ||||||
|  |     } | ||||||
| } | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam