@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.
Files changed (272) hide show
  1. package/bin/run.sh +3 -2
  2. package/dist/cjs/components/blur-input/index.js +2 -12
  3. package/dist/cjs/components/code-editor/editor-all.js +52 -0
  4. package/dist/cjs/components/code-editor/editor-json.js +71 -0
  5. package/dist/cjs/components/code-editor/editor-python.js +63 -0
  6. package/dist/cjs/components/code-editor/editor-shell.js +63 -0
  7. package/dist/cjs/components/code-editor/editor-sql.js +71 -0
  8. package/dist/cjs/components/code-editor/editor-ts.js +80 -0
  9. package/dist/cjs/components/code-editor/editor.js +45 -57
  10. package/dist/cjs/components/code-editor/factory.js +96 -0
  11. package/dist/cjs/components/code-editor/index.js +31 -28
  12. package/dist/cjs/components/code-editor/theme/dark.js +120 -50
  13. package/dist/cjs/components/code-editor/theme/light.js +110 -61
  14. package/dist/cjs/components/code-editor/utils.js +1 -0
  15. package/dist/cjs/components/condition-context/context.js +59 -0
  16. package/dist/cjs/components/condition-context/hooks/use-condition.js +97 -0
  17. package/dist/cjs/components/condition-context/index.js +47 -0
  18. package/dist/cjs/components/condition-context/op.js +117 -0
  19. package/dist/cjs/components/condition-row/index.js +43 -26
  20. package/dist/cjs/components/condition-row/types.js +1 -35
  21. package/dist/cjs/components/{prompt-editor-with-inputs/inputs-picker.js → coze-editor-extensions/extensions/inputs-tree.js} +70 -2
  22. package/dist/cjs/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.js +4 -3
  23. package/dist/cjs/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.js +13 -7
  24. package/dist/cjs/components/coze-editor-extensions/index.js +86 -0
  25. package/dist/cjs/components/db-condition-row/index.js +59 -34
  26. package/dist/cjs/components/display-schema-tree/index.js +2 -2
  27. package/dist/cjs/components/index.js +49 -4
  28. package/dist/cjs/components/json-editor-with-variables/editor.js +10 -7
  29. package/dist/cjs/components/prompt-editor-with-inputs/editor.js +2 -2
  30. package/dist/cjs/components/prompt-editor-with-variables/editor.js +3 -4
  31. package/dist/cjs/components/{condition-row/hooks/useRule.js → sql-editor-with-variables/editor.js} +19 -34
  32. package/dist/cjs/components/sql-editor-with-variables/index.js +57 -0
  33. package/dist/cjs/components/type-selector/index.js +2 -2
  34. package/dist/cjs/components/variable-selector/use-variable-tree.js +1 -2
  35. package/dist/cjs/effects/provide-batch-input/index.js +1 -1
  36. package/dist/cjs/effects/provide-json-schema-outputs/index.js +1 -1
  37. package/dist/cjs/form-plugins/batch-outputs-plugin/index.js +9 -2
  38. package/dist/cjs/form-plugins/infer-assign-plugin/index.js +1 -1
  39. package/dist/cjs/form-plugins/infer-inputs-plugin/index.js +30 -3
  40. package/dist/cjs/index.js +44 -2
  41. package/dist/cjs/plugins/json-schema-preset/create-type-preset-plugin.js +1 -0
  42. package/dist/cjs/plugins/json-schema-preset/index.js +3 -13
  43. package/dist/cjs/{components/code-editor/init-worker.js → plugins/json-schema-preset/react.js} +18 -23
  44. package/dist/cjs/plugins/json-schema-preset/type-definition/array.js +33 -4
  45. package/dist/cjs/plugins/json-schema-preset/type-definition/boolean.js +23 -0
  46. package/dist/cjs/plugins/json-schema-preset/type-definition/date-time.js +31 -2
  47. package/dist/cjs/plugins/json-schema-preset/type-definition/index.js +9 -1
  48. package/dist/cjs/plugins/json-schema-preset/type-definition/integer.js +34 -1
  49. package/dist/cjs/plugins/json-schema-preset/type-definition/map.js +54 -0
  50. package/dist/cjs/plugins/json-schema-preset/type-definition/number.js +34 -1
  51. package/dist/cjs/plugins/json-schema-preset/type-definition/object.js +9 -4
  52. package/dist/cjs/plugins/json-schema-preset/type-definition/string.js +30 -1
  53. package/dist/cjs/plugins/json-schema-preset/types.js +18 -0
  54. package/dist/cjs/shared/flow-value/utils.js +22 -8
  55. package/dist/cjs/shared/inject-material/index.js +2 -1
  56. package/dist/esm/components/blur-input/index.mjs +2 -2
  57. package/dist/esm/components/code-editor/editor-all.mjs +18 -0
  58. package/dist/esm/components/code-editor/editor-json.mjs +16 -0
  59. package/dist/esm/components/code-editor/editor-python.mjs +8 -0
  60. package/dist/esm/components/code-editor/editor-shell.mjs +8 -0
  61. package/dist/esm/components/code-editor/editor-sql.mjs +16 -0
  62. package/dist/esm/components/code-editor/editor-ts.mjs +22 -0
  63. package/dist/esm/components/code-editor/editor.mjs +38 -33
  64. package/dist/esm/components/code-editor/factory.mjs +36 -0
  65. package/dist/esm/components/code-editor/index.mjs +8 -5
  66. package/dist/esm/components/code-editor/theme/dark.mjs +117 -50
  67. package/dist/esm/components/code-editor/theme/light.mjs +108 -62
  68. package/dist/esm/components/code-editor/utils.mjs +1 -0
  69. package/dist/esm/components/condition-context/context.mjs +19 -0
  70. package/dist/esm/components/condition-context/hooks/use-condition.mjs +63 -0
  71. package/dist/esm/components/condition-context/index.mjs +4 -0
  72. package/dist/esm/components/condition-context/op.mjs +80 -0
  73. package/dist/esm/components/condition-row/index.mjs +45 -28
  74. package/dist/esm/components/condition-row/types.mjs +0 -18
  75. package/dist/esm/components/coze-editor-extensions/extensions/inputs-tree.mjs +135 -0
  76. package/dist/esm/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.mjs +4 -3
  77. package/dist/esm/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.mjs +13 -7
  78. package/dist/esm/components/coze-editor-extensions/index.mjs +18 -0
  79. package/dist/esm/components/db-condition-row/index.mjs +59 -34
  80. package/dist/esm/components/display-schema-tree/index.mjs +1 -1
  81. package/dist/esm/components/index.mjs +5 -2
  82. package/dist/esm/components/json-editor-with-variables/editor.mjs +10 -7
  83. package/dist/esm/components/prompt-editor-with-inputs/editor.mjs +2 -2
  84. package/dist/esm/components/prompt-editor-with-variables/editor.mjs +3 -4
  85. package/dist/esm/components/sql-editor-with-variables/editor.mjs +19 -0
  86. package/dist/esm/components/sql-editor-with-variables/index.mjs +5 -0
  87. package/dist/esm/components/type-selector/index.mjs +1 -1
  88. package/dist/esm/components/variable-selector/use-variable-tree.mjs +1 -2
  89. package/dist/esm/effects/provide-batch-input/index.mjs +2 -2
  90. package/dist/esm/effects/provide-json-schema-outputs/index.mjs +2 -2
  91. package/dist/esm/form-plugins/batch-outputs-plugin/index.mjs +10 -3
  92. package/dist/esm/form-plugins/infer-assign-plugin/index.mjs +2 -2
  93. package/dist/esm/form-plugins/infer-inputs-plugin/index.mjs +31 -4
  94. package/dist/esm/index.mjs +2 -2
  95. package/dist/esm/plugins/json-schema-preset/create-type-preset-plugin.mjs +2 -1
  96. package/dist/esm/plugins/json-schema-preset/index.mjs +3 -13
  97. package/dist/esm/plugins/json-schema-preset/react.mjs +14 -0
  98. package/dist/esm/plugins/json-schema-preset/type-definition/array.mjs +33 -4
  99. package/dist/esm/plugins/json-schema-preset/type-definition/boolean.mjs +23 -0
  100. package/dist/esm/plugins/json-schema-preset/type-definition/date-time.mjs +31 -2
  101. package/dist/esm/plugins/json-schema-preset/type-definition/index.mjs +7 -2
  102. package/dist/esm/plugins/json-schema-preset/type-definition/integer.mjs +34 -1
  103. package/dist/esm/plugins/json-schema-preset/type-definition/map.mjs +20 -0
  104. package/dist/esm/plugins/json-schema-preset/type-definition/number.mjs +34 -1
  105. package/dist/esm/plugins/json-schema-preset/type-definition/object.mjs +9 -4
  106. package/dist/esm/plugins/json-schema-preset/type-definition/string.mjs +30 -1
  107. package/dist/esm/plugins/json-schema-preset/types.mjs +0 -0
  108. package/dist/esm/shared/flow-value/utils.mjs +22 -8
  109. package/dist/esm/shared/inject-material/index.mjs +2 -1
  110. package/dist/tsconfig.tsbuildinfo +1 -1
  111. package/dist/types/components/blur-input/index.d.ts +7 -1
  112. package/dist/types/components/code-editor/editor-all.d.ts +8 -0
  113. package/dist/types/components/code-editor/editor-json.d.ts +6 -0
  114. package/dist/types/components/code-editor/editor-python.d.ts +6 -0
  115. package/dist/types/components/code-editor/editor-shell.d.ts +6 -0
  116. package/dist/types/components/code-editor/editor-sql.d.ts +6 -0
  117. package/dist/types/components/code-editor/editor-ts.d.ts +6 -0
  118. package/dist/types/components/code-editor/editor.d.ts +3 -4
  119. package/dist/types/components/code-editor/factory.d.ts +13 -0
  120. package/dist/types/components/code-editor/index.d.ts +7 -2
  121. package/dist/types/components/code-editor/theme/dark.d.ts +29 -0
  122. package/dist/types/components/code-editor/theme/light.d.ts +24 -0
  123. package/dist/types/components/code-editor/utils.d.ts +1 -1
  124. package/dist/types/components/code-editor-mini/index.d.ts +3 -0
  125. package/dist/types/components/condition-context/context.d.ts +14 -0
  126. package/dist/types/components/condition-context/hooks/use-condition.d.ts +29 -0
  127. package/dist/types/components/condition-context/index.d.ts +8 -0
  128. package/dist/types/components/condition-context/op.d.ts +22 -0
  129. package/dist/types/components/condition-context/types.d.ts +14 -0
  130. package/dist/types/components/condition-row/index.d.ts +4 -7
  131. package/dist/types/components/condition-row/types.d.ts +0 -24
  132. package/dist/types/components/{prompt-editor-with-inputs/inputs-picker.d.ts → coze-editor-extensions/extensions/inputs-tree.d.ts} +5 -0
  133. package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.d.ts +3 -1
  134. package/dist/types/components/coze-editor-extensions/index.d.ts +18 -0
  135. package/dist/types/components/db-condition-row/index.d.ts +4 -3
  136. package/dist/types/components/db-condition-row/types.d.ts +0 -8
  137. package/dist/types/components/display-schema-tree/index.d.ts +1 -1
  138. package/dist/types/components/dynamic-value-input/index.d.ts +3 -1
  139. package/dist/types/components/index.d.ts +4 -1
  140. package/dist/types/components/sql-editor-with-variables/editor.d.ts +9 -0
  141. package/dist/types/components/sql-editor-with-variables/index.d.ts +6 -0
  142. package/dist/types/components/type-selector/index.d.ts +3 -1
  143. package/dist/types/components/variable-selector/index.d.ts +4 -2
  144. package/dist/types/form-plugins/batch-outputs-plugin/index.d.ts +4 -0
  145. package/dist/types/form-plugins/infer-inputs-plugin/index.d.ts +4 -0
  146. package/dist/types/index.d.ts +1 -1
  147. package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +1 -1
  148. package/dist/types/plugins/json-schema-preset/index.d.ts +3 -7
  149. package/dist/types/plugins/json-schema-preset/react.d.ts +11 -0
  150. package/dist/types/plugins/json-schema-preset/type-definition/array.d.ts +1 -1
  151. package/dist/types/plugins/json-schema-preset/type-definition/boolean.d.ts +1 -1
  152. package/dist/types/plugins/json-schema-preset/type-definition/date-time.d.ts +1 -1
  153. package/dist/types/plugins/json-schema-preset/type-definition/index.d.ts +3 -1
  154. package/dist/types/plugins/json-schema-preset/type-definition/integer.d.ts +1 -1
  155. package/dist/types/plugins/json-schema-preset/type-definition/map.d.ts +6 -0
  156. package/dist/types/plugins/json-schema-preset/type-definition/number.d.ts +1 -1
  157. package/dist/types/plugins/json-schema-preset/type-definition/object.d.ts +1 -1
  158. package/dist/types/plugins/json-schema-preset/type-definition/string.d.ts +1 -1
  159. package/dist/types/plugins/json-schema-preset/{manager.d.ts → types.d.ts} +5 -0
  160. package/dist/types/shared/flow-value/utils.d.ts +3 -1
  161. package/dist/types/shared/inject-material/index.d.ts +6 -4
  162. package/dist/types/validate/validate-flow-value/index.d.ts +1 -1
  163. package/package.json +56 -17
  164. package/src/components/blur-input/index.tsx +9 -1
  165. package/src/components/code-editor/editor-all.tsx +30 -0
  166. package/src/components/code-editor/editor-json.tsx +25 -0
  167. package/src/components/code-editor/editor-python.tsx +18 -0
  168. package/src/components/code-editor/editor-shell.tsx +18 -0
  169. package/src/components/code-editor/editor-sql.tsx +24 -0
  170. package/src/components/code-editor/editor-ts.tsx +31 -0
  171. package/src/components/code-editor/editor.tsx +45 -36
  172. package/src/components/code-editor/factory.tsx +61 -0
  173. package/src/components/code-editor/index.tsx +7 -7
  174. package/src/components/code-editor/theme/dark.ts +62 -77
  175. package/src/components/code-editor/theme/light.ts +60 -91
  176. package/src/components/code-editor/utils.ts +4 -0
  177. package/src/components/code-editor-mini/index.tsx +3 -0
  178. package/src/components/condition-context/context.tsx +28 -0
  179. package/src/components/condition-context/hooks/use-condition.tsx +99 -0
  180. package/src/components/condition-context/index.tsx +14 -0
  181. package/src/components/condition-context/op.ts +86 -0
  182. package/src/components/condition-context/types.ts +22 -0
  183. package/src/components/condition-row/index.tsx +44 -22
  184. package/src/components/condition-row/types.ts +0 -30
  185. package/src/components/{prompt-editor-with-inputs/inputs-picker.tsx → coze-editor-extensions/extensions/inputs-tree.tsx} +95 -5
  186. package/src/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.tsx +6 -3
  187. package/src/components/{prompt-editor-with-variables → coze-editor-extensions}/extensions/variable-tree.tsx +12 -3
  188. package/src/components/coze-editor-extensions/index.tsx +33 -0
  189. package/src/components/db-condition-row/index.tsx +76 -24
  190. package/src/components/db-condition-row/types.ts +0 -13
  191. package/src/components/display-schema-tree/index.tsx +6 -4
  192. package/src/components/index.ts +29 -1
  193. package/src/components/json-editor-with-variables/editor.tsx +7 -8
  194. package/src/components/prompt-editor-with-inputs/editor.tsx +2 -3
  195. package/src/components/prompt-editor-with-variables/editor.tsx +3 -5
  196. package/src/components/sql-editor-with-variables/editor.tsx +28 -0
  197. package/src/components/sql-editor-with-variables/index.tsx +12 -0
  198. package/src/components/type-selector/index.tsx +2 -3
  199. package/src/components/variable-selector/index.tsx +2 -2
  200. package/src/components/variable-selector/use-variable-tree.tsx +7 -4
  201. package/src/effects/provide-batch-input/index.ts +1 -2
  202. package/src/effects/provide-json-schema-outputs/index.ts +1 -2
  203. package/src/form-plugins/batch-outputs-plugin/index.ts +64 -46
  204. package/src/form-plugins/infer-assign-plugin/index.ts +1 -2
  205. package/src/form-plugins/infer-inputs-plugin/index.ts +62 -14
  206. package/src/index.ts +19 -0
  207. package/src/plugins/json-schema-preset/create-type-preset-plugin.tsx +4 -2
  208. package/src/plugins/json-schema-preset/index.tsx +4 -20
  209. package/src/plugins/json-schema-preset/react.tsx +31 -0
  210. package/src/plugins/json-schema-preset/type-definition/array.tsx +13 -4
  211. package/src/plugins/json-schema-preset/type-definition/boolean.tsx +17 -1
  212. package/src/plugins/json-schema-preset/type-definition/date-time.tsx +21 -2
  213. package/src/plugins/json-schema-preset/type-definition/index.tsx +10 -1
  214. package/src/plugins/json-schema-preset/type-definition/integer.tsx +19 -1
  215. package/src/plugins/json-schema-preset/type-definition/map.tsx +31 -0
  216. package/src/plugins/json-schema-preset/type-definition/number.tsx +19 -1
  217. package/src/plugins/json-schema-preset/type-definition/object.tsx +9 -4
  218. package/src/plugins/json-schema-preset/type-definition/string.tsx +19 -1
  219. package/src/plugins/json-schema-preset/{manager.ts → types.ts} +7 -0
  220. package/src/shared/flow-value/utils.ts +22 -9
  221. package/src/shared/inject-material/index.tsx +10 -6
  222. package/src/validate/validate-flow-value/index.tsx +1 -2
  223. package/dist/cjs/components/code-editor/language-features.js +0 -21
  224. package/dist/cjs/components/condition-row/constants.js +0 -165
  225. package/dist/cjs/components/condition-row/hooks/useOp.js +0 -78
  226. package/dist/cjs/components/db-condition-row/hooks/use-left.js +0 -86
  227. package/dist/cjs/components/db-condition-row/hooks/use-op.js +0 -79
  228. package/dist/cjs/components/json-editor-with-variables/extensions/variable-tag.js +0 -151
  229. package/dist/cjs/components/json-editor-with-variables/extensions/variable-tree.js +0 -97
  230. package/dist/cjs/components/prompt-editor-with-inputs/extensions/inputs-tree.js +0 -101
  231. package/dist/cjs/components/prompt-editor-with-variables/styles.js +0 -89
  232. package/dist/esm/components/code-editor/init-worker.mjs +0 -19
  233. package/dist/esm/components/code-editor/language-features.mjs +0 -15
  234. package/dist/esm/components/condition-row/constants.mjs +0 -128
  235. package/dist/esm/components/condition-row/hooks/useOp.mjs +0 -44
  236. package/dist/esm/components/condition-row/hooks/useRule.mjs +0 -34
  237. package/dist/esm/components/db-condition-row/hooks/use-left.mjs +0 -52
  238. package/dist/esm/components/db-condition-row/hooks/use-op.mjs +0 -45
  239. package/dist/esm/components/json-editor-with-variables/extensions/variable-tree.mjs +0 -63
  240. package/dist/esm/components/prompt-editor-with-inputs/extensions/inputs-tree.mjs +0 -67
  241. package/dist/esm/components/prompt-editor-with-inputs/inputs-picker.mjs +0 -70
  242. package/dist/esm/components/prompt-editor-with-variables/extensions/variable-tag.mjs +0 -117
  243. package/dist/esm/components/prompt-editor-with-variables/styles.mjs +0 -36
  244. package/dist/types/components/code-editor/init-worker.d.ts +0 -5
  245. package/dist/types/components/code-editor/language-features.d.ts +0 -5
  246. package/dist/types/components/condition-row/constants.d.ts +0 -7
  247. package/dist/types/components/condition-row/hooks/useOp.d.ts +0 -18
  248. package/dist/types/components/condition-row/hooks/useRule.d.ts +0 -9
  249. package/dist/types/components/db-condition-row/hooks/use-left.d.ts +0 -18
  250. package/dist/types/components/db-condition-row/hooks/use-op.d.ts +0 -18
  251. package/dist/types/components/prompt-editor-with-inputs/extensions/inputs-tree.d.ts +0 -9
  252. package/dist/types/components/prompt-editor-with-variables/extensions/variable-tag.d.ts +0 -5
  253. package/dist/types/components/prompt-editor-with-variables/extensions/variable-tree.d.ts +0 -6
  254. package/dist/types/components/prompt-editor-with-variables/styles.d.ts +0 -9
  255. package/src/components/code-editor/init-worker.ts +0 -27
  256. package/src/components/code-editor/language-features.ts +0 -23
  257. package/src/components/condition-row/constants.ts +0 -134
  258. package/src/components/condition-row/hooks/useOp.tsx +0 -56
  259. package/src/components/condition-row/hooks/useRule.ts +0 -35
  260. package/src/components/db-condition-row/hooks/use-left.tsx +0 -66
  261. package/src/components/db-condition-row/hooks/use-op.tsx +0 -59
  262. package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +0 -174
  263. package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +0 -83
  264. package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +0 -94
  265. package/src/components/prompt-editor-with-variables/styles.tsx +0 -44
  266. /package/dist/cjs/{plugins/json-schema-preset/manager.js → components/condition-context/types.js} +0 -0
  267. /package/dist/cjs/components/{json-editor-with-variables → coze-editor-extensions}/styles.js +0 -0
  268. /package/dist/esm/{plugins/json-schema-preset/manager.mjs → components/condition-context/types.mjs} +0 -0
  269. /package/dist/esm/components/{json-editor-with-variables → coze-editor-extensions}/styles.mjs +0 -0
  270. /package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/extensions/variable-tag.d.ts +0 -0
  271. /package/dist/types/components/{json-editor-with-variables → coze-editor-extensions}/styles.d.ts +0 -0
  272. /package/src/components/{json-editor-with-variables → coze-editor-extensions}/styles.tsx +0 -0
