Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.
TypeScript cloud-alternativecollaborationcollaborative-editingdropboxfile-serverfile-sharingfile-storagefile-syncfull-text-searchhomelabnextcloudon-premiseopen-sourceprivacy-firstprivate-cloudrealtimesecureself-hostedstorage-serverwebdav
perf(frontend): lazy-load file viewers and route components
johaven42d5d0ae8ae8
diff --git a/frontend/src/app/applications/favorites/favorites.routes.ts b/frontend/src/app/applications/favorites/favorites.routes.tsindex 0c774a24..21d4c565 100644--- a/frontend/src/app/applications/favorites/favorites.routes.ts+++ b/frontend/src/app/applications/favorites/favorites.routes.ts@@ -1,6 +1,11 @@import { Routes } from '@angular/router'import { noUserLinkGuard } from '../users/user.guards'-import { FavoritesComponent } from './components/favorites.component'import { FAVORITES_PATH } from './favorites.constants'-export const favoritesRoutes: Routes = [{ path: FAVORITES_PATH.BASE, component: FavoritesComponent, canActivate: [noUserLinkGuard] }]+export const favoritesRoutes: Routes = [+ {+ path: FAVORITES_PATH.BASE,+ loadComponent: () => import('./components/favorites.component').then((c) => c.FavoritesComponent),+ canActivate: [noUserLinkGuard]+ }+]diff --git a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.htmlindex e516c1b5..1fe3489a 100644--- a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html+++ b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.html@@ -14,50 +14,108 @@</div>@if (currentFile) {<div class="modal-body">+ <ng-template #viewerLoading>+ <div [style.height.px]="currentHeight" class="d-flex align-items-center justify-content-center" role="status">+ <span class="spinner-border text-primary" aria-hidden="true"></span>+ <span class="visually-hidden" l10nTranslate>Loading...</span>+ </div>+ </ng-template>+ <ng-template #viewerError>+ <div [style.height.px]="currentHeight" class="d-flex align-items-center justify-content-center p-4" l10nTranslate>Unable to open document</div>+ </ng-template>@switch (activeViewer()) {@case (SHORT_MIME.IMAGE) {- <app-files-viewer-image [currentHeight]="currentHeight" [(file)]="currentFile" [directoryImages]="directoryImages()"></app-files-viewer-image>+ @defer (on immediate) {+ <app-files-viewer-image [currentHeight]="currentHeight" [(file)]="currentFile" [directoryImages]="directoryImages()"></app-files-viewer-image>+ } @loading (after 100ms; minimum 200ms) {+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>+ } @error {+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>+ }}@case (SHORT_MIME.PDF) {- <app-files-viewer-pdf [currentHeight]="currentHeight" [file]="currentFile"></app-files-viewer-pdf>+ @defer (on immediate) {+ <app-files-viewer-pdf [currentHeight]="currentHeight" [file]="currentFile"></app-files-viewer-pdf>+ } @loading (after 100ms; minimum 200ms) {+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>+ } @error {+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>+ }}@case (SHORT_MIME.MEDIA) {- <app-files-viewer-media [currentHeight]="currentHeight" [file]="currentFile"></app-files-viewer-media>+ @defer (on immediate) {+ <app-files-viewer-media [currentHeight]="currentHeight" [file]="currentFile"></app-files-viewer-media>+ } @loading (after 100ms; minimum 200ms) {+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>+ } @error {+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>+ }}@case (SHORT_MIME.DOCUMENT) {<!-- PDF toggled to OnlyOffice: editorProvider flags are not set for PDFs, so we route directly when the original file was a PDF (hookedShortMime === SHORT_MIME.PDF) -->@if (hookedShortMime === SHORT_MIME.PDF) {- <app-files-viewer-only-office [currentHeight]="currentHeight" [file]="currentFile"- [(isReadonly)]="isReadonly"></app-files-viewer-only-office>+ @defer (on immediate) {+ <app-files-viewer-only-office [currentHeight]="currentHeight" [file]="currentFile"+ [(isReadonly)]="isReadonly"></app-files-viewer-only-office>+ } @loading (after 100ms; minimum 200ms) {+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>+ } @error {+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>+ }} @else if (editorProvider.collabora) {- <app-files-viewer-collabora-online [currentHeight]="currentHeight" [file]="currentFile"- [(isReadonly)]="isReadonly"></app-files-viewer-collabora-online>+ @defer (on immediate) {+ <app-files-viewer-collabora-online [currentHeight]="currentHeight" [file]="currentFile"+ [(isReadonly)]="isReadonly"></app-files-viewer-collabora-online>+ } @loading (after 100ms; minimum 200ms) {+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>+ } @error {+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>+ }} @else if (editorProvider.onlyoffice || editorProvider.eurooffice) {- <app-files-viewer-only-office [currentHeight]="currentHeight" [file]="currentFile"- [(isReadonly)]="isReadonly"></app-files-viewer-only-office>+ @defer (on immediate) {+ <app-files-viewer-only-office [currentHeight]="currentHeight" [file]="currentFile"+ [(isReadonly)]="isReadonly"></app-files-viewer-only-office>+ } @loading (after 100ms; minimum 200ms) {+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>+ } @error {+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>+ }} @else {<!--This case should never happen--><div [style.height.px]="currentHeight" class="d-flex p-4" l10nTranslate>No editor found</div>}}@case (SHORT_MIME.MARKDOWN) {- <app-files-viewer-markdown- [currentHeight]="currentHeight"- [file]="currentFile"- [isWriteable]="isWriteable"- [modalClosing]="modalClosing()"- [(isReadonly)]="isReadonly">- </app-files-viewer-markdown>+ @defer (on immediate) {+ <app-files-viewer-markdown+ [currentHeight]="currentHeight"+ [file]="currentFile"+ [isWriteable]="isWriteable"+ [modalClosing]="modalClosing()"+ (viewerReady)="editableViewerReady.set(true)"+ [(isReadonly)]="isReadonly">+ </app-files-viewer-markdown>+ } @loading (after 100ms; minimum 200ms) {+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>+ } @error {+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>+ }}@default {- <app-files-viewer-text- [currentHeight]="currentHeight"- [file]="currentFile"- [isWriteable]="isWriteable"- [modalClosing]="modalClosing()"- [(isReadonly)]="isReadonly">- </app-files-viewer-text>-+ @defer (on immediate) {+ <app-files-viewer-text+ [currentHeight]="currentHeight"+ [file]="currentFile"+ [isWriteable]="isWriteable"+ [modalClosing]="modalClosing()"+ (viewerReady)="editableViewerReady.set(true)"+ [(isReadonly)]="isReadonly">+ </app-files-viewer-text>+ } @loading (after 100ms; minimum 200ms) {+ <ng-container [ngTemplateOutlet]="viewerLoading"></ng-container>+ } @error {+ <ng-container [ngTemplateOutlet]="viewerError"></ng-container>+ }}}</div>diff --git a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.tsindex 20e4d914..cb41e480 100644--- a/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts+++ b/frontend/src/app/applications/files/components/dialogs/files-viewer-dialog.component.ts@@ -1,3 +1,4 @@+import { NgTemplateOutlet } from '@angular/common'import { Component, computed, HostListener, inject, Input, model, OnDestroy, OnInit, signal } from '@angular/core'import { LucideDynamicIcon, LucideEye, LucidePencil } from '@lucide/angular'import { FILE_MODE } from '@sync-in-server/backend/src/applications/files/constants/operations'@@ -19,6 +20,7 @@ import { FilesViewerTextComponent } from '../viewers/files-viewer-text.component@Component({selector: 'app-files-viewer-dialog',imports: [+ NgTemplateOutlet,FilesViewerPdfComponent,FilesViewerMediaComponent,FilesViewerTextComponent,@@ -40,6 +42,7 @@ export class FilesViewerDialogComponent implements OnInit, OnDestroy {@Input({ required: true }) editorProvider: FileEditorProvidersmodalClosing = signal<boolean>(false)protected activeViewer = signal<string>('')+ protected editableViewerReady = signal(false)protected isReadonly = model<boolean>(true)protected currentHeight: numberprotected readonly SHORT_MIME = SHORT_MIME@@ -65,7 +68,8 @@ export class FilesViewerDialogComponent implements OnInit, OnDestroy {}onClose() {- if (this.hookedShortMime === SHORT_MIME.TEXT || this.hookedShortMime === SHORT_MIME.MARKDOWN) {+ const isEditableViewer = this.hookedShortMime === SHORT_MIME.TEXT || this.hookedShortMime === SHORT_MIME.MARKDOWN+ if (isEditableViewer && this.editableViewerReady()) {// Prevent closing the modal without saving when using text-based editorsthis.modalClosing.set(true)// Force the next state changediff --git a/frontend/src/app/applications/files/components/sidebar/files-selection.component.html b/frontend/src/app/applications/files/components/sidebar/files-selection.component.htmlindex 5f31f501..c9f9dc16 100644--- a/frontend/src/app/applications/files/components/sidebar/files-selection.component.html+++ b/frontend/src/app/applications/files/components/sidebar/files-selection.component.html@@ -41,7 +41,15 @@</div>}@case ('media') {- <app-files-viewer-media [currentHeight]="cardImageSize" [file]="f" [sidebarMode]="true"></app-files-viewer-media>+ @defer (on immediate) {+ <app-files-viewer-media [currentHeight]="cardImageSize" [file]="f" [sidebarMode]="true"></app-files-viewer-media>+ } @loading (after 100ms; minimum 200ms) {+ <div class="d-flex align-items-center justify-content-center" [style.height.px]="cardImageSize" role="status">+ <span class="spinner-border spinner-border-sm text-primary" aria-hidden="true"></span>+ </div>+ } @error {+ <img [src]="f.mimeUrl" alt="" [style.height.px]="cardImageSize" (error)="f.fallBackMimeUrl()">+ }}@default {<img [src]="f.mimeUrl" alt="" [style.height.px]="cardImageSize" (error)="f.fallBackMimeUrl()">diff --git a/frontend/src/app/applications/files/components/viewers/components/files-viewer-codemirror-search-adapter.ts b/frontend/src/app/applications/files/components/viewers/components/files-viewer-codemirror-search-adapter.tsnew file mode 100644index 00000000..f3a60c62--- /dev/null+++ b/frontend/src/app/applications/files/components/viewers/components/files-viewer-codemirror-search-adapter.ts@@ -0,0 +1,138 @@+import { type Extension as CodeMirrorExtension, Prec } from '@codemirror/state'+import {+ closeSearchPanel,+ findNext,+ findPrevious,+ getSearchQuery,+ openSearchPanel,+ search,+ searchPanelOpen,+ SearchQuery,+ setSearchQuery+} from '@codemirror/search'+import { EditorView } from '@codemirror/view'+import { BaseFileViewerSearchAdapter } from './files-viewer-search-adapter'++export class CodeMirrorFileViewerSearchAdapter extends BaseFileViewerSearchAdapter {+ readonly extensions: CodeMirrorExtension[] = [+ Prec.highest(+ EditorView.domEventHandlers({+ keydown: (event) => {+ if (!this.isSearchShortcut(event)) return false+ event.preventDefault()+ event.stopPropagation()+ this.toggle()+ return true+ }+ })+ ),+ search({+ createPanel: () => {+ const dom = document.createElement('div')+ dom.className = 'files-viewer-search-hidden-panel'+ dom.hidden = true+ return { dom }+ }+ }),+ EditorView.updateListener.of((update) => {+ if (update.docChanged || update.selectionSet) {+ this.syncView(update.view)+ }+ })+ ]+ private query = ''++ constructor(private readonly getView: () => EditorView | null | undefined) {+ super()+ }++ override close() {+ const view = this.getView()+ if (view) closeSearchPanel(view)+ this.setOpen(false)+ this.resetMatches()+ }++ override next() {+ const view = this.getView()+ if (!view) return+ findNext(view)+ this.syncView(view)+ }++ override open() {+ const view = this.getView()+ if (!view) return+ openSearchPanel(view)+ this.dispatchQuery(view, this.query)+ this.syncView(view)+ }++ override previous() {+ const view = this.getView()+ if (!view) return+ findPrevious(view)+ this.syncView(view)+ }++ override setQuery(query: string) {+ const view = this.getView()+ this.query = query+ if (!view) {+ this.resetState()+ return+ }+ this.dispatchQuery(view, query)+ this.syncView(view)+ }++ override sync() {+ const view = this.getView()+ if (!view) {+ this.resetState()+ return+ }+ this.syncView(view)+ }++ override toggle() {+ this.sync()+ super.toggle()+ }++ private isSearchShortcut(event: KeyboardEvent): boolean {+ return (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'f'+ }++ private syncView(view: EditorView) {+ const isOpen = searchPanelOpen(view.state)+ this.setOpen(isOpen)+ if (!isOpen) {+ this.resetMatches()+ return+ }+ const query = getSearchQuery(view.state)+ if (!query.search || !query.valid) {+ this.resetMatches()+ return+ }++ const selection = view.state.selection.main+ let currentIndex = 0+ let matchCount = 0+ const cursor = query.getCursor(view.state)++ for (let match = cursor.next(); !match.done; match = cursor.next()) {+ matchCount+++ if (match.value.from === selection.from && match.value.to === selection.to) {+ currentIndex = matchCount+ }+ }++ this.setMatches(currentIndex, matchCount)+ }++ private dispatchQuery(view: EditorView, query: string) {+ view.dispatch({ effects: setSearchQuery.of(new SearchQuery({ search: query })) })+ }+}diff --git a/frontend/src/app/applications/files/components/viewers/components/files-viewer-search-adapter.ts b/frontend/src/app/applications/files/components/viewers/components/files-viewer-search-adapter.tsindex c97c7fe9..a5a98c62 100644--- a/frontend/src/app/applications/files/components/viewers/components/files-viewer-search-adapter.ts+++ b/frontend/src/app/applications/files/components/viewers/components/files-viewer-search-adapter.ts@@ -1,48 +1,7 @@-import { signal, type Signal } from '@angular/core'-import { type Extension as CodeMirrorExtension, Prec } from '@codemirror/state'-import {- closeSearchPanel,- findNext,- findPrevious,- getSearchQuery,- openSearchPanel,- search,- searchPanelOpen,- SearchQuery,- setSearchQuery-} from '@codemirror/search'-import { EditorView } from '@codemirror/view'-import { type Editor as TipTapEditor, Extension as TipTapExtension } from '@tiptap/core'-import type { Node as ProseMirrorNode } from '@tiptap/pm/model'-import { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state'-import { Decoration, DecorationSet } from '@tiptap/pm/view'+import { signal } from '@angular/core'+import type { FileViewerSearchAdapter } from '../../../interfaces/file-viewer-search.interface'-export interface FileViewerSearchAdapter {- readonly currentIndex: Signal<number>- readonly isOpen: Signal<boolean>- readonly matchCount: Signal<number>-- close(): void- next(): void- open(): void- previous(): void- setQuery(query: string): void- sync(): void- toggle(): void-}--interface SearchMatch {- from: number- to: number-}--interface TipTapSearchPluginState {- decorations: DecorationSet- matches: SearchMatch[]- query: string-}--abstract class BaseFileViewerSearchAdapter implements FileViewerSearchAdapter {+export abstract class BaseFileViewerSearchAdapter implements FileViewerSearchAdapter {private readonly currentIndexSignal = signal(0)readonly currentIndex = this.currentIndexSignal.asReadonly()private readonly isOpenSignal = signal(false)@@ -83,291 +42,3 @@ abstract class BaseFileViewerSearchAdapter implements FileViewerSearchAdapter {this.isOpenSignal.set(isOpen)}}--export class CodeMirrorFileViewerSearchAdapter extends BaseFileViewerSearchAdapter {- readonly extensions: CodeMirrorExtension[] = [- Prec.highest(- EditorView.domEventHandlers({- keydown: (event) => {- if (!this.isSearchShortcut(event)) return false- event.preventDefault()- event.stopPropagation()- this.toggle()- return true- }- })- ),- search({- createPanel: () => {- const dom = document.createElement('div')- dom.className = 'files-viewer-search-hidden-panel'- dom.hidden = true- return { dom }- }- }),- EditorView.updateListener.of((update) => {- if (update.docChanged || update.selectionSet) {- this.syncView(update.view)- }- })- ]- private query = ''-- constructor(private readonly getView: () => EditorView | null | undefined) {- super()- }-- override close() {- const view = this.getView()- if (view) closeSearchPanel(view)- this.setOpen(false)- this.resetMatches()- }-- override next() {- const view = this.getView()- if (!view) return- findNext(view)- this.syncView(view)- }-- override open() {- const view = this.getView()- if (!view) return- openSearchPanel(view)- this.dispatchQuery(view, this.query)- this.syncView(view)- }-- override previous() {- const view = this.getView()- if (!view) return- findPrevious(view)- this.syncView(view)- }-- override setQuery(query: string) {- const view = this.getView()- this.query = query- if (!view) {- this.resetState()- return- }- this.dispatchQuery(view, query)- this.syncView(view)- }-- override sync() {- const view = this.getView()- if (!view) {- this.resetState()- return- }- this.syncView(view)- }-- override toggle() {- this.sync()- super.toggle()- }-- private isSearchShortcut(event: KeyboardEvent): boolean {- return (event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'f'- }-- private syncView(view: EditorView) {- const isOpen = searchPanelOpen(view.state)- this.setOpen(isOpen)- if (!isOpen) {- this.resetMatches()- return- }- const query = getSearchQuery(view.state)- if (!query.search || !query.valid) {- this.resetMatches()- return- }-- const selection = view.state.selection.main- let currentIndex = 0- let matchCount = 0- const cursor = query.getCursor(view.state)-- for (let match = cursor.next(); !match.done; match = cursor.next()) {- matchCount++- if (match.value.from === selection.from && match.value.to === selection.to) {- currentIndex = matchCount- }- }-- this.setMatches(currentIndex, matchCount)- }-- private dispatchQuery(view: EditorView, query: string) {- view.dispatch({ effects: setSearchQuery.of(new SearchQuery({ search: query })) })- }-}--export class TipTapFileViewerSearchAdapter extends BaseFileViewerSearchAdapter {- private readonly pluginKey = new PluginKey<TipTapSearchPluginState>('fileViewerSearch')- private readonly plugin = this.createPlugin()- readonly extension = TipTapExtension.create({- name: 'fileViewerSearch',- addProseMirrorPlugins: () => [this.plugin]- })- private query = ''-- constructor(private readonly getEditor: () => TipTapEditor | null | undefined) {- super()- }-- override close() {- this.setOpen(false)- this.dispatchSearch('')- this.resetMatches()- }-- override next() {- this.selectMatch(this.currentIndex() >= this.matchCount() ? 1 : this.currentIndex() + 1)- }-- override open() {- this.setOpen(true)- this.dispatchSearch(this.query)- this.sync()- }-- override previous() {- this.selectMatch(this.currentIndex() <= 1 ? this.matchCount() : this.currentIndex() - 1)- }-- override setQuery(query: string) {- this.query = query- this.dispatchSearch(query)- this.sync()- }-- override sync() {- const editor = this.getEditor()- if (!editor || editor.isDestroyed) {- this.resetMatches()- return- }- const searchState = this.pluginKey.getState(editor.state)- if (!searchState) {- this.resetMatches()- return- }- const selection = editor.state.selection- const currentIndex = searchState.matches.findIndex((match) => match.from === selection.from && match.to === selection.to)- this.setMatches(currentIndex === -1 ? 0 : currentIndex + 1, searchState.matches.length)- }-- private createPlugin(): Plugin<TipTapSearchPluginState> {- return new Plugin<TipTapSearchPluginState>({- key: this.pluginKey,- state: {- init: (_config, state) => this.createPluginState(state.doc, '', state.selection),- apply: (transaction, previous, _oldState, newState) => {- const query = transaction.getMeta(this.pluginKey) as string | undefined- if (query !== undefined) {- return this.createPluginState(newState.doc, query, newState.selection)- }- if (transaction.docChanged || transaction.selectionSet) {- return this.createPluginState(newState.doc, previous.query, newState.selection)- }- return previous- }- },- props: {- decorations: (state) => this.pluginKey.getState(state)?.decorations- }- })- }-- private createPluginState(doc: ProseMirrorNode, query: string, selection: { from: number; to: number }): TipTapSearchPluginState {- const matches = this.findMatches(doc, query)- const decorations = DecorationSet.create(- doc,- matches.map((match) =>- Decoration.inline(match.from, match.to, {- class: match.from === selection.from && match.to === selection.to ? 'files-viewer-search-match is-current' : 'files-viewer-search-match'- })- )- )- return { decorations, matches, query }- }-- private dispatchSearch(query: string) {- const editor = this.getEditor()- if (!editor || editor.isDestroyed) return- editor.view.dispatch(editor.state.tr.setMeta(this.pluginKey, query))- }-- private findMatches(doc: ProseMirrorNode, query: string): SearchMatch[] {- const needle = query.toLocaleLowerCase()- if (!needle) return []-- const matches: SearchMatch[] = []- doc.descendants((node, position) => {- if (!node.isText || !node.text) return- matches.push(...this.findTextMatches(node.text, needle, position))- })- return matches- }-- private findTextMatches(text: string, needle: string, position: number): SearchMatch[] {- const matches: SearchMatch[] = []- const haystack = text.toLocaleLowerCase()- let index = haystack.indexOf(needle)-- while (index !== -1) {- const end = index + needle.length- matches.push({ from: position + index, to: position + end })- index = haystack.indexOf(needle, index + needle.length)- }-- return matches- }-- private selectMatch(index: number) {- const editor = this.getEditor()- if (!editor || editor.isDestroyed || index < 1) return- const searchState = this.pluginKey.getState(editor.state)- const match = searchState?.matches[index - 1]- if (!match) return-- editor.view.dispatch(editor.state.tr.setSelection(TextSelection.create(editor.state.doc, match.from, match.to)).scrollIntoView())- this.scrollMatchIntoView(editor, match)- this.sync()- }-- private scrollMatchIntoView(editor: TipTapEditor, match: SearchMatch) {- setTimeout(() => {- if (editor.isDestroyed) return- const scrollContainer = this.findScrollContainer(editor.view.dom)- if (!scrollContainer) return-- const matchTop = editor.view.coordsAtPos(match.from).top- const containerRect = scrollContainer.getBoundingClientRect()- const offsetTop = matchTop - containerRect.top- const scrollMargin = Math.min(120, containerRect.height / 3)-- if (offsetTop < scrollMargin) {- scrollContainer.scrollTop += offsetTop - scrollMargin- } else if (offsetTop > containerRect.height - scrollMargin) {- scrollContainer.scrollTop += offsetTop - containerRect.height + scrollMargin- }- })- }-- private findScrollContainer(element: HTMLElement): HTMLElement | null {- for (let parent = element.parentElement; parent; parent = parent.parentElement) {- const style = getComputedStyle(parent)- if (/(auto|scroll)/.test(style.overflowY) && parent.scrollHeight > parent.clientHeight) {- return parent- }- }- return null- }-}diff --git a/frontend/src/app/applications/files/components/viewers/components/files-viewer-search.component.ts b/frontend/src/app/applications/files/components/viewers/components/files-viewer-search.component.tsindex ec145125..58a17cf9 100644--- a/frontend/src/app/applications/files/components/viewers/components/files-viewer-search.component.ts+++ b/frontend/src/app/applications/files/components/viewers/components/files-viewer-search.component.ts@@ -1,7 +1,7 @@import { Component, effect, ElementRef, input, signal, untracked, viewChild } from '@angular/core'import { FormsModule } from '@angular/forms'import { LucideChevronDown, LucideChevronUp, LucideDynamicIcon, LucideSearch, LucideX } from '@lucide/angular'-import type { FileViewerSearchAdapter } from './files-viewer-search-adapter'+import type { FileViewerSearchAdapter } from '../../../interfaces/file-viewer-search.interface'@Component({selector: 'app-files-viewer-search',diff --git a/frontend/src/app/applications/files/components/viewers/components/files-viewer-tiptap-search-adapter.ts b/frontend/src/app/applications/files/components/viewers/components/files-viewer-tiptap-search-adapter.tsnew file mode 100644index 00000000..334fc86c--- /dev/null+++ b/frontend/src/app/applications/files/components/viewers/components/files-viewer-tiptap-search-adapter.ts@@ -0,0 +1,170 @@+import { type Editor as TipTapEditor, Extension as TipTapExtension } from '@tiptap/core'+import type { Node as ProseMirrorNode } from '@tiptap/pm/model'+import { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state'+import { Decoration, DecorationSet } from '@tiptap/pm/view'+import type { FileViewerSearchMatch, TipTapFileViewerSearchPluginState } from '../../../interfaces/file-viewer-search.interface'+import { BaseFileViewerSearchAdapter } from './files-viewer-search-adapter'++export class TipTapFileViewerSearchAdapter extends BaseFileViewerSearchAdapter {+ private readonly pluginKey = new PluginKey<TipTapFileViewerSearchPluginState>('fileViewerSearch')+ private readonly plugin = this.createPlugin()+ readonly extension = TipTapExtension.create({+ name: 'fileViewerSearch',+ addProseMirrorPlugins: () => [this.plugin]+ })+ private query = ''++ constructor(private readonly getEditor: () => TipTapEditor | null | undefined) {+ super()+ }++ override close() {+ this.setOpen(false)+ this.dispatchSearch('')+ this.resetMatches()+ }++ override next() {+ this.selectMatch(this.currentIndex() >= this.matchCount() ? 1 : this.currentIndex() + 1)+ }++ override open() {+ this.setOpen(true)+ this.dispatchSearch(this.query)+ this.sync()+ }++ override previous() {+ this.selectMatch(this.currentIndex() <= 1 ? this.matchCount() : this.currentIndex() - 1)+ }++ override setQuery(query: string) {+ this.query = query+ this.dispatchSearch(query)+ this.sync()+ }++ override sync() {+ const editor = this.getEditor()+ if (!editor || editor.isDestroyed) {+ this.resetMatches()+ return+ }+ const searchState = this.pluginKey.getState(editor.state)+ if (!searchState) {+ this.resetMatches()+ return+ }+ const selection = editor.state.selection+ const currentIndex = searchState.matches.findIndex((match) => match.from === selection.from && match.to === selection.to)+ this.setMatches(currentIndex === -1 ? 0 : currentIndex + 1, searchState.matches.length)+ }++ private createPlugin(): Plugin<TipTapFileViewerSearchPluginState> {+ return new Plugin<TipTapFileViewerSearchPluginState>({+ key: this.pluginKey,+ state: {+ init: (_config, state) => this.createPluginState(state.doc, '', state.selection),+ apply: (transaction, previous, _oldState, newState) => {+ const query = transaction.getMeta(this.pluginKey) as string | undefined+ if (query !== undefined) {+ return this.createPluginState(newState.doc, query, newState.selection)+ }+ if (transaction.docChanged || transaction.selectionSet) {+ return this.createPluginState(newState.doc, previous.query, newState.selection)+ }+ return previous+ }+ },+ props: {+ decorations: (state) => this.pluginKey.getState(state)?.decorations+ }+ })+ }++ private createPluginState(doc: ProseMirrorNode, query: string, selection: { from: number; to: number }): TipTapFileViewerSearchPluginState {+ const matches = this.findMatches(doc, query)+ const decorations = DecorationSet.create(+ doc,+ matches.map((match) =>+ Decoration.inline(match.from, match.to, {+ class: match.from === selection.from && match.to === selection.to ? 'files-viewer-search-match is-current' : 'files-viewer-search-match'+ })+ )+ )+ return { decorations, matches, query }+ }++ private dispatchSearch(query: string) {+ const editor = this.getEditor()+ if (!editor || editor.isDestroyed) return+ editor.view.dispatch(editor.state.tr.setMeta(this.pluginKey, query))+ }++ private findMatches(doc: ProseMirrorNode, query: string): FileViewerSearchMatch[] {+ const needle = query.toLocaleLowerCase()+ if (!needle) return []++ const matches: FileViewerSearchMatch[] = []+ doc.descendants((node, position) => {+ if (!node.isText || !node.text) return+ matches.push(...this.findTextMatches(node.text, needle, position))+ })+ return matches+ }++ private findTextMatches(text: string, needle: string, position: number): FileViewerSearchMatch[] {+ const matches: FileViewerSearchMatch[] = []+ const haystack = text.toLocaleLowerCase()+ let index = haystack.indexOf(needle)++ while (index !== -1) {+ const end = index + needle.length+ matches.push({ from: position + index, to: position + end })+ index = haystack.indexOf(needle, index + needle.length)+ }++ return matches+ }++ private selectMatch(index: number) {+ const editor = this.getEditor()+ if (!editor || editor.isDestroyed || index < 1) return+ const searchState = this.pluginKey.getState(editor.state)+ const match = searchState?.matches[index - 1]+ if (!match) return++ editor.view.dispatch(editor.state.tr.setSelection(TextSelection.create(editor.state.doc, match.from, match.to)).scrollIntoView())+ this.scrollMatchIntoView(editor, match)+ this.sync()+ }++ private scrollMatchIntoView(editor: TipTapEditor, match: FileViewerSearchMatch) {+ setTimeout(() => {+ if (editor.isDestroyed) return+ const scrollContainer = this.findScrollContainer(editor.view.dom)+ if (!scrollContainer) return++ const matchTop = editor.view.coordsAtPos(match.from).top+ const containerRect = scrollContainer.getBoundingClientRect()+ const offsetTop = matchTop - containerRect.top+ const scrollMargin = Math.min(120, containerRect.height / 3)++ if (offsetTop < scrollMargin) {+ scrollContainer.scrollTop += offsetTop - scrollMargin+ } else if (offsetTop > containerRect.height - scrollMargin) {+ scrollContainer.scrollTop += offsetTop - containerRect.height + scrollMargin+ }+ })+ }++ private findScrollContainer(element: HTMLElement): HTMLElement | null {+ for (let parent = element.parentElement; parent; parent = parent.parentElement) {+ const style = getComputedStyle(parent)+ if (/(auto|scroll)/.test(style.overflowY) && parent.scrollHeight > parent.clientHeight) {+ return parent+ }+ }+ return null+ }+}diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.tsindex f2ee9737..fc6a909e 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-editable-base.ts@@ -1,5 +1,5 @@import { HttpClient, HttpErrorResponse } from '@angular/common/http'-import { Directive, effect, HostListener, inject, input, model, OnDestroy, signal, untracked } from '@angular/core'+import { AfterViewInit, Directive, effect, HostListener, inject, input, model, OnDestroy, output, signal, untracked } from '@angular/core'import type { FileLockProps } from '@sync-in-server/backend/src/applications/files/interfaces/file-props.interface'import { L10N_LOCALE, L10nLocale } from 'angular-l10n'import { firstValueFrom } from 'rxjs'@@ -11,12 +11,13 @@ import { FilesUploadService } from '../../services/files-upload.service'import { fileLockPropsToString } from '../utils/file-lock.utils'@Directive()-export abstract class FilesViewerEditableBase implements OnDestroy {+export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestroy {currentHeight = input.required<number>()file = model.required<FileModel>()isWriteable = input.required<boolean>()isReadonly = model.required<boolean>()modalClosing = input.required<boolean>()+ readonly viewerReady = output<void>()protected isSupported = signal(false)protected isModified = signal(false)protected isSaving = signal(false)@@ -47,6 +48,10 @@ export abstract class FilesViewerEditableBase implements OnDestroy {})}+ ngAfterViewInit() {+ this.viewerReady.emit()+ }+ngOnDestroy() {this.subscription.unsubscribe()this.isDestroyed = truediff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.tsindex 227c9891..eba52001 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.ts@@ -46,13 +46,11 @@ import { ButtonCheckboxDirective } from 'ngx-bootstrap/buttons'import { BsDropdownModule } from 'ngx-bootstrap/dropdown'import { TooltipModule } from 'ngx-bootstrap/tooltip'import { TiptapEditorDirective } from 'ngx-tiptap'+import type { FileViewerSearchAdapter } from '../../interfaces/file-viewer-search.interface'import { FilesViewerEditableBase } from './files-viewer-editable-base'-import {- CodeMirrorFileViewerSearchAdapter,- type FileViewerSearchAdapter,- TipTapFileViewerSearchAdapter-} from './components/files-viewer-search-adapter'+import { CodeMirrorFileViewerSearchAdapter } from './components/files-viewer-codemirror-search-adapter'import { FilesViewerSearchComponent } from './components/files-viewer-search.component'+import { TipTapFileViewerSearchAdapter } from './components/files-viewer-tiptap-search-adapter'type MarkdownHeadingLevel = 1 | 2 | 3 | 4type MarkdownInlineMark = 'bold' | 'code' | 'italic' | 'strike' | 'underline'diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.tsindex caf06f27..77c7968a 100644--- a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.ts@@ -19,7 +19,7 @@ import { L10nTranslateDirective, L10nTranslatePipe } from 'angular-l10n'import { ButtonCheckboxDirective } from 'ngx-bootstrap/buttons'import { TooltipModule } from 'ngx-bootstrap/tooltip'import { FilesViewerEditableBase } from './files-viewer-editable-base'-import { CodeMirrorFileViewerSearchAdapter } from './components/files-viewer-search-adapter'+import { CodeMirrorFileViewerSearchAdapter } from './components/files-viewer-codemirror-search-adapter'import { FilesViewerSearchComponent } from './components/files-viewer-search.component'@Component({diff --git a/frontend/src/app/applications/files/interfaces/file-viewer-search.interface.ts b/frontend/src/app/applications/files/interfaces/file-viewer-search.interface.tsnew file mode 100644index 00000000..dd3dc63e--- /dev/null+++ b/frontend/src/app/applications/files/interfaces/file-viewer-search.interface.ts@@ -0,0 +1,27 @@+import type { Signal } from '@angular/core'+import type { DecorationSet } from '@tiptap/pm/view'++export interface FileViewerSearchAdapter {+ readonly currentIndex: Signal<number>+ readonly isOpen: Signal<boolean>+ readonly matchCount: Signal<number>++ close(): void+ next(): void+ open(): void+ previous(): void+ setQuery(query: string): void+ sync(): void+ toggle(): void+}++export interface FileViewerSearchMatch {+ from: number+ to: number+}++export interface TipTapFileViewerSearchPluginState {+ decorations: DecorationSet+ matches: FileViewerSearchMatch[]+ query: string+}diff --git a/frontend/src/app/applications/files/services/files.service.ts b/frontend/src/app/applications/files/services/files.service.tsindex 975e9405..2e86ecb0 100644--- a/frontend/src/app/applications/files/services/files.service.ts+++ b/frontend/src/app/applications/files/services/files.service.ts@@ -49,7 +49,7 @@ import { StoreService } from '../../../store/store.service'import { UserService } from '../../users/user.service'import { FilesLockDialogComponent } from '../components/dialogs/files-lock-dialog.component'import { type FilesOverwriteAction, FilesOverwriteDialogComponent } from '../components/dialogs/files-overwrite-dialog.component'-import { FilesViewerDialogComponent } from '../components/dialogs/files-viewer-dialog.component'+import type { FilesViewerDialogComponent as FilesViewerDialogComponentState } from '../components/dialogs/files-viewer-dialog.component'import { FilesViewerSelectDialog } from '../components/dialogs/files-viewer-select-dialog.component'import { fileLockPropsToString } from '../components/utils/file-lock.utils'import { MAX_TEXT_FILE_SIZE, SHORT_MIME } from '../files.constants'@@ -436,6 +436,7 @@ export class FilesService {}}+ const { FilesViewerDialogComponent } = await import('../components/dialogs/files-viewer-dialog.component')this.layout.openDialog(FilesViewerDialogComponent, 'full', {id: file.id, // only used to manage the modalinitialState: {@@ -445,7 +446,7 @@ export class FilesService {isWriteable: isWriteable,hookedShortMime: hookedShortMime,editorProvider: editorProvider- } satisfies Partial<FilesViewerDialogComponent>+ } satisfies Partial<FilesViewerDialogComponentState>})}diff --git a/frontend/src/app/applications/recents/recents.routes.ts b/frontend/src/app/applications/recents/recents.routes.tsindex 1df4290f..31dd0855 100644--- a/frontend/src/app/applications/recents/recents.routes.ts+++ b/frontend/src/app/applications/recents/recents.routes.ts@@ -1,5 +1,6 @@import { Routes } from '@angular/router'-import { RecentsComponent } from './components/recents.component'import { RECENTS_PATH } from './recents.constants'-export const recentsRoutes: Routes = [{ path: RECENTS_PATH.BASE, component: RecentsComponent }]+export const recentsRoutes: Routes = [+ { path: RECENTS_PATH.BASE, loadComponent: () => import('./components/recents.component').then((c) => c.RecentsComponent) }+]diff --git a/frontend/src/app/applications/search/search.routes.ts b/frontend/src/app/applications/search/search.routes.tsindex e0596b57..d290e70a 100644--- a/frontend/src/app/applications/search/search.routes.ts+++ b/frontend/src/app/applications/search/search.routes.ts@@ -1,5 +1,6 @@import { Routes } from '@angular/router'-import { SearchComponent } from './components/search.component'import { SEARCH_PATH } from './search.constants'-export const searchRoutes: Routes = [{ path: SEARCH_PATH.BASE, component: SearchComponent }]+export const searchRoutes: Routes = [+ { path: SEARCH_PATH.BASE, loadComponent: () => import('./components/search.component').then((c) => c.SearchComponent) }+]diff --git a/frontend/src/app/applications/spaces/spaces.routes.ts b/frontend/src/app/applications/spaces/spaces.routes.tsindex 6c46af2c..41e7c71e 100644--- a/frontend/src/app/applications/spaces/spaces.routes.ts+++ b/frontend/src/app/applications/spaces/spaces.routes.ts@@ -1,43 +1,39 @@import { Routes } from '@angular/router'-import { LinksComponent } from '../links/components/links.component'-import { SharedComponent } from '../shares/components/shared.component'-import { SpacesBrowserComponent } from './components/spaces-browser.component'-import { SpacesNavComponent } from './components/spaces-nav.component'-import { SpacesComponent } from './components/spaces.component'-import { TrashComponent } from './components/trash.component'import { SPACES_PATH } from './spaces.constants'import { spacesResolver } from './spaces.resolvers'+const loadSpacesBrowserComponent = () => import('./components/spaces-browser.component').then((c) => c.SpacesBrowserComponent)+export const spacesRoutes: Routes = [{path: '',- component: SpacesNavComponent,+ loadComponent: () => import('./components/spaces-nav.component').then((c) => c.SpacesNavComponent),children: [{path: SPACES_PATH.SPACES,pathMatch: 'full',- component: SpacesComponent,+ loadComponent: () => import('./components/spaces.component').then((c) => c.SpacesComponent),resolve: { routes: spacesResolver },data: { repository: SPACES_PATH.SPACES }},{path: SPACES_PATH.TRASH,pathMatch: 'full',- component: TrashComponent,+ loadComponent: () => import('./components/trash.component').then((c) => c.TrashComponent),resolve: { routes: spacesResolver },data: { repository: SPACES_PATH.TRASHES }},{path: SPACES_PATH.SHARED,pathMatch: 'full',- component: SharedComponent,+ loadComponent: () => import('../shares/components/shared.component').then((c) => c.SharedComponent),resolve: { routes: spacesResolver },data: { repository: SPACES_PATH.SHARED }},{path: SPACES_PATH.LINKS,pathMatch: 'full',- component: LinksComponent,+ loadComponent: () => import('../links/components/links.component').then((c) => c.LinksComponent),resolve: { routes: spacesResolver },data: { repository: SPACES_PATH.LINKS }},@@ -46,7 +42,7 @@ export const spacesRoutes: Routes = [children: [{path: '**',- component: SpacesBrowserComponent,+ loadComponent: loadSpacesBrowserComponent,resolve: { routes: spacesResolver },data: { repository: SPACES_PATH.FILES }}@@ -57,7 +53,7 @@ export const spacesRoutes: Routes = [children: [{path: '**',- component: SpacesBrowserComponent,+ loadComponent: loadSpacesBrowserComponent,resolve: { routes: spacesResolver },data: { repository: SPACES_PATH.SHARES }}@@ -68,7 +64,7 @@ export const spacesRoutes: Routes = [children: [{path: '**',- component: SpacesBrowserComponent,+ loadComponent: loadSpacesBrowserComponent,resolve: { routes: spacesResolver },data: { repository: SPACES_PATH.TRASH }}diff --git a/frontend/src/app/applications/users/user.routes.ts b/frontend/src/app/applications/users/user.routes.tsindex 223e644b..60639503 100644--- a/frontend/src/app/applications/users/user.routes.ts+++ b/frontend/src/app/applications/users/user.routes.ts@@ -1,9 +1,6 @@import { Routes } from '@angular/router'import { routeResolver } from '../../common/resolvers/route.resolver'import { userHaveDesktopAppPermission } from '../sync/sync.guards'-import { UserAccountComponent } from './components/user-account.component'-import { UserApplicationsComponent } from './components/user-applications.component'-import { UserGroupsComponent } from './components/user-groups.component'import { USER_PATH } from './user.constants'import { noUserLinkGuard, onlyUserGuard } from './user.guards'@@ -13,7 +10,10 @@ export const userRoutes: Routes = [pathMatch: 'prefix',canActivate: [noUserLinkGuard],children: [- { path: USER_PATH.ACCOUNT, component: UserAccountComponent },+ {+ path: USER_PATH.ACCOUNT,+ loadComponent: () => import('./components/user-account.component').then((c) => c.UserAccountComponent)+ },{path: USER_PATH.CLIENTS,canActivate: [userHaveDesktopAppPermission],@@ -25,7 +25,7 @@ export const userRoutes: Routes = [{path: '**',resolve: { routes: routeResolver },- component: UserGroupsComponent+ loadComponent: () => import('./components/user-groups.component').then((c) => c.UserGroupsComponent)}]},@@ -36,7 +36,7 @@ export const userRoutes: Routes = [},{path: USER_PATH.APPS,- component: UserApplicationsComponent+ loadComponent: () => import('./components/user-applications.component').then((c) => c.UserApplicationsComponent)},{ path: '**', redirectTo: USER_PATH.ACCOUNT }]