-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (74 loc) · 2.57 KB
/
index.js
File metadata and controls
80 lines (74 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { Note } = require('inkdrop').models
module.exports = {
activate() {
this.subscription = inkdrop.commands.add(document.body, {
'export-as-html:selections': () => this.exportAsHtmlCommand(),
'export-as-html:copy': () => this.copyAsHtmlCommand(),
'export-as-html:copy-simple': () => this.copyAsSimpleHtmlCommand(),
'export-as-html:notebook': e => this.exportNotebook(e)
})
},
deactivate() {
this.subscription.dispose()
},
async exportAsHtmlCommand() {
const {
exportMultipleNotesAsHtml,
exportNoteAsHtml
} = require('./exporter')
const { noteListBar, notes } = inkdrop.store.getState()
const { actionTargetNoteIds } = noteListBar
if (actionTargetNoteIds && actionTargetNoteIds.length > 1) {
inkdrop.notifications.addInfo('Exporting notes started', {
detail: 'It may take a while..',
dismissable: true
})
await exportMultipleNotesAsHtml(actionTargetNoteIds)
inkdrop.notifications.addInfo('Exporting notes completed', {
detail: '',
dismissable: true
})
} else if (actionTargetNoteIds.length === 1) {
const note = await Note.loadWithId(actionTargetNoteIds[0])
exportNoteAsHtml(note)
} else {
inkdrop.notifications.addError('No note opened', {
detail: 'Please open a note to export as HTML',
dismissable: true
})
}
},
async copyAsHtmlCommand() {
const { copyNoteAsHtml } = require('./exporter')
const { noteListBar, notes } = inkdrop.store.getState()
const { actionTargetNoteIds } = noteListBar
if (actionTargetNoteIds && actionTargetNoteIds.length > 0) {
const note = await Note.loadWithId(actionTargetNoteIds[0])
copyNoteAsHtml(note)
}
},
async copyAsSimpleHtmlCommand() {
const { copyNoteAsSimpleHtml } = require('./exporter')
const { noteListBar, notes } = inkdrop.store.getState()
const { actionTargetNoteIds } = noteListBar
if (actionTargetNoteIds && actionTargetNoteIds.length > 0) {
const note = await Note.loadWithId(actionTargetNoteIds[0])
copyNoteAsSimpleHtml(note)
}
},
exportNotebook(e) {
const {
bookList: { bookForContextMenu }
} = inkdrop.store.getState()
const bookId = (e.detail || {}).bookId || (bookForContextMenu || {})._id
if (bookId) {
const { exportNotesInBook } = require('./exporter')
exportNotesInBook(bookId)
} else {
inkdrop.notifications.addError('No notebook specified', {
detail: 'Please select a notebook to export on sidebar',
dismissable: true
})
}
}
}