40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
/*
|
|
* This file is part of the kernelstudio package.
|
|
*
|
|
* (c) 2014-2026 zlin <admin@kernelstudio.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE file
|
|
* that was distributed with this source code.
|
|
*/
|
|
|
|
import type { NodeTemplate } from '../types';
|
|
import type { GraphTaskElement, GraphTaskRect } from '../builder/element';
|
|
import { generateKey } from '@/utils/strings';
|
|
|
|
export const createGraphTaskElementFromTemplate = (
|
|
template: NodeTemplate,
|
|
rect?: GraphTaskRect,
|
|
): GraphTaskElement => {
|
|
let realRect = { width: 200, height: 100, x: 0, y: 0, ...rect || {} }
|
|
console.info('rect',rect)
|
|
return {
|
|
id: 0,
|
|
key: generateKey(template.type),
|
|
type: 'task',
|
|
template: template.id,
|
|
name: template.name,
|
|
category: template.type,
|
|
description: template.description,
|
|
position: {
|
|
x: realRect.x ?? 0,
|
|
y: realRect.y ?? 0,
|
|
},
|
|
width: realRect.width,
|
|
height: realRect.height,
|
|
inputs: null,
|
|
outputs: null,
|
|
parameters: template.parameters ?? [],
|
|
variables: [],
|
|
} as GraphTaskElement;
|
|
};
|