provide-json-schema-output.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 {
  8. provideJsonSchemaOutputs,
  9. syncVariableTitle,
  10. type IJsonSchema,
  11. } from '@flowgram.ai/form-materials';
  12. import { FreeFormMetaStoryBuilder, FormHeader } from '../../free-form-meta-story-builder';
  13. const JsonSchemaEditor = React.lazy(() =>
  14. import('@flowgram.ai/form-materials').then((module) => ({
  15. default: module.JsonSchemaEditor,
  16. }))
  17. );
  18. export const BasicStory = () => (
  19. <FreeFormMetaStoryBuilder
  20. filterStartNode
  21. transformInitialNode={{
  22. end_0: (node) => {
  23. node.data.inputsValues = {
  24. success: { type: 'constant', content: true, schema: { type: 'boolean' } },
  25. message: { type: 'ref', content: ['custom_0', 'name'] },
  26. };
  27. return node;
  28. },
  29. }}
  30. formMeta={{
  31. render: () => (
  32. <>
  33. <FormHeader />
  34. <Field<IJsonSchema | undefined>
  35. name="outputs"
  36. defaultValue={{
  37. type: 'object',
  38. properties: {
  39. name: { type: 'string' },
  40. age: { type: 'number' },
  41. },
  42. }}
  43. >
  44. {({ field }) => (
  45. <JsonSchemaEditor value={field.value} onChange={(value) => field.onChange(value)} />
  46. )}
  47. </Field>
  48. </>
  49. ),
  50. effect: {
  51. // Sync the title to variables
  52. title: syncVariableTitle,
  53. outputs: provideJsonSchemaOutputs,
  54. },
  55. }}
  56. />
  57. );