@flowgram.ai/form-materials 0.1.0-alpha.10 → 0.1.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/bin/index.ts +11 -5
  2. package/bin/materials.ts +10 -1
  3. package/dist/esm/index.js +1996 -1361
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/index.d.mts +328 -114
  6. package/dist/index.d.ts +328 -114
  7. package/dist/index.js +2096 -1472
  8. package/dist/index.js.map +1 -1
  9. package/package.json +7 -5
  10. package/src/components/assign-row/components/blur-input.tsx +27 -0
  11. package/src/components/assign-row/config.json +11 -0
  12. package/src/components/assign-row/index.tsx +84 -0
  13. package/src/components/assign-row/types.ts +25 -0
  14. package/src/components/assign-rows/config.json +11 -0
  15. package/src/components/assign-rows/index.tsx +59 -0
  16. package/src/components/batch-outputs/config.json +2 -1
  17. package/src/components/batch-outputs/index.tsx +4 -12
  18. package/src/components/batch-variable-selector/config.json +6 -2
  19. package/src/components/batch-variable-selector/index.tsx +1 -1
  20. package/src/components/code-editor/config.json +2 -1
  21. package/src/components/code-editor/index.tsx +23 -1
  22. package/src/components/code-editor/language-features.ts +23 -3
  23. package/src/components/code-editor/theme/light.ts +2 -2
  24. package/src/components/code-editor-mini/config.json +7 -0
  25. package/src/components/code-editor-mini/index.tsx +31 -0
  26. package/src/components/condition-row/config.json +10 -2
  27. package/src/components/condition-row/constants.ts +6 -8
  28. package/src/components/condition-row/hooks/useOp.tsx +3 -1
  29. package/src/components/condition-row/hooks/useRule.ts +2 -2
  30. package/src/components/condition-row/index.tsx +2 -1
  31. package/src/components/condition-row/types.ts +3 -1
  32. package/src/components/constant-input/config.json +6 -3
  33. package/src/components/constant-input/index.tsx +18 -62
  34. package/src/components/constant-input/types.ts +6 -9
  35. package/src/components/display-flow-value/config.json +8 -0
  36. package/src/components/display-flow-value/index.tsx +59 -0
  37. package/src/components/display-inputs-values/config.json +9 -0
  38. package/src/components/display-inputs-values/index.tsx +27 -0
  39. package/src/components/display-inputs-values/styles.ts +12 -0
  40. package/src/components/display-outputs/config.json +10 -0
  41. package/src/components/display-outputs/index.tsx +64 -0
  42. package/src/components/display-outputs/styles.ts +12 -0
  43. package/src/components/display-schema-tag/config.json +10 -0
  44. package/src/components/display-schema-tag/index.tsx +44 -0
  45. package/src/components/display-schema-tag/styles.ts +28 -0
  46. package/src/components/display-schema-tree/config.json +11 -0
  47. package/src/components/display-schema-tree/index.tsx +74 -0
  48. package/src/components/display-schema-tree/styles.tsx +90 -0
  49. package/src/components/dynamic-value-input/config.json +11 -2
  50. package/src/components/dynamic-value-input/hooks.ts +53 -0
  51. package/src/components/dynamic-value-input/index.tsx +64 -13
  52. package/src/components/dynamic-value-input/styles.tsx +28 -2
  53. package/src/components/index.ts +9 -0
  54. package/src/components/inputs-values/components/blur-input.tsx +27 -0
  55. package/src/components/inputs-values/config.json +13 -0
  56. package/src/components/inputs-values/index.tsx +73 -0
  57. package/src/components/inputs-values/styles.tsx +19 -0
  58. package/src/components/inputs-values/types.ts +22 -0
  59. package/src/components/json-editor-with-variables/index.tsx +47 -1
  60. package/src/components/json-schema-editor/config.json +2 -2
  61. package/src/components/json-schema-editor/default-value.tsx +1 -1
  62. package/src/components/json-schema-editor/hooks.tsx +4 -2
  63. package/src/components/json-schema-editor/index.tsx +15 -2
  64. package/src/components/json-schema-editor/types.ts +1 -1
  65. package/src/components/prompt-editor/index.tsx +2 -1
  66. package/src/components/prompt-editor/types.tsx +1 -0
  67. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +1 -1
  68. package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +6 -3
  69. package/src/components/type-selector/config.json +6 -2
  70. package/src/components/type-selector/index.tsx +55 -12
  71. package/src/components/variable-selector/config.json +6 -2
  72. package/src/components/variable-selector/index.tsx +34 -13
  73. package/src/components/variable-selector/styles.tsx +18 -8
  74. package/src/components/variable-selector/use-variable-tree.tsx +19 -22
  75. package/src/effects/auto-rename-ref/index.ts +59 -8
  76. package/src/effects/index.ts +3 -1
  77. package/src/effects/listen-ref-schema-change/config.json +10 -0
  78. package/src/effects/listen-ref-schema-change/index.ts +56 -0
  79. package/src/effects/listen-ref-value-change/config.json +9 -0
  80. package/src/effects/listen-ref-value-change/index.ts +53 -0
  81. package/src/effects/provide-json-schema-outputs/config.json +4 -5
  82. package/src/effects/provide-json-schema-outputs/index.ts +1 -3
  83. package/src/effects/sync-variable-title/index.ts +1 -0
  84. package/src/effects/validate-when-variable-sync/config.json +5 -0
  85. package/src/effects/validate-when-variable-sync/index.ts +35 -0
  86. package/src/form-plugins/index.ts +3 -1
  87. package/src/form-plugins/infer-assign-plugin/config.json +7 -0
  88. package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
  89. package/src/form-plugins/infer-inputs-plugin/config.json +9 -0
  90. package/src/form-plugins/infer-inputs-plugin/index.ts +108 -0
  91. package/src/hooks/index.tsx +6 -0
  92. package/src/hooks/use-object-list/config.json +8 -0
  93. package/src/hooks/use-object-list/index.tsx +136 -0
  94. package/src/index.ts +3 -1
  95. package/src/{typings/json-schema → plugins/disable-declaration-plugin}/config.json +1 -1
  96. package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
  97. package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
  98. package/src/plugins/index.ts +7 -0
  99. package/src/plugins/json-schema-preset/config.json +9 -0
  100. package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +28 -0
  101. package/src/plugins/json-schema-preset/index.tsx +41 -0
  102. package/src/plugins/json-schema-preset/manager.ts +18 -0
  103. package/src/plugins/json-schema-preset/type-definition/array.tsx +24 -0
  104. package/src/plugins/json-schema-preset/type-definition/boolean.tsx +32 -0
  105. package/src/plugins/json-schema-preset/type-definition/index.tsx +24 -0
  106. package/src/plugins/json-schema-preset/type-definition/integer.tsx +24 -0
  107. package/src/plugins/json-schema-preset/type-definition/number.tsx +24 -0
  108. package/src/plugins/json-schema-preset/type-definition/object.tsx +24 -0
  109. package/src/plugins/json-schema-preset/type-definition/string.tsx +18 -0
  110. package/src/{utils → shared}/index.ts +0 -1
  111. package/src/typings/flow-value/config.json +3 -1
  112. package/src/typings/flow-value/index.ts +11 -0
  113. package/src/typings/index.ts +0 -1
  114. package/src/validate/index.tsx +6 -0
  115. package/src/validate/validate-flow-value/config.json +7 -0
  116. package/src/validate/validate-flow-value/index.tsx +73 -0
  117. package/src/components/batch-outputs/use-list.ts +0 -86
  118. package/src/components/type-selector/constants.tsx +0 -364
  119. package/src/effects/provide-batch-outputs/config.json +0 -5
  120. package/src/effects/provide-batch-outputs/index.ts +0 -38
  121. package/src/typings/json-schema/index.ts +0 -36
  122. package/src/utils/json-schema/config.json +0 -5
  123. package/src/utils/json-schema/index.ts +0 -180
  124. /package/src/{utils → shared}/format-legacy-refs/config.json +0 -0
  125. /package/src/{utils → shared}/format-legacy-refs/index.ts +0 -0
  126. /package/src/{utils → shared}/format-legacy-refs/readme.md +0 -0
