@qlover/create-app 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/package.json +2 -2
  3. package/templates/react-app/README.md +311 -120
  4. package/templates/react-app/config/Identifier.I18n.ts +170 -0
  5. package/templates/react-app/config/common.ts +13 -0
  6. package/templates/react-app/package.json +6 -2
  7. package/templates/react-app/public/locales/en/common.json +25 -1
  8. package/templates/react-app/public/locales/zh/common.json +25 -1
  9. package/templates/react-app/src/App.tsx +5 -4
  10. package/templates/react-app/src/base/apis/AiApi.ts +4 -4
  11. package/templates/react-app/src/base/apis/feApi/FeApiAdapter.ts +2 -2
  12. package/templates/react-app/src/base/apis/userApi/UserApiAdapter.ts +2 -2
  13. package/templates/react-app/src/base/cases/AppConfig.ts +103 -0
  14. package/templates/react-app/src/base/cases/{appError/AppError.ts → AppError.ts} +0 -3
  15. package/templates/react-app/src/base/cases/DialogHandler.ts +86 -0
  16. package/templates/react-app/src/base/cases/RouterLoader.ts +166 -0
  17. package/templates/react-app/src/base/port/InteractionHubInterface.ts +94 -0
  18. package/templates/react-app/src/base/services/I18nService.ts +19 -0
  19. package/templates/react-app/src/base/types/deprecated-antd.d.ts +60 -0
  20. package/templates/react-app/src/core/IOC.ts +6 -1
  21. package/templates/react-app/src/core/bootstrap.ts +21 -31
  22. package/templates/react-app/src/core/globals.ts +8 -1
  23. package/templates/react-app/src/core/registers/RegisterGlobals.ts +11 -7
  24. package/templates/react-app/src/core/registers/index.ts +1 -2
  25. package/templates/react-app/src/pages/base/About.tsx +114 -1
  26. package/templates/react-app/src/pages/base/Executor.tsx +10 -15
  27. package/templates/react-app/src/styles/css/antd-themes/_default.css +239 -0
  28. package/templates/react-app/src/styles/css/antd-themes/dark.css +176 -0
  29. package/templates/react-app/src/styles/css/antd-themes/index.css +3 -0
  30. package/templates/react-app/src/styles/css/antd-themes/no-context.css +34 -0
  31. package/templates/react-app/src/styles/css/antd-themes/pink.css +199 -0
  32. package/templates/react-app/src/styles/css/index.css +3 -0
  33. package/templates/react-app/src/styles/css/themes/_default.css +10 -181
  34. package/templates/react-app/src/styles/css/themes/dark.css +10 -135
  35. package/templates/react-app/src/styles/css/themes/pink.css +10 -141
  36. package/templates/react-app/src/uikit/components/RouterRenderComponent.tsx +1 -1
  37. package/templates/react-app/src/uikit/controllers/RouterController.ts +1 -1
  38. package/templates/react-app/src/uikit/controllers/UserController.ts +1 -1
  39. package/templates/react-app/tsconfig.json +3 -2
  40. package/templates/react-app/tsconfig.node.json +2 -1
  41. package/templates/react-app/vite.config.ts +70 -2
  42. package/templates/react-app/src/base/cases/router-loader/index.ts +0 -90
  43. package/templates/react-app/src/core/AppConfig.ts +0 -36
@@ -876,3 +876,173 @@ export const PAGE_ERROR_IDENTIFIER_HELP_DESCRIPTION =
876
876
  */
877
877
  export const PAGE_ERROR_IDENTIFIER_CONTACT_SUPPORT =
878
878
  'page.error.identifier.contact_support';
