namirasoft-account-react 1.4.433 → 1.4.435

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 (133) hide show
  1. package/.env.template +15 -15
  2. package/SKILLS.md +514 -514
  3. package/config-overrides.js +72 -72
  4. package/dist/App.css +32 -0
  5. package/dist/App.d.ts +1 -1
  6. package/dist/UseParams.d.ts +1 -1
  7. package/dist/components/NSAAccessListDialog.d.ts +2 -2
  8. package/dist/components/NSAAccessListDialog.module.css +71 -71
  9. package/dist/components/NSAMasterMenu.d.ts +1 -1
  10. package/dist/components/NSAMasterMenu.module.css +248 -248
  11. package/dist/components/NSAMasterMenuItem.d.ts +1 -1
  12. package/dist/components/NSAMessageListDialog.d.ts +1 -1
  13. package/dist/components/NSAMessageListDialog.module.css +99 -99
  14. package/dist/components/NSANavigationGuard.d.ts +1 -1
  15. package/dist/components/NSANavigationGuard.js +12 -5
  16. package/dist/components/NSANavigationGuard.js.map +1 -1
  17. package/dist/components/NSAProductListDialog.d.ts +1 -1
  18. package/dist/components/NSAProductListDialog.module.css +44 -44
  19. package/dist/components/NSAReorderDialog.d.ts +1 -1
  20. package/dist/components/NSAReorderDialog.module.css +49 -49
  21. package/dist/components/NSASortDialog.d.ts +1 -1
  22. package/dist/components/NSATaskBar.d.ts +1 -1
  23. package/dist/components/NSATaskBar.module.css +57 -57
  24. package/dist/components/NSAUserDialog.d.ts +1 -1
  25. package/dist/components/NSAUserDialog.module.css +67 -67
  26. package/dist/components/NSAWorkspaceListDialog.d.ts +1 -1
  27. package/dist/components/NSAWorkspaceListDialog.module.css +41 -41
  28. package/dist/components/NSBoxSecret.d.ts +1 -1
  29. package/dist/components/NSBoxSecret.module.css +23 -23
  30. package/dist/components/NSLabelSecret.d.ts +1 -1
  31. package/dist/components/quickfilter/NSAFilterBoxEnum.module.css +45 -0
  32. package/dist/components/quickfilter/NSAQuickFilterBar.d.ts +1 -1
  33. package/dist/components/quickfilter/NSAQuickFilterBar.module.css +20 -0
  34. package/dist/components/quickfilter/NSAQuickFilterDialog.d.ts +1 -1
  35. package/dist/components/quickfilter/NSAQuickFilterDialog.module.css +75 -0
  36. package/dist/index.css +0 -0
  37. package/dist/layouts/NSALayout.d.ts +1 -1
  38. package/dist/layouts/NSASectionEdit.d.ts +1 -1
  39. package/dist/layouts/NSASectionEditTabPage.d.ts +1 -1
  40. package/dist/layouts/NSASectionEditTabPage.module.css +4 -4
  41. package/dist/layouts/NSASectionList.d.ts +1 -1
  42. package/dist/layouts/NSASectionList.module.css +31 -31
  43. package/dist/layouts/NSASectionView.d.ts +1 -1
  44. package/dist/layouts/NSASectionViewTabMore.d.ts +1 -1
  45. package/dist/layouts/NSASectionViewTabPage.d.ts +1 -1
  46. package/dist/layouts/NSASectionViewTabPage.module.css +47 -47
  47. package/dist/pages/NSAConsentPage.module.css +26 -26
  48. package/dist/pages/NSAEmailVerificationPage.d.ts +1 -1
  49. package/dist/pages/NSAHomePage.d.ts +1 -1
  50. package/dist/pages/NSAHomePage.module.css +41 -41
  51. package/dist/pages/NSALoginPage.d.ts +1 -1
  52. package/dist/pages/NSALoginPage.module.css +26 -26
  53. package/dist/pages/NSAPhoneVerificationPage.d.ts +1 -1
  54. package/dist/pages/NSAVerificationPage.d.ts +1 -1
  55. package/dist/pages/NSAVerificationPage.module.css +31 -31
  56. package/package.json +94 -94
  57. package/public/index.html +21 -21
  58. package/src/App.css +31 -31
  59. package/src/App.tsx +19 -19
  60. package/src/CTFRow.ts +7 -7
  61. package/src/IEntityInfo.ts +33 -33
  62. package/src/NSACacheService.ts +120 -120
  63. package/src/NSAFilterOperators.ts +92 -92
  64. package/src/NSARouterMaker.tsx +140 -140
  65. package/src/NSARouterMakerConfig.ts +15 -15
  66. package/src/NSARouterMakerProps.ts +24 -24
  67. package/src/NSATaskService.ts +122 -122
  68. package/src/Router.tsx +45 -45
  69. package/src/UseParams.tsx +18 -18
  70. package/src/components/NSAAccessListDialog.module.css +71 -71
  71. package/src/components/NSAAccessListDialog.tsx +178 -178
  72. package/src/components/NSAMasterMenu.module.css +248 -248
  73. package/src/components/NSAMasterMenu.tsx +169 -169
  74. package/src/components/NSAMasterMenuItem.tsx +250 -250
  75. package/src/components/NSAMessageListDialog.module.css +99 -99
  76. package/src/components/NSAMessageListDialog.tsx +142 -142
  77. package/src/components/NSANavigationGuard.tsx +21 -6
  78. package/src/components/NSAProductListDialog.module.css +44 -44
  79. package/src/components/NSAProductListDialog.tsx +88 -88
  80. package/src/components/NSAReorderDialog.module.css +49 -49
  81. package/src/components/NSAReorderDialog.tsx +149 -149
  82. package/src/components/NSASortDialog.tsx +117 -117
  83. package/src/components/NSATable.tsx +498 -498
  84. package/src/components/NSATaskBar.module.css +57 -57
  85. package/src/components/NSATaskBar.tsx +101 -101
  86. package/src/components/NSAUserDialog.module.css +67 -67
  87. package/src/components/NSAUserDialog.tsx +122 -122
  88. package/src/components/NSAWorkspaceListDialog.module.css +41 -41
  89. package/src/components/NSAWorkspaceListDialog.tsx +147 -147
  90. package/src/components/NSBoxSecret.module.css +23 -23
  91. package/src/components/NSBoxSecret.tsx +258 -258
  92. package/src/components/NSLabelSecret.tsx +37 -37
  93. package/src/components/quickfilter/NSAFilterBoxBase.tsx +55 -55
  94. package/src/components/quickfilter/NSAFilterBoxBoolean.tsx +54 -54
  95. package/src/components/quickfilter/NSAFilterBoxDate.tsx +104 -104
  96. package/src/components/quickfilter/NSAFilterBoxDateTime.tsx +105 -105
  97. package/src/components/quickfilter/NSAFilterBoxEnum.module.css +44 -44
  98. package/src/components/quickfilter/NSAFilterBoxEnum.tsx +79 -79
  99. package/src/components/quickfilter/NSAFilterBoxNumber.tsx +136 -136
  100. package/src/components/quickfilter/NSAFilterBoxString.tsx +81 -81
  101. package/src/components/quickfilter/NSAFilterBoxTime.tsx +101 -101
  102. package/src/components/quickfilter/NSAQuickFilterBar.module.css +19 -19
  103. package/src/components/quickfilter/NSAQuickFilterBar.tsx +114 -114
  104. package/src/components/quickfilter/NSAQuickFilterDialog.module.css +74 -74
  105. package/src/components/quickfilter/NSAQuickFilterDialog.tsx +260 -260
  106. package/src/css.d.ts +13 -13
  107. package/src/formatters/SecretFormatter.tsx +24 -24
  108. package/src/index.tsx +26 -26
  109. package/src/layouts/Actions.ts +146 -146
  110. package/src/layouts/CFTUtil.ts +18 -18
  111. package/src/layouts/NSALayout.tsx +790 -790
  112. package/src/layouts/NSASectionEdit.tsx +279 -279
  113. package/src/layouts/NSASectionEditTabPage.module.css +4 -4
  114. package/src/layouts/NSASectionEditTabPage.tsx +250 -250
  115. package/src/layouts/NSASectionList.module.css +31 -31
  116. package/src/layouts/NSASectionList.tsx +149 -149
  117. package/src/layouts/NSASectionView.tsx +100 -100
  118. package/src/layouts/NSASectionViewTabMore.tsx +77 -77
  119. package/src/layouts/NSASectionViewTabPage.module.css +47 -47
  120. package/src/layouts/NSASectionViewTabPage.tsx +419 -419
  121. package/src/main.ts +46 -46
  122. package/src/pages/NSAConsentPage.module.css +26 -26
  123. package/src/pages/NSAConsentPage.tsx +120 -120
  124. package/src/pages/NSAEmailVerificationPage.tsx +30 -30
  125. package/src/pages/NSAHomePage.module.css +41 -41
  126. package/src/pages/NSAHomePage.tsx +102 -102
  127. package/src/pages/NSALoginPage.module.css +26 -26
  128. package/src/pages/NSALoginPage.tsx +87 -87
  129. package/src/pages/NSAPhoneVerificationPage.tsx +94 -94
  130. package/src/pages/NSAVerificationPage.module.css +31 -31
  131. package/src/pages/NSAVerificationPage.tsx +186 -186
  132. package/src/pages/PaymentRequired.tsx +76 -76
  133. package/tsconfig.json +43 -43
