@jobber/components 6.109.4 → 6.109.5

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.
@@ -241,24 +241,6 @@ function createInteractionPointerDownHandler(isHandlingMenuInteractionRef) {
241
241
  function useAutocomplete(props) {
242
242
  const { menu, emptyActions, getOptionLabel: getOptionLabelProp, isOptionEqualToValue, inputValue, onInputChange, value, onChange, multiple, openOnFocus = true, readOnly = false, debounce: debounceMs = 300, } = props;
243
243
  const isHandlingMenuInteractionRef = React.useRef(false);
244
- const isValidSingleSelection = (v) => {
245
- if (v && typeof v === "object" && "label" in v && v.label) {
246
- return true;
247
- }
248
- return false;
249
- };
250
- const getSingleSelection = (v) => {
251
- if (isValidSingleSelection(v)) {
252
- return v;
253
- }
254
- return undefined;
255
- };
256
- const getFirstItemFromMultiSelection = (v) => {
257
- if (v && Array.isArray(v)) {
258
- return v[0];
259
- }
260
- return undefined;
261
- };
262
244
  // TODO: Clean up the types in these refs by enhancing the type system in useCallbackRef
263
245
  const getOptionLabelPropRef = jobberHooks.useCallbackRef((opt) => getOptionLabelProp === null || getOptionLabelProp === void 0 ? void 0 : getOptionLabelProp(opt));
264
246
  const getOptionLabel = React.useCallback((opt) => {
@@ -276,7 +258,8 @@ function useAutocomplete(props) {
276
258
  const current = (_a = value) !== null && _a !== void 0 ? _a : [];
277
259
  return current.some(v => equals(v, opt));
278
260
  }
279
- return isValidSingleSelection(value) ? equals(value, opt) : false;
261
+ const current = value;
262
+ return current != null ? equals(current, opt) : false;
280
263
  }, [multiple, value, equals]);
281
264
  const flatInitial = React.useMemo(() => flattenMenu(menu), [menu]);
282
265
  const sections = flatInitial.sections;
@@ -361,7 +344,7 @@ function useAutocomplete(props) {
361
344
  const current = (_a = value) !== null && _a !== void 0 ? _a : [];
362
345
  return Array.isArray(current) && current.length > 0;
363
346
  }
364
- return isValidSingleSelection(value);
347
+ return value != null;
365
348
  }, [multiple, value]);
366
349
  const headerInteractivePersistents = persistentsHeaders.filter(p => Boolean(p.onClick));
367
350
  const footerInteractivePersistents = persistentsFooters.filter(p => Boolean(p.onClick));
