@snack-uikit/breadcrumbs 0.8.37 → 0.8.39-preview-0eada078.0

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,15 @@
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.8.38 (2024-06-06)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/list@0.13.5](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/list/CHANGELOG.md)
10
+
11
+
12
+
13
+
14
+
6
15
  ## 0.8.37 (2024-05-31)
7
16
 
8
17
  ### Only dependencies have been changed
@@ -7,13 +7,15 @@ import { Wrapper } from '../Wrapper';
7
7
  import { useItemModesRender } from './hooks';
8
8
  export const HiddenChain = memo(function HiddenChain({ size, separator, items, onConfigsBuilt, firstItemIconOnly = false, lastEmpty = false, }) {
9
9
  const containerRef = useRef(null);
10
+ const itemsRef = useRef(items);
11
+ itemsRef.current = items;
10
12
  useEffect(() => {
11
13
  const container = containerRef.current;
12
14
  if (container) {
13
15
  const observer = new ResizeObserver(([{ target }]) => {
14
16
  const sizeMap = buildSizeMap(target);
15
17
  if (sizeMap) {
16
- onConfigsBuilt(buildBreadcrumbsConfigs(items, sizeMap, lastEmpty));
18
+ onConfigsBuilt(buildBreadcrumbsConfigs(itemsRef.current, sizeMap, lastEmpty));
17
19
  }
18
20
  });
19
21
  observer.observe(container);
@@ -21,7 +23,7 @@ export const HiddenChain = memo(function HiddenChain({ size, separator, items, o
21
23
  observer.disconnect();
22
24
  };
23
25
  }
24
- }, [items, lastEmpty, onConfigsBuilt]);
26
+ }, [lastEmpty, onConfigsBuilt]);
25
27
  const renderItemModes = useItemModesRender({ firstItemIconOnly });
26
28
  return (_jsxs(Wrapper, { size: size, hidden: true, ref: containerRef, separator: separator, "data-test-id": 'hidden-wrapper', children: [_jsx(Separator, {}), _jsx(Collapse, { currentConfig: [] }), items.map(renderItemModes)] }));
27
29
  });
package/dist/hooks.js CHANGED
@@ -17,6 +17,9 @@ const selectConfig = (containerWidth, configs) => {
17
17
  }
18
18
  }
19
19
  }
20
+ else if (config.width < bestConfig.width) {
21
+ bestConfig = config;
22
+ }
20
23
  }
21
24
  if (bestConfig) {
22
25
  return { chain: bestConfig.chain, containerWidth, chainWidth: bestConfig.width };
@@ -49,9 +52,7 @@ export function useBreadcrumbsLayout(containerRef) {
49
52
  if (!visibleContainer) {
50
53
  return;
51
54
  }
52
- if (configs.length) {
53
- setCurrentConfig(selectConfig(getMaxPossibleWidth(visibleContainer), configs));
54
- }
55
+ setCurrentConfig(selectConfig(getMaxPossibleWidth(visibleContainer), configs));
55
56
  }, [configs, containerRef]);
56
57
  useEffect(() => {
57
58
  var _a;
@@ -46,6 +46,9 @@ const collapseAllRest = (lastElementRenderMode, rest) => rest.map((element, inde
46
46
  return Object.assign(Object.assign({}, element), { renderMode: lastItem ? lastElementRenderMode : ITEM_RENDER_MODE.Collapsed });
47
47
  });
48
48
  export function buildBreadcrumbsConfigs(items, sizeMap, lastEmpty) {
49
+ if (!items.length) {
50
+ return [];
51
+ }
49
52
  const chains = [];
50
53
  const [first, ...rest] = items.map(item => (Object.assign(Object.assign({}, item), { renderMode: ITEM_RENDER_MODE.Full })));
51
54
  buildSubChain(rest, { useCollapse: true, useEllipse: true }).forEach(subset => {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Breadcrumbs",
7
- "version": "0.8.37",
7
+ "version": "0.8.39-preview-0eada078.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,11 +32,11 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/list": "0.13.4",
35
+ "@snack-uikit/list": "0.13.5",
36
36
  "@snack-uikit/typography": "0.6.2",
37
37
  "@snack-uikit/utils": "3.3.0",
38
38
  "classnames": "2.3.2",
39
39
  "lodash.debounce": "4.0.8"
40
40
  },
41
- "gitHead": "a24da7478c0b00f3e60d821466c31b2e9d57a719"
41
+ "gitHead": "022d623ce1e94b48ac4026b5ef0edaae5b06d0e6"
42
42
  }
@@ -25,6 +25,9 @@ export const HiddenChain = memo(function HiddenChain({
25
25
  lastEmpty = false,
26
26
  }: HiddenChainProps) {
27
27
  const containerRef = useRef<HTMLUListElement>(null);
28
+ const itemsRef = useRef<Item[]>(items);
29
+
30
+ itemsRef.current = items;
28
31
 
29
32
  useEffect(() => {
30
33
  const container = containerRef.current;
@@ -32,7 +35,7 @@ export const HiddenChain = memo(function HiddenChain({
32
35
  const observer = new ResizeObserver(([{ target }]) => {
33
36
  const sizeMap = buildSizeMap(target);
34
37
  if (sizeMap) {
35
- onConfigsBuilt(buildBreadcrumbsConfigs(items, sizeMap, lastEmpty));
38
+ onConfigsBuilt(buildBreadcrumbsConfigs(itemsRef.current, sizeMap, lastEmpty));
36
39
  }
37
40
  });
38
41
  observer.observe(container);
@@ -41,7 +44,7 @@ export const HiddenChain = memo(function HiddenChain({
41
44
  observer.disconnect();
42
45
  };
43
46
  }
44
- }, [items, lastEmpty, onConfigsBuilt]);
47
+ }, [lastEmpty, onConfigsBuilt]);
45
48
 
46
49
  const renderItemModes = useItemModesRender({ firstItemIconOnly });
47
50
 
package/src/hooks.tsx CHANGED
@@ -25,6 +25,8 @@ const selectConfig = (containerWidth: number, configs: BreadcrumbsConfig[]): Cur
25
25
  bestConfig = config;
26
26
  }
27
27
  }
28
+ } else if (config.width < bestConfig.width) {
29
+ bestConfig = config;
28
30
  }
29
31
  }
30
32
 
@@ -63,9 +65,7 @@ export function useBreadcrumbsLayout(containerRef: RefObject<HTMLElement>): Brea
63
65
  return;
64
66
  }
65
67
 
66
- if (configs.length) {
67
- setCurrentConfig(selectConfig(getMaxPossibleWidth(visibleContainer), configs));
68
- }
68
+ setCurrentConfig(selectConfig(getMaxPossibleWidth(visibleContainer), configs));
69
69
  }, [configs, containerRef]);
70
70
 
71
71
  useEffect(() => {
@@ -72,6 +72,10 @@ const collapseAllRest = (lastElementRenderMode: ItemRenderMode, rest: InnerItem[
72
72
  });
73
73
 
74
74
  export function buildBreadcrumbsConfigs(items: Item[], sizeMap: SizeMap, lastEmpty?: boolean): BreadcrumbsConfig[] {
75
+ if (!items.length) {
76
+ return [];
77
+ }
78
+
75
79
  const chains: InnerItem[][] = [];
76
80
  const [first, ...rest] = items.map(item => ({ ...item, renderMode: ITEM_RENDER_MODE.Full }));
77
81