2
0

add-node.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {
  2. useService,
  3. WorkflowDocument,
  4. WorkflowNodeEntity,
  5. WorkflowSelectService,
  6. } from '@flowgram.ai/free-layout-editor';
  7. export const AddNode = () => {
  8. const workflowDocument = useService(WorkflowDocument);
  9. const selectService = useService(WorkflowSelectService);
  10. return (
  11. <div style={{ position: 'absolute', zIndex: 10, bottom: 16, left: 8, display: 'flex', gap: 8 }}>
  12. <button
  13. style={{
  14. border: '1px solid #e0e0e0',
  15. borderRadius: '50%',
  16. cursor: 'pointer',
  17. padding: '4px',
  18. color: '#ffffff',
  19. background: '#7e72e8',
  20. width: 70,
  21. height: 70,
  22. fontSize: 14,
  23. }}
  24. onClick={() => {
  25. const node: WorkflowNodeEntity = workflowDocument.createWorkflowNodeByType(
  26. 'custom',
  27. undefined, // position undefined means create node in center of canvas - position undefined 可以在画布中间创建节点
  28. {
  29. data: {
  30. title: 'New Node',
  31. },
  32. }
  33. );
  34. selectService.selectNode(node);
  35. }}
  36. >
  37. + Node
  38. </button>
  39. </div>
  40. );
  41. };