@flowgram.ai/form-materials 0.1.0-alpha.12 → 0.1.0-alpha.14
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 +4 -29
- package/bin/materials.ts +56 -87
- package/bin/project.ts +4 -0
- package/bin/utils/import.ts +127 -0
- package/bin/utils/traverse-file.ts +60 -0
- package/dist/esm/chunk-727SU246.js +13 -0
- package/dist/esm/chunk-727SU246.js.map +1 -0
- package/dist/esm/chunk-DEZUEMUM.js +284 -0
- package/dist/esm/chunk-DEZUEMUM.js.map +1 -0
- package/dist/esm/chunk-DUOXDOUE.js +477 -0
- package/dist/esm/chunk-DUOXDOUE.js.map +1 -0
- package/dist/esm/editor-6UMULJYB.js +180 -0
- package/dist/esm/editor-6UMULJYB.js.map +1 -0
- package/dist/esm/editor-EYOQTGMT.js +282 -0
- package/dist/esm/editor-EYOQTGMT.js.map +1 -0
- package/dist/esm/editor-OXPGKPF5.js +167 -0
- package/dist/esm/editor-OXPGKPF5.js.map +1 -0
- package/dist/esm/editor-VO6YAXRC.js +249 -0
- package/dist/esm/editor-VO6YAXRC.js.map +1 -0
- package/dist/esm/editor-XYLKTB6L.js +365 -0
- package/dist/esm/editor-XYLKTB6L.js.map +1 -0
- package/dist/esm/index.js +1186 -2456
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.mts +363 -70
- package/dist/index.d.ts +363 -70
- package/dist/index.js +4064 -2887
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- 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 +7 -5
- package/src/components/batch-outputs/types.ts +1 -1
- package/src/components/batch-variable-selector/index.tsx +1 -1
- package/src/components/code-editor/editor.tsx +89 -0
- package/src/components/code-editor/index.tsx +5 -89
- package/src/components/code-editor/language-features.ts +18 -18
- package/src/components/code-editor/theme/dark.ts +49 -30
- package/src/components/code-editor/theme/light.ts +56 -32
- package/src/components/code-editor-mini/index.tsx +2 -2
- package/src/components/condition-row/constants.ts +10 -2
- package/src/components/condition-row/hooks/useOp.tsx +13 -9
- package/src/components/condition-row/hooks/useRule.ts +8 -4
- package/src/components/condition-row/index.tsx +31 -10
- package/src/components/condition-row/types.ts +5 -7
- package/src/components/constant-input/index.tsx +5 -2
- package/src/components/constant-input/types.ts +1 -1
- package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
- package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
- package/src/components/db-condition-row/index.tsx +93 -0
- package/src/components/db-condition-row/styles.tsx +43 -0
- package/src/components/db-condition-row/types.ts +34 -0
- package/src/components/display-flow-value/index.tsx +4 -14
- package/src/components/display-inputs-values/index.tsx +46 -7
- 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 +25 -4
- package/src/components/dynamic-value-input/index.tsx +33 -20
- package/src/components/dynamic-value-input/styles.tsx +14 -4
- package/src/components/index.ts +3 -0
- package/src/components/inputs-values/index.tsx +21 -8
- package/src/components/inputs-values/styles.tsx +1 -1
- package/src/components/inputs-values/types.ts +3 -3
- package/src/components/inputs-values-tree/hooks/use-child-list.tsx +76 -0
- package/src/components/inputs-values-tree/index.tsx +62 -0
- package/src/components/inputs-values-tree/row.tsx +177 -0
- package/src/components/inputs-values-tree/styles.tsx +128 -0
- package/src/components/inputs-values-tree/types.ts +21 -0
- package/src/components/json-editor-with-variables/editor.tsx +69 -0
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +6 -5
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +1 -1
- package/src/components/json-editor-with-variables/index.tsx +5 -58
- package/src/components/json-schema-editor/default-value.tsx +12 -108
- package/src/components/json-schema-editor/hooks.tsx +63 -93
- package/src/components/json-schema-editor/index.tsx +36 -70
- package/src/components/json-schema-editor/styles.tsx +12 -84
- package/src/components/json-schema-editor/types.ts +0 -1
- package/src/components/prompt-editor/editor.tsx +81 -0
- package/src/components/prompt-editor/index.tsx +5 -62
- package/src/components/prompt-editor/types.tsx +1 -1
- package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +13 -1
- package/src/components/prompt-editor-with-inputs/index.tsx +5 -15
- package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +34 -17
- package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
- package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +12 -20
- package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +14 -2
- package/src/components/prompt-editor-with-variables/index.tsx +5 -12
- package/src/components/type-selector/index.tsx +21 -9
- package/src/components/variable-selector/context.tsx +28 -0
- package/src/components/variable-selector/index.tsx +19 -6
- package/src/components/variable-selector/use-variable-tree.tsx +4 -4
- package/src/effects/auto-rename-ref/index.ts +8 -55
- 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/effects/validate-when-variable-sync/index.ts +1 -1
- package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
- package/src/form-plugins/infer-assign-plugin/index.ts +2 -2
- package/src/form-plugins/infer-inputs-plugin/index.ts +4 -76
- package/src/hooks/use-object-list/index.tsx +35 -7
- package/src/index.ts +1 -0
- package/src/plugins/json-schema-preset/manager.ts +1 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +3 -1
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +4 -3
- package/src/plugins/json-schema-preset/type-definition/date-time.tsx +25 -0
- package/src/plugins/json-schema-preset/type-definition/index.tsx +2 -0
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/number.tsx +2 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +3 -1
- package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -4
- package/src/shared/flow-value/index.ts +6 -0
- package/src/shared/flow-value/schema.ts +38 -0
- package/src/shared/flow-value/utils.ts +201 -0
- package/src/shared/format-legacy-refs/index.ts +1 -1
- package/src/shared/index.ts +4 -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/shared/lazy-suspense/index.tsx +28 -0
- package/src/shared/polyfill-create-root/index.tsx +33 -0
- package/src/typings/flow-value/index.ts +3 -1
- package/src/validate/validate-flow-value/index.tsx +4 -16
- 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/components/blur-input.tsx +0 -27
- 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/plugins/disable-declaration-plugin/config.json +0 -5
- package/src/plugins/json-schema-preset/config.json +0 -9
- 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/src/components/{inputs-values/components/blur-input.tsx → blur-input/index.tsx} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flowgram.ai/form-materials",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.14",
|
|
4
4
|
"homepage": "https://flowgram.ai/",
|
|
5
5
|
"repository": "https://github.com/bytedance/flowgram.ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,21 +24,22 @@
|
|
|
24
24
|
"@douyinfe/semi-icons": "^2.80.0",
|
|
25
25
|
"@douyinfe/semi-illustrations": "^2.80.0",
|
|
26
26
|
"@douyinfe/semi-ui": "^2.80.0",
|
|
27
|
-
"lodash": "^4.17.21",
|
|
27
|
+
"lodash-es": "^4.17.21",
|
|
28
28
|
"nanoid": "^4.0.2",
|
|
29
29
|
"commander": "^11.0.0",
|
|
30
30
|
"chalk": "^5.3.0",
|
|
31
31
|
"inquirer": "^9.2.7",
|
|
32
32
|
"immer": "~10.1.1",
|
|
33
|
-
"@coze-editor/editor": "0.1.0-alpha.
|
|
33
|
+
"@coze-editor/editor": "0.1.0-alpha.5a549c",
|
|
34
34
|
"@codemirror/view": "~6.38.0",
|
|
35
35
|
"@codemirror/state": "~6.5.2",
|
|
36
36
|
"typescript": "^5.8.3",
|
|
37
|
-
"
|
|
38
|
-
"@flowgram.ai/
|
|
37
|
+
"zod": "^3.24.4",
|
|
38
|
+
"@flowgram.ai/editor": "0.1.0-alpha.14",
|
|
39
|
+
"@flowgram.ai/json-schema": "0.1.0-alpha.14"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@types/lodash": "^4.
|
|
42
|
+
"@types/lodash-es": "^4.17.12",
|
|
42
43
|
"@types/node": "^18",
|
|
43
44
|
"@types/react": "^18",
|
|
44
45
|
"@types/react-dom": "^18",
|
|
@@ -51,8 +52,8 @@
|
|
|
51
52
|
"tsup": "^8.0.1",
|
|
52
53
|
"typescript": "^5.8.3",
|
|
53
54
|
"vitest": "^0.34.6",
|
|
54
|
-
"@flowgram.ai/eslint-config": "0.1.0-alpha.
|
|
55
|
-
"@flowgram.ai/ts-config": "0.1.0-alpha.
|
|
55
|
+
"@flowgram.ai/eslint-config": "0.1.0-alpha.14",
|
|
56
|
+
"@flowgram.ai/ts-config": "0.1.0-alpha.14"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
58
59
|
"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;
|
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import React from 'react';
|
|
7
7
|
|
|
8
|
+
import { I18n } from '@flowgram.ai/editor';
|
|
8
9
|
import { Button, Input } from '@douyinfe/semi-ui';
|
|
9
10
|
import { IconDelete, IconPlus } from '@douyinfe/semi-icons';
|
|
10
11
|
|
|
12
|
+
import { useObjectList } from '@/hooks';
|
|
13
|
+
import { InjectVariableSelector } from '@/components/variable-selector';
|
|
14
|
+
|
|
11
15
|
import { PropsType } from './types';
|
|
12
|
-
import { VariableSelector } from '../variable-selector';
|
|
13
|
-
import { useObjectList } from '../../hooks';
|
|
14
16
|
import { UIRow, UIRows } from './styles';
|
|
15
17
|
|
|
16
18
|
export function BatchOutputs(props: PropsType) {
|
|
@@ -30,7 +32,7 @@ export function BatchOutputs(props: PropsType) {
|
|
|
30
32
|
value={item.key}
|
|
31
33
|
onChange={(v) => updateKey(item.id, v)}
|
|
32
34
|
/>
|
|
33
|
-
<
|
|
35
|
+
<InjectVariableSelector
|
|
34
36
|
style={{ flexGrow: 1 }}
|
|
35
37
|
readonly={readonly}
|
|
36
38
|
value={item.value?.content}
|
|
@@ -45,8 +47,8 @@ export function BatchOutputs(props: PropsType) {
|
|
|
45
47
|
</UIRow>
|
|
46
48
|
))}
|
|
47
49
|
</UIRows>
|
|
48
|
-
<Button disabled={readonly} icon={<IconPlus />} size="small" onClick={add}>
|
|
49
|
-
Add
|
|
50
|
+
<Button disabled={readonly} icon={<IconPlus />} size="small" onClick={() => add()}>
|
|
51
|
+
{I18n.t('Add')}
|
|
50
52
|
</Button>
|
|
51
53
|
</div>
|
|
52
54
|
);
|
|
@@ -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',
|
|
@@ -0,0 +1,89 @@
|
|
|
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 {
|
|
9
|
+
ActiveLinePlaceholder,
|
|
10
|
+
createRenderer,
|
|
11
|
+
EditorProvider,
|
|
12
|
+
InferValues,
|
|
13
|
+
} from '@coze-editor/editor/react';
|
|
14
|
+
import preset, { type EditorAPI } from '@coze-editor/editor/preset-code';
|
|
15
|
+
import { EditorView } from '@codemirror/view';
|
|
16
|
+
|
|
17
|
+
import { getSuffixByLanguageId } from './utils';
|
|
18
|
+
|
|
19
|
+
import './theme';
|
|
20
|
+
import './language-features';
|
|
21
|
+
|
|
22
|
+
const OriginCodeEditor = createRenderer(preset, [
|
|
23
|
+
EditorView.theme({
|
|
24
|
+
'&.cm-focused': {
|
|
25
|
+
outline: 'none',
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
type Preset = typeof preset;
|
|
31
|
+
type Options = Partial<InferValues<Preset[number]>>;
|
|
32
|
+
|
|
33
|
+
export interface CodeEditorPropsType extends React.PropsWithChildren<{}> {
|
|
34
|
+
value?: string;
|
|
35
|
+
onChange?: (value: string) => void;
|
|
36
|
+
languageId: 'python' | 'typescript' | 'shell' | 'json';
|
|
37
|
+
theme?: 'dark' | 'light';
|
|
38
|
+
placeholder?: string;
|
|
39
|
+
activeLinePlaceholder?: string;
|
|
40
|
+
readonly?: boolean;
|
|
41
|
+
options?: Options;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function CodeEditor({
|
|
45
|
+
value,
|
|
46
|
+
onChange,
|
|
47
|
+
languageId = 'python',
|
|
48
|
+
theme = 'light',
|
|
49
|
+
children,
|
|
50
|
+
placeholder,
|
|
51
|
+
activeLinePlaceholder,
|
|
52
|
+
options,
|
|
53
|
+
readonly,
|
|
54
|
+
}: CodeEditorPropsType) {
|
|
55
|
+
const editorRef = useRef<EditorAPI | null>(null);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
// listen to value change
|
|
59
|
+
if (editorRef.current?.getValue() !== value) {
|
|
60
|
+
editorRef.current?.setValue(String(value || ''));
|
|
61
|
+
}
|
|
62
|
+
}, [value]);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<EditorProvider>
|
|
66
|
+
<OriginCodeEditor
|
|
67
|
+
defaultValue={String(value || '')}
|
|
68
|
+
options={{
|
|
69
|
+
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
70
|
+
languageId,
|
|
71
|
+
theme,
|
|
72
|
+
placeholder,
|
|
73
|
+
readOnly: readonly,
|
|
74
|
+
editable: !readonly,
|
|
75
|
+
...(options || {}),
|
|
76
|
+
}}
|
|
77
|
+
didMount={(editor: EditorAPI) => {
|
|
78
|
+
editorRef.current = editor;
|
|
79
|
+
}}
|
|
80
|
+
onChange={(e) => onChange?.(e.value)}
|
|
81
|
+
>
|
|
82
|
+
{activeLinePlaceholder && (
|
|
83
|
+
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
84
|
+
)}
|
|
85
|
+
{children}
|
|
86
|
+
</OriginCodeEditor>
|
|
87
|
+
</EditorProvider>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -3,94 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import { lazySuspense } from '@/shared';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
EditorProvider,
|
|
12
|
-
InferValues,
|
|
13
|
-
} from '@coze-editor/editor/react';
|
|
14
|
-
import preset, { type EditorAPI } from '@coze-editor/editor/preset-code';
|
|
15
|
-
import { EditorView } from '@codemirror/view';
|
|
8
|
+
export const CodeEditor = lazySuspense(() =>
|
|
9
|
+
import('./editor').then((module) => ({ default: module.CodeEditor }))
|
|
10
|
+
);
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
import { initTsWorker } from './language-features';
|
|
19
|
-
|
|
20
|
-
import './theme';
|
|
21
|
-
import './language-features';
|
|
22
|
-
|
|
23
|
-
const OriginCodeEditor = createRenderer(preset, [
|
|
24
|
-
EditorView.theme({
|
|
25
|
-
'&.cm-focused': {
|
|
26
|
-
outline: 'none',
|
|
27
|
-
},
|
|
28
|
-
}),
|
|
29
|
-
]);
|
|
30
|
-
|
|
31
|
-
type Preset = typeof preset;
|
|
32
|
-
type Options = Partial<InferValues<Preset[number]>>;
|
|
33
|
-
|
|
34
|
-
export interface CodeEditorPropsType extends React.PropsWithChildren<{}> {
|
|
35
|
-
value?: string;
|
|
36
|
-
onChange?: (value: string) => void;
|
|
37
|
-
languageId: 'python' | 'typescript' | 'shell' | 'json';
|
|
38
|
-
theme?: 'dark' | 'light';
|
|
39
|
-
placeholder?: string;
|
|
40
|
-
activeLinePlaceholder?: string;
|
|
41
|
-
readonly?: boolean;
|
|
42
|
-
options?: Options;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function CodeEditor({
|
|
46
|
-
value,
|
|
47
|
-
onChange,
|
|
48
|
-
languageId = 'python',
|
|
49
|
-
theme = 'light',
|
|
50
|
-
children,
|
|
51
|
-
placeholder,
|
|
52
|
-
activeLinePlaceholder,
|
|
53
|
-
options,
|
|
54
|
-
readonly,
|
|
55
|
-
}: CodeEditorPropsType) {
|
|
56
|
-
const editorRef = useRef<EditorAPI | null>(null);
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (languageId === 'typescript') {
|
|
60
|
-
initTsWorker();
|
|
61
|
-
}
|
|
62
|
-
}, [languageId]);
|
|
63
|
-
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
// listen to value change
|
|
66
|
-
if (editorRef.current?.getValue() !== value) {
|
|
67
|
-
editorRef.current?.setValue(String(value || ''));
|
|
68
|
-
}
|
|
69
|
-
}, [value]);
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<EditorProvider>
|
|
73
|
-
<OriginCodeEditor
|
|
74
|
-
defaultValue={value}
|
|
75
|
-
options={{
|
|
76
|
-
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
77
|
-
languageId,
|
|
78
|
-
theme,
|
|
79
|
-
placeholder,
|
|
80
|
-
readOnly: readonly,
|
|
81
|
-
editable: !readonly,
|
|
82
|
-
...(options || {}),
|
|
83
|
-
}}
|
|
84
|
-
didMount={(editor: EditorAPI) => {
|
|
85
|
-
editorRef.current = editor;
|
|
86
|
-
}}
|
|
87
|
-
onChange={(e) => onChange?.(e.value)}
|
|
88
|
-
>
|
|
89
|
-
{activeLinePlaceholder && (
|
|
90
|
-
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
91
|
-
)}
|
|
92
|
-
{children}
|
|
93
|
-
</OriginCodeEditor>
|
|
94
|
-
</EditorProvider>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
12
|
+
export type { CodeEditorPropsType } from './editor';
|
|
@@ -22,23 +22,23 @@ languages.register('json', {
|
|
|
22
22
|
languageService: json.languageService,
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
let tsWorkerInit = false;
|
|
25
|
+
// let tsWorkerInit = false;
|
|
26
26
|
|
|
27
|
-
export const initTsWorker = () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
// export const initTsWorker = () => {
|
|
28
|
+
// if (tsWorkerInit) {
|
|
29
|
+
// return;
|
|
30
|
+
// }
|
|
31
|
+
// tsWorkerInit = true;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
33
|
+
// const tsWorker = new Worker(
|
|
34
|
+
// new URL(`@coze-editor/editor/language-typescript/worker`, import.meta.url),
|
|
35
|
+
// { type: 'module' }
|
|
36
|
+
// );
|
|
37
|
+
// typescript.languageService.initialize(tsWorker, {
|
|
38
|
+
// compilerOptions: {
|
|
39
|
+
// // eliminate Promise error
|
|
40
|
+
// lib: ['es2015', 'dom'],
|
|
41
|
+
// noImplicitAny: false,
|
|
42
|
+
// },
|
|
43
|
+
// });
|
|
44
|
+
// };
|
|
@@ -7,55 +7,56 @@ import { createTheme, tags as t } from '@coze-editor/editor/preset-code';
|
|
|
7
7
|
import { type Extension } from '@codemirror/state';
|
|
8
8
|
|
|
9
9
|
const colors = {
|
|
10
|
-
background: '#
|
|
11
|
-
// syntax
|
|
12
|
-
comment: '#
|
|
13
|
-
key: '#
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
background: '#0D1117',
|
|
11
|
+
// syntax - 现代化暗色主题配色
|
|
12
|
+
comment: '#8B949E',
|
|
13
|
+
key: '#7DD3FC',
|
|
14
|
+
variable: '#F472B6',
|
|
15
|
+
string: '#34D399',
|
|
16
|
+
number: '#FBBF24',
|
|
17
|
+
boolean: '#A78BFA',
|
|
18
|
+
null: '#A78BFA',
|
|
19
|
+
separator: '#E6EDF3',
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export const darkTheme: Extension = createTheme({
|
|
22
23
|
variant: 'dark',
|
|
23
24
|
settings: {
|
|
24
25
|
background: colors.background,
|
|
25
|
-
foreground: '#
|
|
26
|
-
caret: '#
|
|
27
|
-
selection: '#
|
|
26
|
+
foreground: '#E6EDF3',
|
|
27
|
+
caret: '#7DD3FC',
|
|
28
|
+
selection: '#264F7833',
|
|
28
29
|
gutterBackground: colors.background,
|
|
29
|
-
gutterForeground: '#
|
|
30
|
+
gutterForeground: '#6E7681',
|
|
30
31
|
gutterBorderColor: 'transparent',
|
|
31
32
|
gutterBorderWidth: 0,
|
|
32
|
-
lineHighlight: '#
|
|
33
|
-
bracketColors: ['#
|
|
33
|
+
lineHighlight: '#21262D',
|
|
34
|
+
bracketColors: ['#FBBF24', '#A78BFA', '#7DD3FC'],
|
|
34
35
|
tooltip: {
|
|
35
|
-
backgroundColor: '#
|
|
36
|
-
color: '#
|
|
37
|
-
border: '
|
|
36
|
+
backgroundColor: '#21262D',
|
|
37
|
+
color: '#E6EDF3',
|
|
38
|
+
border: '1px solid #30363D',
|
|
38
39
|
},
|
|
39
40
|
link: {
|
|
40
|
-
color: '#
|
|
41
|
+
color: '#58A6FF',
|
|
41
42
|
},
|
|
42
43
|
completionItemHover: {
|
|
43
|
-
backgroundColor: '#
|
|
44
|
+
backgroundColor: '#21262D',
|
|
44
45
|
},
|
|
45
46
|
completionItemSelected: {
|
|
46
|
-
backgroundColor: '#
|
|
47
|
+
backgroundColor: '#1F6EEB',
|
|
47
48
|
},
|
|
48
49
|
completionItemIcon: {
|
|
49
|
-
color: '#
|
|
50
|
+
color: '#8B949E',
|
|
50
51
|
},
|
|
51
52
|
completionItemLabel: {
|
|
52
|
-
color: '#
|
|
53
|
+
color: '#E6EDF3',
|
|
53
54
|
},
|
|
54
55
|
completionItemInfo: {
|
|
55
|
-
color: '#
|
|
56
|
+
color: '#8B949E',
|
|
56
57
|
},
|
|
57
58
|
completionItemDetail: {
|
|
58
|
-
color: '#
|
|
59
|
+
color: '#6E7681',
|
|
59
60
|
},
|
|
60
61
|
},
|
|
61
62
|
styles: [
|
|
@@ -89,31 +90,49 @@ export const darkTheme: Extension = createTheme({
|
|
|
89
90
|
color: colors.separator,
|
|
90
91
|
},
|
|
91
92
|
|
|
93
|
+
// js
|
|
94
|
+
{
|
|
95
|
+
tag: [t.definitionKeyword],
|
|
96
|
+
color: '#C084FC',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
tag: [t.modifier],
|
|
100
|
+
color: '#C084FC',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
tag: [t.controlKeyword],
|
|
104
|
+
color: '#C084FC',
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
tag: [t.operatorKeyword],
|
|
108
|
+
color: '#C084FC',
|
|
109
|
+
},
|
|
110
|
+
|
|
92
111
|
// markdown
|
|
93
112
|
{
|
|
94
113
|
tag: [t.heading],
|
|
95
|
-
color: '#
|
|
114
|
+
color: '#7DD3FC',
|
|
96
115
|
},
|
|
97
116
|
{
|
|
98
117
|
tag: [t.processingInstruction],
|
|
99
|
-
color: '#
|
|
118
|
+
color: '#7DD3FC',
|
|
100
119
|
},
|
|
101
120
|
|
|
102
121
|
// shell
|
|
103
122
|
// curl
|
|
104
123
|
{
|
|
105
124
|
tag: [t.standard(t.variableName)],
|
|
106
|
-
color: '#
|
|
125
|
+
color: '#34D399',
|
|
107
126
|
},
|
|
108
127
|
// -X
|
|
109
128
|
{
|
|
110
129
|
tag: [t.attributeName],
|
|
111
|
-
color: '#
|
|
130
|
+
color: '#FBBF24',
|
|
112
131
|
},
|
|
113
132
|
// url in string (includes quotes), e.g. "https://..."
|
|
114
133
|
{
|
|
115
134
|
tag: [t.special(t.string)],
|
|
116
|
-
color: '#
|
|
135
|
+
color: '#7DD3FC',
|
|
117
136
|
},
|
|
118
137
|
],
|
|
119
138
|
});
|
|
@@ -7,55 +7,56 @@ import { createTheme, tags as t } from '@coze-editor/editor/preset-code';
|
|
|
7
7
|
import { type Extension } from '@codemirror/state';
|
|
8
8
|
|
|
9
9
|
const colors = {
|
|
10
|
-
background: '#
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
string: '#
|
|
15
|
-
number: '#
|
|
16
|
-
boolean: '#
|
|
17
|
-
null: '#
|
|
18
|
-
separator: '#
|
|
10
|
+
background: '#FFFFFF',
|
|
11
|
+
comment: '#6B7280',
|
|
12
|
+
key: '#2563EB',
|
|
13
|
+
variable: '#DC2626',
|
|
14
|
+
string: '#059669',
|
|
15
|
+
number: '#EA580C',
|
|
16
|
+
boolean: '#7C3AED',
|
|
17
|
+
null: '#7C3AED',
|
|
18
|
+
separator: '#374151',
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
export const lightTheme: Extension = createTheme({
|
|
22
22
|
variant: 'light',
|
|
23
23
|
settings: {
|
|
24
|
-
background: '#
|
|
25
|
-
foreground: '#
|
|
26
|
-
caret: '#
|
|
27
|
-
selection: '#
|
|
28
|
-
gutterBackground: '#
|
|
29
|
-
gutterForeground: '#
|
|
24
|
+
background: '#FFFFFF',
|
|
25
|
+
foreground: '#1F2937',
|
|
26
|
+
caret: '#2563EB',
|
|
27
|
+
selection: '#E5E7EB',
|
|
28
|
+
gutterBackground: '#F9FAFB',
|
|
29
|
+
gutterForeground: '#6B7280',
|
|
30
30
|
gutterBorderColor: 'transparent',
|
|
31
31
|
gutterBorderWidth: 0,
|
|
32
|
-
lineHighlight: '#
|
|
33
|
-
bracketColors: ['#
|
|
32
|
+
lineHighlight: '#F3F4F680',
|
|
33
|
+
bracketColors: ['#F59E0B', '#8B5CF6', '#06B6D4'],
|
|
34
34
|
tooltip: {
|
|
35
|
-
backgroundColor: '#
|
|
36
|
-
color: '#
|
|
37
|
-
border: '1px solid #
|
|
35
|
+
backgroundColor: '#FFFFFF',
|
|
36
|
+
color: '#1F2937',
|
|
37
|
+
border: '1px solid #E5E7EB',
|
|
38
|
+
boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
|
|
38
39
|
},
|
|
39
40
|
link: {
|
|
40
|
-
color: '#
|
|
41
|
+
color: '#2563EB',
|
|
41
42
|
},
|
|
42
43
|
completionItemHover: {
|
|
43
|
-
backgroundColor: '#
|
|
44
|
+
backgroundColor: '#F3F4F6',
|
|
44
45
|
},
|
|
45
46
|
completionItemSelected: {
|
|
46
|
-
backgroundColor: '#
|
|
47
|
+
backgroundColor: '#E5E7EB',
|
|
47
48
|
},
|
|
48
49
|
completionItemIcon: {
|
|
49
|
-
color: '#
|
|
50
|
+
color: '#4B5563',
|
|
50
51
|
},
|
|
51
52
|
completionItemLabel: {
|
|
52
|
-
color: '#
|
|
53
|
+
color: '#1F2937',
|
|
53
54
|
},
|
|
54
55
|
completionItemInfo: {
|
|
55
|
-
color: '#
|
|
56
|
+
color: '#4B5563',
|
|
56
57
|
},
|
|
57
58
|
completionItemDetail: {
|
|
58
|
-
color: '#
|
|
59
|
+
color: '#6B7280',
|
|
59
60
|
},
|
|
60
61
|
},
|
|
61
62
|
styles: [
|
|
@@ -68,6 +69,11 @@ export const lightTheme: Extension = createTheme({
|
|
|
68
69
|
tag: [t.propertyName],
|
|
69
70
|
color: colors.key,
|
|
70
71
|
},
|
|
72
|
+
{
|
|
73
|
+
tag: [t.variableName],
|
|
74
|
+
color: colors.variable,
|
|
75
|
+
},
|
|
76
|
+
|
|
71
77
|
{
|
|
72
78
|
tag: [t.string],
|
|
73
79
|
color: colors.string,
|
|
@@ -92,28 +98,46 @@ export const lightTheme: Extension = createTheme({
|
|
|
92
98
|
// markdown
|
|
93
99
|
{
|
|
94
100
|
tag: [t.heading],
|
|
95
|
-
color: '#
|
|
101
|
+
color: '#2563EB',
|
|
96
102
|
},
|
|
97
103
|
{
|
|
98
104
|
tag: [t.processingInstruction],
|
|
99
|
-
color: '#
|
|
105
|
+
color: '#2563EB',
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
// js
|
|
109
|
+
{
|
|
110
|
+
tag: [t.definitionKeyword],
|
|
111
|
+
color: '#9333EA',
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
tag: [t.modifier],
|
|
115
|
+
color: '#9333EA',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
tag: [t.controlKeyword],
|
|
119
|
+
color: '#9333EA',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
tag: [t.operatorKeyword],
|
|
123
|
+
color: '#9333EA',
|
|
100
124
|
},
|
|
101
125
|
|
|
102
126
|
// shell
|
|
103
127
|
// curl
|
|
104
128
|
{
|
|
105
129
|
tag: [t.standard(t.variableName)],
|
|
106
|
-
color: '#
|
|
130
|
+
color: '#059669',
|
|
107
131
|
},
|
|
108
132
|
// -X
|
|
109
133
|
{
|
|
110
134
|
tag: [t.attributeName],
|
|
111
|
-
color: '#
|
|
135
|
+
color: '#EA580C',
|
|
112
136
|
},
|
|
113
137
|
// url in string (includes quotes), e.g. "https://..."
|
|
114
138
|
{
|
|
115
139
|
tag: [t.special(t.string)],
|
|
116
|
-
color: '#
|
|
140
|
+
color: '#2563EB',
|
|
117
141
|
},
|
|
118
142
|
],
|
|
119
143
|
});
|
|
@@ -7,11 +7,10 @@ import React from 'react';
|
|
|
7
7
|
|
|
8
8
|
import styled from 'styled-components';
|
|
9
9
|
|
|
10
|
-
import { CodeEditor, CodeEditorPropsType } from '
|
|
10
|
+
import { CodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
|
|
11
11
|
|
|
12
12
|
const UIMini = styled.div`
|
|
13
13
|
.ͼ1 .cm-content {
|
|
14
|
-
padding: 0;
|
|
15
14
|
}
|
|
16
15
|
`;
|
|
17
16
|
|
|
@@ -23,6 +22,7 @@ export function CodeEditorMini(props: CodeEditorPropsType) {
|
|
|
23
22
|
options={{
|
|
24
23
|
lineNumbersGutter: false,
|
|
25
24
|
foldGutter: false,
|
|
25
|
+
minHeight: 24,
|
|
26
26
|
...(props.options || {}),
|
|
27
27
|
}}
|
|
28
28
|
/>
|