Skip to content

Commit c200ab7

Browse files
committed
copy & paste values on connections and start flow from there
1 parent 024cddb commit c200ab7

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

libs/app-canvas/src/app/command-handlers/command-context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,9 @@ export interface ICommandContext<T extends BaseNodeInfo> {
1919
getNodeTaskFactory: (name: string) => NodeTaskFactory<T>;
2020
setupTasksInDropdown: (selectNodeTypeHTMLElement: HTMLSelectElement) => void;
2121
commandRegistry: Map<string, ICommandHandler>;
22+
onBeforeExecuteCommand?: (
23+
commandName: string,
24+
parameter1: any,
25+
parameter2: any
26+
) => boolean;
2227
}

libs/app-canvas/src/app/command-handlers/paste-node-command/paste-node-command.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export class PasteNodeCommand<
1919
this.rootElement = commandContext.rootElement;
2020
this.setupTasksInDropdown = commandContext.setupTasksInDropdown;
2121
this.commandRegistry = commandContext.commandRegistry;
22+
this.commandContext = commandContext;
2223
}
24+
static commandName = 'paste-node';
25+
commandContext: ICommandContext<T>;
2326
commandRegistry: Map<string, ICommandHandler>;
2427
rootElement: HTMLElement;
2528
getCanvasApp: () => IFlowCanvasBase<T> | undefined;
@@ -36,6 +39,17 @@ export class PasteNodeCommand<
3639
if (!canvasApp) {
3740
return;
3841
}
42+
43+
const shouldExecuteCommand =
44+
this.commandContext.onBeforeExecuteCommand?.(
45+
'paste-node',
46+
_parameter1,
47+
_parameter2
48+
) ?? true;
49+
if (shouldExecuteCommand === false) {
50+
return;
51+
}
52+
console.log('PasteNodeCommand.execute');
3953
const copyCommand = this.commandRegistry.get(
4054
'copy-node'
4155
) as CopyNodeCommand<T>;

libs/app-canvas/src/app/command-handlers/register-commands.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const registerCommands = <T extends BaseNodeInfo>(
2626
new CopyNodeCommand<T>(commandContext)
2727
);
2828
commandContext.commandRegistry.set(
29-
'paste-node',
29+
PasteNodeCommand.commandName,
3030
new PasteNodeCommand<T>(commandContext)
3131
);
3232
commandContext.commandRegistry.set(

libs/app-canvas/src/app/flow-app.element.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ import {
114114
removeAllCompositions,
115115
resetRunIndex,
116116
run,
117+
runNodeFromThumb,
117118
runPath,
118119
runPathForNodeConnectionPairs,
119120
runPathFromThumb,
120121
setRunCounterUpdateElement,
121122
setupCanvasNodeTaskRegistry,
122123
} from '@devhelpr/web-flow-executor';
124+
import { PasteNodeCommand } from './command-handlers/paste-node-command/paste-node-command';
123125

124126
export class CodeFlowWebAppCanvas {
125127
appRootSelector?: string;
@@ -800,6 +802,7 @@ export class FlowAppElement extends AppElement<NodeInfo> {
800802
getNodeTaskFactory,
801803
commandRegistry: this.commandRegistry,
802804
setupTasksInDropdown,
805+
onBeforeExecuteCommand: this.onBeforeExecuteCommand,
803806
});
804807
this.clearCanvas();
805808
}
@@ -2139,4 +2142,53 @@ export class FlowAppElement extends AppElement<NodeInfo> {
21392142
);
21402143
}
21412144
};
2145+
2146+
onBeforeExecuteCommand = (
2147+
command: string,
2148+
_parameter1: any,
2149+
_parameter2: any
2150+
) => {
2151+
// parameter1 is the nodeType
2152+
// parameter2 is the id of a selected node
2153+
if (command === PasteNodeCommand.commandName) {
2154+
const selectedNode = getSelectedNode();
2155+
if (selectedNode) {
2156+
const node = this.canvasApp?.elements.get(
2157+
selectedNode.id
2158+
) as IConnectionNodeComponent<NodeInfo>;
2159+
if (
2160+
node &&
2161+
node.nodeType === NodeType.Connection &&
2162+
node.endNode &&
2163+
node.startNodeThumb &&
2164+
this.canvasApp
2165+
) {
2166+
// Copy & paste clipboard to connection and trigger connection
2167+
2168+
const canvasApp = this.canvasApp;
2169+
const endNode = node.endNode;
2170+
const startNodeThumb = node.startNodeThumb;
2171+
navigator.clipboard.readText().then((text) => {
2172+
console.log('clipboard', text);
2173+
if (text) {
2174+
runNodeFromThumb(
2175+
startNodeThumb,
2176+
canvasApp,
2177+
() => {
2178+
//
2179+
},
2180+
text,
2181+
endNode,
2182+
undefined,
2183+
undefined,
2184+
this.createRunCounterContext(true, false)
2185+
);
2186+
}
2187+
});
2188+
return false;
2189+
}
2190+
}
2191+
}
2192+
return true;
2193+
};
21422194
}

0 commit comments

Comments
 (0)