2026-02-08 15:59:14 +08:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2026-02-08 17:57:40 +08:00
|
|
|
import type { NodeTemplate } from '../types';
|
2026-02-08 20:41:49 +08:00
|
|
|
import type { GraphTaskElement, GraphTaskRect } from '../builder/element';
|
2026-02-08 17:57:40 +08:00
|
|
|
import { generateKey } from '@/utils/strings';
|
2026-02-08 15:59:14 +08:00
|
|
|
|
2026-02-08 20:27:40 +08:00
|
|
|
export const createGraphTaskElementFromTemplate = (
|
2026-02-08 15:59:14 +08:00
|
|
|
template: NodeTemplate,
|
2026-02-08 20:41:49 +08:00
|
|
|
rect?: GraphTaskRect,
|
2026-02-08 20:27:40 +08:00
|
|
|
): GraphTaskElement => {
|
2026-02-08 16:01:21 +08:00
|
|
|
let realRect = { width: 200, height: 100, x: 0, y: 0, ...rect || {} }
|
|
|
|
|
console.info('rect',rect)
|
2026-02-08 15:59:14 +08:00
|
|
|
return {
|
|
|
|
|
id: 0,
|
|
|
|
|
key: generateKey(template.type),
|
2026-02-08 20:41:49 +08:00
|
|
|
type: 'task',
|
2026-02-08 15:59:14 +08:00
|
|
|
template: template.id,
|
|
|
|
|
name: template.name,
|
2026-02-08 20:41:49 +08:00
|
|
|
category: template.type,
|
2026-02-08 15:59:14 +08:00
|
|
|
description: template.description,
|
|
|
|
|
position: {
|
|
|
|
|
x: realRect.x ?? 0,
|
|
|
|
|
y: realRect.y ?? 0,
|
|
|
|
|
},
|
|
|
|
|
width: realRect.width,
|
|
|
|
|
height: realRect.height,
|
|
|
|
|
inputs: null,
|
|
|
|
|
outputs: null,
|
2026-02-08 20:57:07 +08:00
|
|
|
parameters: template.parameters ?? [],
|
|
|
|
|
variables: [],
|
2026-02-08 20:27:40 +08:00
|
|
|
} as GraphTaskElement;
|
2026-02-08 15:59:14 +08:00
|
|
|
};
|