@codezee/sixtify-brahma 0.2.151 → 0.2.153

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.
Files changed (26) hide show
  1. package/package.json +1 -1
  2. package/packages/shared-components/dist/AgGrid/AgGrid.d.ts.map +1 -1
  3. package/packages/shared-components/dist/AgGrid/AgGrid.js +4 -1
  4. package/packages/shared-components/dist/AgGrid/hooks/useAgGridCheckBoxSelection.d.ts.map +1 -1
  5. package/packages/shared-components/dist/AgGrid/hooks/useAgGridCheckBoxSelection.js +55 -39
  6. package/packages/shared-components/dist/AgGrid/hooks/useAgGridFocusManagement.d.ts +2 -0
  7. package/packages/shared-components/dist/AgGrid/hooks/useAgGridFocusManagement.d.ts.map +1 -0
  8. package/packages/shared-components/dist/AgGrid/hooks/useAgGridFocusManagement.js +105 -0
  9. package/packages/shared-components/dist/FormFields/Autocomplete/Autocomplete.d.ts +2 -1
  10. package/packages/shared-components/dist/FormFields/Autocomplete/Autocomplete.d.ts.map +1 -1
  11. package/packages/shared-components/dist/FormFields/Autocomplete/Autocomplete.js +96 -9
  12. package/packages/shared-components/dist/HighlightedText/HighlightedText.d.ts +7 -0
  13. package/packages/shared-components/dist/HighlightedText/HighlightedText.d.ts.map +1 -0
  14. package/packages/shared-components/dist/HighlightedText/HighlightedText.js +25 -0
  15. package/packages/shared-components/dist/HighlightedText/index.d.ts +2 -0
  16. package/packages/shared-components/dist/HighlightedText/index.d.ts.map +1 -0
  17. package/packages/shared-components/dist/HighlightedText/index.js +17 -0
  18. package/packages/shared-components/dist/index.d.ts +3 -2
  19. package/packages/shared-components/dist/index.d.ts.map +1 -1
  20. package/packages/shared-components/dist/index.js +3 -2
  21. package/packages/shared-components/dist/utils/hooks/useAutocompleteScrollToSelected.d.ts +5 -0
  22. package/packages/shared-components/dist/utils/hooks/useAutocompleteScrollToSelected.d.ts.map +1 -0
  23. package/packages/shared-components/dist/utils/hooks/useAutocompleteScrollToSelected.js +39 -0
  24. package/packages/shared-components/dist/utils/regex.d.ts +1 -0
  25. package/packages/shared-components/dist/utils/regex.d.ts.map +1 -1
  26. package/packages/shared-components/dist/utils/regex.js +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codezee/sixtify-brahma",
