@fluentui/priority-overflow 9.0.0-rc.1 → 9.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.json +67 -1
- package/CHANGELOG.md +20 -2
- package/lib/debounce.js.map +1 -1
- package/lib/overflowManager.js +21 -57
- package/lib/overflowManager.js.map +1 -1
- package/lib/priorityQueue.js +0 -21
- package/lib/priorityQueue.js.map +1 -1
- package/lib-amd/debounce.js +27 -0
- package/lib-amd/debounce.js.map +1 -0
- package/lib-amd/index.js +7 -0
- package/lib-amd/index.js.map +1 -0
- package/lib-amd/overflowManager.js +208 -0
- package/lib-amd/overflowManager.js.map +1 -0
- package/lib-amd/priorityQueue.js +97 -0
- package/lib-amd/priorityQueue.js.map +1 -0
- package/lib-amd/types.js +5 -0
- package/lib-amd/types.js.map +1 -0
- package/lib-commonjs/debounce.js +0 -2
- package/lib-commonjs/debounce.js.map +1 -1
- package/lib-commonjs/index.js +0 -2
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/overflowManager.js +21 -61
- package/lib-commonjs/overflowManager.js.map +1 -1
- package/lib-commonjs/priorityQueue.js +0 -23
- package/lib-commonjs/priorityQueue.js.map +1 -1
- package/lib-commonjs/types.js.map +1 -1
- package/package.json +5 -5
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["packages/react-components/priority-overflow/src/overflowManager.ts"],"names":[],"mappings":";;;;;;;AAAA,MAAA,UAAA,gBAAA,OAAA,CAAA,YAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;AAGA;;;AAGG;;;AACH,SAAgB,qBAAhB,GAAqC;EACnC,IAAI,SAAJ;EACA,IAAI,YAAJ;EACA,IAAI,SAAS,GAAG,KAAhB;EACA,MAAM,OAAO,GAA6B;IACxC,OAAO,EAAE,EAD+B;IAExC,YAAY,EAAE,YAF0B;IAGxC,iBAAiB,EAAE,KAHqB;IAIxC,cAAc,EAAE,CAJwB;IAKxC,sBAAsB,EAAE,MAAM,SALU;IAMxC,gBA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,EAAf;EACD,CAFD;;EAIA,MAAM,kBAAkB,GAA0C,MAAK;IACrE,YAAY,GAAG,SAAf;EACD,CAFD;;EAIA,MAAM,UAAU,GAAkC,MAAM,IAAG;IACzD,IAAI,CAAC,aAAa,CAAC,MAAD,CAAlB,EAA4B;MAC1B;IACD;;IAED,MAAM,IAAI,GAAG,aAAa,CAAC,MAAD,CAA1B;IACA,gBAAgB,CAAC,MAAjB,CAAwB,MAAxB;IACA,kBAAkB,CAAC,MAAnB,CAA0B,MAA1B;;IAEA,IAAI,IAAI,CAAC,OAAT,EAAkB;MAChB,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,cAA7B,CAA4C,MAA5C,CAAmD,IAAI,CAAC,EAAxD;MACA,cAAc,CAAC,IAAI,CAAC,OAAN,CAAd,CAA6B,gBAA7B,CAA8C,MAA9C,CAAqD,IAAI,CAAC,EAA1D;IACD;;IAED,OAAO,aAAa,CAAC,MAAD,CAApB;IACA,MAAM;EACP,CAhBD;;EAkBA,OAAO;IACL,OADK;IAEL,UAFK;IAGL,WAHK;IAIL,OAJK;IAKL,UALK;IAML,MANK;IAOL,eAPK;IAQL;EARK,CAAP;AAUD;;AA9OD,OAAA,CAAA,qBAAA,GAAA,qBAAA","sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n let observing = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n // Remove items until there's no more overlap\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() === options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n if (invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"],"sourceRoot":"../src/"}
|
1
|
+
{"version":3,"mappings":";;;;;;AAAA;AACA;AAGA;;;;AAIA,SAAgBA,qBAAqB;EACnC,IAAIC,SAAkC;EACtC,IAAIC,YAAqC;EACzC,IAAIC,SAAS,GAAG,KAAK;EACrB,MAAM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Manager","container","overflowMenu","observing","options","padding","overflowAxis","overflowDirection","minimumVisible","onUpdateItemVisibility","undefined","onUpdateOverflow","overflowItems","overflowGroups","resizeObserver","ResizeObserver","entries","update","invisibleItemQueue","priorityQueue_1","a","b","itemA","itemB","priority","positionStatusBit","Node","DOCUMENT_POSITION_FOLLOWING","DOCUMENT_POSITION_PRECEDING","element","compareDocumentPosition","visibleItemQueue","getOffsetSize","el","offsetWidth","offsetHeight","makeItemVisible","nextVisible","dequeue","enqueue","item","visible","groupId","invisibleItemIds","delete","id","visibleItemIds","add","makeItemInvisible","nextInvisible","width","dispatchOverflowUpdate","all","visibleItems","map","itemId","invisibleItems","groupVisibility","Object","forEach","groupState","size","processOverflowItems","availableSize","overflowMenuOffset","visibleTop","peek","invisibleTop","currentWidth","reduce","sum","visibleItemId","child","forceUpdate","debounce_1","observe","observedContainer","userOptions","assign","values","disconnect","addItem","Set","addOverflowMenu","removeOverflowMenu","removeItem","remove","exports"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/overflowManager.ts"],"sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n let observing = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (availableSize: number) => {\n if (!container) {\n return;\n }\n\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n\n // Remove items until there's no more overflow\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() <= options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // make sure the overflow menu can fit\n if (\n visibleItemQueue.size() > options.minimumVisible &&\n invisibleItemQueue.size() > 0 &&\n currentWidth + overflowMenuOffset > availableSize\n ) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n dispatchOverflowUpdate();\n }\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (!container) {\n return;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n processOverflowItems(availableSize);\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"]}
|
@@ -8,103 +8,81 @@ exports.createPriorityQueue = void 0;
|
|
8
8
|
* @param compare - comparison function for items
|
9
9
|
* @returns Priority queue implemented with a min heap
|
10
10
|
*/
|
11
|
-
|
12
11
|
function createPriorityQueue(compare) {
|
13
12
|
const arr = [];
|
14
13
|
let size = 0;
|
15
|
-
|
16
14
|
const left = i => {
|
17
15
|
return 2 * i + 1;
|
18
16
|
};
|
19
|
-
|
20
17
|
const right = i => {
|
21
18
|
return 2 * i + 2;
|
22
19
|
};
|
23
|
-
|
24
20
|
const parent = i => {
|
25
21
|
return Math.floor((i - 1) / 2);
|
26
22
|
};
|
27
|
-
|
28
23
|
const swap = (a, b) => {
|
29
24
|
const tmp = arr[a];
|
30
25
|
arr[a] = arr[b];
|
31
26
|
arr[b] = tmp;
|
32
27
|
};
|
33
|
-
|
34
28
|
const heapify = i => {
|
35
29
|
let smallest = i;
|
36
30
|
const l = left(i);
|
37
31
|
const r = right(i);
|
38
|
-
|
39
32
|
if (l < size && compare(arr[l], arr[smallest]) < 0) {
|
40
33
|
smallest = l;
|
41
34
|
}
|
42
|
-
|
43
35
|
if (r < size && compare(arr[r], arr[smallest]) < 0) {
|
44
36
|
smallest = r;
|
45
37
|
}
|
46
|
-
|
47
38
|
if (smallest !== i) {
|
48
39
|
swap(smallest, i);
|
49
40
|
heapify(smallest);
|
50
41
|
}
|
51
42
|
};
|
52
|
-
|
53
43
|
const dequeue = () => {
|
54
44
|
if (size === 0) {
|
55
45
|
throw new Error('Priority queue empty');
|
56
46
|
}
|
57
|
-
|
58
47
|
const res = arr[0];
|
59
48
|
arr[0] = arr[--size];
|
60
49
|
heapify(0);
|
61
50
|
return res;
|
62
51
|
};
|
63
|
-
|
64
52
|
const peek = () => {
|
65
53
|
if (size === 0) {
|
66
54
|
return null;
|
67
55
|
}
|
68
|
-
|
69
56
|
return arr[0];
|
70
57
|
};
|
71
|
-
|
72
58
|
const enqueue = item => {
|
73
59
|
arr[size++] = item;
|
74
60
|
let i = size - 1;
|
75
61
|
let p = parent(i);
|
76
|
-
|
77
62
|
while (i > 0 && compare(arr[p], arr[i]) > 0) {
|
78
63
|
swap(p, i);
|
79
64
|
i = p;
|
80
65
|
p = parent(i);
|
81
66
|
}
|
82
67
|
};
|
83
|
-
|
84
68
|
const contains = item => {
|
85
69
|
const index = arr.indexOf(item);
|
86
70
|
return index >= 0 && index < size;
|
87
71
|
};
|
88
|
-
|
89
72
|
const remove = item => {
|
90
73
|
const i = arr.indexOf(item);
|
91
|
-
|
92
74
|
if (i === -1 || i >= size) {
|
93
75
|
return;
|
94
76
|
}
|
95
|
-
|
96
77
|
arr[i] = arr[--size];
|
97
78
|
heapify(i);
|
98
79
|
};
|
99
|
-
|
100
80
|
const clear = () => {
|
101
81
|
size = 0;
|
102
82
|
};
|
103
|
-
|
104
83
|
const all = () => {
|
105
84
|
return arr.slice(0, size);
|
106
85
|
};
|
107
|
-
|
108
86
|
return {
|
109
87
|
all,
|
110
88
|
clear,
|
@@ -116,6 +94,5 @@ function createPriorityQueue(compare) {
|
|
116
94
|
size: () => size
|
117
95
|
};
|
118
96
|
}
|
119
|
-
|
120
97
|
exports.createPriorityQueue = createPriorityQueue;
|
121
98
|
//# sourceMappingURL=priorityQueue.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":";;;;;;AAaA;;;;AAIA,SAAgBA,mBAAmB,CAAIC,OAAkC;EACvE,MAAMC,GAAG,GAAQ,EAAE;EACnB,IAAIC,IAAI,GAAG,CAAC;EAEZ,MAAMC,IAAI,GAAIC,CAAS,IAAI;IACzB,OAAO,CAAC,GAAGA,CAAC,GAAG,CAAC;EAClB,CAAC;EAED,MAAMC,KAAK,GAAID,CAAS,IAAI;IAC1B,OAAO,CAAC,GAAGA,CAAC,GAAG,CAAC;EAClB,CAAC;EAED,MAAME,MAAM,GAAIF,CAAS,IAAI;IAC3B,OAAOG,IAAI,CAACC,KAAK,CAAC,CAACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;EAChC,CAAC;EAED,MAAMK,IAAI,GAAG,CAACC,CAAS,EAAEC,CAAS,KAAI;IACpC,MAAMC,GAAG,GAAGX,GAAG,CAACS,CAAC,CAAC;IAClBT,GAAG,CAACS,CAAC,CAAC,GAAGT,GAAG,CAACU,CAAC,CAAC;IACfV,GAAG,CAACU,CAAC,CAAC,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AAIqB,CAAC,GAAGjB,MAAM,CAACF,CAAC,CAAC;IACjB,OAAOA,CAAC,GAAG,CAAC,IAAIJ,OAAO,CAACC,GAAG,CAACsB,CAAC,CAAC,EAAEtB,GAAG,CAACG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;MAC3CK,IAAI,CAACc,CAAC,EAAEnB,CAAC,CAAC;MACVA,CAAC,GAAGmB,CAAC;MACLA,CAAC,GAAGjB,MAAM,CAACF,CAAC,CAAC;;EAEjB,CAAC;EAED,MAAMoB,QAAQ,GAAIF,IAAO,IAAI;IAC3B,MAAMG,KAAK,GAAGxB,GAAG,CAACyB,OAAO,CAACJ,IAAI,CAAC;IAC/B,OAAOG,KAAK,IAAI,CAAC,IAAIA,KAAK,GAAGvB,IAAI;EACnC,CAAC;EAED,MAAMyB,MAAM,GAAIL,IAAO,IAAI;IACzB,MAAMlB,CAAC,GAAGH,GAAG,CAACyB,OAAO,CAACJ,IAAI,CAAC;IAE3B,IAAIlB,CAAC,KAAK,CAAC,CAAC,IAAIA,CAAC,IAAIF,IAAI,EAAE;MACzB;;IAGFD,GAAG,CAACG,CAAC,CAAC,GAAGH,GAAG,CAAC,EAAEC,IAAI,CAAC;IACpBW,OAAO,CAACT,CAAC,CAAC;EACZ,CAAC;EAED,MAAMwB,KAAK,GAAG,MAAK;IACjB1B,IAAI,GAAG,CAAC;EACV,CAAC;EAED,MAAM2B,GAAG,GAAG,MAAK;IACf,OAAO5B,GAAG,CAAC6B,KAAK,CAAC,CAAC,EAAE5B,IAAI,CAAC;EAC3B,CAAC;EAED,OAAO;IACL2B,GAAG;IACHD,KAAK;IACLJ,QAAQ;IACRP,OAAO;IACPI,OAAO;IACPD,IAAI;IACJO,MAAM;IACNzB,IAAI,EAAE,MAAMA;GACb;AACH;AA1GA6B","names":["createPriorityQueue","compare","arr","size","left","i","right","parent","Math","floor","swap","a","b","tmp","heapify","smallest","l","r","dequeue","Error","res","peek","enqueue","item","p","contains","index","indexOf","remove","clear","all","slice","exports"],"sourceRoot":"../src/","sources":["packages/react-components/priority-overflow/src/priorityQueue.ts"],"sourcesContent":["export type PriorityQueueCompareFn<T> = (a: T, b: T) => number;\n\nexport interface PriorityQueue<T> {\n all: () => T[];\n clear: () => void;\n contains: (item: T) => boolean;\n dequeue: () => T;\n enqueue: (item: T) => void;\n peek: () => T | null;\n remove: (item: T) => void;\n size: () => number;\n}\n\n/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */\nexport function createPriorityQueue<T>(compare: PriorityQueueCompareFn<T>): PriorityQueue<T> {\n const arr: T[] = [];\n let size = 0;\n\n const left = (i: number) => {\n return 2 * i + 1;\n };\n\n const right = (i: number) => {\n return 2 * i + 2;\n };\n\n const parent = (i: number) => {\n return Math.floor((i - 1) / 2);\n };\n\n const swap = (a: number, b: number) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n\n const heapify = (i: number) => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n\n return res;\n };\n\n const peek = () => {\n if (size === 0) {\n return null;\n }\n\n return arr[0];\n };\n\n const enqueue = (item: T) => {\n arr[size++] = item;\n let i = size - 1;\n let p = parent(i);\n while (i > 0 && compare(arr[p], arr[i]) > 0) {\n swap(p, i);\n i = p;\n p = parent(i);\n }\n };\n\n const contains = (item: T) => {\n const index = arr.indexOf(item);\n return index >= 0 && index < size;\n };\n\n const remove = (item: T) => {\n const i = arr.indexOf(item);\n\n if (i === -1 || i >= size) {\n return;\n }\n\n arr[i] = arr[--size];\n heapify(i);\n };\n\n const clear = () => {\n size = 0;\n };\n\n const all = () => {\n return arr.slice(0, size);\n };\n\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size,\n };\n}\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"mappings":"","names":[],"sourceRoot":"../src/","sources":[],"sourcesContent":[]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/priority-overflow",
|
3
|
-
"version": "9.0.0
|
3
|
+
"version": "9.0.0",
|
4
4
|
"description": "Vanilla JS utilities to implement overflow menus",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -24,16 +24,16 @@
|
|
24
24
|
},
|
25
25
|
"devDependencies": {
|
26
26
|
"@fluentui/eslint-plugin": "*",
|
27
|
-
"@fluentui/scripts": "
|
27
|
+
"@fluentui/scripts-api-extractor": "*",
|
28
|
+
"@fluentui/scripts-tasks": "*"
|
28
29
|
},
|
29
30
|
"dependencies": {
|
30
31
|
"tslib": "^2.1.0"
|
31
32
|
},
|
32
33
|
"beachball": {
|
33
34
|
"disallowedChangeTypes": [
|
34
|
-
"
|
35
|
-
"
|
36
|
-
"patch"
|
35
|
+
"prerelease",
|
36
|
+
"major"
|
37
37
|
]
|
38
38
|
},
|
39
39
|
"exports": {
|