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

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.json CHANGED
@@ -2,7 +2,73 @@
2
2
  "name": "@fluentui/priority-overflow",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 17 Nov 2022 23:02:29 GMT",
5
+ "date": "Wed, 18 Jan 2023 16:30:55 GMT",
6
+ "tag": "@fluentui/priority-overflow_v9.0.0",
7
+ "version": "9.0.0",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "author": "lingfangao@hotmail.com",
12
+ "package": "@fluentui/priority-overflow",
13
+ "commit": "e59f114d3244739a7917813ea02c59d53406d902",
14
+ "comment": "Release as stable"
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Mon, 16 Jan 2023 08:38:54 GMT",
21
+ "tag": "@fluentui/priority-overflow_v9.0.0-rc.2",
22
+ "version": "9.0.0-rc.2",
23
+ "comments": {
24
+ "none": [
25
+ {
26
+ "author": "martinhochel@microsoft.com",
27
+ "package": "@fluentui/priority-overflow",
28
+ "commit": "64bb45980d68de1219c6b36a7db5363f0a9cff9f",
29
+ "comment": "chore: migrate to packaged scripts"
30
+ }
31
+ ]
32
+ }
33
+ },
34
+ {
35
+ "date": "Mon, 09 Jan 2023 14:34:54 GMT",
36
+ "tag": "@fluentui/priority-overflow_v9.0.0-rc.2",
37
+ "version": "9.0.0-rc.2",
38
+ "comments": {
39
+ "prerelease": [
40
+ {
41
+ "author": "lingfangao@hotmail.com",
42
+ "package": "@fluentui/priority-overflow",
43
+ "commit": "2611ae5441e4bc702c4ce6404c7186f6c2de7cc3",
44
+ "comment": "fix: Minimum visible overflow items should be respected"
45
+ }
46
+ ]
47
+ }
48
+ },
49
+ {
50
+ "date": "Wed, 04 Jan 2023 01:40:47 GMT",
51
+ "tag": "@fluentui/priority-overflow_v9.0.0-rc.1",
52
+ "version": "9.0.0-rc.1",
53
+ "comments": {
54
+ "none": [
55
+ {
56
+ "author": "martinhochel@microsoft.com",
57
+ "package": "@fluentui/priority-overflow",
58
+ "commit": "4ec2b998b294d6d9c3196d3d82893bdd97d0c105",
59
+ "comment": "chore(scripts): move index.ts to to follow sub-folder domain packaging"
60
+ },
61
+ {
62
+ "author": "martinhochel@microsoft.com",
63
+ "package": "@fluentui/priority-overflow",
64
+ "commit": "194b0cf0cc27c1c1233aa945f09b3ad29778d8ca",
65
+ "comment": "chore(scripts): use for @fluentui/scripts version within all package.json"
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ {
71
+ "date": "Thu, 17 Nov 2022 23:05:32 GMT",
6
72
  "tag": "@fluentui/priority-overflow_v9.0.0-rc.1",
7
73
  "version": "9.0.0-rc.1",
8
74
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,30 @@
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 Wed, 18 Jan 2023 16:30:55 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## [9.0.0](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v9.0.0)
8
+
9
+ Wed, 18 Jan 2023 16:30:55 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.0-rc.2..@fluentui/priority-overflow_v9.0.0)
11
+
12
+ ### Patches
13
+
14
+ - Release as stable ([PR #26380](https://github.com/microsoft/fluentui/pull/26380) by lingfangao@hotmail.com)
15
+
16
+ ## [9.0.0-rc.2](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v9.0.0-rc.2)
17
+
18
+ Mon, 09 Jan 2023 14:34:54 GMT
19
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.0-rc.1..@fluentui/priority-overflow_v9.0.0-rc.2)
20
+
21
+ ### Changes
22
+
23
+ - fix: Minimum visible overflow items should be respected ([PR #26194](https://github.com/microsoft/fluentui/pull/26194) by lingfangao@hotmail.com)
24
+
7
25
  ## [9.0.0-rc.1](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v9.0.0-rc.1)
8
26
 
9
- Thu, 17 Nov 2022 23:02:29 GMT
27
+ Thu, 17 Nov 2022 23:05:32 GMT
10
28
  [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
29
 
12
30
  ### 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"],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,EAAmC;QACjC,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,GAA+B;UAC7B,cAAc,EAAE,IAAI,GAAJ,EADa;UAE7B,gBAAgB,EAAE,IAAI,GAAJ;QAFW,CAA/B;MAID;;MAED,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,cAA7B,CAA4C,GAA5C,CAAgD,IAAI,CAAC,EAArD;IACD;;IAED,MAAM;EACP,CAxBD;;EA0BA,MAAM,eAAe,GAAuC,EAAE,IAAG;IAC/D,YAAY,GAAG,EAAf;EACD,CAFD;;EAIA,MAAM,kBAAkB,GAA0C,MAAK;IACrE,YAAY,GAAG,SAAf;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","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,KAAK,GAAGT,aAAa,CAACO,CAAC,CAAC;IAC9B,MAAMG,KAAK,GAAGV,aAAa,CAACQ,CAAC,CAAC;IAC9B;IACA,MAAMG,QAAQ,GAAGD,KAAK,CAACC,QAAQ,GAAGF,KAAK,CAACE,QAAQ;IAChD,IAAIA,QAAQ,KAAK,CAAC,EAAE;MAClB,OAAOA,QAAQ;;IAGjB,MAAMC,iBAAiB,GACrBpB,OAAO,CAACG,iBAAiB,KAAK,KAAK,GAAGkB,IAAI,CAACC,2BAA2B,GAAGD,IAAI,CAACE,2BAA2B;IAE3G;IACA;IACA,OAAON,KAA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AM,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,GAAS,GAAG,CAAC,CAAD,CAAZ;IACA,GAAG,CAAC,CAAD,CAAH,GAAS,GAAT;EACD,CAJD;;EAMA,MAAM,OAAO,GAAI,CAAD,IAAc;IAC5B,IAAI,QAAQ,GAAG,CAAf;IACA,MAAM,CAAC,GAAG,IAAI,CAAC,CAAD,CAAd;IACA,MAAM,CAAC,GAAG,KAAK,CAAC,CAAD,CAAf;;IAEA,IAAI,CAAC,GAAG,IAAJ,IAAY,OAAO,CAAC,GAAG,CAAC,CAAD,CAAJ,EAAS,GAAG,CAAC,QAAD,CAAZ,CAAP,GAAiC,CAAjD,EA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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,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,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I;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"]}
@@ -0,0 +1,27 @@
1
+ define(["require", "exports"], function (require, exports) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.debounce = void 0;
5
+ /**
6
+ * Microtask debouncer
7
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide
8
+ * @param fn - Function to debounce
9
+ * @returns debounced function
10
+ */
11
+ function debounce(fn) {
12
+ var pending;
13
+ return function () {
14
+ if (!pending) {
15
+ pending = true;
16
+ queueMicrotask(function () {
17
+ // Need to set pending to `false` before the debounced function is run.
18
+ // React can actually interrupt the function while it's running!
19
+ pending = false;
20
+ fn();
21
+ });
22
+ }
23
+ };
24
+ }
25
+ exports.debounce = debounce;
26
+ });
27
+ //# sourceMappingURL=debounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/debounce.ts"],"names":[],"mappings":";;;;IAAA;;;;;OAKG;IACH,SAAgB,QAAQ,CAAC,EAAY;QACnC,IAAI,OAAgB,CAAC;QACrB,OAAO;YACL,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,GAAG,IAAI,CAAC;gBACf,cAAc,CAAC;oBACb,uEAAuE;oBACvE,gEAAgE;oBAChE,OAAO,GAAG,KAAK,CAAC;oBAChB,EAAE,EAAE,CAAC;gBACP,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC;IACJ,CAAC;IAbD,4BAaC","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"]}
@@ -0,0 +1,7 @@
1
+ define(["require", "exports", "./overflowManager"], function (require, exports, overflowManager_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.createOverflowManager = void 0;
5
+ Object.defineProperty(exports, "createOverflowManager", { enumerable: true, get: function () { return overflowManager_1.createOverflowManager; } });
6
+ });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/index.ts"],"names":[],"mappings":";;;;IAAS,wHAAA,qBAAqB,OAAA","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"]}