@@ -6,79 +6,35 @@
6
6
  /* eslint-disable react/prop-types */
7
7
  import React, { useMemo } from 'react';
8
8
 
9
- import { Input, InputNumber, Select } from '@douyinfe/semi-ui';
9
+ import { Input } from '@douyinfe/semi-ui';
10
10
 
11
- import { PropsType, Strategy } from './types';
12
-
13
- const defaultStrategies: Strategy[] = [
14
- {
15
- hit: (schema) => schema?.type === 'string',
16
- Renderer: (props) => (
17
- <Input placeholder="Please Input String" size="small" disabled={props.readonly} {...props} />
18
- ),
19
- },
20
- {
21
- hit: (schema) => schema?.type === 'number',
22
- Renderer: (props) => (
23
- <InputNumber
24
- placeholder="Please Input Number"
25
- size="small"
26
- disabled={props.readonly}
27
- hideButtons
28
- {...props}
29
- />
30
- ),
31
- },
32
- {
33
- hit: (schema) => schema?.type === 'integer',
34
- Renderer: (props) => (
35
- <InputNumber
36
- placeholder="Please Input Integer"
37
- size="small"
38
- disabled={props.readonly}
39
- hideButtons
40
- precision={0}
41
- {...props}
42
- />
43
- ),
44
- },
45
- {
46
- hit: (schema) => schema?.type === 'boolean',
47
- Renderer: (props) => {
48
- const { value, onChange, ...rest } = props;
49
- return (
50
- <Select
51
- placeholder="Please Select Boolean"
52
- size="small"
53
- disabled={props.readonly}
54
- optionList={[
55
- { label: 'True', value: 1 },
56
- { label: 'False', value: 0 },
57
- ]}
58
- value={value ? 1 : 0}
59
- onChange={(value) => onChange?.(!!value)}
60
- {...rest}
61
- />
62
- );
63
- },
64
- },
65
- ];
11
+ import { useTypeManager } from '../../plugins';
12
+ import { PropsType } from './types';
66
13
 
