@neovici/cosmoz-bottom-bar 9.2.0 → 9.3.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.
@@ -133,6 +133,9 @@ const useMenuButtons = (host) => {
133
133
  visible: new Set(),
134
134
  overflowing: new Set(),
135
135
  });
136
+ useEffect(() => {
137
+ host.dispatchEvent(new CustomEvent('reflow', { detail: buttonStates }));
138
+ }, [buttonStates]);
136
139
  const allButtons = useMemo(() => [...buttonStates.visible, ...buttonStates.overflowing], [buttonStates]);
137
140
  const processedButtons = useMemo(() => allButtons
138
141
  .map((btn) => ({
@@ -4,6 +4,7 @@ import { DirectiveResult } from 'lit-html/directive.js';
4
4
  type OnOverflow = (opts: {
5
5
  visible: Set<HTMLElement>;
6
6
  overflowing: Set<HTMLElement>;
7
+ hidden: Set<HTMLElement>;
7
8
  }) => void;
8
9
  declare class OverflowDirective extends AsyncDirective {
9
10
  observer?: IntersectionObserver;
package/dist/overflow.js CHANGED
@@ -4,14 +4,30 @@ import { directive } from 'lit-html/directive.js';
4
4
  function isEntryHidden(el) {
5
5
  return el.boundingClientRect.height === 0;
6
6
  }
7
+ function isElementHidden(el) {
8
+ return el.getBoundingClientRect().height === 0;
9
+ }
7
10
  const check = (part) => {
8
11
  if (part.element.tagName !== 'SLOT') {
9
12
  throw new Error('Overflow directive must be used on a slot element');
10
13
  }
11
14
  };
15
+ function reconcileHiddenElements(hidden, overflowing) {
16
+ // If a parent element was hidden, all its children were marked as hidden.
17
+ // When the parent becomes visible, the observer only reports entries for
18
+ // children that intersect the parent’s content box. Others remain stuck in
19
+ // `hidden` even if they should be `overflowing`. This pass corrects that.
20
+ hidden.forEach((el) => {
21
+ if (isElementHidden(el))
22
+ return;
23
+ overflowing.add(el);
24
+ hidden.delete(el);
25
+ });
26
+ }
12
27
  const setupObserver = (slot, onOverflow) => {
13
28
  let visible = new Set();
14
29
  let overflowing = new Set();
30
+ let hidden = new Set();
15
31
  const observer = new IntersectionObserver((entries) => {
16
32
  entries.forEach((entry) => {
17
33
  const el = entry.target;
@@ -19,22 +35,27 @@ const setupObserver = (slot, onOverflow) => {
19
35
  entry.intersectionRect.height !== 0) {
20
36
  visible.add(el);
21
37
  overflowing.delete(el);
38
+ hidden.delete(el);
22
39
  }
23
40
  else if (isEntryHidden(entry)) {
24
41
  visible.delete(el);
25
42
  overflowing.delete(el);
43
+ hidden.add(el);
26
44
  }
27
45
  else {
28
46
  visible.delete(el);
29
47
  overflowing.add(el);
48
+ hidden.delete(el);
30
49
  }
31
50
  });
32
- onOverflow({ visible, overflowing });
51
+ reconcileHiddenElements(hidden, overflowing);
52
+ onOverflow({ visible, overflowing, hidden });
33
53
  }, { root: slot.parentElement, threshold: [0, 0.5, 1] });
34
54
  const observe = () => {
35
55
  const elements = Array.from(slot.assignedElements({ flatten: true }));
36
56
  const newVisible = new Set();
37
57
  const newOverflowing = new Set();
58
+ const newHidden = new Set();
38
59
  for (const c of elements) {
39
60
  if (visible.has(c)) {
40
61
  newVisible.add(c);
@@ -42,13 +63,17 @@ const setupObserver = (slot, onOverflow) => {
42
63
  else if (overflowing.has(c)) {
43
64
  newOverflowing.add(c);
44
65
  }
66
+ else if (hidden.has(c)) {
67
+ newHidden.add(c);
68
+ }
45
69
  else {
46
70
  observer.observe(c);
47
71
  }
48
72
  }
49
73
  visible = newVisible;
50
74
  overflowing = newOverflowing;
51
- onOverflow({ visible, overflowing });
75
+ hidden = newHidden;
76
+ onOverflow({ visible, overflowing, hidden });
52
77
  };
53
78
  observe();
54
79
  slot.addEventListener('slotchange', observe);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-bottom-bar",
3
- "version": "9.2.0",
3
+ "version": "9.3.0",
4
4
  "description": "A responsive bottom-bar that can house buttons/actions and a menu for the buttons that won't fit the available width.",
5
5
  "keywords": [
6
6
  "polymer",