879
+
880
+ /**
881
+ * @description Test message for About page
882
+ * @localZh 这是一条测试消息
883
+ * @localEn This is a test message
884
+ */
885
+ export const ABOUT_MESSAGE_TEST = 'about.message.test';
886
+
887
+ /**
888
+ * @description Notification title for About page
889
+ * @localZh 通知标题
890
+ * @localEn Notification Title
891
+ */
892
+ export const ABOUT_NOTIFICATION_TITLE = 'about.notification.title';
893
+
894
+ /**
895
+ * @description Notification description for About page
896
+ * @localZh 这是一条测试通知
897
+ * @localEn This is a test notification
898
+ */
899
+ export const ABOUT_NOTIFICATION_DESC = 'about.notification.description';
900
+
901
+ /**
902
+ * @description Message button text for About page
903
+ * @localZh 显示 Message
904
+ * @localEn Show Message
905
+ */
906
+ export const ABOUT_BTN_MESSAGE = 'about.button.message';
907
+
908
+ /**
909
+ * @description Message button text for About page
910
+ * @localZh 静态消息
911
+ * @localEn Static Message
912
+ */
913
+ export const ABOUT_BTN_MESSAGE2 = 'about.button.message2';
914
+
915
+ /**
916
+ * @description Notification button text for About page
917
+ * @localZh 显示 Notification
918
+ * @localEn Show Notification
919
+ */
920
+ export const ABOUT_BTN_NOTIFICATION = 'about.button.notification';
921
+
922
+ /**
923
+ * @description Notification button text for About page
924
+ * @localZh 静态通知
925
+ * @localEn Static Notification
926
+ */
927
+ export const ABOUT_BTN_NOTIFICATION2 = 'about.button.notification2';
928
+
929
+ /**
930
+ * @description Tooltip text for About page
931
+ * @localZh 这是一个提示文本
932
+ * @localEn This is a tooltip text
933
+ */
934
+ export const ABOUT_TOOLTIP_TEXT = 'about.tooltip.text';
935
+
936
+ /**
937
+ * @description Tooltip button text for About page
938
+ * @localZh 悬停显示 Tooltip
939
+ * @localEn Hover to show Tooltip
940
+ */
941
+ export const ABOUT_BTN_TOOLTIP = 'about.button.tooltip';
942
+
943
+ /**
944
+ * @description Modal title for About page
945
+ * @localZh 模态框示例
946
+ * @localEn Modal Example
947
+ */
948
+ export const ABOUT_MODAL_TITLE = 'about.modal.title';
949
+
950
+ /**
951
+ * @description Modal content for About page
952
+ * @localZh 这是一个模态框的内容
953
+ * @localEn This is modal content
954
+ */
955
+ export const ABOUT_MODAL_CONTENT = 'about.modal.content';
956
+
957
+ /**
958
+ * @description Modal button text for About page
959
+ * @localZh 显示 Modal
960
+ * @localEn Show Modal
961
+ */
962
+ export const ABOUT_BTN_MODAL = 'about.button.modal';
963
+
964
+ /**
965
+ * @description Drawer title for About page
966
+ * @localZh 抽屉示例
967
+ * @localEn Drawer Example
968
+ */
969
+ export const ABOUT_DRAWER_TITLE = 'about.drawer.title';
970
+
971
+ /**
972
+ * @description Drawer content for About page
973
+ * @localZh 这是一个抽屉的内容
974
+ * @localEn This is drawer content
975
+ */
976
+ export const ABOUT_DRAWER_CONTENT = 'about.drawer.content';
977
+
978
+ /**
979
+ * @description Drawer button text for About page
980
+ * @localZh 显示 Drawer
981
+ * @localEn Show Drawer
982
+ */
983
+ export const ABOUT_BTN_DRAWER = 'about.button.drawer';
984
+
985
+ /**
986
+ * @description Popover content for About page
987
+ * @localZh 这是一个气泡卡片
988
+ * @localEn This is a popover card
989
+ */
990
+ export const ABOUT_POPOVER_CONTENT = 'about.popover.content';
991
+
992
+ /**
993
+ * @description Popover title for About page
994
+ * @localZh Popover 标题
995
+ * @localEn Popover Title
996
+ */
997
+ export const ABOUT_POPOVER_TITLE = 'about.popover.title';
998
+
999
+ /**
1000
+ * @description Popover button text for About page
1001
+ * @localZh 显示 Popover
1002
+ * @localEn Show Popover
1003
+ */
1004
+ export const ABOUT_BTN_POPOVER = 'about.button.popover';
1005
+
1006
+ /**
1007
+ * @description Popconfirm title for About page
1008
+ * @localZh 确认提示
1009
+ * @localEn Confirmation
1010
+ */
1011
+ export const ABOUT_POPCONFIRM_TITLE = 'about.popconfirm.title';
1012
+
1013
+ /**
1014
+ * @description Popconfirm description for About page
1015
+ * @localZh 您确定要执行此操作吗?
1016
+ * @localEn Are you sure you want to perform this action?
1017
+ */
1018
+ export const ABOUT_POPCONFIRM_DESC = 'about.popconfirm.description';
1019
+
1020
+ /**
1021
+ * @description Popconfirm button text for About page
1022
+ * @localZh 显示 Popconfirm
1023
+ * @localEn Show Popconfirm
1024
+ */
1025
+ export const ABOUT_BTN_POPCONFIRM = 'about.button.popconfirm';
1026
+
1027
+ /**
1028
+ * @description Alert message for About page
1029
+ * @localZh 这是一个警告提示
1030
+ * @localEn This is a warning alert
1031
+ */
1032
+ export const ABOUT_ALERT_MESSAGE = 'about.alert.message';
1033
+
1034
+ /**
1035
+ * @description Common OK button text
1036
+ * @localZh 确定
1037
+ * @localEn OK
1038
+ * @Codebase
1039
+ */
1040
+ export const COMMON_OK = 'common.ok';
1041
+
1042
+ /**
1043
+ * @description Common Cancel button text
1044
+ * @localZh 取消
1045
+ * @localEn Cancel
1046
+ * @Codebase
1047
+ */
1048
+ export const COMMON_CANCEL = 'common.cancel';
@@ -1,7 +1,20 @@
1
+ import type { ViteDeprecatedAntdOptions } from '@brain-toolkit/antd-theme-override/vite';
2
+
1
3
  export const envPrefix = 'VITE_';
