@etsoo/react 1.4.99 → 1.5.3

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.
@@ -1,6 +1,7 @@
1
1
  import { CoreApp, IActionResult, IAppSettings, ICoreApp, IUser, IUserData } from '@etsoo/appscript';
2
2
  import { NotificationRenderProps, NotificationReturn } from '@etsoo/notificationbase';
3
3
  import { DataTypes } from '@etsoo/shared';
4
+ import { History } from '@reach/router';
4
5
  import React from 'react';
5
6
  import { NotificationReactCallProps } from '../notifier/Notifier';
6
7
  import { CultureAction, CultureState } from '../states/CultureState';
@@ -30,6 +31,10 @@ export interface IReactApp<S extends IAppSettings, D extends IUser, P extends IP
30
31
  * User state
31
32
  */
32
33
  readonly userState: UserState<D>;
34
+ /**
35
+ * Router history
36
+ */
37
+ readonly history?: History;
33
38
  /**
34
39
  * Is screen size down 'sm'
35
40
  */
@@ -69,6 +74,10 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
69
74
  * Culture state
70
75
  */
71
76
  readonly cultureState: CultureState;
77
+ /**
78
+ * Router history
79
+ */
80
+ readonly history?: History;
72
81
  /**
73
82
  * Page state
74
83
  */
@@ -138,6 +147,11 @@ export declare class ReactApp<S extends IAppSettings, D extends IUser, P extends
138
147
  * @param callback Callback
139
148
  */
140
149
  freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
150
+ /**
151
+ * Redirect to the Url
152
+ * @param url Url
153
+ */
154
+ redirectTo(url: string): void;
141
155
  /**
142
156
  * Set page data
143
157
  * @param data Page data
@@ -1,5 +1,6 @@
1
1
  import { ActionResultError, BridgeUtils, CoreApp, createClient } from '@etsoo/appscript';
2
2
  import { WindowStorage } from '@etsoo/shared';
3
+ import { navigate } from '@reach/router';
3
4
  import React from 'react';
4
5
  import { NotifierMU } from '../mu/NotifierMU';
5
6
  import { ProgressCount } from '../mu/ProgressCount';
@@ -7,6 +8,7 @@ import { CultureState } from '../states/CultureState';
7
8
  import { PageActionType, PageState } from '../states/PageState';
8
9
  import { UserActionType, UserState } from '../states/UserState';
9
10
  import { Labels } from './Labels';
11
+ import { Utils } from './Utils';
10
12
  /**
11
13
  * Global application
12
14
  */
@@ -63,6 +65,10 @@ export class ReactApp extends CoreApp {
63
65
  * User state
64
66
  */
65
67
  this.userState = new UserState();
68
+ this.history =
69
+ window.location.hostname === ''
70
+ ? Utils.getMemoryHistory()
71
+ : undefined;
66
72
  this.cultureState = new CultureState(settings.currentCulture);
67
73
  this.pageState = new PageState();
68
74
  globalApp = this;
@@ -188,6 +194,13 @@ export class ReactApp extends CoreApp {
188
194
  inputs: progress
189
195
  });
190
196
  }
197
+ /**
198
+ * Redirect to the Url
199
+ * @param url Url
200
+ */
201
+ redirectTo(url) {
202
+ (this.history == null ? navigate : this.history.navigate)(url);
203
+ }
191
204
  /**
192
205
  * Set page data
193
206
  * @param data Page data
@@ -1,3 +1,4 @@
1
+ import { History } from '@reach/router';
1
2
  import React from 'react';
2
3
  /**
3
4
  * React utils
@@ -9,6 +10,11 @@ export declare namespace Utils {
9
10
  * @returns Formatted value
10
11
  */
11
12
  function formatInputValue(value: unknown): string | number | any[] | undefined;
13
+ /**
14
+ * Get memory history
15
+ * @returns History
16
+ */
17
+ function getMemoryHistory(): History;
12
18
  /**
13
19
  * Is safe click
14
20
  * @param event Mouse event
package/lib/app/Utils.js CHANGED
@@ -1,8 +1,12 @@
1
+ import { createHistory, createMemorySource } from '@reach/router';
1
2
  /**
2
3
  * React utils
3
4
  */
4
5
  export var Utils;
