fix(demo-free): create copy error (#174)

This commit is contained in:
xiamidaxia 2025-04-25 14:58:34 +08:00 committed by GitHub
parent cb942616ab
commit 61c7ad1a7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 7 deletions

View File

@ -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);

View File

@ -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;
} }