@etsoo/react 1.5.15 → 1.5.16

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.
@@ -8,7 +8,7 @@ import { CultureState } from '../states/CultureState';
8
8
  import { PageActionType, PageState } from '../states/PageState';
9
9
  import { UserActionType, UserState } from '../states/UserState';
10
10
  import { Labels } from './Labels';
11
- import { Utils } from './Utils';
11
+ import { ReactUtils } from './ReactUtils';
12
12
  /**
13
13
  * Global application
14
14
  */
@@ -68,7 +68,7 @@ export class ReactApp extends CoreApp {
68
68
  this.history =
69
69
  BridgeUtils.host == null
70
70
  ? undefined
71
- : Utils.getMemoryHistory(BridgeUtils.host.getStartUrl());
71
+ : ReactUtils.getMemoryHistory(BridgeUtils.host.getStartUrl());
72
72
  this.cultureState = new CultureState(settings.currentCulture);
73
73
  this.pageState = new PageState();
74
74
  globalApp = this;
@@ -3,7 +3,7 @@ import React from 'react';
3
3
  /**
4
4
  * React utils
5
5
  */
6
- export declare namespace Utils {
6
+ export declare namespace ReactUtils {
7
7
  /**
8
8
  * Format input value
9
9
  * @param value Input value
@@ -16,6 +16,11 @@ export declare namespace Utils {
16
16
  * @returns History
17
17
  */
18
18
  function getMemoryHistory(initialPath?: string | null): History;
19
+ /**
20
+ * Get navigate function, works with memory history
21
+ * @returns NavigateFn
22
+ */
23
+ function getNavigateFn(): import("@reach/router").NavigateFn;
19
24
  /**
20
25
  * Is safe click
21
26
  * @param event Mouse event
@@ -1,9 +1,9 @@
1
- import { createHistory, createMemorySource } from '@reach/router';
1
+ import { createHistory, createMemorySource, navigate } from '@reach/router';
2
2
  /**
3
3
  * React utils
4
4
  */
5
- export var Utils;
6
- (function (Utils) {
5
+ export var ReactUtils;
6
+ (function (ReactUtils) {
7
7
  // Memory history
8
8
  // https://github.com/reach/router/issues/225
9
9
  let memoryHistory;
@@ -23,7 +23,7 @@ export var Utils;
23
23
  return value;
24
24
  return String(value);
25
25
  }
26
- Utils.formatInputValue = formatInputValue;
26
+ ReactUtils.formatInputValue = formatInputValue;
27
27
  /**
28
28
  * Get memory history
29
29
  * @param initialPath Initial path
@@ -35,7 +35,17 @@ export var Utils;
35
35
  }
36
36
  return memoryHistory;
37
37
  }
38
- Utils.getMemoryHistory = getMemoryHistory;
38
+ ReactUtils.getMemoryHistory = getMemoryHistory;
39
+ /**
40
+ * Get navigate function, works with memory history
41
+ * @returns NavigateFn
42
+ */
43
+ function getNavigateFn() {
44
+ if (memoryHistory == null)
45
+ return navigate;
46
+ return memoryHistory.navigate;
47
+ }
48
+ ReactUtils.getNavigateFn = getNavigateFn;
39
49
  /**
40
50
  * Is safe click
41
51
  * @param event Mouse event
@@ -61,7 +71,7 @@ export var Utils;
61
71
  }
62
72
  return true;
63
73
  }
64
- Utils.isSafeClick = isSafeClick;
74
+ ReactUtils.isSafeClick = isSafeClick;
65
75
  /**
66
76
  * Trigger input change event
67
77
  * @param input Form input
@@ -99,5 +109,5 @@ export var Utils;
99
109
  input.dispatchEvent(inputEvent);
100
110
  }
101
111
  }
102
- Utils.triggerChange = triggerChange;
103
- })(Utils || (Utils = {}));
112
+ ReactUtils.triggerChange = triggerChange;
113
+ })(ReactUtils || (ReactUtils = {}));
package/lib/index.d.ts CHANGED
@@ -6,9 +6,9 @@ export * from './app/IServiceUser';
6
6
  export * from './app/ISmartERPUser';
7
7
  export * from './app/Labels';
8
8
  export * from './app/ReactApp';
9
+ export * from './app/ReactUtils';
9
10
  export * from './app/RefreshTokenRQ';
10
11
  export * from './app/ServiceApp';
11
- export * from './app/Utils';
12
12
  export * from './components/GridColumn';
13
13
  export * from './components/GridLoader';
14
14
  export * from './components/ListItemReact';
package/lib/index.js CHANGED
@@ -7,9 +7,9 @@ export * from './app/IServiceUser';
7
7
  export * from './app/ISmartERPUser';
8
8
  export * from './app/Labels';
9
9
  export * from './app/ReactApp';
10
+ export * from './app/ReactUtils';
10
11
  export * from './app/RefreshTokenRQ';
11
12
  export * from './app/ServiceApp';
12
- export * from './app/Utils';
13
13
  // components
14
14
  export * from './components/GridColumn';
15
15
  export * from './components/GridLoader';
@@ -1,7 +1,7 @@
1
1
  import { IconButton, useTheme } from '@mui/material';
2
2
  import ArrowBackIcon from '@mui/icons-material/ArrowBack';
3
3
  import React from 'react';
4
- import { useNavigate } from '@reach/router';
4
+ import { ReactUtils } from '../app/ReactUtils';
5
5
  /**
6
6
  * BackButton
7
7
  * @param props Props
@@ -11,7 +11,7 @@ export function BackButton(props) {
11
11
  // Destruct
12
12
  const { color = 'primary', size = 'small', onClick, ...rest } = props;
13
13
  // Navigate
14
- const navigate = useNavigate();
14
+ const navigate = ReactUtils.getNavigateFn();
15
15
  // Theme
16
16
  const theme = useTheme();
17
17
  // Color
@@ -1,6 +1,6 @@
1
1
  import { Button } from '@mui/material';
2
- import { useNavigate } from '@reach/router';
3
2
  import React from 'react';
3
+ import { ReactUtils } from '../app/ReactUtils';
4
4
  /**
5
5
  * ButtonLink
6
6
  * @param props Props
@@ -10,7 +10,7 @@ export function ButtonLink(props) {
10
10
  // Destruct
11
11
  const { href, ...rest } = props;
12
12
  // Navigate
13
- const navigate = useNavigate();
13
+ const navigate = ReactUtils.getNavigateFn();
14
14
  const onClick = href.includes('://')
15
15
  ? () => window.open(href, '_blank')
16
16
  : () => navigate(href);
@@ -1,10 +1,10 @@
1
1
  import { Keyboard } from '@etsoo/shared';
2
2
  import { Autocomplete } from '@mui/material';
3
3
  import React from 'react';
4
- import { Utils } from '../app/Utils';
5
4
  import { Utils as SharedUtils } from '@etsoo/shared';
6
5
  import { InputField } from './InputField';
7
6
  import { SearchField } from './SearchField';
7
+ import { ReactUtils } from '../app/ReactUtils';
8
8
  /**
9
9
  * ComboBox
10
10
  * @param props Props
@@ -71,7 +71,7 @@ export function ComboBox(props) {
71
71
  const newValue = value != null ? `${Reflect.get(value, idField)}` : '';
72
72
  if (newValue !== input.value) {
73
73
  // Different value, trigger change event
74
- Utils.triggerChange(input, newValue, false);
74
+ ReactUtils.triggerChange(input, newValue, false);
75
75
  }
76
76
  }
77
77
  };
@@ -1,6 +1,6 @@
1
1
  import { IconButton } from '@mui/material';
2
- import { useNavigate } from '@reach/router';
3
2
  import React from 'react';
3
+ import { ReactUtils } from '../app/ReactUtils';
4
4
  /**
5
5
  * IconButtonLink
6
6
  * @param props Props
@@ -10,7 +10,7 @@ export function IconButtonLink(props) {
10
10
  // Destruct
11
11
  const { href, ...rest } = props;
12
12
  // Navigate
13
- const navigate = useNavigate();
13
+ const navigate = ReactUtils.getNavigateFn();
14
14
  // Layout
15
15
  return React.createElement(IconButton, { ...rest, onClick: () => navigate(href) });
16
16
  }
@@ -1,7 +1,7 @@
1
1
  import { Box, Stack } from '@mui/material';
2
2
  import React from 'react';
3
3
  import { Labels } from '../app/Labels';
4
- import { Utils } from '../app/Utils';
4
+ import { ReactUtils } from '../app/ReactUtils';
5
5
  import { GridDataGet } from '../components/GridLoader';
6
6
  import useCombinedRefs from '../uses/useCombinedRefs';
7
7
  import { useDimensions } from '../uses/useDimensions';
@@ -126,7 +126,7 @@ export function ResponsibleContainer(props) {
126
126
  return [
127
127
  React.createElement(Box, { className: "ListBox", sx: { height: heightLocal } },
128
128
  React.createElement(ScrollerListEx, { autoLoad: !hasFields, height: heightLocal, loadData: localLoadData, mRef: mRefs, onClick: (event, data) => quickAction &&
129
- Utils.isSafeClick(event) &&
129
+ ReactUtils.isSafeClick(event) &&
130
130
  quickAction(data), oRef: (element) => {
131
131
  if (element != null && elementReady)
132
132
  elementReady(element, false);
@@ -2,9 +2,9 @@ import { Button, Drawer, IconButton, Stack, useTheme } from '@mui/material';
2
2
  import React from 'react';
3
3
  import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
4
4
  import { useDimensions } from '../uses/useDimensions';
5
- import { Utils as AppUtils } from '../app/Utils';
6
5
  import { DomUtils } from '@etsoo/shared';
7
6
  import { Labels } from '../app/Labels';
7
+ import { ReactUtils } from '../app/ReactUtils';
8
8
  // Cached width attribute name
9
9
  const cachedWidthName = 'data-cached-width';
10
10
  // Reset form
@@ -20,7 +20,7 @@ const resetForm = (form) => {
20
20
  continue;
21
21
  // Ignore readOnly without data-reset=true inputs
22
22
  if (!input.readOnly || input.dataset.reset === 'true') {
23
- AppUtils.triggerChange(input, '', true);
23
+ ReactUtils.triggerChange(input, '', true);
24
24
  }
25
25
  continue;
26
26
  }
@@ -1,9 +1,9 @@
1
- import { Utils as AppUtils } from '../app/Utils';
2
1
  import { Checkbox, FormControl, InputLabel, ListItemText, MenuItem, OutlinedInput, Select } from '@mui/material';
3
2
  import React from 'react';
4
3
  import { MUGlobal } from './MUGlobal';
5
4
  import { ListItemRightIcon } from './ListItemRightIcon';
6
5
  import { Utils } from '@etsoo/shared';
6
+ import { ReactUtils } from '../app/ReactUtils';
7
7
  /**
8
8
  * Extended select component
9
9
  * @param props Props
@@ -65,7 +65,7 @@ export function SelectEx(props) {
65
65
  const input = (_a = divRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('input');
66
66
  if (input) {
67
67
  // Different value, trigger change event
68
- AppUtils.triggerChange(input, id, false);
68
+ ReactUtils.triggerChange(input, id, false);
69
69
  }
70
70
  }
71
71
  };
package/lib/mu/Tiplist.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
2
  import { Autocomplete } from '@mui/material';
3
3
  import React from 'react';
4
- import { Utils } from '../app/Utils';
4
+ import { ReactUtils } from '../app/ReactUtils';
5
5
  import { InputField } from './InputField';
6
6
  import { SearchField } from './SearchField';
7
7
  /**
@@ -75,7 +75,7 @@ export function Tiplist(props) {
75
75
  const input = inputRef.current;
76
76
  if (input && input.value !== '') {
77
77
  // Different value, trigger change event
78
- Utils.triggerChange(input, '', false);
78
+ ReactUtils.triggerChange(input, '', false);
79
79
  }
80
80
  if (states.options.length > 0) {
81
81
  // Reset options
@@ -106,7 +106,7 @@ export function Tiplist(props) {
106
106
  const newValue = (_a = DataTypes.getStringValue(value, idField)) !== null && _a !== void 0 ? _a : '';
107
107
  if (newValue !== input.value) {
108
108
  // Different value, trigger change event
109
- Utils.triggerChange(input, newValue, false);
109
+ ReactUtils.triggerChange(input, newValue, false);
110
110
  }
111
111
  }
112
112
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.5.15",
3
+ "version": "1.5.16",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -35,7 +35,7 @@ import {
35
35
  } from '../states/UserState';
36
36
  import { InputDialogProps } from './InputDialogProps';
37
37
  import { Labels } from './Labels';
38
- import { Utils } from './Utils';
38
+ import { ReactUtils } from './ReactUtils';
39
39
 
40
40
  /**
41
41
  * Global application
@@ -223,7 +223,7 @@ export class ReactApp<
223
223
  this.history =
224
224
  BridgeUtils.host == null
225
225
  ? undefined
226
- : Utils.getMemoryHistory(BridgeUtils.host.getStartUrl());
226
+ : ReactUtils.getMemoryHistory(BridgeUtils.host.getStartUrl());
227
227
 
228
228
  this.cultureState = new CultureState(settings.currentCulture);
229
229
  this.pageState = new PageState<P>();
@@ -1,10 +1,15 @@
1
- import { createHistory, createMemorySource, History } from '@reach/router';
1
+ import {
2
+ createHistory,
3
+ createMemorySource,
4
+ History,
5
+ navigate
6
+ } from '@reach/router';
2
7
  import React from 'react';
3
8
 
4
9
  /**
5
10
  * React utils
6
11
  */
7
- export namespace Utils {
12
+ export namespace ReactUtils {
8
13
  // Memory history
9
14
  // https://github.com/reach/router/issues/225
10
15
  let memoryHistory: History | null;
@@ -40,6 +45,15 @@ export namespace Utils {
40
45
  return memoryHistory;
41
46
  }
42
47
 
48
+ /**
49
+ * Get navigate function, works with memory history
50
+ * @returns NavigateFn
51
+ */
52
+ export function getNavigateFn() {
53
+ if (memoryHistory == null) return navigate;
54
+ return memoryHistory.navigate;
55
+ }
56
+
43
57
  /**
44
58
  * Is safe click
45
59
  * @param event Mouse event
package/src/index.ts CHANGED
@@ -7,9 +7,9 @@ export * from './app/IServiceUser';
7
7
  export * from './app/ISmartERPUser';
8
8
  export * from './app/Labels';
9
9
  export * from './app/ReactApp';
10
+ export * from './app/ReactUtils';
10
11
  export * from './app/RefreshTokenRQ';
11
12
  export * from './app/ServiceApp';
12
- export * from './app/Utils';
13
13
 
14
14
  // components
15
15
  export * from './components/GridColumn';
@@ -1,7 +1,7 @@
1
1
  import { IconButton, IconButtonProps, useTheme } from '@mui/material';
2
2
  import ArrowBackIcon from '@mui/icons-material/ArrowBack';
3
3
  import React from 'react';
4
- import { useNavigate } from '@reach/router';
4
+ import { ReactUtils } from '../app/ReactUtils';
5
5
 
6
6
  /**
7
7
  * BackButton props
@@ -18,7 +18,7 @@ export function BackButton(props: BackButtonProps) {
18
18
  const { color = 'primary', size = 'small', onClick, ...rest } = props;
19
19
 
20
20
  // Navigate
21
- const navigate = useNavigate();
21
+ const navigate = ReactUtils.getNavigateFn();
22
22
 
23
23
  // Theme
24
24
  const theme = useTheme();
@@ -1,6 +1,6 @@
1
1
  import { Button, ButtonProps } from '@mui/material';
2
- import { useNavigate } from '@reach/router';
3
2
  import React from 'react';
3
+ import { ReactUtils } from '../app/ReactUtils';
4
4
 
5
5
  /**
6
6
  * ButtonLink props
@@ -22,7 +22,8 @@ export function ButtonLink(props: ButtonLinkProps) {
22
22
  const { href, ...rest } = props;
23
23
 
24
24
  // Navigate
25
- const navigate = useNavigate();
25
+ const navigate = ReactUtils.getNavigateFn();
26
+
26
27
  const onClick = href.includes('://')
27
28
  ? () => window.open(href, '_blank')
28
29
  : () => navigate(href);
@@ -2,11 +2,11 @@ import { IdLabelDto } from '@etsoo/appscript';
2
2
  import { Keyboard } from '@etsoo/shared';
3
3
  import { Autocomplete, AutocompleteRenderInputParams } from '@mui/material';
4
4
  import React from 'react';
5
- import { Utils } from '../app/Utils';
6
5
  import { Utils as SharedUtils } from '@etsoo/shared';
7
6
  import { AutocompleteExtendedProps } from './AutocompleteExtendedProps';
8
7
  import { InputField } from './InputField';
9
8
  import { SearchField } from './SearchField';
9
+ import { ReactUtils } from '../app/ReactUtils';
10
10
 
11
11
  /**
12
12
  * ComboBox props
@@ -152,7 +152,7 @@ export function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>) {
152
152
 
153
153
  if (newValue !== input.value) {
154
154
  // Different value, trigger change event
155
- Utils.triggerChange(input, newValue, false);
155
+ ReactUtils.triggerChange(input, newValue, false);
156
156
  }
157
157
  }
158
158
  };
@@ -1,6 +1,6 @@
1
1
  import { IconButton, IconButtonProps } from '@mui/material';
2
- import { useNavigate } from '@reach/router';
3
2
  import React from 'react';
3
+ import { ReactUtils } from '../app/ReactUtils';
4
4
 
5
5
  /**
6
6
  * IconButtonLink props
@@ -22,7 +22,7 @@ export function IconButtonLink(props: IconButtonLinkProps) {
22
22
  const { href, ...rest } = props;
23
23
 
24
24
  // Navigate
25
- const navigate = useNavigate();
25
+ const navigate = ReactUtils.getNavigateFn();
26
26
 
27
27
  // Layout
28
28
  return <IconButton {...rest} onClick={() => navigate(href)} />;
@@ -3,7 +3,7 @@ import { Box, Stack, SxProps, Theme } from '@mui/material';
3
3
  import React from 'react';
4
4
  import { ListChildComponentProps } from 'react-window';
5
5
  import { Labels } from '../app/Labels';
6
- import { Utils } from '../app/Utils';
6
+ import { ReactUtils } from '../app/ReactUtils';
7
7
  import { GridColumn } from '../components/GridColumn';
8
8
  import {
9
9
  GridDataGet,
@@ -326,7 +326,7 @@ export function ResponsibleContainer<
326
326
  mRef={mRefs}
327
327
  onClick={(event, data) =>
328
328
  quickAction &&
329
- Utils.isSafeClick(event) &&
329
+ ReactUtils.isSafeClick(event) &&
330
330
  quickAction(data)
331
331
  }
332
332
  oRef={(element) => {
@@ -2,9 +2,9 @@ import { Button, Drawer, IconButton, Stack, useTheme } from '@mui/material';
2
2
  import React from 'react';
3
3
  import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
4
4
  import { useDimensions } from '../uses/useDimensions';
5
- import { Utils as AppUtils } from '../app/Utils';
6
5
  import { DomUtils } from '@etsoo/shared';
7
6
  import { Labels } from '../app/Labels';
7
+ import { ReactUtils } from '../app/ReactUtils';
8
8
 
9
9
  /**
10
10
  * Search bar props
@@ -48,7 +48,7 @@ const resetForm = (form: HTMLFormElement) => {
48
48
 
49
49
  // Ignore readOnly without data-reset=true inputs
50
50
  if (!input.readOnly || input.dataset.reset === 'true') {
51
- AppUtils.triggerChange(input, '', true);
51
+ ReactUtils.triggerChange(input, '', true);
52
52
  }
53
53
  continue;
54
54
  }
@@ -1,4 +1,3 @@
1
- import { Utils as AppUtils } from '../app/Utils';
2
1
  import {
3
2
  Checkbox,
4
3
  FormControl,
@@ -15,6 +14,7 @@ import { MUGlobal } from './MUGlobal';
15
14
  import { IdLabelDto } from '@etsoo/appscript';
16
15
  import { ListItemRightIcon } from './ListItemRightIcon';
17
16
  import { Utils } from '@etsoo/shared';
17
+ import { ReactUtils } from '../app/ReactUtils';
18
18
 
19
19
  /**
20
20
  * Extended select component props
@@ -145,7 +145,7 @@ export function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>) {
145
145
  const input = divRef.current?.querySelector('input');
146
146
  if (input) {
147
147
  // Different value, trigger change event
148
- AppUtils.triggerChange(input, id as string, false);
148
+ ReactUtils.triggerChange(input, id as string, false);
149
149
  }
150
150
  }
151
151
  };
@@ -2,7 +2,7 @@ import { IdLabelDto } from '@etsoo/appscript';
2
2
  import { DataTypes } from '@etsoo/shared';
3
3
  import { Autocomplete, AutocompleteRenderInputParams } from '@mui/material';
4
4
  import React from 'react';
5
- import { Utils } from '../app/Utils';
5
+ import { ReactUtils } from '../app/ReactUtils';
6
6
  import { AutocompleteExtendedProps } from './AutocompleteExtendedProps';
7
7
  import { InputField } from './InputField';
8
8
  import { SearchField } from './SearchField';
@@ -152,7 +152,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
152
152
 
153
153
  if (input && input.value !== '') {
154
154
  // Different value, trigger change event
155
- Utils.triggerChange(input, '', false);
155
+ ReactUtils.triggerChange(input, '', false);
156
156
  }
157
157
 
158
158
  if (states.options.length > 0) {
@@ -186,7 +186,7 @@ export function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>) {
186
186
  const newValue = DataTypes.getStringValue(value, idField) ?? '';
187
187
  if (newValue !== input.value) {
188
188
  // Different value, trigger change event
189
- Utils.triggerChange(input, newValue, false);
189
+ ReactUtils.triggerChange(input, newValue, false);
190
190
  }
191
191
  }
192
192
  };