node-registry.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import {
  6. DataEvent,
  7. EffectFuncProps,
  8. Field,
  9. FieldRenderProps,
  10. FormMeta,
  11. ValidateTrigger,
  12. WorkflowNodeRegistry,
  13. } from '@flowgram.ai/free-layout-editor';
  14. import { FieldWrapper } from '@flowgram.ai/demo-node-form';
  15. import { Input } from '@douyinfe/semi-ui';
  16. import '../index.css';
  17. const render = () => (
  18. <div className="demo-node-content">
  19. <div className="demo-node-title">Effect Examples</div>
  20. <Field name="field1">
  21. {({ field }: FieldRenderProps<string>) => (
  22. <FieldWrapper
  23. title="Basic effect"
  24. note={'The following field will console.log field value on value change'}
  25. >
  26. <Input size={'small'} {...field} />
  27. </FieldWrapper>
  28. )}
  29. </Field>
  30. <Field name="field2">
  31. {({ field }: FieldRenderProps<string>) => (
  32. <FieldWrapper
  33. title="Control other fields"
  34. note={'The following field will change Field 3 value on value change'}
  35. >
  36. <Input size={'small'} {...field} />
  37. </FieldWrapper>
  38. )}
  39. </Field>
  40. <Field name="field3">
  41. {({ field }: FieldRenderProps<string>) => (
  42. <FieldWrapper title="Field 3">
  43. <Input size={'small'} {...field} />
  44. </FieldWrapper>
  45. )}
  46. </Field>
  47. </div>
  48. );
  49. interface FormData {
  50. field1: string;
  51. field2: string;
  52. field3: string;
  53. }
  54. const formMeta: FormMeta<FormData> = {
  55. render,
  56. validateTrigger: ValidateTrigger.onChange,
  57. effect: {
  58. field1: [
  59. {
  60. event: DataEvent.onValueChange,
  61. effect: ({ value }: EffectFuncProps<string, FormData>) => {
  62. console.log('field1 value:', value);
  63. },
  64. },
  65. ],
  66. field2: [
  67. {
  68. event: DataEvent.onValueChange,
  69. effect: ({ value, form }: EffectFuncProps<string, FormData>) => {
  70. form.setValueIn('field3', 'field2 value is ' + value);
  71. },
  72. },
  73. ],
  74. },
  75. };
  76. export const nodeRegistry: WorkflowNodeRegistry = {
  77. type: 'custom',
  78. meta: {},
  79. defaultPorts: [{ type: 'output' }, { type: 'input' }],
  80. formMeta,
  81. };