mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
fix(demo-free): create copy error (#174)
This commit is contained in:
parent
cb942616ab
commit
61c7ad1a7a
@ -1,5 +1,4 @@
|
||||
import {
|
||||
FlowNodeTransformData,
|
||||
FreeLayoutPluginContext,
|
||||
Rectangle,
|
||||
ShortcutsHandler,
|
||||
@ -48,7 +47,7 @@ export class CopyShortcut implements ShortcutsHandler {
|
||||
if (!this.isValid(this.selectedNodes)) {
|
||||
return;
|
||||
}
|
||||
const data = this.toData();
|
||||
const data = this.toClipboardData();
|
||||
await this.write(data);
|
||||
}
|
||||
|
||||
@ -91,8 +90,8 @@ export class CopyShortcut implements ShortcutsHandler {
|
||||
/**
|
||||
* create clipboard data - 转换为剪贴板数据
|
||||
*/
|
||||
private toData(): WorkflowClipboardData {
|
||||
const validNodes = this.getValidNodes(this.selectedNodes);
|
||||
toClipboardData(nodes?: WorkflowNodeEntity[]): WorkflowClipboardData {
|
||||
const validNodes = this.getValidNodes(nodes ? nodes : this.selectedNodes);
|
||||
const source = this.toSource();
|
||||
const json = this.toJSON(validNodes);
|
||||
const bounds = this.getEntireBounds(validNodes);
|
||||
|
||||
@ -19,6 +19,7 @@ import { Toast } from '@douyinfe/semi-ui';
|
||||
import { WorkflowClipboardData, WorkflowClipboardRect } from '../type';
|
||||
import { FlowCommandId, WorkflowClipboardDataID } from '../constants';
|
||||
import { generateUniqueWorkflow } from './unique-workflow';
|
||||
import { CopyShortcut } from '../copy';
|
||||
|
||||
export class PasteShortcut implements ShortcutsHandler {
|
||||
public commandId = FlowCommandId.PASTE;
|
||||
@ -38,19 +39,31 @@ export class PasteShortcut implements ShortcutsHandler {
|
||||
/**
|
||||
* initialize paste shortcut handler - 初始化粘贴快捷键处理器
|
||||
*/
|
||||
constructor(context: FreeLayoutPluginContext) {
|
||||
constructor(private context: FreeLayoutPluginContext) {
|
||||
this.document = context.get(WorkflowDocument);
|
||||
this.selectService = context.get(WorkflowSelectService);
|
||||
this.entityManager = context.get(EntityManager);
|
||||
this.hoverService = context.get(WorkflowHoverService);
|
||||
this.dragService = context.get(WorkflowDragService);
|
||||
this.execute = this.execute.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* execute paste action - 执行粘贴操作
|
||||
* Usage:
|
||||
* 1. clientContext.playground.commandService.executeCommand(FlowCommandId.PASTE, [node]);
|
||||
* 2. keyboard: cmd + v
|
||||
*/
|
||||
public async execute(): Promise<WorkflowNodeEntity[] | undefined> {
|
||||
const data = await this.tryReadClipboard();
|
||||
public async execute(
|
||||
targetEntities?: WorkflowNodeEntity[]
|
||||
): Promise<WorkflowNodeEntity[] | undefined> {
|
||||
let data: WorkflowClipboardData | undefined;
|
||||
if (targetEntities && Array.isArray(targetEntities)) {
|
||||
const copyShortcut = new CopyShortcut(this.context);
|
||||
data = copyShortcut.toClipboardData(targetEntities);
|
||||
} else {
|
||||
data = await this.tryReadClipboard();
|
||||
}
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user