@snack-uikit/breadcrumbs 0.11.21-preview-68d9b028.0 → 0.11.21

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 0.11.21 (2025-08-13)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **FF-0000:** render with outdated props from debounce ([ba0a749](https://github.com/cloud-ru-tech/snack-uikit/commit/ba0a74980b209c1f3f74c2453875ae1c02771030))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.11.20 (2025-07-23)
7
18
 
8
19
  ### Only dependencies have been changed
package/dist/cjs/hooks.js CHANGED
@@ -38,21 +38,6 @@ const selectConfig = (containerWidth, configs) => {
38
38
  };
39
39
  }
40
40
  };
41
- const useCustomDebounce = (delay, initFn) => {
42
- const debounceRef = (0, react_1.useRef)(initFn);
43
- const debouncedFn = (0, react_1.useMemo)(() => (0, lodash_debounce_1.default)(() => {
44
- var _a;
45
- return (_a = debounceRef === null || debounceRef === void 0 ? void 0 : debounceRef.current) === null || _a === void 0 ? void 0 : _a.call(debounceRef);
46
- }, delay), [delay]);
47
- const updateDebounceFn = (0, react_1.useCallback)(fn => {
48
- debounceRef.current = fn;
49
- debouncedFn();
50
- }, [debouncedFn]);
51
- return {
52
- debouncedFn,
53
- updateDebounceFn
54
- };
55
- };
56
41
  /**
57
42
  * Расчет способа отображения breadcrumbs работает следующим образом:
58
43
  * Каждый item может быть отображен в одном из режимов:
@@ -68,47 +53,24 @@ const useCustomDebounce = (delay, initFn) => {
68
53
  * Для того чтоб отобразить breadcrumbs, нужно подобрать конфиг, максимальный по ширине, влезающий в контейнер, но с минимальным весом (наименьшим количеством сокращений).
69
54
  */
