@qlover/create-app 0.7.5 → 0.7.6

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 (79) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/templates/react-app/.env.template +0 -2
  5. package/dist/templates/react-app/__tests__/src/base/services/I18nService.test.ts +1 -1
  6. package/dist/templates/react-app/__tests__/src/core/IOC.test.ts +6 -31
  7. package/dist/templates/react-app/__tests__/src/core/bootstraps/BootstrapsApp.test.ts +1 -1
  8. package/dist/templates/react-app/config/IOCIdentifier.ts +77 -5
  9. package/dist/templates/react-app/config/app.router.ts +2 -2
  10. package/dist/templates/react-app/package.json +4 -7
  11. package/dist/templates/react-app/public/locales/en/common.json +1 -1
  12. package/dist/templates/react-app/public/locales/zh/common.json +1 -1
  13. package/dist/templates/react-app/src/App.tsx +9 -4
  14. package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +1 -1
  15. package/dist/templates/react-app/src/base/apis/userApi/UserApiBootstarp.ts +4 -0
  16. package/dist/templates/react-app/src/base/cases/DialogHandler.ts +16 -13
  17. package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +4 -3
  18. package/dist/templates/react-app/src/base/cases/InversifyContainer.ts +2 -2
  19. package/dist/templates/react-app/src/base/cases/RequestLanguages.ts +39 -0
  20. package/dist/templates/react-app/src/base/cases/RequestState.ts +20 -0
  21. package/dist/templates/react-app/src/base/cases/RequestStatusCatcher.ts +2 -2
  22. package/dist/templates/react-app/src/base/cases/RouterLoader.ts +8 -2
  23. package/dist/templates/react-app/src/base/port/AsyncStateInterface.ts +7 -0
  24. package/dist/templates/react-app/src/base/port/ExecutorPageBridgeInterface.ts +24 -0
  25. package/dist/templates/react-app/src/base/port/I18nServiceInterface.ts +10 -0
  26. package/dist/templates/react-app/src/base/port/JSONStoragePageBridgeInterface.ts +20 -0
  27. package/dist/templates/react-app/src/base/port/ProcesserExecutorInterface.ts +20 -0
  28. package/dist/templates/react-app/src/base/port/RequestPageBridgeInterface.ts +23 -0
  29. package/dist/templates/react-app/src/base/port/RequestStatusInterface.ts +5 -0
  30. package/dist/templates/react-app/src/base/port/RouteServiceInterface.ts +27 -0
  31. package/dist/templates/react-app/src/base/port/UserServiceInterface.ts +12 -0
  32. package/dist/templates/react-app/src/base/services/I18nService.ts +10 -6
  33. package/dist/templates/react-app/src/base/services/ProcesserExecutor.ts +23 -5
  34. package/dist/templates/react-app/src/base/services/RouteService.ts +25 -54
  35. package/dist/templates/react-app/src/base/services/UserService.ts +10 -20
  36. package/dist/templates/react-app/src/core/IOC.ts +1 -26
  37. package/dist/templates/react-app/src/core/IocRegisterImpl.ts +125 -0
  38. package/dist/templates/react-app/src/core/bootstraps/BootstrapApp.ts +4 -6
  39. package/dist/templates/react-app/src/core/bootstraps/BootstrapsRegistry.ts +8 -6
  40. package/dist/templates/react-app/src/core/bootstraps/IocIdentifierTest.ts +26 -0
  41. package/dist/templates/react-app/src/pages/auth/Layout.tsx +2 -2
  42. package/dist/templates/react-app/src/pages/auth/LoginPage.tsx +5 -6
  43. package/dist/templates/react-app/src/pages/auth/RegisterPage.tsx +8 -7
  44. package/dist/templates/react-app/src/pages/base/ExecutorPage.tsx +8 -19
  45. package/dist/templates/react-app/src/pages/base/{ErrorIdentifierPage.tsx → IdentifierPage.tsx} +1 -1
  46. package/dist/templates/react-app/src/pages/base/JSONStoragePage.tsx +11 -15
  47. package/dist/templates/react-app/src/pages/base/Layout.tsx +1 -1
  48. package/dist/templates/react-app/src/pages/base/RedirectPathname.tsx +2 -2
  49. package/dist/templates/react-app/src/pages/base/RequestPage.tsx +34 -46
  50. package/dist/templates/react-app/src/styles/css/antd-themes/_default.css +2 -2
  51. package/dist/templates/react-app/src/styles/css/antd-themes/dark.css +2 -2
  52. package/dist/templates/react-app/src/styles/css/antd-themes/pink.css +2 -2
  53. package/dist/templates/react-app/src/styles/css/index.css +1 -0
  54. package/dist/templates/react-app/src/styles/css/page.css +8 -0
  55. package/dist/templates/react-app/src/styles/css/zIndex.css +9 -0
  56. package/dist/templates/react-app/src/uikit/{controllers/ExecutorController.ts → bridges/ExecutorPageBridge.ts} +13 -36
  57. package/dist/templates/react-app/src/uikit/bridges/JSONStoragePageBridge.ts +41 -0
  58. package/dist/templates/react-app/src/uikit/bridges/NavigateBridge.ts +16 -0
  59. package/dist/templates/react-app/src/uikit/bridges/RequestPageBridge.ts +136 -0
  60. package/dist/templates/react-app/src/uikit/components/LanguageSwitcher.tsx +3 -2
  61. package/dist/templates/react-app/src/uikit/components/LogoutButton.tsx +2 -2
  62. package/dist/templates/react-app/src/uikit/{providers → components}/ProcessExecutorProvider.tsx +4 -4
  63. package/dist/templates/react-app/src/uikit/components/RouterRenderComponent.tsx +1 -1
  64. package/dist/templates/react-app/src/uikit/components/ThemeSwitcher.tsx +3 -5
  65. package/dist/templates/react-app/src/uikit/{providers → components}/UserAuthProvider.tsx +3 -3
  66. package/dist/templates/react-app/src/uikit/hooks/useI18nGuard.ts +5 -2
  67. package/dist/templates/react-app/src/uikit/hooks/{userRouterService.ts → useNavigateBridge.ts} +3 -3
  68. package/dist/templates/react-app/src/uikit/hooks/useStore.ts +5 -2
  69. package/dist/templates/react-app/tsconfig.json +1 -4
  70. package/package.json +1 -1
  71. package/dist/templates/react-app/src/base/port/InteractionHubInterface.ts +0 -94
  72. package/dist/templates/react-app/src/base/port/UIDependenciesInterface.ts +0 -37
  73. package/dist/templates/react-app/src/core/registers/IocRegisterImpl.ts +0 -25
  74. package/dist/templates/react-app/src/core/registers/RegisterCommon.ts +0 -74
  75. package/dist/templates/react-app/src/core/registers/RegisterControllers.ts +0 -26
  76. package/dist/templates/react-app/src/core/registers/RegisterGlobals.ts +0 -30
  77. package/dist/templates/react-app/src/uikit/controllers/JSONStorageController.ts +0 -49
  78. package/dist/templates/react-app/src/uikit/controllers/RequestController.ts +0 -158
  79. /package/dist/templates/react-app/src/uikit/{providers → components}/BaseRouteProvider.tsx +0 -0
