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 {
|
import {
|
||||||
FlowNodeTransformData,
|
|
||||||
FreeLayoutPluginContext,
|
FreeLayoutPluginContext,
|
||||||
Rectangle,
|
Rectangle,
|
||||||
ShortcutsHandler,
|
ShortcutsHandler,
|
||||||
@ -48,7 +47,7 @@ export class CopyShortcut implements ShortcutsHandler {
|
|||||||
if (!this.isValid(this.selectedNodes)) {
|
if (!this.isValid(this.selectedNodes)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = this.toData();
|
const data = this.toClipboardData();
|
||||||
await this.write(data);
|
await this.write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +90,8 @@ export class CopyShortcut implements ShortcutsHandler {
|
|||||||
/**
|
/**
|
||||||
* create clipboard data - 转换为剪贴板数据
|
* create clipboard data - 转换为剪贴板数据
|
||||||
*/
|
*/
|
||||||
private toData(): WorkflowClipboardData {
|
toClipboardData(nodes?: WorkflowNodeEntity[]): WorkflowClipboardData {
|
||||||
const validNodes = this.getValidNodes(this.selectedNodes);
|
const validNodes = this.getValidNodes(nodes ? nodes : this.selectedNodes);
|
||||||
const source = this.toSource();
|
const source = this.toSource();
|
||||||
const json = this.toJSON(validNodes);
|
const json = this.toJSON(validNodes);
|
||||||
const bounds = this.getEntireBounds(validNodes);
|
const bounds = this.getEntireBounds(validNodes);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import { Toast } from '@douyinfe/semi-ui';
|
|||||||
import { WorkflowClipboardData, WorkflowClipboardRect } from '../type';
|
import { WorkflowClipboardData, WorkflowClipboardRect } from '../type';
|
||||||
import { FlowCommandId, WorkflowClipboardDataID } from '../constants';
|
import { FlowCommandId, WorkflowClipboardDataID } from '../constants';
|
||||||
import { generateUniqueWorkflow } from './unique-workflow';
|
import { generateUniqueWorkflow } from './unique-workflow';
|
||||||
|
import { CopyShortcut } from '../copy';
|
||||||
|
|
||||||
export class PasteShortcut implements ShortcutsHandler {
|
export class PasteShortcut implements ShortcutsHandler {
|
||||||
public commandId = FlowCommandId.PASTE;
|
public commandId = FlowCommandId.PASTE;
|
||||||
@ -38,19 +39,31 @@ export class PasteShortcut implements ShortcutsHandler {
|
|||||||
/**
|
/**
|
||||||
* initialize paste shortcut handler - 初始化粘贴快捷键处理器
|
* initialize paste shortcut handler - 初始化粘贴快捷键处理器
|
||||||
*/
|
*/
|
||||||
constructor(context: FreeLayoutPluginContext) {
|
constructor(private context: FreeLayoutPluginContext) {
|
||||||
this.document = context.get(WorkflowDocument);
|
this.document = context.get(WorkflowDocument);
|
||||||
this.selectService = context.get(WorkflowSelectService);
|
this.selectService = context.get(WorkflowSelectService);
|
||||||
this.entityManager = context.get(EntityManager);
|
this.entityManager = context.get(EntityManager);
|
||||||
this.hoverService = context.get(WorkflowHoverService);
|
this.hoverService = context.get(WorkflowHoverService);
|
||||||
this.dragService = context.get(WorkflowDragService);
|
this.dragService = context.get(WorkflowDragService);
|
||||||
|
this.execute = this.execute.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* execute paste action - 执行粘贴操作
|
* execute paste action - 执行粘贴操作
|
||||||
|
* Usage:
|
||||||
|
* 1. clientContext.playground.commandService.executeCommand(FlowCommandId.PASTE, [node]);
|
||||||
|
* 2. keyboard: cmd + v
|
||||||
*/
|
*/
|
||||||
public async execute(): Promise<WorkflowNodeEntity[] | undefined> {
|
public async execute(
|
||||||
const data = await this.tryReadClipboard();
|
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) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user