forked from frappe/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataLoaderBlock.vue
More file actions
59 lines (53 loc) · 1.32 KB
/
DataLoaderBlock.vue
File metadata and controls
59 lines (53 loc) · 1.32 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
<template>
<div ref="component">
<div
v-if="!block.hasChildren()"
class="pointer-events-none flex h-full w-full items-center justify-center font-semibold">
Add a block to repeat
</div>
<BuilderBlock
v-else
:data="_data"
:block="block.children[0]"
:preview="index !== 0 || preview"
:breakpoint="breakpoint"
:isChildOfComponent="block.isExtendedFromComponent()"
v-for="(_data, index) in blockData" />
</div>
</template>
<script setup lang="ts">
import type Block from "@/block";
import usePageStore from "@/stores/pageStore";
import { getDataForKey } from "@/utils/helpers";
import { Ref, computed, ref } from "vue";
import BuilderBlock from "./BuilderBlock.vue";
const pageStore = usePageStore();
const props = withDefaults(
defineProps<{
block: Block;
preview?: boolean;
breakpoint?: string;
data?: Record<string, any> | null;
}>(),
{
preview: false,
breakpoint: "desktop",
},
);
const component = ref(null) as Ref<HTMLElement | null>;
const blockData = computed(() => {
const pageData = props.data || pageStore.pageData;
if (pageData && props.block.getDataKey("key")) {
const data = getDataForKey(pageData, props.block.getDataKey("key"));
if (Array.isArray(data)) {
return data.slice(0, 100);
}
return data;
} else {
return [{}];
}
});
defineExpose({
component,
});
</script>