aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/components/CustomElementRender.vue
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/components/CustomElementRender.vue')
-rw-r--r--apps/files/src/components/CustomElementRender.vue54
1 files changed, 54 insertions, 0 deletions
diff --git a/apps/files/src/components/CustomElementRender.vue b/apps/files/src/components/CustomElementRender.vue
new file mode 100644
index 00000000000..b08d3ba5ee5
--- /dev/null
+++ b/apps/files/src/components/CustomElementRender.vue
@@ -0,0 +1,54 @@
+<!--
+ - SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ - SPDX-License-Identifier: AGPL-3.0-or-later
+-->
+<template>
+ <span />
+</template>
+
+<script lang="ts">
+/**
+ * This component is used to render custom
+ * elements provided by an API. Vue doesn't allow
+ * to directly render an HTMLElement, so we can do
+ * this magic here.
+ */
+export default {
+ name: 'CustomElementRender',
+ props: {
+ source: {
+ type: Object,
+ required: true,
+ },
+ currentView: {
+ type: Object,
+ required: true,
+ },
+ render: {
+ type: Function,
+ required: true,
+ },
+ },
+ watch: {
+ source() {
+ this.updateRootElement()
+ },
+ currentView() {
+ this.updateRootElement()
+ },
+ },
+ mounted() {
+ this.updateRootElement()
+ },
+ methods: {
+ async updateRootElement() {
+ const element = await this.render(this.source, this.currentView)
+ if (element) {
+ this.$el.replaceChildren(element)
+ } else {
+ this.$el.replaceChildren()
+ }
+ },
+ },
+}
+</script>