2
4
 
3
5
  export const browserGlobalsName = 'feGlobals';
4
6
 
7
+ /**
8
+ * 覆盖 antd 主题模式
9
+ *
10
+ * - noGlobals 不要使用全局的 antd 组件(推荐)
11
+ * - overrideStatic 单独覆盖静态组件变量(这个文件就是这个作用)
12
+ *
13
+ * If use vite-deprecated-antd, automatically change file
14
+ */
15
+ export const overrideAntdThemeMode: ViteDeprecatedAntdOptions['mode'] =
16
+ 'noGlobals';
17
+
5
18
  /**
6
19
  * bootstrap ,not inject env
7
20
  */
@@ -51,6 +51,7 @@
51
51
  "test": "vitest run"
52
52
  },
53
53
  "dependencies": {
54
+ "@brain-toolkit/antd-theme-override": "^0.0.3",
54
55
  "@qlover/corekit-bridge": "^1.0.3",
55
56
  "@qlover/fe-corekit": "^1.3.1",
56
57
  "@qlover/logger": "^0.1.1",
@@ -68,9 +69,11 @@
68
69
  "react-dom": "^18.3.1",
69
70
  "react-i18next": "^15.2.0",
70
71
  "react-router-dom": "^7.1.5",
71
- "reflect-metadata": "^0.2.2"
72
+ "reflect-metadata": "^0.2.2",
73
+ "vite": "^6.3.5"
72
74
  },
