-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathSuggestionsBar.vue
More file actions
197 lines (177 loc) Β· 4.34 KB
/
SuggestionsBar.vue
File metadata and controls
197 lines (177 loc) Β· 4.34 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<!--
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<transition name="fade">
<div v-if="isEmptyContent && !isMobileDevice" class="container-suggestions">
<NcButton
ref="linkFileOrFolder"
variant="secondary"
size="normal"
class="suggestions--button"
@click="linkFile">
<template #icon>
<Folder :size="20" />
</template>
{{ t('text', 'Link to file or folder') }}
</NcButton>
<NcButton
variant="secondary"
size="normal"
class="suggestions--button"
:disabled="isUploadDisabled"
:title="uploadTitle"
@click="$callChooseLocalAttachment">
<template #icon>
<Upload :size="20" />
</template>
{{ t('text', 'Upload') }}
</NcButton>
<NcButton
variant="secondary"
size="normal"
class="suggestions--button"
@click="insertTable">
<template #icon>
<TableIcon :size="20" />
</template>
{{ t('text', 'Insert Table') }}
</NcButton>
<NcButton
variant="secondary"
size="normal"
class="suggestions--button"
@click="linkPicker">
<template #icon>
<Shape :size="20" />
</template>
{{ t('text', 'Smart Picker') }}
</NcButton>
</div>
</transition>
</template>
<script>
import { t } from '@nextcloud/l10n'
import NcButton from '@nextcloud/vue/components/NcButton'
import { getLinkWithPicker } from '@nextcloud/vue/dist/Components/NcRichText.js'
import { Folder, Shape, Table as TableIcon, Upload } from '../components/icons.js'
import { useConnection } from '../composables/useConnection.ts'
import { useEditor } from '../composables/useEditor.ts'
import { useFileProps } from '../composables/useFileProps.ts'
import { useLinkFile } from '../composables/useLinkFile.ts'
import { useNetworkState } from '../composables/useNetworkState.ts'
import { isMobileDevice } from '../helpers/isMobileDevice.js'
import { useActionChooseLocalAttachmentMixin } from './Editor/MediaHandler.provider.js'
export default {
name: 'SuggestionsBar',
components: {
TableIcon,
Folder,
NcButton,
Shape,
Upload,
},
mixins: [useActionChooseLocalAttachmentMixin],
setup() {
const { editor } = useEditor()
const { openData } = useConnection()
const { networkOnline } = useNetworkState()
const { relativePath } = useFileProps()
const { linkFile } = useLinkFile({ editor, relativePath })
return {
editor,
isMobileDevice,
linkFile,
networkOnline,
openData,
}
},
data: () => {
return {
isEmptyContent: false,
}
},
computed: {
isUploadDisabled() {
return !this.openData?.hasOwner || !this.networkOnline
},
uploadTitle() {
if (!this.networkOnline) {
return t('text', 'Disabled because you are currently offline.')
}
if (this.isUploadDisabled) {
return t(
'text',
'Uploading attachments is disabled because the file is shared from another cloud.',
)
}
return ''
},
},
mounted() {
this.editor.on('update', this.onUpdate)
this.onUpdate({ editor: this.editor })
},
beforeDestroy() {
this.editor.off('update', this.onUpdate)
},
methods: {
/**
* Open smart picker dialog
* Triggered by the "Smart Picker" button
*/
linkPicker() {
getLinkWithPicker(null, true)
.then((link) => {
const chain = this.editor.chain()
if (this.editor.view.state.selection.empty) {
chain.focus().insertPreview(link).run()
} else {
chain.setLink({ href: link }).focus().run()
}
})
.catch((error) => {
console.error('Smart picker promise rejected', error)
})
},
/**
* Insert table
* Triggered by the "Insert table" button
*/
insertTable() {
this.editor.chain().focus().insertTable()?.run()
},
onUpdate({ editor }) {
/**
* Empty document has an empty document and an empty paragraph (open and close blocks)
*/
const EMPTY_DOCUMENT_SIZE = 4
this.isEmptyContent = editor.state.doc.nodeSize <= EMPTY_DOCUMENT_SIZE
},
t,
},
}
</script>
<style scoped lang="scss">
.container-suggestions {
display: flex;
margin-left: max(0px, (100% - var(--text-editor-max-width)) / 2);
flex-wrap: wrap;
}
.suggestions--button {
margin: 5px;
}
.fade-enter-active,
.fade-leave-active {
transition: opacity var(--animation-slow) ease-in-out;
}
.fade-enter-to,
.fade-leave {
opacity: 1;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
}
</style>