@flowgram.ai/form-materials 0.1.0-alpha.15 → 0.1.0-alpha.17
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/run.sh +3 -2
- package/dist/cjs/components/blur-input/index.js +2 -12
- package/dist/cjs/components/code-editor/editor-all.js +52 -0
- package/dist/cjs/components/code-editor/editor-json.js +71 -0
- package/dist/cjs/components/code-editor/editor-python.js +63 -0
- package/dist/cjs/components/code-editor/editor-shell.js +63 -0
- package/dist/cjs/components/code-editor/editor-sql.js +71 -0
- package/dist/cjs/components/code-editor/editor-ts.js +80 -0
- package/dist/cjs/components/code-editor/editor.js +45 -57
- package/dist/cjs/components/code-editor/factory.js +96 -0
- package/dist/cjs/components/code-editor/index.js +31 -28
- package/dist/cjs/components/code-editor/theme/dark.js +120 -50
- package/dist/cjs/components/code-editor/theme/light.js +110 -61
- package/dist/cjs/components/code-editor/utils.js +1 -0
- package/dist/cjs/components/condition-context/context.js +59 -0
- package/dist/cjs/components/condition-context/hooks/use-condition.js +97 -0
- package/dist/cjs/components/condition-context/index.js +47 -0
- package/dist/cjs/components/condition-context/op.js +117 -0
- package/dist/cjs/components/condition-row/index.js +43 -26
- package/dist/cjs/components/condition-row/types.js +1 -35
- package/dist/cjs/components/{prompt-editor-with-inputs/inputs-picker.js → coze-editor-extensions/extensions/inputs-tree.js} +70 -2
- package/dist/cjs/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.js +4 -3
- package/dist/cjs/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.js +13 -7
- package/dist/cjs/components/coze-editor-extensions/index.js +86 -0
- package/dist/cjs/components/db-condition-row/index.js +59 -34
- package/dist/cjs/components/display-schema-tree/index.js +2 -2
- package/dist/cjs/components/index.js +49 -4
- package/dist/cjs/components/json-editor-with-variables/editor.js +10 -7
- package/dist/cjs/components/prompt-editor-with-inputs/editor.js +2 -2
- package/dist/cjs/components/prompt-editor-with-variables/editor.js +3 -4
- package/dist/cjs/components/{condition-row/hooks/useRule.js → sql-editor-with-variables/editor.js} +19 -34
- package/dist/cjs/components/sql-editor-with-variables/index.js +57 -0
- package/dist/cjs/components/type-selector/index.js +2 -2
- package/dist/cjs/components/variable-selector/use-variable-tree.js +1 -2
- package/dist/cjs/effects/provide-batch-input/index.js +1 -1
- package/dist/cjs/effects/provide-json-schema-outputs/index.js +1 -1
- package/dist/cjs/form-plugins/batch-outputs-plugin/index.js +9 -2
- package/dist/cjs/form-plugins/infer-assign-plugin/index.js +1 -1
- package/dist/cjs/form-plugins/infer-inputs-plugin/index.js +30 -3
- package/dist/cjs/index.js +44 -2
- package/dist/cjs/plugins/json-schema-preset/create-type-preset-plugin.js +1 -0
- package/dist/cjs/plugins/json-schema-preset/index.js +3 -13
- package/dist/cjs/{components/code-editor/init-worker.js → plugins/json-schema-preset/react.js} +18 -23
- package/dist/cjs/plugins/json-schema-preset/type-definition/array.js +33 -4
- package/dist/cjs/plugins/json-schema-preset/type-definition/boolean.js +23 -0
- package/dist/cjs/plugins/json-schema-preset/type-definition/date-time.js +31 -2
- package/dist/cjs/plugins/json-schema-preset/type-definition/index.js +9 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/integer.js +34 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/map.js +54 -0
- package/dist/cjs/plugins/json-schema-preset/type-definition/number.js +34 -1
- package/dist/cjs/plugins/json-schema-preset/type-definition/object.js +9 -4
- package/dist/cjs/plugins/json-schema-preset/type-definition/string.js +30 -1
- package/dist/cjs/plugins/json-schema-preset/types.js +18 -0
- package/dist/cjs/shared/flow-value/utils.js +22 -8
- package/dist/cjs/shared/inject-material/index.js +2 -1
- package/dist/esm/components/blur-input/index.mjs +2 -2
- package/dist/esm/components/code-editor/editor-all.mjs +18 -0
- package/dist/esm/components/code-editor/editor-json.mjs +16 -0
- package/dist/esm/components/code-editor/editor-python.mjs +8 -0
- package/dist/esm/components/code-editor/editor-shell.mjs +8 -0
- package/dist/esm/components/code-editor/editor-sql.mjs +16 -0
- package/dist/esm/components/code-editor/editor-ts.mjs +22 -0
- package/dist/esm/components/code-editor/editor.mjs +38 -33
- package/dist/esm/components/code-editor/factory.mjs +36 -0
- package/dist/esm/components/code-editor/index.mjs +8 -5
- package/dist/esm/components/code-editor/theme/dark.mjs +117 -50
- package/dist/esm/components/code-editor/theme/light.mjs +108 -62
- package/dist/esm/components/code-editor/utils.mjs +1 -0
- package/dist/esm/components/condition-context/context.mjs +19 -0
- package/dist/esm/components/condition-context/hooks/use-condition.mjs +63 -0
- package/dist/esm/components/condition-context/index.mjs +4 -0
- package/dist/esm/components/condition-context/op.mjs +80 -0
- package/dist/esm/components/condition-row/index.mjs +45 -28
- package/dist/esm/components/condition-row/types.mjs +0 -18
- package/dist/esm/components/coze-editor-extensions/extensions/inputs-tree.mjs +135 -0
- package/dist/esm/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.mjs +4 -3
- package/dist/esm/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.mjs +13 -7
- package/dist/esm/components/coze-editor-extensions/index.mjs +18 -0
- package/dist/esm/components/db-condition-row/index.mjs +59 -34
- package/dist/esm/components/display-schema-tree/index.mjs +1 -1
- package/dist/esm/components/index.mjs +5 -2
- package/dist/esm/components/json-editor-with-variables/editor.mjs +10 -7
- package/dist/esm/components/prompt-editor-with-inputs/editor.mjs +2 -2
- package/dist/esm/components/prompt-editor-with-variables/editor.mjs +3 -4
- package/dist/esm/components/sql-editor-with-variables/editor.mjs +19 -0
- package/dist/esm/components/sql-editor-with-variables/index.mjs +5 -0
- package/dist/esm/components/type-selector/index.mjs +1 -1
- package/dist/esm/components/variable-selector/use-variable-tree.mjs +1 -2
- package/dist/esm/effects/provide-batch-input/index.mjs +2 -2
- package/dist/esm/effects/provide-json-schema-outputs/index.mjs +2 -2
- package/dist/esm/form-plugins/batch-outputs-plugin/index.mjs +10 -3
- package/dist/esm/form-plugins/infer-assign-plugin/index.mjs +2 -2
- package/dist/esm/form-plugins/infer-inputs-plugin/index.mjs +31 -4
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/plugins/json-schema-preset/create-type-preset-plugin.mjs +2 -1
- package/dist/esm/plugins/json-schema-preset/index.mjs +3 -13
- package/dist/esm/plugins/json-schema-preset/react.mjs +14 -0
- package/dist/esm/plugins/json-schema-preset/type-definition/array.mjs +33 -4
- package/dist/esm/plugins/json-schema-preset/type-definition/boolean.mjs +23 -0
- package/dist/esm/plugins/json-schema-preset/type-definition/date-time.mjs +31 -2
- package/dist/esm/plugins/json-schema-preset/type-definition/index.mjs +7 -2
- package/dist/esm/plugins/json-schema-preset/type-definition/integer.mjs +34 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/map.mjs +20 -0
- package/dist/esm/plugins/json-schema-preset/type-definition/number.mjs +34 -1
- package/dist/esm/plugins/json-schema-preset/type-definition/object.mjs +9 -4
- package/dist/esm/plugins/json-schema-preset/type-definition/string.mjs +30 -1
- package/dist/esm/plugins/json-schema-preset/types.mjs +0 -0
- package/dist/esm/shared/flow-value/utils.mjs +22 -8
- package/dist/esm/shared/inject-material/index.mjs +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/components/blur-input/index.d.ts +7 -1
- package/dist/types/components/code-editor/editor-all.d.ts +8 -0
- package/dist/types/components/code-editor/editor-json.d.ts +6 -0
- package/dist/types/components/code-editor/editor-python.d.ts +6 -0
- package/dist/types/components/code-editor/editor-shell.d.ts +6 -0
- package/dist/types/components/code-editor/editor-sql.d.ts +6 -0
- package/dist/types/components/code-editor/editor-ts.d.ts +6 -0
- package/dist/types/components/code-editor/editor.d.ts +3 -4
- package/dist/types/components/code-editor/factory.d.ts +13 -0
- package/dist/types/components/code-editor/index.d.ts +7 -2
- package/dist/types/components/code-editor/theme/dark.d.ts +29 -0
- package/dist/types/components/code-editor/theme/light.d.ts +24 -0
- package/dist/types/components/code-editor/utils.d.ts +1 -1
- package/dist/types/components/code-editor-mini/index.d.ts +3 -0
- package/dist/types/components/condition-context/context.d.ts +14 -0
- package/dist/types/components/condition-context/hooks/use-condition.d.ts +29 -0
- package/dist/types/components/condition-context/index.d.ts +8 -0
- package/dist/types/components/condition-context/op.d.ts +22 -0
- package/dist/types/components/condition-context/types.d.ts +14 -0
- package/dist/types/components/condition-row/index.d.ts +4 -7
- package/dist/types/components/condition-row/types.d.ts +0 -24
- package/dist/types/components/{prompt-editor-with-inputs/inputs-picker.d.ts → coze-editor-extensions/extensions/inputs-tree.d.ts} +5 -0
- package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.d.ts +3 -1
- package/dist/types/components/coze-editor-extensions/index.d.ts +18 -0
- package/dist/types/components/db-condition-row/index.d.ts +4 -3
- package/dist/types/components/db-condition-row/types.d.ts +0 -8
- package/dist/types/components/display-schema-tree/index.d.ts +1 -1
- package/dist/types/components/dynamic-value-input/index.d.ts +3 -1
- package/dist/types/components/index.d.ts +4 -1
- package/dist/types/components/sql-editor-with-variables/editor.d.ts +9 -0
- package/dist/types/components/sql-editor-with-variables/index.d.ts +6 -0
- package/dist/types/components/type-selector/index.d.ts +3 -1
- package/dist/types/components/variable-selector/index.d.ts +4 -2
- package/dist/types/form-plugins/batch-outputs-plugin/index.d.ts +4 -0
- package/dist/types/form-plugins/infer-inputs-plugin/index.d.ts +4 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/index.d.ts +3 -7
- package/dist/types/plugins/json-schema-preset/react.d.ts +11 -0
- package/dist/types/plugins/json-schema-preset/type-definition/array.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/boolean.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/date-time.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/index.d.ts +3 -1
- package/dist/types/plugins/json-schema-preset/type-definition/integer.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/map.d.ts +6 -0
- package/dist/types/plugins/json-schema-preset/type-definition/number.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/object.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/type-definition/string.d.ts +1 -1
- package/dist/types/plugins/json-schema-preset/{manager.d.ts → types.d.ts} +5 -0
- package/dist/types/shared/flow-value/utils.d.ts +3 -1
- package/dist/types/shared/inject-material/index.d.ts +6 -4
- package/dist/types/validate/validate-flow-value/index.d.ts +1 -1
- package/package.json +56 -17
- package/src/components/blur-input/index.tsx +9 -1
- package/src/components/code-editor/editor-all.tsx +30 -0
- package/src/components/code-editor/editor-json.tsx +25 -0
- package/src/components/code-editor/editor-python.tsx +18 -0
- package/src/components/code-editor/editor-shell.tsx +18 -0
- package/src/components/code-editor/editor-sql.tsx +24 -0
- package/src/components/code-editor/editor-ts.tsx +31 -0
- package/src/components/code-editor/editor.tsx +45 -36
- package/src/components/code-editor/factory.tsx +61 -0
- package/src/components/code-editor/index.tsx +7 -7
- package/src/components/code-editor/theme/dark.ts +62 -77
- package/src/components/code-editor/theme/light.ts +60 -91
- package/src/components/code-editor/utils.ts +4 -0
- package/src/components/code-editor-mini/index.tsx +3 -0
- package/src/components/condition-context/context.tsx +28 -0
- package/src/components/condition-context/hooks/use-condition.tsx +99 -0
- package/src/components/condition-context/index.tsx +14 -0
- package/src/components/condition-context/op.ts +86 -0
- package/src/components/condition-context/types.ts +22 -0
- package/src/components/condition-row/index.tsx +44 -22
- package/src/components/condition-row/types.ts +0 -30
- package/src/components/{prompt-editor-with-inputs/inputs-picker.tsx → coze-editor-extensions/extensions/inputs-tree.tsx} +95 -5
- package/src/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.tsx +6 -3
- package/src/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.tsx +12 -3
- package/src/components/coze-editor-extensions/index.tsx +33 -0
- package/src/components/db-condition-row/index.tsx +76 -24
- package/src/components/db-condition-row/types.ts +0 -13
- package/src/components/display-schema-tree/index.tsx +6 -4
- package/src/components/index.ts +29 -1
- package/src/components/json-editor-with-variables/editor.tsx +7 -8
- package/src/components/prompt-editor-with-inputs/editor.tsx +2 -3
- package/src/components/prompt-editor-with-variables/editor.tsx +3 -5
- package/src/components/sql-editor-with-variables/editor.tsx +28 -0
- package/src/components/sql-editor-with-variables/index.tsx +12 -0
- package/src/components/type-selector/index.tsx +2 -3
- package/src/components/variable-selector/index.tsx +2 -2
- package/src/components/variable-selector/use-variable-tree.tsx +7 -4
- package/src/effects/provide-batch-input/index.ts +1 -2
- package/src/effects/provide-json-schema-outputs/index.ts +1 -2
- package/src/form-plugins/batch-outputs-plugin/index.ts +64 -46
- package/src/form-plugins/infer-assign-plugin/index.ts +1 -2
- package/src/form-plugins/infer-inputs-plugin/index.ts +62 -14
- package/src/index.ts +19 -0
- package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +4 -2
- package/src/plugins/json-schema-preset/index.tsx +4 -20
- package/src/plugins/json-schema-preset/react.tsx +31 -0
- package/src/plugins/json-schema-preset/type-definition/array.tsx +13 -4
- package/src/plugins/json-schema-preset/type-definition/boolean.tsx +17 -1
- package/src/plugins/json-schema-preset/type-definition/date-time.tsx +21 -2
- package/src/plugins/json-schema-preset/type-definition/index.tsx +10 -1
- package/src/plugins/json-schema-preset/type-definition/integer.tsx +19 -1
- package/src/plugins/json-schema-preset/type-definition/map.tsx +31 -0
- package/src/plugins/json-schema-preset/type-definition/number.tsx +19 -1
- package/src/plugins/json-schema-preset/type-definition/object.tsx +9 -4
- package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -1
- package/src/plugins/json-schema-preset/{manager.ts → types.ts} +7 -0
- package/src/shared/flow-value/utils.ts +22 -9
- package/src/shared/inject-material/index.tsx +10 -6
- package/src/validate/validate-flow-value/index.tsx +1 -2
- package/dist/cjs/components/code-editor/language-features.js +0 -21
- package/dist/cjs/components/condition-row/constants.js +0 -165
- package/dist/cjs/components/condition-row/hooks/useOp.js +0 -78
- package/dist/cjs/components/db-condition-row/hooks/use-left.js +0 -86
- package/dist/cjs/components/db-condition-row/hooks/use-op.js +0 -79
- package/dist/cjs/components/json-editor-with-variables/extensions/variable-tag.js +0 -151
- package/dist/cjs/components/json-editor-with-variables/extensions/variable-tree.js +0 -97
- package/dist/cjs/components/prompt-editor-with-inputs/extensions/inputs-tree.js +0 -101
- package/dist/cjs/components/prompt-editor-with-variables/styles.js +0 -89
- package/dist/esm/components/code-editor/init-worker.mjs +0 -19
- package/dist/esm/components/code-editor/language-features.mjs +0 -15
- package/dist/esm/components/condition-row/constants.mjs +0 -128
- package/dist/esm/components/condition-row/hooks/useOp.mjs +0 -44
- package/dist/esm/components/condition-row/hooks/useRule.mjs +0 -34
- package/dist/esm/components/db-condition-row/hooks/use-left.mjs +0 -52
- package/dist/esm/components/db-condition-row/hooks/use-op.mjs +0 -45
- package/dist/esm/components/json-editor-with-variables/extensions/variable-tree.mjs +0 -63
- package/dist/esm/components/prompt-editor-with-inputs/extensions/inputs-tree.mjs +0 -67
- package/dist/esm/components/prompt-editor-with-inputs/inputs-picker.mjs +0 -70
- package/dist/esm/components/prompt-editor-with-variables/extensions/variable-tag.mjs +0 -117
- package/dist/esm/components/prompt-editor-with-variables/styles.mjs +0 -36
- package/dist/types/components/code-editor/init-worker.d.ts +0 -5
- package/dist/types/components/code-editor/language-features.d.ts +0 -5
- package/dist/types/components/condition-row/constants.d.ts +0 -7
- package/dist/types/components/condition-row/hooks/useOp.d.ts +0 -18
- package/dist/types/components/condition-row/hooks/useRule.d.ts +0 -9
- package/dist/types/components/db-condition-row/hooks/use-left.d.ts +0 -18
- package/dist/types/components/db-condition-row/hooks/use-op.d.ts +0 -18
- package/dist/types/components/prompt-editor-with-inputs/extensions/inputs-tree.d.ts +0 -9
- package/dist/types/components/prompt-editor-with-variables/extensions/variable-tag.d.ts +0 -5
- package/dist/types/components/prompt-editor-with-variables/extensions/variable-tree.d.ts +0 -6
- package/dist/types/components/prompt-editor-with-variables/styles.d.ts +0 -9
- package/src/components/code-editor/init-worker.ts +0 -27
- package/src/components/code-editor/language-features.ts +0 -23
- package/src/components/condition-row/constants.ts +0 -134
- package/src/components/condition-row/hooks/useOp.tsx +0 -56
- package/src/components/condition-row/hooks/useRule.ts +0 -35
- package/src/components/db-condition-row/hooks/use-left.tsx +0 -66
- package/src/components/db-condition-row/hooks/use-op.tsx +0 -59
- package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +0 -174
- package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +0 -83
- package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +0 -94
- package/src/components/prompt-editor-with-variables/styles.tsx +0 -44
- /package/dist/cjs/{plugins/json-schema-preset/manager.js → components/condition-context/types.js} +0 -0
- /package/dist/cjs/components/{json-editor-with-variables → coze-editor-extensions}/styles.js +0 -0
- /package/dist/esm/{plugins/json-schema-preset/manager.mjs → components/condition-context/types.mjs} +0 -0
- /package/dist/esm/components/{json-editor-with-variables → coze-editor-extensions}/styles.mjs +0 -0
- /package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.d.ts +0 -0
- /package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/styles.d.ts +0 -0
- /package/src/components/{json-editor-with-variables → coze-editor-extensions}/styles.tsx +0 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { CodeEditorFactory } from './factory';
|
|
7
|
+
import { loadTypescriptLanguage } from './editor-ts';
|
|
8
|
+
import { loadSqlLanguage } from './editor-sql';
|
|
9
|
+
import { loadShellLanguage } from './editor-shell';
|
|
10
|
+
import { loadPythonLanguage } from './editor-python';
|
|
11
|
+
import { loadJsonLanguage } from './editor-json';
|
|
12
|
+
|
|
13
|
+
const languageLoaders: Record<string, (languageId: string) => Promise<any>> = {
|
|
14
|
+
json: loadJsonLanguage,
|
|
15
|
+
python: loadPythonLanguage,
|
|
16
|
+
sql: loadSqlLanguage,
|
|
17
|
+
typescript: loadTypescriptLanguage,
|
|
18
|
+
shell: loadShellLanguage,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated CodeEditor will bundle all languages features, use XXXCodeEditor instead for better bundle experience
|
|
23
|
+
*/
|
|
24
|
+
export const CodeEditor = CodeEditorFactory<false>(
|
|
25
|
+
(languageId) => languageLoaders[languageId]?.(languageId),
|
|
26
|
+
{
|
|
27
|
+
displayName: 'CodeEditor',
|
|
28
|
+
fixLanguageId: undefined,
|
|
29
|
+
}
|
|
30
|
+
);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { languages } from '@flowgram.ai/coze-editor/preset-code';
|
|
7
|
+
import { mixLanguages } from '@flowgram.ai/coze-editor';
|
|
8
|
+
|
|
9
|
+
import { CodeEditorFactory } from './factory';
|
|
10
|
+
|
|
11
|
+
export const loadJsonLanguage = () =>
|
|
12
|
+
import('@flowgram.ai/coze-editor/language-json').then((module) => {
|
|
13
|
+
languages.register('json', {
|
|
14
|
+
// mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
|
|
15
|
+
language: mixLanguages({
|
|
16
|
+
outerLanguage: module.json.language,
|
|
17
|
+
}),
|
|
18
|
+
languageService: module.json.languageService,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const JsonCodeEditor = CodeEditorFactory<true>(loadJsonLanguage, {
|
|
23
|
+
displayName: 'JsonCodeEditor',
|
|
24
|
+
fixLanguageId: 'json',
|
|
25
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { languages } from '@flowgram.ai/coze-editor/preset-code';
|
|
7
|
+
|
|
8
|
+
import { CodeEditorFactory } from './factory';
|
|
9
|
+
|
|
10
|
+
export const loadPythonLanguage = () =>
|
|
11
|
+
import('@flowgram.ai/coze-editor/language-python').then((module) =>
|
|
12
|
+
languages.register('python', module.python)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const PythonCodeEditor = CodeEditorFactory<true>(loadPythonLanguage, {
|
|
16
|
+
displayName: 'PythonCodeEditor',
|
|
17
|
+
fixLanguageId: 'python',
|
|
18
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { languages } from '@flowgram.ai/coze-editor/preset-code';
|
|
7
|
+
|
|
8
|
+
import { CodeEditorFactory } from './factory';
|
|
9
|
+
|
|
10
|
+
export const loadShellLanguage = () =>
|
|
11
|
+
import('@flowgram.ai/coze-editor/language-shell').then((module) =>
|
|
12
|
+
languages.register('shell', module.shell)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export const ShellCodeEditor = CodeEditorFactory<true>(loadShellLanguage, {
|
|
16
|
+
displayName: 'ShellCodeEditor',
|
|
17
|
+
fixLanguageId: 'shell',
|
|
18
|
+
});
|
|
@@ -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 '@flowgram.ai/coze-editor/preset-code';
|
|
7
|
+
import { mixLanguages } from '@flowgram.ai/coze-editor';
|
|
8
|
+
|
|
9
|
+
import { CodeEditorFactory } from './factory';
|
|
10
|
+
|
|
11
|
+
export const loadSqlLanguage = () =>
|
|
12
|
+
import('@flowgram.ai/coze-editor/language-sql').then((module) => {
|
|
13
|
+
languages.register('sql', {
|
|
14
|
+
...module.sql,
|
|
15
|
+
language: mixLanguages({
|
|
16
|
+
outerLanguage: module.sql.language,
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const SQLCodeEditor = CodeEditorFactory<true>(loadSqlLanguage, {
|
|
22
|
+
displayName: 'SQLCodeEditor',
|
|
23
|
+
fixLanguageId: 'sql',
|
|
24
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { languages } from '@flowgram.ai/coze-editor/preset-code';
|
|
7
|
+
|
|
8
|
+
import { CodeEditorFactory } from './factory';
|
|
9
|
+
|
|
10
|
+
export const loadTypescriptLanguage = () =>
|
|
11
|
+
import('@flowgram.ai/coze-editor/language-typescript').then((module) => {
|
|
12
|
+
languages.register('typescript', module.typescript);
|
|
13
|
+
|
|
14
|
+
// Init TypeScript language service
|
|
15
|
+
const tsWorker = new Worker(
|
|
16
|
+
new URL(`@flowgram.ai/coze-editor/language-typescript/worker`, import.meta.url),
|
|
17
|
+
{ type: 'module' }
|
|
18
|
+
);
|
|
19
|
+
module.typescript.languageService.initialize(tsWorker, {
|
|
20
|
+
compilerOptions: {
|
|
21
|
+
// eliminate Promise error
|
|
22
|
+
lib: ['es2015', 'dom'],
|
|
23
|
+
noImplicitAny: false,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export const TypeScriptCodeEditor = CodeEditorFactory<true>(loadTypescriptLanguage, {
|
|
29
|
+
displayName: 'TypeScriptCodeEditor',
|
|
30
|
+
fixLanguageId: 'typescript',
|
|
31
|
+
});
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import React, { useEffect, useRef } from 'react';
|
|
7
7
|
|
|
8
|
+
import styled, { css } from 'styled-components';
|
|
8
9
|
import {
|
|
9
10
|
ActiveLinePlaceholder,
|
|
10
11
|
createRenderer,
|
|
@@ -16,9 +17,6 @@ import { EditorView } from '@codemirror/view';
|
|
|
16
17
|
|
|
17
18
|
import { getSuffixByLanguageId } from './utils';
|
|
18
19
|
|
|
19
|
-
import './theme';
|
|
20
|
-
import './language-features';
|
|
21
|
-
|
|
22
20
|
const OriginCodeEditor = createRenderer(preset, [
|
|
23
21
|
EditorView.theme({
|
|
24
22
|
'&.cm-focused': {
|
|
@@ -27,21 +25,30 @@ const OriginCodeEditor = createRenderer(preset, [
|
|
|
27
25
|
}),
|
|
28
26
|
]);
|
|
29
27
|
|
|
28
|
+
const UIContainer = styled.div<{ $mini?: boolean }>`
|
|
29
|
+
${({ $mini }) =>
|
|
30
|
+
$mini &&
|
|
31
|
+
css`
|
|
32
|
+
height: 24px;
|
|
33
|
+
`}
|
|
34
|
+
`;
|
|
35
|
+
|
|
30
36
|
type Preset = typeof preset;
|
|
31
37
|
type Options = Partial<InferValues<Preset[number]>>;
|
|
32
38
|
|
|
33
39
|
export interface CodeEditorPropsType extends React.PropsWithChildren<{}> {
|
|
34
40
|
value?: string;
|
|
35
41
|
onChange?: (value: string) => void;
|
|
36
|
-
languageId: 'python' | 'typescript' | 'shell' | 'json';
|
|
42
|
+
languageId: 'python' | 'typescript' | 'shell' | 'json' | 'sql';
|
|
37
43
|
theme?: 'dark' | 'light';
|
|
38
44
|
placeholder?: string;
|
|
39
45
|
activeLinePlaceholder?: string;
|
|
40
46
|
readonly?: boolean;
|
|
41
47
|
options?: Options;
|
|
48
|
+
mini?: boolean;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
export function
|
|
51
|
+
export function BaseCodeEditor({
|
|
45
52
|
value,
|
|
46
53
|
onChange,
|
|
47
54
|
languageId = 'python',
|
|
@@ -51,6 +58,7 @@ export function CodeEditor({
|
|
|
51
58
|
activeLinePlaceholder,
|
|
52
59
|
options,
|
|
53
60
|
readonly,
|
|
61
|
+
mini,
|
|
54
62
|
}: CodeEditorPropsType) {
|
|
55
63
|
const editorRef = useRef<EditorAPI | null>(null);
|
|
56
64
|
|
|
@@ -61,37 +69,38 @@ export function CodeEditor({
|
|
|
61
69
|
}
|
|
62
70
|
}, [value]);
|
|
63
71
|
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
if (languageId === 'typescript') {
|
|
66
|
-
import('./init-worker').then((module) => {
|
|
67
|
-
module.initTsWorker();
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}, [languageId]);
|
|
71
|
-
|
|
72
72
|
return (
|
|
73
|
-
<
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
<UIContainer $mini={mini}>
|
|
74
|
+
<EditorProvider>
|
|
75
|
+
<OriginCodeEditor
|
|
76
|
+
defaultValue={String(value || '')}
|
|
77
|
+
options={{
|
|
78
|
+
uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
|
|
79
|
+
languageId,
|
|
80
|
+
theme,
|
|
81
|
+
placeholder,
|
|
82
|
+
readOnly: readonly,
|
|
83
|
+
editable: !readonly,
|
|
84
|
+
...(mini
|
|
85
|
+
? {
|
|
86
|
+
lineNumbersGutter: false,
|
|
87
|
+
foldGutter: false,
|
|
88
|
+
minHeight: 24,
|
|
89
|
+
}
|
|
90
|
+
: {}),
|
|
91
|
+
...(options || {}),
|
|
92
|
+
}}
|
|
93
|
+
didMount={(editor: EditorAPI) => {
|
|
94
|
+
editorRef.current = editor;
|
|
95
|
+
}}
|
|
96
|
+
onChange={(e) => onChange?.(e.value)}
|
|
97
|
+
>
|
|
98
|
+
{activeLinePlaceholder && (
|
|
99
|
+
<ActiveLinePlaceholder>{activeLinePlaceholder}</ActiveLinePlaceholder>
|
|
100
|
+
)}
|
|
101
|
+
{children}
|
|
102
|
+
</OriginCodeEditor>
|
|
103
|
+
</EditorProvider>
|
|
104
|
+
</UIContainer>
|
|
96
105
|
);
|
|
97
106
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { languages } from '@flowgram.ai/coze-editor/preset-code';
|
|
10
|
+
import { Skeleton } from '@douyinfe/semi-ui';
|
|
11
|
+
|
|
12
|
+
import { lazySuspense } from '@/shared';
|
|
13
|
+
|
|
14
|
+
import type { CodeEditorPropsType } from './editor';
|
|
15
|
+
|
|
16
|
+
export const BaseCodeEditor = lazySuspense(() =>
|
|
17
|
+
Promise.all([import('./editor'), import('./theme')]).then(([editorModule]) => ({
|
|
18
|
+
default: editorModule.BaseCodeEditor,
|
|
19
|
+
}))
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
interface FactoryParams<FixLanguageId extends boolean> {
|
|
23
|
+
displayName: string;
|
|
24
|
+
fixLanguageId: FixLanguageId extends true ? CodeEditorPropsType['languageId'] : undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const CodeEditorFactory = <FixLanguageId extends boolean>(
|
|
28
|
+
loadLanguage: (languageId: string) => Promise<any>,
|
|
29
|
+
{ displayName, fixLanguageId }: FactoryParams<FixLanguageId>
|
|
30
|
+
): FixLanguageId extends true
|
|
31
|
+
? React.FC<Omit<CodeEditorPropsType, 'languageId'>>
|
|
32
|
+
: React.FC<CodeEditorPropsType> => {
|
|
33
|
+
const EditorWithLoad = (props: CodeEditorPropsType) => {
|
|
34
|
+
const { languageId = fixLanguageId } = props;
|
|
35
|
+
|
|
36
|
+
if (!languageId) {
|
|
37
|
+
throw new Error('CodeEditorFactory: languageId is required');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const [loaded, setLoaded] = useState(useMemo(() => !!languages.get(languageId), [languageId]));
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (!loaded && loadLanguage) {
|
|
44
|
+
loadLanguage(languageId).then(() => {
|
|
45
|
+
setLoaded(true);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}, [languageId, loaded]);
|
|
49
|
+
|
|
50
|
+
if (!loaded) {
|
|
51
|
+
return <Skeleton />;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return <BaseCodeEditor {...props} languageId={fixLanguageId || languageId} />;
|
|
55
|
+
};
|
|
56
|
+
EditorWithLoad.displayName = displayName;
|
|
57
|
+
|
|
58
|
+
return EditorWithLoad as FixLanguageId extends true
|
|
59
|
+
? React.FC<Omit<CodeEditorPropsType, 'languageId'>>
|
|
60
|
+
: React.FC<CodeEditorPropsType>;
|
|
61
|
+
};
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* SPDX-License-Identifier: MIT
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export type
|
|
6
|
+
export { CodeEditor } from './editor-all';
|
|
7
|
+
export { TypeScriptCodeEditor } from './editor-ts';
|
|
8
|
+
export { ShellCodeEditor } from './editor-shell';
|
|
9
|
+
export { JsonCodeEditor } from './editor-json';
|
|
10
|
+
export { SQLCodeEditor } from './editor-sql';
|
|
11
|
+
export { PythonCodeEditor } from './editor-python';
|
|
12
|
+
export { BaseCodeEditor, type CodeEditorPropsType } from './editor';
|
|
@@ -6,28 +6,45 @@
|
|
|
6
6
|
import { createTheme, tags as t } from '@flowgram.ai/coze-editor/preset-code';
|
|
7
7
|
import { type Extension } from '@codemirror/state';
|
|
8
8
|
|
|
9
|
-
const colors = {
|
|
10
|
-
background: '#
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
export const colors = {
|
|
10
|
+
background: '#24292e',
|
|
11
|
+
foreground: '#d1d5da',
|
|
12
|
+
selection: '#3392FF44',
|
|
13
|
+
cursor: '#c8e1ff',
|
|
14
|
+
dropdownBackground: '#24292e',
|
|
15
|
+
dropdownBorder: '#1b1f23',
|
|
16
|
+
activeLine: '#4d566022',
|
|
17
|
+
matchingBracket: '#888892',
|
|
18
|
+
keyword: '#9197F1',
|
|
19
|
+
storage: '#f97583',
|
|
20
|
+
variable: '#ffab70',
|
|
21
|
+
variableName: '#D9DCFA',
|
|
22
|
+
parameter: '#e1e4e8',
|
|
23
|
+
function: '#FFCA66',
|
|
24
|
+
string: '#FF9878',
|
|
25
|
+
constant: '#79b8ff',
|
|
26
|
+
type: '#79b8ff',
|
|
27
|
+
class: '#b392f0',
|
|
28
|
+
number: '#2EC7D9',
|
|
29
|
+
comment: '#568B2A',
|
|
30
|
+
heading: '#79b8ff',
|
|
31
|
+
invalid: '#f97583',
|
|
32
|
+
regexp: '#9ecbff',
|
|
33
|
+
propertyName: '#9197F1',
|
|
34
|
+
separator: '#888892',
|
|
35
|
+
gutters: '#888892',
|
|
36
|
+
moduleKeyword: '#CC4FD4',
|
|
20
37
|
};
|
|
21
38
|
|
|
22
39
|
export const darkTheme: Extension = createTheme({
|
|
23
40
|
variant: 'dark',
|
|
24
41
|
settings: {
|
|
25
42
|
background: colors.background,
|
|
26
|
-
foreground:
|
|
27
|
-
caret:
|
|
28
|
-
selection:
|
|
43
|
+
foreground: colors.foreground,
|
|
44
|
+
caret: colors.cursor,
|
|
45
|
+
selection: colors.selection,
|
|
29
46
|
gutterBackground: colors.background,
|
|
30
|
-
gutterForeground:
|
|
47
|
+
gutterForeground: colors.foreground,
|
|
31
48
|
gutterBorderColor: 'transparent',
|
|
32
49
|
gutterBorderWidth: 0,
|
|
33
50
|
lineHighlight: '#21262D',
|
|
@@ -44,7 +61,8 @@ export const darkTheme: Extension = createTheme({
|
|
|
44
61
|
backgroundColor: '#21262D',
|
|
45
62
|
},
|
|
46
63
|
completionItemSelected: {
|
|
47
|
-
backgroundColor:
|
|
64
|
+
backgroundColor: colors.selection,
|
|
65
|
+
color: colors.foreground,
|
|
48
66
|
},
|
|
49
67
|
completionItemIcon: {
|
|
50
68
|
color: '#8B949E',
|
|
@@ -60,79 +78,46 @@ export const darkTheme: Extension = createTheme({
|
|
|
60
78
|
},
|
|
61
79
|
},
|
|
62
80
|
styles: [
|
|
63
|
-
|
|
81
|
+
{ tag: t.keyword, color: colors.keyword },
|
|
82
|
+
{ tag: t.variableName, color: colors.variableName },
|
|
64
83
|
{
|
|
65
|
-
tag: t.
|
|
66
|
-
color: colors.
|
|
84
|
+
tag: [t.name, t.deleted, t.character, t.macroName],
|
|
85
|
+
color: colors.variable,
|
|
67
86
|
},
|
|
87
|
+
{ tag: [t.propertyName], color: colors.propertyName },
|
|
68
88
|
{
|
|
69
|
-
tag: [t.
|
|
70
|
-
color: colors.key,
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
tag: [t.string],
|
|
89
|
+
tag: [t.processingInstruction, t.string, t.inserted, t.special(t.string)],
|
|
74
90
|
color: colors.string,
|
|
75
91
|
},
|
|
76
92
|
{
|
|
77
|
-
tag: [t.
|
|
78
|
-
color: colors.
|
|
93
|
+
tag: [t.function(t.variableName), t.function(t.propertyName), t.labelName],
|
|
94
|
+
color: colors.function,
|
|
79
95
|
},
|
|
80
96
|
{
|
|
81
|
-
tag: [t.
|
|
82
|
-
color: colors.
|
|
97
|
+
tag: [t.moduleKeyword, t.controlKeyword],
|
|
98
|
+
color: colors.moduleKeyword,
|
|
83
99
|
},
|
|
84
100
|
{
|
|
85
|
-
tag: [t.
|
|
86
|
-
color: colors.
|
|
101
|
+
tag: [t.color, t.constant(t.name), t.standard(t.name)],
|
|
102
|
+
color: colors.constant,
|
|
87
103
|
},
|
|
104
|
+
{ tag: t.definition(t.name), color: colors.variable },
|
|
105
|
+
{ tag: [t.className], color: colors.class },
|
|
88
106
|
{
|
|
89
|
-
tag: [t.
|
|
90
|
-
color: colors.
|
|
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
|
-
|
|
111
|
-
// markdown
|
|
112
|
-
{
|
|
113
|
-
tag: [t.heading],
|
|
114
|
-
color: '#7DD3FC',
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
tag: [t.processingInstruction],
|
|
118
|
-
color: '#7DD3FC',
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
// shell
|
|
122
|
-
// curl
|
|
123
|
-
{
|
|
124
|
-
tag: [t.standard(t.variableName)],
|
|
125
|
-
color: '#34D399',
|
|
126
|
-
},
|
|
127
|
-
// -X
|
|
128
|
-
{
|
|
129
|
-
tag: [t.attributeName],
|
|
130
|
-
color: '#FBBF24',
|
|
131
|
-
},
|
|
132
|
-
// url in string (includes quotes), e.g. "https://..."
|
|
133
|
-
{
|
|
134
|
-
tag: [t.special(t.string)],
|
|
135
|
-
color: '#7DD3FC',
|
|
107
|
+
tag: [t.number, t.changed, t.annotation, t.modifier, t.self, t.namespace],
|
|
108
|
+
color: colors.number,
|
|
136
109
|
},
|
|
110
|
+
{ tag: [t.typeName], color: colors.type, fontStyle: colors.type },
|
|
111
|
+
{ tag: [t.operatorKeyword], color: colors.keyword },
|
|
112
|
+
{ tag: [t.url, t.escape, t.regexp, t.link], color: colors.regexp },
|
|
113
|
+
{ tag: [t.meta, t.comment], color: colors.comment },
|
|
114
|
+
{ tag: t.strong, fontWeight: 'bold' },
|
|
115
|
+
{ tag: t.emphasis, fontStyle: 'italic' },
|
|
116
|
+
{ tag: t.link, textDecoration: 'underline' },
|
|
117
|
+
{ tag: t.heading, fontWeight: 'bold', color: colors.heading },
|
|
118
|
+
{ tag: [t.atom, t.bool, t.special(t.variableName)], color: colors.variable },
|
|
119
|
+
{ tag: t.invalid, color: colors.invalid },
|
|
120
|
+
{ tag: t.strikethrough, textDecoration: 'line-through' },
|
|
121
|
+
{ tag: t.separator, color: colors.separator },
|
|
137
122
|
],
|
|
138
123
|
});
|