@flowgram.ai/form-materials 0.2.16 → 0.2.18
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/materials.ts +6 -1
- package/bin/project.ts +5 -0
- package/dist/esm/index.js +462 -14
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +177 -6
- package/dist/index.d.ts +177 -6
- package/dist/index.js +482 -43
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/components/batch-outputs/config.json +12 -0
- package/src/components/batch-outputs/index.tsx +61 -0
- package/src/components/batch-outputs/styles.tsx +19 -0
- package/src/components/batch-outputs/types.ts +22 -0
- package/src/components/batch-outputs/use-list.ts +86 -0
- package/src/components/batch-variable-selector/index.tsx +5 -0
- package/src/components/condition-row/constants.ts +5 -0
- package/src/components/condition-row/hooks/useOp.tsx +5 -0
- package/src/components/condition-row/hooks/useRule.ts +5 -0
- package/src/components/condition-row/index.tsx +5 -0
- package/src/components/condition-row/styles.tsx +5 -0
- package/src/components/condition-row/types.ts +5 -0
- package/src/components/constant-input/index.tsx +5 -0
- package/src/components/constant-input/types.ts +5 -0
- package/src/components/dynamic-value-input/index.tsx +7 -0
- package/src/components/dynamic-value-input/styles.tsx +7 -0
- package/src/components/index.ts +8 -0
- package/src/components/json-schema-editor/components/blur-input.tsx +5 -0
- package/src/components/json-schema-editor/default-value.tsx +5 -0
- package/src/components/json-schema-editor/hooks.tsx +5 -0
- package/src/components/json-schema-editor/index.tsx +5 -0
- package/src/components/json-schema-editor/styles.tsx +5 -0
- package/src/components/json-schema-editor/types.ts +5 -0
- package/src/components/json-schema-editor/utils.ts +5 -0
- package/src/components/prompt-editor/config.json +9 -0
- package/src/components/prompt-editor/extensions/jinja.tsx +58 -0
- package/src/components/prompt-editor/extensions/language-support.tsx +19 -0
- package/src/components/prompt-editor/extensions/markdown.tsx +75 -0
- package/src/components/prompt-editor/index.tsx +43 -0
- package/src/components/prompt-editor/styles.tsx +18 -0
- package/src/components/prompt-editor/types.tsx +16 -0
- package/src/components/prompt-editor-with-variables/config.json +10 -0
- package/src/components/prompt-editor-with-variables/extensions/variable.tsx +85 -0
- package/src/components/prompt-editor-with-variables/index.tsx +17 -0
- package/src/components/type-selector/constants.tsx +5 -0
- package/src/components/type-selector/index.tsx +5 -0
- package/src/components/variable-selector/index.tsx +9 -2
- package/src/components/variable-selector/styles.tsx +17 -1
- package/src/components/variable-selector/use-variable-tree.tsx +8 -3
- package/src/effects/auto-rename-ref/index.ts +5 -0
- package/src/effects/index.ts +5 -0
- package/src/effects/provide-batch-input/index.ts +5 -0
- package/src/effects/provide-batch-outputs/index.ts +5 -1
- package/src/effects/provide-json-schema-outputs/index.ts +5 -0
- package/src/effects/sync-variable-title/index.ts +5 -0
- package/src/form-plugins/batch-outputs-plugin/config.json +7 -0
- package/src/form-plugins/batch-outputs-plugin/index.ts +104 -0
- package/src/form-plugins/index.ts +6 -0
- package/src/index.ts +6 -0
- package/src/typings/flow-value/index.ts +5 -0
- package/src/typings/index.ts +5 -0
- package/src/typings/json-schema/index.ts +5 -0
- package/src/utils/format-legacy-refs/index.ts +5 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/json-schema/index.ts +21 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.18",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"chalk": "^5.3.0",
|
|
31
31
|
"inquirer": "^9.2.7",
|
|
32
32
|
"immer": "~10.1.1",
|
|
33
|
-
"@
|
|
33
|
+
"@coze-editor/editor": "0.1.0-alpha.8d7a30",
|
|
34
|
+
"@codemirror/view": "~6.38.0",
|
|
35
|
+
"@flowgram.ai/editor": "0.2.18"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@types/lodash": "^4.14.137",
|
|
@@ -46,8 +48,8 @@
|
|
|
46
48
|
"tsup": "^8.0.1",
|
|
47
49
|
"typescript": "^5.0.4",
|
|
48
50
|
"vitest": "^0.34.6",
|
|
49
|
-
"@flowgram.ai/
|
|
50
|
-
"@flowgram.ai/
|
|
51
|
+
"@flowgram.ai/ts-config": "0.2.18",
|
|
52
|
+
"@flowgram.ai/eslint-config": "0.2.18"
|
|
51
53
|
},
|
|
52
54
|
"peerDependencies": {
|
|
53
55
|
"react": ">=16.8",
|
|
@@ -0,0 +1,61 @@
|
|
|
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, Input } from '@douyinfe/semi-ui';
|
|
9
|
+
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
|
|
10
|
+
|
|
11
|
+
import { useList } from './use-list';
|
|
12
|
+
import { PropsType } from './types';
|
|
13
|
+
import { VariableSelector } from '../variable-selector';
|
|
14
|
+
import { UIRow, UIRows } from './styles';
|
|
15
|
+
|
|
16
|
+
export function BatchOutputs(props: PropsType) {
|
|
17
|
+
const { readonly, style } = props;
|
|
18
|
+
|
|
19
|
+
const { list, add, update, remove } = useList(props);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div>
|
|
23
|
+
<UIRows style={style}>
|
|
24
|
+
{list.map((item) => (
|
|
25
|
+
<UIRow key={item.id}>
|
|
26
|
+
<Input
|
|
27
|
+
style={{ width: 100 }}
|
|
28
|
+
disabled={readonly}
|
|
29
|
+
size="small"
|
|
30
|
+
value={item.key}
|
|
31
|
+
onChange={(v) => update({ ...item, key: v })}
|
|
32
|
+
/>
|
|
33
|
+
<VariableSelector
|
|
34
|
+
style={{ flexGrow: 1 }}
|
|
35
|
+
readonly={readonly}
|
|
36
|
+
value={item.value?.content}
|
|
37
|
+
onChange={(v) =>
|
|
38
|
+
update({
|
|
39
|
+
...item,
|
|
40
|
+
value: {
|
|
41
|
+
type: 'ref',
|
|
42
|
+
content: v,
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
/>
|
|
47
|
+
<Button
|
|
48
|
+
disabled={readonly}
|
|
49
|
+
icon={<IconDelete />}
|
|
50
|
+
size="small"
|
|
51
|
+
onClick={() => remove(item.id)}
|
|
52
|
+
/>
|
|
53
|
+
</UIRow>
|
|
54
|
+
))}
|
|
55
|
+
</UIRows>
|
|
56
|
+
<Button disabled={readonly} icon={<IconPlus />} size="small" onClick={add}>
|
|
57
|
+
Add
|
|
58
|
+
</Button>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -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 { IFlowRefValue } from '../../typings';
|
|
7
|
+
|
|
8
|
+
export type ValueType = Record<string, IFlowRefValue | undefined>;
|
|
9
|
+
|
|
10
|
+
export interface OutputItem {
|
|
11
|
+
id: number;
|
|
12
|
+
key?: string;
|
|
13
|
+
value?: IFlowRefValue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PropsType {
|
|
17
|
+
value?: ValueType;
|
|
18
|
+
onChange: (value?: ValueType) => void;
|
|
19
|
+
readonly?: boolean;
|
|
20
|
+
hasError?: boolean;
|
|
21
|
+
style?: React.CSSProperties;
|
|
22
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { difference } from 'lodash';
|
|
9
|
+
|
|
10
|
+
import { OutputItem, PropsType } from './types';
|
|
11
|
+
|
|
12
|
+
let _id = 0;
|
|
13
|
+
function genId() {
|
|
14
|
+
return _id++;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function useList({ value, onChange }: PropsType) {
|
|
18
|
+
const [list, setList] = useState<OutputItem[]>([]);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
setList((_prevList) => {
|
|
22
|
+
const newKeys = Object.keys(value || {});
|
|
23
|
+
const oldKeys = _prevList.map((item) => item.key).filter(Boolean) as string[];
|
|
24
|
+
const addKeys = difference(newKeys, oldKeys);
|
|
25
|
+
|
|
26
|
+
return _prevList
|
|
27
|
+
.filter((item) => !item.key || newKeys.includes(item.key))
|
|
28
|
+
.map((item) => ({
|
|
29
|
+
id: item.id,
|
|
30
|
+
key: item.key,
|
|
31
|
+
value: item.key ? value?.[item.key!] : undefined,
|
|
32
|
+
}))
|
|
33
|
+
.concat(
|
|
34
|
+
addKeys.map((_key) => ({
|
|
35
|
+
id: genId(),
|
|
36
|
+
key: _key,
|
|
37
|
+
value: value?.[_key],
|
|
38
|
+
}))
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
}, [value]);
|
|
42
|
+
|
|
43
|
+
const add = () => {
|
|
44
|
+
setList((prevList) => [
|
|
45
|
+
...prevList,
|
|
46
|
+
{
|
|
47
|
+
id: genId(),
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const update = (item: OutputItem) => {
|
|
53
|
+
setList((prevList) => {
|
|
54
|
+
const nextList = prevList.map((_item) => {
|
|
55
|
+
if (_item.id === item.id) {
|
|
56
|
+
return item;
|
|
57
|
+
}
|
|
58
|
+
return _item;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
onChange(
|
|
62
|
+
Object.fromEntries(
|
|
63
|
+
nextList.filter((item) => item.key).map((item) => [item.key!, item.value])
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
return nextList;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const remove = (itemId: number) => {
|
|
72
|
+
setList((prevList) => {
|
|
73
|
+
const nextList = prevList.filter((_item) => _item.id !== itemId);
|
|
74
|
+
|
|
75
|
+
onChange(
|
|
76
|
+
Object.fromEntries(
|
|
77
|
+
nextList.filter((item) => item.key).map((item) => [item.key!, item.value])
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return nextList;
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return { list, add, update, remove };
|
|
86
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import React, { useMemo } from 'react';
|
|
2
7
|
|
|
3
8
|
import { IconButton } from '@douyinfe/semi-ui';
|
|
@@ -19,6 +24,7 @@ interface PropsType {
|
|
|
19
24
|
schema?: IJsonSchema;
|
|
20
25
|
constantProps?: {
|
|
21
26
|
strategies?: Strategy[];
|
|
27
|
+
schema?: IJsonSchema; // set schema of constant input only
|
|
22
28
|
[key: string]: any;
|
|
23
29
|
};
|
|
24
30
|
}
|
|
@@ -44,6 +50,7 @@ export function DynamicValueInput({
|
|
|
44
50
|
// Display Variable Or Delete
|
|
45
51
|
return (
|
|
46
52
|
<VariableSelector
|
|
53
|
+
style={{ width: '100%' }}
|
|
47
54
|
value={value?.content}
|
|
48
55
|
onChange={(_v) => onChange(_v ? { type: 'ref', content: _v } : undefined)}
|
|
49
56
|
includeSchema={includeSchema}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import styled from 'styled-components';
|
|
2
7
|
|
|
3
8
|
export const UIContainer = styled.div`
|
|
@@ -8,6 +13,8 @@ export const UIContainer = styled.div`
|
|
|
8
13
|
|
|
9
14
|
export const UIMain = styled.div`
|
|
10
15
|
flex-grow: 1;
|
|
16
|
+
overflow: hidden;
|
|
17
|
+
min-width: 0;
|
|
11
18
|
|
|
12
19
|
& .semi-tree-select,
|
|
13
20
|
& .semi-input-number,
|
package/src/components/index.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
export * from './variable-selector';
|
|
2
7
|
export * from './type-selector';
|
|
3
8
|
export * from './json-schema-editor';
|
|
@@ -5,3 +10,6 @@ export * from './batch-variable-selector';
|
|
|
5
10
|
export * from './constant-input';
|
|
6
11
|
export * from './dynamic-value-input';
|
|
7
12
|
export * from './condition-row';
|
|
13
|
+
export * from './batch-outputs';
|
|
14
|
+
export * from './prompt-editor';
|
|
15
|
+
export * from './prompt-editor-with-variables';
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* Return the corresponding string description according to the type of the input value.根据输入值的类型返回对应的字符串描述。
|
|
3
8
|
* @param value - 需要判断类型的值。The value whose type needs to be judged.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useLayoutEffect } from 'react';
|
|
7
|
+
|
|
8
|
+
import { useInjector } from '@coze-editor/editor/react';
|
|
9
|
+
import { astDecorator } from '@coze-editor/editor';
|
|
10
|
+
import { EditorView } from '@codemirror/view';
|
|
11
|
+
|
|
12
|
+
function JinjaHighlight() {
|
|
13
|
+
const injector = useInjector();
|
|
14
|
+
|
|
15
|
+
useLayoutEffect(
|
|
16
|
+
() =>
|
|
17
|
+
injector.inject([
|
|
18
|
+
astDecorator.whole.of((cursor) => {
|
|
19
|
+
if (cursor.name === 'JinjaStatementStart' || cursor.name === 'JinjaStatementEnd') {
|
|
20
|
+
return {
|
|
21
|
+
type: 'className',
|
|
22
|
+
className: 'jinja-statement-bracket',
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (cursor.name === 'JinjaComment') {
|
|
27
|
+
return {
|
|
28
|
+
type: 'className',
|
|
29
|
+
className: 'jinja-comment',
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (cursor.name === 'JinjaExpression') {
|
|
34
|
+
return {
|
|
35
|
+
type: 'className',
|
|
36
|
+
className: 'jinja-expression',
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
EditorView.theme({
|
|
41
|
+
'.jinja-statement-bracket': {
|
|
42
|
+
color: '#D1009D',
|
|
43
|
+
},
|
|
44
|
+
'.jinja-comment': {
|
|
45
|
+
color: '#0607094D',
|
|
46
|
+
},
|
|
47
|
+
'.jinja-expression': {
|
|
48
|
+
color: '#4E40E5',
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
]),
|
|
52
|
+
[injector]
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default JinjaHighlight;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useLayoutEffect } from 'react';
|
|
7
|
+
|
|
8
|
+
import { useInjector } from '@coze-editor/editor/react';
|
|
9
|
+
import { languageSupport } from '@coze-editor/editor/preset-prompt';
|
|
10
|
+
|
|
11
|
+
function LanguageSupport() {
|
|
12
|
+
const injector = useInjector();
|
|
13
|
+
|
|
14
|
+
useLayoutEffect(() => injector.inject([languageSupport]), [injector]);
|
|
15
|
+
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default LanguageSupport;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useLayoutEffect } from 'react';
|
|
7
|
+
|
|
8
|
+
import { useInjector } from '@coze-editor/editor/react';
|
|
9
|
+
import { astDecorator } from '@coze-editor/editor';
|
|
10
|
+
import { EditorView } from '@codemirror/view';
|
|
11
|
+
|
|
12
|
+
function MarkdownHighlight() {
|
|
13
|
+
const injector = useInjector();
|
|
14
|
+
|
|
15
|
+
useLayoutEffect(
|
|
16
|
+
() =>
|
|
17
|
+
injector.inject([
|
|
18
|
+
astDecorator.whole.of((cursor) => {
|
|
19
|
+
// # heading
|
|
20
|
+
if (cursor.name.startsWith('ATXHeading')) {
|
|
21
|
+
return {
|
|
22
|
+
type: 'className',
|
|
23
|
+
className: 'heading',
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// *italic*
|
|
28
|
+
if (cursor.name === 'Emphasis') {
|
|
29
|
+
return {
|
|
30
|
+
type: 'className',
|
|
31
|
+
className: 'emphasis',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// **bold**
|
|
36
|
+
if (cursor.name === 'StrongEmphasis') {
|
|
37
|
+
return {
|
|
38
|
+
type: 'className',
|
|
39
|
+
className: 'strong-emphasis',
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// -
|
|
44
|
+
// 1.
|
|
45
|
+
// >
|
|
46
|
+
if (cursor.name === 'ListMark' || cursor.name === 'QuoteMark') {
|
|
47
|
+
return {
|
|
48
|
+
type: 'className',
|
|
49
|
+
className: 'mark',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
EditorView.theme({
|
|
54
|
+
'.heading': {
|
|
55
|
+
color: '#00818C',
|
|
56
|
+
fontWeight: 'bold',
|
|
57
|
+
},
|
|
58
|
+
'.emphasis': {
|
|
59
|
+
fontStyle: 'italic',
|
|
60
|
+
},
|
|
61
|
+
'.strong-emphasis': {
|
|
62
|
+
fontWeight: 'bold',
|
|
63
|
+
},
|
|
64
|
+
'.mark': {
|
|
65
|
+
color: '#4E40E5',
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
]),
|
|
69
|
+
[injector]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default MarkdownHighlight;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { Renderer, EditorProvider } from '@coze-editor/editor/react';
|
|
9
|
+
import preset from '@coze-editor/editor/preset-prompt';
|
|
10
|
+
|
|
11
|
+
import { PropsType } from './types';
|
|
12
|
+
import { UIContainer } from './styles';
|
|
13
|
+
import MarkdownHighlight from './extensions/markdown';
|
|
14
|
+
import LanguageSupport from './extensions/language-support';
|
|
15
|
+
import JinjaHighlight from './extensions/jinja';
|
|
16
|
+
|
|
17
|
+
export type PromptEditorPropsType = PropsType;
|
|
18
|
+
|
|
19
|
+
export function PromptEditor(props: PropsType) {
|
|
20
|
+
const { value, onChange, readonly, style, hasError, children } = props || {};
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<UIContainer $hasError={hasError} style={style}>
|
|
24
|
+
<EditorProvider>
|
|
25
|
+
<Renderer
|
|
26
|
+
plugins={preset}
|
|
27
|
+
defaultValue={String(value?.content)}
|
|
28
|
+
options={{
|
|
29
|
+
readOnly: readonly,
|
|
30
|
+
editable: !readonly,
|
|
31
|
+
}}
|
|
32
|
+
onChange={(e) => {
|
|
33
|
+
onChange({ type: 'template', content: e.value });
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
<MarkdownHighlight />
|
|
37
|
+
<LanguageSupport />
|
|
38
|
+
<JinjaHighlight />
|
|
39
|
+
{children}
|
|
40
|
+
</EditorProvider>
|
|
41
|
+
</UIContainer>
|
|
42
|
+
);
|
|
43
|
+
}
|