@etsoo/materialui 1.0.79 → 1.0.81

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.
@@ -0,0 +1,30 @@
1
+ /// <reference types="react" />
2
+ import { AddressRegionDb, RegionsRQ } from '@etsoo/appscript';
3
+ import { DataTypes } from '@etsoo/shared';
4
+ import { TiplistProps } from './Tiplist';
5
+ /**
6
+ * Country list props
7
+ */
8
+ export type CountryListProps = Omit<DataTypes.Optional<TiplistProps<AddressRegionDb, 'id'>, 'name'>, 'loadData'> & {
9
+ /**
10
+ * Load data
11
+ * @param rq Request data
12
+ * @returns Result
13
+ */
14
+ loadData: (rq: RegionsRQ) => Promise<AddressRegionDb[] | undefined>;
15
+ /**
16
+ * Load favored country ids
17
+ * @returns Result
18
+ */
19
+ loadFavoredIds?: () => Promise<string[]>;
20
+ /**
21
+ * Max items to display
22
+ */
23
+ items?: number;
24
+ };
25
+ /**
26
+ * Country list
27
+ * @param props Props
28
+ * @returns Component
29
+ */
30
+ export declare function CountryList(props: CountryListProps): JSX.Element;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Tiplist } from './Tiplist';
3
+ /**
4
+ * Country list
5
+ * @param props Props
6
+ * @returns Component
7
+ */
8
+ export function CountryList(props) {
9
+ // Destruct
10
+ const { items = 16, loadData, loadFavoredIds, name = 'countryId', ...rest } = props;
11
+ // Ref
12
+ const favoredIds = React.useRef([]);
13
+ // Ready
14
+ React.useEffect(() => {
15
+ if (loadFavoredIds)
16
+ loadFavoredIds().then((ids) => {
17
+ favoredIds.current = ids;
18
+ });
19
+ }, [loadFavoredIds]);
20
+ // Layout
21
+ return (React.createElement(Tiplist, { name: name, loadData: (keyword, id) => loadData({ id, keyword, favoredIds: favoredIds.current, items }), ...rest }));
22
+ }
@@ -17,7 +17,7 @@ export type DataStepsProps<T extends object> = Omit<TextFieldProps, 'InputProps'
17
17
  /**
18
18
  * JSON value
19
19
  */
20
- jsonValue?: string;
20
+ jsonValue: T;
21
21
  /**
22
22
  * Value formatter
23
23
  */