@@ -1,141 +1,141 @@
1
- import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
- import { EncodingOperation, EnvService, IStorage, IStorageCookie, ObjectService, ParsedNameValue, URLOperation } from "namirasoft-core";
3
- import { NSRouterMaker, NSRouterMakerProps } from 'namirasoft-site-react';
4
- import queryString, { ParsedQuery } from 'query-string';
5
- import type { NavigateFunction } from 'react-router-dom';
6
- import { NSARouterMakerConfig } from "./NSARouterMakerConfig";
7
- import { NSARouterMakerProps } from "./NSARouterMakerProps";
8
- import { NSAConsentPage } from './pages/NSAConsentPage';
9
- import { NSAEmailVerificationPage } from './pages/NSAEmailVerificationPage';
10
- import { NSAPhoneVerificationPage } from './pages/NSAPhoneVerificationPage';
11
-
12
- export class NSARouterMaker
13
- {
14
- private product_id: string;
15
- private storage: IStorage;
16
- private setState: () => void;
17
- private config: NSARouterMakerConfig;
18
- private navigate: NavigateFunction;
19
- constructor(product_id: string, storage: IStorage, setState: () => void, config: NSARouterMakerConfig, navigate: NavigateFunction)
20
- {
21
- this.product_id = product_id;
22
- this.storage = storage;
23
- this.setState = setState;
24
- this.config = config;
25
- this.navigate = navigate;
26
- this.getProps = this.getProps.bind(this);
27
- this.getQueryStrings = this.getQueryStrings.bind(this);
28
- this.getQuery = this.getQuery.bind(this);
29
- this.getLink = this.getLink.bind(this);
30
- this.redirect = this.redirect.bind(this);
31
- this.onRender = this.onRender.bind(this);
32
- }
33
- private getProps(ns_router_maker_props: NSRouterMakerProps): NSARouterMakerProps
34
- {
35
- let Cookies = process.env.REACT_APP_ACCOUNT_TOKEN;
36
- let storage = new IStorageCookie({ domain: ".namirasoft.com", path: "/" }, Cookies);
37
- let token_manager = new TokenManager(storage, () => { });
38
-
39
- let REACT_APP_BASE_URL_ACCOUNT = new EnvService("REACT_APP_BASE_URL_ACCOUNT", true).getString();
40
- let server = new NamirasoftAccountServer(REACT_APP_BASE_URL_ACCOUNT, token_manager, ns_router_maker_props.notifier.onError);
41
-
42
- return {
43
- product_id: this.product_id,
44
- account: {
45
- token_manager,
46
- server,
47
- },
48
- url: {
49
- getLink: this.getLink,
50
- redirect: this.redirect,
51
- getQueryStrings: this.getQueryStrings,
52
- getQuery: this.getQuery,
53
- navigate: this.navigate,
54
- },
55
- renderer: {
56
- renderOnNSALayout: this.config.renderOnNSALayout
57
- },
58
- ...ns_router_maker_props
59
- };
60
- }
61
- getQueryStrings(): ParsedQuery
62
- {
63
- return queryString.parse(window.location.search);
64
- }
65
- getQuery(name: string, base64: boolean = false, remove: boolean = false): string
66
- {
67
- let query = this.getQueryStrings();
68
- let item = query[name];
69
- let ans = new ObjectService(item).getString();
70
- if (base64)
71
- try
72
- {
73
- ans = EncodingOperation.Base64Decode(ans);
74
- } catch (error)
75
- {
76
- ans = "";
77
- }
78
- if (remove)
79
- {
80
- const url = new URL(window.location.href);
81
- url.searchParams.delete(name);
82
- window.history.replaceState({}, '', url);
83
- }
84
-
85
- return ans;
86
- }
87
- getLink(sub: string, customQuery: { [name: string]: ParsedNameValue })
88
- {
89
- if (!customQuery)
90
- customQuery = {};
91
- return URLOperation.getLink("", sub, customQuery);
92
- }
93
- redirect(sub: string, customQuery: { [name: string]: ParsedNameValue }): void
94
- {
95
- let ans = this.getLink(sub, customQuery);
96
- this.navigate(ans);
97
- }
98
- onRender(): React.JSX.Element
99
- {
100
- let maker = new NSRouterMaker(this.storage, this.setState, {
101
- onRender: (ns_router_maker_props: NSRouterMakerProps) =>
102
- {
103
- let props = this.getProps(ns_router_maker_props);
104
- let banned = false;
105
- if (props.account.token_manager.exists())
106
- {
107
- banned = props.account.token_manager.getUserData(user => user.banned, false);
108
- if (!banned)
109
- {
110
- let result = this.config.getCustomRender?.(props);
111
- if (result)
112
- return result;
113
- return <NSAConsentPage
114
- {...props}
115
- product_id={this.product_id}
116
- onAccepted={() =>
117
- {
118
- if (this.config.requirement.verification.email)
119
- {
120
- let e_verified = props.account.token_manager.getUserData(u => u.e_verified, false);
121
- if (!e_verified)
122
- return this.config.renderOnNSALayout(props, <NSAEmailVerificationPage {...props} callback='' />);
123
- }
124
- if (this.config.requirement.verification.phone)
125
- {
126
- let p_verified = props.account.token_manager.getUserData(u => u.p_verified, false);
127
- if (!p_verified)
128
- return this.config.renderOnNSALayout(props, <NSAPhoneVerificationPage {...props} callback='' />);
129
- }
130
- return this.config.onRenderOnLogin(props);
131
- }}
132
- />;
133
- }
134
- }
135
- return this.config.onRenderOnLogout(props, banned);
136
- }
137
- });
138
-
139
- return maker.onRender();
140
- }
1
+ import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
+ import { EncodingOperation, EnvService, IStorage, IStorageCookie, ObjectService, ParsedNameValue, URLOperation } from "namirasoft-core";
3
+ import { NSRouterMaker, NSRouterMakerProps } from 'namirasoft-site-react';
4
+ import queryString, { ParsedQuery } from 'query-string';
5
+ import type { NavigateFunction } from 'react-router-dom';
6
+ import { NSARouterMakerConfig } from "./NSARouterMakerConfig";
7
+ import { NSARouterMakerProps } from "./NSARouterMakerProps";
8
+ import { NSAConsentPage } from './pages/NSAConsentPage';
9
+ import { NSAEmailVerificationPage } from './pages/NSAEmailVerificationPage';
10
+ import { NSAPhoneVerificationPage } from './pages/NSAPhoneVerificationPage';
11
+
12
+ export class NSARouterMaker
13
+ {
14
+ private product_id: string;
15
+ private storage: IStorage;
16
+ private setState: () => void;
17
+ private config: NSARouterMakerConfig;
18
+ private navigate: NavigateFunction;
19
+ constructor(product_id: string, storage: IStorage, setState: () => void, config: NSARouterMakerConfig, navigate: NavigateFunction)
20
+ {
21
+ this.product_id = product_id;
22
+ this.storage = storage;
23
+ this.setState = setState;
24
+ this.config = config;
25
+ this.navigate = navigate;
26
+ this.getProps = this.getProps.bind(this);
27
+ this.getQueryStrings = this.getQueryStrings.bind(this);
28
+ this.getQuery = this.getQuery.bind(this);
29
+ this.getLink = this.getLink.bind(this);
30
+ this.redirect = this.redirect.bind(this);
31
+ this.onRender = this.onRender.bind(this);
32
+ }
33
+ private getProps(ns_router_maker_props: NSRouterMakerProps): NSARouterMakerProps
34
+ {
35
+ let Cookies = process.env.REACT_APP_ACCOUNT_TOKEN;
36
+ let storage = new IStorageCookie({ domain: ".namirasoft.com", path: "/" }, Cookies);
37
+ let token_manager = new TokenManager(storage, () => { });
38
+
39
+ let REACT_APP_BASE_URL_ACCOUNT = new EnvService("REACT_APP_BASE_URL_ACCOUNT", true).getString();
40
+ let server = new NamirasoftAccountServer(REACT_APP_BASE_URL_ACCOUNT, token_manager, ns_router_maker_props.notifier.onError);
41
+
42
+ return {
43
+ product_id: this.product_id,
44
+ account: {
45
+ token_manager,
46
+ server,
47
+ },
48
+ url: {
49
+ getLink: this.getLink,
50
+ redirect: this.redirect,
51
+ getQueryStrings: this.getQueryStrings,
52
+ getQuery: this.getQuery,
53
+ navigate: this.navigate,
54
+ },
55
+ renderer: {
56
+ renderOnNSALayout: this.config.renderOnNSALayout
57
+ },
58
+ ...ns_router_maker_props
59
+ };
60
+ }
61
+ getQueryStrings(): ParsedQuery
62
+ {
63
+ return queryString.parse(window.location.search);
64
+ }
65
+ getQuery(name: string, base64: boolean = false, remove: boolean = false): string
66
+ {
67
+ let query = this.getQueryStrings();
68
+ let item = query[name];
69
+ let ans = new ObjectService(item).getString();
70
+ if (base64)
71
+ try
72
+ {
73
+ ans = EncodingOperation.Base64Decode(ans);
74
+ } catch (error)
75
+ {
76
+ ans = "";
77
+ }
78
+ if (remove)
79
+ {
80
+ const url = new URL(window.location.href);
81
+ url.searchParams.delete(name);
82
+ window.history.replaceState({}, '', url);
83
+ }
84
+
85
+ return ans;
86
+ }
87
+ getLink(sub: string, customQuery: { [name: string]: ParsedNameValue })
88
+ {
89
+ if (!customQuery)
90
+ customQuery = {};
91
+ return URLOperation.getLink("", sub, customQuery);
92
+ }
93
+ redirect(sub: string, customQuery: { [name: string]: ParsedNameValue }): void
94
+ {
95
+ let ans = this.getLink(sub, customQuery);
96
+ this.navigate(ans);
97
+ }
98
+ onRender(): React.JSX.Element
99
+ {
100
+ let maker = new NSRouterMaker(this.storage, this.setState, {
101
+ onRender: (ns_router_maker_props: NSRouterMakerProps) =>
102
+ {
103
+ let props = this.getProps(ns_router_maker_props);
104
+ let banned = false;
105
+ if (props.account.token_manager.exists())
106
+ {
107
+ banned = props.account.token_manager.getUserData(user => user.banned, false);
108
+ if (!banned)
109
+ {
110
+ let result = this.config.getCustomRender?.(props);
111
+ if (result)
112
+ return result;
113
+ return <NSAConsentPage
114
+ {...props}
115
+ product_id={this.product_id}
116
+ onAccepted={() =>
117
+ {
118
+ if (this.config.requirement.verification.email)
119
+ {
120
+ let e_verified = props.account.token_manager.getUserData(u => u.e_verified, false);
121
+ if (!e_verified)
122
+ return this.config.renderOnNSALayout(props, <NSAEmailVerificationPage {...props} callback='' />);
123
+ }
124
+ if (this.config.requirement.verification.phone)
125
+ {
126
+ let p_verified = props.account.token_manager.getUserData(u => u.p_verified, false);
127
+ if (!p_verified)
128
+ return this.config.renderOnNSALayout(props, <NSAPhoneVerificationPage {...props} callback='' />);
129
+ }
130
+ return this.config.onRenderOnLogin(props);
131
+ }}
132
+ />;
133
+ }
134
+ }
135
+ return this.config.onRenderOnLogout(props, banned);
136
+ }
137
+ });
138
+
139
+ return maker.onRender();
140
+ }
141
141
  };
@@ -1,16 +1,16 @@
1
- import React from "react";
2
- import { NSARouterMakerProps } from "./NSARouterMakerProps";
3
-
4
- export interface NSARouterMakerConfig
5
- {
6
- onRenderOnLogin(props: NSARouterMakerProps): React.JSX.Element;
7
- onRenderOnLogout(props: NSARouterMakerProps, banned: boolean): React.JSX.Element;
8
- renderOnNSALayout(props: NSARouterMakerProps, children: React.JSX.Element): React.JSX.Element;
9
- getCustomRender?: (props: NSARouterMakerProps) => React.JSX.Element | null;
10
- requirement: {
11
- verification: {
12
- email: boolean;
13
- phone: boolean;
14
- };
15
- };
1
+ import React from "react";
2
+ import { NSARouterMakerProps } from "./NSARouterMakerProps";
3
+
4
+ export interface NSARouterMakerConfig
5
+ {
6
+ onRenderOnLogin(props: NSARouterMakerProps): React.JSX.Element;
7
+ onRenderOnLogout(props: NSARouterMakerProps, banned: boolean): React.JSX.Element;
8
+ renderOnNSALayout(props: NSARouterMakerProps, children: React.JSX.Element): React.JSX.Element;
9
+ getCustomRender?: (props: NSARouterMakerProps) => React.JSX.Element | null;
10
+ requirement: {
11
+ verification: {
12
+ email: boolean;
13
+ phone: boolean;
14
+ };
15
+ };
16
16
  }
@@ -1,25 +1,25 @@
1
- import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
- import { ParsedNameValue } from "namirasoft-core";
3
- import { NSRouterMakerProps } from "namirasoft-site-react";
4
- import { ParsedQuery } from "query-string";
5
- import { NavigateFunction } from "react-router-dom";
6
-
7
- export interface NSARouterMakerProps extends NSRouterMakerProps
8
- {
9
- product_id: string;
10
- account: {
11
- token_manager: TokenManager
12
- server: NamirasoftAccountServer;
13
- },
14
- url: {
15
- getQueryStrings(): ParsedQuery;
16
- getQuery(name: string, base64?: boolean, remove?: boolean): string;
17
- getLink(sub: string, customQuery: { [name: string]: ParsedNameValue }): string;
18
- redirect(sub: string, customQuery: { [name: string]: ParsedNameValue }): void;
19
- navigate: NavigateFunction;
20
- },
21
- renderer:
22
- {
23
- renderOnNSALayout(props: NSARouterMakerProps, children: React.JSX.Element): React.JSX.Element;
24
- }
1
+ import { NamirasoftAccountServer, TokenManager } from "namirasoft-account";
2
+ import { ParsedNameValue } from "namirasoft-core";
3
+ import { NSRouterMakerProps } from "namirasoft-site-react";
4
+ import { ParsedQuery } from "query-string";
5
+ import { NavigateFunction } from "react-router-dom";
6
+
7
+ export interface NSARouterMakerProps extends NSRouterMakerProps
8
+ {
9
+ product_id: string;
10
+ account: {
11
+ token_manager: TokenManager
12
+ server: NamirasoftAccountServer;
13
+ },
14
+ url: {
15
+ getQueryStrings(): ParsedQuery;
16
+ getQuery(name: string, base64?: boolean, remove?: boolean): string;
17
+ getLink(sub: string, customQuery: { [name: string]: ParsedNameValue }): string;
18
+ redirect(sub: string, customQuery: { [name: string]: ParsedNameValue }): void;
19
+ navigate: NavigateFunction;
20
+ },
21
+ renderer:
22
+ {
23
+ renderOnNSALayout(props: NSARouterMakerProps, children: React.JSX.Element): React.JSX.Element;
24
+ }
25
25
  }
@@ -1,123 +1,123 @@
1
- export type NSATaskStatus = "running" | "completed" | "cancelled";
2
-
3
- export interface NSATask
4
- {
5
- id: string;
6
- title: string;
7
- total: number;
8
- completed: number;
9
- succeeded: number;
10
- failed: number;
11
- status: NSATaskStatus;
12
- cancel: () => void;
13
- }
14
-
15
- export interface NSATaskResult<T>
16
- {
17
- succeeded: T[];
18
- failed: T[];
19
- cancelled: boolean;
20
- }
21
-
22
- export interface NSATaskRunOptions<T>
23
- {
24
- title: string;
25
- items: T[];
26
- handler: (item: T, index: number) => Promise<void>;
27
- onItemError?: (item: T, error: any, index: number) => void;
28
- onFinished?: (result: NSATaskResult<T>) => void;
29
- }
30
-
31
- export class NSATaskService
32
- {
33
- public static main = new NSATaskService();
34
- private tasks: NSATask[] = [];
35
- private listeners: Set<() => void> = new Set();
36
- private counter: number = 0;
37
- private removeDelayMs: number = 4000;
38
-
39
- subscribe(listener: () => void): () => void
40
- {
41
- this.listeners.add(listener);
42
- return () =>
43
- {
44
- this.listeners.delete(listener);
45
- };
46
- }
47
-
48
- getTasks(): NSATask[]
49
- {
50
- return this.tasks;
51
- }
52
-
53
- private emit(): void
54
- {
55
- this.listeners.forEach(listener => listener());
56
- }
57
-
58
- dismiss(id: string): void
59
- {
60
- this.tasks = this.tasks.filter(task => task.id !== id);
61
- this.emit();
62
- }
63
-
64
- run<T>(options: NSATaskRunOptions<T>): NSATask
65
- {
66
- this.counter += 1;
67
- const id = `nsa-task-${this.counter}`;
68
-
69
- let cancelled = false;
70
- const task: NSATask = {
71
- id,
72
- title: options.title,
73
- total: options.items.length,
74
- completed: 0,
75
- succeeded: 0,
76
- failed: 0,
77
- status: "running",
78
- cancel: () => { cancelled = true; }
79
- };
80
-
81
- this.tasks = [...this.tasks, task];
82
- this.emit();
83
-
84
- const execute = async () =>
85
- {
86
- const succeeded: T[] = [];
87
- const failed: T[] = [];
88
-
89
- for (let index = 0; index < options.items.length; index++)
90
- {
91
- if (cancelled)
92
- break;
93
-
94
- const item = options.items[index];
95
- try
96
- {
97
- await options.handler(item, index);
98
- succeeded.push(item);
99
- task.succeeded += 1;
100
- }
101
- catch (error: any)
102
- {
103
- failed.push(item);
104
- task.failed += 1;
105
- options.onItemError?.(item, error, index);
106
- }
107
- task.completed += 1;
108
- this.emit();
109
- }
110
-
111
- task.status = cancelled ? "cancelled" : "completed";
112
- this.emit();
113
-
114
- options.onFinished?.({ succeeded, failed, cancelled });
115
-
116
- window.setTimeout(() => this.dismiss(id), this.removeDelayMs);
117
- };
118
-
119
- execute();
120
-
121
- return task;
122
- }
1
+ export type NSATaskStatus = "running" | "completed" | "cancelled";
2
+
3
+ export interface NSATask
4
+ {
5
+ id: string;
6
+ title: string;
7
+ total: number;
8
+ completed: number;
9
+ succeeded: number;
10
+ failed: number;
11
+ status: NSATaskStatus;
12
+ cancel: () => void;
13
+ }
14
+
15
+ export interface NSATaskResult<T>
16
+ {
17
+ succeeded: T[];
18
+ failed: T[];
19
+ cancelled: boolean;
20
+ }
21
+
22
+ export interface NSATaskRunOptions<T>
23
+ {
24
+ title: string;
25
+ items: T[];
26
+ handler: (item: T, index: number) => Promise<void>;
27
+ onItemError?: (item: T, error: any, index: number) => void;
28
+ onFinished?: (result: NSATaskResult<T>) => void;
29
+ }
30
+
31
+ export class NSATaskService
32
+ {
33
+ public static main = new NSATaskService();
34
+ private tasks: NSATask[] = [];
35
+ private listeners: Set<() => void> = new Set();
36
+ private counter: number = 0;
37
+ private removeDelayMs: number = 4000;
38
+
39
+ subscribe(listener: () => void): () => void
40
+ {
41
+ this.listeners.add(listener);
42
+ return () =>
43
+ {
44
+ this.listeners.delete(listener);
45
+ };
46
+ }
47
+
48
+ getTasks(): NSATask[]
49
+ {
50
+ return this.tasks;
51
+ }
52
+
53
+ private emit(): void
54
+ {
55
+ this.listeners.forEach(listener => listener());
56
+ }
57
+
58
+ dismiss(id: string): void
59
+ {
60
+ this.tasks = this.tasks.filter(task => task.id !== id);
61
+ this.emit();
62
+ }
63
+
64
+ run<T>(options: NSATaskRunOptions<T>): NSATask
65
+ {
66
+ this.counter += 1;
67
+ const id = `nsa-task-${this.counter}`;
68
+
69
+ let cancelled = false;
70
+ const task: NSATask = {
71
+ id,
72
+ title: options.title,
73
+ total: options.items.length,
74
+ completed: 0,
75
+ succeeded: 0,
76
+ failed: 0,
77
+ status: "running",
78
+ cancel: () => { cancelled = true; }
79
+ };
80
+
81
+ this.tasks = [...this.tasks, task];
82
+ this.emit();
83
+
84
+ const execute = async () =>
85
+ {
86
+ const succeeded: T[] = [];
87
+ const failed: T[] = [];
88
+
89
+ for (let index = 0; index < options.items.length; index++)
90
+ {
91
+ if (cancelled)
92
+ break;
93
+
94
+ const item = options.items[index];
95
+ try
96
+ {
97
+ await options.handler(item, index);
98
+ succeeded.push(item);
99
+ task.succeeded += 1;
100
+ }
101
+ catch (error: any)
102
+ {
103
+ failed.push(item);
104
+ task.failed += 1;
105
+ options.onItemError?.(item, error, index);
106
+ }
107
+ task.completed += 1;
108
+ this.emit();
109
+ }
110
+
111
+ task.status = cancelled ? "cancelled" : "completed";
112
+ this.emit();
113
+
114
+ options.onFinished?.({ succeeded, failed, cancelled });
115
+
116
+ window.setTimeout(() => this.dismiss(id), this.removeDelayMs);
117
+ };
118
+
119
+ execute();
120
+
121
+ return task;
122
+ }
123
123
  }