70
55
  function useBreadcrumbsLayout(containerRef) {
71
- const [currentConfig, setCurrentConfig] = (0, react_1.useState)(undefined);
72
56
  const [configs, setConfigs] = (0, react_1.useState)([]);
73
- const {
74
- debouncedFn,
75
- updateDebounceFn
76
- } = useCustomDebounce(100);
77
- const selectConfigForWidth = (0, react_1.useCallback)(width => selectConfig(width, configs), [configs]);
78
- /**
79
- * Подбор подходящего конфига триггерится изменением ширины контейнера и изменением набора конфигов
80
- */
57
+ const [width, setWidth] = (0, react_1.useState)(0);
81
58
  (0, react_1.useEffect)(() => {
82
59
  var _a;
83
60
  const visibleContainer = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
84
61
  if (!visibleContainer) {
85
62
  return;
86
63
  }
87
- setCurrentConfig(selectConfig((0, utils_1.getMaxPossibleWidth)(visibleContainer), configs));
88
- }, [configs, containerRef]);
89
- (0, react_1.useEffect)(() => {
90
- var _a;
91
- const visibleContainer = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
92
- if (!visibleContainer) {
93
- return;
94
- }
95
- updateDebounceFn(() => {
96
- const width = (0, utils_1.getMaxPossibleWidth)(visibleContainer);
97
- setCurrentConfig(prevConfig => {
98
- if ((prevConfig === null || prevConfig === void 0 ? void 0 : prevConfig.containerWidth) === width) {
99
- return prevConfig;
100
- }
101
- const newConf = selectConfigForWidth(width);
102
- return newConf || (prevConfig ? Object.assign(Object.assign({}, prevConfig), {
103
- containerWidth: width
104
- }) : prevConfig);
105
- });
106
- });
107
- const visibleContainerObserver = new ResizeObserver(debouncedFn);
64
+ setWidth((0, utils_1.getMaxPossibleWidth)(visibleContainer));
65
+ const reselectConfig = (0, lodash_debounce_1.default)(() => {
66
+ setWidth((0, utils_1.getMaxPossibleWidth)(visibleContainer));
67
+ }, 100);
68
+ const visibleContainerObserver = new ResizeObserver(reselectConfig);
108
69
  visibleContainerObserver.observe(visibleContainer);
109
70
  visibleContainerObserver.observe(document.body);
110
71
  return () => visibleContainerObserver.disconnect();
111
- }, [containerRef, selectConfigForWidth, debouncedFn, updateDebounceFn]);
72
+ }, [containerRef]);
73
+ const currentConfig = (0, react_1.useMemo)(() => selectConfig(width, configs), [width, configs]);
112
74
  return {
113
75
  setConfigs,
114
76
  currentConfig
@@ -4,7 +4,6 @@ import { ELEMENT_TYPE, ITEM_RENDER_MODE, SIZE } from './constants';
4
4
  export type Size = ValueOf<typeof SIZE>;
5
5
  export type ElementType = ValueOf<typeof ELEMENT_TYPE>;
6
6
  export type ItemRenderMode = ValueOf<typeof ITEM_RENDER_MODE>;
7
- export type Fn = () => void;
8
7
  export type Item = {
9
8
  id: string;
10
9
  label: string;
package/dist/esm/hooks.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import debounce from 'lodash.debounce';
2
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useEffect, useMemo, useState } from 'react';
3
3
  import { getMaxPossibleWidth } from './utils';
4
4
  const selectConfig = (containerWidth, configs) => {
5
5
  if (!configs.length) {
@@ -25,15 +25,6 @@ const selectConfig = (containerWidth, configs) => {
25
25
  return { chain: bestConfig.chain, containerWidth, chainWidth: bestConfig.width };
26
26
  }
27
27
  };
28
- const useCustomDebounce = (delay, initFn) => {
29
- const debounceRef = useRef(initFn);
30
- const debouncedFn = useMemo(() => debounce(() => { var _a; return (_a = debounceRef === null || debounceRef === void 0 ? void 0 : debounceRef.current) === null || _a === void 0 ? void 0 : _a.call(debounceRef); }, delay), [delay]);
31
- const updateDebounceFn = useCallback((fn) => {
32
- debounceRef.current = fn;
33
- debouncedFn();
34
- }, [debouncedFn]);
35
- return { debouncedFn, updateDebounceFn };
36
- };
37
28
  /**
38
29
  * Расчет способа отображения breadcrumbs работает следующим образом:
39
30
  * Каждый item может быть отображен в одном из режимов:
@@ -49,41 +40,23 @@ const useCustomDebounce = (delay, initFn) => {
49
40
  * Для того чтоб отобразить breadcrumbs, нужно подобрать конфиг, максимальный по ширине, влезающий в контейнер, но с минимальным весом (наименьшим количеством сокращений).
50
41
  */
51
42
  export function useBreadcrumbsLayout(containerRef) {
52
- const [currentConfig, setCurrentConfig] = useState(undefined);
53
43
  const [configs, setConfigs] = useState([]);
54
- const { debouncedFn, updateDebounceFn } = useCustomDebounce(100);
55
- const selectConfigForWidth = useCallback((width) => selectConfig(width, configs), [configs]);
56
- /**
57
- * Подбор подходящего конфига триггерится изменением ширины контейнера и изменением набора конфигов
58
- */
59
- useEffect(() => {
60
- var _a;
61
- const visibleContainer = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
62
- if (!visibleContainer) {
63
- return;
64
- }
65
- setCurrentConfig(selectConfig(getMaxPossibleWidth(visibleContainer), configs));
66
- }, [configs, containerRef]);
44
+ const [width, setWidth] = useState(0);
67
45
  useEffect(() => {
68
46
  var _a;
69
47
  const visibleContainer = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
70
48
  if (!visibleContainer) {
71
49
  return;
72
50
  }
73
- updateDebounceFn(() => {
74
- const width = getMaxPossibleWidth(visibleContainer);
75
- setCurrentConfig(prevConfig => {
76
- if ((prevConfig === null || prevConfig === void 0 ? void 0 : prevConfig.containerWidth) === width) {
77
- return prevConfig;
78
- }
79
- const newConf = selectConfigForWidth(width);
80
- return newConf || (prevConfig ? Object.assign(Object.assign({}, prevConfig), { containerWidth: width }) : prevConfig);
81
- });
82
- });
83
- const visibleContainerObserver = new ResizeObserver(debouncedFn);
51
+ setWidth(getMaxPossibleWidth(visibleContainer));
52
+ const reselectConfig = debounce(() => {
53
+ setWidth(getMaxPossibleWidth(visibleContainer));
54
+ }, 100);
55
+ const visibleContainerObserver = new ResizeObserver(reselectConfig);
84
56
  visibleContainerObserver.observe(visibleContainer);
85
57
  visibleContainerObserver.observe(document.body);
86
58
  return () => visibleContainerObserver.disconnect();
87
- }, [containerRef, selectConfigForWidth, debouncedFn, updateDebounceFn]);
59
+ }, [containerRef]);
60
+ const currentConfig = useMemo(() => selectConfig(width, configs), [width, configs]);
88
61
  return { setConfigs, currentConfig };
89
62
  }
@@ -4,7 +4,6 @@ import { ELEMENT_TYPE, ITEM_RENDER_MODE, SIZE } from './constants';
4
4
  export type Size = ValueOf<typeof SIZE>;
5
5
  export type ElementType = ValueOf<typeof ELEMENT_TYPE>;
6
6
  export type ItemRenderMode = ValueOf<typeof ITEM_RENDER_MODE>;
7
- export type Fn = () => void;
8
7
  export type Item = {
9
8
  id: string;
10
9
  label: string;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Breadcrumbs",
7
- "version": "0.11.21-preview-68d9b028.0",
7
+ "version": "0.11.21",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -42,5 +42,5 @@
42
42
  "classnames": "2.5.1",
43
43
  "lodash.debounce": "4.0.8"
44
44
  },