3
- "version": "0.2.151",
3
+ "version": "0.2.153",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hardikranpariya/sixtify-brahma.git"
@@ -1 +1 @@
1
- {"version":3,"file":"AgGrid.d.ts","sourceRoot":"","sources":["../../src/AgGrid/AgGrid.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,OAAO,EAGR,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAOjC,OAAO,yBAAyB,CAAC;AAUjC,eAAO,MAAM,iBAAiB,GAAI,KAAK,OAAO,CAAC,OAAO,CAAC,KAAG,IAczD,CAAC;AAEF,eAAO,MAAM,eAAe,KAAK,CAAC;AAElC,eAAO,MAAM,eAAe,UAAqB,CAAC;AAGlD,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAAG;IAC3D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,oBAAoB,C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,KAAK,CAAC,yBAAyB,CAAC,WAAW,CAAC,GAC5D,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,WAAW,CAAC,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC;AAElE,eAAO,MAAM,MAAM,EA6Pd,UAAU,CAAC"}
@@ -11,6 +11,7 @@ const AgGridStyleProvider_1 = require("./AgGridStyleProvider");
11
11
  const LoadingOverlay_1 = require("./LoadingOverlay");
12
12
  const NoDataOverlay_1 = require("./NoDataOverlay");
13
13
  require("./registerAgGridModules");
14
+ const useAgGridFocusManagement_1 = require("./hooks/useAgGridFocusManagement");
14
15
  const hideNoRowsOverlay = (api) => {
15
16
  if (!api) {
16
17
  return;
@@ -146,7 +147,9 @@ exports.AgGrid = (0, react_1.forwardRef)((props, ref) => {
146
147
  }
147
148
  }
148
149
  }, [onFilterChanged, rowModelType, updateNoRowsOverlay]);
149
- return ((0, jsx_runtime_1.jsxs)(AgGridStyleProvider_1.AgGridStyleProvider, { className: "ag-theme-quartz ", style: { width: "100%", height, position: "relative" }, children: [(0, jsx_runtime_1.jsx)(ag_grid_react_1.AgGridReact, { ref: ref, theme: "legacy", cacheBlockSize: cacheBlockSize, defaultColDef: {
150
+ const gridContainerRef = (0, react_1.useRef)(null);
151
+ (0, useAgGridFocusManagement_1.useAgGridFocusManagement)(gridContainerRef);
152
+ return ((0, jsx_runtime_1.jsxs)(AgGridStyleProvider_1.AgGridStyleProvider, { ref: gridContainerRef, className: "ag-theme-quartz ", style: { width: "100%", height, position: "relative" }, children: [(0, jsx_runtime_1.jsx)(ag_grid_react_1.AgGridReact, { ref: ref, theme: "legacy", cacheBlockSize: cacheBlockSize, defaultColDef: {
150
153
  ...defaultColumnDef,
151
154
  floatingFilter: enableSecondRowFilter,
152
155
  suppressFloatingFilterButton: enableSecondRowFilter,
@@ -1 +1 @@
1
- {"version":3,"file":"useAgGridCheckBoxSelection.d.ts","sourceRoot":"","sources":["../../../src/AgGrid/hooks/useAgGridCheck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AAC;AAsCF,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,uEAKlE,8BAA8B,CAAC,CAAC,CAAC;;6BAyCF,WAAW,CAAC,gBAAgB,CAAC;;;CAsJ9D,CAAC"}
@@ -3,24 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAgGridCheckBoxSelection = void 0;
4
4
  const react_1 = require("react");
5
5
  const utils_1 = require("../../utils");
6
- const isDialogOnTop = (gridRef) => {
6
+ const isDialogOnTop = () => {
7
+ const backdrop = document.querySelector(
8
+ // eslint-disable-next-line quotes
9
+ '.MuiBackdrop-root:not([style*="display: none"])');
10
+ if (backdrop) {
11
+ return true;
12
+ }
7
13
  const dialogs = document.querySelectorAll(
8
14
  // eslint-disable-next-line quotes
9
15
  '[role="dialog"], .MuiDialog-root, .MuiModal-root');
10
16
  if (dialogs.length === 0) {
11
17
  return false;
12
18
  }
13
- const gridContainer = gridRef.current?.api?.eGridDiv;
14
- const gridZIndex = gridContainer ? (0, utils_1.getZIndex)(gridContainer) : 0;
15
19
  for (const dialog of Array.from(dialogs)) {
16
20
  const dialogElement = dialog;
17
- const isVisible = dialogElement.offsetParent !== null ||
18
- window.getComputedStyle(dialogElement).display !== "none";
21
+ const style = window.getComputedStyle(dialogElement);
22
+ const isVisible = style.display !== "none" &&
23
+ style.visibility !== "hidden" &&
24
+ parseFloat(style.opacity) > 0;
19
25
  if (isVisible) {
20
- const dialogZIndex = (0, utils_1.getZIndex)(dialogElement);
21
- if (dialogZIndex > gridZIndex) {
22
- return true;
23
- }
26
+ return true;
24
27
  }
25
28
  }
26
29
  return false;
@@ -32,12 +35,12 @@ const useAgGridCheckBoxSelection = ({ gridRef, setSelectedEmployee, currentPageI
32
35
  return;
33
36
  }
34
37
  const api = gridRef.current.api;
35
- return currentPageItems.forEach((item) => {
36
- api.getRowNode(item.id)?.setSelected(isChecked);
38
+ return currentPageItems.forEach(({ id }) => {
39
+ api.getRowNode(id)?.setSelected(isChecked);
37
40
  });
38
41
  };
39
42
  const commonCheckBoxMethod = () => {
40
- const currentPageItemsId = currentPageItems.map((item) => item.id);
43
+ const currentPageItemsId = currentPageItems.map(({ id }) => id);
41
44
  if (!isChecked) {
42
45
  handleRowCheckBox(true);
43
46
  setIsChecked(true);
@@ -57,53 +60,66 @@ const useAgGridCheckBoxSelection = ({ gridRef, setSelectedEmployee, currentPageI
57
60
  setIsChecked(event.target.checked);
58
61
  commonCheckBoxMethod();
59
62
  };
60
- (0, utils_1.useGlobalKeyboardShortcut)({
61
- key: "a",
62
- modifierKeys: "ctrl",
63
- onTrigger: () => {
64
- if (isDialogOnTop(gridRef)) {
63
+ (0, react_1.useEffect)(() => {
64
+ const handleCtrlA = (event) => {
65
+ if (event.key.toLowerCase() !== "a" ||
66
+ (!event.ctrlKey && !event.metaKey)) {
65
67
  return;
66
68
  }
67
- if (!currentPageItems.length) {
69
+ if (isDialogOnTop()) {
68
70
  return;
69
71
  }
70
- const currentPageItemsId = currentPageItems.map((item) => item.id);
71
- if (!gridRef.current) {
72
+ const activeElement = document.activeElement;
73
+ const isInputField = activeElement?.tagName === "INPUT" ||
74
+ activeElement?.tagName === "TEXTAREA" ||
75
+ activeElement?.contentEditable === "true";
76
+ if (isInputField) {
77
+ return;
78
+ }
79
+ if (!currentPageItems.length || !gridRef.current) {
72
80
  return;
73
81
  }
82
+ event.preventDefault();
83
+ event.stopPropagation();
74
84
  const api = gridRef.current.api;
75
- currentPageItems.forEach((item) => {
76
- api.getRowNode(item.id)?.setSelected(true);
85
+ const currentPageItemsId = currentPageItems.map(({ id }) => id);
86
+ currentPageItems.forEach(({ id }) => {
87
+ api.getRowNode(id)?.setSelected(true);
77
88
  });
78
89
  setIsChecked(true);
79
- setSelectedEmployee((prev) => {
80
- const newArray = [...prev];
81
- currentPageItemsId.forEach((id) => {
82
- if (!newArray.includes(id)) {
83
- newArray.push(id);
84
- }
85
- });
86
- return newArray;
87
- });
88
- },
89
- });
90
+ const existingIds = new Set(selectedEmployee);
91
+ const idsToAdd = currentPageItemsId.filter((id) => !existingIds.has(id));
92
+ setSelectedEmployee([...selectedEmployee, ...idsToAdd]);
93
+ };
94
+ document.addEventListener("keydown", handleCtrlA, true);
95
+ return () => {
96
+ document.removeEventListener("keydown", handleCtrlA, true);
97
+ };
98
+ }, [currentPageItems, gridRef, setSelectedEmployee]);
90
99
  (0, utils_1.useGlobalKeyboardShortcut)({
91
100
  key: "a",
92
101
  modifierKeys: "alt",
93
102
  onTrigger: () => {
94
- if (isDialogOnTop(gridRef)) {
103
+ if (isDialogOnTop()) {
104
+ return;
105
+ }
106
+ const activeElement = document.activeElement;
107
+ const isInputField = activeElement?.tagName === "INPUT" ||
108
+ activeElement?.tagName === "TEXTAREA" ||
109
+ activeElement?.contentEditable === "true";
110
+ if (isInputField) {
95
111
  return;
96
112
  }
97
113
  if (!currentPageItems.length) {
98
114
  return;
99
115
  }
100
- const currentPageItemsId = currentPageItems.map((item) => item.id);
116
+ const currentPageItemsId = currentPageItems.map(({ id }) => id);
101
117
  if (!gridRef.current) {
102
118
  return;
103
119
  }
104
120
  const api = gridRef.current.api;
105
- currentPageItems.forEach((item) => {
106
- api.getRowNode(item.id)?.setSelected(false);
121
+ currentPageItems.forEach(({ id }) => {
122
+ api.getRowNode(id)?.setSelected(false);
107
123
  });
108
124
  setIsChecked(false);
109
125
  setSelectedEmployee((prev) => prev.filter((id) => !currentPageItemsId.includes(id)));
@@ -111,7 +127,7 @@ const useAgGridCheckBoxSelection = ({ gridRef, setSelectedEmployee, currentPageI
111
127
  });
112
128
  (0, react_1.useEffect)(() => {
113
129
  const isCurrentPageDataChecked = currentPageItems.length > 0 &&
114
- currentPageItems.every((item) => selectedEmployee.includes(item.id));
130
+ currentPageItems.every(({ id }) => selectedEmployee.includes(id));
115
131
  setIsChecked(isCurrentPageDataChecked);
116
132
  const handler = (event) => {
117
133
  if (event.code !== "Space") {
@@ -130,7 +146,7 @@ const useAgGridCheckBoxSelection = ({ gridRef, setSelectedEmployee, currentPageI
130
146
  header?.removeEventListener("keydown", handler);
131
147
  };
132
148
  }, [currentPageItems, selectedEmployee]);
133
- const currentPageSelectedItems = currentPageItems.filter((item) => selectedEmployee.includes(item.id)).length;
149
+ const currentPageSelectedItems = currentPageItems.filter(({ id }) => selectedEmployee.includes(id)).length;
134
150
  const isIndeterminate = (currentPageSelectedItems &&
135
151
  currentPageSelectedItems < currentPageItems.length) ||
136
152
  false;
@@ -0,0 +1,2 @@
1
+ export declare const useAgGridFocusManagement: (containerRef: React.RefObject<HTMLElement>) => void;
2
+ //# sourceMappingURL=useAgGridFocusManagement.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAgGridFocusManagement.d.ts","sourceRoot":"","sources":["../../../src/AgGrid/hooks/useAgGridFocusManagement.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,wBAAwB,GACnC,cAAc,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,SAuJ3C,CAAC"}
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAgGridFocusManagement = void 0;
4
+ /* eslint-disable sonarjs/cognitive-complexity */
5
+ /* eslint-disable sonarjs/no-nested-functions */
6
+ const react_1 = require("react");
7
+ const useAgGridFocusManagement = (containerRef) => {
8
+ const rafRef = (0, react_1.useRef)(null);
9
+ const secondHeaderCellRef = (0, react_1.useRef)(null);
10
+ (0, react_1.useEffect)(() => {
11
+ const container = containerRef.current;
12
+ if (!container) {
13
+ return;
14
+ }
15
+ const getSecondHeaderCell = () => {
16
+ const cached = secondHeaderCellRef.current;
17
+ if (cached && container.contains(cached)) {
18
+ return cached;
19
+ }
20
+ const headerCells = container.querySelectorAll(".ag-header-cell:not(.ag-column-first)");
21
+ const cell = headerCells.length > 0 ? headerCells[0] : null;
22
+ secondHeaderCellRef.current = cell ?? null;
23
+ return cell ?? null;
24
+ };
25
+ const preventUnwantedFocus = () => {
26
+ if (rafRef.current !== null) {
27
+ return;
28
+ }
29
+ rafRef.current = requestAnimationFrame(() => {
30
+ rafRef.current = null;
31
+ const firstHeaderCells = container.querySelectorAll(".ag-header-cell.ag-column-first:not(.ag-floating-filter)");
32
+ firstHeaderCells.forEach((cell) => {
33
+ if (cell.tabIndex !== -1) {
34
+ cell.tabIndex = -1;
35
+ }
36
+ const interactiveElements = cell.querySelectorAll("input, button, select, textarea, [tabindex]:not([tabindex='-1'])");
37
+ interactiveElements.forEach((el) => {
38
+ if (el.tabIndex !== -1) {
39
+ el.tabIndex = -1;
40
+ }
41
+ });
42
+ });
43
+ secondHeaderCellRef.current = null;
44
+ });
45
+ };
46
+ const handleFocusRedirect = (e) => {
47
+ const target = e.target;
48
+ if (!container.contains(target)) {
49
+ return;
50
+ }
51
+ const isFirstHeader = target.closest(".ag-header-cell.ag-column-first:not(.ag-floating-filter)") !== null;
52
+ if (!isFirstHeader) {
53
+ return;
54
+ }
55
+ const secondCell = getSecondHeaderCell();
56
+ if (!secondCell) {
57
+ return;
58
+ }
59
+ e.preventDefault();
60
+ e.stopPropagation();
61
+ requestAnimationFrame(() => {
62
+ secondCell.focus();
63
+ });
64
+ };
65
+ const observer = new MutationObserver((mutations) => {
66
+ const shouldUpdate = mutations.some((mutation) => {
67
+ const target = mutation.target;
68
+ if (target.classList?.contains("ag-header") ||
69
+ target.classList?.contains("ag-header-cell") ||
70
+ target.classList?.contains("ag-header-row")) {
71
+ return true;
72
+ }
73
+ const hasHeaderNodes = Array.from(mutation.addedNodes).some((node) => node instanceof HTMLElement &&
74
+ (node.classList.contains("ag-header-cell") ||
75
+ node.classList.contains("ag-header-row") ||
76
+ node.querySelector(".ag-header-cell, .ag-header-row")));
77
+ return hasHeaderNodes;
78
+ });
79
+ if (shouldUpdate) {
80
+ preventUnwantedFocus();
81
+ }
82
+ });
83
+ const header = container.querySelector(".ag-header");
84
+ if (header instanceof HTMLElement) {
85
+ observer.observe(header, {
86
+ childList: true,
87
+ subtree: true,
88
+ attributes: true,
89
+ attributeFilter: ["class", "tabindex"],
90
+ });
91
+ }
92
+ observer.observe(container, { childList: true });
93
+ container.addEventListener("focusin", handleFocusRedirect, true);
94
+ preventUnwantedFocus();
95
+ return () => {
96
+ if (rafRef.current !== null) {
97
+ cancelAnimationFrame(rafRef.current);
98
+ }
99
+ observer.disconnect();
100
+ container.removeEventListener("focusin", handleFocusRedirect, true);
101
+ secondHeaderCellRef.current = null;
102
+ };
103
+ }, [containerRef]);
104
+ };
105
+ exports.useAgGridFocusManagement = useAgGridFocusManagement;
@@ -34,6 +34,7 @@ export type AutocompleteProps<P extends FieldValues> = UseControllerProps<P> & O
34
34
  setValue?: UseFormSetValue<P>;
35
35
  containerProps?: StackProps;
36
36
  styling?: "custom" | "default";
37
+ customOnChange?: (selected: any) => void;
37
38
  };
38
- export declare function Autocomplete<P extends FieldValues>({ control, defaultValue, name, required, label, multiple, disabled, options, rules, loading, helperText, error, withLabel, placeholder, freeSolo, isShowOptionsOnType, isShowSelectAll, isShowAvatar, isShowEmployeeData, shouldCloseOnSelect, onAction, renderOption, getOptionLabel, maxLimit, autoFocus, defaultOption, disableClearable, containerProps, setValue, limitTags, styling, ...restProps }: AutocompleteProps<P>): import("react/jsx-runtime").JSX.Element;
39
+ export declare function Autocomplete<P extends FieldValues>({ control, defaultValue, name, required, label, multiple, disabled, options, rules, loading, helperText, error, withLabel, placeholder, freeSolo, isShowOptionsOnType, isShowSelectAll, isShowAvatar, isShowEmployeeData, shouldCloseOnSelect, onAction, renderOption, getOptionLabel, maxLimit, autoFocus, defaultOption, disableClearable, containerProps, setValue, limitTags, styling, customOnChange, ...restProps }: AutocompleteProps<P>): import("react/jsx-runtime").JSX.Element;
39
40
  //# sourceMappingURL=Autocomplete.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Autocomplete.d.ts","sourceRoot":"","sources":["../../../src/FormFields/Autocomplete/Autocomplete.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV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exports.Autocomplete = Autocomplete;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const material_1 = require("@mui/material");
9
9
  const styles_1 = require("@mui/material/styles");
10
+ const filter_1 = __importDefault(require("lodash/filter"));
11
+ const find_1 = __importDefault(require("lodash/find"));
12
+ const isArray_1 = __importDefault(require("lodash/isArray"));
10
13
  const isFunction_1 = __importDefault(require("lodash/isFunction"));
14
+ const isObject_1 = __importDefault(require("lodash/isObject"));
15
+ const isString_1 = __importDefault(require("lodash/isString"));
16
+ const map_1 = __importDefault(require("lodash/map"));
11
17
  const react_1 = require("react");
12
18
  const react_hook_form_1 = require("react-hook-form");
13
19
  const react_i18next_1 = require("react-i18next");
14
20
  const Actions_1 = require("../../Actions");
15
21
  const Toast_1 = require("../../Toast");
16
22
  const Tooltip_1 = require("../../Tooltip");
23
+ const useAutocompleteScrollToSelected_1 = require("../../utils/hooks/useAutocompleteScrollToSelected");
17
24
  const CheckBox_styled_1 = require("../CheckBox/CheckBox.styled");
18
25
  const commonStyles_1 = require("../commonStyles");
19
26
  const ChipV2_styled_1 = require("./ChipV2.styled");
20
27
  const Skeleton_1 = require("./Skeleton");
21
28
  const Tags_1 = require("./Tags");
22
- function Autocomplete({ control, defaultValue, name, required = false, label, multiple = false, disabled = false, options = [], rules, loading = false, helperText, error, withLabel = false, placeholder = "", freeSolo, isShowOptionsOnType = false, isShowSelectAll = true, isShowAvatar = false, isShowEmployeeData = false, shouldCloseOnSelect = false, onAction, renderOption, getOptionLabel, maxLimit, autoFocus = false, defaultOption, disableClearable = required ? true : false, containerProps, setValue, limitTags = 0, styling = "custom", ...restProps }) {
29
+ function Autocomplete({ control, defaultValue, name, required = false, label, multiple = false, disabled = false, options = [], rules, loading = false, helperText, error, withLabel = false, placeholder = "", freeSolo, isShowOptionsOnType = false, isShowSelectAll = true, isShowAvatar = false, isShowEmployeeData = false, shouldCloseOnSelect = false, onAction, renderOption, getOptionLabel, maxLimit, autoFocus = false, defaultOption, disableClearable = required ? true : false, containerProps, setValue, limitTags = 0, styling = "custom", customOnChange, ...restProps }) {
23
30
  const { field: { onChange, value, ...restField }, } = (0, react_hook_form_1.useController)({
24
31
  name,
25
32
  control,
@@ -28,15 +35,56 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
28
35
  });
29
36
  const { t } = (0, react_i18next_1.useTranslation)();
30
37
  const [inputValue, setInputValue] = (0, react_1.useState)("");
38
+ const convertValueToOption = (val) => {
39
+ const foundOption = (0, find_1.default)(options, (option) => option.value === val);
40
+ return foundOption || { label: String(val), value: val };
41
+ };
42
+ const convertToOption = (item) => {
43
+ return (0, isString_1.default)(item) ? { label: item, value: item } : item;
44
+ };
45
+ const formatValueForCustomOnChange = (newValue, isMultiple, selectedValues) => {
46
+ if (!customOnChange) {
47
+ return;
48
+ }
49
+ if (isMultiple && (0, isArray_1.default)(selectedValues)) {
50
+ const formattedValues = (0, filter_1.default)((0, map_1.default)(selectedValues, convertValueToOption), (option) => option.value !== "select-all");
51
+ customOnChange(formattedValues);
52
+ }
53
+ else if (isMultiple && (0, isArray_1.default)(newValue)) {
54
+ const formattedValues = (0, map_1.default)((0, filter_1.default)(newValue, (option) => (0, isString_1.default)(option) ||
55
+ ((0, isObject_1.default)(option) && option?.value !== "select-all")), convertToOption);
56
+ customOnChange(formattedValues);
57
+ }
58
+ else if (!isMultiple) {
59
+ if ((0, isString_1.default)(newValue)) {
60
+ customOnChange({ label: newValue, value: newValue });
61
+ }
62
+ else if ((0, isObject_1.default)(newValue) && !(0, isArray_1.default)(newValue)) {
63
+ customOnChange(newValue);
64
+ }
65
+ else {
66
+ customOnChange(null);
67
+ }
68
+ }
69
+ };
70
+ const [open, setOpen] = (0, react_1.useState)(false);
71
+ const listboxRef = (0, react_1.useRef)(null);
72
+ const { setLastSelectedValue } = (0, useAutocompleteScrollToSelected_1.useAutocompleteScrollToSelected)(listboxRef, value);
31
73
  const handleSelectAll = (isSelected) => {
32
74
  const disabledOptions = options.filter((option) => option.disabled);
33
75
  const disabledValues = disabledOptions.map((option) => option.value);
34
76
  if (isSelected) {
35
77
  const allValues = options.map((option) => option.value);
36
78
  onChange(allValues);
79
+ if (customOnChange) {
80
+ customOnChange([...options]);
81
+ }
37
82
  }
38
83
  else {
39
84
  onChange(disabledValues);
85
+ if (customOnChange) {
86
+ customOnChange([...disabledOptions]);
87
+ }
40
88
  }
41
89
  };
42
90
  const isAllSelected = (0, react_1.useMemo)(() => {
@@ -91,7 +139,7 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
91
139
  const { palette: { app: { color }, }, } = (0, material_1.useTheme)();
92
140
  const StyledPaper = (0, styles_1.styled)(material_1.Paper)(({ theme }) => ({
93
141
  "& .MuiAutocomplete-listbox": {
94
- maxHeight: 300,
142
+ maxHeight: 150,
95
143
  overflowY: "auto",
96
144
  marginTop: "0px",
97
145
  "&::-webkit-scrollbar": {
@@ -109,6 +157,19 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
109
157
  },
110
158
  },
111
159
  }));
160
+ const CustomPaperComponent = (0, react_1.useCallback)((props) => {
161
+ const handlePaperRef = (paperElement) => {
162
+ if (paperElement) {
163
+ setTimeout(() => {
164
+ const listbox = paperElement.querySelector(".MuiAutocomplete-listbox");
165
+ if (listbox) {
166
+ listboxRef.current = listbox;
167
+ }
168
+ }, 0);
169
+ }
170
+ };
171
+ return ((0, jsx_runtime_1.jsx)(StyledPaper, { ...props, ref: handlePaperRef, children: props.children }));
172
+ }, []);
112
173
  const GroupHeader = (0, styles_1.styled)("div")(({ theme }) => ({
113
174
  position: "sticky",
114
175
  padding: "4px 10px",
@@ -123,7 +184,7 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
123
184
  if (loading) {
124
185
  return (0, jsx_runtime_1.jsx)(Skeleton_1.Skeleton, { label: label, styling: styling });
125
186
  }
126
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: "5px", ...containerProps, children: [label && styling === "custom" && ((0, jsx_runtime_1.jsx)(material_1.InputLabel, { sx: { fontSize: { xs: "14px", md: "16px" } }, required: required, disabled: disabled, children: label })), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", justifyContent: "space-between", gap: "10px", alignItems: "start", children: [(0, jsx_runtime_1.jsx)(material_1.Autocomplete, { PopperComponent: material_1.Popper, PaperComponent: StyledPaper, sx: {
187
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: "5px", ...containerProps, children: [label && styling === "custom" && ((0, jsx_runtime_1.jsx)(material_1.InputLabel, { sx: { fontSize: { xs: "14px", md: "16px" } }, required: required, disabled: disabled, children: label })), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", justifyContent: "space-between", gap: "10px", alignItems: "start", children: [(0, jsx_runtime_1.jsx)(material_1.Autocomplete, { PopperComponent: material_1.Popper, PaperComponent: CustomPaperComponent, sx: {
127
188
  "& .MuiAutocomplete-tag": {
128
189
  backgroundColor: (0, styles_1.alpha)(color.iron[700], 0.6),
129
190
  color: color.black[900],
@@ -136,7 +197,22 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
136
197
  borderRadius: "50%",
137
198
  },
138
199
  width: "100%",
139
- }, disableCloseOnSelect: multiple || !shouldCloseOnSelect, disabled: disabled, freeSolo: freeSolo, ...restProps, ...restField, disableClearable: disableClearable, renderTags: (value, getTagProps) => {
200
+ }, open: open, onOpen: () => setOpen(true), onClose: () => setOpen(false), disableCloseOnSelect: multiple || !shouldCloseOnSelect, disabled: disabled, freeSolo: freeSolo, ...restProps, ...restField, disableClearable: disableClearable, componentsProps: {
201
+ popper: {
202
+ modifiers: [
203
+ {
204
+ name: "preventOverflow",
205
+ enabled: true,
206
+ options: {
207
+ altAxis: true,
208
+ altBoundary: true,
209
+ tether: true,
210
+ rootBoundary: "document",
211
+ },
212
+ },
213
+ ],
214
+ },
215
+ }, renderTags: (value, getTagProps) => {
140
216
  const visibleTags = limitTags ? value.slice(0, limitTags) : value;
141
217
  const hiddenCount = value.length - visibleTags.length;
142
218
  const hiddenTags = limitTags ? value.slice(limitTags) : value;
@@ -150,7 +226,7 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
150
226
  const { label, avatar, employee_code, punch_code, value } = option;
151
227
  const { key, ...optionProps } = props;
152
228
  const isSelectAll = value === "select-all";
153
- return ((0, jsx_runtime_1.jsx)("li", { ...optionProps, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: "5px", children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", gap: "10px", alignItems: "center", children: [multiple && ((0, jsx_runtime_1.jsx)(material_1.Checkbox, { icon: (0, jsx_runtime_1.jsx)(CheckBox_styled_1.BoxStyled, { size: "small" }), checkedIcon: (0, jsx_runtime_1.jsx)(CheckBox_styled_1.CheckStyled, { size: "small" }), indeterminate: !isAllSelected && selectedValue?.length && isSelectAll
229
+ return ((0, jsx_runtime_1.jsx)("li", { ...optionProps, "data-option-value": value, tabIndex: -1, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: "5px", children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", gap: "10px", alignItems: "center", children: [multiple && ((0, jsx_runtime_1.jsx)(material_1.Checkbox, { icon: (0, jsx_runtime_1.jsx)(CheckBox_styled_1.BoxStyled, { size: "small" }), checkedIcon: (0, jsx_runtime_1.jsx)(CheckBox_styled_1.CheckStyled, { size: "small" }), indeterminate: !isAllSelected && selectedValue?.length && isSelectAll
154
230
  ? true
155
231
  : false, checked: isAllSelected ? true : selected, sx: {
156
232
  marginRight: "8px",
@@ -192,7 +268,9 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
192
268
  setInputValue("");
193
269
  }
194
270
  if (withLabel) {
195
- return onChange(newValue);
271
+ onChange(newValue);
272
+ formatValueForCustomOnChange(newValue, false);
273
+ return;
196
274
  }
197
275
  if (multiple && Array.isArray(newValue)) {
198
276
  const disabledSelectedOptions = options.filter(({ disabled, value: disabledValue }) => disabled && value?.includes(disabledValue));
@@ -204,6 +282,8 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
204
282
  const enabledNewValues = newValue
205
283
  .map((option) => typeof option === "string" ? option : option.value)
206
284
  .filter((val) => !disabledSelectedOptions.some((d) => d.value === val));
285
+ const lastSelected = enabledNewValues[enabledNewValues.length - 1];
286
+ setLastSelectedValue(lastSelected ?? null);
207
287
  const mergedValues = [
208
288
  ...disabledSelectedOptions.map(({ value }) => value),
209
289
  ...enabledNewValues,
@@ -214,12 +294,19 @@ function Autocomplete({ control, defaultValue, name, required = false, label, mu
214
294
  });
215
295
  return;
216
296
  }
217
- return onChange(mergedValues);
297
+ onChange(mergedValues);
298
+ formatValueForCustomOnChange(newValue, true, mergedValues);
299
+ return;
218
300
  }
219
301
  if (typeof newValue === "string") {
220
- return onChange(newValue ?? null);
302
+ onChange(newValue ?? null);
303
+ formatValueForCustomOnChange(newValue, false);
304
+ return;
221
305
  }
222
- onChange(newValue && !Array.isArray(newValue) ? newValue.value : null);
306
+ const finalValue = newValue && !Array.isArray(newValue) ? newValue.value : null;
307
+ onChange(finalValue);
308
+ formatValueForCustomOnChange(newValue, false);
309
+ setLastSelectedValue(finalValue);
223
310
  }, groupBy: (option) => option.heading ?? "", renderGroup: (params) => {
224
311
  if (!params.group) {
225
312
  return (0, jsx_runtime_1.jsx)(material_1.Box, { children: params.children });
@@ -0,0 +1,7 @@
1
+ type HighlightedTextProps = {
2
+ text: string;
3
+ highlightWords?: string[];
4
+ };
5
+ export declare const HighlightedText: ({ text, highlightWords, }: HighlightedTextProps) => JSX.Element;
6
+ export {};
7
+ //# sourceMappingURL=HighlightedText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HighlightedText.d.ts","sourceRoot":"","sources":["../../src/HighlightedText/HighlightedText.tsx"],"names":[],"mappings":"AAIA,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,2BAG7B,oBAAoB,KAAG,GAAG,CAAC,OA2C7B,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HighlightedText = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const material_1 = require("@mui/material");
6
+ const regex_1 = require("../utils/regex");
7
+ const HighlightedText = ({ text, highlightWords, }) => {
8
+ const theme = (0, material_1.useTheme)();
9
+ const { slate } = theme.palette.app.color;
10
+ if (!highlightWords?.length) {
11
+ return (0, jsx_runtime_1.jsx)(material_1.Box, { component: "span", children: text });
12
+ }
13
+ const escapedWords = highlightWords.map((w) => w.replace(regex_1.highlightWordsRegex, "\\$&"));
14
+ const pattern = new RegExp(`(${escapedWords.join("|")})`, "gi");
15
+ const segments = text.split(pattern);
16
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "span", children: segments.map((segment, index) => pattern.test(segment) ? ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "span", sx: {
17
+ padding: "2px 4px",
18
+ backgroundColor: slate[800],
19
+ border: `1px solid ${slate[700]}`,
20
+ borderRadius: "5px",
21
+ fontFamily: "monospace",
22
+ fontSize: "0.9em",
23
+ }, children: segment }, `highlight-${index}-${segment}`)) : ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "span", children: segment }, `text-${index}-${segment}`))) }));
24
+ };
25
+ exports.HighlightedText = HighlightedText;
@@ -0,0 +1,2 @@
1
+ export * from "./HighlightedText";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/HighlightedText/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./HighlightedText"), exports);
@@ -8,14 +8,15 @@ export * from "./Button";
8
8
  export * from "./Card";
9
9
  export * from "./CellSelectionTable";
10
10
  export * from "./Charts";
11
- export * from "./codeSnippetBox";
12
11
  export * from "./Chips";
12
+ export * from "./codeSnippetBox";
13
13
  export * from "./ColumnArranger";
14
14
  export * from "./ContentBox";
15
15
  export * from "./Dialog";
16
16
  export * from "./Drawer";
17
17
  export * from "./FilterList";
18
18
  export * from "./FormFields";
19
+ export * from "./HighlightedText";
19
20
  export * from "./Indicator";
20
21
  export * from "./Layouts";
21
22
  export * from "./Loader";
@@ -31,7 +32,7 @@ export * from "./TabBar";
31
32
  export * from "./Timeline";
32
33
  export * from "./Toast";
33
34
  export * from "./Tooltip";
35
+ export * from "./Tree";
34
36
  export * from "./UserProfileMenu";
35
37
  export * from "./utils";
36
- export * from "./Tree";
37
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,sBAAsB,CAAC;AACrC,cAAc,UAAU,C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cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC"}
@@ -24,14 +24,15 @@ __exportStar(require("./Button"), exports);
24
24
  __exportStar(require("./Card"), exports);
25
25
  __exportStar(require("./CellSelectionTable"), exports);
26
26
  __exportStar(require("./Charts"), exports);
27
- __exportStar(require("./codeSnippetBox"), exports);
28
27
  __exportStar(require("./Chips"), exports);
28
+ __exportStar(require("./codeSnippetBox"), exports);
29
29
  __exportStar(require("./ColumnArranger"), exports);
30
30
  __exportStar(require("./ContentBox"), exports);
31
31
  __exportStar(require("./Dialog"), exports);
32
32
  __exportStar(require("./Drawer"), exports);
33
33
  __exportStar(require("./FilterList"), exports);
34
34
  __exportStar(require("./FormFields"), exports);
35
+ __exportStar(require("./HighlightedText"), exports);
35
36
  __exportStar(require("./Indicator"), exports);
36
37
  __exportStar(require("./Layouts"), exports);
37
38
  __exportStar(require("./Loader"), exports);
@@ -47,6 +48,6 @@ __exportStar(require("./TabBar"), exports);
47
48
  __exportStar(require("./Timeline"), exports);
48
49
  __exportStar(require("./Toast"), exports);
49
50
  __exportStar(require("./Tooltip"), exports);
51
+ __exportStar(require("./Tree"), exports);
50
52
  __exportStar(require("./UserProfileMenu"), exports);
51
53
  __exportStar(require("./utils"), exports);
52
- __exportStar(require("./Tree"), exports);
@@ -0,0 +1,5 @@
1
+ export declare function useAutocompleteScrollToSelected(listboxRef: React.RefObject<HTMLUListElement>, value: string | number | (string | number)[] | null, delay?: number): {
2
+ lastSelectedValueRef: import("react").MutableRefObject<string | number | null>;
3
+ setLastSelectedValue: (selectedValue: string | number | null) => void;
4
+ };
5
+ //# sourceMappingURL=useAutocompleteScrollToSelected.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAutocompleteScrollToSelected.d.ts","sourceRoot":"","sources":["../../../src/utils/hooks/useAutocompleteScrollToSelected.ts"],"names":[],"mappings":"AAEA,wBAAgB,+BAA+B,CAC7C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAC7C,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,GAAG,IAAI,EACnD,KAAK,GAAE,MAAY;;0CAyCqB,MAAM,GAAG,MAAM,GAAG,IAAI;EAI/D"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useAutocompleteScrollToSelected = useAutocompleteScrollToSelected;
4
+ const react_1 = require("react");
5
+ function useAutocompleteScrollToSelected(listboxRef, value, delay = 300) {
6
+ const lastSelectedValueRef = (0, react_1.useRef)(null);
7
+ (0, react_1.useEffect)(() => {
8
+ if (lastSelectedValueRef.current === null || !listboxRef.current) {
9
+ return;
10
+ }
11
+ const timeoutId = setTimeout(() => {
12
+ const listbox = listboxRef.current;
13
+ if (!listbox) {
14
+ lastSelectedValueRef.current = null;
15
+ return;
16
+ }
17
+ const selector = `[data-option-value="${lastSelectedValueRef.current}"]`;
18
+ const optionElement = listbox.querySelector(selector);
19
+ if (optionElement) {
20
+ requestAnimationFrame(() => {
21
+ optionElement.scrollIntoView({
22
+ block: "nearest",
23
+ behavior: "smooth",
24
+ });
25
+ });
26
+ }
27
+ lastSelectedValueRef.current = null;
28
+ }, delay);
29
+ return () => {
30
+ clearTimeout(timeoutId);
31
+ };
32
+ }, [value, delay, listboxRef]);
33
+ return {
34
+ lastSelectedValueRef,
35
+ setLastSelectedValue: (selectedValue) => {
36
+ lastSelectedValueRef.current = selectedValue;
37
+ },
38
+ };
39
+ }
@@ -5,4 +5,5 @@ export declare const emailRegex: RegExp;
5
5
  export declare const timeRegex: RegExp;
6
6
  export declare const accessorFnRegex: RegExp;
7
7
  export declare const hslaRegex: RegExp;
8
+ export declare const highlightWordsRegex: RegExp;
8
9
  //# sourceMappingURL=regex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/utils/regex.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,QAAkB,CAAC;AAE9C,eAAO,MAAM,YAAY,QAAwB,CAAC;AAElD,eAAO,MAAM,uBAAuB,QAAoB,CAAC;AAEzD,eAAO,MAAM,UAAU,QACmvB,CAAC;AAE3wB,eAAO,MAAM,SAAS,QAA6B,CAAC;AAEpD,eAAO,MAAM,eAAe,QACqD,CAAC;AAElF,eAAO,MAAM,SAAS,QAAqD,CAAC"}
1
+ {"version":3,"file":"regex.d.ts","sourceRoot":"","sources":["../../src/utils/regex.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,QAAkB,CAAC;AAE9C,eAAO,MAAM,YAAY,QAAwB,CAAC;AAElD,eAAO,MAAM,uBAAuB,QAAoB,CAAC;AAEzD,eAAO,MAAM,UAAU,QACmvB,CAAC;AAE3wB,eAAO,MAAM,SAAS,QAA6B,CAAC;AAEpD,eAAO,MAAM,eAAe,QACqD,CAAC;AAElF,eAAO,MAAM,SAAS,QAAqD,CAAC;AAE5E,eAAO,MAAM,mBAAmB,QAAwB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hslaRegex = exports.accessorFnRegex = exports.timeRegex = exports.emailRegex = exports.noSpecialCharacterRegex = exports.isoDateRegex = exports.monthYearRegex = void 0;
3
+ exports.highlightWordsRegex = exports.hslaRegex = exports.accessorFnRegex = exports.timeRegex = exports.emailRegex = exports.noSpecialCharacterRegex = exports.isoDateRegex = exports.monthYearRegex = void 0;
4
4
  /* eslint-disable sonarjs/unnecessary-character-escapes */
5
5
  /* eslint-disable no-useless-escape */
6
6
  /* eslint-disable sonarjs/single-character-alternation */
@@ -16,3 +16,4 @@ exports.emailRegex = /^(((?!.*[^\x00-\x7F])[^<>()[\]\\.,;:\s@"](\.[^<>()[\]\\.,;
16
16
  exports.timeRegex = /^\d{1,3}:\d{2}(:\d{2})?$/;
17
17
  exports.accessorFnRegex = /([a-zA-Z0-9_$.\[\]]+)\s*!==\s*null\s*&&\s*\1\s*!==\s*void 0\s*\?\s*\1\s*:\s*/g;
18
18
  exports.hslaRegex = /hsla?\((\d+),\s*(\d+)%,\s*(\d+)%,?\s*([\d.]+)?\)/;
19
+ exports.highlightWordsRegex = /[.*+?^${}()|[\]\\]/g;