update: add slots to Background.vue, Controls.vue and MiniMap.vue
This commit is contained in:
@@ -21,18 +21,17 @@ const defaultColors: Record<BackgroundVariant, string> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const store = inject<RevueFlowStore>('store')!
|
const store = inject<RevueFlowStore>('store')!
|
||||||
const transform = computed(() => store.transform)
|
|
||||||
// when there are multiple flows on a page we need to make sure that every background gets its own pattern.
|
// when there are multiple flows on a page we need to make sure that every background gets its own pattern.
|
||||||
const patternId = `pattern-${Math.floor(Math.random() * 100000)}`
|
|
||||||
|
|
||||||
const bgClasses = ['revue-flow__background']
|
const bgClasses = ['revue-flow__background']
|
||||||
const scaledGap = computed(() => props.gap && props.gap * transform.value[2])
|
const scaledGap = computed(() => props.gap && props.gap * store.transform[2])
|
||||||
const xOffset = computed(() => scaledGap.value && transform.value[0] % scaledGap.value)
|
const xOffset = computed(() => scaledGap.value && store.transform[0] % scaledGap.value)
|
||||||
const yOffset = computed(() => scaledGap.value && transform.value[1] % scaledGap.value)
|
const yOffset = computed(() => scaledGap.value && store.transform[1] % scaledGap.value)
|
||||||
|
const size = computed(() => props.size || 0.4 * store.transform[2])
|
||||||
|
|
||||||
const isLines = computed(() => props.variant === BackgroundVariant.Lines)
|
const isLines = props.variant === BackgroundVariant.Lines
|
||||||
const bgColor = computed(() => (props.color ? props.color : defaultColors[props.variant || BackgroundVariant.Dots]))
|
const bgColor = props.color ? props.color : defaultColors[props.variant || BackgroundVariant.Dots]
|
||||||
const size = computed(() => props.size || 0.4 * transform.value[2])
|
const patternId = `pattern-${Math.floor(Math.random() * 100000)}`
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<svg
|
<svg
|
||||||
@@ -55,5 +54,6 @@ const size = computed(() => props.size || 0.4 * transform.value[2])
|
|||||||
</template>
|
</template>
|
||||||
</pattern>
|
</pattern>
|
||||||
<rect x="0" y="0" width="100%" height="100%" :fill="`url(#${patternId})`" />
|
<rect x="0" y="0" width="100%" height="100%" :fill="`url(#${patternId})`" />
|
||||||
|
<slot></slot>
|
||||||
</svg>
|
</svg>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
export const createGridLinesPath = (size: number, strokeWidth: number, stroke: string) => {
|
|
||||||
return <path stroke={stroke} stroke-width={strokeWidth} d={`M${size / 2} 0 V${size} M0 ${size / 2} H${size}`} />
|
|
||||||
}
|
|
||||||
|
|
||||||
export const createGridDotsPath = (size: number, fill: string) => {
|
|
||||||
return <circle cx={size} cy={size} r={size} fill={fill} />
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { HTMLAttributes } from 'vue'
|
import { HTMLAttributes } from 'vue'
|
||||||
import PlusIcon from '../../../assets/icons/plus.svg'
|
|
||||||
import MinusIcon from '../../../assets/icons/minus.svg'
|
|
||||||
import Fitview from '../../../assets/icons/fitview.svg'
|
|
||||||
import Lock from '../../../assets/icons/lock.svg'
|
|
||||||
import Unlock from '../../../assets/icons/unlock.svg'
|
|
||||||
import ControlButton from './ControlButton.vue'
|
import ControlButton from './ControlButton.vue'
|
||||||
|
import PlusIcon from '@/assets/icons/plus.svg'
|
||||||
|
import MinusIcon from '@/assets/icons/minus.svg'
|
||||||
|
import Fitview from '@/assets/icons/fitview.svg'
|
||||||
|
import Lock from '@/assets/icons/lock.svg'
|
||||||
|
import Unlock from '@/assets/icons/unlock.svg'
|
||||||
import { FitViewParams, RevueFlowStore, ZoomPanHelperFunctions } from '~/types'
|
import { FitViewParams, RevueFlowStore, ZoomPanHelperFunctions } from '~/types'
|
||||||
import useZoomPanHelper from '~/hooks/useZoomPanHelper'
|
import useZoomPanHelper from '~/hooks/useZoomPanHelper'
|
||||||
|
|
||||||
@@ -57,20 +57,38 @@ const onInteractiveChangeHandler = () => {
|
|||||||
<template>
|
<template>
|
||||||
<div :class="mapClasses">
|
<div :class="mapClasses">
|
||||||
<template v-if="props.showZoom">
|
<template v-if="props.showZoom">
|
||||||
<ControlButton on-click="onZoomInHandler" class="revue-flow__controls-zoomin">
|
<slot name="control-zoom-in">
|
||||||
<PlusIcon />
|
<ControlButton class="revue-flow__controls-zoomin" @click="onZoomInHandler">
|
||||||
</ControlButton>
|
<slot name="icon-zoom-in">
|
||||||
<ControlButton on-click="onZoomOutHandler" class="revue-flow__controls-zoomout">
|
<PlusIcon />
|
||||||
<MinusIcon />
|
</slot>
|
||||||
</ControlButton>
|
</ControlButton>
|
||||||
|
</slot>
|
||||||
|
<slot name="control-zoom-out">
|
||||||
|
<ControlButton class="revue-flow__controls-zoomout" @click="onZoomOutHandler">
|
||||||
|
<slot name="icon-zoom-out">
|
||||||
|
<MinusIcon />
|
||||||
|
</slot>
|
||||||
|
</ControlButton>
|
||||||
|
</slot>
|
||||||
</template>
|
</template>
|
||||||
<ControlButton v-if="props.showFitView" class="revue-flow__controls-fitview" on-click="onFitViewHandler">
|
<slot name="control-fitview">
|
||||||
<Fitview />
|
<ControlButton v-if="props.showFitView" class="revue-flow__controls-fitview" @click="onFitViewHandler">
|
||||||
</ControlButton>
|
<slot name="icon-fitview">
|
||||||
<ControlButton v-if="props.showInteractive" class="revue-flow__controls-interactive" on-click="onInteractiveChangeHandler">
|
<Fitview />
|
||||||
<Unlock v-if="isInteractive" />
|
</slot>
|
||||||
<Lock v-else />
|
</ControlButton>
|
||||||
</ControlButton>
|
</slot>
|
||||||
|
<slot name="control-interactive">
|
||||||
|
<ControlButton v-if="props.showInteractive" class="revue-flow__controls-interactive" @click="onInteractiveChangeHandler">
|
||||||
|
<slot name="icon-unlock">
|
||||||
|
<Unlock v-if="isInteractive" />
|
||||||
|
</slot>
|
||||||
|
<slot name="icon-lock">
|
||||||
|
<Lock v-if="!isInteractive" />
|
||||||
|
</slot>
|
||||||
|
</ControlButton>
|
||||||
|
</slot>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -74,22 +74,24 @@ const viewBox = computed(() => {
|
|||||||
:viewBox="`${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`"
|
:viewBox="`${viewBox.x} ${viewBox.y} ${viewBox.width} ${viewBox.height}`"
|
||||||
class="revue-flow__minimap"
|
class="revue-flow__minimap"
|
||||||
>
|
>
|
||||||
<template v-for="(node, i) of store.nodes" :key="`mini-map-node-${i}`">
|
<slot name="mini-map-nodes" :nodes="store.nodes" :view-box="viewBox">
|
||||||
<MiniMapNode
|
<template v-for="(node, i) of store.nodes" :key="`mini-map-node-${i}`">
|
||||||
v-if="!node.isHidden"
|
<MiniMapNode
|
||||||
:x="node.__rf.position.x"
|
v-if="!node.isHidden"
|
||||||
:y="node.__rf.position.y"
|
:x="node.__rf.position.x"
|
||||||
:width="node.__rf.width"
|
:y="node.__rf.position.y"
|
||||||
:height="node.__rf.height"
|
:width="node.__rf.width"
|
||||||
:style="node.style"
|
:height="node.__rf.height"
|
||||||
:class="nodeClassNameFunc(node)"
|
:style="node.style"
|
||||||
:color="nodeColorFunc(node)"
|
:class="nodeClassNameFunc(node)"
|
||||||
:border-radius="props.nodeBorderRadius"
|
:color="nodeColorFunc(node)"
|
||||||
:stroke-color="nodeStrokeColorFunc(node)"
|
:border-radius="props.nodeBorderRadius"
|
||||||
:stroke-width="props.nodeStrokeWidth"
|
:stroke-color="nodeStrokeColorFunc(node)"
|
||||||
:shape-rendering="shapeRendering"
|
:stroke-width="props.nodeStrokeWidth"
|
||||||
/>
|
:shape-rendering="shapeRendering"
|
||||||
</template>
|
/>
|
||||||
|
</template>
|
||||||
|
</slot>
|
||||||
<path
|
<path
|
||||||
class="revue-flow__minimap-mask"
|
class="revue-flow__minimap-mask"
|
||||||
:d="`
|
:d="`
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"~/*": [
|
"~/*": [
|
||||||
"src/*"
|
"src/*"
|
||||||
|
],
|
||||||
|
"@/*": [
|
||||||
|
"*"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user