@vitus-labs/elements 2.6.1 → 2.6.2

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.
package/lib/index.js CHANGED
@@ -557,18 +557,41 @@ const flattenChildren = (children) => {
557
557
  if (isFragment(children)) return children.props.children;
558
558
  return [children];
559
559
  };
560
- /** Drop nullish entries and empty objects (matches legacy behavior). */
561
- const filterValidItems = (data) => data.filter((item) => item != null && !(typeof item === "object" && isEmpty(item)));
562
- /** Determine if the array is uniformly simple (string/number) or complex (object). Mixed → null. */
563
- const detectKind = (items) => {
560
+ const classifyItem = (item) => {
561
+ const t = typeof item;
562
+ if (t === "string" || t === "number") return "simple";
563
+ if (t === "object") return "complex";
564
+ return null;
565
+ };
566
+ /**
567
+ * Single-pass: filter out nullish + empty-object entries and detect whether
568
+ * the surviving items form a uniformly simple (string/number) or complex
569
+ * (object) collection. Mixed shapes → kind `null`. Replaces the prior
570
+ * `filterValidItems` + `detectKind` two-pass which allocated an intermediate
571
+ * filtered array; this fuses both into one scan.
572
+ */
573
+ const filterAndDetectKind = (data) => {
574
+ const items = [];
564
575
  let kind = null;
565
- for (const item of items) {
566
- const t = typeof item === "string" || typeof item === "number" ? "simple" : typeof item === "object" ? "complex" : null;
567
- if (t === null) return null;
576
+ for (const item of data) {
577
+ if (item == null) continue;
578
+ if (typeof item === "object" && isEmpty(item)) continue;
579
+ items.push(item);
580
+ const t = classifyItem(item);
581
+ if (t === null) return {
582
+ items,
583
+ kind: null
584
+ };
568
585
  if (kind === null) kind = t;
569
- else if (kind !== t) return null;
586
+ else if (kind !== t) return {
587
+ items,
588
+ kind: null
589
+ };
570
590
  }
571
- return kind;
591
+ return {
592
+ items,
593
+ kind
594
+ };
572
595
  };
573
596
  const objectKey = (item, index, itemKey) => {
574
597
  if (!itemKey) return item.key ?? item.id ?? item.itemId ?? index;
@@ -607,10 +630,8 @@ const buildObjectSpecs = (items, component, itemKey) => items.map((item, i) => {
607
630
  };
608
631
  });
609
632
  const buildDataSpecs = (data, component, valueName, itemKey) => {
610
- const items = filterValidItems(data);
611
- if (items.length === 0) return null;
612
- const kind = detectKind(items);
613
- if (!kind) return null;
633
+ const { items, kind } = filterAndDetectKind(data);
634
+ if (items.length === 0 || !kind) return null;
614
635
  return kind === "simple" ? buildSimpleSpecs(items, component, valueName, itemKey) : buildObjectSpecs(items, component, itemKey);
615
636
  };
616
637
  const Component$6 = ({ itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps }) => {
@@ -1063,6 +1084,11 @@ const useScrollReposition = ({ active, type, parentContainer, closeOn, handleCon
1063
1084
  * live in dedicated hooks: `./useEscapeKey`, `./useHoverListeners`,
1064
1085
  * `./useScrollReposition`.
1065
1086
  */
1087
+ const CLICK_CLOSE_KINDS = new Set([
1088
+ "click",
1089
+ "clickOnTrigger",
1090
+ "clickOutsideContent"
1091
+ ]);
1066
1092
  const useOverlay = ({ isOpen = false, openOn = "click", closeOn = "click", type = "dropdown", position = "fixed", align = "bottom", alignX = "left", alignY = "bottom", offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = true, hoverDelay = 100, disabled, onOpen, onClose } = {}) => {
1067
1093
  const { rootSize } = useContext(context);
1068
1094
  const ctx = useOverlayContext();
@@ -1220,11 +1246,7 @@ const useOverlay = ({ isOpen = false, openOn = "click", closeOn = "click", type
1220
1246
  });
1221
1247
  useEffect(() => {
1222
1248
  if (blocked || disabled) return void 0;
1223
- if (openOn === "click" || [
1224
- "click",
1225
- "clickOnTrigger",
1226
- "clickOutsideContent"
1227
- ].includes(closeOn)) window.addEventListener("click", handleClick);
1249
+ if (openOn === "click" || CLICK_CLOSE_KINDS.has(closeOn)) window.addEventListener("click", handleClick);
1228
1250
  return () => window.removeEventListener("click", handleClick);
1229
1251
  }, [
1230
1252
  openOn,
@@ -1357,17 +1379,13 @@ var styled_default = styled(textComponent)`
1357
1379
  //#endregion
1358
1380
  //#region src/Text/component.tsx
1359
1381
  const Component$2 = ({ paragraph, label, children, tag, css, ref, ...props }) => {
1360
- const renderContent = (as = void 0) => /* @__PURE__ */ jsx(styled_default, {
1382
+ return /* @__PURE__ */ jsx(styled_default, {
1361
1383
  ref,
1362
- as,
1384
+ as: paragraph ? "p" : tag,
1363
1385
  $text: { extraStyles: css },
1364
1386
  ...props,
1365
1387
  children: children ?? label
1366
1388
  });
1367
- let finalTag;
1368
- if (paragraph) finalTag = "p";
1369
- else finalTag = tag;
1370
- return renderContent(finalTag);
1371
1389
  };
1372
1390
  const name$1 = `${PKG_NAME}/Text`;
1373
1391
  Component$2.displayName = name$1;
@@ -415,18 +415,41 @@ const flattenChildren = (children) => {
415
415
  if (isFragment(children)) return children.props.children;
416
416
  return [children];
417
417
  };
418
- /** Drop nullish entries and empty objects (matches legacy behavior). */
419
- const filterValidItems = (data) => data.filter((item) => item != null && !(typeof item === "object" && isEmpty(item)));
420
- /** Determine if the array is uniformly simple (string/number) or complex (object). Mixed → null. */
421
- const detectKind = (items) => {
418
+ const classifyItem = (item) => {
419
+ const t = typeof item;
420
+ if (t === "string" || t === "number") return "simple";
421
+ if (t === "object") return "complex";
422
+ return null;
423
+ };
424
+ /**
425
+ * Single-pass: filter out nullish + empty-object entries and detect whether
426
+ * the surviving items form a uniformly simple (string/number) or complex
427
+ * (object) collection. Mixed shapes → kind `null`. Replaces the prior
428
+ * `filterValidItems` + `detectKind` two-pass which allocated an intermediate
429
+ * filtered array; this fuses both into one scan.
430
+ */
431
+ const filterAndDetectKind = (data) => {
432
+ const items = [];
422
433
  let kind = null;
423
- for (const item of items) {
424
- const t = typeof item === "string" || typeof item === "number" ? "simple" : typeof item === "object" ? "complex" : null;
425
- if (t === null) return null;
434
+ for (const item of data) {
435
+ if (item == null) continue;
436
+ if (typeof item === "object" && isEmpty(item)) continue;
437
+ items.push(item);
438
+ const t = classifyItem(item);
439
+ if (t === null) return {
440
+ items,
441
+ kind: null
442
+ };
426
443
  if (kind === null) kind = t;
427
- else if (kind !== t) return null;
444
+ else if (kind !== t) return {
445
+ items,
446
+ kind: null
447
+ };
428
448
  }
429
- return kind;
449
+ return {
450
+ items,
451
+ kind
452
+ };
430
453
  };
431
454
  const objectKey = (item, index, itemKey) => {
432
455
  if (!itemKey) return item.key ?? item.id ?? item.itemId ?? index;
@@ -465,10 +488,8 @@ const buildObjectSpecs = (items, component, itemKey) => items.map((item, i) => {
465
488
  };
466
489
  });
467
490
  const buildDataSpecs = (data, component, valueName, itemKey) => {
468
- const items = filterValidItems(data);
469
- if (items.length === 0) return null;
470
- const kind = detectKind(items);
471
- if (!kind) return null;
491
+ const { items, kind } = filterAndDetectKind(data);
492
+ if (items.length === 0 || !kind) return null;
472
493
  return kind === "simple" ? buildSimpleSpecs(items, component, valueName, itemKey) : buildObjectSpecs(items, component, itemKey);
473
494
  };
474
495
  const Component$3 = ({ itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps }) => {
@@ -543,15 +564,13 @@ var styled_default = styled(textComponent)`
543
564
  //#endregion
544
565
  //#region src/Text/component.tsx
545
566
  const Component$1 = ({ paragraph, label, children, tag, css, ref, ...props }) => {
546
- const renderContent = (as = void 0) => /* @__PURE__ */ jsx(styled_default, {
567
+ return /* @__PURE__ */ jsx(styled_default, {
547
568
  ref,
548
- as,
569
+ as: void 0,
549
570
  $text: { extraStyles: css },
550
571
  ...props,
551
572
  children: children ?? label
552
573
  });
553
- let finalTag;
554
- return renderContent(finalTag);
555
574
  };
556
575
  const name$1 = `${PKG_NAME}/Text`;
557
576
  Component$1.displayName = name$1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitus-labs/elements",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
4
4
  "license": "MIT",
5
5
  "author": "Vit Bokisch <vit@bokisch.cz>",
6
6
  "maintainers": [
@@ -57,8 +57,8 @@
57
57
  "typecheck": "tsc --noEmit"
58
58
  },
59
59
  "peerDependencies": {
60
- "@vitus-labs/core": "^2.6.1",
61
- "@vitus-labs/unistyle": "^2.6.1",
60
+ "@vitus-labs/core": "^2.6.2",
61
+ "@vitus-labs/unistyle": "^2.6.2",
62
62
  "react": ">= 19",
63
63
  "react-dom": ">= 19",
64
64
  "react-native": ">= 0.76"