@qlover/create-app 0.7.15 → 0.9.0
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/CHANGELOG.md +21 -0
- package/dist/configs/_common/.github/workflows/general-check.yml +1 -1
- package/dist/configs/_common/.github/workflows/release.yml +2 -2
- package/dist/configs/_common/.gitignore.template +6 -0
- package/dist/configs/_common/.prettierignore +17 -5
- package/dist/configs/_common/.vscode/settings.json +6 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/templates/next-app/.env.template +1 -1
- package/dist/templates/next-app/README.en.md +0 -1
- package/dist/templates/next-app/README.md +0 -1
- package/dist/templates/next-app/config/Identifier/api.ts +5 -5
- package/dist/templates/next-app/config/Identifier/common/admint.table.ts +69 -0
- package/dist/templates/next-app/config/Identifier/common/common.ts +76 -0
- package/dist/templates/next-app/config/Identifier/common/index.ts +3 -0
- package/dist/templates/next-app/config/Identifier/{validator.ts → common/validators.ts} +5 -5
- package/dist/templates/next-app/config/Identifier/index.ts +2 -12
- package/dist/templates/next-app/config/Identifier/pages/index.ts +6 -0
- package/dist/templates/next-app/config/Identifier/pages/page.admin.home.ts +27 -0
- package/dist/templates/next-app/config/Identifier/pages/page.admin.locales.ts +266 -0
- package/dist/templates/next-app/config/Identifier/pages/page.admin.user.ts +293 -0
- package/dist/templates/{react-app/config/Identifier → next-app/config/Identifier/pages}/page.home.ts +15 -22
- package/dist/templates/next-app/config/Identifier/{page.login.ts → pages/page.login.ts} +28 -34
- package/dist/templates/next-app/config/Identifier/{page.register.ts → pages/page.register.ts} +30 -29
- package/dist/templates/next-app/config/adminNavs.ts +19 -0
- package/dist/templates/next-app/config/common.ts +22 -13
- package/dist/templates/next-app/config/i18n/HomeI18n.ts +5 -5
- package/dist/templates/next-app/config/i18n/admin18n.ts +61 -19
- package/dist/templates/next-app/config/i18n/i18nConfig.ts +2 -0
- package/dist/templates/next-app/config/i18n/i18nKeyScheam.ts +36 -0
- package/dist/templates/next-app/config/i18n/loginI18n.ts +22 -22
- package/dist/templates/next-app/config/i18n/register18n.ts +23 -24
- package/dist/templates/next-app/docs/en/index.md +0 -1
- package/dist/templates/next-app/docs/en/project-structure.md +0 -1
- package/dist/templates/next-app/docs/zh/index.md +0 -1
- package/dist/templates/next-app/docs/zh/project-structure.md +0 -1
- package/dist/templates/next-app/make/generateLocales.ts +19 -12
- package/dist/templates/next-app/migrations/schema/LocalesSchema.ts +15 -0
- package/dist/templates/next-app/migrations/sql/1694244000000.sql +11 -0
- package/dist/templates/next-app/package.json +7 -3
- package/dist/templates/next-app/public/locales/en.json +172 -207
- package/dist/templates/next-app/public/locales/zh.json +172 -207
- package/dist/templates/next-app/src/app/[locale]/admin/locales/page.tsx +153 -0
- package/dist/templates/next-app/src/app/[locale]/admin/users/page.tsx +48 -50
- package/dist/templates/next-app/src/app/[locale]/login/LoginForm.tsx +2 -2
- package/dist/templates/next-app/src/app/api/admin/locales/create/route.ts +34 -0
- package/dist/templates/next-app/src/app/api/admin/locales/import/route.ts +40 -0
- package/dist/templates/next-app/src/app/api/admin/locales/route.ts +42 -0
- package/dist/templates/next-app/src/app/api/admin/locales/update/route.ts +32 -0
- package/dist/templates/next-app/src/app/api/locales/json/route.ts +44 -0
- package/dist/templates/next-app/src/base/cases/AdminPageManager.ts +1 -13
- package/dist/templates/next-app/src/base/cases/Datetime.ts +18 -0
- package/dist/templates/next-app/src/base/cases/DialogErrorPlugin.ts +12 -6
- package/dist/templates/next-app/src/base/cases/ResourceState.ts +17 -0
- package/dist/templates/next-app/src/base/cases/TranslateI18nInterface.ts +25 -0
- package/dist/templates/next-app/src/base/cases/ZodColumnBuilder.ts +200 -0
- package/dist/templates/next-app/src/base/port/ZodBuilderInterface.ts +8 -0
- package/dist/templates/next-app/src/base/services/AdminLocalesService.ts +20 -0
- package/dist/templates/next-app/src/base/services/AdminPageEvent.ts +26 -0
- package/dist/templates/next-app/src/base/services/AdminPageScheduler.ts +42 -0
- package/dist/templates/next-app/src/base/services/ResourceService.ts +122 -0
- package/dist/templates/next-app/src/base/services/adminApi/AdminLocalesApi.ts +104 -0
- package/dist/templates/next-app/src/base/services/adminApi/AdminUserApi.ts +38 -5
- package/dist/templates/next-app/src/base/services/appApi/AppApiPlugin.ts +1 -1
- package/dist/templates/next-app/src/i18n/request.ts +30 -1
- package/dist/templates/next-app/src/server/PageParams.ts +2 -10
- package/dist/templates/next-app/src/server/port/DBBridgeInterface.ts +5 -0
- package/dist/templates/next-app/src/server/port/DBTableInterface.ts +2 -0
- package/dist/templates/next-app/src/server/port/LocalesRepositoryInterface.ts +43 -0
- package/dist/templates/next-app/src/server/repositorys/LocalesRepository.ts +197 -0
- package/dist/templates/next-app/src/server/services/ApiLocaleService.ts +122 -0
- package/dist/templates/next-app/src/server/sqlBridges/SupabaseBridge.ts +60 -11
- package/dist/templates/next-app/src/server/validators/ExtendedExecutorError.ts +6 -0
- package/dist/templates/next-app/src/server/validators/LocalesValidator.ts +131 -0
- package/dist/templates/next-app/src/server/validators/LoginValidator.ts +2 -5
- package/dist/templates/next-app/src/server/validators/PaginationValidator.ts +32 -16
- package/dist/templates/next-app/src/styles/css/antd-themes/pagination/_default.css +2 -1
- package/dist/templates/next-app/src/styles/css/antd-themes/pagination/dark.css +28 -29
- package/dist/templates/next-app/src/styles/css/antd-themes/pagination/pink.css +2 -1
- package/dist/templates/next-app/src/uikit/components/AdminLayout.tsx +17 -3
- package/dist/templates/next-app/src/uikit/components/BaseHeader.tsx +5 -4
- package/dist/templates/next-app/src/uikit/components/BaseLayout.tsx +5 -4
- package/dist/templates/next-app/src/uikit/components/BootstrapsProvider.tsx +3 -2
- package/dist/templates/next-app/src/uikit/components/ComboProvider.tsx +1 -1
- package/dist/templates/next-app/src/uikit/components/EditableCell.tsx +118 -0
- package/dist/templates/next-app/src/uikit/components/LogoutButton.tsx +5 -6
- package/dist/templates/next-app/src/uikit/components/ThemeSwitcher.tsx +1 -1
- package/dist/templates/next-app/src/uikit/components/With.tsx +2 -2
- package/dist/templates/next-app/src/uikit/components/localesImportButton/LocalesImportButton.tsx +62 -0
- package/dist/templates/next-app/src/uikit/components/localesImportButton/LocalesImportEvent.ts +28 -0
- package/dist/templates/next-app/src/uikit/components/localesImportButton/import.module.css +6 -0
- package/dist/templates/next-app/src/uikit/hook/useI18nInterface.ts +8 -14
- package/dist/templates/next-app/src/uikit/hook/useWarnTranslations.ts +25 -0
- package/dist/templates/react-app/.prettierignore +17 -0
- package/dist/templates/react-app/README.en.md +71 -54
- package/dist/templates/react-app/README.md +35 -18
- package/dist/templates/react-app/__tests__/__mocks__/BootstrapTest.ts +14 -0
- package/dist/templates/react-app/__tests__/__mocks__/MockAppConfit.ts +1 -1
- package/dist/templates/react-app/__tests__/__mocks__/MockDialogHandler.ts +2 -2
- package/dist/templates/react-app/__tests__/__mocks__/MockLogger.ts +1 -1
- package/dist/templates/react-app/__tests__/__mocks__/components/TestApp.tsx +45 -0
- package/dist/templates/react-app/__tests__/__mocks__/components/TestBootstrapsProvider.tsx +34 -0
- package/dist/templates/react-app/__tests__/__mocks__/components/TestRouter.tsx +46 -0
- package/dist/templates/react-app/__tests__/__mocks__/components/index.ts +12 -0
- package/dist/templates/react-app/__tests__/__mocks__/createMockGlobals.ts +1 -2
- package/dist/templates/react-app/__tests__/__mocks__/testIOC/TestIOC.ts +51 -0
- package/dist/templates/react-app/__tests__/__mocks__/testIOC/TestIOCRegister.ts +69 -0
- package/dist/templates/react-app/__tests__/setup/index.ts +1 -51
- package/dist/templates/react-app/__tests__/setup/setupGlobal.ts +51 -0
- package/dist/templates/react-app/__tests__/src/App.structure.test.tsx +115 -0
- package/dist/templates/react-app/__tests__/src/base/cases/AppConfig.test.ts +2 -2
- package/dist/templates/react-app/__tests__/src/base/cases/AppError.test.ts +1 -1
- package/dist/templates/react-app/__tests__/src/base/cases/DialogHandler.test.ts +3 -5
- package/dist/templates/react-app/__tests__/src/base/cases/I18nKeyErrorPlugin.test.ts +13 -2
- package/dist/templates/react-app/__tests__/src/base/cases/InversifyContainer.test.ts +1 -1
- package/dist/templates/react-app/__tests__/src/base/cases/PublicAssetsPath.test.ts +1 -1
- package/dist/templates/react-app/__tests__/src/base/cases/RequestLogger.test.ts +5 -5
- package/dist/templates/react-app/__tests__/src/base/cases/RequestStatusCatcher.test.ts +1 -2
- package/dist/templates/react-app/__tests__/src/base/cases/RouterLoader.test.ts +25 -15
- package/dist/templates/react-app/__tests__/src/base/services/I18nService.test.ts +29 -15
- package/dist/templates/react-app/__tests__/src/core/IOC.test.ts +19 -9
- package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapClient.test.ts +153 -0
- package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapsApp.test.ts +9 -7
- package/dist/templates/react-app/__tests__/src/main.integration.test.tsx +4 -5
- package/dist/templates/react-app/__tests__/src/main.test.tsx +4 -4
- package/dist/templates/react-app/__tests__/src/uikit/components/BaseHeader.test.tsx +68 -59
- package/dist/templates/react-app/__tests__/src/uikit/components/chatMessage/ChatRoot.test.tsx +274 -0
- package/dist/templates/react-app/config/IOCIdentifier.ts +11 -8
- package/dist/templates/react-app/config/Identifier/{common.error.ts → common/common.error.ts} +5 -5
- package/dist/templates/react-app/config/Identifier/{common.ts → common/common.ts} +9 -9
- package/dist/templates/react-app/config/Identifier/common/index.ts +2 -0
- package/dist/templates/react-app/config/Identifier/components/component.chatMessage.ts +56 -0
- package/dist/templates/react-app/config/Identifier/components/component.messageBaseList.ts +103 -0
- package/dist/templates/react-app/config/Identifier/index.ts +1 -9
- package/dist/templates/react-app/config/Identifier/pages/index.ts +9 -0
- package/dist/templates/react-app/config/Identifier/{page.about.ts → pages/page.about.ts} +34 -26
- package/dist/templates/react-app/config/Identifier/{page.executor.ts → pages/page.executor.ts} +47 -39
- package/dist/templates/{next-app/config/Identifier → react-app/config/Identifier/pages}/page.home.ts +24 -23
- package/dist/templates/react-app/config/Identifier/pages/page.identifiter.ts +102 -0
- package/dist/templates/react-app/config/Identifier/{page.jsonStorage.ts → pages/page.jsonStorage.ts} +18 -11
- package/dist/templates/react-app/config/Identifier/{page.login.ts → pages/page.login.ts} +37 -27
- package/dist/templates/react-app/config/Identifier/pages/page.message.ts +20 -0
- package/dist/templates/react-app/config/Identifier/{page.register.ts → pages/page.register.ts} +37 -25
- package/dist/templates/react-app/config/Identifier/{page.request.ts → pages/page.request.ts} +34 -44
- package/dist/templates/react-app/config/app.router.ts +81 -61
- package/dist/templates/react-app/config/i18n/PageI18nInterface.ts +51 -0
- package/dist/templates/react-app/config/i18n/aboutI18n.ts +42 -0
- package/dist/templates/react-app/config/i18n/chatMessageI18n.ts +17 -0
- package/dist/templates/react-app/config/i18n/executorI18n.ts +51 -0
- package/dist/templates/react-app/config/i18n/homeI18n.ts +24 -0
- package/dist/templates/react-app/config/i18n/i18nConfig.ts +30 -0
- package/dist/templates/react-app/config/i18n/identifiter18n.ts +30 -0
- package/dist/templates/react-app/config/i18n/jsonStorage18n.ts +27 -0
- package/dist/templates/react-app/config/i18n/login18n.ts +42 -0
- package/dist/templates/react-app/config/i18n/messageBaseListI18n.ts +22 -0
- package/dist/templates/react-app/config/i18n/messageI18n.ts +14 -0
- package/dist/templates/react-app/config/i18n/notFoundI18n.ts +34 -0
- package/dist/templates/react-app/config/i18n/register18n.ts +40 -0
- package/dist/templates/react-app/config/i18n/request18n.ts +41 -0
- package/dist/templates/react-app/config/theme.ts +14 -4
- package/dist/templates/react-app/docs/en/bootstrap.md +1670 -341
- package/dist/templates/react-app/docs/en/components/chat-message-component.md +314 -0
- package/dist/templates/react-app/docs/en/components/chat-message-refactor.md +270 -0
- package/dist/templates/react-app/docs/en/components/message-base-list-component.md +172 -0
- package/dist/templates/react-app/docs/en/development-guide.md +1021 -345
- package/dist/templates/react-app/docs/en/env.md +1132 -278
- package/dist/templates/react-app/docs/en/i18n.md +858 -147
- package/dist/templates/react-app/docs/en/index.md +733 -104
- package/dist/templates/react-app/docs/en/ioc.md +1228 -287
- package/dist/templates/react-app/docs/en/playwright/e2e-tests.md +321 -0
- package/dist/templates/react-app/docs/en/playwright/index.md +19 -0
- package/dist/templates/react-app/docs/en/playwright/installation-summary.md +332 -0
- package/dist/templates/react-app/docs/en/playwright/overview.md +222 -0
- package/dist/templates/react-app/docs/en/playwright/quickstart.md +325 -0
- package/dist/templates/react-app/docs/en/playwright/reorganization-notes.md +340 -0
- package/dist/templates/react-app/docs/en/playwright/setup-complete.md +290 -0
- package/dist/templates/react-app/docs/en/playwright/testing-guide.md +565 -0
- package/dist/templates/react-app/docs/en/store.md +1194 -184
- package/dist/templates/react-app/docs/en/why-no-globals.md +797 -0
- package/dist/templates/react-app/docs/zh/bootstrap.md +1670 -341
- package/dist/templates/react-app/docs/zh/components/chat-message-component.md +314 -0
- package/dist/templates/react-app/docs/zh/components/chat-message-refactor.md +270 -0
- package/dist/templates/react-app/docs/zh/components/message-base-list-component.md +172 -0
- package/dist/templates/react-app/docs/zh/development-guide.md +1021 -345
- package/dist/templates/react-app/docs/zh/env.md +1132 -275
- package/dist/templates/react-app/docs/zh/i18n.md +858 -147
- package/dist/templates/react-app/docs/zh/index.md +717 -104
- package/dist/templates/react-app/docs/zh/ioc.md +1229 -287
- package/dist/templates/react-app/docs/zh/playwright/e2e-tests.md +321 -0
- package/dist/templates/react-app/docs/zh/playwright/index.md +19 -0
- package/dist/templates/react-app/docs/zh/playwright/installation-summary.md +332 -0
- package/dist/templates/react-app/docs/zh/playwright/overview.md +222 -0
- package/dist/templates/react-app/docs/zh/playwright/quickstart.md +325 -0
- package/dist/templates/react-app/docs/zh/playwright/reorganization-notes.md +340 -0
- package/dist/templates/react-app/docs/zh/playwright/setup-complete.md +290 -0
- package/dist/templates/react-app/docs/zh/playwright/testing-guide.md +565 -0
- package/dist/templates/react-app/docs/zh/store.md +1192 -184
- package/dist/templates/react-app/docs/zh/why-no-globals.md +797 -0
- package/dist/templates/react-app/e2e/App.spec.ts +319 -0
- package/dist/templates/react-app/e2e/fixtures/base.fixture.ts +40 -0
- package/dist/templates/react-app/e2e/main.spec.ts +20 -0
- package/dist/templates/react-app/e2e/utils/test-helpers.ts +19 -0
- package/dist/templates/react-app/eslint.config.mjs +247 -0
- package/dist/templates/react-app/makes/eslint-utils.mjs +195 -0
- package/dist/templates/react-app/makes/generateTs2LocalesOptions.ts +26 -0
- package/dist/templates/react-app/package.json +31 -3
- package/dist/templates/react-app/playwright.config.ts +79 -0
- package/dist/templates/react-app/public/locales/en/common.json +233 -179
- package/dist/templates/react-app/public/locales/zh/common.json +233 -179
- package/dist/templates/react-app/src/App.tsx +15 -42
- package/dist/templates/react-app/src/base/apis/AiApi.ts +5 -5
- package/dist/templates/react-app/src/base/apis/feApi/FeApi.ts +1 -1
- package/dist/templates/react-app/src/base/apis/feApi/FeApiAdapter.ts +1 -1
- package/dist/templates/react-app/src/base/apis/feApi/FeApiBootstarp.ts +8 -8
- package/dist/templates/react-app/src/base/apis/feApi/FeApiType.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +6 -6
- package/dist/templates/react-app/src/base/apis/userApi/UserApiAdapter.ts +1 -1
- package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +12 -14
- package/dist/templates/react-app/src/base/apis/userApi/UserApiType.ts +1 -1
- package/dist/templates/react-app/src/base/cases/DialogHandler.ts +5 -2
- package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +3 -3
- package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +3 -3
- package/dist/templates/react-app/src/base/cases/RequestLanguages.ts +2 -2
- package/dist/templates/react-app/src/base/cases/RequestLogger.ts +4 -4
- package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +1 -1
- package/dist/templates/react-app/src/base/cases/ResourceState.ts +23 -0
- package/dist/templates/react-app/src/base/cases/RouterLoader.ts +4 -4
- package/dist/templates/react-app/src/base/cases/TranslateI18nInterface.ts +26 -0
- package/dist/templates/react-app/src/base/port/ExecutorPageBridgeInterface.ts +2 -3
- package/dist/templates/react-app/src/base/port/I18nServiceInterface.ts +1 -1
- package/dist/templates/react-app/src/base/port/IOCInterface.ts +36 -0
- package/dist/templates/react-app/src/base/port/JSONStoragePageBridgeInterface.ts +2 -1
- package/dist/templates/react-app/src/base/port/ProcesserExecutorInterface.ts +1 -1
- package/dist/templates/react-app/src/base/port/RequestPageBridgeInterface.ts +2 -2
- package/dist/templates/react-app/src/base/port/RouteServiceInterface.ts +9 -5
- package/dist/templates/react-app/src/base/port/UserServiceInterface.ts +1 -1
- package/dist/templates/react-app/src/base/services/I18nService.ts +29 -29
- package/dist/templates/react-app/src/base/services/IdentifierService.ts +143 -0
- package/dist/templates/react-app/src/base/services/ProcesserExecutor.ts +3 -3
- package/dist/templates/react-app/src/base/services/RouteService.ts +27 -8
- package/dist/templates/react-app/src/base/services/UserService.ts +8 -8
- package/dist/templates/react-app/src/base/types/Page.ts +14 -2
- package/dist/templates/react-app/src/base/types/global.d.ts +1 -1
- package/dist/templates/react-app/src/core/IOC.ts +5 -46
- package/dist/templates/react-app/src/core/bootstraps/{BootstrapApp.ts → BootstrapClient.ts} +44 -17
- package/dist/templates/react-app/src/core/bootstraps/BootstrapsRegistry.ts +14 -7
- package/dist/templates/react-app/src/core/bootstraps/IocIdentifierTest.ts +1 -1
- package/dist/templates/react-app/src/core/bootstraps/PrintBootstrap.ts +1 -1
- package/dist/templates/react-app/src/core/clientIoc/ClientIOC.ts +40 -0
- package/dist/templates/react-app/src/core/{IocRegisterImpl.ts → clientIoc/ClientIOCRegister.ts} +35 -24
- package/dist/templates/react-app/src/core/globals.ts +9 -9
- package/dist/templates/react-app/src/main.tsx +4 -4
- package/dist/templates/react-app/src/pages/404.tsx +6 -3
- package/dist/templates/react-app/src/pages/500.tsx +5 -2
- package/dist/templates/react-app/src/pages/NoRouteFound.tsx +5 -0
- package/dist/templates/react-app/src/pages/auth/Layout.tsx +9 -6
- package/dist/templates/react-app/src/pages/auth/LoginPage.tsx +46 -56
- package/dist/templates/react-app/src/pages/auth/RegisterPage.tsx +46 -58
- package/dist/templates/react-app/src/pages/base/AboutPage.tsx +35 -40
- package/dist/templates/react-app/src/pages/base/ExecutorPage.tsx +51 -51
- package/dist/templates/react-app/src/pages/base/HomePage.tsx +14 -15
- package/dist/templates/react-app/src/pages/base/IdentifierPage.tsx +70 -11
- package/dist/templates/react-app/src/pages/base/JSONStoragePage.tsx +24 -25
- package/dist/templates/react-app/src/pages/base/Layout.tsx +2 -2
- package/dist/templates/react-app/src/pages/base/MessagePage.tsx +40 -0
- package/dist/templates/react-app/src/pages/base/RedirectPathname.tsx +3 -2
- package/dist/templates/react-app/src/pages/base/RequestPage.tsx +41 -59
- package/dist/templates/react-app/src/styles/css/antd-themes/{_default.css → _common/_default.css} +85 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/{dark.css → _common/dark.css} +99 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/_common/index.css +3 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/{pink.css → _common/pink.css} +86 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/index.css +4 -3
- package/dist/templates/react-app/src/styles/css/antd-themes/menu/_default.css +108 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/menu/dark.css +67 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/menu/index.css +3 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/menu/pink.css +67 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/pagination/_default.css +34 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/pagination/dark.css +31 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/pagination/index.css +3 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/pagination/pink.css +36 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/table/_default.css +44 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/table/dark.css +43 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/table/index.css +3 -0
- package/dist/templates/react-app/src/styles/css/antd-themes/table/pink.css +43 -0
- package/dist/templates/react-app/src/styles/css/page.css +4 -3
- package/dist/templates/react-app/src/styles/css/themes/_default.css +1 -0
- package/dist/templates/react-app/src/styles/css/themes/dark.css +1 -0
- package/dist/templates/react-app/src/styles/css/themes/pink.css +1 -0
- package/dist/templates/react-app/src/styles/css/zIndex.css +1 -1
- package/dist/templates/react-app/src/uikit/bridges/ExecutorPageBridge.ts +3 -3
- package/dist/templates/react-app/src/uikit/bridges/JSONStoragePageBridge.ts +2 -2
- package/dist/templates/react-app/src/uikit/bridges/NavigateBridge.ts +1 -1
- package/dist/templates/react-app/src/uikit/bridges/RequestPageBridge.ts +3 -3
- package/dist/templates/react-app/src/uikit/components/AppRouterProvider.tsx +35 -0
- package/dist/templates/react-app/src/uikit/components/BaseHeader.tsx +15 -11
- package/dist/templates/react-app/src/uikit/components/BaseRouteProvider.tsx +14 -11
- package/dist/templates/react-app/src/uikit/components/BaseRouteSeo.tsx +18 -0
- package/dist/templates/react-app/src/uikit/components/BootstrapsProvider.tsx +13 -0
- package/dist/templates/react-app/src/uikit/components/ClientSeo.tsx +62 -0
- package/dist/templates/react-app/src/uikit/components/ComboProvider.tsx +38 -0
- package/dist/templates/react-app/src/uikit/components/LanguageSwitcher.tsx +48 -27
- package/dist/templates/react-app/src/uikit/components/Loading.tsx +4 -2
- package/dist/templates/react-app/src/uikit/components/LocaleLink.tsx +4 -5
- package/dist/templates/react-app/src/uikit/components/LogoutButton.tsx +34 -11
- package/dist/templates/react-app/src/uikit/components/MessageBaseList.tsx +240 -0
- package/dist/templates/react-app/src/uikit/components/ProcessExecutorProvider.tsx +9 -5
- package/dist/templates/react-app/src/uikit/components/RouterRenderComponent.tsx +6 -3
- package/dist/templates/react-app/src/uikit/components/ThemeSwitcher.tsx +97 -40
- package/dist/templates/react-app/src/uikit/components/UserAuthProvider.tsx +5 -5
- package/dist/templates/react-app/src/uikit/components/With.tsx +17 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/ChatMessageBridge.ts +176 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/ChatRoot.tsx +21 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/FocusBar.tsx +106 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/MessageApi.ts +271 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/MessageItem.tsx +102 -0
- package/dist/templates/react-app/src/uikit/components/chatMessage/MessagesList.tsx +86 -0
- package/dist/templates/react-app/src/uikit/contexts/BaseRouteContext.ts +17 -11
- package/dist/templates/react-app/src/uikit/contexts/IOCContext.ts +13 -0
- package/dist/templates/react-app/src/uikit/hooks/useAppTranslation.ts +26 -0
- package/dist/templates/react-app/src/uikit/hooks/useI18nGuard.ts +8 -11
- package/dist/templates/react-app/src/uikit/hooks/useI18nInterface.ts +25 -0
- package/dist/templates/react-app/src/uikit/hooks/useIOC.ts +35 -0
- package/dist/templates/react-app/src/uikit/hooks/useNavigateBridge.ts +3 -3
- package/dist/templates/react-app/src/uikit/hooks/useStrictEffect.ts +0 -1
- package/dist/templates/react-app/tsconfig.e2e.json +21 -0
- package/dist/templates/react-app/tsconfig.json +8 -1
- package/dist/templates/react-app/tsconfig.node.json +1 -1
- package/dist/templates/react-app/tsconfig.test.json +3 -1
- package/dist/templates/react-app/vite.config.ts +50 -34
- package/package.json +2 -1
- package/dist/configs/react-app/eslint.config.js +0 -94
- package/dist/templates/next-app/config/Identifier/common.error.ts +0 -41
- package/dist/templates/next-app/config/Identifier/common.ts +0 -69
- package/dist/templates/next-app/config/Identifier/page.about.ts +0 -181
- package/dist/templates/next-app/config/Identifier/page.admin.ts +0 -48
- package/dist/templates/next-app/config/Identifier/page.executor.ts +0 -272
- package/dist/templates/next-app/config/Identifier/page.identifiter.ts +0 -39
- package/dist/templates/next-app/config/Identifier/page.jsonStorage.ts +0 -72
- package/dist/templates/next-app/config/Identifier/page.request.ts +0 -182
- package/dist/templates/next-app/src/base/cases/ChatAction.ts +0 -21
- package/dist/templates/next-app/src/base/cases/FocusBarAction.ts +0 -36
- package/dist/templates/next-app/src/base/cases/RequestState.ts +0 -20
- package/dist/templates/next-app/src/base/port/AdminPageInterface.ts +0 -85
- package/dist/templates/next-app/src/base/port/AsyncStateInterface.ts +0 -7
- package/dist/templates/next-app/src/base/services/AdminUserService.ts +0 -45
- package/dist/templates/next-app/src/uikit/components/ChatRoot.tsx +0 -17
- package/dist/templates/next-app/src/uikit/components/chat/ChatActionInterface.ts +0 -30
- package/dist/templates/next-app/src/uikit/components/chat/ChatFocusBar.tsx +0 -65
- package/dist/templates/next-app/src/uikit/components/chat/ChatMessages.tsx +0 -59
- package/dist/templates/next-app/src/uikit/components/chat/ChatWrap.tsx +0 -28
- package/dist/templates/next-app/src/uikit/components/chat/FocusBarActionInterface.ts +0 -19
- package/dist/templates/next-app/src/uikit/hook/useMountedClient.ts +0 -17
- package/dist/templates/next-app/src/uikit/hook/useStore.ts +0 -15
- package/dist/templates/react-app/__tests__/__mocks__/I18nService.ts +0 -13
- package/dist/templates/react-app/__tests__/src/App.test.tsx +0 -139
- package/dist/templates/react-app/config/Identifier/page.identifiter.ts +0 -39
- package/dist/templates/react-app/config/i18n.ts +0 -15
- package/dist/templates/react-app/docs/en/project-structure.md +0 -434
- package/dist/templates/react-app/docs/zh/project-structure.md +0 -434
- package/dist/templates/react-app/src/base/cases/RequestState.ts +0 -20
- package/dist/templates/react-app/src/base/port/AsyncStateInterface.ts +0 -7
- package/dist/templates/react-app/src/uikit/hooks/useDocumentTitle.ts +0 -15
- package/dist/templates/react-app/src/uikit/hooks/useStore.ts +0 -15
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# ChatMessage Chat Component System
|
|
2
|
+
|
|
3
|
+
## 📋 Overview
|
|
4
|
+
|
|
5
|
+
ChatMessage is a complete chat component system that supports real-time conversations, streaming output, error handling, and more. Suitable for AI dialogue, customer service chat, and other scenarios.
|
|
6
|
+
|
|
7
|
+
## ✨ Core Features
|
|
8
|
+
|
|
9
|
+
- ✅ **Streaming Output**: Supports character-by-character AI reply display (like ChatGPT)
|
|
10
|
+
- ✅ **Stop Control**: Can stop message generation at any time
|
|
11
|
+
- ✅ **Retry Mechanism**: Failed messages can be retried with one click
|
|
12
|
+
- ✅ **Draft Management**: Automatically saves draft messages being input
|
|
13
|
+
- ✅ **Loading States**: Clear message sending and receiving states
|
|
14
|
+
- ✅ **Error Handling**: Comprehensive error prompts and handling
|
|
15
|
+
- ✅ **Shortcuts**: Ctrl+Enter for quick send
|
|
16
|
+
- ✅ **Internationalization**: Full Chinese/English support
|
|
17
|
+
- ✅ **Responsive Design**: Adapts to different screen sizes
|
|
18
|
+
|
|
19
|
+
## 📁 File Structure
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
src/uikit/components/chatMessage/
|
|
23
|
+
├── ChatRoot.tsx # Root component (assembles all parts)
|
|
24
|
+
├── MessagesList.tsx # Message list component
|
|
25
|
+
├── MessageItem.tsx # Single message item component
|
|
26
|
+
├── FocusBar.tsx # Input bar component
|
|
27
|
+
├── ChatMessageBridge.ts # Bridge layer (connects UI and logic)
|
|
28
|
+
└── MessageApi.ts # API layer (mock/real backend)
|
|
29
|
+
|
|
30
|
+
config/
|
|
31
|
+
├── Identifier/components/component.chatMessage.ts # i18n identifiers
|
|
32
|
+
├── i18n/chatMessageI18n.ts # Component i18n config
|
|
33
|
+
├── Identifier/pages/page.chat.ts # Page i18n identifiers
|
|
34
|
+
└── i18n/chatI18n.ts # Page i18n config
|
|
35
|
+
|
|
36
|
+
src/pages/base/
|
|
37
|
+
└── ChatMessagePage.tsx # Chat page
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 🎯 Core Concepts
|
|
41
|
+
|
|
42
|
+
### 1. ChatMessageBridge (Bridge Layer)
|
|
43
|
+
|
|
44
|
+
Bridge connecting UI and data layer, handles:
|
|
45
|
+
- Message sending logic
|
|
46
|
+
- Draft management
|
|
47
|
+
- State control
|
|
48
|
+
- Stop mechanism
|
|
49
|
+
|
|
50
|
+
### 2. MessageApi (Gateway Layer)
|
|
51
|
+
|
|
52
|
+
Simulates backend API, supports three modes:
|
|
53
|
+
|
|
54
|
+
#### Streaming Mode (stream: true)
|
|
55
|
+
```typescript
|
|
56
|
+
{
|
|
57
|
+
stream: true // Character-by-character output, stoppable
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### Interruptible Normal Mode
|
|
62
|
+
```typescript
|
|
63
|
+
{
|
|
64
|
+
stream: false // One-time return, stoppable
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Fast Normal Mode
|
|
69
|
+
```typescript
|
|
70
|
+
// No options passed, one-time return, non-stoppable
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 3. ChatMessageStore (State Management)
|
|
74
|
+
|
|
75
|
+
Manages all message states:
|
|
76
|
+
- `messages` - History message list
|
|
77
|
+
- `draftMessages` - Draft message list
|
|
78
|
+
- `streaming` - Whether streaming output is in progress
|
|
79
|
+
- `disabledSend` - Whether sending is disabled
|
|
80
|
+
|
|
81
|
+
## 🚀 Usage
|
|
82
|
+
|
|
83
|
+
### Basic Usage
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
import { ChatRoot } from '@/uikit/components/chatMessage/ChatRoot';
|
|
87
|
+
|
|
88
|
+
export default function ChatMessagePage() {
|
|
89
|
+
return (
|
|
90
|
+
<div className="h-screen">
|
|
91
|
+
<ChatRoot />
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Access Paths
|
|
98
|
+
|
|
99
|
+
- `/en/chat` - English
|
|
100
|
+
- `/zh/chat` - Chinese
|
|
101
|
+
|
|
102
|
+
## 🎨 Interface Design
|
|
103
|
+
|
|
104
|
+
### Message Styles
|
|
105
|
+
|
|
106
|
+
**User Messages**:
|
|
107
|
+
- Blue background
|
|
108
|
+
- Right-aligned
|
|
109
|
+
- Max width 80%
|
|
110
|
+
- Shows duration
|
|
111
|
+
- Has retry button
|
|
112
|
+
|
|
113
|
+
**AI Messages**:
|
|
114
|
+
- Light background + border
|
|
115
|
+
- Left-aligned
|
|
116
|
+
- Max width 85%
|
|
117
|
+
- Supports streaming display
|
|
118
|
+
- Shows loading state
|
|
119
|
+
|
|
120
|
+
### Input Bar
|
|
121
|
+
|
|
122
|
+
- Auto-adjusts height (2-6 rows)
|
|
123
|
+
- Ctrl+Enter to send
|
|
124
|
+
- Disabled state control
|
|
125
|
+
- Send/Stop button toggle
|
|
126
|
+
|
|
127
|
+
## 📝 Key APIs
|
|
128
|
+
|
|
129
|
+
### ChatMessageBridge Methods
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
interface ChatMessageBridgeInterface<T> {
|
|
133
|
+
// Send message
|
|
134
|
+
send(message?: ChatMessage<T>): Promise<ChatMessage<T>>;
|
|
135
|
+
|
|
136
|
+
// Stop sending
|
|
137
|
+
stop(messageId?: string): boolean;
|
|
138
|
+
|
|
139
|
+
// Stop all
|
|
140
|
+
stopAll(): void;
|
|
141
|
+
|
|
142
|
+
// Update content
|
|
143
|
+
onChangeContent(content: T): void;
|
|
144
|
+
|
|
145
|
+
// Get message store
|
|
146
|
+
getMessageStore(): ChatMessageStore<T>;
|
|
147
|
+
|
|
148
|
+
// Get first draft message
|
|
149
|
+
getFirstDraftMessage(): ChatMessage<T> | null;
|
|
150
|
+
|
|
151
|
+
// Get sending message
|
|
152
|
+
getSendingMessage(): ChatMessage<T> | null;
|
|
153
|
+
|
|
154
|
+
// Is send disabled
|
|
155
|
+
getDisabledSend(): boolean;
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### MessageApi Modes
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
class MessageApi {
|
|
163
|
+
async sendMessage<M>(
|
|
164
|
+
message: M,
|
|
165
|
+
options?: GatewayOptions<M>
|
|
166
|
+
): Promise<M>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface GatewayOptions<M> {
|
|
170
|
+
stream?: boolean; // Whether streaming
|
|
171
|
+
signal?: AbortSignal; // Stop signal
|
|
172
|
+
onConnected?: () => void; // Connection success
|
|
173
|
+
onChunk?: (msg: M) => void; // Streaming chunk callback
|
|
174
|
+
onProgress?: (p: number) => void; // Progress callback
|
|
175
|
+
onComplete?: (msg: M) => void; // Completion callback
|
|
176
|
+
onAborted?: (msg: M) => void; // Stop callback
|
|
177
|
+
onError?: (err: any) => void; // Error callback
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## 🔧 Custom Configuration
|
|
182
|
+
|
|
183
|
+
### 1. Switch Send Mode
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// Modify ChatRoot.tsx
|
|
187
|
+
const [bridge] = useState(() => {
|
|
188
|
+
return new ChatMessageBridge<string>(messagesStore, {
|
|
189
|
+
gateway: messageApi,
|
|
190
|
+
logger: logger,
|
|
191
|
+
senderName: 'ChatSender',
|
|
192
|
+
gatewayOptions: {
|
|
193
|
+
stream: true // Change to false for normal mode
|
|
194
|
+
}
|
|
195
|
+
}).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 2. Custom Message Component
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
<MessagesList
|
|
203
|
+
bridge={bridge}
|
|
204
|
+
getMessageComponent={(props) => CustomMessageItem}
|
|
205
|
+
/>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 3. Connect Real API
|
|
209
|
+
|
|
210
|
+
Modify `MessageApi.ts`:
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
async sendMessage<M>(message: M, options?: GatewayOptions<M>): Promise<M> {
|
|
214
|
+
// Replace with real API call
|
|
215
|
+
const response = await fetch('/api/chat', {
|
|
216
|
+
method: 'POST',
|
|
217
|
+
body: JSON.stringify(message),
|
|
218
|
+
signal: options?.signal
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// Handle streaming response
|
|
222
|
+
if (options?.stream) {
|
|
223
|
+
const reader = response.body?.getReader();
|
|
224
|
+
// ... process streaming data
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return response.json();
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## 💡 Usage Tips
|
|
232
|
+
|
|
233
|
+
### Test Features
|
|
234
|
+
|
|
235
|
+
**Normal Messages**:
|
|
236
|
+
```
|
|
237
|
+
Hello
|
|
238
|
+
你好
|
|
239
|
+
Test message
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**Trigger Errors**:
|
|
243
|
+
```
|
|
244
|
+
error
|
|
245
|
+
Failed
|
|
246
|
+
test error
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**See Streaming Effect**:
|
|
250
|
+
- Send any message
|
|
251
|
+
- Watch character-by-character output
|
|
252
|
+
- Click stop button to test interruption
|
|
253
|
+
|
|
254
|
+
### Shortcuts
|
|
255
|
+
|
|
256
|
+
- `Ctrl + Enter` - Send message
|
|
257
|
+
- Auto-save draft while typing
|
|
258
|
+
|
|
259
|
+
## 🎯 Use Cases
|
|
260
|
+
|
|
261
|
+
1. **AI Dialogue Apps**: ChatGPT-like dialogue interface
|
|
262
|
+
2. **Customer Service**: Real-time customer service chat
|
|
263
|
+
3. **Q&A Systems**: Q&A interaction
|
|
264
|
+
4. **Code Assistant**: Code generation and explanation
|
|
265
|
+
5. **Teaching Assistant**: Online learning tutoring
|
|
266
|
+
|
|
267
|
+
## 🔄 Message Flow
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
User Input → Draft Message
|
|
271
|
+
↓
|
|
272
|
+
Click Send/Ctrl+Enter
|
|
273
|
+
↓
|
|
274
|
+
Bridge.send()
|
|
275
|
+
↓
|
|
276
|
+
MessageSender → MessageApi
|
|
277
|
+
↓
|
|
278
|
+
[Streaming Mode]
|
|
279
|
+
onConnected → onChunk(word-by-word) → onComplete
|
|
280
|
+
|
|
281
|
+
[Normal Mode]
|
|
282
|
+
onConnected → onComplete
|
|
283
|
+
|
|
284
|
+
[Error]
|
|
285
|
+
onError
|
|
286
|
+
|
|
287
|
+
[Stop]
|
|
288
|
+
onAborted
|
|
289
|
+
↓
|
|
290
|
+
Update ChatMessageStore
|
|
291
|
+
↓
|
|
292
|
+
UI Auto-updates
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## 📊 State Management
|
|
296
|
+
|
|
297
|
+
### Message States
|
|
298
|
+
|
|
299
|
+
- `DRAFT` - Draft
|
|
300
|
+
- `SENDING` - Sending
|
|
301
|
+
- `SENT` - Sent
|
|
302
|
+
- `FAILED` - Failed
|
|
303
|
+
- `STOPPED` - Stopped
|
|
304
|
+
|
|
305
|
+
### Message Roles
|
|
306
|
+
|
|
307
|
+
- `USER` - User message
|
|
308
|
+
- `ASSISTANT` - AI/Assistant message
|
|
309
|
+
- `SYSTEM` - System message
|
|
310
|
+
|
|
311
|
+
## 🎉 Summary
|
|
312
|
+
|
|
313
|
+
ChatMessage is a fully-featured, elegantly designed chat component system, ready to use out of the box, supporting streaming output, error handling, state management, and other core features. Can be used directly in production or extended and customized as needed.
|
|
314
|
+
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# ChatMessage Refactoring Guide
|
|
2
|
+
|
|
3
|
+
## Refactoring Overview
|
|
4
|
+
|
|
5
|
+
Refactored ChatMessage from a standalone page to a reusable component, integrated into MessagePage. Passed the internationalization object `tt` through props to ensure high component reusability.
|
|
6
|
+
|
|
7
|
+
## Changes
|
|
8
|
+
|
|
9
|
+
### 1. ChatRoot Component Refactoring
|
|
10
|
+
|
|
11
|
+
**File:** `src/uikit/components/chatMessage/ChatRoot.tsx`
|
|
12
|
+
|
|
13
|
+
**Changes:**
|
|
14
|
+
- Removed internal creation of `ChatMessageStore`, `MessageApi`, and `ChatMessageBridge`
|
|
15
|
+
- Changed to accept `bridge` and `tt` (internationalization object) as props
|
|
16
|
+
- Added `ChatRootProps` interface definition
|
|
17
|
+
- Removed internal `useI18nInterface` call
|
|
18
|
+
|
|
19
|
+
**Before:**
|
|
20
|
+
```typescript
|
|
21
|
+
export function ChatRoot() {
|
|
22
|
+
const messagesStore = useFactory(ChatMessageStore<string>);
|
|
23
|
+
const messageApi = useFactory(MessageApi, messagesStore);
|
|
24
|
+
const [bridge] = useState(() => {
|
|
25
|
+
return new ChatMessageBridge<string>(messagesStore, {
|
|
26
|
+
gateway: messageApi,
|
|
27
|
+
logger: logger,
|
|
28
|
+
senderName: 'ChatSender',
|
|
29
|
+
gatewayOptions: { stream: true }
|
|
30
|
+
}).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div data-testid="ChatRoot">
|
|
35
|
+
<MessagesList bridge={bridge} />
|
|
36
|
+
<FocusBar bridge={bridge} />
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**After:**
|
|
43
|
+
```typescript
|
|
44
|
+
export interface ChatRootProps {
|
|
45
|
+
bridge: ChatMessageBridge<string>;
|
|
46
|
+
tt: ChatMessageI18nInterface;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function ChatRoot({ bridge, tt }: ChatRootProps) {
|
|
50
|
+
return (
|
|
51
|
+
<div data-testid="ChatRoot">
|
|
52
|
+
<MessagesList bridge={bridge} tt={tt} />
|
|
53
|
+
<FocusBar bridge={bridge} tt={tt} />
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 2. Integrating ChatRoot into MessagePage
|
|
60
|
+
|
|
61
|
+
**File:** `src/pages/base/MessagePage.tsx`
|
|
62
|
+
|
|
63
|
+
**Changes:**
|
|
64
|
+
- Use `useI18nInterface` to get the internationalization object `tt` in MessagePage
|
|
65
|
+
- Create `ChatMessageStore`, `MessageApi`, and `ChatMessageBridge` in MessagePage
|
|
66
|
+
- Pass both `bridge` and `tt` to `ChatRoot` component via props
|
|
67
|
+
- Also integrated the `MessageBaseList` component
|
|
68
|
+
|
|
69
|
+
**Implementation:**
|
|
70
|
+
```typescript
|
|
71
|
+
import { useFactory } from '@brain-toolkit/react-kit';
|
|
72
|
+
import { chatMessageI18n } from '@config/i18n/chatMessageI18n';
|
|
73
|
+
import {
|
|
74
|
+
ChatMessageStore,
|
|
75
|
+
ChatSenderStrategy,
|
|
76
|
+
SendFailureStrategy
|
|
77
|
+
} from '@qlover/corekit-bridge';
|
|
78
|
+
import { useState } from 'react';
|
|
79
|
+
import { logger } from '@/core/globals';
|
|
80
|
+
import { ChatMessageBridge } from '@/uikit/components/chatMessage/ChatMessageBridge';
|
|
81
|
+
import { ChatRoot } from '@/uikit/components/chatMessage/ChatRoot';
|
|
82
|
+
import { MessageApi } from '@/uikit/components/chatMessage/MessageApi';
|
|
83
|
+
import { MessageBaseList } from '@/uikit/components/MessageBaseList';
|
|
84
|
+
import { useI18nInterface } from '@/uikit/hooks/useI18nInterface';
|
|
85
|
+
|
|
86
|
+
export default function MessagePage() {
|
|
87
|
+
const tt = useI18nInterface(chatMessageI18n);
|
|
88
|
+
const messagesStore = useFactory(ChatMessageStore<string>);
|
|
89
|
+
const messageApi = useFactory(MessageApi, messagesStore);
|
|
90
|
+
|
|
91
|
+
const [bridge] = useState(() => {
|
|
92
|
+
return new ChatMessageBridge<string>(messagesStore, {
|
|
93
|
+
gateway: messageApi,
|
|
94
|
+
logger: logger,
|
|
95
|
+
senderName: 'ChatSender',
|
|
96
|
+
gatewayOptions: { stream: true }
|
|
97
|
+
}).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div
|
|
102
|
+
data-testid="MessagePage"
|
|
103
|
+
className="min-h-screen bg-primary py-8 px-4 sm:px-6 lg:px-8"
|
|
104
|
+
>
|
|
105
|
+
<MessageBaseList />
|
|
106
|
+
<ChatRoot bridge={bridge} tt={tt} />
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### 3. Child Component Refactoring (MessagesList, FocusBar, MessageItem)
|
|
113
|
+
|
|
114
|
+
**Changes:**
|
|
115
|
+
- Removed internal `useI18nInterface` calls from all child components
|
|
116
|
+
- Changed to accept `tt` parameter via props
|
|
117
|
+
- Updated Props interface definitions for each component
|
|
118
|
+
|
|
119
|
+
**Example - MessagesList:**
|
|
120
|
+
```typescript
|
|
121
|
+
// Before
|
|
122
|
+
export function MessagesList({ bridge, ... }: MessagesListProps) {
|
|
123
|
+
const tt = useI18nInterface(chatMessageI18n);
|
|
124
|
+
// ...
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// After
|
|
128
|
+
export interface MessagesListProps {
|
|
129
|
+
bridge: ChatMessageBridgeInterface<T>;
|
|
130
|
+
tt: ChatMessageI18nInterface;
|
|
131
|
+
// ...
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export function MessagesList({ bridge, tt, ... }: MessagesListProps) {
|
|
135
|
+
// Use the passed tt directly
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 4. Removed Standalone ChatMessagePage
|
|
140
|
+
|
|
141
|
+
**Deleted Files:**
|
|
142
|
+
- `src/pages/base/ChatMessagePage.tsx`
|
|
143
|
+
- `config/Identifier/pages/page.chat.ts`
|
|
144
|
+
- `config/i18n/chatI18n.ts`
|
|
145
|
+
|
|
146
|
+
**Updated Files:**
|
|
147
|
+
- `config/app.router.ts` - Removed `/chat` route configuration
|
|
148
|
+
- `config/Identifier/pages/index.ts` - Removed `page.chat` export
|
|
149
|
+
|
|
150
|
+
## Advantages of Refactoring
|
|
151
|
+
|
|
152
|
+
### 1. Improved Component Reusability
|
|
153
|
+
- `ChatRoot` is now a pure presentational component that can be used anywhere
|
|
154
|
+
- Creation and configuration of `bridge` and `tt` are controlled by parent component for better flexibility
|
|
155
|
+
- Parent component can customize internationalization content, supporting different language environments
|
|
156
|
+
|
|
157
|
+
### 2. Simplified Routing Structure
|
|
158
|
+
- Reduced unnecessary routing layers
|
|
159
|
+
- Directly integrated chat functionality into message page, aligning with business logic
|
|
160
|
+
|
|
161
|
+
### 3. Better Separation of Concerns
|
|
162
|
+
- `ChatRoot` and its child components focus only on UI presentation
|
|
163
|
+
- Business logic (store, api, bridge) is managed at the page level
|
|
164
|
+
- Internationalization configuration is centrally managed at the page level
|
|
165
|
+
- Easier to test and maintain
|
|
166
|
+
|
|
167
|
+
### 4. Reduced Boilerplate
|
|
168
|
+
- No need to create a separate page for chat functionality
|
|
169
|
+
- No need to create separate i18n configuration for the page
|
|
170
|
+
- Child components don't need to repeatedly call `useI18nInterface`
|
|
171
|
+
|
|
172
|
+
### 5. Performance Improvement
|
|
173
|
+
- Reduced number of hook calls (multiple child components share the same `tt` object)
|
|
174
|
+
- Avoided redundant internationalization configuration parsing
|
|
175
|
+
|
|
176
|
+
## Usage Example
|
|
177
|
+
|
|
178
|
+
### Basic Usage
|
|
179
|
+
|
|
180
|
+
If you need to use `ChatRoot` elsewhere:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { useFactory } from '@brain-toolkit/react-kit';
|
|
184
|
+
import { chatMessageI18n } from '@config/i18n/chatMessageI18n';
|
|
185
|
+
import {
|
|
186
|
+
ChatMessageStore,
|
|
187
|
+
ChatSenderStrategy,
|
|
188
|
+
SendFailureStrategy
|
|
189
|
+
} from '@qlover/corekit-bridge';
|
|
190
|
+
import { useState } from 'react';
|
|
191
|
+
import { logger } from '@/core/globals';
|
|
192
|
+
import { useI18nInterface } from '@/uikit/hooks/useI18nInterface';
|
|
193
|
+
import { ChatMessageBridge } from '@/uikit/components/chatMessage/ChatMessageBridge';
|
|
194
|
+
import { ChatRoot } from '@/uikit/components/chatMessage/ChatRoot';
|
|
195
|
+
import { MessageApi } from '@/uikit/components/chatMessage/MessageApi';
|
|
196
|
+
|
|
197
|
+
function MyCustomChatPage() {
|
|
198
|
+
// Get internationalization object
|
|
199
|
+
const tt = useI18nInterface(chatMessageI18n);
|
|
200
|
+
|
|
201
|
+
const messagesStore = useFactory(ChatMessageStore<string>);
|
|
202
|
+
const messageApi = useFactory(MessageApi, messagesStore);
|
|
203
|
+
|
|
204
|
+
const [bridge] = useState(() => {
|
|
205
|
+
return new ChatMessageBridge<string>(messagesStore, {
|
|
206
|
+
gateway: messageApi,
|
|
207
|
+
logger: logger,
|
|
208
|
+
senderName: 'MyCustomSender',
|
|
209
|
+
gatewayOptions: {
|
|
210
|
+
stream: true,
|
|
211
|
+
// Can customize other options
|
|
212
|
+
}
|
|
213
|
+
}).use(new ChatSenderStrategy(SendFailureStrategy.KEEP_FAILED, logger));
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
return (
|
|
217
|
+
<div>
|
|
218
|
+
<h1>My Custom Chat</h1>
|
|
219
|
+
<ChatRoot bridge={bridge} tt={tt} />
|
|
220
|
+
</div>
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Custom Internationalization
|
|
226
|
+
|
|
227
|
+
If you need to use custom internationalization configuration:
|
|
228
|
+
|
|
229
|
+
```typescript
|
|
230
|
+
import { useState } from 'react';
|
|
231
|
+
import type { ChatMessageI18nInterface } from '@config/i18n/chatMessageI18n';
|
|
232
|
+
|
|
233
|
+
// Custom internationalization object
|
|
234
|
+
const customI18n: ChatMessageI18nInterface = {
|
|
235
|
+
title: 'custom.chat.title',
|
|
236
|
+
empty: 'custom.chat.empty',
|
|
237
|
+
start: 'custom.chat.start',
|
|
238
|
+
// ... other configurations
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
function MyCustomChatPage() {
|
|
242
|
+
const tt = useI18nInterface(customI18n);
|
|
243
|
+
// ... other logic
|
|
244
|
+
|
|
245
|
+
return <ChatRoot bridge={bridge} tt={tt} />;
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Notes
|
|
250
|
+
|
|
251
|
+
1. `ChatRoot` component requires two required parameters via props:
|
|
252
|
+
- `bridge`: `ChatMessageBridge` instance
|
|
253
|
+
- `tt`: `ChatMessageI18nInterface` internationalization object
|
|
254
|
+
|
|
255
|
+
2. Creation and configuration of `bridge` should be done in the parent component
|
|
256
|
+
|
|
257
|
+
3. Ensure `bridge` is created using `useState` to avoid re-initialization
|
|
258
|
+
|
|
259
|
+
4. Internationalization object `tt` should be obtained using `useI18nInterface` in the parent component, then passed to `ChatRoot`
|
|
260
|
+
|
|
261
|
+
5. All child components (`MessagesList`, `FocusBar`, `MessageItem`) used by `ChatRoot` receive both `bridge` and `tt` via props
|
|
262
|
+
|
|
263
|
+
6. All child components no longer call `useI18nInterface` themselves, but use the `tt` passed from the parent component
|
|
264
|
+
|
|
265
|
+
## Related Documentation
|
|
266
|
+
|
|
267
|
+
- [ChatMessage Component Documentation](./chat-message-component.md)
|
|
268
|
+
- [MessagePage Simplification Guide](./message-page-简化说明.md)
|
|
269
|
+
- [Development Guide](./development-guide.md)
|
|
270
|
+
|