@fluentui/priority-overflow 9.0.1 → 9.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,224 +1,222 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createOverflowManager", {
6
+ enumerable: true,
7
+ get: ()=>createOverflowManager
5
8
  });
6
- exports.createOverflowManager = void 0;
7
- const debounce_1 = /*#__PURE__*/require("./debounce");
8
- const priorityQueue_1 = /*#__PURE__*/require("./priorityQueue");
9
- /**
10
- * @internal
11
- * @returns overflow manager instance
12
- */
9
+ const _debounce = require("./debounce");
10
+ const _priorityQueue = require("./priorityQueue");
13
11
  function createOverflowManager() {
14
- let container;
15
- let overflowMenu;
16
- // Set as true when resize observer is observing
17
- let observing = false;
18
- // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change
19
- let forceDispatch = false;
20
- const options = {
21
- padding: 10,
22
- overflowAxis: 'horizontal',
23
- overflowDirection: 'end',
24
- minimumVisible: 0,
25
- onUpdateItemVisibility: () => undefined,
26
- onUpdateOverflow: () => undefined
27
- };
28
- const overflowItems = {};
29
- const overflowGroups = {};
30
- const resizeObserver = new ResizeObserver(entries => {
31
- if (!entries[0] || !container) {
32
- return;
33
- }
34
- update();
35
- });
36
- const invisibleItemQueue = priorityQueue_1.createPriorityQueue((a, b) => {
37
- const itemA = overflowItems[a];
38
- const itemB = overflowItems[b];
39
- // Higher priority at the top of the queue
40
- const priority = itemB.priority - itemA.priority;
41
- if (priority !== 0) {
42
- return priority;
43
- }
44
- const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
45
- // equal priority, use DOM order
46
- // eslint-disable-next-line no-bitwise
47
- return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
48
- });
49
- const visibleItemQueue = priorityQueue_1.createPriorityQueue((a, b) => {
50
- const itemA = overflowItems[a];
51
- const itemB = overflowItems[b];
52
- // Lower priority at the top of the queue
53
- const priority = itemA.priority - itemB.priority;
54
- if (priority !== 0) {
55
- return priority;
56
- }
57
- const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
58
- // equal priority, use DOM order
59
- // eslint-disable-next-line no-bitwise
60
- return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
61
- });
62
- const getOffsetSize = el => {
63
- return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;
64
- };
65
- const makeItemVisible = () => {
66
- const nextVisible = invisibleItemQueue.dequeue();
67
- visibleItemQueue.enqueue(nextVisible);
68
- const item = overflowItems[nextVisible];
69
- options.onUpdateItemVisibility({
70
- item,
71
- visible: true
12
+ let container;
13
+ let overflowMenu;
14
+ // Set as true when resize observer is observing
15
+ let observing = false;
16
+ // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change
17
+ let forceDispatch = false;
18
+ const options = {
19
+ padding: 10,
20
+ overflowAxis: 'horizontal',
21
+ overflowDirection: 'end',
22
+ minimumVisible: 0,
23
+ onUpdateItemVisibility: ()=>undefined,
24
+ onUpdateOverflow: ()=>undefined
25
+ };
26
+ const overflowItems = {};
27
+ const overflowGroups = {};
28
+ const resizeObserver = new ResizeObserver((entries)=>{
29
+ if (!entries[0] || !container) {
30
+ return;
31
+ }
32
+ update();
72
33
  });
73
- if (item.groupId) {
74
- overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
75
- overflowGroups[item.groupId].visibleItemIds.add(item.id);
76
- }
77
- return getOffsetSize(item.element);
78
- };
79
- const makeItemInvisible = () => {
80
- const nextInvisible = visibleItemQueue.dequeue();
81
- invisibleItemQueue.enqueue(nextInvisible);
82
- const item = overflowItems[nextInvisible];
83
- const width = getOffsetSize(item.element);
84
- options.onUpdateItemVisibility({
85
- item,
86
- visible: false
34
+ const invisibleItemQueue = (0, _priorityQueue.createPriorityQueue)((a, b)=>{
35
+ const itemA = overflowItems[a];
36
+ const itemB = overflowItems[b];
37
+ // Higher priority at the top of the queue
38
+ const priority = itemB.priority - itemA.priority;
39
+ if (priority !== 0) {
40
+ return priority;
41
+ }
42
+ const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
43
+ // equal priority, use DOM order
44
+ // eslint-disable-next-line no-bitwise
45
+ return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
87
46
  });
88
- if (item.groupId) {
89
- overflowGroups[item.groupId].visibleItemIds.delete(item.id);
90
- overflowGroups[item.groupId].invisibleItemIds.add(item.id);
91
- }
92
- return width;
93
- };
94
- const dispatchOverflowUpdate = () => {
95
- const visibleItemIds = visibleItemQueue.all();
96
- const invisibleItemIds = invisibleItemQueue.all();
97
- const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);
98
- const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);
99
- const groupVisibility = {};
100
- Object.entries(overflowGroups).forEach(([groupId, groupState]) => {
101
- if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {
102
- groupVisibility[groupId] = 'overflow';
103
- } else if (groupState.visibleItemIds.size === 0) {
104
- groupVisibility[groupId] = 'hidden';
105
- } else {
106
- groupVisibility[groupId] = 'visible';
107
- }
47
+ const visibleItemQueue = (0, _priorityQueue.createPriorityQueue)((a, b)=>{
48
+ const itemA = overflowItems[a];
49
+ const itemB = overflowItems[b];
50
+ // Lower priority at the top of the queue
51
+ const priority = itemA.priority - itemB.priority;
52
+ if (priority !== 0) {
53
+ return priority;
54
+ }
55
+ const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
56
+ // equal priority, use DOM order
57
+ // eslint-disable-next-line no-bitwise
58
+ return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
108
59
  });
109
- options.onUpdateOverflow({
110
- visibleItems,
111
- invisibleItems,
112
- groupVisibility
113
- });
114
- };
115
- const processOverflowItems = () => {
116
- if (!container) {
117
- return false;
118
- }
119
- const availableSize = getOffsetSize(container) - options.padding;
120
- const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
121
- // Snapshot of the visible/invisible state to compare for updates
122
- const visibleTop = visibleItemQueue.peek();
123
- const invisibleTop = invisibleItemQueue.peek();
124
- const visibleItemIds = visibleItemQueue.all();
125
- let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {
126
- const child = overflowItems[visibleItemId].element;
127
- return sum + getOffsetSize(child);
128
- }, 0);
129
- // Add items until available width is filled - can result in overflow
130
- while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {
131
- currentWidth += makeItemVisible();
132
- }
133
- // Remove items until there's no more overflow
134
- while (currentWidth > availableSize && visibleItemQueue.size() > 0) {
135
- if (visibleItemQueue.size() <= options.minimumVisible) {
136
- break;
137
- }
138
- currentWidth -= makeItemInvisible();
139
- }
140
- // make sure the overflow menu can fit
141
- if (visibleItemQueue.size() > options.minimumVisible && invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {
142
- makeItemInvisible();
143
- }
144
- // only update when the state of visible/invisible items has changed
145
- if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
146
- return true;
147
- }
148
- return false;
149
- };
150
- const forceUpdate = () => {
151
- if (processOverflowItems() || forceDispatch) {
152
- forceDispatch = false;
153
- dispatchOverflowUpdate();
154
- }
155
- };
156
- const update = debounce_1.debounce(forceUpdate);
157
- const observe = (observedContainer, userOptions) => {
158
- Object.assign(options, userOptions);
159
- observing = true;
160
- Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));
161
- container = observedContainer;
162
- resizeObserver.observe(container);
163
- };
164
- const disconnect = () => {
165
- observing = false;
166
- resizeObserver.disconnect();
167
- };
168
- const addItem = item => {
169
- if (overflowItems[item.id]) {
170
- return;
171
- }
172
- overflowItems[item.id] = item;
173
- // some options can affect priority which are only set on `observe`
174
- if (observing) {
175
- // Updates to elements might not change the queue tops
176
- // i.e. new element is enqueued but the top of the queue stays the same
177
- // force a dispatch on the next batched update
178
- forceDispatch = true;
179
- visibleItemQueue.enqueue(item.id);
180
- }
181
- if (item.groupId) {
182
- if (!overflowGroups[item.groupId]) {
183
- overflowGroups[item.groupId] = {
184
- visibleItemIds: new Set(),
185
- invisibleItemIds: new Set()
186
- };
187
- }
188
- overflowGroups[item.groupId].visibleItemIds.add(item.id);
189
- }
190
- update();
191
- };
192
- const addOverflowMenu = el => {
193
- overflowMenu = el;
194
- };
195
- const removeOverflowMenu = () => {
196
- overflowMenu = undefined;
197
- };
198
- const removeItem = itemId => {
199
- if (!overflowItems[itemId]) {
200
- return;
201
- }
202
- const item = overflowItems[itemId];
203
- visibleItemQueue.remove(itemId);
204
- invisibleItemQueue.remove(itemId);
205
- if (item.groupId) {
206
- overflowGroups[item.groupId].visibleItemIds.delete(item.id);
207
- overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
208
- }
209
- delete overflowItems[itemId];
210
- update();
211
- };
212
- return {
213
- addItem,
214
- disconnect,
215
- forceUpdate,
216
- observe,
217
- removeItem,
218
- update,
219
- addOverflowMenu,
220
- removeOverflowMenu
221
- };
222
- }
223
- exports.createOverflowManager = createOverflowManager;
60
+ const getOffsetSize = (el)=>{
61
+ return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;
62
+ };
63
+ const makeItemVisible = ()=>{
64
+ const nextVisible = invisibleItemQueue.dequeue();
65
+ visibleItemQueue.enqueue(nextVisible);
66
+ const item = overflowItems[nextVisible];
67
+ options.onUpdateItemVisibility({
68
+ item,
69
+ visible: true
70
+ });
71
+ if (item.groupId) {
72
+ overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
73
+ overflowGroups[item.groupId].visibleItemIds.add(item.id);
74
+ }
75
+ return getOffsetSize(item.element);
76
+ };
77
+ const makeItemInvisible = ()=>{
78
+ const nextInvisible = visibleItemQueue.dequeue();
79
+ invisibleItemQueue.enqueue(nextInvisible);
80
+ const item = overflowItems[nextInvisible];
81
+ const width = getOffsetSize(item.element);
82
+ options.onUpdateItemVisibility({
83
+ item,
84
+ visible: false
85
+ });
86
+ if (item.groupId) {
87
+ overflowGroups[item.groupId].visibleItemIds.delete(item.id);
88
+ overflowGroups[item.groupId].invisibleItemIds.add(item.id);
89
+ }
90
+ return width;
91
+ };
92
+ const dispatchOverflowUpdate = ()=>{
93
+ const visibleItemIds = visibleItemQueue.all();
94
+ const invisibleItemIds = invisibleItemQueue.all();
95
+ const visibleItems = visibleItemIds.map((itemId)=>overflowItems[itemId]);
96
+ const invisibleItems = invisibleItemIds.map((itemId)=>overflowItems[itemId]);
97
+ const groupVisibility = {};
98
+ Object.entries(overflowGroups).forEach(([groupId, groupState])=>{
99
+ if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {
100
+ groupVisibility[groupId] = 'overflow';
101
+ } else if (groupState.visibleItemIds.size === 0) {
102
+ groupVisibility[groupId] = 'hidden';
103
+ } else {
104
+ groupVisibility[groupId] = 'visible';
105
+ }
106
+ });
107
+ options.onUpdateOverflow({
108
+ visibleItems,
109
+ invisibleItems,
110
+ groupVisibility
111
+ });
112
+ };
113
+ const processOverflowItems = ()=>{
114
+ if (!container) {
115
+ return false;
116
+ }
117
+ const availableSize = getOffsetSize(container) - options.padding;
118
+ const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
119
+ // Snapshot of the visible/invisible state to compare for updates
120
+ const visibleTop = visibleItemQueue.peek();
121
+ const invisibleTop = invisibleItemQueue.peek();
122
+ const visibleItemIds = visibleItemQueue.all();
123
+ let currentWidth = visibleItemIds.reduce((sum, visibleItemId)=>{
124
+ const child = overflowItems[visibleItemId].element;
125
+ return sum + getOffsetSize(child);
126
+ }, 0);
127
+ // Add items until available width is filled - can result in overflow
128
+ while(currentWidth < availableSize && invisibleItemQueue.size() > 0){
129
+ currentWidth += makeItemVisible();
130
+ }
131
+ // Remove items until there's no more overflow
132
+ while(currentWidth > availableSize && visibleItemQueue.size() > 0){
133
+ if (visibleItemQueue.size() <= options.minimumVisible) {
134
+ break;
135
+ }
136
+ currentWidth -= makeItemInvisible();
137
+ }
138
+ // make sure the overflow menu can fit
139
+ if (visibleItemQueue.size() > options.minimumVisible && invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {
140
+ makeItemInvisible();
141
+ }
142
+ // only update when the state of visible/invisible items has changed
143
+ if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
144
+ return true;
145
+ }
146
+ return false;
147
+ };
148
+ const forceUpdate = ()=>{
149
+ if (processOverflowItems() || forceDispatch) {
150
+ forceDispatch = false;
151
+ dispatchOverflowUpdate();
152
+ }
153
+ };
154
+ const update = (0, _debounce.debounce)(forceUpdate);
155
+ const observe = (observedContainer, userOptions)=>{
156
+ Object.assign(options, userOptions);
157
+ observing = true;
158
+ Object.values(overflowItems).forEach((item)=>visibleItemQueue.enqueue(item.id));
159
+ container = observedContainer;
160
+ resizeObserver.observe(container);
161
+ };
162
+ const disconnect = ()=>{
163
+ observing = false;
164
+ resizeObserver.disconnect();
165
+ };
166
+ const addItem = (item)=>{
167
+ if (overflowItems[item.id]) {
168
+ return;
169
+ }
170
+ overflowItems[item.id] = item;
171
+ // some options can affect priority which are only set on `observe`
172
+ if (observing) {
173
+ // Updates to elements might not change the queue tops
174
+ // i.e. new element is enqueued but the top of the queue stays the same
175
+ // force a dispatch on the next batched update
176
+ forceDispatch = true;
177
+ visibleItemQueue.enqueue(item.id);
178
+ }
179
+ if (item.groupId) {
180
+ if (!overflowGroups[item.groupId]) {
181
+ overflowGroups[item.groupId] = {
182
+ visibleItemIds: new Set(),
183
+ invisibleItemIds: new Set()
184
+ };
185
+ }
186
+ overflowGroups[item.groupId].visibleItemIds.add(item.id);
187
+ }
188
+ update();
189
+ };
190
+ const addOverflowMenu = (el)=>{
191
+ overflowMenu = el;
192
+ };
193
+ const removeOverflowMenu = ()=>{
194
+ overflowMenu = undefined;
195
+ };
196
+ const removeItem = (itemId)=>{
197
+ if (!overflowItems[itemId]) {
198
+ return;
199
+ }
200
+ const item = overflowItems[itemId];
201
+ visibleItemQueue.remove(itemId);
202
+ invisibleItemQueue.remove(itemId);
203
+ if (item.groupId) {
204
+ overflowGroups[item.groupId].visibleItemIds.delete(item.id);
205
+ overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
206
+ }
207
+ delete overflowItems[itemId];
208
+ update();
209
+ };
210
+ return {
211
+ addItem,
212
+ disconnect,
213
+ forceUpdate,
214
+ observe,
215
+ removeItem,
216
+ update,
217
+ addOverflowMenu,
218
+ removeOverflowMenu
219
+ };
220
+ } //# sourceMappingURL=overflowManager.js.map
221
+
224
222
  //# sourceMappingURL=overflowManager.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;AAAA;AACA;AAGA;;;;AAIA,SAAgBA,qBAAqB;EACnC,IAAIC,SAAkC;EACtC,IAAIC,YAAqC;EACzC;EACA,IAAIC,SAAS,GAAG,KAAK;EACrB;EACA,IAAIC,aAAa,GAAG,KAAK;EACzB,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,CAAChB,SAAS,EAAE;MAC7B;;IAGFiB,MAAM,EAAE;EACV,CAAC,CAAC;EAEF,MAAMC,kBAAkB,GAAGC,mCAAmB,CAAS,CAACC,CAAC,EAA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IAC/DhC,YAAY,GAAGgC,EAAE;EACnB,CAAC;EAED,MAAMmD,kBAAkB,GAA0C,MAAK;IACrEnF,YAAY,GAAGS,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;AA5PAG","names":["createOverflowManager","container","overflowMenu","observing","forceDispatch","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 // Set as true when resize observer is observing\n let observing = false;\n // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change\n let forceDispatch = 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 = (): boolean => {\n if (!container) {\n return false;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\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 return true;\n }\n\n return false;\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (processOverflowItems() || forceDispatch) {\n forceDispatch = false;\n dispatchOverflowUpdate();\n }\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 // Updates to elements might not change the queue tops\n // i.e. new element is enqueued but the top of the queue stays the same\n // force a dispatch on the next batched update\n forceDispatch = true;\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"]}