5
6
  (function (Utils) {
7
+ // Memory history
8
+ // https://github.com/reach/router/issues/225
9
+ let memoryHistory;
6
10
  /**
7
11
  * Format input value
8
12
  * @param value Input value
@@ -20,6 +24,17 @@ export var Utils;
20
24
  return String(value);
21
25
  }
22
26
  Utils.formatInputValue = formatInputValue;
27
+ /**
28
+ * Get memory history
29
+ * @returns History
30
+ */
31
+ function getMemoryHistory() {
32
+ if (memoryHistory == null) {
33
+ memoryHistory = createHistory(createMemorySource('/'));
34
+ }
35
+ return memoryHistory;
36
+ }
37
+ Utils.getMemoryHistory = getMemoryHistory;
23
38
  /**
24
39
  * Is safe click
25
40
  * @param event Mouse event
@@ -24,8 +24,9 @@ export function BridgeCloseButton(props) {
24
24
  onClick(event);
25
25
  host.exit();
26
26
  };
27
- return (React.createElement(IconButton, { "aria-label": "close", color: "primary", onClick: onClickLocal, sx: {
27
+ return (React.createElement(IconButton, { "aria-label": "close", color: "secondary", onClick: onClickLocal, title: title, sx: {
28
28
  position: 'absolute',
29
+ zIndex: (theme) => theme.zIndex.appBar + 1,
29
30
  top: (theme) => theme.spacing(0.5),
30
31
  right: (theme) => theme.spacing(0.5)
31
32
  }, ...rest },
@@ -116,7 +116,9 @@ export function SelectEx(props) {
116
116
  React.createElement(InputLabel, { id: labelId, shrink: search
117
117
  ? MUGlobal.searchFieldShrink
118
118
  : MUGlobal.inputFieldShrink }, label),
119
- React.createElement(Select, { ref: divRef, value: localOptions.length > 0 ? valueState !== null && valueState !== void 0 ? valueState : '' : '', input: React.createElement(OutlinedInput, { notched: true, label: label }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
119
+ React.createElement(Select, { ref: divRef, value: localOptions.some((option) => itemChecked(getId(option)))
120
+ ? valueState !== null && valueState !== void 0 ? valueState : ''
121
+ : '', input: React.createElement(OutlinedInput, { notched: true, label: label }), labelId: labelId, name: name, multiple: multiple, onChange: (event, child) => {
120
122
  if (onChange)
121
123
  onChange(event, child);
122
124
  if (multiple)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.4.99",
3
+ "version": "1.5.3",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -50,7 +50,7 @@
50
50
  "@emotion/react": "^11.7.1",
51
51
  "@emotion/style": "^0.8.0",
52
52
  "@emotion/styled": "^11.6.0",
53
- "@etsoo/appscript": "^1.2.42",
53
+ "@etsoo/appscript": "^1.2.43",
54
54
  "@etsoo/notificationbase": "^1.1.1",
55
55
  "@etsoo/shared": "^1.1.11",
56
56
  "@mui/icons-material": "^5.4.1",
@@ -14,6 +14,7 @@ import {
14
14
  NotificationReturn
15
15
  } from '@etsoo/notificationbase';
16
16
  import { DataTypes, WindowStorage } from '@etsoo/shared';
17
+ import { History, navigate } from '@reach/router';
17
18
  import React from 'react';
18
19
  import { NotifierMU } from '../mu/NotifierMU';
19
20
  import { ProgressCount } from '../mu/ProgressCount';
@@ -34,6 +35,7 @@ import {
34
35
  } from '../states/UserState';
35
36
  import { InputDialogProps } from './InputDialogProps';
36
37
  import { Labels } from './Labels';
38
+ import { Utils } from './Utils';
37
39
 
38
40
  /**
39
41
  * Global application
@@ -97,6 +99,11 @@ export interface IReactApp<
97
99
  */
98
100
  readonly userState: UserState<D>;
99
101
 
102
+ /**
103
+ * Router history
104
+ */
105
+ readonly history?: History;
106
+
100
107
  /**
101
108
  * Is screen size down 'sm'
102
109
  */
@@ -166,6 +173,11 @@ export class ReactApp<
166
173
  */
167
174
  readonly cultureState: CultureState;
168
175
 
176
+ /**
177
+ * Router history
178
+ */
179
+ readonly history?: History;
180
+
169
181
  /**
170
182
  * Page state
171
183
  */
@@ -209,6 +221,10 @@ export class ReactApp<
209
221
  new WindowStorage(),
210
222
  name
211
223
  );
224
+ this.history =
225
+ window.location.hostname === ''
226
+ ? Utils.getMemoryHistory()
227
+ : undefined;
212
228
  this.cultureState = new CultureState(settings.currentCulture);
213
229
  this.pageState = new PageState<P>();
214
230
 
@@ -349,6 +365,14 @@ export class ReactApp<
349
365
  );
350
366
  }
351
367
 
368
+ /**
369
+ * Redirect to the Url
370
+ * @param url Url
371
+ */
372
+ override redirectTo(url: string) {
373
+ (this.history == null ? navigate : this.history.navigate)(url);
374
+ }
375
+
352
376
  /**
353
377
  * Set page data
354
378
  * @param data Page data
package/src/app/Utils.ts CHANGED
@@ -1,9 +1,14 @@
1
+ import { createHistory, createMemorySource, History } from '@reach/router';
1
2
  import React from 'react';
2
3
 
3
4
  /**
4
5
  * React utils
5
6
  */
6
7
  export namespace Utils {
8
+ // Memory history
9
+ // https://github.com/reach/router/issues/225
10
+ let memoryHistory: History | null;
11
+
7
12
  /**
8
13
  * Format input value
9
14
  * @param value Input value
@@ -21,6 +26,17 @@ export namespace Utils {
21
26
  return String(value);
22
27
  }
23
28
 
29
+ /**
30
+ * Get memory history
31
+ * @returns History
32
+ */
33
+ export function getMemoryHistory() {
34
+ if (memoryHistory == null) {
35
+ memoryHistory = createHistory(createMemorySource('/'));
36
+ }
37
+ return memoryHistory;
38
+ }
39
+
24
40
  /**
25
41
  * Is safe click
26
42
  * @param event Mouse event
@@ -47,10 +47,12 @@ export function BridgeCloseButton(props: BridgeCloseButtonProps) {
47
47
  return (
48
48
  <IconButton
49
49
  aria-label="close"
50
- color="primary"
50
+ color="secondary"
51
51
  onClick={onClickLocal}
52
+ title={title}
52
53
  sx={{
53
54
  position: 'absolute',
55
+ zIndex: (theme) => theme.zIndex.appBar + 1,
54
56
  top: (theme) => theme.spacing(0.5),
55
57
  right: (theme) => theme.spacing(0.5)
56
58
  }}
@@ -211,7 +211,11 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
211
211
  </InputLabel>
212
212
  <Select
213
213
  ref={divRef}
214
- value={localOptions.length > 0 ? valueState ?? '' : ''}
214
+ value={
215
+ localOptions.some((option) => itemChecked(getId(option)))
216
+ ? valueState ?? ''
217
+ : ''
218
+ }
215
219
  input={<OutlinedInput notched label={label} />}
216
220
  labelId={labelId}
217
221
  name={name}