@flowgram.ai/form-materials 0.1.0-alpha.10
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 +99 -0
- package/bin/materials.ts +156 -0
- package/bin/project.ts +91 -0
- package/dist/esm/index.js +3303 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +495 -0
- package/dist/index.d.ts +495 -0
- package/dist/index.js +3299 -0
- package/dist/index.js.map +1 -0
- package/package.json +75 -0
- 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/config.json +5 -0
- package/src/components/batch-variable-selector/index.tsx +24 -0
- package/src/components/code-editor/config.json +9 -0
- package/src/components/code-editor/index.tsx +74 -0
- package/src/components/code-editor/language-features.ts +24 -0
- package/src/components/code-editor/theme/dark.ts +119 -0
- package/src/components/code-editor/theme/index.ts +12 -0
- package/src/components/code-editor/theme/light.ts +119 -0
- package/src/components/code-editor/utils.ts +20 -0
- package/src/components/condition-row/config.json +5 -0
- package/src/components/condition-row/constants.ts +128 -0
- package/src/components/condition-row/hooks/useOp.tsx +50 -0
- package/src/components/condition-row/hooks/useRule.ts +31 -0
- package/src/components/condition-row/index.tsx +81 -0
- package/src/components/condition-row/styles.tsx +30 -0
- package/src/components/condition-row/types.ts +42 -0
- package/src/components/constant-input/config.json +6 -0
- package/src/components/constant-input/index.tsx +86 -0
- package/src/components/constant-input/types.ts +23 -0
- package/src/components/dynamic-value-input/config.json +5 -0
- package/src/components/dynamic-value-input/index.tsx +92 -0
- package/src/components/dynamic-value-input/styles.tsx +26 -0
- package/src/components/index.ts +18 -0
- package/src/components/json-editor-with-variables/config.json +13 -0
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +173 -0
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +83 -0
- package/src/components/json-editor-with-variables/index.tsx +19 -0
- package/src/components/json-editor-with-variables/styles.tsx +44 -0
- package/src/components/json-schema-editor/components/blur-input.tsx +27 -0
- package/src/components/json-schema-editor/config.json +13 -0
- package/src/components/json-schema-editor/default-value.tsx +135 -0
- package/src/components/json-schema-editor/hooks.tsx +166 -0
- package/src/components/json-schema-editor/index.tsx +267 -0
- package/src/components/json-schema-editor/styles.tsx +240 -0
- package/src/components/json-schema-editor/types.ts +26 -0
- package/src/components/json-schema-editor/utils.ts +29 -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 +68 -0
- package/src/components/prompt-editor/styles.tsx +18 -0
- package/src/components/prompt-editor/types.tsx +18 -0
- package/src/components/prompt-editor-with-inputs/config.json +13 -0
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +82 -0
- package/src/components/prompt-editor-with-inputs/index.tsx +22 -0
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +100 -0
- package/src/components/prompt-editor-with-variables/config.json +13 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +179 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +83 -0
- package/src/components/prompt-editor-with-variables/index.tsx +19 -0
- package/src/components/prompt-editor-with-variables/styles.tsx +44 -0
- package/src/components/type-selector/config.json +5 -0
- package/src/components/type-selector/constants.tsx +364 -0
- package/src/components/type-selector/index.tsx +62 -0
- package/src/components/variable-selector/config.json +5 -0
- package/src/components/variable-selector/index.tsx +116 -0
- package/src/components/variable-selector/styles.tsx +59 -0
- package/src/components/variable-selector/use-variable-tree.tsx +103 -0
- package/src/effects/auto-rename-ref/config.json +5 -0
- package/src/effects/auto-rename-ref/index.ts +109 -0
- package/src/effects/index.ts +10 -0
- package/src/effects/provide-batch-input/config.json +5 -0
- package/src/effects/provide-batch-input/index.ts +43 -0
- package/src/effects/provide-batch-outputs/config.json +5 -0
- package/src/effects/provide-batch-outputs/index.ts +38 -0
- package/src/effects/provide-json-schema-outputs/config.json +8 -0
- package/src/effects/provide-json-schema-outputs/index.ts +28 -0
- package/src/effects/sync-variable-title/config.json +5 -0
- package/src/effects/sync-variable-title/index.ts +28 -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 +10 -0
- package/src/typings/flow-value/config.json +5 -0
- package/src/typings/flow-value/index.ts +32 -0
- package/src/typings/index.ts +7 -0
- package/src/typings/json-schema/config.json +5 -0
- package/src/typings/json-schema/index.ts +36 -0
- package/src/utils/format-legacy-refs/config.json +5 -0
- package/src/utils/format-legacy-refs/index.ts +158 -0
- package/src/utils/format-legacy-refs/readme.md +38 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/json-schema/config.json +5 -0
- package/src/utils/json-schema/index.ts +180 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { PrivateScopeProvider } from '@flowgram.ai/editor';
|
|
9
|
+
|
|
10
|
+
import { VariableSelector, VariableSelectorProps } from '../variable-selector';
|
|
11
|
+
import { IJsonSchema } from '../../typings';
|
|
12
|
+
|
|
13
|
+
const batchVariableSchema: IJsonSchema = {
|
|
14
|
+
type: 'array',
|
|
15
|
+
extra: { weak: true },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function BatchVariableSelector(props: VariableSelectorProps) {
|
|
19
|
+
return (
|
|
20
|
+
<PrivateScopeProvider>
|
|
21
|
+
<VariableSelector {...props} includeSchema={batchVariableSchema} />
|
|
22
|
+
</PrivateScopeProvider>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
@@ -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, { useEffect, useRef } from 'react';
|
|
7
|
+
|
|
8
|
+
import { ActiveLinePlaceholder, createRenderer, EditorProvider } from '@coze-editor/editor/react';
|
|
9
|
+
import preset, { type EditorAPI } from '@coze-editor/editor/preset-code';
|
|
10
|
+
import { EditorView } from '@codemirror/view';
|
|
11
|
+
|
|
12
|
+
import { getSuffixByLanguageId } from './utils';
|
|
13
|
+
|
|
14
|
+
import './theme';
|
|
15
|
+
import './language-features';
|
|
16
|
+
|
|
17
|
+
const OriginCodeEditor = createRenderer(preset, [
|
|
18
|
+
EditorView.theme({
|
|
19
|
+
'&.cm-focused': {
|
|
20
|
+
outline: 'none',
|
|
21
|
+
},
|
|
22
|
+
}),
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
export interface CodeEditorPropsType extends React.PropsWithChildren<{}> {
|
|
26
|
+
value?: string;
|
|
27
|
+
onChange?: (value: string) => void;
|
|
28
|
+
languageId: 'python' | 'typescript' | 'shell' | 'json';
|
|
29
|
+
theme?: 'dark' | 'light';
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
activeLinePlaceholder?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function CodeEditor({
|
|
35
|
+
value,
|
|
36
|
+
onChange,
|
|
37
|
+
languageId = 'python',
|
|
38
|
+
theme = 'light',
|
|
39
|
+
children,
|
|
40
|
+
placeholder,
|
|
41
|
+
activeLinePlaceholder,
|
|
42
|
+
}: CodeEditorPropsType) {
|
|
43
|
+
const editorRef = useRef<EditorAPI | null>(null);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
// listen to value change
|
|
47
|
+
if (editorRef.current?.getValue() !== value) {
|
|
48
|
+
editorRef.current?.setValue(String(value || ''));
|
|
49
|
+
}
|
|
50
|
+
}, [value]);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<EditorProvider>
|
|
54
|
+
<OriginCodeEditor
|
|
55
|
+
defaultValue={value}
|
|
56
|
+
options={{
|
|
57
|
+
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
58
|
+
languageId,
|
|
59
|
+
theme,
|
|
60
|
+
placeholder,
|
|
61
|
+
}}
|
|
62
|
+
didMount={(editor: EditorAPI) => {
|
|
63
|
+
editorRef.current = editor;
|
|
64
|
+
}}
|
|
65
|
+
onChange={(e) => onChange?.(e.value)}
|
|
66
|
+
>
|
|
67
|
+
{activeLinePlaceholder && (
|
|
68
|
+
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
69
|
+
)}
|
|
70
|
+
{children}
|
|
71
|
+
</OriginCodeEditor>
|
|
72
|
+
</EditorProvider>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { languages } from '@coze-editor/editor/preset-code';
|
|
7
|
+
// import { typescript } from '@coze-editor/editor/language-typescript';
|
|
8
|
+
import { shell } from '@coze-editor/editor/language-shell';
|
|
9
|
+
import { python } from '@coze-editor/editor/language-python';
|
|
10
|
+
import { json } from '@coze-editor/editor/language-json';
|
|
11
|
+
import { mixLanguages } from '@coze-editor/editor';
|
|
12
|
+
|
|
13
|
+
languages.register('python', python);
|
|
14
|
+
// languages.register('typescript', typescript);
|
|
15
|
+
|
|
16
|
+
languages.register('json', {
|
|
17
|
+
// mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
|
|
18
|
+
language: mixLanguages({
|
|
19
|
+
outerLanguage: json.language,
|
|
20
|
+
}),
|
|
21
|
+
languageService: json.languageService,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
languages.register('shell', shell);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createTheme, tags as t } from '@coze-editor/editor/preset-code';
|
|
7
|
+
import { type Extension } from '@codemirror/state';
|
|
8
|
+
|
|
9
|
+
const colors = {
|
|
10
|
+
background: '#151B27',
|
|
11
|
+
// syntax
|
|
12
|
+
comment: '#FFFFFF63',
|
|
13
|
+
key: '#39E5D7',
|
|
14
|
+
string: '#FF94D2',
|
|
15
|
+
number: '#FF9933',
|
|
16
|
+
boolean: '#78B0FF',
|
|
17
|
+
null: '#78B0FF',
|
|
18
|
+
separator: '#FFFFFFC9',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const darkTheme: Extension = createTheme({
|
|
22
|
+
variant: 'dark',
|
|
23
|
+
settings: {
|
|
24
|
+
background: colors.background,
|
|
25
|
+
foreground: '#fff',
|
|
26
|
+
caret: '#AEAFAD',
|
|
27
|
+
selection: '#d9d9d942',
|
|
28
|
+
gutterBackground: colors.background,
|
|
29
|
+
gutterForeground: '#FFFFFF63',
|
|
30
|
+
gutterBorderColor: 'transparent',
|
|
31
|
+
gutterBorderWidth: 0,
|
|
32
|
+
lineHighlight: '#272e3d36',
|
|
33
|
+
bracketColors: ['#FFEF61', '#DD99FF', '#78B0FF'],
|
|
34
|
+
tooltip: {
|
|
35
|
+
backgroundColor: '#363D4D',
|
|
36
|
+
color: '#fff',
|
|
37
|
+
border: 'none',
|
|
38
|
+
},
|
|
39
|
+
link: {
|
|
40
|
+
color: '#4daafc',
|
|
41
|
+
},
|
|
42
|
+
completionItemHover: {
|
|
43
|
+
backgroundColor: '#FFFFFF0F',
|
|
44
|
+
},
|
|
45
|
+
completionItemSelected: {
|
|
46
|
+
backgroundColor: '#FFFFFF17',
|
|
47
|
+
},
|
|
48
|
+
completionItemIcon: {
|
|
49
|
+
color: '#FFFFFFC9',
|
|
50
|
+
},
|
|
51
|
+
completionItemLabel: {
|
|
52
|
+
color: '#FFFFFFC9',
|
|
53
|
+
},
|
|
54
|
+
completionItemInfo: {
|
|
55
|
+
color: '#FFFFFFC9',
|
|
56
|
+
},
|
|
57
|
+
completionItemDetail: {
|
|
58
|
+
color: '#FFFFFF63',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
styles: [
|
|
62
|
+
// json
|
|
63
|
+
{
|
|
64
|
+
tag: t.comment,
|
|
65
|
+
color: colors.comment,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
tag: [t.propertyName],
|
|
69
|
+
color: colors.key,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
tag: [t.string],
|
|
73
|
+
color: colors.string,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
tag: [t.number],
|
|
77
|
+
color: colors.number,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
tag: [t.bool],
|
|
81
|
+
color: colors.boolean,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
tag: [t.null],
|
|
85
|
+
color: colors.null,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
tag: [t.separator],
|
|
89
|
+
color: colors.separator,
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
// markdown
|
|
93
|
+
{
|
|
94
|
+
tag: [t.heading],
|
|
95
|
+
color: '#6b6bff',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
tag: [t.processingInstruction],
|
|
99
|
+
color: '#6b6bff',
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
// shell
|
|
103
|
+
// curl
|
|
104
|
+
{
|
|
105
|
+
tag: [t.standard(t.variableName)],
|
|
106
|
+
color: '#3BEB84',
|
|
107
|
+
},
|
|
108
|
+
// -X
|
|
109
|
+
{
|
|
110
|
+
tag: [t.attributeName],
|
|
111
|
+
color: '#FF9933',
|
|
112
|
+
},
|
|
113
|
+
// url in string (includes quotes), e.g. "https://..."
|
|
114
|
+
{
|
|
115
|
+
tag: [t.special(t.string)],
|
|
116
|
+
color: '#78B0FF',
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { themes } from '@coze-editor/editor/preset-code';
|
|
7
|
+
|
|
8
|
+
import { lightTheme } from './light';
|
|
9
|
+
import { darkTheme } from './dark';
|
|
10
|
+
|
|
11
|
+
themes.register('dark', darkTheme);
|
|
12
|
+
themes.register('light', lightTheme);
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createTheme, tags as t } from '@coze-editor/editor/preset-code';
|
|
7
|
+
import { type Extension } from '@codemirror/state';
|
|
8
|
+
|
|
9
|
+
const colors = {
|
|
10
|
+
background: '#F7F7FC',
|
|
11
|
+
// syntax
|
|
12
|
+
comment: '#000A298A',
|
|
13
|
+
key: '#00818C',
|
|
14
|
+
string: '#D1009D',
|
|
15
|
+
number: '#C74200',
|
|
16
|
+
boolean: '#2B57D9',
|
|
17
|
+
null: '#2B57D9',
|
|
18
|
+
separator: '#0F1529D1',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const lightTheme: Extension = createTheme({
|
|
22
|
+
variant: 'light',
|
|
23
|
+
settings: {
|
|
24
|
+
background: '#fff',
|
|
25
|
+
foreground: '#000',
|
|
26
|
+
caret: '#000',
|
|
27
|
+
selection: '#d9d9d9',
|
|
28
|
+
gutterBackground: '#f0f0f0',
|
|
29
|
+
gutterForeground: '#666',
|
|
30
|
+
gutterBorderColor: 'transparent',
|
|
31
|
+
gutterBorderWidth: 0,
|
|
32
|
+
lineHighlight: '#f0f0f0',
|
|
33
|
+
bracketColors: ['#FFEF61', '#DD99FF', '#78B0FF'],
|
|
34
|
+
tooltip: {
|
|
35
|
+
backgroundColor: '#f0f0f0',
|
|
36
|
+
color: '#000',
|
|
37
|
+
border: '1px solid #ccc',
|
|
38
|
+
},
|
|
39
|
+
link: {
|
|
40
|
+
color: '#007bff',
|
|
41
|
+
},
|
|
42
|
+
completionItemHover: {
|
|
43
|
+
backgroundColor: '#f0f0f0',
|
|
44
|
+
},
|
|
45
|
+
completionItemSelected: {
|
|
46
|
+
backgroundColor: '#e0e0e0',
|
|
47
|
+
},
|
|
48
|
+
completionItemIcon: {
|
|
49
|
+
color: '#333',
|
|
50
|
+
},
|
|
51
|
+
completionItemLabel: {
|
|
52
|
+
color: '#333',
|
|
53
|
+
},
|
|
54
|
+
completionItemInfo: {
|
|
55
|
+
color: '#333',
|
|
56
|
+
},
|
|
57
|
+
completionItemDetail: {
|
|
58
|
+
color: '#666',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
styles: [
|
|
62
|
+
// JSON
|
|
63
|
+
{
|
|
64
|
+
tag: t.comment,
|
|
65
|
+
color: colors.comment,
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
tag: [t.propertyName],
|
|
69
|
+
color: colors.key,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
tag: [t.string],
|
|
73
|
+
color: colors.string,
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
tag: [t.number],
|
|
77
|
+
color: colors.number,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
tag: [t.bool],
|
|
81
|
+
color: colors.boolean,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
tag: [t.null],
|
|
85
|
+
color: colors.null,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
tag: [t.separator],
|
|
89
|
+
color: colors.separator,
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
// markdown
|
|
93
|
+
{
|
|
94
|
+
tag: [t.heading],
|
|
95
|
+
color: '#3e76ef',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
tag: [t.processingInstruction],
|
|
99
|
+
color: '#3e76ef',
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
// shell
|
|
103
|
+
// curl
|
|
104
|
+
{
|
|
105
|
+
tag: [t.standard(t.variableName)],
|
|
106
|
+
color: '#00804A',
|
|
107
|
+
},
|
|
108
|
+
// -X
|
|
109
|
+
{
|
|
110
|
+
tag: [t.attributeName],
|
|
111
|
+
color: '#C74200',
|
|
112
|
+
},
|
|
113
|
+
// url in string (includes quotes), e.g. "https://..."
|
|
114
|
+
{
|
|
115
|
+
tag: [t.special(t.string)],
|
|
116
|
+
color: '#2B57D9',
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export function getSuffixByLanguageId(languageId: string) {
|
|
7
|
+
if (languageId === 'python') {
|
|
8
|
+
return '.py';
|
|
9
|
+
}
|
|
10
|
+
if (languageId === 'typescript') {
|
|
11
|
+
return '.ts';
|
|
12
|
+
}
|
|
13
|
+
if (languageId === 'shell') {
|
|
14
|
+
return '.sh';
|
|
15
|
+
}
|
|
16
|
+
if (languageId === 'json') {
|
|
17
|
+
return '.json';
|
|
18
|
+
}
|
|
19
|
+
return '';
|
|
20
|
+
}
|