forked from frappe/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockHTML.vue
More file actions
51 lines (47 loc) · 1.39 KB
/
BlockHTML.vue
File metadata and controls
51 lines (47 loc) · 1.39 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
<template>
<div ref="component" class="!relative" v-html="html"></div>
</template>
<script setup lang="ts">
import type Block from "@/block";
import { getDataForKey } from "@/utils/helpers";
import { computed, ref } from "vue";
const component = ref<HTMLElement | null>(null);
const props = defineProps<{
block: Block;
data?: Record<string, unknown> | null;
}>();
const getDynamicContent = () => {
let innerHTML = null as string | null;
if (props.data && props.block.getDataKey("property") === "innerHTML") {
const dataValue = getDataForKey(props.data, props.block.getDataKey("key"));
innerHTML = typeof dataValue === "string" ? dataValue : innerHTML;
}
if (props.data) {
props.block.dynamicValues
?.filter((dataKeyObj: BlockDataKey) => {
return dataKeyObj.property === "innerHTML" && dataKeyObj.type === "key";
})
?.forEach((dataKeyObj: BlockDataKey) => {
const dataValue = getDataForKey(props.data as Record<string, any>, dataKeyObj.key as string);
innerHTML = typeof dataValue === "string" ? dataValue : innerHTML;
});
}
return innerHTML;
};
const html = computed(() => {
let content = props.block.getInnerHTML();
if (props.data) {
const dynamicContent = getDynamicContent();
if (dynamicContent) {
content = dynamicContent;
}
}
return `
<div class="absolute top-0 bottom-0 right-0 left-0"></div>
${content}
`;
});
defineExpose({
component,
});
</script>