aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/reference-files.ts
blob: 828cbd3e584140d372b8bb80ab26d6ce1afce310 (plain)
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
/**
 * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import Vue from 'vue'
import { translate as t } from '@nextcloud/l10n'

import { registerWidget, registerCustomPickerElement, NcCustomPickerRenderResult } from '@nextcloud/vue/dist/Components/NcRichText.js'

import FileWidget from './views/ReferenceFileWidget.vue'
import FileReferencePickerElement from './views/FileReferencePickerElement.vue'

Vue.mixin({
	methods: {
		t,
	},
})

registerWidget('file', (el, { richObjectType, richObject, accessible, interactive }) => {
	const Widget = Vue.extend(FileWidget)
	new Widget({
		propsData: {
			richObjectType,
			richObject,
			accessible,
			interactive,
		},
	}).$mount(el)
}, () => {}, { hasInteractiveView: true })

registerCustomPickerElement('files', (el, { providerId, accessible }) => {
	const Element = Vue.extend(FileReferencePickerElement)
	const vueElement = new Element({
		propsData: {
			providerId,
			accessible,
		},
	}).$mount(el)
	return new NcCustomPickerRenderResult(vueElement.$el, vueElement)
}, (el, renderResult) => {
	renderResult.object.$destroy()
})