45
- "gitHead": "f1998d9fa0d43601b504c1b4ca4a8755ac533567"
45
+ "gitHead": "30eefce4500ba1f3256ff1bbccc07af26ded88bf"
46
46
  }
package/src/hooks.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import debounce from 'lodash.debounce';
2
- import { RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { RefObject, useEffect, useMemo, useState } from 'react';
3
3
 
4
- import { BreadcrumbsConfig, CurrentConfigState, Fn } from './types';
4
+ import { BreadcrumbsConfig, CurrentConfigState } from './types';
5
5
  import { getMaxPossibleWidth } from './utils';
6
6
 
7
7
  export type BreadcrumbsLayout = {
@@ -35,22 +35,6 @@ const selectConfig = (containerWidth: number, configs: BreadcrumbsConfig[]): Cur
35
35
  }
36
36
  };
37
37
 
38
- const useCustomDebounce = (delay: number, initFn?: Fn) => {
39
- const debounceRef = useRef<Fn | undefined>(initFn);
40
-
41
- const debouncedFn = useMemo(() => debounce(() => debounceRef?.current?.(), delay), [delay]);
42
-
43
- const updateDebounceFn = useCallback(
44
- (fn: Fn) => {
45
- debounceRef.current = fn;
46
- debouncedFn();
47
- },
48
- [debouncedFn],
49
- );
50
-
51
- return { debouncedFn, updateDebounceFn };
52
- };
53
-
54
38
  /**
55
39
  * Расчет способа отображения breadcrumbs работает следующим образом:
56
40
  * Каждый item может быть отображен в одном из режимов:
@@ -66,16 +50,9 @@ const useCustomDebounce = (delay: number, initFn?: Fn) => {
66
50
  * Для того чтоб отобразить breadcrumbs, нужно подобрать конфиг, максимальный по ширине, влезающий в контейнер, но с минимальным весом (наименьшим количеством сокращений).
67
51
  */
68
52
  export function useBreadcrumbsLayout(containerRef: RefObject<HTMLElement>): BreadcrumbsLayout {
69
- const [currentConfig, setCurrentConfig] = useState<CurrentConfigState | undefined>(undefined);
70
53
  const [configs, setConfigs] = useState<BreadcrumbsConfig[]>([]);
54
+ const [width, setWidth] = useState(0);
71
55
 
72
- const { debouncedFn, updateDebounceFn } = useCustomDebounce(100);
73
-
74
- const selectConfigForWidth = useCallback((width: number) => selectConfig(width, configs), [configs]);
75
-
76
- /**
77
- * Подбор подходящего конфига триггерится изменением ширины контейнера и изменением набора конфигов
78
- */
79
56
  useEffect(() => {
80
57
  const visibleContainer = containerRef.current?.parentElement;
81
58
 
@@ -83,36 +60,20 @@ export function useBreadcrumbsLayout(containerRef: RefObject<HTMLElement>): Brea
83
60
  return;
84
61
  }
85
62
 
86
- setCurrentConfig(selectConfig(getMaxPossibleWidth(visibleContainer), configs));
87
- }, [configs, containerRef]);
63
+ setWidth(getMaxPossibleWidth(visibleContainer));
88
64
 
89
- useEffect(() => {
90
- const visibleContainer = containerRef.current?.parentElement;
91
-
92
- if (!visibleContainer) {
93
- return;
94
- }
95
-
96
- updateDebounceFn(() => {
97
- const width = getMaxPossibleWidth(visibleContainer);
98
-
99
- setCurrentConfig(prevConfig => {
100
- if (prevConfig?.containerWidth === width) {
101
- return prevConfig;
102
- }
103
-
104
- const newConf = selectConfigForWidth(width);
105
- return newConf || (prevConfig ? { ...prevConfig, containerWidth: width } : prevConfig);
106
- });
107
- });
108
-
109
- const visibleContainerObserver = new ResizeObserver(debouncedFn);
65
+ const reselectConfig = debounce(() => {
66
+ setWidth(getMaxPossibleWidth(visibleContainer));
67
+ }, 100);
110
68
 
69
+ const visibleContainerObserver = new ResizeObserver(reselectConfig);
111
70
  visibleContainerObserver.observe(visibleContainer);
112
71
  visibleContainerObserver.observe(document.body);
113
72
 
114
73
  return () => visibleContainerObserver.disconnect();
115
- }, [containerRef, selectConfigForWidth, debouncedFn, updateDebounceFn]);
74
+ }, [containerRef]);
75
+
76
+ const currentConfig = useMemo(() => selectConfig(width, configs), [width, configs]);
116
77
 
117
78
  return { setConfigs, currentConfig };
118
79
  }
package/src/types.ts CHANGED
@@ -10,8 +10,6 @@ export type ElementType = ValueOf<typeof ELEMENT_TYPE>;
10
10
 
11
11
  export type ItemRenderMode = ValueOf<typeof ITEM_RENDER_MODE>;
12
12
 
13
- export type Fn = () => void;
14
-
15
13
  export type Item = {
16
14
  id: string;
17
15
  label: string;