sync-variable-title.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import React from 'react';
  6. import { Field } from '@flowgram.ai/free-layout-editor';
  7. import { provideJsonSchemaOutputs, syncVariableTitle } from '@flowgram.ai/form-materials';
  8. import { FreeFormMetaStoryBuilder, FormHeader } from '../../free-form-meta-story-builder';
  9. const Input = React.lazy(() =>
  10. import('@douyinfe/semi-ui').then((module) => ({
  11. default: module.Input,
  12. }))
  13. );
  14. export const BasicStory = () => (
  15. <FreeFormMetaStoryBuilder
  16. filterStartNode
  17. transformInitialNode={{
  18. end_0: (node) => {
  19. node.data.inputsValues = {
  20. success: { type: 'constant', content: true, schema: { type: 'boolean' } },
  21. message: { type: 'ref', content: ['custom_0', 'name'] },
  22. };
  23. return node;
  24. },
  25. custom_0: (node) => {
  26. node.data.outputs = {
  27. type: 'object',
  28. properties: {
  29. name: { type: 'string' },
  30. age: { type: 'number' },
  31. },
  32. };
  33. return node;
  34. },
  35. }}
  36. formMeta={{
  37. render: () => (
  38. <>
  39. <FormHeader />
  40. <p>Please Edit Title below to sync to variables:</p>
  41. <Field<string | undefined> name="title">
  42. {({ field }) => (
  43. <Input value={field.value} onChange={(value) => field.onChange(value)} />
  44. )}
  45. </Field>
  46. </>
  47. ),
  48. effect: {
  49. // Sync the title to variables
  50. title: syncVariableTitle,
  51. outputs: provideJsonSchemaOutputs,
  52. },
  53. }}
  54. />
  55. );