Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

feat(editors): introduce unified unsaved changes prompt component and improve toolbar responsiveness

johavenc725cf590154
diff --git a/frontend/src/app/applications/files/components/viewers/components/files-viewer-unsaved-changes.component.ts b/frontend/src/app/applications/files/components/viewers/components/files-viewer-unsaved-changes.component.ts
new file mode 100644
index 00000000..9055ec9b
--- /dev/null
+++ b/frontend/src/app/applications/files/components/viewers/components/files-viewer-unsaved-changes.component.ts
@@ -0,0 +1,69 @@
+import { Component, input, output } from '@angular/core'
+import { L10nTranslateDirective } from 'angular-l10n'
+
+@Component({
+ selector: 'app-files-viewer-unsaved-changes',
+ imports: [L10nTranslateDirective],
+ styles: [
+ `
+ :host {
+ position: fixed;
+ z-index: 10;
+ top: 0;
+ left: 50%;
+ max-width: calc(100% - 1.5rem);
+ transform: translateX(-50%);
+ }
+
+ .files-viewer-unsaved-changes {
+ display: flex;
+ flex-wrap: nowrap;
+ justify-content: flex-end;
+ max-width: 100%;
+ gap: 0.5rem;
+ padding: 0.5rem;
+ border: 1px solid var(--app-menu-surface-border, var(--bs-border-color));
+ border-radius: var(--bs-border-radius);
+ color: var(--app-menu-item-color, var(--bs-body-color));
+ background: var(--app-menu-surface-bg, var(--bs-body-bg));
+ box-shadow: var(--bs-box-shadow);
+ }
+
+ @media (max-width: 575.98px) {
+ :host {
+ right: 0;
+ left: 0;
+ width: 100%;
+ max-width: none;
+ transform: none;
+ }
+
+ .files-viewer-unsaved-changes {
+ width: 100%;
+ }
+
+ .files-viewer-unsaved-changes .btn {
+ flex: 1 1 0;
+ min-width: 0;
+ padding-inline: 0.35rem;
+ white-space: normal;
+ }
+ }
+ `
+ ],
+ template: `
+ <div class="files-viewer-unsaved-changes" role="alertdialog">
+ <button (click)="saveAndExit.emit()" class="btn btn-sm btn-primary" type="button" l10nTranslate>Save And Exit</button>
+ <button (click)="closeWithoutSaving.emit()" [disabled]="saving()" class="btn btn-sm btn-danger" type="button" l10nTranslate>
+ Close Without Saving
+ </button>
+ <button (click)="keepEditing.emit()" class="btn btn-sm btn-default" type="button" l10nTranslate>Cancel</button>
+ </div>
+ `
+})
+export class FilesViewerUnsavedChangesComponent {
+ readonly saving = input(false)
+ readonly saveAndExit = output<void>()
+ readonly closeWithoutSaving = output<void>()
+ readonly keepEditing = output<void>()
+}
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.ts
index 76594126..a63a7d29 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
@@ -91,6 +91,10 @@ export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestro
return
}
+ protected onContentLoadError(e: HttpErrorResponse): void {
+ this.layout.sendNotification('error', 'Unable to open document', this.file().name, e)
+ }
+
protected onSaveFinished(): void {
return
}
@@ -168,7 +172,7 @@ export abstract class FilesViewerEditableBase implements AfterViewInit, OnDestro
}
this.http.get(this.file().dataUrl, { responseType: 'text' }).subscribe({
next: (data: string) => this.onContentLoaded(data),
- error: (e: HttpErrorResponse) => this.layout.sendNotification('error', 'Unable to open document', this.file().name, e)
+ error: (e: HttpErrorResponse) => this.onContentLoadError(e)
})
}
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.html b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.html
index 9c29f9a5..2faf8dc3 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.html
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.html
@@ -36,7 +36,7 @@
[disabled]="!canUndo()"
[tooltip]="'Undo' | translate:locale.language"
triggers="hover"
- class="d-none d-sm-block btn btn-custom"
+ class="btn btn-custom"
type="button">
<svg [lucideIcon]="icons.LucideUndo"></svg>
</button>
@@ -46,7 +46,7 @@
[disabled]="!canRedo()"
[tooltip]="'Redo' | translate:locale.language"
triggers="hover"
- class="d-none d-sm-block btn btn-custom"
+ class="btn btn-custom"
type="button">
<svg [lucideIcon]="icons.LucideRedo"></svg>
</button>
@@ -117,7 +117,7 @@
[class.active]="isSelectionActive('underline')"
[tooltip]="'Underline' | translate:locale.language"
triggers="hover"
- class="d-none d-md-block btn btn-custom"
+ class="btn btn-custom"
type="button">
<svg [lucideIcon]="icons.LucideUnderline"></svg>
</button>
@@ -128,12 +128,12 @@
[class.active]="isSelectionActive('strike')"
[tooltip]="'Strikethrough' | translate:locale.language"
triggers="hover"
- class="d-none d-md-block btn btn-custom"
+ class="btn btn-custom"
type="button">
<svg [lucideIcon]="icons.LucideStrikethrough"></svg>
</button>
- <div class="d-none d-md-block vr files-markdown-toolbar-separator"></div>
+ <div class="vr files-markdown-toolbar-separator"></div>
<div class="btn-group" dropdown>
<button
@@ -216,14 +216,14 @@
[class.active]="isSelectionActive('blockquote')"
[tooltip]="'Blockquote' | translate:locale.language"
triggers="hover"
- class="d-none d-md-block btn btn-custom"
+ class="btn btn-custom"
type="button">
<svg [lucideIcon]="icons.LucideQuote"></svg>
</button>
</div>
<div class="files-markdown-toolbar-group">
- <div class="d-none d-lg-block btn-group" dropdown>
+ <div class="btn-group" dropdown>
<button
[attr.aria-label]="'Table' | translate:locale.language"
[disabled]="!canEditVisual()"
@@ -287,7 +287,7 @@
[disabled]="!canEditVisual()"
[tooltip]="'Horizontal Rule' | translate:locale.language"
triggers="hover"
- class="d-none d-lg-block btn btn-custom"
+ class="btn btn-custom"
type="button">
<svg [lucideIcon]="icons.LucideMinus"></svg>
</button>
@@ -353,7 +353,7 @@
<svg [lucideIcon]="icons.LucideTextWrap"></svg>
</button>
}
- <div class="d-none d-sm-block vr files-markdown-toolbar-separator"></div>
+ <div class="vr files-markdown-toolbar-separator"></div>
<button
btnCheckbox
[attr.aria-label]="'Search' | translate:locale.language"
@@ -361,31 +361,21 @@
(ngModelChange)="toggleSearch()"
[tooltip]="'Search' | translate:locale.language"
triggers="hover"
- class="d-none d-sm-block btn btn-custom"
+ class="btn btn-custom"
type="button">
<svg [lucideIcon]="icons.LucideSearch"></svg>
</button>
- @if (warnOnUnsavedChanges()) {
- <button (click)="save(true)"
- class="btn btn-sm btn-primary ms-auto"
- type="button"
- l10nTranslate>Save And Exit
- </button>
- <button (click)="onClose()"
- [disabled]="isSaving()"
- class="btn btn-sm btn-danger"
- data-dismiss="modal" type="button"
- l10nTranslate>Close Without Saving
- </button>
- <button (click)="warnOnUnsavedChanges.set(false)"
- class="d-none d-sm-block btn btn-sm btn-default"
- data-dismiss="modal" type="button"
- l10nTranslate>Cancel
- </button>
- }
</div>
+ @if (warnOnUnsavedChanges()) {
+ <app-files-viewer-unsaved-changes
+ [saving]="isSaving()"
+ (saveAndExit)="save(true)"
+ (closeWithoutSaving)="onClose()"
+ (keepEditing)="warnOnUnsavedChanges.set(false)" />
+ }
+
<div class="files-markdown-content" [class.is-visual]="!isSourceMode()" [class.is-source]="isSourceMode()">
<div class="files-markdown-visual-pane">
<tiptap-editor
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.scss b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.scss
index 761bd3e9..caaaab3d 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.scss
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-markdown.component.scss
@@ -339,6 +339,19 @@
.cm-panel.cm-search {
display: none;
}
+
+ @media (max-width: 767.98px) {
+ .files-markdown-toolbar {
+ flex-wrap: wrap !important;
+ height: auto;
+ min-height: 40px;
+ }
+
+ .files-markdown-toolbar-group,
+ .files-markdown-mode-group {
+ display: contents;
+ }
+ }
}
body.theme-dark {
diff --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.ts
index ca6eb9af..c2efdd38 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
@@ -51,6 +51,7 @@ import { FilesViewerEditableBase } from './files-viewer-editable-base'
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'
+import { FilesViewerUnsavedChangesComponent } from './components/files-viewer-unsaved-changes.component'
type MarkdownHeadingLevel = 1 | 2 | 3 | 4
type MarkdownInlineMark = 'bold' | 'code' | 'italic' | 'strike' | 'underline'
@@ -82,7 +83,8 @@ const ExitInlineCodeOnEnter = Extension.create({
LucideDynamicIcon,
L10nTranslatePipe,
L10nTranslateDirective,
- FilesViewerSearchComponent
+ FilesViewerSearchComponent,
+ FilesViewerUnsavedChangesComponent
],
styleUrl: 'files-viewer-markdown.component.scss',
templateUrl: 'files-viewer-markdown.component.html'
diff --git a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
index 6ea861ee..2bf7b0d2 100644
--- a/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
+++ b/frontend/src/app/applications/files/components/viewers/files-viewer-text.component.html
@@ -72,25 +72,14 @@
type="button">
<svg [lucideIcon]="icons.LucideSearch"></svg>
</button>
- @if (warnOnUnsavedChanges()) {
- <button (click)="save(true)"
- class="btn btn-sm btn-primary ms-auto"
- type="button"
- l10nTranslate>Save And Exit
- </button>
- <button (click)="onClose()"
- [disabled]="isSaving()"
- class="btn btn-sm btn-danger"
- data-dismiss="modal" type="button"
- l10nTranslate>Close Without Saving
- </button>
- <button (click)="warnOnUnsavedChanges.set(false)"
- class="d-none d-sm-block btn btn-sm btn-default"
- data-dismiss="modal" type="button"
- l10nTranslate>Cancel
- </button>
- }
</div>
+ @if (warnOnUnsavedChanges()) {
+ <app-files-viewer-unsaved-changes
+ [saving]="isSaving()"
+ (saveAndExit)="save(true)"
+ (closeWithoutSaving)="onClose()"
+ (keepEditing)="warnOnUnsavedChanges.set(false)" />
+ }
<code-editor
#editor
[languages]="languages"
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.ts
index 77c7968a..57f1114f 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
@@ -15,12 +15,13 @@ import {
LucideTextWrap,
LucideUndo
} from '@lucide/angular'
-import { L10nTranslateDirective, L10nTranslatePipe } from 'angular-l10n'
+import { 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-codemirror-search-adapter'
import { FilesViewerSearchComponent } from './components/files-viewer-search.component'
+import { FilesViewerUnsavedChangesComponent } from './components/files-viewer-unsaved-changes.component'
@Component({
selector: 'app-files-viewer-text',
@@ -32,8 +33,8 @@ import { FilesViewerSearchComponent } from './components/files-viewer-search.com
LucideDynamicIcon,
L10nTranslatePipe,
ButtonCheckboxDirective,
- L10nTranslateDirective,
- FilesViewerSearchComponent
+ FilesViewerSearchComponent,
+ FilesViewerUnsavedChangesComponent
],
styles: [
`