Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add __experimentalFeatures flag to store #449

Merged
merged 3 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-stingrays-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vue-flow/core': patch
---

Add `experimentalFeatures` flag to store
5 changes: 5 additions & 0 deletions .changeset/wise-plums-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vue-flow/core': minor
---

Add experimental support for nested Vue Flow components; Align edges by adding parent flow zoom scale. Connections not supported.
30 changes: 27 additions & 3 deletions packages/core/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,36 @@ export default (state: State, getters: ComputedGetters): Actions => {
const updateNodeDimensions: Actions['updateNodeDimensions'] = (updates) => {
if (!state.vueFlowRef) return

const viewportNode = state.vueFlowRef.querySelector('.vue-flow__transformationpane')
const viewportNode = state.vueFlowRef.querySelector('.vue-flow__transformationpane') as HTMLElement

if (!viewportNode) return

const style = window.getComputedStyle(viewportNode)
const { m22: zoom } = new window.DOMMatrixReadOnly(style.transform)
let zoom: number
if (state.__experimentalFeatures?.nestedFlow) {
let viewportNodes: HTMLElement[] = [viewportNode]
let parentNode = viewportNode
let isNested

while (!isNested && parentNode) {
parentNode = parentNode.parentElement!
isNested = parentNode?.classList.contains('vue-flow__transformationpane')

if (isNested) {
viewportNodes = [parentNode, ...viewportNodes]
}
}

viewportNodes.forEach((vp) => {
const style = window.getComputedStyle(vp)
const { m22 } = new window.DOMMatrixReadOnly(style.transform)
if (!zoom) zoom = m22
else zoom *= m22
})
} else {
const style = window.getComputedStyle(viewportNode)
const { m22 } = new window.DOMMatrixReadOnly(style.transform)
zoom = m22
}

const changes: NodeDimensionChange[] = updates.reduce<NodeDimensionChange[]>((res, update) => {
const node = getters.getNode.value(update.id)
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/store/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ const defaultState = (): State => ({
defaultEdgeOptions: undefined,
elevateEdgesOnSelect: false,

__experimentalFeatures: {
nestedFlow: false,
},

vueFlowVersion: typeof __VUE_FLOW_VERSION__ !== 'undefined' ? __VUE_FLOW_VERSION__ : '-',
})

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/types/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ export interface FlowProps {
defaultEdgeOptions?: DefaultEdgeOptions
/** elevates edges when selected and applies z-Index to put them above their nodes */
elevateEdgesOnSelect?: boolean

__experimentalFeatures?: {
nestedFlow?: boolean
}
}

export type FlowOptions = FlowProps