@@ -5,8 +5,15 @@ import dialogService from "../../services/dialog.js";
5
5
import server from "../../services/server.js" ;
6
6
import toastService from "../../services/toast.js" ;
7
7
import ws from "../../services/ws.js" ;
8
- import appContext from "../../components/app_context.js" ;
8
+ import appContext , { type EventData } from "../../components/app_context.js" ;
9
9
import { t } from "../../services/i18n.js" ;
10
+ import type FNote from "../../entities/fnote.js" ;
11
+ import type { FAttachmentRow } from "../../entities/fattachment.js" ;
12
+
13
+ // TODO: Deduplicate with server
14
+ interface ConvertToAttachmentResponse {
15
+ attachment : FAttachmentRow ;
16
+ }
10
17
11
18
const TPL = `
12
19
<div class="dropdown note-actions">
@@ -52,8 +59,12 @@ const TPL = `
52
59
</li>
53
60
54
61
<li data-trigger-command="printActiveNote" class="dropdown-item print-active-note-button">
55
- <span class="bx bx-printer"></span> ${ t ( "note_actions.print_note" ) } <kbd data-command="printActiveNote"></kbd></li>
62
+ <span class="bx bx-printer"></span> ${ t ( "note_actions.print_note" ) } <kbd data-command="printActiveNote"></kbd>
63
+ </li>
56
64
65
+ <li data-trigger-command="exportAsPdf" class="dropdown-item export-as-pdf-button">
66
+ <span class="bx bxs-file-pdf"></span> ${ t ( "note_actions.print_pdf" ) } <kbd data-command="exportAsPdf"></kbd>
67
+ </li>
57
68
58
69
<div class="dropdown-divider"></div>
59
70
@@ -100,25 +111,45 @@ const TPL = `
100
111
</div>` ;
101
112
102
113
export default class NoteActionsWidget extends NoteContextAwareWidget {
114
+
115
+ private $convertNoteIntoAttachmentButton ! : JQuery < HTMLElement > ;
116
+ private $findInTextButton ! : JQuery < HTMLElement > ;
117
+ private $printActiveNoteButton ! : JQuery < HTMLElement > ;
118
+ private $exportAsPdfButton ! : JQuery < HTMLElement > ;
119
+ private $showSourceButton ! : JQuery < HTMLElement > ;
120
+ private $showAttachmentsButton ! : JQuery < HTMLElement > ;
121
+ private $renderNoteButton ! : JQuery < HTMLElement > ;
122
+ private $saveRevisionButton ! : JQuery < HTMLElement > ;
123
+ private $exportNoteButton ! : JQuery < HTMLElement > ;
124
+ private $importNoteButton ! : JQuery < HTMLElement > ;
125
+ private $openNoteExternallyButton ! : JQuery < HTMLElement > ;
126
+ private $openNoteCustomButton ! : JQuery < HTMLElement > ;
127
+ private $deleteNoteButton ! : JQuery < HTMLElement > ;
128
+
103
129
isEnabled ( ) {
104
130
return this . note ?. type !== "launcher" ;
105
131
}
106
132
107
133
doRender ( ) {
108
134
this . $widget = $ ( TPL ) ;
109
- this . $widget . on ( "show.bs.dropdown" , ( ) => this . refreshVisibility ( this . note ) ) ;
135
+ this . $widget . on ( "show.bs.dropdown" , ( ) => {
136
+ if ( this . note ) {
137
+ this . refreshVisibility ( this . note ) ;
138
+ }
139
+ } ) ;
110
140
111
141
this . $convertNoteIntoAttachmentButton = this . $widget . find ( "[data-trigger-command='convertNoteIntoAttachment']" ) ;
112
142
this . $findInTextButton = this . $widget . find ( ".find-in-text-button" ) ;
113
143
this . $printActiveNoteButton = this . $widget . find ( ".print-active-note-button" ) ;
144
+ this . $exportAsPdfButton = this . $widget . find ( ".export-as-pdf-button" ) ;
114
145
this . $showSourceButton = this . $widget . find ( ".show-source-button" ) ;
115
146
this . $showAttachmentsButton = this . $widget . find ( ".show-attachments-button" ) ;
116
147
this . $renderNoteButton = this . $widget . find ( ".render-note-button" ) ;
117
148
this . $saveRevisionButton = this . $widget . find ( ".save-revision-button" ) ;
118
149
119
150
this . $exportNoteButton = this . $widget . find ( ".export-note-button" ) ;
120
151
this . $exportNoteButton . on ( "click" , ( ) => {
121
- if ( this . $exportNoteButton . hasClass ( "disabled" ) ) {
152
+ if ( this . $exportNoteButton . hasClass ( "disabled" ) || ! this . noteContext ?. notePath ) {
122
153
return ;
123
154
}
124
155
@@ -129,7 +160,11 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {
129
160
} ) ;
130
161
131
162
this . $importNoteButton = this . $widget . find ( ".import-files-button" ) ;
132
- this . $importNoteButton . on ( "click" , ( ) => this . triggerCommand ( "showImportDialog" , { noteId : this . noteId } ) ) ;
163
+ this . $importNoteButton . on ( "click" , ( ) => {
164
+ if ( this . noteId ) {
165
+ this . triggerCommand ( "showImportDialog" , { noteId : this . noteId } ) ;
166
+ }
167
+ } ) ;
133
168
134
169
this . $widget . on ( "click" , ".dropdown-item" , ( ) => this . $widget . find ( "[data-bs-toggle='dropdown']" ) . dropdown ( "toggle" ) ) ;
135
170
@@ -138,15 +173,15 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {
138
173
139
174
this . $deleteNoteButton = this . $widget . find ( ".delete-note-button" ) ;
140
175
this . $deleteNoteButton . on ( "click" , ( ) => {
141
- if ( this . note . noteId === "root" ) {
176
+ if ( ! this . note || this . note . noteId === "root" ) {
142
177
return ;
143
178
}
144
179
145
180
branchService . deleteNotes ( [ this . note . getParentBranches ( ) [ 0 ] . branchId ] , true ) ;
146
181
} ) ;
147
182
}
148
183
149
- async refreshVisibility ( note ) {
184
+ async refreshVisibility ( note : FNote ) {
150
185
const isInOptions = note . noteId . startsWith ( "_options" ) ;
151
186
152
187
this . $convertNoteIntoAttachmentButton . toggle ( note . isEligibleForConversionToAttachment ( ) ) ;
@@ -156,7 +191,10 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {
156
191
this . toggleDisabled ( this . $showAttachmentsButton , ! isInOptions ) ;
157
192
this . toggleDisabled ( this . $showSourceButton , [ "text" , "code" , "relationMap" , "mermaid" , "canvas" , "mindMap" , "geoMap" ] . includes ( note . type ) ) ;
158
193
159
- this . toggleDisabled ( this . $printActiveNoteButton , [ "text" , "code" ] . includes ( note . type ) ) ;
194
+ const canPrint = [ "text" , "code" ] . includes ( note . type ) ;
195
+ this . toggleDisabled ( this . $printActiveNoteButton , canPrint ) ;
196
+ this . toggleDisabled ( this . $exportAsPdfButton , canPrint ) ;
197
+ this . $exportAsPdfButton . toggleClass ( "hidden-ext" , ! utils . isElectron ( ) ) ;
160
198
161
199
this . $renderNoteButton . toggle ( note . type === "render" ) ;
162
200
@@ -177,11 +215,11 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {
177
215
}
178
216
179
217
async convertNoteIntoAttachmentCommand ( ) {
180
- if ( ! ( await dialogService . confirm ( t ( "note_actions.convert_into_attachment_prompt" , { title : this . note . title } ) ) ) ) {
218
+ if ( ! this . note || ! ( await dialogService . confirm ( t ( "note_actions.convert_into_attachment_prompt" , { title : this . note . title } ) ) ) ) {
181
219
return ;
182
220
}
183
221
184
- const { attachment : newAttachment } = await server . post ( `notes/${ this . noteId } /convert-to-attachment` ) ;
222
+ const { attachment : newAttachment } = await server . post < ConvertToAttachmentResponse > ( `notes/${ this . noteId } /convert-to-attachment` ) ;
185
223
186
224
if ( ! newAttachment ) {
187
225
toastService . showMessage ( t ( "note_actions.convert_into_attachment_failed" , { title : this . note . title } ) ) ;
@@ -198,15 +236,15 @@ export default class NoteActionsWidget extends NoteContextAwareWidget {
198
236
} ) ;
199
237
}
200
238
201
- toggleDisabled ( $el , enable ) {
239
+ toggleDisabled ( $el : JQuery < HTMLElement > , enable : boolean ) {
202
240
if ( enable ) {
203
241
$el . removeAttr ( "disabled" ) ;
204
242
} else {
205
243
$el . attr ( "disabled" , "disabled" ) ;
206
244
}
207
245
}
208
246
209
- entitiesReloadedEvent ( { loadResults } ) {
247
+ entitiesReloadedEvent ( { loadResults } : EventData < "entitiesReloaded" > ) {
210
248
if ( loadResults . isNoteReloaded ( this . noteId ) ) {
211
249
this . refresh ( ) ;
212
250
}
0 commit comments