@fluentui/priority-overflow 9.0.0 → 9.0.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +16 -1
- package/CHANGELOG.md +11 -2
- package/lib/overflowManager.js +15 -7
- package/lib/overflowManager.js.map +1 -1
- package/lib-amd/overflowManager.js +15 -7
- package/lib-amd/overflowManager.js.map +1 -1
- package/lib-commonjs/overflowManager.js +15 -7
- package/lib-commonjs/overflowManager.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.json
CHANGED
@@ -2,7 +2,22 @@
|
|
2
2
|
"name": "@fluentui/priority-overflow",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
5
|
+
"date": "Tue, 07 Feb 2023 14:10:45 GMT",
|
6
|
+
"tag": "@fluentui/priority-overflow_v9.0.1",
|
7
|
+
"version": "9.0.1",
|
8
|
+
"comments": {
|
9
|
+
"patch": [
|
10
|
+
{
|
11
|
+
"author": "lingfangao@hotmail.com",
|
12
|
+
"package": "@fluentui/priority-overflow",
|
13
|
+
"commit": "7274228423cc06749b72ab6a8a112db6f18f5378",
|
14
|
+
"comment": "fix: New overflow items all always dispatch updates to subscriber"
|
15
|
+
}
|
16
|
+
]
|
17
|
+
}
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"date": "Wed, 18 Jan 2023 16:32:53 GMT",
|
6
21
|
"tag": "@fluentui/priority-overflow_v9.0.0",
|
7
22
|
"version": "9.0.0",
|
8
23
|
"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
|
3
|
+
This log was last generated on Tue, 07 Feb 2023 14:10:45 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.0.1](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v9.0.1)
|
8
|
+
|
9
|
+
Tue, 07 Feb 2023 14:10:45 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.0..@fluentui/priority-overflow_v9.0.1)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- fix: New overflow items all always dispatch updates to subscriber ([PR #26565](https://github.com/microsoft/fluentui/pull/26565) by lingfangao@hotmail.com)
|
15
|
+
|
7
16
|
## [9.0.0](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v9.0.0)
|
8
17
|
|
9
|
-
Wed, 18 Jan 2023 16:
|
18
|
+
Wed, 18 Jan 2023 16:32:53 GMT
|
10
19
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.0-rc.2..@fluentui/priority-overflow_v9.0.0)
|
11
20
|
|
12
21
|
### Patches
|
package/lib/overflowManager.js
CHANGED
@@ -7,7 +7,10 @@ import { createPriorityQueue } from './priorityQueue';
|
|
7
7
|
export function createOverflowManager() {
|
8
8
|
let container;
|
9
9
|
let overflowMenu;
|
10
|
+
// Set as true when resize observer is observing
|
10
11
|
let observing = false;
|
12
|
+
// If true, next update will dispatch to onUpdateOverflow even if queue top states don't change
|
13
|
+
let forceDispatch = false;
|
11
14
|
const options = {
|
12
15
|
padding: 10,
|
13
16
|
overflowAxis: 'horizontal',
|
@@ -103,10 +106,11 @@ export function createOverflowManager() {
|
|
103
106
|
groupVisibility
|
104
107
|
});
|
105
108
|
};
|
106
|
-
const processOverflowItems =
|
109
|
+
const processOverflowItems = () => {
|
107
110
|
if (!container) {
|
108
|
-
return;
|
111
|
+
return false;
|
109
112
|
}
|
113
|
+
const availableSize = getOffsetSize(container) - options.padding;
|
110
114
|
const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
|
111
115
|
// Snapshot of the visible/invisible state to compare for updates
|
112
116
|
const visibleTop = visibleItemQueue.peek();
|
@@ -133,15 +137,15 @@ export function createOverflowManager() {
|
|
133
137
|
}
|
134
138
|
// only update when the state of visible/invisible items has changed
|
135
139
|
if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
|
136
|
-
|
140
|
+
return true;
|
137
141
|
}
|
142
|
+
return false;
|
138
143
|
};
|
139
144
|
const forceUpdate = () => {
|
140
|
-
if (
|
141
|
-
|
145
|
+
if (processOverflowItems() || forceDispatch) {
|
146
|
+
forceDispatch = false;
|
147
|
+
dispatchOverflowUpdate();
|
142
148
|
}
|
143
|
-
const availableSize = getOffsetSize(container) - options.padding;
|
144
|
-
processOverflowItems(availableSize);
|
145
149
|
};
|
146
150
|
const update = debounce(forceUpdate);
|
147
151
|
const observe = (observedContainer, userOptions) => {
|
@@ -162,6 +166,10 @@ export function createOverflowManager() {
|
|
162
166
|
overflowItems[item.id] = item;
|
163
167
|
// some options can affect priority which are only set on `observe`
|
164
168
|
if (observing) {
|
169
|
+
// Updates to elements might not change the queue tops
|
170
|
+
// i.e. new element is enqueued but the top of the queue stays the same
|
171
|
+
// force a dispatch on the next batched update
|
172
|
+
forceDispatch = true;
|
165
173
|
visibleItemQueue.enqueue(item.id);
|
166
174
|
}
|
167
175
|
if (item.groupId) {
|
@@ -1 +1 @@
|
|
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,IAA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EAAE,CAAC;;IAG1D3B,MAAM,EAAE;EACV,CAAC;EAED,MAAMgE,eAAe,GAAuCjD,EAAE,IAAG;IAC/D9B,YAAY,GAAG8B,EAAE;EACnB,CAAC;EAED,MAAMkD,kBAAkB,GAA0C,MAAK;IACrEhF,YAAY,GAAGQ,SAAS;EAC1B,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"]}
|
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;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,OA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AG;SAC1B;;MAGHnE,cAAc,CAAC0B,IAAI,CAACE,OAAO,CAAC,CAACI,cAAc,CAACC,GAAG,CAACP,IAAI,CAACK,EAAE,CAAC;;IAG1D3B,MAAM,EAAE;EACV,CAAC;EAED,MAAMgE,eAAe,GAAuCjD,EAAE,IAAG;IAC/D/B,YAAY,GAAG+B,EAAE;EACnB,CAAC;EAED,MAAMkD,kBAAkB,GAA0C,MAAK;IACrEjF,YAAY,GAAGS,SAAS;EAC1B,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","forceDispatch","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 // 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"]}
|
@@ -9,7 +9,10 @@ define(["require", "exports", "./debounce", "./priorityQueue"], function (requir
|
|
9
9
|
function createOverflowManager() {
|
10
10
|
var container;
|
11
11
|
var overflowMenu;
|
12
|
+
// Set as true when resize observer is observing
|
12
13
|
var observing = false;
|
14
|
+
// If true, next update will dispatch to onUpdateOverflow even if queue top states don't change
|
15
|
+
var forceDispatch = false;
|
13
16
|
var options = {
|
14
17
|
padding: 10,
|
15
18
|
overflowAxis: 'horizontal',
|
@@ -98,10 +101,11 @@ define(["require", "exports", "./debounce", "./priorityQueue"], function (requir
|
|
98
101
|
});
|
99
102
|
options.onUpdateOverflow({ visibleItems: visibleItems, invisibleItems: invisibleItems, groupVisibility: groupVisibility });
|
100
103
|
};
|
101
|
-
var processOverflowItems = function (
|
104
|
+
var processOverflowItems = function () {
|
102
105
|
if (!container) {
|
103
|
-
return;
|
106
|
+
return false;
|
104
107
|
}
|
108
|
+
var availableSize = getOffsetSize(container) - options.padding;
|
105
109
|
var overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
|
106
110
|
// Snapshot of the visible/invisible state to compare for updates
|
107
111
|
var visibleTop = visibleItemQueue.peek();
|
@@ -130,15 +134,15 @@ define(["require", "exports", "./debounce", "./priorityQueue"], function (requir
|
|
130
134
|
}
|
131
135
|
// only update when the state of visible/invisible items has changed
|
132
136
|
if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
|
133
|
-
|
137
|
+
return true;
|
134
138
|
}
|
139
|
+
return false;
|
135
140
|
};
|
136
141
|
var forceUpdate = function () {
|
137
|
-
if (
|
138
|
-
|
142
|
+
if (processOverflowItems() || forceDispatch) {
|
143
|
+
forceDispatch = false;
|
144
|
+
dispatchOverflowUpdate();
|
139
145
|
}
|
140
|
-
var availableSize = getOffsetSize(container) - options.padding;
|
141
|
-
processOverflowItems(availableSize);
|
142
146
|
};
|
143
147
|
var update = debounce_1.debounce(forceUpdate);
|
144
148
|
var observe = function (observedContainer, userOptions) {
|
@@ -159,6 +163,10 @@ define(["require", "exports", "./debounce", "./priorityQueue"], function (requir
|
|
159
163
|
overflowItems[item.id] = item;
|
160
164
|
// some options can affect priority which are only set on `observe`
|
161
165
|
if (observing) {
|
166
|
+
// Updates to elements might not change the queue tops
|
167
|
+
// i.e. new element is enqueued but the top of the queue stays the same
|
168
|
+
// force a dispatch on the next batched update
|
169
|
+
forceDispatch = true;
|
162
170
|
visibleItemQueue.enqueue(item.id);
|
163
171
|
}
|
164
172
|
if (item.groupId) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"overflowManager.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/overflowManager.ts"],"names":[],"mappings":";;;;IAIA;;;OAGG;IACH,SAAgB,qBAAqB;QACnC,IAAI,SAAkC,CAAC;QACvC,IAAI,YAAqC,CAAC;QAC1C,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,IAAM,OAAO,GAA6B;YACxC,OAAO,EAAE,EAAE;YACX,YAAY,EAAE,YAAY;YAC1B,iBAAiB,EAAE,KAAK;YACxB,cAAc,EAAE,CAAC;YACjB,sBAAsB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;YACvC,gBAAgB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;SAClC,CAAC;QAEF,IAAM,aAAa,GAAsC,EAAE,CAAC;QAC5D,IAAM,cAAc,GAAmF,EAAE,CAAC;QAC1G,IAAM,cAAc,GAAG,IAAI,cAAc,CAAC,UAAA,OAAO;YAC/C,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE;gBAC7B,OAAO;aACR;YAED,MAAM,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;QAEH,IAAM,kBAAkB,GAAG,mCAAmB,CAAS,UAAC,CAAC,EAAE,CAAC;YAC1D,IAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YAC/B,0CAA0C;YAC1C,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YACjD,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,QAAQ,CAAC;aACjB;YAED,IAAM,iBAAiB,GACrB,OAAO,CAAC,iBAAiB,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,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QAEF,IAAM,eAAe,GAAuC,UAAA,EAAE;YAC5D,YAAY,GAAG,EAAE,CAAC;QACpB,CAAC,CAAC;QAEF,IAAM,kBAAkB,GAA0C;YAChE,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC,CAAC;QAEF,IAAM,UAAU,GAAkC,UAAA,MAAM;YACtD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE;gBAC1B,OAAO;aACR;YAED,IAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;YACnC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAChC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAElC,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC5D,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aAC/D;YAED,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;YAC7B,MAAM,EAAE,CAAC;QACX,CAAC,CAAC;QAEF,OAAO;YACL,OAAO,SAAA;YACP,UAAU,YAAA;YACV,WAAW,aAAA;YACX,OAAO,SAAA;YACP,UAAU,YAAA;YACV,MAAM,QAAA;YACN,eAAe,iBAAA;YACf,kBAAkB,oBAAA;SACnB,CAAC;IACJ,CAAC;IApPD,sDAoPC","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"]}
|
1
|
+
{"version":3,"file":"overflowManager.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/overflowManager.ts"],"names":[],"mappings":";;;;IAIA;;;OAGG;IACH,SAAgB,qBAAqB;QACnC,IAAI,SAAkC,CAAC;QACvC,IAAI,YAAqC,CAAC;QAC1C,gDAAgD;QAChD,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,+FAA+F;QAC/F,IAAI,aAAa,GAAG,KAAK,CAAC;QAC1B,IAAM,OAAO,GAA6B;YACxC,OAAO,EAAE,EAAE;YACX,YAAY,EAAE,YAAY;YAC1B,iBAAiB,EAAE,KAAK;YACxB,cAAc,EAAE,CAAC;YACjB,sBAAsB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;YACvC,gBAAgB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;SAClC,CAAC;QAEF,IAAM,aAAa,GAAsC,EAAE,CAAC;QAC5D,IAAM,cAAc,GAAmF,EAAE,CAAC;QAC1G,IAAM,cAAc,GAAG,IAAI,cAAc,CAAC,UAAA,OAAO;YAC/C,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE;gBAC7B,OAAO;aACR;YAED,MAAM,EAAE,CAAC;QACX,CAAC,CAAC,CAAC;QAEH,IAAM,kBAAkB,GAAG,mCAAmB,CAAS,UAAC,CAAC,EAAE,CAAC;YAC1D,IAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAM,KAAK,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YAC/B,0CAA0C;YAC1C,IAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YACjD,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,QAAQ,CAAC;aACjB;YAED,IAAM,iBAAiB,GACrB,OA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AAgB,EAAE,IAAI,GAAG,EAAU;qBACpC,CAAC;iBACH;gBAED,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aAC1D;YAED,MAAM,EAAE,CAAC;QACX,CAAC,CAAC;QAEF,IAAM,eAAe,GAAuC,UAAA,EAAE;YAC5D,YAAY,GAAG,EAAE,CAAC;QACpB,CAAC,CAAC;QAEF,IAAM,kBAAkB,GAA0C;YAChE,YAAY,GAAG,SAAS,CAAC;QAC3B,CAAC,CAAC;QAEF,IAAM,UAAU,GAAkC,UAAA,MAAM;YACtD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE;gBAC1B,OAAO;aACR;YAED,IAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;YACnC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAChC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAElC,IAAI,IAAI,CAAC,OAAO,EAAE;gBAChB,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC5D,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aAC/D;YAED,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;YAC7B,MAAM,EAAE,CAAC;QACX,CAAC,CAAC;QAEF,OAAO;YACL,OAAO,SAAA;YACP,UAAU,YAAA;YACV,WAAW,aAAA;YACX,OAAO,SAAA;YACP,UAAU,YAAA;YACV,MAAM,QAAA;YACN,eAAe,iBAAA;YACf,kBAAkB,oBAAA;SACnB,CAAC;IACJ,CAAC;IA5PD,sDA4PC","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"]}
|
@@ -13,7 +13,10 @@ const priorityQueue_1 = /*#__PURE__*/require("./priorityQueue");
|
|
13
13
|
function createOverflowManager() {
|
14
14
|
let container;
|
15
15
|
let overflowMenu;
|
16
|
+
// Set as true when resize observer is observing
|
16
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;
|
17
20
|
const options = {
|
18
21
|
padding: 10,
|
19
22
|
overflowAxis: 'horizontal',
|
@@ -109,10 +112,11 @@ function createOverflowManager() {
|
|
109
112
|
groupVisibility
|
110
113
|
});
|
111
114
|
};
|
112
|
-
const processOverflowItems =
|
115
|
+
const processOverflowItems = () => {
|
113
116
|
if (!container) {
|
114
|
-
return;
|
117
|
+
return false;
|
115
118
|
}
|
119
|
+
const availableSize = getOffsetSize(container) - options.padding;
|
116
120
|
const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
|
117
121
|
// Snapshot of the visible/invisible state to compare for updates
|
118
122
|
const visibleTop = visibleItemQueue.peek();
|
@@ -139,15 +143,15 @@ function createOverflowManager() {
|
|
139
143
|
}
|
140
144
|
// only update when the state of visible/invisible items has changed
|
141
145
|
if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
|
142
|
-
|
146
|
+
return true;
|
143
147
|
}
|
148
|
+
return false;
|
144
149
|
};
|
145
150
|
const forceUpdate = () => {
|
146
|
-
if (
|
147
|
-
|
151
|
+
if (processOverflowItems() || forceDispatch) {
|
152
|
+
forceDispatch = false;
|
153
|
+
dispatchOverflowUpdate();
|
148
154
|
}
|
149
|
-
const availableSize = getOffsetSize(container) - options.padding;
|
150
|
-
processOverflowItems(availableSize);
|
151
155
|
};
|
152
156
|
const update = debounce_1.debounce(forceUpdate);
|
153
157
|
const observe = (observedContainer, userOptions) => {
|
@@ -168,6 +172,10 @@ function createOverflowManager() {
|
|
168
172
|
overflowItems[item.id] = item;
|
169
173
|
// some options can affect priority which are only set on `observe`
|
170
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;
|
171
179
|
visibleItemQueue.enqueue(item.id);
|
172
180
|
}
|
173
181
|
if (item.groupId) {
|
@@ -1 +1 @@
|
|
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,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,CA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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"]}
|
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,GAA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AAMkE,eAAe,GAAuClD,EAAE,IAAG;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"]}
|