@@ -3,7 +3,7 @@
3
3
  * SPDX-License-Identifier: MIT
4
4
  */
5
5
 
6
- import React, { useMemo } from 'react';
6
+ import React, { useMemo, useEffect, useState } from 'react';
7
7
 
8
8
  import { isPlainObject, last } from 'lodash-es';
9
9
  import {
@@ -13,10 +13,18 @@ import {
13
13
  type BaseVariableField,
14
14
  useScopeAvailable,
15
15
  } from '@flowgram.ai/editor';
16
- import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
17
- import { Tree } from '@douyinfe/semi-ui';
18
-
19
- import { FlowValueUtils } from '@/shared';
16
+ import {
17
+ Mention,
18
+ MentionOpenChangeEvent,
19
+ getCurrentMentionReplaceRange,
20
+ useEditor,
21
+ PositionMirror,
22
+ } from '@flowgram.ai/coze-editor/react';
23
+ import { EditorAPI } from '@flowgram.ai/coze-editor/preset-prompt';
24
+ import { type TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
25
+ import { Tree, Popover } from '@douyinfe/semi-ui';
26
+
27
+ import { IFlowValue, FlowValueUtils } from '@/shared';
20
28
 
21
29
  type VariableField = BaseVariableField<{ icon?: string | JSX.Element; title?: string }>;
22
30
 
@@ -115,3 +123,85 @@ export function InputsPicker({
115
123
 
116
124
  return <Tree treeData={treeData} onSelect={(v) => onSelect(v)} />;
117
125
  }
126
+
127
+ const DEFAULT_TRIGGER_CHARACTERS = ['{', '{}', '@'];
128
+
129
+ export function InputsTree({
130
+ inputsValues,
131
+ triggerCharacters = DEFAULT_TRIGGER_CHARACTERS,
132
+ }: {
133
+ inputsValues: Record<string, IFlowValue>;
134
+ triggerCharacters?: string[];
135
+ }) {
136
+ const [posKey, setPosKey] = useState('');
137
+ const [visible, setVisible] = useState(false);
138
+ const [position, setPosition] = useState(-1);
139
+ const editor = useEditor<EditorAPI>();
140
+
141
+ function insert(variablePath: string) {
142
+ const range = getCurrentMentionReplaceRange(editor.$view.state);
143
+
144
+ if (!range) {
145
+ return;
146
+ }
147
+
148
+ /**
149
+ * When user input {{xxxx}}, {{{xxx}}}(more brackets if possible), replace all brackets with {{xxxx}}
150
+ */
151
+ let { from, to } = range;
152
+ while (editor.$view.state.doc.sliceString(from - 1, from) === '{') {
153
+ from--;
154
+ }
155
+ while (editor.$view.state.doc.sliceString(to, to + 1) === '}') {
156
+ to++;
157
+ }
158
+
159
+ editor.replaceText({
160
+ ...range,
161
+ text: '{{' + variablePath + '}}',
162
+ });
163
+
164
+ setVisible(false);
165
+ }
166
+
167
+ function handleOpenChange(e: MentionOpenChangeEvent) {
168
+ setPosition(e.state.selection.main.head);
169
+ setVisible(e.value);
170
+ }
171
+
172
+ useEffect(() => {
173
+ if (!editor) {
174
+ return;
175
+ }
176
+ }, [editor, visible]);
177
+
178
+ return (
179
+ <>
180
+ <Mention triggerCharacters={triggerCharacters} onOpenChange={handleOpenChange} />
181
+
182
+ <Popover
183
+ visible={visible}
184
+ trigger="custom"
185
+ position="topLeft"
186
+ rePosKey={posKey}
187
+ content={
188
+ <div style={{ width: 300, maxHeight: 300, overflowY: 'auto' }}>
189
+ <InputsPicker
190
+ inputsValues={inputsValues}
191
+ onSelect={(v) => {
192
+ insert(v);
193
+ }}
194
+ />
195
+ </div>
196
+ }
197
+ >
198
+ {/* PositionMirror allows the Popover to appear at the specified cursor position */}
199
+ <PositionMirror
200
+ position={position}
201
+ // When Doc scroll, update position
202
+ onChange={() => setPosKey(String(Math.random()))}
203
+ />
204
+ </Popover>
205
+ </>
206
+ );
207
+ }
@@ -63,10 +63,13 @@ class VariableTagWidget extends WidgetType {
63
63
  return;
64
64
  }
65
65
 
66
- const rootField = last(v.parentFields);
66
+ const rootField = last(v.parentFields) || v;
67
+ const isRoot = v === rootField;
67
68
 
68
69
  const rootTitle = (
69
- <UIRootTitle>{rootField?.meta.title ? `${rootField.meta.title} -` : ''}</UIRootTitle>
70
+ <UIRootTitle>
71
+ {rootField.meta?.title ? `${rootField.meta.title} ${isRoot ? '' : '-'} ` : ''}
72
+ </UIRootTitle>
70
73
  );
71
74
  const rootIcon = this.renderIcon(rootField?.meta.icon);
72
75
 
@@ -82,7 +85,7 @@ class VariableTagWidget extends WidgetType {
82
85
  >
83
86
  <UITag prefixIcon={rootIcon}>
84
87
  {rootTitle}
85
- <UIVarName>{v?.key}</UIVarName>
88
+ {!isRoot && <UIVarName>{v?.key}</UIVarName>}
86
89
  </UITag>
87
90
  </Popover>
88
91
  );
@@ -17,7 +17,13 @@ import { Popover, Tree } from '@douyinfe/semi-ui';
17
17
 
18
18
  import { useVariableTree } from '@/components/variable-selector';
19
19
 
20
- export function VariableTree() {
20
+ const DEFAULT_TRIGGER_CHARACTER = ['{', '{}', '@'];
21
+
22
+ export function VariableTree({
23
+ triggerCharacters = DEFAULT_TRIGGER_CHARACTER,
24
+ }: {
25
+ triggerCharacters?: string[];
26
+ }) {
21
27
  const [posKey, setPosKey] = useState('');
22
28
  const [visible, setVisible] = useState(false);
23
29
  const [position, setPosition] = useState(-1);
@@ -65,7 +71,7 @@ export function VariableTree() {
65
71
 
66
72
  return (
67
73
  <>
68
- <Mention triggerCharacters={['{', '{}', '@']} onOpenChange={handleOpenChange} />
74
+ <Mention triggerCharacters={triggerCharacters} onOpenChange={handleOpenChange} />
69
75
 
70
76
  <Popover
71
77
  visible={visible}
@@ -73,9 +79,12 @@ export function VariableTree() {
73
79
  position="topLeft"
74
80
  rePosKey={posKey}
75
81
  content={
76
- <div style={{ width: 300 }}>
82
+ <div style={{ width: 300, maxHeight: 300, overflowY: 'auto' }}>
77
83
  <Tree
78
84
  treeData={treeData}
85
+ onExpand={(v) => {
86
+ setPosKey(String(Math.random()));
87
+ }}
79
88
  onSelect={(v) => {
80
89
  insert(v);
81
90
  }}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { lazy } from 'react';
7
+
8
+ import { createInjectMaterial } from '@/shared';
9
+
10
+ export const EditorVariableTree = createInjectMaterial(
11
+ lazy(() =>
12
+ import('./extensions/variable-tree').then((module) => ({ default: module.VariableTree }))
13
+ ),
14
+ {
15
+ renderKey: 'EditorVariableTree',
16
+ }
17
+ );
18
+
19
+ export const EditorVariableTagInject = createInjectMaterial(
20
+ lazy(() =>
21
+ import('./extensions/variable-tag').then((module) => ({ default: module.VariableTagInject }))
22
+ ),
23
+ {
24
+ renderKey: 'EditorVariableTagInject',
25
+ }
26
+ );
27
+
28
+ export const EditorInputsTree = createInjectMaterial(
29
+ lazy(() => import('./extensions/inputs-tree').then((module) => ({ default: module.InputsTree }))),
30
+ {
31
+ renderKey: 'EditorInputsTree',
32
+ }
33
+ );
@@ -6,14 +6,27 @@
6
6
  import React, { useMemo } from 'react';
7
7
 
8
8
  import { I18n } from '@flowgram.ai/editor';
9
- import { Input } from '@douyinfe/semi-ui';
9
+ import { Button, Icon, Input, Select } from '@douyinfe/semi-ui';
10
+ import { IconChevronDownStroked } from '@douyinfe/semi-icons';
10
11
 
12
+ import { useTypeManager } from '@/plugins';
11
13
  import { InjectDynamicValueInput } from '@/components/dynamic-value-input';
14
+ import {
15
+ useCondition,
16
+ type ConditionOpConfigs,
17
+ type IConditionRule,
18
+ } from '@/components/condition-context';
12
19
 
13
- import { DBConditionOptionType, DBConditionRowValueType, IRules, OpConfigs } from './types';
14
- import { UIContainer, UILeft, UIOperator, UIRight, UIValues } from './styles';
15
- import { useOp } from './hooks/use-op';
16
- import { useLeft } from './hooks/use-left';
20
+ import { DBConditionOptionType, DBConditionRowValueType } from './types';
21
+ import {
22
+ UIContainer,
23
+ UILeft,
24
+ UIOperator,
25
+ UIOptionLabel,
26
+ UIRight,
27
+ UISelect,
28
+ UIValues,
29
+ } from './styles';
17
30
 
18
31
  interface PropTypes {
19
32
  value?: DBConditionRowValueType;
@@ -22,8 +35,8 @@ interface PropTypes {
22
35
  options?: DBConditionOptionType[];
23
36
  readonly?: boolean;
24
37
  ruleConfig?: {
25
- ops?: OpConfigs;
26
- rules?: IRules;
38
+ ops?: ConditionOpConfigs;
39
+ rules?: Record<string, IConditionRule>;
27
40
  };
28
41
  }
29
42
 
@@ -42,26 +55,65 @@ export function DBConditionRow({
42
55
  }: PropTypes) {
43
56
  const { left, operator, right } = value || {};
44
57
 
45
- const { rule, renderDBOptionSelect } = useLeft({
46
- left,
47
- options,
48
- onChange: (leftKey) => onChange({ ...value, left: leftKey }),
49
- readonly,
50
- userRules: ruleConfig.rules,
51
- });
58
+ const typeManager = useTypeManager();
59
+
60
+ const leftSchema = useMemo(
61
+ () => options?.find((item) => item.value === left)?.schema,
62
+ [left, options]
63
+ );
52
64
 
53
- const { renderOpSelect, opConfig } = useOp({
54
- rule,
55
- op: operator,
56
- onChange: (v) => onChange({ ...value, operator: v }),
57
- readonly,
58
- userOps: ruleConfig.ops,
65
+ const { opConfig, rule, opOptionList, targetSchema } = useCondition({
66
+ leftSchema,
67
+ operator,
68
+ ruleConfig,
59
69
  });
60
70
 
61
- const targetSchema = useMemo(() => {
62
- const targetType: string | null = rule?.[operator || ''] || null;
63
- return targetType ? { type: targetType, extra: { weak: true } } : null;
64
- }, [rule, opConfig]);
71
+ const renderDBOptionSelect = () => (
72
+ <UISelect
73
+ disabled={readonly}
74
+ size="small"
75
+ style={{ width: '100%' }}
76
+ value={left}
77
+ onChange={(v) =>
78
+ onChange({
79
+ ...value,
80
+ left: v as string,
81
+ })
82
+ }
83
+ optionList={
84
+ options?.map((item) => ({
85
+ label: (
86
+ <UIOptionLabel>
87
+ <Icon size="small" svg={typeManager.getDisplayIcon(item.schema)} />
88
+ {item.label}
89
+ </UIOptionLabel>
90
+ ),
91
+ value: item.value,
92
+ })) || []
93
+ }
94
+ />
95
+ );
96
+
97
+ const renderOpSelect = () => (
98
+ <Select
99
+ style={{ height: 22 }}
100
+ disabled={readonly}
101
+ size="small"
102
+ value={operator}
103
+ optionList={opOptionList}
104
+ onChange={(v) => {
105
+ onChange({
106
+ ...value,
107
+ operator: v as string,
108
+ });
109
+ }}
110
+ triggerRender={({ value }) => (
111
+ <Button size="small" disabled={!rule}>
112
+ {opConfig?.abbreviation || <IconChevronDownStroked size="small" />}
113
+ </Button>
114
+ )}
115
+ />
116
+ );
65
117
 
66
118
  return (
67
119
  <UIContainer style={style}>
@@ -7,19 +7,6 @@ import { IJsonSchema } from '@flowgram.ai/json-schema';
7
7
 
8
8
  import { IFlowConstantRefValue } from '@/shared';
9
9
 
10
- export interface OpConfig {
11
- label: string;
12
- abbreviation: string;
13
- // When right is not a value, display this text
14
- rightDisplay?: string;
15
- }
16
-
17
- export type OpConfigs = Record<string, OpConfig>;
18
-
19
- export type IRule = Partial<Record<string, string | null>>;
20
-
21
- export type IRules = Record<string, IRule>;
22
-
23
10
  export interface DBConditionRowValueType {
24
11
  left?: string;
25
12
  schema?: IJsonSchema;
@@ -5,9 +5,11 @@
5
5
 
6
6
  import React from 'react';
7
7
 
8
- import { IJsonSchema, JsonSchemaTypeManager } from '@flowgram.ai/json-schema';
9
-
10
- import { useTypeManager } from '@/plugins';
8
+ import {
9
+ type IJsonSchema,
10
+ type JsonSchemaTypeManager,
11
+ useTypeManager,
12
+ } from '@flowgram.ai/json-schema';
11
13
 
12
14
  import { HorizontalLine, TreeItem, TreeLevel, TreeRow, TreeTitle } from './styles';
13
15
 
@@ -33,7 +35,7 @@ function SchemaTree(props: PropsType) {
33
35
  parentKey = '',
34
36
  } = props || {};
35
37
 
36
- const typeManager = useTypeManager();
38
+ const typeManager = useTypeManager() as JsonSchemaTypeManager;
37
39
 
38
40
  const config = typeManager.getTypeBySchema(schema);
39
41
  const title = typeManager.getComplexText(schema);
@@ -8,10 +8,34 @@ export { AssignRows } from './assign-rows';
8
8
  export { BatchOutputs } from './batch-outputs';
9
9
  export { BatchVariableSelector } from './batch-variable-selector';
10
10
  export { BlurInput } from './blur-input';
11
- export { CodeEditor, type CodeEditorPropsType } from './code-editor';
11
+ export {
12
+ BaseCodeEditor,
13
+ CodeEditor,
14
+ JsonCodeEditor,
15
+ PythonCodeEditor,
16
+ SQLCodeEditor,
17
+ ShellCodeEditor,
18
+ TypeScriptCodeEditor,
19
+ type CodeEditorPropsType,
20
+ } from './code-editor';
12
21
  export { CodeEditorMini } from './code-editor-mini';
22
+ export {
23
+ ConditionPresetOp,
24
+ ConditionProvider,
25
+ type ConditionOpConfig,
26
+ type ConditionOpConfigs,
27
+ type IConditionRule,
28
+ type IConditionRuleFactory,
29
+ useCondition,
30
+ useConditionContext,
31
+ } from './condition-context';
13
32
  export { ConditionRow, type ConditionRowValueType } from './condition-row';
14
33
  export { ConstantInput, type ConstantInputStrategy } from './constant-input';
34
+ export {
35
+ EditorInputsTree,
36
+ EditorVariableTagInject,
37
+ EditorVariableTree,
38
+ } from './coze-editor-extensions';
15
39
  export {
16
40
  DBConditionRow,
17
41
  type DBConditionOptionType,
@@ -39,6 +63,10 @@ export {
39
63
  PromptEditorWithVariables,
40
64
  type PromptEditorWithVariablesProps,
41
65
  } from './prompt-editor-with-variables';
66
+ export {
67
+ SQLEditorWithVariables,
68
+ type SQLEditorWithVariablesProps,
69
+ } from './sql-editor-with-variables';
42
70
  export {
43
71
  InjectTypeSelector,
44
72
  TypeSelector,
@@ -9,10 +9,10 @@ import { I18n } from '@flowgram.ai/editor';
9
9
  import { transformerCreator } from '@flowgram.ai/coze-editor/preset-code';
10
10
  import { Text } from '@flowgram.ai/coze-editor/language-json';
11
11
 
12
- import { CodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
12
+ import { EditorVariableTree, EditorVariableTagInject } from '@/components/coze-editor-extensions';
13
+ import { JsonCodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
13
14
 
14
- import { VariableTree } from './extensions/variable-tree';
15
- import { VariableTagInject } from './extensions/variable-tag';
15
+ const TRIGGER_CHARACTERS = ['@'];
16
16
 
17
17
  type Match = { match: string; range: [number, number] };
18
18
  function findAllMatches(inputString: string, regex: RegExp): Match[] {
@@ -53,8 +53,7 @@ export interface JsonEditorWithVariablesProps extends Omit<CodeEditorPropsType,
53
53
 
54
54
  export function JsonEditorWithVariables(props: JsonEditorWithVariablesProps) {
55
55
  return (
56
- <CodeEditor
57
- languageId="json"
56
+ <JsonCodeEditor
58
57
  activeLinePlaceholder={I18n.t("Press '@' to Select variable")}
59
58
  {...props}
60
59
  options={{
@@ -62,8 +61,8 @@ export function JsonEditorWithVariables(props: JsonEditorWithVariablesProps) {
62
61
  ...(props.options || {}),
63
62
  }}
64
63
  >
65
- <VariableTree />
66
- <VariableTagInject />
67
- </CodeEditor>
64
+ <EditorVariableTree triggerCharacters={TRIGGER_CHARACTERS} />
65
+ <EditorVariableTagInject />
66
+ </JsonCodeEditor>
68
67
  );
69
68
  }
@@ -6,8 +6,7 @@
6
6
  import React from 'react';
7
7
 
8
8
  import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
9
-
10
- import { InputsTree } from './extensions/inputs-tree';
9
+ import { EditorInputsTree } from '@/components/coze-editor-extensions';
11
10
 
12
11
  export interface PromptEditorWithInputsProps extends PromptEditorPropsType {
13
12
  inputsValues: any;
@@ -19,7 +18,7 @@ export function PromptEditorWithInputs({
19
18
  }: PromptEditorWithInputsProps) {
20
19
  return (
21
20
  <PromptEditor {...restProps}>
22
- <InputsTree inputsValues={inputsValues} />
21
+ <EditorInputsTree inputsValues={inputsValues} />
23
22
  </PromptEditor>
24
23
  );
25
24
  }
@@ -6,17 +6,15 @@
6
6
  import React from 'react';
7
7
 
8
8
  import { PromptEditor, PromptEditorPropsType } from '@/components/prompt-editor';
9
-
10
- import { VariableTree } from './extensions/variable-tree';
11
- import { VariableTagInject } from './extensions/variable-tag';
9
+ import { EditorVariableTree, EditorVariableTagInject } from '@/components/coze-editor-extensions';
12
10
 
13
11
  export interface PromptEditorWithVariablesProps extends PromptEditorPropsType {}
14
12
 
15
13
  export function PromptEditorWithVariables(props: PromptEditorWithVariablesProps) {
16
14
  return (
17
15
  <PromptEditor {...props}>
18
- <VariableTree />
19
- <VariableTagInject />
16
+ <EditorVariableTree />
17
+ <EditorVariableTagInject />
20
18
  </PromptEditor>
21
19
  );
22
20
  }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import React from 'react';
7
+
8
+ import { I18n } from '@flowgram.ai/editor';
9
+
10
+ import { EditorVariableTree, EditorVariableTagInject } from '@/components/coze-editor-extensions';
11
+ import { SQLCodeEditor, type CodeEditorPropsType } from '@/components/code-editor';
12
+
13
+ export interface SQLEditorWithVariablesProps extends Omit<CodeEditorPropsType, 'languageId'> {}
14
+
15
+ export function SQLEditorWithVariables(props: SQLEditorWithVariablesProps) {
16
+ return (
17
+ <SQLCodeEditor
18
+ activeLinePlaceholder={I18n.t("Press '@' to Select variable")}
19
+ {...props}
20
+ options={{
21
+ ...(props.options || {}),
22
+ }}
23
+ >
24
+ <EditorVariableTree />
25
+ <EditorVariableTagInject />
26
+ </SQLCodeEditor>
27
+ );
28
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ import { lazySuspense } from '@/shared';
7
+
8
+ export const SQLEditorWithVariables = lazySuspense(() =>
9
+ import('./editor').then((module) => ({ default: module.SQLEditorWithVariables }))
10
+ );
11
+
12
+ export type { SQLEditorWithVariablesProps } from './editor';
@@ -5,11 +5,10 @@
5
5
 
6
6
  import React, { useMemo } from 'react';
7
7
 
8
- import { IJsonSchema } from '@flowgram.ai/json-schema';
8
+ import { IJsonSchema, useTypeManager, JsonSchemaTypeManager } from '@flowgram.ai/json-schema';
9
9
  import { Cascader, Icon, IconButton } from '@douyinfe/semi-ui';
10
10
 
11
11
  import { createInjectMaterial } from '@/shared/inject-material';
12
- import { useTypeManager } from '@/plugins';
13
12
 
14
13
  export interface TypeSelectorProps {
15
14
  value?: Partial<IJsonSchema>;
@@ -47,7 +46,7 @@ export function TypeSelector(props: TypeSelectorProps) {
47
46
 
48
47
  const selectValue = useMemo(() => getTypeSelectValue(value), [value]);
49
48
 
50
- const typeManager = useTypeManager();
49
+ const typeManager = useTypeManager() as JsonSchemaTypeManager;
51
50
 
52
51
  const icon = typeManager.getDisplayIcon(value || {});
53
52
 
@@ -7,8 +7,8 @@ import React, { useMemo } from 'react';
7
7
 
8
8
  import { IJsonSchema } from '@flowgram.ai/json-schema';
9
9
  import { I18n } from '@flowgram.ai/editor';
10
- import { TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
11
- import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
10
+ import { type TriggerRenderProps } from '@douyinfe/semi-ui/lib/es/treeSelect';
11
+ import { type TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
12
12
  import { Popover } from '@douyinfe/semi-ui';
13
13
  import { IconChevronDownStroked, IconIssueStroked } from '@douyinfe/semi-icons';
14
14
 
@@ -5,13 +5,16 @@
5
5
 
6
6
  import React, { useCallback } from 'react';
7
7
 
8
- import { IJsonSchema, JsonSchemaUtils } from '@flowgram.ai/json-schema';
8
+ import {
9
+ IJsonSchema,
10
+ JsonSchemaTypeManager,
11
+ JsonSchemaUtils,
12
+ useTypeManager,
13
+ } from '@flowgram.ai/json-schema';
9
14
  import { ASTMatch, BaseVariableField, useAvailableVariables } from '@flowgram.ai/editor';
10
15
  import { TreeNodeData } from '@douyinfe/semi-ui/lib/es/tree';
11
16
  import { Icon } from '@douyinfe/semi-ui';
12
17
 
13
- import { useTypeManager } from '@/plugins';
14
-
15
18
  type VariableField = BaseVariableField<{
16
19
  icon?: string | JSX.Element;
17
20
  title?: string;
@@ -25,7 +28,7 @@ export function useVariableTree(params: {
25
28
  }): TreeNodeData[] {
26
29
  const { includeSchema, excludeSchema, skipVariable } = params;
27
30
 
28
- const typeManager = useTypeManager();
31
+ const typeManager = useTypeManager() as JsonSchemaTypeManager;
29
32
  const variables = useAvailableVariables();
30
33
 
31
34
  const getVariableTypeIcon = useCallback((variable: VariableField) => {
@@ -8,7 +8,6 @@ import {
8
8
  EffectOptions,
9
9
  FlowNodeRegistry,
10
10
  createEffectFromVariableProvider,
11
- getNodeForm,
12
11
  } from '@flowgram.ai/editor';
13
12
 
14
13
  import { IFlowRefValue } from '@/shared';
@@ -19,7 +18,7 @@ export const provideBatchInputEffect: EffectOptions[] = createEffectFromVariable
19
18
  ASTFactory.createVariableDeclaration({
20
19
  key: `${ctx.node.id}_locals`,
21
20
  meta: {
22
- title: getNodeForm(ctx.node)?.getValueIn('title'),
21
+ title: ctx.node.form?.getValueIn('title'),
23
22
  icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
24
23
  },
25
24
  type: ASTFactory.createObject({
@@ -9,7 +9,6 @@ import {
9
9
  EffectOptions,
10
10
  FlowNodeRegistry,
11
11
  createEffectFromVariableProvider,
12
- getNodeForm,
13
12
  } from '@flowgram.ai/editor';
14
13
 
15
14
  export const provideJsonSchemaOutputs: EffectOptions[] = createEffectFromVariableProvider({
@@ -17,7 +16,7 @@ export const provideJsonSchemaOutputs: EffectOptions[] = createEffectFromVariabl
17
16
  ASTFactory.createVariableDeclaration({
18
17
  key: `${ctx.node.id}`,
19
18
  meta: {
20
- title: getNodeForm(ctx.node)?.getValueIn('title') || ctx.node.id,
19
+ title: ctx.node.form?.getValueIn('title') || ctx.node.id,
21
20
  icon: ctx.node.getNodeRegistry<FlowNodeRegistry>().info?.icon,
22
21
  },
23
22
  type: JsonSchemaUtils.schemaToAST(value),