sellmate-design-system-react 9.0.0-beta.70 → 9.0.0-beta.71

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/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import { extendTailwindMerge } from 'tailwind-merge';
4
4
  import { forwardRef, createContext, useState, useRef, useEffect, useCallback, useImperativeHandle, useLayoutEffect, useContext, useMemo, useId, Children, cloneElement, Fragment as Fragment$1, isValidElement, useSyncExternalStore, Component } from 'react';
5
5
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
6
  import * as RPopover13 from '@radix-ui/react-popover';
7
- import { createPortal } from 'react-dom';
7
+ import { createPortal, flushSync } from 'react-dom';
8
8
  import * as RCheckbox from '@radix-ui/react-checkbox';
9
9
  import { createRoot } from 'react-dom/client';
10
10
  import * as RTooltip from '@radix-ui/react-tooltip';
@@ -15034,6 +15034,14 @@ var DEFAULT_VIRTUAL_BUFFER = 10;
15034
15034
  var DEFAULT_REACH_END_THRESHOLD = 10;
15035
15035
  var DEFAULT_SEARCH_DEBOUNCE = 300;
15036
15036
  var SEARCH_THRESHOLD = 11;
15037
+ function isListSized(el) {
15038
+ return el.clientHeight > 0 && getComputedStyle(el).maxHeight !== "none";
15039
+ }
15040
+ function fallbackListHeight(dropdownHeight) {
15041
+ const viewport = window.innerHeight;
15042
+ const px = typeof dropdownHeight === "number" ? dropdownHeight : Number(/^\s*(\d+(?:\.\d+)?)px\s*$/.exec(dropdownHeight ?? "")?.[1] ?? Number.NaN);
15043
+ return Number.isFinite(px) ? Math.min(px, viewport) : viewport;
15044
+ }
15037
15045
  var SSelectImpl = /* @__PURE__ */ forwardRef(function SSelect({
15038
15046
  value,
15039
15047
  onValueChange,
@@ -15104,6 +15112,7 @@ var SSelectImpl = /* @__PURE__ */ forwardRef(function SSelect({
15104
15112
  const searchBarRef = useRef(null);
15105
15113
  const [listEl, setListEl] = useState(null);
15106
15114
  const setListRef = useCallback((node) => setListEl(node), []);
15115
+ const [listSized, setListSized] = useState(false);
15107
15116
  const dismissedByPointerRef = useRef(false);
15108
15117
  const alignSelectedTopRef = useRef(false);
15109
15118
  const selectedAnchorRef = useRef(-1);
@@ -15224,7 +15233,7 @@ var SSelectImpl = /* @__PURE__ */ forwardRef(function SSelect({
15224
15233
  if (!multi) return;
15225
15234
  const leafValues = groupLeafValues.get(i) ?? [];
15226
15235
  if (leafValues.length === 0) return;
15227
- items.push({ key: `__group_${i}__`, isGroup: true, leafValues });
15236
+ items.push({ key: `__group_${i}__`, isGroup: true, index: i, leafValues });
15228
15237
  } else {
15229
15238
  items.push({ key: o.value, value: o.value, index: i });
15230
15239
  }
@@ -15254,8 +15263,9 @@ var SSelectImpl = /* @__PURE__ */ forwardRef(function SSelect({
15254
15263
  const m = metricsRef.current;
15255
15264
  if (m == null) return;
15256
15265
  const buffer = Math.max(0, Math.floor(virtualBuffer));
15266
+ const listHeight = listSized ? Math.max(0, listEl.clientHeight) : fallbackListHeight(dropdownHeight);
15257
15267
  const viewTop = Math.max(0, listEl.scrollTop - rowsOffset);
15258
- const viewBottom = viewTop + Math.max(0, listEl.clientHeight);
15268
+ const viewBottom = viewTop + listHeight;
15259
15269
  const start = Math.max(0, indexAtOffset(m, viewTop) - buffer);
15260
15270
  const end = Math.min(rowCount, indexAtOffset(m, viewBottom) + 1 + buffer);
15261
15271
  const top = offsetOf(m, start);
@@ -15265,14 +15275,16 @@ var SSelectImpl = /* @__PURE__ */ forwardRef(function SSelect({
15265
15275
  );
15266
15276
  if (!pagingEnabled || !hasMore || loading2) return;
15267
15277
  const contentHeight = rowsOffset + totalSize(m);
15268
- const remaining = contentHeight - listEl.scrollTop - listEl.clientHeight;
15278
+ const remaining = contentHeight - listEl.scrollTop - listHeight;
15269
15279
  if (remaining > Math.max(1, reachEndThreshold) * m.estimate) return;
15270
15280
  if (lastReachEndCountRef.current === rowCount) return;
15271
15281
  lastReachEndCountRef.current = rowCount;
15272
15282
  cbRef.current.onReachEnd?.();
15273
15283
  }, [
15284
+ dropdownHeight,
15274
15285
  hasMore,
15275
15286
  listEl,
15287
+ listSized,
15276
15288
  loading2,
15277
15289
  pagingEnabled,
15278
15290
  reachEndThreshold,
@@ -15286,6 +15298,23 @@ var SSelectImpl = /* @__PURE__ */ forwardRef(function SSelect({
15286
15298
  if (!open) return;
15287
15299
  syncScrollState();
15288
15300
  }, [open, syncScrollState]);
15301
+ useLayoutEffect(() => {
15302
+ if (!open || !listEl) {
15303
+ setListSized(false);
15304
+ return;
15305
+ }
15306
+ if (isListSized(listEl)) {
15307
+ setListSized(true);
15308
+ }
15309
+ if (typeof ResizeObserver === "undefined") return;
15310
+ const observer = new ResizeObserver(() => {
15311
+ if (!isListSized(listEl)) return;
15312
+ flushSync(() => setListSized(true));
15313
+ syncScrollStateRef.current();
15314
+ });
15315
+ observer.observe(listEl);
15316
+ return () => observer.disconnect();
15317
+ }, [listEl, open]);
15289
15318
  useLayoutEffect(() => {
15290
15319
  if (!open || !listEl) {
15291
15320
  setSearchBarHeight(0);
@@ -15430,6 +15459,10 @@ var SSelectImpl = /* @__PURE__ */ forwardRef(function SSelect({
15430
15459
  syncScrollStateRef.current();
15431
15460
  return;
15432
15461
  }
15462
+ if (!listSized) {
15463
+ syncScrollStateRef.current();
15464
+ return;
15465
+ }
15433
15466
  const top = rowsOffset + offsetOf(m, rowIndex);
15434
15467
  const height = sizeOf(m, rowIndex);
15435
15468
  if (alignSelectedTopRef.current) {
@@ -15441,7 +15474,7 @@ var SSelectImpl = /* @__PURE__ */ forwardRef(function SSelect({
15441
15474
  listEl.scrollTop = top + height - listEl.clientHeight;
15442
15475
  }
15443
15476
  syncScrollStateRef.current();
15444
- }, [focusedIndex, listEl, open, rowsOffset]);
15477
+ }, [focusedIndex, listEl, listSized, open, rowsOffset]);
15445
15478
  const moveFocusedIndex = (direction) => {
15446
15479
  if (!open || navigableItems.length === 0) return;
15447
15480
  setFocusedIndex((current) => {