@monolith-forensics/monolith-ui 1.1.56 → 1.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,15 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
11
  import moment from "moment";
3
- import { useFloating, flip, offset, FloatingPortal, useDismiss, useInteractions, autoUpdate } from "@floating-ui/react";
12
+ import { useFloating, flip, offset, FloatingPortal, useDismiss, useInteractions, autoUpdate, } from "@floating-ui/react";
4
13
  import { useEffect, useMemo, useRef, useState, } from "react";
5
14
  import styled from "styled-components";
6
15
  import { FieldLabel, Calendar } from "..";
@@ -246,9 +255,7 @@ const DateInput = styled(({ className, defaultValue, format = "YYYY-MM-DD HH:mm:
246
255
  whileElementsMounted: autoUpdate,
247
256
  });
248
257
  const dismiss = useDismiss(context);
249
- const { getReferenceProps } = useInteractions([
250
- dismiss,
251
- ]);
258
+ const { getReferenceProps } = useInteractions([dismiss]);
252
259
  const segments = useMemo(() => parseTimestamp(moment(value).toISOString(), format, utc), [value, format, utc]);
253
260
  const checkValidRange = (value) => {
254
261
  if (min && moment(value).isBefore(min))
@@ -319,6 +326,7 @@ const DateInput = styled(({ className, defaultValue, format = "YYYY-MM-DD HH:mm:
319
326
  const next = segments[prev.index + 2];
320
327
  return next || prev;
321
328
  });
329
+ typedKeys.current = ""; // clear typed keys when moving to next segment
322
330
  }
323
331
  // Left Arrow
324
332
  if (e.key === "ArrowLeft") {
@@ -329,6 +337,7 @@ const DateInput = styled(({ className, defaultValue, format = "YYYY-MM-DD HH:mm:
329
337
  const next = segments[prev.index - 2];
330
338
  return next || prev;
331
339
  });
340
+ typedKeys.current = ""; // clear typed keys when moving to next segment
332
341
  }
333
342
  // Up Arrow
334
343
  if (e.key === "ArrowUp") {
@@ -368,7 +377,7 @@ const DateInput = styled(({ className, defaultValue, format = "YYYY-MM-DD HH:mm:
368
377
  }
369
378
  // handle paste
370
379
  if (e.key === "v" && (e.metaKey || e.ctrlKey)) {
371
- return;
380
+ handlePaste();
372
381
  }
373
382
  // only allow numbers
374
383
  if (e.key.match(/[0-9]/)) {
@@ -383,7 +392,8 @@ const DateInput = styled(({ className, defaultValue, format = "YYYY-MM-DD HH:mm:
383
392
  setValue((prev) => {
384
393
  if (!(selectedSegment === null || selectedSegment === void 0 ? void 0 : selectedSegment.momentType))
385
394
  return prev;
386
- const newValue = moment(prev)
395
+ const momentValue = utc ? moment.utc(prev) : moment(prev);
396
+ const newValue = moment(momentValue)
387
397
  .set(selectedSegment.momentType, parseInt(tempValue, 10) -
388
398
  (selectedSegment.type === "month" ? 1 : 0))
389
399
  .toISOString();
@@ -397,36 +407,87 @@ const DateInput = styled(({ className, defaultValue, format = "YYYY-MM-DD HH:mm:
397
407
  typedKeys.current = "";
398
408
  }
399
409
  }
400
- e.preventDefault();
401
410
  };
402
411
  const handleWheelEvent = (e) => {
403
412
  if (!selectedSegment)
404
413
  return;
405
- setValue((prev) => {
406
- if (selectedSegment.type === "separator")
407
- return prev;
408
- if (!prev)
409
- return isDateOnly ? moment().format(format) : moment().toISOString();
410
- let newValue = e.deltaY > 0 ? moment(prev).subtract(1, selectedSegment.type).toISOString() : moment(prev).add(1, selectedSegment.type).toISOString();
411
- if (!checkValidRange(newValue))
412
- return prev;
413
- newValue = isDateOnly ? moment(newValue).format(format) : newValue;
414
- onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
415
- return newValue;
416
- });
414
+ if (e.deltaY > 0) {
415
+ setValue((prev) => {
416
+ if (selectedSegment.type === "separator")
417
+ return prev;
418
+ const newValue = prev
419
+ ? moment(prev).subtract(1, selectedSegment.type).toISOString()
420
+ : moment().toISOString();
421
+ if (!checkValidRange(newValue))
422
+ return prev;
423
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
424
+ return newValue;
425
+ });
426
+ }
427
+ else {
428
+ setValue((prev) => {
429
+ if (selectedSegment.type === "separator")
430
+ return prev;
431
+ const newValue = prev
432
+ ? moment(prev).add(1, selectedSegment.type).toISOString()
433
+ : moment().toISOString();
434
+ if (!checkValidRange(newValue))
435
+ return prev;
436
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
437
+ return newValue;
438
+ });
439
+ }
417
440
  };
418
- const handlePaste = (e) => {
419
- var _a, _b;
420
- e.preventDefault();
421
- const pastedText = (_b = (_a = e === null || e === void 0 ? void 0 : e.clipboardData) === null || _a === void 0 ? void 0 : _a.getData) === null || _b === void 0 ? void 0 : _b.call(_a, "text");
441
+ const handlePaste = (e) => __awaiter(void 0, void 0, void 0, function* () {
442
+ const pastedText = yield window.navigator.clipboard.readText();
422
443
  if (!pastedText)
444
+ return; // do nothing if clipboard is empty
445
+ // check for unix timestamp in seconds
446
+ if (pastedText.match(/^\d{10}$/)) {
447
+ const parsedTimestamp = moment
448
+ .unix(parseInt(pastedText, 10))
449
+ .toISOString();
450
+ setValue(parsedTimestamp);
451
+ return;
452
+ }
453
+ // check for unix timestamp in seconds with fractional seconds
454
+ if (pastedText.match(/^\d{10}\.\d{1,6}$/)) {
455
+ const parsedTimestamp = moment
456
+ .unix(parseFloat(pastedText))
457
+ .toISOString();
458
+ setValue(parsedTimestamp);
423
459
  return;
424
- // check if pasted text is a valid timestamp
460
+ }
461
+ // check for unix timestamp in milliseconds
462
+ if (pastedText.match(/^\d{13}$/)) {
463
+ const parsedTimestamp = moment
464
+ .unix(parseInt(pastedText, 10) / 1000)
465
+ .toISOString();
466
+ setValue(parsedTimestamp);
467
+ return;
468
+ }
469
+ // check for windows ldap or filetime timestamp
470
+ if (pastedText.match(/^\d{18}$/)) {
471
+ const parsedTimestamp = moment
472
+ .unix((parseInt(pastedText, 10) - 116444736000000000) / 10000000)
473
+ .toISOString();
474
+ setValue(parsedTimestamp);
475
+ return;
476
+ }
477
+ // check for YMD ldap timestamp in format YYYYMMDDHHMMSSZ
478
+ if (pastedText.match(/^\d{14}Z$/)) {
479
+ const parsedTimestamp = moment
480
+ .utc(pastedText, "YYYYMMDDHHmmssZ")
481
+ .toISOString();
482
+ setValue(parsedTimestamp);
483
+ return;
484
+ }
485
+ // check if pasted text is any other valid timestamp
425
486
  if (!moment(pastedText).isValid())
426
487
  return;
427
488
  const parsedTimestamp = moment.utc(pastedText).toISOString();
428
489
  setValue(parsedTimestamp);
429
- };
490
+ });
430
491
  // Close on outside click
431
492
  useEffect(() => {
432
493
  const close = (e) => {
@@ -458,7 +519,7 @@ const DateInput = styled(({ className, defaultValue, format = "YYYY-MM-DD HH:mm:
458
519
  return (_jsxs("div", { className: className, children: [label && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsxs(StyledInputContainer, { ref: (ref) => {
459
520
  mainRef.current = ref;
460
521
  refs.setReference(ref);
461
- }, onClick: handleContainerClick, onMouseDown: handleMouseDown, onKeyDown: handleKeyDown, onPaste: handlePaste, onFocus: (e) => {
522
+ }, onClick: handleContainerClick, onMouseDown: handleMouseDown, onKeyDown: handleKeyDown, onFocus: (e) => {
462
523
  e.preventDefault();
463
524
  setSelectedSegment(segments[0]);
464
525
  }, onBlur: () => {
@@ -471,7 +532,7 @@ const DateInput = styled(({ className, defaultValue, format = "YYYY-MM-DD HH:mm:
471
532
  }, onFocus: (e) => e.preventDefault(), onPointerDown: (e) => e.preventDefault(), "data-type": "separator", "data-identifier": segment.type, "data-has-space": segment.text.includes(" "), "data-placeholder": segment.placeholder, "data-value": segment.value, children: segment.text }, i));
472
533
  }
473
534
  return (_jsx(InputSegment, { className: "input", tabIndex: i === 0 ? 0 : -1, onClick: (e) => handleSegmentClick(e, segment), "data-type": "input", size: size, "data-identifier": segment.type, "data-has-space": segment.text.includes(" "), "data-placeholder": segment.placeholder, "data-value": segment.value, "data-selected": (selectedSegment === null || selectedSegment === void 0 ? void 0 : selectedSegment.index) === segment.index, children: value ? segment.text : segment.placeholder }, i));
474
- }), utc && _jsx("div", { style: { marginLeft: 5 }, children: "UTC" }), clearable && value ? (_jsx(ClearButton, { onClick: handleClear })) : arrow ? (_jsx(ArrowButton, {})) : null] }), enableCalendar && isOpen && (_jsx(FloatingPortal, { preserveTabOrder: true, children: _jsx(StyledFloatContainer, Object.assign({ ref: refs.setFloating, style: floatingStyles }, getReferenceProps(), { children: _jsx(StyledContent, { maxDropdownHeight: "fit-content", children: _jsx("div", { children: _jsx(Calendar, { defaultValue: value ? moment(value).toDate() : undefined, clearable: false, min: min, max: max, onChange: (date) => {
535
+ }), utc && _jsx("div", { style: { marginLeft: 5 }, children: "UTC" }), clearable && value ? (_jsx(ClearButton, { onClick: handleClear })) : arrow ? (_jsx(ArrowButton, {})) : null] }), enableCalendar && isOpen && (_jsx(FloatingPortal, { preserveTabOrder: true, children: _jsx(StyledFloatContainer, Object.assign({ ref: refs.setFloating, style: floatingStyles }, getReferenceProps(), { children: _jsx(StyledContent, { maxDropdownHeight: "fit-content", children: _jsx("div", { children: _jsx(Calendar, { value: value ? moment(value).toDate() : undefined, clearable: false, min: min, max: max, onChange: (date) => {
475
536
  setValue((prev) => {
476
537
  // make copy of prev variable
477
538
  const oldValue = moment(prev).toISOString();
@@ -1,17 +1,9 @@
1
1
  import { ReactNode } from "react";
2
2
  import { Size, Variant } from "../core";
3
- export declare const StyledInputContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
4
- width?: string | number | null;
5
- }>> & string;
6
- type Option = {
7
- label: string;
8
- value: any;
9
- group?: string;
10
- data?: any;
11
- };
12
3
  interface SelectBoxProps {
13
4
  className?: string;
14
5
  defaultValue?: Option | string;
6
+ value?: Option | string;
15
7
  data?: Option[] | string[];
16
8
  placeholder?: string;
17
9
  arrow?: boolean;
@@ -41,5 +33,14 @@ interface SelectBoxProps {
41
33
  }>;
42
34
  DropDownProps?: any;
43
35
  }
44
- declare const SelectBox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<SelectBoxProps, never>> & string & Omit<({ className, data, placeholder, arrow, onChange, onSearch, searchFn, onScroll, loading, defaultValue, onItemAdded, size, variant, width, allowCustomValue, searchable, clearable, label, description, required, error, openOnFocus, renderOption, actionComponent, focused, grouped, TooltipContent, DropDownProps, }: SelectBoxProps) => import("react/jsx-runtime").JSX.Element, keyof import("react").Component<any, {}, any>>;
36
+ type Option = {
37
+ label: string;
38
+ value: any;
39
+ group?: string;
40
+ data?: any;
41
+ };
42
+ export declare const StyledInputContainer: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
43
+ width?: string | number | null;
44
+ }>> & string;
45
+ declare const SelectBox: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<SelectBoxProps, never>> & string & Omit<({ className, data, placeholder, arrow, onChange, onSearch, searchFn, onScroll, loading, defaultValue, value, onItemAdded, size, variant, width, allowCustomValue, searchable, clearable, label, description, required, error, openOnFocus, renderOption, actionComponent, focused, grouped, TooltipContent, DropDownProps, }: SelectBoxProps) => import("react/jsx-runtime").JSX.Element, keyof import("react").Component<any, {}, any>>;
45
46
  export default SelectBox;
@@ -15,6 +15,7 @@ import { useFloating, flip, offset, FloatingPortal, autoUpdate, } from "@floatin
15
15
  import { useCallback, useEffect, useRef, useState, } from "react";
16
16
  import { Input, FieldLabel, Tooltip } from "..";
17
17
  import { useDebouncedCallback } from "use-debounce";
18
+ import { useUncontrolled } from "@mantine/hooks";
18
19
  import { StyledContent, StyledFloatContainer, ArrowButton, ClearButton, } from "../core";
19
20
  export const StyledInputContainer = styled.div `
20
21
  font-family: ${({ theme }) => theme.typography.fontFamily};
@@ -150,11 +151,15 @@ const StyledItem = styled.div `
150
151
  color: ${(props) => props.theme.palette.text.primary};
151
152
  }
152
153
  `;
153
- const SelectBox = styled(({ className, data = [], placeholder = "Select...", arrow = true, onChange, onSearch, searchFn, onScroll, loading, defaultValue, onItemAdded, size = "sm", variant = "outlined", width = "100%", allowCustomValue = false, searchable = false, clearable = false, label, description, required = false, error, openOnFocus = true, renderOption, actionComponent, focused, grouped, TooltipContent, DropDownProps = {}, }) => {
154
- var _a, _b, _c, _d, _e, _f, _g, _h;
154
+ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arrow = true, onChange, onSearch, searchFn, onScroll, loading, defaultValue, value, onItemAdded, size = "sm", variant = "outlined", width = "100%", allowCustomValue = false, searchable = false, clearable = false, label, description, required = false, error, openOnFocus = true, renderOption, actionComponent, focused, grouped, TooltipContent, DropDownProps = {}, }) => {
155
+ var _a, _b, _c, _d, _e, _f, _g;
155
156
  const isObjectArray = (_a = Object.keys((data === null || data === void 0 ? void 0 : data[0]) || {})) === null || _a === void 0 ? void 0 : _a.includes("label");
157
+ const [_value, handleChange] = useUncontrolled({
158
+ value,
159
+ defaultValue,
160
+ onChange,
161
+ });
156
162
  const [isOpen, setIsOpen] = useState(false);
157
- const [selected, setSelected] = useState(null);
158
163
  const [searchValue, setSearchValue] = useState("");
159
164
  const [customItems, setCustomItems] = useState([]);
160
165
  const [placement, setPlacement] = useState("bottom-start");
@@ -162,8 +167,11 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
162
167
  const inputRef = useRef(null);
163
168
  const containerRef = useRef(null);
164
169
  const scrollContainerRef = useRef(null);
165
- const filteredItems = data
166
- .concat(customItems) // Add custom items to the list
170
+ const uniqueItems = Array.from(new Map([...data, ...customItems].map((item) => [
171
+ isObjectArray ? item.value : item,
172
+ item,
173
+ ])).values());
174
+ const filteredItems = uniqueItems
167
175
  .filter((item) => {
168
176
  const itemValue = (isObjectArray ? item.label : item);
169
177
  return itemValue === null || itemValue === void 0 ? void 0 : itemValue.toLowerCase().includes(searchValue.toLowerCase());
@@ -174,8 +182,10 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
174
182
  const bValue = b.group;
175
183
  return aValue.localeCompare(bValue);
176
184
  }
177
- // return current sort order
178
- return 0;
185
+ // Secondary sort by label/value to ensure consistent ordering
186
+ const aLabel = isObjectArray ? a.label : a;
187
+ const bLabel = isObjectArray ? b.label : b;
188
+ return aLabel.localeCompare(bLabel);
179
189
  });
180
190
  const groupedItems = grouped
181
191
  ? filteredItems.reduce((acc, item) => {
@@ -220,11 +230,9 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
220
230
  };
221
231
  const handleClear = (e) => {
222
232
  e.preventDefault();
223
- if (inputRef.current)
224
- inputRef.current.value = "";
233
+ e.stopPropagation();
225
234
  setIsOpen(false);
226
- handleChangeSelection(null);
227
- setSelected(null);
235
+ handleChange(undefined);
228
236
  setSearchValue("");
229
237
  searchFn === null || searchFn === void 0 ? void 0 : searchFn("");
230
238
  update();
@@ -232,13 +240,9 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
232
240
  const handleItemClick = (event, item) => {
233
241
  event.preventDefault();
234
242
  event.stopPropagation();
235
- handleChangeSelection(item);
243
+ handleChange(item);
236
244
  setIsOpen(false);
237
245
  };
238
- const handleChangeSelection = useCallback((option) => {
239
- setSelected(option);
240
- onChange === null || onChange === void 0 ? void 0 : onChange((option === null || option === void 0 ? void 0 : option.value) || option, option);
241
- }, [onChange]);
242
246
  const handleAddItem = useCallback((newItem) => {
243
247
  const isNewItem = data.every((item) => item.label.toLowerCase() !==
244
248
  newItem.toLowerCase());
@@ -250,7 +254,7 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
250
254
  prev.push(newValue);
251
255
  return prev;
252
256
  });
253
- handleChangeSelection(newValue);
257
+ handleChange(newValue);
254
258
  onItemAdded === null || onItemAdded === void 0 ? void 0 : onItemAdded(newValue);
255
259
  }
256
260
  else {
@@ -259,9 +263,9 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
259
263
  ? item.label.toLowerCase() === newItem.toLowerCase()
260
264
  : item.toLowerCase() === newItem.toLowerCase();
261
265
  });
262
- handleChangeSelection(item);
266
+ handleChange(item);
263
267
  }
264
- }, [onItemAdded, isObjectArray, data, handleChangeSelection]);
268
+ }, [onItemAdded, isObjectArray, data, handleChange]);
265
269
  const handleKeyDown = (e) => {
266
270
  var _a, _b;
267
271
  const currentInputValue = (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.value;
@@ -284,37 +288,30 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
284
288
  // TODO: decide what to do when user presses enter after typing a search value
285
289
  }
286
290
  toggleOpen();
287
- // setIsOpen(false);
288
291
  }
289
292
  // Arrow down
290
293
  if (e.key === "ArrowDown") {
291
294
  e.preventDefault();
292
- setSelected((prev) => {
293
- let newItem = filteredItems[0]; // Loop back to the first item
294
- const index = filteredItems.findIndex((item) => isObjectArray
295
- ? item.value === (prev === null || prev === void 0 ? void 0 : prev.value)
296
- : item === prev);
297
- if (index < filteredItems.length - 1) {
298
- newItem = filteredItems[index + 1];
299
- }
300
- onChange === null || onChange === void 0 ? void 0 : onChange((newItem === null || newItem === void 0 ? void 0 : newItem.value) || newItem, newItem);
301
- return newItem;
302
- });
295
+ let newItem = filteredItems[0]; // Loop back to the first item
296
+ const index = filteredItems.findIndex((item) => isObjectArray
297
+ ? item.value === (_value === null || _value === void 0 ? void 0 : _value.value)
298
+ : item === _value);
299
+ if (index < filteredItems.length - 1) {
300
+ newItem = filteredItems[index + 1];
301
+ }
302
+ handleChange === null || handleChange === void 0 ? void 0 : handleChange(newItem, newItem);
303
303
  }
304
304
  // Arrow up
305
305
  if (e.key === "ArrowUp") {
306
306
  e.preventDefault();
307
- setSelected((prev) => {
308
- let newItem = filteredItems[filteredItems.length - 1]; // Loop back to the last item
309
- const index = filteredItems.findIndex((item) => isObjectArray
310
- ? item.value === (prev === null || prev === void 0 ? void 0 : prev.value)
311
- : item === prev);
312
- if (index > 0) {
313
- newItem = filteredItems[index - 1];
314
- }
315
- onChange === null || onChange === void 0 ? void 0 : onChange((newItem === null || newItem === void 0 ? void 0 : newItem.value) || newItem, newItem);
316
- return newItem;
317
- });
307
+ let newItem = filteredItems[filteredItems.length - 1]; // Loop back to the last item
308
+ const index = filteredItems.findIndex((item) => isObjectArray
309
+ ? item.value === (_value === null || _value === void 0 ? void 0 : _value.value)
310
+ : item === _value);
311
+ if (index > 0) {
312
+ newItem = filteredItems[index - 1];
313
+ }
314
+ handleChange === null || handleChange === void 0 ? void 0 : handleChange(newItem, newItem);
318
315
  }
319
316
  // Tab key
320
317
  if (e.key === "Tab") {
@@ -322,7 +319,7 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
322
319
  handleAddItem(currentInputValue);
323
320
  setSearchValue("");
324
321
  }
325
- else if (!selected) {
322
+ else if (!_value) {
326
323
  // clear input
327
324
  if (inputRef.current) {
328
325
  inputRef.current.value = "";
@@ -352,6 +349,13 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
352
349
  setIsOpen(true);
353
350
  }
354
351
  };
352
+ const handleBlur = () => {
353
+ var _a;
354
+ if (allowCustomValue && ((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value)) {
355
+ handleAddItem(inputRef.current.value);
356
+ setSearchValue("");
357
+ }
358
+ };
355
359
  // Close on outside click
356
360
  useEffect(() => {
357
361
  const close = (e) => {
@@ -370,31 +374,6 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
370
374
  document.addEventListener("click", close);
371
375
  return () => document.removeEventListener("click", close);
372
376
  }, [refs.floating, refs.reference]);
373
- // Handle default value
374
- useEffect(() => {
375
- if (defaultValue) {
376
- const isOption = defaultValue.value !== undefined;
377
- const searchPattern = isOption
378
- ? defaultValue.value
379
- : defaultValue;
380
- setSelected(data.find((item) => isObjectArray
381
- ? item.value === searchPattern
382
- : item === searchPattern) || null);
383
- }
384
- }, [data, defaultValue, isObjectArray]);
385
- // handle input value change
386
- useEffect(() => {
387
- if (inputRef.current) {
388
- if (!selected) {
389
- inputRef.current.value = "";
390
- }
391
- else {
392
- inputRef.current.value = isObjectArray
393
- ? selected.label
394
- : selected;
395
- }
396
- }
397
- }, [selected]);
398
377
  // handle scroll item into view
399
378
  useEffect(() => {
400
379
  var _a, _b;
@@ -402,7 +381,7 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
402
381
  if (item) {
403
382
  item.scrollIntoView({ block: "nearest" });
404
383
  }
405
- }, [selected]);
384
+ }, [_value]);
406
385
  // make calls to onSearch callback
407
386
  useEffect(() => {
408
387
  if (searchable) {
@@ -435,7 +414,7 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
435
414
  setDropDownHeight(bottomHeight);
436
415
  };
437
416
  }, [topHeight, bottomHeight, isOpen]);
438
- return (_jsxs("div", { className: className, children: [label && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsxs(StyledInputContainer, { ref: refs.setReference, onMouseDown: () => setIsOpen(true), width: width, onKeyDown: handleKeyDown, "data-open": isOpen, children: [_jsx(Input, { ref: inputRef, onChange: debouncedHandleOnChange, onFocus: handleFocus, autoFocus: focused, placeholder: placeholder, size: size, readOnly: !searchable, "data-button-right": arrow || clearable }), clearable && (selected || !!((_h = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _h === void 0 ? void 0 : _h.value)) ? (_jsx(ClearButton, { className: "input-btn", onClick: handleClear, onMouseDown: (e) => {
417
+ return (_jsxs("div", { className: className, children: [label && (_jsx(FieldLabel, { error: error, asterisk: required, size: size, description: description, children: label })), _jsxs(StyledInputContainer, { ref: refs.setReference, onMouseDown: () => setIsOpen(true), width: width, onKeyDown: handleKeyDown, "data-open": isOpen, children: [_jsx(Input, { ref: inputRef, value: isObjectArray ? (_value === null || _value === void 0 ? void 0 : _value.label) || "" : _value || "", onChange: debouncedHandleOnChange, onFocus: handleFocus, autoFocus: focused, placeholder: placeholder, size: size, readOnly: !searchable, "data-button-right": arrow || clearable }), clearable && _value ? (_jsx(ClearButton, { className: "input-btn", onClick: handleClear, onMouseDown: (e) => {
439
418
  e.preventDefault();
440
419
  e.stopPropagation();
441
420
  } })) : arrow ? (_jsx(ArrowButton, { onClick: (e) => {
@@ -457,15 +436,14 @@ const SelectBox = styled(({ className, data = [], placeholder = "Select...", arr
457
436
  }, variant: variant, "data-empty": filteredItems.length === 0 }, DropDownProps, { children: [actionComponent && _jsx(ActionMenu, { children: actionComponent }), _jsxs(StyledInnerItemContainer, { ref: scrollContainerRef, "data-scroll-active": scrollActive, onScroll: onScroll, children: [loading && _jsx("div", { children: "Loading..." }), !loading && grouped
458
437
  ? groups.map((group, index) => (_jsxs("div", { children: [_jsx(GroupTitle, { size: size, children: group.label }), group.items.map((item, index) => {
459
438
  return (_jsx(Tooltip, { content: TooltipContent ? (_jsx(TooltipContent, { data: item.data })) : null, side: "left", children: _jsx(StyledItem, { className: "mfFloatingItem", onClick: (e) => handleItemClick(e, item), "data-selected": isObjectArray
460
- ? (selected === null || selected === void 0 ? void 0 : selected.value) ===
461
- item.value
462
- : selected === item, size: size, children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) || (_jsx(_Fragment, { children: (item === null || item === void 0 ? void 0 : item.label) || item })) }, index) }, index));
439
+ ? (_value === null || _value === void 0 ? void 0 : _value.value) === item.value
440
+ : _value === item, size: size, children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) || (_jsx(_Fragment, { children: (item === null || item === void 0 ? void 0 : item.label) || item })) }, index) }, index));
463
441
  })] }, group.label)))
464
442
  : filteredItems.map((item, index) => {
465
443
  return (_jsx(Tooltip, { content: TooltipContent ? (_jsx(TooltipContent, { data: item.data })) : null, side: "left", children: _jsx(StyledItem, { className: "mfFloatingItem", onClick: (e) => handleItemClick(e, item), "data-selected": isObjectArray
466
- ? (selected === null || selected === void 0 ? void 0 : selected.value) ===
444
+ ? (_value === null || _value === void 0 ? void 0 : _value.value) ===
467
445
  (item === null || item === void 0 ? void 0 : item.value)
468
- : selected === item, size: size, children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) || (_jsx(_Fragment, { children: (item === null || item === void 0 ? void 0 : item.label) || item })) }, index) }, index));
446
+ : _value === item, size: size, children: (renderOption === null || renderOption === void 0 ? void 0 : renderOption(item)) || (_jsx(_Fragment, { children: (item === null || item === void 0 ? void 0 : item.label) || item })) }, index) }, index));
469
447
  })] })] })) }) }))] }));
470
448
  }) `
471
449
  position: relative;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.1.56",
3
+ "version": "1.1.58",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@floating-ui/react": "^0.26.16",
25
+ "@mantine/hooks": "^7.13.0",
25
26
  "@radix-ui/react-switch": "^1.0.7",
26
27
  "@radix-ui/react-tooltip": "^1.0.7",
27
28
  "@tabler/icons-react": "^3.11.0",