@mxmweb/aichat 1.1.8 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist/adopters → adopters}/gientechCommon/components/Messages/AiChatBox.d.ts +3 -1
- package/{dist/adopters → adopters}/gientechCommon/components/Messages/RetriveItem.d.ts +2 -0
- package/assets/aichat.css +1 -0
- package/{dist/components → components}/AiChat.d.ts +1 -11
- package/{dist/index.js → index.js} +6523 -6497
- package/package.json +10 -41
- package/{dist/utils → utils}/index.d.ts +1 -0
- package/.editorconfig +0 -38
- package/.github/workflows/release.yml +0 -60
- package/.prettierignore +0 -16
- package/.prettierrc +0 -17
- package/.releaserc.json +0 -36
- package/CHANGELOG.md +0 -58
- package/CONTRIBUTING.md +0 -111
- package/NPMREADME.md +0 -215
- package/bash.exe.stackdump +0 -40
- package/components.json +0 -21
- package/demo.txt +0 -134
- package/dist/README.md +0 -216
- package/dist/assets/aichat.css +0 -1
- package/dist/package.json +0 -19
- package/eslint.config.js +0 -92
- package/index.html +0 -14
- package/postcss.config.cjs +0 -19
- package/public/icons/answerAwartar.png +0 -0
- package/public/icons/docx-file.png +0 -0
- package/public/icons/folder.png +0 -0
- package/public/icons/html.png +0 -0
- package/public/icons/image.png +0 -0
- package/public/icons/jpg-file.png +0 -0
- package/public/icons/json.png +0 -0
- package/public/icons/md.png +0 -0
- package/public/icons/pdf.png +0 -0
- package/public/icons/pptx.png +0 -0
- package/public/icons/questionAwartar.png +0 -0
- package/public/icons/sheets.png +0 -0
- package/public/icons/txt.png +0 -0
- package/public/icons/xlsx.png +0 -0
- package/public/libs/luckysheet/fontAwesome.otf +0 -0
- package/public/libs/luckysheet/fontawesome-webfont.eot +0 -0
- package/public/libs/luckysheet/fontawesome-webfont.svg +0 -2671
- package/public/libs/luckysheet/fontawesome-webfont.ttf +0 -0
- package/public/libs/luckysheet/fontawesome-webfont.woff +0 -0
- package/public/libs/luckysheet/fontawesome-webfont.woff2 +0 -0
- package/public/libs/luckysheet/fonts/fontawesome-webfont.ttf +0 -0
- package/public/libs/luckysheet/fonts/fontawesome-webfont.woff +0 -0
- package/public/libs/luckysheet/fonts/fontawesome-webfont.woff2 +0 -0
- package/public/libs/luckysheet/iconfont.css +0 -461
- package/public/libs/luckysheet/jquery.min.js +0 -2
- package/public/libs/luckysheet/luckysheet.css +0 -1
- package/public/libs/luckysheet/luckysheet.umd.js +0 -27
- package/public/libs/luckysheet/plugin.js +0 -1
- package/public/libs/luckysheet/plugins.css +0 -10
- package/public/libs/luckysheet/pluginsCss.css +0 -1
- package/public/vite.svg +0 -1
- package/public/vs/base/browser/ui/codicons/codicon/codicon.ttf +0 -0
- package/public/vs/base/common/worker/simpleWorker.nls.de.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.es.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.fr.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.it.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.ja.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.ko.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.ru.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.zh-cn.js +0 -8
- package/public/vs/base/common/worker/simpleWorker.nls.zh-tw.js +0 -8
- package/public/vs/base/worker/workerMain.js +0 -27
- package/public/vs/basic-languages/abap/abap.js +0 -10
- package/public/vs/basic-languages/apex/apex.js +0 -10
- package/public/vs/basic-languages/azcli/azcli.js +0 -10
- package/public/vs/basic-languages/bat/bat.js +0 -10
- package/public/vs/basic-languages/bicep/bicep.js +0 -11
- package/public/vs/basic-languages/cameligo/cameligo.js +0 -10
- package/public/vs/basic-languages/clojure/clojure.js +0 -10
- package/public/vs/basic-languages/coffee/coffee.js +0 -10
- package/public/vs/basic-languages/cpp/cpp.js +0 -10
- package/public/vs/basic-languages/csharp/csharp.js +0 -10
- package/public/vs/basic-languages/csp/csp.js +0 -10
- package/public/vs/basic-languages/css/css.js +0 -12
- package/public/vs/basic-languages/cypher/cypher.js +0 -10
- package/public/vs/basic-languages/dart/dart.js +0 -10
- package/public/vs/basic-languages/dockerfile/dockerfile.js +0 -10
- package/public/vs/basic-languages/ecl/ecl.js +0 -10
- package/public/vs/basic-languages/elixir/elixir.js +0 -10
- package/public/vs/basic-languages/flow9/flow9.js +0 -10
- package/public/vs/basic-languages/freemarker2/freemarker2.js +0 -12
- package/public/vs/basic-languages/fsharp/fsharp.js +0 -10
- package/public/vs/basic-languages/go/go.js +0 -10
- package/public/vs/basic-languages/graphql/graphql.js +0 -10
- package/public/vs/basic-languages/handlebars/handlebars.js +0 -10
- package/public/vs/basic-languages/hcl/hcl.js +0 -10
- package/public/vs/basic-languages/html/html.js +0 -10
- package/public/vs/basic-languages/ini/ini.js +0 -10
- package/public/vs/basic-languages/java/java.js +0 -10
- package/public/vs/basic-languages/javascript/javascript.js +0 -10
- package/public/vs/basic-languages/julia/julia.js +0 -10
- package/public/vs/basic-languages/kotlin/kotlin.js +0 -10
- package/public/vs/basic-languages/less/less.js +0 -11
- package/public/vs/basic-languages/lexon/lexon.js +0 -10
- package/public/vs/basic-languages/liquid/liquid.js +0 -10
- package/public/vs/basic-languages/lua/lua.js +0 -10
- package/public/vs/basic-languages/m3/m3.js +0 -10
- package/public/vs/basic-languages/markdown/markdown.js +0 -10
- package/public/vs/basic-languages/mdx/mdx.js +0 -10
- package/public/vs/basic-languages/mips/mips.js +0 -10
- package/public/vs/basic-languages/msdax/msdax.js +0 -10
- package/public/vs/basic-languages/mysql/mysql.js +0 -10
- package/public/vs/basic-languages/objective-c/objective-c.js +0 -10
- package/public/vs/basic-languages/pascal/pascal.js +0 -10
- package/public/vs/basic-languages/pascaligo/pascaligo.js +0 -10
- package/public/vs/basic-languages/perl/perl.js +0 -10
- package/public/vs/basic-languages/pgsql/pgsql.js +0 -10
- package/public/vs/basic-languages/php/php.js +0 -10
- package/public/vs/basic-languages/pla/pla.js +0 -10
- package/public/vs/basic-languages/postiats/postiats.js +0 -10
- package/public/vs/basic-languages/powerquery/powerquery.js +0 -10
- package/public/vs/basic-languages/powershell/powershell.js +0 -10
- package/public/vs/basic-languages/protobuf/protobuf.js +0 -11
- package/public/vs/basic-languages/pug/pug.js +0 -10
- package/public/vs/basic-languages/python/python.js +0 -10
- package/public/vs/basic-languages/qsharp/qsharp.js +0 -10
- package/public/vs/basic-languages/r/r.js +0 -10
- package/public/vs/basic-languages/razor/razor.js +0 -10
- package/public/vs/basic-languages/redis/redis.js +0 -10
- package/public/vs/basic-languages/redshift/redshift.js +0 -10
- package/public/vs/basic-languages/restructuredtext/restructuredtext.js +0 -10
- package/public/vs/basic-languages/ruby/ruby.js +0 -10
- package/public/vs/basic-languages/rust/rust.js +0 -10
- package/public/vs/basic-languages/sb/sb.js +0 -10
- package/public/vs/basic-languages/scala/scala.js +0 -10
- package/public/vs/basic-languages/scheme/scheme.js +0 -10
- package/public/vs/basic-languages/scss/scss.js +0 -12
- package/public/vs/basic-languages/shell/shell.js +0 -10
- package/public/vs/basic-languages/solidity/solidity.js +0 -10
- package/public/vs/basic-languages/sophia/sophia.js +0 -10
- package/public/vs/basic-languages/sparql/sparql.js +0 -10
- package/public/vs/basic-languages/sql/sql.js +0 -10
- package/public/vs/basic-languages/st/st.js +0 -10
- package/public/vs/basic-languages/swift/swift.js +0 -13
- package/public/vs/basic-languages/systemverilog/systemverilog.js +0 -10
- package/public/vs/basic-languages/tcl/tcl.js +0 -10
- package/public/vs/basic-languages/twig/twig.js +0 -10
- package/public/vs/basic-languages/typescript/typescript.js +0 -10
- package/public/vs/basic-languages/vb/vb.js +0 -10
- package/public/vs/basic-languages/wgsl/wgsl.js +0 -307
- package/public/vs/basic-languages/xml/xml.js +0 -10
- package/public/vs/basic-languages/yaml/yaml.js +0 -10
- package/public/vs/editor/editor.main.css +0 -6
- package/public/vs/editor/editor.main.js +0 -745
- package/public/vs/editor/editor.main.js.gz +0 -0
- package/public/vs/editor/editor.main.nls.de.js +0 -31
- package/public/vs/editor/editor.main.nls.es.js +0 -31
- package/public/vs/editor/editor.main.nls.fr.js +0 -29
- package/public/vs/editor/editor.main.nls.it.js +0 -29
- package/public/vs/editor/editor.main.nls.ja.js +0 -31
- package/public/vs/editor/editor.main.nls.js +0 -29
- package/public/vs/editor/editor.main.nls.ko.js +0 -29
- package/public/vs/editor/editor.main.nls.ru.js +0 -31
- package/public/vs/editor/editor.main.nls.zh-cn.js +0 -31
- package/public/vs/editor/editor.main.nls.zh-tw.js +0 -29
- package/public/vs/language/css/cssMode.js +0 -13
- package/public/vs/language/css/cssWorker.js +0 -81
- package/public/vs/language/css/cssWorker.js.gz +0 -0
- package/public/vs/language/html/htmlMode.js +0 -13
- package/public/vs/language/html/htmlWorker.js +0 -453
- package/public/vs/language/json/jsonMode.js +0 -15
- package/public/vs/language/json/jsonWorker.js +0 -36
- package/public/vs/language/typescript/tsMode.js +0 -20
- package/public/vs/language/typescript/tsWorker.js +0 -37016
- package/public/vs/language/typescript/tsWorker.js.gz +0 -0
- package/public/vs/loader.js +0 -11
- package/public/worker/pdf.worker.min.js +0 -32
- package/src/HeadlessChat.tsx +0 -250
- package/src/LoginPage/components/Login/LoginBox/index.tsx +0 -103
- package/src/LoginPage/components/Login/RegisterBox/index.tsx +0 -181
- package/src/LoginPage/components/Login/index.tsx +0 -101
- package/src/LoginPage/index.tsx +0 -103
- package/src/LoginPage/useServices.ts +0 -53
- package/src/LoginPage/utils.ts +0 -42
- package/src/Preview.tsx +0 -278
- package/src/UseLogingHeadless.tsx +0 -238
- package/src/adopters/GientechChat/Conversations/Item.tsx +0 -132
- package/src/adopters/GientechChat/Conversations/List.tsx +0 -127
- package/src/adopters/GientechChat/Conversations/groupByTime.ts +0 -39
- package/src/adopters/GientechChat/Conversations/index.tsx +0 -102
- package/src/adopters/GientechChat/constants.tsx +0 -33
- package/src/adopters/GientechChat/index.tsx +0 -1242
- package/src/adopters/GientechChat/types.ts +0 -17
- package/src/adopters/HeadLessChat/constants.tsx +0 -32
- package/src/adopters/HeadLessChat/index.tsx +0 -1038
- package/src/adopters/HeadLessChat/types.ts +0 -23
- package/src/adopters/gientechCommon/components/AppError.tsx +0 -32
- package/src/adopters/gientechCommon/components/AppLoading.tsx +0 -75
- package/src/adopters/gientechCommon/components/DisplayError.tsx +0 -33
- package/src/adopters/gientechCommon/components/DisplayLoading.tsx +0 -38
- package/src/adopters/gientechCommon/components/FeedBackModal.tsx +0 -310
- package/src/adopters/gientechCommon/components/FileManager/index.tsx +0 -381
- package/src/adopters/gientechCommon/components/FileManager/style.css +0 -5
- package/src/adopters/gientechCommon/components/Messages/AiChatBox.tsx +0 -530
- package/src/adopters/gientechCommon/components/Messages/GientechNewChatWelcome.tsx +0 -245
- package/src/adopters/gientechCommon/components/Messages/ReferenceCard.tsx +0 -302
- package/src/adopters/gientechCommon/components/Messages/RetriveItem.tsx +0 -194
- package/src/adopters/gientechCommon/components/Messages/UserChatBox.tsx +0 -211
- package/src/adopters/gientechCommon/components/RenameModal.tsx +0 -75
- package/src/adopters/gientechCommon/components/style.less +0 -11
- package/src/adopters/gientechCommon/configs/commonConfig.ts +0 -2
- package/src/adopters/gientechCommon/configs/senderConfig.ts +0 -0
- package/src/adopters/gientechCommon/configs/stylesConfig.ts +0 -142
- package/src/adopters/gientechCommon/hooks/AichatUseController.tsx +0 -308
- package/src/adopters/gientechCommon/slate/converters/deserializers.ts +0 -757
- package/src/adopters/gientechCommon/slate/converters/mockData.ts +0 -232
- package/src/adopters/gientechCommon/slate/converters/slateConverters.ts +0 -258
- package/src/adopters/gientechCommon/slate/richElements/index.tsx +0 -476
- package/src/adopters/gientechCommon/utils/request.ts +0 -37
- package/src/adopters/gientechCommon/utils/serverFn.ts +0 -143
- package/src/assets/img/downArrow.png +0 -0
- package/src/assets/img/excel.png +0 -0
- package/src/assets/img/img.png +0 -0
- package/src/assets/img/pdf.png +0 -0
- package/src/assets/img/ppt.png +0 -0
- package/src/assets/img/txt.png +0 -0
- package/src/assets/img/word.png +0 -0
- package/src/assets/login/homeBg.png +0 -0
- package/src/assets/login/left.jpg +0 -0
- package/src/assets/login/logoImg.png +0 -0
- package/src/assets/style.css +0 -1
- package/src/components/AiChat.tsx +0 -647
- package/src/components/AiChat.types.tsx +0 -110
- package/src/components/DefaultAppError.tsx +0 -7
- package/src/components/DefaultAppLoading.tsx +0 -7
- package/src/components/DefaultDisplayError.tsx +0 -7
- package/src/components/DefaultDisplayLoading.tsx +0 -7
- package/src/components/DefaultNewChatWelcome.tsx +0 -10
- package/src/components/Displayer/DefaultAiChatBox.tsx +0 -64
- package/src/components/Displayer/DefaultUserChatBox.tsx +0 -34
- package/src/components/Displayer/index.tsx +0 -107
- package/src/components/Displayer/slate/converters/deserializers.ts +0 -427
- package/src/components/Displayer/slate/converters/mockData.ts +0 -190
- package/src/components/Displayer/slate/converters/slateConverters.ts +0 -258
- package/src/components/Displayer/slate/richElements/index.tsx +0 -308
- package/src/components/DrawerContent.tsx +0 -105
- package/src/components/DrawerPreview.tsx +0 -36
- package/src/components/DynamicForm.tsx +0 -29
- package/src/components/Loading.tsx +0 -0
- package/src/components/RetrieveTest/components/ChatInput.tsx +0 -198
- package/src/components/RetrieveTest/components/ChatMessage.tsx +0 -894
- package/src/components/RetrieveTest/components/ConfigPanel.tsx +0 -472
- package/src/components/RetrieveTest/components/RichTextEditor.tsx +0 -97
- package/src/components/RetrieveTest/components/VoiceInput.tsx +0 -257
- package/src/components/RetrieveTest/components/config/index.ts +0 -0
- package/src/components/RetrieveTest/components/converters/deserializers.ts +0 -393
- package/src/components/RetrieveTest/components/converters/mockData.ts +0 -190
- package/src/components/RetrieveTest/components/converters/slateConverters.ts +0 -164
- package/src/components/RetrieveTest/components/richElements/index.tsx +0 -339
- package/src/components/RetrieveTest/components/style.css +0 -3
- package/src/components/RetrieveTest/index.tsx +0 -679
- package/src/components/Sender/FileUpload.tsx +0 -76
- package/src/components/Sender/FilesDisplay.tsx +0 -103
- package/src/components/Sender/VoiceInput.tsx +0 -81
- package/src/components/Sender/contexts/BadgeContext.tsx +0 -36
- package/src/components/Sender/index.tsx +0 -545
- package/src/components/Sidebar/Loading.tsx +0 -0
- package/src/components/Sidebar/RetriveConfigPanel.tsx +0 -41
- package/src/components/Sidebar/useDynamicFormItems.tsx +0 -176
- package/src/components/SidebarProp.ts +0 -41
- package/src/components/common/FileCardCommon.tsx +0 -82
- package/src/components/defaultStyleSet.tsx +0 -142
- package/src/components/styles.config.ts +0 -4
- package/src/lib_enter.ts +0 -12
- package/src/main.tsx +0 -12
- package/src/mockForm.ts +0 -91
- package/src/servers/chatApi.ts +0 -43
- package/src/servers/fileApi.ts +0 -12
- package/src/servers/modelApi.ts +0 -19
- package/src/style.css +0 -22
- package/src/testj.js +0 -3
- package/src/type.d.ts +0 -0
- package/src/utils/commonFn.tsx +0 -111
- package/src/utils/index.tsx +0 -94
- package/src/vite-env.d.ts +0 -11
- package/tailwind.config.js +0 -18
- package/tsconfig.app.json +0 -29
- package/tsconfig.app.tsbuildinfo +0 -11
- package/tsconfig.json +0 -13
- package/tsconfig.node.json +0 -22
- package/tsconfig.node.tsbuildinfo +0 -1
- package/vite.config.ts +0 -138
- package/vite.config_mainapp.ts +0 -126
- /package/{dist/HeadlessChat.d.ts → HeadlessChat.d.ts} +0 -0
- /package/{dist/LoginPage → LoginPage}/components/Login/LoginBox/index.d.ts +0 -0
- /package/{dist/LoginPage → LoginPage}/components/Login/RegisterBox/index.d.ts +0 -0
- /package/{dist/LoginPage → LoginPage}/components/Login/index.d.ts +0 -0
- /package/{dist/LoginPage → LoginPage}/index.d.ts +0 -0
- /package/{dist/LoginPage → LoginPage}/useServices.d.ts +0 -0
- /package/{dist/LoginPage → LoginPage}/utils.d.ts +0 -0
- /package/{dist/Preview.d.ts → Preview.d.ts} +0 -0
- /package/{dist/UseLogingHeadless.d.ts → UseLogingHeadless.d.ts} +0 -0
- /package/{dist/adopters → adopters}/GientechChat/Conversations/Item.d.ts +0 -0
- /package/{dist/adopters → adopters}/GientechChat/Conversations/List.d.ts +0 -0
- /package/{dist/adopters → adopters}/GientechChat/Conversations/groupByTime.d.ts +0 -0
- /package/{dist/adopters → adopters}/GientechChat/Conversations/index.d.ts +0 -0
- /package/{dist/adopters → adopters}/GientechChat/constants.d.ts +0 -0
- /package/{dist/adopters → adopters}/GientechChat/index.d.ts +0 -0
- /package/{dist/adopters → adopters}/GientechChat/types.d.ts +0 -0
- /package/{dist/adopters → adopters}/HeadLessChat/constants.d.ts +0 -0
- /package/{dist/adopters → adopters}/HeadLessChat/index.d.ts +0 -0
- /package/{dist/adopters → adopters}/HeadLessChat/types.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/AppError.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/AppLoading.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/DisplayError.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/DisplayLoading.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/FeedBackModal.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/FileManager/index.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/Messages/GientechNewChatWelcome.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/Messages/ReferenceCard.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/Messages/UserChatBox.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/components/RenameModal.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/configs/commonConfig.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/configs/senderConfig.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/configs/stylesConfig.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/hooks/AichatUseController.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/slate/converters/deserializers.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/slate/converters/mockData.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/slate/converters/slateConverters.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/slate/richElements/index.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/utils/request.d.ts +0 -0
- /package/{dist/adopters → adopters}/gientechCommon/utils/serverFn.d.ts +0 -0
- /package/{dist/components → components}/AiChat.types.d.ts +0 -0
- /package/{dist/components → components}/DefaultAppError.d.ts +0 -0
- /package/{dist/components → components}/DefaultAppLoading.d.ts +0 -0
- /package/{dist/components → components}/DefaultDisplayError.d.ts +0 -0
- /package/{dist/components → components}/DefaultDisplayLoading.d.ts +0 -0
- /package/{dist/components → components}/DefaultNewChatWelcome.d.ts +0 -0
- /package/{dist/components → components}/Displayer/DefaultAiChatBox.d.ts +0 -0
- /package/{dist/components → components}/Displayer/DefaultUserChatBox.d.ts +0 -0
- /package/{dist/components → components}/Displayer/index.d.ts +0 -0
- /package/{dist/components → components}/Displayer/slate/converters/deserializers.d.ts +0 -0
- /package/{dist/components → components}/Displayer/slate/converters/mockData.d.ts +0 -0
- /package/{dist/components → components}/Displayer/slate/converters/slateConverters.d.ts +0 -0
- /package/{dist/components → components}/Displayer/slate/richElements/index.d.ts +0 -0
- /package/{dist/components → components}/DrawerContent.d.ts +0 -0
- /package/{dist/components → components}/DrawerPreview.d.ts +0 -0
- /package/{dist/components → components}/DynamicForm.d.ts +0 -0
- /package/{dist/components → components}/Loading.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/ChatInput.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/ChatMessage.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/ConfigPanel.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/RichTextEditor.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/VoiceInput.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/config/index.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/converters/deserializers.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/converters/mockData.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/converters/slateConverters.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/components/richElements/index.d.ts +0 -0
- /package/{dist/components → components}/RetrieveTest/index.d.ts +0 -0
- /package/{dist/components → components}/Sender/FileUpload.d.ts +0 -0
- /package/{dist/components → components}/Sender/FilesDisplay.d.ts +0 -0
- /package/{dist/components → components}/Sender/VoiceInput.d.ts +0 -0
- /package/{dist/components → components}/Sender/contexts/BadgeContext.d.ts +0 -0
- /package/{dist/components → components}/Sender/index.d.ts +0 -0
- /package/{dist/components → components}/Sidebar/Loading.d.ts +0 -0
- /package/{dist/components → components}/Sidebar/RetriveConfigPanel.d.ts +0 -0
- /package/{dist/components → components}/Sidebar/useDynamicFormItems.d.ts +0 -0
- /package/{dist/components → components}/SidebarProp.d.ts +0 -0
- /package/{dist/components → components}/common/FileCardCommon.d.ts +0 -0
- /package/{dist/components → components}/defaultStyleSet.d.ts +0 -0
- /package/{dist/components → components}/styles.config.d.ts +0 -0
- /package/{dist/icons → icons}/answerAwartar.png +0 -0
- /package/{dist/icons → icons}/docx-file.png +0 -0
- /package/{dist/icons → icons}/folder.png +0 -0
- /package/{dist/icons → icons}/html.png +0 -0
- /package/{dist/icons → icons}/image.png +0 -0
- /package/{dist/icons → icons}/jpg-file.png +0 -0
- /package/{dist/icons → icons}/json.png +0 -0
- /package/{dist/icons → icons}/md.png +0 -0
- /package/{dist/icons → icons}/pdf.png +0 -0
- /package/{dist/icons → icons}/pptx.png +0 -0
- /package/{dist/icons → icons}/questionAwartar.png +0 -0
- /package/{dist/icons → icons}/sheets.png +0 -0
- /package/{dist/icons → icons}/txt.png +0 -0
- /package/{dist/icons → icons}/xlsx.png +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/lib_enter.d.ts → lib_enter.d.ts} +0 -0
- /package/{dist/libs → libs}/luckysheet/fontAwesome.otf +0 -0
- /package/{dist/libs → libs}/luckysheet/fontawesome-webfont.eot +0 -0
- /package/{dist/libs → libs}/luckysheet/fontawesome-webfont.svg +0 -0
- /package/{dist/libs → libs}/luckysheet/fontawesome-webfont.ttf +0 -0
- /package/{dist/libs → libs}/luckysheet/fontawesome-webfont.woff +0 -0
- /package/{dist/libs → libs}/luckysheet/fontawesome-webfont.woff2 +0 -0
- /package/{dist/libs → libs}/luckysheet/fonts/fontawesome-webfont.ttf +0 -0
- /package/{dist/libs → libs}/luckysheet/fonts/fontawesome-webfont.woff +0 -0
- /package/{dist/libs → libs}/luckysheet/fonts/fontawesome-webfont.woff2 +0 -0
- /package/{dist/libs → libs}/luckysheet/iconfont.css +0 -0
- /package/{dist/libs → libs}/luckysheet/jquery.min.js +0 -0
- /package/{dist/libs → libs}/luckysheet/luckysheet.css +0 -0
- /package/{dist/libs → libs}/luckysheet/luckysheet.umd.js +0 -0
- /package/{dist/libs → libs}/luckysheet/plugin.js +0 -0
- /package/{dist/libs → libs}/luckysheet/plugins.css +0 -0
- /package/{dist/libs → libs}/luckysheet/pluginsCss.css +0 -0
- /package/{dist/main.d.ts → main.d.ts} +0 -0
- /package/{dist/mockForm.d.ts → mockForm.d.ts} +0 -0
- /package/{dist/servers → servers}/chatApi.d.ts +0 -0
- /package/{dist/servers → servers}/fileApi.d.ts +0 -0
- /package/{dist/servers → servers}/modelApi.d.ts +0 -0
- /package/{dist/utils → utils}/commonFn.d.ts +0 -0
- /package/{dist/vite.svg → vite.svg} +0 -0
- /package/{dist/vs → vs}/base/browser/ui/codicons/codicon/codicon.ttf +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.de.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.es.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.fr.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.it.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.ja.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.ko.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.ru.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.zh-cn.js +0 -0
- /package/{dist/vs → vs}/base/common/worker/simpleWorker.nls.zh-tw.js +0 -0
- /package/{dist/vs → vs}/base/worker/workerMain.js +0 -0
- /package/{dist/vs → vs}/basic-languages/abap/abap.js +0 -0
- /package/{dist/vs → vs}/basic-languages/apex/apex.js +0 -0
- /package/{dist/vs → vs}/basic-languages/azcli/azcli.js +0 -0
- /package/{dist/vs → vs}/basic-languages/bat/bat.js +0 -0
- /package/{dist/vs → vs}/basic-languages/bicep/bicep.js +0 -0
- /package/{dist/vs → vs}/basic-languages/cameligo/cameligo.js +0 -0
- /package/{dist/vs → vs}/basic-languages/clojure/clojure.js +0 -0
- /package/{dist/vs → vs}/basic-languages/coffee/coffee.js +0 -0
- /package/{dist/vs → vs}/basic-languages/cpp/cpp.js +0 -0
- /package/{dist/vs → vs}/basic-languages/csharp/csharp.js +0 -0
- /package/{dist/vs → vs}/basic-languages/csp/csp.js +0 -0
- /package/{dist/vs → vs}/basic-languages/css/css.js +0 -0
- /package/{dist/vs → vs}/basic-languages/cypher/cypher.js +0 -0
- /package/{dist/vs → vs}/basic-languages/dart/dart.js +0 -0
- /package/{dist/vs → vs}/basic-languages/dockerfile/dockerfile.js +0 -0
- /package/{dist/vs → vs}/basic-languages/ecl/ecl.js +0 -0
- /package/{dist/vs → vs}/basic-languages/elixir/elixir.js +0 -0
- /package/{dist/vs → vs}/basic-languages/flow9/flow9.js +0 -0
- /package/{dist/vs → vs}/basic-languages/freemarker2/freemarker2.js +0 -0
- /package/{dist/vs → vs}/basic-languages/fsharp/fsharp.js +0 -0
- /package/{dist/vs → vs}/basic-languages/go/go.js +0 -0
- /package/{dist/vs → vs}/basic-languages/graphql/graphql.js +0 -0
- /package/{dist/vs → vs}/basic-languages/handlebars/handlebars.js +0 -0
- /package/{dist/vs → vs}/basic-languages/hcl/hcl.js +0 -0
- /package/{dist/vs → vs}/basic-languages/html/html.js +0 -0
- /package/{dist/vs → vs}/basic-languages/ini/ini.js +0 -0
- /package/{dist/vs → vs}/basic-languages/java/java.js +0 -0
- /package/{dist/vs → vs}/basic-languages/javascript/javascript.js +0 -0
- /package/{dist/vs → vs}/basic-languages/julia/julia.js +0 -0
- /package/{dist/vs → vs}/basic-languages/kotlin/kotlin.js +0 -0
- /package/{dist/vs → vs}/basic-languages/less/less.js +0 -0
- /package/{dist/vs → vs}/basic-languages/lexon/lexon.js +0 -0
- /package/{dist/vs → vs}/basic-languages/liquid/liquid.js +0 -0
- /package/{dist/vs → vs}/basic-languages/lua/lua.js +0 -0
- /package/{dist/vs → vs}/basic-languages/m3/m3.js +0 -0
- /package/{dist/vs → vs}/basic-languages/markdown/markdown.js +0 -0
- /package/{dist/vs → vs}/basic-languages/mdx/mdx.js +0 -0
- /package/{dist/vs → vs}/basic-languages/mips/mips.js +0 -0
- /package/{dist/vs → vs}/basic-languages/msdax/msdax.js +0 -0
- /package/{dist/vs → vs}/basic-languages/mysql/mysql.js +0 -0
- /package/{dist/vs → vs}/basic-languages/objective-c/objective-c.js +0 -0
- /package/{dist/vs → vs}/basic-languages/pascal/pascal.js +0 -0
- /package/{dist/vs → vs}/basic-languages/pascaligo/pascaligo.js +0 -0
- /package/{dist/vs → vs}/basic-languages/perl/perl.js +0 -0
- /package/{dist/vs → vs}/basic-languages/pgsql/pgsql.js +0 -0
- /package/{dist/vs → vs}/basic-languages/php/php.js +0 -0
- /package/{dist/vs → vs}/basic-languages/pla/pla.js +0 -0
- /package/{dist/vs → vs}/basic-languages/postiats/postiats.js +0 -0
- /package/{dist/vs → vs}/basic-languages/powerquery/powerquery.js +0 -0
- /package/{dist/vs → vs}/basic-languages/powershell/powershell.js +0 -0
- /package/{dist/vs → vs}/basic-languages/protobuf/protobuf.js +0 -0
- /package/{dist/vs → vs}/basic-languages/pug/pug.js +0 -0
- /package/{dist/vs → vs}/basic-languages/python/python.js +0 -0
- /package/{dist/vs → vs}/basic-languages/qsharp/qsharp.js +0 -0
- /package/{dist/vs → vs}/basic-languages/r/r.js +0 -0
- /package/{dist/vs → vs}/basic-languages/razor/razor.js +0 -0
- /package/{dist/vs → vs}/basic-languages/redis/redis.js +0 -0
- /package/{dist/vs → vs}/basic-languages/redshift/redshift.js +0 -0
- /package/{dist/vs → vs}/basic-languages/restructuredtext/restructuredtext.js +0 -0
- /package/{dist/vs → vs}/basic-languages/ruby/ruby.js +0 -0
- /package/{dist/vs → vs}/basic-languages/rust/rust.js +0 -0
- /package/{dist/vs → vs}/basic-languages/sb/sb.js +0 -0
- /package/{dist/vs → vs}/basic-languages/scala/scala.js +0 -0
- /package/{dist/vs → vs}/basic-languages/scheme/scheme.js +0 -0
- /package/{dist/vs → vs}/basic-languages/scss/scss.js +0 -0
- /package/{dist/vs → vs}/basic-languages/shell/shell.js +0 -0
- /package/{dist/vs → vs}/basic-languages/solidity/solidity.js +0 -0
- /package/{dist/vs → vs}/basic-languages/sophia/sophia.js +0 -0
- /package/{dist/vs → vs}/basic-languages/sparql/sparql.js +0 -0
- /package/{dist/vs → vs}/basic-languages/sql/sql.js +0 -0
- /package/{dist/vs → vs}/basic-languages/st/st.js +0 -0
- /package/{dist/vs → vs}/basic-languages/swift/swift.js +0 -0
- /package/{dist/vs → vs}/basic-languages/systemverilog/systemverilog.js +0 -0
- /package/{dist/vs → vs}/basic-languages/tcl/tcl.js +0 -0
- /package/{dist/vs → vs}/basic-languages/twig/twig.js +0 -0
- /package/{dist/vs → vs}/basic-languages/typescript/typescript.js +0 -0
- /package/{dist/vs → vs}/basic-languages/vb/vb.js +0 -0
- /package/{dist/vs → vs}/basic-languages/wgsl/wgsl.js +0 -0
- /package/{dist/vs → vs}/basic-languages/xml/xml.js +0 -0
- /package/{dist/vs → vs}/basic-languages/yaml/yaml.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.css +0 -0
- /package/{dist/vs → vs}/editor/editor.main.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.js.gz +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.de.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.es.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.fr.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.it.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.ja.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.ko.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.ru.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.zh-cn.js +0 -0
- /package/{dist/vs → vs}/editor/editor.main.nls.zh-tw.js +0 -0
- /package/{dist/vs → vs}/language/css/cssMode.js +0 -0
- /package/{dist/vs → vs}/language/css/cssWorker.js +0 -0
- /package/{dist/vs → vs}/language/css/cssWorker.js.gz +0 -0
- /package/{dist/vs → vs}/language/html/htmlMode.js +0 -0
- /package/{dist/vs → vs}/language/html/htmlWorker.js +0 -0
- /package/{dist/vs → vs}/language/json/jsonMode.js +0 -0
- /package/{dist/vs → vs}/language/json/jsonWorker.js +0 -0
- /package/{dist/vs → vs}/language/typescript/tsMode.js +0 -0
- /package/{dist/vs → vs}/language/typescript/tsWorker.js +0 -0
- /package/{dist/vs → vs}/language/typescript/tsWorker.js.gz +0 -0
- /package/{dist/vs → vs}/loader.js +0 -0
- /package/{dist/worker → worker}/pdf.worker.min.js +0 -0
|
@@ -1,757 +0,0 @@
|
|
|
1
|
-
import { marked } from 'marked';
|
|
2
|
-
import type {
|
|
3
|
-
CustomElement,
|
|
4
|
-
CustomText,
|
|
5
|
-
ParagraphElement,
|
|
6
|
-
HeadingOneElement,
|
|
7
|
-
HeadingTwoElement,
|
|
8
|
-
ListElement,
|
|
9
|
-
ListItemElement,
|
|
10
|
-
BaseElement,
|
|
11
|
-
CodeBlockElement,
|
|
12
|
-
HeadingThreeElement,
|
|
13
|
-
BlockQuoteElement,
|
|
14
|
-
TableElement,
|
|
15
|
-
TableRowElement,
|
|
16
|
-
TableCellElement,
|
|
17
|
-
} from './slateConverters';
|
|
18
|
-
|
|
19
|
-
// 新增think类型
|
|
20
|
-
export interface ThinkElement extends BaseElement {
|
|
21
|
-
type: 'think';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function ensureChildren(elements: CustomElement[]): CustomElement[] {
|
|
25
|
-
return elements.map(el => {
|
|
26
|
-
if (!el.children || el.children.length === 0) {
|
|
27
|
-
return { ...el, children: [{ text: '' }] };
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
...el,
|
|
31
|
-
children: el.children.map(child => {
|
|
32
|
-
if (typeof child === 'object' && 'type' in child) {
|
|
33
|
-
return ensureChildren([child as CustomElement])[0];
|
|
34
|
-
}
|
|
35
|
-
return child;
|
|
36
|
-
}),
|
|
37
|
-
};
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function getContentAfterThinkTag(text: string) {
|
|
41
|
-
if (text.indexOf('<think>') > -1) {
|
|
42
|
-
if (text.indexOf('</think>') > -1) {
|
|
43
|
-
const closedThinkRegex = /<think>([\s\S]*?)<\/think>([\s\S]*)/s;
|
|
44
|
-
const match = text.match(closedThinkRegex);
|
|
45
|
-
if (match) {
|
|
46
|
-
return {
|
|
47
|
-
thinkContent: match[1],
|
|
48
|
-
content: match[2],
|
|
49
|
-
finish: true,
|
|
50
|
-
};
|
|
51
|
-
} else {
|
|
52
|
-
return {
|
|
53
|
-
thinkContent: '',
|
|
54
|
-
content: text,
|
|
55
|
-
finish: true,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
const closedThinkRegex2 = /<think>(.*?)(?=<|\s*$)/s;
|
|
60
|
-
const match2 = text.match(closedThinkRegex2);
|
|
61
|
-
return { thinkContent: match2?.[1] || '', content: '' };
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
return {
|
|
65
|
-
thinkContent: '',
|
|
66
|
-
content: text,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export function deserializeMarkdown(markdown: string, respTime?: number): CustomElement[] {
|
|
71
|
-
// 先全局处理 retrive-tag
|
|
72
|
-
markdown = markdown.replace(
|
|
73
|
-
/\[retrive-tag([^\]]*)\]\[([\s\S]*?)\]\[\/retrive-tag\]/g,
|
|
74
|
-
(match, attrs, inner) => `<retrive-tag${attrs ? ' ' + attrs.trim() : ''}>${inner}</retrive-tag>`
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
// 1. 用正则分割出 <think>...</think> 和普通 markdown 块
|
|
78
|
-
// const blocks: { type: 'think' | 'markdown', content: string }[] = [];
|
|
79
|
-
// let lastIndex = 0;
|
|
80
|
-
// const thinkRegex = /<think>([\s\S]*?)<\/think>/g;
|
|
81
|
-
// let match;
|
|
82
|
-
// while ((match = thinkRegex.exec(markdown)) !== null) {
|
|
83
|
-
// if (match.index > lastIndex) {
|
|
84
|
-
// blocks.push({ type: 'markdown', content: markdown.slice(lastIndex, match.index) });
|
|
85
|
-
// }
|
|
86
|
-
// blocks.push({ type: 'think', content: match[1] });
|
|
87
|
-
// lastIndex = thinkRegex.lastIndex;
|
|
88
|
-
// }
|
|
89
|
-
// if (lastIndex < markdown.length) {
|
|
90
|
-
// blocks.push({ type: 'markdown', content: markdown.slice(lastIndex) });
|
|
91
|
-
// }
|
|
92
|
-
const blocks: { type: 'think' | 'markdown'; content: string; respTime?: number }[] = [];
|
|
93
|
-
const { thinkContent, content, finish } = getContentAfterThinkTag(markdown || '');
|
|
94
|
-
|
|
95
|
-
blocks.push({ type: 'think', content: thinkContent, respTime });
|
|
96
|
-
blocks.push({ type: 'markdown', content });
|
|
97
|
-
// 2. 分别处理每个块
|
|
98
|
-
let results: CustomElement[] = [];
|
|
99
|
-
let thinkId = 0;
|
|
100
|
-
// 新增:收集retrive-tag id顺序
|
|
101
|
-
const retriveTagOrder: string[] = [];
|
|
102
|
-
const retriveTagSet = new Set<string>();
|
|
103
|
-
// 包装原有的递归,收集id
|
|
104
|
-
function collectRetriveTagIds(nodes: any[]) {
|
|
105
|
-
for (const node of nodes) {
|
|
106
|
-
if (node && typeof node === 'object') {
|
|
107
|
-
if (Array.isArray(node)) {
|
|
108
|
-
collectRetriveTagIds(node);
|
|
109
|
-
} else {
|
|
110
|
-
if (node.retrive && node.id && !retriveTagSet.has(node.id)) {
|
|
111
|
-
retriveTagOrder.push(node.id);
|
|
112
|
-
retriveTagSet.add(node.id);
|
|
113
|
-
}
|
|
114
|
-
if (node.children) collectRetriveTagIds(node.children);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
for (const block of blocks) {
|
|
120
|
-
if (block.type === 'think') {
|
|
121
|
-
// think 块分行,遇到 retrive-tag 用 DOM 解析
|
|
122
|
-
const lines = block.content
|
|
123
|
-
.split(/\n+/)
|
|
124
|
-
.map(line => line.trim())
|
|
125
|
-
.filter(Boolean);
|
|
126
|
-
const children = lines.flatMap(line => {
|
|
127
|
-
if (/<retrive-tag/i.test(line)) {
|
|
128
|
-
const div = document.createElement('div');
|
|
129
|
-
div.innerHTML = line;
|
|
130
|
-
return deserializeHtmlNode(div, respTime);
|
|
131
|
-
} else {
|
|
132
|
-
// 保证类型一致,包装为 ParagraphElement
|
|
133
|
-
return [{ type: 'paragraph', children: [{ text: line }] } as ParagraphElement];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
// console.log('think AST:', {
|
|
137
|
-
// type: 'think',
|
|
138
|
-
// children,
|
|
139
|
-
// });
|
|
140
|
-
results.push({
|
|
141
|
-
type: 'think',
|
|
142
|
-
id: `think-${thinkId++}`,
|
|
143
|
-
thinkContent,
|
|
144
|
-
finish,
|
|
145
|
-
children,
|
|
146
|
-
} as any);
|
|
147
|
-
} else {
|
|
148
|
-
// 其它 markdown 块用 marked 解析
|
|
149
|
-
marked.setOptions({ gfm: true, breaks: true, pedantic: false });
|
|
150
|
-
let html = marked(block.content);
|
|
151
|
-
if (typeof html !== 'string') {
|
|
152
|
-
html = '';
|
|
153
|
-
}
|
|
154
|
-
const div = document.createElement('div');
|
|
155
|
-
div.innerHTML = html;
|
|
156
|
-
const part = deserializeHtmlNode(div, respTime);
|
|
157
|
-
if (part && part.length > 0) {
|
|
158
|
-
results = results.concat(part);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
// 收集所有retrive-tag id顺序
|
|
163
|
-
collectRetriveTagIds(results);
|
|
164
|
-
// 生成编号映射
|
|
165
|
-
const retriveTagIndexMap: Record<string, number> = {};
|
|
166
|
-
retriveTagOrder.forEach((id, idx) => {
|
|
167
|
-
retriveTagIndexMap[id] = idx + 1;
|
|
168
|
-
});
|
|
169
|
-
// 新增:递归给每个retrive-tag节点赋值indexId
|
|
170
|
-
function assignRetriveTagIndexId(nodes: any[]) {
|
|
171
|
-
for (const node of nodes) {
|
|
172
|
-
if (node && typeof node === 'object') {
|
|
173
|
-
if (Array.isArray(node)) {
|
|
174
|
-
assignRetriveTagIndexId(node);
|
|
175
|
-
} else {
|
|
176
|
-
if (node.retrive && node.id && retriveTagIndexMap[node.id]) {
|
|
177
|
-
node.indexId = retriveTagIndexMap[node.id];
|
|
178
|
-
}
|
|
179
|
-
if (node.children) assignRetriveTagIndexId(node.children);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
assignRetriveTagIndexId(results);
|
|
185
|
-
// 挂载到AST根节点
|
|
186
|
-
(results as any)._retriveTagIndexMap = retriveTagIndexMap;
|
|
187
|
-
// 保证返回值始终为非空数组,且所有节点children非空
|
|
188
|
-
if (!results || results.length === 0) {
|
|
189
|
-
return [{ type: 'paragraph', children: [{ text: '' }] } as ParagraphElement];
|
|
190
|
-
}
|
|
191
|
-
//console.log('deserializeMarkdown 返回 AST:', results);
|
|
192
|
-
return ensureChildren(results);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function deserializeHtmlNode(node: Node, respTime?: number): CustomElement[] {
|
|
196
|
-
const elements: CustomElement[] = [];
|
|
197
|
-
|
|
198
|
-
const deNodes = (elements: CustomElement[], nodeList: NodeListOf<ChildNode>) => {
|
|
199
|
-
nodeList.forEach((child: any) => {
|
|
200
|
-
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
201
|
-
const el = child as HTMLElement;
|
|
202
|
-
let result;
|
|
203
|
-
switch (el.tagName && el.tagName.toLowerCase()) {
|
|
204
|
-
case 'p': {
|
|
205
|
-
// 如果 <p> 只包含一个 <think>,则直接提升为 think 节点
|
|
206
|
-
const onlyChild = el.childNodes.length === 1 ? el.childNodes[0] : null;
|
|
207
|
-
if (
|
|
208
|
-
onlyChild &&
|
|
209
|
-
onlyChild.nodeType === Node.ELEMENT_NODE &&
|
|
210
|
-
(onlyChild as HTMLElement).tagName.toLowerCase() === 'think'
|
|
211
|
-
) {
|
|
212
|
-
// 直接递归 think,不包 paragraph
|
|
213
|
-
result = deserializeChildren(el)[0];
|
|
214
|
-
} else {
|
|
215
|
-
result = {
|
|
216
|
-
type: 'paragraph',
|
|
217
|
-
children: deserializeChildren(el),
|
|
218
|
-
} as ParagraphElement;
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
case 'h1':
|
|
223
|
-
result = {
|
|
224
|
-
type: 'heading-one',
|
|
225
|
-
children: deserializeChildren(el),
|
|
226
|
-
} as HeadingOneElement;
|
|
227
|
-
break;
|
|
228
|
-
case 'h2':
|
|
229
|
-
result = {
|
|
230
|
-
type: 'heading-two',
|
|
231
|
-
children: deserializeChildren(el),
|
|
232
|
-
} as HeadingTwoElement;
|
|
233
|
-
break;
|
|
234
|
-
case 'h3':
|
|
235
|
-
result = {
|
|
236
|
-
type: 'heading-three',
|
|
237
|
-
children: deserializeChildren(el),
|
|
238
|
-
} as HeadingThreeElement;
|
|
239
|
-
break;
|
|
240
|
-
case 'ul':
|
|
241
|
-
case 'ol': {
|
|
242
|
-
// 递归 deNodes,让 li 的 case 统一处理
|
|
243
|
-
let listChildren: CustomElement[] = [];
|
|
244
|
-
deNodes(listChildren, el.childNodes);
|
|
245
|
-
result = {
|
|
246
|
-
type: el.tagName.toLowerCase() === 'ul' ? 'bulleted-list' : 'numbered-list',
|
|
247
|
-
children: listChildren,
|
|
248
|
-
} as ListElement;
|
|
249
|
-
break;
|
|
250
|
-
}
|
|
251
|
-
case 'li':
|
|
252
|
-
case 'LI': {
|
|
253
|
-
// 判断 li 里是否有 block 元素
|
|
254
|
-
const hasBlock = Array.from(el.childNodes).some(child => {
|
|
255
|
-
if (child.nodeType !== Node.ELEMENT_NODE) return false;
|
|
256
|
-
const tag = (child as HTMLElement).tagName?.toUpperCase?.();
|
|
257
|
-
return tag === 'UL' || tag === 'OL' || tag === 'P';
|
|
258
|
-
});
|
|
259
|
-
let children: (CustomText | CustomElement)[];
|
|
260
|
-
if (hasBlock) {
|
|
261
|
-
// 直接递归所有子节点
|
|
262
|
-
children = el.childNodes
|
|
263
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
264
|
-
: [];
|
|
265
|
-
} else {
|
|
266
|
-
// 包一层 paragraph
|
|
267
|
-
children = [
|
|
268
|
-
{
|
|
269
|
-
type: 'paragraph',
|
|
270
|
-
children: (el.childNodes
|
|
271
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
272
|
-
: [{ text: '' }]) as (CustomText | CustomElement)[],
|
|
273
|
-
},
|
|
274
|
-
];
|
|
275
|
-
}
|
|
276
|
-
result = {
|
|
277
|
-
type: 'list-item',
|
|
278
|
-
children: children as (CustomText | CustomElement)[],
|
|
279
|
-
};
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
case 'pre': {
|
|
283
|
-
const codeEl = el.querySelector('code');
|
|
284
|
-
if (codeEl) {
|
|
285
|
-
result = {
|
|
286
|
-
type: 'code-block',
|
|
287
|
-
children: [{ text: codeEl.textContent || '' }],
|
|
288
|
-
} as any;
|
|
289
|
-
} else {
|
|
290
|
-
result = {
|
|
291
|
-
type: 'code-block',
|
|
292
|
-
children: [{ text: el.textContent || '' }],
|
|
293
|
-
} as any;
|
|
294
|
-
}
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
case 'code': {
|
|
298
|
-
if (!el.closest('pre')) {
|
|
299
|
-
result = {
|
|
300
|
-
type: 'paragraph',
|
|
301
|
-
children: [{ text: el.textContent || '', code: true }],
|
|
302
|
-
} as ParagraphElement;
|
|
303
|
-
}
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
case 'blockquote':
|
|
307
|
-
result = {
|
|
308
|
-
type: 'block-quote',
|
|
309
|
-
children: deserializeChildren(el),
|
|
310
|
-
} as BlockQuoteElement;
|
|
311
|
-
break;
|
|
312
|
-
case 'table':
|
|
313
|
-
result = deserializeTable(el);
|
|
314
|
-
break;
|
|
315
|
-
case 'think':
|
|
316
|
-
// 这里不再递归,直接跳过,由上层处理
|
|
317
|
-
return;
|
|
318
|
-
case 'retrive-tag': {
|
|
319
|
-
const id = el.getAttribute('id') || undefined;
|
|
320
|
-
const text = el.textContent || '';
|
|
321
|
-
result = [{ text, retrive: true, id }];
|
|
322
|
-
break;
|
|
323
|
-
}
|
|
324
|
-
case 'span':
|
|
325
|
-
case 'div': {
|
|
326
|
-
// flatten 所有子节点
|
|
327
|
-
let result: (CustomText | BaseElement)[] = [];
|
|
328
|
-
for (const child of Array.from(el.childNodes)) {
|
|
329
|
-
result = result.concat(processNode(child, {}));
|
|
330
|
-
}
|
|
331
|
-
return result;
|
|
332
|
-
}
|
|
333
|
-
default:
|
|
334
|
-
result = {
|
|
335
|
-
type: 'paragraph',
|
|
336
|
-
children: deserializeChildren(el),
|
|
337
|
-
} as ParagraphElement;
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
if (Array.isArray(result)) {
|
|
341
|
-
result.forEach(item => {
|
|
342
|
-
if ('text' in item && !('type' in item)) {
|
|
343
|
-
if (elements.length === 0) {
|
|
344
|
-
elements.push({ type: 'paragraph', children: [item] } as ParagraphElement);
|
|
345
|
-
} else {
|
|
346
|
-
const last = elements[elements.length - 1];
|
|
347
|
-
if (Array.isArray(last.children)) {
|
|
348
|
-
last.children.push(item);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
} else {
|
|
352
|
-
elements.push(item);
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
} else if (result) {
|
|
356
|
-
elements.push(result);
|
|
357
|
-
}
|
|
358
|
-
} else if (child.nodeType === Node.TEXT_NODE && child.textContent?.trim()) {
|
|
359
|
-
elements.push({
|
|
360
|
-
type: 'paragraph',
|
|
361
|
-
children: [{ text: child.textContent }],
|
|
362
|
-
} as ParagraphElement);
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
return elements;
|
|
366
|
-
};
|
|
367
|
-
deNodes(elements, node.childNodes);
|
|
368
|
-
// console.log('elements:', elements)
|
|
369
|
-
return elements;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// 将 processNode 提升到 deserializeChildren 外部作用域
|
|
373
|
-
function processNode(node: Node, styles: Partial<CustomText> = {}): (CustomText | CustomElement)[] {
|
|
374
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
375
|
-
const text = node.textContent?.trim();
|
|
376
|
-
if (text) {
|
|
377
|
-
if (styles.code) {
|
|
378
|
-
// 如果是行内代码,解析其中的 Markdown 样式
|
|
379
|
-
return parseInlineCodeMarkdown(text);
|
|
380
|
-
} else {
|
|
381
|
-
return [{ text, ...styles }];
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return [];
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
388
|
-
const el = node as HTMLElement;
|
|
389
|
-
const currentStyles = { ...styles };
|
|
390
|
-
|
|
391
|
-
const tag = el.tagName?.toUpperCase?.() || '';
|
|
392
|
-
|
|
393
|
-
if (tag === 'UL' || tag === 'OL') {
|
|
394
|
-
return [
|
|
395
|
-
{
|
|
396
|
-
type: tag === 'UL' ? 'bulleted-list' : 'numbered-list',
|
|
397
|
-
children: (el.childNodes
|
|
398
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
399
|
-
: []) as (CustomText | CustomElement)[],
|
|
400
|
-
},
|
|
401
|
-
];
|
|
402
|
-
}
|
|
403
|
-
if (tag === 'LI') {
|
|
404
|
-
// 判断 li 里是否有 block 元素
|
|
405
|
-
const hasBlock = Array.from(el.childNodes).some(child => {
|
|
406
|
-
if (child.nodeType !== Node.ELEMENT_NODE) return false;
|
|
407
|
-
const tag = (child as HTMLElement).tagName?.toUpperCase?.();
|
|
408
|
-
return tag === 'UL' || tag === 'OL' || tag === 'P';
|
|
409
|
-
});
|
|
410
|
-
let children: (CustomText | CustomElement)[];
|
|
411
|
-
if (hasBlock) {
|
|
412
|
-
// 直接递归所有子节点
|
|
413
|
-
children = el.childNodes
|
|
414
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
415
|
-
: [];
|
|
416
|
-
} else {
|
|
417
|
-
// 包一层 paragraph
|
|
418
|
-
children = [
|
|
419
|
-
{
|
|
420
|
-
type: 'paragraph',
|
|
421
|
-
children: (el.childNodes
|
|
422
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
423
|
-
: [{ text: '' }]) as (CustomText | CustomElement)[],
|
|
424
|
-
},
|
|
425
|
-
];
|
|
426
|
-
}
|
|
427
|
-
return [
|
|
428
|
-
{
|
|
429
|
-
type: 'list-item',
|
|
430
|
-
children: children as (CustomText | CustomElement)[],
|
|
431
|
-
},
|
|
432
|
-
];
|
|
433
|
-
}
|
|
434
|
-
if (tag === 'TABLE') {
|
|
435
|
-
return [
|
|
436
|
-
{
|
|
437
|
-
type: 'table',
|
|
438
|
-
children: (el.childNodes
|
|
439
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
440
|
-
: []) as (CustomText | CustomElement)[],
|
|
441
|
-
},
|
|
442
|
-
];
|
|
443
|
-
}
|
|
444
|
-
if (tag === 'THEAD' || tag === 'TBODY') {
|
|
445
|
-
return (
|
|
446
|
-
el.childNodes ? Array.from(el.childNodes).flatMap(child => processNode(child, {})) : []
|
|
447
|
-
) as (CustomText | CustomElement)[];
|
|
448
|
-
}
|
|
449
|
-
if (tag === 'TR') {
|
|
450
|
-
return [
|
|
451
|
-
{
|
|
452
|
-
type: 'table-row',
|
|
453
|
-
children: (el.childNodes
|
|
454
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
455
|
-
: []) as (CustomText | CustomElement)[],
|
|
456
|
-
},
|
|
457
|
-
];
|
|
458
|
-
}
|
|
459
|
-
if (tag === 'TD') {
|
|
460
|
-
return [
|
|
461
|
-
{
|
|
462
|
-
type: 'table-cell',
|
|
463
|
-
children: (el.childNodes
|
|
464
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
465
|
-
: [{ text: '' }]) as (CustomText | CustomElement)[],
|
|
466
|
-
},
|
|
467
|
-
];
|
|
468
|
-
}
|
|
469
|
-
if (tag === 'TH') {
|
|
470
|
-
return [
|
|
471
|
-
{
|
|
472
|
-
type: 'table-cell',
|
|
473
|
-
header: true,
|
|
474
|
-
children: (el.childNodes
|
|
475
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
476
|
-
: [{ text: '' }]) as (CustomText | CustomElement)[],
|
|
477
|
-
},
|
|
478
|
-
];
|
|
479
|
-
}
|
|
480
|
-
if (tag === 'THINK') {
|
|
481
|
-
return [
|
|
482
|
-
{
|
|
483
|
-
type: 'think',
|
|
484
|
-
children: (el.childNodes
|
|
485
|
-
? Array.from(el.childNodes).flatMap(child => processNode(child, {}))
|
|
486
|
-
: []) as (CustomText | CustomElement)[],
|
|
487
|
-
} as any,
|
|
488
|
-
];
|
|
489
|
-
}
|
|
490
|
-
if (tag === 'RETRIVE-TAG') {
|
|
491
|
-
// 收集所有 attribute
|
|
492
|
-
const attrs: Record<string, string> = {};
|
|
493
|
-
for (const attr of Array.from(el.attributes)) {
|
|
494
|
-
attrs[attr.name] = attr.value;
|
|
495
|
-
}
|
|
496
|
-
const children = el.childNodes
|
|
497
|
-
? Array.from(el.childNodes).flatMap(child => {
|
|
498
|
-
const nodes = processNode(child, {});
|
|
499
|
-
return nodes.map(n =>
|
|
500
|
-
typeof n === 'object' && 'text' in n ? { ...n, retrive: true, ...attrs } : n
|
|
501
|
-
);
|
|
502
|
-
})
|
|
503
|
-
: [{ text: '', retrive: true, ...attrs }];
|
|
504
|
-
return children as (CustomText | CustomElement)[];
|
|
505
|
-
}
|
|
506
|
-
// 兜底:未知标签递归其所有子节点
|
|
507
|
-
if (el.childNodes && el.childNodes.length > 0) {
|
|
508
|
-
return Array.from(el.childNodes).flatMap(child => processNode(child, {})) as (
|
|
509
|
-
| CustomText
|
|
510
|
-
| CustomElement
|
|
511
|
-
)[];
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
switch (tag) {
|
|
515
|
-
case 'EM':
|
|
516
|
-
case 'I':
|
|
517
|
-
currentStyles.italic = true;
|
|
518
|
-
break;
|
|
519
|
-
case 'STRONG':
|
|
520
|
-
case 'B':
|
|
521
|
-
currentStyles.bold = true;
|
|
522
|
-
break;
|
|
523
|
-
case 'CODE':
|
|
524
|
-
if (!el.closest('pre')) {
|
|
525
|
-
currentStyles.code = true;
|
|
526
|
-
}
|
|
527
|
-
break;
|
|
528
|
-
case 'DEL':
|
|
529
|
-
case 'S':
|
|
530
|
-
currentStyles.strikethrough = true;
|
|
531
|
-
break;
|
|
532
|
-
case 'U':
|
|
533
|
-
currentStyles.underline = true;
|
|
534
|
-
break;
|
|
535
|
-
case 'A':
|
|
536
|
-
currentStyles.link = el.getAttribute('href') || undefined;
|
|
537
|
-
break;
|
|
538
|
-
case 'SPAN':
|
|
539
|
-
case 'DIV': {
|
|
540
|
-
// flatten 所有子节点
|
|
541
|
-
let result: (CustomText | CustomElement)[] = [];
|
|
542
|
-
for (const child of Array.from(el.childNodes)) {
|
|
543
|
-
result = result.concat(processNode(child, {}));
|
|
544
|
-
}
|
|
545
|
-
return result;
|
|
546
|
-
}
|
|
547
|
-
default:
|
|
548
|
-
break;
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
return [];
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
// 解析行内代码中的 Markdown 样式
|
|
555
|
-
function parseInlineCodeMarkdown(text: string): CustomText[] {
|
|
556
|
-
const result: CustomText[] = [];
|
|
557
|
-
let currentText = '';
|
|
558
|
-
let isBold = false;
|
|
559
|
-
let isItalic = false;
|
|
560
|
-
let i = 0;
|
|
561
|
-
|
|
562
|
-
while (i < text.length) {
|
|
563
|
-
if (text.startsWith('**', i)) {
|
|
564
|
-
// 处理加粗
|
|
565
|
-
if (currentText) {
|
|
566
|
-
result.push({
|
|
567
|
-
text: currentText,
|
|
568
|
-
code: true,
|
|
569
|
-
bold: isBold,
|
|
570
|
-
italic: isItalic,
|
|
571
|
-
});
|
|
572
|
-
currentText = '';
|
|
573
|
-
}
|
|
574
|
-
isBold = !isBold;
|
|
575
|
-
i += 2;
|
|
576
|
-
} else if (text.startsWith('*', i)) {
|
|
577
|
-
// 处理斜体
|
|
578
|
-
if (currentText) {
|
|
579
|
-
result.push({
|
|
580
|
-
text: currentText,
|
|
581
|
-
code: true,
|
|
582
|
-
bold: isBold,
|
|
583
|
-
italic: isItalic,
|
|
584
|
-
});
|
|
585
|
-
currentText = '';
|
|
586
|
-
}
|
|
587
|
-
isItalic = !isItalic;
|
|
588
|
-
i += 1;
|
|
589
|
-
} else {
|
|
590
|
-
currentText += text[i];
|
|
591
|
-
i += 1;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
if (currentText) {
|
|
596
|
-
result.push({
|
|
597
|
-
text: currentText,
|
|
598
|
-
code: true,
|
|
599
|
-
bold: isBold,
|
|
600
|
-
italic: isItalic,
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
return result;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// 保持 processNode 和 deserializeChildren 的实现
|
|
608
|
-
function deserializeChildren(node: Node): (CustomText | BaseElement)[] {
|
|
609
|
-
const texts: (CustomText | BaseElement)[] = [];
|
|
610
|
-
|
|
611
|
-
for (const child of Array.from(node.childNodes)) {
|
|
612
|
-
texts.push(...processNode(child));
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
return texts;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
function deserializeTable(tableEl: HTMLElement): TableElement {
|
|
619
|
-
const rows: TableRowElement[] = [];
|
|
620
|
-
|
|
621
|
-
// 处理表头
|
|
622
|
-
const thead = tableEl.querySelector('thead');
|
|
623
|
-
const tbody = tableEl.querySelector('tbody');
|
|
624
|
-
|
|
625
|
-
// 如果没有 thead 和 tbody,说明是简单表格,需要自动添加结构
|
|
626
|
-
if (!thead && !tbody) {
|
|
627
|
-
const allRows = Array.from(tableEl.querySelectorAll('tr'));
|
|
628
|
-
if (allRows.length > 0) {
|
|
629
|
-
// 第一行作为表头
|
|
630
|
-
rows.push({
|
|
631
|
-
type: 'table-row',
|
|
632
|
-
children: Array.from(allRows[0].children).map(
|
|
633
|
-
cell =>
|
|
634
|
-
({
|
|
635
|
-
type: 'table-cell',
|
|
636
|
-
header: true,
|
|
637
|
-
children: deserializeChildren(cell),
|
|
638
|
-
}) as TableCellElement
|
|
639
|
-
),
|
|
640
|
-
} as TableRowElement);
|
|
641
|
-
|
|
642
|
-
// 剩余行作为表格主体
|
|
643
|
-
allRows.slice(1).forEach(tr => {
|
|
644
|
-
rows.push({
|
|
645
|
-
type: 'table-row',
|
|
646
|
-
children: Array.from(tr.children).map(
|
|
647
|
-
cell =>
|
|
648
|
-
({
|
|
649
|
-
type: 'table-cell',
|
|
650
|
-
header: false,
|
|
651
|
-
children: deserializeChildren(cell),
|
|
652
|
-
}) as TableCellElement
|
|
653
|
-
),
|
|
654
|
-
} as TableRowElement);
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
} else {
|
|
658
|
-
// 处理表头
|
|
659
|
-
if (thead) {
|
|
660
|
-
const headerRow = thead.querySelector('tr');
|
|
661
|
-
if (headerRow) {
|
|
662
|
-
rows.push({
|
|
663
|
-
type: 'table-row',
|
|
664
|
-
children: Array.from(headerRow.querySelectorAll('th')).map(
|
|
665
|
-
cell =>
|
|
666
|
-
({
|
|
667
|
-
type: 'table-cell',
|
|
668
|
-
header: true,
|
|
669
|
-
children: deserializeChildren(cell),
|
|
670
|
-
}) as TableCellElement
|
|
671
|
-
),
|
|
672
|
-
} as TableRowElement);
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
// 处理表格主体
|
|
677
|
-
if (tbody) {
|
|
678
|
-
Array.from(tbody.querySelectorAll('tr')).forEach(tr => {
|
|
679
|
-
rows.push({
|
|
680
|
-
type: 'table-row',
|
|
681
|
-
children: Array.from(tr.querySelectorAll('td')).map(
|
|
682
|
-
cell =>
|
|
683
|
-
({
|
|
684
|
-
type: 'table-cell',
|
|
685
|
-
header: false,
|
|
686
|
-
children: deserializeChildren(cell),
|
|
687
|
-
}) as TableCellElement
|
|
688
|
-
),
|
|
689
|
-
} as TableRowElement);
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
return {
|
|
695
|
-
type: 'table',
|
|
696
|
-
children: rows,
|
|
697
|
-
} as TableElement;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
function mergeHeadingAndList(html: string): string {
|
|
701
|
-
const div = document.createElement('div');
|
|
702
|
-
div.innerHTML = html;
|
|
703
|
-
let nodes = Array.from(div.childNodes);
|
|
704
|
-
let i = 0;
|
|
705
|
-
while (i < nodes.length - 1) {
|
|
706
|
-
const cur = nodes[i];
|
|
707
|
-
const next = nodes[i + 1];
|
|
708
|
-
// 支持 h2/h3/h4 + ul/ol/p/blockquote/pre
|
|
709
|
-
if (
|
|
710
|
-
cur.nodeType === 1 &&
|
|
711
|
-
['H2', 'H3', 'H4'].includes((cur as HTMLElement).tagName) &&
|
|
712
|
-
next.nodeType === 1 &&
|
|
713
|
-
['UL', 'OL', 'P', 'BLOCKQUOTE', 'PRE'].includes((next as HTMLElement).tagName)
|
|
714
|
-
) {
|
|
715
|
-
// 创建 li
|
|
716
|
-
const li = document.createElement('li');
|
|
717
|
-
li.appendChild(cur.cloneNode(true));
|
|
718
|
-
li.appendChild(next.cloneNode(true));
|
|
719
|
-
// 检查后续是否还有连续的 ul/ol/p/blockquote/pre
|
|
720
|
-
let j = i + 2;
|
|
721
|
-
while (
|
|
722
|
-
j < nodes.length &&
|
|
723
|
-
nodes[j].nodeType === 1 &&
|
|
724
|
-
['UL', 'OL', 'P', 'BLOCKQUOTE', 'PRE'].includes((nodes[j] as HTMLElement).tagName)
|
|
725
|
-
) {
|
|
726
|
-
li.appendChild(nodes[j].cloneNode(true));
|
|
727
|
-
j++;
|
|
728
|
-
}
|
|
729
|
-
// 查找前面的 ol,没有就新建
|
|
730
|
-
let ol = null;
|
|
731
|
-
for (let k = i - 1; k >= 0; k--) {
|
|
732
|
-
if (nodes[k].nodeType === 1 && (nodes[k] as HTMLElement).tagName === 'OL') {
|
|
733
|
-
ol = nodes[k];
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
if (!ol) {
|
|
738
|
-
ol = document.createElement('ol');
|
|
739
|
-
div.insertBefore(ol, cur);
|
|
740
|
-
nodes = Array.from(div.childNodes);
|
|
741
|
-
i = nodes.indexOf(ol);
|
|
742
|
-
}
|
|
743
|
-
ol.appendChild(li);
|
|
744
|
-
// 移除原 h2/h3/h4 和后续所有连续的 ul/ol/p/blockquote/pre
|
|
745
|
-
div.removeChild(cur);
|
|
746
|
-
div.removeChild(next);
|
|
747
|
-
for (let k = i + 1; k < j - 1; k++) {
|
|
748
|
-
div.removeChild(nodes[k + 1]);
|
|
749
|
-
}
|
|
750
|
-
// 重新获取 nodes
|
|
751
|
-
nodes = Array.from(div.childNodes);
|
|
752
|
-
i = -1; // 重新遍历
|
|
753
|
-
}
|
|
754
|
-
i++;
|
|
755
|
-
}
|
|
756
|
-
return div.innerHTML;
|
|
757
|
-
}
|