73
75
  "devDependencies": {
76
+ "@brain-toolkit/ts2locales": "^0.2.3",
74
77
  "@qlover/env-loader": "latest",
75
78
  "@qlover/eslint-plugin-fe-dev": "^0.2.0",
76
79
  "@qlover/fe-scripts": "latest",
@@ -94,10 +97,11 @@
94
97
  "prettier": "^3.5.3",
95
98
  "sass-embedded": "^1.79.4",
96
99
  "tailwindcss": "^4.1.8",
100
+ "terser": "^5.41.0",
97
101
  "typescript": "^5.6.3",
98
102
  "typescript-eslint": "^8.15.0",
99
- "vite": "^5.4.8",
100
103
  "vite-plugin-cross-origin-isolation": "^0.1.6",
104
+ "vite-plugin-imp": "^2.4.0",
101
105
  "vite-tsconfig-paths": "^5.1.4",
102
106
  "vitest": "^3.0.5"
103
107
  }
@@ -123,5 +123,29 @@
123
123
  "page.error.identifier.source_description": "Identifier From: '@config/Identifier.Error'",
124
124
  "page.error.identifier.help.title": "Need Help?",
125
125
  "page.error.identifier.help.description": "If you encounter any issues while using error identifiers, please contact our support team",
126
- "page.error.identifier.contact_support": "Contact Support"
126
+ "page.error.identifier.contact_support": "Contact Support",
127
+ "about.message.test": "This is a test message",
128
+ "about.notification.title": "Notification Title",
129
+ "about.notification.description": "This is a test notification",
130
+ "about.button.message": "Show Message",
131
+ "about.button.notification": "Show Notification",
132
+ "about.tooltip.text": "This is a tooltip text",
133
+ "about.button.tooltip": "Hover to show Tooltip",
134
+ "about.modal.title": "Modal Example",
135
+ "about.modal.content": "This is modal content",
136
+ "about.button.modal": "Show Modal",
137
+ "about.drawer.title": "Drawer Example",
138
+ "about.drawer.content": "This is drawer content",
139
+ "about.button.drawer": "Show Drawer",
140
+ "about.popover.content": "This is a popover card",
141
+ "about.popover.title": "Popover Title",
142
+ "about.button.popover": "Show Popover",
143
+ "about.popconfirm.title": "Confirmation",
144
+ "about.popconfirm.description": "Are you sure you want to perform this action?",
145
+ "about.button.popconfirm": "Show Popconfirm",
146
+ "about.alert.message": "This is a warning alert",
147
+ "common.ok": "OK",
148
+ "common.cancel": "Cancel",
149
+ "about.button.message2": "Static Message",
150
+ "about.button.notification2": "Static Notification"
127
151
  }
@@ -123,5 +123,29 @@
123
123
  "page.error.identifier.source_description": "来自 '@config/Identifier.Error' 的标识符",
124
124
  "page.error.identifier.help.title": "需要帮助?",
125
125
  "page.error.identifier.help.description": "如果您在使用错误标识符时遇到问题,请联系我们的支持团队",
126
- "page.error.identifier.contact_support": "联系支持"
126
+ "page.error.identifier.contact_support": "联系支持",
127
+ "about.message.test": "这是一条测试消息",
128
+ "about.notification.title": "通知标题",
129
+ "about.notification.description": "这是一条测试通知",
130
+ "about.button.message": "显示 Message",
131
+ "about.button.notification": "显示 Notification",
132
+ "about.tooltip.text": "这是一个提示文本",
133
+ "about.button.tooltip": "悬停显示 Tooltip",
134
+ "about.modal.title": "模态框示例",
135
+ "about.modal.content": "这是一个模态框的内容",
136
+ "about.button.modal": "显示 Modal",
137
+ "about.drawer.title": "抽屉示例",
138
+ "about.drawer.content": "这是一个抽屉的内容",
139
+ "about.button.drawer": "显示 Drawer",
140
+ "about.popover.content": "这是一个气泡卡片",
141
+ "about.popover.title": "Popover 标题",
142
+ "about.button.popover": "显示 Popover",
143
+ "about.popconfirm.title": "确认提示",
144
+ "about.popconfirm.description": "您确定要执行此操作吗?",
145
+ "about.button.popconfirm": "显示 Popconfirm",
146
+ "about.alert.message": "这是一个警告提示",
147
+ "common.ok": "确定",
148
+ "common.cancel": "取消",
149
+ "about.button.message2": "静态消息",
150
+ "about.button.notification2": "静态通知"
127
151
  }
