@flowgram.ai/form-materials 0.3.4 → 0.3.6
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.
- package/bin/index.ts +5 -19
- package/bin/materials.ts +31 -89
- package/bin/project.ts +4 -0
- package/bin/utils/import.ts +127 -0
- package/bin/utils/traverse-file.ts +60 -0
- package/dist/esm/index.js +383 -488
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +64 -6
- package/dist/index.d.ts +64 -6
- package/dist/index.js +625 -730
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/assign-row/index.tsx +4 -4
- package/src/components/assign-rows/index.tsx +1 -1
- package/src/components/batch-outputs/index.tsx +4 -3
- package/src/components/batch-outputs/types.ts +1 -1
- package/src/components/batch-variable-selector/index.tsx +1 -1
- package/src/components/code-editor-mini/index.tsx +1 -1
- package/src/components/condition-row/hooks/useRule.ts +2 -1
- package/src/components/condition-row/index.tsx +5 -4
- package/src/components/condition-row/types.ts +1 -1
- package/src/components/constant-input/index.tsx +5 -2
- package/src/components/constant-input/types.ts +1 -1
- package/src/components/display-flow-value/index.tsx +2 -2
- package/src/components/display-inputs-values/index.tsx +3 -2
- package/src/components/display-outputs/index.tsx +2 -1
- package/src/components/display-schema-tag/index.tsx +3 -2
- package/src/components/display-schema-tree/index.tsx +2 -1
- package/src/components/dynamic-value-input/hooks.ts +1 -1
- package/src/components/dynamic-value-input/index.tsx +13 -9
- package/src/components/inputs-values/index.tsx +7 -5
- package/src/components/inputs-values/types.ts +3 -3
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/json-editor-with-variables/index.tsx +2 -1
- package/src/components/json-schema-editor/default-value.tsx +11 -105
- package/src/components/json-schema-editor/hooks.tsx +53 -94
- package/src/components/json-schema-editor/index.tsx +11 -8
- package/src/components/json-schema-editor/styles.tsx +0 -29
- package/src/components/prompt-editor/types.tsx +1 -1
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +2 -1
- package/src/components/prompt-editor-with-inputs/index.tsx +3 -2
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +1 -1
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/prompt-editor-with-variables/index.tsx +2 -1
- package/src/components/type-selector/index.tsx +7 -3
- package/src/components/variable-selector/index.tsx +7 -4
- package/src/components/variable-selector/use-variable-tree.tsx +1 -1
- package/src/effects/auto-rename-ref/index.ts +1 -1
- package/src/effects/listen-ref-schema-change/index.ts +1 -1
- package/src/effects/listen-ref-value-change/index.ts +1 -1
- package/src/effects/provide-batch-input/index.ts +1 -1
- package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +1 -1
- package/src/form-plugins/infer-inputs-plugin/index.ts +1 -1
- package/src/shared/index.ts +1 -0
- package/src/shared/inject-material/README.md +170 -0
- package/src/shared/inject-material/README.zh.md +174 -0
- package/src/shared/inject-material/index.tsx +87 -0
- package/src/components/assign-row/config.json +0 -11
- package/src/components/assign-rows/config.json +0 -11
- package/src/components/batch-outputs/config.json +0 -13
- package/src/components/batch-variable-selector/config.json +0 -9
- package/src/components/code-editor/config.json +0 -10
- package/src/components/code-editor-mini/config.json +0 -7
- package/src/components/condition-row/config.json +0 -13
- package/src/components/constant-input/config.json +0 -9
- package/src/components/display-flow-value/config.json +0 -8
- package/src/components/display-inputs-values/config.json +0 -9
- package/src/components/display-outputs/config.json +0 -10
- package/src/components/display-schema-tag/config.json +0 -10
- package/src/components/display-schema-tree/config.json +0 -11
- package/src/components/dynamic-value-input/config.json +0 -14
- package/src/components/inputs-values/config.json +0 -13
- package/src/components/json-editor-with-variables/config.json +0 -13
- package/src/components/json-schema-editor/config.json +0 -13
- package/src/components/json-schema-editor/utils.ts +0 -29
- package/src/components/prompt-editor/config.json +0 -9
- package/src/components/prompt-editor-with-inputs/config.json +0 -13
- package/src/components/prompt-editor-with-variables/config.json +0 -13
- package/src/components/type-selector/config.json +0 -9
- package/src/components/variable-selector/config.json +0 -9
- package/src/effects/auto-rename-ref/config.json +0 -5
- package/src/effects/listen-ref-schema-change/config.json +0 -10
- package/src/effects/listen-ref-value-change/config.json +0 -9
- package/src/effects/provide-batch-input/config.json +0 -5
- package/src/effects/provide-json-schema-outputs/config.json +0 -7
- package/src/effects/sync-variable-title/config.json +0 -5
- package/src/effects/validate-when-variable-sync/config.json +0 -5
- package/src/form-plugins/batch-outputs-plugin/config.json +0 -7
- package/src/form-plugins/infer-assign-plugin/config.json +0 -7
- package/src/form-plugins/infer-inputs-plugin/config.json +0 -9
- package/src/hooks/use-object-list/config.json +0 -8
- package/src/shared/format-legacy-refs/config.json +0 -5
- package/src/typings/flow-value/config.json +0 -7
- package/src/validate/validate-flow-value/config.json +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"@codemirror/view": "~6.38.0",
|
|
35
35
|
"@codemirror/state": "~6.5.2",
|
|
36
36
|
"typescript": "^5.8.3",
|
|
37
|
-
"@flowgram.ai/editor": "0.3.
|
|
38
|
-
"@flowgram.ai/json-schema": "0.3.
|
|
37
|
+
"@flowgram.ai/editor": "0.3.6",
|
|
38
|
+
"@flowgram.ai/json-schema": "0.3.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/lodash": "^4.14.137",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"tsup": "^8.0.1",
|
|
52
52
|
"typescript": "^5.8.3",
|
|
53
53
|
"vitest": "^0.34.6",
|
|
54
|
-
"@flowgram.ai/eslint-config": "0.3.
|
|
55
|
-
"@flowgram.ai/ts-config": "0.3.
|
|
54
|
+
"@flowgram.ai/eslint-config": "0.3.6",
|
|
55
|
+
"@flowgram.ai/ts-config": "0.3.6"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"react": ">=16.8",
|
|
@@ -9,11 +9,11 @@ import { IconButton } from '@douyinfe/semi-ui';
|
|
|
9
9
|
import { IconMinus } from '@douyinfe/semi-icons';
|
|
10
10
|
|
|
11
11
|
import { IFlowConstantRefValue } from '@/typings';
|
|
12
|
+
import { InjectVariableSelector } from '@/components/variable-selector';
|
|
13
|
+
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
12
14
|
|
|
13
15
|
import { AssignRowProps } from './types';
|
|
14
16
|
import { BlurInput } from './components/blur-input';
|
|
15
|
-
import { VariableSelector } from '../variable-selector';
|
|
16
|
-
import { DynamicValueInput } from '../dynamic-value-input';
|
|
17
17
|
|
|
18
18
|
export function AssignRow(props: AssignRowProps) {
|
|
19
19
|
const {
|
|
@@ -29,7 +29,7 @@ export function AssignRow(props: AssignRowProps) {
|
|
|
29
29
|
<div style={{ display: 'flex', alignItems: 'center', gap: 5 }}>
|
|
30
30
|
<div style={{ width: 150, minWidth: 150, maxWidth: 150 }}>
|
|
31
31
|
{value?.operator === 'assign' ? (
|
|
32
|
-
<
|
|
32
|
+
<InjectVariableSelector
|
|
33
33
|
style={{ width: '100%', height: 26 }}
|
|
34
34
|
value={value?.left?.content}
|
|
35
35
|
config={{ placeholder: 'Select Left' }}
|
|
@@ -56,7 +56,7 @@ export function AssignRow(props: AssignRowProps) {
|
|
|
56
56
|
)}
|
|
57
57
|
</div>
|
|
58
58
|
<div style={{ flexGrow: 1 }}>
|
|
59
|
-
<
|
|
59
|
+
<InjectDynamicValueInput
|
|
60
60
|
readonly={readonly}
|
|
61
61
|
value={value?.right as IFlowConstantRefValue | undefined}
|
|
62
62
|
onChange={(v) =>
|
|
@@ -9,7 +9,7 @@ import { FieldArray, FieldArrayRenderProps } from '@flowgram.ai/editor';
|
|
|
9
9
|
import { Button } from '@douyinfe/semi-ui';
|
|
10
10
|
import { IconPlus } from '@douyinfe/semi-icons';
|
|
11
11
|
|
|
12
|
-
import { AssignRow, AssignValueType } from '
|
|
12
|
+
import { AssignRow, AssignValueType } from '@/components/assign-row';
|
|
13
13
|
|
|
14
14
|
interface AssignRowsProps {
|
|
15
15
|
name: string;
|
|
@@ -8,9 +8,10 @@ import React from 'react';
|
|
|
8
8
|
import { Button, Input } from '@douyinfe/semi-ui';
|
|
9
9
|
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
|
|
10
10
|
|
|
11
|
+
import { useObjectList } from '@/hooks';
|
|
12
|
+
import { InjectVariableSelector } from '@/components/variable-selector';
|
|
13
|
+
|
|
11
14
|
import { PropsType } from './types';
|
|
12
|
-
import { VariableSelector } from '../variable-selector';
|
|
13
|
-
import { useObjectList } from '../../hooks';
|
|
14
15
|
import { UIRow, UIRows } from './styles';
|
|
15
16
|
|
|
16
17
|
export function BatchOutputs(props: PropsType) {
|
|
@@ -30,7 +31,7 @@ export function BatchOutputs(props: PropsType) {
|
|
|
30
31
|
value={item.key}
|
|
31
32
|
onChange={(v) => updateKey(item.id, v)}
|
|
32
33
|
/>
|
|
33
|
-
<
|
|
34
|
+
<InjectVariableSelector
|
|
34
35
|
style={{ flexGrow: 1 }}
|
|
35
36
|
readonly={readonly}
|
|
36
37
|
value={item.value?.content}
|
|
@@ -8,7 +8,7 @@ import React from 'react';
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { PrivateScopeProvider } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
-
import { VariableSelector, VariableSelectorProps } from '
|
|
11
|
+
import { VariableSelector, VariableSelectorProps } from '@/components/variable-selector';
|
|
12
12
|
|
|
13
13
|
const batchVariableSchema: IJsonSchema = {
|
|
14
14
|
type: 'array',
|
|
@@ -7,7 +7,7 @@ import React from 'react';
|
|
|
7
7
|
|
|
8
8
|
import styled from 'styled-components';
|
|
9
9
|
|
|
10
|
-
import { CodeEditor, CodeEditorPropsType } from '
|
|
10
|
+
import { CodeEditor, CodeEditorPropsType } from '@/components/code-editor';
|
|
11
11
|
|
|
12
12
|
const UIMini = styled.div`
|
|
13
13
|
.ͼ1 .cm-content {
|
|
@@ -8,9 +8,10 @@ import { useMemo } from 'react';
|
|
|
8
8
|
import { JsonSchemaUtils, JsonSchemaBasicType } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
+
import { IFlowRefValue } from '@/typings';
|
|
12
|
+
|
|
11
13
|
import { IRules } from '../types';
|
|
12
14
|
import { defaultRules } from '../constants';
|
|
13
|
-
import { IFlowRefValue } from '../../../typings';
|
|
14
15
|
|
|
15
16
|
export function useRule(left?: IFlowRefValue, userRules?: IRules) {
|
|
16
17
|
const available = useScopeAvailable();
|
|
@@ -8,12 +8,13 @@ import React, { useMemo } from 'react';
|
|
|
8
8
|
import { I18n } from '@flowgram.ai/editor';
|
|
9
9
|
import { Input } from '@douyinfe/semi-ui';
|
|
10
10
|
|
|
11
|
+
import { InjectVariableSelector } from '@/components/variable-selector';
|
|
12
|
+
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
13
|
+
|
|
11
14
|
import { ConditionRowValueType, IRules, OpConfigs } from './types';
|
|
12
15
|
import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
|
|
13
16
|
import { useRule } from './hooks/useRule';
|
|
14
17
|
import { useOp } from './hooks/useOp';
|
|
15
|
-
import { VariableSelector } from '../variable-selector';
|
|
16
|
-
import { DynamicValueInput } from '../dynamic-value-input';
|
|
17
18
|
|
|
18
19
|
interface PropTypes {
|
|
19
20
|
value?: ConditionRowValueType;
|
|
@@ -58,7 +59,7 @@ export function ConditionRow({
|
|
|
58
59
|
<UIOperator>{renderOpSelect()}</UIOperator>
|
|
59
60
|
<UIValues>
|
|
60
61
|
<UILeft>
|
|
61
|
-
<
|
|
62
|
+
<InjectVariableSelector
|
|
62
63
|
readonly={readonly}
|
|
63
64
|
style={{ width: '100%' }}
|
|
64
65
|
value={left?.content}
|
|
@@ -75,7 +76,7 @@ export function ConditionRow({
|
|
|
75
76
|
</UILeft>
|
|
76
77
|
<UIRight>
|
|
77
78
|
{targetSchema ? (
|
|
78
|
-
<
|
|
79
|
+
<InjectDynamicValueInput
|
|
79
80
|
readonly={readonly || !rule}
|
|
80
81
|
value={right}
|
|
81
82
|
schema={targetSchema}
|
|
@@ -8,8 +8,11 @@ import React, { useMemo } from 'react';
|
|
|
8
8
|
|
|
9
9
|
import { Input } from '@douyinfe/semi-ui';
|
|
10
10
|
|
|
11
|
-
import { useTypeManager } from '
|
|
12
|
-
|
|
11
|
+
import { useTypeManager } from '@/plugins';
|
|
12
|
+
|
|
13
|
+
import { PropsType, Strategy as ConstantInputStrategy } from './types';
|
|
14
|
+
|
|
15
|
+
export { ConstantInputStrategy };
|
|
13
16
|
|
|
14
17
|
export function ConstantInput(props: PropsType) {
|
|
15
18
|
const { value, onChange, schema, strategies, fallbackRenderer, readonly, ...rest } = props;
|
|
@@ -8,8 +8,8 @@ import React, { useMemo } from 'react';
|
|
|
8
8
|
import { JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { IFlowValue } from '@/typings';
|
|
12
|
+
import { DisplaySchemaTag } from '@/components/display-schema-tag';
|
|
13
13
|
|
|
14
14
|
interface PropsType {
|
|
15
15
|
value?: IFlowValue;
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { IFlowValue } from '@/typings';
|
|
9
|
+
import { DisplayFlowValue } from '@/components/display-flow-value';
|
|
10
|
+
|
|
10
11
|
import { DisplayInputsWrapper } from './styles';
|
|
11
12
|
|
|
12
13
|
interface PropsType {
|
|
@@ -8,7 +8,8 @@ import React, { useEffect } from 'react';
|
|
|
8
8
|
import { IJsonSchema, JsonSchemaTypeManager, JsonSchemaUtils } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { useCurrentScope, useRefresh } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
-
import { DisplaySchemaTag } from '
|
|
11
|
+
import { DisplaySchemaTag } from '@/components/display-schema-tag';
|
|
12
|
+
|
|
12
13
|
import { DisplayOutputsWrapper } from './styles';
|
|
13
14
|
|
|
14
15
|
interface PropsType {
|
|
@@ -8,8 +8,9 @@ import React from 'react';
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { Popover } from '@douyinfe/semi-ui';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { useTypeManager } from '@/plugins';
|
|
12
|
+
import { DisplaySchemaTree } from '@/components/display-schema-tree';
|
|
13
|
+
|
|
13
14
|
import { PopoverContent, StyledTag, TitleSpan } from './styles';
|
|
14
15
|
|
|
15
16
|
interface PropsType {
|
|
@@ -7,7 +7,8 @@ import React from 'react';
|
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema, JsonSchemaTypeManager } from '@flowgram.ai/json-schema';
|
|
9
9
|
|
|
10
|
-
import { useTypeManager } from '
|
|
10
|
+
import { useTypeManager } from '@/plugins';
|
|
11
|
+
|
|
11
12
|
import { HorizontalLine, TreeItem, TreeLevel, TreeRow, TreeTitle } from './styles';
|
|
12
13
|
|
|
13
14
|
interface PropsType {
|
|
@@ -8,7 +8,7 @@ import { useMemo, useState } from 'react';
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
9
|
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
10
|
|
|
11
|
-
import { IFlowConstantRefValue } from '
|
|
11
|
+
import { IFlowConstantRefValue } from '@/typings/flow-value';
|
|
12
12
|
|
|
13
13
|
export function useRefVariable(value?: IFlowConstantRefValue) {
|
|
14
14
|
const available = useScopeAvailable();
|
|
@@ -9,11 +9,12 @@ import { JsonSchemaUtils, IJsonSchema } from '@flowgram.ai/json-schema';
|
|
|
9
9
|
import { IconButton } from '@douyinfe/semi-ui';
|
|
10
10
|
import { IconSetting } from '@douyinfe/semi-icons';
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
12
|
+
import { IFlowConstantRefValue } from '@/typings/flow-value';
|
|
13
|
+
import { createInjectMaterial } from '@/shared';
|
|
14
|
+
import { InjectVariableSelector } from '@/components/variable-selector';
|
|
15
|
+
import { TypeSelector } from '@/components/type-selector';
|
|
16
|
+
import { ConstantInput, ConstantInputStrategy } from '@/components/constant-input';
|
|
17
|
+
|
|
17
18
|
import { UIContainer, UIMain, UITrigger, UIType } from './styles';
|
|
18
19
|
import { useIncludeSchema, useRefVariable, useSelectSchema } from './hooks';
|
|
19
20
|
|
|
@@ -25,7 +26,7 @@ interface PropsType {
|
|
|
25
26
|
style?: React.CSSProperties;
|
|
26
27
|
schema?: IJsonSchema;
|
|
27
28
|
constantProps?: {
|
|
28
|
-
strategies?:
|
|
29
|
+
strategies?: ConstantInputStrategy[];
|
|
29
30
|
schema?: IJsonSchema; // set schema of constant input only
|
|
30
31
|
[key: string]: any;
|
|
31
32
|
};
|
|
@@ -88,7 +89,7 @@ export function DynamicValueInput({
|
|
|
88
89
|
if (value?.type === 'ref') {
|
|
89
90
|
// Display Variable Or Delete
|
|
90
91
|
return (
|
|
91
|
-
<
|
|
92
|
+
<InjectVariableSelector
|
|
92
93
|
style={{ width: '100%' }}
|
|
93
94
|
value={value?.content}
|
|
94
95
|
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : undefined)}
|
|
@@ -108,7 +109,7 @@ export function DynamicValueInput({
|
|
|
108
109
|
readonly={readonly}
|
|
109
110
|
strategies={[...(constantProps?.strategies || [])]}
|
|
110
111
|
fallbackRenderer={() => (
|
|
111
|
-
<
|
|
112
|
+
<InjectVariableSelector
|
|
112
113
|
style={{ width: '100%' }}
|
|
113
114
|
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : undefined)}
|
|
114
115
|
includeSchema={includeSchema}
|
|
@@ -121,7 +122,7 @@ export function DynamicValueInput({
|
|
|
121
122
|
};
|
|
122
123
|
|
|
123
124
|
const renderTrigger = () => (
|
|
124
|
-
<
|
|
125
|
+
<InjectVariableSelector
|
|
125
126
|
style={{ width: '100%' }}
|
|
126
127
|
value={value?.type === 'ref' ? value?.content : undefined}
|
|
127
128
|
onChange={(_v) => onChange({ type: 'ref', content: _v })}
|
|
@@ -141,3 +142,6 @@ export function DynamicValueInput({
|
|
|
141
142
|
</UIContainer>
|
|
142
143
|
);
|
|
143
144
|
}
|
|
145
|
+
|
|
146
|
+
DynamicValueInput.renderKey = 'dynamic-value-input-render-key';
|
|
147
|
+
export const InjectDynamicValueInput = createInjectMaterial(DynamicValueInput);
|
|
@@ -5,13 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
8
9
|
import { Button, IconButton } from '@douyinfe/semi-ui';
|
|
9
10
|
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
|
|
10
11
|
|
|
12
|
+
import { IFlowConstantRefValue, IFlowValue } from '@/typings';
|
|
13
|
+
import { useObjectList } from '@/hooks';
|
|
14
|
+
import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
|
|
15
|
+
|
|
11
16
|
import { PropsType } from './types';
|
|
12
|
-
import { DynamicValueInput } from '../dynamic-value-input';
|
|
13
|
-
import { IFlowConstantRefValue, IFlowValue } from '../../typings';
|
|
14
|
-
import { useObjectList } from '../../hooks';
|
|
15
17
|
import { UIRow, UIRows } from './styles';
|
|
16
18
|
import { BlurInput } from './components/blur-input';
|
|
17
19
|
|
|
@@ -41,9 +43,9 @@ export function InputsValues({
|
|
|
41
43
|
size="small"
|
|
42
44
|
value={item.key}
|
|
43
45
|
onChange={(v) => updateKey(item.id, v)}
|
|
44
|
-
placeholder=
|
|
46
|
+
placeholder={I18n.t('Input Key')}
|
|
45
47
|
/>
|
|
46
|
-
<
|
|
48
|
+
<InjectDynamicValueInput
|
|
47
49
|
style={{ flexGrow: 1 }}
|
|
48
50
|
readonly={readonly}
|
|
49
51
|
value={item.value as IFlowConstantRefValue}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { IFlowValue } from '@/typings';
|
|
9
|
+
import { ConstantInputStrategy } from '@/components/constant-input';
|
|
10
10
|
|
|
11
11
|
export interface PropsType {
|
|
12
12
|
value?: Record<string, IFlowValue | undefined>;
|
|
@@ -16,7 +16,7 @@ export interface PropsType {
|
|
|
16
16
|
schema?: IJsonSchema;
|
|
17
17
|
style?: React.CSSProperties;
|
|
18
18
|
constantProps?: {
|
|
19
|
-
strategies?:
|
|
19
|
+
strategies?: ConstantInputStrategy[];
|
|
20
20
|
[key: string]: any;
|
|
21
21
|
};
|
|
22
22
|
}
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from '@coze-editor/editor/react';
|
|
16
16
|
import { EditorAPI } from '@coze-editor/editor/preset-prompt';
|
|
17
17
|
|
|
18
|
-
import { useVariableTree } from '
|
|
18
|
+
import { useVariableTree } from '@/components/variable-selector';
|
|
19
19
|
|
|
20
20
|
export function VariableTree() {
|
|
21
21
|
const [posKey, setPosKey] = useState('');
|
|
@@ -8,9 +8,10 @@ import React from 'react';
|
|
|
8
8
|
import { transformerCreator } from '@coze-editor/editor/preset-code';
|
|
9
9
|
import { Text } from '@coze-editor/editor/language-json';
|
|
10
10
|
|
|
11
|
+
import { CodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
|
|
12
|
+
|
|
11
13
|
import { VariableTree } from './extensions/variable-tree';
|
|
12
14
|
import { VariableTagInject } from './extensions/variable-tag';
|
|
13
|
-
import { CodeEditor, type CodeEditorPropsType } from '../code-editor';
|
|
14
15
|
|
|
15
16
|
type Match = { match: string; range: [number, number] };
|
|
16
17
|
function findAllMatches(inputString: string, regex: RegExp): Match[] {
|
|
@@ -3,26 +3,19 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React
|
|
6
|
+
import React from 'react';
|
|
7
7
|
|
|
8
8
|
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
9
|
-
import {
|
|
10
|
-
import { IconBrackets } from '@douyinfe/semi-icons';
|
|
9
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
11
10
|
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
JSONHeader,
|
|
16
|
-
JSONHeaderLeft,
|
|
17
|
-
JSONHeaderRight,
|
|
18
|
-
JSONViewerWrapper,
|
|
19
|
-
} from './styles';
|
|
20
|
-
import { ConstantInput } from '../constant-input';
|
|
11
|
+
import { ConstantInput } from '@/components/constant-input';
|
|
12
|
+
|
|
13
|
+
import { ConstantInputWrapper } from './styles';
|
|
21
14
|
|
|
22
15
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @param props -
|
|
25
|
-
* @returns
|
|
16
|
+
* Renders the corresponding default value input component based on different data types.
|
|
17
|
+
* @param props - Component properties, including value, type, placeholder, onChange.
|
|
18
|
+
* @returns Returns the input component of the corresponding type or null.
|
|
26
19
|
*/
|
|
27
20
|
export function DefaultValue(props: {
|
|
28
21
|
value: any;
|
|
@@ -33,102 +26,15 @@ export function DefaultValue(props: {
|
|
|
33
26
|
jsonFormatText?: string;
|
|
34
27
|
onChange: (value: any) => void;
|
|
35
28
|
}) {
|
|
36
|
-
const { value, schema,
|
|
37
|
-
|
|
38
|
-
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
39
|
-
const JsonViewerRef = useRef<JsonViewer>(null);
|
|
40
|
-
|
|
41
|
-
// 为 JsonViewer 添加状态管理
|
|
42
|
-
const [internalJsonValue, setInternalJsonValue] = useState<string>(
|
|
43
|
-
getValueType(value) === 'string' ? value : ''
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// 使用 useCallback 创建稳定的回调函数
|
|
47
|
-
const handleJsonChange = useCallback((val: string) => {
|
|
48
|
-
// 只在值真正改变时才更新状态
|
|
49
|
-
if (val !== internalJsonValue) {
|
|
50
|
-
setInternalJsonValue(val);
|
|
51
|
-
}
|
|
52
|
-
}, []);
|
|
53
|
-
|
|
54
|
-
// 处理编辑完成事件
|
|
55
|
-
const handleEditComplete = useCallback(() => {
|
|
56
|
-
// 只有当存在key,编辑完成时才触发父组件的 onChange
|
|
57
|
-
onChange(internalJsonValue);
|
|
58
|
-
// 确保在更新后移除焦点
|
|
59
|
-
requestAnimationFrame(() => {
|
|
60
|
-
// JsonViewerRef.current?.format();
|
|
61
|
-
wrapperRef.current?.blur();
|
|
62
|
-
});
|
|
63
|
-
setJsonReadOnly(true);
|
|
64
|
-
}, [internalJsonValue, onChange]);
|
|
65
|
-
|
|
66
|
-
const [jsonReadOnly, setJsonReadOnly] = useState<boolean>(true);
|
|
67
|
-
|
|
68
|
-
const handleFormatJson = useCallback(() => {
|
|
69
|
-
try {
|
|
70
|
-
const parsed = JSON.parse(internalJsonValue);
|
|
71
|
-
const formatted = JSON.stringify(parsed, null, 4);
|
|
72
|
-
setInternalJsonValue(formatted);
|
|
73
|
-
onChange(formatted);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error('Invalid JSON:', error);
|
|
76
|
-
}
|
|
77
|
-
}, [internalJsonValue, onChange]);
|
|
78
|
-
|
|
79
|
-
return type === 'object' ? (
|
|
80
|
-
<>
|
|
81
|
-
<JSONHeader>
|
|
82
|
-
<JSONHeaderLeft>json</JSONHeaderLeft>
|
|
83
|
-
<JSONHeaderRight>
|
|
84
|
-
<Tooltip content={jsonFormatText ?? 'Format'}>
|
|
85
|
-
<IconButton
|
|
86
|
-
icon={<IconBrackets style={{ color: 'var(--semi-color-primary)' }} />}
|
|
87
|
-
size="small"
|
|
88
|
-
type="tertiary"
|
|
89
|
-
theme="borderless"
|
|
90
|
-
onClick={handleFormatJson}
|
|
91
|
-
/>
|
|
92
|
-
</Tooltip>
|
|
93
|
-
</JSONHeaderRight>
|
|
94
|
-
</JSONHeader>
|
|
29
|
+
const { value, schema, onChange, placeholder } = props;
|
|
95
30
|
|
|
96
|
-
|
|
97
|
-
ref={wrapperRef}
|
|
98
|
-
tabIndex={-1}
|
|
99
|
-
onBlur={(e) => {
|
|
100
|
-
if (wrapperRef.current && !wrapperRef.current?.contains(e.relatedTarget as Node)) {
|
|
101
|
-
handleEditComplete();
|
|
102
|
-
}
|
|
103
|
-
}}
|
|
104
|
-
onClick={(e: React.MouseEvent) => {
|
|
105
|
-
setJsonReadOnly(false);
|
|
106
|
-
}}
|
|
107
|
-
>
|
|
108
|
-
<JsonViewer
|
|
109
|
-
ref={JsonViewerRef}
|
|
110
|
-
value={getValueType(value) === 'string' ? value : ''}
|
|
111
|
-
height={120}
|
|
112
|
-
width="100%"
|
|
113
|
-
showSearch={false}
|
|
114
|
-
options={{
|
|
115
|
-
readOnly: jsonReadOnly,
|
|
116
|
-
formatOptions: { tabSize: 4, insertSpaces: true, eol: '\n' },
|
|
117
|
-
}}
|
|
118
|
-
style={{
|
|
119
|
-
padding: 0,
|
|
120
|
-
}}
|
|
121
|
-
onChange={handleJsonChange}
|
|
122
|
-
/>
|
|
123
|
-
</JSONViewerWrapper>
|
|
124
|
-
</>
|
|
125
|
-
) : (
|
|
31
|
+
return (
|
|
126
32
|
<ConstantInputWrapper>
|
|
127
33
|
<ConstantInput
|
|
128
34
|
value={value}
|
|
129
35
|
onChange={(_v) => onChange(_v)}
|
|
130
36
|
schema={schema || { type: 'string' }}
|
|
131
|
-
placeholder={placeholder ?? 'Default value if parameter is not provided'}
|
|
37
|
+
placeholder={placeholder ?? I18n.t('Default value if parameter is not provided')}
|
|
132
38
|
/>
|
|
133
39
|
</ConstantInputWrapper>
|
|
134
40
|
);
|