@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.
- package/bin/index.ts +11 -5
- package/bin/materials.ts +10 -1
- package/dist/esm/index.js +1996 -1361
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +328 -114
- package/dist/index.d.ts +328 -114
- package/dist/index.js +2096 -1472
- package/dist/index.js.map +1 -1
- package/package.json +7 -5
- package/src/components/assign-row/components/blur-input.tsx +27 -0
- package/src/components/assign-row/config.json +11 -0
- package/src/components/assign-row/index.tsx +84 -0
- package/src/components/assign-row/types.ts +25 -0
- package/src/components/assign-rows/config.json +11 -0
- package/src/components/assign-rows/index.tsx +59 -0
- package/src/components/batch-outputs/config.json +2 -1
- package/src/components/batch-outputs/index.tsx +4 -12
- package/src/components/batch-variable-selector/config.json +6 -2
- package/src/components/batch-variable-selector/index.tsx +1 -1
- package/src/components/code-editor/config.json +2 -1
- package/src/components/code-editor/index.tsx +23 -1
- package/src/components/code-editor/language-features.ts +23 -3
- package/src/components/code-editor/theme/light.ts +2 -2
- package/src/components/code-editor-mini/config.json +7 -0
- package/src/components/code-editor-mini/index.tsx +31 -0
- package/src/components/condition-row/config.json +10 -2
- package/src/components/condition-row/constants.ts +6 -8
- package/src/components/condition-row/hooks/useOp.tsx +3 -1
- package/src/components/condition-row/hooks/useRule.ts +2 -2
- package/src/components/condition-row/index.tsx +2 -1
- package/src/components/condition-row/types.ts +3 -1
- package/src/components/constant-input/config.json +6 -3
- package/src/components/constant-input/index.tsx +18 -62
- package/src/components/constant-input/types.ts +6 -9
- package/src/components/display-flow-value/config.json +8 -0
- package/src/components/display-flow-value/index.tsx +59 -0
- package/src/components/display-inputs-values/config.json +9 -0
- package/src/components/display-inputs-values/index.tsx +27 -0
- package/src/components/display-inputs-values/styles.ts +12 -0
- package/src/components/display-outputs/config.json +10 -0
- package/src/components/display-outputs/index.tsx +64 -0
- package/src/components/display-outputs/styles.ts +12 -0
- package/src/components/display-schema-tag/config.json +10 -0
- package/src/components/display-schema-tag/index.tsx +44 -0
- package/src/components/display-schema-tag/styles.ts +28 -0
- package/src/components/display-schema-tree/config.json +11 -0
- package/src/components/display-schema-tree/index.tsx +74 -0
- package/src/components/display-schema-tree/styles.tsx +90 -0
- package/src/components/dynamic-value-input/config.json +11 -2
- package/src/components/dynamic-value-input/hooks.ts +53 -0
- package/src/components/dynamic-value-input/index.tsx +64 -13
- package/src/components/dynamic-value-input/styles.tsx +28 -2
- package/src/components/index.ts +9 -0
- package/src/components/inputs-values/components/blur-input.tsx +27 -0
- package/src/components/inputs-values/config.json +13 -0
- package/src/components/inputs-values/index.tsx +73 -0
- package/src/components/inputs-values/styles.tsx +19 -0
- package/src/components/inputs-values/types.ts +22 -0
- package/src/components/json-editor-with-variables/index.tsx +47 -1
- package/src/components/json-schema-editor/config.json +2 -2
- package/src/components/json-schema-editor/default-value.tsx +1 -1
- package/src/components/json-schema-editor/hooks.tsx +4 -2
- package/src/components/json-schema-editor/index.tsx +15 -2
- package/src/components/json-schema-editor/types.ts +1 -1
- package/src/components/prompt-editor/index.tsx +2 -1
- package/src/components/prompt-editor/types.tsx +1 -0
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +1 -1
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +6 -3
- package/src/components/type-selector/config.json +6 -2
- package/src/components/type-selector/index.tsx +55 -12
- package/src/components/variable-selector/config.json +6 -2
- package/src/components/variable-selector/index.tsx +34 -13
- package/src/components/variable-selector/styles.tsx +18 -8
- package/src/components/variable-selector/use-variable-tree.tsx +19 -22
- package/src/effects/auto-rename-ref/index.ts +59 -8
- package/src/effects/index.ts +3 -1
- package/src/effects/listen-ref-schema-change/config.json +10 -0
- package/src/effects/listen-ref-schema-change/index.ts +56 -0
- package/src/effects/listen-ref-value-change/config.json +9 -0
- package/src/effects/listen-ref-value-change/index.ts +53 -0
- package/src/effects/provide-json-schema-outputs/config.json +4 -5
- package/src/effects/provide-json-schema-outputs/index.ts +1 -3
- package/src/effects/sync-variable-title/index.ts +1 -0
- package/src/effects/validate-when-variable-sync/config.json +5 -0
- package/src/effects/validate-when-variable-sync/index.ts +35 -0
- package/src/form-plugins/index.ts +3 -1
- package/src/form-plugins/infer-assign-plugin/config.json +7 -0
- package/src/form-plugins/infer-assign-plugin/index.ts +90 -0
- package/src/form-plugins/infer-inputs-plugin/config.json +9 -0
- package/src/form-plugins/infer-inputs-plugin/index.ts +108 -0
- package/src/hooks/index.tsx +6 -0
- package/src/hooks/use-object-list/config.json +8 -0
- package/src/hooks/use-object-list/index.tsx +136 -0
- package/src/index.ts +3 -1
- package/src/{typings/json-schema → plugins/disable-declaration-plugin}/config.json +1 -1
- package/src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts +31 -0
- package/src/plugins/disable-declaration-plugin/index.tsx +6 -0
- package/src/plugins/index.ts +7 -0
- package/src/plugins/json-schema-preset/config.json +9 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +28 -0
- package/src/plugins/json-schema-preset/index.tsx +41 -0
- package/src/plugins/json-schema-preset/manager.ts +18 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +32 -0
- package/src/plugins/json-schema-preset/type-definition/index.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/number.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/object.tsx +24 -0
- package/src/plugins/json-schema-preset/type-definition/string.tsx +18 -0
- package/src/{utils → shared}/index.ts +0 -1
- package/src/typings/flow-value/config.json +3 -1
- package/src/typings/flow-value/index.ts +11 -0
- package/src/typings/index.ts +0 -1
- package/src/validate/index.tsx +6 -0
- package/src/validate/validate-flow-value/config.json +7 -0
- package/src/validate/validate-flow-value/index.tsx +73 -0
- package/src/components/batch-outputs/use-list.ts +0 -86
- package/src/components/type-selector/constants.tsx +0 -364
- package/src/effects/provide-batch-outputs/config.json +0 -5
- package/src/effects/provide-batch-outputs/index.ts +0 -38
- package/src/typings/json-schema/index.ts +0 -36
- package/src/utils/json-schema/config.json +0 -5
- package/src/utils/json-schema/index.ts +0 -180
- /package/src/{utils → shared}/format-legacy-refs/config.json +0 -0
- /package/src/{utils → shared}/format-legacy-refs/index.ts +0 -0
- /package/src/{utils → shared}/format-legacy-refs/readme.md +0 -0
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import React
|
|
6
|
+
import React from 'react';
|
|
7
7
|
|
|
8
|
+
import { JsonSchemaUtils, IJsonSchema } from '@flowgram.ai/json-schema';
|
|
8
9
|
import { IconButton } from '@douyinfe/semi-ui';
|
|
9
10
|
import { IconSetting } from '@douyinfe/semi-icons';
|
|
10
11
|
|
|
12
|
+
import { VariableSelector } from '../variable-selector';
|
|
13
|
+
import { TypeSelector } from '../type-selector';
|
|
11
14
|
import { Strategy } from '../constant-input/types';
|
|
12
15
|
import { ConstantInput } from '../constant-input';
|
|
13
16
|
import { IFlowConstantRefValue } from '../../typings/flow-value';
|
|
14
|
-
import { UIContainer, UIMain, UITrigger } from './styles';
|
|
15
|
-
import {
|
|
16
|
-
import { IJsonSchema } from '../../typings';
|
|
17
|
+
import { UIContainer, UIMain, UITrigger, UIType } from './styles';
|
|
18
|
+
import { useIncludeSchema, useRefVariable, useSelectSchema } from './hooks';
|
|
17
19
|
|
|
18
20
|
interface PropsType {
|
|
19
21
|
value?: IFlowConstantRefValue;
|
|
@@ -34,16 +36,53 @@ export function DynamicValueInput({
|
|
|
34
36
|
onChange,
|
|
35
37
|
readonly,
|
|
36
38
|
style,
|
|
37
|
-
schema,
|
|
39
|
+
schema: schemaFromProps,
|
|
38
40
|
constantProps,
|
|
39
41
|
}: PropsType) {
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const refVariable = useRefVariable(value);
|
|
43
|
+
const [selectSchema, setSelectSchema] = useSelectSchema(schemaFromProps, constantProps, value);
|
|
44
|
+
const includeSchema = useIncludeSchema(schemaFromProps);
|
|
45
|
+
|
|
46
|
+
const renderTypeSelector = () => {
|
|
47
|
+
if (schemaFromProps) {
|
|
48
|
+
return <TypeSelector value={schemaFromProps} readonly={true} />;
|
|
44
49
|
}
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
|
|
51
|
+
if (value?.type === 'ref') {
|
|
52
|
+
const schema = refVariable?.type ? JsonSchemaUtils.astToSchema(refVariable?.type) : undefined;
|
|
53
|
+
|
|
54
|
+
return <TypeSelector value={schema} readonly={true} />;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<TypeSelector
|
|
59
|
+
value={selectSchema}
|
|
60
|
+
onChange={(_v) => {
|
|
61
|
+
setSelectSchema(_v || { type: 'string' });
|
|
62
|
+
let content;
|
|
63
|
+
|
|
64
|
+
if (_v?.type === 'object') {
|
|
65
|
+
content = '{}';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (_v?.type === 'array') {
|
|
69
|
+
content = '[]';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (_v?.type === 'boolean') {
|
|
73
|
+
content = false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onChange({
|
|
77
|
+
type: 'constant',
|
|
78
|
+
content,
|
|
79
|
+
schema: _v || { type: 'string' },
|
|
80
|
+
});
|
|
81
|
+
}}
|
|
82
|
+
readonly={readonly}
|
|
83
|
+
/>
|
|
84
|
+
);
|
|
85
|
+
};
|
|
47
86
|
|
|
48
87
|
const renderMain = () => {
|
|
49
88
|
if (value?.type === 'ref') {
|
|
@@ -59,12 +98,23 @@ export function DynamicValueInput({
|
|
|
59
98
|
);
|
|
60
99
|
}
|
|
61
100
|
|
|
101
|
+
const constantSchema = schemaFromProps || selectSchema || { type: 'string' };
|
|
102
|
+
|
|
62
103
|
return (
|
|
63
104
|
<ConstantInput
|
|
64
105
|
value={value?.content}
|
|
65
|
-
onChange={(_v) => onChange({ type: 'constant', content: _v })}
|
|
66
|
-
schema={
|
|
106
|
+
onChange={(_v) => onChange({ type: 'constant', content: _v, schema: constantSchema })}
|
|
107
|
+
schema={constantSchema || { type: 'string' }}
|
|
67
108
|
readonly={readonly}
|
|
109
|
+
strategies={[...(constantProps?.strategies || [])]}
|
|
110
|
+
fallbackRenderer={() => (
|
|
111
|
+
<VariableSelector
|
|
112
|
+
style={{ width: '100%' }}
|
|
113
|
+
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : undefined)}
|
|
114
|
+
includeSchema={includeSchema}
|
|
115
|
+
readonly={readonly}
|
|
116
|
+
/>
|
|
117
|
+
)}
|
|
68
118
|
{...constantProps}
|
|
69
119
|
/>
|
|
70
120
|
);
|
|
@@ -85,6 +135,7 @@ export function DynamicValueInput({
|
|
|
85
135
|
|
|
86
136
|
return (
|
|
87
137
|
<UIContainer style={style}>
|
|
138
|
+
<UIType>{renderTypeSelector()}</UIType>
|
|
88
139
|
<UIMain>{renderMain()}</UIMain>
|
|
89
140
|
<UITrigger>{renderTrigger()}</UITrigger>
|
|
90
141
|
</UIContainer>
|
|
@@ -8,7 +8,12 @@ import styled from 'styled-components';
|
|
|
8
8
|
export const UIContainer = styled.div`
|
|
9
9
|
display: flex;
|
|
10
10
|
align-items: center;
|
|
11
|
-
|
|
11
|
+
border-radius: 4px;
|
|
12
|
+
border: 1px solid var(--semi-color-border);
|
|
13
|
+
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
|
|
16
|
+
background-color: var(--semi-color-fill-0);
|
|
12
17
|
`;
|
|
13
18
|
|
|
14
19
|
export const UIMain = styled.div`
|
|
@@ -20,7 +25,28 @@ export const UIMain = styled.div`
|
|
|
20
25
|
& .semi-input-number,
|
|
21
26
|
& .semi-select {
|
|
22
27
|
width: 100%;
|
|
28
|
+
border: none;
|
|
29
|
+
border-radius: 0;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
& .semi-input-wrapper {
|
|
33
|
+
border: none;
|
|
34
|
+
border-radius: 0;
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
export const UIType = styled.div`
|
|
39
|
+
border-right: 1px solid #e5e5e5;
|
|
40
|
+
|
|
41
|
+
& .semi-button {
|
|
42
|
+
border-radius: 0;
|
|
23
43
|
}
|
|
24
44
|
`;
|
|
25
45
|
|
|
26
|
-
export const UITrigger = styled.div
|
|
46
|
+
export const UITrigger = styled.div`
|
|
47
|
+
border-left: 1px solid #e5e5e5;
|
|
48
|
+
|
|
49
|
+
& .semi-button {
|
|
50
|
+
border-radius: 0;
|
|
51
|
+
}
|
|
52
|
+
`;
|
package/src/components/index.ts
CHANGED
|
@@ -15,4 +15,13 @@ export * from './prompt-editor';
|
|
|
15
15
|
export * from './prompt-editor-with-variables';
|
|
16
16
|
export * from './prompt-editor-with-inputs';
|
|
17
17
|
export * from './code-editor';
|
|
18
|
+
export * from './code-editor-mini';
|
|
18
19
|
export * from './json-editor-with-variables';
|
|
20
|
+
export * from './inputs-values';
|
|
21
|
+
export * from './display-schema-tree';
|
|
22
|
+
export * from './display-outputs';
|
|
23
|
+
export * from './display-schema-tag';
|
|
24
|
+
export * from './display-flow-value';
|
|
25
|
+
export * from './display-inputs-values';
|
|
26
|
+
export * from './assign-rows';
|
|
27
|
+
export * from './assign-row';
|
|
@@ -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, { useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import Input, { InputProps } from '@douyinfe/semi-ui/lib/es/input';
|
|
9
|
+
|
|
10
|
+
export function BlurInput(props: InputProps) {
|
|
11
|
+
const [value, setValue] = useState('');
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
setValue(props.value as string);
|
|
15
|
+
}, [props.value]);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Input
|
|
19
|
+
{...props}
|
|
20
|
+
value={value}
|
|
21
|
+
onChange={(value) => {
|
|
22
|
+
setValue(value);
|
|
23
|
+
}}
|
|
24
|
+
onBlur={(e) => props.onChange?.(value, e)}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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 { Button, IconButton } from '@douyinfe/semi-ui';
|
|
9
|
+
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
|
|
10
|
+
|
|
11
|
+
import { PropsType } from './types';
|
|
12
|
+
import { DynamicValueInput } from '../dynamic-value-input';
|
|
13
|
+
import { IFlowConstantRefValue, IFlowValue } from '../../typings';
|
|
14
|
+
import { useObjectList } from '../../hooks';
|
|
15
|
+
import { UIRow, UIRows } from './styles';
|
|
16
|
+
import { BlurInput } from './components/blur-input';
|
|
17
|
+
|
|
18
|
+
export function InputsValues({
|
|
19
|
+
value,
|
|
20
|
+
onChange,
|
|
21
|
+
style,
|
|
22
|
+
readonly,
|
|
23
|
+
constantProps,
|
|
24
|
+
schema,
|
|
25
|
+
hasError,
|
|
26
|
+
}: PropsType) {
|
|
27
|
+
const { list, updateKey, updateValue, remove, add } = useObjectList<IFlowValue | undefined>({
|
|
28
|
+
value,
|
|
29
|
+
onChange,
|
|
30
|
+
sortIndexKey: 'extra.index',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div>
|
|
35
|
+
<UIRows style={style}>
|
|
36
|
+
{list.map((item) => (
|
|
37
|
+
<UIRow key={item.id}>
|
|
38
|
+
<BlurInput
|
|
39
|
+
style={{ width: 100, minWidth: 100, maxWidth: 100 }}
|
|
40
|
+
disabled={readonly}
|
|
41
|
+
size="small"
|
|
42
|
+
value={item.key}
|
|
43
|
+
onChange={(v) => updateKey(item.id, v)}
|
|
44
|
+
placeholder="Input Key"
|
|
45
|
+
/>
|
|
46
|
+
<DynamicValueInput
|
|
47
|
+
style={{ flexGrow: 1 }}
|
|
48
|
+
readonly={readonly}
|
|
49
|
+
value={item.value as IFlowConstantRefValue}
|
|
50
|
+
onChange={(v) => updateValue(item.id, v)}
|
|
51
|
+
schema={schema}
|
|
52
|
+
hasError={hasError}
|
|
53
|
+
constantProps={{
|
|
54
|
+
...constantProps,
|
|
55
|
+
strategies: [...(constantProps?.strategies || [])],
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
<IconButton
|
|
59
|
+
disabled={readonly}
|
|
60
|
+
theme="borderless"
|
|
61
|
+
icon={<IconDelete size="small" />}
|
|
62
|
+
size="small"
|
|
63
|
+
onClick={() => remove(item.id)}
|
|
64
|
+
/>
|
|
65
|
+
</UIRow>
|
|
66
|
+
))}
|
|
67
|
+
</UIRows>
|
|
68
|
+
<Button disabled={readonly} icon={<IconPlus />} size="small" onClick={add}>
|
|
69
|
+
Add
|
|
70
|
+
</Button>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 UIRows = styled.div`
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
gap: 10px;
|
|
12
|
+
margin-bottom: 10px;
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export const UIRow = styled.div`
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
gap: 5px;
|
|
19
|
+
`;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
7
|
+
|
|
8
|
+
import { Strategy } from '../constant-input/types';
|
|
9
|
+
import { IFlowValue } from '../../typings';
|
|
10
|
+
|
|
11
|
+
export interface PropsType {
|
|
12
|
+
value?: Record<string, IFlowValue | undefined>;
|
|
13
|
+
onChange: (value?: Record<string, IFlowValue | undefined>) => void;
|
|
14
|
+
readonly?: boolean;
|
|
15
|
+
hasError?: boolean;
|
|
16
|
+
schema?: IJsonSchema;
|
|
17
|
+
style?: React.CSSProperties;
|
|
18
|
+
constantProps?: {
|
|
19
|
+
strategies?: Strategy[];
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -5,13 +5,59 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
+
import { transformerCreator } from '@coze-editor/editor/preset-code';
|
|
9
|
+
import { Text } from '@coze-editor/editor/language-json';
|
|
10
|
+
|
|
8
11
|
import { VariableTree } from './extensions/variable-tree';
|
|
9
12
|
import { VariableTagInject } from './extensions/variable-tag';
|
|
10
13
|
import { CodeEditor, type CodeEditorPropsType } from '../code-editor';
|
|
11
14
|
|
|
15
|
+
type Match = { match: string; range: [number, number] };
|
|
16
|
+
function findAllMatches(inputString: string, regex: RegExp): Match[] {
|
|
17
|
+
const globalRegex = new RegExp(
|
|
18
|
+
regex,
|
|
19
|
+
regex.flags.includes('g') ? regex.flags : regex.flags + 'g'
|
|
20
|
+
);
|
|
21
|
+
let match;
|
|
22
|
+
const matches: Match[] = [];
|
|
23
|
+
|
|
24
|
+
while ((match = globalRegex.exec(inputString)) !== null) {
|
|
25
|
+
if (match.index === globalRegex.lastIndex) {
|
|
26
|
+
globalRegex.lastIndex++;
|
|
27
|
+
}
|
|
28
|
+
matches.push({
|
|
29
|
+
match: match[0],
|
|
30
|
+
range: [match.index, match.index + match[0].length],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return matches;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const transformer = transformerCreator((text: Text) => {
|
|
38
|
+
const originalSource = text.toString();
|
|
39
|
+
const matches = findAllMatches(originalSource, /\{\{([^\}]*)\}\}/g);
|
|
40
|
+
|
|
41
|
+
if (matches.length > 0) {
|
|
42
|
+
matches.forEach(({ range }) => {
|
|
43
|
+
text.replaceRange(range[0], range[1], 'null');
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return text;
|
|
48
|
+
});
|
|
49
|
+
|
|
12
50
|
export function JsonEditorWithVariables(props: Omit<CodeEditorPropsType, 'languageId'>) {
|
|
13
51
|
return (
|
|
14
|
-
<CodeEditor
|
|
52
|
+
<CodeEditor
|
|
53
|
+
languageId="json"
|
|
54
|
+
activeLinePlaceholder="Press '@' to Select variable"
|
|
55
|
+
{...props}
|
|
56
|
+
options={{
|
|
57
|
+
transformer,
|
|
58
|
+
...(props.options || {}),
|
|
59
|
+
}}
|
|
60
|
+
>
|
|
15
61
|
<VariableTree />
|
|
16
62
|
<VariableTagInject />
|
|
17
63
|
</CodeEditor>
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
"name": "json-schema-editor",
|
|
3
3
|
"depMaterials": [
|
|
4
4
|
"type-selector",
|
|
5
|
-
"typings/json-schema",
|
|
6
5
|
"constant-inputs"
|
|
7
6
|
],
|
|
8
7
|
"depPackages": [
|
|
9
8
|
"@douyinfe/semi-ui",
|
|
10
9
|
"@douyinfe/semi-icons",
|
|
11
|
-
"styled-components"
|
|
10
|
+
"styled-components",
|
|
11
|
+
"@flowgram.ai/json-schema"
|
|
12
12
|
]
|
|
13
13
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useRef, useState, useCallback } from 'react';
|
|
7
7
|
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
8
9
|
import { IconButton, JsonViewer, Tooltip } from '@douyinfe/semi-ui';
|
|
9
10
|
import { IconBrackets } from '@douyinfe/semi-icons';
|
|
10
11
|
|
|
@@ -17,7 +18,6 @@ import {
|
|
|
17
18
|
JSONViewerWrapper,
|
|
18
19
|
} from './styles';
|
|
19
20
|
import { ConstantInput } from '../constant-input';
|
|
20
|
-
import { IJsonSchema } from '../../typings';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* 根据不同的数据类型渲染对应的默认值输入组件。
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { omit } from 'lodash';
|
|
9
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
10
|
+
|
|
9
11
|
import { PropertyValueType } from './types';
|
|
10
12
|
|
|
11
13
|
let _id = 0;
|
|
@@ -113,7 +115,7 @@ export function usePropertiesEdit(
|
|
|
113
115
|
continue;
|
|
114
116
|
}
|
|
115
117
|
|
|
116
|
-
nextProperties[_property.name] = _property;
|
|
118
|
+
nextProperties[_property.name] = omit(_property, ['key', 'name', 'isPropertyRequired']);
|
|
117
119
|
|
|
118
120
|
if (_property.isPropertyRequired) {
|
|
119
121
|
nextRequired.push(_property.name);
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useMemo, useState } from 'react';
|
|
7
7
|
|
|
8
|
+
import { IJsonSchema } from '@flowgram.ai/json-schema';
|
|
8
9
|
import { Button, Checkbox, IconButton } from '@douyinfe/semi-ui';
|
|
9
10
|
import {
|
|
10
11
|
IconExpand,
|
|
@@ -16,7 +17,6 @@ import {
|
|
|
16
17
|
} from '@douyinfe/semi-icons';
|
|
17
18
|
|
|
18
19
|
import { TypeSelector } from '../type-selector';
|
|
19
|
-
import { IJsonSchema } from '../../typings';
|
|
20
20
|
import { ConfigType, PropertyValueType } from './types';
|
|
21
21
|
import {
|
|
22
22
|
IconAddChildren,
|
|
@@ -44,8 +44,9 @@ export function JsonSchemaEditor(props: {
|
|
|
44
44
|
onChange?: (value: IJsonSchema) => void;
|
|
45
45
|
config?: ConfigType;
|
|
46
46
|
className?: string;
|
|
47
|
+
readonly?: boolean;
|
|
47
48
|
}) {
|
|
48
|
-
const { value = { type: 'object' }, config = {}, onChange: onChangeProps } = props;
|
|
49
|
+
const { value = { type: 'object' }, config = {}, onChange: onChangeProps, readonly } = props;
|
|
49
50
|
const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
|
|
50
51
|
value,
|
|
51
52
|
onChangeProps
|
|
@@ -56,6 +57,7 @@ export function JsonSchemaEditor(props: {
|
|
|
56
57
|
<UIProperties>
|
|
57
58
|
{propertyList.map((_property, index) => (
|
|
58
59
|
<PropertyEdit
|
|
60
|
+
readonly={readonly}
|
|
59
61
|
key={_property.key}
|
|
60
62
|
value={_property}
|
|
61
63
|
config={config}
|
|
@@ -70,6 +72,7 @@ export function JsonSchemaEditor(props: {
|
|
|
70
72
|
))}
|
|
71
73
|
</UIProperties>
|
|
72
74
|
<Button
|
|
75
|
+
disabled={readonly}
|
|
73
76
|
size="small"
|
|
74
77
|
style={{ marginTop: 10, marginLeft: 16 }}
|
|
75
78
|
icon={<IconPlus />}
|
|
@@ -86,6 +89,7 @@ function PropertyEdit(props: {
|
|
|
86
89
|
config?: ConfigType;
|
|
87
90
|
onChange?: (value: PropertyValueType) => void;
|
|
88
91
|
onRemove?: () => void;
|
|
92
|
+
readonly?: boolean;
|
|
89
93
|
$isLast?: boolean;
|
|
90
94
|
$index?: number;
|
|
91
95
|
$isFirst?: boolean;
|
|
@@ -97,6 +101,7 @@ function PropertyEdit(props: {
|
|
|
97
101
|
const {
|
|
98
102
|
value,
|
|
99
103
|
config,
|
|
104
|
+
readonly,
|
|
100
105
|
$level = 0,
|
|
101
106
|
onChange: onChangeProps,
|
|
102
107
|
onRemove,
|
|
@@ -155,6 +160,7 @@ function PropertyEdit(props: {
|
|
|
155
160
|
<UIRow>
|
|
156
161
|
<UIName>
|
|
157
162
|
<BlurInput
|
|
163
|
+
disabled={readonly}
|
|
158
164
|
placeholder={config?.placeholder ?? 'Input Variable Name'}
|
|
159
165
|
size="small"
|
|
160
166
|
value={name}
|
|
@@ -164,6 +170,7 @@ function PropertyEdit(props: {
|
|
|
164
170
|
<UIType>
|
|
165
171
|
<TypeSelector
|
|
166
172
|
value={typeSelectorValue}
|
|
173
|
+
readonly={readonly}
|
|
167
174
|
onChange={(_value) => {
|
|
168
175
|
onChangeProps?.({
|
|
169
176
|
...(value || {}),
|
|
@@ -174,12 +181,14 @@ function PropertyEdit(props: {
|
|
|
174
181
|
</UIType>
|
|
175
182
|
<UIRequired>
|
|
176
183
|
<Checkbox
|
|
184
|
+
disabled={readonly}
|
|
177
185
|
checked={isPropertyRequired}
|
|
178
186
|
onChange={(e) => onChange('isPropertyRequired', e.target.checked)}
|
|
179
187
|
/>
|
|
180
188
|
</UIRequired>
|
|
181
189
|
<UIActions>
|
|
182
190
|
<IconButton
|
|
191
|
+
disabled={readonly}
|
|
183
192
|
size="small"
|
|
184
193
|
theme="borderless"
|
|
185
194
|
icon={expand ? <IconShrink size="small" /> : <IconExpand size="small" />}
|
|
@@ -189,6 +198,7 @@ function PropertyEdit(props: {
|
|
|
189
198
|
/>
|
|
190
199
|
{isDrilldownObject && (
|
|
191
200
|
<IconButton
|
|
201
|
+
disabled={readonly}
|
|
192
202
|
size="small"
|
|
193
203
|
theme="borderless"
|
|
194
204
|
icon={<IconAddChildren />}
|
|
@@ -199,6 +209,7 @@ function PropertyEdit(props: {
|
|
|
199
209
|
/>
|
|
200
210
|
)}
|
|
201
211
|
<IconButton
|
|
212
|
+
disabled={readonly}
|
|
202
213
|
size="small"
|
|
203
214
|
theme="borderless"
|
|
204
215
|
icon={<IconMinus size="small" />}
|
|
@@ -210,6 +221,7 @@ function PropertyEdit(props: {
|
|
|
210
221
|
<UIExpandDetail>
|
|
211
222
|
<UILabel>{config?.descTitle ?? 'Description'}</UILabel>
|
|
212
223
|
<BlurInput
|
|
224
|
+
disabled={readonly}
|
|
213
225
|
size="small"
|
|
214
226
|
value={description}
|
|
215
227
|
onChange={(value) => onChange('description', value)}
|
|
@@ -240,6 +252,7 @@ function PropertyEdit(props: {
|
|
|
240
252
|
<UIProperties $shrink={true}>
|
|
241
253
|
{propertyList.map((_property, index) => (
|
|
242
254
|
<PropertyEdit
|
|
255
|
+
readonly={readonly}
|
|
243
256
|
key={_property.key}
|
|
244
257
|
value={_property}
|
|
245
258
|
config={config}
|
|
@@ -26,6 +26,7 @@ export function PromptEditor(props: PropsType) {
|
|
|
26
26
|
style,
|
|
27
27
|
hasError,
|
|
28
28
|
children,
|
|
29
|
+
disableMarkdownHighlight,
|
|
29
30
|
} = props || {};
|
|
30
31
|
|
|
31
32
|
const editorRef = useRef<EditorAPI | null>(null);
|
|
@@ -58,7 +59,7 @@ export function PromptEditor(props: PropsType) {
|
|
|
58
59
|
{activeLinePlaceholder && (
|
|
59
60
|
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
60
61
|
)}
|
|
61
|
-
<MarkdownHighlight />
|
|
62
|
+
{!disableMarkdownHighlight && <MarkdownHighlight />}
|
|
62
63
|
<LanguageSupport />
|
|
63
64
|
<JinjaHighlight />
|
|
64
65
|
{children}
|
|
@@ -79,7 +79,7 @@ export function InputsPicker({
|
|
|
79
79
|
const treeData: TreeNodeData[] = useMemo(
|
|
80
80
|
() =>
|
|
81
81
|
Object.entries(inputsValues).map(([key, value]) => {
|
|
82
|
-
if (value
|
|
82
|
+
if (value?.type === 'ref') {
|
|
83
83
|
const variable = available.getByKeyPath(value.content || []);
|
|
84
84
|
|
|
85
85
|
if (variable) {
|
|
@@ -67,10 +67,13 @@ class VariableTagWidget extends WidgetType {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const rootField = last(v.parentFields);
|
|
70
|
+
const rootField = last(v.parentFields) || v;
|
|
71
|
+
const isRoot = v.parentFields.length === 0;
|
|
71
72
|
|
|
72
73
|
const rootTitle = (
|
|
73
|
-
<UIRootTitle>
|
|
74
|
+
<UIRootTitle>
|
|
75
|
+
{rootField?.meta.title ? `${rootField.meta.title} ${isRoot ? '' : '-'} ` : ''}
|
|
76
|
+
</UIRootTitle>
|
|
74
77
|
);
|
|
75
78
|
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
76
79
|
|
|
@@ -86,7 +89,7 @@ class VariableTagWidget extends WidgetType {
|
|
|
86
89
|
>
|
|
87
90
|
<UITag prefixIcon={rootIcon}>
|
|
88
91
|
{rootTitle}
|
|
89
|
-
<UIVarName>{v?.key}</UIVarName>
|
|
92
|
+
{!isRoot && <UIVarName>{v?.key}</UIVarName>}
|
|
90
93
|
</UITag>
|
|
91
94
|
</Popover>
|
|
92
95
|
);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-selector",
|
|
3
|
-
"depMaterials": [
|
|
4
|
-
"depPackages": [
|
|
3
|
+
"depMaterials": [],
|
|
4
|
+
"depPackages": [
|
|
5
|
+
"@douyinfe/semi-ui",
|
|
6
|
+
"@douyinfe/semi-icons",
|
|
7
|
+
"@flowgram.ai/json-schema"
|
|
8
|
+
]
|
|
5
9
|
}
|