es-grid-template 1.9.100 → 1.9.102
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.
- package/es/ali-table/base-table/cell/EditCell.js +2 -58
- package/es/ali-table/base-table/cell/HeaderEditCell.js +2 -58
- package/es/grid-component/type.d.ts +1 -1
- package/es/group-component/body/EditableCell.js +2 -58
- package/es/group-component/components/async-table-select/index.d.ts +2 -11
- package/es/group-component/components/async-table-select/index.js +1 -40
- package/es/group-component/hook/utils.d.ts +3 -3
- package/es/table-component/body/EditableCell.js +2 -58
- package/es/table-component/components/async-table-select/index.d.ts +2 -1
- package/es/table-component/components/async-table-select/index.js +64 -3
- package/lib/ali-table/base-table/cell/EditCell.js +2 -58
- package/lib/ali-table/base-table/cell/HeaderEditCell.js +2 -58
- package/lib/grid-component/type.d.ts +1 -1
- package/lib/group-component/body/EditableCell.js +2 -58
- package/lib/group-component/components/async-table-select/index.d.ts +2 -11
- package/lib/group-component/components/async-table-select/index.js +7 -44
- package/lib/group-component/hook/utils.d.ts +9 -9
- package/lib/table-component/body/EditableCell.js +2 -58
- package/lib/table-component/components/async-table-select/index.d.ts +2 -1
- package/lib/table-component/components/async-table-select/index.js +63 -2
- package/package.json +1 -1
|
@@ -558,64 +558,8 @@ const EditCell = props => {
|
|
|
558
558
|
fieldNames: fieldNames ? fieldNames : {
|
|
559
559
|
value: keySelect,
|
|
560
560
|
label: inputKey ?? 'label'
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// onBlur={(event: any) => {
|
|
564
|
-
|
|
565
|
-
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
566
|
-
// const val = event.inputValue
|
|
567
|
-
// onChange(val ?? undefined)
|
|
568
|
-
|
|
569
|
-
// const formState = getValues()
|
|
570
|
-
// // const itemState = getValues(dataIndex)
|
|
571
|
-
// // @ts-ignore
|
|
572
|
-
// const prevState = record[dataIndex]
|
|
573
|
-
// const newState = val
|
|
574
|
-
|
|
575
|
-
// handleCellChange?.({
|
|
576
|
-
// key,
|
|
577
|
-
// field: column.field ?? column.field as any,
|
|
578
|
-
// record: formState,
|
|
579
|
-
// prevState,
|
|
580
|
-
// newState,
|
|
581
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
582
|
-
// indexCol,
|
|
583
|
-
// indexRow,
|
|
584
|
-
// type: 'blur'
|
|
585
|
-
// })
|
|
586
|
-
// }
|
|
587
|
-
// }}
|
|
588
|
-
|
|
589
|
-
// onKeyDown={(event: any) => {
|
|
590
|
-
|
|
591
|
-
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
592
|
-
|
|
593
|
-
// const val = event.target.value
|
|
594
|
-
// onChange(val)
|
|
595
|
-
|
|
596
|
-
// const formState = getValues()
|
|
597
|
-
// // const itemState = getValues(dataIndex)
|
|
598
|
-
// // @ts-ignore
|
|
599
|
-
// const prevState = record[dataIndex]
|
|
600
|
-
// const newState = val
|
|
601
|
-
|
|
602
|
-
// handleCellChange?.({
|
|
603
|
-
// key,
|
|
604
|
-
// field: column.field ?? column.field as any,
|
|
605
|
-
// record: formState,
|
|
606
|
-
// prevState,
|
|
607
|
-
// newState,
|
|
608
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
609
|
-
// indexCol,
|
|
610
|
-
// indexRow,
|
|
611
|
-
// type: 'blur'
|
|
612
|
-
// })
|
|
613
|
-
|
|
614
|
-
// }
|
|
615
|
-
|
|
616
|
-
// }}
|
|
617
|
-
,
|
|
618
|
-
|
|
561
|
+
},
|
|
562
|
+
searchTextAsValue: column.editSelectSettings?.searchTextAsValue,
|
|
619
563
|
"data-tooltip-content": message,
|
|
620
564
|
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
621
565
|
});
|
|
@@ -556,64 +556,8 @@ const HeaderEditCell = props => {
|
|
|
556
556
|
fieldNames: fieldNames ? fieldNames : {
|
|
557
557
|
value: keySelect,
|
|
558
558
|
label: inputKey ?? 'label'
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// onBlur={(event: any) => {
|
|
562
|
-
|
|
563
|
-
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
564
|
-
// const val = event.inputValue
|
|
565
|
-
// onChange(val ?? undefined)
|
|
566
|
-
|
|
567
|
-
// const formState = getValues()
|
|
568
|
-
// // const itemState = getValues(dataIndex)
|
|
569
|
-
// // @ts-ignore
|
|
570
|
-
// const prevState = record[dataIndex]
|
|
571
|
-
// const newState = val
|
|
572
|
-
|
|
573
|
-
// handleCellChange?.({
|
|
574
|
-
// key,
|
|
575
|
-
// field: column.field ?? column.field as any,
|
|
576
|
-
// record: formState,
|
|
577
|
-
// prevState,
|
|
578
|
-
// newState,
|
|
579
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
580
|
-
// indexCol,
|
|
581
|
-
// indexRow,
|
|
582
|
-
// type: 'blur'
|
|
583
|
-
// })
|
|
584
|
-
// }
|
|
585
|
-
// }}
|
|
586
|
-
|
|
587
|
-
// onKeyDown={(event: any) => {
|
|
588
|
-
|
|
589
|
-
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
590
|
-
|
|
591
|
-
// const val = event.target.value
|
|
592
|
-
// onChange(val)
|
|
593
|
-
|
|
594
|
-
// const formState = getValues()
|
|
595
|
-
// // const itemState = getValues(dataIndex)
|
|
596
|
-
// // @ts-ignore
|
|
597
|
-
// const prevState = record[dataIndex]
|
|
598
|
-
// const newState = val
|
|
599
|
-
|
|
600
|
-
// handleCellChange?.({
|
|
601
|
-
// key,
|
|
602
|
-
// field: column.field ?? column.field as any,
|
|
603
|
-
// record: formState,
|
|
604
|
-
// prevState,
|
|
605
|
-
// newState,
|
|
606
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
607
|
-
// indexCol,
|
|
608
|
-
// indexRow,
|
|
609
|
-
// type: 'blur'
|
|
610
|
-
// })
|
|
611
|
-
|
|
612
|
-
// }
|
|
613
|
-
|
|
614
|
-
// }}
|
|
615
|
-
,
|
|
616
|
-
|
|
559
|
+
},
|
|
560
|
+
searchTextAsValue: column.editSelectSettings?.searchTextAsValue,
|
|
617
561
|
"data-tooltip-content": message,
|
|
618
562
|
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
619
563
|
});
|
|
@@ -614,7 +614,7 @@ export type IEditSelectSettings = {
|
|
|
614
614
|
fieldValue?: string;
|
|
615
615
|
/** get label form other field **/
|
|
616
616
|
fieldLabel?: string;
|
|
617
|
-
/**
|
|
617
|
+
/** Lưu nội dung tìm kiếm làm giá trị khi rời ô chọn đơn. `select` và `selectTable` cũng hỗ trợ Enter. */
|
|
618
618
|
searchTextAsValue?: boolean;
|
|
619
619
|
filterKey?: string[];
|
|
620
620
|
selectMode?: SelectMode;
|
|
@@ -556,64 +556,8 @@ const EditableCell = props => {
|
|
|
556
556
|
fieldNames: fieldNames ? fieldNames : {
|
|
557
557
|
value: keySelect,
|
|
558
558
|
label: inputKey ?? 'label'
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
// onBlur={(event: any) => {
|
|
562
|
-
|
|
563
|
-
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
564
|
-
// const val = event.inputValue
|
|
565
|
-
// onChange(val ?? undefined)
|
|
566
|
-
|
|
567
|
-
// const formState = getValues()
|
|
568
|
-
// // const itemState = getValues(dataIndex)
|
|
569
|
-
// // @ts-ignore
|
|
570
|
-
// const prevState = record[dataIndex]
|
|
571
|
-
// const newState = val
|
|
572
|
-
|
|
573
|
-
// handleCellChange?.({
|
|
574
|
-
// key,
|
|
575
|
-
// field: column.field ?? column.field as any,
|
|
576
|
-
// record: formState,
|
|
577
|
-
// prevState,
|
|
578
|
-
// newState,
|
|
579
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
580
|
-
// indexCol,
|
|
581
|
-
// indexRow,
|
|
582
|
-
// type: 'blur'
|
|
583
|
-
// })
|
|
584
|
-
// }
|
|
585
|
-
// }}
|
|
586
|
-
|
|
587
|
-
// onKeyDown={(event: any) => {
|
|
588
|
-
|
|
589
|
-
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
590
|
-
|
|
591
|
-
// const val = event.target.value
|
|
592
|
-
// onChange(val)
|
|
593
|
-
|
|
594
|
-
// const formState = getValues()
|
|
595
|
-
// // const itemState = getValues(dataIndex)
|
|
596
|
-
// // @ts-ignore
|
|
597
|
-
// const prevState = record[dataIndex]
|
|
598
|
-
// const newState = val
|
|
599
|
-
|
|
600
|
-
// handleCellChange?.({
|
|
601
|
-
// key,
|
|
602
|
-
// field: column.field ?? column.field as any,
|
|
603
|
-
// record: formState,
|
|
604
|
-
// prevState,
|
|
605
|
-
// newState,
|
|
606
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
607
|
-
// indexCol,
|
|
608
|
-
// indexRow,
|
|
609
|
-
// type: 'blur'
|
|
610
|
-
// })
|
|
611
|
-
|
|
612
|
-
// }
|
|
613
|
-
|
|
614
|
-
// }}
|
|
615
|
-
,
|
|
616
|
-
|
|
559
|
+
},
|
|
560
|
+
searchTextAsValue: column.editSelectSettings?.searchTextAsValue,
|
|
617
561
|
"data-tooltip-content": message,
|
|
618
562
|
"data-tooltip-id": `${id}-tooltip-error`
|
|
619
563
|
});
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { TableSelectProps } from "rc-master-ui";
|
|
4
|
-
import type { LoadOptionsArgs } from '../../../grid-component/type';
|
|
5
|
-
export interface DebounceSelectProps<OptionType extends BaseOptionType = DefaultOptionType> extends TableSelectProps {
|
|
6
|
-
loadOptions?: (search: string, callback: (newOptions: OptionType[]) => void, args?: LoadOptionsArgs) => void;
|
|
7
|
-
debounceTimeout?: number;
|
|
8
|
-
defaultOptions?: OptionType[];
|
|
9
|
-
rowData?: any;
|
|
10
|
-
}
|
|
11
|
-
export declare function AsyncTableSelect<OptionType extends BaseOptionType>({ loadOptions, debounceTimeout, defaultOptions, columns, rowData, ...props }: DebounceSelectProps<OptionType>): JSX.Element;
|
|
1
|
+
export { AsyncTableSelect } from '../../../table-component/components/async-table-select';
|
|
2
|
+
export type { DebounceSelectProps } from '../../../table-component/components/async-table-select';
|
|
@@ -1,40 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
3
|
-
import debounce from 'lodash/debounce';
|
|
4
|
-
import { TableSelect } from "rc-master-ui";
|
|
5
|
-
export function AsyncTableSelect({
|
|
6
|
-
loadOptions,
|
|
7
|
-
debounceTimeout = 500,
|
|
8
|
-
defaultOptions,
|
|
9
|
-
columns,
|
|
10
|
-
rowData,
|
|
11
|
-
...props
|
|
12
|
-
}) {
|
|
13
|
-
const [options, setOptions] = useState(defaultOptions ?? []);
|
|
14
|
-
const debounceFetcher = useMemo(() => {
|
|
15
|
-
const fetchOptions = value => {
|
|
16
|
-
if (value.trim().length === 0) {
|
|
17
|
-
setOptions(defaultOptions ?? []);
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
if (loadOptions) {
|
|
21
|
-
loadOptions(value, newOptions => {
|
|
22
|
-
setOptions(newOptions);
|
|
23
|
-
}, {
|
|
24
|
-
rowData
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
return debounce(fetchOptions, debounceTimeout);
|
|
29
|
-
}, [debounceTimeout, loadOptions, defaultOptions, rowData]);
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
setOptions(defaultOptions ?? []);
|
|
32
|
-
}, [defaultOptions]);
|
|
33
|
-
return /*#__PURE__*/React.createElement(TableSelect, _extends({}, props, {
|
|
34
|
-
filterOption: loadOptions ? false : props?.filterOption,
|
|
35
|
-
onSearch: debounceFetcher,
|
|
36
|
-
onSelect: () => setOptions(defaultOptions ?? []),
|
|
37
|
-
options: options,
|
|
38
|
-
columns: columns
|
|
39
|
-
}));
|
|
40
|
-
}
|
|
1
|
+
export { AsyncTableSelect } from "../../../table-component/components/async-table-select";
|
|
@@ -196,10 +196,10 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
|
|
|
196
196
|
value: any;
|
|
197
197
|
rowData: RecordType;
|
|
198
198
|
}) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
|
|
199
|
-
onCellStyles?: Omit<CSSProperties, "right" | "left" | "
|
|
200
|
-
onCellHeaderStyles?: Omit<CSSProperties, "right" | "left" | "
|
|
199
|
+
onCellStyles?: Omit<CSSProperties, "right" | "left" | "width" | "display" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "right" | "left" | "width" | "display" | "minWidth" | "position">);
|
|
200
|
+
onCellHeaderStyles?: Omit<CSSProperties, "right" | "left" | "width" | "display" | "minWidth" | "position"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "right" | "left" | "width" | "display" | "minWidth" | "position">);
|
|
201
201
|
onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
|
|
202
|
-
onCellFooterStyles?: Omit<CSSProperties, "right" | "left" | "
|
|
202
|
+
onCellFooterStyles?: Omit<CSSProperties, "right" | "left" | "width" | "display" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "right" | "left" | "width" | "display" | "minWidth" | "position">);
|
|
203
203
|
getValue?: (row: any, rowIndex: number) => any;
|
|
204
204
|
getCellProps?: (value: any, row: any, rowIndex: number) => import("./../../grid-component/type").CellProps;
|
|
205
205
|
headerCellProps?: import("./../../grid-component/type").CellProps;
|
|
@@ -558,64 +558,8 @@ const EditableCell = props => {
|
|
|
558
558
|
fieldNames: fieldNames ? fieldNames : {
|
|
559
559
|
value: keySelect,
|
|
560
560
|
label: inputKey ?? 'label'
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
// onBlur={(event: any) => {
|
|
564
|
-
|
|
565
|
-
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
566
|
-
// const val = event.inputValue
|
|
567
|
-
// onChange(val ?? undefined)
|
|
568
|
-
|
|
569
|
-
// const formState = getValues()
|
|
570
|
-
// // const itemState = getValues(dataIndex)
|
|
571
|
-
// // @ts-ignore
|
|
572
|
-
// const prevState = record[dataIndex]
|
|
573
|
-
// const newState = val
|
|
574
|
-
|
|
575
|
-
// handleCellChange?.({
|
|
576
|
-
// key,
|
|
577
|
-
// field: column.field ?? column.field as any,
|
|
578
|
-
// record: formState,
|
|
579
|
-
// prevState,
|
|
580
|
-
// newState,
|
|
581
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
582
|
-
// indexCol,
|
|
583
|
-
// indexRow,
|
|
584
|
-
// type: 'blur'
|
|
585
|
-
// })
|
|
586
|
-
// }
|
|
587
|
-
// }}
|
|
588
|
-
|
|
589
|
-
// onKeyDown={(event: any) => {
|
|
590
|
-
|
|
591
|
-
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
592
|
-
|
|
593
|
-
// const val = event.target.value
|
|
594
|
-
// onChange(val)
|
|
595
|
-
|
|
596
|
-
// const formState = getValues()
|
|
597
|
-
// // const itemState = getValues(dataIndex)
|
|
598
|
-
// // @ts-ignore
|
|
599
|
-
// const prevState = record[dataIndex]
|
|
600
|
-
// const newState = val
|
|
601
|
-
|
|
602
|
-
// handleCellChange?.({
|
|
603
|
-
// key,
|
|
604
|
-
// field: column.field ?? column.field as any,
|
|
605
|
-
// record: formState,
|
|
606
|
-
// prevState,
|
|
607
|
-
// newState,
|
|
608
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
609
|
-
// indexCol,
|
|
610
|
-
// indexRow,
|
|
611
|
-
// type: 'blur'
|
|
612
|
-
// })
|
|
613
|
-
|
|
614
|
-
// }
|
|
615
|
-
|
|
616
|
-
// }}
|
|
617
|
-
,
|
|
618
|
-
|
|
561
|
+
},
|
|
562
|
+
searchTextAsValue: column.editSelectSettings?.searchTextAsValue,
|
|
619
563
|
"data-tooltip-content": message,
|
|
620
564
|
"data-tooltip-id": `${id}-tooltip-error`
|
|
621
565
|
});
|
|
@@ -7,5 +7,6 @@ export interface DebounceSelectProps<OptionType extends BaseOptionType = Default
|
|
|
7
7
|
debounceTimeout?: number;
|
|
8
8
|
defaultOptions?: OptionType[];
|
|
9
9
|
rowData?: any;
|
|
10
|
+
searchTextAsValue?: boolean;
|
|
10
11
|
}
|
|
11
|
-
export declare function AsyncTableSelect<OptionType extends BaseOptionType>({ loadOptions, debounceTimeout, defaultOptions, columns, rowData, ...props }: DebounceSelectProps<OptionType>): JSX.Element;
|
|
12
|
+
export declare function AsyncTableSelect<OptionType extends BaseOptionType>({ loadOptions, debounceTimeout, defaultOptions, columns, rowData, searchTextAsValue, onChange, ...props }: DebounceSelectProps<OptionType>): JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import debounce from 'lodash/debounce';
|
|
4
4
|
import { TableSelect } from "rc-master-ui";
|
|
5
5
|
export function AsyncTableSelect({
|
|
@@ -8,9 +8,43 @@ export function AsyncTableSelect({
|
|
|
8
8
|
defaultOptions,
|
|
9
9
|
columns,
|
|
10
10
|
rowData,
|
|
11
|
+
searchTextAsValue,
|
|
12
|
+
onChange,
|
|
11
13
|
...props
|
|
12
14
|
}) {
|
|
13
15
|
const [options, setOptions] = useState(defaultOptions ?? []);
|
|
16
|
+
const selectRef = useRef(null);
|
|
17
|
+
const searchText = useRef('');
|
|
18
|
+
const allowSearchText = searchTextAsValue && !props.disabled && !props.mode && props.selectMode !== 'checkbox';
|
|
19
|
+
const popupClass = `es-grid-select-table-popup-${useId().replace(/:/g, '')}`;
|
|
20
|
+
const popupClassName = allowSearchText ? [props.popupClassName || props.dropdownClassName, popupClass].filter(Boolean).join(' ') : props.popupClassName;
|
|
21
|
+
const commitSearchText = useCallback(() => {
|
|
22
|
+
const value = searchText.current;
|
|
23
|
+
searchText.current = '';
|
|
24
|
+
if (allowSearchText && value) {
|
|
25
|
+
onChange?.(value, {
|
|
26
|
+
value,
|
|
27
|
+
label: value,
|
|
28
|
+
searchTextAsValue: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}, [allowSearchText, onChange]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
const element = selectRef.current?.nativeElement;
|
|
34
|
+
if (!allowSearchText || !element) return;
|
|
35
|
+
|
|
36
|
+
// The grid can unmount the editor on mousedown before the browser dispatches blur.
|
|
37
|
+
const commitOnOutsideMouseDown = event => {
|
|
38
|
+
if (!searchText.current) return;
|
|
39
|
+
const path = event.composedPath();
|
|
40
|
+
const isInsidePopup = path.some(node => node instanceof Element && node.classList.contains(popupClass));
|
|
41
|
+
if (path.includes(element) || isInsidePopup) return;
|
|
42
|
+
commitSearchText();
|
|
43
|
+
};
|
|
44
|
+
const ownerDocument = element.ownerDocument;
|
|
45
|
+
ownerDocument.addEventListener('mousedown', commitOnOutsideMouseDown, true);
|
|
46
|
+
return () => ownerDocument.removeEventListener('mousedown', commitOnOutsideMouseDown, true);
|
|
47
|
+
}, [allowSearchText, commitSearchText, popupClass]);
|
|
14
48
|
const debounceFetcher = useMemo(() => {
|
|
15
49
|
const fetchOptions = value => {
|
|
16
50
|
if (value.trim().length === 0) {
|
|
@@ -31,9 +65,36 @@ export function AsyncTableSelect({
|
|
|
31
65
|
setOptions(defaultOptions ?? []);
|
|
32
66
|
}, [defaultOptions]);
|
|
33
67
|
return /*#__PURE__*/React.createElement(TableSelect, _extends({}, props, {
|
|
68
|
+
ref: selectRef,
|
|
69
|
+
popupClassName: popupClassName,
|
|
34
70
|
filterOption: loadOptions ? false : props?.filterOption,
|
|
35
|
-
onSearch:
|
|
36
|
-
|
|
71
|
+
onSearch: value => {
|
|
72
|
+
searchText.current = value;
|
|
73
|
+
debounceFetcher(value);
|
|
74
|
+
},
|
|
75
|
+
onChange: (value, option) => {
|
|
76
|
+
searchText.current = '';
|
|
77
|
+
onChange?.(value, option);
|
|
78
|
+
},
|
|
79
|
+
onSelect: () => {
|
|
80
|
+
searchText.current = '';
|
|
81
|
+
setOptions(defaultOptions ?? []);
|
|
82
|
+
},
|
|
83
|
+
onBlur: event => {
|
|
84
|
+
commitSearchText();
|
|
85
|
+
props.onBlur?.(event);
|
|
86
|
+
},
|
|
87
|
+
onInputKeyDown: event => {
|
|
88
|
+
props.onInputKeyDown?.(event);
|
|
89
|
+
if (!allowSearchText || event.key !== 'Enter' || !searchText.current) return;
|
|
90
|
+
|
|
91
|
+
// Stop Enter before the dropdown selects the active row or the grid saves again.
|
|
92
|
+
event.stopPropagation();
|
|
93
|
+
if (!event.nativeEvent.isComposing && event.keyCode !== 229) {
|
|
94
|
+
event.preventDefault();
|
|
95
|
+
event.currentTarget.blur();
|
|
96
|
+
}
|
|
97
|
+
},
|
|
37
98
|
options: options,
|
|
38
99
|
columns: columns
|
|
39
100
|
}));
|
|
@@ -565,64 +565,8 @@ const EditCell = props => {
|
|
|
565
565
|
fieldNames: fieldNames ? fieldNames : {
|
|
566
566
|
value: keySelect,
|
|
567
567
|
label: inputKey ?? 'label'
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// onBlur={(event: any) => {
|
|
571
|
-
|
|
572
|
-
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
573
|
-
// const val = event.inputValue
|
|
574
|
-
// onChange(val ?? undefined)
|
|
575
|
-
|
|
576
|
-
// const formState = getValues()
|
|
577
|
-
// // const itemState = getValues(dataIndex)
|
|
578
|
-
// // @ts-ignore
|
|
579
|
-
// const prevState = record[dataIndex]
|
|
580
|
-
// const newState = val
|
|
581
|
-
|
|
582
|
-
// handleCellChange?.({
|
|
583
|
-
// key,
|
|
584
|
-
// field: column.field ?? column.field as any,
|
|
585
|
-
// record: formState,
|
|
586
|
-
// prevState,
|
|
587
|
-
// newState,
|
|
588
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
589
|
-
// indexCol,
|
|
590
|
-
// indexRow,
|
|
591
|
-
// type: 'blur'
|
|
592
|
-
// })
|
|
593
|
-
// }
|
|
594
|
-
// }}
|
|
595
|
-
|
|
596
|
-
// onKeyDown={(event: any) => {
|
|
597
|
-
|
|
598
|
-
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
599
|
-
|
|
600
|
-
// const val = event.target.value
|
|
601
|
-
// onChange(val)
|
|
602
|
-
|
|
603
|
-
// const formState = getValues()
|
|
604
|
-
// // const itemState = getValues(dataIndex)
|
|
605
|
-
// // @ts-ignore
|
|
606
|
-
// const prevState = record[dataIndex]
|
|
607
|
-
// const newState = val
|
|
608
|
-
|
|
609
|
-
// handleCellChange?.({
|
|
610
|
-
// key,
|
|
611
|
-
// field: column.field ?? column.field as any,
|
|
612
|
-
// record: formState,
|
|
613
|
-
// prevState,
|
|
614
|
-
// newState,
|
|
615
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
616
|
-
// indexCol,
|
|
617
|
-
// indexRow,
|
|
618
|
-
// type: 'blur'
|
|
619
|
-
// })
|
|
620
|
-
|
|
621
|
-
// }
|
|
622
|
-
|
|
623
|
-
// }}
|
|
624
|
-
,
|
|
625
|
-
|
|
568
|
+
},
|
|
569
|
+
searchTextAsValue: column.editSelectSettings?.searchTextAsValue,
|
|
626
570
|
"data-tooltip-content": message,
|
|
627
571
|
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
628
572
|
});
|
|
@@ -563,64 +563,8 @@ const HeaderEditCell = props => {
|
|
|
563
563
|
fieldNames: fieldNames ? fieldNames : {
|
|
564
564
|
value: keySelect,
|
|
565
565
|
label: inputKey ?? 'label'
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// onBlur={(event: any) => {
|
|
569
|
-
|
|
570
|
-
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
571
|
-
// const val = event.inputValue
|
|
572
|
-
// onChange(val ?? undefined)
|
|
573
|
-
|
|
574
|
-
// const formState = getValues()
|
|
575
|
-
// // const itemState = getValues(dataIndex)
|
|
576
|
-
// // @ts-ignore
|
|
577
|
-
// const prevState = record[dataIndex]
|
|
578
|
-
// const newState = val
|
|
579
|
-
|
|
580
|
-
// handleCellChange?.({
|
|
581
|
-
// key,
|
|
582
|
-
// field: column.field ?? column.field as any,
|
|
583
|
-
// record: formState,
|
|
584
|
-
// prevState,
|
|
585
|
-
// newState,
|
|
586
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
587
|
-
// indexCol,
|
|
588
|
-
// indexRow,
|
|
589
|
-
// type: 'blur'
|
|
590
|
-
// })
|
|
591
|
-
// }
|
|
592
|
-
// }}
|
|
593
|
-
|
|
594
|
-
// onKeyDown={(event: any) => {
|
|
595
|
-
|
|
596
|
-
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
597
|
-
|
|
598
|
-
// const val = event.target.value
|
|
599
|
-
// onChange(val)
|
|
600
|
-
|
|
601
|
-
// const formState = getValues()
|
|
602
|
-
// // const itemState = getValues(dataIndex)
|
|
603
|
-
// // @ts-ignore
|
|
604
|
-
// const prevState = record[dataIndex]
|
|
605
|
-
// const newState = val
|
|
606
|
-
|
|
607
|
-
// handleCellChange?.({
|
|
608
|
-
// key,
|
|
609
|
-
// field: column.field ?? column.field as any,
|
|
610
|
-
// record: formState,
|
|
611
|
-
// prevState,
|
|
612
|
-
// newState,
|
|
613
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
614
|
-
// indexCol,
|
|
615
|
-
// indexRow,
|
|
616
|
-
// type: 'blur'
|
|
617
|
-
// })
|
|
618
|
-
|
|
619
|
-
// }
|
|
620
|
-
|
|
621
|
-
// }}
|
|
622
|
-
,
|
|
623
|
-
|
|
566
|
+
},
|
|
567
|
+
searchTextAsValue: column.editSelectSettings?.searchTextAsValue,
|
|
624
568
|
"data-tooltip-content": message,
|
|
625
569
|
"data-tooltip-id": `${tableId}-tooltip-error`
|
|
626
570
|
});
|
|
@@ -614,7 +614,7 @@ export type IEditSelectSettings = {
|
|
|
614
614
|
fieldValue?: string;
|
|
615
615
|
/** get label form other field **/
|
|
616
616
|
fieldLabel?: string;
|
|
617
|
-
/**
|
|
617
|
+
/** Lưu nội dung tìm kiếm làm giá trị khi rời ô chọn đơn. `select` và `selectTable` cũng hỗ trợ Enter. */
|
|
618
618
|
searchTextAsValue?: boolean;
|
|
619
619
|
filterKey?: string[];
|
|
620
620
|
selectMode?: SelectMode;
|
|
@@ -563,64 +563,8 @@ const EditableCell = props => {
|
|
|
563
563
|
fieldNames: fieldNames ? fieldNames : {
|
|
564
564
|
value: keySelect,
|
|
565
565
|
label: inputKey ?? 'label'
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// onBlur={(event: any) => {
|
|
569
|
-
|
|
570
|
-
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
571
|
-
// const val = event.inputValue
|
|
572
|
-
// onChange(val ?? undefined)
|
|
573
|
-
|
|
574
|
-
// const formState = getValues()
|
|
575
|
-
// // const itemState = getValues(dataIndex)
|
|
576
|
-
// // @ts-ignore
|
|
577
|
-
// const prevState = record[dataIndex]
|
|
578
|
-
// const newState = val
|
|
579
|
-
|
|
580
|
-
// handleCellChange?.({
|
|
581
|
-
// key,
|
|
582
|
-
// field: column.field ?? column.field as any,
|
|
583
|
-
// record: formState,
|
|
584
|
-
// prevState,
|
|
585
|
-
// newState,
|
|
586
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
587
|
-
// indexCol,
|
|
588
|
-
// indexRow,
|
|
589
|
-
// type: 'blur'
|
|
590
|
-
// })
|
|
591
|
-
// }
|
|
592
|
-
// }}
|
|
593
|
-
|
|
594
|
-
// onKeyDown={(event: any) => {
|
|
595
|
-
|
|
596
|
-
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
597
|
-
|
|
598
|
-
// const val = event.target.value
|
|
599
|
-
// onChange(val)
|
|
600
|
-
|
|
601
|
-
// const formState = getValues()
|
|
602
|
-
// // const itemState = getValues(dataIndex)
|
|
603
|
-
// // @ts-ignore
|
|
604
|
-
// const prevState = record[dataIndex]
|
|
605
|
-
// const newState = val
|
|
606
|
-
|
|
607
|
-
// handleCellChange?.({
|
|
608
|
-
// key,
|
|
609
|
-
// field: column.field ?? column.field as any,
|
|
610
|
-
// record: formState,
|
|
611
|
-
// prevState,
|
|
612
|
-
// newState,
|
|
613
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
614
|
-
// indexCol,
|
|
615
|
-
// indexRow,
|
|
616
|
-
// type: 'blur'
|
|
617
|
-
// })
|
|
618
|
-
|
|
619
|
-
// }
|
|
620
|
-
|
|
621
|
-
// }}
|
|
622
|
-
,
|
|
623
|
-
|
|
566
|
+
},
|
|
567
|
+
searchTextAsValue: column.editSelectSettings?.searchTextAsValue,
|
|
624
568
|
"data-tooltip-content": message,
|
|
625
569
|
"data-tooltip-id": `${id}-tooltip-error`
|
|
626
570
|
});
|
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { TableSelectProps } from "rc-master-ui";
|
|
4
|
-
import type { LoadOptionsArgs } from '../../../grid-component/type';
|
|
5
|
-
export interface DebounceSelectProps<OptionType extends BaseOptionType = DefaultOptionType> extends TableSelectProps {
|
|
6
|
-
loadOptions?: (search: string, callback: (newOptions: OptionType[]) => void, args?: LoadOptionsArgs) => void;
|
|
7
|
-
debounceTimeout?: number;
|
|
8
|
-
defaultOptions?: OptionType[];
|
|
9
|
-
rowData?: any;
|
|
10
|
-
}
|
|
11
|
-
export declare function AsyncTableSelect<OptionType extends BaseOptionType>({ loadOptions, debounceTimeout, defaultOptions, columns, rowData, ...props }: DebounceSelectProps<OptionType>): JSX.Element;
|
|
1
|
+
export { AsyncTableSelect } from '../../../table-component/components/async-table-select';
|
|
2
|
+
export type { DebounceSelectProps } from '../../../table-component/components/async-table-select';
|
|
@@ -1,49 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function AsyncTableSelect({
|
|
15
|
-
loadOptions,
|
|
16
|
-
debounceTimeout = 500,
|
|
17
|
-
defaultOptions,
|
|
18
|
-
columns,
|
|
19
|
-
rowData,
|
|
20
|
-
...props
|
|
21
|
-
}) {
|
|
22
|
-
const [options, setOptions] = (0, _react.useState)(defaultOptions ?? []);
|
|
23
|
-
const debounceFetcher = (0, _react.useMemo)(() => {
|
|
24
|
-
const fetchOptions = value => {
|
|
25
|
-
if (value.trim().length === 0) {
|
|
26
|
-
setOptions(defaultOptions ?? []);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (loadOptions) {
|
|
30
|
-
loadOptions(value, newOptions => {
|
|
31
|
-
setOptions(newOptions);
|
|
32
|
-
}, {
|
|
33
|
-
rowData
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
return (0, _debounce.default)(fetchOptions, debounceTimeout);
|
|
38
|
-
}, [debounceTimeout, loadOptions, defaultOptions, rowData]);
|
|
39
|
-
(0, _react.useEffect)(() => {
|
|
40
|
-
setOptions(defaultOptions ?? []);
|
|
41
|
-
}, [defaultOptions]);
|
|
42
|
-
return /*#__PURE__*/_react.default.createElement(_rcMasterUi.TableSelect, (0, _extends2.default)({}, props, {
|
|
43
|
-
filterOption: loadOptions ? false : props?.filterOption,
|
|
44
|
-
onSearch: debounceFetcher,
|
|
45
|
-
onSelect: () => setOptions(defaultOptions ?? []),
|
|
46
|
-
options: options,
|
|
47
|
-
columns: columns
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
6
|
+
Object.defineProperty(exports, "AsyncTableSelect", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _asyncTableSelect.AsyncTableSelect;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _asyncTableSelect = require("../../../table-component/components/async-table-select");
|
|
@@ -167,7 +167,7 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
|
|
|
167
167
|
haveSum?: boolean;
|
|
168
168
|
isSummary?: boolean;
|
|
169
169
|
sumGroup?: boolean;
|
|
170
|
-
summaryTemplate?: (data: number, key: string) => import("react").
|
|
170
|
+
summaryTemplate?: (data: number, key: string) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode;
|
|
171
171
|
sorter?: boolean;
|
|
172
172
|
allowFiltering?: boolean;
|
|
173
173
|
allowSortering?: boolean;
|
|
@@ -179,27 +179,27 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
|
|
|
179
179
|
showFilterSearch?: boolean;
|
|
180
180
|
hidden?: boolean;
|
|
181
181
|
visible?: boolean;
|
|
182
|
-
headerTooltip?: string | boolean | (() => import("react").
|
|
182
|
+
headerTooltip?: string | boolean | (() => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
|
|
183
183
|
columnGroupText?: string;
|
|
184
184
|
headerTextAlign?: import("./../../grid-component/type").ITextAlign;
|
|
185
|
-
headerTemplate?: import("react").
|
|
185
|
+
headerTemplate?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((column: ColumnTable<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
|
|
186
186
|
fixedType?: import("./../../grid-component/type").FixedType;
|
|
187
187
|
headerTextWrap?: boolean;
|
|
188
188
|
ellipsis?: boolean;
|
|
189
189
|
allowResizing?: boolean;
|
|
190
190
|
align?: import("./../../grid-component/type").ITextAlign;
|
|
191
191
|
textAlign?: import("./../../grid-component/type").ITextAlign;
|
|
192
|
-
template?: import("react").
|
|
193
|
-
linkTemplate?: import("react").
|
|
192
|
+
template?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
|
|
193
|
+
linkTemplate?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
|
|
194
194
|
showTooltip?: boolean;
|
|
195
195
|
tooltipDescription?: string | ((args: {
|
|
196
196
|
value: any;
|
|
197
197
|
rowData: RecordType;
|
|
198
|
-
}) => import("react").
|
|
199
|
-
onCellStyles?: Omit<CSSProperties, "
|
|
200
|
-
onCellHeaderStyles?: Omit<CSSProperties, "
|
|
198
|
+
}) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
|
|
199
|
+
onCellStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
|
|
200
|
+
onCellHeaderStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
|
|
201
201
|
onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
|
|
202
|
-
onCellFooterStyles?: Omit<CSSProperties, "
|
|
202
|
+
onCellFooterStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
|
|
203
203
|
getValue?: (row: any, rowIndex: number) => any;
|
|
204
204
|
getCellProps?: (value: any, row: any, rowIndex: number) => import("./../../grid-component/type").CellProps;
|
|
205
205
|
headerCellProps?: import("./../../grid-component/type").CellProps;
|
|
@@ -565,64 +565,8 @@ const EditableCell = props => {
|
|
|
565
565
|
fieldNames: fieldNames ? fieldNames : {
|
|
566
566
|
value: keySelect,
|
|
567
567
|
label: inputKey ?? 'label'
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// onBlur={(event: any) => {
|
|
571
|
-
|
|
572
|
-
// if (event.inputValue && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
573
|
-
// const val = event.inputValue
|
|
574
|
-
// onChange(val ?? undefined)
|
|
575
|
-
|
|
576
|
-
// const formState = getValues()
|
|
577
|
-
// // const itemState = getValues(dataIndex)
|
|
578
|
-
// // @ts-ignore
|
|
579
|
-
// const prevState = record[dataIndex]
|
|
580
|
-
// const newState = val
|
|
581
|
-
|
|
582
|
-
// handleCellChange?.({
|
|
583
|
-
// key,
|
|
584
|
-
// field: column.field ?? column.field as any,
|
|
585
|
-
// record: formState,
|
|
586
|
-
// prevState,
|
|
587
|
-
// newState,
|
|
588
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
589
|
-
// indexCol,
|
|
590
|
-
// indexRow,
|
|
591
|
-
// type: 'blur'
|
|
592
|
-
// })
|
|
593
|
-
// }
|
|
594
|
-
// }}
|
|
595
|
-
|
|
596
|
-
// onKeyDown={(event: any) => {
|
|
597
|
-
|
|
598
|
-
// if (event.key === 'Enter' && event.target?.value && column?.editSelectSettings?.searchTextAsValue && isMulti !== true) {
|
|
599
|
-
|
|
600
|
-
// const val = event.target.value
|
|
601
|
-
// onChange(val)
|
|
602
|
-
|
|
603
|
-
// const formState = getValues()
|
|
604
|
-
// // const itemState = getValues(dataIndex)
|
|
605
|
-
// // @ts-ignore
|
|
606
|
-
// const prevState = record[dataIndex]
|
|
607
|
-
// const newState = val
|
|
608
|
-
|
|
609
|
-
// handleCellChange?.({
|
|
610
|
-
// key,
|
|
611
|
-
// field: column.field ?? column.field as any,
|
|
612
|
-
// record: formState,
|
|
613
|
-
// prevState,
|
|
614
|
-
// newState,
|
|
615
|
-
// option: { value: val, label: val, searchTextAsValue: true } as any,
|
|
616
|
-
// indexCol,
|
|
617
|
-
// indexRow,
|
|
618
|
-
// type: 'blur'
|
|
619
|
-
// })
|
|
620
|
-
|
|
621
|
-
// }
|
|
622
|
-
|
|
623
|
-
// }}
|
|
624
|
-
,
|
|
625
|
-
|
|
568
|
+
},
|
|
569
|
+
searchTextAsValue: column.editSelectSettings?.searchTextAsValue,
|
|
626
570
|
"data-tooltip-content": message,
|
|
627
571
|
"data-tooltip-id": `${id}-tooltip-error`
|
|
628
572
|
});
|
|
@@ -7,5 +7,6 @@ export interface DebounceSelectProps<OptionType extends BaseOptionType = Default
|
|
|
7
7
|
debounceTimeout?: number;
|
|
8
8
|
defaultOptions?: OptionType[];
|
|
9
9
|
rowData?: any;
|
|
10
|
+
searchTextAsValue?: boolean;
|
|
10
11
|
}
|
|
11
|
-
export declare function AsyncTableSelect<OptionType extends BaseOptionType>({ loadOptions, debounceTimeout, defaultOptions, columns, rowData, ...props }: DebounceSelectProps<OptionType>): JSX.Element;
|
|
12
|
+
export declare function AsyncTableSelect<OptionType extends BaseOptionType>({ loadOptions, debounceTimeout, defaultOptions, columns, rowData, searchTextAsValue, onChange, ...props }: DebounceSelectProps<OptionType>): JSX.Element;
|
|
@@ -17,9 +17,43 @@ function AsyncTableSelect({
|
|
|
17
17
|
defaultOptions,
|
|
18
18
|
columns,
|
|
19
19
|
rowData,
|
|
20
|
+
searchTextAsValue,
|
|
21
|
+
onChange,
|
|
20
22
|
...props
|
|
21
23
|
}) {
|
|
22
24
|
const [options, setOptions] = (0, _react.useState)(defaultOptions ?? []);
|
|
25
|
+
const selectRef = (0, _react.useRef)(null);
|
|
26
|
+
const searchText = (0, _react.useRef)('');
|
|
27
|
+
const allowSearchText = searchTextAsValue && !props.disabled && !props.mode && props.selectMode !== 'checkbox';
|
|
28
|
+
const popupClass = `es-grid-select-table-popup-${(0, _react.useId)().replace(/:/g, '')}`;
|
|
29
|
+
const popupClassName = allowSearchText ? [props.popupClassName || props.dropdownClassName, popupClass].filter(Boolean).join(' ') : props.popupClassName;
|
|
30
|
+
const commitSearchText = (0, _react.useCallback)(() => {
|
|
31
|
+
const value = searchText.current;
|
|
32
|
+
searchText.current = '';
|
|
33
|
+
if (allowSearchText && value) {
|
|
34
|
+
onChange?.(value, {
|
|
35
|
+
value,
|
|
36
|
+
label: value,
|
|
37
|
+
searchTextAsValue: true
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, [allowSearchText, onChange]);
|
|
41
|
+
(0, _react.useEffect)(() => {
|
|
42
|
+
const element = selectRef.current?.nativeElement;
|
|
43
|
+
if (!allowSearchText || !element) return;
|
|
44
|
+
|
|
45
|
+
// The grid can unmount the editor on mousedown before the browser dispatches blur.
|
|
46
|
+
const commitOnOutsideMouseDown = event => {
|
|
47
|
+
if (!searchText.current) return;
|
|
48
|
+
const path = event.composedPath();
|
|
49
|
+
const isInsidePopup = path.some(node => node instanceof Element && node.classList.contains(popupClass));
|
|
50
|
+
if (path.includes(element) || isInsidePopup) return;
|
|
51
|
+
commitSearchText();
|
|
52
|
+
};
|
|
53
|
+
const ownerDocument = element.ownerDocument;
|
|
54
|
+
ownerDocument.addEventListener('mousedown', commitOnOutsideMouseDown, true);
|
|
55
|
+
return () => ownerDocument.removeEventListener('mousedown', commitOnOutsideMouseDown, true);
|
|
56
|
+
}, [allowSearchText, commitSearchText, popupClass]);
|
|
23
57
|
const debounceFetcher = (0, _react.useMemo)(() => {
|
|
24
58
|
const fetchOptions = value => {
|
|
25
59
|
if (value.trim().length === 0) {
|
|
@@ -40,9 +74,36 @@ function AsyncTableSelect({
|
|
|
40
74
|
setOptions(defaultOptions ?? []);
|
|
41
75
|
}, [defaultOptions]);
|
|
42
76
|
return /*#__PURE__*/_react.default.createElement(_rcMasterUi.TableSelect, (0, _extends2.default)({}, props, {
|
|
77
|
+
ref: selectRef,
|
|
78
|
+
popupClassName: popupClassName,
|
|
43
79
|
filterOption: loadOptions ? false : props?.filterOption,
|
|
44
|
-
onSearch:
|
|
45
|
-
|
|
80
|
+
onSearch: value => {
|
|
81
|
+
searchText.current = value;
|
|
82
|
+
debounceFetcher(value);
|
|
83
|
+
},
|
|
84
|
+
onChange: (value, option) => {
|
|
85
|
+
searchText.current = '';
|
|
86
|
+
onChange?.(value, option);
|
|
87
|
+
},
|
|
88
|
+
onSelect: () => {
|
|
89
|
+
searchText.current = '';
|
|
90
|
+
setOptions(defaultOptions ?? []);
|
|
91
|
+
},
|
|
92
|
+
onBlur: event => {
|
|
93
|
+
commitSearchText();
|
|
94
|
+
props.onBlur?.(event);
|
|
95
|
+
},
|
|
96
|
+
onInputKeyDown: event => {
|
|
97
|
+
props.onInputKeyDown?.(event);
|
|
98
|
+
if (!allowSearchText || event.key !== 'Enter' || !searchText.current) return;
|
|
99
|
+
|
|
100
|
+
// Stop Enter before the dropdown selects the active row or the grid saves again.
|
|
101
|
+
event.stopPropagation();
|
|
102
|
+
if (!event.nativeEvent.isComposing && event.keyCode !== 229) {
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
event.currentTarget.blur();
|
|
105
|
+
}
|
|
106
|
+
},
|
|
46
107
|
options: options,
|
|
47
108
|
columns: columns
|
|
48
109
|
}));
|