1
+ {"version":3,"sources":["../lib/overflowManager.js"],"sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager() {\n let container;\n let overflowMenu;\n // Set as true when resize observer is observing\n let observing = false;\n // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change\n let forceDispatch = false;\n const options = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined\n };\n const overflowItems = {};\n const overflowGroups = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n update();\n });\n const invisibleItemQueue = createPriorityQueue((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 const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\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 const visibleItemQueue = createPriorityQueue((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 if (priority !== 0) {\n return priority;\n }\n const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\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 const getOffsetSize = el => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({\n item,\n visible: true\n });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n return getOffsetSize(item.element);\n };\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({\n item,\n visible: false\n });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n return width;\n };\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n const groupVisibility = {};\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 options.onUpdateOverflow({\n visibleItems,\n invisibleItems,\n groupVisibility\n });\n };\n const processOverflowItems = () => {\n if (!container) {\n return false;\n }\n const availableSize = getOffsetSize(container) - options.padding;\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\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 // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\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 // make sure the overflow menu can fit\n if (visibleItemQueue.size() > options.minimumVisible && invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {\n makeItemInvisible();\n }\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n return true;\n }\n return false;\n };\n const forceUpdate = () => {\n if (processOverflowItems() || forceDispatch) {\n forceDispatch = false;\n dispatchOverflowUpdate();\n }\n };\n const update = debounce(forceUpdate);\n const observe = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n container = observedContainer;\n resizeObserver.observe(container);\n };\n const disconnect = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n const addItem = item => {\n if (overflowItems[item.id]) {\n return;\n }\n overflowItems[item.id] = item;\n // some options can affect priority which are only set on `observe`\n if (observing) {\n // Updates to elements might not change the queue tops\n // i.e. new element is enqueued but the top of the queue stays the same\n // force a dispatch on the next batched update\n forceDispatch = true;\n visibleItemQueue.enqueue(item.id);\n }\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set(),\n invisibleItemIds: new Set()\n };\n }\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n update();\n };\n const addOverflowMenu = el => {\n overflowMenu = el;\n };\n const removeOverflowMenu = () => {\n overflowMenu = undefined;\n };\n const removeItem = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n delete overflowItems[itemId];\n update();\n };\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu\n };\n}\n//# sourceMappingURL=overflowManager.js.map"],"names":["createOverflowManager","container","overflowMenu","observing","forceDispatch","options","padding","overflowAxis","overflowDirection","minimumVisible","onUpdateItemVisibility","undefined","onUpdateOverflow","overflowItems","overflowGroups","resizeObserver","ResizeObserver","entries","update","invisibleItemQueue","createPriorityQueue","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","observe","observedContainer","userOptions","assign","values","disconnect","addItem","Set","addOverflowMenu","removeOverflowMenu","removeItem","remove"],"mappings":";;;;+BAMgBA;;aAAAA;;0BANS;+BACW;AAK7B,SAASA,wBAAwB;IACtC,IAAIC;IACJ,IAAIC;IACJ,gDAAgD;IAChD,IAAIC,YAAY,KAAK;IACrB,+FAA+F;IAC/F,IAAIC,gBAAgB,KAAK;IACzB,MAAMC,UAAU;QACdC,SAAS;QACTC,cAAc;QACdC,mBAAmB;QACnBC,gBAAgB;QAChBC,wBAAwB,IAAMC;QAC9BC,kBAAkB,IAAMD;IAC1B;IACA,MAAME,gBAAgB,CAAC;IACvB,MAAMC,iBAAiB,CAAC;IACxB,MAAMC,iBAAiB,IAAIC,eAAeC,CAAAA,UAAW;QACnD,IAAI,CAACA,OAAO,CAAC,EAAE,IAAI,CAAChB,WAAW;YAC7B;QACF,CAAC;QACDiB;IACF;IACA,MAAMC,qBAAqBC,IAAAA,kCAAmB,EAAC,CAACC,GAAGC,IAAM;QACvD,MAAMC,QAAQV,aAAa,CAACQ,EAAE;QAC9B,MAAMG,QAAQX,aAAa,CAACS,EAAE;QAC9B,0CAA0C;QAC1C,MAAMG,WAAWD,MAAMC,QAAQ,GAAGF,MAAME,QAAQ;QAChD,IAAIA,aAAa,GAAG;YAClB,OAAOA;QACT,CAAC;QACD,MAAMC,oBAAoBrB,QAAQG,iBAAiB,KAAK,QAAQmB,KAAKC,2BAA2B,GAAGD,KAAKE,2BAA2B;QACnI,gCAAgC;QAChC,sCAAsC;QACtC,OAAON,MAAMO,OAAO,CAACC,uBAAuB,CAACP,MAAMM,OAAO,IAAIJ,oBAAoB,CAAC,IAAI,CAAC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