@@ -372,8 +355,8 @@ function useAutocomplete(props) {
372
355
  // Compute the currently selected index in the global navigable list (header -> middle -> footer)
373
356
  const selectedIndex = React.useMemo(() => {
374
357
  const selectedValue = multiple
375
- ? getFirstItemFromMultiSelection(value)
376
- : getSingleSelection(value);
358
+ ? value === null || value === void 0 ? void 0 : value[0]
359
+ : value;
377
360
  if (!selectedValue)
378
361
  return null;
379
362
  const middleIndex = findNavigableIndexForValue(renderable, equals, selectedValue);
@@ -459,8 +442,8 @@ function useAutocomplete(props) {
459
442
  if (!hasSelection)
460
443
  return;
461
444
  const selectedValue = multiple
462
- ? getFirstItemFromMultiSelection(value)
463
- : getSingleSelection(value);
445
+ ? value === null || value === void 0 ? void 0 : value[0]
446
+ : value;
464
447
  if (!selectedValue)
465
448
  return;
466
449
  const idx = findNavigableIndexForValue(renderable, equals, selectedValue);
@@ -483,8 +466,8 @@ function useAutocomplete(props) {
483
466
  // - If there is a current selection, highlight that option
484
467
  // - Otherwise, leave the highlight unset (null)
485
468
  const selectedValue = multiple
486
- ? getFirstItemFromMultiSelection(value)
487
- : getSingleSelection(value);
469
+ ? value === null || value === void 0 ? void 0 : value[0]
470
+ : value;
488
471
  if (selectedValue) {
489
472
  const selectedNavigableIndex = findNavigableIndexForValue(renderable, equals, selectedValue);
490
473
  if (selectedNavigableIndex != null) {
@@ -538,8 +521,8 @@ function useAutocomplete(props) {
538
521
  if (props.allowFreeForm === true)
539
522
  return;
540
523
  const selectedValue = multiple
541
- ? getFirstItemFromMultiSelection(value)
542
- : getSingleSelection(value);
524
+ ? value === null || value === void 0 ? void 0 : value[0]
525
+ : value;
543
526
  if (!selectedValue)
544
527
  return;
545
528
  const selectedLabel = getOptionLabel(selectedValue);
@@ -239,24 +239,6 @@ function createInteractionPointerDownHandler(isHandlingMenuInteractionRef) {
239
239
  function useAutocomplete(props) {
240
240
  const { menu, emptyActions, getOptionLabel: getOptionLabelProp, isOptionEqualToValue, inputValue, onInputChange, value, onChange, multiple, openOnFocus = true, readOnly = false, debounce: debounceMs = 300, } = props;
241
241
  const isHandlingMenuInteractionRef = useRef(false);
242
- const isValidSingleSelection = (v) => {
243
- if (v && typeof v === "object" && "label" in v && v.label) {
244
- return true;
245
- }
246
- return false;
247
- };
248
- const getSingleSelection = (v) => {
249
- if (isValidSingleSelection(v)) {
250
- return v;
251
- }
252
- return undefined;
253
- };
254
- const getFirstItemFromMultiSelection = (v) => {
255
- if (v && Array.isArray(v)) {
256
- return v[0];
257
- }
258
- return undefined;
259
- };
260
242
  // TODO: Clean up the types in these refs by enhancing the type system in useCallbackRef
261
243
  const getOptionLabelPropRef = useCallbackRef((opt) => getOptionLabelProp === null || getOptionLabelProp === void 0 ? void 0 : getOptionLabelProp(opt));
262
244
  const getOptionLabel = useCallback((opt) => {
@@ -274,7 +256,8 @@ function useAutocomplete(props) {
274
256
  const current = (_a = value) !== null && _a !== void 0 ? _a : [];
275
257
  return current.some(v => equals(v, opt));
276
258
  }
277
- return isValidSingleSelection(value) ? equals(value, opt) : false;
259
+ const current = value;
260
+ return current != null ? equals(current, opt) : false;
278
261
  }, [multiple, value, equals]);
279
262
  const flatInitial = useMemo(() => flattenMenu(menu), [menu]);
280
263
  const sections = flatInitial.sections;
@@ -359,7 +342,7 @@ function useAutocomplete(props) {
359
342
  const current = (_a = value) !== null && _a !== void 0 ? _a : [];
360
343
  return Array.isArray(current) && current.length > 0;
361
344
  }
362
- return isValidSingleSelection(value);
345
+ return value != null;
363
346
  }, [multiple, value]);
364
347
  const headerInteractivePersistents = persistentsHeaders.filter(p => Boolean(p.onClick));
365
348
  const footerInteractivePersistents = persistentsFooters.filter(p => Boolean(p.onClick));
@@ -370,8 +353,8 @@ function useAutocomplete(props) {
370
353
  // Compute the currently selected index in the global navigable list (header -> middle -> footer)
371
354
  const selectedIndex = useMemo(() => {
372
355
  const selectedValue = multiple
373
- ? getFirstItemFromMultiSelection(value)
374
- : getSingleSelection(value);
356
+ ? value === null || value === void 0 ? void 0 : value[0]
357
+ : value;
375
358
  if (!selectedValue)
376
359
  return null;
377
360
  const middleIndex = findNavigableIndexForValue(renderable, equals, selectedValue);
@@ -457,8 +440,8 @@ function useAutocomplete(props) {
457
440
  if (!hasSelection)
458
441
  return;
459
442
  const selectedValue = multiple
460
- ? getFirstItemFromMultiSelection(value)
461
- : getSingleSelection(value);
443
+ ? value === null || value === void 0 ? void 0 : value[0]
444
+ : value;
462
445
  if (!selectedValue)
463
446
  return;
464
447
  const idx = findNavigableIndexForValue(renderable, equals, selectedValue);
@@ -481,8 +464,8 @@ function useAutocomplete(props) {
481
464
  // - If there is a current selection, highlight that option
482
465
  // - Otherwise, leave the highlight unset (null)
483
466
  const selectedValue = multiple
484
- ? getFirstItemFromMultiSelection(value)
485
- : getSingleSelection(value);
467
+ ? value === null || value === void 0 ? void 0 : value[0]
468
+ : value;
486
469
  if (selectedValue) {
487
470
  const selectedNavigableIndex = findNavigableIndexForValue(renderable, equals, selectedValue);
488
471
  if (selectedNavigableIndex != null) {
@@ -536,8 +519,8 @@ function useAutocomplete(props) {
536
519
  if (props.allowFreeForm === true)
537
520
  return;
538
521
  const selectedValue = multiple
539
- ? getFirstItemFromMultiSelection(value)
540
- : getSingleSelection(value);
522
+ ? value === null || value === void 0 ? void 0 : value[0]
523
+ : value;
541
524
  if (!selectedValue)
542
525
  return;
543
526
  const selectedLabel = getOptionLabel(selectedValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "6.109.4",
3
+ "version": "6.109.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -538,5 +538,5 @@
538
538
  "> 1%",
539
539
  "IE 10"
540
540
  ],
541
- "gitHead": "8774f1709929f5e6dec002492593914bd8cb035d"
541
+ "gitHead": "f7a0a568d4416a7f2e691260e61efebe85541559"
542
542
  }