package/lib/DataSteps.js CHANGED
@@ -25,14 +25,12 @@ export function DataSteps(props) {
25
25
  (_a = InputLabelProps.shrink) !== null && _a !== void 0 ? _a : (InputLabelProps.shrink = MUGlobal.searchFieldShrink);
26
26
  // Current index
27
27
  const indexRef = React.useRef(-1);
28
- // Current data
29
- const dataRef = React.useRef({});
30
28
  // Current value
31
29
  const [localValue, setLocalValue] = React.useState(value);
32
30
  // Get step
33
31
  const showStep = (index) => {
34
32
  indexRef.current = index;
35
- const [{ callback, ...rest }, more] = steps(index, dataRef.current);
33
+ const [{ callback, ...rest }, more] = steps(index, jsonValue);
36
34
  app.showInputDialog({
37
35
  ...rest,
38
36
  buttons: (n, callback) => (React.createElement(HBox, { paddingLeft: 2, paddingRight: 2, paddingBottom: 2, gap: 2, justifyContent: "space-between" },
@@ -49,10 +47,9 @@ export function DataSteps(props) {
49
47
  const result = await callback(event);
50
48
  if (!result)
51
49
  return;
52
- const value = dataRef.current;
53
- setLocalValue(valueFormatter(value));
50
+ setLocalValue(valueFormatter(jsonValue));
54
51
  if (onValueChange)
55
- onValueChange(value);
52
+ onValueChange(jsonValue);
56
53
  } }, labels.submit)))),
57
54
  callback: (form) => {
58
55
  if (form == null)
@@ -69,10 +66,7 @@ export function DataSteps(props) {
69
66
  event.preventDefault();
70
67
  };
71
68
  React.useEffect(() => {
72
- if (jsonValue) {
73
- dataRef.current = JSON.parse(jsonValue);
74
- setLocalValue(valueFormatter(dataRef.current));
75
- }
69
+ setLocalValue(valueFormatter(jsonValue));
76
70
  }, [jsonValue]);
77
71
  return (React.createElement(TextField, { InputLabelProps: InputLabelProps, inputProps: { style: { cursor: 'pointer' } }, InputProps: {
78
72
  onKeyDown: (event) => {
package/lib/Tiplist.js CHANGED
@@ -153,5 +153,5 @@ export function Tiplist(props) {
153
153
  open: false,
154
154
  ...(!states.value && { options: [] })
155
155
  });
156
- }, loading: states.loading, sx: sx, renderInput: (params) => search ? (React.createElement(SearchField, { onChange: changeHandle, ...params, readOnly: readOnly, label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })) : (React.createElement(InputField, { onChange: changeHandle, ...addReadOnly(params), label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })), isOptionEqualToValue: (option, value) => option[idField] === value[idField], ...rest })));
156
+ }, loading: states.loading, sx: sx, renderInput: (params) => search ? (React.createElement(SearchField, { onChange: changeHandle, ...addReadOnly(params), readOnly: readOnly, label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })) : (React.createElement(InputField, { onChange: changeHandle, ...addReadOnly(params), label: label, name: name + 'Input', margin: inputMargin, variant: inputVariant, required: inputRequired, autoComplete: inputAutoComplete, error: inputError, helperText: inputHelperText })), isOptionEqualToValue: (option, value) => option[idField] === value[idField], ...rest })));
157
157
  }
package/lib/index.d.ts CHANGED
@@ -29,6 +29,7 @@ export * from './BridgeCloseButton';
29
29
  export * from './ButtonLink';
30
30
  export * from './ComboBox';
31
31
  export * from './CountdownButton';
32
+ export * from './CountryList';
32
33
  export * from './CustomFabProps';
33
34
  export * from './DataGridEx';
34
35
  export * from './DataGridRenderers';
package/lib/index.js CHANGED
@@ -29,6 +29,7 @@ export * from './BridgeCloseButton';
29
29
  export * from './ButtonLink';
30
30
  export * from './ComboBox';
31
31
  export * from './CountdownButton';
32
+ export * from './CountryList';
32
33
  export * from './CustomFabProps';
33
34
  export * from './DataGridEx';
34
35
  export * from './DataGridRenderers';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.0.79",
