2
0

use-editor-props.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. Field,
  8. FreeLayoutProps,
  9. PlaygroundConfigEntity,
  10. WorkflowLinesManager,
  11. } from '@flowgram.ai/free-layout-editor';
  12. import { updatePosition } from './update-position';
  13. import { NodeRender } from './node-render';
  14. import { nodeRegistries } from './node-registries';
  15. import { NodeColorMap } from './node-color';
  16. import { initialData } from './initial-data';
  17. export const useEditorProps = () =>
  18. useMemo<FreeLayoutProps>(
  19. () => ({
  20. background: false,
  21. materials: {
  22. renderDefaultNode: NodeRender,
  23. },
  24. isHideArrowLine: (ctx, line) => {
  25. if (line.from && line.to) {
  26. return true;
  27. }
  28. return false;
  29. },
  30. nodeRegistries,
  31. initialData,
  32. onInit: (ctx) => {
  33. const linesManager = ctx.get(WorkflowLinesManager);
  34. linesManager.getLineColor = (line) => {
  35. const lineColor = NodeColorMap[line.from?.id ?? line.to?.id ?? ''] ?? '#000';
  36. return lineColor;
  37. };
  38. },
  39. onAllLayersRendered: (ctx) => {
  40. ctx.tools.fitView(false);
  41. // disable playground operations
  42. const playgroundConfig = ctx.get(PlaygroundConfigEntity);
  43. playgroundConfig.updateConfig = () => {};
  44. updatePosition(ctx);
  45. },
  46. getNodeDefaultRegistry(type) {
  47. return {
  48. type,
  49. meta: {
  50. defaultExpanded: true,
  51. },
  52. formMeta: {
  53. /**
  54. * Render form
  55. */
  56. render: () => (
  57. <>
  58. <Field<string> name="title">{({ field }) => <div>{field.value}</div>}</Field>
  59. </>
  60. ),
  61. },
  62. };
  63. },
  64. }),
  65. []
  66. );