2
0

infer-inputs-plugin.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 { createInferInputsPlugin } from '@flowgram.ai/form-materials';
  8. import { FreeFormMetaStoryBuilder, FormHeader } from '../../free-form-meta-story-builder';
  9. const InputsValues = React.lazy(() =>
  10. import('@flowgram.ai/form-materials').then((module) => ({
  11. default: module.InputsValues,
  12. }))
  13. );
  14. const InputsValuesTree = React.lazy(() =>
  15. import('@flowgram.ai/form-materials').then((module) => ({
  16. default: module.InputsValuesTree,
  17. }))
  18. );
  19. /**
  20. * Basic usage story - demonstrates automatic schema inference from InputsValues
  21. */
  22. export const BasicStory = () => (
  23. <FreeFormMetaStoryBuilder
  24. filterEndNode
  25. height={500}
  26. formMeta={{
  27. render: () => (
  28. <>
  29. <FormHeader />
  30. <div>
  31. <div>
  32. <h4>Headers</h4>
  33. <Field<Record<string, any> | undefined>
  34. name="headersValues"
  35. defaultValue={{
  36. 'Content-Type': {
  37. type: 'constant',
  38. content: 'application/json',
  39. schema: { type: 'string' },
  40. },
  41. Authorization: {
  42. type: 'ref',
  43. content: ['start_0', 'str'],
  44. },
  45. }}
  46. >
  47. {({ field }) => (
  48. <InputsValues value={field.value} onChange={(value) => field.onChange(value)} />
  49. )}
  50. </Field>
  51. </div>
  52. <div>
  53. <h4>Body</h4>
  54. <Field<Record<string, any> | undefined>
  55. name="bodyValues"
  56. defaultValue={{
  57. page: {
  58. index: {
  59. type: 'ref',
  60. content: ['start_0', 'obj', 'obj2', 'num'],
  61. },
  62. size: {
  63. type: 'constant',
  64. content: 10,
  65. schema: { type: 'number' },
  66. },
  67. },
  68. query: {
  69. type: 'ref',
  70. content: ['start_0', 'obj'],
  71. },
  72. }}
  73. >
  74. {({ field }) => (
  75. <InputsValuesTree
  76. value={field.value}
  77. onChange={(value) => field.onChange(value)}
  78. />
  79. )}
  80. </Field>
  81. </div>
  82. </div>
  83. </>
  84. ),
  85. plugins: [
  86. createInferInputsPlugin({
  87. sourceKey: 'headersValues',
  88. targetKey: 'headersSchema',
  89. }),
  90. createInferInputsPlugin({
  91. sourceKey: 'bodyValues',
  92. targetKey: 'bodySchema',
  93. }),
  94. ],
  95. }}
  96. />
  97. );