3
+ "version": "1.0.81",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -0,0 +1,68 @@
1
+ import { AddressRegionDb, RegionsRQ } from '@etsoo/appscript';
2
+ import { DataTypes } from '@etsoo/shared';
3
+ import React from 'react';
4
+ import { Tiplist, TiplistProps } from './Tiplist';
5
+
6
+ /**
7
+ * Country list props
8
+ */
9
+ export type CountryListProps = Omit<
10
+ DataTypes.Optional<TiplistProps<AddressRegionDb, 'id'>, 'name'>,
11
+ 'loadData'
12
+ > & {
13
+ /**
14
+ * Load data
15
+ * @param rq Request data
16
+ * @returns Result
17
+ */
18
+ loadData: (rq: RegionsRQ) => Promise<AddressRegionDb[] | undefined>;
19
+
20
+ /**
21
+ * Load favored country ids
22
+ * @returns Result
23
+ */
24
+ loadFavoredIds?: () => Promise<string[]>;
25
+
26
+ /**
27
+ * Max items to display
28
+ */
29
+ items?: number;
30
+ };
31
+
32
+ /**
33
+ * Country list
34
+ * @param props Props
35
+ * @returns Component
36
+ */
37
+ export function CountryList(props: CountryListProps) {
38
+ // Destruct
39
+ const {
40
+ items = 16,
41
+ loadData,
42
+ loadFavoredIds,
43
+ name = 'countryId',
44
+ ...rest
45
+ } = props;
46
+
47
+ // Ref
48
+ const favoredIds = React.useRef<string[]>([]);
49
+
50
+ // Ready
51
+ React.useEffect(() => {
52
+ if (loadFavoredIds)
53
+ loadFavoredIds().then((ids) => {
54
+ favoredIds.current = ids;
55
+ });
56
+ }, [loadFavoredIds]);
57
+
58
+ // Layout
59
+ return (
60
+ <Tiplist<AddressRegionDb, 'id'>
61
+ name={name}
62
+ loadData={(keyword, id) =>
63
+ loadData({ id, keyword, favoredIds: favoredIds.current, items })
64
+ }
65
+ {...rest}
66
+ />
67
+ );
68
+ }
package/src/DataSteps.tsx CHANGED
@@ -36,7 +36,7 @@ export type DataStepsProps<T extends object> = Omit<
36
36
  /**
37
37
  * JSON value
38
38
  */
39
- jsonValue?: string;
39
+ jsonValue: T;
40
40
 
41
41
  /**
42
42
  * Value formatter
@@ -83,16 +83,13 @@ export function DataSteps<T extends object>(props: DataStepsProps<T>) {
83
83
  // Current index
84
84
  const indexRef = React.useRef<number>(-1);
85
85
 
86
- // Current data
87
- const dataRef = React.useRef({} as T);
88
-
89
86
  // Current value
90
87
  const [localValue, setLocalValue] = React.useState(value);
91
88
 
92
89
  // Get step
93
90
  const showStep = (index: number) => {
94
91
  indexRef.current = index;
95
- const [{ callback, ...rest }, more] = steps(index, dataRef.current);
92
+ const [{ callback, ...rest }, more] = steps(index, jsonValue);
96
93
 
97
94
  app.showInputDialog({
98
95
  ...rest,
@@ -145,10 +142,9 @@ export function DataSteps<T extends object>(props: DataStepsProps<T>) {
145
142
  const result = await callback(event);
146
143
  if (!result) return;
147
144
 
148
- const value = dataRef.current;
149
- setLocalValue(valueFormatter(value));
145
+ setLocalValue(valueFormatter(jsonValue));
150
146
 
151
- if (onValueChange) onValueChange(value);
147
+ if (onValueChange) onValueChange(jsonValue);
152
148
  }}
153
149
  >
154
150
  {labels.submit}
@@ -172,10 +168,7 @@ export function DataSteps<T extends object>(props: DataStepsProps<T>) {
172
168
  };
173
169
 
174
170
  React.useEffect(() => {
175
- if (jsonValue) {
176
- dataRef.current = JSON.parse(jsonValue);
177
- setLocalValue(valueFormatter(dataRef.current));
178
- }
171
+ setLocalValue(valueFormatter(jsonValue));
179
172
  }, [jsonValue]);
180
173
 
181
174
  return (
package/src/Tiplist.tsx CHANGED
@@ -267,7 +267,7 @@ export function Tiplist<
267
267
  search ? (
268
268
  <SearchField
269
269
  onChange={changeHandle}
270
- {...params}
270
+ {...addReadOnly(params)}
271
271
  readOnly={readOnly}
272
272
  label={label}
273
273
  name={name + 'Input'}
package/src/index.ts CHANGED
@@ -32,6 +32,7 @@ export * from './BridgeCloseButton';
32
32
  export * from './ButtonLink';
33
33
  export * from './ComboBox';
34
34
  export * from './CountdownButton';
35
+ export * from './CountryList';
35
36
  export * from './CustomFabProps';
36
37
  export * from './DataGridEx';
37
38
  export * from './DataGridRenderers';