infer-assign-plugin.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import React from 'react';
  6. import { createInferAssignPlugin } from '@flowgram.ai/form-materials';
  7. import { FreeFormMetaStoryBuilder, FormHeader } from '../../free-form-meta-story-builder';
  8. const AssignRows = React.lazy(() =>
  9. import('@flowgram.ai/form-materials').then((module) => ({
  10. default: module.AssignRows,
  11. }))
  12. );
  13. const DisplayOutputs = React.lazy(() =>
  14. import('@flowgram.ai/form-materials').then((module) => ({
  15. default: module.DisplayOutputs,
  16. }))
  17. );
  18. export const BasicStory = () => (
  19. <FreeFormMetaStoryBuilder
  20. transformInitialNode={{
  21. end_0: (node) => {
  22. node.data.inputsValues = {
  23. info: {
  24. type: 'ref',
  25. content: ['custom_0', 'userInfo'],
  26. },
  27. };
  28. return node;
  29. },
  30. }}
  31. formMeta={{
  32. render: () => (
  33. <>
  34. <FormHeader />
  35. <AssignRows
  36. name="assign"
  37. defaultValue={[
  38. // 从常量声明变量
  39. {
  40. operator: 'declare',
  41. left: 'userName',
  42. right: {
  43. type: 'constant',
  44. content: 'John Doe',
  45. schema: { type: 'string' },
  46. },
  47. },
  48. // 从变量声明变量
  49. {
  50. operator: 'declare',
  51. left: 'userInfo',
  52. right: {
  53. type: 'ref',
  54. content: ['start_0', 'obj'],
  55. },
  56. },
  57. // 赋值现有变量
  58. {
  59. operator: 'assign',
  60. left: {
  61. type: 'ref',
  62. content: ['start_0', 'str'],
  63. },
  64. right: {
  65. type: 'constant',
  66. content: 'Hello Flowgram',
  67. schema: { type: 'string' },
  68. },
  69. },
  70. ]}
  71. />
  72. <DisplayOutputs displayFromScope style={{ marginTop: 10 }} />
  73. </>
  74. ),
  75. plugins: [
  76. createInferAssignPlugin({
  77. assignKey: 'assign',
  78. outputKey: 'outputs',
  79. }),
  80. ],
  81. }}
  82. />
  83. );