feat(editor): Add initial code for NodeView and Canvas rewrite (no-changelog) (#9135)
Co-authored-by: Csaba Tuncsik <csaba.tuncsik@gmail.com>
This commit is contained in:
87
packages/editor-ui/src/__tests__/data/canvas.ts
Normal file
87
packages/editor-ui/src/__tests__/data/canvas.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { CanvasNodeKey } from '@/constants';
|
||||
import { ref } from 'vue';
|
||||
import type { CanvasElement, CanvasElementData } from '@/types';
|
||||
|
||||
export function createCanvasNodeData({
|
||||
id = 'node',
|
||||
type = 'test',
|
||||
typeVersion = 1,
|
||||
inputs = [],
|
||||
outputs = [],
|
||||
renderType = 'default',
|
||||
}: Partial<CanvasElementData> = {}): CanvasElementData {
|
||||
return {
|
||||
id,
|
||||
type,
|
||||
typeVersion,
|
||||
inputs,
|
||||
outputs,
|
||||
renderType,
|
||||
};
|
||||
}
|
||||
|
||||
export function createCanvasNodeElement({
|
||||
id = '1',
|
||||
type = 'node',
|
||||
label = 'Node',
|
||||
position = { x: 100, y: 100 },
|
||||
data,
|
||||
}: Partial<
|
||||
Omit<CanvasElement, 'data'> & { data: Partial<CanvasElementData> }
|
||||
> = {}): CanvasElement {
|
||||
return {
|
||||
id,
|
||||
type,
|
||||
label,
|
||||
position,
|
||||
data: createCanvasNodeData({ id, type, ...data }),
|
||||
};
|
||||
}
|
||||
|
||||
export function createCanvasNodeProps({
|
||||
id = 'node',
|
||||
label = 'Test Node',
|
||||
selected = false,
|
||||
data = {},
|
||||
} = {}) {
|
||||
return {
|
||||
id,
|
||||
label,
|
||||
selected,
|
||||
data: createCanvasNodeData(data),
|
||||
};
|
||||
}
|
||||
|
||||
export function createCanvasNodeProvide({
|
||||
id = 'node',
|
||||
label = 'Test Node',
|
||||
selected = false,
|
||||
data = {},
|
||||
} = {}) {
|
||||
const props = createCanvasNodeProps({ id, label, selected, data });
|
||||
return {
|
||||
[`${CanvasNodeKey}`]: {
|
||||
id: ref(props.id),
|
||||
label: ref(props.label),
|
||||
selected: ref(props.selected),
|
||||
data: ref(props.data),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function createCanvasConnection(
|
||||
nodeA: CanvasElement,
|
||||
nodeB: CanvasElement,
|
||||
{ sourceIndex = 0, targetIndex = 0 } = {},
|
||||
) {
|
||||
const nodeAOutput = nodeA.data?.outputs[sourceIndex];
|
||||
const nodeBInput = nodeA.data?.inputs[targetIndex];
|
||||
|
||||
return {
|
||||
id: `${nodeA.id}-${nodeB.id}`,
|
||||
source: nodeA.id,
|
||||
target: nodeB.id,
|
||||
...(nodeAOutput ? { sourceHandle: `outputs/${nodeAOutput.type}/${nodeAOutput.index}` } : {}),
|
||||
...(nodeBInput ? { targetHandle: `inputs/${nodeBInput.type}/${nodeBInput.index}` } : {}),
|
||||
};
|
||||
}
|
||||
1
packages/editor-ui/src/__tests__/data/index.ts
Normal file
1
packages/editor-ui/src/__tests__/data/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './canvas';
|
||||
Reference in New Issue
Block a user