editor.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { useMemo } from 'react';
  6. import {
  7. Command,
  8. PlaygroundReact,
  9. PlaygroundReactContent,
  10. PlaygroundReactProps,
  11. } from '@flowgram.ai/playground-react';
  12. import { PlaygroundTools } from './components/playground-tools';
  13. import { StaticCard, DragableCard } from './components/card';
  14. // Load style
  15. import '@flowgram.ai/playground-react/index.css';
  16. /**
  17. * The ability to zoom to provide an infinite canvas
  18. */
  19. export function PlaygroundEditor(props: { className?: string }) {
  20. const playgroundProps = useMemo<PlaygroundReactProps>(
  21. () => ({
  22. background: true, // Background available
  23. playground: {
  24. ineractiveType: 'PAD', // MOUSE | PAD
  25. },
  26. // 自定义快捷键
  27. shortcuts(registry, ctx) {
  28. registry.addHandlers(
  29. /**
  30. * Zoom In
  31. */
  32. {
  33. commandId: Command.Default.ZOOM_IN,
  34. shortcuts: ['meta =', 'ctrl ='],
  35. execute: () => {
  36. ctx.playground.config.zoomin();
  37. },
  38. },
  39. /**
  40. * Zoom Out
  41. */
  42. {
  43. commandId: Command.Default.ZOOM_OUT,
  44. shortcuts: ['meta -', 'ctrl -'],
  45. execute: () => {
  46. ctx.playground.config.zoomout();
  47. },
  48. }
  49. );
  50. },
  51. }),
  52. []
  53. );
  54. /*
  55. * PlaygroundReact: Canvas React containers 画布 react 容器
  56. * PlaygroundReactContent: The canvas content will be scaled accordingly 画布内容,会跟着缩放
  57. */
  58. return (
  59. <div className={props.className}>
  60. <PlaygroundReact {...playgroundProps}>
  61. <PlaygroundReactContent>
  62. <StaticCard />
  63. <DragableCard />
  64. </PlaygroundReactContent>
  65. <PlaygroundTools />
  66. </PlaygroundReact>
  67. </div>
  68. );
  69. }