@flowgram.ai/form-materials 0.1.0-alpha.13 → 0.1.0-alpha.15

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 (477) hide show
  1. package/bin/run.sh +6 -0
  2. package/dist/cjs/components/assign-row/index.js +112 -0
  3. package/dist/cjs/components/assign-row/types.js +18 -0
  4. package/dist/cjs/components/assign-rows/index.js +85 -0
  5. package/dist/cjs/components/batch-outputs/index.js +91 -0
  6. package/dist/cjs/components/batch-outputs/styles.js +60 -0
  7. package/dist/cjs/components/batch-outputs/types.js +18 -0
  8. package/dist/cjs/components/batch-variable-selector/index.js +53 -0
  9. package/dist/cjs/components/blur-input/index.js +64 -0
  10. package/dist/cjs/components/code-editor/editor.js +117 -0
  11. package/dist/cjs/components/code-editor/index.js +57 -0
  12. package/dist/cjs/components/code-editor/init-worker.js +56 -0
  13. package/dist/cjs/components/code-editor/language-features.js +21 -0
  14. package/dist/cjs/components/code-editor/theme/dark.js +188 -0
  15. package/dist/cjs/components/code-editor/theme/index.js +11 -0
  16. package/dist/cjs/components/code-editor/theme/light.js +195 -0
  17. package/dist/cjs/components/code-editor/utils.js +42 -0
  18. package/dist/cjs/components/code-editor-mini/index.js +66 -0
  19. package/dist/cjs/components/condition-row/constants.js +165 -0
  20. package/dist/cjs/components/condition-row/hooks/useOp.js +78 -0
  21. package/dist/cjs/components/condition-row/hooks/useRule.js +68 -0
  22. package/dist/cjs/components/condition-row/index.js +123 -0
  23. package/dist/cjs/components/condition-row/styles.js +77 -0
  24. package/dist/cjs/components/condition-row/types.js +52 -0
  25. package/dist/cjs/components/constant-input/index.js +80 -0
  26. package/dist/cjs/components/constant-input/types.js +18 -0
  27. package/dist/cjs/components/db-condition-row/hooks/use-left.js +86 -0
  28. package/dist/cjs/components/db-condition-row/hooks/use-op.js +79 -0
  29. package/dist/cjs/components/db-condition-row/index.js +115 -0
  30. package/dist/cjs/components/db-condition-row/styles.js +94 -0
  31. package/dist/cjs/components/db-condition-row/types.js +18 -0
  32. package/dist/cjs/components/display-flow-value/index.js +64 -0
  33. package/dist/cjs/components/display-inputs-values/index.js +76 -0
  34. package/dist/cjs/components/display-inputs-values/styles.js +51 -0
  35. package/dist/cjs/components/display-outputs/index.js +72 -0
  36. package/dist/cjs/components/display-outputs/styles.js +51 -0
  37. package/dist/cjs/components/display-schema-tag/index.js +77 -0
  38. package/dist/cjs/components/display-schema-tag/styles.js +71 -0
  39. package/dist/cjs/components/display-schema-tree/index.js +93 -0
  40. package/dist/cjs/components/display-schema-tree/styles.js +135 -0
  41. package/dist/cjs/components/dynamic-value-input/hooks.js +99 -0
  42. package/dist/cjs/components/dynamic-value-input/index.js +174 -0
  43. package/dist/cjs/components/dynamic-value-input/styles.js +107 -0
  44. package/dist/cjs/components/index.js +156 -0
  45. package/dist/cjs/components/inputs-values/index.js +112 -0
  46. package/dist/cjs/components/inputs-values/styles.js +60 -0
  47. package/dist/cjs/components/inputs-values/types.js +18 -0
  48. package/dist/cjs/components/inputs-values-tree/hooks/use-child-list.js +77 -0
  49. package/dist/cjs/components/inputs-values-tree/index.js +87 -0
  50. package/dist/cjs/components/inputs-values-tree/row.js +183 -0
  51. package/dist/cjs/components/inputs-values-tree/styles.js +177 -0
  52. package/dist/cjs/components/inputs-values-tree/types.js +18 -0
  53. package/dist/cjs/components/json-editor-with-variables/editor.js +81 -0
  54. package/dist/cjs/components/json-editor-with-variables/extensions/variable-tag.js +151 -0
  55. package/dist/cjs/components/json-editor-with-variables/extensions/variable-tree.js +97 -0
  56. package/dist/cjs/components/json-editor-with-variables/index.js +57 -0
  57. package/dist/cjs/components/json-editor-with-variables/styles.js +89 -0
  58. package/dist/cjs/components/json-schema-editor/default-value.js +54 -0
  59. package/dist/cjs/components/json-schema-editor/hooks.js +130 -0
  60. package/dist/cjs/components/json-schema-editor/index.js +246 -0
  61. package/dist/cjs/components/json-schema-editor/styles.js +231 -0
  62. package/dist/cjs/components/json-schema-editor/types.js +18 -0
  63. package/dist/cjs/components/prompt-editor/editor.js +99 -0
  64. package/dist/cjs/components/prompt-editor/extensions/jinja.js +73 -0
  65. package/dist/cjs/components/prompt-editor/extensions/language-support.js +48 -0
  66. package/dist/cjs/components/prompt-editor/extensions/markdown.js +81 -0
  67. package/dist/cjs/components/prompt-editor/index.js +57 -0
  68. package/dist/cjs/components/prompt-editor/styles.js +55 -0
  69. package/dist/cjs/components/prompt-editor/types.js +7 -0
  70. package/dist/cjs/components/prompt-editor-with-inputs/editor.js +47 -0
  71. package/dist/cjs/components/prompt-editor-with-inputs/extensions/inputs-tree.js +101 -0
  72. package/dist/cjs/components/prompt-editor-with-inputs/index.js +57 -0
  73. package/dist/cjs/components/prompt-editor-with-inputs/inputs-picker.js +104 -0
  74. package/dist/cjs/components/prompt-editor-with-variables/editor.js +49 -0
  75. package/dist/cjs/components/prompt-editor-with-variables/extensions/variable-tag.js +151 -0
  76. package/dist/cjs/components/prompt-editor-with-variables/extensions/variable-tree.js +103 -0
  77. package/dist/cjs/components/prompt-editor-with-variables/index.js +57 -0
  78. package/dist/cjs/components/prompt-editor-with-variables/styles.js +89 -0
  79. package/dist/cjs/components/type-selector/index.js +139 -0
  80. package/dist/cjs/components/variable-selector/context.js +56 -0
  81. package/dist/cjs/components/variable-selector/index.js +143 -0
  82. package/dist/cjs/components/variable-selector/styles.js +114 -0
  83. package/dist/cjs/components/variable-selector/use-variable-tree.js +100 -0
  84. package/dist/cjs/effects/auto-rename-ref/index.js +98 -0
  85. package/dist/cjs/effects/index.js +60 -0
  86. package/dist/cjs/effects/listen-ref-schema-change/index.js +57 -0
  87. package/dist/cjs/effects/listen-ref-value-change/index.js +54 -0
  88. package/dist/cjs/effects/provide-batch-input/index.js +64 -0
  89. package/dist/cjs/effects/provide-json-schema-outputs/index.js +49 -0
  90. package/dist/cjs/effects/sync-variable-title/index.js +52 -0
  91. package/dist/cjs/effects/validate-when-variable-sync/index.js +49 -0
  92. package/dist/cjs/form-plugins/batch-outputs-plugin/index.js +97 -0
  93. package/dist/cjs/form-plugins/index.js +47 -0
  94. package/dist/cjs/form-plugins/infer-assign-plugin/index.js +72 -0
  95. package/dist/cjs/form-plugins/infer-inputs-plugin/index.js +47 -0
  96. package/dist/cjs/hooks/index.js +36 -0
  97. package/dist/cjs/hooks/use-object-list/index.js +136 -0
  98. package/dist/cjs/index.js +228 -0
  99. package/dist/cjs/plugins/disable-declaration-plugin/create-disable-declaration-plugin.js +51 -0
  100. package/dist/cjs/plugins/disable-declaration-plugin/index.js +36 -0
  101. package/dist/cjs/plugins/index.js +49 -0
  102. package/dist/cjs/plugins/json-schema-preset/create-type-preset-plugin.js +49 -0
  103. package/dist/cjs/plugins/json-schema-preset/index.js +57 -0
  104. package/dist/cjs/plugins/json-schema-preset/manager.js +18 -0
  105. package/dist/cjs/plugins/json-schema-preset/type-definition/array.js +49 -0
  106. package/dist/cjs/plugins/json-schema-preset/type-definition/boolean.js +63 -0
  107. package/dist/cjs/plugins/json-schema-preset/type-definition/date-time.js +52 -0
  108. package/dist/cjs/plugins/json-schema-preset/type-definition/index.js +53 -0
  109. package/dist/cjs/plugins/json-schema-preset/type-definition/integer.js +49 -0
  110. package/dist/cjs/plugins/json-schema-preset/type-definition/number.js +49 -0
  111. package/dist/cjs/plugins/json-schema-preset/type-definition/object.js +49 -0
  112. package/dist/cjs/plugins/json-schema-preset/type-definition/string.js +54 -0
  113. package/dist/cjs/shared/flow-value/index.js +36 -0
  114. package/dist/cjs/shared/flow-value/schema.js +82 -0
  115. package/dist/cjs/shared/flow-value/types.js +18 -0
  116. package/dist/cjs/shared/flow-value/utils.js +142 -0
  117. package/dist/cjs/shared/format-legacy-refs/index.js +99 -0
  118. package/dist/cjs/shared/index.js +73 -0
  119. package/dist/cjs/shared/inject-material/index.js +65 -0
  120. package/dist/cjs/shared/lazy-suspense/index.js +58 -0
  121. package/dist/cjs/shared/polyfill-create-root/index.js +53 -0
  122. package/dist/cjs/validate/index.js +36 -0
  123. package/dist/cjs/validate/validate-flow-value/index.js +63 -0
  124. package/dist/esm/components/assign-row/index.mjs +78 -0
  125. package/dist/esm/components/assign-row/types.mjs +0 -0
  126. package/dist/esm/components/assign-rows/index.mjs +51 -0
  127. package/dist/esm/components/batch-outputs/index.mjs +57 -0
  128. package/dist/esm/components/batch-outputs/styles.mjs +13 -0
  129. package/dist/esm/components/batch-outputs/types.mjs +0 -0
  130. package/dist/esm/components/batch-variable-selector/index.mjs +19 -0
  131. package/dist/esm/components/blur-input/index.mjs +20 -0
  132. package/dist/esm/components/code-editor/editor.mjs +55 -0
  133. package/dist/esm/components/code-editor/index.mjs +5 -0
  134. package/dist/esm/components/code-editor/init-worker.mjs +19 -0
  135. package/dist/esm/components/code-editor/language-features.mjs +15 -0
  136. package/dist/esm/components/code-editor/theme/dark.mjs +154 -0
  137. package/dist/esm/components/code-editor/theme/index.mjs +5 -0
  138. package/dist/esm/components/code-editor/theme/light.mjs +161 -0
  139. package/dist/esm/components/code-editor/utils.mjs +8 -0
  140. package/dist/esm/components/code-editor-mini/index.mjs +22 -0
  141. package/dist/esm/components/condition-row/constants.mjs +128 -0
  142. package/dist/esm/components/condition-row/hooks/useOp.mjs +44 -0
  143. package/dist/esm/components/condition-row/hooks/useRule.mjs +34 -0
  144. package/dist/esm/components/condition-row/index.mjs +89 -0
  145. package/dist/esm/components/condition-row/styles.mjs +21 -0
  146. package/dist/esm/components/condition-row/types.mjs +18 -0
  147. package/dist/esm/components/constant-input/index.mjs +36 -0
  148. package/dist/esm/components/constant-input/types.mjs +0 -0
  149. package/dist/esm/components/db-condition-row/hooks/use-left.mjs +52 -0
  150. package/dist/esm/components/db-condition-row/hooks/use-op.mjs +45 -0
  151. package/dist/esm/components/db-condition-row/index.mjs +81 -0
  152. package/dist/esm/components/db-condition-row/styles.mjs +32 -0
  153. package/dist/esm/components/db-condition-row/types.mjs +0 -0
  154. package/dist/esm/components/display-flow-value/index.mjs +30 -0
  155. package/dist/esm/components/display-inputs-values/index.mjs +39 -0
  156. package/dist/esm/components/display-inputs-values/styles.mjs +7 -0
  157. package/dist/esm/components/display-outputs/index.mjs +38 -0
  158. package/dist/esm/components/display-outputs/styles.mjs +7 -0
  159. package/dist/esm/components/display-schema-tag/index.mjs +33 -0
  160. package/dist/esm/components/display-schema-tag/styles.mjs +21 -0
  161. package/dist/esm/components/display-schema-tree/index.mjs +49 -0
  162. package/dist/esm/components/display-schema-tree/styles.mjs +79 -0
  163. package/dist/esm/components/dynamic-value-input/hooks.mjs +59 -0
  164. package/dist/esm/components/dynamic-value-input/index.mjs +137 -0
  165. package/dist/esm/components/dynamic-value-input/styles.mjs +54 -0
  166. package/dist/esm/components/index.mjs +26 -0
  167. package/dist/esm/components/inputs-values/index.mjs +78 -0
  168. package/dist/esm/components/inputs-values/styles.mjs +13 -0
  169. package/dist/esm/components/inputs-values/types.mjs +0 -0
  170. package/dist/esm/components/inputs-values-tree/hooks/use-child-list.mjs +43 -0
  171. package/dist/esm/components/inputs-values-tree/index.mjs +53 -0
  172. package/dist/esm/components/inputs-values-tree/row.mjs +149 -0
  173. package/dist/esm/components/inputs-values-tree/styles.mjs +105 -0
  174. package/dist/esm/components/inputs-values-tree/types.mjs +0 -0
  175. package/dist/esm/components/json-editor-with-variables/editor.mjs +47 -0
  176. package/dist/esm/components/json-editor-with-variables/extensions/variable-tag.mjs +117 -0
  177. package/dist/esm/components/json-editor-with-variables/extensions/variable-tree.mjs +63 -0
  178. package/dist/esm/components/json-editor-with-variables/index.mjs +5 -0
  179. package/dist/esm/components/json-editor-with-variables/styles.mjs +36 -0
  180. package/dist/esm/components/json-schema-editor/default-value.mjs +20 -0
  181. package/dist/esm/components/json-schema-editor/hooks.mjs +96 -0
  182. package/dist/esm/components/json-schema-editor/index.mjs +212 -0
  183. package/dist/esm/components/json-schema-editor/styles.mjs +138 -0
  184. package/dist/esm/components/json-schema-editor/types.mjs +0 -0
  185. package/dist/esm/components/prompt-editor/editor.mjs +52 -0
  186. package/dist/esm/components/prompt-editor/extensions/jinja.mjs +39 -0
  187. package/dist/esm/components/prompt-editor/extensions/language-support.mjs +14 -0
  188. package/dist/esm/components/prompt-editor/extensions/markdown.mjs +47 -0
  189. package/dist/esm/components/prompt-editor/index.mjs +5 -0
  190. package/dist/esm/components/prompt-editor/styles.mjs +11 -0
  191. package/dist/esm/components/prompt-editor/types.mjs +1 -0
  192. package/dist/esm/components/prompt-editor-with-inputs/editor.mjs +13 -0
  193. package/dist/esm/components/prompt-editor-with-inputs/extensions/inputs-tree.mjs +67 -0
  194. package/dist/esm/components/prompt-editor-with-inputs/index.mjs +5 -0
  195. package/dist/esm/components/prompt-editor-with-inputs/inputs-picker.mjs +70 -0
  196. package/dist/esm/components/prompt-editor-with-variables/editor.mjs +15 -0
  197. package/dist/esm/components/prompt-editor-with-variables/extensions/variable-tag.mjs +117 -0
  198. package/dist/esm/components/prompt-editor-with-variables/extensions/variable-tree.mjs +69 -0
  199. package/dist/esm/components/prompt-editor-with-variables/index.mjs +5 -0
  200. package/dist/esm/components/prompt-editor-with-variables/styles.mjs +36 -0
  201. package/dist/esm/components/type-selector/index.mjs +96 -0
  202. package/dist/esm/components/variable-selector/context.mjs +16 -0
  203. package/dist/esm/components/variable-selector/index.mjs +100 -0
  204. package/dist/esm/components/variable-selector/styles.mjs +58 -0
  205. package/dist/esm/components/variable-selector/use-variable-tree.mjs +66 -0
  206. package/dist/esm/effects/auto-rename-ref/index.mjs +64 -0
  207. package/dist/esm/effects/index.mjs +8 -0
  208. package/dist/esm/effects/listen-ref-schema-change/index.mjs +23 -0
  209. package/dist/esm/effects/listen-ref-value-change/index.mjs +20 -0
  210. package/dist/esm/effects/provide-batch-input/index.mjs +30 -0
  211. package/dist/esm/effects/provide-json-schema-outputs/index.mjs +15 -0
  212. package/dist/esm/effects/sync-variable-title/index.mjs +18 -0
  213. package/dist/esm/effects/validate-when-variable-sync/index.mjs +15 -0
  214. package/dist/esm/form-plugins/batch-outputs-plugin/index.mjs +60 -0
  215. package/dist/esm/form-plugins/index.mjs +4 -0
  216. package/dist/esm/form-plugins/infer-assign-plugin/index.mjs +38 -0
  217. package/dist/esm/form-plugins/infer-inputs-plugin/index.mjs +13 -0
  218. package/dist/esm/hooks/index.mjs +2 -0
  219. package/dist/esm/hooks/use-object-list/index.mjs +102 -0
  220. package/dist/esm/index.mjs +8 -0
  221. package/dist/esm/plugins/disable-declaration-plugin/create-disable-declaration-plugin.mjs +17 -0
  222. package/dist/esm/plugins/disable-declaration-plugin/index.mjs +2 -0
  223. package/dist/esm/plugins/index.mjs +3 -0
  224. package/dist/esm/plugins/json-schema-preset/create-type-preset-plugin.mjs +15 -0
  225. package/dist/esm/plugins/json-schema-preset/index.mjs +14 -0
  226. package/dist/esm/plugins/json-schema-preset/manager.mjs +0 -0
  227. package/dist/esm/plugins/json-schema-preset/type-definition/array.mjs +15 -0
  228. package/dist/esm/plugins/json-schema-preset/type-definition/boolean.mjs +29 -0
  229. package/dist/esm/plugins/json-schema-preset/type-definition/date-time.mjs +18 -0
  230. package/dist/esm/plugins/json-schema-preset/type-definition/index.mjs +19 -0
  231. package/dist/esm/plugins/json-schema-preset/type-definition/integer.mjs +15 -0
  232. package/dist/esm/plugins/json-schema-preset/type-definition/number.mjs +15 -0
  233. package/dist/esm/plugins/json-schema-preset/type-definition/object.mjs +15 -0
  234. package/dist/esm/plugins/json-schema-preset/type-definition/string.mjs +20 -0
  235. package/dist/esm/shared/flow-value/index.mjs +2 -0
  236. package/dist/esm/shared/flow-value/schema.mjs +26 -0
  237. package/dist/esm/shared/flow-value/types.mjs +0 -0
  238. package/dist/esm/shared/flow-value/utils.mjs +108 -0
  239. package/dist/esm/shared/format-legacy-refs/index.mjs +50 -0
  240. package/dist/esm/shared/index.mjs +6 -0
  241. package/dist/esm/shared/inject-material/index.mjs +21 -0
  242. package/dist/esm/shared/lazy-suspense/index.mjs +21 -0
  243. package/dist/esm/shared/polyfill-create-root/index.mjs +16 -0
  244. package/dist/esm/validate/index.mjs +2 -0
  245. package/dist/esm/validate/validate-flow-value/index.mjs +29 -0
  246. package/dist/tsconfig.tsbuildinfo +1 -0
  247. package/dist/types/components/assign-row/index.d.ts +8 -0
  248. package/dist/types/components/assign-row/types.d.ts +20 -0
  249. package/dist/types/components/assign-rows/index.d.ts +11 -0
  250. package/dist/types/components/batch-outputs/index.d.ts +7 -0
  251. package/dist/types/components/batch-outputs/styles.d.ts +6 -0
  252. package/dist/types/components/batch-outputs/types.d.ts +18 -0
  253. package/dist/types/components/batch-variable-selector/index.d.ts +7 -0
  254. package/dist/types/components/blur-input/index.d.ts +7 -0
  255. package/dist/types/components/code-editor/editor.d.ts +23 -0
  256. package/dist/types/components/code-editor/index.d.ts +6 -0
  257. package/{src/validate/index.tsx → dist/types/components/code-editor/init-worker.d.ts} +1 -2
  258. package/{src/typings/index.ts → dist/types/components/code-editor/language-features.d.ts} +1 -2
  259. package/dist/types/components/code-editor/theme/dark.d.ts +6 -0
  260. package/{src/hooks/index.tsx → dist/types/components/code-editor/theme/index.d.ts} +1 -2
  261. package/dist/types/components/code-editor/theme/light.d.ts +6 -0
  262. package/dist/types/components/code-editor/utils.d.ts +5 -0
  263. package/dist/types/components/code-editor-mini/index.d.ts +7 -0
  264. package/dist/types/components/condition-row/constants.d.ts +7 -0
  265. package/dist/types/components/condition-row/hooks/useOp.d.ts +18 -0
  266. package/dist/types/components/condition-row/hooks/useRule.d.ts +9 -0
  267. package/dist/types/components/condition-row/index.d.ts +22 -0
  268. package/dist/types/components/condition-row/styles.d.ts +9 -0
  269. package/dist/types/components/condition-row/types.d.ts +34 -0
  270. package/dist/types/components/constant-input/index.d.ts +8 -0
  271. package/dist/types/components/constant-input/types.d.ts +16 -0
  272. package/dist/types/components/db-condition-row/hooks/use-left.d.ts +18 -0
  273. package/dist/types/components/db-condition-row/hooks/use-op.d.ts +18 -0
  274. package/dist/types/components/db-condition-row/index.d.ts +19 -0
  275. package/dist/types/components/db-condition-row/styles.d.ts +12 -0
  276. package/dist/types/components/db-condition-row/types.d.ts +25 -0
  277. package/dist/types/components/display-flow-value/index.d.ts +15 -0
  278. package/dist/types/components/display-inputs-values/index.d.ts +14 -0
  279. package/dist/types/components/display-inputs-values/styles.d.ts +5 -0
  280. package/dist/types/components/display-outputs/index.d.ts +14 -0
  281. package/dist/types/components/display-outputs/styles.d.ts +5 -0
  282. package/dist/types/components/display-schema-tag/index.d.ts +14 -0
  283. package/dist/types/components/display-schema-tag/styles.d.ts +8 -0
  284. package/dist/types/components/display-schema-tree/index.d.ts +16 -0
  285. package/dist/types/components/display-schema-tree/styles.d.ts +11 -0
  286. package/dist/types/components/dynamic-value-input/hooks.d.ts +28 -0
  287. package/dist/types/components/dynamic-value-input/index.d.ts +27 -0
  288. package/dist/types/components/dynamic-value-input/styles.d.ts +8 -0
  289. package/dist/types/components/index.d.ts +29 -0
  290. package/dist/types/components/inputs-values/index.d.ts +7 -0
  291. package/dist/types/components/inputs-values/styles.d.ts +6 -0
  292. package/dist/types/components/inputs-values/types.d.ts +19 -0
  293. package/dist/types/components/inputs-values-tree/hooks/use-child-list.d.ts +19 -0
  294. package/dist/types/components/inputs-values-tree/index.d.ts +7 -0
  295. package/dist/types/components/inputs-values-tree/row.d.ts +15 -0
  296. package/dist/types/components/inputs-values-tree/styles.d.ts +23 -0
  297. package/dist/types/components/inputs-values-tree/types.d.ts +18 -0
  298. package/dist/types/components/json-editor-with-variables/editor.d.ts +9 -0
  299. package/dist/types/components/json-editor-with-variables/extensions/variable-tag.d.ts +5 -0
  300. package/dist/types/components/json-editor-with-variables/extensions/variable-tree.d.ts +6 -0
  301. package/dist/types/components/json-editor-with-variables/index.d.ts +6 -0
  302. package/dist/types/components/json-editor-with-variables/styles.d.ts +9 -0
  303. package/dist/types/components/json-schema-editor/default-value.d.ts +17 -0
  304. package/dist/types/components/json-schema-editor/hooks.d.ts +12 -0
  305. package/dist/types/components/json-schema-editor/index.d.ts +14 -0
  306. package/dist/types/components/json-schema-editor/styles.d.ts +30 -0
  307. package/dist/types/components/json-schema-editor/types.d.ts +20 -0
  308. package/dist/types/components/prompt-editor/editor.d.ts +15 -0
  309. package/dist/types/components/prompt-editor/extensions/jinja.d.ts +6 -0
  310. package/dist/types/components/prompt-editor/extensions/language-support.d.ts +6 -0
  311. package/dist/types/components/prompt-editor/extensions/markdown.d.ts +6 -0
  312. package/dist/types/components/prompt-editor/index.d.ts +6 -0
  313. package/dist/types/components/prompt-editor/styles.d.ts +7 -0
  314. package/dist/types/components/prompt-editor/types.d.ts +16 -0
  315. package/dist/types/components/prompt-editor-with-inputs/editor.d.ts +10 -0
  316. package/dist/types/components/prompt-editor-with-inputs/extensions/inputs-tree.d.ts +9 -0
  317. package/dist/types/components/prompt-editor-with-inputs/index.d.ts +6 -0
  318. package/dist/types/components/prompt-editor-with-inputs/inputs-picker.d.ts +9 -0
  319. package/dist/types/components/prompt-editor-with-variables/editor.d.ts +9 -0
  320. package/dist/types/components/prompt-editor-with-variables/extensions/variable-tag.d.ts +5 -0
  321. package/dist/types/components/prompt-editor-with-variables/extensions/variable-tree.d.ts +6 -0
  322. package/dist/types/components/prompt-editor-with-variables/index.d.ts +6 -0
  323. package/dist/types/components/prompt-editor-with-variables/styles.d.ts +9 -0
  324. package/dist/types/components/type-selector/index.d.ts +23 -0
  325. package/dist/types/components/variable-selector/context.d.ts +16 -0
  326. package/dist/types/components/variable-selector/index.d.ts +29 -0
  327. package/dist/types/components/variable-selector/styles.d.ts +14 -0
  328. package/dist/types/components/variable-selector/use-variable-tree.d.ts +18 -0
  329. package/dist/types/effects/auto-rename-ref/index.d.ts +17 -0
  330. package/dist/types/effects/index.d.ts +11 -0
  331. package/dist/types/effects/listen-ref-schema-change/index.d.ts +22 -0
  332. package/dist/types/effects/listen-ref-value-change/index.d.ts +22 -0
  333. package/dist/types/effects/provide-batch-input/index.d.ts +6 -0
  334. package/dist/types/effects/provide-json-schema-outputs/index.d.ts +6 -0
  335. package/dist/types/effects/sync-variable-title/index.d.ts +6 -0
  336. package/dist/types/effects/validate-when-variable-sync/index.d.ts +8 -0
  337. package/dist/types/form-plugins/batch-outputs-plugin/index.d.ts +12 -0
  338. package/dist/types/form-plugins/index.d.ts +7 -0
  339. package/dist/types/form-plugins/infer-assign-plugin/index.d.ts +10 -0
  340. package/dist/types/form-plugins/infer-inputs-plugin/index.d.ts +11 -0
  341. package/dist/types/hooks/index.d.ts +5 -0
  342. package/dist/types/hooks/use-object-list/index.d.ts +22 -0
  343. package/dist/types/index.d.ts +11 -0
  344. package/dist/types/plugins/disable-declaration-plugin/create-disable-declaration-plugin.d.ts +5 -0
  345. package/dist/types/plugins/disable-declaration-plugin/index.d.ts +5 -0
  346. package/dist/types/plugins/index.d.ts +6 -0
  347. package/dist/types/plugins/json-schema-preset/create-type-preset-plugin.d.ts +9 -0
  348. package/dist/types/plugins/json-schema-preset/index.d.ts +13 -0
  349. package/dist/types/plugins/json-schema-preset/manager.d.ts +17 -0
  350. package/dist/types/plugins/json-schema-preset/type-definition/array.d.ts +6 -0
  351. package/dist/types/plugins/json-schema-preset/type-definition/boolean.d.ts +6 -0
  352. package/dist/types/plugins/json-schema-preset/type-definition/date-time.d.ts +6 -0
  353. package/dist/types/plugins/json-schema-preset/type-definition/index.d.ts +5 -0
  354. package/dist/types/plugins/json-schema-preset/type-definition/integer.d.ts +6 -0
  355. package/dist/types/plugins/json-schema-preset/type-definition/number.d.ts +6 -0
  356. package/dist/types/plugins/json-schema-preset/type-definition/object.d.ts +6 -0
  357. package/dist/types/plugins/json-schema-preset/type-definition/string.d.ts +6 -0
  358. package/dist/types/shared/flow-value/index.d.ts +6 -0
  359. package/dist/types/shared/flow-value/schema.d.ts +107 -0
  360. package/dist/types/shared/flow-value/types.d.ts +32 -0
  361. package/dist/types/shared/flow-value/utils.d.ts +65 -0
  362. package/dist/types/shared/format-legacy-refs/index.d.ts +84 -0
  363. package/dist/types/shared/index.d.ts +9 -0
  364. package/dist/types/shared/inject-material/index.d.ts +46 -0
  365. package/dist/types/shared/lazy-suspense/index.d.ts +7 -0
  366. package/dist/types/shared/polyfill-create-root/index.d.ts +10 -0
  367. package/dist/types/validate/index.d.ts +5 -0
  368. package/dist/types/validate/validate-flow-value/index.d.ts +19 -0
  369. package/package.json +22 -23
  370. package/src/components/assign-row/index.tsx +3 -3
  371. package/src/components/assign-row/types.ts +1 -1
  372. package/src/components/batch-outputs/index.tsx +3 -2
  373. package/src/components/batch-outputs/types.ts +1 -1
  374. package/src/components/code-editor/editor.tsx +97 -0
  375. package/src/components/code-editor/index.tsx +5 -89
  376. package/src/components/code-editor/init-worker.ts +27 -0
  377. package/src/components/code-editor/language-features.ts +6 -27
  378. package/src/components/code-editor/theme/dark.ts +50 -31
  379. package/src/components/code-editor/theme/index.ts +1 -1
  380. package/src/components/code-editor/theme/light.ts +57 -33
  381. package/src/components/code-editor-mini/index.tsx +2 -2
  382. package/src/components/condition-row/constants.ts +8 -0
  383. package/src/components/condition-row/hooks/useRule.ts +1 -1
  384. package/src/components/condition-row/index.tsx +4 -0
  385. package/src/components/condition-row/types.ts +1 -1
  386. package/src/components/constant-input/index.tsx +1 -1
  387. package/src/components/db-condition-row/hooks/use-left.tsx +66 -0
  388. package/src/components/db-condition-row/hooks/use-op.tsx +59 -0
  389. package/src/components/db-condition-row/index.tsx +93 -0
  390. package/src/components/db-condition-row/styles.tsx +43 -0
  391. package/src/components/db-condition-row/types.ts +34 -0
  392. package/src/components/display-flow-value/index.tsx +3 -13
  393. package/src/components/display-inputs-values/index.tsx +44 -6
  394. package/src/components/dynamic-value-input/hooks.ts +25 -4
  395. package/src/components/dynamic-value-input/index.tsx +21 -12
  396. package/src/components/dynamic-value-input/styles.tsx +14 -4
  397. package/src/components/index.ts +50 -22
  398. package/src/components/inputs-values/index.tsx +15 -4
  399. package/src/components/inputs-values/styles.tsx +1 -1
  400. package/src/components/inputs-values/types.ts +1 -1
  401. package/src/components/inputs-values-tree/hooks/use-child-list.tsx +76 -0
  402. package/src/components/inputs-values-tree/index.tsx +62 -0
  403. package/src/components/inputs-values-tree/row.tsx +177 -0
  404. package/src/components/inputs-values-tree/styles.tsx +128 -0
  405. package/src/components/inputs-values-tree/types.ts +21 -0
  406. package/src/components/json-editor-with-variables/editor.tsx +69 -0
  407. package/src/components/json-editor-with-variables/extensions/variable-tag.tsx +7 -6
  408. package/src/components/json-editor-with-variables/extensions/variable-tree.tsx +3 -3
  409. package/src/components/json-editor-with-variables/index.tsx +5 -59
  410. package/src/components/json-schema-editor/default-value.tsx +1 -3
  411. package/src/components/json-schema-editor/hooks.tsx +14 -3
  412. package/src/components/json-schema-editor/index.tsx +18 -58
  413. package/src/components/json-schema-editor/styles.tsx +12 -55
  414. package/src/components/json-schema-editor/types.ts +0 -1
  415. package/src/components/prompt-editor/editor.tsx +81 -0
  416. package/src/components/prompt-editor/extensions/jinja.tsx +2 -2
  417. package/src/components/prompt-editor/extensions/language-support.tsx +2 -2
  418. package/src/components/prompt-editor/extensions/markdown.tsx +2 -2
  419. package/src/components/prompt-editor/index.tsx +5 -62
  420. package/src/components/prompt-editor/types.tsx +1 -1
  421. package/src/components/prompt-editor-with-inputs/editor.tsx +25 -0
  422. package/src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx +15 -4
  423. package/src/components/prompt-editor-with-inputs/index.tsx +5 -16
  424. package/src/components/prompt-editor-with-inputs/inputs-picker.tsx +34 -17
  425. package/src/components/prompt-editor-with-variables/editor.tsx +22 -0
  426. package/src/components/prompt-editor-with-variables/extensions/variable-tag.tsx +13 -21
  427. package/src/components/prompt-editor-with-variables/extensions/variable-tree.tsx +16 -4
  428. package/src/components/prompt-editor-with-variables/index.tsx +5 -13
  429. package/src/components/type-selector/index.tsx +12 -2
  430. package/src/components/variable-selector/context.tsx +28 -0
  431. package/src/components/variable-selector/index.tsx +10 -1
  432. package/src/components/variable-selector/use-variable-tree.tsx +3 -3
  433. package/src/effects/auto-rename-ref/index.ts +8 -55
  434. package/src/effects/index.ts +7 -7
  435. package/src/effects/listen-ref-schema-change/index.ts +1 -1
  436. package/src/effects/listen-ref-value-change/index.ts +1 -1
  437. package/src/effects/provide-batch-input/index.ts +1 -1
  438. package/src/effects/validate-when-variable-sync/index.ts +1 -1
  439. package/src/form-plugins/batch-outputs-plugin/index.ts +1 -1
  440. package/src/form-plugins/index.ts +3 -3
  441. package/src/form-plugins/infer-assign-plugin/index.ts +2 -2
  442. package/src/form-plugins/infer-inputs-plugin/index.ts +4 -76
  443. package/src/hooks/index.ts +6 -0
  444. package/src/hooks/use-object-list/index.tsx +35 -7
  445. package/src/index.ts +98 -7
  446. package/src/plugins/index.ts +11 -2
  447. package/src/plugins/json-schema-preset/index.tsx +4 -4
  448. package/src/plugins/json-schema-preset/manager.ts +1 -0
  449. package/src/plugins/json-schema-preset/type-definition/date-time.tsx +25 -0
  450. package/src/plugins/json-schema-preset/type-definition/index.tsx +2 -0
  451. package/src/plugins/json-schema-preset/type-definition/string.tsx +18 -9
  452. package/src/shared/flow-value/index.ts +16 -0
  453. package/src/shared/flow-value/schema.ts +38 -0
  454. package/src/{typings/flow-value/index.ts → shared/flow-value/types.ts} +3 -1
  455. package/src/shared/flow-value/utils.ts +200 -0
  456. package/src/shared/format-legacy-refs/index.ts +1 -1
  457. package/src/shared/index.ts +26 -2
  458. package/src/shared/lazy-suspense/index.tsx +28 -0
  459. package/src/shared/polyfill-create-root/index.tsx +33 -0
  460. package/src/validate/index.ts +6 -0
  461. package/src/validate/validate-flow-value/index.tsx +4 -16
  462. package/bin/index.ts +0 -91
  463. package/bin/materials.ts +0 -107
  464. package/bin/project.ts +0 -95
  465. package/bin/utils/import.ts +0 -127
  466. package/bin/utils/traverse-file.ts +0 -60
  467. package/dist/esm/index.js +0 -3864
  468. package/dist/esm/index.js.map +0 -1
  469. package/dist/index.d.mts +0 -763
  470. package/dist/index.d.ts +0 -763
  471. package/dist/index.js +0 -3849
  472. package/dist/index.js.map +0 -1
  473. package/src/components/inputs-values/components/blur-input.tsx +0 -27
  474. package/src/components/json-schema-editor/components/blur-input.tsx +0 -27
  475. package/src/plugins/disable-declaration-plugin/config.json +0 -5
  476. package/src/plugins/json-schema-preset/config.json +0 -9
  477. /package/src/components/{assign-row/components/blur-input.tsx → blur-input/index.tsx} +0 -0