@@ -4,8 +4,8 @@ import { lazy, useMemo } from 'react';
4
4
  import { RouterRenderComponent } from './uikit/components/RouterRenderComponent';
5
5
  import { IOC } from './core/IOC';
6
6
  import { RouterController } from './uikit/controllers/RouterController';
7
- import { RouterLoader, type ComponentValue } from '@/base/cases/router-loader';
8
- import { ConfigProvider } from 'antd';
7
+ import { RouterLoader, type ComponentValue } from '@/base/cases/RouterLoader';
8
+ import { AntdThemeProvider } from '@brain-toolkit/antd-theme-override/react';
9
9
 
10
10
  function getAllPages() {
11
11
  const modules = import.meta.glob('./pages/**/*.tsx');
@@ -36,7 +36,8 @@ function App() {
36
36
  }, []);
37
37
 
38
38
  return (
39
- <ConfigProvider
39
+ <AntdThemeProvider
40
+ staticApi={IOC('DialogHandler')}
40
41
  theme={{
41
42
  cssVar: {
42
43
  key: 'fe-theme',
@@ -45,7 +46,7 @@ function App() {
45
46
  }}
46
47
  >
47
48
  <RouterProvider router={routerBase} />
48
- </ConfigProvider>
49
+ </AntdThemeProvider>
49
50
  );
50
51
  }
51
52
 
@@ -1,4 +1,3 @@
1
- import AppConfig from '@/core/AppConfig';
2
1
  import {
3
2
  FetchURLPlugin,
4
3
  RequestAdapterFetch,
@@ -10,9 +9,10 @@ import {
10
9
  } from '@qlover/corekit-bridge';
11
10
  import { RequestLogger } from '../cases/RequestLogger';
12
11
  import { IOCIdentifier } from '@/core/IOC';
12
+ import { appConfig } from '@/core/globals';
13
13
 
14
14
  const apiApiAdapter = new RequestAdapterFetch({
15
- baseURL: AppConfig.aiApiBaseUrl
15
+ baseURL: appConfig.aiApiBaseUrl
16
16
  });
17
17
 
18
18
  // 使用 RequestScheduler
@@ -27,8 +27,8 @@ export const AiApiBootstarp: BootstrapExecutorPlugin = {
27
27
  apiApiAdapter.usePlugin(new FetchURLPlugin());
28
28
  apiApiAdapter.usePlugin(
29
29
  new RequestCommonPlugin({
30
- tokenPrefix: AppConfig.aiApiTokenPrefix,
31
- token: AppConfig.aiApiToken
30
+ tokenPrefix: appConfig.aiApiTokenPrefix,
31
+ token: appConfig.aiApiToken
32
32
  })
33
33
  );
34
34
  apiApiAdapter.usePlugin(ioc.get(IOCIdentifier.ApiMockPlugin));
@@ -1,11 +1,11 @@
1
+ import type { AppConfig } from '@/base/cases/AppConfig';
1
2
  import { IOCIdentifier } from '@/core/IOC';
2
3
  import { RequestAdapterFetch } from '@qlover/fe-corekit';
3
4
  import { inject, injectable } from 'inversify';
4
- import { AppConfigImpl } from '@/core/AppConfig';
5
5
 
6
6
  @injectable()
7
7
  export class FeApiAdapter extends RequestAdapterFetch {
8
- constructor(@inject(IOCIdentifier.AppConfig) appConfig: AppConfigImpl) {
8
+ constructor(@inject(IOCIdentifier.AppConfig) appConfig: AppConfig) {
9
9
  super({
10
10
  responseType: 'json',
11
11
  baseURL: appConfig.feApiBaseUrl
@@ -1,11 +1,11 @@
1
+ import type { AppConfig } from '@/base/cases/AppConfig';
1
2
  import { IOCIdentifier } from '@/core/IOC';
2
3
  import { RequestAdapterFetch } from '@qlover/fe-corekit';
3
4
  import { inject, injectable } from 'inversify';
4
- import { AppConfigImpl } from '@/core/AppConfig';
5
5
 
6
6
  @injectable()
7
7
  export class UserApiAdapter extends RequestAdapterFetch {
8
- constructor(@inject(IOCIdentifier.AppConfig) appConfig: AppConfigImpl) {
8
+ constructor(@inject(IOCIdentifier.AppConfig) appConfig: AppConfig) {
9
9
  super({
10
10
  responseType: 'json',
11
11
  baseURL: appConfig.feApiBaseUrl
@@ -0,0 +1,103 @@
1
+ import type { EnvConfigInterface } from '@qlover/corekit-bridge';
2
+
3
+ /**
4
+ * Application Configuration Management
5
+ *
6
+ * Significance: Centralized configuration management for the application
7
+ * Core idea: Single source of truth for all environment and application settings
8
+ * Main function: Provide typed access to application configuration values
9
+ * Main purpose: Maintain consistent configuration across the application
10
+ *
11
+ * Configuration values are automatically injected from the project's .env files:
12
+ * - .env: Default environment variables
13
+ * - .env.development: Development environment variables
14
+ * - .env.production: Production environment variables
15
+ * - .env.local: Local overrides (git ignored)
16
+ *
17
+ * Environment variables should be prefixed with VITE_ to be exposed to the client side.
18
+ * Example .env file:
19
+ * ```
20
+ * VITE_APP_NAME=MyApp
21
+ * VITE_API_BASE_URL=http://api.example.com
22
+ * VITE_USER_TOKEN_KEY=user_token
23
+ * ```
24
+ *
25
+ * @example
26
+ * const config = new AppConfig();
27
+ * console.log(config.appName); // Value from VITE_APP_NAME
28
+ * console.log(config.aiApiBaseUrl); // Value from VITE_AI_API_BASE_URL
29
+ */
30
+ export class AppConfig implements EnvConfigInterface {
31
+ /**
32
+ * Application name identifier
33
+ * @description Injected from VITE_APP_NAME environment variable
34
+ */
35
+ readonly appName = '';
36
+
37
+ /**
38
+ * Current version of the application
39
+ * @description Injected from VITE_APP_VERSION environment variable
40
+ */
41
+ readonly appVersion = '';
42
+
43
+ /**
44
+ * Current environment mode for Vite
45
+ * @description Represents the running environment (development, production, etc.)
46
+ * Automatically set based on the current .env file being used
47
+ */
48
+ readonly env: string = '';
49
+
50
+ /**
51
+ * Storage key for user authentication token
52
+ * @description Injected from VITE_USER_TOKEN_STORAGE_KEY environment variable
53
+ */
54
+ readonly userTokenStorageKey = '';
55
+
56
+ /**
57
+ * Available OpenAI model configurations
58
+ * @description List of supported OpenAI models for the application
59
+ */
60
+ readonly openAiModels = [
61
+ 'gpt-4o-mini',
62
+ 'gpt-3.5-turbo',
63
+ 'gpt-3.5-turbo-2',
64
+ 'gpt-4',
65
+ 'gpt-4-32k'
66
+ ];
67
+
68
+ /** Base URL for OpenAI API endpoints */
69
+ readonly openAiBaseUrl = '';
70
+
71
+ /** Authentication token for OpenAI API */
72
+ readonly openAiToken = '';
73
+
74
+ /** Prefix for OpenAI authentication token */
75
+ readonly openAiTokenPrefix = '';
76
+
77
+ /** Flag indicating if OpenAI token is required */
78
+ readonly openAiRequireToken = true;
79
+
80
+ /** Default login username */
81
+ readonly loginUser = '';
82
+
83
+ /** Default login password */
84
+ readonly loginPassword = '';
85
+
86
+ /** Base URL for frontend API endpoints */
87
+ readonly feApiBaseUrl = '';
88
+
89
+ /** Base URL for user-related API endpoints */
90
+ readonly userApiBaseUrl = '';
91
+
92
+ /** Base URL for AI service API endpoints */
93
+ readonly aiApiBaseUrl = 'https://api.openai.com/v1';
94
+
95
+ /** Authentication token for AI service API */
96
+ readonly aiApiToken = '';
97
+
98
+ /** Prefix for AI service authentication token */
99
+ readonly aiApiTokenPrefix = 'Bearer';
100
+
101
+ /** Flag indicating if AI service token is required */
102
+ readonly aiApiRequireToken = true;
103
+ }
@@ -1,8 +1,5 @@
1
1
  import { ExecutorError } from '@qlover/fe-corekit';
2
2
 
3
- /**
4
- * 统一当前项目中开发的错误
5
- */
6
3
  export class AppError extends ExecutorError {
7
4
  constructor(
8
5
  public readonly id: string,
@@ -0,0 +1,86 @@
1
+ import type {
2
+ AntdStaticApiInterface,
3
+ MessageApi,
4
+ ModalApi,
5
+ NotificationApi
6
+ } from '@brain-toolkit/antd-theme-override/react';
7
+ import type {
8
+ InteractionHubInterface,
9
+ InteractionOptions,
10
+ ConfirmOptions
11
+ } from '../port/InteractionHubInterface';
12
+
13
+ /**
14
+ * Dialog Handler Implementation
15
+ *
16
+ * Implements the InteractionHubInterface using Ant Design components.
17
+ * Provides concrete implementations for displaying notifications and confirmation dialogs.
18
+ *
19
+ * Features:
20
+ * - Uses Ant Design's message component for notifications
21
+ * - Uses Ant Design's Modal component for confirmations
22
+ * - Supports customizable display durations
23
+ * - Handles error objects appropriately
24
+ *
25
+ * @example
26
+ * const dialog = new DialogHandler();
27
+ * dialog.success('Data saved successfully');
28
+ * dialog.confirm({
29
+ * title: 'Confirm Delete',
30
+ * content: 'Are you sure you want to delete this item?',
31
+ * onOk: () => handleDelete(),
32
+ * });
33
+ */
34
+ export class DialogHandler
35
+ implements InteractionHubInterface, AntdStaticApiInterface
36
+ {
37
+ private antds: {
38
+ message?: MessageApi;
39
+ modal?: ModalApi;
40
+ notification?: NotificationApi;
41
+ } = {};
42
+
43
+ setMessage(message: MessageApi): void {
44
+ this.antds.message = message;
45
+ }
46
+
47
+ setModal(modal: ModalApi): void {
48
+ this.antds.modal = modal;
49
+ }
50
+
51
+ setNotification(notification: NotificationApi): void {
52
+ this.antds.notification = notification;
53
+ }
54
+
55
+ /**
56
+ * Formats error message from various error types
57
+ */
58
+ private formatErrorMessage(error: unknown): string {
59
+ if (error instanceof Error) return error.message;
60
+ if (typeof error === 'string') return error;
61
+ return 'An unknown error occurred';
62
+ }
63
+
64
+ public success(msg: string, options?: InteractionOptions): void {
65
+ this.antds.message?.success({ content: msg, ...options });
66
+ }
67
+
68
+ public error(msg: string, options?: InteractionOptions): void {
69
+ this.antds.message?.error({
70
+ content: options?.error ? this.formatErrorMessage(options.error) : msg,
71
+ ...options
72
+ });
73
+ }
74
+
75
+ public info(msg: string, options?: InteractionOptions): void {
76
+ this.antds.message?.info({ content: msg, ...options });
77
+ }
78
+
79
+ public warn(msg: string, options?: InteractionOptions): void {
80
+ this.antds.message?.warning({ content: msg, ...options });
81
+ }
82
+
83
+ public confirm(options: ConfirmOptions): void {
84
+ this.antds.modal?.confirm(options);
85
+ }
86
+ }