@etsoo/react 1.5.74 → 1.5.77

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,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import React from 'react';
2
3
  import { Align, GridChildComponentProps, VariableSizeGridProps } from 'react-window';
3
4
  import { GridMethodRef } from '../mu/GridMethodRef';
@@ -15,7 +16,7 @@ export interface ScrollerGridItemRendererProps<T> extends Omit<GridChildComponen
15
16
  /**
16
17
  * Scroller vertical grid props
17
18
  */
18
- export interface ScrollerGridProps<T> extends GridLoader<T>, Omit<VariableSizeGridProps<T>, 'children' | 'rowCount' | 'rowHeight' | 'ref'> {
19
+ export interface ScrollerGridProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends GridLoader<T>, Omit<VariableSizeGridProps<T>, 'children' | 'rowCount' | 'rowHeight' | 'ref'> {
19
20
  /**
20
21
  * Default order by asc
21
22
  * @default true
@@ -33,7 +34,7 @@ export interface ScrollerGridProps<T> extends GridLoader<T>, Omit<VariableSizeGr
33
34
  * Id field
34
35
  * @default id
35
36
  */
36
- idField?: string & keyof T;
37
+ idField?: D;
37
38
  /**
38
39
  * Item renderer
39
40
  */
@@ -109,4 +110,4 @@ export interface ScrollerGridForwardRef extends GridMethodRef {
109
110
  * @param props Props
110
111
  * @returns Component
111
112
  */
112
- export declare const ScrollerGrid: <T extends Record<string, unknown>>(props: ScrollerGridProps<T>) => JSX.Element;
113
+ export declare const ScrollerGrid: <T extends Record<string, unknown>>(props: ScrollerGridProps<T, DataTypes.Keys<T, string | number>>) => JSX.Element;
@@ -59,5 +59,5 @@ export interface ScrollerListForwardRef extends GridMethodRef, ScrollerListRef {
59
59
  * @param props Props
60
60
  * @returns Component
61
61
  */
62
- export declare const ScrollerList: <T extends Record<string, any>>(props: ScrollerListProps<T>) => JSX.Element;
62
+ export declare const ScrollerList: <T extends {}>(props: ScrollerListProps<T>) => JSX.Element;
63
63
  export {};
@@ -4,15 +4,15 @@ import { ChangeEventHandler } from 'react';
4
4
  /**
5
5
  * Autocomplete extended props
6
6
  */
7
- export interface AutocompleteExtendedProps<T extends Record<string, unknown>> extends Omit<AutocompleteProps<T, undefined, false, false>, 'renderInput' | 'options'> {
7
+ export interface AutocompleteExtendedProps<T extends {}, D extends DataTypes.Keys<T>> extends Omit<AutocompleteProps<T, undefined, false, false>, 'renderInput' | 'options'> {
8
8
  /**
9
9
  * Id field, default is id
10
10
  */
11
- idField?: string & keyof T;
11
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
12
12
  /**
13
13
  * Id value
14
14
  */
15
- idValue?: DataTypes.IdType;
15
+ idValue?: T[D];
16
16
  /**
17
17
  * Autocomplete for the input
18
18
  */
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { IdLabelDto } from '@etsoo/appscript';
2
+ import { DataTypes } from '@etsoo/shared';
3
3
  import { AutocompleteExtendedProps } from './AutocompleteExtendedProps';
4
4
  /**
5
5
  * ComboBox props
6
6
  */
7
- export interface ComboBoxProps<T extends {}> extends AutocompleteExtendedProps<T> {
7
+ export interface ComboBoxProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends AutocompleteExtendedProps<T, D> {
8
8
  /**
9
9
  * Auto add blank item
10
10
  */
@@ -16,7 +16,7 @@ export interface ComboBoxProps<T extends {}> extends AutocompleteExtendedProps<T
16
16
  /**
17
17
  * Label field
18
18
  */
19
- labelField?: string & keyof T;
19
+ labelField: T extends DataTypes.IdLabelItem ? D | undefined : D;
20
20
  /**
21
21
  * Load data callback
22
22
  */
@@ -35,4 +35,4 @@ export interface ComboBoxProps<T extends {}> extends AutocompleteExtendedProps<T
35
35
  * @param props Props
36
36
  * @returns Component
37
37
  */
38
- export declare function ComboBox<T extends {} = IdLabelDto>(props: ComboBoxProps<T>): JSX.Element;
38
+ export declare function ComboBox<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: ComboBoxProps<T, D>): JSX.Element;
@@ -12,7 +12,7 @@ import { ReactUtils } from '../app/ReactUtils';
12
12
  */
13
13
  export function ComboBox(props) {
14
14
  // Destruct
15
- const { search = false, autoAddBlankItem = search, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, getOptionLabel = (option) => String(Reflect.get(option, labelField)), sx = { minWidth: '150px' }, ...rest } = props;
15
+ const { search = false, autoAddBlankItem = search, idField = 'id', idValue, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputVariant, defaultValue, label, labelField = 'label', loadData, onLoadData, name, inputAutoComplete = 'off', options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, getOptionLabel = (option) => `${option[labelField]}`, sx = { minWidth: '150px' }, ...rest } = props;
16
16
  // Value input ref
17
17
  const inputRef = React.createRef();
18
18
  // Options state
@@ -27,7 +27,7 @@ export function ComboBox(props) {
27
27
  }, [JSON.stringify(options), propertyWay]);
28
28
  // Local default value
29
29
  let localValue = idValue != null
30
- ? localOptions.find((o) => Reflect.get(o, idField) === idValue)
30
+ ? localOptions.find((o) => o[idField] === idValue)
31
31
  : defaultValue !== null && defaultValue !== void 0 ? defaultValue : value;
32
32
  if (localValue === undefined)
33
33
  localValue = null;
@@ -36,7 +36,7 @@ export function ComboBox(props) {
36
36
  const [stateValue, setStateValue] = React.useState(null);
37
37
  // Current id value
38
38
  // One time calculation for input's default value (uncontrolled)
39
- const localIdValue = stateValue && Reflect.get(stateValue, idField);
39
+ const localIdValue = stateValue && stateValue[idField];
40
40
  React.useEffect(() => {
41
41
  if (localValue != null)
42
42
  setStateValue(localValue);
@@ -68,7 +68,7 @@ export function ComboBox(props) {
68
68
  const input = inputRef.current;
69
69
  if (input) {
70
70
  // Update value
71
- const newValue = value != null ? `${Reflect.get(value, idField)}` : '';
71
+ const newValue = value != null ? `${value[idField]}` : '';
72
72
  if (newValue !== input.value) {
73
73
  // Different value, trigger change event
74
74
  ReactUtils.triggerChange(input, newValue, false);
@@ -97,8 +97,8 @@ export function ComboBox(props) {
97
97
  }, []);
98
98
  // Layout
99
99
  return (React.createElement("div", null,
100
- React.createElement("input", { ref: inputRef, "data-reset": "true", type: "text", style: { display: 'none' }, name: name, value: localIdValue !== null && localIdValue !== void 0 ? localIdValue : '', readOnly: true, onChange: inputOnChange }),
101
- React.createElement(Autocomplete, { value: stateValue, getOptionLabel: getOptionLabel, isOptionEqualToValue: (option, value) => Reflect.get(option, idField) === Reflect.get(value, idField), onChange: (event, value, reason, details) => {
100
+ React.createElement("input", { ref: inputRef, "data-reset": "true", type: "text", style: { display: 'none' }, name: name, value: `${localIdValue !== null && localIdValue !== void 0 ? localIdValue : ''}`, readOnly: true, onChange: inputOnChange }),
101
+ React.createElement(Autocomplete, { value: stateValue, getOptionLabel: getOptionLabel, isOptionEqualToValue: (option, value) => option[idField] === value[idField], onChange: (event, value, reason, details) => {
102
102
  // Set value
103
103
  setInputValue(value);
104
104
  // Custom
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import React from 'react';
2
3
  import { GridColumn } from '../components/GridColumn';
3
4
  import { GridLoaderStates } from '../components/GridLoader';
@@ -6,7 +7,7 @@ import { MouseEventWithDataHandler } from './MUGlobal';
6
7
  /**
7
8
  * Footer item renderer props
8
9
  */
9
- export interface DataGridExFooterItemRendererProps<T extends Record<string, any>> {
10
+ export interface DataGridExFooterItemRendererProps<T extends {}> {
10
11
  column: GridColumn<T>;
11
12
  index: number;
12
13
  states: GridLoaderStates<T>;
@@ -16,7 +17,7 @@ export interface DataGridExFooterItemRendererProps<T extends Record<string, any>
16
17
  /**
17
18
  * Extended DataGrid with VariableSizeGrid props
18
19
  */
19
- export interface DataGridExProps<T extends Record<string, any>> extends Omit<ScrollerGridProps<T>, 'itemRenderer' | 'columnCount' | 'columnWidth' | 'width'> {
20
+ export interface DataGridExProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<ScrollerGridProps<T, D>, 'itemRenderer' | 'columnCount' | 'columnWidth' | 'width'> {
20
21
  /**
21
22
  * Alternating colors for odd/even rows
22
23
  */
@@ -92,4 +93,4 @@ export declare function DataGridExCalColumns<T>(columns: GridColumn<T>[]): {
92
93
  * @param props Props
93
94
  * @returns Component
94
95
  */
95
- export declare function DataGridEx<T extends Record<string, any>>(props: DataGridExProps<T>): JSX.Element;
96
+ export declare function DataGridEx<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: DataGridExProps<T, D>): JSX.Element;
@@ -1,15 +1,14 @@
1
1
  /// <reference types="react" />
2
- import { IdLabelDto } from '@etsoo/appscript';
3
2
  import { DataTypes } from '@etsoo/shared';
4
3
  import { FormControlProps } from '@mui/material';
5
4
  /**
6
5
  * OptionGroup props
7
6
  */
8
- export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D extends DataTypes.IdType = string> extends Omit<FormControlProps<'fieldset'>, 'defaultValue'> {
7
+ export interface OptionGroupProps<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<FormControlProps<'fieldset'>, 'defaultValue'> {
9
8
  /**
10
9
  * Default value
11
10
  */
12
- defaultValue?: D | D[];
11
+ defaultValue?: T[D] | T[D][];
13
12
  /**
14
13
  * Get option label function
15
14
  */
@@ -17,7 +16,7 @@ export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D
17
16
  /**
18
17
  * Id field, default is id
19
18
  */
20
- idField?: string & keyof T;
19
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
21
20
  /**
22
21
  * Label
23
22
  */
@@ -25,7 +24,7 @@ export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D
25
24
  /**
26
25
  * Label field, default is label
27
26
  */
28
- labelField?: string & keyof T;
27
+ labelField: T extends DataTypes.IdLabelItem ? D | undefined : D;
29
28
  /**
30
29
  * Multiple choose item
31
30
  */
@@ -37,7 +36,7 @@ export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D
37
36
  /**
38
37
  * On value change handler
39
38
  */
40
- onValueChange?: (value: D | D[] | undefined) => void;
39
+ onValueChange?: (value: T[D] | T[D][] | undefined) => void;
41
40
  /**
42
41
  * Array of options.
43
42
  */
@@ -56,4 +55,4 @@ export interface OptionGroupProps<T extends Record<string, any> = IdLabelDto, D
56
55
  * @param props Props
57
56
  * @returns Component
58
57
  */
59
- export declare function OptionGroup<T extends Record<string, unknown> = IdLabelDto, D extends DataTypes.IdType = string>(props: OptionGroupProps<T, D>): JSX.Element;
58
+ export declare function OptionGroup<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: OptionGroupProps<T, D>): JSX.Element;
@@ -10,7 +10,7 @@ import { ScrollerListExInnerItemRendererProps, ScrollerListExItemSize } from './
10
10
  /**
11
11
  * ResponsibleContainer props
12
12
  */
13
- export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate> extends Omit<DataGridExProps<T>, 'height' | 'itemKey' | 'loadData' | 'mRef' | 'onScroll' | 'onItemsRendered'> {
13
+ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<DataGridExProps<T, D>, 'height' | 'itemKey' | 'loadData' | 'mRef' | 'onScroll' | 'onItemsRendered'> {
14
14
  /**
15
15
  * Height will be deducted
16
16
  * @param height Current calcuated height
@@ -86,4 +86,4 @@ export interface ResponsibleContainerProps<T extends {}, F extends DataTypes.Bas
86
86
  * @param props Props
87
87
  * @returns Layout
88
88
  */
89
- export declare function ResponsibleContainer<T extends {}, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate>(props: ResponsibleContainerProps<T, F>): JSX.Element;
89
+ export declare function ResponsibleContainer<T extends {}, F extends DataTypes.BasicTemplate = DataTypes.BasicTemplate, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: ResponsibleContainerProps<T, F, D>): JSX.Element;
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import React from 'react';
2
3
  import { ListChildComponentProps } from 'react-window';
3
4
  import { ScrollerListProps } from '../components/ScrollerList';
@@ -33,7 +34,7 @@ export declare type ScrollerListExItemSize = ((index: number) => [number, number
33
34
  /**
34
35
  * Extended ScrollerList Props
35
36
  */
36
- export interface ScrollerListExProps<T> extends Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> {
37
+ export interface ScrollerListExProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<ScrollerListProps<T>, 'itemRenderer' | 'itemSize'> {
37
38
  /**
38
39
  * Alternating colors for odd/even rows
39
40
  */
@@ -41,7 +42,7 @@ export interface ScrollerListExProps<T> extends Omit<ScrollerListProps<T>, 'item
41
42
  /**
42
43
  * Id field
43
44
  */
44
- idField?: string & keyof T;
45
+ idField?: D;
45
46
  /**
46
47
  * Inner item renderer
47
48
  */
@@ -76,4 +77,4 @@ export interface ScrollerListExProps<T> extends Omit<ScrollerListProps<T>, 'item
76
77
  * @param props Props
77
78
  * @returns Component
78
79
  */
79
- export declare function ScrollerListEx<T extends Record<string, unknown>>(props: ScrollerListExProps<T>): JSX.Element;
80
+ export declare function ScrollerListEx<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: ScrollerListExProps<T, D>): JSX.Element;
@@ -112,7 +112,7 @@ export function ScrollerListEx(props) {
112
112
  return selected;
113
113
  };
114
114
  // Destruct
115
- const { alternatingColors = [undefined, undefined], className, idField = 'id', innerItemRenderer, itemSize, itemKey = (index, data) => { var _a; return (_a = DataTypes.getValue(data, idField)) !== null && _a !== void 0 ? _a : index; }, itemRenderer = (itemProps) => {
115
+ const { alternatingColors = [undefined, undefined], className, idField = 'id', innerItemRenderer, itemSize, itemKey = (index, data) => { var _a; return (_a = DataTypes.getIdValue1(data, idField)) !== null && _a !== void 0 ? _a : index; }, itemRenderer = (itemProps) => {
116
116
  const [itemHeight, space, margins] = calculateItemSize(itemProps.index);
117
117
  return defaultItemRenderer({
118
118
  itemHeight,
@@ -1,5 +1,4 @@
1
1
  /// <reference types="react" />
2
- import { IdLabelDto } from '@etsoo/appscript';
3
2
  import { DataTypes } from '@etsoo/shared';
4
3
  import { OptionGroupProps } from './OptionGroup';
5
4
  /**
@@ -7,4 +6,4 @@ import { OptionGroupProps } from './OptionGroup';
7
6
  * @param props Props
8
7
  * @returns Component
9
8
  */
10
- export declare function SearchOptionGroup<T extends Record<string, any> = IdLabelDto, D extends DataTypes.IdType = string>(props: OptionGroupProps<T, D>): JSX.Element;
9
+ export declare function SearchOptionGroup<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: OptionGroupProps<T, D>): JSX.Element;
@@ -1,10 +1,10 @@
1
1
  /// <reference types="react" />
2
- import { IdLabelDto } from '@etsoo/appscript';
2
+ import { DataTypes } from '@etsoo/shared';
3
3
  import { SelectExProps } from './SelectEx';
4
4
  /**
5
5
  * SelectBool props
6
6
  */
7
- export interface SelectBoolProps extends Omit<SelectExProps<IdLabelDto<string>>, 'options' | 'loadData'> {
7
+ export interface SelectBoolProps extends Omit<SelectExProps<DataTypes.IdLabelItem<string>>, 'options' | 'loadData'> {
8
8
  }
9
9
  /**
10
10
  * SelectBool (yes/no)
@@ -18,5 +18,5 @@ export function SelectBool(props) {
18
18
  if (autoAddBlankItem)
19
19
  Utils.addBlankItem(options);
20
20
  // Layout
21
- return React.createElement(SelectEx, { options: options, search: search, ...rest });
21
+ return (React.createElement(SelectEx, { options: options, search: search, ...rest }));
22
22
  }
@@ -1,26 +1,26 @@
1
1
  import { SelectProps } from '@mui/material';
2
2
  import React from 'react';
3
- import { IdLabelDto } from '@etsoo/appscript';
3
+ import { DataTypes } from '@etsoo/shared';
4
4
  /**
5
5
  * Extended select component props
6
6
  */
7
- export interface SelectExProps<T extends {}> extends Omit<SelectProps, 'labelId' | 'input' | 'native'> {
7
+ export interface SelectExProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends Omit<SelectProps, 'labelId' | 'input' | 'native'> {
8
8
  /**
9
9
  * Auto add blank item
10
10
  */
11
11
  autoAddBlankItem?: boolean;
12
12
  /**
13
- * Id field, default is id
13
+ * Id field
14
14
  */
15
- idField?: string & keyof T;
15
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
16
16
  /**
17
17
  * Item icon renderer
18
18
  */
19
19
  itemIconRenderer?: (id: unknown) => React.ReactNode;
20
20
  /**
21
- * Label field, default is label
21
+ * Label field
22
22
  */
23
- labelField?: ((option: T) => string) | (string & keyof T);
23
+ labelField: ((option: T) => string) | (T extends DataTypes.IdLabelItem ? D | undefined : D);
24
24
  /**
25
25
  * Load data callback
26
26
  */
@@ -47,4 +47,4 @@ export interface SelectExProps<T extends {}> extends Omit<SelectProps, 'labelId'
47
47
  * @param props Props
48
48
  * @returns Component
49
49
  */
50
- export declare function SelectEx<T extends {} = IdLabelDto>(props: SelectExProps<T>): JSX.Element;
50
+ export declare function SelectEx<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: SelectExProps<T, D>): JSX.Element;
@@ -71,13 +71,13 @@ export function SelectEx(props) {
71
71
  };
72
72
  // Get option id
73
73
  const getId = (option) => {
74
- return Reflect.get(option, idField);
74
+ return option[idField];
75
75
  };
76
76
  // Get option label
77
77
  const getLabel = (option) => {
78
78
  return typeof labelField === 'function'
79
79
  ? labelField(option)
80
- : Reflect.get(option, labelField);
80
+ : new String(option[labelField]);
81
81
  };
82
82
  // Refs
83
83
  const divRef = React.useRef();
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { TableProps } from '@mui/material';
2
3
  import React from 'react';
3
4
  import { GridColumn } from '../components/GridColumn';
@@ -19,7 +20,7 @@ export interface TableExMethodRef extends GridMethodRef {
19
20
  /**
20
21
  * Extended table props
21
22
  */
22
- export interface TableExProps<T extends Record<string, any>> extends TableProps, GridLoader<T> {
23
+ export interface TableExProps<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>> extends TableProps, GridLoader<T> {
23
24
  /**
24
25
  * Alternating colors for odd/even rows
25
26
  */
@@ -35,7 +36,7 @@ export interface TableExProps<T extends Record<string, any>> extends TableProps,
35
36
  /**
36
37
  * Id field
37
38
  */
38
- idField?: string & keyof T;
39
+ idField?: D;
39
40
  /**
40
41
  * Max height
41
42
  */
@@ -62,4 +63,4 @@ export interface TableExProps<T extends Record<string, any>> extends TableProps,
62
63
  * @param props Props
63
64
  * @returns Component
64
65
  */
65
- export declare function TableEx<T extends Record<string, unknown>>(props: TableExProps<T>): JSX.Element;
66
+ export declare function TableEx<T extends {}, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: TableExProps<T, D>): JSX.Element;
package/lib/mu/TableEx.js CHANGED
@@ -259,8 +259,7 @@ export function TableEx(props) {
259
259
  columnIndex,
260
260
  cellProps
261
261
  })) : (React.createElement(React.Fragment, null, "\u00A0"));
262
- return (React.createElement(TableCell, { key: rowId.toString() +
263
- columnIndex, ...cellProps }, child));
262
+ return (React.createElement(TableCell, { key: `${rowId}${columnIndex}`, ...cellProps }, child));
264
263
  })));
265
264
  })))),
266
265
  React.createElement(TablePagination, { component: "div", showFirstButton: true, count: totalRows, rowsPerPage: batchSize, page: currentPage, onPageChange: handleChangePage, onRowsPerPageChange: handleChangeRowsPerPage, rowsPerPageOptions: [
@@ -1,19 +1,18 @@
1
1
  /// <reference types="react" />
2
- import { IdLabelDto } from '@etsoo/appscript';
3
2
  import { DataTypes } from '@etsoo/shared';
4
3
  import { AutocompleteExtendedProps } from './AutocompleteExtendedProps';
5
4
  /**
6
5
  * Tiplist props
7
6
  */
8
- export interface TiplistProps<T extends {}> extends Omit<AutocompleteExtendedProps<T>, 'open'> {
7
+ export interface TiplistProps<T extends {}, D extends DataTypes.Keys<T>> extends Omit<AutocompleteExtendedProps<T, D>, 'open'> {
9
8
  /**
10
9
  * Load data callback
11
10
  */
12
- loadData: (keyword?: string, id?: DataTypes.IdType) => PromiseLike<T[] | null | undefined>;
11
+ loadData: (keyword?: string, id?: T[D]) => PromiseLike<T[] | null | undefined>;
13
12
  }
14
13
  /**
15
14
  * Tiplist
16
15
  * @param props Props
17
16
  * @returns Component
18
17
  */
19
- export declare function Tiplist<T extends {} = IdLabelDto>(props: TiplistProps<T>): JSX.Element;
18
+ export declare function Tiplist<T extends {} = DataTypes.IdLabelItem, D extends DataTypes.Keys<T> = DataTypes.Keys<T>>(props: TiplistProps<T, D>): JSX.Element;
package/lib/mu/Tiplist.js CHANGED
@@ -20,7 +20,7 @@ export function Tiplist(props) {
20
20
  if (localValue === undefined)
21
21
  localValue = null;
22
22
  // One time calculation for input's default value (uncontrolled)
23
- const localIdValue = idValue !== null && idValue !== void 0 ? idValue : (localValue && Reflect.get(localValue, idField));
23
+ const localIdValue = idValue !== null && idValue !== void 0 ? idValue : DataTypes.getValue(localValue, idField !== null && idField !== void 0 ? idField : 'id');
24
24
  // Changable states
25
25
  const [states, stateUpdate] = React.useReducer((currentState, newState) => {
26
26
  return { ...currentState, ...newState };
@@ -31,7 +31,7 @@ export function Tiplist(props) {
31
31
  value: null
32
32
  });
33
33
  // Input value
34
- const inputValue = React.useMemo(() => states.value && Reflect.get(states.value, idField), [states.value]);
34
+ const inputValue = React.useMemo(() => states.value && states.value[idField], [states.value]);
35
35
  React.useEffect(() => {
36
36
  if (localValue != null)
37
37
  stateUpdate({ value: localValue });
@@ -128,7 +128,7 @@ export function Tiplist(props) {
128
128
  }, []);
129
129
  // Layout
130
130
  return (React.createElement("div", null,
131
- React.createElement("input", { ref: inputRef, "data-reset": "true", type: "text", style: { display: 'none' }, name: name, value: inputValue !== null && inputValue !== void 0 ? inputValue : '', readOnly: true, onChange: inputOnChange }),
131
+ React.createElement("input", { ref: inputRef, "data-reset": "true", type: "text", style: { display: 'none' }, name: name, value: `${inputValue !== null && inputValue !== void 0 ? inputValue : ''}`, readOnly: true, onChange: inputOnChange }),
132
132
  React.createElement(Autocomplete, { filterOptions: (options, _state) => options, value: states.value, options: states.options, onChange: (event, value, reason, details) => {
133
133
  // Set value
134
134
  setInputValue(value);
@@ -150,7 +150,7 @@ export function Tiplist(props) {
150
150
  if (loading)
151
151
  loadDataDirect(undefined, states.value == null
152
152
  ? undefined
153
- : Reflect.get(states.value, idField));
153
+ : states.value[idField]);
154
154
  }, onClose: () => {
155
155
  stateUpdate({
156
156
  open: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.5.74",
3
+ "version": "1.5.77",
4
4
  "description": "TypeScript ReactJs framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -51,11 +51,11 @@
51
51
  "@emotion/css": "^11.10.0",
52
52
  "@emotion/react": "^11.10.0",
53
53
  "@emotion/styled": "^11.10.0",
54
- "@etsoo/appscript": "^1.2.77",
54
+ "@etsoo/appscript": "^1.2.81",
55
55
  "@etsoo/notificationbase": "^1.1.6",
56
- "@etsoo/shared": "^1.1.45",
57
- "@mui/icons-material": "^5.8.4",
58
- "@mui/material": "^5.10.1",
56
+ "@etsoo/shared": "^1.1.47",
57
+ "@mui/icons-material": "^5.10.2",
58
+ "@mui/material": "^5.10.2",
59
59
  "@types/pica": "^9.0.1",
60
60
  "@types/pulltorefreshjs": "^0.1.5",
61
61
  "@types/react": "^18.0.17",
@@ -75,14 +75,14 @@
75
75
  },
76
76
  "devDependencies": {
77
77
  "@babel/cli": "^7.18.10",
78
- "@babel/core": "^7.18.10",
78
+ "@babel/core": "^7.18.13",
79
79
  "@babel/plugin-transform-runtime": "^7.18.10",
80
80
  "@babel/preset-env": "^7.18.10",
81
81
  "@babel/runtime-corejs3": "^7.18.9",
82
82
  "@types/jest": "^28.1.7",
83
83
  "@types/react-test-renderer": "^18.0.0",
84
- "@typescript-eslint/eslint-plugin": "^5.33.1",
85
- "@typescript-eslint/parser": "^5.33.1",
84
+ "@typescript-eslint/eslint-plugin": "^5.34.0",
85
+ "@typescript-eslint/parser": "^5.34.0",
86
86
  "eslint": "^8.22.0",
87
87
  "eslint-config-airbnb-base": "^15.0.0",
88
88
  "eslint-plugin-import": "^2.26.0",
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import React from 'react';
2
3
  import {
3
4
  Align,
@@ -25,8 +26,10 @@ export interface ScrollerGridItemRendererProps<T>
25
26
  /**
26
27
  * Scroller vertical grid props
27
28
  */
28
- export interface ScrollerGridProps<T>
29
- extends GridLoader<T>,
29
+ export interface ScrollerGridProps<
30
+ T extends {},
31
+ D extends DataTypes.Keys<T> = DataTypes.Keys<T>
32
+ > extends GridLoader<T>,
30
33
  Omit<
31
34
  VariableSizeGridProps<T>,
32
35
  'children' | 'rowCount' | 'rowHeight' | 'ref'
@@ -54,7 +57,7 @@ export interface ScrollerGridProps<T>
54
57
  * Id field
55
58
  * @default id
56
59
  */
57
- idField?: string & keyof T;
60
+ idField?: D;
58
61
 
59
62
  /**
60
63
  * Item renderer
@@ -98,9 +98,7 @@ const calculateBatchSize = (
98
98
  * @param props Props
99
99
  * @returns Component
100
100
  */
101
- export const ScrollerList = <T extends Record<string, any>>(
102
- props: ScrollerListProps<T>
103
- ) => {
101
+ export const ScrollerList = <T extends {}>(props: ScrollerListProps<T>) => {
104
102
  // Destruct
105
103
  const {
106
104
  autoLoad = true,
@@ -5,20 +5,22 @@ import { ChangeEventHandler } from 'react';
5
5
  /**
6
6
  * Autocomplete extended props
7
7
  */
8
- export interface AutocompleteExtendedProps<T extends Record<string, unknown>>
9
- extends Omit<
8
+ export interface AutocompleteExtendedProps<
9
+ T extends {},
10
+ D extends DataTypes.Keys<T>
11
+ > extends Omit<
10
12
  AutocompleteProps<T, undefined, false, false>,
11
13
  'renderInput' | 'options'
12
14
  > {
13
15
  /**
14
16
  * Id field, default is id
15
17
  */
16
- idField?: string & keyof T;
18
+ idField: T extends DataTypes.IdLabelItem ? D | undefined : D;
17
19
 
18
20
  /**
19
21
  * Id value
20
22
  */
21
- idValue?: DataTypes.IdType;
23
+ idValue?: T[D];
22
24
 
23
25
  /**
24
26
  * Autocomplete for the input