package/dist/esm/index.js DELETED
@@ -1,3864 +0,0 @@
1
- // src/components/variable-selector/index.tsx
2
- import React12, { useMemo } from "react";
3
- import { I18n as I18n7 } from "@flowgram.ai/editor";
4
- import { Popover } from "@douyinfe/semi-ui";
5
- import { IconChevronDownStroked, IconIssueStroked } from "@douyinfe/semi-icons";
6
-
7
- // src/shared/format-legacy-refs/index.ts
8
- import { isObject } from "lodash";
9
- function formatLegacyRefOnSubmit(value) {
10
- if (isObject(value)) {
11
- if (isLegacyFlowRefValueSchema(value)) {
12
- return formatLegacyRefToNewRef(value);
13
- }
14
- return Object.fromEntries(
15
- Object.entries(value).map(([key, value2]) => [
16
- key,
17
- formatLegacyRefOnSubmit(value2)
18
- ])
19
- );
20
- }
21
- if (Array.isArray(value)) {
22
- return value.map(formatLegacyRefOnSubmit);
23
- }
24
- return value;
25
- }
26
- function formatLegacyRefOnInit(value) {
27
- if (isObject(value)) {
28
- if (isNewFlowRefValueSchema(value)) {
29
- return formatNewRefToLegacyRef(value);
30
- }
31
- return Object.fromEntries(
32
- Object.entries(value).map(([key, value2]) => [
33
- key,
34
- formatLegacyRefOnInit(value2)
35
- ])
36
- );
37
- }
38
- if (Array.isArray(value)) {
39
- return value.map(formatLegacyRefOnInit);
40
- }
41
- return value;
42
- }
43
- function isLegacyFlowRefValueSchema(value) {
44
- return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && typeof value.content === "string";
45
- }
46
- function isNewFlowRefValueSchema(value) {
47
- return isObject(value) && Object.keys(value).length === 2 && value.type === "ref" && Array.isArray(value.content);
48
- }
49
- function formatLegacyRefToNewRef(value) {
50
- const keyPath = value.content.split(".");
51
- if (keyPath[1] === "outputs") {
52
- return {
53
- type: "ref",
54
- content: [`${keyPath[0]}.${keyPath[1]}`, ...keyPath.length > 2 ? keyPath.slice(2) : []]
55
- };
56
- }
57
- return {
58
- type: "ref",
59
- content: keyPath
60
- };
61
- }
62
- function formatNewRefToLegacyRef(value) {
63
- return {
64
- type: "ref",
65
- content: value.content.join(".")
66
- };
67
- }
68
-
69
- // src/shared/inject-material/index.tsx
70
- import React from "react";
71
- import {
72
- FlowRendererComponentType,
73
- FlowRendererRegistry,
74
- usePlaygroundContainer
75
- } from "@flowgram.ai/editor";
76
- function createInjectMaterial(Component, params) {
77
- const InjectComponent = (props) => {
78
- const container = usePlaygroundContainer();
79
- if (!container?.isBound(FlowRendererRegistry)) {
80
- return React.createElement(Component, { ...props });
81
- }
82
- const rendererRegistry = container.get(FlowRendererRegistry);
83
- const renderKey = params?.renderKey || Component.renderKey || Component.name || "";
84
- const renderer = rendererRegistry.tryToGetRendererComponent(renderKey);
85
- if (renderer?.type !== FlowRendererComponentType.REACT) {
86
- return React.createElement(Component, { ...props });
87
- }
88
- return React.createElement(renderer.renderer, {
89
- ...props
90
- });
91
- };
92
- return InjectComponent;
93
- }
94
-
95
- // src/components/variable-selector/use-variable-tree.tsx
96
- import React11, { useCallback } from "react";
97
- import { JsonSchemaUtils as JsonSchemaUtils2 } from "@flowgram.ai/json-schema";
98
- import { ASTMatch as ASTMatch2, useAvailableVariables } from "@flowgram.ai/editor";
99
- import { Icon } from "@douyinfe/semi-ui";
100
-
101
- // src/plugins/json-schema-preset/index.tsx
102
- import React10 from "react";
103
- import {
104
- JsonSchemaUtils,
105
- useTypeManager as useOriginTypeManager,
106
- TypePresetProvider as OriginTypePresetProvider
107
- } from "@flowgram.ai/json-schema";
108
-
109
- // src/plugins/json-schema-preset/type-definition/index.tsx
110
- import { jsonSchemaTypeManager } from "@flowgram.ai/json-schema";
111
-
112
- // src/plugins/json-schema-preset/type-definition/string.tsx
113
- import React2 from "react";
114
- import { I18n } from "@flowgram.ai/editor";
115
- import { Input } from "@douyinfe/semi-ui";
116
- var stringRegistry = {
117
- type: "string",
118
- ConstantRenderer: (props) => /* @__PURE__ */ React2.createElement(
119
- Input,
120
- {
121
- placeholder: I18n.t("Please Input String"),
122
- size: "small",
123
- disabled: props.readonly,
124
- ...props
125
- }
126
- )
127
- };
128
-
129
- // src/plugins/json-schema-preset/type-definition/object.tsx
130
- import React5 from "react";
131
- import { I18n as I18n2 } from "@flowgram.ai/editor";
132
-
133
- // src/components/code-editor-mini/index.tsx
134
- import React4 from "react";
135
- import styled from "styled-components";
136
-
137
- // src/components/code-editor/index.tsx
138
- import React3, { useEffect, useRef } from "react";
139
- import {
140
- ActiveLinePlaceholder,
141
- createRenderer,
142
- EditorProvider
143
- } from "@coze-editor/editor/react";
144
- import preset from "@coze-editor/editor/preset-code";
145
- import { EditorView } from "@codemirror/view";
146
-
147
- // src/components/code-editor/utils.ts
148
- function getSuffixByLanguageId(languageId) {
149
- if (languageId === "python") {
150
- return ".py";
151
- }
152
- if (languageId === "typescript") {
153
- return ".ts";
154
- }
155
- if (languageId === "shell") {
156
- return ".sh";
157
- }
158
- if (languageId === "json") {
159
- return ".json";
160
- }
161
- return "";
162
- }
163
-
164
- // src/components/code-editor/language-features.ts
165
- import { languages } from "@coze-editor/editor/preset-code";
166
- import { typescript } from "@coze-editor/editor/language-typescript";
167
- import { shell } from "@coze-editor/editor/language-shell";
168
- import { python } from "@coze-editor/editor/language-python";
169
- import { json } from "@coze-editor/editor/language-json";
170
- import { mixLanguages } from "@coze-editor/editor";
171
- languages.register("python", python);
172
- languages.register("shell", shell);
173
- languages.register("typescript", typescript);
174
- languages.register("json", {
175
- // mixLanguages is used to solve the problem that interpolation also uses parentheses, which causes incorrect highlighting
176
- language: mixLanguages({
177
- outerLanguage: json.language
178
- }),
179
- languageService: json.languageService
180
- });
181
- var tsWorkerInit = false;
182
- var initTsWorker = () => {
183
- if (tsWorkerInit) {
184
- return;
185
- }
186
- tsWorkerInit = true;
187
- const tsWorker = new Worker(
188
- new URL(`@coze-editor/editor/language-typescript/worker`, import.meta.url),
189
- { type: "module" }
190
- );
191
- typescript.languageService.initialize(tsWorker, {
192
- compilerOptions: {
193
- // eliminate Promise error
194
- lib: ["es2015", "dom"],
195
- noImplicitAny: false
196
- }
197
- });
198
- };
199
-
200
- // src/components/code-editor/theme/index.ts
201
- import { themes } from "@coze-editor/editor/preset-code";
202
-
203
- // src/components/code-editor/theme/light.ts
204
- import { createTheme, tags as t } from "@coze-editor/editor/preset-code";
205
- var colors = {
206
- background: "#F7F7FC",
207
- // syntax
208
- comment: "#000A298A",
209
- key: "#00818C",
210
- string: "#D1009D",
211
- number: "#C74200",
212
- boolean: "#2B57D9",
213
- null: "#2B57D9",
214
- separator: "#0F1529D1"
215
- };
216
- var lightTheme = createTheme({
217
- variant: "light",
218
- settings: {
219
- background: "#fff",
220
- foreground: "#000",
221
- caret: "#000",
222
- selection: "#d9d9d9",
223
- gutterBackground: "#f0f0f0",
224
- gutterForeground: "#666",
225
- gutterBorderColor: "transparent",
226
- gutterBorderWidth: 0,
227
- lineHighlight: "#e1e1e180",
228
- bracketColors: ["#FFD700", "#DD99FF", "#78B0FF"],
229
- tooltip: {
230
- backgroundColor: "#f0f0f0",
231
- color: "#000",
232
- border: "1px solid #ccc"
233
- },
234
- link: {
235
- color: "#007bff"
236
- },
237
- completionItemHover: {
238
- backgroundColor: "#f0f0f0"
239
- },
240
- completionItemSelected: {
241
- backgroundColor: "#e0e0e0"
242
- },
243
- completionItemIcon: {
244
- color: "#333"
245
- },
246
- completionItemLabel: {
247
- color: "#333"
248
- },
249
- completionItemInfo: {
250
- color: "#333"
251
- },
252
- completionItemDetail: {
253
- color: "#666"
254
- }
255
- },
256
- styles: [
257
- // JSON
258
- {
259
- tag: t.comment,
260
- color: colors.comment
261
- },
262
- {
263
- tag: [t.propertyName],
264
- color: colors.key
265
- },
266
- {
267
- tag: [t.string],
268
- color: colors.string
269
- },
270
- {
271
- tag: [t.number],
272
- color: colors.number
273
- },
274
- {
275
- tag: [t.bool],
276
- color: colors.boolean
277
- },
278
- {
279
- tag: [t.null],
280
- color: colors.null
281
- },
282
- {
283
- tag: [t.separator],
284
- color: colors.separator
285
- },
286
- // markdown
287
- {
288
- tag: [t.heading],
289
- color: "#3e76ef"
290
- },
291
- {
292
- tag: [t.processingInstruction],
293
- color: "#3e76ef"
294
- },
295
- // shell
296
- // curl
297
- {
298
- tag: [t.standard(t.variableName)],
299
- color: "#00804A"
300
- },
301
- // -X
302
- {
303
- tag: [t.attributeName],
304
- color: "#C74200"
305
- },
306
- // url in string (includes quotes), e.g. "https://..."
307
- {
308
- tag: [t.special(t.string)],
309
- color: "#2B57D9"
310
- }
311
- ]
312
- });
313
-
314
- // src/components/code-editor/theme/dark.ts
315
- import { createTheme as createTheme2, tags as t2 } from "@coze-editor/editor/preset-code";
316
- var colors2 = {
317
- background: "#151B27",
318
- // syntax
319
- comment: "#FFFFFF63",
320
- key: "#39E5D7",
321
- string: "#FF94D2",
322
- number: "#FF9933",
323
- boolean: "#78B0FF",
324
- null: "#78B0FF",
325
- separator: "#FFFFFFC9"
326
- };
327
- var darkTheme = createTheme2({
328
- variant: "dark",
329
- settings: {
330
- background: colors2.background,
331
- foreground: "#fff",
332
- caret: "#AEAFAD",
333
- selection: "#d9d9d942",
334
- gutterBackground: colors2.background,
335
- gutterForeground: "#FFFFFF63",
336
- gutterBorderColor: "transparent",
337
- gutterBorderWidth: 0,
338
- lineHighlight: "#272e3d36",
339
- bracketColors: ["#FFEF61", "#DD99FF", "#78B0FF"],
340
- tooltip: {
341
- backgroundColor: "#363D4D",
342
- color: "#fff",
343
- border: "none"
344
- },
345
- link: {
346
- color: "#4daafc"
347
- },
348
- completionItemHover: {
349
- backgroundColor: "#FFFFFF0F"
350
- },
351
- completionItemSelected: {
352
- backgroundColor: "#FFFFFF17"
353
- },
354
- completionItemIcon: {
355
- color: "#FFFFFFC9"
356
- },
357
- completionItemLabel: {
358
- color: "#FFFFFFC9"
359
- },
360
- completionItemInfo: {
361
- color: "#FFFFFFC9"
362
- },
363
- completionItemDetail: {
364
- color: "#FFFFFF63"
365
- }
366
- },
367
- styles: [
368
- // json
369
- {
370
- tag: t2.comment,
371
- color: colors2.comment
372
- },
373
- {
374
- tag: [t2.propertyName],
375
- color: colors2.key
376
- },
377
- {
378
- tag: [t2.string],
379
- color: colors2.string
380
- },
381
- {
382
- tag: [t2.number],
383
- color: colors2.number
384
- },
385
- {
386
- tag: [t2.bool],
387
- color: colors2.boolean
388
- },
389
- {
390
- tag: [t2.null],
391
- color: colors2.null
392
- },
393
- {
394
- tag: [t2.separator],
395
- color: colors2.separator
396
- },
397
- // markdown
398
- {
399
- tag: [t2.heading],
400
- color: "#6b6bff"
401
- },
402
- {
403
- tag: [t2.processingInstruction],
404
- color: "#6b6bff"
405
- },
406
- // shell
407
- // curl
408
- {
409
- tag: [t2.standard(t2.variableName)],
410
- color: "#3BEB84"
411
- },
412
- // -X
413
- {
414
- tag: [t2.attributeName],
415
- color: "#FF9933"
416
- },
417
- // url in string (includes quotes), e.g. "https://..."
418
- {
419
- tag: [t2.special(t2.string)],
420
- color: "#78B0FF"
421
- }
422
- ]
423
- });
424
-
425
- // src/components/code-editor/theme/index.ts
426
- themes.register("dark", darkTheme);
427
- themes.register("light", lightTheme);
428
-
429
- // src/components/code-editor/index.tsx
430
- var OriginCodeEditor = createRenderer(preset, [
431
- EditorView.theme({
432
- "&.cm-focused": {
433
- outline: "none"
434
- }
435
- })
436
- ]);
437
- function CodeEditor({
438
- value,
439
- onChange,
440
- languageId = "python",
441
- theme = "light",
442
- children,
443
- placeholder,
444
- activeLinePlaceholder,
445
- options,
446
- readonly
447
- }) {
448
- const editorRef = useRef(null);
449
- useEffect(() => {
450
- if (languageId === "typescript") {
451
- initTsWorker();
452
- }
453
- }, [languageId]);
454
- useEffect(() => {
455
- if (editorRef.current?.getValue() !== value) {
456
- editorRef.current?.setValue(String(value || ""));
457
- }
458
- }, [value]);
459
- return /* @__PURE__ */ React3.createElement(EditorProvider, null, /* @__PURE__ */ React3.createElement(
460
- OriginCodeEditor,
461
- {
462
- defaultValue: value,
463
- options: {
464
- uri: `file:///untitled${getSuffixByLanguageId(languageId)}`,
465
- languageId,
466
- theme,
467
- placeholder,
468
- readOnly: readonly,
469
- editable: !readonly,
470
- ...options || {}
471
- },
472
- didMount: (editor) => {
473
- editorRef.current = editor;
474
- },
475
- onChange: (e) => onChange?.(e.value)
476
- },
477
- activeLinePlaceholder && /* @__PURE__ */ React3.createElement(ActiveLinePlaceholder, null, activeLinePlaceholder),
478
- children
479
- ));
480
- }
481
-
482
- // src/components/code-editor-mini/index.tsx
483
- var UIMini = styled.div`
484
- .ͼ1 .cm-content {
485
- padding: 0;
486
- }
487
- `;
488
- function CodeEditorMini(props) {
489
- return /* @__PURE__ */ React4.createElement(UIMini, null, /* @__PURE__ */ React4.createElement(
490
- CodeEditor,
491
- {
492
- ...props,
493
- options: {
494
- lineNumbersGutter: false,
495
- foldGutter: false,
496
- ...props.options || {}
497
- }
498
- }
499
- ));
500
- }
501
-
502
- // src/plugins/json-schema-preset/type-definition/object.tsx
503
- var objectRegistry = {
504
- type: "object",
505
- ConstantRenderer: (props) => /* @__PURE__ */ React5.createElement(
506
- CodeEditorMini,
507
- {
508
- value: props.value,
509
- onChange: (v) => props.onChange?.(v),
510
- languageId: "json",
511
- placeholder: I18n2.t("Please Input Object"),
512
- readonly: props.readonly
513
- }
514
- )
515
- };
516
-
517
- // src/plugins/json-schema-preset/type-definition/number.tsx
518
- import React6 from "react";
519
- import { I18n as I18n3 } from "@flowgram.ai/editor";
520
- import { InputNumber } from "@douyinfe/semi-ui";
521
- var numberRegistry = {
522
- type: "number",
523
- ConstantRenderer: (props) => /* @__PURE__ */ React6.createElement(
524
- InputNumber,
525
- {
526
- placeholder: I18n3.t("Please Input Number"),
527
- size: "small",
528
- disabled: props.readonly,
529
- hideButtons: true,
530
- ...props
531
- }
532
- )
533
- };
534
-
535
- // src/plugins/json-schema-preset/type-definition/integer.tsx
536
- import React7 from "react";
537
- import { I18n as I18n4 } from "@flowgram.ai/editor";
538
- import { InputNumber as InputNumber2 } from "@douyinfe/semi-ui";
539
- var integerRegistry = {
540
- type: "integer",
541
- ConstantRenderer: (props) => /* @__PURE__ */ React7.createElement(
542
- InputNumber2,
543
- {
544
- placeholder: I18n4.t("Please Input Integer"),
545
- size: "small",
546
- disabled: props.readonly,
547
- precision: 0,
548
- ...props
549
- }
550
- )
551
- };
552
-
553
- // src/plugins/json-schema-preset/type-definition/boolean.tsx
554
- import React8 from "react";
555
- import { I18n as I18n5 } from "@flowgram.ai/editor";
556
- import { Select } from "@douyinfe/semi-ui";
557
- var booleanRegistry = {
558
- type: "boolean",
559
- ConstantRenderer: (props) => {
560
- const { value, onChange, ...rest } = props;
561
- return /* @__PURE__ */ React8.createElement(
562
- Select,
563
- {
564
- placeholder: I18n5.t("Please Select Boolean"),
565
- size: "small",
566
- disabled: props.readonly,
567
- optionList: [
568
- { label: I18n5.t("True"), value: 1 },
569
- { label: I18n5.t("False"), value: 0 }
570
- ],
571
- value: value ? 1 : 0,
572
- onChange: (value2) => onChange?.(!!value2),
573
- ...rest
574
- }
575
- );
576
- }
577
- };
578
-
579
- // src/plugins/json-schema-preset/type-definition/array.tsx
580
- import React9 from "react";
581
- import { I18n as I18n6 } from "@flowgram.ai/editor";
582
- var arrayRegistry = {
583
- type: "array",
584
- ConstantRenderer: (props) => /* @__PURE__ */ React9.createElement(
585
- CodeEditorMini,
586
- {
587
- value: props.value,
588
- languageId: "json",
589
- onChange: (v) => props.onChange?.(v),
590
- placeholder: I18n6.t("Please Input Array"),
591
- readonly: props.readonly
592
- }
593
- )
594
- };
595
-
596
- // src/plugins/json-schema-preset/type-definition/index.tsx
597
- var jsonSchemaTypePreset = [
598
- stringRegistry,
599
- objectRegistry,
600
- numberRegistry,
601
- integerRegistry,
602
- booleanRegistry,
603
- arrayRegistry
604
- ];
605
- jsonSchemaTypePreset.forEach((_type) => jsonSchemaTypeManager.register(_type));
606
-
607
- // src/plugins/json-schema-preset/create-type-preset-plugin.tsx
608
- import {
609
- BaseTypeManager,
610
- jsonSchemaContainerModule
611
- } from "@flowgram.ai/json-schema";
612
- import { definePluginCreator } from "@flowgram.ai/editor";
613
- var createTypePresetPlugin = definePluginCreator({
614
- onInit(ctx, opts) {
615
- const typeManager = ctx.get(BaseTypeManager);
616
- jsonSchemaTypePreset.forEach((_type) => typeManager.register(_type));
617
- opts.types?.forEach((_type) => typeManager.register(_type));
618
- opts.unregisterTypes?.forEach((_type) => typeManager.unregister(_type));
619
- },
620
- containerModules: [jsonSchemaContainerModule]
621
- });
622
-
623
- // src/plugins/json-schema-preset/index.tsx
624
- var useTypeManager = () => useOriginTypeManager();
625
- var JsonSchemaTypePresetProvider = ({
626
- types = [],
627
- children
628
- }) => /* @__PURE__ */ React10.createElement(OriginTypePresetProvider, { types: [...jsonSchemaTypePreset, ...types] }, children);
629
-
630
- // src/plugins/disable-declaration-plugin/create-disable-declaration-plugin.ts
631
- import {
632
- ASTMatch,
633
- definePluginCreator as definePluginCreator2,
634
- VariableEngine
635
- } from "@flowgram.ai/editor";
636
- var createDisableDeclarationPlugin = definePluginCreator2({
637
- onInit(ctx) {
638
- const variableEngine = ctx.get(VariableEngine);
639
- const handleEvent = (action) => {
640
- if (ASTMatch.isVariableDeclaration(action.ast)) {
641
- if (!action.ast.meta?.disabled) {
642
- action.ast.updateMeta({
643
- ...action.ast.meta || {},
644
- disabled: true
645
- });
646
- }
647
- }
648
- };
649
- variableEngine.onGlobalEvent("NewAST", handleEvent);
650
- variableEngine.onGlobalEvent("UpdateAST", handleEvent);
651
- }
652
- });
653
-
654
- // src/components/variable-selector/use-variable-tree.tsx
655
- function useVariableTree(params) {
656
- const { includeSchema, excludeSchema, customSkip } = params;
657
- const typeManager = useTypeManager();
658
- const variables = useAvailableVariables();
659
- const getVariableTypeIcon = useCallback((variable) => {
660
- if (variable.meta?.icon) {
661
- if (typeof variable.meta.icon === "string") {
662
- return /* @__PURE__ */ React11.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: variable.meta.icon });
663
- }
664
- return variable.meta.icon;
665
- }
666
- const schema = JsonSchemaUtils2.astToSchema(variable.type, { drilldownObject: false });
667
- return /* @__PURE__ */ React11.createElement(Icon, { size: "small", svg: typeManager.getDisplayIcon(schema || {}) });
668
- }, []);
669
- const renderVariable = (variable, parentFields = []) => {
670
- let type = variable?.type;
671
- if (!type) {
672
- return null;
673
- }
674
- let children;
675
- if (ASTMatch2.isObject(type)) {
676
- children = (type.properties || []).map((_property) => renderVariable(_property, [...parentFields, variable])).filter(Boolean);
677
- }
678
- const keyPath = [...parentFields.map((_field) => _field.key), variable.key];
679
- const key = keyPath.join(".");
680
- const isSchemaInclude = includeSchema ? JsonSchemaUtils2.isASTMatchSchema(type, includeSchema) : true;
681
- const isSchemaExclude = excludeSchema ? JsonSchemaUtils2.isASTMatchSchema(type, excludeSchema) : false;
682
- const isCustomSkip = customSkip ? customSkip(variable) : false;
683
- const isMetaDisabled = variable.meta?.disabled;
684
- const isSchemaMatch = isSchemaInclude && !isSchemaExclude && !isCustomSkip && !isMetaDisabled;
685
- if (!isSchemaMatch && !children?.length) {
686
- return null;
687
- }
688
- return {
689
- key,
690
- label: variable.meta?.title || variable.key,
691
- value: key,
692
- keyPath,
693
- icon: getVariableTypeIcon(variable),
694
- children,
695
- disabled: !isSchemaMatch,
696
- rootMeta: parentFields[0]?.meta || variable.meta,
697
- isRoot: !parentFields?.length
698
- };
699
- };
700
- return [...variables.slice(0).reverse()].map((_variable) => renderVariable(_variable)).filter(Boolean);
701
- }
702
-
703
- // src/components/variable-selector/styles.tsx
704
- import styled2, { css } from "styled-components";
705
- import { Tag, TreeSelect } from "@douyinfe/semi-ui";
706
- var UIRootTitle = styled2.div`
707
- margin-right: 4px;
708
- min-width: 20px;
709
- overflow: hidden;
710
- text-overflow: ellipsis;
711
- white-space: nowrap;
712
- color: var(--semi-color-text-2);
713
- `;
714
- var UIVarName = styled2.div`
715
- overflow: hidden;
716
- text-overflow: ellipsis;
717
- white-space: nowrap;
718
-
719
- ${({ $inSelector }) => $inSelector && css`
720
- min-width: 50%;
721
- `}
722
- `;
723
- var UITag = styled2(Tag)`
724
- width: 100%;
725
- display: flex;
726
- align-items: center;
727
- justify-content: flex-start;
728
-
729
- & .semi-tag-content-center {
730
- justify-content: flex-start;
731
- }
732
-
733
- &.semi-tag {
734
- margin: 0;
735
- height: 22px;
736
- }
737
- `;
738
- var UITreeSelect = styled2(TreeSelect)`
739
- outline: ${({ $error }) => $error ? "1px solid red" : "none"};
740
-
741
- & .semi-tree-select-selection {
742
- padding: 0px;
743
- height: 22px;
744
- }
745
-
746
- & .semi-tree-select-selection-content {
747
- width: 100%;
748
- }
749
-
750
- & .semi-tree-select-selection-placeholder {
751
- padding-left: 10px;
752
- }
753
- `;
754
- var UIPopoverContent = styled2.div`
755
- padding: 10px;
756
- display: inline-flex;
757
- align-items: center;
758
- justify-content: flex-start;
759
- white-space: nowrap;
760
- `;
761
-
762
- // src/components/variable-selector/index.tsx
763
- var VariableSelector = ({
764
- value,
765
- config = {},
766
- onChange,
767
- style,
768
- readonly = false,
769
- includeSchema,
770
- excludeSchema,
771
- hasError,
772
- triggerRender
773
- }) => {
774
- const treeData = useVariableTree({ includeSchema, excludeSchema });
775
- const treeValue = useMemo(() => {
776
- if (typeof value === "string") {
777
- console.warn(
778
- "The Value of VariableSelector is a string, it should be an ARRAY. \n",
779
- "Please check the value of VariableSelector \n"
780
- );
781
- return value;
782
- }
783
- return value?.join(".");
784
- }, [value]);
785
- const renderIcon = (icon) => {
786
- if (typeof icon === "string") {
787
- return /* @__PURE__ */ React12.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: icon });
788
- }
789
- return icon;
790
- };
791
- return /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(
792
- UITreeSelect,
793
- {
794
- dropdownMatchSelectWidth: false,
795
- disabled: readonly,
796
- treeData,
797
- size: "small",
798
- value: treeValue,
799
- clearIcon: null,
800
- $error: hasError,
801
- style,
802
- validateStatus: hasError ? "error" : void 0,
803
- onChange: (_, _config) => {
804
- onChange(_config.keyPath);
805
- },
806
- renderSelectedItem: (_option) => {
807
- if (!_option?.keyPath) {
808
- return /* @__PURE__ */ React12.createElement(
809
- UITag,
810
- {
811
- prefixIcon: /* @__PURE__ */ React12.createElement(IconIssueStroked, null),
812
- color: "amber",
813
- closable: !readonly,
814
- onClose: () => onChange(void 0)
815
- },
816
- config?.notFoundContent ?? "Undefined"
817
- );
818
- }
819
- const rootIcon = renderIcon(_option.rootMeta?.icon || _option?.icon);
820
- const rootTitle = /* @__PURE__ */ React12.createElement(UIRootTitle, null, _option.rootMeta?.title ? `${_option.rootMeta?.title} ${_option.isRoot ? "" : "-"} ` : null);
821
- return /* @__PURE__ */ React12.createElement("div", null, /* @__PURE__ */ React12.createElement(
822
- Popover,
823
- {
824
- content: /* @__PURE__ */ React12.createElement(UIPopoverContent, null, rootIcon, rootTitle, /* @__PURE__ */ React12.createElement(UIVarName, null, _option.keyPath.slice(1).join(".")))
825
- },
826
- /* @__PURE__ */ React12.createElement(
827
- UITag,
828
- {
829
- prefixIcon: rootIcon,
830
- closable: !readonly,
831
- onClose: () => onChange(void 0)
832
- },
833
- rootTitle,
834
- !_option.isRoot && /* @__PURE__ */ React12.createElement(UIVarName, { $inSelector: true }, _option.label)
835
- )
836
- ));
837
- },
838
- showClear: false,
839
- arrowIcon: /* @__PURE__ */ React12.createElement(IconChevronDownStroked, { size: "small" }),
840
- triggerRender,
841
- placeholder: config?.placeholder ?? I18n7.t("Select Variable")
842
- }
843
- ));
844
- };
845
- VariableSelector.renderKey = "variable-selector-render-key";
846
- var InjectVariableSelector = createInjectMaterial(VariableSelector);
847
-
848
- // src/components/type-selector/index.tsx
849
- import React13, { useMemo as useMemo2 } from "react";
850
- import { Cascader, Icon as Icon2, IconButton } from "@douyinfe/semi-ui";
851
- var labelStyle = { display: "flex", alignItems: "center", gap: 5 };
852
- var getTypeSelectValue = (value) => {
853
- if (value?.type === "array" && value?.items) {
854
- return [value.type, ...getTypeSelectValue(value.items) || []];
855
- }
856
- return value?.type ? [value.type] : void 0;
857
- };
858
- var parseTypeSelectValue = (value) => {
859
- const [type, ...subTypes] = value || [];
860
- if (type === "array") {
861
- return { type: "array", items: parseTypeSelectValue(subTypes) };
862
- }
863
- return { type };
864
- };
865
- function TypeSelector(props) {
866
- const { value, onChange, readonly, disabled, style } = props;
867
- const selectValue = useMemo2(() => getTypeSelectValue(value), [value]);
868
- const typeManager = useTypeManager();
869
- const icon = typeManager.getDisplayIcon(value || {});
870
- const options = useMemo2(
871
- () => typeManager.getTypeRegistriesWithParentType().map((_type) => {
872
- const isArray2 = _type.type === "array";
873
- return {
874
- label: /* @__PURE__ */ React13.createElement("div", { style: labelStyle }, /* @__PURE__ */ React13.createElement(Icon2, { size: "small", svg: _type.icon }), typeManager.getTypeBySchema(_type)?.label || _type.type),
875
- value: _type.type,
876
- children: isArray2 ? typeManager.getTypeRegistriesWithParentType("array").map((_type2) => ({
877
- label: /* @__PURE__ */ React13.createElement("div", { style: labelStyle }, /* @__PURE__ */ React13.createElement(
878
- Icon2,
879
- {
880
- size: "small",
881
- svg: typeManager.getDisplayIcon({
882
- type: "array",
883
- items: { type: _type2.type }
884
- })
885
- }
886
- ), typeManager.getTypeBySchema(_type2)?.label || _type2.type),
887
- value: _type2.type
888
- })) : []
889
- };
890
- }),
891
- []
892
- );
893
- return /* @__PURE__ */ React13.createElement(
894
- Cascader,
895
- {
896
- disabled: readonly || disabled,
897
- size: "small",
898
- triggerRender: () => /* @__PURE__ */ React13.createElement(IconButton, { size: "small", style, disabled: readonly || disabled, icon }),
899
- treeData: options,
900
- value: selectValue,
901
- leafOnly: true,
902
- onChange: (value2) => {
903
- onChange?.(parseTypeSelectValue(value2));
904
- }
905
- }
906
- );
907
- }
908
- TypeSelector.renderKey = "type-selector-render-key";
909
- var InjectTypeSelector = createInjectMaterial(TypeSelector);
910
-
911
- // src/components/json-schema-editor/index.tsx
912
- import React18, { useMemo as useMemo4, useState as useState3 } from "react";
913
- import { I18n as I18n9 } from "@flowgram.ai/editor";
914
- import { Button, Checkbox, IconButton as IconButton2 } from "@douyinfe/semi-ui";
915
- import {
916
- IconExpand,
917
- IconShrink,
918
- IconPlus,
919
- IconChevronDown,
920
- IconChevronRight,
921
- IconMinus
922
- } from "@douyinfe/semi-icons";
923
-
924
- // src/components/json-schema-editor/styles.tsx
925
- import React14 from "react";
926
- import styled3, { css as css2 } from "styled-components";
927
- import Icon3 from "@douyinfe/semi-icons";
928
- var UIContainer = styled3.div`
929
- /* & .semi-input {
930
- background-color: #fff;
931
- border-radius: 6px;
932
- height: 24px;
933
- } */
934
- `;
935
- var UIRow = styled3.div`
936
- display: flex;
937
- align-items: center;
938
- gap: 6px;
939
- `;
940
- var UICollapseTrigger = styled3.div`
941
- cursor: pointer;
942
- margin-right: 5px;
943
- `;
944
- var UIExpandDetail = styled3.div`
945
- display: flex;
946
- flex-direction: column;
947
- `;
948
- var UILabel = styled3.div`
949
- font-size: 12px;
950
- color: #999;
951
- font-weight: 400;
952
- margin-bottom: 2px;
953
- `;
954
- var UIProperties = styled3.div`
955
- display: grid;
956
- grid-template-columns: auto 1fr;
957
-
958
- ${({ $shrink }) => $shrink && css2`
959
- padding-left: 10px;
960
- margin-top: 10px;
961
- `}
962
- `;
963
- var UIPropertyLeft = styled3.div`
964
- grid-column: 1;
965
- position: relative;
966
- width: 16px;
967
-
968
- ${({ $showLine, $isLast, $parentType }) => {
969
- let height = "100%";
970
- if ($parentType && $isLast) {
971
- height = "24px";
972
- }
973
- return $showLine && css2`
974
- &::before {
975
- /* 竖线 */
976
- content: '';
977
- height: ${height};
978
- position: absolute;
979
- left: -22px;
980
- top: -16px;
981
- width: 1px;
982
- background: #d9d9d9;
983
- display: block;
984
- }
985
-
986
- &::after {
987
- /* 横线 */
988
- content: '';
989
- position: absolute;
990
- left: -22px; // 横线起点和竖线对齐
991
- top: 8px; // 跟随你的行高调整
992
- width: 18px; // 横线长度
993
- height: 1px;
994
- background: #d9d9d9;
995
- display: block;
996
- }
997
- `;
998
- }}
999
- `;
1000
- var UIPropertyRight = styled3.div`
1001
- grid-column: 2;
1002
- margin-bottom: 10px;
1003
-
1004
- &:last-child {
1005
- margin-bottom: 0px;
1006
- }
1007
- `;
1008
- var UIPropertyMain = styled3.div`
1009
- display: flex;
1010
- flex-direction: column;
1011
- gap: 10px;
1012
- position: relative;
1013
-
1014
- ${({ $expand, type, $collapse, $showCollapse }) => {
1015
- const beforeElement = `
1016
- &::before {
1017
- /* \u7AD6\u7EBF */
1018
- content: '';
1019
- height: 100%;
1020
- position: absolute;
1021
- left: -12px;
1022
- top: 18px;
1023
- width: 1px;
1024
- background: #d9d9d9;
1025
- display: block;
1026
- }`;
1027
- return $expand && css2`
1028
- background-color: #f5f5f5;
1029
- padding: 10px;
1030
- border-radius: 4px;
1031
-
1032
- ${$showCollapse && $collapse && (type === "array" || type === "object") && css2`
1033
- ${beforeElement}
1034
- `}
1035
- `;
1036
- }}
1037
- `;
1038
- var UICollapsible = styled3.div`
1039
- display: none;
1040
-
1041
- ${({ $collapse }) => $collapse && css2`
1042
- display: block;
1043
- `}
1044
- `;
1045
- var UIName = styled3.div`
1046
- flex-grow: 1;
1047
- `;
1048
- var UIType = styled3.div``;
1049
- var UIRequired = styled3.div``;
1050
- var UIActions = styled3.div`
1051
- white-space: nowrap;
1052
- `;
1053
- var iconAddChildrenSvg = /* @__PURE__ */ React14.createElement(
1054
- "svg",
1055
- {
1056
- className: "icon-icon icon-icon-coz_add_node ",
1057
- width: "1em",
1058
- height: "1em",
1059
- viewBox: "0 0 24 24",
1060
- fill: "currentColor",
1061
- xmlns: "http://www.w3.org/2000/svg"
1062
- },
1063
- /* @__PURE__ */ React14.createElement(
1064
- "path",
1065
- {
1066
- fillRule: "evenodd",
1067
- clipRule: "evenodd",
1068
- d: "M11 6.49988C11 8.64148 9.50397 10.4337 7.49995 10.8884V15.4998C7.49995 16.0521 7.94767 16.4998 8.49995 16.4998H11.208C11.0742 16.8061 11 17.1443 11 17.4998C11 17.8554 11.0742 18.1936 11.208 18.4998H8.49995C6.8431 18.4998 5.49995 17.1567 5.49995 15.4998V10.8884C3.49599 10.4336 2 8.64145 2 6.49988C2 4.0146 4.01472 1.99988 6.5 1.99988C8.98528 1.99988 11 4.0146 11 6.49988ZM6.5 8.99988C7.88071 8.99988 9 7.88059 9 6.49988C9 5.11917 7.88071 3.99988 6.5 3.99988C5.11929 3.99988 4 5.11917 4 6.49988C4 7.88059 5.11929 8.99988 6.5 8.99988Z"
1069
- }
1070
- ),
1071
- /* @__PURE__ */ React14.createElement("path", { d: "M17.5 12.4999C18.0523 12.4999 18.5 12.9476 18.5 13.4999V16.4999H21.5C22.0523 16.4999 22.5 16.9476 22.5 17.4999C22.5 18.0522 22.0523 18.4999 21.5 18.4999H18.5V21.4999C18.5 22.0522 18.0523 22.4999 17.5 22.4999C16.9477 22.4999 16.5 22.0522 16.5 21.4999V18.4999H13.5C12.9477 18.4999 12.5 18.0522 12.5 17.4999C12.5 16.9476 12.9477 16.4999 13.5 16.4999H16.5V13.4999C16.5 12.9476 16.9477 12.4999 17.5 12.4999Z" })
1072
- );
1073
- var IconAddChildren = () => /* @__PURE__ */ React14.createElement(Icon3, { size: "small", svg: iconAddChildrenSvg });
1074
- var DefaultValueWrapper = styled3.div`
1075
- margin: 0;
1076
- `;
1077
- var ConstantInputWrapper = styled3.div`
1078
- flex-grow: 1;
1079
-
1080
- & .semi-tree-select,
1081
- & .semi-input-number,
1082
- & .semi-select {
1083
- width: 100%;
1084
- }
1085
- `;
1086
-
1087
- // src/components/json-schema-editor/hooks.tsx
1088
- import { useEffect as useEffect2, useState } from "react";
1089
- import { difference, omit } from "lodash";
1090
- import { produce } from "immer";
1091
- import { useTypeManager as useTypeManager2 } from "@flowgram.ai/json-schema";
1092
- var _id = 0;
1093
- function genId() {
1094
- return _id++;
1095
- }
1096
- function usePropertiesEdit(value, onChange) {
1097
- const typeManager = useTypeManager2();
1098
- const drilldownSchema = typeManager.getPropertiesParent(value || {});
1099
- const canAddField = typeManager.canAddField(value || {});
1100
- const [propertyList, setPropertyList] = useState([]);
1101
- useEffect2(() => {
1102
- setPropertyList((_list) => {
1103
- const newNames = Object.entries(drilldownSchema?.properties || {}).sort(([, a], [, b]) => (a.extra?.index ?? 0) - (b.extra?.index ?? 0)).map(([key]) => key);
1104
- const oldNames = _list.map((item) => item.name).filter(Boolean);
1105
- const addNames = difference(newNames, oldNames);
1106
- return _list.filter((item) => !item.name || newNames.includes(item.name)).map((item) => ({
1107
- key: item.key,
1108
- name: item.name,
1109
- isPropertyRequired: drilldownSchema?.required?.includes(item.name || "") || false,
1110
- ...item
1111
- })).concat(
1112
- addNames.map((_name) => ({
1113
- key: genId(),
1114
- name: _name,
1115
- isPropertyRequired: drilldownSchema?.required?.includes(_name) || false,
1116
- ...drilldownSchema?.properties?.[_name] || {}
1117
- }))
1118
- );
1119
- });
1120
- }, [drilldownSchema]);
1121
- const updatePropertyList = (updater) => {
1122
- setPropertyList((_list) => {
1123
- const next = updater(_list);
1124
- const nextProperties = {};
1125
- const nextRequired = [];
1126
- for (const _property of next) {
1127
- if (!_property.name) {
1128
- continue;
1129
- }
1130
- nextProperties[_property.name] = omit(_property, ["key", "name", "isPropertyRequired"]);
1131
- if (_property.isPropertyRequired) {
1132
- nextRequired.push(_property.name);
1133
- }
1134
- }
1135
- onChange?.(
1136
- produce(value || {}, (draft) => {
1137
- const propertiesParent = typeManager.getPropertiesParent(draft);
1138
- if (propertiesParent) {
1139
- propertiesParent.properties = nextProperties;
1140
- propertiesParent.required = nextRequired;
1141
- return;
1142
- }
1143
- })
1144
- );
1145
- return next;
1146
- });
1147
- };
1148
- const onAddProperty = () => {
1149
- setPropertyList((_list) => [
1150
- ..._list,
1151
- { key: genId(), name: "", type: "string", extra: { index: _list.length + 1 } }
1152
- ]);
1153
- };
1154
- const onRemoveProperty = (key) => {
1155
- updatePropertyList((_list) => _list.filter((_property) => _property.key !== key));
1156
- };
1157
- const onEditProperty = (key, nextValue) => {
1158
- updatePropertyList(
1159
- (_list) => _list.map((_property) => _property.key === key ? nextValue : _property)
1160
- );
1161
- };
1162
- useEffect2(() => {
1163
- if (!canAddField) {
1164
- setPropertyList([]);
1165
- }
1166
- }, [canAddField]);
1167
- return {
1168
- propertyList,
1169
- canAddField,
1170
- onAddProperty,
1171
- onRemoveProperty,
1172
- onEditProperty
1173
- };
1174
- }
1175
-
1176
- // src/components/json-schema-editor/default-value.tsx
1177
- import React16 from "react";
1178
- import { I18n as I18n8 } from "@flowgram.ai/editor";
1179
-
1180
- // src/components/constant-input/index.tsx
1181
- import React15, { useMemo as useMemo3 } from "react";
1182
- import { Input as Input2 } from "@douyinfe/semi-ui";
1183
- function ConstantInput(props) {
1184
- const { value, onChange, schema, strategies, fallbackRenderer, readonly, ...rest } = props;
1185
- const typeManager = useTypeManager();
1186
- const Renderer2 = useMemo3(() => {
1187
- const strategy = (strategies || []).find((_strategy) => _strategy.hit(schema));
1188
- if (!strategy) {
1189
- return typeManager.getTypeBySchema(schema)?.ConstantRenderer;
1190
- }
1191
- return strategy?.Renderer;
1192
- }, [strategies, schema]);
1193
- if (!Renderer2) {
1194
- if (fallbackRenderer) {
1195
- return React15.createElement(fallbackRenderer, {
1196
- value,
1197
- onChange,
1198
- readonly,
1199
- ...rest
1200
- });
1201
- }
1202
- return /* @__PURE__ */ React15.createElement(Input2, { size: "small", disabled: true, placeholder: "Unsupported type" });
1203
- }
1204
- return /* @__PURE__ */ React15.createElement(Renderer2, { value, onChange, readonly, ...rest });
1205
- }
1206
-
1207
- // src/components/json-schema-editor/default-value.tsx
1208
- function DefaultValue(props) {
1209
- const { value, schema, onChange, placeholder } = props;
1210
- return /* @__PURE__ */ React16.createElement(ConstantInputWrapper, null, /* @__PURE__ */ React16.createElement(
1211
- ConstantInput,
1212
- {
1213
- value,
1214
- onChange: (_v) => onChange(_v),
1215
- schema: schema || { type: "string" },
1216
- placeholder: placeholder ?? I18n8.t("Default value if parameter is not provided")
1217
- }
1218
- ));
1219
- }
1220
-
1221
- // src/components/json-schema-editor/components/blur-input.tsx
1222
- import React17, { useEffect as useEffect3, useState as useState2 } from "react";
1223
- import Input3 from "@douyinfe/semi-ui/lib/es/input";
1224
- function BlurInput(props) {
1225
- const [value, setValue] = useState2("");
1226
- useEffect3(() => {
1227
- setValue(props.value);
1228
- }, [props.value]);
1229
- return /* @__PURE__ */ React17.createElement(
1230
- Input3,
1231
- {
1232
- ...props,
1233
- value,
1234
- onChange: (value2) => {
1235
- setValue(value2);
1236
- },
1237
- onBlur: (e) => props.onChange?.(value, e)
1238
- }
1239
- );
1240
- }
1241
-
1242
- // src/components/json-schema-editor/index.tsx
1243
- var DEFAULT = { type: "object" };
1244
- function JsonSchemaEditor(props) {
1245
- const { value = DEFAULT, config = {}, onChange: onChangeProps, readonly } = props;
1246
- const { propertyList, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(
1247
- value,
1248
- onChangeProps
1249
- );
1250
- return /* @__PURE__ */ React18.createElement(UIContainer, { className: props.className }, /* @__PURE__ */ React18.createElement(UIProperties, null, propertyList.map((_property, index) => /* @__PURE__ */ React18.createElement(
1251
- PropertyEdit,
1252
- {
1253
- readonly,
1254
- key: _property.key,
1255
- value: _property,
1256
- config,
1257
- $index: index,
1258
- onChange: (_v) => {
1259
- onEditProperty(_property.key, _v);
1260
- },
1261
- onRemove: () => {
1262
- onRemoveProperty(_property.key);
1263
- }
1264
- }
1265
- ))), /* @__PURE__ */ React18.createElement(
1266
- Button,
1267
- {
1268
- disabled: readonly,
1269
- size: "small",
1270
- style: { marginTop: 10, marginLeft: 16 },
1271
- icon: /* @__PURE__ */ React18.createElement(IconPlus, null),
1272
- onClick: onAddProperty
1273
- },
1274
- config?.addButtonText ?? I18n9.t("Add")
1275
- ));
1276
- }
1277
- function PropertyEdit(props) {
1278
- const {
1279
- value,
1280
- config,
1281
- readonly,
1282
- $level = 0,
1283
- onChange: onChangeProps,
1284
- onRemove,
1285
- $index,
1286
- $isFirst,
1287
- $isLast,
1288
- $parentExpand = false,
1289
- $parentType = "",
1290
- $showLine
1291
- } = props;
1292
- const [expand, setExpand] = useState3(false);
1293
- const [collapse, setCollapse] = useState3(false);
1294
- const { name, type, items, default: defaultValue, description, isPropertyRequired } = value || {};
1295
- const typeSelectorValue = useMemo4(() => ({ type, items }), [type, items]);
1296
- const { propertyList, canAddField, onAddProperty, onRemoveProperty, onEditProperty } = usePropertiesEdit(value, onChangeProps);
1297
- const onChange = (key, _value) => {
1298
- onChangeProps?.({
1299
- ...value || {},
1300
- [key]: _value
1301
- });
1302
- };
1303
- const showCollapse = canAddField && propertyList.length > 0;
1304
- return /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement(
1305
- UIPropertyLeft,
1306
- {
1307
- type,
1308
- $index,
1309
- $isFirst,
1310
- $isLast,
1311
- $showLine,
1312
- $isExpand: expand,
1313
- $parentExpand,
1314
- $parentType
1315
- },
1316
- showCollapse && /* @__PURE__ */ React18.createElement(UICollapseTrigger, { onClick: () => setCollapse((_collapse) => !_collapse) }, collapse ? /* @__PURE__ */ React18.createElement(IconChevronDown, { size: "small" }) : /* @__PURE__ */ React18.createElement(IconChevronRight, { size: "small" }))
1317
- ), /* @__PURE__ */ React18.createElement(UIPropertyRight, null, /* @__PURE__ */ React18.createElement(
1318
- UIPropertyMain,
1319
- {
1320
- $showCollapse: showCollapse,
1321
- $collapse: collapse,
1322
- $expand: expand,
1323
- type
1324
- },
1325
- /* @__PURE__ */ React18.createElement(UIRow, null, /* @__PURE__ */ React18.createElement(UIName, null, /* @__PURE__ */ React18.createElement(
1326
- BlurInput,
1327
- {
1328
- disabled: readonly,
1329
- placeholder: config?.placeholder ?? "Input Variable Name",
1330
- size: "small",
1331
- value: name,
1332
- onChange: (value2) => onChange("name", value2)
1333
- }
1334
- )), /* @__PURE__ */ React18.createElement(UIType, null, /* @__PURE__ */ React18.createElement(
1335
- InjectTypeSelector,
1336
- {
1337
- value: typeSelectorValue,
1338
- readonly,
1339
- onChange: (_value) => {
1340
- onChangeProps?.({
1341
- ...value || {},
1342
- ..._value
1343
- });
1344
- }
1345
- }
1346
- )), /* @__PURE__ */ React18.createElement(UIRequired, null, /* @__PURE__ */ React18.createElement(
1347
- Checkbox,
1348
- {
1349
- disabled: readonly,
1350
- checked: isPropertyRequired,
1351
- onChange: (e) => onChange("isPropertyRequired", e.target.checked)
1352
- }
1353
- )), /* @__PURE__ */ React18.createElement(UIActions, null, /* @__PURE__ */ React18.createElement(
1354
- IconButton2,
1355
- {
1356
- disabled: readonly,
1357
- size: "small",
1358
- theme: "borderless",
1359
- icon: expand ? /* @__PURE__ */ React18.createElement(IconShrink, { size: "small" }) : /* @__PURE__ */ React18.createElement(IconExpand, { size: "small" }),
1360
- onClick: () => {
1361
- setExpand((_expand) => !_expand);
1362
- }
1363
- }
1364
- ), canAddField && /* @__PURE__ */ React18.createElement(
1365
- IconButton2,
1366
- {
1367
- disabled: readonly,
1368
- size: "small",
1369
- theme: "borderless",
1370
- icon: /* @__PURE__ */ React18.createElement(IconAddChildren, null),
1371
- onClick: () => {
1372
- onAddProperty();
1373
- setCollapse(true);
1374
- }
1375
- }
1376
- ), /* @__PURE__ */ React18.createElement(
1377
- IconButton2,
1378
- {
1379
- disabled: readonly,
1380
- size: "small",
1381
- theme: "borderless",
1382
- icon: /* @__PURE__ */ React18.createElement(IconMinus, { size: "small" }),
1383
- onClick: onRemove
1384
- }
1385
- ))),
1386
- expand && /* @__PURE__ */ React18.createElement(UIExpandDetail, null, /* @__PURE__ */ React18.createElement(UILabel, null, config?.descTitle ?? I18n9.t("Description")), /* @__PURE__ */ React18.createElement(
1387
- BlurInput,
1388
- {
1389
- disabled: readonly,
1390
- size: "small",
1391
- value: description,
1392
- onChange: (value2) => onChange("description", value2),
1393
- placeholder: config?.descPlaceholder ?? I18n9.t("Help LLM to understand the property")
1394
- }
1395
- ), $level === 0 && /* @__PURE__ */ React18.createElement(React18.Fragment, null, /* @__PURE__ */ React18.createElement(UILabel, { style: { marginTop: 10 } }, config?.defaultValueTitle ?? I18n9.t("Default Value")), /* @__PURE__ */ React18.createElement(DefaultValueWrapper, null, /* @__PURE__ */ React18.createElement(
1396
- DefaultValue,
1397
- {
1398
- value: defaultValue,
1399
- schema: value,
1400
- type,
1401
- placeholder: config?.defaultValuePlaceholder ?? I18n9.t("Default Value"),
1402
- jsonFormatText: config?.jsonFormatText,
1403
- onChange: (value2) => onChange("default", value2)
1404
- }
1405
- ))))
1406
- ), showCollapse && /* @__PURE__ */ React18.createElement(UICollapsible, { $collapse: collapse }, /* @__PURE__ */ React18.createElement(UIProperties, { $shrink: true }, propertyList.map((_property, index) => /* @__PURE__ */ React18.createElement(
1407
- PropertyEdit,
1408
- {
1409
- readonly,
1410
- key: _property.key,
1411
- value: _property,
1412
- config,
1413
- $level: $level + 1,
1414
- $parentExpand: expand,
1415
- $parentType: type,
1416
- onChange: (_v) => {
1417
- onEditProperty(_property.key, _v);
1418
- },
1419
- onRemove: () => {
1420
- onRemoveProperty(_property.key);
1421
- },
1422
- $isLast: index === propertyList.length - 1,
1423
- $isFirst: index === 0,
1424
- $index: index,
1425
- $showLine: true
1426
- }
1427
- ))))));
1428
- }
1429
-
1430
- // src/components/batch-variable-selector/index.tsx
1431
- import React19 from "react";
1432
- import { PrivateScopeProvider } from "@flowgram.ai/editor";
1433
- var batchVariableSchema = {
1434
- type: "array",
1435
- extra: { weak: true }
1436
- };
1437
- function BatchVariableSelector(props) {
1438
- return /* @__PURE__ */ React19.createElement(PrivateScopeProvider, null, /* @__PURE__ */ React19.createElement(VariableSelector, { ...props, includeSchema: batchVariableSchema }));
1439
- }
1440
-
1441
- // src/components/dynamic-value-input/index.tsx
1442
- import React20 from "react";
1443
- import { JsonSchemaUtils as JsonSchemaUtils3 } from "@flowgram.ai/json-schema";
1444
- import { IconButton as IconButton3 } from "@douyinfe/semi-ui";
1445
- import { IconSetting } from "@douyinfe/semi-icons";
1446
-
1447
- // src/components/dynamic-value-input/styles.tsx
1448
- import styled4 from "styled-components";
1449
- var UIContainer2 = styled4.div`
1450
- display: flex;
1451
- align-items: center;
1452
- border-radius: 4px;
1453
- border: 1px solid var(--semi-color-border);
1454
-
1455
- overflow: hidden;
1456
-
1457
- background-color: var(--semi-color-fill-0);
1458
- `;
1459
- var UIMain = styled4.div`
1460
- flex-grow: 1;
1461
- overflow: hidden;
1462
- min-width: 0;
1463
-
1464
- & .semi-tree-select,
1465
- & .semi-input-number,
1466
- & .semi-select {
1467
- width: 100%;
1468
- border: none;
1469
- border-radius: 0;
1470
- }
1471
-
1472
- & .semi-input-wrapper {
1473
- border: none;
1474
- border-radius: 0;
1475
- }
1476
- `;
1477
- var UIType2 = styled4.div`
1478
- border-right: 1px solid #e5e5e5;
1479
-
1480
- & .semi-button {
1481
- border-radius: 0;
1482
- }
1483
- `;
1484
- var UITrigger = styled4.div`
1485
- border-left: 1px solid #e5e5e5;
1486
-
1487
- & .semi-button {
1488
- border-radius: 0;
1489
- }
1490
- `;
1491
-
1492
- // src/components/dynamic-value-input/hooks.ts
1493
- import { useMemo as useMemo5, useState as useState4 } from "react";
1494
- import { useScopeAvailable } from "@flowgram.ai/editor";
1495
- function useRefVariable(value) {
1496
- const available = useScopeAvailable();
1497
- const refVariable = useMemo5(() => {
1498
- if (value?.type === "ref") {
1499
- return available.getByKeyPath(value.content);
1500
- }
1501
- }, [value, available]);
1502
- return refVariable;
1503
- }
1504
- function useSelectSchema(schemaFromProps, constantProps, value) {
1505
- let defaultSelectSchema = schemaFromProps || constantProps?.schema || { type: "string" };
1506
- if (value?.type === "constant") {
1507
- defaultSelectSchema = value?.schema || defaultSelectSchema;
1508
- }
1509
- const [selectSchema, setSelectSchema] = useState4(defaultSelectSchema);
1510
- return [selectSchema, setSelectSchema];
1511
- }
1512
- function useIncludeSchema(schemaFromProps) {
1513
- const includeSchema = useMemo5(() => {
1514
- if (!schemaFromProps) {
1515
- return;
1516
- }
1517
- if (schemaFromProps?.type === "number") {
1518
- return [schemaFromProps, { type: "integer" }];
1519
- }
1520
- return { ...schemaFromProps, extra: { ...schemaFromProps?.extra, weak: true } };
1521
- }, [schemaFromProps]);
1522
- return includeSchema;
1523
- }
1524
-
1525
- // src/components/dynamic-value-input/index.tsx
1526
- function DynamicValueInput({
1527
- value,
1528
- onChange,
1529
- readonly,
1530
- style,
1531
- schema: schemaFromProps,
1532
- constantProps
1533
- }) {
1534
- const refVariable = useRefVariable(value);
1535
- const [selectSchema, setSelectSchema] = useSelectSchema(schemaFromProps, constantProps, value);
1536
- const includeSchema = useIncludeSchema(schemaFromProps);
1537
- const renderTypeSelector = () => {
1538
- if (schemaFromProps) {
1539
- return /* @__PURE__ */ React20.createElement(TypeSelector, { value: schemaFromProps, readonly: true });
1540
- }
1541
- if (value?.type === "ref") {
1542
- const schema = refVariable?.type ? JsonSchemaUtils3.astToSchema(refVariable?.type) : void 0;
1543
- return /* @__PURE__ */ React20.createElement(TypeSelector, { value: schema, readonly: true });
1544
- }
1545
- return /* @__PURE__ */ React20.createElement(
1546
- TypeSelector,
1547
- {
1548
- value: selectSchema,
1549
- onChange: (_v) => {
1550
- setSelectSchema(_v || { type: "string" });
1551
- let content;
1552
- if (_v?.type === "object") {
1553
- content = "{}";
1554
- }
1555
- if (_v?.type === "array") {
1556
- content = "[]";
1557
- }
1558
- if (_v?.type === "boolean") {
1559
- content = false;
1560
- }
1561
- onChange({
1562
- type: "constant",
1563
- content,
1564
- schema: _v || { type: "string" }
1565
- });
1566
- },
1567
- readonly
1568
- }
1569
- );
1570
- };
1571
- const renderMain = () => {
1572
- if (value?.type === "ref") {
1573
- return /* @__PURE__ */ React20.createElement(
1574
- InjectVariableSelector,
1575
- {
1576
- style: { width: "100%" },
1577
- value: value?.content,
1578
- onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
1579
- includeSchema,
1580
- readonly
1581
- }
1582
- );
1583
- }
1584
- const constantSchema = schemaFromProps || selectSchema || { type: "string" };
1585
- return /* @__PURE__ */ React20.createElement(
1586
- ConstantInput,
1587
- {
1588
- value: value?.content,
1589
- onChange: (_v) => onChange({ type: "constant", content: _v, schema: constantSchema }),
1590
- schema: constantSchema || { type: "string" },
1591
- readonly,
1592
- strategies: [...constantProps?.strategies || []],
1593
- fallbackRenderer: () => /* @__PURE__ */ React20.createElement(
1594
- InjectVariableSelector,
1595
- {
1596
- style: { width: "100%" },
1597
- onChange: (_v) => onChange(_v ? { type: "ref", content: _v } : void 0),
1598
- includeSchema,
1599
- readonly
1600
- }
1601
- ),
1602
- ...constantProps
1603
- }
1604
- );
1605
- };
1606
- const renderTrigger = () => /* @__PURE__ */ React20.createElement(
1607
- InjectVariableSelector,
1608
- {
1609
- style: { width: "100%" },
1610
- value: value?.type === "ref" ? value?.content : void 0,
1611
- onChange: (_v) => onChange({ type: "ref", content: _v }),
1612
- includeSchema,
1613
- readonly,
1614
- triggerRender: () => /* @__PURE__ */ React20.createElement(IconButton3, { disabled: readonly, size: "small", icon: /* @__PURE__ */ React20.createElement(IconSetting, { size: "small" }) })
1615
- }
1616
- );
1617
- return /* @__PURE__ */ React20.createElement(UIContainer2, { style }, /* @__PURE__ */ React20.createElement(UIType2, null, renderTypeSelector()), /* @__PURE__ */ React20.createElement(UIMain, null, renderMain()), /* @__PURE__ */ React20.createElement(UITrigger, null, renderTrigger()));
1618
- }
1619
- DynamicValueInput.renderKey = "dynamic-value-input-render-key";
1620
- var InjectDynamicValueInput = createInjectMaterial(DynamicValueInput);
1621
-
1622
- // src/components/condition-row/index.tsx
1623
- import React22, { useMemo as useMemo8 } from "react";
1624
- import { I18n as I18n11 } from "@flowgram.ai/editor";
1625
- import { Input as Input4 } from "@douyinfe/semi-ui";
1626
-
1627
- // src/components/condition-row/styles.tsx
1628
- import styled5 from "styled-components";
1629
- var UIContainer3 = styled5.div`
1630
- display: flex;
1631
- align-items: center;
1632
- gap: 4px;
1633
- `;
1634
- var UIOperator = styled5.div``;
1635
- var UILeft = styled5.div`
1636
- width: 100%;
1637
- `;
1638
- var UIRight = styled5.div`
1639
- width: 100%;
1640
- `;
1641
- var UIValues = styled5.div`
1642
- flex-grow: 1;
1643
- display: flex;
1644
- flex-direction: column;
1645
- align-items: center;
1646
- gap: 4px;
1647
- `;
1648
-
1649
- // src/components/condition-row/hooks/useRule.ts
1650
- import { useMemo as useMemo6 } from "react";
1651
- import { JsonSchemaUtils as JsonSchemaUtils4 } from "@flowgram.ai/json-schema";
1652
- import { useScopeAvailable as useScopeAvailable2 } from "@flowgram.ai/editor";
1653
-
1654
- // src/components/condition-row/constants.ts
1655
- var defaultRules = {
1656
- string: {
1657
- ["eq" /* EQ */]: "string",
1658
- ["neq" /* NEQ */]: "string",
1659
- ["contains" /* CONTAINS */]: "string",
1660
- ["not_contains" /* NOT_CONTAINS */]: "string",
1661
- ["in" /* IN */]: "array",
1662
- ["nin" /* NIN */]: "array",
1663
- ["is_empty" /* IS_EMPTY */]: null,
1664
- ["is_not_empty" /* IS_NOT_EMPTY */]: null
1665
- },
1666
- number: {
1667
- ["eq" /* EQ */]: "number",
1668
- ["neq" /* NEQ */]: "number",
1669
- ["gt" /* GT */]: "number",
1670
- ["gte" /* GTE */]: "number",
1671
- ["lt" /* LT */]: "number",
1672
- ["lte" /* LTE */]: "number",
1673
- ["in" /* IN */]: "array",
1674
- ["nin" /* NIN */]: "array"
1675
- },
1676
- integer: {
1677
- ["eq" /* EQ */]: "number",
1678
- ["neq" /* NEQ */]: "number",
1679
- ["gt" /* GT */]: "number",
1680
- ["gte" /* GTE */]: "number",
1681
- ["lt" /* LT */]: "number",
1682
- ["lte" /* LTE */]: "number",
1683
- ["in" /* IN */]: "array",
1684
- ["nin" /* NIN */]: "array"
1685
- },
1686
- boolean: {
1687
- ["eq" /* EQ */]: "boolean",
1688
- ["neq" /* NEQ */]: "boolean",
1689
- ["is_true" /* IS_TRUE */]: null,
1690
- ["is_false" /* IS_FALSE */]: null,
1691
- ["in" /* IN */]: "array",
1692
- ["nin" /* NIN */]: "array"
1693
- },
1694
- object: {
1695
- ["is_empty" /* IS_EMPTY */]: null,
1696
- ["is_not_empty" /* IS_NOT_EMPTY */]: null
1697
- },
1698
- array: {
1699
- ["is_empty" /* IS_EMPTY */]: null,
1700
- ["is_not_empty" /* IS_NOT_EMPTY */]: null,
1701
- ["contains" /* CONTAINS */]: "array",
1702
- ["not_contains" /* NOT_CONTAINS */]: "array",
1703
- ["eq" /* EQ */]: "array",
1704
- ["neq" /* NEQ */]: "array"
1705
- },
1706
- map: {
1707
- ["is_empty" /* IS_EMPTY */]: null,
1708
- ["is_not_empty" /* IS_NOT_EMPTY */]: null
1709
- }
1710
- };
1711
- var defaultOpConfigs = {
1712
- ["eq" /* EQ */]: {
1713
- label: "Equal",
1714
- abbreviation: "="
1715
- },
1716
- ["neq" /* NEQ */]: {
1717
- label: "Not Equal",
1718
- abbreviation: "\u2260"
1719
- },
1720
- ["gt" /* GT */]: {
1721
- label: "Greater Than",
1722
- abbreviation: ">"
1723
- },
1724
- ["gte" /* GTE */]: {
1725
- label: "Greater Than or Equal",
1726
- abbreviation: ">="
1727
- },
1728
- ["lt" /* LT */]: {
1729
- label: "Less Than",
1730
- abbreviation: "<"
1731
- },
1732
- ["lte" /* LTE */]: {
1733
- label: "Less Than or Equal",
1734
- abbreviation: "<="
1735
- },
1736
- ["in" /* IN */]: {
1737
- label: "In",
1738
- abbreviation: "\u2208"
1739
- },
1740
- ["nin" /* NIN */]: {
1741
- label: "Not In",
1742
- abbreviation: "\u2209"
1743
- },
1744
- ["contains" /* CONTAINS */]: {
1745
- label: "Contains",
1746
- abbreviation: "\u2287"
1747
- },
1748
- ["not_contains" /* NOT_CONTAINS */]: {
1749
- label: "Not Contains",
1750
- abbreviation: "\u2289"
1751
- },
1752
- ["is_empty" /* IS_EMPTY */]: {
1753
- label: "Is Empty",
1754
- abbreviation: "=",
1755
- rightDisplay: "Empty"
1756
- },
1757
- ["is_not_empty" /* IS_NOT_EMPTY */]: {
1758
- label: "Is Not Empty",
1759
- abbreviation: "\u2260",
1760
- rightDisplay: "Empty"
1761
- },
1762
- ["is_true" /* IS_TRUE */]: {
1763
- label: "Is True",
1764
- abbreviation: "=",
1765
- rightDisplay: "True"
1766
- },
1767
- ["is_false" /* IS_FALSE */]: {
1768
- label: "Is False",
1769
- abbreviation: "=",
1770
- rightDisplay: "False"
1771
- }
1772
- };
1773
-
1774
- // src/components/condition-row/hooks/useRule.ts
1775
- function useRule(left, userRules) {
1776
- const available = useScopeAvailable2();
1777
- const rules = useMemo6(() => ({ ...defaultRules, ...userRules || {} }), [userRules]);
1778
- const variable = useMemo6(() => {
1779
- if (!left) return void 0;
1780
- return available.getByKeyPath(left.content);
1781
- }, [available, left]);
1782
- const rule = useMemo6(() => {
1783
- if (!variable) return void 0;
1784
- const schema = JsonSchemaUtils4.astToSchema(variable.type, { drilldown: false });
1785
- return rules[schema?.type];
1786
- }, [variable?.type, rules]);
1787
- return { rule };
1788
- }
1789
-
1790
- // src/components/condition-row/hooks/useOp.tsx
1791
- import React21, { useMemo as useMemo7 } from "react";
1792
- import { I18n as I18n10 } from "@flowgram.ai/editor";
1793
- import { Button as Button2, Select as Select2 } from "@douyinfe/semi-ui";
1794
- import { IconChevronDownStroked as IconChevronDownStroked2 } from "@douyinfe/semi-icons";
1795
- function useOp({ rule, op, onChange, readonly, userOps }) {
1796
- const options = useMemo7(
1797
- () => Object.keys(rule || {}).map((_op) => ({
1798
- ...defaultOpConfigs[_op] || {},
1799
- ...userOps?.[_op] || {},
1800
- value: _op,
1801
- label: I18n10.t(userOps?.[_op]?.label || defaultOpConfigs[_op]?.label)
1802
- })),
1803
- [rule, userOps]
1804
- );
1805
- const opConfig = useMemo7(() => defaultOpConfigs[op], [op]);
1806
- const renderOpSelect = () => /* @__PURE__ */ React21.createElement(
1807
- Select2,
1808
- {
1809
- style: { height: 22 },
1810
- disabled: readonly,
1811
- size: "small",
1812
- value: op,
1813
- optionList: options,
1814
- onChange: (v) => {
1815
- onChange(v);
1816
- },
1817
- triggerRender: ({ value }) => /* @__PURE__ */ React21.createElement(Button2, { size: "small", disabled: !rule }, opConfig?.abbreviation || /* @__PURE__ */ React21.createElement(IconChevronDownStroked2, { size: "small" }))
1818
- }
1819
- );
1820
- return { renderOpSelect, opConfig };
1821
- }
1822
-
1823
- // src/components/condition-row/index.tsx
1824
- var defaultRuleConfig = {
1825
- ops: {},
1826
- rules: {}
1827
- };
1828
- function ConditionRow({
1829
- style,
1830
- value,
1831
- onChange,
1832
- readonly,
1833
- ruleConfig = defaultRuleConfig
1834
- }) {
1835
- const { left, operator, right } = value || {};
1836
- const { rule } = useRule(left, ruleConfig.rules);
1837
- const { renderOpSelect, opConfig } = useOp({
1838
- rule,
1839
- op: operator,
1840
- onChange: (v) => onChange({ ...value, operator: v }),
1841
- readonly,
1842
- userOps: ruleConfig.ops
1843
- });
1844
- const targetSchema = useMemo8(() => {
1845
- const targetType = rule?.[operator || ""] || null;
1846
- return targetType ? { type: targetType, extra: { weak: true } } : null;
1847
- }, [rule, opConfig]);
1848
- return /* @__PURE__ */ React22.createElement(UIContainer3, { style }, /* @__PURE__ */ React22.createElement(UIOperator, null, renderOpSelect()), /* @__PURE__ */ React22.createElement(UIValues, null, /* @__PURE__ */ React22.createElement(UILeft, null, /* @__PURE__ */ React22.createElement(
1849
- InjectVariableSelector,
1850
- {
1851
- readonly,
1852
- style: { width: "100%" },
1853
- value: left?.content,
1854
- onChange: (v) => onChange({
1855
- ...value,
1856
- left: {
1857
- type: "ref",
1858
- content: v
1859
- }
1860
- })
1861
- }
1862
- )), /* @__PURE__ */ React22.createElement(UIRight, null, targetSchema ? /* @__PURE__ */ React22.createElement(
1863
- InjectDynamicValueInput,
1864
- {
1865
- readonly: readonly || !rule,
1866
- value: right,
1867
- schema: targetSchema,
1868
- onChange: (v) => onChange({ ...value, right: v })
1869
- }
1870
- ) : /* @__PURE__ */ React22.createElement(
1871
- Input4,
1872
- {
1873
- size: "small",
1874
- disabled: true,
1875
- style: { pointerEvents: "none" },
1876
- value: opConfig?.rightDisplay || I18n11.t("Empty")
1877
- }
1878
- ))));
1879
- }
1880
-
1881
- // src/components/batch-outputs/index.tsx
1882
- import React23 from "react";
1883
- import { Button as Button3, Input as Input5 } from "@douyinfe/semi-ui";
1884
- import { IconDelete, IconPlus as IconPlus2 } from "@douyinfe/semi-icons";
1885
-
1886
- // src/hooks/use-object-list/index.tsx
1887
- import { useEffect as useEffect4, useState as useState5 } from "react";
1888
- import { nanoid } from "nanoid";
1889
- import { difference as difference2, get, isObject as isObject2, set } from "lodash";
1890
- function genId2() {
1891
- return nanoid();
1892
- }
1893
- function useObjectList({
1894
- value,
1895
- onChange,
1896
- sortIndexKey
1897
- }) {
1898
- const [list, setList] = useState5([]);
1899
- useEffect4(() => {
1900
- setList((_prevList) => {
1901
- const newKeys = Object.entries(value || {}).sort((a, b) => get(a[1], sortIndexKey || 0) - get(b[1], sortIndexKey || 0)).map(([key]) => key);
1902
- const oldKeys = _prevList.map((item) => item.key).filter(Boolean);
1903
- const addKeys = difference2(newKeys, oldKeys);
1904
- return _prevList.filter((item) => !item.key || newKeys.includes(item.key)).map((item) => ({
1905
- id: item.id,
1906
- key: item.key,
1907
- value: item.key ? value?.[item.key] : item.value
1908
- })).concat(
1909
- addKeys.map((_key) => ({
1910
- id: genId2(),
1911
- key: _key,
1912
- value: value?.[_key]
1913
- }))
1914
- );
1915
- });
1916
- }, [value]);
1917
- const add = () => {
1918
- setList((prevList) => [
1919
- ...prevList,
1920
- {
1921
- id: genId2()
1922
- }
1923
- ]);
1924
- };
1925
- const updateValue = (itemId, value2) => {
1926
- setList((prevList) => {
1927
- const nextList = prevList.map((_item) => {
1928
- if (_item.id === itemId) {
1929
- return {
1930
- ..._item,
1931
- value: value2
1932
- };
1933
- }
1934
- return _item;
1935
- });
1936
- onChange(
1937
- Object.fromEntries(
1938
- nextList.filter((item) => item.key).map((item) => [item.key, item.value]).map((_res, idx) => {
1939
- if (isObject2(_res[1]) && sortIndexKey) {
1940
- set(_res[1], sortIndexKey, idx);
1941
- }
1942
- return _res;
1943
- })
1944
- )
1945
- );
1946
- return nextList;
1947
- });
1948
- };
1949
- const updateKey = (itemId, key) => {
1950
- setList((prevList) => {
1951
- const nextList = prevList.map((_item) => {
1952
- if (_item.id === itemId) {
1953
- return {
1954
- ..._item,
1955
- key
1956
- };
1957
- }
1958
- return _item;
1959
- });
1960
- onChange(
1961
- Object.fromEntries(
1962
- nextList.filter((item) => item.key).map((item) => [item.key, item.value])
1963
- )
1964
- );
1965
- return nextList;
1966
- });
1967
- };
1968
- const remove = (itemId) => {
1969
- setList((prevList) => {
1970
- const nextList = prevList.filter((_item) => _item.id !== itemId);
1971
- onChange(
1972
- Object.fromEntries(
1973
- nextList.filter((item) => item.key).map((item) => [item.key, item.value])
1974
- )
1975
- );
1976
- return nextList;
1977
- });
1978
- };
1979
- return { list, add, updateKey, updateValue, remove };
1980
- }
1981
-
1982
- // src/components/batch-outputs/styles.tsx
1983
- import styled6 from "styled-components";
1984
- var UIRows = styled6.div`
1985
- display: flex;
1986
- flex-direction: column;
1987
- gap: 10px;
1988
- margin-bottom: 10px;
1989
- `;
1990
- var UIRow2 = styled6.div`
1991
- display: flex;
1992
- align-items: center;
1993
- gap: 5px;
1994
- `;
1995
-
1996
- // src/components/batch-outputs/index.tsx
1997
- function BatchOutputs(props) {
1998
- const { readonly, style } = props;
1999
- const { list, add, updateKey, updateValue, remove } = useObjectList(props);
2000
- return /* @__PURE__ */ React23.createElement("div", null, /* @__PURE__ */ React23.createElement(UIRows, { style }, list.map((item) => /* @__PURE__ */ React23.createElement(UIRow2, { key: item.id }, /* @__PURE__ */ React23.createElement(
2001
- Input5,
2002
- {
2003
- style: { width: 100 },
2004
- disabled: readonly,
2005
- size: "small",
2006
- value: item.key,
2007
- onChange: (v) => updateKey(item.id, v)
2008
- }
2009
- ), /* @__PURE__ */ React23.createElement(
2010
- InjectVariableSelector,
2011
- {
2012
- style: { flexGrow: 1 },
2013
- readonly,
2014
- value: item.value?.content,
2015
- onChange: (v) => updateValue(item.id, { type: "ref", content: v })
2016
- }
2017
- ), /* @__PURE__ */ React23.createElement(
2018
- Button3,
2019
- {
2020
- disabled: readonly,
2021
- icon: /* @__PURE__ */ React23.createElement(IconDelete, null),
2022
- size: "small",
2023
- onClick: () => remove(item.id)
2024
- }
2025
- )))), /* @__PURE__ */ React23.createElement(Button3, { disabled: readonly, icon: /* @__PURE__ */ React23.createElement(IconPlus2, null), size: "small", onClick: add }, "Add"));
2026
- }
2027
-
2028
- // src/components/prompt-editor/index.tsx
2029
- import React24, { useEffect as useEffect5, useRef as useRef2 } from "react";
2030
- import { Renderer, EditorProvider as EditorProvider2, ActiveLinePlaceholder as ActiveLinePlaceholder2 } from "@coze-editor/editor/react";
2031
- import preset2 from "@coze-editor/editor/preset-prompt";
2032
-
2033
- // src/components/prompt-editor/styles.tsx
2034
- import styled7, { css as css3 } from "styled-components";
2035
- var UIContainer4 = styled7.div`
2036
- background-color: var(--semi-color-fill-0);
2037
- padding-left: 10px;
2038
- padding-right: 6px;
2039
-
2040
- ${({ $hasError }) => $hasError && css3`
2041
- border: 1px solid var(--semi-color-danger-6);
2042
- `}
2043
- `;
2044
-
2045
- // src/components/prompt-editor/extensions/markdown.tsx
2046
- import { useLayoutEffect } from "react";
2047
- import { useInjector } from "@coze-editor/editor/react";
2048
- import { astDecorator } from "@coze-editor/editor";
2049
- import { EditorView as EditorView2 } from "@codemirror/view";
2050
- function MarkdownHighlight() {
2051
- const injector = useInjector();
2052
- useLayoutEffect(
2053
- () => injector.inject([
2054
- astDecorator.whole.of((cursor) => {
2055
- if (cursor.name.startsWith("ATXHeading")) {
2056
- return {
2057
- type: "className",
2058
- className: "heading"
2059
- };
2060
- }
2061
- if (cursor.name === "Emphasis") {
2062
- return {
2063
- type: "className",
2064
- className: "emphasis"
2065
- };
2066
- }
2067
- if (cursor.name === "StrongEmphasis") {
2068
- return {
2069
- type: "className",
2070
- className: "strong-emphasis"
2071
- };
2072
- }
2073
- if (cursor.name === "ListMark" || cursor.name === "QuoteMark") {
2074
- return {
2075
- type: "className",
2076
- className: "mark"
2077
- };
2078
- }
2079
- }),
2080
- EditorView2.theme({
2081
- ".heading": {
2082
- color: "#00818C",
2083
- fontWeight: "bold"
2084
- },
2085
- ".emphasis": {
2086
- fontStyle: "italic"
2087
- },
2088
- ".strong-emphasis": {
2089
- fontWeight: "bold"
2090
- },
2091
- ".mark": {
2092
- color: "#4E40E5"
2093
- }
2094
- })
2095
- ]),
2096
- [injector]
2097
- );
2098
- return null;
2099
- }
2100
- var markdown_default = MarkdownHighlight;
2101
-
2102
- // src/components/prompt-editor/extensions/language-support.tsx
2103
- import { useLayoutEffect as useLayoutEffect2 } from "react";
2104
- import { useInjector as useInjector2 } from "@coze-editor/editor/react";
2105
- import { languageSupport } from "@coze-editor/editor/preset-prompt";
2106
- function LanguageSupport() {
2107
- const injector = useInjector2();
2108
- useLayoutEffect2(() => injector.inject([languageSupport]), [injector]);
2109
- return null;
2110
- }
2111
- var language_support_default = LanguageSupport;
2112
-
2113
- // src/components/prompt-editor/extensions/jinja.tsx
2114
- import { useLayoutEffect as useLayoutEffect3 } from "react";
2115
- import { useInjector as useInjector3 } from "@coze-editor/editor/react";
2116
- import { astDecorator as astDecorator2 } from "@coze-editor/editor";
2117
- import { EditorView as EditorView3 } from "@codemirror/view";
2118
- function JinjaHighlight() {
2119
- const injector = useInjector3();
2120
- useLayoutEffect3(
2121
- () => injector.inject([
2122
- astDecorator2.whole.of((cursor) => {
2123
- if (cursor.name === "JinjaStatementStart" || cursor.name === "JinjaStatementEnd") {
2124
- return {
2125
- type: "className",
2126
- className: "jinja-statement-bracket"
2127
- };
2128
- }
2129
- if (cursor.name === "JinjaComment") {
2130
- return {
2131
- type: "className",
2132
- className: "jinja-comment"
2133
- };
2134
- }
2135
- if (cursor.name === "JinjaExpression") {
2136
- return {
2137
- type: "className",
2138
- className: "jinja-expression"
2139
- };
2140
- }
2141
- }),
2142
- EditorView3.theme({
2143
- ".jinja-statement-bracket": {
2144
- color: "#D1009D"
2145
- },
2146
- ".jinja-comment": {
2147
- color: "#0607094D"
2148
- },
2149
- ".jinja-expression": {
2150
- color: "#4E40E5"
2151
- }
2152
- })
2153
- ]),
2154
- [injector]
2155
- );
2156
- return null;
2157
- }
2158
- var jinja_default = JinjaHighlight;
2159
-
2160
- // src/components/prompt-editor/index.tsx
2161
- function PromptEditor(props) {
2162
- const {
2163
- value,
2164
- onChange,
2165
- readonly,
2166
- placeholder,
2167
- activeLinePlaceholder,
2168
- style,
2169
- hasError,
2170
- children,
2171
- disableMarkdownHighlight
2172
- } = props || {};
2173
- const editorRef = useRef2(null);
2174
- useEffect5(() => {
2175
- if (editorRef.current?.getValue() !== value?.content) {
2176
- editorRef.current?.setValue(String(value?.content || ""));
2177
- }
2178
- }, [value]);
2179
- return /* @__PURE__ */ React24.createElement(UIContainer4, { $hasError: hasError, style }, /* @__PURE__ */ React24.createElement(EditorProvider2, null, /* @__PURE__ */ React24.createElement(
2180
- Renderer,
2181
- {
2182
- didMount: (editor) => {
2183
- editorRef.current = editor;
2184
- },
2185
- plugins: preset2,
2186
- defaultValue: String(value?.content),
2187
- options: {
2188
- readOnly: readonly,
2189
- editable: !readonly,
2190
- placeholder
2191
- },
2192
- onChange: (e) => {
2193
- onChange({ type: "template", content: e.value });
2194
- }
2195
- }
2196
- ), activeLinePlaceholder && /* @__PURE__ */ React24.createElement(ActiveLinePlaceholder2, null, activeLinePlaceholder), !disableMarkdownHighlight && /* @__PURE__ */ React24.createElement(markdown_default, null), /* @__PURE__ */ React24.createElement(language_support_default, null), /* @__PURE__ */ React24.createElement(jinja_default, null), children));
2197
- }
2198
-
2199
- // src/components/prompt-editor-with-variables/index.tsx
2200
- import React27 from "react";
2201
-
2202
- // src/components/prompt-editor-with-variables/extensions/variable-tree.tsx
2203
- import React25, { useEffect as useEffect6, useState as useState6 } from "react";
2204
- import { Popover as Popover2, Tree } from "@douyinfe/semi-ui";
2205
- import {
2206
- Mention,
2207
- getCurrentMentionReplaceRange,
2208
- useEditor,
2209
- PositionMirror
2210
- } from "@coze-editor/editor/react";
2211
- function VariableTree() {
2212
- const [posKey, setPosKey] = useState6("");
2213
- const [visible, setVisible] = useState6(false);
2214
- const [position, setPosition] = useState6(-1);
2215
- const editor = useEditor();
2216
- function insert(variablePath) {
2217
- const range = getCurrentMentionReplaceRange(editor.$view.state);
2218
- if (!range) {
2219
- return;
2220
- }
2221
- editor.replaceText({
2222
- ...range,
2223
- text: "{{" + variablePath + "}}"
2224
- });
2225
- setVisible(false);
2226
- }
2227
- function handleOpenChange(e) {
2228
- setPosition(e.state.selection.main.head);
2229
- setVisible(e.value);
2230
- }
2231
- useEffect6(() => {
2232
- if (!editor) {
2233
- return;
2234
- }
2235
- }, [editor, visible]);
2236
- const treeData = useVariableTree({});
2237
- return /* @__PURE__ */ React25.createElement(React25.Fragment, null, /* @__PURE__ */ React25.createElement(Mention, { triggerCharacters: ["{", "{}", "@"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React25.createElement(
2238
- Popover2,
2239
- {
2240
- visible,
2241
- trigger: "custom",
2242
- position: "topLeft",
2243
- rePosKey: posKey,
2244
- content: /* @__PURE__ */ React25.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ React25.createElement(
2245
- Tree,
2246
- {
2247
- treeData,
2248
- onSelect: (v) => {
2249
- insert(v);
2250
- }
2251
- }
2252
- ))
2253
- },
2254
- /* @__PURE__ */ React25.createElement(
2255
- PositionMirror,
2256
- {
2257
- position,
2258
- onChange: () => setPosKey(String(Math.random()))
2259
- }
2260
- )
2261
- ));
2262
- }
2263
-
2264
- // src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
2265
- import ReactDOM from "react-dom";
2266
- import React26, { useLayoutEffect as useLayoutEffect4 } from "react";
2267
- import { isEqual, last } from "lodash";
2268
- import {
2269
- Disposable,
2270
- DisposableCollection,
2271
- useCurrentScope
2272
- } from "@flowgram.ai/editor";
2273
- import { Popover as Popover3 } from "@douyinfe/semi-ui";
2274
- import { IconIssueStroked as IconIssueStroked2 } from "@douyinfe/semi-icons";
2275
- import { useInjector as useInjector4 } from "@coze-editor/editor/react";
2276
- import {
2277
- Decoration,
2278
- EditorView as EditorView4,
2279
- MatchDecorator,
2280
- ViewPlugin,
2281
- WidgetType
2282
- } from "@codemirror/view";
2283
-
2284
- // src/components/prompt-editor-with-variables/styles.tsx
2285
- import styled8 from "styled-components";
2286
- import { Tag as Tag2 } from "@douyinfe/semi-ui";
2287
- var UIRootTitle2 = styled8.div`
2288
- margin-right: 4px;
2289
- min-width: 20px;
2290
- overflow: hidden;
2291
- text-overflow: ellipsis;
2292
- white-space: nowrap;
2293
- color: var(--semi-color-text-2);
2294
- `;
2295
- var UIVarName2 = styled8.div`
2296
- overflow: hidden;
2297
- text-overflow: ellipsis;
2298
- white-space: nowrap;
2299
- `;
2300
- var UITag2 = styled8(Tag2)`
2301
- display: inline-flex;
2302
- align-items: center;
2303
- justify-content: flex-start;
2304
- max-width: 300px;
2305
-
2306
- & .semi-tag-content-center {
2307
- justify-content: flex-start;
2308
- }
2309
-
2310
- &.semi-tag {
2311
- margin: 0 5px;
2312
- }
2313
- `;
2314
- var UIPopoverContent2 = styled8.div`
2315
- padding: 10px;
2316
- display: inline-flex;
2317
- align-items: center;
2318
- justify-content: flex-start;
2319
- `;
2320
-
2321
- // src/components/prompt-editor-with-variables/extensions/variable-tag.tsx
2322
- var VariableTagWidget = class extends WidgetType {
2323
- constructor({ keyPath, scope }) {
2324
- super();
2325
- this.toDispose = new DisposableCollection();
2326
- this.renderIcon = (icon) => {
2327
- if (typeof icon === "string") {
2328
- return /* @__PURE__ */ React26.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: icon });
2329
- }
2330
- return icon;
2331
- };
2332
- this.keyPath = keyPath;
2333
- this.scope = scope;
2334
- }
2335
- renderReact(jsx) {
2336
- ReactDOM.render(jsx, this.rootDOM);
2337
- }
2338
- renderVariable(v) {
2339
- if (!v) {
2340
- this.renderReact(
2341
- /* @__PURE__ */ React26.createElement(UITag2, { prefixIcon: /* @__PURE__ */ React26.createElement(IconIssueStroked2, null), color: "amber" }, "Unknown")
2342
- );
2343
- return;
2344
- }
2345
- const rootField = last(v.parentFields) || v;
2346
- const isRoot = v.parentFields.length === 0;
2347
- const rootTitle = /* @__PURE__ */ React26.createElement(UIRootTitle2, null, rootField?.meta.title ? `${rootField.meta.title} ${isRoot ? "" : "-"} ` : "");
2348
- const rootIcon = this.renderIcon(rootField?.meta.icon);
2349
- this.renderReact(
2350
- /* @__PURE__ */ React26.createElement(
2351
- Popover3,
2352
- {
2353
- content: /* @__PURE__ */ React26.createElement(UIPopoverContent2, null, rootIcon, rootTitle, /* @__PURE__ */ React26.createElement(UIVarName2, null, v?.keyPath.slice(1).join(".")))
2354
- },
2355
- /* @__PURE__ */ React26.createElement(UITag2, { prefixIcon: rootIcon }, rootTitle, !isRoot && /* @__PURE__ */ React26.createElement(UIVarName2, null, v?.key))
2356
- )
2357
- );
2358
- }
2359
- toDOM(view) {
2360
- const dom = document.createElement("span");
2361
- this.rootDOM = dom;
2362
- this.toDispose.push(
2363
- Disposable.create(() => {
2364
- ReactDOM.unmountComponentAtNode(this.rootDOM);
2365
- })
2366
- );
2367
- this.toDispose.push(
2368
- this.scope.available.trackByKeyPath(
2369
- this.keyPath,
2370
- (v) => {
2371
- this.renderVariable(v);
2372
- },
2373
- { triggerOnInit: false }
2374
- )
2375
- );
2376
- this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
2377
- return dom;
2378
- }
2379
- eq(other) {
2380
- return isEqual(this.keyPath, other.keyPath);
2381
- }
2382
- ignoreEvent() {
2383
- return false;
2384
- }
2385
- destroy(dom) {
2386
- this.toDispose.dispose();
2387
- }
2388
- };
2389
- function VariableTagInject() {
2390
- const injector = useInjector4();
2391
- const scope = useCurrentScope();
2392
- useLayoutEffect4(() => {
2393
- const atMatcher = new MatchDecorator({
2394
- regexp: /\{\{([^\}]+)\}\}/g,
2395
- decoration: (match) => Decoration.replace({
2396
- widget: new VariableTagWidget({
2397
- keyPath: match[1]?.split(".") ?? [],
2398
- scope
2399
- })
2400
- })
2401
- });
2402
- return injector.inject([
2403
- ViewPlugin.fromClass(
2404
- class {
2405
- constructor(view) {
2406
- this.view = view;
2407
- this.decorations = atMatcher.createDeco(view);
2408
- }
2409
- update() {
2410
- this.decorations = atMatcher.createDeco(this.view);
2411
- }
2412
- },
2413
- {
2414
- decorations: (p) => p.decorations,
2415
- provide(p) {
2416
- return EditorView4.atomicRanges.of(
2417
- (view) => view.plugin(p)?.decorations ?? Decoration.none
2418
- );
2419
- }
2420
- }
2421
- )
2422
- ]);
2423
- }, [injector]);
2424
- return null;
2425
- }
2426
-
2427
- // src/components/prompt-editor-with-variables/index.tsx
2428
- function PromptEditorWithVariables(props) {
2429
- return /* @__PURE__ */ React27.createElement(PromptEditor, { ...props }, /* @__PURE__ */ React27.createElement(VariableTree, null), /* @__PURE__ */ React27.createElement(VariableTagInject, null));
2430
- }
2431
-
2432
- // src/components/prompt-editor-with-inputs/index.tsx
2433
- import React30 from "react";
2434
-
2435
- // src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
2436
- import React29, { useEffect as useEffect7, useState as useState7 } from "react";
2437
- import { Popover as Popover4 } from "@douyinfe/semi-ui";
2438
- import {
2439
- Mention as Mention2,
2440
- getCurrentMentionReplaceRange as getCurrentMentionReplaceRange2,
2441
- useEditor as useEditor2,
2442
- PositionMirror as PositionMirror2
2443
- } from "@coze-editor/editor/react";
2444
-
2445
- // src/components/prompt-editor-with-inputs/inputs-picker.tsx
2446
- import React28, { useMemo as useMemo9 } from "react";
2447
- import { last as last2 } from "lodash";
2448
- import {
2449
- ASTMatch as ASTMatch3,
2450
- useScopeAvailable as useScopeAvailable3
2451
- } from "@flowgram.ai/editor";
2452
- import { Tree as Tree2 } from "@douyinfe/semi-ui";
2453
- function InputsPicker({
2454
- inputsValues,
2455
- onSelect
2456
- }) {
2457
- const available = useScopeAvailable3();
2458
- const getArrayDrilldown = (type, depth = 1) => {
2459
- if (ASTMatch3.isArray(type.items)) {
2460
- return getArrayDrilldown(type.items, depth + 1);
2461
- }
2462
- return { type: type.items, depth };
2463
- };
2464
- const renderVariable = (variable, keyPath) => {
2465
- let type = variable?.type;
2466
- let children;
2467
- if (ASTMatch3.isObject(type)) {
2468
- children = (type.properties || []).map((_property) => renderVariable(_property, [...keyPath, _property.key])).filter(Boolean);
2469
- }
2470
- if (ASTMatch3.isArray(type)) {
2471
- const drilldown = getArrayDrilldown(type);
2472
- if (ASTMatch3.isObject(drilldown.type)) {
2473
- children = (drilldown.type.properties || []).map(
2474
- (_property) => renderVariable(_property, [
2475
- ...keyPath,
2476
- ...new Array(drilldown.depth).fill("[0]"),
2477
- _property.key
2478
- ])
2479
- ).filter(Boolean);
2480
- }
2481
- }
2482
- const key = keyPath.map((_key, idx) => _key === "[0]" || idx === 0 ? _key : `.${_key}`).join("");
2483
- return {
2484
- key,
2485
- label: last2(keyPath),
2486
- value: key,
2487
- children
2488
- };
2489
- };
2490
- const treeData = useMemo9(
2491
- () => Object.entries(inputsValues).map(([key, value]) => {
2492
- if (value?.type === "ref") {
2493
- const variable = available.getByKeyPath(value.content || []);
2494
- if (variable) {
2495
- return renderVariable(variable, [key]);
2496
- }
2497
- }
2498
- return {
2499
- key,
2500
- value: key,
2501
- label: key
2502
- };
2503
- }),
2504
- []
2505
- );
2506
- return /* @__PURE__ */ React28.createElement(Tree2, { treeData, onSelect: (v) => onSelect(v) });
2507
- }
2508
-
2509
- // src/components/prompt-editor-with-inputs/extensions/inputs-tree.tsx
2510
- function InputsTree({ inputsValues }) {
2511
- const [posKey, setPosKey] = useState7("");
2512
- const [visible, setVisible] = useState7(false);
2513
- const [position, setPosition] = useState7(-1);
2514
- const editor = useEditor2();
2515
- function insert(variablePath) {
2516
- const range = getCurrentMentionReplaceRange2(editor.$view.state);
2517
- if (!range) {
2518
- return;
2519
- }
2520
- editor.replaceText({
2521
- ...range,
2522
- text: "{{" + variablePath + "}}"
2523
- });
2524
- setVisible(false);
2525
- }
2526
- function handleOpenChange(e) {
2527
- setPosition(e.state.selection.main.head);
2528
- setVisible(e.value);
2529
- }
2530
- useEffect7(() => {
2531
- if (!editor) {
2532
- return;
2533
- }
2534
- }, [editor, visible]);
2535
- return /* @__PURE__ */ React29.createElement(React29.Fragment, null, /* @__PURE__ */ React29.createElement(Mention2, { triggerCharacters: ["{", "{}", "@"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React29.createElement(
2536
- Popover4,
2537
- {
2538
- visible,
2539
- trigger: "custom",
2540
- position: "topLeft",
2541
- rePosKey: posKey,
2542
- content: /* @__PURE__ */ React29.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ React29.createElement(
2543
- InputsPicker,
2544
- {
2545
- inputsValues,
2546
- onSelect: (v) => {
2547
- insert(v);
2548
- }
2549
- }
2550
- ))
2551
- },
2552
- /* @__PURE__ */ React29.createElement(
2553
- PositionMirror2,
2554
- {
2555
- position,
2556
- onChange: () => setPosKey(String(Math.random()))
2557
- }
2558
- )
2559
- ));
2560
- }
2561
-
2562
- // src/components/prompt-editor-with-inputs/index.tsx
2563
- function PromptEditorWithInputs({ inputsValues, ...restProps }) {
2564
- return /* @__PURE__ */ React30.createElement(PromptEditor, { ...restProps }, /* @__PURE__ */ React30.createElement(InputsTree, { inputsValues }));
2565
- }
2566
-
2567
- // src/components/json-editor-with-variables/index.tsx
2568
- import React33 from "react";
2569
- import { transformerCreator } from "@coze-editor/editor/preset-code";
2570
-
2571
- // src/components/json-editor-with-variables/extensions/variable-tree.tsx
2572
- import React31, { useEffect as useEffect8, useState as useState8 } from "react";
2573
- import { Popover as Popover5, Tree as Tree3 } from "@douyinfe/semi-ui";
2574
- import {
2575
- Mention as Mention3,
2576
- getCurrentMentionReplaceRange as getCurrentMentionReplaceRange3,
2577
- useEditor as useEditor3,
2578
- PositionMirror as PositionMirror3
2579
- } from "@coze-editor/editor/react";
2580
- function VariableTree2() {
2581
- const [posKey, setPosKey] = useState8("");
2582
- const [visible, setVisible] = useState8(false);
2583
- const [position, setPosition] = useState8(-1);
2584
- const editor = useEditor3();
2585
- function insert(variablePath) {
2586
- const range = getCurrentMentionReplaceRange3(editor.$view.state);
2587
- if (!range) {
2588
- return;
2589
- }
2590
- editor.replaceText({
2591
- ...range,
2592
- text: "{{" + variablePath + "}}"
2593
- });
2594
- setVisible(false);
2595
- }
2596
- function handleOpenChange(e) {
2597
- setPosition(e.state.selection.main.head);
2598
- setVisible(e.value);
2599
- }
2600
- useEffect8(() => {
2601
- if (!editor) {
2602
- return;
2603
- }
2604
- }, [editor, visible]);
2605
- const treeData = useVariableTree({});
2606
- return /* @__PURE__ */ React31.createElement(React31.Fragment, null, /* @__PURE__ */ React31.createElement(Mention3, { triggerCharacters: ["@"], onOpenChange: handleOpenChange }), /* @__PURE__ */ React31.createElement(
2607
- Popover5,
2608
- {
2609
- visible,
2610
- trigger: "custom",
2611
- position: "topLeft",
2612
- rePosKey: posKey,
2613
- content: /* @__PURE__ */ React31.createElement("div", { style: { width: 300 } }, /* @__PURE__ */ React31.createElement(
2614
- Tree3,
2615
- {
2616
- treeData,
2617
- onSelect: (v) => {
2618
- insert(v);
2619
- }
2620
- }
2621
- ))
2622
- },
2623
- /* @__PURE__ */ React31.createElement(
2624
- PositionMirror3,
2625
- {
2626
- position,
2627
- onChange: () => setPosKey(String(Math.random()))
2628
- }
2629
- )
2630
- ));
2631
- }
2632
-
2633
- // src/components/json-editor-with-variables/extensions/variable-tag.tsx
2634
- import React32, { useLayoutEffect as useLayoutEffect5 } from "react";
2635
- import { createRoot } from "react-dom/client";
2636
- import { isEqual as isEqual2, last as last3 } from "lodash";
2637
- import {
2638
- Disposable as Disposable2,
2639
- DisposableCollection as DisposableCollection2,
2640
- useCurrentScope as useCurrentScope2
2641
- } from "@flowgram.ai/editor";
2642
- import { Popover as Popover6 } from "@douyinfe/semi-ui";
2643
- import { IconIssueStroked as IconIssueStroked3 } from "@douyinfe/semi-icons";
2644
- import { useInjector as useInjector5 } from "@coze-editor/editor/react";
2645
- import {
2646
- Decoration as Decoration2,
2647
- EditorView as EditorView5,
2648
- MatchDecorator as MatchDecorator2,
2649
- ViewPlugin as ViewPlugin2,
2650
- WidgetType as WidgetType2
2651
- } from "@codemirror/view";
2652
-
2653
- // src/components/json-editor-with-variables/styles.tsx
2654
- import styled9 from "styled-components";
2655
- import { Tag as Tag3 } from "@douyinfe/semi-ui";
2656
- var UIRootTitle3 = styled9.div`
2657
- margin-right: 4px;
2658
- min-width: 20px;
2659
- overflow: hidden;
2660
- text-overflow: ellipsis;
2661
- white-space: nowrap;
2662
- color: var(--semi-color-text-2);
2663
- `;
2664
- var UIVarName3 = styled9.div`
2665
- overflow: hidden;
2666
- text-overflow: ellipsis;
2667
- white-space: nowrap;
2668
- `;
2669
- var UITag3 = styled9(Tag3)`
2670
- display: inline-flex;
2671
- align-items: center;
2672
- justify-content: flex-start;
2673
- max-width: 300px;
2674
-
2675
- & .semi-tag-content-center {
2676
- justify-content: flex-start;
2677
- }
2678
-
2679
- &.semi-tag {
2680
- margin: 0 5px;
2681
- }
2682
- `;
2683
- var UIPopoverContent3 = styled9.div`
2684
- padding: 10px;
2685
- display: inline-flex;
2686
- align-items: center;
2687
- justify-content: flex-start;
2688
- `;
2689
-
2690
- // src/components/json-editor-with-variables/extensions/variable-tag.tsx
2691
- var VariableTagWidget2 = class extends WidgetType2 {
2692
- constructor({ keyPath, scope }) {
2693
- super();
2694
- this.toDispose = new DisposableCollection2();
2695
- this.renderIcon = (icon) => {
2696
- if (typeof icon === "string") {
2697
- return /* @__PURE__ */ React32.createElement("img", { style: { marginRight: 8 }, width: 12, height: 12, src: icon });
2698
- }
2699
- return icon;
2700
- };
2701
- this.keyPath = keyPath;
2702
- this.scope = scope;
2703
- }
2704
- renderVariable(v) {
2705
- if (!v) {
2706
- this.root.render(
2707
- /* @__PURE__ */ React32.createElement(UITag3, { prefixIcon: /* @__PURE__ */ React32.createElement(IconIssueStroked3, null), color: "amber" }, "Unknown")
2708
- );
2709
- return;
2710
- }
2711
- const rootField = last3(v.parentFields);
2712
- const rootTitle = /* @__PURE__ */ React32.createElement(UIRootTitle3, null, rootField?.meta.title ? `${rootField.meta.title} -` : "");
2713
- const rootIcon = this.renderIcon(rootField?.meta.icon);
2714
- this.root.render(
2715
- /* @__PURE__ */ React32.createElement(
2716
- Popover6,
2717
- {
2718
- content: /* @__PURE__ */ React32.createElement(UIPopoverContent3, null, rootIcon, rootTitle, /* @__PURE__ */ React32.createElement(UIVarName3, null, v?.keyPath.slice(1).join(".")))
2719
- },
2720
- /* @__PURE__ */ React32.createElement(UITag3, { prefixIcon: rootIcon }, rootTitle, /* @__PURE__ */ React32.createElement(UIVarName3, null, v?.key))
2721
- )
2722
- );
2723
- }
2724
- toDOM(view) {
2725
- const dom = document.createElement("span");
2726
- this.root = createRoot(dom);
2727
- this.toDispose.push(
2728
- Disposable2.create(() => {
2729
- this.root.unmount();
2730
- })
2731
- );
2732
- this.toDispose.push(
2733
- this.scope.available.trackByKeyPath(
2734
- this.keyPath,
2735
- (v) => {
2736
- this.renderVariable(v);
2737
- },
2738
- { triggerOnInit: false }
2739
- )
2740
- );
2741
- this.renderVariable(this.scope.available.getByKeyPath(this.keyPath));
2742
- return dom;
2743
- }
2744
- eq(other) {
2745
- return isEqual2(this.keyPath, other.keyPath);
2746
- }
2747
- ignoreEvent() {
2748
- return false;
2749
- }
2750
- destroy(dom) {
2751
- this.toDispose.dispose();
2752
- }
2753
- };
2754
- function VariableTagInject2() {
2755
- const injector = useInjector5();
2756
- const scope = useCurrentScope2();
2757
- useLayoutEffect5(() => {
2758
- const atMatcher = new MatchDecorator2({
2759
- regexp: /\{\{([^\}]+)\}\}/g,
2760
- decoration: (match) => Decoration2.replace({
2761
- widget: new VariableTagWidget2({
2762
- keyPath: match[1]?.split(".") ?? [],
2763
- scope
2764
- })
2765
- })
2766
- });
2767
- return injector.inject([
2768
- ViewPlugin2.fromClass(
2769
- class {
2770
- constructor(view) {
2771
- this.view = view;
2772
- this.decorations = atMatcher.createDeco(view);
2773
- }
2774
- update() {
2775
- this.decorations = atMatcher.createDeco(this.view);
2776
- }
2777
- },
2778
- {
2779
- decorations: (p) => p.decorations,
2780
- provide(p) {
2781
- return EditorView5.atomicRanges.of(
2782
- (view) => view.plugin(p)?.decorations ?? Decoration2.none
2783
- );
2784
- }
2785
- }
2786
- )
2787
- ]);
2788
- }, [injector]);
2789
- return null;
2790
- }
2791
-
2792
- // src/components/json-editor-with-variables/index.tsx
2793
- function findAllMatches(inputString, regex) {
2794
- const globalRegex = new RegExp(
2795
- regex,
2796
- regex.flags.includes("g") ? regex.flags : regex.flags + "g"
2797
- );
2798
- let match;
2799
- const matches = [];
2800
- while ((match = globalRegex.exec(inputString)) !== null) {
2801
- if (match.index === globalRegex.lastIndex) {
2802
- globalRegex.lastIndex++;
2803
- }
2804
- matches.push({
2805
- match: match[0],
2806
- range: [match.index, match.index + match[0].length]
2807
- });
2808
- }
2809
- return matches;
2810
- }
2811
- var transformer = transformerCreator((text) => {
2812
- const originalSource = text.toString();
2813
- const matches = findAllMatches(originalSource, /\{\{([^\}]*)\}\}/g);
2814
- if (matches.length > 0) {
2815
- matches.forEach(({ range }) => {
2816
- text.replaceRange(range[0], range[1], "null");
2817
- });
2818
- }
2819
- return text;
2820
- });
2821
- function JsonEditorWithVariables(props) {
2822
- return /* @__PURE__ */ React33.createElement(
2823
- CodeEditor,
2824
- {
2825
- languageId: "json",
2826
- activeLinePlaceholder: "Press '@' to Select variable",
2827
- ...props,
2828
- options: {
2829
- transformer,
2830
- ...props.options || {}
2831
- }
2832
- },
2833
- /* @__PURE__ */ React33.createElement(VariableTree2, null),
2834
- /* @__PURE__ */ React33.createElement(VariableTagInject2, null)
2835
- );
2836
- }
2837
-
2838
- // src/components/inputs-values/index.tsx
2839
- import React35 from "react";
2840
- import { I18n as I18n12 } from "@flowgram.ai/editor";
2841
- import { Button as Button4, IconButton as IconButton4 } from "@douyinfe/semi-ui";
2842
- import { IconDelete as IconDelete2, IconPlus as IconPlus3 } from "@douyinfe/semi-icons";
2843
-
2844
- // src/components/inputs-values/styles.tsx
2845
- import styled10 from "styled-components";
2846
- var UIRows2 = styled10.div`
2847
- display: flex;
2848
- flex-direction: column;
2849
- gap: 10px;
2850
- margin-bottom: 10px;
2851
- `;
2852
- var UIRow3 = styled10.div`
2853
- display: flex;
2854
- align-items: center;
2855
- gap: 5px;
2856
- `;
2857
-
2858
- // src/components/inputs-values/components/blur-input.tsx
2859
- import React34, { useEffect as useEffect9, useState as useState9 } from "react";
2860
- import Input6 from "@douyinfe/semi-ui/lib/es/input";
2861
- function BlurInput2(props) {
2862
- const [value, setValue] = useState9("");
2863
- useEffect9(() => {
2864
- setValue(props.value);
2865
- }, [props.value]);
2866
- return /* @__PURE__ */ React34.createElement(
2867
- Input6,
2868
- {
2869
- ...props,
2870
- value,
2871
- onChange: (value2) => {
2872
- setValue(value2);
2873
- },
2874
- onBlur: (e) => props.onChange?.(value, e)
2875
- }
2876
- );
2877
- }
2878
-
2879
- // src/components/inputs-values/index.tsx
2880
- function InputsValues({
2881
- value,
2882
- onChange,
2883
- style,
2884
- readonly,
2885
- constantProps,
2886
- schema,
2887
- hasError
2888
- }) {
2889
- const { list, updateKey, updateValue, remove, add } = useObjectList({
2890
- value,
2891
- onChange,
2892
- sortIndexKey: "extra.index"
2893
- });
2894
- return /* @__PURE__ */ React35.createElement("div", null, /* @__PURE__ */ React35.createElement(UIRows2, { style }, list.map((item) => /* @__PURE__ */ React35.createElement(UIRow3, { key: item.id }, /* @__PURE__ */ React35.createElement(
2895
- BlurInput2,
2896
- {
2897
- style: { width: 100, minWidth: 100, maxWidth: 100 },
2898
- disabled: readonly,
2899
- size: "small",
2900
- value: item.key,
2901
- onChange: (v) => updateKey(item.id, v),
2902
- placeholder: I18n12.t("Input Key")
2903
- }
2904
- ), /* @__PURE__ */ React35.createElement(
2905
- InjectDynamicValueInput,
2906
- {
2907
- style: { flexGrow: 1 },
2908
- readonly,
2909
- value: item.value,
2910
- onChange: (v) => updateValue(item.id, v),
2911
- schema,
2912
- hasError,
2913
- constantProps: {
2914
- ...constantProps,
2915
- strategies: [...constantProps?.strategies || []]
2916
- }
2917
- }
2918
- ), /* @__PURE__ */ React35.createElement(
2919
- IconButton4,
2920
- {
2921
- disabled: readonly,
2922
- theme: "borderless",
2923
- icon: /* @__PURE__ */ React35.createElement(IconDelete2, { size: "small" }),
2924
- size: "small",
2925
- onClick: () => remove(item.id)
2926
- }
2927
- )))), /* @__PURE__ */ React35.createElement(Button4, { disabled: readonly, icon: /* @__PURE__ */ React35.createElement(IconPlus3, null), size: "small", onClick: add }, "Add"));
2928
- }
2929
-
2930
- // src/components/display-schema-tree/index.tsx
2931
- import React36 from "react";
2932
-
2933
- // src/components/display-schema-tree/styles.tsx
2934
- import styled11, { css as css4 } from "styled-components";
2935
- var TreeRow = styled11.div`
2936
- display: flex;
2937
- align-items: center;
2938
-
2939
- .tree-icon {
2940
- margin-right: 8px;
2941
- width: 14px;
2942
- height: 14px;
2943
- }
2944
-
2945
- height: 27px;
2946
- white-space: nowrap;
2947
- `;
2948
- var HorizontalLine = styled11.div`
2949
- position: relative;
2950
-
2951
- &::before,
2952
- &::after {
2953
- content: '';
2954
- position: absolute;
2955
- background-color: var(--semi-color-text-3);
2956
- }
2957
-
2958
- &::after {
2959
- top: 0px;
2960
- right: 6px;
2961
- width: 15px;
2962
- height: 1px;
2963
- }
2964
- `;
2965
- var TreeTitle = styled11.div`
2966
- // overflow: hidden;
2967
- // text-overflow: ellipsis;
2968
- `;
2969
- var TreeLevel = styled11.div`
2970
- padding-left: 30px;
2971
- position: relative;
2972
-
2973
- /* &::before {
2974
- content: '';
2975
- position: absolute;
2976
- background-color: var(--semi-color-text-3);
2977
- top: 0px;
2978
- bottom: 0px;
2979
- left: -22px;
2980
- width: 1px;
2981
- } */
2982
- `;
2983
- var TreeItem = styled11.div`
2984
- position: relative;
2985
-
2986
- &::before {
2987
- content: '';
2988
- position: absolute;
2989
- background-color: var(--semi-color-text-3);
2990
- }
2991
-
2992
- &:not(:last-child)::before {
2993
- width: 1px;
2994
- top: 0;
2995
- bottom: 0;
2996
- left: -22px;
2997
- }
2998
-
2999
- &:last-child::before {
3000
- width: 1px;
3001
- top: 0;
3002
- height: 14px;
3003
- left: -22px;
3004
- }
3005
-
3006
- ${(props) => props.depth === 0 && css4`
3007
- &::before {
3008
- width: 0px !important;
3009
- }
3010
- `}
3011
- `;
3012
-
3013
- // src/components/display-schema-tree/index.tsx
3014
- function DisplaySchemaTree(props) {
3015
- return /* @__PURE__ */ React36.createElement(SchemaTree, { ...props });
3016
- }
3017
- function SchemaTree(props) {
3018
- const {
3019
- value: schema = {},
3020
- drilldown = true,
3021
- depth = 0,
3022
- showIcon = true,
3023
- parentKey = ""
3024
- } = props || {};
3025
- const typeManager = useTypeManager();
3026
- const config = typeManager.getTypeBySchema(schema);
3027
- const title = typeManager.getComplexText(schema);
3028
- const icon = typeManager?.getDisplayIcon(schema);
3029
- let properties = drilldown && config ? config.getTypeSchemaProperties(schema) : {};
3030
- const childEntries = Object.entries(properties || {});
3031
- return /* @__PURE__ */ React36.createElement(TreeItem, { depth, key: parentKey || "root" }, /* @__PURE__ */ React36.createElement(TreeRow, null, depth !== 0 && /* @__PURE__ */ React36.createElement(HorizontalLine, null), showIcon && icon && React36.cloneElement(icon, {
3032
- className: "tree-icon"
3033
- }), /* @__PURE__ */ React36.createElement(TreeTitle, null, parentKey ? /* @__PURE__ */ React36.createElement(React36.Fragment, null, `${parentKey} (`, title, ")") : title)), childEntries?.length ? /* @__PURE__ */ React36.createElement(TreeLevel, null, childEntries.map(([key, value]) => /* @__PURE__ */ React36.createElement(SchemaTree, { key, ...props, parentKey: key, value, depth: depth + 1 }))) : null);
3034
- }
3035
-
3036
- // src/components/display-outputs/index.tsx
3037
- import React38, { useEffect as useEffect10 } from "react";
3038
- import { JsonSchemaUtils as JsonSchemaUtils5 } from "@flowgram.ai/json-schema";
3039
- import { useCurrentScope as useCurrentScope3, useRefresh } from "@flowgram.ai/editor";
3040
-
3041
- // src/components/display-schema-tag/index.tsx
3042
- import React37 from "react";
3043
- import { Popover as Popover7 } from "@douyinfe/semi-ui";
3044
-
3045
- // src/components/display-schema-tag/styles.ts
3046
- import styled12 from "styled-components";
3047
- import { Tag as Tag4 } from "@douyinfe/semi-ui";
3048
- var PopoverContent = styled12.div`
3049
- padding: 10px;
3050
- `;
3051
- var StyledTag = styled12(Tag4)`
3052
- padding: 4px;
3053
-
3054
- .tag-icon {
3055
- width: 12px;
3056
- height: 12px;
3057
- }
3058
- `;
3059
- var TitleSpan = styled12.span`
3060
- display: inline-block;
3061
- margin-left: 4px;
3062
- margin-top: -1px;
3063
- overflow: hidden;
3064
- text-overflow: ellipsis;
3065
- `;
3066
-
3067
- // src/components/display-schema-tag/index.tsx
3068
- function DisplaySchemaTag({ value = {}, showIconInTree, title, warning }) {
3069
- const typeManager = useTypeManager();
3070
- const icon = typeManager?.getDisplayIcon(value) || typeManager.getDisplayIcon({ type: "unknown" });
3071
- return /* @__PURE__ */ React37.createElement(
3072
- Popover7,
3073
- {
3074
- content: /* @__PURE__ */ React37.createElement(PopoverContent, null, /* @__PURE__ */ React37.createElement(DisplaySchemaTree, { value, typeManager, showIcon: showIconInTree }))
3075
- },
3076
- /* @__PURE__ */ React37.createElement(StyledTag, { color: warning ? "amber" : "white" }, icon && React37.cloneElement(icon, {
3077
- className: "tag-icon"
3078
- }), title && /* @__PURE__ */ React37.createElement(TitleSpan, null, title))
3079
- );
3080
- }
3081
-
3082
- // src/components/display-outputs/styles.ts
3083
- import styled13 from "styled-components";
3084
- var DisplayOutputsWrapper = styled13.div`
3085
- display: flex;
3086
- gap: 5px;
3087
- flex-wrap: wrap;
3088
- `;
3089
-
3090
- // src/components/display-outputs/index.tsx
3091
- function DisplayOutputs({ value, showIconInTree, displayFromScope }) {
3092
- const scope = useCurrentScope3();
3093
- const refresh = useRefresh();
3094
- useEffect10(() => {
3095
- if (!displayFromScope) {
3096
- return () => null;
3097
- }
3098
- const disposable = scope.output.onListOrAnyVarChange(() => {
3099
- refresh();
3100
- });
3101
- return () => {
3102
- disposable.dispose();
3103
- };
3104
- }, [displayFromScope]);
3105
- const properties = displayFromScope ? scope.output.variables?.reduce((acm, curr) => {
3106
- acm = {
3107
- ...acm,
3108
- ...JsonSchemaUtils5.astToSchema(curr.type)?.properties || {}
3109
- };
3110
- return acm;
3111
- }, {}) : value?.properties || {};
3112
- const childEntries = Object.entries(properties || {});
3113
- return /* @__PURE__ */ React38.createElement(DisplayOutputsWrapper, null, childEntries.map(([key, schema]) => /* @__PURE__ */ React38.createElement(
3114
- DisplaySchemaTag,
3115
- {
3116
- key,
3117
- title: key,
3118
- value: schema,
3119
- showIconInTree,
3120
- warning: !schema
3121
- }
3122
- )));
3123
- }
3124
-
3125
- // src/components/display-flow-value/index.tsx
3126
- import React39, { useMemo as useMemo10 } from "react";
3127
- import { JsonSchemaUtils as JsonSchemaUtils6 } from "@flowgram.ai/json-schema";
3128
- import { useScopeAvailable as useScopeAvailable4 } from "@flowgram.ai/editor";
3129
- function DisplayFlowValue({ value, title, showIconInTree }) {
3130
- const available = useScopeAvailable4();
3131
- const variable = value?.type === "ref" ? available.getByKeyPath(value?.content) : void 0;
3132
- const schema = useMemo10(() => {
3133
- if (value?.type === "ref") {
3134
- return JsonSchemaUtils6.astToSchema(variable?.type);
3135
- }
3136
- if (value?.type === "template") {
3137
- return { type: "string" };
3138
- }
3139
- if (value?.type === "constant") {
3140
- if (value?.schema) {
3141
- return value?.schema;
3142
- }
3143
- if (typeof value?.content === "string") {
3144
- return { type: "string" };
3145
- }
3146
- if (typeof value?.content === "number") {
3147
- return { type: "number" };
3148
- }
3149
- if (typeof value?.content === "boolean") {
3150
- return { type: "boolean" };
3151
- }
3152
- }
3153
- return { type: "unknown" };
3154
- }, [value, variable?.hash]);
3155
- return /* @__PURE__ */ React39.createElement(
3156
- DisplaySchemaTag,
3157
- {
3158
- title,
3159
- value: schema,
3160
- showIconInTree,
3161
- warning: value?.type === "ref" && !variable
3162
- }
3163
- );
3164
- }
3165
-
3166
- // src/components/display-inputs-values/index.tsx
3167
- import React40 from "react";
3168
-
3169
- // src/components/display-inputs-values/styles.ts
3170
- import styled14 from "styled-components";
3171
- var DisplayInputsWrapper = styled14.div`
3172
- display: flex;
3173
- gap: 5px;
3174
- flex-wrap: wrap;
3175
- `;
3176
-
3177
- // src/components/display-inputs-values/index.tsx
3178
- function DisplayInputsValues({ value, showIconInTree }) {
3179
- const childEntries = Object.entries(value || {});
3180
- return /* @__PURE__ */ React40.createElement(DisplayInputsWrapper, null, childEntries.map(([key, value2]) => /* @__PURE__ */ React40.createElement(DisplayFlowValue, { key, title: key, value: value2, showIconInTree })));
3181
- }
3182
-
3183
- // src/components/assign-rows/index.tsx
3184
- import React43 from "react";
3185
- import { FieldArray } from "@flowgram.ai/editor";
3186
- import { Button as Button5 } from "@douyinfe/semi-ui";
3187
- import { IconPlus as IconPlus4 } from "@douyinfe/semi-icons";
3188
-
3189
- // src/components/assign-row/index.tsx
3190
- import React42 from "react";
3191
- import { IconButton as IconButton5 } from "@douyinfe/semi-ui";
3192
- import { IconMinus as IconMinus2 } from "@douyinfe/semi-icons";
3193
-
3194
- // src/components/assign-row/components/blur-input.tsx
3195
- import React41, { useEffect as useEffect11, useState as useState10 } from "react";
3196
- import Input7 from "@douyinfe/semi-ui/lib/es/input";
3197
- function BlurInput3(props) {
3198
- const [value, setValue] = useState10("");
3199
- useEffect11(() => {
3200
- setValue(props.value);
3201
- }, [props.value]);
3202
- return /* @__PURE__ */ React41.createElement(
3203
- Input7,
3204
- {
3205
- ...props,
3206
- value,
3207
- onChange: (value2) => {
3208
- setValue(value2);
3209
- },
3210
- onBlur: (e) => props.onChange?.(value, e)
3211
- }
3212
- );
3213
- }
3214
-
3215
- // src/components/assign-row/index.tsx
3216
- function AssignRow(props) {
3217
- const {
3218
- value = {
3219
- operator: "assign"
3220
- },
3221
- onChange,
3222
- onDelete,
3223
- readonly
3224
- } = props;
3225
- return /* @__PURE__ */ React42.createElement("div", { style: { display: "flex", alignItems: "center", gap: 5 } }, /* @__PURE__ */ React42.createElement("div", { style: { width: 150, minWidth: 150, maxWidth: 150 } }, value?.operator === "assign" ? /* @__PURE__ */ React42.createElement(
3226
- InjectVariableSelector,
3227
- {
3228
- style: { width: "100%", height: 26 },
3229
- value: value?.left?.content,
3230
- config: { placeholder: "Select Left" },
3231
- onChange: (v) => onChange?.({
3232
- ...value,
3233
- left: { type: "ref", content: v }
3234
- })
3235
- }
3236
- ) : /* @__PURE__ */ React42.createElement(
3237
- BlurInput3,
3238
- {
3239
- style: { height: 26 },
3240
- size: "small",
3241
- placeholder: "Input Name",
3242
- value: value?.left,
3243
- onChange: (v) => onChange?.({
3244
- ...value,
3245
- left: v
3246
- })
3247
- }
3248
- )), /* @__PURE__ */ React42.createElement("div", { style: { flexGrow: 1 } }, /* @__PURE__ */ React42.createElement(
3249
- InjectDynamicValueInput,
3250
- {
3251
- readonly,
3252
- value: value?.right,
3253
- onChange: (v) => onChange?.({
3254
- ...value,
3255
- right: v
3256
- })
3257
- }
3258
- )), onDelete && /* @__PURE__ */ React42.createElement("div", null, /* @__PURE__ */ React42.createElement(
3259
- IconButton5,
3260
- {
3261
- size: "small",
3262
- theme: "borderless",
3263
- icon: /* @__PURE__ */ React42.createElement(IconMinus2, null),
3264
- onClick: () => onDelete?.()
3265
- }
3266
- )));
3267
- }
3268
-
3269
- // src/components/assign-rows/index.tsx
3270
- function AssignRows(props) {
3271
- const { name, readonly } = props;
3272
- return /* @__PURE__ */ React43.createElement(FieldArray, { name }, ({ field }) => /* @__PURE__ */ React43.createElement(React43.Fragment, null, field.map((childField, index) => /* @__PURE__ */ React43.createElement(
3273
- AssignRow,
3274
- {
3275
- key: childField.key,
3276
- readonly,
3277
- value: childField.value,
3278
- onChange: (value) => {
3279
- childField.onChange(value);
3280
- },
3281
- onDelete: () => field.remove(index)
3282
- }
3283
- )), /* @__PURE__ */ React43.createElement("div", { style: { display: "flex", gap: 5 } }, /* @__PURE__ */ React43.createElement(
3284
- Button5,
3285
- {
3286
- size: "small",
3287
- theme: "borderless",
3288
- icon: /* @__PURE__ */ React43.createElement(IconPlus4, null),
3289
- onClick: () => field.append({ operator: "assign" })
3290
- },
3291
- "Assign"
3292
- ), /* @__PURE__ */ React43.createElement(
3293
- Button5,
3294
- {
3295
- size: "small",
3296
- theme: "borderless",
3297
- icon: /* @__PURE__ */ React43.createElement(IconPlus4, null),
3298
- onClick: () => field.append({ operator: "declare" })
3299
- },
3300
- "Declaration"
3301
- ))));
3302
- }
3303
-
3304
- // src/effects/provide-batch-input/index.ts
3305
- import {
3306
- ASTFactory,
3307
- createEffectFromVariableProvider,
3308
- getNodeForm
3309
- } from "@flowgram.ai/editor";
3310
- var provideBatchInputEffect = createEffectFromVariableProvider({
3311
- private: true,
3312
- parse: (value, ctx) => [
3313
- ASTFactory.createVariableDeclaration({
3314
- key: `${ctx.node.id}_locals`,
3315
- meta: {
3316
- title: getNodeForm(ctx.node)?.getValueIn("title"),
3317
- icon: ctx.node.getNodeRegistry().info?.icon
3318
- },
3319
- type: ASTFactory.createObject({
3320
- properties: [
3321
- ASTFactory.createProperty({
3322
- key: "item",
3323
- initializer: ASTFactory.createEnumerateExpression({
3324
- enumerateFor: ASTFactory.createKeyPathExpression({
3325
- keyPath: value.content || []
3326
- })
3327
- })
3328
- }),
3329
- ASTFactory.createProperty({
3330
- key: "index",
3331
- type: ASTFactory.createNumber()
3332
- })
3333
- ]
3334
- })
3335
- })
3336
- ]
3337
- });
3338
-
3339
- // src/effects/auto-rename-ref/index.ts
3340
- import { isArray, isObject as isObject3, uniq } from "lodash";
3341
- import {
3342
- DataEvent,
3343
- VariableFieldKeyRenameService
3344
- } from "@flowgram.ai/editor";
3345
- var autoRenameRefEffect = [
3346
- {
3347
- event: DataEvent.onValueInit,
3348
- effect: (params) => {
3349
- const { context, form, name } = params;
3350
- const renameService = context.node.getService(VariableFieldKeyRenameService);
3351
- const disposable = renameService.onRename(({ before, after }) => {
3352
- const beforeKeyPath = [
3353
- ...before.parentFields.map((_field) => _field.key).reverse(),
3354
- before.key
3355
- ];
3356
- const afterKeyPath = [
3357
- ...after.parentFields.map((_field) => _field.key).reverse(),
3358
- after.key
3359
- ];
3360
- traverseRef(name, form.getValueIn(name), (_drilldownName, _v) => {
3361
- if (_v.type === "ref") {
3362
- if (isKeyPathMatch(_v.content, beforeKeyPath)) {
3363
- _v.content = [...afterKeyPath, ...(_v.content || [])?.slice(beforeKeyPath.length)];
3364
- form.setValueIn(_drilldownName, _v);
3365
- }
3366
- } else if (_v.type === "template") {
3367
- const templateKeyPaths = getTemplateKeyPaths(_v);
3368
- let hasMatch = false;
3369
- templateKeyPaths.forEach((_keyPath) => {
3370
- if (isKeyPathMatch(_keyPath, beforeKeyPath)) {
3371
- hasMatch = true;
3372
- const nextKeyPath = [
3373
- ...afterKeyPath,
3374
- ...(_keyPath || [])?.slice(beforeKeyPath.length)
3375
- ];
3376
- _v.content = _v.content?.replace(
3377
- `{{${_keyPath.join(".")}}`,
3378
- `{{${nextKeyPath.join(".")}}`
3379
- );
3380
- }
3381
- });
3382
- if (hasMatch) {
3383
- form.setValueIn(_drilldownName, { ..._v });
3384
- }
3385
- }
3386
- });
3387
- });
3388
- return () => {
3389
- disposable.dispose();
3390
- };
3391
- }
3392
- }
3393
- ];
3394
- function isKeyPathMatch(keyPath = [], targetKeyPath) {
3395
- return targetKeyPath.every((_key, index) => _key === keyPath[index]);
3396
- }
3397
- function getTemplateKeyPaths(value) {
3398
- const keyPathReg = /{{(.*?)}}/g;
3399
- return uniq(value.content?.match(keyPathReg) || []).map(
3400
- (_keyPath) => _keyPath.slice(2, -2).split(".")
3401
- );
3402
- }
3403
- function isRef(value) {
3404
- return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
3405
- }
3406
- function isTemplate(value) {
3407
- return value?.type === "template" && typeof value?.content === "string";
3408
- }
3409
- function traverseRef(name, value, cb) {
3410
- if (isObject3(value)) {
3411
- if (isRef(value)) {
3412
- cb(name, value);
3413
- return;
3414
- }
3415
- if (isTemplate(value)) {
3416
- cb(name, value);
3417
- return;
3418
- }
3419
- Object.entries(value).forEach(([_key, _value]) => {
3420
- traverseRef(`${name}.${_key}`, _value, cb);
3421
- });
3422
- return;
3423
- }
3424
- if (isArray(value)) {
3425
- value.forEach((_value, idx) => {
3426
- traverseRef(`${name}[${idx}]`, _value, cb);
3427
- });
3428
- return;
3429
- }
3430
- return;
3431
- }
3432
-
3433
- // src/effects/provide-json-schema-outputs/index.ts
3434
- import { JsonSchemaUtils as JsonSchemaUtils7 } from "@flowgram.ai/json-schema";
3435
- import {
3436
- ASTFactory as ASTFactory2,
3437
- createEffectFromVariableProvider as createEffectFromVariableProvider2,
3438
- getNodeForm as getNodeForm2
3439
- } from "@flowgram.ai/editor";
3440
- var provideJsonSchemaOutputs = createEffectFromVariableProvider2({
3441
- parse: (value, ctx) => [
3442
- ASTFactory2.createVariableDeclaration({
3443
- key: `${ctx.node.id}`,
3444
- meta: {
3445
- title: getNodeForm2(ctx.node)?.getValueIn("title") || ctx.node.id,
3446
- icon: ctx.node.getNodeRegistry().info?.icon
3447
- },
3448
- type: JsonSchemaUtils7.schemaToAST(value)
3449
- })
3450
- ]
3451
- });
3452
-
3453
- // src/effects/sync-variable-title/index.ts
3454
- import {
3455
- DataEvent as DataEvent2,
3456
- FlowNodeVariableData
3457
- } from "@flowgram.ai/editor";
3458
- var syncVariableTitle = [
3459
- {
3460
- event: DataEvent2.onValueChange,
3461
- effect: ({ value, context }) => {
3462
- context.node.getData(FlowNodeVariableData).allScopes.forEach((_scope) => {
3463
- _scope.output.variables.forEach((_var) => {
3464
- _var.updateMeta({
3465
- ..._var.meta || {},
3466
- title: value || context.node.id,
3467
- icon: context.node.getNodeRegistry().info?.icon
3468
- });
3469
- });
3470
- });
3471
- }
3472
- }
3473
- ];
3474
-
3475
- // src/effects/validate-when-variable-sync/index.ts
3476
- import { isEmpty } from "lodash";
3477
- import {
3478
- DataEvent as DataEvent3,
3479
- getNodeScope,
3480
- getNodePrivateScope
3481
- } from "@flowgram.ai/editor";
3482
- var validateWhenVariableSync = ({
3483
- scope
3484
- } = {}) => [
3485
- {
3486
- event: DataEvent3.onValueInit,
3487
- effect: ({ context, form }) => {
3488
- const nodeScope = scope === "private" ? getNodePrivateScope(context.node) : getNodeScope(context.node);
3489
- const disposable = nodeScope.available.onListOrAnyVarChange(() => {
3490
- if (!isEmpty(form.state.errors)) {
3491
- form.validate();
3492
- }
3493
- });
3494
- return () => disposable.dispose();
3495
- }
3496
- }
3497
- ];
3498
-
3499
- // src/effects/listen-ref-value-change/index.ts
3500
- import {
3501
- DataEvent as DataEvent4,
3502
- getNodeScope as getNodeScope2
3503
- } from "@flowgram.ai/editor";
3504
- var listenRefValueChange = (cb) => [
3505
- {
3506
- event: DataEvent4.onValueInitOrChange,
3507
- effect: (params) => {
3508
- const { context, value } = params;
3509
- if (value?.type !== "ref") {
3510
- return () => null;
3511
- }
3512
- const disposable = getNodeScope2(context.node).available.trackByKeyPath(
3513
- value?.content || [],
3514
- (v) => {
3515
- cb({ ...params, variable: v });
3516
- }
3517
- );
3518
- return () => {
3519
- disposable.dispose();
3520
- };
3521
- }
3522
- }
3523
- ];
3524
-
3525
- // src/effects/listen-ref-schema-change/index.ts
3526
- import { JsonSchemaUtils as JsonSchemaUtils8 } from "@flowgram.ai/json-schema";
3527
- import {
3528
- DataEvent as DataEvent5,
3529
- getNodeScope as getNodeScope3
3530
- } from "@flowgram.ai/editor";
3531
- var listenRefSchemaChange = (cb) => [
3532
- {
3533
- event: DataEvent5.onValueInitOrChange,
3534
- effect: (params) => {
3535
- const { context, value } = params;
3536
- if (value?.type !== "ref") {
3537
- return () => null;
3538
- }
3539
- const disposable = getNodeScope3(context.node).available.trackByKeyPath(
3540
- value?.content || [],
3541
- (_type) => {
3542
- cb({ ...params, schema: JsonSchemaUtils8.astToSchema(_type) });
3543
- },
3544
- {
3545
- selector: (_v) => _v?.type
3546
- }
3547
- );
3548
- return () => {
3549
- disposable.dispose();
3550
- };
3551
- }
3552
- }
3553
- ];
3554
-
3555
- // src/form-plugins/batch-outputs-plugin/index.ts
3556
- import {
3557
- ASTFactory as ASTFactory3,
3558
- createEffectFromVariableProvider as createEffectFromVariableProvider3,
3559
- defineFormPluginCreator,
3560
- getNodeForm as getNodeForm3,
3561
- getNodePrivateScope as getNodePrivateScope2,
3562
- getNodeScope as getNodeScope4,
3563
- ScopeChainTransformService,
3564
- FlowNodeScopeType
3565
- } from "@flowgram.ai/editor";
3566
- var provideBatchOutputsEffect = createEffectFromVariableProvider3({
3567
- parse: (value, ctx) => [
3568
- ASTFactory3.createVariableDeclaration({
3569
- key: `${ctx.node.id}`,
3570
- meta: {
3571
- title: getNodeForm3(ctx.node)?.getValueIn("title"),
3572
- icon: ctx.node.getNodeRegistry().info?.icon
3573
- },
3574
- type: ASTFactory3.createObject({
3575
- properties: Object.entries(value).map(
3576
- ([_key, value2]) => ASTFactory3.createProperty({
3577
- key: _key,
3578
- initializer: ASTFactory3.createWrapArrayExpression({
3579
- wrapFor: ASTFactory3.createKeyPathExpression({
3580
- keyPath: value2?.content || []
3581
- })
3582
- })
3583
- })
3584
- )
3585
- })
3586
- })
3587
- ]
3588
- });
3589
- var createBatchOutputsFormPlugin = defineFormPluginCreator({
3590
- name: "batch-outputs-plugin",
3591
- onSetupFormMeta({ mergeEffect }, { outputKey }) {
3592
- mergeEffect({
3593
- [outputKey]: provideBatchOutputsEffect
3594
- });
3595
- },
3596
- onInit(ctx, { outputKey }) {
3597
- const chainTransformService = ctx.node.getService(ScopeChainTransformService);
3598
- const batchNodeType = ctx.node.flowNodeType;
3599
- const transformerId = `${batchNodeType}-outputs`;
3600
- if (chainTransformService.hasTransformer(transformerId)) {
3601
- return;
3602
- }
3603
- chainTransformService.registerTransformer(transformerId, {
3604
- transformCovers: (covers, ctx2) => {
3605
- const node = ctx2.scope.meta?.node;
3606
- if (node?.parent?.flowNodeType === batchNodeType) {
3607
- return [...covers, getNodeScope4(node.parent)];
3608
- }
3609
- return covers;
3610
- },
3611
- transformDeps(scopes, ctx2) {
3612
- const scopeMeta = ctx2.scope.meta;
3613
- if (scopeMeta?.type === FlowNodeScopeType.private) {
3614
- return scopes;
3615
- }
3616
- const node = scopeMeta?.node;
3617
- if (node?.flowNodeType === batchNodeType) {
3618
- const childBlocks = node.blocks;
3619
- return [
3620
- getNodePrivateScope2(node),
3621
- ...childBlocks.map((_childBlock) => getNodeScope4(_childBlock))
3622
- ];
3623
- }
3624
- return scopes;
3625
- }
3626
- });
3627
- }
3628
- });
3629
-
3630
- // src/form-plugins/infer-inputs-plugin/index.ts
3631
- import { get as get2, set as set2 } from "lodash";
3632
- import { JsonSchemaUtils as JsonSchemaUtils9 } from "@flowgram.ai/json-schema";
3633
- import {
3634
- defineFormPluginCreator as defineFormPluginCreator2,
3635
- getNodePrivateScope as getNodePrivateScope3,
3636
- getNodeScope as getNodeScope5
3637
- } from "@flowgram.ai/editor";
3638
- var createInferInputsPlugin = defineFormPluginCreator2({
3639
- onSetupFormMeta({ addFormatOnSubmit }, { sourceKey, targetKey, scope }) {
3640
- if (!sourceKey || !targetKey) {
3641
- return;
3642
- }
3643
- addFormatOnSubmit((formData, ctx) => {
3644
- set2(
3645
- formData,
3646
- targetKey,
3647
- infer(
3648
- get2(formData, sourceKey),
3649
- scope === "private" ? getNodePrivateScope3(ctx.node) : getNodeScope5(ctx.node)
3650
- )
3651
- );
3652
- return formData;
3653
- });
3654
- }
3655
- });
3656
- function isRef2(value) {
3657
- return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
3658
- }
3659
- function isTemplate2(value) {
3660
- return value?.type === "template" && typeof value?.content === "string";
3661
- }
3662
- function isConstant(value) {
3663
- return value?.type === "constant" && typeof value?.content !== "undefined";
3664
- }
3665
- var infer = (values, scope) => {
3666
- if (typeof values === "object") {
3667
- if (isConstant(values)) {
3668
- if (values?.schema) {
3669
- return values.schema;
3670
- }
3671
- if (typeof values.content === "string") {
3672
- return {
3673
- type: "string"
3674
- };
3675
- }
3676
- if (typeof values.content === "number") {
3677
- return {
3678
- type: "number"
3679
- };
3680
- }
3681
- if (typeof values.content === "boolean") {
3682
- return {
3683
- type: "boolean"
3684
- };
3685
- }
3686
- }
3687
- if (isRef2(values)) {
3688
- const variable = scope.available.getByKeyPath(values?.content);
3689
- const schema = variable?.type ? JsonSchemaUtils9.astToSchema(variable?.type) : void 0;
3690
- return schema;
3691
- }
3692
- if (isTemplate2(values)) {
3693
- return {
3694
- type: "string"
3695
- };
3696
- }
3697
- return {
3698
- type: "object",
3699
- properties: Object.keys(values).reduce((acc, key) => {
3700
- const schema = infer(values[key], scope);
3701
- if (schema) {
3702
- acc[key] = schema;
3703
- }
3704
- return acc;
3705
- }, {})
3706
- };
3707
- }
3708
- };
3709
-
3710
- // src/form-plugins/infer-assign-plugin/index.ts
3711
- import { set as set3, uniqBy } from "lodash";
3712
- import { JsonSchemaUtils as JsonSchemaUtils10 } from "@flowgram.ai/json-schema";
3713
- import {
3714
- ASTFactory as ASTFactory4,
3715
- createEffectFromVariableProvider as createEffectFromVariableProvider4,
3716
- defineFormPluginCreator as defineFormPluginCreator3,
3717
- getNodeForm as getNodeForm4,
3718
- getNodeScope as getNodeScope6
3719
- } from "@flowgram.ai/editor";
3720
- var createInferAssignPlugin = defineFormPluginCreator3({
3721
- onSetupFormMeta({ addFormatOnSubmit, mergeEffect }, { assignKey, outputKey }) {
3722
- if (!assignKey || !outputKey) {
3723
- return;
3724
- }
3725
- mergeEffect({
3726
- [assignKey]: createEffectFromVariableProvider4({
3727
- parse: (value, ctx) => {
3728
- const declareRows = uniqBy(
3729
- value.filter((_v) => _v.operator === "declare" && _v.left && _v.right),
3730
- "left"
3731
- );
3732
- return [
3733
- ASTFactory4.createVariableDeclaration({
3734
- key: `${ctx.node.id}`,
3735
- meta: {
3736
- title: getNodeForm4(ctx.node)?.getValueIn("title"),
3737
- icon: ctx.node.getNodeRegistry().info?.icon
3738
- },
3739
- type: ASTFactory4.createObject({
3740
- properties: declareRows.map(
3741
- (_v) => ASTFactory4.createProperty({
3742
- key: _v.left,
3743
- type: _v.right?.type === "constant" ? JsonSchemaUtils10.schemaToAST(_v.right?.schema || {}) : void 0,
3744
- initializer: _v.right?.type === "ref" ? ASTFactory4.createKeyPathExpression({
3745
- keyPath: _v.right?.content || []
3746
- }) : {}
3747
- })
3748
- )
3749
- })
3750
- })
3751
- ];
3752
- }
3753
- })
3754
- });
3755
- addFormatOnSubmit((formData, ctx) => {
3756
- set3(
3757
- formData,
3758
- outputKey,
3759
- JsonSchemaUtils10.astToSchema(getNodeScope6(ctx.node).output.variables?.[0]?.type)
3760
- );
3761
- return formData;
3762
- });
3763
- }
3764
- });
3765
-
3766
- // src/validate/validate-flow-value/index.tsx
3767
- import { isNil, uniq as uniq2 } from "lodash";
3768
- import { FeedbackLevel, getNodeScope as getNodeScope7 } from "@flowgram.ai/editor";
3769
- function validateFlowValue(value, ctx) {
3770
- const { node, required, errorMessages } = ctx;
3771
- const {
3772
- required: requiredMessage = "Field is required",
3773
- unknownVariable: unknownVariableMessage = "Unknown Variable"
3774
- } = errorMessages || {};
3775
- if (required && (isNil(value) || isNil(value?.content) || value?.content === "")) {
3776
- return {
3777
- level: FeedbackLevel.Error,
3778
- message: requiredMessage
3779
- };
3780
- }
3781
- if (value?.type === "ref") {
3782
- const variable = getNodeScope7(node).available.getByKeyPath(value?.content || []);
3783
- if (!variable) {
3784
- return {
3785
- level: FeedbackLevel.Error,
3786
- message: unknownVariableMessage
3787
- };
3788
- }
3789
- }
3790
- if (value?.type === "template") {
3791
- const allRefs = getTemplateKeyPaths2(value);
3792
- for (const ref of allRefs) {
3793
- const variable = getNodeScope7(node).available.getByKeyPath(ref);
3794
- if (!variable) {
3795
- return {
3796
- level: FeedbackLevel.Error,
3797
- message: unknownVariableMessage
3798
- };
3799
- }
3800
- }
3801
- }
3802
- return void 0;
3803
- }
3804
- function getTemplateKeyPaths2(value) {
3805
- const keyPathReg = /{{(.*?)}}/g;
3806
- return uniq2(value.content?.match(keyPathReg) || []).map(
3807
- (_keyPath) => _keyPath.slice(2, -2).split(".")
3808
- );
3809
- }
3810
- export {
3811
- AssignRow,
3812
- AssignRows,
3813
- BatchOutputs,
3814
- BatchVariableSelector,
3815
- CodeEditor,
3816
- CodeEditorMini,
3817
- ConditionRow,
3818
- ConstantInput,
3819
- DisplayFlowValue,
3820
- DisplayInputsValues,
3821
- DisplayOutputs,
3822
- DisplaySchemaTag,
3823
- DisplaySchemaTree,
3824
- DynamicValueInput,
3825
- InjectDynamicValueInput,
3826
- InjectTypeSelector,
3827
- InjectVariableSelector,
3828
- InputsValues,
3829
- JsonEditorWithVariables,
3830
- JsonSchemaEditor,
3831
- JsonSchemaTypePresetProvider,
3832
- JsonSchemaUtils,
3833
- PromptEditor,
3834
- PromptEditorWithInputs,
3835
- PromptEditorWithVariables,
3836
- TypeSelector,
3837
- VariableSelector,
3838
- autoRenameRefEffect,
3839
- createBatchOutputsFormPlugin,
3840
- createDisableDeclarationPlugin,
3841
- createInferAssignPlugin,
3842
- createInferInputsPlugin,
3843
- createInjectMaterial,
3844
- createTypePresetPlugin,
3845
- formatLegacyRefOnInit,
3846
- formatLegacyRefOnSubmit,
3847
- formatLegacyRefToNewRef,
3848
- formatNewRefToLegacyRef,
3849
- getTypeSelectValue,
3850
- isLegacyFlowRefValueSchema,
3851
- isNewFlowRefValueSchema,
3852
- listenRefSchemaChange,
3853
- listenRefValueChange,
3854
- parseTypeSelectValue,
3855
- provideBatchInputEffect,
3856
- provideBatchOutputsEffect,
3857
- provideJsonSchemaOutputs,
3858
- syncVariableTitle,
3859
- useTypeManager,
3860
- useVariableTree,
3861
- validateFlowValue,
3862
- validateWhenVariableSync
3863
- };
3864
- //# sourceMappingURL=index.js.map