es-grid-template 1.9.101 → 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.
@@ -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, "position" | "left" | "right" | "display" | "width" | "minWidth"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth">);
200
- onCellHeaderStyles?: Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth">);
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, "position" | "left" | "right" | "display" | "width" | "minWidth"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "position" | "left" | "right" | "display" | "width" | "minWidth">);
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;
@@ -9,4 +9,4 @@ export interface DebounceSelectProps<OptionType extends BaseOptionType = Default
9
9
  rowData?: any;
10
10
  searchTextAsValue?: boolean;
11
11
  }
12
- export declare function AsyncTableSelect<OptionType extends BaseOptionType>({ loadOptions, debounceTimeout, defaultOptions, columns, rowData, searchTextAsValue, ...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, useRef, 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({
@@ -9,11 +9,42 @@ export function AsyncTableSelect({
9
9
  columns,
10
10
  rowData,
11
11
  searchTextAsValue,
12
+ onChange,
12
13
  ...props
13
14
  }) {
14
15
  const [options, setOptions] = useState(defaultOptions ?? []);
16
+ const selectRef = useRef(null);
15
17
  const searchText = useRef('');
16
- const allowSearchText = searchTextAsValue && !props.mode && props.selectMode !== 'checkbox';
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]);
17
48
  const debounceFetcher = useMemo(() => {
18
49
  const fetchOptions = value => {
19
50
  if (value.trim().length === 0) {
@@ -34,6 +65,8 @@ export function AsyncTableSelect({
34
65
  setOptions(defaultOptions ?? []);
35
66
  }, [defaultOptions]);
36
67
  return /*#__PURE__*/React.createElement(TableSelect, _extends({}, props, {
68
+ ref: selectRef,
69
+ popupClassName: popupClassName,
37
70
  filterOption: loadOptions ? false : props?.filterOption,
38
71
  onSearch: value => {
39
72
  searchText.current = value;
@@ -41,22 +74,14 @@ export function AsyncTableSelect({
41
74
  },
42
75
  onChange: (value, option) => {
43
76
  searchText.current = '';
44
- props.onChange?.(value, option);
77
+ onChange?.(value, option);
45
78
  },
46
79
  onSelect: () => {
47
80
  searchText.current = '';
48
81
  setOptions(defaultOptions ?? []);
49
82
  },
50
83
  onBlur: event => {
51
- const value = searchText.current;
52
- searchText.current = '';
53
- if (allowSearchText && value) {
54
- props.onChange?.(value, {
55
- value,
56
- label: value,
57
- searchTextAsValue: true
58
- });
59
- }
84
+ commitSearchText();
60
85
  props.onBlur?.(event);
61
86
  },
62
87
  onInputKeyDown: event => {
@@ -9,4 +9,4 @@ export interface DebounceSelectProps<OptionType extends BaseOptionType = Default
9
9
  rowData?: any;
10
10
  searchTextAsValue?: boolean;
11
11
  }
12
- export declare function AsyncTableSelect<OptionType extends BaseOptionType>({ loadOptions, debounceTimeout, defaultOptions, columns, rowData, searchTextAsValue, ...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;
@@ -18,11 +18,42 @@ function AsyncTableSelect({
18
18
  columns,
19
19
  rowData,
20
20
  searchTextAsValue,
21
+ onChange,
21
22
  ...props
22
23
  }) {
23
24
  const [options, setOptions] = (0, _react.useState)(defaultOptions ?? []);
25
+ const selectRef = (0, _react.useRef)(null);
24
26
  const searchText = (0, _react.useRef)('');
25
- const allowSearchText = searchTextAsValue && !props.mode && props.selectMode !== 'checkbox';
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]);
26
57
  const debounceFetcher = (0, _react.useMemo)(() => {
27
58
  const fetchOptions = value => {
28
59
  if (value.trim().length === 0) {
@@ -43,6 +74,8 @@ function AsyncTableSelect({
43
74
  setOptions(defaultOptions ?? []);
44
75
  }, [defaultOptions]);
45
76
  return /*#__PURE__*/_react.default.createElement(_rcMasterUi.TableSelect, (0, _extends2.default)({}, props, {
77
+ ref: selectRef,
78
+ popupClassName: popupClassName,
46
79
  filterOption: loadOptions ? false : props?.filterOption,
47
80
  onSearch: value => {
48
81
  searchText.current = value;
@@ -50,22 +83,14 @@ function AsyncTableSelect({
50
83
  },
51
84
  onChange: (value, option) => {
52
85
  searchText.current = '';
53
- props.onChange?.(value, option);
86
+ onChange?.(value, option);
54
87
  },
55
88
  onSelect: () => {
56
89
  searchText.current = '';
57
90
  setOptions(defaultOptions ?? []);
58
91
  },
59
92
  onBlur: event => {
60
- const value = searchText.current;
61
- searchText.current = '';
62
- if (allowSearchText && value) {
63
- props.onChange?.(value, {
64
- value,
65
- label: value,
66
- searchTextAsValue: true
67
- });
68
- }
93
+ commitSearchText();
69
94
  props.onBlur?.(event);
70
95
  },
71
96
  onInputKeyDown: event => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.9.101",
3
+ "version": "1.9.102",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",