@flowgram.ai/form-materials 0.1.0-alpha.15 → 0.1.0-alpha.16
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
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { IRules, Op, OpConfigs } from './types';
|
|
7
|
-
|
|
8
|
-
export const defaultRules: IRules = {
|
|
9
|
-
string: {
|
|
10
|
-
[Op.EQ]: 'string',
|
|
11
|
-
[Op.NEQ]: 'string',
|
|
12
|
-
[Op.CONTAINS]: 'string',
|
|
13
|
-
[Op.NOT_CONTAINS]: 'string',
|
|
14
|
-
[Op.IN]: 'array',
|
|
15
|
-
[Op.NIN]: 'array',
|
|
16
|
-
[Op.IS_EMPTY]: null,
|
|
17
|
-
[Op.IS_NOT_EMPTY]: null,
|
|
18
|
-
},
|
|
19
|
-
number: {
|
|
20
|
-
[Op.EQ]: 'number',
|
|
21
|
-
[Op.NEQ]: 'number',
|
|
22
|
-
[Op.GT]: 'number',
|
|
23
|
-
[Op.GTE]: 'number',
|
|
24
|
-
[Op.LT]: 'number',
|
|
25
|
-
[Op.LTE]: 'number',
|
|
26
|
-
[Op.IN]: 'array',
|
|
27
|
-
[Op.NIN]: 'array',
|
|
28
|
-
},
|
|
29
|
-
integer: {
|
|
30
|
-
[Op.EQ]: 'number',
|
|
31
|
-
[Op.NEQ]: 'number',
|
|
32
|
-
[Op.GT]: 'number',
|
|
33
|
-
[Op.GTE]: 'number',
|
|
34
|
-
[Op.LT]: 'number',
|
|
35
|
-
[Op.LTE]: 'number',
|
|
36
|
-
[Op.IN]: 'array',
|
|
37
|
-
[Op.NIN]: 'array',
|
|
38
|
-
},
|
|
39
|
-
boolean: {
|
|
40
|
-
[Op.EQ]: 'boolean',
|
|
41
|
-
[Op.NEQ]: 'boolean',
|
|
42
|
-
[Op.IS_TRUE]: null,
|
|
43
|
-
[Op.IS_FALSE]: null,
|
|
44
|
-
[Op.IN]: 'array',
|
|
45
|
-
[Op.NIN]: 'array',
|
|
46
|
-
},
|
|
47
|
-
object: {
|
|
48
|
-
[Op.IS_EMPTY]: null,
|
|
49
|
-
[Op.IS_NOT_EMPTY]: null,
|
|
50
|
-
},
|
|
51
|
-
array: {
|
|
52
|
-
[Op.IS_EMPTY]: null,
|
|
53
|
-
[Op.IS_NOT_EMPTY]: null,
|
|
54
|
-
[Op.CONTAINS]: 'array',
|
|
55
|
-
[Op.NOT_CONTAINS]: 'array',
|
|
56
|
-
[Op.EQ]: 'array',
|
|
57
|
-
[Op.NEQ]: 'array',
|
|
58
|
-
},
|
|
59
|
-
map: {
|
|
60
|
-
[Op.IS_EMPTY]: null,
|
|
61
|
-
[Op.IS_NOT_EMPTY]: null,
|
|
62
|
-
},
|
|
63
|
-
['date-time']: {
|
|
64
|
-
[Op.EQ]: 'date-time',
|
|
65
|
-
[Op.NEQ]: 'date-time',
|
|
66
|
-
[Op.GT]: 'date-time',
|
|
67
|
-
[Op.GTE]: 'date-time',
|
|
68
|
-
[Op.LT]: 'date-time',
|
|
69
|
-
[Op.LTE]: 'date-time',
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const defaultOpConfigs: OpConfigs = {
|
|
74
|
-
[Op.EQ]: {
|
|
75
|
-
label: 'Equal',
|
|
76
|
-
abbreviation: '=',
|
|
77
|
-
},
|
|
78
|
-
[Op.NEQ]: {
|
|
79
|
-
label: 'Not Equal',
|
|
80
|
-
abbreviation: '≠',
|
|
81
|
-
},
|
|
82
|
-
[Op.GT]: {
|
|
83
|
-
label: 'Greater Than',
|
|
84
|
-
abbreviation: '>',
|
|
85
|
-
},
|
|
86
|
-
[Op.GTE]: {
|
|
87
|
-
label: 'Greater Than or Equal',
|
|
88
|
-
abbreviation: '>=',
|
|
89
|
-
},
|
|
90
|
-
[Op.LT]: {
|
|
91
|
-
label: 'Less Than',
|
|
92
|
-
abbreviation: '<',
|
|
93
|
-
},
|
|
94
|
-
[Op.LTE]: {
|
|
95
|
-
label: 'Less Than or Equal',
|
|
96
|
-
abbreviation: '<=',
|
|
97
|
-
},
|
|
98
|
-
[Op.IN]: {
|
|
99
|
-
label: 'In',
|
|
100
|
-
abbreviation: '∈',
|
|
101
|
-
},
|
|
102
|
-
[Op.NIN]: {
|
|
103
|
-
label: 'Not In',
|
|
104
|
-
abbreviation: '∉',
|
|
105
|
-
},
|
|
106
|
-
[Op.CONTAINS]: {
|
|
107
|
-
label: 'Contains',
|
|
108
|
-
abbreviation: '⊇',
|
|
109
|
-
},
|
|
110
|
-
[Op.NOT_CONTAINS]: {
|
|
111
|
-
label: 'Not Contains',
|
|
112
|
-
abbreviation: '⊉',
|
|
113
|
-
},
|
|
114
|
-
[Op.IS_EMPTY]: {
|
|
115
|
-
label: 'Is Empty',
|
|
116
|
-
abbreviation: '=',
|
|
117
|
-
rightDisplay: 'Empty',
|
|
118
|
-
},
|
|
119
|
-
[Op.IS_NOT_EMPTY]: {
|
|
120
|
-
label: 'Is Not Empty',
|
|
121
|
-
abbreviation: '≠',
|
|
122
|
-
rightDisplay: 'Empty',
|
|
123
|
-
},
|
|
124
|
-
[Op.IS_TRUE]: {
|
|
125
|
-
label: 'Is True',
|
|
126
|
-
abbreviation: '=',
|
|
127
|
-
rightDisplay: 'True',
|
|
128
|
-
},
|
|
129
|
-
[Op.IS_FALSE]: {
|
|
130
|
-
label: 'Is False',
|
|
131
|
-
abbreviation: '=',
|
|
132
|
-
rightDisplay: 'False',
|
|
133
|
-
},
|
|
134
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { useMemo } from 'react';
|
|
7
|
-
|
|
8
|
-
import { I18n } from '@flowgram.ai/editor';
|
|
9
|
-
import { Button, Select } from '@douyinfe/semi-ui';
|
|
10
|
-
import { IconChevronDownStroked } from '@douyinfe/semi-icons';
|
|
11
|
-
|
|
12
|
-
import { IRule, OpConfigs } from '../types';
|
|
13
|
-
import { defaultOpConfigs } from '../constants';
|
|
14
|
-
|
|
15
|
-
interface HookParams {
|
|
16
|
-
rule?: IRule;
|
|
17
|
-
op?: string;
|
|
18
|
-
onChange: (op: string) => void;
|
|
19
|
-
readonly?: boolean;
|
|
20
|
-
userOps?: OpConfigs;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function useOp({ rule, op, onChange, readonly, userOps }: HookParams) {
|
|
24
|
-
const options = useMemo(
|
|
25
|
-
() =>
|
|
26
|
-
Object.keys(rule || {}).map((_op) => ({
|
|
27
|
-
...(defaultOpConfigs[_op] || {}),
|
|
28
|
-
...(userOps?.[_op] || {}),
|
|
29
|
-
value: _op,
|
|
30
|
-
label: I18n.t(userOps?.[_op]?.label || defaultOpConfigs[_op]?.label),
|
|
31
|
-
})),
|
|
32
|
-
[rule, userOps]
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
const opConfig = useMemo(() => defaultOpConfigs[op as string], [op]);
|
|
36
|
-
|
|
37
|
-
const renderOpSelect = () => (
|
|
38
|
-
<Select
|
|
39
|
-
style={{ height: 22 }}
|
|
40
|
-
disabled={readonly}
|
|
41
|
-
size="small"
|
|
42
|
-
value={op}
|
|
43
|
-
optionList={options}
|
|
44
|
-
onChange={(v) => {
|
|
45
|
-
onChange(v as string);
|
|
46
|
-
}}
|
|
47
|
-
triggerRender={({ value }) => (
|
|
48
|
-
<Button size="small" disabled={!rule}>
|
|
49
|
-
{opConfig?.abbreviation || <IconChevronDownStroked size="small" />}
|
|
50
|
-
</Button>
|
|
51
|
-
)}
|
|
52
|
-
/>
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
return { renderOpSelect, opConfig };
|
|
56
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useMemo } from 'react';
|
|
7
|
-
|
|
8
|
-
import { JsonSchemaUtils, JsonSchemaBasicType } from '@flowgram.ai/json-schema';
|
|
9
|
-
import { useScopeAvailable } from '@flowgram.ai/editor';
|
|
10
|
-
|
|
11
|
-
import { IFlowRefValue } from '@/shared';
|
|
12
|
-
|
|
13
|
-
import { IRules } from '../types';
|
|
14
|
-
import { defaultRules } from '../constants';
|
|
15
|
-
|
|
16
|
-
export function useRule(left?: IFlowRefValue, userRules?: IRules) {
|
|
17
|
-
const available = useScopeAvailable();
|
|
18
|
-
|
|
19
|
-
const rules = useMemo(() => ({ ...defaultRules, ...(userRules || {}) }), [userRules]);
|
|
20
|
-
|
|
21
|
-
const variable = useMemo(() => {
|
|
22
|
-
if (!left) return undefined;
|
|
23
|
-
return available.getByKeyPath(left.content);
|
|
24
|
-
}, [available, left]);
|
|
25
|
-
|
|
26
|
-
const rule = useMemo(() => {
|
|
27
|
-
if (!variable) return undefined;
|
|
28
|
-
|
|
29
|
-
const schema = JsonSchemaUtils.astToSchema(variable.type, { drilldown: false });
|
|
30
|
-
|
|
31
|
-
return rules[schema?.type as JsonSchemaBasicType];
|
|
32
|
-
}, [variable?.type, rules]);
|
|
33
|
-
|
|
34
|
-
return { rule };
|
|
35
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useMemo } from 'react';
|
|
7
|
-
import React from 'react';
|
|
8
|
-
|
|
9
|
-
import { JsonSchemaTypeManager, useTypeManager } from '@flowgram.ai/json-schema';
|
|
10
|
-
import { Icon } from '@douyinfe/semi-ui';
|
|
11
|
-
|
|
12
|
-
import { ConditionRow } from '@/components';
|
|
13
|
-
|
|
14
|
-
import { DBConditionOptionType, IRules } from '../types';
|
|
15
|
-
import { UIOptionLabel, UISelect } from '../styles';
|
|
16
|
-
|
|
17
|
-
const defaultRules = ConditionRow.defaultRules;
|
|
18
|
-
|
|
19
|
-
interface HookParams {
|
|
20
|
-
left?: string;
|
|
21
|
-
options?: DBConditionOptionType[];
|
|
22
|
-
userRules?: IRules;
|
|
23
|
-
readonly?: boolean;
|
|
24
|
-
onChange: (leftKey: string) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function useLeft({ left, options, userRules, readonly, onChange }: HookParams) {
|
|
28
|
-
const rules = useMemo(() => ({ ...defaultRules, ...(userRules || {}) }), [userRules]);
|
|
29
|
-
|
|
30
|
-
const typeManager = useTypeManager() as JsonSchemaTypeManager;
|
|
31
|
-
|
|
32
|
-
const rule = useMemo(() => {
|
|
33
|
-
if (!left) return undefined;
|
|
34
|
-
|
|
35
|
-
const option = options?.find((item) => item.value === left);
|
|
36
|
-
|
|
37
|
-
if (!option?.schema?.type) {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return rules[option.schema.type];
|
|
42
|
-
}, [left, options, rules]);
|
|
43
|
-
|
|
44
|
-
const renderDBOptionSelect = () => (
|
|
45
|
-
<UISelect
|
|
46
|
-
disabled={readonly}
|
|
47
|
-
size="small"
|
|
48
|
-
style={{ width: '100%' }}
|
|
49
|
-
value={left}
|
|
50
|
-
onChange={(v) => onChange(v as string)}
|
|
51
|
-
optionList={
|
|
52
|
-
options?.map((item) => ({
|
|
53
|
-
label: (
|
|
54
|
-
<UIOptionLabel>
|
|
55
|
-
<Icon size="small" svg={typeManager.getDisplayIcon(item.schema)} />
|
|
56
|
-
{item.label}
|
|
57
|
-
</UIOptionLabel>
|
|
58
|
-
),
|
|
59
|
-
value: item.value,
|
|
60
|
-
})) || []
|
|
61
|
-
}
|
|
62
|
-
/>
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return { rule, renderDBOptionSelect };
|
|
66
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { useMemo } from 'react';
|
|
7
|
-
|
|
8
|
-
import { I18n } from '@flowgram.ai/editor';
|
|
9
|
-
import { Button, Select } from '@douyinfe/semi-ui';
|
|
10
|
-
import { IconChevronDownStroked } from '@douyinfe/semi-icons';
|
|
11
|
-
|
|
12
|
-
import { ConditionRow } from '@/components';
|
|
13
|
-
|
|
14
|
-
import { IRule, OpConfigs } from '../types';
|
|
15
|
-
|
|
16
|
-
const defaultOpConfigs = ConditionRow.defaultOpConfigs;
|
|
17
|
-
|
|
18
|
-
interface HookParams {
|
|
19
|
-
rule?: IRule;
|
|
20
|
-
op?: string;
|
|
21
|
-
onChange: (op: string) => void;
|
|
22
|
-
readonly?: boolean;
|
|
23
|
-
userOps?: OpConfigs;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function useOp({ rule, op, onChange, readonly, userOps }: HookParams) {
|
|
27
|
-
const options = useMemo(
|
|
28
|
-
() =>
|
|
29
|
-
Object.keys(rule || {}).map((_op) => ({
|
|
30
|
-
...(defaultOpConfigs[_op] || {}),
|
|
31
|
-
...(userOps?.[_op] || {}),
|
|
32
|
-
value: _op,
|
|
33
|
-
label: I18n.t(userOps?.[_op]?.label || defaultOpConfigs[_op]?.label),
|
|
34
|
-
})),
|
|
35
|
-
[rule, userOps]
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const opConfig = useMemo(() => defaultOpConfigs[op as string], [op]);
|
|
39
|
-
|
|
40
|
-
const renderOpSelect = () => (
|
|
41
|
-
<Select
|
|
42
|
-
style={{ height: 22 }}
|
|
43
|
-
disabled={readonly}
|
|
44
|
-
size="small"
|
|
45
|
-
value={op}
|
|
46
|
-
optionList={options}
|
|
47
|
-
onChange={(v) => {
|
|
48
|
-
onChange(v as string);
|
|
49
|
-
}}
|
|
50
|
-
triggerRender={({ value }) => (
|
|
51
|
-
<Button size="small" disabled={!rule}>
|
|
52
|
-
{opConfig?.abbreviation || <IconChevronDownStroked size="small" />}
|
|
53
|
-
</Button>
|
|
54
|
-
)}
|
|
55
|
-
/>
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return { renderOpSelect, opConfig };
|
|
59
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { useLayoutEffect } from 'react';
|
|
7
|
-
|
|
8
|
-
import { isEqual, last } from 'lodash-es';
|
|
9
|
-
import {
|
|
10
|
-
BaseVariableField,
|
|
11
|
-
Disposable,
|
|
12
|
-
DisposableCollection,
|
|
13
|
-
Scope,
|
|
14
|
-
useCurrentScope,
|
|
15
|
-
} from '@flowgram.ai/editor';
|
|
16
|
-
import { useInjector } from '@flowgram.ai/coze-editor/react';
|
|
17
|
-
import { Popover } from '@douyinfe/semi-ui';
|
|
18
|
-
import { IconIssueStroked } from '@douyinfe/semi-icons';
|
|
19
|
-
import {
|
|
20
|
-
Decoration,
|
|
21
|
-
DecorationSet,
|
|
22
|
-
EditorView,
|
|
23
|
-
MatchDecorator,
|
|
24
|
-
ViewPlugin,
|
|
25
|
-
WidgetType,
|
|
26
|
-
} from '@codemirror/view';
|
|
27
|
-
|
|
28
|
-
import { IPolyfillRoot, polyfillCreateRoot } from '@/shared';
|
|
29
|
-
|
|
30
|
-
import { UIPopoverContent, UIRootTitle, UITag, UIVarName } from '../styles';
|
|
31
|
-
|
|
32
|
-
class VariableTagWidget extends WidgetType {
|
|
33
|
-
keyPath?: string[];
|
|
34
|
-
|
|
35
|
-
toDispose = new DisposableCollection();
|
|
36
|
-
|
|
37
|
-
scope: Scope;
|
|
38
|
-
|
|
39
|
-
root: IPolyfillRoot;
|
|
40
|
-
|
|
41
|
-
constructor({ keyPath, scope }: { keyPath?: string[]; scope: Scope }) {
|
|
42
|
-
super();
|
|
43
|
-
|
|
44
|
-
this.keyPath = keyPath;
|
|
45
|
-
this.scope = scope;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
renderIcon = (icon: string | JSX.Element) => {
|
|
49
|
-
if (typeof icon === 'string') {
|
|
50
|
-
return <img style={{ marginRight: 8 }} width={12} height={12} src={icon} />;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return icon;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
renderVariable(v?: BaseVariableField) {
|
|
57
|
-
if (!v) {
|
|
58
|
-
this.root.render(
|
|
59
|
-
<UITag prefixIcon={<IconIssueStroked />} color="amber">
|
|
60
|
-
Unknown
|
|
61
|
-
</UITag>
|
|
62
|
-
);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const rootField = last(v.parentFields);
|
|
67
|
-
|
|
68
|
-
const rootTitle = (
|
|
69
|
-
<UIRootTitle>{rootField?.meta.title ? `${rootField.meta.title} -` : ''}</UIRootTitle>
|
|
70
|
-
);
|
|
71
|
-
const rootIcon = this.renderIcon(rootField?.meta.icon);
|
|
72
|
-
|
|
73
|
-
this.root.render(
|
|
74
|
-
<Popover
|
|
75
|
-
content={
|
|
76
|
-
<UIPopoverContent>
|
|
77
|
-
{rootIcon}
|
|
78
|
-
{rootTitle}
|
|
79
|
-
<UIVarName>{v?.keyPath.slice(1).join('.')}</UIVarName>
|
|
80
|
-
</UIPopoverContent>
|
|
81
|
-
}
|
|
82
|
-
>
|
|
83
|
-
<UITag prefixIcon={rootIcon}>
|
|
84
|
-
{rootTitle}
|
|
85
|
-
<UIVarName>{v?.key}</UIVarName>
|
|
86
|
-
</UITag>
|
|
87
|
-
</Popover>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
toDOM(view: EditorView): HTMLElement {
|
|
92
|
-
const dom = document.createElement('span');
|
|
93
|
-
|
|
94
|
-
this.root = polyfillCreateRoot(dom);
|
|
95
|
-
|
|
96
|
-
this.toDispose.push(
|
|
97
|
-
Disposable.create(() => {
|
|
98
|
-
this.root.unmount();
|
|
99
|
-
})
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
this.toDispose.push(
|
|
103
|
-
this.scope.available.trackByKeyPath(
|
|
104
|
-
this.keyPath,
|
|
105
|
-
(v) => {
|
|
106
|
-
this.renderVariable(v);
|
|
107
|
-
},
|
|
108
|
-
{ triggerOnInit: false }
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
|
|
113
|
-
|
|
114
|
-
return dom;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
eq(other: VariableTagWidget) {
|
|
118
|
-
return isEqual(this.keyPath, other.keyPath);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
ignoreEvent(): boolean {
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
destroy(dom: HTMLElement): void {
|
|
126
|
-
this.toDispose.dispose();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function VariableTagInject() {
|
|
131
|
-
const injector = useInjector();
|
|
132
|
-
|
|
133
|
-
const scope = useCurrentScope();
|
|
134
|
-
|
|
135
|
-
// 基于 {{var}} 的正则进行匹配,匹配后进行自定义渲染
|
|
136
|
-
useLayoutEffect(() => {
|
|
137
|
-
const atMatcher = new MatchDecorator({
|
|
138
|
-
regexp: /\{\{([^\}\{]+)\}\}/g,
|
|
139
|
-
decoration: (match) =>
|
|
140
|
-
Decoration.replace({
|
|
141
|
-
widget: new VariableTagWidget({
|
|
142
|
-
keyPath: match[1]?.split('.') ?? [],
|
|
143
|
-
scope,
|
|
144
|
-
}),
|
|
145
|
-
}),
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
return injector.inject([
|
|
149
|
-
ViewPlugin.fromClass(
|
|
150
|
-
class {
|
|
151
|
-
decorations: DecorationSet;
|
|
152
|
-
|
|
153
|
-
constructor(private view: EditorView) {
|
|
154
|
-
this.decorations = atMatcher.createDeco(view);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
update() {
|
|
158
|
-
this.decorations = atMatcher.createDeco(this.view);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
decorations: (p) => p.decorations,
|
|
163
|
-
provide(p) {
|
|
164
|
-
return EditorView.atomicRanges.of(
|
|
165
|
-
(view) => view.plugin(p)?.decorations ?? Decoration.none
|
|
166
|
-
);
|
|
167
|
-
},
|
|
168
|
-
}
|
|
169
|
-
),
|
|
170
|
-
]);
|
|
171
|
-
}, [injector]);
|
|
172
|
-
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { useEffect, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
Mention,
|
|
10
|
-
MentionOpenChangeEvent,
|
|
11
|
-
getCurrentMentionReplaceRange,
|
|
12
|
-
useEditor,
|
|
13
|
-
PositionMirror,
|
|
14
|
-
} from '@flowgram.ai/coze-editor/react';
|
|
15
|
-
import { EditorAPI } from '@flowgram.ai/coze-editor/preset-prompt';
|
|
16
|
-
import { Popover, Tree } from '@douyinfe/semi-ui';
|
|
17
|
-
|
|
18
|
-
import { useVariableTree } from '@/components/variable-selector';
|
|
19
|
-
|
|
20
|
-
export function VariableTree() {
|
|
21
|
-
const [posKey, setPosKey] = useState('');
|
|
22
|
-
const [visible, setVisible] = useState(false);
|
|
23
|
-
const [position, setPosition] = useState(-1);
|
|
24
|
-
const editor = useEditor<EditorAPI>();
|
|
25
|
-
|
|
26
|
-
function insert(variablePath: string) {
|
|
27
|
-
const range = getCurrentMentionReplaceRange(editor.$view.state);
|
|
28
|
-
|
|
29
|
-
if (!range) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
editor.replaceText({
|
|
34
|
-
...range,
|
|
35
|
-
text: '{{' + variablePath + '}}',
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
setVisible(false);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function handleOpenChange(e: MentionOpenChangeEvent) {
|
|
42
|
-
setPosition(e.state.selection.main.head);
|
|
43
|
-
setVisible(e.value);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (!editor) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
}, [editor, visible]);
|
|
51
|
-
|
|
52
|
-
const treeData = useVariableTree({});
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<>
|
|
56
|
-
<Mention triggerCharacters={['@']} onOpenChange={handleOpenChange} />
|
|
57
|
-
|
|
58
|
-
<Popover
|
|
59
|
-
visible={visible}
|
|
60
|
-
trigger="custom"
|
|
61
|
-
position="topLeft"
|
|
62
|
-
rePosKey={posKey}
|
|
63
|
-
content={
|
|
64
|
-
<div style={{ width: 300 }}>
|
|
65
|
-
<Tree
|
|
66
|
-
treeData={treeData}
|
|
67
|
-
onSelect={(v) => {
|
|
68
|
-
insert(v);
|
|
69
|
-
}}
|
|
70
|
-
/>
|
|
71
|
-
</div>
|
|
72
|
-
}
|
|
73
|
-
>
|
|
74
|
-
{/* PositionMirror allows the Popover to appear at the specified cursor position */}
|
|
75
|
-
<PositionMirror
|
|
76
|
-
position={position}
|
|
77
|
-
// When Doc scroll, update position
|
|
78
|
-
onChange={() => setPosKey(String(Math.random()))}
|
|
79
|
-
/>
|
|
80
|
-
</Popover>
|
|
81
|
-
</>
|
|
82
|
-
);
|
|
83
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
3
|
-
* SPDX-License-Identifier: MIT
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import React, { useEffect, useState } from 'react';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
Mention,
|
|
10
|
-
MentionOpenChangeEvent,
|
|
11
|
-
getCurrentMentionReplaceRange,
|
|
12
|
-
useEditor,
|
|
13
|
-
PositionMirror,
|
|
14
|
-
} from '@flowgram.ai/coze-editor/react';
|
|
15
|
-
import { EditorAPI } from '@flowgram.ai/coze-editor/preset-prompt';
|
|
16
|
-
import { Popover } from '@douyinfe/semi-ui';
|
|
17
|
-
|
|
18
|
-
import { IFlowValue } from '@/shared';
|
|
19
|
-
|
|
20
|
-
import { InputsPicker } from '../inputs-picker';
|
|
21
|
-
|
|
22
|
-
export function InputsTree({ inputsValues }: { inputsValues: Record<string, IFlowValue> }) {
|
|
23
|
-
const [posKey, setPosKey] = useState('');
|
|
24
|
-
const [visible, setVisible] = useState(false);
|
|
25
|
-
const [position, setPosition] = useState(-1);
|
|
26
|
-
const editor = useEditor<EditorAPI>();
|
|
27
|
-
|
|
28
|
-
function insert(variablePath: string) {
|
|
29
|
-
const range = getCurrentMentionReplaceRange(editor.$view.state);
|
|
30
|
-
|
|
31
|
-
if (!range) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* When user input {{xxxx}}, {{{xxx}}}(more brackets if possible), replace all brackets with {{xxxx}}
|
|
37
|
-
*/
|
|
38
|
-
let { from, to } = range;
|
|
39
|
-
while (editor.$view.state.doc.sliceString(from - 1, from) === '{') {
|
|
40
|
-
from--;
|
|
41
|
-
}
|
|
42
|
-
while (editor.$view.state.doc.sliceString(to, to + 1) === '}') {
|
|
43
|
-
to++;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
editor.replaceText({
|
|
47
|
-
...range,
|
|
48
|
-
text: '{{' + variablePath + '}}',
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
setVisible(false);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function handleOpenChange(e: MentionOpenChangeEvent) {
|
|
55
|
-
setPosition(e.state.selection.main.head);
|
|
56
|
-
setVisible(e.value);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
useEffect(() => {
|
|
60
|
-
if (!editor) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
}, [editor, visible]);
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<>
|
|
67
|
-
<Mention triggerCharacters={['{', '{}', '@']} onOpenChange={handleOpenChange} />
|
|
68
|
-
|
|
69
|
-
<Popover
|
|
70
|
-
visible={visible}
|
|
71
|
-
trigger="custom"
|
|
72
|
-
position="topLeft"
|
|
73
|
-
rePosKey={posKey}
|
|
74
|
-
content={
|
|
75
|
-
<div style={{ width: 300 }}>
|
|
76
|
-
<InputsPicker
|
|
77
|
-
inputsValues={inputsValues}
|
|
78
|
-
onSelect={(v) => {
|
|
79
|
-
insert(v);
|
|
80
|
-
}}
|
|
81
|
-
/>
|
|
82
|
-
</div>
|
|
83
|
-
}
|
|
84
|
-
>
|
|
85
|
-
{/* PositionMirror allows the Popover to appear at the specified cursor position */}
|
|
86
|
-
<PositionMirror
|
|
87
|
-
position={position}
|
|
88
|
-
// When Doc scroll, update position
|
|
89
|
-
onChange={() => setPosKey(String(Math.random()))}
|
|
90
|
-
/>
|
|
91
|
-
</Popover>
|
|
92
|
-
</>
|
|
93
|
-
);
|
|
94
|
-
}
|