@gientech/modual 2.0.7 → 2.0.9

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 (415) hide show
  1. package/.editorconfig +38 -0
  2. package/.prettierignore +16 -0
  3. package/.prettierrc +17 -0
  4. package/INSTALL_TROUBLESHOOTING.md +316 -0
  5. package/USAGE.md +247 -0
  6. package/bash.exe.stackdump +40 -0
  7. package/components.json +21 -0
  8. package/dist/README.md +761 -0
  9. package/{assets/GientechStreamReader-Dx72IaEx.js → dist/assets/GientechStreamReader-CNj6Rcm7.js} +1 -1
  10. package/{assets/index-D4pXe94o.js → dist/assets/index-BJv0t0eJ.js} +36 -36
  11. package/{assets/index-BbNz3Zrz.js → dist/assets/index-CU45mVZ4.js} +1 -1
  12. package/{chat.js → dist/chat.js} +1 -1
  13. package/{databaseId.js → dist/databaseId.js} +1 -1
  14. package/{index.js → dist/index.js} +1 -1
  15. package/dist/package.json +68 -0
  16. package/{streamFilesReader.js → dist/streamFilesReader.js} +1 -1
  17. package/doc_assets/2.png +0 -0
  18. package/doc_assets/demo.md +27 -0
  19. package/doc_assets/demos/dist-app/assets/index.Dh-ZAS9Z.css +2 -0
  20. package/doc_assets/demos/dist-app/assets/index.Dv8KVW18.js +23699 -0
  21. package/doc_assets/demos/dist-app/assets/index.Dv8KVW18.js.map +1 -0
  22. package/doc_assets/demos/dist-app/index.html +14 -0
  23. package/doc_assets/demos/dist-app/vite.svg +1 -0
  24. package/doc_assets/images/1.png +0 -0
  25. package/doc_assets/images/3.png +0 -0
  26. package/doc_assets/images/component-screenshot.png +1 -0
  27. package/doc_assets/install.md +5 -0
  28. package/doc_assets/v2.0.7/345/217/230/346/233/264/346/200/273/347/273/223.md +115 -0
  29. package/doc_assets//346/226/271/346/241/210//344/274/230/345/214/226/346/226/271/346/241/210-/345/244/232/344/274/232/350/257/235SSE/350/277/236/346/216/245/347/256/241/347/220/206.md +504 -0
  30. package/eslint.config.js +92 -0
  31. package/index.html +13 -0
  32. package/package.json +103 -41
  33. package/package.json.demo-backup +109 -0
  34. package/postcss.config.cjs +19 -0
  35. package/public/icons/answerAwartar.png +0 -0
  36. package/public/icons/docx-file.png +0 -0
  37. package/public/icons/folder.png +0 -0
  38. package/public/icons/html.png +0 -0
  39. package/public/icons/image.png +0 -0
  40. package/public/icons/jpg-file.png +0 -0
  41. package/public/icons/json.png +0 -0
  42. package/public/icons/md.png +0 -0
  43. package/public/icons/pdf.png +0 -0
  44. package/public/icons/pptx.png +0 -0
  45. package/public/icons/questionAwartar.png +0 -0
  46. package/public/icons/sheets.png +0 -0
  47. package/public/icons/txt.png +0 -0
  48. package/public/icons/xlsx.png +0 -0
  49. package/public/vite.svg +1 -0
  50. package/public/worker/pdf.worker.min.js +22 -0
  51. package/scripts/README.md +133 -0
  52. package/scripts/build-demo.js +88 -0
  53. package/scripts/decrypt-api-key.js +95 -0
  54. package/scripts/demo-selector.js +216 -0
  55. package/scripts/dev-demo.js +76 -0
  56. package/scripts/preview-demo.js +130 -0
  57. package/scripts/run-demo.bat +34 -0
  58. package/src/assets/img/close.png +0 -0
  59. package/src/assets/img/database.png +0 -0
  60. package/src/assets/img/downArrow.png +0 -0
  61. package/src/assets/img/downLoad.png +0 -0
  62. package/src/assets/img/excel.png +0 -0
  63. package/src/assets/img/graphIcon.png +0 -0
  64. package/src/assets/img/img.png +0 -0
  65. package/src/assets/img/pdf.png +0 -0
  66. package/src/assets/img/ppt.png +0 -0
  67. package/src/assets/img/singleQa.png +0 -0
  68. package/src/assets/img/txt.png +0 -0
  69. package/src/assets/img/webSearch.png +0 -0
  70. package/src/assets/img/word.png +0 -0
  71. package/src/assets/login/homeBg.png +0 -0
  72. package/src/assets/login/left.jpg +0 -0
  73. package/src/assets/login/logoImg.png +0 -0
  74. package/src/examples/ConversationAssistantPage/index.tsx +41 -0
  75. package/src/examples/Demo/index.tsx +12 -0
  76. package/src/examples/LoginPage/index.tsx +18 -0
  77. package/src/examples/chat/components/DrawerGraphPreview.tsx +78 -0
  78. package/src/examples/chat/index.tsx +166 -0
  79. package/src/examples/chat/logo03.png +0 -0
  80. package/src/examples/gientechStreamFilesReader/index.tsx +951 -0
  81. package/src/examples/headlessChat/assets/mind.svg +6 -0
  82. package/src/examples/headlessChat/assets/net.svg +7 -0
  83. package/src/examples/headlessChat/index.tsx +285 -0
  84. package/src/examples/ragDatabaseDataPage/index.tsx +40 -0
  85. package/src/examples/ragDatabaseIdPage/index.tsx +47 -0
  86. package/src/examples/ragDatabasePage/index.tsx +36 -0
  87. package/src/examples/ragModelManagePage/index.tsx +38 -0
  88. package/src/examples/ragSearchPage/index.tsx +0 -0
  89. package/src/examples/ragSensitiveWordsPage/index.tsx +32 -0
  90. package/src/examples/streamFiles/index.tsx +417 -0
  91. package/src/lib_enter.ts +43 -0
  92. package/src/main.tsx +5 -0
  93. package/src/main.tsx.backup +5 -0
  94. package/src/modules/CHAT_UNIFICATION_PLAN.md +324 -0
  95. package/src/modules/assistantConfig/assets/databse.svg +6 -0
  96. package/src/modules/assistantConfig/assets/empty.png +0 -0
  97. package/src/modules/assistantConfig/assets/graph.svg +4 -0
  98. package/src/modules/assistantConfig/assets/knowledge.svg +4 -0
  99. package/src/modules/assistantConfig/assets/sensitive.svg +5 -0
  100. package/src/modules/assistantConfig/components/Database.tsx +171 -0
  101. package/src/modules/assistantConfig/components/Graph.tsx +177 -0
  102. package/src/modules/assistantConfig/components/Knowledge.tsx +276 -0
  103. package/src/modules/assistantConfig/components/NotFoundContent.tsx +21 -0
  104. package/src/modules/assistantConfig/components/Paragraph.tsx +51 -0
  105. package/src/modules/assistantConfig/components/ParamsItem.tsx +39 -0
  106. package/src/modules/assistantConfig/components/ResourceBinderItem.tsx +133 -0
  107. package/src/modules/assistantConfig/components/SearchableSelector.tsx +500 -0
  108. package/src/modules/assistantConfig/components/Sensitive.tsx +221 -0
  109. package/src/modules/assistantConfig/components/SliderInput.tsx +65 -0
  110. package/src/modules/assistantConfig/constants.tsx +75 -0
  111. package/src/modules/assistantConfig/index.tsx +710 -0
  112. package/src/modules/assistantConfig/server.ts +262 -0
  113. package/src/modules/chat/Conversations/Item.tsx +167 -0
  114. package/src/modules/chat/Conversations/List.tsx +210 -0
  115. package/src/modules/chat/Conversations/groupByTime.ts +39 -0
  116. package/src/modules/chat/Conversations/index.tsx +252 -0
  117. package/src/modules/chat/ReferenceBar.tsx +622 -0
  118. package/src/modules/chat/constants.tsx +57 -0
  119. package/src/modules/chat/index.tsx +2449 -0
  120. package/src/modules/chat/referenceCom/DeleteModal.tsx +75 -0
  121. package/src/modules/chat/referenceCom/DrawerContent.tsx +136 -0
  122. package/src/modules/chat/referenceCom/DrawerDatabase.tsx +102 -0
  123. package/src/modules/chat/referenceCom/DrawerGraphPreview.tsx +86 -0
  124. package/src/modules/chat/referenceCom/DrawerPreview.tsx +73 -0
  125. package/src/modules/chat/referenceCom/DrawerTitle.tsx +26 -0
  126. package/src/modules/chat/referenceCom/RenameModal.tsx +86 -0
  127. package/src/modules/chat/referenceCom/TagCom.tsx +30 -0
  128. package/src/modules/chat/style.less +3 -0
  129. package/src/modules/chat/types.ts +17 -0
  130. package/src/modules/chat/utils/index.ts +348 -0
  131. package/src/modules/database/CreateModal.tsx +403 -0
  132. package/src/modules/database/assets/Doris.png +0 -0
  133. package/src/modules/database/assets/PostgreSQL.png +0 -0
  134. package/src/modules/database/assets/SQLServer.png +0 -0
  135. package/src/modules/database/assets/database.svg +11 -0
  136. package/src/modules/database/assets/database_add.svg +53 -0
  137. package/src/modules/database/assets/database_connect.svg +66 -0
  138. package/src/modules/database/assets/database_upload.svg +29 -0
  139. package/src/modules/database/assets/empty.png +0 -0
  140. package/src/modules/database/assets/mysql.svg +14 -0
  141. package/src/modules/database/index.tsx +477 -0
  142. package/src/modules/database/server.ts +196 -0
  143. package/src/modules/databaseId/CustomCom.tsx +156 -0
  144. package/src/modules/databaseId/EditConfig.tsx +280 -0
  145. package/src/modules/databaseId/UploadDrawer.tsx +535 -0
  146. package/src/modules/databaseId/assets/aiOptimize.svg +10 -0
  147. package/src/modules/databaseId/assets/empty.png +0 -0
  148. package/src/modules/databaseId/assets/template.svg +6 -0
  149. package/src/modules/databaseId/assets/upload.svg +9 -0
  150. package/src/modules/databaseId/assets/useTemp.svg +6 -0
  151. package/src/modules/databaseId/index.tsx +769 -0
  152. package/src/modules/databaseId/server.ts +286 -0
  153. package/src/modules/databaseId/style.css +5 -0
  154. package/src/modules/databaseTable/EditRowDrawer.tsx +124 -0
  155. package/src/modules/databaseTable/index.tsx +359 -0
  156. package/src/modules/databaseTable/server.ts +180 -0
  157. package/src/modules/headlessChat/ReferenceBar.tsx +783 -0
  158. package/src/modules/headlessChat/constants.tsx +54 -0
  159. package/src/modules/headlessChat/index.tsx +1782 -0
  160. package/src/modules/headlessChat/referenceCom/DeleteModal.tsx +75 -0
  161. package/src/modules/headlessChat/referenceCom/DrawerContent.tsx +136 -0
  162. package/src/modules/headlessChat/referenceCom/DrawerDatabase.tsx +102 -0
  163. package/src/modules/headlessChat/referenceCom/DrawerGraphPreview.tsx +86 -0
  164. package/src/modules/headlessChat/referenceCom/DrawerPreview.tsx +73 -0
  165. package/src/modules/headlessChat/referenceCom/DrawerTitle.tsx +26 -0
  166. package/src/modules/headlessChat/referenceCom/RenameModal.tsx +86 -0
  167. package/src/modules/headlessChat/referenceCom/TagCom.tsx +30 -0
  168. package/src/modules/headlessChat/style.less +3 -0
  169. package/src/modules/headlessChat/types.ts +23 -0
  170. package/src/modules/headlessChat/utils/index.ts +348 -0
  171. package/src/modules/login/components/Login/LoginBox/index.tsx +102 -0
  172. package/src/modules/login/components/Login/RegisterBox/index.tsx +180 -0
  173. package/src/modules/login/components/Login/index.tsx +100 -0
  174. package/src/modules/login/index.tsx +106 -0
  175. package/src/modules/login/style.css +3 -0
  176. package/src/modules/login/useServices.ts +53 -0
  177. package/src/modules/login/utils.ts +42 -0
  178. package/src/modules/modelManage/ConfigDrawer.tsx +249 -0
  179. package/src/modules/modelManage/ReplaceModal.tsx +124 -0
  180. package/src/modules/modelManage/assets/empty.png +0 -0
  181. package/src/modules/modelManage/const.ts +51 -0
  182. package/src/modules/modelManage/index.tsx +606 -0
  183. package/src/modules/modelManage/server.ts +223 -0
  184. package/src/modules/nodegraph/index.tsx +1 -0
  185. package/src/modules/search/assets/Icon-history.svg +8 -0
  186. package/src/modules/search/assets/answerAwartar.png +0 -0
  187. package/src/modules/search/assets/doc.png +0 -0
  188. package/src/modules/search/assets/genera.gif +0 -0
  189. package/src/modules/search/assets/icon-robot.svg +9 -0
  190. package/src/modules/search/assets/icon-search-bar.svg +14 -0
  191. package/src/modules/search/assets/icon-sub-title.svg +3 -0
  192. package/src/modules/search/assets/icon-title.svg +9 -0
  193. package/src/modules/search/assets/icon-zoomOut.svg +9 -0
  194. package/src/modules/search/assets/iconAi.svg +9 -0
  195. package/src/modules/search/assets/pdf.png +0 -0
  196. package/src/modules/search/assets/ppt.png +0 -0
  197. package/src/modules/search/assets/search.svg +3 -0
  198. package/src/modules/search/assets/selected.svg +4 -0
  199. package/src/modules/search/assets/txt.png +0 -0
  200. package/src/modules/search/assets/xls.png +0 -0
  201. package/src/modules/search/components/AssisSelect.tsx +137 -0
  202. package/src/modules/search/components/Editor/ChatViewEditor.tsx +261 -0
  203. package/src/modules/search/components/Editor/aichat.css +1 -0
  204. package/src/modules/search/components/Editor/constant.ts +13 -0
  205. package/src/modules/search/components/Editor/index.tsx +113 -0
  206. package/src/modules/search/components/Editor/plugins/autofomatRules.ts +332 -0
  207. package/src/modules/search/components/Editor/plugins/convertImgPlugins.tsx +20 -0
  208. package/src/modules/search/components/Editor/plugins/createIndexes.tsx +38 -0
  209. package/src/modules/search/components/Editor/plugins/displayer.ts +298 -0
  210. package/src/modules/search/components/Editor/plugins/imageClick.tsx +32 -0
  211. package/src/modules/search/components/Editor/plugins/myplugin.tsx +98 -0
  212. package/src/modules/search/components/Editor/ui/avatar.tsx +19 -0
  213. package/src/modules/search/components/Editor/ui/blockquote-element.tsx +21 -0
  214. package/src/modules/search/components/Editor/ui/button.tsx +58 -0
  215. package/src/modules/search/components/Editor/ui/calendar.tsx +68 -0
  216. package/src/modules/search/components/Editor/ui/caption.tsx +46 -0
  217. package/src/modules/search/components/Editor/ui/checkbox.tsx +27 -0
  218. package/src/modules/search/components/Editor/ui/code-block-combobox.tsx +188 -0
  219. package/src/modules/search/components/Editor/ui/code-block-element.css +434 -0
  220. package/src/modules/search/components/Editor/ui/code-block-element.tsx +39 -0
  221. package/src/modules/search/components/Editor/ui/code-leaf.tsx +24 -0
  222. package/src/modules/search/components/Editor/ui/code-line-element.tsx +10 -0
  223. package/src/modules/search/components/Editor/ui/code-syntax-leaf.tsx +21 -0
  224. package/src/modules/search/components/Editor/ui/column-element.tsx +30 -0
  225. package/src/modules/search/components/Editor/ui/column-group-element.tsx +94 -0
  226. package/src/modules/search/components/Editor/ui/command.tsx +75 -0
  227. package/src/modules/search/components/Editor/ui/comment-avatar.tsx +22 -0
  228. package/src/modules/search/components/Editor/ui/comment-create-form.tsx +37 -0
  229. package/src/modules/search/components/Editor/ui/comment-item.tsx +74 -0
  230. package/src/modules/search/components/Editor/ui/comment-leaf.tsx +49 -0
  231. package/src/modules/search/components/Editor/ui/comment-more-dropdown.tsx +42 -0
  232. package/src/modules/search/components/Editor/ui/comment-reply-items.tsx +22 -0
  233. package/src/modules/search/components/Editor/ui/comment-resolve-button.tsx +32 -0
  234. package/src/modules/search/components/Editor/ui/comment-value.tsx +34 -0
  235. package/src/modules/search/components/Editor/ui/comments-popover.tsx +63 -0
  236. package/src/modules/search/components/Editor/ui/date-element.tsx +83 -0
  237. package/src/modules/search/components/Editor/ui/dialog.tsx +63 -0
  238. package/src/modules/search/components/Editor/ui/draggable.tsx +177 -0
  239. package/src/modules/search/components/Editor/ui/dropdown-menu.tsx +180 -0
  240. package/src/modules/search/components/Editor/ui/emoji-input-element.tsx +85 -0
  241. package/src/modules/search/components/Editor/ui/excalidraw-element.tsx +28 -0
  242. package/src/modules/search/components/Editor/ui/fixed-toolbar-buttons.tsx +76 -0
  243. package/src/modules/search/components/Editor/ui/fixed-toolbar.tsx +8 -0
  244. package/src/modules/search/components/Editor/ui/floating-toolbar-buttons.tsx +51 -0
  245. package/src/modules/search/components/Editor/ui/floating-toolbar.tsx +77 -0
  246. package/src/modules/search/components/Editor/ui/heading-element.tsx +48 -0
  247. package/src/modules/search/components/Editor/ui/highlight-leaf.tsx +17 -0
  248. package/src/modules/search/components/Editor/ui/hr-element.tsx +30 -0
  249. package/src/modules/search/components/Editor/ui/icons.tsx +267 -0
  250. package/src/modules/search/components/Editor/ui/image-element.tsx +74 -0
  251. package/src/modules/search/components/Editor/ui/inline-combobox.tsx +368 -0
  252. package/src/modules/search/components/Editor/ui/input.tsx +25 -0
  253. package/src/modules/search/components/Editor/ui/insert-dropdown-menu.tsx +218 -0
  254. package/src/modules/search/components/Editor/ui/kbd-leaf.tsx +20 -0
  255. package/src/modules/search/components/Editor/ui/link-element.tsx +29 -0
  256. package/src/modules/search/components/Editor/ui/link-floating-toolbar.tsx +161 -0
  257. package/src/modules/search/components/Editor/ui/list-element.tsx +30 -0
  258. package/src/modules/search/components/Editor/ui/mark-toolbar-button.tsx +24 -0
  259. package/src/modules/search/components/Editor/ui/media-embed-element.tsx +133 -0
  260. package/src/modules/search/components/Editor/ui/media-popover.tsx +97 -0
  261. package/src/modules/search/components/Editor/ui/mention-element.tsx +43 -0
  262. package/src/modules/search/components/Editor/ui/mention-input-element.tsx +141 -0
  263. package/src/modules/search/components/Editor/ui/mode-dropdown-menu.tsx +93 -0
  264. package/src/modules/search/components/Editor/ui/more-dropdown-menu.tsx +67 -0
  265. package/src/modules/search/components/Editor/ui/paragraph-element.tsx +4 -0
  266. package/src/modules/search/components/Editor/ui/placeholder.tsx +52 -0
  267. package/src/modules/search/components/Editor/ui/popover.tsx +32 -0
  268. package/src/modules/search/components/Editor/ui/resizable.tsx +66 -0
  269. package/src/modules/search/components/Editor/ui/separator.tsx +25 -0
  270. package/src/modules/search/components/Editor/ui/style.less +12 -0
  271. package/src/modules/search/components/Editor/ui/table-cell-element.tsx +143 -0
  272. package/src/modules/search/components/Editor/ui/table-element.tsx +243 -0
  273. package/src/modules/search/components/Editor/ui/table-row-element.tsx +22 -0
  274. package/src/modules/search/components/Editor/ui/tableValue.tsx +135 -0
  275. package/src/modules/search/components/Editor/ui/todo-list-element.tsx +43 -0
  276. package/src/modules/search/components/Editor/ui/toggle-element.tsx +31 -0
  277. package/src/modules/search/components/Editor/ui/toolbar.tsx +157 -0
  278. package/src/modules/search/components/Editor/ui/tooltip.tsx +65 -0
  279. package/src/modules/search/components/Editor/ui/turn-into-dropdown-menu.tsx +160 -0
  280. package/src/modules/search/components/Editor/ui/with-draggables.tsx +175 -0
  281. package/src/modules/search/components/FileList.tsx +287 -0
  282. package/src/modules/search/components/ImageGroupView/index.tsx +85 -0
  283. package/src/modules/search/components/ResultContent.tsx +232 -0
  284. package/src/modules/search/components/SearchInput.tsx +232 -0
  285. package/src/modules/search/components/SearchLanding.tsx +74 -0
  286. package/src/modules/search/components/SearchView.tsx +563 -0
  287. package/src/modules/search/components/SimpleEditor.tsx +158 -0
  288. package/src/modules/search/components/SimpleFileList.tsx +215 -0
  289. package/src/modules/search/index.tsx +10 -0
  290. package/src/modules/search/reademe.md +1 -0
  291. package/src/modules/search/servers/apis.tsx +19 -0
  292. package/src/modules/search/servers/index.ts +184 -0
  293. package/src/modules/search/style.less +503 -0
  294. package/src/modules/search/type.ts +22 -0
  295. package/src/modules/search/utils.ts +34 -0
  296. package/src/modules/sensitive/index.tsx +313 -0
  297. package/src/modules/sensitive/server.ts +122 -0
  298. package/src/modules/streamFilesReader/GientechStreamReader.tsx +1625 -0
  299. package/src/modules/streamFilesReader/components/Header/Toolbar.tsx +0 -0
  300. package/src/modules/streamFilesReader/components/Header/index.tsx +297 -0
  301. package/src/modules/streamFilesReader/index.tsx +3 -0
  302. package/src/style.css +6 -0
  303. package/src/type.d.ts +0 -0
  304. package/src/utils/commonFn.tsx +111 -0
  305. package/src/utils/decryptApiKey.ts +40 -0
  306. package/src/utils/gientechCommon/components/AppError.tsx +32 -0
  307. package/src/utils/gientechCommon/components/AppLoading.tsx +75 -0
  308. package/src/utils/gientechCommon/components/DeleteModal.tsx +75 -0
  309. package/src/utils/gientechCommon/components/DisplayError.tsx +33 -0
  310. package/src/utils/gientechCommon/components/DisplayLoading.tsx +38 -0
  311. package/src/utils/gientechCommon/components/FeedBackModal.tsx +319 -0
  312. package/src/utils/gientechCommon/components/FileCardCommon.tsx +82 -0
  313. package/src/utils/gientechCommon/components/FileManager/index.tsx +418 -0
  314. package/src/utils/gientechCommon/components/FileManager/style.css +5 -0
  315. package/src/utils/gientechCommon/components/Messages/GientechNewChatWelcome.tsx +581 -0
  316. package/src/utils/gientechCommon/components/Messages/ReferenceCard.tsx +359 -0
  317. package/src/utils/gientechCommon/components/Messages/RetriveItem.tsx +245 -0
  318. package/src/utils/gientechCommon/components/Messages/WebRetriveItem.tsx +209 -0
  319. package/src/utils/gientechCommon/components/Messages/defaultBot.png +0 -0
  320. package/src/utils/gientechCommon/components/Messages/defaultStyleSet.tsx +148 -0
  321. package/src/utils/gientechCommon/components/Messages/defaultWeLogo.svg +14 -0
  322. package/src/utils/gientechCommon/components/RenameModal.tsx +86 -0
  323. package/src/utils/gientechCommon/components/style.less +11 -0
  324. package/src/utils/gientechCommon/configs/commonConfig.ts +2 -0
  325. package/src/utils/gientechCommon/configs/senderConfig.ts +0 -0
  326. package/src/utils/gientechCommon/configs/stylesConfig.ts +142 -0
  327. package/src/utils/gientechCommon/hooks/AichatUseController.tsx +417 -0
  328. package/src/utils/gientechCommon/hooks/useFileDisplayTools.tsx +251 -0
  329. package/src/utils/gientechCommon/hooks/useFileManager.ts +208 -0
  330. package/src/utils/gientechCommon/slate/converters/deserializers.ts +763 -0
  331. package/src/utils/gientechCommon/slate/converters/mockData.ts +232 -0
  332. package/src/utils/gientechCommon/slate/converters/slateConverters.ts +258 -0
  333. package/src/utils/gientechCommon/slate/richElements/index.tsx +499 -0
  334. package/src/utils/gientechCommon/utils/fileUtils.ts +86 -0
  335. package/src/utils/gientechCommon/utils/request.ts +37 -0
  336. package/src/utils/gientechCommon/utils/serverFn.ts +172 -0
  337. package/src/utils/index.tsx +142 -0
  338. package/src/utils/testconfigs/demologin/index.tsx +32 -0
  339. package/src/utils/testconfigs/index.ts +59 -0
  340. package/src/vite-env.d.ts +42 -0
  341. package/stats.html +4949 -0
  342. package/tailwind.config.js +170 -0
  343. package/tsconfig.app.json +30 -0
  344. package/tsconfig.app.tsbuildinfo +11 -0
  345. package/tsconfig.json +13 -0
  346. package/tsconfig.node.json +22 -0
  347. package/tsconfig.node.tsbuildinfo +1 -0
  348. package/vite.config.app.ts +93 -0
  349. package/vite.config.ts +232 -0
  350. package/workflows/release.yml +60 -0
  351. package//346/215/242/350/241/214/346/240/274/345/274/217/344/277/235/346/214/201/344/274/230/345/214/226/346/226/271/346/241/210.md +359 -0
  352. /package/{assets → dist/assets}/Doris.png +0 -0
  353. /package/{assets → dist/assets}/PostgreSQL.png +0 -0
  354. /package/{assets → dist/assets}/SQLServer.png +0 -0
  355. /package/{assets → dist/assets}/database.svg +0 -0
  356. /package/{assets → dist/assets}/database_add.svg +0 -0
  357. /package/{assets → dist/assets}/database_connect.svg +0 -0
  358. /package/{assets → dist/assets}/database_upload.svg +0 -0
  359. /package/{assets → dist/assets}/databse.svg +0 -0
  360. /package/{assets → dist/assets}/defaultWeLogo.svg +0 -0
  361. /package/{assets → dist/assets}/empty.png +0 -0
  362. /package/{assets → dist/assets}/graph.svg +0 -0
  363. /package/{assets → dist/assets}/homeBg.png +0 -0
  364. /package/{assets → dist/assets}/index-B2yNvzjy.js +0 -0
  365. /package/{assets → dist/assets}/index-BKe5FgcC.js +0 -0
  366. /package/{assets → dist/assets}/index-CpW6Dhpp.js +0 -0
  367. /package/{assets → dist/assets}/index-D72cKELw.js +0 -0
  368. /package/{assets → dist/assets}/index-DdVFXD_y.js +0 -0
  369. /package/{assets → dist/assets}/index-DrkSoKz6.js +0 -0
  370. /package/{assets → dist/assets}/index-ZopkeZtI.js +0 -0
  371. /package/{assets → dist/assets}/index-g-SUxfJH.js +0 -0
  372. /package/{assets → dist/assets}/index-j0kQJd0a.js +0 -0
  373. /package/{assets → dist/assets}/knowledge.svg +0 -0
  374. /package/{assets → dist/assets}/left.jpg +0 -0
  375. /package/{assets → dist/assets}/logoImg.png +0 -0
  376. /package/{assets → dist/assets}/mysql.svg +0 -0
  377. /package/{assets → dist/assets}/plus-V9zUoSq6.js +0 -0
  378. /package/{assets → dist/assets}/sensitive.svg +0 -0
  379. /package/{assets → dist/assets}/style-CGmZ5osp.js +0 -0
  380. /package/{assets → dist/assets}/style.css +0 -0
  381. /package/{assets → dist/assets}/style2.css +0 -0
  382. /package/{assets → dist/assets}/style3.css +0 -0
  383. /package/{assets → dist/assets}/style4.css +0 -0
  384. /package/{assets → dist/assets}/worker-BbpylX7l.js +0 -0
  385. /package/{assets → dist/assets}/x-CnaaLGJF.js +0 -0
  386. /package/{assistantConfig.d.ts → dist/assistantConfig.d.ts} +0 -0
  387. /package/{assistantConfig.js → dist/assistantConfig.js} +0 -0
  388. /package/{chat.d.ts → dist/chat.d.ts} +0 -0
  389. /package/{database.d.ts → dist/database.d.ts} +0 -0
  390. /package/{database.js → dist/database.js} +0 -0
  391. /package/{databaseId.d.ts → dist/databaseId.d.ts} +0 -0
  392. /package/{databaseTable.d.ts → dist/databaseTable.d.ts} +0 -0
  393. /package/{databaseTable.js → dist/databaseTable.js} +0 -0
  394. /package/{icons → dist/icons}/answerAwartar.png +0 -0
  395. /package/{icons → dist/icons}/docx-file.png +0 -0
  396. /package/{icons → dist/icons}/folder.png +0 -0
  397. /package/{icons → dist/icons}/html.png +0 -0
  398. /package/{icons → dist/icons}/image.png +0 -0
  399. /package/{icons → dist/icons}/jpg-file.png +0 -0
  400. /package/{icons → dist/icons}/json.png +0 -0
  401. /package/{icons → dist/icons}/md.png +0 -0
  402. /package/{icons → dist/icons}/pdf.png +0 -0
  403. /package/{icons → dist/icons}/pptx.png +0 -0
  404. /package/{icons → dist/icons}/questionAwartar.png +0 -0
  405. /package/{icons → dist/icons}/sheets.png +0 -0
  406. /package/{icons → dist/icons}/txt.png +0 -0
  407. /package/{icons → dist/icons}/xlsx.png +0 -0
  408. /package/{index.d.ts → dist/index.d.ts} +0 -0
  409. /package/{modelManage.d.ts → dist/modelManage.d.ts} +0 -0
  410. /package/{modelManage.js → dist/modelManage.js} +0 -0
  411. /package/{sensitive.d.ts → dist/sensitive.d.ts} +0 -0
  412. /package/{sensitive.js → dist/sensitive.js} +0 -0
  413. /package/{streamFilesReader.d.ts → dist/streamFilesReader.d.ts} +0 -0
  414. /package/{vite.svg → dist/vite.svg} +0 -0
  415. /package/{worker → dist/worker}/pdf.worker.min.js +0 -0
