@doist/reactist 28.1.0 → 28.1.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.
@@ -2355,31 +2355,13 @@ const TextArea = /*#__PURE__*/React__namespace.forwardRef(function TextArea(_ref
2355
2355
  const containerRef = React__namespace.useRef(null);
2356
2356
  const internalRef = React__namespace.useRef(null);
2357
2357
  const combinedRef = useCallbackRef.useMergeRefs([ref, internalRef]);
2358
+ useAutoExpand({
2359
+ value,
2360
+ autoExpand,
2361
+ containerRef,
2362
+ internalRef
2363
+ });
2358
2364
  const textAreaClassName = classNames__default["default"]([autoExpand ? modules_2728c236.disableResize : null, disableResize ? modules_2728c236.disableResize : null]);
2359
- React__namespace.useEffect(function setupAutoExpand() {
2360
- const containerElement = containerRef.current;
2361
-
2362
- function handleAutoExpand(value) {
2363
- if (containerElement) {
2364
- containerElement.dataset.replicatedValue = value;
2365
- }
2366
- }
2367
-
2368
- function handleInput(event) {
2369
- handleAutoExpand(event.currentTarget.value);
2370
- }
2371
-
2372
- const textAreaElement = internalRef.current;
2373
-
2374
- if (!textAreaElement || !autoExpand) {
2375
- return undefined;
2376
- } // Apply change initially, in case the text area has a non-empty initial value
2377
-
2378
-
2379
- handleAutoExpand(textAreaElement.value);
2380
- textAreaElement.addEventListener('input', handleInput);
2381
- return () => textAreaElement.removeEventListener('input', handleInput);
2382
- }, [autoExpand]);
2383
2365
  return /*#__PURE__*/React__namespace.createElement(BaseField, {
2384
2366
  variant: variant,
2385
2367
  id: id,
@@ -2417,6 +2399,50 @@ const TextArea = /*#__PURE__*/React__namespace.forwardRef(function TextArea(_ref
2417
2399
  });
2418
2400
  });
2419
2401
 
2402
+ function useAutoExpand({
2403
+ value,
2404
+ autoExpand,
2405
+ containerRef,
2406
+ internalRef
2407
+ }) {
2408
+ const isControlled = value !== undefined;
2409
+ React__namespace.useEffect(function setupAutoExpandWhenUncontrolled() {
2410
+ const textAreaElement = internalRef.current;
2411
+
2412
+ if (!textAreaElement || !autoExpand || isControlled) {
2413
+ return undefined;
2414
+ }
2415
+
2416
+ const containerElement = containerRef.current;
2417
+
2418
+ function handleAutoExpand(value) {
2419
+ if (containerElement) {
2420
+ containerElement.dataset.replicatedValue = value;
2421
+ }
2422
+ }
2423
+
2424
+ function handleInput(event) {
2425
+ handleAutoExpand(event.currentTarget.value);
2426
+ } // Apply change initially, in case the text area has a non-empty initial value
2427
+
2428
+
2429
+ handleAutoExpand(textAreaElement.value);
2430
+ textAreaElement.addEventListener('input', handleInput);
2431
+ return () => textAreaElement.removeEventListener('input', handleInput);
2432
+ }, [autoExpand, containerRef, internalRef, isControlled]);
2433
+ React__namespace.useEffect(function setupAutoExpandWhenControlled() {
2434
+ if (!isControlled) {
2435
+ return;
2436
+ }
2437
+
2438
+ const containerElement = containerRef.current;
2439
+
2440
+ if (containerElement) {
2441
+ containerElement.dataset.replicatedValue = value;
2442
+ }
2443
+ }, [value, containerRef, isControlled]);
2444
+ }
2445
+
2420
2446
  function getInitials(name) {
2421
2447
  var _initials;
2422
2448
 
@@ -2855,35 +2881,63 @@ function TabList(_ref2) {
2855
2881
  } = _ref2,
2856
2882
  props = _objectWithoutProperties(_ref2, _excluded$5);
2857
2883
 
2884
+ const tabListRef = React__namespace.useRef(null);
2885
+ const tabListPrevWidthRef = React__namespace.useRef(0);
2858
2886
  const tabContextValue = React__namespace.useContext(TabsContext);
2859
2887
  const [selectedTabElement, setSelectedTabElement] = React__namespace.useState(null);
2860
2888
  const [selectedTabStyle, setSelectedTabStyle] = React__namespace.useState({});
2861
- const tabListRef = React__namespace.useRef(null);
2862
2889
  const selectedId = tabContextValue == null ? void 0 : tabContextValue.tabStore.useState('selectedId');
2863
- React__namespace.useLayoutEffect(() => {
2864
- function updateSelectedTabStyle() {
2865
- if (!selectedId || !tabListRef.current) {
2866
- return;
2867
- }
2890
+ const updateSelectedTabPosition = React__namespace.useCallback(function updateSelectedTabPositionCallback() {
2891
+ if (!selectedId || !tabListRef.current) {
2892
+ return;
2893
+ }
2868
2894
 
2869
- const tabs = tabListRef.current.querySelectorAll('[role="tab"]');
2870
- const selectedTab = Array.from(tabs).find(tab => tab.getAttribute('id') === selectedId);
2895
+ const tabs = tabListRef.current.querySelectorAll('[role="tab"]');
2896
+ const selectedTab = Array.from(tabs).find(tab => tab.getAttribute('id') === selectedId);
2871
2897
 
2872
- if (selectedTab) {
2873
- setSelectedTabElement(selectedTab);
2874
- setSelectedTabStyle({
2875
- left: selectedTab.offsetLeft + "px",
2876
- width: selectedTab.offsetWidth + "px"
2898
+ if (selectedTab) {
2899
+ setSelectedTabElement(selectedTab);
2900
+ setSelectedTabStyle({
2901
+ left: selectedTab.offsetLeft + "px",
2902
+ width: selectedTab.offsetWidth + "px"
2903
+ });
2904
+ }
2905
+ }, [selectedId]);
2906
+ React__namespace.useEffect(function updateSelectedTabPositionOnTabChange() {
2907
+ updateSelectedTabPosition();
2908
+ }, // `selectedId` is a dependency to ensure the effect runs when the selected tab changes
2909
+ [selectedId, updateSelectedTabPosition]);
2910
+ React__namespace.useEffect(function observeTabListWidthChange() {
2911
+ let animationFrameId = null;
2912
+ const tabListObserver = new ResizeObserver(([entry]) => {
2913
+ const width = entry == null ? void 0 : entry.contentRect.width;
2914
+
2915
+ if (width && tabListPrevWidthRef.current !== width) {
2916
+ tabListPrevWidthRef.current = width;
2917
+
2918
+ if (animationFrameId !== null) {
2919
+ cancelAnimationFrame(animationFrameId);
2920
+ }
2921
+
2922
+ animationFrameId = requestAnimationFrame(() => {
2923
+ updateSelectedTabPosition();
2924
+ animationFrameId = null;
2877
2925
  });
2878
2926
  }
2927
+ });
2928
+
2929
+ if (tabListRef.current) {
2930
+ tabListObserver.observe(tabListRef.current);
2879
2931
  }
2880
2932
 
2881
- updateSelectedTabStyle();
2882
- window.addEventListener('resize', updateSelectedTabStyle);
2883
- return function cleanupEventListener() {
2884
- window.removeEventListener('resize', updateSelectedTabStyle);
2933
+ return function cleanupResizeObserver() {
2934
+ if (animationFrameId) {
2935
+ cancelAnimationFrame(animationFrameId);
2936
+ }
2937
+
2938
+ tabListObserver.disconnect();
2885
2939
  };
2886
- }, [selectedId]);
2940
+ }, [updateSelectedTabPosition]);
2887
2941
 
2888
2942
  if (!tabContextValue) {
2889
2943
  return null;