67
14
  export function ConstantInput(props: PropsType) {
68
- const { value, onChange, schema, strategies: extraStrategies, readonly, ...rest } = props;
15
+ const { value, onChange, schema, strategies, fallbackRenderer, readonly, ...rest } = props;
69
16
 
70
- const strategies = useMemo(
71
- () => [...defaultStrategies, ...(extraStrategies || [])],
72
- [extraStrategies]
73
- );
17
+ const typeManager = useTypeManager();
74
18
 
75
19
  const Renderer = useMemo(() => {
76
- const strategy = strategies.find((_strategy) => _strategy.hit(schema));
20
+ const strategy = (strategies || []).find((_strategy) => _strategy.hit(schema));
21
+
22
+ if (!strategy) {
23
+ return typeManager.getTypeBySchema(schema)?.ConstantRenderer;
24
+ }
77
25
 
78
26
  return strategy?.Renderer;
79
27
  }, [strategies, schema]);
80
28
 
81
29
  if (!Renderer) {
30
+ if (fallbackRenderer) {
31
+ return React.createElement(fallbackRenderer, {
32
+ value,
33
+ onChange,
34
+ readonly,
35
+ ...rest,
36
+ });
37
+ }
82
38
  return <Input size="small" disabled placeholder="Unsupported type" />;
83
39
  }
84
40
 
@@ -3,21 +3,18 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import { IJsonSchema } from '../../typings';
6
+ import { IJsonSchema } from '@flowgram.ai/json-schema';
7
+
8
+ import { ConstantRendererProps } from '../../plugins';
7
9
 
8
10
  export interface Strategy<Value = any> {
9
11
  hit: (schema: IJsonSchema) => boolean;
10
- Renderer: React.FC<RendererProps<Value>>;
11
- }
12
-
13
- export interface RendererProps<Value = any> {
14
- value?: Value;
15
- onChange?: (value: Value) => void;
16
- readonly?: boolean;
12
+ Renderer: React.FC<ConstantRendererProps<Value>>;
17
13
  }
18
14
 
19
- export interface PropsType extends RendererProps {
15
+ export interface PropsType extends ConstantRendererProps {
20
16
  schema: IJsonSchema;
21
17
  strategies?: Strategy[];
18
+ fallbackRenderer?: React.FC<ConstantRendererProps>;
22
19
  [key: string]: any;
23
20
  }
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "display-flow-value",
3
+ "depMaterials": [
4
+ "components/display-schema-tag",
5
+ "typings/flow-value"
6
+ ],
7
+ "depPackages": []
8
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React, { useMemo } from 'react';
7
+
8
+ import { JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
9
+ import { useScopeAvailable } from '@flowgram.ai/editor';
10
+
11
+ import { DisplaySchemaTag } from '../display-schema-tag';
12
+ import { IFlowValue } from '../../typings';
13
+
14
+ interface PropsType {
15
+ value?: IFlowValue;
16
+ title?: JSX.Element | string;
17
+ showIconInTree?: boolean;
18
+ typeManager?: JsonSchemaTypeManager;
19
+ }
20
+
21
+ export function DisplayFlowValue({ value, title, showIconInTree }: PropsType) {
22
+ const available = useScopeAvailable();
23
+
24
+ const variable = value?.type === 'ref' ? available.getByKeyPath(value?.content) : undefined;
25
+
26
+ const schema = useMemo(() => {
27
+ if (value?.type === 'ref') {
28
+ return JsonSchemaUtils.astToSchema(variable?.type);
29
+ }
30
+ if (value?.type === 'template') {
31
+ return { type: 'string' };
32
+ }
33
+ if (value?.type === 'constant') {
34
+ if (value?.schema) {
35
+ return value?.schema;
36
+ }
37
+ if (typeof value?.content === 'string') {
38
+ return { type: 'string' };
39
+ }
40
+ if (typeof value?.content === 'number') {
41
+ return { type: 'number' };
42
+ }
43
+ if (typeof value?.content === 'boolean') {
44
+ return { type: 'boolean' };
45
+ }
46
+ }
47
+
48
+ return { type: 'unknown' };
49
+ }, [value, variable?.hash]);
50
+
51
+ return (
52
+ <DisplaySchemaTag
53
+ title={title}
54
+ value={schema}
55
+ showIconInTree={showIconInTree}
56
+ warning={value?.type === 'ref' && !variable}
57
+ />
58
+ );
59
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "display-outputs",
3
+ "depMaterials": [
4
+ "components/display-schema-tag"
5
+ ],
6
+ "depPackages": [
7
+ "@douyinfe/semi-ui"
8
+ ]
9
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React from 'react';
7
+
8
+ import { DisplayFlowValue } from '../display-flow-value';
9
+ import { IFlowValue } from '../../typings';
10
+ import { DisplayInputsWrapper } from './styles';
11
+
12
+ interface PropsType {
13
+ value?: Record<string, IFlowValue | undefined>;
14
+ showIconInTree?: boolean;
15
+ }
16
+
17
+ export function DisplayInputsValues({ value, showIconInTree }: PropsType) {
18
+ const childEntries = Object.entries(value || {});
19
+
20
+ return (
21
+ <DisplayInputsWrapper>
22
+ {childEntries.map(([key, value]) => (
23
+ <DisplayFlowValue key={key} title={key} value={value} showIconInTree={showIconInTree} />
24
+ ))}
25
+ </DisplayInputsWrapper>
26
+ );
27
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import styled from 'styled-components';
7
+
8
+ export const DisplayInputsWrapper = styled.div`
9
+ display: flex;
10
+ gap: 5px;
11
+ flex-wrap: wrap;
12
+ `;
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "display-outputs",
3
+ "depMaterials": [
4
+ "components/display-flow-value"
5
+ ],
6
+ "depPackages": [
7
+ "@douyinfe/semi-ui",
8
+ "styled-components"
9
+ ]
10
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React, { useEffect } from 'react';
7
+
8
+ import { IJsonSchema, JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
9
+ import { useCurrentScope, useRefresh } from '@flowgram.ai/editor';
10
+
11
+ import { DisplaySchemaTag } from '../display-schema-tag';
12
+ import { DisplayOutputsWrapper } from './styles';
13
+
14
+ interface PropsType {
15
+ value?: IJsonSchema;
16
+ showIconInTree?: boolean;
17
+ displayFromScope?: boolean;
18
+ typeManager?: JsonSchemaTypeManager;
19
+ }
20
+
21
+ export function DisplayOutputs({ value, showIconInTree, displayFromScope }: PropsType) {
22
+ const scope = useCurrentScope();
23
+ const refresh = useRefresh();
24
+
25
+ useEffect(() => {
26
+ if (!displayFromScope) {
27
+ return () => null;
28
+ }
29
+
30
+ const disposable = scope.output.onListOrAnyVarChange(() => {
31
+ refresh();
32
+ });
33
+
34
+ return () => {
35
+ disposable.dispose();
36
+ };
37
+ }, [displayFromScope]);
38
+
39
+ const properties: IJsonSchema['properties'] = displayFromScope
40
+ ? scope.output.variables?.reduce((acm, curr) => {
41
+ acm = {
42
+ ...acm,
43
+ ...(JsonSchemaUtils.astToSchema(curr.type)?.properties || {}),
44
+ };
45
+ return acm;
46
+ }, {})
47
+ : value?.properties || {};
48
+
49
+ const childEntries = Object.entries(properties || {});
50
+
51
+ return (
52
+ <DisplayOutputsWrapper>
53
+ {childEntries.map(([key, schema]) => (
54
+ <DisplaySchemaTag
55
+ key={key}
56
+ title={key}
57
+ value={schema}
58
+ showIconInTree={showIconInTree}
59
+ warning={!schema}
60
+ />
61
+ ))}
62
+ </DisplayOutputsWrapper>
63
+ );
64
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import styled from 'styled-components';
7
+
8
+ export const DisplayOutputsWrapper = styled.div`
9
+ display: flex;
10
+ gap: 5px;
11
+ flex-wrap: wrap;
12
+ `;
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "display-schema-tag",
3
+ "depMaterials": [
4
+ "components/display-schema-tree"
5
+ ],
6
+ "depPackages": [
7
+ "@douyinfe/semi-ui",
8
+ "styled-components"
9
+ ]
10
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React from 'react';
7
+
8
+ import { IJsonSchema } from '@flowgram.ai/json-schema';
9
+ import { Popover } from '@douyinfe/semi-ui';
10
+
11
+ import { DisplaySchemaTree } from '../display-schema-tree';
12
+ import { useTypeManager } from '../../plugins';
13
+ import { PopoverContent, StyledTag, TitleSpan } from './styles';
14
+
15
+ interface PropsType {
16
+ title?: JSX.Element | string;
17
+ value?: IJsonSchema;
18
+ showIconInTree?: boolean;
19
+ warning?: boolean;
20
+ }
21
+
22
+ export function DisplaySchemaTag({ value = {}, showIconInTree, title, warning }: PropsType) {
23
+ const typeManager = useTypeManager();
24
+ const icon =
25
+ typeManager?.getDisplayIcon(value) || typeManager.getDisplayIcon({ type: 'unknown' });
26
+
27
+ return (
28
+ <Popover
29
+ content={
30
+ <PopoverContent>
31
+ <DisplaySchemaTree value={value} typeManager={typeManager} showIcon={showIconInTree} />
32
+ </PopoverContent>
33
+ }
34
+ >
35
+ <StyledTag color={warning ? 'amber' : 'white'}>
36
+ {icon &&
37
+ React.cloneElement(icon, {
38
+ className: 'tag-icon',
39
+ })}
40
+ {title && <TitleSpan>{title}</TitleSpan>}
41
+ </StyledTag>
42
+ </Popover>
43
+ );
44
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import styled from 'styled-components';
7
+ import { Tag } from '@douyinfe/semi-ui';
8
+
9
+ export const PopoverContent = styled.div`
10
+ padding: 10px;
11
+ `;
12
+
13
+ export const StyledTag = styled(Tag)`
14
+ padding: 4px;
15
+
16
+ .tag-icon {
17
+ width: 12px;
18
+ height: 12px;
19
+ }
20
+ `;
21
+
22
+ export const TitleSpan = styled.span`
23
+ display: inline-block;
24
+ margin-left: 4px;
25
+ margin-top: -1px;
26
+ overflow: hidden;
27
+ text-overflow: ellipsis;
28
+ `;
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "display-schema-tree",
3
+ "depMaterials": [
4
+ "plugins/json-schema-preset"
5
+ ],
6
+ "depPackages": [
7
+ "@douyinfe/semi-ui",
8
+ "styled-components",
9
+ "@flowgram.ai/json-schema"
10
+ ]
11
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React from 'react';
7
+
8
+ import { IJsonSchema, JsonSchemaTypeManager } from '@flowgram.ai/json-schema';
9
+
10
+ import { useTypeManager } from '../../plugins';
11
+ import { HorizontalLine, TreeItem, TreeLevel, TreeRow, TreeTitle } from './styles';
12
+
13
+ interface PropsType {
14
+ value?: IJsonSchema;
15
+ parentKey?: string;
16
+ depth?: number;
17
+ drilldown?: boolean;
18
+ showIcon?: boolean;
19
+ typeManager?: JsonSchemaTypeManager;
20
+ }
21
+
22
+ export function DisplaySchemaTree(props: Omit<PropsType, 'parentKey' | 'depth'>) {
23
+ return <SchemaTree {...props} />;
24
+ }
25
+
26
+ function SchemaTree(props: PropsType) {
27
+ const {
28
+ value: schema = {},
29
+ drilldown = true,
30
+ depth = 0,
31
+ showIcon = true,
32
+ parentKey = '',
33
+ } = props || {};
34
+
35
+ const typeManager = useTypeManager();
36
+
37
+ const config = typeManager.getTypeBySchema(schema);
38
+ const title = typeManager.getComplexText(schema);
39
+ const icon = typeManager?.getDisplayIcon(schema);
40
+ let properties: IJsonSchema['properties'] =
41
+ drilldown && config ? config.getTypeSchemaProperties(schema) : {};
42
+ const childEntries = Object.entries(properties || {});
43
+
44
+ return (
45
+ <TreeItem depth={depth} key={parentKey || 'root'}>
46
+ <TreeRow>
47
+ {depth !== 0 && <HorizontalLine />}
48
+ {showIcon &&
49
+ icon &&
50
+ React.cloneElement(icon, {
51
+ className: 'tree-icon',
52
+ })}
53
+ <TreeTitle>
54
+ {parentKey ? (
55
+ <>
56
+ {`${parentKey} (`}
57
+ {title}
58
+ {')'}
59
+ </>
60
+ ) : (
61
+ title
62
+ )}
63
+ </TreeTitle>
64
+ </TreeRow>
65
+ {childEntries?.length ? (
66
+ <TreeLevel>
67
+ {childEntries.map(([key, value]) => (
68
+ <SchemaTree key={key} {...props} parentKey={key} value={value} depth={depth + 1} />
69
+ ))}
70
+ </TreeLevel>
71
+ ) : null}
72
+ </TreeItem>
73
+ );
74
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import styled, { css } from 'styled-components';
7
+
8
+ export const TreeRow = styled.div`
9
+ display: flex;
10
+ align-items: center;
11
+
12
+ .tree-icon {
13
+ margin-right: 8px;
14
+ width: 14px;
15
+ height: 14px;
16
+ }
17
+
18
+ height: 27px;
19
+ white-space: nowrap;
20
+ `;
21
+
22
+ export const HorizontalLine = styled.div`
23
+ position: relative;
24
+
25
+ &::before,
26
+ &::after {
27
+ content: '';
28
+ position: absolute;
29
+ background-color: var(--semi-color-text-3);
30
+ }
31
+
32
+ &::after {
33
+ top: 0px;
34
+ right: 6px;
35
+ width: 15px;
36
+ height: 1px;
37
+ }
38
+ `;
39
+
40
+ export const TreeTitle = styled.div`
41
+ // overflow: hidden;
42
+ // text-overflow: ellipsis;
43
+ `;
44
+
45
+ export const TreeLevel = styled.div`
46
+ padding-left: 30px;
47
+ position: relative;
48
+
49
+ /* &::before {
50
+ content: '';
51
+ position: absolute;
52
+ background-color: var(--semi-color-text-3);
53
+ top: 0px;
54
+ bottom: 0px;
55
+ left: -22px;
56
+ width: 1px;
57
+ } */
58
+ `;
59
+
60
+ export const TreeItem = styled.div<{ depth: number }>`
61
+ position: relative;
62
+
63
+ &::before {
64
+ content: '';
65
+ position: absolute;
66
+ background-color: var(--semi-color-text-3);
67
+ }
68
+
69
+ &:not(:last-child)::before {
70
+ width: 1px;
71
+ top: 0;
72
+ bottom: 0;
73
+ left: -22px;
74
+ }
75
+
76
+ &:last-child::before {
77
+ width: 1px;
78
+ top: 0;
79
+ height: 14px;
80
+ left: -22px;
81
+ }
82
+
83
+ ${(props) =>
84
+ props.depth === 0 &&
85
+ css`
86
+ &::before {
87
+ width: 0px !important;
88
+ }
89
+ `}
90
+ `;
@@ -1,5 +1,14 @@
1
1
  {
2
2
  "name": "dynamic-value-input",
3
- "depMaterials": ["flow-value", "constant-input", "variable-selector"],
4
- "depPackages": ["@douyinfe/semi-ui", "@douyinfe/semi-icons", "styled-components"]
3
+ "depMaterials": [
4
+ "flow-value",
5
+ "constant-input",
6
+ "variable-selector"
7
+ ],
8
+ "depPackages": [
9
+ "@douyinfe/semi-ui",
10
+ "@douyinfe/semi-icons",
11
+ "styled-components",
12
+ "@flowgram.ai/json-schema"
13
+ ]
5
14
  }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { useMemo, useState } from 'react';
7
+
8
+ import { IJsonSchema } from '@flowgram.ai/json-schema';
9
+ import { useScopeAvailable } from '@flowgram.ai/editor';
10
+
11
+ import { IFlowConstantRefValue } from '../../typings/flow-value';
12
+
13
+ export function useRefVariable(value?: IFlowConstantRefValue) {
14
+ const available = useScopeAvailable();
15
+ const refVariable = useMemo(() => {
16
+ if (value?.type === 'ref') {
17
+ return available.getByKeyPath(value.content);
18
+ }
19
+ }, [value, available]);
20
+
21
+ return refVariable;
22
+ }
23
+
24
+ export function useSelectSchema(
25
+ schemaFromProps?: IJsonSchema,
26
+ constantProps?: {
27
+ schema?: IJsonSchema;
28
+ },
29
+ value?: IFlowConstantRefValue
30
+ ) {
31
+ let defaultSelectSchema = schemaFromProps || constantProps?.schema || { type: 'string' };
32
+ if (value?.type === 'constant') {
33
+ defaultSelectSchema = value?.schema || defaultSelectSchema;
34
+ }
35
+
36
+ const [selectSchema, setSelectSchema] = useState(defaultSelectSchema);
37
+
38
+ return [selectSchema, setSelectSchema] as const;
39
+ }
40
+
41
+ export function useIncludeSchema(schemaFromProps?: IJsonSchema) {
42
+ const includeSchema = useMemo(() => {
43
+ if (!schemaFromProps) {
44
+ return;
45
+ }
46
+ if (schemaFromProps?.type === 'number') {
47
+ return [schemaFromProps, { type: 'integer' }];
48
+ }
49
+ return { ...schemaFromProps, extra: { ...schemaFromProps?.extra, weak: true } };
50
+ }, [schemaFromProps]);
51
+
52
+ return includeSchema;
53
+ }