@@ -0,0 +1,563 @@
1
+ import { message, Spin } from "antd";
2
+ import { useEffect, useState, useMemo, useCallback, useRef } from "react";
3
+ import { uid } from "uid";
4
+
5
+ import AssisSelect from "./AssisSelect";
6
+ import SearchInput from "./SearchInput";
7
+ import ResultContent from "./ResultContent";
8
+ import FileList from "./FileList";
9
+ import SearchLanding from "./SearchLanding";
10
+
11
+ import {
12
+ api_createDialogue,
13
+ api_start_kb_search,
14
+ api_kbSearchHistoryList,
15
+ api_kbSearchHistoryAdd,
16
+ api_kbSearcHistoryDelete
17
+ } from "../servers";
18
+
19
+ import { getUrlPrefix } from "../utils";
20
+ import "@/assets/styles/knowledgeSearch.less";
21
+
22
+ // 临时类型定义
23
+ enum StatusType {
24
+ Pending = 0,
25
+ Process = 1,
26
+ Success = 2,
27
+ Error = 3,
28
+ Done = 4
29
+ }
30
+
31
+ enum ChatSystemType {
32
+ TEMPORARY = 0,
33
+ PERMANENT = 1
34
+ }
35
+
36
+ interface QAChatItem {
37
+ id: string;
38
+ query: {
39
+ content: string;
40
+ type: string;
41
+ audioUrl: string;
42
+ queryId: string;
43
+ };
44
+ answer: {
45
+ content: string;
46
+ };
47
+ status: StatusType;
48
+ searchConfigDTO?: any;
49
+ }
50
+
51
+ // const initialPage = {
52
+ // page: 1,
53
+ // pageSize: 1000
54
+ // };
55
+
56
+ const cfg = {
57
+ url: getUrlPrefix(),
58
+ enableMock: false,
59
+ token: "/"
60
+ };
61
+
62
+ const KnowledgeSearch = () => {
63
+ const token = ""; // TODO: 需要从正确的store获取token
64
+ const [assistList, setAssistList] = useState<any[]>([]);
65
+ const [assistId, setAssistId] = useState<string>("");
66
+ const [searchRes, setSearchRes] = useState<any>({});
67
+ const [keyWord, setKeyWord] = useState<string>("");
68
+
69
+ const [cfgLoading, setCfgLoading] = useState(false);
70
+ const [loading] = useState(false);
71
+ const [isShowAssisText, setIsShowAssisText] = useState<boolean>(false);
72
+ const [historyList, setHistoryList] = useState<Array<any>>([]);
73
+ const [historyLoading, setHistoryLoading] = useState(false);
74
+ const [isSearch, setIsSearch] = useState(false);
75
+ const [filesObj, setFilesObj] = useState<any>({});
76
+ const [conversation, setConversation] = useState<any>({
77
+ id: uid(32),
78
+ name: "",
79
+ status: 0,
80
+ modify_timeStamp: new Date().getTime(),
81
+ sseController: new AbortController()
82
+ });
83
+ const streamDataRef = useRef<undefined | any>(undefined);
84
+ const initMessageData = useRef<any | undefined>(undefined);
85
+ const [selectFile, setSelectFile] = useState<string>("");
86
+ const [selectBlock, setSelectBlock] = useState<string>("");
87
+ const [isHistoryHide, setIsHistoryHide] = useState<boolean>(false);
88
+ const [clickPosition, setClickPosition] = useState<any>({ x: 0, y: 0 });
89
+ const [isHasSearch, setIsHasSearch] = useState<boolean>(false);
90
+ const [cptKey, setCptKey] = useState<string>(uid(32));
91
+
92
+ const getFileName = (url: string) => {
93
+ const regex = /([^/]+)\.([^/]+)$/;
94
+ const match = url.match(regex);
95
+
96
+ if (match) {
97
+ return {
98
+ fileName: match[1],
99
+ fileExtension: match[2],
100
+ url
101
+ };
102
+ }
103
+ return {};
104
+ };
105
+
106
+ const fileList = useMemo(() => {
107
+ const keys = Object.keys(filesObj);
108
+
109
+ return keys.length
110
+ ? keys.map((key: string) => {
111
+ const obj = {
112
+ ...getFileName(key),
113
+ list: (filesObj[key] || []).map((i: any, idx: number) =>
114
+ Object.assign({}, i, {
115
+ id: `${i.order_num || i.score}_${idx}`
116
+ })
117
+ )
118
+ };
119
+ return obj;
120
+ })
121
+ : [];
122
+ }, [filesObj]);
123
+
124
+ const handleAssistChanged = (aId: string) => {
125
+ setAssistId(aId);
126
+ };
127
+
128
+ const getConfig = () => {
129
+ return Object.assign({}, cfg, {
130
+ token: token || cfg.token
131
+ });
132
+ };
133
+
134
+ const fetchAssisList = () => {
135
+ setCfgLoading(true);
136
+ // TODO: 需要实现api_getHelperConfigList函数
137
+ Promise.resolve({ records: [] })
138
+ .then((res: any) => {
139
+ let _records = res;
140
+ if (Object.prototype.toString.call(_records) !== "[object Array]") {
141
+ const { records } = res;
142
+ _records = records || [];
143
+ }
144
+ const _assistId = _records && _records.length ? _records[0].id : "";
145
+ setAssistList([..._records]); // TODO: 需要实现assistantDTO_to_SelectOption函数
146
+ setAssistId(_assistId);
147
+ })
148
+ .finally(() => setCfgLoading(false));
149
+ };
150
+
151
+ const fetchHistoryList = () => {
152
+ setHistoryLoading(true);
153
+ api_kbSearchHistoryList({
154
+ data: {},
155
+ config: getConfig()
156
+ })
157
+ .then((res) => {
158
+ const _list =
159
+ Object.prototype.toString.call(res) === "[object Array]"
160
+ ? [...res]
161
+ : [];
162
+ setHistoryList([...Array.from(new Set([..._list]))]);
163
+ })
164
+ .finally(() => {
165
+ setHistoryLoading(false);
166
+ });
167
+ };
168
+
169
+ const deleteHistory = (queryContent: string = "") => {
170
+ api_kbSearcHistoryDelete({
171
+ data: {
172
+ queryContent
173
+ },
174
+ config: getConfig()
175
+ }).then((res: any) => {
176
+ if (res) {
177
+ if (queryContent) {
178
+ const _historyList = [...historyList];
179
+ const idx = _historyList.findIndex((i: string) => i === queryContent);
180
+ _historyList.splice(idx, 1);
181
+ setHistoryList([..._historyList]);
182
+ } else {
183
+ setHistoryList([]);
184
+ }
185
+ }
186
+ });
187
+ };
188
+
189
+ const keyOnChange = (val: string, isSearch: boolean = false) => {
190
+ setKeyWord(val);
191
+ if (isSearch) {
192
+ setTimeout(() => {
193
+ keyOnSearch(val);
194
+ }, 0);
195
+ }
196
+ };
197
+
198
+ const keyOnSearch = (val?: string) => {
199
+ const _val = val || keyWord;
200
+ if (_val) {
201
+ setConversation({
202
+ ...conversation,
203
+ status: StatusType.Process,
204
+ question: _val
205
+ });
206
+ api_kbSearchHistoryAdd({
207
+ data: {
208
+ queryContent: _val
209
+ },
210
+ config: getConfig()
211
+ }).then(() => {
212
+ setHistoryList([...Array.from(new Set([...historyList, _val]))]);
213
+ });
214
+ }
215
+ };
216
+
217
+ const onBlurHandler = () => {
218
+ setTimeout(() => {
219
+ isShowAssisText && setIsShowAssisText(false);
220
+ }, 500);
221
+ };
222
+
223
+ const showAssisText = () => {
224
+ !isShowAssisText && setIsShowAssisText(true);
225
+ };
226
+
227
+ const fixRetrieveTag = (content: string) => {
228
+ return Object.prototype.toString.call(content) === "[object String]"
229
+ ? content.replace(/\[retrive-tag[^\]]*\].*?\[\/retrive-tag\]/g, "")
230
+ : content;
231
+ };
232
+
233
+ const onMessageCallback = useCallback((event: any) => {
234
+ const curData = JSON.parse(event.data);
235
+ // console.log(curData, StatusType.Done)
236
+ setConversation({
237
+ ...conversation,
238
+ status: curData.status
239
+ });
240
+ if (curData.status === StatusType.Done) {
241
+ const { docsTree } = curData;
242
+ if (docsTree) {
243
+ try {
244
+ setFilesObj(JSON.parse(docsTree));
245
+ } catch (e) {
246
+ console.log(e);
247
+ }
248
+ }
249
+ setIsSearch(false);
250
+ setSearchRes((prevChat: any) => {
251
+ streamDataRef.current =
252
+ streamDataRef.current || initMessageData.current;
253
+ if (streamDataRef.current) {
254
+ const lastData = { ...curData };
255
+ lastData.reply.content =
256
+ streamDataRef.current?.answer?.content + curData.reply.content ||
257
+ "";
258
+ const data = lastData; // TODO: 需要实现stremDataToQAdata函数
259
+ // console.log("最新对话的最终处理数据", data)
260
+ const p = {
261
+ ...streamDataRef.current,
262
+ answer: {
263
+ ...streamDataRef.current.answer,
264
+ id: data?.qaData?.id || "",
265
+ reference: data?.qaData?.answer?.reference || [],
266
+ content: fixRetrieveTag(lastData.reply.content),
267
+ type: "text"
268
+ },
269
+ status: StatusType.Done
270
+ };
271
+ // console.log("最新对话的最终数据", p)
272
+ streamDataRef.current = undefined;
273
+ return { ...p };
274
+ }
275
+ return prevChat;
276
+ });
277
+ } else {
278
+ streamDataRef.current = !streamDataRef.current
279
+ ? initMessageData.current
280
+ : {
281
+ ...streamDataRef.current,
282
+ answer: {
283
+ ...(curData.reply || {}),
284
+ content:
285
+ streamDataRef.current.answer.content +
286
+ (curData.reply.content || ""),
287
+ type: "text" // 修正类型
288
+ }
289
+ };
290
+ try {
291
+ setSearchRes((prevChat: any) => {
292
+ if (streamDataRef.current) {
293
+ const lastData = { ...curData };
294
+ lastData.reply.content =
295
+ streamDataRef.current?.answer?.content || "";
296
+ const data = lastData; // TODO: 需要实现stremDataToQAdata函数
297
+ if (streamDataRef.current?.answer?.reference) {
298
+ streamDataRef.current.answer.reference =
299
+ data?.qaData?.answer?.reference || [];
300
+ streamDataRef.current.answer.id = data?.qaData?.id || "";
301
+ }
302
+ // console.log("data :", data)
303
+ const p = {
304
+ ...streamDataRef.current,
305
+ status: StatusType.Process
306
+ };
307
+ return { ...p };
308
+ }
309
+ return prevChat;
310
+ });
311
+ } catch (e) {
312
+ console.error(e);
313
+ }
314
+ }
315
+ }, []);
316
+
317
+ const onErrorCallback = useCallback(
318
+ (e: any) => {
319
+ setIsSearch(false);
320
+ setConversation({
321
+ ...conversation,
322
+ status: StatusType.Done
323
+ });
324
+
325
+ setSearchRes((_prevChat: any) => {
326
+ const p = {
327
+ ...(streamDataRef.current || initMessageData.current),
328
+ status: StatusType.Done
329
+ };
330
+ streamDataRef.current = undefined;
331
+ return { ...p };
332
+ });
333
+ message.error("请求失败!");
334
+ throw e;
335
+ },
336
+ [conversation]
337
+ );
338
+
339
+ const onCloseCallback = useCallback(() => {
340
+ setIsSearch(false);
341
+ // console.log("onCloseCallback sse")
342
+ // console.log("这里已经关闭了,不应该有数据")
343
+ conversation?.sseController.abort();
344
+ }, [conversation]);
345
+
346
+ const resetAll = () => {
347
+ setIsSearch(true);
348
+ setSearchRes({});
349
+ setFilesObj({});
350
+ clearSelect();
351
+ };
352
+
353
+ const clearSelect = () => {
354
+ setSelectBlock("");
355
+ setSelectFile("");
356
+ };
357
+
358
+ const selectFileHandler = (fileId: string) => {
359
+ setSelectFile(fileId);
360
+ setSelectBlock("");
361
+ };
362
+
363
+ const selectBlockHandler = (blockId: string) => {
364
+ setSelectBlock(blockId);
365
+ };
366
+
367
+ const historyHideHandler = (sta: boolean) => {
368
+ if (sta !== isHistoryHide) {
369
+ setIsHistoryHide(sta);
370
+ setTimeout(() => {
371
+ setIsHistoryHide(!sta);
372
+ }, 10);
373
+ }
374
+ };
375
+
376
+ const containerClickHandler = (e: any) => {
377
+ // e.preventDefault()
378
+ // e.stopPropagation()
379
+ if (!isHasSearch) {
380
+ const { clientX, clientY } = e;
381
+ // console.log(e.target, clientX, clientY)
382
+ setClickPosition({
383
+ x: clientX,
384
+ y: clientY
385
+ });
386
+ }
387
+ };
388
+
389
+ const resetClickPosition = (data: any) => {
390
+ setClickPosition({ ...data });
391
+ };
392
+
393
+ useEffect(() => {
394
+ const asyncEffect = async () => {
395
+ if (
396
+ conversation &&
397
+ conversation.status === StatusType.Process &&
398
+ conversation?.question &&
399
+ keyWord
400
+ ) {
401
+ resetAll();
402
+ const dialogId = `${uid(32)}_${assistId}`;
403
+ const res = await api_createDialogue({
404
+ data: {
405
+ label: keyWord,
406
+ sessionId: dialogId,
407
+ assist_id: assistId!,
408
+ sysType: ChatSystemType.TEMPORARY as any
409
+ },
410
+ config: getConfig()
411
+ });
412
+
413
+ if (res && conversation.status === StatusType.Process) {
414
+ conversation.sseController = new AbortController();
415
+ const chat_id = uid(32);
416
+ const serverInfo = getConfig();
417
+ conversation?.sseController.abort();
418
+ api_start_kb_search({
419
+ data: {
420
+ sessionId: res.sessionId,
421
+ queryId: chat_id,
422
+ name: res.name,
423
+ lastDate: new Date().getTime().toString(),
424
+ type: "text",
425
+ content: keyWord,
426
+ configId: res.configId,
427
+ audioUrl: "",
428
+ onMessage: onMessageCallback,
429
+ onError: onErrorCallback,
430
+ onClose: onCloseCallback,
431
+ signal: conversation.sseController.signal
432
+ },
433
+ config: {
434
+ url: serverInfo.url,
435
+ token: serverInfo.token,
436
+ enableMock: false
437
+ }
438
+ });
439
+ }
440
+ const p: QAChatItem = {
441
+ id: res ? res.sessionId : dialogId!,
442
+ query: {
443
+ content: keyWord!,
444
+ type: "text",
445
+ audioUrl: "",
446
+ queryId: uid(32)
447
+ },
448
+ answer: {
449
+ content: ""
450
+ },
451
+ status: StatusType.Pending,
452
+ searchConfigDTO: res ? res.searchConfigDTO : undefined // 添加此行以解决错误
453
+ };
454
+ initMessageData.current = p;
455
+ if (!isHasSearch) {
456
+ setIsHasSearch(true);
457
+ }
458
+ setCptKey(uid(32));
459
+ setSearchRes((_prevChat: any) => {
460
+ return { ..._prevChat, ...p };
461
+ });
462
+ }
463
+ };
464
+ asyncEffect();
465
+ }, [conversation]);
466
+
467
+ useEffect(() => {
468
+ fetchAssisList();
469
+ fetchHistoryList();
470
+ }, []);
471
+
472
+ return (
473
+ <div
474
+ className="knowledge-search-wrap p-5 mb-10 pr-0"
475
+ onClick={containerClickHandler}
476
+ >
477
+ <Spin spinning={loading}>
478
+ <div className="flex h-12 pr-5">
479
+ {isHasSearch ? (
480
+ <div className="flex-1 pr-5 search-wrap">
481
+ <SearchInput
482
+ loading={false}
483
+ keyWord={keyWord}
484
+ historyList={historyList}
485
+ historyLoading={historyLoading}
486
+ isSearch={isSearch}
487
+ isHistoryHide={isHistoryHide}
488
+ keyOnChange={keyOnChange}
489
+ keyOnSearch={keyOnSearch}
490
+ deleteHistory={deleteHistory}
491
+ />
492
+ </div>
493
+ ) : null}
494
+ <div className="min-w-[448px] w-1/3">
495
+ {isHasSearch ? (
496
+ <AssisSelect
497
+ disabled={false}
498
+ assistList={assistList}
499
+ value={assistId || ""}
500
+ loading={cfgLoading}
501
+ onChange={handleAssistChanged}
502
+ />
503
+ ) : (
504
+ <div
505
+ className={`show-search-select-wrap`}
506
+ onFocus={showAssisText}
507
+ >
508
+ <div className="select-wrap">
509
+ <AssisSelect
510
+ disabled={false}
511
+ assistList={assistList}
512
+ value={assistId || ""}
513
+ loading={cfgLoading}
514
+ onChange={handleAssistChanged}
515
+ onBlurHandler={onBlurHandler}
516
+ />
517
+ </div>
518
+ </div>
519
+ )}
520
+ </div>
521
+ </div>
522
+ {!isHasSearch ? (
523
+ <SearchLanding
524
+ keyWord={keyWord}
525
+ historyList={historyList}
526
+ historyLoading={historyLoading}
527
+ isSearch={isSearch}
528
+ isHistoryHide={isHistoryHide}
529
+ clickPosition={clickPosition}
530
+ keyOnChange={keyOnChange}
531
+ keyOnSearch={keyOnSearch}
532
+ setKeyWord={setKeyWord}
533
+ deleteHistory={deleteHistory}
534
+ resetClickPosition={resetClickPosition}
535
+ />
536
+ ) : (
537
+ <div className="result-wrap">
538
+ <ResultContent
539
+ answer={searchRes.answer}
540
+ status={conversation.status}
541
+ selectFile={selectFile}
542
+ selectBlock={selectBlock}
543
+ isHistoryHide={isHistoryHide}
544
+ fileList={fileList}
545
+ historyHideHandler={historyHideHandler}
546
+ clearSelect={clearSelect}
547
+ />
548
+ <FileList
549
+ key={`file-list-${cptKey}`}
550
+ fileList={fileList}
551
+ selectFile={selectFile}
552
+ selectBlock={selectBlock}
553
+ selectFileHandler={selectFileHandler}
554
+ selectBlockHandler={selectBlockHandler}
555
+ />
556
+ </div>
557
+ )}
558
+ </Spin>
559
+ </div>
560
+ );
561
+ };
562
+
563
+ export default KnowledgeSearch;
@@ -0,0 +1,158 @@
1
+ import React, { useState, useRef, useEffect } from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ const EditorContainer = styled.div`
5
+ border: 1px solid #d9d9d9;
6
+ border-radius: 6px;
7
+ padding: 8px 12px;
8
+ min-height: 100px;
9
+ background: #fff;
10
+ transition: border-color 0.3s;
11
+
12
+ &:focus-within {
13
+ border-color: #1890ff;
14
+ box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
15
+ }
16
+ `;
17
+
18
+ const EditorContent = styled.div`
19
+ outline: none;
20
+ min-height: 80px;
21
+ line-height: 1.5;
22
+ color: #262626;
23
+ font-size: 14px;
24
+
25
+ &[contenteditable="true"]:empty:before {
26
+ content: attr(data-placeholder);
27
+ color: #bfbfbf;
28
+ pointer-events: none;
29
+ }
30
+ `;
31
+
32
+ const Toolbar = styled.div`
33
+ display: flex;
34
+ gap: 8px;
35
+ margin-bottom: 8px;
36
+ padding: 4px 0;
37
+ border-bottom: 1px solid #f0f0f0;
38
+ `;
39
+
40
+ const ToolbarButton = styled.button<{ active?: boolean }>`
41
+ padding: 4px 8px;
42
+ border: 1px solid #d9d9d9;
43
+ border-radius: 4px;
44
+ background: ${props => props.active ? '#1890ff' : '#fff'};
45
+ color: ${props => props.active ? '#fff' : '#262626'};
46
+ cursor: pointer;
47
+ font-size: 12px;
48
+ transition: all 0.3s;
49
+
50
+ &:hover {
51
+ border-color: #1890ff;
52
+ color: #1890ff;
53
+ }
54
+
55
+ &:disabled {
56
+ opacity: 0.5;
57
+ cursor: not-allowed;
58
+ }
59
+ `;
60
+
61
+ interface SimpleEditorProps {
62
+ value?: string;
63
+ onChange?: (value: string) => void;
64
+ placeholder?: string;
65
+ readOnly?: boolean;
66
+ className?: string;
67
+ }
68
+
69
+ const SimpleEditor: React.FC<SimpleEditorProps> = ({
70
+ value = '',
71
+ onChange,
72
+ placeholder = '请输入内容...',
73
+ readOnly = false,
74
+ className
75
+ }) => {
76
+ const editorRef = useRef<HTMLDivElement>(null);
77
+ const [isBold, setIsBold] = useState(false);
78
+ const [isItalic, setIsItalic] = useState(false);
79
+
80
+ useEffect(() => {
81
+ if (editorRef.current && editorRef.current.innerHTML !== value) {
82
+ editorRef.current.innerHTML = value;
83
+ }
84
+ }, [value]);
85
+
86
+ const handleInput = () => {
87
+ if (editorRef.current && onChange) {
88
+ onChange(editorRef.current.innerHTML);
89
+ }
90
+ };
91
+
92
+ const execCommand = (command: string, value?: string) => {
93
+ document.execCommand(command, false, value);
94
+ editorRef.current?.focus();
95
+ handleInput();
96
+ };
97
+
98
+ const toggleBold = () => {
99
+ execCommand('bold');
100
+ setIsBold(!isBold);
101
+ };
102
+
103
+ const toggleItalic = () => {
104
+ execCommand('italic');
105
+ setIsItalic(!isItalic);
106
+ };
107
+
108
+ const insertLink = () => {
109
+ const url = prompt('请输入链接地址:');
110
+ if (url) {
111
+ execCommand('createLink', url);
112
+ }
113
+ };
114
+
115
+ const insertList = () => {
116
+ execCommand('insertUnorderedList');
117
+ };
118
+
119
+ return (
120
+ <div className={className}>
121
+ {!readOnly && (
122
+ <Toolbar>
123
+ <ToolbarButton
124
+ active={isBold}
125
+ onClick={toggleBold}
126
+ onMouseDown={(e) => e.preventDefault()}
127
+ >
128
+ 粗体
129
+ </ToolbarButton>
130
+ <ToolbarButton
131
+ active={isItalic}
132
+ onClick={toggleItalic}
133
+ onMouseDown={(e) => e.preventDefault()}
134
+ >
135
+ 斜体
136
+ </ToolbarButton>
137
+ <ToolbarButton onClick={insertLink} onMouseDown={(e) => e.preventDefault()}>
138
+ 链接
139
+ </ToolbarButton>
140
+ <ToolbarButton onClick={insertList} onMouseDown={(e) => e.preventDefault()}>
141
+ 列表
142
+ </ToolbarButton>
143
+ </Toolbar>
144
+ )}
145
+ <EditorContainer>
146
+ <EditorContent
147
+ ref={editorRef}
148
+ contentEditable={!readOnly}
149
+ onInput={handleInput}
150
+ data-placeholder={placeholder}
151
+ dangerouslySetInnerHTML={{ __html: value }}
152
+ />
153
+ </EditorContainer>
154
+ </div>
155
+ );
156
+ };
157
+
158
+ export default SimpleEditor;