@bigtablet/design-system 3.25.0 → 3.25.1

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 (2) hide show
  1. package/dist/index.js +31 -26
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -402,12 +402,12 @@ function useFocusTrap(containerRef, isActive, options) {
402
402
  const handleKeyDown2 = (e) => {
403
403
  if (e.key !== "Tab") return;
404
404
  const focusableElements2 = getFocusableElements();
405
- if (focusableElements2.length === 0) {
405
+ const firstElement = focusableElements2[0];
406
+ const lastElement = focusableElements2[focusableElements2.length - 1];
407
+ if (!firstElement || !lastElement) {
406
408
  e.preventDefault();
407
409
  return;
408
410
  }
409
- const firstElement = focusableElements2[0];
410
- const lastElement = focusableElements2[focusableElements2.length - 1];
411
411
  if (e.shiftKey) {
412
412
  if (document.activeElement === firstElement) {
413
413
  e.preventDefault();
@@ -566,7 +566,8 @@ function useListboxPopup({
566
566
  const len = items.length;
567
567
  for (let step = 0; step < len; step++) {
568
568
  i = (i + dir + len) % len;
569
- if (!items[i].disabled) {
569
+ const item = items[i];
570
+ if (item && !item.disabled) {
570
571
  setActiveIndex(i);
571
572
  break;
572
573
  }
@@ -575,15 +576,15 @@ function useListboxPopup({
575
576
  [items, isOpen, activeIndex]
576
577
  );
577
578
  const commitActive = useCallback(() => {
578
- if (activeIndex < 0 || activeIndex >= items.length) return;
579
579
  const item = items[activeIndex];
580
- if (item.disabled) return;
580
+ if (!item || item.disabled) return;
581
581
  onCommit(item);
582
582
  }, [activeIndex, items, onCommit]);
583
583
  const firstEnabled = useCallback(() => items.findIndex((o) => !o.disabled), [items]);
584
584
  const lastEnabled = useCallback(() => {
585
585
  for (let i = items.length - 1; i >= 0; i--) {
586
- if (!items[i].disabled) return i;
586
+ const item = items[i];
587
+ if (item && !item.disabled) return i;
587
588
  }
588
589
  return -1;
589
590
  }, [items]);
@@ -798,9 +799,9 @@ var Accordion = ({
798
799
  };
799
800
  function getInitials(name) {
800
801
  const parts = name.trim().split(/\s+/);
801
- if (parts.length === 0) return "";
802
- if (parts.length === 1) return parts[0].charAt(0).toUpperCase();
803
- return (parts[0].charAt(0) + parts[parts.length - 1].charAt(0)).toUpperCase();
802
+ const first = parts[0] ?? "";
803
+ const last = parts.length > 1 ? parts.at(-1) ?? "" : "";
804
+ return (first.charAt(0) + last.charAt(0)).toUpperCase();
804
805
  }
805
806
  var Avatar = ({
806
807
  src,
@@ -1349,12 +1350,14 @@ var Menu = ({ items, trigger, align = "start" }) => {
1349
1350
  }, [open, items]);
1350
1351
  const moveFocus = (dir) => {
1351
1352
  const enabled = items.flatMap((it, i) => it.disabled ? [] : [i]);
1352
- if (enabled.length === 0) return;
1353
- if (dir === "first") return void itemRefs.current[enabled[0]]?.focus();
1354
- if (dir === "last") return void itemRefs.current[enabled[enabled.length - 1]]?.focus();
1353
+ const focusAt = (i) => {
1354
+ if (i !== void 0) itemRefs.current[i]?.focus();
1355
+ };
1356
+ if (dir === "first") return focusAt(enabled[0]);
1357
+ if (dir === "last") return focusAt(enabled.at(-1));
1355
1358
  const pos2 = enabled.findIndex((i) => itemRefs.current[i] === document.activeElement);
1356
1359
  const next = pos2 < 0 ? dir === 1 ? 0 : enabled.length - 1 : (pos2 + dir + enabled.length) % enabled.length;
1357
- itemRefs.current[enabled[next]]?.focus();
1360
+ focusAt(enabled[next]);
1358
1361
  };
1359
1362
  const handleMenuKeyDown = (e) => {
1360
1363
  if (["ArrowDown", "ArrowUp", "Home", "End", "Escape"].includes(e.key)) {
@@ -1992,10 +1995,11 @@ var Tab = ({ value, className, children, onClick, onKeyDown, ...props }) => {
1992
1995
  else if (e.key === "ArrowLeft") next = (currentIndex - 1 + tabs.length) % tabs.length;
1993
1996
  else if (e.key === "Home") next = 0;
1994
1997
  else if (e.key === "End") next = tabs.length - 1;
1995
- const targetValue = tabs[next].dataset.value;
1996
- if (targetValue) {
1998
+ const target = tabs[next];
1999
+ const targetValue = target?.dataset.value;
2000
+ if (target && targetValue !== void 0) {
1997
2001
  ctx.setValue(targetValue);
1998
- tabs[next].focus();
2002
+ target.focus();
1999
2003
  }
2000
2004
  };
2001
2005
  return /* @__PURE__ */ jsx(
@@ -5301,8 +5305,9 @@ var FileInput = ({
5301
5305
  const urls = [];
5302
5306
  const limit = isPreviewVariant ? Math.min(1, files.length) : files.length;
5303
5307
  for (let i = 0; i < limit; i++) {
5304
- if (files[i].type.startsWith("image/")) {
5305
- urls.push(URL.createObjectURL(files[i]));
5308
+ const file = files[i];
5309
+ if (file?.type.startsWith("image/")) {
5310
+ urls.push(URL.createObjectURL(file));
5306
5311
  }
5307
5312
  }
5308
5313
  setPreviewUrls(urls);
@@ -5761,7 +5766,7 @@ var OtpInput = ({
5761
5766
  const filled = nextDigit.replace(/\D/g, "").slice(0, length);
5762
5767
  if (!filled) return;
5763
5768
  const newDigits2 = [...digits];
5764
- for (let i = 0; i < filled.length; i++) newDigits2[i] = filled[i];
5769
+ newDigits2.splice(0, filled.length, ...filled);
5765
5770
  updateValue(newDigits2);
5766
5771
  focusInput(Math.min(filled.length, length - 1));
5767
5772
  return;
@@ -5815,9 +5820,7 @@ var OtpInput = ({
5815
5820
  const pasted = e.clipboardData.getData("text").replace(/\D/g, "").slice(0, length);
5816
5821
  if (!pasted) return;
5817
5822
  const newDigits = [...digits];
5818
- for (let i = 0; i < pasted.length; i++) {
5819
- newDigits[i] = pasted[i];
5820
- }
5823
+ newDigits.splice(0, pasted.length, ...pasted);
5821
5824
  updateValue(newDigits);
5822
5825
  const nextIndex = Math.min(pasted.length, length - 1);
5823
5826
  focusInput(nextIndex);
@@ -6065,6 +6068,7 @@ var TagInput = ({
6065
6068
  };
6066
6069
  const removeAt = (index) => {
6067
6070
  const removed = tags[index];
6071
+ if (removed === void 0) return;
6068
6072
  setTags(tags.filter((_, i) => i !== index));
6069
6073
  setAnnouncement(t("tagInput.removed", { name: removed }));
6070
6074
  };
@@ -6275,7 +6279,7 @@ var Textarea = ({
6275
6279
  Textarea.displayName = "Textarea";
6276
6280
  var toMinutes = (value) => {
6277
6281
  if (!value) return null;
6278
- const [h, m] = value.split(":").map(Number);
6282
+ const [h = Number.NaN, m = Number.NaN] = value.split(":").map(Number);
6279
6283
  if (!Number.isInteger(h) || !Number.isInteger(m)) return null;
6280
6284
  if (h < 0 || h > 23 || m < 0 || m > 59) return null;
6281
6285
  return h * 60 + m;
@@ -6327,8 +6331,9 @@ var TimePicker = ({
6327
6331
  const candidates = Array.from({ length: Math.ceil(60 / step) }, (_, i) => i * step).filter(
6328
6332
  (m) => m < 60 && h * 60 + m >= min && h * 60 + m <= max
6329
6333
  );
6330
- if (candidates.length === 0) return;
6331
- const keep = minute !== null && candidates.includes(minute) ? minute : candidates[0];
6334
+ const firstCandidate = candidates[0];
6335
+ if (firstCandidate === void 0) return;
6336
+ const keep = minute !== null && candidates.includes(minute) ? minute : firstCandidate;
6332
6337
  emit(h, keep);
6333
6338
  };
6334
6339
  const handleMinuteChange = (raw) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigtablet/design-system",
3
- "version": "3.25.0",
3
+ "version": "3.25.1",
4
4
  "description": "Bigtablet Design System UI Components",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",