@@ -1,74 +0,0 @@
1
- import {
2
- FetchAbortPlugin,
3
- type SyncStorageInterface
4
- } from '@qlover/fe-corekit';
5
- import { Logger } from '@qlover/logger';
6
- import {
7
- RequestCommonPlugin,
8
- ApiMockPlugin,
9
- ApiCatchPlugin,
10
- ThemeService,
11
- TokenStorage
12
- } from '@qlover/corekit-bridge';
13
- import mockDataJson from '@config/feapi.mock.json';
14
- import { RequestStatusCatcher } from '@/base/cases/RequestStatusCatcher';
15
- import { themeConfig } from '@config/theme';
16
- import { localStorage, logger } from '../globals';
17
- import { I18nService } from '@/base/services/I18nService';
18
- import { RouteService } from '@/base/services/RouteService';
19
- import { baseRoutes, baseNoLocaleRoutes } from '@config/app.router';
20
- import { useLocaleRoutes } from '@config/common';
21
- import { UserService } from '@/base/services/UserService';
22
- import { IOCRegister } from '../IOC';
23
- import { IOCIdentifier } from '@config/IOCIdentifier';
24
-
25
- export const RegisterCommon: IOCRegister = {
26
- register(container, _, options): void {
27
- const AppConfig = container.get(IOCIdentifier.AppConfig);
28
-
29
- const feApiToken = new TokenStorage(AppConfig.userTokenStorageKey, {
30
- storage: container.get(IOCIdentifier.LocalStorageEncrypt)
31
- });
32
- const feApiAbort = new FetchAbortPlugin();
33
- const feApiRequestCommonPlugin = new RequestCommonPlugin({
34
- tokenPrefix: AppConfig.openAiTokenPrefix,
35
- requiredToken: true,
36
- token: () => container.get(UserService).getToken()
37
- });
38
-
39
- container.bind(FetchAbortPlugin, feApiAbort);
40
-
41
- container.bind(IOCIdentifier.FeApiToken, feApiToken);
42
- container.bind(IOCIdentifier.FeApiCommonPlugin, feApiRequestCommonPlugin);
43
- container.bind(
44
- IOCIdentifier.ApiMockPlugin,
45
- new ApiMockPlugin(mockDataJson, container.get(Logger))
46
- );
47
- container.bind(
48
- IOCIdentifier.ApiCatchPlugin,
49
- new ApiCatchPlugin(
50
- container.get(Logger),
51
- container.get(RequestStatusCatcher)
52
- )
53
- );
54
-
55
- container.bind(
56
- ThemeService,
57
- new ThemeService({
58
- ...themeConfig,
59
- storage: localStorage as SyncStorageInterface<string, string>
60
- })
61
- );
62
-
63
- container.bind(
64
- RouteService,
65
- new RouteService({
66
- routes: useLocaleRoutes ? baseRoutes : baseNoLocaleRoutes,
67
- logger,
68
- hasLocalRoutes: useLocaleRoutes
69
- })
70
- );
71
-
72
- container.bind(I18nService, new I18nService(options!.pathname));
73
- }
74
- };
@@ -1,26 +0,0 @@
1
- import { localStorage } from '../globals';
2
- import { JSONStorageController } from '@/uikit/controllers/JSONStorageController';
3
- import { ProcesserExecutor } from '@/base/services/ProcesserExecutor';
4
- import { UserService } from '@/base/services/UserService';
5
- import { I18nKeyErrorPlugin } from '@/base/cases/I18nKeyErrorPlugin';
6
- import { IOCContainer, IOCRegister } from '../IOC';
7
- import { IOCManagerInterface } from '@qlover/corekit-bridge';
8
-
9
- export class RegisterControllers implements IOCRegister {
10
- /**
11
- * @override
12
- */
13
- register(
14
- container: IOCContainer,
15
- _: IOCManagerInterface<IOCContainer>
16
- ): void {
17
- const jsonStorageController = new JSONStorageController(localStorage);
18
-
19
- container.bind(JSONStorageController, jsonStorageController);
20
-
21
- container
22
- .get(ProcesserExecutor)
23
- .use(container.get(I18nKeyErrorPlugin))
24
- .use(container.get(UserService));
25
- }
26
- }
@@ -1,30 +0,0 @@
1
- import { JSONSerializer } from '@qlover/fe-corekit';
2
- import {
3
- cookieStorage,
4
- dialogHandler,
5
- JSON,
6
- localStorage,
7
- localStorageEncrypt,
8
- logger
9
- } from '../globals';
10
- import { IOCRegister } from '@/core/IOC';
11
- import { Logger } from '@qlover/logger';
12
- import { IOCIdentifier } from '@config/IOCIdentifier';
13
-
14
- export const RegisterGlobals: IOCRegister = {
15
- register(container, _, options): void {
16
- // inject AppConfig to IOC
17
- container.bind(IOCIdentifier.AppConfig, options!.appConfig);
18
- container.bind(IOCIdentifier.DialogHandler, dialogHandler);
19
-
20
- container.bind(JSONSerializer, JSON);
21
- container.bind(IOCIdentifier.JSON, JSON);
22
-
23
- container.bind(Logger, logger);
24
- container.bind(IOCIdentifier.Logger, logger);
25
-
26
- container.bind(IOCIdentifier.LocalStorage, localStorage);
27
- container.bind(IOCIdentifier.LocalStorageEncrypt, localStorageEncrypt);
28
- container.bind(IOCIdentifier.CookieStorage, cookieStorage);
29
- }
30
- };
@@ -1,49 +0,0 @@
1
- import {
2
- StoreInterface,
3
- type StoreStateInterface
4
- } from '@qlover/corekit-bridge';
5
- import { SyncStorageInterface } from '@qlover/fe-corekit';
6
- import random from 'lodash/random';
7
-
8
- interface JSONStoragePageState extends StoreStateInterface {
9
- testKey1?: number;
10
- testKey2?: number;
11
- expireTime: number;
12
- requestTimeout: number;
13
- }
14
-
15
- export class JSONStorageController extends StoreInterface<JSONStoragePageState> {
16
- selector = {
17
- requestTimeout: (state: JSONStoragePageState) => state.requestTimeout
18
- };
19
-
20
- constructor(private storage: SyncStorageInterface<string, unknown>) {
21
- super(() => ({
22
- testKey1: storage.getItem('testKey1') ?? 0,
23
- testKey2: storage.getItem('testKey2') ?? 0,
24
- expireTime: 5000,
25
- requestTimeout: storage.getItem('requestTimeout') ?? 5000
26
- }));
27
- }
28
-
29
- changeRandomTestKey1 = (): void => {
30
- const value = random(100, 9000);
31
- this.storage.setItem('testKey1', value);
32
- this.emit({ ...this.state, testKey1: value });
33
- };
34
-
35
- onChangeRandomTestKey2 = (): void => {
36
- const value = random(100, 9000);
37
- this.storage.setItem('testKey2', value, Date.now() + this.state.expireTime);
38
- this.emit({ ...this.state, testKey2: value });
39
- };
40
-
41
- changeExpireTime = (expireTime: number): void => {
42
- this.emit({ ...this.state, expireTime });
43
- };
44
-
45
- changeRequestTimeout = (requestTimeout: number): void => {
46
- this.storage.setItem('requestTimeout', requestTimeout);
47
- this.emit({ ...this.state, requestTimeout });
48
- };
49
- }
@@ -1,158 +0,0 @@
1
- import { inject, injectable } from 'inversify';
2
- import { FeApi } from '@/base/apis/feApi/FeApi';
3
- import { logger } from '@/core/globals';
4
- import { UserApi } from '@/base/apis/userApi/UserApi';
5
- import { aiHello } from '@/base/apis/AiApi';
6
- import { StoreInterface } from '@qlover/corekit-bridge';
7
-
8
- function createDefaultState() {
9
- return {
10
- helloState: {
11
- loading: false,
12
- result: null as unknown,
13
- error: null as unknown
14
- },
15
- ipInfoState: {
16
- loading: false,
17
- result: null as unknown,
18
- error: null as unknown
19
- },
20
- randomUserState: {
21
- loading: false,
22
- result: null as unknown,
23
- error: null as unknown
24
- },
25
- abortState: {
26
- loading: false,
27
- result: null as unknown,
28
- error: null as unknown
29
- },
30
- apiCatchResultState: {
31
- loading: false,
32
- result: null as unknown,
33
- error: null as unknown
34
- }
35
- };
36
- }
37
-
38
- export type RequestControllerState = ReturnType<typeof createDefaultState>;
39
-
40
- @injectable()
41
- export class RequestController extends StoreInterface<RequestControllerState> {
42
- constructor(
43
- @inject(FeApi) private readonly feApi: FeApi,
44
- @inject(UserApi) private readonly userApi: UserApi
45
- ) {
46
- super(createDefaultState);
47
- }
48
-
49
- setState(state: Partial<RequestControllerState>): void {
50
- this.emit({ ...this.state, ...state });
51
- }
52
-
53
- onHello = async () => {
54
- if (this.state.helloState.loading) {
55
- return;
56
- }
57
-
58
- this.setState({ helloState: { loading: true, result: '', error: null } });
59
-
60
- try {
61
- const result = await aiHello({
62
- messages: [{ role: 'user', content: 'Hello, world!' }]
63
- });
64
- this.setState({ helloState: { loading: false, result, error: null } });
65
- } catch (error) {
66
- logger.error(error);
67
- this.setState({ helloState: { loading: false, result: null, error } });
68
- }
69
- };
70
-
71
- onIpInfo = async () => {
72
- if (this.state.ipInfoState.loading) {
73
- return;
74
- }
75
-
76
- this.setState({
77
- ipInfoState: { loading: true, result: null, error: null }
78
- });
79
-
80
- try {
81
- const result = await this.feApi.getIpInfo();
82
- this.setState({ ipInfoState: { loading: false, result, error: null } });
83
- } catch (error) {
84
- logger.error(error);
85
- this.setState({ ipInfoState: { loading: false, result: null, error } });
86
- }
87
- };
88
-
89
- onRandomUser = async () => {
90
- if (this.state.randomUserState.loading) {
91
- return;
92
- }
93
-
94
- this.setState({
95
- randomUserState: { loading: true, result: null, error: null }
96
- });
97
- try {
98
- const result = await this.userApi.getRandomUser();
99
- this.setState({
100
- randomUserState: { loading: false, result, error: null }
101
- });
102
- } catch (error) {
103
- logger.error(error);
104
- this.setState({
105
- randomUserState: { loading: false, result: null, error }
106
- });
107
- }
108
- };
109
-
110
- onTriggerApiCatchResult = async () => {
111
- if (this.state.apiCatchResultState.loading) {
112
- return;
113
- }
114
-
115
- this.setState({
116
- apiCatchResultState: { loading: true, result: null, error: null }
117
- });
118
- try {
119
- const result = await this.userApi.testApiCatchResult();
120
- this.setState({
121
- apiCatchResultState: {
122
- loading: false,
123
- result,
124
- error: result.apiCatchResult
125
- }
126
- });
127
- } catch (error) {
128
- this.setState({
129
- apiCatchResultState: { loading: false, result: null, error }
130
- });
131
- }
132
- };
133
-
134
- onTriggerAbortRequest = async () => {
135
- if (this.state.abortState.loading) {
136
- this.stopAbortRequest();
137
- return;
138
- }
139
-
140
- this.setState({ abortState: { loading: true, result: null, error: null } });
141
- try {
142
- await this.userApi.request({
143
- method: 'GET',
144
- url: 'https://api.example.com/users',
145
- disabledMock: true,
146
- requestId: 'onTriggerAbortRequest'
147
- });
148
- } catch (error) {
149
- this.setState({ abortState: { loading: false, result: null, error } });
150
- }
151
- };
152
-
153
- stopAbortRequest = async () => {
154
- this.userApi.stop({
155
- requestId: 'onTriggerAbortRequest'
156
- });
157
- };
158
- }