@fluentui/priority-overflow 9.0.0-rc.1 → 9.0.0-rc.2

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,43 @@
2
2
  "name": "@fluentui/priority-overflow",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 17 Nov 2022 23:02:29 GMT",
5
+ "date": "Mon, 09 Jan 2023 14:31:41 GMT",
6
+ "tag": "@fluentui/priority-overflow_v9.0.0-rc.2",
7
+ "version": "9.0.0-rc.2",
8
+ "comments": {
9
+ "prerelease": [
10
+ {
11
+ "author": "lingfangao@hotmail.com",
12
+ "package": "@fluentui/priority-overflow",
13
+ "commit": "2611ae5441e4bc702c4ce6404c7186f6c2de7cc3",
14
+ "comment": "fix: Minimum visible overflow items should be respected"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Wed, 04 Jan 2023 01:40:47 GMT",
21
+ "tag": "@fluentui/priority-overflow_v9.0.0-rc.1",
22
+ "version": "9.0.0-rc.1",
23
+ "comments": {
24
+ "none": [
25
+ {
26
+ "author": "martinhochel@microsoft.com",
27
+ "package": "@fluentui/priority-overflow",
28
+ "commit": "4ec2b998b294d6d9c3196d3d82893bdd97d0c105",
29
+ "comment": "chore(scripts): move index.ts to to follow sub-folder domain packaging"
30
+ },
31
+ {
32
+ "author": "martinhochel@microsoft.com",
33
+ "package": "@fluentui/priority-overflow",
34
+ "commit": "194b0cf0cc27c1c1233aa945f09b3ad29778d8ca",
35
+ "comment": "chore(scripts): use for @fluentui/scripts version within all package.json"
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ {
41
+ "date": "Thu, 17 Nov 2022 23:05:32 GMT",
6
42
  "tag": "@fluentui/priority-overflow_v9.0.0-rc.1",
7
43
  "version": "9.0.0-rc.1",
8
44
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Change Log - @fluentui/priority-overflow
2
2
 
3
- This log was last generated on Thu, 17 Nov 2022 23:02:29 GMT and should not be manually modified.
3
+ This log was last generated on Mon, 09 Jan 2023 14:31:41 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.0.0-rc.2](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v9.0.0-rc.2)
8
+
9
+ Mon, 09 Jan 2023 14:31:41 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.0-rc.1..@fluentui/priority-overflow_v9.0.0-rc.2)
11
+
12
+ ### Changes
13
+
14
+ - fix: Minimum visible overflow items should be respected ([PR #26194](https://github.com/microsoft/fluentui/pull/26194) by lingfangao@hotmail.com)
15
+
7
16
  ## [9.0.0-rc.1](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v9.0.0-rc.1)
8
17
 
9
- Thu, 17 Nov 2022 23:02:29 GMT
18
+ Thu, 17 Nov 2022 23:05:32 GMT
10
19
  [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.0-beta.4..@fluentui/priority-overflow_v9.0.0-rc.1)
11
20
 
12
21
  ### Changes
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/priority-overflow/src/debounce.ts"],"names":[],"mappings":"AAAA;;;;;AAKG;AACH,OAAM,SAAU,QAAV,CAAmB,EAAnB,EAA+B;EACnC,IAAI,OAAJ;EACA,OAAO,MAAK;IACV,IAAI,CAAC,OAAL,EAAc;MACZ,OAAO,GAAG,IAAV;MACA,cAAc,CAAC,MAAK;QAClB;QACA;QACA,OAAO,GAAG,KAAV;QACA,EAAE;MACH,CALa,CAAd;IAMD;EACF,CAVD;AAWD","sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA;;;;;;AAMA,OAAM,SAAUA,QAAQ,CAACC,EAAY;EACnC,IAAIC,OAAgB;EACpB,OAAO,MAAK;IACV,IAAI,CAACA,OAAO,EAAE;MACZA,OAAO,GAAG,IAAI;MACdC,cAAc,CAAC,MAAK;QAClB;QACA;QACAD,OAAO,GAAG,KAAK;QACfD,EAAE,EAAE;MACN,CAAC,CAAC;;EAEN,CAAC;AACH","names":["debounce","fn","pending","queueMicrotask"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/debounce.ts"],"sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"]}
@@ -4,7 +4,6 @@ import { createPriorityQueue } from './priorityQueue';
4
4
  * @internal
5
5
  * @returns overflow manager instance
6
6
  */
7
-
8
7
  export function createOverflowManager() {
9
8
  let container;
10
9
  let overflowMenu;
@@ -23,44 +22,37 @@ export function createOverflowManager() {
23
22
  if (!entries[0] || !container) {
24
23
  return;
25
24
  }
26
-
27
25
  update();
28
26
  });
29
27
  const invisibleItemQueue = createPriorityQueue((a, b) => {
30
28
  const itemA = overflowItems[a];
31
- const itemB = overflowItems[b]; // Higher priority at the top of the queue
32
-
29
+ const itemB = overflowItems[b];
30
+ // Higher priority at the top of the queue
33
31
  const priority = itemB.priority - itemA.priority;
34
-
35
32
  if (priority !== 0) {
36
33
  return priority;
37
34
  }
38
-
39
- const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING; // equal priority, use DOM order
35
+ const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
36
+ // equal priority, use DOM order
40
37
  // eslint-disable-next-line no-bitwise
41
-
42
38
  return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
43
39
  });
44
40
  const visibleItemQueue = createPriorityQueue((a, b) => {
45
41
  const itemA = overflowItems[a];
46
- const itemB = overflowItems[b]; // Lower priority at the top of the queue
47
-
42
+ const itemB = overflowItems[b];
43
+ // Lower priority at the top of the queue
48
44
  const priority = itemA.priority - itemB.priority;
49
-
50
45
  if (priority !== 0) {
51
46
  return priority;
52
47
  }
53
-
54
- const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING; // equal priority, use DOM order
48
+ const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
49
+ // equal priority, use DOM order
55
50
  // eslint-disable-next-line no-bitwise
56
-
57
51
  return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
58
52
  });
59
-
60
53
  const getOffsetSize = el => {
61
54
  return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;
62
55
  };
63
-
64
56
  const makeItemVisible = () => {
65
57
  const nextVisible = invisibleItemQueue.dequeue();
66
58
  visibleItemQueue.enqueue(nextVisible);
@@ -69,15 +61,12 @@ export function createOverflowManager() {
69
61
  item,
70
62
  visible: true
71
63
  });
72
-
73
64
  if (item.groupId) {
74
65
  overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
75
66
  overflowGroups[item.groupId].visibleItemIds.add(item.id);
76
67
  }
77
-
78
68
  return getOffsetSize(item.element);
79
69
  };
80
-
81
70
  const makeItemInvisible = () => {
82
71
  const nextInvisible = visibleItemQueue.dequeue();
83
72
  invisibleItemQueue.enqueue(nextInvisible);
@@ -87,15 +76,12 @@ export function createOverflowManager() {
87
76
  item,
88
77
  visible: false
89
78
  });
90
-
91
79
  if (item.groupId) {
92
80
  overflowGroups[item.groupId].visibleItemIds.delete(item.id);
93
81
  overflowGroups[item.groupId].invisibleItemIds.add(item.id);
94
82
  }
95
-
96
83
  return width;
97
84
  };
98
-
99
85
  const dispatchOverflowUpdate = () => {
100
86
  const visibleItemIds = visibleItemQueue.all();
101
87
  const invisibleItemIds = invisibleItemQueue.all();
@@ -117,56 +103,47 @@ export function createOverflowManager() {
117
103
  groupVisibility
118
104
  });
119
105
  };
120
-
121
106
  const processOverflowItems = availableSize => {
122
107
  if (!container) {
123
108
  return;
124
109
  }
125
-
126
- const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0; // Snapshot of the visible/invisible state to compare for updates
127
-
110
+ const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
111
+ // Snapshot of the visible/invisible state to compare for updates
128
112
  const visibleTop = visibleItemQueue.peek();
129
113
  const invisibleTop = invisibleItemQueue.peek();
130
114
  const visibleItemIds = visibleItemQueue.all();
131
115
  let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {
132
116
  const child = overflowItems[visibleItemId].element;
133
117
  return sum + getOffsetSize(child);
134
- }, 0); // Add items until available width is filled
135
-
118
+ }, 0);
119
+ // Add items until available width is filled - can result in overflow
136
120
  while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {
137
121
  currentWidth += makeItemVisible();
138
- } // Remove items until there's no more overlap
139
-
140
-
122
+ }
123
+ // Remove items until there's no more overflow
141
124
  while (currentWidth > availableSize && visibleItemQueue.size() > 0) {
142
- if (visibleItemQueue.size() === options.minimumVisible) {
125
+ if (visibleItemQueue.size() <= options.minimumVisible) {
143
126
  break;
144
127
  }
145
-
146
128
  currentWidth -= makeItemInvisible();
147
129
  }
148
-
149
- if (invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {
130
+ // make sure the overflow menu can fit
131
+ if (visibleItemQueue.size() > options.minimumVisible && invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {
150
132
  makeItemInvisible();
151
- } // only update when the state of visible/invisible items has changed
152
-
153
-
133
+ }
134
+ // only update when the state of visible/invisible items has changed
154
135
  if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
155
136
  dispatchOverflowUpdate();
156
137
  }
157
138
  };
158
-
159
139
  const forceUpdate = () => {
160
140
  if (!container) {
161
141
  return;
162
142
  }
163
-
164
143
  const availableSize = getOffsetSize(container) - options.padding;
165
144
  processOverflowItems(availableSize);
166
145
  };
167
-
168
146
  const update = debounce(forceUpdate);
169
-
170
147
  const observe = (observedContainer, userOptions) => {
171
148
  Object.assign(options, userOptions);
172
149
  observing = true;
@@ -174,23 +151,19 @@ export function createOverflowManager() {
174
151
  container = observedContainer;
175
152
  resizeObserver.observe(container);
176
153
  };
177
-
178
154
  const disconnect = () => {
179
155
  observing = false;
180
156
  resizeObserver.disconnect();
181
157
  };
182
-
183
158
  const addItem = item => {
184
159
  if (overflowItems[item.id]) {
185
160
  return;
186
161
  }
187
-
188
- overflowItems[item.id] = item; // some options can affect priority which are only set on `observe`
189
-
162
+ overflowItems[item.id] = item;
163
+ // some options can affect priority which are only set on `observe`
190
164
  if (observing) {
191
165
  visibleItemQueue.enqueue(item.id);
192
166
  }
193
-
194
167
  if (item.groupId) {
195
168
  if (!overflowGroups[item.groupId]) {
196
169
  overflowGroups[item.groupId] = {
@@ -198,39 +171,30 @@ export function createOverflowManager() {
198
171
  invisibleItemIds: new Set()
199
172
  };
200
173
  }
201
-
202
174
  overflowGroups[item.groupId].visibleItemIds.add(item.id);
203
175
  }
204
-
205
176
  update();
206
177
  };
207
-
208
178
  const addOverflowMenu = el => {
209
179
  overflowMenu = el;
210
180
  };
211
-
212
181
  const removeOverflowMenu = () => {
213
182
  overflowMenu = undefined;
214
183
  };
215
-
216
184
  const removeItem = itemId => {
217
185
  if (!overflowItems[itemId]) {
218
186
  return;
219
187
  }
220
-
221
188
  const item = overflowItems[itemId];
222
189
  visibleItemQueue.remove(itemId);
223
190
  invisibleItemQueue.remove(itemId);
224
-
225
191
  if (item.groupId) {
226
192
  overflowGroups[item.groupId].visibleItemIds.delete(item.id);
227
193
  overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
228
194
  }
229
-
230
195
  delete overflowItems[itemId];
231
196
  update();
232
197
  };
233
-
234
198
  return {
235
199
  addItem,
236
200
  disconnect,
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/priority-overflow/src/overflowManager.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,QAAyB,YAAzB;AACA,SAAS,mBAAT,QAAoC,iBAApC;AAGA;;;AAGG;;AACH,OAAM,SAAU,qBAAV,GAA+B;EACnC,IAAI,SAAJ;EACA,IAAI,YAAJ;EACA,IAAI,SAAS,GAAG,KAAhB;EACA,MAAM,OAAO,GAA6B;IACxC,OAAO,EAAE,EAD+B;IAExC,YAAY,EAAE,YAF0B;IAGxC,iBAAiB,EAAE,KAHqB;IAIxC,cAAc,EAAE,CAJwB;IAKxC,sBAAsB,EAAE,MAAM,SALU;IAMxC,gBAAgB,EAAE,MAAM;EANgB,CAA1C;EASA,MAAM,aAAa,GAAsC,EAAzD;EACA,MAAM,cAAc,GAAmF,EAAvG;EACA,MAAM,cAAc,GAAG,IAAI,cAAJ,CAAmB,OAAO,IAAG;IAClD,IAAI,CAAC,OAAO,CAAC,CAAD,CAAR,IAAe,CAAC,SAApB,EAA+B;MAC7B;IACD;;IAED,MAAM;EACP,CANsB,CAAvB;EAQA,MAAM,kBAAkB,GAAG,mBAAmB,CAAS,CAAC,CAAD,EAAI,CAAJ,KAAS;IAC9D,MAAM,KAAK,GAAG,aAAa,CAAC,CAAD,CAA3B;IACA,MAAM,KAAK,GAAG,aAAa,CAAC,CAAD,CAA3B,CAF8D,CAG9D;;IACA,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAN,GAA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C,CAAqD,IAAI,CAAC,EAA1D;IACD;;IAED,OAAO,aAAa,CAAC,MAAD,CAApB;IACA,MAAM;EACP,CAhBD;;EAkBA,OAAO;IACL,OADK;IAEL,UAFK;IAGL,WAHK;IAIL,OAJK;IAKL,UALK;IAML,MANK;IAOL,eAPK;IAQL;EARK,CAAP;AAUD","sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n let observing = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n // Remove items until there's no more overlap\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() === options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n if (invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAAA,SAASA,QAAQ,QAAQ,YAAY;AACrC,SAASC,mBAAmB,QAAQ,iBAAiB;AAGrD;;;;AAIA,OAAM,SAAUC,qBAAqB;EACnC,IAAIC,SAAkC;EACtC,IAAIC,YAAqC;EACzC,IAAIC,SAAS,GAAG,KAAK;EACrB,MAAMC,OAAO,GAA6B;IACxCC,OAAO,EAAE,EAAE;IACXC,YAAY,EAAE,YAAY;IAC1BC,iBAAiB,EAAE,KAAK;IACxBC,cAAc,EAAE,CAAC;IACjBC,sBAAsB,EAAE,MAAMC,SAAS;IACvCC,gBAAgB,EAAE,MAAMD;GACzB;EAED,MAAME,aAAa,GAAsC,EAAE;EAC3D,MAAMC,cAAc,GAAmF,EAAE;EACzG,MAAMC,cAAc,GAAG,IAAIC,cAAc,CAACC,OAAO,IAAG;IAClD,IAAI,CAACA,OAAO,CAAC,CAAC,CAAC,IAAI,CAACf,SAAS,EAAE;MAC7B;;IAGFgB,MAAM,EAAE;EACV,CAAC,CAAC;EAEF,MAAMC,kBAAkB,GAAGnB,mBAAmB,CAAS,CAACoB,CAAC,EAAEC,CAAC,KAAI;IAC9D,MAAMC,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AC1B,CAAC;EAED,MAAMyE,UAAU,GAAkC7B,MAAM,IAAG;IACzD,IAAI,CAAC1C,aAAa,CAAC0C,MAAM,CAAC,EAAE;MAC1B;;IAGF,MAAMf,IAAI,GAAG3B,aAAa,CAAC0C,MAAM,CAAC;IAClCxB,gBAAgB,CAACsD,MAAM,CAAC9B,MAAM,CAAC;IAC/BpC,kBAAkB,CAACkE,MAAM,CAAC9B,MAAM,CAAC;IAEjC,IAAIf,IAAI,CAACE,OAAO,EAAE;MAChB5B,cAAc,CAAC0B,IAAI,CAACE,OAAO,CAAC,CAACI,cAAc,CAACF,MAAM,CAACJ,IAAI,CAACK,EAAE,CAAC;MAC3D/B,cAAc,CAAC0B,IAAI,CAACE,OAAO,CAAC,CAACC,gBAAgB,CAACC,MAAM,CAACJ,IAAI,CAACK,EAAE,CAAC;;IAG/D,OAAOhC,aAAa,CAAC0C,MAAM,CAAC;IAC5BrC,MAAM,EAAE;EACV,CAAC;EAED,OAAO;IACL8D,OAAO;IACPD,UAAU;IACVN,WAAW;IACXC,OAAO;IACPU,UAAU;IACVlE,MAAM;IACNgE,eAAe;IACfC;GACD;AACH","names":["debounce","createPriorityQueue","createOverflowManager","container","overflowMenu","observing","options","padding","overflowAxis","overflowDirection","minimumVisible","onUpdateItemVisibility","undefined","onUpdateOverflow","overflowItems","overflowGroups","resizeObserver","ResizeObserver","entries","update","invisibleItemQueue","a","b","itemA","itemB","priority","positionStatusBit","Node","DOCUMENT_POSITION_FOLLOWING","DOCUMENT_POSITION_PRECEDING","element","compareDocumentPosition","visibleItemQueue","getOffsetSize","el","offsetWidth","offsetHeight","makeItemVisible","nextVisible","dequeue","enqueue","item","visible","groupId","invisibleItemIds","delete","id","visibleItemIds","add","makeItemInvisible","nextInvisible","width","dispatchOverflowUpdate","all","visibleItems","map","itemId","invisibleItems","groupVisibility","Object","forEach","groupState","size","processOverflowItems","availableSize","overflowMenuOffset","visibleTop","peek","invisibleTop","currentWidth","reduce","sum","visibleItemId","child","forceUpdate","observe","observedContainer","userOptions","assign","values","disconnect","addItem","Set","addOverflowMenu","removeOverflowMenu","removeItem","remove"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/overflowManager.ts"],"sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n let observing = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n\n // Remove items until there's no more overflow\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() <= options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // make sure the overflow menu can fit\n if (\n visibleItemQueue.size() > options.minimumVisible &&\n invisibleItemQueue.size() > 0 &&\n currentWidth + overflowMenuOffset > availableSize\n ) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"]}
@@ -5,99 +5,78 @@
5
5
  export function createPriorityQueue(compare) {
6
6
  const arr = [];
7
7
  let size = 0;
8
-
9
8
  const left = i => {
10
9
  return 2 * i + 1;
11
10
  };
12
-
13
11
  const right = i => {
14
12
  return 2 * i + 2;
15
13
  };
16
-
17
14
  const parent = i => {
18
15
  return Math.floor((i - 1) / 2);
19
16
  };
20
-
21
17
  const swap = (a, b) => {
22
18
  const tmp = arr[a];
23
19
  arr[a] = arr[b];
24
20
  arr[b] = tmp;
25
21
  };
26
-
27
22
  const heapify = i => {
28
23
  let smallest = i;
29
24
  const l = left(i);
30
25
  const r = right(i);
31
-
32
26
  if (l < size && compare(arr[l], arr[smallest]) < 0) {
33
27
  smallest = l;
34
28
  }
35
-
36
29
  if (r < size && compare(arr[r], arr[smallest]) < 0) {
37
30
  smallest = r;
38
31
  }
39
-
40
32
  if (smallest !== i) {
41
33
  swap(smallest, i);
42
34
  heapify(smallest);
43
35
  }
44
36
  };
45
-
46
37
  const dequeue = () => {
47
38
  if (size === 0) {
48
39
  throw new Error('Priority queue empty');
49
40
  }
50
-
51
41
  const res = arr[0];
52
42
  arr[0] = arr[--size];
53
43
  heapify(0);
54
44
  return res;
55
45
  };
56
-
57
46
  const peek = () => {
58
47
  if (size === 0) {
59
48
  return null;
60
49
  }
61
-
62
50
  return arr[0];
63
51
  };
64
-
65
52
  const enqueue = item => {
66
53
  arr[size++] = item;
67
54
  let i = size - 1;
68
55
  let p = parent(i);
69
-
70
56
  while (i > 0 && compare(arr[p], arr[i]) > 0) {
71
57
  swap(p, i);
72
58
  i = p;
73
59
  p = parent(i);
74
60
  }
75
61
  };
76
-
77
62
  const contains = item => {
78
63
  const index = arr.indexOf(item);
79
64
  return index >= 0 && index < size;
80
65
  };
81
-
82
66
  const remove = item => {
83
67
  const i = arr.indexOf(item);
84
-
85
68
  if (i === -1 || i >= size) {
86
69
  return;
87
70
  }
88
-
89
71
  arr[i] = arr[--size];
90
72
  heapify(i);
91
73
  };
92
-
93
74
  const clear = () => {
94
75
  size = 0;
95
76
  };
96
-
97
77
  const all = () => {
98
78
  return arr.slice(0, size);
99
79
  };
100
-
101
80
  return {
102
81
  all,
103
82
  clear,
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/priority-overflow/src/priorityQueue.ts"],"names":[],"mappings":"AAaA;;;AAGG;AACH,OAAM,SAAU,mBAAV,CAAiC,OAAjC,EAAmE;EACvE,MAAM,GAAG,GAAQ,EAAjB;EACA,IAAI,IAAI,GAAG,CAAX;;EAEA,MAAM,IAAI,GAAI,CAAD,IAAc;IACzB,OAAO,IAAI,CAAJ,GAAQ,CAAf;EACD,CAFD;;EAIA,MAAM,KAAK,GAAI,CAAD,IAAc;IAC1B,OAAO,IAAI,CAAJ,GAAQ,CAAf;EACD,CAFD;;EAIA,MAAM,MAAM,GAAI,CAAD,IAAc;IAC3B,OAAO,IAAI,CAAC,KAAL,CAAW,CAAC,CAAC,GAAG,CAAL,IAAU,CAArB,CAAP;EACD,CAFD;;EAIA,MAAM,IAAI,GAAG,CAAC,CAAD,EAAY,CAAZ,KAAyB;IACpC,MAAM,GAAG,GAAG,GAAG,CAAC,CAAD,CAAf;IACA,GAAG,CAAC,CAAD,CAAH,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,GAAG,IAAI,GAAG,CAAf;IACA,IAAI,CAAC,GAAG,MAAM,CAAC,CAAD,CAAd;;IACA,OAAO,CAAC,GAAG,CAAJ,IAAS,OAAO,CAAC,GAAG,CAAC,CAAD,CAAJ,EAAS,GAAG,CAAC,CAAD,CAAZ,CAAP,GAA0B,CAA1C,EAA6C;MAC3C,IAAI,CAAC,CAAD,EAAI,CAAJ,CAAJ;MACA,CAAC,GAAG,CAAJ;MACA,CAAC,GAAG,MAAM,CAAC,CAAD,CAAV;IACD;EACF,CATD;;EAWA,MAAM,QAAQ,GAAI,IAAD,IAAY;IAC3B,MAAM,KAAK,GAAG,GAAG,CAAC,OAAJ,CAAY,IAAZ,CAAd;IACA,OAAO,KAAK,IAAI,CAAT,IAAc,KAAK,GAAG,IAA7B;EACD,CAHD;;EAKA,MAAM,MAAM,GAAI,IAAD,IAAY;IACzB,MAAM,CAAC,GAAG,GAAG,CAAC,OAAJ,CAAY,IAAZ,CAAV;;IAEA,IAAI,CAAC,KAAK,CAAC,CAAP,IAAY,CAAC,IAAI,IAArB,EAA2B;MACzB;IACD;;IAED,GAAG,CAAC,CAAD,CAAH,GAAS,GAAG,CAAC,EAAE,IAAH,CAAZ;IACA,OAAO,CAAC,CAAD,CAAP;EACD,CATD;;EAWA,MAAM,KAAK,GAAG,MAAK;IACjB,IAAI,GAAG,CAAP;EACD,CAFD;;EAIA,MAAM,GAAG,GAAG,MAAK;IACf,OAAO,GAAG,CAAC,KAAJ,CAAU,CAAV,EAAa,IAAb,CAAP;EACD,CAFD;;EAIA,OAAO;IACL,GADK;IAEL,KAFK;IAGL,QAHK;IAIL,OAJK;IAKL,OALK;IAML,IANK;IAOL,MAPK;IAQL,IAAI,EAAE,MAAM;EARP,CAAP;AAUD","sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n const index = arr.indexOf(item);\n return index >= 0 && index < size;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1 || i >= size) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"AAaA;;;;AAIA,OAAM,SAAUA,mBAAmB,CAAIC,OAAkC;EACvE,MAAMC,GAAG,GAA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IAGFD,GAAG,CAACG,CAAC,CAAC,GAAGH,GAAG,CAAC,EAAEC,IAAI,CAAC;IACpBW,OAAO,CAACT,CAAC,CAAC;EACZ,CAAC;EAED,MAAMwB,KAAK,GAAG,MAAK;IACjB1B,IAAI,GAAG,CAAC;EACV,CAAC;EAED,MAAM2B,GAAG,GAAG,MAAK;IACf,OAAO5B,GAAG,CAAC6B,KAAK,CAAC,CAAC,EAAE5B,IAAI,CAAC;EAC3B,CAAC;EAED,OAAO;IACL2B,GAAG;IACHD,KAAK;IACLJ,QAAQ;IACRP,OAAO;IACPI,OAAO;IACPD,IAAI;IACJO,MAAM;IACNzB,IAAI,EAAE,MAAMA;GACb;AACH","names":["createPriorityQueue","compare","arr","size","left","i","right","parent","Math","floor","swap","a","b","tmp","heapify","smallest","l","r","dequeue","Error","res","peek","enqueue","item","p","contains","index","indexOf","remove","clear","all","slice"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/priorityQueue.ts"],"sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n const index = arr.indexOf(item);\n return index >= 0 && index < size;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1 || i >= size) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"]}
@@ -10,7 +10,6 @@ exports.debounce = void 0;
10
10
  * @param fn - Function to debounce
11
11
  * @returns debounced function
12
12
  */
13
-
14
13
  function debounce(fn) {
15
14
  let pending;
16
15
  return () => {
@@ -25,6 +24,5 @@ function debounce(fn) {
25
24
  }
26
25
  };
27
26
  }
28
-
29
27
  exports.debounce = debounce;
30
28
  //# sourceMappingURL=debounce.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/priority-overflow/src/debounce.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;AAKG;;AACH,SAAgB,QAAhB,CAAyB,EAAzB,EAAqC;EACnC,IAAI,OAAJ;EACA,OAAO,MAAK;IACV,IAAI,CAAC,OAAL,EAAc;MACZ,OAAO,GAAG,IAAV;MACA,cAAc,CAAC,MAAK;QAClB;QACA;QACA,OAAO,GAAG,KAAV;QACA,EAAE;MACH,CALa,CAAd;IAMD;EACF,CAVD;AAWD;;AAbD,OAAA,CAAA,QAAA,GAAA,QAAA","sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;;;;;;AAMA,SAAgBA,QAAQ,CAACC,EAAY;EACnC,IAAIC,OAAgB;EACpB,OAAO,MAAK;IACV,IAAI,CAACA,OAAO,EAAE;MACZA,OAAO,GAAG,IAAI;MACdC,cAAc,CAAC,MAAK;QAClB;QACA;QACAD,OAAO,GAAG,KAAK;QACfD,EAAE,EAAE;MACN,CAAC,CAAC;;EAEN,CAAC;AACH;AAbAG","names":["debounce","fn","pending","queueMicrotask","exports"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/debounce.ts"],"sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"]}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createOverflowManager = void 0;
7
-
8
7
  var overflowManager_1 = /*#__PURE__*/require("./overflowManager");
9
-
10
8
  Object.defineProperty(exports, "createOverflowManager", {
11
9
  enumerable: true,
12
10
  get: function () {
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/priority-overflow/src/index.ts"],"names":[],"mappings":";;;;;;;AAAA,IAAA,iBAAA,gBAAA,OAAA,CAAA,mBAAA,CAAA;;AAAS,MAAA,CAAA,cAAA,CAAA,OAAA,EAAA,uBAAA,EAAA;EAAA,UAAA,EAAA,IAAA;EAAA,GAAA,EAAA,YAAA;IAAA,OAAA,iBAAA,CAAA,qBAAA;EAAqB;AAArB,CAAA","sourcesContent":["export { createOverflowManager } from './overflowManager';\nexport type {\n ObserveOptions,\n OnUpdateItemVisibility,\n OnUpdateItemVisibilityPayload,\n OnUpdateOverflow,\n OverflowAxis,\n OverflowDirection,\n OverflowEventPayload,\n OverflowGroupState,\n OverflowItemEntry,\n OverflowManager,\n} from './types';\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AAASA;EAAAC;EAAAC;IAAA,8CAAqB;EAAA;AAAA","names":["Object","enumerable","get"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/index.ts"],"sourcesContent":["export { createOverflowManager } from './overflowManager';\nexport type {\n ObserveOptions,\n OnUpdateItemVisibility,\n OnUpdateItemVisibilityPayload,\n OnUpdateOverflow,\n OverflowAxis,\n OverflowDirection,\n OverflowEventPayload,\n OverflowGroupState,\n OverflowItemEntry,\n OverflowManager,\n} from './types';\n"]}
@@ -4,16 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createOverflowManager = void 0;
7
-
8
7
  const debounce_1 = /*#__PURE__*/require("./debounce");
9
-
10
8
  const priorityQueue_1 = /*#__PURE__*/require("./priorityQueue");
11
9
  /**
12
10
  * @internal
13
11
  * @returns overflow manager instance
14
12
  */
15
-
16
-
17
13
  function createOverflowManager() {
18
14
  let container;
19
15
  let overflowMenu;
@@ -32,44 +28,37 @@ function createOverflowManager() {
32
28
  if (!entries[0] || !container) {
33
29
  return;
34
30
  }
35
-
36
31
  update();
37
32
  });
38
33
  const invisibleItemQueue = priorityQueue_1.createPriorityQueue((a, b) => {
39
34
  const itemA = overflowItems[a];
40
- const itemB = overflowItems[b]; // Higher priority at the top of the queue
41
-
35
+ const itemB = overflowItems[b];
36
+ // Higher priority at the top of the queue
42
37
  const priority = itemB.priority - itemA.priority;
43
-
44
38
  if (priority !== 0) {
45
39
  return priority;
46
40
  }
47
-
48
- const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING; // equal priority, use DOM order
41
+ const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
42
+ // equal priority, use DOM order
49
43
  // eslint-disable-next-line no-bitwise
50
-
51
44
  return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
52
45
  });
53
46
  const visibleItemQueue = priorityQueue_1.createPriorityQueue((a, b) => {
54
47
  const itemA = overflowItems[a];
55
- const itemB = overflowItems[b]; // Lower priority at the top of the queue
56
-
48
+ const itemB = overflowItems[b];
49
+ // Lower priority at the top of the queue
57
50
  const priority = itemA.priority - itemB.priority;
58
-
59
51
  if (priority !== 0) {
60
52
  return priority;
61
53
  }
62
-
63
- const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING; // equal priority, use DOM order
54
+ const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
55
+ // equal priority, use DOM order
64
56
  // eslint-disable-next-line no-bitwise
65
-
66
57
  return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
67
58
  });
68
-
69
59
  const getOffsetSize = el => {
70
60
  return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;
71
61
  };
72
-
73
62
  const makeItemVisible = () => {
74
63
  const nextVisible = invisibleItemQueue.dequeue();
75
64
  visibleItemQueue.enqueue(nextVisible);
@@ -78,15 +67,12 @@ function createOverflowManager() {
78
67
  item,
79
68
  visible: true
80
69
  });
81
-
82
70
  if (item.groupId) {
83
71
  overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
84
72
  overflowGroups[item.groupId].visibleItemIds.add(item.id);
85
73
  }
86
-
87
74
  return getOffsetSize(item.element);
88
75
  };
89
-
90
76
  const makeItemInvisible = () => {
91
77
  const nextInvisible = visibleItemQueue.dequeue();
92
78
  invisibleItemQueue.enqueue(nextInvisible);
@@ -96,15 +82,12 @@ function createOverflowManager() {
96
82
  item,
97
83
  visible: false
98
84
  });
99
-
100
85
  if (item.groupId) {
101
86
  overflowGroups[item.groupId].visibleItemIds.delete(item.id);
102
87
  overflowGroups[item.groupId].invisibleItemIds.add(item.id);
103
88
  }
104
-
105
89
  return width;
106
90
  };
107
-
108
91
  const dispatchOverflowUpdate = () => {
109
92
  const visibleItemIds = visibleItemQueue.all();
110
93
  const invisibleItemIds = invisibleItemQueue.all();
@@ -126,56 +109,47 @@ function createOverflowManager() {
126
109
  groupVisibility
127
110
  });
128
111
  };
129
-
130
112
  const processOverflowItems = availableSize => {
131
113
  if (!container) {
132
114
  return;
133
115
  }
134
-
135
- const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0; // Snapshot of the visible/invisible state to compare for updates
136
-
116
+ const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
117
+ // Snapshot of the visible/invisible state to compare for updates
137
118
  const visibleTop = visibleItemQueue.peek();
138
119
  const invisibleTop = invisibleItemQueue.peek();
139
120
  const visibleItemIds = visibleItemQueue.all();
140
121
  let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {
141
122
  const child = overflowItems[visibleItemId].element;
142
123
  return sum + getOffsetSize(child);
143
- }, 0); // Add items until available width is filled
144
-
124
+ }, 0);
125
+ // Add items until available width is filled - can result in overflow
145
126
  while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {
146
127
  currentWidth += makeItemVisible();
147
- } // Remove items until there's no more overlap
148
-
149
-
128
+ }
129
+ // Remove items until there's no more overflow
150
130
  while (currentWidth > availableSize && visibleItemQueue.size() > 0) {
151
- if (visibleItemQueue.size() === options.minimumVisible) {
131
+ if (visibleItemQueue.size() <= options.minimumVisible) {
152
132
  break;
153
133
  }
154
-
155
134
  currentWidth -= makeItemInvisible();
156
135
  }
157
-
158
- if (invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {
136
+ // make sure the overflow menu can fit
137
+ if (visibleItemQueue.size() > options.minimumVisible && invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {
159
138
  makeItemInvisible();
160
- } // only update when the state of visible/invisible items has changed
161
-
162
-
139
+ }
140
+ // only update when the state of visible/invisible items has changed
163
141
  if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
164
142
  dispatchOverflowUpdate();
165
143
  }
166
144
  };
167
-
168
145
  const forceUpdate = () => {
169
146
  if (!container) {
170
147
  return;
171
148
  }
172
-
173
149
  const availableSize = getOffsetSize(container) - options.padding;
174
150
  processOverflowItems(availableSize);
175
151
  };
176
-
177
152
  const update = debounce_1.debounce(forceUpdate);
178
-
179
153
  const observe = (observedContainer, userOptions) => {
180
154
  Object.assign(options, userOptions);
181
155
  observing = true;
@@ -183,23 +157,19 @@ function createOverflowManager() {
183
157
  container = observedContainer;
184
158
  resizeObserver.observe(container);
185
159
  };
186
-
187
160
  const disconnect = () => {
188
161
  observing = false;
189
162
  resizeObserver.disconnect();
190
163
  };
191
-
192
164
  const addItem = item => {
193
165
  if (overflowItems[item.id]) {
194
166
  return;
195
167
  }
196
-
197
- overflowItems[item.id] = item; // some options can affect priority which are only set on `observe`
198
-
168
+ overflowItems[item.id] = item;
169
+ // some options can affect priority which are only set on `observe`
199
170
  if (observing) {
200
171
  visibleItemQueue.enqueue(item.id);
201
172
  }
202
-
203
173
  if (item.groupId) {
204
174
  if (!overflowGroups[item.groupId]) {
205
175
  overflowGroups[item.groupId] = {
@@ -207,39 +177,30 @@ function createOverflowManager() {
207
177
  invisibleItemIds: new Set()
208
178
  };
209
179
  }
210
-
211
180
  overflowGroups[item.groupId].visibleItemIds.add(item.id);
212
181
  }
213
-
214
182
  update();
215
183
  };
216
-
217
184
  const addOverflowMenu = el => {
218
185
  overflowMenu = el;
219
186
  };
220
-
221
187
  const removeOverflowMenu = () => {
222
188
  overflowMenu = undefined;
223
189
  };
224
-
225
190
  const removeItem = itemId => {
226
191
  if (!overflowItems[itemId]) {
227
192
  return;
228
193
  }
229
-
230
194
  const item = overflowItems[itemId];
231
195
  visibleItemQueue.remove(itemId);
232
196
  invisibleItemQueue.remove(itemId);
233
-
234
197
  if (item.groupId) {
235
198
  overflowGroups[item.groupId].visibleItemIds.delete(item.id);
236
199
  overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
237
200
  }
238
-
239
201
  delete overflowItems[itemId];
240
202
  update();
241
203
  };
242
-
243
204
  return {
244
205
  addItem,
245
206
  disconnect,
@@ -251,6 +212,5 @@ function createOverflowManager() {
251
212
  removeOverflowMenu
252
213
  };
253
214
  }
254
-
255
215
  exports.createOverflowManager = createOverflowManager;
256
216
  //# sourceMappingURL=overflowManager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["packages/react-components/priority-overflow/src/overflowManager.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;AAGA;;;AAGG;;;AACH,SAAgB,qBAAhB,GAAqC;EACnC,IAAI,SAAJ;EACA,IAAI,YAAJ;EACA,IAAI,SAAS,GAAG,KAAhB;EACA,MAAM,OAAO,GAA6B;IACxC,OAAO,EAAE,EAD+B;IAExC,YAAY,EAAE,YAF0B;IAGxC,iBAAiB,EAAE,KAHqB;IAIxC,cAAc,EAAE,CAJwB;IAKxC,sBAAsB,EAAE,MAAM,SALU;IAMxC,gBAAgB,EAAE,MAAM;EANgB,CAA1C;EASA,MAAM,aAAa,GAAsC,EAAzD;EACA,MAAM,cAA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;EACD,CAFD;;EAIA,MAAM,UAAU,GAAkC,MAAM,IAAG;IACzD,IAAI,CAAC,aAAa,CAAC,MAAD,CAAlB,EAA4B;MAC1B;IACD;;IAED,MAAM,IAAI,GAAG,aAAa,CAAC,MAAD,CAA1B;IACA,gBAAgB,CAAC,MAAjB,CAAwB,MAAxB;IACA,kBAAkB,CAAC,MAAnB,CAA0B,MAA1B;;IAEA,IAAI,IAAI,CAAC,OAAT,EAAkB;MAChB,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,cAA7B,CAA4C,MAA5C,CAAmD,IAAI,CAAC,EAAxD;MACA,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,gBAA7B,CAA8C,MAA9C,CAAqD,IAAI,CAAC,EAA1D;IACD;;IAED,OAAO,aAAa,CAAC,MAAD,CAApB;IACA,MAAM;EACP,CAhBD;;EAkBA,OAAO;IACL,OADK;IAEL,UAFK;IAGL,WAHK;IAIL,OAJK;IAKL,UALK;IAML,MANK;IAOL,eAPK;IAQL;EARK,CAAP;AAUD;;AA9OD,OAAA,CAAA,qBAAA,GAAA,qBAAA","sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n let observing = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n // Remove items until there's no more overlap\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() === options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n if (invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAAA;AACA;AAGA;;;;AAIA,SAAgBA,qBAAqB;EACnC,IAAIC,SAAkC;EACtC,IAAIC,YAAqC;EACzC,IAAIC,SAAS,GAAG,KAAK;EACrB,MAAMC,OAAO,GAA6B;IACxCC,OAAO,EAAE,EAAE;IACXC,YAAY,EAAE,YAAY;IAC1BC,iBAAiB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,EAAE;QACjC7B,cAAc,CAAC2B,IAAI,CAACE,OAAO,CAAC,GAAG;UAC7BI,cAAc,EAAE,IAAIoC,GAAG,EAAU;UACjCvC,gBAAgB,EAAE,IAAIuC,GAAG;SAC1B;;MAGHrE,cAAc,CAAC2B,IAAI,CAACE,OAAO,CAAC,CAACI,cAAc,CAACC,GAAG,CAACP,IAAI,CAACK,EAAE,CAAC;;IAG1D5B,MAAM,EAAE;EACV,CAAC;EAED,MAAMkE,eAAe,GAAuClD,EAAE,IAAG;IAC/D/B,YAAY,GAAG+B,EAAE;EACnB,CAAC;EAED,MAAMmD,kBAAkB,GAA0C,MAAK;IACrElF,YAAY,GAAGQ,SAAS;EAC1B,CAAC;EAED,MAAM2E,UAAU,GAAkC9B,MAAM,IAAG;IACzD,IAAI,CAAC3C,aAAa,CAAC2C,MAAM,CAAC,EAAE;MAC1B;;IAGF,MAAMf,IAAI,GAAG5B,aAAa,CAAC2C,MAAM,CAAC;IAClCxB,gBAAgB,CAACuD,MAAM,CAAC/B,MAAM,CAAC;IAC/BrC,kBAAkB,CAACoE,MAAM,CAAC/B,MAAM,CAAC;IAEjC,IAAIf,IAAI,CAACE,OAAO,EAAE;MAChB7B,cAAc,CAAC2B,IAAI,CAACE,OAAO,CAAC,CAACI,cAAc,CAACF,MAAM,CAACJ,IAAI,CAACK,EAAE,CAAC;MAC3DhC,cAAc,CAAC2B,IAAI,CAACE,OAAO,CAAC,CAACC,gBAAgB,CAACC,MAAM,CAACJ,IAAI,CAACK,EAAE,CAAC;;IAG/D,OAAOjC,aAAa,CAAC2C,MAAM,CAAC;IAC5BtC,MAAM,EAAE;EACV,CAAC;EAED,OAAO;IACLgE,OAAO;IACPD,UAAU;IACVP,WAAW;IACXE,OAAO;IACPU,UAAU;IACVpE,MAAM;IACNkE,eAAe;IACfC;GACD;AACH;AApPAG","names":["createOverflowManager","container","overflowMenu","observing","options","padding","overflowAxis","overflowDirection","minimumVisible","onUpdateItemVisibility","undefined","onUpdateOverflow","overflowItems","overflowGroups","resizeObserver","ResizeObserver","entries","update","invisibleItemQueue","priorityQueue_1","a","b","itemA","itemB","priority","positionStatusBit","Node","DOCUMENT_POSITION_FOLLOWING","DOCUMENT_POSITION_PRECEDING","element","compareDocumentPosition","visibleItemQueue","getOffsetSize","el","offsetWidth","offsetHeight","makeItemVisible","nextVisible","dequeue","enqueue","item","visible","groupId","invisibleItemIds","delete","id","visibleItemIds","add","makeItemInvisible","nextInvisible","width","dispatchOverflowUpdate","all","visibleItems","map","itemId","invisibleItems","groupVisibility","Object","forEach","groupState","size","processOverflowItems","availableSize","overflowMenuOffset","visibleTop","peek","invisibleTop","currentWidth","reduce","sum","visibleItemId","child","forceUpdate","debounce_1","observe","observedContainer","userOptions","assign","values","disconnect","addItem","Set","addOverflowMenu","removeOverflowMenu","removeItem","remove","exports"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/overflowManager.ts"],"sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n let observing = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n\n // Remove items until there's no more overflow\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() <= options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // make sure the overflow menu can fit\n if (\n visibleItemQueue.size() > options.minimumVisible &&\n invisibleItemQueue.size() > 0 &&\n currentWidth + overflowMenuOffset > availableSize\n ) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"]}
@@ -8,103 +8,81 @@ exports.createPriorityQueue = void 0;
8
8
  * @param compare - comparison function for items
9
9
  * @returns Priority queue implemented with a min heap
10
10
  */
11
-
12
11
  function createPriorityQueue(compare) {
13
12
  const arr = [];
14
13
  let size = 0;
15
-
16
14
  const left = i => {
17
15
  return 2 * i + 1;
18
16
  };
19
-
20
17
  const right = i => {
21
18
  return 2 * i + 2;
22
19
  };
23
-
24
20
  const parent = i => {
25
21
  return Math.floor((i - 1) / 2);
26
22
  };
27
-
28
23
  const swap = (a, b) => {
29
24
  const tmp = arr[a];
30
25
  arr[a] = arr[b];
31
26
  arr[b] = tmp;
32
27
  };
33
-
34
28
  const heapify = i => {
35
29
  let smallest = i;
36
30
  const l = left(i);
37
31
  const r = right(i);
38
-
39
32
  if (l < size && compare(arr[l], arr[smallest]) < 0) {
40
33
  smallest = l;
41
34
  }
42
-
43
35
  if (r < size && compare(arr[r], arr[smallest]) < 0) {
44
36
  smallest = r;
45
37
  }
46
-
47
38
  if (smallest !== i) {
48
39
  swap(smallest, i);
49
40
  heapify(smallest);
50
41
  }
51
42
  };
52
-
53
43
  const dequeue = () => {
54
44
  if (size === 0) {
55
45
  throw new Error('Priority queue empty');
56
46
  }
57
-
58
47
  const res = arr[0];
59
48
  arr[0] = arr[--size];
60
49
  heapify(0);
61
50
  return res;
62
51
  };
63
-
64
52
  const peek = () => {
65
53
  if (size === 0) {
66
54
  return null;
67
55
  }
68
-
69
56
  return arr[0];
70
57
  };
71
-
72
58
  const enqueue = item => {
73
59
  arr[size++] = item;
74
60
  let i = size - 1;
75
61
  let p = parent(i);
76
-
77
62
  while (i > 0 && compare(arr[p], arr[i]) > 0) {
78
63
  swap(p, i);
79
64
  i = p;
80
65
  p = parent(i);
81
66
  }
82
67
  };
83
-
84
68
  const contains = item => {
85
69
  const index = arr.indexOf(item);
86
70
  return index >= 0 && index < size;
87
71
  };
88
-
89
72
  const remove = item => {
90
73
  const i = arr.indexOf(item);
91
-
92
74
  if (i === -1 || i >= size) {
93
75
  return;
94
76
  }
95
-
96
77
  arr[i] = arr[--size];
97
78
  heapify(i);
98
79
  };
99
-
100
80
  const clear = () => {
101
81
  size = 0;
102
82
  };
103
-
104
83
  const all = () => {
105
84
  return arr.slice(0, size);
106
85
  };
107
-
108
86
  return {
109
87
  all,
110
88
  clear,
@@ -116,6 +94,5 @@ function createPriorityQueue(compare) {
116
94
  size: () => size
117
95
  };
118
96
  }
119
-
120
97
  exports.createPriorityQueue = createPriorityQueue;
121
98
  //#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C,OAAJ,CAAY,IAAZ,CAAV;;IAEA,IAAI,CAAC,KAAK,CAAC,CAAP,IAAY,CAAC,IAAI,IAArB,EAA2B;MACzB;IACD;;IAED,GAAG,CAAC,CAAD,CAAH,GAAS,GAAG,CAAC,EAAE,IAAH,CAAZ;IACA,OAAO,CAAC,CAAD,CAAP;EACD,CATD;;EAWA,MAAM,KAAK,GAAG,MAAK;IACjB,IAAI,GAAG,CAAP;EACD,CAFD;;EAIA,MAAM,GAAG,GAAG,MAAK;IACf,OAAO,GAAG,CAAC,KAAJ,CAAU,CAAV,EAAa,IAAb,CAAP;EACD,CAFD;;EAIA,OAAO;IACL,GADK;IAEL,KAFK;IAGL,QAHK;IAIL,OAJK;IAKL,OALK;IAML,IANK;IAOL,MAPK;IAQL,IAAI,EAAE,MAAM;EARP,CAAP;AAUD;;AA1GD,OAAA,CAAA,mBAAA,GAAA,mBAAA","sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n const index = arr.indexOf(item);\n return index >= 0 && index < size;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1 || i >= size) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"mappings":";;;;;;AAaA;;;;AAIA,SAAgBA,mBAAmB,CAAIC,OAAkC;EACvE,MAAMC,GAAG,GAAQ,EAAE;EACnB,IAAIC,IAAI,GAAG,CAAC;EAEZ,MAAMC,IAAI,GAAIC,CAAS,IAAI;IACzB,OAAO,CAAC,GAAGA,CAAC,GAAG,CAAC;EAClB,CAAC;EAED,MAAMC,KAAK,GAAID,CAAS,IAAI;IAC1B,OAAO,CAAC,GAAGA,CAAC,GAAG,CAAC;EAClB,CAAC;EAED,MAAME,MAAM,GAAIF,CAAS,IAAI;IAC3B,OAAOG,IAAI,CAACC,KAAK,CAAC,CAACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;EAChC,CAAC;EAED,MAAMK,IAAI,GAAG,CAACC,CAAS,EAAEC,CAAS,KAAI;IACpC,MAAMC,GAAG,GAAGX,GAAG,CAACS,CAAC,CAAC;IAClBT,GAAG,CAACS,CAAC,CAAC,GAAGT,GAAG,CAACU,CAAC,CAAC;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AGF,IAAI,GAAG,CAAC;IAChB,IAAIqB,CAAC,GAAGjB,MAAM,CAACF,CAAC,CAAC;IACjB,OAAOA,CAAC,GAAG,CAAC,IAAIJ,OAAO,CAACC,GAAG,CAACsB,CAAC,CAAC,EAAEtB,GAAG,CAACG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;MAC3CK,IAAI,CAACc,CAAC,EAAEnB,CAAC,CAAC;MACVA,CAAC,GAAGmB,CAAC;MACLA,CAAC,GAAGjB,MAAM,CAACF,CAAC,CAAC;;EAEjB,CAAC;EAED,MAAMoB,QAAQ,GAAIF,IAAO,IAAI;IAC3B,MAAMG,KAAK,GAAGxB,GAAG,CAACyB,OAAO,CAACJ,IAAI,CAAC;IAC/B,OAAOG,KAAK,IAAI,CAAC,IAAIA,KAAK,GAAGvB,IAAI;EACnC,CAAC;EAED,MAAMyB,MAAM,GAAIL,IAAO,IAAI;IACzB,MAAMlB,CAAC,GAAGH,GAAG,CAACyB,OAAO,CAACJ,IAAI,CAAC;IAE3B,IAAIlB,CAAC,KAAK,CAAC,CAAC,IAAIA,CAAC,IAAIF,IAAI,EAAE;MACzB;;IAGFD,GAAG,CAACG,CAAC,CAAC,GAAGH,GAAG,CAAC,EAAEC,IAAI,CAAC;IACpBW,OAAO,CAACT,CAAC,CAAC;EACZ,CAAC;EAED,MAAMwB,KAAK,GAAG,MAAK;IACjB1B,IAAI,GAAG,CAAC;EACV,CAAC;EAED,MAAM2B,GAAG,GAAG,MAAK;IACf,OAAO5B,GAAG,CAAC6B,KAAK,CAAC,CAAC,EAAE5B,IAAI,CAAC;EAC3B,CAAC;EAED,OAAO;IACL2B,GAAG;IACHD,KAAK;IACLJ,QAAQ;IACRP,OAAO;IACPI,OAAO;IACPD,IAAI;IACJO,MAAM;IACNzB,IAAI,EAAE,MAAMA;GACb;AACH;AA1GA6B","names":["createPriorityQueue","compare","arr","size","left","i","right","parent","Math","floor","swap","a","b","tmp","heapify","smallest","l","r","dequeue","Error","res","peek","enqueue","item","p","contains","index","indexOf","remove","clear","all","slice","exports"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/priorityQueue.ts"],"sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n const index = arr.indexOf(item);\n return index >= 0 && index < size;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1 || i >= size) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
1
+ {"version":3,"mappings":"","names":[],"sourceRoot":"../src/","sources":[],"sourcesContent":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/priority-overflow",
3
- "version": "9.0.0-rc.1",
3
+ "version": "9.0.0-rc.2",
4
4
  "description": "Vanilla JS utilities to implement overflow menus",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "devDependencies": {
26
26
  "@fluentui/eslint-plugin": "*",
27
- "@fluentui/scripts": "^1.0.0"
27
+ "@fluentui/scripts": "*"
28
28
  },
29
29
  "dependencies": {
30
30
  "tslib": "^2.1.0"